@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.
Files changed (85) hide show
  1. package/dist/database-lifecycle/index.d.ts +4 -2
  2. package/dist/database-lifecycle/index.d.ts.map +1 -1
  3. package/dist/database-lifecycle/index.js +14 -5
  4. package/dist/database-lifecycle/index.js.map +1 -1
  5. package/dist/database-lifecycle/index.test.js +49 -1
  6. package/dist/database-lifecycle/index.test.js.map +1 -1
  7. package/dist/plugins/templates/postgres.d.ts.map +1 -1
  8. package/dist/plugins/templates/postgres.js +17 -14
  9. package/dist/plugins/templates/postgres.js.map +1 -1
  10. package/dist/plugins/templates/postgres.test.js +14 -1
  11. package/dist/plugins/templates/postgres.test.js.map +1 -1
  12. package/dist/tracing/errorSanitizer.js +4 -4
  13. package/dist/tracing/errorSanitizer.js.map +1 -1
  14. package/dist/tracing/errorSanitizer.test.js +19 -3
  15. package/dist/tracing/errorSanitizer.test.js.map +1 -1
  16. package/dist/types/ai/quota-paywall.d.ts +1 -1
  17. package/dist/types/ai/quota-paywall.d.ts.map +1 -1
  18. package/dist/types/ai/quota-paywall.js +14 -0
  19. package/dist/types/ai/quota-paywall.js.map +1 -1
  20. package/dist/types/ai/quota-paywall.test.js +6 -0
  21. package/dist/types/ai/quota-paywall.test.js.map +1 -1
  22. package/dist/types/billing/billing.d.ts +3 -0
  23. package/dist/types/billing/billing.d.ts.map +1 -1
  24. package/dist/types/billing/billing.js.map +1 -1
  25. package/dist/types/billing/index.d.ts +1 -0
  26. package/dist/types/billing/index.d.ts.map +1 -1
  27. package/dist/types/billing/index.js +1 -0
  28. package/dist/types/billing/index.js.map +1 -1
  29. package/dist/types/billing/pricingModel.d.ts +39 -0
  30. package/dist/types/billing/pricingModel.d.ts.map +1 -0
  31. package/dist/types/billing/pricingModel.js +54 -0
  32. package/dist/types/billing/pricingModel.js.map +1 -0
  33. package/dist/types/billing/pricingModel.test.d.ts +2 -0
  34. package/dist/types/billing/pricingModel.test.d.ts.map +1 -0
  35. package/dist/types/billing/pricingModel.test.js +52 -0
  36. package/dist/types/billing/pricingModel.test.js.map +1 -0
  37. package/dist-esm/database-lifecycle/index.d.ts +4 -2
  38. package/dist-esm/database-lifecycle/index.d.ts.map +1 -1
  39. package/dist-esm/database-lifecycle/index.js +12 -4
  40. package/dist-esm/database-lifecycle/index.js.map +1 -1
  41. package/dist-esm/database-lifecycle/index.test.js +50 -2
  42. package/dist-esm/database-lifecycle/index.test.js.map +1 -1
  43. package/dist-esm/plugins/templates/postgres.d.ts.map +1 -1
  44. package/dist-esm/plugins/templates/postgres.js +17 -14
  45. package/dist-esm/plugins/templates/postgres.js.map +1 -1
  46. package/dist-esm/plugins/templates/postgres.test.js +14 -1
  47. package/dist-esm/plugins/templates/postgres.test.js.map +1 -1
  48. package/dist-esm/tracing/errorSanitizer.js +4 -4
  49. package/dist-esm/tracing/errorSanitizer.js.map +1 -1
  50. package/dist-esm/tracing/errorSanitizer.test.js +19 -3
  51. package/dist-esm/tracing/errorSanitizer.test.js.map +1 -1
  52. package/dist-esm/types/ai/quota-paywall.d.ts +1 -1
  53. package/dist-esm/types/ai/quota-paywall.d.ts.map +1 -1
  54. package/dist-esm/types/ai/quota-paywall.js +14 -0
  55. package/dist-esm/types/ai/quota-paywall.js.map +1 -1
  56. package/dist-esm/types/ai/quota-paywall.test.js +6 -0
  57. package/dist-esm/types/ai/quota-paywall.test.js.map +1 -1
  58. package/dist-esm/types/billing/billing.d.ts +3 -0
  59. package/dist-esm/types/billing/billing.d.ts.map +1 -1
  60. package/dist-esm/types/billing/billing.js.map +1 -1
  61. package/dist-esm/types/billing/index.d.ts +1 -0
  62. package/dist-esm/types/billing/index.d.ts.map +1 -1
  63. package/dist-esm/types/billing/index.js +1 -0
  64. package/dist-esm/types/billing/index.js.map +1 -1
  65. package/dist-esm/types/billing/pricingModel.d.ts +39 -0
  66. package/dist-esm/types/billing/pricingModel.d.ts.map +1 -0
  67. package/dist-esm/types/billing/pricingModel.js +48 -0
  68. package/dist-esm/types/billing/pricingModel.js.map +1 -0
  69. package/dist-esm/types/billing/pricingModel.test.d.ts +2 -0
  70. package/dist-esm/types/billing/pricingModel.test.d.ts.map +1 -0
  71. package/dist-esm/types/billing/pricingModel.test.js +50 -0
  72. package/dist-esm/types/billing/pricingModel.test.js.map +1 -0
  73. package/package.json +1 -1
  74. package/src/database-lifecycle/index.test.ts +57 -1
  75. package/src/database-lifecycle/index.ts +15 -5
  76. package/src/plugins/templates/postgres.test.ts +18 -1
  77. package/src/plugins/templates/postgres.ts +17 -14
  78. package/src/tracing/errorSanitizer.test.ts +20 -3
  79. package/src/tracing/errorSanitizer.ts +4 -4
  80. package/src/types/ai/quota-paywall.test.ts +9 -0
  81. package/src/types/ai/quota-paywall.ts +19 -0
  82. package/src/types/billing/billing.ts +3 -0
  83. package/src/types/billing/index.ts +1 -0
  84. package/src/types/billing/pricingModel.test.ts +60 -0
  85. 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
+ }