From 16b15e25ddcfd8a34a6f4c9732fc5e67929ac62b Mon Sep 17 00:00:00 2001 From: Manuel Spagnolo Date: Tue, 11 May 2021 10:49:23 +0200 Subject: [PATCH] fix: include typings in the release (#699) * fix: include typings in the release * chore: tweak space api types to adhere to cma.js * refactor: Item -> Items * revert: old tags api * feat: export UserAPI --- lib/types/api.types.ts | 2 +- lib/types/entities.ts | 62 +++++++++++++++++----------------------- lib/types/index.ts | 2 ++ lib/types/space.types.ts | 7 ++--- lib/types/utils.ts | 28 +++++++++--------- tsconfig.json | 2 +- 6 files changed, 48 insertions(+), 55 deletions(-) diff --git a/lib/types/api.types.ts b/lib/types/api.types.ts index 6eba8d45e6..bfb70103bb 100644 --- a/lib/types/api.types.ts +++ b/lib/types/api.types.ts @@ -10,7 +10,7 @@ import { NavigatorAPI } from './navigator.types' import { EntryFieldInfo, FieldInfo } from './field.types' /* User API */ -interface UserAPI { +export interface UserAPI { sys: { id: string type: string diff --git a/lib/types/entities.ts b/lib/types/entities.ts index c5f45bd8af..aa1d1a23c6 100644 --- a/lib/types/entities.ts +++ b/lib/types/entities.ts @@ -1,6 +1,6 @@ import { ContentEntitySys, ContentEntityType, Items, Link, Metadata } from './utils' -type TagVisibility = 'private' | 'public' +export type TagVisibility = 'private' | 'public' export interface User { /** @@ -53,8 +53,8 @@ export interface Tag { id: string space: Link environment: Link - createdBy: Link - updatedBy: Link + createdBy?: Link + updatedBy?: Link createdAt: string updatedAt: string version: number @@ -114,13 +114,15 @@ export interface Task { sys: TaskSys } -const enum PublicActionStatus { - Scheduled = 'scheduled', - Succeeded = 'succeeded', - Failed = 'failed', - Canceled = 'canceled', +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 { @@ -133,13 +135,7 @@ export interface ScheduledAction { /** ISO 8601 string */ canceledAt?: string canceledBy?: Link - space: { - sys: { - id: string - linkType: 'Space' - type: string - } - } + space: Link status: PublicActionStatus } entity: { @@ -149,13 +145,7 @@ export interface ScheduledAction { type: string } } - environment: { - sys: { - id: string - linkType: 'Environment' - type: string - } - } + environment?: Link scheduledFor: { /** ISO 8601 string */ datetime: string @@ -163,30 +153,32 @@ export interface ScheduledAction { action: ScheduledActionActionType } -export interface ContentTypeField { - disabled: boolean +export interface ContentTypeField extends Items { id: string - localized: boolean name: string - omitted: boolean required: boolean - type: string - validations: Object[] - linkType?: string + localized: boolean + disabled?: boolean + omitted?: boolean + deleted?: boolean items?: Items + apiName?: string } export interface ContentType { sys: { type: string id: string - version?: number - space?: Link - environment?: Link - createdAt?: string + version: number createdBy?: Link - updatedAt?: string + createdAt: string updatedBy?: Link + updatedAt: string + space: Link + environment: Link + firstPublishedAt?: string + publishedCounter?: number + publishedVersion?: number } fields: ContentTypeField[] name: string diff --git a/lib/types/index.ts b/lib/types/index.ts index 613403c24f..3d282daa0e 100644 --- a/lib/types/index.ts +++ b/lib/types/index.ts @@ -17,6 +17,7 @@ export type { ParametersAPI, SharedEditorSDK, SidebarExtensionSDK, + UserAPI, } from './api.types' export type { AppConfigAPI, AppState } from './app.types' @@ -39,6 +40,7 @@ export type { ScheduledAction, SpaceMembership, Tag, + TagVisibility, Task, } from './entities' diff --git a/lib/types/space.types.ts b/lib/types/space.types.ts index 3b3c138f44..1efe8e9c00 100644 --- a/lib/types/space.types.ts +++ b/lib/types/space.types.ts @@ -6,12 +6,11 @@ import { ContentType, EditorInterface, ScheduledAction, - SearchQuery, Tag, - TagVisibility, User, + TagVisibility, } from './entities' -import { CollectionResponse, ContentEntityType, Link, WithOptionalSys } from './utils' +import { CollectionResponse, ContentEntityType, Link, WithOptionalSys, SearchQuery } from './utils' type Snapshot = { sys: { @@ -34,7 +33,7 @@ export interface SpaceAPI { getCachedContentTypes: () => ContentType[] getContentType: (id: string) => Promise getContentTypes: () => Promise> - createContentType: (data: WithOptionalSys) => Promise + createContentType: (data: ContentType) => Promise updateContentType: (data: ContentType) => Promise deleteContentType: (data: ContentType) => Promise diff --git a/lib/types/utils.ts b/lib/types/utils.ts index dfcee22d1d..1451584b67 100644 --- a/lib/types/utils.ts +++ b/lib/types/utils.ts @@ -2,11 +2,11 @@ export type WithOptionalSys = Omit & sys?: Type['sys'] } -export interface Link { +export interface Link { sys: { id: string - type: 'Link' - linkType: Type + type: Type + linkType: LinkType } } @@ -18,7 +18,7 @@ export interface CollectionResponse { sys: { type: string } } -export type ContentEntityType = 'Entry' | 'Asset' +export type ContentEntityType = 'Entry' | 'Asset' | string export interface ContentEntitySys { space: Link @@ -27,22 +27,22 @@ export interface ContentEntitySys { createdAt: string updatedAt: string environment: Link - publishedVersion: number + publishedVersion?: number deletedVersion?: number archivedVersion?: number - publishedAt: string - firstPublishedAt: string - createdBy: Link - updatedBy: Link - publishedCounter: number + publishedAt?: string + firstPublishedAt?: string + createdBy?: Link + updatedBy?: Link + publishedCounter?: number version: number - publishedBy: Link + publishedBy?: Link contentType: Link } -export type Metadata = Partial<{ - tags: Link<'Tag'>[] -}> +export type Metadata = { + tags: Link<'Tag', 'Link'>[] +} export interface Items { type: string diff --git a/tsconfig.json b/tsconfig.json index a295388dfa..f05a2b4fe5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,6 @@ "forceConsistentCasingInFileNames": true, "declaration": true }, - "include": ["lib"], + "include": ["lib/**/*"], "exclude": ["test"] }