@heymantle/core-api-client 0.1.26 → 0.2.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 +626 -87
- package/dist/index.d.mts +21950 -4644
- package/dist/index.d.ts +21950 -4644
- package/dist/index.js +519 -2216
- package/dist/index.mjs +501 -2215
- package/package.json +7 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -26,6 +36,7 @@ __export(index_exports, {
|
|
|
26
36
|
AffiliateReferralsResource: () => AffiliateReferralsResource,
|
|
27
37
|
AffiliatesResource: () => AffiliatesResource,
|
|
28
38
|
AgentsResource: () => AgentsResource,
|
|
39
|
+
AiAgentRunsResource: () => AiAgentRunsResource,
|
|
29
40
|
AppsResource: () => AppsResource,
|
|
30
41
|
BaseResource: () => BaseResource,
|
|
31
42
|
ChannelsResource: () => ChannelsResource,
|
|
@@ -39,8 +50,12 @@ __export(index_exports, {
|
|
|
39
50
|
DealFlowsResource: () => DealFlowsResource,
|
|
40
51
|
DealsResource: () => DealsResource,
|
|
41
52
|
DocsResource: () => DocsResource,
|
|
53
|
+
EmailUnsubscribeGroupsResource: () => EmailUnsubscribeGroupsResource,
|
|
42
54
|
EntitiesResource: () => EntitiesResource,
|
|
55
|
+
FlowExtensionsResource: () => FlowExtensionsResource,
|
|
43
56
|
FlowsResource: () => FlowsResource,
|
|
57
|
+
JournalEntriesResource: () => JournalEntriesResource,
|
|
58
|
+
ListsResource: () => ListsResource,
|
|
44
59
|
MantleAPIError: () => MantleAPIError,
|
|
45
60
|
MantleAuthenticationError: () => MantleAuthenticationError,
|
|
46
61
|
MantleCoreClient: () => MantleCoreClient,
|
|
@@ -49,12 +64,14 @@ __export(index_exports, {
|
|
|
49
64
|
MantleRateLimitError: () => MantleRateLimitError,
|
|
50
65
|
MantleValidationError: () => MantleValidationError,
|
|
51
66
|
MeResource: () => MeResource,
|
|
67
|
+
MeetingsResource: () => MeetingsResource,
|
|
52
68
|
MetricsResource: () => MetricsResource,
|
|
53
|
-
MiddlewareManager: () => MiddlewareManager,
|
|
54
69
|
OrganizationResource: () => OrganizationResource,
|
|
55
70
|
SubscriptionsResource: () => SubscriptionsResource,
|
|
71
|
+
SyncedEmailsResource: () => SyncedEmailsResource,
|
|
56
72
|
TasksResource: () => TasksResource,
|
|
57
73
|
TicketsResource: () => TicketsResource,
|
|
74
|
+
TimelineCommentsResource: () => TimelineCommentsResource,
|
|
58
75
|
TransactionsResource: () => TransactionsResource,
|
|
59
76
|
UsageEventsResource: () => UsageEventsResource,
|
|
60
77
|
UsersResource: () => UsersResource,
|
|
@@ -64,136 +81,8 @@ __export(index_exports, {
|
|
|
64
81
|
});
|
|
65
82
|
module.exports = __toCommonJS(index_exports);
|
|
66
83
|
|
|
67
|
-
// src/
|
|
68
|
-
var
|
|
69
|
-
constructor() {
|
|
70
|
-
this.middlewares = [];
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Register a middleware function
|
|
74
|
-
*
|
|
75
|
-
* @param middleware - The middleware function to register
|
|
76
|
-
* @param options - Optional configuration
|
|
77
|
-
* @returns this for chaining
|
|
78
|
-
*/
|
|
79
|
-
use(middleware, options = {}) {
|
|
80
|
-
const registered = {
|
|
81
|
-
fn: middleware,
|
|
82
|
-
name: options.name ?? `middleware_${Date.now()}_${Math.random().toString(36).slice(2)}`,
|
|
83
|
-
priority: options.priority ?? 100
|
|
84
|
-
};
|
|
85
|
-
this.middlewares.push(registered);
|
|
86
|
-
this.middlewares.sort((a, b) => a.priority - b.priority);
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Remove a middleware by name
|
|
91
|
-
*
|
|
92
|
-
* @param name - The name of the middleware to remove
|
|
93
|
-
* @returns true if removed, false if not found
|
|
94
|
-
*/
|
|
95
|
-
remove(name) {
|
|
96
|
-
const index = this.middlewares.findIndex((m) => m.name === name);
|
|
97
|
-
if (index !== -1) {
|
|
98
|
-
this.middlewares.splice(index, 1);
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get all registered middleware names
|
|
105
|
-
*/
|
|
106
|
-
list() {
|
|
107
|
-
return this.middlewares.map((m) => m.name);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Check if any middleware is registered
|
|
111
|
-
*/
|
|
112
|
-
hasMiddleware() {
|
|
113
|
-
return this.middlewares.length > 0;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Execute the middleware chain with retry support
|
|
117
|
-
*
|
|
118
|
-
* @param ctx - The middleware context
|
|
119
|
-
* @param coreHandler - The core request handler to call at the end of the chain
|
|
120
|
-
* @returns The response from the core handler
|
|
121
|
-
*/
|
|
122
|
-
async execute(ctx, coreHandler) {
|
|
123
|
-
const maxAttempts = ctx.maxRetries + 1;
|
|
124
|
-
let attempts = 0;
|
|
125
|
-
while (attempts < maxAttempts) {
|
|
126
|
-
ctx.retryCount = attempts;
|
|
127
|
-
ctx.retry = false;
|
|
128
|
-
ctx.error = void 0;
|
|
129
|
-
try {
|
|
130
|
-
await this.runChain(ctx, coreHandler);
|
|
131
|
-
if (!ctx.retry) {
|
|
132
|
-
return ctx.response;
|
|
133
|
-
}
|
|
134
|
-
attempts++;
|
|
135
|
-
} catch (error) {
|
|
136
|
-
if (!ctx.retry || attempts >= maxAttempts - 1) {
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
attempts++;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
throw ctx.error ?? new Error("Max retries exceeded");
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Run the middleware chain (onion model)
|
|
146
|
-
*/
|
|
147
|
-
async runChain(ctx, coreHandler) {
|
|
148
|
-
let index = -1;
|
|
149
|
-
const dispatch = async (i) => {
|
|
150
|
-
if (i <= index) {
|
|
151
|
-
throw new Error("next() called multiple times");
|
|
152
|
-
}
|
|
153
|
-
index = i;
|
|
154
|
-
if (i < this.middlewares.length) {
|
|
155
|
-
const middleware = this.middlewares[i];
|
|
156
|
-
await middleware.fn(ctx, () => dispatch(i + 1));
|
|
157
|
-
} else {
|
|
158
|
-
try {
|
|
159
|
-
ctx.response = await coreHandler();
|
|
160
|
-
} catch (error) {
|
|
161
|
-
ctx.error = error;
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
await dispatch(0);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
// src/utils/sanitize.ts
|
|
171
|
-
function sanitizeObject(obj) {
|
|
172
|
-
if (!obj || typeof obj !== "object") {
|
|
173
|
-
return obj;
|
|
174
|
-
}
|
|
175
|
-
const sanitized = {};
|
|
176
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
177
|
-
if (value !== void 0) {
|
|
178
|
-
sanitized[key] = value;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return sanitized;
|
|
182
|
-
}
|
|
183
|
-
function toQueryString(params) {
|
|
184
|
-
const sanitized = sanitizeObject(params);
|
|
185
|
-
const searchParams = new URLSearchParams();
|
|
186
|
-
for (const [key, value] of Object.entries(sanitized)) {
|
|
187
|
-
if (Array.isArray(value)) {
|
|
188
|
-
if (value.length > 0) {
|
|
189
|
-
searchParams.append(key, value.map(String).join(","));
|
|
190
|
-
}
|
|
191
|
-
} else if (value !== null && value !== void 0) {
|
|
192
|
-
searchParams.append(key, String(value));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return searchParams.toString();
|
|
196
|
-
}
|
|
84
|
+
// src/client.ts
|
|
85
|
+
var import_openapi_fetch = __toESM(require("openapi-fetch"));
|
|
197
86
|
|
|
198
87
|
// src/utils/errors.ts
|
|
199
88
|
var MantleAPIError = class _MantleAPIError extends Error {
|
|
@@ -250,218 +139,124 @@ var BaseResource = class {
|
|
|
250
139
|
constructor(client) {
|
|
251
140
|
this.client = client;
|
|
252
141
|
}
|
|
253
|
-
get(
|
|
254
|
-
return this.client.
|
|
142
|
+
get api() {
|
|
143
|
+
return this.client._api;
|
|
255
144
|
}
|
|
256
|
-
|
|
257
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Access the API client without path type-checking.
|
|
147
|
+
* Used for endpoints not yet in the OpenAPI spec.
|
|
148
|
+
*/
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
+
get untypedApi() {
|
|
151
|
+
return this.client._api;
|
|
258
152
|
}
|
|
259
|
-
|
|
260
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Unwraps an openapi-fetch response, throwing typed errors on failure.
|
|
155
|
+
*/
|
|
156
|
+
async unwrap(promise) {
|
|
157
|
+
const { data, error, response } = await promise;
|
|
158
|
+
if (error !== void 0) {
|
|
159
|
+
throw this.createError(response, error);
|
|
160
|
+
}
|
|
161
|
+
return data;
|
|
261
162
|
}
|
|
262
|
-
|
|
263
|
-
|
|
163
|
+
createError(response, error) {
|
|
164
|
+
const err = error;
|
|
165
|
+
const message = (typeof err?.error === "string" ? err.error : null) || `API request failed: ${response.status}`;
|
|
166
|
+
const details = typeof err?.details === "string" ? err.details : void 0;
|
|
167
|
+
switch (response.status) {
|
|
168
|
+
case 401:
|
|
169
|
+
return new MantleAuthenticationError(message);
|
|
170
|
+
case 403:
|
|
171
|
+
return new MantlePermissionError(message);
|
|
172
|
+
case 404:
|
|
173
|
+
return new MantleAPIError(message, 404, details);
|
|
174
|
+
case 422:
|
|
175
|
+
return new MantleValidationError(message, details);
|
|
176
|
+
case 429: {
|
|
177
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
178
|
+
return new MantleRateLimitError(
|
|
179
|
+
message,
|
|
180
|
+
retryAfter ? parseInt(retryAfter, 10) : void 0
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
default:
|
|
184
|
+
return new MantleAPIError(message, response.status, details);
|
|
185
|
+
}
|
|
264
186
|
}
|
|
265
187
|
};
|
|
266
188
|
|
|
267
189
|
// src/resources/customers.ts
|
|
268
190
|
var CustomersResource = class extends BaseResource {
|
|
269
|
-
/**
|
|
270
|
-
* List customers with optional filters and pagination
|
|
271
|
-
*/
|
|
272
191
|
async list(params) {
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
customers: response.customers || [],
|
|
276
|
-
hasNextPage: response.hasNextPage || false,
|
|
277
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
278
|
-
total: response.total,
|
|
279
|
-
cursor: response.cursor
|
|
280
|
-
};
|
|
192
|
+
return this.unwrap(this.api.GET("/customers", { params: { query: params } }));
|
|
281
193
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
*/
|
|
285
|
-
async retrieve(customerId, params) {
|
|
286
|
-
return this.get(
|
|
287
|
-
`/customers/${customerId}`,
|
|
288
|
-
params
|
|
289
|
-
);
|
|
194
|
+
async get(customerId) {
|
|
195
|
+
return this.unwrap(this.api.GET("/customers/{id}", { params: { path: { id: customerId } } }));
|
|
290
196
|
}
|
|
291
|
-
/**
|
|
292
|
-
* Create a new customer
|
|
293
|
-
*/
|
|
294
197
|
async create(data) {
|
|
295
|
-
return this.
|
|
198
|
+
return this.unwrap(this.api.POST("/customers", { body: data }));
|
|
296
199
|
}
|
|
297
|
-
/**
|
|
298
|
-
* Update an existing customer
|
|
299
|
-
*/
|
|
300
200
|
async update(customerId, data) {
|
|
301
|
-
return this.
|
|
302
|
-
`/customers/${customerId}`,
|
|
303
|
-
data
|
|
304
|
-
);
|
|
201
|
+
return this.unwrap(this.api.PUT("/customers/{id}", { params: { path: { id: customerId } }, body: data }));
|
|
305
202
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Add tags to a customer
|
|
308
|
-
*/
|
|
309
203
|
async addTags(customerId, tags) {
|
|
310
|
-
return this.
|
|
311
|
-
`/customers/${customerId}/addTags`,
|
|
312
|
-
{ tags }
|
|
313
|
-
);
|
|
204
|
+
return this.unwrap(this.api.POST("/customers/{id}/addTags", { params: { path: { id: customerId } }, body: { tags } }));
|
|
314
205
|
}
|
|
315
|
-
/**
|
|
316
|
-
* Remove tags from a customer
|
|
317
|
-
*/
|
|
318
206
|
async removeTags(customerId, tags) {
|
|
319
|
-
return this.
|
|
320
|
-
`/customers/${customerId}/removeTags`,
|
|
321
|
-
{ tags }
|
|
322
|
-
);
|
|
207
|
+
return this.unwrap(this.api.POST("/customers/{id}/removeTags", { params: { path: { id: customerId } }, body: { tags } }));
|
|
323
208
|
}
|
|
324
|
-
/**
|
|
325
|
-
* Get customer activity timeline
|
|
326
|
-
*/
|
|
327
209
|
async getTimeline(customerId, params) {
|
|
328
|
-
|
|
329
|
-
`/customers/${customerId}/timeline`,
|
|
330
|
-
{ limit: 25, ...params }
|
|
331
|
-
);
|
|
332
|
-
return {
|
|
333
|
-
events: response.events || [],
|
|
334
|
-
hasNextPage: response.hasNextPage || false,
|
|
335
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
336
|
-
cursor: response.cursor
|
|
337
|
-
};
|
|
210
|
+
return this.unwrap(this.api.GET("/customers/{id}/timeline", { params: { path: { id: customerId }, query: params } }));
|
|
338
211
|
}
|
|
339
|
-
/**
|
|
340
|
-
* List account owners for a customer
|
|
341
|
-
*/
|
|
342
212
|
async listAccountOwners(customerId) {
|
|
343
|
-
return this.
|
|
344
|
-
`/customers/${customerId}/account_owners`
|
|
345
|
-
);
|
|
213
|
+
return this.unwrap(this.api.GET("/customers/{id}/account_owners", { params: { path: { id: customerId } } }));
|
|
346
214
|
}
|
|
347
|
-
/**
|
|
348
|
-
* Add an account owner to a customer
|
|
349
|
-
*/
|
|
350
215
|
async addAccountOwner(customerId, data) {
|
|
351
|
-
return this.
|
|
216
|
+
return this.unwrap(this.api.POST("/customers/{id}/account_owners", { params: { path: { id: customerId } }, body: data }));
|
|
352
217
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Remove an account owner from a customer
|
|
355
|
-
*/
|
|
356
218
|
async removeAccountOwner(customerId, ownerId) {
|
|
357
|
-
return this.
|
|
358
|
-
`/customers/${customerId}/account_owners/${ownerId}`
|
|
359
|
-
);
|
|
219
|
+
return this.unwrap(this.api.DELETE("/customers/{id}/account_owners/{ownerId}", { params: { path: { id: customerId, ownerId } } }));
|
|
360
220
|
}
|
|
361
|
-
/**
|
|
362
|
-
* List custom fields
|
|
363
|
-
*/
|
|
364
221
|
async listCustomFields(params) {
|
|
365
|
-
return this.
|
|
366
|
-
"/customers/custom_fields",
|
|
367
|
-
params
|
|
368
|
-
);
|
|
222
|
+
return this.unwrap(this.api.GET("/customers/custom_fields", { params: { query: params } }));
|
|
369
223
|
}
|
|
370
|
-
/**
|
|
371
|
-
* Create a custom field
|
|
372
|
-
*/
|
|
373
224
|
async createCustomField(data) {
|
|
374
|
-
return this.
|
|
375
|
-
"/customers/custom_fields",
|
|
376
|
-
data
|
|
377
|
-
);
|
|
225
|
+
return this.unwrap(this.api.POST("/customers/custom_fields", { body: data }));
|
|
378
226
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
*/
|
|
382
|
-
async retrieveCustomField(fieldId) {
|
|
383
|
-
return this.get(
|
|
384
|
-
`/customers/custom_fields/${fieldId}`
|
|
385
|
-
);
|
|
227
|
+
async getCustomField(fieldId) {
|
|
228
|
+
return this.unwrap(this.api.GET("/customers/custom_fields/{id}", { params: { path: { id: fieldId } } }));
|
|
386
229
|
}
|
|
387
|
-
/**
|
|
388
|
-
* Update a custom field
|
|
389
|
-
*/
|
|
390
230
|
async updateCustomField(fieldId, data) {
|
|
391
|
-
return this.
|
|
392
|
-
`/customers/custom_fields/${fieldId}`,
|
|
393
|
-
data
|
|
394
|
-
);
|
|
231
|
+
return this.unwrap(this.api.PUT("/customers/custom_fields/{id}", { params: { path: { id: fieldId } }, body: data }));
|
|
395
232
|
}
|
|
396
|
-
/**
|
|
397
|
-
* Delete a custom field
|
|
398
|
-
*/
|
|
399
233
|
async deleteCustomField(fieldId) {
|
|
400
|
-
return this.
|
|
401
|
-
`/customers/custom_fields/${fieldId}`
|
|
402
|
-
);
|
|
234
|
+
return this.unwrap(this.api.DELETE("/customers/custom_fields/{id}", { params: { path: { id: fieldId } } }));
|
|
403
235
|
}
|
|
404
236
|
};
|
|
405
237
|
|
|
406
238
|
// src/resources/contacts.ts
|
|
407
239
|
var ContactsResource = class extends BaseResource {
|
|
408
|
-
/**
|
|
409
|
-
* List contacts with optional filters and pagination
|
|
410
|
-
*/
|
|
411
240
|
async list(params) {
|
|
412
|
-
|
|
413
|
-
return {
|
|
414
|
-
contacts: response.contacts || [],
|
|
415
|
-
hasNextPage: response.hasNextPage || false,
|
|
416
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
417
|
-
total: response.total,
|
|
418
|
-
cursor: response.cursor
|
|
419
|
-
};
|
|
241
|
+
return this.unwrap(this.api.GET("/contacts", { params: { query: params } }));
|
|
420
242
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
*/
|
|
424
|
-
async retrieve(contactId) {
|
|
425
|
-
return this.get(`/contacts/${contactId}`);
|
|
243
|
+
async get(contactId) {
|
|
244
|
+
return this.unwrap(this.api.GET("/contacts/{id}", { params: { path: { id: contactId } } }));
|
|
426
245
|
}
|
|
427
|
-
/**
|
|
428
|
-
* Create or update a contact.
|
|
429
|
-
* If a contact with the same email exists in the organization, it will be updated.
|
|
430
|
-
* Otherwise, a new contact will be created.
|
|
431
|
-
* @returns The contact and a boolean indicating if it was newly created
|
|
432
|
-
*/
|
|
433
246
|
async create(data) {
|
|
434
|
-
return this.
|
|
247
|
+
return this.unwrap(this.api.POST("/contacts", { body: data }));
|
|
435
248
|
}
|
|
436
|
-
/**
|
|
437
|
-
* Update an existing contact
|
|
438
|
-
*/
|
|
439
249
|
async update(contactId, data) {
|
|
440
|
-
return this.
|
|
250
|
+
return this.unwrap(this.api.PUT("/contacts/{id}", { params: { path: { id: contactId } }, body: data }));
|
|
441
251
|
}
|
|
442
|
-
/**
|
|
443
|
-
* Delete a contact
|
|
444
|
-
*/
|
|
445
252
|
async del(contactId) {
|
|
446
|
-
return this.
|
|
253
|
+
return this.unwrap(this.api.DELETE("/contacts/{id}", { params: { path: { id: contactId } } }));
|
|
447
254
|
}
|
|
448
|
-
/**
|
|
449
|
-
* Add tags to a contact
|
|
450
|
-
*/
|
|
451
255
|
async addTags(contactId, tags) {
|
|
452
|
-
return this.
|
|
453
|
-
`/contacts/${contactId}/addTags`,
|
|
454
|
-
{ tags }
|
|
455
|
-
);
|
|
256
|
+
return this.unwrap(this.api.POST("/contacts/{id}/addTags", { params: { path: { id: contactId } }, body: { tags } }));
|
|
456
257
|
}
|
|
457
|
-
/**
|
|
458
|
-
* Remove tags from a contact
|
|
459
|
-
*/
|
|
460
258
|
async removeTags(contactId, tags) {
|
|
461
|
-
return this.
|
|
462
|
-
`/contacts/${contactId}/removeTags`,
|
|
463
|
-
{ tags }
|
|
464
|
-
);
|
|
259
|
+
return this.unwrap(this.api.POST("/contacts/{id}/removeTags", { params: { path: { id: contactId } }, body: { tags } }));
|
|
465
260
|
}
|
|
466
261
|
};
|
|
467
262
|
|
|
@@ -471,25 +266,13 @@ var SubscriptionsResource = class extends BaseResource {
|
|
|
471
266
|
* List subscriptions with optional filters and pagination
|
|
472
267
|
*/
|
|
473
268
|
async list(params) {
|
|
474
|
-
|
|
475
|
-
"/subscriptions",
|
|
476
|
-
params
|
|
477
|
-
);
|
|
478
|
-
return {
|
|
479
|
-
subscriptions: response.subscriptions || [],
|
|
480
|
-
hasNextPage: response.hasNextPage || false,
|
|
481
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
482
|
-
total: response.total,
|
|
483
|
-
cursor: response.cursor
|
|
484
|
-
};
|
|
269
|
+
return this.unwrap(this.api.GET("/subscriptions", { params: { query: params } }));
|
|
485
270
|
}
|
|
486
271
|
/**
|
|
487
|
-
*
|
|
272
|
+
* Get a single subscription by ID
|
|
488
273
|
*/
|
|
489
|
-
async
|
|
490
|
-
return this.
|
|
491
|
-
`/subscriptions/${subscriptionId}`
|
|
492
|
-
);
|
|
274
|
+
async get(subscriptionId) {
|
|
275
|
+
return this.unwrap(this.api.GET("/subscriptions/{id}", { params: { path: { id: subscriptionId } } }));
|
|
493
276
|
}
|
|
494
277
|
};
|
|
495
278
|
|
|
@@ -499,18 +282,7 @@ var UsageEventsResource = class extends BaseResource {
|
|
|
499
282
|
* List usage events with optional filters and pagination
|
|
500
283
|
*/
|
|
501
284
|
async list(params) {
|
|
502
|
-
|
|
503
|
-
"/usage_events",
|
|
504
|
-
params
|
|
505
|
-
);
|
|
506
|
-
return {
|
|
507
|
-
usageEvents: response.usageEvents || response.events || [],
|
|
508
|
-
events: response.events,
|
|
509
|
-
hasNextPage: response.hasNextPage || false,
|
|
510
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
511
|
-
total: response.total,
|
|
512
|
-
cursor: response.cursor
|
|
513
|
-
};
|
|
285
|
+
return this.unwrap(this.api.GET("/usage_events", { params: { query: params } }));
|
|
514
286
|
}
|
|
515
287
|
/**
|
|
516
288
|
* Create usage event(s)
|
|
@@ -534,549 +306,212 @@ var UsageEventsResource = class extends BaseResource {
|
|
|
534
306
|
* });
|
|
535
307
|
*/
|
|
536
308
|
async create(data) {
|
|
537
|
-
return this.
|
|
309
|
+
return this.unwrap(this.api.POST("/usage_events", { body: data }));
|
|
538
310
|
}
|
|
539
311
|
};
|
|
540
312
|
|
|
541
313
|
// src/resources/apps.ts
|
|
542
314
|
var AppsResource = class extends BaseResource {
|
|
543
|
-
|
|
544
|
-
* List all apps
|
|
545
|
-
*/
|
|
315
|
+
// Apps
|
|
546
316
|
async list(params) {
|
|
547
|
-
return this.
|
|
317
|
+
return this.unwrap(this.api.GET("/apps", { params: { query: params } }));
|
|
548
318
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
*/
|
|
552
|
-
async retrieve(appId) {
|
|
553
|
-
return this.get(`/apps/${appId}`);
|
|
319
|
+
async get(appId) {
|
|
320
|
+
return this.unwrap(this.api.GET("/apps/{id}", { params: { path: { id: appId } } }));
|
|
554
321
|
}
|
|
555
|
-
//
|
|
556
|
-
/**
|
|
557
|
-
* List plans for an app
|
|
558
|
-
*/
|
|
322
|
+
// Plans
|
|
559
323
|
async listPlans(appId, params) {
|
|
560
|
-
return this.
|
|
324
|
+
return this.unwrap(this.api.GET("/apps/{id}/plans", { params: { path: { id: appId }, query: params } }));
|
|
561
325
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
*/
|
|
565
|
-
async retrievePlan(appId, planId) {
|
|
566
|
-
return this.get(`/apps/${appId}/plans/${planId}`);
|
|
326
|
+
async getPlan(appId, planId) {
|
|
327
|
+
return this.unwrap(this.api.GET("/apps/{id}/plans/{planId}", { params: { path: { id: appId, planId } } }));
|
|
567
328
|
}
|
|
568
|
-
/**
|
|
569
|
-
* Create a new plan for an app
|
|
570
|
-
*/
|
|
571
329
|
async createPlan(appId, data) {
|
|
572
|
-
return this.
|
|
330
|
+
return this.unwrap(this.api.POST("/apps/{id}/plans", { params: { path: { id: appId } }, body: data }));
|
|
573
331
|
}
|
|
574
|
-
/**
|
|
575
|
-
* Update an existing plan
|
|
576
|
-
*/
|
|
577
332
|
async updatePlan(appId, planId, data) {
|
|
578
|
-
return this.
|
|
333
|
+
return this.unwrap(this.api.PUT("/apps/{id}/plans/{planId}", { params: { path: { id: appId, planId } }, body: data }));
|
|
579
334
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Archive a plan
|
|
582
|
-
*/
|
|
583
335
|
async archivePlan(appId, planId) {
|
|
584
|
-
return this.
|
|
585
|
-
`/apps/${appId}/plans/${planId}/archive`,
|
|
586
|
-
{}
|
|
587
|
-
);
|
|
336
|
+
return this.unwrap(this.api.PUT("/apps/{id}/plans/{planId}/archive", { params: { path: { id: appId, planId } } }));
|
|
588
337
|
}
|
|
589
|
-
/**
|
|
590
|
-
* Unarchive a plan
|
|
591
|
-
*/
|
|
592
338
|
async unarchivePlan(appId, planId) {
|
|
593
|
-
return this.
|
|
594
|
-
`/apps/${appId}/plans/${planId}/unarchive`,
|
|
595
|
-
{}
|
|
596
|
-
);
|
|
339
|
+
return this.unwrap(this.api.PUT("/apps/{id}/plans/{planId}/unarchive", { params: { path: { id: appId, planId } } }));
|
|
597
340
|
}
|
|
598
|
-
//
|
|
599
|
-
/**
|
|
600
|
-
* List features for an app
|
|
601
|
-
*/
|
|
341
|
+
// Features
|
|
602
342
|
async listFeatures(appId) {
|
|
603
|
-
return this.
|
|
343
|
+
return this.unwrap(this.api.GET("/apps/{appId}/plans/features", { params: { path: { appId } } }));
|
|
604
344
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
*/
|
|
608
|
-
async retrieveFeature(appId, featureId) {
|
|
609
|
-
return this.get(
|
|
610
|
-
`/apps/${appId}/plans/features/${featureId}`
|
|
611
|
-
);
|
|
345
|
+
async getFeature(appId, featureId) {
|
|
346
|
+
return this.unwrap(this.api.GET("/apps/{appId}/plans/features/{featureId}", { params: { path: { appId, featureId } } }));
|
|
612
347
|
}
|
|
613
|
-
/**
|
|
614
|
-
* Create a new feature for an app
|
|
615
|
-
*/
|
|
616
348
|
async createFeature(appId, data) {
|
|
617
|
-
return this.
|
|
618
|
-
`/apps/${appId}/plans/features`,
|
|
619
|
-
data
|
|
620
|
-
);
|
|
349
|
+
return this.unwrap(this.api.POST("/apps/{appId}/plans/features", { params: { path: { appId } }, body: data }));
|
|
621
350
|
}
|
|
622
|
-
/**
|
|
623
|
-
* Update an existing feature
|
|
624
|
-
*/
|
|
625
351
|
async updateFeature(appId, featureId, data) {
|
|
626
|
-
return this.
|
|
627
|
-
`/apps/${appId}/plans/features/${featureId}`,
|
|
628
|
-
data
|
|
629
|
-
);
|
|
352
|
+
return this.unwrap(this.api.PUT("/apps/{appId}/plans/features/{featureId}", { params: { path: { appId, featureId } }, body: data }));
|
|
630
353
|
}
|
|
631
|
-
/**
|
|
632
|
-
* Delete a feature
|
|
633
|
-
*/
|
|
634
354
|
async deleteFeature(appId, featureId) {
|
|
635
|
-
return this.
|
|
636
|
-
`/apps/${appId}/plans/features/${featureId}`
|
|
637
|
-
);
|
|
355
|
+
return this.unwrap(this.api.DELETE("/apps/{appId}/plans/features/{featureId}", { params: { path: { appId, featureId } } }));
|
|
638
356
|
}
|
|
639
|
-
//
|
|
640
|
-
/**
|
|
641
|
-
* List reviews for an app
|
|
642
|
-
*/
|
|
357
|
+
// Reviews
|
|
643
358
|
async listReviews(appId) {
|
|
644
|
-
return this.
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Retrieve a single review
|
|
648
|
-
*/
|
|
649
|
-
async retrieveReview(appId, reviewId) {
|
|
650
|
-
return this.get(`/apps/${appId}/reviews/${reviewId}`);
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Create a new review for an app
|
|
654
|
-
*/
|
|
655
|
-
async createReview(appId, data) {
|
|
656
|
-
return this.post(`/apps/${appId}/reviews`, data);
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* Update an existing review
|
|
660
|
-
*/
|
|
661
|
-
async updateReview(appId, reviewId, data) {
|
|
662
|
-
return this.put(
|
|
663
|
-
`/apps/${appId}/reviews/${reviewId}`,
|
|
664
|
-
data
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Delete a review
|
|
669
|
-
*/
|
|
670
|
-
async deleteReview(appId, reviewId) {
|
|
671
|
-
return this._delete(`/apps/${appId}/reviews/${reviewId}`);
|
|
359
|
+
return this.unwrap(this.api.GET("/apps/{id}/reviews", { params: { path: { id: appId } } }));
|
|
672
360
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
* Get usage event names for an app
|
|
676
|
-
*/
|
|
677
|
-
async listEventNames(appId) {
|
|
678
|
-
return this.get(
|
|
679
|
-
`/apps/${appId}/usage_events/event_names`
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Get property keys for a specific event name
|
|
684
|
-
*/
|
|
685
|
-
async listPropertyKeys(appId, eventName) {
|
|
686
|
-
return this.get(
|
|
687
|
-
`/apps/${appId}/usage_events/property_keys`,
|
|
688
|
-
{ eventName }
|
|
689
|
-
);
|
|
361
|
+
async getReview(appId, reviewId) {
|
|
362
|
+
return this.unwrap(this.api.GET("/apps/{id}/reviews/{reviewId}", { params: { path: { id: appId, reviewId } } }));
|
|
690
363
|
}
|
|
691
|
-
//
|
|
692
|
-
/**
|
|
693
|
-
* List usage metrics for an app
|
|
694
|
-
*/
|
|
364
|
+
// Usage Metrics
|
|
695
365
|
async listUsageMetrics(appId) {
|
|
696
|
-
return this.
|
|
697
|
-
`/apps/${appId}/usage_metrics`
|
|
698
|
-
);
|
|
366
|
+
return this.unwrap(this.api.GET("/apps/{id}/usage_metrics", { params: { path: { id: appId } } }));
|
|
699
367
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
*/
|
|
703
|
-
async retrieveUsageMetric(appId, usageMetricId) {
|
|
704
|
-
return this.get(
|
|
705
|
-
`/apps/${appId}/usage_metrics/${usageMetricId}`
|
|
706
|
-
);
|
|
368
|
+
async getUsageMetric(appId, usageMetricId) {
|
|
369
|
+
return this.unwrap(this.api.GET("/apps/{id}/usage_metrics/{usageMetricId}", { params: { path: { id: appId, usageMetricId } } }));
|
|
707
370
|
}
|
|
708
|
-
/**
|
|
709
|
-
* Create a new usage metric for an app
|
|
710
|
-
*/
|
|
711
371
|
async createUsageMetric(appId, data) {
|
|
712
|
-
return this.
|
|
713
|
-
`/apps/${appId}/usage_metrics`,
|
|
714
|
-
data
|
|
715
|
-
);
|
|
372
|
+
return this.unwrap(this.api.POST("/apps/{id}/usage_metrics", { params: { path: { id: appId } }, body: data }));
|
|
716
373
|
}
|
|
717
|
-
/**
|
|
718
|
-
* Update an existing usage metric
|
|
719
|
-
*/
|
|
720
374
|
async updateUsageMetric(appId, usageMetricId, data) {
|
|
721
|
-
return this.
|
|
722
|
-
`/apps/${appId}/usage_metrics/${usageMetricId}`,
|
|
723
|
-
data
|
|
724
|
-
);
|
|
375
|
+
return this.unwrap(this.api.PUT("/apps/{id}/usage_metrics/{usageMetricId}", { params: { path: { id: appId, usageMetricId } }, body: data }));
|
|
725
376
|
}
|
|
726
|
-
/**
|
|
727
|
-
* Delete a usage metric
|
|
728
|
-
*/
|
|
729
377
|
async deleteUsageMetric(appId, usageMetricId) {
|
|
730
|
-
return this.
|
|
731
|
-
`/apps/${appId}/usage_metrics/${usageMetricId}`
|
|
732
|
-
);
|
|
378
|
+
return this.unwrap(this.api.DELETE("/apps/{id}/usage_metrics/{usageMetricId}", { params: { path: { id: appId, usageMetricId } } }));
|
|
733
379
|
}
|
|
734
|
-
//
|
|
735
|
-
/**
|
|
736
|
-
* List app events
|
|
737
|
-
*/
|
|
380
|
+
// App Events
|
|
738
381
|
async listAppEvents(appId, params) {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
);
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
747
|
-
total: response.total,
|
|
748
|
-
cursor: response.cursor
|
|
749
|
-
};
|
|
382
|
+
return this.unwrap(this.api.GET("/apps/{id}/app_events", { params: { path: { id: appId }, query: params } }));
|
|
383
|
+
}
|
|
384
|
+
async getAppEvent(appId, appEventId) {
|
|
385
|
+
return this.unwrap(this.api.GET("/apps/{id}/app_events/{appEventId}", { params: { path: { id: appId, appEventId } } }));
|
|
386
|
+
}
|
|
387
|
+
async createAppEvent(appId, data) {
|
|
388
|
+
return this.unwrap(this.api.POST("/apps/{id}/app_events", { params: { path: { id: appId } }, body: data }));
|
|
750
389
|
}
|
|
751
390
|
};
|
|
752
391
|
|
|
753
392
|
// src/resources/deals.ts
|
|
754
393
|
var DealsResource = class extends BaseResource {
|
|
755
|
-
/**
|
|
756
|
-
* List deals with optional filters and pagination
|
|
757
|
-
*/
|
|
758
394
|
async list(params) {
|
|
759
|
-
|
|
760
|
-
return {
|
|
761
|
-
deals: response.deals || [],
|
|
762
|
-
hasNextPage: response.hasNextPage || false,
|
|
763
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
764
|
-
total: response.total,
|
|
765
|
-
cursor: response.cursor
|
|
766
|
-
};
|
|
395
|
+
return this.unwrap(this.api.GET("/deals", { params: { query: params } }));
|
|
767
396
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
*/
|
|
771
|
-
async retrieve(dealId) {
|
|
772
|
-
return this.get(`/deals/${dealId}`);
|
|
397
|
+
async get(dealId) {
|
|
398
|
+
return this.unwrap(this.api.GET("/deals/{id}", { params: { path: { id: dealId } } }));
|
|
773
399
|
}
|
|
774
|
-
/**
|
|
775
|
-
* Create a new deal
|
|
776
|
-
*
|
|
777
|
-
* **Linking a Customer:**
|
|
778
|
-
* There are three ways to associate a customer with a deal (use only one):
|
|
779
|
-
*
|
|
780
|
-
* 1. `customerId` - Link to an existing customer by ID
|
|
781
|
-
* 2. `customer` - Create or update a customer inline. Matches existing customers
|
|
782
|
-
* by `domain` or `shopifyDomain`. If no match, creates a new customer.
|
|
783
|
-
* 3. `domain` and/or `shopifyDomain` - Find an existing customer by domain,
|
|
784
|
-
* or create a minimal customer record if not found.
|
|
785
|
-
*
|
|
786
|
-
* If `domain` or `shopifyDomain` are provided alongside `customerId` or `customer`,
|
|
787
|
-
* they will be used to update the customer's domain fields only if not already set.
|
|
788
|
-
*
|
|
789
|
-
* **Linking Contacts:**
|
|
790
|
-
* There are two ways to associate contacts with a deal (use only one):
|
|
791
|
-
*
|
|
792
|
-
* 1. `contactIds` - Link to existing contacts by their IDs
|
|
793
|
-
* 2. `contacts` - Create or update contacts inline. Matches existing contacts
|
|
794
|
-
* by email. Contacts are automatically linked to both the customer and the deal.
|
|
795
|
-
*
|
|
796
|
-
* @example
|
|
797
|
-
* // Using an existing customer
|
|
798
|
-
* await client.deals.create({ name: 'Deal', customerId: 'cust_123', dealFlowId: '...', dealStageId: '...' });
|
|
799
|
-
*
|
|
800
|
-
* // Creating a customer inline
|
|
801
|
-
* await client.deals.create({
|
|
802
|
-
* name: 'Deal',
|
|
803
|
-
* customer: { name: 'Acme Corp', domain: 'acme.com', email: 'info@acme.com' },
|
|
804
|
-
* contacts: [{ email: 'john@acme.com', name: 'John Doe', jobTitle: 'CEO' }],
|
|
805
|
-
* dealFlowId: '...',
|
|
806
|
-
* dealStageId: '...',
|
|
807
|
-
* });
|
|
808
|
-
*
|
|
809
|
-
* // Using domain to find/create customer
|
|
810
|
-
* await client.deals.create({ name: 'Deal', shopifyDomain: 'acme.myshopify.com', dealFlowId: '...', dealStageId: '...' });
|
|
811
|
-
*/
|
|
812
400
|
async create(data) {
|
|
813
|
-
return this.
|
|
401
|
+
return this.unwrap(this.api.POST("/deals", { body: data }));
|
|
814
402
|
}
|
|
815
|
-
/**
|
|
816
|
-
* Update an existing deal
|
|
817
|
-
*
|
|
818
|
-
* **Updating Customer Association:**
|
|
819
|
-
* There are three ways to change or update the customer (use only one):
|
|
820
|
-
*
|
|
821
|
-
* 1. `customerId` - Change to a different existing customer
|
|
822
|
-
* 2. `customer` - Update the linked customer inline, or create/link a new one.
|
|
823
|
-
* Matches existing customers by `domain` or `shopifyDomain`.
|
|
824
|
-
* 3. `domain` and/or `shopifyDomain` - Find a different customer by domain,
|
|
825
|
-
* or create a minimal customer record if not found.
|
|
826
|
-
*
|
|
827
|
-
* If `domain` or `shopifyDomain` are provided alongside `customerId` or `customer`,
|
|
828
|
-
* they will be used to update the customer's domain fields only if not already set.
|
|
829
|
-
*
|
|
830
|
-
* **Updating Contacts:**
|
|
831
|
-
* There are two ways to update contacts (use only one):
|
|
832
|
-
*
|
|
833
|
-
* 1. `contactIds` - Replace deal contacts with the specified contact IDs
|
|
834
|
-
* 2. `contacts` - Create or update contacts inline. Matches existing contacts
|
|
835
|
-
* by email. Contacts are automatically linked to both the customer and the deal.
|
|
836
|
-
*
|
|
837
|
-
* @example
|
|
838
|
-
* // Update customer's domain if not set
|
|
839
|
-
* await client.deals.update('deal_123', { customerId: 'cust_456', domain: 'newdomain.com' });
|
|
840
|
-
*
|
|
841
|
-
* // Update customer and contacts inline
|
|
842
|
-
* await client.deals.update('deal_123', {
|
|
843
|
-
* customer: { name: 'Updated Name', domain: 'acme.com' },
|
|
844
|
-
* contacts: [{ email: 'new@acme.com', name: 'New Contact' }],
|
|
845
|
-
* });
|
|
846
|
-
*/
|
|
847
403
|
async update(dealId, data) {
|
|
848
|
-
return this.
|
|
404
|
+
return this.unwrap(this.api.PUT("/deals/{id}", { params: { path: { id: dealId } }, body: data }));
|
|
849
405
|
}
|
|
850
|
-
/**
|
|
851
|
-
* Archive (soft delete) a deal
|
|
852
|
-
*/
|
|
853
406
|
async del(dealId) {
|
|
854
|
-
return this.
|
|
407
|
+
return this.unwrap(this.api.DELETE("/deals/{id}", { params: { path: { id: dealId } } }));
|
|
855
408
|
}
|
|
856
|
-
/**
|
|
857
|
-
* Get deal activity timeline
|
|
858
|
-
*/
|
|
859
409
|
async timeline(dealId) {
|
|
860
|
-
|
|
861
|
-
`/deals/${dealId}/timeline`
|
|
862
|
-
);
|
|
863
|
-
return {
|
|
864
|
-
events: response.events || [],
|
|
865
|
-
hasNextPage: response.hasNextPage || false,
|
|
866
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
867
|
-
cursor: response.cursor
|
|
868
|
-
};
|
|
410
|
+
return this.unwrap(this.api.GET("/deals/{id}/timeline", { params: { path: { id: dealId } } }));
|
|
869
411
|
}
|
|
870
|
-
/**
|
|
871
|
-
* List deal events
|
|
872
|
-
*/
|
|
873
412
|
async listEvents(dealId) {
|
|
874
|
-
|
|
875
|
-
`/deals/${dealId}/events`
|
|
876
|
-
);
|
|
877
|
-
return {
|
|
878
|
-
events: response.events || [],
|
|
879
|
-
hasNextPage: response.hasNextPage || false,
|
|
880
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
881
|
-
total: response.total,
|
|
882
|
-
cursor: response.cursor
|
|
883
|
-
};
|
|
413
|
+
return this.unwrap(this.api.GET("/deals/{id}/events", { params: { path: { id: dealId } } }));
|
|
884
414
|
}
|
|
885
|
-
/**
|
|
886
|
-
* Create a deal event
|
|
887
|
-
*
|
|
888
|
-
* Creates an event on a deal. If `dealStageId` is provided, the deal will
|
|
889
|
-
* progress to that stage. If `dealActivityId` is provided and the activity
|
|
890
|
-
* is configured for a future stage, the deal will automatically progress.
|
|
891
|
-
*
|
|
892
|
-
* @example
|
|
893
|
-
* // Create a simple note
|
|
894
|
-
* await client.deals.createEvent('deal_123', { notes: 'Follow-up call completed' });
|
|
895
|
-
*
|
|
896
|
-
* // Create an event and progress to a new stage
|
|
897
|
-
* await client.deals.createEvent('deal_123', {
|
|
898
|
-
* dealStageId: 'stage_456',
|
|
899
|
-
* notes: 'Moving to negotiation phase',
|
|
900
|
-
* });
|
|
901
|
-
*/
|
|
902
415
|
async createEvent(dealId, data) {
|
|
903
|
-
return this.
|
|
416
|
+
return this.unwrap(this.api.POST("/deals/{id}/events", { params: { path: { id: dealId } }, body: data }));
|
|
904
417
|
}
|
|
905
418
|
};
|
|
906
419
|
|
|
907
420
|
// src/resources/deal-flows.ts
|
|
908
421
|
var DealFlowsResource = class extends BaseResource {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
*/
|
|
912
|
-
async list() {
|
|
913
|
-
return this.get("/deal_flows");
|
|
422
|
+
async list(params) {
|
|
423
|
+
return this.unwrap(this.api.GET("/deal_flows", { params: { query: params } }));
|
|
914
424
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
*/
|
|
918
|
-
async retrieve(dealFlowId) {
|
|
919
|
-
return this.get(`/deal_flows/${dealFlowId}`);
|
|
425
|
+
async get(dealFlowId) {
|
|
426
|
+
return this.unwrap(this.api.GET("/deal_flows/{id}", { params: { path: { id: dealFlowId } } }));
|
|
920
427
|
}
|
|
921
|
-
/**
|
|
922
|
-
* Create a new deal flow
|
|
923
|
-
*/
|
|
924
428
|
async create(data) {
|
|
925
|
-
return this.
|
|
429
|
+
return this.unwrap(this.api.POST("/deal_flows", { body: data }));
|
|
926
430
|
}
|
|
927
|
-
/**
|
|
928
|
-
* Update an existing deal flow
|
|
929
|
-
*/
|
|
930
431
|
async update(dealFlowId, data) {
|
|
931
|
-
return this.
|
|
932
|
-
`/deal_flows/${dealFlowId}`,
|
|
933
|
-
data
|
|
934
|
-
);
|
|
432
|
+
return this.unwrap(this.api.PUT("/deal_flows/{id}", { params: { path: { id: dealFlowId } }, body: data }));
|
|
935
433
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Delete a deal flow
|
|
938
|
-
*/
|
|
939
434
|
async del(dealFlowId) {
|
|
940
|
-
return this.
|
|
435
|
+
return this.unwrap(this.api.DELETE("/deal_flows/{id}", { params: { path: { id: dealFlowId } } }));
|
|
941
436
|
}
|
|
942
437
|
};
|
|
943
438
|
|
|
944
439
|
// src/resources/deal-activities.ts
|
|
945
440
|
var DealActivitiesResource = class extends BaseResource {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
*/
|
|
949
|
-
async list() {
|
|
950
|
-
return this.get("/deal_activities");
|
|
441
|
+
async list(params) {
|
|
442
|
+
return this.unwrap(this.api.GET("/deal_activities", { params: { query: params } }));
|
|
951
443
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
*/
|
|
955
|
-
async retrieve(dealActivityId) {
|
|
956
|
-
return this.get(
|
|
957
|
-
`/deal_activities/${dealActivityId}`
|
|
958
|
-
);
|
|
444
|
+
async get(dealActivityId) {
|
|
445
|
+
return this.unwrap(this.api.GET("/deal_activities/{id}", { params: { path: { id: dealActivityId } } }));
|
|
959
446
|
}
|
|
960
|
-
/**
|
|
961
|
-
* Create a new deal activity
|
|
962
|
-
*/
|
|
963
447
|
async create(data) {
|
|
964
|
-
return this.
|
|
448
|
+
return this.unwrap(this.api.POST("/deal_activities", { body: data }));
|
|
965
449
|
}
|
|
966
|
-
/**
|
|
967
|
-
* Update an existing deal activity
|
|
968
|
-
*/
|
|
969
450
|
async update(dealActivityId, data) {
|
|
970
|
-
return this.
|
|
971
|
-
`/deal_activities/${dealActivityId}`,
|
|
972
|
-
data
|
|
973
|
-
);
|
|
451
|
+
return this.unwrap(this.api.PUT("/deal_activities/{id}", { params: { path: { id: dealActivityId } }, body: data }));
|
|
974
452
|
}
|
|
975
|
-
/**
|
|
976
|
-
* Delete a deal activity
|
|
977
|
-
*/
|
|
978
453
|
async del(dealActivityId) {
|
|
979
|
-
return this.
|
|
454
|
+
return this.unwrap(this.api.DELETE("/deal_activities/{id}", { params: { path: { id: dealActivityId } } }));
|
|
980
455
|
}
|
|
981
456
|
};
|
|
982
457
|
|
|
983
458
|
// src/resources/tickets.ts
|
|
984
459
|
var TicketsResource = class extends BaseResource {
|
|
985
|
-
|
|
986
|
-
* List tickets with optional filters and pagination
|
|
987
|
-
*/
|
|
460
|
+
// Tickets
|
|
988
461
|
async list(params) {
|
|
989
|
-
|
|
990
|
-
return {
|
|
991
|
-
tickets: response.tickets || [],
|
|
992
|
-
hasNextPage: response.hasNextPage || false,
|
|
993
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
994
|
-
total: response.total,
|
|
995
|
-
cursor: response.cursor
|
|
996
|
-
};
|
|
462
|
+
return this.unwrap(this.api.GET("/tickets", { params: { query: params } }));
|
|
997
463
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
*/
|
|
1001
|
-
async retrieve(ticketId) {
|
|
1002
|
-
return this.get(`/tickets/${ticketId}`);
|
|
464
|
+
async get(ticketId) {
|
|
465
|
+
return this.unwrap(this.api.GET("/tickets/{id}", { params: { path: { id: ticketId } } }));
|
|
1003
466
|
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Create a new ticket
|
|
1006
|
-
*/
|
|
1007
467
|
async create(data) {
|
|
1008
|
-
return this.
|
|
468
|
+
return this.unwrap(this.api.POST("/tickets", { body: data }));
|
|
1009
469
|
}
|
|
1010
|
-
/**
|
|
1011
|
-
* Update an existing ticket
|
|
1012
|
-
*/
|
|
1013
470
|
async update(ticketId, data) {
|
|
1014
|
-
return this.
|
|
1015
|
-
}
|
|
1016
|
-
/**
|
|
1017
|
-
* Delete a ticket
|
|
1018
|
-
*/
|
|
1019
|
-
async del(ticketId) {
|
|
1020
|
-
return this._delete(`/tickets/${ticketId}`);
|
|
471
|
+
return this.unwrap(this.api.PUT("/tickets/{id}", { params: { path: { id: ticketId } }, body: data }));
|
|
1021
472
|
}
|
|
1022
|
-
//
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
*/
|
|
1026
|
-
async listMessages(ticketId) {
|
|
1027
|
-
return this.get(
|
|
1028
|
-
`/tickets/${ticketId}/messages`
|
|
1029
|
-
);
|
|
473
|
+
// Messages
|
|
474
|
+
async listMessages(ticketId, params) {
|
|
475
|
+
return this.unwrap(this.api.GET("/tickets/{id}/messages", { params: { path: { id: ticketId }, query: params } }));
|
|
1030
476
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
*/
|
|
1034
|
-
async retrieveMessage(ticketId, messageId) {
|
|
1035
|
-
return this.get(
|
|
1036
|
-
`/tickets/${ticketId}/messages/${messageId}`
|
|
1037
|
-
);
|
|
477
|
+
async getMessage(ticketId, messageId) {
|
|
478
|
+
return this.unwrap(this.api.GET("/tickets/{id}/messages/{messageId}", { params: { path: { id: ticketId, messageId } } }));
|
|
1038
479
|
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Create a new message on a ticket
|
|
1041
|
-
*/
|
|
1042
480
|
async createMessage(ticketId, data) {
|
|
1043
|
-
return this.
|
|
1044
|
-
`/tickets/${ticketId}/messages`,
|
|
1045
|
-
data
|
|
1046
|
-
);
|
|
481
|
+
return this.unwrap(this.api.POST("/tickets/{id}/messages", { params: { path: { id: ticketId } }, body: data }));
|
|
1047
482
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
*/
|
|
1051
|
-
async updateMessage(ticketId, messageId, data) {
|
|
1052
|
-
return this.put(
|
|
1053
|
-
`/tickets/${ticketId}/messages/${messageId}`,
|
|
1054
|
-
data
|
|
1055
|
-
);
|
|
483
|
+
async updateMessage(ticketId, data) {
|
|
484
|
+
return this.unwrap(this.api.PUT("/tickets/{id}/messages", { params: { path: { id: ticketId } }, body: data }));
|
|
1056
485
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
486
|
+
// Events
|
|
487
|
+
async listEvents(ticketId, params) {
|
|
488
|
+
return this.unwrap(this.api.GET("/tickets/{id}/events", { params: { path: { id: ticketId }, query: params } }));
|
|
489
|
+
}
|
|
490
|
+
async createEvent(ticketId, data) {
|
|
491
|
+
return this.unwrap(this.api.POST("/tickets/{id}/events", { params: { path: { id: ticketId } }, body: data }));
|
|
492
|
+
}
|
|
493
|
+
// Loops
|
|
494
|
+
async listLoops(ticketId) {
|
|
495
|
+
return this.unwrap(this.api.GET("/tickets/{id}/loops", { params: { path: { id: ticketId } } }));
|
|
496
|
+
}
|
|
497
|
+
async getLoop(ticketId, loopId) {
|
|
498
|
+
return this.unwrap(this.api.GET("/tickets/{id}/loops/{loopId}", { params: { path: { id: ticketId, loopId } } }));
|
|
1064
499
|
}
|
|
1065
500
|
};
|
|
1066
501
|
|
|
1067
502
|
// src/resources/channels.ts
|
|
1068
503
|
var ChannelsResource = class extends BaseResource {
|
|
1069
504
|
/**
|
|
1070
|
-
* List CX channels
|
|
505
|
+
* List CX channels with optional filters
|
|
1071
506
|
*/
|
|
1072
507
|
async list(params) {
|
|
1073
|
-
return this.
|
|
508
|
+
return this.unwrap(this.api.GET("/channels", { params: { query: params } }));
|
|
1074
509
|
}
|
|
1075
510
|
/**
|
|
1076
511
|
* Create a new CX channel
|
|
1077
512
|
*/
|
|
1078
513
|
async create(data) {
|
|
1079
|
-
return this.
|
|
514
|
+
return this.unwrap(this.api.POST("/channels", { body: data }));
|
|
1080
515
|
}
|
|
1081
516
|
};
|
|
1082
517
|
|
|
@@ -1086,113 +521,67 @@ var FlowsResource = class extends BaseResource {
|
|
|
1086
521
|
* List flows with optional filters and pagination
|
|
1087
522
|
*/
|
|
1088
523
|
async list(params) {
|
|
1089
|
-
|
|
1090
|
-
return {
|
|
1091
|
-
flows: response.flows || [],
|
|
1092
|
-
hasNextPage: response.hasNextPage || false,
|
|
1093
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1094
|
-
total: response.total,
|
|
1095
|
-
cursor: response.cursor
|
|
1096
|
-
};
|
|
524
|
+
return this.unwrap(this.api.GET("/flows", { params: { query: params } }));
|
|
1097
525
|
}
|
|
1098
526
|
/**
|
|
1099
|
-
*
|
|
527
|
+
* Get a single flow by ID
|
|
1100
528
|
*/
|
|
1101
|
-
async
|
|
1102
|
-
return this.
|
|
529
|
+
async get(flowId) {
|
|
530
|
+
return this.unwrap(this.api.GET("/flows/{id}", { params: { path: { id: flowId } } }));
|
|
1103
531
|
}
|
|
1104
532
|
/**
|
|
1105
533
|
* Create a new flow
|
|
1106
534
|
*/
|
|
1107
535
|
async create(data) {
|
|
1108
|
-
return this.
|
|
536
|
+
return this.unwrap(this.api.POST("/flows", { body: data }));
|
|
1109
537
|
}
|
|
1110
538
|
/**
|
|
1111
539
|
* Update an existing flow
|
|
1112
540
|
*/
|
|
1113
541
|
async update(flowId, data) {
|
|
1114
|
-
return this.
|
|
542
|
+
return this.unwrap(this.api.PATCH("/flows/{id}", { params: { path: { id: flowId } }, body: data }));
|
|
1115
543
|
}
|
|
1116
544
|
/**
|
|
1117
545
|
* Delete a flow
|
|
1118
546
|
*/
|
|
1119
547
|
async del(flowId) {
|
|
1120
|
-
return this.
|
|
548
|
+
return this.unwrap(this.api.DELETE("/flows/{id}", { params: { path: { id: flowId } } }));
|
|
1121
549
|
}
|
|
1122
550
|
};
|
|
1123
551
|
|
|
1124
552
|
// src/resources/tasks.ts
|
|
1125
553
|
var TasksResource = class extends BaseResource {
|
|
1126
|
-
|
|
1127
|
-
* List tasks with optional filters and pagination
|
|
1128
|
-
*/
|
|
554
|
+
// Tasks
|
|
1129
555
|
async list(params) {
|
|
1130
|
-
|
|
1131
|
-
return {
|
|
1132
|
-
tasks: response.tasks || [],
|
|
1133
|
-
hasNextPage: response.hasNextPage || false,
|
|
1134
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1135
|
-
total: response.total,
|
|
1136
|
-
cursor: response.cursor
|
|
1137
|
-
};
|
|
556
|
+
return this.unwrap(this.api.GET("/tasks", { params: { query: params } }));
|
|
1138
557
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
*/
|
|
1142
|
-
async retrieve(taskId) {
|
|
1143
|
-
return this.get(`/tasks/${taskId}`);
|
|
558
|
+
async get(taskId) {
|
|
559
|
+
return this.unwrap(this.api.GET("/tasks/{id}", { params: { path: { id: taskId } } }));
|
|
1144
560
|
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Create a new task
|
|
1147
|
-
*/
|
|
1148
561
|
async create(data) {
|
|
1149
|
-
return this.
|
|
562
|
+
return this.unwrap(this.api.POST("/tasks", { body: data }));
|
|
1150
563
|
}
|
|
1151
|
-
/**
|
|
1152
|
-
* Update an existing task
|
|
1153
|
-
*/
|
|
1154
564
|
async update(taskId, data) {
|
|
1155
|
-
return this.
|
|
565
|
+
return this.unwrap(this.api.PUT("/tasks/{id}", { params: { path: { id: taskId } }, body: data }));
|
|
1156
566
|
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Delete a task
|
|
1159
|
-
*/
|
|
1160
567
|
async del(taskId) {
|
|
1161
|
-
return this.
|
|
568
|
+
return this.unwrap(this.api.DELETE("/tasks/{id}", { params: { path: { id: taskId } } }));
|
|
1162
569
|
}
|
|
1163
|
-
//
|
|
1164
|
-
/**
|
|
1165
|
-
* List todo items for a task
|
|
1166
|
-
*/
|
|
570
|
+
// Todo Items
|
|
1167
571
|
async listTodoItems(taskId) {
|
|
1168
|
-
return this.
|
|
572
|
+
return this.unwrap(this.api.GET("/tasks/{id}/todo-items", { params: { path: { id: taskId } } }));
|
|
1169
573
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
*/
|
|
1173
|
-
async retrieveTodoItem(taskId, itemId) {
|
|
1174
|
-
return this.get(`/tasks/${taskId}/todo-items/${itemId}`);
|
|
574
|
+
async getTodoItem(taskId, itemId) {
|
|
575
|
+
return this.unwrap(this.api.GET("/tasks/{id}/todo-items/{itemId}", { params: { path: { id: taskId, itemId } } }));
|
|
1175
576
|
}
|
|
1176
|
-
/**
|
|
1177
|
-
* Create a todo item for a task
|
|
1178
|
-
*/
|
|
1179
577
|
async createTodoItem(taskId, data) {
|
|
1180
|
-
return this.
|
|
578
|
+
return this.unwrap(this.api.POST("/tasks/{id}/todo-items", { params: { path: { id: taskId } }, body: data }));
|
|
1181
579
|
}
|
|
1182
|
-
/**
|
|
1183
|
-
* Update a todo item
|
|
1184
|
-
*/
|
|
1185
580
|
async updateTodoItem(taskId, itemId, data) {
|
|
1186
|
-
return this.
|
|
1187
|
-
`/tasks/${taskId}/todo-items/${itemId}`,
|
|
1188
|
-
data
|
|
1189
|
-
);
|
|
581
|
+
return this.unwrap(this.api.PUT("/tasks/{id}/todo-items/{itemId}", { params: { path: { id: taskId, itemId } }, body: data }));
|
|
1190
582
|
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Delete a todo item
|
|
1193
|
-
*/
|
|
1194
583
|
async deleteTodoItem(taskId, itemId) {
|
|
1195
|
-
return this.
|
|
584
|
+
return this.unwrap(this.api.DELETE("/tasks/{id}/todo-items/{itemId}", { params: { path: { id: taskId, itemId } } }));
|
|
1196
585
|
}
|
|
1197
586
|
};
|
|
1198
587
|
|
|
@@ -1202,36 +591,25 @@ var WebhooksResource = class extends BaseResource {
|
|
|
1202
591
|
* List all webhooks
|
|
1203
592
|
*/
|
|
1204
593
|
async list() {
|
|
1205
|
-
|
|
1206
|
-
return {
|
|
1207
|
-
webhooks: response.webhooks || [],
|
|
1208
|
-
hasNextPage: response.hasNextPage || false,
|
|
1209
|
-
hasPreviousPage: response.hasPreviousPage || false
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
/**
|
|
1213
|
-
* Retrieve a single webhook by ID
|
|
1214
|
-
*/
|
|
1215
|
-
async retrieve(webhookId) {
|
|
1216
|
-
return this.get(`/webhooks/${webhookId}`);
|
|
594
|
+
return this.unwrap(this.api.GET("/webhooks"));
|
|
1217
595
|
}
|
|
1218
596
|
/**
|
|
1219
597
|
* Create a new webhook
|
|
1220
598
|
*/
|
|
1221
599
|
async create(data) {
|
|
1222
|
-
return this.
|
|
600
|
+
return this.unwrap(this.api.POST("/webhooks", { body: data }));
|
|
1223
601
|
}
|
|
1224
602
|
/**
|
|
1225
603
|
* Update an existing webhook
|
|
1226
604
|
*/
|
|
1227
605
|
async update(webhookId, data) {
|
|
1228
|
-
return this.
|
|
606
|
+
return this.unwrap(this.api.PUT("/webhooks/{id}", { params: { path: { id: webhookId } }, body: data }));
|
|
1229
607
|
}
|
|
1230
608
|
/**
|
|
1231
609
|
* Delete a webhook
|
|
1232
610
|
*/
|
|
1233
611
|
async del(webhookId) {
|
|
1234
|
-
return this.
|
|
612
|
+
return this.unwrap(this.api.DELETE("/webhooks/{id}", { params: { path: { id: webhookId } } }));
|
|
1235
613
|
}
|
|
1236
614
|
};
|
|
1237
615
|
|
|
@@ -1241,37 +619,31 @@ var CompaniesResource = class extends BaseResource {
|
|
|
1241
619
|
* List companies with optional pagination
|
|
1242
620
|
*/
|
|
1243
621
|
async list(params) {
|
|
1244
|
-
|
|
1245
|
-
return {
|
|
1246
|
-
companies: response.companies || [],
|
|
1247
|
-
hasNextPage: response.hasNextPage || false,
|
|
1248
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1249
|
-
cursor: response.cursor
|
|
1250
|
-
};
|
|
622
|
+
return this.unwrap(this.api.GET("/companies", { params: { query: params } }));
|
|
1251
623
|
}
|
|
1252
624
|
/**
|
|
1253
|
-
*
|
|
625
|
+
* Get a single company by ID
|
|
1254
626
|
*/
|
|
1255
|
-
async
|
|
1256
|
-
return this.
|
|
627
|
+
async get(companyId) {
|
|
628
|
+
return this.unwrap(this.api.GET("/companies/{id}", { params: { path: { id: companyId } } }));
|
|
1257
629
|
}
|
|
1258
630
|
/**
|
|
1259
631
|
* Create a new company
|
|
1260
632
|
*/
|
|
1261
633
|
async create(data) {
|
|
1262
|
-
return this.
|
|
634
|
+
return this.unwrap(this.api.POST("/companies", { body: data }));
|
|
1263
635
|
}
|
|
1264
636
|
/**
|
|
1265
637
|
* Update an existing company
|
|
1266
638
|
*/
|
|
1267
639
|
async update(companyId, data) {
|
|
1268
|
-
return this.
|
|
640
|
+
return this.unwrap(this.api.PUT("/companies/{id}", { params: { path: { id: companyId } }, body: data }));
|
|
1269
641
|
}
|
|
1270
642
|
/**
|
|
1271
643
|
* Delete a company
|
|
1272
644
|
*/
|
|
1273
645
|
async del(companyId) {
|
|
1274
|
-
return this.
|
|
646
|
+
return this.unwrap(this.api.DELETE("/companies/{id}", { params: { path: { id: companyId } } }));
|
|
1275
647
|
}
|
|
1276
648
|
};
|
|
1277
649
|
|
|
@@ -1281,24 +653,13 @@ var CustomerSegmentsResource = class extends BaseResource {
|
|
|
1281
653
|
* List public customer segments with optional pagination
|
|
1282
654
|
*/
|
|
1283
655
|
async list(params) {
|
|
1284
|
-
|
|
1285
|
-
"/customer_segments",
|
|
1286
|
-
params
|
|
1287
|
-
);
|
|
1288
|
-
return {
|
|
1289
|
-
customerSegments: response.customerSegments || [],
|
|
1290
|
-
hasNextPage: response.hasNextPage || false,
|
|
1291
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1292
|
-
cursor: response.cursor
|
|
1293
|
-
};
|
|
656
|
+
return this.unwrap(this.api.GET("/customer_segments", { params: { query: params } }));
|
|
1294
657
|
}
|
|
1295
658
|
/**
|
|
1296
|
-
*
|
|
659
|
+
* Get a single customer segment by ID
|
|
1297
660
|
*/
|
|
1298
|
-
async
|
|
1299
|
-
return this.
|
|
1300
|
-
`/customer_segments/${segmentId}`
|
|
1301
|
-
);
|
|
661
|
+
async get(segmentId) {
|
|
662
|
+
return this.unwrap(this.api.GET("/customer_segments/{id}", { params: { path: { id: segmentId } } }));
|
|
1302
663
|
}
|
|
1303
664
|
};
|
|
1304
665
|
|
|
@@ -1308,75 +669,57 @@ var AffiliatesResource = class extends BaseResource {
|
|
|
1308
669
|
* List affiliates with optional filters and pagination
|
|
1309
670
|
*/
|
|
1310
671
|
async list(params) {
|
|
1311
|
-
|
|
1312
|
-
"/affiliates",
|
|
1313
|
-
params
|
|
1314
|
-
);
|
|
1315
|
-
return {
|
|
1316
|
-
affiliates: response.affiliates || [],
|
|
1317
|
-
hasNextPage: response.hasNextPage || false,
|
|
1318
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1319
|
-
cursor: response.cursor
|
|
1320
|
-
};
|
|
672
|
+
return this.unwrap(this.api.GET("/affiliates", { params: { query: params } }));
|
|
1321
673
|
}
|
|
1322
674
|
/**
|
|
1323
|
-
*
|
|
675
|
+
* Get a single affiliate by ID
|
|
1324
676
|
*/
|
|
1325
|
-
async
|
|
1326
|
-
return this.
|
|
677
|
+
async get(affiliateId) {
|
|
678
|
+
return this.unwrap(this.api.GET("/affiliates/{id}", { params: { path: { id: affiliateId } } }));
|
|
1327
679
|
}
|
|
1328
680
|
/**
|
|
1329
681
|
* Update an existing affiliate
|
|
682
|
+
* Note: PUT not in OpenAPI spec but kept for backwards compatibility
|
|
1330
683
|
*/
|
|
1331
684
|
async update(affiliateId, data) {
|
|
1332
|
-
return this.
|
|
1333
|
-
`/affiliates/${affiliateId}`,
|
|
1334
|
-
data
|
|
1335
|
-
);
|
|
685
|
+
return this.unwrap(this.untypedApi.PUT("/affiliates/{id}", { params: { path: { id: affiliateId } }, body: data }));
|
|
1336
686
|
}
|
|
1337
687
|
};
|
|
1338
688
|
|
|
1339
689
|
// src/resources/affiliate-programs.ts
|
|
1340
690
|
var AffiliateProgramsResource = class extends BaseResource {
|
|
1341
691
|
/**
|
|
1342
|
-
* List
|
|
692
|
+
* List affiliate programs with optional filters and pagination
|
|
1343
693
|
*/
|
|
1344
|
-
async list() {
|
|
1345
|
-
return this.
|
|
1346
|
-
"/affiliate_programs"
|
|
1347
|
-
);
|
|
694
|
+
async list(params) {
|
|
695
|
+
return this.unwrap(this.api.GET("/affiliate_programs", { params: { query: params } }));
|
|
1348
696
|
}
|
|
1349
697
|
/**
|
|
1350
|
-
*
|
|
698
|
+
* Get a single affiliate program by ID
|
|
1351
699
|
*/
|
|
1352
|
-
async
|
|
1353
|
-
return this.
|
|
1354
|
-
`/affiliate_programs/${programId}`
|
|
1355
|
-
);
|
|
700
|
+
async get(programId) {
|
|
701
|
+
return this.unwrap(this.api.GET("/affiliate_programs/{id}", { params: { path: { id: programId } } }));
|
|
1356
702
|
}
|
|
1357
703
|
/**
|
|
1358
704
|
* Create a new affiliate program
|
|
705
|
+
* Note: POST not yet in OpenAPI spec
|
|
1359
706
|
*/
|
|
1360
707
|
async create(data) {
|
|
1361
|
-
return this.
|
|
1362
|
-
"/affiliate_programs",
|
|
1363
|
-
data
|
|
1364
|
-
);
|
|
708
|
+
return this.unwrap(this.untypedApi.POST("/affiliate_programs", { body: data }));
|
|
1365
709
|
}
|
|
1366
710
|
/**
|
|
1367
711
|
* Update an existing affiliate program
|
|
712
|
+
* Note: PUT not yet in OpenAPI spec
|
|
1368
713
|
*/
|
|
1369
714
|
async update(programId, data) {
|
|
1370
|
-
return this.
|
|
1371
|
-
`/affiliate_programs/${programId}`,
|
|
1372
|
-
data
|
|
1373
|
-
);
|
|
715
|
+
return this.unwrap(this.untypedApi.PUT("/affiliate_programs/{id}", { params: { path: { id: programId } }, body: data }));
|
|
1374
716
|
}
|
|
1375
717
|
/**
|
|
1376
718
|
* Delete an affiliate program
|
|
719
|
+
* Note: DELETE not yet in OpenAPI spec
|
|
1377
720
|
*/
|
|
1378
721
|
async del(programId) {
|
|
1379
|
-
return this.
|
|
722
|
+
return this.unwrap(this.untypedApi.DELETE("/affiliate_programs/{id}", { params: { path: { id: programId } } }));
|
|
1380
723
|
}
|
|
1381
724
|
};
|
|
1382
725
|
|
|
@@ -1386,24 +729,13 @@ var AffiliateCommissionsResource = class extends BaseResource {
|
|
|
1386
729
|
* List affiliate commissions with optional filters and pagination
|
|
1387
730
|
*/
|
|
1388
731
|
async list(params) {
|
|
1389
|
-
|
|
1390
|
-
"/affiliate_commissions",
|
|
1391
|
-
params
|
|
1392
|
-
);
|
|
1393
|
-
return {
|
|
1394
|
-
commissions: response.commissions || [],
|
|
1395
|
-
hasNextPage: response.hasNextPage || false,
|
|
1396
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1397
|
-
cursor: response.cursor
|
|
1398
|
-
};
|
|
732
|
+
return this.unwrap(this.api.GET("/affiliate_commissions", { params: { query: params } }));
|
|
1399
733
|
}
|
|
1400
734
|
/**
|
|
1401
|
-
*
|
|
735
|
+
* Get a single affiliate commission by ID
|
|
1402
736
|
*/
|
|
1403
|
-
async
|
|
1404
|
-
return this.
|
|
1405
|
-
`/affiliate_commissions/${commissionId}`
|
|
1406
|
-
);
|
|
737
|
+
async get(commissionId) {
|
|
738
|
+
return this.unwrap(this.api.GET("/affiliate_commissions/{id}", { params: { path: { id: commissionId } } }));
|
|
1407
739
|
}
|
|
1408
740
|
};
|
|
1409
741
|
|
|
@@ -1413,24 +745,13 @@ var AffiliatePayoutsResource = class extends BaseResource {
|
|
|
1413
745
|
* List affiliate payouts with optional filters and pagination
|
|
1414
746
|
*/
|
|
1415
747
|
async list(params) {
|
|
1416
|
-
|
|
1417
|
-
"/affiliate_payouts",
|
|
1418
|
-
params
|
|
1419
|
-
);
|
|
1420
|
-
return {
|
|
1421
|
-
payouts: response.payouts || [],
|
|
1422
|
-
hasNextPage: response.hasNextPage || false,
|
|
1423
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1424
|
-
cursor: response.cursor
|
|
1425
|
-
};
|
|
748
|
+
return this.unwrap(this.api.GET("/affiliate_payouts", { params: { query: params } }));
|
|
1426
749
|
}
|
|
1427
750
|
/**
|
|
1428
|
-
*
|
|
751
|
+
* Get a single affiliate payout by ID
|
|
1429
752
|
*/
|
|
1430
|
-
async
|
|
1431
|
-
return this.
|
|
1432
|
-
`/affiliate_payouts/${payoutId}`
|
|
1433
|
-
);
|
|
753
|
+
async get(payoutId) {
|
|
754
|
+
return this.unwrap(this.api.GET("/affiliate_payouts/{id}", { params: { path: { id: payoutId } } }));
|
|
1434
755
|
}
|
|
1435
756
|
};
|
|
1436
757
|
|
|
@@ -1440,24 +761,13 @@ var AffiliateReferralsResource = class extends BaseResource {
|
|
|
1440
761
|
* List affiliate referrals with optional filters and pagination
|
|
1441
762
|
*/
|
|
1442
763
|
async list(params) {
|
|
1443
|
-
|
|
1444
|
-
"/affiliate_referrals",
|
|
1445
|
-
params
|
|
1446
|
-
);
|
|
1447
|
-
return {
|
|
1448
|
-
referrals: response.referrals || [],
|
|
1449
|
-
hasNextPage: response.hasNextPage || false,
|
|
1450
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1451
|
-
cursor: response.cursor
|
|
1452
|
-
};
|
|
764
|
+
return this.unwrap(this.api.GET("/affiliate_referrals", { params: { query: params } }));
|
|
1453
765
|
}
|
|
1454
766
|
/**
|
|
1455
|
-
*
|
|
767
|
+
* Get a single affiliate referral by ID
|
|
1456
768
|
*/
|
|
1457
|
-
async
|
|
1458
|
-
return this.
|
|
1459
|
-
`/affiliate_referrals/${referralId}`
|
|
1460
|
-
);
|
|
769
|
+
async get(referralId) {
|
|
770
|
+
return this.unwrap(this.api.GET("/affiliate_referrals/{id}", { params: { path: { id: referralId } } }));
|
|
1461
771
|
}
|
|
1462
772
|
};
|
|
1463
773
|
|
|
@@ -1467,14 +777,7 @@ var ChargesResource = class extends BaseResource {
|
|
|
1467
777
|
* List charges with optional filters and pagination
|
|
1468
778
|
*/
|
|
1469
779
|
async list(params) {
|
|
1470
|
-
|
|
1471
|
-
return {
|
|
1472
|
-
charges: response.charges || [],
|
|
1473
|
-
hasNextPage: response.hasNextPage || false,
|
|
1474
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1475
|
-
total: response.total,
|
|
1476
|
-
cursor: response.cursor
|
|
1477
|
-
};
|
|
780
|
+
return this.unwrap(this.api.GET("/charges", { params: { query: params } }));
|
|
1478
781
|
}
|
|
1479
782
|
};
|
|
1480
783
|
|
|
@@ -1484,227 +787,62 @@ var TransactionsResource = class extends BaseResource {
|
|
|
1484
787
|
* List transactions with optional filters and pagination
|
|
1485
788
|
*/
|
|
1486
789
|
async list(params) {
|
|
1487
|
-
|
|
1488
|
-
"/transactions",
|
|
1489
|
-
params
|
|
1490
|
-
);
|
|
1491
|
-
return {
|
|
1492
|
-
transactions: response.transactions || [],
|
|
1493
|
-
hasNextPage: response.hasNextPage || false,
|
|
1494
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1495
|
-
total: response.total,
|
|
1496
|
-
cursor: response.cursor
|
|
1497
|
-
};
|
|
790
|
+
return this.unwrap(this.api.GET("/transactions", { params: { query: params } }));
|
|
1498
791
|
}
|
|
1499
792
|
/**
|
|
1500
|
-
*
|
|
793
|
+
* Get a single transaction by ID
|
|
1501
794
|
*/
|
|
1502
|
-
async
|
|
1503
|
-
return this.
|
|
1504
|
-
`/transactions/${transactionId}`
|
|
1505
|
-
);
|
|
795
|
+
async get(transactionId) {
|
|
796
|
+
return this.unwrap(this.api.GET("/transactions/{id}", { params: { path: { id: transactionId } } }));
|
|
1506
797
|
}
|
|
1507
798
|
};
|
|
1508
799
|
|
|
1509
800
|
// src/resources/metrics.ts
|
|
1510
801
|
var MetricsResource = class extends BaseResource {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
*/
|
|
1514
|
-
async fetch(params) {
|
|
1515
|
-
const response = await this.client.get("/metrics", {
|
|
1516
|
-
...params,
|
|
1517
|
-
includes: params.includes || ["includeTotal"],
|
|
1518
|
-
appEventsForMrr: params.appEventsForMrr ?? true
|
|
1519
|
-
});
|
|
1520
|
-
const data = Array.isArray(response) ? response : [];
|
|
1521
|
-
const first = data[0];
|
|
1522
|
-
return {
|
|
1523
|
-
data,
|
|
1524
|
-
total: first?.total,
|
|
1525
|
-
startingTotal: first?.startingTotal,
|
|
1526
|
-
change: first?.change,
|
|
1527
|
-
changePercentage: first?.changePercentage,
|
|
1528
|
-
formattedTotal: first?.formattedTotal,
|
|
1529
|
-
formattedChange: first?.formattedChange,
|
|
1530
|
-
formattedChangePercentage: first?.formattedChangePercentage
|
|
1531
|
-
};
|
|
802
|
+
async mrr(params) {
|
|
803
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/mrr", { params: { query: params } }));
|
|
1532
804
|
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Get Annual Recurring Revenue (ARR)
|
|
1535
|
-
*/
|
|
1536
805
|
async arr(params) {
|
|
1537
|
-
return this.
|
|
1538
|
-
metric: "PlatformApp.arr",
|
|
1539
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1540
|
-
...params
|
|
1541
|
-
});
|
|
806
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/arr", { params: { query: params } }));
|
|
1542
807
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
*/
|
|
1546
|
-
async mrr(params) {
|
|
1547
|
-
return this.fetch({
|
|
1548
|
-
metric: "PlatformApp.mrr",
|
|
1549
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1550
|
-
...params
|
|
1551
|
-
});
|
|
808
|
+
async arpu(params) {
|
|
809
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/arpu", { params: { query: params } }));
|
|
1552
810
|
}
|
|
1553
|
-
/**
|
|
1554
|
-
* Get active subscriptions count
|
|
1555
|
-
*/
|
|
1556
811
|
async activeSubscriptions(params) {
|
|
1557
|
-
return this.
|
|
1558
|
-
metric: "PlatformApp.activeSubscriptions",
|
|
1559
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1560
|
-
...params
|
|
1561
|
-
});
|
|
812
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/activeSubscriptions", { params: { query: params } }));
|
|
1562
813
|
}
|
|
1563
|
-
/**
|
|
1564
|
-
* Get active installations count
|
|
1565
|
-
*/
|
|
1566
814
|
async activeInstalls(params) {
|
|
1567
|
-
return this.
|
|
1568
|
-
metric: "PlatformApp.activeInstalls",
|
|
1569
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1570
|
-
...params
|
|
1571
|
-
});
|
|
815
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/activeInstalls", { params: { query: params } }));
|
|
1572
816
|
}
|
|
1573
|
-
/**
|
|
1574
|
-
* Get net new installations
|
|
1575
|
-
*/
|
|
1576
817
|
async netInstalls(params) {
|
|
1577
|
-
return this.
|
|
1578
|
-
metric: "PlatformApp.netInstalls",
|
|
1579
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1580
|
-
...params
|
|
1581
|
-
});
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Get Average Revenue Per User (ARPU)
|
|
1585
|
-
*/
|
|
1586
|
-
async arpu(params) {
|
|
1587
|
-
return this.fetch({
|
|
1588
|
-
metric: "PlatformApp.arpu",
|
|
1589
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1590
|
-
...params
|
|
1591
|
-
});
|
|
818
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/netInstalls", { params: { query: params } }));
|
|
1592
819
|
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
*/
|
|
1596
|
-
async ltv(params) {
|
|
1597
|
-
return this.fetch({
|
|
1598
|
-
metric: "PlatformApp.ltv",
|
|
1599
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1600
|
-
...params
|
|
1601
|
-
});
|
|
820
|
+
async logoChurn(params) {
|
|
821
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/logoChurn", { params: { query: params } }));
|
|
1602
822
|
}
|
|
1603
|
-
/**
|
|
1604
|
-
* Get revenue churn rate
|
|
1605
|
-
*/
|
|
1606
823
|
async revenueChurn(params) {
|
|
1607
|
-
return this.
|
|
1608
|
-
metric: "PlatformApp.revenueChurn",
|
|
1609
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1610
|
-
...params
|
|
1611
|
-
});
|
|
824
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/revenueChurn", { params: { query: params } }));
|
|
1612
825
|
}
|
|
1613
|
-
/**
|
|
1614
|
-
* Get logo (customer) churn rate
|
|
1615
|
-
*/
|
|
1616
|
-
async logoChurn(params) {
|
|
1617
|
-
return this.fetch({
|
|
1618
|
-
metric: "PlatformApp.logoChurn",
|
|
1619
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1620
|
-
...params
|
|
1621
|
-
});
|
|
1622
|
-
}
|
|
1623
|
-
/**
|
|
1624
|
-
* Get revenue retention rate
|
|
1625
|
-
*/
|
|
1626
826
|
async revenueRetention(params) {
|
|
1627
|
-
return this.
|
|
1628
|
-
metric: "PlatformApp.revenueRetention",
|
|
1629
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1630
|
-
...params
|
|
1631
|
-
});
|
|
827
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/revenueRetention", { params: { query: params } }));
|
|
1632
828
|
}
|
|
1633
|
-
/**
|
|
1634
|
-
* Get net revenue retention rate
|
|
1635
|
-
*/
|
|
1636
829
|
async netRevenueRetention(params) {
|
|
1637
|
-
return this.
|
|
1638
|
-
metric: "PlatformApp.netRevenueRetention",
|
|
1639
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1640
|
-
...params
|
|
1641
|
-
});
|
|
830
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/netRevenueRetention", { params: { query: params } }));
|
|
1642
831
|
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Get net revenue
|
|
1645
|
-
*/
|
|
1646
832
|
async netRevenue(params) {
|
|
1647
|
-
return this.
|
|
1648
|
-
metric: "PlatformApp.netRevenue",
|
|
1649
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1650
|
-
...params
|
|
1651
|
-
});
|
|
833
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/netRevenue", { params: { query: params } }));
|
|
1652
834
|
}
|
|
1653
|
-
/**
|
|
1654
|
-
* Get payout amount
|
|
1655
|
-
*/
|
|
1656
835
|
async payout(params) {
|
|
1657
|
-
return this.
|
|
1658
|
-
metric: "PlatformApp.payout",
|
|
1659
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1660
|
-
...params
|
|
1661
|
-
});
|
|
836
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/payout", { params: { query: params } }));
|
|
1662
837
|
}
|
|
1663
|
-
/**
|
|
1664
|
-
* Get predicted Lifetime Value
|
|
1665
|
-
*/
|
|
1666
838
|
async predictedLtv(params) {
|
|
1667
|
-
return this.
|
|
1668
|
-
metric: "PlatformApp.predictedLtv",
|
|
1669
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1670
|
-
...params
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
|
-
/**
|
|
1674
|
-
* Get charges
|
|
1675
|
-
*/
|
|
1676
|
-
async charges(params) {
|
|
1677
|
-
return this.fetch({
|
|
1678
|
-
metric: "PlatformApp.charges",
|
|
1679
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1680
|
-
...params
|
|
1681
|
-
});
|
|
839
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/predictedLtv", { params: { query: params } }));
|
|
1682
840
|
}
|
|
1683
|
-
/**
|
|
1684
|
-
* Get usage event metrics
|
|
1685
|
-
*/
|
|
1686
841
|
async usageEvent(params) {
|
|
1687
|
-
return this.
|
|
1688
|
-
metric: "PlatformApp.usageEvent",
|
|
1689
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1690
|
-
...params
|
|
1691
|
-
});
|
|
842
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/usageEvent", { params: { query: params } }));
|
|
1692
843
|
}
|
|
1693
|
-
/**
|
|
1694
|
-
* Get usage metric data
|
|
1695
|
-
*/
|
|
1696
844
|
async usageMetric(params) {
|
|
1697
|
-
return this.
|
|
1698
|
-
metric: "PlatformApp.usageMetric",
|
|
1699
|
-
dateRange: params.dateRange || "last_30_days",
|
|
1700
|
-
...params
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
/**
|
|
1704
|
-
* Get key sales metrics
|
|
1705
|
-
*/
|
|
1706
|
-
async sales(params) {
|
|
1707
|
-
return this.get("/metrics/sales", params);
|
|
845
|
+
return this.unwrap(this.api.GET("/api/core/v1/metrics/usageMetric", { params: { query: params } }));
|
|
1708
846
|
}
|
|
1709
847
|
};
|
|
1710
848
|
|
|
@@ -1714,29 +852,20 @@ var UsersResource = class extends BaseResource {
|
|
|
1714
852
|
* List organization users with optional pagination
|
|
1715
853
|
*/
|
|
1716
854
|
async list(params) {
|
|
1717
|
-
|
|
1718
|
-
return {
|
|
1719
|
-
users: response.users || [],
|
|
1720
|
-
hasNextPage: response.hasNextPage || false,
|
|
1721
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1722
|
-
cursor: response.cursor
|
|
1723
|
-
};
|
|
855
|
+
return this.unwrap(this.api.GET("/users", { params: { query: params } }));
|
|
1724
856
|
}
|
|
1725
857
|
/**
|
|
1726
|
-
*
|
|
858
|
+
* Get a single user by ID
|
|
1727
859
|
*/
|
|
1728
|
-
async
|
|
1729
|
-
return this.
|
|
860
|
+
async get(userId) {
|
|
861
|
+
return this.unwrap(this.api.GET("/users/{id}", { params: { path: { id: userId } } }));
|
|
1730
862
|
}
|
|
1731
863
|
};
|
|
1732
864
|
|
|
1733
865
|
// src/resources/me.ts
|
|
1734
866
|
var MeResource = class extends BaseResource {
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
*/
|
|
1738
|
-
async retrieve() {
|
|
1739
|
-
return this.client.get("/me");
|
|
867
|
+
async get() {
|
|
868
|
+
return this.unwrap(this.untypedApi.GET("/me", {}));
|
|
1740
869
|
}
|
|
1741
870
|
};
|
|
1742
871
|
|
|
@@ -1745,206 +874,77 @@ var OrganizationResource = class extends BaseResource {
|
|
|
1745
874
|
/**
|
|
1746
875
|
* Get organization details
|
|
1747
876
|
*/
|
|
1748
|
-
async
|
|
1749
|
-
return this.
|
|
877
|
+
async get() {
|
|
878
|
+
return this.unwrap(this.api.GET("/organization"));
|
|
1750
879
|
}
|
|
1751
880
|
};
|
|
1752
881
|
|
|
1753
882
|
// src/resources/agents.ts
|
|
1754
883
|
var AgentsResource = class extends BaseResource {
|
|
1755
|
-
/**
|
|
1756
|
-
* List support agents
|
|
1757
|
-
*/
|
|
1758
884
|
async list() {
|
|
1759
|
-
return this.
|
|
885
|
+
return this.unwrap(this.untypedApi.GET("/agents", {}));
|
|
1760
886
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
*/
|
|
1764
|
-
async retrieve(agentId) {
|
|
1765
|
-
return this.get(`/agents/${agentId}`);
|
|
887
|
+
async get(agentId) {
|
|
888
|
+
return this.unwrap(this.untypedApi.GET("/agents/{id}", { params: { path: { id: agentId } } }));
|
|
1766
889
|
}
|
|
1767
|
-
/**
|
|
1768
|
-
* Create a new agent
|
|
1769
|
-
*/
|
|
1770
890
|
async create(params) {
|
|
1771
|
-
return this.
|
|
891
|
+
return this.unwrap(this.untypedApi.POST("/agents", { body: params }));
|
|
1772
892
|
}
|
|
1773
|
-
/**
|
|
1774
|
-
* Find an existing agent by email, or create one if not found.
|
|
1775
|
-
* This is useful for sync operations where you want to ensure
|
|
1776
|
-
* an agent exists without duplicating.
|
|
1777
|
-
*
|
|
1778
|
-
* @param params - Agent data (email required, name optional)
|
|
1779
|
-
* @returns The existing or newly created agent
|
|
1780
|
-
*/
|
|
1781
893
|
async findOrCreate(params) {
|
|
1782
|
-
|
|
1783
|
-
return await this.create(params);
|
|
1784
|
-
} catch (error) {
|
|
1785
|
-
if (error instanceof MantleAPIError && error.statusCode === 409) {
|
|
1786
|
-
const { agents } = await this.list();
|
|
1787
|
-
const existingAgent = agents.find(
|
|
1788
|
-
(agent) => agent.email.toLowerCase() === params.email.toLowerCase()
|
|
1789
|
-
);
|
|
1790
|
-
if (existingAgent) {
|
|
1791
|
-
return { agent: existingAgent };
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
throw error;
|
|
1795
|
-
}
|
|
894
|
+
return this.unwrap(this.untypedApi.POST("/agents/find_or_create", { body: params }));
|
|
1796
895
|
}
|
|
1797
896
|
};
|
|
1798
897
|
|
|
1799
898
|
// src/resources/docs.ts
|
|
1800
899
|
var DocsResource = class extends BaseResource {
|
|
1801
|
-
//
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
*/
|
|
1805
|
-
async listCollections() {
|
|
1806
|
-
return this.get("/docs/collections");
|
|
900
|
+
// Collections
|
|
901
|
+
async listCollections(params) {
|
|
902
|
+
return this.unwrap(this.api.GET("/docs/collections", { params: { query: params } }));
|
|
1807
903
|
}
|
|
1808
|
-
/**
|
|
1809
|
-
* Retrieve a single doc collection
|
|
1810
|
-
*/
|
|
1811
|
-
async retrieveCollection(collectionId) {
|
|
1812
|
-
return this.get(
|
|
1813
|
-
`/docs/collections/${collectionId}`
|
|
1814
|
-
);
|
|
1815
|
-
}
|
|
1816
|
-
/**
|
|
1817
|
-
* Create a new doc collection
|
|
1818
|
-
*/
|
|
1819
904
|
async createCollection(data) {
|
|
1820
|
-
return this.
|
|
905
|
+
return this.unwrap(this.api.POST("/docs/collections", { body: data }));
|
|
1821
906
|
}
|
|
1822
|
-
/**
|
|
1823
|
-
* Update a doc collection
|
|
1824
|
-
*/
|
|
1825
907
|
async updateCollection(collectionId, data) {
|
|
1826
|
-
return this.
|
|
1827
|
-
`/docs/collections/${collectionId}`,
|
|
1828
|
-
data
|
|
1829
|
-
);
|
|
908
|
+
return this.unwrap(this.api.PUT("/docs/collections/{collection_id}", { params: { path: { collection_id: collectionId } }, body: data }));
|
|
1830
909
|
}
|
|
1831
|
-
/**
|
|
1832
|
-
* Delete a doc collection
|
|
1833
|
-
*/
|
|
1834
910
|
async deleteCollection(collectionId) {
|
|
1835
|
-
return this.
|
|
1836
|
-
}
|
|
1837
|
-
// ========== Groups ==========
|
|
1838
|
-
/**
|
|
1839
|
-
* List all doc groups
|
|
1840
|
-
*/
|
|
1841
|
-
async listGroups() {
|
|
1842
|
-
return this.get("/docs/groups");
|
|
911
|
+
return this.unwrap(this.api.DELETE("/docs/collections/{collection_id}", { params: { path: { collection_id: collectionId } } }));
|
|
1843
912
|
}
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
async retrieveGroup(groupId) {
|
|
1848
|
-
return this.get(`/docs/groups/${groupId}`);
|
|
913
|
+
// Groups
|
|
914
|
+
async listGroups(params) {
|
|
915
|
+
return this.unwrap(this.api.GET("/docs/groups", { params: { query: params } }));
|
|
1849
916
|
}
|
|
1850
|
-
/**
|
|
1851
|
-
* Create a new doc group
|
|
1852
|
-
*/
|
|
1853
917
|
async createGroup(data) {
|
|
1854
|
-
return this.
|
|
918
|
+
return this.unwrap(this.api.POST("/docs/groups", { body: data }));
|
|
1855
919
|
}
|
|
1856
|
-
/**
|
|
1857
|
-
* Update a doc group
|
|
1858
|
-
*/
|
|
1859
920
|
async updateGroup(groupId, data) {
|
|
1860
|
-
return this.
|
|
921
|
+
return this.unwrap(this.api.PUT("/docs/groups/{group_id}", { params: { path: { group_id: groupId } }, body: data }));
|
|
1861
922
|
}
|
|
1862
|
-
/**
|
|
1863
|
-
* Delete a doc group
|
|
1864
|
-
*/
|
|
1865
923
|
async deleteGroup(groupId) {
|
|
1866
|
-
return this.
|
|
924
|
+
return this.unwrap(this.api.DELETE("/docs/groups/{group_id}", { params: { path: { group_id: groupId } } }));
|
|
1867
925
|
}
|
|
1868
|
-
//
|
|
1869
|
-
/**
|
|
1870
|
-
* List doc pages with optional filters
|
|
1871
|
-
*/
|
|
926
|
+
// Pages
|
|
1872
927
|
async listPages(params) {
|
|
1873
|
-
|
|
1874
|
-
return {
|
|
1875
|
-
pages: response.pages || [],
|
|
1876
|
-
hasNextPage: response.hasNextPage || false,
|
|
1877
|
-
hasPreviousPage: response.hasPreviousPage || false
|
|
1878
|
-
};
|
|
928
|
+
return this.unwrap(this.api.GET("/docs/pages", { params: { query: params } }));
|
|
1879
929
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
*/
|
|
1883
|
-
async retrievePage(pageId) {
|
|
1884
|
-
return this.get(`/docs/pages/${pageId}`);
|
|
930
|
+
async getPage(pageId) {
|
|
931
|
+
return this.unwrap(this.api.GET("/docs/pages/{page_id}", { params: { path: { page_id: pageId } } }));
|
|
1885
932
|
}
|
|
1886
|
-
/**
|
|
1887
|
-
* Create a new doc page
|
|
1888
|
-
*/
|
|
1889
933
|
async createPage(data) {
|
|
1890
|
-
return this.
|
|
934
|
+
return this.unwrap(this.api.POST("/docs/pages", { body: data }));
|
|
1891
935
|
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Update a doc page
|
|
1894
|
-
*/
|
|
1895
936
|
async updatePage(pageId, data) {
|
|
1896
|
-
return this.
|
|
937
|
+
return this.unwrap(this.api.PUT("/docs/pages/{page_id}", { params: { path: { page_id: pageId } }, body: data }));
|
|
1897
938
|
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Publish a doc page
|
|
1900
|
-
*/
|
|
1901
|
-
async publishPage(pageId) {
|
|
1902
|
-
return this.post(`/docs/pages/${pageId}/publish`, {});
|
|
1903
|
-
}
|
|
1904
|
-
/**
|
|
1905
|
-
* Archive a doc page
|
|
1906
|
-
*/
|
|
1907
|
-
async archivePage(pageId) {
|
|
1908
|
-
return this.post(`/docs/pages/${pageId}/archive`, {});
|
|
1909
|
-
}
|
|
1910
|
-
/**
|
|
1911
|
-
* Delete a doc page
|
|
1912
|
-
*/
|
|
1913
939
|
async deletePage(pageId) {
|
|
1914
|
-
return this.
|
|
1915
|
-
}
|
|
1916
|
-
// ========== Tree ==========
|
|
1917
|
-
/**
|
|
1918
|
-
* Get the full documentation tree structure
|
|
1919
|
-
*/
|
|
1920
|
-
async getTree() {
|
|
1921
|
-
return this.get("/docs/tree");
|
|
940
|
+
return this.unwrap(this.api.DELETE("/docs/pages/{page_id}", { params: { path: { page_id: pageId } } }));
|
|
1922
941
|
}
|
|
1923
|
-
//
|
|
1924
|
-
/**
|
|
1925
|
-
* List all doc repositories
|
|
1926
|
-
*/
|
|
942
|
+
// Repositories
|
|
1927
943
|
async listRepositories(params) {
|
|
1928
|
-
|
|
1929
|
-
"/docs/repositories",
|
|
1930
|
-
params
|
|
1931
|
-
);
|
|
1932
|
-
return {
|
|
1933
|
-
repositories: response.repositories || [],
|
|
1934
|
-
hasNextPage: response.hasNextPage || false,
|
|
1935
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1936
|
-
total: response.total,
|
|
1937
|
-
cursor: response.cursor
|
|
1938
|
-
};
|
|
944
|
+
return this.unwrap(this.api.GET("/docs/repositories", { params: { query: params } }));
|
|
1939
945
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
*/
|
|
1943
|
-
async retrieveRepository(repositoryId, params) {
|
|
1944
|
-
return this.get(
|
|
1945
|
-
`/docs/repositories/${repositoryId}`,
|
|
1946
|
-
params
|
|
1947
|
-
);
|
|
946
|
+
async getRepository(repositoryId, params) {
|
|
947
|
+
return this.unwrap(this.api.GET("/docs/repositories/{id}", { params: { path: { id: repositoryId }, query: params } }));
|
|
1948
948
|
}
|
|
1949
949
|
};
|
|
1950
950
|
|
|
@@ -1955,50 +955,17 @@ var EntitiesResource = class extends BaseResource {
|
|
|
1955
955
|
* Returns entities with a _type discriminator field
|
|
1956
956
|
*/
|
|
1957
957
|
async search(params) {
|
|
1958
|
-
|
|
1959
|
-
return {
|
|
1960
|
-
entities: response.entities || [],
|
|
1961
|
-
hasNextPage: response.hasNextPage || false,
|
|
1962
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
1963
|
-
total: response.total,
|
|
1964
|
-
cursor: response.cursor
|
|
1965
|
-
};
|
|
958
|
+
return this.unwrap(this.api.GET("/entities", { params: { query: params } }));
|
|
1966
959
|
}
|
|
1967
960
|
};
|
|
1968
961
|
|
|
1969
962
|
// src/resources/custom-data.ts
|
|
1970
963
|
var CustomDataResource = class extends BaseResource {
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
* This will create or update the value for the given key.
|
|
1974
|
-
*
|
|
1975
|
-
* @param params - The custom data parameters
|
|
1976
|
-
*/
|
|
1977
|
-
async set(params) {
|
|
1978
|
-
await this.put("/custom_data", params);
|
|
964
|
+
async set(data) {
|
|
965
|
+
return this.unwrap(this.api.PUT("/custom_data", { body: data }));
|
|
1979
966
|
}
|
|
1980
|
-
/**
|
|
1981
|
-
* Get custom data from a resource.
|
|
1982
|
-
*
|
|
1983
|
-
* @param params - Parameters identifying the custom data to retrieve
|
|
1984
|
-
* @returns The custom data value
|
|
1985
|
-
*/
|
|
1986
967
|
async getValue(params) {
|
|
1987
|
-
|
|
1988
|
-
return this.get(
|
|
1989
|
-
`/custom_data/${resourceType}/${resourceId}/${encodeURIComponent(key)}`
|
|
1990
|
-
);
|
|
1991
|
-
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Delete custom data from a resource.
|
|
1994
|
-
*
|
|
1995
|
-
* @param params - Parameters identifying the custom data to delete
|
|
1996
|
-
*/
|
|
1997
|
-
async del(params) {
|
|
1998
|
-
const { resourceType, resourceId, key } = params;
|
|
1999
|
-
await this._delete(
|
|
2000
|
-
`/custom_data/${resourceType}/${resourceId}/${encodeURIComponent(key)}`
|
|
2001
|
-
);
|
|
968
|
+
return this.unwrap(this.api.GET("/custom_data", { params: { query: params } }));
|
|
2002
969
|
}
|
|
2003
970
|
};
|
|
2004
971
|
|
|
@@ -2008,130 +975,56 @@ var TimelineCommentsResource = class extends BaseResource {
|
|
|
2008
975
|
* List timeline comments with optional filters and pagination
|
|
2009
976
|
*/
|
|
2010
977
|
async list(params) {
|
|
2011
|
-
|
|
2012
|
-
"/timeline_comments",
|
|
2013
|
-
params
|
|
2014
|
-
);
|
|
2015
|
-
return {
|
|
2016
|
-
timelineComments: response.timelineComments || [],
|
|
2017
|
-
hasNextPage: response.hasNextPage || false,
|
|
2018
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2019
|
-
total: response.total,
|
|
2020
|
-
cursor: response.cursor
|
|
2021
|
-
};
|
|
978
|
+
return this.unwrap(this.api.GET("/timeline_comments", { params: { query: params } }));
|
|
2022
979
|
}
|
|
2023
980
|
/**
|
|
2024
|
-
*
|
|
981
|
+
* Get a single timeline comment by ID
|
|
2025
982
|
*/
|
|
2026
|
-
async
|
|
2027
|
-
return this.
|
|
2028
|
-
`/timeline_comments/${id}`
|
|
2029
|
-
);
|
|
983
|
+
async get(id) {
|
|
984
|
+
return this.unwrap(this.api.GET("/timeline_comments/{id}", { params: { path: { id } } }));
|
|
2030
985
|
}
|
|
2031
986
|
/**
|
|
2032
987
|
* Create a new timeline comment
|
|
2033
988
|
*/
|
|
2034
989
|
async create(data) {
|
|
2035
|
-
return this.
|
|
990
|
+
return this.unwrap(this.api.POST("/timeline_comments", { body: data }));
|
|
2036
991
|
}
|
|
2037
992
|
/**
|
|
2038
993
|
* Update an existing timeline comment
|
|
2039
994
|
*/
|
|
2040
995
|
async update(id, data) {
|
|
2041
|
-
return this.
|
|
2042
|
-
`/timeline_comments/${id}`,
|
|
2043
|
-
data
|
|
2044
|
-
);
|
|
996
|
+
return this.unwrap(this.api.PUT("/timeline_comments/{id}", { params: { path: { id } }, body: data }));
|
|
2045
997
|
}
|
|
2046
998
|
/**
|
|
2047
999
|
* Delete a timeline comment
|
|
2048
1000
|
*/
|
|
2049
|
-
async del(id) {
|
|
2050
|
-
return this.
|
|
1001
|
+
async del(id, data) {
|
|
1002
|
+
return this.unwrap(this.api.DELETE("/timeline_comments/{id}", { params: { path: { id } }, body: data }));
|
|
2051
1003
|
}
|
|
2052
1004
|
};
|
|
2053
1005
|
|
|
2054
1006
|
// src/resources/lists.ts
|
|
2055
1007
|
var ListsResource = class extends BaseResource {
|
|
2056
|
-
/**
|
|
2057
|
-
* List all lists
|
|
2058
|
-
*
|
|
2059
|
-
* @param params - Optional list parameters
|
|
2060
|
-
* @returns Paginated list of lists
|
|
2061
|
-
*/
|
|
2062
1008
|
async list(params) {
|
|
2063
|
-
|
|
2064
|
-
return {
|
|
2065
|
-
lists: response.lists || [],
|
|
2066
|
-
hasNextPage: response.hasNextPage || false,
|
|
2067
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2068
|
-
total: response.total
|
|
2069
|
-
};
|
|
1009
|
+
return this.unwrap(this.api.GET("/lists", { params: { query: params } }));
|
|
2070
1010
|
}
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
*
|
|
2074
|
-
* @param listId - The ID of the list
|
|
2075
|
-
* @param params - Optional parameters to filter entities
|
|
2076
|
-
* @returns The list with its entities
|
|
2077
|
-
*/
|
|
2078
|
-
async retrieve(listId, params) {
|
|
2079
|
-
const response = await this.get(`/lists/${listId}`, params);
|
|
2080
|
-
return {
|
|
2081
|
-
list: response.list,
|
|
2082
|
-
entities: response.entities || [],
|
|
2083
|
-
hasNextPage: response.hasNextPage || false,
|
|
2084
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2085
|
-
total: response.total
|
|
2086
|
-
};
|
|
1011
|
+
async get(listId) {
|
|
1012
|
+
return this.unwrap(this.api.GET("/lists/{id}", { params: { path: { id: listId } } }));
|
|
2087
1013
|
}
|
|
2088
|
-
/**
|
|
2089
|
-
* Create a new list
|
|
2090
|
-
*
|
|
2091
|
-
* @param data - List creation parameters
|
|
2092
|
-
* @returns The created list
|
|
2093
|
-
*/
|
|
2094
1014
|
async create(data) {
|
|
2095
|
-
return this.
|
|
1015
|
+
return this.unwrap(this.api.POST("/lists", { body: data }));
|
|
2096
1016
|
}
|
|
2097
|
-
/**
|
|
2098
|
-
* Update an existing list
|
|
2099
|
-
*
|
|
2100
|
-
* @param listId - The ID of the list to update
|
|
2101
|
-
* @param data - List update parameters
|
|
2102
|
-
* @returns The updated list
|
|
2103
|
-
*/
|
|
2104
1017
|
async update(listId, data) {
|
|
2105
|
-
return this.
|
|
1018
|
+
return this.unwrap(this.api.PUT("/lists/{id}", { params: { path: { id: listId } }, body: data }));
|
|
2106
1019
|
}
|
|
2107
|
-
/**
|
|
2108
|
-
* Delete a list
|
|
2109
|
-
*
|
|
2110
|
-
* @param listId - The ID of the list to delete
|
|
2111
|
-
* @returns Delete confirmation
|
|
2112
|
-
*/
|
|
2113
1020
|
async del(listId) {
|
|
2114
|
-
return this.
|
|
1021
|
+
return this.unwrap(this.api.DELETE("/lists/{id}", { params: { path: { id: listId } } }));
|
|
2115
1022
|
}
|
|
2116
|
-
/**
|
|
2117
|
-
* Add customers and/or contacts to a list
|
|
2118
|
-
*
|
|
2119
|
-
* @param listId - The ID of the list
|
|
2120
|
-
* @param data - IDs of customers and/or contacts to add
|
|
2121
|
-
* @returns Count of added and skipped entities
|
|
2122
|
-
*/
|
|
2123
1023
|
async addEntities(listId, data) {
|
|
2124
|
-
return this.
|
|
1024
|
+
return this.unwrap(this.api.POST("/lists/{id}/add", { params: { path: { id: listId } }, body: data }));
|
|
2125
1025
|
}
|
|
2126
|
-
/**
|
|
2127
|
-
* Remove customers and/or contacts from a list
|
|
2128
|
-
*
|
|
2129
|
-
* @param listId - The ID of the list
|
|
2130
|
-
* @param data - IDs of customers and/or contacts to remove
|
|
2131
|
-
* @returns Count of removed entities
|
|
2132
|
-
*/
|
|
2133
1026
|
async removeEntities(listId, data) {
|
|
2134
|
-
return this.
|
|
1027
|
+
return this.unwrap(this.api.POST("/lists/{id}/remove", { params: { path: { id: listId } }, body: data }));
|
|
2135
1028
|
}
|
|
2136
1029
|
};
|
|
2137
1030
|
|
|
@@ -2141,566 +1034,172 @@ var JournalEntriesResource = class extends BaseResource {
|
|
|
2141
1034
|
* List journal entries with optional filters and pagination
|
|
2142
1035
|
*/
|
|
2143
1036
|
async list(params) {
|
|
2144
|
-
|
|
2145
|
-
"/journal_entries",
|
|
2146
|
-
params
|
|
2147
|
-
);
|
|
2148
|
-
return {
|
|
2149
|
-
journalEntries: response.journalEntries || [],
|
|
2150
|
-
hasNextPage: response.hasNextPage || false,
|
|
2151
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2152
|
-
total: response.total,
|
|
2153
|
-
cursor: response.cursor
|
|
2154
|
-
};
|
|
1037
|
+
return this.unwrap(this.api.GET("/journal_entries", { params: { query: params } }));
|
|
2155
1038
|
}
|
|
2156
1039
|
/**
|
|
2157
|
-
*
|
|
1040
|
+
* Get a single journal entry by ID
|
|
2158
1041
|
*/
|
|
2159
|
-
async
|
|
2160
|
-
return this.
|
|
2161
|
-
`/journal_entries/${entryId}`
|
|
2162
|
-
);
|
|
1042
|
+
async get(entryId, params) {
|
|
1043
|
+
return this.unwrap(this.api.GET("/journal_entries/{id}", { params: { path: { id: entryId }, query: params } }));
|
|
2163
1044
|
}
|
|
2164
1045
|
/**
|
|
2165
1046
|
* Create a new journal entry
|
|
2166
1047
|
*/
|
|
2167
1048
|
async create(data) {
|
|
2168
|
-
return this.
|
|
1049
|
+
return this.unwrap(this.api.POST("/journal_entries", { body: data }));
|
|
2169
1050
|
}
|
|
2170
1051
|
/**
|
|
2171
1052
|
* Update an existing journal entry
|
|
2172
1053
|
*/
|
|
2173
1054
|
async update(entryId, data) {
|
|
2174
|
-
return this.
|
|
2175
|
-
`/journal_entries/${entryId}`,
|
|
2176
|
-
data
|
|
2177
|
-
);
|
|
1055
|
+
return this.unwrap(this.api.PUT("/journal_entries/{id}", { params: { path: { id: entryId } }, body: data }));
|
|
2178
1056
|
}
|
|
2179
1057
|
/**
|
|
2180
1058
|
* Delete a journal entry
|
|
2181
1059
|
*/
|
|
2182
1060
|
async del(entryId) {
|
|
2183
|
-
return this.
|
|
1061
|
+
return this.unwrap(this.api.DELETE("/journal_entries/{id}", { params: { path: { id: entryId } } }));
|
|
2184
1062
|
}
|
|
2185
1063
|
};
|
|
2186
1064
|
|
|
2187
1065
|
// src/resources/email-unsubscribe-groups.ts
|
|
2188
1066
|
var EmailUnsubscribeGroupsResource = class extends BaseResource {
|
|
2189
|
-
/**
|
|
2190
|
-
* List all email unsubscribe groups
|
|
2191
|
-
*/
|
|
2192
1067
|
async list(params) {
|
|
2193
|
-
|
|
2194
|
-
"/email/unsubscribe_groups",
|
|
2195
|
-
params
|
|
2196
|
-
);
|
|
2197
|
-
return {
|
|
2198
|
-
unsubscribeGroups: response.unsubscribeGroups || [],
|
|
2199
|
-
hasNextPage: response.hasNextPage || false,
|
|
2200
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2201
|
-
total: response.total,
|
|
2202
|
-
cursor: response.cursor
|
|
2203
|
-
};
|
|
1068
|
+
return this.unwrap(this.api.GET("/email/unsubscribe_groups", { params: { query: params } }));
|
|
2204
1069
|
}
|
|
2205
|
-
/**
|
|
2206
|
-
* Retrieve a single unsubscribe group
|
|
2207
|
-
*/
|
|
2208
|
-
async retrieve(groupId) {
|
|
2209
|
-
return this.get(
|
|
2210
|
-
`/email/unsubscribe_groups/${groupId}`
|
|
2211
|
-
);
|
|
2212
|
-
}
|
|
2213
|
-
// ========== Members ==========
|
|
2214
|
-
/**
|
|
2215
|
-
* List members of an unsubscribe group
|
|
2216
|
-
*/
|
|
2217
1070
|
async listMembers(groupId, params) {
|
|
2218
|
-
|
|
2219
|
-
`/email/unsubscribe_groups/${groupId}/members`,
|
|
2220
|
-
params
|
|
2221
|
-
);
|
|
2222
|
-
return {
|
|
2223
|
-
members: response.members || [],
|
|
2224
|
-
hasNextPage: response.hasNextPage || false,
|
|
2225
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2226
|
-
total: response.total,
|
|
2227
|
-
cursor: response.cursor
|
|
2228
|
-
};
|
|
1071
|
+
return this.unwrap(this.api.GET("/email/unsubscribe_groups/{id}/members", { params: { path: { id: groupId }, query: params } }));
|
|
2229
1072
|
}
|
|
2230
|
-
/**
|
|
2231
|
-
* Add members to an unsubscribe group by email addresses
|
|
2232
|
-
*/
|
|
2233
1073
|
async addMembers(groupId, data) {
|
|
2234
|
-
return this.
|
|
2235
|
-
`/email/unsubscribe_groups/${groupId}/members`,
|
|
2236
|
-
data
|
|
2237
|
-
);
|
|
1074
|
+
return this.unwrap(this.api.POST("/email/unsubscribe_groups/{id}/members", { params: { path: { id: groupId } }, body: data }));
|
|
2238
1075
|
}
|
|
2239
|
-
/**
|
|
2240
|
-
* Remove members from an unsubscribe group by email addresses
|
|
2241
|
-
*/
|
|
2242
1076
|
async removeMembers(groupId, data) {
|
|
2243
|
-
return this.
|
|
2244
|
-
`/email/unsubscribe_groups/${groupId}/members?emails=${encodeURIComponent(data.emails.join(","))}`
|
|
2245
|
-
);
|
|
1077
|
+
return this.unwrap(this.api.DELETE("/email/unsubscribe_groups/{id}/members", { params: { path: { id: groupId } }, body: data }));
|
|
2246
1078
|
}
|
|
2247
|
-
/**
|
|
2248
|
-
* Remove a single member from an unsubscribe group by member ID
|
|
2249
|
-
*/
|
|
2250
1079
|
async removeMember(groupId, memberId) {
|
|
2251
|
-
return this.
|
|
2252
|
-
`/email/unsubscribe_groups/${groupId}/members/${memberId}`
|
|
2253
|
-
);
|
|
1080
|
+
return this.unwrap(this.api.DELETE("/email/unsubscribe_groups/{id}/members/{member_id}", { params: { path: { id: groupId, member_id: memberId } } }));
|
|
2254
1081
|
}
|
|
2255
1082
|
};
|
|
2256
1083
|
|
|
2257
1084
|
// src/resources/flow-extensions.ts
|
|
2258
1085
|
var FlowExtensionsResource = class extends BaseResource {
|
|
2259
|
-
//
|
|
2260
|
-
/**
|
|
2261
|
-
* List flow extension actions
|
|
2262
|
-
*/
|
|
1086
|
+
// Actions
|
|
2263
1087
|
async listActions(params) {
|
|
2264
|
-
|
|
2265
|
-
"/flow/extensions/actions",
|
|
2266
|
-
params
|
|
2267
|
-
);
|
|
2268
|
-
return {
|
|
2269
|
-
actions: response.actions || [],
|
|
2270
|
-
hasNextPage: response.hasNextPage || false,
|
|
2271
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2272
|
-
total: response.total,
|
|
2273
|
-
cursor: response.cursor
|
|
2274
|
-
};
|
|
1088
|
+
return this.unwrap(this.api.GET("/flow/extensions/actions", { params: { query: params } }));
|
|
2275
1089
|
}
|
|
2276
|
-
/**
|
|
2277
|
-
* Retrieve a single flow extension action
|
|
2278
|
-
*/
|
|
2279
|
-
async retrieveAction(actionId) {
|
|
2280
|
-
return this.get(
|
|
2281
|
-
`/flow/extensions/actions/${actionId}`
|
|
2282
|
-
);
|
|
2283
|
-
}
|
|
2284
|
-
/**
|
|
2285
|
-
* Create a new flow extension action
|
|
2286
|
-
*/
|
|
2287
1090
|
async createAction(data) {
|
|
2288
|
-
return this.
|
|
2289
|
-
"/flow/extensions/actions",
|
|
2290
|
-
data
|
|
2291
|
-
);
|
|
1091
|
+
return this.unwrap(this.api.POST("/flow/extensions/actions", { body: data }));
|
|
2292
1092
|
}
|
|
2293
|
-
/**
|
|
2294
|
-
* Update an existing flow extension action
|
|
2295
|
-
*/
|
|
2296
1093
|
async updateAction(actionId, data) {
|
|
2297
|
-
return this.
|
|
2298
|
-
`/flow/extensions/actions/${actionId}`,
|
|
2299
|
-
data
|
|
2300
|
-
);
|
|
1094
|
+
return this.unwrap(this.api.PUT("/flow/extensions/actions/{id}", { params: { path: { id: actionId } }, body: data }));
|
|
2301
1095
|
}
|
|
2302
|
-
/**
|
|
2303
|
-
* Delete a flow extension action
|
|
2304
|
-
*/
|
|
2305
1096
|
async deleteAction(actionId) {
|
|
2306
|
-
return this.
|
|
2307
|
-
`/flow/extensions/actions/${actionId}`
|
|
2308
|
-
);
|
|
1097
|
+
return this.unwrap(this.api.DELETE("/flow/extensions/actions/{id}", { params: { path: { id: actionId } } }));
|
|
2309
1098
|
}
|
|
2310
|
-
//
|
|
2311
|
-
/**
|
|
2312
|
-
* Update a flow action run status
|
|
2313
|
-
* Used to report completion or failure of async action execution
|
|
2314
|
-
*/
|
|
1099
|
+
// Action Runs
|
|
2315
1100
|
async updateActionRun(runId, data) {
|
|
2316
|
-
return this.
|
|
1101
|
+
return this.unwrap(this.api.PUT("/flow/actions/runs/{id}", { params: { path: { id: runId } }, body: data }));
|
|
1102
|
+
}
|
|
1103
|
+
// Triggers
|
|
1104
|
+
async listTriggers() {
|
|
1105
|
+
return this.unwrap(this.api.GET("/flow/extensions/triggers"));
|
|
1106
|
+
}
|
|
1107
|
+
async getTrigger(handle) {
|
|
1108
|
+
return this.unwrap(this.api.GET("/flow/extensions/triggers/{handle}", { params: { path: { handle } } }));
|
|
1109
|
+
}
|
|
1110
|
+
async createTrigger(data) {
|
|
1111
|
+
return this.unwrap(this.api.POST("/flow/extensions/triggers", { body: data }));
|
|
1112
|
+
}
|
|
1113
|
+
async updateTrigger(handle, data) {
|
|
1114
|
+
return this.unwrap(this.api.PUT("/flow/extensions/triggers/{handle}", { params: { path: { handle } }, body: data }));
|
|
1115
|
+
}
|
|
1116
|
+
async deleteTrigger(handle) {
|
|
1117
|
+
return this.unwrap(this.api.DELETE("/flow/extensions/triggers/{handle}", { params: { path: { handle } } }));
|
|
1118
|
+
}
|
|
1119
|
+
async fireTrigger(handle, data) {
|
|
1120
|
+
return this.unwrap(this.api.POST("/flow/extensions/triggers/{handle}/fire", { params: { path: { handle } }, body: data }));
|
|
2317
1121
|
}
|
|
2318
1122
|
};
|
|
2319
1123
|
|
|
2320
1124
|
// src/resources/ai-agent-runs.ts
|
|
2321
1125
|
var AiAgentRunsResource = class extends BaseResource {
|
|
2322
|
-
/**
|
|
2323
|
-
* Create a new AI agent run
|
|
2324
|
-
* Returns 202 Accepted as the run executes asynchronously
|
|
2325
|
-
* Poll the retrieve endpoint to check for completion
|
|
2326
|
-
*/
|
|
2327
1126
|
async create(agentId, data) {
|
|
2328
|
-
return this.
|
|
2329
|
-
`/ai/agents/${agentId}/runs`,
|
|
2330
|
-
data || {}
|
|
2331
|
-
);
|
|
1127
|
+
return this.unwrap(this.api.POST("/ai/agents/{agentId}/runs", { params: { path: { agentId } }, body: data }));
|
|
2332
1128
|
}
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
* Use this to poll for completion after creating a run
|
|
2336
|
-
*/
|
|
2337
|
-
async retrieve(agentId, runId) {
|
|
2338
|
-
return this.get(
|
|
2339
|
-
`/ai/agents/${agentId}/runs/${runId}`
|
|
2340
|
-
);
|
|
1129
|
+
async get(agentId, runId) {
|
|
1130
|
+
return this.unwrap(this.api.GET("/ai/agents/{agentId}/runs/{runId}", { params: { path: { agentId, runId } } }));
|
|
2341
1131
|
}
|
|
2342
1132
|
/**
|
|
2343
|
-
* Create
|
|
2344
|
-
* Convenience method that handles the async polling pattern
|
|
2345
|
-
*
|
|
2346
|
-
* @param agentId - The ID of the AI agent
|
|
2347
|
-
* @param data - Optional parameters for the run
|
|
2348
|
-
* @param options - Polling options
|
|
2349
|
-
* @returns The completed agent run
|
|
1133
|
+
* Create an agent run and poll until it completes or errors.
|
|
2350
1134
|
*/
|
|
2351
1135
|
async createAndWait(agentId, data, options) {
|
|
2352
|
-
const timeout = options
|
|
2353
|
-
const
|
|
2354
|
-
const
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
1136
|
+
const { timeout = 3e5, pollInterval = 2e3 } = options || {};
|
|
1137
|
+
const result = await this.create(agentId, data);
|
|
1138
|
+
const run = result.run;
|
|
1139
|
+
if (!run?.id) throw new Error("Agent run ID not returned");
|
|
1140
|
+
const start = Date.now();
|
|
1141
|
+
while (Date.now() - start < timeout) {
|
|
1142
|
+
const response = await this.get(agentId, run.id);
|
|
1143
|
+
const agentRun = response.run;
|
|
1144
|
+
if (agentRun.status === "completed" || agentRun.status === "error") {
|
|
1145
|
+
return agentRun;
|
|
2360
1146
|
}
|
|
2361
1147
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
2362
1148
|
}
|
|
2363
|
-
throw new Error(
|
|
2364
|
-
`Agent run ${run.id} did not complete within ${timeout}ms timeout`
|
|
2365
|
-
);
|
|
1149
|
+
throw new Error(`Agent run timed out after ${timeout}ms`);
|
|
2366
1150
|
}
|
|
2367
1151
|
};
|
|
2368
1152
|
|
|
2369
1153
|
// src/resources/meetings.ts
|
|
2370
1154
|
var MeetingsResource = class extends BaseResource {
|
|
2371
|
-
/**
|
|
2372
|
-
* List meetings with optional filters and pagination
|
|
2373
|
-
*
|
|
2374
|
-
* @param params - Filter and pagination parameters
|
|
2375
|
-
* @returns Paginated list of meetings
|
|
2376
|
-
*
|
|
2377
|
-
* @example
|
|
2378
|
-
* ```typescript
|
|
2379
|
-
* // List all meetings
|
|
2380
|
-
* const { meetings } = await client.meetings.list();
|
|
2381
|
-
*
|
|
2382
|
-
* // List meetings for a specific deal
|
|
2383
|
-
* const { meetings } = await client.meetings.list({ dealId: 'deal_123' });
|
|
2384
|
-
*
|
|
2385
|
-
* // List meetings from Google Meet
|
|
2386
|
-
* const { meetings } = await client.meetings.list({ platform: 'google_meet' });
|
|
2387
|
-
* ```
|
|
2388
|
-
*/
|
|
2389
1155
|
async list(params) {
|
|
2390
|
-
|
|
2391
|
-
return {
|
|
2392
|
-
meetings: response.meetings || [],
|
|
2393
|
-
hasNextPage: response.hasNextPage || false,
|
|
2394
|
-
hasPreviousPage: response.hasPreviousPage || false,
|
|
2395
|
-
total: response.total,
|
|
2396
|
-
page: response.page,
|
|
2397
|
-
totalPages: response.totalPages
|
|
2398
|
-
};
|
|
1156
|
+
return this.unwrap(this.api.GET("/meetings", { params: { query: params } }));
|
|
2399
1157
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
*
|
|
2403
|
-
* @param meetingId - The meeting ID
|
|
2404
|
-
* @returns The meeting with all related data
|
|
2405
|
-
*
|
|
2406
|
-
* @example
|
|
2407
|
-
* ```typescript
|
|
2408
|
-
* const { meeting } = await client.meetings.retrieve('meeting_123');
|
|
2409
|
-
* console.log(meeting.transcript?.fullText);
|
|
2410
|
-
* ```
|
|
2411
|
-
*/
|
|
2412
|
-
async retrieve(meetingId) {
|
|
2413
|
-
return this.get(`/meetings/${meetingId}`);
|
|
1158
|
+
async get(meetingId) {
|
|
1159
|
+
return this.unwrap(this.api.GET("/meetings/{id}", { params: { path: { id: meetingId } } }));
|
|
2414
1160
|
}
|
|
2415
|
-
/**
|
|
2416
|
-
* Create a new meeting
|
|
2417
|
-
*
|
|
2418
|
-
* Typically called when a recording starts in the browser extension.
|
|
2419
|
-
* The meeting can be created with optional transcript and attendee data,
|
|
2420
|
-
* or these can be added later via transcription.
|
|
2421
|
-
*
|
|
2422
|
-
* @param data - Meeting creation parameters
|
|
2423
|
-
* @returns The created meeting
|
|
2424
|
-
*
|
|
2425
|
-
* @example
|
|
2426
|
-
* ```typescript
|
|
2427
|
-
* // Create meeting when recording starts
|
|
2428
|
-
* const meeting = await client.meetings.create({
|
|
2429
|
-
* meetingData: {
|
|
2430
|
-
* platform: 'zoom',
|
|
2431
|
-
* title: 'Weekly Sync',
|
|
2432
|
-
* meetingUrl: 'https://zoom.us/j/123456789',
|
|
2433
|
-
* startTime: new Date().toISOString(),
|
|
2434
|
-
* recordingStatus: 'pending',
|
|
2435
|
-
* }
|
|
2436
|
-
* });
|
|
2437
|
-
*
|
|
2438
|
-
* // Create meeting with transcript (from local transcription)
|
|
2439
|
-
* const meeting = await client.meetings.create({
|
|
2440
|
-
* meetingData: { ... },
|
|
2441
|
-
* transcript: {
|
|
2442
|
-
* fullText: 'Hello, this is the transcript...',
|
|
2443
|
-
* utterances: [
|
|
2444
|
-
* { attendeeId: 'A', text: 'Hello', startTime: 0, endTime: 500 },
|
|
2445
|
-
* ],
|
|
2446
|
-
* },
|
|
2447
|
-
* attendees: [
|
|
2448
|
-
* { externalId: 'A', name: 'John Doe', email: 'john@example.com' },
|
|
2449
|
-
* ],
|
|
2450
|
-
* });
|
|
2451
|
-
* ```
|
|
2452
|
-
*/
|
|
2453
1161
|
async create(data) {
|
|
2454
|
-
return this.
|
|
1162
|
+
return this.unwrap(this.api.POST("/meetings", { body: data }));
|
|
2455
1163
|
}
|
|
2456
|
-
/**
|
|
2457
|
-
* Update an existing meeting
|
|
2458
|
-
*
|
|
2459
|
-
* @param meetingId - The meeting ID
|
|
2460
|
-
* @param data - Fields to update
|
|
2461
|
-
* @returns The updated meeting
|
|
2462
|
-
*
|
|
2463
|
-
* @example
|
|
2464
|
-
* ```typescript
|
|
2465
|
-
* // Update meeting title and link to a deal
|
|
2466
|
-
* const meeting = await client.meetings.update('meeting_123', {
|
|
2467
|
-
* title: 'Updated Meeting Title',
|
|
2468
|
-
* dealId: 'deal_456',
|
|
2469
|
-
* });
|
|
2470
|
-
* ```
|
|
2471
|
-
*/
|
|
2472
1164
|
async update(meetingId, data) {
|
|
2473
|
-
return this.
|
|
1165
|
+
return this.unwrap(this.api.PUT("/meetings/{id}", { params: { path: { id: meetingId } }, body: data }));
|
|
2474
1166
|
}
|
|
2475
|
-
/**
|
|
2476
|
-
* Archive (soft delete) a meeting
|
|
2477
|
-
*
|
|
2478
|
-
* @param meetingId - The meeting ID
|
|
2479
|
-
* @returns Success response
|
|
2480
|
-
*
|
|
2481
|
-
* @example
|
|
2482
|
-
* ```typescript
|
|
2483
|
-
* await client.meetings.del('meeting_123');
|
|
2484
|
-
* ```
|
|
2485
|
-
*/
|
|
2486
1167
|
async del(meetingId) {
|
|
2487
|
-
return this.
|
|
1168
|
+
return this.unwrap(this.api.DELETE("/meetings/{id}", { params: { path: { id: meetingId } } }));
|
|
2488
1169
|
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
*
|
|
2496
|
-
* @param meetingId - The meeting ID
|
|
2497
|
-
* @param filename - Optional filename (default: "recording.webm")
|
|
2498
|
-
* @returns Upload URL and recording key
|
|
2499
|
-
*
|
|
2500
|
-
* @example
|
|
2501
|
-
* ```typescript
|
|
2502
|
-
* const { uploadUrl, recordingKey } = await client.meetings.getUploadUrl('meeting_123');
|
|
2503
|
-
*
|
|
2504
|
-
* // Upload the recording blob directly to S3
|
|
2505
|
-
* const response = await fetch(uploadUrl, {
|
|
2506
|
-
* method: 'PUT',
|
|
2507
|
-
* body: recordingBlob,
|
|
2508
|
-
* headers: { 'Content-Type': 'audio/webm' },
|
|
2509
|
-
* });
|
|
2510
|
-
*
|
|
2511
|
-
* // Then start transcription
|
|
2512
|
-
* await client.meetings.startTranscription('meeting_123', { recordingKey });
|
|
2513
|
-
* ```
|
|
2514
|
-
*/
|
|
2515
|
-
async getUploadUrl(meetingId, filename) {
|
|
2516
|
-
return this.post(
|
|
2517
|
-
`/meetings/${meetingId}/transcribe/upload`,
|
|
2518
|
-
filename ? { filename } : {}
|
|
2519
|
-
);
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
// src/resources/synced-emails.ts
|
|
1173
|
+
var SyncedEmailsResource = class extends BaseResource {
|
|
1174
|
+
async list(params) {
|
|
1175
|
+
return this.unwrap(this.untypedApi.GET("/synced_emails", { params: { query: params } }));
|
|
2520
1176
|
}
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
*
|
|
2524
|
-
* The recording must first be uploaded using the URL from `getUploadUrl`.
|
|
2525
|
-
* Transcription is processed asynchronously - poll `getTranscriptionStatus`
|
|
2526
|
-
* or retrieve the meeting to check for completion.
|
|
2527
|
-
*
|
|
2528
|
-
* @param meetingId - The meeting ID
|
|
2529
|
-
* @param params - Transcription parameters including the recording key
|
|
2530
|
-
* @returns The meeting with pending transcription status
|
|
2531
|
-
*
|
|
2532
|
-
* @example
|
|
2533
|
-
* ```typescript
|
|
2534
|
-
* // Start transcription after uploading
|
|
2535
|
-
* const meeting = await client.meetings.startTranscription('meeting_123', {
|
|
2536
|
-
* recordingKey: 'meeting-recordings/org-id/meeting-123/uuid/recording.webm',
|
|
2537
|
-
* });
|
|
2538
|
-
*
|
|
2539
|
-
* // meeting.recordingStatus will be 'pending' or 'processing'
|
|
2540
|
-
* ```
|
|
2541
|
-
*/
|
|
2542
|
-
async startTranscription(meetingId, params) {
|
|
2543
|
-
return this.post(`/meetings/${meetingId}/transcribe`, params);
|
|
1177
|
+
async get(syncedEmailId) {
|
|
1178
|
+
return this.unwrap(this.untypedApi.GET("/synced_emails/{id}", { params: { path: { id: syncedEmailId } } }));
|
|
2544
1179
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
*
|
|
2548
|
-
* Use this to poll for transcription completion after calling
|
|
2549
|
-
* `startTranscription`.
|
|
2550
|
-
*
|
|
2551
|
-
* @param meetingId - The meeting ID
|
|
2552
|
-
* @returns Current transcription status
|
|
2553
|
-
*
|
|
2554
|
-
* @example
|
|
2555
|
-
* ```typescript
|
|
2556
|
-
* // Poll for completion
|
|
2557
|
-
* const poll = async () => {
|
|
2558
|
-
* const status = await client.meetings.getTranscriptionStatus('meeting_123');
|
|
2559
|
-
*
|
|
2560
|
-
* if (status.recordingStatus === 'ready') {
|
|
2561
|
-
* // Transcription complete - fetch the full meeting
|
|
2562
|
-
* const meeting = await client.meetings.retrieve('meeting_123');
|
|
2563
|
-
* return meeting;
|
|
2564
|
-
* }
|
|
2565
|
-
*
|
|
2566
|
-
* if (status.recordingStatus === 'failed') {
|
|
2567
|
-
* throw new Error('Transcription failed');
|
|
2568
|
-
* }
|
|
2569
|
-
*
|
|
2570
|
-
* // Still processing - wait and retry
|
|
2571
|
-
* await new Promise(r => setTimeout(r, 5000));
|
|
2572
|
-
* return poll();
|
|
2573
|
-
* };
|
|
2574
|
-
* ```
|
|
2575
|
-
*/
|
|
2576
|
-
async getTranscriptionStatus(meetingId) {
|
|
2577
|
-
return this.get(
|
|
2578
|
-
`/meetings/${meetingId}/transcribe`
|
|
2579
|
-
);
|
|
1180
|
+
async create(data) {
|
|
1181
|
+
return this.unwrap(this.untypedApi.POST("/synced_emails", { body: data }));
|
|
2580
1182
|
}
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
*
|
|
2584
|
-
* Updates attendee details such as name or links the attendee to a Mantle contact.
|
|
2585
|
-
* This is useful for speaker identification in transcripts.
|
|
2586
|
-
*
|
|
2587
|
-
* @param meetingId - The meeting ID
|
|
2588
|
-
* @param attendeeId - The attendee ID (or externalId if useExternalId option is set)
|
|
2589
|
-
* @param data - Fields to update
|
|
2590
|
-
* @param options - Additional options
|
|
2591
|
-
* @param options.useExternalId - If true, treat attendeeId as the externalId (e.g., "A", "B" from browser extension)
|
|
2592
|
-
* @returns The updated attendee
|
|
2593
|
-
*
|
|
2594
|
-
* @example
|
|
2595
|
-
* ```typescript
|
|
2596
|
-
* // Update attendee name by server ID
|
|
2597
|
-
* const { attendee } = await client.meetings.updateAttendee(
|
|
2598
|
-
* 'meeting_123',
|
|
2599
|
-
* 'attendee_456',
|
|
2600
|
-
* { name: 'John Doe' }
|
|
2601
|
-
* );
|
|
2602
|
-
*
|
|
2603
|
-
* // Update attendee name by external ID (e.g., from browser extension)
|
|
2604
|
-
* const { attendee } = await client.meetings.updateAttendee(
|
|
2605
|
-
* 'meeting_123',
|
|
2606
|
-
* 'A',
|
|
2607
|
-
* { name: 'John Doe' },
|
|
2608
|
-
* { useExternalId: true }
|
|
2609
|
-
* );
|
|
2610
|
-
*
|
|
2611
|
-
* // Link attendee to a contact
|
|
2612
|
-
* const { attendee } = await client.meetings.updateAttendee(
|
|
2613
|
-
* 'meeting_123',
|
|
2614
|
-
* 'attendee_456',
|
|
2615
|
-
* { contactId: 'contact_789' }
|
|
2616
|
-
* );
|
|
2617
|
-
* ```
|
|
2618
|
-
*/
|
|
2619
|
-
async updateAttendee(meetingId, attendeeId, data, options) {
|
|
2620
|
-
const queryParams = options?.useExternalId ? "?useExternalId=true" : "";
|
|
2621
|
-
return this.put(
|
|
2622
|
-
`/meetings/${meetingId}/attendees/${attendeeId}${queryParams}`,
|
|
2623
|
-
data
|
|
2624
|
-
);
|
|
1183
|
+
async update(syncedEmailId, data) {
|
|
1184
|
+
return this.unwrap(this.untypedApi.PUT("/synced_emails/{id}", { params: { path: { id: syncedEmailId } }, body: data }));
|
|
2625
1185
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
*
|
|
2629
|
-
* Returns a temporary signed URL that can be used to play or download
|
|
2630
|
-
* the meeting recording. URLs expire after 1 hour.
|
|
2631
|
-
*
|
|
2632
|
-
* @param meetingId - The meeting ID
|
|
2633
|
-
* @returns Signed URL and expiration info
|
|
2634
|
-
*
|
|
2635
|
-
* @example
|
|
2636
|
-
* ```typescript
|
|
2637
|
-
* const { recordingUrl, expiresIn } = await client.meetings.getRecordingUrl('meeting_123');
|
|
2638
|
-
*
|
|
2639
|
-
* // Use the URL in an audio/video element
|
|
2640
|
-
* audioElement.src = recordingUrl;
|
|
2641
|
-
* ```
|
|
2642
|
-
*/
|
|
2643
|
-
async getRecordingUrl(meetingId) {
|
|
2644
|
-
return this.get(
|
|
2645
|
-
`/meetings/${meetingId}/recording-url`
|
|
2646
|
-
);
|
|
1186
|
+
async del(syncedEmailId) {
|
|
1187
|
+
return this.unwrap(this.untypedApi.DELETE("/synced_emails/{id}", { params: { path: { id: syncedEmailId } } }));
|
|
2647
1188
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
*
|
|
2651
|
-
* Creates a real Task from the suggestion. Optional overrides allow
|
|
2652
|
-
* modifying the title, description, priority, due date, or assignee
|
|
2653
|
-
* before creating the task.
|
|
2654
|
-
*
|
|
2655
|
-
* @param meetingId - The meeting ID
|
|
2656
|
-
* @param suggestionId - The task suggestion ID
|
|
2657
|
-
* @param overrides - Optional fields to override on the created task
|
|
2658
|
-
* @returns The created task and updated suggestion
|
|
2659
|
-
*
|
|
2660
|
-
* @example
|
|
2661
|
-
* ```typescript
|
|
2662
|
-
* // Accept a suggestion as-is
|
|
2663
|
-
* const { task, suggestion } = await client.meetings.acceptTaskSuggestion(
|
|
2664
|
-
* 'meeting_123',
|
|
2665
|
-
* 'suggestion_456'
|
|
2666
|
-
* );
|
|
2667
|
-
*
|
|
2668
|
-
* // Accept with overrides
|
|
2669
|
-
* const { task } = await client.meetings.acceptTaskSuggestion(
|
|
2670
|
-
* 'meeting_123',
|
|
2671
|
-
* 'suggestion_456',
|
|
2672
|
-
* { title: 'Custom title', priority: 'high' }
|
|
2673
|
-
* );
|
|
2674
|
-
* ```
|
|
2675
|
-
*/
|
|
2676
|
-
async acceptTaskSuggestion(meetingId, suggestionId, overrides) {
|
|
2677
|
-
return this.post(
|
|
2678
|
-
`/meetings/${meetingId}/task-suggestions/${suggestionId}/accept`,
|
|
2679
|
-
overrides || {}
|
|
2680
|
-
);
|
|
1189
|
+
async addMessages(syncedEmailId, data) {
|
|
1190
|
+
return this.unwrap(this.untypedApi.POST("/synced_emails/{id}/messages", { params: { path: { id: syncedEmailId } }, body: data }));
|
|
2681
1191
|
}
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
*
|
|
2685
|
-
* Marks the suggestion as dismissed so it no longer appears as pending.
|
|
2686
|
-
*
|
|
2687
|
-
* @param meetingId - The meeting ID
|
|
2688
|
-
* @param suggestionId - The task suggestion ID
|
|
2689
|
-
* @returns Success response
|
|
2690
|
-
*
|
|
2691
|
-
* @example
|
|
2692
|
-
* ```typescript
|
|
2693
|
-
* await client.meetings.dismissTaskSuggestion('meeting_123', 'suggestion_456');
|
|
2694
|
-
* ```
|
|
2695
|
-
*/
|
|
2696
|
-
async dismissTaskSuggestion(meetingId, suggestionId) {
|
|
2697
|
-
return this.post(
|
|
2698
|
-
`/meetings/${meetingId}/task-suggestions/${suggestionId}/dismiss`
|
|
2699
|
-
);
|
|
1192
|
+
async getMessages(syncedEmailId) {
|
|
1193
|
+
return this.unwrap(this.untypedApi.GET("/synced_emails/{id}/messages", { params: { path: { id: syncedEmailId } } }));
|
|
2700
1194
|
}
|
|
2701
1195
|
};
|
|
2702
1196
|
|
|
2703
1197
|
// src/client.ts
|
|
1198
|
+
function createTimeoutSignal(ms) {
|
|
1199
|
+
const controller = new AbortController();
|
|
1200
|
+
setTimeout(() => controller.abort(), ms);
|
|
1201
|
+
return controller.signal;
|
|
1202
|
+
}
|
|
2704
1203
|
var MantleCoreClient = class {
|
|
2705
1204
|
constructor(config) {
|
|
2706
1205
|
if (!config.apiKey && !config.accessToken) {
|
|
@@ -2708,18 +1207,35 @@ var MantleCoreClient = class {
|
|
|
2708
1207
|
"MantleCoreClient requires either apiKey or accessToken"
|
|
2709
1208
|
);
|
|
2710
1209
|
}
|
|
2711
|
-
this.baseURL = config.baseURL || "https://api.heymantle.com/v1";
|
|
2712
1210
|
this.apiKey = config.apiKey;
|
|
2713
1211
|
this.accessToken = config.accessToken;
|
|
2714
|
-
|
|
2715
|
-
this.
|
|
1212
|
+
const timeoutMs = config.timeout ?? 3e4;
|
|
1213
|
+
this._api = (0, import_openapi_fetch.default)({
|
|
1214
|
+
baseUrl: config.baseURL || "https://api.heymantle.com/v1",
|
|
1215
|
+
headers: {
|
|
1216
|
+
"Content-Type": "application/json"
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
this._api.use({
|
|
1220
|
+
onRequest: ({ request }) => {
|
|
1221
|
+
const token = this.accessToken || this.apiKey;
|
|
1222
|
+
if (token) {
|
|
1223
|
+
request.headers.set("Authorization", `Bearer ${token}`);
|
|
1224
|
+
}
|
|
1225
|
+
return request;
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
if (timeoutMs > 0) {
|
|
1229
|
+
this._api.use({
|
|
1230
|
+
onRequest: ({ request }) => {
|
|
1231
|
+
const signal = typeof AbortSignal !== "undefined" && "timeout" in AbortSignal ? AbortSignal.timeout(timeoutMs) : createTimeoutSignal(timeoutMs);
|
|
1232
|
+
return new Request(request, { signal });
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
2716
1236
|
if (config.middleware) {
|
|
2717
1237
|
for (const mw of config.middleware) {
|
|
2718
|
-
|
|
2719
|
-
this.middlewareManager.use(mw[0], mw[1]);
|
|
2720
|
-
} else {
|
|
2721
|
-
this.middlewareManager.use(mw);
|
|
2722
|
-
}
|
|
1238
|
+
this._api.use(mw);
|
|
2723
1239
|
}
|
|
2724
1240
|
}
|
|
2725
1241
|
this.customers = new CustomersResource(this);
|
|
@@ -2759,41 +1275,24 @@ var MantleCoreClient = class {
|
|
|
2759
1275
|
this.flowExtensions = new FlowExtensionsResource(this);
|
|
2760
1276
|
this.aiAgentRuns = new AiAgentRunsResource(this);
|
|
2761
1277
|
this.meetings = new MeetingsResource(this);
|
|
1278
|
+
this.syncedEmails = new SyncedEmailsResource(this);
|
|
2762
1279
|
}
|
|
2763
1280
|
/**
|
|
2764
|
-
* Register
|
|
2765
|
-
*
|
|
2766
|
-
* @param middleware - The middleware function to register
|
|
2767
|
-
* @param options - Optional configuration (name, priority)
|
|
2768
|
-
* @returns this for chaining
|
|
2769
|
-
*
|
|
2770
|
-
* @example
|
|
2771
|
-
* ```typescript
|
|
2772
|
-
* client.use(async (ctx, next) => {
|
|
2773
|
-
* console.log('Request:', ctx.request.url);
|
|
2774
|
-
* await next();
|
|
2775
|
-
* console.log('Response:', ctx.response?.status);
|
|
2776
|
-
* });
|
|
2777
|
-
* ```
|
|
1281
|
+
* Register an openapi-fetch middleware
|
|
2778
1282
|
*/
|
|
2779
|
-
use(middleware
|
|
2780
|
-
this.
|
|
1283
|
+
use(middleware) {
|
|
1284
|
+
this._api.use(middleware);
|
|
2781
1285
|
return this;
|
|
2782
1286
|
}
|
|
2783
1287
|
/**
|
|
2784
|
-
* Remove a middleware
|
|
2785
|
-
*
|
|
2786
|
-
* @param name - The name of the middleware to remove
|
|
2787
|
-
* @returns true if removed, false if not found
|
|
1288
|
+
* Remove a registered middleware
|
|
2788
1289
|
*/
|
|
2789
|
-
|
|
2790
|
-
|
|
1290
|
+
eject(middleware) {
|
|
1291
|
+
this._api.eject(middleware);
|
|
1292
|
+
return this;
|
|
2791
1293
|
}
|
|
2792
1294
|
/**
|
|
2793
1295
|
* Update authentication credentials
|
|
2794
|
-
* Useful for middleware that needs to refresh tokens
|
|
2795
|
-
*
|
|
2796
|
-
* @param credentials - New credentials to set
|
|
2797
1296
|
*/
|
|
2798
1297
|
updateAuth(credentials) {
|
|
2799
1298
|
if (credentials.apiKey !== void 0) {
|
|
@@ -2803,234 +1302,43 @@ var MantleCoreClient = class {
|
|
|
2803
1302
|
this.accessToken = credentials.accessToken;
|
|
2804
1303
|
}
|
|
2805
1304
|
}
|
|
2806
|
-
/**
|
|
2807
|
-
* Performs a GET request to the API
|
|
2808
|
-
*/
|
|
2809
|
-
async get(endpoint, params) {
|
|
2810
|
-
const sanitizedParams = params ? sanitizeObject(params) : {};
|
|
2811
|
-
const query = toQueryString(sanitizedParams);
|
|
2812
|
-
const url = query ? `${endpoint}?${query}` : endpoint;
|
|
2813
|
-
return this.makeRequest(url, { method: "GET" });
|
|
2814
|
-
}
|
|
2815
|
-
/**
|
|
2816
|
-
* Performs a POST request to the API
|
|
2817
|
-
*/
|
|
2818
|
-
async post(endpoint, data) {
|
|
2819
|
-
const sanitizedData = data ? sanitizeObject(data) : {};
|
|
2820
|
-
return this.makeRequest(endpoint, {
|
|
2821
|
-
method: "POST",
|
|
2822
|
-
body: JSON.stringify(sanitizedData)
|
|
2823
|
-
});
|
|
2824
|
-
}
|
|
2825
|
-
/**
|
|
2826
|
-
* Performs a PUT request to the API
|
|
2827
|
-
*/
|
|
2828
|
-
async put(endpoint, data) {
|
|
2829
|
-
const sanitizedData = data ? sanitizeObject(data) : {};
|
|
2830
|
-
return this.makeRequest(endpoint, {
|
|
2831
|
-
method: "PUT",
|
|
2832
|
-
body: JSON.stringify(sanitizedData)
|
|
2833
|
-
});
|
|
2834
|
-
}
|
|
2835
|
-
/**
|
|
2836
|
-
* Performs a DELETE request to the API
|
|
2837
|
-
*/
|
|
2838
|
-
async delete(endpoint) {
|
|
2839
|
-
return this.makeRequest(endpoint, { method: "DELETE" });
|
|
2840
|
-
}
|
|
2841
|
-
/**
|
|
2842
|
-
* Makes an HTTP request to the API
|
|
2843
|
-
*/
|
|
2844
|
-
async makeRequest(endpoint, options) {
|
|
2845
|
-
if (this.middlewareManager.hasMiddleware()) {
|
|
2846
|
-
return this.makeRequestWithMiddleware(endpoint, options);
|
|
2847
|
-
}
|
|
2848
|
-
return this.executeRequest(endpoint, options);
|
|
2849
|
-
}
|
|
2850
|
-
/**
|
|
2851
|
-
* Execute request through middleware chain
|
|
2852
|
-
*/
|
|
2853
|
-
async makeRequestWithMiddleware(endpoint, options) {
|
|
2854
|
-
const request = {
|
|
2855
|
-
url: `${this.baseURL}${endpoint}`,
|
|
2856
|
-
method: options.method,
|
|
2857
|
-
headers: {
|
|
2858
|
-
Authorization: this.getAuthHeader(),
|
|
2859
|
-
"Content-Type": "application/json",
|
|
2860
|
-
...options.headers
|
|
2861
|
-
},
|
|
2862
|
-
body: options.body,
|
|
2863
|
-
endpoint
|
|
2864
|
-
};
|
|
2865
|
-
const ctx = {
|
|
2866
|
-
request,
|
|
2867
|
-
retry: false,
|
|
2868
|
-
retryCount: 0,
|
|
2869
|
-
maxRetries: 3,
|
|
2870
|
-
updateAuth: (credentials) => this.updateAuth(credentials)
|
|
2871
|
-
};
|
|
2872
|
-
const coreHandler = async () => {
|
|
2873
|
-
const controller = new AbortController();
|
|
2874
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
2875
|
-
try {
|
|
2876
|
-
const response2 = await fetch(ctx.request.url, {
|
|
2877
|
-
method: ctx.request.method,
|
|
2878
|
-
body: ctx.request.body,
|
|
2879
|
-
headers: ctx.request.headers,
|
|
2880
|
-
signal: controller.signal
|
|
2881
|
-
});
|
|
2882
|
-
clearTimeout(timeoutId);
|
|
2883
|
-
if (!response2.ok) {
|
|
2884
|
-
await this.handleErrorResponse(response2);
|
|
2885
|
-
}
|
|
2886
|
-
const text = await response2.text();
|
|
2887
|
-
const data = text ? JSON.parse(text) : {};
|
|
2888
|
-
return {
|
|
2889
|
-
data,
|
|
2890
|
-
status: response2.status,
|
|
2891
|
-
headers: response2.headers
|
|
2892
|
-
};
|
|
2893
|
-
} catch (error) {
|
|
2894
|
-
clearTimeout(timeoutId);
|
|
2895
|
-
if (error instanceof MantleAPIError) {
|
|
2896
|
-
throw error;
|
|
2897
|
-
}
|
|
2898
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
2899
|
-
throw new MantleAPIError("Request timeout", 408);
|
|
2900
|
-
}
|
|
2901
|
-
throw new MantleAPIError(
|
|
2902
|
-
error instanceof Error ? error.message : "Unknown error occurred",
|
|
2903
|
-
500
|
|
2904
|
-
);
|
|
2905
|
-
}
|
|
2906
|
-
};
|
|
2907
|
-
const response = await this.middlewareManager.execute(ctx, coreHandler);
|
|
2908
|
-
return response.data;
|
|
2909
|
-
}
|
|
2910
|
-
/**
|
|
2911
|
-
* Direct request execution (no middleware)
|
|
2912
|
-
*/
|
|
2913
|
-
async executeRequest(endpoint, options) {
|
|
2914
|
-
const authHeader = this.getAuthHeader();
|
|
2915
|
-
const controller = new AbortController();
|
|
2916
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
2917
|
-
try {
|
|
2918
|
-
const response = await fetch(`${this.baseURL}${endpoint}`, {
|
|
2919
|
-
method: options.method,
|
|
2920
|
-
body: options.body,
|
|
2921
|
-
headers: {
|
|
2922
|
-
Authorization: authHeader,
|
|
2923
|
-
"Content-Type": "application/json",
|
|
2924
|
-
...options.headers
|
|
2925
|
-
},
|
|
2926
|
-
signal: controller.signal
|
|
2927
|
-
});
|
|
2928
|
-
clearTimeout(timeoutId);
|
|
2929
|
-
if (!response.ok) {
|
|
2930
|
-
await this.handleErrorResponse(response);
|
|
2931
|
-
}
|
|
2932
|
-
const text = await response.text();
|
|
2933
|
-
if (!text) {
|
|
2934
|
-
return {};
|
|
2935
|
-
}
|
|
2936
|
-
return JSON.parse(text);
|
|
2937
|
-
} catch (error) {
|
|
2938
|
-
clearTimeout(timeoutId);
|
|
2939
|
-
if (error instanceof MantleAPIError) {
|
|
2940
|
-
throw error;
|
|
2941
|
-
}
|
|
2942
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
2943
|
-
throw new MantleAPIError("Request timeout", 408);
|
|
2944
|
-
}
|
|
2945
|
-
throw new MantleAPIError(
|
|
2946
|
-
error instanceof Error ? error.message : "Unknown error occurred",
|
|
2947
|
-
500
|
|
2948
|
-
);
|
|
2949
|
-
}
|
|
2950
|
-
}
|
|
2951
|
-
/**
|
|
2952
|
-
* Gets the authorization header value
|
|
2953
|
-
*/
|
|
2954
|
-
getAuthHeader() {
|
|
2955
|
-
if (this.accessToken) {
|
|
2956
|
-
return `Bearer ${this.accessToken}`;
|
|
2957
|
-
}
|
|
2958
|
-
if (this.apiKey) {
|
|
2959
|
-
return `Bearer ${this.apiKey}`;
|
|
2960
|
-
}
|
|
2961
|
-
throw new MantleAuthenticationError(
|
|
2962
|
-
"Authentication not configured. Please set up API key or OAuth."
|
|
2963
|
-
);
|
|
2964
|
-
}
|
|
2965
|
-
/**
|
|
2966
|
-
* Handles error responses from the API
|
|
2967
|
-
*/
|
|
2968
|
-
async handleErrorResponse(response) {
|
|
2969
|
-
let errorData = {};
|
|
2970
|
-
try {
|
|
2971
|
-
const text = await response.text();
|
|
2972
|
-
if (text) {
|
|
2973
|
-
errorData = JSON.parse(text);
|
|
2974
|
-
}
|
|
2975
|
-
} catch {
|
|
2976
|
-
}
|
|
2977
|
-
const message = errorData.error || `API request failed: ${response.status}`;
|
|
2978
|
-
switch (response.status) {
|
|
2979
|
-
case 401:
|
|
2980
|
-
throw new MantleAuthenticationError(message);
|
|
2981
|
-
case 403:
|
|
2982
|
-
throw new MantlePermissionError(message);
|
|
2983
|
-
case 404:
|
|
2984
|
-
throw new MantleAPIError(message, 404, errorData.details);
|
|
2985
|
-
case 422:
|
|
2986
|
-
throw new MantleValidationError(message, errorData.details);
|
|
2987
|
-
case 429: {
|
|
2988
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
2989
|
-
throw new MantleRateLimitError(
|
|
2990
|
-
message,
|
|
2991
|
-
retryAfter ? parseInt(retryAfter, 10) : void 0
|
|
2992
|
-
);
|
|
2993
|
-
}
|
|
2994
|
-
default:
|
|
2995
|
-
throw new MantleAPIError(message, response.status, errorData.details);
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
1305
|
};
|
|
2999
1306
|
|
|
3000
1307
|
// src/middleware/auth-refresh.ts
|
|
3001
1308
|
function createAuthRefreshMiddleware(options) {
|
|
3002
1309
|
const {
|
|
3003
1310
|
refreshToken,
|
|
1311
|
+
updateAuth,
|
|
3004
1312
|
onRefreshSuccess,
|
|
3005
1313
|
onRefreshFailed,
|
|
3006
1314
|
maxRefreshAttempts = 1
|
|
3007
1315
|
} = options;
|
|
3008
1316
|
let refreshAttempts = 0;
|
|
3009
|
-
return
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
} catch (error) {
|
|
3013
|
-
if (!(error instanceof MantleAuthenticationError)) {
|
|
3014
|
-
throw error;
|
|
3015
|
-
}
|
|
1317
|
+
return {
|
|
1318
|
+
async onResponse({ request, response }) {
|
|
1319
|
+
if (response.status !== 401) return void 0;
|
|
3016
1320
|
if (refreshAttempts >= maxRefreshAttempts) {
|
|
3017
1321
|
refreshAttempts = 0;
|
|
3018
|
-
|
|
1322
|
+
return void 0;
|
|
3019
1323
|
}
|
|
3020
1324
|
refreshAttempts++;
|
|
3021
1325
|
try {
|
|
3022
1326
|
const newToken = await refreshToken();
|
|
3023
|
-
|
|
3024
|
-
ctx.request.headers.Authorization = `Bearer ${newToken}`;
|
|
1327
|
+
updateAuth(newToken);
|
|
3025
1328
|
onRefreshSuccess?.(newToken);
|
|
3026
|
-
ctx.retry = true;
|
|
3027
1329
|
refreshAttempts = 0;
|
|
1330
|
+
const headers = new Headers(request.headers);
|
|
1331
|
+
headers.set("Authorization", `Bearer ${newToken}`);
|
|
1332
|
+
return fetch(new Request(request.url, {
|
|
1333
|
+
method: request.method,
|
|
1334
|
+
headers,
|
|
1335
|
+
body: request.body,
|
|
1336
|
+
signal: request.signal
|
|
1337
|
+
}));
|
|
3028
1338
|
} catch (refreshError) {
|
|
3029
1339
|
refreshAttempts = 0;
|
|
3030
1340
|
onRefreshFailed?.(refreshError);
|
|
3031
|
-
|
|
3032
|
-
"Authentication failed. Please re-authenticate."
|
|
3033
|
-
);
|
|
1341
|
+
return void 0;
|
|
3034
1342
|
}
|
|
3035
1343
|
}
|
|
3036
1344
|
};
|
|
@@ -3045,69 +1353,52 @@ var RateLimiter = class {
|
|
|
3045
1353
|
this.burstWindowMs = options.burstWindowMs;
|
|
3046
1354
|
this.throttleThreshold = options.throttleThreshold;
|
|
3047
1355
|
}
|
|
3048
|
-
/**
|
|
3049
|
-
* Prune timestamps older than the burst window
|
|
3050
|
-
*/
|
|
3051
1356
|
prune() {
|
|
3052
|
-
const
|
|
3053
|
-
const cutoff = now - this.burstWindowMs;
|
|
1357
|
+
const cutoff = Date.now() - this.burstWindowMs;
|
|
3054
1358
|
this.timestamps = this.timestamps.filter((ts) => ts > cutoff);
|
|
3055
1359
|
}
|
|
3056
|
-
/**
|
|
3057
|
-
* Get current usage statistics
|
|
3058
|
-
*/
|
|
3059
1360
|
getUsage() {
|
|
3060
1361
|
this.prune();
|
|
3061
|
-
const
|
|
3062
|
-
const oneMinuteAgo = now - 6e4;
|
|
1362
|
+
const oneMinuteAgo = Date.now() - 6e4;
|
|
3063
1363
|
const minuteUsage = this.timestamps.filter((ts) => ts > oneMinuteAgo).length;
|
|
3064
|
-
|
|
3065
|
-
return { minuteUsage, burstUsage };
|
|
1364
|
+
return { minuteUsage, burstUsage: this.timestamps.length };
|
|
3066
1365
|
}
|
|
3067
|
-
/**
|
|
3068
|
-
* Calculate the delay needed before the next request can be made
|
|
3069
|
-
* Returns 0 if no delay is needed
|
|
3070
|
-
*/
|
|
3071
1366
|
getDelay() {
|
|
3072
1367
|
const { minuteUsage, burstUsage } = this.getUsage();
|
|
3073
1368
|
const minuteThreshold = Math.floor(this.requestsPerMinute * this.throttleThreshold);
|
|
3074
1369
|
const burstThreshold = Math.floor(this.burstLimit * this.throttleThreshold);
|
|
1370
|
+
const now = Date.now();
|
|
3075
1371
|
if (minuteUsage >= minuteThreshold) {
|
|
3076
|
-
const now = Date.now();
|
|
3077
1372
|
const oneMinuteAgo = now - 6e4;
|
|
3078
|
-
const
|
|
3079
|
-
if (
|
|
3080
|
-
const delay =
|
|
3081
|
-
if (delay > 0)
|
|
3082
|
-
return delay;
|
|
3083
|
-
}
|
|
1373
|
+
const oldest = this.timestamps.find((ts) => ts > oneMinuteAgo);
|
|
1374
|
+
if (oldest) {
|
|
1375
|
+
const delay = oldest + 6e4 - now;
|
|
1376
|
+
if (delay > 0) return delay;
|
|
3084
1377
|
}
|
|
3085
1378
|
}
|
|
3086
1379
|
if (burstUsage >= burstThreshold) {
|
|
3087
|
-
const now = Date.now();
|
|
3088
1380
|
const burstCutoff = now - this.burstWindowMs;
|
|
3089
|
-
const
|
|
3090
|
-
if (
|
|
3091
|
-
const delay =
|
|
3092
|
-
if (delay > 0)
|
|
3093
|
-
return delay;
|
|
3094
|
-
}
|
|
1381
|
+
const oldest = this.timestamps.find((ts) => ts > burstCutoff);
|
|
1382
|
+
if (oldest) {
|
|
1383
|
+
const delay = oldest + this.burstWindowMs - now;
|
|
1384
|
+
if (delay > 0) return delay;
|
|
3095
1385
|
}
|
|
3096
1386
|
}
|
|
3097
1387
|
return 0;
|
|
3098
1388
|
}
|
|
3099
|
-
/**
|
|
3100
|
-
* Record a request timestamp
|
|
3101
|
-
*/
|
|
3102
1389
|
recordRequest() {
|
|
3103
1390
|
this.timestamps.push(Date.now());
|
|
3104
1391
|
}
|
|
3105
1392
|
};
|
|
3106
|
-
function calculateRetryDelay(
|
|
1393
|
+
function calculateRetryDelay(retryAfterHeader, retryCount, options) {
|
|
1394
|
+
if (retryAfterHeader) {
|
|
1395
|
+
const retryAfter = parseInt(retryAfterHeader, 10);
|
|
1396
|
+
if (!isNaN(retryAfter) && retryAfter > 0) {
|
|
1397
|
+
return retryAfter * 1e3;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
3107
1400
|
let delay;
|
|
3108
|
-
if (
|
|
3109
|
-
return retryAfter * 1e3;
|
|
3110
|
-
} else if (options.exponentialBackoff) {
|
|
1401
|
+
if (options.exponentialBackoff) {
|
|
3111
1402
|
delay = options.baseDelay * Math.pow(2, retryCount);
|
|
3112
1403
|
} else {
|
|
3113
1404
|
delay = options.baseDelay;
|
|
@@ -3131,37 +1422,42 @@ function createRateLimitMiddleware(options = {}) {
|
|
|
3131
1422
|
burstWindowMs = 3e5,
|
|
3132
1423
|
throttleThreshold = 0.9
|
|
3133
1424
|
} = options;
|
|
3134
|
-
const rateLimiter = enableThrottle ? new RateLimiter({
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
if (rateLimiter) {
|
|
3142
|
-
const delay = rateLimiter.getDelay();
|
|
3143
|
-
if (delay > 0) {
|
|
3144
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
3145
|
-
}
|
|
3146
|
-
}
|
|
3147
|
-
try {
|
|
3148
|
-
await next();
|
|
3149
|
-
rateLimiter?.recordRequest();
|
|
3150
|
-
} catch (error) {
|
|
3151
|
-
rateLimiter?.recordRequest();
|
|
3152
|
-
if (enableRetry && error instanceof MantleRateLimitError) {
|
|
3153
|
-
if (ctx.retryCount < maxRetries) {
|
|
3154
|
-
const delay = calculateRetryDelay(error.retryAfter, ctx.retryCount, {
|
|
3155
|
-
baseDelay,
|
|
3156
|
-
exponentialBackoff,
|
|
3157
|
-
jitter
|
|
3158
|
-
});
|
|
1425
|
+
const rateLimiter = enableThrottle ? new RateLimiter({ requestsPerMinute, burstLimit, burstWindowMs, throttleThreshold }) : null;
|
|
1426
|
+
let retryCount = 0;
|
|
1427
|
+
return {
|
|
1428
|
+
async onRequest({ request }) {
|
|
1429
|
+
if (rateLimiter) {
|
|
1430
|
+
const delay = rateLimiter.getDelay();
|
|
1431
|
+
if (delay > 0) {
|
|
3159
1432
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
3160
|
-
ctx.retry = true;
|
|
3161
|
-
return;
|
|
3162
1433
|
}
|
|
3163
1434
|
}
|
|
3164
|
-
|
|
1435
|
+
return request;
|
|
1436
|
+
},
|
|
1437
|
+
async onResponse({ request, response }) {
|
|
1438
|
+
rateLimiter?.recordRequest();
|
|
1439
|
+
if (response.status !== 429 || !enableRetry) return void 0;
|
|
1440
|
+
if (retryCount >= maxRetries) {
|
|
1441
|
+
retryCount = 0;
|
|
1442
|
+
return void 0;
|
|
1443
|
+
}
|
|
1444
|
+
const delay = calculateRetryDelay(
|
|
1445
|
+
response.headers.get("Retry-After"),
|
|
1446
|
+
retryCount,
|
|
1447
|
+
{ baseDelay, exponentialBackoff, jitter }
|
|
1448
|
+
);
|
|
1449
|
+
retryCount++;
|
|
1450
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1451
|
+
const retryResponse = await fetch(new Request(request.url, {
|
|
1452
|
+
method: request.method,
|
|
1453
|
+
headers: request.headers,
|
|
1454
|
+
body: request.body,
|
|
1455
|
+
signal: request.signal
|
|
1456
|
+
}));
|
|
1457
|
+
if (retryResponse.status !== 429) {
|
|
1458
|
+
retryCount = 0;
|
|
1459
|
+
}
|
|
1460
|
+
return retryResponse;
|
|
3165
1461
|
}
|
|
3166
1462
|
};
|
|
3167
1463
|
}
|
|
@@ -3173,6 +1469,7 @@ function createRateLimitMiddleware(options = {}) {
|
|
|
3173
1469
|
AffiliateReferralsResource,
|
|
3174
1470
|
AffiliatesResource,
|
|
3175
1471
|
AgentsResource,
|
|
1472
|
+
AiAgentRunsResource,
|
|
3176
1473
|
AppsResource,
|
|
3177
1474
|
BaseResource,
|
|
3178
1475
|
ChannelsResource,
|
|
@@ -3186,8 +1483,12 @@ function createRateLimitMiddleware(options = {}) {
|
|
|
3186
1483
|
DealFlowsResource,
|
|
3187
1484
|
DealsResource,
|
|
3188
1485
|
DocsResource,
|
|
1486
|
+
EmailUnsubscribeGroupsResource,
|
|
3189
1487
|
EntitiesResource,
|
|
1488
|
+
FlowExtensionsResource,
|
|
3190
1489
|
FlowsResource,
|
|
1490
|
+
JournalEntriesResource,
|
|
1491
|
+
ListsResource,
|
|
3191
1492
|
MantleAPIError,
|
|
3192
1493
|
MantleAuthenticationError,
|
|
3193
1494
|
MantleCoreClient,
|
|
@@ -3196,12 +1497,14 @@ function createRateLimitMiddleware(options = {}) {
|
|
|
3196
1497
|
MantleRateLimitError,
|
|
3197
1498
|
MantleValidationError,
|
|
3198
1499
|
MeResource,
|
|
1500
|
+
MeetingsResource,
|
|
3199
1501
|
MetricsResource,
|
|
3200
|
-
MiddlewareManager,
|
|
3201
1502
|
OrganizationResource,
|
|
3202
1503
|
SubscriptionsResource,
|
|
1504
|
+
SyncedEmailsResource,
|
|
3203
1505
|
TasksResource,
|
|
3204
1506
|
TicketsResource,
|
|
1507
|
+
TimelineCommentsResource,
|
|
3205
1508
|
TransactionsResource,
|
|
3206
1509
|
UsageEventsResource,
|
|
3207
1510
|
UsersResource,
|