Skip to content

Commit

Permalink
add schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Aug 5, 2023
1 parent 24b6685 commit ab7ebb6
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 75 deletions.
26 changes: 20 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
"description": "Node.js library for the Bandcamp API",
"type": "module",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./schema": {
"import": "./dist/schema/index.mjs",
"require": "./dist/schema/index.js"
}
},
"types": "./dist",
"types": "./dist",
"files": [
"dist/",
"types/",
Expand All @@ -24,16 +30,24 @@
],
"license": "MIT",
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts",
"dev": "npm run start",
"build": "npm-run-all --parallel build:*",
"build:lib": "tsup src/index.ts --format esm,cjs --dts",
"build:schema": "tsup src/schema/index.ts --format esm,cjs --dts --out-dir dist/schema",
"dev": "npm-run-all --parallel dev:*",
"dev:lib": "npm run build:lib -- --watch",
"dev:schema": "npm run build:schema -- --watch",
"fix": "eslint --fix ./src",
"lint:code": "eslint ./src --ignore-path .gitignore",
"lint": "npm-run-all --parallel lint:*",
"start": "npm run build -- --watch",
"start": "npm run dev",
"test": "ava ./tests/*.mjs --serial --verbose",
"prepack": "npm run build",
"prepare": "husky install"
},
"dependencies": {
"valibot": "^0.10.0",
"zod": "^3.21.4"
},
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@types/node": "^14.18.33",
Expand Down
85 changes: 16 additions & 69 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { requestSchema as valibotSchema } from './valibot';
export { requestSchema as zodSchema } from './zod';
105 changes: 105 additions & 0 deletions src/schema/valibot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { array, boolean, date, enumType, literal, number, object, optional, string, tuple } from 'valibot';

const format = optional(enumType(['csv', 'json']));
const dateString = tuple([date(), string()]);
const idType = enumType(['o', 'p'])

const sharedCredentialProps = {
grant_type: literal('client_credentials'),
client_id: number(),
client_secret: string()
};

const sharedSalesMerchProps = {
band_id: number(),
member_band_id: optional(number()),
start_time: dateString,
end_time: optional(dateString)
};

export const requestSchema = {
/**
* Account API
* @see {@link https://bandcamp.com/developer/account}
*/
clientCredentials: object(sharedCredentialProps),

refreshToken: object({
...sharedCredentialProps,
refresh_token: string()
}),

/**
* Sales API
* @see {@link https://bandcamp.com/developer/sales}
*/
salesReport: object({
...sharedSalesMerchProps,
format: format
}),

/**
* Merchant API
* @see {@link https://bandcamp.com/developer/merch}
*/
getMerchDetails: object({
...sharedSalesMerchProps,
package_ids: array(number())
}),

getShippingOrigin: object({
band_id: optional(number()),
origin_id: optional(number())
}),

getOrders: object({
band_id: number(),
member_band_id: optional(number()),
start_time: optional(dateString),
end_time: optional(dateString),
unshipped_only: optional(boolean()),
name: optional(string()),
origin_id: optional(number()),
format: format
}),

updateShippedItems: array(
object({
id: number(),
id_type: enumType(['p', 's']),
shipped: optional(boolean()),
notification: optional(boolean()),
notification_message: optional(string()),
ship_date: optional(dateString),
carrier: optional(string()),
tracking_code: optional(tuple([number(), string()]))
})
),

markDateRangeAsShipped: object({
band_id: number(),
member_band_id: optional(number()),
start_time: optional(dateString),
end_time: dateString,
origin_id: optional(number()),
email_notifications: optional(boolean())
}),

updateQuantities: array(
object({
id: number(),
id_type: idType,
quantity_sold: number(),
quantity_available: number(),
origin_id: optional(number())
})
),

updateSku: array(
object({
id: number(),
id_type: idType,
sku: string()
})
)
};

0 comments on commit ab7ebb6

Please sign in to comment.