@kahitsan/plugin-sdk 0.6.0 → 0.7.1
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/flow-bundle.js +116 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/flow-bundle.js
CHANGED
|
@@ -185,11 +185,127 @@ async function runFlow(flow, startId, ctx) {
|
|
|
185
185
|
current = target;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
+
|
|
189
|
+
// src/flow/resource-flows.ts
|
|
190
|
+
function crudFlow(opts) {
|
|
191
|
+
return {
|
|
192
|
+
id: opts.id,
|
|
193
|
+
title: opts.title,
|
|
194
|
+
nodes: [
|
|
195
|
+
{
|
|
196
|
+
id: opts.triggerId,
|
|
197
|
+
kind: "trigger",
|
|
198
|
+
label: opts.triggerLabel,
|
|
199
|
+
out: [{ id: "o", to: "commit" }]
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: "commit",
|
|
203
|
+
kind: "commit",
|
|
204
|
+
label: opts.commitLabel,
|
|
205
|
+
detail: opts.commitDetail,
|
|
206
|
+
request: opts.request,
|
|
207
|
+
out: [{ id: "o", to: "cond" }]
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
id: "cond",
|
|
211
|
+
kind: "condition",
|
|
212
|
+
label: opts.conditionLabel,
|
|
213
|
+
when: (ctx) => ctx.state.commit ? "yes" : "no",
|
|
214
|
+
out: [
|
|
215
|
+
{ id: "yes", to: "refresh", label: "yes" },
|
|
216
|
+
{ id: "no", to: "error", label: "no" }
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: "error",
|
|
221
|
+
kind: "effect",
|
|
222
|
+
label: opts.errorLabel,
|
|
223
|
+
effect: "toast",
|
|
224
|
+
out: [{ id: "o", to: "done_err" }]
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
id: "refresh",
|
|
228
|
+
kind: "effect",
|
|
229
|
+
label: opts.refreshLabel,
|
|
230
|
+
effect: "refresh",
|
|
231
|
+
out: [{ id: "o", to: "done" }]
|
|
232
|
+
},
|
|
233
|
+
{ id: "done", kind: "terminal", label: opts.doneLabel },
|
|
234
|
+
{ id: "done_err", kind: "terminal", label: opts.failedLabel }
|
|
235
|
+
]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function resourceFlows(cfg) {
|
|
239
|
+
const noun = cfg.noun;
|
|
240
|
+
const lower = noun.toLowerCase();
|
|
241
|
+
const createFlow = crudFlow({
|
|
242
|
+
id: `${cfg.id}.create`,
|
|
243
|
+
title: `Add ${noun}`,
|
|
244
|
+
triggerId: "submit",
|
|
245
|
+
triggerLabel: `Create ${noun}`,
|
|
246
|
+
commitLabel: `Create ${lower}`,
|
|
247
|
+
commitDetail: `POST ${cfg.basePath}`,
|
|
248
|
+
request: (ctx) => ({ url: cfg.basePath, method: "POST", body: ctx.state.body }),
|
|
249
|
+
conditionLabel: "Server accepted?",
|
|
250
|
+
errorLabel: "Show server error in form",
|
|
251
|
+
refreshLabel: "Close modal + reset form + refresh list",
|
|
252
|
+
doneLabel: `${noun} added`,
|
|
253
|
+
failedLabel: "Create failed"
|
|
254
|
+
});
|
|
255
|
+
const editFlow = crudFlow({
|
|
256
|
+
id: `${cfg.id}.edit`,
|
|
257
|
+
title: `Edit ${noun}`,
|
|
258
|
+
triggerId: "submit",
|
|
259
|
+
triggerLabel: "Save Changes",
|
|
260
|
+
commitLabel: `Update ${lower}`,
|
|
261
|
+
commitDetail: `PUT ${cfg.basePath}/:id`,
|
|
262
|
+
request: (ctx) => ({
|
|
263
|
+
url: `${cfg.basePath}/${ctx.state.id}`,
|
|
264
|
+
method: "PUT",
|
|
265
|
+
body: ctx.state.body
|
|
266
|
+
}),
|
|
267
|
+
conditionLabel: "Server accepted?",
|
|
268
|
+
errorLabel: "Show server error in form",
|
|
269
|
+
refreshLabel: "Update modal row + exit edit + refresh list",
|
|
270
|
+
doneLabel: `${noun} updated`,
|
|
271
|
+
failedLabel: "Update failed"
|
|
272
|
+
});
|
|
273
|
+
const archiveFlow = crudFlow({
|
|
274
|
+
id: `${cfg.id}.archive`,
|
|
275
|
+
title: `Archive ${noun}`,
|
|
276
|
+
triggerId: "trigger",
|
|
277
|
+
triggerLabel: `Archive button (active ${lower})`,
|
|
278
|
+
commitLabel: `Soft-delete ${lower}`,
|
|
279
|
+
commitDetail: `DELETE ${cfg.basePath}/:id`,
|
|
280
|
+
request: (ctx) => ({ url: `${cfg.basePath}/${ctx.state.id}`, method: "DELETE" }),
|
|
281
|
+
conditionLabel: "Archived?",
|
|
282
|
+
errorLabel: "Show archive error in modal",
|
|
283
|
+
refreshLabel: "Refresh list + close modal",
|
|
284
|
+
doneLabel: `${noun} archived`,
|
|
285
|
+
failedLabel: "Archive failed"
|
|
286
|
+
});
|
|
287
|
+
const restoreFlow = crudFlow({
|
|
288
|
+
id: `${cfg.id}.restore`,
|
|
289
|
+
title: `Restore ${noun}`,
|
|
290
|
+
triggerId: "trigger",
|
|
291
|
+
triggerLabel: `Restore button (archived ${lower})`,
|
|
292
|
+
commitLabel: `Restore ${lower}`,
|
|
293
|
+
commitDetail: `PATCH ${cfg.basePath}/:id/restore`,
|
|
294
|
+
request: (ctx) => ({ url: `${cfg.basePath}/${ctx.state.id}/restore`, method: "PATCH" }),
|
|
295
|
+
conditionLabel: "Restored?",
|
|
296
|
+
errorLabel: "Show restore error in modal",
|
|
297
|
+
refreshLabel: "Update modal row + refresh list",
|
|
298
|
+
doneLabel: `${noun} restored`,
|
|
299
|
+
failedLabel: "Restore failed"
|
|
300
|
+
});
|
|
301
|
+
return { createFlow, editFlow, archiveFlow, restoreFlow, all: [createFlow, editFlow, archiveFlow, restoreFlow] };
|
|
302
|
+
}
|
|
188
303
|
export {
|
|
189
304
|
FlowSteps,
|
|
190
305
|
buildFlow,
|
|
191
306
|
defineFlow,
|
|
192
307
|
edge,
|
|
193
308
|
node,
|
|
309
|
+
resourceFlows,
|
|
194
310
|
runFlow
|
|
195
311
|
};
|