@usebillow/sdk 0.5.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +274 -0
  4. package/dist/billing-C4RIMgH_.d.ts +1053 -0
  5. package/dist/billing-DZ4rIyg7.d.cts +1053 -0
  6. package/dist/billing-status-BZQN_gm7.d.cts +29 -0
  7. package/dist/billing-status-BZQN_gm7.d.ts +29 -0
  8. package/dist/chunk-CCG4F5FK.js +48 -0
  9. package/dist/chunk-CCG4F5FK.js.map +1 -0
  10. package/dist/chunk-Z6VXPONT.js +1493 -0
  11. package/dist/chunk-Z6VXPONT.js.map +1 -0
  12. package/dist/config.cjs +233 -0
  13. package/dist/config.cjs.map +1 -0
  14. package/dist/config.d.cts +104 -0
  15. package/dist/config.d.ts +104 -0
  16. package/dist/config.js +228 -0
  17. package/dist/config.js.map +1 -0
  18. package/dist/credits-C3Fe3TO0.d.cts +315 -0
  19. package/dist/credits-C3Fe3TO0.d.ts +315 -0
  20. package/dist/index.cjs +1560 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +2379 -0
  23. package/dist/index.d.ts +2379 -0
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/ingestion.cjs +259 -0
  27. package/dist/ingestion.cjs.map +1 -0
  28. package/dist/ingestion.d.cts +182 -0
  29. package/dist/ingestion.d.ts +182 -0
  30. package/dist/ingestion.js +252 -0
  31. package/dist/ingestion.js.map +1 -0
  32. package/dist/react.cjs +360 -0
  33. package/dist/react.cjs.map +1 -0
  34. package/dist/react.d.cts +71 -0
  35. package/dist/react.d.ts +71 -0
  36. package/dist/react.js +153 -0
  37. package/dist/react.js.map +1 -0
  38. package/dist/server.cjs +98 -0
  39. package/dist/server.cjs.map +1 -0
  40. package/dist/server.d.cts +54 -0
  41. package/dist/server.d.ts +54 -0
  42. package/dist/server.js +96 -0
  43. package/dist/server.js.map +1 -0
  44. package/dist/status.cjs +60 -0
  45. package/dist/status.cjs.map +1 -0
  46. package/dist/status.d.cts +31 -0
  47. package/dist/status.d.ts +31 -0
  48. package/dist/status.js +3 -0
  49. package/dist/status.js.map +1 -0
  50. package/dist/webhooks.cjs +157 -0
  51. package/dist/webhooks.cjs.map +1 -0
  52. package/dist/webhooks.d.cts +391 -0
  53. package/dist/webhooks.d.ts +391 -0
  54. package/dist/webhooks.js +143 -0
  55. package/dist/webhooks.js.map +1 -0
  56. package/package.json +169 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Charge / invoice / refund / payment-method / webhook-delivery status vocabularies,
3
+ * mirrored for the SDK (which cannot import the server-side `@billow/core`). The DB-enum
4
+ * ones (charge, invoice, refund, payment method) mirror core enums and are parity-tested
5
+ * against it (see billing-status.test.ts); webhook-delivery status is a free-text column
6
+ * server-side with a fixed vocabulary, documented here.
7
+ */
8
+ /** A charge's lifecycle status — mirrors `@billow/core` `CHARGE_STATUSES`. */
9
+ declare const CHARGE_STATUSES: readonly ["pending", "processing", "succeeded", "failed", "requires_reconciliation", "disputed"];
10
+ type ChargeStatus = (typeof CHARGE_STATUSES)[number];
11
+ /** An invoice's lifecycle status — mirrors `@billow/core` `INVOICE_STATUSES`. */
12
+ declare const INVOICE_STATUSES: readonly ["draft", "open", "paid", "uncollectible", "void"];
13
+ type InvoiceStatus = (typeof INVOICE_STATUSES)[number];
14
+ /** A refund's lifecycle status — mirrors `@billow/core` `REFUND_STATUSES`. */
15
+ declare const REFUND_STATUSES: readonly ["pending", "succeeded", "failed"];
16
+ type RefundStatus = (typeof REFUND_STATUSES)[number];
17
+ /** A saved payment method's status — mirrors `@billow/core` `PAYMENT_METHOD_STATUSES`. */
18
+ declare const PAYMENT_METHOD_STATUSES: readonly ["active", "expired", "removed"];
19
+ type PaymentMethodStatus = (typeof PAYMENT_METHOD_STATUSES)[number];
20
+ /**
21
+ * A webhook delivery attempt's status. Not a DB enum (a free-text column); the dispatcher
22
+ * inserts one row per attempt with exactly `delivered` (a 2xx) or `failed` (anything else) —
23
+ * see `packages/server/src/jobs/outbox.ts`. (Retry/backoff state lives on the outbox event,
24
+ * a separate table, not on the delivery record.)
25
+ */
26
+ declare const WEBHOOK_DELIVERY_STATUSES: readonly ["delivered", "failed"];
27
+ type WebhookDeliveryStatus = (typeof WEBHOOK_DELIVERY_STATUSES)[number];
28
+
29
+ export { type ChargeStatus as C, type InvoiceStatus as I, type PaymentMethodStatus as P, type RefundStatus as R, type WebhookDeliveryStatus as W, CHARGE_STATUSES as a, INVOICE_STATUSES as b, PAYMENT_METHOD_STATUSES as c, REFUND_STATUSES as d, WEBHOOK_DELIVERY_STATUSES as e };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Charge / invoice / refund / payment-method / webhook-delivery status vocabularies,
3
+ * mirrored for the SDK (which cannot import the server-side `@billow/core`). The DB-enum
4
+ * ones (charge, invoice, refund, payment method) mirror core enums and are parity-tested
5
+ * against it (see billing-status.test.ts); webhook-delivery status is a free-text column
6
+ * server-side with a fixed vocabulary, documented here.
7
+ */
8
+ /** A charge's lifecycle status — mirrors `@billow/core` `CHARGE_STATUSES`. */
9
+ declare const CHARGE_STATUSES: readonly ["pending", "processing", "succeeded", "failed", "requires_reconciliation", "disputed"];
10
+ type ChargeStatus = (typeof CHARGE_STATUSES)[number];
11
+ /** An invoice's lifecycle status — mirrors `@billow/core` `INVOICE_STATUSES`. */
12
+ declare const INVOICE_STATUSES: readonly ["draft", "open", "paid", "uncollectible", "void"];
13
+ type InvoiceStatus = (typeof INVOICE_STATUSES)[number];
14
+ /** A refund's lifecycle status — mirrors `@billow/core` `REFUND_STATUSES`. */
15
+ declare const REFUND_STATUSES: readonly ["pending", "succeeded", "failed"];
16
+ type RefundStatus = (typeof REFUND_STATUSES)[number];
17
+ /** A saved payment method's status — mirrors `@billow/core` `PAYMENT_METHOD_STATUSES`. */
18
+ declare const PAYMENT_METHOD_STATUSES: readonly ["active", "expired", "removed"];
19
+ type PaymentMethodStatus = (typeof PAYMENT_METHOD_STATUSES)[number];
20
+ /**
21
+ * A webhook delivery attempt's status. Not a DB enum (a free-text column); the dispatcher
22
+ * inserts one row per attempt with exactly `delivered` (a 2xx) or `failed` (anything else) —
23
+ * see `packages/server/src/jobs/outbox.ts`. (Retry/backoff state lives on the outbox event,
24
+ * a separate table, not on the delivery record.)
25
+ */
26
+ declare const WEBHOOK_DELIVERY_STATUSES: readonly ["delivered", "failed"];
27
+ type WebhookDeliveryStatus = (typeof WEBHOOK_DELIVERY_STATUSES)[number];
28
+
29
+ export { type ChargeStatus as C, type InvoiceStatus as I, type PaymentMethodStatus as P, type RefundStatus as R, type WebhookDeliveryStatus as W, CHARGE_STATUSES as a, INVOICE_STATUSES as b, PAYMENT_METHOD_STATUSES as c, REFUND_STATUSES as d, WEBHOOK_DELIVERY_STATUSES as e };
@@ -0,0 +1,48 @@
1
+ // src/billing-status.ts
2
+ var CHARGE_STATUSES = [
3
+ "pending",
4
+ "processing",
5
+ "succeeded",
6
+ "failed",
7
+ "requires_reconciliation",
8
+ "disputed"
9
+ ];
10
+ var INVOICE_STATUSES = ["draft", "open", "paid", "uncollectible", "void"];
11
+ var REFUND_STATUSES = ["pending", "succeeded", "failed"];
12
+ var PAYMENT_METHOD_STATUSES = ["active", "expired", "removed"];
13
+ var WEBHOOK_DELIVERY_STATUSES = ["delivered", "failed"];
14
+
15
+ // src/subscription-status.ts
16
+ var SUBSCRIPTION_STATUSES = [
17
+ "incomplete",
18
+ "incomplete_expired",
19
+ "trialing",
20
+ "active",
21
+ "past_due",
22
+ "paused",
23
+ "canceled",
24
+ "unpaid"
25
+ ];
26
+ var ACTIVE_SUBSCRIPTION_STATUSES = [
27
+ "trialing",
28
+ "active",
29
+ "past_due"
30
+ ];
31
+ var TERMINAL_SUBSCRIPTION_STATUSES = [
32
+ "incomplete_expired",
33
+ "canceled"
34
+ ];
35
+ var NEVER_ACTIVATED_SUBSCRIPTION_STATUSES = [
36
+ "incomplete",
37
+ "incomplete_expired"
38
+ ];
39
+ function grantsAccess(status) {
40
+ return ACTIVE_SUBSCRIPTION_STATUSES.includes(status);
41
+ }
42
+ function isTerminal(status) {
43
+ return TERMINAL_SUBSCRIPTION_STATUSES.includes(status);
44
+ }
45
+
46
+ export { ACTIVE_SUBSCRIPTION_STATUSES, CHARGE_STATUSES, INVOICE_STATUSES, NEVER_ACTIVATED_SUBSCRIPTION_STATUSES, PAYMENT_METHOD_STATUSES, REFUND_STATUSES, SUBSCRIPTION_STATUSES, TERMINAL_SUBSCRIPTION_STATUSES, WEBHOOK_DELIVERY_STATUSES, grantsAccess, isTerminal };
47
+ //# sourceMappingURL=chunk-CCG4F5FK.js.map
48
+ //# sourceMappingURL=chunk-CCG4F5FK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/billing-status.ts","../src/subscription-status.ts"],"names":[],"mappings":";AASO,IAAM,eAAA,GAAkB;AAAA,EAC7B,SAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA,QAAA;AAAA,EACA,yBAAA;AAAA,EACA;AACF;AAIO,IAAM,mBAAmB,CAAC,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,iBAAiB,MAAM;AAI1E,IAAM,eAAA,GAAkB,CAAC,SAAA,EAAW,WAAA,EAAa,QAAQ;AAIzD,IAAM,uBAAA,GAA0B,CAAC,QAAA,EAAU,SAAA,EAAW,SAAS;AAS/D,IAAM,yBAAA,GAA4B,CAAC,WAAA,EAAa,QAAQ;;;ACxBxD,IAAM,qBAAA,GAAwB;AAAA,EACnC,YAAA;AAAA,EACA,oBAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA,QAAA;AAAA,EACA,UAAA;AAAA,EACA;AACF;AAQO,IAAM,4BAAA,GAA8D;AAAA,EACzE,UAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAGO,IAAM,8BAAA,GAAgE;AAAA,EAC3E,oBAAA;AAAA,EACA;AACF;AAGO,IAAM,qCAAA,GAAuE;AAAA,EAClF,YAAA;AAAA,EACA;AACF;AAGO,SAAS,aAAa,MAAA,EAAqC;AAChE,EAAA,OAAO,4BAAA,CAA6B,SAAS,MAAM,CAAA;AACrD;AAGO,SAAS,WAAW,MAAA,EAAqC;AAC9D,EAAA,OAAO,8BAAA,CAA+B,SAAS,MAAM,CAAA;AACvD","file":"chunk-CCG4F5FK.js","sourcesContent":["/**\n * Charge / invoice / refund / payment-method / webhook-delivery status vocabularies,\n * mirrored for the SDK (which cannot import the server-side `@billow/core`). The DB-enum\n * ones (charge, invoice, refund, payment method) mirror core enums and are parity-tested\n * against it (see billing-status.test.ts); webhook-delivery status is a free-text column\n * server-side with a fixed vocabulary, documented here.\n */\n\n/** A charge's lifecycle status — mirrors `@billow/core` `CHARGE_STATUSES`. */\nexport const CHARGE_STATUSES = [\n \"pending\",\n \"processing\",\n \"succeeded\",\n \"failed\",\n \"requires_reconciliation\",\n \"disputed\",\n] as const;\nexport type ChargeStatus = (typeof CHARGE_STATUSES)[number];\n\n/** An invoice's lifecycle status — mirrors `@billow/core` `INVOICE_STATUSES`. */\nexport const INVOICE_STATUSES = [\"draft\", \"open\", \"paid\", \"uncollectible\", \"void\"] as const;\nexport type InvoiceStatus = (typeof INVOICE_STATUSES)[number];\n\n/** A refund's lifecycle status — mirrors `@billow/core` `REFUND_STATUSES`. */\nexport const REFUND_STATUSES = [\"pending\", \"succeeded\", \"failed\"] as const;\nexport type RefundStatus = (typeof REFUND_STATUSES)[number];\n\n/** A saved payment method's status — mirrors `@billow/core` `PAYMENT_METHOD_STATUSES`. */\nexport const PAYMENT_METHOD_STATUSES = [\"active\", \"expired\", \"removed\"] as const;\nexport type PaymentMethodStatus = (typeof PAYMENT_METHOD_STATUSES)[number];\n\n/**\n * A webhook delivery attempt's status. Not a DB enum (a free-text column); the dispatcher\n * inserts one row per attempt with exactly `delivered` (a 2xx) or `failed` (anything else) —\n * see `packages/server/src/jobs/outbox.ts`. (Retry/backoff state lives on the outbox event,\n * a separate table, not on the delivery record.)\n */\nexport const WEBHOOK_DELIVERY_STATUSES = [\"delivered\", \"failed\"] as const;\nexport type WebhookDeliveryStatus = (typeof WEBHOOK_DELIVERY_STATUSES)[number];\n","/**\n * The subscription status vocabulary + access predicate, mirrored from @billow/core\n * (`enums.ts` + `billing/subscription-state.ts`) so SDK consumers can type and branch on\n * billow's own model instead of hand-maintaining a union that drifts (a real bug: an app\n * copy once carried a non-existent `ended` status - that string is a webhook event type,\n * not a subscription status).\n *\n * Mirrored, not imported: @billow/core is a server package the published SDK cannot depend\n * on (the same reason @billow/contracts mirrors core's pure logic). The parity test\n * `subscription-status.test.ts` imports @billow/core and fails CI on any drift.\n */\n\n/** The 8 canonical subscription statuses, in lifecycle order. */\nexport const SUBSCRIPTION_STATUSES = [\n \"incomplete\",\n \"incomplete_expired\",\n \"trialing\",\n \"active\",\n \"past_due\",\n \"paused\",\n \"canceled\",\n \"unpaid\",\n] as const;\n\nexport type SubscriptionStatus = (typeof SUBSCRIPTION_STATUSES)[number];\n\n/**\n * Statuses that currently grant access (a live commitment): `trialing`, `active`, and\n * `past_due` (access is retained through dunning). Note `paused` does NOT grant access.\n */\nexport const ACTIVE_SUBSCRIPTION_STATUSES: readonly SubscriptionStatus[] = [\n \"trialing\",\n \"active\",\n \"past_due\",\n];\n\n/** Statuses a subscription can never leave: `incomplete_expired` and `canceled`. */\nexport const TERMINAL_SUBSCRIPTION_STATUSES: readonly SubscriptionStatus[] = [\n \"incomplete_expired\",\n \"canceled\",\n];\n\n/** Statuses in which a subscription never activated (no access was ever granted). */\nexport const NEVER_ACTIVATED_SUBSCRIPTION_STATUSES: readonly SubscriptionStatus[] = [\n \"incomplete\",\n \"incomplete_expired\",\n];\n\n/** Whether access should currently be granted for a subscription in this state. */\nexport function grantsAccess(status: SubscriptionStatus): boolean {\n return ACTIVE_SUBSCRIPTION_STATUSES.includes(status);\n}\n\n/** Whether this is a terminal status the subscription can never leave. */\nexport function isTerminal(status: SubscriptionStatus): boolean {\n return TERMINAL_SUBSCRIPTION_STATUSES.includes(status);\n}\n"]}