@heymantle/core-api-client 0.1.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 +333 -0
- package/dist/index.d.mts +2907 -0
- package/dist/index.d.ts +2907 -0
- package/dist/index.js +1846 -0
- package/dist/index.mjs +1784 -0
- package/package.json +56 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1784 @@
|
|
|
1
|
+
// src/utils/sanitize.ts
|
|
2
|
+
function sanitizeObject(obj) {
|
|
3
|
+
if (!obj || typeof obj !== "object") {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
const sanitized = {};
|
|
7
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
+
if (value !== void 0) {
|
|
9
|
+
sanitized[key] = value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return sanitized;
|
|
13
|
+
}
|
|
14
|
+
function toQueryString(params) {
|
|
15
|
+
const sanitized = sanitizeObject(params);
|
|
16
|
+
const searchParams = new URLSearchParams();
|
|
17
|
+
for (const [key, value] of Object.entries(sanitized)) {
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
value.forEach((v) => searchParams.append(key, String(v)));
|
|
20
|
+
} else if (value !== null && value !== void 0) {
|
|
21
|
+
searchParams.append(key, String(value));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return searchParams.toString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/utils/errors.ts
|
|
28
|
+
var MantleAPIError = class _MantleAPIError extends Error {
|
|
29
|
+
constructor(message, statusCode, details) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "MantleAPIError";
|
|
32
|
+
this.statusCode = statusCode;
|
|
33
|
+
this.details = details;
|
|
34
|
+
Object.setPrototypeOf(this, _MantleAPIError.prototype);
|
|
35
|
+
}
|
|
36
|
+
static fromResponse(response, statusCode) {
|
|
37
|
+
return new _MantleAPIError(response.error, statusCode, response.details);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var MantleAuthenticationError = class _MantleAuthenticationError extends MantleAPIError {
|
|
41
|
+
constructor(message = "Authentication failed") {
|
|
42
|
+
super(message, 401);
|
|
43
|
+
this.name = "MantleAuthenticationError";
|
|
44
|
+
Object.setPrototypeOf(this, _MantleAuthenticationError.prototype);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var MantlePermissionError = class _MantlePermissionError extends MantleAPIError {
|
|
48
|
+
constructor(message = "Permission denied") {
|
|
49
|
+
super(message, 403);
|
|
50
|
+
this.name = "MantlePermissionError";
|
|
51
|
+
Object.setPrototypeOf(this, _MantlePermissionError.prototype);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var MantleNotFoundError = class _MantleNotFoundError extends MantleAPIError {
|
|
55
|
+
constructor(resource, id) {
|
|
56
|
+
super(`${resource} with id '${id}' not found`, 404);
|
|
57
|
+
this.name = "MantleNotFoundError";
|
|
58
|
+
Object.setPrototypeOf(this, _MantleNotFoundError.prototype);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var MantleValidationError = class _MantleValidationError extends MantleAPIError {
|
|
62
|
+
constructor(message, details) {
|
|
63
|
+
super(message, 422, details);
|
|
64
|
+
this.name = "MantleValidationError";
|
|
65
|
+
Object.setPrototypeOf(this, _MantleValidationError.prototype);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var MantleRateLimitError = class _MantleRateLimitError extends MantleAPIError {
|
|
69
|
+
constructor(message = "Rate limit exceeded", retryAfter) {
|
|
70
|
+
super(message, 429);
|
|
71
|
+
this.name = "MantleRateLimitError";
|
|
72
|
+
this.retryAfter = retryAfter;
|
|
73
|
+
Object.setPrototypeOf(this, _MantleRateLimitError.prototype);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/resources/base.ts
|
|
78
|
+
var BaseResource = class {
|
|
79
|
+
constructor(client) {
|
|
80
|
+
this.client = client;
|
|
81
|
+
}
|
|
82
|
+
get(endpoint, params) {
|
|
83
|
+
return this.client.get(endpoint, params);
|
|
84
|
+
}
|
|
85
|
+
post(endpoint, data) {
|
|
86
|
+
return this.client.post(endpoint, data);
|
|
87
|
+
}
|
|
88
|
+
put(endpoint, data) {
|
|
89
|
+
return this.client.put(endpoint, data);
|
|
90
|
+
}
|
|
91
|
+
_delete(endpoint) {
|
|
92
|
+
return this.client.delete(endpoint);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/resources/customers.ts
|
|
97
|
+
var CustomersResource = class extends BaseResource {
|
|
98
|
+
/**
|
|
99
|
+
* List customers with optional filters and pagination
|
|
100
|
+
*/
|
|
101
|
+
async list(params) {
|
|
102
|
+
const response = await this.get("/customers", params);
|
|
103
|
+
return {
|
|
104
|
+
customers: response.customers || [],
|
|
105
|
+
hasNextPage: response.hasNextPage || false,
|
|
106
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
107
|
+
total: response.total,
|
|
108
|
+
cursor: response.cursor
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Retrieve a single customer by ID
|
|
113
|
+
*/
|
|
114
|
+
async retrieve(customerId, params) {
|
|
115
|
+
return this.get(
|
|
116
|
+
`/customers/${customerId}`,
|
|
117
|
+
params
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a new customer
|
|
122
|
+
*/
|
|
123
|
+
async create(data) {
|
|
124
|
+
return this.post("/customers", data);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Update an existing customer
|
|
128
|
+
*/
|
|
129
|
+
async update(customerId, data) {
|
|
130
|
+
return this.put(
|
|
131
|
+
`/customers/${customerId}`,
|
|
132
|
+
data
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Add tags to a customer
|
|
137
|
+
*/
|
|
138
|
+
async addTags(customerId, tags) {
|
|
139
|
+
return this.post(
|
|
140
|
+
`/customers/${customerId}/addTags`,
|
|
141
|
+
{ tags }
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Remove tags from a customer
|
|
146
|
+
*/
|
|
147
|
+
async removeTags(customerId, tags) {
|
|
148
|
+
return this.post(
|
|
149
|
+
`/customers/${customerId}/removeTags`,
|
|
150
|
+
{ tags }
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get customer activity timeline
|
|
155
|
+
*/
|
|
156
|
+
async getTimeline(customerId, params) {
|
|
157
|
+
const response = await this.get(
|
|
158
|
+
`/customers/${customerId}/timeline`,
|
|
159
|
+
{ limit: 25, ...params }
|
|
160
|
+
);
|
|
161
|
+
return {
|
|
162
|
+
events: response.events || [],
|
|
163
|
+
hasNextPage: response.hasNextPage || false,
|
|
164
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
165
|
+
cursor: response.cursor
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* List account owners for a customer
|
|
170
|
+
*/
|
|
171
|
+
async listAccountOwners(customerId) {
|
|
172
|
+
return this.get(
|
|
173
|
+
`/customers/${customerId}/account_owners`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Add an account owner to a customer
|
|
178
|
+
*/
|
|
179
|
+
async addAccountOwner(customerId, data) {
|
|
180
|
+
return this.post(`/customers/${customerId}/account_owners`, data);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Remove an account owner from a customer
|
|
184
|
+
*/
|
|
185
|
+
async removeAccountOwner(customerId, ownerId) {
|
|
186
|
+
return this._delete(
|
|
187
|
+
`/customers/${customerId}/account_owners/${ownerId}`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* List custom fields
|
|
192
|
+
*/
|
|
193
|
+
async listCustomFields(params) {
|
|
194
|
+
return this.get(
|
|
195
|
+
"/customers/custom_fields",
|
|
196
|
+
params
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a custom field
|
|
201
|
+
*/
|
|
202
|
+
async createCustomField(data) {
|
|
203
|
+
return this.post(
|
|
204
|
+
"/customers/custom_fields",
|
|
205
|
+
data
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Retrieve a custom field by ID
|
|
210
|
+
*/
|
|
211
|
+
async retrieveCustomField(fieldId) {
|
|
212
|
+
return this.get(
|
|
213
|
+
`/customers/custom_fields/${fieldId}`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Update a custom field
|
|
218
|
+
*/
|
|
219
|
+
async updateCustomField(fieldId, data) {
|
|
220
|
+
return this.put(
|
|
221
|
+
`/customers/custom_fields/${fieldId}`,
|
|
222
|
+
data
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Delete a custom field
|
|
227
|
+
*/
|
|
228
|
+
async deleteCustomField(fieldId) {
|
|
229
|
+
return this._delete(
|
|
230
|
+
`/customers/custom_fields/${fieldId}`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// src/resources/contacts.ts
|
|
236
|
+
var ContactsResource = class extends BaseResource {
|
|
237
|
+
/**
|
|
238
|
+
* List contacts with optional filters and pagination
|
|
239
|
+
*/
|
|
240
|
+
async list(params) {
|
|
241
|
+
const response = await this.get("/contacts", params);
|
|
242
|
+
return {
|
|
243
|
+
contacts: response.contacts || [],
|
|
244
|
+
hasNextPage: response.hasNextPage || false,
|
|
245
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
246
|
+
total: response.total,
|
|
247
|
+
cursor: response.cursor
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Retrieve a single contact by ID
|
|
252
|
+
*/
|
|
253
|
+
async retrieve(contactId) {
|
|
254
|
+
return this.get(`/contacts/${contactId}`);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a new contact
|
|
258
|
+
*/
|
|
259
|
+
async create(data) {
|
|
260
|
+
return this.post("/contacts", data);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Update an existing contact
|
|
264
|
+
*/
|
|
265
|
+
async update(contactId, data) {
|
|
266
|
+
return this.put(`/contacts/${contactId}`, data);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Delete a contact
|
|
270
|
+
*/
|
|
271
|
+
async del(contactId) {
|
|
272
|
+
return this._delete(`/contacts/${contactId}`);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Add tags to a contact
|
|
276
|
+
*/
|
|
277
|
+
async addTags(contactId, tags) {
|
|
278
|
+
return this.post(
|
|
279
|
+
`/contacts/${contactId}/addTags`,
|
|
280
|
+
{ tags }
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Remove tags from a contact
|
|
285
|
+
*/
|
|
286
|
+
async removeTags(contactId, tags) {
|
|
287
|
+
return this.post(
|
|
288
|
+
`/contacts/${contactId}/removeTags`,
|
|
289
|
+
{ tags }
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/resources/subscriptions.ts
|
|
295
|
+
var SubscriptionsResource = class extends BaseResource {
|
|
296
|
+
/**
|
|
297
|
+
* List subscriptions with optional filters and pagination
|
|
298
|
+
*/
|
|
299
|
+
async list(params) {
|
|
300
|
+
const response = await this.get(
|
|
301
|
+
"/subscriptions",
|
|
302
|
+
params
|
|
303
|
+
);
|
|
304
|
+
return {
|
|
305
|
+
subscriptions: response.subscriptions || [],
|
|
306
|
+
hasNextPage: response.hasNextPage || false,
|
|
307
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
308
|
+
total: response.total,
|
|
309
|
+
cursor: response.cursor
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Retrieve a single subscription by ID
|
|
314
|
+
*/
|
|
315
|
+
async retrieve(subscriptionId) {
|
|
316
|
+
return this.get(
|
|
317
|
+
`/subscriptions/${subscriptionId}`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/resources/usage-events.ts
|
|
323
|
+
var UsageEventsResource = class extends BaseResource {
|
|
324
|
+
/**
|
|
325
|
+
* List usage events with optional filters and pagination
|
|
326
|
+
*/
|
|
327
|
+
async list(params) {
|
|
328
|
+
const response = await this.get(
|
|
329
|
+
"/usage_events",
|
|
330
|
+
params
|
|
331
|
+
);
|
|
332
|
+
return {
|
|
333
|
+
usageEvents: response.usageEvents || response.events || [],
|
|
334
|
+
events: response.events,
|
|
335
|
+
hasNextPage: response.hasNextPage || false,
|
|
336
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
337
|
+
total: response.total,
|
|
338
|
+
cursor: response.cursor
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Create usage event(s)
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* // Single event
|
|
346
|
+
* await client.usageEvents.create({
|
|
347
|
+
* eventName: 'api_call',
|
|
348
|
+
* customerId: 'cust_123',
|
|
349
|
+
* appId: 'app_456',
|
|
350
|
+
* properties: { endpoint: '/users' },
|
|
351
|
+
* });
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* // Multiple events
|
|
355
|
+
* await client.usageEvents.create({
|
|
356
|
+
* events: [
|
|
357
|
+
* { eventName: 'api_call', customerId: 'cust_123', appId: 'app_456' },
|
|
358
|
+
* { eventName: 'api_call', customerId: 'cust_789', appId: 'app_456' },
|
|
359
|
+
* ],
|
|
360
|
+
* });
|
|
361
|
+
*/
|
|
362
|
+
async create(data) {
|
|
363
|
+
return this.post("/usage_events", data);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// src/resources/apps.ts
|
|
368
|
+
var AppsResource = class extends BaseResource {
|
|
369
|
+
/**
|
|
370
|
+
* List all apps
|
|
371
|
+
*/
|
|
372
|
+
async list(params) {
|
|
373
|
+
return this.get("/apps", params);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Retrieve a single app by ID
|
|
377
|
+
*/
|
|
378
|
+
async retrieve(appId) {
|
|
379
|
+
return this.get(`/apps/${appId}`);
|
|
380
|
+
}
|
|
381
|
+
// ========== Plans ==========
|
|
382
|
+
/**
|
|
383
|
+
* List plans for an app
|
|
384
|
+
*/
|
|
385
|
+
async listPlans(appId, params) {
|
|
386
|
+
return this.get(`/apps/${appId}/plans`, params);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Retrieve a single plan
|
|
390
|
+
*/
|
|
391
|
+
async retrievePlan(appId, planId) {
|
|
392
|
+
return this.get(`/apps/${appId}/plans/${planId}`);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Create a new plan for an app
|
|
396
|
+
*/
|
|
397
|
+
async createPlan(appId, data) {
|
|
398
|
+
return this.post(`/apps/${appId}/plans`, data);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Update an existing plan
|
|
402
|
+
*/
|
|
403
|
+
async updatePlan(appId, planId, data) {
|
|
404
|
+
return this.put(`/apps/${appId}/plans/${planId}`, data);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Archive a plan
|
|
408
|
+
*/
|
|
409
|
+
async archivePlan(appId, planId) {
|
|
410
|
+
return this.post(
|
|
411
|
+
`/apps/${appId}/plans/${planId}/archive`,
|
|
412
|
+
{}
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Unarchive a plan
|
|
417
|
+
*/
|
|
418
|
+
async unarchivePlan(appId, planId) {
|
|
419
|
+
return this.post(
|
|
420
|
+
`/apps/${appId}/plans/${planId}/unarchive`,
|
|
421
|
+
{}
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
// ========== Features ==========
|
|
425
|
+
/**
|
|
426
|
+
* List features for an app
|
|
427
|
+
*/
|
|
428
|
+
async listFeatures(appId) {
|
|
429
|
+
return this.get(`/apps/${appId}/plans/features`);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Retrieve a single feature
|
|
433
|
+
*/
|
|
434
|
+
async retrieveFeature(appId, featureId) {
|
|
435
|
+
return this.get(
|
|
436
|
+
`/apps/${appId}/plans/features/${featureId}`
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Create a new feature for an app
|
|
441
|
+
*/
|
|
442
|
+
async createFeature(appId, data) {
|
|
443
|
+
return this.post(
|
|
444
|
+
`/apps/${appId}/plans/features`,
|
|
445
|
+
data
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Update an existing feature
|
|
450
|
+
*/
|
|
451
|
+
async updateFeature(appId, featureId, data) {
|
|
452
|
+
return this.put(
|
|
453
|
+
`/apps/${appId}/plans/features/${featureId}`,
|
|
454
|
+
data
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Delete a feature
|
|
459
|
+
*/
|
|
460
|
+
async deleteFeature(appId, featureId) {
|
|
461
|
+
return this._delete(
|
|
462
|
+
`/apps/${appId}/plans/features/${featureId}`
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
// ========== Reviews ==========
|
|
466
|
+
/**
|
|
467
|
+
* List reviews for an app
|
|
468
|
+
*/
|
|
469
|
+
async listReviews(appId) {
|
|
470
|
+
return this.get(`/apps/${appId}/reviews`);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Retrieve a single review
|
|
474
|
+
*/
|
|
475
|
+
async retrieveReview(appId, reviewId) {
|
|
476
|
+
return this.get(`/apps/${appId}/reviews/${reviewId}`);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Create a new review for an app
|
|
480
|
+
*/
|
|
481
|
+
async createReview(appId, data) {
|
|
482
|
+
return this.post(`/apps/${appId}/reviews`, data);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Update an existing review
|
|
486
|
+
*/
|
|
487
|
+
async updateReview(appId, reviewId, data) {
|
|
488
|
+
return this.put(
|
|
489
|
+
`/apps/${appId}/reviews/${reviewId}`,
|
|
490
|
+
data
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Delete a review
|
|
495
|
+
*/
|
|
496
|
+
async deleteReview(appId, reviewId) {
|
|
497
|
+
return this._delete(`/apps/${appId}/reviews/${reviewId}`);
|
|
498
|
+
}
|
|
499
|
+
// ========== Usage Event Metadata ==========
|
|
500
|
+
/**
|
|
501
|
+
* Get usage event names for an app
|
|
502
|
+
*/
|
|
503
|
+
async listEventNames(appId) {
|
|
504
|
+
return this.get(
|
|
505
|
+
`/apps/${appId}/usage_events/event_names`
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Get property keys for a specific event name
|
|
510
|
+
*/
|
|
511
|
+
async listPropertyKeys(appId, eventName) {
|
|
512
|
+
return this.get(
|
|
513
|
+
`/apps/${appId}/usage_events/property_keys`,
|
|
514
|
+
{ eventName }
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
// ========== Usage Metrics ==========
|
|
518
|
+
/**
|
|
519
|
+
* List usage metrics for an app
|
|
520
|
+
*/
|
|
521
|
+
async listUsageMetrics(appId) {
|
|
522
|
+
return this.get(
|
|
523
|
+
`/apps/${appId}/usage_metrics`
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Retrieve a single usage metric
|
|
528
|
+
*/
|
|
529
|
+
async retrieveUsageMetric(appId, usageMetricId) {
|
|
530
|
+
return this.get(
|
|
531
|
+
`/apps/${appId}/usage_metrics/${usageMetricId}`
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Create a new usage metric for an app
|
|
536
|
+
*/
|
|
537
|
+
async createUsageMetric(appId, data) {
|
|
538
|
+
return this.post(
|
|
539
|
+
`/apps/${appId}/usage_metrics`,
|
|
540
|
+
data
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Update an existing usage metric
|
|
545
|
+
*/
|
|
546
|
+
async updateUsageMetric(appId, usageMetricId, data) {
|
|
547
|
+
return this.put(
|
|
548
|
+
`/apps/${appId}/usage_metrics/${usageMetricId}`,
|
|
549
|
+
data
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Delete a usage metric
|
|
554
|
+
*/
|
|
555
|
+
async deleteUsageMetric(appId, usageMetricId) {
|
|
556
|
+
return this._delete(
|
|
557
|
+
`/apps/${appId}/usage_metrics/${usageMetricId}`
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
// ========== App Events ==========
|
|
561
|
+
/**
|
|
562
|
+
* List app events
|
|
563
|
+
*/
|
|
564
|
+
async listAppEvents(appId, params) {
|
|
565
|
+
const response = await this.get(
|
|
566
|
+
`/apps/${appId}/app_events`,
|
|
567
|
+
params
|
|
568
|
+
);
|
|
569
|
+
return {
|
|
570
|
+
appEvents: response.appEvents || [],
|
|
571
|
+
hasNextPage: response.hasNextPage || false,
|
|
572
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
573
|
+
total: response.total,
|
|
574
|
+
cursor: response.cursor
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
// src/resources/deals.ts
|
|
580
|
+
var DealsResource = class extends BaseResource {
|
|
581
|
+
/**
|
|
582
|
+
* List deals with optional filters and pagination
|
|
583
|
+
*/
|
|
584
|
+
async list(params) {
|
|
585
|
+
const response = await this.get("/deals", params);
|
|
586
|
+
return {
|
|
587
|
+
deals: response.deals || [],
|
|
588
|
+
hasNextPage: response.hasNextPage || false,
|
|
589
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
590
|
+
total: response.total,
|
|
591
|
+
cursor: response.cursor
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Retrieve a single deal by ID
|
|
596
|
+
*/
|
|
597
|
+
async retrieve(dealId) {
|
|
598
|
+
return this.get(`/deals/${dealId}`);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Create a new deal
|
|
602
|
+
*/
|
|
603
|
+
async create(data) {
|
|
604
|
+
return this.post("/deals", data);
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Update an existing deal
|
|
608
|
+
*/
|
|
609
|
+
async update(dealId, data) {
|
|
610
|
+
return this.put(`/deals/${dealId}`, data);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Archive (soft delete) a deal
|
|
614
|
+
*/
|
|
615
|
+
async del(dealId) {
|
|
616
|
+
return this._delete(`/deals/${dealId}`);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Get deal activity timeline
|
|
620
|
+
*/
|
|
621
|
+
async getTimeline(dealId) {
|
|
622
|
+
const response = await this.get(
|
|
623
|
+
`/deals/${dealId}/timeline`
|
|
624
|
+
);
|
|
625
|
+
return {
|
|
626
|
+
events: response.events || [],
|
|
627
|
+
hasNextPage: response.hasNextPage || false,
|
|
628
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
629
|
+
cursor: response.cursor
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Get deal events
|
|
634
|
+
*/
|
|
635
|
+
async getEvents(dealId) {
|
|
636
|
+
return this.get(`/deals/${dealId}/events`);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
// src/resources/deal-flows.ts
|
|
641
|
+
var DealFlowsResource = class extends BaseResource {
|
|
642
|
+
/**
|
|
643
|
+
* List all deal flows
|
|
644
|
+
*/
|
|
645
|
+
async list() {
|
|
646
|
+
return this.get("/deal_flows");
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Retrieve a single deal flow by ID
|
|
650
|
+
*/
|
|
651
|
+
async retrieve(dealFlowId) {
|
|
652
|
+
return this.get(`/deal_flows/${dealFlowId}`);
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Create a new deal flow
|
|
656
|
+
*/
|
|
657
|
+
async create(data) {
|
|
658
|
+
return this.post("/deal_flows", data);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Update an existing deal flow
|
|
662
|
+
*/
|
|
663
|
+
async update(dealFlowId, data) {
|
|
664
|
+
return this.put(
|
|
665
|
+
`/deal_flows/${dealFlowId}`,
|
|
666
|
+
data
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Delete a deal flow
|
|
671
|
+
*/
|
|
672
|
+
async del(dealFlowId) {
|
|
673
|
+
return this._delete(`/deal_flows/${dealFlowId}`);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
// src/resources/deal-activities.ts
|
|
678
|
+
var DealActivitiesResource = class extends BaseResource {
|
|
679
|
+
/**
|
|
680
|
+
* List all deal activities
|
|
681
|
+
*/
|
|
682
|
+
async list() {
|
|
683
|
+
return this.get("/deal_activities");
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Retrieve a single deal activity by ID
|
|
687
|
+
*/
|
|
688
|
+
async retrieve(dealActivityId) {
|
|
689
|
+
return this.get(
|
|
690
|
+
`/deal_activities/${dealActivityId}`
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Create a new deal activity
|
|
695
|
+
*/
|
|
696
|
+
async create(data) {
|
|
697
|
+
return this.post("/deal_activities", data);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Update an existing deal activity
|
|
701
|
+
*/
|
|
702
|
+
async update(dealActivityId, data) {
|
|
703
|
+
return this.put(
|
|
704
|
+
`/deal_activities/${dealActivityId}`,
|
|
705
|
+
data
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Delete a deal activity
|
|
710
|
+
*/
|
|
711
|
+
async del(dealActivityId) {
|
|
712
|
+
return this._delete(`/deal_activities/${dealActivityId}`);
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
// src/resources/tickets.ts
|
|
717
|
+
var TicketsResource = class extends BaseResource {
|
|
718
|
+
/**
|
|
719
|
+
* List tickets with optional filters and pagination
|
|
720
|
+
*/
|
|
721
|
+
async list(params) {
|
|
722
|
+
const response = await this.get("/tickets", params);
|
|
723
|
+
return {
|
|
724
|
+
tickets: response.tickets || [],
|
|
725
|
+
hasNextPage: response.hasNextPage || false,
|
|
726
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
727
|
+
total: response.total,
|
|
728
|
+
cursor: response.cursor
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Retrieve a single ticket by ID
|
|
733
|
+
*/
|
|
734
|
+
async retrieve(ticketId) {
|
|
735
|
+
return this.get(`/tickets/${ticketId}`);
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Create a new ticket
|
|
739
|
+
*/
|
|
740
|
+
async create(data) {
|
|
741
|
+
return this.post("/tickets", data);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Update an existing ticket
|
|
745
|
+
*/
|
|
746
|
+
async update(ticketId, data) {
|
|
747
|
+
return this.put(`/tickets/${ticketId}`, data);
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Delete a ticket
|
|
751
|
+
*/
|
|
752
|
+
async del(ticketId) {
|
|
753
|
+
return this._delete(`/tickets/${ticketId}`);
|
|
754
|
+
}
|
|
755
|
+
// ========== Messages ==========
|
|
756
|
+
/**
|
|
757
|
+
* List messages for a ticket
|
|
758
|
+
*/
|
|
759
|
+
async listMessages(ticketId) {
|
|
760
|
+
return this.get(
|
|
761
|
+
`/tickets/${ticketId}/messages`
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Retrieve a single message
|
|
766
|
+
*/
|
|
767
|
+
async retrieveMessage(ticketId, messageId) {
|
|
768
|
+
return this.get(
|
|
769
|
+
`/tickets/${ticketId}/messages/${messageId}`
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Create a new message on a ticket
|
|
774
|
+
*/
|
|
775
|
+
async createMessage(ticketId, data) {
|
|
776
|
+
return this.post(
|
|
777
|
+
`/tickets/${ticketId}/messages`,
|
|
778
|
+
data
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Update a message
|
|
783
|
+
*/
|
|
784
|
+
async updateMessage(ticketId, messageId, data) {
|
|
785
|
+
return this.put(
|
|
786
|
+
`/tickets/${ticketId}/messages/${messageId}`,
|
|
787
|
+
data
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Delete a message
|
|
792
|
+
*/
|
|
793
|
+
async deleteMessage(ticketId, messageId) {
|
|
794
|
+
return this._delete(
|
|
795
|
+
`/tickets/${ticketId}/messages/${messageId}`
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
// src/resources/channels.ts
|
|
801
|
+
var ChannelsResource = class extends BaseResource {
|
|
802
|
+
/**
|
|
803
|
+
* List CX channels
|
|
804
|
+
*/
|
|
805
|
+
async list(params) {
|
|
806
|
+
return this.get("/channels", params);
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Create a new CX channel
|
|
810
|
+
*/
|
|
811
|
+
async create(data) {
|
|
812
|
+
return this.post("/channels", data);
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
// src/resources/flows.ts
|
|
817
|
+
var FlowsResource = class extends BaseResource {
|
|
818
|
+
/**
|
|
819
|
+
* List flows with optional filters and pagination
|
|
820
|
+
*/
|
|
821
|
+
async list(params) {
|
|
822
|
+
const response = await this.get("/flows", params);
|
|
823
|
+
return {
|
|
824
|
+
flows: response.flows || [],
|
|
825
|
+
hasNextPage: response.hasNextPage || false,
|
|
826
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
827
|
+
total: response.total,
|
|
828
|
+
cursor: response.cursor
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Retrieve a single flow by ID
|
|
833
|
+
*/
|
|
834
|
+
async retrieve(flowId) {
|
|
835
|
+
return this.get(`/flows/${flowId}`);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Create a new flow
|
|
839
|
+
*/
|
|
840
|
+
async create(data) {
|
|
841
|
+
return this.post("/flows", data);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Update an existing flow
|
|
845
|
+
*/
|
|
846
|
+
async update(flowId, data) {
|
|
847
|
+
return this.put(`/flows/${flowId}`, data);
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Delete a flow
|
|
851
|
+
*/
|
|
852
|
+
async del(flowId) {
|
|
853
|
+
return this._delete(`/flows/${flowId}`);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
// src/resources/tasks.ts
|
|
858
|
+
var TasksResource = class extends BaseResource {
|
|
859
|
+
/**
|
|
860
|
+
* List tasks with optional filters and pagination
|
|
861
|
+
*/
|
|
862
|
+
async list(params) {
|
|
863
|
+
const response = await this.get("/tasks", params);
|
|
864
|
+
return {
|
|
865
|
+
tasks: response.tasks || [],
|
|
866
|
+
hasNextPage: response.hasNextPage || false,
|
|
867
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
868
|
+
total: response.total,
|
|
869
|
+
cursor: response.cursor
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Retrieve a single task by ID
|
|
874
|
+
*/
|
|
875
|
+
async retrieve(taskId) {
|
|
876
|
+
return this.get(`/tasks/${taskId}`);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Create a new task
|
|
880
|
+
*/
|
|
881
|
+
async create(data) {
|
|
882
|
+
return this.post("/tasks", data);
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Update an existing task
|
|
886
|
+
*/
|
|
887
|
+
async update(taskId, data) {
|
|
888
|
+
return this.put(`/tasks/${taskId}`, data);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Delete a task
|
|
892
|
+
*/
|
|
893
|
+
async del(taskId) {
|
|
894
|
+
return this._delete(`/tasks/${taskId}`);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
|
|
898
|
+
// src/resources/webhooks.ts
|
|
899
|
+
var WebhooksResource = class extends BaseResource {
|
|
900
|
+
/**
|
|
901
|
+
* List all webhooks
|
|
902
|
+
*/
|
|
903
|
+
async list() {
|
|
904
|
+
const response = await this.get("/webhooks");
|
|
905
|
+
return {
|
|
906
|
+
webhooks: response.webhooks || [],
|
|
907
|
+
hasNextPage: response.hasNextPage || false,
|
|
908
|
+
hasPreviousPage: response.hasPreviousPage || false
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Retrieve a single webhook by ID
|
|
913
|
+
*/
|
|
914
|
+
async retrieve(webhookId) {
|
|
915
|
+
return this.get(`/webhooks/${webhookId}`);
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Create a new webhook
|
|
919
|
+
*/
|
|
920
|
+
async create(data) {
|
|
921
|
+
return this.post("/webhooks", data);
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* Update an existing webhook
|
|
925
|
+
*/
|
|
926
|
+
async update(webhookId, data) {
|
|
927
|
+
return this.put(`/webhooks/${webhookId}`, data);
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Delete a webhook
|
|
931
|
+
*/
|
|
932
|
+
async del(webhookId) {
|
|
933
|
+
return this._delete(`/webhooks/${webhookId}`);
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
// src/resources/companies.ts
|
|
938
|
+
var CompaniesResource = class extends BaseResource {
|
|
939
|
+
/**
|
|
940
|
+
* List companies with optional pagination
|
|
941
|
+
*/
|
|
942
|
+
async list(params) {
|
|
943
|
+
const response = await this.get("/companies", params);
|
|
944
|
+
return {
|
|
945
|
+
companies: response.companies || [],
|
|
946
|
+
hasNextPage: response.hasNextPage || false,
|
|
947
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
948
|
+
cursor: response.cursor
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Retrieve a single company by ID
|
|
953
|
+
*/
|
|
954
|
+
async retrieve(companyId) {
|
|
955
|
+
return this.get(`/companies/${companyId}`);
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Create a new company
|
|
959
|
+
*/
|
|
960
|
+
async create(data) {
|
|
961
|
+
return this.post("/companies", data);
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Update an existing company
|
|
965
|
+
*/
|
|
966
|
+
async update(companyId, data) {
|
|
967
|
+
return this.put(`/companies/${companyId}`, data);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Delete a company
|
|
971
|
+
*/
|
|
972
|
+
async del(companyId) {
|
|
973
|
+
return this._delete(`/companies/${companyId}`);
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
// src/resources/customer-segments.ts
|
|
978
|
+
var CustomerSegmentsResource = class extends BaseResource {
|
|
979
|
+
/**
|
|
980
|
+
* List public customer segments with optional pagination
|
|
981
|
+
*/
|
|
982
|
+
async list(params) {
|
|
983
|
+
const response = await this.get(
|
|
984
|
+
"/customer_segments",
|
|
985
|
+
params
|
|
986
|
+
);
|
|
987
|
+
return {
|
|
988
|
+
customerSegments: response.customerSegments || [],
|
|
989
|
+
hasNextPage: response.hasNextPage || false,
|
|
990
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
991
|
+
cursor: response.cursor
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Retrieve a single customer segment by ID
|
|
996
|
+
*/
|
|
997
|
+
async retrieve(segmentId) {
|
|
998
|
+
return this.get(
|
|
999
|
+
`/customer_segments/${segmentId}`
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
// src/resources/affiliates.ts
|
|
1005
|
+
var AffiliatesResource = class extends BaseResource {
|
|
1006
|
+
/**
|
|
1007
|
+
* List affiliates with optional filters and pagination
|
|
1008
|
+
*/
|
|
1009
|
+
async list(params) {
|
|
1010
|
+
const response = await this.get(
|
|
1011
|
+
"/affiliates",
|
|
1012
|
+
params
|
|
1013
|
+
);
|
|
1014
|
+
return {
|
|
1015
|
+
affiliates: response.affiliates || [],
|
|
1016
|
+
hasNextPage: response.hasNextPage || false,
|
|
1017
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1018
|
+
cursor: response.cursor
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Retrieve a single affiliate by ID
|
|
1023
|
+
*/
|
|
1024
|
+
async retrieve(affiliateId) {
|
|
1025
|
+
return this.get(`/affiliates/${affiliateId}`);
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Update an existing affiliate
|
|
1029
|
+
*/
|
|
1030
|
+
async update(affiliateId, data) {
|
|
1031
|
+
return this.put(
|
|
1032
|
+
`/affiliates/${affiliateId}`,
|
|
1033
|
+
data
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
// src/resources/affiliate-programs.ts
|
|
1039
|
+
var AffiliateProgramsResource = class extends BaseResource {
|
|
1040
|
+
/**
|
|
1041
|
+
* List all affiliate programs
|
|
1042
|
+
*/
|
|
1043
|
+
async list() {
|
|
1044
|
+
return this.get(
|
|
1045
|
+
"/affiliate_programs"
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Retrieve a single affiliate program by ID
|
|
1050
|
+
*/
|
|
1051
|
+
async retrieve(programId) {
|
|
1052
|
+
return this.get(
|
|
1053
|
+
`/affiliate_programs/${programId}`
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Create a new affiliate program
|
|
1058
|
+
*/
|
|
1059
|
+
async create(data) {
|
|
1060
|
+
return this.post(
|
|
1061
|
+
"/affiliate_programs",
|
|
1062
|
+
data
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Update an existing affiliate program
|
|
1067
|
+
*/
|
|
1068
|
+
async update(programId, data) {
|
|
1069
|
+
return this.put(
|
|
1070
|
+
`/affiliate_programs/${programId}`,
|
|
1071
|
+
data
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Delete an affiliate program
|
|
1076
|
+
*/
|
|
1077
|
+
async del(programId) {
|
|
1078
|
+
return this._delete(`/affiliate_programs/${programId}`);
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
// src/resources/affiliate-commissions.ts
|
|
1083
|
+
var AffiliateCommissionsResource = class extends BaseResource {
|
|
1084
|
+
/**
|
|
1085
|
+
* List affiliate commissions with optional filters and pagination
|
|
1086
|
+
*/
|
|
1087
|
+
async list(params) {
|
|
1088
|
+
const response = await this.get(
|
|
1089
|
+
"/affiliate_commissions",
|
|
1090
|
+
params
|
|
1091
|
+
);
|
|
1092
|
+
return {
|
|
1093
|
+
commissions: response.commissions || [],
|
|
1094
|
+
hasNextPage: response.hasNextPage || false,
|
|
1095
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1096
|
+
cursor: response.cursor
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Retrieve a single affiliate commission by ID
|
|
1101
|
+
*/
|
|
1102
|
+
async retrieve(commissionId) {
|
|
1103
|
+
return this.get(
|
|
1104
|
+
`/affiliate_commissions/${commissionId}`
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
// src/resources/affiliate-payouts.ts
|
|
1110
|
+
var AffiliatePayoutsResource = class extends BaseResource {
|
|
1111
|
+
/**
|
|
1112
|
+
* List affiliate payouts with optional filters and pagination
|
|
1113
|
+
*/
|
|
1114
|
+
async list(params) {
|
|
1115
|
+
const response = await this.get(
|
|
1116
|
+
"/affiliate_payouts",
|
|
1117
|
+
params
|
|
1118
|
+
);
|
|
1119
|
+
return {
|
|
1120
|
+
payouts: response.payouts || [],
|
|
1121
|
+
hasNextPage: response.hasNextPage || false,
|
|
1122
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1123
|
+
cursor: response.cursor
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Retrieve a single affiliate payout by ID
|
|
1128
|
+
*/
|
|
1129
|
+
async retrieve(payoutId) {
|
|
1130
|
+
return this.get(
|
|
1131
|
+
`/affiliate_payouts/${payoutId}`
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
// src/resources/affiliate-referrals.ts
|
|
1137
|
+
var AffiliateReferralsResource = class extends BaseResource {
|
|
1138
|
+
/**
|
|
1139
|
+
* List affiliate referrals with optional filters and pagination
|
|
1140
|
+
*/
|
|
1141
|
+
async list(params) {
|
|
1142
|
+
const response = await this.get(
|
|
1143
|
+
"/affiliate_referrals",
|
|
1144
|
+
params
|
|
1145
|
+
);
|
|
1146
|
+
return {
|
|
1147
|
+
referrals: response.referrals || [],
|
|
1148
|
+
hasNextPage: response.hasNextPage || false,
|
|
1149
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1150
|
+
cursor: response.cursor
|
|
1151
|
+
};
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Retrieve a single affiliate referral by ID
|
|
1155
|
+
*/
|
|
1156
|
+
async retrieve(referralId) {
|
|
1157
|
+
return this.get(
|
|
1158
|
+
`/affiliate_referrals/${referralId}`
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
// src/resources/charges.ts
|
|
1164
|
+
var ChargesResource = class extends BaseResource {
|
|
1165
|
+
/**
|
|
1166
|
+
* List charges with optional filters and pagination
|
|
1167
|
+
*/
|
|
1168
|
+
async list(params) {
|
|
1169
|
+
const response = await this.get("/charges", params);
|
|
1170
|
+
return {
|
|
1171
|
+
charges: response.charges || [],
|
|
1172
|
+
hasNextPage: response.hasNextPage || false,
|
|
1173
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1174
|
+
total: response.total,
|
|
1175
|
+
cursor: response.cursor
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
// src/resources/transactions.ts
|
|
1181
|
+
var TransactionsResource = class extends BaseResource {
|
|
1182
|
+
/**
|
|
1183
|
+
* List transactions with optional filters and pagination
|
|
1184
|
+
*/
|
|
1185
|
+
async list(params) {
|
|
1186
|
+
const response = await this.get(
|
|
1187
|
+
"/transactions",
|
|
1188
|
+
params
|
|
1189
|
+
);
|
|
1190
|
+
return {
|
|
1191
|
+
transactions: response.transactions || [],
|
|
1192
|
+
hasNextPage: response.hasNextPage || false,
|
|
1193
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1194
|
+
total: response.total,
|
|
1195
|
+
cursor: response.cursor
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Retrieve a single transaction by ID
|
|
1200
|
+
*/
|
|
1201
|
+
async retrieve(transactionId) {
|
|
1202
|
+
return this.get(
|
|
1203
|
+
`/transactions/${transactionId}`
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// src/resources/metrics.ts
|
|
1209
|
+
var MetricsResource = class extends BaseResource {
|
|
1210
|
+
/**
|
|
1211
|
+
* Fetch metrics with custom parameters
|
|
1212
|
+
*/
|
|
1213
|
+
async fetch(params) {
|
|
1214
|
+
const response = await this.client.get("/metrics", {
|
|
1215
|
+
...params,
|
|
1216
|
+
includes: params.includes || ["includeTotal"],
|
|
1217
|
+
appEventsForMrr: params.appEventsForMrr ?? true
|
|
1218
|
+
});
|
|
1219
|
+
const data = Array.isArray(response) ? response : [];
|
|
1220
|
+
const first = data[0];
|
|
1221
|
+
return {
|
|
1222
|
+
data,
|
|
1223
|
+
total: first?.total,
|
|
1224
|
+
startingTotal: first?.startingTotal,
|
|
1225
|
+
change: first?.change,
|
|
1226
|
+
changePercentage: first?.changePercentage,
|
|
1227
|
+
formattedTotal: first?.formattedTotal,
|
|
1228
|
+
formattedChange: first?.formattedChange,
|
|
1229
|
+
formattedChangePercentage: first?.formattedChangePercentage
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Get Annual Recurring Revenue (ARR)
|
|
1234
|
+
*/
|
|
1235
|
+
async arr(params) {
|
|
1236
|
+
return this.fetch({
|
|
1237
|
+
metric: "PlatformApp.arr",
|
|
1238
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1239
|
+
...params
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Get Monthly Recurring Revenue (MRR)
|
|
1244
|
+
*/
|
|
1245
|
+
async mrr(params) {
|
|
1246
|
+
return this.fetch({
|
|
1247
|
+
metric: "PlatformApp.mrr",
|
|
1248
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1249
|
+
...params
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Get active subscriptions count
|
|
1254
|
+
*/
|
|
1255
|
+
async activeSubscriptions(params) {
|
|
1256
|
+
return this.fetch({
|
|
1257
|
+
metric: "PlatformApp.activeSubscriptions",
|
|
1258
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1259
|
+
...params
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Get active installations count
|
|
1264
|
+
*/
|
|
1265
|
+
async activeInstalls(params) {
|
|
1266
|
+
return this.fetch({
|
|
1267
|
+
metric: "PlatformApp.activeInstalls",
|
|
1268
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1269
|
+
...params
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Get net new installations
|
|
1274
|
+
*/
|
|
1275
|
+
async netInstalls(params) {
|
|
1276
|
+
return this.fetch({
|
|
1277
|
+
metric: "PlatformApp.netInstalls",
|
|
1278
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1279
|
+
...params
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Get Average Revenue Per User (ARPU)
|
|
1284
|
+
*/
|
|
1285
|
+
async arpu(params) {
|
|
1286
|
+
return this.fetch({
|
|
1287
|
+
metric: "PlatformApp.arpu",
|
|
1288
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1289
|
+
...params
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Get Lifetime Value (LTV)
|
|
1294
|
+
*/
|
|
1295
|
+
async ltv(params) {
|
|
1296
|
+
return this.fetch({
|
|
1297
|
+
metric: "PlatformApp.ltv",
|
|
1298
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1299
|
+
...params
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Get revenue churn rate
|
|
1304
|
+
*/
|
|
1305
|
+
async revenueChurn(params) {
|
|
1306
|
+
return this.fetch({
|
|
1307
|
+
metric: "PlatformApp.revenueChurn",
|
|
1308
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1309
|
+
...params
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Get logo (customer) churn rate
|
|
1314
|
+
*/
|
|
1315
|
+
async logoChurn(params) {
|
|
1316
|
+
return this.fetch({
|
|
1317
|
+
metric: "PlatformApp.logoChurn",
|
|
1318
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1319
|
+
...params
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Get revenue retention rate
|
|
1324
|
+
*/
|
|
1325
|
+
async revenueRetention(params) {
|
|
1326
|
+
return this.fetch({
|
|
1327
|
+
metric: "PlatformApp.revenueRetention",
|
|
1328
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1329
|
+
...params
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Get net revenue retention rate
|
|
1334
|
+
*/
|
|
1335
|
+
async netRevenueRetention(params) {
|
|
1336
|
+
return this.fetch({
|
|
1337
|
+
metric: "PlatformApp.netRevenueRetention",
|
|
1338
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1339
|
+
...params
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Get net revenue
|
|
1344
|
+
*/
|
|
1345
|
+
async netRevenue(params) {
|
|
1346
|
+
return this.fetch({
|
|
1347
|
+
metric: "PlatformApp.netRevenue",
|
|
1348
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1349
|
+
...params
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Get payout amount
|
|
1354
|
+
*/
|
|
1355
|
+
async payout(params) {
|
|
1356
|
+
return this.fetch({
|
|
1357
|
+
metric: "PlatformApp.payout",
|
|
1358
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1359
|
+
...params
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Get predicted Lifetime Value
|
|
1364
|
+
*/
|
|
1365
|
+
async predictedLtv(params) {
|
|
1366
|
+
return this.fetch({
|
|
1367
|
+
metric: "PlatformApp.predictedLtv",
|
|
1368
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1369
|
+
...params
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Get charges
|
|
1374
|
+
*/
|
|
1375
|
+
async charges(params) {
|
|
1376
|
+
return this.fetch({
|
|
1377
|
+
metric: "PlatformApp.charges",
|
|
1378
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1379
|
+
...params
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Get usage event metrics
|
|
1384
|
+
*/
|
|
1385
|
+
async usageEvent(params) {
|
|
1386
|
+
return this.fetch({
|
|
1387
|
+
metric: "PlatformApp.usageEvent",
|
|
1388
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1389
|
+
...params
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Get usage metric data
|
|
1394
|
+
*/
|
|
1395
|
+
async usageMetric(params) {
|
|
1396
|
+
return this.fetch({
|
|
1397
|
+
metric: "PlatformApp.usageMetric",
|
|
1398
|
+
dateRange: params.dateRange || "last_30_days",
|
|
1399
|
+
...params
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
// src/resources/users.ts
|
|
1405
|
+
var UsersResource = class extends BaseResource {
|
|
1406
|
+
/**
|
|
1407
|
+
* List organization users with optional pagination
|
|
1408
|
+
*/
|
|
1409
|
+
async list(params) {
|
|
1410
|
+
const response = await this.get("/users", params);
|
|
1411
|
+
return {
|
|
1412
|
+
users: response.users || [],
|
|
1413
|
+
hasNextPage: response.hasNextPage || false,
|
|
1414
|
+
hasPreviousPage: response.hasPreviousPage || false,
|
|
1415
|
+
cursor: response.cursor
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Retrieve a single user by ID
|
|
1420
|
+
*/
|
|
1421
|
+
async retrieve(userId) {
|
|
1422
|
+
return this.get(`/users/${userId}`);
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
1425
|
+
|
|
1426
|
+
// src/resources/me.ts
|
|
1427
|
+
var MeResource = class extends BaseResource {
|
|
1428
|
+
/**
|
|
1429
|
+
* Get current user and organization info
|
|
1430
|
+
*/
|
|
1431
|
+
async retrieve() {
|
|
1432
|
+
return this.client.get("/me");
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
// src/resources/organization.ts
|
|
1437
|
+
var OrganizationResource = class extends BaseResource {
|
|
1438
|
+
/**
|
|
1439
|
+
* Get organization details
|
|
1440
|
+
*/
|
|
1441
|
+
async retrieve() {
|
|
1442
|
+
return this.client.get("/organization");
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
// src/resources/agents.ts
|
|
1447
|
+
var AgentsResource = class extends BaseResource {
|
|
1448
|
+
/**
|
|
1449
|
+
* List support agents
|
|
1450
|
+
*/
|
|
1451
|
+
async list() {
|
|
1452
|
+
return this.get("/agents");
|
|
1453
|
+
}
|
|
1454
|
+
};
|
|
1455
|
+
|
|
1456
|
+
// src/resources/docs.ts
|
|
1457
|
+
var DocsResource = class extends BaseResource {
|
|
1458
|
+
// ========== Collections ==========
|
|
1459
|
+
/**
|
|
1460
|
+
* List all doc collections
|
|
1461
|
+
*/
|
|
1462
|
+
async listCollections() {
|
|
1463
|
+
return this.get("/docs/collections");
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* Retrieve a single doc collection
|
|
1467
|
+
*/
|
|
1468
|
+
async retrieveCollection(collectionId) {
|
|
1469
|
+
return this.get(
|
|
1470
|
+
`/docs/collections/${collectionId}`
|
|
1471
|
+
);
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Create a new doc collection
|
|
1475
|
+
*/
|
|
1476
|
+
async createCollection(data) {
|
|
1477
|
+
return this.post("/docs/collections", data);
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Update a doc collection
|
|
1481
|
+
*/
|
|
1482
|
+
async updateCollection(collectionId, data) {
|
|
1483
|
+
return this.put(
|
|
1484
|
+
`/docs/collections/${collectionId}`,
|
|
1485
|
+
data
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Delete a doc collection
|
|
1490
|
+
*/
|
|
1491
|
+
async deleteCollection(collectionId) {
|
|
1492
|
+
return this._delete(`/docs/collections/${collectionId}`);
|
|
1493
|
+
}
|
|
1494
|
+
// ========== Groups ==========
|
|
1495
|
+
/**
|
|
1496
|
+
* List all doc groups
|
|
1497
|
+
*/
|
|
1498
|
+
async listGroups() {
|
|
1499
|
+
return this.get("/docs/groups");
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Retrieve a single doc group
|
|
1503
|
+
*/
|
|
1504
|
+
async retrieveGroup(groupId) {
|
|
1505
|
+
return this.get(`/docs/groups/${groupId}`);
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Create a new doc group
|
|
1509
|
+
*/
|
|
1510
|
+
async createGroup(data) {
|
|
1511
|
+
return this.post("/docs/groups", data);
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Update a doc group
|
|
1515
|
+
*/
|
|
1516
|
+
async updateGroup(groupId, data) {
|
|
1517
|
+
return this.put(`/docs/groups/${groupId}`, data);
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Delete a doc group
|
|
1521
|
+
*/
|
|
1522
|
+
async deleteGroup(groupId) {
|
|
1523
|
+
return this._delete(`/docs/groups/${groupId}`);
|
|
1524
|
+
}
|
|
1525
|
+
// ========== Pages ==========
|
|
1526
|
+
/**
|
|
1527
|
+
* List doc pages with optional filters
|
|
1528
|
+
*/
|
|
1529
|
+
async listPages(params) {
|
|
1530
|
+
const response = await this.get("/docs/pages", params);
|
|
1531
|
+
return {
|
|
1532
|
+
pages: response.pages || [],
|
|
1533
|
+
hasNextPage: response.hasNextPage || false,
|
|
1534
|
+
hasPreviousPage: response.hasPreviousPage || false
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Retrieve a single doc page
|
|
1539
|
+
*/
|
|
1540
|
+
async retrievePage(pageId) {
|
|
1541
|
+
return this.get(`/docs/pages/${pageId}`);
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Create a new doc page
|
|
1545
|
+
*/
|
|
1546
|
+
async createPage(data) {
|
|
1547
|
+
return this.post("/docs/pages", data);
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Update a doc page
|
|
1551
|
+
*/
|
|
1552
|
+
async updatePage(pageId, data) {
|
|
1553
|
+
return this.put(`/docs/pages/${pageId}`, data);
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* Publish a doc page
|
|
1557
|
+
*/
|
|
1558
|
+
async publishPage(pageId) {
|
|
1559
|
+
return this.post(`/docs/pages/${pageId}/publish`, {});
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Archive a doc page
|
|
1563
|
+
*/
|
|
1564
|
+
async archivePage(pageId) {
|
|
1565
|
+
return this.post(`/docs/pages/${pageId}/archive`, {});
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Delete a doc page
|
|
1569
|
+
*/
|
|
1570
|
+
async deletePage(pageId) {
|
|
1571
|
+
return this._delete(`/docs/pages/${pageId}`);
|
|
1572
|
+
}
|
|
1573
|
+
// ========== Tree ==========
|
|
1574
|
+
/**
|
|
1575
|
+
* Get the full documentation tree structure
|
|
1576
|
+
*/
|
|
1577
|
+
async getTree() {
|
|
1578
|
+
return this.get("/docs/tree");
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
|
|
1582
|
+
// src/client.ts
|
|
1583
|
+
var MantleCoreClient = class {
|
|
1584
|
+
constructor(config) {
|
|
1585
|
+
if (!config.apiKey && !config.accessToken) {
|
|
1586
|
+
throw new Error(
|
|
1587
|
+
"MantleCoreClient requires either apiKey or accessToken"
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
this.baseURL = config.baseURL || "https://api.heymantle.com/v1";
|
|
1591
|
+
this.apiKey = config.apiKey;
|
|
1592
|
+
this.accessToken = config.accessToken;
|
|
1593
|
+
this.timeout = config.timeout || 3e4;
|
|
1594
|
+
this.customers = new CustomersResource(this);
|
|
1595
|
+
this.contacts = new ContactsResource(this);
|
|
1596
|
+
this.subscriptions = new SubscriptionsResource(this);
|
|
1597
|
+
this.usageEvents = new UsageEventsResource(this);
|
|
1598
|
+
this.apps = new AppsResource(this);
|
|
1599
|
+
this.deals = new DealsResource(this);
|
|
1600
|
+
this.dealFlows = new DealFlowsResource(this);
|
|
1601
|
+
this.dealActivities = new DealActivitiesResource(this);
|
|
1602
|
+
this.tickets = new TicketsResource(this);
|
|
1603
|
+
this.channels = new ChannelsResource(this);
|
|
1604
|
+
this.flows = new FlowsResource(this);
|
|
1605
|
+
this.tasks = new TasksResource(this);
|
|
1606
|
+
this.webhooks = new WebhooksResource(this);
|
|
1607
|
+
this.companies = new CompaniesResource(this);
|
|
1608
|
+
this.customerSegments = new CustomerSegmentsResource(this);
|
|
1609
|
+
this.affiliates = new AffiliatesResource(this);
|
|
1610
|
+
this.affiliatePrograms = new AffiliateProgramsResource(this);
|
|
1611
|
+
this.affiliateCommissions = new AffiliateCommissionsResource(this);
|
|
1612
|
+
this.affiliatePayouts = new AffiliatePayoutsResource(this);
|
|
1613
|
+
this.affiliateReferrals = new AffiliateReferralsResource(this);
|
|
1614
|
+
this.charges = new ChargesResource(this);
|
|
1615
|
+
this.transactions = new TransactionsResource(this);
|
|
1616
|
+
this.metrics = new MetricsResource(this);
|
|
1617
|
+
this.users = new UsersResource(this);
|
|
1618
|
+
this.me = new MeResource(this);
|
|
1619
|
+
this.organization = new OrganizationResource(this);
|
|
1620
|
+
this.agents = new AgentsResource(this);
|
|
1621
|
+
this.docs = new DocsResource(this);
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Performs a GET request to the API
|
|
1625
|
+
*/
|
|
1626
|
+
async get(endpoint, params) {
|
|
1627
|
+
const sanitizedParams = params ? sanitizeObject(params) : {};
|
|
1628
|
+
const query = toQueryString(sanitizedParams);
|
|
1629
|
+
const url = query ? `${endpoint}?${query}` : endpoint;
|
|
1630
|
+
return this.makeRequest(url, { method: "GET" });
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Performs a POST request to the API
|
|
1634
|
+
*/
|
|
1635
|
+
async post(endpoint, data) {
|
|
1636
|
+
const sanitizedData = data ? sanitizeObject(data) : {};
|
|
1637
|
+
return this.makeRequest(endpoint, {
|
|
1638
|
+
method: "POST",
|
|
1639
|
+
body: JSON.stringify(sanitizedData)
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Performs a PUT request to the API
|
|
1644
|
+
*/
|
|
1645
|
+
async put(endpoint, data) {
|
|
1646
|
+
const sanitizedData = data ? sanitizeObject(data) : {};
|
|
1647
|
+
return this.makeRequest(endpoint, {
|
|
1648
|
+
method: "PUT",
|
|
1649
|
+
body: JSON.stringify(sanitizedData)
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Performs a DELETE request to the API
|
|
1654
|
+
*/
|
|
1655
|
+
async delete(endpoint) {
|
|
1656
|
+
return this.makeRequest(endpoint, { method: "DELETE" });
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Makes an HTTP request to the API
|
|
1660
|
+
*/
|
|
1661
|
+
async makeRequest(endpoint, options) {
|
|
1662
|
+
const authHeader = this.getAuthHeader();
|
|
1663
|
+
const controller = new AbortController();
|
|
1664
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
1665
|
+
try {
|
|
1666
|
+
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
1667
|
+
method: options.method,
|
|
1668
|
+
body: options.body,
|
|
1669
|
+
headers: {
|
|
1670
|
+
Authorization: authHeader,
|
|
1671
|
+
"Content-Type": "application/json",
|
|
1672
|
+
...options.headers
|
|
1673
|
+
},
|
|
1674
|
+
signal: controller.signal
|
|
1675
|
+
});
|
|
1676
|
+
clearTimeout(timeoutId);
|
|
1677
|
+
if (!response.ok) {
|
|
1678
|
+
await this.handleErrorResponse(response);
|
|
1679
|
+
}
|
|
1680
|
+
const text = await response.text();
|
|
1681
|
+
if (!text) {
|
|
1682
|
+
return {};
|
|
1683
|
+
}
|
|
1684
|
+
return JSON.parse(text);
|
|
1685
|
+
} catch (error) {
|
|
1686
|
+
clearTimeout(timeoutId);
|
|
1687
|
+
if (error instanceof MantleAPIError) {
|
|
1688
|
+
throw error;
|
|
1689
|
+
}
|
|
1690
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
1691
|
+
throw new MantleAPIError("Request timeout", 408);
|
|
1692
|
+
}
|
|
1693
|
+
throw new MantleAPIError(
|
|
1694
|
+
error instanceof Error ? error.message : "Unknown error occurred",
|
|
1695
|
+
500
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* Gets the authorization header value
|
|
1701
|
+
*/
|
|
1702
|
+
getAuthHeader() {
|
|
1703
|
+
if (this.accessToken) {
|
|
1704
|
+
return `Bearer ${this.accessToken}`;
|
|
1705
|
+
}
|
|
1706
|
+
if (this.apiKey) {
|
|
1707
|
+
return `Bearer ${this.apiKey}`;
|
|
1708
|
+
}
|
|
1709
|
+
throw new MantleAuthenticationError(
|
|
1710
|
+
"Authentication not configured. Please set up API key or OAuth."
|
|
1711
|
+
);
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Handles error responses from the API
|
|
1715
|
+
*/
|
|
1716
|
+
async handleErrorResponse(response) {
|
|
1717
|
+
let errorData = {};
|
|
1718
|
+
try {
|
|
1719
|
+
const text = await response.text();
|
|
1720
|
+
if (text) {
|
|
1721
|
+
errorData = JSON.parse(text);
|
|
1722
|
+
}
|
|
1723
|
+
} catch {
|
|
1724
|
+
}
|
|
1725
|
+
const message = errorData.error || `API request failed: ${response.status}`;
|
|
1726
|
+
switch (response.status) {
|
|
1727
|
+
case 401:
|
|
1728
|
+
throw new MantleAuthenticationError(message);
|
|
1729
|
+
case 403:
|
|
1730
|
+
throw new MantlePermissionError(message);
|
|
1731
|
+
case 404:
|
|
1732
|
+
throw new MantleAPIError(message, 404, errorData.details);
|
|
1733
|
+
case 422:
|
|
1734
|
+
throw new MantleValidationError(message, errorData.details);
|
|
1735
|
+
case 429: {
|
|
1736
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
1737
|
+
throw new MantleRateLimitError(
|
|
1738
|
+
message,
|
|
1739
|
+
retryAfter ? parseInt(retryAfter, 10) : void 0
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
default:
|
|
1743
|
+
throw new MantleAPIError(message, response.status, errorData.details);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
export {
|
|
1748
|
+
AffiliateCommissionsResource,
|
|
1749
|
+
AffiliatePayoutsResource,
|
|
1750
|
+
AffiliateProgramsResource,
|
|
1751
|
+
AffiliateReferralsResource,
|
|
1752
|
+
AffiliatesResource,
|
|
1753
|
+
AgentsResource,
|
|
1754
|
+
AppsResource,
|
|
1755
|
+
BaseResource,
|
|
1756
|
+
ChannelsResource,
|
|
1757
|
+
ChargesResource,
|
|
1758
|
+
CompaniesResource,
|
|
1759
|
+
ContactsResource,
|
|
1760
|
+
CustomerSegmentsResource,
|
|
1761
|
+
CustomersResource,
|
|
1762
|
+
DealActivitiesResource,
|
|
1763
|
+
DealFlowsResource,
|
|
1764
|
+
DealsResource,
|
|
1765
|
+
DocsResource,
|
|
1766
|
+
FlowsResource,
|
|
1767
|
+
MantleAPIError,
|
|
1768
|
+
MantleAuthenticationError,
|
|
1769
|
+
MantleCoreClient,
|
|
1770
|
+
MantleNotFoundError,
|
|
1771
|
+
MantlePermissionError,
|
|
1772
|
+
MantleRateLimitError,
|
|
1773
|
+
MantleValidationError,
|
|
1774
|
+
MeResource,
|
|
1775
|
+
MetricsResource,
|
|
1776
|
+
OrganizationResource,
|
|
1777
|
+
SubscriptionsResource,
|
|
1778
|
+
TasksResource,
|
|
1779
|
+
TicketsResource,
|
|
1780
|
+
TransactionsResource,
|
|
1781
|
+
UsageEventsResource,
|
|
1782
|
+
UsersResource,
|
|
1783
|
+
WebhooksResource
|
|
1784
|
+
};
|