@heymantle/core-api-client 0.1.27 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/dist/index.d.mts +22157 -5177
  2. package/dist/index.d.ts +22157 -5177
  3. package/dist/index.js +506 -2367
  4. package/dist/index.mjs +489 -2366
  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,218 +139,124 @@ 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);
142
+ get api() {
143
+ return this.client._api;
256
144
  }
257
- post(endpoint, data) {
258
- return this.client.post(endpoint, data);
145
+ /**
146
+ * Access the API client without path type-checking.
147
+ * Used for endpoints not yet in the OpenAPI spec.
148
+ */
149
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
150
+ get untypedApi() {
151
+ return this.client._api;
259
152
  }
260
- put(endpoint, data) {
261
- return this.client.put(endpoint, data);
153
+ /**
154
+ * Unwraps an openapi-fetch response, throwing typed errors on failure.
155
+ */
156
+ async unwrap(promise) {
157
+ const { data, error, response } = await promise;
158
+ if (error !== void 0) {
159
+ throw this.createError(response, error);
160
+ }
161
+ return data;
262
162
  }
263
- _delete(endpoint) {
264
- return this.client.delete(endpoint);
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
+ }
265
186
  }
266
187
  };
267
188
 
268
189
  // src/resources/customers.ts
269
190
  var CustomersResource = class extends BaseResource {
270
- /**
271
- * List customers with optional filters and pagination
272
- */
273
191
  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
- };
192
+ return this.unwrap(this.api.GET("/customers", { params: { query: params } }));
282
193
  }
283
- /**
284
- * Retrieve a single customer by ID
285
- */
286
- async retrieve(customerId, params) {
287
- return this.get(
288
- `/customers/${customerId}`,
289
- params
290
- );
194
+ async get(customerId) {
195
+ return this.unwrap(this.api.GET("/customers/{id}", { params: { path: { id: customerId } } }));
291
196
  }
292
- /**
293
- * Create a new customer
294
- */
295
197
  async create(data) {
296
- return this.post("/customers", data);
198
+ return this.unwrap(this.api.POST("/customers", { body: data }));
297
199
  }
298
- /**
299
- * Update an existing customer
300
- */
301
200
  async update(customerId, data) {
302
- return this.put(
303
- `/customers/${customerId}`,
304
- data
305
- );
201
+ return this.unwrap(this.api.PUT("/customers/{id}", { params: { path: { id: customerId } }, body: data }));
306
202
  }
307
- /**
308
- * Add tags to a customer
309
- */
310
203
  async addTags(customerId, tags) {
311
- return this.post(
312
- `/customers/${customerId}/addTags`,
313
- { tags }
314
- );
204
+ return this.unwrap(this.api.POST("/customers/{id}/addTags", { params: { path: { id: customerId } }, body: { tags } }));
315
205
  }
316
- /**
317
- * Remove tags from a customer
318
- */
319
206
  async removeTags(customerId, tags) {
320
- return this.post(
321
- `/customers/${customerId}/removeTags`,
322
- { tags }
323
- );
207
+ return this.unwrap(this.api.POST("/customers/{id}/removeTags", { params: { path: { id: customerId } }, body: { tags } }));
324
208
  }
325
- /**
326
- * Get customer activity timeline
327
- */
328
209
  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
- };
210
+ return this.unwrap(this.api.GET("/customers/{id}/timeline", { params: { path: { id: customerId }, query: params } }));
339
211
  }
340
- /**
341
- * List account owners for a customer
342
- */
343
212
  async listAccountOwners(customerId) {
344
- return this.get(
345
- `/customers/${customerId}/account_owners`
346
- );
213
+ return this.unwrap(this.api.GET("/customers/{id}/account_owners", { params: { path: { id: customerId } } }));
347
214
  }
348
- /**
349
- * Add an account owner to a customer
350
- */
351
215
  async addAccountOwner(customerId, data) {
352
- return this.post(`/customers/${customerId}/account_owners`, data);
216
+ return this.unwrap(this.api.POST("/customers/{id}/account_owners", { params: { path: { id: customerId } }, body: data }));
353
217
  }
354
- /**
355
- * Remove an account owner from a customer
356
- */
357
218
  async removeAccountOwner(customerId, ownerId) {
358
- return this._delete(
359
- `/customers/${customerId}/account_owners/${ownerId}`
360
- );
219
+ return this.unwrap(this.api.DELETE("/customers/{id}/account_owners/{ownerId}", { params: { path: { id: customerId, ownerId } } }));
361
220
  }
362
- /**
363
- * List custom fields
364
- */
365
221
  async listCustomFields(params) {
366
- return this.get(
367
- "/customers/custom_fields",
368
- params
369
- );
222
+ return this.unwrap(this.api.GET("/customers/custom_fields", { params: { query: params } }));
370
223
  }
371
- /**
372
- * Create a custom field
373
- */
374
224
  async createCustomField(data) {
375
- return this.post(
376
- "/customers/custom_fields",
377
- data
378
- );
225
+ return this.unwrap(this.api.POST("/customers/custom_fields", { body: data }));
379
226
  }
380
- /**
381
- * Retrieve a custom field by ID
382
- */
383
- async retrieveCustomField(fieldId) {
384
- return this.get(
385
- `/customers/custom_fields/${fieldId}`
386
- );
227
+ async getCustomField(fieldId) {
228
+ return this.unwrap(this.api.GET("/customers/custom_fields/{id}", { params: { path: { id: fieldId } } }));
387
229
  }
388
- /**
389
- * Update a custom field
390
- */
391
230
  async updateCustomField(fieldId, data) {
392
- return this.put(
393
- `/customers/custom_fields/${fieldId}`,
394
- data
395
- );
231
+ return this.unwrap(this.api.PUT("/customers/custom_fields/{id}", { params: { path: { id: fieldId } }, body: data }));
396
232
  }
397
- /**
398
- * Delete a custom field
399
- */
400
233
  async deleteCustomField(fieldId) {
401
- return this._delete(
402
- `/customers/custom_fields/${fieldId}`
403
- );
234
+ return this.unwrap(this.api.DELETE("/customers/custom_fields/{id}", { params: { path: { id: fieldId } } }));
404
235
  }
405
236
  };
406
237
 
407
238
  // src/resources/contacts.ts
408
239
  var ContactsResource = class extends BaseResource {
409
- /**
410
- * List contacts with optional filters and pagination
411
- */
412
240
  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
- };
241
+ return this.unwrap(this.api.GET("/contacts", { params: { query: params } }));
421
242
  }
422
- /**
423
- * Retrieve a single contact by ID
424
- */
425
- async retrieve(contactId) {
426
- return this.get(`/contacts/${contactId}`);
243
+ async get(contactId) {
244
+ return this.unwrap(this.api.GET("/contacts/{id}", { params: { path: { id: contactId } } }));
427
245
  }
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
246
  async create(data) {
435
- return this.post("/contacts", data);
247
+ return this.unwrap(this.api.POST("/contacts", { body: data }));
436
248
  }
437
- /**
438
- * Update an existing contact
439
- */
440
249
  async update(contactId, data) {
441
- return this.put(`/contacts/${contactId}`, data);
250
+ return this.unwrap(this.api.PUT("/contacts/{id}", { params: { path: { id: contactId } }, body: data }));
442
251
  }
443
- /**
444
- * Delete a contact
445
- */
446
252
  async del(contactId) {
447
- return this._delete(`/contacts/${contactId}`);
253
+ return this.unwrap(this.api.DELETE("/contacts/{id}", { params: { path: { id: contactId } } }));
448
254
  }
449
- /**
450
- * Add tags to a contact
451
- */
452
255
  async addTags(contactId, tags) {
453
- return this.post(
454
- `/contacts/${contactId}/addTags`,
455
- { tags }
456
- );
256
+ return this.unwrap(this.api.POST("/contacts/{id}/addTags", { params: { path: { id: contactId } }, body: { tags } }));
457
257
  }
458
- /**
459
- * Remove tags from a contact
460
- */
461
258
  async removeTags(contactId, tags) {
462
- return this.post(
463
- `/contacts/${contactId}/removeTags`,
464
- { tags }
465
- );
259
+ return this.unwrap(this.api.POST("/contacts/{id}/removeTags", { params: { path: { id: contactId } }, body: { tags } }));
466
260
  }
467
261
  };
468
262
 
@@ -472,25 +266,13 @@ var SubscriptionsResource = class extends BaseResource {
472
266
  * List subscriptions with optional filters and pagination
473
267
  */
474
268
  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
- };
269
+ return this.unwrap(this.api.GET("/subscriptions", { params: { query: params } }));
486
270
  }
487
271
  /**
488
- * Retrieve a single subscription by ID
272
+ * Get a single subscription by ID
489
273
  */
490
- async retrieve(subscriptionId) {
491
- return this.get(
492
- `/subscriptions/${subscriptionId}`
493
- );
274
+ async get(subscriptionId) {
275
+ return this.unwrap(this.api.GET("/subscriptions/{id}", { params: { path: { id: subscriptionId } } }));
494
276
  }
495
277
  };
496
278
 
@@ -500,18 +282,7 @@ var UsageEventsResource = class extends BaseResource {
500
282
  * List usage events with optional filters and pagination
501
283
  */
502
284
  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
- };
285
+ return this.unwrap(this.api.GET("/usage_events", { params: { query: params } }));
515
286
  }
516
287
  /**
517
288
  * Create usage event(s)
@@ -535,549 +306,212 @@ var UsageEventsResource = class extends BaseResource {
535
306
  * });
536
307
  */
537
308
  async create(data) {
538
- return this.post("/usage_events", data);
309
+ return this.unwrap(this.api.POST("/usage_events", { body: data }));
539
310
  }
540
311
  };
541
312
 
542
313
  // src/resources/apps.ts
543
314
  var AppsResource = class extends BaseResource {
544
- /**
545
- * List all apps
546
- */
315
+ // Apps
547
316
  async list(params) {
548
- return this.get("/apps", params);
317
+ return this.unwrap(this.api.GET("/apps", { params: { query: params } }));
549
318
  }
550
- /**
551
- * Retrieve a single app by ID
552
- */
553
- async retrieve(appId) {
554
- return this.get(`/apps/${appId}`);
319
+ async get(appId) {
320
+ return this.unwrap(this.api.GET("/apps/{id}", { params: { path: { id: appId } } }));
555
321
  }
556
- // ========== Plans ==========
557
- /**
558
- * List plans for an app
559
- */
322
+ // Plans
560
323
  async listPlans(appId, params) {
561
- return this.get(`/apps/${appId}/plans`, params);
324
+ return this.unwrap(this.api.GET("/apps/{id}/plans", { params: { path: { id: appId }, query: params } }));
562
325
  }
563
- /**
564
- * Retrieve a single plan
565
- */
566
- async retrievePlan(appId, planId) {
567
- return this.get(`/apps/${appId}/plans/${planId}`);
326
+ async getPlan(appId, planId) {
327
+ return this.unwrap(this.api.GET("/apps/{id}/plans/{planId}", { params: { path: { id: appId, planId } } }));
568
328
  }
569
- /**
570
- * Create a new plan for an app
571
- */
572
329
  async createPlan(appId, data) {
573
- return this.post(`/apps/${appId}/plans`, data);
330
+ return this.unwrap(this.api.POST("/apps/{id}/plans", { params: { path: { id: appId } }, body: data }));
574
331
  }
575
- /**
576
- * Update an existing plan
577
- */
578
332
  async updatePlan(appId, planId, data) {
579
- return this.put(`/apps/${appId}/plans/${planId}`, data);
333
+ return this.unwrap(this.api.PUT("/apps/{id}/plans/{planId}", { params: { path: { id: appId, planId } }, body: data }));
580
334
  }
581
- /**
582
- * Archive a plan
583
- */
584
335
  async archivePlan(appId, planId) {
585
- return this.post(
586
- `/apps/${appId}/plans/${planId}/archive`,
587
- {}
588
- );
336
+ return this.unwrap(this.api.PUT("/apps/{id}/plans/{planId}/archive", { params: { path: { id: appId, planId } } }));
589
337
  }
590
- /**
591
- * Unarchive a plan
592
- */
593
338
  async unarchivePlan(appId, planId) {
594
- return this.post(
595
- `/apps/${appId}/plans/${planId}/unarchive`,
596
- {}
597
- );
339
+ return this.unwrap(this.api.PUT("/apps/{id}/plans/{planId}/unarchive", { params: { path: { id: appId, planId } } }));
598
340
  }
599
- // ========== Features ==========
600
- /**
601
- * List features for an app
602
- */
341
+ // Features
603
342
  async listFeatures(appId) {
604
- return this.get(`/apps/${appId}/plans/features`);
343
+ return this.unwrap(this.api.GET("/apps/{appId}/plans/features", { params: { path: { appId } } }));
605
344
  }
606
- /**
607
- * Retrieve a single feature
608
- */
609
- async retrieveFeature(appId, featureId) {
610
- return this.get(
611
- `/apps/${appId}/plans/features/${featureId}`
612
- );
345
+ async getFeature(appId, featureId) {
346
+ return this.unwrap(this.api.GET("/apps/{appId}/plans/features/{featureId}", { params: { path: { appId, featureId } } }));
613
347
  }
614
- /**
615
- * Create a new feature for an app
616
- */
617
348
  async createFeature(appId, data) {
618
- return this.post(
619
- `/apps/${appId}/plans/features`,
620
- data
621
- );
349
+ return this.unwrap(this.api.POST("/apps/{appId}/plans/features", { params: { path: { appId } }, body: data }));
622
350
  }
623
- /**
624
- * Update an existing feature
625
- */
626
351
  async updateFeature(appId, featureId, data) {
627
- return this.put(
628
- `/apps/${appId}/plans/features/${featureId}`,
629
- data
630
- );
352
+ return this.unwrap(this.api.PUT("/apps/{appId}/plans/features/{featureId}", { params: { path: { appId, featureId } }, body: data }));
631
353
  }
632
- /**
633
- * Delete a feature
634
- */
635
354
  async deleteFeature(appId, featureId) {
636
- return this._delete(
637
- `/apps/${appId}/plans/features/${featureId}`
638
- );
355
+ return this.unwrap(this.api.DELETE("/apps/{appId}/plans/features/{featureId}", { params: { path: { appId, featureId } } }));
639
356
  }
640
- // ========== Reviews ==========
641
- /**
642
- * List reviews for an app
643
- */
357
+ // Reviews
644
358
  async listReviews(appId) {
645
- return this.get(`/apps/${appId}/reviews`);
646
- }
647
- /**
648
- * Retrieve a single review
649
- */
650
- async retrieveReview(appId, reviewId) {
651
- return this.get(`/apps/${appId}/reviews/${reviewId}`);
652
- }
653
- /**
654
- * Create a new review for an app
655
- */
656
- async createReview(appId, data) {
657
- return this.post(`/apps/${appId}/reviews`, data);
658
- }
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
- );
667
- }
668
- /**
669
- * Delete a review
670
- */
671
- async deleteReview(appId, reviewId) {
672
- return this._delete(`/apps/${appId}/reviews/${reviewId}`);
359
+ return this.unwrap(this.api.GET("/apps/{id}/reviews", { params: { path: { id: appId } } }));
673
360
  }
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
- );
682
- }
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
- );
361
+ async getReview(appId, reviewId) {
362
+ return this.unwrap(this.api.GET("/apps/{id}/reviews/{reviewId}", { params: { path: { id: appId, reviewId } } }));
691
363
  }
692
- // ========== Usage Metrics ==========
693
- /**
694
- * List usage metrics for an app
695
- */
364
+ // Usage Metrics
696
365
  async listUsageMetrics(appId) {
697
- return this.get(
698
- `/apps/${appId}/usage_metrics`
699
- );
366
+ return this.unwrap(this.api.GET("/apps/{id}/usage_metrics", { params: { path: { id: appId } } }));
700
367
  }
701
- /**
702
- * Retrieve a single usage metric
703
- */
704
- async retrieveUsageMetric(appId, usageMetricId) {
705
- return this.get(
706
- `/apps/${appId}/usage_metrics/${usageMetricId}`
707
- );
368
+ async getUsageMetric(appId, usageMetricId) {
369
+ return this.unwrap(this.api.GET("/apps/{id}/usage_metrics/{usageMetricId}", { params: { path: { id: appId, usageMetricId } } }));
708
370
  }
709
- /**
710
- * Create a new usage metric for an app
711
- */
712
371
  async createUsageMetric(appId, data) {
713
- return this.post(
714
- `/apps/${appId}/usage_metrics`,
715
- data
716
- );
372
+ return this.unwrap(this.api.POST("/apps/{id}/usage_metrics", { params: { path: { id: appId } }, body: data }));
717
373
  }
718
- /**
719
- * Update an existing usage metric
720
- */
721
374
  async updateUsageMetric(appId, usageMetricId, data) {
722
- return this.put(
723
- `/apps/${appId}/usage_metrics/${usageMetricId}`,
724
- data
725
- );
375
+ return this.unwrap(this.api.PUT("/apps/{id}/usage_metrics/{usageMetricId}", { params: { path: { id: appId, usageMetricId } }, body: data }));
726
376
  }
727
- /**
728
- * Delete a usage metric
729
- */
730
377
  async deleteUsageMetric(appId, usageMetricId) {
731
- return this._delete(
732
- `/apps/${appId}/usage_metrics/${usageMetricId}`
733
- );
378
+ return this.unwrap(this.api.DELETE("/apps/{id}/usage_metrics/{usageMetricId}", { params: { path: { id: appId, usageMetricId } } }));
734
379
  }
735
- // ========== App Events ==========
736
- /**
737
- * List app events
738
- */
380
+ // App Events
739
381
  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
- };
382
+ return this.unwrap(this.api.GET("/apps/{id}/app_events", { params: { path: { id: appId }, query: params } }));
383
+ }
384
+ async getAppEvent(appId, appEventId) {
385
+ return this.unwrap(this.api.GET("/apps/{id}/app_events/{appEventId}", { params: { path: { id: appId, appEventId } } }));
386
+ }
387
+ async createAppEvent(appId, data) {
388
+ return this.unwrap(this.api.POST("/apps/{id}/app_events", { params: { path: { id: appId } }, body: data }));
751
389
  }
752
390
  };
753
391
 
754
392
  // src/resources/deals.ts
755
393
  var DealsResource = class extends BaseResource {
756
- /**
757
- * List deals with optional filters and pagination
758
- */
759
394
  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
- };
395
+ return this.unwrap(this.api.GET("/deals", { params: { query: params } }));
768
396
  }
769
- /**
770
- * Retrieve a single deal by ID
771
- */
772
- async retrieve(dealId) {
773
- return this.get(`/deals/${dealId}`);
397
+ async get(dealId) {
398
+ return this.unwrap(this.api.GET("/deals/{id}", { params: { path: { id: dealId } } }));
774
399
  }
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
400
  async create(data) {
814
- return this.post("/deals", data);
401
+ return this.unwrap(this.api.POST("/deals", { body: data }));
815
402
  }
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
403
  async update(dealId, data) {
849
- return this.put(`/deals/${dealId}`, data);
404
+ return this.unwrap(this.api.PUT("/deals/{id}", { params: { path: { id: dealId } }, body: data }));
850
405
  }
851
- /**
852
- * Archive (soft delete) a deal
853
- */
854
406
  async del(dealId) {
855
- return this._delete(`/deals/${dealId}`);
407
+ return this.unwrap(this.api.DELETE("/deals/{id}", { params: { path: { id: dealId } } }));
856
408
  }
857
- /**
858
- * Get deal activity timeline
859
- */
860
409
  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
- };
410
+ return this.unwrap(this.api.GET("/deals/{id}/timeline", { params: { path: { id: dealId } } }));
870
411
  }
871
- /**
872
- * List deal events
873
- */
874
412
  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
- };
413
+ return this.unwrap(this.api.GET("/deals/{id}/events", { params: { path: { id: dealId } } }));
885
414
  }
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
415
  async createEvent(dealId, data) {
904
- return this.post(`/deals/${dealId}/events`, data);
416
+ return this.unwrap(this.api.POST("/deals/{id}/events", { params: { path: { id: dealId } }, body: data }));
905
417
  }
906
418
  };
907
419
 
908
420
  // src/resources/deal-flows.ts
909
421
  var DealFlowsResource = class extends BaseResource {
910
- /**
911
- * List all deal flows
912
- */
913
- async list() {
914
- return this.get("/deal_flows");
422
+ async list(params) {
423
+ return this.unwrap(this.api.GET("/deal_flows", { params: { query: params } }));
915
424
  }
916
- /**
917
- * Retrieve a single deal flow by ID
918
- */
919
- async retrieve(dealFlowId) {
920
- return this.get(`/deal_flows/${dealFlowId}`);
425
+ async get(dealFlowId) {
426
+ return this.unwrap(this.api.GET("/deal_flows/{id}", { params: { path: { id: dealFlowId } } }));
921
427
  }
922
- /**
923
- * Create a new deal flow
924
- */
925
428
  async create(data) {
926
- return this.post("/deal_flows", data);
429
+ return this.unwrap(this.api.POST("/deal_flows", { body: data }));
927
430
  }
928
- /**
929
- * Update an existing deal flow
930
- */
931
431
  async update(dealFlowId, data) {
932
- return this.put(
933
- `/deal_flows/${dealFlowId}`,
934
- data
935
- );
432
+ return this.unwrap(this.api.PUT("/deal_flows/{id}", { params: { path: { id: dealFlowId } }, body: data }));
936
433
  }
937
- /**
938
- * Delete a deal flow
939
- */
940
434
  async del(dealFlowId) {
941
- return this._delete(`/deal_flows/${dealFlowId}`);
435
+ return this.unwrap(this.api.DELETE("/deal_flows/{id}", { params: { path: { id: dealFlowId } } }));
942
436
  }
943
437
  };
944
438
 
945
439
  // src/resources/deal-activities.ts
946
440
  var DealActivitiesResource = class extends BaseResource {
947
- /**
948
- * List all deal activities
949
- */
950
- async list() {
951
- return this.get("/deal_activities");
441
+ async list(params) {
442
+ return this.unwrap(this.api.GET("/deal_activities", { params: { query: params } }));
952
443
  }
953
- /**
954
- * Retrieve a single deal activity by ID
955
- */
956
- async retrieve(dealActivityId) {
957
- return this.get(
958
- `/deal_activities/${dealActivityId}`
959
- );
444
+ async get(dealActivityId) {
445
+ return this.unwrap(this.api.GET("/deal_activities/{id}", { params: { path: { id: dealActivityId } } }));
960
446
  }
961
- /**
962
- * Create a new deal activity
963
- */
964
447
  async create(data) {
965
- return this.post("/deal_activities", data);
448
+ return this.unwrap(this.api.POST("/deal_activities", { body: data }));
966
449
  }
967
- /**
968
- * Update an existing deal activity
969
- */
970
450
  async update(dealActivityId, data) {
971
- return this.put(
972
- `/deal_activities/${dealActivityId}`,
973
- data
974
- );
451
+ return this.unwrap(this.api.PUT("/deal_activities/{id}", { params: { path: { id: dealActivityId } }, body: data }));
975
452
  }
976
- /**
977
- * Delete a deal activity
978
- */
979
453
  async del(dealActivityId) {
980
- return this._delete(`/deal_activities/${dealActivityId}`);
454
+ return this.unwrap(this.api.DELETE("/deal_activities/{id}", { params: { path: { id: dealActivityId } } }));
981
455
  }
982
456
  };
983
457
 
984
458
  // src/resources/tickets.ts
985
459
  var TicketsResource = class extends BaseResource {
986
- /**
987
- * List tickets with optional filters and pagination
988
- */
460
+ // Tickets
989
461
  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
- };
462
+ return this.unwrap(this.api.GET("/tickets", { params: { query: params } }));
998
463
  }
999
- /**
1000
- * Retrieve a single ticket by ID
1001
- */
1002
- async retrieve(ticketId) {
1003
- return this.get(`/tickets/${ticketId}`);
464
+ async get(ticketId) {
465
+ return this.unwrap(this.api.GET("/tickets/{id}", { params: { path: { id: ticketId } } }));
1004
466
  }
1005
- /**
1006
- * Create a new ticket
1007
- */
1008
467
  async create(data) {
1009
- return this.post("/tickets", data);
468
+ return this.unwrap(this.api.POST("/tickets", { body: data }));
1010
469
  }
1011
- /**
1012
- * Update an existing ticket
1013
- */
1014
470
  async update(ticketId, data) {
1015
- return this.put(`/tickets/${ticketId}`, data);
1016
- }
1017
- /**
1018
- * Delete a ticket
1019
- */
1020
- async del(ticketId) {
1021
- return this._delete(`/tickets/${ticketId}`);
471
+ return this.unwrap(this.api.PUT("/tickets/{id}", { params: { path: { id: ticketId } }, body: data }));
1022
472
  }
1023
- // ========== Messages ==========
1024
- /**
1025
- * List messages for a ticket
1026
- */
1027
- async listMessages(ticketId) {
1028
- return this.get(
1029
- `/tickets/${ticketId}/messages`
1030
- );
473
+ // Messages
474
+ async listMessages(ticketId, params) {
475
+ return this.unwrap(this.api.GET("/tickets/{id}/messages", { params: { path: { id: ticketId }, query: params } }));
1031
476
  }
1032
- /**
1033
- * Retrieve a single message
1034
- */
1035
- async retrieveMessage(ticketId, messageId) {
1036
- return this.get(
1037
- `/tickets/${ticketId}/messages/${messageId}`
1038
- );
477
+ async getMessage(ticketId, messageId) {
478
+ return this.unwrap(this.api.GET("/tickets/{id}/messages/{messageId}", { params: { path: { id: ticketId, messageId } } }));
1039
479
  }
1040
- /**
1041
- * Create a new message on a ticket
1042
- */
1043
480
  async createMessage(ticketId, data) {
1044
- return this.post(
1045
- `/tickets/${ticketId}/messages`,
1046
- data
1047
- );
481
+ return this.unwrap(this.api.POST("/tickets/{id}/messages", { params: { path: { id: ticketId } }, body: data }));
1048
482
  }
1049
- /**
1050
- * Update a message
1051
- */
1052
- async updateMessage(ticketId, messageId, data) {
1053
- return this.put(
1054
- `/tickets/${ticketId}/messages/${messageId}`,
1055
- data
1056
- );
483
+ async updateMessage(ticketId, data) {
484
+ return this.unwrap(this.api.PUT("/tickets/{id}/messages", { params: { path: { id: ticketId } }, body: data }));
1057
485
  }
1058
- /**
1059
- * Delete a message
1060
- */
1061
- async deleteMessage(ticketId, messageId) {
1062
- return this._delete(
1063
- `/tickets/${ticketId}/messages/${messageId}`
1064
- );
486
+ // Events
487
+ async listEvents(ticketId, params) {
488
+ return this.unwrap(this.api.GET("/tickets/{id}/events", { params: { path: { id: ticketId }, query: params } }));
489
+ }
490
+ async createEvent(ticketId, data) {
491
+ return this.unwrap(this.api.POST("/tickets/{id}/events", { params: { path: { id: ticketId } }, body: data }));
492
+ }
493
+ // Loops
494
+ async listLoops(ticketId) {
495
+ return this.unwrap(this.api.GET("/tickets/{id}/loops", { params: { path: { id: ticketId } } }));
496
+ }
497
+ async getLoop(ticketId, loopId) {
498
+ return this.unwrap(this.api.GET("/tickets/{id}/loops/{loopId}", { params: { path: { id: ticketId, loopId } } }));
1065
499
  }
1066
500
  };
1067
501
 
1068
502
  // src/resources/channels.ts
1069
503
  var ChannelsResource = class extends BaseResource {
1070
504
  /**
1071
- * List CX channels
505
+ * List CX channels with optional filters
1072
506
  */
1073
507
  async list(params) {
1074
- return this.get("/channels", params);
508
+ return this.unwrap(this.api.GET("/channels", { params: { query: params } }));
1075
509
  }
1076
510
  /**
1077
511
  * Create a new CX channel
1078
512
  */
1079
513
  async create(data) {
1080
- return this.post("/channels", data);
514
+ return this.unwrap(this.api.POST("/channels", { body: data }));
1081
515
  }
1082
516
  };
1083
517
 
@@ -1087,113 +521,67 @@ var FlowsResource = class extends BaseResource {
1087
521
  * List flows with optional filters and pagination
1088
522
  */
1089
523
  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
- };
524
+ return this.unwrap(this.api.GET("/flows", { params: { query: params } }));
1098
525
  }
1099
526
  /**
1100
- * Retrieve a single flow by ID
527
+ * Get a single flow by ID
1101
528
  */
1102
- async retrieve(flowId) {
1103
- return this.get(`/flows/${flowId}`);
529
+ async get(flowId) {
530
+ return this.unwrap(this.api.GET("/flows/{id}", { params: { path: { id: flowId } } }));
1104
531
  }
1105
532
  /**
1106
533
  * Create a new flow
1107
534
  */
1108
535
  async create(data) {
1109
- return this.post("/flows", data);
536
+ return this.unwrap(this.api.POST("/flows", { body: data }));
1110
537
  }
1111
538
  /**
1112
539
  * Update an existing flow
1113
540
  */
1114
541
  async update(flowId, data) {
1115
- return this.put(`/flows/${flowId}`, data);
542
+ return this.unwrap(this.api.PATCH("/flows/{id}", { params: { path: { id: flowId } }, body: data }));
1116
543
  }
1117
544
  /**
1118
545
  * Delete a flow
1119
546
  */
1120
547
  async del(flowId) {
1121
- return this._delete(`/flows/${flowId}`);
548
+ return this.unwrap(this.api.DELETE("/flows/{id}", { params: { path: { id: flowId } } }));
1122
549
  }
1123
550
  };
1124
551
 
1125
552
  // src/resources/tasks.ts
1126
553
  var TasksResource = class extends BaseResource {
1127
- /**
1128
- * List tasks with optional filters and pagination
1129
- */
554
+ // Tasks
1130
555
  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
- };
556
+ return this.unwrap(this.api.GET("/tasks", { params: { query: params } }));
1139
557
  }
1140
- /**
1141
- * Retrieve a single task by ID
1142
- */
1143
- async retrieve(taskId) {
1144
- return this.get(`/tasks/${taskId}`);
558
+ async get(taskId) {
559
+ return this.unwrap(this.api.GET("/tasks/{id}", { params: { path: { id: taskId } } }));
1145
560
  }
1146
- /**
1147
- * Create a new task
1148
- */
1149
561
  async create(data) {
1150
- return this.post("/tasks", data);
562
+ return this.unwrap(this.api.POST("/tasks", { body: data }));
1151
563
  }
1152
- /**
1153
- * Update an existing task
1154
- */
1155
564
  async update(taskId, data) {
1156
- return this.put(`/tasks/${taskId}`, data);
565
+ return this.unwrap(this.api.PUT("/tasks/{id}", { params: { path: { id: taskId } }, body: data }));
1157
566
  }
1158
- /**
1159
- * Delete a task
1160
- */
1161
567
  async del(taskId) {
1162
- return this._delete(`/tasks/${taskId}`);
568
+ return this.unwrap(this.api.DELETE("/tasks/{id}", { params: { path: { id: taskId } } }));
1163
569
  }
1164
- // ========== Todo Items ==========
1165
- /**
1166
- * List todo items for a task
1167
- */
570
+ // Todo Items
1168
571
  async listTodoItems(taskId) {
1169
- return this.get(`/tasks/${taskId}/todo-items`);
572
+ return this.unwrap(this.api.GET("/tasks/{id}/todo-items", { params: { path: { id: taskId } } }));
1170
573
  }
1171
- /**
1172
- * Retrieve a single todo item
1173
- */
1174
- async retrieveTodoItem(taskId, itemId) {
1175
- return this.get(`/tasks/${taskId}/todo-items/${itemId}`);
574
+ async getTodoItem(taskId, itemId) {
575
+ return this.unwrap(this.api.GET("/tasks/{id}/todo-items/{itemId}", { params: { path: { id: taskId, itemId } } }));
1176
576
  }
1177
- /**
1178
- * Create a todo item for a task
1179
- */
1180
577
  async createTodoItem(taskId, data) {
1181
- return this.post(`/tasks/${taskId}/todo-items`, data);
578
+ return this.unwrap(this.api.POST("/tasks/{id}/todo-items", { params: { path: { id: taskId } }, body: data }));
1182
579
  }
1183
- /**
1184
- * Update a todo item
1185
- */
1186
580
  async updateTodoItem(taskId, itemId, data) {
1187
- return this.put(
1188
- `/tasks/${taskId}/todo-items/${itemId}`,
1189
- data
1190
- );
581
+ return this.unwrap(this.api.PUT("/tasks/{id}/todo-items/{itemId}", { params: { path: { id: taskId, itemId } }, body: data }));
1191
582
  }
1192
- /**
1193
- * Delete a todo item
1194
- */
1195
583
  async deleteTodoItem(taskId, itemId) {
1196
- return this._delete(`/tasks/${taskId}/todo-items/${itemId}`);
584
+ return this.unwrap(this.api.DELETE("/tasks/{id}/todo-items/{itemId}", { params: { path: { id: taskId, itemId } } }));
1197
585
  }
1198
586
  };
1199
587
 
@@ -1203,36 +591,25 @@ var WebhooksResource = class extends BaseResource {
1203
591
  * List all webhooks
1204
592
  */
1205
593
  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
- };
1212
- }
1213
- /**
1214
- * Retrieve a single webhook by ID
1215
- */
1216
- async retrieve(webhookId) {
1217
- return this.get(`/webhooks/${webhookId}`);
594
+ return this.unwrap(this.api.GET("/webhooks"));
1218
595
  }
1219
596
  /**
1220
597
  * Create a new webhook
1221
598
  */
1222
599
  async create(data) {
1223
- return this.post("/webhooks", data);
600
+ return this.unwrap(this.api.POST("/webhooks", { body: data }));
1224
601
  }
1225
602
  /**
1226
603
  * Update an existing webhook
1227
604
  */
1228
605
  async update(webhookId, data) {
1229
- return this.put(`/webhooks/${webhookId}`, data);
606
+ return this.unwrap(this.api.PUT("/webhooks/{id}", { params: { path: { id: webhookId } }, body: data }));
1230
607
  }
1231
608
  /**
1232
609
  * Delete a webhook
1233
610
  */
1234
611
  async del(webhookId) {
1235
- return this._delete(`/webhooks/${webhookId}`);
612
+ return this.unwrap(this.api.DELETE("/webhooks/{id}", { params: { path: { id: webhookId } } }));
1236
613
  }
1237
614
  };
1238
615
 
@@ -1242,37 +619,31 @@ var CompaniesResource = class extends BaseResource {
1242
619
  * List companies with optional pagination
1243
620
  */
1244
621
  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
- };
622
+ return this.unwrap(this.api.GET("/companies", { params: { query: params } }));
1252
623
  }
1253
624
  /**
1254
- * Retrieve a single company by ID
625
+ * Get a single company by ID
1255
626
  */
1256
- async retrieve(companyId) {
1257
- return this.get(`/companies/${companyId}`);
627
+ async get(companyId) {
628
+ return this.unwrap(this.api.GET("/companies/{id}", { params: { path: { id: companyId } } }));
1258
629
  }
1259
630
  /**
1260
631
  * Create a new company
1261
632
  */
1262
633
  async create(data) {
1263
- return this.post("/companies", data);
634
+ return this.unwrap(this.api.POST("/companies", { body: data }));
1264
635
  }
1265
636
  /**
1266
637
  * Update an existing company
1267
638
  */
1268
639
  async update(companyId, data) {
1269
- return this.put(`/companies/${companyId}`, data);
640
+ return this.unwrap(this.api.PUT("/companies/{id}", { params: { path: { id: companyId } }, body: data }));
1270
641
  }
1271
642
  /**
1272
643
  * Delete a company
1273
644
  */
1274
645
  async del(companyId) {
1275
- return this._delete(`/companies/${companyId}`);
646
+ return this.unwrap(this.api.DELETE("/companies/{id}", { params: { path: { id: companyId } } }));
1276
647
  }
1277
648
  };
1278
649
 
@@ -1282,24 +653,13 @@ var CustomerSegmentsResource = class extends BaseResource {
1282
653
  * List public customer segments with optional pagination
1283
654
  */
1284
655
  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
- };
656
+ return this.unwrap(this.api.GET("/customer_segments", { params: { query: params } }));
1295
657
  }
1296
658
  /**
1297
- * Retrieve a single customer segment by ID
659
+ * Get a single customer segment by ID
1298
660
  */
1299
- async retrieve(segmentId) {
1300
- return this.get(
1301
- `/customer_segments/${segmentId}`
1302
- );
661
+ async get(segmentId) {
662
+ return this.unwrap(this.api.GET("/customer_segments/{id}", { params: { path: { id: segmentId } } }));
1303
663
  }
1304
664
  };
1305
665
 
@@ -1309,75 +669,57 @@ var AffiliatesResource = class extends BaseResource {
1309
669
  * List affiliates with optional filters and pagination
1310
670
  */
1311
671
  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
- };
672
+ return this.unwrap(this.api.GET("/affiliates", { params: { query: params } }));
1322
673
  }
1323
674
  /**
1324
- * Retrieve a single affiliate by ID
675
+ * Get a single affiliate by ID
1325
676
  */
1326
- async retrieve(affiliateId) {
1327
- return this.get(`/affiliates/${affiliateId}`);
677
+ async get(affiliateId) {
678
+ return this.unwrap(this.api.GET("/affiliates/{id}", { params: { path: { id: affiliateId } } }));
1328
679
  }
1329
680
  /**
1330
681
  * Update an existing affiliate
682
+ * Note: PUT not in OpenAPI spec but kept for backwards compatibility
1331
683
  */
1332
684
  async update(affiliateId, data) {
1333
- return this.put(
1334
- `/affiliates/${affiliateId}`,
1335
- data
1336
- );
685
+ return this.unwrap(this.untypedApi.PUT("/affiliates/{id}", { params: { path: { id: affiliateId } }, body: data }));
1337
686
  }
1338
687
  };
1339
688
 
1340
689
  // src/resources/affiliate-programs.ts
1341
690
  var AffiliateProgramsResource = class extends BaseResource {
1342
691
  /**
1343
- * List all affiliate programs
692
+ * List affiliate programs with optional filters and pagination
1344
693
  */
1345
- async list() {
1346
- return this.get(
1347
- "/affiliate_programs"
1348
- );
694
+ async list(params) {
695
+ return this.unwrap(this.api.GET("/affiliate_programs", { params: { query: params } }));
1349
696
  }
1350
697
  /**
1351
- * Retrieve a single affiliate program by ID
698
+ * Get a single affiliate program by ID
1352
699
  */
1353
- async retrieve(programId) {
1354
- return this.get(
1355
- `/affiliate_programs/${programId}`
1356
- );
700
+ async get(programId) {
701
+ return this.unwrap(this.api.GET("/affiliate_programs/{id}", { params: { path: { id: programId } } }));
1357
702
  }
1358
703
  /**
1359
704
  * Create a new affiliate program
705
+ * Note: POST not yet in OpenAPI spec
1360
706
  */
1361
707
  async create(data) {
1362
- return this.post(
1363
- "/affiliate_programs",
1364
- data
1365
- );
708
+ return this.unwrap(this.untypedApi.POST("/affiliate_programs", { body: data }));
1366
709
  }
1367
710
  /**
1368
711
  * Update an existing affiliate program
712
+ * Note: PUT not yet in OpenAPI spec
1369
713
  */
1370
714
  async update(programId, data) {
1371
- return this.put(
1372
- `/affiliate_programs/${programId}`,
1373
- data
1374
- );
715
+ return this.unwrap(this.untypedApi.PUT("/affiliate_programs/{id}", { params: { path: { id: programId } }, body: data }));
1375
716
  }
1376
717
  /**
1377
718
  * Delete an affiliate program
719
+ * Note: DELETE not yet in OpenAPI spec
1378
720
  */
1379
721
  async del(programId) {
1380
- return this._delete(`/affiliate_programs/${programId}`);
722
+ return this.unwrap(this.untypedApi.DELETE("/affiliate_programs/{id}", { params: { path: { id: programId } } }));
1381
723
  }
1382
724
  };
1383
725
 
@@ -1387,24 +729,13 @@ var AffiliateCommissionsResource = class extends BaseResource {
1387
729
  * List affiliate commissions with optional filters and pagination
1388
730
  */
1389
731
  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
- };
732
+ return this.unwrap(this.api.GET("/affiliate_commissions", { params: { query: params } }));
1400
733
  }
1401
734
  /**
1402
- * Retrieve a single affiliate commission by ID
735
+ * Get a single affiliate commission by ID
1403
736
  */
1404
- async retrieve(commissionId) {
1405
- return this.get(
1406
- `/affiliate_commissions/${commissionId}`
1407
- );
737
+ async get(commissionId) {
738
+ return this.unwrap(this.api.GET("/affiliate_commissions/{id}", { params: { path: { id: commissionId } } }));
1408
739
  }
1409
740
  };
1410
741
 
@@ -1414,24 +745,13 @@ var AffiliatePayoutsResource = class extends BaseResource {
1414
745
  * List affiliate payouts with optional filters and pagination
1415
746
  */
1416
747
  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
- };
748
+ return this.unwrap(this.api.GET("/affiliate_payouts", { params: { query: params } }));
1427
749
  }
1428
750
  /**
1429
- * Retrieve a single affiliate payout by ID
751
+ * Get a single affiliate payout by ID
1430
752
  */
1431
- async retrieve(payoutId) {
1432
- return this.get(
1433
- `/affiliate_payouts/${payoutId}`
1434
- );
753
+ async get(payoutId) {
754
+ return this.unwrap(this.api.GET("/affiliate_payouts/{id}", { params: { path: { id: payoutId } } }));
1435
755
  }
1436
756
  };
1437
757
 
@@ -1441,24 +761,13 @@ var AffiliateReferralsResource = class extends BaseResource {
1441
761
  * List affiliate referrals with optional filters and pagination
1442
762
  */
1443
763
  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
- };
764
+ return this.unwrap(this.api.GET("/affiliate_referrals", { params: { query: params } }));
1454
765
  }
1455
766
  /**
1456
- * Retrieve a single affiliate referral by ID
767
+ * Get a single affiliate referral by ID
1457
768
  */
1458
- async retrieve(referralId) {
1459
- return this.get(
1460
- `/affiliate_referrals/${referralId}`
1461
- );
769
+ async get(referralId) {
770
+ return this.unwrap(this.api.GET("/affiliate_referrals/{id}", { params: { path: { id: referralId } } }));
1462
771
  }
1463
772
  };
1464
773
 
@@ -1468,14 +777,7 @@ var ChargesResource = class extends BaseResource {
1468
777
  * List charges with optional filters and pagination
1469
778
  */
1470
779
  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
- };
780
+ return this.unwrap(this.api.GET("/charges", { params: { query: params } }));
1479
781
  }
1480
782
  };
1481
783
 
@@ -1485,227 +787,62 @@ var TransactionsResource = class extends BaseResource {
1485
787
  * List transactions with optional filters and pagination
1486
788
  */
1487
789
  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
- };
790
+ return this.unwrap(this.api.GET("/transactions", { params: { query: params } }));
1499
791
  }
1500
792
  /**
1501
- * Retrieve a single transaction by ID
793
+ * Get a single transaction by ID
1502
794
  */
1503
- async retrieve(transactionId) {
1504
- return this.get(
1505
- `/transactions/${transactionId}`
1506
- );
795
+ async get(transactionId) {
796
+ return this.unwrap(this.api.GET("/transactions/{id}", { params: { path: { id: transactionId } } }));
1507
797
  }
1508
798
  };
1509
799
 
1510
800
  // src/resources/metrics.ts
1511
801
  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
- };
802
+ async mrr(params) {
803
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/mrr", { params: { query: params } }));
1533
804
  }
1534
- /**
1535
- * Get Annual Recurring Revenue (ARR)
1536
- */
1537
805
  async arr(params) {
1538
- return this.fetch({
1539
- metric: "PlatformApp.arr",
1540
- dateRange: params.dateRange || "last_30_days",
1541
- ...params
1542
- });
806
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/arr", { params: { query: params } }));
1543
807
  }
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
- });
808
+ async arpu(params) {
809
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/arpu", { params: { query: params } }));
1553
810
  }
1554
- /**
1555
- * Get active subscriptions count
1556
- */
1557
811
  async activeSubscriptions(params) {
1558
- return this.fetch({
1559
- metric: "PlatformApp.activeSubscriptions",
1560
- dateRange: params.dateRange || "last_30_days",
1561
- ...params
1562
- });
812
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/activeSubscriptions", { params: { query: params } }));
1563
813
  }
1564
- /**
1565
- * Get active installations count
1566
- */
1567
814
  async activeInstalls(params) {
1568
- return this.fetch({
1569
- metric: "PlatformApp.activeInstalls",
1570
- dateRange: params.dateRange || "last_30_days",
1571
- ...params
1572
- });
815
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/activeInstalls", { params: { query: params } }));
1573
816
  }
1574
- /**
1575
- * Get net new installations
1576
- */
1577
817
  async netInstalls(params) {
1578
- return this.fetch({
1579
- metric: "PlatformApp.netInstalls",
1580
- dateRange: params.dateRange || "last_30_days",
1581
- ...params
1582
- });
818
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/netInstalls", { params: { query: params } }));
1583
819
  }
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
- });
1593
- }
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
- });
820
+ async logoChurn(params) {
821
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/logoChurn", { params: { query: params } }));
1603
822
  }
1604
- /**
1605
- * Get revenue churn rate
1606
- */
1607
823
  async revenueChurn(params) {
1608
- return this.fetch({
1609
- metric: "PlatformApp.revenueChurn",
1610
- dateRange: params.dateRange || "last_30_days",
1611
- ...params
1612
- });
1613
- }
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
- });
824
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/revenueChurn", { params: { query: params } }));
1623
825
  }
1624
- /**
1625
- * Get revenue retention rate
1626
- */
1627
826
  async revenueRetention(params) {
1628
- return this.fetch({
1629
- metric: "PlatformApp.revenueRetention",
1630
- dateRange: params.dateRange || "last_30_days",
1631
- ...params
1632
- });
827
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/revenueRetention", { params: { query: params } }));
1633
828
  }
1634
- /**
1635
- * Get net revenue retention rate
1636
- */
1637
829
  async netRevenueRetention(params) {
1638
- return this.fetch({
1639
- metric: "PlatformApp.netRevenueRetention",
1640
- dateRange: params.dateRange || "last_30_days",
1641
- ...params
1642
- });
830
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/netRevenueRetention", { params: { query: params } }));
1643
831
  }
1644
- /**
1645
- * Get net revenue
1646
- */
1647
832
  async netRevenue(params) {
1648
- return this.fetch({
1649
- metric: "PlatformApp.netRevenue",
1650
- dateRange: params.dateRange || "last_30_days",
1651
- ...params
1652
- });
833
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/netRevenue", { params: { query: params } }));
1653
834
  }
1654
- /**
1655
- * Get payout amount
1656
- */
1657
835
  async payout(params) {
1658
- return this.fetch({
1659
- metric: "PlatformApp.payout",
1660
- dateRange: params.dateRange || "last_30_days",
1661
- ...params
1662
- });
836
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/payout", { params: { query: params } }));
1663
837
  }
1664
- /**
1665
- * Get predicted Lifetime Value
1666
- */
1667
838
  async predictedLtv(params) {
1668
- return this.fetch({
1669
- metric: "PlatformApp.predictedLtv",
1670
- dateRange: params.dateRange || "last_30_days",
1671
- ...params
1672
- });
839
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/predictedLtv", { params: { query: params } }));
1673
840
  }
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
- });
1683
- }
1684
- /**
1685
- * Get usage event metrics
1686
- */
1687
841
  async usageEvent(params) {
1688
- return this.fetch({
1689
- metric: "PlatformApp.usageEvent",
1690
- dateRange: params.dateRange || "last_30_days",
1691
- ...params
1692
- });
842
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/usageEvent", { params: { query: params } }));
1693
843
  }
1694
- /**
1695
- * Get usage metric data
1696
- */
1697
844
  async usageMetric(params) {
1698
- return this.fetch({
1699
- metric: "PlatformApp.usageMetric",
1700
- dateRange: params.dateRange || "last_30_days",
1701
- ...params
1702
- });
1703
- }
1704
- /**
1705
- * Get key sales metrics
1706
- */
1707
- async sales(params) {
1708
- return this.get("/metrics/sales", params);
845
+ return this.unwrap(this.api.GET("/api/core/v1/metrics/usageMetric", { params: { query: params } }));
1709
846
  }
1710
847
  };
1711
848
 
@@ -1715,29 +852,20 @@ var UsersResource = class extends BaseResource {
1715
852
  * List organization users with optional pagination
1716
853
  */
1717
854
  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
- };
855
+ return this.unwrap(this.api.GET("/users", { params: { query: params } }));
1725
856
  }
1726
857
  /**
1727
- * Retrieve a single user by ID
858
+ * Get a single user by ID
1728
859
  */
1729
- async retrieve(userId) {
1730
- return this.get(`/users/${userId}`);
860
+ async get(userId) {
861
+ return this.unwrap(this.api.GET("/users/{id}", { params: { path: { id: userId } } }));
1731
862
  }
1732
863
  };
1733
864
 
1734
865
  // src/resources/me.ts
1735
866
  var MeResource = class extends BaseResource {
1736
- /**
1737
- * Get current user and organization info
1738
- */
1739
- async retrieve() {
1740
- return this.client.get("/me");
867
+ async get() {
868
+ return this.unwrap(this.untypedApi.GET("/me", {}));
1741
869
  }
1742
870
  };
1743
871
 
@@ -1746,206 +874,77 @@ var OrganizationResource = class extends BaseResource {
1746
874
  /**
1747
875
  * Get organization details
1748
876
  */
1749
- async retrieve() {
1750
- return this.client.get("/organization");
877
+ async get() {
878
+ return this.unwrap(this.api.GET("/organization"));
1751
879
  }
1752
880
  };
1753
881
 
1754
882
  // src/resources/agents.ts
1755
883
  var AgentsResource = class extends BaseResource {
1756
- /**
1757
- * List support agents
1758
- */
1759
884
  async list() {
1760
- return this.get("/agents");
885
+ return this.unwrap(this.untypedApi.GET("/agents", {}));
1761
886
  }
1762
- /**
1763
- * Retrieve a specific agent by ID
1764
- */
1765
- async retrieve(agentId) {
1766
- return this.get(`/agents/${agentId}`);
887
+ async get(agentId) {
888
+ return this.unwrap(this.untypedApi.GET("/agents/{id}", { params: { path: { id: agentId } } }));
1767
889
  }
1768
- /**
1769
- * Create a new agent
1770
- */
1771
890
  async create(params) {
1772
- return this.post("/agents", params);
891
+ return this.unwrap(this.untypedApi.POST("/agents", { body: params }));
1773
892
  }
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
893
  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
- }
894
+ return this.unwrap(this.untypedApi.POST("/agents/find_or_create", { body: params }));
1797
895
  }
1798
896
  };
1799
897
 
1800
898
  // src/resources/docs.ts
1801
899
  var DocsResource = class extends BaseResource {
1802
- // ========== Collections ==========
1803
- /**
1804
- * List all doc collections
1805
- */
1806
- async listCollections() {
1807
- return this.get("/docs/collections");
900
+ // Collections
901
+ async listCollections(params) {
902
+ return this.unwrap(this.api.GET("/docs/collections", { params: { query: params } }));
1808
903
  }
1809
- /**
1810
- * Retrieve a single doc collection
1811
- */
1812
- async retrieveCollection(collectionId) {
1813
- return this.get(
1814
- `/docs/collections/${collectionId}`
1815
- );
1816
- }
1817
- /**
1818
- * Create a new doc collection
1819
- */
1820
904
  async createCollection(data) {
1821
- return this.post("/docs/collections", data);
905
+ return this.unwrap(this.api.POST("/docs/collections", { body: data }));
1822
906
  }
1823
- /**
1824
- * Update a doc collection
1825
- */
1826
907
  async updateCollection(collectionId, data) {
1827
- return this.put(
1828
- `/docs/collections/${collectionId}`,
1829
- data
1830
- );
908
+ return this.unwrap(this.api.PUT("/docs/collections/{collection_id}", { params: { path: { collection_id: collectionId } }, body: data }));
1831
909
  }
1832
- /**
1833
- * Delete a doc collection
1834
- */
1835
910
  async deleteCollection(collectionId) {
1836
- return this._delete(`/docs/collections/${collectionId}`);
911
+ return this.unwrap(this.api.DELETE("/docs/collections/{collection_id}", { params: { path: { collection_id: collectionId } } }));
1837
912
  }
1838
- // ========== Groups ==========
1839
- /**
1840
- * List all doc groups
1841
- */
1842
- async listGroups() {
1843
- return this.get("/docs/groups");
913
+ // Groups
914
+ async listGroups(params) {
915
+ return this.unwrap(this.api.GET("/docs/groups", { params: { query: params } }));
1844
916
  }
1845
- /**
1846
- * Retrieve a single doc group
1847
- */
1848
- async retrieveGroup(groupId) {
1849
- return this.get(`/docs/groups/${groupId}`);
1850
- }
1851
- /**
1852
- * Create a new doc group
1853
- */
1854
917
  async createGroup(data) {
1855
- return this.post("/docs/groups", data);
918
+ return this.unwrap(this.api.POST("/docs/groups", { body: data }));
1856
919
  }
1857
- /**
1858
- * Update a doc group
1859
- */
1860
920
  async updateGroup(groupId, data) {
1861
- return this.put(`/docs/groups/${groupId}`, data);
921
+ return this.unwrap(this.api.PUT("/docs/groups/{group_id}", { params: { path: { group_id: groupId } }, body: data }));
1862
922
  }
1863
- /**
1864
- * Delete a doc group
1865
- */
1866
923
  async deleteGroup(groupId) {
1867
- return this._delete(`/docs/groups/${groupId}`);
924
+ return this.unwrap(this.api.DELETE("/docs/groups/{group_id}", { params: { path: { group_id: groupId } } }));
1868
925
  }
1869
- // ========== Pages ==========
1870
- /**
1871
- * List doc pages with optional filters
1872
- */
926
+ // Pages
1873
927
  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
- };
928
+ return this.unwrap(this.api.GET("/docs/pages", { params: { query: params } }));
1880
929
  }
1881
- /**
1882
- * Retrieve a single doc page
1883
- */
1884
- async retrievePage(pageId) {
1885
- return this.get(`/docs/pages/${pageId}`);
930
+ async getPage(pageId) {
931
+ return this.unwrap(this.api.GET("/docs/pages/{page_id}", { params: { path: { page_id: pageId } } }));
1886
932
  }
1887
- /**
1888
- * Create a new doc page
1889
- */
1890
933
  async createPage(data) {
1891
- return this.post("/docs/pages", data);
934
+ return this.unwrap(this.api.POST("/docs/pages", { body: data }));
1892
935
  }
1893
- /**
1894
- * Update a doc page
1895
- */
1896
936
  async updatePage(pageId, data) {
1897
- return this.put(`/docs/pages/${pageId}`, data);
1898
- }
1899
- /**
1900
- * Publish a doc page
1901
- */
1902
- async publishPage(pageId) {
1903
- return this.post(`/docs/pages/${pageId}/publish`, {});
1904
- }
1905
- /**
1906
- * Archive a doc page
1907
- */
1908
- async archivePage(pageId) {
1909
- return this.post(`/docs/pages/${pageId}/archive`, {});
937
+ return this.unwrap(this.api.PUT("/docs/pages/{page_id}", { params: { path: { page_id: pageId } }, body: data }));
1910
938
  }
1911
- /**
1912
- * Delete a doc page
1913
- */
1914
939
  async deletePage(pageId) {
1915
- return this._delete(`/docs/pages/${pageId}`);
940
+ return this.unwrap(this.api.DELETE("/docs/pages/{page_id}", { params: { path: { page_id: pageId } } }));
1916
941
  }
1917
- // ========== Tree ==========
1918
- /**
1919
- * Get the full documentation tree structure
1920
- */
1921
- async getTree() {
1922
- return this.get("/docs/tree");
1923
- }
1924
- // ========== Repositories ==========
1925
- /**
1926
- * List all doc repositories
1927
- */
942
+ // Repositories
1928
943
  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
- };
944
+ return this.unwrap(this.api.GET("/docs/repositories", { params: { query: params } }));
1940
945
  }
1941
- /**
1942
- * Retrieve a single doc repository
1943
- */
1944
- async retrieveRepository(repositoryId, params) {
1945
- return this.get(
1946
- `/docs/repositories/${repositoryId}`,
1947
- params
1948
- );
946
+ async getRepository(repositoryId, params) {
947
+ return this.unwrap(this.api.GET("/docs/repositories/{id}", { params: { path: { id: repositoryId }, query: params } }));
1949
948
  }
1950
949
  };
1951
950
 
@@ -1956,50 +955,17 @@ var EntitiesResource = class extends BaseResource {
1956
955
  * Returns entities with a _type discriminator field
1957
956
  */
1958
957
  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
- };
958
+ return this.unwrap(this.api.GET("/entities", { params: { query: params } }));
1967
959
  }
1968
960
  };
1969
961
 
1970
962
  // src/resources/custom-data.ts
1971
963
  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);
964
+ async set(data) {
965
+ return this.unwrap(this.api.PUT("/custom_data", { body: data }));
1980
966
  }
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
967
  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
- );
968
+ return this.unwrap(this.api.GET("/custom_data", { params: { query: params } }));
2003
969
  }
2004
970
  };
2005
971
 
@@ -2009,130 +975,56 @@ var TimelineCommentsResource = class extends BaseResource {
2009
975
  * List timeline comments with optional filters and pagination
2010
976
  */
2011
977
  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
- };
978
+ return this.unwrap(this.api.GET("/timeline_comments", { params: { query: params } }));
2023
979
  }
2024
980
  /**
2025
- * Retrieve a single timeline comment by ID
981
+ * Get a single timeline comment by ID
2026
982
  */
2027
- async retrieve(id) {
2028
- return this.get(
2029
- `/timeline_comments/${id}`
2030
- );
983
+ async get(id) {
984
+ return this.unwrap(this.api.GET("/timeline_comments/{id}", { params: { path: { id } } }));
2031
985
  }
2032
986
  /**
2033
987
  * Create a new timeline comment
2034
988
  */
2035
989
  async create(data) {
2036
- return this.post("/timeline_comments", data);
990
+ return this.unwrap(this.api.POST("/timeline_comments", { body: data }));
2037
991
  }
2038
992
  /**
2039
993
  * Update an existing timeline comment
2040
994
  */
2041
995
  async update(id, data) {
2042
- return this.put(
2043
- `/timeline_comments/${id}`,
2044
- data
2045
- );
996
+ return this.unwrap(this.api.PUT("/timeline_comments/{id}", { params: { path: { id } }, body: data }));
2046
997
  }
2047
998
  /**
2048
999
  * Delete a timeline comment
2049
1000
  */
2050
- async del(id) {
2051
- return this._delete(`/timeline_comments/${id}`);
1001
+ async del(id, data) {
1002
+ return this.unwrap(this.api.DELETE("/timeline_comments/{id}", { params: { path: { id } }, body: data }));
2052
1003
  }
2053
1004
  };
2054
1005
 
2055
1006
  // src/resources/lists.ts
2056
1007
  var ListsResource = class extends BaseResource {
2057
- /**
2058
- * List all lists
2059
- *
2060
- * @param params - Optional list parameters
2061
- * @returns Paginated list of lists
2062
- */
2063
1008
  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
- };
1009
+ return this.unwrap(this.api.GET("/lists", { params: { query: params } }));
2071
1010
  }
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
- };
1011
+ async get(listId) {
1012
+ return this.unwrap(this.api.GET("/lists/{id}", { params: { path: { id: listId } } }));
2088
1013
  }
2089
- /**
2090
- * Create a new list
2091
- *
2092
- * @param data - List creation parameters
2093
- * @returns The created list
2094
- */
2095
1014
  async create(data) {
2096
- return this.post("/lists", data);
1015
+ return this.unwrap(this.api.POST("/lists", { body: data }));
2097
1016
  }
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
1017
  async update(listId, data) {
2106
- return this.put(`/lists/${listId}`, data);
1018
+ return this.unwrap(this.api.PUT("/lists/{id}", { params: { path: { id: listId } }, body: data }));
2107
1019
  }
2108
- /**
2109
- * Delete a list
2110
- *
2111
- * @param listId - The ID of the list to delete
2112
- * @returns Delete confirmation
2113
- */
2114
1020
  async del(listId) {
2115
- return this._delete(`/lists/${listId}`);
1021
+ return this.unwrap(this.api.DELETE("/lists/{id}", { params: { path: { id: listId } } }));
2116
1022
  }
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
1023
  async addEntities(listId, data) {
2125
- return this.post(`/lists/${listId}/add`, data);
1024
+ return this.unwrap(this.api.POST("/lists/{id}/add", { params: { path: { id: listId } }, body: data }));
2126
1025
  }
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
1026
  async removeEntities(listId, data) {
2135
- return this.post(`/lists/${listId}/remove`, data);
1027
+ return this.unwrap(this.api.POST("/lists/{id}/remove", { params: { path: { id: listId } }, body: data }));
2136
1028
  }
2137
1029
  };
2138
1030
 
@@ -2142,727 +1034,172 @@ var JournalEntriesResource = class extends BaseResource {
2142
1034
  * List journal entries with optional filters and pagination
2143
1035
  */
2144
1036
  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
- };
1037
+ return this.unwrap(this.api.GET("/journal_entries", { params: { query: params } }));
2156
1038
  }
2157
1039
  /**
2158
- * Retrieve a single journal entry by ID
1040
+ * Get a single journal entry by ID
2159
1041
  */
2160
- async retrieve(entryId) {
2161
- return this.get(
2162
- `/journal_entries/${entryId}`
2163
- );
1042
+ async get(entryId, params) {
1043
+ return this.unwrap(this.api.GET("/journal_entries/{id}", { params: { path: { id: entryId }, query: params } }));
2164
1044
  }
2165
1045
  /**
2166
1046
  * Create a new journal entry
2167
1047
  */
2168
1048
  async create(data) {
2169
- return this.post("/journal_entries", data);
1049
+ return this.unwrap(this.api.POST("/journal_entries", { body: data }));
2170
1050
  }
2171
1051
  /**
2172
1052
  * Update an existing journal entry
2173
1053
  */
2174
1054
  async update(entryId, data) {
2175
- return this.put(
2176
- `/journal_entries/${entryId}`,
2177
- data
2178
- );
1055
+ return this.unwrap(this.api.PUT("/journal_entries/{id}", { params: { path: { id: entryId } }, body: data }));
2179
1056
  }
2180
1057
  /**
2181
1058
  * Delete a journal entry
2182
1059
  */
2183
1060
  async del(entryId) {
2184
- return this._delete(`/journal_entries/${entryId}`);
1061
+ return this.unwrap(this.api.DELETE("/journal_entries/{id}", { params: { path: { id: entryId } } }));
2185
1062
  }
2186
1063
  };
2187
1064
 
2188
1065
  // src/resources/email-unsubscribe-groups.ts
2189
1066
  var EmailUnsubscribeGroupsResource = class extends BaseResource {
2190
- /**
2191
- * List all email unsubscribe groups
2192
- */
2193
1067
  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
- };
1068
+ return this.unwrap(this.api.GET("/email/unsubscribe_groups", { params: { query: params } }));
2205
1069
  }
2206
- /**
2207
- * Retrieve a single unsubscribe group
2208
- */
2209
- async retrieve(groupId) {
2210
- return this.get(
2211
- `/email/unsubscribe_groups/${groupId}`
2212
- );
2213
- }
2214
- // ========== Members ==========
2215
- /**
2216
- * List members of an unsubscribe group
2217
- */
2218
1070
  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
- };
1071
+ return this.unwrap(this.api.GET("/email/unsubscribe_groups/{id}/members", { params: { path: { id: groupId }, query: params } }));
2230
1072
  }
2231
- /**
2232
- * Add members to an unsubscribe group by email addresses
2233
- */
2234
1073
  async addMembers(groupId, data) {
2235
- return this.post(
2236
- `/email/unsubscribe_groups/${groupId}/members`,
2237
- data
2238
- );
1074
+ return this.unwrap(this.api.POST("/email/unsubscribe_groups/{id}/members", { params: { path: { id: groupId } }, body: data }));
2239
1075
  }
2240
- /**
2241
- * Remove members from an unsubscribe group by email addresses
2242
- */
2243
1076
  async removeMembers(groupId, data) {
2244
- return this._delete(
2245
- `/email/unsubscribe_groups/${groupId}/members?emails=${encodeURIComponent(data.emails.join(","))}`
2246
- );
1077
+ return this.unwrap(this.api.DELETE("/email/unsubscribe_groups/{id}/members", { params: { path: { id: groupId } }, body: data }));
2247
1078
  }
2248
- /**
2249
- * Remove a single member from an unsubscribe group by member ID
2250
- */
2251
1079
  async removeMember(groupId, memberId) {
2252
- return this._delete(
2253
- `/email/unsubscribe_groups/${groupId}/members/${memberId}`
2254
- );
1080
+ return this.unwrap(this.api.DELETE("/email/unsubscribe_groups/{id}/members/{member_id}", { params: { path: { id: groupId, member_id: memberId } } }));
2255
1081
  }
2256
1082
  };
2257
1083
 
2258
1084
  // src/resources/flow-extensions.ts
2259
1085
  var FlowExtensionsResource = class extends BaseResource {
2260
- // ========== Actions ==========
2261
- /**
2262
- * List flow extension actions
2263
- */
1086
+ // Actions
2264
1087
  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
- };
2276
- }
2277
- /**
2278
- * Retrieve a single flow extension action
2279
- */
2280
- async retrieveAction(actionId) {
2281
- return this.get(
2282
- `/flow/extensions/actions/${actionId}`
2283
- );
1088
+ return this.unwrap(this.api.GET("/flow/extensions/actions", { params: { query: params } }));
2284
1089
  }
2285
- /**
2286
- * Create a new flow extension action
2287
- */
2288
1090
  async createAction(data) {
2289
- return this.post(
2290
- "/flow/extensions/actions",
2291
- data
2292
- );
1091
+ return this.unwrap(this.api.POST("/flow/extensions/actions", { body: data }));
2293
1092
  }
2294
- /**
2295
- * Update an existing flow extension action
2296
- */
2297
1093
  async updateAction(actionId, data) {
2298
- return this.put(
2299
- `/flow/extensions/actions/${actionId}`,
2300
- data
2301
- );
1094
+ return this.unwrap(this.api.PUT("/flow/extensions/actions/{id}", { params: { path: { id: actionId } }, body: data }));
2302
1095
  }
2303
- /**
2304
- * Delete a flow extension action
2305
- */
2306
1096
  async deleteAction(actionId) {
2307
- return this._delete(
2308
- `/flow/extensions/actions/${actionId}`
2309
- );
1097
+ return this.unwrap(this.api.DELETE("/flow/extensions/actions/{id}", { params: { path: { id: actionId } } }));
2310
1098
  }
2311
- // ========== Action Runs ==========
2312
- /**
2313
- * Update a flow action run status
2314
- * Used to report completion or failure of async action execution
2315
- */
1099
+ // Action Runs
2316
1100
  async updateActionRun(runId, data) {
2317
- return this.put(`/flow/actions/runs/${runId}`, data);
1101
+ return this.unwrap(this.api.PUT("/flow/actions/runs/{id}", { params: { path: { id: runId } }, body: data }));
1102
+ }
1103
+ // Triggers
1104
+ async listTriggers() {
1105
+ return this.unwrap(this.api.GET("/flow/extensions/triggers"));
1106
+ }
1107
+ async getTrigger(handle) {
1108
+ return this.unwrap(this.api.GET("/flow/extensions/triggers/{handle}", { params: { path: { handle } } }));
1109
+ }
1110
+ async createTrigger(data) {
1111
+ return this.unwrap(this.api.POST("/flow/extensions/triggers", { body: data }));
1112
+ }
1113
+ async updateTrigger(handle, data) {
1114
+ return this.unwrap(this.api.PUT("/flow/extensions/triggers/{handle}", { params: { path: { handle } }, body: data }));
1115
+ }
1116
+ async deleteTrigger(handle) {
1117
+ return this.unwrap(this.api.DELETE("/flow/extensions/triggers/{handle}", { params: { path: { handle } } }));
1118
+ }
1119
+ async fireTrigger(handle, data) {
1120
+ return this.unwrap(this.api.POST("/flow/extensions/triggers/{handle}/fire", { params: { path: { handle } }, body: data }));
2318
1121
  }
2319
1122
  };
2320
1123
 
2321
1124
  // src/resources/ai-agent-runs.ts
2322
1125
  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
1126
  async create(agentId, data) {
2329
- return this.post(
2330
- `/ai/agents/${agentId}/runs`,
2331
- data || {}
2332
- );
1127
+ return this.unwrap(this.api.POST("/ai/agents/{agentId}/runs", { params: { path: { agentId } }, body: data }));
2333
1128
  }
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
- );
1129
+ async get(agentId, runId) {
1130
+ return this.unwrap(this.api.GET("/ai/agents/{agentId}/runs/{runId}", { params: { path: { agentId, runId } } }));
2342
1131
  }
2343
1132
  /**
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
1133
+ * Create an agent run and poll until it completes or errors.
2351
1134
  */
2352
1135
  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;
1136
+ const { timeout = 3e5, pollInterval = 2e3 } = options || {};
1137
+ const result = await this.create(agentId, data);
1138
+ const run = result.run;
1139
+ if (!run?.id) throw new Error("Agent run ID not returned");
1140
+ const start = Date.now();
1141
+ while (Date.now() - start < timeout) {
1142
+ const response = await this.get(agentId, run.id);
1143
+ const agentRun = response.run;
1144
+ if (agentRun.status === "completed" || agentRun.status === "error") {
1145
+ return agentRun;
2361
1146
  }
2362
1147
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
2363
1148
  }
2364
- throw new Error(
2365
- `Agent run ${run.id} did not complete within ${timeout}ms timeout`
2366
- );
1149
+ throw new Error(`Agent run timed out after ${timeout}ms`);
2367
1150
  }
2368
1151
  };
2369
1152
 
2370
1153
  // src/resources/meetings.ts
2371
1154
  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
- */
2390
1155
  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
- };
1156
+ return this.unwrap(this.api.GET("/meetings", { params: { query: params } }));
2400
1157
  }
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}`);
1158
+ async get(meetingId) {
1159
+ return this.unwrap(this.api.GET("/meetings/{id}", { params: { path: { id: meetingId } } }));
2415
1160
  }
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
1161
  async create(data) {
2455
- return this.post("/meetings", data);
1162
+ return this.unwrap(this.api.POST("/meetings", { body: data }));
2456
1163
  }
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
1164
  async update(meetingId, data) {
2474
- return this.put(`/meetings/${meetingId}`, data);
1165
+ return this.unwrap(this.api.PUT("/meetings/{id}", { params: { path: { id: meetingId } }, body: data }));
2475
1166
  }
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
1167
  async del(meetingId) {
2488
- return this._delete(`/meetings/${meetingId}`);
2489
- }
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
- );
2521
- }
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);
2545
- }
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
- );
2581
- }
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
- );
2626
- }
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
- );
2648
- }
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
- );
2682
- }
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
- );
1168
+ return this.unwrap(this.api.DELETE("/meetings/{id}", { params: { path: { id: meetingId } } }));
2701
1169
  }
2702
1170
  };
2703
1171
 
2704
1172
  // src/resources/synced-emails.ts
2705
1173
  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
- */
2724
1174
  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
- };
1175
+ return this.unwrap(this.untypedApi.GET("/synced_emails", { params: { query: params } }));
2734
1176
  }
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}`);
1177
+ async get(syncedEmailId) {
1178
+ return this.unwrap(this.untypedApi.GET("/synced_emails/{id}", { params: { path: { id: syncedEmailId } } }));
2749
1179
  }
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
1180
  async create(data) {
2783
- return this.post("/synced_emails", data);
1181
+ return this.unwrap(this.untypedApi.POST("/synced_emails", { body: data }));
2784
1182
  }
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
1183
  async update(syncedEmailId, data) {
2801
- return this.put(`/synced_emails/${syncedEmailId}`, data);
1184
+ return this.unwrap(this.untypedApi.PUT("/synced_emails/{id}", { params: { path: { id: syncedEmailId } }, body: data }));
2802
1185
  }
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
1186
  async del(syncedEmailId) {
2815
- return this._delete(`/synced_emails/${syncedEmailId}`);
1187
+ return this.unwrap(this.untypedApi.DELETE("/synced_emails/{id}", { params: { path: { id: syncedEmailId } } }));
2816
1188
  }
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
1189
  async addMessages(syncedEmailId, data) {
2842
- return this.post(
2843
- `/synced_emails/${syncedEmailId}/messages`,
2844
- data
2845
- );
1190
+ return this.unwrap(this.untypedApi.POST("/synced_emails/{id}/messages", { params: { path: { id: syncedEmailId } }, body: data }));
2846
1191
  }
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
1192
  async getMessages(syncedEmailId) {
2859
- return this.get(
2860
- `/synced_emails/${syncedEmailId}/messages`
2861
- );
1193
+ return this.unwrap(this.untypedApi.GET("/synced_emails/{id}/messages", { params: { path: { id: syncedEmailId } } }));
2862
1194
  }
2863
1195
  };
2864
1196
 
2865
1197
  // src/client.ts
1198
+ function createTimeoutSignal(ms) {
1199
+ const controller = new AbortController();
1200
+ setTimeout(() => controller.abort(), ms);
1201
+ return controller.signal;
1202
+ }
2866
1203
  var MantleCoreClient = class {
2867
1204
  constructor(config) {
2868
1205
  if (!config.apiKey && !config.accessToken) {
@@ -2870,18 +1207,35 @@ var MantleCoreClient = class {
2870
1207
  "MantleCoreClient requires either apiKey or accessToken"
2871
1208
  );
2872
1209
  }
2873
- this.baseURL = config.baseURL || "https://api.heymantle.com/v1";
2874
1210
  this.apiKey = config.apiKey;
2875
1211
  this.accessToken = config.accessToken;
2876
- this.timeout = config.timeout || 3e4;
2877
- this.middlewareManager = new MiddlewareManager();
1212
+ const timeoutMs = config.timeout ?? 3e4;
1213
+ this._api = (0, import_openapi_fetch.default)({
1214
+ baseUrl: config.baseURL || "https://api.heymantle.com/v1",
1215
+ headers: {
1216
+ "Content-Type": "application/json"
1217
+ }
1218
+ });
1219
+ this._api.use({
1220
+ onRequest: ({ request }) => {
1221
+ const token = this.accessToken || this.apiKey;
1222
+ if (token) {
1223
+ request.headers.set("Authorization", `Bearer ${token}`);
1224
+ }
1225
+ return request;
1226
+ }
1227
+ });
1228
+ if (timeoutMs > 0) {
1229
+ this._api.use({
1230
+ onRequest: ({ request }) => {
1231
+ const signal = typeof AbortSignal !== "undefined" && "timeout" in AbortSignal ? AbortSignal.timeout(timeoutMs) : createTimeoutSignal(timeoutMs);
1232
+ return new Request(request, { signal });
1233
+ }
1234
+ });
1235
+ }
2878
1236
  if (config.middleware) {
2879
1237
  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
- }
1238
+ this._api.use(mw);
2885
1239
  }
2886
1240
  }
2887
1241
  this.customers = new CustomersResource(this);
@@ -2924,39 +1278,21 @@ var MantleCoreClient = class {
2924
1278
  this.syncedEmails = new SyncedEmailsResource(this);
2925
1279
  }
2926
1280
  /**
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
- * ```
1281
+ * Register an openapi-fetch middleware
2941
1282
  */
2942
- use(middleware, options) {
2943
- this.middlewareManager.use(middleware, options);
1283
+ use(middleware) {
1284
+ this._api.use(middleware);
2944
1285
  return this;
2945
1286
  }
2946
1287
  /**
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
1288
+ * Remove a registered middleware
2951
1289
  */
2952
- removeMiddleware(name) {
2953
- return this.middlewareManager.remove(name);
1290
+ eject(middleware) {
1291
+ this._api.eject(middleware);
1292
+ return this;
2954
1293
  }
2955
1294
  /**
2956
1295
  * Update authentication credentials
2957
- * Useful for middleware that needs to refresh tokens
2958
- *
2959
- * @param credentials - New credentials to set
2960
1296
  */
2961
1297
  updateAuth(credentials) {
2962
1298
  if (credentials.apiKey !== void 0) {
@@ -2966,234 +1302,43 @@ var MantleCoreClient = class {
2966
1302
  this.accessToken = credentials.accessToken;
2967
1303
  }
2968
1304
  }
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
1305
  };
3162
1306
 
3163
1307
  // src/middleware/auth-refresh.ts
3164
1308
  function createAuthRefreshMiddleware(options) {
3165
1309
  const {
3166
1310
  refreshToken,
1311
+ updateAuth,
3167
1312
  onRefreshSuccess,
3168
1313
  onRefreshFailed,
3169
1314
  maxRefreshAttempts = 1
3170
1315
  } = options;
3171
1316
  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
- }
1317
+ return {
1318
+ async onResponse({ request, response }) {
1319
+ if (response.status !== 401) return void 0;
3179
1320
  if (refreshAttempts >= maxRefreshAttempts) {
3180
1321
  refreshAttempts = 0;
3181
- throw error;
1322
+ return void 0;
3182
1323
  }
3183
1324
  refreshAttempts++;
3184
1325
  try {
3185
1326
  const newToken = await refreshToken();
3186
- ctx.updateAuth({ accessToken: newToken });
3187
- ctx.request.headers.Authorization = `Bearer ${newToken}`;
1327
+ updateAuth(newToken);
3188
1328
  onRefreshSuccess?.(newToken);
3189
- ctx.retry = true;
3190
1329
  refreshAttempts = 0;
1330
+ const headers = new Headers(request.headers);
1331
+ headers.set("Authorization", `Bearer ${newToken}`);
1332
+ return fetch(new Request(request.url, {
1333
+ method: request.method,
1334
+ headers,
1335
+ body: request.body,
1336
+ signal: request.signal
1337
+ }));
3191
1338
  } catch (refreshError) {
3192
1339
  refreshAttempts = 0;
3193
1340
  onRefreshFailed?.(refreshError);
3194
- throw new MantleAuthenticationError(
3195
- "Authentication failed. Please re-authenticate."
3196
- );
1341
+ return void 0;
3197
1342
  }
3198
1343
  }
3199
1344
  };
@@ -3208,69 +1353,52 @@ var RateLimiter = class {
3208
1353
  this.burstWindowMs = options.burstWindowMs;
3209
1354
  this.throttleThreshold = options.throttleThreshold;
3210
1355
  }
3211
- /**
3212
- * Prune timestamps older than the burst window
3213
- */
3214
1356
  prune() {
3215
- const now = Date.now();
3216
- const cutoff = now - this.burstWindowMs;
1357
+ const cutoff = Date.now() - this.burstWindowMs;
3217
1358
  this.timestamps = this.timestamps.filter((ts) => ts > cutoff);
3218
1359
  }
3219
- /**
3220
- * Get current usage statistics
3221
- */
3222
1360
  getUsage() {
3223
1361
  this.prune();
3224
- const now = Date.now();
3225
- const oneMinuteAgo = now - 6e4;
1362
+ const oneMinuteAgo = Date.now() - 6e4;
3226
1363
  const minuteUsage = this.timestamps.filter((ts) => ts > oneMinuteAgo).length;
3227
- const burstUsage = this.timestamps.length;
3228
- return { minuteUsage, burstUsage };
1364
+ return { minuteUsage, burstUsage: this.timestamps.length };
3229
1365
  }
3230
- /**
3231
- * Calculate the delay needed before the next request can be made
3232
- * Returns 0 if no delay is needed
3233
- */
3234
1366
  getDelay() {
3235
1367
  const { minuteUsage, burstUsage } = this.getUsage();
3236
1368
  const minuteThreshold = Math.floor(this.requestsPerMinute * this.throttleThreshold);
3237
1369
  const burstThreshold = Math.floor(this.burstLimit * this.throttleThreshold);
1370
+ const now = Date.now();
3238
1371
  if (minuteUsage >= minuteThreshold) {
3239
- const now = Date.now();
3240
1372
  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
- }
1373
+ const oldest = this.timestamps.find((ts) => ts > oneMinuteAgo);
1374
+ if (oldest) {
1375
+ const delay = oldest + 6e4 - now;
1376
+ if (delay > 0) return delay;
3247
1377
  }
3248
1378
  }
3249
1379
  if (burstUsage >= burstThreshold) {
3250
- const now = Date.now();
3251
1380
  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
- }
1381
+ const oldest = this.timestamps.find((ts) => ts > burstCutoff);
1382
+ if (oldest) {
1383
+ const delay = oldest + this.burstWindowMs - now;
1384
+ if (delay > 0) return delay;
3258
1385
  }
3259
1386
  }
3260
1387
  return 0;
3261
1388
  }
3262
- /**
3263
- * Record a request timestamp
3264
- */
3265
1389
  recordRequest() {
3266
1390
  this.timestamps.push(Date.now());
3267
1391
  }
3268
1392
  };
3269
- function calculateRetryDelay(retryAfter, retryCount, options) {
1393
+ function calculateRetryDelay(retryAfterHeader, retryCount, options) {
1394
+ if (retryAfterHeader) {
1395
+ const retryAfter = parseInt(retryAfterHeader, 10);
1396
+ if (!isNaN(retryAfter) && retryAfter > 0) {
1397
+ return retryAfter * 1e3;
1398
+ }
1399
+ }
3270
1400
  let delay;
3271
- if (retryAfter !== void 0 && retryAfter > 0) {
3272
- return retryAfter * 1e3;
3273
- } else if (options.exponentialBackoff) {
1401
+ if (options.exponentialBackoff) {
3274
1402
  delay = options.baseDelay * Math.pow(2, retryCount);
3275
1403
  } else {
3276
1404
  delay = options.baseDelay;
@@ -3294,37 +1422,42 @@ function createRateLimitMiddleware(options = {}) {
3294
1422
  burstWindowMs = 3e5,
3295
1423
  throttleThreshold = 0.9
3296
1424
  } = 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
- });
1425
+ const rateLimiter = enableThrottle ? new RateLimiter({ requestsPerMinute, burstLimit, burstWindowMs, throttleThreshold }) : null;
1426
+ let retryCount = 0;
1427
+ return {
1428
+ async onRequest({ request }) {
1429
+ if (rateLimiter) {
1430
+ const delay = rateLimiter.getDelay();
1431
+ if (delay > 0) {
3322
1432
  await new Promise((resolve) => setTimeout(resolve, delay));
3323
- ctx.retry = true;
3324
- return;
3325
1433
  }
3326
1434
  }
3327
- throw error;
1435
+ return request;
1436
+ },
1437
+ async onResponse({ request, response }) {
1438
+ rateLimiter?.recordRequest();
1439
+ if (response.status !== 429 || !enableRetry) return void 0;
1440
+ if (retryCount >= maxRetries) {
1441
+ retryCount = 0;
1442
+ return void 0;
1443
+ }
1444
+ const delay = calculateRetryDelay(
1445
+ response.headers.get("Retry-After"),
1446
+ retryCount,
1447
+ { baseDelay, exponentialBackoff, jitter }
1448
+ );
1449
+ retryCount++;
1450
+ await new Promise((resolve) => setTimeout(resolve, delay));
1451
+ const retryResponse = await fetch(new Request(request.url, {
1452
+ method: request.method,
1453
+ headers: request.headers,
1454
+ body: request.body,
1455
+ signal: request.signal
1456
+ }));
1457
+ if (retryResponse.status !== 429) {
1458
+ retryCount = 0;
1459
+ }
1460
+ return retryResponse;
3328
1461
  }
3329
1462
  };
3330
1463
  }
@@ -3336,6 +1469,7 @@ function createRateLimitMiddleware(options = {}) {
3336
1469
  AffiliateReferralsResource,
3337
1470
  AffiliatesResource,
3338
1471
  AgentsResource,
1472
+ AiAgentRunsResource,
3339
1473
  AppsResource,
3340
1474
  BaseResource,
3341
1475
  ChannelsResource,
@@ -3349,8 +1483,12 @@ function createRateLimitMiddleware(options = {}) {
3349
1483
  DealFlowsResource,
3350
1484
  DealsResource,
3351
1485
  DocsResource,
1486
+ EmailUnsubscribeGroupsResource,
3352
1487
  EntitiesResource,
1488
+ FlowExtensionsResource,
3353
1489
  FlowsResource,
1490
+ JournalEntriesResource,
1491
+ ListsResource,
3354
1492
  MantleAPIError,
3355
1493
  MantleAuthenticationError,
3356
1494
  MantleCoreClient,
@@ -3359,13 +1497,14 @@ function createRateLimitMiddleware(options = {}) {
3359
1497
  MantleRateLimitError,
3360
1498
  MantleValidationError,
3361
1499
  MeResource,
1500
+ MeetingsResource,
3362
1501
  MetricsResource,
3363
- MiddlewareManager,
3364
1502
  OrganizationResource,
3365
1503
  SubscriptionsResource,
3366
1504
  SyncedEmailsResource,
3367
1505
  TasksResource,
3368
1506
  TicketsResource,
1507
+ TimelineCommentsResource,
3369
1508
  TransactionsResource,
3370
1509
  UsageEventsResource,
3371
1510
  UsersResource,