lago-javascript-client 0.20.0-beta → 0.21.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 +21 -0
- package/README.md +115 -0
- package/esm/swagger/client.js +16 -1
- package/package.json +2 -1
- package/script/swagger/client.js +16 -1
- package/types/swagger/client.d.ts +16 -2
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
|
+
[](https://badge.fury.io/js/lago-javascript-client)
|
|
6
|
+
[](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).
|
package/esm/swagger/client.js
CHANGED
|
@@ -148,7 +148,7 @@ export class HttpClient {
|
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* @title Lago API documentation
|
|
151
|
-
* @version 0.0
|
|
151
|
+
* @version 0.21.0-beta
|
|
152
152
|
* @baseUrl https://api.getlago.com/api/v1
|
|
153
153
|
* @externalDocs https://github.com/getlago
|
|
154
154
|
* @contact <tech@getlago.com>
|
|
@@ -859,6 +859,21 @@ export class Api extends HttpClient {
|
|
|
859
859
|
format: "json",
|
|
860
860
|
...params,
|
|
861
861
|
}),
|
|
862
|
+
/**
|
|
863
|
+
* @description Retry invoice payment
|
|
864
|
+
*
|
|
865
|
+
* @tags invoices
|
|
866
|
+
* @name RetryPayment
|
|
867
|
+
* @summary Retry invoice payment
|
|
868
|
+
* @request POST:/invoices/{id}/retry_payment
|
|
869
|
+
* @secure
|
|
870
|
+
*/
|
|
871
|
+
retryPayment: (id, params = {}) => this.request({
|
|
872
|
+
path: `/invoices/${id}/retry_payment`,
|
|
873
|
+
method: "POST",
|
|
874
|
+
secure: true,
|
|
875
|
+
...params,
|
|
876
|
+
}),
|
|
862
877
|
/**
|
|
863
878
|
* @description Refresh a draft invoice
|
|
864
879
|
*
|
package/package.json
CHANGED
package/script/swagger/client.js
CHANGED
|
@@ -152,7 +152,7 @@ class HttpClient {
|
|
|
152
152
|
exports.HttpClient = HttpClient;
|
|
153
153
|
/**
|
|
154
154
|
* @title Lago API documentation
|
|
155
|
-
* @version 0.0
|
|
155
|
+
* @version 0.21.0-beta
|
|
156
156
|
* @baseUrl https://api.getlago.com/api/v1
|
|
157
157
|
* @externalDocs https://github.com/getlago
|
|
158
158
|
* @contact <tech@getlago.com>
|
|
@@ -863,6 +863,21 @@ class Api extends HttpClient {
|
|
|
863
863
|
format: "json",
|
|
864
864
|
...params,
|
|
865
865
|
}),
|
|
866
|
+
/**
|
|
867
|
+
* @description Retry invoice payment
|
|
868
|
+
*
|
|
869
|
+
* @tags invoices
|
|
870
|
+
* @name RetryPayment
|
|
871
|
+
* @summary Retry invoice payment
|
|
872
|
+
* @request POST:/invoices/{id}/retry_payment
|
|
873
|
+
* @secure
|
|
874
|
+
*/
|
|
875
|
+
retryPayment: (id, params = {}) => this.request({
|
|
876
|
+
path: `/invoices/${id}/retry_payment`,
|
|
877
|
+
method: "POST",
|
|
878
|
+
secure: true,
|
|
879
|
+
...params,
|
|
880
|
+
}),
|
|
866
881
|
/**
|
|
867
882
|
* @description Refresh a draft invoice
|
|
868
883
|
*
|
|
@@ -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;
|
|
@@ -1065,7 +1069,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
1065
1069
|
}
|
|
1066
1070
|
/**
|
|
1067
1071
|
* @title Lago API documentation
|
|
1068
|
-
* @version 0.0
|
|
1072
|
+
* @version 0.21.0-beta
|
|
1069
1073
|
* @baseUrl https://api.getlago.com/api/v1
|
|
1070
1074
|
* @externalDocs https://github.com/getlago
|
|
1071
1075
|
* @contact <tech@getlago.com>
|
|
@@ -1113,7 +1117,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1113
1117
|
* @request DELETE:/billable_metrics/{code}
|
|
1114
1118
|
* @secure
|
|
1115
1119
|
*/
|
|
1116
|
-
destroyBillableMetric: (code: string, params?: RequestParams) => Promise<HttpResponse<BillableMetric, ApiResponseUnauthorized | ApiResponseNotFound
|
|
1120
|
+
destroyBillableMetric: (code: string, params?: RequestParams) => Promise<HttpResponse<BillableMetric, ApiResponseUnauthorized | ApiResponseNotFound>>;
|
|
1117
1121
|
/**
|
|
1118
1122
|
* @description Find all billable metrics in certain organisation
|
|
1119
1123
|
*
|
|
@@ -1602,6 +1606,16 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1602
1606
|
* @secure
|
|
1603
1607
|
*/
|
|
1604
1608
|
downloadInvoice: (id: string, params?: RequestParams) => Promise<HttpResponse<Invoice, ApiResponseUnauthorized | ApiResponseNotFound>>;
|
|
1609
|
+
/**
|
|
1610
|
+
* @description Retry invoice payment
|
|
1611
|
+
*
|
|
1612
|
+
* @tags invoices
|
|
1613
|
+
* @name RetryPayment
|
|
1614
|
+
* @summary Retry invoice payment
|
|
1615
|
+
* @request POST:/invoices/{id}/retry_payment
|
|
1616
|
+
* @secure
|
|
1617
|
+
*/
|
|
1618
|
+
retryPayment: (id: string, params?: RequestParams) => Promise<HttpResponse<void, ApiResponseUnauthorized | ApiResponseNotFound | ApiResponseNotAllowed>>;
|
|
1605
1619
|
/**
|
|
1606
1620
|
* @description Refresh a draft invoice
|
|
1607
1621
|
*
|