@heymantle/core-api-client 0.1.27 → 0.2.1

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