genuka-api
Version:
Javascript(TS) Package to use Genuka API for a StoreFront website
1,312 lines (1,290 loc) • 59.5 kB
JavaScript
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.js
var index_exports = {};
__export(index_exports, {
default: () => index_default
});
module.exports = __toCommonJS(index_exports);
// src/lib/axios.js
var import_axios = __toESM(require("axios"), 1);
var import_uuid = require("uuid");
var AxiosConfig = class {
static instance;
static token = null;
static shopId = null;
static companyId = null;
static lang = "en";
static initialize({ version = "2023-11", token = null, adminMode = false }) {
const requestId = (0, import_uuid.v4)();
this.instance = import_axios.default.create({
baseURL: `https://preprod-api.genuka.com/${version}${adminMode ? "/admin" : ""}`,
// baseURL: `http://127.0.0.1:8000/${version}${adminMode ? "/admin" : ""}`,
headers: {
Accept: "application/json",
"Accept-Language": this.lang,
"X-Request-ID": requestId
}
// withCredentials: true,
});
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) {
console.log("Company ID:", this.companyId);
console.log("Request ID:", requestId);
config.headers["X-Company"] = this.companyId;
}
if (this.shopId) {
config.headers["X-Shop"] = this.shopId;
}
return config;
});
}
static setToken(newToken) {
this.token = newToken;
}
static setShopId(newShopId) {
this.shopId = newShopId;
}
static setCompanyId(newCompanyId) {
this.companyId = newCompanyId;
}
static setLang(newLang) {
this.lang = newLang;
}
static get AxiosInstance() {
return this.instance;
}
};
var axios_default = AxiosConfig;
// src/services/addresses.js
var AddressService = class {
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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var ArticleService = class {
model = "articles";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var BlogService = class {
model = "blogs";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var CartService = class {
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 axios_default.AxiosInstance.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.js
var CollectionService = class {
model = "collections";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var CompanyService = class {
async retrieve() {
var _a, _b;
try {
const response = await axios_default.AxiosInstance.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.js
var CustomerService = class {
async register({
first_name,
last_name,
email,
phone,
gender,
password,
password_confirmation
}) {
var _a, _b, _c, _d;
try {
const response = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 };
}
}
};
// src/services/discounts.js
var DiscountService = class {
model = "discounts";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.get(
`/${this.model}/count`
);
return data.count;
}
async retrieve({ id, code }) {
var _a, _b;
try {
const response = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var OrderService = class {
model = "orders";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count(isAdmin = false) {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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) {
var _a, _b;
try {
const response = await axios_default.AxiosInstance.get(
`${isAdmin ? "" : "/customers"}/${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 };
}
}
async create({ isAdmin = false, ...data }) {
var _a, _b, _c, _d;
try {
const response = await axios_default.AxiosInstance.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.js
var DeliveryService = class {
model = "deliveries";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count(isAdmin = false) {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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) {
var _a, _b;
try {
const response = await axios_default.AxiosInstance.get(
`${isAdmin ? "" : "/customers"}/${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 };
}
}
async create({ isAdmin = false, ...data }) {
var _a, _b, _c, _d;
try {
const response = await axios_default.AxiosInstance.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.js
var BillService = class {
model = "bills";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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) {
var _a, _b;
try {
const response = await axios_default.AxiosInstance.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 };
}
}
async create({ ...data }) {
var _a, _b, _c, _d;
try {
const response = await axios_default.AxiosInstance.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.js
var PageService = class {
model = "pages";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var PaymentMethodService = class {
model = "paymentMethods";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var ProductVariantService = class {
model = "productVariants";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var ProductService = class {
productVariantService;
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
constructor() {
this.productVariantService = new ProductVariantService();
}
get variants() {
return this.productVariantService;
}
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var ShippingService = class {
model = "shipping-fees";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var PickupService = class {
model = "pickup-locations";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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.js
var ShopService = class {
model = "shops";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.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 axios_default.AxiosInstance.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 axios_default.AxiosInstance.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/subscriptions.js
var SubscriptionService = class {
model = "subscriptions";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async retrieve({ id }) {
var _a, _b;
try {
const response = await axios_default.AxiosInstance.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 };
}
}
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 axios_default.AxiosInstance.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 };
}
}
};
// src/services/returns.js
var ReturnsService = class {
model = "returns";
page = 1;
limit = 10;
filter = {};
sort = [];
include = [];
queries = {};
async count() {
const { data } = await axios_default.AxiosInstance.get(
`/${this.model}/count`
);
return data.count;
}
async list(props) {
var _a, _b;
con