@appsemble/utils 0.28.6 → 0.28.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/README.md +3 -3
- package/allActions.d.ts +3 -0
- package/allActions.js +9 -0
- package/api/components/schemas/ActionDefinition.js +1 -0
- package/api/components/schemas/FlowCancelActionDefinition.d.ts +1 -0
- package/api/components/schemas/FlowCancelActionDefinition.js +14 -0
- package/api/components/schemas/index.d.ts +1 -0
- package/api/components/schemas/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/serverActions.d.ts +2 -1
- package/validation.js +13 -13
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Utilities
|
|
2
2
|
|
|
3
3
|
> Internal utility functions used across multiple Appsemble projects.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.28.8)
|
|
7
7
|
[](https://prettier.io)
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
@@ -26,5 +26,5 @@ not guaranteed.
|
|
|
26
26
|
|
|
27
27
|
## License
|
|
28
28
|
|
|
29
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.28.
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.28.8/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
package/allActions.d.ts
ADDED
package/allActions.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { schemas } from './index.js';
|
|
2
|
+
const [, kinds] = schemas.ActionDefinition.allOf;
|
|
3
|
+
export const allActions = new Set(kinds.anyOf.map(({ $ref }) => {
|
|
4
|
+
const ref = $ref.split('/').at(-1);
|
|
5
|
+
const action = schemas[ref];
|
|
6
|
+
const name = action.properties.type.enum[0];
|
|
7
|
+
return name;
|
|
8
|
+
}));
|
|
9
|
+
//# sourceMappingURL=allActions.js.map
|
|
@@ -38,6 +38,7 @@ export const ActionDefinition = {
|
|
|
38
38
|
{ $ref: '#/components/schemas/FlowBackActionDefinition' },
|
|
39
39
|
{ $ref: '#/components/schemas/FlowFinishActionDefinition' },
|
|
40
40
|
{ $ref: '#/components/schemas/FlowNextActionDefinition' },
|
|
41
|
+
{ $ref: '#/components/schemas/FlowCancelActionDefinition' },
|
|
41
42
|
{ $ref: '#/components/schemas/FlowToActionDefinition' },
|
|
42
43
|
{ $ref: '#/components/schemas/LinkActionDefinition' },
|
|
43
44
|
{ $ref: '#/components/schemas/LinkBackActionDefinition' },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FlowCancelActionDefinition: import("openapi-types").OpenAPIV3.SchemaObject;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseActionDefinition } from './BaseActionDefinition.js';
|
|
2
|
+
import { extendJSONSchema } from './utils.js';
|
|
3
|
+
export const FlowCancelActionDefinition = extendJSONSchema(BaseActionDefinition, {
|
|
4
|
+
type: 'object',
|
|
5
|
+
additionalProperties: false,
|
|
6
|
+
required: ['type'],
|
|
7
|
+
properties: {
|
|
8
|
+
type: {
|
|
9
|
+
enum: ['flow.cancel'],
|
|
10
|
+
description: "On [flow pages](#flow-page-definition-sub-pages), cancel the ongoing flow and invoke the page's [`onFlowFinish`](#flow-page-actions-definition-on-flow-finish) action.",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=FlowCancelActionDefinition.js.map
|
|
@@ -32,6 +32,7 @@ export * from './EventsDefinition.js';
|
|
|
32
32
|
export * from './FlowBackActionDefinition.js';
|
|
33
33
|
export * from './FlowFinishActionDefinition.js';
|
|
34
34
|
export * from './FlowNextActionDefinition.js';
|
|
35
|
+
export * from './FlowCancelActionDefinition.js';
|
|
35
36
|
export * from './FlowPageActionsDefinition.js';
|
|
36
37
|
export * from './FlowPageDefinition.js';
|
|
37
38
|
export * from './FlowToActionDefinition.js';
|
|
@@ -32,6 +32,7 @@ export * from './EventsDefinition.js';
|
|
|
32
32
|
export * from './FlowBackActionDefinition.js';
|
|
33
33
|
export * from './FlowFinishActionDefinition.js';
|
|
34
34
|
export * from './FlowNextActionDefinition.js';
|
|
35
|
+
export * from './FlowCancelActionDefinition.js';
|
|
35
36
|
export * from './FlowPageActionsDefinition.js';
|
|
36
37
|
export * from './FlowPageDefinition.js';
|
|
37
38
|
export * from './FlowToActionDefinition.js';
|
package/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './theme.js';
|
|
|
24
24
|
export * from './langmap.js';
|
|
25
25
|
export * from './i18n.js';
|
|
26
26
|
export * from './examples.js';
|
|
27
|
+
export * from './allActions.js';
|
|
27
28
|
export * from './serverActions.js';
|
|
28
29
|
export * from './validation.js';
|
|
29
30
|
export * from './convertToCsv.js';
|
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export * from './theme.js';
|
|
|
24
24
|
export * from './langmap.js';
|
|
25
25
|
export * from './i18n.js';
|
|
26
26
|
export * from './examples.js';
|
|
27
|
+
export * from './allActions.js';
|
|
27
28
|
export * from './serverActions.js';
|
|
28
29
|
export * from './validation.js';
|
|
29
30
|
export * from './convertToCsv.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.8",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test": "vitest"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@appsemble/types": "0.28.
|
|
40
|
+
"@appsemble/types": "0.28.8",
|
|
41
41
|
"axios": "^1.0.0",
|
|
42
42
|
"cron-parser": "^4.0.0",
|
|
43
43
|
"date-fns": "^2.0.0",
|
package/serverActions.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const serverActions: Set<
|
|
1
|
+
export declare const serverActions: Set<"log" | "condition" | "each" | "email" | "noop" | "notify" | "static" | "throw" | "request" | "resource.create" | "resource.delete" | "resource.get" | "resource.patch" | "resource.query" | "resource.update">;
|
|
2
|
+
export type ServerActionName = typeof serverActions extends Set<infer T> ? T : never;
|
package/validation.js
CHANGED
|
@@ -491,7 +491,7 @@ function validateActions(definition, report) {
|
|
|
491
491
|
const urlRegex = new RegExp(`^${partialNormalized.source}:`);
|
|
492
492
|
iterApp(definition, {
|
|
493
493
|
onAction(action, path) {
|
|
494
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
494
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
495
495
|
if (path[0] === 'cron' && !serverActions.has(action.type)) {
|
|
496
496
|
report(action.type, 'action type is not supported for cron jobs', [...path, 'type']);
|
|
497
497
|
return;
|
|
@@ -501,10 +501,10 @@ function validateActions(definition, report) {
|
|
|
501
501
|
return;
|
|
502
502
|
}
|
|
503
503
|
if (['user.register', 'user.create', 'user.update'].includes(action.type) &&
|
|
504
|
-
Object.values(action.properties)[0] &&
|
|
505
|
-
((
|
|
506
|
-
for (const propertyName of Object.keys(Object.values(action.properties)[0])) {
|
|
507
|
-
if (!((
|
|
504
|
+
Object.values((_a = action.properties) !== null && _a !== void 0 ? _a : {})[0] &&
|
|
505
|
+
((_b = definition.users) === null || _b === void 0 ? void 0 : _b.properties)) {
|
|
506
|
+
for (const propertyName of Object.keys(Object.values((_c = action.properties) !== null && _c !== void 0 ? _c : {})[0])) {
|
|
507
|
+
if (!((_d = definition.users) === null || _d === void 0 ? void 0 : _d.properties[propertyName])) {
|
|
508
508
|
report(action.type, 'contains a property that doesn’t exist in users.properties', [
|
|
509
509
|
...path,
|
|
510
510
|
'properties',
|
|
@@ -515,14 +515,14 @@ function validateActions(definition, report) {
|
|
|
515
515
|
if (action.type.startsWith('resource.')) {
|
|
516
516
|
// All of the actions starting with `resource.` contain a property called `resource`.
|
|
517
517
|
const { resource: resourceName, view } = action;
|
|
518
|
-
const resource = (
|
|
518
|
+
const resource = (_e = definition.resources) === null || _e === void 0 ? void 0 : _e[resourceName];
|
|
519
519
|
if (!resource) {
|
|
520
520
|
report(action.type, 'refers to a resource that doesn’t exist', [...path, 'resource']);
|
|
521
521
|
return;
|
|
522
522
|
}
|
|
523
523
|
if (!action.type.startsWith('resource.subscription.')) {
|
|
524
524
|
const type = action.type.split('.')[1];
|
|
525
|
-
const roles = (
|
|
525
|
+
const roles = (_g = (_f = resource === null || resource === void 0 ? void 0 : resource[type]) === null || _f === void 0 ? void 0 : _f.roles) !== null && _g !== void 0 ? _g : resource === null || resource === void 0 ? void 0 : resource.roles;
|
|
526
526
|
if (!roles) {
|
|
527
527
|
report(action.type, 'refers to a resource action that is currently set to private', [
|
|
528
528
|
...path,
|
|
@@ -535,11 +535,11 @@ function validateActions(definition, report) {
|
|
|
535
535
|
return;
|
|
536
536
|
}
|
|
537
537
|
if ((type === 'get' || type === 'query') && view) {
|
|
538
|
-
if (!((
|
|
538
|
+
if (!((_h = resource.views) === null || _h === void 0 ? void 0 : _h[view])) {
|
|
539
539
|
report(action.type, 'refers to a view that doesn’t exist', [...path, 'view']);
|
|
540
540
|
return;
|
|
541
541
|
}
|
|
542
|
-
const viewRoles = (
|
|
542
|
+
const viewRoles = (_j = resource === null || resource === void 0 ? void 0 : resource.views) === null || _j === void 0 ? void 0 : _j[view].roles;
|
|
543
543
|
if (!(viewRoles === null || viewRoles === void 0 ? void 0 : viewRoles.length)) {
|
|
544
544
|
report(action.type, 'refers to a resource view that is currently set to private', [
|
|
545
545
|
...path,
|
|
@@ -555,19 +555,19 @@ function validateActions(definition, report) {
|
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
if (action.type.startsWith('flow.')) {
|
|
558
|
-
const page = (
|
|
558
|
+
const page = (_k = definition.pages) === null || _k === void 0 ? void 0 : _k[Number(path[1])];
|
|
559
559
|
if (page.type !== 'flow' && page.type !== 'loop') {
|
|
560
560
|
report(action.type, 'flow actions can only be used on pages with the type ‘flow’ or ‘loop’', [...path, 'type']);
|
|
561
561
|
return;
|
|
562
562
|
}
|
|
563
|
-
if (action.type === 'flow.cancel' && !((
|
|
563
|
+
if (action.type === 'flow.cancel' && !((_l = page.actions) === null || _l === void 0 ? void 0 : _l.onFlowCancel)) {
|
|
564
564
|
report(action.type, 'was defined but ‘onFlowCancel’ page action wasn’t defined', [
|
|
565
565
|
...path,
|
|
566
566
|
'type',
|
|
567
567
|
]);
|
|
568
568
|
return;
|
|
569
569
|
}
|
|
570
|
-
if (action.type === 'flow.finish' && !((
|
|
570
|
+
if (action.type === 'flow.finish' && !((_m = page.actions) === null || _m === void 0 ? void 0 : _m.onFlowFinish)) {
|
|
571
571
|
report(action.type, 'was defined but ‘onFlowFinish’ page action wasn’t defined', [
|
|
572
572
|
...path,
|
|
573
573
|
'type',
|
|
@@ -581,7 +581,7 @@ function validateActions(definition, report) {
|
|
|
581
581
|
if (page.type === 'flow' &&
|
|
582
582
|
action.type === 'flow.next' &&
|
|
583
583
|
Number(path[3]) === page.steps.length - 1 &&
|
|
584
|
-
!((
|
|
584
|
+
!((_o = page.actions) === null || _o === void 0 ? void 0 : _o.onFlowFinish)) {
|
|
585
585
|
report(action.type, 'was defined on the last step but ‘onFlowFinish’ page action wasn’t defined', [...path, 'type']);
|
|
586
586
|
return;
|
|
587
587
|
}
|