@paid-ai/paid-node 1.0.1-alpha0 → 1.0.1-alpha2

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.
Files changed (74) hide show
  1. package/dist/cjs/Client.js +2 -2
  2. package/dist/cjs/api/resources/plans/client/Client.d.ts +70 -0
  3. package/dist/cjs/api/resources/plans/client/Client.js +282 -2
  4. package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.d.ts +13 -0
  5. package/dist/cjs/api/resources/plans/client/requests/PlansSubscribeRequest.js +3 -0
  6. package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.ts +10 -0
  7. package/dist/cjs/api/resources/plans/client/requests/PlansUnsubscribeRequest.js +3 -0
  8. package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.d.ts +16 -0
  9. package/dist/cjs/api/resources/plans/client/requests/PlansUpgradeRequest.js +3 -0
  10. package/dist/cjs/api/resources/plans/client/requests/index.d.ts +3 -0
  11. package/dist/cjs/api/resources/usage/client/Client.d.ts +3 -3
  12. package/dist/cjs/api/resources/usage/client/Client.js +3 -3
  13. package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +3 -3
  14. package/dist/cjs/api/types/Plan.d.ts +33 -0
  15. package/dist/cjs/api/types/Plan.js +19 -0
  16. package/dist/cjs/api/types/PlanWithFeatures.d.ts +67 -0
  17. package/dist/cjs/api/types/PlanWithFeatures.js +22 -0
  18. package/dist/cjs/api/types/SignalV2.d.ts +5 -5
  19. package/dist/cjs/api/types/index.d.ts +1 -0
  20. package/dist/cjs/api/types/index.js +1 -0
  21. package/dist/cjs/integrations/adapters/expressjs/index.d.ts +2 -2
  22. package/dist/cjs/integrations/adapters/expressjs/index.js +2 -1
  23. package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +16 -0
  24. package/dist/cjs/integrations/adapters/expressjs/routes.js +28 -0
  25. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
  26. package/dist/cjs/integrations/adapters/nextjs/index.js +6 -1
  27. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +75 -0
  28. package/dist/cjs/integrations/adapters/nextjs/routes.js +101 -0
  29. package/dist/cjs/integrations/controllers/index.d.ts +1 -0
  30. package/dist/cjs/integrations/controllers/index.js +13 -1
  31. package/dist/cjs/integrations/controllers/orders.js +52 -17
  32. package/dist/cjs/integrations/controllers/plans.d.ts +208 -0
  33. package/dist/cjs/integrations/controllers/plans.js +365 -0
  34. package/dist/cjs/integrations/types.d.ts +5 -2
  35. package/dist/cjs/version.d.ts +1 -1
  36. package/dist/cjs/version.js +1 -1
  37. package/dist/esm/Client.mjs +2 -2
  38. package/dist/esm/api/resources/plans/client/Client.d.mts +70 -0
  39. package/dist/esm/api/resources/plans/client/Client.mjs +282 -2
  40. package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.d.mts +13 -0
  41. package/dist/esm/api/resources/plans/client/requests/PlansSubscribeRequest.mjs +2 -0
  42. package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.d.mts +10 -0
  43. package/dist/esm/api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs +2 -0
  44. package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.d.mts +16 -0
  45. package/dist/esm/api/resources/plans/client/requests/PlansUpgradeRequest.mjs +2 -0
  46. package/dist/esm/api/resources/plans/client/requests/index.d.mts +3 -0
  47. package/dist/esm/api/resources/usage/client/Client.d.mts +3 -3
  48. package/dist/esm/api/resources/usage/client/Client.mjs +3 -3
  49. package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +3 -3
  50. package/dist/esm/api/types/Plan.d.mts +33 -0
  51. package/dist/esm/api/types/Plan.mjs +18 -1
  52. package/dist/esm/api/types/PlanWithFeatures.d.mts +67 -0
  53. package/dist/esm/api/types/PlanWithFeatures.mjs +19 -0
  54. package/dist/esm/api/types/SignalV2.d.mts +5 -5
  55. package/dist/esm/api/types/index.d.mts +1 -0
  56. package/dist/esm/api/types/index.mjs +1 -0
  57. package/dist/esm/integrations/adapters/expressjs/index.d.mts +2 -2
  58. package/dist/esm/integrations/adapters/expressjs/index.mjs +2 -2
  59. package/dist/esm/integrations/adapters/expressjs/routes.d.mts +16 -0
  60. package/dist/esm/integrations/adapters/expressjs/routes.mjs +27 -0
  61. package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
  62. package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
  63. package/dist/esm/integrations/adapters/nextjs/routes.d.mts +75 -0
  64. package/dist/esm/integrations/adapters/nextjs/routes.mjs +96 -0
  65. package/dist/esm/integrations/controllers/index.d.mts +1 -0
  66. package/dist/esm/integrations/controllers/index.mjs +1 -0
  67. package/dist/esm/integrations/controllers/orders.mjs +52 -17
  68. package/dist/esm/integrations/controllers/plans.d.mts +208 -0
  69. package/dist/esm/integrations/controllers/plans.mjs +353 -0
  70. package/dist/esm/integrations/types.d.mts +5 -2
  71. package/dist/esm/version.d.mts +1 -1
  72. package/dist/esm/version.mjs +1 -1
  73. package/package.json +36 -2
  74. package/reference.md +280 -3
@@ -0,0 +1,208 @@
1
+ import { PaidClient } from "../../Client.mjs";
2
+ import type { PlanGroup } from "../../api/types/PlanGroup.mjs";
3
+ import type { Plan } from "../../api/types/Plan.mjs";
4
+ import type { PlanWithFeatures } from "../../api/types/PlanWithFeatures.mjs";
5
+ import type { Order } from "../../api/types/Order.mjs";
6
+ import type { CancelRenewalResponse } from "../../api/types/CancelRenewalResponse.mjs";
7
+ import type { ProrationUpgradeResponse } from "../../api/types/ProrationUpgradeResponse.mjs";
8
+ import type { PlansSubscribeRequest } from "../../api/resources/plans/client/requests/PlansSubscribeRequest.mjs";
9
+ import type { PlansUnsubscribeRequest } from "../../api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs";
10
+ import type { PlansUpgradeRequest } from "../../api/resources/plans/client/requests/PlansUpgradeRequest.mjs";
11
+ /**
12
+ * Get a plan by ID
13
+ *
14
+ * @param client - PaidClient instance
15
+ * @param planId - Plan's ID
16
+ * @returns Plan data
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const plan = await getPlanById(client, 'plan-123');
21
+ * console.log(plan.name, plan.id);
22
+ * ```
23
+ */
24
+ export declare function getPlanById(client: PaidClient, planId: string): Promise<Plan>;
25
+ /**
26
+ * Get a plan group by ID
27
+ *
28
+ * @param client - PaidClient instance
29
+ * @param planGroupId - Plan group's ID
30
+ * @returns Plan group data
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const planGroup = await getPlanGroupById(client, 'plan-group-123');
35
+ * console.log(planGroup.name, planGroup.id);
36
+ * ```
37
+ */
38
+ export declare function getPlanGroupById(client: PaidClient, planGroupId: string): Promise<PlanGroup>;
39
+ /**
40
+ * Create a framework-agnostic handler for fetching a plan group by ID
41
+ *
42
+ * This handler can be used with any framework adapter.
43
+ * The plan group ID should be provided either in params or query string.
44
+ *
45
+ * @returns Handler function
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // In Next.js route: /api/plans/[planGroupId]/route.ts
50
+ * import { createGetPlanGroupByIdHandler } from '@paid-ai/paid-node/integrations';
51
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
52
+ *
53
+ * const handler = createGetPlanGroupByIdHandler();
54
+ * export const GET = nextjsAdapter(handler);
55
+ * ```
56
+ */
57
+ export declare function createGetPlanGroupByIdHandler(): (request: any, response: any, config?: any) => Promise<any>;
58
+ /**
59
+ * Get all plans in a plan group
60
+ *
61
+ * @param client - PaidClient instance
62
+ * @param planGroupId - Plan group's ID
63
+ * @returns Array of plans with features
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const plans = await getGroupPlans(client, 'plan-group-123');
68
+ * console.log(plans.length);
69
+ * ```
70
+ */
71
+ export declare function getGroupPlans(client: PaidClient, planGroupId: string): Promise<PlanWithFeatures[]>;
72
+ /**
73
+ * Create a framework-agnostic handler for fetching plans in a plan group
74
+ *
75
+ * This handler can be used with any framework adapter.
76
+ * The plan group ID should be provided either in params or query string.
77
+ *
78
+ * @returns Handler function
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // In Next.js route: /api/plans/[planGroupId]/plans/route.ts
83
+ * import { createGetGroupPlansHandler } from '@paid-ai/paid-node/integrations';
84
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
85
+ *
86
+ * const handler = createGetGroupPlansHandler();
87
+ * export const GET = nextjsAdapter(handler);
88
+ * ```
89
+ */
90
+ export declare function createGetGroupPlansHandler(): (request: any, response: any, config?: any) => Promise<any>;
91
+ /**
92
+ * Subscribe a customer to a plan
93
+ *
94
+ * Creates a new order for a customer based on the specified plan, automatically converting plan products to order lines.
95
+ *
96
+ * @param client - PaidClient instance
97
+ * @param planId - Plan's ID
98
+ * @param request - Subscribe request with customer external ID and currency
99
+ * @returns Created order
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const order = await subscribe(client, 'plan-123', {
104
+ * customerExternalId: 'customer-123',
105
+ * currency: 'USD'
106
+ * });
107
+ * console.log(order.id);
108
+ * ```
109
+ */
110
+ export declare function subscribe(client: PaidClient, planId: string, request: PlansSubscribeRequest): Promise<Order>;
111
+ /**
112
+ * Create a framework-agnostic handler for subscribing a customer to a plan
113
+ *
114
+ * This handler can be used with any framework adapter.
115
+ * The plan ID should be provided either in params or query string.
116
+ * The request body should contain customerExternalId and currency.
117
+ *
118
+ * @returns Handler function
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // In Next.js route: /api/plans/[planId]/subscribe/route.ts
123
+ * import { createSubscribeHandler } from '@paid-ai/paid-node/integrations';
124
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
125
+ *
126
+ * const handler = createSubscribeHandler();
127
+ * export const POST = nextjsAdapter(handler);
128
+ * ```
129
+ */
130
+ export declare function createSubscribeHandler(): (request: any, response: any, config?: any) => Promise<any>;
131
+ /**
132
+ * Unsubscribe a customer from a plan
133
+ *
134
+ * Cancels the renewal of an order associated with the specified plan. The order will remain active until the cancellation date.
135
+ *
136
+ * @param client - PaidClient instance
137
+ * @param planId - Plan's ID
138
+ * @param request - Unsubscribe request with customer external ID
139
+ * @returns Cancel renewal response
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const response = await unsubscribe(client, 'plan-123', {
144
+ * customerExternalId: 'customer-123'
145
+ * });
146
+ * console.log(response.message);
147
+ * ```
148
+ */
149
+ export declare function unsubscribe(client: PaidClient, planId: string, request: PlansUnsubscribeRequest): Promise<CancelRenewalResponse>;
150
+ /**
151
+ * Create a framework-agnostic handler for unsubscribing a customer from a plan
152
+ *
153
+ * This handler can be used with any framework adapter.
154
+ * The plan ID should be provided either in params or query string.
155
+ * The request body should contain customerExternalId.
156
+ *
157
+ * @returns Handler function
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // In Next.js route: /api/plans/[planId]/unsubscribe/route.ts
162
+ * import { createUnsubscribeHandler } from '@paid-ai/paid-node/integrations';
163
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
164
+ *
165
+ * const handler = createUnsubscribeHandler();
166
+ * export const POST = nextjsAdapter(handler);
167
+ * ```
168
+ */
169
+ export declare function createUnsubscribeHandler(): (request: any, response: any, config?: any) => Promise<any>;
170
+ /**
171
+ * Upgrade a customer from their current plan to a new plan
172
+ *
173
+ * Upgrades a customer from their current plan to a new plan with automatic proration calculation. This schedules a plan change and applies credits for the unused portion of the current billing period.
174
+ *
175
+ * @param client - PaidClient instance
176
+ * @param request - Upgrade request with customer external ID, old plan ID, and new plan ID
177
+ * @returns Proration upgrade response
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const response = await upgrade(client, {
182
+ * customerExternalId: 'customer-123',
183
+ * oldPlanId: 'plan-123',
184
+ * newPlanId: 'plan-456'
185
+ * });
186
+ * console.log(response.order.id);
187
+ * ```
188
+ */
189
+ export declare function upgrade(client: PaidClient, request: PlansUpgradeRequest): Promise<ProrationUpgradeResponse>;
190
+ /**
191
+ * Create a framework-agnostic handler for upgrading a customer's plan
192
+ *
193
+ * This handler can be used with any framework adapter.
194
+ * The request body should contain customerExternalId, oldPlanId, and newPlanId.
195
+ *
196
+ * @returns Handler function
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * // In Next.js route: /api/plans/upgrade/route.ts
201
+ * import { createUpgradeHandler } from '@paid-ai/paid-node/integrations';
202
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
203
+ *
204
+ * const handler = createUpgradeHandler();
205
+ * export const POST = nextjsAdapter(handler);
206
+ * ```
207
+ */
208
+ export declare function createUpgradeHandler(): (request: any, response: any, config?: any) => Promise<any>;
@@ -0,0 +1,353 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { PaidClient } from "../../Client.mjs";
11
+ import { createHandler } from "../utils/base-handler.mjs";
12
+ /**
13
+ * Get a plan by ID
14
+ *
15
+ * @param client - PaidClient instance
16
+ * @param planId - Plan's ID
17
+ * @returns Plan data
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const plan = await getPlanById(client, 'plan-123');
22
+ * console.log(plan.name, plan.id);
23
+ * ```
24
+ */
25
+ export function getPlanById(client, planId) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const plan = yield client.plans.getById(planId);
28
+ return plan;
29
+ });
30
+ }
31
+ /**
32
+ * Get a plan group by ID
33
+ *
34
+ * @param client - PaidClient instance
35
+ * @param planGroupId - Plan group's ID
36
+ * @returns Plan group data
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const planGroup = await getPlanGroupById(client, 'plan-group-123');
41
+ * console.log(planGroup.name, planGroup.id);
42
+ * ```
43
+ */
44
+ export function getPlanGroupById(client, planGroupId) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const planGroup = yield client.plans.getGroupById(planGroupId);
47
+ return planGroup;
48
+ });
49
+ }
50
+ /**
51
+ * Create a framework-agnostic handler for fetching a plan group by ID
52
+ *
53
+ * This handler can be used with any framework adapter.
54
+ * The plan group ID should be provided either in params or query string.
55
+ *
56
+ * @returns Handler function
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * // In Next.js route: /api/plans/[planGroupId]/route.ts
61
+ * import { createGetPlanGroupByIdHandler } from '@paid-ai/paid-node/integrations';
62
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
63
+ *
64
+ * const handler = createGetPlanGroupByIdHandler();
65
+ * export const GET = nextjsAdapter(handler);
66
+ * ```
67
+ */
68
+ export function createGetPlanGroupByIdHandler() {
69
+ return createHandler((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
70
+ const planGroupId = params === null || params === void 0 ? void 0 : params.planGroupId;
71
+ if (!planGroupId) {
72
+ return {
73
+ success: false,
74
+ error: "planGroupId is required",
75
+ status: 400,
76
+ };
77
+ }
78
+ const planGroup = yield getPlanGroupById(client, planGroupId);
79
+ return { success: true, data: planGroup };
80
+ }), {
81
+ allowedMethods: ['GET'],
82
+ requireOrganizationId: false,
83
+ });
84
+ }
85
+ /**
86
+ * Get all plans in a plan group
87
+ *
88
+ * @param client - PaidClient instance
89
+ * @param planGroupId - Plan group's ID
90
+ * @returns Array of plans with features
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const plans = await getGroupPlans(client, 'plan-group-123');
95
+ * console.log(plans.length);
96
+ * ```
97
+ */
98
+ export function getGroupPlans(client, planGroupId) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const plans = yield client.plans.getGroupPlans(planGroupId);
101
+ return plans;
102
+ });
103
+ }
104
+ /**
105
+ * Create a framework-agnostic handler for fetching plans in a plan group
106
+ *
107
+ * This handler can be used with any framework adapter.
108
+ * The plan group ID should be provided either in params or query string.
109
+ *
110
+ * @returns Handler function
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * // In Next.js route: /api/plans/[planGroupId]/plans/route.ts
115
+ * import { createGetGroupPlansHandler } from '@paid-ai/paid-node/integrations';
116
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
117
+ *
118
+ * const handler = createGetGroupPlansHandler();
119
+ * export const GET = nextjsAdapter(handler);
120
+ * ```
121
+ */
122
+ export function createGetGroupPlansHandler() {
123
+ return createHandler((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
124
+ const planGroupId = params === null || params === void 0 ? void 0 : params.planGroupId;
125
+ if (!planGroupId) {
126
+ return {
127
+ success: false,
128
+ error: "planGroupId is required",
129
+ status: 400,
130
+ };
131
+ }
132
+ const plans = yield getGroupPlans(client, planGroupId);
133
+ return { success: true, data: plans };
134
+ }), {
135
+ allowedMethods: ['GET'],
136
+ requireOrganizationId: false,
137
+ });
138
+ }
139
+ /**
140
+ * Subscribe a customer to a plan
141
+ *
142
+ * Creates a new order for a customer based on the specified plan, automatically converting plan products to order lines.
143
+ *
144
+ * @param client - PaidClient instance
145
+ * @param planId - Plan's ID
146
+ * @param request - Subscribe request with customer external ID and currency
147
+ * @returns Created order
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const order = await subscribe(client, 'plan-123', {
152
+ * customerExternalId: 'customer-123',
153
+ * currency: 'USD'
154
+ * });
155
+ * console.log(order.id);
156
+ * ```
157
+ */
158
+ export function subscribe(client, planId, request) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ const order = yield client.plans.subscribe(planId, request);
161
+ return order;
162
+ });
163
+ }
164
+ /**
165
+ * Create a framework-agnostic handler for subscribing a customer to a plan
166
+ *
167
+ * This handler can be used with any framework adapter.
168
+ * The plan ID should be provided either in params or query string.
169
+ * The request body should contain customerExternalId and currency.
170
+ *
171
+ * @returns Handler function
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * // In Next.js route: /api/plans/[planId]/subscribe/route.ts
176
+ * import { createSubscribeHandler } from '@paid-ai/paid-node/integrations';
177
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
178
+ *
179
+ * const handler = createSubscribeHandler();
180
+ * export const POST = nextjsAdapter(handler);
181
+ * ```
182
+ */
183
+ export function createSubscribeHandler() {
184
+ return createHandler((client, body, params) => __awaiter(this, void 0, void 0, function* () {
185
+ const planId = params === null || params === void 0 ? void 0 : params.planId;
186
+ if (!planId) {
187
+ return {
188
+ success: false,
189
+ error: "planId is required",
190
+ status: 400,
191
+ };
192
+ }
193
+ if (!body.customerExternalId) {
194
+ return {
195
+ success: false,
196
+ error: "customerExternalId is required",
197
+ status: 400,
198
+ };
199
+ }
200
+ if (!body.currency) {
201
+ return {
202
+ success: false,
203
+ error: "currency is required",
204
+ status: 400,
205
+ };
206
+ }
207
+ const order = yield subscribe(client, planId, body);
208
+ return { success: true, data: order };
209
+ }), {
210
+ allowedMethods: ['POST'],
211
+ requireOrganizationId: false,
212
+ });
213
+ }
214
+ /**
215
+ * Unsubscribe a customer from a plan
216
+ *
217
+ * Cancels the renewal of an order associated with the specified plan. The order will remain active until the cancellation date.
218
+ *
219
+ * @param client - PaidClient instance
220
+ * @param planId - Plan's ID
221
+ * @param request - Unsubscribe request with customer external ID
222
+ * @returns Cancel renewal response
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const response = await unsubscribe(client, 'plan-123', {
227
+ * customerExternalId: 'customer-123'
228
+ * });
229
+ * console.log(response.message);
230
+ * ```
231
+ */
232
+ export function unsubscribe(client, planId, request) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ const response = yield client.plans.unsubscribe(planId, request);
235
+ return response;
236
+ });
237
+ }
238
+ /**
239
+ * Create a framework-agnostic handler for unsubscribing a customer from a plan
240
+ *
241
+ * This handler can be used with any framework adapter.
242
+ * The plan ID should be provided either in params or query string.
243
+ * The request body should contain customerExternalId.
244
+ *
245
+ * @returns Handler function
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * // In Next.js route: /api/plans/[planId]/unsubscribe/route.ts
250
+ * import { createUnsubscribeHandler } from '@paid-ai/paid-node/integrations';
251
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
252
+ *
253
+ * const handler = createUnsubscribeHandler();
254
+ * export const POST = nextjsAdapter(handler);
255
+ * ```
256
+ */
257
+ export function createUnsubscribeHandler() {
258
+ return createHandler((client, body, params) => __awaiter(this, void 0, void 0, function* () {
259
+ const planId = params === null || params === void 0 ? void 0 : params.planId;
260
+ if (!planId) {
261
+ return {
262
+ success: false,
263
+ error: "planId is required",
264
+ status: 400,
265
+ };
266
+ }
267
+ if (!body.customerExternalId) {
268
+ return {
269
+ success: false,
270
+ error: "customerExternalId is required",
271
+ status: 400,
272
+ };
273
+ }
274
+ const response = yield unsubscribe(client, planId, body);
275
+ return { success: true, data: response };
276
+ }), {
277
+ allowedMethods: ['POST'],
278
+ requireOrganizationId: false,
279
+ });
280
+ }
281
+ /**
282
+ * Upgrade a customer from their current plan to a new plan
283
+ *
284
+ * Upgrades a customer from their current plan to a new plan with automatic proration calculation. This schedules a plan change and applies credits for the unused portion of the current billing period.
285
+ *
286
+ * @param client - PaidClient instance
287
+ * @param request - Upgrade request with customer external ID, old plan ID, and new plan ID
288
+ * @returns Proration upgrade response
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const response = await upgrade(client, {
293
+ * customerExternalId: 'customer-123',
294
+ * oldPlanId: 'plan-123',
295
+ * newPlanId: 'plan-456'
296
+ * });
297
+ * console.log(response.order.id);
298
+ * ```
299
+ */
300
+ export function upgrade(client, request) {
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ const response = yield client.plans.upgrade(request);
303
+ return response;
304
+ });
305
+ }
306
+ /**
307
+ * Create a framework-agnostic handler for upgrading a customer's plan
308
+ *
309
+ * This handler can be used with any framework adapter.
310
+ * The request body should contain customerExternalId, oldPlanId, and newPlanId.
311
+ *
312
+ * @returns Handler function
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * // In Next.js route: /api/plans/upgrade/route.ts
317
+ * import { createUpgradeHandler } from '@paid-ai/paid-node/integrations';
318
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
319
+ *
320
+ * const handler = createUpgradeHandler();
321
+ * export const POST = nextjsAdapter(handler);
322
+ * ```
323
+ */
324
+ export function createUpgradeHandler() {
325
+ return createHandler((client, body) => __awaiter(this, void 0, void 0, function* () {
326
+ if (!body.customerExternalId) {
327
+ return {
328
+ success: false,
329
+ error: "customerExternalId is required",
330
+ status: 400,
331
+ };
332
+ }
333
+ if (!body.oldPlanId) {
334
+ return {
335
+ success: false,
336
+ error: "oldPlanId is required",
337
+ status: 400,
338
+ };
339
+ }
340
+ if (!body.newPlanId) {
341
+ return {
342
+ success: false,
343
+ error: "newPlanId is required",
344
+ status: 400,
345
+ };
346
+ }
347
+ const response = yield upgrade(client, body);
348
+ return { success: true, data: response };
349
+ }), {
350
+ allowedMethods: ['POST'],
351
+ requireOrganizationId: false,
352
+ });
353
+ }
@@ -41,18 +41,20 @@ export interface OrderConfig {
41
41
  customerId: string;
42
42
  customerExternalId: string;
43
43
  billingContactId?: string;
44
- agentExternalId: string;
44
+ agentExternalId?: string;
45
45
  name?: string;
46
46
  description?: string;
47
47
  startDate?: string;
48
48
  endDate?: string;
49
49
  currency?: string;
50
50
  orderLines?: OrderLineConfig[];
51
+ planId?: string;
51
52
  }
52
53
  export interface OrderLineConfig {
53
54
  agentExternalId: string;
54
55
  name?: string;
55
56
  description?: string;
57
+ planProductId?: string;
56
58
  }
57
59
  /**
58
60
  * Note: orderLines is not required because if agentExternalId is provided,
@@ -62,13 +64,14 @@ export interface CompleteOrderConfig {
62
64
  customerId: string;
63
65
  customerExternalId: string;
64
66
  billingContactId?: string;
65
- agentExternalId: string;
67
+ agentExternalId?: string;
66
68
  name: string;
67
69
  description: string;
68
70
  startDate: string;
69
71
  endDate: string;
70
72
  currency: string;
71
73
  orderLines: OrderLineConfig[];
74
+ planId?: string;
72
75
  }
73
76
  export interface OrderOptions {
74
77
  /**
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.1-alpha0";
1
+ export declare const SDK_VERSION = "1.0.1-alpha2";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.1-alpha0";
1
+ export const SDK_VERSION = "1.0.1-alpha2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paid-ai/paid-node",
3
- "version": "1.0.1-alpha0",
3
+ "version": "1.0.1-alpha2",
4
4
  "private": false,
5
5
  "repository": "github:paid-ai/paid-node",
6
6
  "type": "commonjs",
@@ -242,5 +242,39 @@
242
242
  "engines": {
243
243
  "node": ">=18.0.0"
244
244
  },
245
- "sideEffects": false
245
+ "sideEffects": false,
246
+ "typesVersions": {
247
+ "*": {
248
+ "openai": [
249
+ "./dist/cjs/openai-wrapper/index.d.ts"
250
+ ],
251
+ "anthropic": [
252
+ "./dist/cjs/anthropic-wrapper/index.d.ts"
253
+ ],
254
+ "mistral": [
255
+ "./dist/cjs/mistral-wrapper/index.d.ts"
256
+ ],
257
+ "langchain": [
258
+ "./dist/cjs/langchain-wrapper/index.d.ts"
259
+ ],
260
+ "vercel": [
261
+ "./dist/cjs/vercel-wrapper/index.d.ts"
262
+ ],
263
+ "tracing": [
264
+ "./dist/cjs/tracing/index.d.ts"
265
+ ],
266
+ "integrations": [
267
+ "./dist/cjs/integrations/index.d.ts"
268
+ ],
269
+ "integrations/nextjs": [
270
+ "./dist/cjs/integrations/adapters/nextjs/index.d.ts"
271
+ ],
272
+ "integrations/express": [
273
+ "./dist/cjs/integrations/adapters/expressjs/index.d.ts"
274
+ ],
275
+ "integrations/nestjs": [
276
+ "./dist/cjs/integrations/adapters/nestjs/index.d.ts"
277
+ ]
278
+ }
279
+ }
246
280
  }