@scaleway/sdk-billing 1.0.4 → 1.1.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.
@@ -167,5 +167,25 @@ class API extends sdkClient.API {
167
167
  * @returns A Promise of ListDiscountsResponse
168
168
  */
169
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
+ );
170
190
  }
171
191
  exports.API = API;
@@ -1,5 +1,5 @@
1
1
  import { API as ParentAPI } from '@scaleway/sdk-client';
2
- import type { DownloadInvoiceRequest, ExportInvoicesRequest, GetInvoiceRequest, Invoice, ListConsumptionsRequest, ListConsumptionsResponse, ListDiscountsRequest, ListDiscountsResponse, ListInvoicesRequest, ListInvoicesResponse, ListTaxesRequest, ListTaxesResponse } from './types.gen';
2
+ import type { Discount, DownloadInvoiceRequest, ExportInvoicesRequest, GetInvoiceRequest, Invoice, ListConsumptionsRequest, ListConsumptionsResponse, ListDiscountsRequest, ListDiscountsResponse, ListInvoicesRequest, ListInvoicesResponse, ListTaxesRequest, ListTaxesResponse, RedeemCouponRequest } from './types.gen';
3
3
  /**
4
4
  * Billing API.
5
5
 
@@ -71,7 +71,14 @@ export declare class API extends ParentAPI {
71
71
  * @returns A Promise of ListDiscountsResponse
72
72
  */
73
73
  listDiscounts: (request?: Readonly<ListDiscountsRequest>) => Promise<ListDiscountsResponse> & {
74
- all: () => Promise<import("./types.gen").Discount[]>;
75
- [Symbol.asyncIterator]: () => AsyncGenerator<import("./types.gen").Discount[], void, void>;
74
+ all: () => Promise<Discount[]>;
75
+ [Symbol.asyncIterator]: () => AsyncGenerator<Discount[], void, void>;
76
76
  };
77
+ /**
78
+ * Redeem coupon. Redeem a coupon given the related code.
79
+ *
80
+ * @param request - The request {@link RedeemCouponRequest}
81
+ * @returns A Promise of Discount
82
+ */
83
+ redeemCoupon: (request: Readonly<RedeemCouponRequest>) => Promise<Discount>;
77
84
  }
@@ -1,5 +1,5 @@
1
1
  import { API as API$1, urlParams, resolveOneOf, enrichForPagination, validatePathParam } from "@scaleway/sdk-client";
2
- import { unmarshalListConsumptionsResponse, unmarshalListTaxesResponse, unmarshalListInvoicesResponse, unmarshalInvoice, unmarshalListDiscountsResponse } from "./marshalling.gen.js";
2
+ import { unmarshalListConsumptionsResponse, unmarshalListTaxesResponse, unmarshalListInvoicesResponse, unmarshalInvoice, unmarshalListDiscountsResponse, unmarshalDiscount } from "./marshalling.gen.js";
3
3
  class API extends API$1 {
4
4
  pageOfListConsumptions = (request = {}) => this.client.fetch(
5
5
  {
@@ -165,6 +165,26 @@ class API extends API$1 {
165
165
  * @returns A Promise of ListDiscountsResponse
166
166
  */
167
167
  listDiscounts = (request = {}) => enrichForPagination("discounts", this.pageOfListDiscounts, request);
168
+ /**
169
+ * Redeem coupon. Redeem a coupon given the related code.
170
+ *
171
+ * @param request - The request {@link RedeemCouponRequest}
172
+ * @returns A Promise of Discount
173
+ */
174
+ redeemCoupon = (request) => this.client.fetch(
175
+ {
176
+ method: "POST",
177
+ path: `/billing/v2beta1/redeem-coupon`,
178
+ urlParams: urlParams(
179
+ ["code", request.code],
180
+ [
181
+ "organization_id",
182
+ request.organizationId ?? this.client.settings.defaultOrganizationId
183
+ ]
184
+ )
185
+ },
186
+ unmarshalDiscount
187
+ );
168
188
  }
169
189
  export {
170
190
  API
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const api_gen = require("./api.gen.cjs");
4
4
  const marshalling_gen = require("./marshalling.gen.cjs");
5
5
  exports.API = api_gen.API;
6
+ exports.unmarshalDiscount = marshalling_gen.unmarshalDiscount;
6
7
  exports.unmarshalInvoice = marshalling_gen.unmarshalInvoice;
7
8
  exports.unmarshalListConsumptionsResponse = marshalling_gen.unmarshalListConsumptionsResponse;
8
9
  exports.unmarshalListDiscountsResponse = marshalling_gen.unmarshalListDiscountsResponse;
@@ -1,3 +1,3 @@
1
1
  export { API } from './api.gen';
2
2
  export * from './marshalling.gen';
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, } from './types.gen';
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';
@@ -1,7 +1,8 @@
1
1
  import { API } from "./api.gen.js";
2
- import { unmarshalInvoice, unmarshalListConsumptionsResponse, unmarshalListDiscountsResponse, unmarshalListInvoicesResponse, unmarshalListTaxesResponse } from "./marshalling.gen.js";
2
+ import { unmarshalDiscount, unmarshalInvoice, unmarshalListConsumptionsResponse, unmarshalListDiscountsResponse, unmarshalListInvoicesResponse, unmarshalListTaxesResponse } from "./marshalling.gen.js";
3
3
  export {
4
4
  API,
5
+ unmarshalDiscount,
5
6
  unmarshalInvoice,
6
7
  unmarshalListConsumptionsResponse,
7
8
  unmarshalListDiscountsResponse,
@@ -1,6 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
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
+ };
4
47
  const unmarshalInvoice = (data) => {
5
48
  if (!sdkClient.isJSONObject(data)) {
6
49
  throw new TypeError(
@@ -60,49 +103,6 @@ const unmarshalListConsumptionsResponse = (data) => {
60
103
  updatedAt: sdkClient.unmarshalDate(data.updated_at)
61
104
  };
62
105
  };
63
- const unmarshalDiscountCoupon = (data) => {
64
- if (!sdkClient.isJSONObject(data)) {
65
- throw new TypeError(
66
- `Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary.`
67
- );
68
- }
69
- return {
70
- description: data.description
71
- };
72
- };
73
- const unmarshalDiscountFilter = (data) => {
74
- if (!sdkClient.isJSONObject(data)) {
75
- throw new TypeError(
76
- `Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary.`
77
- );
78
- }
79
- return {
80
- exclude: data.exclude,
81
- type: data.type,
82
- value: data.value
83
- };
84
- };
85
- const unmarshalDiscount = (data) => {
86
- if (!sdkClient.isJSONObject(data)) {
87
- throw new TypeError(
88
- `Unmarshalling the type 'Discount' failed as data isn't a dictionary.`
89
- );
90
- }
91
- return {
92
- coupon: data.coupon ? unmarshalDiscountCoupon(data.coupon) : void 0,
93
- creationDate: sdkClient.unmarshalDate(data.creation_date),
94
- description: data.description,
95
- filters: sdkClient.unmarshalArrayOfObject(data.filters, unmarshalDiscountFilter),
96
- id: data.id,
97
- mode: data.mode,
98
- organizationId: data.organization_id,
99
- startDate: sdkClient.unmarshalDate(data.start_date),
100
- stopDate: sdkClient.unmarshalDate(data.stop_date),
101
- value: data.value,
102
- valueRemaining: data.value_remaining,
103
- valueUsed: data.value_used
104
- };
105
- };
106
106
  const unmarshalListDiscountsResponse = (data) => {
107
107
  if (!sdkClient.isJSONObject(data)) {
108
108
  throw new TypeError(
@@ -150,6 +150,7 @@ const unmarshalListTaxesResponse = (data) => {
150
150
  updatedAt: sdkClient.unmarshalDate(data.updated_at)
151
151
  };
152
152
  };
153
+ exports.unmarshalDiscount = unmarshalDiscount;
153
154
  exports.unmarshalInvoice = unmarshalInvoice;
154
155
  exports.unmarshalListConsumptionsResponse = unmarshalListConsumptionsResponse;
155
156
  exports.unmarshalListDiscountsResponse = unmarshalListDiscountsResponse;
@@ -1,4 +1,5 @@
1
- import type { Invoice, ListConsumptionsResponse, ListDiscountsResponse, ListInvoicesResponse, ListTaxesResponse } from './types.gen';
1
+ import type { Discount, Invoice, ListConsumptionsResponse, ListDiscountsResponse, ListInvoicesResponse, ListTaxesResponse } from './types.gen';
2
+ export declare const unmarshalDiscount: (data: unknown) => Discount;
2
3
  export declare const unmarshalInvoice: (data: unknown) => Invoice;
3
4
  export declare const unmarshalListConsumptionsResponse: (data: unknown) => ListConsumptionsResponse;
4
5
  export declare const unmarshalListDiscountsResponse: (data: unknown) => ListDiscountsResponse;
@@ -1,4 +1,47 @@
1
- import { isJSONObject, unmarshalMoney, unmarshalDate, unmarshalArrayOfObject } from "@scaleway/sdk-client";
1
+ import { isJSONObject, unmarshalDate, unmarshalArrayOfObject, unmarshalMoney } from "@scaleway/sdk-client";
2
+ const unmarshalDiscountCoupon = (data) => {
3
+ if (!isJSONObject(data)) {
4
+ throw new TypeError(
5
+ `Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary.`
6
+ );
7
+ }
8
+ return {
9
+ description: data.description
10
+ };
11
+ };
12
+ const unmarshalDiscountFilter = (data) => {
13
+ if (!isJSONObject(data)) {
14
+ throw new TypeError(
15
+ `Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary.`
16
+ );
17
+ }
18
+ return {
19
+ exclude: data.exclude,
20
+ type: data.type,
21
+ value: data.value
22
+ };
23
+ };
24
+ const unmarshalDiscount = (data) => {
25
+ if (!isJSONObject(data)) {
26
+ throw new TypeError(
27
+ `Unmarshalling the type 'Discount' failed as data isn't a dictionary.`
28
+ );
29
+ }
30
+ return {
31
+ coupon: data.coupon ? unmarshalDiscountCoupon(data.coupon) : void 0,
32
+ creationDate: unmarshalDate(data.creation_date),
33
+ description: data.description,
34
+ filters: unmarshalArrayOfObject(data.filters, unmarshalDiscountFilter),
35
+ id: data.id,
36
+ mode: data.mode,
37
+ organizationId: data.organization_id,
38
+ startDate: unmarshalDate(data.start_date),
39
+ stopDate: unmarshalDate(data.stop_date),
40
+ value: data.value,
41
+ valueRemaining: data.value_remaining,
42
+ valueUsed: data.value_used
43
+ };
44
+ };
2
45
  const unmarshalInvoice = (data) => {
3
46
  if (!isJSONObject(data)) {
4
47
  throw new TypeError(
@@ -58,49 +101,6 @@ const unmarshalListConsumptionsResponse = (data) => {
58
101
  updatedAt: unmarshalDate(data.updated_at)
59
102
  };
60
103
  };
61
- const unmarshalDiscountCoupon = (data) => {
62
- if (!isJSONObject(data)) {
63
- throw new TypeError(
64
- `Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary.`
65
- );
66
- }
67
- return {
68
- description: data.description
69
- };
70
- };
71
- const unmarshalDiscountFilter = (data) => {
72
- if (!isJSONObject(data)) {
73
- throw new TypeError(
74
- `Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary.`
75
- );
76
- }
77
- return {
78
- exclude: data.exclude,
79
- type: data.type,
80
- value: data.value
81
- };
82
- };
83
- const unmarshalDiscount = (data) => {
84
- if (!isJSONObject(data)) {
85
- throw new TypeError(
86
- `Unmarshalling the type 'Discount' failed as data isn't a dictionary.`
87
- );
88
- }
89
- return {
90
- coupon: data.coupon ? unmarshalDiscountCoupon(data.coupon) : void 0,
91
- creationDate: unmarshalDate(data.creation_date),
92
- description: data.description,
93
- filters: unmarshalArrayOfObject(data.filters, unmarshalDiscountFilter),
94
- id: data.id,
95
- mode: data.mode,
96
- organizationId: data.organization_id,
97
- startDate: unmarshalDate(data.start_date),
98
- stopDate: unmarshalDate(data.stop_date),
99
- value: data.value,
100
- valueRemaining: data.value_remaining,
101
- valueUsed: data.value_used
102
- };
103
- };
104
104
  const unmarshalListDiscountsResponse = (data) => {
105
105
  if (!isJSONObject(data)) {
106
106
  throw new TypeError(
@@ -149,6 +149,7 @@ const unmarshalListTaxesResponse = (data) => {
149
149
  };
150
150
  };
151
151
  export {
152
+ unmarshalDiscount,
152
153
  unmarshalInvoice,
153
154
  unmarshalListConsumptionsResponse,
154
155
  unmarshalListDiscountsResponse,
@@ -398,3 +398,13 @@ export interface ListTaxesResponse {
398
398
  */
399
399
  updatedAt?: Date;
400
400
  }
401
+ export type RedeemCouponRequest = {
402
+ /**
403
+ * The Organization ID of the discount.
404
+ */
405
+ organizationId?: string;
406
+ /**
407
+ * The code of the coupon to redeem.
408
+ */
409
+ code: string;
410
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleway/sdk-billing",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Scaleway SDK billing",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
@@ -30,13 +30,13 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@scaleway/random-name": "5.1.1",
33
- "@scaleway/sdk-std": "1.0.4"
33
+ "@scaleway/sdk-std": "1.0.5"
34
34
  },
35
35
  "peerDependencies": {
36
- "@scaleway/sdk-client": "^1.2.3"
36
+ "@scaleway/sdk-client": "^1.3.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@scaleway/sdk-client": "^1.2.3"
39
+ "@scaleway/sdk-client": "^1.3.0"
40
40
  },
41
41
  "scripts": {
42
42
  "package:check": "pnpm publint",