@surgent-dev/surpay-convex 0.1.0 → 0.1.2
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 +35 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +12 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -4
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +22 -9
- package/src/types.ts +12 -4
package/README.md
CHANGED
|
@@ -17,10 +17,19 @@ import { Surpay } from "@surgent-dev/surpay-convex";
|
|
|
17
17
|
|
|
18
18
|
const surpay = new Surpay({
|
|
19
19
|
apiKey: process.env.SURPAY_API_KEY!,
|
|
20
|
+
identify: async (ctx) => {
|
|
21
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
22
|
+
if (!identity) return null;
|
|
23
|
+
return {
|
|
24
|
+
customerId: identity.subject,
|
|
25
|
+
customerData: { name: identity.name, email: identity.email },
|
|
26
|
+
};
|
|
27
|
+
},
|
|
20
28
|
});
|
|
21
29
|
|
|
22
30
|
export const {
|
|
23
31
|
createCheckout,
|
|
32
|
+
check,
|
|
24
33
|
getCustomer,
|
|
25
34
|
listCustomers,
|
|
26
35
|
listSubscriptions,
|
|
@@ -53,6 +62,20 @@ if (error) {
|
|
|
53
62
|
}
|
|
54
63
|
```
|
|
55
64
|
|
|
65
|
+
### Check Access
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { api } from "./_generated/api";
|
|
69
|
+
|
|
70
|
+
const { data, error } = await ctx.runAction(api.surpay.check, {
|
|
71
|
+
product_id: "prod_123",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (data?.allowed) {
|
|
75
|
+
// Allow access
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
56
79
|
### Get Customer
|
|
57
80
|
|
|
58
81
|
```typescript
|
|
@@ -64,6 +87,16 @@ const { data, error } = await ctx.runAction(api.surpay.getCustomer, {
|
|
|
64
87
|
});
|
|
65
88
|
```
|
|
66
89
|
|
|
90
|
+
### List Customers
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { api } from "./_generated/api";
|
|
94
|
+
|
|
95
|
+
const { data, error } = await ctx.runAction(api.surpay.listCustomers, {
|
|
96
|
+
project_id: "proj_123",
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
67
100
|
### List Subscriptions
|
|
68
101
|
|
|
69
102
|
```typescript
|
|
@@ -78,7 +111,8 @@ const { data, error } = await ctx.runAction(api.surpay.listSubscriptions, {
|
|
|
78
111
|
|
|
79
112
|
| Action | Args | Returns |
|
|
80
113
|
|--------|------|---------|
|
|
81
|
-
| `createCheckout` | `product_id`, `price_id
|
|
114
|
+
| `createCheckout` | `product_id`, `price_id?`, `success_url?`, `cancel_url?` | `{ checkout_url: string, customer_id: string }` |
|
|
115
|
+
| `check` | `product_id` | `{ allowed: boolean }` |
|
|
82
116
|
| `getCustomer` | `project_id`, `customer_id` | `CustomerWithDetails` |
|
|
83
117
|
| `listCustomers` | `project_id` | `Customer[]` |
|
|
84
118
|
| `listSubscriptions` | `project_id` | `Subscription[]` |
|
package/dist/index.d.ts
CHANGED
|
@@ -29,10 +29,10 @@ export declare class Surpay {
|
|
|
29
29
|
}>;
|
|
30
30
|
api(): {
|
|
31
31
|
createCheckout: import("convex/server").RegisteredAction<"public", {
|
|
32
|
+
price_id?: string | undefined;
|
|
33
|
+
success_url?: string | undefined;
|
|
34
|
+
cancel_url?: string | undefined;
|
|
32
35
|
product_id: string;
|
|
33
|
-
price_id: string;
|
|
34
|
-
success_url: string;
|
|
35
|
-
cancel_url: string;
|
|
36
36
|
}, Promise<{
|
|
37
37
|
data: null;
|
|
38
38
|
error: PlainError;
|
|
@@ -40,6 +40,15 @@ export declare class Surpay {
|
|
|
40
40
|
data: import("@surgent-dev/surpay").CreateCheckoutResponse;
|
|
41
41
|
error: null;
|
|
42
42
|
}>>;
|
|
43
|
+
check: import("convex/server").RegisteredAction<"public", {
|
|
44
|
+
product_id: string;
|
|
45
|
+
}, Promise<{
|
|
46
|
+
data: null;
|
|
47
|
+
error: PlainError;
|
|
48
|
+
} | {
|
|
49
|
+
data: import("@surgent-dev/surpay").CheckResponse;
|
|
50
|
+
error: null;
|
|
51
|
+
}>>;
|
|
43
52
|
getCustomer: import("convex/server").RegisteredAction<"public", {
|
|
44
53
|
project_id: string;
|
|
45
54
|
customer_id: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAS7D,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CACxD,CAAC;AAGF,KAAK,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAwBrD,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,EAAE,YAAY;IAU1B,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAI3D,aAAa,CAAC,EAClB,GAAG,EACH,WAAkB,GACnB,EAAE;QACD,GAAG,EAAE,GAAG,CAAC;QACT,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAA;KAAE,CAAC;IAQ5E,GAAG;;;;;;;kBA5CyC,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;CAqGhC;AAED,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { actionGeneric } from "convex/server";
|
|
26
26
|
import { Surpay as SurpayClient } from "@surgent-dev/surpay";
|
|
27
|
-
import { CreateCheckoutArgs, GetCustomerArgs, ListCustomersArgs, ListSubscriptionsArgs, } from "./types.js";
|
|
27
|
+
import { CreateCheckoutArgs, CheckArgs, GetCustomerArgs, ListCustomersArgs, ListSubscriptionsArgs, } from "./types.js";
|
|
28
28
|
function toPlainError(error) {
|
|
29
29
|
if (error instanceof Error) {
|
|
30
30
|
return { message: error.message, code: error.code };
|
|
@@ -49,9 +49,11 @@ export class Surpay {
|
|
|
49
49
|
options;
|
|
50
50
|
constructor(config) {
|
|
51
51
|
this.options = config;
|
|
52
|
+
const g = globalThis;
|
|
53
|
+
const envBaseUrl = g.process?.env.SURPAY_BASE_URL;
|
|
52
54
|
this.client = new SurpayClient({
|
|
53
55
|
apiKey: config.apiKey,
|
|
54
|
-
baseUrl: config.baseUrl,
|
|
56
|
+
baseUrl: config.baseUrl ?? envBaseUrl,
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
async getIdentifierOpts(ctx) {
|
|
@@ -70,14 +72,21 @@ export class Surpay {
|
|
|
70
72
|
args: CreateCheckoutArgs,
|
|
71
73
|
handler: async (ctx, args) => {
|
|
72
74
|
const { client, identifierOpts } = await this.getAuthParams({ ctx });
|
|
73
|
-
|
|
74
|
-
const checkoutParams = {
|
|
75
|
+
return wrapSdkCall(() => client.checkout.create({
|
|
75
76
|
...args,
|
|
76
77
|
customer_id: identifierOpts.customerId,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
customer_data: identifierOpts.customerData,
|
|
79
|
+
}));
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
check: actionGeneric({
|
|
83
|
+
args: CheckArgs,
|
|
84
|
+
handler: async (ctx, args) => {
|
|
85
|
+
const { client, identifierOpts } = await this.getAuthParams({ ctx });
|
|
86
|
+
return wrapSdkCall(() => client.check({
|
|
87
|
+
product_id: args.product_id,
|
|
88
|
+
customer_id: identifierOpts.customerId,
|
|
89
|
+
}));
|
|
81
90
|
},
|
|
82
91
|
}),
|
|
83
92
|
getCustomer: actionGeneric({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAgBpB,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,YAAY,KAAK,EA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ANGED
|
@@ -3,17 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Infer } from "convex/values";
|
|
5
5
|
export declare const CreateCheckoutArgs: import("convex/values").VObject<{
|
|
6
|
+
price_id?: string | undefined;
|
|
7
|
+
success_url?: string | undefined;
|
|
8
|
+
cancel_url?: string | undefined;
|
|
6
9
|
product_id: string;
|
|
7
|
-
price_id: string;
|
|
8
|
-
success_url: string;
|
|
9
|
-
cancel_url: string;
|
|
10
10
|
}, {
|
|
11
11
|
product_id: import("convex/values").VString<string, "required">;
|
|
12
|
-
price_id: import("convex/values").VString<string, "
|
|
13
|
-
success_url: import("convex/values").VString<string, "
|
|
14
|
-
cancel_url: import("convex/values").VString<string, "
|
|
12
|
+
price_id: import("convex/values").VString<string | undefined, "optional">;
|
|
13
|
+
success_url: import("convex/values").VString<string | undefined, "optional">;
|
|
14
|
+
cancel_url: import("convex/values").VString<string | undefined, "optional">;
|
|
15
15
|
}, "required", "product_id" | "price_id" | "success_url" | "cancel_url">;
|
|
16
16
|
export type CreateCheckoutArgs = Infer<typeof CreateCheckoutArgs>;
|
|
17
|
+
export declare const CheckArgs: import("convex/values").VObject<{
|
|
18
|
+
product_id: string;
|
|
19
|
+
}, {
|
|
20
|
+
product_id: import("convex/values").VString<string, "required">;
|
|
21
|
+
}, "required", "product_id">;
|
|
22
|
+
export type CheckArgs = Infer<typeof CheckArgs>;
|
|
17
23
|
export declare const ListSubscriptionsArgs: import("convex/values").VObject<{
|
|
18
24
|
project_id: string;
|
|
19
25
|
}, {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAK,KAAK,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAIzC,eAAO,MAAM,kBAAkB;;;;;;;;;;wEAK7B,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIlE,eAAO,MAAM,SAAS;;;;4BAEpB,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAGhD,eAAO,MAAM,qBAAqB;;;;4BAEhC,CAAC;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAGxE,eAAO,MAAM,eAAe;;;;;;4CAG1B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAG5D,eAAO,MAAM,iBAAiB;;;;4BAE5B,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
* Convex validators for Surpay action arguments
|
|
3
3
|
*/
|
|
4
4
|
import { v } from "convex/values";
|
|
5
|
-
//
|
|
5
|
+
// CreateCheckoutArgs: product_id required, price_id/URLs optional
|
|
6
|
+
// Note: customer_id is NOT here - it's injected by the wrapper via identify()
|
|
6
7
|
export const CreateCheckoutArgs = v.object({
|
|
7
8
|
product_id: v.string(),
|
|
8
|
-
price_id: v.string(),
|
|
9
|
-
success_url: v.string(),
|
|
10
|
-
cancel_url: v.string(),
|
|
9
|
+
price_id: v.optional(v.string()),
|
|
10
|
+
success_url: v.optional(v.string()),
|
|
11
|
+
cancel_url: v.optional(v.string()),
|
|
12
|
+
});
|
|
13
|
+
// CheckArgs: product_id required
|
|
14
|
+
// Note: customer_id is NOT here - it's injected by the wrapper via identify()
|
|
15
|
+
export const CheckArgs = v.object({
|
|
16
|
+
product_id: v.string(),
|
|
11
17
|
});
|
|
12
18
|
// ListSubscriptions: requires project_id
|
|
13
19
|
export const ListSubscriptionsArgs = v.object({
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAS,MAAM,eAAe,CAAC;AAEzC,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAS,MAAM,eAAe,CAAC;AAEzC,kEAAkE;AAClE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAChC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACnC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CACnC,CAAC,CAAC;AAGH,iCAAiC;AACjC,8EAA8E;AAC9E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAGH,yCAAyC;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAGH,mDAAmD;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAGH,qCAAqC;AACrC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { actionGeneric } from "convex/server";
|
|
|
26
26
|
import { Surpay as SurpayClient } from "@surgent-dev/surpay";
|
|
27
27
|
import {
|
|
28
28
|
CreateCheckoutArgs,
|
|
29
|
+
CheckArgs,
|
|
29
30
|
GetCustomerArgs,
|
|
30
31
|
ListCustomersArgs,
|
|
31
32
|
ListSubscriptionsArgs,
|
|
@@ -73,9 +74,11 @@ export class Surpay {
|
|
|
73
74
|
|
|
74
75
|
constructor(config: SurpayConfig) {
|
|
75
76
|
this.options = config;
|
|
77
|
+
const g = globalThis as { process?: { env: Record<string, string | undefined> } };
|
|
78
|
+
const envBaseUrl = g.process?.env.SURPAY_BASE_URL;
|
|
76
79
|
this.client = new SurpayClient({
|
|
77
80
|
apiKey: config.apiKey,
|
|
78
|
-
baseUrl: config.baseUrl,
|
|
81
|
+
baseUrl: config.baseUrl ?? envBaseUrl,
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
|
|
@@ -103,15 +106,25 @@ export class Surpay {
|
|
|
103
106
|
args: CreateCheckoutArgs,
|
|
104
107
|
handler: async (ctx, args) => {
|
|
105
108
|
const { client, identifierOpts } = await this.getAuthParams({ ctx });
|
|
106
|
-
// Merge customer info from auth context with checkout args
|
|
107
|
-
const checkoutParams = {
|
|
108
|
-
...args,
|
|
109
|
-
customer_id: identifierOpts!.customerId,
|
|
110
|
-
customer_name: identifierOpts!.customerData?.name,
|
|
111
|
-
customer_email: identifierOpts!.customerData?.email,
|
|
112
|
-
};
|
|
113
109
|
return wrapSdkCall(() =>
|
|
114
|
-
client.checkout.create(
|
|
110
|
+
client.checkout.create({
|
|
111
|
+
...args,
|
|
112
|
+
customer_id: identifierOpts!.customerId,
|
|
113
|
+
customer_data: identifierOpts!.customerData,
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
|
|
119
|
+
check: actionGeneric({
|
|
120
|
+
args: CheckArgs,
|
|
121
|
+
handler: async (ctx, args) => {
|
|
122
|
+
const { client, identifierOpts } = await this.getAuthParams({ ctx });
|
|
123
|
+
return wrapSdkCall(() =>
|
|
124
|
+
client.check({
|
|
125
|
+
product_id: args.product_id,
|
|
126
|
+
customer_id: identifierOpts!.customerId,
|
|
127
|
+
})
|
|
115
128
|
);
|
|
116
129
|
},
|
|
117
130
|
}),
|
package/src/types.ts
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { v, Infer } from "convex/values";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// CreateCheckoutArgs: product_id required, price_id/URLs optional
|
|
7
|
+
// Note: customer_id is NOT here - it's injected by the wrapper via identify()
|
|
7
8
|
export const CreateCheckoutArgs = v.object({
|
|
8
9
|
product_id: v.string(),
|
|
9
|
-
price_id: v.string(),
|
|
10
|
-
success_url: v.string(),
|
|
11
|
-
cancel_url: v.string(),
|
|
10
|
+
price_id: v.optional(v.string()),
|
|
11
|
+
success_url: v.optional(v.string()),
|
|
12
|
+
cancel_url: v.optional(v.string()),
|
|
12
13
|
});
|
|
13
14
|
export type CreateCheckoutArgs = Infer<typeof CreateCheckoutArgs>;
|
|
14
15
|
|
|
16
|
+
// CheckArgs: product_id required
|
|
17
|
+
// Note: customer_id is NOT here - it's injected by the wrapper via identify()
|
|
18
|
+
export const CheckArgs = v.object({
|
|
19
|
+
product_id: v.string(),
|
|
20
|
+
});
|
|
21
|
+
export type CheckArgs = Infer<typeof CheckArgs>;
|
|
22
|
+
|
|
15
23
|
// ListSubscriptions: requires project_id
|
|
16
24
|
export const ListSubscriptionsArgs = v.object({
|
|
17
25
|
project_id: v.string(),
|