Skip to content

Commit

Permalink
feat: [EXT-3599] Bundle contentful-management with app-sdk. (Fixing p…
Browse files Browse the repository at this point in the history
…revious PR) (#1556)

* feat: add node-resolve Rollup plugin

* feat: add external deps to bundle

* Revert "revert: expose cma in the sdk [EXT-3599] (#1548)"

This reverts commit 9b8684f.

* feat: bundle contentful-management in separate file

* feat: add jsdelivr config

* fix: package version

* fix: dependencies

* chore: remove global var for non-browser bundle

* chore: base package-lock off of canary file
  • Loading branch information
colomolo authored Jun 28, 2023
1 parent 07899c8 commit 2779675
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 46 deletions.
4 changes: 3 additions & 1 deletion lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from './types'
import { Channel } from './channel'
import { createAdapter } from './cmaAdapter'
import { createCMAClient } from './cma'
import { KeyValueMap } from 'contentful-management/types'

const DEFAULT_API_PRODUCERS = [
Expand Down Expand Up @@ -64,9 +65,10 @@ function makeSharedAPI(
const currentLocation = data.location || locations.LOCATION_ENTRY_FIELD

return {
cma: createCMAClient(ids, channel),
cmaAdapter: createAdapter(channel),
location: {
is: (tested) => currentLocation === tested,
is: (tested: string) => currentLocation === tested,
},
user,
parameters,
Expand Down
19 changes: 19 additions & 0 deletions lib/cma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createClient } from 'contentful-management'
import { createAdapter } from './cmaAdapter'
import { CMAClient } from './types/cmaClient.types'
import type { IdsAPI } from './types/api.types'
import type { Channel } from './channel'

export function createCMAClient(ids: IdsAPI, channel: Channel): CMAClient {
return createClient(
{ apiAdapter: createAdapter(channel) },
{
type: 'plain',
defaults: {
environmentId: ids.environmentAlias ?? ids.environment,
spaceId: ids.space,
organizationId: ids.organization,
},
}
)
}
3 changes: 3 additions & 0 deletions lib/types/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AppConfigAPI } from './app.types'
import { NavigatorAPI } from './navigator.types'
import { EntryFieldInfo, FieldInfo } from './field.types'
import { Adapter, KeyValueMap } from 'contentful-management/types'
import { CMAClient } from './cmaClient.types'

/* User API */

Expand Down Expand Up @@ -244,6 +245,8 @@ export interface BaseAppSDK<
ids: Omit<IdsAPI, EntryScopedIds>
/** Adapter to be injected in contentful-management client */
cmaAdapter: Adapter
/** A CMA Client initialized with default params */
cma: CMAClient
}

export type EditorAppSDK<
Expand Down
Loading

0 comments on commit 2779675

Please sign in to comment.