clinkx 1.1.2 → 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 +63 -0
- package/README.md +67 -14
- package/clinkx-workflows/dist/allowed-roots.js +2 -0
- package/clinkx-workflows/dist/allowed-roots.js.map +1 -1
- 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/child-env.d.ts +3 -1
- package/clinkx-workflows/dist/child-env.js +6 -2
- package/clinkx-workflows/dist/child-env.js.map +1 -1
- 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/config.d.ts +28 -5
- package/clinkx-workflows/dist/config.js +137 -20
- package/clinkx-workflows/dist/config.js.map +1 -1
- package/clinkx-workflows/dist/contained-file.js +9 -0
- package/clinkx-workflows/dist/contained-file.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/session-log-identity.js +2 -1
- package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -1
- 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/root-path-validation.d.ts +12 -0
- package/clinkx-workflows/dist/root-path-validation.js +63 -0
- package/clinkx-workflows/dist/root-path-validation.js.map +1 -0
- package/clinkx-workflows/dist/rosters.d.ts +1 -0
- package/clinkx-workflows/dist/rosters.js +16 -6
- package/clinkx-workflows/dist/rosters.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/server.js +5 -2
- package/clinkx-workflows/dist/server.js.map +1 -1
- package/clinkx-workflows/dist/state-schema.d.ts +24 -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 +185 -4
- package/clinkx-workflows/dist/state.js +684 -88
- 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-completion.d.ts +83 -0
- package/clinkx-workflows/dist/workflow-completion.js +250 -0
- package/clinkx-workflows/dist/workflow-completion.js.map +1 -0
- package/clinkx-workflows/dist/workflow-tools.d.ts +53 -6
- package/clinkx-workflows/dist/workflow-tools.js +1123 -65
- 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/allowed-roots.d.ts +1 -1
- package/dist/allowed-roots.js +124 -14
- package/dist/allowed-roots.js.map +1 -1
- package/dist/context-builder/bundle.js +4 -3
- package/dist/context-builder/bundle.js.map +1 -1
- package/dist/context-builder/config.d.ts +1 -0
- package/dist/context-builder/config.js +21 -9
- package/dist/context-builder/config.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/mutation-lock.d.ts +4 -0
- package/dist/context-builder/mutation-lock.js +7 -1
- package/dist/context-builder/mutation-lock.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/storage.d.ts +10 -2
- package/dist/context-builder/storage.js +213 -16
- package/dist/context-builder/storage.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 +8 -0
- package/dist/dashboard-cli.js +155 -86
- 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/registry.d.ts +1 -1
- package/dist/registry.js +5 -1
- package/dist/registry.js.map +1 -1
- package/dist/runner.d.ts +43 -1
- package/dist/runner.js +234 -35
- package/dist/runner.js.map +1 -1
- package/dist/server.js +21 -6
- package/dist/server.js.map +1 -1
- package/docs/configuration.md +181 -15
- package/docs/engineering-recipes.md +291 -0
- package/docs/security.md +87 -0
- package/docs/verification/project-checks.md +24 -2
- package/package.json +5 -1
- package/scripts/provider-doctor-core.mjs +21 -5
- 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,264 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import type { DashboardGatewayStripeBillingConfig } from "../config.js";
|
|
3
|
+
import { type EntitlementStatus, type SubscriptionState } from "./contracts.js";
|
|
4
|
+
import { type SchedulerTimers, type TenantAccessAuthority } from "./entitlements.js";
|
|
5
|
+
import type { BillingEnvironment, BillingEventTrigger, BillingJobRecord, ControlPlaneStore, EntitlementRecord, SessionActor, TenantRecord } from "./store.js";
|
|
6
|
+
/**
|
|
7
|
+
* The Stripe API version every request is pinned to. It is the default of the
|
|
8
|
+
* pinned `stripe` 22.6.2 SDK, whose types describe only this version; the
|
|
9
|
+
* `satisfies` check fails the build if an SDK upgrade moves the default.
|
|
10
|
+
*/
|
|
11
|
+
export declare const STRIPE_API_VERSION = "2026-08-26.dahlia";
|
|
12
|
+
export declare const DEFAULT_WEBHOOK_MAX_BODY_BYTES: number;
|
|
13
|
+
export declare const DEFAULT_BILLING_RETRY_BASE_MS = 5000;
|
|
14
|
+
export declare const DEFAULT_BILLING_RETRY_MAX_MS: number;
|
|
15
|
+
export declare const DEFAULT_BILLING_MAX_ATTEMPTS = 8;
|
|
16
|
+
export declare const DEFAULT_BILLING_JOB_RETENTION_MS: number;
|
|
17
|
+
export declare const DEFAULT_TRANSITION_RETRY_DELAYS_MS: readonly number[];
|
|
18
|
+
/** Provider lists longer than this are refused rather than applied from a truncated view. */
|
|
19
|
+
export declare const MAX_PROVIDER_LIST_ITEMS = 1000;
|
|
20
|
+
export type BillingConfig = DashboardGatewayStripeBillingConfig;
|
|
21
|
+
export interface ProviderSubscriptionItem {
|
|
22
|
+
readonly priceId: string;
|
|
23
|
+
/** UTC seconds, as the provider reports it. */
|
|
24
|
+
readonly currentPeriodEnd: number | null;
|
|
25
|
+
}
|
|
26
|
+
export interface ProviderSubscription {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly customerId: string;
|
|
29
|
+
readonly status: string;
|
|
30
|
+
/** UTC seconds. */
|
|
31
|
+
readonly created: number;
|
|
32
|
+
readonly livemode: boolean;
|
|
33
|
+
readonly items: readonly ProviderSubscriptionItem[];
|
|
34
|
+
}
|
|
35
|
+
export interface ProviderInvoice {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
/** The invoice's own customer and subscription as the provider reports them; `null` when absent or malformed. */
|
|
38
|
+
readonly customerId: string | null;
|
|
39
|
+
readonly subscriptionId: string | null;
|
|
40
|
+
readonly status: string;
|
|
41
|
+
/**
|
|
42
|
+
* UTC seconds when the obligation became due, which anchors its grace period.
|
|
43
|
+
* Stripe: `status_transitions.finalized_at`, falling back to `created`.
|
|
44
|
+
* `null` when the provider reports neither; grace then starts when recorded.
|
|
45
|
+
*/
|
|
46
|
+
readonly openedAt: number | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The billing provider operations the gateway uses. Every call is made outside
|
|
50
|
+
* a database transaction. Implementations throw `BillingProviderError` and
|
|
51
|
+
* never put secrets in errors.
|
|
52
|
+
*/
|
|
53
|
+
export interface BillingProvider {
|
|
54
|
+
createCustomer(input: {
|
|
55
|
+
tenantId: string;
|
|
56
|
+
idempotencyKey: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
id: string;
|
|
59
|
+
livemode: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
createCheckoutSession(input: {
|
|
62
|
+
customerId: string;
|
|
63
|
+
priceId: string;
|
|
64
|
+
tenantId: string;
|
|
65
|
+
successUrl: string;
|
|
66
|
+
cancelUrl: string;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
url: string;
|
|
69
|
+
}>;
|
|
70
|
+
createPortalSession(input: {
|
|
71
|
+
customerId: string;
|
|
72
|
+
returnUrl: string;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
url: string;
|
|
75
|
+
}>;
|
|
76
|
+
/** Every subscription of a customer, in any status. */
|
|
77
|
+
listSubscriptions(customerId: string): Promise<readonly ProviderSubscription[]>;
|
|
78
|
+
/** Open (unpaid, collectable) invoices of one subscription. */
|
|
79
|
+
listOpenInvoices(subscriptionId: string): Promise<readonly ProviderInvoice[]>;
|
|
80
|
+
}
|
|
81
|
+
/** A provider request failed. `kind` is a short provider error class, never a message. */
|
|
82
|
+
export declare class BillingProviderError extends Error {
|
|
83
|
+
readonly kind: string;
|
|
84
|
+
constructor(kind: string, options?: {
|
|
85
|
+
cause?: unknown;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Stored billing state changed during every fetch-compare round; the job retries later. */
|
|
89
|
+
export declare class BillingContentionError extends Error {
|
|
90
|
+
constructor();
|
|
91
|
+
}
|
|
92
|
+
/** An open invoice does not name the subscription and customer it was listed for; nothing is applied and the job retries. */
|
|
93
|
+
export declare class BillingInvoiceIdentityError extends Error {
|
|
94
|
+
constructor();
|
|
95
|
+
}
|
|
96
|
+
/** Reconciliation cannot succeed by retrying (for example, a subscription already bound to another tenant). */
|
|
97
|
+
export declare class BillingPermanentError extends Error {
|
|
98
|
+
constructor(message: string);
|
|
99
|
+
}
|
|
100
|
+
type Environment = Readonly<Record<string, string | undefined>>;
|
|
101
|
+
/** Stripe through the pinned SDK and API version. The secret key is read from the named variable at each use. */
|
|
102
|
+
export declare function createStripeBillingProvider(options: {
|
|
103
|
+
readonly stripe: Pick<BillingConfig["stripe"], "environment" | "secretKeyEnv">;
|
|
104
|
+
readonly env?: Environment;
|
|
105
|
+
readonly timeoutMs?: number;
|
|
106
|
+
/** Tests only: replaces the SDK's network client. */
|
|
107
|
+
readonly httpClient?: NonNullable<Stripe.StripeConfig["httpClient"]>;
|
|
108
|
+
}): BillingProvider;
|
|
109
|
+
export interface VerifiedBillingEvent {
|
|
110
|
+
readonly id: string;
|
|
111
|
+
readonly type: string;
|
|
112
|
+
/** `null` when the event names no customer, or is not a billing-state event. */
|
|
113
|
+
readonly trigger: BillingEventTrigger | null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Verify a raw webhook body against the signing secret and the configured
|
|
117
|
+
* environment. The body is never parsed before its signature is checked, and
|
|
118
|
+
* nothing in it is applied as state: it only selects reconciliation work.
|
|
119
|
+
*/
|
|
120
|
+
export declare function verifyBillingWebhook(input: {
|
|
121
|
+
rawBody: Buffer;
|
|
122
|
+
signature: string | undefined;
|
|
123
|
+
secret: string;
|
|
124
|
+
environment: BillingEnvironment;
|
|
125
|
+
}): VerifiedBillingEvent;
|
|
126
|
+
/** Provider status to stored state; anything unrecognized is `unknown`, which denies. */
|
|
127
|
+
export declare function subscriptionStateOf(status: string): SubscriptionState;
|
|
128
|
+
/**
|
|
129
|
+
* The customer's current purchase from current provider state alone, so the
|
|
130
|
+
* order events arrived in plays no part. Among subscriptions for a configured
|
|
131
|
+
* Price: (a) the bound subscription while it is active, trialing, or past due;
|
|
132
|
+
* otherwise (b) the active or trialing one with the latest period end, then the
|
|
133
|
+
* newest; otherwise (d) the bound subscription in its terminal state. Pending
|
|
134
|
+
* (`incomplete`) and expired Checkout subscriptions therefore never displace a
|
|
135
|
+
* bound purchase and never grant. Only with no bound subscription in the
|
|
136
|
+
* provider's list does the best remaining state (past due, then unpaid or
|
|
137
|
+
* paused, then incomplete) apply. Stripe allows overlapping active
|
|
138
|
+
* subscriptions; any of them is a paying purchase.
|
|
139
|
+
*/
|
|
140
|
+
export declare function selectCurrentSubscription(input: {
|
|
141
|
+
subscriptions: readonly ProviderSubscription[];
|
|
142
|
+
customerId: string;
|
|
143
|
+
priceIds: readonly string[];
|
|
144
|
+
livemode: boolean;
|
|
145
|
+
boundSubscriptionId: string | null;
|
|
146
|
+
}): ProviderSubscription | null;
|
|
147
|
+
/** The access cutoff: the earliest period end among the subscription's configured-price items, in milliseconds. */
|
|
148
|
+
export declare function periodEndOf(subscription: ProviderSubscription, priceIds: readonly string[]): number | null;
|
|
149
|
+
export type ReconcileOutcome = {
|
|
150
|
+
readonly status: "applied";
|
|
151
|
+
readonly entitlement: EntitlementRecord;
|
|
152
|
+
} | {
|
|
153
|
+
readonly status: "not_found" | "unbound";
|
|
154
|
+
};
|
|
155
|
+
export interface ReconcileContext {
|
|
156
|
+
readonly store: ControlPlaneStore;
|
|
157
|
+
readonly provider: BillingProvider;
|
|
158
|
+
readonly access: Pick<TenantAccessAuthority, "applyPastDue">;
|
|
159
|
+
readonly environment: BillingEnvironment;
|
|
160
|
+
readonly priceIds: readonly string[];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Bring one tenant's entitlement to current provider state. Provider state is
|
|
164
|
+
* fetched outside any transaction; each write then compares the stored
|
|
165
|
+
* revision and purchase binding, and any change in between restarts the
|
|
166
|
+
* fetch-compare round. Never touches suspension or device credentials.
|
|
167
|
+
*/
|
|
168
|
+
export declare function reconcileTenantBilling(context: ReconcileContext, tenantId: string): Promise<ReconcileOutcome>;
|
|
169
|
+
/** A job failure description safe to persist: error classes only, never provider messages or secrets. */
|
|
170
|
+
export declare function describeBillingFailure(error: unknown): string;
|
|
171
|
+
export interface BillingReconcilerOptions {
|
|
172
|
+
readonly store: ControlPlaneStore;
|
|
173
|
+
readonly provider: BillingProvider;
|
|
174
|
+
readonly access: Pick<TenantAccessAuthority, "applyPastDue">;
|
|
175
|
+
readonly config: {
|
|
176
|
+
readonly stripe: Pick<BillingConfig["stripe"], "environment" | "priceIds">;
|
|
177
|
+
readonly billing: Pick<BillingConfig["billing"], "reconciliationIntervalSeconds">;
|
|
178
|
+
};
|
|
179
|
+
readonly timers?: SchedulerTimers;
|
|
180
|
+
/** Clock for timer delays only; job times come from the store clock. */
|
|
181
|
+
readonly now?: () => number;
|
|
182
|
+
readonly retryBaseMs?: number;
|
|
183
|
+
readonly retryMaxMs?: number;
|
|
184
|
+
readonly maxAttempts?: number;
|
|
185
|
+
readonly jobRetentionMs?: number;
|
|
186
|
+
/**
|
|
187
|
+
* Delays between in-process retries of a job's durable completion or failure
|
|
188
|
+
* record. A job whose record still cannot be written stays `running` until
|
|
189
|
+
* the next drain or sweep reclaims it.
|
|
190
|
+
*/
|
|
191
|
+
readonly transitionRetryDelaysMs?: readonly number[];
|
|
192
|
+
/** Diagnostics. Receives errors only; never webhook payloads or secrets. */
|
|
193
|
+
readonly onError?: (error: unknown, job: Pick<BillingJobRecord, "id" | "trigger" | "attempts"> | null) => void;
|
|
194
|
+
}
|
|
195
|
+
export interface BillingReconciler {
|
|
196
|
+
/**
|
|
197
|
+
* Requeue jobs a stopped process left running, queue the startup repair of
|
|
198
|
+
* every bound purchase, start draining, and arm the periodic repair.
|
|
199
|
+
*/
|
|
200
|
+
start(): void;
|
|
201
|
+
/**
|
|
202
|
+
* Stop timers and wait for the job in progress, if any. Queued jobs stay
|
|
203
|
+
* pending; a drain started after stop runs at most one job.
|
|
204
|
+
*/
|
|
205
|
+
stop(): Promise<void>;
|
|
206
|
+
/** Process due jobs now. Jobs run one at a time, in this process only. */
|
|
207
|
+
kick(): void;
|
|
208
|
+
/** Process every due job; resolves when none is due. Concurrent callers share one serialized drain. */
|
|
209
|
+
drain(): Promise<void>;
|
|
210
|
+
/** Queue a repair job for every bound purchase and drain. */
|
|
211
|
+
sweep(trigger: "startup" | "periodic"): Promise<void>;
|
|
212
|
+
readonly running: boolean;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Serialized, durable reconciliation. Webhooks, the startup run, and the
|
|
216
|
+
* periodic run all become rows in `billing_job` and run through one in-process
|
|
217
|
+
* queue. A failed attempt stays pending with exponential backoff until
|
|
218
|
+
* `maxAttempts`; periodic repair still covers a purchase whose job failed.
|
|
219
|
+
*/
|
|
220
|
+
export declare function createBillingReconciler(options: BillingReconcilerOptions): BillingReconciler;
|
|
221
|
+
/** The billing operations behind `/api/control/billing/*`. */
|
|
222
|
+
export interface BillingHttpService {
|
|
223
|
+
/** Throws `ControlStoreUnavailableError` when the store fails. */
|
|
224
|
+
status(tenantId: string): EntitlementStatus;
|
|
225
|
+
createCheckout(input: {
|
|
226
|
+
tenant: TenantRecord;
|
|
227
|
+
actor: SessionActor;
|
|
228
|
+
}): Promise<{
|
|
229
|
+
url: string;
|
|
230
|
+
}>;
|
|
231
|
+
createPortal(input: {
|
|
232
|
+
tenant: TenantRecord;
|
|
233
|
+
actor: SessionActor;
|
|
234
|
+
}): Promise<{
|
|
235
|
+
url: string;
|
|
236
|
+
}>;
|
|
237
|
+
/** Verify, then durably record the event and its job; resolves only after both commit. */
|
|
238
|
+
receiveWebhook(input: {
|
|
239
|
+
rawBody: Buffer;
|
|
240
|
+
signature: string | undefined;
|
|
241
|
+
}): {
|
|
242
|
+
eventId: string;
|
|
243
|
+
duplicate: boolean;
|
|
244
|
+
};
|
|
245
|
+
readonly webhookMaxBodyBytes: number;
|
|
246
|
+
}
|
|
247
|
+
export interface BillingServiceOptions {
|
|
248
|
+
readonly store: ControlPlaneStore;
|
|
249
|
+
readonly provider: BillingProvider;
|
|
250
|
+
/** The single public origin; Checkout and Portal return the browser here. */
|
|
251
|
+
readonly publicOrigin: string;
|
|
252
|
+
readonly access: Pick<TenantAccessAuthority, "entitlementStatus">;
|
|
253
|
+
readonly config: {
|
|
254
|
+
readonly stripe: Pick<BillingConfig["stripe"], "environment" | "priceIds" | "webhookSecretEnv">;
|
|
255
|
+
};
|
|
256
|
+
/** Started after each recorded webhook job. */
|
|
257
|
+
readonly reconciler?: Pick<BillingReconciler, "kick">;
|
|
258
|
+
readonly env?: Environment;
|
|
259
|
+
readonly webhookMaxBodyBytes?: number;
|
|
260
|
+
/** Diagnostics for provider and configuration failures. Never receives secrets or payloads. */
|
|
261
|
+
readonly onError?: (error: unknown) => void;
|
|
262
|
+
}
|
|
263
|
+
export declare function createBillingService(options: BillingServiceOptions): BillingHttpService;
|
|
264
|
+
export {};
|