Add orders page

This commit is contained in:
Dominic Ferrando
2026-07-17 15:18:06 -04:00
parent d4dacbaded
commit 086f458db5
4 changed files with 100 additions and 3 deletions
+12
View File
@@ -103,6 +103,18 @@ class ProductsClient {
class OrdersClient {
constructor(private creds: Credentials) { }
async get(orderId: number | string): Promise<Printful.Orders.Order | undefined> {
const res = await fetch(`${this.creds.apiUrl}/store/orders/${orderId}`, {
method: "GET",
headers: this.creds.authHeaders,
});
if (res.status === 429) throw new PrintfulRateLimitError(res.headers.get("Retry-After"), await parsePayload(res));
if (res.status === 404 || res.status === 400) return;
if (!res.ok) throw new PrintfulError("Failed to get Printful order", res.status, await parsePayload(res));
const payload = (await res.json()) as Printful.MetaDataSingle<Printful.Orders.Order>;
return payload.result;
}
async create(pOrder: Printful.Orders.Order) {
const res = await fetch(`${this.creds.apiUrl}/orders`, {
method: "POST",
+11
View File
@@ -192,6 +192,17 @@ class ProductsClient {
class OrdersClient {
constructor(private creds: Credentials) { }
async get(wOrderId: string): Promise<Webflow.Orders.Order | undefined> {
const res = await fetch(`${this.creds.apiSitesUrl}/orders/${wOrderId}`, {
method: "GET",
headers: this.creds.authHeader,
});
if (res.status === 429) throw new WebflowRateLimitError(res.headers.get("Retry-After"), await parsePayload(res));
if (res.status === 404 || res.status === 400) return;
if (!res.ok) throw new WebflowError("Failed to get Webflow order", res.status, await parsePayload(res));
return (await res.json()) as Webflow.Orders.Order;
}
async list(opt: PagingOptions & { status?: Webflow.Orders.Order["status"] } = {}): Promise<Webflow.Orders.Order[]> {
const allOrders: Webflow.Orders.Order[] = [];
let offset = opt.offset ?? 0;