pancake-client-sdk
Version:
Official TypeScript SDK for Pancake POS API
102 lines • 4.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PancakeClient = void 0;
const customer_1 = require("./resources/customer");
const order_1 = require("./resources/order");
const product_1 = require("./resources/product");
const promotion_1 = require("./resources/promotion");
const shipping_1 = require("./resources/shipping");
const shop_1 = require("./resources/shop");
const warehouse_1 = require("./resources/warehouse");
const finance_1 = require("./resources/finance");
const staff_1 = require("./resources/staff");
const crm_1 = require("./resources/crm");
const review_1 = require("./resources/review");
const loyalty_1 = require("./resources/loyalty");
const webhook_1 = require("./resources/webhook");
const reports_1 = require("./resources/reports");
const geo_1 = require("./resources/geo");
const task_1 = require("./resources/task");
const measurement_1 = require("./resources/measurement");
const customer_note_1 = require("./resources/customer-note");
const return_1 = require("./resources/return");
const einvoice_1 = require("./resources/einvoice");
const tag_1 = require("./resources/tag");
const media_1 = require("./resources/media");
const marketplace_1 = require("./resources/marketplace");
const payment_1 = require("./resources/payment");
const settings_1 = require("./resources/settings");
class PancakeClient {
constructor(apiKey, shopId) {
this.apiKey = apiKey;
this.shopId = shopId;
this.baseUrl = "https://pos.pages.fm/api/v1";
this.customers = new customer_1.CustomerResource(this);
this.orders = new order_1.OrderResource(this);
this.products = new product_1.ProductResource(this);
this.promotions = new promotion_1.PromotionResource(this);
this.shipping = new shipping_1.ShippingResource(this);
this.shops = new shop_1.ShopResource(this);
this.warehouses = new warehouse_1.WarehouseResource(this);
this.finance = new finance_1.FinanceResource(this);
this.staff = new staff_1.StaffResource(this);
this.crm = new crm_1.CRMResource(this);
this.reviews = new review_1.ReviewResource(this);
this.loyalty = new loyalty_1.LoyaltyResource(this);
this.webhooks = new webhook_1.WebhookResource(this);
this.reports = new reports_1.ReportResource(this);
this.geo = new geo_1.GeoResource(this);
this.tasks = new task_1.TaskResource(this);
this.measurements = new measurement_1.MeasurementResource(this);
this.customerNotes = new customer_note_1.CustomerNoteResource(this);
this.returns = new return_1.ReturnResource(this);
this.einvoices = new einvoice_1.EInvoiceResource(this);
this.tags = new tag_1.TagResource(this);
this.media = new media_1.MediaResource(this);
this.marketplace = new marketplace_1.MarketplaceResource(this);
this.payments = new payment_1.PaymentResource(this);
this.settings = new settings_1.SettingsResource(this);
}
get(path, params) {
return this.request('GET', path, params);
}
post(path, body, params) {
return this.request('POST', path, params, body);
}
put(path, body, params) {
return this.request('PUT', path, params, body);
}
delete(path, params) {
return this.request('DELETE', path, params);
}
createResource(resourceClass) {
return new resourceClass(this);
}
async request(method, path, params, body) {
const url = new URL(`${this.baseUrl}${path}`);
// Add API key to all requests
url.searchParams.append('api_key', this.apiKey);
// Add query parameters if provided
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
url.searchParams.append(key, String(value));
}
});
}
const response = await fetch(url.toString(), {
method,
headers: {
'Content-Type': 'application/json',
},
body: body ? JSON.stringify(body) : undefined,
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
}
exports.PancakeClient = PancakeClient;
exports.default = PancakeClient;
//# sourceMappingURL=client.js.map