@surgent-dev/surpay-convex 0.1.4 → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # @surgent-dev/surpay-convex
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 809165a: Updated requirement of project ID across a lot of APIs, also deleted some unused ones.
8
+
9
+ ### Patch Changes
10
+
11
+ - 809165a: Improve SDK reliability and type safety
12
+
13
+ - Add configurable request timeouts (30s default) with AbortController
14
+ - Catch network errors and return as Result failures instead of throwing
15
+ - Handle invalid JSON responses gracefully
16
+ - Add proper generics for Convex auth context (removes `any` types)
17
+ - Fix examples and documentation to match current API
18
+
19
+ - Updated dependencies [809165a]
20
+ - Updated dependencies [809165a]
21
+ - @surgent-dev/surpay@0.2.0
package/README.md CHANGED
@@ -50,6 +50,7 @@ import { api } from "./_generated/api";
50
50
  // Inside a Convex action or from client
51
51
  const { data, error } = await ctx.runAction(api.surpay.createCheckout, {
52
52
  product_id: "prod_123",
53
+ customer_id: "cust_123", // Optional if using identify()
53
54
  price_id: "price_123",
54
55
  success_url: "https://example.com/success",
55
56
  cancel_url: "https://example.com/cancel",
@@ -69,6 +70,7 @@ import { api } from "./_generated/api";
69
70
 
70
71
  const { data, error } = await ctx.runAction(api.surpay.check, {
71
72
  product_id: "prod_123",
73
+ customer_id: "cust_123", // Optional if using identify()
72
74
  });
73
75
 
74
76
  if (data?.allowed) {
@@ -82,7 +84,6 @@ if (data?.allowed) {
82
84
  import { api } from "./_generated/api";
83
85
 
84
86
  const { data, error } = await ctx.runAction(api.surpay.getCustomer, {
85
- project_id: "proj_123",
86
87
  customer_id: "cust_123",
87
88
  });
88
89
  ```
@@ -92,9 +93,7 @@ const { data, error } = await ctx.runAction(api.surpay.getCustomer, {
92
93
  ```typescript
93
94
  import { api } from "./_generated/api";
94
95
 
95
- const { data, error } = await ctx.runAction(api.surpay.listCustomers, {
96
- project_id: "proj_123",
97
- });
96
+ const { data, error } = await ctx.runAction(api.surpay.listCustomers, {});
98
97
  ```
99
98
 
100
99
  ### List Subscriptions
@@ -102,17 +101,15 @@ const { data, error } = await ctx.runAction(api.surpay.listCustomers, {
102
101
  ```typescript
103
102
  import { api } from "./_generated/api";
104
103
 
105
- const { data, error } = await ctx.runAction(api.surpay.listSubscriptions, {
106
- project_id: "proj_123",
107
- });
104
+ const { data, error } = await ctx.runAction(api.surpay.listSubscriptions, {});
108
105
  ```
109
106
 
110
107
  ## API Reference
111
108
 
112
109
  | Action | Args | Returns |
113
110
  |--------|------|---------|
114
- | `createCheckout` | `product_id`, `price_id?`, `success_url?`, `cancel_url?` | `{ checkout_url: string, customer_id: string }` |
115
- | `check` | `product_id` | `{ allowed: boolean }` |
116
- | `getCustomer` | `project_id`, `customer_id` | `CustomerWithDetails` |
117
- | `listCustomers` | `project_id` | `Customer[]` |
118
- | `listSubscriptions` | `project_id` | `Subscription[]` |
111
+ | `createCheckout` | `product_id`, `customer_id?`, `price_id?`, `success_url?`, `cancel_url?` | `{ checkout_url: string, customer_id: string }` |
112
+ | `check` | `product_id`, `customer_id?` | `{ allowed: boolean }` |
113
+ | `getCustomer` | `customer_id` | `CustomerWithDetails` |
114
+ | `listCustomers` | - | `Customer[]` |
115
+ | `listSubscriptions` | - | `Subscription[]` |
package/dist/index.d.ts CHANGED
@@ -1,3 +1,28 @@
1
+ /**
2
+ * Surpay Convex Integration
3
+ *
4
+ * Provides Convex actions that wrap the Surpay SDK with auth context support.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * // convex/surpay.ts
9
+ * import { Surpay } from "@surgent-dev/surpay-convex";
10
+ *
11
+ * const surpay = new Surpay({
12
+ * apiKey: process.env.SURPAY_API_KEY!,
13
+ * identify: async (ctx) => {
14
+ * const identity = await ctx.auth.getUserIdentity();
15
+ * if (!identity) return null;
16
+ * return {
17
+ * customerId: identity.subject,
18
+ * customerData: { name: identity.name, email: identity.email },
19
+ * };
20
+ * },
21
+ * });
22
+ * export const { createCheckout, getCustomer, listCustomers, listSubscriptions } = surpay.api();
23
+ * ```
24
+ */
25
+ import { GenericActionCtx } from "convex/server";
1
26
  import { Surpay as SurpayClient, ResponseCase } from "@surgent-dev/surpay";
2
27
  export type IdentifierOpts = {
3
28
  customerId: string;
@@ -6,7 +31,7 @@ export type IdentifierOpts = {
6
31
  email?: string;
7
32
  };
8
33
  };
9
- export type SurpayConfig = {
34
+ export type SurpayConfig<Ctx extends GenericActionCtx<any> = GenericActionCtx<any>> = {
10
35
  apiKey: string;
11
36
  baseUrl?: string;
12
37
  /**
@@ -17,19 +42,19 @@ export type SurpayConfig = {
17
42
  * Defaults to 'snake' for Convex validator compatibility.
18
43
  */
19
44
  responseCase?: ResponseCase;
20
- identify: (ctx: any) => Promise<IdentifierOpts | null>;
45
+ identify: (ctx: Ctx) => Promise<IdentifierOpts | null>;
21
46
  };
22
47
  type PlainError = {
23
48
  message: string;
24
49
  code?: string;
25
50
  };
26
- export declare class Surpay {
51
+ export declare class Surpay<Ctx extends GenericActionCtx<any> = GenericActionCtx<any>> {
27
52
  private client;
28
53
  private options;
29
- constructor(config: SurpayConfig);
30
- getIdentifierOpts(ctx: any): Promise<IdentifierOpts | null>;
54
+ constructor(config: SurpayConfig<Ctx>);
55
+ getIdentifierOpts(ctx: Ctx): Promise<IdentifierOpts | null>;
31
56
  getAuthParams({ ctx, requireAuth, }: {
32
- ctx: any;
57
+ ctx: Ctx;
33
58
  requireAuth?: boolean;
34
59
  }): Promise<{
35
60
  client: SurpayClient;
@@ -37,10 +62,10 @@ export declare class Surpay {
37
62
  }>;
38
63
  api(): {
39
64
  createCheckout: import("convex/server").RegisteredAction<"public", {
40
- price_id?: string | undefined;
41
- success_url?: string | undefined;
42
- cancel_url?: string | undefined;
43
- product_id: string;
65
+ priceId?: string | undefined;
66
+ successUrl?: string | undefined;
67
+ cancelUrl?: string | undefined;
68
+ productId: string;
44
69
  }, Promise<{
45
70
  data: null;
46
71
  error: PlainError;
@@ -49,7 +74,7 @@ export declare class Surpay {
49
74
  error: null;
50
75
  }>>;
51
76
  check: import("convex/server").RegisteredAction<"public", {
52
- product_id: string;
77
+ productId: string;
53
78
  }, Promise<{
54
79
  data: null;
55
80
  error: PlainError;
@@ -58,7 +83,6 @@ export declare class Surpay {
58
83
  error: null;
59
84
  }>>;
60
85
  getCustomer: import("convex/server").RegisteredAction<"public", {
61
- project_id: string;
62
86
  customer_id: string;
63
87
  }, Promise<{
64
88
  data: null;
@@ -67,18 +91,14 @@ export declare class Surpay {
67
91
  data: import("@surgent-dev/surpay").CustomerWithDetails;
68
92
  error: null;
69
93
  }>>;
70
- listCustomers: import("convex/server").RegisteredAction<"public", {
71
- project_id: string;
72
- }, Promise<{
94
+ listCustomers: import("convex/server").RegisteredAction<"public", {}, Promise<{
73
95
  data: null;
74
96
  error: PlainError;
75
97
  } | {
76
98
  data: import("@surgent-dev/surpay").Customer[];
77
99
  error: null;
78
100
  }>>;
79
- listSubscriptions: import("convex/server").RegisteredAction<"public", {
80
- project_id: string;
81
- }, Promise<{
101
+ listSubscriptions: import("convex/server").RegisteredAction<"public", {}, Promise<{
82
102
  data: null;
83
103
  error: PlainError;
84
104
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAS3E,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;;;;;;OAMG;IACH,YAA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AAxC,IAAI;;;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;kBAAa,IAAI;mBAAS,UAAU;;;mBAAxC,IAAI;;;CA4GhC;AAED,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@
23
23
  * ```
24
24
  */
25
25
  import { actionGeneric } from "convex/server";
26
- import { Surpay as SurpayClient } from "@surgent-dev/surpay";
26
+ import { Surpay as SurpayClient, camelToSnake } from "@surgent-dev/surpay";
27
27
  import { CreateCheckoutArgs, CheckArgs, GetCustomerArgs, ListCustomersArgs, ListSubscriptionsArgs, } from "./types.js";
28
28
  function toPlainError(error) {
29
29
  if (error instanceof Error) {
@@ -44,6 +44,7 @@ async function wrapSdkCall(fn) {
44
44
  return { data: null, error: toPlainError(e) };
45
45
  }
46
46
  }
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
48
  export class Surpay {
48
49
  client;
49
50
  options;
@@ -73,9 +74,11 @@ export class Surpay {
73
74
  createCheckout: actionGeneric({
74
75
  args: CreateCheckoutArgs,
75
76
  handler: async (ctx, args) => {
76
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
77
+ const { client, identifierOpts } = await this.getAuthParams({ ctx: ctx });
78
+ // Transform camelCase user args to snake_case for API
79
+ const snakeCaseArgs = camelToSnake(args);
77
80
  return wrapSdkCall(() => client.checkout.create({
78
- ...args,
81
+ ...snakeCaseArgs,
79
82
  customer_id: identifierOpts.customerId,
80
83
  customer_data: identifierOpts.customerData,
81
84
  }));
@@ -84,9 +87,9 @@ export class Surpay {
84
87
  check: actionGeneric({
85
88
  args: CheckArgs,
86
89
  handler: async (ctx, args) => {
87
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
90
+ const { client, identifierOpts } = await this.getAuthParams({ ctx: ctx });
88
91
  return wrapSdkCall(() => client.check({
89
- product_id: args.product_id,
92
+ product_id: args.productId,
90
93
  customer_id: identifierOpts.customerId,
91
94
  }));
92
95
  },
@@ -94,23 +97,22 @@ export class Surpay {
94
97
  getCustomer: actionGeneric({
95
98
  args: GetCustomerArgs,
96
99
  handler: async (ctx, args) => {
97
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
98
- const customerId = args.customer_id || identifierOpts.customerId;
99
- return wrapSdkCall(() => client.customers.get(args.project_id, customerId));
100
+ const { client } = await this.getAuthParams({ ctx: ctx, requireAuth: false });
101
+ return wrapSdkCall(() => client.customers.get(args.customer_id));
100
102
  },
101
103
  }),
102
104
  listCustomers: actionGeneric({
103
105
  args: ListCustomersArgs,
104
- handler: async (ctx, args) => {
105
- const { client } = await this.getAuthParams({ ctx });
106
- return wrapSdkCall(() => client.customers.list(args.project_id));
106
+ handler: async (ctx) => {
107
+ const { client } = await this.getAuthParams({ ctx: ctx });
108
+ return wrapSdkCall(() => client.customers.list());
107
109
  },
108
110
  }),
109
111
  listSubscriptions: actionGeneric({
110
112
  args: ListSubscriptionsArgs,
111
- handler: async (ctx, args) => {
112
- const { client } = await this.getAuthParams({ ctx });
113
- return wrapSdkCall(() => client.subscriptions.list(args.project_id));
113
+ handler: async (ctx) => {
114
+ const { client } = await this.getAuthParams({ ctx: ctx });
115
+ return wrapSdkCall(() => client.subscriptions.list());
114
116
  },
115
117
  }),
116
118
  };
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,EAAgB,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAwBpB,SAA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,EAAE,CAAC,CAAC;gBACpD,CAAC;aACF,CAAC;YAEF,iBAAiB,EAAE,aAAa,CAAC;gBAC/B,IAAI,EAAE,qBAAqB;gBAC3B,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;oBACrB,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,GAAU,EAAE,CAAC,CAAC;oBACjE,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;gBACxD,CAAC;aACF,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AAED,cAAc,YAAY,CAAC"}
package/dist/types.d.ts CHANGED
@@ -3,41 +3,31 @@
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;
9
- product_id: string;
6
+ priceId?: string | undefined;
7
+ successUrl?: string | undefined;
8
+ cancelUrl?: string | undefined;
9
+ productId: string;
10
10
  }, {
11
- product_id: import("convex/values").VString<string, "required">;
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
- }, "required", "product_id" | "price_id" | "success_url" | "cancel_url">;
11
+ productId: import("convex/values").VString<string, "required">;
12
+ priceId: import("convex/values").VString<string | undefined, "optional">;
13
+ successUrl: import("convex/values").VString<string | undefined, "optional">;
14
+ cancelUrl: import("convex/values").VString<string | undefined, "optional">;
15
+ }, "required", "productId" | "priceId" | "successUrl" | "cancelUrl">;
16
16
  export type CreateCheckoutArgs = Infer<typeof CreateCheckoutArgs>;
17
17
  export declare const CheckArgs: import("convex/values").VObject<{
18
- product_id: string;
18
+ productId: string;
19
19
  }, {
20
- product_id: import("convex/values").VString<string, "required">;
21
- }, "required", "product_id">;
20
+ productId: import("convex/values").VString<string, "required">;
21
+ }, "required", "productId">;
22
22
  export type CheckArgs = Infer<typeof CheckArgs>;
23
- export declare const ListSubscriptionsArgs: import("convex/values").VObject<{
24
- project_id: string;
25
- }, {
26
- project_id: import("convex/values").VString<string, "required">;
27
- }, "required", "project_id">;
23
+ export declare const ListSubscriptionsArgs: import("convex/values").VObject<{}, {}, "required", never>;
28
24
  export type ListSubscriptionsArgs = Infer<typeof ListSubscriptionsArgs>;
29
25
  export declare const GetCustomerArgs: import("convex/values").VObject<{
30
- project_id: string;
31
26
  customer_id: string;
32
27
  }, {
33
- project_id: import("convex/values").VString<string, "required">;
34
28
  customer_id: import("convex/values").VString<string, "required">;
35
- }, "required", "project_id" | "customer_id">;
29
+ }, "required", "customer_id">;
36
30
  export type GetCustomerArgs = Infer<typeof GetCustomerArgs>;
37
- export declare const ListCustomersArgs: import("convex/values").VObject<{
38
- project_id: string;
39
- }, {
40
- project_id: import("convex/values").VString<string, "required">;
41
- }, "required", "project_id">;
31
+ export declare const ListCustomersArgs: import("convex/values").VObject<{}, {}, "required", never>;
42
32
  export type ListCustomersArgs = Infer<typeof ListCustomersArgs>;
43
33
  //# sourceMappingURL=types.d.ts.map
@@ -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;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"}
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;;;;;;;;;;oEAK7B,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIlE,eAAO,MAAM,SAAS;;;;2BAEpB,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAGhD,eAAO,MAAM,qBAAqB,4DAAe,CAAC;AAClD,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAGxE,eAAO,MAAM,eAAe;;;;6BAE1B,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAG5D,eAAO,MAAM,iBAAiB,4DAAe,CAAC;AAC9C,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
package/dist/types.js CHANGED
@@ -2,30 +2,25 @@
2
2
  * Convex validators for Surpay action arguments
3
3
  */
4
4
  import { v } from "convex/values";
5
- // CreateCheckoutArgs: product_id required, price_id/URLs optional
6
- // Note: customer_id is NOT here - it's injected by the wrapper via identify()
5
+ // CreateCheckoutArgs: productId required, priceId/URLs optional
6
+ // Note: customerId is NOT here - it's injected by the wrapper via identify()
7
7
  export const CreateCheckoutArgs = v.object({
8
- product_id: v.string(),
9
- price_id: v.optional(v.string()),
10
- success_url: v.optional(v.string()),
11
- cancel_url: v.optional(v.string()),
8
+ productId: v.string(),
9
+ priceId: v.optional(v.string()),
10
+ successUrl: v.optional(v.string()),
11
+ cancelUrl: v.optional(v.string()),
12
12
  });
13
- // CheckArgs: product_id required
14
- // Note: customer_id is NOT here - it's injected by the wrapper via identify()
13
+ // CheckArgs: productId required
14
+ // Note: customerId is NOT here - it's injected by the wrapper via identify()
15
15
  export const CheckArgs = v.object({
16
- product_id: v.string(),
16
+ productId: v.string(),
17
17
  });
18
- // ListSubscriptions: requires project_id
19
- export const ListSubscriptionsArgs = v.object({
20
- project_id: v.string(),
21
- });
22
- // GetCustomer: requires project_id and customer_id
18
+ // ListSubscriptions: no args required (project_id from auth context)
19
+ export const ListSubscriptionsArgs = v.object({});
20
+ // GetCustomer: requires customer_id (project_id from auth context)
23
21
  export const GetCustomerArgs = v.object({
24
- project_id: v.string(),
25
22
  customer_id: v.string(),
26
23
  });
27
- // ListCustomers: requires project_id
28
- export const ListCustomersArgs = v.object({
29
- project_id: v.string(),
30
- });
24
+ // ListCustomers: no args required (project_id from auth context)
25
+ export const ListCustomersArgs = v.object({});
31
26
  //# sourceMappingURL=types.js.map
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,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,E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,EAAE,CAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC;AAGH,qEAAqE;AACrE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAGlD,mEAAmE;AACnE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAGH,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@surgent-dev/surpay-convex",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
+ "description": "Convex integration for Surpay SDK",
4
5
  "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/surgent-dev/surpay-sdk-ts.git",
11
+ "directory": "packages/surpay-convex"
12
+ },
13
+ "homepage": "https://github.com/surgent-dev/surpay-sdk-ts#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/surgent-dev/surpay-sdk-ts/issues"
16
+ },
7
17
  "exports": {
8
18
  ".": {
9
19
  "types": "./dist/index.d.ts",
@@ -15,7 +25,7 @@
15
25
  "clean": "rm -rf dist"
16
26
  },
17
27
  "dependencies": {
18
- "@surgent-dev/surpay": "^0.1.7"
28
+ "@surgent-dev/surpay": "^0.2.0"
19
29
  },
20
30
  "peerDependencies": {
21
31
  "convex": "^1.25.0"
package/src/index.ts CHANGED
@@ -22,8 +22,8 @@
22
22
  * export const { createCheckout, getCustomer, listCustomers, listSubscriptions } = surpay.api();
23
23
  * ```
24
24
  */
25
- import { actionGeneric } from "convex/server";
26
- import { Surpay as SurpayClient, ResponseCase } from "@surgent-dev/surpay";
25
+ import { actionGeneric, GenericActionCtx } from "convex/server";
26
+ import { Surpay as SurpayClient, ResponseCase, camelToSnake } from "@surgent-dev/surpay";
27
27
  import {
28
28
  CreateCheckoutArgs,
29
29
  CheckArgs,
@@ -37,7 +37,8 @@ export type IdentifierOpts = {
37
37
  customerData?: { name?: string; email?: string };
38
38
  };
39
39
 
40
- export type SurpayConfig = {
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ export type SurpayConfig<Ctx extends GenericActionCtx<any> = GenericActionCtx<any>> = {
41
42
  apiKey: string;
42
43
  baseUrl?: string;
43
44
  /**
@@ -48,7 +49,7 @@ export type SurpayConfig = {
48
49
  * Defaults to 'snake' for Convex validator compatibility.
49
50
  */
50
51
  responseCase?: ResponseCase;
51
- identify: (ctx: any) => Promise<IdentifierOpts | null>;
52
+ identify: (ctx: Ctx) => Promise<IdentifierOpts | null>;
52
53
  };
53
54
 
54
55
  // Convex can't serialize class instances - convert errors to plain objects
@@ -76,11 +77,12 @@ async function wrapSdkCall<T>(
76
77
  }
77
78
  }
78
79
 
79
- export class Surpay {
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ export class Surpay<Ctx extends GenericActionCtx<any> = GenericActionCtx<any>> {
80
82
  private client: SurpayClient;
81
- private options: SurpayConfig;
83
+ private options: SurpayConfig<Ctx>;
82
84
 
83
- constructor(config: SurpayConfig) {
85
+ constructor(config: SurpayConfig<Ctx>) {
84
86
  this.options = config;
85
87
  const g = globalThis as { process?: { env: Record<string, string | undefined> } };
86
88
  const envBaseUrl = g.process?.env.SURPAY_BASE_URL;
@@ -92,7 +94,7 @@ export class Surpay {
92
94
  });
93
95
  }
94
96
 
95
- async getIdentifierOpts(ctx: any): Promise<IdentifierOpts | null> {
97
+ async getIdentifierOpts(ctx: Ctx): Promise<IdentifierOpts | null> {
96
98
  return await this.options.identify(ctx);
97
99
  }
98
100
 
@@ -100,7 +102,7 @@ export class Surpay {
100
102
  ctx,
101
103
  requireAuth = true,
102
104
  }: {
103
- ctx: any;
105
+ ctx: Ctx;
104
106
  requireAuth?: boolean;
105
107
  }): Promise<{ client: SurpayClient; identifierOpts: IdentifierOpts | null }> {
106
108
  const identifierOpts = await this.getIdentifierOpts(ctx);
@@ -115,10 +117,17 @@ export class Surpay {
115
117
  createCheckout: actionGeneric({
116
118
  args: CreateCheckoutArgs,
117
119
  handler: async (ctx, args) => {
118
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
120
+ const { client, identifierOpts } = await this.getAuthParams({ ctx: ctx as Ctx });
121
+ // Transform camelCase user args to snake_case for API
122
+ const snakeCaseArgs = camelToSnake(args) as unknown as {
123
+ product_id: string;
124
+ price_id?: string;
125
+ success_url?: string;
126
+ cancel_url?: string;
127
+ };
119
128
  return wrapSdkCall(() =>
120
129
  client.checkout.create({
121
- ...args,
130
+ ...snakeCaseArgs,
122
131
  customer_id: identifierOpts!.customerId,
123
132
  customer_data: identifierOpts!.customerData,
124
133
  })
@@ -129,10 +138,10 @@ export class Surpay {
129
138
  check: actionGeneric({
130
139
  args: CheckArgs,
131
140
  handler: async (ctx, args) => {
132
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
141
+ const { client, identifierOpts } = await this.getAuthParams({ ctx: ctx as Ctx });
133
142
  return wrapSdkCall(() =>
134
143
  client.check({
135
- product_id: args.product_id,
144
+ product_id: args.productId,
136
145
  customer_id: identifierOpts!.customerId,
137
146
  })
138
147
  );
@@ -142,27 +151,24 @@ export class Surpay {
142
151
  getCustomer: actionGeneric({
143
152
  args: GetCustomerArgs,
144
153
  handler: async (ctx, args) => {
145
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
146
- const customerId = args.customer_id || identifierOpts!.customerId;
147
- return wrapSdkCall(() =>
148
- client.customers.get(args.project_id, customerId)
149
- );
154
+ const { client } = await this.getAuthParams({ ctx: ctx as Ctx, requireAuth: false });
155
+ return wrapSdkCall(() => client.customers.get(args.customer_id));
150
156
  },
151
157
  }),
152
158
 
153
159
  listCustomers: actionGeneric({
154
160
  args: ListCustomersArgs,
155
- handler: async (ctx, args) => {
156
- const { client } = await this.getAuthParams({ ctx });
157
- return wrapSdkCall(() => client.customers.list(args.project_id));
161
+ handler: async (ctx) => {
162
+ const { client } = await this.getAuthParams({ ctx: ctx as Ctx });
163
+ return wrapSdkCall(() => client.customers.list());
158
164
  },
159
165
  }),
160
166
 
161
167
  listSubscriptions: actionGeneric({
162
168
  args: ListSubscriptionsArgs,
163
- handler: async (ctx, args) => {
164
- const { client } = await this.getAuthParams({ ctx });
165
- return wrapSdkCall(() => client.subscriptions.list(args.project_id));
169
+ handler: async (ctx) => {
170
+ const { client } = await this.getAuthParams({ ctx: ctx as Ctx });
171
+ return wrapSdkCall(() => client.subscriptions.list());
166
172
  },
167
173
  }),
168
174
  };
package/src/types.ts CHANGED
@@ -3,38 +3,33 @@
3
3
  */
4
4
  import { v, Infer } from "convex/values";
5
5
 
6
- // CreateCheckoutArgs: product_id required, price_id/URLs optional
7
- // Note: customer_id is NOT here - it's injected by the wrapper via identify()
6
+ // CreateCheckoutArgs: productId required, priceId/URLs optional
7
+ // Note: customerId is NOT here - it's injected by the wrapper via identify()
8
8
  export const CreateCheckoutArgs = v.object({
9
- product_id: v.string(),
10
- price_id: v.optional(v.string()),
11
- success_url: v.optional(v.string()),
12
- cancel_url: v.optional(v.string()),
9
+ productId: v.string(),
10
+ priceId: v.optional(v.string()),
11
+ successUrl: v.optional(v.string()),
12
+ cancelUrl: v.optional(v.string()),
13
13
  });
14
14
  export type CreateCheckoutArgs = Infer<typeof CreateCheckoutArgs>;
15
15
 
16
- // CheckArgs: product_id required
17
- // Note: customer_id is NOT here - it's injected by the wrapper via identify()
16
+ // CheckArgs: productId required
17
+ // Note: customerId is NOT here - it's injected by the wrapper via identify()
18
18
  export const CheckArgs = v.object({
19
- product_id: v.string(),
19
+ productId: v.string(),
20
20
  });
21
21
  export type CheckArgs = Infer<typeof CheckArgs>;
22
22
 
23
- // ListSubscriptions: requires project_id
24
- export const ListSubscriptionsArgs = v.object({
25
- project_id: v.string(),
26
- });
23
+ // ListSubscriptions: no args required (project_id from auth context)
24
+ export const ListSubscriptionsArgs = v.object({});
27
25
  export type ListSubscriptionsArgs = Infer<typeof ListSubscriptionsArgs>;
28
26
 
29
- // GetCustomer: requires project_id and customer_id
27
+ // GetCustomer: requires customer_id (project_id from auth context)
30
28
  export const GetCustomerArgs = v.object({
31
- project_id: v.string(),
32
29
  customer_id: v.string(),
33
30
  });
34
31
  export type GetCustomerArgs = Infer<typeof GetCustomerArgs>;
35
32
 
36
- // ListCustomers: requires project_id
37
- export const ListCustomersArgs = v.object({
38
- project_id: v.string(),
39
- });
33
+ // ListCustomers: no args required (project_id from auth context)
34
+ export const ListCustomersArgs = v.object({});
40
35
  export type ListCustomersArgs = Infer<typeof ListCustomersArgs>;