@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.
Files changed (62) hide show
  1. package/README.md +201 -80
  2. package/dist/index.d.mts +20895 -0
  3. package/dist/index.d.ts +20895 -0
  4. package/dist/index.js +2 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +2 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +38 -43
  9. package/.swagger-codegen/VERSION +0 -1
  10. package/.swagger-codegen-ignore +0 -23
  11. package/.travis.yml +0 -4
  12. package/babel.config.json +0 -10
  13. package/docs/Cost.md +0 -11
  14. package/docs/Costs.md +0 -11
  15. package/docs/CostsApi.md +0 -168
  16. package/docs/PingApi.md +0 -51
  17. package/docs/Price.md +0 -14
  18. package/docs/Prices.md +0 -9
  19. package/docs/PricesApi.md +0 -328
  20. package/docs/Product.md +0 -13
  21. package/docs/Products.md +0 -9
  22. package/docs/Provider.md +0 -10
  23. package/docs/Providers.md +0 -9
  24. package/docs/Report.md +0 -13
  25. package/docs/Reports.md +0 -9
  26. package/docs/Service.md +0 -11
  27. package/docs/Services.md +0 -9
  28. package/lib/Vantage/ApiClient.js +0 -645
  29. package/lib/Vantage/Vantage/CostsApi.js +0 -183
  30. package/lib/Vantage/Vantage/PingApi.js +0 -71
  31. package/lib/Vantage/Vantage/PricesApi.js +0 -325
  32. package/lib/Vantage/index.js +0 -133
  33. package/lib/Vantage/model/Cost.js +0 -81
  34. package/lib/Vantage/model/Costs.js +0 -82
  35. package/lib/Vantage/model/Price.js +0 -102
  36. package/lib/Vantage/model/Prices.js +0 -68
  37. package/lib/Vantage/model/Product.js +0 -95
  38. package/lib/Vantage/model/Products.js +0 -68
  39. package/lib/Vantage/model/Provider.js +0 -73
  40. package/lib/Vantage/model/Providers.js +0 -68
  41. package/lib/Vantage/model/Report.js +0 -95
  42. package/lib/Vantage/model/Reports.js +0 -68
  43. package/lib/Vantage/model/Service.js +0 -80
  44. package/lib/Vantage/model/Services.js +0 -68
  45. package/mocha.opts +0 -1
  46. package/test/Vantage/Vantage/CostsApi.spec.js +0 -164
  47. package/test/Vantage/Vantage/PingApi.spec.js +0 -61
  48. package/test/Vantage/Vantage/PricesApi.spec.js +0 -280
  49. package/test/Vantage/model/Cost.spec.js +0 -71
  50. package/test/Vantage/model/Costs.spec.js +0 -71
  51. package/test/Vantage/model/Price.spec.js +0 -89
  52. package/test/Vantage/model/Prices.spec.js +0 -59
  53. package/test/Vantage/model/Product.spec.js +0 -83
  54. package/test/Vantage/model/Products.spec.js +0 -59
  55. package/test/Vantage/model/Provider.spec.js +0 -65
  56. package/test/Vantage/model/Providers.spec.js +0 -59
  57. package/test/Vantage/model/Report.spec.js +0 -83
  58. package/test/Vantage/model/Reports.spec.js +0 -59
  59. package/test/Vantage/model/Service.spec.js +0 -71
  60. package/test/Vantage/model/Services.spec.js +0 -59
  61. package/test/assert-equals.js +0 -81
  62. package/vantage-sh-vantage-client-0.1.0-beta6.tgz +0 -0
package/README.md CHANGED
@@ -1,118 +1,239 @@
1
- [![Build Status](https://www.travis-ci.com/vantage-sh/vantage-js.svg?branch=main)](https://www.travis-ci.com/vantage-sh/vantage-js)
1
+ # @vantage-sh/vantage-client
2
2
 
3
- # Vantage Javascript Client
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
- ![Vantage Picture](https://uploads-ssl.webflow.com/5f9ba05ba40d6414f341df34/5f9bb1764b6670c6f7739564_moutain-scene.svg)
5
+ ## Installation
6
6
 
7
- [Vantage](http://vantage.sh/) is a cloud cost transparency platform. This is the official Ruby client for the [Vantage API](http://vantage.readme.io/). You can use the API to get EC2 instance price and product information through a few simple-to-use API calls. The data offered through this API is heavily inspired from data avaiable from [ec2instances.info](http://ec2instances.info/). The feedback we get from users is that this API is significantly easier than learning and using AWS Pricing APIs. We have plans to expand the data available through this API in the future.
7
+ ```bash
8
+ npm install @vantage-sh/vantage-client
9
+ ```
8
10
 
9
- ## Need Help?
11
+ ## Two Ways to Use
10
12
 
11
- Feel free to join us in our [community Slack](https://join.slack.com/t/vantagecommunity/shared_invite/zt-oey52myv-gq4AWRKkX25kjp1UGziPTw) in the #api channel. We're happy to chat and help. You're also welcome to email support@vantage.sh or ping [@JoinVantage](https://twitter.com/joinvantage) on Twitter and we're happy to give assistance. Lastly, we monitor issues on this repo if you have any feature requests or issues.
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
- ## Installation
15
+ ### High-Level API
14
16
 
15
- The easiest way to get going is to install the client through RubyGems:
17
+ The `APIV2Client` organizes endpoints by resource with intuitive CRUD methods:
16
18
 
17
- ```shell
18
- npm i @vantage-sh/vantage-client --save
19
- ```
19
+ ```typescript
20
+ import { APIV2Client } from "@vantage-sh/vantage-client";
20
21
 
21
- ## Generate a Free API Token
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
- * Head to [http://vantage.sh/](http://vantage.sh/)
25
- * Register a free account and confirm your email
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
- You'll only need to do this once and you can use your API token for all usage going forward.
27
+ // Get a specific resource by token
28
+ const report = await client.costReports.get("rprt_abc123");
30
29
 
31
- ## Client
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
- Vantage - JavaScript client for vantage
34
- Vantage API
35
- This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
41
+ // Delete a resource
42
+ await client.folders.delete("fldr_abc123");
43
+ ```
36
44
 
37
- - API version: 1.0.0
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
- ## Getting Started
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
- Please follow the [installation](#installation) instruction and execute the following JS code:
55
+ ### Low-Level Typed Requests
45
56
 
46
- ```javascript
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
- var defaultClient = Vantage.ApiClient.instance;
59
+ ```typescript
60
+ import { APIV2Client } from "@vantage-sh/vantage-client";
50
61
 
51
- // Configure OAuth2 access token for authorization: oauth2
52
- var oauth2 = defaultClient.authentications['oauth2'];
53
- oauth2.accessToken = "YOUR ACCESS TOKEN"
62
+ const client = new APIV2Client("your-api-token");
54
63
 
55
- var api = new Vantage.CostsApi()
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
- var reportId = "reportId_example"; // {String}
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
- var opts = {
60
- 'startDate': "startDate_example", // {String} Query costs by the first date you would like to filter from. ISO 8601 Formatted - 2021-07-15 or 2021-07-15T19:20:48+00:00.
61
- 'endDate': "endDate_example", // {String} Query costs by the last date you would like to filter to. ISO 8601 Formatted - 2021-07-15 or 2021-07-15T19:20:48+00:00.
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
- ## Documentation for API Endpoints
123
+ ## Error Handling
75
124
 
76
- All URIs are relative to *https://api.vantage.sh*
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
- Class | Method | HTTP request | Description
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
- ## Documentation for Models
145
+ ```typescript
146
+ import { APIV2Client, VantageAPIError } from "@vantage-sh/vantage-client";
93
147
 
94
- - [Vantage.Cost](docs/Cost.md)
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
- ## Documentation for Authorization
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
- ### oauth2
229
+ ### Type Helpers
112
230
 
113
- - **Type**: OAuth
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 |