@surgent-dev/surpay-convex 0.1.3 → 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,4 +1,29 @@
1
- import { Surpay as SurpayClient } from "@surgent-dev/surpay";
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";
26
+ import { Surpay as SurpayClient, ResponseCase } from "@surgent-dev/surpay";
2
27
  export type IdentifierOpts = {
3
28
  customerId: string;
4
29
  customerData?: {
@@ -6,22 +31,30 @@ 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
- identify: (ctx: any) => Promise<IdentifierOpts | null>;
37
+ /**
38
+ * Response key case format.
39
+ * - 'snake' (default): snake_case keys to match Convex validators
40
+ * - 'camel': camelCase keys from API responses
41
+ *
42
+ * Defaults to 'snake' for Convex validator compatibility.
43
+ */
44
+ responseCase?: ResponseCase;
45
+ identify: (ctx: Ctx) => Promise<IdentifierOpts | null>;
13
46
  };
14
47
  type PlainError = {
15
48
  message: string;
16
49
  code?: string;
17
50
  };
18
- export declare class Surpay {
51
+ export declare class Surpay<Ctx extends GenericActionCtx<any> = GenericActionCtx<any>> {
19
52
  private client;
20
53
  private options;
21
- constructor(config: SurpayConfig);
22
- getIdentifierOpts(ctx: any): Promise<IdentifierOpts | null>;
54
+ constructor(config: SurpayConfig<Ctx>);
55
+ getIdentifierOpts(ctx: Ctx): Promise<IdentifierOpts | null>;
23
56
  getAuthParams({ ctx, requireAuth, }: {
24
- ctx: any;
57
+ ctx: Ctx;
25
58
  requireAuth?: boolean;
26
59
  }): Promise<{
27
60
  client: SurpayClient;
@@ -29,10 +62,10 @@ export declare class Surpay {
29
62
  }>;
30
63
  api(): {
31
64
  createCheckout: import("convex/server").RegisteredAction<"public", {
32
- price_id?: string | undefined;
33
- success_url?: string | undefined;
34
- cancel_url?: string | undefined;
35
- product_id: string;
65
+ priceId?: string | undefined;
66
+ successUrl?: string | undefined;
67
+ cancelUrl?: string | undefined;
68
+ productId: string;
36
69
  }, Promise<{
37
70
  data: null;
38
71
  error: PlainError;
@@ -41,7 +74,7 @@ export declare class Surpay {
41
74
  error: null;
42
75
  }>>;
43
76
  check: import("convex/server").RegisteredAction<"public", {
44
- product_id: string;
77
+ productId: string;
45
78
  }, Promise<{
46
79
  data: null;
47
80
  error: PlainError;
@@ -50,7 +83,6 @@ export declare class Surpay {
50
83
  error: null;
51
84
  }>>;
52
85
  getCustomer: import("convex/server").RegisteredAction<"public", {
53
- project_id: string;
54
86
  customer_id: string;
55
87
  }, Promise<{
56
88
  data: null;
@@ -59,18 +91,14 @@ export declare class Surpay {
59
91
  data: import("@surgent-dev/surpay").CustomerWithDetails;
60
92
  error: null;
61
93
  }>>;
62
- listCustomers: import("convex/server").RegisteredAction<"public", {
63
- project_id: string;
64
- }, Promise<{
94
+ listCustomers: import("convex/server").RegisteredAction<"public", {}, Promise<{
65
95
  data: null;
66
96
  error: PlainError;
67
97
  } | {
68
98
  data: import("@surgent-dev/surpay").Customer[];
69
99
  error: null;
70
100
  }>>;
71
- listSubscriptions: import("convex/server").RegisteredAction<"public", {
72
- project_id: string;
73
- }, Promise<{
101
+ listSubscriptions: import("convex/server").RegisteredAction<"public", {}, Promise<{
74
102
  data: null;
75
103
  error: PlainError;
76
104
  } | {
@@ -80,4 +108,5 @@ export declare class Surpay {
80
108
  };
81
109
  }
82
110
  export * from "./types.js";
111
+ export type { ResponseCase } from "@surgent-dev/surpay";
83
112
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAS7D,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE;QAA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AAC;IAQ5E,GAAG;;;;;;;kBA/CyC,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;;;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;
@@ -54,6 +55,8 @@ export class Surpay {
54
55
  this.client = new SurpayClient({
55
56
  apiKey: config.apiKey,
56
57
  baseUrl: config.baseUrl ?? envBaseUrl,
58
+ // Default to snake_case for Convex validator compatibility
59
+ responseCase: config.responseCase ?? "snake",
57
60
  });
58
61
  }
59
62
  async getIdentifierOpts(ctx) {
@@ -71,9 +74,11 @@ export class Surpay {
71
74
  createCheckout: actionGeneric({
72
75
  args: CreateCheckoutArgs,
73
76
  handler: async (ctx, args) => {
74
- 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);
75
80
  return wrapSdkCall(() => client.checkout.create({
76
- ...args,
81
+ ...snakeCaseArgs,
77
82
  customer_id: identifierOpts.customerId,
78
83
  customer_data: identifierOpts.customerData,
79
84
  }));
@@ -82,9 +87,9 @@ export class Surpay {
82
87
  check: actionGeneric({
83
88
  args: CheckArgs,
84
89
  handler: async (ctx, args) => {
85
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
90
+ const { client, identifierOpts } = await this.getAuthParams({ ctx: ctx });
86
91
  return wrapSdkCall(() => client.check({
87
- product_id: args.product_id,
92
+ product_id: args.productId,
88
93
  customer_id: identifierOpts.customerId,
89
94
  }));
90
95
  },
@@ -92,23 +97,22 @@ export class Surpay {
92
97
  getCustomer: actionGeneric({
93
98
  args: GetCustomerArgs,
94
99
  handler: async (ctx, args) => {
95
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
96
- const customerId = args.customer_id || identifierOpts.customerId;
97
- 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));
98
102
  },
99
103
  }),
100
104
  listCustomers: actionGeneric({
101
105
  args: ListCustomersArgs,
102
- handler: async (ctx, args) => {
103
- const { client } = await this.getAuthParams({ ctx });
104
- 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());
105
109
  },
106
110
  }),
107
111
  listSubscriptions: actionGeneric({
108
112
  args: ListSubscriptionsArgs,
109
- handler: async (ctx, args) => {
110
- const { client } = await this.getAuthParams({ ctx });
111
- 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());
112
116
  },
113
117
  }),
114
118
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3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AI,EAAE,iBAAiB;gBACvB,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,SAAS,CAAC,IAAI,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;IACz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,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;CAClC,CAAC,CAAC;AAGH,gCAAgC;AAChC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,SAAS,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.3",
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.6"
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 } 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,10 +37,19 @@ 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
- identify: (ctx: any) => Promise<IdentifierOpts | null>;
44
+ /**
45
+ * Response key case format.
46
+ * - 'snake' (default): snake_case keys to match Convex validators
47
+ * - 'camel': camelCase keys from API responses
48
+ *
49
+ * Defaults to 'snake' for Convex validator compatibility.
50
+ */
51
+ responseCase?: ResponseCase;
52
+ identify: (ctx: Ctx) => Promise<IdentifierOpts | null>;
44
53
  };
45
54
 
46
55
  // Convex can't serialize class instances - convert errors to plain objects
@@ -68,21 +77,24 @@ async function wrapSdkCall<T>(
68
77
  }
69
78
  }
70
79
 
71
- export class Surpay {
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ export class Surpay<Ctx extends GenericActionCtx<any> = GenericActionCtx<any>> {
72
82
  private client: SurpayClient;
73
- private options: SurpayConfig;
83
+ private options: SurpayConfig<Ctx>;
74
84
 
75
- constructor(config: SurpayConfig) {
85
+ constructor(config: SurpayConfig<Ctx>) {
76
86
  this.options = config;
77
87
  const g = globalThis as { process?: { env: Record<string, string | undefined> } };
78
88
  const envBaseUrl = g.process?.env.SURPAY_BASE_URL;
79
89
  this.client = new SurpayClient({
80
90
  apiKey: config.apiKey,
81
91
  baseUrl: config.baseUrl ?? envBaseUrl,
92
+ // Default to snake_case for Convex validator compatibility
93
+ responseCase: config.responseCase ?? "snake",
82
94
  });
83
95
  }
84
96
 
85
- async getIdentifierOpts(ctx: any): Promise<IdentifierOpts | null> {
97
+ async getIdentifierOpts(ctx: Ctx): Promise<IdentifierOpts | null> {
86
98
  return await this.options.identify(ctx);
87
99
  }
88
100
 
@@ -90,7 +102,7 @@ export class Surpay {
90
102
  ctx,
91
103
  requireAuth = true,
92
104
  }: {
93
- ctx: any;
105
+ ctx: Ctx;
94
106
  requireAuth?: boolean;
95
107
  }): Promise<{ client: SurpayClient; identifierOpts: IdentifierOpts | null }> {
96
108
  const identifierOpts = await this.getIdentifierOpts(ctx);
@@ -105,10 +117,17 @@ export class Surpay {
105
117
  createCheckout: actionGeneric({
106
118
  args: CreateCheckoutArgs,
107
119
  handler: async (ctx, args) => {
108
- 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
+ };
109
128
  return wrapSdkCall(() =>
110
129
  client.checkout.create({
111
- ...args,
130
+ ...snakeCaseArgs,
112
131
  customer_id: identifierOpts!.customerId,
113
132
  customer_data: identifierOpts!.customerData,
114
133
  })
@@ -119,10 +138,10 @@ export class Surpay {
119
138
  check: actionGeneric({
120
139
  args: CheckArgs,
121
140
  handler: async (ctx, args) => {
122
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
141
+ const { client, identifierOpts } = await this.getAuthParams({ ctx: ctx as Ctx });
123
142
  return wrapSdkCall(() =>
124
143
  client.check({
125
- product_id: args.product_id,
144
+ product_id: args.productId,
126
145
  customer_id: identifierOpts!.customerId,
127
146
  })
128
147
  );
@@ -132,27 +151,24 @@ export class Surpay {
132
151
  getCustomer: actionGeneric({
133
152
  args: GetCustomerArgs,
134
153
  handler: async (ctx, args) => {
135
- const { client, identifierOpts } = await this.getAuthParams({ ctx });
136
- const customerId = args.customer_id || identifierOpts!.customerId;
137
- return wrapSdkCall(() =>
138
- client.customers.get(args.project_id, customerId)
139
- );
154
+ const { client } = await this.getAuthParams({ ctx: ctx as Ctx, requireAuth: false });
155
+ return wrapSdkCall(() => client.customers.get(args.customer_id));
140
156
  },
141
157
  }),
142
158
 
143
159
  listCustomers: actionGeneric({
144
160
  args: ListCustomersArgs,
145
- handler: async (ctx, args) => {
146
- const { client } = await this.getAuthParams({ ctx });
147
- 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());
148
164
  },
149
165
  }),
150
166
 
151
167
  listSubscriptions: actionGeneric({
152
168
  args: ListSubscriptionsArgs,
153
- handler: async (ctx, args) => {
154
- const { client } = await this.getAuthParams({ ctx });
155
- 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());
156
172
  },
157
173
  }),
158
174
  };
@@ -160,3 +176,4 @@ export class Surpay {
160
176
  }
161
177
 
162
178
  export * from "./types.js";
179
+ export type { ResponseCase } from "@surgent-dev/surpay";
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>;