@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.
- package/README.md +180 -39
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/errors/ForbiddenError.d.ts +9 -0
- package/dist/cjs/api/errors/ForbiddenError.js +52 -0
- package/dist/cjs/api/errors/index.d.ts +1 -0
- package/dist/cjs/api/errors/index.js +17 -0
- package/dist/cjs/api/index.d.ts +1 -0
- package/dist/cjs/api/index.js +1 -0
- package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/agents/client/Client.js +6 -2
- package/dist/cjs/api/resources/contacts/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/contacts/client/Client.js +6 -2
- package/dist/cjs/api/resources/customers/client/Client.d.ts +14 -3
- package/dist/cjs/api/resources/customers/client/Client.js +62 -2
- package/dist/cjs/api/resources/orders/client/Client.d.ts +13 -3
- package/dist/cjs/api/resources/orders/client/Client.js +16 -2
- package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +10 -0
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +6 -2
- package/dist/cjs/api/resources/usage/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/usage/client/Client.js +6 -2
- package/dist/cjs/api/types/EntitlementUsage.d.ts +23 -0
- package/dist/cjs/api/types/EntitlementUsage.js +5 -0
- package/dist/cjs/api/types/OrderLineAttributeCreate.d.ts +12 -0
- package/dist/cjs/api/types/OrderLineAttributeCreate.js +5 -0
- package/dist/cjs/api/types/OrderLineCreate.d.ts +7 -0
- package/dist/cjs/api/types/index.d.ts +2 -0
- package/dist/cjs/api/types/index.js +2 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/errors/ForbiddenError.d.mts +9 -0
- package/dist/esm/api/errors/ForbiddenError.mjs +15 -0
- package/dist/esm/api/errors/index.d.mts +1 -0
- package/dist/esm/api/errors/index.mjs +1 -0
- package/dist/esm/api/index.d.mts +1 -0
- package/dist/esm/api/index.mjs +1 -0
- package/dist/esm/api/resources/agents/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/agents/client/Client.mjs +6 -2
- package/dist/esm/api/resources/contacts/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/contacts/client/Client.mjs +6 -2
- package/dist/esm/api/resources/customers/client/Client.d.mts +14 -3
- package/dist/esm/api/resources/customers/client/Client.mjs +62 -2
- package/dist/esm/api/resources/orders/client/Client.d.mts +13 -3
- package/dist/esm/api/resources/orders/client/Client.mjs +16 -2
- package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +10 -0
- package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +6 -2
- package/dist/esm/api/resources/usage/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/usage/client/Client.mjs +6 -2
- package/dist/esm/api/types/EntitlementUsage.d.mts +23 -0
- package/dist/esm/api/types/EntitlementUsage.mjs +4 -0
- package/dist/esm/api/types/OrderLineAttributeCreate.d.mts +12 -0
- package/dist/esm/api/types/OrderLineAttributeCreate.mjs +4 -0
- package/dist/esm/api/types/OrderLineCreate.d.mts +7 -0
- package/dist/esm/api/types/index.d.mts +2 -0
- package/dist/esm/api/types/index.mjs +2 -0
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
- 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
|
-
|
|
92
|
-
As of now, the following
|
|
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
|
-
|
|
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
|
|
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
|
-
//
|
|
104
|
-
await client.initializeTracing()
|
|
114
|
+
// Initialize cost tracking
|
|
115
|
+
await client.initializeTracing();
|
|
105
116
|
|
|
106
|
-
//
|
|
107
|
-
const openaiClient = new OpenAI({ apiKey: "<your_openai_api_key" });
|
|
108
|
-
const
|
|
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
|
-
//
|
|
121
|
+
// Trace the call
|
|
111
122
|
await client.trace("<your_external_customer_id>", async () => {
|
|
112
|
-
const response = await
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
// ...
|
|
170
|
-
client.signal("
|
|
171
|
-
|
|
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
|
|
package/dist/cjs/Client.js
CHANGED
|
@@ -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.
|
|
64
|
-
"User-Agent": "@paid-ai/paid-node/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);
|
package/dist/cjs/api/index.d.ts
CHANGED
package/dist/cjs/api/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
}
|