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

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 (77) hide show
  1. package/README.md +4 -4
  2. package/dist/cjs/Client.js +2 -2
  3. package/dist/cjs/api/resources/index.d.ts +1 -0
  4. package/dist/cjs/api/resources/index.js +1 -0
  5. package/dist/cjs/api/resources/plans/client/Client.d.ts +17 -0
  6. package/dist/cjs/api/resources/plans/client/Client.js +70 -0
  7. package/dist/cjs/api/resources/plans/client/requests/PlansGetCurrentRequest.d.ts +15 -0
  8. package/dist/cjs/api/resources/plans/client/requests/PlansGetCurrentRequest.js +3 -0
  9. package/dist/cjs/api/resources/plans/client/requests/index.d.ts +1 -0
  10. package/dist/cjs/api/resources/plans/index.d.ts +1 -0
  11. package/dist/cjs/api/resources/plans/index.js +1 -0
  12. package/dist/cjs/api/resources/plans/types/PlansGetCurrentResponse.d.ts +83 -0
  13. package/dist/cjs/api/resources/plans/types/PlansGetCurrentResponse.js +16 -0
  14. package/dist/cjs/api/resources/plans/types/index.d.ts +1 -0
  15. package/dist/cjs/api/resources/plans/types/index.js +17 -0
  16. package/dist/cjs/api/types/Plan.d.ts +1 -24
  17. package/dist/cjs/api/types/Plan.js +0 -9
  18. package/dist/cjs/api/types/PlanPricing.d.ts +23 -0
  19. package/dist/cjs/api/types/PlanPricing.js +15 -0
  20. package/dist/cjs/api/types/PlanWithFeatures.d.ts +2 -24
  21. package/dist/cjs/api/types/PlanWithFeatures.js +0 -9
  22. package/dist/cjs/api/types/index.d.ts +1 -0
  23. package/dist/cjs/api/types/index.js +1 -0
  24. package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
  25. package/dist/cjs/integrations/adapters/nextjs/index.js +2 -1
  26. package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +16 -0
  27. package/dist/cjs/integrations/adapters/nextjs/routes.js +21 -0
  28. package/dist/cjs/integrations/controllers/index.d.ts +1 -1
  29. package/dist/cjs/integrations/controllers/index.js +3 -1
  30. package/dist/cjs/integrations/controllers/plans.d.ts +40 -0
  31. package/dist/cjs/integrations/controllers/plans.js +62 -0
  32. package/dist/cjs/tracing/autoInstrumentation.d.ts +1 -1
  33. package/dist/cjs/tracing/autoInstrumentation.js +115 -39
  34. package/dist/cjs/tracing/signal.js +1 -4
  35. package/dist/cjs/tracing/spanProcessor.js +12 -0
  36. package/dist/cjs/tracing/tracing.js +3 -6
  37. package/dist/cjs/version.d.ts +1 -1
  38. package/dist/cjs/version.js +1 -1
  39. package/dist/esm/Client.mjs +2 -2
  40. package/dist/esm/api/resources/index.d.mts +1 -0
  41. package/dist/esm/api/resources/index.mjs +1 -0
  42. package/dist/esm/api/resources/plans/client/Client.d.mts +17 -0
  43. package/dist/esm/api/resources/plans/client/Client.mjs +70 -0
  44. package/dist/esm/api/resources/plans/client/requests/PlansGetCurrentRequest.d.mts +15 -0
  45. package/dist/esm/api/resources/plans/client/requests/PlansGetCurrentRequest.mjs +2 -0
  46. package/dist/esm/api/resources/plans/client/requests/index.d.mts +1 -0
  47. package/dist/esm/api/resources/plans/index.d.mts +1 -0
  48. package/dist/esm/api/resources/plans/index.mjs +1 -0
  49. package/dist/esm/api/resources/plans/types/PlansGetCurrentResponse.d.mts +83 -0
  50. package/dist/esm/api/resources/plans/types/PlansGetCurrentResponse.mjs +13 -0
  51. package/dist/esm/api/resources/plans/types/index.d.mts +1 -0
  52. package/dist/esm/api/resources/plans/types/index.mjs +1 -0
  53. package/dist/esm/api/types/Plan.d.mts +1 -24
  54. package/dist/esm/api/types/Plan.mjs +0 -9
  55. package/dist/esm/api/types/PlanPricing.d.mts +23 -0
  56. package/dist/esm/api/types/PlanPricing.mjs +12 -0
  57. package/dist/esm/api/types/PlanWithFeatures.d.mts +2 -24
  58. package/dist/esm/api/types/PlanWithFeatures.mjs +0 -9
  59. package/dist/esm/api/types/index.d.mts +1 -0
  60. package/dist/esm/api/types/index.mjs +1 -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 +16 -0
  64. package/dist/esm/integrations/adapters/nextjs/routes.mjs +21 -1
  65. package/dist/esm/integrations/controllers/index.d.mts +1 -1
  66. package/dist/esm/integrations/controllers/index.mjs +1 -1
  67. package/dist/esm/integrations/controllers/plans.d.mts +40 -0
  68. package/dist/esm/integrations/controllers/plans.mjs +60 -0
  69. package/dist/esm/tracing/autoInstrumentation.d.mts +1 -1
  70. package/dist/esm/tracing/autoInstrumentation.mjs +82 -39
  71. package/dist/esm/tracing/signal.mjs +1 -4
  72. package/dist/esm/tracing/spanProcessor.mjs +12 -0
  73. package/dist/esm/tracing/tracing.mjs +3 -6
  74. package/dist/esm/version.d.mts +1 -1
  75. package/dist/esm/version.mjs +1 -1
  76. package/package.json +1 -1
  77. package/reference.md +65 -0
@@ -15,8 +15,7 @@ export interface Plan {
15
15
  description?: string;
16
16
  /** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
17
17
  type: Plan.Type;
18
- /** The pricing configuration for the plan */
19
- pricing: Plan.Pricing;
18
+ pricing: Paid.PlanPricing;
20
19
  /** The ID of the next plan in the sequence */
21
20
  nextPlanId?: string;
22
21
  /** The ID of the previous plan in the sequence */
@@ -36,28 +35,6 @@ export declare namespace Plan {
36
35
  readonly Credit: "credit";
37
36
  };
38
37
  type Type = (typeof Type)[keyof typeof Type];
39
- /**
40
- * The pricing configuration for the plan
41
- */
42
- interface Pricing {
43
- /** The currency code (e.g., "USD", "EUR") */
44
- currency: string;
45
- /** The fixed amount for flat plans (in smallest currency unit, e.g., cents) */
46
- amount?: number;
47
- /** The billing frequency for the plan */
48
- billingFrequency: Pricing.BillingFrequency;
49
- /** Custom billing frequency in months (if not using standard frequencies) */
50
- billingFrequencyCustomMonths?: number;
51
- }
52
- namespace Pricing {
53
- /** The billing frequency for the plan */
54
- const BillingFrequency: {
55
- readonly Monthly: "monthly";
56
- readonly Quarterly: "quarterly";
57
- readonly Annual: "annual";
58
- };
59
- type BillingFrequency = (typeof BillingFrequency)[keyof typeof BillingFrequency];
60
- }
61
38
  type PlanProducts = PlanProducts.Item[];
62
39
  namespace PlanProducts {
63
40
  interface Item {
@@ -7,13 +7,4 @@ export var Plan;
7
7
  Usage: "usage",
8
8
  Credit: "credit",
9
9
  };
10
- let Pricing;
11
- (function (Pricing) {
12
- /** The billing frequency for the plan */
13
- Pricing.BillingFrequency = {
14
- Monthly: "monthly",
15
- Quarterly: "quarterly",
16
- Annual: "annual",
17
- };
18
- })(Pricing = Plan.Pricing || (Plan.Pricing = {}));
19
10
  })(Plan || (Plan = {}));
@@ -0,0 +1,23 @@
1
+ import type * as Paid from "../index.mjs";
2
+ /**
3
+ * The pricing configuration for a plan. Uses the same PricePoints structure as product pricing.
4
+ */
5
+ export interface PlanPricing {
6
+ /** Price points keyed by currency code (e.g., "USD", "EUR") */
7
+ PricePoints: Record<string, Paid.PricePoint>;
8
+ /** The billing frequency for the plan */
9
+ billingFrequency: PlanPricing.BillingFrequency;
10
+ /** Custom billing frequency in months (when billingFrequency is "custom") */
11
+ billingFrequencyCustomMonths?: number;
12
+ }
13
+ export declare namespace PlanPricing {
14
+ /** The billing frequency for the plan */
15
+ const BillingFrequency: {
16
+ readonly Monthly: "monthly";
17
+ readonly Quarterly: "quarterly";
18
+ readonly SemiAnnually: "semi-annually";
19
+ readonly Yearly: "yearly";
20
+ readonly Custom: "custom";
21
+ };
22
+ type BillingFrequency = (typeof BillingFrequency)[keyof typeof BillingFrequency];
23
+ }
@@ -0,0 +1,12 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export var PlanPricing;
3
+ (function (PlanPricing) {
4
+ /** The billing frequency for the plan */
5
+ PlanPricing.BillingFrequency = {
6
+ Monthly: "monthly",
7
+ Quarterly: "quarterly",
8
+ SemiAnnually: "semi-annually",
9
+ Yearly: "yearly",
10
+ Custom: "custom",
11
+ };
12
+ })(PlanPricing || (PlanPricing = {}));
@@ -1,3 +1,4 @@
1
+ import type * as Paid from "../index.mjs";
1
2
  /**
2
3
  * A plan with its features (product-attribute pairs) for display
3
4
  */
@@ -10,8 +11,7 @@ export interface PlanWithFeatures {
10
11
  description?: string;
11
12
  /** The type of plan (flat for fixed pricing, usage for usage-based, credit for prepaid credits) */
12
13
  type: PlanWithFeatures.Type;
13
- /** The pricing configuration for the plan */
14
- pricing: PlanWithFeatures.Pricing;
14
+ pricing: Paid.PlanPricing;
15
15
  /** When the plan was created */
16
16
  createdAt: string;
17
17
  /** When the plan was last updated */
@@ -31,28 +31,6 @@ export declare namespace PlanWithFeatures {
31
31
  readonly Credit: "credit";
32
32
  };
33
33
  type Type = (typeof Type)[keyof typeof Type];
34
- /**
35
- * The pricing configuration for the plan
36
- */
37
- interface Pricing {
38
- /** The currency code (e.g., "USD", "EUR") */
39
- currency: string;
40
- /** The fixed amount for flat plans (in smallest currency unit, e.g., cents) */
41
- amount?: number;
42
- /** The billing frequency for the plan */
43
- billingFrequency: Pricing.BillingFrequency;
44
- /** Custom billing frequency in months (if not using standard frequencies) */
45
- billingFrequencyCustomMonths?: number;
46
- }
47
- namespace Pricing {
48
- /** The billing frequency for the plan */
49
- const BillingFrequency: {
50
- readonly Monthly: "monthly";
51
- readonly Quarterly: "quarterly";
52
- readonly Annual: "annual";
53
- };
54
- type BillingFrequency = (typeof BillingFrequency)[keyof typeof BillingFrequency];
55
- }
56
34
  type Features = Features.Item[];
57
35
  namespace Features {
58
36
  interface Item {
@@ -7,13 +7,4 @@ export var PlanWithFeatures;
7
7
  Usage: "usage",
8
8
  Credit: "credit",
9
9
  };
10
- let Pricing;
11
- (function (Pricing) {
12
- /** The billing frequency for the plan */
13
- Pricing.BillingFrequency = {
14
- Monthly: "monthly",
15
- Quarterly: "quarterly",
16
- Annual: "annual",
17
- };
18
- })(Pricing = PlanWithFeatures.Pricing || (PlanWithFeatures.Pricing = {}));
19
10
  })(PlanWithFeatures || (PlanWithFeatures = {}));
@@ -30,6 +30,7 @@ export * from "./PaginationMeta.mjs";
30
30
  export * from "./PaymentMethod.mjs";
31
31
  export * from "./Plan.mjs";
32
32
  export * from "./PlanGroup.mjs";
33
+ export * from "./PlanPricing.mjs";
33
34
  export * from "./PlanWithFeatures.mjs";
34
35
  export * from "./PricePoint.mjs";
35
36
  export * from "./Pricing.mjs";
@@ -30,6 +30,7 @@ export * from "./PaginationMeta.mjs";
30
30
  export * from "./PaymentMethod.mjs";
31
31
  export * from "./Plan.mjs";
32
32
  export * from "./PlanGroup.mjs";
33
+ export * from "./PlanPricing.mjs";
33
34
  export * from "./PlanWithFeatures.mjs";
34
35
  export * from "./PricePoint.mjs";
35
36
  export * from "./Pricing.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, createGetPlanGroupByIdRoute, createGetGroupPlansRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, createSubscribeRoute, createUnsubscribeRoute, createUpgradeRoute, type ActivateOrderSyncRouteConfig, type OrdersRouteConfig, type ProvisioningRouteConfig, type SetupIntentRouteConfig, } from "./routes.mjs";
5
+ export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createGetPlanGroupByIdRoute, createGetGroupPlansRoute, createGetCurrentRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, createSubscribeRoute, createUnsubscribeRoute, createUpgradeRoute, 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, createGetPlanGroupByIdRoute, createGetGroupPlansRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, createSubscribeRoute, createUnsubscribeRoute, createUpgradeRoute, } from "./routes.mjs";
5
+ export { createActivateOrderSyncRoute, createContactsRoute, createCustomerInvoicesRoute, createCustomersRoute, createGetCustomerRoute, createGetPlanGroupByIdRoute, createGetGroupPlansRoute, createGetCurrentRoute, createOrdersRoute, createPayInvoiceRoute, createProvisioningRoute, createSetupIntentRoute, createSubscribeRoute, createUnsubscribeRoute, createUpgradeRoute, } from "./routes.mjs";
@@ -299,4 +299,20 @@ export declare function createUnsubscribeRoute(config?: BaseHandlerConfig): (req
299
299
  * ```
300
300
  */
301
301
  export declare function createUpgradeRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
302
+ /**
303
+ * Create a Next.js API route handler for getting a customer's current plan
304
+ *
305
+ * @param config - Handler configuration options
306
+ * @returns Next.js route handler function
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * // src/app/api/plans/current/[customerExternalId]/route.ts
311
+ * // GET /api/plans/current/customer-123
312
+ * import { createGetCurrentRoute } from '@paid-ai/paid-node/integrations/nextjs';
313
+ *
314
+ * export const GET = createGetCurrentRoute();
315
+ * ```
316
+ */
317
+ export declare function createGetCurrentRoute(config?: BaseHandlerConfig): (request: any, context?: any) => Promise<any>;
302
318
  export {};
@@ -5,7 +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, createGetGroupPlansHandler, createSubscribeHandler, createUnsubscribeHandler, createUpgradeHandler } from "../../controllers/plans.mjs";
8
+ import { createGetPlanGroupByIdHandler, createGetGroupPlansHandler, createSubscribeHandler, createUnsubscribeHandler, createUpgradeHandler, createGetCurrentHandler } from "../../controllers/plans.mjs";
9
9
  /**
10
10
  * Create a Next.js API route handler for synchronous order activation
11
11
  *
@@ -338,3 +338,23 @@ export function createUpgradeRoute(config = {}) {
338
338
  const adaptedHandler = nextjsAdapter(handler);
339
339
  return (request, context) => adaptedHandler(request, context, config);
340
340
  }
341
+ /**
342
+ * Create a Next.js API route handler for getting a customer's current plan
343
+ *
344
+ * @param config - Handler configuration options
345
+ * @returns Next.js route handler function
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * // src/app/api/plans/current/[customerExternalId]/route.ts
350
+ * // GET /api/plans/current/customer-123
351
+ * import { createGetCurrentRoute } from '@paid-ai/paid-node/integrations/nextjs';
352
+ *
353
+ * export const GET = createGetCurrentRoute();
354
+ * ```
355
+ */
356
+ export function createGetCurrentRoute(config = {}) {
357
+ const handler = createGetCurrentHandler();
358
+ const adaptedHandler = nextjsAdapter(handler);
359
+ return (request, context) => adaptedHandler(request, context, config);
360
+ }
@@ -4,4 +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 { getPlanById, getPlanGroupById, createGetPlanGroupByIdHandler, getGroupPlans, createGetGroupPlansHandler, subscribe, createSubscribeHandler, unsubscribe, createUnsubscribeHandler, upgrade, createUpgradeHandler, } from "./plans.mjs";
7
+ export { getPlanById, getPlanGroupById, createGetPlanGroupByIdHandler, getGroupPlans, createGetGroupPlansHandler, subscribe, createSubscribeHandler, unsubscribe, createUnsubscribeHandler, upgrade, createUpgradeHandler, getCurrent, createGetCurrentHandler, } from "./plans.mjs";
@@ -4,4 +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 { getPlanById, getPlanGroupById, createGetPlanGroupByIdHandler, getGroupPlans, createGetGroupPlansHandler, subscribe, createSubscribeHandler, unsubscribe, createUnsubscribeHandler, upgrade, createUpgradeHandler, } from "./plans.mjs";
7
+ export { getPlanById, getPlanGroupById, createGetPlanGroupByIdHandler, getGroupPlans, createGetGroupPlansHandler, subscribe, createSubscribeHandler, unsubscribe, createUnsubscribeHandler, upgrade, createUpgradeHandler, getCurrent, createGetCurrentHandler, } from "./plans.mjs";
@@ -8,6 +8,8 @@ import type { ProrationUpgradeResponse } from "../../api/types/ProrationUpgradeR
8
8
  import type { PlansSubscribeRequest } from "../../api/resources/plans/client/requests/PlansSubscribeRequest.mjs";
9
9
  import type { PlansUnsubscribeRequest } from "../../api/resources/plans/client/requests/PlansUnsubscribeRequest.mjs";
10
10
  import type { PlansUpgradeRequest } from "../../api/resources/plans/client/requests/PlansUpgradeRequest.mjs";
11
+ import type { PlansGetCurrentRequest } from "../../api/resources/plans/client/requests/PlansGetCurrentRequest.mjs";
12
+ import type { PlansGetCurrentResponse } from "../../api/resources/plans/types/PlansGetCurrentResponse.mjs";
11
13
  /**
12
14
  * Get a plan by ID
13
15
  *
@@ -206,3 +208,41 @@ export declare function upgrade(client: PaidClient, request: PlansUpgradeRequest
206
208
  * ```
207
209
  */
208
210
  export declare function createUpgradeHandler(): (request: any, response: any, config?: any) => Promise<any>;
211
+ /**
212
+ * Get the currently active plan subscription for a customer
213
+ *
214
+ * Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
215
+ *
216
+ * @param client - PaidClient instance
217
+ * @param request - Get current request with customer external ID
218
+ * @returns Current plan response
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const response = await getCurrent(client, {
223
+ * customerExternalId: 'customer-123'
224
+ * });
225
+ * console.log(response.plan.id);
226
+ * ```
227
+ */
228
+ export declare function getCurrent(client: PaidClient, request: PlansGetCurrentRequest): Promise<PlansGetCurrentResponse>;
229
+ /**
230
+ * Create a framework-agnostic handler for getting a customer's current plan
231
+ *
232
+ * This handler can be used with any framework adapter.
233
+ * The customerExternalId should be provided as a URL parameter.
234
+ *
235
+ * @returns Handler function
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * // In Next.js route: /api/plans/current/[customerExternalId]/route.ts
240
+ * // GET /api/plans/current/customer-123
241
+ * import { createGetCurrentHandler } from '@paid-ai/paid-node/integrations';
242
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
243
+ *
244
+ * const handler = createGetCurrentHandler();
245
+ * export const GET = nextjsAdapter(handler);
246
+ * ```
247
+ */
248
+ export declare function createGetCurrentHandler(): (request: any, response: any, config?: any) => Promise<any>;
@@ -351,3 +351,63 @@ export function createUpgradeHandler() {
351
351
  requireOrganizationId: false,
352
352
  });
353
353
  }
354
+ /**
355
+ * Get the currently active plan subscription for a customer
356
+ *
357
+ * Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
358
+ *
359
+ * @param client - PaidClient instance
360
+ * @param request - Get current request with customer external ID
361
+ * @returns Current plan response
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * const response = await getCurrent(client, {
366
+ * customerExternalId: 'customer-123'
367
+ * });
368
+ * console.log(response.plan.id);
369
+ * ```
370
+ */
371
+ export function getCurrent(client, request) {
372
+ return __awaiter(this, void 0, void 0, function* () {
373
+ const response = yield client.plans.getCurrent(request);
374
+ return response;
375
+ });
376
+ }
377
+ /**
378
+ * Create a framework-agnostic handler for getting a customer's current plan
379
+ *
380
+ * This handler can be used with any framework adapter.
381
+ * The customerExternalId should be provided as a URL parameter.
382
+ *
383
+ * @returns Handler function
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * // In Next.js route: /api/plans/current/[customerExternalId]/route.ts
388
+ * // GET /api/plans/current/customer-123
389
+ * import { createGetCurrentHandler } from '@paid-ai/paid-node/integrations';
390
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
391
+ *
392
+ * const handler = createGetCurrentHandler();
393
+ * export const GET = nextjsAdapter(handler);
394
+ * ```
395
+ */
396
+ export function createGetCurrentHandler() {
397
+ return createHandler((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
398
+ // Support customerExternalId from params (URL/query)
399
+ const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
400
+ if (!customerExternalId) {
401
+ return {
402
+ success: false,
403
+ error: "customerExternalId is required",
404
+ status: 400,
405
+ };
406
+ }
407
+ const response = yield getCurrent(client, { customerExternalId });
408
+ return { success: true, data: response };
409
+ }), {
410
+ allowedMethods: ['GET'],
411
+ requireOrganizationId: false,
412
+ });
413
+ }
@@ -6,5 +6,5 @@ interface SupportedLibraries {
6
6
  anthropic?: typeof anthropic.Anthropic;
7
7
  bedrock?: typeof bedrock;
8
8
  }
9
- export declare function paidAutoInstrument(libraries?: SupportedLibraries): void;
9
+ export declare function paidAutoInstrument(libraries?: SupportedLibraries): Promise<void>;
10
10
  export {};
@@ -1,54 +1,97 @@
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
+ };
1
10
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
2
- import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
3
- import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
4
- import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic";
5
11
  import { getPaidTracerProvider, initializeTracing, logger } from "./tracing.mjs";
6
12
  let IS_INITIALIZED = false;
7
- const getInstrumentations = (tracerProvider) => {
8
- const instrumentations = [
9
- new OpenAIInstrumentation({ tracerProvider }),
10
- new AnthropicInstrumentation({ tracerProvider }),
11
- new BedrockInstrumentation(),
12
- ];
13
+ const getInstrumentations = (tracerProvider) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const instrumentations = [];
15
+ try {
16
+ const { OpenAIInstrumentation } = yield import("@arizeai/openinference-instrumentation-openai");
17
+ instrumentations.push(new OpenAIInstrumentation({ tracerProvider }));
18
+ }
19
+ catch (_a) {
20
+ logger.debug("OpenAI instrumentation not available - openai package not installed");
21
+ }
22
+ try {
23
+ const { AnthropicInstrumentation } = yield import("@arizeai/openinference-instrumentation-anthropic");
24
+ instrumentations.push(new AnthropicInstrumentation({ tracerProvider }));
25
+ }
26
+ catch (_b) {
27
+ logger.debug("Anthropic instrumentation not available - @anthropic-ai/sdk package not installed");
28
+ }
29
+ try {
30
+ const { BedrockInstrumentation } = yield import("@traceloop/instrumentation-bedrock");
31
+ instrumentations.push(new BedrockInstrumentation());
32
+ }
33
+ catch (_c) {
34
+ logger.debug("Bedrock instrumentation not available - @aws-sdk/client-bedrock-runtime package not installed");
35
+ }
13
36
  return instrumentations;
14
- };
15
- const getManualInstrumentations = (tracerProvider, libraries) => {
37
+ });
38
+ const getManualInstrumentations = (tracerProvider, libraries) => __awaiter(void 0, void 0, void 0, function* () {
16
39
  const instrumentations = [];
17
40
  if (libraries.openai) {
18
- const openaiInstrumentation = new OpenAIInstrumentation({ tracerProvider });
19
- instrumentations.push(openaiInstrumentation);
20
- openaiInstrumentation.manuallyInstrument(libraries.openai);
41
+ try {
42
+ const { OpenAIInstrumentation } = yield import("@arizeai/openinference-instrumentation-openai");
43
+ const openaiInstrumentation = new OpenAIInstrumentation({ tracerProvider });
44
+ instrumentations.push(openaiInstrumentation);
45
+ openaiInstrumentation.manuallyInstrument(libraries.openai);
46
+ }
47
+ catch (_a) {
48
+ logger.warn("Failed to load OpenAI instrumentation");
49
+ }
21
50
  }
22
51
  if (libraries.anthropic) {
23
- const anthropicInstrumentation = new AnthropicInstrumentation({ tracerProvider });
24
- instrumentations.push(anthropicInstrumentation);
25
- anthropicInstrumentation.manuallyInstrument(libraries.anthropic);
52
+ try {
53
+ const { AnthropicInstrumentation } = yield import("@arizeai/openinference-instrumentation-anthropic");
54
+ const anthropicInstrumentation = new AnthropicInstrumentation({ tracerProvider });
55
+ instrumentations.push(anthropicInstrumentation);
56
+ anthropicInstrumentation.manuallyInstrument(libraries.anthropic);
57
+ }
58
+ catch (_b) {
59
+ logger.warn("Failed to load Anthropic instrumentation");
60
+ }
26
61
  }
27
62
  if (libraries.bedrock) {
28
- const bedrockInstrumentation = new BedrockInstrumentation();
29
- instrumentations.push(bedrockInstrumentation);
30
- bedrockInstrumentation.manuallyInstrument(libraries.bedrock);
63
+ try {
64
+ const { BedrockInstrumentation } = yield import("@traceloop/instrumentation-bedrock");
65
+ const bedrockInstrumentation = new BedrockInstrumentation();
66
+ instrumentations.push(bedrockInstrumentation);
67
+ bedrockInstrumentation.manuallyInstrument(libraries.bedrock);
68
+ }
69
+ catch (_c) {
70
+ logger.warn("Failed to load Bedrock instrumentation");
71
+ }
31
72
  }
32
73
  return instrumentations;
33
- };
74
+ });
34
75
  export function paidAutoInstrument(libraries) {
35
- if (IS_INITIALIZED) {
36
- logger.info("Auto instrumentation is already initialized");
37
- return;
38
- }
39
- initializeTracing(); // try initializing tracing
40
- const tracerProvider = getPaidTracerProvider();
41
- if (!tracerProvider) {
42
- logger.error("Could not get tracer provider, make sure you ran 'initializeTracing()' or check your environment variables");
43
- return;
44
- }
45
- const isManualInstrumentation = libraries && Object.keys(libraries).length > 0;
46
- const instrumentations = isManualInstrumentation
47
- ? getManualInstrumentations(tracerProvider, libraries)
48
- : getInstrumentations(tracerProvider);
49
- registerInstrumentations({
50
- instrumentations,
51
- tracerProvider,
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (IS_INITIALIZED) {
78
+ logger.info("Auto instrumentation is already initialized");
79
+ return;
80
+ }
81
+ initializeTracing(); // try initializing tracing
82
+ const tracerProvider = getPaidTracerProvider();
83
+ if (!tracerProvider) {
84
+ logger.error("Could not get tracer provider, make sure you ran 'initializeTracing()' or check your environment variables");
85
+ return;
86
+ }
87
+ const isManualInstrumentation = libraries && Object.keys(libraries).length > 0;
88
+ const instrumentations = isManualInstrumentation
89
+ ? yield getManualInstrumentations(tracerProvider, libraries)
90
+ : yield getInstrumentations(tracerProvider);
91
+ registerInstrumentations({
92
+ instrumentations,
93
+ tracerProvider,
94
+ });
95
+ IS_INITIALIZED = true;
52
96
  });
53
- IS_INITIALIZED = true;
54
97
  }
@@ -28,13 +28,10 @@ export function signal(eventName, enableCostTracing = false, data) {
28
28
  if (!externalCustomerId || !externalProductId) {
29
29
  throw new Error(`Missing some of: external_customer_id: ${externalCustomerId}, external_product_id: ${externalProductId}, or token. Make sure to call signal() within trace()`);
30
30
  }
31
- paidTracer.startActiveSpan("trace.signal", (span) => {
31
+ paidTracer.startActiveSpan("signal", (span) => {
32
32
  try {
33
33
  const attributes = {
34
- external_customer_id: externalCustomerId,
35
- external_agent_id: externalProductId,
36
34
  event_name: eventName,
37
- token: token,
38
35
  };
39
36
  if (enableCostTracing) {
40
37
  // let the app know to associate this signal with cost traces
@@ -13,6 +13,16 @@ export class PaidSpanProcessor {
13
13
  const { name } = span;
14
14
  const { storePrompt, externalCustomerId, externalProductId: externalAgentId } = getTracingContext();
15
15
  if (!storePrompt) {
16
+ // Filter attributes that were set during span creation (before onStart)
17
+ const existingAttrs = span.attributes;
18
+ if (existingAttrs) {
19
+ for (const key of Object.keys(existingAttrs)) {
20
+ if (PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((s) => key.includes(s))) {
21
+ delete existingAttrs[key];
22
+ }
23
+ }
24
+ }
25
+ // Patch setAttribute/setAttributes for attributes set after onStart
16
26
  const originalSetAttribute = span.setAttribute;
17
27
  span.setAttribute = function (key, value) {
18
28
  const isPromptRelated = PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((substr) => key.includes(substr));
@@ -70,4 +80,6 @@ PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS = [
70
80
  "langchain.prompt",
71
81
  "output.value",
72
82
  "input.value",
83
+ "ai.response.text",
84
+ "ai.prompt",
73
85
  ];
@@ -91,15 +91,12 @@ export function trace(options, fn, ...args) {
91
91
  const token = getToken();
92
92
  const tracer = getPaidTracer();
93
93
  if (!token || !tracer) {
94
- throw new Error("Paid tracing is not initialized. Make sure to call initializeTracing() first.");
94
+ // don't throw, tracing should not crash user app.
95
+ logger.error("Paid tracing is not initialized. Make sure to call initializeTracing() first.");
96
+ return yield fn(...args);
95
97
  }
96
98
  const { externalCustomerId, externalProductId: externalAgentId, storePrompt, metadata } = options;
97
99
  return yield tracer.startActiveSpan("parent_span", (span) => __awaiter(this, void 0, void 0, function* () {
98
- span.setAttribute("external_customer_id", externalCustomerId);
99
- span.setAttribute("token", token);
100
- if (externalAgentId) {
101
- span.setAttribute("external_agent_id", externalAgentId);
102
- }
103
100
  try {
104
101
  const res = yield runWithTracingContext({
105
102
  externalCustomerId,
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.1-alpha2";
1
+ export declare const SDK_VERSION = "1.0.1-alpha5";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.1-alpha2";
1
+ export const SDK_VERSION = "1.0.1-alpha5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paid-ai/paid-node",
3
- "version": "1.0.1-alpha2",
3
+ "version": "1.0.1-alpha5",
4
4
  "private": false,
5
5
  "repository": "github:paid-ai/paid-node",
6
6
  "type": "commonjs",