@paid-ai/paid-node 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +180 -39
  2. package/dist/cjs/Client.js +2 -2
  3. package/dist/cjs/api/errors/ForbiddenError.d.ts +9 -0
  4. package/dist/cjs/api/errors/ForbiddenError.js +52 -0
  5. package/dist/cjs/api/errors/index.d.ts +1 -0
  6. package/dist/cjs/api/errors/index.js +17 -0
  7. package/dist/cjs/api/index.d.ts +1 -0
  8. package/dist/cjs/api/index.js +1 -0
  9. package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -3
  10. package/dist/cjs/api/resources/agents/client/Client.js +6 -2
  11. package/dist/cjs/api/resources/contacts/client/Client.d.ts +3 -3
  12. package/dist/cjs/api/resources/contacts/client/Client.js +6 -2
  13. package/dist/cjs/api/resources/customers/client/Client.d.ts +14 -3
  14. package/dist/cjs/api/resources/customers/client/Client.js +62 -2
  15. package/dist/cjs/api/resources/orders/client/Client.d.ts +13 -3
  16. package/dist/cjs/api/resources/orders/client/Client.js +16 -2
  17. package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +10 -0
  18. package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +3 -3
  19. package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +6 -2
  20. package/dist/cjs/api/resources/usage/client/Client.d.ts +3 -3
  21. package/dist/cjs/api/resources/usage/client/Client.js +6 -2
  22. package/dist/cjs/api/types/EntitlementUsage.d.ts +23 -0
  23. package/dist/cjs/api/types/EntitlementUsage.js +5 -0
  24. package/dist/cjs/api/types/OrderLineAttributeCreate.d.ts +12 -0
  25. package/dist/cjs/api/types/OrderLineAttributeCreate.js +5 -0
  26. package/dist/cjs/api/types/OrderLineCreate.d.ts +7 -0
  27. package/dist/cjs/api/types/index.d.ts +2 -0
  28. package/dist/cjs/api/types/index.js +2 -0
  29. package/dist/cjs/index.d.ts +1 -1
  30. package/dist/cjs/index.js +3 -3
  31. package/dist/cjs/version.d.ts +1 -1
  32. package/dist/cjs/version.js +1 -1
  33. package/dist/esm/Client.mjs +2 -2
  34. package/dist/esm/api/errors/ForbiddenError.d.mts +9 -0
  35. package/dist/esm/api/errors/ForbiddenError.mjs +15 -0
  36. package/dist/esm/api/errors/index.d.mts +1 -0
  37. package/dist/esm/api/errors/index.mjs +1 -0
  38. package/dist/esm/api/index.d.mts +1 -0
  39. package/dist/esm/api/index.mjs +1 -0
  40. package/dist/esm/api/resources/agents/client/Client.d.mts +3 -3
  41. package/dist/esm/api/resources/agents/client/Client.mjs +6 -2
  42. package/dist/esm/api/resources/contacts/client/Client.d.mts +3 -3
  43. package/dist/esm/api/resources/contacts/client/Client.mjs +6 -2
  44. package/dist/esm/api/resources/customers/client/Client.d.mts +14 -3
  45. package/dist/esm/api/resources/customers/client/Client.mjs +62 -2
  46. package/dist/esm/api/resources/orders/client/Client.d.mts +13 -3
  47. package/dist/esm/api/resources/orders/client/Client.mjs +16 -2
  48. package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +10 -0
  49. package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +3 -3
  50. package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +6 -2
  51. package/dist/esm/api/resources/usage/client/Client.d.mts +3 -3
  52. package/dist/esm/api/resources/usage/client/Client.mjs +6 -2
  53. package/dist/esm/api/types/EntitlementUsage.d.mts +23 -0
  54. package/dist/esm/api/types/EntitlementUsage.mjs +4 -0
  55. package/dist/esm/api/types/OrderLineAttributeCreate.d.mts +12 -0
  56. package/dist/esm/api/types/OrderLineAttributeCreate.mjs +4 -0
  57. package/dist/esm/api/types/OrderLineCreate.d.mts +7 -0
  58. package/dist/esm/api/types/index.d.mts +2 -0
  59. package/dist/esm/api/types/index.mjs +2 -0
  60. package/dist/esm/index.d.mts +1 -1
  61. package/dist/esm/index.mjs +1 -1
  62. package/dist/esm/version.d.mts +1 -1
  63. package/dist/esm/version.mjs +1 -1
  64. package/package.json +1 -1
  65. package/reference.md +48 -0
package/README.md CHANGED
@@ -86,30 +86,41 @@ To enable logs, set the `PAID_LOG_LEVEL` environment variable. Available levels
86
86
 
87
87
  Example: `PAID_LOG_LEVEL=debug node your-app.js`
88
88
 
89
- ## Cost Tracking
89
+ ## Cost Tracking via OTEL tracing
90
90
 
91
- It's possible to track usage costs by using Paid wrappers around you AI provider API.
92
- As of now, the following AI providers are supported: `OpenAI`, `Anthropic`, `Mistral` (OCR), and `Langchain`.
91
+ You can track usage costs by using Paid wrappers around your AI provider's SDK.
92
+ As of now, the following SDKs' APIs are wrapped:
93
93
 
94
- Example usage:
94
+ ```
95
+ openai
96
+ anthropic
97
+ mistral
98
+ langchain (as a callback)
99
+ vercel (Vercel AI SDK)
100
+ ```
101
+
102
+ ### Using the Paid wrappers
103
+
104
+ Example usage with OpenAI:
95
105
 
96
106
  ```typescript
97
- import { PaidClient, PaidOpenAI } from "@paid-ai/paid-node";
107
+ import { PaidClient } from "@paid-ai/paid-node";
108
+ import { PaidOpenAI } from "@paid-ai/paid-node/openai";
98
109
  import OpenAI from "openai";
99
110
 
100
111
  async function main() {
101
112
  const client = new PaidClient({ token: "<your_paid_api_key>" });
102
113
 
103
- // initialize cost tracking
104
- await client.initializeTracing()
114
+ // Initialize cost tracking
115
+ await client.initializeTracing();
105
116
 
106
- // wrap openai in paid wrapper
107
- const openaiClient = new OpenAI({ apiKey: "<your_openai_api_key" });
108
- const paidOpenAiWrapper = new PaidOpenAI(openaiClient);
117
+ // Wrap OpenAI in paid wrapper
118
+ const openaiClient = new OpenAI({ apiKey: "<your_openai_api_key>" });
119
+ const paidOpenAI = new PaidOpenAI(openaiClient);
109
120
 
110
- // trace the call
121
+ // Trace the call
111
122
  await client.trace("<your_external_customer_id>", async () => {
112
- const response = await paidOpenAiWrapper.images.generate({
123
+ const response = await paidOpenAI.images.generate({
113
124
  prompt: "A beautiful sunset over the mountains",
114
125
  n: 1,
115
126
  size: "256x256"
@@ -121,54 +132,184 @@ async function main() {
121
132
  }
122
133
  ```
123
134
 
135
+ ## Signaling via OTEL tracing
136
+
137
+ A more reliable and user-friendly way to send signals is to send them via OTEL tracing.
138
+ This allows you to send signals with less arguments and boilerplate as the information is available in the tracing context `Paid.trace()`.
139
+ The interface is `Paid.signal()`, which takes in signal name, optional data, and a flag that attaches costs from the same trace.
140
+ `Paid.signal()` has to be called within a trace - meaning inside of a callback to `Paid.trace()`.
141
+ In contrast to `Paid.usage.recordBulk()`, `Paid.signal()` is using OpenTelemetry to provide reliable delivery.
142
+
143
+ Here's an example of how to use it:
144
+
145
+ ```typescript
146
+ import { PaidClient } from "@paid-ai/paid-node";
147
+
148
+ async function main() {
149
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
150
+
151
+ // Initialize tracing
152
+ await client.initializeTracing();
153
+
154
+ // Trace the call
155
+ await client.trace("<your_external_customer_id>", async () => {
156
+ // ...do some work...
157
+ client.signal("<your_signal_name>", { /* optional data */ });
158
+ }, "<your_external_agent_id>"); // external_agent_id is required for signals
159
+ }
160
+ ```
161
+
162
+ ### Signal-costs - Attaching cost traces to a signal
163
+
164
+ If you want a signal to carry information about costs,
165
+ then the signal should be sent from the same tracing context
166
+ as the wrappers that recorded those costs.
167
+
168
+ This will look something like this:
169
+
170
+ ```typescript
171
+ import { PaidClient } from "@paid-ai/paid-node";
172
+ import { PaidOpenAI } from "@paid-ai/paid-node/openai";
173
+ import OpenAI from "openai";
174
+
175
+ async function main() {
176
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
177
+ await client.initializeTracing();
178
+
179
+ const openaiClient = new OpenAI({ apiKey: "<your_openai_api_key>" });
180
+ const paidOpenAI = new PaidOpenAI(openaiClient);
181
+
182
+ await client.trace("<your_external_customer_id>", async () => {
183
+ // ... your workflow logic
184
+ // ... your AI calls made through Paid wrappers
185
+ const response = await paidOpenAI.chat.completions.create({
186
+ model: "gpt-4",
187
+ messages: [{ role: "user", content: "Hello!" }]
188
+ });
189
+
190
+ // Send signal with cost tracing enabled
191
+ client.signal(
192
+ "<your_signal_name>",
193
+ true, // enableCostTracing - set this flag to associate it with costs
194
+ { /* optional data */ }
195
+ );
196
+
197
+ // ... your workflow logic
198
+ // ... your AI calls made through Paid wrappers (can be sent after the signal too)
199
+ }, "<your_external_agent_id>");
200
+ }
201
+ ```
202
+
203
+ Then, all of the costs traced in `client.trace()` context are related to that signal.
204
+
124
205
  ## Manual Cost Tracking
125
206
 
126
- When using `client.usage.recordUsage()` API, it's possible to create cost traces manually
127
- just by passing in the cost data.
207
+ If you would prefer to not use Paid to track your costs automatically but you want to send us the costs yourself,
208
+ then you can use manual cost tracking mechanism. Just attach the cost information in the following format to a signal payload:
128
209
 
129
210
  ```typescript
130
- const additionalData = {
131
- costData: {
132
- vendor: "<vendor_name>", // can be anything
133
- cost : {
134
- amount: 0.0001,
135
- currency: "USD"
211
+ import { PaidClient, Paid } from "@paid-ai/paid-node";
212
+
213
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
214
+
215
+ const signal: Paid.Signal = {
216
+ event_name: "<your_signal_name>",
217
+ agent_id: "<your_agent_id>",
218
+ customer_id: "<your_external_customer_id>",
219
+ data: {
220
+ costData: {
221
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
222
+ cost: {
223
+ amount: 0.002,
224
+ currency: "USD"
225
+ },
226
+ "gen_ai.response.model": "<ai_model_name>",
136
227
  }
137
228
  }
138
229
  };
139
- await client.usage.recordBulk({
140
- signals: [{
141
- agent_id: "<your_agent_id>",
142
- event_name: "<your_signal_name>",
143
- customer_id: "<your_customer_id>",
144
- data: additionalData,
145
- }]
146
- })
147
230
 
231
+ await client.usage.recordBulk({ signals: [signal] });
148
232
  await client.usage.flush(); // need to flush to send usage immediately
149
233
  ```
150
234
 
151
- ## Send signals over OTLP
235
+ Alternatively the same `costData` payload can be passed to OTLP signaling mechanism:
236
+
237
+ ```typescript
238
+ import { PaidClient } from "@paid-ai/paid-node";
239
+
240
+ async function main() {
241
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
242
+ await client.initializeTracing();
243
+
244
+ await client.trace("<your_external_customer_id>", async () => {
245
+ // ...do some work...
246
+ client.signal("<your_signal_name>", {
247
+ costData: {
248
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
249
+ cost: {
250
+ amount: 0.002,
251
+ currency: "USD"
252
+ },
253
+ "gen_ai.response.model": "<ai_model_name>",
254
+ }
255
+ });
256
+ }, "<your_external_agent_id>");
257
+ }
258
+ ```
259
+
260
+ ### Manual Usage Tracking
152
261
 
153
- Besides sending signals over REST, it's also possible to send signals as part or tracing
154
- context, just like with cost tracking.
262
+ If you would prefer to send us raw usage manually (without wrappers) and have us compute the cost, you can attach usage data in the following format:
155
263
 
156
- Example usage:
264
+ ```typescript
265
+ import { PaidClient, Paid } from "@paid-ai/paid-node";
266
+
267
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
268
+
269
+ const signal: Paid.Signal = {
270
+ event_name: "<your_signal_name>",
271
+ agent_id: "<your_agent_id>",
272
+ customer_id: "<your_external_customer_id>",
273
+ data: {
274
+ costData: {
275
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
276
+ attributes: {
277
+ "gen_ai.response.model": "gpt-4-turbo",
278
+ "gen_ai.usage.input_tokens": 100,
279
+ "gen_ai.usage.output_tokens": 300,
280
+ "gen_ai.usage.cached_input_tokens": 600,
281
+ },
282
+ }
283
+ }
284
+ };
285
+
286
+ await client.usage.recordBulk({ signals: [signal] });
287
+ await client.usage.flush();
288
+ ```
289
+
290
+ Same but via OTEL signaling:
157
291
 
158
292
  ```typescript
159
293
  import { PaidClient } from "@paid-ai/paid-node";
160
294
 
161
295
  async function main() {
162
296
  const client = new PaidClient({ token: "<your_paid_api_key>" });
297
+ await client.initializeTracing();
163
298
 
164
- // initialize cost tracking
165
- await client.initializeTracing()
166
-
167
- // trace the call
168
299
  await client.trace("<your_external_customer_id>", async () => {
169
- // ... your app logic, cost tracking LLM wrapper calls
170
- client.signal("signal_name", { "data": { // ... additional data, e.g. costs } });
171
- }, "<optional_external_agent_id>");
300
+ // ...do some work...
301
+ client.signal("<your_signal_name>", {
302
+ costData: {
303
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
304
+ attributes: {
305
+ "gen_ai.response.model": "gpt-4-turbo",
306
+ "gen_ai.usage.input_tokens": 100,
307
+ "gen_ai.usage.output_tokens": 300,
308
+ "gen_ai.usage.cached_input_tokens": 600,
309
+ },
310
+ }
311
+ });
312
+ }, "<your_external_agent_id>");
172
313
  }
173
314
  ```
174
315
 
@@ -60,8 +60,8 @@ class PaidClient {
60
60
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
61
61
  "X-Fern-Language": "JavaScript",
62
62
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
63
- "X-Fern-SDK-Version": "0.2.0",
64
- "User-Agent": "@paid-ai/paid-node/0.2.0",
63
+ "X-Fern-SDK-Version": "0.3.0",
64
+ "User-Agent": "@paid-ai/paid-node/0.3.0",
65
65
  "X-Fern-Runtime": core.RUNTIME.type,
66
66
  "X-Fern-Runtime-Version": core.RUNTIME.version,
67
67
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+ import * as errors from "../../errors/index.js";
5
+ import * as Paid from "../index.js";
6
+ import * as core from "../../core/index.js";
7
+ export declare class ForbiddenError extends errors.PaidError {
8
+ constructor(body: Paid.Error_, rawResponse?: core.RawResponse);
9
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * This file was auto-generated by Fern from our API Definition.
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ForbiddenError = void 0;
40
+ const errors = __importStar(require("../../errors/index.js"));
41
+ class ForbiddenError extends errors.PaidError {
42
+ constructor(body, rawResponse) {
43
+ super({
44
+ message: "ForbiddenError",
45
+ statusCode: 403,
46
+ body: body,
47
+ rawResponse: rawResponse,
48
+ });
49
+ Object.setPrototypeOf(this, ForbiddenError.prototype);
50
+ }
51
+ }
52
+ exports.ForbiddenError = ForbiddenError;
@@ -0,0 +1 @@
1
+ export * from "./ForbiddenError.js";
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ForbiddenError.js"), exports);
@@ -1,2 +1,3 @@
1
1
  export * from "./types/index.js";
2
+ export * from "./errors/index.js";
2
3
  export * from "./resources/index.js";
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types/index.js"), exports);
18
+ __exportStar(require("./errors/index.js"), exports);
18
19
  __exportStar(require("./resources/index.js"), exports);
@@ -9,7 +9,7 @@ export declare namespace Agents {
9
9
  environment?: core.Supplier<environments.PaidEnvironment | string>;
10
10
  /** Specify a custom URL to connect the client to. */
11
11
  baseUrl?: core.Supplier<string>;
12
- token: core.Supplier<core.BearerToken>;
12
+ token?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
14
  headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
15
  }
@@ -26,7 +26,7 @@ export declare namespace Agents {
26
26
  }
27
27
  export declare class Agents {
28
28
  protected readonly _options: Agents.Options;
29
- constructor(_options: Agents.Options);
29
+ constructor(_options?: Agents.Options);
30
30
  /**
31
31
  * @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
32
32
  *
@@ -151,5 +151,5 @@ export declare class Agents {
151
151
  */
152
152
  deleteByExternalId(externalId: string, requestOptions?: Agents.RequestOptions): core.HttpResponsePromise<void>;
153
153
  private __deleteByExternalId;
154
- protected _getAuthorizationHeader(): Promise<string>;
154
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
155
155
  }
@@ -55,7 +55,7 @@ const headers_js_1 = require("../../../../core/headers.js");
55
55
  const url_join_1 = __importDefault(require("url-join"));
56
56
  const errors = __importStar(require("../../../../errors/index.js"));
57
57
  class Agents {
58
- constructor(_options) {
58
+ constructor(_options = {}) {
59
59
  this._options = _options;
60
60
  }
61
61
  /**
@@ -505,7 +505,11 @@ class Agents {
505
505
  }
506
506
  _getAuthorizationHeader() {
507
507
  return __awaiter(this, void 0, void 0, function* () {
508
- return `Bearer ${yield core.Supplier.get(this._options.token)}`;
508
+ const bearer = yield core.Supplier.get(this._options.token);
509
+ if (bearer != null) {
510
+ return `Bearer ${bearer}`;
511
+ }
512
+ return undefined;
509
513
  });
510
514
  }
511
515
  }
@@ -9,7 +9,7 @@ export declare namespace Contacts {
9
9
  environment?: core.Supplier<environments.PaidEnvironment | string>;
10
10
  /** Specify a custom URL to connect the client to. */
11
11
  baseUrl?: core.Supplier<string>;
12
- token: core.Supplier<core.BearerToken>;
12
+ token?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
14
  headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
15
  }
@@ -26,7 +26,7 @@ export declare namespace Contacts {
26
26
  }
27
27
  export declare class Contacts {
28
28
  protected readonly _options: Contacts.Options;
29
- constructor(_options: Contacts.Options);
29
+ constructor(_options?: Contacts.Options);
30
30
  /**
31
31
  * @param {Contacts.RequestOptions} requestOptions - Request-specific configuration.
32
32
  *
@@ -86,5 +86,5 @@ export declare class Contacts {
86
86
  */
87
87
  deleteByExternalId(externalId: string, requestOptions?: Contacts.RequestOptions): core.HttpResponsePromise<void>;
88
88
  private __deleteByExternalId;
89
- protected _getAuthorizationHeader(): Promise<string>;
89
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
90
90
  }
@@ -55,7 +55,7 @@ const headers_js_1 = require("../../../../core/headers.js");
55
55
  const url_join_1 = __importDefault(require("url-join"));
56
56
  const errors = __importStar(require("../../../../errors/index.js"));
57
57
  class Contacts {
58
- constructor(_options) {
58
+ constructor(_options = {}) {
59
59
  this._options = _options;
60
60
  }
61
61
  /**
@@ -356,7 +356,11 @@ class Contacts {
356
356
  }
357
357
  _getAuthorizationHeader() {
358
358
  return __awaiter(this, void 0, void 0, function* () {
359
- return `Bearer ${yield core.Supplier.get(this._options.token)}`;
359
+ const bearer = yield core.Supplier.get(this._options.token);
360
+ if (bearer != null) {
361
+ return `Bearer ${bearer}`;
362
+ }
363
+ return undefined;
360
364
  });
361
365
  }
362
366
  }
@@ -9,7 +9,7 @@ export declare namespace Customers {
9
9
  environment?: core.Supplier<environments.PaidEnvironment | string>;
10
10
  /** Specify a custom URL to connect the client to. */
11
11
  baseUrl?: core.Supplier<string>;
12
- token: core.Supplier<core.BearerToken>;
12
+ token?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
14
  headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
15
15
  }
@@ -26,7 +26,7 @@ export declare namespace Customers {
26
26
  }
27
27
  export declare class Customers {
28
28
  protected readonly _options: Customers.Options;
29
- constructor(_options: Customers.Options);
29
+ constructor(_options?: Customers.Options);
30
30
  /**
31
31
  * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
32
32
  *
@@ -80,6 +80,17 @@ export declare class Customers {
80
80
  */
81
81
  delete(customerId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<void>;
82
82
  private __delete;
83
+ /**
84
+ * @param {string} customerId - The customer ID
85
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
86
+ *
87
+ * @throws {@link Paid.ForbiddenError}
88
+ *
89
+ * @example
90
+ * await client.customers.getEntitlements("customerId")
91
+ */
92
+ getEntitlements(customerId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<Paid.EntitlementUsage[]>;
93
+ private __getEntitlements;
83
94
  /**
84
95
  * @param {string} externalId
85
96
  * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
@@ -108,5 +119,5 @@ export declare class Customers {
108
119
  */
109
120
  deleteByExternalId(externalId: string, requestOptions?: Customers.RequestOptions): core.HttpResponsePromise<void>;
110
121
  private __deleteByExternalId;
111
- protected _getAuthorizationHeader(): Promise<string>;
122
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
112
123
  }
@@ -51,11 +51,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.Customers = void 0;
52
52
  const environments = __importStar(require("../../../../environments.js"));
53
53
  const core = __importStar(require("../../../../core/index.js"));
54
+ const Paid = __importStar(require("../../../index.js"));
54
55
  const headers_js_1 = require("../../../../core/headers.js");
55
56
  const url_join_1 = __importDefault(require("url-join"));
56
57
  const errors = __importStar(require("../../../../errors/index.js"));
57
58
  class Customers {
58
- constructor(_options) {
59
+ constructor(_options = {}) {
59
60
  this._options = _options;
60
61
  }
61
62
  /**
@@ -312,6 +313,61 @@ class Customers {
312
313
  }
313
314
  });
314
315
  }
316
+ /**
317
+ * @param {string} customerId - The customer ID
318
+ * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
319
+ *
320
+ * @throws {@link Paid.ForbiddenError}
321
+ *
322
+ * @example
323
+ * await client.customers.getEntitlements("customerId")
324
+ */
325
+ getEntitlements(customerId, requestOptions) {
326
+ return core.HttpResponsePromise.fromPromise(this.__getEntitlements(customerId, requestOptions));
327
+ }
328
+ __getEntitlements(customerId, requestOptions) {
329
+ return __awaiter(this, void 0, void 0, function* () {
330
+ var _a, _b, _c;
331
+ const _response = yield core.fetcher({
332
+ url: (0, url_join_1.default)((_b = (_a = (yield core.Supplier.get(this._options.baseUrl))) !== null && _a !== void 0 ? _a : (yield core.Supplier.get(this._options.environment))) !== null && _b !== void 0 ? _b : environments.PaidEnvironment.Production, `customers/${encodeURIComponent(customerId)}/credit-bundles`),
333
+ method: "GET",
334
+ headers: (0, headers_js_1.mergeHeaders)((_c = this._options) === null || _c === void 0 ? void 0 : _c.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers),
335
+ timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
336
+ maxRetries: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries,
337
+ abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
338
+ });
339
+ if (_response.ok) {
340
+ return { data: _response.body, rawResponse: _response.rawResponse };
341
+ }
342
+ if (_response.error.reason === "status-code") {
343
+ switch (_response.error.statusCode) {
344
+ case 403:
345
+ throw new Paid.ForbiddenError(_response.error.body, _response.rawResponse);
346
+ default:
347
+ throw new errors.PaidError({
348
+ statusCode: _response.error.statusCode,
349
+ body: _response.error.body,
350
+ rawResponse: _response.rawResponse,
351
+ });
352
+ }
353
+ }
354
+ switch (_response.error.reason) {
355
+ case "non-json":
356
+ throw new errors.PaidError({
357
+ statusCode: _response.error.statusCode,
358
+ body: _response.error.rawBody,
359
+ rawResponse: _response.rawResponse,
360
+ });
361
+ case "timeout":
362
+ throw new errors.PaidTimeoutError("Timeout exceeded when calling GET /customers/{customerId}/credit-bundles.");
363
+ case "unknown":
364
+ throw new errors.PaidError({
365
+ message: _response.error.errorMessage,
366
+ rawResponse: _response.rawResponse,
367
+ });
368
+ }
369
+ });
370
+ }
315
371
  /**
316
372
  * @param {string} externalId
317
373
  * @param {Customers.RequestOptions} requestOptions - Request-specific configuration.
@@ -462,7 +518,11 @@ class Customers {
462
518
  }
463
519
  _getAuthorizationHeader() {
464
520
  return __awaiter(this, void 0, void 0, function* () {
465
- return `Bearer ${yield core.Supplier.get(this._options.token)}`;
521
+ const bearer = yield core.Supplier.get(this._options.token);
522
+ if (bearer != null) {
523
+ return `Bearer ${bearer}`;
524
+ }
525
+ return undefined;
466
526
  });
467
527
  }
468
528
  }
@@ -10,7 +10,7 @@ export declare namespace Orders {
10
10
  environment?: core.Supplier<environments.PaidEnvironment | string>;
11
11
  /** Specify a custom URL to connect the client to. */
12
12
  baseUrl?: core.Supplier<string>;
13
- token: core.Supplier<core.BearerToken>;
13
+ token?: core.Supplier<core.BearerToken | undefined>;
14
14
  /** Additional headers to include in requests. */
15
15
  headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
16
16
  }
@@ -28,7 +28,7 @@ export declare namespace Orders {
28
28
  export declare class Orders {
29
29
  protected readonly _options: Orders.Options;
30
30
  protected _lines: Lines | undefined;
31
- constructor(_options: Orders.Options);
31
+ constructor(_options?: Orders.Options);
32
32
  get lines(): Lines;
33
33
  /**
34
34
  * @param {Orders.RequestOptions} requestOptions - Request-specific configuration.
@@ -51,6 +51,16 @@ export declare class Orders {
51
51
  * endDate: "2026-01-01",
52
52
  * currency: "USD"
53
53
  * })
54
+ *
55
+ * @example
56
+ * await client.orders.create({
57
+ * customerExternalId: "acme-inc",
58
+ * name: "Acme Order with Custom Pricing",
59
+ * description: "Order with customized attribute pricing",
60
+ * startDate: "2025-01-01",
61
+ * endDate: "2026-01-01",
62
+ * currency: "USD"
63
+ * })
54
64
  */
55
65
  create(request: Paid.OrderCreate, requestOptions?: Orders.RequestOptions): core.HttpResponsePromise<Paid.Order>;
56
66
  private __create;
@@ -81,5 +91,5 @@ export declare class Orders {
81
91
  */
82
92
  activate(orderId: string, requestOptions?: Orders.RequestOptions): core.HttpResponsePromise<Paid.Order>;
83
93
  private __activate;
84
- protected _getAuthorizationHeader(): Promise<string>;
94
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
85
95
  }