@vrplatform/hyperline-client 1.0.1 → 1.0.3

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 (45) hide show
  1. package/build/main/client.d.ts +812 -0
  2. package/build/main/client.js +187 -0
  3. package/build/main/client.js.map +1 -0
  4. package/build/main/const.d.ts +24 -0
  5. package/build/main/const.js +209 -1
  6. package/build/main/const.js.map +1 -1
  7. package/build/main/hooks.d.ts +10 -0
  8. package/build/main/hooks.js +13 -0
  9. package/build/main/hooks.js.map +1 -0
  10. package/build/main/index.d.ts +3 -867
  11. package/build/main/index.js +3 -217
  12. package/build/main/index.js.map +1 -1
  13. package/build/main/tsconfig.main.tsbuildinfo +1 -1
  14. package/build/main/types.d.ts +35 -0
  15. package/build/main/types.js +2 -0
  16. package/build/main/types.js.map +1 -0
  17. package/build/main/utils.d.ts +1 -0
  18. package/build/main/utils.js +6 -0
  19. package/build/main/utils.js.map +1 -0
  20. package/build/module/client.d.ts +812 -0
  21. package/build/module/client.js +189 -0
  22. package/build/module/client.js.map +1 -0
  23. package/build/module/const.d.ts +24 -0
  24. package/build/module/const.js +209 -1
  25. package/build/module/const.js.map +1 -1
  26. package/build/module/hooks.d.ts +10 -0
  27. package/build/module/hooks.js +13 -0
  28. package/build/module/hooks.js.map +1 -0
  29. package/build/module/index.d.ts +3 -867
  30. package/build/module/index.js +3 -219
  31. package/build/module/index.js.map +1 -1
  32. package/build/module/tsconfig.esm.tsbuildinfo +1 -1
  33. package/build/module/types.d.ts +35 -0
  34. package/build/module/types.js +2 -0
  35. package/build/module/types.js.map +1 -0
  36. package/build/module/utils.d.ts +1 -0
  37. package/build/module/utils.js +6 -0
  38. package/build/module/utils.js.map +1 -0
  39. package/package.json +1 -1
  40. package/src/client.ts +362 -0
  41. package/src/const.ts +225 -1
  42. package/src/hooks.ts +24 -0
  43. package/src/index.ts +3 -445
  44. package/src/types.ts +43 -0
  45. package/src/utils.ts +5 -0
package/src/client.ts ADDED
@@ -0,0 +1,362 @@
1
+ import { utc } from '@finalytic/utils';
2
+ import type { operations, paths } from './_types.generated';
3
+ import { BillableEvents, CreateBillableEvent } from './types';
4
+ import { arrayBufferToBase64 } from './utils';
5
+
6
+ export type Logger = { error(message?: any, ...optionalParams: any[]): void };
7
+
8
+ export class HyperlineAPI {
9
+ constructor(token: string, logger: Logger = console) {
10
+ this.headers = {
11
+ 'Content-Type': 'application/json',
12
+ Authorization: `Bearer ${token}`,
13
+ };
14
+ this.logger = logger;
15
+ }
16
+
17
+ private headers: Record<string, string>;
18
+
19
+ private logger: Logger;
20
+
21
+ private async fetchBasic<T>(
22
+ path: string,
23
+ options?: RequestInit,
24
+ data?: Record<string, any>
25
+ ): Promise<T | null> {
26
+ if (data) options = { body: JSON.stringify(data), ...(options || {}) };
27
+
28
+ const sandbox = this.headers.Authorization.includes('test')
29
+ ? 'sandbox.'
30
+ : '';
31
+
32
+ const result = await fetch(`https://${sandbox}${path}`, {
33
+ method: 'GET',
34
+ ...options,
35
+ headers: { ...this.headers, ...options?.headers },
36
+ });
37
+
38
+ if (!result || !result?.ok) {
39
+ const status = result?.status;
40
+ const statusText = result?.statusText;
41
+
42
+ if (status === 429) {
43
+ // get difference between rate limit reset and now
44
+ const rateLimitReset = utc(result?.headers.get('x-ratelimit-reset'));
45
+ const diff = rateLimitReset.diff(utc(), 'milliseconds');
46
+
47
+ // wait until rate limit resets
48
+ await new Promise((resolve) => setTimeout(resolve, diff));
49
+
50
+ return await this.fetchBasic<T>(path, options, data);
51
+ } else if (status === 404) {
52
+ return null;
53
+ } else {
54
+ const content: any = await result.json();
55
+ throw new Error(
56
+ `Hyperline Error ${status} (${statusText}) in ${path} for ${options?.method || 'GET'}: ${content.message}`
57
+ );
58
+ }
59
+ } else if (result.headers.get('content-type')?.includes('application/pdf'))
60
+ return arrayBufferToBase64(await result.arrayBuffer()) as T;
61
+
62
+ return (await result.json()) as T;
63
+ }
64
+
65
+ private async fetch<T>(
66
+ path: string,
67
+ options?: RequestInit,
68
+ data?: Record<string, any>
69
+ ): Promise<T | null> {
70
+ return await this.fetchBasic(`api.hyperline.co${path}`, options, data);
71
+ }
72
+
73
+ private async fetchIngest<T>(
74
+ path: string,
75
+ options?: RequestInit,
76
+ data?: Record<string, any>
77
+ ): Promise<T | null> {
78
+ return await this.fetchBasic(`ingest.hyperline.co${path}`, options, data);
79
+ }
80
+
81
+ // CUSTOMER
82
+
83
+ async getCustomer(id?: string) {
84
+ if (!id) {
85
+ this.logger.error('Missing customer ID', { id });
86
+ throw new Error('Missing customer ID');
87
+ }
88
+
89
+ return await this.fetch<
90
+ paths['/v1/customers/{id}']['get']['responses'][200]['content']['application/json']
91
+ >(`/v1/customers/${id}`);
92
+ }
93
+
94
+ async getCustomers(skip = 0, take = 100) {
95
+ return await this.fetch<
96
+ paths['/v1/customers']['get']['responses'][200]['content']['application/json']
97
+ >(`/v1/customers?take=${take}&skip=${skip}`);
98
+ }
99
+
100
+ async getAllCustomers(
101
+ items: paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data'] = []
102
+ ): Promise<
103
+ paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data']
104
+ > {
105
+ const { data } = (await this.getCustomers(items.length)) || { data: [] };
106
+
107
+ return data.length
108
+ ? this.getAllCustomers([...items, ...data])
109
+ : [...items, ...data];
110
+ }
111
+
112
+ async createCustomer(
113
+ data: NonNullable<
114
+ paths['/v1/customers']['post']['requestBody']
115
+ >['content']['application/json']
116
+ ) {
117
+ return await this.fetch<
118
+ paths['/v1/customers']['post']['responses'][201]['content']['application/json']
119
+ >(
120
+ '/v1/customers',
121
+ { method: 'POST' },
122
+ { currency: 'USD', timezone: 'Etc/UTC', ...data }
123
+ );
124
+ }
125
+
126
+ async updateCustomer(
127
+ id: string,
128
+ data: NonNullable<
129
+ paths['/v1/customers/{id}']['put']['requestBody']
130
+ >['content']['application/json']
131
+ ) {
132
+ if (!id) {
133
+ this.logger.error('Missing customer ID', { id });
134
+ throw new Error('Missing customer ID');
135
+ }
136
+
137
+ return await this.fetch<
138
+ paths['/v1/customers/{id}']['put']['responses'][200]['content']['application/json']
139
+ >(`/v1/customers/${id}`, { method: 'PUT' }, data);
140
+ }
141
+
142
+ async deleteCustomer(id: string) {
143
+ return await this.fetch<
144
+ paths['/v1/customers/{id}']['delete']['responses'][204]['content']
145
+ >(`/v1/customers/${id}`, {
146
+ method: 'DELETE',
147
+ });
148
+ }
149
+
150
+ async archiveCustomer(id: string) {
151
+ return await this.fetch<
152
+ paths['/v1/customers/{id}/archive']['put']['responses'][200]['content']['application/json']
153
+ >(`/v1/customers/${id}/archive`, {
154
+ method: 'PUT',
155
+ });
156
+ }
157
+
158
+ async unarchiveCustomer(id: string) {
159
+ if (!id) {
160
+ this.logger.error('Missing customer ID', { id });
161
+ throw new Error('Missing customer ID');
162
+ }
163
+
164
+ return await this.fetch<
165
+ paths['/v1/customers/{id}/unarchive']['put']['responses'][200]['content']['application/json']
166
+ >(`/v1/customers/${id}/unarchive`, { method: 'PUT' });
167
+ }
168
+
169
+ async getCustomerPortal(id: string) {
170
+ return await this.fetch<
171
+ paths['/v1/customers/{id}/portal']['get']['responses'][200]['content']['application/json']
172
+ >(`/v1/customers/${id}/portal`);
173
+ }
174
+
175
+ // SUBSCRIPTION
176
+
177
+ async getSubscription(id: string) {
178
+ if (!id) {
179
+ this.logger.error('Missing subscription ID', { id });
180
+ throw new Error('Missing subscription ID');
181
+ }
182
+
183
+ return await this.fetch<
184
+ paths['/v2/subscriptions/{id}']['get']['responses'][200]['content']['application/json']
185
+ >(`/v2/subscriptions/${id}?include_live_billing=true`);
186
+ }
187
+
188
+ async getSubscriptions(
189
+ skip = 0,
190
+ take = 100,
191
+ query: operations['getSubscriptions']['parameters']['query'] = {
192
+ status: 'all',
193
+ }
194
+ ) {
195
+ return await this.fetch<
196
+ paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']
197
+ >(
198
+ `/v2/subscriptions?take=${take}&skip=${skip}${Object.entries(query)
199
+ .filter(([_, value]) => value !== undefined)
200
+ .map(([key, value]) => `&${key}=${value}`)
201
+ .join('')}`
202
+ );
203
+ }
204
+
205
+ async getAllSubscriptions(
206
+ items: paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data'] = [],
207
+ query: operations['getSubscriptions']['parameters']['query'] = {}
208
+ ): Promise<
209
+ paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data']
210
+ > {
211
+ const { data } = (await this.getSubscriptions(
212
+ items.length,
213
+ 100,
214
+ query
215
+ )) || { data: [] };
216
+
217
+ return data.length
218
+ ? this.getAllSubscriptions([...items, ...data], query)
219
+ : [...items, ...data];
220
+ }
221
+
222
+ async createSubscription(
223
+ data: NonNullable<
224
+ paths['/v2/subscriptions']['post']['requestBody']
225
+ >['content']['application/json']
226
+ ) {
227
+ return await this.fetch<
228
+ paths['/v2/subscriptions']['post']['responses'][201]['content']['application/json']
229
+ >('/v2/subscriptions', { method: 'POST' }, data);
230
+ }
231
+
232
+ async updateSubscription(
233
+ id: string,
234
+ data: NonNullable<
235
+ paths['/v1/subscriptions/{id}/update']['post']['requestBody']
236
+ >['content']['application/json']
237
+ ) {
238
+ return await this.fetch<
239
+ paths['/v1/subscriptions/{id}/update']['post']['responses'][201]['content']['application/json']
240
+ >(`/v1/subscriptions/${id}/update`, { method: 'POST' }, data);
241
+ }
242
+
243
+ async cancelSubscription(
244
+ id: string,
245
+ data: NonNullable<
246
+ paths['/v1/subscriptions/{id}/cancel']['post']['requestBody']
247
+ >['content']['application/json']
248
+ ) {
249
+ return await this.fetch<
250
+ paths['/v1/subscriptions/{id}/cancel']['post']['responses'][200]['content']['application/json']
251
+ >(
252
+ `/v1/subscriptions/${id}/cancel`,
253
+ {
254
+ method: 'POST',
255
+ },
256
+ data
257
+ );
258
+ }
259
+
260
+ async reinstateSubscription(id: string) {
261
+ return await this.fetch<
262
+ paths['/v1/subscriptions/{id}/reinstate']['post']['responses'][200]['content']['application/json']
263
+ >(`/v1/subscriptions/${id}/reinstate`, {
264
+ method: 'POST',
265
+ });
266
+ }
267
+
268
+ // PLAN
269
+
270
+ async getPlan(id: string) {
271
+ if (!id) {
272
+ this.logger.error('Missing plan ID', { id });
273
+ throw new Error('Missing plan ID');
274
+ }
275
+
276
+ return await this.fetch<
277
+ paths['/v1/plans/{id}']['get']['responses'][200]['content']['application/json']
278
+ >(`/v1/plans/${id}`);
279
+ }
280
+
281
+ async getPlans(skip = 0, take = 100) {
282
+ return await this.fetch<
283
+ paths['/v1/plans']['get']['responses'][200]['content']['application/json']
284
+ >(`/v1/plans?take=${take}&skip=${skip}`);
285
+ }
286
+
287
+ // INVOICE
288
+
289
+ async getInvoice(id: string) {
290
+ if (!id) {
291
+ this.logger.error('Missing invoice ID', { id });
292
+ throw new Error('Missing invoice ID');
293
+ }
294
+
295
+ return await this.fetch<
296
+ paths['/v1/invoices/{id}']['get']['responses'][200]['content']['application/json']
297
+ >(`/v1/invoices/${id}`);
298
+ }
299
+
300
+ async getInvoices(
301
+ skip = 0,
302
+ take = 100,
303
+ query: operations['getInvoices']['parameters']['query'] = { status: 'all' }
304
+ ) {
305
+ return await this.fetch<
306
+ paths['/v1/invoices']['get']['responses'][200]['content']['application/json']
307
+ >(
308
+ `/v1/invoices?take=${take}&skip=${skip}&${Object.entries(query)
309
+ .filter(([_, value]) => value !== undefined)
310
+ .map(([key, value]) => `&${key}=${value}`)
311
+ .join('')}`
312
+ );
313
+ }
314
+
315
+ async getInvoicesByCustomerId(id: string) {
316
+ return await this.fetch<
317
+ paths['/v1/invoices']['get']['responses'][200]['content']['application/json']
318
+ >(`/v1/invoices?customerId__equals=${id}`);
319
+ }
320
+
321
+ async getInvoiceDownload(id: string) {
322
+ return await this.fetch<string>(
323
+ // TODO: fix if type != unknown paths['/v1/invoices/{id}/download']['get']['responses'][200]['content']['application/pdf']
324
+ `/v1/invoices/${id}/download`,
325
+ {
326
+ headers: { 'Content-type': 'application/pdf' },
327
+ }
328
+ );
329
+ }
330
+
331
+ async getAllInvoices(
332
+ items: paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data'] = []
333
+ ): Promise<
334
+ paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data']
335
+ > {
336
+ const { data } = (await this.getInvoices(items.length)) || { data: [] };
337
+
338
+ return data.length
339
+ ? this.getAllInvoices([...items, ...data])
340
+ : [...items, ...data];
341
+ }
342
+
343
+ // OTHERS
344
+
345
+ async createBillableEvent(data: CreateBillableEvent[]) {
346
+ if (!data.length) return { events_created: [] };
347
+
348
+ return await this.fetchIngest<BillableEvents>(
349
+ '/v1/events/batch',
350
+ { method: 'POST' },
351
+ data
352
+ );
353
+ }
354
+
355
+ async getComponentToken(data: {
356
+ customer_id: string;
357
+ }) {
358
+ return await this.fetch<
359
+ paths['/v1/integrations/components/token']['post']['responses'][201]['content']['application/json']
360
+ >('/v1/integrations/components/token', { method: 'POST' }, data);
361
+ }
362
+ }
package/src/const.ts CHANGED
@@ -1,12 +1,236 @@
1
+ import type { currency_enum } from '@finalytic/graphql';
2
+ import type { TrackingEvent } from '@vrplatform/log';
3
+ import { HyperlineEntities } from './types';
4
+
5
+ // Tenants
1
6
  export const VRP_TENANT_ID = '7bfec41f-aa3f-4602-95d2-f7996e4f0e59';
2
7
  export const DEMO_TEST_PARTNER_TENANT_ID =
3
8
  '0b6a7bd6-56cc-46b5-b2ab-1bd7d1e994fa';
4
9
  export const XIMPLIFI_TENANT_ID = 'd6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5';
5
10
 
6
- // Hyperline
11
+ // Customers
7
12
  export const XIMPLIFI_CUSTOMER_ID = 'cus_HDUZawnaJbPa9p';
13
+
14
+ // Coupons
8
15
  export const XIMPLIFI_COUPON_ID = 'cou_MXCaik3r19_Xkn';
9
16
  export const ACCOUNTING_PARTNER_COUPON_ID = 'cou_PJQ328MBAD9kxY';
17
+
18
+ // Plans
10
19
  export const HYPERLINE_DEFAULT_PLAN_ID = 'plan_Dyb5P0ICZ6HsIT';
20
+ export const HYPERLINE_DEFAULT_PLAN_NAME = 'All-in-One VRP Subscription';
21
+
11
22
  export const HYPERLINE_PARTNER_PLAN_ID = 'plan_vkYJcCz7z0XD0N';
23
+ export const HYPERLINE_PARTNER_PLAN_NAME = 'VRP Subscription - Partners';
24
+
12
25
  export const DEV_HYPERLINE_DEFAULT_PLAN_ID = 'plan_UTCVXFQnKD0oMS';
26
+
27
+ export const GL_HYPERLINE_DEFAULT_PLAN_ID = 'plan_JXviWSpU5yuokD';
28
+ export const GL_HYPERLINE_DEFAULT_PLAN_NAME = 'VRTrust Subscription';
29
+
30
+ export const GL_HYPERLINE_PARTNER_PLAN_ID = 'plan_vyxckdvUi8X_mr';
31
+ export const GL_HYPERLINE_PARTNER_PLAN_NAME = 'VRTrust Subscription - Partners';
32
+
33
+ export const WEBHOOKS = {
34
+ 'payment_method.created': 'hyperline_payment_method_created',
35
+ 'payment_method.errored': 'hyperline_payment_method_errored',
36
+ 'payment_method.deleted': 'hyperline_payment_method_deleted',
37
+ 'subscription.activated': 'hyperline_subscription_status_changed',
38
+ 'subscription.reactivated': 'hyperline_subscription_status_changed',
39
+ 'subscription.cancelled': 'hyperline_subscription_status_changed',
40
+ 'subscription.cancellation_scheduled':
41
+ 'hyperline_subscription_cancellation_scheduled',
42
+ // 'subscription.created': 'hyperline_subscription_created',
43
+ 'subscription.errored': 'hyperline_subscription_status_changed',
44
+ 'subscription.paused': 'hyperline_subscription_status_changed',
45
+ 'subscription.voided': 'hyperline_subscription_status_changed',
46
+ // 'subscription.charged': 'hyperline_subscription_charged',
47
+ 'customer.created': 'hyperline_customer_created',
48
+ 'customer.updated': 'hyperline_customer_updated',
49
+ 'customer.deleted': 'hyperline_customer_deleted',
50
+ } satisfies Record<string, TrackingEvent>;
51
+
52
+ export const CURRENCY_MAP: Record<
53
+ currency_enum,
54
+ HyperlineEntities['Currency'] | undefined
55
+ > = {
56
+ aed: 'AED',
57
+ afn: 'AFN',
58
+ all: 'ALL',
59
+ amd: 'AMD',
60
+ ang: 'ANG',
61
+ aoa: 'AOA',
62
+ ars: 'ARS',
63
+ aud: 'AUD',
64
+ awg: 'AWG',
65
+ azn: 'AZN',
66
+ bam: 'BAM',
67
+ bbd: 'BBD',
68
+ bdt: 'BDT',
69
+ bgn: 'BGN',
70
+ bhd: 'BHD',
71
+ bif: 'BIF',
72
+ bmd: 'BMD',
73
+ bnd: 'BND',
74
+ bob: 'BOB',
75
+ bov: 'BOB',
76
+ brl: 'BRL',
77
+ bsd: 'BSD',
78
+ btn: 'BTN',
79
+ bwp: 'BWP',
80
+ byn: 'BYR',
81
+ byr: 'BYR',
82
+ bzd: 'BZD',
83
+ cad: 'CAD',
84
+ cdf: 'CDF',
85
+ che: 'CHF',
86
+ chf: 'CHF',
87
+ chw: 'CHF',
88
+ clf: 'CLP',
89
+ clp: 'CLP',
90
+ cny: 'CNY',
91
+ cop: 'COP',
92
+ cou: 'COP',
93
+ crc: 'CRC',
94
+ cuc: 'CUP',
95
+ cup: 'CUP',
96
+ cve: 'CVE',
97
+ czk: 'CZK',
98
+ djf: 'DJF',
99
+ dkk: 'DKK',
100
+ dop: 'DOP',
101
+ dzd: 'DZD',
102
+ egp: 'EGP',
103
+ ern: 'ERN',
104
+ etb: 'ETB',
105
+ eur: 'EUR',
106
+ fjd: 'FJD',
107
+ fkp: 'FKP',
108
+ gbp: 'GBP',
109
+ gel: 'GEL',
110
+ ghs: 'GHS',
111
+ gip: 'GIP',
112
+ gmd: 'GMD',
113
+ gnf: 'GNF',
114
+ gtq: 'GTQ',
115
+ gyd: 'GYD',
116
+ hkd: 'HKD',
117
+ hnl: 'HNL',
118
+ hrk: 'HRK',
119
+ htg: 'HTG',
120
+ huf: 'HUF',
121
+ idr: 'IDR',
122
+ ils: 'ILS',
123
+ inr: 'INR',
124
+ iqd: 'IQD',
125
+ irr: 'IRR',
126
+ isk: 'ISK',
127
+ jmd: 'JMD',
128
+ jod: 'JOD',
129
+ jpy: 'JPY',
130
+ kes: 'KES',
131
+ kgs: 'KGS',
132
+ khr: 'KHR',
133
+ kmf: 'KMF',
134
+ kpw: 'KPW',
135
+ krw: 'KRW',
136
+ kwd: 'KWD',
137
+ kyd: 'KYD',
138
+ kzt: 'KZT',
139
+ lak: 'LAK',
140
+ lbp: 'LBP',
141
+ lkr: 'LKR',
142
+ lrd: 'LRD',
143
+ lsl: 'LSL',
144
+ ltl: 'EUR',
145
+ lvl: 'EUR',
146
+ lyd: 'LYD',
147
+ mad: 'MAD',
148
+ mdl: 'MDL',
149
+ mga: 'MGA',
150
+ mkd: 'MKD',
151
+ mmk: 'MMK',
152
+ mnt: 'MNT',
153
+ mop: 'MOP',
154
+ mro: 'MRO',
155
+ mur: 'MUR',
156
+ mvr: 'MVR',
157
+ mwk: 'MWK',
158
+ mxn: 'MXN',
159
+ mxv: 'MXN',
160
+ myr: 'MYR',
161
+ mzn: 'MZN',
162
+ nad: 'NAD',
163
+ ngn: 'NGN',
164
+ nio: 'NIO',
165
+ nok: 'NOK',
166
+ npr: 'NPR',
167
+ nzd: 'NZD',
168
+ omr: 'OMR',
169
+ pab: 'PAB',
170
+ pen: 'PEN',
171
+ pgk: 'PGK',
172
+ php: 'PHP',
173
+ pkr: 'PKR',
174
+ pln: 'PLN',
175
+ pyg: 'PYG',
176
+ qar: 'QAR',
177
+ ron: 'RON',
178
+ rsd: 'RSD',
179
+ rub: 'RUB',
180
+ rwf: 'RWF',
181
+ sar: 'SAR',
182
+ sbd: 'SBD',
183
+ scr: 'SCR',
184
+ sdg: 'SDG',
185
+ sek: 'SEK',
186
+ sgd: 'SGD',
187
+ shp: 'SHP',
188
+ sll: 'SLL',
189
+ sos: 'SOS',
190
+ srd: 'SRD',
191
+ ssp: 'SSP',
192
+ std: 'STD',
193
+ syp: 'SYP',
194
+ szl: 'SZL',
195
+ thb: 'THB',
196
+ tjs: 'TJS',
197
+ tmt: 'TMT',
198
+ tnd: 'TND',
199
+ top: 'TOP',
200
+ try: 'TRY',
201
+ ttd: 'TTD',
202
+ twd: 'TWD',
203
+ tzs: 'TZS',
204
+ uah: 'UAH',
205
+ ugx: 'UGX',
206
+ usd: 'USD',
207
+ uyu: 'UYU',
208
+ uzs: 'UZS',
209
+ vef: 'VEF',
210
+ vnd: 'VND',
211
+ vuv: 'VUV',
212
+ wst: 'WST',
213
+ xaf: 'XAF',
214
+ xpf: 'XPF',
215
+ yer: 'YER',
216
+ zar: 'ZAR',
217
+ zmw: 'ZMW',
218
+ zwl: 'ZWL',
219
+ usn: undefined,
220
+ uss: undefined,
221
+ uyi: undefined,
222
+ xag: undefined,
223
+ xau: undefined,
224
+ xba: undefined,
225
+ xbb: undefined,
226
+ xbc: undefined,
227
+ xbd: undefined,
228
+ xcd: undefined,
229
+ xdr: undefined,
230
+ xfu: undefined,
231
+ xof: undefined,
232
+ xpd: undefined,
233
+ xpt: undefined,
234
+ xts: undefined,
235
+ xxx: undefined,
236
+ };
package/src/hooks.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { HyperlineAPI, Logger } from './client';
2
+
3
+ export function useHyperline(
4
+ env: {
5
+ PRODUCTION_HYPERLINE_API_KEY: string;
6
+ DEV_HYPERLINE_API_KEY: string;
7
+ },
8
+ environment: 'production' | 'development',
9
+ logger?: Logger
10
+ ) {
11
+ const isProduction = environment === 'production';
12
+
13
+ const token = isProduction
14
+ ? env.PRODUCTION_HYPERLINE_API_KEY
15
+ : env.DEV_HYPERLINE_API_KEY;
16
+
17
+ const hyperline = useHyperlineByToken(token, logger);
18
+
19
+ return { hyperline, token, isProduction };
20
+ }
21
+
22
+ export function useHyperlineByToken(token: string, logger: Logger = console) {
23
+ return new HyperlineAPI(token, logger);
24
+ }