@scaleway/sdk-billing 1.3.0 → 2.1.1

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 ADDED
@@ -0,0 +1,96 @@
1
+ # @scaleway/sdk-billing
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@scaleway/sdk-billing.svg)](https://www.npmjs.com/package/@scaleway/sdk-billing)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@scaleway/sdk-billing.svg)](https://www.npmjs.com/package/@scaleway/sdk-billing)
5
+ [![license](https://img.shields.io/npm/l/@scaleway/sdk-billing.svg)](https://github.com/scaleway/scaleway-sdk-js/blob/master/LICENSE)
6
+
7
+ Scaleway SDK for Billing API.
8
+
9
+ > **Note**
10
+ > This is an automatically generated package that is part of the [Scaleway SDK for JavaScript](https://github.com/scaleway/scaleway-sdk-js).
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @scaleway/sdk-billing @scaleway/sdk-client
16
+ ```
17
+
18
+ or with pnpm:
19
+
20
+ ```bash
21
+ pnpm add @scaleway/sdk-billing @scaleway/sdk-client
22
+ ```
23
+
24
+ or with yarn:
25
+
26
+ ```bash
27
+ yarn add @scaleway/sdk-billing @scaleway/sdk-client
28
+ ```
29
+
30
+ ## Getting Started
31
+
32
+ You'll need a pair of access and secret keys to connect to Scaleway API. Please check the [documentation](https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/) on how to retrieve them.
33
+
34
+ ### Basic Usage
35
+
36
+ ```typescript
37
+ import { createClient } from '@scaleway/sdk-client'
38
+ import { Billing } from '@scaleway/sdk-billing'
39
+
40
+ const client = createClient({
41
+ accessKey: 'SCWXXXXXXXXXXXXXXXXX',
42
+ secretKey: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
43
+ defaultProjectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
44
+ defaultRegion: 'fr-par',
45
+ defaultZone: 'fr-par-1',
46
+ })
47
+
48
+ const api = new Billing.v1.API(client)
49
+
50
+ // Use the API
51
+ // Example: await api.listServers()
52
+ ```
53
+
54
+ ### Using Configuration Loader
55
+
56
+ For a simpler setup, you can load credentials from the configuration file or environment variables:
57
+
58
+ ```typescript
59
+ import { createClient } from '@scaleway/sdk-client'
60
+ import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader'
61
+ import { Billing } from '@scaleway/sdk-billing'
62
+
63
+ const profile = loadProfileFromConfigurationFile()
64
+ const client = createClient(profile)
65
+ const api = new Billing.v1.API(client)
66
+ ```
67
+
68
+ ## Documentation
69
+
70
+ - 📚 [Scaleway SDK Reference Documentation](https://scaleway.github.io/scaleway-sdk-js)
71
+ - 🌐 [Scaleway Billing API Documentation](https://www.scaleway.com/en/developers/api/billing/)
72
+ - 📖 [Main Repository](https://github.com/scaleway/scaleway-sdk-js)
73
+ - 💡 [Example Projects](https://github.com/scaleway/scaleway-sdk-js/tree/master/examples)
74
+
75
+ ## Features
76
+
77
+ - ✅ Full TypeScript support with complete type definitions
78
+ - ✅ Promise-based API
79
+ - ✅ Automatic pagination helpers
80
+ - ✅ Built-in error handling
81
+ - ✅ Compatible with Node.js ≥ 20
82
+
83
+ ## Support
84
+
85
+ We love feedback! Feel free to reach us on:
86
+ - [Scaleway Slack community](https://slack.scaleway.com/) - Join us on [#opensource](https://scaleway-community.slack.com/app_redirect?channel=opensource)
87
+ - [GitHub Issues](https://github.com/scaleway/scaleway-sdk-js/issues)
88
+
89
+ ## Contributing
90
+
91
+ This repository is at its early stage and is still in active development. If you are looking for a way to contribute, please read [CONTRIBUTING.md](https://github.com/scaleway/scaleway-sdk-js/blob/master/CONTRIBUTING.md).
92
+
93
+ ## License
94
+
95
+ This project is Apache 2.0 licensed. See the [LICENSE](https://github.com/scaleway/scaleway-sdk-js/blob/master/LICENSE) file for details.
96
+
@@ -10,24 +10,19 @@ class API extends API$1 {
10
10
  ["category_name", request.categoryName],
11
11
  ["order_by", request.orderBy],
12
12
  ["page", request.page],
13
- [
14
- "page_size",
15
- request.pageSize ?? this.client.settings.defaultPageSize
16
- ],
17
- ...Object.entries(
18
- resolveOneOf([
19
- {
20
- default: this.client.settings.defaultOrganizationId,
21
- param: "organization_id",
22
- value: request.organizationId
23
- },
24
- {
25
- default: this.client.settings.defaultProjectId,
26
- param: "project_id",
27
- value: request.projectId
28
- }
29
- ])
30
- )
13
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize],
14
+ ...Object.entries(resolveOneOf([
15
+ {
16
+ default: this.client.settings.defaultOrganizationId,
17
+ param: "organization_id",
18
+ value: request.organizationId
19
+ },
20
+ {
21
+ default: this.client.settings.defaultProjectId,
22
+ param: "project_id",
23
+ value: request.projectId
24
+ }
25
+ ]))
31
26
  )
32
27
  },
33
28
  unmarshalListConsumptionsResponse
@@ -46,15 +41,9 @@ class API extends API$1 {
46
41
  urlParams: urlParams(
47
42
  ["billing_period", request.billingPeriod],
48
43
  ["order_by", request.orderBy],
49
- [
50
- "organization_id",
51
- request.organizationId ?? this.client.settings.defaultOrganizationId
52
- ],
44
+ ["organization_id", request.organizationId ?? this.client.settings.defaultOrganizationId],
53
45
  ["page", request.page],
54
- [
55
- "page_size",
56
- request.pageSize ?? this.client.settings.defaultPageSize
57
- ]
46
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize]
58
47
  )
59
48
  },
60
49
  unmarshalListTaxesResponse
@@ -77,10 +66,7 @@ class API extends API$1 {
77
66
  ["order_by", request.orderBy],
78
67
  ["organization_id", request.organizationId],
79
68
  ["page", request.page],
80
- [
81
- "page_size",
82
- request.pageSize ?? this.client.settings.defaultPageSize
83
- ]
69
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize]
84
70
  )
85
71
  },
86
72
  unmarshalListInvoicesResponse
@@ -98,22 +84,24 @@ class API extends API$1 {
98
84
  * @param request - The request {@link ExportInvoicesRequest}
99
85
  * @returns A Promise of Blob
100
86
  */
101
- exportInvoices = (request = {}) => this.client.fetch({
102
- method: "GET",
103
- path: `/billing/v2beta1/export-invoices`,
104
- urlParams: urlParams(
105
- ["dl", 1],
106
- ["billing_period_start_after", request.billingPeriodStartAfter],
107
- ["billing_period_start_before", request.billingPeriodStartBefore],
108
- ["file_type", request.fileType],
109
- ["invoice_type", request.invoiceType],
110
- ["order_by", request.orderBy],
111
- ["organization_id", request.organizationId],
112
- ["page", request.page],
113
- ["page_size", request.pageSize ?? this.client.settings.defaultPageSize]
114
- ),
115
- responseType: "blob"
116
- });
87
+ exportInvoices = (request = {}) => this.client.fetch(
88
+ {
89
+ method: "GET",
90
+ path: `/billing/v2beta1/export-invoices`,
91
+ urlParams: urlParams(
92
+ ["dl", 1],
93
+ ["billing_period_start_after", request.billingPeriodStartAfter],
94
+ ["billing_period_start_before", request.billingPeriodStartBefore],
95
+ ["file_type", request.fileType],
96
+ ["invoice_type", request.invoiceType],
97
+ ["order_by", request.orderBy],
98
+ ["organization_id", request.organizationId],
99
+ ["page", request.page],
100
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize]
101
+ ),
102
+ responseType: "blob"
103
+ }
104
+ );
117
105
  /**
118
106
  * Get an invoice. Get a specific invoice, specified by its ID.
119
107
  *
@@ -133,12 +121,17 @@ class API extends API$1 {
133
121
  * @param request - The request {@link DownloadInvoiceRequest}
134
122
  * @returns A Promise of Blob
135
123
  */
136
- downloadInvoice = (request) => this.client.fetch({
137
- method: "GET",
138
- path: `/billing/v2beta1/invoices/${validatePathParam("invoiceId", request.invoiceId)}/download`,
139
- urlParams: urlParams(["dl", 1], ["file_type", request.fileType]),
140
- responseType: "blob"
141
- });
124
+ downloadInvoice = (request) => this.client.fetch(
125
+ {
126
+ method: "GET",
127
+ path: `/billing/v2beta1/invoices/${validatePathParam("invoiceId", request.invoiceId)}/download`,
128
+ urlParams: urlParams(
129
+ ["dl", 1],
130
+ ["file_type", request.fileType]
131
+ ),
132
+ responseType: "blob"
133
+ }
134
+ );
142
135
  pageOfListDiscounts = (request = {}) => this.client.fetch(
143
136
  {
144
137
  method: "GET",
@@ -147,10 +140,7 @@ class API extends API$1 {
147
140
  ["order_by", request.orderBy],
148
141
  ["organization_id", request.organizationId],
149
142
  ["page", request.page],
150
- [
151
- "page_size",
152
- request.pageSize ?? this.client.settings.defaultPageSize
153
- ]
143
+ ["page_size", request.pageSize ?? this.client.settings.defaultPageSize]
154
144
  )
155
145
  },
156
146
  unmarshalListDiscountsResponse
@@ -177,10 +167,7 @@ class API extends API$1 {
177
167
  path: `/billing/v2beta1/redeem-coupon`,
178
168
  urlParams: urlParams(
179
169
  ["code", request.code],
180
- [
181
- "organization_id",
182
- request.organizationId ?? this.client.settings.defaultOrganizationId
183
- ]
170
+ ["organization_id", request.organizationId ?? this.client.settings.defaultOrganizationId]
184
171
  )
185
172
  },
186
173
  unmarshalDiscount
@@ -1,3 +1,3 @@
1
- export { API } from './api.gen.js';
1
+ export { API, } from './api.gen.js';
2
2
  export * from './marshalling.gen.js';
3
3
  export type { Discount, DiscountCoupon, DiscountDiscountMode, DiscountFilter, DiscountFilterType, DownloadInvoiceRequest, DownloadInvoiceRequestFileType, ExportInvoicesRequest, ExportInvoicesRequestFileType, ExportInvoicesRequestOrderBy, GetInvoiceRequest, Invoice, InvoiceType, ListConsumptionsRequest, ListConsumptionsRequestOrderBy, ListConsumptionsResponse, ListConsumptionsResponseConsumption, ListDiscountsRequest, ListDiscountsRequestOrderBy, ListDiscountsResponse, ListInvoicesRequest, ListInvoicesRequestOrderBy, ListInvoicesResponse, ListTaxesRequest, ListTaxesRequestOrderBy, ListTaxesResponse, ListTaxesResponseTax, RedeemCouponRequest, } from './types.gen.js';
@@ -93,10 +93,7 @@ const unmarshalListConsumptionsResponse = (data) => {
93
93
  );
94
94
  }
95
95
  return {
96
- consumptions: unmarshalArrayOfObject(
97
- data.consumptions,
98
- unmarshalListConsumptionsResponseConsumption
99
- ),
96
+ consumptions: unmarshalArrayOfObject(data.consumptions, unmarshalListConsumptionsResponseConsumption),
100
97
  totalCount: data.total_count,
101
98
  totalDiscountUntaxedValue: data.total_discount_untaxed_value,
102
99
  updatedAt: unmarshalDate(data.updated_at)
package/package.json CHANGED
@@ -1,23 +1,20 @@
1
1
  {
2
2
  "name": "@scaleway/sdk-billing",
3
- "version": "1.3.0",
3
+ "version": "2.1.1",
4
4
  "description": "Scaleway SDK billing",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
+ "README.md",
7
8
  "dist"
8
9
  ],
9
10
  "type": "module",
10
11
  "exports": {
11
12
  ".": {
12
13
  "types": "./dist/index.gen.d.ts",
13
- "import": "./dist/index.gen.js",
14
- "require": "./dist/index.gen.cjs",
15
14
  "default": "./dist/index.gen.js"
16
15
  },
17
16
  "./*": {
18
17
  "types": "./dist/*/index.gen.d.ts",
19
- "import": "./dist/*/index.gen.js",
20
- "require": "./dist/*/index.gen.cjs",
21
18
  "default": "./dist/*/index.gen.js"
22
19
  }
23
20
  },
@@ -26,17 +23,17 @@
26
23
  "directory": "packages_generated/billing"
27
24
  },
28
25
  "engines": {
29
- "node": ">=20.19.4"
26
+ "node": ">=20.19.6"
30
27
  },
31
28
  "dependencies": {
32
29
  "@scaleway/random-name": "5.1.2",
33
- "@scaleway/sdk-std": "1.2.0"
30
+ "@scaleway/sdk-std": "2.1.0"
34
31
  },
35
32
  "peerDependencies": {
36
- "@scaleway/sdk-client": "^1.3.3"
33
+ "@scaleway/sdk-client": "^2.1.0"
37
34
  },
38
35
  "devDependencies": {
39
- "@scaleway/sdk-client": "^1.3.3"
36
+ "@scaleway/sdk-client": "^2.1.0"
40
37
  },
41
38
  "scripts": {
42
39
  "package:check": "pnpm publint",
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index_gen = require("./v2beta1/index.gen.cjs");
4
- exports.Billingv2beta1 = index_gen;
@@ -1,191 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const sdkClient = require("@scaleway/sdk-client");
4
- const marshalling_gen = require("./marshalling.gen.cjs");
5
- class API extends sdkClient.API {
6
- pageOfListConsumptions = (request = {}) => this.client.fetch(
7
- {
8
- method: "GET",
9
- path: `/billing/v2beta1/consumptions`,
10
- urlParams: sdkClient.urlParams(
11
- ["billing_period", request.billingPeriod],
12
- ["category_name", request.categoryName],
13
- ["order_by", request.orderBy],
14
- ["page", request.page],
15
- [
16
- "page_size",
17
- request.pageSize ?? this.client.settings.defaultPageSize
18
- ],
19
- ...Object.entries(
20
- sdkClient.resolveOneOf([
21
- {
22
- default: this.client.settings.defaultOrganizationId,
23
- param: "organization_id",
24
- value: request.organizationId
25
- },
26
- {
27
- default: this.client.settings.defaultProjectId,
28
- param: "project_id",
29
- value: request.projectId
30
- }
31
- ])
32
- )
33
- )
34
- },
35
- marshalling_gen.unmarshalListConsumptionsResponse
36
- );
37
- /**
38
- * Get monthly consumption. Consumption allows you to retrieve your past or current consumption cost, by project or category.
39
- *
40
- * @param request - The request {@link ListConsumptionsRequest}
41
- * @returns A Promise of ListConsumptionsResponse
42
- */
43
- listConsumptions = (request = {}) => sdkClient.enrichForPagination("consumptions", this.pageOfListConsumptions, request);
44
- pageOfListTaxes = (request = {}) => this.client.fetch(
45
- {
46
- method: "GET",
47
- path: `/billing/v2beta1/taxes`,
48
- urlParams: sdkClient.urlParams(
49
- ["billing_period", request.billingPeriod],
50
- ["order_by", request.orderBy],
51
- [
52
- "organization_id",
53
- request.organizationId ?? this.client.settings.defaultOrganizationId
54
- ],
55
- ["page", request.page],
56
- [
57
- "page_size",
58
- request.pageSize ?? this.client.settings.defaultPageSize
59
- ]
60
- )
61
- },
62
- marshalling_gen.unmarshalListTaxesResponse
63
- );
64
- /**
65
- * Get monthly consumption taxes. Consumption Tax allows you to retrieve your past or current tax charges, by project or category.
66
- *
67
- * @param request - The request {@link ListTaxesRequest}
68
- * @returns A Promise of ListTaxesResponse
69
- */
70
- listTaxes = (request = {}) => sdkClient.enrichForPagination("taxes", this.pageOfListTaxes, request);
71
- pageOfListInvoices = (request = {}) => this.client.fetch(
72
- {
73
- method: "GET",
74
- path: `/billing/v2beta1/invoices`,
75
- urlParams: sdkClient.urlParams(
76
- ["billing_period_start_after", request.billingPeriodStartAfter],
77
- ["billing_period_start_before", request.billingPeriodStartBefore],
78
- ["invoice_type", request.invoiceType],
79
- ["order_by", request.orderBy],
80
- ["organization_id", request.organizationId],
81
- ["page", request.page],
82
- [
83
- "page_size",
84
- request.pageSize ?? this.client.settings.defaultPageSize
85
- ]
86
- )
87
- },
88
- marshalling_gen.unmarshalListInvoicesResponse
89
- );
90
- /**
91
- * List invoices. List all your invoices, filtering by `start_date` and `invoice_type`. Each invoice has its own ID.
92
- *
93
- * @param request - The request {@link ListInvoicesRequest}
94
- * @returns A Promise of ListInvoicesResponse
95
- */
96
- listInvoices = (request = {}) => sdkClient.enrichForPagination("invoices", this.pageOfListInvoices, request);
97
- /**
98
- * Export invoices. Export invoices in a CSV file.
99
- *
100
- * @param request - The request {@link ExportInvoicesRequest}
101
- * @returns A Promise of Blob
102
- */
103
- exportInvoices = (request = {}) => this.client.fetch({
104
- method: "GET",
105
- path: `/billing/v2beta1/export-invoices`,
106
- urlParams: sdkClient.urlParams(
107
- ["dl", 1],
108
- ["billing_period_start_after", request.billingPeriodStartAfter],
109
- ["billing_period_start_before", request.billingPeriodStartBefore],
110
- ["file_type", request.fileType],
111
- ["invoice_type", request.invoiceType],
112
- ["order_by", request.orderBy],
113
- ["organization_id", request.organizationId],
114
- ["page", request.page],
115
- ["page_size", request.pageSize ?? this.client.settings.defaultPageSize]
116
- ),
117
- responseType: "blob"
118
- });
119
- /**
120
- * Get an invoice. Get a specific invoice, specified by its ID.
121
- *
122
- * @param request - The request {@link GetInvoiceRequest}
123
- * @returns A Promise of Invoice
124
- */
125
- getInvoice = (request) => this.client.fetch(
126
- {
127
- method: "GET",
128
- path: `/billing/v2beta1/invoices/${sdkClient.validatePathParam("invoiceId", request.invoiceId)}`
129
- },
130
- marshalling_gen.unmarshalInvoice
131
- );
132
- /**
133
- * Download an invoice. Download a specific invoice, specified by its ID.
134
- *
135
- * @param request - The request {@link DownloadInvoiceRequest}
136
- * @returns A Promise of Blob
137
- */
138
- downloadInvoice = (request) => this.client.fetch({
139
- method: "GET",
140
- path: `/billing/v2beta1/invoices/${sdkClient.validatePathParam("invoiceId", request.invoiceId)}/download`,
141
- urlParams: sdkClient.urlParams(["dl", 1], ["file_type", request.fileType]),
142
- responseType: "blob"
143
- });
144
- pageOfListDiscounts = (request = {}) => this.client.fetch(
145
- {
146
- method: "GET",
147
- path: `/billing/v2beta1/discounts`,
148
- urlParams: sdkClient.urlParams(
149
- ["order_by", request.orderBy],
150
- ["organization_id", request.organizationId],
151
- ["page", request.page],
152
- [
153
- "page_size",
154
- request.pageSize ?? this.client.settings.defaultPageSize
155
- ]
156
- )
157
- },
158
- marshalling_gen.unmarshalListDiscountsResponse
159
- );
160
- /**
161
- * List discounts. List all discounts for your Organization and usable categories, products, offers, references, regions and zones where the discount can be applied. As a reseller:
162
- - If you do not specify an `organization_id` you will list the discounts applied to your own Organization and your customers
163
- - If you indicate your `organization_id` you will list only the discounts applied to your Organization
164
- - If you indicate `the organization_id` of one of your customers, you will list the discounts applied to their Organization.
165
- *
166
- * @param request - The request {@link ListDiscountsRequest}
167
- * @returns A Promise of ListDiscountsResponse
168
- */
169
- listDiscounts = (request = {}) => sdkClient.enrichForPagination("discounts", this.pageOfListDiscounts, request);
170
- /**
171
- * Redeem coupon. Redeem a coupon given the related code.
172
- *
173
- * @param request - The request {@link RedeemCouponRequest}
174
- * @returns A Promise of Discount
175
- */
176
- redeemCoupon = (request) => this.client.fetch(
177
- {
178
- method: "POST",
179
- path: `/billing/v2beta1/redeem-coupon`,
180
- urlParams: sdkClient.urlParams(
181
- ["code", request.code],
182
- [
183
- "organization_id",
184
- request.organizationId ?? this.client.settings.defaultOrganizationId
185
- ]
186
- )
187
- },
188
- marshalling_gen.unmarshalDiscount
189
- );
190
- }
191
- exports.API = API;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const api_gen = require("./api.gen.cjs");
4
- const marshalling_gen = require("./marshalling.gen.cjs");
5
- exports.API = api_gen.API;
6
- exports.unmarshalDiscount = marshalling_gen.unmarshalDiscount;
7
- exports.unmarshalInvoice = marshalling_gen.unmarshalInvoice;
8
- exports.unmarshalListConsumptionsResponse = marshalling_gen.unmarshalListConsumptionsResponse;
9
- exports.unmarshalListDiscountsResponse = marshalling_gen.unmarshalListDiscountsResponse;
10
- exports.unmarshalListInvoicesResponse = marshalling_gen.unmarshalListInvoicesResponse;
11
- exports.unmarshalListTaxesResponse = marshalling_gen.unmarshalListTaxesResponse;
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const sdkClient = require("@scaleway/sdk-client");
4
- const unmarshalDiscountCoupon = (data) => {
5
- if (!sdkClient.isJSONObject(data)) {
6
- throw new TypeError(
7
- `Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary.`
8
- );
9
- }
10
- return {
11
- description: data.description
12
- };
13
- };
14
- const unmarshalDiscountFilter = (data) => {
15
- if (!sdkClient.isJSONObject(data)) {
16
- throw new TypeError(
17
- `Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary.`
18
- );
19
- }
20
- return {
21
- exclude: data.exclude,
22
- type: data.type,
23
- value: data.value
24
- };
25
- };
26
- const unmarshalDiscount = (data) => {
27
- if (!sdkClient.isJSONObject(data)) {
28
- throw new TypeError(
29
- `Unmarshalling the type 'Discount' failed as data isn't a dictionary.`
30
- );
31
- }
32
- return {
33
- coupon: data.coupon ? unmarshalDiscountCoupon(data.coupon) : void 0,
34
- creationDate: sdkClient.unmarshalDate(data.creation_date),
35
- description: data.description,
36
- filters: sdkClient.unmarshalArrayOfObject(data.filters, unmarshalDiscountFilter),
37
- id: data.id,
38
- mode: data.mode,
39
- organizationId: data.organization_id,
40
- startDate: sdkClient.unmarshalDate(data.start_date),
41
- stopDate: sdkClient.unmarshalDate(data.stop_date),
42
- value: data.value,
43
- valueRemaining: data.value_remaining,
44
- valueUsed: data.value_used
45
- };
46
- };
47
- const unmarshalInvoice = (data) => {
48
- if (!sdkClient.isJSONObject(data)) {
49
- throw new TypeError(
50
- `Unmarshalling the type 'Invoice' failed as data isn't a dictionary.`
51
- );
52
- }
53
- return {
54
- billingPeriod: sdkClient.unmarshalDate(data.billing_period),
55
- dueDate: sdkClient.unmarshalDate(data.due_date),
56
- id: data.id,
57
- issuedDate: sdkClient.unmarshalDate(data.issued_date),
58
- number: data.number,
59
- organizationId: data.organization_id,
60
- organizationName: data.organization_name,
61
- sellerName: data.seller_name,
62
- startDate: sdkClient.unmarshalDate(data.start_date),
63
- state: data.state,
64
- stopDate: sdkClient.unmarshalDate(data.stop_date),
65
- totalDiscount: data.total_discount ? sdkClient.unmarshalMoney(data.total_discount) : void 0,
66
- totalTax: data.total_tax ? sdkClient.unmarshalMoney(data.total_tax) : void 0,
67
- totalTaxed: data.total_taxed ? sdkClient.unmarshalMoney(data.total_taxed) : void 0,
68
- totalUndiscount: data.total_undiscount ? sdkClient.unmarshalMoney(data.total_undiscount) : void 0,
69
- totalUntaxed: data.total_untaxed ? sdkClient.unmarshalMoney(data.total_untaxed) : void 0,
70
- type: data.type
71
- };
72
- };
73
- const unmarshalListConsumptionsResponseConsumption = (data) => {
74
- if (!sdkClient.isJSONObject(data)) {
75
- throw new TypeError(
76
- `Unmarshalling the type 'ListConsumptionsResponseConsumption' failed as data isn't a dictionary.`
77
- );
78
- }
79
- return {
80
- billedQuantity: data.billed_quantity,
81
- categoryName: data.category_name,
82
- consumerId: data.consumer_id,
83
- productName: data.product_name,
84
- projectId: data.project_id,
85
- resourceName: data.resource_name,
86
- sku: data.sku,
87
- unit: data.unit,
88
- value: data.value ? sdkClient.unmarshalMoney(data.value) : void 0
89
- };
90
- };
91
- const unmarshalListConsumptionsResponse = (data) => {
92
- if (!sdkClient.isJSONObject(data)) {
93
- throw new TypeError(
94
- `Unmarshalling the type 'ListConsumptionsResponse' failed as data isn't a dictionary.`
95
- );
96
- }
97
- return {
98
- consumptions: sdkClient.unmarshalArrayOfObject(
99
- data.consumptions,
100
- unmarshalListConsumptionsResponseConsumption
101
- ),
102
- totalCount: data.total_count,
103
- totalDiscountUntaxedValue: data.total_discount_untaxed_value,
104
- updatedAt: sdkClient.unmarshalDate(data.updated_at)
105
- };
106
- };
107
- const unmarshalListDiscountsResponse = (data) => {
108
- if (!sdkClient.isJSONObject(data)) {
109
- throw new TypeError(
110
- `Unmarshalling the type 'ListDiscountsResponse' failed as data isn't a dictionary.`
111
- );
112
- }
113
- return {
114
- discounts: sdkClient.unmarshalArrayOfObject(data.discounts, unmarshalDiscount),
115
- totalCount: data.total_count
116
- };
117
- };
118
- const unmarshalListInvoicesResponse = (data) => {
119
- if (!sdkClient.isJSONObject(data)) {
120
- throw new TypeError(
121
- `Unmarshalling the type 'ListInvoicesResponse' failed as data isn't a dictionary.`
122
- );
123
- }
124
- return {
125
- invoices: sdkClient.unmarshalArrayOfObject(data.invoices, unmarshalInvoice),
126
- totalCount: data.total_count
127
- };
128
- };
129
- const unmarshalListTaxesResponseTax = (data) => {
130
- if (!sdkClient.isJSONObject(data)) {
131
- throw new TypeError(
132
- `Unmarshalling the type 'ListTaxesResponseTax' failed as data isn't a dictionary.`
133
- );
134
- }
135
- return {
136
- currency: data.currency,
137
- description: data.description,
138
- rate: data.rate,
139
- totalTaxValue: data.total_tax_value
140
- };
141
- };
142
- const unmarshalListTaxesResponse = (data) => {
143
- if (!sdkClient.isJSONObject(data)) {
144
- throw new TypeError(
145
- `Unmarshalling the type 'ListTaxesResponse' failed as data isn't a dictionary.`
146
- );
147
- }
148
- return {
149
- taxes: sdkClient.unmarshalArrayOfObject(data.taxes, unmarshalListTaxesResponseTax),
150
- totalCount: data.total_count,
151
- updatedAt: sdkClient.unmarshalDate(data.updated_at)
152
- };
153
- };
154
- exports.unmarshalDiscount = unmarshalDiscount;
155
- exports.unmarshalInvoice = unmarshalInvoice;
156
- exports.unmarshalListConsumptionsResponse = unmarshalListConsumptionsResponse;
157
- exports.unmarshalListDiscountsResponse = unmarshalListDiscountsResponse;
158
- exports.unmarshalListInvoicesResponse = unmarshalListInvoicesResponse;
159
- exports.unmarshalListTaxesResponse = unmarshalListTaxesResponse;