@heymantle/core-api-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +333 -0
- package/dist/index.d.mts +2907 -0
- package/dist/index.d.ts +2907 -0
- package/dist/index.js +1846 -0
- package/dist/index.mjs +1784 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# @heymantle/core-api-client
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for the Mantle Core API. Built with a resource-based architecture similar to the Stripe SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @heymantle/core-api-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { MantleCoreClient } from '@heymantle/core-api-client';
|
|
15
|
+
|
|
16
|
+
const client = new MantleCoreClient({
|
|
17
|
+
apiKey: 'your-api-key',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// List customers
|
|
21
|
+
const { customers, hasNextPage } = await client.customers.list({ take: 25 });
|
|
22
|
+
|
|
23
|
+
// Get a specific customer
|
|
24
|
+
const { customer } = await client.customers.retrieve('cust_123');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Authentication
|
|
28
|
+
|
|
29
|
+
The client supports two authentication methods:
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// API Key (for server-side use)
|
|
33
|
+
const client = new MantleCoreClient({
|
|
34
|
+
apiKey: 'your-api-key',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// OAuth Access Token
|
|
38
|
+
const client = new MantleCoreClient({
|
|
39
|
+
accessToken: 'your-oauth-token',
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Resources
|
|
44
|
+
|
|
45
|
+
### Customers
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// List customers with filters
|
|
49
|
+
const { customers } = await client.customers.list({
|
|
50
|
+
take: 25,
|
|
51
|
+
search: 'acme',
|
|
52
|
+
appIds: ['app_123'],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Create a customer
|
|
56
|
+
const { customer } = await client.customers.create({
|
|
57
|
+
name: 'Acme Inc',
|
|
58
|
+
email: 'contact@acme.com',
|
|
59
|
+
tags: ['enterprise'],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Update a customer
|
|
63
|
+
const { customer } = await client.customers.update('cust_123', {
|
|
64
|
+
name: 'Acme Corporation',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Add/remove tags
|
|
68
|
+
await client.customers.addTags('cust_123', ['premium']);
|
|
69
|
+
await client.customers.removeTags('cust_123', ['trial']);
|
|
70
|
+
|
|
71
|
+
// Get customer timeline
|
|
72
|
+
const { events } = await client.customers.getTimeline('cust_123');
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Contacts
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const { contacts } = await client.contacts.list();
|
|
79
|
+
const { contact } = await client.contacts.create({
|
|
80
|
+
name: 'John Doe',
|
|
81
|
+
email: 'john@example.com',
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Subscriptions
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const { subscriptions } = await client.subscriptions.list({
|
|
89
|
+
appId: 'app_123',
|
|
90
|
+
active: true,
|
|
91
|
+
});
|
|
92
|
+
const { subscription } = await client.subscriptions.retrieve('sub_123');
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Apps & Plans
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// List apps
|
|
99
|
+
const { apps } = await client.apps.list();
|
|
100
|
+
|
|
101
|
+
// List plans for an app
|
|
102
|
+
const { plans } = await client.apps.listPlans('app_123');
|
|
103
|
+
|
|
104
|
+
// Create a plan
|
|
105
|
+
const { plan } = await client.apps.createPlan('app_123', {
|
|
106
|
+
name: 'Pro Plan',
|
|
107
|
+
amount: 2900,
|
|
108
|
+
currencyCode: 'USD',
|
|
109
|
+
interval: 'month',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Manage features
|
|
113
|
+
const { features } = await client.apps.listFeatures('app_123');
|
|
114
|
+
const { feature } = await client.apps.createFeature('app_123', {
|
|
115
|
+
name: 'API Access',
|
|
116
|
+
type: 'boolean',
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Deals
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const { deals } = await client.deals.list({
|
|
124
|
+
customerId: 'cust_123',
|
|
125
|
+
stage: 'negotiation',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const { deal } = await client.deals.create({
|
|
129
|
+
name: 'Enterprise Deal',
|
|
130
|
+
amount: 50000,
|
|
131
|
+
customerId: 'cust_123',
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Tickets
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const { tickets } = await client.tickets.list({
|
|
139
|
+
status: 'open',
|
|
140
|
+
priority: 'high',
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const { ticket } = await client.tickets.create({
|
|
144
|
+
subject: 'Need help with integration',
|
|
145
|
+
customerId: 'cust_123',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Add a message
|
|
149
|
+
const { message } = await client.tickets.createMessage('ticket_123', {
|
|
150
|
+
body: 'Here is the solution...',
|
|
151
|
+
from: 'agent',
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Metrics
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Get MRR
|
|
159
|
+
const mrr = await client.metrics.mrr({
|
|
160
|
+
appId: 'app_123',
|
|
161
|
+
dateRange: 'last_30_days',
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Get ARR
|
|
165
|
+
const arr = await client.metrics.arr({ appId: 'app_123' });
|
|
166
|
+
|
|
167
|
+
// Other metrics
|
|
168
|
+
const arpu = await client.metrics.arpu({ appId: 'app_123' });
|
|
169
|
+
const churn = await client.metrics.revenueChurn({ appId: 'app_123' });
|
|
170
|
+
const ltv = await client.metrics.ltv({ appId: 'app_123' });
|
|
171
|
+
const nrr = await client.metrics.netRevenueRetention({ appId: 'app_123' });
|
|
172
|
+
|
|
173
|
+
// Custom metric query
|
|
174
|
+
const data = await client.metrics.fetch({
|
|
175
|
+
metric: 'PlatformApp.activeInstalls',
|
|
176
|
+
appId: 'app_123',
|
|
177
|
+
dateRange: 'last_90_days',
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Usage Events
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
// Track a single event
|
|
185
|
+
await client.usageEvents.create({
|
|
186
|
+
eventName: 'api_call',
|
|
187
|
+
customerId: 'cust_123',
|
|
188
|
+
appId: 'app_123',
|
|
189
|
+
properties: { endpoint: '/users', method: 'GET' },
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Track multiple events
|
|
193
|
+
await client.usageEvents.create({
|
|
194
|
+
events: [
|
|
195
|
+
{ eventName: 'api_call', customerId: 'cust_123', appId: 'app_123' },
|
|
196
|
+
{ eventName: 'api_call', customerId: 'cust_456', appId: 'app_123' },
|
|
197
|
+
],
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Webhooks
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
const { webhooks } = await client.webhooks.list();
|
|
205
|
+
|
|
206
|
+
const { webhook } = await client.webhooks.create({
|
|
207
|
+
topic: 'customer.created',
|
|
208
|
+
address: 'https://your-app.com/webhooks',
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Affiliates
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
const { affiliates } = await client.affiliates.list({
|
|
216
|
+
status: 'active',
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const { affiliatePrograms } = await client.affiliatePrograms.list();
|
|
220
|
+
const { commissions } = await client.affiliateCommissions.list();
|
|
221
|
+
const { payouts } = await client.affiliatePayouts.list();
|
|
222
|
+
const { referrals } = await client.affiliateReferrals.list();
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Other Resources
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
// Current user & organization
|
|
229
|
+
const { user, organization } = await client.me.retrieve();
|
|
230
|
+
const { organization } = await client.organization.retrieve();
|
|
231
|
+
|
|
232
|
+
// Users
|
|
233
|
+
const { users } = await client.users.list();
|
|
234
|
+
|
|
235
|
+
// Companies
|
|
236
|
+
const { companies } = await client.companies.list();
|
|
237
|
+
|
|
238
|
+
// Customer segments
|
|
239
|
+
const { customerSegments } = await client.customerSegments.list();
|
|
240
|
+
|
|
241
|
+
// Tasks
|
|
242
|
+
const { tasks } = await client.tasks.list({ status: 'pending' });
|
|
243
|
+
|
|
244
|
+
// Flows (automation)
|
|
245
|
+
const { flows } = await client.flows.list();
|
|
246
|
+
|
|
247
|
+
// Transactions & Charges
|
|
248
|
+
const { transactions } = await client.transactions.list();
|
|
249
|
+
const { charges } = await client.charges.list();
|
|
250
|
+
|
|
251
|
+
// Documentation
|
|
252
|
+
const { collections } = await client.docs.listCollections();
|
|
253
|
+
const { pages } = await client.docs.listPages();
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Pagination
|
|
257
|
+
|
|
258
|
+
All list methods return pagination metadata:
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
const { customers, hasNextPage, hasPreviousPage, cursor, total } =
|
|
262
|
+
await client.customers.list({ take: 25 });
|
|
263
|
+
|
|
264
|
+
// Fetch next page
|
|
265
|
+
if (hasNextPage) {
|
|
266
|
+
const nextPage = await client.customers.list({ take: 25, cursor });
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Error Handling
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import {
|
|
274
|
+
MantleAPIError,
|
|
275
|
+
MantleAuthenticationError,
|
|
276
|
+
MantlePermissionError,
|
|
277
|
+
MantleValidationError,
|
|
278
|
+
MantleRateLimitError,
|
|
279
|
+
} from '@heymantle/core-api-client';
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
await client.customers.retrieve('invalid_id');
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (error instanceof MantleAuthenticationError) {
|
|
285
|
+
// Handle authentication error (401)
|
|
286
|
+
} else if (error instanceof MantlePermissionError) {
|
|
287
|
+
// Handle permission error (403)
|
|
288
|
+
} else if (error instanceof MantleValidationError) {
|
|
289
|
+
// Handle validation error (422)
|
|
290
|
+
console.log(error.details);
|
|
291
|
+
} else if (error instanceof MantleRateLimitError) {
|
|
292
|
+
// Handle rate limit (429)
|
|
293
|
+
console.log(`Retry after: ${error.retryAfter}s`);
|
|
294
|
+
} else if (error instanceof MantleAPIError) {
|
|
295
|
+
// Handle other API errors
|
|
296
|
+
console.log(error.statusCode, error.message);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## TypeScript Support
|
|
302
|
+
|
|
303
|
+
All types are exported for use in your application:
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
import type {
|
|
307
|
+
Customer,
|
|
308
|
+
CustomerCreateParams,
|
|
309
|
+
Deal,
|
|
310
|
+
Subscription,
|
|
311
|
+
MetricsResponse,
|
|
312
|
+
// ... and many more
|
|
313
|
+
} from '@heymantle/core-api-client';
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Configuration Options
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
const client = new MantleCoreClient({
|
|
320
|
+
// Required: one of apiKey or accessToken
|
|
321
|
+
apiKey: 'your-api-key',
|
|
322
|
+
|
|
323
|
+
// Optional: custom base URL (defaults to https://api.heymantle.com/v1)
|
|
324
|
+
baseURL: 'https://api.heymantle.com/v1',
|
|
325
|
+
|
|
326
|
+
// Optional: request timeout in ms (defaults to 30000)
|
|
327
|
+
timeout: 30000,
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
MIT
|