@stackbit/cms-contentstack 0.1.2-staging.1 → 0.1.2-staging.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.
@@ -0,0 +1,41 @@
1
+ import * as StackbitTypes from '@stackbit/types';
2
+ import { EntryData } from '@contentstack/management/types/stack/contentType/entry';
3
+ import { Entry } from './contentstack-types';
4
+ import { ModelWithContext } from './contentstack-schema-converter';
5
+ import { DocumentWithContext } from './contentstack-entries-converter';
6
+ declare type GetModelByName = (modelName: string) => ModelWithContext | undefined;
7
+ declare type GetDocumentById = (documentId: string) => DocumentWithContext | undefined;
8
+ export declare function createEntryFromOperationFields({ updateOperationFields, model, getDocumentById, getModelByName, logger }: {
9
+ updateOperationFields: Record<string, StackbitTypes.UpdateOperationField>;
10
+ model: ModelWithContext;
11
+ getDocumentById: GetDocumentById;
12
+ getModelByName: GetModelByName;
13
+ logger: StackbitTypes.Logger;
14
+ }): EntryData;
15
+ export declare function updateEntryFromUpdateOperations({ entry, updateOperations, getDocumentById, getModelByName, logger }: {
16
+ entry: Entry;
17
+ updateOperations: StackbitTypes.UpdateOperation[];
18
+ getDocumentById: GetDocumentById;
19
+ getModelByName: GetModelByName;
20
+ logger: StackbitTypes.Logger;
21
+ }): Entry;
22
+ export declare function getUpdatedEntryAtFieldPathWithOperation({ entry, updateOperation, model, getDocumentById, getModelByName, logger }: {
23
+ entry: Entry;
24
+ updateOperation: StackbitTypes.UpdateOperation;
25
+ model: ModelWithContext;
26
+ getDocumentById: GetDocumentById;
27
+ getModelByName: GetModelByName;
28
+ logger: StackbitTypes.Logger;
29
+ }): Entry;
30
+ export declare function convertOperationFieldValue({ updateOperationField, rootModel, modelField, entryFieldPath, modelFieldPath, getDocumentById, getModelByName, errorPrefix }: {
31
+ updateOperationField: StackbitTypes.UpdateOperationField;
32
+ rootModel: ModelWithContext;
33
+ modelField: StackbitTypes.FieldSpecificProps;
34
+ entryFieldPath: (string | number)[];
35
+ modelFieldPath: string[];
36
+ getDocumentById: GetDocumentById;
37
+ getModelByName: GetModelByName;
38
+ errorPrefix: string;
39
+ }): any;
40
+ export {};
41
+ //# sourceMappingURL=contentstack-conversion-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentstack-conversion-utils.d.ts","sourceRoot":"","sources":["../src/contentstack-conversion-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,wDAAwD,CAAC;AAEnF,OAAO,EAAE,KAAK,EAAS,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,aAAK,cAAc,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAC1E,aAAK,eAAe,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,mBAAmB,GAAG,SAAS,CAAC;AAE/E,wBAAgB,8BAA8B,CAAC,EAC3C,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,cAAc,EACd,MAAM,EACT,EAAE;IACC,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAAC;IAC1E,KAAK,EAAE,gBAAgB,CAAC;IACxB,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;CAChC,GAAG,SAAS,CAsBZ;AAED,wBAAgB,+BAA+B,CAAC,EAC5C,KAAK,EACL,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,MAAM,EACT,EAAE;IACC,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,aAAa,CAAC,eAAe,EAAE,CAAC;IAClD,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;CAChC,GAAG,KAAK,CA8CR;AAED,wBAAgB,uCAAuC,CAAC,EACpD,KAAK,EACL,eAAe,EACf,KAAK,EACL,eAAe,EACf,cAAc,EACd,MAAM,EACT,EAAE;IACC,KAAK,EAAE,KAAK,CAAC;IACb,eAAe,EAAE,aAAa,CAAC,eAAe,CAAC;IAC/C,KAAK,EAAE,gBAAgB,CAAC;IACxB,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC;CAChC,GAAG,KAAK,CA+OR;AA2FD,wBAAgB,0BAA0B,CAAC,EACvC,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,WAAW,EACd,EAAE;IACC,oBAAoB,EAAE,aAAa,CAAC,oBAAoB,CAAC;IACzD,SAAS,EAAE,gBAAgB,CAAC;IAC5B,UAAU,EAAE,aAAa,CAAC,kBAAkB,CAAC;IAC7C,cAAc,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACpC,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;CACvB,GAAG,GAAG,CA+KN"}
@@ -0,0 +1,504 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.convertOperationFieldValue = exports.getUpdatedEntryAtFieldPathWithOperation = exports.updateEntryFromUpdateOperations = exports.createEntryFromOperationFields = void 0;
7
+ const uuid_1 = require("uuid");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ function createEntryFromOperationFields({ updateOperationFields, model, getDocumentById, getModelByName, logger }) {
10
+ return lodash_1.default.reduce(updateOperationFields, (accum, updateOperationField, fieldName) => {
11
+ const modelField = getModelField(model, fieldName);
12
+ if (!modelField) {
13
+ return accum;
14
+ }
15
+ accum[fieldName] = convertOperationFieldValue({
16
+ updateOperationField,
17
+ modelField,
18
+ rootModel: model,
19
+ entryFieldPath: [fieldName],
20
+ modelFieldPath: [fieldName],
21
+ getDocumentById,
22
+ getModelByName,
23
+ errorPrefix: 'Error occurred while creating an entry.'
24
+ });
25
+ return accum;
26
+ }, { title: (0, uuid_1.v4)() });
27
+ }
28
+ exports.createEntryFromOperationFields = createEntryFromOperationFields;
29
+ function updateEntryFromUpdateOperations({ entry, updateOperations, getDocumentById, getModelByName, logger }) {
30
+ const model = getModelByName(entry.content_type_uid);
31
+ if (!model) {
32
+ throw new Error(`Error occurred while updating entry ${entry.uid}, model ${entry.content_type_uid} not found.`);
33
+ }
34
+ let updatedEntry = lodash_1.default.reduce(updateOperations, (entry, updateOperation) => {
35
+ return getUpdatedEntryAtFieldPathWithOperation({
36
+ entry,
37
+ updateOperation,
38
+ model,
39
+ getDocumentById,
40
+ getModelByName,
41
+ logger
42
+ });
43
+ }, entry);
44
+ // Create a copy of the entry and remove fields that were not updated.
45
+ const modelFieldsMap = lodash_1.default.keyBy(model.fields, 'name');
46
+ const updatedRootFieldNames = updateOperations.reduce((fieldNamesMap, updateOperations) => {
47
+ fieldNamesMap[updateOperations.fieldPath[0]] = true;
48
+ return fieldNamesMap;
49
+ }, {});
50
+ // const includedMetaProps = _.transform(
51
+ // ['uid', 'stackHeaders', 'content_type_uid', 'taxonomy_uid', 'locale', '_version', 'urlPath'],
52
+ // (map, value) => {
53
+ // map[value] = true;
54
+ // },
55
+ // {} as Record<string, boolean>
56
+ // );
57
+ updatedEntry = lodash_1.default.reduce(updatedEntry, (newEntry, value, prop) => {
58
+ if (!modelFieldsMap[prop] || updatedRootFieldNames[prop]) {
59
+ newEntry[prop] = value;
60
+ }
61
+ return newEntry;
62
+ }, {});
63
+ return sanitizeForUpdate(updatedEntry);
64
+ }
65
+ exports.updateEntryFromUpdateOperations = updateEntryFromUpdateOperations;
66
+ function getUpdatedEntryAtFieldPathWithOperation({ entry, updateOperation, model, getDocumentById, getModelByName, logger }) {
67
+ let opMessage;
68
+ switch (updateOperation.opType) {
69
+ case 'set':
70
+ opMessage = 'setting a field';
71
+ break;
72
+ case 'unset':
73
+ opMessage = 'unsetting a field';
74
+ break;
75
+ case 'insert':
76
+ opMessage = 'inserting an item into a list';
77
+ break;
78
+ case 'remove':
79
+ opMessage = 'removing an item from a list';
80
+ break;
81
+ case 'reorder':
82
+ opMessage = 'reordering a list';
83
+ break;
84
+ }
85
+ const errorPrefix = `Error occurred while ${opMessage} in entry '${entry.uid}'.`;
86
+ function createError(detailedMessage) {
87
+ return new Error(`${errorPrefix} ${detailedMessage}`);
88
+ }
89
+ function iterateModel({ value, model, fieldPath, entryFieldPath, modelFieldPath }) {
90
+ if (fieldPath.length === 0) {
91
+ return getValueForOperation({
92
+ updateOperation,
93
+ value,
94
+ rootEntry: entry,
95
+ rootModel: model,
96
+ entryFieldPath,
97
+ modelFieldPath,
98
+ getDocumentById,
99
+ getModelByName,
100
+ errorPrefix,
101
+ logger
102
+ });
103
+ }
104
+ const fieldName = lodash_1.default.head(fieldPath);
105
+ const fieldPathTail = lodash_1.default.tail(fieldPath);
106
+ if (typeof fieldName !== 'string') {
107
+ throw createError(`The field '${fieldName}' in field path '${entryFieldPath.concat(fieldName).join('.')}' ` +
108
+ `is not a string, 'typeof ${fieldName} === ${typeof fieldName}'.`);
109
+ }
110
+ const modelField = getModelField(model, fieldName);
111
+ if (!modelField) {
112
+ throw createError(`The field '${fieldName}' in field path '${entryFieldPath.concat(fieldName).join('.')}' does not exist in model '${model.name}'.`);
113
+ }
114
+ return {
115
+ ...value,
116
+ [fieldName]: iterateField({
117
+ value: value ? value[fieldName] : undefined,
118
+ modelField,
119
+ fieldPath: fieldPathTail,
120
+ rootModel: model,
121
+ entryFieldPath: entryFieldPath.concat(fieldName),
122
+ modelFieldPath: modelFieldPath.concat(fieldName)
123
+ })
124
+ };
125
+ }
126
+ function iterateField({ value, modelField, fieldPath, rootModel, entryFieldPath, modelFieldPath }) {
127
+ var _a, _b;
128
+ if (fieldPath.length === 0) {
129
+ return getValueForOperation({
130
+ updateOperation,
131
+ value,
132
+ rootEntry: entry,
133
+ rootModel,
134
+ entryFieldPath,
135
+ modelFieldPath,
136
+ getDocumentById,
137
+ getModelByName,
138
+ errorPrefix,
139
+ logger
140
+ });
141
+ }
142
+ if (modelField.type === 'object') {
143
+ // The value must be an object to apply the operation on its nested field with name fieldName,
144
+ // otherwise the fieldPath is illegal
145
+ if (!isObject(value)) {
146
+ throw createError(`The field path '${entryFieldPath.join('.')}' points to an empty value.`);
147
+ }
148
+ const fieldName = lodash_1.default.head(fieldPath);
149
+ const fieldPathTail = lodash_1.default.tail(fieldPath);
150
+ if (typeof fieldName !== 'string') {
151
+ throw createError(`The field '${fieldName}' in field path '${entryFieldPath.concat(fieldName).join('.')}' ` +
152
+ `is not a string, 'typeof ${fieldName} === ${typeof fieldName}'.`);
153
+ }
154
+ const childModelField = getModelField(modelField, fieldName);
155
+ if (!childModelField) {
156
+ throw createError(`The field '${fieldName}' in field path '${entryFieldPath.concat(fieldName).join('.')}' does not exist in model '${model.name}'.`);
157
+ }
158
+ return {
159
+ ...value,
160
+ [fieldName]: iterateField({
161
+ value: value ? value[fieldName] : undefined,
162
+ modelField: childModelField,
163
+ fieldPath: fieldPathTail,
164
+ rootModel,
165
+ entryFieldPath: entryFieldPath.concat(fieldName),
166
+ modelFieldPath: modelFieldPath.concat(fieldName)
167
+ })
168
+ };
169
+ }
170
+ else if (modelField.type === 'model') {
171
+ // The value must be an object to apply the operation on its nested field with name fieldName,
172
+ // otherwise the fieldPath is illegal
173
+ if (!isObject(value)) {
174
+ throw createError(`The field path '${entryFieldPath.join('.')}' points to an empty value.`);
175
+ }
176
+ const fieldPathStr = modelFieldPath.join('.');
177
+ const blockMap = (_b = (_a = rootModel.context) === null || _a === void 0 ? void 0 : _a.blockMap) === null || _b === void 0 ? void 0 : _b[fieldPathStr];
178
+ if (blockMap) {
179
+ // This is a modular blocks field with keys mapping to inline (object)
180
+ // or global (model) fields mapped by model.context.blockMap[blockUID].
181
+ const blockUIDs = lodash_1.default.keys(value);
182
+ const blockUID = blockUIDs[0];
183
+ if (blockUIDs.length !== 1 || !blockUID) {
184
+ throw createError(`The modular block at field path '${entryFieldPath.join('.')}' has no UID.`);
185
+ }
186
+ const block = value[blockUID];
187
+ if (!isObject(block)) {
188
+ throw createError(`The field path '${entryFieldPath.join('.')}' points to an empty modular block '${blockUID}'.`);
189
+ }
190
+ const modelName = blockMap.blockIdToModelName[blockUID];
191
+ if (!modelName) {
192
+ throw createError(`Could not match model name for modular block '${blockUID}' at field path '${entryFieldPath.join('.')}'.`);
193
+ }
194
+ const nestedModel = getModelByName(modelName);
195
+ if (!nestedModel) {
196
+ throw createError(`Could not find model named '${modelName}' for modular block '${blockUID}' ` + `at field path '${entryFieldPath.join('.')}'.`);
197
+ }
198
+ return {
199
+ [blockUID]: iterateModel({
200
+ value: block,
201
+ fieldPath: fieldPath,
202
+ model: nestedModel,
203
+ entryFieldPath: entryFieldPath,
204
+ modelFieldPath: []
205
+ })
206
+ };
207
+ }
208
+ else {
209
+ // This is as a regular global field (model) with a single model or as a CNTSTK_LINK_MODEL
210
+ if (modelField.models.length !== 1) {
211
+ throw createError(`A model field at field path '${entryFieldPath.join('.')}' has more than one (or zero) models ${modelField.models.join('.')}.`);
212
+ }
213
+ const modelName = modelField.models[0];
214
+ const nestedModel = getModelByName(modelName);
215
+ if (!nestedModel) {
216
+ throw createError(`Could not find model named '${modelName}' for object at field path '${entryFieldPath.join('.')}.'`);
217
+ }
218
+ return iterateModel({
219
+ value: value,
220
+ fieldPath: fieldPath,
221
+ model: nestedModel,
222
+ entryFieldPath: entryFieldPath,
223
+ modelFieldPath: []
224
+ });
225
+ }
226
+ }
227
+ else if (modelField.type === 'list') {
228
+ // The value must be an array to apply the operation on its nested items with item index,
229
+ // otherwise the fieldPath is illegal
230
+ if (!Array.isArray(value)) {
231
+ throw createError(`The value at field path '${entryFieldPath.join('.')}' is not an array.`);
232
+ }
233
+ const fieldName = lodash_1.default.head(fieldPath);
234
+ const fieldPathTail = lodash_1.default.tail(fieldPath);
235
+ const index = lodash_1.default.toNumber(fieldName);
236
+ if (typeof index !== 'number' || lodash_1.default.isNaN(index)) {
237
+ throw createError(`The field '${fieldName}' in field path '${entryFieldPath.concat(fieldName).join('.')}' ` +
238
+ `is not a string, 'typeof ${fieldName} === ${typeof fieldName}'.`);
239
+ }
240
+ const newArray = value.slice();
241
+ newArray.splice(index, 1, iterateField({
242
+ value: value[index],
243
+ fieldPath: fieldPathTail,
244
+ modelField: modelField.items,
245
+ rootModel,
246
+ entryFieldPath: entryFieldPath.concat(index),
247
+ modelFieldPath: modelFieldPath
248
+ }));
249
+ return newArray;
250
+ }
251
+ throw createError(`The field type '${modelField.type}' at field path '${entryFieldPath.join('.')}' is not a container type (object, model, list).`);
252
+ }
253
+ return iterateModel({
254
+ value: entry,
255
+ model,
256
+ fieldPath: updateOperation.fieldPath,
257
+ entryFieldPath: [],
258
+ modelFieldPath: []
259
+ });
260
+ }
261
+ exports.getUpdatedEntryAtFieldPathWithOperation = getUpdatedEntryAtFieldPathWithOperation;
262
+ function getValueForOperation({ updateOperation, value, rootModel, entryFieldPath, modelFieldPath, getDocumentById, getModelByName, errorPrefix, logger }) {
263
+ switch (updateOperation.opType) {
264
+ case 'set':
265
+ return convertOperationFieldValue({
266
+ updateOperationField: updateOperation.field,
267
+ modelField: updateOperation.modelField,
268
+ rootModel: rootModel,
269
+ entryFieldPath: entryFieldPath,
270
+ modelFieldPath: modelFieldPath,
271
+ getModelByName,
272
+ getDocumentById,
273
+ errorPrefix
274
+ });
275
+ case 'unset': {
276
+ // TODO: is unset different per type?
277
+ return null;
278
+ }
279
+ case 'insert': {
280
+ if (typeof value === 'undefined') {
281
+ value = [];
282
+ }
283
+ if (!Array.isArray(value)) {
284
+ throw new Error(`${errorPrefix} The field path points to a non array value.`);
285
+ }
286
+ const newValue = convertOperationFieldValue({
287
+ updateOperationField: updateOperation.item,
288
+ modelField: updateOperation.modelField.items,
289
+ rootModel: rootModel,
290
+ entryFieldPath: entryFieldPath,
291
+ modelFieldPath: modelFieldPath,
292
+ getModelByName,
293
+ getDocumentById,
294
+ errorPrefix
295
+ });
296
+ if (typeof updateOperation.index === 'undefined') {
297
+ return value.concat(newValue);
298
+ }
299
+ const newArray = value.slice();
300
+ newArray.splice(updateOperation.index, 0, newValue);
301
+ return newArray;
302
+ }
303
+ case 'remove': {
304
+ if (typeof value === 'undefined') {
305
+ value = [];
306
+ }
307
+ if (!Array.isArray(value)) {
308
+ throw new Error(`${errorPrefix} The field path points to a non array value.`);
309
+ }
310
+ const newArray = value.slice();
311
+ newArray.splice(updateOperation.index, 1);
312
+ return newArray;
313
+ }
314
+ case 'reorder': {
315
+ if (typeof value === 'undefined') {
316
+ value = [];
317
+ }
318
+ if (!Array.isArray(value)) {
319
+ throw new Error(`${errorPrefix} The field path points to a non array value.`);
320
+ }
321
+ return updateOperation.order.map((newIndex) => value[newIndex]);
322
+ }
323
+ default: {
324
+ const _exhaustiveCheck = updateOperation;
325
+ return _exhaustiveCheck;
326
+ }
327
+ }
328
+ }
329
+ function convertOperationFieldValue({ updateOperationField, rootModel, modelField, entryFieldPath, modelFieldPath, getDocumentById, getModelByName, errorPrefix }) {
330
+ var _a, _b;
331
+ function createError(detailedMessage) {
332
+ return new Error(`${errorPrefix} ${detailedMessage}`);
333
+ }
334
+ switch (updateOperationField.type) {
335
+ case 'string':
336
+ case 'url':
337
+ case 'slug':
338
+ case 'text':
339
+ case 'markdown':
340
+ case 'html':
341
+ case 'date':
342
+ case 'datetime':
343
+ case 'color':
344
+ case 'enum': {
345
+ return updateOperationField.value;
346
+ }
347
+ case 'number': {
348
+ return updateOperationField.value || 0;
349
+ }
350
+ case 'boolean': {
351
+ return updateOperationField.value || false;
352
+ }
353
+ case 'file':
354
+ case 'image': {
355
+ return updateOperationField.value || null;
356
+ }
357
+ case 'richText':
358
+ case 'json':
359
+ case 'style':
360
+ case 'cross-reference': {
361
+ return updateOperationField.value;
362
+ }
363
+ case 'reference': {
364
+ if ((updateOperationField === null || updateOperationField === void 0 ? void 0 : updateOperationField.refType) === 'asset') {
365
+ return updateOperationField.refId;
366
+ }
367
+ const document = getDocumentById(updateOperationField === null || updateOperationField === void 0 ? void 0 : updateOperationField.refId);
368
+ if (!document) {
369
+ throw createError(`Could not find entry with ID '${updateOperationField === null || updateOperationField === void 0 ? void 0 : updateOperationField.refId}' referenced at field path ${entryFieldPath.join('.')}.`);
370
+ }
371
+ return {
372
+ uid: updateOperationField.refId,
373
+ _content_type_uid: document.modelName
374
+ };
375
+ }
376
+ case 'object': {
377
+ if (modelField.type !== 'object') {
378
+ throw createError(`The operation field type 'object' does not match model field type '${modelField.type}' at field path ${entryFieldPath.join('.')}.`);
379
+ }
380
+ return lodash_1.default.reduce(updateOperationField.fields, (accum, nestedUpdateOperationField, fieldName) => {
381
+ const nestedModelField = getModelField(modelField, fieldName);
382
+ if (!nestedModelField) {
383
+ return accum;
384
+ }
385
+ accum[fieldName] = convertOperationFieldValue({
386
+ updateOperationField: nestedUpdateOperationField,
387
+ rootModel,
388
+ modelField: nestedModelField,
389
+ entryFieldPath: entryFieldPath.concat(fieldName),
390
+ modelFieldPath: modelFieldPath.concat(fieldName),
391
+ getDocumentById,
392
+ getModelByName,
393
+ errorPrefix
394
+ });
395
+ return accum;
396
+ }, {});
397
+ }
398
+ case 'model': {
399
+ if (modelField.type !== 'model') {
400
+ throw createError(`The operation field type 'model' does not match model field type '${modelField.type}' at field path ${entryFieldPath.join('.')}.`);
401
+ }
402
+ const nestedModel = getModelByName(updateOperationField.modelName);
403
+ if (!nestedModel) {
404
+ throw createError(`Could not find model named '${updateOperationField.modelName}' for field at path '${entryFieldPath.join('.')}'.`);
405
+ }
406
+ const fieldPathStr = modelFieldPath.join('.');
407
+ const blockMap = (_b = (_a = rootModel.context) === null || _a === void 0 ? void 0 : _a.blockMap) === null || _b === void 0 ? void 0 : _b[fieldPathStr];
408
+ if (blockMap) {
409
+ // this is a modular blocks field with keys mapping to inline (object) or global (model) fields
410
+ // mapped by context.blockMap[blockUID]
411
+ const blockUID = blockMap.modelNameToBlockId[updateOperationField.modelName];
412
+ if (!blockUID) {
413
+ throw createError(`Could not match modular block UI for model '${updateOperationField.modelName}' for field path '${entryFieldPath.join('.')}'.`);
414
+ }
415
+ return {
416
+ [blockUID]: lodash_1.default.reduce(updateOperationField.fields, (accum, nestedUpdateOperationField, fieldName) => {
417
+ const nestedModelField = getModelField(nestedModel, fieldName);
418
+ if (!nestedModelField) {
419
+ return accum;
420
+ }
421
+ accum[fieldName] = convertOperationFieldValue({
422
+ updateOperationField: nestedUpdateOperationField,
423
+ rootModel: nestedModel,
424
+ modelField: nestedModelField,
425
+ entryFieldPath: entryFieldPath.concat([blockUID, fieldName]),
426
+ modelFieldPath: [fieldName],
427
+ getDocumentById,
428
+ getModelByName,
429
+ errorPrefix
430
+ });
431
+ return accum;
432
+ }, {})
433
+ };
434
+ }
435
+ else {
436
+ // this is a regular global field (model) with a single model or as a CNTSTK_LINK_MODEL
437
+ return lodash_1.default.reduce(updateOperationField.fields, (accum, nestedUpdateOperationField, fieldName) => {
438
+ const nestedModelField = getModelField(nestedModel, fieldName);
439
+ if (!nestedModelField) {
440
+ return accum;
441
+ }
442
+ accum[fieldName] = convertOperationFieldValue({
443
+ updateOperationField: nestedUpdateOperationField,
444
+ rootModel: nestedModel,
445
+ modelField: nestedModelField,
446
+ entryFieldPath: entryFieldPath.concat(fieldName),
447
+ modelFieldPath: [fieldName],
448
+ getDocumentById,
449
+ getModelByName,
450
+ errorPrefix
451
+ });
452
+ return accum;
453
+ }, {});
454
+ }
455
+ }
456
+ case 'list': {
457
+ if (modelField.type !== 'list') {
458
+ throw createError(`The operation field type 'list' does not match model field type '${modelField.type}' at field path ${entryFieldPath.join('.')}.`);
459
+ }
460
+ return lodash_1.default.reduce(updateOperationField.items, (accum, listItem, index) => {
461
+ accum.push(convertOperationFieldValue({
462
+ updateOperationField: listItem,
463
+ rootModel,
464
+ modelField: modelField.items,
465
+ entryFieldPath: entryFieldPath.concat(index),
466
+ modelFieldPath: modelFieldPath,
467
+ getDocumentById,
468
+ getModelByName,
469
+ errorPrefix
470
+ }));
471
+ return accum;
472
+ }, []);
473
+ }
474
+ default: {
475
+ const _exhaustiveCheck = updateOperationField;
476
+ return _exhaustiveCheck;
477
+ }
478
+ }
479
+ }
480
+ exports.convertOperationFieldValue = convertOperationFieldValue;
481
+ function getModelField(model, fieldName) {
482
+ var _a;
483
+ return (_a = model.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.name === fieldName);
484
+ }
485
+ function isObject(value) {
486
+ return lodash_1.default.isPlainObject(value);
487
+ }
488
+ function sanitizeForUpdate(entry) {
489
+ return lodash_1.default.cloneDeepWith(entry, (value) => {
490
+ if (isAsset(value)) {
491
+ return value.uid;
492
+ }
493
+ });
494
+ }
495
+ function isAsset(value) {
496
+ if (!isObject(value) || !value.uid) {
497
+ return false;
498
+ }
499
+ // if all asset keys are present in the value, then it is an asset
500
+ const imageKeys = ['uid', 'created_at', 'updated_at', 'created_by', 'updated_by', 'content_type', 'file_size', 'filename', 'url'];
501
+ const objectKeys = lodash_1.default.keys(value);
502
+ return lodash_1.default.difference(imageKeys, objectKeys).length === 0;
503
+ }
504
+ //# sourceMappingURL=contentstack-conversion-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentstack-conversion-utils.js","sourceRoot":"","sources":["../src/contentstack-conversion-utils.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAoC;AACpC,oDAAuB;AAWvB,SAAgB,8BAA8B,CAAC,EAC3C,qBAAqB,EACrB,KAAK,EACL,eAAe,EACf,cAAc,EACd,MAAM,EAOT;IACG,OAAO,gBAAC,CA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Y,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAClI,MAAM,UAAU,GAAG,gBAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,gBAAC,CAAC,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC5D,CAAC"}
@@ -220,6 +220,11 @@ export declare type Entry = ContentStackEntry & {
220
220
  updated_at: string;
221
221
  created_by: string;
222
222
  updated_by: string;
223
+ /**
224
+ * The entry's locale.
225
+ * Note, this can be different from the `publish_details.locale` if the
226
+ * entry was not localized for the published locale.
227
+ */
223
228
  locale?: string;
224
229
  tags?: string[];
225
230
  publish_details?: PublishDetails[];
@@ -232,23 +237,49 @@ export declare type PublishDetails = {
232
237
  environment: string;
233
238
  time: string;
234
239
  user: string;
240
+ /**
241
+ * The version of the entry that was published.
242
+ * If the entry_locale is provided, then the version is of that entry locale.
243
+ * Otherwise, it is a version of the entry's own locale.
244
+ */
235
245
  version: number;
236
246
  /**
237
- * The locale of the published document.
238
- * Note, the locale may be different from entry's own locale.
247
+ * The published locale.
248
+ * Note, the published locale may be different from the entry's locale if a
249
+ * non-localized entry was published.
250
+ *
251
+ * For example, a non-localized "fr-fr" entry can be published to the "fr-fr"
252
+ * locale. In this case, the entry will be published from the values stored
253
+ * in the entry of the fallback locale, e.g., 'en-us'. When this entry is
254
+ * fetched using the content delivery API with `locale=fr-fr` it will return
255
+ * the entry with `locale: 'en-us'`, and `publish_details.locale: 'fr-fr'`.
256
+ *
257
+ * If an entry was not published to a `fr-fr` locale but was published to its
258
+ * fallback locale, then it will be returned from the Content Delivery API
259
+ * for `locale=fr-fr` parameter only if it also has `include_fallback=false`.
260
+ * In other words, non-published locales will be returned only when
261
+ * `include_fallback=true`.
239
262
  */
240
263
  locale: string;
241
264
  /**
242
- * The 'entry_locale' specified the original entry locale under which the
243
- * entry was published, it may be different from the 'locale'.
265
+ * The 'publish_details.entry_locale' specifies the original entry locale
266
+ * from which the entry was published, and it may be different from the
267
+ * 'publish_details.locale' if the entry was localized after it was published.
268
+ *
269
+ * It also specifies the entry's locale the version field relates to.
244
270
  *
245
- * For example, if an entry with locale "A" has been published to locale "B",
246
- * for which it isn't localized. Then the 'locale' will be locale "B", while
247
- * the entry's own locale will remain "A" (because it is not localized),
248
- * even when entries are fetched with locale=B filter.
249
- * But, once the entry will be localized to locale "B", the 'entry_locale'
250
- * will be set to locale "A", and the 'locale' will be set to locale "B"
251
- * matching the entry's own locale.
271
+ * For example, if an entry with locale "en-us" has been published to "fr-fr"
272
+ * locale without having a localized entry for "fr-fr". Then, when the entry
273
+ * is fetched with the locale=fr-fr filter, the `publish_details.locale`
274
+ * will be set to "fr-fr", but the entry's locale will remain "en-us" because
275
+ * it was not localized, and the `publish_details.entry_locale` will be undefined.
276
+ * Then, if the entry will be localized to "fr-fr" locale, the locale of
277
+ * the entry will be changed to "fr-fr", the `publish_details.locale` will
278
+ * remain "fr-fr" and the `publish_details.entry_locale` will be set to
279
+ * "en-us" specifying that the published entry's locale doesn't match the
280
+ * current's entry locale. Only after the localized "fr-fr" entry will be
281
+ * published to "fr-fr", then the `publish_details.entry_locale` will be set
282
+ * back to undefined.
252
283
  */
253
284
  entry_locale?: string;
254
285
  };