@vantage-sh/vantage-client 0.1.0-beta7 → 2.0.0
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/README.md +201 -80
- package/dist/index.d.mts +20895 -0
- package/dist/index.d.ts +20895 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -43
- package/.swagger-codegen/VERSION +0 -1
- package/.swagger-codegen-ignore +0 -23
- package/.travis.yml +0 -4
- package/babel.config.json +0 -10
- package/docs/Cost.md +0 -11
- package/docs/Costs.md +0 -11
- package/docs/CostsApi.md +0 -168
- package/docs/PingApi.md +0 -51
- package/docs/Price.md +0 -14
- package/docs/Prices.md +0 -9
- package/docs/PricesApi.md +0 -328
- package/docs/Product.md +0 -13
- package/docs/Products.md +0 -9
- package/docs/Provider.md +0 -10
- package/docs/Providers.md +0 -9
- package/docs/Report.md +0 -13
- package/docs/Reports.md +0 -9
- package/docs/Service.md +0 -11
- package/docs/Services.md +0 -9
- package/lib/Vantage/ApiClient.js +0 -645
- package/lib/Vantage/Vantage/CostsApi.js +0 -183
- package/lib/Vantage/Vantage/PingApi.js +0 -71
- package/lib/Vantage/Vantage/PricesApi.js +0 -325
- package/lib/Vantage/index.js +0 -133
- package/lib/Vantage/model/Cost.js +0 -81
- package/lib/Vantage/model/Costs.js +0 -82
- package/lib/Vantage/model/Price.js +0 -102
- package/lib/Vantage/model/Prices.js +0 -68
- package/lib/Vantage/model/Product.js +0 -95
- package/lib/Vantage/model/Products.js +0 -68
- package/lib/Vantage/model/Provider.js +0 -73
- package/lib/Vantage/model/Providers.js +0 -68
- package/lib/Vantage/model/Report.js +0 -95
- package/lib/Vantage/model/Reports.js +0 -68
- package/lib/Vantage/model/Service.js +0 -80
- package/lib/Vantage/model/Services.js +0 -68
- package/mocha.opts +0 -1
- package/test/Vantage/Vantage/CostsApi.spec.js +0 -164
- package/test/Vantage/Vantage/PingApi.spec.js +0 -61
- package/test/Vantage/Vantage/PricesApi.spec.js +0 -280
- package/test/Vantage/model/Cost.spec.js +0 -71
- package/test/Vantage/model/Costs.spec.js +0 -71
- package/test/Vantage/model/Price.spec.js +0 -89
- package/test/Vantage/model/Prices.spec.js +0 -59
- package/test/Vantage/model/Product.spec.js +0 -83
- package/test/Vantage/model/Products.spec.js +0 -59
- package/test/Vantage/model/Provider.spec.js +0 -65
- package/test/Vantage/model/Providers.spec.js +0 -59
- package/test/Vantage/model/Report.spec.js +0 -83
- package/test/Vantage/model/Reports.spec.js +0 -59
- package/test/Vantage/model/Service.spec.js +0 -71
- package/test/Vantage/model/Services.spec.js +0 -59
- package/test/assert-equals.js +0 -81
- package/vantage-sh-vantage-client-0.1.0-beta6.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,118 +1,239 @@
|
|
|
1
|
-
|
|
1
|
+
# @vantage-sh/vantage-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A fully-typed TypeScript SDK for the [Vantage](https://vantage.sh) API. Types and client methods are auto-generated from the official OpenAPI specification.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vantage-sh/vantage-client
|
|
9
|
+
```
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## Two Ways to Use
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
This SDK provides two distinct modes of operation: a **high-level resource API** for convenience, and a **low-level typed request method** for full control with complete type safety.
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
### High-Level API
|
|
14
16
|
|
|
15
|
-
The
|
|
17
|
+
The `APIV2Client` organizes endpoints by resource with intuitive CRUD methods:
|
|
16
18
|
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```
|
|
19
|
+
```typescript
|
|
20
|
+
import { APIV2Client } from "@vantage-sh/vantage-client";
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
The Vantage API is provided completely for free but requires an API token to use. To generate a free API token, follow these steps:
|
|
22
|
+
const client = new APIV2Client("your-api-token");
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* When you're asked _"What would you like to do first?"_ click _"Access Cloud Pricing API"_
|
|
27
|
-
* Create an API token from the account profile page and you're all set
|
|
24
|
+
// List resources with query parameters
|
|
25
|
+
const reports = await client.costReports.list({ page: 1 });
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
// Get a specific resource by token
|
|
28
|
+
const report = await client.costReports.get("rprt_abc123");
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
// Create a new resource
|
|
31
|
+
const folder = await client.folders.create({
|
|
32
|
+
title: "Production Costs",
|
|
33
|
+
workspace_token: "wrkspc_123",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Update a resource
|
|
37
|
+
await client.folders.update("fldr_abc123", {
|
|
38
|
+
title: "Updated Title",
|
|
39
|
+
});
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
// Delete a resource
|
|
42
|
+
await client.folders.delete("fldr_abc123");
|
|
43
|
+
```
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
- Package version: 0.1.0-beta7
|
|
39
|
-
- Build package: io.swagger.codegen.languages.JavascriptClientCodegen
|
|
40
|
-
For more information, please visit [https://www.vantage.sh](https://www.vantage.sh)
|
|
45
|
+
Resources with nested or specialized endpoints expose additional methods:
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
```typescript
|
|
48
|
+
// Access sub-resources
|
|
49
|
+
const costs = await client.costs.getForCostReport("rprt_abc123", {
|
|
50
|
+
start_date: "2024-01-01",
|
|
51
|
+
end_date: "2024-01-31",
|
|
52
|
+
});
|
|
53
|
+
```
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
### Low-Level Typed Requests
|
|
45
56
|
|
|
46
|
-
|
|
47
|
-
var Vantage = require('vantage');
|
|
57
|
+
For full control, use the `request` method directly with path strings. The SDK provides **complete type safety** — TypeScript validates that your path exists, your method is supported, and your request/response bodies match the schema:
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
```typescript
|
|
60
|
+
import { APIV2Client } from "@vantage-sh/vantage-client";
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
var oauth2 = defaultClient.authentications['oauth2'];
|
|
53
|
-
oauth2.accessToken = "YOUR ACCESS TOKEN"
|
|
62
|
+
const client = new APIV2Client("your-api-token");
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
// Path and method are type-checked against the OpenAPI schema
|
|
65
|
+
const report = await client.request(
|
|
66
|
+
"/cost_reports/rprt_abc123",
|
|
67
|
+
"GET",
|
|
68
|
+
undefined
|
|
69
|
+
);
|
|
56
70
|
|
|
57
|
-
|
|
71
|
+
// TypeScript enforces correct body shape for POST/PUT/PATCH
|
|
72
|
+
const newFolder = await client.request("/folders", "POST", {
|
|
73
|
+
title: "My Folder",
|
|
74
|
+
workspace_token: "wrkspc_123",
|
|
75
|
+
});
|
|
58
76
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'page': 2, // {Number} The page of results to return.
|
|
63
|
-
'limit': 500 // {Number} The amount of results to return. The maximum is 1000
|
|
64
|
-
};
|
|
65
|
-
api.getCosts(reportId, opts).then(function(data) {
|
|
66
|
-
console.log('API called successfully. Returned data: ' + data);
|
|
67
|
-
}, function(error) {
|
|
68
|
-
console.error(error);
|
|
77
|
+
// Query parameters are passed as the body for GET requests
|
|
78
|
+
const reports = await client.request("/cost_reports", "GET", {
|
|
79
|
+
page: 1,
|
|
69
80
|
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Path Type Safety
|
|
70
84
|
|
|
85
|
+
The `Path` type is a union of all valid API paths. TypeScript will error on invalid paths:
|
|
71
86
|
|
|
87
|
+
```typescript
|
|
88
|
+
// ✓ Valid path
|
|
89
|
+
await client.request("/cost_reports", "GET", { page: 1 });
|
|
90
|
+
|
|
91
|
+
// ✗ TypeScript error: invalid path
|
|
92
|
+
await client.request("/not_a_real_endpoint", "GET", {});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Method Type Safety
|
|
96
|
+
|
|
97
|
+
The `SupportedMethods<P>` type ensures only valid HTTP methods for each path:
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// ✓ GET is supported on /cost_reports
|
|
101
|
+
await client.request("/cost_reports", "GET", { page: 1 });
|
|
102
|
+
|
|
103
|
+
// ✗ TypeScript error: DELETE not supported on /cost_reports
|
|
104
|
+
await client.request("/cost_reports", "DELETE", {});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Request/Response Types
|
|
108
|
+
|
|
109
|
+
Import types for individual endpoints when needed:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import type {
|
|
113
|
+
GetCostReportResponse,
|
|
114
|
+
CreateFolderRequest,
|
|
115
|
+
CreateFolderResponse,
|
|
116
|
+
} from "@vantage-sh/vantage-client";
|
|
117
|
+
|
|
118
|
+
function displayReport(report: GetCostReportResponse) {
|
|
119
|
+
console.log(report.title);
|
|
120
|
+
}
|
|
72
121
|
```
|
|
73
122
|
|
|
74
|
-
##
|
|
123
|
+
## Error Handling
|
|
75
124
|
|
|
76
|
-
|
|
125
|
+
By default, API errors are thrown as `VantageAPIError` with structured error information:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { VantageAPIError } from "@vantage-sh/vantage-client";
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
await client.costReports.get("invalid_token");
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error instanceof VantageAPIError) {
|
|
134
|
+
console.log(error.status); // 404
|
|
135
|
+
console.log(error.statusText); // "Not Found"
|
|
136
|
+
console.log(error.errors); // ["Resource not found"] or null
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
77
140
|
|
|
78
|
-
|
|
79
|
-
------------ | ------------- | ------------- | -------------
|
|
80
|
-
*Vantage.CostsApi* | [**getCosts**](docs/CostsApi.md#getCosts) | **GET** /v1/reports/{report_id}/costs |
|
|
81
|
-
*Vantage.CostsApi* | [**getReport**](docs/CostsApi.md#getReport) | **GET** /v1/reports/{report_id} |
|
|
82
|
-
*Vantage.CostsApi* | [**getReports**](docs/CostsApi.md#getReports) | **GET** /v1/reports |
|
|
83
|
-
*Vantage.PingApi* | [**ping**](docs/PingApi.md#ping) | **GET** /v1/ping |
|
|
84
|
-
*Vantage.PricesApi* | [**getPrice**](docs/PricesApi.md#getPrice) | **GET** /v1/products/{product_id}/prices/{id} |
|
|
85
|
-
*Vantage.PricesApi* | [**getPrices**](docs/PricesApi.md#getPrices) | **GET** /v1/products/{product_id}/prices |
|
|
86
|
-
*Vantage.PricesApi* | [**getProduct**](docs/PricesApi.md#getProduct) | **GET** /v1/products/{id} |
|
|
87
|
-
*Vantage.PricesApi* | [**getProducts**](docs/PricesApi.md#getProducts) | **GET** /v1/products |
|
|
88
|
-
*Vantage.PricesApi* | [**getProviders**](docs/PricesApi.md#getProviders) | **GET** /v1/providers |
|
|
89
|
-
*Vantage.PricesApi* | [**getServices**](docs/PricesApi.md#getServices) | **GET** /v1/services |
|
|
141
|
+
### Never Throw Mode
|
|
90
142
|
|
|
143
|
+
For Go-style error handling without try/catch, enable never throw mode by passing `true` as the second argument to the client constructor:
|
|
91
144
|
|
|
92
|
-
|
|
145
|
+
```typescript
|
|
146
|
+
import { APIV2Client, VantageAPIError } from "@vantage-sh/vantage-client";
|
|
93
147
|
|
|
94
|
-
-
|
|
95
|
-
- [Vantage.Costs](docs/Costs.md)
|
|
96
|
-
- [Vantage.Price](docs/Price.md)
|
|
97
|
-
- [Vantage.Prices](docs/Prices.md)
|
|
98
|
-
- [Vantage.Product](docs/Product.md)
|
|
99
|
-
- [Vantage.Products](docs/Products.md)
|
|
100
|
-
- [Vantage.Provider](docs/Provider.md)
|
|
101
|
-
- [Vantage.Providers](docs/Providers.md)
|
|
102
|
-
- [Vantage.Report](docs/Report.md)
|
|
103
|
-
- [Vantage.Reports](docs/Reports.md)
|
|
104
|
-
- [Vantage.Service](docs/Service.md)
|
|
105
|
-
- [Vantage.Services](docs/Services.md)
|
|
148
|
+
const client = new APIV2Client("your-api-token", true);
|
|
106
149
|
|
|
150
|
+
// All methods return [result, null] on success or [null, error] on failure
|
|
151
|
+
const [report, error] = await client.costReports.get("rprt_abc123");
|
|
107
152
|
|
|
108
|
-
|
|
153
|
+
if (error) {
|
|
154
|
+
console.log(error.status); // 404
|
|
155
|
+
console.log(error.errors); // ["Resource not found"]
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// TypeScript knows report is defined here
|
|
160
|
+
console.log(report.title);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This pattern works with all client methods, including the low-level `request` method:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const client = new APIV2Client("your-api-token", true);
|
|
167
|
+
|
|
168
|
+
const [folders, error] = await client.request("/folders", "GET", { page: 1 });
|
|
169
|
+
|
|
170
|
+
if (error) {
|
|
171
|
+
// Handle error
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Use folders safely
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Utilities
|
|
179
|
+
|
|
180
|
+
### Path Encoding
|
|
181
|
+
|
|
182
|
+
Use `pathEncode` to safely encode dynamic path segments:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { pathEncode } from "@vantage-sh/vantage-client";
|
|
186
|
+
|
|
187
|
+
const token = pathEncode(userProvidedToken);
|
|
188
|
+
const report = await client.request(
|
|
189
|
+
`/cost_reports/${token}`,
|
|
190
|
+
"GET",
|
|
191
|
+
undefined
|
|
192
|
+
);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Development
|
|
196
|
+
|
|
197
|
+
### Building
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npm run build
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
This fetches the latest OpenAPI schema from the Vantage API, generates TypeScript types, and compiles the client.
|
|
204
|
+
|
|
205
|
+
### Type Checking
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
npm run type-check
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Multipart Edge Cases
|
|
212
|
+
|
|
213
|
+
The client automatically detects `multipart/form-data` routes and handles them appropriately. However, this detection requires a manually-maintained mapping in `BaseClient.ts`:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const multipartEdgeCases: MultipartEdgeCases = {
|
|
217
|
+
"/exchange_rates/csv": {
|
|
218
|
+
POST: true,
|
|
219
|
+
},
|
|
220
|
+
"/business_metrics/{}/values.csv": {
|
|
221
|
+
PUT: true,
|
|
222
|
+
},
|
|
223
|
+
// ...
|
|
224
|
+
};
|
|
225
|
+
```
|
|
109
226
|
|
|
227
|
+
The `MultipartEdgeCases` type is derived from the OpenAPI schema. If a new multipart route is added to the API, **TypeScript will produce an error** until you add the route to this object. Path parameters are represented as `{}` in the keys.
|
|
110
228
|
|
|
111
|
-
###
|
|
229
|
+
### Type Helpers
|
|
112
230
|
|
|
113
|
-
|
|
114
|
-
- **Flow**: application
|
|
115
|
-
- **Authorization URL**:
|
|
116
|
-
- **Scopes**:
|
|
117
|
-
- read: Grants read access
|
|
231
|
+
The SDK exports several utility types for advanced use:
|
|
118
232
|
|
|
233
|
+
| Type | Description |
|
|
234
|
+
|------|-------------|
|
|
235
|
+
| `Path` | Union of all valid API paths |
|
|
236
|
+
| `SupportedMethods<P>` | Valid HTTP methods for a given path |
|
|
237
|
+
| `RequestBodyForPathAndMethod<P, M>` | Request body type for a path/method |
|
|
238
|
+
| `ResponseBodyForPathAndMethod<P, M>` | Response body type for a path/method |
|
|
239
|
+
| `NoSlashString` | Branded type for safely encoded path segments |
|