@vrplatform/hyperline-client 1.0.30 → 1.0.31

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.
@@ -1,4 +1,3 @@
1
- import { utc } from '@vrplatform/utils';
2
1
  import { arrayBufferToBase64 } from './utils';
3
2
  export class HyperlineAPI {
4
3
  constructor(token, logger = console) {
@@ -47,19 +46,11 @@ export class HyperlineAPI {
47
46
  (typeof content === 'string' ? content : null) ||
48
47
  (content ? JSON.stringify(content) : null) ||
49
48
  'Unknown error';
50
- if (status === 429) {
51
- // get difference between rate limit reset and now
52
- const rateLimitReset = utc(result?.headers.get('x-ratelimit-reset'));
53
- const diff = rateLimitReset.diff(utc(), 'milliseconds');
54
- // wait until rate limit resets
55
- await new Promise((resolve) => setTimeout(resolve, diff));
56
- return await this.fetchBasic(path, options, data);
57
- }
58
- else if (status === 404 && method === 'GET') {
49
+ if (status === 404 && method === 'GET') {
59
50
  return null;
60
51
  }
61
52
  else {
62
- throw new Error(`Hyperline Error ${status} (${statusText}) in ${path} for ${method}: ${message}`);
53
+ throw Object.assign(new Error(`Hyperline Error ${status} (${statusText}) in ${path} for ${method}: ${message}`), { status });
63
54
  }
64
55
  }
65
56
  else if (result.headers.get('content-type')?.includes('application/pdf'))
@@ -91,37 +82,42 @@ export class HyperlineAPI {
91
82
  this.logger.error('Missing customer ID', { id });
92
83
  throw new Error('Missing customer ID');
93
84
  }
94
- return await this.fetch(`/v1/customers/${id}`);
85
+ return await this.fetch(`/v2/customers/${id}`);
95
86
  }
96
87
  async getCustomerById(id) {
97
88
  if (!id) {
98
89
  this.logger.error('Missing tenant ID', { id });
99
90
  throw new Error('Missing tenant ID');
100
91
  }
101
- const results = await this.fetch(`/v1/customers?external_id__equals=${id}`);
92
+ const results = await this.getCustomers({
93
+ external_id__equals: id,
94
+ status: 'all',
95
+ limit: 1,
96
+ });
102
97
  return results?.data[0];
103
98
  }
104
- async getCustomers(skip = 0, take = 100, query = {}) {
99
+ async getCustomers(query = {}) {
105
100
  const queryParams = new URLSearchParams();
106
- queryParams.set('take', take.toString());
107
- queryParams.set('skip', skip.toString());
108
- for (const [key, value] of Object.entries(query)) {
101
+ for (const [key, value] of Object.entries({ limit: 100, ...query })) {
109
102
  if (value === undefined || value === null)
110
103
  continue;
111
104
  queryParams.set(key, value.toString());
112
105
  }
113
- return await this.fetch(`/v1/customers?${queryParams.toString()}`);
106
+ return await this.fetch(`/v2/customers?${queryParams.toString()}`);
114
107
  }
115
108
  async getAllCustomers(items = [], query = {}) {
116
- const { data } = (await this.getCustomers(items.length, 100, {
109
+ const page = await this.getCustomers({
117
110
  status: 'all',
118
111
  ...query,
119
- })) || {
120
- data: [],
121
- };
122
- return data.length
123
- ? this.getAllCustomers([...items, ...data], { status: 'all', ...query })
124
- : [...items, ...data];
112
+ });
113
+ if (!page)
114
+ throw new Error('Customer list not found');
115
+ return page.next_cursor
116
+ ? this.getAllCustomers([...items, ...page.data], {
117
+ ...query,
118
+ cursor: page.next_cursor,
119
+ })
120
+ : [...items, ...page.data];
125
121
  }
126
122
  async createCustomer(data) {
127
123
  return await this.fetch('/v1/customers', { method: 'POST' }, { currency: 'USD', timezone: 'Etc/UTC', ...data });
@@ -199,47 +195,29 @@ export class HyperlineAPI {
199
195
  method: 'POST',
200
196
  });
201
197
  }
202
- // PLAN
203
- async getPlan(id) {
204
- if (!id) {
205
- this.logger.error('Missing plan ID', { id });
206
- throw new Error('Missing plan ID');
207
- }
208
- return await this.fetch(`/v1/plans/${id}`);
209
- }
210
- async getPlans(skip = 0, take = 100) {
211
- return await this.fetch(`/v1/plans?take=${take}&skip=${skip}`);
212
- }
213
198
  // INVOICE
214
199
  async getInvoice(id) {
215
200
  if (!id) {
216
201
  this.logger.error('Missing invoice ID', { id });
217
202
  throw new Error('Missing invoice ID');
218
203
  }
219
- return await this.fetch(`/v1/invoices/${id}`);
204
+ return await this.fetch(`/v2/invoices/${id}`);
220
205
  }
221
- async getInvoices(skip = 0, take = 100, query = { status: 'all' }) {
206
+ async getInvoices(query = {}) {
222
207
  const queryParams = new URLSearchParams();
223
- queryParams.set('take', take.toString());
224
- queryParams.set('skip', skip.toString());
225
- for (const [key, value] of Object.entries(query)) {
208
+ for (const [key, value] of Object.entries({
209
+ limit: 100,
210
+ status: 'all',
211
+ ...query,
212
+ })) {
226
213
  if (value === undefined || value === null)
227
214
  continue;
228
215
  queryParams.set(key, value.toString());
229
216
  }
230
- return await this.fetch(`/v1/invoices?${queryParams.toString()}`);
217
+ return await this.fetch(`/v2/invoices?${queryParams.toString()}`);
231
218
  }
232
219
  async getInvoicesByCustomerId(id, filters) {
233
- const queryParams = new URLSearchParams();
234
- queryParams.append('customerId__equals', id);
235
- if (filters) {
236
- Object.entries(filters).forEach(([key, value]) => {
237
- if (value !== undefined && value !== null) {
238
- queryParams.append(key, value.toString());
239
- }
240
- });
241
- }
242
- return await this.fetch(`/v1/invoices?${queryParams.toString()}`);
220
+ return await this.getInvoices({ ...filters, customer_id: id });
243
221
  }
244
222
  async getInvoiceDownload(id) {
245
223
  return await this.fetch(
@@ -248,16 +226,16 @@ export class HyperlineAPI {
248
226
  headers: { 'Content-type': 'application/pdf' },
249
227
  });
250
228
  }
251
- async getAllInvoices(items = [], query = { status: 'all' }) {
252
- const { data } = (await this.getInvoices(items.length, 100, {
253
- status: 'all',
254
- ...query,
255
- })) || {
256
- data: [],
257
- };
258
- return data.length
259
- ? this.getAllInvoices([...items, ...data], { status: 'all', ...query })
260
- : [...items, ...data];
229
+ async getAllInvoices(items = [], query = {}) {
230
+ const page = await this.getInvoices(query);
231
+ if (!page)
232
+ throw new Error('Invoice list not found');
233
+ return page.next_cursor
234
+ ? this.getAllInvoices([...items, ...page.data], {
235
+ ...query,
236
+ cursor: page.next_cursor,
237
+ })
238
+ : [...items, ...page.data];
261
239
  }
262
240
  async voidInvoice(id, data = { send_email: false }) {
263
241
  if (!id) {
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"src/","sources":["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K,CAAC,mBAAmB,CAAC,IAA2B;QACnD,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;QAEhD,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,kBAAkB,EAClB,EAAE,MAAM,EAAE,MAAM,EAAE,EAClB,IAAI,CACL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,IAA6B;QACnD,OAAO,MAAM,IAAI,CAAC,KAAK,CAErB,mCAAmC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { utc } from '@vrplatform/utils';\nimport type { operations, paths } from './_types.generated';\nimport { BillableEvents, CreateBillableEvent } from './types';\nimport { arrayBufferToBase64 } from './utils';\n\nexport type Logger = { error(message?: any, ...optionalParams: any[]): void };\n\nexport class HyperlineAPI {\n constructor(token: string, logger: Logger = console) {\n this.headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n };\n this.logger = logger;\n }\n\n private headers: Record<string, string>;\n\n private logger: Logger;\n\n private async fetchBasic<T>(\n path: string,\n options?: RequestInit,\n data?: Record<string, any>\n ): Promise<T | null> {\n if (data) options = { body: JSON.stringify(data), ...(options || {}) };\n\n const method = (options?.method || 'GET').toUpperCase();\n const sandbox = this.headers.Authorization.includes('test')\n ? 'sandbox.'\n : '';\n\n const result = await fetch(`https://${sandbox}${path}`, {\n method: 'GET',\n ...options,\n headers: { ...this.headers, ...options?.headers },\n });\n\n if (!result?.ok) {\n const status = result?.status;\n const statusText = result?.statusText;\n let content: any = null;\n\n try {\n const rawBody = await result.text();\n const trimmedBody = rawBody.trim();\n\n if (trimmedBody) {\n try {\n content = JSON.parse(trimmedBody);\n } catch (_) {\n content = rawBody;\n }\n }\n } catch (_) {\n // ignore\n }\n\n const message =\n (content && typeof content === 'object' && 'message' in content\n ? (content as any).message\n : null) ||\n (typeof content === 'string' ? content : null) ||\n (content ? JSON.stringify(content) : null) ||\n 'Unknown error';\n\n if (status === 429) {\n // get difference between rate limit reset and now\n const rateLimitReset = utc(result?.headers.get('x-ratelimit-reset'));\n const diff = rateLimitReset.diff(utc(), 'milliseconds');\n\n // wait until rate limit resets\n await new Promise((resolve) => setTimeout(resolve, diff));\n\n return await this.fetchBasic<T>(path, options, data);\n } else if (status === 404 && method === 'GET') {\n return null;\n } else {\n throw new Error(\n `Hyperline Error ${status} (${statusText}) in ${path} for ${method}: ${message}`\n );\n }\n } else if (result.headers.get('content-type')?.includes('application/pdf'))\n return arrayBufferToBase64(await result.arrayBuffer()) as T;\n\n if (result.status === 204) return null;\n\n return (await result.json()) as T;\n }\n\n private async fetch<T>(\n path: string,\n options?: RequestInit,\n data?: Record<string, any>\n ): Promise<T | null> {\n return await this.fetchBasic(`api.hyperline.co${path}`, options, data);\n }\n\n private async fetchIngest<T>(\n path: string,\n options?: RequestInit,\n data?: Record<string, any>\n ): Promise<T | null> {\n return await this.fetchBasic(`ingest.hyperline.co${path}`, options, data);\n }\n\n // INVOICING ENTITY\n\n async getInvoicingEntities() {\n return await this.fetch<\n paths['/v1/invoicing-entities']['get']['responses'][200]['content']['application/json']\n >('/v1/invoicing-entities');\n }\n\n async getInvoicingEntity(id?: string) {\n if (!id) {\n this.logger.error('Missing invoicing entity ID', { id });\n throw new Error('Missing invoicing entity ID');\n }\n\n return await this.fetch<\n paths['/v1/invoicing-entities/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v1/invoicing-entities/${id}`);\n }\n\n // CUSTOMER\n\n async getCustomer(id?: string) {\n if (!id) {\n this.logger.error('Missing customer ID', { id });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}`);\n }\n\n async getCustomerById(id?: string) {\n if (!id) {\n this.logger.error('Missing tenant ID', { id });\n throw new Error('Missing tenant ID');\n }\n\n const results = await this.fetch<\n paths['/v1/customers']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers?external_id__equals=${id}`);\n\n return results?.data[0];\n }\n\n async getCustomers(\n skip = 0,\n take = 100,\n query: operations['getCustomers']['parameters']['query'] = {}\n ) {\n const queryParams = new URLSearchParams();\n queryParams.set('take', take.toString());\n queryParams.set('skip', skip.toString());\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n queryParams.set(key, value.toString());\n }\n\n return await this.fetch<\n paths['/v1/customers']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers?${queryParams.toString()}`);\n }\n\n async getAllCustomers(\n items: paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data'] = [],\n query: operations['getCustomers']['parameters']['query'] = {}\n ): Promise<\n paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data']\n > {\n const { data } = (await this.getCustomers(items.length, 100, {\n status: 'all',\n ...query,\n })) || {\n data: [],\n };\n\n return data.length\n ? this.getAllCustomers([...items, ...data], { status: 'all', ...query })\n : [...items, ...data];\n }\n\n async createCustomer(\n data: NonNullable<\n paths['/v1/customers']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v1/customers']['post']['responses'][201]['content']['application/json']\n >(\n '/v1/customers',\n { method: 'POST' },\n { currency: 'USD', timezone: 'Etc/UTC', ...data }\n );\n }\n\n async updateCustomer(\n id: string,\n data: NonNullable<\n paths['/v1/customers/{id}']['put']['requestBody']\n >['content']['application/json']\n ) {\n if (!id) {\n this.logger.error('Missing customer ID', { id });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}']['put']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}`, { method: 'PUT' }, data);\n }\n\n async deleteCustomer(id: string) {\n return await this.fetch<\n paths['/v1/customers/{id}']['delete']['responses'][204]['content']\n >(`/v1/customers/${id}`, {\n method: 'DELETE',\n });\n }\n\n async archiveCustomer(id: string) {\n return await this.fetch<\n paths['/v1/customers/{id}/archive']['put']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}/archive`, {\n method: 'PUT',\n });\n }\n\n async unarchiveCustomer(id: string) {\n if (!id) {\n this.logger.error('Missing customer ID', { id });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}/unarchive']['put']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}/unarchive`, { method: 'PUT' });\n }\n\n async getCustomerPortal(id: string) {\n return await this.fetch<\n paths['/v1/customers/{id}/portal']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}/portal`);\n }\n\n // SUBSCRIPTION\n\n async getSubscription(id: string, liveBilling = false) {\n if (!id) {\n this.logger.error('Missing subscription ID', { id });\n throw new Error('Missing subscription ID');\n }\n\n return await this.fetch<\n paths['/v2/subscriptions/{id}']['get']['responses'][200]['content']['application/json']\n >(\n `/v2/subscriptions/${id}?include_live_billing=${liveBilling ? 'true' : 'false'}`\n );\n }\n\n async getSubscriptions(\n skip = 0,\n take = 100,\n query: operations['getSubscriptions']['parameters']['query'] = {\n status: 'all',\n }\n ) {\n const queryParams = new URLSearchParams();\n queryParams.set('take', take.toString());\n queryParams.set('skip', skip.toString());\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n queryParams.set(key, value.toString());\n }\n\n return await this.fetch<\n paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']\n >(`/v2/subscriptions?${queryParams.toString()}`);\n }\n\n async getAllSubscriptions(\n items: paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data'] = [],\n query: operations['getSubscriptions']['parameters']['query'] = {}\n ): Promise<\n paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data']\n > {\n const { data } = (await this.getSubscriptions(\n items.length,\n 100,\n query\n )) || { data: [] };\n\n return data.length\n ? this.getAllSubscriptions([...items, ...data], query)\n : [...items, ...data];\n }\n\n async createSubscription(\n data: NonNullable<\n paths['/v2/subscriptions']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v2/subscriptions']['post']['responses'][201]['content']['application/json']\n >('/v2/subscriptions', { method: 'POST' }, data);\n }\n\n async updateSubscription(\n id: string,\n data: NonNullable<\n paths['/v2/subscriptions/{id}']['put']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v2/subscriptions/{id}']['put']['responses'][200]['content']['application/json']\n >(`/v2/subscriptions/${id}`, { method: 'PUT' }, data);\n }\n\n async createSubscriptionUpdate(\n id: string,\n data: NonNullable<\n paths['/v1/subscriptions/{id}/update']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v1/subscriptions/{id}/update']['post']['responses'][201]['content']['application/json']\n >(`/v1/subscriptions/${id}/update`, { method: 'POST' }, data);\n }\n\n async cancelSubscription(\n id: string,\n data: NonNullable<\n paths['/v1/subscriptions/{id}/cancel']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v1/subscriptions/{id}/cancel']['post']['responses'][200]['content']['application/json']\n >(\n `/v1/subscriptions/${id}/cancel`,\n {\n method: 'POST',\n },\n data\n );\n }\n\n async reinstateSubscription(id: string) {\n return await this.fetch<\n paths['/v1/subscriptions/{id}/reinstate']['post']['responses'][200]['content']['application/json']\n >(`/v1/subscriptions/${id}/reinstate`, {\n method: 'POST',\n });\n }\n\n // PLAN\n\n async getPlan(id: string) {\n if (!id) {\n this.logger.error('Missing plan ID', { id });\n throw new Error('Missing plan ID');\n }\n\n return await this.fetch<\n paths['/v1/plans/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v1/plans/${id}`);\n }\n\n async getPlans(skip = 0, take = 100) {\n return await this.fetch<\n paths['/v1/plans']['get']['responses'][200]['content']['application/json']\n >(`/v1/plans?take=${take}&skip=${skip}`);\n }\n\n // INVOICE\n\n async getInvoice(id: string) {\n if (!id) {\n this.logger.error('Missing invoice ID', { id });\n throw new Error('Missing invoice ID');\n }\n\n return await this.fetch<\n paths['/v1/invoices/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v1/invoices/${id}`);\n }\n\n async getInvoices(\n skip = 0,\n take = 100,\n query: operations['getInvoices']['parameters']['query'] = { status: 'all' }\n ) {\n const queryParams = new URLSearchParams();\n queryParams.set('take', take.toString());\n queryParams.set('skip', skip.toString());\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n queryParams.set(key, value.toString());\n }\n\n return await this.fetch<\n paths['/v1/invoices']['get']['responses'][200]['content']['application/json']\n >(`/v1/invoices?${queryParams.toString()}`);\n }\n\n async getInvoicesByCustomerId(\n id: string,\n filters?: Partial<operations['getInvoices']['parameters']['query']>\n ) {\n const queryParams = new URLSearchParams();\n queryParams.append('customerId__equals', id);\n\n if (filters) {\n Object.entries(filters).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n queryParams.append(key, value.toString());\n }\n });\n }\n\n return await this.fetch<\n paths['/v1/invoices']['get']['responses'][200]['content']['application/json']\n >(`/v1/invoices?${queryParams.toString()}`);\n }\n\n async getInvoiceDownload(id: string) {\n return await this.fetch<string>(\n // TODO: fix if type != unknown paths['/v1/invoices/{id}/download']['get']['responses'][200]['content']['application/pdf']\n `/v1/invoices/${id}/download`,\n {\n headers: { 'Content-type': 'application/pdf' },\n }\n );\n }\n\n async getAllInvoices(\n items: paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data'] = [],\n query: operations['getInvoices']['parameters']['query'] = { status: 'all' }\n ): Promise<\n paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data']\n > {\n const { data } = (await this.getInvoices(items.length, 100, {\n status: 'all',\n ...query,\n })) || {\n data: [],\n };\n\n return data.length\n ? this.getAllInvoices([...items, ...data], { status: 'all', ...query })\n : [...items, ...data];\n }\n\n async voidInvoice(\n id: string,\n data: NonNullable<\n paths['/v1/invoices/{id}/void']['post']['requestBody']\n >['content']['application/json'] = { send_email: false }\n ) {\n if (!id) {\n this.logger.error('Missing invoice ID', { id });\n throw new Error('Missing invoice ID');\n }\n\n return await this.fetch<\n paths['/v1/invoices/{id}/void']['post']['responses'][200]['content']['application/json']\n >(`/v1/invoices/${id}/void`, { method: 'POST' }, data);\n }\n\n async deleteInvoice(id: string) {\n if (!id) {\n this.logger.error('Missing invoice ID', { id });\n throw new Error('Missing invoice ID');\n }\n\n return await this.fetch<\n paths['/v1/invoices/{id}']['delete']['responses'][204]['content']\n >(`/v1/invoices/${id}`, { method: 'DELETE' });\n }\n\n // OTHERS\n\n async getCustomerPaymentMethods(customerId: string) {\n if (!customerId) {\n this.logger.error('Missing customer ID', { customerId });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}/payment-methods']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${customerId}/payment-methods`);\n }\n\n async getPaymentMethod(customerId: string, paymentMethodId: string) {\n return await this.fetch<\n paths['/v1/customers/{id}/payment-methods/{paymentMethodId}']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${customerId}/payment-methods/${paymentMethodId}`);\n }\n\n async createBillableEvent(data: CreateBillableEvent[]) {\n if (!data.length) return { events_created: [] };\n\n return await this.fetchIngest<BillableEvents>(\n '/v1/events/batch',\n { method: 'POST' },\n data\n );\n }\n\n async getComponentToken(data: { customer_id: string }) {\n return await this.fetch<\n paths['/v1/integrations/components/token']['post']['responses'][201]['content']['application/json']\n >('/v1/integrations/components/token', { method: 'POST' }, data);\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"src/","sources":["client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAI9C,MAAM,OAAO,YAAY;IACvB,YAAY,KAAa,EAAE,SAAiB,OAAO;QACjD,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEO,OAAO,CAAyB;IAEhC,MAAM,CA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;QAChD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,KAAK,CAErB,iBAAiB,UAAU,kBAAkB,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,UAAkB,EAAE,eAAuB;QAChE,OAAO,MAAM,IAAI,CAAC,KAAK,CAErB,iBAAiB,UAAU,oBAAoB,eAAe,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,IAA2B;QACnD,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;QAEhD,OAAO,MAAM,IAAI,CAAC,WAAW,CAC3B,kBAAkB,EAClB,EAAE,MAAM,EAAE,MAAM,EAAE,EAClB,IAAI,CACL,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,IAA6B;QACnD,OAAO,MAAM,IAAI,CAAC,KAAK,CAErB,mCAAmC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import type { paths } from './_types.generated';\nimport { BillableEvents, CreateBillableEvent } from './types';\nimport { arrayBufferToBase64 } from './utils';\n\nexport type Logger = { error(message?: any, ...optionalParams: any[]): void };\n\nexport class HyperlineAPI {\n constructor(token: string, logger: Logger = console) {\n this.headers = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${token}`,\n };\n this.logger = logger;\n }\n\n private headers: Record<string, string>;\n\n private logger: Logger;\n\n private async fetchBasic<T>(\n path: string,\n options?: RequestInit,\n data?: Record<string, any>\n ): Promise<T | null> {\n if (data) options = { body: JSON.stringify(data), ...(options || {}) };\n\n const method = (options?.method || 'GET').toUpperCase();\n const sandbox = this.headers.Authorization.includes('test')\n ? 'sandbox.'\n : '';\n\n const result = await fetch(`https://${sandbox}${path}`, {\n method: 'GET',\n ...options,\n headers: { ...this.headers, ...options?.headers },\n });\n\n if (!result?.ok) {\n const status = result?.status;\n const statusText = result?.statusText;\n let content: any = null;\n\n try {\n const rawBody = await result.text();\n const trimmedBody = rawBody.trim();\n\n if (trimmedBody) {\n try {\n content = JSON.parse(trimmedBody);\n } catch (_) {\n content = rawBody;\n }\n }\n } catch (_) {\n // ignore\n }\n\n const message =\n (content && typeof content === 'object' && 'message' in content\n ? (content as any).message\n : null) ||\n (typeof content === 'string' ? content : null) ||\n (content ? JSON.stringify(content) : null) ||\n 'Unknown error';\n\n if (status === 404 && method === 'GET') {\n return null;\n } else {\n throw Object.assign(\n new Error(\n `Hyperline Error ${status} (${statusText}) in ${path} for ${method}: ${message}`\n ),\n { status }\n );\n }\n } else if (result.headers.get('content-type')?.includes('application/pdf'))\n return arrayBufferToBase64(await result.arrayBuffer()) as T;\n\n if (result.status === 204) return null;\n\n return (await result.json()) as T;\n }\n\n private async fetch<T>(\n path: string,\n options?: RequestInit,\n data?: Record<string, any>\n ): Promise<T | null> {\n return await this.fetchBasic(`api.hyperline.co${path}`, options, data);\n }\n\n private async fetchIngest<T>(\n path: string,\n options?: RequestInit,\n data?: Record<string, any>\n ): Promise<T | null> {\n return await this.fetchBasic(`ingest.hyperline.co${path}`, options, data);\n }\n\n // INVOICING ENTITY\n\n async getInvoicingEntities() {\n return await this.fetch<\n paths['/v1/invoicing-entities']['get']['responses'][200]['content']['application/json']\n >('/v1/invoicing-entities');\n }\n\n async getInvoicingEntity(id?: string) {\n if (!id) {\n this.logger.error('Missing invoicing entity ID', { id });\n throw new Error('Missing invoicing entity ID');\n }\n\n return await this.fetch<\n paths['/v1/invoicing-entities/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v1/invoicing-entities/${id}`);\n }\n\n // CUSTOMER\n\n async getCustomer(id?: string) {\n if (!id) {\n this.logger.error('Missing customer ID', { id });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v2/customers/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v2/customers/${id}`);\n }\n\n async getCustomerById(id?: string) {\n if (!id) {\n this.logger.error('Missing tenant ID', { id });\n throw new Error('Missing tenant ID');\n }\n\n const results = await this.getCustomers({\n external_id__equals: id,\n status: 'all',\n limit: 1,\n });\n\n return results?.data[0];\n }\n\n async getCustomers(\n query: paths['/v2/customers']['get']['parameters']['query'] = {}\n ) {\n const queryParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries({ limit: 100, ...query })) {\n if (value === undefined || value === null) continue;\n queryParams.set(key, value.toString());\n }\n\n return await this.fetch<\n paths['/v2/customers']['get']['responses'][200]['content']['application/json']\n >(`/v2/customers?${queryParams.toString()}`);\n }\n\n async getAllCustomers(\n items: paths['/v2/customers']['get']['responses'][200]['content']['application/json']['data'] = [],\n query: paths['/v2/customers']['get']['parameters']['query'] = {}\n ): Promise<\n paths['/v2/customers']['get']['responses'][200]['content']['application/json']['data']\n > {\n const page = await this.getCustomers({\n status: 'all',\n ...query,\n });\n if (!page) throw new Error('Customer list not found');\n\n return page.next_cursor\n ? this.getAllCustomers([...items, ...page.data], {\n ...query,\n cursor: page.next_cursor,\n })\n : [...items, ...page.data];\n }\n\n async createCustomer(\n data: NonNullable<\n paths['/v1/customers']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v1/customers']['post']['responses'][201]['content']['application/json']\n >(\n '/v1/customers',\n { method: 'POST' },\n { currency: 'USD', timezone: 'Etc/UTC', ...data }\n );\n }\n\n async updateCustomer(\n id: string,\n data: NonNullable<\n paths['/v1/customers/{id}']['put']['requestBody']\n >['content']['application/json']\n ) {\n if (!id) {\n this.logger.error('Missing customer ID', { id });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}']['put']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}`, { method: 'PUT' }, data);\n }\n\n async deleteCustomer(id: string) {\n return await this.fetch<\n paths['/v1/customers/{id}']['delete']['responses'][204]['content']\n >(`/v1/customers/${id}`, {\n method: 'DELETE',\n });\n }\n\n async archiveCustomer(id: string) {\n return await this.fetch<\n paths['/v1/customers/{id}/archive']['put']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}/archive`, {\n method: 'PUT',\n });\n }\n\n async unarchiveCustomer(id: string) {\n if (!id) {\n this.logger.error('Missing customer ID', { id });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}/unarchive']['put']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}/unarchive`, { method: 'PUT' });\n }\n\n async getCustomerPortal(id: string) {\n return await this.fetch<\n paths['/v1/customers/{id}/portal']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${id}/portal`);\n }\n\n // SUBSCRIPTION\n\n async getSubscription(id: string, liveBilling = false) {\n if (!id) {\n this.logger.error('Missing subscription ID', { id });\n throw new Error('Missing subscription ID');\n }\n\n return await this.fetch<\n paths['/v2/subscriptions/{id}']['get']['responses'][200]['content']['application/json']\n >(\n `/v2/subscriptions/${id}?include_live_billing=${liveBilling ? 'true' : 'false'}`\n );\n }\n\n async getSubscriptions(\n skip = 0,\n take = 100,\n query: paths['/v2/subscriptions']['get']['parameters']['query'] = {\n status: 'all',\n }\n ) {\n const queryParams = new URLSearchParams();\n queryParams.set('take', take.toString());\n queryParams.set('skip', skip.toString());\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null) continue;\n queryParams.set(key, value.toString());\n }\n\n return await this.fetch<\n paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']\n >(`/v2/subscriptions?${queryParams.toString()}`);\n }\n\n async getAllSubscriptions(\n items: paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data'] = [],\n query: paths['/v2/subscriptions']['get']['parameters']['query'] = {}\n ): Promise<\n paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data']\n > {\n const { data } = (await this.getSubscriptions(\n items.length,\n 100,\n query\n )) || { data: [] };\n\n return data.length\n ? this.getAllSubscriptions([...items, ...data], query)\n : [...items, ...data];\n }\n\n async createSubscription(\n data: NonNullable<\n paths['/v2/subscriptions']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v2/subscriptions']['post']['responses'][201]['content']['application/json']\n >('/v2/subscriptions', { method: 'POST' }, data);\n }\n\n async updateSubscription(\n id: string,\n data: NonNullable<\n paths['/v2/subscriptions/{id}']['put']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v2/subscriptions/{id}']['put']['responses'][200]['content']['application/json']\n >(`/v2/subscriptions/${id}`, { method: 'PUT' }, data);\n }\n\n async createSubscriptionUpdate(\n id: string,\n data: NonNullable<\n paths['/v1/subscriptions/{id}/update']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v1/subscriptions/{id}/update']['post']['responses'][201]['content']['application/json']\n >(`/v1/subscriptions/${id}/update`, { method: 'POST' }, data);\n }\n\n async cancelSubscription(\n id: string,\n data: NonNullable<\n paths['/v1/subscriptions/{id}/cancel']['post']['requestBody']\n >['content']['application/json']\n ) {\n return await this.fetch<\n paths['/v1/subscriptions/{id}/cancel']['post']['responses'][200]['content']['application/json']\n >(\n `/v1/subscriptions/${id}/cancel`,\n {\n method: 'POST',\n },\n data\n );\n }\n\n async reinstateSubscription(id: string) {\n return await this.fetch<\n paths['/v1/subscriptions/{id}/reinstate']['post']['responses'][200]['content']['application/json']\n >(`/v1/subscriptions/${id}/reinstate`, {\n method: 'POST',\n });\n }\n\n // INVOICE\n\n async getInvoice(id: string) {\n if (!id) {\n this.logger.error('Missing invoice ID', { id });\n throw new Error('Missing invoice ID');\n }\n\n return await this.fetch<\n paths['/v2/invoices/{id}']['get']['responses'][200]['content']['application/json']\n >(`/v2/invoices/${id}`);\n }\n\n async getInvoices(\n query: paths['/v2/invoices']['get']['parameters']['query'] = {}\n ) {\n const queryParams = new URLSearchParams();\n for (const [key, value] of Object.entries({\n limit: 100,\n status: 'all',\n ...query,\n })) {\n if (value === undefined || value === null) continue;\n queryParams.set(key, value.toString());\n }\n\n return await this.fetch<\n paths['/v2/invoices']['get']['responses'][200]['content']['application/json']\n >(`/v2/invoices?${queryParams.toString()}`);\n }\n\n async getInvoicesByCustomerId(\n id: string,\n filters?: paths['/v2/invoices']['get']['parameters']['query']\n ) {\n return await this.getInvoices({ ...filters, customer_id: id });\n }\n\n async getInvoiceDownload(id: string) {\n return await this.fetch<string>(\n // TODO: fix if type != unknown paths['/v1/invoices/{id}/download']['get']['responses'][200]['content']['application/pdf']\n `/v1/invoices/${id}/download`,\n {\n headers: { 'Content-type': 'application/pdf' },\n }\n );\n }\n\n async getAllInvoices(\n items: paths['/v2/invoices']['get']['responses'][200]['content']['application/json']['data'] = [],\n query: paths['/v2/invoices']['get']['parameters']['query'] = {}\n ): Promise<\n paths['/v2/invoices']['get']['responses'][200]['content']['application/json']['data']\n > {\n const page = await this.getInvoices(query);\n if (!page) throw new Error('Invoice list not found');\n\n return page.next_cursor\n ? this.getAllInvoices([...items, ...page.data], {\n ...query,\n cursor: page.next_cursor,\n })\n : [...items, ...page.data];\n }\n\n async voidInvoice(\n id: string,\n data: NonNullable<\n paths['/v1/invoices/{id}/void']['post']['requestBody']\n >['content']['application/json'] = { send_email: false }\n ) {\n if (!id) {\n this.logger.error('Missing invoice ID', { id });\n throw new Error('Missing invoice ID');\n }\n\n return await this.fetch<\n paths['/v1/invoices/{id}/void']['post']['responses'][200]['content']['application/json']\n >(`/v1/invoices/${id}/void`, { method: 'POST' }, data);\n }\n\n async deleteInvoice(id: string) {\n if (!id) {\n this.logger.error('Missing invoice ID', { id });\n throw new Error('Missing invoice ID');\n }\n\n return await this.fetch<\n paths['/v1/invoices/{id}']['delete']['responses'][204]['content']\n >(`/v1/invoices/${id}`, { method: 'DELETE' });\n }\n\n // OTHERS\n\n async getCustomerPaymentMethods(customerId: string) {\n if (!customerId) {\n this.logger.error('Missing customer ID', { customerId });\n throw new Error('Missing customer ID');\n }\n\n return await this.fetch<\n paths['/v1/customers/{id}/payment-methods']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${customerId}/payment-methods`);\n }\n\n async getPaymentMethod(customerId: string, paymentMethodId: string) {\n return await this.fetch<\n paths['/v1/customers/{id}/payment-methods/{paymentMethodId}']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers/${customerId}/payment-methods/${paymentMethodId}`);\n }\n\n async createBillableEvent(data: CreateBillableEvent[]) {\n if (!data.length) return { events_created: [] };\n\n return await this.fetchIngest<BillableEvents>(\n '/v1/events/batch',\n { method: 'POST' },\n data\n );\n }\n\n async getComponentToken(data: { customer_id: string }) {\n return await this.fetch<\n paths['/v1/integrations/components/token']['post']['responses'][201]['content']['application/json']\n >('/v1/integrations/components/token', { method: 'POST' }, data);\n }\n}\n"]}
@@ -52,6 +52,7 @@ export declare const WEBHOOKS: {
52
52
  'payment_method.deleted': "hyperline_payment_method_deleted";
53
53
  'payment_method.expired': "hyperline_payment_method_expired";
54
54
  'subscription.activated': "hyperline_subscription_status_changed";
55
+ 'subscription.updated': "hyperline_subscription_status_changed";
55
56
  'subscription.reactivated': "hyperline_subscription_status_changed";
56
57
  'subscription.cancellation_scheduled': "hyperline_subscription_cancellation_scheduled";
57
58
  'subscription.cancelled': "hyperline_subscription_status_changed";
@@ -56,6 +56,7 @@ export const WEBHOOKS = {
56
56
  'payment_method.deleted': 'hyperline_payment_method_deleted',
57
57
  'payment_method.expired': 'hyperline_payment_method_expired',
58
58
  'subscription.activated': 'hyperline_subscription_status_changed',
59
+ 'subscription.updated': 'hyperline_subscription_status_changed',
59
60
  'subscription.reactivated': 'hyperline_subscription_status_changed',
60
61
  'subscription.cancellation_scheduled': 'hyperline_subscription_cancellation_scheduled',
61
62
  'subscription.cancelled': 'hyperline_subscription_status_changed',
@@ -1 +1 @@
1
- {"version":3,"file":"const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E,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;CAIf,CAAC","sourcesContent":["import type { TrackingEvent } from '@vrplatform/tracking';\nimport { HyperlineEntities } from './types';\n\n// Tenants\nexport const VRP_TENANT_ID = '7bfec41f-aa3f-4602-95d2-f7996e4f0e59';\nexport const DEMO_TEST_PARTNER_TENANT_ID =\n '0b6a7bd6-56cc-46b5-b2ab-1bd7d1e994fa';\nexport const XIMPLIFI_TENANT_ID = 'd6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5';\nexport const TEST_TENANT_ID = 'fa4d1a20-2f47-4021-9c72-c5a809be9c48';\n\n// Customers\nexport const XIMPLIFI_CUSTOMER_ID = 'cus_HDUZawnaJbPa9p';\nexport const XIMPLIFI_DEV_CUSTOMER_ID = 'cus_dNUGCETGYVu3ZV';\n\n// Coupons\nexport const XIMPLIFI_COUPON_ID = 'cou_MXCaik3r19_Xkn';\nexport const XIMPLIFI_DEV_COUPON_ID = 'cou_MGtxHbT8IR1gK9';\n\nexport const ACCOUNTING_PARTNER_COUPON_ID = 'cou_PJQ328MBAD9kxY';\nexport const ACCOUNTING_PARTNER_DEV_COUPON_ID = 'cou_y6UfaI2X1m34Qg';\n\nexport const VRTRUST_HALF_PRICE_COUPON_ID = 'cou_CTOQqs0SOeSc-e'; // 50% off\nexport const VRTRUST_HALF_PRICE_DEV_COUPON_ID = 'cou_tHLiRdwQ6xGqKA'; // 50% off\nexport const VRTRUST_FREE_PRICE_COUPON_ID = 'cou_JGiLite8_nFtnX'; // 100% off\nexport const VRTRUST_FREE_PRICE_DEV_COUPON_ID = 'cou_N4GNqSSLEFscto'; // 100% off\n\nexport const HYPERLINE_PARTNER_TIER_10_PERCENT_COUPON_ID = 'cou_56kMhdo4fYNs7c';\nexport const HYPERLINE_PARTNER_TIER_20_PERCENT_COUPON_ID = 'cou_ExjGVUcu15XKeq';\nexport const HYPERLINE_PARTNER_TIER_30_PERCENT_COUPON_ID = 'cou_PJI6mXZHOyoWlx';\nexport const HYPERLINE_PARTNER_TIER_40_PERCENT_COUPON_ID = 'cou_gnYic7Uu8zHJX9';\nexport const HYPERLINE_PARTNER_TIER_50_PERCENT_COUPON_ID = 'cou_1saVofWCoJsVyz';\nexport const HYPERLINE_PARTNER_TIER_60_PERCENT_COUPON_ID = 'cou_tJI9hmHkQXjXOp';\n\nexport const HYPERLINE_PARTNER_TIER_COUPON_IDS = {\n 10: HYPERLINE_PARTNER_TIER_10_PERCENT_COUPON_ID,\n 20: HYPERLINE_PARTNER_TIER_20_PERCENT_COUPON_ID,\n 30: HYPERLINE_PARTNER_TIER_30_PERCENT_COUPON_ID,\n 40: HYPERLINE_PARTNER_TIER_40_PERCENT_COUPON_ID,\n 50: HYPERLINE_PARTNER_TIER_50_PERCENT_COUPON_ID,\n 60: HYPERLINE_PARTNER_TIER_60_PERCENT_COUPON_ID,\n} as const;\n\n// Plans\nexport const HYPERLINE_DEFAULT_PLAN_ID = 'plan_Dyb5P0ICZ6HsIT';\nexport const HYPERLINE_DEFAULT_DEV_PLAN_ID = 'plan_UTCVXFQnKD0oMS';\nexport const HYPERLINE_DEFAULT_PLAN_NAME = 'All-in-One VRP Subscription';\nexport const HYPERLINE_DEFAULT_PRODUCT_ID = 'itm_9NU7ffT14I4ris';\nexport const HYPERLINE_DEFAULT_MIN_AMOUNT = 12500;\n\nexport const HYPERLINE_NEW_PRICING_DIRECT_PRODUCT_ID = 'itm_VeR6AJi9OyUQN2';\nexport const HYPERLINE_NEW_PRICING_PARTNER_CLIENT_PRODUCT_ID =\n 'itm_wrrT0HuAZ8Tlh1';\n\nexport const HYPERLINE_PARTNER_PLAN_ID = 'plan_vkYJcCz7z0XD0N';\nexport const HYPERLINE_PARTNER_DEV_PLAN_ID = 'plan_8qtj8T4j0W3oiS';\nexport const HYPERLINE_PARTNER_PLAN_NAME = 'VRP Subscription - Partners';\nexport const HYPERLINE_PARTNER_PRODUCT_ID = 'itm_AJBM0_jPsrqizl';\n\nexport const GL_HYPERLINE_DEFAULT_PLAN_ID = 'plan_JXviWSpU5yuokD';\nexport const GL_HYPERLINE_DEFAULT_DEV_PLAN_ID = 'plan_Nnozk8_TfYqTkj';\nexport const GL_HYPERLINE_DEFAULT_PLAN_NAME = 'VRTrust Subscription';\nexport const GL_HYPERLINE_DEFAULT_PRODUCT_ID = 'itm_NRTRBQ0fc8bFGW';\nexport const GL_HYPERLINE_DEFAULT_MIN_AMOUNT = 25000;\n\nexport const GL_HYPERLINE_PARTNER_PLAN_ID = 'plan_vyxckdvUi8X_mr';\nexport const GL_HYPERLINE_PARTNER_DEV_PLAN_ID = 'plan_CVXQ47ErOWANhJ';\nexport const GL_HYPERLINE_PARTNER_PLAN_NAME = 'VRTrust Subscription - Partners';\nexport const GL_HYPERLINE_PARTNER_PRODUCT_ID = 'itm_bE4y9lhrZ6Qtsf';\n\nexport const WEBHOOKS = {\n 'payment_method.created': 'hyperline_payment_method_created',\n 'payment_method.errored': 'hyperline_payment_method_errored',\n 'payment_method.deleted': 'hyperline_payment_method_deleted',\n 'payment_method.expired': 'hyperline_payment_method_expired',\n 'subscription.activated': 'hyperline_subscription_status_changed',\n 'subscription.reactivated': 'hyperline_subscription_status_changed',\n 'subscription.cancellation_scheduled':\n 'hyperline_subscription_cancellation_scheduled',\n 'subscription.cancelled': 'hyperline_subscription_status_changed',\n 'subscription.reinstated': 'hyperline_subscription_status_changed',\n 'subscription.charged': 'hyperline_subscription_charged',\n 'subscription.errored': 'hyperline_subscription_status_changed',\n 'subscription.paused': 'hyperline_subscription_status_changed',\n 'subscription.voided': 'hyperline_subscription_status_changed',\n 'customer.created': 'hyperline_customer_created',\n 'customer.updated': 'hyperline_customer_updated',\n 'customer.deleted': 'hyperline_customer_deleted',\n 'invoice.errored': 'hyperline_invoice_errored',\n 'invoice.ready': 'hyperline_invoice_ready',\n 'invoice.settled': 'hyperline_invoice_settled',\n 'invoice.voided': 'hyperline_invoice_voided',\n} satisfies Record<string, TrackingEvent>;\n\nexport const CURRENCY_MAP = {\n aed: 'AED',\n afn: 'AFN',\n all: 'ALL',\n amd: 'AMD',\n ang: 'ANG',\n aoa: 'AOA',\n ars: 'ARS',\n aud: 'AUD',\n awg: 'AWG',\n azn: 'AZN',\n bam: 'BAM',\n bbd: 'BBD',\n bdt: 'BDT',\n bgn: 'BGN',\n bhd: 'BHD',\n bif: 'BIF',\n bmd: 'BMD',\n bnd: 'BND',\n bob: 'BOB',\n bov: 'BOB',\n brl: 'BRL',\n bsd: 'BSD',\n btn: 'BTN',\n bwp: 'BWP',\n byn: 'BYR',\n byr: 'BYR',\n bzd: 'BZD',\n cad: 'CAD',\n cdf: 'CDF',\n che: 'CHF',\n chf: 'CHF',\n chw: 'CHF',\n clf: 'CLP',\n clp: 'CLP',\n cny: 'CNY',\n cop: 'COP',\n cou: 'COP',\n crc: 'CRC',\n cuc: 'CUP',\n cup: 'CUP',\n cve: 'CVE',\n czk: 'CZK',\n djf: 'DJF',\n dkk: 'DKK',\n dop: 'DOP',\n dzd: 'DZD',\n egp: 'EGP',\n ern: 'ERN',\n etb: 'ETB',\n eur: 'EUR',\n fjd: 'FJD',\n fkp: 'FKP',\n gbp: 'GBP',\n gel: 'GEL',\n ghs: 'GHS',\n gip: 'GIP',\n gmd: 'GMD',\n gnf: 'GNF',\n gtq: 'GTQ',\n gyd: 'GYD',\n hkd: 'HKD',\n hnl: 'HNL',\n hrk: 'HRK',\n htg: 'HTG',\n huf: 'HUF',\n idr: 'IDR',\n ils: 'ILS',\n inr: 'INR',\n iqd: 'IQD',\n irr: 'IRR',\n isk: 'ISK',\n jmd: 'JMD',\n jod: 'JOD',\n jpy: 'JPY',\n kes: 'KES',\n kgs: 'KGS',\n khr: 'KHR',\n kmf: 'KMF',\n kpw: 'KPW',\n krw: 'KRW',\n kwd: 'KWD',\n kyd: 'KYD',\n kzt: 'KZT',\n lak: 'LAK',\n lbp: 'LBP',\n lkr: 'LKR',\n lrd: 'LRD',\n lsl: 'LSL',\n ltl: 'EUR',\n lvl: 'EUR',\n lyd: 'LYD',\n mad: 'MAD',\n mdl: 'MDL',\n mga: 'MGA',\n mkd: 'MKD',\n mmk: 'MMK',\n mnt: 'MNT',\n mop: 'MOP',\n mro: 'MRO',\n mur: 'MUR',\n mvr: 'MVR',\n mwk: 'MWK',\n mxn: 'MXN',\n mxv: 'MXN',\n myr: 'MYR',\n mzn: 'MZN',\n nad: 'NAD',\n ngn: 'NGN',\n nio: 'NIO',\n nok: 'NOK',\n npr: 'NPR',\n nzd: 'NZD',\n omr: 'OMR',\n pab: 'PAB',\n pen: 'PEN',\n pgk: 'PGK',\n php: 'PHP',\n pkr: 'PKR',\n pln: 'PLN',\n pyg: 'PYG',\n qar: 'QAR',\n ron: 'RON',\n rsd: 'RSD',\n rub: 'RUB',\n rwf: 'RWF',\n sar: 'SAR',\n sbd: 'SBD',\n scr: 'SCR',\n sdg: 'SDG',\n sek: 'SEK',\n sgd: 'SGD',\n shp: 'SHP',\n sll: 'SLL',\n sos: 'SOS',\n srd: 'SRD',\n ssp: 'SSP',\n std: 'STD',\n syp: 'SYP',\n szl: 'SZL',\n thb: 'THB',\n tjs: 'TJS',\n tmt: 'TMT',\n tnd: 'TND',\n top: 'TOP',\n try: 'TRY',\n ttd: 'TTD',\n twd: 'TWD',\n tzs: 'TZS',\n uah: 'UAH',\n ugx: 'UGX',\n usd: 'USD',\n uyu: 'UYU',\n uzs: 'UZS',\n vef: 'VEF',\n vnd: 'VND',\n vuv: 'VUV',\n wst: 'WST',\n xaf: 'XAF',\n xpf: 'XPF',\n yer: 'YER',\n zar: 'ZAR',\n zmw: 'ZMW',\n zwl: 'ZWL',\n usn: undefined,\n uss: undefined,\n uyi: undefined,\n xag: undefined,\n xau: undefined,\n xba: undefined,\n xbb: undefined,\n xbc: undefined,\n xbd: undefined,\n xcd: undefined,\n xdr: undefined,\n xfu: undefined,\n xof: undefined,\n xpd: undefined,\n xpt: undefined,\n xts: undefined,\n xxx: undefined,\n} satisfies Record<\n string,\n HyperlineEntities['Invoice']['currency'] | undefined\n>;\n"]}
1
+ {"version":3,"file":"const.js","sourceRoot":"src/","sources":["const.ts"],"names":[],"mappings":"AAGA,UAAU;AACV,MAAM,CAAC,MAAM,aAAa,GAAG,sCAAsC,CAAC;AACpE,MAAM,CAAC,MAAM,2BAA2B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GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;CAIf,CAAC","sourcesContent":["import type { TrackingEvent } from '@vrplatform/tracking';\nimport { HyperlineEntities } from './types';\n\n// Tenants\nexport const VRP_TENANT_ID = '7bfec41f-aa3f-4602-95d2-f7996e4f0e59';\nexport const DEMO_TEST_PARTNER_TENANT_ID =\n '0b6a7bd6-56cc-46b5-b2ab-1bd7d1e994fa';\nexport const XIMPLIFI_TENANT_ID = 'd6ab2bbe-e0fc-48d9-89a3-c3c05f4e79b5';\nexport const TEST_TENANT_ID = 'fa4d1a20-2f47-4021-9c72-c5a809be9c48';\n\n// Customers\nexport const XIMPLIFI_CUSTOMER_ID = 'cus_HDUZawnaJbPa9p';\nexport const XIMPLIFI_DEV_CUSTOMER_ID = 'cus_dNUGCETGYVu3ZV';\n\n// Coupons\nexport const XIMPLIFI_COUPON_ID = 'cou_MXCaik3r19_Xkn';\nexport const XIMPLIFI_DEV_COUPON_ID = 'cou_MGtxHbT8IR1gK9';\n\nexport const ACCOUNTING_PARTNER_COUPON_ID = 'cou_PJQ328MBAD9kxY';\nexport const ACCOUNTING_PARTNER_DEV_COUPON_ID = 'cou_y6UfaI2X1m34Qg';\n\nexport const VRTRUST_HALF_PRICE_COUPON_ID = 'cou_CTOQqs0SOeSc-e'; // 50% off\nexport const VRTRUST_HALF_PRICE_DEV_COUPON_ID = 'cou_tHLiRdwQ6xGqKA'; // 50% off\nexport const VRTRUST_FREE_PRICE_COUPON_ID = 'cou_JGiLite8_nFtnX'; // 100% off\nexport const VRTRUST_FREE_PRICE_DEV_COUPON_ID = 'cou_N4GNqSSLEFscto'; // 100% off\n\nexport const HYPERLINE_PARTNER_TIER_10_PERCENT_COUPON_ID = 'cou_56kMhdo4fYNs7c';\nexport const HYPERLINE_PARTNER_TIER_20_PERCENT_COUPON_ID = 'cou_ExjGVUcu15XKeq';\nexport const HYPERLINE_PARTNER_TIER_30_PERCENT_COUPON_ID = 'cou_PJI6mXZHOyoWlx';\nexport const HYPERLINE_PARTNER_TIER_40_PERCENT_COUPON_ID = 'cou_gnYic7Uu8zHJX9';\nexport const HYPERLINE_PARTNER_TIER_50_PERCENT_COUPON_ID = 'cou_1saVofWCoJsVyz';\nexport const HYPERLINE_PARTNER_TIER_60_PERCENT_COUPON_ID = 'cou_tJI9hmHkQXjXOp';\n\nexport const HYPERLINE_PARTNER_TIER_COUPON_IDS = {\n 10: HYPERLINE_PARTNER_TIER_10_PERCENT_COUPON_ID,\n 20: HYPERLINE_PARTNER_TIER_20_PERCENT_COUPON_ID,\n 30: HYPERLINE_PARTNER_TIER_30_PERCENT_COUPON_ID,\n 40: HYPERLINE_PARTNER_TIER_40_PERCENT_COUPON_ID,\n 50: HYPERLINE_PARTNER_TIER_50_PERCENT_COUPON_ID,\n 60: HYPERLINE_PARTNER_TIER_60_PERCENT_COUPON_ID,\n} as const;\n\n// Plans\nexport const HYPERLINE_DEFAULT_PLAN_ID = 'plan_Dyb5P0ICZ6HsIT';\nexport const HYPERLINE_DEFAULT_DEV_PLAN_ID = 'plan_UTCVXFQnKD0oMS';\nexport const HYPERLINE_DEFAULT_PLAN_NAME = 'All-in-One VRP Subscription';\nexport const HYPERLINE_DEFAULT_PRODUCT_ID = 'itm_9NU7ffT14I4ris';\nexport const HYPERLINE_DEFAULT_MIN_AMOUNT = 12500;\n\nexport const HYPERLINE_NEW_PRICING_DIRECT_PRODUCT_ID = 'itm_VeR6AJi9OyUQN2';\nexport const HYPERLINE_NEW_PRICING_PARTNER_CLIENT_PRODUCT_ID =\n 'itm_wrrT0HuAZ8Tlh1';\n\nexport const HYPERLINE_PARTNER_PLAN_ID = 'plan_vkYJcCz7z0XD0N';\nexport const HYPERLINE_PARTNER_DEV_PLAN_ID = 'plan_8qtj8T4j0W3oiS';\nexport const HYPERLINE_PARTNER_PLAN_NAME = 'VRP Subscription - Partners';\nexport const HYPERLINE_PARTNER_PRODUCT_ID = 'itm_AJBM0_jPsrqizl';\n\nexport const GL_HYPERLINE_DEFAULT_PLAN_ID = 'plan_JXviWSpU5yuokD';\nexport const GL_HYPERLINE_DEFAULT_DEV_PLAN_ID = 'plan_Nnozk8_TfYqTkj';\nexport const GL_HYPERLINE_DEFAULT_PLAN_NAME = 'VRTrust Subscription';\nexport const GL_HYPERLINE_DEFAULT_PRODUCT_ID = 'itm_NRTRBQ0fc8bFGW';\nexport const GL_HYPERLINE_DEFAULT_MIN_AMOUNT = 25000;\n\nexport const GL_HYPERLINE_PARTNER_PLAN_ID = 'plan_vyxckdvUi8X_mr';\nexport const GL_HYPERLINE_PARTNER_DEV_PLAN_ID = 'plan_CVXQ47ErOWANhJ';\nexport const GL_HYPERLINE_PARTNER_PLAN_NAME = 'VRTrust Subscription - Partners';\nexport const GL_HYPERLINE_PARTNER_PRODUCT_ID = 'itm_bE4y9lhrZ6Qtsf';\n\nexport const WEBHOOKS = {\n 'payment_method.created': 'hyperline_payment_method_created',\n 'payment_method.errored': 'hyperline_payment_method_errored',\n 'payment_method.deleted': 'hyperline_payment_method_deleted',\n 'payment_method.expired': 'hyperline_payment_method_expired',\n 'subscription.activated': 'hyperline_subscription_status_changed',\n 'subscription.updated': 'hyperline_subscription_status_changed',\n 'subscription.reactivated': 'hyperline_subscription_status_changed',\n 'subscription.cancellation_scheduled':\n 'hyperline_subscription_cancellation_scheduled',\n 'subscription.cancelled': 'hyperline_subscription_status_changed',\n 'subscription.reinstated': 'hyperline_subscription_status_changed',\n 'subscription.charged': 'hyperline_subscription_charged',\n 'subscription.errored': 'hyperline_subscription_status_changed',\n 'subscription.paused': 'hyperline_subscription_status_changed',\n 'subscription.voided': 'hyperline_subscription_status_changed',\n 'customer.created': 'hyperline_customer_created',\n 'customer.updated': 'hyperline_customer_updated',\n 'customer.deleted': 'hyperline_customer_deleted',\n 'invoice.errored': 'hyperline_invoice_errored',\n 'invoice.ready': 'hyperline_invoice_ready',\n 'invoice.settled': 'hyperline_invoice_settled',\n 'invoice.voided': 'hyperline_invoice_voided',\n} satisfies Record<string, TrackingEvent>;\n\nexport const CURRENCY_MAP = {\n aed: 'AED',\n afn: 'AFN',\n all: 'ALL',\n amd: 'AMD',\n ang: 'ANG',\n aoa: 'AOA',\n ars: 'ARS',\n aud: 'AUD',\n awg: 'AWG',\n azn: 'AZN',\n bam: 'BAM',\n bbd: 'BBD',\n bdt: 'BDT',\n bgn: 'BGN',\n bhd: 'BHD',\n bif: 'BIF',\n bmd: 'BMD',\n bnd: 'BND',\n bob: 'BOB',\n bov: 'BOB',\n brl: 'BRL',\n bsd: 'BSD',\n btn: 'BTN',\n bwp: 'BWP',\n byn: 'BYR',\n byr: 'BYR',\n bzd: 'BZD',\n cad: 'CAD',\n cdf: 'CDF',\n che: 'CHF',\n chf: 'CHF',\n chw: 'CHF',\n clf: 'CLP',\n clp: 'CLP',\n cny: 'CNY',\n cop: 'COP',\n cou: 'COP',\n crc: 'CRC',\n cuc: 'CUP',\n cup: 'CUP',\n cve: 'CVE',\n czk: 'CZK',\n djf: 'DJF',\n dkk: 'DKK',\n dop: 'DOP',\n dzd: 'DZD',\n egp: 'EGP',\n ern: 'ERN',\n etb: 'ETB',\n eur: 'EUR',\n fjd: 'FJD',\n fkp: 'FKP',\n gbp: 'GBP',\n gel: 'GEL',\n ghs: 'GHS',\n gip: 'GIP',\n gmd: 'GMD',\n gnf: 'GNF',\n gtq: 'GTQ',\n gyd: 'GYD',\n hkd: 'HKD',\n hnl: 'HNL',\n hrk: 'HRK',\n htg: 'HTG',\n huf: 'HUF',\n idr: 'IDR',\n ils: 'ILS',\n inr: 'INR',\n iqd: 'IQD',\n irr: 'IRR',\n isk: 'ISK',\n jmd: 'JMD',\n jod: 'JOD',\n jpy: 'JPY',\n kes: 'KES',\n kgs: 'KGS',\n khr: 'KHR',\n kmf: 'KMF',\n kpw: 'KPW',\n krw: 'KRW',\n kwd: 'KWD',\n kyd: 'KYD',\n kzt: 'KZT',\n lak: 'LAK',\n lbp: 'LBP',\n lkr: 'LKR',\n lrd: 'LRD',\n lsl: 'LSL',\n ltl: 'EUR',\n lvl: 'EUR',\n lyd: 'LYD',\n mad: 'MAD',\n mdl: 'MDL',\n mga: 'MGA',\n mkd: 'MKD',\n mmk: 'MMK',\n mnt: 'MNT',\n mop: 'MOP',\n mro: 'MRO',\n mur: 'MUR',\n mvr: 'MVR',\n mwk: 'MWK',\n mxn: 'MXN',\n mxv: 'MXN',\n myr: 'MYR',\n mzn: 'MZN',\n nad: 'NAD',\n ngn: 'NGN',\n nio: 'NIO',\n nok: 'NOK',\n npr: 'NPR',\n nzd: 'NZD',\n omr: 'OMR',\n pab: 'PAB',\n pen: 'PEN',\n pgk: 'PGK',\n php: 'PHP',\n pkr: 'PKR',\n pln: 'PLN',\n pyg: 'PYG',\n qar: 'QAR',\n ron: 'RON',\n rsd: 'RSD',\n rub: 'RUB',\n rwf: 'RWF',\n sar: 'SAR',\n sbd: 'SBD',\n scr: 'SCR',\n sdg: 'SDG',\n sek: 'SEK',\n sgd: 'SGD',\n shp: 'SHP',\n sll: 'SLL',\n sos: 'SOS',\n srd: 'SRD',\n ssp: 'SSP',\n std: 'STD',\n syp: 'SYP',\n szl: 'SZL',\n thb: 'THB',\n tjs: 'TJS',\n tmt: 'TMT',\n tnd: 'TND',\n top: 'TOP',\n try: 'TRY',\n ttd: 'TTD',\n twd: 'TWD',\n tzs: 'TZS',\n uah: 'UAH',\n ugx: 'UGX',\n usd: 'USD',\n uyu: 'UYU',\n uzs: 'UZS',\n vef: 'VEF',\n vnd: 'VND',\n vuv: 'VUV',\n wst: 'WST',\n xaf: 'XAF',\n xpf: 'XPF',\n yer: 'YER',\n zar: 'ZAR',\n zmw: 'ZMW',\n zwl: 'ZWL',\n usn: undefined,\n uss: undefined,\n uyi: undefined,\n xag: undefined,\n xau: undefined,\n xba: undefined,\n xbb: undefined,\n xbc: undefined,\n xbd: undefined,\n xcd: undefined,\n xdr: undefined,\n xfu: undefined,\n xof: undefined,\n xpd: undefined,\n xpt: undefined,\n xts: undefined,\n xxx: undefined,\n} satisfies Record<\n string,\n HyperlineEntities['Invoice']['currency'] | undefined\n>;\n"]}
@@ -31,5 +31,6 @@ export type CreateBillableEvent = {
31
31
  amount?: number;
32
32
  amountGl?: number;
33
33
  amountNonGl?: number;
34
+ amountAll?: number;
34
35
  };
35
36
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type { components, paths } from './_types.generated';\nimport { WEBHOOKS } from './const';\n\nexport type HyperlineEntities = components['schemas'];\n\nexport type HyperlineEndpoints = paths;\n\nexport type HyperlineWebhook = keyof typeof WEBHOOKS;\n\nexport type HyperlineEvent<T extends HyperlineWebhook> = (typeof WEBHOOKS)[T];\n\nexport type HyperlinePayload<T extends HyperlineWebhook> = {\n event_type: T;\n data: Record<string, any>;\n};\n\nexport type BillableEvent = {\n record: {\n id: '202408_cus_w_Q7M9bXcHMKB6';\n amount: 26;\n };\n timestamp: '2024-08-07T07:35:20.307Z';\n event_type: 'api_call';\n customer_id: 'cus_w_Q7M9bXcHMKB6';\n};\n\nexport type BillableEvents = {\n events_created: BillableEvent[];\n};\n\nexport type CreateBillableEvent = {\n customer_id: string;\n event_type: 'api_call';\n timestamp: string;\n record: {\n id?: string;\n durationInMs?: number;\n isVerified?: true;\n amount?: number;\n amountGl?: number;\n amountNonGl?: number;\n };\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import type { components, paths } from './_types.generated';\nimport { WEBHOOKS } from './const';\n\nexport type HyperlineEntities = components['schemas'];\n\nexport type HyperlineEndpoints = paths;\n\nexport type HyperlineWebhook = keyof typeof WEBHOOKS;\n\nexport type HyperlineEvent<T extends HyperlineWebhook> = (typeof WEBHOOKS)[T];\n\nexport type HyperlinePayload<T extends HyperlineWebhook> = {\n event_type: T;\n data: Record<string, any>;\n};\n\nexport type BillableEvent = {\n record: {\n id: '202408_cus_w_Q7M9bXcHMKB6';\n amount: 26;\n };\n timestamp: '2024-08-07T07:35:20.307Z';\n event_type: 'api_call';\n customer_id: 'cus_w_Q7M9bXcHMKB6';\n};\n\nexport type BillableEvents = {\n events_created: BillableEvent[];\n};\n\nexport type CreateBillableEvent = {\n customer_id: string;\n event_type: 'api_call';\n timestamp: string;\n record: {\n id?: string;\n durationInMs?: number;\n isVerified?: true;\n amount?: number;\n amountGl?: number;\n amountNonGl?: number;\n amountAll?: number;\n };\n};\n"]}
@@ -6,11 +6,11 @@ export declare function calculateMrr(subscriptionId: string, estimated?: boolean
6
6
  products?: unknown[];
7
7
  coupons?: ({
8
8
  type: 'amount';
9
- repeat: 'once' | 'forever' | 'custom';
9
+ repeat: HyperlineEntities['Coupon']['repeat'];
10
10
  discount_amount: number;
11
11
  } | {
12
12
  type: 'percent';
13
- repeat: 'once' | 'forever' | 'custom';
13
+ repeat: HyperlineEntities['Coupon']['repeat'];
14
14
  discount_percent: number;
15
15
  })[];
16
16
  phases?: {
@@ -35,7 +35,7 @@ export declare function calculateMrr(subscriptionId: string, estimated?: boolean
35
35
  } | null>;
36
36
  getInvoicesByCustomerId(id: string): Promise<{
37
37
  data: {
38
- emitted_at: string;
38
+ issued_at: string;
39
39
  total_amount: number;
40
40
  }[];
41
41
  } | null>;
@@ -90,7 +90,7 @@ export async function calculateMrr(subscriptionId, estimated = false, _activeLis
90
90
  : { data: [] };
91
91
  // sort invoices by date
92
92
  const invoices = data
93
- ?.sort((a, b) => a.emitted_at.localeCompare(b.emitted_at))
93
+ ?.sort((a, b) => a.issued_at.localeCompare(b.issued_at))
94
94
  .reverse();
95
95
  // get the last invoice
96
96
  mrr = (invoices[0]?.total_amount || 0) / 100;
@@ -1 +1 @@
1
- {"version":3,"file":"calculateMrr.js","sourceRoot":"src/","sources":["utils/calculateMrr.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAAsB,EACtB,SAAS,GAAG,KAAK,EACjB,eAAwB,EACxB,YAqDI,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC,EACrD,kBAAkB,GAAG,KAAK;IAE1B,MAAM,aAAa,GAAG,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\n HYPERLINE_DEFAULT_PLAN_ID,\n} from '../const';\nimport { useHyperlineByToken } from '../hooks';\nimport type { HyperlineEntities } from '../types';\n\nexport async function calculateMrr(\n subscriptionId: string,\n estimated = false,\n _activeListings?: number,\n hyperline: {\n getSubscription(\n id: string,\n liveBilling?: boolean\n ): Promise<{\n customer_id: string;\n plan_id: string | null;\n products?: unknown[];\n coupons?: (\n | {\n type: 'amount';\n repeat: 'once' | 'forever' | 'custom';\n discount_amount: number;\n }\n | {\n type: 'percent';\n repeat: 'once' | 'forever' | 'custom';\n discount_percent: number;\n }\n )[];\n phases?: {\n type: HyperlineEntities['SubscriptionDetails']['phases'][number]['type'];\n products: {\n min_amount?: number | null;\n max_amount?: number | null;\n prices: (\n | {\n type: 'volume';\n amount: number;\n from: number;\n to: number | null;\n unit_count: number;\n }\n | {\n type:\n | 'bps'\n | 'bulk'\n | 'bundle'\n | 'fee'\n | 'flat_fee'\n | 'packaged';\n }\n )[];\n }[];\n }[];\n live_billing?: { total_amount: number };\n } | null>;\n getInvoicesByCustomerId(id: string): Promise<{\n data: {\n emitted_at: string;\n total_amount: number;\n }[];\n } | null>;\n } = useHyperlineByToken(process.env.HYPERLINE_TOKEN!),\n includeLiveBilling = false\n) {\n const _subscription = await hyperline.getSubscription(\n subscriptionId,\n includeLiveBilling\n );\n if (!_subscription) throw new Error('Subscription not found');\n\n const { products, phases, ...subscription } = _subscription;\n\n let mrr = 0;\n const activeListings = _activeListings || 0;\n const phase = phases?.find((x) => x.type === 'standard');\n const product = phase?.products?.[0];\n const type = product?.prices?.[0].type;\n if (type === 'volume') {\n const volumePrices: Array<{\n amount: number;\n from: number;\n to: number | null;\n unit_count: number;\n }> = [];\n\n product?.prices?.forEach((price) => {\n if (\n price.type !== 'volume' ||\n !('amount' in price) ||\n !('from' in price) ||\n !('to' in price) ||\n !('unit_count' in price)\n )\n return;\n\n volumePrices.push({\n amount: price.amount,\n from: price.from,\n to: price.to,\n unit_count: price.unit_count,\n });\n });\n volumePrices.sort((a, b) => a.from - b.from);\n\n mrr =\n volumePrices.reduce((acc, price) => {\n const listings =\n price.to && activeListings >= price.to\n ? price.to - price.from\n : activeListings >= price.from\n ? activeListings - price.from\n : 0;\n\n acc += (price.amount / 100) * (listings / price.unit_count);\n\n return acc;\n }, 0) || 0;\n\n const firstTier = volumePrices[0];\n const secondTier = volumePrices[1];\n const product_min_amount =\n product &&\n 'min_amount' in product &&\n typeof product.min_amount === 'number'\n ? product.min_amount\n : null;\n const product_max_amount =\n product &&\n 'max_amount' in product &&\n typeof product.max_amount === 'number'\n ? product.max_amount\n : null;\n const inferred_min_amount =\n firstTier &&\n secondTier &&\n firstTier.from === 0 &&\n firstTier.to != null &&\n secondTier.from === firstTier.to &&\n firstTier.amount === secondTier.amount &&\n firstTier.unit_count === secondTier.unit_count\n ? firstTier.amount *\n ((firstTier.to - firstTier.from) / firstTier.unit_count)\n : 0;\n const plan_min_amount = [\n GL_HYPERLINE_DEFAULT_PLAN_ID,\n GL_HYPERLINE_DEFAULT_DEV_PLAN_ID,\n ].includes(subscription.plan_id!)\n ? GL_HYPERLINE_DEFAULT_MIN_AMOUNT\n : [HYPERLINE_DEFAULT_PLAN_ID, HYPERLINE_DEFAULT_DEV_PLAN_ID].includes(\n subscription.plan_id!\n )\n ? HYPERLINE_DEFAULT_MIN_AMOUNT\n : 0;\n\n const min_amount =\n ((product_min_amount || plan_min_amount || inferred_min_amount) ?? 0) /\n 100;\n mrr = Math.max(mrr, min_amount);\n\n const max_amount = ((product_max_amount || 0) ?? 0) / 100;\n mrr = max_amount > 0 ? Math.min(mrr, max_amount) : mrr;\n\n // apply discounts (only these who repeat forever if estimated is true)\n (subscription.coupons || [])\n .filter((coupon) => (estimated ? coupon.repeat === 'forever' : true))\n .forEach((x) => {\n if ('discount_amount' in x && x.discount_amount)\n mrr -= x.discount_amount / 100;\n else if ('discount_percent' in x && x.discount_percent)\n mrr -= (x.discount_percent / 100) * mrr;\n });\n } else if (type === 'bps') {\n const { data } = subscription?.customer_id\n ? (await hyperline.getInvoicesByCustomerId(subscription.customer_id)) || {\n data: [],\n }\n : { data: [] };\n\n // sort invoices by date\n const invoices = data\n ?.sort((a, b) => a.emitted_at.localeCompare(b.emitted_at))\n .reverse();\n\n // get the last invoice\n mrr = (invoices[0]?.total_amount || 0) / 100;\n }\n\n return {\n mrr,\n mrrAlt:\n subscription.live_billing?.total_amount == null\n ? null\n : subscription.live_billing.total_amount / 100,\n };\n}\n"]}
1
+ {"version":3,"file":"calculateMrr.js","sourceRoot":"src/","sources":["utils/calculateMrr.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,4BAA4B,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG/C,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAAsB,EACtB,SAAS,GAAG,KAAK,EACjB,eAAwB,EACxB,YAsDI,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC,EACrD,kBAAkB,GAAG,KAAK;IAE1B,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,eAAe,CACnD,cAAc,EACd,kBAAkB,CACnB,CAAC;IACF,IAAI,CAAC,aAAa;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAE9D,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,GAAG,aAAa,CAAC;IAE5D,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,MAAM,cAAc,GAAG,eAAe,IAAI,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,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AAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAEjB,wBAAwB;QACxB,MAAM,QAAQ,GAAG,IAAI;YACnB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aACvD,OAAO,EAAE,CAAC;QAEb,uBAAuB;QACvB,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC;IAC/C,CAAC;IAED,OAAO;QACL,GAAG;QACH,MAAM,EACJ,YAAY,CAAC,YAAY,EAAE,YAAY,IAAI,IAAI;YAC7C,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,YAAY,GAAG,GAAG;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import {\n GL_HYPERLINE_DEFAULT_DEV_PLAN_ID,\n GL_HYPERLINE_DEFAULT_MIN_AMOUNT,\n GL_HYPERLINE_DEFAULT_PLAN_ID,\n HYPERLINE_DEFAULT_DEV_PLAN_ID,\n HYPERLINE_DEFAULT_MIN_AMOUNT,\n HYPERLINE_DEFAULT_PLAN_ID,\n} from '../const';\nimport { useHyperlineByToken } from '../hooks';\nimport type { HyperlineEntities } from '../types';\n\nexport async function calculateMrr(\n subscriptionId: string,\n estimated = false,\n _activeListings?: number,\n hyperline: {\n getSubscription(\n id: string,\n liveBilling?: boolean\n ): Promise<{\n customer_id: string;\n // BIL-614: legacy minimums remain until the subscription migration is complete.\n plan_id: string | null;\n products?: unknown[];\n coupons?: (\n | {\n type: 'amount';\n repeat: HyperlineEntities['Coupon']['repeat'];\n discount_amount: number;\n }\n | {\n type: 'percent';\n repeat: HyperlineEntities['Coupon']['repeat'];\n discount_percent: number;\n }\n )[];\n phases?: {\n type: HyperlineEntities['SubscriptionDetails']['phases'][number]['type'];\n products: {\n min_amount?: number | null;\n max_amount?: number | null;\n prices: (\n | {\n type: 'volume';\n amount: number;\n from: number;\n to: number | null;\n unit_count: number;\n }\n | {\n type:\n | 'bps'\n | 'bulk'\n | 'bundle'\n | 'fee'\n | 'flat_fee'\n | 'packaged';\n }\n )[];\n }[];\n }[];\n live_billing?: { total_amount: number };\n } | null>;\n getInvoicesByCustomerId(id: string): Promise<{\n data: {\n issued_at: string;\n total_amount: number;\n }[];\n } | null>;\n } = useHyperlineByToken(process.env.HYPERLINE_TOKEN!),\n includeLiveBilling = false\n) {\n const _subscription = await hyperline.getSubscription(\n subscriptionId,\n includeLiveBilling\n );\n if (!_subscription) throw new Error('Subscription not found');\n\n const { products, phases, ...subscription } = _subscription;\n\n let mrr = 0;\n const activeListings = _activeListings || 0;\n const phase = phases?.find((x) => x.type === 'standard');\n const product = phase?.products?.[0];\n const type = product?.prices?.[0].type;\n if (type === 'volume') {\n const volumePrices: Array<{\n amount: number;\n from: number;\n to: number | null;\n unit_count: number;\n }> = [];\n\n product?.prices?.forEach((price) => {\n if (\n price.type !== 'volume' ||\n !('amount' in price) ||\n !('from' in price) ||\n !('to' in price) ||\n !('unit_count' in price)\n )\n return;\n\n volumePrices.push({\n amount: price.amount,\n from: price.from,\n to: price.to,\n unit_count: price.unit_count,\n });\n });\n volumePrices.sort((a, b) => a.from - b.from);\n\n mrr =\n volumePrices.reduce((acc, price) => {\n const listings =\n price.to && activeListings >= price.to\n ? price.to - price.from\n : activeListings >= price.from\n ? activeListings - price.from\n : 0;\n\n acc += (price.amount / 100) * (listings / price.unit_count);\n\n return acc;\n }, 0) || 0;\n\n const firstTier = volumePrices[0];\n const secondTier = volumePrices[1];\n const product_min_amount =\n product &&\n 'min_amount' in product &&\n typeof product.min_amount === 'number'\n ? product.min_amount\n : null;\n const product_max_amount =\n product &&\n 'max_amount' in product &&\n typeof product.max_amount === 'number'\n ? product.max_amount\n : null;\n const inferred_min_amount =\n firstTier &&\n secondTier &&\n firstTier.from === 0 &&\n firstTier.to != null &&\n secondTier.from === firstTier.to &&\n firstTier.amount === secondTier.amount &&\n firstTier.unit_count === secondTier.unit_count\n ? firstTier.amount *\n ((firstTier.to - firstTier.from) / firstTier.unit_count)\n : 0;\n const plan_min_amount = [\n GL_HYPERLINE_DEFAULT_PLAN_ID,\n GL_HYPERLINE_DEFAULT_DEV_PLAN_ID,\n ].includes(subscription.plan_id!)\n ? GL_HYPERLINE_DEFAULT_MIN_AMOUNT\n : [HYPERLINE_DEFAULT_PLAN_ID, HYPERLINE_DEFAULT_DEV_PLAN_ID].includes(\n subscription.plan_id!\n )\n ? HYPERLINE_DEFAULT_MIN_AMOUNT\n : 0;\n\n const min_amount =\n ((product_min_amount || plan_min_amount || inferred_min_amount) ?? 0) /\n 100;\n mrr = Math.max(mrr, min_amount);\n\n const max_amount = ((product_max_amount || 0) ?? 0) / 100;\n mrr = max_amount > 0 ? Math.min(mrr, max_amount) : mrr;\n\n // apply discounts (only these who repeat forever if estimated is true)\n (subscription.coupons || [])\n .filter((coupon) => (estimated ? coupon.repeat === 'forever' : true))\n .forEach((x) => {\n if ('discount_amount' in x && x.discount_amount)\n mrr -= x.discount_amount / 100;\n else if ('discount_percent' in x && x.discount_percent)\n mrr -= (x.discount_percent / 100) * mrr;\n });\n } else if (type === 'bps') {\n const { data } = subscription?.customer_id\n ? (await hyperline.getInvoicesByCustomerId(subscription.customer_id)) || {\n data: [],\n }\n : { data: [] };\n\n // sort invoices by date\n const invoices = data\n ?.sort((a, b) => a.issued_at.localeCompare(b.issued_at))\n .reverse();\n\n // get the last invoice\n mrr = (invoices[0]?.total_amount || 0) / 100;\n }\n\n return {\n mrr,\n mrrAlt:\n subscription.live_billing?.total_amount == null\n ? null\n : subscription.live_billing.total_amount / 100,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrplatform/hyperline-client",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "main": "src/index.ts",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -32,10 +32,10 @@
32
32
  "node": ">=14"
33
33
  },
34
34
  "dependencies": {
35
- "@vrplatform/tracking": "*",
36
- "@vrplatform/utils": "*"
35
+ "@vrplatform/tracking": "*"
37
36
  },
38
37
  "devDependencies": {
39
- "openapi-typescript": "^7.13.0"
38
+ "openapi-typescript": "7.13.0",
39
+ "typescript": "5.9.3"
40
40
  }
41
41
  }