@stackbit/cms-contentful 0.4.49-staging.2 → 0.4.50-staging.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,9 +103,44 @@ export interface ContentSourceOptions {
103
103
  * Use webhook for content updates.
104
104
  */
105
105
  useWebhookForContentUpdates?: boolean;
106
+ /**
107
+ * Use accessToken instead of userContext.accessToken for write operations.
108
+ */
109
+ useAccessTokenForUpdates?: boolean;
110
+ /**
111
+ * Switches the ContentfulContentSource to work with EU data regions.
112
+ * When set to true, the following updated accordingly:
113
+ * previewHost: 'preview.eu.contentful.com'
114
+ * manageHost: 'api.eu.contentful.com'
115
+ * uploadHost: 'upload.eu.contentful.com'
116
+ */
117
+ useEURegion?: boolean;
118
+ /**
119
+ * The host of the Contentful's preview API.
120
+ * By default, this value is set to 'preview.contentful.com'.
121
+ * If `useEURegion` is set, uses 'preview.eu.contentful.com'.
122
+ */
123
+ previewHost?: string;
124
+ /**
125
+ * The host of the Contentful's management API.
126
+ * By default, this value is `undefined` which makes the contentful-management
127
+ * use the 'api.contentful.com'.
128
+ * If `useEURegion` is set, this value is set to 'api.eu.contentful.com'.
129
+ */
130
+ managementHost?: string;
131
+ /**
132
+ * The host used to upload assets to Contentful.
133
+ * By default, this value is `undefined` which makes the contentful-management
134
+ * use the 'upload.contentful.com'.
135
+ * If `useEURegion` is set, this value is set to 'upload.eu.contentful.com'.
136
+ */
137
+ uploadHost?: string;
106
138
  }
107
139
 
108
140
  type UserContext = {
141
+ // The user's accessToken is provided by the "Netlify Create" Contentful
142
+ // OAuth Application when users connect their Netlify Create and Contentful
143
+ // accounts via OAuth flow.
109
144
  accessToken: string;
110
145
  };
111
146
 
@@ -131,6 +166,11 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
131
166
  private localDev!: boolean;
132
167
  private contentPoller: ContentPoller | null = null;
133
168
  private useWebhookForContentUpdates: boolean;
169
+ private useAccessTokenForUpdates: boolean;
170
+ private useEURegion: boolean;
171
+ private previewHost?: string;
172
+ private managementHost?: string;
173
+ private uploadHost?: string;
134
174
  private locales: LocaleProps[] = [];
135
175
  private defaultLocale?: LocaleProps;
136
176
  private userMap: Record<string, UserProps> = {};
@@ -149,6 +189,11 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
149
189
  this.previewToken = options.previewToken ?? process.env.CONTENTFUL_PREVIEW_TOKEN;
150
190
  this.useLocalizedAssetFields = options.useLocalizedAssetFields ?? false;
151
191
  this.useWebhookForContentUpdates = options.useWebhookForContentUpdates ?? false;
192
+ this.useAccessTokenForUpdates = options.useAccessTokenForUpdates ?? false;
193
+ this.useEURegion = options.useEURegion ?? false;
194
+ this.previewHost = options.previewHost ?? (this.useEURegion ? 'preview.eu.contentful.com' : undefined);
195
+ this.managementHost = options.managementHost ?? (this.useEURegion ? 'api.eu.contentful.com' : undefined);
196
+ this.uploadHost = options.uploadHost ?? (this.useEURegion ? 'upload.eu.contentful.com' : undefined);
152
197
  // Max active bulk actions per space is limited to 5.
153
198
  // Max of 200 items per bulk action.
154
199
  this.taskQueue = new TaskQueue({ limit: 5 });
@@ -159,7 +204,7 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
159
204
  }
160
205
 
161
206
  getContentSourceType(): string {
162
- return 'contentful';
207
+ return this.useEURegion ? 'contentful-eu' : 'contentful';
163
208
  }
164
209
 
165
210
  getProjectId(): string {
@@ -201,7 +246,9 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
201
246
  this.plainClient = createPlainApiClient({
202
247
  spaceId: this.spaceId,
203
248
  accessToken: this.accessToken,
204
- environment: this.environment
249
+ environment: this.environment,
250
+ managementHost: this.managementHost,
251
+ uploadHost: this.uploadHost
205
252
  });
206
253
 
207
254
  await this.validateConfig();
@@ -328,6 +375,9 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
328
375
  environment: this.environment,
329
376
  previewToken: this.previewToken,
330
377
  managementToken: this.accessToken,
378
+ previewHost: this.previewHost,
379
+ managementHost: this.managementHost,
380
+ uploadHost: this.uploadHost,
331
381
  pollType: 'date',
332
382
  syncContext: this.getSyncContextForContentPollerFromCache(),
333
383
  notificationCallback: async (syncResult) => {
@@ -528,7 +578,7 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
528
578
  }
529
579
 
530
580
  async hasAccess({ userContext }: { userContext?: UserContext }): Promise<{ hasConnection: boolean; hasPermissions: boolean }> {
531
- if (!this.localDev && !userContext?.accessToken) {
581
+ if (!this.localDev && !this.useAccessTokenForUpdates && !userContext?.accessToken) {
532
582
  return {
533
583
  hasConnection: false,
534
584
  hasPermissions: false
@@ -1039,7 +1089,7 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
1039
1089
  }
1040
1090
 
1041
1091
  private getPlainApiClientForUser({ userContext }: { userContext?: UserContext }): PlainClientAPI {
1042
- if (this.localDev) {
1092
+ if (this.localDev || this.useAccessTokenForUpdates) {
1043
1093
  return this.plainClient;
1044
1094
  }
1045
1095
  const userAccessToken = userContext?.accessToken;
@@ -1049,7 +1099,9 @@ export class ContentfulContentSource implements ContentSourceTypes.ContentSource
1049
1099
  return createPlainApiClient({
1050
1100
  spaceId: this.spaceId,
1051
1101
  accessToken: userAccessToken,
1052
- environment: this.environment
1102
+ environment: this.environment,
1103
+ managementHost: this.managementHost,
1104
+ uploadHost: this.uploadHost
1053
1105
  });
1054
1106
  }
1055
1107