@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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/content-store.d.ts +3 -2
- package/dist/content-store.d.ts.map +1 -1
- package/dist/content-store.js +16 -10
- package/dist/content-store.js.map +1 -1
- package/dist/types/content-store-types.d.ts +1 -0
- package/dist/types/content-store-types.d.ts.map +1 -1
- package/dist/types/custom-actions.d.ts +104 -20
- package/dist/types/custom-actions.d.ts.map +1 -1
- package/dist/utils/create-update-csi-docs.d.ts +6 -6
- package/dist/utils/create-update-csi-docs.d.ts.map +1 -1
- package/dist/utils/create-update-csi-docs.js +7 -14
- package/dist/utils/create-update-csi-docs.js.map +1 -1
- package/dist/utils/custom-actions.d.ts +13 -10
- package/dist/utils/custom-actions.d.ts.map +1 -1
- package/dist/utils/custom-actions.js +530 -339
- package/dist/utils/custom-actions.js.map +1 -1
- package/dist/utils/document-hooks.d.ts.map +1 -1
- package/dist/utils/document-hooks.js +18 -0
- package/dist/utils/document-hooks.js.map +1 -1
- package/dist/utils/field-path-utils.d.ts.map +1 -1
- package/dist/utils/field-path-utils.js +1 -1
- package/dist/utils/field-path-utils.js.map +1 -1
- package/dist/utils/model-utils.d.ts.map +1 -1
- package/dist/utils/model-utils.js +7 -3
- package/dist/utils/model-utils.js.map +1 -1
- package/package.json +5 -5
- package/src/content-store.ts +21 -12
- package/src/types/content-store-types.ts +1 -0
- package/src/types/custom-actions.ts +123 -20
- package/src/utils/create-update-csi-docs.ts +7 -15
- package/src/utils/custom-actions.ts +658 -403
- package/src/utils/document-hooks.ts +18 -0
- package/src/utils/field-path-utils.ts +3 -1
- package/src/utils/model-utils.ts +9 -5
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CustomActionGlobal,
|
|
3
3
|
CustomActionBulk,
|
|
4
|
+
CustomActionModel,
|
|
4
5
|
CustomActionDocument,
|
|
6
|
+
CustomActionModelObject,
|
|
5
7
|
CustomActionObjectModel,
|
|
6
8
|
CustomActionObjectField,
|
|
7
9
|
CustomActionField,
|
|
@@ -9,63 +11,121 @@ import {
|
|
|
9
11
|
CustomActionInputField,
|
|
10
12
|
CustomActionPermissions
|
|
11
13
|
} from '@stackbit/types';
|
|
14
|
+
import * as StackbitTypes from '@stackbit/types';
|
|
12
15
|
import { User } from './index';
|
|
13
16
|
|
|
17
|
+
export type CustomActionStateWithFinished = CustomActionState | 'finished' | 'failed';
|
|
18
|
+
|
|
14
19
|
export type CustomActionRunStateMap = Record<string, CustomActionRunState>;
|
|
15
20
|
export type CustomActionRunState = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
isRunning?: boolean;
|
|
22
|
+
userId?: string;
|
|
23
|
+
/**
|
|
24
|
+
* An object specifying the model the running action belong to.
|
|
25
|
+
* This property is only applicable for actions of type 'modelGlobal' as
|
|
26
|
+
* these actions are not defined inside a model but inside stackbit config.
|
|
27
|
+
**/
|
|
28
|
+
modelSpec?: APICustomActionModelSpecifier;
|
|
20
29
|
};
|
|
21
30
|
|
|
22
31
|
export type ExtendedCustomAction =
|
|
23
32
|
| ExtendedCustomActionGlobal
|
|
24
33
|
| ExtendedCustomActionBulk
|
|
34
|
+
| ExtendedCustomActionModelGlobal
|
|
35
|
+
| ExtendedCustomActionModel
|
|
25
36
|
| ExtendedCustomActionDocument
|
|
37
|
+
| ExtendedCustomActionModelObject
|
|
26
38
|
| ExtendedCustomActionObjectModel
|
|
27
39
|
| ExtendedCustomActionObjectField
|
|
28
40
|
| ExtendedCustomActionField;
|
|
29
41
|
|
|
30
|
-
export type ExtendedCustomActionGlobal = CustomActionGlobal & ContentStoreCustomActionCommonProps;
|
|
31
|
-
export type ExtendedCustomActionBulk = CustomActionBulk & ContentStoreCustomActionCommonProps;
|
|
42
|
+
export type ExtendedCustomActionGlobal = CustomActionGlobal & ContentStoreCustomActionCommonProps & { extendedType: 'global' };
|
|
43
|
+
export type ExtendedCustomActionBulk = CustomActionBulk & ContentStoreCustomActionCommonProps & { extendedType: 'bulk' };
|
|
44
|
+
export type ExtendedCustomActionModelGlobal = CustomActionModel &
|
|
45
|
+
ContentStoreCustomActionCommonProps & {
|
|
46
|
+
extendedType: 'modelGlobal';
|
|
47
|
+
modelSpec?: APICustomActionModelSpecifier;
|
|
48
|
+
};
|
|
49
|
+
export type ExtendedCustomActionModel = CustomActionModel &
|
|
50
|
+
ContentStoreCustomActionCommonProps & {
|
|
51
|
+
extendedType: 'model';
|
|
52
|
+
modelSpec: APICustomActionModelSpecifier;
|
|
53
|
+
};
|
|
32
54
|
export type ExtendedCustomActionDocument = CustomActionDocument &
|
|
33
55
|
ContentStoreCustomActionCommonProps & {
|
|
34
56
|
type: 'document';
|
|
35
|
-
|
|
57
|
+
extendedType: 'document';
|
|
58
|
+
documentWithSource: StackbitTypes.DocumentWithSource;
|
|
59
|
+
modelWithSource: StackbitTypes.ModelWithSource;
|
|
36
60
|
};
|
|
37
|
-
export type
|
|
61
|
+
export type ExtendedCustomActionModelObject = CustomActionModelObject &
|
|
38
62
|
ContentStoreCustomActionCommonProps & {
|
|
39
|
-
|
|
40
|
-
|
|
63
|
+
extendedType: 'modelObject';
|
|
64
|
+
documentWithSource: StackbitTypes.DocumentWithSource;
|
|
65
|
+
modelWithSource: StackbitTypes.ModelWithSource;
|
|
66
|
+
modelField: StackbitTypes.FieldModel;
|
|
67
|
+
objectModel: StackbitTypes.ModelWithSource<StackbitTypes.ObjectModel>;
|
|
41
68
|
fieldPath: (string | number)[];
|
|
69
|
+
// objectModel: ModelWithSource<ObjectModel>;
|
|
42
70
|
};
|
|
43
|
-
export type
|
|
71
|
+
export type ExtendedCustomActionObjectModel = CustomActionObjectModel &
|
|
44
72
|
ContentStoreCustomActionCommonProps & {
|
|
45
|
-
type: '
|
|
46
|
-
|
|
73
|
+
type: 'object';
|
|
74
|
+
extendedType: 'objectModel';
|
|
75
|
+
documentWithSource: StackbitTypes.DocumentWithSource;
|
|
76
|
+
modelWithSource: StackbitTypes.ModelWithSource;
|
|
77
|
+
documentField: StackbitTypes.DocumentModelFieldNonLocalized;
|
|
78
|
+
modelField: StackbitTypes.FieldModel;
|
|
79
|
+
objectModel: StackbitTypes.ModelWithSource<StackbitTypes.ObjectModel>;
|
|
80
|
+
fieldPath: (string | number)[];
|
|
81
|
+
};
|
|
82
|
+
export type ExtendedCustomActionObjectField = CustomActionObjectField &
|
|
83
|
+
ContentStoreCustomActionCommonProps & {
|
|
84
|
+
extendedType: 'objectField';
|
|
85
|
+
documentWithSource: StackbitTypes.DocumentWithSource;
|
|
86
|
+
modelWithSource: StackbitTypes.ModelWithSource;
|
|
87
|
+
documentField: StackbitTypes.DocumentObjectFieldNonLocalized;
|
|
88
|
+
modelField: StackbitTypes.FieldObject;
|
|
47
89
|
fieldPath: (string | number)[];
|
|
48
90
|
};
|
|
49
91
|
export type ExtendedCustomActionField = CustomActionField &
|
|
50
92
|
ContentStoreCustomActionCommonProps & {
|
|
51
93
|
type: 'field';
|
|
52
|
-
|
|
94
|
+
extendedType: 'field';
|
|
95
|
+
documentWithSource: StackbitTypes.DocumentWithSource;
|
|
96
|
+
modelWithSource: StackbitTypes.ModelWithSource;
|
|
97
|
+
documentField: StackbitTypes.DocumentField | undefined;
|
|
98
|
+
modelField: StackbitTypes.Field;
|
|
53
99
|
fieldPath: (string | number)[];
|
|
54
100
|
};
|
|
55
101
|
export type ContentStoreCustomActionCommonProps = {
|
|
56
102
|
type: string;
|
|
103
|
+
extendedType: string;
|
|
104
|
+
/**
|
|
105
|
+
* The unique id of the action definition.
|
|
106
|
+
* All actions, except actions of type 'model', can not run in parallel.
|
|
107
|
+
* Actions of type 'model' can run in parallel and can be triggered by the
|
|
108
|
+
* same user or by different users. The `actionId` of these executions will
|
|
109
|
+
* be different that the ID of the action that was originally triggered.
|
|
110
|
+
**/
|
|
57
111
|
actionId: string;
|
|
112
|
+
/** The id of the user who executed the action */
|
|
113
|
+
userId?: string;
|
|
58
114
|
// override optional label to required one
|
|
59
115
|
label: string;
|
|
60
116
|
// specifies if the action is current running in this container instance
|
|
61
|
-
|
|
62
|
-
// the action state returned by the recent 'run' invocation
|
|
63
|
-
lastResultState?: CustomActionState;
|
|
117
|
+
isRunning?: boolean;
|
|
64
118
|
};
|
|
65
119
|
|
|
66
|
-
export type CustomActionType = 'global' | 'bulk' | 'document' | 'object' | 'field';
|
|
120
|
+
export type CustomActionType = 'global' | 'bulk' | 'model' | 'document' | 'object' | 'field';
|
|
67
121
|
|
|
68
|
-
export type APICustomAction =
|
|
122
|
+
export type APICustomAction =
|
|
123
|
+
| APICustomActionGlobal
|
|
124
|
+
| APICustomActionBulk
|
|
125
|
+
| APICustomActionModel
|
|
126
|
+
| APICustomActionDocument
|
|
127
|
+
| APICustomActionObject
|
|
128
|
+
| APICustomActionField;
|
|
69
129
|
|
|
70
130
|
export interface APICustomActionGlobal extends APICustomActionCommonProps {
|
|
71
131
|
type: 'global';
|
|
@@ -75,6 +135,11 @@ export interface APICustomActionBulk extends APICustomActionCommonProps {
|
|
|
75
135
|
type: 'bulk';
|
|
76
136
|
}
|
|
77
137
|
|
|
138
|
+
export interface APICustomActionModel extends APICustomActionCommonProps {
|
|
139
|
+
type: 'model';
|
|
140
|
+
models?: string[];
|
|
141
|
+
}
|
|
142
|
+
|
|
78
143
|
export interface APICustomActionDocument extends APICustomActionCommonProps {
|
|
79
144
|
type: 'document';
|
|
80
145
|
}
|
|
@@ -94,14 +159,20 @@ export interface APICustomActionCommonProps {
|
|
|
94
159
|
icon?: string;
|
|
95
160
|
inputFields?: CustomActionInputField[];
|
|
96
161
|
actionId: string;
|
|
162
|
+
/** The userId is set when the action is in 'running' state */
|
|
163
|
+
userId?: string;
|
|
97
164
|
state: CustomActionState;
|
|
98
165
|
hidden?: boolean;
|
|
99
166
|
permissions?: CustomActionPermissions;
|
|
100
167
|
}
|
|
101
168
|
|
|
169
|
+
export type APIRunCustomActionResponse = { actionId: string };
|
|
170
|
+
|
|
102
171
|
export type APIRunCustomActionRequest =
|
|
103
172
|
| APIRunCustomActionRequestGlobal
|
|
104
173
|
| APIRunCustomActionRequestBulk
|
|
174
|
+
| APIRunCustomActionRequestModelGlobal
|
|
175
|
+
| APIRunCustomActionRequestModel
|
|
105
176
|
| APIRunCustomActionRequestDocument
|
|
106
177
|
| APIRunCustomActionRequestObject
|
|
107
178
|
| APIRunCustomActionRequestField;
|
|
@@ -115,6 +186,21 @@ export interface APIRunCustomActionRequestBulk extends APIRunCustomActionRequest
|
|
|
115
186
|
documents: APICustomActionDocumentSpecifier[];
|
|
116
187
|
}
|
|
117
188
|
|
|
189
|
+
export interface APIRunCustomActionRequestModelGlobal extends APIRunCustomActionRequestCommonParams {
|
|
190
|
+
actionType: 'model';
|
|
191
|
+
srcType: string;
|
|
192
|
+
srcProjectId: string;
|
|
193
|
+
modelName: string;
|
|
194
|
+
location: 'new-card' | 'preset-card';
|
|
195
|
+
presetId?: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface APIRunCustomActionRequestModel extends APIRunCustomActionRequestCommonParams {
|
|
199
|
+
actionType: 'model';
|
|
200
|
+
location: 'new-card' | 'preset-card';
|
|
201
|
+
presetId?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
118
204
|
export interface APIRunCustomActionRequestDocument extends APIRunCustomActionRequestCommonParams {
|
|
119
205
|
actionType: 'document';
|
|
120
206
|
}
|
|
@@ -146,6 +232,16 @@ export interface APIGetCustomActionRequest {
|
|
|
146
232
|
currentPageDocument?: APICustomActionDocumentSpecifier; // the document id of the current page
|
|
147
233
|
}
|
|
148
234
|
|
|
235
|
+
export interface APIGetRunningCustomActionsRequest {
|
|
236
|
+
user: User;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface APICustomActionModelSpecifier {
|
|
240
|
+
srcType: string;
|
|
241
|
+
srcProjectId: string;
|
|
242
|
+
modelName: string;
|
|
243
|
+
}
|
|
244
|
+
|
|
149
245
|
export interface APICustomActionDocumentSpecifier {
|
|
150
246
|
srcType: string;
|
|
151
247
|
srcProjectId: string;
|
|
@@ -156,7 +252,14 @@ export interface CustomActionStateChange {
|
|
|
156
252
|
actionType: CustomActionType;
|
|
157
253
|
actionId: string;
|
|
158
254
|
actionName: string;
|
|
159
|
-
state:
|
|
255
|
+
state: CustomActionStateWithFinished;
|
|
256
|
+
userId?: string;
|
|
257
|
+
// While the action is running, the 'message' may change multiple times
|
|
258
|
+
// with user-facing messages to provide information about the progress of the action.
|
|
259
|
+
message?: string;
|
|
260
|
+
// While the action is running, the 'percent' may update with numerical value
|
|
261
|
+
// between 0 and 100 to provide information about the progress of the action.
|
|
262
|
+
percent?: number;
|
|
160
263
|
success?: string;
|
|
161
264
|
error?: string;
|
|
162
265
|
result?: unknown;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
-
import slugify from 'slugify';
|
|
3
2
|
|
|
4
3
|
import { Config, Model as SDKModel } from '@stackbit/sdk';
|
|
5
4
|
import {
|
|
@@ -87,13 +86,13 @@ export function getCreateDocumentThunk({
|
|
|
87
86
|
/**
|
|
88
87
|
* Receives a plain `object`, and creates a map of `CSITypes.UpdateOperationField`
|
|
89
88
|
* by recursively iterating the `object` fields. Then invokes the `createDocument`
|
|
90
|
-
* callback to delegate the creation
|
|
89
|
+
* callback to delegate the creation of the document to a CSI module.
|
|
91
90
|
*
|
|
92
|
-
* If the `object` has fields of type `reference` or `model`
|
|
93
|
-
* `$$type` property holding the model name of the nested object,
|
|
94
|
-
* will recursively create new documents and nested objects for
|
|
95
|
-
* Other fields
|
|
96
|
-
* nested object.
|
|
91
|
+
* If the `object` has fields of type `reference`, `cross-reference` or `model`
|
|
92
|
+
* with the special `$$type` property holding the model name of the nested object,
|
|
93
|
+
* this function will recursively create new documents and nested objects for
|
|
94
|
+
* these fields. Other fields within the object will be used to populate the
|
|
95
|
+
* fields of the new document or nested object.
|
|
97
96
|
*
|
|
98
97
|
* @example
|
|
99
98
|
* {
|
|
@@ -181,13 +180,6 @@ export async function createDocumentRecursively({
|
|
|
181
180
|
};
|
|
182
181
|
}
|
|
183
182
|
|
|
184
|
-
function sanitizeSlug(slug?: string) {
|
|
185
|
-
return slug
|
|
186
|
-
?.split('/')
|
|
187
|
-
.map((part) => slugify(part, { lower: true }))
|
|
188
|
-
.join('/');
|
|
189
|
-
}
|
|
190
|
-
|
|
191
183
|
async function createObjectRecursively({
|
|
192
184
|
object,
|
|
193
185
|
modelFields,
|
|
@@ -339,7 +331,7 @@ async function createObjectRecursively({
|
|
|
339
331
|
* { type: 'text', name: 'content' }
|
|
340
332
|
* ]
|
|
341
333
|
* }
|
|
342
|
-
* )
|
|
334
|
+
* })
|
|
343
335
|
* // The generated UpdateOperationField will use the original csiModelField types:
|
|
344
336
|
* {
|
|
345
337
|
* field: {
|