@vrplatform/hyperline-client 1.0.21 → 1.0.25
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 +217 -2
- package/build/main/client.js +87 -16
- package/build/main/client.js.map +1 -1
- package/build/main/const.d.ts +24 -0
- package/build/main/const.js +24 -0
- package/build/main/const.js.map +1 -1
- package/build/main/types.d.ts +43 -0
- package/build/main/types.js.map +1 -1
- package/build/main/utils/arrayBufferToBase64.js +5 -2
- package/build/main/utils/arrayBufferToBase64.js.map +1 -1
- package/build/main/utils/getMrrDiffReasons.js +7 -1
- package/build/main/utils/getMrrDiffReasons.js.map +1 -1
- package/build/module/client.d.ts +217 -2
- package/build/module/client.js +87 -16
- package/build/module/client.js.map +1 -1
- package/build/module/const.d.ts +24 -0
- package/build/module/const.js +24 -0
- package/build/module/const.js.map +1 -1
- package/build/module/types.d.ts +43 -0
- package/build/module/types.js.map +1 -1
- package/build/module/utils/arrayBufferToBase64.js +5 -2
- package/build/module/utils/arrayBufferToBase64.js.map +1 -1
- package/build/module/utils/getMrrDiffReasons.js +7 -1
- package/build/module/utils/getMrrDiffReasons.js.map +1 -1
- package/package.json +6 -4
- package/src/client.ts +123 -28
- package/src/const.ts +35 -0
- package/src/types.ts +55 -0
- package/src/utils/arrayBufferToBase64.ts +9 -2
- package/src/utils/getMrrDiffReasons.ts +22 -18
- package/build/main/tsconfig.main.tsbuildinfo +0 -1
- package/build/module/tsconfig.esm.tsbuildinfo +0 -1
package/build/module/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { operations, paths } from './_types.generated';
|
|
2
|
-
import { BillableEvents, CreateBillableEvent } from './types';
|
|
2
|
+
import { BillableEvents, CreateBillableEvent, HyperlineCreateSubscriptionPayload } from './types';
|
|
3
3
|
export type Logger = {
|
|
4
4
|
error(message?: any, ...optionalParams: any[]): void;
|
|
5
5
|
};
|
|
@@ -10,6 +10,91 @@ export declare class HyperlineAPI {
|
|
|
10
10
|
private fetchBasic;
|
|
11
11
|
private fetch;
|
|
12
12
|
private fetchIngest;
|
|
13
|
+
getInvoicingEntities(): Promise<{
|
|
14
|
+
meta: {
|
|
15
|
+
total: number;
|
|
16
|
+
taken: number;
|
|
17
|
+
skipped: number;
|
|
18
|
+
};
|
|
19
|
+
data: {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
trade_name?: string;
|
|
23
|
+
timezone: string;
|
|
24
|
+
language: "fr" | "en" | "de" | "it" | "nl" | "es" | "pt" | "pl";
|
|
25
|
+
is_default: boolean;
|
|
26
|
+
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
27
|
+
accounting_currency: string;
|
|
28
|
+
address_line1: string | null;
|
|
29
|
+
address_line2: string | null;
|
|
30
|
+
zip_code: string | null;
|
|
31
|
+
state: string | null;
|
|
32
|
+
city: string | null;
|
|
33
|
+
country: "AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AO" | "AQ" | "AR" | "AS" | "AT" | "AU" | "AW" | "AX" | "AZ" | "BA" | "BB" | "BD" | "BE" | "BF" | "BG" | "BH" | "BI" | "BJ" | "BL" | "BM" | "BN" | "BO" | "BQ" | "BR" | "BS" | "BT" | "BV" | "BW" | "BY" | "BZ" | "CA" | "CC" | "CD" | "CF" | "CG" | "CH" | "CI" | "CK" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CV" | "CW" | "CX" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "DO" | "DZ" | "EC" | "EE" | "EG" | "EH" | "ER" | "ES" | "ET" | "FI" | "FJ" | "FK" | "FM" | "FO" | "FR" | "GA" | "GB" | "GD" | "GE" | "GF" | "GG" | "GH" | "GI" | "GL" | "GM" | "GN" | "GP" | "GQ" | "GR" | "GS" | "GT" | "GU" | "GW" | "GY" | "HK" | "HM" | "HN" | "HR" | "HT" | "HU" | "IC" | "ID" | "IE" | "IL" | "IM" | "IN" | "IO" | "IQ" | "IR" | "IS" | "IT" | "JE" | "JM" | "JO" | "JP" | "KE" | "KG" | "KH" | "KI" | "KM" | "KN" | "KP" | "KR" | "KW" | "KY" | "KZ" | "LA" | "LB" | "LC" | "LI" | "LK" | "LR" | "LS" | "LT" | "LU" | "LV" | "LY" | "MA" | "MC" | "MD" | "ME" | "MF" | "MG" | "MH" | "MK" | "ML" | "MM" | "MN" | "MO" | "MP" | "MQ" | "MR" | "MS" | "MT" | "MU" | "MV" | "MW" | "MX" | "MY" | "MZ" | "NA" | "NC" | "NE" | "NF" | "NG" | "NI" | "NL" | "NO" | "NP" | "NR" | "NU" | "NZ" | "OM" | "PA" | "PE" | "PF" | "PG" | "PH" | "PK" | "PL" | "PM" | "PN" | "PR" | "PS" | "PT" | "PT-20" | "PT-30" | "PW" | "PY" | "QA" | "RE" | "RO" | "RS" | "RU" | "RW" | "SA" | "SB" | "SC" | "SD" | "SE" | "SG" | "SH" | "SI" | "SJ" | "SK" | "SL" | "SM" | "SN" | "SO" | "SR" | "SS" | "ST" | "SV" | "SX" | "SY" | "SZ" | "TC" | "TD" | "TF" | "TG" | "TH" | "TJ" | "TK" | "TL" | "TM" | "TN" | "TO" | "TR" | "TT" | "TV" | "TW" | "TZ" | "UA" | "UG" | "UM" | "US" | "UY" | "UZ" | "VA" | "VC" | "VE" | "VG" | "VI" | "VN" | "VU" | "WF" | "WS" | "XK" | "YE" | "YT" | "ZA" | "ZM" | "ZW";
|
|
34
|
+
tax_id: string | null;
|
|
35
|
+
tax_id_valid?: boolean;
|
|
36
|
+
billing_email: string | null;
|
|
37
|
+
invoice_number_pattern: string;
|
|
38
|
+
credit_note_number_pattern: string;
|
|
39
|
+
document_number_pattern: string;
|
|
40
|
+
next_invoice_number: number;
|
|
41
|
+
next_credit_note_number: number;
|
|
42
|
+
next_document_number: number;
|
|
43
|
+
default_payment_delay: number;
|
|
44
|
+
invoice_grace_period_duration: number;
|
|
45
|
+
invoice_payment_initiation_delay: number | null;
|
|
46
|
+
document_payment_initiation_delay: number | null;
|
|
47
|
+
invoice_late_fees: string | null;
|
|
48
|
+
invoice_footer: string | null;
|
|
49
|
+
document_footer: string | null;
|
|
50
|
+
logo_url: string | null;
|
|
51
|
+
favicon_url: string | null;
|
|
52
|
+
brand_color: string | null;
|
|
53
|
+
forced_customer_type: "corporate" | "person" | null;
|
|
54
|
+
created_at: string;
|
|
55
|
+
updated_at: string;
|
|
56
|
+
deleted_at: string | null;
|
|
57
|
+
}[];
|
|
58
|
+
} | null>;
|
|
59
|
+
getInvoicingEntity(id?: string): Promise<{
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
trade_name?: string;
|
|
63
|
+
timezone: string;
|
|
64
|
+
language: "fr" | "en" | "de" | "it" | "nl" | "es" | "pt" | "pl";
|
|
65
|
+
is_default: boolean;
|
|
66
|
+
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
67
|
+
accounting_currency: string;
|
|
68
|
+
address_line1: string | null;
|
|
69
|
+
address_line2: string | null;
|
|
70
|
+
zip_code: string | null;
|
|
71
|
+
state: string | null;
|
|
72
|
+
city: string | null;
|
|
73
|
+
country: "AD" | "AE" | "AF" | "AG" | "AI" | "AL" | "AM" | "AO" | "AQ" | "AR" | "AS" | "AT" | "AU" | "AW" | "AX" | "AZ" | "BA" | "BB" | "BD" | "BE" | "BF" | "BG" | "BH" | "BI" | "BJ" | "BL" | "BM" | "BN" | "BO" | "BQ" | "BR" | "BS" | "BT" | "BV" | "BW" | "BY" | "BZ" | "CA" | "CC" | "CD" | "CF" | "CG" | "CH" | "CI" | "CK" | "CL" | "CM" | "CN" | "CO" | "CR" | "CU" | "CV" | "CW" | "CX" | "CY" | "CZ" | "DE" | "DJ" | "DK" | "DM" | "DO" | "DZ" | "EC" | "EE" | "EG" | "EH" | "ER" | "ES" | "ET" | "FI" | "FJ" | "FK" | "FM" | "FO" | "FR" | "GA" | "GB" | "GD" | "GE" | "GF" | "GG" | "GH" | "GI" | "GL" | "GM" | "GN" | "GP" | "GQ" | "GR" | "GS" | "GT" | "GU" | "GW" | "GY" | "HK" | "HM" | "HN" | "HR" | "HT" | "HU" | "IC" | "ID" | "IE" | "IL" | "IM" | "IN" | "IO" | "IQ" | "IR" | "IS" | "IT" | "JE" | "JM" | "JO" | "JP" | "KE" | "KG" | "KH" | "KI" | "KM" | "KN" | "KP" | "KR" | "KW" | "KY" | "KZ" | "LA" | "LB" | "LC" | "LI" | "LK" | "LR" | "LS" | "LT" | "LU" | "LV" | "LY" | "MA" | "MC" | "MD" | "ME" | "MF" | "MG" | "MH" | "MK" | "ML" | "MM" | "MN" | "MO" | "MP" | "MQ" | "MR" | "MS" | "MT" | "MU" | "MV" | "MW" | "MX" | "MY" | "MZ" | "NA" | "NC" | "NE" | "NF" | "NG" | "NI" | "NL" | "NO" | "NP" | "NR" | "NU" | "NZ" | "OM" | "PA" | "PE" | "PF" | "PG" | "PH" | "PK" | "PL" | "PM" | "PN" | "PR" | "PS" | "PT" | "PT-20" | "PT-30" | "PW" | "PY" | "QA" | "RE" | "RO" | "RS" | "RU" | "RW" | "SA" | "SB" | "SC" | "SD" | "SE" | "SG" | "SH" | "SI" | "SJ" | "SK" | "SL" | "SM" | "SN" | "SO" | "SR" | "SS" | "ST" | "SV" | "SX" | "SY" | "SZ" | "TC" | "TD" | "TF" | "TG" | "TH" | "TJ" | "TK" | "TL" | "TM" | "TN" | "TO" | "TR" | "TT" | "TV" | "TW" | "TZ" | "UA" | "UG" | "UM" | "US" | "UY" | "UZ" | "VA" | "VC" | "VE" | "VG" | "VI" | "VN" | "VU" | "WF" | "WS" | "XK" | "YE" | "YT" | "ZA" | "ZM" | "ZW";
|
|
74
|
+
tax_id: string | null;
|
|
75
|
+
tax_id_valid?: boolean;
|
|
76
|
+
billing_email: string | null;
|
|
77
|
+
invoice_number_pattern: string;
|
|
78
|
+
credit_note_number_pattern: string;
|
|
79
|
+
document_number_pattern: string;
|
|
80
|
+
next_invoice_number: number;
|
|
81
|
+
next_credit_note_number: number;
|
|
82
|
+
next_document_number: number;
|
|
83
|
+
default_payment_delay: number;
|
|
84
|
+
invoice_grace_period_duration: number;
|
|
85
|
+
invoice_payment_initiation_delay: number | null;
|
|
86
|
+
document_payment_initiation_delay: number | null;
|
|
87
|
+
invoice_late_fees: string | null;
|
|
88
|
+
invoice_footer: string | null;
|
|
89
|
+
document_footer: string | null;
|
|
90
|
+
logo_url: string | null;
|
|
91
|
+
favicon_url: string | null;
|
|
92
|
+
brand_color: string | null;
|
|
93
|
+
forced_customer_type: "corporate" | "person" | null;
|
|
94
|
+
created_at: string;
|
|
95
|
+
updated_at: string;
|
|
96
|
+
deleted_at: string | null;
|
|
97
|
+
} | null>;
|
|
13
98
|
getCustomer(id?: string): Promise<({
|
|
14
99
|
id: string;
|
|
15
100
|
name: string;
|
|
@@ -581,7 +666,7 @@ export declare class HyperlineAPI {
|
|
|
581
666
|
data: import("./_types.generated").components["schemas"]["Subscription"][];
|
|
582
667
|
} | null>;
|
|
583
668
|
getAllSubscriptions(items?: paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data'], query?: operations['getSubscriptions']['parameters']['query']): Promise<paths['/v2/subscriptions']['get']['responses'][200]['content']['application/json']['data']>;
|
|
584
|
-
createSubscription(data:
|
|
669
|
+
createSubscription(data: HyperlineCreateSubscriptionPayload): Promise<({
|
|
585
670
|
id: string;
|
|
586
671
|
name: string | null;
|
|
587
672
|
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
@@ -1397,6 +1482,136 @@ export declare class HyperlineAPI {
|
|
|
1397
1482
|
} | null>;
|
|
1398
1483
|
getInvoiceDownload(id: string): Promise<string | null>;
|
|
1399
1484
|
getAllInvoices(items?: paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data'], query?: operations['getInvoices']['parameters']['query']): Promise<paths['/v1/invoices']['get']['responses'][200]['content']['application/json']['data']>;
|
|
1485
|
+
voidInvoice(id: string, data?: NonNullable<paths['/v1/invoices/{id}/void']['post']['requestBody']>['content']['application/json']): Promise<({
|
|
1486
|
+
id: string;
|
|
1487
|
+
number: string;
|
|
1488
|
+
type: "invoice" | "credit_note" | "document" | "child_invoice_ref" | "child_creditnote_ref";
|
|
1489
|
+
document_name: string | null;
|
|
1490
|
+
status: "draft" | "open" | "to_pay" | "grace_period" | "partially_paid" | "paid" | "voided" | "closed" | "error" | "missing_info" | "archived" | "charged_on_parent" | "pending_parent_concat" | "uncollectible";
|
|
1491
|
+
reference: string | null;
|
|
1492
|
+
purchase_order: string | null;
|
|
1493
|
+
original_invoice_id: string | null;
|
|
1494
|
+
original_invoice_number: string | null;
|
|
1495
|
+
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
1496
|
+
source: "hyperline" | "api" | "pennylane" | "chargebee" | "stripe" | "lago" | "sequence" | "other";
|
|
1497
|
+
total_amount: number;
|
|
1498
|
+
amount_due: number;
|
|
1499
|
+
amount_paid: number;
|
|
1500
|
+
amount_fixed: number;
|
|
1501
|
+
amount_excluding_tax: number;
|
|
1502
|
+
tax_rate: number;
|
|
1503
|
+
tax_amount: number;
|
|
1504
|
+
tax_scheme: "exempt" | "standard" | "reverse_charge" | "manual" | "not_eligible";
|
|
1505
|
+
discount_amount: number;
|
|
1506
|
+
conversion_rate: number | null;
|
|
1507
|
+
converted_amount: number | null;
|
|
1508
|
+
converted_at: string | null;
|
|
1509
|
+
payment_method_id: string | null;
|
|
1510
|
+
bank_account_id: string | null;
|
|
1511
|
+
custom_note: string | null;
|
|
1512
|
+
additional_info: string | null;
|
|
1513
|
+
footer: string | null;
|
|
1514
|
+
customer: {
|
|
1515
|
+
id: string;
|
|
1516
|
+
name: string;
|
|
1517
|
+
email: string | null;
|
|
1518
|
+
external_id: string | null;
|
|
1519
|
+
vat_number: string | null;
|
|
1520
|
+
address: import("./_types.generated").components["schemas"]["Address"];
|
|
1521
|
+
};
|
|
1522
|
+
seller: {
|
|
1523
|
+
id: string;
|
|
1524
|
+
name: string;
|
|
1525
|
+
tax_id: string | null;
|
|
1526
|
+
address: import("./_types.generated").components["schemas"]["Address"];
|
|
1527
|
+
};
|
|
1528
|
+
subscription_id: string | null;
|
|
1529
|
+
period_starts_at: string | null;
|
|
1530
|
+
period_ends_at: string | null;
|
|
1531
|
+
emitted_at: string;
|
|
1532
|
+
due_at: string;
|
|
1533
|
+
refunded_at: string | null;
|
|
1534
|
+
grace_period_ended_at: string | null;
|
|
1535
|
+
settled_at: string | null;
|
|
1536
|
+
updated_at: string | null;
|
|
1537
|
+
properties: {
|
|
1538
|
+
[key: string]: string | number | boolean | null | (string | number | boolean | null)[];
|
|
1539
|
+
} | null;
|
|
1540
|
+
line_items: import("./_types.generated").components["schemas"]["InvoiceLineItem"][];
|
|
1541
|
+
coupons: import("./_types.generated").components["schemas"]["InvoiceCoupon"][];
|
|
1542
|
+
transactions: ({
|
|
1543
|
+
id: string;
|
|
1544
|
+
type: "subscription" | "one_time" | "refund";
|
|
1545
|
+
amount: number;
|
|
1546
|
+
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
1547
|
+
customer_id: string;
|
|
1548
|
+
provider_id: string | null;
|
|
1549
|
+
process_at: string;
|
|
1550
|
+
refunded_at: string | null;
|
|
1551
|
+
last_refreshed_at: string | null;
|
|
1552
|
+
provider_fee: {
|
|
1553
|
+
amount: number;
|
|
1554
|
+
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
1555
|
+
exchange_rate: number | null;
|
|
1556
|
+
} | null;
|
|
1557
|
+
chargeback: {
|
|
1558
|
+
amount: number;
|
|
1559
|
+
last_chargeback_at: string;
|
|
1560
|
+
} | null;
|
|
1561
|
+
} & ({
|
|
1562
|
+
payment_method_type: "card" | "direct_debit" | "direct_debit_ach" | "direct_debit_bacs";
|
|
1563
|
+
payment_method: import("./_types.generated").components["schemas"]["PaymentMethod"];
|
|
1564
|
+
} | {
|
|
1565
|
+
payment_method_type: "transfer" | "transfer_automated";
|
|
1566
|
+
bank_account: import("./_types.generated").components["schemas"]["BankAccount"] & (({
|
|
1567
|
+
id: string;
|
|
1568
|
+
currency: "EUR" | "AED" | "AFN" | "XCD" | "ALL" | "AMD" | "AOA" | "ARS" | "USD" | "AUD" | "AWG" | "AZN" | "BAM" | "BBD" | "BDT" | "XOF" | "BGN" | "BHD" | "BIF" | "BMD" | "BND" | "BOB" | "BRL" | "BSD" | "BTN" | "NOK" | "BWP" | "BYR" | "BZD" | "CAD" | "CDF" | "XAF" | "CHF" | "NZD" | "CLP" | "CNY" | "COP" | "CRC" | "CUP" | "CVE" | "ANG" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EGP" | "MAD" | "ERN" | "ETB" | "FJD" | "FKP" | "GBP" | "GEL" | "GHS" | "GIP" | "GMD" | "GNF" | "GTQ" | "GYD" | "HKD" | "HNL" | "HRK" | "HTG" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KGS" | "KHR" | "KMF" | "KPW" | "KRW" | "KWD" | "KYD" | "KZT" | "LAK" | "LBP" | "LKR" | "LRD" | "LSL" | "LYD" | "MDL" | "MGA" | "MKD" | "MMK" | "MNT" | "MOP" | "MRO" | "MUR" | "MVR" | "MWK" | "MXN" | "MYR" | "MZN" | "NAD" | "XPF" | "NGN" | "NIO" | "NPR" | "OMR" | "PAB" | "PEN" | "PGK" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SBD" | "SCR" | "SDG" | "SEK" | "SGD" | "SHP" | "SLL" | "SOS" | "SRD" | "SSP" | "STD" | "SYP" | "SZL" | "THB" | "TJS" | "TMT" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "VUV" | "WST" | "YER" | "ZAR" | "ZMW" | "ZWL";
|
|
1569
|
+
bank_name: string | null;
|
|
1570
|
+
} & ({
|
|
1571
|
+
format: "iban_bic_swift";
|
|
1572
|
+
iban: string;
|
|
1573
|
+
bic_swift: string | null;
|
|
1574
|
+
} | {
|
|
1575
|
+
format: "sort_code_account_number";
|
|
1576
|
+
sort_code: string;
|
|
1577
|
+
account_number: string;
|
|
1578
|
+
} | {
|
|
1579
|
+
format: "account_number_routing_number";
|
|
1580
|
+
account_number: string;
|
|
1581
|
+
routing_number: string;
|
|
1582
|
+
} | {
|
|
1583
|
+
format: "account_number_bic_swift";
|
|
1584
|
+
account_number: string;
|
|
1585
|
+
bic_swift: string;
|
|
1586
|
+
})) | null);
|
|
1587
|
+
} | {
|
|
1588
|
+
payment_method_type: "wallet";
|
|
1589
|
+
wallet_id: string;
|
|
1590
|
+
} | {
|
|
1591
|
+
payment_method_type: "external";
|
|
1592
|
+
}) & ({
|
|
1593
|
+
status: "scheduled" | "to_process" | "pending" | "settled" | "cancelled";
|
|
1594
|
+
} | {
|
|
1595
|
+
status: "failed";
|
|
1596
|
+
error_type: "authentication_required" | "declined" | "fraud" | "insufficient_funds" | "payment_method_authorization_error" | "payment_method_declined" | "payment_method_expired" | "payment_method_invalid" | "payment_method_not_supported" | "processing_error" | "provider_error" | "unknown" | null;
|
|
1597
|
+
error_message: string | null;
|
|
1598
|
+
}))[];
|
|
1599
|
+
} & {
|
|
1600
|
+
integrations: {
|
|
1601
|
+
entity_id: string;
|
|
1602
|
+
provider_name: "stripe" | "mollie" | "gocardless" | "airwallex" | "salesforce" | "hubspot" | "attio" | "xero" | "pennylane" | "exact-online" | "quickbooks" | "netsuite" | "anrok";
|
|
1603
|
+
provider_account_id: string;
|
|
1604
|
+
}[];
|
|
1605
|
+
}) | null>;
|
|
1606
|
+
deleteInvoice(id: string): Promise<null | undefined>;
|
|
1607
|
+
getCustomerPaymentMethods(customerId: string): Promise<{
|
|
1608
|
+
meta: {
|
|
1609
|
+
total: number;
|
|
1610
|
+
taken: number;
|
|
1611
|
+
skipped: number;
|
|
1612
|
+
};
|
|
1613
|
+
data: (import("./_types.generated").components["schemas"]["PaymentMethod"] & (import("./_types.generated").components["schemas"]["PaymentMethodCard"] | import("./_types.generated").components["schemas"]["PaymentMethodDirectDebit"] | import("./_types.generated").components["schemas"]["PaymentMethodStripeLink"]))[];
|
|
1614
|
+
} | null>;
|
|
1400
1615
|
getPaymentMethod(customerId: string, paymentMethodId: string): Promise<({
|
|
1401
1616
|
id: string;
|
|
1402
1617
|
} & {
|
package/build/module/client.js
CHANGED
|
@@ -13,6 +13,7 @@ export class HyperlineAPI {
|
|
|
13
13
|
async fetchBasic(path, options, data) {
|
|
14
14
|
if (data)
|
|
15
15
|
options = { body: JSON.stringify(data), ...(options || {}) };
|
|
16
|
+
const method = (options?.method || 'GET').toUpperCase();
|
|
16
17
|
const sandbox = this.headers.Authorization.includes('test')
|
|
17
18
|
? 'sandbox.'
|
|
18
19
|
: '';
|
|
@@ -21,9 +22,31 @@ export class HyperlineAPI {
|
|
|
21
22
|
...options,
|
|
22
23
|
headers: { ...this.headers, ...options?.headers },
|
|
23
24
|
});
|
|
24
|
-
if (!result
|
|
25
|
+
if (!result?.ok) {
|
|
25
26
|
const status = result?.status;
|
|
26
27
|
const statusText = result?.statusText;
|
|
28
|
+
let content = null;
|
|
29
|
+
try {
|
|
30
|
+
const rawBody = await result.text();
|
|
31
|
+
const trimmedBody = rawBody.trim();
|
|
32
|
+
if (trimmedBody) {
|
|
33
|
+
try {
|
|
34
|
+
content = JSON.parse(trimmedBody);
|
|
35
|
+
}
|
|
36
|
+
catch (_) {
|
|
37
|
+
content = rawBody;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (_) {
|
|
42
|
+
// ignore
|
|
43
|
+
}
|
|
44
|
+
const message = (content && typeof content === 'object' && 'message' in content
|
|
45
|
+
? content.message
|
|
46
|
+
: null) ||
|
|
47
|
+
(typeof content === 'string' ? content : null) ||
|
|
48
|
+
(content ? JSON.stringify(content) : null) ||
|
|
49
|
+
'Unknown error';
|
|
27
50
|
if (status === 429) {
|
|
28
51
|
// get difference between rate limit reset and now
|
|
29
52
|
const rateLimitReset = utc(result?.headers.get('x-ratelimit-reset'));
|
|
@@ -32,16 +55,17 @@ export class HyperlineAPI {
|
|
|
32
55
|
await new Promise((resolve) => setTimeout(resolve, diff));
|
|
33
56
|
return await this.fetchBasic(path, options, data);
|
|
34
57
|
}
|
|
35
|
-
else if (status === 404) {
|
|
58
|
+
else if (status === 404 && method === 'GET') {
|
|
36
59
|
return null;
|
|
37
60
|
}
|
|
38
61
|
else {
|
|
39
|
-
|
|
40
|
-
throw new Error(`Hyperline Error ${status} (${statusText}) in ${path} for ${options?.method || 'GET'}: ${content.message}`);
|
|
62
|
+
throw new Error(`Hyperline Error ${status} (${statusText}) in ${path} for ${method}: ${message}`);
|
|
41
63
|
}
|
|
42
64
|
}
|
|
43
65
|
else if (result.headers.get('content-type')?.includes('application/pdf'))
|
|
44
66
|
return arrayBufferToBase64(await result.arrayBuffer());
|
|
67
|
+
if (result.status === 204)
|
|
68
|
+
return null;
|
|
45
69
|
return (await result.json());
|
|
46
70
|
}
|
|
47
71
|
async fetch(path, options, data) {
|
|
@@ -50,6 +74,17 @@ export class HyperlineAPI {
|
|
|
50
74
|
async fetchIngest(path, options, data) {
|
|
51
75
|
return await this.fetchBasic(`ingest.hyperline.co${path}`, options, data);
|
|
52
76
|
}
|
|
77
|
+
// INVOICING ENTITY
|
|
78
|
+
async getInvoicingEntities() {
|
|
79
|
+
return await this.fetch('/v1/invoicing-entities');
|
|
80
|
+
}
|
|
81
|
+
async getInvoicingEntity(id) {
|
|
82
|
+
if (!id) {
|
|
83
|
+
this.logger.error('Missing invoicing entity ID', { id });
|
|
84
|
+
throw new Error('Missing invoicing entity ID');
|
|
85
|
+
}
|
|
86
|
+
return await this.fetch(`/v1/invoicing-entities/${id}`);
|
|
87
|
+
}
|
|
53
88
|
// CUSTOMER
|
|
54
89
|
async getCustomer(id) {
|
|
55
90
|
if (!id) {
|
|
@@ -67,10 +102,15 @@ export class HyperlineAPI {
|
|
|
67
102
|
return results?.data[0];
|
|
68
103
|
}
|
|
69
104
|
async getCustomers(skip = 0, take = 100, query = {}) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
105
|
+
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)) {
|
|
109
|
+
if (value === undefined || value === null)
|
|
110
|
+
continue;
|
|
111
|
+
queryParams.set(key, value.toString());
|
|
112
|
+
}
|
|
113
|
+
return await this.fetch(`/v1/customers?${queryParams.toString()}`);
|
|
74
114
|
}
|
|
75
115
|
async getAllCustomers(items = [], query = {}) {
|
|
76
116
|
const { data } = (await this.getCustomers(items.length, 100, {
|
|
@@ -124,10 +164,15 @@ export class HyperlineAPI {
|
|
|
124
164
|
async getSubscriptions(skip = 0, take = 100, query = {
|
|
125
165
|
status: 'all',
|
|
126
166
|
}) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
167
|
+
const queryParams = new URLSearchParams();
|
|
168
|
+
queryParams.set('take', take.toString());
|
|
169
|
+
queryParams.set('skip', skip.toString());
|
|
170
|
+
for (const [key, value] of Object.entries(query)) {
|
|
171
|
+
if (value === undefined || value === null)
|
|
172
|
+
continue;
|
|
173
|
+
queryParams.set(key, value.toString());
|
|
174
|
+
}
|
|
175
|
+
return await this.fetch(`/v2/subscriptions?${queryParams.toString()}`);
|
|
131
176
|
}
|
|
132
177
|
async getAllSubscriptions(items = [], query = {}) {
|
|
133
178
|
const { data } = (await this.getSubscriptions(items.length, 100, query)) || { data: [] };
|
|
@@ -174,10 +219,15 @@ export class HyperlineAPI {
|
|
|
174
219
|
return await this.fetch(`/v1/invoices/${id}`);
|
|
175
220
|
}
|
|
176
221
|
async getInvoices(skip = 0, take = 100, query = { status: 'all' }) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
222
|
+
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)) {
|
|
226
|
+
if (value === undefined || value === null)
|
|
227
|
+
continue;
|
|
228
|
+
queryParams.set(key, value.toString());
|
|
229
|
+
}
|
|
230
|
+
return await this.fetch(`/v1/invoices?${queryParams.toString()}`);
|
|
181
231
|
}
|
|
182
232
|
async getInvoicesByCustomerId(id, filters) {
|
|
183
233
|
const queryParams = new URLSearchParams();
|
|
@@ -209,7 +259,28 @@ export class HyperlineAPI {
|
|
|
209
259
|
? this.getAllInvoices([...items, ...data], { status: 'all', ...query })
|
|
210
260
|
: [...items, ...data];
|
|
211
261
|
}
|
|
262
|
+
async voidInvoice(id, data = { send_email: false }) {
|
|
263
|
+
if (!id) {
|
|
264
|
+
this.logger.error('Missing invoice ID', { id });
|
|
265
|
+
throw new Error('Missing invoice ID');
|
|
266
|
+
}
|
|
267
|
+
return await this.fetch(`/v1/invoices/${id}/void`, { method: 'POST' }, data);
|
|
268
|
+
}
|
|
269
|
+
async deleteInvoice(id) {
|
|
270
|
+
if (!id) {
|
|
271
|
+
this.logger.error('Missing invoice ID', { id });
|
|
272
|
+
throw new Error('Missing invoice ID');
|
|
273
|
+
}
|
|
274
|
+
return await this.fetch(`/v1/invoices/${id}`, { method: 'DELETE' });
|
|
275
|
+
}
|
|
212
276
|
// OTHERS
|
|
277
|
+
async getCustomerPaymentMethods(customerId) {
|
|
278
|
+
if (!customerId) {
|
|
279
|
+
this.logger.error('Missing customer ID', { customerId });
|
|
280
|
+
throw new Error('Missing customer ID');
|
|
281
|
+
}
|
|
282
|
+
return await this.fetch(`/v1/customers/${customerId}/payment-methods`);
|
|
283
|
+
}
|
|
213
284
|
async getPaymentMethod(customerId, paymentMethodId) {
|
|
214
285
|
return await this.fetch(`/v1/customers/${customerId}/payment-methods/${paymentMethodId}`);
|
|
215
286
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"src/","sources":["client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGxC,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,CAAS;IAEf,KAAK,CAAC,UAAU,CACtB,IAAY,EACZ,OAAqB,EACrB,IAA0B;QAE1B,IAAI,IAAI;YAAE,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QAEvE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC;YACzD,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,WAAW,OAAO,GAAG,IAAI,EAAE,EAAE;YACtD,MAAM,EAAE,KAAK;YACb,GAAG,OAAO;YACV,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,O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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 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 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 return await this.fetch<\n paths['/v1/customers']['get']['responses'][200]['content']['application/json']\n >(\n `/v1/customers?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 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 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['/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 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(\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 // OTHERS\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":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAOxC,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,CAAS;IAEf,KAAK,CAAC,UAAU,CACtB,IAAY,EACZ,OAAqB,EACrB,IAA0B;QAE1B,IAAI,IAAI;YAAE,OAAO,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;QAEvE,MA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oB,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,KAAK,CAErB,gBAAgB,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,SAAS;IAET,KAAK,CAAC,yBAAyB,CAAC,UAAkB;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 { utc } from '@vrplatform/utils';\nimport type { operations, paths } from './_types.generated';\nimport {\n BillableEvents,\n CreateBillableEvent,\n HyperlineCreateSubscriptionPayload,\n} 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(data: HyperlineCreateSubscriptionPayload) {\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"]}
|