@dudousxd/nestjs-durable 0.58.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
@@ -346,6 +346,168 @@ __name(attributesOf, "attributesOf");
346
346
  import { resolveTenantToken, workflowName } from "@dudousxd/nestjs-durable-core";
347
347
  import { Injectable } from "@nestjs/common";
348
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
+
349
511
  // src/tenant-contracts.ts
350
512
  var RESOLVED = Symbol("nestjs-durable:resolved-tenant-auth");
351
513
  function markResolved(fn) {
@@ -536,16 +698,22 @@ var DurableStartClient = class {
536
698
  }
537
699
  options;
538
700
  deps;
701
+ accessor;
539
702
  tenant;
540
703
  tenantToken;
541
- constructor(options, deps) {
704
+ constructor(options, deps, accessor) {
542
705
  this.options = options;
543
706
  this.deps = deps;
707
+ this.accessor = accessor;
544
708
  this.tenant = options.partition ?? "default";
545
709
  this.tenantToken = resolveTenantTokenSource(options.tenantToken);
546
710
  }
547
711
  async start(workflow, input, runId = globalThis.crypto.randomUUID(), opts) {
548
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);
549
717
  await startRun(this.options.connection, {
550
718
  // The signed token (when configured) rides in the `tenant` field, as on every run request; an
551
719
  // operator with `verifyTenant` derives the run's namespace from it.
@@ -564,6 +732,12 @@ var DurableStartClient = class {
564
732
  ...opts?.searchAttributes !== void 0 ? {
565
733
  searchAttributes: opts.searchAttributes
566
734
  } : {},
735
+ ...tenant ? {
736
+ tenantId: tenant.id,
737
+ ...tenant.kind !== void 0 ? {
738
+ tenantKind: tenant.kind
739
+ } : {}
740
+ } : {},
567
741
  ...this.deps !== void 0 ? {
568
742
  deps: this.deps
569
743
  } : {}
@@ -606,7 +780,8 @@ DurableStartClient = _ts_decorate([
606
780
  _ts_metadata("design:type", Function),
607
781
  _ts_metadata("design:paramtypes", [
608
782
  typeof DurableModuleOptions === "undefined" ? Object : DurableModuleOptions,
609
- typeof StartRunDeps === "undefined" ? Object : StartRunDeps
783
+ typeof StartRunDeps === "undefined" ? Object : StartRunDeps,
784
+ typeof ContextAccessor === "undefined" ? Object : ContextAccessor
610
785
  ])
611
786
  ], DurableStartClient);
612
787
  function tenantUnsupported(method) {
@@ -1392,7 +1567,7 @@ function inAppWorkerProviders() {
1392
1567
  __name(inAppWorkerProviders, "inAppWorkerProviders");
1393
1568
 
1394
1569
  // src/proxy-run-gateway.ts
1395
- 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";
1396
1571
  import { Injectable as Injectable6 } from "@nestjs/common";
1397
1572
 
1398
1573
  // src/run-request-responder.ts
@@ -1867,20 +2042,63 @@ var ProxyRunGateway = class {
1867
2042
  timeoutMs;
1868
2043
  capabilityTtlMs;
1869
2044
  tenantToken;
2045
+ tenantFilter;
1870
2046
  pending = /* @__PURE__ */ new Map();
1871
2047
  /** Verb → when to ask the control plane for it again, after it answered that it does not know it.
1872
2048
  * During a rolling upgrade the control plane is several pods of mixed versions behind one queue,
1873
2049
  * and a reply does not say which pod sent it, so the whole control plane is assumed old until the
1874
2050
  * entry expires. */
1875
2051
  unsupportedUntil = /* @__PURE__ */ new Map();
1876
- constructor(transport, tenant, timeoutMs = 1e4, capabilityTtlMs = 6e4, tenantToken) {
2052
+ constructor(transport, tenant, timeoutMs = 1e4, capabilityTtlMs = 6e4, tenantToken, tenantFilter) {
1877
2053
  this.transport = transport;
1878
2054
  this.tenant = tenant;
1879
2055
  this.timeoutMs = timeoutMs;
1880
2056
  this.capabilityTtlMs = capabilityTtlMs;
1881
2057
  this.tenantToken = tenantToken;
2058
+ this.tenantFilter = tenantFilter;
1882
2059
  this.transport.onRunReply?.((reply) => this.handleReply(reply));
1883
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
+ }
1884
2102
  handleReply(reply) {
1885
2103
  const pending = this.pending.get(reply.requestId);
1886
2104
  if (!pending) return;
@@ -1935,6 +2153,7 @@ var ProxyRunGateway = class {
1935
2153
  * a summarized detail always carries `fans`, so its absence means the summary is made here.
1936
2154
  */
1937
2155
  async getRunDetail(runId, options) {
2156
+ const filter = this.restrictive();
1938
2157
  const detail = await this.request(options === void 0 ? {
1939
2158
  kind: "getRunDetail",
1940
2159
  runId
@@ -1943,6 +2162,7 @@ var ProxyRunGateway = class {
1943
2162
  runId,
1944
2163
  options
1945
2164
  });
2165
+ if (detail && filter && !this.visible(detail.run, filter)) return null;
1946
2166
  const over = options?.summarizeFansOver;
1947
2167
  if (over === void 0 || !detail || detail.fans !== void 0) return detail;
1948
2168
  const { timeline, fans } = summarizeTimeline(detail.timeline, over);
@@ -1957,6 +2177,7 @@ var ProxyRunGateway = class {
1957
2177
  }
1958
2178
  /** Paged from the full detail when the control plane is too old to page a fan itself. */
1959
2179
  async getFanMembers(runId, group, query) {
2180
+ if (this.restrictive() && await this.hidden(runId)) return null;
1960
2181
  if (!this.knownUnsupported("getFanMembers")) {
1961
2182
  try {
1962
2183
  const page = await this.request({
@@ -1982,6 +2203,9 @@ var ProxyRunGateway = class {
1982
2203
  * to know the verb: it then answers with no data, or with an unsupported-request error.
1983
2204
  */
1984
2205
  async getRun(runId) {
2206
+ return this.visible(await this.getRunUnscoped(runId));
2207
+ }
2208
+ async getRunUnscoped(runId) {
1985
2209
  if (!this.knownUnsupported("getRun")) {
1986
2210
  try {
1987
2211
  const run = await this.request({
@@ -2010,27 +2234,27 @@ var ProxyRunGateway = class {
2010
2234
  /** The control plane's `StoreRunGateway` resolves each run's `waiting` descriptor; the reply carries
2011
2235
  * it through as plain JSON, so a tenant's list rows name the wait too. */
2012
2236
  listRuns(query) {
2013
- return this.request({
2237
+ return this.scoped(query, (q) => this.request({
2014
2238
  kind: "listRuns",
2015
- query
2016
- });
2239
+ query: q
2240
+ }));
2017
2241
  }
2018
2242
  /** Counted on the operator, over the same tenant-scoped predicates its `listRuns` reply obeys. */
2019
2243
  runFacets(query) {
2020
- return this.request({
2244
+ return this.scoped(query, (q) => this.request({
2021
2245
  kind: "runFacets",
2022
- query
2023
- });
2246
+ query: q
2247
+ }));
2024
2248
  }
2025
2249
  /** Enumerated on the operator, over the same tenant-scoped predicates its `listRuns` reply obeys —
2026
2250
  * so a tenant's pickers offer its own tenants/tags/attributes and never another's. */
2027
2251
  runValueFacets(axis, query, opts) {
2028
- return this.request({
2252
+ return this.scoped(query, (q) => this.request({
2029
2253
  kind: "runValueFacets",
2030
2254
  axis,
2031
- query,
2255
+ query: q,
2032
2256
  opts
2033
- });
2257
+ }));
2034
2258
  }
2035
2259
  /** Round-trips to the operator, which scopes the result to this tenant's own `@<tenant>` groups. */
2036
2260
  workerHealth() {
@@ -2047,39 +2271,39 @@ var ProxyRunGateway = class {
2047
2271
  });
2048
2272
  }
2049
2273
  cancel(runId, opts) {
2050
- return this.request(opts === void 0 ? {
2274
+ return this.guarded(runId, () => this.request(opts === void 0 ? {
2051
2275
  kind: "cancel",
2052
2276
  runId
2053
2277
  } : {
2054
2278
  kind: "cancel",
2055
2279
  runId,
2056
2280
  opts
2057
- });
2281
+ }));
2058
2282
  }
2059
2283
  retry(runId) {
2060
- return this.request({
2284
+ return this.guarded(runId, () => this.request({
2061
2285
  kind: "retry",
2062
2286
  runId
2063
- });
2287
+ }));
2064
2288
  }
2065
2289
  continue(runId) {
2066
- return this.request({
2290
+ return this.guarded(runId, () => this.request({
2067
2291
  kind: "continue",
2068
2292
  runId
2069
- });
2293
+ }));
2070
2294
  }
2071
2295
  retryWithInput(runId, input) {
2072
- return this.request({
2296
+ return this.guarded(runId, () => this.request({
2073
2297
  kind: "retryWithInput",
2074
2298
  runId,
2075
2299
  input
2076
- });
2300
+ }));
2077
2301
  }
2078
2302
  redispatchPending(runId) {
2079
- return this.request({
2303
+ return this.guarded(runId, () => this.request({
2080
2304
  kind: "redispatch",
2081
2305
  runId
2082
- });
2306
+ }));
2083
2307
  }
2084
2308
  /**
2085
2309
  * Republished on the control plane: a one-run target is checked against this tenant like
@@ -2133,7 +2357,8 @@ ProxyRunGateway = _ts_decorate6([
2133
2357
  String,
2134
2358
  void 0,
2135
2359
  void 0,
2136
- typeof TenantTokenSource === "undefined" ? Object : TenantTokenSource
2360
+ typeof TenantTokenSource === "undefined" ? Object : TenantTokenSource,
2361
+ Function
2137
2362
  ])
2138
2363
  ], ProxyRunGateway);
2139
2364
 
@@ -2840,111 +3065,6 @@ StoreRunGateway = _ts_decorate9([
2840
3065
  ])
2841
3066
  ], StoreRunGateway);
2842
3067
 
2843
- // src/tenancy.ts
2844
- var SLOT = Symbol.for("@dudousxd/nestjs-diagnostics:accessor");
2845
- function accessorOf(accessor) {
2846
- if (accessor) return accessor;
2847
- const slot = globalThis[SLOT];
2848
- return slot?.current ?? void 0;
2849
- }
2850
- __name(accessorOf, "accessorOf");
2851
- function readTenancy(option, accessor) {
2852
- const a = accessorOf(accessor);
2853
- if (option === false || typeof a?.tenancy !== "function" || typeof a.tenantFilter !== "function") {
2854
- return {
2855
- enabled: false
2856
- };
2857
- }
2858
- const own = typeof option === "object" ? option : {};
2859
- const inherit = own.enabled === void 0 || own.enabled === "inherit";
2860
- if (!(inherit ? a.tenancy().enabled : own.enabled)) return {
2861
- enabled: false
2862
- };
2863
- const kinds = own.kinds;
2864
- const tenantFilter = a.tenantFilter.bind(a);
2865
- return {
2866
- enabled: true,
2867
- nullRows: own.nullRows ?? "tenantless",
2868
- filter: /* @__PURE__ */ __name(() => tenantFilter(kinds ? {
2869
- kinds
2870
- } : void 0), "filter")
2871
- };
2872
- }
2873
- __name(readTenancy, "readTenancy");
2874
- function isTenantRuntime(x) {
2875
- return !!x && typeof x.withTenant === "function";
2876
- }
2877
- __name(isTenantRuntime, "isTenantRuntime");
2878
- function restore(runtime, tenant, fn) {
2879
- return runtime.withTenant({
2880
- id: tenant.id,
2881
- kind: tenant.kind ?? "unknown",
2882
- source: "carrier"
2883
- }, fn);
2884
- }
2885
- __name(restore, "restore");
2886
- function buildEngineTenancy(option, accessor, runtime) {
2887
- if (option === false || !runtime) return void 0;
2888
- return {
2889
- current() {
2890
- const t = readTenancy(option, accessor);
2891
- if (!t.enabled) return void 0;
2892
- const f = t.filter();
2893
- return f.mode === "tenant" ? {
2894
- id: f.tenant.id,
2895
- kind: f.tenant.kind
2896
- } : void 0;
2897
- },
2898
- filter() {
2899
- const t = readTenancy(option, accessor);
2900
- if (!t.enabled) return {
2901
- mode: "system"
2902
- };
2903
- const f = t.filter();
2904
- if (f.mode === "tenant") return {
2905
- mode: "tenant",
2906
- tenantId: f.tenant.id,
2907
- nullRows: t.nullRows
2908
- };
2909
- if (f.mode === "tenantless") return {
2910
- mode: "tenantless"
2911
- };
2912
- return f.mode === "all" ? {
2913
- mode: "all"
2914
- } : {
2915
- mode: "system"
2916
- };
2917
- },
2918
- run: /* @__PURE__ */ __name((tenant, fn) => restore(runtime, tenant, fn), "run")
2919
- };
2920
- }
2921
- __name(buildEngineTenancy, "buildEngineTenancy");
2922
- function tenantFromCarrier(carrier) {
2923
- const ref = carrier?.tenant;
2924
- if (ref && typeof ref.id === "string") {
2925
- return typeof ref.kind === "string" ? {
2926
- id: ref.id,
2927
- kind: ref.kind
2928
- } : {
2929
- id: ref.id
2930
- };
2931
- }
2932
- const id = carrier?.tenantId;
2933
- return typeof id === "string" ? {
2934
- id
2935
- } : void 0;
2936
- }
2937
- __name(tenantFromCarrier, "tenantFromCarrier");
2938
- function stepTenantWrapper(option, accessor, runtime) {
2939
- return (execution, next) => {
2940
- if (execution.unit !== "step") return next();
2941
- const tenant = tenantFromCarrier(execution.context);
2942
- if (!tenant || !readTenancy(option, accessor).enabled) return next();
2943
- return restore(runtime, tenant, next);
2944
- };
2945
- }
2946
- __name(stepTenantWrapper, "stepTenantWrapper");
2947
-
2948
3068
  // src/tenant-event-republisher.ts
2949
3069
  function isTerminalRunEvent(event) {
2950
3070
  return event.type === "run.completed" || event.type === "run.failed";
@@ -3741,10 +3861,10 @@ var DurableTenancyBridge = class DurableTenancyBridge2 {
3741
3861
  async onApplicationBootstrap() {
3742
3862
  if (this.options.tenancy === false) return;
3743
3863
  const accessor = resolveAccessor(this.moduleRef);
3744
- if (!readTenancy(this.options.tenancy, accessor).enabled) return;
3864
+ if (!readTenancy2(this.options.tenancy, accessor).enabled) return;
3745
3865
  const runtime = await resolveContextRuntime();
3746
- if (!isTenantRuntime(runtime)) return;
3747
- 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));
3748
3868
  }
3749
3869
  onModuleDestroy() {
3750
3870
  this.unregister?.();
@@ -3848,7 +3968,7 @@ var DurableModule = class _DurableModule {
3848
3968
  ...auth.tenantToken !== void 0 ? {
3849
3969
  tenantToken: auth.tenantToken
3850
3970
  } : {}
3851
- });
3971
+ }, void 0, resolveAccessor(moduleRef));
3852
3972
  }
3853
3973
  if (!store) {
3854
3974
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
@@ -3935,20 +4055,21 @@ var DurableModule = class _DurableModule {
3935
4055
  // gateway whose every method rejects with a clear tenant error.
3936
4056
  {
3937
4057
  provide: RunGateway2,
3938
- useFactory: /* @__PURE__ */ __name((options, store, engine, auth) => {
4058
+ useFactory: /* @__PURE__ */ __name((options, store, engine, auth, moduleRef) => {
3939
4059
  if (options.store !== void 0) {
3940
4060
  if (!store) {
3941
4061
  throw new Error("unreachable: STATE_STORE_CANONICAL must resolve a store when options.store is set");
3942
4062
  }
3943
4063
  return new StoreRunGateway(store, engine);
3944
4064
  }
3945
- 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();
3946
4066
  }, "useFactory"),
3947
4067
  inject: [
3948
4068
  DURABLE_OPTIONS_CANONICAL8,
3949
4069
  STATE_STORE_CANONICAL4,
3950
4070
  WorkflowEngine6,
3951
- TENANT_AUTH
4071
+ TENANT_AUTH,
4072
+ ModuleRef2
3952
4073
  ]
3953
4074
  },
3954
4075
  RunGatewayBootstrap,