@onflay/node 0.2.1 → 1.0.0-staging-20261206080029

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 (218) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +211 -48
  3. package/dist/chunk-4RUPPDC2.mjs +121 -0
  4. package/dist/chunk-4RUPPDC2.mjs.map +1 -0
  5. package/dist/chunk-63KSRMJG.mjs +47 -0
  6. package/dist/chunk-63KSRMJG.mjs.map +1 -0
  7. package/dist/chunk-7LYAEZCT.mjs +197 -0
  8. package/dist/chunk-7LYAEZCT.mjs.map +1 -0
  9. package/dist/chunk-A3TRCKHK.mjs +60 -0
  10. package/dist/chunk-A3TRCKHK.mjs.map +1 -0
  11. package/dist/chunk-AFAU2FH2.js +47 -0
  12. package/dist/chunk-AFAU2FH2.js.map +1 -0
  13. package/dist/chunk-DBE2YZWE.mjs +38 -0
  14. package/dist/chunk-DBE2YZWE.mjs.map +1 -0
  15. package/dist/chunk-EOHFYWFQ.mjs +154 -0
  16. package/dist/chunk-EOHFYWFQ.mjs.map +1 -0
  17. package/dist/chunk-I2IVHBFA.js +197 -0
  18. package/dist/chunk-I2IVHBFA.js.map +1 -0
  19. package/dist/chunk-J4MYKTPN.mjs +37 -0
  20. package/dist/chunk-J4MYKTPN.mjs.map +1 -0
  21. package/dist/chunk-JQPANXLV.mjs +37 -0
  22. package/dist/chunk-JQPANXLV.mjs.map +1 -0
  23. package/dist/chunk-JXP6V2P2.mjs +1057 -0
  24. package/dist/chunk-JXP6V2P2.mjs.map +1 -0
  25. package/dist/chunk-M52GW7GQ.js +1057 -0
  26. package/dist/chunk-M52GW7GQ.js.map +1 -0
  27. package/dist/chunk-MMMUKAI6.js +37 -0
  28. package/dist/chunk-MMMUKAI6.js.map +1 -0
  29. package/dist/chunk-NSR4UQLV.js +87 -0
  30. package/dist/chunk-NSR4UQLV.js.map +1 -0
  31. package/dist/chunk-SUONZUVK.js +154 -0
  32. package/dist/chunk-SUONZUVK.js.map +1 -0
  33. package/dist/chunk-T26CPULH.js +121 -0
  34. package/dist/chunk-T26CPULH.js.map +1 -0
  35. package/dist/chunk-V2XJ4GZU.js +38 -0
  36. package/dist/chunk-V2XJ4GZU.js.map +1 -0
  37. package/dist/chunk-W6AEPYUG.js +37 -0
  38. package/dist/chunk-W6AEPYUG.js.map +1 -0
  39. package/dist/chunk-YHQ7XIC6.js +60 -0
  40. package/dist/chunk-YHQ7XIC6.js.map +1 -0
  41. package/dist/chunk-YSXUZYUY.mjs +87 -0
  42. package/dist/chunk-YSXUZYUY.mjs.map +1 -0
  43. package/dist/index-C1KFW_9r.d.mts +3989 -0
  44. package/dist/index-C1KFW_9r.d.ts +3989 -0
  45. package/dist/index.d.mts +918 -0
  46. package/dist/index.d.ts +918 -26
  47. package/dist/index.js +2990 -40
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs +2991 -0
  50. package/dist/index.mjs.map +1 -0
  51. package/dist/lib/config.d.mts +59 -0
  52. package/dist/lib/config.d.ts +59 -0
  53. package/dist/lib/config.js +15 -0
  54. package/dist/lib/config.js.map +1 -0
  55. package/dist/lib/config.mjs +15 -0
  56. package/dist/lib/config.mjs.map +1 -0
  57. package/dist/lib/http.d.mts +51 -0
  58. package/dist/lib/http.d.ts +51 -0
  59. package/dist/lib/http.js +13 -0
  60. package/dist/lib/http.js.map +1 -0
  61. package/dist/lib/http.mjs +13 -0
  62. package/dist/lib/http.mjs.map +1 -0
  63. package/dist/lib/retries.d.mts +41 -0
  64. package/dist/lib/retries.d.ts +41 -0
  65. package/dist/lib/retries.js +16 -0
  66. package/dist/lib/retries.js.map +1 -0
  67. package/dist/lib/retries.mjs +16 -0
  68. package/dist/lib/retries.mjs.map +1 -0
  69. package/dist/lib/sdks.d.mts +61 -0
  70. package/dist/lib/sdks.d.ts +61 -0
  71. package/dist/lib/sdks.js +12 -0
  72. package/dist/lib/sdks.js.map +1 -0
  73. package/dist/lib/sdks.mjs +12 -0
  74. package/dist/lib/sdks.mjs.map +1 -0
  75. package/dist/models/components/index.d.mts +1 -0
  76. package/dist/models/components/index.d.ts +1 -0
  77. package/dist/models/components/index.js +1 -0
  78. package/dist/models/components/index.js.map +1 -0
  79. package/dist/models/components/index.mjs +1 -0
  80. package/dist/models/components/index.mjs.map +1 -0
  81. package/dist/models/errors/index.d.mts +161 -0
  82. package/dist/models/errors/index.d.ts +161 -0
  83. package/dist/models/errors/index.js +29 -0
  84. package/dist/models/errors/index.js.map +1 -0
  85. package/dist/models/errors/index.mjs +29 -0
  86. package/dist/models/errors/index.mjs.map +1 -0
  87. package/dist/models/operations/index.d.mts +769 -0
  88. package/dist/models/operations/index.d.ts +769 -0
  89. package/dist/models/operations/index.js +1 -0
  90. package/dist/models/operations/index.js.map +1 -0
  91. package/dist/models/operations/index.mjs +1 -0
  92. package/dist/models/operations/index.mjs.map +1 -0
  93. package/dist/types/index.d.mts +26 -0
  94. package/dist/types/index.d.ts +26 -0
  95. package/dist/types/index.js +1 -0
  96. package/dist/types/index.js.map +1 -0
  97. package/dist/types/index.mjs +1 -0
  98. package/dist/types/index.mjs.map +1 -0
  99. package/dist/verify-tF2BsJK6.d.mts +325 -0
  100. package/dist/verify-tF2BsJK6.d.ts +325 -0
  101. package/dist/webhooks/express.d.mts +39 -0
  102. package/dist/webhooks/express.d.ts +39 -0
  103. package/dist/webhooks/express.js +10 -0
  104. package/dist/webhooks/express.js.map +1 -0
  105. package/dist/webhooks/express.mjs +10 -0
  106. package/dist/webhooks/express.mjs.map +1 -0
  107. package/dist/webhooks/hono.d.mts +33 -0
  108. package/dist/webhooks/hono.d.ts +33 -0
  109. package/dist/webhooks/hono.js +10 -0
  110. package/dist/webhooks/hono.js.map +1 -0
  111. package/dist/webhooks/hono.mjs +10 -0
  112. package/dist/webhooks/hono.mjs.map +1 -0
  113. package/dist/webhooks/index.d.mts +34 -0
  114. package/dist/webhooks/index.d.ts +34 -0
  115. package/dist/webhooks/index.js +75 -0
  116. package/dist/webhooks/index.js.map +1 -0
  117. package/dist/webhooks/index.mjs +75 -0
  118. package/dist/webhooks/index.mjs.map +1 -0
  119. package/dist/webhooks/next.d.mts +38 -0
  120. package/dist/webhooks/next.d.ts +38 -0
  121. package/dist/webhooks/next.js +10 -0
  122. package/dist/webhooks/next.js.map +1 -0
  123. package/dist/webhooks/next.mjs +10 -0
  124. package/dist/webhooks/next.mjs.map +1 -0
  125. package/package.json +273 -14
  126. package/dist/client.d.ts +0 -65
  127. package/dist/client.d.ts.map +0 -1
  128. package/dist/client.js +0 -216
  129. package/dist/client.js.map +0 -1
  130. package/dist/errors.d.ts +0 -61
  131. package/dist/errors.d.ts.map +0 -1
  132. package/dist/errors.js +0 -134
  133. package/dist/errors.js.map +0 -1
  134. package/dist/index.d.ts.map +0 -1
  135. package/dist/onflay.d.ts +0 -42
  136. package/dist/onflay.d.ts.map +0 -1
  137. package/dist/onflay.js +0 -60
  138. package/dist/onflay.js.map +0 -1
  139. package/dist/pagination.d.ts +0 -19
  140. package/dist/pagination.d.ts.map +0 -1
  141. package/dist/pagination.js +0 -61
  142. package/dist/pagination.js.map +0 -1
  143. package/dist/resources/checkout-sessions.d.ts +0 -11
  144. package/dist/resources/checkout-sessions.d.ts.map +0 -1
  145. package/dist/resources/checkout-sessions.js +0 -20
  146. package/dist/resources/checkout-sessions.js.map +0 -1
  147. package/dist/resources/customers.d.ts +0 -17
  148. package/dist/resources/customers.d.ts.map +0 -1
  149. package/dist/resources/customers.js +0 -39
  150. package/dist/resources/customers.js.map +0 -1
  151. package/dist/resources/payments.d.ts +0 -11
  152. package/dist/resources/payments.d.ts.map +0 -1
  153. package/dist/resources/payments.js +0 -27
  154. package/dist/resources/payments.js.map +0 -1
  155. package/dist/resources/prices.d.ts +0 -24
  156. package/dist/resources/prices.d.ts.map +0 -1
  157. package/dist/resources/prices.js +0 -46
  158. package/dist/resources/prices.js.map +0 -1
  159. package/dist/resources/products.d.ts +0 -18
  160. package/dist/resources/products.d.ts.map +0 -1
  161. package/dist/resources/products.js +0 -40
  162. package/dist/resources/products.js.map +0 -1
  163. package/dist/resources/subscriptions.d.ts +0 -39
  164. package/dist/resources/subscriptions.d.ts.map +0 -1
  165. package/dist/resources/subscriptions.js +0 -62
  166. package/dist/resources/subscriptions.js.map +0 -1
  167. package/dist/resources/usage.d.ts +0 -26
  168. package/dist/resources/usage.d.ts.map +0 -1
  169. package/dist/resources/usage.js +0 -43
  170. package/dist/resources/usage.js.map +0 -1
  171. package/dist/resources/webhook-endpoints.d.ts +0 -20
  172. package/dist/resources/webhook-endpoints.d.ts.map +0 -1
  173. package/dist/resources/webhook-endpoints.js +0 -47
  174. package/dist/resources/webhook-endpoints.js.map +0 -1
  175. package/dist/types/checkout-sessions.d.ts +0 -67
  176. package/dist/types/checkout-sessions.d.ts.map +0 -1
  177. package/dist/types/checkout-sessions.js +0 -3
  178. package/dist/types/checkout-sessions.js.map +0 -1
  179. package/dist/types/customers.d.ts +0 -28
  180. package/dist/types/customers.d.ts.map +0 -1
  181. package/dist/types/customers.js +0 -3
  182. package/dist/types/customers.js.map +0 -1
  183. package/dist/types/events.d.ts +0 -95
  184. package/dist/types/events.d.ts.map +0 -1
  185. package/dist/types/events.js +0 -24
  186. package/dist/types/events.js.map +0 -1
  187. package/dist/types/payments.d.ts +0 -25
  188. package/dist/types/payments.d.ts.map +0 -1
  189. package/dist/types/payments.js +0 -3
  190. package/dist/types/payments.js.map +0 -1
  191. package/dist/types/prices.d.ts +0 -57
  192. package/dist/types/prices.d.ts.map +0 -1
  193. package/dist/types/prices.js +0 -3
  194. package/dist/types/prices.js.map +0 -1
  195. package/dist/types/products.d.ts +0 -29
  196. package/dist/types/products.d.ts.map +0 -1
  197. package/dist/types/products.js +0 -3
  198. package/dist/types/products.js.map +0 -1
  199. package/dist/types/shared.d.ts +0 -34
  200. package/dist/types/shared.d.ts.map +0 -1
  201. package/dist/types/shared.js +0 -4
  202. package/dist/types/shared.js.map +0 -1
  203. package/dist/types/subscriptions.d.ts +0 -85
  204. package/dist/types/subscriptions.d.ts.map +0 -1
  205. package/dist/types/subscriptions.js +0 -3
  206. package/dist/types/subscriptions.js.map +0 -1
  207. package/dist/types/usage.d.ts +0 -35
  208. package/dist/types/usage.d.ts.map +0 -1
  209. package/dist/types/usage.js +0 -3
  210. package/dist/types/usage.js.map +0 -1
  211. package/dist/types/webhook-endpoints.d.ts +0 -48
  212. package/dist/types/webhook-endpoints.d.ts.map +0 -1
  213. package/dist/types/webhook-endpoints.js +0 -3
  214. package/dist/types/webhook-endpoints.js.map +0 -1
  215. package/dist/version.d.ts +0 -4
  216. package/dist/version.d.ts.map +0 -1
  217. package/dist/version.js +0 -7
  218. package/dist/version.js.map +0 -1
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Webhook event payloads. Onflay's public OpenAPI spec (3.0) has no `webhooks`
3
+ * section, so these types are hand-written here, next to signature verification.
4
+ * They moved from `@onflay/node` 0.x, which re-exports them from
5
+ * `@onflay/node/webhooks` in 1.x.
6
+ */
7
+ interface OnflayMetadata {
8
+ [key: string]: string | number | boolean | null;
9
+ }
10
+ type SubscriptionStatus = 'active' | 'past_due' | 'canceled' | 'unpaid' | 'expired' | 'trialing' | 'incomplete';
11
+ /** Customer summary embedded in subscriptions and payments. */
12
+ interface OnflayCustomerRef {
13
+ id: string;
14
+ /** Your app's id for the customer (checkout `externalCustomerId`). */
15
+ externalCustomerId: string | null;
16
+ email: string;
17
+ }
18
+ /** Product summary; `key` is the catalog key. */
19
+ interface OnflayProductRef {
20
+ id: string;
21
+ key: string | null;
22
+ name: string;
23
+ }
24
+ /** Plan summary. */
25
+ interface OnflayPlanRef {
26
+ key: string | null;
27
+ name: string;
28
+ }
29
+ /** The Price row a subscription is pinned to. */
30
+ interface OnflaySubscriptionPrice {
31
+ id: string;
32
+ /** Null for tiered or usage-based prices. */
33
+ amountInCents: number | null;
34
+ currency: string;
35
+ interval: 'day' | 'week' | 'month' | 'year' | null;
36
+ intervalCount: number | null;
37
+ }
38
+ /** A subscription as embedded in `subscription.*` events (dates are ISO strings). */
39
+ interface OnflaySubscription {
40
+ id: string;
41
+ object: 'subscription';
42
+ status: SubscriptionStatus;
43
+ customer: OnflayCustomerRef;
44
+ product: OnflayProductRef;
45
+ plan: OnflayPlanRef | null;
46
+ price: OnflaySubscriptionPrice | null;
47
+ currentPeriodStart: string;
48
+ currentPeriodEnd: string;
49
+ /** `status` stays `active` (or `trialing`) until the period ends. */
50
+ cancelAtPeriodEnd: boolean;
51
+ canceledAt: string | null;
52
+ createdAt: string;
53
+ updatedAt: string;
54
+ }
55
+ /**
56
+ * Public webhook event names. These are the values consumers should pin
57
+ * their handlers to. Adding a new value here is a breaking change for
58
+ * receivers that exhaustively `switch` on `event.type` — bump the SDK
59
+ * minor and call it out in the changelog.
60
+ */
61
+ declare const ONFLAY_EVENT_TYPES: readonly ["payment.completed", "payment.refunded", "payout.scheduled", "payout.completed", "payout.failed", "dispute.opened", "dispute.resolved", "subscription.created", "subscription.renewed", "subscription.cancel_scheduled", "subscription.uncanceled", "subscription.canceled", "subscription.updated", "subscription.expired", "subscription.dunning", "invoice.created", "invoice.finalized", "invoice.paid", "invoice.payment_failed", "customer.access_changed", "catalog.product.updated", "catalog.plan.updated", "credits.granted", "license_key.created", "license_key.revoked"];
62
+ type OnflayEventType = (typeof ONFLAY_EVENT_TYPES)[number];
63
+ interface OnflayWebhookEnvelope<TData = unknown> {
64
+ /** Public event ID (`evt_...`). */
65
+ id: string;
66
+ type: OnflayEventType | string;
67
+ /** Unix seconds. */
68
+ createdAt: number;
69
+ /** `false` for sandbox, `true` for production. */
70
+ livemode: boolean;
71
+ /** Schema version of `data`. */
72
+ apiVersion: string;
73
+ data: TData;
74
+ }
75
+ /**
76
+ * Actual runtime shape of `event.data` for `payment.completed` and
77
+ * `payment.refunded` events. Matches the fields emitted by
78
+ * `TransactionCompletedPayload` in `@onflay/contracts`.
79
+ *
80
+ * Note: the `object` field is always `"payment"` and is injected by the
81
+ * webhook dispatch layer.
82
+ */
83
+ interface PaymentEventData {
84
+ object: 'payment';
85
+ transactionId: string;
86
+ creatorId: string;
87
+ customerId: string;
88
+ listingId: string;
89
+ listingType: string;
90
+ /** Pre-fee charged amount in cents. */
91
+ grossAmountInCents: number;
92
+ currency: string;
93
+ /**
94
+ * True when the checkout session was created with a developer-supplied
95
+ * `customPrice` override via the SDK.
96
+ */
97
+ isCustomPrice?: boolean;
98
+ /**
99
+ * Variant list price at the time of checkout. Only present when
100
+ * `isCustomPrice` is true.
101
+ */
102
+ basePriceInCents?: number;
103
+ /** Developer note passed in `customPrice.description`, if any. */
104
+ customPriceDescription?: string;
105
+ }
106
+ interface PaymentRefundedEventData {
107
+ object: 'payment';
108
+ transactionId: string;
109
+ refundId: string;
110
+ creatorId: string;
111
+ amountInCents: number;
112
+ isFullRefund: boolean;
113
+ currency: string;
114
+ }
115
+ interface PayoutEventData {
116
+ payoutId: string;
117
+ creatorId: string;
118
+ amountInCents: number;
119
+ externalTransferId?: string;
120
+ scheduledFor?: string;
121
+ failureReason?: string;
122
+ metadata?: OnflayMetadata;
123
+ }
124
+ interface DisputeEventData {
125
+ disputeId: string;
126
+ transactionId: string;
127
+ externalDisputeId?: string;
128
+ amountInCents: number;
129
+ resolution?: string;
130
+ metadata?: OnflayMetadata;
131
+ }
132
+ /**
133
+ * Enriched payload for cancel / uncancel / plan-change subscription webhooks.
134
+ */
135
+ interface SubscriptionLifecycleEventData {
136
+ object: 'subscription';
137
+ subscriptionId: string;
138
+ creatorId: string;
139
+ customerId: string;
140
+ externalCustomerId?: string;
141
+ status: string;
142
+ cancelAtPeriodEnd: boolean;
143
+ cancelAt?: string | null;
144
+ currentPeriodEnd: string;
145
+ accessUntil: string | null;
146
+ catalogKey?: string;
147
+ planKey?: string;
148
+ interval?: 'month' | 'year' | null;
149
+ previousPlanKey?: string;
150
+ previousInterval?: string | null;
151
+ }
152
+ interface SubscriptionEventData extends OnflaySubscription {
153
+ /** Sub-event detail surfaced by the dispatch listener (e.g. dunning attempt #). */
154
+ detail?: Record<string, unknown>;
155
+ }
156
+ interface InvoiceLineItem {
157
+ description: string;
158
+ amountInCents: number;
159
+ quantity?: number;
160
+ unitAmountInCents?: number;
161
+ }
162
+ interface InvoiceEventData {
163
+ object: 'billing_invoice';
164
+ id: string;
165
+ externalInvoiceId: string | null;
166
+ status: 'open' | 'paid' | 'failed' | 'voided';
167
+ source: 'developer_push' | 'usage_metered';
168
+ currency: string;
169
+ totalInCents: number;
170
+ lineItems: InvoiceLineItem[];
171
+ periodStart: string | null;
172
+ periodEnd: string | null;
173
+ customerId: string;
174
+ subscriptionId: string | null;
175
+ createdAt: string;
176
+ }
177
+ interface CustomerAccessChangedEventData {
178
+ object: 'customer_access_changed';
179
+ externalCustomerId: string;
180
+ accessVersion: number;
181
+ changedSections: readonly string[];
182
+ timestamp: string;
183
+ }
184
+ /**
185
+ * Thin catalog change notification. Re-fetch
186
+ * `GET /v1/catalog/products/{productKey}` for the current state.
187
+ */
188
+ interface CatalogChangedEventData {
189
+ object: 'catalog_changed';
190
+ productKey: string;
191
+ /** Present for `catalog.plan.updated`. */
192
+ planKey?: string;
193
+ change: 'created' | 'updated' | 'deleted';
194
+ source: 'dashboard' | 'api' | 'code';
195
+ timestamp: string;
196
+ }
197
+ /**
198
+ * Thin `credits.granted`: a purchase or a positive adjustment added credits.
199
+ * Re-fetch `GET /v1/credits/{externalCustomerId}` for the current balances.
200
+ */
201
+ interface CreditsGrantedEventData {
202
+ object: 'credits_granted';
203
+ /** Null when the customer was never linked to your app's id. */
204
+ externalCustomerId: string | null;
205
+ key: string;
206
+ amount: number;
207
+ /** Balance right after the grant. */
208
+ balance: number;
209
+ reason: 'purchase' | 'adjustment';
210
+ /** Credit ledger entry id. */
211
+ entryId: string;
212
+ /** Payment that granted the credits (purchases only). */
213
+ paymentId?: string;
214
+ subscriptionId?: string;
215
+ timestamp: string;
216
+ }
217
+ /**
218
+ * Thin `license_key.created` / `license_key.revoked`. Never carries the key itself:
219
+ * fetch it with `GET /v1/license-keys/{licenseKeyId}`.
220
+ */
221
+ interface LicenseKeyChangedEventData {
222
+ object: 'license_key_changed';
223
+ licenseKeyId: string;
224
+ externalCustomerId: string | null;
225
+ productKey: string | null;
226
+ planKey: string | null;
227
+ status: 'active' | 'revoked' | 'expired';
228
+ expiresAt: string | null;
229
+ /** Payment that issued the key. */
230
+ paymentId?: string;
231
+ subscriptionId?: string;
232
+ timestamp: string;
233
+ }
234
+ type OnflayEvent = (OnflayWebhookEnvelope<PaymentEventData> & {
235
+ type: 'payment.completed';
236
+ }) | (OnflayWebhookEnvelope<PaymentRefundedEventData> & {
237
+ type: 'payment.refunded';
238
+ }) | (OnflayWebhookEnvelope<PayoutEventData> & {
239
+ type: 'payout.scheduled' | 'payout.completed' | 'payout.failed';
240
+ }) | (OnflayWebhookEnvelope<DisputeEventData> & {
241
+ type: 'dispute.opened' | 'dispute.resolved';
242
+ }) | (OnflayWebhookEnvelope<SubscriptionEventData> & {
243
+ type: 'subscription.created' | 'subscription.renewed' | 'subscription.expired' | 'subscription.dunning';
244
+ }) | (OnflayWebhookEnvelope<SubscriptionLifecycleEventData> & {
245
+ type: 'subscription.cancel_scheduled' | 'subscription.uncanceled' | 'subscription.canceled' | 'subscription.updated';
246
+ }) | (OnflayWebhookEnvelope<InvoiceEventData> & {
247
+ type: 'invoice.created' | 'invoice.finalized' | 'invoice.paid' | 'invoice.payment_failed';
248
+ }) | (OnflayWebhookEnvelope<CustomerAccessChangedEventData> & {
249
+ type: 'customer.access_changed';
250
+ }) | (OnflayWebhookEnvelope<CatalogChangedEventData> & {
251
+ type: 'catalog.product.updated' | 'catalog.plan.updated';
252
+ }) | (OnflayWebhookEnvelope<CreditsGrantedEventData> & {
253
+ type: 'credits.granted';
254
+ }) | (OnflayWebhookEnvelope<LicenseKeyChangedEventData> & {
255
+ type: 'license_key.created' | 'license_key.revoked';
256
+ });
257
+
258
+ declare const ONFLAY_SIGNATURE_HEADER = "x-onflay-signature";
259
+ declare const STANDARD_WEBHOOK_ID_HEADER = "webhook-id";
260
+ declare const STANDARD_WEBHOOK_TIMESTAMP_HEADER = "webhook-timestamp";
261
+ declare const STANDARD_WEBHOOK_SIGNATURE_HEADER = "webhook-signature";
262
+ declare const DEFAULT_REPLAY_TOLERANCE_SECONDS = 300;
263
+ /**
264
+ * Request headers in any common shape: a Fetch `Headers` instance (Next.js,
265
+ * Hono, Workers) or a plain object such as Node/Express `req.headers`.
266
+ * Plain-object lookups are case-insensitive.
267
+ */
268
+ type WebhookHeaders = {
269
+ get(name: string): string | null;
270
+ } | Record<string, string | string[] | null | undefined>;
271
+ declare class OnflaySignatureError extends Error {
272
+ readonly code: 'missing_signature' | 'malformed_signature' | 'invalid_signature' | 'expired_signature' | 'missing_payload';
273
+ constructor(code: OnflaySignatureError['code'], message: string);
274
+ }
275
+ interface VerifyWebhookOptions {
276
+ /** Per-endpoint signing secret (`whsec_…`). */
277
+ secret: string;
278
+ /**
279
+ * Replay window in seconds. Reject events older than this. Defaults to
280
+ * 300 (5 minutes); set to 0 to disable.
281
+ */
282
+ toleranceSeconds?: number;
283
+ /** Inject a clock for tests. Defaults to `Date.now`. */
284
+ now?: () => Date;
285
+ }
286
+ interface VerifiedWebhook<TEvent = unknown> {
287
+ /** The parsed JSON envelope. */
288
+ event: TEvent;
289
+ /** Raw bytes that were verified (the body field passed in). */
290
+ rawBody: string;
291
+ /** Signature timestamp (unix seconds). */
292
+ timestamp: number;
293
+ /** Which signature scheme verified the request. */
294
+ scheme: 'standard' | 'legacy';
295
+ /** Standard Webhooks message id (`webhook-id`); set when `scheme` is `standard`. */
296
+ webhookId?: string;
297
+ }
298
+ /**
299
+ * Verify an inbound Onflay webhook against the raw request body and a
300
+ * per-endpoint secret. Returns the parsed event envelope on success;
301
+ * throws `OnflaySignatureError` for any verification failure.
302
+ *
303
+ * The second argument is either:
304
+ * - the request headers (`Headers` or a plain object): Standard Webhooks
305
+ * (`webhook-id` / `webhook-timestamp` / `webhook-signature`) is tried
306
+ * first, then the legacy `X-Onflay-Signature` header; or
307
+ * - the `X-Onflay-Signature` header value alone (legacy scheme only, the
308
+ * original signature of this function).
309
+ *
310
+ * IMPORTANT: pass the raw body bytes (string), NOT a re-serialized JSON
311
+ * object. Re-serializing changes whitespace/property order and breaks the
312
+ * HMAC.
313
+ */
314
+ declare function verifyWebhookSignature<TEvent = unknown>(rawBody: string, signatureHeaderOrHeaders: string | string[] | null | undefined | WebhookHeaders, options: VerifyWebhookOptions): VerifiedWebhook<TEvent>;
315
+ /**
316
+ * Verify a Standard Webhooks signature (https://www.standardwebhooks.com):
317
+ * `webhook-signature` holds one or more space-separated `v1,<base64>`
318
+ * entries, each an HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{body}`
319
+ * keyed with the base64 decode of the secret after its `whsec_` prefix.
320
+ * Rejects timestamps more than `toleranceSeconds` (default 300) away from
321
+ * now in either direction.
322
+ */
323
+ declare function verifyStandardWebhook<TEvent = unknown>(rawBody: string, headers: WebhookHeaders, options: VerifyWebhookOptions): VerifiedWebhook<TEvent>;
324
+
325
+ export { type CatalogChangedEventData as C, DEFAULT_REPLAY_TOLERANCE_SECONDS as D, type InvoiceEventData as I, type LicenseKeyChangedEventData as L, type OnflayEvent as O, type PaymentEventData as P, STANDARD_WEBHOOK_ID_HEADER as S, type VerifyWebhookOptions as V, type WebhookHeaders as W, type CreditsGrantedEventData as a, type CustomerAccessChangedEventData as b, type DisputeEventData as c, type InvoiceLineItem as d, ONFLAY_EVENT_TYPES as e, ONFLAY_SIGNATURE_HEADER as f, type OnflayCustomerRef as g, type OnflayEventType as h, type OnflayMetadata as i, type OnflayPlanRef as j, type OnflayProductRef as k, OnflaySignatureError as l, type OnflaySubscription as m, type OnflaySubscriptionPrice as n, type OnflayWebhookEnvelope as o, type PaymentRefundedEventData as p, type PayoutEventData as q, STANDARD_WEBHOOK_SIGNATURE_HEADER as r, STANDARD_WEBHOOK_TIMESTAMP_HEADER as s, type SubscriptionEventData as t, type SubscriptionLifecycleEventData as u, type SubscriptionStatus as v, type VerifiedWebhook as w, verifyStandardWebhook as x, verifyWebhookSignature as y };
@@ -0,0 +1,39 @@
1
+ import { V as VerifyWebhookOptions, O as OnflayEvent, w as VerifiedWebhook, l as OnflaySignatureError } from '../verify-tF2BsJK6.mjs';
2
+
3
+ interface ExpressLikeRequest {
4
+ headers: Record<string, string | string[] | undefined>;
5
+ body: unknown;
6
+ rawBody?: Buffer | string;
7
+ }
8
+ interface ExpressLikeResponse {
9
+ status(code: number): ExpressLikeResponse;
10
+ send(body?: unknown): unknown;
11
+ json(body: unknown): unknown;
12
+ }
13
+ type NextFn = (err?: unknown) => void;
14
+ /**
15
+ * Verify the signature of an inbound Express request whose body has been
16
+ * captured raw. Configure your route with `express.raw({ type: '*' })`
17
+ * (or equivalent) so the request body remains a `Buffer`. Re-parsing
18
+ * after `express.json()` will break the HMAC.
19
+ */
20
+ declare function verifyExpressWebhook<TEvent = OnflayEvent>(req: ExpressLikeRequest, options: VerifyWebhookOptions): VerifiedWebhook<TEvent>;
21
+ interface ExpressHandlerOptions extends VerifyWebhookOptions {
22
+ /** Called after successful verification with the parsed event. */
23
+ onEvent: (event: OnflayEvent, raw: VerifiedWebhook<OnflayEvent>) => unknown | Promise<unknown>;
24
+ /** Optional logger override; defaults to no-op. */
25
+ onError?: (error: OnflaySignatureError | Error) => void;
26
+ }
27
+ /**
28
+ * Higher-level helper that returns a ready-to-mount Express middleware:
29
+ *
30
+ * ```ts
31
+ * app.post('/webhooks/onflay',
32
+ * express.raw({ type: 'application/json' }),
33
+ * createExpressWebhookHandler({ secret, onEvent: async (e) => {} }),
34
+ * );
35
+ * ```
36
+ */
37
+ declare function createExpressWebhookHandler(opts: ExpressHandlerOptions): (req: ExpressLikeRequest, res: ExpressLikeResponse, next?: NextFn) => Promise<void>;
38
+
39
+ export { createExpressWebhookHandler, verifyExpressWebhook };
@@ -0,0 +1,39 @@
1
+ import { V as VerifyWebhookOptions, O as OnflayEvent, w as VerifiedWebhook, l as OnflaySignatureError } from '../verify-tF2BsJK6.js';
2
+
3
+ interface ExpressLikeRequest {
4
+ headers: Record<string, string | string[] | undefined>;
5
+ body: unknown;
6
+ rawBody?: Buffer | string;
7
+ }
8
+ interface ExpressLikeResponse {
9
+ status(code: number): ExpressLikeResponse;
10
+ send(body?: unknown): unknown;
11
+ json(body: unknown): unknown;
12
+ }
13
+ type NextFn = (err?: unknown) => void;
14
+ /**
15
+ * Verify the signature of an inbound Express request whose body has been
16
+ * captured raw. Configure your route with `express.raw({ type: '*' })`
17
+ * (or equivalent) so the request body remains a `Buffer`. Re-parsing
18
+ * after `express.json()` will break the HMAC.
19
+ */
20
+ declare function verifyExpressWebhook<TEvent = OnflayEvent>(req: ExpressLikeRequest, options: VerifyWebhookOptions): VerifiedWebhook<TEvent>;
21
+ interface ExpressHandlerOptions extends VerifyWebhookOptions {
22
+ /** Called after successful verification with the parsed event. */
23
+ onEvent: (event: OnflayEvent, raw: VerifiedWebhook<OnflayEvent>) => unknown | Promise<unknown>;
24
+ /** Optional logger override; defaults to no-op. */
25
+ onError?: (error: OnflaySignatureError | Error) => void;
26
+ }
27
+ /**
28
+ * Higher-level helper that returns a ready-to-mount Express middleware:
29
+ *
30
+ * ```ts
31
+ * app.post('/webhooks/onflay',
32
+ * express.raw({ type: 'application/json' }),
33
+ * createExpressWebhookHandler({ secret, onEvent: async (e) => {} }),
34
+ * );
35
+ * ```
36
+ */
37
+ declare function createExpressWebhookHandler(opts: ExpressHandlerOptions): (req: ExpressLikeRequest, res: ExpressLikeResponse, next?: NextFn) => Promise<void>;
38
+
39
+ export { createExpressWebhookHandler, verifyExpressWebhook };
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkAFAU2FH2js = require('../chunk-AFAU2FH2.js');
5
+ require('../chunk-I2IVHBFA.js');
6
+
7
+
8
+
9
+ exports.createExpressWebhookHandler = _chunkAFAU2FH2js.createExpressWebhookHandler; exports.verifyExpressWebhook = _chunkAFAU2FH2js.verifyExpressWebhook;
10
+ //# sourceMappingURL=express.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/onflay/onflay/sdks/node/dist/webhooks/express.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,yJAAC","file":"/home/runner/work/onflay/onflay/sdks/node/dist/webhooks/express.js"}
@@ -0,0 +1,10 @@
1
+ import {
2
+ createExpressWebhookHandler,
3
+ verifyExpressWebhook
4
+ } from "../chunk-63KSRMJG.mjs";
5
+ import "../chunk-7LYAEZCT.mjs";
6
+ export {
7
+ createExpressWebhookHandler,
8
+ verifyExpressWebhook
9
+ };
10
+ //# sourceMappingURL=express.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,33 @@
1
+ import { V as VerifyWebhookOptions, O as OnflayEvent, w as VerifiedWebhook, l as OnflaySignatureError } from '../verify-tF2BsJK6.mjs';
2
+
3
+ interface HonoLikeContext {
4
+ req: {
5
+ text(): Promise<string>;
6
+ header(name: string): string | undefined;
7
+ };
8
+ json(body: unknown, status?: number): Response;
9
+ text(body: string, status?: number): Response;
10
+ }
11
+ /**
12
+ * Verify the signature of an inbound Hono request. Hono exposes the raw
13
+ * body via `c.req.text()`, which is consumed exactly once.
14
+ *
15
+ * ```ts
16
+ * import { Hono } from 'hono';
17
+ * import { verifyHonoWebhook } from '@onflay/node/webhooks/hono';
18
+ *
19
+ * const app = new Hono();
20
+ * app.post('/webhooks/onflay', async (c) => {
21
+ * const { event } = await verifyHonoWebhook(c, { secret: '...' });
22
+ * return c.text('ok');
23
+ * });
24
+ * ```
25
+ */
26
+ declare function verifyHonoWebhook<TEvent = OnflayEvent>(c: HonoLikeContext, options: VerifyWebhookOptions): Promise<VerifiedWebhook<TEvent>>;
27
+ interface HonoHandlerOptions extends VerifyWebhookOptions {
28
+ onEvent: (event: OnflayEvent, raw: VerifiedWebhook<OnflayEvent>) => unknown | Promise<unknown>;
29
+ onError?: (error: OnflaySignatureError | Error) => void;
30
+ }
31
+ declare function createHonoWebhookHandler(opts: HonoHandlerOptions): (c: HonoLikeContext) => Promise<Response>;
32
+
33
+ export { createHonoWebhookHandler, verifyHonoWebhook };
@@ -0,0 +1,33 @@
1
+ import { V as VerifyWebhookOptions, O as OnflayEvent, w as VerifiedWebhook, l as OnflaySignatureError } from '../verify-tF2BsJK6.js';
2
+
3
+ interface HonoLikeContext {
4
+ req: {
5
+ text(): Promise<string>;
6
+ header(name: string): string | undefined;
7
+ };
8
+ json(body: unknown, status?: number): Response;
9
+ text(body: string, status?: number): Response;
10
+ }
11
+ /**
12
+ * Verify the signature of an inbound Hono request. Hono exposes the raw
13
+ * body via `c.req.text()`, which is consumed exactly once.
14
+ *
15
+ * ```ts
16
+ * import { Hono } from 'hono';
17
+ * import { verifyHonoWebhook } from '@onflay/node/webhooks/hono';
18
+ *
19
+ * const app = new Hono();
20
+ * app.post('/webhooks/onflay', async (c) => {
21
+ * const { event } = await verifyHonoWebhook(c, { secret: '...' });
22
+ * return c.text('ok');
23
+ * });
24
+ * ```
25
+ */
26
+ declare function verifyHonoWebhook<TEvent = OnflayEvent>(c: HonoLikeContext, options: VerifyWebhookOptions): Promise<VerifiedWebhook<TEvent>>;
27
+ interface HonoHandlerOptions extends VerifyWebhookOptions {
28
+ onEvent: (event: OnflayEvent, raw: VerifiedWebhook<OnflayEvent>) => unknown | Promise<unknown>;
29
+ onError?: (error: OnflaySignatureError | Error) => void;
30
+ }
31
+ declare function createHonoWebhookHandler(opts: HonoHandlerOptions): (c: HonoLikeContext) => Promise<Response>;
32
+
33
+ export { createHonoWebhookHandler, verifyHonoWebhook };
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkW6AEPYUGjs = require('../chunk-W6AEPYUG.js');
5
+ require('../chunk-I2IVHBFA.js');
6
+
7
+
8
+
9
+ exports.createHonoWebhookHandler = _chunkW6AEPYUGjs.createHonoWebhookHandler; exports.verifyHonoWebhook = _chunkW6AEPYUGjs.verifyHonoWebhook;
10
+ //# sourceMappingURL=hono.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/onflay/onflay/sdks/node/dist/webhooks/hono.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,6IAAC","file":"/home/runner/work/onflay/onflay/sdks/node/dist/webhooks/hono.js"}
@@ -0,0 +1,10 @@
1
+ import {
2
+ createHonoWebhookHandler,
3
+ verifyHonoWebhook
4
+ } from "../chunk-J4MYKTPN.mjs";
5
+ import "../chunk-7LYAEZCT.mjs";
6
+ export {
7
+ createHonoWebhookHandler,
8
+ verifyHonoWebhook
9
+ };
10
+ //# sourceMappingURL=hono.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,34 @@
1
+ import { O as OnflayEvent, W as WebhookHeaders, V as VerifyWebhookOptions } from '../verify-tF2BsJK6.mjs';
2
+ export { C as CatalogChangedEventData, a as CreditsGrantedEventData, b as CustomerAccessChangedEventData, D as DEFAULT_REPLAY_TOLERANCE_SECONDS, c as DisputeEventData, I as InvoiceEventData, d as InvoiceLineItem, L as LicenseKeyChangedEventData, e as ONFLAY_EVENT_TYPES, f as ONFLAY_SIGNATURE_HEADER, g as OnflayCustomerRef, h as OnflayEventType, i as OnflayMetadata, j as OnflayPlanRef, k as OnflayProductRef, l as OnflaySignatureError, m as OnflaySubscription, n as OnflaySubscriptionPrice, o as OnflayWebhookEnvelope, P as PaymentEventData, p as PaymentRefundedEventData, q as PayoutEventData, S as STANDARD_WEBHOOK_ID_HEADER, r as STANDARD_WEBHOOK_SIGNATURE_HEADER, s as STANDARD_WEBHOOK_TIMESTAMP_HEADER, t as SubscriptionEventData, u as SubscriptionLifecycleEventData, v as SubscriptionStatus, w as VerifiedWebhook, x as verifyStandardWebhook, y as verifyWebhookSignature } from '../verify-tF2BsJK6.mjs';
3
+ export { createExpressWebhookHandler, verifyExpressWebhook } from './express.mjs';
4
+ export { createNextWebhookHandler, verifyNextWebhook } from './next.mjs';
5
+ export { createHonoWebhookHandler, verifyHonoWebhook } from './hono.mjs';
6
+
7
+ /**
8
+ * Webhook signature verification, framework adapters and event types
9
+ * (Standard Webhooks, with the legacy `X-Onflay-Signature` fallback).
10
+ *
11
+ * ```ts
12
+ * import { unwrap } from '@onflay/node/webhooks';
13
+ *
14
+ * export async function POST(req: Request) {
15
+ * const event = unwrap(await req.text(), req.headers, { secret: process.env.ONFLAY_WEBHOOK_SECRET! });
16
+ * if (event.type === 'customer.access_changed') {
17
+ * // refresh the customer's access
18
+ * }
19
+ * return new Response('ok');
20
+ * }
21
+ * ```
22
+ *
23
+ * Framework handlers also have their own entry points: `@onflay/node/webhooks/next`,
24
+ * `@onflay/node/webhooks/express` and `@onflay/node/webhooks/hono`.
25
+ */
26
+
27
+ /**
28
+ * Verifies a webhook delivery and returns its event. Throws `OnflaySignatureError` when the
29
+ * signature is missing, invalid or outside the replay window. `rawBody` must be the exact
30
+ * request body (do not re-serialize parsed JSON).
31
+ */
32
+ declare function unwrap<TEvent = OnflayEvent>(rawBody: string, headers: WebhookHeaders, options: VerifyWebhookOptions): TEvent;
33
+
34
+ export { OnflayEvent, VerifyWebhookOptions, WebhookHeaders, unwrap };
@@ -0,0 +1,34 @@
1
+ import { O as OnflayEvent, W as WebhookHeaders, V as VerifyWebhookOptions } from '../verify-tF2BsJK6.js';
2
+ export { C as CatalogChangedEventData, a as CreditsGrantedEventData, b as CustomerAccessChangedEventData, D as DEFAULT_REPLAY_TOLERANCE_SECONDS, c as DisputeEventData, I as InvoiceEventData, d as InvoiceLineItem, L as LicenseKeyChangedEventData, e as ONFLAY_EVENT_TYPES, f as ONFLAY_SIGNATURE_HEADER, g as OnflayCustomerRef, h as OnflayEventType, i as OnflayMetadata, j as OnflayPlanRef, k as OnflayProductRef, l as OnflaySignatureError, m as OnflaySubscription, n as OnflaySubscriptionPrice, o as OnflayWebhookEnvelope, P as PaymentEventData, p as PaymentRefundedEventData, q as PayoutEventData, S as STANDARD_WEBHOOK_ID_HEADER, r as STANDARD_WEBHOOK_SIGNATURE_HEADER, s as STANDARD_WEBHOOK_TIMESTAMP_HEADER, t as SubscriptionEventData, u as SubscriptionLifecycleEventData, v as SubscriptionStatus, w as VerifiedWebhook, x as verifyStandardWebhook, y as verifyWebhookSignature } from '../verify-tF2BsJK6.js';
3
+ export { createExpressWebhookHandler, verifyExpressWebhook } from './express.js';
4
+ export { createNextWebhookHandler, verifyNextWebhook } from './next.js';
5
+ export { createHonoWebhookHandler, verifyHonoWebhook } from './hono.js';
6
+
7
+ /**
8
+ * Webhook signature verification, framework adapters and event types
9
+ * (Standard Webhooks, with the legacy `X-Onflay-Signature` fallback).
10
+ *
11
+ * ```ts
12
+ * import { unwrap } from '@onflay/node/webhooks';
13
+ *
14
+ * export async function POST(req: Request) {
15
+ * const event = unwrap(await req.text(), req.headers, { secret: process.env.ONFLAY_WEBHOOK_SECRET! });
16
+ * if (event.type === 'customer.access_changed') {
17
+ * // refresh the customer's access
18
+ * }
19
+ * return new Response('ok');
20
+ * }
21
+ * ```
22
+ *
23
+ * Framework handlers also have their own entry points: `@onflay/node/webhooks/next`,
24
+ * `@onflay/node/webhooks/express` and `@onflay/node/webhooks/hono`.
25
+ */
26
+
27
+ /**
28
+ * Verifies a webhook delivery and returns its event. Throws `OnflaySignatureError` when the
29
+ * signature is missing, invalid or outside the replay window. `rawBody` must be the exact
30
+ * request body (do not re-serialize parsed JSON).
31
+ */
32
+ declare function unwrap<TEvent = OnflayEvent>(rawBody: string, headers: WebhookHeaders, options: VerifyWebhookOptions): TEvent;
33
+
34
+ export { OnflayEvent, VerifyWebhookOptions, WebhookHeaders, unwrap };