@stackbit/cms-contentstack 0.1.1-staging.0

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.
Files changed (72) hide show
  1. package/README.md +1 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/contentstack-api-client.d.ts +63 -0
  4. package/dist/contentstack-api-client.d.ts.map +1 -0
  5. package/dist/contentstack-api-client.js +295 -0
  6. package/dist/contentstack-api-client.js.map +1 -0
  7. package/dist/contentstack-content-poller.d.ts +46 -0
  8. package/dist/contentstack-content-poller.d.ts.map +1 -0
  9. package/dist/contentstack-content-poller.js +111 -0
  10. package/dist/contentstack-content-poller.js.map +1 -0
  11. package/dist/contentstack-content-source.d.ts +138 -0
  12. package/dist/contentstack-content-source.d.ts.map +1 -0
  13. package/dist/contentstack-content-source.js +544 -0
  14. package/dist/contentstack-content-source.js.map +1 -0
  15. package/dist/contentstack-conversion-utils.d.ts +41 -0
  16. package/dist/contentstack-conversion-utils.d.ts.map +1 -0
  17. package/dist/contentstack-conversion-utils.js +504 -0
  18. package/dist/contentstack-conversion-utils.js.map +1 -0
  19. package/dist/contentstack-entries-converter.d.ts +39 -0
  20. package/dist/contentstack-entries-converter.d.ts.map +1 -0
  21. package/dist/contentstack-entries-converter.js +333 -0
  22. package/dist/contentstack-entries-converter.js.map +1 -0
  23. package/dist/contentstack-operation-converter.d.ts +42 -0
  24. package/dist/contentstack-operation-converter.d.ts.map +1 -0
  25. package/dist/contentstack-operation-converter.js +535 -0
  26. package/dist/contentstack-operation-converter.js.map +1 -0
  27. package/dist/contentstack-schema-converter.d.ts +26 -0
  28. package/dist/contentstack-schema-converter.d.ts.map +1 -0
  29. package/dist/contentstack-schema-converter.js +379 -0
  30. package/dist/contentstack-schema-converter.js.map +1 -0
  31. package/dist/contentstack-types.d.ts +429 -0
  32. package/dist/contentstack-types.d.ts.map +1 -0
  33. package/dist/contentstack-types.js +3 -0
  34. package/dist/contentstack-types.js.map +1 -0
  35. package/dist/contentstack-utils.d.ts +31 -0
  36. package/dist/contentstack-utils.d.ts.map +1 -0
  37. package/dist/contentstack-utils.js +144 -0
  38. package/dist/contentstack-utils.js.map +1 -0
  39. package/dist/entries-converter.d.ts +10 -0
  40. package/dist/entries-converter.d.ts.map +1 -0
  41. package/dist/entries-converter.js +245 -0
  42. package/dist/entries-converter.js.map +1 -0
  43. package/dist/file-download.d.ts +2 -0
  44. package/dist/file-download.d.ts.map +1 -0
  45. package/dist/file-download.js +33 -0
  46. package/dist/file-download.js.map +1 -0
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +14 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/schema-converter.d.ts +3 -0
  52. package/dist/schema-converter.d.ts.map +1 -0
  53. package/dist/schema-converter.js +169 -0
  54. package/dist/schema-converter.js.map +1 -0
  55. package/dist/transformation-utils.d.ts +41 -0
  56. package/dist/transformation-utils.d.ts.map +1 -0
  57. package/dist/transformation-utils.js +730 -0
  58. package/dist/transformation-utils.js.map +1 -0
  59. package/dist/types.d.ts +120 -0
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +3 -0
  62. package/dist/types.js.map +1 -0
  63. package/package.json +44 -0
  64. package/src/contentstack-api-client.ts +330 -0
  65. package/src/contentstack-content-poller.ts +157 -0
  66. package/src/contentstack-content-source.ts +687 -0
  67. package/src/contentstack-entries-converter.ts +438 -0
  68. package/src/contentstack-operation-converter.ts +703 -0
  69. package/src/contentstack-schema-converter.ts +486 -0
  70. package/src/contentstack-types.ts +527 -0
  71. package/src/contentstack-utils.ts +174 -0
  72. package/src/index.ts +3 -0
@@ -0,0 +1,544 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ContentstackContentSource = void 0;
7
+ const promises_1 = require("fs/promises");
8
+ const path_1 = __importDefault(require("path"));
9
+ const uuid_1 = require("uuid");
10
+ const lodash_1 = __importDefault(require("lodash"));
11
+ const types_1 = require("@stackbit/types");
12
+ const contentstack_api_client_1 = require("./contentstack-api-client");
13
+ const contentstack_schema_converter_1 = require("./contentstack-schema-converter");
14
+ const contentstack_entries_converter_1 = require("./contentstack-entries-converter");
15
+ const contentstack_operation_converter_1 = require("./contentstack-operation-converter");
16
+ const contentstack_utils_1 = require("./contentstack-utils");
17
+ const contentstack_content_poller_1 = require("./contentstack-content-poller");
18
+ class ContentstackContentSource {
19
+ constructor({ apiKey, managementToken, branch, authtoken, masterLocale, publishEnvironmentName, skipFetchOnStartIfCache }) {
20
+ this.useContentPoller = false;
21
+ this.contentPoller = null;
22
+ this.skipFetchOnStartIfCache = false;
23
+ this.updateCacheOnFirstPoll = false;
24
+ this.usersById = {};
25
+ this.apiKey = apiKey;
26
+ this.managementToken = managementToken;
27
+ this.branch = branch;
28
+ this.authtoken = authtoken;
29
+ this.masterLocale = masterLocale;
30
+ this.publishEnvironmentName = publishEnvironmentName;
31
+ if (skipFetchOnStartIfCache) {
32
+ this.skipFetchOnStartIfCache = true;
33
+ this.updateCacheOnFirstPoll = true;
34
+ }
35
+ }
36
+ async getVersion() {
37
+ return (0, types_1.getVersion)({ packageJsonPath: path_1.default.join(__dirname, '../package.json') });
38
+ }
39
+ getContentSourceType() {
40
+ return 'contentstack';
41
+ }
42
+ getProjectId() {
43
+ return this.apiKey;
44
+ }
45
+ getProjectEnvironment() {
46
+ var _a;
47
+ return (_a = this.branch) !== null && _a !== void 0 ? _a : 'main';
48
+ }
49
+ getProjectManageUrl() {
50
+ return (0, contentstack_utils_1.getContentstackDashboardUrl)({ apiKey: this.apiKey, branch: this.branch });
51
+ }
52
+ async init({ localDev, logger, userLogger, webhookUrl, cache }) {
53
+ var _a;
54
+ this.logger = logger.createLogger({ label: 'contentstack' });
55
+ this.userLogger = userLogger.createLogger({ label: 'contentstack' });
56
+ this.cache = cache;
57
+ this.logger.debug('init');
58
+ this.contentStackClient = new contentstack_api_client_1.ContentStackClient({
59
+ apiKey: this.apiKey,
60
+ managementToken: this.managementToken,
61
+ branch: this.branch,
62
+ logger: this.logger
63
+ });
64
+ // If running locally, use ContentPoller instead of webhook unless explicitly debugging webhooks
65
+ if (localDev && !webhookUrl) {
66
+ this.logger.info(`no webhookUrl provided, using content poller`);
67
+ this.useContentPoller = true;
68
+ }
69
+ else {
70
+ // if not a local dev, or webhook was provided, do not skip fetch on start
71
+ this.skipFetchOnStartIfCache = false;
72
+ this.updateCacheOnFirstPoll = false;
73
+ }
74
+ await this.reset();
75
+ await (0, contentstack_utils_1.createWebhookIfNeeded)({
76
+ webhookUrl,
77
+ publishEnvironmentName: this.publishEnvironment.name,
78
+ branch: this.branch,
79
+ isLocalDev: localDev,
80
+ contentStackClient: this.contentStackClient,
81
+ logger: this.logger
82
+ });
83
+ this.syncContext = (_a = (await this.cache.get('syncContext'))) !== null && _a !== void 0 ? _a : {};
84
+ }
85
+ async reset() {
86
+ const environments = await this.contentStackClient.getEnvironments();
87
+ this.publishEnvironment = (0, contentstack_utils_1.resolvePublishEnvironment)({
88
+ environments,
89
+ publishEnvironmentName: this.publishEnvironmentName,
90
+ logger: this.logger
91
+ });
92
+ if (this.authtoken) {
93
+ const stack = await this.contentStackClient.getStack(this.authtoken);
94
+ this.masterLocale = stack.master_locale;
95
+ await this.fetchUsers();
96
+ }
97
+ // The contentPoller updates its syncContext property internally when
98
+ // it gets an updated content. But, the actual cached data is not
99
+ // updated. Therefore, when content source module is restarted, we need
100
+ // to reset the contentPoller's internal syncContext, so it will be
101
+ // able to fetch all the updated content from its cached state.
102
+ if (this.contentPoller) {
103
+ this.contentPoller.setSyncContext(this.syncContext);
104
+ }
105
+ }
106
+ async destroy() { }
107
+ startWatchingContentUpdates() {
108
+ this.logger.debug('startWatchingContentUpdates');
109
+ if (!this.useContentPoller) {
110
+ return;
111
+ }
112
+ if (this.contentPoller) {
113
+ this.stopWatchingContentUpdates();
114
+ }
115
+ const { models } = this.cache.getSchema();
116
+ const modelNames = models.filter((model) => ['data', 'page'].includes(model.type)).map((model) => model.name);
117
+ this.contentPoller = new contentstack_content_poller_1.ContentPoller({
118
+ modelNames,
119
+ contentStackClient: this.contentStackClient,
120
+ syncContext: this.syncContext,
121
+ logger: this.logger,
122
+ notificationCallback: async (syncResult) => {
123
+ if (syncResult.contentTypes.length || syncResult.globalFields.length) {
124
+ this.logger.debug('schema was changed, invalidate schema');
125
+ this.cache.invalidateSchema();
126
+ }
127
+ else {
128
+ const result = await this.convertSyncResult(syncResult);
129
+ await this.cache.updateContent(result);
130
+ }
131
+ }
132
+ });
133
+ this.contentPoller.start();
134
+ }
135
+ stopWatchingContentUpdates() {
136
+ this.logger.debug('stopWatchingContentUpdates');
137
+ if (this.contentPoller) {
138
+ this.contentPoller.stop();
139
+ this.contentPoller = null;
140
+ }
141
+ }
142
+ async convertSyncResult(syncResult) {
143
+ var _a, _b;
144
+ if (this.updateCacheOnFirstPoll) {
145
+ if (syncResult.entries.length || syncResult.assets.length) {
146
+ if (syncResult.entries.length) {
147
+ const cachedEntries = (_a = (await this.cache.get('entries'))) !== null && _a !== void 0 ? _a : [];
148
+ this.syncContext.lastUpdatedEntryDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(syncResult.entries);
149
+ const entries = lodash_1.default.unionBy(syncResult.entries, cachedEntries, 'uid');
150
+ await this.cache.set('entries', entries);
151
+ }
152
+ if (syncResult.assets.length) {
153
+ const cachedAssets = (_b = (await this.cache.get('assets'))) !== null && _b !== void 0 ? _b : [];
154
+ this.syncContext.lastUpdatedAssetDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(syncResult.assets);
155
+ const assets = lodash_1.default.unionBy(syncResult.assets, cachedAssets, 'uid');
156
+ await this.cache.set('assets', assets);
157
+ }
158
+ await this.cache.set('syncContext', this.syncContext);
159
+ this.updateCacheOnFirstPoll = false;
160
+ }
161
+ }
162
+ if (this.authtoken) {
163
+ const hasMissingUser = [...syncResult.entries, ...syncResult.assets].some((entity) => (0, contentstack_utils_1.userMissingInMap)(this.usersById, entity));
164
+ if (hasMissingUser) {
165
+ await this.fetchUsers();
166
+ }
167
+ }
168
+ const documents = (0, contentstack_entries_converter_1.convertEntries)({
169
+ entries: syncResult.entries,
170
+ apiKey: this.apiKey,
171
+ getModelByName: this.cache.getModelByName,
172
+ usersById: this.usersById,
173
+ publishEnvironment: this.publishEnvironment,
174
+ logger: this.logger
175
+ });
176
+ const assets = (0, contentstack_entries_converter_1.convertAssets)({
177
+ assets: syncResult.assets,
178
+ apiKey: this.apiKey,
179
+ usersById: this.usersById,
180
+ publishEnvironment: this.publishEnvironment
181
+ });
182
+ return {
183
+ documents,
184
+ assets,
185
+ deletedDocumentIds: syncResult.deletedEntries.map((entry) => entry.uid),
186
+ deletedAssetIds: syncResult.deletedAssets.map((asset) => asset.uid)
187
+ };
188
+ }
189
+ async fetchUsers() {
190
+ if (this.authtoken) {
191
+ const users = await this.contentStackClient.getUsers(this.authtoken);
192
+ this.usersById = lodash_1.default.keyBy(users, 'uid');
193
+ }
194
+ }
195
+ async getSchema() {
196
+ this.logger.debug('getSchema');
197
+ const [globalFields, contentTypes, contentStackLocales] = await Promise.all([
198
+ this.contentStackClient.getGlobalFields(),
199
+ this.contentStackClient.getContentTypes(),
200
+ this.contentStackClient.getLocales()
201
+ ]);
202
+ const models = (0, contentstack_schema_converter_1.convertModels)({ contentStackModels: [...globalFields, ...contentTypes] });
203
+ const locales = (0, contentstack_schema_converter_1.convertLocales)({ contentStackLocales, masterLocale: this.masterLocale, logger: this.logger });
204
+ // Check if one of the content types was changed from the last time the
205
+ // content types were fetched, in which case remove all cached content.
206
+ const lastUpdatedContentTypeDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(contentTypes);
207
+ const lastUpdatedGlobalFieldDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(globalFields);
208
+ if (this.syncContext.lastUpdatedContentTypeDate !== lastUpdatedContentTypeDate ||
209
+ this.syncContext.lastUpdatedGlobalFieldDate !== lastUpdatedGlobalFieldDate) {
210
+ this.logger.debug(`last updated content type date '${lastUpdatedContentTypeDate}' is different from cached ` +
211
+ `syncContext.lastUpdatedContentTypeDate '${this.syncContext.lastUpdatedContentTypeDate}', ` +
212
+ `or last updated global field date '${lastUpdatedGlobalFieldDate}' is different from cached ` +
213
+ `syncContext.lastUpdatedGlobalFieldDate '${this.syncContext.lastUpdatedGlobalFieldDate}', ` +
214
+ `clearing cache`);
215
+ await this.cache.remove('entries');
216
+ await this.cache.remove('assets');
217
+ this.skipFetchOnStartIfCache = false;
218
+ this.updateCacheOnFirstPoll = false;
219
+ this.syncContext = { lastUpdatedContentTypeDate, lastUpdatedGlobalFieldDate };
220
+ await this.cache.set('syncContext', this.syncContext);
221
+ }
222
+ this.logger.debug(`got ${contentTypes.length} content types, ${globalFields.length} global fields, ${locales.length} locales`);
223
+ return {
224
+ models,
225
+ locales,
226
+ context: null
227
+ };
228
+ }
229
+ async getDocuments() {
230
+ var _a;
231
+ this.logger.debug('getDocuments');
232
+ const { models } = this.cache.getSchema();
233
+ const modelNames = models.filter((model) => ['data', 'page'].includes(model.type)).map((model) => model.name);
234
+ let entries;
235
+ const cachedEntries = (_a = (await this.cache.get('entries'))) !== null && _a !== void 0 ? _a : [];
236
+ try {
237
+ if (this.syncContext.lastUpdatedEntryDate && cachedEntries) {
238
+ entries = cachedEntries;
239
+ if (!this.skipFetchOnStartIfCache) {
240
+ this.logger.debug(`got ${cachedEntries.length} entries from cache, fetching entries updated after ${this.syncContext.lastUpdatedEntryDate}`);
241
+ const updatedEntries = await this.contentStackClient.getAllEntriesUpdatedAfter(modelNames, this.syncContext.lastUpdatedEntryDate);
242
+ this.logger.debug(`got ${updatedEntries.length} updated/created entries after ${this.syncContext.lastUpdatedEntryDate}`);
243
+ if (updatedEntries.length) {
244
+ this.syncContext.lastUpdatedEntryDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(updatedEntries);
245
+ entries = lodash_1.default.unionBy(updatedEntries, cachedEntries, 'uid');
246
+ await this.cache.set('entries', entries);
247
+ }
248
+ }
249
+ }
250
+ else {
251
+ entries = await this.contentStackClient.getAllEntries(modelNames);
252
+ await this.cache.set('entries', entries);
253
+ this.syncContext.lastUpdatedEntryDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(entries);
254
+ }
255
+ }
256
+ catch (error) {
257
+ // Stackbit won't be able to work properly even if one of the entries was not fetched.
258
+ // All api methods use Contentstack's API client that handles errors and retries automatically.
259
+ this.logger.error(`Failed fetching documents from Contentstack, error: ${error.message}`);
260
+ throw new Error(`Failed fetching documents from Contentstack, error: ${error.message}`);
261
+ }
262
+ await this.cache.set('syncContext', this.syncContext);
263
+ // TODO: localization: fetch entries per locale, and merge them into localized fields of a single document
264
+ const documents = (0, contentstack_entries_converter_1.convertEntries)({
265
+ entries,
266
+ apiKey: this.apiKey,
267
+ getModelByName: this.cache.getModelByName,
268
+ usersById: this.usersById,
269
+ publishEnvironment: this.publishEnvironment,
270
+ logger: this.logger
271
+ });
272
+ this.logger.debug(`got ${documents.length} documents`);
273
+ return documents;
274
+ }
275
+ async getAssets() {
276
+ var _a;
277
+ this.logger.debug('getAssets');
278
+ let assets;
279
+ const cachedAssets = (_a = (await this.cache.get('assets'))) !== null && _a !== void 0 ? _a : [];
280
+ try {
281
+ if (this.syncContext.lastUpdatedAssetDate && cachedAssets) {
282
+ assets = cachedAssets;
283
+ if (!this.skipFetchOnStartIfCache) {
284
+ this.logger.debug(`got ${cachedAssets.length} assets from cache, fetching assets updated after ${this.syncContext.lastUpdatedAssetDate}`);
285
+ const updatedAssets = await this.contentStackClient.getAssetsUpdatedAfter(this.syncContext.lastUpdatedAssetDate);
286
+ this.logger.debug(`got ${updatedAssets.length} updated/created assets after ${this.syncContext.lastUpdatedAssetDate}`);
287
+ if (updatedAssets.length) {
288
+ this.syncContext.lastUpdatedAssetDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(updatedAssets);
289
+ assets = lodash_1.default.unionBy(updatedAssets, cachedAssets, 'uid');
290
+ await this.cache.set('assets', assets);
291
+ }
292
+ }
293
+ }
294
+ else {
295
+ assets = await this.contentStackClient.getAssets();
296
+ await this.cache.set('assets', assets);
297
+ this.syncContext.lastUpdatedAssetDate = (0, contentstack_content_poller_1.getLastUpdatedEntityDate)(assets);
298
+ }
299
+ }
300
+ catch (error) {
301
+ // Stackbit won't be able to work properly even if one of the entries or the assets was not fetched.
302
+ // All api methods use Contentstack's API client that handles errors and retries automatically.
303
+ this.logger.error(`Failed fetching assets from Contentstack, error: ${error.message}`);
304
+ throw new Error(`Failed fetching assets from Contentstack, error: ${error.message}`);
305
+ }
306
+ await this.cache.set('syncContext', this.syncContext);
307
+ const stackbitAssets = (0, contentstack_entries_converter_1.convertAssets)({
308
+ assets: assets,
309
+ apiKey: this.apiKey,
310
+ usersById: this.usersById,
311
+ publishEnvironment: this.publishEnvironment
312
+ });
313
+ this.logger.debug(`got ${stackbitAssets.length} documents`);
314
+ return stackbitAssets;
315
+ }
316
+ async hasAccess(options) {
317
+ // TODO: add ContentStack OAuth and validate user's access to the current stack/branch
318
+ return {
319
+ hasConnection: true,
320
+ hasPermissions: true
321
+ };
322
+ }
323
+ async createDocument(options) {
324
+ this.logger.debug('createDocument');
325
+ const entry = (0, contentstack_operation_converter_1.createEntryFromOperationFields)({
326
+ updateOperationFields: options.updateOperationFields,
327
+ model: options.model,
328
+ getDocumentById: this.cache.getDocumentById,
329
+ getModelByName: this.cache.getModelByName,
330
+ logger: this.logger
331
+ });
332
+ const newEntry = await this.contentStackClient.createEntry(options.model.name, entry);
333
+ return { documentId: newEntry.uid };
334
+ }
335
+ async updateDocument(options) {
336
+ this.logger.debug('updateDocument');
337
+ const { document, operations } = options;
338
+ const entry = await this.contentStackClient.getEntry(document.modelName, document.id);
339
+ const updatedEntry = (0, contentstack_operation_converter_1.updateEntryFromUpdateOperations)({
340
+ entry,
341
+ updateOperations: operations,
342
+ getDocumentById: this.cache.getDocumentById,
343
+ getModelByName: this.cache.getModelByName,
344
+ logger: this.logger
345
+ });
346
+ await this.contentStackClient.updateEntry(updatedEntry);
347
+ }
348
+ async deleteDocument(options) {
349
+ this.logger.debug('deleteDocument');
350
+ await this.contentStackClient.deleteEntry(options.document.modelName, options.document.id);
351
+ }
352
+ async uploadAsset(options) {
353
+ var _a, _b;
354
+ this.logger.debug('uploadAsset');
355
+ const tempName = `${(0, uuid_1.v4)()}-${options.fileName}`;
356
+ let asset;
357
+ try {
358
+ if (options.base64) {
359
+ // TODO: write to .stackbit/cache folder
360
+ await (0, promises_1.writeFile)(tempName, Buffer.from(options.base64, 'base64'));
361
+ }
362
+ else {
363
+ await (0, contentstack_utils_1.downloadFile)(options.url, tempName);
364
+ }
365
+ asset = await this.contentStackClient.uploadImage(tempName, options.fileName);
366
+ const locales = (_a = this.cache.getSchema().locales) !== null && _a !== void 0 ? _a : [];
367
+ const defaultLocale = (_b = locales.find((locale) => locale.default)) === null || _b === void 0 ? void 0 : _b.code;
368
+ await asset.publish({
369
+ publishDetails: {
370
+ environments: [this.publishEnvironment.name],
371
+ locales: [defaultLocale]
372
+ },
373
+ locale: defaultLocale
374
+ });
375
+ }
376
+ finally {
377
+ await (0, promises_1.unlink)(tempName);
378
+ }
379
+ this.logger.debug(`uploaded asset, new asset id: ${asset.uid}`);
380
+ return (0, contentstack_entries_converter_1.convertAsset)({
381
+ asset,
382
+ apiKey: this.apiKey,
383
+ usersById: this.usersById,
384
+ publishEnvironment: this.publishEnvironment
385
+ });
386
+ }
387
+ async validateDocuments(options) {
388
+ const validations = [];
389
+ return { errors: validations };
390
+ }
391
+ async publishDocuments(options) {
392
+ this.logger.debug('publishDocuments');
393
+ await this.contentStackClient.publishDocuments({
394
+ documents: options.documents,
395
+ publishEnvironmentName: this.publishEnvironment.name
396
+ });
397
+ }
398
+ async onWebhook(data) {
399
+ var _a, _b, _c, _d, _e, _f;
400
+ const webhookData = data.data;
401
+ const updates = {
402
+ assets: [],
403
+ documents: [],
404
+ deletedDocumentIds: [],
405
+ deletedAssetIds: []
406
+ };
407
+ // check that the webhook is related to the current branch, if not ignore
408
+ if (this.branch && this.branch !== webhookData.data.branch.uid) {
409
+ return;
410
+ }
411
+ this.logger.debug(`got webhook for ${webhookData.event} ${webhookData.module}`);
412
+ if (webhookData.module === 'entry') {
413
+ switch (webhookData.event) {
414
+ case 'create':
415
+ case 'update': {
416
+ if ((0, contentstack_utils_1.userMissingInMap)(this.usersById, webhookData.data.entry)) {
417
+ await this.fetchUsers();
418
+ }
419
+ const document = (0, contentstack_entries_converter_1.convertEntry)({
420
+ entry: {
421
+ ...webhookData.data.entry,
422
+ content_type_uid: webhookData.data.content_type.uid,
423
+ publish_details: [],
424
+ _branch: webhookData.data.branch.uid
425
+ },
426
+ status: webhookData.event === 'create' ? 'added' : 'modified',
427
+ apiKey: this.apiKey,
428
+ getModelByName: this.cache.getModelByName,
429
+ usersById: this.usersById,
430
+ publishEnvironment: this.publishEnvironment,
431
+ logger: this.logger
432
+ });
433
+ updates.documents.push(document);
434
+ break;
435
+ }
436
+ case 'publish': {
437
+ if (webhookData.data.environment.uid !== this.publishEnvironment.uid) {
438
+ this.logger.debug(`entry was published in an environment '${webhookData.data.environment.name}' ` +
439
+ `different from the publish environment '${this.publishEnvironment.name}', ignoring the webhook'`);
440
+ break;
441
+ }
442
+ if ((0, contentstack_utils_1.userMissingInMap)(this.usersById, webhookData.data.entry)) {
443
+ await this.fetchUsers();
444
+ }
445
+ const document = (0, contentstack_entries_converter_1.convertEntry)({
446
+ entry: {
447
+ ...webhookData.data.entry,
448
+ content_type_uid: webhookData.data.content_type.uid,
449
+ publish_details: [],
450
+ _branch: webhookData.data.branch.uid
451
+ },
452
+ status: 'published',
453
+ apiKey: this.apiKey,
454
+ getModelByName: this.cache.getModelByName,
455
+ usersById: this.usersById,
456
+ publishEnvironment: this.publishEnvironment,
457
+ logger: this.logger
458
+ });
459
+ updates.documents.push(document);
460
+ break;
461
+ }
462
+ case 'unpublish':
463
+ if (webhookData.data.environment.uid !== this.publishEnvironment.uid) {
464
+ this.logger.debug(`entry was published in an environment '${webhookData.data.environment.name}' ` +
465
+ `different from the publish environment '${this.publishEnvironment.name}', ignoring the webhook'`);
466
+ break;
467
+ }
468
+ updates.deletedDocumentIds.push(webhookData.data.entry.uid);
469
+ break;
470
+ case 'delete':
471
+ updates.deletedDocumentIds.push(webhookData.data.entry.uid);
472
+ break;
473
+ }
474
+ }
475
+ else if (webhookData.module === 'asset') {
476
+ switch (webhookData.event) {
477
+ case 'create':
478
+ case 'update': {
479
+ if ((0, contentstack_utils_1.userMissingInMap)(this.usersById, webhookData.data.asset)) {
480
+ await this.fetchUsers();
481
+ }
482
+ const asset = (0, contentstack_entries_converter_1.convertAsset)({
483
+ asset: {
484
+ ...webhookData.data.asset,
485
+ publish_details: [],
486
+ _branch: webhookData.data.branch.uid
487
+ },
488
+ apiKey: this.apiKey,
489
+ usersById: this.usersById,
490
+ publishEnvironment: this.publishEnvironment
491
+ });
492
+ updates.assets.push(asset);
493
+ break;
494
+ }
495
+ case 'publish': {
496
+ if (webhookData.data.environment.uid !== this.publishEnvironment.uid) {
497
+ this.logger.debug(`asset was published in an environment '${webhookData.data.environment.name}' ` +
498
+ `different from the publish environment '${this.publishEnvironment.name}', ignoring the webhook'`);
499
+ return;
500
+ }
501
+ if ((0, contentstack_utils_1.userMissingInMap)(this.usersById, webhookData.data.asset)) {
502
+ await this.fetchUsers();
503
+ }
504
+ const asset = (0, contentstack_entries_converter_1.convertAsset)({
505
+ asset: {
506
+ ...webhookData.data.asset,
507
+ publish_details: [],
508
+ _branch: webhookData.data.branch.uid
509
+ },
510
+ apiKey: this.apiKey,
511
+ usersById: this.usersById,
512
+ publishEnvironment: this.publishEnvironment
513
+ });
514
+ updates.assets.push(asset);
515
+ break;
516
+ }
517
+ case 'unpublish':
518
+ if (webhookData.data.environment.uid !== this.publishEnvironment.uid) {
519
+ this.logger.debug(`asset was published in an environment '${webhookData.data.environment.name}' ` +
520
+ `different from the publish environment '${this.publishEnvironment.name}', ignoring the webhook'`);
521
+ return;
522
+ }
523
+ (_a = updates.deletedAssetIds) === null || _a === void 0 ? void 0 : _a.push(webhookData.data.asset.uid);
524
+ break;
525
+ case 'delete':
526
+ (_b = updates.deletedAssetIds) === null || _b === void 0 ? void 0 : _b.push(webhookData.data.asset.uid);
527
+ break;
528
+ }
529
+ }
530
+ else if (webhookData.module === 'content_type' || webhookData.module === 'global_field') {
531
+ this.logger.debug(`webhook for '${webhookData.module}' invalidate schema`);
532
+ this.cache.invalidateSchema();
533
+ return;
534
+ }
535
+ this.logger.debug(`update content from webhook, ` +
536
+ `documents: ${(_c = updates.documents) === null || _c === void 0 ? void 0 : _c.length}, ` +
537
+ `assets: ${(_d = updates.assets) === null || _d === void 0 ? void 0 : _d.length}, ` +
538
+ `deleted documents: ${(_e = updates.deletedDocumentIds) === null || _e === void 0 ? void 0 : _e.length}, ` +
539
+ `deleted assets: ${(_f = updates.deletedAssetIds) === null || _f === void 0 ? void 0 : _f.length}`);
540
+ this.cache.updateContent(updates);
541
+ }
542
+ }
543
+ exports.ContentstackContentSource = ContentstackContentSource;
544
+ //# sourceMappingURL=contentstack-content-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentstack-content-source.js","sourceRoot":"","sources":["../src/contentstack-content-source.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAgD;AAChD,gDAAwB;AACxB,+BAAoC;AACpC,oDAAuB;AAEvB,2CAA4E;AAC5E,uEAA+D;AAC/D,mFAAgH;AAChH,qFAQ0C;AAC1C,yFAAqH;AACrH,6DAAqJ;AACrJ,+EAAiH;AAgDjH,MAAa,yBAAyB;IAqBlC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,EAAE,uBAAuB,EAA6B;QAT5I,qBAAgB,GAAY,KAAK,CAAC;QAClC,kBAAa,GAAyB,IAAI,C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C;QACF,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACJ;AA3mBD,8DA2mBC"}
@@ -0,0 +1,41 @@
1
+ import * as StackbitTypes from '@stackbit/types';
2
+ import { EntryData } from '@contentstack/management/types/stack/contentType/entry';
3
+ import { Entry } from './contentstack-types';
4
+ import { ModelWithContext } from './contentstack-schema-converter';
5
+ import { DocumentWithContext } from './contentstack-entries-converter';
6
+ declare type GetModelByName = (modelName: string) => ModelWithContext | undefined;
7
+ declare type GetDocumentById = (documentId: string) => DocumentWithContext | undefined;
8
+ export declare function createEntryFromOperationFields({ updateOperationFields, model, getDocumentById, getModelByName, logger }: {
9
+ updateOperationFields: Record<string, StackbitTypes.UpdateOperationField>;
10
+ model: ModelWithContext;
11
+ getDocumentById: GetDocumentById;
12
+ getModelByName: GetModelByName;
13
+ logger: StackbitTypes.Logger;
14
+ }): EntryData;
15
+ export declare function updateEntryFromUpdateOperations({ entry, updateOperations, getDocumentById, getModelByName, logger }: {
16
+ entry: Entry;
17
+ updateOperations: StackbitTypes.UpdateOperation[];
18
+ getDocumentById: GetDocumentById;
19
+ getModelByName: GetModelByName;
20
+ logger: StackbitTypes.Logger;
21
+ }): Entry;
22
+ export declare function getUpdatedEntryAtFieldPathWithOperation({ entry, updateOperation, model, getDocumentById, getModelByName, logger }: {
23
+ entry: Entry;
24
+ updateOperation: StackbitTypes.UpdateOperation;
25
+ model: ModelWithContext;
26
+ getDocumentById: GetDocumentById;
27
+ getModelByName: GetModelByName;
28
+ logger: StackbitTypes.Logger;
29
+ }): Entry;
30
+ export declare function convertOperationFieldValue({ updateOperationField, rootModel, modelField, entryFieldPath, modelFieldPath, getDocumentById, getModelByName, errorPrefix }: {
31
+ updateOperationField: StackbitTypes.UpdateOperationField;
32
+ rootModel: ModelWithContext;
33
+ modelField: StackbitTypes.FieldSpecificProps;
34
+ entryFieldPath: (string | number)[];
35
+ modelFieldPath: string[];
36
+ getDocumentById: GetDocumentById;
37
+ getModelByName: GetModelByName;
38
+ errorPrefix: string;
39
+ }): any;
40
+ export {};
41
+ //# sourceMappingURL=contentstack-conversion-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentstack-conversion-utils.d.ts","sourceRoot":"","sources":["../src/contentstack-conversion-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AAEnF,OAAO,EAAE,KAAK,EAAS,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,aAAK,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAC1E,aAAK,eAAe,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,mBAAmB,GAAG,SAAS,CAAC;AAE/E,wBAAgB,8BAA8B,CAAC,EAC3C,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,cAAc,EACd,MAAM,EACT,EAAE;IACC,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;IAC1E,KAAK,EAAE,gBAAgB,CAAC;IACxB,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;CAChC,GAAG,SAAS,CAsBZ;AAED,wBAAgB,+BAA+B,CAAC,EAC5C,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,MAAM,EACT,EAAE;IACC,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,aAAa,CAAC,eAAe,EAAE,CAAC;IAClD,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,aAAa,CA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