@authhero/multi-tenancy 14.25.1 → 14.27.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/multi-tenancy.cjs +1 -1
- package/dist/multi-tenancy.mjs +435 -181
- package/dist/types/hooks/provisioning.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/operations/enqueue.d.ts +17 -0
- package/dist/types/operations/enqueue.d.ts.map +1 -0
- package/dist/types/operations/index.d.ts +9 -0
- package/dist/types/operations/index.d.ts.map +1 -0
- package/dist/types/operations/inline-executor.d.ts +40 -0
- package/dist/types/operations/inline-executor.d.ts.map +1 -0
- package/dist/types/operations/instance-id.d.ts +6 -0
- package/dist/types/operations/instance-id.d.ts.map +1 -0
- package/dist/types/operations/record-provision.d.ts +20 -0
- package/dist/types/operations/record-provision.d.ts.map +1 -0
- package/dist/types/operations/recorder.d.ts +29 -0
- package/dist/types/operations/recorder.d.ts.map +1 -0
- package/dist/types/operations/types.d.ts +59 -0
- package/dist/types/operations/types.d.ts.map +1 -0
- package/dist/types/routes/tenants.d.ts.map +1 -1
- package/dist/types/types.d.ts +17 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provisioning.d.ts","sourceRoot":"","sources":["../../../src/hooks/provisioning.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provisioning.d.ts","sourceRoot":"","sources":["../../../src/hooks/provisioning.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAGlB;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,kBAAkB,GACzB,iBAAiB,CAiHnB"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { initMultiTenant } from "./init";
|
|
|
5
5
|
export type { MultiTenantConfig, MultiTenantResult, ControlPlaneConfig, } from "./init";
|
|
6
6
|
export { createDirectRolloutAdapter, projectControlPlaneDefaults, buildControlPlaneDefaultsPayload, applyControlPlaneDefaultsPayload, } from "./rollout";
|
|
7
7
|
export type { ControlPlaneRolloutAdapter, DefaultsProjectionConfig, DefaultsProjectionEntities, DefaultsProjectionResult, EntityProjectionOutcome, ProjectableDefaults, ControlPlaneDefaultsPayload, ControlPlaneDefaultsApplyResult, ControlPlaneTenantSeed, DefaultsPayloadEntities, } from "./rollout";
|
|
8
|
+
export * from "./operations";
|
|
8
9
|
export { createSyncHooks } from "./hooks/sync";
|
|
9
10
|
export type { EntitySyncConfig, SyncHooksResult } from "./hooks/sync";
|
|
10
11
|
export { createTenantsOpenAPIRouter } from "./routes";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAajB,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,QAAQ,CAAC;AAKhB,OAAO,EACL,0BAA0B,EAC1B,2BAA2B,EAC3B,gCAAgC,EAChC,gCAAgC,GACjC,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,mBAAmB,EACnB,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"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,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,kBAAkB,GACzB,iBAAiB,CAgBnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB;cAE/C,oBAAoB;eACnB,qBAAqB;0CASnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB;;;;;;;kBAnD9C,oBAAoB;mBACnB,qBAAqB;;;IAwDhC;;;;;;;OAOG;6BAES,OAAO,UAAU,EAAE,YAAY,qBACtB;QAAE,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAAE;EAOzD"}
|
package/dist/types/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,cAAc,EAEd,YAAY,EAGb,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,cAAc,EAEd,YAAY,EAGb,MAAM,UAAU,CAAC;AAWlB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAC7C,cAAc,EACd,aAAa,GAAG,yBAAyB,CAC1C;IACC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAElC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAE3C;;;;OAIG;IACH,IAAI,CAAC,EACD;QACE,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,GACD,KAAK,CAAC;IAEV;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE9B;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;OAGG;IACH,uBAAuB,CAAC,EAAE,cAAc,CAAC,yBAAyB,CAAC,CAAC;IAEpE;;;OAGG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;IAE5C;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE5C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,8BAA8B;IAC9B,GAAG,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;IACpC,kCAAkC;IAClC,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,CA+N5E"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TenantOperation } from "authhero";
|
|
2
|
+
import { EnqueueTenantOperationParams, TenantOperationExecutor, TenantOperationStores } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Persist a new operation row and stamp its deterministic engine instance
|
|
5
|
+
* id. Shared by the executor enqueue path and the inline recording wrapper
|
|
6
|
+
* (`runRecordedTenantOperation`) so the row-first setup can't drift.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createOperationRow(stores: TenantOperationStores, params: EnqueueTenantOperationParams, engine: TenantOperationExecutor["engine"]): Promise<TenantOperation>;
|
|
9
|
+
/**
|
|
10
|
+
* Row-first enqueue: persist the operation as `pending`, write the
|
|
11
|
+
* deterministic engine instance id, then hand it to the executor. If
|
|
12
|
+
* `start` throws, the row is marked failed (unless the executor already
|
|
13
|
+
* finalized it) and the error is rethrown so callers keep their existing
|
|
14
|
+
* failure semantics.
|
|
15
|
+
*/
|
|
16
|
+
export declare function enqueueTenantOperation(stores: TenantOperationStores, executor: TenantOperationExecutor, params: EnqueueTenantOperationParams): Promise<TenantOperation>;
|
|
17
|
+
//# sourceMappingURL=enqueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enqueue.d.ts","sourceRoot":"","sources":["../../../src/operations/enqueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAIjB;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,qBAAqB,EAC7B,MAAM,EAAE,4BAA4B,EACpC,MAAM,EAAE,uBAAuB,CAAC,QAAQ,CAAC,GACxC,OAAO,CAAC,eAAe,CAAC,CAyB1B;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,EAAE,uBAAuB,EACjC,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,eAAe,CAAC,CAgC1B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { StepConfig, StepRunner, StepReporter, TenantOperationStores, TenantOperationExecutor, EnqueueTenantOperationParams, } from "./types";
|
|
2
|
+
export { buildEngineInstanceId } from "./instance-id";
|
|
3
|
+
export { createOperationRecorder, errorToMessage, isTerminalStatus, } from "./recorder";
|
|
4
|
+
export type { OperationRecorder } from "./recorder";
|
|
5
|
+
export { createInlineExecutor, inlineStepRunner } from "./inline-executor";
|
|
6
|
+
export type { InlineExecutorConfig, TenantOperationDefinitions, TenantOperationStep, TenantOperationStepContext, } from "./inline-executor";
|
|
7
|
+
export { enqueueTenantOperation } from "./enqueue";
|
|
8
|
+
export { runRecordedTenantOperation } from "./record-provision";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/operations/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,YAAY,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TenantOperation, TenantOperationKind } from "authhero";
|
|
2
|
+
import { StepRunner, TenantOperationExecutor, TenantOperationStores } from "./types";
|
|
3
|
+
export interface TenantOperationStepContext {
|
|
4
|
+
operation: TenantOperation;
|
|
5
|
+
step: StepRunner;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A named, idempotent unit of work. The resolved value (when a plain
|
|
9
|
+
* object) is stored as the succeeded-event detail.
|
|
10
|
+
*/
|
|
11
|
+
export interface TenantOperationStep {
|
|
12
|
+
name: string;
|
|
13
|
+
run(ctx: TenantOperationStepContext): Promise<Record<string, unknown> | void>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Maps an operation kind to its ordered steps. Factories receive the
|
|
17
|
+
* operation row so steps can read the target tenant / versions — but they
|
|
18
|
+
* must resolve all heavy dependencies from their own closure, never from
|
|
19
|
+
* serialized state.
|
|
20
|
+
*/
|
|
21
|
+
export type TenantOperationDefinitions = Partial<Record<TenantOperationKind, (operation: TenantOperation) => TenantOperationStep[]>>;
|
|
22
|
+
/**
|
|
23
|
+
* Trivial StepRunner: no retries, no durability — runs the function
|
|
24
|
+
* immediately. Used by the inline executor so operation definitions are
|
|
25
|
+
* written against the same `StepRunner` seam the Workflows engine
|
|
26
|
+
* satisfies in phase 2.
|
|
27
|
+
*/
|
|
28
|
+
export declare const inlineStepRunner: StepRunner;
|
|
29
|
+
export interface InlineExecutorConfig {
|
|
30
|
+
stores: TenantOperationStores;
|
|
31
|
+
definitions: TenantOperationDefinitions;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runs operations synchronously in the calling process, writing the same
|
|
35
|
+
* operation/event rows the durable executor writes. Used by tests and
|
|
36
|
+
* deployments without Cloudflare Workflows; `enqueueTenantOperation`
|
|
37
|
+
* resolves only after the run reaches a terminal status.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createInlineExecutor(config: InlineExecutorConfig): TenantOperationExecutor;
|
|
40
|
+
//# sourceMappingURL=inline-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-executor.d.ts","sourceRoot":"","sources":["../../../src/operations/inline-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAGjB,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,eAAe,CAAC;IAC3B,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,GAAG,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;CAC/E;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAC9C,MAAM,CACJ,mBAAmB,EACnB,CAAC,SAAS,EAAE,eAAe,KAAK,mBAAmB,EAAE,CACtD,CACF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,UAe9B,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,WAAW,EAAE,0BAA0B,CAAC;CACzC;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,oBAAoB,GAC3B,uBAAuB,CAiDzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-id.d.ts","sourceRoot":"","sources":["../../../src/operations/instance-id.ts"],"names":[],"mappings":"AAiBA,wBAAgB,qBAAqB,CAAC,SAAS,EAAE;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;CACZ,GAAG,MAAM,CAcT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DataAdapters } from "authhero";
|
|
2
|
+
import { EnqueueTenantOperationParams, StepReporter } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Wraps an existing inline lifecycle flow (today: the provisioning hook)
|
|
5
|
+
* so it is recorded as a tenant operation with step events — with NO
|
|
6
|
+
* behavior change:
|
|
7
|
+
*
|
|
8
|
+
* - When the operations adapters are absent, `fn` runs exactly as before.
|
|
9
|
+
* - Recording writes are best-effort (warn-only): a broken control-plane
|
|
10
|
+
* log must never block or fail a provision. This mirrors the existing
|
|
11
|
+
* markFailed philosophy in the WFP tenant hook.
|
|
12
|
+
* - `fn`'s error is always rethrown, preserving the caller's rollback
|
|
13
|
+
* semantics.
|
|
14
|
+
*
|
|
15
|
+
* `fn` receives a StepReporter it may call at step boundaries; if it never
|
|
16
|
+
* does (e.g. a custom onProvision that ignores the parameter), a single
|
|
17
|
+
* coarse step named after the operation kind is recorded instead.
|
|
18
|
+
*/
|
|
19
|
+
export declare function runRecordedTenantOperation(adapters: DataAdapters, params: EnqueueTenantOperationParams, fn: (report: StepReporter | undefined) => Promise<void>): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=record-provision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-provision.d.ts","sourceRoot":"","sources":["../../../src/operations/record-provision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACL,4BAA4B,EAC5B,YAAY,EAEb,MAAM,SAAS,CAAC;AAcjB;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,4BAA4B,EACpC,EAAE,EAAE,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GACtD,OAAO,CAAC,IAAI,CAAC,CAmEf"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TenantOperation } from "authhero";
|
|
2
|
+
import { TenantOperationStores } from "./types";
|
|
3
|
+
export declare function errorToMessage(error: unknown): string;
|
|
4
|
+
/**
|
|
5
|
+
* Write-back helpers for the operation log, callable with just stores and
|
|
6
|
+
* an operation id. All writes are idempotent (safe under workflow-step
|
|
7
|
+
* replay): status transitions rewrite the same values, and duplicate
|
|
8
|
+
* events are harmless in an append-only step history.
|
|
9
|
+
*
|
|
10
|
+
* These helpers throw on write failure — in the executor path the log IS
|
|
11
|
+
* the deliverable. Callers that must never let recording break the actual
|
|
12
|
+
* work (the provisioning recording wrapper) catch and warn instead.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createOperationRecorder(stores: TenantOperationStores): {
|
|
15
|
+
markRunning(operationId: string, currentStep?: string): Promise<void>;
|
|
16
|
+
setCurrentStep(operationId: string, step: string): Promise<void>;
|
|
17
|
+
appendEvent(operationId: string, event: {
|
|
18
|
+
step: string;
|
|
19
|
+
outcome: "started" | "succeeded" | "failed" | "retried" | "skipped" | "reconciled";
|
|
20
|
+
detail?: Record<string, unknown>;
|
|
21
|
+
attempt?: number;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
markSucceeded(operationId: string): Promise<void>;
|
|
24
|
+
markFailed(operationId: string, error: unknown): Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
export type OperationRecorder = ReturnType<typeof createOperationRecorder>;
|
|
27
|
+
/** True when the operation can no longer transition (reconciler guard). */
|
|
28
|
+
export declare function isTerminalStatus(status: TenantOperation["status"]): boolean;
|
|
29
|
+
//# sourceMappingURL=recorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../../../src/operations/recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAIhD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAcrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,qBAAqB;6BAIlC,MAAM,gBAAgB,MAAM;gCAOzB,MAAM,QAAQ,MAAM;6BAKvC,MAAM,SACZ;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EACH,SAAS,GACT,WAAW,GACX,QAAQ,GACR,SAAS,GACT,SAAS,GACT,YAAY,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACjC,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;+BAW8B,MAAM;4BAQT,MAAM,SAAS,OAAO;EAQvD;AAED,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE3E,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,OAAO,CAI3E"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TenantOperation, TenantOperationEventsAdapter, TenantOperationKind, TenantOperationsAdapter } from "authhero";
|
|
2
|
+
/**
|
|
3
|
+
* Structural subset of Cloudflare Workflows' `WorkflowStepConfig`, kept
|
|
4
|
+
* platform-agnostic so operation orchestration can run against any engine.
|
|
5
|
+
*/
|
|
6
|
+
export interface StepConfig {
|
|
7
|
+
retries?: {
|
|
8
|
+
limit: number;
|
|
9
|
+
delay: string | number;
|
|
10
|
+
backoff?: "constant" | "linear" | "exponential";
|
|
11
|
+
};
|
|
12
|
+
timeout?: string | number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Structural subset of Cloudflare Workflows' `WorkflowStep`. The inline
|
|
16
|
+
* executor runs steps through a trivial implementation; the Workflows
|
|
17
|
+
* executor passes the engine's own `step` object, which satisfies this
|
|
18
|
+
* type structurally.
|
|
19
|
+
*/
|
|
20
|
+
export interface StepRunner {
|
|
21
|
+
do<T>(name: string, fn: () => Promise<T>): Promise<T>;
|
|
22
|
+
do<T>(name: string, config: StepConfig, fn: () => Promise<T>): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
/** The control-plane stores every operation write goes through. */
|
|
25
|
+
export interface TenantOperationStores {
|
|
26
|
+
tenantOperations: TenantOperationsAdapter;
|
|
27
|
+
tenantOperationEvents: TenantOperationEventsAdapter;
|
|
28
|
+
}
|
|
29
|
+
export interface EnqueueTenantOperationParams {
|
|
30
|
+
kind: TenantOperationKind;
|
|
31
|
+
/** Target tenant; null for fleet-level operations. */
|
|
32
|
+
tenant_id: string | null;
|
|
33
|
+
rollout_id?: string;
|
|
34
|
+
initiated_by?: string;
|
|
35
|
+
target_worker_version?: string;
|
|
36
|
+
target_database_version?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Executes an already-persisted operation row. Row-first contract: the
|
|
40
|
+
* caller (`enqueueTenantOperation`) creates the row and writes the
|
|
41
|
+
* deterministic `engine_instance_id` before calling `start`, so a crashed
|
|
42
|
+
* enqueue can never leave an untracked engine instance.
|
|
43
|
+
*
|
|
44
|
+
* - Inline executor: `start` runs the steps to a terminal status before
|
|
45
|
+
* resolving.
|
|
46
|
+
* - Cloudflare Workflows executor (phase 2): `start` returns as soon as
|
|
47
|
+
* the instance is created; the workflow owns all further writes.
|
|
48
|
+
*/
|
|
49
|
+
export interface TenantOperationExecutor {
|
|
50
|
+
readonly engine: "inline" | "cloudflare-workflows";
|
|
51
|
+
start(operation: TenantOperation): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Step-boundary callback threaded through provisioning hooks so the
|
|
55
|
+
* existing inline provision flow can report coarse step outcomes without
|
|
56
|
+
* depending on this package (implementations accept it structurally).
|
|
57
|
+
*/
|
|
58
|
+
export type StepReporter = (step: string, outcome: "started" | "succeeded" | "failed", detail?: Record<string, unknown>) => Promise<void>;
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/operations/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,4BAA4B,EAC5B,mBAAmB,EACnB,uBAAuB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AG,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,EAC3C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../../../src/routes/tenants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"tenants.d.ts","sourceRoot":"","sources":["../../../src/routes/tenants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAWhE,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAwClB;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,iBAAiB;cAGZ,oBAAoB;eACnB,qBAAqB;YAshBnC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CreateTenantParams, DataAdapters, Tenant } from "authhero";
|
|
2
2
|
import { Context } from "hono";
|
|
3
|
+
import type { StepReporter } from "./operations/types";
|
|
3
4
|
/**
|
|
4
5
|
* Bindings type from authhero core - simplified version for this package
|
|
5
6
|
*/
|
|
@@ -114,6 +115,11 @@ export interface DatabaseIsolationConfig {
|
|
|
114
115
|
*
|
|
115
116
|
* @param tenantId - The ID of the newly created tenant
|
|
116
117
|
*
|
|
118
|
+
* When the control plane carries the tenant-operations adapters, the
|
|
119
|
+
* hook receives an optional `StepReporter` — call it at step boundaries
|
|
120
|
+
* to surface per-step events in the operation history (issue #1026).
|
|
121
|
+
* Implementations may ignore it; a single coarse step is recorded then.
|
|
122
|
+
*
|
|
117
123
|
* @example
|
|
118
124
|
* ```typescript
|
|
119
125
|
* onProvision: async (tenantId) => {
|
|
@@ -123,7 +129,17 @@ export interface DatabaseIsolationConfig {
|
|
|
123
129
|
* }
|
|
124
130
|
* ```
|
|
125
131
|
*/
|
|
126
|
-
onProvision?: (tenantId: string) => Promise<void>;
|
|
132
|
+
onProvision?: (tenantId: string, report?: StepReporter) => Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Whether `afterCreate` wraps `onProvision` in
|
|
135
|
+
* `runRecordedTenantOperation` (default true). Set to `false` when the
|
|
136
|
+
* hook manages its own operation rows — e.g.
|
|
137
|
+
* `createWfpWorkflowProvisioningHook`, whose durable workflow creates
|
|
138
|
+
* and finalizes the operation itself; the wrapper would otherwise write
|
|
139
|
+
* a second, immediately-"succeeded" row for a run that is still in
|
|
140
|
+
* flight on the engine.
|
|
141
|
+
*/
|
|
142
|
+
recordProvisionOperations?: boolean;
|
|
127
143
|
/**
|
|
128
144
|
* Called when a tenant is being deleted to cleanup its database.
|
|
129
145
|
* Use this to delete the database, backup data, etc.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,YAAY,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,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C;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/markusahlstrand/authhero"
|
|
13
13
|
},
|
|
14
|
-
"version": "14.
|
|
14
|
+
"version": "14.27.0",
|
|
15
15
|
"description": "Multi-tenancy support for AuthHero with organization-based access control and per-tenant database isolation",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"typescript": "^5.6.0",
|
|
37
37
|
"vite": "^8.0.14",
|
|
38
38
|
"vitest": "^4.1.7",
|
|
39
|
-
"@authhero/adapter-interfaces": "3.
|
|
40
|
-
"
|
|
41
|
-
"authhero": "
|
|
39
|
+
"@authhero/adapter-interfaces": "3.8.0",
|
|
40
|
+
"authhero": "8.18.0",
|
|
41
|
+
"@authhero/kysely-adapter": "11.14.2"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"zod": "^4.4.3"
|