better-auth-streampay 1.2.1 → 2.0.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.
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as StreamPayClient } from './streampay-DMlTwJUB.cjs';
2
- export { $ as $ERROR_CODES, A as AdminOptions, b as AuthorizeReferenceContext, C as CheckoutBody, c as CheckoutOptions, d as CheckoutParams, e as ClaimExistingConsumerBy, f as ClaimExistingConsumerIdentifier, g as ConsumerCreateOverrides, F as FeatureKey, L as LimitCheckResult, P as PLAN_NAME_METADATA_KEY, h as PluginAdapter, i as PortalOptions, R as REFERENCE_ID_METADATA_KEY, j as ResolvedPlans, k as STREAMPAY_EVENT_TYPES, l as STREAMPAY_INVOICE_EVENT_TYPES, m as STREAMPAY_PAYMENT_EVENT_TYPES, n as STREAMPAY_PAYMENT_LINK_EVENT_TYPES, o as STREAMPAY_SUBSCRIPTION_EVENT_TYPES, p as StreamPayEndpoints, q as StreamPayEntityType, S as StreamPayErrorCode, r as StreamPayEventType, t as StreamPayHookContext, u as StreamPayInvoiceEventType, v as StreamPayOptions, w as StreamPayPaymentEventType, x as StreamPayPaymentLinkEventType, y as StreamPayPlan, z as StreamPayPlanLike, B as StreamPayPlugin, D as StreamPayPluginRegistry, G as StreamPayPlugins, H as StreamPayProduct, I as StreamPaySubscriptionEventType, J as StreamPayWebhookData, K as StreamPayWebhookPayload, M as Subscription, N as SubscriptionCallback, O as SubscriptionCallbackData, Q as SubscriptionCallbacks, T as SubscriptionStatus, U as SubscriptionsOptions, V as SyncContext, W as WebhookHandler, X as WebhookHandlers, Y as WebhookSyncFailure, Z as WebhooksOptions, _ as admin, a0 as checkLimit, a1 as checkout, a2 as classifyWebhookFailure, a3 as dispatchWebhook, a4 as hasFeature, a5 as mapToErrorCode, a6 as portal, s as streampay, a7 as subscriptions, a8 as syncWebhookPayload, a9 as webhooks } from './streampay-DMlTwJUB.cjs';
1
+ import { a as StreamPayClient } from './streampay-CYAHE6Qj.cjs';
2
+ export { $ as $ERROR_CODES, A as AdminOptions, b as AuthorizeReferenceContext, C as CheckoutBody, c as CheckoutOptions, d as CheckoutParams, e as ClaimExistingConsumerBy, f as ClaimExistingConsumerIdentifier, g as ConsumerCreateOverrides, D as DEFAULT_ACCESS_STATUSES, F as FeatureKey, L as LimitCheckResult, P as PLAN_NAME_METADATA_KEY, h as PluginAdapter, i as PortalOptions, R as REFERENCE_ID_METADATA_KEY, j as REFERENCE_TYPE_METADATA_KEY, k as ResolvedPlans, l as STREAMPAY_EVENT_TYPES, m as STREAMPAY_INVOICE_EVENT_TYPES, n as STREAMPAY_PAYMENT_EVENT_TYPES, o as STREAMPAY_PAYMENT_LINK_EVENT_TYPES, p as STREAMPAY_SUBSCRIPTION_EVENT_TYPES, q as SUBSCRIPTION_ROW_ID_METADATA_KEY, r as StreamPayCustomFieldDefinition, t as StreamPayCustomFieldsSchema, u as StreamPayEndpoints, v as StreamPayEntityType, S as StreamPayErrorCode, w as StreamPayEventType, x as StreamPayHookContext, y as StreamPayInvoiceEventType, z as StreamPayOptions, B as StreamPayPaymentEventType, G as StreamPayPaymentLinkEventType, H as StreamPayPlan, I as StreamPayPlanLike, J as StreamPayPlugin, K as StreamPayPluginRegistry, M as StreamPayPlugins, N as StreamPayProduct, O as StreamPaySubscriptionEventType, Q as StreamPayWebhookData, T as StreamPayWebhookEnvelope, U as StreamPayWebhookPayload, V as Subscription, W as SubscriptionBillingStatus, X as SubscriptionCallback, Y as SubscriptionCallbackData, Z as SubscriptionCallbacks, _ as SubscriptionReferenceType, a0 as SubscriptionStatus, a1 as SubscriptionsOptions, a2 as SyncContext, a3 as TrialEligibilityContext, a4 as WebhookEnvelopeHandler, a5 as WebhookHandler, a6 as WebhookHandlers, a7 as WebhookSyncFailure, a8 as WebhooksOptions, a9 as admin, aa as checkLimit, ab as checkout, ac as classifyWebhookFailure, ad as dispatchWebhook, ae as hasFeature, af as hasSubscriptionAccess, ag as isKnownStreamPayWebhookPayload, ah as isStreamPayWebhookEnvelope, ai as mapToErrorCode, aj as portal, s as streampay, ak as subscriptionSlotKey, al as subscriptions, am as syncWebhookPayload, an as webhooks } from './streampay-CYAHE6Qj.cjs';
3
3
  import { InvoiceDetailed, PaymentResponse, ConsumerResponse } from '@streamsdk/typescript';
4
4
  import 'better-auth';
5
- import 'zod/v4/core';
6
5
  import 'zod';
6
+ import 'zod/v4/core';
7
7
 
8
8
  declare const subscriptionSchema: {
9
9
  readonly streampayWebhookEvent: {
@@ -17,18 +17,44 @@ declare const subscriptionSchema: {
17
17
  readonly type: "string";
18
18
  readonly required: true;
19
19
  };
20
- /** Last activity (insert/retry/completion/dead-letter).
21
- * For `completed` = finished-at; for `pending` = last attempt. */
22
- readonly processedAt: {
20
+ readonly receivedAt: {
23
21
  readonly type: "date";
24
22
  readonly required: true;
25
23
  readonly index: true;
26
24
  };
27
- /** Defaults to `completed` so pre-state-machine rows still dedupe. */
25
+ readonly lastAttemptAt: {
26
+ readonly type: "date";
27
+ readonly required: false;
28
+ readonly index: true;
29
+ };
30
+ readonly nextAttemptAt: {
31
+ readonly type: "date";
32
+ readonly required: false;
33
+ readonly index: true;
34
+ };
35
+ readonly completedAt: {
36
+ readonly type: "date";
37
+ readonly required: false;
38
+ readonly index: true;
39
+ };
40
+ readonly deadLetteredAt: {
41
+ readonly type: "date";
42
+ readonly required: false;
43
+ readonly index: true;
44
+ };
45
+ readonly lockedAt: {
46
+ readonly type: "date";
47
+ readonly required: false;
48
+ readonly index: true;
49
+ };
50
+ readonly lockedBy: {
51
+ readonly type: "string";
52
+ readonly required: false;
53
+ };
28
54
  readonly status: {
29
55
  readonly type: "string";
30
56
  readonly required: false;
31
- readonly defaultValue: "completed";
57
+ readonly defaultValue: "pending";
32
58
  readonly index: true;
33
59
  };
34
60
  readonly attemptCount: {
@@ -36,10 +62,6 @@ declare const subscriptionSchema: {
36
62
  readonly required: false;
37
63
  readonly defaultValue: 1;
38
64
  };
39
- readonly firstSeenAt: {
40
- readonly type: "date";
41
- readonly required: false;
42
- };
43
65
  readonly rawPayload: {
44
66
  readonly type: "string";
45
67
  readonly required: false;
@@ -52,6 +74,11 @@ declare const subscriptionSchema: {
52
74
  readonly type: "string";
53
75
  readonly required: false;
54
76
  };
77
+ readonly lastErrorCode: {
78
+ readonly type: "string";
79
+ readonly required: false;
80
+ readonly index: true;
81
+ };
55
82
  };
56
83
  };
57
84
  readonly subscription: {
@@ -60,6 +87,19 @@ declare const subscriptionSchema: {
60
87
  readonly type: "string";
61
88
  readonly required: true;
62
89
  readonly input: false;
90
+ readonly index: true;
91
+ };
92
+ readonly referenceType: {
93
+ readonly type: "string";
94
+ readonly required: false;
95
+ readonly defaultValue: "user";
96
+ readonly input: false;
97
+ };
98
+ readonly activeSlotKey: {
99
+ readonly type: "string";
100
+ readonly required: false;
101
+ readonly unique: true;
102
+ readonly input: false;
63
103
  };
64
104
  readonly streampaySubscriptionId: {
65
105
  readonly type: "string";
@@ -71,16 +111,37 @@ declare const subscriptionSchema: {
71
111
  readonly type: "string";
72
112
  readonly required: false;
73
113
  readonly input: false;
114
+ readonly index: true;
115
+ };
116
+ readonly streampayPaymentLinkId: {
117
+ readonly type: "string";
118
+ readonly required: false;
119
+ readonly unique: true;
120
+ readonly input: false;
74
121
  };
75
122
  readonly plan: {
76
123
  readonly type: "string";
77
124
  readonly required: true;
78
125
  };
126
+ readonly planVersion: {
127
+ readonly type: "string";
128
+ readonly required: false;
129
+ };
130
+ readonly productId: {
131
+ readonly type: "string";
132
+ readonly required: false;
133
+ readonly index: true;
134
+ };
79
135
  readonly group: {
80
136
  readonly type: "string";
81
137
  readonly required: false;
138
+ readonly index: true;
82
139
  };
83
- readonly amountHalalat: {
140
+ readonly amountInSmallestUnit: {
141
+ readonly type: "number";
142
+ readonly required: false;
143
+ };
144
+ readonly originalAmountInSmallestUnit: {
84
145
  readonly type: "number";
85
146
  readonly required: false;
86
147
  };
@@ -102,6 +163,17 @@ declare const subscriptionSchema: {
102
163
  readonly type: "string";
103
164
  readonly required: false;
104
165
  readonly defaultValue: "incomplete";
166
+ readonly index: true;
167
+ };
168
+ readonly providerStatus: {
169
+ readonly type: "string";
170
+ readonly required: false;
171
+ };
172
+ readonly billingStatus: {
173
+ readonly type: "string";
174
+ readonly required: false;
175
+ readonly defaultValue: "current";
176
+ readonly index: true;
105
177
  };
106
178
  readonly periodStart: {
107
179
  readonly type: "date";
@@ -111,11 +183,48 @@ declare const subscriptionSchema: {
111
183
  readonly type: "date";
112
184
  readonly required: false;
113
185
  };
186
+ readonly currentCycleNumber: {
187
+ readonly type: "number";
188
+ readonly required: false;
189
+ };
190
+ readonly trialStart: {
191
+ readonly type: "date";
192
+ readonly required: false;
193
+ };
194
+ readonly trialEnd: {
195
+ readonly type: "date";
196
+ readonly required: false;
197
+ };
114
198
  readonly cancelAtPeriodEnd: {
115
199
  readonly type: "boolean";
116
200
  readonly required: false;
117
201
  readonly defaultValue: false;
118
202
  };
203
+ readonly cancelAt: {
204
+ readonly type: "date";
205
+ readonly required: false;
206
+ };
207
+ readonly cancelScheduledAt: {
208
+ readonly type: "date";
209
+ readonly required: false;
210
+ };
211
+ readonly canceledAt: {
212
+ readonly type: "date";
213
+ readonly required: false;
214
+ };
215
+ readonly pendingPlan: {
216
+ readonly type: "string";
217
+ readonly required: false;
218
+ };
219
+ readonly pendingProductId: {
220
+ readonly type: "string";
221
+ readonly required: false;
222
+ readonly index: true;
223
+ };
224
+ readonly pendingPlanEffectiveAt: {
225
+ readonly type: "date";
226
+ readonly required: false;
227
+ };
119
228
  readonly endedAt: {
120
229
  readonly type: "date";
121
230
  readonly required: false;
@@ -128,33 +237,37 @@ declare const subscriptionSchema: {
128
237
  readonly type: "date";
129
238
  readonly required: false;
130
239
  };
240
+ readonly providerUpdatedAt: {
241
+ readonly type: "date";
242
+ readonly required: false;
243
+ };
244
+ readonly syncedAt: {
245
+ readonly type: "date";
246
+ readonly required: false;
247
+ readonly index: true;
248
+ };
249
+ readonly createdAt: {
250
+ readonly type: "date";
251
+ readonly required: false;
252
+ readonly input: false;
253
+ };
254
+ readonly updatedAt: {
255
+ readonly type: "date";
256
+ readonly required: false;
257
+ readonly input: false;
258
+ readonly index: true;
259
+ };
131
260
  };
132
261
  };
133
262
  };
134
263
  type SubscriptionSchema = typeof subscriptionSchema;
135
264
 
136
- /**
137
- * Re-exports of the string-literal enums the StreamPay SDK uses
138
- * internally. The SDK does not surface these as top-level names, so
139
- * we derive them from exported shapes where possible. This keeps them
140
- * tied to the SDK's `components["schemas"]` graph — when the upstream
141
- * enum widens or tightens, our types track automatically.
142
- *
143
- * `Language` is the one exception: `ConsumerCreate.preferred_language`
144
- * is typed as plain `string` on the exported `ConsumerCreate`, so we
145
- * mirror the internal `Language` schema by hand.
146
- */
147
265
  type StreamPayPaymentStatus = NonNullable<PaymentResponse["current_status"]>;
148
266
  type InvoiceStatus = NonNullable<InvoiceDetailed["status"]>;
149
267
  type PaymentMethod = NonNullable<PaymentResponse["payment_method"]>;
150
268
  type RefundReason = NonNullable<PaymentResponse["refund_reason"]>;
151
269
  type Language = "AR" | "EN";
152
270
 
153
- /**
154
- * StreamPay represents money as decimal SAR strings (`"10.50"`). We
155
- * convert to integer halalat (1 SAR = 100 halalat) at this boundary so
156
- * the rest of the code is drift-free.
157
- */
158
271
  declare const StreamPayAmount: {
159
272
  readonly toHalalat: (sar: string | number) => number;
160
273
  readonly toSAR: (halalat: number) => string;
@@ -170,84 +283,30 @@ interface ConsumerIdentifiers {
170
283
  external_id?: string | null;
171
284
  iban?: string | null;
172
285
  }
173
- /**
174
- * Exact match on ANY supplied identifier — one `search_term` query per
175
- * populated identifier, stops at first hit. Returns the full consumer
176
- * so callers can inspect `external_id` for the stranded vs. linked
177
- * decision.
178
- */
179
286
  declare function findConsumerByIdentifiers(client: StreamPayClient, identifiers: ConsumerIdentifiers): Promise<ConsumerResponse | null>;
180
287
 
181
- /**
182
- * Unwraps the useful detail out of a `@streamsdk/typescript` error.
183
- *
184
- * The SDK throws `StreamSDKError` (a subclass of `Error`) whose `.message`
185
- * is always the opaque shape `HTTP <status> calling <method> <path>`. The
186
- * actual StreamPay API response — including `additional_info` and FastAPI
187
- * validation details — lives on `.body`. This helper surfaces the best
188
- * available message so developers see *why* an upstream call failed, not
189
- * just that it did.
190
- *
191
- * Shapes handled:
192
- * 1. `{ error: { additional_info: "..." } }` — branded envelope, preferred.
193
- * 2. `{ error: { message: "..." } }` — same envelope, fallback.
194
- * 3. `{ detail: [{ loc, msg }] }` — FastAPI 422 validation errors.
195
- * 4. Anything else — `JSON.stringify(body)` if object, else `err.message`.
196
- * 5. Non-Error throwables — `String(err)`.
197
- */
198
288
  declare function formatStreamPayError(err: unknown): string;
199
289
 
200
- /**
201
- * Structural parser for errors thrown by the StreamPay SDK (or any
202
- * HTTP client that follows the same envelope). Returns a narrow,
203
- * serializable shape so callers can branch on `code`, log `requestId`,
204
- * and render `validationErrors` without pattern-matching on `unknown`.
205
- *
206
- * Parsing delegates to zod schemas in `error-envelope.ts` so every
207
- * caller (parse, format, classify) sees the same shape.
208
- */
209
- /**
210
- * One entry of FastAPI/Pydantic's 422 validation detail array.
211
- * `loc` is the field path (`["body", "email"]`), `msg` is a human
212
- * string, `type` is Pydantic's machine type.
213
- */
214
290
  interface StreamPayValidationIssue {
215
291
  loc: (string | number)[];
216
292
  message: string;
217
293
  type: string;
218
294
  }
219
295
  interface ParsedStreamPayError {
220
- /** HTTP status from the response, or `undefined` if the error was thrown before a response arrived. */
221
296
  status: number | undefined;
222
- /** StreamPay's stable error code (e.g. `"DUPLICATE_CONSUMER"`), or `undefined` for 422 / network errors. */
223
297
  code: string | undefined;
224
- /** Value of the `x-request-id` response header if the SDK captured it. Forward this to support tickets. */
225
298
  requestId: string | undefined;
226
- /** Human-readable message from the error envelope, falling back to `err.message`. */
227
299
  message: string;
228
- /** The `additional_info` field from StreamPay's envelope — optional debug detail. */
229
300
  additionalInfo: string | undefined;
230
- /** 422 validation issues. Empty array when the error is not a validation error. */
231
301
  validationErrors: StreamPayValidationIssue[];
232
302
  }
233
303
  declare function parseStreamPayError(err: unknown): ParsedStreamPayError;
234
304
 
235
- /**
236
- * StreamPay signs webhooks via `X-Webhook-Signature: t=<unix>,v1=<hex>`
237
- * where the hex is `HMAC_SHA256(secret, "${t}.${rawBody}")`.
238
- * https://docs.streampay.sa/webhooks#verifying-webhook-authenticity
239
- */
240
305
  interface VerifyWebhookInput {
241
- /**
242
- * Shared secret — or array of secrets for rolling rotation (signature
243
- * passes if ANY matches). Empty array rejects everything.
244
- */
245
306
  secret: string | readonly string[];
246
307
  rawBody: string;
247
308
  signatureHeader: string | null | undefined;
248
- /** Max signature age (seconds). Defaults to 300s (5 min). */
249
309
  toleranceSeconds?: number;
250
- /** Clock hook for tests. */
251
310
  now?: () => number;
252
311
  }
253
312
  type VerifyWebhookResult = {