@heymantle/core-api-client 0.1.0

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