Skip to content

Commit 2779675

Browse files
authored
feat: [EXT-3599] Bundle contentful-management with app-sdk. (Fixing previous 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
1 parent 07899c8 commit 2779675

File tree

8 files changed

+294
-46
lines changed

8 files changed

+294
-46
lines changed

lib/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from './types'
1919
import { Channel } from './channel'
2020
import { createAdapter } from './cmaAdapter'
21+
import { createCMAClient } from './cma'
2122
import { KeyValueMap } from 'contentful-management/types'
2223

2324
const DEFAULT_API_PRODUCERS = [
@@ -64,9 +65,10 @@ function makeSharedAPI(
6465
const currentLocation = data.location || locations.LOCATION_ENTRY_FIELD
6566

6667
return {
68+
cma: createCMAClient(ids, channel),
6769
cmaAdapter: createAdapter(channel),
6870
location: {
69-
is: (tested) => currentLocation === tested,
71+
is: (tested: string) => currentLocation === tested,
7072
},
7173
user,
7274
parameters,

lib/cma.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createClient } from 'contentful-management'
2+
import { createAdapter } from './cmaAdapter'
3+
import { CMAClient } from './types/cmaClient.types'
4+
import type { IdsAPI } from './types/api.types'
5+
import type { Channel } from './channel'
6+
7+
export function createCMAClient(ids: IdsAPI, channel: Channel): CMAClient {
8+
return createClient(
9+
{ apiAdapter: createAdapter(channel) },
10+
{
11+
type: 'plain',
12+
defaults: {
13+
environmentId: ids.environmentAlias ?? ids.environment,
14+
spaceId: ids.space,
15+
organizationId: ids.organization,
16+
},
17+
}
18+
)
19+
}

lib/types/api.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { AppConfigAPI } from './app.types'
2020
import { NavigatorAPI } from './navigator.types'
2121
import { EntryFieldInfo, FieldInfo } from './field.types'
2222
import { Adapter, KeyValueMap } from 'contentful-management/types'
23+
import { CMAClient } from './cmaClient.types'
2324

2425
/* User API */
2526

@@ -244,6 +245,8 @@ export interface BaseAppSDK<
244245
ids: Omit<IdsAPI, EntryScopedIds>
245246
/** Adapter to be injected in contentful-management client */
246247
cmaAdapter: Adapter
248+
/** A CMA Client initialized with default params */
249+
cma: CMAClient
247250
}
248251

249252
export type EditorAppSDK<

0 commit comments

Comments
 (0)