Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/clients/src/api/billing/v2beta1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
unmarshalInvoice,
unmarshalListConsumptionsResponse,
unmarshalListDiscountsResponse,
unmarshalListInvoicesResponse,
unmarshalListTaxesResponse,
} from './marshalling.gen'
Expand All @@ -20,6 +21,8 @@ import type {
Invoice,
ListConsumptionsRequest,
ListConsumptionsResponse,
ListDiscountsRequest,
ListDiscountsResponse,
ListInvoicesRequest,
ListInvoicesResponse,
ListTaxesRequest,
Expand Down Expand Up @@ -201,4 +204,27 @@ export class API extends ParentAPI {
urlParams: urlParams(['dl', 1], ['file_type', request.fileType]),
responseType: 'blob',
})

protected pageOfListDiscounts = (
request: Readonly<ListDiscountsRequest> = {},
) =>
this.client.fetch<ListDiscountsResponse>(
{
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<ListDiscountsRequest> = {}) =>
enrichForPagination('discounts', this.pageOfListDiscounts, request)
}
8 changes: 8 additions & 0 deletions packages/clients/src/api/billing/v2beta1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,6 +19,9 @@ export type {
ListConsumptionsRequestOrderBy,
ListConsumptionsResponse,
ListConsumptionsResponseConsumption,
ListDiscountsRequest,
ListDiscountsRequestOrderBy,
ListDiscountsResponse,
ListInvoicesRequest,
ListInvoicesRequestOrderBy,
ListInvoicesResponse,
Expand Down
70 changes: 69 additions & 1 deletion packages/clients/src/api/billing/v2beta1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {
unmarshalMoney,
} from '../../../bridge'
import type {
Discount,
DiscountCoupon,
DiscountFilter,
Invoice,
ListConsumptionsResponse,
ListConsumptionsResponseConsumption,
ListDiscountsResponse,
ListInvoicesResponse,
ListTaxesResponse,
ListTaxesResponseTax,
Expand All @@ -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),
Expand Down Expand Up @@ -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
}
Expand All @@ -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 => {
Expand Down
97 changes: 91 additions & 6 deletions packages/clients/src/api/billing/v2beta1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down