@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.
- package/build/main/client.d.ts +812 -0
- package/build/main/client.js +187 -0
- package/build/main/client.js.map +1 -0
- package/build/main/const.d.ts +24 -0
- package/build/main/const.js +209 -1
- package/build/main/const.js.map +1 -1
- package/build/main/hooks.d.ts +10 -0
- package/build/main/hooks.js +13 -0
- package/build/main/hooks.js.map +1 -0
- package/build/main/index.d.ts +3 -867
- package/build/main/index.js +3 -217
- package/build/main/index.js.map +1 -1
- package/build/main/tsconfig.main.tsbuildinfo +1 -1
- package/build/main/types.d.ts +35 -0
- package/build/main/types.js +2 -0
- package/build/main/types.js.map +1 -0
- package/build/main/utils.d.ts +1 -0
- package/build/main/utils.js +6 -0
- package/build/main/utils.js.map +1 -0
- package/build/module/client.d.ts +812 -0
- package/build/module/client.js +189 -0
- package/build/module/client.js.map +1 -0
- package/build/module/const.d.ts +24 -0
- package/build/module/const.js +209 -1
- package/build/module/const.js.map +1 -1
- package/build/module/hooks.d.ts +10 -0
- package/build/module/hooks.js +13 -0
- package/build/module/hooks.js.map +1 -0
- package/build/module/index.d.ts +3 -867
- package/build/module/index.js +3 -219
- package/build/module/index.js.map +1 -1
- package/build/module/tsconfig.esm.tsbuildinfo +1 -1
- package/build/module/types.d.ts +35 -0
- package/build/module/types.js +2 -0
- package/build/module/types.js.map +1 -0
- package/build/module/utils.d.ts +1 -0
- package/build/module/utils.js +6 -0
- package/build/module/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/client.ts +362 -0
- package/src/const.ts +225 -1
- package/src/hooks.ts +24 -0
- package/src/index.ts +3 -445
- package/src/types.ts +43 -0
- package/src/utils.ts +5 -0
package/build/main/index.js
CHANGED
|
@@ -1,219 +1,5 @@
|
|
|
1
|
-
import { utc } from '@finalytic/utils';
|
|
2
1
|
export * from './const';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
'payment_method.deleted': 'hyperline_payment_method_deleted',
|
|
7
|
-
'subscription.activated': 'hyperline_subscription_status_changed',
|
|
8
|
-
'subscription.reactivated': 'hyperline_subscription_status_changed',
|
|
9
|
-
'subscription.cancelled': 'hyperline_subscription_status_changed',
|
|
10
|
-
'subscription.cancellation_scheduled': 'hyperline_subscription_cancellation_scheduled',
|
|
11
|
-
// 'subscription.created': 'hyperline_subscription_created',
|
|
12
|
-
'subscription.errored': 'hyperline_subscription_status_changed',
|
|
13
|
-
'subscription.paused': 'hyperline_subscription_status_changed',
|
|
14
|
-
'subscription.voided': 'hyperline_subscription_status_changed',
|
|
15
|
-
// 'subscription.charged': 'hyperline_subscription_charged',
|
|
16
|
-
'customer.created': 'hyperline_customer_created',
|
|
17
|
-
'customer.updated': 'hyperline_customer_updated',
|
|
18
|
-
};
|
|
19
|
-
function arrayBufferToBase64(arrayBuffer) {
|
|
20
|
-
const uint8Array = new Uint8Array(arrayBuffer);
|
|
21
|
-
const binaryString = String.fromCharCode.apply(null, uint8Array);
|
|
22
|
-
return btoa(binaryString);
|
|
23
|
-
}
|
|
24
|
-
export class HyperlineAPI {
|
|
25
|
-
constructor(token, logger = console) {
|
|
26
|
-
this.headers = {
|
|
27
|
-
'Content-Type': 'application/json',
|
|
28
|
-
Authorization: `Bearer ${token}`,
|
|
29
|
-
};
|
|
30
|
-
this.logger = logger;
|
|
31
|
-
}
|
|
32
|
-
async fetchBasic(path, options, data) {
|
|
33
|
-
if (data)
|
|
34
|
-
options = { body: JSON.stringify(data), ...(options || {}) };
|
|
35
|
-
const sandbox = this.headers.Authorization.includes('test')
|
|
36
|
-
? 'sandbox.'
|
|
37
|
-
: '';
|
|
38
|
-
const result = await fetch(`https://${sandbox}${path}`, {
|
|
39
|
-
method: 'GET',
|
|
40
|
-
...options,
|
|
41
|
-
headers: { ...this.headers, ...options?.headers },
|
|
42
|
-
});
|
|
43
|
-
if (!result || !result?.ok) {
|
|
44
|
-
const status = result?.status;
|
|
45
|
-
const statusText = result?.statusText;
|
|
46
|
-
if (status === 429) {
|
|
47
|
-
// get difference between rate limit reset and now
|
|
48
|
-
const rateLimitReset = utc(result?.headers.get('x-ratelimit-reset'));
|
|
49
|
-
const diff = rateLimitReset.diff(utc(), 'milliseconds');
|
|
50
|
-
// wait until rate limit resets
|
|
51
|
-
await new Promise((resolve) => setTimeout(resolve, diff));
|
|
52
|
-
return await this.fetchBasic(path, options, data);
|
|
53
|
-
}
|
|
54
|
-
else if (status === 404) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const content = await result.json();
|
|
59
|
-
throw new Error(`Hyperline Error ${status} (${statusText}) in ${path} for ${options?.method || 'GET'}: ${content.message}`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else if (result.headers.get('content-type')?.includes('application/pdf'))
|
|
63
|
-
return arrayBufferToBase64(await result.arrayBuffer());
|
|
64
|
-
return (await result.json());
|
|
65
|
-
}
|
|
66
|
-
async fetch(path, options, data) {
|
|
67
|
-
return await this.fetchBasic(`api.hyperline.co${path}`, options, data);
|
|
68
|
-
}
|
|
69
|
-
async fetchIngest(path, options, data) {
|
|
70
|
-
return await this.fetchBasic(`ingest.hyperline.co${path}`, options, data);
|
|
71
|
-
}
|
|
72
|
-
// CUSTOMER
|
|
73
|
-
async getCustomer(id) {
|
|
74
|
-
if (!id) {
|
|
75
|
-
this.logger.error('Missing customer ID', { id });
|
|
76
|
-
throw new Error('Missing customer ID');
|
|
77
|
-
}
|
|
78
|
-
return await this.fetch(`/v1/customers/${id}`);
|
|
79
|
-
}
|
|
80
|
-
async getCustomers(skip = 0, take = 100) {
|
|
81
|
-
return await this.fetch(`/v1/customers?take=${take}&skip=${skip}`);
|
|
82
|
-
}
|
|
83
|
-
async getAllCustomers(items = []) {
|
|
84
|
-
const { data } = (await this.getCustomers(items.length)) || { data: [] };
|
|
85
|
-
return data.length
|
|
86
|
-
? this.getAllCustomers([...items, ...data])
|
|
87
|
-
: [...items, ...data];
|
|
88
|
-
}
|
|
89
|
-
async createCustomer(data) {
|
|
90
|
-
return await this.fetch('/v1/customers', { method: 'POST' }, { currency: 'USD', timezone: 'Etc/UTC', ...data });
|
|
91
|
-
}
|
|
92
|
-
async updateCustomer(id, data) {
|
|
93
|
-
if (!id) {
|
|
94
|
-
this.logger.error('Missing customer ID', { id });
|
|
95
|
-
throw new Error('Missing customer ID');
|
|
96
|
-
}
|
|
97
|
-
return await this.fetch(`/v1/customers/${id}`, { method: 'PUT' }, data);
|
|
98
|
-
}
|
|
99
|
-
async deleteCustomer(id) {
|
|
100
|
-
return await this.fetch(`/v1/customers/${id}`, {
|
|
101
|
-
method: 'DELETE',
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
async archiveCustomer(id) {
|
|
105
|
-
return await this.fetch(`/v1/customers/${id}/archive`, {
|
|
106
|
-
method: 'PUT',
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async unarchiveCustomer(id) {
|
|
110
|
-
if (!id) {
|
|
111
|
-
this.logger.error('Missing customer ID', { id });
|
|
112
|
-
throw new Error('Missing customer ID');
|
|
113
|
-
}
|
|
114
|
-
return await this.fetch(`/v1/customers/${id}/unarchive`, { method: 'PUT' });
|
|
115
|
-
}
|
|
116
|
-
async getCustomerPortal(id) {
|
|
117
|
-
return await this.fetch(`/v1/customers/${id}/portal`);
|
|
118
|
-
}
|
|
119
|
-
// SUBSCRIPTION
|
|
120
|
-
async getSubscription(id) {
|
|
121
|
-
if (!id) {
|
|
122
|
-
this.logger.error('Missing subscription ID', { id });
|
|
123
|
-
throw new Error('Missing subscription ID');
|
|
124
|
-
}
|
|
125
|
-
return await this.fetch(`/v2/subscriptions/${id}?include_live_billing=true`);
|
|
126
|
-
}
|
|
127
|
-
async getSubscriptions(skip = 0, take = 100, query = {
|
|
128
|
-
status: 'all',
|
|
129
|
-
}) {
|
|
130
|
-
return await this.fetch(`/v2/subscriptions?take=${take}&skip=${skip}${Object.entries(query)
|
|
131
|
-
.filter(([_, value]) => value !== undefined)
|
|
132
|
-
.map(([key, value]) => `&${key}=${value}`)
|
|
133
|
-
.join('')}`);
|
|
134
|
-
}
|
|
135
|
-
async getAllSubscriptions(items = [], query = {}) {
|
|
136
|
-
const { data } = (await this.getSubscriptions(items.length, 100, query)) || { data: [] };
|
|
137
|
-
return data.length
|
|
138
|
-
? this.getAllSubscriptions([...items, ...data], query)
|
|
139
|
-
: [...items, ...data];
|
|
140
|
-
}
|
|
141
|
-
async createSubscription(data) {
|
|
142
|
-
return await this.fetch('/v2/subscriptions', { method: 'POST' }, data);
|
|
143
|
-
}
|
|
144
|
-
async updateSubscription(id, data) {
|
|
145
|
-
return await this.fetch(`/v1/subscriptions/${id}/update`, { method: 'POST' }, data);
|
|
146
|
-
}
|
|
147
|
-
async cancelSubscription(id, data) {
|
|
148
|
-
return await this.fetch(`/v1/subscriptions/${id}/cancel`, {
|
|
149
|
-
method: 'POST',
|
|
150
|
-
}, data);
|
|
151
|
-
}
|
|
152
|
-
async reinstateSubscription(id) {
|
|
153
|
-
return await this.fetch(`/v1/subscriptions/${id}/reinstate`, {
|
|
154
|
-
method: 'POST',
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
// PLAN
|
|
158
|
-
async getPlan(id) {
|
|
159
|
-
if (!id) {
|
|
160
|
-
this.logger.error('Missing plan ID', { id });
|
|
161
|
-
throw new Error('Missing plan ID');
|
|
162
|
-
}
|
|
163
|
-
return await this.fetch(`/v1/plans/${id}`);
|
|
164
|
-
}
|
|
165
|
-
async getPlans(skip = 0, take = 100) {
|
|
166
|
-
return await this.fetch(`/v1/plans?take=${take}&skip=${skip}`);
|
|
167
|
-
}
|
|
168
|
-
// INVOICE
|
|
169
|
-
async getInvoice(id) {
|
|
170
|
-
if (!id) {
|
|
171
|
-
this.logger.error('Missing invoice ID', { id });
|
|
172
|
-
throw new Error('Missing invoice ID');
|
|
173
|
-
}
|
|
174
|
-
return await this.fetch(`/v1/invoices/${id}`);
|
|
175
|
-
}
|
|
176
|
-
async getInvoices(skip = 0, take = 100, query = { status: 'all' }) {
|
|
177
|
-
return await this.fetch(`/v1/invoices?take=${take}&skip=${skip}&${Object.entries(query)
|
|
178
|
-
.filter(([_, value]) => value !== undefined)
|
|
179
|
-
.map(([key, value]) => `&${key}=${value}`)
|
|
180
|
-
.join('')}`);
|
|
181
|
-
}
|
|
182
|
-
async getInvoicesByCustomerId(id) {
|
|
183
|
-
return await this.fetch(`/v1/invoices?customerId__equals=${id}`);
|
|
184
|
-
}
|
|
185
|
-
async getInvoiceDownload(id) {
|
|
186
|
-
return await this.fetch(
|
|
187
|
-
// TODO: fix if type != unknown paths['/v1/invoices/{id}/download']['get']['responses'][200]['content']['application/pdf']
|
|
188
|
-
`/v1/invoices/${id}/download`, {
|
|
189
|
-
headers: { 'Content-type': 'application/pdf' },
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
async getAllInvoices(items = []) {
|
|
193
|
-
const { data } = (await this.getInvoices(items.length)) || { data: [] };
|
|
194
|
-
return data.length
|
|
195
|
-
? this.getAllInvoices([...items, ...data])
|
|
196
|
-
: [...items, ...data];
|
|
197
|
-
}
|
|
198
|
-
// OTHERS
|
|
199
|
-
async createBillableEvent(data) {
|
|
200
|
-
if (!data.length)
|
|
201
|
-
return { events_created: [] };
|
|
202
|
-
return await this.fetchIngest('/v1/events/batch', { method: 'POST' }, data);
|
|
203
|
-
}
|
|
204
|
-
async getComponentToken(data) {
|
|
205
|
-
return await this.fetch('/v1/integrations/components/token', { method: 'POST' }, data);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
export function useHyperline(env, environment, logger) {
|
|
209
|
-
const isProduction = environment === 'production';
|
|
210
|
-
const token = isProduction
|
|
211
|
-
? env.PRODUCTION_HYPERLINE_API_KEY
|
|
212
|
-
: env.DEV_HYPERLINE_API_KEY;
|
|
213
|
-
const hyperline = useHyperlineByToken(token, logger);
|
|
214
|
-
return { hyperline, token, isProduction };
|
|
215
|
-
}
|
|
216
|
-
export function useHyperlineByToken(token, logger = console) {
|
|
217
|
-
return new HyperlineAPI(token, logger);
|
|
218
|
-
}
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './client';
|
|
4
|
+
export * from './hooks';
|
|
219
5
|
//# sourceMappingURL=index.js.map
|
package/build/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAOvC,cAAc,SAAS,CAAC;AAExB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,wBAAwB,EAAE,kCAAkC;IAC5D,wBAAwB,EAAE,kCAAkC;IAC5D,wBAAwB,EAAE,kCAAkC;IAC5D,wBAAwB,EAAE,uCAAuC;IACjE,0BAA0B,EAAE,uCAAuC;IACnE,wBAAwB,EAAE,uCAAuC;IACjE,qCAAqC,EACnC,+CAA+C;IACjD,4DAA4D;IAC5D,sBAAsB,EAAE,uCAAuC;IAC/D,qBAAqB,EAAE,uCAAuC;IAC9D,qBAAqB,EAAE,uCAAuC;IAC9D,4DAA4D;IAC5D,kBAAkB,EAAE,4BAA4B;IAChD,kBAAkB,EAAE,4BAA4B;CACT,CAAC;AAqC1C,SAAS,mBAAmB,CAAC,WAAwB;IACnD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,UAAiB,CAAC,CAAC;IACxE,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC;AAED,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;QAC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C;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,IAEvB;QACC,OAAO,MAAM,IAAI,CAAC,KAAK,CAErB,mCAAmC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IACnE,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAC1B,GAGC,EACD,WAAyC,EACzC,MAAe;IAEf,MAAM,YAAY,GAAG,WAAW,KAAK,YAAY,CAAC;IAElD,MAAM,KAAK,GAAG,YAAY;QACxB,CAAC,CAAC,GAAG,CAAC,4BAA4B;QAClC,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC;IAE9B,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAErD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,SAAiB,OAAO;IACzE,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { utc } from '@finalytic/utils';\nimport type { TrackingEvent } from '@vrplatform/log';\nimport type { components, operations, paths } from './_types.generated';\n\nexport type HyperlineEntities = components['schemas'];\nexport type HyperlineEndpoints = paths;\n\nexport * from './const';\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 'subscription.activated': 'hyperline_subscription_status_changed',\n 'subscription.reactivated': 'hyperline_subscription_status_changed',\n 'subscription.cancelled': 'hyperline_subscription_status_changed',\n 'subscription.cancellation_scheduled':\n 'hyperline_subscription_cancellation_scheduled',\n // 'subscription.created': 'hyperline_subscription_created',\n 'subscription.errored': 'hyperline_subscription_status_changed',\n 'subscription.paused': 'hyperline_subscription_status_changed',\n 'subscription.voided': 'hyperline_subscription_status_changed',\n // 'subscription.charged': 'hyperline_subscription_charged',\n 'customer.created': 'hyperline_customer_created',\n 'customer.updated': 'hyperline_customer_updated',\n} satisfies Record<string, TrackingEvent>;\n\nexport type HyperlineWebhook = keyof typeof webhooks;\nexport type HyperlineEvent<T extends HyperlineWebhook> = (typeof webhooks)[T];\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};\nexport type BillableEvents = {\n events_created: BillableEvent[];\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\ntype Logger = { error(message?: any, ...optionalParams: any[]): void };\n\nfunction arrayBufferToBase64(arrayBuffer: ArrayBuffer) {\n const uint8Array = new Uint8Array(arrayBuffer);\n const binaryString = String.fromCharCode.apply(null, uint8Array as any);\n return btoa(binaryString);\n}\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 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 || !result?.ok) {\n const status = result?.status;\n const statusText = result?.statusText;\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) {\n return null;\n } else {\n const content: any = await result.json();\n throw new Error(\n `Hyperline Error ${status} (${statusText}) in ${path} for ${options?.method || 'GET'}: ${content.message}`\n );\n }\n } else if (result.headers.get('content-type')?.includes('application/pdf'))\n return arrayBufferToBase64(await result.arrayBuffer()) as T;\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 // 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 getCustomers(skip = 0, take = 100) {\n return await this.fetch<\n paths['/v1/customers']['get']['responses'][200]['content']['application/json']\n >(`/v1/customers?take=${take}&skip=${skip}`);\n }\n\n async getAllCustomers(\n items: paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data'] = []\n ): Promise<\n paths['/v1/customers']['get']['responses'][200]['content']['application/json']['data']\n > {\n const { data } = (await this.getCustomers(items.length)) || { data: [] };\n\n return data.length\n ? this.getAllCustomers([...items, ...data])\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) {\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 >(`/v2/subscriptions/${id}?include_live_billing=true`);\n }\n\n async getSubscriptions(\n skip = 0,\n take = 100,\n query: operations['getSubscriptions']['parameters']['query'] = {\n status: 'all',\n }\n ) {\n return await this.fetch<\n paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']\n >(\n `/v2/subscriptions?take=${take}&skip=${skip}${Object.entries(query)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => `&${key}=${value}`)\n .join('')}`\n );\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['/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 return await this.fetch<\n paths['/v1/invoices']['get']['responses'][200]['content']['application/json']\n >(\n `/v1/invoices?take=${take}&skip=${skip}&${Object.entries(query)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => `&${key}=${value}`)\n .join('')}`\n );\n }\n\n async getInvoicesByCustomerId(id: string) {\n return await this.fetch<\n paths['/v1/invoices']['get']['responses'][200]['content']['application/json']\n >(`/v1/invoices?customerId__equals=${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['/v1/invoices']['get']['responses'][200]['content']['application/json']['data'] = []\n ): Promise<\n paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data']\n > {\n const { data } = (await this.getInvoices(items.length)) || { data: [] };\n\n return data.length\n ? this.getAllInvoices([...items, ...data])\n : [...items, ...data];\n }\n\n // OTHERS\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: {\n customer_id: string;\n }) {\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\nexport function useHyperline(\n env: {\n PRODUCTION_HYPERLINE_API_KEY: string;\n DEV_HYPERLINE_API_KEY: string;\n },\n environment: 'production' | 'development',\n logger?: Logger\n) {\n const isProduction = environment === 'production';\n\n const token = isProduction\n ? env.PRODUCTION_HYPERLINE_API_KEY\n : env.DEV_HYPERLINE_API_KEY;\n\n const hyperline = useHyperlineByToken(token, logger);\n\n return { hyperline, token, isProduction };\n}\n\nexport function useHyperlineByToken(token: string, logger: Logger = console) {\n return new HyperlineAPI(token, logger);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC","sourcesContent":["export * from './const';\nexport * from './types';\nexport * from './client';\nexport * from './hooks';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/_types.generated.ts","../../src/const.ts","../../src/index.ts"],"version":"5.7.3"}
|
|
1
|
+
{"root":["../../src/_types.generated.ts","../../src/client.ts","../../src/const.ts","../../src/hooks.ts","../../src/index.ts","../../src/types.ts","../../src/utils.ts"],"version":"5.7.3"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { components, paths } from './_types.generated';
|
|
2
|
+
import { WEBHOOKS } from './const';
|
|
3
|
+
export type HyperlineEntities = components['schemas'];
|
|
4
|
+
export type HyperlineEndpoints = paths;
|
|
5
|
+
export type HyperlineWebhook = keyof typeof WEBHOOKS;
|
|
6
|
+
export type HyperlineEvent<T extends HyperlineWebhook> = (typeof WEBHOOKS)[T];
|
|
7
|
+
export type HyperlinePayload<T extends HyperlineWebhook> = {
|
|
8
|
+
event_type: T;
|
|
9
|
+
data: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
export type BillableEvent = {
|
|
12
|
+
record: {
|
|
13
|
+
id: '202408_cus_w_Q7M9bXcHMKB6';
|
|
14
|
+
amount: 26;
|
|
15
|
+
};
|
|
16
|
+
timestamp: '2024-08-07T07:35:20.307Z';
|
|
17
|
+
event_type: 'api_call';
|
|
18
|
+
customer_id: 'cus_w_Q7M9bXcHMKB6';
|
|
19
|
+
};
|
|
20
|
+
export type BillableEvents = {
|
|
21
|
+
events_created: BillableEvent[];
|
|
22
|
+
};
|
|
23
|
+
export type CreateBillableEvent = {
|
|
24
|
+
customer_id: string;
|
|
25
|
+
event_type: 'api_call';
|
|
26
|
+
timestamp: string;
|
|
27
|
+
record: {
|
|
28
|
+
id?: string;
|
|
29
|
+
durationInMs?: number;
|
|
30
|
+
isVerified?: true;
|
|
31
|
+
amount?: number;
|
|
32
|
+
amountGl?: number;
|
|
33
|
+
amountNonGl?: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function arrayBufferToBase64(arrayBuffer: ArrayBuffer): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"src/","sources":["utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,WAAwB;IAC1D,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,UAAiB,CAAC,CAAC;IACxE,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["export function arrayBufferToBase64(arrayBuffer: ArrayBuffer) {\n const uint8Array = new Uint8Array(arrayBuffer);\n const binaryString = String.fromCharCode.apply(null, uint8Array as any);\n return btoa(binaryString);\n}\n"]}
|