better-auth-streampay 1.2.0 → 1.3.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,5 +1,5 @@
1
- import { a as StreamPayClient } from './streampay-DWXCWh1U.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, 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, F as StreamPayPlugins, G as StreamPayProduct, H as StreamPaySubscriptionEventType, I as StreamPayWebhookData, J as StreamPayWebhookPayload, K as Subscription, M as SubscriptionCallback, N as SubscriptionCallbackData, O as SubscriptionCallbacks, Q as SubscriptionStatus, T as SubscriptionsOptions, U as SyncContext, W as WebhookHandler, V as WebhookHandlers, X as WebhookSyncFailure, Y as WebhooksOptions, Z as admin, _ as checkLimit, a0 as checkout, a1 as classifyWebhookFailure, a2 as dispatchWebhook, a3 as hasFeature, a4 as mapToErrorCode, a5 as portal, s as streampay, a6 as subscriptions, a7 as syncWebhookPayload, a8 as webhooks } from './streampay-DWXCWh1U.cjs';
1
+ import { a as StreamPayClient } from './streampay-1mamzabs.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-1mamzabs.cjs';
3
3
  import { InvoiceDetailed, PaymentResponse, ConsumerResponse } from '@streamsdk/typescript';
4
4
  import 'better-auth';
5
5
  import 'zod/v4/core';
@@ -17,14 +17,11 @@ 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
20
  readonly processedAt: {
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. */
28
25
  readonly status: {
29
26
  readonly type: "string";
30
27
  readonly required: false;
@@ -133,28 +130,13 @@ declare const subscriptionSchema: {
133
130
  };
134
131
  type SubscriptionSchema = typeof subscriptionSchema;
135
132
 
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
133
  type StreamPayPaymentStatus = NonNullable<PaymentResponse["current_status"]>;
148
134
  type InvoiceStatus = NonNullable<InvoiceDetailed["status"]>;
149
135
  type PaymentMethod = NonNullable<PaymentResponse["payment_method"]>;
150
136
  type RefundReason = NonNullable<PaymentResponse["refund_reason"]>;
151
137
  type Language = "AR" | "EN";
152
138
 
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
- */
139
+ /** Convert between decimal-SAR strings/numbers and integer halalat (1 SAR = 100 halalat). */
158
140
  declare const StreamPayAmount: {
159
141
  readonly toHalalat: (sar: string | number) => number;
160
142
  readonly toSAR: (halalat: number) => string;
@@ -170,84 +152,30 @@ interface ConsumerIdentifiers {
170
152
  external_id?: string | null;
171
153
  iban?: string | null;
172
154
  }
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
155
  declare function findConsumerByIdentifiers(client: StreamPayClient, identifiers: ConsumerIdentifiers): Promise<ConsumerResponse | null>;
180
156
 
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
157
  declare function formatStreamPayError(err: unknown): string;
199
158
 
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
159
  interface StreamPayValidationIssue {
215
160
  loc: (string | number)[];
216
161
  message: string;
217
162
  type: string;
218
163
  }
219
164
  interface ParsedStreamPayError {
220
- /** HTTP status from the response, or `undefined` if the error was thrown before a response arrived. */
221
165
  status: number | undefined;
222
- /** StreamPay's stable error code (e.g. `"DUPLICATE_CONSUMER"`), or `undefined` for 422 / network errors. */
223
166
  code: string | undefined;
224
- /** Value of the `x-request-id` response header if the SDK captured it. Forward this to support tickets. */
225
167
  requestId: string | undefined;
226
- /** Human-readable message from the error envelope, falling back to `err.message`. */
227
168
  message: string;
228
- /** The `additional_info` field from StreamPay's envelope — optional debug detail. */
229
169
  additionalInfo: string | undefined;
230
- /** 422 validation issues. Empty array when the error is not a validation error. */
231
170
  validationErrors: StreamPayValidationIssue[];
232
171
  }
233
172
  declare function parseStreamPayError(err: unknown): ParsedStreamPayError;
234
173
 
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
174
  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
175
  secret: string | readonly string[];
246
176
  rawBody: string;
247
177
  signatureHeader: string | null | undefined;
248
- /** Max signature age (seconds). Defaults to 300s (5 min). */
249
178
  toleranceSeconds?: number;
250
- /** Clock hook for tests. */
251
179
  now?: () => number;
252
180
  }
253
181
  type VerifyWebhookResult = {
@@ -262,7 +190,9 @@ declare class StreamPayWebhookError extends Error {
262
190
  readonly reason: VerifyFailureReason;
263
191
  constructor(reason: VerifyFailureReason, message?: string);
264
192
  }
193
+ /** Verify a StreamPay webhook signature against the raw body. Returns a result object; never throws. */
265
194
  declare function verifyWebhook(input: VerifyWebhookInput): VerifyWebhookResult;
195
+ /** Like `verifyWebhook` but throws `StreamPayWebhookError` on failure; returns the signed timestamp on success. */
266
196
  declare function verifyWebhookOrThrow(input: VerifyWebhookInput): number;
267
197
 
268
198
  export { type ConsumerIdentifiers, type InvoiceStatus, type Language, type ParsedStreamPayError, type PaymentMethod, type RefundReason, StreamPayAmount, type StreamPayPaymentStatus, type StreamPayValidationIssue, StreamPayWebhookError, type SubscriptionSchema, type VerifyFailureReason, type VerifyWebhookInput, type VerifyWebhookResult, findConsumerByExternalId, findConsumerByIdentifiers, formatStreamPayError, parseStreamPayError, subscriptionSchema, verifyWebhook, verifyWebhookOrThrow };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as StreamPayClient } from './streampay-DWXCWh1U.js';
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, 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, F as StreamPayPlugins, G as StreamPayProduct, H as StreamPaySubscriptionEventType, I as StreamPayWebhookData, J as StreamPayWebhookPayload, K as Subscription, M as SubscriptionCallback, N as SubscriptionCallbackData, O as SubscriptionCallbacks, Q as SubscriptionStatus, T as SubscriptionsOptions, U as SyncContext, W as WebhookHandler, V as WebhookHandlers, X as WebhookSyncFailure, Y as WebhooksOptions, Z as admin, _ as checkLimit, a0 as checkout, a1 as classifyWebhookFailure, a2 as dispatchWebhook, a3 as hasFeature, a4 as mapToErrorCode, a5 as portal, s as streampay, a6 as subscriptions, a7 as syncWebhookPayload, a8 as webhooks } from './streampay-DWXCWh1U.js';
1
+ import { a as StreamPayClient } from './streampay-1mamzabs.js';
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-1mamzabs.js';
3
3
  import { InvoiceDetailed, PaymentResponse, ConsumerResponse } from '@streamsdk/typescript';
4
4
  import 'better-auth';
5
5
  import 'zod/v4/core';
@@ -17,14 +17,11 @@ 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
20
  readonly processedAt: {
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. */
28
25
  readonly status: {
29
26
  readonly type: "string";
30
27
  readonly required: false;
@@ -133,28 +130,13 @@ declare const subscriptionSchema: {
133
130
  };
134
131
  type SubscriptionSchema = typeof subscriptionSchema;
135
132
 
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
133
  type StreamPayPaymentStatus = NonNullable<PaymentResponse["current_status"]>;
148
134
  type InvoiceStatus = NonNullable<InvoiceDetailed["status"]>;
149
135
  type PaymentMethod = NonNullable<PaymentResponse["payment_method"]>;
150
136
  type RefundReason = NonNullable<PaymentResponse["refund_reason"]>;
151
137
  type Language = "AR" | "EN";
152
138
 
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
- */
139
+ /** Convert between decimal-SAR strings/numbers and integer halalat (1 SAR = 100 halalat). */
158
140
  declare const StreamPayAmount: {
159
141
  readonly toHalalat: (sar: string | number) => number;
160
142
  readonly toSAR: (halalat: number) => string;
@@ -170,84 +152,30 @@ interface ConsumerIdentifiers {
170
152
  external_id?: string | null;
171
153
  iban?: string | null;
172
154
  }
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
155
  declare function findConsumerByIdentifiers(client: StreamPayClient, identifiers: ConsumerIdentifiers): Promise<ConsumerResponse | null>;
180
156
 
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
157
  declare function formatStreamPayError(err: unknown): string;
199
158
 
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
159
  interface StreamPayValidationIssue {
215
160
  loc: (string | number)[];
216
161
  message: string;
217
162
  type: string;
218
163
  }
219
164
  interface ParsedStreamPayError {
220
- /** HTTP status from the response, or `undefined` if the error was thrown before a response arrived. */
221
165
  status: number | undefined;
222
- /** StreamPay's stable error code (e.g. `"DUPLICATE_CONSUMER"`), or `undefined` for 422 / network errors. */
223
166
  code: string | undefined;
224
- /** Value of the `x-request-id` response header if the SDK captured it. Forward this to support tickets. */
225
167
  requestId: string | undefined;
226
- /** Human-readable message from the error envelope, falling back to `err.message`. */
227
168
  message: string;
228
- /** The `additional_info` field from StreamPay's envelope — optional debug detail. */
229
169
  additionalInfo: string | undefined;
230
- /** 422 validation issues. Empty array when the error is not a validation error. */
231
170
  validationErrors: StreamPayValidationIssue[];
232
171
  }
233
172
  declare function parseStreamPayError(err: unknown): ParsedStreamPayError;
234
173
 
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
174
  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
175
  secret: string | readonly string[];
246
176
  rawBody: string;
247
177
  signatureHeader: string | null | undefined;
248
- /** Max signature age (seconds). Defaults to 300s (5 min). */
249
178
  toleranceSeconds?: number;
250
- /** Clock hook for tests. */
251
179
  now?: () => number;
252
180
  }
253
181
  type VerifyWebhookResult = {
@@ -262,7 +190,9 @@ declare class StreamPayWebhookError extends Error {
262
190
  readonly reason: VerifyFailureReason;
263
191
  constructor(reason: VerifyFailureReason, message?: string);
264
192
  }
193
+ /** Verify a StreamPay webhook signature against the raw body. Returns a result object; never throws. */
265
194
  declare function verifyWebhook(input: VerifyWebhookInput): VerifyWebhookResult;
195
+ /** Like `verifyWebhook` but throws `StreamPayWebhookError` on failure; returns the signed timestamp on success. */
266
196
  declare function verifyWebhookOrThrow(input: VerifyWebhookInput): number;
267
197
 
268
198
  export { type ConsumerIdentifiers, type InvoiceStatus, type Language, type ParsedStreamPayError, type PaymentMethod, type RefundReason, StreamPayAmount, type StreamPayPaymentStatus, type StreamPayValidationIssue, StreamPayWebhookError, type SubscriptionSchema, type VerifyFailureReason, type VerifyWebhookInput, type VerifyWebhookResult, findConsumerByExternalId, findConsumerByIdentifiers, formatStreamPayError, parseStreamPayError, subscriptionSchema, verifyWebhook, verifyWebhookOrThrow };