Skip to content

Commit

Permalink
fix: navigator api types (#725)
Browse files Browse the repository at this point in the history
* chore: bump contentful-management from 7.19.1 to 7.20.0 (#718)

* chore: bump @typescript-eslint/eslint-plugin from 4.23.0 to 4.24.0 (#719)

* chore: bump rollup from 2.47.0 to 2.48.0 (#715)

* chore: bump @typescript-eslint/parser from 4.23.0 to 4.24.0 (#720)

* feat: expose WithId

* chore: bump contentful-management from 7.20.0 to 7.20.1 (#723)

* test: [] change stale limit to 2 hours (#721)

Change stale limit to 2 hours instead of 1 day

* feat: add meaningful types to navigator api

* chore: use cma for typings

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Lorenz Weiß <[email protected]>
  • Loading branch information
3 people committed May 20, 2021
1 parent ad7186e commit 7cac2eb
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 367 deletions.
234 changes: 14 additions & 220 deletions lib/types/entities.ts
Original file line number Diff line number Diff line change
@@ -1,223 +1,17 @@
import { ContentEntitySys, ContentEntityType, Items, Link, Metadata } from './utils'

export type TagVisibility = 'private' | 'public'

export interface User {
/**
* System metadata
*/
sys: {
type: string
id: string
version: number
createdBy?: Link
createdAt: string
updatedBy?: Link
updatedAt: string
}
/**
* First name of the user
*/
firstName: string
/**
* Last name of the user
*/
lastName: string
/**
* Url to the users avatar
*/
avatarUrl: string
/**
* Email address of the user
*/
email: string
/**
* Activation flag
*/
activated: boolean
/**
* Number of sign ins
*/
signInCount: number
/**
* User confirmation flag
*/
confirmed: boolean
'2faEnabled': boolean
cookieConsentData: string
}

export interface Tag {
sys: {
type: 'Tag'
id: string
space: Link
environment: Link
createdBy?: Link
updatedBy?: Link
createdAt: string
updatedAt: string
version: number
visibility: TagVisibility
}
name: string
}

export interface Asset {
sys: ContentEntitySys
fields: {
/** Title for this asset */
title: {
[key: string]: string
}
/** Description for this asset */
description?: {
[key: string]: string
}
/** File object for this asset */
file: {
[key: string]: {
fileName: string
contentType: string
/** Url where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone. */
upload?: string
/** Url where the file is available at the Contentful media asset system. This field won't be available until the asset is processed. */
url?: string
/** Details for the file, depending on file type (example: image size in bytes, etc) */
details?: Record<string, any>
uploadFrom?: Record<string, any>
}
}
}
metadata?: Metadata
}

type TaskStatus = 'active' | 'resolved'

interface TaskSys {
id: string
type: 'Task'
parentEntity: { sys: Link }
space: Link
environment: Link
createdBy: Link
createdAt: string
updatedBy: Link
updatedAt: string
version: number
}

export interface Task {
assignedTo: Link
body: string
status: TaskStatus
sys: TaskSys
}

export enum ScheduledActionStatuses {
scheduled = 'scheduled',
inProgress = 'inProgress',
succeeded = 'succeeded',
failed = 'failed',
canceled = 'canceled',
}
// WARNING: This is using 'keyof' which looks at the left hand name, not the right hand value
type PublicActionStatus = keyof typeof ScheduledActionStatuses
type ScheduledActionActionType = 'publish' | 'unpublish'

export interface ScheduledAction {
sys: {
id: string
type: 'ScheduledAction'
/** ISO 8601 string */
createdAt: string
createdBy: Link
/** ISO 8601 string */
canceledAt?: string
canceledBy?: Link
space: Link
status: PublicActionStatus
}
entity: {
sys: {
id: string
linkType: ContentEntityType
type: string
}
}
environment?: Link
scheduledFor: {
/** ISO 8601 string */
datetime: string
}
action: ScheduledActionActionType
}

export interface ContentTypeField extends Items {
id: string
name: string
required: boolean
localized: boolean
disabled?: boolean
omitted?: boolean
deleted?: boolean
items?: Items
apiName?: string
}

export interface ContentType {
sys: {
type: string
id: string
version: number
createdBy?: Link
createdAt: string
updatedBy?: Link
updatedAt: string
space: Link
environment: Link
firstPublishedAt?: string
publishedCounter?: number
publishedVersion?: number
}
fields: ContentTypeField[]
name: string
displayField: string
description: string
}

interface EditorWidget {
widgetId: string
widgetNamespace: string
settings?: Object
}

export interface EditorInterface {
sys: Object
controls?: Array<{
fieldId: string
widgetId?: string
widgetNamespace?: string
settings?: Object
}>
sidebar?: Array<{
widgetId: string
widgetNamespace: string
settings?: Object
disabled?: boolean
}>
editor?: EditorWidget
editors?: EditorWidget[]
}

export interface SpaceMembership {
sys: {
id: string
type: string
}
admin: boolean
roles: { name: string; description: string }[]
}
export type {
TagProps as Tag,
TagVisibility,
UserProps as User,
AssetProps as Asset,
TaskProps as Task,
ScheduledActionProps as ScheduledAction,
ContentTypeProps as ContentType,
EditorInterfaceProps as EditorInterface,
SpaceMembershipProps as SpaceMembership,
ContentFields as ContentTypeField,
EntryProps as Entry,
KeyValueMap,
} from 'contentful-management/types'

export interface CanonicalRequest {
method: 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'
Expand Down
6 changes: 0 additions & 6 deletions lib/types/entry.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,3 @@ export interface EntryAPI extends TaskAPI {
*/
metadata?: Metadata
}

export type Entry<Fields = Record<string, any>> = {
sys: ContentEntitySys
metadata?: Metadata
fields: Fields
}
3 changes: 2 additions & 1 deletion lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export type {
Tag,
TagVisibility,
Task,
Entry,
} from './entities'

export type { Entry, EntryAPI, TaskAPI, TaskInputData } from './entry.types'
export type { EntryAPI, TaskAPI, TaskInputData } from './entry.types'

export type { FieldInfo, EntryFieldInfo, EntryFieldAPI } from './field.types'

Expand Down
16 changes: 9 additions & 7 deletions lib/types/navigator.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Asset, Entry, KeyValueMap } from './entities'

export interface NavigatorAPIOptions {
/** use `waitForClose` if you want promise to be resolved only after slide in editor is closed */
slideIn?: boolean | { waitForClose: boolean }
Expand Down Expand Up @@ -36,22 +38,22 @@ export interface NavigatorOpenResponse<T> {

export interface NavigatorAPI {
/** Opens an existing entry in the current Web App session. */
openEntry: <T = Object>(
openEntry: <Fields extends KeyValueMap = KeyValueMap>(
entryId: string,
options?: NavigatorAPIOptions
) => Promise<NavigatorOpenResponse<T>>
) => Promise<NavigatorOpenResponse<Entry<Fields>>>
/** Opens an existing asset in the current Web App session. */
openAsset: <T = Object>(
openAsset: (
assetId: string,
options?: NavigatorAPIOptions
) => Promise<NavigatorOpenResponse<T>>
) => Promise<NavigatorOpenResponse<Asset>>
/** Opens a new entry in the current Web App session. */
openNewEntry: <T = Object>(
openNewEntry: <Fields extends KeyValueMap = KeyValueMap>(
contentTypeId: string,
options?: NavigatorAPIOptions
) => Promise<NavigatorOpenResponse<T>>
) => Promise<NavigatorOpenResponse<Entry<Fields>>>
/** Opens a new asset in the current Web App session. */
openNewAsset: <T = Object>(options: NavigatorAPIOptions) => Promise<NavigatorOpenResponse<T>>
openNewAsset: (options: NavigatorAPIOptions) => Promise<NavigatorOpenResponse<Asset>>
/** Navigates to a page extension in the current Web App session. Calling without `options` will navigate to the home route of your page extension. */
openPageExtension: (options?: PageExtensionOptions) => Promise<NavigatorPageResponse>
/** Navigates to the app's page location. */
Expand Down
31 changes: 22 additions & 9 deletions lib/types/space.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Entry } from './entry.types'
import {
Asset,
CanonicalRequest,
Expand All @@ -8,6 +7,8 @@ import {
Tag,
User,
TagVisibility,
KeyValueMap,
Entry,
} from './entities'
import {
CollectionResponse,
Expand Down Expand Up @@ -43,21 +44,33 @@ export interface SpaceAPI {
updateContentType: (data: ContentType) => Promise<ContentType>
deleteContentType: (data: ContentType) => Promise<void>

getEntry: <Fields>(id: string) => Promise<Entry<Fields>>
getEntrySnapshots: <Fields>(id: string) => Promise<CollectionResponse<Snapshot<Entry<Fields>>>>
getEntry: <Fields extends KeyValueMap = KeyValueMap>(id: string) => Promise<Entry<Fields>>
getEntrySnapshots: <Fields extends KeyValueMap = KeyValueMap>(
id: string
) => Promise<CollectionResponse<Snapshot<Entry<Fields>>>>
getEntries: <Fields, Query extends SearchQuery = SearchQuery>(
query?: Query
) => Promise<CollectionResponse<Entry<Fields>>>
createEntry: <Fields>(
contentTypeId: string,
data: WithOptionalId<Entry<Fields>>
) => Promise<Entry<Fields>>
updateEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
publishEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
unpublishEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
archiveEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
unarchiveEntry: <Fields>(data: Entry<Fields>) => Promise<Entry<Fields>>
deleteEntry: <Fields>(data: Entry<Fields>) => Promise<void>
updateEntry: <Fields extends KeyValueMap = KeyValueMap>(
data: Entry<Fields>
) => Promise<Entry<Fields>>
publishEntry: <Fields extends KeyValueMap = KeyValueMap>(
data: Entry<Fields>
) => Promise<Entry<Fields>>
unpublishEntry: <Fields extends KeyValueMap = KeyValueMap>(
data: Entry<Fields>
) => Promise<Entry<Fields>>
archiveEntry: <Fields extends KeyValueMap = KeyValueMap>(
data: Entry<Fields>
) => Promise<Entry<Fields>>
unarchiveEntry: <Fields extends KeyValueMap = KeyValueMap>(
data: Entry<Fields>
) => Promise<Entry<Fields>>
deleteEntry: <Fields extends KeyValueMap = KeyValueMap>(data: Entry<Fields>) => Promise<void>
getPublishedEntries: <Fields, Query extends SearchQuery = SearchQuery>(
query?: Query
) => Promise<CollectionResponse<Entry<Fields>>>
Expand Down
Loading

0 comments on commit 7cac2eb

Please sign in to comment.