@storepecker/storefront-core 1.0.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/dist/address-DQEZzyUG.d.cts +19 -0
- package/dist/address-DQEZzyUG.d.ts +19 -0
- package/dist/api/index.cjs +367 -0
- package/dist/api/index.d.cts +127 -0
- package/dist/api/index.d.ts +127 -0
- package/dist/api/index.js +131 -0
- package/dist/booking-ClX-dhX7.d.ts +131 -0
- package/dist/booking-Drl7-IL7.d.cts +131 -0
- package/dist/cart-DVrn8hD0.d.cts +367 -0
- package/dist/cart-DVrn8hD0.d.ts +367 -0
- package/dist/checkout/index.cjs +228 -0
- package/dist/checkout/index.d.cts +251 -0
- package/dist/checkout/index.d.ts +251 -0
- package/dist/checkout/index.js +122 -0
- package/dist/chunk-4CVKE6CC.cjs +312 -0
- package/dist/chunk-4MJMNIAB.js +123 -0
- package/dist/chunk-57ZBPAXU.js +114 -0
- package/dist/chunk-7MQOVWLW.js +40 -0
- package/dist/chunk-7UH6REGV.js +12 -0
- package/dist/chunk-A6IO3HIN.cjs +151 -0
- package/dist/chunk-CFF632IQ.cjs +100 -0
- package/dist/chunk-CSISWBZZ.js +121 -0
- package/dist/chunk-E7WPE3PV.js +98 -0
- package/dist/chunk-FLBJKM6G.js +83 -0
- package/dist/chunk-GB3HW6DM.js +61 -0
- package/dist/chunk-GH75WUO2.cjs +42 -0
- package/dist/chunk-GQTO5ZE2.cjs +96 -0
- package/dist/chunk-JHGXIIBZ.cjs +37 -0
- package/dist/chunk-JQMLHRWL.js +21 -0
- package/dist/chunk-K44JZ5NL.cjs +212 -0
- package/dist/chunk-K5B62JZO.cjs +154 -0
- package/dist/chunk-KWKHHRRJ.cjs +15 -0
- package/dist/chunk-LBGIUNM6.js +30 -0
- package/dist/chunk-LC5ZAUKL.cjs +220 -0
- package/dist/chunk-N3CTXRFT.cjs +30 -0
- package/dist/chunk-QCQCFYYR.js +206 -0
- package/dist/chunk-QM73PI5L.cjs +218 -0
- package/dist/chunk-RCXQJ6XC.cjs +131 -0
- package/dist/chunk-UM24VDYB.js +216 -0
- package/dist/chunk-UXLUE3HW.cjs +69 -0
- package/dist/chunk-WFDKKOO7.js +210 -0
- package/dist/chunk-YUPBTD4M.js +289 -0
- package/dist/components/index.cjs +576 -0
- package/dist/components/index.css +329 -0
- package/dist/components/index.d.cts +58 -0
- package/dist/components/index.d.ts +58 -0
- package/dist/components/index.js +569 -0
- package/dist/coupons-C7iJ-1cy.d.cts +37 -0
- package/dist/coupons-CnfTKL1i.d.ts +37 -0
- package/dist/hooks/index.cjs +381 -0
- package/dist/hooks/index.d.cts +123 -0
- package/dist/hooks/index.d.ts +123 -0
- package/dist/hooks/index.js +364 -0
- package/dist/index-DTyIuLuI.d.cts +18 -0
- package/dist/index-DTyIuLuI.d.ts +18 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.d.cts +53 -0
- package/dist/models/index.d.ts +53 -0
- package/dist/models/index.js +1 -0
- package/dist/orders-CkUzv5Xh.d.ts +159 -0
- package/dist/orders-D0oC9ugD.d.cts +159 -0
- package/dist/phonepe-D7vn-9SR.d.cts +27 -0
- package/dist/phonepe-D7vn-9SR.d.ts +27 -0
- package/dist/store/index.cjs +149 -0
- package/dist/store/index.d.cts +46 -0
- package/dist/store/index.d.ts +46 -0
- package/dist/store/index.js +141 -0
- package/dist/useAddressForm-C-Uzug4d.d.ts +42 -0
- package/dist/useAddressForm-DgkCP1nG.d.cts +42 -0
- package/dist/utils/index.cjs +535 -0
- package/dist/utils/index.d.cts +507 -0
- package/dist/utils/index.d.ts +507 -0
- package/dist/utils/index.js +342 -0
- package/dist/wishlist-BzhnCAQD.d.ts +41 -0
- package/dist/wishlist-CBCZD66Y.d.cts +41 -0
- package/package.json +134 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// src/utils/cache.ts
|
|
2
|
+
var DEFAULT_EXPIRY_HOURS = 24;
|
|
3
|
+
var CacheManager = class _CacheManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
6
|
+
this.loadFromStorage();
|
|
7
|
+
}
|
|
8
|
+
static getInstance() {
|
|
9
|
+
if (!_CacheManager.instance) {
|
|
10
|
+
_CacheManager.instance = new _CacheManager();
|
|
11
|
+
}
|
|
12
|
+
return _CacheManager.instance;
|
|
13
|
+
}
|
|
14
|
+
loadFromStorage() {
|
|
15
|
+
if (typeof window === "undefined") return;
|
|
16
|
+
try {
|
|
17
|
+
const stored = localStorage.getItem("app_cache");
|
|
18
|
+
if (stored) {
|
|
19
|
+
const parsed = JSON.parse(stored);
|
|
20
|
+
this.cache = new Map(Object.entries(parsed));
|
|
21
|
+
this.cleanExpired();
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.warn("Failed to load cache from storage:", error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
saveToStorage() {
|
|
28
|
+
if (typeof window === "undefined") return;
|
|
29
|
+
try {
|
|
30
|
+
const cacheObject = Object.fromEntries(this.cache);
|
|
31
|
+
localStorage.setItem("app_cache", JSON.stringify(cacheObject));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.warn("Failed to save cache to storage:", error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
cleanExpired() {
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
const keysToDelete = [];
|
|
39
|
+
this.cache.forEach((item, key) => {
|
|
40
|
+
if (now > item.expiry) {
|
|
41
|
+
keysToDelete.push(key);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
keysToDelete.forEach((key) => {
|
|
45
|
+
this.cache.delete(key);
|
|
46
|
+
});
|
|
47
|
+
this.saveToStorage();
|
|
48
|
+
}
|
|
49
|
+
set(key, data, options = {}) {
|
|
50
|
+
const expiryHours = options.expiryHours || DEFAULT_EXPIRY_HOURS;
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
const expiry = now + expiryHours * 60 * 60 * 1e3;
|
|
53
|
+
const cacheItem = {
|
|
54
|
+
data,
|
|
55
|
+
timestamp: now,
|
|
56
|
+
expiry
|
|
57
|
+
};
|
|
58
|
+
this.cache.set(key, cacheItem);
|
|
59
|
+
this.saveToStorage();
|
|
60
|
+
}
|
|
61
|
+
get(key) {
|
|
62
|
+
this.cleanExpired();
|
|
63
|
+
const item = this.cache.get(key);
|
|
64
|
+
if (!item) return null;
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
if (now > item.expiry) {
|
|
67
|
+
this.cache.delete(key);
|
|
68
|
+
this.saveToStorage();
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return item.data;
|
|
72
|
+
}
|
|
73
|
+
has(key) {
|
|
74
|
+
this.cleanExpired();
|
|
75
|
+
return this.cache.has(key);
|
|
76
|
+
}
|
|
77
|
+
delete(key) {
|
|
78
|
+
this.cache.delete(key);
|
|
79
|
+
this.saveToStorage();
|
|
80
|
+
}
|
|
81
|
+
clear() {
|
|
82
|
+
this.cache.clear();
|
|
83
|
+
if (typeof window !== "undefined") {
|
|
84
|
+
localStorage.removeItem("app_cache");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
getCacheInfo() {
|
|
88
|
+
this.cleanExpired();
|
|
89
|
+
return {
|
|
90
|
+
size: this.cache.size,
|
|
91
|
+
keys: Array.from(this.cache.keys())
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
invalidateCache(pattern) {
|
|
95
|
+
this.cleanExpired();
|
|
96
|
+
if (!pattern) {
|
|
97
|
+
this.clear();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const keysToDelete = [];
|
|
101
|
+
this.cache.forEach((item, key) => {
|
|
102
|
+
if (key.includes(pattern)) {
|
|
103
|
+
keysToDelete.push(key);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
keysToDelete.forEach((key) => {
|
|
107
|
+
this.cache.delete(key);
|
|
108
|
+
});
|
|
109
|
+
this.saveToStorage();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var cache = CacheManager.getInstance();
|
|
113
|
+
function setCache(key, data, options = {}) {
|
|
114
|
+
cache.set(key, data, options);
|
|
115
|
+
}
|
|
116
|
+
function getCache(key) {
|
|
117
|
+
return cache.get(key);
|
|
118
|
+
}
|
|
119
|
+
function hasCache(key) {
|
|
120
|
+
return cache.has(key);
|
|
121
|
+
}
|
|
122
|
+
function deleteCache(key) {
|
|
123
|
+
cache.delete(key);
|
|
124
|
+
}
|
|
125
|
+
function clearCache() {
|
|
126
|
+
cache.clear();
|
|
127
|
+
}
|
|
128
|
+
function invalidateCache(pattern) {
|
|
129
|
+
cache.invalidateCache(pattern);
|
|
130
|
+
}
|
|
131
|
+
function generateCacheKey(endpoint, params) {
|
|
132
|
+
const baseKey = endpoint.replace(/[^a-zA-Z0-9]/g, "_");
|
|
133
|
+
if (!params) return baseKey;
|
|
134
|
+
const paramString = JSON.stringify(params);
|
|
135
|
+
const hash = btoa(paramString).replace(/[^a-zA-Z0-9]/g, "");
|
|
136
|
+
return `${baseKey}_${hash}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/utils/misc.ts
|
|
140
|
+
function convertObjectToParams(params) {
|
|
141
|
+
const cleanedParams = Object.fromEntries(
|
|
142
|
+
Object.entries(params).filter(([_, value]) => value !== void 0)
|
|
143
|
+
);
|
|
144
|
+
const searchParams = new URLSearchParams(cleanedParams);
|
|
145
|
+
return searchParams.toString();
|
|
146
|
+
}
|
|
147
|
+
function getParamsFromURL() {
|
|
148
|
+
if (typeof window === "undefined") return {};
|
|
149
|
+
const queryParams = {};
|
|
150
|
+
const search = window.location.search;
|
|
151
|
+
const searchParams = new URLSearchParams(search);
|
|
152
|
+
searchParams.forEach((value, key) => {
|
|
153
|
+
if (value.includes(",")) {
|
|
154
|
+
queryParams[key] = value.split(",");
|
|
155
|
+
} else if (isNaN(Number(value))) {
|
|
156
|
+
queryParams[key] = value;
|
|
157
|
+
} else queryParams[key] = Number(value);
|
|
158
|
+
});
|
|
159
|
+
return queryParams;
|
|
160
|
+
}
|
|
161
|
+
function pushParamsToURL(params) {
|
|
162
|
+
const cleanedParams = Object.fromEntries(
|
|
163
|
+
Object.entries(params).filter(([_, value]) => {
|
|
164
|
+
return Array.isArray(value) ? value.length : !(value === void 0 || value === 0);
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
const searchParams = new URLSearchParams(cleanedParams);
|
|
168
|
+
return searchParams.toString();
|
|
169
|
+
}
|
|
170
|
+
function convertToCurrency(amount, fraction = 0, currency) {
|
|
171
|
+
return amount?.toLocaleString("en-IN", {
|
|
172
|
+
style: "currency",
|
|
173
|
+
currency: currency || (typeof window !== "undefined" ? window.currency_code : void 0) || "INR",
|
|
174
|
+
maximumFractionDigits: fraction
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function formatDateTime(date) {
|
|
178
|
+
return new Date(date).toLocaleString("en-IN", {
|
|
179
|
+
dateStyle: "medium"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
var getQueryParams = (params, filterKeys = []) => {
|
|
183
|
+
let filterParams = params;
|
|
184
|
+
Object.keys(filterParams).forEach((key) => {
|
|
185
|
+
const value = filterParams[key];
|
|
186
|
+
if (!value) {
|
|
187
|
+
delete filterParams[key];
|
|
188
|
+
}
|
|
189
|
+
if (filterKeys.includes(key)) {
|
|
190
|
+
if (value && !Array.isArray(value)) {
|
|
191
|
+
filterParams[key] = value.toString()?.split(",");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return filterParams;
|
|
196
|
+
};
|
|
197
|
+
var shareLink = (shareData, title, url) => {
|
|
198
|
+
if (navigator.share) {
|
|
199
|
+
navigator.share({
|
|
200
|
+
title: "Storepecker",
|
|
201
|
+
text: shareData,
|
|
202
|
+
url: url || window.location.href
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
navigator.clipboard.writeText(window.location.href);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function pluralize(strings, count, singular, plural) {
|
|
209
|
+
const word = count === 1 ? singular : plural;
|
|
210
|
+
return `${strings[0]}${count} ${word}${strings[1]}`;
|
|
211
|
+
}
|
|
212
|
+
async function digestMessage(message) {
|
|
213
|
+
const msgUint8 = new TextEncoder().encode(message);
|
|
214
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgUint8);
|
|
215
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
216
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
217
|
+
return hashHex;
|
|
218
|
+
}
|
|
219
|
+
var constructFilter = (filter) => {
|
|
220
|
+
if (filter) {
|
|
221
|
+
const filtersObj = {};
|
|
222
|
+
filter.forEach((filter2) => {
|
|
223
|
+
if (filtersObj[filter2.type]) {
|
|
224
|
+
if (Array.isArray(filter2.value)) {
|
|
225
|
+
filtersObj[filter2.type] = filtersObj[filter2.type] + "," + filter2.value.join(",");
|
|
226
|
+
} else {
|
|
227
|
+
filtersObj[filter2.type] = filtersObj[filter2.type] + "," + filter2.value;
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
filtersObj[filter2.type] = Array.isArray(filter2.value) ? filter2.value.join(",") : filter2.value;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
return filtersObj;
|
|
234
|
+
}
|
|
235
|
+
return {};
|
|
236
|
+
};
|
|
237
|
+
var getDelayInMilliseconds = (value, unit) => {
|
|
238
|
+
switch (unit) {
|
|
239
|
+
case "seconds":
|
|
240
|
+
return value * 1e3;
|
|
241
|
+
case "minutes":
|
|
242
|
+
return value * 60 * 1e3;
|
|
243
|
+
case "hours":
|
|
244
|
+
return value * 60 * 60 * 1e3;
|
|
245
|
+
case "days":
|
|
246
|
+
return value * 24 * 60 * 60 * 1e3;
|
|
247
|
+
case "weeks":
|
|
248
|
+
return value * 7 * 24 * 60 * 60 * 1e3;
|
|
249
|
+
case "months":
|
|
250
|
+
return value * 30 * 24 * 60 * 60 * 1e3;
|
|
251
|
+
default:
|
|
252
|
+
return value * 1e3;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
function formatPostalLabel(zipNameType) {
|
|
256
|
+
if (!zipNameType) return "";
|
|
257
|
+
const t = zipNameType.toLowerCase();
|
|
258
|
+
switch (t) {
|
|
259
|
+
case "zip":
|
|
260
|
+
return "ZIP Code";
|
|
261
|
+
case "pin":
|
|
262
|
+
return "PIN Code";
|
|
263
|
+
case "postal":
|
|
264
|
+
return "Postal Code";
|
|
265
|
+
case "post":
|
|
266
|
+
return "Postcode";
|
|
267
|
+
case "eir":
|
|
268
|
+
return "Eircode";
|
|
269
|
+
case "cep":
|
|
270
|
+
return "CEP";
|
|
271
|
+
case "cap":
|
|
272
|
+
return "CAP";
|
|
273
|
+
default:
|
|
274
|
+
return t.charAt(0).toUpperCase() + t.slice(1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async function getAddressMeta(countryCode) {
|
|
278
|
+
const res = await fetch(
|
|
279
|
+
`https://chromium-i18n.appspot.com/ssl-address/data/${countryCode}`
|
|
280
|
+
);
|
|
281
|
+
const data = await res.json();
|
|
282
|
+
return {
|
|
283
|
+
regionLabel: data.state_name_type || "State",
|
|
284
|
+
postalLabel: formatPostalLabel(data.zip_name_type) || "Postal Code",
|
|
285
|
+
hasPostal: !!data.zip_name_type
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export { CacheManager, cache, clearCache, constructFilter, convertObjectToParams, convertToCurrency, deleteCache, digestMessage, formatDateTime, formatPostalLabel, generateCacheKey, getAddressMeta, getCache, getDelayInMilliseconds, getParamsFromURL, getQueryParams, hasCache, invalidateCache, pluralize, pushParamsToURL, setCache, shareLink };
|