@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
@@ -8,6 +8,8 @@ import type { ProrationUpgradeResponse } from "../../api/types/ProrationUpgradeR
8
8
  import type { PlansSubscribeRequest } from "../../api/resources/plans/client/requests/PlansSubscribeRequest.js";
9
9
  import type { PlansUnsubscribeRequest } from "../../api/resources/plans/client/requests/PlansUnsubscribeRequest.js";
10
10
  import type { PlansUpgradeRequest } from "../../api/resources/plans/client/requests/PlansUpgradeRequest.js";
11
+ import type { PlansGetCurrentRequest } from "../../api/resources/plans/client/requests/PlansGetCurrentRequest.js";
12
+ import type { PlansGetCurrentResponse } from "../../api/resources/plans/types/PlansGetCurrentResponse.js";
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>;
@@ -20,6 +20,8 @@ exports.unsubscribe = unsubscribe;
20
20
  exports.createUnsubscribeHandler = createUnsubscribeHandler;
21
21
  exports.upgrade = upgrade;
22
22
  exports.createUpgradeHandler = createUpgradeHandler;
23
+ exports.getCurrent = getCurrent;
24
+ exports.createGetCurrentHandler = createGetCurrentHandler;
23
25
  const base_handler_js_1 = require("../utils/base-handler.js");
24
26
  /**
25
27
  * Get a plan by ID
@@ -363,3 +365,63 @@ function createUpgradeHandler() {
363
365
  requireOrganizationId: false,
364
366
  });
365
367
  }
368
+ /**
369
+ * Get the currently active plan subscription for a customer
370
+ *
371
+ * Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
372
+ *
373
+ * @param client - PaidClient instance
374
+ * @param request - Get current request with customer external ID
375
+ * @returns Current plan response
376
+ *
377
+ * @example
378
+ * ```typescript
379
+ * const response = await getCurrent(client, {
380
+ * customerExternalId: 'customer-123'
381
+ * });
382
+ * console.log(response.plan.id);
383
+ * ```
384
+ */
385
+ function getCurrent(client, request) {
386
+ return __awaiter(this, void 0, void 0, function* () {
387
+ const response = yield client.plans.getCurrent(request);
388
+ return response;
389
+ });
390
+ }
391
+ /**
392
+ * Create a framework-agnostic handler for getting a customer's current plan
393
+ *
394
+ * This handler can be used with any framework adapter.
395
+ * The customerExternalId should be provided as a URL parameter.
396
+ *
397
+ * @returns Handler function
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * // In Next.js route: /api/plans/current/[customerExternalId]/route.ts
402
+ * // GET /api/plans/current/customer-123
403
+ * import { createGetCurrentHandler } from '@paid-ai/paid-node/integrations';
404
+ * import { nextjsAdapter } from '@paid-ai/paid-node/integrations/nextjs';
405
+ *
406
+ * const handler = createGetCurrentHandler();
407
+ * export const GET = nextjsAdapter(handler);
408
+ * ```
409
+ */
410
+ function createGetCurrentHandler() {
411
+ return (0, base_handler_js_1.createHandler)((client, _body, params) => __awaiter(this, void 0, void 0, function* () {
412
+ // Support customerExternalId from params (URL/query)
413
+ const customerExternalId = params === null || params === void 0 ? void 0 : params.customerExternalId;
414
+ if (!customerExternalId) {
415
+ return {
416
+ success: false,
417
+ error: "customerExternalId is required",
418
+ status: 400,
419
+ };
420
+ }
421
+ const response = yield getCurrent(client, { customerExternalId });
422
+ return { success: true, data: response };
423
+ }), {
424
+ allowedMethods: ['GET'],
425
+ requireOrganizationId: false,
426
+ });
427
+ }
@@ -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,57 +1,133 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
2
44
  Object.defineProperty(exports, "__esModule", { value: true });
3
45
  exports.paidAutoInstrument = paidAutoInstrument;
4
46
  const instrumentation_1 = require("@opentelemetry/instrumentation");
5
- const openinference_instrumentation_openai_1 = require("@arizeai/openinference-instrumentation-openai");
6
- const instrumentation_bedrock_1 = require("@traceloop/instrumentation-bedrock");
7
- const openinference_instrumentation_anthropic_1 = require("@arizeai/openinference-instrumentation-anthropic");
8
47
  const tracing_js_1 = require("./tracing.js");
9
48
  let IS_INITIALIZED = false;
10
- const getInstrumentations = (tracerProvider) => {
11
- const instrumentations = [
12
- new openinference_instrumentation_openai_1.OpenAIInstrumentation({ tracerProvider }),
13
- new openinference_instrumentation_anthropic_1.AnthropicInstrumentation({ tracerProvider }),
14
- new instrumentation_bedrock_1.BedrockInstrumentation(),
15
- ];
49
+ const getInstrumentations = (tracerProvider) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const instrumentations = [];
51
+ try {
52
+ const { OpenAIInstrumentation } = yield Promise.resolve().then(() => __importStar(require("@arizeai/openinference-instrumentation-openai")));
53
+ instrumentations.push(new OpenAIInstrumentation({ tracerProvider }));
54
+ }
55
+ catch (_a) {
56
+ tracing_js_1.logger.debug("OpenAI instrumentation not available - openai package not installed");
57
+ }
58
+ try {
59
+ const { AnthropicInstrumentation } = yield Promise.resolve().then(() => __importStar(require("@arizeai/openinference-instrumentation-anthropic")));
60
+ instrumentations.push(new AnthropicInstrumentation({ tracerProvider }));
61
+ }
62
+ catch (_b) {
63
+ tracing_js_1.logger.debug("Anthropic instrumentation not available - @anthropic-ai/sdk package not installed");
64
+ }
65
+ try {
66
+ const { BedrockInstrumentation } = yield Promise.resolve().then(() => __importStar(require("@traceloop/instrumentation-bedrock")));
67
+ instrumentations.push(new BedrockInstrumentation());
68
+ }
69
+ catch (_c) {
70
+ tracing_js_1.logger.debug("Bedrock instrumentation not available - @aws-sdk/client-bedrock-runtime package not installed");
71
+ }
16
72
  return instrumentations;
17
- };
18
- const getManualInstrumentations = (tracerProvider, libraries) => {
73
+ });
74
+ const getManualInstrumentations = (tracerProvider, libraries) => __awaiter(void 0, void 0, void 0, function* () {
19
75
  const instrumentations = [];
20
76
  if (libraries.openai) {
21
- const openaiInstrumentation = new openinference_instrumentation_openai_1.OpenAIInstrumentation({ tracerProvider });
22
- instrumentations.push(openaiInstrumentation);
23
- openaiInstrumentation.manuallyInstrument(libraries.openai);
77
+ try {
78
+ const { OpenAIInstrumentation } = yield Promise.resolve().then(() => __importStar(require("@arizeai/openinference-instrumentation-openai")));
79
+ const openaiInstrumentation = new OpenAIInstrumentation({ tracerProvider });
80
+ instrumentations.push(openaiInstrumentation);
81
+ openaiInstrumentation.manuallyInstrument(libraries.openai);
82
+ }
83
+ catch (_a) {
84
+ tracing_js_1.logger.warn("Failed to load OpenAI instrumentation");
85
+ }
24
86
  }
25
87
  if (libraries.anthropic) {
26
- const anthropicInstrumentation = new openinference_instrumentation_anthropic_1.AnthropicInstrumentation({ tracerProvider });
27
- instrumentations.push(anthropicInstrumentation);
28
- anthropicInstrumentation.manuallyInstrument(libraries.anthropic);
88
+ try {
89
+ const { AnthropicInstrumentation } = yield Promise.resolve().then(() => __importStar(require("@arizeai/openinference-instrumentation-anthropic")));
90
+ const anthropicInstrumentation = new AnthropicInstrumentation({ tracerProvider });
91
+ instrumentations.push(anthropicInstrumentation);
92
+ anthropicInstrumentation.manuallyInstrument(libraries.anthropic);
93
+ }
94
+ catch (_b) {
95
+ tracing_js_1.logger.warn("Failed to load Anthropic instrumentation");
96
+ }
29
97
  }
30
98
  if (libraries.bedrock) {
31
- const bedrockInstrumentation = new instrumentation_bedrock_1.BedrockInstrumentation();
32
- instrumentations.push(bedrockInstrumentation);
33
- bedrockInstrumentation.manuallyInstrument(libraries.bedrock);
99
+ try {
100
+ const { BedrockInstrumentation } = yield Promise.resolve().then(() => __importStar(require("@traceloop/instrumentation-bedrock")));
101
+ const bedrockInstrumentation = new BedrockInstrumentation();
102
+ instrumentations.push(bedrockInstrumentation);
103
+ bedrockInstrumentation.manuallyInstrument(libraries.bedrock);
104
+ }
105
+ catch (_c) {
106
+ tracing_js_1.logger.warn("Failed to load Bedrock instrumentation");
107
+ }
34
108
  }
35
109
  return instrumentations;
36
- };
110
+ });
37
111
  function paidAutoInstrument(libraries) {
38
- if (IS_INITIALIZED) {
39
- tracing_js_1.logger.info("Auto instrumentation is already initialized");
40
- return;
41
- }
42
- (0, tracing_js_1.initializeTracing)(); // try initializing tracing
43
- const tracerProvider = (0, tracing_js_1.getPaidTracerProvider)();
44
- if (!tracerProvider) {
45
- tracing_js_1.logger.error("Could not get tracer provider, make sure you ran 'initializeTracing()' or check your environment variables");
46
- return;
47
- }
48
- const isManualInstrumentation = libraries && Object.keys(libraries).length > 0;
49
- const instrumentations = isManualInstrumentation
50
- ? getManualInstrumentations(tracerProvider, libraries)
51
- : getInstrumentations(tracerProvider);
52
- (0, instrumentation_1.registerInstrumentations)({
53
- instrumentations,
54
- tracerProvider,
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ if (IS_INITIALIZED) {
114
+ tracing_js_1.logger.info("Auto instrumentation is already initialized");
115
+ return;
116
+ }
117
+ (0, tracing_js_1.initializeTracing)(); // try initializing tracing
118
+ const tracerProvider = (0, tracing_js_1.getPaidTracerProvider)();
119
+ if (!tracerProvider) {
120
+ tracing_js_1.logger.error("Could not get tracer provider, make sure you ran 'initializeTracing()' or check your environment variables");
121
+ return;
122
+ }
123
+ const isManualInstrumentation = libraries && Object.keys(libraries).length > 0;
124
+ const instrumentations = isManualInstrumentation
125
+ ? yield getManualInstrumentations(tracerProvider, libraries)
126
+ : yield getInstrumentations(tracerProvider);
127
+ (0, instrumentation_1.registerInstrumentations)({
128
+ instrumentations,
129
+ tracerProvider,
130
+ });
131
+ IS_INITIALIZED = true;
55
132
  });
56
- IS_INITIALIZED = true;
57
133
  }
@@ -31,13 +31,10 @@ function signal(eventName, enableCostTracing = false, data) {
31
31
  if (!externalCustomerId || !externalProductId) {
32
32
  throw new Error(`Missing some of: external_customer_id: ${externalCustomerId}, external_product_id: ${externalProductId}, or token. Make sure to call signal() within trace()`);
33
33
  }
34
- paidTracer.startActiveSpan("trace.signal", (span) => {
34
+ paidTracer.startActiveSpan("signal", (span) => {
35
35
  try {
36
36
  const attributes = {
37
- external_customer_id: externalCustomerId,
38
- external_agent_id: externalProductId,
39
37
  event_name: eventName,
40
- token: token,
41
38
  };
42
39
  if (enableCostTracing) {
43
40
  // let the app know to associate this signal with cost traces
@@ -16,6 +16,16 @@ class PaidSpanProcessor {
16
16
  const { name } = span;
17
17
  const { storePrompt, externalCustomerId, externalProductId: externalAgentId } = (0, tracingContext_js_1.getTracingContext)();
18
18
  if (!storePrompt) {
19
+ // Filter attributes that were set during span creation (before onStart)
20
+ const existingAttrs = span.attributes;
21
+ if (existingAttrs) {
22
+ for (const key of Object.keys(existingAttrs)) {
23
+ if (PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((s) => key.includes(s))) {
24
+ delete existingAttrs[key];
25
+ }
26
+ }
27
+ }
28
+ // Patch setAttribute/setAttributes for attributes set after onStart
19
29
  const originalSetAttribute = span.setAttribute;
20
30
  span.setAttribute = function (key, value) {
21
31
  const isPromptRelated = PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((substr) => key.includes(substr));
@@ -74,4 +84,6 @@ PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS = [
74
84
  "langchain.prompt",
75
85
  "output.value",
76
86
  "input.value",
87
+ "ai.response.text",
88
+ "ai.prompt",
77
89
  ];
@@ -101,15 +101,12 @@ function trace(options, fn, ...args) {
101
101
  const token = getToken();
102
102
  const tracer = getPaidTracer();
103
103
  if (!token || !tracer) {
104
- throw new Error("Paid tracing is not initialized. Make sure to call initializeTracing() first.");
104
+ // don't throw, tracing should not crash user app.
105
+ exports.logger.error("Paid tracing is not initialized. Make sure to call initializeTracing() first.");
106
+ return yield fn(...args);
105
107
  }
106
108
  const { externalCustomerId, externalProductId: externalAgentId, storePrompt, metadata } = options;
107
109
  return yield tracer.startActiveSpan("parent_span", (span) => __awaiter(this, void 0, void 0, function* () {
108
- span.setAttribute("external_customer_id", externalCustomerId);
109
- span.setAttribute("token", token);
110
- if (externalAgentId) {
111
- span.setAttribute("external_agent_id", externalAgentId);
112
- }
113
110
  try {
114
111
  const res = yield (0, tracingContext_js_1.runWithTracingContext)({
115
112
  externalCustomerId,
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.1-alpha2";
1
+ export declare const SDK_VERSION = "1.0.1-alpha5";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "1.0.1-alpha2";
4
+ exports.SDK_VERSION = "1.0.1-alpha5";
@@ -14,8 +14,8 @@ export class PaidClient {
14
14
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
15
15
  "X-Fern-Language": "JavaScript",
16
16
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
17
- "X-Fern-SDK-Version": "1.0.1-alpha2",
18
- "User-Agent": "@paid-ai/paid-node/1.0.1-alpha2",
17
+ "X-Fern-SDK-Version": "1.0.1-alpha5",
18
+ "User-Agent": "@paid-ai/paid-node/1.0.1-alpha5",
19
19
  "X-Fern-Runtime": core.RUNTIME.type,
20
20
  "X-Fern-Runtime-Version": core.RUNTIME.version,
21
21
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -9,6 +9,7 @@ export * from "./orders/client/requests/index.mjs";
9
9
  export * as orders from "./orders/index.mjs";
10
10
  export * from "./plans/client/requests/index.mjs";
11
11
  export * as plans from "./plans/index.mjs";
12
+ export * from "./plans/types/index.mjs";
12
13
  export * from "./products/client/requests/index.mjs";
13
14
  export * as products from "./products/index.mjs";
14
15
  export * from "./traces/client/requests/index.mjs";
@@ -9,6 +9,7 @@ export * from "./orders/client/requests/index.mjs";
9
9
  export * as orders from "./orders/index.mjs";
10
10
  export * from "./plans/client/requests/index.mjs";
11
11
  export * as plans from "./plans/index.mjs";
12
+ export * from "./plans/types/index.mjs";
12
13
  export * from "./products/client/requests/index.mjs";
13
14
  export * as products from "./products/index.mjs";
14
15
  export * from "./traces/client/requests/index.mjs";
@@ -10,6 +10,23 @@ export declare namespace Plans {
10
10
  export declare class Plans {
11
11
  protected readonly _options: Plans.Options;
12
12
  constructor(_options?: Plans.Options);
13
+ /**
14
+ * Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
15
+ *
16
+ * @param {Paid.PlansGetCurrentRequest} request
17
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
18
+ *
19
+ * @throws {@link Paid.BadRequestError}
20
+ * @throws {@link Paid.ForbiddenError}
21
+ * @throws {@link Paid.NotFoundError}
22
+ *
23
+ * @example
24
+ * await client.plans.getCurrent({
25
+ * customerExternalId: "customerExternalId"
26
+ * })
27
+ */
28
+ getCurrent(request: Paid.PlansGetCurrentRequest, requestOptions?: Plans.RequestOptions): core.HttpResponsePromise<Paid.PlansGetCurrentResponse>;
29
+ private __getCurrent;
13
30
  /**
14
31
  * @param {string} planId - The ID of the plan
15
32
  * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
@@ -17,6 +17,76 @@ export class Plans {
17
17
  constructor(_options = {}) {
18
18
  this._options = _options;
19
19
  }
20
+ /**
21
+ * Retrieves the currently active plan subscription for a customer by their external ID. Returns the plan details and subscription information.
22
+ *
23
+ * @param {Paid.PlansGetCurrentRequest} request
24
+ * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
25
+ *
26
+ * @throws {@link Paid.BadRequestError}
27
+ * @throws {@link Paid.ForbiddenError}
28
+ * @throws {@link Paid.NotFoundError}
29
+ *
30
+ * @example
31
+ * await client.plans.getCurrent({
32
+ * customerExternalId: "customerExternalId"
33
+ * })
34
+ */
35
+ getCurrent(request, requestOptions) {
36
+ return core.HttpResponsePromise.fromPromise(this.__getCurrent(request, requestOptions));
37
+ }
38
+ __getCurrent(request, requestOptions) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ var _a, _b, _c, _d, _e, _f, _g, _h;
41
+ const { customerExternalId } = request;
42
+ const _queryParams = {};
43
+ _queryParams.customerExternalId = customerExternalId;
44
+ const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
45
+ const _response = yield core.fetcher({
46
+ url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, "plans/current"),
47
+ method: "GET",
48
+ headers: _headers,
49
+ queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
50
+ timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
51
+ maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
52
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
53
+ });
54
+ if (_response.ok) {
55
+ return { data: _response.body, rawResponse: _response.rawResponse };
56
+ }
57
+ if (_response.error.reason === "status-code") {
58
+ switch (_response.error.statusCode) {
59
+ case 400:
60
+ throw new Paid.BadRequestError(_response.error.body, _response.rawResponse);
61
+ case 403:
62
+ throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
63
+ case 404:
64
+ throw new Paid.NotFoundError(_response.error.body, _response.rawResponse);
65
+ default:
66
+ throw new errors.PaidError({
67
+ statusCode: _response.error.statusCode,
68
+ body: _response.error.body,
69
+ rawResponse: _response.rawResponse,
70
+ });
71
+ }
72
+ }
73
+ switch (_response.error.reason) {
74
+ case "non-json":
75
+ throw new errors.PaidError({
76
+ statusCode: _response.error.statusCode,
77
+ body: _response.error.rawBody,
78
+ rawResponse: _response.rawResponse,
79
+ });
80
+ case "timeout":
81
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /plans/current.");
82
+ case "unknown":
83
+ throw new errors.PaidError({
84
+ message: _response.error.errorMessage,
85
+ rawResponse: _response.rawResponse,
86
+ });
87
+ }
88
+ });
89
+ }
20
90
  /**
21
91
  * @param {string} planId - The ID of the plan
22
92
  * @param {Plans.RequestOptions} requestOptions - Request-specific configuration.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @example
3
+ * {
4
+ * customerExternalId: "customerExternalId"
5
+ * }
6
+ *
7
+ * @example
8
+ * {
9
+ * customerExternalId: "customerExternalId"
10
+ * }
11
+ */
12
+ export interface PlansGetCurrentRequest {
13
+ /** The external ID of the customer */
14
+ customerExternalId: string;
15
+ }
@@ -0,0 +1,2 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export {};
@@ -1,3 +1,4 @@
1
+ export type { PlansGetCurrentRequest } from "./PlansGetCurrentRequest.mjs";
1
2
  export type { PlansGetUsageRequest } from "./PlansGetUsageRequest.mjs";
2
3
  export type { PlansSubscribeRequest } from "./PlansSubscribeRequest.mjs";
3
4
  export type { PlansUnsubscribeRequest } from "./PlansUnsubscribeRequest.mjs";
@@ -1 +1,2 @@
1
1
  export * from "./client/index.mjs";
2
+ export * from "./types/index.mjs";
@@ -1 +1,2 @@
1
1
  export * from "./client/index.mjs";
2
+ export * from "./types/index.mjs";
@@ -0,0 +1,83 @@
1
+ import type * as Paid from "../../../index.mjs";
2
+ export interface PlansGetCurrentResponse {
3
+ /** The plan details, or null if the customer has no active plan */
4
+ plan?: PlansGetCurrentResponse.Plan;
5
+ /** The subscription details, or null if the customer has no active plan */
6
+ subscription?: PlansGetCurrentResponse.Subscription;
7
+ }
8
+ export declare namespace PlansGetCurrentResponse {
9
+ /**
10
+ * The plan details, or null if the customer has no active plan
11
+ */
12
+ interface Plan {
13
+ /** The unique identifier of the plan */
14
+ id: string;
15
+ /** The name of the plan */
16
+ name: string;
17
+ /** The description of the plan */
18
+ description?: string;
19
+ /** The type of plan */
20
+ type: Plan.Type;
21
+ pricing: Paid.PlanPricing;
22
+ /** The plan group ID this plan belongs to */
23
+ planGroupId: string;
24
+ /** The ID of the next plan in the sequence */
25
+ nextPlanId?: string;
26
+ /** The ID of the previous plan in the sequence */
27
+ prevPlanId?: string;
28
+ /** The features (product-attribute pairs) included in this plan with usage and limits */
29
+ features: Plan.Features.Item[];
30
+ }
31
+ namespace Plan {
32
+ /** The type of plan */
33
+ const Type: {
34
+ readonly Flat: "flat";
35
+ readonly Usage: "usage";
36
+ readonly Credit: "credit";
37
+ };
38
+ type Type = (typeof Type)[keyof typeof Type];
39
+ type Features = Features.Item[];
40
+ namespace Features {
41
+ interface Item {
42
+ /** The name of the product */
43
+ productName: string;
44
+ /** The name of the product attribute */
45
+ attributeName: string;
46
+ /** The pricing configuration for this feature */
47
+ pricing: Record<string, unknown>;
48
+ /** Current usage and limits for this feature */
49
+ usage: Item.Usage;
50
+ }
51
+ namespace Item {
52
+ /**
53
+ * Current usage and limits for this feature
54
+ */
55
+ interface Usage {
56
+ /** The event name used to track usage for this feature */
57
+ eventName?: string;
58
+ /** The current usage quantity for this feature on the order */
59
+ currentUsage: number;
60
+ /** The usage limit for this feature (null if unlimited) */
61
+ limit?: number;
62
+ /** Whether this feature has unlimited usage */
63
+ isUnlimited: boolean;
64
+ }
65
+ }
66
+ }
67
+ }
68
+ /**
69
+ * The subscription details, or null if the customer has no active plan
70
+ */
71
+ interface Subscription {
72
+ /** The ID of the order */
73
+ orderId: string;
74
+ /** The display ID of the order */
75
+ orderDisplayId?: string;
76
+ /** The start date of the subscription */
77
+ startDate: string;
78
+ /** The end date of the subscription (null if ongoing) */
79
+ endDate?: string;
80
+ /** The total usage quantity across all features on this order */
81
+ totalUsage: number;
82
+ }
83
+ }
@@ -0,0 +1,13 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ export var PlansGetCurrentResponse;
3
+ (function (PlansGetCurrentResponse) {
4
+ let Plan;
5
+ (function (Plan) {
6
+ /** The type of plan */
7
+ Plan.Type = {
8
+ Flat: "flat",
9
+ Usage: "usage",
10
+ Credit: "credit",
11
+ };
12
+ })(Plan = PlansGetCurrentResponse.Plan || (PlansGetCurrentResponse.Plan = {}));
13
+ })(PlansGetCurrentResponse || (PlansGetCurrentResponse = {}));
@@ -0,0 +1 @@
1
+ export * from "./PlansGetCurrentResponse.mjs";
@@ -0,0 +1 @@
1
+ export * from "./PlansGetCurrentResponse.mjs";