better-auth-streampay 1.2.1 → 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/README.md +0 -1
- package/dist/client.cjs +0 -4
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +3 -2
- package/dist/client.d.ts +3 -2
- package/dist/client.js +0 -4
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +41 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -75
- package/dist/index.d.ts +5 -75
- package/dist/index.js +41 -125
- package/dist/index.js.map +1 -1
- package/dist/{streampay-DMlTwJUB.d.cts → streampay-1mamzabs.d.cts} +15 -178
- package/dist/{streampay-DMlTwJUB.d.ts → streampay-1mamzabs.d.ts} +15 -178
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -193,7 +193,6 @@ await authClient.checkout({
|
|
|
193
193
|
| `slug` | `string` | Resolved server-side via `products` |
|
|
194
194
|
| `products` | `string \| string[] \| { productId, quantity? }[]` | UUID(s) |
|
|
195
195
|
| `referenceId` | `string` | Stored in `custom_metadata` |
|
|
196
|
-
| `consumerId` | `string` (uuid) | Override the resolved consumer |
|
|
197
196
|
| `name` | `string` | Payment link display name |
|
|
198
197
|
| `description` | `string` | |
|
|
199
198
|
| `metadata` | `Record<string, string \| number \| boolean>` | |
|
package/dist/client.cjs
CHANGED
|
@@ -43,10 +43,6 @@ var streampayClient = () => {
|
|
|
43
43
|
return {
|
|
44
44
|
id: "streampay-client",
|
|
45
45
|
$InferServerPlugin: {},
|
|
46
|
-
// Exposed on the client plugin so Better Auth's client reflections
|
|
47
|
-
// (and downstream UI code) can reach the taxonomy without importing
|
|
48
|
-
// the server entry. Mirrors Better Auth's own convention — cf. the
|
|
49
|
-
// organization plugin's `$ERROR_CODES` surface.
|
|
50
46
|
$ERROR_CODES
|
|
51
47
|
};
|
|
52
48
|
};
|
package/dist/client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error-codes.ts","../src/client.ts"],"names":[],"mappings":";;;
|
|
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,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,sBAAA,EAAwB,kCAAA;AAAA,EACxB,2BAAA,EAA6B,oDAAA;AAAA,EAC7B,2BAAA,EAA6B,4DAAA;AAAA,EAC7B,0BAAA,EAA4B,0DAAA;AAAA,EAC5B,8BAAA,EAAgC,0DAAA;AAAA,EAChC,qCAAA,EACC,+DAAA;AAAA,EACD,OAAA,EAAS;AACV,CAAC;;;ACvCM,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\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\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_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\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_INVALID_STATE\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"SUBSCRIPTION_INVALID_STATE\",\n\tSUBSCRIPTION_NOT_FROZEN: \"SUBSCRIPTION_FREEZE_NOT_ACTIVE\",\n\tSUBSCRIPTION_EXPIRED: \"SUBSCRIPTION_INVALID_STATE\",\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\n/** Better Auth client plugin. Add to `createAuthClient` to type the StreamPay endpoints and error codes. */\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"]}
|
package/dist/client.d.cts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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-1mamzabs.cjs';
|
|
2
|
+
export { $ as $ERROR_CODES, S as StreamPayErrorCode } from './streampay-1mamzabs.cjs';
|
|
3
3
|
import '@streamsdk/typescript';
|
|
4
4
|
import 'better-auth';
|
|
5
5
|
import 'zod/v4/core';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
|
+
/** Better Auth client plugin. Add to `createAuthClient` to type the StreamPay endpoints and error codes. */
|
|
8
9
|
declare const streampayClient: () => {
|
|
9
10
|
id: "streampay-client";
|
|
10
11
|
$InferServerPlugin: ReturnType<typeof streampay>;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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-1mamzabs.js';
|
|
2
|
+
export { $ as $ERROR_CODES, S as StreamPayErrorCode } from './streampay-1mamzabs.js';
|
|
3
3
|
import '@streamsdk/typescript';
|
|
4
4
|
import 'better-auth';
|
|
5
5
|
import 'zod/v4/core';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
|
+
/** Better Auth client plugin. Add to `createAuthClient` to type the StreamPay endpoints and error codes. */
|
|
8
9
|
declare const streampayClient: () => {
|
|
9
10
|
id: "streampay-client";
|
|
10
11
|
$InferServerPlugin: ReturnType<typeof streampay>;
|
package/dist/client.js
CHANGED
|
@@ -41,10 +41,6 @@ var streampayClient = () => {
|
|
|
41
41
|
return {
|
|
42
42
|
id: "streampay-client",
|
|
43
43
|
$InferServerPlugin: {},
|
|
44
|
-
// Exposed on the client plugin so Better Auth's client reflections
|
|
45
|
-
// (and downstream UI code) can reach the taxonomy without importing
|
|
46
|
-
// the server entry. Mirrors Better Auth's own convention — cf. the
|
|
47
|
-
// organization plugin's `$ERROR_CODES` surface.
|
|
48
44
|
$ERROR_CODES
|
|
49
45
|
};
|
|
50
46
|
};
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/error-codes.ts","../src/client.ts"],"names":[],"mappings":";
|
|
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,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,sBAAA,EAAwB,kCAAA;AAAA,EACxB,2BAAA,EAA6B,oDAAA;AAAA,EAC7B,2BAAA,EAA6B,4DAAA;AAAA,EAC7B,0BAAA,EAA4B,0DAAA;AAAA,EAC5B,8BAAA,EAAgC,0DAAA;AAAA,EAChC,qCAAA,EACC,+DAAA;AAAA,EACD,OAAA,EAAS;AACV,CAAC;;;ACvCM,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\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\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_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\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_INVALID_STATE\",\n\tSUBSCRIPTION_ALREADY_FROZEN: \"SUBSCRIPTION_INVALID_STATE\",\n\tSUBSCRIPTION_NOT_FROZEN: \"SUBSCRIPTION_FREEZE_NOT_ACTIVE\",\n\tSUBSCRIPTION_EXPIRED: \"SUBSCRIPTION_INVALID_STATE\",\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\n/** Better Auth client plugin. Add to `createAuthClient` to type the StreamPay endpoints and error codes. */\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"]}
|
package/dist/index.cjs
CHANGED
|
@@ -42,35 +42,27 @@ var $ERROR_CODES = defineErrorCodes({
|
|
|
42
42
|
UNKNOWN: "An unexpected error occurred."
|
|
43
43
|
});
|
|
44
44
|
var RAW_CODE_MAP = {
|
|
45
|
-
// Validation
|
|
46
45
|
INVALID_PARAMETERS: "VALIDATION_ERROR",
|
|
47
|
-
// Permissions
|
|
48
46
|
PERMISSION_FORBIDDEN: "FORBIDDEN",
|
|
49
47
|
BRANCH_ACCESS_DENIED: "FORBIDDEN",
|
|
50
48
|
BRANCH_NOT_FOUND: "NOT_FOUND",
|
|
51
|
-
// Consumer
|
|
52
49
|
DUPLICATE_CONSUMER: "CONSUMER_DUPLICATE",
|
|
53
50
|
DUPLICATE_CARD_TOKEN: "CONSUMER_DUPLICATE",
|
|
54
51
|
CONSUMER_HAS_ONGOING_INVOICES: "CONSUMER_HAS_ONGOING_ACTIVITY",
|
|
55
52
|
CONSUMER_HAS_ONGOING_SUBSCRIPTIONS: "CONSUMER_HAS_ONGOING_ACTIVITY",
|
|
56
|
-
// Invoice state
|
|
57
53
|
INVOICE_FINALISED: "INVOICE_INVALID_STATE",
|
|
58
54
|
INVOICE_INVALID_STATUS: "INVOICE_INVALID_STATE",
|
|
59
55
|
INVOICE_CONSENT_CONSUMED: "INVOICE_INVALID_STATE",
|
|
60
56
|
INVOICE_CONSENT_EXPIRED: "INVOICE_INVALID_STATE",
|
|
61
57
|
INVOICE_TOTAL_MISMATCH_PAYMENT_AMOUNT_SUM: "INVOICE_INVALID_STATE",
|
|
62
58
|
INVOICE_PAYMENT_COUNT_NOT_MATCHED: "INVOICE_INVALID_STATE",
|
|
63
|
-
// Payment state / duplicates
|
|
64
59
|
DUPLICATE_PAYMENT: "PAYMENT_DUPLICATE",
|
|
65
60
|
PAYMENT_IN_PROGRESS: "PAYMENT_INVALID_STATE",
|
|
66
61
|
PAYMENT_FINALIZED: "PAYMENT_INVALID_STATE",
|
|
67
62
|
PAYMEND_UNPAID: "PAYMENT_INVALID_STATE",
|
|
68
|
-
// sic — upstream typo we inherit
|
|
69
63
|
INVALID_STATUS: "PAYMENT_INVALID_STATE",
|
|
70
|
-
// Refund outcomes
|
|
71
64
|
PAYMENT_REFUNDED_ALREADY: "PAYMENT_ALREADY_REFUNDED",
|
|
72
65
|
PAYMENT_REFUNDED_FAILED: "PAYMENT_REFUND_FAILED",
|
|
73
|
-
// Gateway — declined (do not auto-retry; user must take action)
|
|
74
66
|
PAYMENT_GATEWAY_DECLINED: "PAYMENT_GATEWAY_DECLINED",
|
|
75
67
|
INSUFFICIENT_FUNDS: "PAYMENT_GATEWAY_DECLINED",
|
|
76
68
|
MOYASAR_PAYMENT_INFO_MISMATCH: "PAYMENT_GATEWAY_DECLINED",
|
|
@@ -79,23 +71,18 @@ var RAW_CODE_MAP = {
|
|
|
79
71
|
MOYASAR_FORBIDDEN: "PAYMENT_GATEWAY_DECLINED",
|
|
80
72
|
MOYASAR_NOT_FOUND: "PAYMENT_GATEWAY_DECLINED",
|
|
81
73
|
MOYASAR_METHOD_NOT_ALLOWED: "PAYMENT_GATEWAY_DECLINED",
|
|
82
|
-
// Gateway — transient (safe to retry with backoff)
|
|
83
74
|
MOYASAR_TIMEOUT: "PAYMENT_GATEWAY_UNAVAILABLE",
|
|
84
75
|
MOYASAR_TOO_MANY_REQUESTS: "PAYMENT_GATEWAY_UNAVAILABLE",
|
|
85
76
|
MOYASAR_INTERNAL_SERVER_ERROR: "PAYMENT_GATEWAY_UNAVAILABLE",
|
|
86
77
|
MOYASAR_SERVICE_UNAVAILABLE: "PAYMENT_GATEWAY_UNAVAILABLE",
|
|
87
|
-
// Payment method identity
|
|
88
78
|
MOYASAR_INVALID_CARD_TOKEN: "PAYMENT_METHOD_INVALID",
|
|
89
79
|
MANUAL_INVOICE_CARD_ID: "PAYMENT_METHOD_INVALID",
|
|
90
80
|
ONE_OFF_INVALID_PAYMENT_FLOW: "PAYMENT_METHOD_INVALID",
|
|
91
81
|
ONE_OFF_CARD_ID: "PAYMENT_METHOD_INVALID",
|
|
92
82
|
AUTO_INVOICE_MISSING_CARD_ID: "PAYMENT_METHOD_INVALID",
|
|
93
83
|
PAYMENT_FLOW_NOT_ALLOWED: "PAYMENT_METHOD_INVALID",
|
|
94
|
-
// Catalog
|
|
95
84
|
PRODUCT_USED_IN_FINALIZED_INVOICE: "PRODUCT_LOCKED",
|
|
96
85
|
COUPON_USED_IN_FINALIZED_INVOICE: "COUPON_LOCKED",
|
|
97
|
-
// Subscription state — these fire from the upstream API when the
|
|
98
|
-
// caller attempts an action the current subscription state forbids.
|
|
99
86
|
SUBSCRIPTION_ALREADY_ACTIVE: "SUBSCRIPTION_ALREADY_ACTIVE",
|
|
100
87
|
SUBSCRIPTION_NOT_FOUND: "SUBSCRIPTION_NOT_FOUND",
|
|
101
88
|
SUBSCRIPTION_ALREADY_CANCELED: "SUBSCRIPTION_INVALID_STATE",
|
|
@@ -121,9 +108,21 @@ async function findConsumerByExternalId(client, { externalId }) {
|
|
|
121
108
|
const hit = await searchExact(client, externalId, (c) => c.external_id === externalId);
|
|
122
109
|
return hit?.id ?? null;
|
|
123
110
|
}
|
|
111
|
+
function sameEmail(a, b) {
|
|
112
|
+
if (!a || !b) return false;
|
|
113
|
+
return a.trim().toLowerCase() === b.trim().toLowerCase();
|
|
114
|
+
}
|
|
115
|
+
function samePhone(a, b) {
|
|
116
|
+
if (!a || !b) return false;
|
|
117
|
+
return a.trim() === b.trim();
|
|
118
|
+
}
|
|
124
119
|
async function findConsumerByIdentifiers(client, identifiers) {
|
|
125
120
|
if (identifiers.email) {
|
|
126
|
-
const hit = await searchExact(
|
|
121
|
+
const hit = await searchExact(
|
|
122
|
+
client,
|
|
123
|
+
identifiers.email,
|
|
124
|
+
(c) => sameEmail(c.email, identifiers.email)
|
|
125
|
+
);
|
|
127
126
|
if (hit) return hit;
|
|
128
127
|
}
|
|
129
128
|
if (identifiers.phone_number) {
|
|
@@ -255,14 +254,6 @@ function getLogger(ctx) {
|
|
|
255
254
|
}
|
|
256
255
|
|
|
257
256
|
// src/utils/ensure-consumer.ts
|
|
258
|
-
function sameEmail(a, b) {
|
|
259
|
-
if (!a || !b) return false;
|
|
260
|
-
return a.trim().toLowerCase() === b.trim().toLowerCase();
|
|
261
|
-
}
|
|
262
|
-
function samePhone(a, b) {
|
|
263
|
-
if (!a || !b) return false;
|
|
264
|
-
return a.trim() === b.trim();
|
|
265
|
-
}
|
|
266
257
|
function canClaimBy(mode, identifier) {
|
|
267
258
|
return mode?.includes(identifier) ?? false;
|
|
268
259
|
}
|
|
@@ -517,7 +508,7 @@ var WEBHOOK_EVENT_MODEL = "streampayWebhookEvent";
|
|
|
517
508
|
function logger(ctx) {
|
|
518
509
|
return scopedLogger(ctx.context.logger);
|
|
519
510
|
}
|
|
520
|
-
var DEFAULT_MAX_WEBHOOK_ATTEMPTS =
|
|
511
|
+
var DEFAULT_MAX_WEBHOOK_ATTEMPTS = 5;
|
|
521
512
|
var MAX_CAUSE_DEPTH = 5;
|
|
522
513
|
function matchesUniqueMarker(err) {
|
|
523
514
|
if (!err || typeof err !== "object") return false;
|
|
@@ -762,6 +753,9 @@ async function reconcileFromStreamPay(ctx, payload, client, plans) {
|
|
|
762
753
|
}
|
|
763
754
|
const existing = await findSubscriptionByStreampayId(ctx, streampaySubscriptionId);
|
|
764
755
|
const projected = projectSubscriptionFields(stream);
|
|
756
|
+
if (payload.event_type === "SUBSCRIPTION_CYCLE_RENEWAL_FAILED" && projected.status === "active") {
|
|
757
|
+
projected.status = "past_due";
|
|
758
|
+
}
|
|
765
759
|
if (existing) {
|
|
766
760
|
const updated = await ctx.context.adapter.update({
|
|
767
761
|
model: SUBSCRIPTION_MODEL,
|
|
@@ -807,11 +801,14 @@ var SubscriptionItemSchema = zod.z.object({
|
|
|
807
801
|
product: zod.z.object({ id: zod.z.string() }).passthrough().optional(),
|
|
808
802
|
product_id: zod.z.string().optional()
|
|
809
803
|
}).passthrough();
|
|
804
|
+
function subscriptionItemProductId(item) {
|
|
805
|
+
const parsed = SubscriptionItemSchema.safeParse(item);
|
|
806
|
+
if (!parsed.success) return null;
|
|
807
|
+
return parsed.data.product?.id ?? parsed.data.product_id ?? null;
|
|
808
|
+
}
|
|
810
809
|
function inferPlanFromItems(sub, plans) {
|
|
811
810
|
const first = Array.isArray(sub.items) ? sub.items[0] : void 0;
|
|
812
|
-
const
|
|
813
|
-
if (!parsed.success) return null;
|
|
814
|
-
const productId = parsed.data.product?.id ?? parsed.data.product_id;
|
|
811
|
+
const productId = subscriptionItemProductId(first);
|
|
815
812
|
if (!productId) return null;
|
|
816
813
|
return plans.list.find((plan) => plan.productId === productId)?.name ?? null;
|
|
817
814
|
}
|
|
@@ -885,12 +882,13 @@ async function handleInvoiceCompleted(ctx, payload, client, _plans, callbacks) {
|
|
|
885
882
|
}
|
|
886
883
|
const existing = await findSubscriptionByStreampayId(ctx, subscriptionId);
|
|
887
884
|
if (!existing) return;
|
|
885
|
+
const projected = projectSubscriptionFields(stream);
|
|
888
886
|
const updated = await ctx.context.adapter.update({
|
|
889
887
|
model: SUBSCRIPTION_MODEL,
|
|
890
|
-
update:
|
|
888
|
+
update: projected,
|
|
891
889
|
where: [{ field: "id", value: existing.id }]
|
|
892
890
|
});
|
|
893
|
-
const row = updated ?? { ...existing, ...
|
|
891
|
+
const row = updated ?? { ...existing, ...projected };
|
|
894
892
|
const user = await resolveRowUser(ctx, row);
|
|
895
893
|
await fireCallback(
|
|
896
894
|
ctx,
|
|
@@ -932,9 +930,9 @@ async function dispatchSubscriptionCallback(ctx, payload, data, callbacks) {
|
|
|
932
930
|
}
|
|
933
931
|
function classifyWebhookFailure(err) {
|
|
934
932
|
const { status } = readSdkErrorFields(err);
|
|
935
|
-
if (status
|
|
936
|
-
|
|
937
|
-
|
|
933
|
+
if (status === void 0) return "TRANSIENT";
|
|
934
|
+
if (status === 404 || status === 429) return "TRANSIENT";
|
|
935
|
+
if (status >= 400 && status < 500) return "PERMANENT";
|
|
938
936
|
return "TRANSIENT";
|
|
939
937
|
}
|
|
940
938
|
|
|
@@ -1165,14 +1163,6 @@ function buildSubscriptionsEndpoints(client, adminOptions) {
|
|
|
1165
1163
|
}
|
|
1166
1164
|
}
|
|
1167
1165
|
),
|
|
1168
|
-
/**
|
|
1169
|
-
* Immediate cancel from admin. Unlike the consumer `/subscription/cancel`,
|
|
1170
|
-
* this one bypasses the local ownership check — an admin can cancel
|
|
1171
|
-
* any subscription by StreamPay id. Mirrors the SDK's
|
|
1172
|
-
* `SubscriptionCancel` body shape verbatim (only
|
|
1173
|
-
* `cancel_related_invoices`; no period-end flag — StreamPay doesn't
|
|
1174
|
-
* expose one on this endpoint).
|
|
1175
|
-
*/
|
|
1176
1166
|
adminCancelSubscription: api.createAuthEndpoint(
|
|
1177
1167
|
"/admin/streampay/subscriptions/:id/cancel",
|
|
1178
1168
|
{
|
|
@@ -1205,11 +1195,6 @@ function buildSubscriptionsEndpoints(client, adminOptions) {
|
|
|
1205
1195
|
}
|
|
1206
1196
|
}
|
|
1207
1197
|
),
|
|
1208
|
-
/**
|
|
1209
|
-
* Admin-initiated freeze. Creates a new freeze window on a
|
|
1210
|
-
* subscription. Body matches `FreezeSubscriptionCreateRequest`
|
|
1211
|
-
* from the SDK. Returns the created `FreezeSubscriptionBase`.
|
|
1212
|
-
*/
|
|
1213
1198
|
adminFreezeSubscription: api.createAuthEndpoint(
|
|
1214
1199
|
"/admin/streampay/subscriptions/:id/freeze",
|
|
1215
1200
|
{
|
|
@@ -1243,12 +1228,6 @@ function buildSubscriptionsEndpoints(client, adminOptions) {
|
|
|
1243
1228
|
}
|
|
1244
1229
|
}
|
|
1245
1230
|
),
|
|
1246
|
-
/**
|
|
1247
|
-
* List all freeze windows attached to a subscription. Useful for
|
|
1248
|
-
* UIs that show "this sub is frozen X times" or for the
|
|
1249
|
-
* adminDeleteFreeze / adminUpdateFreeze flows below that need a
|
|
1250
|
-
* freeze id.
|
|
1251
|
-
*/
|
|
1252
1231
|
adminListSubscriptionFreezes: api.createAuthEndpoint(
|
|
1253
1232
|
"/admin/streampay/subscriptions/:id/freeze",
|
|
1254
1233
|
{
|
|
@@ -1269,13 +1248,6 @@ function buildSubscriptionsEndpoints(client, adminOptions) {
|
|
|
1269
1248
|
}
|
|
1270
1249
|
}
|
|
1271
1250
|
),
|
|
1272
|
-
/**
|
|
1273
|
-
* Update an existing freeze window (shift start/end, change notes).
|
|
1274
|
-
* Matches SDK's `updateSubscriptionFreeze` which takes
|
|
1275
|
-
* `FreezeSubscriptionUpdateRequest` — note that
|
|
1276
|
-
* `freeze_start_datetime` is REQUIRED on update even if it doesn't
|
|
1277
|
-
* change (per OpenAPI schema).
|
|
1278
|
-
*/
|
|
1279
1251
|
adminUpdateSubscriptionFreeze: api.createAuthEndpoint(
|
|
1280
1252
|
"/admin/streampay/subscriptions/:id/freeze/:freezeId",
|
|
1281
1253
|
{
|
|
@@ -1309,15 +1281,6 @@ function buildSubscriptionsEndpoints(client, adminOptions) {
|
|
|
1309
1281
|
}
|
|
1310
1282
|
}
|
|
1311
1283
|
),
|
|
1312
|
-
/**
|
|
1313
|
-
* Delete (unfreeze) a specific freeze window. This is how you
|
|
1314
|
-
* "unfreeze" as an admin: find the active freeze id via
|
|
1315
|
-
* adminListSubscriptionFreezes, then DELETE it.
|
|
1316
|
-
*
|
|
1317
|
-
* Returns `{ deleted: true }` on success — the SDK's
|
|
1318
|
-
* `deleteSubscriptionFreeze` returns `void`, so we synthesize a
|
|
1319
|
-
* response body for client feedback.
|
|
1320
|
-
*/
|
|
1321
1284
|
adminDeleteSubscriptionFreeze: api.createAuthEndpoint(
|
|
1322
1285
|
"/admin/streampay/subscriptions/:id/freeze/:freezeId",
|
|
1323
1286
|
{
|
|
@@ -1418,9 +1381,6 @@ function buildConsumersEndpoints(client, adminOptions) {
|
|
|
1418
1381
|
}
|
|
1419
1382
|
}
|
|
1420
1383
|
),
|
|
1421
|
-
// Delete on StreamPay AND clear the `streampayConsumerId` link so
|
|
1422
|
-
// the next checkout lazy-creates instead of 404'ing. deleteConsumer
|
|
1423
|
-
// 404 is treated as success (race); a failed link-clear only logs.
|
|
1424
1384
|
adminDeleteConsumer: api.createAuthEndpoint(
|
|
1425
1385
|
"/admin/streampay/consumers/:id",
|
|
1426
1386
|
{
|
|
@@ -1912,7 +1872,6 @@ var CheckoutBody = zod.z.object({
|
|
|
1912
1872
|
]).optional(),
|
|
1913
1873
|
slug: zod.z.string().optional(),
|
|
1914
1874
|
referenceId: zod.z.string().optional(),
|
|
1915
|
-
consumerId: zod.z.string().uuid().optional(),
|
|
1916
1875
|
name: zod.z.string().min(1).optional(),
|
|
1917
1876
|
description: zod.z.string().optional(),
|
|
1918
1877
|
metadata: zod.z.record(zod.z.string(), zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean()])).optional(),
|
|
@@ -1954,8 +1913,7 @@ function resolveRedirectUrl(urlOrPath, request, baseURL) {
|
|
|
1954
1913
|
if (!urlOrPath) return void 0;
|
|
1955
1914
|
return new URL(urlOrPath, request?.url ?? baseURL).toString();
|
|
1956
1915
|
}
|
|
1957
|
-
async function resolveConsumerId(options, ctx,
|
|
1958
|
-
if (body.consumerId) return body.consumerId;
|
|
1916
|
+
async function resolveConsumerId(options, ctx, user) {
|
|
1959
1917
|
if (!user || user.isAnonymous) return null;
|
|
1960
1918
|
const { consumerId } = await ensureConsumerForUser(options, ctx, user);
|
|
1961
1919
|
return consumerId;
|
|
@@ -1986,7 +1944,7 @@ var checkout = (checkoutOptions = {}) => (options) => {
|
|
|
1986
1944
|
}
|
|
1987
1945
|
}
|
|
1988
1946
|
const items = await resolveProducts(ctx.body, checkoutOptions);
|
|
1989
|
-
const consumerId = await resolveConsumerId(options, ctx,
|
|
1947
|
+
const consumerId = await resolveConsumerId(options, ctx, sessionUser);
|
|
1990
1948
|
const successUrl = resolveRedirectUrl(
|
|
1991
1949
|
ctx.body.successUrl ?? checkoutOptions.successUrl,
|
|
1992
1950
|
ctx.request,
|
|
@@ -2223,33 +2181,10 @@ var SuccessQuery = zod.z.object({
|
|
|
2223
2181
|
var CancelBody = zod.z.object({
|
|
2224
2182
|
subscriptionId: zod.z.string().uuid(),
|
|
2225
2183
|
cancelRelatedInvoices: zod.z.boolean().optional(),
|
|
2226
|
-
/**
|
|
2227
|
-
* When `true`, schedule the cancellation to take effect at the end
|
|
2228
|
-
* of the current billing period instead of terminating immediately.
|
|
2229
|
-
* Implemented via StreamPay's `PATCH /subscriptions/:id` with
|
|
2230
|
-
* `until_cycle_number = current_cycle_number` (see OpenAPI
|
|
2231
|
-
* `SubscriptionUpdate.until_cycle_number`). The customer retains
|
|
2232
|
-
* access through `periodEnd`; status stays `active` until the
|
|
2233
|
-
* `SUBSCRIPTION_CANCEL_AT_PERIOD_END` webhook lands.
|
|
2234
|
-
*/
|
|
2235
2184
|
cancelAtPeriodEnd: zod.z.boolean().optional()
|
|
2236
2185
|
});
|
|
2237
2186
|
var ChangePlanBody = zod.z.object({
|
|
2238
|
-
/** Target plan name, must be declared in `subscriptions({ plans })`. */
|
|
2239
2187
|
plan: zod.z.string().min(1),
|
|
2240
|
-
/**
|
|
2241
|
-
* `at_period_end` (default) — old plan keeps serving until
|
|
2242
|
-
* `periodEnd`, then the new plan's payment link is presented via a
|
|
2243
|
-
* freshly spawned `incomplete` row. Safer. Customer pays only what
|
|
2244
|
-
* they would on a normal renewal cycle.
|
|
2245
|
-
*
|
|
2246
|
-
* `immediate` — PATCH the existing StreamPay subscription's items
|
|
2247
|
-
* to the new plan's productId. No proration — StreamPay does not
|
|
2248
|
-
* expose proration on PATCH. The current cycle's paid invoice is
|
|
2249
|
-
* NOT refunded; the customer starts paying the new price from the
|
|
2250
|
-
* next cycle. Use for "upgrade now, I'll pay more later" UX where
|
|
2251
|
-
* proration is acceptable.
|
|
2252
|
-
*/
|
|
2253
2188
|
mode: zod.z.enum(["at_period_end", "immediate"]).optional(),
|
|
2254
2189
|
successUrl: zod.z.string().url().optional(),
|
|
2255
2190
|
failureUrl: zod.z.string().url().optional()
|
|
@@ -2493,12 +2428,17 @@ function buildSubscriptionEndpoints(options, subsOptions, plansRef) {
|
|
|
2493
2428
|
return ctx.json({ subscription: row, synced: false });
|
|
2494
2429
|
}
|
|
2495
2430
|
try {
|
|
2431
|
+
const plans = await plansRef();
|
|
2432
|
+
const plan = plans.byName.get(row.plan);
|
|
2433
|
+
if (!plan) {
|
|
2434
|
+
getLogger(ctx).warn(
|
|
2435
|
+
`subscriptionSuccess: plan "${row.plan}" is no longer configured \u2014 skipping fallback sync for row=${row.id}.`
|
|
2436
|
+
);
|
|
2437
|
+
return ctx.json({ subscription: row, synced: false });
|
|
2438
|
+
}
|
|
2496
2439
|
const list = await client.listSubscriptions({ page: 1, size: 100 });
|
|
2497
2440
|
const match = list.data?.find(
|
|
2498
|
-
(sub) => sub.organization_consumer_id === row.streampayConsumerId && Array.isArray(sub.items) && sub.items.some((item) =>
|
|
2499
|
-
const productId = typeof item === "object" && item && "product" in item && item.product && typeof item.product === "object" && "id" in item.product ? item.product.id : typeof item === "object" && item && "product_id" in item ? item.product_id : null;
|
|
2500
|
-
return typeof productId === "string" && productId.length > 0 && row.plan && sub.status !== "CANCELED";
|
|
2501
|
-
})
|
|
2441
|
+
(sub) => sub.organization_consumer_id === row.streampayConsumerId && sub.status !== "CANCELED" && Array.isArray(sub.items) && sub.items.some((item) => subscriptionItemProductId(item) === plan.productId)
|
|
2502
2442
|
);
|
|
2503
2443
|
if (!match?.id) {
|
|
2504
2444
|
return ctx.json({ subscription: row, synced: false });
|
|
@@ -2936,23 +2876,6 @@ function buildSubscriptionEndpoints(options, subsOptions, plansRef) {
|
|
|
2936
2876
|
);
|
|
2937
2877
|
}
|
|
2938
2878
|
),
|
|
2939
|
-
/**
|
|
2940
|
-
* Returns the user's current billable subscription, or `null` if
|
|
2941
|
-
* none. **Intentionally filters out `incomplete`, `canceled`,
|
|
2942
|
-
* `expired`, and `inactive` rows** — only `active | frozen |
|
|
2943
|
-
* past_due` are surfaced, since those are the statuses that
|
|
2944
|
-
* represent a *live* entitlement.
|
|
2945
|
-
*
|
|
2946
|
-
* Notable consequence: between `/subscription/upgrade` (creates
|
|
2947
|
-
* an `incomplete` row + payment link) and the
|
|
2948
|
-
* `SUBSCRIPTION_ACTIVATED` webhook landing, this endpoint
|
|
2949
|
-
* returns `null`. If you want to render "your subscription is
|
|
2950
|
-
* being activated" during that window, call `/subscription/list`
|
|
2951
|
-
* and filter for `status === "incomplete"` yourself.
|
|
2952
|
-
*
|
|
2953
|
-
* Pass `?group=<name>` to scope to a single plan group when the
|
|
2954
|
-
* app declares multiple concurrent subscriptions per user.
|
|
2955
|
-
*/
|
|
2956
2879
|
currentSubscription: api.createAuthEndpoint(
|
|
2957
2880
|
"/subscription/current",
|
|
2958
2881
|
{
|
|
@@ -3122,14 +3045,11 @@ var webhookEventTable = {
|
|
|
3122
3045
|
type: "string",
|
|
3123
3046
|
required: true
|
|
3124
3047
|
},
|
|
3125
|
-
/** Last activity (insert/retry/completion/dead-letter).
|
|
3126
|
-
* For `completed` = finished-at; for `pending` = last attempt. */
|
|
3127
3048
|
processedAt: {
|
|
3128
3049
|
type: "date",
|
|
3129
3050
|
required: true,
|
|
3130
3051
|
index: true
|
|
3131
3052
|
},
|
|
3132
|
-
/** Defaults to `completed` so pre-state-machine rows still dedupe. */
|
|
3133
3053
|
status: {
|
|
3134
3054
|
type: "string",
|
|
3135
3055
|
required: false,
|
|
@@ -3258,7 +3178,6 @@ function subscriptions(subsOptions) {
|
|
|
3258
3178
|
async function dispatchWebhook(payload, handlers) {
|
|
3259
3179
|
if (handlers.onPayload) await handlers.onPayload(payload);
|
|
3260
3180
|
switch (payload.event_type) {
|
|
3261
|
-
// Payment
|
|
3262
3181
|
case "PAYMENT_SUCCEEDED":
|
|
3263
3182
|
await handlers.onPaymentSucceeded?.(payload);
|
|
3264
3183
|
return;
|
|
@@ -3274,7 +3193,6 @@ async function dispatchWebhook(payload, handlers) {
|
|
|
3274
3193
|
case "PAYMENT_MARKED_AS_PAID":
|
|
3275
3194
|
await handlers.onPaymentMarkedAsPaid?.(payload);
|
|
3276
3195
|
return;
|
|
3277
|
-
// Invoice
|
|
3278
3196
|
case "INVOICE_CREATED":
|
|
3279
3197
|
await handlers.onInvoiceCreated?.(payload);
|
|
3280
3198
|
return;
|
|
@@ -3296,7 +3214,6 @@ async function dispatchWebhook(payload, handlers) {
|
|
|
3296
3214
|
case "INVOICE_UPDATED":
|
|
3297
3215
|
await handlers.onInvoiceUpdated?.(payload);
|
|
3298
3216
|
return;
|
|
3299
|
-
// Subscription
|
|
3300
3217
|
case "SUBSCRIPTION_CREATED":
|
|
3301
3218
|
await handlers.onSubscriptionCreated?.(payload);
|
|
3302
3219
|
return;
|
|
@@ -3330,7 +3247,6 @@ async function dispatchWebhook(payload, handlers) {
|
|
|
3330
3247
|
case "SUBSCRIPTION_FREEZE_CANCEL":
|
|
3331
3248
|
await handlers.onSubscriptionFreezeCancel?.(payload);
|
|
3332
3249
|
return;
|
|
3333
|
-
// Payment Link
|
|
3334
3250
|
case "PAYMENT_LINK_PAY_ATTEMPT_FAILED":
|
|
3335
3251
|
await handlers.onPaymentLinkPayAttemptFailed?.(payload);
|
|
3336
3252
|
return;
|
|
@@ -3600,7 +3516,7 @@ var onUserDelete = (options) => async (user, context) => {
|
|
|
3600
3516
|
|
|
3601
3517
|
// package.json
|
|
3602
3518
|
var package_default = {
|
|
3603
|
-
version: "1.
|
|
3519
|
+
version: "1.3.0"};
|
|
3604
3520
|
|
|
3605
3521
|
// src/version.ts
|
|
3606
3522
|
var version = package_default.version;
|