@vrplatform/hyperline-client 1.0.13 → 1.0.15

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/src/client.ts CHANGED
@@ -104,21 +104,36 @@ export class HyperlineAPI {
104
104
  return results?.data[0];
105
105
  }
106
106
 
107
- async getCustomers(skip = 0, take = 100) {
107
+ async getCustomers(
108
+ skip = 0,
109
+ take = 100,
110
+ query: operations['getCustomers']['parameters']['query'] = {}
111
+ ) {
108
112
  return await this.fetch<
109
113
  paths['/v1/customers']['get']['responses'][200]['content']['application/json']
110
- >(`/v1/customers?take=${take}&skip=${skip}`);
114
+ >(
115
+ `/v1/customers?take=${take}&skip=${skip}&${Object.entries(query)
116
+ .filter(([_, value]) => value !== undefined)
117
+ .map(([key, value]) => `&${key}=${value}`)
118
+ .join('')}`
119
+ );
111
120
  }
112
121
 
113
122
  async getAllCustomers(
114
- items: paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data'] = []
123
+ items: paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data'] = [],
124
+ query: operations['getCustomers']['parameters']['query'] = {}
115
125
  ): Promise<
116
126
  paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data']
117
127
  > {
118
- const { data } = (await this.getCustomers(items.length)) || { data: [] };
128
+ const { data } = (await this.getCustomers(items.length, 100, {
129
+ status: 'all',
130
+ ...query,
131
+ })) || {
132
+ data: [],
133
+ };
119
134
 
120
135
  return data.length
121
- ? this.getAllCustomers([...items, ...data])
136
+ ? this.getAllCustomers([...items, ...data], { status: 'all', ...query })
122
137
  : [...items, ...data];
123
138
  }
124
139
 
@@ -245,6 +260,17 @@ export class HyperlineAPI {
245
260
  }
246
261
 
247
262
  async updateSubscription(
263
+ id: string,
264
+ data: NonNullable<
265
+ paths['/v2/subscriptions/{id}']['put']['requestBody']
266
+ >['content']['application/json']
267
+ ) {
268
+ return await this.fetch<
269
+ paths['/v2/subscriptions/{id}']['put']['responses'][200]['content']['application/json']
270
+ >(`/v2/subscriptions/${id}`, { method: 'PUT' }, data);
271
+ }
272
+
273
+ async createSubscriptionUpdate(
248
274
  id: string,
249
275
  data: NonNullable<
250
276
  paths['/v1/subscriptions/{id}/update']['post']['requestBody']
@@ -327,10 +353,24 @@ export class HyperlineAPI {
327
353
  );
328
354
  }
329
355
 
330
- async getInvoicesByCustomerId(id: string) {
356
+ async getInvoicesByCustomerId(
357
+ id: string,
358
+ filters?: Partial<operations['getInvoices']['parameters']['query']>
359
+ ) {
360
+ const queryParams = new URLSearchParams();
361
+ queryParams.append('customerId__equals', id);
362
+
363
+ if (filters) {
364
+ Object.entries(filters).forEach(([key, value]) => {
365
+ if (value !== undefined && value !== null) {
366
+ queryParams.append(key, value.toString());
367
+ }
368
+ });
369
+ }
370
+
331
371
  return await this.fetch<
332
372
  paths['/v1/invoices']['get']['responses'][200]['content']['application/json']
333
- >(`/v1/invoices?customerId__equals=${id}`);
373
+ >(`/v1/invoices?${queryParams.toString()}`);
334
374
  }
335
375
 
336
376
  async getInvoiceDownload(id: string) {
@@ -344,19 +384,31 @@ export class HyperlineAPI {
344
384
  }
345
385
 
346
386
  async getAllInvoices(
347
- items: paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data'] = []
387
+ items: paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data'] = [],
388
+ query: operations['getInvoices']['parameters']['query'] = { status: 'all' }
348
389
  ): Promise<
349
390
  paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data']
350
391
  > {
351
- const { data } = (await this.getInvoices(items.length)) || { data: [] };
392
+ const { data } = (await this.getInvoices(items.length, 100, {
393
+ status: 'all',
394
+ ...query,
395
+ })) || {
396
+ data: [],
397
+ };
352
398
 
353
399
  return data.length
354
- ? this.getAllInvoices([...items, ...data])
400
+ ? this.getAllInvoices([...items, ...data], { status: 'all', ...query })
355
401
  : [...items, ...data];
356
402
  }
357
403
 
358
404
  // OTHERS
359
405
 
406
+ async getPaymentMethod(customerId: string, paymentMethodId: string) {
407
+ return await this.fetch<
408
+ paths['/v1/customers/{id}/payment-methods/{paymentMethodId}']['get']['responses'][200]['content']['application/json']
409
+ >(`/v1/customers/${customerId}/payment-methods/${paymentMethodId}`);
410
+ }
411
+
360
412
  async createBillableEvent(data: CreateBillableEvent[]) {
361
413
  if (!data.length) return { events_created: [] };
362
414
 
package/src/const.ts CHANGED
@@ -29,6 +29,7 @@ export const HYPERLINE_DEFAULT_PLAN_ID = 'plan_Dyb5P0ICZ6HsIT';
29
29
  export const HYPERLINE_DEFAULT_DEV_PLAN_ID = 'plan_UTCVXFQnKD0oMS';
30
30
  export const HYPERLINE_DEFAULT_PLAN_NAME = 'All-in-One VRP Subscription';
31
31
  export const HYPERLINE_DEFAULT_PRODUCT_ID = 'itm_9NU7ffT14I4ris';
32
+ export const HYPERLINE_DEFAULT_MIN_AMOUNT = 12500;
32
33
 
33
34
  export const HYPERLINE_PARTNER_PLAN_ID = 'plan_vkYJcCz7z0XD0N';
34
35
  export const HYPERLINE_PARTNER_DEV_PLAN_ID = 'plan_8qtj8T4j0W3oiS';
@@ -39,6 +40,7 @@ export const GL_HYPERLINE_DEFAULT_PLAN_ID = 'plan_JXviWSpU5yuokD';
39
40
  export const GL_HYPERLINE_DEFAULT_DEV_PLAN_ID = 'plan_Nnozk8_TfYqTkj';
40
41
  export const GL_HYPERLINE_DEFAULT_PLAN_NAME = 'VRTrust Subscription';
41
42
  export const GL_HYPERLINE_DEFAULT_PRODUCT_ID = 'itm_NRTRBQ0fc8bFGW';
43
+ export const GL_HYPERLINE_DEFAULT_MIN_AMOUNT = 25000;
42
44
 
43
45
  export const GL_HYPERLINE_PARTNER_PLAN_ID = 'plan_vyxckdvUi8X_mr';
44
46
  export const GL_HYPERLINE_PARTNER_DEV_PLAN_ID = 'plan_CVXQ47ErOWANhJ';
@@ -71,7 +73,7 @@ export const WEBHOOKS = {
71
73
 
72
74
  export const CURRENCY_MAP: Record<
73
75
  currency_enum,
74
- HyperlineEntities['Currency'] | undefined
76
+ HyperlineEntities['Invoice']['currency'] | undefined
75
77
  > = {
76
78
  aed: 'AED',
77
79
  afn: 'AFN',