@lightspeed/ecom-headless 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/api/index.cjs +1 -1
- package/dist/api/index.cjs.map +1 -1
- package/dist/api/index.d.cts +164 -16
- package/dist/api/index.d.mts +164 -16
- package/dist/api/index.d.ts +164 -16
- package/dist/api/index.mjs +1 -1
- package/dist/api/index.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/plugin-visualizer/bundle.html +1 -1
- package/dist/shared/ecom-headless.DTL4WyVk.d.cts +2824 -0
- package/dist/shared/ecom-headless.DTL4WyVk.d.mts +2824 -0
- package/dist/shared/ecom-headless.DTL4WyVk.d.ts +2824 -0
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/shared/ecom-headless.BaNiBjDE.d.cts +0 -1297
- package/dist/shared/ecom-headless.BaNiBjDE.d.mts +0 -1297
- package/dist/shared/ecom-headless.BaNiBjDE.d.ts +0 -1297
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.0 - 2025-10-06
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add support for REST API :: Categories :: Search categories by path.
|
|
8
|
+
- Add support for REST API :: Products :: Search product variations.
|
|
9
|
+
- Add support for REST API :: Products :: Get product variation.
|
|
10
|
+
- Add support for REST API :: Products :: Search product types.
|
|
11
|
+
- Add support for REST API :: Products :: Get product type.
|
|
12
|
+
- Add support for REST API :: Products :: Search product brands.
|
|
13
|
+
|
|
3
14
|
## 1.0.0 - 2025-09-23
|
|
4
15
|
|
|
5
16
|
### Added
|
package/dist/api/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const getStoreId=require("../shared/ecom-headless.CiGkSfL9.cjs"),API_BASE_URL="https://app.ecwid.com/api/v3/",API_TIMEOUT=1e4;let o;const getApiConfig=()=>{if(o===void 0)throw new Error(getStoreId.ERROR_MESSAGES.CONFIG_NOT_INITIALIZED);return o},initStorefrontApi=async r=>{if(r.publicToken===void 0)throw new Error(getStoreId.ERROR_MESSAGES.CONFIG_PUBLIC_TOKEN_REQUIRED);const e=r.storeId??await getStoreId.getStoreId();if(e===void 0)throw new Error(getStoreId.ERROR_MESSAGES.CONFIG_STORE_ID_NOT_FOUND);o={baseURL:r.baseURL??API_BASE_URL,publicToken:r.publicToken,storeId:e}};class TimeoutError extends Error{constructor(e,n
|
|
1
|
+
"use strict";const getStoreId=require("../shared/ecom-headless.CiGkSfL9.cjs"),API_BASE_URL="https://app.ecwid.com/api/v3/",API_TIMEOUT=1e4;let o;const getApiConfig=()=>{if(o===void 0)throw new Error(getStoreId.ERROR_MESSAGES.CONFIG_NOT_INITIALIZED);return o},initStorefrontApi=async r=>{if(r.publicToken===void 0)throw new Error(getStoreId.ERROR_MESSAGES.CONFIG_PUBLIC_TOKEN_REQUIRED);const e=r.storeId??await getStoreId.getStoreId();if(e===void 0)throw new Error(getStoreId.ERROR_MESSAGES.CONFIG_STORE_ID_NOT_FOUND);o={baseURL:r.baseURL??API_BASE_URL,publicToken:r.publicToken,storeId:e}};class TimeoutError extends Error{constructor(e,s,n){super(`Request timeout${n?` after ${n}ms`:""}${e?` for ${s} ${e}`:""}`),this.name="TimeoutError"}}function createTimeoutError(r,e,s){return new TimeoutError(r,e,s)}function isAbortError(r){return r instanceof Error&&r.name==="AbortError"}function isObject(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function isFetchAvailable(){return typeof globalThis.fetch=="function"}function buildRequestHeaders(r,e={}){return{Authorization:`Bearer ${r}`,"X-Lightspeed-Request-Origin":"ecom-headless",redirect:"follow",...e.headers}}function prepareRequestBody(r,e){if(!(r==="GET"||e===void 0)){if(typeof e=="string")return e;if(isObject(e))return JSON.stringify(e)}}async function parseResponseData(r,e){switch(e){case"json":return r.json();case"blob":return r.blob();default:try{return await r.json()}catch{return r}}}function createTimeoutController(r){if(typeof AbortController>"u")return{};const e=new AbortController,s=setTimeout(()=>{e.abort()},r);return{controller:e,timer:s}}function clearTimeoutController(r){r.timer!==void 0&&clearTimeout(r.timer)}function u(r,e){if(e!==void 0)return`${encodeURIComponent(r)}=${encodeURIComponent(String(e))}`}function a(r){if(r.startsWith("http://")||r.startsWith("https://"))return r;const{baseURL:e}=getApiConfig(),s=e.endsWith("/")?e:e+"/",n=r.startsWith("/")?r.slice(1):r;return s+n}function buildUrlWithParams(r,e){const s=a(r);if(e===void 0)return s;const n=Object.entries(e).map(([c,i])=>u(c,i)).filter(c=>c!==void 0);return n.length>0?`${s}?${n.join("&")}`:s}function createClient(){const{publicToken:r}=getApiConfig();async function e(s,n,c,i){const d=c?.timeout??API_TIMEOUT,l=createTimeoutController(d);try{const p=buildRequestHeaders(r,c),h=buildUrlWithParams(n,c?.params),f=await fetch(h,{method:s,headers:p,body:prepareRequestBody(s,i),signal:l.controller?.signal}),g=await parseResponseData(f,c?.responseType);return Object.assign(f,{data:g})}catch(p){throw isAbortError(p)?createTimeoutError(n,s,d):p}finally{clearTimeoutController(l)}}return{get:(s,n)=>e("GET",s,n),post:(s,n,c)=>e("POST",s,c,n),put:(s,n,c)=>e("PUT",s,c,n),patch:(s,n,c)=>e("PATCH",s,c,n),delete:(s,n)=>e("DELETE",s,n)}}let t;function getApiClient(){if(t!==void 0)return t;if(!isFetchAvailable())throw new Error(getStoreId.ERROR_MESSAGES.FETCH_API_NOT_AVAILABLE);return t=createClient(),t}const searchCategories=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),n={params:r},c=`${s}/categories`;return(await e.get(c,n)).data},searchCategoriesByPath=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),n={params:r},c=`${s}/categoriesByPath`;return(await e.get(c,n)).data},searchProducts=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),n={params:r},c=`${s}/products`;return(await e.get(c,n)).data},getProduct=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),{productId:n}=r,c={params:r},i=`${s}/products/${n}`;return(await e.get(i,c)).data},downloadProductFile=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),{productId:n,fileId:c}=r,i={responseType:"blob"},d=`${s}/products/${n}/files/${c}`;return(await e.get(d,i)).data},searchProductVariations=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),{productId:n}=r,c={params:r},i=`${s}/products/${n}/combinations`;return(await e.get(i,c)).data},getProductVariation=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),{productId:n,combinationId:c}=r,i={params:r},d=`${s}/products/${n}/combinations/${c}`;return(await e.get(d,i)).data},searchProductTypes=async()=>{const r=getApiClient(),{storeId:e}=getApiConfig(),s=`${e}/classes`;return(await r.get(s)).data},getProductType=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),n={params:r},c=`${s}/classes/${r.classId}`;return(await e.get(c,n)).data},searchProductBrands=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),n={params:r},c=`${s}/brands`;return(await e.get(c,n)).data},getStoreProfile=async r=>{const e=getApiClient(),{storeId:s}=getApiConfig(),n={params:r},c=`${s}/profile`;return(await e.get(c,n)).data};exports.downloadProductFile=downloadProductFile;exports.getApiConfig=getApiConfig;exports.getProduct=getProduct;exports.getProductType=getProductType;exports.getProductVariation=getProductVariation;exports.getStoreProfile=getStoreProfile;exports.initStorefrontApi=initStorefrontApi;exports.searchCategories=searchCategories;exports.searchCategoriesByPath=searchCategoriesByPath;exports.searchProductBrands=searchProductBrands;exports.searchProductTypes=searchProductTypes;exports.searchProductVariations=searchProductVariations;exports.searchProducts=searchProducts;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/api/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/api/config/constants.ts","../../src/api/config/index.ts","../../src/client/utils/errors.ts","../../src/client/utils/is-object.ts","../../src/client/utils/request.ts","../../src/client/utils/response.ts","../../src/client/utils/timeout.ts","../../src/client/utils/url.ts","../../src/client/create-client.ts","../../src/client/index.ts","../../src/api/categories/search-categories.ts","../../src/api/products/search-products.ts","../../src/api/products/get-product.ts","../../src/api/products/download-product-file.ts","../../src/api/store/get-store-profile.ts"],"sourcesContent":["export const API_BASE_URL = 'https://app.ecwid.com/api/v3/';\nexport const API_TIMEOUT = 10000;\n","import { API_BASE_URL } from '@/api/config/constants';\nimport { ERROR_MESSAGES } from '@/client/constants';\nimport { getStoreId } from '@/storefront';\nimport { ApiConfig } from '@/types';\n\nlet apiConfig: Required<ApiConfig> | undefined;\n\nexport const getApiConfig = (): Required<ApiConfig> => {\n if (apiConfig === undefined) {\n throw new Error(ERROR_MESSAGES.CONFIG_NOT_INITIALIZED);\n }\n return apiConfig;\n};\n\nexport const initStorefrontApi = async (config: ApiConfig): Promise<void> => {\n if (config.publicToken === undefined) {\n throw new Error(ERROR_MESSAGES.CONFIG_PUBLIC_TOKEN_REQUIRED);\n }\n\n const storeId = config.storeId ?? await getStoreId();\n if (storeId === undefined) {\n throw new Error(ERROR_MESSAGES.CONFIG_STORE_ID_NOT_FOUND);\n }\n\n apiConfig = {\n baseURL: config.baseURL ?? API_BASE_URL,\n publicToken: config.publicToken,\n storeId,\n } satisfies Required<ApiConfig>;\n};\n","export class TimeoutError extends Error {\n constructor(url?: string, method?: string, timeout?: number) {\n super(\n `Request timeout${timeout ? ` after ${timeout}ms` : ''}${url ? ` for ${method} ${url}` : ''}`,\n );\n this.name = 'TimeoutError';\n }\n}\n\nexport function createTimeoutError(url?: string, method?: string, timeout?: number): TimeoutError {\n return new TimeoutError(url, method, timeout);\n}\n\nexport function isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n","export function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","import { isObject } from '@/client/utils';\nimport { BaseHeaders, RequestConfig, RequestData } from '@/types';\n\nexport function isFetchAvailable(): boolean {\n return typeof globalThis.fetch === 'function';\n}\n\nexport function buildRequestHeaders(\n publicToken: string,\n config: RequestConfig = {},\n): Record<string, string> & BaseHeaders {\n return {\n 'Authorization': `Bearer ${publicToken}`,\n 'X-Lightspeed-Request-Origin': 'ecom-headless',\n 'redirect': 'follow',\n ...config.headers,\n };\n}\n\nexport function prepareRequestBody(\n method: string,\n data: RequestData,\n): BodyInit | undefined {\n if (method === 'GET' || data === undefined) {\n return undefined;\n }\n\n if (typeof data === 'string') {\n return data;\n }\n\n if (isObject(data)) {\n return JSON.stringify(data);\n }\n\n return undefined;\n}\n","import { ResponseType } from '@/types';\n\nexport async function parseResponseData(\n response: Response,\n responseType?: ResponseType,\n): Promise<ReturnType<typeof response.json> | ReturnType<typeof response.blob> | Response> {\n switch (responseType) {\n case 'json':\n return response.json();\n case 'blob':\n return response.blob();\n default:\n try {\n return await response.json();\n } catch {\n return response;\n }\n }\n}\n","interface TimeoutController {\n controller?: AbortController;\n timer?: ReturnType<typeof setTimeout>;\n}\n\nexport function createTimeoutController(timeout: number): {\n controller?: AbortController;\n timer?: ReturnType<typeof setTimeout>;\n} {\n if (typeof AbortController === 'undefined') {\n return {};\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => {\n controller.abort();\n }, timeout);\n\n return { controller, timer };\n}\n\nexport function clearTimeoutController(timeoutController: TimeoutController): void {\n if (timeoutController.timer !== undefined) {\n clearTimeout(timeoutController.timer);\n }\n}\n","import { getApiConfig } from '@/api';\nimport { QueryParams } from '@/types';\n\nfunction processQueryParam(\n key: string,\n value: QueryParams[string],\n): string | undefined {\n if (value === undefined) {\n return;\n }\n\n return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`;\n}\n\nfunction createUrl(path: string): string {\n if (path.startsWith('http://') || path.startsWith('https://')) {\n return path;\n }\n\n const { baseURL } = getApiConfig();\n const normalizedBase = baseURL.endsWith('/') ? baseURL : baseURL + '/';\n const normalizedPath = path.startsWith('/') ? path.slice(1) : path;\n\n return normalizedBase + normalizedPath;\n}\n\nexport function buildUrlWithParams(path: string, params?: QueryParams): string {\n const url = createUrl(path);\n\n if (params === undefined) {\n return url;\n }\n\n const queryParams = Object\n .entries(params)\n .map(([key, value]) => processQueryParam(key, value))\n .filter((param): param is string => param !== undefined);\n\n if (queryParams.length > 0) {\n return `${url}?${queryParams.join('&')}`;\n }\n\n return url;\n}\n","import { getApiConfig } from '@/api/config';\nimport { API_TIMEOUT } from '@/api/config/constants';\nimport {\n buildRequestHeaders,\n buildUrlWithParams,\n clearTimeoutController,\n createTimeoutController,\n createTimeoutError,\n isAbortError,\n parseResponseData,\n prepareRequestBody,\n} from '@/client/utils';\nimport { HttpClient, RequestConfig, RequestData, HttpResponse } from '@/types';\n\nexport function createClient(): HttpClient {\n const { publicToken } = getApiConfig();\n\n async function request<T = unknown>(\n method: string,\n path: string,\n config?: RequestConfig,\n requestData?: RequestData,\n ): Promise<HttpResponse<T>> {\n const timeout = config?.timeout ?? API_TIMEOUT;\n const timeoutController = createTimeoutController(timeout);\n\n try {\n const headers = buildRequestHeaders(publicToken, config);\n const finalUrl = buildUrlWithParams(path, config?.params);\n\n const response = await fetch(finalUrl, {\n method,\n headers,\n body: prepareRequestBody(method, requestData),\n signal: timeoutController.controller?.signal,\n });\n\n const parsedResponseData = await parseResponseData(response, config?.responseType);\n\n return Object.assign(response, {\n data: parsedResponseData,\n }) satisfies HttpResponse<T>;\n } catch (error) {\n if (isAbortError(error)) {\n throw createTimeoutError(path, method, timeout);\n }\n\n throw error;\n } finally {\n clearTimeoutController(timeoutController);\n }\n }\n\n return {\n get: <T>(url: string, config?: RequestConfig) => request<T>('GET', url, config),\n post: <T>(url: string, data?: RequestData, config?: RequestConfig) => request<T>('POST', url, config, data),\n put: <T>(url: string, data?: RequestData, config?: RequestConfig) => request<T>('PUT', url, config, data),\n patch: <T>(url: string, data?: RequestData, config?: RequestConfig) => request<T>('PATCH', url, config, data),\n delete: <T>(url: string, config?: RequestConfig) => request<T>('DELETE', url, config),\n };\n}\n","import { ERROR_MESSAGES } from '@/client/constants';\nimport { createClient } from '@/client/create-client';\nimport { isFetchAvailable } from '@/client/utils';\nimport { HttpClient } from '@/types';\n\nlet client: HttpClient | undefined;\n\n/**\n * Get the singleton instance of the API client.\n * @returns The HTTP client instance\n * @throws {Error} If the fetch API is not available or client creation fails\n */\nexport function getApiClient(): HttpClient {\n if (client !== undefined) {\n return client;\n }\n\n if (!isFetchAvailable()) {\n throw new Error(ERROR_MESSAGES.FETCH_API_NOT_AVAILABLE);\n }\n\n client = createClient();\n\n return client;\n}\n\n/**\n * Reset the singleton API client instance.\n * Useful for testing or when configuration changes require a fresh client.\n */\nexport function resetApiClient(): void {\n client = undefined;\n}\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchCategoriesParams, SearchCategoriesResponse, RequestConfig } from '@/types';\n\n/**\n * Search categories in the store based on provided parameters.\n *\n * @param {SearchCategoriesParams} params - The parameters for the searchCategories request.\n * @returns {Promise<SearchCategoriesResponse>} A promise that resolves to the categories search results.\n */\nexport const searchCategories = async (\n params?: SearchCategoriesParams,\n): Promise<SearchCategoriesResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<SearchCategoriesParams> = {\n params,\n };\n\n const url = `${storeId}/categories`;\n const response = await apiClient.get<SearchCategoriesResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchProductsParams, SearchProductsResponse, RequestConfig } from '@/types';\n\n/**\n * Search for products.\n *\n * @param {SearchProductsParams} params - The parameters for the searchProducts request.\n * @returns {Promise<SearchProductsResponse>} A promise that resolves to the search results.\n */\nexport const searchProducts = async (\n params?: SearchProductsParams,\n): Promise<SearchProductsResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<SearchProductsParams> = {\n params,\n };\n\n const url = `${storeId}/products`;\n const response = await apiClient.get<SearchProductsResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { GetProductParams, GetProductResponse, RequestConfig } from '@/types';\n\n/**\n * Fetches a single product by its ID.\n *\n * @param {GetProductParams} params - The parameters for the getProduct request.\n * @returns {Promise<GetProductResponse>} A promise that resolves to the product details.\n */\nexport const getProduct = async (\n params: GetProductParams,\n): Promise<GetProductResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const { productId } = params;\n const options: RequestConfig<GetProductParams> = {\n params,\n };\n\n const url = `${storeId}/products/${productId}`;\n const response = await apiClient.get<GetProductResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { DownloadProductFileParams, DownloadProductFileResponse, RequestConfig } from '@/types';\n\n/**\n * Download a product file\n * @param {DownloadProductFileParams} params - The parameters for the downloadProductFile request.\n * @returns {Promise<DownloadProductFileResponse>} A promise that resolves to the download product file results.\n */\nexport const downloadProductFile = async (\n params: DownloadProductFileParams,\n): Promise<DownloadProductFileResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const { productId, fileId } = params;\n const options: RequestConfig<DownloadProductFileParams> = {\n responseType: 'blob',\n };\n\n const url = `${storeId}/products/${productId}/files/${fileId}`;\n const response = await apiClient.get<DownloadProductFileResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { GetStoreProfileParams, GetStoreProfileResponse, RequestConfig } from '@/types';\n\n/**\n * Fetches the store profile.\n *\n * @param {GetStoreProfileParams} params - Optional parameters for the getStoreProfile request.\n * @returns {Promise<GetStoreProfileResponse>} A promise that resolves to the store profile.\n */\nexport const getStoreProfile = async (\n params?: GetStoreProfileParams,\n): Promise<GetStoreProfileResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<GetStoreProfileParams> = {\n params,\n };\n\n const url = `${storeId}/profile`;\n const response = await apiClient.get<GetStoreProfileResponse>(url, options);\n return response.data;\n};\n"],"names":["apiConfig","ERROR_MESSAGES","config","storeId","getStoreId","API_BASE_URL","url","method","timeout","error","value","publicToken","data","isObject","response","responseType","controller","timer","timeoutController","processQueryParam","key","createUrl","path","baseURL","getApiConfig","normalizedBase","normalizedPath","params","queryParams","param","request","requestData","API_TIMEOUT","createTimeoutController","headers","buildRequestHeaders","finalUrl","buildUrlWithParams","prepareRequestBody","parsedResponseData","parseResponseData","isAbortError","createTimeoutError","clearTimeoutController","client","isFetchAvailable","createClient","apiClient","getApiClient","options","productId","fileId"],"mappings":"8EAAa,aAAe,gCACf,YAAc,ICI3B,IAAIA,QAES,aAAe,IAA2B,CACrD,GAAIA,IAAc,OAChB,MAAM,IAAI,MAAMC,WAAe,eAAA,sBAAsB,EAEvD,OAAOD,CACT,EAEa,kBAAoB,MAAOE,GAAqC,CAC3E,GAAIA,EAAO,cAAgB,OACzB,MAAM,IAAI,MAAMD,WAAAA,eAAe,4BAA4B,EAG7D,MAAME,EAAUD,EAAO,SAAW,MAAME,WAAW,WAAA,EACnD,GAAID,IAAY,OACd,MAAM,IAAI,MAAMF,WAAAA,eAAe,yBAAyB,EAG1DD,EAAY,CACV,QAASE,EAAO,SAAWG,aAC3B,YAAaH,EAAO,YACpB,QAAAC,CACF,CACF,EC7Ba,MAAA,qBAAqB,KAAM,CACtC,YAAYG,EAAcC,EAAiBC,EAAkB,CAC3D,MACE,kBAAkBA,EAAU,UAAUA,CAAO,KAAO,EAAE,GAAGF,EAAM,QAAQC,CAAM,IAAID,CAAG,GAAK,EAAE,EAC7F,EACA,KAAK,KAAO,cACd,CACF,CAEO,SAAS,mBAAmBA,EAAcC,EAA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AAIvB,EAChBsB,EAA2C,CAC/C,OAAAtB,CACF,EAEMrB,EAAM,GAAGH,CAAO,aAAa+C,CAAS,GAE5C,OADiB,MAAMH,EAAU,IAAwBzC,EAAK2C,CAAO,GACrD,IAClB,ECda,oBAAsB,MACjCtB,GACyC,CACzC,MAAMoB,EAAYC,eACZ,CAAE,QAAA7C,CAAQ,EAAIqB,aAAa,EAC3B,CAAE,UAAA0B,EAAW,OAAAC,CAAO,EAAIxB,EACxBsB,EAAoD,CACxD,aAAc,MAChB,EAEM3C,EAAM,GAAGH,CAAO,aAAa+C,CAAS,UAAUC,CAAM,GAE5D,OADiB,MAAMJ,EAAU,IAAiCzC,EAAK2C,CAAO,GAC9D,IAClB,ECZa,gBAAkB,MAC7BtB,GACqC,CACrC,MAAMoB,EAAYC,aAAa,EACzB,CAAE,QAAA7C,CAAQ,EAAIqB,eACdyB,EAAgD,CACpD,OAAAtB,CACF,EAEMrB,EAAM,GAAGH,CAAO,WAEtB,OADiB,MAAM4C,EAAU,IAA6BzC,EAAK2C,CAAO,GAC1D,IAClB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/api/config/constants.ts","../../src/api/config/index.ts","../../src/client/utils/errors.ts","../../src/client/utils/is-object.ts","../../src/client/utils/request.ts","../../src/client/utils/response.ts","../../src/client/utils/timeout.ts","../../src/client/utils/url.ts","../../src/client/create-client.ts","../../src/client/index.ts","../../src/api/categories/search-categories.ts","../../src/api/categories/search-categories-by-path.ts","../../src/api/products/search-products.ts","../../src/api/products/get-product.ts","../../src/api/products/download-product-file.ts","../../src/api/products/search-product-variations.ts","../../src/api/products/get-product-variation.ts","../../src/api/products/search-product-types.ts","../../src/api/products/get-product-type.ts","../../src/api/products/search-product-brands.ts","../../src/api/store/get-store-profile.ts"],"sourcesContent":["export const API_BASE_URL = 'https://app.ecwid.com/api/v3/';\nexport const API_TIMEOUT = 10000;\n","import { API_BASE_URL } from '@/api/config/constants';\nimport { ERROR_MESSAGES } from '@/client/constants';\nimport { getStoreId } from '@/storefront';\nimport { ApiConfig } from '@/types';\n\nlet apiConfig: Required<ApiConfig> | undefined;\n\n/**\n * Get the API configuration.\n *\n * @example\n * ```typescript\n * import { getApiConfig, ApiConfig } from '@lightspeed/ecom-headless';\n *\n * const config: ApiConfig = getApiConfig();\n * ```\n */\nexport const getApiConfig = (): Required<ApiConfig> => {\n if (apiConfig === undefined) {\n throw new Error(ERROR_MESSAGES.CONFIG_NOT_INITIALIZED);\n }\n\n return apiConfig;\n};\n\n/**\n * Initialize the Storefront API client.\n *\n * @example\n * ```typescript\n * import { initStorefrontApi } from '@lightspeed/ecom-headless';\n *\n * await initStorefrontApi({\n * publicToken: 'YOUR_PUBLIC_TOKEN',\n * storeId: 'YOUR_STORE_ID'\n * });\n * ```\n *\n * @remarks\n * - This method must be called before using any other API methods.\n * - If storeId is not provided, it will be auto-detected. If detection fails, an error will be thrown.\n */\nexport const initStorefrontApi = async (config: ApiConfig): Promise<void> => {\n if (config.publicToken === undefined) {\n throw new Error(ERROR_MESSAGES.CONFIG_PUBLIC_TOKEN_REQUIRED);\n }\n\n const storeId = config.storeId ?? await getStoreId();\n\n if (storeId === undefined) {\n throw new Error(ERROR_MESSAGES.CONFIG_STORE_ID_NOT_FOUND);\n }\n\n apiConfig = {\n baseURL: config.baseURL ?? API_BASE_URL,\n publicToken: config.publicToken,\n storeId,\n } satisfies Required<ApiConfig>;\n};\n","export class TimeoutError extends Error {\n constructor(url?: string, method?: string, timeout?: number) {\n super(\n `Request timeout${timeout ? ` after ${timeout}ms` : ''}${url ? ` for ${method} ${url}` : ''}`,\n );\n this.name = 'TimeoutError';\n }\n}\n\nexport function createTimeoutError(url?: string, method?: string, timeout?: number): TimeoutError {\n return new TimeoutError(url, method, timeout);\n}\n\nexport function isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n","export function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n","import { isObject } from '@/client/utils';\nimport { BaseHeaders, RequestConfig, RequestData } from '@/types';\n\nexport function isFetchAvailable(): boolean {\n return typeof globalThis.fetch === 'function';\n}\n\nexport function buildRequestHeaders(\n publicToken: string,\n config: RequestConfig = {},\n): Record<string, string> & BaseHeaders {\n return {\n 'Authorization': `Bearer ${publicToken}`,\n 'X-Lightspeed-Request-Origin': 'ecom-headless',\n 'redirect': 'follow',\n ...config.headers,\n };\n}\n\nexport function prepareRequestBody(\n method: string,\n data: RequestData,\n): BodyInit | undefined {\n if (method === 'GET' || data === undefined) {\n return undefined;\n }\n\n if (typeof data === 'string') {\n return data;\n }\n\n if (isObject(data)) {\n return JSON.stringify(data);\n }\n\n return undefined;\n}\n","import { ResponseType } from '@/types';\n\nexport async function parseResponseData(\n response: Response,\n responseType?: ResponseType,\n): Promise<ReturnType<typeof response.json> | ReturnType<typeof response.blob> | Response> {\n switch (responseType) {\n case 'json':\n return response.json();\n case 'blob':\n return response.blob();\n default:\n try {\n return await response.json();\n } catch {\n return response;\n }\n }\n}\n","interface TimeoutController {\n controller?: AbortController;\n timer?: ReturnType<typeof setTimeout>;\n}\n\nexport function createTimeoutController(timeout: number): {\n controller?: AbortController;\n timer?: ReturnType<typeof setTimeout>;\n} {\n if (typeof AbortController === 'undefined') {\n return {};\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => {\n controller.abort();\n }, timeout);\n\n return { controller, timer };\n}\n\nexport function clearTimeoutController(timeoutController: TimeoutController): void {\n if (timeoutController.timer !== undefined) {\n clearTimeout(timeoutController.timer);\n }\n}\n","import { getApiConfig } from '@/api';\nimport { QueryParams } from '@/types';\n\nfunction processQueryParam(\n key: string,\n value: QueryParams[string],\n): string | undefined {\n if (value === undefined) {\n return;\n }\n\n return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`;\n}\n\nfunction createUrl(path: string): string {\n if (path.startsWith('http://') || path.startsWith('https://')) {\n return path;\n }\n\n const { baseURL } = getApiConfig();\n const normalizedBase = baseURL.endsWith('/') ? baseURL : baseURL + '/';\n const normalizedPath = path.startsWith('/') ? path.slice(1) : path;\n\n return normalizedBase + normalizedPath;\n}\n\nexport function buildUrlWithParams(path: string, params?: QueryParams): string {\n const url = createUrl(path);\n\n if (params === undefined) {\n return url;\n }\n\n const queryParams = Object\n .entries(params)\n .map(([key, value]) => processQueryParam(key, value))\n .filter((param): param is string => param !== undefined);\n\n if (queryParams.length > 0) {\n return `${url}?${queryParams.join('&')}`;\n }\n\n return url;\n}\n","import { getApiConfig } from '@/api/config';\nimport { API_TIMEOUT } from '@/api/config/constants';\nimport {\n buildRequestHeaders,\n buildUrlWithParams,\n clearTimeoutController,\n createTimeoutController,\n createTimeoutError,\n isAbortError,\n parseResponseData,\n prepareRequestBody,\n} from '@/client/utils';\nimport { HttpClient, RequestConfig, RequestData, HttpResponse } from '@/types';\n\nexport function createClient(): HttpClient {\n const { publicToken } = getApiConfig();\n\n async function request<T = unknown>(\n method: string,\n path: string,\n config?: RequestConfig,\n requestData?: RequestData,\n ): Promise<HttpResponse<T>> {\n const timeout = config?.timeout ?? API_TIMEOUT;\n const timeoutController = createTimeoutController(timeout);\n\n try {\n const headers = buildRequestHeaders(publicToken, config);\n const finalUrl = buildUrlWithParams(path, config?.params);\n\n const response = await fetch(finalUrl, {\n method,\n headers,\n body: prepareRequestBody(method, requestData),\n signal: timeoutController.controller?.signal,\n });\n\n const parsedResponseData = await parseResponseData(response, config?.responseType);\n\n return Object.assign(response, {\n data: parsedResponseData,\n }) satisfies HttpResponse<T>;\n } catch (error) {\n if (isAbortError(error)) {\n throw createTimeoutError(path, method, timeout);\n }\n\n throw error;\n } finally {\n clearTimeoutController(timeoutController);\n }\n }\n\n return {\n get: <T>(url: string, config?: RequestConfig) => request<T>('GET', url, config),\n post: <T>(url: string, data?: RequestData, config?: RequestConfig) => request<T>('POST', url, config, data),\n put: <T>(url: string, data?: RequestData, config?: RequestConfig) => request<T>('PUT', url, config, data),\n patch: <T>(url: string, data?: RequestData, config?: RequestConfig) => request<T>('PATCH', url, config, data),\n delete: <T>(url: string, config?: RequestConfig) => request<T>('DELETE', url, config),\n };\n}\n","import { ERROR_MESSAGES } from '@/client/constants';\nimport { createClient } from '@/client/create-client';\nimport { isFetchAvailable } from '@/client/utils';\nimport { HttpClient } from '@/types';\n\nlet client: HttpClient | undefined;\n\n/**\n * Get the singleton instance of the API client.\n * @returns The HTTP client instance\n * @throws {Error} If the fetch API is not available or client creation fails\n */\nexport function getApiClient(): HttpClient {\n if (client !== undefined) {\n return client;\n }\n\n if (!isFetchAvailable()) {\n throw new Error(ERROR_MESSAGES.FETCH_API_NOT_AVAILABLE);\n }\n\n client = createClient();\n\n return client;\n}\n\n/**\n * Reset the singleton API client instance.\n * Useful for testing or when configuration changes require a fresh client.\n */\nexport function resetApiClient(): void {\n client = undefined;\n}\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchCategoriesParams, SearchCategoriesResponse, RequestConfig } from '@/types';\n\n/**\n * Search categories in the store based on provided parameters.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/categories/search-categories | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { searchCategories, SearchCategoriesResponse } from '@lightspeed/ecom-headless';\n *\n * const categories: SearchCategoriesResponse = await searchCategories();\n * ```\n */\nexport const searchCategories = async (\n params?: SearchCategoriesParams,\n): Promise<SearchCategoriesResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<SearchCategoriesParams> = {\n params,\n };\n\n const url = `${storeId}/categories`;\n const response = await apiClient.get<SearchCategoriesResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchCategoriesByPathParams, SearchCategoriesByPathResponse, RequestConfig } from '@/types';\n\n/**\n * Search categories by path using a delimiter-separated path string.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/categories/search-categories-by-path | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { searchCategoriesByPath, SearchCategoriesByPathResponse } from '@lightspeed/ecom-headless';\n *\n * const categories: SearchCategoriesByPathResponse = await searchCategoriesByPath({\n * path: \"Electronics/Phones/Smartphones\",\n * delimiter: \"/\"\n * });\n * ```\n */\nexport const searchCategoriesByPath = async (\n params: SearchCategoriesByPathParams,\n): Promise<SearchCategoriesByPathResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<SearchCategoriesByPathParams> = {\n params,\n };\n\n const url = `${storeId}/categoriesByPath`;\n const response = await apiClient.get<SearchCategoriesByPathResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchProductsParams, SearchProductsResponse, RequestConfig } from '@/types';\n\n/**\n * Search for products in a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/search-products | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { searchProducts, SearchProductsResponse } from '@lightspeed/ecom-headless';\n *\n * const products: SearchProductsResponse = await searchProducts({ keyword: 'laptop' });\n * ```\n */\nexport const searchProducts = async (\n params?: SearchProductsParams,\n): Promise<SearchProductsResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<SearchProductsParams> = {\n params,\n };\n\n const url = `${storeId}/products`;\n const response = await apiClient.get<SearchProductsResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { GetProductParams, GetProductResponse, RequestConfig } from '@/types';\n\n/**\n * Get a product from a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/get-product | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { getProduct, GetProductResponse } from '@lightspeed/ecom-headless';\n *\n * const product: GetProductResponse = await getProduct({ productId: 123 });\n * ```\n */\nexport const getProduct = async (\n params: GetProductParams,\n): Promise<GetProductResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const { productId } = params;\n const options: RequestConfig<GetProductParams> = {\n params,\n };\n\n const url = `${storeId}/products/${productId}`;\n const response = await apiClient.get<GetProductResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { DownloadProductFileParams, DownloadProductFileResponse, RequestConfig } from '@/types';\n\n/**\n * Download a product file from a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-files/download-product-file | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { downloadProductFile, DownloadProductFileResponse } from '@lightspeed/ecom-headless';\n *\n * const file: DownloadProductFileResponse = await downloadProductFile({ productId: 123, fileId: 456 });\n * ```\n */\nexport const downloadProductFile = async (\n params: DownloadProductFileParams,\n): Promise<DownloadProductFileResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const { productId, fileId } = params;\n const options: RequestConfig<DownloadProductFileParams> = {\n responseType: 'blob',\n };\n\n const url = `${storeId}/products/${productId}/files/${fileId}`;\n const response = await apiClient.get<DownloadProductFileResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchProductVariationsParams, SearchProductVariationsResponse, RequestConfig } from '@/types';\n\n/**\n * Search for product variations in a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-variations/search-product-variations | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { searchProductVariations, SearchProductVariationsResponse } from '@lightspeed/ecom-headless';\n *\n * const variations: SearchProductVariationsResponse = await searchProductVariations({ productId: 123 });\n * ```\n */\nexport const searchProductVariations = async (\n params: SearchProductVariationsParams,\n): Promise<SearchProductVariationsResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const { productId } = params;\n const options: RequestConfig<SearchProductVariationsParams> = {\n params,\n };\n\n const url = `${storeId}/products/${productId}/combinations`;\n const response = await apiClient.get<SearchProductVariationsResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { GetProductVariationParams, GetProductVariationResponse, RequestConfig } from '@/types';\n\n/**\n * Get a product variation from a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-variations/get-product-variation | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { getProductVariation, GetProductVariationResponse } from '@lightspeed/ecom-headless';\n *\n * const variation: GetProductVariationResponse = await getProductVariation({\n * productId: 123,\n * combinationId: 456\n * });\n * ```\n */\nexport const getProductVariation = async (\n params: GetProductVariationParams,\n): Promise<GetProductVariationResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const { productId, combinationId } = params;\n const options: RequestConfig<GetProductVariationParams> = {\n params,\n };\n\n const url = `${storeId}/products/${productId}/combinations/${combinationId}`;\n const response = await apiClient.get<GetProductVariationResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchProductTypesResponse } from '@/types';\n\n/**\n * Search for product types in a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-types-and-attributes/search-product-types | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { searchProductTypes, SearchProductTypesResponse } from '@lightspeed/ecom-headless';\n *\n * const productTypes: SearchProductTypesResponse = await searchProductTypes();\n * ```\n */\nexport const searchProductTypes = async (): Promise<SearchProductTypesResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n\n const url = `${storeId}/classes`;\n const response = await apiClient.get<SearchProductTypesResponse>(url);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { GetProductTypeParams, GetProductTypeResponse, RequestConfig } from '@/types';\n\n/**\n * Get a product type from a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-types-and-attributes/get-product-type | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { getProductType, GetProductTypeResponse } from '@lightspeed/ecom-headless';\n *\n * const productType: GetProductTypeResponse = await getProductType({ classId: 0 });\n * ```\n */\nexport const getProductType = async (\n params: GetProductTypeParams,\n): Promise<GetProductTypeResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<GetProductTypeParams> = {\n params,\n };\n\n const url = `${storeId}/classes/${params.classId}`;\n const response = await apiClient.get<GetProductTypeResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { SearchProductBrandsParams, SearchProductBrandsResponse, RequestConfig } from '@/types';\n\n/**\n * Search for product brands in a store.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/products/search-product-brands | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { searchProductBrands, SearchProductBrandsResponse } from '@lightspeed/ecom-headless';\n *\n * const brands: SearchProductBrandsResponse = await searchProductBrands({ limit: 10 });\n * ```\n */\nexport const searchProductBrands = async (\n params?: SearchProductBrandsParams,\n): Promise<SearchProductBrandsResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<SearchProductBrandsParams> = {\n params,\n };\n\n const url = `${storeId}/brands`;\n const response = await apiClient.get<SearchProductBrandsResponse>(url, options);\n return response.data;\n};\n","import { getApiConfig } from '@/api/config';\nimport { getApiClient } from '@/client';\nimport { GetStoreProfileParams, GetStoreProfileResponse, RequestConfig } from '@/types';\n\n/**\n * Get basic information about an Ecwid store: settings, store location, email, etc.\n *\n * @see {@link https://docs.ecwid.com/api-reference/rest-api/store-profile/get-store-profile | Ecwid API Documentation}\n *\n * @example\n * ```typescript\n * import { getStoreProfile, GetStoreProfileResponse } from '@lightspeed/ecom-headless';\n *\n * const profile: GetStoreProfileResponse = await getStoreProfile();\n * ```\n */\nexport const getStoreProfile = async (\n params?: GetStoreProfileParams,\n): Promise<GetStoreProfileResponse> => {\n const apiClient = getApiClient();\n const { storeId } = getApiConfig();\n const options: RequestConfig<GetStoreProfileParams> = {\n params,\n };\n\n const url = `${storeId}/profile`;\n const response = await apiClient.get<GetStoreProfileResponse>(url, options);\n return response.data;\n};\n"],"names":["apiConfig","ERROR_MESSAGES","config","storeId","getStoreId","API_BASE_URL","url","method","timeout","error","value","publicToken","data","isObject","response","responseType","controller","timer","timeoutController","processQueryParam","key","createUrl","path","baseURL","getApiConfig","normalizedBase","normalizedPath","params","queryParams","param","request","requestData","API_TIMEOUT","createTimeoutController","headers","buildRequestHeaders","finalUrl","buildUrlWithParams","prepareRequestBody","parsedResponseData","parseResponseData","isAbortError","createTimeoutError","clearTimeoutController","client","isFetchAvailable","createClient","apiClient","getApiClient","options","productId","fileId","combinationId"],"mappings":"8EAAa,aAAe,gCACf,YAAc,ICI3B,IAAIA,QAYS,aAAe,IAA2B,CACrD,GAAIA,IAAc,OAChB,MAAM,IAAI,MAAMC,WAAe,eAAA,sBAAsB,EAGvD,OAAOD,CACT,EAmBa,kBAAoB,MAAOE,GAAqC,CAC3E,GAAIA,EAAO,cAAgB,OACzB,MAAM,IAAI,MAAMD,WAAAA,eAAe,4BAA4B,EAG7D,MAAME,EAAUD,EAAO,SAAW,MAAME,WAAW,WAAA,EAEnD,GAAID,IAAY,OACd,MAAM,IAAI,MAAMF,WAAAA,eAAe,yBAAyB,EAG1DD,EAAY,CACV,QAASE,EAAO,SAAWG,aAC3B,YAAaH,EAAO,YACpB,QAAAC,CACF,CACF,EC1Da,MAAA,qBAAqB,KAAM,CACtC,YAAYG,EAAcC,EAAiBC,EAAkB,CAC3D,MACE,kBAAkBA,EAAU,UAAUA,CAAO,KAAO,EAAE,GAAGF,EAAM,QAAQC,CAAM,IAAID,CAAG,GAAK,EAAE,EAC7F,EACA,KAAK,KAAO,cACd,CACF,CAEO,SAAS,mBAAmBA,EAAcC,EAAiBC,EAAgC,CAChG,OAAO,IAAI,aAAaF,EAAKC,EAAQC,CAAO,CAC9C,CAEO,SAAS,aAAaC,EAAyB,CACpD,OAAOA,aAAiB,OAASA,EAAM,OAAS,YAClD,CCfO,SAAS,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C,EAAU,IAAgCzC,CAAG,GACpD,IAClB,ECPa,eAAiB,MAC5BqB,GACoC,CACpC,MAAMoB,EAAYC,aACZ,EAAA,CAAE,QAAA7C,CAAQ,EAAIqB,aAAa,EAC3ByB,EAA+C,CACnD,OAAAtB,CACF,EAEMrB,EAAM,GAAGH,CAAO,YAAYwB,EAAO,OAAO,GAEhD,OADiB,MAAMoB,EAAU,IAA4BzC,EAAK2C,CAAO,GACzD,IAClB,ECZa,oBAAsB,MACjCtB,GACyC,CACzC,MAAMoB,EAAYC,aAAa,EACzB,CAAE,QAAA7C,CAAQ,EAAIqB,eACdyB,EAAoD,CACxD,OAAAtB,CACF,EAEMrB,EAAM,GAAGH,CAAO,UAEtB,OADiB,MAAM4C,EAAU,IAAiCzC,EAAK2C,CAAO,GAC9D,IAClB,ECZa,gBAAkB,MAC7BtB,GACqC,CACrC,MAAMoB,EAAYC,aAAa,EACzB,CAAE,QAAA7C,CAAQ,EAAIqB,eACdyB,EAAgD,CACpD,OAAAtB,CACF,EAEMrB,EAAM,GAAGH,CAAO,WAEtB,OADiB,MAAM4C,EAAU,IAA6BzC,EAAK2C,CAAO,GAC1D,IAClB"}
|
package/dist/api/index.d.cts
CHANGED
|
@@ -1,46 +1,194 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b5 as ApiConfig, d as SearchCategoriesParams, c as SearchCategoriesResponse, f as SearchCategoriesByPathParams, e as SearchCategoriesByPathResponse, K as SearchProductsParams, J as SearchProductsResponse, N as GetProductParams, M as GetProductResponse, Q as DownloadProductFileParams, O as DownloadProductFileResponse, T as SearchProductVariationsParams, R as SearchProductVariationsResponse, V as GetProductVariationParams, U as GetProductVariationResponse, X as SearchProductTypesResponse, Z as GetProductTypeParams, Y as GetProductTypeResponse, $ as SearchProductBrandsParams, _ as SearchProductBrandsResponse, b4 as GetStoreProfileParams, b3 as GetStoreProfileResponse } from '../shared/ecom-headless.DTL4WyVk.cjs';
|
|
2
2
|
import 'buffer';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Get the API configuration.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { getApiConfig, ApiConfig } from '@lightspeed/ecom-headless';
|
|
10
|
+
*
|
|
11
|
+
* const config: ApiConfig = getApiConfig();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
4
14
|
declare const getApiConfig: () => Required<ApiConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the Storefront API client.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { initStorefrontApi } from '@lightspeed/ecom-headless';
|
|
21
|
+
*
|
|
22
|
+
* await initStorefrontApi({
|
|
23
|
+
* publicToken: 'YOUR_PUBLIC_TOKEN',
|
|
24
|
+
* storeId: 'YOUR_STORE_ID'
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* - This method must be called before using any other API methods.
|
|
30
|
+
* - If storeId is not provided, it will be auto-detected. If detection fails, an error will be thrown.
|
|
31
|
+
*/
|
|
5
32
|
declare const initStorefrontApi: (config: ApiConfig) => Promise<void>;
|
|
6
33
|
|
|
7
34
|
/**
|
|
8
35
|
* Search categories in the store based on provided parameters.
|
|
9
36
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
37
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/categories/search-categories | Ecwid API Documentation}
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { searchCategories, SearchCategoriesResponse } from '@lightspeed/ecom-headless';
|
|
42
|
+
*
|
|
43
|
+
* const categories: SearchCategoriesResponse = await searchCategories();
|
|
44
|
+
* ```
|
|
12
45
|
*/
|
|
13
46
|
declare const searchCategories: (params?: SearchCategoriesParams) => Promise<SearchCategoriesResponse>;
|
|
14
47
|
|
|
15
48
|
/**
|
|
16
|
-
* Search
|
|
49
|
+
* Search categories by path using a delimiter-separated path string.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/categories/search-categories-by-path | Ecwid API Documentation}
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { searchCategoriesByPath, SearchCategoriesByPathResponse } from '@lightspeed/ecom-headless';
|
|
56
|
+
*
|
|
57
|
+
* const categories: SearchCategoriesByPathResponse = await searchCategoriesByPath({
|
|
58
|
+
* path: "Electronics/Phones/Smartphones",
|
|
59
|
+
* delimiter: "/"
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare const searchCategoriesByPath: (params: SearchCategoriesByPathParams) => Promise<SearchCategoriesByPathResponse>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Search for products in a store.
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/search-products | Ecwid API Documentation}
|
|
17
69
|
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { searchProducts, SearchProductsResponse } from '@lightspeed/ecom-headless';
|
|
73
|
+
*
|
|
74
|
+
* const products: SearchProductsResponse = await searchProducts({ keyword: 'laptop' });
|
|
75
|
+
* ```
|
|
20
76
|
*/
|
|
21
77
|
declare const searchProducts: (params?: SearchProductsParams) => Promise<SearchProductsResponse>;
|
|
22
78
|
|
|
23
79
|
/**
|
|
24
|
-
*
|
|
80
|
+
* Get a product from a store.
|
|
81
|
+
*
|
|
82
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/get-product | Ecwid API Documentation}
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { getProduct, GetProductResponse } from '@lightspeed/ecom-headless';
|
|
25
87
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
88
|
+
* const product: GetProductResponse = await getProduct({ productId: 123 });
|
|
89
|
+
* ```
|
|
28
90
|
*/
|
|
29
91
|
declare const getProduct: (params: GetProductParams) => Promise<GetProductResponse>;
|
|
30
92
|
|
|
31
93
|
/**
|
|
32
|
-
* Download a product file
|
|
33
|
-
*
|
|
34
|
-
* @
|
|
94
|
+
* Download a product file from a store.
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-files/download-product-file | Ecwid API Documentation}
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* import { downloadProductFile, DownloadProductFileResponse } from '@lightspeed/ecom-headless';
|
|
101
|
+
*
|
|
102
|
+
* const file: DownloadProductFileResponse = await downloadProductFile({ productId: 123, fileId: 456 });
|
|
103
|
+
* ```
|
|
35
104
|
*/
|
|
36
105
|
declare const downloadProductFile: (params: DownloadProductFileParams) => Promise<DownloadProductFileResponse>;
|
|
37
106
|
|
|
38
107
|
/**
|
|
39
|
-
*
|
|
108
|
+
* Search for product variations in a store.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-variations/search-product-variations | Ecwid API Documentation}
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { searchProductVariations, SearchProductVariationsResponse } from '@lightspeed/ecom-headless';
|
|
115
|
+
*
|
|
116
|
+
* const variations: SearchProductVariationsResponse = await searchProductVariations({ productId: 123 });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare const searchProductVariations: (params: SearchProductVariationsParams) => Promise<SearchProductVariationsResponse>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get a product variation from a store.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-variations/get-product-variation | Ecwid API Documentation}
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { getProductVariation, GetProductVariationResponse } from '@lightspeed/ecom-headless';
|
|
129
|
+
*
|
|
130
|
+
* const variation: GetProductVariationResponse = await getProductVariation({
|
|
131
|
+
* productId: 123,
|
|
132
|
+
* combinationId: 456
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare const getProductVariation: (params: GetProductVariationParams) => Promise<GetProductVariationResponse>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Search for product types in a store.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-types-and-attributes/search-product-types | Ecwid API Documentation}
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { searchProductTypes, SearchProductTypesResponse } from '@lightspeed/ecom-headless';
|
|
146
|
+
*
|
|
147
|
+
* const productTypes: SearchProductTypesResponse = await searchProductTypes();
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare const searchProductTypes: () => Promise<SearchProductTypesResponse>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get a product type from a store.
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-types-and-attributes/get-product-type | Ecwid API Documentation}
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* import { getProductType, GetProductTypeResponse } from '@lightspeed/ecom-headless';
|
|
160
|
+
*
|
|
161
|
+
* const productType: GetProductTypeResponse = await getProductType({ classId: 0 });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare const getProductType: (params: GetProductTypeParams) => Promise<GetProductTypeResponse>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Search for product brands in a store.
|
|
168
|
+
*
|
|
169
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/search-product-brands | Ecwid API Documentation}
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { searchProductBrands, SearchProductBrandsResponse } from '@lightspeed/ecom-headless';
|
|
174
|
+
*
|
|
175
|
+
* const brands: SearchProductBrandsResponse = await searchProductBrands({ limit: 10 });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare const searchProductBrands: (params?: SearchProductBrandsParams) => Promise<SearchProductBrandsResponse>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Get basic information about an Ecwid store: settings, store location, email, etc.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/store-profile/get-store-profile | Ecwid API Documentation}
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { getStoreProfile, GetStoreProfileResponse } from '@lightspeed/ecom-headless';
|
|
40
188
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
189
|
+
* const profile: GetStoreProfileResponse = await getStoreProfile();
|
|
190
|
+
* ```
|
|
43
191
|
*/
|
|
44
192
|
declare const getStoreProfile: (params?: GetStoreProfileParams) => Promise<GetStoreProfileResponse>;
|
|
45
193
|
|
|
46
|
-
export { downloadProductFile, getApiConfig, getProduct, getStoreProfile, initStorefrontApi, searchCategories, searchProducts };
|
|
194
|
+
export { downloadProductFile, getApiConfig, getProduct, getProductType, getProductVariation, getStoreProfile, initStorefrontApi, searchCategories, searchCategoriesByPath, searchProductBrands, searchProductTypes, searchProductVariations, searchProducts };
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,46 +1,194 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b5 as ApiConfig, d as SearchCategoriesParams, c as SearchCategoriesResponse, f as SearchCategoriesByPathParams, e as SearchCategoriesByPathResponse, K as SearchProductsParams, J as SearchProductsResponse, N as GetProductParams, M as GetProductResponse, Q as DownloadProductFileParams, O as DownloadProductFileResponse, T as SearchProductVariationsParams, R as SearchProductVariationsResponse, V as GetProductVariationParams, U as GetProductVariationResponse, X as SearchProductTypesResponse, Z as GetProductTypeParams, Y as GetProductTypeResponse, $ as SearchProductBrandsParams, _ as SearchProductBrandsResponse, b4 as GetStoreProfileParams, b3 as GetStoreProfileResponse } from '../shared/ecom-headless.DTL4WyVk.mjs';
|
|
2
2
|
import 'buffer';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Get the API configuration.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { getApiConfig, ApiConfig } from '@lightspeed/ecom-headless';
|
|
10
|
+
*
|
|
11
|
+
* const config: ApiConfig = getApiConfig();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
4
14
|
declare const getApiConfig: () => Required<ApiConfig>;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the Storefront API client.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { initStorefrontApi } from '@lightspeed/ecom-headless';
|
|
21
|
+
*
|
|
22
|
+
* await initStorefrontApi({
|
|
23
|
+
* publicToken: 'YOUR_PUBLIC_TOKEN',
|
|
24
|
+
* storeId: 'YOUR_STORE_ID'
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* - This method must be called before using any other API methods.
|
|
30
|
+
* - If storeId is not provided, it will be auto-detected. If detection fails, an error will be thrown.
|
|
31
|
+
*/
|
|
5
32
|
declare const initStorefrontApi: (config: ApiConfig) => Promise<void>;
|
|
6
33
|
|
|
7
34
|
/**
|
|
8
35
|
* Search categories in the store based on provided parameters.
|
|
9
36
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
37
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/categories/search-categories | Ecwid API Documentation}
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { searchCategories, SearchCategoriesResponse } from '@lightspeed/ecom-headless';
|
|
42
|
+
*
|
|
43
|
+
* const categories: SearchCategoriesResponse = await searchCategories();
|
|
44
|
+
* ```
|
|
12
45
|
*/
|
|
13
46
|
declare const searchCategories: (params?: SearchCategoriesParams) => Promise<SearchCategoriesResponse>;
|
|
14
47
|
|
|
15
48
|
/**
|
|
16
|
-
* Search
|
|
49
|
+
* Search categories by path using a delimiter-separated path string.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/categories/search-categories-by-path | Ecwid API Documentation}
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { searchCategoriesByPath, SearchCategoriesByPathResponse } from '@lightspeed/ecom-headless';
|
|
56
|
+
*
|
|
57
|
+
* const categories: SearchCategoriesByPathResponse = await searchCategoriesByPath({
|
|
58
|
+
* path: "Electronics/Phones/Smartphones",
|
|
59
|
+
* delimiter: "/"
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare const searchCategoriesByPath: (params: SearchCategoriesByPathParams) => Promise<SearchCategoriesByPathResponse>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Search for products in a store.
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/search-products | Ecwid API Documentation}
|
|
17
69
|
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { searchProducts, SearchProductsResponse } from '@lightspeed/ecom-headless';
|
|
73
|
+
*
|
|
74
|
+
* const products: SearchProductsResponse = await searchProducts({ keyword: 'laptop' });
|
|
75
|
+
* ```
|
|
20
76
|
*/
|
|
21
77
|
declare const searchProducts: (params?: SearchProductsParams) => Promise<SearchProductsResponse>;
|
|
22
78
|
|
|
23
79
|
/**
|
|
24
|
-
*
|
|
80
|
+
* Get a product from a store.
|
|
81
|
+
*
|
|
82
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/get-product | Ecwid API Documentation}
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { getProduct, GetProductResponse } from '@lightspeed/ecom-headless';
|
|
25
87
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
88
|
+
* const product: GetProductResponse = await getProduct({ productId: 123 });
|
|
89
|
+
* ```
|
|
28
90
|
*/
|
|
29
91
|
declare const getProduct: (params: GetProductParams) => Promise<GetProductResponse>;
|
|
30
92
|
|
|
31
93
|
/**
|
|
32
|
-
* Download a product file
|
|
33
|
-
*
|
|
34
|
-
* @
|
|
94
|
+
* Download a product file from a store.
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-files/download-product-file | Ecwid API Documentation}
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* import { downloadProductFile, DownloadProductFileResponse } from '@lightspeed/ecom-headless';
|
|
101
|
+
*
|
|
102
|
+
* const file: DownloadProductFileResponse = await downloadProductFile({ productId: 123, fileId: 456 });
|
|
103
|
+
* ```
|
|
35
104
|
*/
|
|
36
105
|
declare const downloadProductFile: (params: DownloadProductFileParams) => Promise<DownloadProductFileResponse>;
|
|
37
106
|
|
|
38
107
|
/**
|
|
39
|
-
*
|
|
108
|
+
* Search for product variations in a store.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-variations/search-product-variations | Ecwid API Documentation}
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { searchProductVariations, SearchProductVariationsResponse } from '@lightspeed/ecom-headless';
|
|
115
|
+
*
|
|
116
|
+
* const variations: SearchProductVariationsResponse = await searchProductVariations({ productId: 123 });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare const searchProductVariations: (params: SearchProductVariationsParams) => Promise<SearchProductVariationsResponse>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Get a product variation from a store.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-variations/get-product-variation | Ecwid API Documentation}
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { getProductVariation, GetProductVariationResponse } from '@lightspeed/ecom-headless';
|
|
129
|
+
*
|
|
130
|
+
* const variation: GetProductVariationResponse = await getProductVariation({
|
|
131
|
+
* productId: 123,
|
|
132
|
+
* combinationId: 456
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
declare const getProductVariation: (params: GetProductVariationParams) => Promise<GetProductVariationResponse>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Search for product types in a store.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-types-and-attributes/search-product-types | Ecwid API Documentation}
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { searchProductTypes, SearchProductTypesResponse } from '@lightspeed/ecom-headless';
|
|
146
|
+
*
|
|
147
|
+
* const productTypes: SearchProductTypesResponse = await searchProductTypes();
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare const searchProductTypes: () => Promise<SearchProductTypesResponse>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get a product type from a store.
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/product-types-and-attributes/get-product-type | Ecwid API Documentation}
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* import { getProductType, GetProductTypeResponse } from '@lightspeed/ecom-headless';
|
|
160
|
+
*
|
|
161
|
+
* const productType: GetProductTypeResponse = await getProductType({ classId: 0 });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare const getProductType: (params: GetProductTypeParams) => Promise<GetProductTypeResponse>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Search for product brands in a store.
|
|
168
|
+
*
|
|
169
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/products/search-product-brands | Ecwid API Documentation}
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { searchProductBrands, SearchProductBrandsResponse } from '@lightspeed/ecom-headless';
|
|
174
|
+
*
|
|
175
|
+
* const brands: SearchProductBrandsResponse = await searchProductBrands({ limit: 10 });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare const searchProductBrands: (params?: SearchProductBrandsParams) => Promise<SearchProductBrandsResponse>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Get basic information about an Ecwid store: settings, store location, email, etc.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link https://docs.ecwid.com/api-reference/rest-api/store-profile/get-store-profile | Ecwid API Documentation}
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* import { getStoreProfile, GetStoreProfileResponse } from '@lightspeed/ecom-headless';
|
|
40
188
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
189
|
+
* const profile: GetStoreProfileResponse = await getStoreProfile();
|
|
190
|
+
* ```
|
|
43
191
|
*/
|
|
44
192
|
declare const getStoreProfile: (params?: GetStoreProfileParams) => Promise<GetStoreProfileResponse>;
|
|
45
193
|
|
|
46
|
-
export { downloadProductFile, getApiConfig, getProduct, getStoreProfile, initStorefrontApi, searchCategories, searchProducts };
|
|
194
|
+
export { downloadProductFile, getApiConfig, getProduct, getProductType, getProductVariation, getStoreProfile, initStorefrontApi, searchCategories, searchCategoriesByPath, searchProductBrands, searchProductTypes, searchProductVariations, searchProducts };
|