Shorten printful/webflow naming convention
This commit is contained in:
@@ -34,11 +34,11 @@ class SkusClient {
|
||||
constructor(private creds: Credentials) { }
|
||||
|
||||
async create(
|
||||
webflowProductId: string,
|
||||
wProductId: string,
|
||||
skus: DeepPartial<Webflow.Products.Skus.Sku>[],
|
||||
): Promise<string[]> {
|
||||
const res = await fetch(
|
||||
`${this.creds.apiSitesUrl}/products/${webflowProductId}/skus`,
|
||||
`${this.creds.apiSitesUrl}/products/${wProductId}/skus`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -54,19 +54,19 @@ class SkusClient {
|
||||
}
|
||||
|
||||
async update(
|
||||
webflowProductId: string,
|
||||
webflowSkuId: string,
|
||||
webflowSku: DeepPartial<Webflow.Products.Skus.Sku>,
|
||||
wProductId: string,
|
||||
wSkuId: string,
|
||||
wSku: DeepPartial<Webflow.Products.Skus.Sku>,
|
||||
): Promise<void> {
|
||||
const res = await fetch(
|
||||
`${this.creds.apiSitesUrl}/products/${webflowProductId}/skus/${webflowSkuId}`,
|
||||
`${this.creds.apiSitesUrl}/products/${wProductId}/skus/${wSkuId}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...this.creds.authHeader,
|
||||
},
|
||||
body: JSON.stringify({ sku: webflowSku }),
|
||||
body: JSON.stringify({ sku: wSku }),
|
||||
},
|
||||
);
|
||||
if (!res.ok) throw new WebflowError("Failed to update Webflow product SKU", res.status, await parsePayload(res));
|
||||
@@ -81,7 +81,7 @@ class ProductsClient {
|
||||
}
|
||||
|
||||
async create(
|
||||
webflowProductAndSku: DeepPartial<Webflow.Products.ProductAndSku>,
|
||||
wProductAndSku: DeepPartial<Webflow.Products.ProductAndSku>,
|
||||
): Promise<string> {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/products`, {
|
||||
method: "POST",
|
||||
@@ -89,7 +89,7 @@ class ProductsClient {
|
||||
"Content-Type": "application/json",
|
||||
...this.creds.authHeader,
|
||||
},
|
||||
body: JSON.stringify(webflowProductAndSku),
|
||||
body: JSON.stringify(wProductAndSku),
|
||||
});
|
||||
if (!res.ok) throw new WebflowError("Failed to create Webflow product", res.status, await parsePayload(res));
|
||||
const payload = (await res.json()) as { product: { id: string } };
|
||||
@@ -97,7 +97,7 @@ class ProductsClient {
|
||||
}
|
||||
|
||||
async list(opt: PagingOptions = {}): Promise<Webflow.Products.ProductAndSkus[]> {
|
||||
const allWebflowProducts: Webflow.Products.ProductAndSkus[] = [];
|
||||
const allWProducts: Webflow.Products.ProductAndSkus[] = [];
|
||||
let offset = opt.offset ?? 0;
|
||||
do {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/products?offset=${offset}&limit=${opt.limit ?? 100}`, {
|
||||
@@ -106,15 +106,15 @@ class ProductsClient {
|
||||
});
|
||||
if (!res.ok) throw new WebflowError("Failed to list Webflow products", res.status, await parsePayload(res));
|
||||
const payload = (await res.json()) as Webflow.MetaDataMulti<"items", Webflow.Products.ProductAndSkus>;
|
||||
allWebflowProducts.push(...payload.items);
|
||||
offset = allWebflowProducts.length;
|
||||
if (allWebflowProducts.length >= (payload?.pagination?.total ?? 0)) break;
|
||||
allWProducts.push(...payload.items);
|
||||
offset = allWProducts.length;
|
||||
if (allWProducts.length >= (payload?.pagination?.total ?? 0)) break;
|
||||
} while (opt.forceAll);
|
||||
return allWebflowProducts;
|
||||
return allWProducts;
|
||||
}
|
||||
|
||||
async get(webflowProductId: string): Promise<Webflow.Products.ProductAndSkus | undefined> {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/products/${webflowProductId}`, {
|
||||
async get(wProductId: string): Promise<Webflow.Products.ProductAndSkus | undefined> {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/products/${wProductId}`, {
|
||||
method: "GET",
|
||||
headers: this.creds.authHeader,
|
||||
});
|
||||
@@ -124,23 +124,23 @@ class ProductsClient {
|
||||
}
|
||||
|
||||
async update(
|
||||
webflowProductId: string,
|
||||
webflowProduct: DeepPartial<Webflow.Products.ProductAndSku>,
|
||||
wProductId: string,
|
||||
wProduct: DeepPartial<Webflow.Products.ProductAndSku>,
|
||||
): Promise<void> {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/products/${webflowProductId}`, {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/products/${wProductId}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...this.creds.authHeader,
|
||||
},
|
||||
body: JSON.stringify(webflowProduct),
|
||||
body: JSON.stringify(wProduct),
|
||||
});
|
||||
if (!res.ok) throw new WebflowError("Failed to update Webflow product", res.status, await parsePayload(res));
|
||||
}
|
||||
|
||||
async remove(webflowProductId: string): Promise<void> {
|
||||
async remove(wProductId: string): Promise<void> {
|
||||
const res = await fetch(
|
||||
`${this.creds.apiCollectionsUrl}/items/${webflowProductId}`,
|
||||
`${this.creds.apiCollectionsUrl}/items/${wProductId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
@@ -179,30 +179,30 @@ class OrdersClient {
|
||||
}
|
||||
|
||||
async update(
|
||||
webflowOrderId: string,
|
||||
webflowOrderUpdate: {
|
||||
wOrderId: string,
|
||||
wOrderUpdate: {
|
||||
comment?: string;
|
||||
shippingProvider?: string;
|
||||
shippingTracking?: string;
|
||||
shippingTrackingURL: string;
|
||||
},
|
||||
): Promise<void> {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/orders/${webflowOrderId}`, {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/orders/${wOrderId}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...this.creds.authHeader,
|
||||
},
|
||||
body: JSON.stringify(webflowOrderUpdate),
|
||||
body: JSON.stringify(wOrderUpdate),
|
||||
});
|
||||
if (!res.ok) throw new WebflowError("Failed to update Webflow order", res.status, await parsePayload(res));
|
||||
}
|
||||
|
||||
async fulfill(
|
||||
webflowOrderId: string,
|
||||
wOrderId: string,
|
||||
opt: { sendOrderFulfilledEmail?: boolean } = {},
|
||||
): Promise<void> {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/orders/${webflowOrderId}/fulfill`, {
|
||||
const res = await fetch(`${this.creds.apiSitesUrl}/orders/${wOrderId}/fulfill`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
Reference in New Issue
Block a user