UNPKG

genuka-api

Version:

Javascript(TS) Package to use Genuka API for a StoreFront website

1,398 lines (1,378 loc) 65.5 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { default: () => index_default }); module.exports = __toCommonJS(index_exports); // src/lib/axios.ts var import_axios = __toESM(require("axios"), 1); var import_uuid = require("uuid"); var AxiosConfig = class { instance; token; companyId; shopId; lang; pendingRequests = /* @__PURE__ */ new Map(); constructor({ version = "2023-11", adminMode = false, token, lang = "en", companyId, shopId, apiBaseUrl = "https://api.genuka.com", timezone = "Africa/Douala" } = {}) { this.token = token; this.companyId = companyId; this.shopId = shopId; this.lang = lang; this.instance = import_axios.default.create({ baseURL: `${apiBaseUrl}/${version}${adminMode ? "/admin" : ""}`, headers: { Accept: "application/json", "Accept-Language": this.lang, "X-Request-ID": (0, import_uuid.v4)(), "X-Timezone": timezone } }); this.instance.interceptors.request.use((config) => { if (this.token) config.headers["Authorization"] = `Bearer ${this.token}`; if (this.lang) config.headers["Accept-Language"] = this.lang; if (this.companyId) config.headers["X-Company"] = this.companyId; if (this.shopId) config.headers["X-Shop"] = this.shopId; const requestKey = this.generateRequestKey(config); if (this.pendingRequests.has(requestKey)) { const existingController = this.pendingRequests.get(requestKey); existingController == null ? void 0 : existingController.abort(); } const abortController = new AbortController(); config.signal = abortController.signal; this.pendingRequests.set(requestKey, abortController); return config; }); this.instance.interceptors.response.use( (response) => { const requestKey = this.generateRequestKey(response.config); this.pendingRequests.delete(requestKey); return response; }, (error) => { if (error.config) { const requestKey = this.generateRequestKey(error.config); this.pendingRequests.delete(requestKey); } return Promise.reject(error); } ); } setToken(t) { this.token = t; } setCompanyId(id) { this.companyId = id; } setShopId(id) { this.shopId = id; } setLang(l) { this.lang = l; } generateRequestKey(config) { var _a; const method = ((_a = config.method) == null ? void 0 : _a.toUpperCase()) || "GET"; const url = config.url || ""; const params = JSON.stringify(config.params || {}); const data = JSON.stringify(config.data || {}); return `${method}:${url}:${params}:${data}`; } // Method to manually cancel all pending requests cancelAllRequests() { this.pendingRequests.forEach((controller) => { controller.abort(); }); this.pendingRequests.clear(); } // Method to cancel specific request by key cancelRequest(method, url, params, data) { const requestKey = `${method.toUpperCase()}:${url}:${JSON.stringify( params || {} )}:${JSON.stringify(data || {})}`; const controller = this.pendingRequests.get(requestKey); if (controller) { controller.abort(); this.pendingRequests.delete(requestKey); } } }; var axios_default = AxiosConfig; // src/services/addresses.ts var AddressService = class { constructor(http) { this.http = http; } page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/customers/addresses?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id }) { var _a, _b; try { const response = await this.http.instance.get( `/customers/addresses/${id}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async create(data) { var _a, _b; try { const response = await this.http.instance.post( `/customers/addresses`, data ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async update({ id, ...data }) { var _a, _b; try { const response = await this.http.instance.put( `/customers/addresses/${id}`, data ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async delete({ id }) { var _a, _b; try { const response = await this.http.instance.delete( `/customers/addresses/${id}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/articles.ts var ArticleService = class { constructor(http) { this.http = http; } model = "articles"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""} ` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/blogs.ts var BlogService = class { constructor(http) { this.http = http; } model = "blogs"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""}` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/cart.ts var CartService = class { constructor(http) { this.http = http; } items = []; total = 0; evaluateTotal() { this.total = this.items.reduce( (acc, item) => acc + item.price * item.quantity, 0 ); } set(items = []) { this.items = items; this.evaluateTotal(); } add(item) { const existingVariant = this.items.find( (i) => i.variant_id === item.variant_id ); if (existingVariant) { this.update(item.variant_id, { quantity: item.quantity + existingVariant.quantity }); return; } this.items.push(item); this.evaluateTotal(); } async checkAvailability(item) { try { const response = await this.http.instance.get( `/products/${item.product_id}/variants/${item.variant_id}?check_stock=true` ); const stockQuantity = response.data.data; return stockQuantity >= item.quantity; } catch (e) { console.error("Error checking availability:", e); return false; } } remove(variant_id) { this.items = this.items.filter((i) => i.variant_id !== variant_id); this.evaluateTotal(); } clear() { this.items = []; this.evaluateTotal(); } retrieve() { return this.items; } update(variant_id, itemObj) { this.items = this.items.map((item) => { if (item.variant_id === variant_id) { return { ...item, ...itemObj }; } return item; }); this.evaluateTotal(); } }; // src/services/collections.ts var CollectionService = class { constructor(http) { this.http = http; } model = "collections"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""} ` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/company.ts var CompanyService = class { constructor(http) { this.http = http; } async retrieve() { var _a, _b; try { const response = await this.http.instance.get(`/company`); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/customers.ts var CustomerService = class { constructor(http) { this.http = http; } model = "customers"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async register({ first_name, last_name, email, phone, gender, password, password_confirmation }) { var _a, _b, _c, _d; try { const response = await this.http.instance.post(`/customers/register`, { first_name, last_name, email, phone, gender, password, password_confirmation }); return response.data; } catch (error) { console.error( `Error registering customer:`, ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } async login({ email, phone, password }) { var _a, _b, _c, _d; try { const response = await this.http.instance.post(`/customers/login`, { email, phone, password }); return response.data; } catch (error) { console.error( `Error login customer:`, ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } async getResetLinkToken({ email }) { var _a, _b; try { const response = await this.http.instance.post( `/customers/password/reset-link`, { email } ); return response.data; } catch (error) { console.error(`Error getting reset token customer:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async resetPassword({ email, token, password, password_confirmation }) { var _a, _b; try { const response = await this.http.instance.post( `/customers/password/reset`, { token, password, password_confirmation: password_confirmation || password, email } ); return response.data; } catch (error) { console.error(`Error resetting customer password:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async me() { var _a, _b; try { const response = await this.http.instance.get(`/customers/profile`); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve() { var _a, _b; try { const response = await this.http.instance.get(`/customers/profile`); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async update({ first_name, last_name, email, phone, gender, password, password_confirmation }) { var _a, _b; try { const response = await this.http.instance.put(`/customers/profile`, { first_name, last_name, email, phone, gender, password, password_confirmation }); return response.data; } catch (error) { console.error(`Error updating customer:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async changePassword({ current_password, new_password }) { var _a, _b; try { const response = await this.http.instance.put( `/customers/profile/password`, { current_password, new_password } ); return response.data; } catch (error) { console.error(`Error changing customer password :`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async logout() { var _a, _b; try { const response = await this.http.instance.post(`/customers/logout`); return response.data; } catch (error) { console.error(`Error logout customer:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async get(id) { var _a, _b; try { const response = await this.http.instance.get( `${this.model}/${id}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/discounts.ts var DiscountService = class { constructor(http) { this.http = http; } model = "discounts"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async retrieve({ id, code }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `?code=${code}`}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } // data = { customer? {first_name, last_name, email, phone}, cart_product[{product_id, variant_id, quantity}]} async getAutomatics(data) { var _a, _b; try { const response = await this.http.instance.post( `/${this.model}/automatic`, data ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/orders.ts var OrderService = class { constructor(http) { this.http = http; } model = "orders"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count(isAdmin = false) { const { data } = await this.http.instance.get( `${isAdmin ? "" : "/customers"}/${this.model}/count` ); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries, isAdmin = false } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `${isAdmin ? "" : "/customers"}/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve(id, isAdmin = false, { include = [] } = {}) { var _a, _b; try { const response = await this.http.instance.get( `${isAdmin ? "" : "/customers"}/${this.model}/${id}?include=${include.join(",")}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async create({ isAdmin = false, ...data }) { var _a, _b, _c, _d; try { const response = await this.http.instance.post( `${isAdmin ? "" : "/customers"}/${this.model}`, data ); return response.data; } catch (error) { console.error( `Error creating ${this.model}. Verify the creation (isAdmin = true | false). More info :`, ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } }; // src/services/deliveries.ts var DeliveryService = class { constructor(http) { this.http = http; } model = "deliveries"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count(isAdmin = false) { const { data } = await this.http.instance.get( `${isAdmin ? "" : "/customers"}/${this.model}/count` ); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries, isAdmin = false } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `${isAdmin ? "" : "/customers"}/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve(id, isAdmin = false, { include = [] } = {}) { var _a, _b; try { const response = await this.http.instance.get( `${isAdmin ? "" : "/customers"}/${this.model}/${id}?include=${include.join(",")}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async create({ isAdmin = false, ...data }) { var _a, _b, _c, _d; try { const response = await this.http.instance.post( `${isAdmin ? "" : "/customers"}/${this.model}`, data ); return response.data; } catch (error) { console.error( `Error creating ${this.model}. Verify the creation (isAdmin = true | false). More info :`, ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } }; // src/services/bills.ts var BillService = class { constructor(http) { this.http = http; } model = "bills"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve(id, { include = [] } = {}) { var _a, _b; try { const response = await this.http.instance.get(`/${this.model}/${id}?include=${include.join(",")}`); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async create({ ...data }) { var _a, _b, _c, _d; try { const response = await this.http.instance.post(`/${this.model}`, data); return response.data; } catch (error) { console.error( `Error creating ${this.model}. Verify the creation (isAdmin = true | false). More info :`, ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } }; // src/services/pages.ts var PageService = class { constructor(http) { this.http = http; } model = "pages"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""} ` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/paymentMethods.ts var PaymentMethodService = class { constructor(http) { this.http = http; } model = "paymentMethods"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/productVariants.ts var ProductVariantService = class { constructor(http) { this.http = http; } model = "productVariants"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b, _c, _d; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { console.error( "Error fetching products list:", ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } async retrieve({ id, handle, queries }) { var _a, _b, _c, _d; try { this.queries = queries ?? this.queries; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}${parsedQueries}` ); return response.data; } catch (error) { console.error( "Error fetching product detail:", ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } }; // src/services/products.ts var ProductService = class { constructor(http) { this.http = http; this.productVariantService = new ProductVariantService(this.http); } productVariantService; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; get variants() { return this.productVariantService; } async count() { const { data } = await this.http.instance.get("/products/count"); return data.count; } async list(props) { var _a, _b, _c, _d; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/products?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { console.error( "Error fetching products list:", ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } async retrieve({ id, handle, queries }) { var _a, _b, _c, _d; try { this.queries = queries ?? this.queries; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; const response = await this.http.instance.get( `/products/${id ? id : `handle/${handle}`}${parsedQueries}` ); return response.data; } catch (error) { console.error( "Error fetching product detail:", ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b, _c, _d; try { const response = await this.http.instance.get( `/products/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""} ` ); return response.data; } catch (error) { console.error( "Error fetching similar products:", ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message ); return { error: ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.message) || error.message }; } } }; // src/services/shippings.ts var ShippingService = class { constructor(http) { this.http = http; } model = "shipping-fees"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""} ` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/pickups.ts var PickupService = class { constructor(http) { this.http = http; } model = "pickup-locations"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page = page ?? this.page; this.limit = limit ?? this.limit; this.filter = filter ?? this.filter; this.sort = sort ?? this.sort; this.include = include ?? this.include; this.queries = queries ?? this.queries; const parsedFilter = Object.keys(this.filter).length > 0 ? Object.keys(this.filter).map((key) => `&filter[${key}]=${this.filter[key]}`).join("") : ""; const parsedSort = this.sort.length > 0 ? `&sort=${this.sort.join(",")}` : ""; const parsedInclude = this.include.length > 0 ? `&include=${this.include.join(",")}` : ""; const parsedQueries = Object.keys(this.queries).length > 0 ? `&${Object.keys(this.queries).map((key) => `${key}=${this.queries[key]}`).join("&")}` : ""; try { const response = await this.http.instance.get( `/${this.model}?page=${this.page}&per_page=${this.limit}${parsedFilter}${parsedSort}${parsedInclude}${parsedQueries}` ); return response.data.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async retrieve({ id, handle }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } async similar({ id, handle, limit }) { var _a, _b; try { const response = await this.http.instance.get( `/${this.model}/${id ? id : `handle/${handle}`}/similar${limit ? `?limit=${limit}` : ""} ` ); return response.data; } catch (error) { console.error(`Error fetching ${this.model} details:`, error); return { error: ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message }; } } }; // src/services/shops.ts var ShopService = class { constructor(http) { this.http = http; } model = "shops"; page = 1; limit = 10; filter = {}; sort = []; include = []; queries = {}; async count() { const { data } = await this.http.instance.get(`/${this.model}/count`); return data.count; } async list(props) { var _a, _b; const { page, limit, filter, sort, include, queries } = props || {}; this.page =