packages/ at markup-kit dd1e6eb5270e
A snapshot of packages/ in the Weft repository; the official packages are published from these commits. Markup-Kit-Commit: dd1e6eb5270e62e0c8b6c202b3d01f0da6e00ddc
This commit is contained in:
commit
306b143104
72 changed files with 10915 additions and 0 deletions
125
stripe/products.weft
Normal file
125
stripe/products.weft
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
// Products: what you sell.
|
||||
import { collect, request, segment } from "./stripe"
|
||||
import type { Client, Deleted, Page, RequestOptions, StripeError } from "./stripe"
|
||||
|
||||
/// A product. `default_price` is expandable: `idOf` gives its id.
|
||||
export type Product = {
|
||||
id: string,
|
||||
name?: string,
|
||||
active?: boolean,
|
||||
description?: string,
|
||||
images?: string[],
|
||||
metadata?: json,
|
||||
default_price?: json,
|
||||
tax_code?: json,
|
||||
unit_label?: string,
|
||||
url?: string,
|
||||
created?: float,
|
||||
updated?: float,
|
||||
livemode?: boolean,
|
||||
}
|
||||
|
||||
/// The fields of a product you can set. `extra` holds any field this type doesn't list.
|
||||
export type ProductParams = {
|
||||
name?: string,
|
||||
id?: string,
|
||||
active?: boolean,
|
||||
description?: string,
|
||||
images?: string[],
|
||||
metadata?: Map<string, string>,
|
||||
default_price?: string,
|
||||
tax_code?: string,
|
||||
unit_label?: string,
|
||||
url?: string,
|
||||
extra?: json,
|
||||
}
|
||||
|
||||
/// What to list.
|
||||
export type ProductListParams = {
|
||||
active?: boolean,
|
||||
ids?: string[],
|
||||
url?: string,
|
||||
limit?: float,
|
||||
starting_after?: string,
|
||||
ending_before?: string,
|
||||
extra?: json,
|
||||
}
|
||||
|
||||
/// Creates a product.
|
||||
export async fn create(
|
||||
c: Client,
|
||||
params: ProductParams,
|
||||
options: RequestOptions = {},
|
||||
): Product ! StripeError {
|
||||
return try await request(c, "POST", "/v1/products", params, options, j => try j as Product)
|
||||
}
|
||||
|
||||
/// Gets a product by id.
|
||||
export async fn retrieve(
|
||||
c: Client,
|
||||
id: string,
|
||||
options: RequestOptions = {},
|
||||
): Product ! StripeError {
|
||||
return try await request(
|
||||
c,
|
||||
"GET",
|
||||
`/v1/products/${segment(id)}`,
|
||||
null,
|
||||
options,
|
||||
j => try j as Product,
|
||||
)
|
||||
}
|
||||
|
||||
/// Changes the fields given.
|
||||
export async fn update(
|
||||
c: Client,
|
||||
id: string,
|
||||
params: ProductParams,
|
||||
options: RequestOptions = {},
|
||||
): Product ! StripeError {
|
||||
return try await request(
|
||||
c,
|
||||
"POST",
|
||||
`/v1/products/${segment(id)}`,
|
||||
params,
|
||||
options,
|
||||
j => try j as Product,
|
||||
)
|
||||
}
|
||||
|
||||
/// Deletes a product that has no prices.
|
||||
export async fn remove(c: Client, id: string, options: RequestOptions = {}): Deleted ! StripeError {
|
||||
return try await request(
|
||||
c,
|
||||
"DELETE",
|
||||
`/v1/products/${segment(id)}`,
|
||||
null,
|
||||
options,
|
||||
j => try j as Deleted,
|
||||
)
|
||||
}
|
||||
|
||||
/// One page of products.
|
||||
export async fn list(c: Client, params: ProductListParams = {}, options: RequestOptions = {}): Page<
|
||||
Product,
|
||||
> ! StripeError {
|
||||
return try await request(c, "GET", "/v1/products", params, options, j => try j as Page<Product>)
|
||||
}
|
||||
|
||||
/// Every product matching `params`, up to `max`.
|
||||
export async fn listAll(
|
||||
c: Client,
|
||||
params: ProductListParams = {},
|
||||
options: RequestOptions = {},
|
||||
max: int = 10000,
|
||||
): Product[] ! StripeError {
|
||||
return try await collect(
|
||||
c,
|
||||
"/v1/products",
|
||||
params,
|
||||
options,
|
||||
j => try j as Page<Product>,
|
||||
x => x.id,
|
||||
max,
|
||||
)
|
||||
}
|
||||
Loading…
Reference in a new issue