Skip to content

Commit

Permalink
update schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Dec 3, 2023
1 parent c5da0ab commit a7ba6f3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 79 deletions.
162 changes: 86 additions & 76 deletions src/schema/valibot.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { array, boolean, date, email, enumType, integer, isoDate, literal, minLength, minValue, null_, number, object, optional, record, string, tuple, union, url } from 'valibot';
import { array, boolean, date, email, integer, isoDate, literal, maxLength, minLength, minValue, null_, number, object, optional, picklist, record, string, tuple, union, url } from 'valibot';

const currency = number([minValue(0)]);
const format = optional(enumType(['csv', 'json']));
const format = optional(picklist(['csv', 'json']));
const dateString = tuple([date(), string()]);
const idType = enumType(['o', 'p'])
const idType = picklist(['o', 'p'])
const nullOrString = tuple([null_(), string()]);

const sharedCredentialProps = {
grant_type: literal('client_credentials'),
Expand Down Expand Up @@ -64,75 +65,84 @@ export const salesReport = {
...sharedSalesMerchProps,
format: format
}),
response: record(string([minLength(1)]), object({
date: string([isoDate()]),
paid_to: string(),
item_type: tuple([literal('album'), literal('track')]),
item_name: string(),
artist: string(),
currency: union([
literal('AUD'),
literal('CAD'),
literal('CHF'),
literal('CZK'),
literal('DKK'),
literal('EUR'),
literal('GBP'),
literal('HKD'),
literal('HUF'),
literal('ILS'),
literal('JPY'),
literal('MXN'),
literal('NOK'),
literal('NZD'),
literal('PLN'),
literal('SEK'),
literal('SGD'),
literal('USD')
]),
item_price: currency,
quantity: number([integer(), minValue(0)]),
discount_code: tuple([null_(), string()]),
sub_total: currency,
// seller_tax: null,
// marketplace_tax: null,
// shipping: null,
// ship_from_country_name: null,
transaction_fee: currency,
// fee_type: paypal,
item_total: currency,
amount_you_received: currency,
bandcamp_transaction_id: number([integer()]),
// // paypal_transaction_id: null,
// net_amount: currency,
// // package: digital download,
// // option: null,
item_url: string([url()]),
// // catalog_number: null,
upc: string(),
isrc: string(),
buyer_name: string(),
buyer_email: string([email()]),
// // buyer_phone: null,
// // buyer_note: null,
ship_to_name: string(),
ship_to_street: string(),
ship_to_street_2: string(),
// // ship_to_city: null,
// // ship_to_state: null,
// // ship_to_zip: null,
// // ship_to_country: null,
// // ship_to_country_code: null,
// // ship_date: null,
// // ship_notes: null,
// // country: United States,
// // country_code: US,
// // region_or_state: IL,
city: string(),
referer: string(),
// referer_url: bandcamp.com/app/android/search,
// // sku: null
}))
response: tuple([
// JSON
record(string([minLength(1)]), object({
date: string([isoDate()]),
paid_to: tuple([
string(),
string([email()]),
]),
item_type: tuple([literal('album'), literal('package'), literal('track')]),
item_name: string(),
artist: string(),
currency: union([
literal('AUD'),
literal('CAD'),
literal('CHF'),
literal('CZK'),
literal('DKK'),
literal('EUR'),
literal('GBP'),
literal('HKD'),
literal('HUF'),
literal('ILS'),
literal('JPY'),
literal('MXN'),
literal('NOK'),
literal('NZD'),
literal('PLN'),
literal('SEK'),
literal('SGD'),
literal('USD')
]),
item_price: currency,
quantity: number([integer(), minValue(0)]),
discount_code: nullOrString,
sub_total: currency,
seller_tax: number(),
marketplace_tax: number(),
shipping: tuple([null_(), number()]),
ship_from_country_name: string(), // TODO use literals?,
transaction_fee: currency,
fee_type: tuple([null_(), literal('creditcard'), literal('paypal')]), // TODO is it really 'creaditcard'?,
item_total: currency,
amount_you_received: currency,
bandcamp_transaction_id: number([integer()]),
paypal_transaction_id: nullOrString,
net_amount: currency,
package: string(), // TOD: can it be null?
option: null_(), // TODO what values are there?
item_url: string([url()]),
catalog_number: nullOrString,
upc: string(),
isrc: string(),
buyer_name: string(),
buyer_email: string([email()]),
buyer_phone: nullOrString,
buyer_note: nullOrString,
ship_to_name: nullOrString,
ship_to_street: string(),
ship_to_street_2: string(),
ship_to_city: nullOrString,
ship_to_state: nullOrString,
ship_to_zip: nullOrString,
ship_to_country: nullOrString,
ship_to_country_code: nullOrString, // TODO use literals?
ship_date: dateString,
ship_notes: nullOrString,
country: string(), // TODO literals?
country_code: string([maxLength(2)]), // TODO literals?
region_or_state: string(),
city: nullOrString,
referer: string(),
referer_url: string(), // TODO url without protocol
sku: nullOrString
})),
object({
csv: string()
})
])
};

/**
Expand All @@ -155,8 +165,8 @@ export const getShippingOrigin = {
response: undefined
};

export const getOrders = {
requestBody: object({
export const getOrders = {
requestBody: object({
band_id: number([integer()]),
member_band_id: optional(number([integer()])),
start_time: optional(dateString),
Expand All @@ -173,7 +183,7 @@ export const updateShippedItems = {
requestBody: array(
object({
id: number([integer()]),
id_type: enumType(['p', 's']),
id_type: picklist(['p', 's']),
shipped: optional(boolean()),
notification: optional(boolean()),
notification_message: optional(string()),
Expand Down Expand Up @@ -211,7 +221,7 @@ export const updateQuantities = {
};

export const updateSku = {
requestBody: array(
requestBody: array(
object({
id: number([integer()]),
id_type: idType,
Expand Down
6 changes: 3 additions & 3 deletions src/schema/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const salesReport = {
sub_total: currency,
seller_tax: z.number(),
marketplace_tax: z.number(),
shipping: z.number(),
shipping: z.tuple([z.null(), z.number()]),
ship_from_country_name: z.string(), // TODO use literals?
transaction_fee: currency,
fee_type: z.tuple([z.null(), z.literal('creditcard'), z.literal('paypal')]), // TODO is it really 'creaditcard'?
Expand All @@ -120,8 +120,8 @@ export const salesReport = {
bandcamp_transaction_id: z.number().int(),
paypal_transaction_id: nullOrString,
net_amount: currency,
package: z.string(), // TODO: can it be null?
option: z.null(), // TODO: what values are there?
package: z.string(), // TODO can it be null?
option: z.null(), // TODO what values are there?
item_url: z.string().url(),
catalog_number: nullOrString,
upc: z.string(),
Expand Down

0 comments on commit a7ba6f3

Please sign in to comment.