@wildo-ai/saas-minions-lib 1.1.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.
Files changed (47) hide show
  1. package/LICENSE +34 -0
  2. package/dist/esm/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.d.ts +22 -0
  3. package/dist/esm/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.d.ts.map +1 -0
  4. package/dist/esm/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.js +234 -0
  5. package/dist/esm/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.js.map +1 -0
  6. package/dist/esm/index.d.ts +9 -0
  7. package/dist/esm/index.d.ts.map +1 -0
  8. package/dist/esm/index.js +9 -0
  9. package/dist/esm/index.js.map +1 -0
  10. package/dist/esm/inject/models/container.d.ts +7 -0
  11. package/dist/esm/inject/models/container.d.ts.map +1 -0
  12. package/dist/esm/inject/models/container.js +55 -0
  13. package/dist/esm/inject/models/container.js.map +1 -0
  14. package/dist/esm/inject/models/service-types.d.ts +7 -0
  15. package/dist/esm/inject/models/service-types.d.ts.map +1 -0
  16. package/dist/esm/inject/models/service-types.js +6 -0
  17. package/dist/esm/inject/models/service-types.js.map +1 -0
  18. package/dist/esm/runtime/queue/minion-tick-consumer.backend.service.d.ts +47 -0
  19. package/dist/esm/runtime/queue/minion-tick-consumer.backend.service.d.ts.map +1 -0
  20. package/dist/esm/runtime/queue/minion-tick-consumer.backend.service.js +157 -0
  21. package/dist/esm/runtime/queue/minion-tick-consumer.backend.service.js.map +1 -0
  22. package/dist/esm/runtime/services/define-minion-init.d.ts +98 -0
  23. package/dist/esm/runtime/services/define-minion-init.d.ts.map +1 -0
  24. package/dist/esm/runtime/services/define-minion-init.js +4 -0
  25. package/dist/esm/runtime/services/define-minion-init.js.map +1 -0
  26. package/dist/esm/runtime/services/own-schedule-reader.backend.service.d.ts +75 -0
  27. package/dist/esm/runtime/services/own-schedule-reader.backend.service.d.ts.map +1 -0
  28. package/dist/esm/runtime/services/own-schedule-reader.backend.service.js +124 -0
  29. package/dist/esm/runtime/services/own-schedule-reader.backend.service.js.map +1 -0
  30. package/dist/esm/runtime/services/start-minion-application.backend.service.d.ts +48 -0
  31. package/dist/esm/runtime/services/start-minion-application.backend.service.d.ts.map +1 -0
  32. package/dist/esm/runtime/services/start-minion-application.backend.service.js +304 -0
  33. package/dist/esm/runtime/services/start-minion-application.backend.service.js.map +1 -0
  34. package/dist/tsconfig.build.tsbuildinfo +1 -0
  35. package/package.json +56 -0
  36. package/src/base-classes/services/services/__tests__/minion-scoped-services-registry-handler.backend.service.test.ts +252 -0
  37. package/src/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.ts +337 -0
  38. package/src/index.ts +11 -0
  39. package/src/inject/models/__tests__/container.test.ts +30 -0
  40. package/src/inject/models/container.ts +68 -0
  41. package/src/inject/models/service-types.ts +11 -0
  42. package/src/runtime/queue/minion-tick-consumer.backend.service.ts +181 -0
  43. package/src/runtime/services/__tests__/own-schedule-reader.backend.service.test.ts +118 -0
  44. package/src/runtime/services/__tests__/start-minion-application.backend.service.test.ts +422 -0
  45. package/src/runtime/services/define-minion-init.ts +113 -0
  46. package/src/runtime/services/own-schedule-reader.backend.service.ts +146 -0
  47. package/src/runtime/services/start-minion-application.backend.service.ts +398 -0
package/LICENSE ADDED
@@ -0,0 +1,34 @@
1
+ Copyright (c) 2026 P2C Consulting, s.à r.l.-S
2
+ RCS Luxembourg B307591
3
+ 6C, Porte de France, L-4360 Esch-sur-Alzette, Luxembourg
4
+
5
+ All rights reserved.
6
+
7
+ This software and its accompanying materials (the "Software") are the
8
+ confidential and proprietary property of P2C Consulting, s.à r.l.-S (the
9
+ "Licensor"). The Software is made available for viewing only. No licence,
10
+ right, or permission of any kind is granted by its publication or by its
11
+ availability on any package registry or source repository.
12
+
13
+ Without the Licensor's prior written permission, you may not use, copy,
14
+ reproduce, modify, adapt, translate, merge, publish, distribute, sublicense,
15
+ sell, host, or create derivative works of the Software, in whole or in part,
16
+ nor use it to provide a service to any third party.
17
+
18
+ Publication of the Software in any public registry is for distribution to
19
+ authorised recipients and for technical evaluation of its packaging only. It
20
+ does not place the Software in the public domain, does not constitute an open
21
+ source release, and does not waive any right of the Licensor.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ LICENSOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+
30
+ Third-party components distributed with the Software remain governed by their
31
+ own licences.
32
+
33
+ Contact: P2C Consulting, s.à r.l.-S, 6C, Porte de France, L-4360
34
+ Esch-sur-Alzette, Luxembourg.
@@ -0,0 +1,22 @@
1
+ import type { AppConfiguration, ServicesRegistryHandlerBackendService } from '@wildo-ai/saas-backend-lib';
2
+ type MinionResourceAccessConfig = NonNullable<NonNullable<AppConfiguration['minions']>[string]['resourceAccess']>;
3
+ export declare class MinionScopedServicesRegistryHandlerBackendService {
4
+ private readonly baseRegistry;
5
+ private readonly minionName;
6
+ private readonly readAllowlist;
7
+ private readonly writeAllowlist;
8
+ private readonly serviceProxyCache;
9
+ constructor(baseRegistry: ServicesRegistryHandlerBackendService, minionName: string, resourceAccess: MinionResourceAccessConfig | undefined);
10
+ asDecoratedRegistry(): ServicesRegistryHandlerBackendService;
11
+ private getService;
12
+ private getServiceOrThrow;
13
+ private doByOperationPath;
14
+ private doByExecutionContext;
15
+ private wrapRegistryMethod;
16
+ private wrapService;
17
+ private assertAllowedForOperationPath;
18
+ private resolveAccessMode;
19
+ private assertAllowed;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=minion-scoped-services-registry-handler.backend.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minion-scoped-services-registry-handler.backend.service.d.ts","sourceRoot":"","sources":["../../../../../../src/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,gBAAgB,EAEhB,qCAAqC,EACtC,MAAM,4BAA4B,CAAC;AAEpC,KAAK,0BAA0B,GAAG,WAAW,CAC3C,WAAW,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CACnE,CAAC;AAgFF,qBAAa,iDAAiD;IAM1D,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAN7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAc;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA8B;gBAG7C,YAAY,EAAE,qCAAqC,EACnD,UAAU,EAAE,MAAM,EACnC,cAAc,EAAE,0BAA0B,GAAG,SAAS;IAMjD,mBAAmB,IAAI,qCAAqC;IAiDnE,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,iBAAiB;YAKX,iBAAiB;YAiBjB,oBAAoB;IAelC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,WAAW;IAuFnB,OAAO,CAAC,6BAA6B;IAUrC,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,aAAa;CAatB"}
@@ -0,0 +1,234 @@
1
+ import { ResourceAccessForbiddenError, ResourceAccessMode, } from '@wildo-ai/saas-models';
2
+ /**
3
+ * Read-side operation identifiers. Anything in this set is classified
4
+ * as a READ; anything else falls through to the path-aware classifiers
5
+ * via `doByOperationPath` / `doByExecutionContext` rather than being
6
+ * silently labelled WRITE (M4 fix). Custom operations and relationship
7
+ * actions in particular cannot be classified by name — they MUST go
8
+ * through `doByOperationPath` so the operation's own metadata drives
9
+ * the access-mode decision.
10
+ */
11
+ const READ_OPERATION_IDENTIFIERS = new Set([
12
+ 'READ',
13
+ 'LIST',
14
+ 'SEARCH',
15
+ 'COUNT',
16
+ // EXPORT serializes data outward; it's a read in v1. Listed explicitly
17
+ // so a future EXPORT introduction does not silently classify as WRITE.
18
+ 'EXPORT',
19
+ ]);
20
+ const READ_SERVICE_METHODS = new Set([
21
+ 'read',
22
+ // NOTE: `readAsSystem`/`listAsSystem` (ACL-bypassing system reads) deliberately
23
+ // do NOT appear here — they were moved off the services registry handler onto the
24
+ // dedicated `SystemAccessService` (Guard 3), which minion code is not granted. The
25
+ // handler this proxy wraps no longer exposes a system-read at all.
26
+ 'list',
27
+ 'search',
28
+ 'count',
29
+ ]);
30
+ /**
31
+ * Service methods classified as unconditional writes by name. The first
32
+ * group are unambiguous CRUD writes; the polymorphic methods at the end
33
+ * are listed conservatively as WRITE because their name alone does not
34
+ * carry the operation's read/write intent. Worker code that needs read
35
+ * semantics for a custom op or relationship action MUST go through
36
+ * `doByOperationPath` so the operation's own metadata drives the
37
+ * access-mode decision (see `resolveAccessMode`).
38
+ */
39
+ const WRITE_SERVICE_METHODS = new Set([
40
+ 'create',
41
+ 'createMany',
42
+ 'update',
43
+ 'updateMany',
44
+ 'delete',
45
+ 'deleteMany',
46
+ 'executeCustomOperation',
47
+ 'applyRelationshipActionMany',
48
+ ]);
49
+ /**
50
+ * Per KD-11.A: the proxy is fail-CLOSED. A property name not in any of
51
+ * the four sets above and not listed here is denied — minion code must
52
+ * route through the chokepoints (`doByOperationPath`,
53
+ * `doByExecutionContext`, `getService`, `getServiceOrThrow`) so the
54
+ * resourceAccess whitelist applies.
55
+ *
56
+ * Symbol-keyed properties (e.g. `Symbol.toStringTag` for runtime
57
+ * stringification) and a small number of harmless meta-properties are
58
+ * allow-listed because denying them would break basic JS semantics
59
+ * (`typeof`, `instanceof`, error formatting) without security value.
60
+ */
61
+ const ALLOW_THROUGH_REGISTRY_PROPERTIES = new Set([
62
+ 'getService',
63
+ 'getServiceOrThrow',
64
+ 'doByOperationPath',
65
+ 'doByExecutionContext',
66
+ 'constructor',
67
+ 'then', // present so Promise resolution doesn't trip when this proxy is awaited by accident
68
+ ]);
69
+ const ALLOW_THROUGH_SERVICE_PROPERTIES = new Set([
70
+ 'doByOperationPath',
71
+ 'doByExecutionContext',
72
+ 'constructor',
73
+ 'then',
74
+ ]);
75
+ export class MinionScopedServicesRegistryHandlerBackendService {
76
+ baseRegistry;
77
+ minionName;
78
+ readAllowlist;
79
+ writeAllowlist;
80
+ serviceProxyCache = new Map();
81
+ constructor(baseRegistry, minionName, resourceAccess) {
82
+ this.baseRegistry = baseRegistry;
83
+ this.minionName = minionName;
84
+ this.readAllowlist = new Set(resourceAccess?.read ?? []);
85
+ this.writeAllowlist = new Set(resourceAccess?.write ?? []);
86
+ }
87
+ asDecoratedRegistry() {
88
+ return new Proxy(this.baseRegistry, {
89
+ get: (_target, property) => {
90
+ if (property === 'getService') {
91
+ return this.getService.bind(this);
92
+ }
93
+ if (property === 'getServiceOrThrow') {
94
+ return this.getServiceOrThrow.bind(this);
95
+ }
96
+ if (property === 'doByOperationPath') {
97
+ return this.doByOperationPath.bind(this);
98
+ }
99
+ if (property === 'doByExecutionContext') {
100
+ return this.doByExecutionContext.bind(this);
101
+ }
102
+ if (typeof property === 'string' && READ_SERVICE_METHODS.has(property)) {
103
+ return this.wrapRegistryMethod(property, ResourceAccessMode.READ);
104
+ }
105
+ if (typeof property === 'string' && WRITE_SERVICE_METHODS.has(property)) {
106
+ return this.wrapRegistryMethod(property, ResourceAccessMode.WRITE);
107
+ }
108
+ // Symbol-keyed properties pass through (Symbol.toStringTag,
109
+ // Symbol.toPrimitive, etc.) — they have no security relevance
110
+ // and denying them breaks basic JS reflection.
111
+ if (typeof property === 'symbol') {
112
+ const value = this.baseRegistry[property];
113
+ return typeof value === 'function' ? value.bind(this.baseRegistry) : value;
114
+ }
115
+ // M3 fix — fail-CLOSED for unknown property names. Only the
116
+ // explicit allow-list above and `ALLOW_THROUGH_REGISTRY_PROPERTIES`
117
+ // expose the underlying registry; everything else throws so a
118
+ // future method on `ServicesRegistryHandlerBackendService`
119
+ // cannot silently bypass the resourceAccess whitelist.
120
+ if (typeof property === 'string' && ALLOW_THROUGH_REGISTRY_PROPERTIES.has(property)) {
121
+ const value = this.baseRegistry[property];
122
+ return typeof value === 'function' ? value.bind(this.baseRegistry) : value;
123
+ }
124
+ throw new ResourceAccessForbiddenError({
125
+ minionName: this.minionName,
126
+ resourceType: '<unscoped-registry-access>',
127
+ accessMode: ResourceAccessMode.WRITE,
128
+ });
129
+ },
130
+ });
131
+ }
132
+ getService(resourceType) {
133
+ const service = this.baseRegistry.getService(resourceType);
134
+ if (!service) {
135
+ return undefined;
136
+ }
137
+ return this.wrapService(resourceType, service);
138
+ }
139
+ getServiceOrThrow(resourceType) {
140
+ const service = this.baseRegistry.getServiceOrThrow(resourceType);
141
+ return this.wrapService(resourceType, service);
142
+ }
143
+ async doByOperationPath(operationPath, executionContext, idOrIdsOrFilter, data, options) {
144
+ this.assertAllowedForOperationPath(operationPath);
145
+ return this.baseRegistry.doByOperationPath(operationPath, executionContext, idOrIdsOrFilter, data, options);
146
+ }
147
+ async doByExecutionContext(executionContext, data, options) {
148
+ this.assertAllowed(executionContext.operation.resourceIdentifier, this.resolveAccessMode(executionContext.operation.resourceOperationLike, executionContext.operation.operationIdentifier));
149
+ return this.baseRegistry.doByExecutionContext(executionContext, data, options);
150
+ }
151
+ wrapRegistryMethod(methodName, accessMode) {
152
+ return async (...args) => {
153
+ const [resourceType] = args;
154
+ this.assertAllowed(resourceType, accessMode);
155
+ return this.baseRegistry[methodName].apply(this.baseRegistry, args);
156
+ };
157
+ }
158
+ wrapService(resourceType, service) {
159
+ if (this.serviceProxyCache.has(resourceType)) {
160
+ return this.serviceProxyCache.get(resourceType);
161
+ }
162
+ const wrapped = new Proxy(service, {
163
+ get: (_target, property) => {
164
+ if (property === 'doByOperationPath') {
165
+ return async (operationPath, executionContext, idOrIdsOrFilter, data, options) => {
166
+ this.assertAllowedForOperationPath(operationPath);
167
+ return service.doByOperationPath.call(service, operationPath, executionContext, idOrIdsOrFilter, data, options);
168
+ };
169
+ }
170
+ if (property === 'doByExecutionContext') {
171
+ return async (executionContext, data, options) => {
172
+ this.assertAllowed(resourceType, this.resolveAccessMode(executionContext.operation.resourceOperationLike, executionContext.operation.operationIdentifier));
173
+ return service.doByExecutionContext.call(service, executionContext, data, options);
174
+ };
175
+ }
176
+ if (typeof property === 'string' && READ_SERVICE_METHODS.has(property)) {
177
+ return async (...args) => {
178
+ this.assertAllowed(resourceType, ResourceAccessMode.READ);
179
+ return service[property].apply(service, args);
180
+ };
181
+ }
182
+ if (typeof property === 'string' && WRITE_SERVICE_METHODS.has(property)) {
183
+ return async (...args) => {
184
+ this.assertAllowed(resourceType, ResourceAccessMode.WRITE);
185
+ return service[property].apply(service, args);
186
+ };
187
+ }
188
+ // Symbol-keyed properties pass through (Symbol.toStringTag etc.).
189
+ if (typeof property === 'symbol') {
190
+ const value = service[property];
191
+ return typeof value === 'function' ? value.bind(service) : value;
192
+ }
193
+ // M3 fix — fail-CLOSED. Only allow-listed property names + the
194
+ // explicit method classifications above expose the underlying
195
+ // service. Everything else throws so a future method on the
196
+ // service cannot bypass the whitelist.
197
+ if (typeof property === 'string' && ALLOW_THROUGH_SERVICE_PROPERTIES.has(property)) {
198
+ const value = service[property];
199
+ return typeof value === 'function' ? value.bind(service) : value;
200
+ }
201
+ throw new ResourceAccessForbiddenError({
202
+ minionName: this.minionName,
203
+ resourceType,
204
+ accessMode: ResourceAccessMode.WRITE,
205
+ });
206
+ },
207
+ });
208
+ this.serviceProxyCache.set(resourceType, wrapped);
209
+ return wrapped;
210
+ }
211
+ assertAllowedForOperationPath(operationPath) {
212
+ this.assertAllowed(operationPath.resourceIdentifier, this.resolveAccessMode(operationPath.resourceOperationLike, operationPath.operationIdentifier));
213
+ }
214
+ resolveAccessMode(resourceOperationLike, operationIdentifier) {
215
+ const effectiveOperation = resourceOperationLike ?? operationIdentifier;
216
+ return READ_OPERATION_IDENTIFIERS.has(effectiveOperation)
217
+ ? ResourceAccessMode.READ
218
+ : ResourceAccessMode.WRITE;
219
+ }
220
+ assertAllowed(resourceType, accessMode) {
221
+ const allowlist = accessMode === ResourceAccessMode.READ
222
+ ? this.readAllowlist
223
+ : this.writeAllowlist;
224
+ if (allowlist.has('*') || allowlist.has(resourceType)) {
225
+ return;
226
+ }
227
+ throw new ResourceAccessForbiddenError({
228
+ minionName: this.minionName,
229
+ resourceType,
230
+ accessMode,
231
+ });
232
+ }
233
+ }
234
+ //# sourceMappingURL=minion-scoped-services-registry-handler.backend.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minion-scoped-services-registry-handler.backend.service.js","sourceRoot":"","sources":["../../../../../../src/base-classes/services/services/minion-scoped-services-registry-handler.backend.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAW/B;;;;;;;;GAQG;AACH,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAS;IACjD,MAAM;IACN,MAAM;IACN,QAAQ;IACR,OAAO;IACP,uEAAuE;IACvE,uEAAuE;IACvE,QAAQ;CACT,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,MAAM;IACN,gFAAgF;IAChF,kFAAkF;IAClF,mFAAmF;IACnF,mEAAmE;IACnE,MAAM;IACN,QAAQ;IACR,OAAO;CACR,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,wBAAwB;IACxB,6BAA6B;CAC9B,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG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AAS,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACtD,OAAO;QACT,CAAC;QACD,MAAM,IAAI,4BAA4B,CAAC;YACrC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,YAAY;YACZ,UAAU;SACX,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n ResourceConfiguration_OperationPath,\n ResourceType,\n ResourceAccessForbiddenError,\n ResourceAccessMode,\n} from '@wildo-ai/saas-models';\nimport type {\n AppConfiguration,\n ExecutionContext,\n ServicesRegistryHandlerBackendService,\n} from '@wildo-ai/saas-backend-lib';\n\ntype MinionResourceAccessConfig = NonNullable<\n NonNullable<AppConfiguration['minions']>[string]['resourceAccess']\n>;\n\n/**\n * Read-side operation identifiers. Anything in this set is classified\n * as a READ; anything else falls through to the path-aware classifiers\n * via `doByOperationPath` / `doByExecutionContext` rather than being\n * silently labelled WRITE (M4 fix). Custom operations and relationship\n * actions in particular cannot be classified by name — they MUST go\n * through `doByOperationPath` so the operation's own metadata drives\n * the access-mode decision.\n */\nconst READ_OPERATION_IDENTIFIERS = new Set<string>([\n 'READ',\n 'LIST',\n 'SEARCH',\n 'COUNT',\n // EXPORT serializes data outward; it's a read in v1. Listed explicitly\n // so a future EXPORT introduction does not silently classify as WRITE.\n 'EXPORT',\n]);\n\nconst READ_SERVICE_METHODS = new Set([\n 'read',\n // NOTE: `readAsSystem`/`listAsSystem` (ACL-bypassing system reads) deliberately\n // do NOT appear here — they were moved off the services registry handler onto the\n // dedicated `SystemAccessService` (Guard 3), which minion code is not granted. The\n // handler this proxy wraps no longer exposes a system-read at all.\n 'list',\n 'search',\n 'count',\n]);\n\n/**\n * Service methods classified as unconditional writes by name. The first\n * group are unambiguous CRUD writes; the polymorphic methods at the end\n * are listed conservatively as WRITE because their name alone does not\n * carry the operation's read/write intent. Worker code that needs read\n * semantics for a custom op or relationship action MUST go through\n * `doByOperationPath` so the operation's own metadata drives the\n * access-mode decision (see `resolveAccessMode`).\n */\nconst WRITE_SERVICE_METHODS = new Set([\n 'create',\n 'createMany',\n 'update',\n 'updateMany',\n 'delete',\n 'deleteMany',\n 'executeCustomOperation',\n 'applyRelationshipActionMany',\n]);\n\n/**\n * Per KD-11.A: the proxy is fail-CLOSED. A property name not in any of\n * the four sets above and not listed here is denied — minion code must\n * route through the chokepoints (`doByOperationPath`,\n * `doByExecutionContext`, `getService`, `getServiceOrThrow`) so the\n * resourceAccess whitelist applies.\n *\n * Symbol-keyed properties (e.g. `Symbol.toStringTag` for runtime\n * stringification) and a small number of harmless meta-properties are\n * allow-listed because denying them would break basic JS semantics\n * (`typeof`, `instanceof`, error formatting) without security value.\n */\nconst ALLOW_THROUGH_REGISTRY_PROPERTIES = new Set<string>([\n 'getService',\n 'getServiceOrThrow',\n 'doByOperationPath',\n 'doByExecutionContext',\n 'constructor',\n 'then', // present so Promise resolution doesn't trip when this proxy is awaited by accident\n]);\n\nconst ALLOW_THROUGH_SERVICE_PROPERTIES = new Set<string>([\n 'doByOperationPath',\n 'doByExecutionContext',\n 'constructor',\n 'then',\n]);\n\nexport class MinionScopedServicesRegistryHandlerBackendService {\n private readonly readAllowlist: Set<string>;\n private readonly writeAllowlist: Set<string>;\n private readonly serviceProxyCache = new Map<string, unknown>();\n\n constructor(\n private readonly baseRegistry: ServicesRegistryHandlerBackendService,\n private readonly minionName: string,\n resourceAccess: MinionResourceAccessConfig | undefined,\n ) {\n this.readAllowlist = new Set(resourceAccess?.read ?? []);\n this.writeAllowlist = new Set(resourceAccess?.write ?? []);\n }\n\n public asDecoratedRegistry(): ServicesRegistryHandlerBackendService {\n return new Proxy(this.baseRegistry, {\n get: (_target, property) => {\n if (property === 'getService') {\n return this.getService.bind(this);\n }\n if (property === 'getServiceOrThrow') {\n return this.getServiceOrThrow.bind(this);\n }\n if (property === 'doByOperationPath') {\n return this.doByOperationPath.bind(this);\n }\n if (property === 'doByExecutionContext') {\n return this.doByExecutionContext.bind(this);\n }\n if (typeof property === 'string' && READ_SERVICE_METHODS.has(property)) {\n return this.wrapRegistryMethod(property, ResourceAccessMode.READ);\n }\n if (typeof property === 'string' && WRITE_SERVICE_METHODS.has(property)) {\n return this.wrapRegistryMethod(property, ResourceAccessMode.WRITE);\n }\n\n // Symbol-keyed properties pass through (Symbol.toStringTag,\n // Symbol.toPrimitive, etc.) — they have no security relevance\n // and denying them breaks basic JS reflection.\n if (typeof property === 'symbol') {\n const value = (this.baseRegistry as unknown as Record<PropertyKey, unknown>)[property as unknown as string];\n return typeof value === 'function' ? value.bind(this.baseRegistry) : value;\n }\n\n // M3 fix — fail-CLOSED for unknown property names. Only the\n // explicit allow-list above and `ALLOW_THROUGH_REGISTRY_PROPERTIES`\n // expose the underlying registry; everything else throws so a\n // future method on `ServicesRegistryHandlerBackendService`\n // cannot silently bypass the resourceAccess whitelist.\n if (typeof property === 'string' && ALLOW_THROUGH_REGISTRY_PROPERTIES.has(property)) {\n const value = (this.baseRegistry as unknown as Record<PropertyKey, unknown>)[property];\n return typeof value === 'function' ? value.bind(this.baseRegistry) : value;\n }\n\n throw new ResourceAccessForbiddenError({\n minionName: this.minionName,\n resourceType: '<unscoped-registry-access>' as ResourceType,\n accessMode: ResourceAccessMode.WRITE,\n });\n },\n }) as ServicesRegistryHandlerBackendService;\n }\n\n private getService(resourceType: ResourceType): unknown {\n const service = this.baseRegistry.getService(resourceType);\n if (!service) {\n return undefined;\n }\n return this.wrapService(resourceType, service as unknown as Record<string, unknown>);\n }\n\n private getServiceOrThrow(resourceType: ResourceType): unknown {\n const service = this.baseRegistry.getServiceOrThrow(resourceType);\n return this.wrapService(resourceType, service as unknown as Record<string, unknown>);\n }\n\n private async doByOperationPath<T = unknown>(\n operationPath: ResourceConfiguration_OperationPath<any, any>,\n executionContext: ExecutionContext<any>,\n idOrIdsOrFilter?: unknown,\n data?: unknown,\n options?: unknown,\n ): Promise<T> {\n this.assertAllowedForOperationPath(operationPath);\n return this.baseRegistry.doByOperationPath(\n operationPath,\n executionContext,\n idOrIdsOrFilter,\n data,\n options,\n ) as Promise<T>;\n }\n\n private async doByExecutionContext<T = unknown>(\n executionContext: ExecutionContext<any>,\n data?: unknown,\n options?: unknown,\n ): Promise<T> {\n this.assertAllowed(\n executionContext.operation.resourceIdentifier as ResourceType,\n this.resolveAccessMode(\n executionContext.operation.resourceOperationLike as string | undefined,\n executionContext.operation.operationIdentifier as string,\n ),\n );\n return this.baseRegistry.doByExecutionContext(executionContext, data, options) as Promise<T>;\n }\n\n private wrapRegistryMethod(\n methodName: string,\n accessMode: ResourceAccessMode,\n ): (...args: unknown[]) => unknown {\n return async (...args: unknown[]) => {\n const [resourceType] = args;\n this.assertAllowed(resourceType as ResourceType, accessMode);\n return ((this.baseRegistry as unknown as Record<string, unknown>)[methodName] as (...callArgs: unknown[]) => unknown).apply(\n this.baseRegistry,\n args,\n );\n };\n }\n\n private wrapService(resourceType: ResourceType, service: Record<string, unknown>): unknown {\n if (this.serviceProxyCache.has(resourceType)) {\n return this.serviceProxyCache.get(resourceType);\n }\n\n const wrapped = new Proxy(service, {\n get: (_target, property) => {\n if (property === 'doByOperationPath') {\n return async (\n operationPath: ResourceConfiguration_OperationPath<any, any>,\n executionContext: ExecutionContext<any>,\n idOrIdsOrFilter?: unknown,\n data?: unknown,\n options?: unknown,\n ) => {\n this.assertAllowedForOperationPath(operationPath);\n return (service.doByOperationPath as (...args: unknown[]) => unknown).call(\n service,\n operationPath,\n executionContext,\n idOrIdsOrFilter,\n data,\n options,\n );\n };\n }\n if (property === 'doByExecutionContext') {\n return async (\n executionContext: ExecutionContext<any>,\n data?: unknown,\n options?: unknown,\n ) => {\n this.assertAllowed(\n resourceType,\n this.resolveAccessMode(\n executionContext.operation.resourceOperationLike as string | undefined,\n executionContext.operation.operationIdentifier as string,\n ),\n );\n return (service.doByExecutionContext as (...args: unknown[]) => unknown).call(\n service,\n executionContext,\n data,\n options,\n );\n };\n }\n if (typeof property === 'string' && READ_SERVICE_METHODS.has(property)) {\n return async (...args: unknown[]) => {\n this.assertAllowed(resourceType, ResourceAccessMode.READ);\n return (service[property] as (...callArgs: unknown[]) => unknown).apply(service, args);\n };\n }\n if (typeof property === 'string' && WRITE_SERVICE_METHODS.has(property)) {\n return async (...args: unknown[]) => {\n this.assertAllowed(resourceType, ResourceAccessMode.WRITE);\n return (service[property] as (...callArgs: unknown[]) => unknown).apply(service, args);\n };\n }\n\n // Symbol-keyed properties pass through (Symbol.toStringTag etc.).\n if (typeof property === 'symbol') {\n const value = service[property as unknown as keyof typeof service];\n return typeof value === 'function' ? value.bind(service) : value;\n }\n\n // M3 fix — fail-CLOSED. Only allow-listed property names + the\n // explicit method classifications above expose the underlying\n // service. Everything else throws so a future method on the\n // service cannot bypass the whitelist.\n if (typeof property === 'string' && ALLOW_THROUGH_SERVICE_PROPERTIES.has(property)) {\n const value = service[property as keyof typeof service];\n return typeof value === 'function' ? value.bind(service) : value;\n }\n\n throw new ResourceAccessForbiddenError({\n minionName: this.minionName,\n resourceType,\n accessMode: ResourceAccessMode.WRITE,\n });\n },\n });\n\n this.serviceProxyCache.set(resourceType, wrapped);\n return wrapped;\n }\n\n private assertAllowedForOperationPath(operationPath: ResourceConfiguration_OperationPath<any, any>): void {\n this.assertAllowed(\n operationPath.resourceIdentifier as ResourceType,\n this.resolveAccessMode(\n (operationPath as { resourceOperationLike?: string }).resourceOperationLike,\n operationPath.operationIdentifier as string,\n ),\n );\n }\n\n private resolveAccessMode(\n resourceOperationLike: string | undefined,\n operationIdentifier: string,\n ): ResourceAccessMode {\n const effectiveOperation = resourceOperationLike ?? operationIdentifier;\n return READ_OPERATION_IDENTIFIERS.has(effectiveOperation)\n ? ResourceAccessMode.READ\n : ResourceAccessMode.WRITE;\n }\n\n private assertAllowed(resourceType: ResourceType, accessMode: ResourceAccessMode): void {\n const allowlist = accessMode === ResourceAccessMode.READ\n ? this.readAllowlist\n : this.writeAllowlist;\n if (allowlist.has('*') || allowlist.has(resourceType)) {\n return;\n }\n throw new ResourceAccessForbiddenError({\n minionName: this.minionName,\n resourceType,\n accessMode,\n });\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ export * from './inject/models/service-types';
2
+ export * from './inject/models/container';
3
+ export * from './runtime/services/define-minion-init';
4
+ export * from './runtime/services/start-minion-application.backend.service';
5
+ export * from './runtime/queue/minion-tick-consumer.backend.service';
6
+ export * from './base-classes/services/services/minion-scoped-services-registry-handler.backend.service';
7
+ export { projectApplicationInitializationConfigToMinion, type ProjectedMinionInitializationConfig, } from '@wildo-ai/saas-backend-lib';
8
+ export * from './runtime/services/own-schedule-reader.backend.service';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,6DAA6D,CAAC;AAC5E,cAAc,sDAAsD,CAAC;AACrE,cAAc,0FAA0F,CAAC;AACzG,OAAO,EACL,8CAA8C,EAC9C,KAAK,mCAAmC,GACzC,MAAM,4BAA4B,CAAC;AACpC,cAAc,wDAAwD,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './inject/models/service-types.js';
2
+ export * from './inject/models/container.js';
3
+ export * from './runtime/services/define-minion-init.js';
4
+ export * from './runtime/services/start-minion-application.backend.service.js';
5
+ export * from './runtime/queue/minion-tick-consumer.backend.service.js';
6
+ export * from './base-classes/services/services/minion-scoped-services-registry-handler.backend.service.js';
7
+ export { projectApplicationInitializationConfigToMinion, } from '@wildo-ai/saas-backend-lib';
8
+ export * from './runtime/services/own-schedule-reader.backend.service.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uCAAuC,CAAC;AACtD,cAAc,6DAA6D,CAAC;AAC5E,cAAc,sDAAsD,CAAC;AACrE,cAAc,0FAA0F,CAAC;AACzG,OAAO,EACL,8CAA8C,GAE/C,MAAM,4BAA4B,CAAC;AACpC,cAAc,wDAAwD,CAAC","sourcesContent":["export * from './inject/models/service-types';\nexport * from './inject/models/container';\nexport * from './runtime/services/define-minion-init';\nexport * from './runtime/services/start-minion-application.backend.service';\nexport * from './runtime/queue/minion-tick-consumer.backend.service';\nexport * from './base-classes/services/services/minion-scoped-services-registry-handler.backend.service';\nexport {\n projectApplicationInitializationConfigToMinion,\n type ProjectedMinionInitializationConfig,\n} from '@wildo-ai/saas-backend-lib';\nexport * from './runtime/services/own-schedule-reader.backend.service';\n"]}
@@ -0,0 +1,7 @@
1
+ import { type InversifyContainer } from '@wildo-ai/saas-backend-lib';
2
+ type Container = InversifyContainer;
3
+ export declare function setupSaasMinionInjection(existing?: Container): Container;
4
+ export declare function getGlobalMinionsContainer(): Container;
5
+ export declare function resetGlobalMinionsContainer(): void;
6
+ export {};
7
+ //# sourceMappingURL=container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../../../../src/inject/models/container.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,4BAA4B,CAAC;AAMpC,KAAK,SAAS,GAAG,kBAAkB,CAAC;AAmCpC,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAYxE;AAED,wBAAgB,yBAAyB,IAAI,SAAS,CAErD;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAGlD"}
@@ -0,0 +1,55 @@
1
+ import { resetGlobalContainer, SAAS_SERVICE_TYPES, setupSaasBackendInjection, } from '@wildo-ai/saas-backend-lib';
2
+ import { StartMinionApplicationBackendService } from '../../runtime/services/start-minion-application.backend.service.js';
3
+ import { MinionTickConsumerBackendService } from '../../runtime/queue/minion-tick-consumer.backend.service.js';
4
+ import { OwnScheduleReaderBackendService } from '../../runtime/services/own-schedule-reader.backend.service.js';
5
+ import { SAAS_MINIONS_SERVICE_TYPES } from './service-types.js';
6
+ let globalMinionsContainer;
7
+ class SaasMinionsContainer {
8
+ container;
9
+ constructor(container) {
10
+ this.container = container;
11
+ this.bindRuntimeServices();
12
+ }
13
+ getContainer() {
14
+ return this.container;
15
+ }
16
+ bindRuntimeServices() {
17
+ if (!this.container.isBound(SAAS_MINIONS_SERVICE_TYPES.StartMinionApplicationService)) {
18
+ this.container
19
+ .bind(SAAS_MINIONS_SERVICE_TYPES.StartMinionApplicationService)
20
+ .to(StartMinionApplicationBackendService)
21
+ .inSingletonScope();
22
+ }
23
+ if (!this.container.isBound(SAAS_MINIONS_SERVICE_TYPES.MinionTickConsumerService)) {
24
+ this.container
25
+ .bind(SAAS_MINIONS_SERVICE_TYPES.MinionTickConsumerService)
26
+ .to(MinionTickConsumerBackendService)
27
+ .inSingletonScope();
28
+ }
29
+ if (!this.container.isBound(SAAS_MINIONS_SERVICE_TYPES.OwnScheduleReaderService)) {
30
+ this.container
31
+ .bind(SAAS_MINIONS_SERVICE_TYPES.OwnScheduleReaderService)
32
+ .to(OwnScheduleReaderBackendService)
33
+ .inSingletonScope();
34
+ }
35
+ }
36
+ }
37
+ export function setupSaasMinionInjection(existing) {
38
+ const container = existing ?? globalMinionsContainer ?? setupSaasBackendInjection();
39
+ if (existing && !container.isBound(SAAS_SERVICE_TYPES.StartApplicationService)) {
40
+ throw new Error('setupSaasMinionInjection(existing) requires a container that already includes saas-backend-lib bindings.');
41
+ }
42
+ const minionsContainer = new SaasMinionsContainer(container);
43
+ if (!existing) {
44
+ globalMinionsContainer = minionsContainer.getContainer();
45
+ }
46
+ return minionsContainer.getContainer();
47
+ }
48
+ export function getGlobalMinionsContainer() {
49
+ return globalMinionsContainer ?? setupSaasMinionInjection();
50
+ }
51
+ export function resetGlobalMinionsContainer() {
52
+ globalMinionsContainer = undefined;
53
+ resetGlobalContainer();
54
+ }
55
+ //# sourceMappingURL=container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.js","sourceRoot":"","sources":["../../../../../src/inject/models/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACpB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oCAAoC,EAAE,MAAM,iEAAiE,CAAC;AACvH,OAAO,EAAE,gCAAgC,EAAE,MAAM,0DAA0D,CAAC;AAC5G,OAAO,EAAE,+BAA+B,EAAE,MAAM,4DAA4D,CAAC;AAC7G,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAI7D,IAAI,sBAA6C,CAAC;AAElD,MAAM,oBAAoB;IACK;IAA7B,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;QAC/C,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAEM,YAAY;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEO,mBAAmB;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,0BAA0B,CAAC,6BAA6B,CAAC,EAAE,CAAC;YACtF,IAAI,CAAC,SAAS;iBACX,IAAI,CAAC,0BAA0B,CAAC,6BAA6B,CAAC;iBAC9D,EAAE,CAAC,oCAAoC,CAAC;iBACxC,gBAAgB,EAAE,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,CAAC;YAClF,IAAI,CAAC,SAAS;iBACX,IAAI,CAAC,0BAA0B,CAAC,yBAAyB,CAAC;iBAC1D,EAAE,CAAC,gCAAgC,CAAC;iBACpC,gBAAgB,EAAE,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,0BAA0B,CAAC,wBAAwB,CAAC,EAAE,CAAC;YACjF,IAAI,CAAC,SAAS;iBACX,IAAI,CAAC,0BAA0B,CAAC,wBAAwB,CAAC;iBACzD,EAAE,CAAC,+BAA+B,CAAC;iBACnC,gBAAgB,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CAAC,QAAoB;IAC3D,MAAM,SAAS,GAAG,QAAQ,IAAI,sBAAsB,IAAI,yBAAyB,EAAE,CAAC;IACpF,IAAI,QAAQ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAC/E,MAAM,IAAI,KAAK,CACb,0GAA0G,CAC3G,CAAC;IACJ,CAAC;IACD,MAAM,gBAAgB,GAAG,IAAI,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC7D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,sBAAsB,GAAG,gBAAgB,CAAC,YAAY,EAAE,CAAC;IAC3D,CAAC;IACD,OAAO,gBAAgB,CAAC,YAAY,EAAE,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,OAAO,sBAAsB,IAAI,wBAAwB,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,sBAAsB,GAAG,SAAS,CAAC;IACnC,oBAAoB,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n type InversifyContainer,\n resetGlobalContainer,\n SAAS_SERVICE_TYPES,\n setupSaasBackendInjection,\n} from '@wildo-ai/saas-backend-lib';\nimport { StartMinionApplicationBackendService } from '../../runtime/services/start-minion-application.backend.service';\nimport { MinionTickConsumerBackendService } from '../../runtime/queue/minion-tick-consumer.backend.service';\nimport { OwnScheduleReaderBackendService } from '../../runtime/services/own-schedule-reader.backend.service';\nimport { SAAS_MINIONS_SERVICE_TYPES } from './service-types';\n\ntype Container = InversifyContainer;\n\nlet globalMinionsContainer: Container | undefined;\n\nclass SaasMinionsContainer {\n constructor(private readonly container: Container) {\n this.bindRuntimeServices();\n }\n\n public getContainer(): Container {\n return this.container;\n }\n\n private bindRuntimeServices(): void {\n if (!this.container.isBound(SAAS_MINIONS_SERVICE_TYPES.StartMinionApplicationService)) {\n this.container\n .bind(SAAS_MINIONS_SERVICE_TYPES.StartMinionApplicationService)\n .to(StartMinionApplicationBackendService)\n .inSingletonScope();\n }\n if (!this.container.isBound(SAAS_MINIONS_SERVICE_TYPES.MinionTickConsumerService)) {\n this.container\n .bind(SAAS_MINIONS_SERVICE_TYPES.MinionTickConsumerService)\n .to(MinionTickConsumerBackendService)\n .inSingletonScope();\n }\n if (!this.container.isBound(SAAS_MINIONS_SERVICE_TYPES.OwnScheduleReaderService)) {\n this.container\n .bind(SAAS_MINIONS_SERVICE_TYPES.OwnScheduleReaderService)\n .to(OwnScheduleReaderBackendService)\n .inSingletonScope();\n }\n }\n}\n\nexport function setupSaasMinionInjection(existing?: Container): Container {\n const container = existing ?? globalMinionsContainer ?? setupSaasBackendInjection();\n if (existing && !container.isBound(SAAS_SERVICE_TYPES.StartApplicationService)) {\n throw new Error(\n 'setupSaasMinionInjection(existing) requires a container that already includes saas-backend-lib bindings.',\n );\n }\n const minionsContainer = new SaasMinionsContainer(container);\n if (!existing) {\n globalMinionsContainer = minionsContainer.getContainer();\n }\n return minionsContainer.getContainer();\n}\n\nexport function getGlobalMinionsContainer(): Container {\n return globalMinionsContainer ?? setupSaasMinionInjection();\n}\n\nexport function resetGlobalMinionsContainer(): void {\n globalMinionsContainer = undefined;\n resetGlobalContainer();\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export interface SaasMinionsServiceTypes {
2
+ readonly StartMinionApplicationService: symbol;
3
+ readonly MinionTickConsumerService: symbol;
4
+ readonly OwnScheduleReaderService: symbol;
5
+ }
6
+ export declare const SAAS_MINIONS_SERVICE_TYPES: SaasMinionsServiceTypes;
7
+ //# sourceMappingURL=service-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-types.d.ts","sourceRoot":"","sources":["../../../../../src/inject/models/service-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,6BAA6B,EAAE,MAAM,CAAC;IAC/C,QAAQ,CAAC,yBAAyB,EAAE,MAAM,CAAC;IAC3C,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;CAC3C;AAED,eAAO,MAAM,0BAA0B,EAAE,uBAIxC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export const SAAS_MINIONS_SERVICE_TYPES = {
2
+ StartMinionApplicationService: Symbol.for('SaaS.Minions.StartMinionApplicationService'),
3
+ MinionTickConsumerService: Symbol.for('SaaS.Minions.MinionTickConsumerService'),
4
+ OwnScheduleReaderService: Symbol.for('SaaS.Minions.OwnScheduleReaderService'),
5
+ };
6
+ //# sourceMappingURL=service-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-types.js","sourceRoot":"","sources":["../../../../../src/inject/models/service-types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,0BAA0B,GAA4B;IACjE,6BAA6B,EAAE,MAAM,CAAC,GAAG,CAAC,4CAA4C,CAAC;IACvF,yBAAyB,EAAE,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC;IAC/E,wBAAwB,EAAE,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC;CAC9E,CAAC","sourcesContent":["export interface SaasMinionsServiceTypes {\n readonly StartMinionApplicationService: symbol;\n readonly MinionTickConsumerService: symbol;\n readonly OwnScheduleReaderService: symbol;\n}\n\nexport const SAAS_MINIONS_SERVICE_TYPES: SaasMinionsServiceTypes = {\n StartMinionApplicationService: Symbol.for('SaaS.Minions.StartMinionApplicationService'),\n MinionTickConsumerService: Symbol.for('SaaS.Minions.MinionTickConsumerService'),\n OwnScheduleReaderService: Symbol.for('SaaS.Minions.OwnScheduleReaderService'),\n};\n"]}
@@ -0,0 +1,47 @@
1
+ import { LoggerService, RabbitMQAdapterBackendService, ScheduledMessageVerifierBackendService, type MinionTickJobToken } from '@wildo-ai/saas-backend-lib';
2
+ /**
3
+ * Handler invoked once per verified minion tick. The handler is
4
+ * responsible for routing to the minion's locally-hosted actor system /
5
+ * flow registry. Returning resolves the message ack; throwing causes the
6
+ * consumer to NACK without requeue (per KD-6: minion ticks don't retry
7
+ * via the queue — they'll run again on the next cron cycle).
8
+ */
9
+ export type MinionTickHandler = (token: MinionTickJobToken) => Promise<void>;
10
+ /**
11
+ * Minion-side consumer for the per-minion tick queue
12
+ * (`wildo.queue.<appId>.minion-tick.<minionName>`, see `QueueNamingUtils.buildMinionTickQueueName`).
13
+ *
14
+ * Per KD-12 of `.claude/plans/minions-and-workers-implementation.md`:
15
+ * - Subscribes only to the queue dedicated to THIS minion (no shared
16
+ * `scheduled` queue subscription, so the backend-api and minion don't
17
+ * compete on cron tick deliveries).
18
+ * - Verifies every inbound JWT through
19
+ * `ScheduledMessageVerifierBackendService.verifyAndExtractMinionTick(token, expectedMinionName)`
20
+ * — invalid signature, malformed payload, wrong issuer/audience, or
21
+ * wrong target minion all NACK without requeue.
22
+ * - Dispatches `MINION_TICK` tokens that match this minion's identity to
23
+ * the registered handler. The handler typically routes into the
24
+ * locally-hosted `flowsActorsRegistry` per Q9 LOCKED.
25
+ *
26
+ * Backpressure / cron-overlap guarding (CC-10) is intentionally NOT done
27
+ * here — that's the handler's responsibility (Redis-backed advisory
28
+ * lease pattern documented in CC-10).
29
+ */
30
+ export declare class MinionTickConsumerBackendService {
31
+ private readonly adapter;
32
+ private readonly scheduledMessageVerifier;
33
+ private readonly logger;
34
+ private isConsuming;
35
+ private consumingQueueName?;
36
+ protected readonly logDebug: (message: string, context?: Record<string, unknown>) => void;
37
+ constructor(adapter: RabbitMQAdapterBackendService, scheduledMessageVerifier: ScheduledMessageVerifierBackendService, logger: LoggerService);
38
+ start(input: {
39
+ applicationId: string;
40
+ minionName: string;
41
+ handler: MinionTickHandler;
42
+ }): Promise<void>;
43
+ stop(): Promise<void>;
44
+ isRunning(): boolean;
45
+ private handleMessage;
46
+ }
47
+ //# sourceMappingURL=minion-tick-consumer.backend.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minion-tick-consumer.backend.service.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/queue/minion-tick-consumer.backend.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,aAAa,EACb,6BAA6B,EAE7B,sCAAsC,EACtC,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAC;AAGpC;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE7E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBACa,gCAAgC;IAQzC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,wBAAwB;IAEzC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAXzB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAAC,CAAS;IAEpC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;gBAIvE,OAAO,EAAE,6BAA6B,EAEtC,wBAAwB,EAAE,sCAAsC,EAEhE,MAAM,EAAE,aAAa;IAM3B,KAAK,CAAC,KAAK,EAAE;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,iBAAiB,CAAC;KAC5B,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDJ,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3B,SAAS,IAAI,OAAO;YAIb,aAAa;CAiD5B"}