lago-javascript-client 0.20.0-beta → 0.22.0-beta

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Lago
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Lago JavaScript Client
2
+
3
+ This is a JavaScript wrapper for Lago API. Works in Cloudflare Workers, Deno, and Node.js. Generated from [the Lago Swagger document](https://swagger.getlago.com/#/).
4
+
5
+ [![PyPI version](https://badge.fury.io/js/lago-javascript-client.svg)](https://badge.fury.io/js/lago-javascript-client)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://spdx.org/licenses/MIT.html)
7
+
8
+ ## Installation
9
+
10
+ For npm users:
11
+
12
+ ```bash
13
+ npm install lago-javascript-client
14
+ ```
15
+
16
+ ```typescript
17
+ // npm
18
+ import { Client, getLagoError } from 'lago-javascript-client';
19
+
20
+ // Deno
21
+ import { Client, getLagoError } from 'https://deno.land/x/lago/mod.ts';
22
+
23
+ const lagoClient = Client('__YOUR_API_KEY__');
24
+
25
+ try {
26
+ const { data } = await lagoClient.billableMetrics.createBillableMetric(billableMetric);
27
+ } catch (error) {
28
+ const lagoError = await getLagoError<typeof lagoClient.billableMetrics.createBillableMetric>(error);
29
+ }
30
+ ```
31
+
32
+ ## Compatibility
33
+
34
+ This SDK uses the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and natively supported Node.js version >= 18. For other Node versions:
35
+
36
+ 1. Ideally, run Node with the [`--experimental-fetch` flag](https://nodejs.org/docs/latest-v16.x/api/cli.html#--experimental-fetch)
37
+
38
+ 1. Otherwise, polyfill the Fetch API by doing both:
39
+
40
+ 1. [Patching globalThis](https://github.com/node-fetch/node-fetch#providing-global-access)
41
+
42
+ 1. [Pass a Fetch instance](https://github.com/node-fetch/node-fetch#loading-and-configuring-the-module) to the Lago client
43
+
44
+ ```typescript
45
+ import { Client } from 'lago-javascript-client';
46
+ import fetch from 'node-fetch';
47
+
48
+ const lagoClient = Client("api_key", { customFetch: fetch });
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ Check the [Lago API reference](https://doc.getlago.com/docs/api/intro)
54
+
55
+ ### Error handling
56
+
57
+ Use the get `getLagoError<>()` utility function to extract the error object and TypeScript type:
58
+
59
+ ```typescript
60
+ try {
61
+ const { data } = await lagoClient.billableMetrics.createBillableMetric(billableMetric);
62
+ } catch (error) {
63
+ const lagoError = await getLagoError<typeof lagoClient.billableMetrics.createBillableMetric>(error);
64
+ }
65
+ ```
66
+
67
+ ## Development
68
+
69
+ Uses [dnt](https://github.com/denoland/dnt) to build and test for Deno and Node.
70
+
71
+ ### Release new version
72
+
73
+ Change the affected fields in `scripts/build_npm.ts` and commit to GitHub. GitHub Actions will build and deploy to npm.
74
+
75
+ ### Dependencies
76
+
77
+ Requires [Deno](https://deno.land/) and [Node.js >= 18](https://nodejs.org/en/)
78
+
79
+ ### Generate client from Swagger
80
+
81
+ ```bash
82
+ deno task generate:swagger
83
+ ```
84
+
85
+ ### Run tests
86
+
87
+ ```bash
88
+ deno task test
89
+ ```
90
+
91
+ ### Build
92
+
93
+ ```bash
94
+ deno task build
95
+ ```
96
+
97
+ ### Publish to npm
98
+
99
+ ```bash
100
+ deno task build
101
+ cd npm
102
+ npm publish
103
+ ```
104
+
105
+ ## Documentation
106
+
107
+ The Lago documentation is available at [doc.getlago.com](https://doc.getlago.com/docs/api/intro).
108
+
109
+ ## Contributing
110
+
111
+ The contribution documentation is available [here](https://github.com/getlago/lago-javascript-client/blob/main/CONTRIBUTING.md)
112
+
113
+ ## License
114
+
115
+ Lago JavaScript client is distributed under [MIT license](LICENSE).
@@ -148,7 +148,7 @@ export class HttpClient {
148
148
  }
149
149
  /**
150
150
  * @title Lago API documentation
151
- * @version 0.0.1
151
+ * @version 0.22.0-beta
152
152
  * @baseUrl https://api.getlago.com/api/v1
153
153
  * @externalDocs https://github.com/getlago
154
154
  * @contact <tech@getlago.com>
@@ -546,6 +546,22 @@ export class Api extends HttpClient {
546
546
  format: "json",
547
547
  ...params,
548
548
  }),
549
+ /**
550
+ * @description Return the deleted customer
551
+ *
552
+ * @tags customers
553
+ * @name DeleteCustomer
554
+ * @summary Delete a customer
555
+ * @request DELETE:/customers/{external_id}
556
+ * @secure
557
+ */
558
+ deleteCustomer: (externalId, params = {}) => this.request({
559
+ path: `/customers/${externalId}`,
560
+ method: "DELETE",
561
+ secure: true,
562
+ format: "json",
563
+ ...params,
564
+ }),
549
565
  /**
550
566
  * @description Return a customer current usage
551
567
  *
@@ -859,6 +875,21 @@ export class Api extends HttpClient {
859
875
  format: "json",
860
876
  ...params,
861
877
  }),
878
+ /**
879
+ * @description Retry invoice payment
880
+ *
881
+ * @tags invoices
882
+ * @name RetryPayment
883
+ * @summary Retry invoice payment
884
+ * @request POST:/invoices/{id}/retry_payment
885
+ * @secure
886
+ */
887
+ retryPayment: (id, params = {}) => this.request({
888
+ path: `/invoices/${id}/retry_payment`,
889
+ method: "POST",
890
+ secure: true,
891
+ ...params,
892
+ }),
862
893
  /**
863
894
  * @description Refresh a draft invoice
864
895
  *
@@ -995,6 +1026,23 @@ export class Api extends HttpClient {
995
1026
  format: "json",
996
1027
  ...params,
997
1028
  }),
1029
+ /**
1030
+ * @description Find all wallet transactions for certain wallet
1031
+ *
1032
+ * @tags wallets
1033
+ * @name FindAllWalletTransactions
1034
+ * @summary Find wallet transactions
1035
+ * @request GET:/wallets/{id}/wallet_transactions
1036
+ * @secure
1037
+ */
1038
+ findAllWalletTransactions: (id, query, params = {}) => this.request({
1039
+ path: `/wallets/${id}/wallet_transactions`,
1040
+ method: "GET",
1041
+ query: query,
1042
+ secure: true,
1043
+ format: "json",
1044
+ ...params,
1045
+ }),
998
1046
  };
999
1047
  walletTransactions = {
1000
1048
  /**
package/package.json CHANGED
@@ -3,7 +3,8 @@
3
3
  "main": "./script/mod.js",
4
4
  "types": "./types/mod.d.ts",
5
5
  "name": "lago-javascript-client",
6
- "version": "v0.20.0-beta",
6
+ "sideEffects": false,
7
+ "version": "v0.22.0-beta",
7
8
  "description": "Lago JavaScript API Client",
8
9
  "repository": {
9
10
  "type": "git",
@@ -152,7 +152,7 @@ class HttpClient {
152
152
  exports.HttpClient = HttpClient;
153
153
  /**
154
154
  * @title Lago API documentation
155
- * @version 0.0.1
155
+ * @version 0.22.0-beta
156
156
  * @baseUrl https://api.getlago.com/api/v1
157
157
  * @externalDocs https://github.com/getlago
158
158
  * @contact <tech@getlago.com>
@@ -550,6 +550,22 @@ class Api extends HttpClient {
550
550
  format: "json",
551
551
  ...params,
552
552
  }),
553
+ /**
554
+ * @description Return the deleted customer
555
+ *
556
+ * @tags customers
557
+ * @name DeleteCustomer
558
+ * @summary Delete a customer
559
+ * @request DELETE:/customers/{external_id}
560
+ * @secure
561
+ */
562
+ deleteCustomer: (externalId, params = {}) => this.request({
563
+ path: `/customers/${externalId}`,
564
+ method: "DELETE",
565
+ secure: true,
566
+ format: "json",
567
+ ...params,
568
+ }),
553
569
  /**
554
570
  * @description Return a customer current usage
555
571
  *
@@ -863,6 +879,21 @@ class Api extends HttpClient {
863
879
  format: "json",
864
880
  ...params,
865
881
  }),
882
+ /**
883
+ * @description Retry invoice payment
884
+ *
885
+ * @tags invoices
886
+ * @name RetryPayment
887
+ * @summary Retry invoice payment
888
+ * @request POST:/invoices/{id}/retry_payment
889
+ * @secure
890
+ */
891
+ retryPayment: (id, params = {}) => this.request({
892
+ path: `/invoices/${id}/retry_payment`,
893
+ method: "POST",
894
+ secure: true,
895
+ ...params,
896
+ }),
866
897
  /**
867
898
  * @description Refresh a draft invoice
868
899
  *
@@ -999,6 +1030,23 @@ class Api extends HttpClient {
999
1030
  format: "json",
1000
1031
  ...params,
1001
1032
  }),
1033
+ /**
1034
+ * @description Find all wallet transactions for certain wallet
1035
+ *
1036
+ * @tags wallets
1037
+ * @name FindAllWalletTransactions
1038
+ * @summary Find wallet transactions
1039
+ * @request GET:/wallets/{id}/wallet_transactions
1040
+ * @secure
1041
+ */
1042
+ findAllWalletTransactions: (id, query, params = {}) => this.request({
1043
+ path: `/wallets/${id}/wallet_transactions`,
1044
+ method: "GET",
1045
+ query: query,
1046
+ secure: true,
1047
+ format: "json",
1048
+ ...params,
1049
+ }),
1002
1050
  };
1003
1051
  walletTransactions = {
1004
1052
  /**
@@ -19,6 +19,10 @@ export interface BillableMetricObject {
19
19
  /** Aggregation type */
20
20
  aggregation_type?: "count_agg" | "sum_agg" | "max_agg" | "unique_count_agg" | "recurring_count_agg";
21
21
  group?: BillableMetricGroup;
22
+ /** @example 0 */
23
+ active_subscriptions_count?: number;
24
+ /** @example 0 */
25
+ draft_invoices_count?: number;
22
26
  }
23
27
  export interface BillableMetric {
24
28
  billable_metric?: BillableMetricObject;
@@ -848,6 +852,9 @@ export interface WalletTransactionObject {
848
852
  export interface WalletTransaction {
849
853
  wallet_transaction?: WalletTransactionObject;
850
854
  }
855
+ export interface WalletTransactions {
856
+ wallet_transactions?: WalletTransactionObject[];
857
+ }
851
858
  export interface WalletTransactionInput {
852
859
  wallet_transaction?: {
853
860
  /** @example "985da83c-c007-4fbb-afcd-b00c07c41ffe" */
@@ -1065,7 +1072,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
1065
1072
  }
1066
1073
  /**
1067
1074
  * @title Lago API documentation
1068
- * @version 0.0.1
1075
+ * @version 0.22.0-beta
1069
1076
  * @baseUrl https://api.getlago.com/api/v1
1070
1077
  * @externalDocs https://github.com/getlago
1071
1078
  * @contact <tech@getlago.com>
@@ -1113,7 +1120,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1113
1120
  * @request DELETE:/billable_metrics/{code}
1114
1121
  * @secure
1115
1122
  */
1116
- destroyBillableMetric: (code: string, params?: RequestParams) => Promise<HttpResponse<BillableMetric, ApiResponseUnauthorized | ApiResponseNotFound | ApiResponseNotAllowed>>;
1123
+ destroyBillableMetric: (code: string, params?: RequestParams) => Promise<HttpResponse<BillableMetric, ApiResponseUnauthorized | ApiResponseNotFound>>;
1117
1124
  /**
1118
1125
  * @description Find all billable metrics in certain organisation
1119
1126
  *
@@ -1368,6 +1375,16 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1368
1375
  * @secure
1369
1376
  */
1370
1377
  findCustomer: (externalId: string, params?: RequestParams) => Promise<HttpResponse<Customer, ApiResponseUnauthorized | ApiResponseNotFound>>;
1378
+ /**
1379
+ * @description Return the deleted customer
1380
+ *
1381
+ * @tags customers
1382
+ * @name DeleteCustomer
1383
+ * @summary Delete a customer
1384
+ * @request DELETE:/customers/{external_id}
1385
+ * @secure
1386
+ */
1387
+ deleteCustomer: (externalId: string, params?: RequestParams) => Promise<HttpResponse<Customer, ApiResponseUnauthorized | ApiResponseNotFound | ApiResponseNotAllowed>>;
1371
1388
  /**
1372
1389
  * @description Return a customer current usage
1373
1390
  *
@@ -1602,6 +1619,16 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1602
1619
  * @secure
1603
1620
  */
1604
1621
  downloadInvoice: (id: string, params?: RequestParams) => Promise<HttpResponse<Invoice, ApiResponseUnauthorized | ApiResponseNotFound>>;
1622
+ /**
1623
+ * @description Retry invoice payment
1624
+ *
1625
+ * @tags invoices
1626
+ * @name RetryPayment
1627
+ * @summary Retry invoice payment
1628
+ * @request POST:/invoices/{id}/retry_payment
1629
+ * @secure
1630
+ */
1631
+ retryPayment: (id: string, params?: RequestParams) => Promise<HttpResponse<void, ApiResponseUnauthorized | ApiResponseNotFound | ApiResponseNotAllowed>>;
1605
1632
  /**
1606
1633
  * @description Refresh a draft invoice
1607
1634
  *
@@ -1731,6 +1758,37 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1731
1758
  */
1732
1759
  external_customer_id: string;
1733
1760
  }, params?: RequestParams) => Promise<HttpResponse<Wallets, ApiResponseUnauthorized>>;
1761
+ /**
1762
+ * @description Find all wallet transactions for certain wallet
1763
+ *
1764
+ * @tags wallets
1765
+ * @name FindAllWalletTransactions
1766
+ * @summary Find wallet transactions
1767
+ * @request GET:/wallets/{id}/wallet_transactions
1768
+ * @secure
1769
+ */
1770
+ findAllWalletTransactions: (id: string, query?: {
1771
+ /**
1772
+ * Number of page
1773
+ * @example 2
1774
+ */
1775
+ page?: number;
1776
+ /**
1777
+ * Number of records per page
1778
+ * @example 20
1779
+ */
1780
+ per_page?: number;
1781
+ /**
1782
+ * Status (pending or settled)
1783
+ * @example "pending"
1784
+ */
1785
+ status?: string;
1786
+ /**
1787
+ * Transaction Type (inbound or outbound)
1788
+ * @example "inbound"
1789
+ */
1790
+ transaction_type?: string;
1791
+ }, params?: RequestParams) => Promise<HttpResponse<WalletTransactions, ApiResponseUnauthorized | ApiResponseNotFound>>;
1734
1792
  };
1735
1793
  walletTransactions: {
1736
1794
  /**
@@ -1742,7 +1800,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1742
1800
  * @request POST:/wallet_transactions
1743
1801
  * @secure
1744
1802
  */
1745
- createWalletTransaction: (data: WalletTransactionInput, params?: RequestParams) => Promise<HttpResponse<WalletTransaction, ApiResponseBadRequest | ApiResponseUnauthorized | ApiResponseUnprocessableEntity>>;
1803
+ createWalletTransaction: (data: WalletTransactionInput, params?: RequestParams) => Promise<HttpResponse<WalletTransactions, ApiResponseBadRequest | ApiResponseUnauthorized | ApiResponseUnprocessableEntity>>;
1746
1804
  };
1747
1805
  creditNotes: {
1748
1806
  /**