clinkx 1.2.0 → 1.3.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/CHANGELOG.md +32 -0
- package/README.md +4 -2
- package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
- package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
- package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
- package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
- package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
- package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
- package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
- package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
- package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
- package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
- package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
- package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
- package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
- package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
- package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
- package/clinkx-workflows/dist/artifacts.d.ts +19 -4
- package/clinkx-workflows/dist/artifacts.js +16 -7
- package/clinkx-workflows/dist/artifacts.js.map +1 -1
- package/clinkx-workflows/dist/backend.d.ts +30 -0
- package/clinkx-workflows/dist/clink-client.d.ts +8 -2
- package/clinkx-workflows/dist/clink-client.js +4 -2
- package/clinkx-workflows/dist/clink-client.js.map +1 -1
- package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
- package/clinkx-workflows/dist/context-preflight.js.map +1 -1
- package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
- package/clinkx-workflows/dist/council-execution-policy.js +4 -0
- package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
- package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
- package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DRId2DVA.js +119 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-CHAw57y5.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
- package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
- package/clinkx-workflows/dist/delegate-signature.js +4 -3
- package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
- package/clinkx-workflows/dist/durable-file.d.ts +69 -0
- package/clinkx-workflows/dist/durable-file.js +145 -0
- package/clinkx-workflows/dist/durable-file.js.map +1 -0
- package/clinkx-workflows/dist/engine.d.ts +42 -7
- package/clinkx-workflows/dist/engine.js +196 -24
- package/clinkx-workflows/dist/engine.js.map +1 -1
- package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
- package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
- package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
- package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
- package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
- package/clinkx-workflows/dist/ping-pong/control.js +12 -0
- package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
- package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
- package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
- package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
- package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
- package/clinkx-workflows/dist/plan-review/publication.js +5 -6
- package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
- package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
- package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
- package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
- package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
- package/clinkx-workflows/dist/recipe-host.js +183 -0
- package/clinkx-workflows/dist/recipe-host.js.map +1 -0
- package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
- package/clinkx-workflows/dist/recipe-seats.js +163 -0
- package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
- package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
- package/clinkx-workflows/dist/reducers/index.js +30 -0
- package/clinkx-workflows/dist/reducers/index.js.map +1 -1
- package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
- package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
- package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
- package/clinkx-workflows/dist/state-schema.d.ts +11 -0
- package/clinkx-workflows/dist/state-schema.js +4 -1
- package/clinkx-workflows/dist/state-schema.js.map +1 -1
- package/clinkx-workflows/dist/state.d.ts +178 -3
- package/clinkx-workflows/dist/state.js +618 -83
- package/clinkx-workflows/dist/state.js.map +1 -1
- package/clinkx-workflows/dist/transport.d.ts +2 -1
- package/clinkx-workflows/dist/transport.js +5 -0
- package/clinkx-workflows/dist/transport.js.map +1 -1
- package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
- package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
- package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
- package/clinkx-workflows/dist/validators/index.js +4 -0
- package/clinkx-workflows/dist/validators/index.js.map +1 -1
- package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
- package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
- package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
- package/clinkx-workflows/dist/workflow-tools.d.ts +51 -5
- package/clinkx-workflows/dist/workflow-tools.js +785 -34
- package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
- package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
- package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
- package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
- package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
- package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
- package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
- package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
- package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
- package/dist/context-builder/bundle.js +4 -3
- package/dist/context-builder/bundle.js.map +1 -1
- package/dist/context-builder/delegate-packet.d.ts +1 -0
- package/dist/context-builder/delegate-packet.js +66 -7
- package/dist/context-builder/delegate-packet.js.map +1 -1
- package/dist/context-builder/delegate-validation.d.ts +12 -3
- package/dist/context-builder/delegate-validation.js +23 -13
- package/dist/context-builder/delegate-validation.js.map +1 -1
- package/dist/context-builder/external-gaps.d.ts +14 -3
- package/dist/context-builder/external-gaps.js +124 -18
- package/dist/context-builder/external-gaps.js.map +1 -1
- package/dist/context-builder/handler.js +108 -191
- package/dist/context-builder/handler.js.map +1 -1
- package/dist/context-builder/review-coverage.js +27 -1
- package/dist/context-builder/review-coverage.js.map +1 -1
- package/dist/context-builder/secrets.js +1 -1
- package/dist/context-builder/secrets.js.map +1 -1
- package/dist/context-builder/versions.d.ts +10 -4
- package/dist/context-builder/versions.js +10 -4
- package/dist/context-builder/versions.js.map +1 -1
- package/dist/context-builder/workflow-runner.js +33 -24
- package/dist/context-builder/workflow-runner.js.map +1 -1
- package/dist/dashboard-cli.d.ts +2 -0
- package/dist/dashboard-cli.js +147 -57
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/client.d.ts +10 -0
- package/dist/dashboard-companion/client.js +43 -1
- package/dist/dashboard-companion/client.js.map +1 -1
- package/dist/dashboard-companion/config.d.ts +19 -1
- package/dist/dashboard-companion/config.js +104 -3
- package/dist/dashboard-companion/config.js.map +1 -1
- package/dist/dashboard-companion/protocol.d.ts +16 -0
- package/dist/dashboard-companion/protocol.js +38 -1
- package/dist/dashboard-companion/protocol.js.map +1 -1
- package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
- package/dist/dashboard-companion/workstation-binding.js +192 -0
- package/dist/dashboard-companion/workstation-binding.js.map +1 -0
- package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
- package/dist/dashboard-gateway/admin-cli.js +266 -0
- package/dist/dashboard-gateway/admin-cli.js.map +1 -0
- package/dist/dashboard-gateway/config.d.ts +50 -0
- package/dist/dashboard-gateway/config.js +235 -1
- package/dist/dashboard-gateway/config.js.map +1 -1
- package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
- package/dist/dashboard-gateway/connection-registry.js +228 -0
- package/dist/dashboard-gateway/connection-registry.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
- package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
- package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
- package/dist/dashboard-gateway/control-plane/billing.js +787 -0
- package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
- package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
- package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
- package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
- package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
- package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
- package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
- package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
- package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
- package/dist/dashboard-gateway/control-plane/errors.js +23 -0
- package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
- package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
- package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
- package/dist/dashboard-gateway/control-plane/http.js +331 -0
- package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
- package/dist/dashboard-gateway/control-plane/schema.js +247 -0
- package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
- package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
- package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
- package/dist/dashboard-gateway/control-plane/store.js +1115 -0
- package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
- package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
- package/dist/dashboard-gateway/cookie-boundary.js +205 -0
- package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
- package/dist/dashboard-gateway/index.js +271 -494
- package/dist/dashboard-gateway/index.js.map +1 -1
- package/dist/dashboard-gateway/main.js +7 -2
- package/dist/dashboard-gateway/main.js.map +1 -1
- package/dist/dashboard-gateway/routing.d.ts +43 -0
- package/dist/dashboard-gateway/routing.js +65 -0
- package/dist/dashboard-gateway/routing.js.map +1 -0
- package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
- package/dist/dashboard-gateway/tenant-gateway.js +989 -0
- package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
- package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
- package/dist/dashboard-gateway/tenant-main.js +303 -0
- package/dist/dashboard-gateway/tenant-main.js.map +1 -0
- package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
- package/dist/dashboard-gateway/tunnel-errors.js +22 -0
- package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
- package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
- package/dist/dashboard-gateway/tunnel-http.js +175 -0
- package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
- package/dist/handler.d.ts +6 -0
- package/dist/handler.js +17 -1
- package/dist/handler.js.map +1 -1
- package/dist/local-clink-backend.d.ts +2 -1
- package/dist/local-clink-backend.js +28 -4
- package/dist/local-clink-backend.js.map +1 -1
- package/dist/parsers/extract.d.ts +19 -1
- package/dist/parsers/extract.js +68 -3
- package/dist/parsers/extract.js.map +1 -1
- package/dist/pipeline.d.ts +17 -1
- package/dist/pipeline.js +34 -6
- package/dist/pipeline.js.map +1 -1
- package/dist/process-group.d.ts +65 -0
- package/dist/process-group.js +153 -0
- package/dist/process-group.js.map +1 -0
- package/dist/progress-report/schema.d.ts +23 -23
- package/dist/project-verification/files.js +1 -1
- package/dist/project-verification/files.js.map +1 -1
- package/dist/project-verification/process.js +23 -44
- package/dist/project-verification/process.js.map +1 -1
- package/dist/project-verification/service.js +9 -1
- package/dist/project-verification/service.js.map +1 -1
- package/dist/prompt.d.ts +7 -0
- package/dist/prompt.js +18 -1
- package/dist/prompt.js.map +1 -1
- package/dist/recipe-host/git-trust.d.ts +43 -0
- package/dist/recipe-host/git-trust.js +360 -0
- package/dist/recipe-host/git-trust.js.map +1 -0
- package/dist/recipe-host/git.d.ts +42 -0
- package/dist/recipe-host/git.js +207 -0
- package/dist/recipe-host/git.js.map +1 -0
- package/dist/recipe-host/native-recipe-host.d.ts +127 -0
- package/dist/recipe-host/native-recipe-host.js +880 -0
- package/dist/recipe-host/native-recipe-host.js.map +1 -0
- package/dist/recipe-host/seat-cwd.d.ts +16 -0
- package/dist/recipe-host/seat-cwd.js +170 -0
- package/dist/recipe-host/seat-cwd.js.map +1 -0
- package/dist/runner.d.ts +43 -1
- package/dist/runner.js +234 -35
- package/dist/runner.js.map +1 -1
- package/dist/server.js +9 -1
- package/dist/server.js.map +1 -1
- package/docs/configuration.md +24 -3
- package/docs/engineering-recipes.md +291 -0
- package/docs/security.md +84 -0
- package/docs/verification/project-checks.md +24 -2
- package/package.json +5 -1
- package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
- package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export const SECRET_BYTES = 32;
|
|
3
|
+
const SECRET_BODY = /^[A-Za-z0-9_-]{43}$/;
|
|
4
|
+
export const SECRET_PREFIX = {
|
|
5
|
+
deviceCredential: "clxd",
|
|
6
|
+
session: "clxs",
|
|
7
|
+
loginBinding: "clxl",
|
|
8
|
+
};
|
|
9
|
+
export function generateOpaqueSecret(prefix) {
|
|
10
|
+
return `${prefix}_${randomBytes(SECRET_BYTES).toString("base64url")}`;
|
|
11
|
+
}
|
|
12
|
+
export function generateNonce() {
|
|
13
|
+
return randomBytes(SECRET_BYTES).toString("base64url");
|
|
14
|
+
}
|
|
15
|
+
export function isOpaqueSecret(prefix, value) {
|
|
16
|
+
return (typeof value === "string" &&
|
|
17
|
+
value.length === prefix.length + 44 &&
|
|
18
|
+
value.startsWith(`${prefix}_`) &&
|
|
19
|
+
SECRET_BODY.test(value.slice(prefix.length + 1)));
|
|
20
|
+
}
|
|
21
|
+
export function deriveVerifier(purpose, secret) {
|
|
22
|
+
return createHash("sha256").update(`clinkx-control-v1\0${purpose}\0${secret}`, "utf8").digest("base64url");
|
|
23
|
+
}
|
|
24
|
+
export function nonceDigest(nonce) {
|
|
25
|
+
return createHash("sha256").update(nonce, "utf8").digest("base64url");
|
|
26
|
+
}
|
|
27
|
+
export function constantTimeEqual(expected, actual) {
|
|
28
|
+
const left = Buffer.from(expected, "utf8");
|
|
29
|
+
const right = Buffer.from(actual, "utf8");
|
|
30
|
+
if (left.length !== right.length) {
|
|
31
|
+
timingSafeEqual(left, left);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return timingSafeEqual(left, right);
|
|
35
|
+
}
|
|
36
|
+
export function generateControlId(prefix) {
|
|
37
|
+
return `${prefix}_${randomBytes(16).toString("base64url")}`;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../../src/dashboard-gateway/control-plane/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAC/B,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,gBAAgB,EAAE,MAAM;IACxB,OAAO,EAAE,MAAM;IACf,YAAY,EAAE,MAAM;CACZ,CAAC;AAaX,MAAM,UAAU,oBAAoB,CAAC,MAAoB;IACvD,OAAO,GAAG,MAAM,IAAI,WAAW,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAoB,EAAE,KAAc;IACjE,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,GAAG,EAAE;QACnC,KAAK,CAAC,UAAU,CAAC,GAAG,MAAM,GAAG,CAAC;QAC9B,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,MAAc;IACrE,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,sBAAsB,OAAO,KAAK,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC7G,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,MAAc;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACtC,CAAC;AAID,MAAM,UAAU,iBAAiB,CAAC,MAAuB;IACvD,OAAO,GAAG,MAAM,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import { MAX_WORKSTATIONS, type SubscriptionState } from "./contracts.js";
|
|
2
|
+
export { MAX_WORKSTATIONS };
|
|
3
|
+
export declare const DEFAULT_BUSY_TIMEOUT_MS = 5000;
|
|
4
|
+
export declare const DEFAULT_MAX_LIVE_PENDING_LOGINS = 10000;
|
|
5
|
+
/** Extended result codes; `@types/node` does not declare `errcode`, so it is narrowed at runtime. */
|
|
6
|
+
export declare const SQLITE_BUSY = 5;
|
|
7
|
+
export declare const SQLITE_CONSTRAINT_UNIQUE = 2067;
|
|
8
|
+
export declare const SQLITE_CONSTRAINT_PRIMARYKEY = 1555;
|
|
9
|
+
export declare function sqliteErrcode(error: unknown): number | undefined;
|
|
10
|
+
export type MembershipRole = "owner";
|
|
11
|
+
export interface AccountRecord {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly issuer: string;
|
|
14
|
+
readonly subject: string;
|
|
15
|
+
readonly displayName: string | null;
|
|
16
|
+
readonly authorityRevision: number;
|
|
17
|
+
}
|
|
18
|
+
/** An account's workspace. */
|
|
19
|
+
export interface TenantRecord {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
}
|
|
22
|
+
export interface MembershipRecord {
|
|
23
|
+
readonly tenant: TenantRecord;
|
|
24
|
+
readonly role: MembershipRole;
|
|
25
|
+
}
|
|
26
|
+
export interface PendingLoginRecord {
|
|
27
|
+
readonly bindingVerifier: string;
|
|
28
|
+
readonly codeVerifier: string;
|
|
29
|
+
readonly nonce: string;
|
|
30
|
+
}
|
|
31
|
+
export type InsertPendingLoginResult = {
|
|
32
|
+
readonly status: "ok" | "rate_limited";
|
|
33
|
+
};
|
|
34
|
+
export type ConsumePendingLoginResult = {
|
|
35
|
+
readonly status: "ok";
|
|
36
|
+
readonly login: PendingLoginRecord;
|
|
37
|
+
} | {
|
|
38
|
+
readonly status: "missing" | "consumed" | "expired";
|
|
39
|
+
};
|
|
40
|
+
export interface SessionInsert {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly verifier: string;
|
|
43
|
+
readonly ttlMs: number;
|
|
44
|
+
}
|
|
45
|
+
export interface AccountSessionContext {
|
|
46
|
+
readonly sessionId: string;
|
|
47
|
+
readonly account: AccountRecord;
|
|
48
|
+
readonly expiresAt: number;
|
|
49
|
+
}
|
|
50
|
+
export interface TenantMemberContext {
|
|
51
|
+
readonly sessionId: string;
|
|
52
|
+
readonly account: AccountRecord;
|
|
53
|
+
readonly tenant: TenantRecord;
|
|
54
|
+
readonly role: MembershipRole;
|
|
55
|
+
readonly expiresAt: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The authenticated principal behind a mutation: an account session. Every
|
|
59
|
+
* state-changing store operation re-checks it inside its own transaction, so
|
|
60
|
+
* authority that lapsed while the request body was in flight cannot reach the write.
|
|
61
|
+
*/
|
|
62
|
+
export interface SessionActor {
|
|
63
|
+
readonly sessionId: string;
|
|
64
|
+
readonly accountId: string;
|
|
65
|
+
/** The account authority revision the session was resolved under. */
|
|
66
|
+
readonly authorityRevision: number;
|
|
67
|
+
}
|
|
68
|
+
export declare function tenantActorOf(context: TenantMemberContext): SessionActor;
|
|
69
|
+
export declare function accountActorOf(context: AccountSessionContext): SessionActor;
|
|
70
|
+
export interface WorkstationRecord {
|
|
71
|
+
readonly companionId: string;
|
|
72
|
+
readonly tenantId: string;
|
|
73
|
+
readonly label: string;
|
|
74
|
+
readonly createdAt: number;
|
|
75
|
+
/** The live key's credential ID, or `null` when the workstation has no unrevoked key. */
|
|
76
|
+
readonly activeCredentialId: string | null;
|
|
77
|
+
readonly keyIssuedAt: number | null;
|
|
78
|
+
}
|
|
79
|
+
/** API keys never expire: a key lives until it is rotated or its workstation is revoked. */
|
|
80
|
+
export interface DeviceCredentialInsert {
|
|
81
|
+
readonly verifier: string;
|
|
82
|
+
}
|
|
83
|
+
export type EnsureWorkspaceResult = {
|
|
84
|
+
readonly status: "ok";
|
|
85
|
+
readonly tenant: TenantRecord;
|
|
86
|
+
readonly created: boolean;
|
|
87
|
+
} | {
|
|
88
|
+
readonly status: "account_missing";
|
|
89
|
+
};
|
|
90
|
+
export type CreateWorkstationResult = {
|
|
91
|
+
readonly status: "ok";
|
|
92
|
+
readonly workstation: WorkstationRecord;
|
|
93
|
+
readonly credentialId: string;
|
|
94
|
+
} | {
|
|
95
|
+
readonly status: "unauthorized" | "entitlement_inactive" | "workstation_limit";
|
|
96
|
+
};
|
|
97
|
+
export type RotateWorkstationKeyResult = {
|
|
98
|
+
readonly status: "ok";
|
|
99
|
+
readonly credentialId: string;
|
|
100
|
+
readonly revokedCredentialId: string | null;
|
|
101
|
+
readonly issuedAt: number;
|
|
102
|
+
} | {
|
|
103
|
+
readonly status: "unauthorized" | "not_found" | "not_active";
|
|
104
|
+
};
|
|
105
|
+
export type RevokeWorkstationResult = {
|
|
106
|
+
readonly status: "ok";
|
|
107
|
+
readonly revokedAt: number;
|
|
108
|
+
readonly alreadyRevoked: boolean;
|
|
109
|
+
} | {
|
|
110
|
+
readonly status: "unauthorized" | "not_found";
|
|
111
|
+
};
|
|
112
|
+
export type DeviceCredentialVerification = {
|
|
113
|
+
readonly status: "ok";
|
|
114
|
+
readonly credentialId: string;
|
|
115
|
+
readonly companionId: string;
|
|
116
|
+
readonly tenant: TenantRecord;
|
|
117
|
+
} | {
|
|
118
|
+
readonly status: "unknown" | "revoked";
|
|
119
|
+
};
|
|
120
|
+
export interface EntitlementRecord {
|
|
121
|
+
readonly tenantId: string;
|
|
122
|
+
readonly revision: number;
|
|
123
|
+
readonly environment: "test" | "live" | null;
|
|
124
|
+
readonly stripeCustomerId: string | null;
|
|
125
|
+
readonly stripeSubscriptionId: string | null;
|
|
126
|
+
readonly subscriptionState: SubscriptionState;
|
|
127
|
+
readonly currentPeriodEnd: number | null;
|
|
128
|
+
readonly graceInvoiceId: string | null;
|
|
129
|
+
readonly graceDeadline: number | null;
|
|
130
|
+
readonly suspendedAt: number | null;
|
|
131
|
+
readonly suspendedReason: string | null;
|
|
132
|
+
/** Operator grant: access until this UTC millisecond cutoff, independent of billing. */
|
|
133
|
+
readonly grantExpiresAt: number | null;
|
|
134
|
+
readonly grantReason: string | null;
|
|
135
|
+
/** When an operator last set or revoked the grant. */
|
|
136
|
+
readonly grantUpdatedAt: number | null;
|
|
137
|
+
readonly lastReconciledAt: number | null;
|
|
138
|
+
readonly updatedAt: number;
|
|
139
|
+
}
|
|
140
|
+
export type BillingEnvironment = "test" | "live";
|
|
141
|
+
/** The provider objects an entitlement is bound to; billing writes compare it before applying. */
|
|
142
|
+
export interface PurchaseBinding {
|
|
143
|
+
readonly environment: BillingEnvironment | null;
|
|
144
|
+
readonly stripeCustomerId: string | null;
|
|
145
|
+
readonly stripeSubscriptionId: string | null;
|
|
146
|
+
}
|
|
147
|
+
export interface EntitlementUpdate {
|
|
148
|
+
readonly binding: PurchaseBinding;
|
|
149
|
+
readonly subscriptionState: SubscriptionState;
|
|
150
|
+
/** UTC milliseconds; `null` never means perpetual access. */
|
|
151
|
+
readonly currentPeriodEnd: number | null;
|
|
152
|
+
/**
|
|
153
|
+
* `clear` drops the current grace obligation from the entitlement. The
|
|
154
|
+
* obligation record itself is kept, so a later failure of the same invoice
|
|
155
|
+
* reuses its original deadline instead of starting a new one. `keep` keeps
|
|
156
|
+
* grace only while the binding is unchanged; a rebind always clears it,
|
|
157
|
+
* because grace belongs to an obligation of one purchase binding.
|
|
158
|
+
*/
|
|
159
|
+
readonly grace: "keep" | "clear";
|
|
160
|
+
}
|
|
161
|
+
export type ApplyEntitlementUpdateResult = {
|
|
162
|
+
readonly status: "ok";
|
|
163
|
+
readonly entitlement: EntitlementRecord;
|
|
164
|
+
} | {
|
|
165
|
+
readonly status: "not_found" | "binding_conflict";
|
|
166
|
+
} | {
|
|
167
|
+
readonly status: "stale_revision" | "binding_mismatch";
|
|
168
|
+
readonly current: EntitlementRecord;
|
|
169
|
+
};
|
|
170
|
+
/** One provider-open invoice of the current purchase. */
|
|
171
|
+
export interface OpenInvoiceObligation {
|
|
172
|
+
readonly invoiceId: string;
|
|
173
|
+
/** Provider-reported start of the obligation (UTC ms); `null` anchors at the record time. */
|
|
174
|
+
readonly failedSinceMs: number | null;
|
|
175
|
+
}
|
|
176
|
+
export type ApplyPastDueResult = {
|
|
177
|
+
readonly status: "ok";
|
|
178
|
+
readonly entitlement: EntitlementRecord;
|
|
179
|
+
} | {
|
|
180
|
+
readonly status: "not_found";
|
|
181
|
+
} | {
|
|
182
|
+
readonly status: "stale_revision" | "binding_mismatch";
|
|
183
|
+
readonly current: EntitlementRecord;
|
|
184
|
+
};
|
|
185
|
+
/** A purchase binding naming all three provider identifiers; a past-due purchase needs one. */
|
|
186
|
+
export interface CompletePurchaseBinding extends PurchaseBinding {
|
|
187
|
+
readonly environment: BillingEnvironment;
|
|
188
|
+
readonly stripeCustomerId: string;
|
|
189
|
+
readonly stripeSubscriptionId: string;
|
|
190
|
+
}
|
|
191
|
+
export type SuspendTenantResult = {
|
|
192
|
+
readonly status: "ok";
|
|
193
|
+
readonly suspendedAt: number;
|
|
194
|
+
readonly alreadySuspended: boolean;
|
|
195
|
+
} | {
|
|
196
|
+
readonly status: "not_found";
|
|
197
|
+
} | {
|
|
198
|
+
readonly status: "stale_revision";
|
|
199
|
+
readonly current: EntitlementRecord;
|
|
200
|
+
};
|
|
201
|
+
export type UnsuspendTenantResult = {
|
|
202
|
+
readonly status: "ok";
|
|
203
|
+
readonly wasSuspended: boolean;
|
|
204
|
+
} | {
|
|
205
|
+
readonly status: "not_found";
|
|
206
|
+
} | {
|
|
207
|
+
readonly status: "stale_revision";
|
|
208
|
+
readonly current: EntitlementRecord;
|
|
209
|
+
};
|
|
210
|
+
/** The longest operator grant, counted from the moment it is written. */
|
|
211
|
+
export declare const MAX_OPERATOR_GRANT_MS: number;
|
|
212
|
+
export type GrantTenantAccessResult = {
|
|
213
|
+
readonly status: "ok";
|
|
214
|
+
readonly entitlement: EntitlementRecord;
|
|
215
|
+
} | {
|
|
216
|
+
readonly status: "not_found";
|
|
217
|
+
} | {
|
|
218
|
+
readonly status: "invalid_expiry";
|
|
219
|
+
readonly now: number;
|
|
220
|
+
} | {
|
|
221
|
+
readonly status: "stale_revision";
|
|
222
|
+
readonly current: EntitlementRecord;
|
|
223
|
+
};
|
|
224
|
+
export type RevokeTenantGrantResult = {
|
|
225
|
+
readonly status: "ok";
|
|
226
|
+
readonly entitlement: EntitlementRecord;
|
|
227
|
+
readonly hadGrant: boolean;
|
|
228
|
+
} | {
|
|
229
|
+
readonly status: "not_found";
|
|
230
|
+
} | {
|
|
231
|
+
readonly status: "stale_revision";
|
|
232
|
+
readonly current: EntitlementRecord;
|
|
233
|
+
};
|
|
234
|
+
/** One workspace as the operator sees it. */
|
|
235
|
+
export interface OperatorTenantRecord {
|
|
236
|
+
readonly tenantId: string;
|
|
237
|
+
readonly createdAt: number;
|
|
238
|
+
readonly ownerAccountId: string | null;
|
|
239
|
+
readonly liveWorkstations: number;
|
|
240
|
+
readonly entitlement: EntitlementRecord | null;
|
|
241
|
+
}
|
|
242
|
+
export interface OperatorTenantSnapshot {
|
|
243
|
+
readonly now: number;
|
|
244
|
+
readonly tenants: readonly OperatorTenantRecord[];
|
|
245
|
+
}
|
|
246
|
+
export interface EntitlementSnapshot {
|
|
247
|
+
/** The store clock at the read; decisions over this snapshot must use it. */
|
|
248
|
+
readonly now: number;
|
|
249
|
+
readonly entitlement: EntitlementRecord | null;
|
|
250
|
+
}
|
|
251
|
+
export interface EntitlementListSnapshot {
|
|
252
|
+
readonly now: number;
|
|
253
|
+
readonly entitlements: readonly EntitlementRecord[];
|
|
254
|
+
}
|
|
255
|
+
export type EntitlementChangeListener = (tenantId: string) => void;
|
|
256
|
+
export type ReadBillingAccountResult = {
|
|
257
|
+
readonly status: "ok";
|
|
258
|
+
readonly entitlement: EntitlementRecord;
|
|
259
|
+
} | {
|
|
260
|
+
readonly status: "unauthorized" | "not_found";
|
|
261
|
+
};
|
|
262
|
+
export type BindBillingCustomerResult = {
|
|
263
|
+
readonly status: "ok";
|
|
264
|
+
readonly entitlement: EntitlementRecord;
|
|
265
|
+
} | {
|
|
266
|
+
readonly status: "unauthorized" | "not_found" | "binding_conflict";
|
|
267
|
+
} | {
|
|
268
|
+
readonly status: "stale_revision";
|
|
269
|
+
readonly current: EntitlementRecord;
|
|
270
|
+
};
|
|
271
|
+
export type BillingJobTrigger = "webhook" | "startup" | "periodic";
|
|
272
|
+
export type BillingJobState = "pending" | "running" | "succeeded" | "failed";
|
|
273
|
+
export interface BillingJobRecord {
|
|
274
|
+
readonly id: string;
|
|
275
|
+
readonly environment: BillingEnvironment;
|
|
276
|
+
readonly trigger: BillingJobTrigger;
|
|
277
|
+
readonly eventId: string | null;
|
|
278
|
+
readonly tenantId: string | null;
|
|
279
|
+
readonly stripeCustomerId: string | null;
|
|
280
|
+
readonly stripeSubscriptionId: string | null;
|
|
281
|
+
readonly stripeInvoiceId: string | null;
|
|
282
|
+
readonly state: BillingJobState;
|
|
283
|
+
readonly attempts: number;
|
|
284
|
+
readonly nextAttemptAt: number;
|
|
285
|
+
readonly lastError: string | null;
|
|
286
|
+
readonly createdAt: number;
|
|
287
|
+
readonly updatedAt: number;
|
|
288
|
+
}
|
|
289
|
+
/** Provider identifiers named by a verified webhook event. They only select work; they are never applied as state. */
|
|
290
|
+
export interface BillingEventTrigger {
|
|
291
|
+
readonly stripeCustomerId: string | null;
|
|
292
|
+
readonly stripeSubscriptionId: string | null;
|
|
293
|
+
readonly stripeInvoiceId: string | null;
|
|
294
|
+
}
|
|
295
|
+
export type RecordBillingEventResult = {
|
|
296
|
+
readonly status: "recorded";
|
|
297
|
+
readonly jobId: string | null;
|
|
298
|
+
} | {
|
|
299
|
+
readonly status: "duplicate";
|
|
300
|
+
};
|
|
301
|
+
export interface ControlPlaneStoreOptions {
|
|
302
|
+
readonly path: string;
|
|
303
|
+
readonly busyTimeoutMs?: number;
|
|
304
|
+
/** UTC milliseconds. Injectable for tests; the store is the only reader of the clock. */
|
|
305
|
+
readonly now?: () => number;
|
|
306
|
+
/** Unconsumed, unexpired login starts allowed at once; further starts are refused until some expire or complete. */
|
|
307
|
+
readonly maxLivePendingLogins?: number;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Durable control-plane state on one SQLite file and one writer process.
|
|
311
|
+
*
|
|
312
|
+
* Every public method either returns a decision computed from committed state
|
|
313
|
+
* or throws `ControlStoreUnavailableError`; it never returns a partial or
|
|
314
|
+
* default value that a caller could read as access. Methods accept verifiers,
|
|
315
|
+
* never plaintext secrets.
|
|
316
|
+
*/
|
|
317
|
+
export declare class ControlPlaneStore {
|
|
318
|
+
private readonly db;
|
|
319
|
+
private readonly clock;
|
|
320
|
+
private readonly statements;
|
|
321
|
+
private readonly entitlementListeners;
|
|
322
|
+
private readonly maxLivePendingLogins;
|
|
323
|
+
private constructor();
|
|
324
|
+
static open(options: ControlPlaneStoreOptions): ControlPlaneStore;
|
|
325
|
+
get isOpen(): boolean;
|
|
326
|
+
close(): void;
|
|
327
|
+
private statement;
|
|
328
|
+
private get;
|
|
329
|
+
private all;
|
|
330
|
+
private changes;
|
|
331
|
+
/** Read paths sample the clock immediately before their single query. */
|
|
332
|
+
private read;
|
|
333
|
+
private guard;
|
|
334
|
+
private readClock;
|
|
335
|
+
/**
|
|
336
|
+
* Run `operation` inside BEGIN IMMEDIATE. A returned result commits, so a
|
|
337
|
+
* denial that burns a single-use secret is durable; a thrown error rolls back.
|
|
338
|
+
*
|
|
339
|
+
* `now` is sampled only after the write lock is held. Acquiring it can wait
|
|
340
|
+
* up to the busy timeout, so a time taken earlier could let a session or code
|
|
341
|
+
* that expired during the wait still authorize the write.
|
|
342
|
+
*/
|
|
343
|
+
private transaction;
|
|
344
|
+
upsertAccount(input: {
|
|
345
|
+
issuer: string;
|
|
346
|
+
subject: string;
|
|
347
|
+
displayName: string | null;
|
|
348
|
+
}): AccountRecord;
|
|
349
|
+
getAccount(accountId: string): AccountRecord | null;
|
|
350
|
+
/** Invalidate every account session of this account by advancing its authority revision. */
|
|
351
|
+
revokeAccountSessions(accountId: string): boolean;
|
|
352
|
+
/**
|
|
353
|
+
* The account's workspace: its tenant, owner membership, and a no-access
|
|
354
|
+
* entitlement row, created together on first call. Idempotent; an account
|
|
355
|
+
* owns at most one workspace.
|
|
356
|
+
*/
|
|
357
|
+
ensureWorkspace(accountId: string): EnsureWorkspaceResult;
|
|
358
|
+
getTenant(tenantId: string): TenantRecord | null;
|
|
359
|
+
listMemberships(accountId: string): MembershipRecord[];
|
|
360
|
+
getMembershipRole(tenantId: string, accountId: string): MembershipRole | null;
|
|
361
|
+
/** Remove a membership; sessions stop resolving the workspace at once, because membership is read on every request. */
|
|
362
|
+
removeMembership(tenantId: string, accountId: string): boolean;
|
|
363
|
+
/** Refused when the tenant already has an owner or the account already owns a workspace. */
|
|
364
|
+
addOwnerMembership(tenantId: string, accountId: string): boolean;
|
|
365
|
+
/**
|
|
366
|
+
* Record an anonymous login start. At the live-row cap nothing is written and
|
|
367
|
+
* `rate_limited` is returned, never thrown, so the guard does not report it
|
|
368
|
+
* as a store failure.
|
|
369
|
+
*/
|
|
370
|
+
insertPendingLogin(input: {
|
|
371
|
+
stateVerifier: string;
|
|
372
|
+
bindingVerifier: string;
|
|
373
|
+
codeVerifier: string;
|
|
374
|
+
nonce: string;
|
|
375
|
+
ttlMs: number;
|
|
376
|
+
}): InsertPendingLoginResult;
|
|
377
|
+
/** Single use: the login is consumed on first presentation, including when it has expired. */
|
|
378
|
+
consumePendingLogin(stateVerifier: string): ConsumePendingLoginResult;
|
|
379
|
+
/** Returns the session's expiry, computed from the transaction's clock. */
|
|
380
|
+
insertAccountSession(input: SessionInsert & {
|
|
381
|
+
accountId: string;
|
|
382
|
+
}): number;
|
|
383
|
+
resolveAccountSession(verifier: string): AccountSessionContext | null;
|
|
384
|
+
/**
|
|
385
|
+
* The browser authority for workspace and tunneled access: a live account
|
|
386
|
+
* session together with the workspace its account owns, read in one query.
|
|
387
|
+
* `null` when the session does not resolve or the account owns no workspace.
|
|
388
|
+
*/
|
|
389
|
+
resolveTenantMember(verifier: string): TenantMemberContext | null;
|
|
390
|
+
/** Sign-out: revoke one account session. */
|
|
391
|
+
revokeAccountSession(verifier: string): boolean;
|
|
392
|
+
private accountSessionAuthorizes;
|
|
393
|
+
/** Current owner authority for a workspace mutation: a live, unsuperseded account session of the owner. */
|
|
394
|
+
private tenantOwnerAuthorizes;
|
|
395
|
+
private workstationRow;
|
|
396
|
+
/** The workspace's live workstations, oldest first. Never returns a verifier. */
|
|
397
|
+
listWorkstations(tenantId: string): WorkstationRecord[];
|
|
398
|
+
/** One live workstation of this workspace, or `null`: unknown, revoked, or another workspace's. */
|
|
399
|
+
findLiveWorkstation(tenantId: string, companionId: string): WorkstationRecord | null;
|
|
400
|
+
private insertCredential;
|
|
401
|
+
/**
|
|
402
|
+
* Create a workstation and its API key in one commit. Requires the owner's
|
|
403
|
+
* current authority, an entitlement that grants access, and fewer than
|
|
404
|
+
* `MAX_WORKSTATIONS` live workstations; the cap is counted under the write lock.
|
|
405
|
+
*/
|
|
406
|
+
createWorkstation(input: {
|
|
407
|
+
tenantId: string;
|
|
408
|
+
actor: SessionActor;
|
|
409
|
+
label: string;
|
|
410
|
+
credential: DeviceCredentialInsert;
|
|
411
|
+
}): CreateWorkstationResult;
|
|
412
|
+
/**
|
|
413
|
+
* Replace a live workstation's key in one commit: the old key is revoked and
|
|
414
|
+
* the new one issued, with no overlap. Owner only; a revoked workstation is
|
|
415
|
+
* `not_active`. Needs no entitlement, as a key is unusable while access is denied.
|
|
416
|
+
*/
|
|
417
|
+
rotateWorkstationKey(input: {
|
|
418
|
+
tenantId: string;
|
|
419
|
+
companionId: string;
|
|
420
|
+
actor: SessionActor;
|
|
421
|
+
credential: DeviceCredentialInsert;
|
|
422
|
+
}): RotateWorkstationKeyResult;
|
|
423
|
+
/** Revoke a workstation and its key in one commit, freeing its cap slot. Permanent; owner only. */
|
|
424
|
+
revokeWorkstation(input: {
|
|
425
|
+
tenantId: string;
|
|
426
|
+
companionId: string;
|
|
427
|
+
actor: SessionActor;
|
|
428
|
+
}): RevokeWorkstationResult;
|
|
429
|
+
verifyDeviceCredential(verifier: string): DeviceCredentialVerification;
|
|
430
|
+
getEntitlement(tenantId: string): EntitlementRecord | null;
|
|
431
|
+
/** One tenant's entitlement together with the store clock sampled for the same read. */
|
|
432
|
+
readEntitlementAccess(tenantId: string): EntitlementSnapshot;
|
|
433
|
+
/** Every entitlement, ordered by tenant ID, with the store clock sampled for the same read. */
|
|
434
|
+
snapshotEntitlements(): EntitlementListSnapshot;
|
|
435
|
+
/**
|
|
436
|
+
* Called synchronously after each committed entitlement change, outside the
|
|
437
|
+
* transaction. Returns an unsubscribe function.
|
|
438
|
+
*/
|
|
439
|
+
onEntitlementChange(listener: EntitlementChangeListener): () => void;
|
|
440
|
+
private notifyEntitlementChange;
|
|
441
|
+
/**
|
|
442
|
+
* Operator suspension. Independent of billing and of operator grants: no
|
|
443
|
+
* entitlement update, payment, or grant clears it. Like every operator write
|
|
444
|
+
* it advances the revision, and with `expectedRevision` it applies only if
|
|
445
|
+
* the entitlement has not changed since the caller read it.
|
|
446
|
+
*/
|
|
447
|
+
suspendTenant(input: {
|
|
448
|
+
tenantId: string;
|
|
449
|
+
reason: string;
|
|
450
|
+
expectedRevision?: number;
|
|
451
|
+
}): SuspendTenantResult;
|
|
452
|
+
unsuspendTenant(tenantId: string, options?: {
|
|
453
|
+
expectedRevision?: number;
|
|
454
|
+
}): UnsuspendTenantResult;
|
|
455
|
+
/**
|
|
456
|
+
* Set or replace the operator grant: access until `expiresAt`, whatever the
|
|
457
|
+
* billing state, unless suspended. The cutoff must lie after the store clock
|
|
458
|
+
* and at most `MAX_OPERATOR_GRANT_MS` beyond it, so a grant is never perpetual.
|
|
459
|
+
*/
|
|
460
|
+
grantTenantAccess(input: {
|
|
461
|
+
tenantId: string;
|
|
462
|
+
expiresAt: number;
|
|
463
|
+
reason: string;
|
|
464
|
+
expectedRevision?: number;
|
|
465
|
+
}): GrantTenantAccessResult;
|
|
466
|
+
/** Remove the operator grant. Access falls back to the purchase at once. */
|
|
467
|
+
revokeTenantGrant(input: {
|
|
468
|
+
tenantId: string;
|
|
469
|
+
expectedRevision?: number;
|
|
470
|
+
}): RevokeTenantGrantResult;
|
|
471
|
+
private entitlementInTransaction;
|
|
472
|
+
/** Every workspace with its owner, live workstation count, and entitlement, read at one store time. */
|
|
473
|
+
listTenantsForOperator(): OperatorTenantSnapshot;
|
|
474
|
+
/**
|
|
475
|
+
* Apply a past-due purchase in one write: the stored revision and complete
|
|
476
|
+
* purchase binding must still equal `expected`, so an invoice of a replaced
|
|
477
|
+
* subscription cannot install grace on its replacement. Each invoice still
|
|
478
|
+
* open at the provider is an obligation; the first record of one fixes its
|
|
479
|
+
* deadline at `min(now, failedSinceMs) + graceMs` and later records keep it,
|
|
480
|
+
* including after the invoice was paid and reopened. Grace is the earliest
|
|
481
|
+
* deadline among exactly these open invoices, so a paid invoice no longer
|
|
482
|
+
* holds it and nothing extends an open one; with none open there is no grace.
|
|
483
|
+
* Every conflict is found before anything is written.
|
|
484
|
+
*/
|
|
485
|
+
applyPastDue(input: {
|
|
486
|
+
tenantId: string;
|
|
487
|
+
expected: {
|
|
488
|
+
revision: number;
|
|
489
|
+
binding: CompletePurchaseBinding;
|
|
490
|
+
};
|
|
491
|
+
openInvoices: readonly OpenInvoiceObligation[];
|
|
492
|
+
graceMs: number;
|
|
493
|
+
currentPeriodEnd: number | null;
|
|
494
|
+
}): ApplyPastDueResult;
|
|
495
|
+
/**
|
|
496
|
+
* The billing write path. Applies only when the stored revision and purchase
|
|
497
|
+
* binding still equal what the caller compared against provider state, so a
|
|
498
|
+
* stale fetch or an old subscription cannot overwrite its replacement. The
|
|
499
|
+
* caller fetches provider state outside any transaction and, on a stale
|
|
500
|
+
* result, fetches again. Never touches suspension or device credentials.
|
|
501
|
+
*/
|
|
502
|
+
applyEntitlementUpdate(input: {
|
|
503
|
+
tenantId: string;
|
|
504
|
+
expected: {
|
|
505
|
+
revision: number;
|
|
506
|
+
binding: PurchaseBinding;
|
|
507
|
+
};
|
|
508
|
+
update: EntitlementUpdate;
|
|
509
|
+
}): ApplyEntitlementUpdateResult;
|
|
510
|
+
/** How many tenants are bound to a provider customer outside `environment`. */
|
|
511
|
+
countForeignEnvironmentBindings(environment: BillingEnvironment): number;
|
|
512
|
+
/** How many tenants hold a purchase in a state that `evaluateEntitlementAccess` can grant on. */
|
|
513
|
+
countAccessGrantingPurchases(): number;
|
|
514
|
+
/** The entitlement bound to a provider customer in one billing environment. */
|
|
515
|
+
findEntitlementByCustomer(environment: BillingEnvironment, stripeCustomerId: string): EntitlementRecord | null;
|
|
516
|
+
/** The tenant's entitlement, read under the owner's current authority. */
|
|
517
|
+
readBillingAccount(input: {
|
|
518
|
+
tenantId: string;
|
|
519
|
+
actor: SessionActor;
|
|
520
|
+
}): ReadBillingAccountResult;
|
|
521
|
+
/**
|
|
522
|
+
* Store the provider customer for a tenant that has none, under the owner's
|
|
523
|
+
* current authority and the revision the caller read before creating the
|
|
524
|
+
* customer. Grants nothing: the subscription state is left unchanged.
|
|
525
|
+
*/
|
|
526
|
+
bindBillingCustomer(input: {
|
|
527
|
+
tenantId: string;
|
|
528
|
+
actor: SessionActor;
|
|
529
|
+
expectedRevision: number;
|
|
530
|
+
environment: BillingEnvironment;
|
|
531
|
+
stripeCustomerId: string;
|
|
532
|
+
}): BindBillingCustomerResult;
|
|
533
|
+
/**
|
|
534
|
+
* Durably record a verified webhook event and, when it names a customer, its
|
|
535
|
+
* reconciliation job, in one transaction. A repeated event ID records nothing.
|
|
536
|
+
* The caller acknowledges the webhook only after this returns.
|
|
537
|
+
*/
|
|
538
|
+
recordBillingEvent(input: {
|
|
539
|
+
environment: BillingEnvironment;
|
|
540
|
+
eventId: string;
|
|
541
|
+
eventType: string;
|
|
542
|
+
trigger: BillingEventTrigger | null;
|
|
543
|
+
}): RecordBillingEventResult;
|
|
544
|
+
/**
|
|
545
|
+
* Queue one repair job for every entitlement bound to a customer in this
|
|
546
|
+
* environment, whether or not any webhook arrived. A tenant that already has
|
|
547
|
+
* an unfinished repair job gets no second one. Returns how many were queued.
|
|
548
|
+
*/
|
|
549
|
+
enqueueBillingSweep(input: {
|
|
550
|
+
environment: BillingEnvironment;
|
|
551
|
+
trigger: "startup" | "periodic";
|
|
552
|
+
}): number;
|
|
553
|
+
/** Mark the next due job running and count the attempt; `null` when nothing is due. */
|
|
554
|
+
claimBillingJob(environment: BillingEnvironment): BillingJobRecord | null;
|
|
555
|
+
completeBillingJob(id: string): boolean;
|
|
556
|
+
/**
|
|
557
|
+
* Record a failed attempt. With a retry delay the job returns to `pending`
|
|
558
|
+
* at `now + retryDelayMs`; without one it is terminally `failed`.
|
|
559
|
+
*/
|
|
560
|
+
failBillingJob(input: {
|
|
561
|
+
id: string;
|
|
562
|
+
error: string;
|
|
563
|
+
retryDelayMs: number | null;
|
|
564
|
+
}): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Return `running` jobs other than `exceptJobId` to `pending`, due now: jobs
|
|
567
|
+
* left by a process that stopped mid-job, or whose durable record failed.
|
|
568
|
+
* Only the single serialized worker may call this.
|
|
569
|
+
*/
|
|
570
|
+
requeueRunningBillingJobs(environment: BillingEnvironment, exceptJobId?: string | null): number;
|
|
571
|
+
/** UTC milliseconds of the earliest pending job, or `null`. */
|
|
572
|
+
nextBillingJobAt(environment: BillingEnvironment): number | null;
|
|
573
|
+
listBillingJobs(environment: BillingEnvironment): BillingJobRecord[];
|
|
574
|
+
/** Delete succeeded jobs last updated more than `retentionMs` ago. Event receipts are kept for duplicate detection. */
|
|
575
|
+
pruneBillingJobs(retentionMs: number): number;
|
|
576
|
+
/** Delete pending logins at their expiry, and account sessions that expired more than `retentionMs` ago. */
|
|
577
|
+
pruneExpired(retentionMs?: number): number;
|
|
578
|
+
}
|
|
579
|
+
export declare function openControlPlaneStore(options: ControlPlaneStoreOptions): ControlPlaneStore;
|