@stackbit/cms-core 1.0.10-develop.1 → 1.0.10-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/consts.d.ts +1 -0
- package/dist/consts.d.ts.map +1 -1
- package/dist/consts.js +2 -1
- package/dist/consts.js.map +1 -1
- package/dist/content-store.d.ts +25 -12
- package/dist/content-store.d.ts.map +1 -1
- package/dist/content-store.js +259 -40
- package/dist/content-store.js.map +1 -1
- package/dist/types/content-store-documents.d.ts +2 -0
- package/dist/types/content-store-documents.d.ts.map +1 -1
- package/dist/types/content-store-types.d.ts +2 -1
- package/dist/types/content-store-types.d.ts.map +1 -1
- package/dist/types/search-filter.d.ts +6 -3
- package/dist/types/search-filter.d.ts.map +1 -1
- package/dist/utils/csi-to-api-docs-converter.d.ts +2 -1
- package/dist/utils/csi-to-api-docs-converter.d.ts.map +1 -1
- package/dist/utils/csi-to-api-docs-converter.js +2 -2
- package/dist/utils/csi-to-api-docs-converter.js.map +1 -1
- package/dist/utils/csi-to-store-docs-converter.d.ts.map +1 -1
- package/dist/utils/csi-to-store-docs-converter.js +3 -1
- package/dist/utils/csi-to-store-docs-converter.js.map +1 -1
- package/dist/utils/document-utils.d.ts +5 -0
- package/dist/utils/document-utils.d.ts.map +1 -0
- package/dist/utils/document-utils.js +46 -0
- package/dist/utils/document-utils.js.map +1 -0
- package/dist/utils/filtered-entities.d.ts +34 -0
- package/dist/utils/filtered-entities.d.ts.map +1 -0
- package/dist/utils/filtered-entities.js +177 -0
- package/dist/utils/filtered-entities.js.map +1 -0
- package/dist/utils/model-utils.d.ts +3 -0
- package/dist/utils/model-utils.d.ts.map +1 -1
- package/dist/utils/model-utils.js +8 -1
- package/dist/utils/model-utils.js.map +1 -1
- package/dist/utils/remove-hidden.d.ts +29 -0
- package/dist/utils/remove-hidden.d.ts.map +1 -0
- package/dist/utils/remove-hidden.js +199 -0
- package/dist/utils/remove-hidden.js.map +1 -0
- package/dist/utils/search-utils.d.ts.map +1 -1
- package/dist/utils/search-utils.js +72 -20
- package/dist/utils/search-utils.js.map +1 -1
- package/dist/utils/site-map.d.ts.map +1 -1
- package/dist/utils/site-map.js.map +1 -1
- package/dist/utils/store-to-csi-docs-converter.d.ts.map +1 -1
- package/dist/utils/store-to-csi-docs-converter.js +1 -0
- package/dist/utils/store-to-csi-docs-converter.js.map +1 -1
- package/dist/utils/tree-views.d.ts +8 -0
- package/dist/utils/tree-views.d.ts.map +1 -1
- package/dist/utils/tree-views.js +32 -1
- package/dist/utils/tree-views.js.map +1 -1
- package/package.json +5 -5
- package/src/consts.ts +2 -0
- package/src/content-store.ts +278 -39
- package/src/types/content-store-documents.ts +2 -0
- package/src/types/content-store-types.ts +3 -1
- package/src/types/search-filter.ts +7 -3
- package/src/utils/csi-to-api-docs-converter.ts +4 -2
- package/src/utils/csi-to-store-docs-converter.ts +3 -2
- package/src/utils/document-utils.ts +39 -0
- package/src/utils/filtered-entities.ts +247 -0
- package/src/utils/model-utils.ts +7 -0
- package/src/utils/search-utils.ts +94 -21
- package/src/utils/site-map.ts +0 -1
- package/src/utils/store-to-csi-docs-converter.ts +1 -0
- package/src/utils/tree-views.ts +43 -0
- package/dist/utils/custom-search-filters.d.ts +0 -12
- package/dist/utils/custom-search-filters.d.ts.map +0 -1
- package/dist/utils/custom-search-filters.js +0 -46
- package/dist/utils/custom-search-filters.js.map +0 -1
package/dist/content-store.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ContentStore =
|
|
6
|
+
exports.ContentStore = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const sanitize_filename_1 = __importDefault(require("sanitize-filename"));
|
|
@@ -33,13 +33,14 @@ const user_log_utils_1 = require("./utils/user-log-utils");
|
|
|
33
33
|
const content_engine_1 = require("content-engine");
|
|
34
34
|
const csi_to_api_docs_converter_1 = require("./utils/csi-to-api-docs-converter");
|
|
35
35
|
const file_cache_1 = require("./utils/file-cache");
|
|
36
|
+
const filtered_entities_1 = require("./utils/filtered-entities");
|
|
37
|
+
const consts_1 = require("./consts");
|
|
36
38
|
const ContentStoreEventType = {
|
|
37
39
|
YamlModelFilesChange: 'yamlModelFilesChange',
|
|
38
40
|
PresetFilesChange: 'presetFilesChange',
|
|
39
41
|
ContentSourceInvalidateSchema: 'contentSourceInvalidateSchema',
|
|
40
42
|
ContentSourceContentChange: 'contentSourceContentChange'
|
|
41
43
|
};
|
|
42
|
-
exports.StackbitPresetModelName = 'stackbitPreset';
|
|
43
44
|
class ContentStore {
|
|
44
45
|
constructor(options) {
|
|
45
46
|
this.contentSources = [];
|
|
@@ -262,7 +263,7 @@ class ContentStore {
|
|
|
262
263
|
}
|
|
263
264
|
async loadPresetsFromContentSource(contentSourceData) {
|
|
264
265
|
const presets = lodash_1.default.reduce(contentSourceData.csiDocuments, (result, csiDocument) => {
|
|
265
|
-
if (csiDocument.modelName ===
|
|
266
|
+
if (csiDocument.modelName === consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
266
267
|
const preset = (0, preset_utils_1.getPresetFromDocument)({
|
|
267
268
|
srcType: contentSourceData.srcType,
|
|
268
269
|
srcProjectId: contentSourceData.srcProjectId,
|
|
@@ -364,7 +365,7 @@ class ContentStore {
|
|
|
364
365
|
// find first content source that supports presets
|
|
365
366
|
for (let i = 0; i < contentSources.length; i++) {
|
|
366
367
|
const contentSourceDataRaw = contentSourceRawDataArr[i];
|
|
367
|
-
if ((_d = contentSourceDataRaw === null || contentSourceDataRaw === void 0 ? void 0 : contentSourceDataRaw.csiModelMap) === null || _d === void 0 ? void 0 : _d[
|
|
368
|
+
if ((_d = contentSourceDataRaw === null || contentSourceDataRaw === void 0 ? void 0 : contentSourceDataRaw.csiModelMap) === null || _d === void 0 ? void 0 : _d[consts_1.STACKBIT_PRESET_MODEL_NAME]) {
|
|
368
369
|
this.presetsContentSource = contentSourceDataRaw.instance;
|
|
369
370
|
// reload presets from content source only if needed
|
|
370
371
|
if (init || !contentSourceIds || contentSourceIds.includes(contentSourceDataRaw.id)) {
|
|
@@ -863,7 +864,7 @@ class ContentStore {
|
|
|
863
864
|
var _a;
|
|
864
865
|
// remove preset, make sure there is something to remove first because
|
|
865
866
|
// were explicitly calling onContentChange from deletePreset as well
|
|
866
|
-
if (this.presets[docId] && ((_a = contentSourceData.csiDocumentMap[docId]) === null || _a === void 0 ? void 0 : _a.modelName) ===
|
|
867
|
+
if (this.presets[docId] && ((_a = contentSourceData.csiDocumentMap[docId]) === null || _a === void 0 ? void 0 : _a.modelName) === consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
867
868
|
presetsUpdated = true;
|
|
868
869
|
const preset = this.presets[docId];
|
|
869
870
|
const model = contentSourceData.modelMap[preset.modelName];
|
|
@@ -978,7 +979,7 @@ class ContentStore {
|
|
|
978
979
|
contentSourceData.documents.splice(dataIndex, 1, document);
|
|
979
980
|
contentSourceData.csiDocuments.splice(dataIndex, 1, csiDocument);
|
|
980
981
|
}
|
|
981
|
-
if (csiDocument.modelName ===
|
|
982
|
+
if (csiDocument.modelName === consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
982
983
|
presetsUpdated = true;
|
|
983
984
|
const preset = (0, preset_utils_1.getPresetFromDocument)({
|
|
984
985
|
srcType: contentSourceData.srcType,
|
|
@@ -1201,14 +1202,25 @@ class ContentStore {
|
|
|
1201
1202
|
getAssetSources() {
|
|
1202
1203
|
return (0, asset_sources_utils_1.getAssetSourcesForClient)(this.stackbitConfig);
|
|
1203
1204
|
}
|
|
1204
|
-
getModels() {
|
|
1205
|
+
getModels({ user } = {}) {
|
|
1206
|
+
const configDelegate = (0, config_delegate_1.createConfigDelegate)({
|
|
1207
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1208
|
+
logger: this.userLogger
|
|
1209
|
+
});
|
|
1205
1210
|
return lodash_1.default.reduce(this.contentSourceDataById, (result, contentSourceData) => {
|
|
1211
|
+
var _a;
|
|
1206
1212
|
const contentSourceType = contentSourceData.instance.getContentSourceType();
|
|
1207
1213
|
const srcProjectId = contentSourceData.instance.getProjectId();
|
|
1208
|
-
const filteredModels =
|
|
1214
|
+
const filteredModels = (0, filtered_entities_1.getContentSourceFilteredModelsForUser)({
|
|
1215
|
+
user,
|
|
1216
|
+
configDelegate,
|
|
1217
|
+
contentSourceData,
|
|
1218
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel
|
|
1219
|
+
});
|
|
1220
|
+
const modelsMap = (0, model_utils_1.getModelMap)({ models: filteredModels });
|
|
1209
1221
|
// 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.
|
|
1210
1222
|
// _.setWith(..., Object) ensures the values are always created as object keys, not as array indexes.
|
|
1211
|
-
lodash_1.default.setWith(result, [contentSourceType, srcProjectId],
|
|
1223
|
+
lodash_1.default.setWith(result, [contentSourceType, srcProjectId], modelsMap, Object);
|
|
1212
1224
|
lodash_1.default.setWith(result, [contentSourceType, srcProjectId, '__image_model'], common_schema_1.IMAGE_MODEL, Object);
|
|
1213
1225
|
return result;
|
|
1214
1226
|
}, {});
|
|
@@ -1344,9 +1356,41 @@ class ContentStore {
|
|
|
1344
1356
|
}))
|
|
1345
1357
|
};
|
|
1346
1358
|
}
|
|
1347
|
-
getSiteMapEntries({ locale } = {}) {
|
|
1359
|
+
getSiteMapEntries({ locale, user } = {}) {
|
|
1360
|
+
var _a;
|
|
1348
1361
|
const siteMapEntries = lodash_1.default.reduce(this.siteMapEntryGroups, (accum, siteMapEntryGroup) => {
|
|
1349
1362
|
return lodash_1.default.reduce(siteMapEntryGroup, (accum, siteMapEntry) => {
|
|
1363
|
+
var _a, _b, _c, _d, _e;
|
|
1364
|
+
if (!lodash_1.default.isEmpty(locale)) {
|
|
1365
|
+
// filter out in wrong locale
|
|
1366
|
+
if (siteMapEntry.locale && siteMapEntry.locale !== locale) {
|
|
1367
|
+
return accum;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
if ('document' in siteMapEntry) {
|
|
1371
|
+
// check for hidden documents
|
|
1372
|
+
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(siteMapEntry.document.srcType, siteMapEntry.document.srcProjectId);
|
|
1373
|
+
const document = (_a = (0, content_store_utils_1.getContentSourceDataByIdOrThrow)(contentSourceId, this.contentSourceDataById)) === null || _a === void 0 ? void 0 : _a.documentMap[siteMapEntry.document.id];
|
|
1374
|
+
if (document) {
|
|
1375
|
+
const [filteredDocument] = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1376
|
+
user,
|
|
1377
|
+
documents: [document],
|
|
1378
|
+
filterModel: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterModel,
|
|
1379
|
+
filterDocument: (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.filterDocument,
|
|
1380
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1381
|
+
assetSources: (_e = (_d = this.stackbitConfig) === null || _d === void 0 ? void 0 : _d.assetSources) !== null && _e !== void 0 ? _e : [],
|
|
1382
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1383
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1384
|
+
logger: this.userLogger
|
|
1385
|
+
}),
|
|
1386
|
+
logger: this.userLogger,
|
|
1387
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
1388
|
+
});
|
|
1389
|
+
if (filteredDocument && filteredDocument.hidden) {
|
|
1390
|
+
return accum;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1350
1394
|
if (!siteMapEntry.label) {
|
|
1351
1395
|
const fieldLabelValue = (0, site_map_1.getDocumentFieldLabelValueForSiteMapEntry)({
|
|
1352
1396
|
siteMapEntry,
|
|
@@ -1362,10 +1406,51 @@ class ContentStore {
|
|
|
1362
1406
|
return accum;
|
|
1363
1407
|
}, accum);
|
|
1364
1408
|
}, []);
|
|
1365
|
-
|
|
1409
|
+
if (user && ((_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.transformSitemap)) {
|
|
1410
|
+
const configDelegate = (0, config_delegate_1.createConfigDelegate)({
|
|
1411
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1412
|
+
logger: this.userLogger
|
|
1413
|
+
});
|
|
1414
|
+
return this.stackbitConfig.transformSitemap({ ...configDelegate, sitemap: lodash_1.default.cloneDeep(siteMapEntries), userContext: user });
|
|
1415
|
+
}
|
|
1416
|
+
return siteMapEntries;
|
|
1366
1417
|
}
|
|
1367
|
-
getTreeViews() {
|
|
1368
|
-
|
|
1418
|
+
getTreeViews({ user } = {}) {
|
|
1419
|
+
var _a;
|
|
1420
|
+
let treeViews = this.treeViews;
|
|
1421
|
+
if (((_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.transformTreeViews) && user) {
|
|
1422
|
+
const configDelegate = (0, config_delegate_1.createConfigDelegate)({
|
|
1423
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1424
|
+
logger: this.userLogger
|
|
1425
|
+
});
|
|
1426
|
+
treeViews = this.stackbitConfig.transformTreeViews({ ...configDelegate, treeViews: lodash_1.default.cloneDeep(treeViews), userContext: user });
|
|
1427
|
+
}
|
|
1428
|
+
return (0, tree_views_1.removeHiddenTreeViews)({
|
|
1429
|
+
treeViews,
|
|
1430
|
+
getDocumentForUser: (opts) => {
|
|
1431
|
+
var _a, _b, _c, _d, _e;
|
|
1432
|
+
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(opts.srcType, opts.srcProjectId);
|
|
1433
|
+
const document = (_a = (0, content_store_utils_1.getContentSourceDataByIdOrThrow)(contentSourceId, this.contentSourceDataById)) === null || _a === void 0 ? void 0 : _a.documentMap[opts.srcDocumentId];
|
|
1434
|
+
if (!document || !user) {
|
|
1435
|
+
return document;
|
|
1436
|
+
}
|
|
1437
|
+
const [filteredDocument] = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1438
|
+
user,
|
|
1439
|
+
documents: [document],
|
|
1440
|
+
filterModel: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterModel,
|
|
1441
|
+
filterDocument: (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.filterDocument,
|
|
1442
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1443
|
+
assetSources: (_e = (_d = this.stackbitConfig) === null || _d === void 0 ? void 0 : _d.assetSources) !== null && _e !== void 0 ? _e : [],
|
|
1444
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1445
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1446
|
+
logger: this.userLogger
|
|
1447
|
+
}),
|
|
1448
|
+
logger: this.userLogger,
|
|
1449
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
1450
|
+
});
|
|
1451
|
+
return filteredDocument;
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1369
1454
|
}
|
|
1370
1455
|
getSiteMapEntriesForDocument({ srcType, srcProjectId, srcDocumentId, locale }) {
|
|
1371
1456
|
const key = (0, site_map_1.getSiteMapGroupKeyForDocument)({
|
|
@@ -1377,10 +1462,29 @@ class ContentStore {
|
|
|
1377
1462
|
const siteMapEntries = lodash_1.default.values(siteMapEntryGroup);
|
|
1378
1463
|
return lodash_1.default.isEmpty(locale) ? siteMapEntries : siteMapEntries.filter((siteMapEntry) => !siteMapEntry.locale || siteMapEntry.locale === locale);
|
|
1379
1464
|
}
|
|
1380
|
-
getDocument({ srcDocumentId, srcProjectId, srcType }) {
|
|
1465
|
+
getDocument({ srcDocumentId, srcProjectId, srcType, user }) {
|
|
1466
|
+
var _a, _b, _c, _d;
|
|
1381
1467
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
1382
1468
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
1383
|
-
|
|
1469
|
+
const document = contentSourceData.documentMap[srcDocumentId];
|
|
1470
|
+
if (!document) {
|
|
1471
|
+
return document;
|
|
1472
|
+
}
|
|
1473
|
+
const [filteredDocument] = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1474
|
+
user,
|
|
1475
|
+
documents: [document],
|
|
1476
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel,
|
|
1477
|
+
filterDocument: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterDocument,
|
|
1478
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1479
|
+
assetSources: (_d = (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.assetSources) !== null && _d !== void 0 ? _d : [],
|
|
1480
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1481
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1482
|
+
logger: this.userLogger
|
|
1483
|
+
}),
|
|
1484
|
+
logger: this.userLogger,
|
|
1485
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
1486
|
+
});
|
|
1487
|
+
return filteredDocument !== null && filteredDocument !== void 0 ? filteredDocument : document;
|
|
1384
1488
|
}
|
|
1385
1489
|
getDocumentsByContext({ context, srcProjectId, srcType }) {
|
|
1386
1490
|
const contentSourcesData = (0, content_store_utils_1.findContentSourcesDataForTypeOrId)({
|
|
@@ -1395,16 +1499,33 @@ class ContentStore {
|
|
|
1395
1499
|
return [...documents, ...matchingDocuments];
|
|
1396
1500
|
}, []);
|
|
1397
1501
|
}
|
|
1398
|
-
getDocuments({ locale } = {}) {
|
|
1399
|
-
|
|
1502
|
+
getDocuments({ locale, user } = {}) {
|
|
1503
|
+
var _a, _b, _c, _d;
|
|
1504
|
+
const documents = lodash_1.default.reduce(this.contentSourceDataById, (documents, contentSourceData) => {
|
|
1400
1505
|
const currentDocuments = lodash_1.default.isEmpty(locale)
|
|
1401
1506
|
? contentSourceData.documents
|
|
1402
1507
|
: contentSourceData.documents.filter((document) => !document.locale || document.locale === locale);
|
|
1403
|
-
const filteredDocuments = currentDocuments.filter((document) => document.srcModelName !==
|
|
1508
|
+
const filteredDocuments = currentDocuments.filter((document) => document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME);
|
|
1404
1509
|
return documents.concat(filteredDocuments);
|
|
1405
1510
|
}, []);
|
|
1511
|
+
const filteredDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1512
|
+
user,
|
|
1513
|
+
documents,
|
|
1514
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel,
|
|
1515
|
+
filterDocument: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterDocument,
|
|
1516
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1517
|
+
assetSources: (_d = (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.assetSources) !== null && _d !== void 0 ? _d : [],
|
|
1518
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1519
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1520
|
+
logger: this.userLogger
|
|
1521
|
+
}),
|
|
1522
|
+
logger: this.userLogger,
|
|
1523
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
1524
|
+
});
|
|
1525
|
+
return filteredDocuments;
|
|
1406
1526
|
}
|
|
1407
|
-
getApiDocuments({ documentSpecs } = {}) {
|
|
1527
|
+
getApiDocuments({ documentSpecs, user } = {}) {
|
|
1528
|
+
var _a, _b, _c, _d;
|
|
1408
1529
|
let filteredDocuments;
|
|
1409
1530
|
if (documentSpecs === null || documentSpecs === void 0 ? void 0 : documentSpecs.length) {
|
|
1410
1531
|
// filter over documentSpecs
|
|
@@ -1412,7 +1533,7 @@ class ContentStore {
|
|
|
1412
1533
|
var _a;
|
|
1413
1534
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(docSpec.srcType, docSpec.srcProjectId);
|
|
1414
1535
|
const document = (_a = this.contentSourceDataById[contentSourceId]) === null || _a === void 0 ? void 0 : _a.documentMap[docSpec.srcDocumentId];
|
|
1415
|
-
if (document && document.srcModelName !==
|
|
1536
|
+
if (document && document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME) {
|
|
1416
1537
|
acc.push(document);
|
|
1417
1538
|
}
|
|
1418
1539
|
return acc;
|
|
@@ -1421,9 +1542,23 @@ class ContentStore {
|
|
|
1421
1542
|
else {
|
|
1422
1543
|
// filter over all documents
|
|
1423
1544
|
filteredDocuments = lodash_1.default.reduce(this.contentSourceDataById, (accDocuments, contentSourceData) => {
|
|
1424
|
-
return accDocuments.concat(contentSourceData.documents.filter((document) => document.srcModelName !==
|
|
1545
|
+
return accDocuments.concat(contentSourceData.documents.filter((document) => document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME));
|
|
1425
1546
|
}, []);
|
|
1426
1547
|
}
|
|
1548
|
+
filteredDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1549
|
+
user,
|
|
1550
|
+
documents: filteredDocuments,
|
|
1551
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel,
|
|
1552
|
+
filterDocument: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterDocument,
|
|
1553
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1554
|
+
assetSources: (_d = (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.assetSources) !== null && _d !== void 0 ? _d : [],
|
|
1555
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1556
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1557
|
+
logger: this.userLogger
|
|
1558
|
+
}),
|
|
1559
|
+
logger: this.userLogger,
|
|
1560
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
1561
|
+
});
|
|
1427
1562
|
return {
|
|
1428
1563
|
documents: (0, store_to_api_v2_docs_converter_1.mapDocumentsToApiDocuments)({
|
|
1429
1564
|
documents: filteredDocuments,
|
|
@@ -1437,17 +1572,27 @@ class ContentStore {
|
|
|
1437
1572
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
1438
1573
|
return contentSourceData.assetMap[srcAssetId];
|
|
1439
1574
|
}
|
|
1440
|
-
getAssets({ locale }) {
|
|
1441
|
-
|
|
1575
|
+
getAssets({ locale, user } = {}) {
|
|
1576
|
+
var _a;
|
|
1577
|
+
const assets = lodash_1.default.reduce(this.contentSourceDataById, (assets, contentSourceData) => {
|
|
1442
1578
|
const currentAssets = lodash_1.default.isEmpty(locale)
|
|
1443
1579
|
? contentSourceData.assets
|
|
1444
1580
|
: contentSourceData.assets.filter((asset) => !asset.locale || asset.locale === locale);
|
|
1445
1581
|
return assets.concat(currentAssets);
|
|
1446
1582
|
}, []);
|
|
1583
|
+
const filteredAssets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1584
|
+
user,
|
|
1585
|
+
assets,
|
|
1586
|
+
filterAsset: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterAsset,
|
|
1587
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1588
|
+
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1589
|
+
});
|
|
1590
|
+
return filteredAssets;
|
|
1447
1591
|
}
|
|
1448
|
-
getLocalizedApiObjects({ locale, objectIds }) {
|
|
1592
|
+
getLocalizedApiObjects({ locale, objectIds, user }) {
|
|
1449
1593
|
const hasExplicitLocale = !lodash_1.default.isEmpty(locale);
|
|
1450
1594
|
return lodash_1.default.reduce(this.contentSourceDataById, (objects, contentSourceData) => {
|
|
1595
|
+
var _a, _b, _c, _d, _e;
|
|
1451
1596
|
let documents = objectIds
|
|
1452
1597
|
? contentSourceData.documents.filter((document) => objectIds.includes(document.srcObjectId))
|
|
1453
1598
|
: contentSourceData.documents;
|
|
@@ -1455,7 +1600,28 @@ class ContentStore {
|
|
|
1455
1600
|
let assets = objectIds ? contentSourceData.assets.filter((asset) => objectIds.includes(asset.srcObjectId)) : contentSourceData.assets;
|
|
1456
1601
|
assets = hasExplicitLocale ? assets.filter((asset) => !asset.locale || asset.locale === locale) : assets;
|
|
1457
1602
|
const currentLocale = locale !== null && locale !== void 0 ? locale : contentSourceData.defaultLocaleCode;
|
|
1458
|
-
|
|
1603
|
+
let filteredDocuments = documents.filter((document) => document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME);
|
|
1604
|
+
filteredDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
1605
|
+
user,
|
|
1606
|
+
documents: filteredDocuments,
|
|
1607
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel,
|
|
1608
|
+
filterDocument: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterDocument,
|
|
1609
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1610
|
+
assetSources: (_d = (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.assetSources) !== null && _d !== void 0 ? _d : [],
|
|
1611
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
1612
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
1613
|
+
logger: this.userLogger
|
|
1614
|
+
}),
|
|
1615
|
+
logger: this.userLogger,
|
|
1616
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
1617
|
+
});
|
|
1618
|
+
assets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1619
|
+
user,
|
|
1620
|
+
assets,
|
|
1621
|
+
filterAsset: (_e = this.stackbitConfig) === null || _e === void 0 ? void 0 : _e.filterAsset,
|
|
1622
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1623
|
+
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1624
|
+
});
|
|
1459
1625
|
const documentObjects = (0, store_to_api_docs_converter_1.mapDocumentsToLocalizedApiObjects)({
|
|
1460
1626
|
documents: filteredDocuments,
|
|
1461
1627
|
locale: currentLocale,
|
|
@@ -1465,16 +1631,32 @@ class ContentStore {
|
|
|
1465
1631
|
return objects.concat(documentObjects, imageObjects);
|
|
1466
1632
|
}, []);
|
|
1467
1633
|
}
|
|
1468
|
-
getApiAssets({ srcType, srcProjectId, pageSize = 20, pageNum = 1, searchQuery } = {}) {
|
|
1634
|
+
getApiAssets({ srcType, srcProjectId, pageSize = 20, pageNum = 1, searchQuery, user } = {}) {
|
|
1635
|
+
var _a;
|
|
1469
1636
|
let assets;
|
|
1470
1637
|
if (srcProjectId && srcType) {
|
|
1471
1638
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
1472
1639
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
1473
|
-
|
|
1640
|
+
const filteredAssets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1641
|
+
user,
|
|
1642
|
+
assets: contentSourceData.assets,
|
|
1643
|
+
filterAsset: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterAsset,
|
|
1644
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1645
|
+
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1646
|
+
});
|
|
1647
|
+
assets = (0, store_to_api_docs_converter_1.mapStoreAssetsToAPIAssets)(filteredAssets, this.staticAssetsPublicPath, contentSourceData.defaultLocaleCode);
|
|
1474
1648
|
}
|
|
1475
1649
|
else {
|
|
1476
1650
|
assets = lodash_1.default.reduce(this.contentSourceDataById, (result, contentSourceData) => {
|
|
1477
|
-
|
|
1651
|
+
var _a;
|
|
1652
|
+
const filteredAssets = (0, filtered_entities_1.getFilteredAssetsForUser)({
|
|
1653
|
+
user,
|
|
1654
|
+
assets: contentSourceData.assets,
|
|
1655
|
+
filterAsset: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterAsset,
|
|
1656
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
1657
|
+
configDelegate: (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: this.contentSourceDataById, logger: this.userLogger })
|
|
1658
|
+
});
|
|
1659
|
+
const assets = (0, store_to_api_docs_converter_1.mapStoreAssetsToAPIAssets)(filteredAssets, this.staticAssetsPublicPath, contentSourceData.defaultLocaleCode);
|
|
1478
1660
|
return result.concat(assets);
|
|
1479
1661
|
}, []);
|
|
1480
1662
|
}
|
|
@@ -1615,9 +1797,9 @@ class ContentStore {
|
|
|
1615
1797
|
const document = await this.createDocument({
|
|
1616
1798
|
srcType: this.presetsContentSource.getContentSourceType(),
|
|
1617
1799
|
srcProjectId: this.presetsContentSource.getProjectId(),
|
|
1618
|
-
modelName:
|
|
1800
|
+
modelName: consts_1.STACKBIT_PRESET_MODEL_NAME,
|
|
1619
1801
|
object: {
|
|
1620
|
-
...(0, preset_utils_1.getDocumentObjectFromPreset)(preset, contentSourceData.modelMap[
|
|
1802
|
+
...(0, preset_utils_1.getDocumentObjectFromPreset)(preset, contentSourceData.modelMap[consts_1.STACKBIT_PRESET_MODEL_NAME]),
|
|
1621
1803
|
thumbnail
|
|
1622
1804
|
},
|
|
1623
1805
|
user
|
|
@@ -2083,14 +2265,31 @@ class ContentStore {
|
|
|
2083
2265
|
const scheduledActions = [];
|
|
2084
2266
|
const defaultLocales = {};
|
|
2085
2267
|
contentSourceIds.forEach((contentSourceId) => {
|
|
2268
|
+
var _a, _b, _c, _d;
|
|
2086
2269
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2087
2270
|
lodash_1.default.set(schema, [contentSourceData.srcType, contentSourceData.srcProjectId], contentSourceData.modelMap);
|
|
2088
2271
|
const contentSourceDocuments = lodash_1.default.isEmpty(locale)
|
|
2089
2272
|
? contentSourceData.documents
|
|
2090
2273
|
: contentSourceData.documents.filter((document) => !document.locale || document.locale === locale);
|
|
2091
2274
|
const contentSourceScheduledActions = contentSourceData.scheduledActions;
|
|
2092
|
-
const filteredDocuments = contentSourceDocuments.filter((document) => document.srcModelName !==
|
|
2093
|
-
|
|
2275
|
+
const filteredDocuments = contentSourceDocuments.filter((document) => document.srcModelName !== consts_1.STACKBIT_PRESET_MODEL_NAME);
|
|
2276
|
+
const userDocuments = (0, filtered_entities_1.getFilteredDocumentsForUser)({
|
|
2277
|
+
user: data.user,
|
|
2278
|
+
documents: filteredDocuments,
|
|
2279
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel,
|
|
2280
|
+
filterDocument: (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.filterDocument,
|
|
2281
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
2282
|
+
assetSources: (_d = (_c = this.stackbitConfig) === null || _c === void 0 ? void 0 : _c.assetSources) !== null && _d !== void 0 ? _d : [],
|
|
2283
|
+
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
2284
|
+
getContentSourceDataById: () => this.contentSourceDataById,
|
|
2285
|
+
logger: this.userLogger
|
|
2286
|
+
}),
|
|
2287
|
+
logger: this.userLogger,
|
|
2288
|
+
customActionRunStateMap: this.customActionRunStateMap
|
|
2289
|
+
});
|
|
2290
|
+
// filter out hidden documents from the search
|
|
2291
|
+
const visibleDocuments = userDocuments.filter((document) => !document.hidden);
|
|
2292
|
+
documents.push(...visibleDocuments);
|
|
2094
2293
|
scheduledActions.push(...contentSourceScheduledActions);
|
|
2095
2294
|
if (contentSourceData.defaultLocaleCode) {
|
|
2096
2295
|
defaultLocales[contentSourceId] = contentSourceData.defaultLocaleCode;
|
|
@@ -2105,8 +2304,8 @@ class ContentStore {
|
|
|
2105
2304
|
defaultLocales
|
|
2106
2305
|
});
|
|
2107
2306
|
}
|
|
2108
|
-
async getDocumentVersions({ srcType, srcProjectId, documentId, locale }) {
|
|
2109
|
-
var _a, _b;
|
|
2307
|
+
async getDocumentVersions({ srcType, srcProjectId, documentId, locale, user }) {
|
|
2308
|
+
var _a, _b, _c;
|
|
2110
2309
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
2111
2310
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2112
2311
|
locale = locale !== null && locale !== void 0 ? locale : contentSourceData.defaultLocaleCode;
|
|
@@ -2120,8 +2319,17 @@ class ContentStore {
|
|
|
2120
2319
|
throw new Error('Content source plugin missing required method: getDocumentVersions');
|
|
2121
2320
|
}
|
|
2122
2321
|
const { versions } = await contentSourceData.instance.getDocumentVersions({ documentId });
|
|
2322
|
+
const models = (0, filtered_entities_1.getContentSourceFilteredModelsForUser)({
|
|
2323
|
+
user,
|
|
2324
|
+
contentSourceData,
|
|
2325
|
+
configDelegate: (0, config_delegate_1.createConfigDelegate)({
|
|
2326
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
2327
|
+
logger: this.userLogger
|
|
2328
|
+
}),
|
|
2329
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel
|
|
2330
|
+
});
|
|
2123
2331
|
const apiVersions = (0, csi_to_api_docs_converter_1.mapDocumentVersionsToApiDocumentVersions)({
|
|
2124
|
-
assetSources: (
|
|
2332
|
+
assetSources: (_c = (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.assetSources) !== null && _c !== void 0 ? _c : [],
|
|
2125
2333
|
customActionRunStateMap: this.customActionRunStateMap,
|
|
2126
2334
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
2127
2335
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
@@ -2130,12 +2338,13 @@ class ContentStore {
|
|
|
2130
2338
|
versions,
|
|
2131
2339
|
contentSourceData,
|
|
2132
2340
|
contentSourceDataById: this.contentSourceDataById,
|
|
2133
|
-
locale
|
|
2341
|
+
locale,
|
|
2342
|
+
modelMap: (0, model_utils_1.getModelMap)({ models })
|
|
2134
2343
|
});
|
|
2135
2344
|
return { versions: apiVersions };
|
|
2136
2345
|
}
|
|
2137
|
-
async getDocumentForVersion({ srcType, srcProjectId, documentId, versionId, locale }) {
|
|
2138
|
-
var _a, _b;
|
|
2346
|
+
async getDocumentForVersion({ srcType, srcProjectId, documentId, versionId, locale, user }) {
|
|
2347
|
+
var _a, _b, _c;
|
|
2139
2348
|
const contentSourceId = (0, content_store_utils_1.getContentSourceId)(srcType, srcProjectId);
|
|
2140
2349
|
const contentSourceData = this.getContentSourceDataByIdOrThrow(contentSourceId);
|
|
2141
2350
|
locale = locale !== null && locale !== void 0 ? locale : contentSourceData.defaultLocaleCode;
|
|
@@ -2150,9 +2359,18 @@ class ContentStore {
|
|
|
2150
2359
|
throw new Error('Content source plugin missing required method: getDocumentForVersion');
|
|
2151
2360
|
}
|
|
2152
2361
|
const { version } = await contentSourceData.instance.getDocumentForVersion({ documentId, versionId });
|
|
2362
|
+
const models = (0, filtered_entities_1.getContentSourceFilteredModelsForUser)({
|
|
2363
|
+
user,
|
|
2364
|
+
contentSourceData,
|
|
2365
|
+
configDelegate: (0, config_delegate_1.createConfigDelegate)({
|
|
2366
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
2367
|
+
logger: this.userLogger
|
|
2368
|
+
}),
|
|
2369
|
+
filterModel: (_a = this.stackbitConfig) === null || _a === void 0 ? void 0 : _a.filterModel
|
|
2370
|
+
});
|
|
2153
2371
|
const [apiVersion] = (0, csi_to_api_docs_converter_1.mapDocumentVersionsToApiDocumentVersions)({
|
|
2154
2372
|
versions: [version],
|
|
2155
|
-
assetSources: (
|
|
2373
|
+
assetSources: (_c = (_b = this.stackbitConfig) === null || _b === void 0 ? void 0 : _b.assetSources) !== null && _c !== void 0 ? _c : [],
|
|
2156
2374
|
customActionRunStateMap: this.customActionRunStateMap,
|
|
2157
2375
|
createConfigDelegate: (0, config_delegate_1.getCreateConfigDelegateThunk)({
|
|
2158
2376
|
getContentSourceDataById: () => this.contentSourceDataById,
|
|
@@ -2160,7 +2378,8 @@ class ContentStore {
|
|
|
2160
2378
|
}),
|
|
2161
2379
|
contentSourceData,
|
|
2162
2380
|
locale,
|
|
2163
|
-
contentSourceDataById: this.contentSourceDataById
|
|
2381
|
+
contentSourceDataById: this.contentSourceDataById,
|
|
2382
|
+
modelMap: (0, model_utils_1.getModelMap)({ models })
|
|
2164
2383
|
});
|
|
2165
2384
|
if (!apiVersion || !apiVersion.object || !apiVersion.document || !apiVersion.apiDocument) {
|
|
2166
2385
|
throw new Error(`getDocumentForVersion could not transform document into api object for document ${version.documentId}`);
|