@superblocksteam/shared 0.9601.3 → 0.9602.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database-lifecycle/index.d.ts +4 -2
- package/dist/database-lifecycle/index.d.ts.map +1 -1
- package/dist/database-lifecycle/index.js +14 -5
- package/dist/database-lifecycle/index.js.map +1 -1
- package/dist/database-lifecycle/index.test.js +49 -1
- package/dist/database-lifecycle/index.test.js.map +1 -1
- package/dist/plugins/templates/postgres.d.ts.map +1 -1
- package/dist/plugins/templates/postgres.js +17 -14
- package/dist/plugins/templates/postgres.js.map +1 -1
- package/dist/plugins/templates/postgres.test.js +14 -1
- package/dist/plugins/templates/postgres.test.js.map +1 -1
- package/dist/tracing/errorSanitizer.js +4 -4
- package/dist/tracing/errorSanitizer.js.map +1 -1
- package/dist/tracing/errorSanitizer.test.js +19 -3
- package/dist/tracing/errorSanitizer.test.js.map +1 -1
- package/dist/types/ai/quota-paywall.d.ts +1 -1
- package/dist/types/ai/quota-paywall.d.ts.map +1 -1
- package/dist/types/ai/quota-paywall.js +14 -0
- package/dist/types/ai/quota-paywall.js.map +1 -1
- package/dist/types/ai/quota-paywall.test.js +6 -0
- package/dist/types/ai/quota-paywall.test.js.map +1 -1
- package/dist/types/billing/billing.d.ts +3 -0
- package/dist/types/billing/billing.d.ts.map +1 -1
- package/dist/types/billing/billing.js.map +1 -1
- package/dist/types/billing/index.d.ts +1 -0
- package/dist/types/billing/index.d.ts.map +1 -1
- package/dist/types/billing/index.js +1 -0
- package/dist/types/billing/index.js.map +1 -1
- package/dist/types/billing/pricingModel.d.ts +39 -0
- package/dist/types/billing/pricingModel.d.ts.map +1 -0
- package/dist/types/billing/pricingModel.js +54 -0
- package/dist/types/billing/pricingModel.js.map +1 -0
- package/dist/types/billing/pricingModel.test.d.ts +2 -0
- package/dist/types/billing/pricingModel.test.d.ts.map +1 -0
- package/dist/types/billing/pricingModel.test.js +52 -0
- package/dist/types/billing/pricingModel.test.js.map +1 -0
- package/dist-esm/database-lifecycle/index.d.ts +4 -2
- package/dist-esm/database-lifecycle/index.d.ts.map +1 -1
- package/dist-esm/database-lifecycle/index.js +12 -4
- package/dist-esm/database-lifecycle/index.js.map +1 -1
- package/dist-esm/database-lifecycle/index.test.js +50 -2
- package/dist-esm/database-lifecycle/index.test.js.map +1 -1
- package/dist-esm/plugins/templates/postgres.d.ts.map +1 -1
- package/dist-esm/plugins/templates/postgres.js +17 -14
- package/dist-esm/plugins/templates/postgres.js.map +1 -1
- package/dist-esm/plugins/templates/postgres.test.js +14 -1
- package/dist-esm/plugins/templates/postgres.test.js.map +1 -1
- package/dist-esm/tracing/errorSanitizer.js +4 -4
- package/dist-esm/tracing/errorSanitizer.js.map +1 -1
- package/dist-esm/tracing/errorSanitizer.test.js +19 -3
- package/dist-esm/tracing/errorSanitizer.test.js.map +1 -1
- package/dist-esm/types/ai/quota-paywall.d.ts +1 -1
- package/dist-esm/types/ai/quota-paywall.d.ts.map +1 -1
- package/dist-esm/types/ai/quota-paywall.js +14 -0
- package/dist-esm/types/ai/quota-paywall.js.map +1 -1
- package/dist-esm/types/ai/quota-paywall.test.js +6 -0
- package/dist-esm/types/ai/quota-paywall.test.js.map +1 -1
- package/dist-esm/types/billing/billing.d.ts +3 -0
- package/dist-esm/types/billing/billing.d.ts.map +1 -1
- package/dist-esm/types/billing/billing.js.map +1 -1
- package/dist-esm/types/billing/index.d.ts +1 -0
- package/dist-esm/types/billing/index.d.ts.map +1 -1
- package/dist-esm/types/billing/index.js +1 -0
- package/dist-esm/types/billing/index.js.map +1 -1
- package/dist-esm/types/billing/pricingModel.d.ts +39 -0
- package/dist-esm/types/billing/pricingModel.d.ts.map +1 -0
- package/dist-esm/types/billing/pricingModel.js +48 -0
- package/dist-esm/types/billing/pricingModel.js.map +1 -0
- package/dist-esm/types/billing/pricingModel.test.d.ts +2 -0
- package/dist-esm/types/billing/pricingModel.test.d.ts.map +1 -0
- package/dist-esm/types/billing/pricingModel.test.js +50 -0
- package/dist-esm/types/billing/pricingModel.test.js.map +1 -0
- package/package.json +1 -1
- package/src/database-lifecycle/index.test.ts +57 -1
- package/src/database-lifecycle/index.ts +15 -5
- package/src/plugins/templates/postgres.test.ts +18 -1
- package/src/plugins/templates/postgres.ts +17 -14
- package/src/tracing/errorSanitizer.test.ts +20 -3
- package/src/tracing/errorSanitizer.ts +4 -4
- package/src/types/ai/quota-paywall.test.ts +9 -0
- package/src/types/ai/quota-paywall.ts +19 -0
- package/src/types/billing/billing.ts +3 -0
- package/src/types/billing/index.ts +1 -0
- package/src/types/billing/pricingModel.test.ts +60 -0
- package/src/types/billing/pricingModel.ts +52 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which pricing model an organization is on, persisted on `billing.pricing_model`.
|
|
3
|
+
*
|
|
4
|
+
* `seats` (default) is the legacy seat-based model: the Stripe subscription is
|
|
5
|
+
* anchored on a `builder_seat` line item and AI usage is gated per assigned seat.
|
|
6
|
+
* `credits` is the PLG model where the org buys credit packs (surfaced as "GAUs")
|
|
7
|
+
* and deployed apps, and AI usage is metered against the org-level pool with no seats.
|
|
8
|
+
*
|
|
9
|
+
* Values match the PostgreSQL `pricing_model_enum`. Existing orgs default to `seats`
|
|
10
|
+
* so they are grandfathered onto seat-based pricing until explicitly migrated.
|
|
11
|
+
*/
|
|
12
|
+
export enum PricingModelEnum {
|
|
13
|
+
CREDITS = 'credits',
|
|
14
|
+
SEATS = 'seats'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PricingModel = `${PricingModelEnum}`;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* True only when the org is on the seatless credits (GAU) pricing model. Anything
|
|
21
|
+
* absent or unrecognized is treated as seat-based — the grandfather-safe default.
|
|
22
|
+
*/
|
|
23
|
+
export function isCreditsPricing(pricingModel: PricingModel | undefined | null): boolean {
|
|
24
|
+
return pricingModel === PricingModelEnum.CREDITS;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* True when the org is on seat-based pricing — the inverse of {@link isCreditsPricing}.
|
|
29
|
+
* Anything absent or unrecognized reads as seat-based, so use this rather than a raw
|
|
30
|
+
* `=== 'seats'` comparison, which would miss the grandfathered (unset) case.
|
|
31
|
+
*/
|
|
32
|
+
export function isSeatsPricing(pricingModel: PricingModel | undefined | null): boolean {
|
|
33
|
+
return !isCreditsPricing(pricingModel);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const KNOWN_PRICING_MODELS: ReadonlySet<string> = new Set(Object.values(PricingModelEnum));
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Coerce the raw value of the `superblocks.billing.default-pricing-model` LaunchDarkly
|
|
40
|
+
* flag into a valid {@link PricingModel} for stamping onto a new org at creation. (Conversion
|
|
41
|
+
* does not re-resolve the flag; it carries the existing stamp forward — see
|
|
42
|
+
* `createBillingHistoryRowForOrg`.)
|
|
43
|
+
*
|
|
44
|
+
* Fails **closed to `seats`** for anything unrecognized — an LD typo, a variation the
|
|
45
|
+
* running code doesn't know yet, or a wrong-typed value — so a misconfigured flag can
|
|
46
|
+
* never strand a new org on a half-built pricing model.
|
|
47
|
+
*/
|
|
48
|
+
export function resolvePricingModel(rawFlagValue: unknown): PricingModel {
|
|
49
|
+
return typeof rawFlagValue === 'string' && KNOWN_PRICING_MODELS.has(rawFlagValue)
|
|
50
|
+
? (rawFlagValue as PricingModel)
|
|
51
|
+
: PricingModelEnum.SEATS;
|
|
52
|
+
}
|