@stackbit/cms-core 0.8.4-develop.1 → 0.8.4-develop.3
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-utils.d.ts.map +1 -1
- package/dist/content-store-utils.js +44 -48
- 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 +14 -7
- package/dist/content-store.js.map +1 -1
- package/dist/types/custom-actions.d.ts +12 -8
- package/dist/types/custom-actions.d.ts.map +1 -1
- package/dist/utils/csi-to-store-docs-converter.d.ts +14 -11
- package/dist/utils/csi-to-store-docs-converter.d.ts.map +1 -1
- package/dist/utils/csi-to-store-docs-converter.js +21 -92
- package/dist/utils/csi-to-store-docs-converter.js.map +1 -1
- package/dist/utils/custom-actions.d.ts +39 -24
- package/dist/utils/custom-actions.d.ts.map +1 -1
- package/dist/utils/custom-actions.js +417 -231
- package/dist/utils/custom-actions.js.map +1 -1
- package/dist/utils/store-to-api-docs-converter.d.ts.map +1 -1
- package/dist/utils/store-to-api-docs-converter.js +40 -3
- package/dist/utils/store-to-api-docs-converter.js.map +1 -1
- package/package.json +4 -4
- package/src/content-store-utils.ts +79 -51
- package/src/content-store.ts +15 -8
- package/src/types/custom-actions.ts +22 -16
- package/src/utils/csi-to-store-docs-converter.ts +89 -227
- package/src/utils/custom-actions.ts +514 -263
- package/src/utils/store-to-api-docs-converter.ts +40 -3
|
@@ -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.runCustomAction = exports.resolveCustomActionsById = exports.
|
|
6
|
+
exports.runCustomAction = exports.resolveCustomActionsById = exports.getFieldActions = exports.getObjectFieldActionsThunk = exports.getObjectModelActionsThunk = exports.getDocumentActionsThunk = exports.getGlobalAndBulkAPIActions = exports.stripModelActions = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const sdk_1 = require("@stackbit/sdk");
|
|
9
9
|
const utils_1 = require("@stackbit/utils");
|
|
@@ -33,7 +33,7 @@ function stripModelActions({ modelMap }) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
exports.stripModelActions = stripModelActions;
|
|
36
|
-
async function getGlobalAndBulkAPIActions({ stackbitConfig,
|
|
36
|
+
async function getGlobalAndBulkAPIActions({ stackbitConfig, customActionRunStateMap, contentSourceDataById, userLogger, pageUrl, user, locale, currentPageDocument }) {
|
|
37
37
|
if (!stackbitConfig || !Array.isArray(stackbitConfig.actions)) {
|
|
38
38
|
return [];
|
|
39
39
|
}
|
|
@@ -43,24 +43,15 @@ async function getGlobalAndBulkAPIActions({ stackbitConfig, customActionMap, con
|
|
|
43
43
|
});
|
|
44
44
|
return (0, utils_1.mapPromise)(stackbitConfig.actions, async (action) => {
|
|
45
45
|
var _a, _b;
|
|
46
|
-
const actionId =
|
|
47
|
-
const
|
|
48
|
-
const storeAction = {
|
|
49
|
-
// if configuration is updated, the new action properties will override the stored action properties
|
|
50
|
-
...action,
|
|
51
|
-
actionId,
|
|
52
|
-
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
53
|
-
runningHandler: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.runningHandler,
|
|
54
|
-
lastResultState: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.lastResultState
|
|
55
|
-
};
|
|
56
|
-
customActionMap[actionId] = storeAction;
|
|
46
|
+
const actionId = globalActionId(action);
|
|
47
|
+
const actionRunState = customActionRunStateMap[actionId];
|
|
57
48
|
let state;
|
|
58
|
-
if (
|
|
49
|
+
if (actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.runningHandler) {
|
|
59
50
|
state = 'running';
|
|
60
51
|
}
|
|
61
|
-
else if (
|
|
52
|
+
else if (action.state) {
|
|
62
53
|
const pageDocument = getCSIDocumentWithSourceFromDocumentSpec(currentPageDocument, configDelegate);
|
|
63
|
-
state = await
|
|
54
|
+
state = await action.state({
|
|
64
55
|
actionId: actionId,
|
|
65
56
|
currentLocale: locale,
|
|
66
57
|
currentUser: user ? { name: user.name, email: user.email } : undefined,
|
|
@@ -70,152 +61,158 @@ async function getGlobalAndBulkAPIActions({ stackbitConfig, customActionMap, con
|
|
|
70
61
|
});
|
|
71
62
|
}
|
|
72
63
|
else {
|
|
73
|
-
state = (
|
|
64
|
+
state = (_a = actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.lastResultState) !== null && _a !== void 0 ? _a : 'enabled';
|
|
74
65
|
}
|
|
75
66
|
return (0, utils_1.omitByNil)({
|
|
67
|
+
type: action.type,
|
|
76
68
|
actionId: actionId,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
icon: storeAction.icon,
|
|
69
|
+
name: action.name,
|
|
70
|
+
label: (_b = action.label) !== null && _b !== void 0 ? _b : lodash_1.default.startCase(action.name),
|
|
71
|
+
icon: action.icon,
|
|
81
72
|
state: state,
|
|
82
|
-
inputFields:
|
|
73
|
+
inputFields: action.inputFields
|
|
83
74
|
});
|
|
84
75
|
});
|
|
85
76
|
}
|
|
86
77
|
exports.getGlobalAndBulkAPIActions = getGlobalAndBulkAPIActions;
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const prevStoreAction = customActionMap[actionId];
|
|
91
|
-
const storeAction = {
|
|
92
|
-
// if configuration is updated, the new action properties will override the stored action properties
|
|
93
|
-
...action,
|
|
94
|
-
type: 'document',
|
|
95
|
-
actionId,
|
|
96
|
-
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
97
|
-
runningHandler: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.runningHandler,
|
|
98
|
-
lastResultState: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.lastResultState,
|
|
99
|
-
documentSpec: {
|
|
100
|
-
srcType: csiDocument.srcType,
|
|
101
|
-
srcProjectId: csiDocument.srcProjectId,
|
|
102
|
-
srcDocumentId: csiDocument.id
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
customActionMap[actionId] = storeAction;
|
|
106
|
-
let state;
|
|
107
|
-
let needsResolving = false;
|
|
108
|
-
if (storeAction === null || storeAction === void 0 ? void 0 : storeAction.runningHandler) {
|
|
109
|
-
state = 'running';
|
|
78
|
+
function getDocumentActionsThunk({ csiDocument, model, srcType, srcProjectId, customActionRunStateMap }) {
|
|
79
|
+
if (!('actions' in model) || !Array.isArray(model.actions)) {
|
|
80
|
+
return () => undefined;
|
|
110
81
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
82
|
+
const extendedDocumentActions = model.actions.map((action) => {
|
|
83
|
+
var _a;
|
|
84
|
+
const documentSpec = {
|
|
85
|
+
srcType: srcType,
|
|
86
|
+
srcProjectId: srcProjectId,
|
|
87
|
+
srcDocumentId: csiDocument.id
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
91
|
+
...action,
|
|
92
|
+
type: 'document',
|
|
93
|
+
actionId: documentActionId({ ...documentSpec, actionName: action.name }),
|
|
94
|
+
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
95
|
+
documentSpec: documentSpec
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
return () => extendedDocumentActions.map((extendedAction) => {
|
|
99
|
+
return (0, utils_1.omitByNil)({
|
|
100
|
+
type: 'document',
|
|
101
|
+
actionId: extendedAction.actionId,
|
|
102
|
+
name: extendedAction.name,
|
|
103
|
+
label: extendedAction.label,
|
|
104
|
+
icon: extendedAction.icon,
|
|
105
|
+
inputFields: extendedAction.inputFields,
|
|
106
|
+
...getAPIActionState(extendedAction, customActionRunStateMap)
|
|
107
|
+
});
|
|
127
108
|
});
|
|
128
109
|
}
|
|
129
|
-
exports.
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const prevStoreAction = customActionMap[actionId];
|
|
134
|
-
const storeAction = {
|
|
135
|
-
// if configuration is updated, the new action properties will override the stored action properties
|
|
136
|
-
...action,
|
|
137
|
-
type: 'objectModel',
|
|
138
|
-
actionId,
|
|
139
|
-
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
140
|
-
runningHandler: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.runningHandler,
|
|
141
|
-
lastResultState: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.lastResultState,
|
|
142
|
-
documentSpec: {
|
|
143
|
-
srcType: csiParentDocument.srcType,
|
|
144
|
-
srcProjectId: csiParentDocument.srcProjectId,
|
|
145
|
-
srcDocumentId: csiParentDocument.id
|
|
146
|
-
},
|
|
147
|
-
fieldPath
|
|
148
|
-
};
|
|
149
|
-
customActionMap[actionId] = storeAction;
|
|
150
|
-
let state;
|
|
151
|
-
let needsResolving = false;
|
|
152
|
-
if (storeAction === null || storeAction === void 0 ? void 0 : storeAction.runningHandler) {
|
|
153
|
-
state = 'running';
|
|
154
|
-
}
|
|
155
|
-
else if (action.state) {
|
|
156
|
-
state = 'unknown';
|
|
157
|
-
needsResolving = true;
|
|
110
|
+
exports.getDocumentActionsThunk = getDocumentActionsThunk;
|
|
111
|
+
function getObjectModelActionsThunk({ model, csiParentDocument, srcType, srcProjectId, customActionRunStateMap, fieldPath }) {
|
|
112
|
+
if (!('actions' in model) || !Array.isArray(model.actions)) {
|
|
113
|
+
return () => undefined;
|
|
158
114
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
115
|
+
const extendedObjectModelActions = model.actions.map((action) => {
|
|
116
|
+
var _a;
|
|
117
|
+
const documentSpec = {
|
|
118
|
+
srcType: srcType,
|
|
119
|
+
srcProjectId: srcProjectId,
|
|
120
|
+
srcDocumentId: csiParentDocument.id
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
124
|
+
...action,
|
|
125
|
+
type: 'objectModel',
|
|
126
|
+
actionId: fieldPathActionId({ ...documentSpec, fieldPath, actionName: action.name }),
|
|
127
|
+
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
128
|
+
documentSpec: documentSpec,
|
|
129
|
+
fieldPath
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
return () => extendedObjectModelActions.map((extendedAction) => {
|
|
133
|
+
return (0, utils_1.omitByNil)({
|
|
134
|
+
type: 'object',
|
|
135
|
+
actionId: extendedAction.actionId,
|
|
136
|
+
name: extendedAction.name,
|
|
137
|
+
label: extendedAction.label,
|
|
138
|
+
icon: extendedAction.icon,
|
|
139
|
+
inputFields: extendedAction.inputFields,
|
|
140
|
+
...getAPIActionState(extendedAction, customActionRunStateMap)
|
|
141
|
+
});
|
|
171
142
|
});
|
|
172
143
|
}
|
|
173
|
-
exports.
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const prevStoreAction = customActionMap[actionId];
|
|
178
|
-
const storeAction = {
|
|
179
|
-
// if configuration is updated, the new action properties will override the stored action properties
|
|
180
|
-
...action,
|
|
181
|
-
type: action.type === 'object' ? 'objectField' : 'field',
|
|
182
|
-
actionId,
|
|
183
|
-
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
184
|
-
runningHandler: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.runningHandler,
|
|
185
|
-
lastResultState: prevStoreAction === null || prevStoreAction === void 0 ? void 0 : prevStoreAction.lastResultState,
|
|
186
|
-
documentSpec: {
|
|
187
|
-
srcType: csiParentDocument.srcType,
|
|
188
|
-
srcProjectId: csiParentDocument.srcProjectId,
|
|
189
|
-
srcDocumentId: csiParentDocument.id
|
|
190
|
-
},
|
|
191
|
-
fieldPath
|
|
192
|
-
};
|
|
193
|
-
customActionMap[actionId] = storeAction;
|
|
194
|
-
let state;
|
|
195
|
-
let needsResolving = false;
|
|
196
|
-
if (storeAction === null || storeAction === void 0 ? void 0 : storeAction.runningHandler) {
|
|
197
|
-
state = 'running';
|
|
198
|
-
}
|
|
199
|
-
else if (action.state) {
|
|
200
|
-
state = 'unknown';
|
|
201
|
-
needsResolving = true;
|
|
144
|
+
exports.getObjectModelActionsThunk = getObjectModelActionsThunk;
|
|
145
|
+
function getObjectFieldActionsThunk({ modelField, csiParentDocument, srcType, srcProjectId, customActionRunStateMap, fieldPath }) {
|
|
146
|
+
if (!('actions' in modelField) || !Array.isArray(modelField.actions)) {
|
|
147
|
+
return () => undefined;
|
|
202
148
|
}
|
|
203
|
-
|
|
204
|
-
|
|
149
|
+
const objectFieldActions = modelField.actions.filter((action) => action.type === 'object');
|
|
150
|
+
const extendedObjectFieldActions = objectFieldActions.map((action) => {
|
|
151
|
+
var _a;
|
|
152
|
+
const documentSpec = {
|
|
153
|
+
srcType: srcType,
|
|
154
|
+
srcProjectId: srcProjectId,
|
|
155
|
+
srcDocumentId: csiParentDocument.id
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
159
|
+
...action,
|
|
160
|
+
type: 'objectField',
|
|
161
|
+
actionId: fieldPathActionId({ ...documentSpec, fieldPath, actionName: action.name }),
|
|
162
|
+
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
163
|
+
documentSpec: documentSpec,
|
|
164
|
+
fieldPath
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
return () => extendedObjectFieldActions.map((extendedAction) => {
|
|
168
|
+
return (0, utils_1.omitByNil)({
|
|
169
|
+
type: 'object',
|
|
170
|
+
actionId: extendedAction.actionId,
|
|
171
|
+
name: extendedAction.name,
|
|
172
|
+
label: extendedAction.label,
|
|
173
|
+
icon: extendedAction.icon,
|
|
174
|
+
inputFields: extendedAction.inputFields,
|
|
175
|
+
...getAPIActionState(extendedAction, customActionRunStateMap)
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
exports.getObjectFieldActionsThunk = getObjectFieldActionsThunk;
|
|
180
|
+
function getFieldActions({ modelField, csiParentDocument, srcType, srcProjectId, customActionRunStateMap, fieldPath }) {
|
|
181
|
+
if (!('actions' in modelField) || !Array.isArray(modelField.actions)) {
|
|
182
|
+
return undefined;
|
|
205
183
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
184
|
+
const fieldActions = modelField.actions.filter((action) => action.type !== 'object');
|
|
185
|
+
const extendedFieldActions = fieldActions.map((action) => {
|
|
186
|
+
var _a;
|
|
187
|
+
const documentSpec = {
|
|
188
|
+
srcType: srcType,
|
|
189
|
+
srcProjectId: srcProjectId,
|
|
190
|
+
srcDocumentId: csiParentDocument.id
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
194
|
+
...action,
|
|
195
|
+
type: 'field',
|
|
196
|
+
actionId: fieldPathActionId({ ...documentSpec, fieldPath, actionName: action.name }),
|
|
197
|
+
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
198
|
+
documentSpec: documentSpec,
|
|
199
|
+
fieldPath
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
return extendedFieldActions.map((extendedAction) => {
|
|
203
|
+
return (0, utils_1.omitByNil)({
|
|
204
|
+
type: 'field',
|
|
205
|
+
actionId: extendedAction.actionId,
|
|
206
|
+
name: extendedAction.name,
|
|
207
|
+
label: extendedAction.label,
|
|
208
|
+
icon: extendedAction.icon,
|
|
209
|
+
inputFields: extendedAction.inputFields,
|
|
210
|
+
...getAPIActionState(extendedAction, customActionRunStateMap)
|
|
211
|
+
});
|
|
215
212
|
});
|
|
216
213
|
}
|
|
217
|
-
exports.
|
|
218
|
-
async function resolveCustomActionsById({ getActionRequest,
|
|
214
|
+
exports.getFieldActions = getFieldActions;
|
|
215
|
+
async function resolveCustomActionsById({ getActionRequest, customActionRunStateMap, contentSourceDataById, stackbitConfig, userLogger }) {
|
|
219
216
|
var _a;
|
|
220
217
|
const result = [];
|
|
221
218
|
const { customActionIds, locale, user, pageUrl, currentPageDocument } = getActionRequest;
|
|
@@ -224,17 +221,22 @@ async function resolveCustomActionsById({ getActionRequest, customActionMap, con
|
|
|
224
221
|
logger: userLogger
|
|
225
222
|
});
|
|
226
223
|
for (const actionId of customActionIds) {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
224
|
+
const extendedAction = findCustomActionById({
|
|
225
|
+
actionId,
|
|
226
|
+
customActionRunStateMap,
|
|
227
|
+
contentSourceDataById,
|
|
228
|
+
stackbitConfig
|
|
229
|
+
});
|
|
230
|
+
if (!extendedAction) {
|
|
231
|
+
userLogger.debug(`custom action with id: '${actionId}' was not found`);
|
|
230
232
|
continue;
|
|
231
233
|
}
|
|
232
234
|
try {
|
|
233
235
|
let state;
|
|
234
|
-
if (
|
|
236
|
+
if (extendedAction.runningHandler) {
|
|
235
237
|
state = 'running';
|
|
236
238
|
}
|
|
237
|
-
else if (
|
|
239
|
+
else if (extendedAction.state) {
|
|
238
240
|
const pageDocument = getCSIDocumentWithSourceFromDocumentSpec(currentPageDocument, configDelegate);
|
|
239
241
|
const commonStateOptions = {
|
|
240
242
|
actionId: actionId,
|
|
@@ -249,66 +251,66 @@ async function resolveCustomActionsById({ getActionRequest, customActionMap, con
|
|
|
249
251
|
currentPageDocument: pageDocument,
|
|
250
252
|
...configDelegate
|
|
251
253
|
};
|
|
252
|
-
if (
|
|
253
|
-
state = await
|
|
254
|
+
if (extendedAction.type === 'global' || extendedAction.type === 'bulk') {
|
|
255
|
+
state = await extendedAction.state(commonStateOptions);
|
|
254
256
|
}
|
|
255
|
-
else if (
|
|
257
|
+
else if (extendedAction.type === 'document') {
|
|
256
258
|
const { document, model } = getCSIDocumentAndModelWithSourceFromDocumentSpec({
|
|
257
|
-
documentSpec:
|
|
259
|
+
documentSpec: extendedAction.documentSpec,
|
|
258
260
|
contentSourceDataById
|
|
259
261
|
});
|
|
260
|
-
state = await
|
|
262
|
+
state = await extendedAction.state({
|
|
261
263
|
...commonStateOptions,
|
|
262
264
|
document: document,
|
|
263
265
|
model: model
|
|
264
266
|
});
|
|
265
267
|
}
|
|
266
|
-
else if (
|
|
268
|
+
else if (extendedAction.type === 'objectModel') {
|
|
267
269
|
const stateObjectParams = getHandlerParamsForObjectModelAction({
|
|
268
|
-
|
|
270
|
+
extendedAction,
|
|
269
271
|
contentSourceDataById
|
|
270
272
|
});
|
|
271
|
-
state = await
|
|
273
|
+
state = await extendedAction.state({
|
|
272
274
|
...commonStateOptions,
|
|
273
275
|
...stateObjectParams
|
|
274
276
|
});
|
|
275
277
|
}
|
|
276
|
-
else if (
|
|
278
|
+
else if (extendedAction.type === 'objectField') {
|
|
277
279
|
const stateObjectParams = getHandlerParamsForObjectFieldAction({
|
|
278
|
-
|
|
280
|
+
extendedAction,
|
|
279
281
|
contentSourceDataById
|
|
280
282
|
});
|
|
281
|
-
state = await
|
|
283
|
+
state = await extendedAction.state({
|
|
282
284
|
...commonStateOptions,
|
|
283
285
|
...stateObjectParams
|
|
284
286
|
});
|
|
285
287
|
}
|
|
286
|
-
else if (
|
|
288
|
+
else if (extendedAction.type === 'field') {
|
|
287
289
|
const stateFieldParams = getHandlerParamsForFieldAction({
|
|
288
|
-
|
|
290
|
+
extendedAction,
|
|
289
291
|
contentSourceDataById
|
|
290
292
|
});
|
|
291
|
-
state = await
|
|
293
|
+
state = await extendedAction.state({
|
|
292
294
|
...commonStateOptions,
|
|
293
295
|
...stateFieldParams
|
|
294
296
|
});
|
|
295
297
|
}
|
|
296
298
|
else {
|
|
297
|
-
const _exhaustiveCheck =
|
|
299
|
+
const _exhaustiveCheck = extendedAction;
|
|
298
300
|
continue;
|
|
299
301
|
}
|
|
300
302
|
}
|
|
301
303
|
else {
|
|
302
|
-
state = (_a =
|
|
304
|
+
state = (_a = extendedAction.lastResultState) !== null && _a !== void 0 ? _a : 'enabled';
|
|
303
305
|
}
|
|
304
306
|
result.push((0, utils_1.omitByNil)({
|
|
305
307
|
actionId: actionId,
|
|
306
|
-
type: storeActionTypeToAPIActionType(
|
|
307
|
-
name:
|
|
308
|
-
label:
|
|
309
|
-
icon:
|
|
308
|
+
type: storeActionTypeToAPIActionType(extendedAction.type),
|
|
309
|
+
name: extendedAction.name,
|
|
310
|
+
label: extendedAction.label,
|
|
311
|
+
icon: extendedAction.icon,
|
|
310
312
|
state: state,
|
|
311
|
-
inputFields:
|
|
313
|
+
inputFields: extendedAction.inputFields
|
|
312
314
|
}));
|
|
313
315
|
}
|
|
314
316
|
catch (error) {
|
|
@@ -318,24 +320,31 @@ async function resolveCustomActionsById({ getActionRequest, customActionMap, con
|
|
|
318
320
|
return result;
|
|
319
321
|
}
|
|
320
322
|
exports.resolveCustomActionsById = resolveCustomActionsById;
|
|
321
|
-
function runCustomAction({ runActionRequest,
|
|
323
|
+
function runCustomAction({ runActionRequest, customActionRunStateMap, contentSourceDataById, stackbitConfig, userLogger }) {
|
|
322
324
|
var _a, _b;
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
+
const extendedAction = findCustomActionById({
|
|
326
|
+
actionId: runActionRequest.actionId,
|
|
327
|
+
customActionRunStateMap,
|
|
328
|
+
contentSourceDataById,
|
|
329
|
+
stackbitConfig
|
|
330
|
+
});
|
|
331
|
+
if (!extendedAction) {
|
|
325
332
|
throw new Error(`Error running action: action not found, action name: '${runActionRequest.actionName}' action ID: '${runActionRequest.actionId}'.`);
|
|
326
333
|
}
|
|
327
|
-
const prevResultState =
|
|
328
|
-
if (
|
|
334
|
+
const prevResultState = extendedAction.lastResultState;
|
|
335
|
+
if (extendedAction.lastResultState && extendedAction.lastResultState !== 'enabled') {
|
|
329
336
|
throw new Error(`Error running action: action is not enabled, action name: '${runActionRequest.actionName}' action ID: '${runActionRequest.actionId}'.`);
|
|
330
337
|
}
|
|
331
338
|
try {
|
|
332
|
-
const actionLogger = userLogger.createLogger({ label: `action:${
|
|
339
|
+
const actionLogger = userLogger.createLogger({ label: `action:${extendedAction.name}` });
|
|
333
340
|
const configDelegate = (0, config_delegate_1.createConfigDelegate)({ contentSourceDataById: contentSourceDataById, logger: actionLogger });
|
|
334
341
|
const currentPageDocument = getCSIDocumentWithSourceFromDocumentSpec(runActionRequest.currentPageDocument, configDelegate);
|
|
335
|
-
|
|
336
|
-
|
|
342
|
+
customActionRunStateMap[runActionRequest.actionId] = {
|
|
343
|
+
runningHandler: true,
|
|
344
|
+
lastResultState: 'running'
|
|
345
|
+
};
|
|
337
346
|
const commonRunOptions = {
|
|
338
|
-
actionId:
|
|
347
|
+
actionId: extendedAction.actionId,
|
|
339
348
|
inputData: runActionRequest.inputData,
|
|
340
349
|
currentLocale: runActionRequest.locale,
|
|
341
350
|
currentUser: runActionRequest.user,
|
|
@@ -351,10 +360,10 @@ function runCustomAction({ runActionRequest, customActionMap, contentSourceDataB
|
|
|
351
360
|
...configDelegate
|
|
352
361
|
};
|
|
353
362
|
let promise;
|
|
354
|
-
if (
|
|
355
|
-
promise =
|
|
363
|
+
if (extendedAction.type === 'global') {
|
|
364
|
+
promise = extendedAction.run(commonRunOptions);
|
|
356
365
|
}
|
|
357
|
-
else if (
|
|
366
|
+
else if (extendedAction.type === 'bulk') {
|
|
358
367
|
const documents = runActionRequest.documents.map((documentSpec) => {
|
|
359
368
|
const { document } = getCSIDocumentAndModelWithSourceFromDocumentSpec({
|
|
360
369
|
documentSpec,
|
|
@@ -362,78 +371,80 @@ function runCustomAction({ runActionRequest, customActionMap, contentSourceDataB
|
|
|
362
371
|
});
|
|
363
372
|
return document;
|
|
364
373
|
});
|
|
365
|
-
promise =
|
|
374
|
+
promise = extendedAction.run({
|
|
366
375
|
...commonRunOptions,
|
|
367
376
|
documents
|
|
368
377
|
});
|
|
369
378
|
}
|
|
370
|
-
else if (
|
|
379
|
+
else if (extendedAction.type === 'document') {
|
|
371
380
|
const { document, model } = getCSIDocumentAndModelWithSourceFromDocumentSpec({
|
|
372
|
-
documentSpec:
|
|
381
|
+
documentSpec: extendedAction.documentSpec,
|
|
373
382
|
contentSourceDataById
|
|
374
383
|
});
|
|
375
|
-
promise =
|
|
384
|
+
promise = extendedAction.run({
|
|
376
385
|
...commonRunOptions,
|
|
377
386
|
document,
|
|
378
387
|
model,
|
|
379
388
|
contentSourceActions: commonRunOptions.getContentSourceActionsForSource({
|
|
380
|
-
srcType:
|
|
381
|
-
srcProjectId:
|
|
389
|
+
srcType: extendedAction.documentSpec.srcType,
|
|
390
|
+
srcProjectId: extendedAction.documentSpec.srcProjectId
|
|
382
391
|
})
|
|
383
392
|
});
|
|
384
393
|
}
|
|
385
|
-
else if (
|
|
394
|
+
else if (extendedAction.type === 'objectModel') {
|
|
386
395
|
const handlerObjectParams = getHandlerParamsForObjectModelAction({
|
|
387
|
-
|
|
396
|
+
extendedAction,
|
|
388
397
|
contentSourceDataById
|
|
389
398
|
});
|
|
390
|
-
promise =
|
|
399
|
+
promise = extendedAction.run({
|
|
391
400
|
...commonRunOptions,
|
|
392
401
|
...handlerObjectParams,
|
|
393
402
|
contentSourceActions: commonRunOptions.getContentSourceActionsForSource({
|
|
394
|
-
srcType:
|
|
395
|
-
srcProjectId:
|
|
403
|
+
srcType: extendedAction.documentSpec.srcType,
|
|
404
|
+
srcProjectId: extendedAction.documentSpec.srcProjectId
|
|
396
405
|
})
|
|
397
406
|
});
|
|
398
407
|
}
|
|
399
|
-
else if (
|
|
408
|
+
else if (extendedAction.type === 'objectField') {
|
|
400
409
|
const handlerObjectParams = getHandlerParamsForObjectFieldAction({
|
|
401
|
-
|
|
410
|
+
extendedAction,
|
|
402
411
|
contentSourceDataById
|
|
403
412
|
});
|
|
404
|
-
promise =
|
|
413
|
+
promise = extendedAction.run({
|
|
405
414
|
...commonRunOptions,
|
|
406
415
|
...handlerObjectParams,
|
|
407
416
|
contentSourceActions: commonRunOptions.getContentSourceActionsForSource({
|
|
408
|
-
srcType:
|
|
409
|
-
srcProjectId:
|
|
417
|
+
srcType: extendedAction.documentSpec.srcType,
|
|
418
|
+
srcProjectId: extendedAction.documentSpec.srcProjectId
|
|
410
419
|
})
|
|
411
420
|
});
|
|
412
421
|
}
|
|
413
|
-
else if (
|
|
414
|
-
const handlerFieldParams = getHandlerParamsForFieldAction({
|
|
415
|
-
promise =
|
|
422
|
+
else if (extendedAction.type === 'field') {
|
|
423
|
+
const handlerFieldParams = getHandlerParamsForFieldAction({ extendedAction, contentSourceDataById });
|
|
424
|
+
promise = extendedAction.run({
|
|
416
425
|
...commonRunOptions,
|
|
417
426
|
...handlerFieldParams,
|
|
418
427
|
contentSourceActions: commonRunOptions.getContentSourceActionsForSource({
|
|
419
|
-
srcType:
|
|
420
|
-
srcProjectId:
|
|
428
|
+
srcType: extendedAction.documentSpec.srcType,
|
|
429
|
+
srcProjectId: extendedAction.documentSpec.srcProjectId
|
|
421
430
|
})
|
|
422
431
|
});
|
|
423
432
|
}
|
|
424
433
|
else {
|
|
425
|
-
throw new Error(`action type ${
|
|
434
|
+
throw new Error(`action type ${extendedAction.type} not supported`);
|
|
426
435
|
}
|
|
427
436
|
return promise
|
|
428
437
|
.then((actionResult) => {
|
|
429
438
|
var _a;
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
439
|
+
customActionRunStateMap[runActionRequest.actionId] = {
|
|
440
|
+
runningHandler: false,
|
|
441
|
+
lastResultState: actionResult === null || actionResult === void 0 ? void 0 : actionResult.state
|
|
442
|
+
};
|
|
443
|
+
userLogger.debug(`Action completed: ${extendedAction.actionId}`);
|
|
433
444
|
return Promise.resolve((0, utils_1.omitByNil)({
|
|
434
|
-
actionId:
|
|
435
|
-
actionName:
|
|
436
|
-
actionType: storeActionTypeToAPIActionType(
|
|
445
|
+
actionId: extendedAction.actionId,
|
|
446
|
+
actionName: extendedAction.name,
|
|
447
|
+
actionType: storeActionTypeToAPIActionType(extendedAction.type),
|
|
437
448
|
// TODO: resolve the state if state function is defined
|
|
438
449
|
state: (_a = actionResult === null || actionResult === void 0 ? void 0 : actionResult.state) !== null && _a !== void 0 ? _a : 'enabled',
|
|
439
450
|
success: actionResult === null || actionResult === void 0 ? void 0 : actionResult.success,
|
|
@@ -441,13 +452,15 @@ function runCustomAction({ runActionRequest, customActionMap, contentSourceDataB
|
|
|
441
452
|
}));
|
|
442
453
|
})
|
|
443
454
|
.catch((error) => {
|
|
444
|
-
|
|
445
|
-
|
|
455
|
+
customActionRunStateMap[runActionRequest.actionId] = {
|
|
456
|
+
runningHandler: false,
|
|
457
|
+
lastResultState: prevResultState
|
|
458
|
+
};
|
|
446
459
|
userLogger.debug(`Error running action: ${error.message}`);
|
|
447
460
|
return Promise.resolve({
|
|
448
|
-
actionId:
|
|
449
|
-
actionName:
|
|
450
|
-
actionType: storeActionTypeToAPIActionType(
|
|
461
|
+
actionId: extendedAction.actionId,
|
|
462
|
+
actionName: extendedAction.name,
|
|
463
|
+
actionType: storeActionTypeToAPIActionType(extendedAction.type),
|
|
451
464
|
// TODO: resolve the state if state function is defined
|
|
452
465
|
state: prevResultState !== null && prevResultState !== void 0 ? prevResultState : 'enabled',
|
|
453
466
|
error: `Error running action: ${error.message}`
|
|
@@ -455,15 +468,17 @@ function runCustomAction({ runActionRequest, customActionMap, contentSourceDataB
|
|
|
455
468
|
});
|
|
456
469
|
}
|
|
457
470
|
catch (error) {
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
|
|
471
|
+
if (customActionRunStateMap[runActionRequest.actionId]) {
|
|
472
|
+
customActionRunStateMap[runActionRequest.actionId] = {
|
|
473
|
+
runningHandler: false,
|
|
474
|
+
lastResultState: prevResultState
|
|
475
|
+
};
|
|
461
476
|
}
|
|
462
477
|
userLogger.debug(`Error running action: ${error.message}`);
|
|
463
478
|
return Promise.resolve({
|
|
464
479
|
actionId: runActionRequest.actionId,
|
|
465
|
-
actionName: (_a =
|
|
466
|
-
actionType: (_b = storeActionTypeToAPIActionType(
|
|
480
|
+
actionName: (_a = extendedAction === null || extendedAction === void 0 ? void 0 : extendedAction.name) !== null && _a !== void 0 ? _a : runActionRequest.actionName,
|
|
481
|
+
actionType: (_b = storeActionTypeToAPIActionType(extendedAction === null || extendedAction === void 0 ? void 0 : extendedAction.type)) !== null && _b !== void 0 ? _b : runActionRequest.actionType,
|
|
467
482
|
// TODO: resolve the state if state function is defined
|
|
468
483
|
state: prevResultState !== null && prevResultState !== void 0 ? prevResultState : 'enabled',
|
|
469
484
|
error: `Error running action: ${error.message}`
|
|
@@ -480,16 +495,34 @@ function getCSIDocumentWithSourceFromDocumentSpec(documentSpec, configDelegate)
|
|
|
480
495
|
})
|
|
481
496
|
: undefined;
|
|
482
497
|
}
|
|
483
|
-
function
|
|
498
|
+
function getAPIActionState(extendedAction, customActionRunStateMap) {
|
|
499
|
+
var _a;
|
|
500
|
+
const actionId = extendedAction.actionId;
|
|
501
|
+
const actionRunState = customActionRunStateMap[actionId];
|
|
502
|
+
let state;
|
|
503
|
+
let needsResolving = false;
|
|
504
|
+
if (actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.runningHandler) {
|
|
505
|
+
state = 'running';
|
|
506
|
+
}
|
|
507
|
+
else if (extendedAction.state) {
|
|
508
|
+
state = 'unknown';
|
|
509
|
+
needsResolving = true;
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
state = (_a = actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.lastResultState) !== null && _a !== void 0 ? _a : 'enabled';
|
|
513
|
+
}
|
|
514
|
+
return { state, needsResolving };
|
|
515
|
+
}
|
|
516
|
+
function getHandlerParamsForObjectModelAction({ extendedAction, contentSourceDataById }) {
|
|
484
517
|
const fieldActionCommonParams = getHandlerParamsForFieldAction({
|
|
485
|
-
|
|
518
|
+
extendedAction,
|
|
486
519
|
contentSourceDataById
|
|
487
520
|
});
|
|
488
521
|
if (!fieldActionCommonParams.documentField) {
|
|
489
|
-
throw new Error(`object document field not found at field path: ${
|
|
522
|
+
throw new Error(`object document field not found at field path: ${extendedAction.fieldPath.join('.')}`);
|
|
490
523
|
}
|
|
491
524
|
const documentField = fieldActionCommonParams.documentField;
|
|
492
|
-
const documentSpec =
|
|
525
|
+
const documentSpec = extendedAction.documentSpec;
|
|
493
526
|
const contentSourceData = (0, content_store_utils_1.getContentSourceDataByTypeAndProjectIdOrThrow)(documentSpec.srcType, documentSpec.srcProjectId, contentSourceDataById);
|
|
494
527
|
const objectModel = contentSourceData.modelMap[documentField.modelName];
|
|
495
528
|
if (!objectModel || objectModel.type !== 'object') {
|
|
@@ -506,13 +539,13 @@ function getHandlerParamsForObjectModelAction({ storeAction, contentSourceDataBy
|
|
|
506
539
|
}
|
|
507
540
|
};
|
|
508
541
|
}
|
|
509
|
-
function getHandlerParamsForObjectFieldAction({
|
|
542
|
+
function getHandlerParamsForObjectFieldAction({ extendedAction, contentSourceDataById }) {
|
|
510
543
|
const fieldActionCommonParams = getHandlerParamsForFieldAction({
|
|
511
|
-
|
|
544
|
+
extendedAction,
|
|
512
545
|
contentSourceDataById
|
|
513
546
|
});
|
|
514
547
|
if (!fieldActionCommonParams.documentField) {
|
|
515
|
-
throw new Error(`object document field not found at field path: ${
|
|
548
|
+
throw new Error(`object document field not found at field path: ${extendedAction.fieldPath.join('.')}`);
|
|
516
549
|
}
|
|
517
550
|
return {
|
|
518
551
|
...fieldActionCommonParams,
|
|
@@ -520,8 +553,8 @@ function getHandlerParamsForObjectFieldAction({ storeAction, contentSourceDataBy
|
|
|
520
553
|
modelField: fieldActionCommonParams.modelField
|
|
521
554
|
};
|
|
522
555
|
}
|
|
523
|
-
function getHandlerParamsForFieldAction({
|
|
524
|
-
const documentSpec =
|
|
556
|
+
function getHandlerParamsForFieldAction({ extendedAction, contentSourceDataById }) {
|
|
557
|
+
const documentSpec = extendedAction.documentSpec;
|
|
525
558
|
const contentSourceData = (0, content_store_utils_1.getContentSourceDataByTypeAndProjectIdOrThrow)(documentSpec.srcType, documentSpec.srcProjectId, contentSourceDataById);
|
|
526
559
|
const document = contentSourceData.documentMap[documentSpec.srcDocumentId];
|
|
527
560
|
const csiDocument = contentSourceData.csiDocumentMap[documentSpec.srcDocumentId];
|
|
@@ -537,7 +570,7 @@ function getHandlerParamsForFieldAction({ storeAction, contentSourceDataById })
|
|
|
537
570
|
const { modelField, documentField } = (0, content_store_utils_1.getModelAndDocumentFieldForLocalizedFieldPath)({
|
|
538
571
|
document,
|
|
539
572
|
model,
|
|
540
|
-
fieldPath:
|
|
573
|
+
fieldPath: extendedAction.fieldPath,
|
|
541
574
|
modelMap: contentSourceData.modelMap
|
|
542
575
|
});
|
|
543
576
|
const csiDocumentField = (0, store_to_csi_docs_converter_1.mapStoreFieldToCSIField)(documentField);
|
|
@@ -550,7 +583,7 @@ function getHandlerParamsForFieldAction({ storeAction, contentSourceDataById })
|
|
|
550
583
|
},
|
|
551
584
|
documentField: csiDocumentField,
|
|
552
585
|
modelField: modelField,
|
|
553
|
-
fieldPath:
|
|
586
|
+
fieldPath: extendedAction.fieldPath
|
|
554
587
|
};
|
|
555
588
|
}
|
|
556
589
|
function getCSIDocumentAndModelWithSourceFromDocumentSpec({ documentSpec, contentSourceDataById }) {
|
|
@@ -583,4 +616,157 @@ function storeActionTypeToAPIActionType(storeActionType) {
|
|
|
583
616
|
}
|
|
584
617
|
return storeActionType;
|
|
585
618
|
}
|
|
619
|
+
function findCustomActionById({ actionId, customActionRunStateMap, contentSourceDataById, stackbitConfig }) {
|
|
620
|
+
var _a, _b, _c, _d, _e;
|
|
621
|
+
const actionRunState = customActionRunStateMap[actionId];
|
|
622
|
+
if (isGlobalActionId(actionId)) {
|
|
623
|
+
if (!stackbitConfig || !Array.isArray(stackbitConfig.actions)) {
|
|
624
|
+
return undefined;
|
|
625
|
+
}
|
|
626
|
+
const actionName = getGlobalActionNameFromId(actionId);
|
|
627
|
+
const action = stackbitConfig.actions.find((action) => action.name === actionName);
|
|
628
|
+
if (!action) {
|
|
629
|
+
return undefined;
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
...action,
|
|
633
|
+
actionId,
|
|
634
|
+
label: (_a = action.label) !== null && _a !== void 0 ? _a : lodash_1.default.startCase(action.name),
|
|
635
|
+
runningHandler: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.runningHandler,
|
|
636
|
+
lastResultState: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.lastResultState
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
const { srcType, srcProjectId, srcDocumentId, actionName, fieldPath } = (_b = parseActionId(actionId)) !== null && _b !== void 0 ? _b : {};
|
|
640
|
+
if (!srcType || !srcProjectId || !srcDocumentId || !actionName) {
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
const documentSpec = { srcType, srcProjectId, srcDocumentId };
|
|
644
|
+
const contentSourceData = (0, content_store_utils_1.getContentSourceDataByTypeAndProjectIdOrThrow)(srcType, srcProjectId, contentSourceDataById);
|
|
645
|
+
const document = contentSourceData.documentMap[srcDocumentId];
|
|
646
|
+
if (!document) {
|
|
647
|
+
return undefined;
|
|
648
|
+
}
|
|
649
|
+
const modelName = document.srcModelName;
|
|
650
|
+
const model = contentSourceData.modelMap[modelName];
|
|
651
|
+
// The model of a document is always 'page' or 'data',
|
|
652
|
+
// this condition helps TS to infer the right type of model.actions
|
|
653
|
+
if (!model || (model.type !== 'page' && model.type !== 'data')) {
|
|
654
|
+
return undefined;
|
|
655
|
+
}
|
|
656
|
+
if (!('actions' in model) || !Array.isArray(model.actions)) {
|
|
657
|
+
return undefined;
|
|
658
|
+
}
|
|
659
|
+
if (typeof fieldPath === 'undefined') {
|
|
660
|
+
// fieldPath was not provided, therefore the model must be of type "page" or "data",
|
|
661
|
+
// and the action type must be 'document'
|
|
662
|
+
const action = model.actions.find((action) => action.name === actionName);
|
|
663
|
+
if (!action) {
|
|
664
|
+
return undefined;
|
|
665
|
+
}
|
|
666
|
+
return {
|
|
667
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
668
|
+
...action,
|
|
669
|
+
type: 'document',
|
|
670
|
+
actionId,
|
|
671
|
+
label: (_c = action.label) !== null && _c !== void 0 ? _c : lodash_1.default.startCase(action.name),
|
|
672
|
+
documentSpec,
|
|
673
|
+
runningHandler: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.runningHandler,
|
|
674
|
+
lastResultState: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.lastResultState
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
const { modelField, documentField } = (0, content_store_utils_1.getModelAndDocumentFieldForLocalizedFieldPath)({
|
|
679
|
+
document,
|
|
680
|
+
model,
|
|
681
|
+
fieldPath,
|
|
682
|
+
modelMap: contentSourceData.modelMap
|
|
683
|
+
});
|
|
684
|
+
if ('actions' in modelField && Array.isArray(modelField.actions)) {
|
|
685
|
+
const action = modelField.actions.find((action) => action.name === actionName);
|
|
686
|
+
if (action) {
|
|
687
|
+
return {
|
|
688
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
689
|
+
...action,
|
|
690
|
+
type: action.type === 'object' ? 'objectField' : 'field',
|
|
691
|
+
actionId,
|
|
692
|
+
label: (_d = action.label) !== null && _d !== void 0 ? _d : lodash_1.default.startCase(action.name),
|
|
693
|
+
documentSpec,
|
|
694
|
+
fieldPath,
|
|
695
|
+
runningHandler: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.runningHandler,
|
|
696
|
+
lastResultState: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.lastResultState
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (modelField.type === 'model') {
|
|
701
|
+
if (documentField.type !== 'model' || documentField.localized || documentField.isUnset) {
|
|
702
|
+
return undefined;
|
|
703
|
+
}
|
|
704
|
+
const modelName = documentField.srcModelName;
|
|
705
|
+
const model = contentSourceData.modelMap[modelName];
|
|
706
|
+
if (!model || model.type !== 'object') {
|
|
707
|
+
return undefined;
|
|
708
|
+
}
|
|
709
|
+
if (!('actions' in model && Array.isArray(model.actions))) {
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
712
|
+
// This is a nested model of type "object", so the action must be CustomActionObjectModel
|
|
713
|
+
const action = model.actions.find((action) => action.name === actionName);
|
|
714
|
+
if (!action) {
|
|
715
|
+
return undefined;
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
// if configuration is updated, the new action properties will override the stored action properties
|
|
719
|
+
...action,
|
|
720
|
+
type: 'objectModel',
|
|
721
|
+
actionId,
|
|
722
|
+
label: (_e = action.label) !== null && _e !== void 0 ? _e : lodash_1.default.startCase(action.name),
|
|
723
|
+
documentSpec,
|
|
724
|
+
fieldPath,
|
|
725
|
+
runningHandler: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.runningHandler,
|
|
726
|
+
lastResultState: actionRunState === null || actionRunState === void 0 ? void 0 : actionRunState.lastResultState
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function globalActionId(action) {
|
|
732
|
+
return `config.actions.${action.name}`;
|
|
733
|
+
}
|
|
734
|
+
function isGlobalActionId(actionId) {
|
|
735
|
+
return actionId.startsWith('config.actions.');
|
|
736
|
+
}
|
|
737
|
+
function getGlobalActionNameFromId(actionId) {
|
|
738
|
+
return actionId.substring('config.actions.'.length);
|
|
739
|
+
}
|
|
740
|
+
function documentActionId({ srcType, srcProjectId, srcDocumentId, actionName }) {
|
|
741
|
+
return `${srcType}:${srcProjectId}:${srcDocumentId}:${actionName}`;
|
|
742
|
+
}
|
|
743
|
+
function fieldPathActionId({ srcType, srcProjectId, srcDocumentId, fieldPath, actionName }) {
|
|
744
|
+
return `${srcType}:${srcProjectId}:${srcDocumentId}:${fieldPath.join('.')}:${actionName}`;
|
|
745
|
+
}
|
|
746
|
+
function parseActionId(actionId) {
|
|
747
|
+
var _a;
|
|
748
|
+
const parts = actionId.split(':');
|
|
749
|
+
if (parts.length < 4 || parts.length > 5) {
|
|
750
|
+
return undefined;
|
|
751
|
+
}
|
|
752
|
+
const srcType = parts[0];
|
|
753
|
+
const srcProjectId = parts[1];
|
|
754
|
+
const srcDocumentId = parts[2];
|
|
755
|
+
let fieldPath;
|
|
756
|
+
let actionName;
|
|
757
|
+
if (parts.length === 5) {
|
|
758
|
+
fieldPath = (_a = parts[3]) === null || _a === void 0 ? void 0 : _a.split('.');
|
|
759
|
+
actionName = parts[4];
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
actionName = parts[3];
|
|
763
|
+
}
|
|
764
|
+
return {
|
|
765
|
+
srcType,
|
|
766
|
+
srcProjectId,
|
|
767
|
+
srcDocumentId,
|
|
768
|
+
actionName,
|
|
769
|
+
fieldPath
|
|
770
|
+
};
|
|
771
|
+
}
|
|
586
772
|
//# sourceMappingURL=custom-actions.js.map
|