@stackbit/cms-core 3.0.7 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/content-store.d.ts +3 -2
  3. package/dist/content-store.d.ts.map +1 -1
  4. package/dist/content-store.js +16 -10
  5. package/dist/content-store.js.map +1 -1
  6. package/dist/types/content-store-types.d.ts +1 -0
  7. package/dist/types/content-store-types.d.ts.map +1 -1
  8. package/dist/types/custom-actions.d.ts +104 -20
  9. package/dist/types/custom-actions.d.ts.map +1 -1
  10. package/dist/utils/create-update-csi-docs.d.ts +6 -6
  11. package/dist/utils/create-update-csi-docs.d.ts.map +1 -1
  12. package/dist/utils/create-update-csi-docs.js +7 -14
  13. package/dist/utils/create-update-csi-docs.js.map +1 -1
  14. package/dist/utils/custom-actions.d.ts +13 -10
  15. package/dist/utils/custom-actions.d.ts.map +1 -1
  16. package/dist/utils/custom-actions.js +530 -339
  17. package/dist/utils/custom-actions.js.map +1 -1
  18. package/dist/utils/document-hooks.d.ts.map +1 -1
  19. package/dist/utils/document-hooks.js +18 -0
  20. package/dist/utils/document-hooks.js.map +1 -1
  21. package/dist/utils/field-path-utils.d.ts.map +1 -1
  22. package/dist/utils/field-path-utils.js +1 -1
  23. package/dist/utils/field-path-utils.js.map +1 -1
  24. package/dist/utils/model-utils.d.ts.map +1 -1
  25. package/dist/utils/model-utils.js +7 -3
  26. package/dist/utils/model-utils.js.map +1 -1
  27. package/package.json +5 -5
  28. package/src/content-store.ts +21 -12
  29. package/src/types/content-store-types.ts +1 -0
  30. package/src/types/custom-actions.ts +123 -20
  31. package/src/utils/create-update-csi-docs.ts +7 -15
  32. package/src/utils/custom-actions.ts +658 -403
  33. package/src/utils/document-hooks.ts +18 -0
  34. package/src/utils/field-path-utils.ts +3 -1
  35. package/src/utils/model-utils.ts +9 -5
@@ -7,6 +7,7 @@ import type { ContentSourceData } from '../types';
7
7
  import type { BackCompatContentSourceInterface } from './backward-compatibility';
8
8
  import { getUserContextForSrcType, findContentSourcesDataForTypeOrId, getUserContextForSrcTypeThunk } from '../content-store-utils';
9
9
  import { createConfigDelegate } from './config-delegate';
10
+ import { createDocumentRecursively, getCreateDocumentThunk } from './create-update-csi-docs';
10
11
 
11
12
  export interface DocumentHookBaseOptions {
12
13
  stackbitConfig: Config | null;
@@ -314,6 +315,23 @@ function getContentSourceActionsForContentSourceData({
314
315
  logger
315
316
  });
316
317
  },
318
+ createDocumentFromObject: async (options: Parameters<StackbitTypes.ContentSourceActions['createDocumentFromObject']>[0]) => {
319
+ return createDocumentRecursively({
320
+ object: options.object,
321
+ locale: options.locale,
322
+ modelName: options.modelName,
323
+ contentSourceId: contentSourceData.id,
324
+ contentSourceDataById: getContentSourceDataById(),
325
+ assetSources: stackbitConfig?.assetSources ?? [],
326
+ userLogger: logger,
327
+ createDocument: getCreateDocumentThunk({
328
+ stackbitConfig,
329
+ getContentSourceDataById,
330
+ logger,
331
+ user
332
+ })
333
+ });
334
+ },
317
335
  updateDocument: (options: Parameters<StackbitTypes.ContentSourceInterface['updateDocument']>[0]) => {
318
336
  return updateDocumentHooked({
319
337
  actionOptions: {
@@ -627,7 +627,9 @@ export function getModelAndDocumentFieldForLocalizedFieldPath({
627
627
  // field locale is not set
628
628
  return { modelField, documentField: undefined };
629
629
  }
630
- throw new Error(`fieldPath '${origFieldPath.join('.')}' doesn't specify the locale`);
630
+ throw new Error(
631
+ `document '${docId}' of type '${origModelName}' doesn't have a localized value for locale ${locale} at path '${getPrefixOf(fieldPath)}'`
632
+ );
631
633
  }
632
634
  docField = localizedDocField;
633
635
  }
@@ -52,16 +52,19 @@ export function normalizeModels({ models, logger }: { models: ModelWithSource[];
52
52
 
53
53
  assignLabelFieldIfNeeded(model);
54
54
 
55
+ // Ensure that actions always have types and labels
55
56
  if ((model.type === 'data' || model.type === 'page') && model.actions) {
56
57
  model.actions = model.actions.map((action) => ({
57
58
  ...action,
58
- type: 'document'
59
- }));
59
+ type: action.type ?? 'document',
60
+ label: action.label ?? _.startCase(action.name)
61
+ })) as (StackbitTypes.CustomActionDocument | StackbitTypes.CustomActionModel)[];
60
62
  } else if (model.type === 'object' && model.actions) {
61
63
  model.actions = model.actions.map((action) => ({
62
64
  ...action,
63
- type: 'object'
64
- }));
65
+ type: action.type ?? 'object',
66
+ label: action.label ?? _.startCase(action.name)
67
+ })) as (StackbitTypes.CustomActionObjectModel | StackbitTypes.CustomActionModelObject)[];
65
68
  }
66
69
 
67
70
  model = mapModelFieldsRecursively(model, (field) => {
@@ -74,7 +77,8 @@ export function normalizeModels({ models, logger }: { models: ModelWithSource[];
74
77
  if (field.actions) {
75
78
  field.actions = field.actions.map((action) => ({
76
79
  ...action,
77
- type: action.type ?? 'field'
80
+ type: action.type ?? 'field',
81
+ label: action.label ?? _.startCase(action.name)
78
82
  })) as (CustomActionField | CustomActionObjectField)[];
79
83
  }
80
84