@rytass/bpm-core-nestjs-module 0.11.0 → 0.13.0
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/CHANGELOG.md +65 -0
- package/README.md +160 -3
- package/package.json +3 -3
- package/src/lib/attachment/attachment-options.d.ts +11 -0
- package/src/lib/attachment/attachment-options.js +21 -6
- package/src/lib/attachment/attachment-options.js.map +1 -1
- package/src/lib/attachment/index.d.ts +1 -0
- package/src/lib/attachment/index.js +1 -0
- package/src/lib/attachment/index.js.map +1 -1
- package/src/lib/bpm/bpm-root.module.d.ts +35 -0
- package/src/lib/bpm/bpm-root.module.js +8 -0
- package/src/lib/bpm/bpm-root.module.js.map +1 -1
- package/src/lib/bpm-auth/bpm-auth.authorization.js +3 -2
- package/src/lib/bpm-auth/bpm-auth.authorization.js.map +1 -1
- package/src/lib/bpm-auth/bpm-auth.decorators.js +2 -1
- package/src/lib/bpm-auth/bpm-auth.decorators.js.map +1 -1
- package/src/lib/bpm-auth/bpm-resolver-access.decorator.d.ts +13 -0
- package/src/lib/bpm-auth/bpm-resolver-access.decorator.js +27 -0
- package/src/lib/bpm-auth/bpm-resolver-access.decorator.js.map +1 -0
- package/src/lib/bpm-auth/bpm-resolver-metadata.d.ts +73 -0
- package/src/lib/bpm-auth/bpm-resolver-metadata.js +158 -0
- package/src/lib/bpm-auth/bpm-resolver-metadata.js.map +1 -0
- package/src/lib/bpm-auth/index.d.ts +2 -0
- package/src/lib/bpm-auth/index.js +2 -0
- package/src/lib/bpm-auth/index.js.map +1 -1
- package/src/lib/condition/condition.service.js +49 -5
- package/src/lib/condition/condition.service.js.map +1 -1
- package/src/lib/form/form-schema.validator.js +277 -56
- package/src/lib/form/form-schema.validator.js.map +1 -1
- package/src/lib/form/form-table-reference.d.ts +28 -0
- package/src/lib/form/form-table-reference.js +53 -0
- package/src/lib/form/form-table-reference.js.map +1 -0
- package/src/lib/form-data-source/form-data-source-value-resolver.service.js +81 -13
- package/src/lib/form-data-source/form-data-source-value-resolver.service.js.map +1 -1
- package/src/lib/form-data-source/form-data-source.queries.d.ts +4 -0
- package/src/lib/form-data-source/form-data-source.queries.js +31 -0
- package/src/lib/form-data-source/form-data-source.queries.js.map +1 -1
- package/src/lib/form-data-source/form-data-source.service.d.ts +21 -0
- package/src/lib/form-data-source/form-data-source.service.js +70 -17
- package/src/lib/form-data-source/form-data-source.service.js.map +1 -1
- package/src/lib/form-data-source/form-data-source.types.d.ts +6 -0
- package/src/lib/form-data-source/form-data-source.types.js.map +1 -1
- package/src/lib/form-data-source/form-data-source.validation.d.ts +12 -1
- package/src/lib/form-data-source/form-data-source.validation.js +34 -5
- package/src/lib/form-data-source/form-data-source.validation.js.map +1 -1
- package/src/lib/identity/identity-options.d.ts +16 -0
- package/src/lib/identity/identity-options.js.map +1 -1
- package/src/lib/identity/identity.module.d.ts +6 -0
- package/src/lib/identity/identity.module.js +9 -2
- package/src/lib/identity/identity.module.js.map +1 -1
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.d.ts +9 -1
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.js +55 -4
- package/src/lib/migrations/0000000000001-enable-postgres-extensions.js.map +1 -1
- package/src/lib/notification/index.d.ts +1 -0
- package/src/lib/notification/index.js +1 -0
- package/src/lib/notification/index.js.map +1 -1
- package/src/lib/organization/dto/manager-resolution.input.d.ts +7 -7
- package/src/lib/organization/dto/membership.input.d.ts +7 -7
- package/src/lib/organization/dto/org-unit.input.d.ts +28 -6
- package/src/lib/organization/dto/org-unit.input.js +4 -2
- package/src/lib/organization/dto/org-unit.input.js.map +1 -1
- package/src/lib/organization/dto/position.input.d.ts +4 -4
- package/src/lib/organization/index.d.ts +4 -0
- package/src/lib/organization/index.js +4 -0
- package/src/lib/organization/index.js.map +1 -1
- package/src/lib/organization/organization.mutations.d.ts +1 -0
- package/src/lib/organization/organization.mutations.js +10 -0
- package/src/lib/organization/organization.mutations.js.map +1 -1
- package/src/lib/organization/organization.service.d.ts +43 -0
- package/src/lib/organization/organization.service.js +166 -7
- package/src/lib/organization/organization.service.js.map +1 -1
- package/src/lib/template/dto/approval-template.input.d.ts +31 -20
- package/src/lib/template/dto/approval-template.input.js.map +1 -1
- package/src/lib/template/template.service.js +34 -1
- package/src/lib/template/template.service.js.map +1 -1
- package/src/lib/workflow-engine/workflow-condition-evaluator.js +18 -0
- package/src/lib/workflow-engine/workflow-condition-evaluator.js.map +1 -1
- package/src/lib/workflow-engine/workflow-engine.service.js +119 -6
- package/src/lib/workflow-engine/workflow-engine.service.js.map +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension point that lets a host stamp its own route metadata onto every BPM
|
|
3
|
+
* GraphQL handler.
|
|
4
|
+
*
|
|
5
|
+
* BPM guards its own resolvers with `@BPMAuthenticated()`, `@BPMAdminOnly()`
|
|
6
|
+
* and `@BPMDesignerOnly()`. A host that also installs a *global* guard of its
|
|
7
|
+
* own — `@rytass/member-base-nestjs-module` registers a `CasbinGuard` that
|
|
8
|
+
* rejects any route carrying no `@CheckPermission` metadata — rejects all of
|
|
9
|
+
* them before BPM's guards ever run, and the two packages cannot be mounted
|
|
10
|
+
* together at all.
|
|
11
|
+
*
|
|
12
|
+
* BPM cannot import the host's decorator, and a decorator cannot read module
|
|
13
|
+
* options because it runs when the class is defined. So the resolver classes
|
|
14
|
+
* register themselves here as they are decorated, and the host supplies a
|
|
15
|
+
* factory that BPM replays over them at module wiring time — before Nest reads
|
|
16
|
+
* any of this metadata, which it only does per request.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* How much authority BPM itself demands of a caller for one handler. A host
|
|
20
|
+
* maps this onto its own permission vocabulary.
|
|
21
|
+
*/
|
|
22
|
+
export type BPMResolverAccessLevel = 'admin' | 'authenticated' | 'designer';
|
|
23
|
+
export interface BPMResolverHandlerDescriptor {
|
|
24
|
+
/** Authority BPM's own guards require for this handler. */
|
|
25
|
+
readonly access: BPMResolverAccessLevel;
|
|
26
|
+
/**
|
|
27
|
+
* Method name on the resolver class. Across BPM this is also the GraphQL
|
|
28
|
+
* field name — `orgUnits`, `createOrgUnit`, `member`.
|
|
29
|
+
*/
|
|
30
|
+
readonly methodName: string;
|
|
31
|
+
/** Resolver class name, for example `OrganizationQueries`. */
|
|
32
|
+
readonly resolverName: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the metadata to attach to one BPM handler, keyed exactly as the
|
|
36
|
+
* host's guard reads it. Return `null` or `undefined` to leave a handler
|
|
37
|
+
* alone.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const resolverMetadataFactory: BPMResolverMetadataFactory = ({ access }) => ({
|
|
42
|
+
* // the key `@CheckPermission` writes, and the value its guard expects
|
|
43
|
+
* PERMISSION_METADATA_KEY: access === 'authenticated' ? ['bpm:use'] : ['bpm:admin'],
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type BPMResolverMetadataFactory = (handler: BPMResolverHandlerDescriptor) => Readonly<Record<string | symbol, unknown>> | null | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Records that a whole resolver class sits behind `access`. Called by BPM's
|
|
50
|
+
* own authorization decorators; hosts do not call this.
|
|
51
|
+
*/
|
|
52
|
+
export declare function registerBPMResolverClassAccess(resolverClass: object, access: BPMResolverAccessLevel): void;
|
|
53
|
+
/**
|
|
54
|
+
* Records that a single handler sits behind `access`, overriding whatever the
|
|
55
|
+
* class-level decorator asked for. Called by BPM's own authorization
|
|
56
|
+
* decorators; hosts do not call this.
|
|
57
|
+
*/
|
|
58
|
+
export declare function registerBPMResolverMethodAccess(resolverClass: object, methodName: string, access: BPMResolverAccessLevel): void;
|
|
59
|
+
/**
|
|
60
|
+
* Replays `factory` over every registered BPM handler and writes the metadata
|
|
61
|
+
* it returns onto the prototype method, which is what Nest hands a guard as
|
|
62
|
+
* `context.getHandler()`.
|
|
63
|
+
*
|
|
64
|
+
* `BPMRootModule` calls this for `resolverMetadataFactory`. Calling it twice
|
|
65
|
+
* with the same factory simply writes the same values again.
|
|
66
|
+
*/
|
|
67
|
+
export declare function applyBPMResolverMetadata(factory: BPMResolverMetadataFactory): void;
|
|
68
|
+
/**
|
|
69
|
+
* Every BPM handler the metadata factory would be offered, in registration
|
|
70
|
+
* order. Exposed so a host can print the list while mapping BPM operations
|
|
71
|
+
* onto its own permissions.
|
|
72
|
+
*/
|
|
73
|
+
export declare function listBPMResolverHandlers(): readonly BPMResolverHandlerDescriptor[];
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Extension point that lets a host stamp its own route metadata onto every BPM
|
|
4
|
+
* GraphQL handler.
|
|
5
|
+
*
|
|
6
|
+
* BPM guards its own resolvers with `@BPMAuthenticated()`, `@BPMAdminOnly()`
|
|
7
|
+
* and `@BPMDesignerOnly()`. A host that also installs a *global* guard of its
|
|
8
|
+
* own — `@rytass/member-base-nestjs-module` registers a `CasbinGuard` that
|
|
9
|
+
* rejects any route carrying no `@CheckPermission` metadata — rejects all of
|
|
10
|
+
* them before BPM's guards ever run, and the two packages cannot be mounted
|
|
11
|
+
* together at all.
|
|
12
|
+
*
|
|
13
|
+
* BPM cannot import the host's decorator, and a decorator cannot read module
|
|
14
|
+
* options because it runs when the class is defined. So the resolver classes
|
|
15
|
+
* register themselves here as they are decorated, and the host supplies a
|
|
16
|
+
* factory that BPM replays over them at module wiring time — before Nest reads
|
|
17
|
+
* any of this metadata, which it only does per request.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.registerBPMResolverClassAccess = registerBPMResolverClassAccess;
|
|
21
|
+
exports.registerBPMResolverMethodAccess = registerBPMResolverMethodAccess;
|
|
22
|
+
exports.applyBPMResolverMetadata = applyBPMResolverMetadata;
|
|
23
|
+
exports.listBPMResolverHandlers = listBPMResolverHandlers;
|
|
24
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
25
|
+
const ACCESS_BY_RESOLVER = new Map();
|
|
26
|
+
/**
|
|
27
|
+
* Records that a whole resolver class sits behind `access`. Called by BPM's
|
|
28
|
+
* own authorization decorators; hosts do not call this.
|
|
29
|
+
*/
|
|
30
|
+
function registerBPMResolverClassAccess(resolverClass, access) {
|
|
31
|
+
readRegistration(resolverClass).classAccess = access;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Records that a single handler sits behind `access`, overriding whatever the
|
|
35
|
+
* class-level decorator asked for. Called by BPM's own authorization
|
|
36
|
+
* decorators; hosts do not call this.
|
|
37
|
+
*/
|
|
38
|
+
function registerBPMResolverMethodAccess(resolverClass, methodName, access) {
|
|
39
|
+
readRegistration(resolverClass).accessByMethod.set(methodName, access);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Replays `factory` over every registered BPM handler and writes the metadata
|
|
43
|
+
* it returns onto the prototype method, which is what Nest hands a guard as
|
|
44
|
+
* `context.getHandler()`.
|
|
45
|
+
*
|
|
46
|
+
* `BPMRootModule` calls this for `resolverMetadataFactory`. Calling it twice
|
|
47
|
+
* with the same factory simply writes the same values again.
|
|
48
|
+
*/
|
|
49
|
+
function applyBPMResolverMetadata(factory) {
|
|
50
|
+
for (const [resolverClass, registration] of ACCESS_BY_RESOLVER) {
|
|
51
|
+
const prototype = readPrototype(resolverClass);
|
|
52
|
+
if (!prototype) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
for (const methodName of listHandlerMethodNames(prototype)) {
|
|
56
|
+
const access = registration.accessByMethod.get(methodName) ??
|
|
57
|
+
registration.classAccess;
|
|
58
|
+
if (access === null || access === undefined) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const metadata = factory({
|
|
62
|
+
access,
|
|
63
|
+
methodName,
|
|
64
|
+
resolverName: readResolverName(resolverClass),
|
|
65
|
+
});
|
|
66
|
+
if (!metadata) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const handler = prototype[methodName];
|
|
70
|
+
// `Reflect.ownKeys`, not `Object.entries`: several Nest ecosystem guards
|
|
71
|
+
// key their metadata by symbol, and dropping those silently would look
|
|
72
|
+
// to a host exactly like the factory never ran.
|
|
73
|
+
for (const key of Reflect.ownKeys(metadata)) {
|
|
74
|
+
Reflect.defineMetadata(key, metadata[key], handler);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Every BPM handler the metadata factory would be offered, in registration
|
|
81
|
+
* order. Exposed so a host can print the list while mapping BPM operations
|
|
82
|
+
* onto its own permissions.
|
|
83
|
+
*/
|
|
84
|
+
function listBPMResolverHandlers() {
|
|
85
|
+
const handlers = [];
|
|
86
|
+
for (const [resolverClass, registration] of ACCESS_BY_RESOLVER) {
|
|
87
|
+
const prototype = readPrototype(resolverClass);
|
|
88
|
+
if (!prototype) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
for (const methodName of listHandlerMethodNames(prototype)) {
|
|
92
|
+
const access = registration.accessByMethod.get(methodName) ??
|
|
93
|
+
registration.classAccess;
|
|
94
|
+
if (access === null || access === undefined) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
handlers.push({
|
|
98
|
+
access,
|
|
99
|
+
methodName,
|
|
100
|
+
resolverName: readResolverName(resolverClass),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return handlers;
|
|
105
|
+
}
|
|
106
|
+
function readRegistration(resolverClass) {
|
|
107
|
+
const existing = ACCESS_BY_RESOLVER.get(resolverClass);
|
|
108
|
+
if (existing) {
|
|
109
|
+
return existing;
|
|
110
|
+
}
|
|
111
|
+
const registration = {
|
|
112
|
+
accessByMethod: new Map(),
|
|
113
|
+
classAccess: null,
|
|
114
|
+
};
|
|
115
|
+
ACCESS_BY_RESOLVER.set(resolverClass, registration);
|
|
116
|
+
return registration;
|
|
117
|
+
}
|
|
118
|
+
function readPrototype(resolverClass) {
|
|
119
|
+
const prototype = resolverClass
|
|
120
|
+
.prototype;
|
|
121
|
+
return typeof prototype === 'object' && prototype !== null
|
|
122
|
+
? prototype
|
|
123
|
+
: null;
|
|
124
|
+
}
|
|
125
|
+
function readResolverName(resolverClass) {
|
|
126
|
+
const name = resolverClass.name;
|
|
127
|
+
return typeof name === 'string' ? name : '';
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The GraphQL handlers on a resolver prototype and everything it inherits.
|
|
131
|
+
*
|
|
132
|
+
* Two things this must not do. It must not list a plain helper method: a host
|
|
133
|
+
* builds its permission map from `listBPMResolverHandlers()`, and a private
|
|
134
|
+
* helper would show up there as a GraphQL field that does not exist. And it
|
|
135
|
+
* must not stop at the class's own prototype: a handler inherited from a base
|
|
136
|
+
* resolver would then get no metadata at all, which a host sees only as an
|
|
137
|
+
* unexplained 403.
|
|
138
|
+
*
|
|
139
|
+
* `@Query` / `@Mutation` / `@ResolveField` each stamp
|
|
140
|
+
* `RESOLVER_TYPE_METADATA` on the method, so that is the test.
|
|
141
|
+
*/
|
|
142
|
+
function listHandlerMethodNames(prototype) {
|
|
143
|
+
const methodNames = new Set();
|
|
144
|
+
for (let current = prototype; current !== null && current !== Object.prototype; current = Object.getPrototypeOf(current)) {
|
|
145
|
+
for (const methodName of Object.getOwnPropertyNames(current)) {
|
|
146
|
+
if (methodName === 'constructor') {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const member = current[methodName];
|
|
150
|
+
if (typeof member === 'function' &&
|
|
151
|
+
Reflect.getMetadata(graphql_1.RESOLVER_TYPE_METADATA, member) !== undefined) {
|
|
152
|
+
methodNames.add(methodName);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return [...methodNames];
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=bpm-resolver-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bpm-resolver-metadata.js","sourceRoot":"","sources":["../../../../../../libs/bpm-core/src/lib/bpm-auth/bpm-resolver-metadata.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AAoDH,wEAKC;AAOD,0EAMC;AAUD,4DA2CC;AAOD,0DA4BC;AA5JD,6CAAyD;AAEzD,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAyC,CAAC;AA4C5E;;;GAGG;AACH,SAAgB,8BAA8B,CAC5C,aAAqB,EACrB,MAA8B;IAE9B,gBAAgB,CAAC,aAAa,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC;AACvD,CAAC;AAED;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,aAAqB,EACrB,UAAkB,EAClB,MAA8B;IAE9B,gBAAgB,CAAC,aAAa,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,wBAAwB,CACtC,OAAmC;IAEnC,KAAK,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,kBAAkB,EAAE,CAAC;QAC/D,MAAM,SAAS,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;QAE/C,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,SAAS;QACX,CAAC;QAED,KAAK,MAAM,UAAU,IAAI,sBAAsB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3D,MAAM,MAAM,GACV,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC;gBAC3C,YAAY,CAAC,WAAW,CAAC;YAE3B,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC5C,SAAS;YACX,CAAC;YAED,MAAM,QAAQ,GAAG,OAAO,CAAC;gBACvB,MAAM;gBACN,UAAU;gBACV,YAAY,EAAE,gBAAgB,CAAC,aAAa,CAAC;aAC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AC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -7,4 +7,6 @@ tslib_1.__exportStar(require("./bpm-auth.decorators"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./bpm-auth.guard"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./bpm-auth.module"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./bpm-auth.options"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./bpm-resolver-access.decorator"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./bpm-resolver-metadata"), exports);
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/bpm-core/src/lib/bpm-auth/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,mEAAyC;AACzC,gEAAsC;AACtC,2DAAiC;AACjC,4DAAkC;AAClC,6DAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/bpm-core/src/lib/bpm-auth/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,mEAAyC;AACzC,gEAAsC;AACtC,2DAAiC;AACjC,4DAAkC;AAClC,6DAAmC;AACnC,0EAAgD;AAChD,kEAAwC"}
|
|
@@ -3,9 +3,52 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConditionService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
|
|
6
|
+
let celEngine = null;
|
|
7
|
+
/**
|
|
8
|
+
* Loads `cel-js` on first use rather than when this module is imported.
|
|
9
|
+
*
|
|
10
|
+
* `cel-js` is ESM-only and its `chevrotain` dependency ships an exports map
|
|
11
|
+
* that `jest-resolve` cannot follow. While the import sat at the top of this
|
|
12
|
+
* file, the package root pulled it in through
|
|
13
|
+
* `index → bpm-root → delegation → condition`, so *any* consumer test that
|
|
14
|
+
* imported anything from `@rytass/bpm-core-nestjs-module` failed to load with
|
|
15
|
+
* `Cannot find module 'chevrotain'` — pointing deep into `node_modules`, far
|
|
16
|
+
* from the code under test. Hosts had to stub `cel-js` before they could write
|
|
17
|
+
* a single test.
|
|
18
|
+
*
|
|
19
|
+
* Deferring the load means a host that never evaluates a CEL expression never
|
|
20
|
+
* resolves the package at all. `require` (not `await import`) keeps every
|
|
21
|
+
* caller in this file synchronous.
|
|
22
|
+
*/
|
|
23
|
+
function loadCelEngine() {
|
|
24
|
+
if (celEngine === null) {
|
|
25
|
+
try {
|
|
26
|
+
celEngine = require('cel-js');
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// Deferring the load also defers this failure: it used to surface at
|
|
30
|
+
// boot as a bare ERR_REQUIRE_ESM, and would now surface as a 500 on
|
|
31
|
+
// whichever request first evaluated a condition. Name the cause where it
|
|
32
|
+
// is thrown.
|
|
33
|
+
if (isRequireEsmError(error)) {
|
|
34
|
+
throw new Error(`[@rytass/bpm-core-nestjs-module] This Node version cannot require the ESM-only 'cel-js'. BPM needs Node >=20.19 or >=22.12 to evaluate CEL conditions. Original error: ${error instanceof Error ? error.message : String(error)}`);
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return celEngine;
|
|
40
|
+
}
|
|
41
|
+
function isRequireEsmError(error) {
|
|
42
|
+
return (typeof error === 'object' &&
|
|
43
|
+
error !== null &&
|
|
44
|
+
'code' in error &&
|
|
45
|
+
error.code === 'ERR_REQUIRE_ESM');
|
|
46
|
+
}
|
|
7
47
|
const DEFAULT_MAX_EXPRESSION_LENGTH = 2000;
|
|
8
|
-
|
|
48
|
+
// `has` and `size` are CEL macros, not context identifiers; the root-identifier
|
|
49
|
+
// lint must not report them as unknown. `size` is required by the table field
|
|
50
|
+
// IS_FILLED / IS_EMPTY expressions (ADR 16 §3.8).
|
|
51
|
+
const CEL_KEYWORDS = new Set(['false', 'has', 'in', 'null', 'size', 'true']);
|
|
9
52
|
let ConditionService = class ConditionService {
|
|
10
53
|
lintExpressions(expressions, options = {}) {
|
|
11
54
|
return expressions.flatMap(({ expression, label }) => this.lintExpression(expression, label, options));
|
|
@@ -22,7 +65,7 @@ let ConditionService = class ConditionService {
|
|
|
22
65
|
if (trimmedExpression.length > maxExpressionLength) {
|
|
23
66
|
return [`${label} must be ${maxExpressionLength} characters or fewer`];
|
|
24
67
|
}
|
|
25
|
-
const parseResult = (
|
|
68
|
+
const parseResult = loadCelEngine().parse(trimmedExpression);
|
|
26
69
|
if (isParseFailure(parseResult)) {
|
|
27
70
|
return parseResult.errors.map((error) => `${label}: ${error}`);
|
|
28
71
|
}
|
|
@@ -44,12 +87,13 @@ let ConditionService = class ConditionService {
|
|
|
44
87
|
if (lengthErrors.length) {
|
|
45
88
|
throw new common_1.BadRequestException(lengthErrors.join('; '));
|
|
46
89
|
}
|
|
47
|
-
const
|
|
90
|
+
const engine = loadCelEngine();
|
|
91
|
+
const parseResult = engine.parse(trimmedExpression);
|
|
48
92
|
if (isParseFailure(parseResult)) {
|
|
49
93
|
throw new common_1.BadRequestException(parseResult.errors.map((error) => `${label}: ${error}`).join('; '));
|
|
50
94
|
}
|
|
51
95
|
try {
|
|
52
|
-
return
|
|
96
|
+
return engine.evaluate(parseResult.cst, { ...context });
|
|
53
97
|
}
|
|
54
98
|
catch (error) {
|
|
55
99
|
throw new common_1.BadRequestException(error instanceof Error ? `${label}: ${error.message}` : label);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.service.js","sourceRoot":"","sources":["../../../../../../libs/bpm-core/src/lib/condition/condition.service.ts"],"names":[],"mappings":";;;;AAAA,2CAAiE;
|
|
1
|
+
{"version":3,"file":"condition.service.js","sourceRoot":"","sources":["../../../../../../libs/bpm-core/src/lib/cond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