better-auth-streampay 2.2.1 → 3.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/README.md +172 -2
- package/dist/client.cjs +1 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +6 -2
- package/dist/client.d.ts +6 -2
- package/dist/client.js +1 -0
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +594 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +594 -205
- package/dist/index.js.map +1 -1
- package/dist/{streampay-B3vf7Hvq.d.cts → streampay-Cfl70SR_.d.cts} +413 -251
- package/dist/{streampay-B3vf7Hvq.d.ts → streampay-Cfl70SR_.d.ts} +413 -251
- package/package.json +11 -4
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ pnpm add better-auth-streampay @streamsdk/typescript
|
|
|
29
29
|
|
|
30
30
|
Required versions:
|
|
31
31
|
|
|
32
|
-
- `better-auth ^1.
|
|
32
|
+
- `better-auth ^1.6.0`
|
|
33
33
|
- `@streamsdk/typescript ^1.1.3`
|
|
34
34
|
- `zod ^3.24.0 || ^4.0.0`
|
|
35
35
|
|
|
@@ -104,6 +104,26 @@ Review the generated schema, then use your normal migration process. The plugin
|
|
|
104
104
|
schema but never changes your database at runtime. For an existing subscription table, backfill
|
|
105
105
|
`seats` to `1` in the same migration.
|
|
106
106
|
|
|
107
|
+
Add `subscription.catalogMapped` with a default of `true` before deploying this version.
|
|
108
|
+
Better Auth 1.6's migration generator does not apply static defaults to added columns. Review
|
|
109
|
+
and backfill the column explicitly. For PostgreSQL with the default table name:
|
|
110
|
+
|
|
111
|
+
```sql
|
|
112
|
+
ALTER TABLE subscription ADD COLUMN IF NOT EXISTS "catalogMapped" boolean DEFAULT true;
|
|
113
|
+
ALTER TABLE subscription ALTER COLUMN "catalogMapped" SET DEFAULT true;
|
|
114
|
+
UPDATE subscription SET "catalogMapped" = true WHERE "catalogMapped" IS NULL;
|
|
115
|
+
ALTER TABLE subscription ADD COLUMN IF NOT EXISTS "renewalCallbackEventId" text;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Use your configured table name and your database's boolean syntax when they differ. The column
|
|
119
|
+
remains nullable for rolling migrations; legacy null values preserve existing access until
|
|
120
|
+
reconciliation provides a catalog decision. Better Auth 1.6.0 is the minimum because 1.5's built-in
|
|
121
|
+
SQL adapter handles null comparisons incorrectly, breaking ungrouped reads and released leases.
|
|
122
|
+
|
|
123
|
+
Reconciliation sets it to `false` when Stream's current products do not match a configured plan;
|
|
124
|
+
billing details remain visible, but features and limits deny access. Dynamic plan factories
|
|
125
|
+
resolve on each resolution.
|
|
126
|
+
|
|
107
127
|
`streampayConsumerId` is unique. Before applying the generated unique index to an existing
|
|
108
128
|
database, resolve any duplicate non-null consumer IDs. Checkout fails closed when a consumer link
|
|
109
129
|
cannot be stored safely.
|
|
@@ -230,18 +250,64 @@ storefront has a different origin.
|
|
|
230
250
|
|
|
231
251
|
## Billing portal
|
|
232
252
|
|
|
233
|
-
`portal()` adds
|
|
253
|
+
`portal()` adds signed-in user actions:
|
|
234
254
|
|
|
235
255
|
- `state`
|
|
236
256
|
- `subscriptions`
|
|
237
257
|
- `invoices`
|
|
258
|
+
- `portal.session` when hosted session creation is configured
|
|
238
259
|
|
|
239
260
|
```ts
|
|
240
261
|
const state = await authClient.consumer.state();
|
|
241
262
|
const subscriptions = await authClient.consumer.subscriptions.list();
|
|
242
263
|
const invoices = await authClient.consumer.invoices.list();
|
|
264
|
+
const nextInvoices = await authClient.consumer.invoices.list({ query: { page: 2, size: 10 } });
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Invoice and subscription lists return Stream's `pagination` alongside `data`. The consumer filter
|
|
268
|
+
always comes from the signed-in account. `page` must be a positive safe integer; `size` is 1–100.
|
|
269
|
+
The plugin translates `size` to Stream's documented `limit` query parameter; SDK 1.1.3's
|
|
270
|
+
`size` parameter is ignored by the current API.
|
|
271
|
+
|
|
272
|
+
To open [Stream's hosted customer portal](https://docs.streampay.sa/customer-portal/), configure a
|
|
273
|
+
server-side session creator. Stream SDK 1.1.3 does not expose this endpoint yet:
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
portal({
|
|
277
|
+
createSession: async (input) => {
|
|
278
|
+
const response = await fetch(`${process.env.STREAMPAY_BASE_URL}/api/v2/consumer_portal/sessions`, {
|
|
279
|
+
method: "POST",
|
|
280
|
+
headers: {
|
|
281
|
+
"x-api-key": process.env.STREAMPAY_API_KEY!,
|
|
282
|
+
"content-type": "application/json",
|
|
283
|
+
},
|
|
284
|
+
body: JSON.stringify(input),
|
|
285
|
+
signal: AbortSignal.timeout(15_000),
|
|
286
|
+
});
|
|
287
|
+
if (!response.ok) {
|
|
288
|
+
throw Object.assign(new Error("Portal session creation failed."), { status: response.status });
|
|
289
|
+
}
|
|
290
|
+
return response.json();
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Frontend, using streampayClient():
|
|
295
|
+
const { data, error } = await authClient.consumer.portal.session();
|
|
296
|
+
if (error) throw new Error(error.message);
|
|
297
|
+
if (data) window.location.assign(data.url);
|
|
243
298
|
```
|
|
244
299
|
|
|
300
|
+
`POST /consumer/portal/session` resolves the consumer from the session and ignores consumer IDs
|
|
301
|
+
in the request. Missing consumers or configuration return 404; anonymous sessions are rejected.
|
|
302
|
+
Each request creates a fresh URL, requires HTTPS, and sends `Cache-Control: no-store`. Treat the
|
|
303
|
+
single-use URL as a credential: do not log, persist, or share it. Keep API keys on the server.
|
|
304
|
+
|
|
305
|
+
Enable customer permissions and branding in Stream's dashboard. Product switches require switch
|
|
306
|
+
groups; add-ons require catalog mappings. Stream controls proration and payment confirmation.
|
|
307
|
+
Keep webhook reconciliation enabled so portal changes update local subscription access. This
|
|
308
|
+
initial integration opens the consumer's portal; subscription deep links are not exposed. The
|
|
309
|
+
current OpenAPI omits the guide's `return_url` field, so the plugin does not send it.
|
|
310
|
+
|
|
245
311
|
## Subscriptions
|
|
246
312
|
|
|
247
313
|
```ts
|
|
@@ -350,6 +416,44 @@ await authClient.subscription.freeze.cancel({
|
|
|
350
416
|
});
|
|
351
417
|
```
|
|
352
418
|
|
|
419
|
+
SDK 1.1.3 cannot request later freeze pages. Configure `listSubscriptionFreezes` on the
|
|
420
|
+
server to enable complete freeze lookup for cancellation and unfreezing:
|
|
421
|
+
|
|
422
|
+
```ts
|
|
423
|
+
import { StreamSDKError } from "@streamsdk/typescript";
|
|
424
|
+
|
|
425
|
+
subscriptions({
|
|
426
|
+
plans,
|
|
427
|
+
listSubscriptionFreezes: async (subscriptionId, { page, limit }) => {
|
|
428
|
+
const url = new URL(
|
|
429
|
+
`/api/v2/subscriptions/${encodeURIComponent(subscriptionId)}/freeze`,
|
|
430
|
+
process.env.STREAMPAY_BASE_URL!,
|
|
431
|
+
);
|
|
432
|
+
url.search = new URLSearchParams({
|
|
433
|
+
page: String(page), limit: String(limit),
|
|
434
|
+
sort_field: "created_at", sort_direction: "asc",
|
|
435
|
+
}).toString();
|
|
436
|
+
const response = await fetch(url, {
|
|
437
|
+
headers: { "x-api-key": process.env.STREAMPAY_API_KEY! },
|
|
438
|
+
signal: AbortSignal.timeout(15000),
|
|
439
|
+
});
|
|
440
|
+
const body = await response.json();
|
|
441
|
+
if (!response.ok) {
|
|
442
|
+
throw new StreamSDKError("Freeze history request failed", {
|
|
443
|
+
status: response.status, body,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return body;
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
The callback receives only an authorized subscription ID. Return the API's complete page
|
|
452
|
+
response, including pagination. The plugin requests up to 100 entries per page and searches
|
|
453
|
+
up to 100 pages, stopping when it finds the freeze. Invalid or nonadvancing pages return 409;
|
|
454
|
+
API failures propagate without reporting cancellation. Without this callback, the plugin uses
|
|
455
|
+
the SDK's first page and retains the safe latest-freeze fallback or 409 for unresolved history.
|
|
456
|
+
|
|
353
457
|
### Read access and limits
|
|
354
458
|
|
|
355
459
|
```ts
|
|
@@ -457,6 +561,7 @@ Then add the handlers you need:
|
|
|
457
561
|
```ts
|
|
458
562
|
webhooks({
|
|
459
563
|
secret: process.env.STREAMPAY_WEBHOOK_SECRET!,
|
|
564
|
+
deduplicate: true,
|
|
460
565
|
|
|
461
566
|
onPaymentSucceeded: async (event) => {},
|
|
462
567
|
onPaymentFailed: async (event) => {},
|
|
@@ -474,6 +579,22 @@ The plugin:
|
|
|
474
579
|
- retries temporary failures
|
|
475
580
|
- stores failed subscription events for admin replay
|
|
476
581
|
|
|
582
|
+
`deduplicate: true` also persists generic handler deliveries in `streampayWebhookEvent`, including
|
|
583
|
+
unknown event envelopes. Apply the inbox table migration before enabling it. Handler receipts use
|
|
584
|
+
the `handlers:` event ID prefix and support the existing authenticated admin replay endpoint.
|
|
585
|
+
The default is `false` to preserve existing installations that have no inbox table.
|
|
586
|
+
|
|
587
|
+
Verified payloads are persisted when processing is claimed, so an interrupted delivery can be
|
|
588
|
+
recovered after its lease expires. Callbacks must still be idempotent: a crash after an external
|
|
589
|
+
side effect, or failure of a later callback, can repeat earlier work on retry. Inbox deduplication
|
|
590
|
+
does not provide exactly-once execution of external side effects.
|
|
591
|
+
|
|
592
|
+
Typed handlers include `onPaymentPartiallyRefunded` and `onSubscriptionCycleRenewedSuccessfully`.
|
|
593
|
+
Successful renewal events reconcile billing state and share renewal inference with completed
|
|
594
|
+
invoices. The cycle update records its callback owner in `renewalCallbackEventId`; an interrupted
|
|
595
|
+
owner can resume on replay, and competing events cannot take its pending callback. Apply this
|
|
596
|
+
nullable column before deploying. External callback side effects still need idempotency.
|
|
597
|
+
|
|
477
598
|
The StreamPay SDK does not export webhook payload types. This package provides checked event
|
|
478
599
|
types based on StreamPay's documented payloads.
|
|
479
600
|
|
|
@@ -547,6 +668,55 @@ import {
|
|
|
547
668
|
} from "better-auth-streampay";
|
|
548
669
|
```
|
|
549
670
|
|
|
671
|
+
## Local staging demo
|
|
672
|
+
|
|
673
|
+
The demo uses Node 22's SQLite support, real Better Auth sessions, and a Stream sandbox organization.
|
|
674
|
+
It binds to `127.0.0.1:3100`; the tunnel exposes only signed webhook ingress. Credentials and local
|
|
675
|
+
state are ignored by Git. It is a single-account test harness, not a deployable application.
|
|
676
|
+
|
|
677
|
+
Copy `examples/demo/.env.example` to `.env.local` in the same directory, fill in sandbox credentials
|
|
678
|
+
and the recurring starter product ID, and generate distinct random auth and webhook secrets.
|
|
679
|
+
|
|
680
|
+
```bash
|
|
681
|
+
pnpm build
|
|
682
|
+
pnpm demo:setup
|
|
683
|
+
pnpm demo
|
|
684
|
+
# In another terminal:
|
|
685
|
+
cloudflared tunnel --url http://localhost:3100 --no-autoupdate
|
|
686
|
+
pnpm demo:setup https://YOUR-TUNNEL.trycloudflare.com
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
Open `http://localhost:3100`, create a local account, then run `pnpm demo:exercise`. The script
|
|
690
|
+
creates a dedicated free trial with notifications disabled, and sends an explicitly synthetic
|
|
691
|
+
signed event twice to correlate that fixture with the local account. Provider-created events
|
|
692
|
+
arrive separately through the registered webhook. Creating a subscription directly through the
|
|
693
|
+
Stream API does not include the plugin's checkout correlation metadata automatically.
|
|
694
|
+
|
|
695
|
+
The setup command creates or updates only the webhook saved in the demo's state file and
|
|
696
|
+
synchronizes its signing secret, including after rotation. When done,
|
|
697
|
+
run `pnpm demo:cleanup` to cancel its trial and remove its webhook, then stop the server and tunnel.
|
|
698
|
+
Cleanup also requests cancellation of a saved paid validation subscription, if present. Stream
|
|
699
|
+
cancels active subscriptions at period end; cleanup retains their state files until cancellation
|
|
700
|
+
completes. It retains the dedicated consumer and local database.
|
|
701
|
+
|
|
702
|
+
Validation on 2026-10-10 used Better Auth 1.7.7 and Stream SDK 1.1.3. Tests also ran on Node
|
|
703
|
+
20.19.0 and 24.21.0, and in an isolated Better Auth 1.6.0 / Zod 3.24 installation. PostgreSQL
|
|
704
|
+
17 tests run against a temporary schema and cover concurrent claims, expired-lease replay,
|
|
705
|
+
stale worker fencing, simultaneous renewal evidence, and migration/backfill of an existing row.
|
|
706
|
+
|
|
707
|
+
```bash
|
|
708
|
+
STREAMPAY_TEST_DATABASE_URL=postgres://USER:PASSWORD@localhost:5432/TEST_DATABASE pnpm test:postgres
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
Dependency builds are explicit in `pnpm-workspace.yaml`: esbuild is allowed; optional lefthook
|
|
712
|
+
and MSW dependency scripts are disabled. The root prepare script installs the Git hooks.
|
|
713
|
+
|
|
714
|
+
The PostgreSQL suite owns a randomly named schema and drops it afterward. CI runs it in a
|
|
715
|
+
separate PostgreSQL service. Use a test database, not the application's staging or production database.
|
|
716
|
+
|
|
717
|
+
See [staging validation](docs/staging-validation.md) for the live coverage, regression evidence,
|
|
718
|
+
provider discrepancies and remaining limits.
|
|
719
|
+
|
|
550
720
|
## License
|
|
551
721
|
|
|
552
722
|
MIT
|
package/dist/client.cjs
CHANGED
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error-codes.ts","../src/client.ts"],"names":[],"mappings":";;;AAMA,SAAS,iBACR,KAAA,EACqD;AACrD,EAAA,MAAM,MAAM,EAAC;AACb,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,EAA+B;AACjE,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI;AAAA,MACV,IAAA,EAAM,GAAA;AAAA,MACN,OAAA,EAAS,MAAM,GAAG,CAAA;AAAA,MAClB,UAAU,MAAM;AAAA,KACjB;AAAA,EACD;AACA,EAAA,OAAO,GAAA;AACR;AAEO,IAAM,eAAe,gBAAA,CAAiB;AAAA,EAC5C,gBAAA,EAAkB,6BAAA;AAAA,EAClB,YAAA,EAAc,qCAAA;AAAA,EACd,SAAA,EAAW,oDAAA;AAAA,EACX,SAAA,EAAW,uCAAA;AAAA,EACX,kBAAA,EAAoB,iEAAA;AAAA,EACpB,gCAAA,EAAkC,+DAAA;AAAA,EAClC,oCAAA,EAAsC,iDAAA;AAAA,EACtC,6BAAA,EACC,mFAAA;AAAA,EACD,qBAAA,EAAuB,qDAAA;AAAA,EACvB,iBAAA,EAAmB,qDAAA;AAAA,EACnB,qBAAA,EAAuB,qDAAA;AAAA,EACvB,wBAAA,EAA0B,yCAAA;AAAA,EAC1B,qBAAA,EAAuB,4CAAA;AAAA,EACvB,wBAAA,EAA0B,0CAAA;AAAA,EAC1B,2BAAA,EAA6B,kEAAA;AAAA,EAC7B,sBAAA,EAAwB,uDAAA;AAAA,EACxB,cAAA,EAAgB,0EAAA;AAAA,EAChB,aAAA,EAAe,yEAAA;AAAA,EACf,gCAAA,EAAkC,iDAAA;AAAA,EAClC,sBAAA,EAAwB,kCAAA;AAAA,EACxB,2BAAA,EAA6B,oDAAA;AAAA,EAC7B,2BAAA,EAA6B,4DAAA;AAAA,EAC7B,iCAAA,EACC,uEAAA;AAAA,EACD,6BAAA,EAA+B,uCAAA;AAAA,EAC/B,2BAAA,EAA6B,qCAAA;AAAA,EAC7B,oBAAA,EAAsB,+BAAA;AAAA,EACtB,qCAAA,EACC,gEAAA;AAAA,EACD,4BAAA,EAA8B,oDAAA;AAAA,EAC9B,+BAAA,EAAiC,oDAAA;AAAA,EACjC,0CAAA,EACC,uDAAA;AAAA,EACD,yCAAA,EACC,6EAAA;AAAA,EACD,0CAAA,EACC,2EAAA;AAAA,EACD,gCAAA,EACC,4EAAA;AAAA,EACD,0CAAA,EACC,qEAAA;AAAA,EACD,0BAAA,EAA4B,0DAAA;AAAA,EAC5B,8BAAA,EAAgC,0DAAA;AAAA,EAChC,qCAAA,EACC,+DAAA;AAAA,EACD,0BAAA,EAA4B,+CAAA;AAAA,EAC5B,OAAA,EAAS;AACV,CAAC;;;AC/DM,IAAM,kBAAkB,MAAM;AACpC,EAAA,OAAO;AAAA,IACN,EAAA,EAAI,kBAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB;AAAA,GACD;AACD","file":"client.cjs","sourcesContent":["export interface ErrorCodeEntry<K extends string> {\n\tcode: K;\n\tmessage: string;\n\ttoString: () => K;\n}\n\nfunction defineErrorCodes<const Codes extends Record<string, string>>(\n\tcodes: Codes,\n): { [K in keyof Codes & string]: ErrorCodeEntry<K> } {\n\tconst out = {} as { [K in keyof Codes & string]: ErrorCodeEntry<K> };\n\tfor (const key of Object.keys(codes) as (keyof Codes & string)[]) {\n\t\tout[key] = {\n\t\t\tcode: key,\n\t\t\tmessage: codes[key] as Codes[typeof key],\n\t\t\ttoString: () => key,\n\t\t};\n\t}\n\treturn out;\n}\n\nexport const $ERROR_CODES = defineErrorCodes({\n\tVALIDATION_ERROR: \"Request input is not valid.\",\n\tUNAUTHORIZED: \"Missing or invalid API credentials.\",\n\tFORBIDDEN: \"You do not have permission to perform this action.\",\n\tNOT_FOUND: \"The requested resource was not found.\",\n\tCONSUMER_DUPLICATE: \"A consumer with one of the provided identifiers already exists.\",\n\tSTREAMPAY_CONSUMER_LINK_CONFLICT: \"This StreamPay consumer is already linked to another account.\",\n\tSTREAMPAY_CONSUMER_LINK_WRITE_FAILED: \"The StreamPay consumer link could not be saved.\",\n\tCONSUMER_HAS_ONGOING_ACTIVITY:\n\t\t\"The consumer has ongoing invoices or active subscriptions and cannot be modified.\",\n\tINVOICE_INVALID_STATE: \"The invoice is in a state that forbids this action.\",\n\tPAYMENT_DUPLICATE: \"A payment with the same information already exists.\",\n\tPAYMENT_INVALID_STATE: \"The payment is in a state that forbids this action.\",\n\tPAYMENT_ALREADY_REFUNDED: \"This payment has already been refunded.\",\n\tPAYMENT_REFUND_FAILED: \"The payment processor rejected the refund.\",\n\tPAYMENT_GATEWAY_DECLINED: \"The payment was declined by the gateway.\",\n\tPAYMENT_GATEWAY_UNAVAILABLE: \"The payment gateway is temporarily unavailable. Try again later.\",\n\tPAYMENT_METHOD_INVALID: \"The supplied payment method is invalid for this flow.\",\n\tPRODUCT_LOCKED: \"The product is referenced by a finalized invoice and cannot be modified.\",\n\tCOUPON_LOCKED: \"The coupon is referenced by a finalized invoice and cannot be modified.\",\n\tCHECKOUT_CLIENT_FIELDS_FORBIDDEN: \"Checkout fields must be resolved by the server.\",\n\tSUBSCRIPTION_NOT_FOUND: \"The subscription does not exist.\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"The requested subscription plan is not configured.\",\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"An active subscription already exists for this plan group.\",\n\tSUBSCRIPTION_CHECKOUT_IN_PROGRESS:\n\t\t\"A subscription checkout is already being created for this plan group.\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"The subscription is already canceled.\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"The subscription is already frozen.\",\n\tSUBSCRIPTION_EXPIRED: \"The subscription has expired.\",\n\tSUBSCRIPTION_ALREADY_SCHEDULED_CANCEL:\n\t\t\"The subscription is already scheduled to cancel at period end.\",\n\tSUBSCRIPTION_ALREADY_ON_PLAN: \"The subscription is already on the requested plan.\",\n\tSUBSCRIPTION_SEAT_COUNT_INVALID: \"The requested seat count is invalid for this plan.\",\n\tSUBSCRIPTION_SEAT_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different subscription change is already scheduled.\",\n\tSUBSCRIPTION_IMMEDIATE_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay does not support immediate cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PERIOD_END_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay only supports period-end cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PLAN_GROUP_MISMATCH:\n\t\t\"Subscription plan changes must stay within the same configured plan group.\",\n\tSUBSCRIPTION_PLAN_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different plan change is already scheduled for this subscription.\",\n\tSUBSCRIPTION_INVALID_STATE: \"The subscription is in a state that forbids this action.\",\n\tSUBSCRIPTION_FREEZE_NOT_ACTIVE: \"No active freeze period was found for this subscription.\",\n\tSUBSCRIPTION_REFERENCE_NOT_AUTHORIZED:\n\t\t\"You are not authorized to act on this subscription reference.\",\n\tWEBHOOK_REPLAY_IN_PROGRESS: \"This webhook event is already being replayed.\",\n\tUNKNOWN: \"An unexpected error occurred.\",\n});\n\nexport type StreamPayErrorCode = keyof typeof $ERROR_CODES;\n\nconst RAW_CODE_MAP: Record<string, StreamPayErrorCode> = {\n\tINVALID_PARAMETERS: \"VALIDATION_ERROR\",\n\n\tPERMISSION_FORBIDDEN: \"FORBIDDEN\",\n\tBRANCH_ACCESS_DENIED: \"FORBIDDEN\",\n\tBRANCH_NOT_FOUND: \"NOT_FOUND\",\n\n\tDUPLICATE_CONSUMER: \"CONSUMER_DUPLICATE\",\n\tDUPLICATE_CARD_TOKEN: \"CONSUMER_DUPLICATE\",\n\tCONSUMER_HAS_ONGOING_INVOICES: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\tCONSUMER_HAS_ONGOING_SUBSCRIPTIONS: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\n\tINVOICE_FINALISED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_INVALID_STATUS: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_CONSUMED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_EXPIRED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_TOTAL_MISMATCH_PAYMENT_AMOUNT_SUM: \"INVOICE_INVALID_STATE\",\n\tINVOICE_PAYMENT_COUNT_NOT_MATCHED: \"INVOICE_INVALID_STATE\",\n\n\tDUPLICATE_PAYMENT: \"PAYMENT_DUPLICATE\",\n\tPAYMENT_IN_PROGRESS: \"PAYMENT_INVALID_STATE\",\n\tPAYMENT_FINALIZED: \"PAYMENT_INVALID_STATE\",\n\tPAYMEND_UNPAID: \"PAYMENT_INVALID_STATE\",\n\tINVALID_STATUS: \"PAYMENT_INVALID_STATE\",\n\n\tPAYMENT_REFUNDED_ALREADY: \"PAYMENT_ALREADY_REFUNDED\",\n\tPAYMENT_REFUNDED_FAILED: \"PAYMENT_REFUND_FAILED\",\n\n\tPAYMENT_GATEWAY_DECLINED: \"PAYMENT_GATEWAY_DECLINED\",\n\tINSUFFICIENT_FUNDS: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_PAYMENT_INFO_MISMATCH: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_BAD_REQUEST: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_UNAUTHORIZED: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_FORBIDDEN: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_NOT_FOUND: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_METHOD_NOT_ALLOWED: \"PAYMENT_GATEWAY_DECLINED\",\n\n\tMOYASAR_TIMEOUT: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_TOO_MANY_REQUESTS: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_INTERNAL_SERVER_ERROR: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_SERVICE_UNAVAILABLE: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\n\tMOYASAR_INVALID_CARD_TOKEN: \"PAYMENT_METHOD_INVALID\",\n\tMANUAL_INVOICE_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_INVALID_PAYMENT_FLOW: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tAUTO_INVOICE_MISSING_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tPAYMENT_FLOW_NOT_ALLOWED: \"PAYMENT_METHOD_INVALID\",\n\n\tPRODUCT_USED_IN_FINALIZED_INVOICE: \"PRODUCT_LOCKED\",\n\tCOUPON_USED_IN_FINALIZED_INVOICE: \"COUPON_LOCKED\",\n\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"SUBSCRIPTION_ALREADY_ACTIVE\",\n\tSUBSCRIPTION_NOT_FOUND: \"SUBSCRIPTION_NOT_FOUND\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"SUBSCRIPTION_ALREADY_CANCELED\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"SUBSCRIPTION_ALREADY_FROZEN\",\n\tSUBSCRIPTION_NOT_FROZEN: \"SUBSCRIPTION_FREEZE_NOT_ACTIVE\",\n\tSUBSCRIPTION_EXPIRED: \"SUBSCRIPTION_EXPIRED\",\n};\n\nexport function mapToErrorCode(\n\trawCode: string | undefined,\n\tstatus: number | undefined,\n): StreamPayErrorCode {\n\tif (rawCode && rawCode in RAW_CODE_MAP) {\n\t\tconst mapped = RAW_CODE_MAP[rawCode];\n\t\tif (mapped) return mapped;\n\t}\n\tif (status === 401) return \"UNAUTHORIZED\";\n\tif (status === 403) return \"FORBIDDEN\";\n\tif (status === 404) return \"NOT_FOUND\";\n\tif (status === 422) return \"VALIDATION_ERROR\";\n\treturn \"UNKNOWN\";\n}\n","import type { BetterAuthClientPlugin } from \"better-auth\";\nimport { $ERROR_CODES } from \"./error-codes\";\nimport type { streampay } from \"./streampay\";\n\nexport { $ERROR_CODES, type StreamPayErrorCode } from \"./error-codes\";\n\nexport const streampayClient = () => {\n\treturn {\n\t\tid: \"streampay-client\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof streampay>,\n\t\t$ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/error-codes.ts","../src/client.ts"],"names":[],"mappings":";;;AAMA,SAAS,iBACR,KAAA,EACqD;AACrD,EAAA,MAAM,MAAM,EAAC;AACb,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,EAA+B;AACjE,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI;AAAA,MACV,IAAA,EAAM,GAAA;AAAA,MACN,OAAA,EAAS,MAAM,GAAG,CAAA;AAAA,MAClB,UAAU,MAAM;AAAA,KACjB;AAAA,EACD;AACA,EAAA,OAAO,GAAA;AACR;AAEO,IAAM,eAAe,gBAAA,CAAiB;AAAA,EAC5C,gBAAA,EAAkB,6BAAA;AAAA,EAClB,YAAA,EAAc,qCAAA;AAAA,EACd,SAAA,EAAW,oDAAA;AAAA,EACX,SAAA,EAAW,uCAAA;AAAA,EACX,kBAAA,EAAoB,iEAAA;AAAA,EACpB,gCAAA,EAAkC,+DAAA;AAAA,EAClC,oCAAA,EAAsC,iDAAA;AAAA,EACtC,6BAAA,EACC,mFAAA;AAAA,EACD,qBAAA,EAAuB,qDAAA;AAAA,EACvB,iBAAA,EAAmB,qDAAA;AAAA,EACnB,qBAAA,EAAuB,qDAAA;AAAA,EACvB,wBAAA,EAA0B,yCAAA;AAAA,EAC1B,qBAAA,EAAuB,4CAAA;AAAA,EACvB,wBAAA,EAA0B,0CAAA;AAAA,EAC1B,2BAAA,EAA6B,kEAAA;AAAA,EAC7B,sBAAA,EAAwB,uDAAA;AAAA,EACxB,cAAA,EAAgB,0EAAA;AAAA,EAChB,aAAA,EAAe,yEAAA;AAAA,EACf,gCAAA,EAAkC,iDAAA;AAAA,EAClC,sBAAA,EAAwB,kCAAA;AAAA,EACxB,2BAAA,EAA6B,oDAAA;AAAA,EAC7B,2BAAA,EAA6B,4DAAA;AAAA,EAC7B,iCAAA,EACC,uEAAA;AAAA,EACD,6BAAA,EAA+B,uCAAA;AAAA,EAC/B,2BAAA,EAA6B,qCAAA;AAAA,EAC7B,oBAAA,EAAsB,+BAAA;AAAA,EACtB,qCAAA,EACC,gEAAA;AAAA,EACD,4BAAA,EAA8B,oDAAA;AAAA,EAC9B,+BAAA,EAAiC,oDAAA;AAAA,EACjC,0CAAA,EACC,uDAAA;AAAA,EACD,yCAAA,EACC,6EAAA;AAAA,EACD,0CAAA,EACC,2EAAA;AAAA,EACD,gCAAA,EACC,4EAAA;AAAA,EACD,0CAAA,EACC,qEAAA;AAAA,EACD,0BAAA,EAA4B,0DAAA;AAAA,EAC5B,8BAAA,EAAgC,0DAAA;AAAA,EAChC,qCAAA,EACC,+DAAA;AAAA,EACD,0BAAA,EAA4B,+CAAA;AAAA,EAC5B,OAAA,EAAS;AACV,CAAC;;;AC/DM,IAAM,kBAAkB,MAAM;AACpC,EAAA,OAAO;AAAA,IACN,EAAA,EAAI,kBAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,WAAA,EAAa,EAAE,0BAAA,EAA4B,MAAA,EAAQ,aAAa,MAAA,EAAO;AAAA,IACvE;AAAA,GACD;AACD","file":"client.cjs","sourcesContent":["export interface ErrorCodeEntry<K extends string> {\n\tcode: K;\n\tmessage: string;\n\ttoString: () => K;\n}\n\nfunction defineErrorCodes<const Codes extends Record<string, string>>(\n\tcodes: Codes,\n): { [K in keyof Codes & string]: ErrorCodeEntry<K> } {\n\tconst out = {} as { [K in keyof Codes & string]: ErrorCodeEntry<K> };\n\tfor (const key of Object.keys(codes) as (keyof Codes & string)[]) {\n\t\tout[key] = {\n\t\t\tcode: key,\n\t\t\tmessage: codes[key] as Codes[typeof key],\n\t\t\ttoString: () => key,\n\t\t};\n\t}\n\treturn out;\n}\n\nexport const $ERROR_CODES = defineErrorCodes({\n\tVALIDATION_ERROR: \"Request input is not valid.\",\n\tUNAUTHORIZED: \"Missing or invalid API credentials.\",\n\tFORBIDDEN: \"You do not have permission to perform this action.\",\n\tNOT_FOUND: \"The requested resource was not found.\",\n\tCONSUMER_DUPLICATE: \"A consumer with one of the provided identifiers already exists.\",\n\tSTREAMPAY_CONSUMER_LINK_CONFLICT: \"This StreamPay consumer is already linked to another account.\",\n\tSTREAMPAY_CONSUMER_LINK_WRITE_FAILED: \"The StreamPay consumer link could not be saved.\",\n\tCONSUMER_HAS_ONGOING_ACTIVITY:\n\t\t\"The consumer has ongoing invoices or active subscriptions and cannot be modified.\",\n\tINVOICE_INVALID_STATE: \"The invoice is in a state that forbids this action.\",\n\tPAYMENT_DUPLICATE: \"A payment with the same information already exists.\",\n\tPAYMENT_INVALID_STATE: \"The payment is in a state that forbids this action.\",\n\tPAYMENT_ALREADY_REFUNDED: \"This payment has already been refunded.\",\n\tPAYMENT_REFUND_FAILED: \"The payment processor rejected the refund.\",\n\tPAYMENT_GATEWAY_DECLINED: \"The payment was declined by the gateway.\",\n\tPAYMENT_GATEWAY_UNAVAILABLE: \"The payment gateway is temporarily unavailable. Try again later.\",\n\tPAYMENT_METHOD_INVALID: \"The supplied payment method is invalid for this flow.\",\n\tPRODUCT_LOCKED: \"The product is referenced by a finalized invoice and cannot be modified.\",\n\tCOUPON_LOCKED: \"The coupon is referenced by a finalized invoice and cannot be modified.\",\n\tCHECKOUT_CLIENT_FIELDS_FORBIDDEN: \"Checkout fields must be resolved by the server.\",\n\tSUBSCRIPTION_NOT_FOUND: \"The subscription does not exist.\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"The requested subscription plan is not configured.\",\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"An active subscription already exists for this plan group.\",\n\tSUBSCRIPTION_CHECKOUT_IN_PROGRESS:\n\t\t\"A subscription checkout is already being created for this plan group.\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"The subscription is already canceled.\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"The subscription is already frozen.\",\n\tSUBSCRIPTION_EXPIRED: \"The subscription has expired.\",\n\tSUBSCRIPTION_ALREADY_SCHEDULED_CANCEL:\n\t\t\"The subscription is already scheduled to cancel at period end.\",\n\tSUBSCRIPTION_ALREADY_ON_PLAN: \"The subscription is already on the requested plan.\",\n\tSUBSCRIPTION_SEAT_COUNT_INVALID: \"The requested seat count is invalid for this plan.\",\n\tSUBSCRIPTION_SEAT_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different subscription change is already scheduled.\",\n\tSUBSCRIPTION_IMMEDIATE_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay does not support immediate cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PERIOD_END_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay only supports period-end cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PLAN_GROUP_MISMATCH:\n\t\t\"Subscription plan changes must stay within the same configured plan group.\",\n\tSUBSCRIPTION_PLAN_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different plan change is already scheduled for this subscription.\",\n\tSUBSCRIPTION_INVALID_STATE: \"The subscription is in a state that forbids this action.\",\n\tSUBSCRIPTION_FREEZE_NOT_ACTIVE: \"No active freeze period was found for this subscription.\",\n\tSUBSCRIPTION_REFERENCE_NOT_AUTHORIZED:\n\t\t\"You are not authorized to act on this subscription reference.\",\n\tWEBHOOK_REPLAY_IN_PROGRESS: \"This webhook event is already being replayed.\",\n\tUNKNOWN: \"An unexpected error occurred.\",\n});\n\nexport type StreamPayErrorCode = keyof typeof $ERROR_CODES;\n\nconst RAW_CODE_MAP: Record<string, StreamPayErrorCode> = {\n\tINVALID_PARAMETERS: \"VALIDATION_ERROR\",\n\n\tPERMISSION_FORBIDDEN: \"FORBIDDEN\",\n\tBRANCH_ACCESS_DENIED: \"FORBIDDEN\",\n\tBRANCH_NOT_FOUND: \"NOT_FOUND\",\n\n\tDUPLICATE_CONSUMER: \"CONSUMER_DUPLICATE\",\n\tDUPLICATE_CARD_TOKEN: \"CONSUMER_DUPLICATE\",\n\tCONSUMER_HAS_ONGOING_INVOICES: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\tCONSUMER_HAS_ONGOING_SUBSCRIPTIONS: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\n\tINVOICE_FINALISED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_INVALID_STATUS: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_CONSUMED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_EXPIRED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_TOTAL_MISMATCH_PAYMENT_AMOUNT_SUM: \"INVOICE_INVALID_STATE\",\n\tINVOICE_PAYMENT_COUNT_NOT_MATCHED: \"INVOICE_INVALID_STATE\",\n\n\tDUPLICATE_PAYMENT: \"PAYMENT_DUPLICATE\",\n\tPAYMENT_IN_PROGRESS: \"PAYMENT_INVALID_STATE\",\n\tPAYMENT_FINALIZED: \"PAYMENT_INVALID_STATE\",\n\tPAYMEND_UNPAID: \"PAYMENT_INVALID_STATE\",\n\tINVALID_STATUS: \"PAYMENT_INVALID_STATE\",\n\n\tPAYMENT_REFUNDED_ALREADY: \"PAYMENT_ALREADY_REFUNDED\",\n\tPAYMENT_REFUNDED_FAILED: \"PAYMENT_REFUND_FAILED\",\n\n\tPAYMENT_GATEWAY_DECLINED: \"PAYMENT_GATEWAY_DECLINED\",\n\tINSUFFICIENT_FUNDS: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_PAYMENT_INFO_MISMATCH: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_BAD_REQUEST: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_UNAUTHORIZED: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_FORBIDDEN: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_NOT_FOUND: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_METHOD_NOT_ALLOWED: \"PAYMENT_GATEWAY_DECLINED\",\n\n\tMOYASAR_TIMEOUT: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_TOO_MANY_REQUESTS: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_INTERNAL_SERVER_ERROR: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_SERVICE_UNAVAILABLE: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\n\tMOYASAR_INVALID_CARD_TOKEN: \"PAYMENT_METHOD_INVALID\",\n\tMANUAL_INVOICE_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_INVALID_PAYMENT_FLOW: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tAUTO_INVOICE_MISSING_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tPAYMENT_FLOW_NOT_ALLOWED: \"PAYMENT_METHOD_INVALID\",\n\n\tPRODUCT_USED_IN_FINALIZED_INVOICE: \"PRODUCT_LOCKED\",\n\tCOUPON_USED_IN_FINALIZED_INVOICE: \"COUPON_LOCKED\",\n\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"SUBSCRIPTION_ALREADY_ACTIVE\",\n\tSUBSCRIPTION_NOT_FOUND: \"SUBSCRIPTION_NOT_FOUND\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"SUBSCRIPTION_ALREADY_CANCELED\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"SUBSCRIPTION_ALREADY_FROZEN\",\n\tSUBSCRIPTION_NOT_FROZEN: \"SUBSCRIPTION_FREEZE_NOT_ACTIVE\",\n\tSUBSCRIPTION_EXPIRED: \"SUBSCRIPTION_EXPIRED\",\n};\n\nexport function mapToErrorCode(\n\trawCode: string | undefined,\n\tstatus: number | undefined,\n): StreamPayErrorCode {\n\tif (rawCode && rawCode in RAW_CODE_MAP) {\n\t\tconst mapped = RAW_CODE_MAP[rawCode];\n\t\tif (mapped) return mapped;\n\t}\n\tif (status === 401) return \"UNAUTHORIZED\";\n\tif (status === 403) return \"FORBIDDEN\";\n\tif (status === 404) return \"NOT_FOUND\";\n\tif (status === 422) return \"VALIDATION_ERROR\";\n\treturn \"UNKNOWN\";\n}\n","import type { BetterAuthClientPlugin } from \"better-auth\";\nimport { $ERROR_CODES } from \"./error-codes\";\nimport type { streampay } from \"./streampay\";\n\nexport { $ERROR_CODES, type StreamPayErrorCode } from \"./error-codes\";\n\nexport const streampayClient = () => {\n\treturn {\n\t\tid: \"streampay-client\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof streampay>,\n\t\tpathMethods: { \"/consumer/portal/session\": \"POST\", \"/checkout\": \"POST\" },\n\t\t$ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
|
package/dist/client.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as streampay, E as ErrorCodeEntry } from './streampay-
|
|
2
|
-
export { $ as $ERROR_CODES, S as StreamPayErrorCode } from './streampay-
|
|
1
|
+
import { s as streampay, E as ErrorCodeEntry } from './streampay-Cfl70SR_.cjs';
|
|
2
|
+
export { $ as $ERROR_CODES, S as StreamPayErrorCode } from './streampay-Cfl70SR_.cjs';
|
|
3
3
|
import '@streamsdk/typescript';
|
|
4
4
|
import 'better-auth';
|
|
5
5
|
import 'zod';
|
|
@@ -8,6 +8,10 @@ import 'zod/v4/core';
|
|
|
8
8
|
declare const streampayClient: () => {
|
|
9
9
|
id: "streampay-client";
|
|
10
10
|
$InferServerPlugin: ReturnType<typeof streampay>;
|
|
11
|
+
pathMethods: {
|
|
12
|
+
"/consumer/portal/session": "POST";
|
|
13
|
+
"/checkout": "POST";
|
|
14
|
+
};
|
|
11
15
|
$ERROR_CODES: {
|
|
12
16
|
UNAUTHORIZED: ErrorCodeEntry<"UNAUTHORIZED">;
|
|
13
17
|
FORBIDDEN: ErrorCodeEntry<"FORBIDDEN">;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as streampay, E as ErrorCodeEntry } from './streampay-
|
|
2
|
-
export { $ as $ERROR_CODES, S as StreamPayErrorCode } from './streampay-
|
|
1
|
+
import { s as streampay, E as ErrorCodeEntry } from './streampay-Cfl70SR_.js';
|
|
2
|
+
export { $ as $ERROR_CODES, S as StreamPayErrorCode } from './streampay-Cfl70SR_.js';
|
|
3
3
|
import '@streamsdk/typescript';
|
|
4
4
|
import 'better-auth';
|
|
5
5
|
import 'zod';
|
|
@@ -8,6 +8,10 @@ import 'zod/v4/core';
|
|
|
8
8
|
declare const streampayClient: () => {
|
|
9
9
|
id: "streampay-client";
|
|
10
10
|
$InferServerPlugin: ReturnType<typeof streampay>;
|
|
11
|
+
pathMethods: {
|
|
12
|
+
"/consumer/portal/session": "POST";
|
|
13
|
+
"/checkout": "POST";
|
|
14
|
+
};
|
|
11
15
|
$ERROR_CODES: {
|
|
12
16
|
UNAUTHORIZED: ErrorCodeEntry<"UNAUTHORIZED">;
|
|
13
17
|
FORBIDDEN: ErrorCodeEntry<"FORBIDDEN">;
|
package/dist/client.js
CHANGED
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error-codes.ts","../src/client.ts"],"names":[],"mappings":";AAMA,SAAS,iBACR,KAAA,EACqD;AACrD,EAAA,MAAM,MAAM,EAAC;AACb,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,EAA+B;AACjE,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI;AAAA,MACV,IAAA,EAAM,GAAA;AAAA,MACN,OAAA,EAAS,MAAM,GAAG,CAAA;AAAA,MAClB,UAAU,MAAM;AAAA,KACjB;AAAA,EACD;AACA,EAAA,OAAO,GAAA;AACR;AAEO,IAAM,eAAe,gBAAA,CAAiB;AAAA,EAC5C,gBAAA,EAAkB,6BAAA;AAAA,EAClB,YAAA,EAAc,qCAAA;AAAA,EACd,SAAA,EAAW,oDAAA;AAAA,EACX,SAAA,EAAW,uCAAA;AAAA,EACX,kBAAA,EAAoB,iEAAA;AAAA,EACpB,gCAAA,EAAkC,+DAAA;AAAA,EAClC,oCAAA,EAAsC,iDAAA;AAAA,EACtC,6BAAA,EACC,mFAAA;AAAA,EACD,qBAAA,EAAuB,qDAAA;AAAA,EACvB,iBAAA,EAAmB,qDAAA;AAAA,EACnB,qBAAA,EAAuB,qDAAA;AAAA,EACvB,wBAAA,EAA0B,yCAAA;AAAA,EAC1B,qBAAA,EAAuB,4CAAA;AAAA,EACvB,wBAAA,EAA0B,0CAAA;AAAA,EAC1B,2BAAA,EAA6B,kEAAA;AAAA,EAC7B,sBAAA,EAAwB,uDAAA;AAAA,EACxB,cAAA,EAAgB,0EAAA;AAAA,EAChB,aAAA,EAAe,yEAAA;AAAA,EACf,gCAAA,EAAkC,iDAAA;AAAA,EAClC,sBAAA,EAAwB,kCAAA;AAAA,EACxB,2BAAA,EAA6B,oDAAA;AAAA,EAC7B,2BAAA,EAA6B,4DAAA;AAAA,EAC7B,iCAAA,EACC,uEAAA;AAAA,EACD,6BAAA,EAA+B,uCAAA;AAAA,EAC/B,2BAAA,EAA6B,qCAAA;AAAA,EAC7B,oBAAA,EAAsB,+BAAA;AAAA,EACtB,qCAAA,EACC,gEAAA;AAAA,EACD,4BAAA,EAA8B,oDAAA;AAAA,EAC9B,+BAAA,EAAiC,oDAAA;AAAA,EACjC,0CAAA,EACC,uDAAA;AAAA,EACD,yCAAA,EACC,6EAAA;AAAA,EACD,0CAAA,EACC,2EAAA;AAAA,EACD,gCAAA,EACC,4EAAA;AAAA,EACD,0CAAA,EACC,qEAAA;AAAA,EACD,0BAAA,EAA4B,0DAAA;AAAA,EAC5B,8BAAA,EAAgC,0DAAA;AAAA,EAChC,qCAAA,EACC,+DAAA;AAAA,EACD,0BAAA,EAA4B,+CAAA;AAAA,EAC5B,OAAA,EAAS;AACV,CAAC;;;AC/DM,IAAM,kBAAkB,MAAM;AACpC,EAAA,OAAO;AAAA,IACN,EAAA,EAAI,kBAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB;AAAA,GACD;AACD","file":"client.js","sourcesContent":["export interface ErrorCodeEntry<K extends string> {\n\tcode: K;\n\tmessage: string;\n\ttoString: () => K;\n}\n\nfunction defineErrorCodes<const Codes extends Record<string, string>>(\n\tcodes: Codes,\n): { [K in keyof Codes & string]: ErrorCodeEntry<K> } {\n\tconst out = {} as { [K in keyof Codes & string]: ErrorCodeEntry<K> };\n\tfor (const key of Object.keys(codes) as (keyof Codes & string)[]) {\n\t\tout[key] = {\n\t\t\tcode: key,\n\t\t\tmessage: codes[key] as Codes[typeof key],\n\t\t\ttoString: () => key,\n\t\t};\n\t}\n\treturn out;\n}\n\nexport const $ERROR_CODES = defineErrorCodes({\n\tVALIDATION_ERROR: \"Request input is not valid.\",\n\tUNAUTHORIZED: \"Missing or invalid API credentials.\",\n\tFORBIDDEN: \"You do not have permission to perform this action.\",\n\tNOT_FOUND: \"The requested resource was not found.\",\n\tCONSUMER_DUPLICATE: \"A consumer with one of the provided identifiers already exists.\",\n\tSTREAMPAY_CONSUMER_LINK_CONFLICT: \"This StreamPay consumer is already linked to another account.\",\n\tSTREAMPAY_CONSUMER_LINK_WRITE_FAILED: \"The StreamPay consumer link could not be saved.\",\n\tCONSUMER_HAS_ONGOING_ACTIVITY:\n\t\t\"The consumer has ongoing invoices or active subscriptions and cannot be modified.\",\n\tINVOICE_INVALID_STATE: \"The invoice is in a state that forbids this action.\",\n\tPAYMENT_DUPLICATE: \"A payment with the same information already exists.\",\n\tPAYMENT_INVALID_STATE: \"The payment is in a state that forbids this action.\",\n\tPAYMENT_ALREADY_REFUNDED: \"This payment has already been refunded.\",\n\tPAYMENT_REFUND_FAILED: \"The payment processor rejected the refund.\",\n\tPAYMENT_GATEWAY_DECLINED: \"The payment was declined by the gateway.\",\n\tPAYMENT_GATEWAY_UNAVAILABLE: \"The payment gateway is temporarily unavailable. Try again later.\",\n\tPAYMENT_METHOD_INVALID: \"The supplied payment method is invalid for this flow.\",\n\tPRODUCT_LOCKED: \"The product is referenced by a finalized invoice and cannot be modified.\",\n\tCOUPON_LOCKED: \"The coupon is referenced by a finalized invoice and cannot be modified.\",\n\tCHECKOUT_CLIENT_FIELDS_FORBIDDEN: \"Checkout fields must be resolved by the server.\",\n\tSUBSCRIPTION_NOT_FOUND: \"The subscription does not exist.\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"The requested subscription plan is not configured.\",\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"An active subscription already exists for this plan group.\",\n\tSUBSCRIPTION_CHECKOUT_IN_PROGRESS:\n\t\t\"A subscription checkout is already being created for this plan group.\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"The subscription is already canceled.\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"The subscription is already frozen.\",\n\tSUBSCRIPTION_EXPIRED: \"The subscription has expired.\",\n\tSUBSCRIPTION_ALREADY_SCHEDULED_CANCEL:\n\t\t\"The subscription is already scheduled to cancel at period end.\",\n\tSUBSCRIPTION_ALREADY_ON_PLAN: \"The subscription is already on the requested plan.\",\n\tSUBSCRIPTION_SEAT_COUNT_INVALID: \"The requested seat count is invalid for this plan.\",\n\tSUBSCRIPTION_SEAT_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different subscription change is already scheduled.\",\n\tSUBSCRIPTION_IMMEDIATE_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay does not support immediate cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PERIOD_END_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay only supports period-end cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PLAN_GROUP_MISMATCH:\n\t\t\"Subscription plan changes must stay within the same configured plan group.\",\n\tSUBSCRIPTION_PLAN_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different plan change is already scheduled for this subscription.\",\n\tSUBSCRIPTION_INVALID_STATE: \"The subscription is in a state that forbids this action.\",\n\tSUBSCRIPTION_FREEZE_NOT_ACTIVE: \"No active freeze period was found for this subscription.\",\n\tSUBSCRIPTION_REFERENCE_NOT_AUTHORIZED:\n\t\t\"You are not authorized to act on this subscription reference.\",\n\tWEBHOOK_REPLAY_IN_PROGRESS: \"This webhook event is already being replayed.\",\n\tUNKNOWN: \"An unexpected error occurred.\",\n});\n\nexport type StreamPayErrorCode = keyof typeof $ERROR_CODES;\n\nconst RAW_CODE_MAP: Record<string, StreamPayErrorCode> = {\n\tINVALID_PARAMETERS: \"VALIDATION_ERROR\",\n\n\tPERMISSION_FORBIDDEN: \"FORBIDDEN\",\n\tBRANCH_ACCESS_DENIED: \"FORBIDDEN\",\n\tBRANCH_NOT_FOUND: \"NOT_FOUND\",\n\n\tDUPLICATE_CONSUMER: \"CONSUMER_DUPLICATE\",\n\tDUPLICATE_CARD_TOKEN: \"CONSUMER_DUPLICATE\",\n\tCONSUMER_HAS_ONGOING_INVOICES: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\tCONSUMER_HAS_ONGOING_SUBSCRIPTIONS: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\n\tINVOICE_FINALISED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_INVALID_STATUS: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_CONSUMED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_EXPIRED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_TOTAL_MISMATCH_PAYMENT_AMOUNT_SUM: \"INVOICE_INVALID_STATE\",\n\tINVOICE_PAYMENT_COUNT_NOT_MATCHED: \"INVOICE_INVALID_STATE\",\n\n\tDUPLICATE_PAYMENT: \"PAYMENT_DUPLICATE\",\n\tPAYMENT_IN_PROGRESS: \"PAYMENT_INVALID_STATE\",\n\tPAYMENT_FINALIZED: \"PAYMENT_INVALID_STATE\",\n\tPAYMEND_UNPAID: \"PAYMENT_INVALID_STATE\",\n\tINVALID_STATUS: \"PAYMENT_INVALID_STATE\",\n\n\tPAYMENT_REFUNDED_ALREADY: \"PAYMENT_ALREADY_REFUNDED\",\n\tPAYMENT_REFUNDED_FAILED: \"PAYMENT_REFUND_FAILED\",\n\n\tPAYMENT_GATEWAY_DECLINED: \"PAYMENT_GATEWAY_DECLINED\",\n\tINSUFFICIENT_FUNDS: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_PAYMENT_INFO_MISMATCH: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_BAD_REQUEST: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_UNAUTHORIZED: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_FORBIDDEN: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_NOT_FOUND: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_METHOD_NOT_ALLOWED: \"PAYMENT_GATEWAY_DECLINED\",\n\n\tMOYASAR_TIMEOUT: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_TOO_MANY_REQUESTS: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_INTERNAL_SERVER_ERROR: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_SERVICE_UNAVAILABLE: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\n\tMOYASAR_INVALID_CARD_TOKEN: \"PAYMENT_METHOD_INVALID\",\n\tMANUAL_INVOICE_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_INVALID_PAYMENT_FLOW: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tAUTO_INVOICE_MISSING_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tPAYMENT_FLOW_NOT_ALLOWED: \"PAYMENT_METHOD_INVALID\",\n\n\tPRODUCT_USED_IN_FINALIZED_INVOICE: \"PRODUCT_LOCKED\",\n\tCOUPON_USED_IN_FINALIZED_INVOICE: \"COUPON_LOCKED\",\n\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"SUBSCRIPTION_ALREADY_ACTIVE\",\n\tSUBSCRIPTION_NOT_FOUND: \"SUBSCRIPTION_NOT_FOUND\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"SUBSCRIPTION_ALREADY_CANCELED\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"SUBSCRIPTION_ALREADY_FROZEN\",\n\tSUBSCRIPTION_NOT_FROZEN: \"SUBSCRIPTION_FREEZE_NOT_ACTIVE\",\n\tSUBSCRIPTION_EXPIRED: \"SUBSCRIPTION_EXPIRED\",\n};\n\nexport function mapToErrorCode(\n\trawCode: string | undefined,\n\tstatus: number | undefined,\n): StreamPayErrorCode {\n\tif (rawCode && rawCode in RAW_CODE_MAP) {\n\t\tconst mapped = RAW_CODE_MAP[rawCode];\n\t\tif (mapped) return mapped;\n\t}\n\tif (status === 401) return \"UNAUTHORIZED\";\n\tif (status === 403) return \"FORBIDDEN\";\n\tif (status === 404) return \"NOT_FOUND\";\n\tif (status === 422) return \"VALIDATION_ERROR\";\n\treturn \"UNKNOWN\";\n}\n","import type { BetterAuthClientPlugin } from \"better-auth\";\nimport { $ERROR_CODES } from \"./error-codes\";\nimport type { streampay } from \"./streampay\";\n\nexport { $ERROR_CODES, type StreamPayErrorCode } from \"./error-codes\";\n\nexport const streampayClient = () => {\n\treturn {\n\t\tid: \"streampay-client\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof streampay>,\n\t\t$ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/error-codes.ts","../src/client.ts"],"names":[],"mappings":";AAMA,SAAS,iBACR,KAAA,EACqD;AACrD,EAAA,MAAM,MAAM,EAAC;AACb,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,EAA+B;AACjE,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI;AAAA,MACV,IAAA,EAAM,GAAA;AAAA,MACN,OAAA,EAAS,MAAM,GAAG,CAAA;AAAA,MAClB,UAAU,MAAM;AAAA,KACjB;AAAA,EACD;AACA,EAAA,OAAO,GAAA;AACR;AAEO,IAAM,eAAe,gBAAA,CAAiB;AAAA,EAC5C,gBAAA,EAAkB,6BAAA;AAAA,EAClB,YAAA,EAAc,qCAAA;AAAA,EACd,SAAA,EAAW,oDAAA;AAAA,EACX,SAAA,EAAW,uCAAA;AAAA,EACX,kBAAA,EAAoB,iEAAA;AAAA,EACpB,gCAAA,EAAkC,+DAAA;AAAA,EAClC,oCAAA,EAAsC,iDAAA;AAAA,EACtC,6BAAA,EACC,mFAAA;AAAA,EACD,qBAAA,EAAuB,qDAAA;AAAA,EACvB,iBAAA,EAAmB,qDAAA;AAAA,EACnB,qBAAA,EAAuB,qDAAA;AAAA,EACvB,wBAAA,EAA0B,yCAAA;AAAA,EAC1B,qBAAA,EAAuB,4CAAA;AAAA,EACvB,wBAAA,EAA0B,0CAAA;AAAA,EAC1B,2BAAA,EAA6B,kEAAA;AAAA,EAC7B,sBAAA,EAAwB,uDAAA;AAAA,EACxB,cAAA,EAAgB,0EAAA;AAAA,EAChB,aAAA,EAAe,yEAAA;AAAA,EACf,gCAAA,EAAkC,iDAAA;AAAA,EAClC,sBAAA,EAAwB,kCAAA;AAAA,EACxB,2BAAA,EAA6B,oDAAA;AAAA,EAC7B,2BAAA,EAA6B,4DAAA;AAAA,EAC7B,iCAAA,EACC,uEAAA;AAAA,EACD,6BAAA,EAA+B,uCAAA;AAAA,EAC/B,2BAAA,EAA6B,qCAAA;AAAA,EAC7B,oBAAA,EAAsB,+BAAA;AAAA,EACtB,qCAAA,EACC,gEAAA;AAAA,EACD,4BAAA,EAA8B,oDAAA;AAAA,EAC9B,+BAAA,EAAiC,oDAAA;AAAA,EACjC,0CAAA,EACC,uDAAA;AAAA,EACD,yCAAA,EACC,6EAAA;AAAA,EACD,0CAAA,EACC,2EAAA;AAAA,EACD,gCAAA,EACC,4EAAA;AAAA,EACD,0CAAA,EACC,qEAAA;AAAA,EACD,0BAAA,EAA4B,0DAAA;AAAA,EAC5B,8BAAA,EAAgC,0DAAA;AAAA,EAChC,qCAAA,EACC,+DAAA;AAAA,EACD,0BAAA,EAA4B,+CAAA;AAAA,EAC5B,OAAA,EAAS;AACV,CAAC;;;AC/DM,IAAM,kBAAkB,MAAM;AACpC,EAAA,OAAO;AAAA,IACN,EAAA,EAAI,kBAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,WAAA,EAAa,EAAE,0BAAA,EAA4B,MAAA,EAAQ,aAAa,MAAA,EAAO;AAAA,IACvE;AAAA,GACD;AACD","file":"client.js","sourcesContent":["export interface ErrorCodeEntry<K extends string> {\n\tcode: K;\n\tmessage: string;\n\ttoString: () => K;\n}\n\nfunction defineErrorCodes<const Codes extends Record<string, string>>(\n\tcodes: Codes,\n): { [K in keyof Codes & string]: ErrorCodeEntry<K> } {\n\tconst out = {} as { [K in keyof Codes & string]: ErrorCodeEntry<K> };\n\tfor (const key of Object.keys(codes) as (keyof Codes & string)[]) {\n\t\tout[key] = {\n\t\t\tcode: key,\n\t\t\tmessage: codes[key] as Codes[typeof key],\n\t\t\ttoString: () => key,\n\t\t};\n\t}\n\treturn out;\n}\n\nexport const $ERROR_CODES = defineErrorCodes({\n\tVALIDATION_ERROR: \"Request input is not valid.\",\n\tUNAUTHORIZED: \"Missing or invalid API credentials.\",\n\tFORBIDDEN: \"You do not have permission to perform this action.\",\n\tNOT_FOUND: \"The requested resource was not found.\",\n\tCONSUMER_DUPLICATE: \"A consumer with one of the provided identifiers already exists.\",\n\tSTREAMPAY_CONSUMER_LINK_CONFLICT: \"This StreamPay consumer is already linked to another account.\",\n\tSTREAMPAY_CONSUMER_LINK_WRITE_FAILED: \"The StreamPay consumer link could not be saved.\",\n\tCONSUMER_HAS_ONGOING_ACTIVITY:\n\t\t\"The consumer has ongoing invoices or active subscriptions and cannot be modified.\",\n\tINVOICE_INVALID_STATE: \"The invoice is in a state that forbids this action.\",\n\tPAYMENT_DUPLICATE: \"A payment with the same information already exists.\",\n\tPAYMENT_INVALID_STATE: \"The payment is in a state that forbids this action.\",\n\tPAYMENT_ALREADY_REFUNDED: \"This payment has already been refunded.\",\n\tPAYMENT_REFUND_FAILED: \"The payment processor rejected the refund.\",\n\tPAYMENT_GATEWAY_DECLINED: \"The payment was declined by the gateway.\",\n\tPAYMENT_GATEWAY_UNAVAILABLE: \"The payment gateway is temporarily unavailable. Try again later.\",\n\tPAYMENT_METHOD_INVALID: \"The supplied payment method is invalid for this flow.\",\n\tPRODUCT_LOCKED: \"The product is referenced by a finalized invoice and cannot be modified.\",\n\tCOUPON_LOCKED: \"The coupon is referenced by a finalized invoice and cannot be modified.\",\n\tCHECKOUT_CLIENT_FIELDS_FORBIDDEN: \"Checkout fields must be resolved by the server.\",\n\tSUBSCRIPTION_NOT_FOUND: \"The subscription does not exist.\",\n\tSUBSCRIPTION_PLAN_NOT_FOUND: \"The requested subscription plan is not configured.\",\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"An active subscription already exists for this plan group.\",\n\tSUBSCRIPTION_CHECKOUT_IN_PROGRESS:\n\t\t\"A subscription checkout is already being created for this plan group.\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"The subscription is already canceled.\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"The subscription is already frozen.\",\n\tSUBSCRIPTION_EXPIRED: \"The subscription has expired.\",\n\tSUBSCRIPTION_ALREADY_SCHEDULED_CANCEL:\n\t\t\"The subscription is already scheduled to cancel at period end.\",\n\tSUBSCRIPTION_ALREADY_ON_PLAN: \"The subscription is already on the requested plan.\",\n\tSUBSCRIPTION_SEAT_COUNT_INVALID: \"The requested seat count is invalid for this plan.\",\n\tSUBSCRIPTION_SEAT_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different subscription change is already scheduled.\",\n\tSUBSCRIPTION_IMMEDIATE_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay does not support immediate cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PERIOD_END_CANCEL_UNSUPPORTED:\n\t\t\"StreamPay only supports period-end cancellation for active subscriptions.\",\n\tSUBSCRIPTION_PLAN_GROUP_MISMATCH:\n\t\t\"Subscription plan changes must stay within the same configured plan group.\",\n\tSUBSCRIPTION_PLAN_CHANGE_ALREADY_SCHEDULED:\n\t\t\"A different plan change is already scheduled for this subscription.\",\n\tSUBSCRIPTION_INVALID_STATE: \"The subscription is in a state that forbids this action.\",\n\tSUBSCRIPTION_FREEZE_NOT_ACTIVE: \"No active freeze period was found for this subscription.\",\n\tSUBSCRIPTION_REFERENCE_NOT_AUTHORIZED:\n\t\t\"You are not authorized to act on this subscription reference.\",\n\tWEBHOOK_REPLAY_IN_PROGRESS: \"This webhook event is already being replayed.\",\n\tUNKNOWN: \"An unexpected error occurred.\",\n});\n\nexport type StreamPayErrorCode = keyof typeof $ERROR_CODES;\n\nconst RAW_CODE_MAP: Record<string, StreamPayErrorCode> = {\n\tINVALID_PARAMETERS: \"VALIDATION_ERROR\",\n\n\tPERMISSION_FORBIDDEN: \"FORBIDDEN\",\n\tBRANCH_ACCESS_DENIED: \"FORBIDDEN\",\n\tBRANCH_NOT_FOUND: \"NOT_FOUND\",\n\n\tDUPLICATE_CONSUMER: \"CONSUMER_DUPLICATE\",\n\tDUPLICATE_CARD_TOKEN: \"CONSUMER_DUPLICATE\",\n\tCONSUMER_HAS_ONGOING_INVOICES: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\tCONSUMER_HAS_ONGOING_SUBSCRIPTIONS: \"CONSUMER_HAS_ONGOING_ACTIVITY\",\n\n\tINVOICE_FINALISED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_INVALID_STATUS: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_CONSUMED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_CONSENT_EXPIRED: \"INVOICE_INVALID_STATE\",\n\tINVOICE_TOTAL_MISMATCH_PAYMENT_AMOUNT_SUM: \"INVOICE_INVALID_STATE\",\n\tINVOICE_PAYMENT_COUNT_NOT_MATCHED: \"INVOICE_INVALID_STATE\",\n\n\tDUPLICATE_PAYMENT: \"PAYMENT_DUPLICATE\",\n\tPAYMENT_IN_PROGRESS: \"PAYMENT_INVALID_STATE\",\n\tPAYMENT_FINALIZED: \"PAYMENT_INVALID_STATE\",\n\tPAYMEND_UNPAID: \"PAYMENT_INVALID_STATE\",\n\tINVALID_STATUS: \"PAYMENT_INVALID_STATE\",\n\n\tPAYMENT_REFUNDED_ALREADY: \"PAYMENT_ALREADY_REFUNDED\",\n\tPAYMENT_REFUNDED_FAILED: \"PAYMENT_REFUND_FAILED\",\n\n\tPAYMENT_GATEWAY_DECLINED: \"PAYMENT_GATEWAY_DECLINED\",\n\tINSUFFICIENT_FUNDS: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_PAYMENT_INFO_MISMATCH: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_BAD_REQUEST: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_UNAUTHORIZED: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_FORBIDDEN: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_NOT_FOUND: \"PAYMENT_GATEWAY_DECLINED\",\n\tMOYASAR_METHOD_NOT_ALLOWED: \"PAYMENT_GATEWAY_DECLINED\",\n\n\tMOYASAR_TIMEOUT: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_TOO_MANY_REQUESTS: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_INTERNAL_SERVER_ERROR: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\tMOYASAR_SERVICE_UNAVAILABLE: \"PAYMENT_GATEWAY_UNAVAILABLE\",\n\n\tMOYASAR_INVALID_CARD_TOKEN: \"PAYMENT_METHOD_INVALID\",\n\tMANUAL_INVOICE_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_INVALID_PAYMENT_FLOW: \"PAYMENT_METHOD_INVALID\",\n\tONE_OFF_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tAUTO_INVOICE_MISSING_CARD_ID: \"PAYMENT_METHOD_INVALID\",\n\tPAYMENT_FLOW_NOT_ALLOWED: \"PAYMENT_METHOD_INVALID\",\n\n\tPRODUCT_USED_IN_FINALIZED_INVOICE: \"PRODUCT_LOCKED\",\n\tCOUPON_USED_IN_FINALIZED_INVOICE: \"COUPON_LOCKED\",\n\n\tSUBSCRIPTION_ALREADY_ACTIVE: \"SUBSCRIPTION_ALREADY_ACTIVE\",\n\tSUBSCRIPTION_NOT_FOUND: \"SUBSCRIPTION_NOT_FOUND\",\n\tSUBSCRIPTION_ALREADY_CANCELED: \"SUBSCRIPTION_ALREADY_CANCELED\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"SUBSCRIPTION_ALREADY_FROZEN\",\n\tSUBSCRIPTION_NOT_FROZEN: \"SUBSCRIPTION_FREEZE_NOT_ACTIVE\",\n\tSUBSCRIPTION_EXPIRED: \"SUBSCRIPTION_EXPIRED\",\n};\n\nexport function mapToErrorCode(\n\trawCode: string | undefined,\n\tstatus: number | undefined,\n): StreamPayErrorCode {\n\tif (rawCode && rawCode in RAW_CODE_MAP) {\n\t\tconst mapped = RAW_CODE_MAP[rawCode];\n\t\tif (mapped) return mapped;\n\t}\n\tif (status === 401) return \"UNAUTHORIZED\";\n\tif (status === 403) return \"FORBIDDEN\";\n\tif (status === 404) return \"NOT_FOUND\";\n\tif (status === 422) return \"VALIDATION_ERROR\";\n\treturn \"UNKNOWN\";\n}\n","import type { BetterAuthClientPlugin } from \"better-auth\";\nimport { $ERROR_CODES } from \"./error-codes\";\nimport type { streampay } from \"./streampay\";\n\nexport { $ERROR_CODES, type StreamPayErrorCode } from \"./error-codes\";\n\nexport const streampayClient = () => {\n\treturn {\n\t\tid: \"streampay-client\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof streampay>,\n\t\tpathMethods: { \"/consumer/portal/session\": \"POST\", \"/checkout\": \"POST\" },\n\t\t$ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n"]}
|