@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.js CHANGED
@@ -119,9 +119,6 @@ __name(fileOfFrame, "fileOfFrame");
119
119
  var WORKFLOW_METADATA = Symbol("nestjs-durable:workflow");
120
120
  function Workflow(options) {
121
121
  const declaredIn = declaringFile(Workflow);
122
- if (options.input !== void 0 && options.inputSchema !== void 0) {
123
- throw new Error(`@Workflow ${options.name}: set either \`input\` or its alias \`inputSchema\`, not both`);
124
- }
125
122
  return (target) => {
126
123
  rememberDeclaringFile(target, declaredIn);
127
124
  const meta = {
@@ -133,7 +130,7 @@ function Workflow(options) {
133
130
  singleton: options.singleton,
134
131
  concurrency: options.concurrency,
135
132
  executionTimeout: options.executionTimeout,
136
- input: options.input ?? options.inputSchema,
133
+ input: options.input,
137
134
  output: options.output,
138
135
  validateInput: options.validateInput,
139
136
  searchAttributes: options.searchAttributes,
@@ -190,7 +187,6 @@ function Step(nameOrOptions) {
190
187
  };
191
188
  }
192
189
  __name(Step, "Step");
193
- var DurableStep = Step;
194
190
  function getDurableStepMeta(method) {
195
191
  return Reflect.getMetadata(DURABLE_STEP_METADATA, method);
196
192
  }
@@ -318,7 +314,6 @@ function addEventSubscriptions(target, entries) {
318
314
  ], target);
319
315
  }
320
316
  __name(addEventSubscriptions, "addEventSubscriptions");
321
- var OnEvent = OnDurableEvent;
322
317
  function getOnEvents(meta, target) {
323
318
  const fromDecorator = Reflect.getMetadata(ON_EVENT_METADATA, target) ?? [];
324
319
  const names = /* @__PURE__ */ new Set();
@@ -351,6 +346,168 @@ __name(attributesOf, "attributesOf");
351
346
  import { resolveTenantToken, workflowName } from "@dudousxd/nestjs-durable-core";
352
347
  import { Injectable } from "@nestjs/common";
353
348
 
349
+ // src/tenancy.ts
350
+ import { AsyncLocalStorage } from "node:async_hooks";
351
+
352
+ // src/tenancy-reader.ts
353
+ var SLOT = Symbol.for("@dudousxd/nestjs-diagnostics:accessor");
354
+ function accessorOf(accessor) {
355
+ const slot = globalThis[SLOT];
356
+ return accessor ?? slot?.current ?? void 0;
357
+ }
358
+ __name(accessorOf, "accessorOf");
359
+ function readTenancy(option = "inherit", accessor) {
360
+ const a = accessorOf(accessor);
361
+ if (option === false || typeof a?.tenancy !== "function" || !a.tenantFilter) {
362
+ return {
363
+ enabled: false
364
+ };
365
+ }
366
+ const own = typeof option === "object" ? option : {};
367
+ const inherit = own.enabled === void 0 || own.enabled === "inherit";
368
+ if (!(inherit ? a.tenancy().enabled : own.enabled)) return {
369
+ enabled: false
370
+ };
371
+ const options = {};
372
+ if (own.kinds) options.kinds = own.kinds;
373
+ if (own.family !== void 0) options.family = own.family;
374
+ if (own.required !== void 0) options.required = own.required;
375
+ const tenantFilter = a.tenantFilter.bind(a);
376
+ return {
377
+ enabled: true,
378
+ nullRows: own.nullRows ?? "tenantless",
379
+ // Throws the context's TenantRequiredError (403) when a tenant is required and missing.
380
+ filter: /* @__PURE__ */ __name(() => tenantFilter(Object.keys(options).length > 0 ? options : void 0), "filter")
381
+ };
382
+ }
383
+ __name(readTenancy, "readTenancy");
384
+
385
+ // src/tenancy.ts
386
+ var durableWork = new AsyncLocalStorage();
387
+ function inDurableWork(fn) {
388
+ return durableWork.getStore() ? fn() : durableWork.run(true, fn);
389
+ }
390
+ __name(inDurableWork, "inDurableWork");
391
+ function readTenancy2(option, accessor) {
392
+ const own = option ?? "inherit";
393
+ const effective = durableWork.getStore() && own !== false ? {
394
+ ...typeof own === "object" ? own : {},
395
+ required: false
396
+ } : own;
397
+ return readTenancy(effective, accessor);
398
+ }
399
+ __name(readTenancy2, "readTenancy");
400
+ function isTenantRuntime(x) {
401
+ return !!x && typeof x.withTenant === "function";
402
+ }
403
+ __name(isTenantRuntime, "isTenantRuntime");
404
+ var TENANCY_SLOT = Symbol.for("@dudousxd/nestjs-context:tenancy");
405
+ function tenancySlot() {
406
+ const slot = globalThis[TENANCY_SLOT];
407
+ return slot?.version === 1 && isTenantRuntime(slot) ? slot : void 0;
408
+ }
409
+ __name(tenancySlot, "tenancySlot");
410
+ function restorer(runtime) {
411
+ return tenancySlot() ?? runtime;
412
+ }
413
+ __name(restorer, "restorer");
414
+ function restore(runtime, option, tenant, fn) {
415
+ const family = typeof option === "object" ? option.family : void 0;
416
+ const ref = {
417
+ id: tenant.id,
418
+ kind: tenant.kind ?? "unknown",
419
+ source: "carrier"
420
+ };
421
+ return family !== void 0 ? runtime.withTenant(ref, fn, {
422
+ family
423
+ }) : runtime.withTenant(ref, fn);
424
+ }
425
+ __name(restore, "restore");
426
+ function buildEngineTenancy(option, accessor, runtime) {
427
+ if (option === false || !restorer(runtime)) return void 0;
428
+ return {
429
+ current() {
430
+ const t = readTenancy2(option, accessor);
431
+ if (!t.enabled) return void 0;
432
+ const f = t.filter();
433
+ return f.mode === "tenant" ? {
434
+ id: f.tenant.id,
435
+ kind: f.tenant.kind
436
+ } : void 0;
437
+ },
438
+ filter: /* @__PURE__ */ __name(() => tenantFilterNow(option, accessor), "filter"),
439
+ run: /* @__PURE__ */ __name((tenant, fn) => {
440
+ const using = restorer(runtime);
441
+ return using ? restore(using, option, tenant, fn) : fn();
442
+ }, "run"),
443
+ system: inDurableWork
444
+ };
445
+ }
446
+ __name(buildEngineTenancy, "buildEngineTenancy");
447
+ function tenantFilterNow(option, accessor) {
448
+ const t = readTenancy2(option, accessor);
449
+ if (!t.enabled) return {
450
+ mode: "system"
451
+ };
452
+ const f = t.filter();
453
+ if (f.mode === "tenant") return {
454
+ mode: "tenant",
455
+ tenantId: f.tenant.id,
456
+ nullRows: t.nullRows
457
+ };
458
+ if (f.mode === "tenantless") return {
459
+ mode: "tenantless"
460
+ };
461
+ return f.mode === "all" ? {
462
+ mode: "all"
463
+ } : {
464
+ mode: "system"
465
+ };
466
+ }
467
+ __name(tenantFilterNow, "tenantFilterNow");
468
+ function tenantFromCarrier(carrier) {
469
+ const ref = carrier?.tenant;
470
+ if (ref && typeof ref.id === "string") {
471
+ return typeof ref.kind === "string" ? {
472
+ id: ref.id,
473
+ kind: ref.kind
474
+ } : {
475
+ id: ref.id
476
+ };
477
+ }
478
+ const id = carrier?.tenantId;
479
+ return typeof id === "string" ? {
480
+ id
481
+ } : void 0;
482
+ }
483
+ __name(tenantFromCarrier, "tenantFromCarrier");
484
+ function stepTenantWrapper(option, accessor, runtime) {
485
+ return (execution, next) => {
486
+ if (execution.unit !== "step") return next();
487
+ return inDurableWork(() => {
488
+ const tenant = tenantFromCarrier(execution.context);
489
+ const using = restorer(runtime);
490
+ if (!tenant || !using || !readTenancy2(option, accessor).enabled) return next();
491
+ return restore(using, option, tenant, next);
492
+ });
493
+ };
494
+ }
495
+ __name(stepTenantWrapper, "stepTenantWrapper");
496
+ function canRestoreTenant(runtime) {
497
+ return tenancySlot() !== void 0 || isTenantRuntime(runtime);
498
+ }
499
+ __name(canRestoreTenant, "canRestoreTenant");
500
+ function currentTenant(option, accessor) {
501
+ const t = readTenancy2(option, accessor);
502
+ if (!t.enabled) return void 0;
503
+ const f = t.filter();
504
+ return f.mode === "tenant" ? {
505
+ id: f.tenant.id,
506
+ kind: f.tenant.kind
507
+ } : void 0;
508
+ }
509
+ __name(currentTenant, "currentTenant");
510
+
354
511
  // src/tenant-contracts.ts
355
512
  var RESOLVED = Symbol("nestjs-durable:resolved-tenant-auth");
356
513
  function markResolved(fn) {
@@ -541,16 +698,22 @@ var DurableStartClient = class {
541
698
  }
542
699
  options;
543
700
  deps;
701
+ accessor;
544
702
  tenant;
545
703
  tenantToken;
546
- constructor(options, deps) {
704
+ constructor(options, deps, accessor) {
547
705
  this.options = options;
548
706
  this.deps = deps;
707
+ this.accessor = accessor;
549
708
  this.tenant = options.partition ?? "default";
550
709
  this.tenantToken = resolveTenantTokenSource(options.tenantToken);
551
710
  }
552
711
  async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
553
712
  const name = workflowName(workflow);
713
+ const tenant = opts?.tenantId !== void 0 ? opts.tenantId === null ? void 0 : {
714
+ id: opts.tenantId,
715
+ kind: opts.tenantKind
716
+ } : currentTenant(this.options.tenancy, this.accessor);
554
717
  await startRun(this.options.connection, {
555
718
  // The signed token (when configured) rides in the `tenant` field, as on every run request; an
556
719
  // operator with `verifyTenant` derives the run's namespace from it.
@@ -569,6 +732,12 @@ var DurableStartClient = class {
569
732
  ...opts?.searchAttributes !== void 0 ? {
570
733
  searchAttributes: opts.searchAttributes
571
734
  } : {},
735
+ ...tenant ? {
736
+ tenantId: tenant.id,
737
+ ...tenant.kind !== void 0 ? {
738
+ tenantKind: tenant.kind
739
+ } : {}
740
+ } : {},
572
741
  ...this.deps !== void 0 ? {
573
742
  deps: this.deps
574
743
  } : {}
@@ -611,7 +780,8 @@ DurableStartClient = _ts_decorate([
611
780
  _ts_metadata("design:type", Function),
612
781
  _ts_metadata("design:paramtypes", [
613
782
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
614
- typeof StartRunDeps === "undefined" ? Object : StartRunDeps
783
+ typeof StartRunDeps === "undefined" ? Object : StartRunDeps,
784
+ typeof ContextAccessor === "undefined" ? Object : ContextAccessor
615
785
  ])
616
786
  ], DurableStartClient);
617
787
  function tenantUnsupported(method) {
@@ -1397,7 +1567,7 @@ function inAppWorkerProviders() {
1397
1567
  __name(inAppWorkerProviders, "inAppWorkerProviders");
1398
1568
 
1399
1569
  // src/proxy-run-gateway.ts
1400
- import { SUMMARY_CHILD_LIMIT, childIdsOf, pageFan, resolveTenantToken as resolveTenantToken2, summarizeTimeline } from "@dudousxd/nestjs-durable-core";
1570
+ import { SUMMARY_CHILD_LIMIT, childIdsOf, pageFan, resolveTenantToken as resolveTenantToken2, scopeTenantQuery, summarizeTimeline, tenantVisible } from "@dudousxd/nestjs-durable-core";
1401
1571
  import { Injectable as Injectable6 } from "@nestjs/common";
1402
1572
 
1403
1573
  // src/run-request-responder.ts
@@ -1872,20 +2042,63 @@ var ProxyRunGateway = class {
1872
2042
  timeoutMs;
1873
2043
  capabilityTtlMs;
1874
2044
  tenantToken;
2045
+ tenantFilter;
1875
2046
  pending = /* @__PURE__ */ new Map();
1876
2047
  /** Verb → when to ask the control plane for it again, after it answered that it does not know it.
1877
2048
  * During a rolling upgrade the control plane is several pods of mixed versions behind one queue,
1878
2049
  * and a reply does not say which pod sent it, so the whole control plane is assumed old until the
1879
2050
  * entry expires. */
1880
2051
  unsupportedUntil = /* @__PURE__ */ new Map();
1881
- constructor(transport, tenant, timeoutMs = 1e4, capabilityTtlMs = 6e4, tenantToken) {
2052
+ constructor(transport, tenant, timeoutMs = 1e4, capabilityTtlMs = 6e4, tenantToken, tenantFilter) {
1882
2053
  this.transport = transport;
1883
2054
  this.tenant = tenant;
1884
2055
  this.timeoutMs = timeoutMs;
1885
2056
  this.capabilityTtlMs = capabilityTtlMs;
1886
2057
  this.tenantToken = tenantToken;
2058
+ this.tenantFilter = tenantFilter;
1887
2059
  this.transport.onRunReply?.((reply) => this.handleReply(reply));
1888
2060
  }
2061
+ /** The request's tenant filter when it can hide runs (`tenant` / `tenantless`), else undefined. */
2062
+ restrictive() {
2063
+ const filter = this.tenantFilter?.();
2064
+ return filter && filter.mode !== "system" && filter.mode !== "all" ? filter : void 0;
2065
+ }
2066
+ /**
2067
+ * Send `query`, narrowed to the runs the request may see. A tenant-required request with no
2068
+ * tenant rejects (never throws synchronously).
2069
+ */
2070
+ scoped(query, send) {
2071
+ let filter;
2072
+ try {
2073
+ filter = this.restrictive();
2074
+ } catch (err) {
2075
+ return Promise.reject(err);
2076
+ }
2077
+ return send(filter ? scopeTenantQuery(query, filter) : query);
2078
+ }
2079
+ /** `run` when the request may see it, else null (an invisible run reads like a missing one). */
2080
+ visible(run, filter = this.restrictive()) {
2081
+ if (!run) return null;
2082
+ return !filter || tenantVisible(run, filter) ? run : null;
2083
+ }
2084
+ /** Run a control call unless the request may not act on `runId` (then `null`, like a missing run).
2085
+ * Sent at once when nothing narrows the request. */
2086
+ guarded(runId, call) {
2087
+ let filter;
2088
+ try {
2089
+ filter = this.restrictive();
2090
+ } catch (err) {
2091
+ return Promise.reject(err);
2092
+ }
2093
+ if (!filter) return call();
2094
+ return this.hidden(runId).then((hidden) => hidden ? null : call());
2095
+ }
2096
+ /** Before a control call: true when the request may NOT act on `runId`. */
2097
+ async hidden(runId) {
2098
+ const filter = this.restrictive();
2099
+ if (!filter) return false;
2100
+ return this.visible(await this.getRunUnscoped(runId), filter) === null;
2101
+ }
1889
2102
  handleReply(reply) {
1890
2103
  const pending = this.pending.get(reply.requestId);
1891
2104
  if (!pending) return;
@@ -1940,6 +2153,7 @@ var ProxyRunGateway = class {
1940
2153
  * a summarized detail always carries `fans`, so its absence means the summary is made here.
1941
2154
  */
1942
2155
  async getRunDetail(runId, options) {
2156
+ const filter = this.restrictive();
1943
2157
  const detail = await this.request(options === void 0 ? {
1944
2158
  kind: "getRunDetail",
1945
2159
  runId
@@ -1948,6 +2162,7 @@ var ProxyRunGateway = class {
1948
2162
  runId,
1949
2163
  options
1950
2164
  });
2165
+ if (detail && filter && !this.visible(detail.run, filter)) return null;
1951
2166
  const over = options?.summarizeFansOver;
1952
2167
  if (over === void 0 || !detail || detail.fans !== void 0) return detail;
1953
2168
  const { timeline, fans } = summarizeTimeline(detail.timeline, over);
@@ -1962,6 +2177,7 @@ var ProxyRunGateway = class {
1962
2177
  }
1963
2178
  /** Paged from the full detail when the control plane is too old to page a fan itself. */
1964
2179
  async getFanMembers(runId, group, query) {
2180
+ if (this.restrictive() && await this.hidden(runId)) return null;
1965
2181
  if (!this.knownUnsupported("getFanMembers")) {
1966
2182
  try {
1967
2183
  const page = await this.request({
@@ -1987,6 +2203,9 @@ var ProxyRunGateway = class {
1987
2203
  * to know the verb: it then answers with no data, or with an unsupported-request error.
1988
2204
  */
1989
2205
  async getRun(runId) {
2206
+ return this.visible(await this.getRunUnscoped(runId));
2207
+ }
2208
+ async getRunUnscoped(runId) {
1990
2209
  if (!this.knownUnsupported("getRun")) {
1991
2210
  try {
1992
2211
  const run = await this.request({
@@ -2015,27 +2234,27 @@ var ProxyRunGateway = class {
2015
2234
  /** The control plane's `StoreRunGateway` resolves each run's `waiting` descriptor; the reply carries
2016
2235
  * it through as plain JSON, so a tenant's list rows name the wait too. */
2017
2236
  listRuns(query) {
2018
- return this.request({
2237
+ return this.scoped(query, (q) => this.request({
2019
2238
  kind: "listRuns",
2020
- query
2021
- });
2239
+ query: q
2240
+ }));
2022
2241
  }
2023
2242
  /** Counted on the operator, over the same tenant-scoped predicates its `listRuns` reply obeys. */
2024
2243
  runFacets(query) {
2025
- return this.request({
2244
+ return this.scoped(query, (q) => this.request({
2026
2245
  kind: "runFacets",
2027
- query
2028
- });
2246
+ query: q
2247
+ }));
2029
2248
  }
2030
2249
  /** Enumerated on the operator, over the same tenant-scoped predicates its `listRuns` reply obeys —
2031
2250
  * so a tenant's pickers offer its own tenants/tags/attributes and never another's. */
2032
2251
  runValueFacets(axis, query, opts) {
2033
- return this.request({
2252
+ return this.scoped(query, (q) => this.request({
2034
2253
  kind: "runValueFacets",
2035
2254
  axis,
2036
- query,
2255
+ query: q,
2037
2256
  opts
2038
- });
2257
+ }));
2039
2258
  }
2040
2259
  /** Round-trips to the operator, which scopes the result to this tenant's own `@<tenant>` groups. */
2041
2260
  workerHealth() {
@@ -2052,39 +2271,39 @@ var ProxyRunGateway = class {
2052
2271
  });
2053
2272
  }
2054
2273
  cancel(runId, opts) {
2055
- return this.request(opts === void 0 ? {
2274
+ return this.guarded(runId, () => this.request(opts === void 0 ? {
2056
2275
  kind: "cancel",
2057
2276
  runId
2058
2277
  } : {
2059
2278
  kind: "cancel",
2060
2279
  runId,
2061
2280
  opts
2062
- });
2281
+ }));
2063
2282
  }
2064
2283
  retry(runId) {
2065
- return this.request({
2284
+ return this.guarded(runId, () => this.request({
2066
2285
  kind: "retry",
2067
2286
  runId
2068
- });
2287
+ }));
2069
2288
  }
2070
2289
  continue(runId) {
2071
- return this.request({
2290
+ return this.guarded(runId, () => this.request({
2072
2291
  kind: "continue",
2073
2292
  runId
2074
- });
2293
+ }));
2075
2294
  }
2076
2295
  retryWithInput(runId, input) {
2077
- return this.request({
2296
+ return this.guarded(runId, () => this.request({
2078
2297
  kind: "retryWithInput",
2079
2298
  runId,
2080
2299
  input
2081
- });
2300
+ }));
2082
2301
  }
2083
2302
  redispatchPending(runId) {
2084
- return this.request({
2303
+ return this.guarded(runId, () => this.request({
2085
2304
  kind: "redispatch",
2086
2305
  runId
2087
- });
2306
+ }));
2088
2307
  }
2089
2308
  /**
2090
2309
  * Republished on the control plane: a one-run target is checked against this tenant like
@@ -2138,7 +2357,8 @@ ProxyRunGateway = _ts_decorate6([
2138
2357
  String,
2139
2358
  void 0,
2140
2359
  void 0,
2141
- typeof TenantTokenSource === "undefined" ? Object : TenantTokenSource
2360
+ typeof TenantTokenSource === "undefined" ? Object : TenantTokenSource,
2361
+ Function
2142
2362
  ])
2143
2363
  ], ProxyRunGateway);
2144
2364
 
@@ -2845,111 +3065,6 @@ StoreRunGateway = _ts_decorate9([
2845
3065
  ])
2846
3066
  ], StoreRunGateway);
2847
3067
 
2848
- // src/tenancy.ts
2849
- var SLOT = Symbol.for("@dudousxd/nestjs-diagnostics:accessor");
2850
- function accessorOf(accessor) {
2851
- if (accessor) return accessor;
2852
- const slot = globalThis[SLOT];
2853
- return slot?.current ?? void 0;
2854
- }
2855
- __name(accessorOf, "accessorOf");
2856
- function readTenancy(option, accessor) {
2857
- const a = accessorOf(accessor);
2858
- if (option === false || typeof a?.tenancy !== "function" || typeof a.tenantFilter !== "function") {
2859
- return {
2860
- enabled: false
2861
- };
2862
- }
2863
- const own = typeof option === "object" ? option : {};
2864
- const inherit = own.enabled === void 0 || own.enabled === "inherit";
2865
- if (!(inherit ? a.tenancy().enabled : own.enabled)) return {
2866
- enabled: false
2867
- };
2868
- const kinds = own.kinds;
2869
- const tenantFilter = a.tenantFilter.bind(a);
2870
- return {
2871
- enabled: true,
2872
- nullRows: own.nullRows ?? "tenantless",
2873
- filter: /* @__PURE__ */ __name(() => tenantFilter(kinds ? {
2874
- kinds
2875
- } : void 0), "filter")
2876
- };
2877
- }
2878
- __name(readTenancy, "readTenancy");
2879
- function isTenantRuntime(x) {
2880
- return !!x && typeof x.withTenant === "function";
2881
- }
2882
- __name(isTenantRuntime, "isTenantRuntime");
2883
- function restore(runtime, tenant, fn) {
2884
- return runtime.withTenant({
2885
- id: tenant.id,
2886
- kind: tenant.kind ?? "unknown",
2887
- source: "carrier"
2888
- }, fn);
2889
- }
2890
- __name(restore, "restore");
2891
- function buildEngineTenancy(option, accessor, runtime) {
2892
- if (option === false || !runtime) return void 0;
2893
- return {
2894
- current() {
2895
- const t = readTenancy(option, accessor);
2896
- if (!t.enabled) return void 0;
2897
- const f = t.filter();
2898
- return f.mode === "tenant" ? {
2899
- id: f.tenant.id,
2900
- kind: f.tenant.kind
2901
- } : void 0;
2902
- },
2903
- filter() {
2904
- const t = readTenancy(option, accessor);
2905
- if (!t.enabled) return {
2906
- mode: "system"
2907
- };
2908
- const f = t.filter();
2909
- if (f.mode === "tenant") return {
2910
- mode: "tenant",
2911
- tenantId: f.tenant.id,
2912
- nullRows: t.nullRows
2913
- };
2914
- if (f.mode === "tenantless") return {
2915
- mode: "tenantless"
2916
- };
2917
- return f.mode === "all" ? {
2918
- mode: "all"
2919
- } : {
2920
- mode: "system"
2921
- };
2922
- },
2923
- run: /* @__PURE__ */ __name((tenant, fn) => restore(runtime, tenant, fn), "run")
2924
- };
2925
- }
2926
- __name(buildEngineTenancy, "buildEngineTenancy");
2927
- function tenantFromCarrier(carrier) {
2928
- const ref = carrier?.tenant;
2929
- if (ref && typeof ref.id === "string") {
2930
- return typeof ref.kind === "string" ? {
2931
- id: ref.id,
2932
- kind: ref.kind
2933
- } : {
2934
- id: ref.id
2935
- };
2936
- }
2937
- const id = carrier?.tenantId;
2938
- return typeof id === "string" ? {
2939
- id
2940
- } : void 0;
2941
- }
2942
- __name(tenantFromCarrier, "tenantFromCarrier");
2943
- function stepTenantWrapper(option, accessor, runtime) {
2944
- return (execution, next) => {
2945
- if (execution.unit !== "step") return next();
2946
- const tenant = tenantFromCarrier(execution.context);
2947
- if (!tenant || !readTenancy(option, accessor).enabled) return next();
2948
- return restore(runtime, tenant, next);
2949
- };
2950
- }
2951
- __name(stepTenantWrapper, "stepTenantWrapper");
2952
-
2953
3068
  // src/tenant-event-republisher.ts
2954
3069
  function isTerminalRunEvent(event) {
2955
3070
  return event.type === "run.completed" || event.type === "run.failed";
@@ -3746,10 +3861,10 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
3746
3861
  async onApplicationBootstrap() {
3747
3862
  if (this.options.tenancy === false) return;
3748
3863
  const accessor = resolveAccessor(this.moduleRef);
3749
- if (!readTenancy(this.options.tenancy, accessor).enabled) return;
3864
+ if (!readTenancy2(this.options.tenancy, accessor).enabled) return;
3750
3865
  const runtime = await resolveContextRuntime();
3751
- if (!isTenantRuntime(runtime)) return;
3752
- this.unregister = useDurableExecution(stepTenantWrapper(this.options.tenancy, accessor, runtime));
3866
+ if (!canRestoreTenant(runtime)) return;
3867
+ this.unregister = useDurableExecution(stepTenantWrapper(this.options.tenancy, accessor, isTenantRuntime(runtime) ? runtime : void 0));
3753
3868
  }
3754
3869
  onModuleDestroy() {
3755
3870
  this.unregister?.();
@@ -3828,7 +3943,7 @@ var DurableModule = class _DurableModule {
3828
3943
  ModuleRef2
3829
3944
  ]
3830
3945
  },
3831
- // Legacy back-compat aliases (deprecated tokens still resolve to the same instances):
3946
+ // Deprecated tokens that published releases still import resolve to the same instances:
3832
3947
  {
3833
3948
  provide: STATE_STORE,
3834
3949
  useExisting: STATE_STORE_CANONICAL4
@@ -3853,7 +3968,7 @@ var DurableModule = class _DurableModule {
3853
3968
  ...auth.tenantToken !== void 0 ? {
3854
3969
  tenantToken: auth.tenantToken
3855
3970
  } : {}
3856
- });
3971
+ }, void 0, resolveAccessor(moduleRef));
3857
3972
  }
3858
3973
  if (!store) {
3859
3974
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
@@ -3940,20 +4055,21 @@ var DurableModule = class _DurableModule {
3940
4055
  // gateway whose every method rejects with a clear tenant error.
3941
4056
  {
3942
4057
  provide: RunGateway2,
3943
- useFactory: /* @__PURE__ */ __name((options, store, engine, auth) => {
4058
+ useFactory: /* @__PURE__ */ __name((options, store, engine, auth, moduleRef) => {
3944
4059
  if (options.store !== void 0) {
3945
4060
  if (!store) {
3946
4061
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
3947
4062
  }
3948
4063
  return new StoreRunGateway(store, engine);
3949
4064
  }
3950
- return options.transport ? new ProxyRunGateway(options.transport, options.partition ?? "default", options.runGatewayTimeoutMs, void 0, auth.tenantToken) : unavailableRunGateway();
4065
+ 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();
3951
4066
  }, "useFactory"),
3952
4067
  inject: [
3953
4068
  DURABLE_OPTIONS_CANONICAL8,
3954
4069
  STATE_STORE_CANONICAL4,
3955
4070
  WorkflowEngine6,
3956
- TENANT_AUTH
4071
+ TENANT_AUTH,
4072
+ ModuleRef2
3957
4073
  ]
3958
4074
  },
3959
4075
  RunGatewayBootstrap,
@@ -3995,7 +4111,6 @@ export {
3995
4111
  DeadLetter,
3996
4112
  DurableModule,
3997
4113
  DurableStartClient,
3998
- DurableStep,
3999
4114
  ENTITY_METADATA,
4000
4115
  ENTITY_ON_METADATA,
4001
4116
  Entity,
@@ -4012,7 +4127,6 @@ export {
4012
4127
  On,
4013
4128
  OnDurableEvent,
4014
4129
  OnError,
4015
- OnEvent,
4016
4130
  OnWorkflowCompleted,
4017
4131
  OnWorkflowFailed,
4018
4132
  ProxyRunGateway,