UNPKG

storenest-commerce

Version:

Complete e-commerce SDK for Storenest platform with React components, multi-language support, secure checkout, and enterprise-grade security

47 lines (46 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getShop = getShop; exports.getCategories = getCategories; exports.getShopPlugins = getShopPlugins; const config_1 = require("./config"); const utils_1 = require("./utils"); async function getHeaders(requestBody) { const apiKey = (0, config_1.getApiKey)(); if (!apiKey) return undefined; const { timestamp, signature, nonce } = await (0, utils_1.generateApiToken)(apiKey, requestBody); return { 'x-api-key': apiKey, 'x-timestamp': timestamp, 'x-signature': signature, 'x-nonce': nonce, 'Content-Type': 'application/json', }; } async function getShop() { const res = await fetch(`${(0, config_1.getApiBaseUrl)()}/shop`, { headers: await getHeaders(), }); if (res.status === 404) return null; if (!res.ok) throw new Error('Failed to fetch shop'); return await res.json(); } async function getCategories() { const res = await fetch(`${(0, config_1.getApiBaseUrl)()}/shop/categories`, { headers: await getHeaders(), }); if (!res.ok) throw new Error('Failed to fetch categories'); return await res.json(); } async function getShopPlugins() { const res = await fetch(`${(0, config_1.getApiBaseUrl)()}/shop/plugins`, { headers: await getHeaders(), }); if (!res.ok) throw new Error('Failed to fetch shop plugins'); return await res.json(); }