UNPKG

@pfantato/printful-ts

Version:

Typescript SDK to integrate with Printful

86 lines (85 loc) 6.27 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrdersService = void 0; const constants_1 = require("@printful-ts/constants"); const schemas_1 = require("@printful-ts/schemas"); const printful_api_service_1 = require("./printful-api.service"); const list_order_shipments_schema_1 = require("@printful-ts/schemas/endpoints/orders/list-order-shipments.schema"); class OrdersService extends printful_api_service_1.PrintfulApiService { async listOrders(params = {}, options = {}) { const _a = schemas_1.ListOrdersSearchParams.parse(params), { store_id } = _a, searchParams = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}`, Object.assign(Object.assign({}, options), { store_id, searchParams }), schemas_1.ListOrdersResponse); } async getOrder(order_id, store_id, options = {}) { return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}`, Object.assign(Object.assign({}, options), { store_id: store_id }), schemas_1.OrderResponse); } async createOrder(body, options = {}) { const _a = schemas_1.CreateOrderBody.parse(body), { store_id } = _a, json = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}`, Object.assign(Object.assign({}, options), { method: 'post', store_id, json }), schemas_1.OrderResponse); } async updateOrder(order_id, body, options = {}) { const _a = schemas_1.CreateOrderBody.parse(body), { store_id } = _a, json = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}`, Object.assign(Object.assign({}, options), { method: 'pat', store_id, json }), schemas_1.OrderResponse); } async confirmOrder(order_id, store_id, options = {}) { return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/confirmation`, Object.assign(Object.assign({}, options), { method: 'post', store_id }), schemas_1.ConfirmOrderResponse); } async deleteOrder(order_id, store_id, options = {}) { return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}`, Object.assign(Object.assign({}, options), { method: 'delete', store_id, validateResponseSchema: false })); } async listOrderItems(order_id, params, options = {}) { const _a = schemas_1.GetOrderItemsSearchParams.parse(params), { store_id } = _a, searchParams = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/order-items`, Object.assign(Object.assign({}, options), { store_id, searchParams }), schemas_1.GetOrderItemsResponse); } async getOrderItem(path_params, store_id, options = {}) { const { order_id, order_item_id } = schemas_1.GetOrderItemPathParams.parse(path_params); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/order-items/${order_item_id}`, Object.assign(Object.assign({}, options), { store_id: store_id }), schemas_1.GetOrderItemResponse); } async createOrderItem(order_id, body, options = {}) { const _a = schemas_1.CreateOrderItemBody.parse(body), { store_id } = _a, json = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/order-items`, Object.assign(Object.assign({}, options), { method: 'post', store_id, json }), schemas_1.CreateOrderItemResponse); } async updateOrderItem(path_params, body, options = {}) { const { order_id, order_item_id } = schemas_1.GetOrderItemPathParams.parse(path_params); const _a = schemas_1.CreateOrderItemBody.parse(body), { store_id } = _a, json = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/order-items/${order_item_id}`, Object.assign(Object.assign({}, options), { method: 'patch', store_id, json }), schemas_1.CreateOrderItemResponse); } async deleteOrderItem(path_params, store_id, options = {}) { const { order_id, order_item_id } = schemas_1.GetOrderItemPathParams.parse(path_params); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/order-items/${order_item_id}`, Object.assign(Object.assign({}, options), { method: 'delete', store_id, validateResponseSchema: false })); } async listShipments(order_id, params, options = {}) { const _a = list_order_shipments_schema_1.ListOrderShipmentsSearchParams.parse(params), { store_id } = _a, searchParams = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/shipments`, Object.assign(Object.assign({}, options), { store_id, searchParams }), list_order_shipments_schema_1.ListOrderShipmentsResponse); } async getInvoice(order_id, store_id, options = {}) { return await this.request(`${constants_1.ORDERS_RESOURCE}/${order_id}/invoice`, Object.assign(Object.assign({}, options), { store_id }), schemas_1.GetInvoiceResponse); } async getOrderEstimationTask(task_id, store_id, options = {}) { return await this.request(`${constants_1.ORDERS_RESOURCE}/estimation-task/${task_id}`, Object.assign(Object.assign({}, options), { store_id }), schemas_1.GetOrderEstimationTaskResponse); } async createOrderEstimationTask(body, options = {}) { const _a = schemas_1.CreateOrderEstimationTaskBody.parse(body), { store_id } = _a, json = __rest(_a, ["store_id"]); return await this.request(`${constants_1.ORDERS_RESOURCE}/estimation-task`, Object.assign(Object.assign({}, options), { method: 'post', store_id, json }), schemas_1.CreateOrderEstimationTaskResponse); } } exports.OrdersService = OrdersService;