diff --git a/packages/clients/src/api/billing/v2beta1/api.gen.ts b/packages/clients/src/api/billing/v2beta1/api.gen.ts index b6abed6dc..e4ebf8922 100644 --- a/packages/clients/src/api/billing/v2beta1/api.gen.ts +++ b/packages/clients/src/api/billing/v2beta1/api.gen.ts @@ -10,6 +10,7 @@ import { import { unmarshalInvoice, unmarshalListConsumptionsResponse, + unmarshalListDiscountsResponse, unmarshalListInvoicesResponse, unmarshalListTaxesResponse, } from './marshalling.gen' @@ -20,6 +21,8 @@ import type { Invoice, ListConsumptionsRequest, ListConsumptionsResponse, + ListDiscountsRequest, + ListDiscountsResponse, ListInvoicesRequest, ListInvoicesResponse, ListTaxesRequest, @@ -201,4 +204,27 @@ export class API extends ParentAPI { urlParams: urlParams(['dl', 1], ['file_type', request.fileType]), responseType: 'blob', }) + + protected pageOfListDiscounts = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/billing/v2beta1/discounts`, + urlParams: urlParams( + ['order_by', request.orderBy], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListDiscountsResponse, + ) + + listDiscounts = (request: Readonly = {}) => + enrichForPagination('discounts', this.pageOfListDiscounts, request) } diff --git a/packages/clients/src/api/billing/v2beta1/index.gen.ts b/packages/clients/src/api/billing/v2beta1/index.gen.ts index a6a17a06f..7057b294b 100644 --- a/packages/clients/src/api/billing/v2beta1/index.gen.ts +++ b/packages/clients/src/api/billing/v2beta1/index.gen.ts @@ -2,6 +2,11 @@ // If you have any remark or suggestion do not hesitate to open an issue. export { API } from './api.gen' export type { + Discount, + DiscountCoupon, + DiscountDiscountMode, + DiscountFilter, + DiscountFilterType, DownloadInvoiceRequest, DownloadInvoiceRequestFileType, ExportInvoicesRequest, @@ -14,6 +19,9 @@ export type { ListConsumptionsRequestOrderBy, ListConsumptionsResponse, ListConsumptionsResponseConsumption, + ListDiscountsRequest, + ListDiscountsRequestOrderBy, + ListDiscountsResponse, ListInvoicesRequest, ListInvoicesRequestOrderBy, ListInvoicesResponse, diff --git a/packages/clients/src/api/billing/v2beta1/marshalling.gen.ts b/packages/clients/src/api/billing/v2beta1/marshalling.gen.ts index 5a1d1cfd1..37122743f 100644 --- a/packages/clients/src/api/billing/v2beta1/marshalling.gen.ts +++ b/packages/clients/src/api/billing/v2beta1/marshalling.gen.ts @@ -7,9 +7,13 @@ import { unmarshalMoney, } from '../../../bridge' import type { + Discount, + DiscountCoupon, + DiscountFilter, Invoice, ListConsumptionsResponse, ListConsumptionsResponseConsumption, + ListDiscountsResponse, ListInvoicesResponse, ListTaxesResponse, ListTaxesResponseTax, @@ -24,7 +28,6 @@ export const unmarshalInvoice = (data: unknown): Invoice => { return { billingPeriod: unmarshalDate(data.billing_period), - customerName: data.customer_name, dueDate: unmarshalDate(data.due_date), id: data.id, issuedDate: unmarshalDate(data.issued_date), @@ -60,11 +63,13 @@ const unmarshalListConsumptionsResponseConsumption = ( } return { + billedQuantity: data.billed_quantity, categoryName: data.category_name, productName: data.product_name, projectId: data.project_id, resourceName: data.resource_name, sku: data.sku, + unit: data.unit, value: data.value ? unmarshalMoney(data.value) : undefined, } as ListConsumptionsResponseConsumption } @@ -89,6 +94,69 @@ export const unmarshalListConsumptionsResponse = ( } as ListConsumptionsResponse } +const unmarshalDiscountCoupon = (data: unknown): DiscountCoupon => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DiscountCoupon' failed as data isn't a dictionary.`, + ) + } + + return { + description: data.description, + } as DiscountCoupon +} + +const unmarshalDiscountFilter = (data: unknown): DiscountFilter => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DiscountFilter' failed as data isn't a dictionary.`, + ) + } + + return { + type: data.type, + value: data.value, + } as DiscountFilter +} + +const unmarshalDiscount = (data: unknown): Discount => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Discount' failed as data isn't a dictionary.`, + ) + } + + return { + coupon: data.coupon ? unmarshalDiscountCoupon(data.coupon) : undefined, + creationDate: unmarshalDate(data.creation_date), + description: data.description, + filters: unmarshalArrayOfObject(data.filters, unmarshalDiscountFilter), + id: data.id, + mode: data.mode, + organizationId: data.organization_id, + startDate: unmarshalDate(data.start_date), + stopDate: unmarshalDate(data.stop_date), + value: data.value, + valueRemaining: data.value_remaining, + valueUsed: data.value_used, + } as Discount +} + +export const unmarshalListDiscountsResponse = ( + data: unknown, +): ListDiscountsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListDiscountsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + discounts: unmarshalArrayOfObject(data.discounts, unmarshalDiscount), + totalCount: data.total_count, + } as ListDiscountsResponse +} + export const unmarshalListInvoicesResponse = ( data: unknown, ): ListInvoicesResponse => { diff --git a/packages/clients/src/api/billing/v2beta1/types.gen.ts b/packages/clients/src/api/billing/v2beta1/types.gen.ts index b129eea67..0a799b95b 100644 --- a/packages/clients/src/api/billing/v2beta1/types.gen.ts +++ b/packages/clients/src/api/billing/v2beta1/types.gen.ts @@ -2,6 +2,21 @@ // If you have any remark or suggestion do not hesitate to open an issue. import type { Money } from '../../../bridge' +export type DiscountDiscountMode = + | 'unknown_discount_mode' + | 'discount_mode_rate' + | 'discount_mode_value' + | 'discount_mode_splittable' + +export type DiscountFilterType = + | 'unknown_type' + | 'category_name' + | 'product_name' + | 'product_range' + | 'resource_name' + | 'region' + | 'zone' + export type DownloadInvoiceRequestFileType = 'pdf' export type ExportInvoicesRequestFileType = 'csv' @@ -25,11 +40,15 @@ export type ExportInvoicesRequestOrderBy = export type InvoiceType = 'unknown_type' | 'periodic' | 'purchase' export type ListConsumptionsRequestOrderBy = - | 'updated_at_date_desc' - | 'updated_at_date_asc' + | 'updated_at_desc' + | 'updated_at_asc' | 'category_name_desc' | 'category_name_asc' +export type ListDiscountsRequestOrderBy = + | 'creation_date_desc' + | 'creation_date_asc' + export type ListInvoicesRequestOrderBy = | 'invoice_number_desc' | 'invoice_number_asc' @@ -47,11 +66,26 @@ export type ListInvoicesRequestOrderBy = | 'invoice_type_asc' export type ListTaxesRequestOrderBy = - | 'updated_at_date_desc' - | 'updated_at_date_asc' + | 'updated_at_desc' + | 'updated_at_asc' | 'category_name_desc' | 'category_name_asc' +export interface DiscountCoupon { + /** The description of the coupon. */ + description?: string +} + +export interface DiscountFilter { + /** + * Type of the filter (category name, product name, product range, resource + * name, region or zone). + */ + type: DiscountFilterType + /** Value of filter. */ + value: string +} + export interface ListConsumptionsResponseConsumption { /** Monetary value of the consumption. */ value?: Money @@ -68,6 +102,37 @@ export interface ListConsumptionsResponseConsumption { projectId: string /** Name of consumption category. */ categoryName: string + /** Unit of consumed quantity. */ + unit: string + /** Consumed quantity. */ + billedQuantity: string +} + +export interface Discount { + /** The ID of the discount. */ + id: string + /** The creation date of the discount. */ + creationDate?: Date + /** The organization ID of the discount. */ + organizationId: string + /** The description of the discount. */ + description: string + /** The initial value of the discount. */ + value: number + /** The value indicating how much of the discount has been used. */ + valueUsed: number + /** The remaining value of the discount. */ + valueRemaining: number + /** The mode of the discount. */ + mode: DiscountDiscountMode + /** The start date of the discount. */ + startDate?: Date + /** The stop date of the discount. */ + stopDate?: Date + /** The description of the coupon. */ + coupon?: DiscountCoupon + /** List of the discount scopes. */ + filters: DiscountFilter[] } export interface Invoice { @@ -100,9 +165,8 @@ export interface Invoice { state: string /** Invoice number. */ number: number + /** The name of the seller (Scaleway). */ sellerName: string - /** Customer name associated to this organization. */ - customerName: string } export interface ListTaxesResponseTax { @@ -203,6 +267,27 @@ export interface ListConsumptionsResponse { updatedAt?: Date } +export type ListDiscountsRequest = { + /** Order discounts in the response by their description. */ + orderBy?: ListDiscountsRequestOrderBy + /** Positive integer to choose the page to return. */ + page?: number + /** + * Positive integer lower or equal to 100 to select the number of items to + * return. + */ + pageSize?: number + /** ID of the organization. */ + organizationId?: string +} + +export interface ListDiscountsResponse { + /** Total number of discounts. */ + totalCount: number + /** Paginated returned discounts. */ + discounts: Discount[] +} + export type ListInvoicesRequest = { /** * Organization ID. If specified, only invoices from this Organization will be