Skip to content

Commit

Permalink
feat: hostnames API (#1633)
Browse files Browse the repository at this point in the history
* feat: add hostnames API

* test: update shared api test

* fix: cdn -> cda

* refactor: tweak property names

* refactor: tweak property names
  • Loading branch information
andipaetzold authored Aug 25, 2023
1 parent fe3c043 commit e776ce4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function makeSharedAPI(
channel: Channel,
data: ConnectMessage
): BaseAppSDK<KeyValueMap, KeyValueMap, never> {
const { user, parameters, locales, ids, initialContentTypes } = data
const { user, parameters, locales, ids, initialContentTypes, hostnames } = data
const currentLocation = data.location || locations.LOCATION_ENTRY_FIELD

return {
Expand Down Expand Up @@ -90,6 +90,7 @@ function makeSharedAPI(
warning: (message: string) => channel.send('notify', { type: 'warning', message }),
},
ids,
hostnames,
access: {
can: (action: string, entity: any, patch?: JSONPatchItem[]) =>
channel.call('checkAccess', action, entity, patch) as Promise<boolean>,
Expand Down
19 changes: 19 additions & 0 deletions lib/types/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ export interface IdsAPI {
contentType: string
}

/** Hostnames */
export interface HostnamesAPI {
/** Hostname of the Content Delivery API */
delivery: string
/** Hostname of the Content Management API */
management: string
/** Hostname of the Preview API */
preview: string
/** Hostname of the Upload API */
upload: string
/** Hostname of the GraphQL API */
graphql: string
/** Hostname of the Web App */
webapp: string
}

/** Content API */
export interface ContentTypeAPI {
sys: {
Expand Down Expand Up @@ -243,6 +259,8 @@ export interface BaseAppSDK<
access: AccessAPI
/** Exposes relevant ids, keys may be ommited based on location */
ids: Omit<IdsAPI, EntryScopedIds>
/** Exposes hostnames to interact with Contentful's API or to link to the web app */
hostnames: HostnamesAPI
/** Adapter to be injected in contentful-management client */
cmaAdapter: Adapter
/** A CMA Client initialized with default params */
Expand Down Expand Up @@ -389,4 +407,5 @@ export interface ConnectMessage {
}
fieldInfo: EntryFieldInfo[]
field?: FieldInfo
hostnames: HostnamesAPI
}
1 change: 1 addition & 0 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type {
SharedEditorSDK,
UserAPI,
JSONPatchItem,
HostnamesAPI,
} from './api.types'

export type {
Expand Down
1 change: 1 addition & 0 deletions test/unit/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const sharedExpected = [
'ids',
'access',
'cmaAdapter',
'hostnames',
'cma',
]

Expand Down

0 comments on commit e776ce4

Please sign in to comment.