@happyvertical/smrt-subscriptions 0.60.14 → 0.60.16
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/AGENTS.md +152 -0
- package/README.md +206 -0
- package/dist/billing/apply.d.ts +52 -0
- package/dist/billing/apply.d.ts.map +1 -0
- package/dist/billing/checkout-sessions.d.ts +99 -0
- package/dist/billing/checkout-sessions.d.ts.map +1 -0
- package/dist/billing/config.d.ts +64 -0
- package/dist/billing/config.d.ts.map +1 -0
- package/dist/billing/events.d.ts +49 -0
- package/dist/billing/events.d.ts.map +1 -0
- package/dist/billing/host.d.ts +3 -0
- package/dist/billing/host.d.ts.map +1 -0
- package/dist/billing/index.d.ts +4 -0
- package/dist/billing/index.d.ts.map +1 -0
- package/dist/billing/plans.d.ts +45 -0
- package/dist/billing/plans.d.ts.map +1 -0
- package/dist/billing/signing.d.ts +24 -0
- package/dist/billing/signing.d.ts.map +1 -0
- package/dist/billing/types.d.ts +265 -0
- package/dist/billing/types.d.ts.map +1 -0
- package/dist/collections/TenantUsageMetricCollection.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3230 -1123
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +314 -4
- package/dist/models/BillingCheckoutSession.d.ts +39 -0
- package/dist/models/BillingCheckoutSession.d.ts.map +1 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/recipes.d.ts +1 -1
- package/dist/services/entitlement-changes.d.ts +115 -0
- package/dist/services/entitlement-changes.d.ts.map +1 -0
- package/dist/services/hosted-ai-spend.d.ts +182 -0
- package/dist/services/hosted-ai-spend.d.ts.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/subscription-feature-source.d.ts +89 -0
- package/dist/services/subscription-feature-source.d.ts.map +1 -0
- package/dist/services/subscription-resolver.d.ts +34 -1
- package/dist/services/subscription-resolver.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +103 -8
- package/dist/smrt-knowledge.okf.md +6 -2
- package/dist/vault-account/actions.d.ts +24 -0
- package/dist/vault-account/actions.d.ts.map +1 -0
- package/dist/vault-account/errors.d.ts +20 -0
- package/dist/vault-account/errors.d.ts.map +1 -0
- package/dist/vault-account/index.d.ts +5 -0
- package/dist/vault-account/index.d.ts.map +1 -0
- package/dist/vault-account/relay-admin-client.d.ts +10 -0
- package/dist/vault-account/relay-admin-client.d.ts.map +1 -0
- package/dist/vault-account/types.d.ts +115 -0
- package/dist/vault-account/types.d.ts.map +1 -0
- package/package.json +9 -6
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise verified Stripe webhook payloads into the facts this module acts
|
|
3
|
+
* on (#4786). Pure: no I/O, no trust decisions beyond reading shapes.
|
|
4
|
+
*/
|
|
5
|
+
import type { SubscriptionStatus } from '../types.js';
|
|
6
|
+
import type { BillingSubscriptionState } from './types.js';
|
|
7
|
+
export declare const SUBSCRIPTION_EVENT_TYPES: Set<string>;
|
|
8
|
+
export declare const CHECKOUT_COMPLETED = "checkout.session.completed";
|
|
9
|
+
export declare const SUBSCRIPTION_DELETED = "customer.subscription.deleted";
|
|
10
|
+
/** What the provider says about one subscription at a point in time. */
|
|
11
|
+
export interface SubscriptionSnapshot {
|
|
12
|
+
subscriptionId: string;
|
|
13
|
+
customerId: string;
|
|
14
|
+
status: SubscriptionStatus;
|
|
15
|
+
priceId?: string;
|
|
16
|
+
startedAt?: Date | null;
|
|
17
|
+
currentPeriodStart?: Date | null;
|
|
18
|
+
currentPeriodEnd?: Date | null;
|
|
19
|
+
trialEndsAt?: Date | null;
|
|
20
|
+
cancelAtPeriodEnd?: boolean;
|
|
21
|
+
canceledAt?: Date | null;
|
|
22
|
+
endedAt?: Date | null;
|
|
23
|
+
}
|
|
24
|
+
export interface CheckoutCompletedFacts {
|
|
25
|
+
sessionId: string;
|
|
26
|
+
mode: string | undefined;
|
|
27
|
+
paymentStatus: string | undefined;
|
|
28
|
+
customerId: string | undefined;
|
|
29
|
+
subscriptionId: string | undefined;
|
|
30
|
+
metadata: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
type UnknownRecord = Record<string, unknown>;
|
|
33
|
+
export declare function asRecord(value: unknown): UnknownRecord | null;
|
|
34
|
+
export declare function asString(value: unknown): string | undefined;
|
|
35
|
+
/** A Stripe id that is either a string or an expanded `{ id }` object. */
|
|
36
|
+
export declare function externalId(value: unknown): string | undefined;
|
|
37
|
+
export declare function stripeObject(payload: unknown): UnknownRecord | null;
|
|
38
|
+
export declare function toDate(value: unknown): Date | null;
|
|
39
|
+
/** Unknown provider statuses fail closed to a non-entitling status. */
|
|
40
|
+
export declare function mapSubscriptionStatus(value: string | undefined): SubscriptionStatus;
|
|
41
|
+
/** The first line-item price id: what the provider actually bills. */
|
|
42
|
+
export declare function subscriptionPriceId(object: UnknownRecord): string | undefined;
|
|
43
|
+
/** Facts from a `customer.subscription.*` event object. */
|
|
44
|
+
export declare function subscriptionSnapshotFromObject(object: UnknownRecord, eventType: string): SubscriptionSnapshot | null;
|
|
45
|
+
/** Facts from a provider subscription read back through the SDK. */
|
|
46
|
+
export declare function subscriptionSnapshotFromState(state: BillingSubscriptionState): SubscriptionSnapshot;
|
|
47
|
+
export declare function checkoutFactsFromObject(object: UnknownRecord): CheckoutCompletedFacts | null;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/billing/events.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAE3D,eAAO,MAAM,wBAAwB,aAMnC,CAAC;AAEH,eAAO,MAAM,kBAAkB,+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IAAI,CAEnE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAQlD;AAeD,uEAAuE;AACvE,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,kBAAkB,CAEpB;AAmBD,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAM7E;AAiBD,2DAA2D;AAC3D,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,GAChB,oBAAoB,GAAG,IAAI,CAwB7B;AAED,oEAAoE;AACpE,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,wBAAwB,GAC9B,oBAAoB,CAmBtB;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,GACpB,sBAAsB,GAAG,IAAI,CAW/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/billing/host.ts"],"names":[],"mappings":"AAqEA,OAAO,EAGL,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EAIxB,MAAM,YAAY,CAAC;AAoFpB,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAguB1E"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BILLING_ENV, type BillingEnvConfig, type BillingEnvOptions, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, MAX_WEBHOOK_TOLERANCE_SECONDS, priceEnvName, readBillingEnv, } from './config.js';
|
|
2
|
+
export { createBillingHost } from './host.js';
|
|
3
|
+
export { type BillingAuth, type BillingCheckoutLineItem, type BillingCheckoutResult, type BillingCheckoutSessionInput, type BillingHost, BillingHostError, type BillingHostErrorCode, type BillingHostOptions, type BillingLogger, type BillingPlanPurchaseContext, type BillingPortalResult, type BillingProviderPort, type BillingProviderWebhookEvent, type BillingSubscriptionState, type BillingUnreconciledCheckout, type BillingUrls, type BillingWebhookOutcome, type BillingWebhookResponse, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/billing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,iCAAiC,EACjC,6BAA6B,EAC7B,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan lookup, price mapping and purchasability for the billing glue (#4786).
|
|
3
|
+
*
|
|
4
|
+
* Plans are read in a system context and then checked explicitly: a plan is
|
|
5
|
+
* visible to a tenant only when it is the tenant's own or a global
|
|
6
|
+
* (`tenantId: null`) plan. The provider price always comes from server
|
|
7
|
+
* configuration or the plan's own binding, never from a request.
|
|
8
|
+
*/
|
|
9
|
+
import type { DatabaseInterface } from '@happyvertical/sql';
|
|
10
|
+
import type { SubscriptionPlan } from '../models/SubscriptionPlan.js';
|
|
11
|
+
export declare function planVisibleToTenant(plan: SubscriptionPlan, tenantId: string): boolean;
|
|
12
|
+
/** The provider price id a plan is sold under, or undefined when unset. */
|
|
13
|
+
export declare function priceIdForPlan(plan: SubscriptionPlan, prices: Record<string, string> | undefined): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Whose plans may be sold and resolved from a provider price. `deny` (the
|
|
16
|
+
* default) is operator plans only: a tenant that can write its own
|
|
17
|
+
* `SubscriptionPlan` rows (for example through a mounted generated API) cannot
|
|
18
|
+
* mint a plan, or shadow a global plan key, and buy the entitlements it wrote.
|
|
19
|
+
*/
|
|
20
|
+
export type TenantPlanPolicy = 'deny' | 'allow';
|
|
21
|
+
export declare class PlanDirectory {
|
|
22
|
+
private readonly db;
|
|
23
|
+
private readonly prices;
|
|
24
|
+
private readonly tenantPlans;
|
|
25
|
+
constructor(db: DatabaseInterface, prices: Record<string, string> | undefined, tenantPlans?: TenantPlanPolicy);
|
|
26
|
+
private sellable;
|
|
27
|
+
/**
|
|
28
|
+
* The plan a subscription row already points at, for status-only updates:
|
|
29
|
+
* visibility only, so a row on a legacy tenant plan keeps resolving.
|
|
30
|
+
*/
|
|
31
|
+
findExisting(tenantId: string, planId: string): Promise<SubscriptionPlan | null>;
|
|
32
|
+
private collection;
|
|
33
|
+
/** A plan `tenantId` may buy, by key (own plan first if allowed) or by id. */
|
|
34
|
+
find(tenantId: string, ref: {
|
|
35
|
+
planKey?: string;
|
|
36
|
+
planId?: string;
|
|
37
|
+
}): Promise<SubscriptionPlan | null>;
|
|
38
|
+
/**
|
|
39
|
+
* The plan a provider price id is sold as, for `tenantId`: configured
|
|
40
|
+
* price map first, then plan price bindings. The tenant's own plan beats a
|
|
41
|
+
* global one.
|
|
42
|
+
*/
|
|
43
|
+
findByPriceId(tenantId: string, priceId: string): Promise<SubscriptionPlan | null>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sourceRoot":"","sources":["../../src/billing/plans.ts"],"names":[],"mappings":"AAAA;;;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
|
1
|
+
/**
|
|
2
|
+
* Signed Checkout metadata and secret hygiene (#4786).
|
|
3
|
+
*
|
|
4
|
+
* Another integration on the same Stripe account can create Checkout Sessions
|
|
5
|
+
* with any metadata it likes. A completed session is only trusted to link a
|
|
6
|
+
* tenant and plan when its `smrt_*` metadata carries an HMAC made with a
|
|
7
|
+
* server-side secret at session creation. Uses WebCrypto so the module loads
|
|
8
|
+
* in every runtime the package does.
|
|
9
|
+
*/
|
|
10
|
+
export declare const METADATA_SIGNATURE_KEY = "smrt_sig";
|
|
11
|
+
export declare const METADATA_PURPOSE = "tenant_subscription";
|
|
12
|
+
/** Compare without an early exit on the first differing character. */
|
|
13
|
+
export declare function constantTimeEqual(left: string, right: string): boolean;
|
|
14
|
+
/** Add the signature to `metadata`. Only `smrt_*` keys are covered. */
|
|
15
|
+
export declare function signCheckoutMetadata(metadata: Record<string, string>, secret: string): Promise<Record<string, string>>;
|
|
16
|
+
export declare function checkoutMetadataValid(metadata: Record<string, string>, secret: string): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Strip anything shaped like a Stripe key or signing secret. Applied to every
|
|
19
|
+
* error message before it reaches a log, as provider errors can echo the
|
|
20
|
+
* credential they were called with.
|
|
21
|
+
*/
|
|
22
|
+
export declare function redactSecrets(text: string): string;
|
|
23
|
+
export declare function safeErrorMessage(error: unknown): string;
|
|
24
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/billing/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAyBtD,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAOtE;AAeD,uEAAuE;AACvE,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAQjC;AAED,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAOlB;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGvD"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the billing host glue (#4786).
|
|
3
|
+
*
|
|
4
|
+
* The provider port is structural: `StripeAccountingProvider` from
|
|
5
|
+
* `@happyvertical/accounting` satisfies it (a compile-time test pins that), so
|
|
6
|
+
* this package carries no runtime or type dependency on the SDK. Every
|
|
7
|
+
* provider call goes through that SDK; nothing here talks to Stripe directly.
|
|
8
|
+
*/
|
|
9
|
+
import type { DatabaseInterface } from '@happyvertical/sql';
|
|
10
|
+
import type { SubscriptionPlan } from '../models/SubscriptionPlan.js';
|
|
11
|
+
/** A line item priced by a provider price id (never by a client-sent amount). */
|
|
12
|
+
export interface BillingCheckoutLineItem {
|
|
13
|
+
price: string;
|
|
14
|
+
quantity: number;
|
|
15
|
+
}
|
|
16
|
+
export interface BillingCheckoutSessionInput {
|
|
17
|
+
mode?: 'subscription';
|
|
18
|
+
successUrl: string;
|
|
19
|
+
cancelUrl: string;
|
|
20
|
+
customerExternalId?: string;
|
|
21
|
+
customerEmail?: string;
|
|
22
|
+
clientReferenceId?: string;
|
|
23
|
+
lineItems: BillingCheckoutLineItem[];
|
|
24
|
+
metadata: Record<string, string>;
|
|
25
|
+
idempotencyKey?: string;
|
|
26
|
+
}
|
|
27
|
+
/** The slice of a provider subscription this module reads. */
|
|
28
|
+
export interface BillingSubscriptionState {
|
|
29
|
+
externalId: string;
|
|
30
|
+
status: string;
|
|
31
|
+
customerExternalId: string;
|
|
32
|
+
currentPeriodStart?: Date;
|
|
33
|
+
currentPeriodEnd?: Date;
|
|
34
|
+
cancelAtPeriodEnd: boolean;
|
|
35
|
+
canceledAt?: Date;
|
|
36
|
+
trialEnd?: Date;
|
|
37
|
+
raw?: unknown;
|
|
38
|
+
}
|
|
39
|
+
/** A parsed (not yet trusted until `verify` passed) webhook event. */
|
|
40
|
+
export interface BillingProviderWebhookEvent {
|
|
41
|
+
id?: string;
|
|
42
|
+
type: string;
|
|
43
|
+
timestamp: Date;
|
|
44
|
+
payload: unknown;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The provider operations the glue needs. `StripeAccountingProvider` from
|
|
48
|
+
* `@happyvertical/accounting` is assignable to this.
|
|
49
|
+
*/
|
|
50
|
+
export interface BillingProviderPort {
|
|
51
|
+
readonly webhooks: {
|
|
52
|
+
verify(payload: string, signature: string, secret: string): boolean;
|
|
53
|
+
parse(payload: string): BillingProviderWebhookEvent;
|
|
54
|
+
};
|
|
55
|
+
readonly billing: {
|
|
56
|
+
createCheckoutSession(input: BillingCheckoutSessionInput): Promise<{
|
|
57
|
+
externalId: string;
|
|
58
|
+
url: string | null;
|
|
59
|
+
}>;
|
|
60
|
+
createCustomerPortalSession(input: {
|
|
61
|
+
customerExternalId: string;
|
|
62
|
+
returnUrl: string;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
url: string;
|
|
65
|
+
}>;
|
|
66
|
+
retrieveSubscriptionStatus(subscriptionExternalId: string): Promise<BillingSubscriptionState>;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Fixed, host-configured destinations. Never taken from a request. */
|
|
70
|
+
export interface BillingUrls {
|
|
71
|
+
/** Where Checkout sends the buyer after paying. */
|
|
72
|
+
successUrl: string;
|
|
73
|
+
/** Where Checkout sends the buyer when they back out. */
|
|
74
|
+
cancelUrl: string;
|
|
75
|
+
/** Where the customer portal returns to. */
|
|
76
|
+
portalReturnUrl: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Structured, secret-free log sink. Every field passed is safe to persist:
|
|
80
|
+
* event ids, types, tenant ids and reason codes only.
|
|
81
|
+
*/
|
|
82
|
+
export interface BillingLogger {
|
|
83
|
+
info?(message: string, fields?: Record<string, unknown>): void;
|
|
84
|
+
warn?(message: string, fields?: Record<string, unknown>): void;
|
|
85
|
+
error?(message: string, fields?: Record<string, unknown>): void;
|
|
86
|
+
}
|
|
87
|
+
export interface BillingPlanPurchaseContext {
|
|
88
|
+
tenantId: string;
|
|
89
|
+
plan: SubscriptionPlan;
|
|
90
|
+
}
|
|
91
|
+
export interface BillingHostOptions {
|
|
92
|
+
/** The accounting provider (Stripe) from `@happyvertical/accounting`. */
|
|
93
|
+
provider: BillingProviderPort;
|
|
94
|
+
/**
|
|
95
|
+
* Resolved database handle with `transaction()` support (SQLite or
|
|
96
|
+
* PostgreSQL). Event idempotency and the subscription write share one
|
|
97
|
+
* transaction on it. Take it from any collection, for example
|
|
98
|
+
* `(await TenantSubscriptionCollection.create(config)).db`.
|
|
99
|
+
*/
|
|
100
|
+
db: DatabaseInterface;
|
|
101
|
+
/** Webhook endpoint signing secret (`whsec_…`). Required, never defaulted. */
|
|
102
|
+
webhookSecret: string;
|
|
103
|
+
/**
|
|
104
|
+
* Secret used to sign new Checkout metadata. Defaults to `webhookSecret`, so
|
|
105
|
+
* rotating the webhook secret also changes it: list the retired secret in
|
|
106
|
+
* `metadataVerificationSecrets` for as long as sessions created under it can
|
|
107
|
+
* still complete, or give the host its own stable secret here.
|
|
108
|
+
*/
|
|
109
|
+
metadataSigningSecret?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Retired secrets still accepted when a completed Checkout is verified (never
|
|
112
|
+
* used to sign). Needed across a rotation of the signing secret, otherwise a
|
|
113
|
+
* session paid after the rotation is not trusted and the purchase is dropped.
|
|
114
|
+
*/
|
|
115
|
+
metadataVerificationSecrets?: readonly string[];
|
|
116
|
+
/** Maximum webhook signature age in seconds (default 300, at most 900). */
|
|
117
|
+
webhookToleranceSeconds?: number;
|
|
118
|
+
/** Largest accepted webhook body in bytes (default 1 MiB). */
|
|
119
|
+
maxWebhookBodyBytes?: number;
|
|
120
|
+
urls: BillingUrls;
|
|
121
|
+
/**
|
|
122
|
+
* Whether tenant-owned plans (`SubscriptionPlan.tenantId` set) may be sold.
|
|
123
|
+
* Default `deny`: only operator-owned global plans are sold, so a tenant
|
|
124
|
+
* that can write plan rows cannot buy entitlements it defined itself. Use
|
|
125
|
+
* `allow` only when tenants cannot write plans.
|
|
126
|
+
*/
|
|
127
|
+
tenantPlans?: 'deny' | 'allow';
|
|
128
|
+
/** Plan key to provider price id. Wins over the plan's own price binding. */
|
|
129
|
+
prices?: Record<string, string>;
|
|
130
|
+
/**
|
|
131
|
+
* Extra purchase policy, evaluated after the built-in checks (plan visible
|
|
132
|
+
* to the tenant, active, fixed price, price configured, tenant not already
|
|
133
|
+
* subscribed). Return false to refuse.
|
|
134
|
+
*/
|
|
135
|
+
canPurchasePlan?: (context: BillingPlanPurchaseContext) => boolean | Promise<boolean>;
|
|
136
|
+
/** Namespaces the idempotency claim when several accounts share a database. */
|
|
137
|
+
accountKey?: string;
|
|
138
|
+
logger?: BillingLogger;
|
|
139
|
+
}
|
|
140
|
+
/** The tenant a host has already authenticated and authorised for billing. */
|
|
141
|
+
export interface BillingAuth {
|
|
142
|
+
tenantId: string;
|
|
143
|
+
/** Prefilled on Checkout for a tenant with no billing customer yet. */
|
|
144
|
+
email?: string;
|
|
145
|
+
}
|
|
146
|
+
export type BillingHostErrorCode = 'invalid_request' | 'tenant_mismatch' | 'plan_unavailable' | 'plan_forbidden' | 'plan_not_purchasable' | 'price_unconfigured' | 'already_subscribed' | 'no_billing_account' | 'checkout_not_reconcilable' | 'provider_error';
|
|
147
|
+
/**
|
|
148
|
+
* A refusal with a stable code and a fixed message. The message never carries
|
|
149
|
+
* provider text, ids or configuration, so it is safe to return to a browser.
|
|
150
|
+
*/
|
|
151
|
+
export declare class BillingHostError extends Error {
|
|
152
|
+
readonly code: BillingHostErrorCode;
|
|
153
|
+
readonly status: number;
|
|
154
|
+
constructor(code: BillingHostErrorCode);
|
|
155
|
+
}
|
|
156
|
+
export interface BillingCheckoutResult {
|
|
157
|
+
/** Hosted checkout page to send the buyer to. */
|
|
158
|
+
url: string;
|
|
159
|
+
sessionId: string;
|
|
160
|
+
}
|
|
161
|
+
export interface BillingPortalResult {
|
|
162
|
+
url: string;
|
|
163
|
+
}
|
|
164
|
+
export type BillingWebhookOutcome = 'applied' | 'ignored' | 'duplicate'
|
|
165
|
+
/**
|
|
166
|
+
* A paid first-purchase Checkout could not be tied to a session this host
|
|
167
|
+
* created. It was not linked and not discarded: it is stored for an
|
|
168
|
+
* operator (`listCheckoutsNeedingReconciliation`, `reconcileCheckout`).
|
|
169
|
+
*/
|
|
170
|
+
| 'needs_reconciliation';
|
|
171
|
+
/** A paid Checkout session waiting for an operator. Ids and codes only. */
|
|
172
|
+
export interface BillingUnreconciledCheckout {
|
|
173
|
+
sessionId: string;
|
|
174
|
+
/** `session_record_missing`, `session_record_mismatch` or `session_expired`. */
|
|
175
|
+
reason: string;
|
|
176
|
+
/** The tenant the signed metadata named (not trusted). */
|
|
177
|
+
claimedTenantId: string;
|
|
178
|
+
subscriptionId: string;
|
|
179
|
+
/**
|
|
180
|
+
* The provider customer that paid. Confirm it is the claimed tenant's own
|
|
181
|
+
* customer before reconciling: it is the one value that decides who gets
|
|
182
|
+
* control of the tenant's billing portal.
|
|
183
|
+
*/
|
|
184
|
+
customerId: string;
|
|
185
|
+
/** The tenant the host recorded the session for (empty when no record). */
|
|
186
|
+
targetTenantId: string;
|
|
187
|
+
/**
|
|
188
|
+
* True when the claimed tenant has its own pending or completed session
|
|
189
|
+
* recorded by this host, which suggests the flagged payment is a copy of
|
|
190
|
+
* that tenant's signed metadata rather than the tenant's purchase.
|
|
191
|
+
*/
|
|
192
|
+
claimedTenantHasOwnSession: boolean;
|
|
193
|
+
eventId: string;
|
|
194
|
+
flaggedAt: Date;
|
|
195
|
+
}
|
|
196
|
+
export interface BillingWebhookResponse {
|
|
197
|
+
status: number;
|
|
198
|
+
body: {
|
|
199
|
+
received: boolean;
|
|
200
|
+
outcome?: BillingWebhookOutcome;
|
|
201
|
+
error?: string;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export interface BillingHost {
|
|
205
|
+
createCheckout(auth: BillingAuth, input: {
|
|
206
|
+
planKey?: string;
|
|
207
|
+
planId?: string;
|
|
208
|
+
}): Promise<BillingCheckoutResult>;
|
|
209
|
+
createPortalLink(auth: BillingAuth): Promise<BillingPortalResult>;
|
|
210
|
+
/** Paid Checkout sessions flagged `needs_reconciliation`, oldest first. */
|
|
211
|
+
listCheckoutsNeedingReconciliation(options?: {
|
|
212
|
+
/** Page size, 1..1000 (default 200). */
|
|
213
|
+
limit?: number;
|
|
214
|
+
offset?: number;
|
|
215
|
+
}): Promise<BillingUnreconciledCheckout[]>;
|
|
216
|
+
/** How many paid sessions are flagged, so a page is never mistaken for all. */
|
|
217
|
+
countCheckoutsNeedingReconciliation(): Promise<number>;
|
|
218
|
+
/**
|
|
219
|
+
* Operator-only (same rules as `reconcileCheckout`): close a flagged session
|
|
220
|
+
* on purpose WITHOUT linking it (for example a payment from another
|
|
221
|
+
* integration on the same account). Terminal state `dismissed`, logged with
|
|
222
|
+
* the operator id and reason; throws `checkout_not_reconcilable` when the
|
|
223
|
+
* session is not flagged.
|
|
224
|
+
*/
|
|
225
|
+
dismissCheckout(input: {
|
|
226
|
+
sessionId: string;
|
|
227
|
+
operatorId: string;
|
|
228
|
+
reason: string;
|
|
229
|
+
}): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Operator-only, called by host code that has already authenticated and
|
|
232
|
+
* authorised an operator (never wired to a request handler). Links a flagged
|
|
233
|
+
* paid session to `tenantId` on purpose, once: the subscription is re-read
|
|
234
|
+
* from the provider and must be the one recorded when the session was
|
|
235
|
+
* flagged. `planId` defaults to the plan the signed metadata named. Throws
|
|
236
|
+
* `checkout_not_reconcilable` when the session is not flagged (or was
|
|
237
|
+
* already reconciled); otherwise reports whether the link was `applied` or
|
|
238
|
+
* `ignored` with a reason (for example `already_subscribed`).
|
|
239
|
+
*/
|
|
240
|
+
reconcileCheckout(input: {
|
|
241
|
+
sessionId: string;
|
|
242
|
+
tenantId: string;
|
|
243
|
+
planId?: string;
|
|
244
|
+
/** Who is acting; recorded in the audit log. */
|
|
245
|
+
operatorId: string;
|
|
246
|
+
}): Promise<{
|
|
247
|
+
outcome: 'applied' | 'ignored';
|
|
248
|
+
reason?: string;
|
|
249
|
+
}>;
|
|
250
|
+
handleWebhook(input: {
|
|
251
|
+
payload: string;
|
|
252
|
+
signature: string | null;
|
|
253
|
+
}): Promise<BillingWebhookResponse>;
|
|
254
|
+
/**
|
|
255
|
+
* Fetch-API handlers for any framework (`+server.ts`, Hono, Workers). The
|
|
256
|
+
* host authenticates and authorises the caller first and passes the tenant;
|
|
257
|
+
* checkout and portal never read a tenant, price or URL from the request.
|
|
258
|
+
*/
|
|
259
|
+
handlers: {
|
|
260
|
+
checkout(request: Request, auth: BillingAuth): Promise<Response>;
|
|
261
|
+
portal(request: Request, auth: BillingAuth): Promise<Response>;
|
|
262
|
+
webhook(request: Request): Promise<Response>;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/billing/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,iFAAiF;AACjF,MAAM,WAAW,uBAAuB;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B,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACrB,YAAY,EACb,MAAM,aAAa,CAAC;AAQrB,qBAAa,2BAA4B,SAAQ,cAAc,CAAC,iBAAiB,CAAC;IAChF,MAAM,CAAC,QAAQ,CAAC,UAAU,2BAAqB;IAEzC,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmD1E;;;OAGG;IACG,qBAAqB,CACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAOzB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC;IAsCrE,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,YAAY,EAAE,CAAC;IAqE1B;;;;;;;;;;;OAWG;IACG,sBAAsB,CAC1B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"TenantUsageMetricCollection.d.ts","sourceRoot":"","sources":["../../src/collections/TenantUsageMetricCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,qBAAqB,EACrB,YAAY,EACb,MAAM,aAAa,CAAC;AAQrB,qBAAa,2BAA4B,SAAQ,cAAc,CAAC,iBAAiB,CAAC;IAChF,MAAM,CAAC,QAAQ,CAAC,UAAU,2BAAqB;IAEzC,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAmD1E;;;OAGG;IACG,qBAAqB,CACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAOzB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC;IAsCrE,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,YAAY,EAAE,CAAC;IAqE1B;;;;;;;;;;;OAWG;IACG,sBAAsB,CAC1B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,cAAc,CAAC;CA+B3B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,16 +7,18 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
import './__smrt-register__.js';
|
|
10
|
+
export { BILLING_ENV, type BillingAuth, type BillingCheckoutLineItem, type BillingCheckoutResult, type BillingCheckoutSessionInput, type BillingEnvConfig, type BillingEnvOptions, type BillingHost, BillingHostError, type BillingHostErrorCode, type BillingHostOptions, type BillingLogger, type BillingPlanPurchaseContext, type BillingPortalResult, type BillingProviderPort, type BillingProviderWebhookEvent, type BillingSubscriptionState, type BillingUnreconciledCheckout, type BillingUrls, type BillingWebhookOutcome, type BillingWebhookResponse, createBillingHost, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, MAX_WEBHOOK_TOLERANCE_SECONDS, priceEnvName, readBillingEnv, } from './billing/index.js';
|
|
10
11
|
export { SubscriptionPlanCollection, SubscriptionPlanVersionCollection, TenantSubscriptionCollection, TenantUsageMetricCollection, } from './collections/index.js';
|
|
11
12
|
export { migrateSubscriptionsMoneyToMinorUnits, preflightSubscriptionsMoneyMinorUnits, SUBSCRIPTIONS_MONEY_COLUMNS, SUBSCRIPTIONS_MONEY_MINOR_UNITS_BACKFILL, } from './migrations/moneyMinorUnits.js';
|
|
12
13
|
export { migrateSubscriptionPlanVersions, type SubscriptionPlanVersionsMigrationReport, } from './migrations/planVersions.js';
|
|
13
14
|
export type { PriceBookKind, PricingStrategy, SpendingBasis, SpendingPeriod, SpendingPolicyBehavior, } from './models/index.js';
|
|
14
|
-
export { BillingAdjustment, BillingAdjustmentCollection, ClientCharge, ClientChargeCollection, CreditGrant, CreditGrantCollection, isCurrencyCode, isPriceBookKind, PriceBook, PriceBookAssignment, PriceBookCollection, PricingRule, PricingRuleCollection, RetailCharge, RetailChargeCollection, SpendingPolicy, SpendingPolicyCollection, SubscriptionPlan, SubscriptionPlanVersion, TenantSubscription, TenantUsageMetric, } from './models/index.js';
|
|
15
|
+
export { BillingAdjustment, BillingAdjustmentCollection, BillingCheckoutSession, ClientCharge, ClientChargeCollection, CreditGrant, CreditGrantCollection, isCurrencyCode, isPriceBookKind, PriceBook, PriceBookAssignment, PriceBookCollection, PricingRule, PricingRuleCollection, RetailCharge, RetailChargeCollection, SpendingPolicy, SpendingPolicyCollection, SubscriptionPlan, SubscriptionPlanVersion, TenantSubscription, TenantUsageMetric, } from './models/index.js';
|
|
15
16
|
export { enabledFeatureKeys, extractPlanTerms, isEntitlementUpgrade, PLAN_TERM_FIELDS, samePlanTerms, validThresholds, } from './plan-terms.js';
|
|
16
17
|
export type { PlanVersionReplacement } from './plan-versioning.js';
|
|
17
18
|
export { SubscriptionPlansRecipe } from './recipes.js';
|
|
18
19
|
export type { AssignPriceBooksInput, AutoTopUpGrant, AutoTopUpHook, AutoTopUpRequest, BillingRelationshipReader, CommercialBillingStorage, CommercialUsageServiceOptions, CustomPricingContext, CustomPricingStrategy, DefinePriceBookPriceInput, DelegatedSpendingPolicyInput, GrantChildCreditInput, GrantCreditInput, PriceBookAssignmentView, PriceBookLeg, PriceUsageOptions, RateUsageOptions, ResellerBillingAction, ResellerBillingErrorCode, ResellerBillingServiceOptions, SpendingDecision, SpendingEvaluationInput, SpendingPolicyEvaluatorExtensions, SpendingPolicyEvaluatorOptions, UsageRating, } from './services/index.js';
|
|
19
|
-
export { assertCommercialBillingStorageSupported, CommercialBillingStorageConfigurationError, CommercialUsageService, evaluateThreshold, evaluateThresholds, ResellerBillingError, ResellerBillingService, SpendingPolicyEvaluator, type SubscriptionPlanReader, type SubscriptionPlanVersionReader, SubscriptionResolver, type SubscriptionResolverReaders, type TenantSubscriptionReader, TenantUsageMeter, UnsupportedCommercialBillingStorageError, type UsageSummaryReader, } from './services/index.js';
|
|
20
|
+
export { AI_HOSTED_SPEND_METRIC, AI_HOSTED_USER_SPEND_METRIC, assertCommercialBillingStorageSupported, CommercialBillingStorageConfigurationError, CommercialUsageService, createHostedAiSpendReader, decideHostedAiSpend, diffEntitlements, ENTITLEMENT_CHANGE_LISTENERS_SLOT_KEY, type EntitlementChange, type EntitlementChangeFailure, type EntitlementChangeListener, type EntitlementChangeOutcome, type EntitlementSnapshot, emptyEntitlementSnapshot, evaluateHostedAiSpendThreshold, evaluateThreshold, evaluateThresholds, FEATURE_GRANT_SOURCE_SLOT_KEY, type GrantingPlanReader, getEntitlementChangeListeners, type HostedAiSpendDecision, type HostedAiSpendEvaluation, HostedAiSpendEvaluator, type HostedAiSpendEvaluatorOptions, type HostedAiSpendPolicy, HostedAiSpendPolicyError, type HostedAiSpendReader, type HostedAiSpendScope, type HostedAiSpendSummary, hasEntitlementChange, hostedAiSpendThresholds, hostedAiTagFragment, isMissingSubscriptionTableError, MICROS_PER_USD, notifyEntitlementChange, ResellerBillingError, ResellerBillingService, registerEntitlementChangeListener, registerSubscriptionFeatureSource, SpendingPolicyEvaluator, type SubscriptionFeatureGrants, SubscriptionFeatureSource, type SubscriptionFeatureSourceOptions, type SubscriptionGrantingPlan, type SubscriptionPlanReader, type SubscriptionPlanVersionReader, SubscriptionResolver, type SubscriptionResolverReaders, snapshotEntitlements, type TenantSubscriptionReader, TenantUsageMeter, type TrackEntitlementChangeOptions, trackEntitlementChange, UnsupportedCommercialBillingStorageError, type UsageSummaryReader, } from './services/index.js';
|
|
20
21
|
export type { AiUsageSummary, BillingInterval, EntitlementResolution, EntitlementResolutionContext, JsonObject, PlanFeatureGrant, PlanTerms, PlanThreshold, PlanVersionPinReason, PricingMode, RecordUsageOptions, Subscriber, SubscriberKind, SubscriptionPlanStatus, SubscriptionPlanVersionOptions, SubscriptionResolverOptions, SubscriptionStatus, SummarizeAiUsageOptions, SummarizeUsageBatchOptions, SummarizeUsageOptions, ThresholdEnforcement, ThresholdEvaluation, ThresholdWindow, UsageMeterOptions, UsageMetricRecord, UsageSummary, UsageWindow, } from './types.js';
|
|
21
22
|
export { assertSubscriberInvariant, getWindowForThreshold, getWindowKey, isValidThreshold, normalizeFeatureGrants, normalizeSubscriber, subscriberToColumns, } from './utils.js';
|
|
23
|
+
export { createVaultRelayAdminClient, NOT_OWNER_CODE, NotOwnerError, type ProvisionRestartAccountInput, type ProvisionRestartAccountResult, provisionRestartAccount, StepUpRequiredError, type SupersedeVaultAccountInput, supersedeVaultAccount, type UnsupersedeVaultAccountInput, unsupersedeVaultAccount, type VaultAccountAction, type VaultAccountAdminDeps, VaultAccountAdminError, type VaultAccountAuditEntry, type VaultAccountAuditSink, type VaultAccountDenial, type VaultAccountDirectory, type VaultRelayAdminClientOptions, type VaultRelayAdminPort, } from './vault-account/index.js';
|
|
22
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,wBAAwB,CAAC;AAGhC,OAAO,EACL,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EA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