@stackbit/cms-core 1.0.13-develop.1 → 1.0.13-develop.2
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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/annotator/html.js +1 -0
- package/dist/annotator/html.js.map +1 -1
- package/dist/annotator/index.js +2 -1
- package/dist/annotator/index.js.map +1 -1
- package/dist/annotator/react.js +1 -0
- package/dist/annotator/react.js.map +1 -1
- package/dist/connector/ConnectorWrapper.d.mts +62 -0
- package/dist/connector/ConnectorWrapper.d.mts.map +1 -0
- package/dist/connector/ConnectorWrapper.mjs +163 -0
- package/dist/connector/ConnectorWrapper.mjs.map +1 -0
- package/dist/connector/ModelConverter.d.mts +3 -0
- package/dist/connector/ModelConverter.d.mts.map +1 -0
- package/dist/connector/ModelConverter.mjs +125 -0
- package/dist/connector/ModelConverter.mjs.map +1 -0
- package/dist/connector/connector-wrapper.d.mts +102 -0
- package/dist/connector/connector-wrapper.d.mts.map +1 -0
- package/dist/connector/connector-wrapper.mjs +152 -0
- package/dist/connector/connector-wrapper.mjs.map +1 -0
- package/dist/connector/model-converter.d.mts +3 -0
- package/dist/connector/model-converter.d.mts.map +1 -0
- package/dist/connector/model-converter.mjs +138 -0
- package/dist/connector/model-converter.mjs.map +1 -0
- package/dist/consts.d.ts +8 -5
- package/dist/consts.d.ts.map +1 -1
- package/dist/consts.js +14 -9
- package/dist/consts.js.map +1 -1
- package/dist/content-store-utils.js +10 -13
- package/dist/content-store-utils.js.map +1 -1
- package/dist/content-store.d.ts +1 -1
- package/dist/content-store.d.ts.map +1 -1
- package/dist/content-store.js +163 -197
- package/dist/content-store.js.map +1 -1
- package/dist/integration/IntegrationContentSourceWrapper.d.mts +62 -0
- package/dist/integration/IntegrationContentSourceWrapper.d.mts.map +1 -0
- package/dist/integration/IntegrationContentSourceWrapper.d.ts +2 -0
- package/dist/integration/IntegrationContentSourceWrapper.d.ts.map +1 -0
- package/dist/integration/IntegrationContentSourceWrapper.js +3 -0
- package/dist/integration/IntegrationContentSourceWrapper.js.map +1 -0
- package/dist/integration/IntegrationContentSourceWrapper.mjs +161 -0
- package/dist/integration/IntegrationContentSourceWrapper.mjs.map +1 -0
- package/dist/integration/IntegrationWrapper.d.mts +62 -0
- package/dist/integration/IntegrationWrapper.d.mts.map +1 -0
- package/dist/integration/IntegrationWrapper.mjs +164 -0
- package/dist/integration/IntegrationWrapper.mjs.map +1 -0
- package/dist/integration/ModelConverter.d.mts +3 -0
- package/dist/integration/ModelConverter.d.mts.map +1 -0
- package/dist/integration/ModelConverter.mjs +125 -0
- package/dist/integration/ModelConverter.mjs.map +1 -0
- package/dist/services/git.js +2 -2
- package/dist/services/git.js.map +1 -1
- package/dist/services/run.d.ts +1 -0
- package/dist/services/run.d.ts.map +1 -1
- package/dist/services/run.js +6 -6
- package/dist/services/run.js.map +1 -1
- package/dist/utils/asset-sources-utils.js +14 -17
- package/dist/utils/asset-sources-utils.js.map +1 -1
- package/dist/utils/backward-compatibility.js +2 -4
- package/dist/utils/backward-compatibility.js.map +1 -1
- package/dist/utils/config-delegate.js +5 -7
- package/dist/utils/config-delegate.js.map +1 -1
- package/dist/utils/create-update-csi-docs.js +13 -13
- package/dist/utils/create-update-csi-docs.js.map +1 -1
- package/dist/utils/csi-to-store-docs-converter.js +49 -61
- package/dist/utils/csi-to-store-docs-converter.js.map +1 -1
- package/dist/utils/custom-actions.js +26 -31
- package/dist/utils/custom-actions.js.map +1 -1
- package/dist/utils/document-hooks.js +12 -24
- package/dist/utils/document-hooks.js.map +1 -1
- package/dist/utils/duplicate-document.js +6 -7
- package/dist/utils/duplicate-document.js.map +1 -1
- package/dist/utils/file-cache.js +1 -1
- package/dist/utils/file-cache.js.map +1 -1
- package/dist/utils/filtered-entities.js +1 -1
- package/dist/utils/filtered-entities.js.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/meta-fields-filters.js +5 -9
- package/dist/utils/meta-fields-filters.js.map +1 -1
- package/dist/utils/model-utils.js +4 -7
- package/dist/utils/model-utils.js.map +1 -1
- package/dist/utils/preset-utils.js +18 -19
- package/dist/utils/preset-utils.js.map +1 -1
- package/dist/utils/search-utils.js +40 -51
- package/dist/utils/search-utils.js.map +1 -1
- package/dist/utils/site-map.js +9 -14
- package/dist/utils/site-map.js.map +1 -1
- package/dist/utils/store-to-api-docs-converter.js +14 -17
- package/dist/utils/store-to-api-docs-converter.js.map +1 -1
- package/dist/utils/store-to-api-v2-docs-converter.js +15 -19
- package/dist/utils/store-to-api-v2-docs-converter.js.map +1 -1
- package/dist/utils/timer.js +2 -3
- package/dist/utils/timer.js.map +1 -1
- package/dist/utils/tree-views.js +5 -7
- package/dist/utils/tree-views.js.map +1 -1
- package/package.json +8 -7
- package/src/connector/connector-wrapper.mts +219 -0
- package/src/connector/model-converter.mts +162 -0
- package/src/consts.js +31 -0
- package/src/content-store.ts +51 -33
- package/src/consts.ts +0 -21
package/dist/content-store.js
CHANGED
|
@@ -83,25 +83,24 @@ class ContentStore {
|
|
|
83
83
|
argsResolver: ({ nextArgs, prevArgs }) => {
|
|
84
84
|
// If at least one call had "init: true" then call the deferred
|
|
85
85
|
// function with "init: true" and without contentSourceIds.
|
|
86
|
-
const init = nextArgs[0].init || Boolean(prevArgs
|
|
86
|
+
const init = nextArgs[0].init || Boolean(prevArgs?.[0].init);
|
|
87
87
|
if (init) {
|
|
88
88
|
return [{ init }];
|
|
89
89
|
}
|
|
90
90
|
// If at least one call had "startWatchingContentUpdates: true" then call the deferred
|
|
91
91
|
// function with "startWatchingContentUpdates: true".
|
|
92
|
-
const startWatchingContentUpdates = nextArgs[0].startWatchingContentUpdates || Boolean(prevArgs
|
|
92
|
+
const startWatchingContentUpdates = nextArgs[0].startWatchingContentUpdates || Boolean(prevArgs?.[0].startWatchingContentUpdates);
|
|
93
93
|
// If at least one call had "contentSourceIds: undefined" (signal to reload all content sources)
|
|
94
94
|
// then call the deferred function with "contentSourceIds: undefined",
|
|
95
95
|
// otherwise call it with union of content source ids.
|
|
96
96
|
const contentSourceIds = typeof nextArgs[0].contentSourceIds === 'undefined' || (prevArgs && typeof prevArgs[0].contentSourceIds === 'undefined')
|
|
97
97
|
? undefined
|
|
98
|
-
: lodash_1.default.union(nextArgs[0].contentSourceIds, prevArgs
|
|
98
|
+
: lodash_1.default.union(nextArgs[0].contentSourceIds, prevArgs?.[0].contentSourceIds);
|
|
99
99
|
return [{ init, startWatchingContentUpdates, contentSourceIds }];
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
103
|
async init({ stackbitConfig }) {
|
|
104
|
-
var _a;
|
|
105
104
|
this.logger.debug('init');
|
|
106
105
|
this.stackbitConfig = stackbitConfig;
|
|
107
106
|
if (stackbitConfig) {
|
|
@@ -110,14 +109,13 @@ class ContentStore {
|
|
|
110
109
|
}
|
|
111
110
|
else {
|
|
112
111
|
this.yamlModels = await this.loadYamlModels({ stackbitConfig });
|
|
113
|
-
this.configModels = this.mergeConfigModels(
|
|
112
|
+
this.configModels = this.mergeConfigModels(stackbitConfig.models ?? [], this.yamlModels);
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
115
|
await this.loadContentSourcesAndProcessData({ init: true });
|
|
117
116
|
this.contentUpdatesWatchTimer.startTimer();
|
|
118
117
|
}
|
|
119
118
|
async onStackbitConfigChange({ stackbitConfig }) {
|
|
120
|
-
var _a;
|
|
121
119
|
this.logger.debug('onStackbitConfigChange');
|
|
122
120
|
this.stackbitConfig = stackbitConfig;
|
|
123
121
|
if (stackbitConfig) {
|
|
@@ -125,7 +123,7 @@ class ContentStore {
|
|
|
125
123
|
this.modelExtensions = stackbitConfig.modelExtensions;
|
|
126
124
|
}
|
|
127
125
|
else {
|
|
128
|
-
this.configModels = this.mergeConfigModels(
|
|
126
|
+
this.configModels = this.mergeConfigModels(stackbitConfig.models ?? [], this.yamlModels);
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
129
|
await this.loadContentSourcesAndProcessData({ init: true });
|
|
@@ -139,9 +137,8 @@ class ContentStore {
|
|
|
139
137
|
* reducing the CMS API usage.
|
|
140
138
|
*/
|
|
141
139
|
handleTimerTimeout() {
|
|
142
|
-
var _a;
|
|
143
140
|
for (const contentSourceInstance of this.contentSources) {
|
|
144
|
-
|
|
141
|
+
contentSourceInstance.stopWatchingContentUpdates?.();
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
144
|
/**
|
|
@@ -159,18 +156,13 @@ class ContentStore {
|
|
|
159
156
|
await this.loadContentSourcesAndProcessData({ init: false, startWatchingContentUpdates: true });
|
|
160
157
|
}
|
|
161
158
|
async destroy() {
|
|
162
|
-
var _a, _b, _c, _d;
|
|
163
159
|
this.contentUpdatesWatchTimer.stopTimer();
|
|
164
|
-
(_a = this.contentEngine) === null || _a === void 0 ? void 0 : _a.clearListeners();
|
|
165
|
-
await ((_b = this.contentEngine) === null || _b === void 0 ? void 0 : _b.stop());
|
|
166
|
-
this.contentEngine = null;
|
|
167
160
|
for (const contentSourceInstance of this.contentSources) {
|
|
168
|
-
|
|
169
|
-
await
|
|
161
|
+
contentSourceInstance.stopWatchingContentUpdates?.();
|
|
162
|
+
await contentSourceInstance.destroy?.();
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
165
|
async onFilesChange(updatedFiles) {
|
|
173
|
-
var _a;
|
|
174
166
|
this.logger.debug('onFilesChange');
|
|
175
167
|
if (this.stackbitConfig && !this.stackbitConfig.modelExtensions) {
|
|
176
168
|
// Check if any of the yaml models files were changed. If yaml model files were changed,
|
|
@@ -180,7 +172,7 @@ class ContentStore {
|
|
|
180
172
|
if (yamlModelsChanged) {
|
|
181
173
|
this.logger.debug('identified change in stackbit model files');
|
|
182
174
|
this.yamlModels = await this.loadYamlModels({ stackbitConfig: this.stackbitConfig });
|
|
183
|
-
this.configModels = this.mergeConfigModels(
|
|
175
|
+
this.configModels = this.mergeConfigModels(this.stackbitConfig.models ?? [], this.yamlModels);
|
|
184
176
|
this.pushContentSourceEvent({
|
|
185
177
|
eventName: ContentStoreEventType.YamlModelFilesChange
|
|
186
178
|
});
|
|
@@ -201,7 +193,7 @@ class ContentStore {
|
|
|
201
193
|
for (const contentSourceInstance of this.contentSources) {
|
|
202
194
|
const contentSourceId = (0, content_store_utils_1.getContentSourceIdForContentSource)(contentSourceInstance);
|
|
203
195
|
const contentSourceData = this.contentSourceDataById[contentSourceId];
|
|
204
|
-
if (contentSourceData
|
|
196
|
+
if (contentSourceData?.destroyed) {
|
|
205
197
|
this.logger.debug(`contentSource '${contentSourceId}' was destroyed, don't call onFilesChange`);
|
|
206
198
|
continue;
|
|
207
199
|
}
|
|
@@ -243,8 +235,7 @@ class ContentStore {
|
|
|
243
235
|
return configModelsResult.models;
|
|
244
236
|
}
|
|
245
237
|
async loadPresetsFromConfig({ stackbitConfig }) {
|
|
246
|
-
|
|
247
|
-
const contentSources = (_a = stackbitConfig === null || stackbitConfig === void 0 ? void 0 : stackbitConfig.contentSources) !== null && _a !== void 0 ? _a : [];
|
|
238
|
+
const contentSources = stackbitConfig?.contentSources ?? [];
|
|
248
239
|
const singleContentSource = contentSources.length === 1 ? contentSources[0] : null;
|
|
249
240
|
const presetResult = await (0, sdk_1.loadPresets)({
|
|
250
241
|
config: stackbitConfig,
|
|
@@ -284,32 +275,26 @@ class ContentStore {
|
|
|
284
275
|
* of these plugin definitions and creates the content engine.
|
|
285
276
|
*/
|
|
286
277
|
async createContentEngineIfNeeded() {
|
|
287
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
288
278
|
const logger = this.userLogger.createLogger({ label: 'content-engine' });
|
|
289
279
|
if (this.contentEngine) {
|
|
290
|
-
logger.
|
|
291
|
-
|
|
292
|
-
await this.contentEngine.stop();
|
|
293
|
-
this.contentEngine = null;
|
|
280
|
+
logger.debug(`Content Engine already exists, cannot recreate it as it's running in this process. To recreate it with updated config options the current process must be restarted.`);
|
|
281
|
+
return;
|
|
294
282
|
}
|
|
295
|
-
const
|
|
283
|
+
const contentSources = this.contentSources || [];
|
|
284
|
+
const plugins = Array.from(new Set(contentSources.flatMap((contentSource) => contentSource.getContentEngineConfig?.()?.plugins).filter(Boolean)));
|
|
296
285
|
if (plugins.length < 1) {
|
|
297
286
|
return;
|
|
298
287
|
}
|
|
299
|
-
logger.info('
|
|
288
|
+
logger.info('Creating content engine');
|
|
300
289
|
this.contentEngine = (0, content_engine_1.contentEngine)({
|
|
301
|
-
directory:
|
|
302
|
-
port:
|
|
303
|
-
host:
|
|
290
|
+
directory: this.stackbitConfig?.dirPath,
|
|
291
|
+
port: this.stackbitConfig?.contentEngine?.port,
|
|
292
|
+
host: this.stackbitConfig?.contentEngine?.host,
|
|
304
293
|
engineConfig: {
|
|
305
294
|
plugins
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
logger.info(data.toString());
|
|
310
|
-
});
|
|
311
|
-
(_h = this.contentEngine) === null || _h === void 0 ? void 0 : _h.onStdErr((data) => {
|
|
312
|
-
logger.error(data.toString());
|
|
295
|
+
},
|
|
296
|
+
// content engine must run in the same process so that unified connectors can share state in memory
|
|
297
|
+
runInSubProcess: false
|
|
313
298
|
});
|
|
314
299
|
}
|
|
315
300
|
/**
|
|
@@ -330,7 +315,6 @@ class ContentStore {
|
|
|
330
315
|
* @private
|
|
331
316
|
*/
|
|
332
317
|
async loadContentSourcesAndProcessData({ init, startWatchingContentUpdates, contentSourceIds }) {
|
|
333
|
-
var _a, _b, _c, _d, _e, _f;
|
|
334
318
|
this.logger.debug('loadContentSourcesAndProcessData', { init, contentSourceIds });
|
|
335
319
|
if (this.processingContentSourcesPromise) {
|
|
336
320
|
// for internal monitoring
|
|
@@ -340,18 +324,34 @@ class ContentStore {
|
|
|
340
324
|
// On init, get the new content source instances from the config and wrap them with backward compatibility Proxy.
|
|
341
325
|
// Otherwise, reuse existing proxy wrapped backward compatible content sources.
|
|
342
326
|
const contentSources = init || this.contentSources.length === 0
|
|
343
|
-
? (
|
|
327
|
+
? (this.stackbitConfig?.contentSources ?? []).map((contentSource) => {
|
|
344
328
|
return (0, backward_compatibility_1.backwardCompatibleContentSource)(contentSource);
|
|
345
329
|
})
|
|
346
330
|
: this.contentSources;
|
|
347
331
|
this.contentSources = contentSources;
|
|
348
332
|
if (init) {
|
|
349
333
|
this.logger.debug('init content sources');
|
|
334
|
+
if (this.stackbitConfig?.connectors) {
|
|
335
|
+
const contentSources = this.contentSources || [];
|
|
336
|
+
if (this.stackbitConfig?.connectors?.length) {
|
|
337
|
+
const ConnectorWrapper = (await import('./connector/connector-wrapper.mjs')).default;
|
|
338
|
+
for (const connector of this.stackbitConfig.connectors) {
|
|
339
|
+
contentSources.push(new ConnectorWrapper(connector));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
this.contentSources = contentSources;
|
|
343
|
+
}
|
|
350
344
|
await this.createContentEngineIfNeeded();
|
|
351
|
-
await ((_c = this.contentEngine) === null || _c === void 0 ? void 0 : _c.sync({
|
|
352
|
-
runServer: true
|
|
353
|
-
}));
|
|
354
345
|
}
|
|
346
|
+
const contentEngineSyncPromise = this.contentEngine
|
|
347
|
+
? // store the content engine sync promise instead of awaiting here
|
|
348
|
+
// unified connectors need the internal CSI + source plugin to run simultaneously.
|
|
349
|
+
// waiting for this promise here means internal unified connector APIs will be stuck forever
|
|
350
|
+
// it's awaited further below
|
|
351
|
+
this.contentEngine?.sync({
|
|
352
|
+
runServer: true
|
|
353
|
+
})
|
|
354
|
+
: Promise.resolve();
|
|
355
355
|
const promises = contentSources.map((contentSourceInstance) => {
|
|
356
356
|
const contentSourceId = (0, content_store_utils_1.getContentSourceIdForContentSource)(contentSourceInstance);
|
|
357
357
|
if (init || !contentSourceIds || contentSourceIds.includes(contentSourceId)) {
|
|
@@ -365,7 +365,7 @@ class ContentStore {
|
|
|
365
365
|
// find first content source that supports presets
|
|
366
366
|
for (let i = 0; i < contentSources.length; i++) {
|
|
367
367
|
const contentSourceDataRaw = contentSourceRawDataArr[i];
|
|
368
|
-
if (
|
|
368
|
+
if (contentSourceDataRaw?.csiModelMap?.[consts_1.STACKBIT_PRESET_MODEL_NAME]) {
|
|
369
369
|
this.presetsContentSource = contentSourceDataRaw.instance;
|
|
370
370
|
// reload presets from content source only if needed
|
|
371
371
|
if (init || !contentSourceIds || contentSourceIds.includes(contentSourceDataRaw.id)) {
|
|
@@ -381,7 +381,7 @@ class ContentStore {
|
|
|
381
381
|
// update all content sources at once to prevent race conditions
|
|
382
382
|
this.contentSourceDataById = await this.processData({
|
|
383
383
|
stackbitConfig: this.stackbitConfig,
|
|
384
|
-
configModels:
|
|
384
|
+
configModels: this.modelExtensions ?? this.configModels ?? [],
|
|
385
385
|
presets: this.presets,
|
|
386
386
|
contentSourceRawDataArr: contentSourceRawDataArr
|
|
387
387
|
});
|
|
@@ -407,6 +407,7 @@ class ContentStore {
|
|
|
407
407
|
this.logger.debug('loadContentSourcesAndProcessData finished', { init, contentSourceIds });
|
|
408
408
|
const processingPromise = this.processingContentSourcesPromise;
|
|
409
409
|
this.processingContentSourcesPromise = null;
|
|
410
|
+
await contentEngineSyncPromise;
|
|
410
411
|
// Do not "await" on processContentStoreEvents as it may introduce a deadlock with
|
|
411
412
|
// the nested loadContentSourcesAndProcessData call which is wrapped by deferWhileRunning.
|
|
412
413
|
this.processContentStoreEvents()
|
|
@@ -535,9 +536,8 @@ class ContentStore {
|
|
|
535
536
|
});
|
|
536
537
|
}
|
|
537
538
|
async loadContentSourceData({ contentSourceInstance, init, startWatchingContentUpdates }) {
|
|
538
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
539
539
|
const contentSourceId = (0, content_store_utils_1.getContentSourceIdForContentSource)(contentSourceInstance);
|
|
540
|
-
const contentEngineConfig =
|
|
540
|
+
const contentEngineConfig = contentSourceInstance.getContentEngineConfig?.();
|
|
541
541
|
this.logger.debug('loadContentSourceData', { contentSourceId, init });
|
|
542
542
|
// clear content source events emitted by this content source because all the content source data is reloaded
|
|
543
543
|
this.clearEventsForContentSourceId(contentSourceId);
|
|
@@ -579,7 +579,7 @@ class ContentStore {
|
|
|
579
579
|
const cache = {
|
|
580
580
|
getSchema: () => {
|
|
581
581
|
const contentSourceData = getContentSourceDataForCurrentInstance('getSchema');
|
|
582
|
-
if (!
|
|
582
|
+
if (!contentSourceData?.csiSchema) {
|
|
583
583
|
if (contentSourceData) {
|
|
584
584
|
const atLine = (0, content_store_utils_1.getErrorAtLine)(1);
|
|
585
585
|
const errorMessage = `Content source life cycle error! The content source with id '${contentSourceId}' called the 'cache.getSchema' ` +
|
|
@@ -592,7 +592,7 @@ class ContentStore {
|
|
|
592
592
|
},
|
|
593
593
|
getModelByName: (modelName) => {
|
|
594
594
|
const contentSourceData = getContentSourceDataForCurrentInstance('getModelByName');
|
|
595
|
-
if (!
|
|
595
|
+
if (!contentSourceData?.csiModelMap) {
|
|
596
596
|
if (contentSourceData) {
|
|
597
597
|
const atLine = (0, content_store_utils_1.getErrorAtLine)(1);
|
|
598
598
|
const errorMessage = `Content source life cycle error! The content source with id '${contentSourceId}' called the 'cache.getModelByName' ` +
|
|
@@ -604,34 +604,28 @@ class ContentStore {
|
|
|
604
604
|
return contentSourceData.csiModelMap[modelName];
|
|
605
605
|
},
|
|
606
606
|
getDocuments: () => {
|
|
607
|
-
var _a;
|
|
608
607
|
const contentSourceData = getContentSourceDataForCurrentInstance('getDocuments');
|
|
609
|
-
return
|
|
608
|
+
return contentSourceData?.csiDocuments ?? [];
|
|
610
609
|
},
|
|
611
610
|
getDocumentById: (documentId) => {
|
|
612
|
-
var _a;
|
|
613
611
|
const contentSourceData = getContentSourceDataForCurrentInstance('getDocumentById');
|
|
614
|
-
return
|
|
612
|
+
return contentSourceData?.csiDocumentMap?.[documentId];
|
|
615
613
|
},
|
|
616
614
|
getAssets: () => {
|
|
617
|
-
var _a;
|
|
618
615
|
const contentSourceData = getContentSourceDataForCurrentInstance('getAssets');
|
|
619
|
-
return
|
|
616
|
+
return contentSourceData?.csiAssets ?? [];
|
|
620
617
|
},
|
|
621
618
|
getScheduledActions: () => {
|
|
622
|
-
var _a;
|
|
623
619
|
const contentSourceData = getContentSourceDataForCurrentInstance('getScheduledActions');
|
|
624
|
-
return
|
|
620
|
+
return contentSourceData?.scheduledActions ?? [];
|
|
625
621
|
},
|
|
626
622
|
getScheduledActionsForDocumentId: (documentId) => {
|
|
627
|
-
var _a, _b;
|
|
628
623
|
const contentSourceData = getContentSourceDataForCurrentInstance('getScheduledActionsForDocumentId');
|
|
629
|
-
return
|
|
624
|
+
return contentSourceData?.scheduledActions?.filter((scheduledAction) => scheduledAction.documentIds.includes(documentId)) ?? [];
|
|
630
625
|
},
|
|
631
626
|
getAssetById: (assetId) => {
|
|
632
|
-
var _a;
|
|
633
627
|
const contentSourceData = getContentSourceDataForCurrentInstance('getAssetById');
|
|
634
|
-
return
|
|
628
|
+
return contentSourceData?.csiAssetMap?.[assetId];
|
|
635
629
|
},
|
|
636
630
|
updateContent: async (contentChanges) => {
|
|
637
631
|
if ((0, content_store_utils_1.isContentChangesEmpty)(contentChanges)) {
|
|
@@ -642,13 +636,6 @@ class ContentStore {
|
|
|
642
636
|
return;
|
|
643
637
|
}
|
|
644
638
|
this.logger.debug('content source called updateContent', { contentSourceId });
|
|
645
|
-
if (contentEngineConfig && this.contentEngine) {
|
|
646
|
-
this.logger.debug(`syncing ${contentEngineConfig.connector}`);
|
|
647
|
-
await this.contentEngine.sync({
|
|
648
|
-
buildSchema: false,
|
|
649
|
-
connector: contentEngineConfig.connector
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
639
|
this.pushContentSourceEvent({
|
|
653
640
|
eventName: ContentStoreEventType.ContentSourceContentChange,
|
|
654
641
|
contentSourceId: contentSourceId,
|
|
@@ -705,7 +692,7 @@ class ContentStore {
|
|
|
705
692
|
if (contentSourceData && contentSourceData.instance !== contentSourceInstance) {
|
|
706
693
|
this.logger.debug('destroy previous content source instance', { contentSourceId });
|
|
707
694
|
try {
|
|
708
|
-
|
|
695
|
+
contentSourceData.instance.stopWatchingContentUpdates?.();
|
|
709
696
|
await contentSourceData.instance.destroy();
|
|
710
697
|
}
|
|
711
698
|
catch (error) {
|
|
@@ -735,7 +722,7 @@ class ContentStore {
|
|
|
735
722
|
const csiModels = csiSchema.models;
|
|
736
723
|
const csiModelMap = lodash_1.default.keyBy(csiModels, 'name');
|
|
737
724
|
const locales = csiSchema.locales;
|
|
738
|
-
const defaultLocaleCode =
|
|
725
|
+
const defaultLocaleCode = locales?.find((locale) => locale.default)?.code;
|
|
739
726
|
localCache.csiSchema = csiSchema;
|
|
740
727
|
localCache.csiModels = csiModels;
|
|
741
728
|
localCache.csiModelMap = csiModelMap;
|
|
@@ -756,7 +743,7 @@ class ContentStore {
|
|
|
756
743
|
contentSourceInstance.getScheduledActions);
|
|
757
744
|
try {
|
|
758
745
|
if (scheduledActionsMethodsImplemented) {
|
|
759
|
-
scheduledActions = (
|
|
746
|
+
scheduledActions = (await contentSourceInstance.getScheduledActions?.()) ?? [];
|
|
760
747
|
localCache.scheduledActions = scheduledActions;
|
|
761
748
|
enabledScheduledActions = true;
|
|
762
749
|
}
|
|
@@ -774,7 +761,7 @@ class ContentStore {
|
|
|
774
761
|
this.logger.debug('loaded content source data', {
|
|
775
762
|
contentSourceId,
|
|
776
763
|
defaultLocaleCode,
|
|
777
|
-
localesCount:
|
|
764
|
+
localesCount: locales?.length ?? 0,
|
|
778
765
|
modelCount: csiModels.length,
|
|
779
766
|
documentCount: csiDocuments.length,
|
|
780
767
|
assetCount: csiAssets.length
|
|
@@ -784,21 +771,18 @@ class ContentStore {
|
|
|
784
771
|
`${csiAssets.length} ${(0, user_log_utils_1.pluralize)('asset', csiAssets.length)}`);
|
|
785
772
|
if (init || startWatchingContentUpdates) {
|
|
786
773
|
// backward compatibility
|
|
787
|
-
|
|
774
|
+
contentSourceInstance.startWatchingContentUpdates?.({
|
|
788
775
|
getModelMap: () => {
|
|
789
|
-
var _a;
|
|
790
776
|
const contentSourceData = getContentSourceDataForCurrentInstance('getModelMap');
|
|
791
|
-
return
|
|
777
|
+
return contentSourceData?.csiModelMap ?? {};
|
|
792
778
|
},
|
|
793
779
|
getDocument: ({ documentId }) => {
|
|
794
|
-
var _a;
|
|
795
780
|
const contentSourceData = getContentSourceDataForCurrentInstance('getDocument');
|
|
796
|
-
return
|
|
781
|
+
return contentSourceData?.csiDocumentMap?.[documentId];
|
|
797
782
|
},
|
|
798
783
|
getAsset: ({ assetId }) => {
|
|
799
|
-
var _a;
|
|
800
784
|
const contentSourceData = getContentSourceDataForCurrentInstance('getAsset');
|
|
801
|
-
return
|
|
785
|
+
return contentSourceData?.csiAssetMap?.[assetId];
|
|
802
786
|
},
|
|
803
787
|
onContentChange: cache.updateContent,
|
|
804
788
|
onSchemaChange: cache.invalidateSchema
|
|
@@ -830,16 +814,15 @@ class ContentStore {
|
|
|
830
814
|
};
|
|
831
815
|
}
|
|
832
816
|
onContentChange(contentSourceId, contentChanges) {
|
|
833
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
834
817
|
// certain content changes, like preset changes are interpreted as schema changes
|
|
835
818
|
let presetsUpdated = false;
|
|
836
819
|
const contentChangesFull = {
|
|
837
|
-
documents:
|
|
838
|
-
assets:
|
|
839
|
-
scheduledActions:
|
|
840
|
-
deletedDocumentIds:
|
|
841
|
-
deletedAssetIds:
|
|
842
|
-
deletedScheduledActionIds:
|
|
820
|
+
documents: contentChanges.documents ?? [],
|
|
821
|
+
assets: contentChanges.assets ?? [],
|
|
822
|
+
scheduledActions: contentChanges.scheduledActions ?? [],
|
|
823
|
+
deletedDocumentIds: contentChanges.deletedDocumentIds ?? [],
|
|
824
|
+
deletedAssetIds: contentChanges.deletedAssetIds ?? [],
|
|
825
|
+
deletedScheduledActionIds: contentChanges.deletedScheduledActionIds ?? []
|
|
843
826
|
};
|
|
844
827
|
this.logger.debug('onContentChange', {
|
|
845
828
|
contentSourceId,
|
|
@@ -861,10 +844,9 @@ class ContentStore {
|
|
|
861
844
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
862
845
|
// update contentSourceData with deleted documents
|
|
863
846
|
contentChangesFull.deletedDocumentIds.forEach((docId) => {
|
|
864
|
-
var _a;
|
|
865
847
|
// remove preset, make sure there is something to remove first because
|
|
866
848
|
// were explicitly calling onContentChange from deletePreset as well
|
|
867
|
-
if (this.presets[docId] &&
|
|
849
|
+
if (this.presets[docId] && contentSourceData.csiDocumentMap[docId]?.modelName === consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
868
850
|
presetsUpdated = true;
|
|
869
851
|
const preset = this.presets[docId];
|
|
870
852
|
const model = contentSourceData.modelMap[preset.modelName];
|
|
@@ -923,7 +905,7 @@ class ContentStore {
|
|
|
923
905
|
});
|
|
924
906
|
// map csi documents through stackbitConfig.mapDocuments
|
|
925
907
|
let mappedDocs = contentChangesFull.documents;
|
|
926
|
-
if (
|
|
908
|
+
if (this.stackbitConfig?.mapDocuments) {
|
|
927
909
|
const csiDocumentsWithSource = contentChangesFull.documents.map((csiDocument) => ({
|
|
928
910
|
srcType: contentSourceData.srcType,
|
|
929
911
|
srcProjectId: contentSourceData.srcProjectId,
|
|
@@ -937,10 +919,10 @@ class ContentStore {
|
|
|
937
919
|
};
|
|
938
920
|
});
|
|
939
921
|
mappedDocs =
|
|
940
|
-
|
|
922
|
+
this.stackbitConfig?.mapDocuments?.({
|
|
941
923
|
documents: lodash_1.default.cloneDeep(csiDocumentsWithSource),
|
|
942
924
|
models: lodash_1.default.cloneDeep(modelsWithSource)
|
|
943
|
-
})
|
|
925
|
+
}) ?? csiDocumentsWithSource;
|
|
944
926
|
}
|
|
945
927
|
// map csi documents and assets to content store documents and assets
|
|
946
928
|
const documents = (0, csi_to_store_docs_converter_1.mapCSIDocumentsToStoreDocuments)({
|
|
@@ -948,7 +930,7 @@ class ContentStore {
|
|
|
948
930
|
contentSourceInstance: contentSourceData.instance,
|
|
949
931
|
modelMap: contentSourceData.modelMap,
|
|
950
932
|
defaultLocaleCode: contentSourceData.defaultLocaleCode,
|
|
951
|
-
assetSources:
|
|
933
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
952
934
|
customActionRunStateMap: this.customActionRunStateMap,
|
|
953
935
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
954
936
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
@@ -992,7 +974,7 @@ class ContentStore {
|
|
|
992
974
|
this.presets[csiDocument.id] = preset;
|
|
993
975
|
if (dataIndex === -1) {
|
|
994
976
|
//TODO recalculate assets as well
|
|
995
|
-
|
|
977
|
+
contentSourceData.modelMap[preset.modelName]?.presets?.push(csiDocument.id);
|
|
996
978
|
}
|
|
997
979
|
}
|
|
998
980
|
}
|
|
@@ -1045,7 +1027,6 @@ class ContentStore {
|
|
|
1045
1027
|
};
|
|
1046
1028
|
}
|
|
1047
1029
|
async processData({ stackbitConfig, configModels, presets, contentSourceRawDataArr }) {
|
|
1048
|
-
var _a, _b, _c, _d;
|
|
1049
1030
|
this.logger.debug('processData');
|
|
1050
1031
|
// Group models from all content sources by their names
|
|
1051
1032
|
const csiModelGroups = contentSourceRawDataArr.reduce((modelGroups, csData) => {
|
|
@@ -1114,10 +1095,9 @@ class ContentStore {
|
|
|
1114
1095
|
this.userLogger.warn(configModelMessage + contentSourceModelsMessage);
|
|
1115
1096
|
}
|
|
1116
1097
|
const modelsWithSource = contentSourceRawDataArr.reduce((accum, csData) => {
|
|
1117
|
-
var _a;
|
|
1118
1098
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(csData.srcType, csData.srcProjectId);
|
|
1119
1099
|
const mergedModels = (0, sdk_1.mergeConfigModelsWithExternalModels)({
|
|
1120
|
-
configModels:
|
|
1100
|
+
configModels: configModelsByContentSourceId[contentSourceId] ?? [],
|
|
1121
1101
|
externalModels: csData.csiModels,
|
|
1122
1102
|
logger: this.userLogger
|
|
1123
1103
|
});
|
|
@@ -1132,13 +1112,13 @@ class ContentStore {
|
|
|
1132
1112
|
}, []);
|
|
1133
1113
|
// TODO: Is there a better way than deep cloning objects before passing them to user methods?
|
|
1134
1114
|
// Not cloning mutable objects will break the internal state if user mutates the objects.
|
|
1135
|
-
const mappedModels =
|
|
1115
|
+
const mappedModels = stackbitConfig?.mapModels?.({ models: lodash_1.default.cloneDeep(modelsWithSource) }) ?? modelsWithSource;
|
|
1136
1116
|
const normalizedModels = (0, model_utils_1.normalizeModels)({ models: mappedModels, logger: this.userLogger });
|
|
1137
1117
|
const validatedModels = (0, model_utils_1.validateModels)({ models: normalizedModels, logger: this.userLogger });
|
|
1138
1118
|
const modelsWithPresetsIds = (0, sdk_1.extendModelsWithPresetsIds)({ models: validatedModels, presets });
|
|
1139
1119
|
const { models } = await this.handleConfigAssets({ models: modelsWithPresetsIds });
|
|
1140
1120
|
let documentMapByContentSource = null;
|
|
1141
|
-
if (stackbitConfig
|
|
1121
|
+
if (stackbitConfig?.mapDocuments) {
|
|
1142
1122
|
const csiDocumentsWithSource = contentSourceRawDataArr.reduce((accum, csData) => {
|
|
1143
1123
|
const csiDocumentsWithSource = csData.csiDocuments.map((csiDocument) => ({
|
|
1144
1124
|
srcType: csData.srcType,
|
|
@@ -1149,15 +1129,14 @@ class ContentStore {
|
|
|
1149
1129
|
}, []);
|
|
1150
1130
|
// TODO: Is there a better way than deep cloning objects before passing them to user methods?
|
|
1151
1131
|
// Not cloning mutable objects will break the internal state if user mutates the objects.
|
|
1152
|
-
const mappedDocs =
|
|
1132
|
+
const mappedDocs = stackbitConfig?.mapDocuments?.({
|
|
1153
1133
|
documents: lodash_1.default.cloneDeep(csiDocumentsWithSource),
|
|
1154
1134
|
models: lodash_1.default.cloneDeep(models)
|
|
1155
|
-
})
|
|
1135
|
+
}) ?? csiDocumentsWithSource;
|
|
1156
1136
|
documentMapByContentSource = (0, content_store_utils_1.groupDocumentsByContentSource)({ documents: mappedDocs });
|
|
1157
1137
|
}
|
|
1158
1138
|
const modelMapByContentSource = (0, content_store_utils_1.groupModelsByContentSource)({ models: models });
|
|
1159
1139
|
const contentSourceDataArr = contentSourceRawDataArr.map((csData) => {
|
|
1160
|
-
var _a, _b;
|
|
1161
1140
|
const modelMap = lodash_1.default.get(modelMapByContentSource, [csData.srcType, csData.srcProjectId], {});
|
|
1162
1141
|
const csiDocuments = documentMapByContentSource
|
|
1163
1142
|
? lodash_1.default.get(documentMapByContentSource, [csData.srcType, csData.srcProjectId], [])
|
|
@@ -1167,7 +1146,7 @@ class ContentStore {
|
|
|
1167
1146
|
contentSourceInstance: csData.instance,
|
|
1168
1147
|
modelMap: modelMap,
|
|
1169
1148
|
defaultLocaleCode: csData.defaultLocaleCode,
|
|
1170
|
-
assetSources:
|
|
1149
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1171
1150
|
customActionRunStateMap: this.customActionRunStateMap,
|
|
1172
1151
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1173
1152
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
@@ -1188,14 +1167,13 @@ class ContentStore {
|
|
|
1188
1167
|
}
|
|
1189
1168
|
getContentSourceMeta() {
|
|
1190
1169
|
return lodash_1.default.reduce(this.contentSourceDataById, (result, contentSourceData) => {
|
|
1191
|
-
var _a, _b;
|
|
1192
1170
|
return result.concat({
|
|
1193
1171
|
srcType: contentSourceData.srcType,
|
|
1194
1172
|
srcProjectId: contentSourceData.srcProjectId,
|
|
1195
1173
|
srcVersion: contentSourceData.version.contentSourceVersion,
|
|
1196
1174
|
csiVersion: contentSourceData.version.interfaceVersion,
|
|
1197
|
-
supportsScheduledActions:
|
|
1198
|
-
supportsDocumentVersions:
|
|
1175
|
+
supportsScheduledActions: contentSourceData?.enabledFeatures.scheduledActions ?? false,
|
|
1176
|
+
supportsDocumentVersions: contentSourceData?.enabledFeatures.documentVersions ?? false
|
|
1199
1177
|
});
|
|
1200
1178
|
}, []);
|
|
1201
1179
|
}
|
|
@@ -1208,14 +1186,13 @@ class ContentStore {
|
|
|
1208
1186
|
logger: this.userLogger
|
|
1209
1187
|
});
|
|
1210
1188
|
return lodash_1.default.reduce(this.contentSourceDataById, (result, contentSourceData) => {
|
|
1211
|
-
var _a;
|
|
1212
1189
|
const contentSourceType = contentSourceData.instance.getContentSourceType();
|
|
1213
1190
|
const srcProjectId = contentSourceData.instance.getProjectId();
|
|
1214
1191
|
const filteredModels = (0, filtered_entities_1.getContentSourceFilteredModelsForUser)({
|
|
1215
1192
|
user,
|
|
1216
1193
|
configDelegate,
|
|
1217
1194
|
contentSourceData,
|
|
1218
|
-
filterModel:
|
|
1195
|
+
filterModel: this.stackbitConfig?.filterModel
|
|
1219
1196
|
});
|
|
1220
1197
|
const modelsMap = (0, model_utils_1.getModelMap)({ models: filteredModels });
|
|
1221
1198
|
// if `projectId` is number (even as string) e.g., '1234', _.set() will create an array of length 1235 and insert the item at the end.
|
|
@@ -1227,11 +1204,10 @@ class ContentStore {
|
|
|
1227
1204
|
}
|
|
1228
1205
|
getLocales() {
|
|
1229
1206
|
return lodash_1.default.reduce(this.contentSourceDataById, (result, contentSourceData) => {
|
|
1230
|
-
var _a, _b;
|
|
1231
1207
|
return result.concat({
|
|
1232
1208
|
srcType: contentSourceData.srcType,
|
|
1233
1209
|
srcProjectId: contentSourceData.srcProjectId,
|
|
1234
|
-
locales:
|
|
1210
|
+
locales: contentSourceData.locales?.map((locale) => locale.code) ?? [],
|
|
1235
1211
|
defaultLocale: contentSourceData.defaultLocaleCode
|
|
1236
1212
|
});
|
|
1237
1213
|
}, []);
|
|
@@ -1275,9 +1251,8 @@ class ContentStore {
|
|
|
1275
1251
|
});
|
|
1276
1252
|
}
|
|
1277
1253
|
getPresets({ locale } = {}) {
|
|
1278
|
-
var _a;
|
|
1279
1254
|
if (!this.presets || !locale) {
|
|
1280
|
-
return
|
|
1255
|
+
return this.presets ?? {};
|
|
1281
1256
|
}
|
|
1282
1257
|
return lodash_1.default.pickBy(this.presets, (preset) => !preset.locale || preset.locale === locale);
|
|
1283
1258
|
}
|
|
@@ -1357,10 +1332,8 @@ class ContentStore {
|
|
|
1357
1332
|
};
|
|
1358
1333
|
}
|
|
1359
1334
|
getSiteMapEntries({ locale, user } = {}) {
|
|
1360
|
-
var _a;
|
|
1361
1335
|
const siteMapEntries = lodash_1.default.reduce(this.siteMapEntryGroups, (accum, siteMapEntryGroup) => {
|
|
1362
1336
|
return lodash_1.default.reduce(siteMapEntryGroup, (accum, siteMapEntry) => {
|
|
1363
|
-
var _a, _b, _c, _d, _e;
|
|
1364
1337
|
if (!lodash_1.default.isEmpty(locale)) {
|
|
1365
1338
|
// filter out in wrong locale
|
|
1366
1339
|
if (siteMapEntry.locale && siteMapEntry.locale !== locale) {
|
|
@@ -1370,15 +1343,15 @@ class ContentStore {
|
|
|
1370
1343
|
if ('document' in siteMapEntry) {
|
|
1371
1344
|
// check for hidden documents
|
|
1372
1345
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(siteMapEntry.document.srcType, siteMapEntry.document.srcProjectId);
|
|
1373
|
-
const document = (
|
|
1346
|
+
const document = (0, content_store_utils_1.getContentSourceDataByIdOrThrow)(contentSourceId, this.contentSourceDataById)?.documentMap[siteMapEntry.document.id];
|
|
1374
1347
|
if (document) {
|
|
1375
1348
|
const [filteredDocument] = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1376
1349
|
user,
|
|
1377
1350
|
documents: [document],
|
|
1378
|
-
filterModel:
|
|
1379
|
-
filterDocument:
|
|
1351
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
1352
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
1380
1353
|
contentSourceDataById: this.contentSourceDataById,
|
|
1381
|
-
assetSources:
|
|
1354
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1382
1355
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1383
1356
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1384
1357
|
logger: this.userLogger
|
|
@@ -1399,14 +1372,14 @@ class ContentStore {
|
|
|
1399
1372
|
});
|
|
1400
1373
|
siteMapEntry = {
|
|
1401
1374
|
...siteMapEntry,
|
|
1402
|
-
label: fieldLabelValue
|
|
1375
|
+
label: fieldLabelValue ?? siteMapEntry.urlPath
|
|
1403
1376
|
};
|
|
1404
1377
|
}
|
|
1405
1378
|
accum.push(siteMapEntry);
|
|
1406
1379
|
return accum;
|
|
1407
1380
|
}, accum);
|
|
1408
1381
|
}, []);
|
|
1409
|
-
if (user &&
|
|
1382
|
+
if (user && this.stackbitConfig?.transformSitemap) {
|
|
1410
1383
|
const configDelegate = (0, config_delegate_1.createConfigDelegate)({
|
|
1411
1384
|
contentSourceDataById: this.contentSourceDataById,
|
|
1412
1385
|
logger: this.userLogger
|
|
@@ -1416,9 +1389,8 @@ class ContentStore {
|
|
|
1416
1389
|
return siteMapEntries;
|
|
1417
1390
|
}
|
|
1418
1391
|
getTreeViews({ user } = {}) {
|
|
1419
|
-
var _a;
|
|
1420
1392
|
let treeViews = this.treeViews;
|
|
1421
|
-
if (
|
|
1393
|
+
if (this.stackbitConfig?.transformTreeViews && user) {
|
|
1422
1394
|
const configDelegate = (0, config_delegate_1.createConfigDelegate)({
|
|
1423
1395
|
contentSourceDataById: this.contentSourceDataById,
|
|
1424
1396
|
logger: this.userLogger
|
|
@@ -1428,19 +1400,18 @@ class ContentStore {
|
|
|
1428
1400
|
return (0, tree_views_1.removeHiddenTreeViews)({
|
|
1429
1401
|
treeViews,
|
|
1430
1402
|
getDocumentForUser: (opts) => {
|
|
1431
|
-
var _a, _b, _c, _d, _e;
|
|
1432
1403
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(opts.srcType, opts.srcProjectId);
|
|
1433
|
-
const document = (
|
|
1404
|
+
const document = (0, content_store_utils_1.getContentSourceDataByIdOrThrow)(contentSourceId, this.contentSourceDataById)?.documentMap[opts.srcDocumentId];
|
|
1434
1405
|
if (!document || !user) {
|
|
1435
1406
|
return document;
|
|
1436
1407
|
}
|
|
1437
1408
|
const [filteredDocument] = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1438
1409
|
user,
|
|
1439
1410
|
documents: [document],
|
|
1440
|
-
filterModel:
|
|
1441
|
-
filterDocument:
|
|
1411
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
1412
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
1442
1413
|
contentSourceDataById: this.contentSourceDataById,
|
|
1443
|
-
assetSources:
|
|
1414
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1444
1415
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1445
1416
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1446
1417
|
logger: this.userLogger
|
|
@@ -1463,7 +1434,6 @@ class ContentStore {
|
|
|
1463
1434
|
return lodash_1.default.isEmpty(locale) ? siteMapEntries : siteMapEntries.filter((siteMapEntry) => !siteMapEntry.locale || siteMapEntry.locale === locale);
|
|
1464
1435
|
}
|
|
1465
1436
|
getDocument({ srcDocumentId, srcProjectId, srcType, user }) {
|
|
1466
|
-
var _a, _b, _c, _d;
|
|
1467
1437
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
1468
1438
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
1469
1439
|
const document = contentSourceData.documentMap[srcDocumentId];
|
|
@@ -1473,10 +1443,10 @@ class ContentStore {
|
|
|
1473
1443
|
const [filteredDocument] = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1474
1444
|
user,
|
|
1475
1445
|
documents: [document],
|
|
1476
|
-
filterModel:
|
|
1477
|
-
filterDocument:
|
|
1446
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
1447
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
1478
1448
|
contentSourceDataById: this.contentSourceDataById,
|
|
1479
|
-
assetSources:
|
|
1449
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1480
1450
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1481
1451
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1482
1452
|
logger: this.userLogger
|
|
@@ -1484,7 +1454,7 @@ class ContentStore {
|
|
|
1484
1454
|
logger: this.userLogger,
|
|
1485
1455
|
customActionRunStateMap: this.customActionRunStateMap
|
|
1486
1456
|
});
|
|
1487
|
-
return filteredDocument
|
|
1457
|
+
return filteredDocument ?? document;
|
|
1488
1458
|
}
|
|
1489
1459
|
getDocumentsByContext({ context, srcProjectId, srcType }) {
|
|
1490
1460
|
const contentSourcesData = (0, content_store_utils_1.findContentSourcesDataForTypeOrId)({
|
|
@@ -1500,7 +1470,6 @@ class ContentStore {
|
|
|
1500
1470
|
}, []);
|
|
1501
1471
|
}
|
|
1502
1472
|
getDocuments({ locale, user } = {}) {
|
|
1503
|
-
var _a, _b, _c, _d;
|
|
1504
1473
|
const documents = lodash_1.default.reduce(this.contentSourceDataById, (documents, contentSourceData) => {
|
|
1505
1474
|
const currentDocuments = lodash_1.default.isEmpty(locale)
|
|
1506
1475
|
? contentSourceData.documents
|
|
@@ -1511,10 +1480,10 @@ class ContentStore {
|
|
|
1511
1480
|
const filteredDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1512
1481
|
user,
|
|
1513
1482
|
documents,
|
|
1514
|
-
filterModel:
|
|
1515
|
-
filterDocument:
|
|
1483
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
1484
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
1516
1485
|
contentSourceDataById: this.contentSourceDataById,
|
|
1517
|
-
assetSources:
|
|
1486
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1518
1487
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1519
1488
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1520
1489
|
logger: this.userLogger
|
|
@@ -1525,14 +1494,12 @@ class ContentStore {
|
|
|
1525
1494
|
return filteredDocuments;
|
|
1526
1495
|
}
|
|
1527
1496
|
getApiDocuments({ documentSpecs, user } = {}) {
|
|
1528
|
-
var _a, _b, _c, _d;
|
|
1529
1497
|
let filteredDocuments;
|
|
1530
|
-
if (documentSpecs
|
|
1498
|
+
if (documentSpecs?.length) {
|
|
1531
1499
|
// filter over documentSpecs
|
|
1532
|
-
filteredDocuments = documentSpecs
|
|
1533
|
-
var _a;
|
|
1500
|
+
filteredDocuments = documentSpecs?.reduce((acc, docSpec) => {
|
|
1534
1501
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(docSpec.srcType, docSpec.srcProjectId);
|
|
1535
|
-
const document =
|
|
1502
|
+
const document = this.contentSourceDataById[contentSourceId]?.documentMap[docSpec.srcDocumentId];
|
|
1536
1503
|
if (document && document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
1537
1504
|
acc.push(document);
|
|
1538
1505
|
}
|
|
@@ -1548,10 +1515,10 @@ class ContentStore {
|
|
|
1548
1515
|
filteredDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1549
1516
|
user,
|
|
1550
1517
|
documents: filteredDocuments,
|
|
1551
|
-
filterModel:
|
|
1552
|
-
filterDocument:
|
|
1518
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
1519
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
1553
1520
|
contentSourceDataById: this.contentSourceDataById,
|
|
1554
|
-
assetSources:
|
|
1521
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1555
1522
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1556
1523
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1557
1524
|
logger: this.userLogger
|
|
@@ -1569,11 +1536,10 @@ class ContentStore {
|
|
|
1569
1536
|
}
|
|
1570
1537
|
getCSIDocuments({ documentSpecs, srcType, srcProjectId, limit = 100, offset = 0 } = {}) {
|
|
1571
1538
|
// If document specs provided, return the specified documents. Don't use limit or offset.
|
|
1572
|
-
if (documentSpecs
|
|
1539
|
+
if (documentSpecs?.length) {
|
|
1573
1540
|
const documents = documentSpecs.reduce((csiDocuments, docSpec) => {
|
|
1574
|
-
var _a;
|
|
1575
1541
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(docSpec.srcType, docSpec.srcProjectId);
|
|
1576
|
-
const document =
|
|
1542
|
+
const document = this.contentSourceDataById[contentSourceId]?.csiDocumentMap[docSpec.srcDocumentId];
|
|
1577
1543
|
if (document && document.modelName !== consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
1578
1544
|
csiDocuments.push(document);
|
|
1579
1545
|
}
|
|
@@ -1609,7 +1575,6 @@ class ContentStore {
|
|
|
1609
1575
|
return contentSourceData.assetMap[srcAssetId];
|
|
1610
1576
|
}
|
|
1611
1577
|
getAssets({ locale, user } = {}) {
|
|
1612
|
-
var _a;
|
|
1613
1578
|
const assets = lodash_1.default.reduce(this.contentSourceDataById, (assets, contentSourceData) => {
|
|
1614
1579
|
const currentAssets = lodash_1.default.isEmpty(locale)
|
|
1615
1580
|
? contentSourceData.assets
|
|
@@ -1619,7 +1584,7 @@ class ContentStore {
|
|
|
1619
1584
|
const filteredAssets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1620
1585
|
user,
|
|
1621
1586
|
assets,
|
|
1622
|
-
filterAsset:
|
|
1587
|
+
filterAsset: this.stackbitConfig?.filterAsset,
|
|
1623
1588
|
contentSourceDataById: this.contentSourceDataById,
|
|
1624
1589
|
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1625
1590
|
});
|
|
@@ -1628,22 +1593,21 @@ class ContentStore {
|
|
|
1628
1593
|
getLocalizedApiObjects({ locale, objectIds, user }) {
|
|
1629
1594
|
const hasExplicitLocale = !lodash_1.default.isEmpty(locale);
|
|
1630
1595
|
return lodash_1.default.reduce(this.contentSourceDataById, (objects, contentSourceData) => {
|
|
1631
|
-
var _a, _b, _c, _d, _e;
|
|
1632
1596
|
let documents = objectIds
|
|
1633
1597
|
? contentSourceData.documents.filter((document) => objectIds.includes(document.srcObjectId))
|
|
1634
1598
|
: contentSourceData.documents;
|
|
1635
1599
|
documents = hasExplicitLocale ? documents.filter((document) => !document.locale || document.locale === locale) : documents;
|
|
1636
1600
|
let assets = objectIds ? contentSourceData.assets.filter((asset) => objectIds.includes(asset.srcObjectId)) : contentSourceData.assets;
|
|
1637
1601
|
assets = hasExplicitLocale ? assets.filter((asset) => !asset.locale || asset.locale === locale) : assets;
|
|
1638
|
-
const currentLocale = locale
|
|
1602
|
+
const currentLocale = locale ?? contentSourceData.defaultLocaleCode;
|
|
1639
1603
|
let filteredDocuments = documents.filter((document) => document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME);
|
|
1640
1604
|
filteredDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1641
1605
|
user,
|
|
1642
1606
|
documents: filteredDocuments,
|
|
1643
|
-
filterModel:
|
|
1644
|
-
filterDocument:
|
|
1607
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
1608
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
1645
1609
|
contentSourceDataById: this.contentSourceDataById,
|
|
1646
|
-
assetSources:
|
|
1610
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1647
1611
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1648
1612
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1649
1613
|
logger: this.userLogger
|
|
@@ -1654,7 +1618,7 @@ class ContentStore {
|
|
|
1654
1618
|
assets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1655
1619
|
user,
|
|
1656
1620
|
assets,
|
|
1657
|
-
filterAsset:
|
|
1621
|
+
filterAsset: this.stackbitConfig?.filterAsset,
|
|
1658
1622
|
contentSourceDataById: this.contentSourceDataById,
|
|
1659
1623
|
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1660
1624
|
});
|
|
@@ -1668,7 +1632,6 @@ class ContentStore {
|
|
|
1668
1632
|
}, []);
|
|
1669
1633
|
}
|
|
1670
1634
|
getApiAssets({ srcType, srcProjectId, pageSize = 20, pageNum = 1, searchQuery, user } = {}) {
|
|
1671
|
-
var _a;
|
|
1672
1635
|
let assets;
|
|
1673
1636
|
if (srcProjectId && srcType) {
|
|
1674
1637
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
@@ -1676,7 +1639,7 @@ class ContentStore {
|
|
|
1676
1639
|
const filteredAssets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1677
1640
|
user,
|
|
1678
1641
|
assets: contentSourceData.assets,
|
|
1679
|
-
filterAsset:
|
|
1642
|
+
filterAsset: this.stackbitConfig?.filterAsset,
|
|
1680
1643
|
contentSourceDataById: this.contentSourceDataById,
|
|
1681
1644
|
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1682
1645
|
});
|
|
@@ -1684,11 +1647,10 @@ class ContentStore {
|
|
|
1684
1647
|
}
|
|
1685
1648
|
else {
|
|
1686
1649
|
assets = lodash_1.default.reduce(this.contentSourceDataById, (result, contentSourceData) => {
|
|
1687
|
-
var _a;
|
|
1688
1650
|
const filteredAssets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1689
1651
|
user,
|
|
1690
1652
|
assets: contentSourceData.assets,
|
|
1691
|
-
filterAsset:
|
|
1653
|
+
filterAsset: this.stackbitConfig?.filterAsset,
|
|
1692
1654
|
contentSourceDataById: this.contentSourceDataById,
|
|
1693
1655
|
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1694
1656
|
});
|
|
@@ -1725,7 +1687,7 @@ class ContentStore {
|
|
|
1725
1687
|
const modelMap = contentSourceData.modelMap;
|
|
1726
1688
|
const csiModelMap = contentSourceData.csiModelMap;
|
|
1727
1689
|
// get the 'reference' model field in the updated document that will be used to link the new document
|
|
1728
|
-
locale = locale
|
|
1690
|
+
locale = locale ?? contentSourceData.defaultLocaleCode;
|
|
1729
1691
|
const modelField = (0, field_path_utils_1.getModelFieldAtFieldPath)(document, fieldPath, modelMap, locale);
|
|
1730
1692
|
const csiModelField = (0, field_path_utils_1.getModelFieldAtFieldPath)(document, fieldPath, csiModelMap, locale);
|
|
1731
1693
|
if (!modelField || !csiModelField) {
|
|
@@ -1815,7 +1777,6 @@ class ContentStore {
|
|
|
1815
1777
|
return { srcDocumentId: srcDocumentId, createdDocumentId: result.srcDocumentId };
|
|
1816
1778
|
}
|
|
1817
1779
|
async createPreset({ preset, thumbnailAsset, user }) {
|
|
1818
|
-
var _a;
|
|
1819
1780
|
if (!this.presetsContentSource) {
|
|
1820
1781
|
throw new Error('Error saving preset: No content source available.');
|
|
1821
1782
|
}
|
|
@@ -1827,7 +1788,7 @@ class ContentStore {
|
|
|
1827
1788
|
assets: [thumbnailAsset],
|
|
1828
1789
|
user
|
|
1829
1790
|
});
|
|
1830
|
-
thumbnail =
|
|
1791
|
+
thumbnail = assets[0]?.objectId;
|
|
1831
1792
|
}
|
|
1832
1793
|
const contentSourceData = this.getContentSourceDataByIdOrThrow((0, content_store_utils_1.getContentSourceIdForContentSource)(this.presetsContentSource));
|
|
1833
1794
|
const document = await this.createDocument({
|
|
@@ -1879,7 +1840,7 @@ class ContentStore {
|
|
|
1879
1840
|
}
|
|
1880
1841
|
const csiModelMap = contentSourceData.csiModelMap;
|
|
1881
1842
|
// get the 'reference' model field in the updated document that will be used to link the new asset
|
|
1882
|
-
locale = locale
|
|
1843
|
+
locale = locale ?? contentSourceData.defaultLocaleCode;
|
|
1883
1844
|
const csiModelField = (0, field_path_utils_1.getModelFieldAtFieldPath)(document, fieldPath, csiModelMap, locale);
|
|
1884
1845
|
if (!csiModelField) {
|
|
1885
1846
|
throw Error(`Field path not found: '${fieldPath.join('.')}'.`);
|
|
@@ -1934,19 +1895,18 @@ class ContentStore {
|
|
|
1934
1895
|
return { srcDocumentId: srcDocumentId };
|
|
1935
1896
|
}
|
|
1936
1897
|
async createDocument({ srcType, srcProjectId, modelName, object, locale, defaultLocaleDocumentId, user }) {
|
|
1937
|
-
var _a, _b, _c;
|
|
1938
1898
|
this.logger.debug('createDocument', { srcType, srcProjectId, modelName, locale });
|
|
1939
1899
|
(0, user_log_utils_1.logCreateDocument)({ userLogger: this.userLogger, srcType, srcProjectId, modelName, locale, object });
|
|
1940
1900
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
1941
1901
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
1942
|
-
const resolvedLocale = locale
|
|
1902
|
+
const resolvedLocale = locale ?? contentSourceData.defaultLocaleCode;
|
|
1943
1903
|
const csiModel = contentSourceData.csiModelMap[modelName];
|
|
1944
1904
|
if (!csiModel) {
|
|
1945
1905
|
throw new Error(`Error creating document: model not found: '${modelName}' (source: ${contentSourceId}).`);
|
|
1946
1906
|
}
|
|
1947
|
-
if (
|
|
1907
|
+
if (this.stackbitConfig?.onContentCreate) {
|
|
1948
1908
|
object = await this.stackbitConfig.onContentCreate({
|
|
1949
|
-
object: object
|
|
1909
|
+
object: object ?? {},
|
|
1950
1910
|
locale,
|
|
1951
1911
|
model: {
|
|
1952
1912
|
srcType: contentSourceData.srcType,
|
|
@@ -1966,7 +1926,7 @@ class ContentStore {
|
|
|
1966
1926
|
modelName,
|
|
1967
1927
|
contentSourceId,
|
|
1968
1928
|
contentSourceDataById: this.contentSourceDataById,
|
|
1969
|
-
assetSources:
|
|
1929
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
1970
1930
|
createDocument: this.getCreateDocumentThunk({
|
|
1971
1931
|
defaultLocaleDocumentId,
|
|
1972
1932
|
user
|
|
@@ -1994,8 +1954,7 @@ class ContentStore {
|
|
|
1994
1954
|
throw new Error(`Error updating document: could not find document model '${documentModelName}'.`);
|
|
1995
1955
|
}
|
|
1996
1956
|
const operations = await (0, utils_1.mapPromise)(updateOperations, async (updateOperation) => {
|
|
1997
|
-
|
|
1998
|
-
const locale = (_a = updateOperation.locale) !== null && _a !== void 0 ? _a : contentSourceData.defaultLocaleCode;
|
|
1957
|
+
const locale = updateOperation.locale ?? contentSourceData.defaultLocaleCode;
|
|
1999
1958
|
const modelField = (0, field_path_utils_1.getModelFieldAtFieldPath)(document, updateOperation.fieldPath, modelMap, locale);
|
|
2000
1959
|
const csiModelField = (0, field_path_utils_1.getModelFieldAtFieldPath)(document, updateOperation.fieldPath, csiModelMap, locale);
|
|
2001
1960
|
switch (updateOperation.opType) {
|
|
@@ -2010,7 +1969,7 @@ class ContentStore {
|
|
|
2010
1969
|
csiModelMap,
|
|
2011
1970
|
contentSourceId,
|
|
2012
1971
|
contentSourceDataById: this.contentSourceDataById,
|
|
2013
|
-
assetSources:
|
|
1972
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
2014
1973
|
createDocument: this.getCreateDocumentThunk({ user }),
|
|
2015
1974
|
userLogger: this.userLogger
|
|
2016
1975
|
});
|
|
@@ -2039,7 +1998,7 @@ class ContentStore {
|
|
|
2039
1998
|
csiModelMap,
|
|
2040
1999
|
contentSourceId,
|
|
2041
2000
|
contentSourceDataById: this.contentSourceDataById,
|
|
2042
|
-
assetSources:
|
|
2001
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
2043
2002
|
createDocument: this.getCreateDocumentThunk({ user }),
|
|
2044
2003
|
userLogger: this.userLogger
|
|
2045
2004
|
}));
|
|
@@ -2080,7 +2039,6 @@ class ContentStore {
|
|
|
2080
2039
|
return { srcDocumentId: srcDocumentId };
|
|
2081
2040
|
}
|
|
2082
2041
|
async duplicateDocument({ srcType, srcProjectId, srcDocumentId, object, locale, user }) {
|
|
2083
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2084
2042
|
this.logger.debug('duplicateDocument', { srcType, srcProjectId, srcDocumentId, locale });
|
|
2085
2043
|
(0, user_log_utils_1.logDuplicateDocument)({ userLogger: this.userLogger, srcType, srcProjectId, srcDocumentId, locale });
|
|
2086
2044
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
@@ -2094,20 +2052,20 @@ class ContentStore {
|
|
|
2094
2052
|
if (!model || !csiModel) {
|
|
2095
2053
|
throw new Error(`Model not found: '${document.srcModelName}' (source: ${contentSourceId})`);
|
|
2096
2054
|
}
|
|
2097
|
-
const resolvedLocale = locale
|
|
2055
|
+
const resolvedLocale = locale ?? contentSourceData.defaultLocaleCode;
|
|
2098
2056
|
let extendedObject = (0, duplicate_document_1.mergeObjectWithDocument)({
|
|
2099
2057
|
object,
|
|
2100
2058
|
document,
|
|
2101
2059
|
locale: resolvedLocale,
|
|
2102
2060
|
contentSourceId,
|
|
2103
2061
|
contentSourceDataById: this.contentSourceDataById,
|
|
2104
|
-
referenceBehavior:
|
|
2105
|
-
duplicatableModels:
|
|
2106
|
-
nonDuplicatableModels:
|
|
2062
|
+
referenceBehavior: this.stackbitConfig?.presetReferenceBehavior,
|
|
2063
|
+
duplicatableModels: this.stackbitConfig?.duplicatableModels,
|
|
2064
|
+
nonDuplicatableModels: this.stackbitConfig?.nonDuplicatableModels
|
|
2107
2065
|
});
|
|
2108
|
-
if (
|
|
2066
|
+
if (this.stackbitConfig?.onContentCreate) {
|
|
2109
2067
|
extendedObject = await this.stackbitConfig.onContentCreate({
|
|
2110
|
-
object: extendedObject
|
|
2068
|
+
object: extendedObject ?? {},
|
|
2111
2069
|
locale,
|
|
2112
2070
|
model: {
|
|
2113
2071
|
srcType: contentSourceData.srcType,
|
|
@@ -2127,7 +2085,7 @@ class ContentStore {
|
|
|
2127
2085
|
modelName: model.name,
|
|
2128
2086
|
contentSourceId,
|
|
2129
2087
|
contentSourceDataById: this.contentSourceDataById,
|
|
2130
|
-
assetSources:
|
|
2088
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
2131
2089
|
createDocument: this.getCreateDocumentThunk({ user })
|
|
2132
2090
|
});
|
|
2133
2091
|
this.logger.debug('duplicated document', { srcType, srcProjectId, srcDocumentId, newDocumentId: result.documentId, modelName: model.name });
|
|
@@ -2159,7 +2117,7 @@ class ContentStore {
|
|
|
2159
2117
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2160
2118
|
const sourceAssets = [];
|
|
2161
2119
|
const userContext = (0, content_store_utils_1.getUserContextForSrcType)(srcType, user);
|
|
2162
|
-
locale = locale
|
|
2120
|
+
locale = locale ?? contentSourceData.defaultLocaleCode;
|
|
2163
2121
|
for (const asset of assets) {
|
|
2164
2122
|
let base64 = undefined;
|
|
2165
2123
|
if (asset.data) {
|
|
@@ -2260,7 +2218,7 @@ class ContentStore {
|
|
|
2260
2218
|
let errors = [];
|
|
2261
2219
|
for (const [contentSourceId, contentSourceObjects] of Object.entries(objectsBySourceId)) {
|
|
2262
2220
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2263
|
-
locale = locale
|
|
2221
|
+
locale = locale ?? contentSourceData.defaultLocaleCode;
|
|
2264
2222
|
const { documents, assets } = (0, content_store_utils_1.getCSIDocumentsAndAssetsFromContentSourceDataByIds)(contentSourceData, contentSourceObjects);
|
|
2265
2223
|
const userContext = (0, content_store_utils_1.getUserContextForSrcType)(contentSourceData.srcType, user);
|
|
2266
2224
|
const internalValidationErrors = internalValidateContent(documents, assets, contentSourceData, locale);
|
|
@@ -2301,7 +2259,6 @@ class ContentStore {
|
|
|
2301
2259
|
const scheduledActions = [];
|
|
2302
2260
|
const defaultLocales = {};
|
|
2303
2261
|
contentSourceIds.forEach((contentSourceId) => {
|
|
2304
|
-
var _a, _b, _c, _d;
|
|
2305
2262
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2306
2263
|
lodash_1.default.set(schema, [contentSourceData.srcType, contentSourceData.srcProjectId], contentSourceData.modelMap);
|
|
2307
2264
|
const contentSourceDocuments = lodash_1.default.isEmpty(locale)
|
|
@@ -2312,10 +2269,10 @@ class ContentStore {
|
|
|
2312
2269
|
const userDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
2313
2270
|
user: data.user,
|
|
2314
2271
|
documents: filteredDocuments,
|
|
2315
|
-
filterModel:
|
|
2316
|
-
filterDocument:
|
|
2272
|
+
filterModel: this.stackbitConfig?.filterModel,
|
|
2273
|
+
filterDocument: this.stackbitConfig?.filterDocument,
|
|
2317
2274
|
contentSourceDataById: this.contentSourceDataById,
|
|
2318
|
-
assetSources:
|
|
2275
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
2319
2276
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
2320
2277
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
2321
2278
|
logger: this.userLogger
|
|
@@ -2341,10 +2298,9 @@ class ContentStore {
|
|
|
2341
2298
|
});
|
|
2342
2299
|
}
|
|
2343
2300
|
async getDocumentVersions({ srcType, srcProjectId, documentId, locale, user }) {
|
|
2344
|
-
var _a, _b, _c;
|
|
2345
2301
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
2346
2302
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2347
|
-
locale = locale
|
|
2303
|
+
locale = locale ?? contentSourceData.defaultLocaleCode;
|
|
2348
2304
|
this.logger.debug('getDocumentVersions', { srcType, srcProjectId, documentId });
|
|
2349
2305
|
if (!contentSourceData.instance.getDocumentVersions) {
|
|
2350
2306
|
this.logger.error('Trying to call getDocumentVersions, but it is not implemented', {
|
|
@@ -2362,10 +2318,10 @@ class ContentStore {
|
|
|
2362
2318
|
contentSourceDataById: this.contentSourceDataById,
|
|
2363
2319
|
logger: this.userLogger
|
|
2364
2320
|
}),
|
|
2365
|
-
filterModel:
|
|
2321
|
+
filterModel: this.stackbitConfig?.filterModel
|
|
2366
2322
|
});
|
|
2367
2323
|
const apiVersions = (0, csi_to_api_docs_converter_1.mapDocumentVersionsToApiDocumentVersions)({
|
|
2368
|
-
assetSources:
|
|
2324
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
2369
2325
|
customActionRunStateMap: this.customActionRunStateMap,
|
|
2370
2326
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
2371
2327
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
@@ -2380,10 +2336,9 @@ class ContentStore {
|
|
|
2380
2336
|
return { versions: apiVersions };
|
|
2381
2337
|
}
|
|
2382
2338
|
async getDocumentForVersion({ srcType, srcProjectId, documentId, versionId, locale, user }) {
|
|
2383
|
-
var _a, _b, _c;
|
|
2384
2339
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
2385
2340
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2386
|
-
locale = locale
|
|
2341
|
+
locale = locale ?? contentSourceData.defaultLocaleCode;
|
|
2387
2342
|
this.logger.debug('getDocumentForVersion', { srcType, srcProjectId, documentId, versionId });
|
|
2388
2343
|
if (!contentSourceData.instance.getDocumentForVersion) {
|
|
2389
2344
|
this.logger.error('Trying to call getDocumentForVersion, but it is not implemented', {
|
|
@@ -2402,11 +2357,11 @@ class ContentStore {
|
|
|
2402
2357
|
contentSourceDataById: this.contentSourceDataById,
|
|
2403
2358
|
logger: this.userLogger
|
|
2404
2359
|
}),
|
|
2405
|
-
filterModel:
|
|
2360
|
+
filterModel: this.stackbitConfig?.filterModel
|
|
2406
2361
|
});
|
|
2407
2362
|
const [apiVersion] = (0, csi_to_api_docs_converter_1.mapDocumentVersionsToApiDocumentVersions)({
|
|
2408
2363
|
versions: [version],
|
|
2409
|
-
assetSources:
|
|
2364
|
+
assetSources: this.stackbitConfig?.assetSources ?? [],
|
|
2410
2365
|
customActionRunStateMap: this.customActionRunStateMap,
|
|
2411
2366
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
2412
2367
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
@@ -2452,11 +2407,22 @@ class ContentStore {
|
|
|
2452
2407
|
getContentSourceDataByIdOrThrow(contentSourceId) {
|
|
2453
2408
|
return (0, content_store_utils_1.getContentSourceDataByIdOrThrow)(contentSourceId, this.contentSourceDataById);
|
|
2454
2409
|
}
|
|
2455
|
-
onWebhook({ srcType, srcProjectId, data, headers }) {
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2410
|
+
async onWebhook({ srcType, srcProjectId, data, headers }) {
|
|
2411
|
+
if (this.contentEngine) {
|
|
2412
|
+
// if there's a content-engine always pass the webhook body to it
|
|
2413
|
+
await this.contentEngine.sync({
|
|
2414
|
+
webhookBody: data,
|
|
2415
|
+
// selective connector syncing can happen via a header
|
|
2416
|
+
connector: headers?.connector
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
// unified connectors handle their own webhook syncing via the .sync call above.
|
|
2420
|
+
// passing "connector" as the source type in the webhook url opts out of traditional CSI onWebhook calls
|
|
2421
|
+
if (srcType !== `connector`) {
|
|
2422
|
+
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
2423
|
+
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2424
|
+
return contentSourceData.instance.onWebhook?.({ data, headers });
|
|
2425
|
+
}
|
|
2460
2426
|
}
|
|
2461
2427
|
getWebhookUrl(contentSourceType, projectId) {
|
|
2462
2428
|
if (!this.webhookUrl) {
|