@dudousxd/nestjs-durable 0.57.0 → 0.59.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/dist/index.cjs CHANGED
@@ -40,7 +40,6 @@ __export(src_exports, {
40
40
  DeadLetter: () => DeadLetter,
41
41
  DurableModule: () => DurableModule,
42
42
  DurableStartClient: () => DurableStartClient,
43
- DurableStep: () => DurableStep,
44
43
  ENTITY_METADATA: () => ENTITY_METADATA,
45
44
  ENTITY_ON_METADATA: () => ENTITY_ON_METADATA,
46
45
  Entity: () => Entity,
@@ -57,7 +56,6 @@ __export(src_exports, {
57
56
  On: () => On,
58
57
  OnDurableEvent: () => OnDurableEvent,
59
58
  OnError: () => OnError,
60
- OnEvent: () => OnEvent,
61
59
  OnWorkflowCompleted: () => OnWorkflowCompleted,
62
60
  OnWorkflowFailed: () => OnWorkflowFailed,
63
61
  ProxyRunGateway: () => ProxyRunGateway,
@@ -228,9 +226,6 @@ __name(fileOfFrame, "fileOfFrame");
228
226
  var WORKFLOW_METADATA = Symbol("nestjs-durable:workflow");
229
227
  function Workflow(options) {
230
228
  const declaredIn = declaringFile(Workflow);
231
- if (options.input !== void 0 && options.inputSchema !== void 0) {
232
- throw new Error(`@Workflow ${options.name}: set either \`input\` or its alias \`inputSchema\`, not both`);
233
- }
234
229
  return (target) => {
235
230
  rememberDeclaringFile(target, declaredIn);
236
231
  const meta = {
@@ -242,7 +237,7 @@ function Workflow(options) {
242
237
  singleton: options.singleton,
243
238
  concurrency: options.concurrency,
244
239
  executionTimeout: options.executionTimeout,
245
- input: options.input ?? options.inputSchema,
240
+ input: options.input,
246
241
  output: options.output,
247
242
  validateInput: options.validateInput,
248
243
  searchAttributes: options.searchAttributes,
@@ -299,7 +294,6 @@ function Step(nameOrOptions) {
299
294
  };
300
295
  }
301
296
  __name(Step, "Step");
302
- var DurableStep = Step;
303
297
  function getDurableStepMeta(method) {
304
298
  return Reflect.getMetadata(DURABLE_STEP_METADATA, method);
305
299
  }
@@ -427,7 +421,6 @@ function addEventSubscriptions(target, entries) {
427
421
  ], target);
428
422
  }
429
423
  __name(addEventSubscriptions, "addEventSubscriptions");
430
- var OnEvent = OnDurableEvent;
431
424
  function getOnEvents(meta, target) {
432
425
  const fromDecorator = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
433
426
  const names = /* @__PURE__ */ new Set();
@@ -460,6 +453,168 @@ __name(attributesOf, "attributesOf");
460
453
  var import_nestjs_durable_core3 = require("@dudousxd/nestjs-durable-core");
461
454
  var import_common = require("@nestjs/common");
462
455
 
456
+ // src/tenancy.ts
457
+ var import_node_async_hooks = require("async_hooks");
458
+
459
+ // src/tenancy-reader.ts
460
+ var SLOT = Symbol.for("@dudousxd/nestjs-diagnostics:accessor");
461
+ function accessorOf(accessor) {
462
+ const slot = globalThis[SLOT];
463
+ return accessor ?? slot?.current ?? void 0;
464
+ }
465
+ __name(accessorOf, "accessorOf");
466
+ function readTenancy(option = "inherit", accessor) {
467
+ const a = accessorOf(accessor);
468
+ if (option === false || typeof a?.tenancy !== "function" || !a.tenantFilter) {
469
+ return {
470
+ enabled: false
471
+ };
472
+ }
473
+ const own = typeof option === "object" ? option : {};
474
+ const inherit = own.enabled === void 0 || own.enabled === "inherit";
475
+ if (!(inherit ? a.tenancy().enabled : own.enabled)) return {
476
+ enabled: false
477
+ };
478
+ const options = {};
479
+ if (own.kinds) options.kinds = own.kinds;
480
+ if (own.family !== void 0) options.family = own.family;
481
+ if (own.required !== void 0) options.required = own.required;
482
+ const tenantFilter = a.tenantFilter.bind(a);
483
+ return {
484
+ enabled: true,
485
+ nullRows: own.nullRows ?? "tenantless",
486
+ // Throws the context's TenantRequiredError (403) when a tenant is required and missing.
487
+ filter: /* @__PURE__ */ __name(() => tenantFilter(Object.keys(options).length > 0 ? options : void 0), "filter")
488
+ };
489
+ }
490
+ __name(readTenancy, "readTenancy");
491
+
492
+ // src/tenancy.ts
493
+ var durableWork = new import_node_async_hooks.AsyncLocalStorage();
494
+ function inDurableWork(fn) {
495
+ return durableWork.getStore() ? fn() : durableWork.run(true, fn);
496
+ }
497
+ __name(inDurableWork, "inDurableWork");
498
+ function readTenancy2(option, accessor) {
499
+ const own = option ?? "inherit";
500
+ const effective = durableWork.getStore() && own !== false ? {
501
+ ...typeof own === "object" ? own : {},
502
+ required: false
503
+ } : own;
504
+ return readTenancy(effective, accessor);
505
+ }
506
+ __name(readTenancy2, "readTenancy");
507
+ function isTenantRuntime(x) {
508
+ return !!x && typeof x.withTenant === "function";
509
+ }
510
+ __name(isTenantRuntime, "isTenantRuntime");
511
+ var TENANCY_SLOT = Symbol.for("@dudousxd/nestjs-context:tenancy");
512
+ function tenancySlot() {
513
+ const slot = globalThis[TENANCY_SLOT];
514
+ return slot?.version === 1 && isTenantRuntime(slot) ? slot : void 0;
515
+ }
516
+ __name(tenancySlot, "tenancySlot");
517
+ function restorer(runtime) {
518
+ return tenancySlot() ?? runtime;
519
+ }
520
+ __name(restorer, "restorer");
521
+ function restore(runtime, option, tenant, fn) {
522
+ const family = typeof option === "object" ? option.family : void 0;
523
+ const ref = {
524
+ id: tenant.id,
525
+ kind: tenant.kind ?? "unknown",
526
+ source: "carrier"
527
+ };
528
+ return family !== void 0 ? runtime.withTenant(ref, fn, {
529
+ family
530
+ }) : runtime.withTenant(ref, fn);
531
+ }
532
+ __name(restore, "restore");
533
+ function buildEngineTenancy(option, accessor, runtime) {
534
+ if (option === false || !restorer(runtime)) return void 0;
535
+ return {
536
+ current() {
537
+ const t = readTenancy2(option, accessor);
538
+ if (!t.enabled) return void 0;
539
+ const f = t.filter();
540
+ return f.mode === "tenant" ? {
541
+ id: f.tenant.id,
542
+ kind: f.tenant.kind
543
+ } : void 0;
544
+ },
545
+ filter: /* @__PURE__ */ __name(() => tenantFilterNow(option, accessor), "filter"),
546
+ run: /* @__PURE__ */ __name((tenant, fn) => {
547
+ const using = restorer(runtime);
548
+ return using ? restore(using, option, tenant, fn) : fn();
549
+ }, "run"),
550
+ system: inDurableWork
551
+ };
552
+ }
553
+ __name(buildEngineTenancy, "buildEngineTenancy");
554
+ function tenantFilterNow(option, accessor) {
555
+ const t = readTenancy2(option, accessor);
556
+ if (!t.enabled) return {
557
+ mode: "system"
558
+ };
559
+ const f = t.filter();
560
+ if (f.mode === "tenant") return {
561
+ mode: "tenant",
562
+ tenantId: f.tenant.id,
563
+ nullRows: t.nullRows
564
+ };
565
+ if (f.mode === "tenantless") return {
566
+ mode: "tenantless"
567
+ };
568
+ return f.mode === "all" ? {
569
+ mode: "all"
570
+ } : {
571
+ mode: "system"
572
+ };
573
+ }
574
+ __name(tenantFilterNow, "tenantFilterNow");
575
+ function tenantFromCarrier(carrier) {
576
+ const ref = carrier?.tenant;
577
+ if (ref && typeof ref.id === "string") {
578
+ return typeof ref.kind === "string" ? {
579
+ id: ref.id,
580
+ kind: ref.kind
581
+ } : {
582
+ id: ref.id
583
+ };
584
+ }
585
+ const id = carrier?.tenantId;
586
+ return typeof id === "string" ? {
587
+ id
588
+ } : void 0;
589
+ }
590
+ __name(tenantFromCarrier, "tenantFromCarrier");
591
+ function stepTenantWrapper(option, accessor, runtime) {
592
+ return (execution, next) => {
593
+ if (execution.unit !== "step") return next();
594
+ return inDurableWork(() => {
595
+ const tenant = tenantFromCarrier(execution.context);
596
+ const using = restorer(runtime);
597
+ if (!tenant || !using || !readTenancy2(option, accessor).enabled) return next();
598
+ return restore(using, option, tenant, next);
599
+ });
600
+ };
601
+ }
602
+ __name(stepTenantWrapper, "stepTenantWrapper");
603
+ function canRestoreTenant(runtime) {
604
+ return tenancySlot() !== void 0 || isTenantRuntime(runtime);
605
+ }
606
+ __name(canRestoreTenant, "canRestoreTenant");
607
+ function currentTenant(option, accessor) {
608
+ const t = readTenancy2(option, accessor);
609
+ if (!t.enabled) return void 0;
610
+ const f = t.filter();
611
+ return f.mode === "tenant" ? {
612
+ id: f.tenant.id,
613
+ kind: f.tenant.kind
614
+ } : void 0;
615
+ }
616
+ __name(currentTenant, "currentTenant");
617
+
463
618
  // src/tenant-contracts.ts
464
619
  var RESOLVED = Symbol("nestjs-durable:resolved-tenant-auth");
465
620
  function markResolved(fn) {
@@ -650,16 +805,22 @@ var DurableStartClient = class {
650
805
  }
651
806
  options;
652
807
  deps;
808
+ accessor;
653
809
  tenant;
654
810
  tenantToken;
655
- constructor(options, deps) {
811
+ constructor(options, deps, accessor) {
656
812
  this.options = options;
657
813
  this.deps = deps;
814
+ this.accessor = accessor;
658
815
  this.tenant = options.partition ?? "default";
659
816
  this.tenantToken = resolveTenantTokenSource(options.tenantToken);
660
817
  }
661
818
  async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
662
819
  const name = (0, import_nestjs_durable_core3.workflowName)(workflow);
820
+ const tenant = opts?.tenantId !== void 0 ? opts.tenantId === null ? void 0 : {
821
+ id: opts.tenantId,
822
+ kind: opts.tenantKind
823
+ } : currentTenant(this.options.tenancy, this.accessor);
663
824
  await startRun(this.options.connection, {
664
825
  // The signed token (when configured) rides in the `tenant` field, as on every run request; an
665
826
  // operator with `verifyTenant` derives the run's namespace from it.
@@ -678,6 +839,12 @@ var DurableStartClient = class {
678
839
  ...opts?.searchAttributes !== void 0 ? {
679
840
  searchAttributes: opts.searchAttributes
680
841
  } : {},
842
+ ...tenant ? {
843
+ tenantId: tenant.id,
844
+ ...tenant.kind !== void 0 ? {
845
+ tenantKind: tenant.kind
846
+ } : {}
847
+ } : {},
681
848
  ...this.deps !== void 0 ? {
682
849
  deps: this.deps
683
850
  } : {}
@@ -720,7 +887,8 @@ DurableStartClient = _ts_decorate([
720
887
  _ts_metadata("design:type", Function),
721
888
  _ts_metadata("design:paramtypes", [
722
889
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
723
- typeof StartRunDeps === "undefined" ? Object : StartRunDeps
890
+ typeof StartRunDeps === "undefined" ? Object : StartRunDeps,
891
+ typeof ContextAccessor === "undefined" ? Object : ContextAccessor
724
892
  ])
725
893
  ], DurableStartClient);
726
894
  function tenantUnsupported(method) {
@@ -1981,20 +2149,63 @@ var ProxyRunGateway = class {
1981
2149
  timeoutMs;
1982
2150
  capabilityTtlMs;
1983
2151
  tenantToken;
2152
+ tenantFilter;
1984
2153
  pending = /* @__PURE__ */ new Map();
1985
2154
  /** Verb → when to ask the control plane for it again, after it answered that it does not know it.
1986
2155
  * During a rolling upgrade the control plane is several pods of mixed versions behind one queue,
1987
2156
  * and a reply does not say which pod sent it, so the whole control plane is assumed old until the
1988
2157
  * entry expires. */
1989
2158
  unsupportedUntil = /* @__PURE__ */ new Map();
1990
- constructor(transport, tenant, timeoutMs = 1e4, capabilityTtlMs = 6e4, tenantToken) {
2159
+ constructor(transport, tenant, timeoutMs = 1e4, capabilityTtlMs = 6e4, tenantToken, tenantFilter) {
1991
2160
  this.transport = transport;
1992
2161
  this.tenant = tenant;
1993
2162
  this.timeoutMs = timeoutMs;
1994
2163
  this.capabilityTtlMs = capabilityTtlMs;
1995
2164
  this.tenantToken = tenantToken;
2165
+ this.tenantFilter = tenantFilter;
1996
2166
  this.transport.onRunReply?.((reply) => this.handleReply(reply));
1997
2167
  }
2168
+ /** The request's tenant filter when it can hide runs (`tenant` / `tenantless`), else undefined. */
2169
+ restrictive() {
2170
+ const filter = this.tenantFilter?.();
2171
+ return filter && filter.mode !== "system" && filter.mode !== "all" ? filter : void 0;
2172
+ }
2173
+ /**
2174
+ * Send `query`, narrowed to the runs the request may see. A tenant-required request with no
2175
+ * tenant rejects (never throws synchronously).
2176
+ */
2177
+ scoped(query, send) {
2178
+ let filter;
2179
+ try {
2180
+ filter = this.restrictive();
2181
+ } catch (err) {
2182
+ return Promise.reject(err);
2183
+ }
2184
+ return send(filter ? (0, import_nestjs_durable_core11.scopeTenantQuery)(query, filter) : query);
2185
+ }
2186
+ /** `run` when the request may see it, else null (an invisible run reads like a missing one). */
2187
+ visible(run, filter = this.restrictive()) {
2188
+ if (!run) return null;
2189
+ return !filter || (0, import_nestjs_durable_core11.tenantVisible)(run, filter) ? run : null;
2190
+ }
2191
+ /** Run a control call unless the request may not act on `runId` (then `null`, like a missing run).
2192
+ * Sent at once when nothing narrows the request. */
2193
+ guarded(runId, call) {
2194
+ let filter;
2195
+ try {
2196
+ filter = this.restrictive();
2197
+ } catch (err) {
2198
+ return Promise.reject(err);
2199
+ }
2200
+ if (!filter) return call();
2201
+ return this.hidden(runId).then((hidden) => hidden ? null : call());
2202
+ }
2203
+ /** Before a control call: true when the request may NOT act on `runId`. */
2204
+ async hidden(runId) {
2205
+ const filter = this.restrictive();
2206
+ if (!filter) return false;
2207
+ return this.visible(await this.getRunUnscoped(runId), filter) === null;
2208
+ }
1998
2209
  handleReply(reply) {
1999
2210
  const pending = this.pending.get(reply.requestId);
2000
2211
  if (!pending) return;
@@ -2049,6 +2260,7 @@ var ProxyRunGateway = class {
2049
2260
  * a summarized detail always carries `fans`, so its absence means the summary is made here.
2050
2261
  */
2051
2262
  async getRunDetail(runId, options) {
2263
+ const filter = this.restrictive();
2052
2264
  const detail = await this.request(options === void 0 ? {
2053
2265
  kind: "getRunDetail",
2054
2266
  runId
@@ -2057,6 +2269,7 @@ var ProxyRunGateway = class {
2057
2269
  runId,
2058
2270
  options
2059
2271
  });
2272
+ if (detail && filter && !this.visible(detail.run, filter)) return null;
2060
2273
  const over = options?.summarizeFansOver;
2061
2274
  if (over === void 0 || !detail || detail.fans !== void 0) return detail;
2062
2275
  const { timeline, fans } = (0, import_nestjs_durable_core11.summarizeTimeline)(detail.timeline, over);
@@ -2071,6 +2284,7 @@ var ProxyRunGateway = class {
2071
2284
  }
2072
2285
  /** Paged from the full detail when the control plane is too old to page a fan itself. */
2073
2286
  async getFanMembers(runId, group, query) {
2287
+ if (this.restrictive() && await this.hidden(runId)) return null;
2074
2288
  if (!this.knownUnsupported("getFanMembers")) {
2075
2289
  try {
2076
2290
  const page = await this.request({
@@ -2096,6 +2310,9 @@ var ProxyRunGateway = class {
2096
2310
  * to know the verb: it then answers with no data, or with an unsupported-request error.
2097
2311
  */
2098
2312
  async getRun(runId) {
2313
+ return this.visible(await this.getRunUnscoped(runId));
2314
+ }
2315
+ async getRunUnscoped(runId) {
2099
2316
  if (!this.knownUnsupported("getRun")) {
2100
2317
  try {
2101
2318
  const run = await this.request({
@@ -2124,27 +2341,27 @@ var ProxyRunGateway = class {
2124
2341
  /** The control plane's `StoreRunGateway` resolves each run's `waiting` descriptor; the reply carries
2125
2342
  * it through as plain JSON, so a tenant's list rows name the wait too. */
2126
2343
  listRuns(query) {
2127
- return this.request({
2344
+ return this.scoped(query, (q) => this.request({
2128
2345
  kind: "listRuns",
2129
- query
2130
- });
2346
+ query: q
2347
+ }));
2131
2348
  }
2132
2349
  /** Counted on the operator, over the same tenant-scoped predicates its `listRuns` reply obeys. */
2133
2350
  runFacets(query) {
2134
- return this.request({
2351
+ return this.scoped(query, (q) => this.request({
2135
2352
  kind: "runFacets",
2136
- query
2137
- });
2353
+ query: q
2354
+ }));
2138
2355
  }
2139
2356
  /** Enumerated on the operator, over the same tenant-scoped predicates its `listRuns` reply obeys —
2140
2357
  * so a tenant's pickers offer its own tenants/tags/attributes and never another's. */
2141
2358
  runValueFacets(axis, query, opts) {
2142
- return this.request({
2359
+ return this.scoped(query, (q) => this.request({
2143
2360
  kind: "runValueFacets",
2144
2361
  axis,
2145
- query,
2362
+ query: q,
2146
2363
  opts
2147
- });
2364
+ }));
2148
2365
  }
2149
2366
  /** Round-trips to the operator, which scopes the result to this tenant's own `@<tenant>` groups. */
2150
2367
  workerHealth() {
@@ -2161,39 +2378,39 @@ var ProxyRunGateway = class {
2161
2378
  });
2162
2379
  }
2163
2380
  cancel(runId, opts) {
2164
- return this.request(opts === void 0 ? {
2381
+ return this.guarded(runId, () => this.request(opts === void 0 ? {
2165
2382
  kind: "cancel",
2166
2383
  runId
2167
2384
  } : {
2168
2385
  kind: "cancel",
2169
2386
  runId,
2170
2387
  opts
2171
- });
2388
+ }));
2172
2389
  }
2173
2390
  retry(runId) {
2174
- return this.request({
2391
+ return this.guarded(runId, () => this.request({
2175
2392
  kind: "retry",
2176
2393
  runId
2177
- });
2394
+ }));
2178
2395
  }
2179
2396
  continue(runId) {
2180
- return this.request({
2397
+ return this.guarded(runId, () => this.request({
2181
2398
  kind: "continue",
2182
2399
  runId
2183
- });
2400
+ }));
2184
2401
  }
2185
2402
  retryWithInput(runId, input) {
2186
- return this.request({
2403
+ return this.guarded(runId, () => this.request({
2187
2404
  kind: "retryWithInput",
2188
2405
  runId,
2189
2406
  input
2190
- });
2407
+ }));
2191
2408
  }
2192
2409
  redispatchPending(runId) {
2193
- return this.request({
2410
+ return this.guarded(runId, () => this.request({
2194
2411
  kind: "redispatch",
2195
2412
  runId
2196
- });
2413
+ }));
2197
2414
  }
2198
2415
  /**
2199
2416
  * Republished on the control plane: a one-run target is checked against this tenant like
@@ -2247,7 +2464,8 @@ ProxyRunGateway = _ts_decorate6([
2247
2464
  String,
2248
2465
  void 0,
2249
2466
  void 0,
2250
- typeof TenantTokenSource === "undefined" ? Object : TenantTokenSource
2467
+ typeof TenantTokenSource === "undefined" ? Object : TenantTokenSource,
2468
+ Function
2251
2469
  ])
2252
2470
  ], ProxyRunGateway);
2253
2471
 
@@ -2954,111 +3172,6 @@ StoreRunGateway = _ts_decorate9([
2954
3172
  ])
2955
3173
  ], StoreRunGateway);
2956
3174
 
2957
- // src/tenancy.ts
2958
- var SLOT = Symbol.for("@dudousxd/nestjs-diagnostics:accessor");
2959
- function accessorOf(accessor) {
2960
- if (accessor) return accessor;
2961
- const slot = globalThis[SLOT];
2962
- return slot?.current ?? void 0;
2963
- }
2964
- __name(accessorOf, "accessorOf");
2965
- function readTenancy(option, accessor) {
2966
- const a = accessorOf(accessor);
2967
- if (option === false || typeof a?.tenancy !== "function" || typeof a.tenantFilter !== "function") {
2968
- return {
2969
- enabled: false
2970
- };
2971
- }
2972
- const own = typeof option === "object" ? option : {};
2973
- const inherit = own.enabled === void 0 || own.enabled === "inherit";
2974
- if (!(inherit ? a.tenancy().enabled : own.enabled)) return {
2975
- enabled: false
2976
- };
2977
- const kinds = own.kinds;
2978
- const tenantFilter = a.tenantFilter.bind(a);
2979
- return {
2980
- enabled: true,
2981
- nullRows: own.nullRows ?? "tenantless",
2982
- filter: /* @__PURE__ */ __name(() => tenantFilter(kinds ? {
2983
- kinds
2984
- } : void 0), "filter")
2985
- };
2986
- }
2987
- __name(readTenancy, "readTenancy");
2988
- function isTenantRuntime(x) {
2989
- return !!x && typeof x.withTenant === "function";
2990
- }
2991
- __name(isTenantRuntime, "isTenantRuntime");
2992
- function restore(runtime, tenant, fn) {
2993
- return runtime.withTenant({
2994
- id: tenant.id,
2995
- kind: tenant.kind ?? "unknown",
2996
- source: "carrier"
2997
- }, fn);
2998
- }
2999
- __name(restore, "restore");
3000
- function buildEngineTenancy(option, accessor, runtime) {
3001
- if (option === false || !runtime) return void 0;
3002
- return {
3003
- current() {
3004
- const t = readTenancy(option, accessor);
3005
- if (!t.enabled) return void 0;
3006
- const f = t.filter();
3007
- return f.mode === "tenant" ? {
3008
- id: f.tenant.id,
3009
- kind: f.tenant.kind
3010
- } : void 0;
3011
- },
3012
- filter() {
3013
- const t = readTenancy(option, accessor);
3014
- if (!t.enabled) return {
3015
- mode: "system"
3016
- };
3017
- const f = t.filter();
3018
- if (f.mode === "tenant") return {
3019
- mode: "tenant",
3020
- tenantId: f.tenant.id,
3021
- nullRows: t.nullRows
3022
- };
3023
- if (f.mode === "tenantless") return {
3024
- mode: "tenantless"
3025
- };
3026
- return f.mode === "all" ? {
3027
- mode: "all"
3028
- } : {
3029
- mode: "system"
3030
- };
3031
- },
3032
- run: /* @__PURE__ */ __name((tenant, fn) => restore(runtime, tenant, fn), "run")
3033
- };
3034
- }
3035
- __name(buildEngineTenancy, "buildEngineTenancy");
3036
- function tenantFromCarrier(carrier) {
3037
- const ref = carrier?.tenant;
3038
- if (ref && typeof ref.id === "string") {
3039
- return typeof ref.kind === "string" ? {
3040
- id: ref.id,
3041
- kind: ref.kind
3042
- } : {
3043
- id: ref.id
3044
- };
3045
- }
3046
- const id = carrier?.tenantId;
3047
- return typeof id === "string" ? {
3048
- id
3049
- } : void 0;
3050
- }
3051
- __name(tenantFromCarrier, "tenantFromCarrier");
3052
- function stepTenantWrapper(option, accessor, runtime) {
3053
- return (execution, next) => {
3054
- if (execution.unit !== "step") return next();
3055
- const tenant = tenantFromCarrier(execution.context);
3056
- if (!tenant || !readTenancy(option, accessor).enabled) return next();
3057
- return restore(runtime, tenant, next);
3058
- };
3059
- }
3060
- __name(stepTenantWrapper, "stepTenantWrapper");
3061
-
3062
3175
  // src/tenant-event-republisher.ts
3063
3176
  function isTerminalRunEvent(event) {
3064
3177
  return event.type === "run.completed" || event.type === "run.failed";
@@ -3855,10 +3968,10 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
3855
3968
  async onApplicationBootstrap() {
3856
3969
  if (this.options.tenancy === false) return;
3857
3970
  const accessor = resolveAccessor(this.moduleRef);
3858
- if (!readTenancy(this.options.tenancy, accessor).enabled) return;
3971
+ if (!readTenancy2(this.options.tenancy, accessor).enabled) return;
3859
3972
  const runtime = await resolveContextRuntime();
3860
- if (!isTenantRuntime(runtime)) return;
3861
- this.unregister = (0, import_nestjs_durable_core19.useDurableExecution)(stepTenantWrapper(this.options.tenancy, accessor, runtime));
3973
+ if (!canRestoreTenant(runtime)) return;
3974
+ this.unregister = (0, import_nestjs_durable_core19.useDurableExecution)(stepTenantWrapper(this.options.tenancy, accessor, isTenantRuntime(runtime) ? runtime : void 0));
3862
3975
  }
3863
3976
  onModuleDestroy() {
3864
3977
  this.unregister?.();
@@ -3937,7 +4050,7 @@ var DurableModule = class _DurableModule {
3937
4050
  import_core6.ModuleRef
3938
4051
  ]
3939
4052
  },
3940
- // Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
4053
+ // Deprecated tokens that published releases still import resolve to the same instances:
3941
4054
  {
3942
4055
  provide: import_nestjs_durable_core19.STATE_STORE,
3943
4056
  useExisting: import_nestjs_durable_core19.STATE_STORE_CANONICAL
@@ -3962,7 +4075,7 @@ var DurableModule = class _DurableModule {
3962
4075
  ...auth.tenantToken !== void 0 ? {
3963
4076
  tenantToken: auth.tenantToken
3964
4077
  } : {}
3965
- });
4078
+ }, void 0, resolveAccessor(moduleRef));
3966
4079
  }
3967
4080
  if (!store) {
3968
4081
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
@@ -4049,20 +4162,21 @@ var DurableModule = class _DurableModule {
4049
4162
  // gateway whose every method rejects with a clear tenant error.
4050
4163
  {
4051
4164
  provide: import_nestjs_durable_core19.RunGateway,
4052
- useFactory: /* @__PURE__ */ __name((options, store, engine, auth) => {
4165
+ useFactory: /* @__PURE__ */ __name((options, store, engine, auth, moduleRef) => {
4053
4166
  if (options.store !== void 0) {
4054
4167
  if (!store) {
4055
4168
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
4056
4169
  }
4057
4170
  return new StoreRunGateway(store, engine);
4058
4171
  }
4059
- return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, auth.tenantToken) : unavailableRunGateway();
4172
+ return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, auth.tenantToken, options.tenancy === false ? void 0 : () => tenantFilterNow(options.tenancy, resolveAccessor(moduleRef))) : unavailableRunGateway();
4060
4173
  }, "useFactory"),
4061
4174
  inject: [
4062
4175
  import_nestjs_durable_core19.DURABLE_OPTIONS_CANONICAL,
4063
4176
  import_nestjs_durable_core19.STATE_STORE_CANONICAL,
4064
4177
  import_nestjs_durable_core19.WorkflowEngine,
4065
- TENANT_AUTH
4178
+ TENANT_AUTH,
4179
+ import_core6.ModuleRef
4066
4180
  ]
4067
4181
  },
4068
4182
  RunGatewayBootstrap,
@@ -4105,7 +4219,6 @@ var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
4105
4219
  DeadLetter,
4106
4220
  DurableModule,
4107
4221
  DurableStartClient,
4108
- DurableStep,
4109
4222
  ENTITY_METADATA,
4110
4223
  ENTITY_ON_METADATA,
4111
4224
  Entity,
@@ -4122,7 +4235,6 @@ var import_nestjs_durable_core20 = require("@dudousxd/nestjs-durable-core");
4122
4235
  On,
4123
4236
  OnDurableEvent,
4124
4237
  OnError,
4125
- OnEvent,
4126
4238
  OnWorkflowCompleted,
4127
4239
  OnWorkflowFailed,
4128
4240
  ProxyRunGateway,