@paid-ai/paid-node 1.0.0 → 1.0.1-alpha1
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/dist/cjs/BaseClient.d.ts +4 -17
- package/dist/cjs/BaseClient.js +0 -59
- package/dist/cjs/Client.d.ts +28 -28
- package/dist/cjs/Client.js +52 -11
- package/dist/cjs/api/errors/BadRequestError.js +1 -5
- package/dist/cjs/api/errors/ForbiddenError.js +1 -5
- package/dist/cjs/api/errors/InternalServerError.js +1 -5
- package/dist/cjs/api/errors/NotFoundError.js +1 -5
- package/dist/cjs/api/resources/agents/client/Client.d.ts +23 -22
- package/dist/cjs/api/resources/agents/client/Client.js +158 -55
- package/dist/cjs/api/resources/contacts/client/Client.d.ts +19 -18
- package/dist/cjs/api/resources/contacts/client/Client.js +122 -43
- package/dist/cjs/api/resources/customers/client/Client.d.ts +37 -36
- package/dist/cjs/api/resources/customers/client/Client.js +315 -113
- package/dist/cjs/api/resources/orders/client/Client.d.ts +28 -27
- package/dist/cjs/api/resources/orders/client/Client.js +177 -62
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +9 -8
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +32 -13
- package/dist/cjs/api/resources/plans/client/Client.d.ts +25 -12
- package/dist/cjs/api/resources/plans/client/Client.js +143 -33
- package/dist/cjs/api/resources/products/client/Client.d.ts +23 -22
- package/dist/cjs/api/resources/products/client/Client.js +158 -55
- package/dist/cjs/api/resources/products/client/requests/index.d.ts +1 -1
- package/dist/cjs/api/resources/products/client/requests/index.js +0 -3
- package/dist/cjs/api/resources/traces/client/Client.d.ts +9 -8
- package/dist/cjs/api/resources/traces/client/Client.js +57 -23
- package/dist/cjs/api/resources/usage/client/Client.d.ts +16 -15
- package/dist/cjs/api/resources/usage/client/Client.js +71 -28
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +3 -3
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +34 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +3 -0
- package/dist/cjs/api/types/SignalV2.d.ts +5 -5
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +1 -4
- package/dist/cjs/core/auth/BearerToken.d.ts +1 -3
- package/dist/cjs/core/auth/BearerToken.js +6 -7
- package/dist/cjs/core/auth/index.d.ts +0 -1
- package/dist/cjs/core/auth/index.js +1 -3
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +7 -6
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -10
- package/dist/cjs/core/fetcher/Fetcher.js +10 -204
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +4 -0
- package/dist/cjs/core/fetcher/ResponseWithBody.js +6 -0
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
- package/dist/cjs/core/fetcher/getRequestBody.js +0 -4
- package/dist/cjs/core/fetcher/getResponseBody.js +4 -18
- package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
- package/dist/cjs/core/fetcher/makeRequest.js +2 -0
- package/dist/cjs/core/fetcher/requestWithRetries.js +9 -0
- package/dist/cjs/core/fetcher/signals.d.ts +7 -1
- package/dist/cjs/core/fetcher/signals.js +12 -0
- package/dist/cjs/core/headers.d.ts +2 -2
- package/dist/cjs/core/headers.js +4 -6
- package/dist/cjs/core/index.d.ts +0 -1
- package/dist/cjs/core/index.js +1 -2
- package/dist/cjs/core/runtime/runtime.js +10 -11
- package/dist/cjs/core/url/join.js +1 -0
- package/dist/cjs/errors/PaidError.js +1 -5
- package/dist/cjs/errors/PaidTimeoutError.js +1 -5
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -4
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +2 -2
- package/dist/cjs/integrations/adapters/expressjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +16 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +28 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +15 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +21 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -0
- package/dist/cjs/integrations/controllers/index.js +3 -1
- package/dist/cjs/integrations/controllers/orders.js +52 -17
- package/dist/cjs/integrations/controllers/plans.d.ts +50 -0
- package/dist/cjs/integrations/controllers/plans.js +88 -0
- package/dist/cjs/integrations/types.d.ts +5 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +4 -17
- package/dist/esm/BaseClient.mjs +1 -24
- package/dist/esm/Client.d.mts +28 -28
- package/dist/esm/Client.mjs +27 -19
- package/dist/esm/api/errors/BadRequestError.mjs +1 -5
- package/dist/esm/api/errors/ForbiddenError.mjs +1 -5
- package/dist/esm/api/errors/InternalServerError.mjs +1 -5
- package/dist/esm/api/errors/NotFoundError.mjs +1 -5
- package/dist/esm/api/resources/agents/client/Client.d.mts +23 -22
- package/dist/esm/api/resources/agents/client/Client.mjs +157 -54
- package/dist/esm/api/resources/contacts/client/Client.d.mts +19 -18
- package/dist/esm/api/resources/contacts/client/Client.mjs +121 -42
- package/dist/esm/api/resources/customers/client/Client.d.mts +37 -36
- package/dist/esm/api/resources/customers/client/Client.mjs +314 -112
- package/dist/esm/api/resources/orders/client/Client.d.mts +28 -27
- package/dist/esm/api/resources/orders/client/Client.mjs +177 -62
- package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +9 -8
- package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +31 -12
- package/dist/esm/api/resources/plans/client/Client.d.mts +25 -12
- package/dist/esm/api/resources/plans/client/Client.mjs +142 -32
- package/dist/esm/api/resources/products/client/Client.d.mts +23 -22
- package/dist/esm/api/resources/products/client/Client.mjs +157 -54
- package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -1
- package/dist/esm/api/resources/products/client/requests/index.mjs +1 -1
- package/dist/esm/api/resources/traces/client/Client.d.mts +9 -8
- package/dist/esm/api/resources/traces/client/Client.mjs +56 -22
- package/dist/esm/api/resources/usage/client/Client.d.mts +16 -15
- package/dist/esm/api/resources/usage/client/Client.mjs +70 -27
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +3 -3
- package/dist/esm/api/types/PlanWithFeatures.d.mts +34 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +2 -0
- package/dist/esm/api/types/SignalV2.d.mts +5 -5
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +1 -4
- package/dist/esm/core/auth/BearerToken.d.mts +1 -3
- package/dist/esm/core/auth/BearerToken.mjs +6 -7
- package/dist/esm/core/auth/index.d.mts +0 -1
- package/dist/esm/core/auth/index.mjs +0 -1
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +7 -6
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -10
- package/dist/esm/core/fetcher/Fetcher.mjs +10 -204
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +4 -0
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +3 -0
- package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
- package/dist/esm/core/fetcher/getRequestBody.mjs +0 -4
- package/dist/esm/core/fetcher/getResponseBody.mjs +4 -18
- package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +2 -0
- package/dist/esm/core/fetcher/requestWithRetries.mjs +9 -0
- package/dist/esm/core/fetcher/signals.d.mts +7 -1
- package/dist/esm/core/fetcher/signals.mjs +12 -0
- package/dist/esm/core/headers.d.mts +2 -2
- package/dist/esm/core/headers.mjs +4 -6
- package/dist/esm/core/index.d.mts +0 -1
- package/dist/esm/core/index.mjs +0 -1
- package/dist/esm/core/runtime/runtime.mjs +10 -11
- package/dist/esm/core/url/join.mjs +1 -0
- package/dist/esm/errors/PaidError.mjs +1 -5
- package/dist/esm/errors/PaidTimeoutError.mjs +1 -5
- package/dist/esm/index.d.mts +0 -1
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +2 -2
- package/dist/esm/integrations/adapters/expressjs/index.mjs +2 -2
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +16 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +27 -0
- package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
- package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
- package/dist/esm/integrations/adapters/nextjs/routes.d.mts +15 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +20 -0
- package/dist/esm/integrations/controllers/index.d.mts +1 -0
- package/dist/esm/integrations/controllers/index.mjs +1 -0
- package/dist/esm/integrations/controllers/orders.mjs +52 -17
- package/dist/esm/integrations/controllers/plans.d.mts +50 -0
- package/dist/esm/integrations/controllers/plans.mjs +84 -0
- package/dist/esm/integrations/types.d.mts +5 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +38 -7
- package/reference.md +106 -57
- package/dist/cjs/auth/BearerAuthProvider.d.ts +0 -20
- package/dist/cjs/auth/BearerAuthProvider.js +0 -79
- package/dist/cjs/auth/index.d.ts +0 -1
- package/dist/cjs/auth/index.js +0 -5
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +0 -5
- package/dist/cjs/core/auth/NoOpAuthProvider.js +0 -9
- package/dist/cjs/core/exports.d.ts +0 -1
- package/dist/cjs/core/exports.js +0 -17
- package/dist/cjs/core/logging/exports.d.ts +0 -18
- package/dist/cjs/core/logging/exports.js +0 -45
- package/dist/cjs/core/logging/index.d.ts +0 -1
- package/dist/cjs/core/logging/index.js +0 -17
- package/dist/cjs/core/logging/logger.d.ts +0 -126
- package/dist/cjs/core/logging/logger.js +0 -144
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +0 -2
- package/dist/cjs/errors/handleNonStatusCodeError.js +0 -65
- package/dist/cjs/exports.d.ts +0 -1
- package/dist/cjs/exports.js +0 -17
- package/dist/esm/auth/BearerAuthProvider.d.mts +0 -20
- package/dist/esm/auth/BearerAuthProvider.mjs +0 -42
- package/dist/esm/auth/index.d.mts +0 -1
- package/dist/esm/auth/index.mjs +0 -1
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +0 -5
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +0 -5
- package/dist/esm/core/exports.d.mts +0 -1
- package/dist/esm/core/exports.mjs +0 -1
- package/dist/esm/core/logging/exports.d.mts +0 -18
- package/dist/esm/core/logging/exports.mjs +0 -9
- package/dist/esm/core/logging/index.d.mts +0 -1
- package/dist/esm/core/logging/index.mjs +0 -1
- package/dist/esm/core/logging/logger.d.mts +0 -126
- package/dist/esm/core/logging/logger.mjs +0 -138
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +0 -2
- package/dist/esm/errors/handleNonStatusCodeError.mjs +0 -29
- package/dist/esm/exports.d.mts +0 -1
- package/dist/esm/exports.mjs +0 -1
|
@@ -9,6 +9,7 @@ import { createCustomersHandler, createGetCustomerHandler } from "../../controll
|
|
|
9
9
|
import { createOrdersHandler } from "../../controllers/orders.mjs";
|
|
10
10
|
import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
|
|
11
11
|
import { createActivateOrderSyncHandler, createPayInvoiceHandler, createSetupIntentHandler, } from "../../controllers/billing.mjs";
|
|
12
|
+
import { createGetPlanGroupByIdHandler } from "../../controllers/plans.mjs";
|
|
12
13
|
/**
|
|
13
14
|
* Helper to extract headers from Express Request
|
|
14
15
|
*/
|
|
@@ -265,3 +266,29 @@ export function createSetupIntentRoute(config = {}) {
|
|
|
265
266
|
};
|
|
266
267
|
return route;
|
|
267
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Create an Express handler for getting a plan group by ID
|
|
271
|
+
*
|
|
272
|
+
* @param config - Handler configuration options
|
|
273
|
+
* @returns Express route handler function
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* import express from 'express';
|
|
278
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/express';
|
|
279
|
+
*
|
|
280
|
+
* const app = express();
|
|
281
|
+
* app.get('/paid/plans/:planGroupId', createGetPlanGroupByIdRoute());
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export function createGetPlanGroupByIdRoute(config = {}) {
|
|
285
|
+
const handler = createGetPlanGroupByIdHandler();
|
|
286
|
+
return (req, res) => {
|
|
287
|
+
return handler({
|
|
288
|
+
body: req.body,
|
|
289
|
+
headers: extractHeaders(req),
|
|
290
|
+
method: "GET",
|
|
291
|
+
params: req.params,
|
|
292
|
+
}, createExpressJSResponseContext(res), config);
|
|
293
|
+
};
|
|
294
|
+
}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Next.js API Route handlers for Paid integration
|
|
3
3
|
* Drop-in handlers for Next.js App Router
|
|
4
4
|
*/
|
|
5
|
-
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from
|
|
5
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createGetPlanGroupByIdRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from "./routes.mjs";
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Next.js API Route handlers for Paid integration
|
|
3
3
|
* Drop-in handlers for Next.js App Router
|
|
4
4
|
*/
|
|
5
|
-
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, } from
|
|
5
|
+
export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createGetPlanGroupByIdRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, } from "./routes.mjs";
|
|
@@ -224,4 +224,19 @@ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
|
|
|
224
224
|
* ```
|
|
225
225
|
*/
|
|
226
226
|
export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): NextJsHandler;
|
|
227
|
+
/**
|
|
228
|
+
* Create a Next.js API route handler for getting a plan group by ID
|
|
229
|
+
*
|
|
230
|
+
* @param config - Handler configuration options
|
|
231
|
+
* @returns Next.js route handler function
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // src/app/api/plans/[planGroupId]/route.ts
|
|
236
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/nextjs';
|
|
237
|
+
*
|
|
238
|
+
* export const GET = createGetPlanGroupByIdRoute();
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export declare function createGetPlanGroupByIdRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
|
|
227
242
|
export {};
|
|
@@ -5,6 +5,7 @@ import { createCustomersHandler, createGetCustomerHandler } from "../../controll
|
|
|
5
5
|
import { createOrdersHandler } from "../../controllers/orders.mjs";
|
|
6
6
|
import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
|
|
7
7
|
import { createActivateOrderSyncHandler, createPayInvoiceHandler, createSetupIntentHandler } from "../../controllers/billing.mjs";
|
|
8
|
+
import { createGetPlanGroupByIdHandler } from "../../controllers/plans.mjs";
|
|
8
9
|
/**
|
|
9
10
|
* Create a Next.js API route handler for synchronous order activation
|
|
10
11
|
*
|
|
@@ -242,3 +243,22 @@ export function createSetupIntentRoute(config = {}) {
|
|
|
242
243
|
const route = (request, context) => adaptedHandler(request, context, config);
|
|
243
244
|
return route;
|
|
244
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Create a Next.js API route handler for getting a plan group by ID
|
|
248
|
+
*
|
|
249
|
+
* @param config - Handler configuration options
|
|
250
|
+
* @returns Next.js route handler function
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* // src/app/api/plans/[planGroupId]/route.ts
|
|
255
|
+
* import { createGetPlanGroupByIdRoute } from '@paid-ai/paid-node/integrations/nextjs';
|
|
256
|
+
*
|
|
257
|
+
* export const GET = createGetPlanGroupByIdRoute();
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
export function createGetPlanGroupByIdRoute(config = {}) {
|
|
261
|
+
const handler = createGetPlanGroupByIdHandler();
|
|
262
|
+
const adaptedHandler = nextjsAdapter(handler);
|
|
263
|
+
return (request, context) => adaptedHandler(request, context, config);
|
|
264
|
+
}
|
|
@@ -4,3 +4,4 @@ export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./or
|
|
|
4
4
|
export { payInvoice, createPayInvoiceHandler, type PayInvoiceConfig, type PayInvoiceRequest, type PayInvoiceResult, activateOrderSync, createActivateOrderSyncHandler, type ActivateOrderSyncConfig, type ActivateOrderSyncRequest, type ActivateOrderSyncResult, createSetupIntent, createSetupIntentHandler, type SetupIntentConfig, type SetupIntentRequest, type SetupIntentResponse, } from "./billing.mjs";
|
|
5
5
|
export { getCustomerInvoices, createCustomerInvoicesHandler, type CustomerInvoicesResult, } from "./invoices.mjs";
|
|
6
6
|
export { provisionNewUser, createProvisioningHandler, } from "./provision-users.mjs";
|
|
7
|
+
export { createGetPlanGroupByIdHandler, } from "./plans.mjs";
|
|
@@ -4,3 +4,4 @@ export { createOrder, createOrderWithDefaults, createOrdersHandler, } from "./or
|
|
|
4
4
|
export { payInvoice, createPayInvoiceHandler, activateOrderSync, createActivateOrderSyncHandler, createSetupIntent, createSetupIntentHandler, } from "./billing.mjs";
|
|
5
5
|
export { getCustomerInvoices, createCustomerInvoicesHandler, } from "./invoices.mjs";
|
|
6
6
|
export { provisionNewUser, createProvisioningHandler, } from "./provision-users.mjs";
|
|
7
|
+
export { createGetPlanGroupByIdHandler, } from "./plans.mjs";
|
|
@@ -8,11 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { createHandler } from "../utils/base-handler.mjs";
|
|
11
|
+
import { getPlanById } from "./plans.mjs";
|
|
12
|
+
function hasProductWithExternalId(pp) {
|
|
13
|
+
if (!pp.product) {
|
|
14
|
+
throw new Error(`Plan product ${pp.id} is missing nested product data`);
|
|
15
|
+
}
|
|
16
|
+
return !!pp.product.externalId;
|
|
17
|
+
}
|
|
11
18
|
/**
|
|
12
19
|
* Generate default values for missing order fields
|
|
13
20
|
*/
|
|
14
21
|
function generateOrderDefaults(config, options = {}) {
|
|
15
|
-
var _a;
|
|
16
22
|
const { defaultDurationDays = 365 } = options;
|
|
17
23
|
const startDate = config.startDate || new Date().toISOString().split("T")[0];
|
|
18
24
|
const endDate = config.endDate ||
|
|
@@ -22,20 +28,31 @@ function generateOrderDefaults(config, options = {}) {
|
|
|
22
28
|
const name = config.name || "Subscription Order";
|
|
23
29
|
const description = config.description || "Annual subscription";
|
|
24
30
|
const currency = config.currency || "USD";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// defensive guard
|
|
32
|
+
if (!config.orderLines && !config.planId && !config.agentExternalId) {
|
|
33
|
+
throw new Error("Either orderLines, planId, or agentExternalId must be provided");
|
|
34
|
+
}
|
|
35
|
+
const orderLines = config.orderLines
|
|
36
|
+
? config.orderLines.map(line => {
|
|
37
|
+
var _a;
|
|
38
|
+
return ({
|
|
39
|
+
agentExternalId: line.agentExternalId,
|
|
40
|
+
name: line.name || name,
|
|
41
|
+
description: line.description || description,
|
|
42
|
+
planProductId: (_a = line.planProductId) !== null && _a !== void 0 ? _a : undefined,
|
|
43
|
+
});
|
|
44
|
+
})
|
|
45
|
+
: [{
|
|
46
|
+
agentExternalId: config.agentExternalId,
|
|
47
|
+
name,
|
|
48
|
+
description,
|
|
49
|
+
}];
|
|
34
50
|
return {
|
|
35
51
|
customerId: config.customerId,
|
|
36
52
|
customerExternalId: config.customerExternalId,
|
|
37
53
|
billingContactId: config.billingContactId,
|
|
38
54
|
agentExternalId: config.agentExternalId,
|
|
55
|
+
planId: config.planId,
|
|
39
56
|
name,
|
|
40
57
|
description,
|
|
41
58
|
startDate,
|
|
@@ -64,8 +81,12 @@ function createAndActivateOrder(client, config, autoActivate) {
|
|
|
64
81
|
orderLine.name = line.name;
|
|
65
82
|
if (line.description)
|
|
66
83
|
orderLine.description = line.description;
|
|
84
|
+
// planProductId is not in the create orders api spec - this is functioning but greptile will complain
|
|
85
|
+
if (line.planProductId)
|
|
86
|
+
orderLine.planProductId = line.planProductId;
|
|
67
87
|
return orderLine;
|
|
68
88
|
}),
|
|
89
|
+
planId: config.planId,
|
|
69
90
|
});
|
|
70
91
|
if (!order.id) {
|
|
71
92
|
throw new Error("Order created but missing ID");
|
|
@@ -172,18 +193,32 @@ export function createOrder(client_1, config_1) {
|
|
|
172
193
|
*/
|
|
173
194
|
export function createOrdersHandler(helperOptions) {
|
|
174
195
|
return createHandler((client, body) => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
var _a, _b;
|
|
176
|
-
if (!body.customerId) {
|
|
177
|
-
throw new Error("customerId is required");
|
|
178
|
-
}
|
|
196
|
+
var _a, _b, _c;
|
|
179
197
|
if (!body.customerExternalId) {
|
|
180
198
|
throw new Error("customerExternalId is required");
|
|
181
199
|
}
|
|
182
|
-
if (!body.agentExternalId) {
|
|
183
|
-
throw new Error("agentExternalId
|
|
200
|
+
if (!body.agentExternalId && !body.planId) {
|
|
201
|
+
throw new Error("agentExternalId or planId are required");
|
|
184
202
|
}
|
|
185
203
|
const orderOptions = Object.assign(Object.assign({}, helperOptions), { autoActivate: (_b = (_a = body.autoActivate) !== null && _a !== void 0 ? _a : helperOptions === null || helperOptions === void 0 ? void 0 : helperOptions.autoActivate) !== null && _b !== void 0 ? _b : true });
|
|
204
|
+
if (body.planId) {
|
|
205
|
+
const plan = yield getPlanById(client, body.planId);
|
|
206
|
+
if (!((_c = plan.planProducts) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
207
|
+
throw new Error(`Plan ${body.planId} has no products`);
|
|
208
|
+
}
|
|
209
|
+
body.orderLines = plan.planProducts
|
|
210
|
+
.filter(hasProductWithExternalId)
|
|
211
|
+
.map((pp) => ({
|
|
212
|
+
agentExternalId: pp.product.externalId,
|
|
213
|
+
name: pp.product.name,
|
|
214
|
+
description: pp.product.description,
|
|
215
|
+
planProductId: pp.id,
|
|
216
|
+
}));
|
|
217
|
+
if (body.orderLines.length === 0) {
|
|
218
|
+
throw new Error(`Plan ${body.planId} has no products with externalId`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
186
221
|
const order = yield createOrderWithDefaults(client, body, orderOptions);
|
|
187
222
|
return { success: true, data: order };
|
|
188
|
-
}), { requiredFields: ['
|
|
223
|
+
}), { requiredFields: ['customerExternalId'] });
|
|
189
224
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Get a plan by ID
|
|
6
|
+
*
|
|
7
|
+
* @param client - PaidClient instance
|
|
8
|
+
* @param planId - Plan's ID
|
|
9
|
+
* @returns Plan data
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const plan = await getPlanById(client, 'plan-123');
|
|
14
|
+
* console.log(plan.name, plan.id);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPlanById(client: PaidClient, planId: string): Promise<Plan>;
|
|
18
|
+
/**
|
|
19
|
+
* Get a plan group by ID
|
|
20
|
+
*
|
|
21
|
+
* @param client - PaidClient instance
|
|
22
|
+
* @param planGroupId - Plan group's ID
|
|
23
|
+
* @returns Plan group data
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const planGroup = await getPlanGroupById(client, 'plan-group-123');
|
|
28
|
+
* console.log(planGroup.name, planGroup.id);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function getPlanGroupById(client: PaidClient, planGroupId: string): Promise<PlanGroup>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a framework-agnostic handler for fetching a plan group by ID
|
|
34
|
+
*
|
|
35
|
+
* This handler can be used with any framework adapter.
|
|
36
|
+
* The plan group ID should be provided either in params or query string.
|
|
37
|
+
*
|
|
38
|
+
* @returns Handler function
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // In Next.js route: /api/plans/[planGroupId]/route.ts
|
|
43
|
+
* import { createGetPlanGroupByIdHandler } from '@paid-ai/paid-node/integrations';
|
|
44
|
+
* import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
|
|
45
|
+
*
|
|
46
|
+
* const handler = createGetPlanGroupByIdHandler();
|
|
47
|
+
* export const GET = nextjsAdapter(handler);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function createGetPlanGroupByIdHandler(): (request: any, response: any, config?: any) => Promise<any>;
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -41,18 +41,20 @@ export interface OrderConfig {
|
|
|
41
41
|
customerId: string;
|
|
42
42
|
customerExternalId: string;
|
|
43
43
|
billingContactId?: string;
|
|
44
|
-
agentExternalId
|
|
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
|
|
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
|
/**
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.1-alpha1";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.1-alpha1";
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paid-ai/paid-node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"repository":
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/paid-ai/paid-node.git"
|
|
8
|
-
},
|
|
5
|
+
"repository": "github:paid-ai/paid-node",
|
|
9
6
|
"type": "commonjs",
|
|
10
7
|
"main": "./dist/cjs/index.js",
|
|
11
8
|
"module": "./dist/esm/index.mjs",
|
|
@@ -241,9 +238,43 @@
|
|
|
241
238
|
"path": false,
|
|
242
239
|
"stream": false
|
|
243
240
|
},
|
|
244
|
-
"packageManager": "pnpm@10.
|
|
241
|
+
"packageManager": "pnpm@10.14.0",
|
|
245
242
|
"engines": {
|
|
246
243
|
"node": ">=18.0.0"
|
|
247
244
|
},
|
|
248
|
-
"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
|
+
}
|
|
249
280
|
}
|