crovver-node 1.0.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/CHANGELOG.md +111 -0
- package/LICENSE +21 -0
- package/README.md +271 -0
- package/dist/cjs/constants.js +5 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.js +479 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/constants.js +2 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.js +471 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/index.d.ts +582 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { CROVVER_BASE_URL } from "./constants";
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for Crovver API errors
|
|
5
|
+
*/
|
|
6
|
+
export class CrovverError extends Error {
|
|
7
|
+
constructor(message, statusCode, code, originalError) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "CrovverError";
|
|
10
|
+
this.statusCode = statusCode;
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.originalError = originalError;
|
|
13
|
+
this.isRetryable = CrovverError.isRetryableStatus(statusCode);
|
|
14
|
+
// Maintains proper stack trace for where error was thrown (V8 engines)
|
|
15
|
+
if (Error.captureStackTrace) {
|
|
16
|
+
Error.captureStackTrace(this, CrovverError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if a status code indicates a retryable error
|
|
21
|
+
* - 5xx: Server errors (temporary)
|
|
22
|
+
* - 429: Rate limited
|
|
23
|
+
* - 408: Request timeout
|
|
24
|
+
* - undefined: Network errors
|
|
25
|
+
*/
|
|
26
|
+
static isRetryableStatus(status) {
|
|
27
|
+
if (!status)
|
|
28
|
+
return true; // Network errors are retryable
|
|
29
|
+
return status >= 500 || status === 429 || status === 408;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert to JSON for logging
|
|
33
|
+
*/
|
|
34
|
+
toJSON() {
|
|
35
|
+
return {
|
|
36
|
+
name: this.name,
|
|
37
|
+
message: this.message,
|
|
38
|
+
statusCode: this.statusCode,
|
|
39
|
+
code: this.code,
|
|
40
|
+
isRetryable: this.isRetryable,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function sleep(ms) {
|
|
45
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
46
|
+
}
|
|
47
|
+
function calculateBackoff(attempt, baseDelay, maxDelay) {
|
|
48
|
+
const delay = Math.min(baseDelay * Math.pow(2, attempt), maxDelay);
|
|
49
|
+
// Add jitter (±25%)
|
|
50
|
+
const jitter = delay * 0.25 * (Math.random() * 2 - 1);
|
|
51
|
+
return Math.round(delay + jitter);
|
|
52
|
+
}
|
|
53
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
54
|
+
// CROVVER CLIENT
|
|
55
|
+
// ════════════════════════════════════════════════════════════════════════
|
|
56
|
+
export class CrovverClient {
|
|
57
|
+
constructor(config) {
|
|
58
|
+
if (!config.apiKey) {
|
|
59
|
+
throw new Error("CrovverConfig.apiKey is required");
|
|
60
|
+
}
|
|
61
|
+
this.config = {
|
|
62
|
+
...config,
|
|
63
|
+
maxRetries: config.maxRetries ?? 3,
|
|
64
|
+
debug: config.debug ?? false,
|
|
65
|
+
};
|
|
66
|
+
this.logger =
|
|
67
|
+
config.logger ||
|
|
68
|
+
((message, data) => {
|
|
69
|
+
if (this.config.debug) {
|
|
70
|
+
console.log(`[Crovver SDK] ${message}`, data ?? "");
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
this.client = axios.create({
|
|
74
|
+
baseURL: config.baseUrl ?? CROVVER_BASE_URL,
|
|
75
|
+
timeout: config.timeout || 30000,
|
|
76
|
+
headers: {
|
|
77
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
this.setupInterceptors();
|
|
82
|
+
}
|
|
83
|
+
setupInterceptors() {
|
|
84
|
+
// Request interceptor for logging
|
|
85
|
+
this.client.interceptors.request.use((config) => {
|
|
86
|
+
this.logger(`Request: ${config.method?.toUpperCase()} ${config.url}`, {
|
|
87
|
+
data: config.data,
|
|
88
|
+
params: config.params,
|
|
89
|
+
});
|
|
90
|
+
return config;
|
|
91
|
+
});
|
|
92
|
+
// Response interceptor to unwrap ApiResponse format
|
|
93
|
+
this.client.interceptors.response.use((response) => {
|
|
94
|
+
const apiResponse = response.data;
|
|
95
|
+
this.logger(`Response: ${response.status}`, {
|
|
96
|
+
success: apiResponse.success,
|
|
97
|
+
hasData: !!apiResponse.data,
|
|
98
|
+
});
|
|
99
|
+
if (apiResponse.success && apiResponse.data !== null) {
|
|
100
|
+
response.data = apiResponse.data;
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
else if (!apiResponse.success && apiResponse.error) {
|
|
104
|
+
throw new CrovverError(apiResponse.error.message, response.status, apiResponse.error.code);
|
|
105
|
+
}
|
|
106
|
+
return response;
|
|
107
|
+
}, (error) => {
|
|
108
|
+
if (error.response) {
|
|
109
|
+
const apiResponse = error.response.data;
|
|
110
|
+
this.logger(`Error Response: ${error.response.status}`, {
|
|
111
|
+
error: apiResponse?.error,
|
|
112
|
+
});
|
|
113
|
+
if (apiResponse?.error) {
|
|
114
|
+
throw new CrovverError(apiResponse.error.message, error.response.status, apiResponse.error.code, error);
|
|
115
|
+
}
|
|
116
|
+
throw new CrovverError("Request failed", error.response.status, undefined, error);
|
|
117
|
+
}
|
|
118
|
+
this.logger("Network Error", { message: error.message });
|
|
119
|
+
throw new CrovverError(error.message || "Network error", undefined, "NETWORK_ERROR", error);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Execute a request with automatic retry logic
|
|
124
|
+
*/
|
|
125
|
+
async withRetry(operation, retryConfig) {
|
|
126
|
+
const config = {
|
|
127
|
+
maxRetries: retryConfig?.maxRetries ?? this.config.maxRetries,
|
|
128
|
+
baseDelay: retryConfig?.baseDelay ?? 1000,
|
|
129
|
+
maxDelay: retryConfig?.maxDelay ?? 30000,
|
|
130
|
+
};
|
|
131
|
+
let lastError;
|
|
132
|
+
for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
|
|
133
|
+
try {
|
|
134
|
+
return await operation();
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
lastError = error;
|
|
138
|
+
const isCrovverError = error instanceof CrovverError;
|
|
139
|
+
const isRetryable = isCrovverError ? error.isRetryable : true;
|
|
140
|
+
if (!isRetryable || attempt >= config.maxRetries) {
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
const delay = calculateBackoff(attempt, config.baseDelay, config.maxDelay);
|
|
144
|
+
this.logger(`Retry attempt ${attempt + 1}/${config.maxRetries} after ${delay}ms`);
|
|
145
|
+
await sleep(delay);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
throw lastError;
|
|
149
|
+
}
|
|
150
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
151
|
+
// TENANT MANAGEMENT (B2B Only)
|
|
152
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
153
|
+
/**
|
|
154
|
+
* Create a new tenant (B2B organizations only)
|
|
155
|
+
*
|
|
156
|
+
* For D2C organizations, tenants are automatically created during checkout.
|
|
157
|
+
*
|
|
158
|
+
* @param request - Tenant creation request
|
|
159
|
+
* @returns Created tenant and owner information
|
|
160
|
+
* @throws {CrovverError} If the organization is D2C or tenant already exists
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const result = await crovver.createTenant({
|
|
165
|
+
* externalTenantId: 'company-123',
|
|
166
|
+
* name: 'Acme Corporation',
|
|
167
|
+
* ownerExternalUserId: 'user-456',
|
|
168
|
+
* ownerEmail: 'admin@acme.com',
|
|
169
|
+
* });
|
|
170
|
+
* console.log('Tenant created:', result.tenant.id);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
async createTenant(request) {
|
|
174
|
+
return this.withRetry(async () => {
|
|
175
|
+
const response = await this.client.post("/api/public/tenants", request);
|
|
176
|
+
return response.data;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get tenant information by external tenant ID
|
|
181
|
+
*
|
|
182
|
+
* @param externalTenantId - The external tenant ID from your SaaS app
|
|
183
|
+
* @returns Tenant information with members
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const { tenant, members } = await crovver.getTenant('company-123');
|
|
188
|
+
* console.log(`Tenant: ${tenant.name}`);
|
|
189
|
+
* console.log(`Members: ${members.length}`);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
async getTenant(externalTenantId) {
|
|
193
|
+
return this.withRetry(async () => {
|
|
194
|
+
const response = await this.client.get("/api/public/tenants", {
|
|
195
|
+
params: { externalUserId: externalTenantId },
|
|
196
|
+
});
|
|
197
|
+
return response.data;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
201
|
+
// PLANS
|
|
202
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
203
|
+
/**
|
|
204
|
+
* Get all available plans for the organization
|
|
205
|
+
*
|
|
206
|
+
* Use this to render pricing pages or display upgrade options.
|
|
207
|
+
*
|
|
208
|
+
* @returns List of all active plans with pricing and features
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const { plans } = await crovver.getPlans();
|
|
213
|
+
* plans.forEach(plan => {
|
|
214
|
+
* console.log(`${plan.name}: $${plan.pricing.amount}/${plan.pricing.interval}`);
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
async getPlans() {
|
|
219
|
+
return this.withRetry(async () => {
|
|
220
|
+
const response = await this.client.get("/api/public/plans");
|
|
221
|
+
return response.data;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
225
|
+
// SUBSCRIPTIONS
|
|
226
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
227
|
+
/**
|
|
228
|
+
* Get active subscriptions for a tenant/user
|
|
229
|
+
*
|
|
230
|
+
* @param requestingEntityId - External tenant ID (B2B) or user ID (D2C)
|
|
231
|
+
* @returns Active subscriptions with plan and billing details
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const { subscriptions, tenant } = await crovver.getSubscriptions('company-123');
|
|
236
|
+
* console.log(`${tenant.name} has ${subscriptions.length} subscriptions`);
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
async getSubscriptions(requestingEntityId) {
|
|
240
|
+
return this.withRetry(async () => {
|
|
241
|
+
const response = await this.client.get("/api/public/subscriptions", {
|
|
242
|
+
params: { requestingEntityId },
|
|
243
|
+
});
|
|
244
|
+
return response.data;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
248
|
+
// CHECKOUT
|
|
249
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
250
|
+
/**
|
|
251
|
+
* Create a checkout session for payment
|
|
252
|
+
*
|
|
253
|
+
* For B2B: Provide requestingUserId and requestingTenantId
|
|
254
|
+
* For D2C: Provide requestingUserId, userEmail, and userName (tenant auto-created)
|
|
255
|
+
*
|
|
256
|
+
* @param request - Checkout session request
|
|
257
|
+
* @returns Checkout URL to redirect the user to
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* // B2B checkout
|
|
262
|
+
* const checkout = await crovver.createCheckoutSession({
|
|
263
|
+
* requestingUserId: 'user-456',
|
|
264
|
+
* requestingTenantId: 'company-123',
|
|
265
|
+
* planId: 'plan-uuid',
|
|
266
|
+
* provider: 'stripe',
|
|
267
|
+
* successUrl: 'https://myapp.com/success',
|
|
268
|
+
* cancelUrl: 'https://myapp.com/cancel',
|
|
269
|
+
* });
|
|
270
|
+
* window.location.href = checkout.checkoutUrl;
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
async createCheckoutSession(request) {
|
|
274
|
+
// Checkout operations should not be retried to avoid duplicate payments
|
|
275
|
+
const response = await this.client.post("/api/public/checkout", request);
|
|
276
|
+
return response.data;
|
|
277
|
+
}
|
|
278
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
279
|
+
// ENTITLEMENT CHECKS
|
|
280
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
281
|
+
/**
|
|
282
|
+
* Check if a tenant/user can access a specific feature
|
|
283
|
+
*
|
|
284
|
+
* @param requestingEntityId - External tenant ID (B2B) or user ID (D2C)
|
|
285
|
+
* @param featureKey - The feature key to check
|
|
286
|
+
* @returns Whether access is allowed
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const canAccess = await crovver.canAccess('company-123', 'advanced-analytics');
|
|
291
|
+
* if (canAccess) {
|
|
292
|
+
* // Show the feature
|
|
293
|
+
* } else {
|
|
294
|
+
* // Show upgrade prompt
|
|
295
|
+
* }
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
async canAccess(requestingEntityId, featureKey) {
|
|
299
|
+
return this.withRetry(async () => {
|
|
300
|
+
const response = await this.client.post("/api/public/can-access", {
|
|
301
|
+
requestingEntityId,
|
|
302
|
+
featureKey,
|
|
303
|
+
});
|
|
304
|
+
return response.data.canAccess;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Record usage for a metric
|
|
309
|
+
*
|
|
310
|
+
* @param requestingEntityId - External tenant ID (B2B) or user ID (D2C)
|
|
311
|
+
* @param metric - The metric key to record usage for
|
|
312
|
+
* @param value - Usage value (default: 1)
|
|
313
|
+
* @param metadata - Optional metadata
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* await crovver.recordUsage('company-123', 'api-calls', 1, {
|
|
318
|
+
* endpoint: '/api/v1/users',
|
|
319
|
+
* method: 'GET'
|
|
320
|
+
* });
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
async recordUsage(requestingEntityId, metric, value = 1, metadata) {
|
|
324
|
+
return this.withRetry(async () => {
|
|
325
|
+
const response = await this.client.post("/api/public/record-usage", {
|
|
326
|
+
requestingEntityId,
|
|
327
|
+
metric,
|
|
328
|
+
value,
|
|
329
|
+
metadata,
|
|
330
|
+
});
|
|
331
|
+
return response.data;
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Check current usage and limits for a metric
|
|
336
|
+
*
|
|
337
|
+
* @param requestingEntityId - External tenant ID (B2B) or user ID (D2C)
|
|
338
|
+
* @param metric - The metric key to check
|
|
339
|
+
* @returns Usage information including current value, limit, and remaining
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const usage = await crovver.checkUsageLimit('company-123', 'api-calls');
|
|
344
|
+
* console.log(`Used: ${usage.current} / ${usage.limit}`);
|
|
345
|
+
* console.log(`Remaining: ${usage.remaining}`);
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
async checkUsageLimit(requestingEntityId, metric) {
|
|
349
|
+
return this.withRetry(async () => {
|
|
350
|
+
const response = await this.client.post("/api/public/check-usage-limit", {
|
|
351
|
+
requestingEntityId,
|
|
352
|
+
metric,
|
|
353
|
+
});
|
|
354
|
+
return response.data;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
358
|
+
// PRORATION (Seat-Based Plans)
|
|
359
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
360
|
+
/**
|
|
361
|
+
* Create a proration checkout session for a mid-cycle seat capacity upgrade.
|
|
362
|
+
*
|
|
363
|
+
* The proration amount is calculated server-side. After successful payment
|
|
364
|
+
* the webhook will upgrade the subscription capacity automatically.
|
|
365
|
+
*
|
|
366
|
+
* @param params - Proration checkout details
|
|
367
|
+
* @returns Checkout URL, proration ID, and calculated amount
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const checkout = await crovver.createProrationCheckout({
|
|
372
|
+
* requestingEntityId: 'company-123',
|
|
373
|
+
* newCapacity: 15,
|
|
374
|
+
* planId: 'plan-uuid', // optional
|
|
375
|
+
* successUrl: 'https://myapp.com/success',
|
|
376
|
+
* cancelUrl: 'https://myapp.com/cancel',
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* if (checkout.checkoutUrl) {
|
|
380
|
+
* window.location.href = checkout.checkoutUrl;
|
|
381
|
+
* }
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
async createProrationCheckout(params) {
|
|
385
|
+
// Payment operations should not be retried to avoid duplicate charges
|
|
386
|
+
const response = await this.client.post("/api/public/capacity/proration-checkout", {
|
|
387
|
+
requestingEntityId: params.requestingEntityId,
|
|
388
|
+
newCapacity: params.newCapacity,
|
|
389
|
+
planId: params.planId,
|
|
390
|
+
successUrl: params.successUrl,
|
|
391
|
+
cancelUrl: params.cancelUrl,
|
|
392
|
+
});
|
|
393
|
+
return response.data;
|
|
394
|
+
}
|
|
395
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
396
|
+
// SUBSCRIPTION MANAGEMENT
|
|
397
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
398
|
+
/**
|
|
399
|
+
* Cancel an active subscription.
|
|
400
|
+
*
|
|
401
|
+
* The subscription remains active until the end of the current billing
|
|
402
|
+
* period (cancel-at-period-end behaviour).
|
|
403
|
+
*
|
|
404
|
+
* @param subscriptionId - The Crovver subscription ID
|
|
405
|
+
* @param reason - Cancellation reason (required by the API)
|
|
406
|
+
* @param feedback - Optional free-text feedback
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const result = await crovver.cancelSubscription(
|
|
411
|
+
* 'sub-uuid',
|
|
412
|
+
* 'too_expensive',
|
|
413
|
+
* 'Pricing is a bit high for our team size',
|
|
414
|
+
* );
|
|
415
|
+
* console.log(`Subscription ends at: ${result.willEndAt}`);
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
async cancelSubscription(subscriptionId, reason, feedback) {
|
|
419
|
+
return this.withRetry(async () => {
|
|
420
|
+
const response = await this.client.post(`/api/public/subscriptions/${subscriptionId}/cancel`, { reason, feedback });
|
|
421
|
+
return response.data;
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
425
|
+
// BILLING / INVOICES
|
|
426
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
427
|
+
/**
|
|
428
|
+
* Get invoices for a tenant.
|
|
429
|
+
*
|
|
430
|
+
* @param externalTenantId - External tenant ID
|
|
431
|
+
* @returns List of invoices
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```typescript
|
|
435
|
+
* const { invoices } = await crovver.getInvoices('company-123');
|
|
436
|
+
* invoices.forEach(inv => {
|
|
437
|
+
* console.log(`${inv.invoice_number}: ${inv.total_amount} ${inv.currency}`);
|
|
438
|
+
* });
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
async getInvoices(externalTenantId) {
|
|
442
|
+
return this.withRetry(async () => {
|
|
443
|
+
const response = await this.client.get("/api/public/billing/invoices", { params: { externalTenantId } });
|
|
444
|
+
return response.data;
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
448
|
+
// PAYMENT PROVIDERS
|
|
449
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
450
|
+
/**
|
|
451
|
+
* Get list of supported payment providers
|
|
452
|
+
*
|
|
453
|
+
* Returns all payment providers available on the Crovver platform.
|
|
454
|
+
*
|
|
455
|
+
* @returns List of supported payment providers
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```typescript
|
|
459
|
+
* const { providers } = await crovver.getSupportedProviders();
|
|
460
|
+
* providers.forEach(p => console.log(`${p.name}: ${p.code}`));
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
async getSupportedProviders() {
|
|
464
|
+
return this.withRetry(async () => {
|
|
465
|
+
const response = await this.client.get("/api/public/supported-providers");
|
|
466
|
+
return response.data;
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
export default CrovverClient;
|
|
471
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAIN,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAsC/C;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAUrC,YACE,OAAe,EACf,UAAmB,EACnB,IAAa,EACb,aAAuB;QAEvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,YAAY,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAE9D,uEAAuE;QACvE,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;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