bananas-commerce
Version:
A client for bananas-commerce with support for TypeScript
47 lines (46 loc) • 1.65 kB
JavaScript
import { casedObjectKeys, } from "../util/casedObjectKeys.js";
import { formatVariableResult, } from "../util/formatVariableResult.js";
import { Extension } from "../extension.js";
export class Webshipper extends Extension {
constructor() {
super(...arguments);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: "webshipper"
});
}
async shippingOptions(args) {
this.assertLoaded();
const { countryCode = this.defaults.countryCode, ...body } = args;
const snakeBody = casedObjectKeys(body, "snake");
const response = await this.catchApiError(this.fetcher
.endpoint("/api/v1/webshipper/shipping-options/")
.method("post")({
body: {
...snakeBody,
delivery_address: {
...snakeBody["delivery_address"],
country_code: countryCode,
},
},
}));
return formatVariableResult({ ...response, data: casedObjectKeys(response.data, "camel") }, (response) => {
switch (response.status) {
case 200:
return "success";
case 204:
return "no-shipping-needed";
case 400:
return "invalid-args";
case 404:
return "not-found";
case 422:
return "unprocessable";
case 503:
return "internal-error";
}
});
}
}