@tiendanube/nube-sdk-helper 0.0.1
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/README.md +174 -0
- package/dist/index.cjs +449 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1167 -0
- package/dist/index.d.ts +1167 -0
- package/dist/index.js +373 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// src/lib/instance.ts
|
|
2
|
+
var registeredInstance;
|
|
3
|
+
function readGlobalInstance() {
|
|
4
|
+
return typeof self !== "undefined" ? self.__SDK_INSTANCE__ : void 0;
|
|
5
|
+
}
|
|
6
|
+
function setNubeInstance(nube) {
|
|
7
|
+
registeredInstance = nube;
|
|
8
|
+
}
|
|
9
|
+
function getNubeInstance() {
|
|
10
|
+
const instance2 = registeredInstance ?? readGlobalInstance();
|
|
11
|
+
if (!instance2) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"NubeSDK instance not registered. Call setNubeInstance(nube) at the start of your App(nube) entry point."
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return instance2;
|
|
17
|
+
}
|
|
18
|
+
function clearNubeInstance() {
|
|
19
|
+
registeredInstance = void 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/lib/browser.ts
|
|
23
|
+
var instance = null;
|
|
24
|
+
var browser = new Proxy({}, {
|
|
25
|
+
get(_, prop) {
|
|
26
|
+
if (instance === null) {
|
|
27
|
+
instance = getNubeInstance().getBrowserAPIs();
|
|
28
|
+
}
|
|
29
|
+
return instance[prop];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
function navigate(route) {
|
|
33
|
+
browser.navigate(route);
|
|
34
|
+
}
|
|
35
|
+
function clearBrowserCache() {
|
|
36
|
+
instance = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/lib/ui.ts
|
|
40
|
+
var ui = Object.freeze({
|
|
41
|
+
// Helpers for common components
|
|
42
|
+
showToast(message, variant = "info") {
|
|
43
|
+
const toast = {
|
|
44
|
+
type: "toastRoot",
|
|
45
|
+
variant,
|
|
46
|
+
children: [{ type: "toastTitle", children: message }]
|
|
47
|
+
};
|
|
48
|
+
getNubeInstance().render("corner_top_right", toast);
|
|
49
|
+
},
|
|
50
|
+
// Clear slot
|
|
51
|
+
clear(slot) {
|
|
52
|
+
getNubeInstance().clearSlot(slot);
|
|
53
|
+
},
|
|
54
|
+
render(slot, component) {
|
|
55
|
+
getNubeInstance().render(slot, component);
|
|
56
|
+
},
|
|
57
|
+
// Render the same component across multiple slots in a single call.
|
|
58
|
+
renderAll(slots, component) {
|
|
59
|
+
const nube = getNubeInstance();
|
|
60
|
+
for (const slot of slots) {
|
|
61
|
+
nube.render(slot, component);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/lib/events.ts
|
|
67
|
+
function onEvent(event, listener) {
|
|
68
|
+
const nube = getNubeInstance();
|
|
69
|
+
nube.on(event, listener);
|
|
70
|
+
return () => nube.off(event, listener);
|
|
71
|
+
}
|
|
72
|
+
function toastOn(event, message, variant) {
|
|
73
|
+
const listener = ((state) => {
|
|
74
|
+
const text = typeof message === "function" ? message(state) : message;
|
|
75
|
+
ui.showToast(text, variant);
|
|
76
|
+
});
|
|
77
|
+
return onEvent(event, listener);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/lib/getters.ts
|
|
81
|
+
function getCurrentState() {
|
|
82
|
+
return getNubeInstance().getState();
|
|
83
|
+
}
|
|
84
|
+
function getAppData() {
|
|
85
|
+
return self.__APP_DATA__;
|
|
86
|
+
}
|
|
87
|
+
var cachedScriptURL;
|
|
88
|
+
function getScriptURL() {
|
|
89
|
+
if (!cachedScriptURL) {
|
|
90
|
+
cachedScriptURL = Object.freeze(new URL(self.__APP_DATA__.script));
|
|
91
|
+
}
|
|
92
|
+
return cachedScriptURL;
|
|
93
|
+
}
|
|
94
|
+
function getScriptSearchParams() {
|
|
95
|
+
return getScriptURL().searchParams;
|
|
96
|
+
}
|
|
97
|
+
function getScriptParam(key) {
|
|
98
|
+
return getScriptSearchParams().get(key);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/internal/primitives.ts
|
|
102
|
+
function isObject(value) {
|
|
103
|
+
return typeof value === "object" && value !== null;
|
|
104
|
+
}
|
|
105
|
+
function isPlainObject(value) {
|
|
106
|
+
return isObject(value) && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/lib/guards/address.ts
|
|
110
|
+
function isAddress(value) {
|
|
111
|
+
return isPlainObject(value) && typeof value.zipcode === "string" && (value.first_name === null || typeof value.first_name === "string") && (value.last_name === null || typeof value.last_name === "string") && (value.address === null || typeof value.address === "string") && (value.number === null || typeof value.number === "string") && (value.floor === null || typeof value.floor === "string") && (value.locality === null || typeof value.locality === "string") && (value.city === null || typeof value.city === "string") && (value.state === null || typeof value.state === "string") && (value.country === null || typeof value.country === "string") && (value.phone === null || typeof value.phone === "string");
|
|
112
|
+
}
|
|
113
|
+
function isShippingAddress(value) {
|
|
114
|
+
return isPlainObject(value) && typeof value.zipcode === "string" && (value.first_name === null || typeof value.first_name === "string") && (value.last_name === null || typeof value.last_name === "string") && (value.address === null || typeof value.address === "string") && (value.number === null || typeof value.number === "string") && (value.floor === null || typeof value.floor === "string") && (value.locality === null || typeof value.locality === "string") && (value.city === null || typeof value.city === "string") && (value.state === null || typeof value.state === "string") && (value.country === null || typeof value.country === "string") && (value.phone === null || typeof value.phone === "string") && (value.between_street === null || typeof value.between_street === "string") && (value.reference === null || typeof value.reference === "string");
|
|
115
|
+
}
|
|
116
|
+
function isBillingAddress(value) {
|
|
117
|
+
return isPlainObject(value) && typeof value.zipcode === "string" && (value.first_name === null || typeof value.first_name === "string") && (value.last_name === null || typeof value.last_name === "string") && (value.address === null || typeof value.address === "string") && (value.number === null || typeof value.number === "string") && (value.floor === null || typeof value.floor === "string") && (value.locality === null || typeof value.locality === "string") && (value.city === null || typeof value.city === "string") && (value.state === null || typeof value.state === "string") && (value.country === null || typeof value.country === "string") && (value.phone === null || typeof value.phone === "string") && (value.id_number === null || typeof value.id_number === "string") && (value.customer_type === null || typeof value.customer_type === "string") && (value.business_name === null || typeof value.business_name === "string") && (value.trade_name === null || typeof value.trade_name === "string") && (value.state_registration === null || typeof value.state_registration === "string") && (value.fiscal_regime === null || typeof value.fiscal_regime === "string") && (value.invoice_use === null || typeof value.invoice_use === "string") && (value.document_type === null || typeof value.document_type === "string") && (value.business_activity === null || typeof value.business_activity === "string");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/lib/guards/cart.ts
|
|
121
|
+
function isCart(value) {
|
|
122
|
+
return isPlainObject(value) && typeof value.id === "string" && isPlainObject(value.validation) && typeof value.validation.status === "string" && Array.isArray(value.items) && isPlainObject(value.prices) && typeof value.prices.subtotal === "number" && typeof value.prices.total === "number" && isPlainObject(value.coupon);
|
|
123
|
+
}
|
|
124
|
+
function isCartItem(value) {
|
|
125
|
+
return isPlainObject(value) && typeof value.id === "number" && typeof value.name === "string" && typeof value.price === "string" && typeof value.quantity === "number" && typeof value.free_shipping === "boolean" && typeof value.product_id === "number" && typeof value.variant_id === "number" && typeof value.thumbnail === "string" && typeof value.variant_values === "string" && typeof value.url === "string" && typeof value.is_ahora_12_eligible === "boolean";
|
|
126
|
+
}
|
|
127
|
+
function isCartValidationSuccess(validation) {
|
|
128
|
+
return validation.status === "success";
|
|
129
|
+
}
|
|
130
|
+
function isCartValidationPending(validation) {
|
|
131
|
+
return validation.status === "pending";
|
|
132
|
+
}
|
|
133
|
+
function isCartValidationFail(validation) {
|
|
134
|
+
return validation.status === "fail";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/lib/guards/components.ts
|
|
138
|
+
function isNubeComponent(value) {
|
|
139
|
+
return typeof value === "string" || isPlainObject(value) && typeof value.type === "string";
|
|
140
|
+
}
|
|
141
|
+
function hasProductList(data) {
|
|
142
|
+
return isObject(data) && "products" in data && Array.isArray(data.products);
|
|
143
|
+
}
|
|
144
|
+
function hasSections(data) {
|
|
145
|
+
return isObject(data) && "sections" in data && Array.isArray(data.sections);
|
|
146
|
+
}
|
|
147
|
+
function isSectionWithProducts(item) {
|
|
148
|
+
return isObject(item) && "products" in item && Array.isArray(item.products);
|
|
149
|
+
}
|
|
150
|
+
function hasSingleProduct(data) {
|
|
151
|
+
return isObject(data) && "product" in data && isObject(data.product) && "id" in data.product;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/lib/guards/domain.ts
|
|
155
|
+
function isStore(value) {
|
|
156
|
+
return isPlainObject(value) && typeof value.id === "number" && typeof value.name === "string" && typeof value.domain === "string" && typeof value.currency === "string" && typeof value.language === "string";
|
|
157
|
+
}
|
|
158
|
+
function isCustomer(value) {
|
|
159
|
+
return isPlainObject(value) && (value.id === null || typeof value.id === "number") && isPlainObject(value.contact) && isPlainObject(value.shipping_address) && isPlainObject(value.billing_address);
|
|
160
|
+
}
|
|
161
|
+
function isPayment(value) {
|
|
162
|
+
return isPlainObject(value) && (value.status === null || typeof value.status === "string") && (value.selected === null || isPlainObject(value.selected));
|
|
163
|
+
}
|
|
164
|
+
function isShipping(value) {
|
|
165
|
+
return isPlainObject(value) && (value.selected === null || typeof value.selected === "string") && (value.options === void 0 || Array.isArray(value.options)) && (value.custom_labels === void 0 || isPlainObject(value.custom_labels));
|
|
166
|
+
}
|
|
167
|
+
function isShippingOption(value) {
|
|
168
|
+
return isPlainObject(value) && typeof value.id === "string" && typeof value.price === "number" && typeof value.currency === "string" && typeof value.phone_required === "boolean" && typeof value.id_required === "boolean" && typeof value.accepts_cod === "boolean" && typeof value.free_shipping_eligible === "boolean" && isPlainObject(value.extra) && typeof value.hidden === "boolean" && typeof value.shippable === "boolean";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/lib/guards/pages.ts
|
|
172
|
+
function isProductPage(page) {
|
|
173
|
+
return page.type === "product";
|
|
174
|
+
}
|
|
175
|
+
function isCategoryPage(page) {
|
|
176
|
+
return page.type === "category";
|
|
177
|
+
}
|
|
178
|
+
function isCheckoutPage(page) {
|
|
179
|
+
return page.type === "checkout";
|
|
180
|
+
}
|
|
181
|
+
function isAllProductsPage(page) {
|
|
182
|
+
return page.type === "products";
|
|
183
|
+
}
|
|
184
|
+
function isSearchPage(page) {
|
|
185
|
+
return page.type === "search";
|
|
186
|
+
}
|
|
187
|
+
function isHomePage(page) {
|
|
188
|
+
return page.type === "home";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/lib/page-match.ts
|
|
192
|
+
function pageMatch(state, handlers) {
|
|
193
|
+
const { page } = state.location;
|
|
194
|
+
if (isProductPage(page)) {
|
|
195
|
+
handlers.product?.(state, page.data.product);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (isCategoryPage(page)) {
|
|
199
|
+
handlers.category?.(state, page.data);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (isCheckoutPage(page)) {
|
|
203
|
+
handlers.checkout?.(state, page.data);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (isHomePage(page)) {
|
|
207
|
+
handlers.home?.(state, page.data);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function onPage(handlers) {
|
|
212
|
+
const nube = getNubeInstance();
|
|
213
|
+
const currentState = nube.getState();
|
|
214
|
+
pageMatch(currentState, handlers);
|
|
215
|
+
const listener = (state) => pageMatch(state, handlers);
|
|
216
|
+
nube.on("location:updated", listener);
|
|
217
|
+
return () => nube.off("location:updated", listener);
|
|
218
|
+
}
|
|
219
|
+
function onCheckoutStep(handlers) {
|
|
220
|
+
const nube = getNubeInstance();
|
|
221
|
+
const currentState = nube.getState();
|
|
222
|
+
const currentPage = currentState.location.page;
|
|
223
|
+
if (currentPage.type === "checkout") {
|
|
224
|
+
handlers[currentPage?.data?.step]?.(currentState);
|
|
225
|
+
}
|
|
226
|
+
const listener = (state) => {
|
|
227
|
+
const { page } = state.location;
|
|
228
|
+
if (page.type !== "checkout") return;
|
|
229
|
+
const step = page.data.step;
|
|
230
|
+
handlers[step]?.(state);
|
|
231
|
+
};
|
|
232
|
+
nube.on("checkout:ready", listener);
|
|
233
|
+
return () => nube.off("checkout:ready", listener);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/lib/render.ts
|
|
237
|
+
function getProductsFromState(state) {
|
|
238
|
+
const { page } = state.location;
|
|
239
|
+
if (!page || !("data" in page) || !page.data) {
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
const products = [];
|
|
243
|
+
if (hasProductList(page.data)) {
|
|
244
|
+
products.push(...page.data.products);
|
|
245
|
+
}
|
|
246
|
+
if (hasSections(page.data)) {
|
|
247
|
+
for (const section of page.data.sections) {
|
|
248
|
+
if (isSectionWithProducts(section)) {
|
|
249
|
+
products.push(...section.products);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (hasSingleProduct(page.data)) {
|
|
254
|
+
products.push(page.data.product);
|
|
255
|
+
}
|
|
256
|
+
return products;
|
|
257
|
+
}
|
|
258
|
+
function forEachProduct(renderFactory) {
|
|
259
|
+
return (state) => {
|
|
260
|
+
const products = getProductsFromState(state);
|
|
261
|
+
if (!products.length) return [];
|
|
262
|
+
return products.reduce((acc, product) => {
|
|
263
|
+
const component = renderFactory(product);
|
|
264
|
+
if (component) {
|
|
265
|
+
acc.push(Object.assign({}, component, { key: product.id }));
|
|
266
|
+
}
|
|
267
|
+
return acc;
|
|
268
|
+
}, []);
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/lib/selectors.ts
|
|
273
|
+
function getCart(state = getCurrentState()) {
|
|
274
|
+
return state.cart;
|
|
275
|
+
}
|
|
276
|
+
function getCartItems(state = getCurrentState()) {
|
|
277
|
+
return state.cart.items;
|
|
278
|
+
}
|
|
279
|
+
function getPageType(state = getCurrentState()) {
|
|
280
|
+
return state.location.page.type;
|
|
281
|
+
}
|
|
282
|
+
function getCustomer(state = getCurrentState()) {
|
|
283
|
+
return state.customer;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/lib/utils.ts
|
|
287
|
+
function deepClone(obj) {
|
|
288
|
+
if (obj === null || typeof obj !== "object") {
|
|
289
|
+
return obj;
|
|
290
|
+
}
|
|
291
|
+
if (typeof structuredClone === "function") {
|
|
292
|
+
return structuredClone(obj);
|
|
293
|
+
}
|
|
294
|
+
return JSON.parse(JSON.stringify(obj));
|
|
295
|
+
}
|
|
296
|
+
function debounce(func, wait) {
|
|
297
|
+
let timeout;
|
|
298
|
+
return (...args) => {
|
|
299
|
+
const later = () => {
|
|
300
|
+
timeout = void 0;
|
|
301
|
+
func(...args);
|
|
302
|
+
};
|
|
303
|
+
if (timeout) {
|
|
304
|
+
clearTimeout(timeout);
|
|
305
|
+
}
|
|
306
|
+
timeout = setTimeout(later, wait);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function throttle(func, limit) {
|
|
310
|
+
let inThrottle;
|
|
311
|
+
return (...args) => {
|
|
312
|
+
if (!inThrottle) {
|
|
313
|
+
func(...args);
|
|
314
|
+
inThrottle = true;
|
|
315
|
+
setTimeout(() => {
|
|
316
|
+
inThrottle = false;
|
|
317
|
+
}, limit);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
export {
|
|
322
|
+
browser,
|
|
323
|
+
clearBrowserCache,
|
|
324
|
+
clearNubeInstance,
|
|
325
|
+
debounce,
|
|
326
|
+
deepClone,
|
|
327
|
+
forEachProduct,
|
|
328
|
+
getAppData,
|
|
329
|
+
getCart,
|
|
330
|
+
getCartItems,
|
|
331
|
+
getCurrentState,
|
|
332
|
+
getCustomer,
|
|
333
|
+
getNubeInstance,
|
|
334
|
+
getPageType,
|
|
335
|
+
getProductsFromState,
|
|
336
|
+
getScriptParam,
|
|
337
|
+
getScriptSearchParams,
|
|
338
|
+
getScriptURL,
|
|
339
|
+
hasProductList,
|
|
340
|
+
hasSections,
|
|
341
|
+
hasSingleProduct,
|
|
342
|
+
isAddress,
|
|
343
|
+
isAllProductsPage,
|
|
344
|
+
isBillingAddress,
|
|
345
|
+
isCart,
|
|
346
|
+
isCartItem,
|
|
347
|
+
isCartValidationFail,
|
|
348
|
+
isCartValidationPending,
|
|
349
|
+
isCartValidationSuccess,
|
|
350
|
+
isCategoryPage,
|
|
351
|
+
isCheckoutPage,
|
|
352
|
+
isCustomer,
|
|
353
|
+
isHomePage,
|
|
354
|
+
isNubeComponent,
|
|
355
|
+
isPayment,
|
|
356
|
+
isProductPage,
|
|
357
|
+
isSearchPage,
|
|
358
|
+
isSectionWithProducts,
|
|
359
|
+
isShipping,
|
|
360
|
+
isShippingAddress,
|
|
361
|
+
isShippingOption,
|
|
362
|
+
isStore,
|
|
363
|
+
navigate,
|
|
364
|
+
onCheckoutStep,
|
|
365
|
+
onEvent,
|
|
366
|
+
onPage,
|
|
367
|
+
pageMatch,
|
|
368
|
+
setNubeInstance,
|
|
369
|
+
throttle,
|
|
370
|
+
toastOn,
|
|
371
|
+
ui
|
|
372
|
+
};
|
|
373
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/instance.ts","../src/lib/browser.ts","../src/lib/ui.ts","../src/lib/events.ts","../src/lib/getters.ts","../src/internal/primitives.ts","../src/lib/guards/address.ts","../src/lib/guards/cart.ts","../src/lib/guards/components.ts","../src/lib/guards/domain.ts","../src/lib/guards/pages.ts","../src/lib/page-match.ts","../src/lib/render.ts","../src/lib/selectors.ts","../src/lib/utils.ts"],"sourcesContent":["/**\n * @fileoverview NubeSDK instance management\n *\n * The NubeSDK runtime passes the SDK instance only as the argument of the\n * app entry point (`App(nube)`); it does not expose it on a global. This module\n * lets an app register that instance once, so every other helper\n * (`getCurrentState`, `ui`, `browser`, `onPage`, selectors, ...) can access it\n * without threading `nube` through every function and component.\n */\n\nimport type { NubeSDK } from \"@tiendanube/nube-sdk-types\";\n\n/**\n * The instance registered by the app via {@link setNubeInstance}.\n * `undefined` until the app registers one.\n */\nlet registeredInstance: Readonly<NubeSDK> | undefined;\n\n/**\n * Reads `self.__SDK_INSTANCE__` if it exists, guarding against environments\n * where `self` is undefined (e.g. Node-based test runners).\n */\nfunction readGlobalInstance(): Readonly<NubeSDK> | undefined {\n\treturn typeof self !== \"undefined\" ? self.__SDK_INSTANCE__ : undefined;\n}\n\n/**\n * Registers the NubeSDK instance for the current app.\n *\n * Call this once at the very start of your app entry point so the rest of the\n * helper API can access the instance without it being passed around.\n *\n * @param nube - The NubeSDK instance received by your `App(nube)` entry point\n *\n * @example\n * ```typescript\n * import { setNubeInstance, getCurrentState, ui } from \"@tiendanube/nube-sdk-helper\";\n *\n * export function App(nube: NubeSDK) {\n * setNubeInstance(nube);\n *\n * // No need to pass `nube` around anymore:\n * const state = getCurrentState();\n * ui.showToast(\"App ready!\");\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function setNubeInstance(nube: Readonly<NubeSDK>): void {\n\tregisteredInstance = nube;\n}\n\n/**\n * Gets the NubeSDK instance for the current app.\n *\n * Returns the instance registered via {@link setNubeInstance}. If none was\n * registered, it falls back to `self.__SDK_INSTANCE__` (for forward\n * compatibility) and throws a descriptive error if neither is available.\n *\n * @returns The readonly NubeSDK instance\n * @throws If no instance was registered and no global instance exists\n *\n * @example\n * ```typescript\n * const nube = getNubeInstance();\n * nube.on(\"location:updated\", (state) => {\n * console.log(\"Page updated:\", state.location.page);\n * });\n * ```\n *\n * @since 0.1.0\n */\nexport function getNubeInstance(): Readonly<NubeSDK> {\n\tconst instance = registeredInstance ?? readGlobalInstance();\n\n\tif (!instance) {\n\t\tthrow new Error(\n\t\t\t\"NubeSDK instance not registered. Call setNubeInstance(nube) at the start of your App(nube) entry point.\",\n\t\t);\n\t}\n\n\treturn instance;\n}\n\n/**\n * Clears the registered NubeSDK instance.\n *\n * Mainly useful for testing or for tearing down between app reloads.\n *\n * @since 0.1.0\n */\nexport function clearNubeInstance(): void {\n\tregisteredInstance = undefined;\n}\n","/**\n * @fileoverview Browser APIs access functions for NubeSDK\n *\n * This module provides utility functions to easily access\n * browser APIs through the NubeSDK instance.\n */\n\nimport type { NubeBrowserAPIs } from \"@tiendanube/nube-sdk-types\";\nimport { getNubeInstance } from \"./instance\";\n\n// Cache for the browser APIs instance\nlet instance: Readonly<NubeBrowserAPIs> | null = null;\n\n/**\n * Browser APIs available through NubeSDK.\n *\n * Provides access to browser storage, navigation, and other APIs\n * in a convenient and type-safe way.\n *\n * @example\n * ```typescript\n * // Use async localStorage\n * await browser.asyncLocalStorage.setItem('key', 'value');\n * const value = await browser.asyncLocalStorage.getItem('key');\n *\n * // Use async sessionStorage\n * await browser.asyncSessionStorage.setItem('session', 'data');\n *\n * // Navigate to a route\n * browser.navigate('/products/123');\n * ```\n *\n * @since 0.1.0\n */\nexport const browser = new Proxy({} as Readonly<NubeBrowserAPIs>, {\n\tget(_, prop: keyof NubeBrowserAPIs) {\n\t\t// Lazy load: create instance only when a property is accessed\n\t\tif (instance === null) {\n\t\t\tinstance = getNubeInstance().getBrowserAPIs();\n\t\t}\n\n\t\t// Return the property from the cached instance\n\t\treturn instance[prop];\n\t},\n});\n\n/**\n * Navigates to a specific route within the Nube application.\n *\n * @param route - The route to navigate to, must start with '/'\n *\n * @example\n * ```typescript\n * // Navigate to a product page\n * navigate('/products/123');\n *\n * // Navigate to home\n * navigate('/');\n *\n * ```\n *\n * @since 0.1.0\n */\nexport function navigate(route: `/${string}`): void {\n\tbrowser.navigate(route);\n}\n\n/**\n * Clears the browser APIs cache.\n *\n * This function is useful for testing or when you need to force\n * a fresh instance of the browser APIs to be created.\n *\n * @example\n * ```typescript\n * // Clear cache before testing\n * clearBrowserCache();\n *\n * // Next access to browser properties will create a new instance\n * await browser.asyncLocalStorage.setItem('key', 'value');\n * ```\n *\n * @since 0.1.0\n */\nexport function clearBrowserCache(): void {\n\tinstance = null;\n}\n","import type {\n\tNubeComponent,\n\tNubeSDKState,\n\tUISlot,\n} from \"@tiendanube/nube-sdk-types\";\nimport { getNubeInstance } from \"./instance\";\n\n/**\n * Visual variants supported by {@link UIHelper.showToast}.\n *\n * @since 0.1.0\n */\nexport type ToastVariant = \"success\" | \"error\" | \"warning\" | \"info\";\n\n/**\n * A component, list of components, or a render function that derives them from\n * the current state.\n *\n * @since 0.1.0\n */\nexport type RenderableComponent =\n\t| NubeComponent\n\t| NubeComponent[]\n\t| ((state: Readonly<NubeSDKState>) => NubeComponent | NubeComponent[]);\n\nexport type UIHelper = {\n\tshowToast: (message: string, variant?: ToastVariant) => void;\n\tclear: (slot: UISlot) => void;\n\trender: (slot: UISlot, component: RenderableComponent) => void;\n\trenderAll: (slots: UISlot[], component: RenderableComponent) => void;\n};\n\n/**\n * View helpers for NubeSDK.\n *\n * Provides methods to show toasts, clear slots, and render components.\n */\n\nexport const ui: Readonly<UIHelper> = Object.freeze({\n\t// Helpers for common components\n\tshowToast(message, variant = \"info\") {\n\t\tconst toast = {\n\t\t\ttype: \"toastRoot\" as const,\n\t\t\tvariant,\n\t\t\tchildren: [{ type: \"toastTitle\" as const, children: message }],\n\t\t};\n\t\tgetNubeInstance().render(\"corner_top_right\", toast);\n\t},\n\n\t// Clear slot\n\tclear(slot) {\n\t\tgetNubeInstance().clearSlot(slot);\n\t},\n\n\trender(slot, component) {\n\t\tgetNubeInstance().render(slot, component);\n\t},\n\n\t// Render the same component across multiple slots in a single call.\n\trenderAll(slots, component) {\n\t\tconst nube = getNubeInstance();\n\t\tfor (const slot of slots) {\n\t\t\tnube.render(slot, component);\n\t\t}\n\t},\n});\n","/**\n * @fileoverview Event subscription helpers for NubeSDK\n *\n * Thin, ergonomic wrappers around `nube.on` that return an unsubscribe\n * function, plus sugar for the very common \"show a toast when an event fires\"\n * pattern seen across apps.\n */\n\nimport type {\n\tEventListenerMap,\n\tNubeSDKListenableEvent,\n\tNubeSDKState,\n} from \"@tiendanube/nube-sdk-types\";\nimport { getNubeInstance } from \"./instance\";\nimport { type ToastVariant, ui } from \"./ui\";\n\n/**\n * Subscribes a listener to a NubeSDK event and returns an unsubscribe function.\n *\n * Equivalent to calling `nube.on(event, listener)`, but the returned function\n * detaches the listener via `nube.off`, so you don't need to hold a reference\n * to both the instance and the listener to clean it up.\n *\n * @param event - The event to listen for\n * @param listener - The listener to register\n * @returns An unsubscribe function\n *\n * @example\n * ```typescript\n * const unsubscribe = onEvent(\"cart:update\", (state) => {\n * console.log(\"Cart now has\", state.cart.items.length, \"items\");\n * });\n *\n * // Later:\n * unsubscribe();\n * ```\n *\n * @since 0.1.0\n */\nexport function onEvent<T extends NubeSDKListenableEvent>(\n\tevent: T,\n\tlistener: EventListenerMap[T],\n): () => void {\n\tconst nube = getNubeInstance();\n\tnube.on(event, listener);\n\treturn () => nube.off(event, listener);\n}\n\n/**\n * Shows a toast whenever the given event fires.\n *\n * Replaces the repetitive `nube.on(\"...:success\", () => ui.showToast(...))`\n * pattern. The message can be a static string or a function deriving it from\n * the current state.\n *\n * @param event - The event to listen for\n * @param message - The toast message, or a function returning it from state\n * @param variant - Optional toast variant (defaults to the {@link ui.showToast} default)\n * @returns An unsubscribe function\n *\n * @example\n * ```typescript\n * toastOn(\"cart:add:success\", \"Product added to cart\", \"success\");\n *\n * toastOn(\n * \"cart:update\",\n * (state) => `Cart updated: ${state.cart.items.length} items`,\n * );\n * ```\n *\n * @since 0.1.0\n */\nexport function toastOn<T extends NubeSDKListenableEvent>(\n\tevent: T,\n\tmessage: string | ((state: Readonly<NubeSDKState>) => string),\n\tvariant?: ToastVariant,\n): () => void {\n\tconst listener = ((state: Readonly<NubeSDKState>) => {\n\t\tconst text = typeof message === \"function\" ? message(state) : message;\n\t\tui.showToast(text, variant);\n\t}) as EventListenerMap[T];\n\n\treturn onEvent(event, listener);\n}\n","/**\n * @fileoverview Access functions for NubeSDK instance data\n *\n * This module provides utility functions to easily access\n * the SDK instance, current state and application data.\n */\n\nimport type { NubeSDKState, Nullable } from \"@tiendanube/nube-sdk-types\";\nimport { getNubeInstance } from \"./instance\";\n\n/**\n * Gets the current NubeSDK state.\n *\n * @returns The current readonly SDK state\n *\n * @example\n * ```typescript\n * const state = getCurrentState();\n * console.log('Current page:', state.location.page.type);\n * console.log('Page data:', state.location.page.data);\n * ```\n *\n * @since 0.1.0\n */\nexport function getCurrentState(): Readonly<NubeSDKState> {\n\treturn getNubeInstance().getState();\n}\n\n/**\n * Gets the current application data.\n *\n * @returns Readonly object containing application ID and script\n *\n * @example\n * ```typescript\n * const appData = getAppData();\n * console.log('Application ID:', appData.id);\n * console.log('Application script:', appData.script);\n * ```\n *\n * @since 0.1.0\n */\nexport function getAppData(): Readonly<{\n\tid: string;\n\tscript: string;\n}> {\n\treturn self.__APP_DATA__;\n}\n\nlet cachedScriptURL: Readonly<URL> | undefined;\n\n/**\n * Gets the parsed URL of the application script.\n *\n * @returns The readonly URL instance of the application script\n *\n * @example\n * ```typescript\n * const url = getScriptURL();\n * console.log('Script origin:', url.origin);\n * console.log('Script pathname:', url.pathname);\n * ```\n *\n * @since 0.1.0\n */\nexport function getScriptURL(): Readonly<URL> {\n\tif (!cachedScriptURL) {\n\t\tcachedScriptURL = Object.freeze(new URL(self.__APP_DATA__.script));\n\t}\n\treturn cachedScriptURL;\n}\n\n/**\n * Gets the search parameters of the application script URL.\n *\n * @returns The readonly URLSearchParams instance from the script URL\n *\n * @example\n * ```typescript\n * const params = getScriptSearchParams();\n * for (const [key, value] of params) {\n * console.log(`${key}: ${value}`);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function getScriptSearchParams(): Readonly<URLSearchParams> {\n\treturn getScriptURL().searchParams;\n}\n\n/**\n * Gets a specific search parameter from the application script URL.\n *\n * @param key - The name of the search parameter to retrieve\n * @returns The value of the search parameter, or null if not present\n *\n * @example\n * ```typescript\n * const version = getScriptParam('version');\n * if (version) {\n * console.log('Script version:', version);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function getScriptParam(key: string): Nullable<string> {\n\treturn getScriptSearchParams().get(key);\n}\n","/**\n * @fileoverview Internal primitive type guards shared across the guards folder.\n *\n * These are building blocks used by the domain-specific guards. They are NOT\n * part of the package's public API and are intentionally not re-exported by\n * `guards/index.ts`.\n *\n * @internal\n */\n\n/**\n * Internal type guard to check if a value is any kind of object (including arrays, dates, etc.)\n * Excludes null and primitive values\n *\n * @internal\n */\nexport function isObject(value: unknown): value is object {\n\treturn typeof value === \"object\" && value !== null;\n}\n\n/**\n * Internal type guard to check if a value is a plain object (not array, date, or other built-in objects)\n *\n * @internal\n */\nexport function isPlainObject(\n\tvalue: unknown,\n): value is Record<string, unknown> {\n\treturn (\n\t\tisObject(value) &&\n\t\t!Array.isArray(value) &&\n\t\tObject.prototype.toString.call(value) === \"[object Object]\"\n\t);\n}\n","/**\n * @fileoverview Address type guards for NubeSDK (address, shipping & billing).\n */\n\nimport type {\n\tAddress,\n\tBillingAddress,\n\tShippingAddress,\n} from \"@tiendanube/nube-sdk-types\";\nimport { isPlainObject } from \"../../internal/primitives\";\n\n/**\n * Type guard to check if a value is a valid address object\n *\n * @param value - The value to check\n * @returns True if the value is an Address\n *\n * @example\n * ```typescript\n * if (isAddress(data)) {\n * // data is now typed as Address\n * console.log(data.zipcode);\n * console.log(data.city);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isAddress(value: unknown): value is Address {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.zipcode === \"string\" &&\n\t\t(value.first_name === null || typeof value.first_name === \"string\") &&\n\t\t(value.last_name === null || typeof value.last_name === \"string\") &&\n\t\t(value.address === null || typeof value.address === \"string\") &&\n\t\t(value.number === null || typeof value.number === \"string\") &&\n\t\t(value.floor === null || typeof value.floor === \"string\") &&\n\t\t(value.locality === null || typeof value.locality === \"string\") &&\n\t\t(value.city === null || typeof value.city === \"string\") &&\n\t\t(value.state === null || typeof value.state === \"string\") &&\n\t\t(value.country === null || typeof value.country === \"string\") &&\n\t\t(value.phone === null || typeof value.phone === \"string\")\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid shipping address\n *\n * @param value - The value to check\n * @returns True if the value is a ShippingAddress\n *\n * @example\n * ```typescript\n * if (isShippingAddress(data)) {\n * // data is now typed as ShippingAddress\n * console.log(data.zipcode);\n * console.log(data.between_street);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isShippingAddress(value: unknown): value is ShippingAddress {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.zipcode === \"string\" &&\n\t\t(value.first_name === null || typeof value.first_name === \"string\") &&\n\t\t(value.last_name === null || typeof value.last_name === \"string\") &&\n\t\t(value.address === null || typeof value.address === \"string\") &&\n\t\t(value.number === null || typeof value.number === \"string\") &&\n\t\t(value.floor === null || typeof value.floor === \"string\") &&\n\t\t(value.locality === null || typeof value.locality === \"string\") &&\n\t\t(value.city === null || typeof value.city === \"string\") &&\n\t\t(value.state === null || typeof value.state === \"string\") &&\n\t\t(value.country === null || typeof value.country === \"string\") &&\n\t\t(value.phone === null || typeof value.phone === \"string\") &&\n\t\t(value.between_street === null ||\n\t\t\ttypeof value.between_street === \"string\") &&\n\t\t(value.reference === null || typeof value.reference === \"string\")\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid billing address\n *\n * @param value - The value to check\n * @returns True if the value is a BillingAddress\n *\n * @example\n * ```typescript\n * if (isBillingAddress(data)) {\n * // data is now typed as BillingAddress\n * console.log(data.zipcode);\n * console.log(data.business_name);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isBillingAddress(value: unknown): value is BillingAddress {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.zipcode === \"string\" &&\n\t\t(value.first_name === null || typeof value.first_name === \"string\") &&\n\t\t(value.last_name === null || typeof value.last_name === \"string\") &&\n\t\t(value.address === null || typeof value.address === \"string\") &&\n\t\t(value.number === null || typeof value.number === \"string\") &&\n\t\t(value.floor === null || typeof value.floor === \"string\") &&\n\t\t(value.locality === null || typeof value.locality === \"string\") &&\n\t\t(value.city === null || typeof value.city === \"string\") &&\n\t\t(value.state === null || typeof value.state === \"string\") &&\n\t\t(value.country === null || typeof value.country === \"string\") &&\n\t\t(value.phone === null || typeof value.phone === \"string\") &&\n\t\t(value.id_number === null || typeof value.id_number === \"string\") &&\n\t\t(value.customer_type === null || typeof value.customer_type === \"string\") &&\n\t\t(value.business_name === null || typeof value.business_name === \"string\") &&\n\t\t(value.trade_name === null || typeof value.trade_name === \"string\") &&\n\t\t(value.state_registration === null ||\n\t\t\ttypeof value.state_registration === \"string\") &&\n\t\t(value.fiscal_regime === null || typeof value.fiscal_regime === \"string\") &&\n\t\t(value.invoice_use === null || typeof value.invoice_use === \"string\") &&\n\t\t(value.document_type === null || typeof value.document_type === \"string\") &&\n\t\t(value.business_activity === null ||\n\t\t\ttypeof value.business_activity === \"string\")\n\t);\n}\n","/**\n * @fileoverview Cart type guards for NubeSDK.\n */\n\nimport type {\n\tCart,\n\tCartItem,\n\tCartValidation,\n\tCartValidationFail,\n\tCartValidationPending,\n\tCartValidationSuccess,\n} from \"@tiendanube/nube-sdk-types\";\nimport { isPlainObject } from \"../../internal/primitives\";\n\n/**\n * Type guard to check if a value is a valid cart object\n *\n * @param value - The value to check\n * @returns True if the value is a Cart\n *\n * @example\n * ```typescript\n * if (isCart(data)) {\n * // data is now typed as Cart\n * console.log(data.id);\n * console.log(data.items.length);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCart(value: unknown): value is Cart {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\tisPlainObject(value.validation) &&\n\t\ttypeof value.validation.status === \"string\" &&\n\t\tArray.isArray(value.items) &&\n\t\tisPlainObject(value.prices) &&\n\t\ttypeof value.prices.subtotal === \"number\" &&\n\t\ttypeof value.prices.total === \"number\" &&\n\t\tisPlainObject(value.coupon)\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid cart item\n *\n * @param value - The value to check\n * @returns True if the value is a CartItem\n *\n * @example\n * ```typescript\n * if (isCartItem(item)) {\n * // item is now typed as CartItem\n * console.log(item.name);\n * console.log(item.price);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCartItem(value: unknown): value is CartItem {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.id === \"number\" &&\n\t\ttypeof value.name === \"string\" &&\n\t\ttypeof value.price === \"string\" &&\n\t\ttypeof value.quantity === \"number\" &&\n\t\ttypeof value.free_shipping === \"boolean\" &&\n\t\ttypeof value.product_id === \"number\" &&\n\t\ttypeof value.variant_id === \"number\" &&\n\t\ttypeof value.thumbnail === \"string\" &&\n\t\ttypeof value.variant_values === \"string\" &&\n\t\ttypeof value.url === \"string\" &&\n\t\ttypeof value.is_ahora_12_eligible === \"boolean\"\n\t);\n}\n\n/**\n * Type guard to check if a cart validation is successful\n *\n * @param validation - The validation to check\n * @returns True if the validation is successful\n *\n * @example\n * ```typescript\n * if (isCartValidationSuccess(cart.validation)) {\n * // cart.validation is now typed as CartValidationSuccess\n * console.log('Cart is valid');\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCartValidationSuccess(\n\tvalidation: CartValidation,\n): validation is CartValidationSuccess {\n\treturn validation.status === \"success\";\n}\n\n/**\n * Type guard to check if a cart validation is pending\n *\n * @param validation - The validation to check\n * @returns True if the validation is pending\n *\n * @example\n * ```typescript\n * if (isCartValidationPending(cart.validation)) {\n * // cart.validation is now typed as CartValidationPending\n * console.log('Cart validation in progress...');\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCartValidationPending(\n\tvalidation: CartValidation,\n): validation is CartValidationPending {\n\treturn validation.status === \"pending\";\n}\n\n/**\n * Type guard to check if a cart validation failed\n *\n * @param validation - The validation to check\n * @returns True if the validation failed\n *\n * @example\n * ```typescript\n * if (isCartValidationFail(cart.validation)) {\n * // cart.validation is now typed as CartValidationFail\n * console.log('Cart validation failed:', cart.validation.reason);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCartValidationFail(\n\tvalidation: CartValidation,\n): validation is CartValidationFail {\n\treturn validation.status === \"fail\";\n}\n","/**\n * @fileoverview Component & page-data structure guards for NubeSDK.\n */\n\nimport type { NubeComponent, ProductDetails } from \"@tiendanube/nube-sdk-types\";\nimport { isObject, isPlainObject } from \"../../internal/primitives\";\n\n/**\n * Type guard to check if a value is a valid Nube component\n *\n * @param value - The value to check\n * @returns True if the value is a NubeComponent\n *\n * @example\n * ```typescript\n * if (isNubeComponent(component)) {\n * // component is now typed as NubeComponent\n * console.log(component.type);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isNubeComponent(value: unknown): value is NubeComponent {\n\treturn (\n\t\ttypeof value === \"string\" ||\n\t\t(isPlainObject(value) && typeof value.type === \"string\")\n\t);\n}\n\n/**\n * Type guard that checks if an object contains a list of products.\n *\n * This function verifies that the provided data is an object with a `products`\n * property that is an array of ProductDetails. Useful for validating page data\n * structures that may contain product lists.\n *\n * @param data - The unknown value to check\n * @returns True if data is an object with a `products` array property, false otherwise\n *\n * @example\n * ```typescript\n * const pageData = { products: [product1, product2] };\n * if (hasProductList(pageData)) {\n * // TypeScript now knows pageData.products exists and is ProductDetails[]\n * pageData.products.forEach(product => console.log(product.id));\n * }\n * ```\n */\nexport function hasProductList(\n\tdata: unknown,\n): data is { products: ProductDetails[] } {\n\treturn isObject(data) && \"products\" in data && Array.isArray(data.products);\n}\n\n/**\n * Type guard that checks if an object contains a list of sections.\n *\n * This function verifies that the provided data is an object with a `sections`\n * property that is an array. Useful for validating page data structures that\n * may contain section-based content.\n *\n * @param data - The unknown value to check\n * @returns True if data is an object with a `sections` array property, false otherwise\n *\n * @example\n * ```typescript\n * const pageData = { sections: [{ type: \"featured_products\", products: [] }] };\n * if (hasSections(pageData)) {\n * // TypeScript now knows pageData.sections exists and is an array\n * pageData.sections.forEach(section => processSection(section));\n * }\n * ```\n */\nexport function hasSections(data: unknown): data is { sections: unknown[] } {\n\treturn isObject(data) && \"sections\" in data && Array.isArray(data.sections);\n}\n\n/**\n * Type guard that checks if a section item contains products.\n *\n * This function verifies that the provided item is an object with a `products`\n * property that is an array of ProductDetails. Useful for iterating through\n * sections and filtering those that contain product lists.\n *\n * @param item - The unknown value to check (typically a section object)\n * @returns True if item is an object with a `products` array property, false otherwise\n *\n * @example\n * ```typescript\n * const sections = [{ type: \"featured_products\", products: [product1] }];\n * sections.forEach(section => {\n * if (isSectionWithProducts(section)) {\n * // TypeScript now knows section.products exists and is ProductDetails[]\n * section.products.forEach(product => renderProduct(product));\n * }\n * });\n * ```\n */\nexport function isSectionWithProducts(\n\titem: unknown,\n): item is { products: ProductDetails[] } {\n\treturn isObject(item) && \"products\" in item && Array.isArray(item.products);\n}\n\n/**\n * Type guard that checks if an object contains a single product (Product Detail Page).\n *\n * This function verifies that the provided data is an object with a `product`\n * property that is a valid ProductDetails object. It performs a minimal integrity\n * check by verifying the product has an `id` property. Useful for validating\n * product detail page data structures.\n *\n * @param data - The unknown value to check\n * @returns True if data is an object with a `product` property containing a valid ProductDetails, false otherwise\n *\n * @example\n * ```typescript\n * const pageData = { product: { id: 1, name: {...}, ... } };\n * if (hasSingleProduct(pageData)) {\n * // TypeScript now knows pageData.product exists and is ProductDetails\n * console.log(pageData.product.id);\n * }\n * ```\n */\nexport function hasSingleProduct(\n\tdata: unknown,\n): data is { product: ProductDetails } {\n\treturn (\n\t\tisObject(data) &&\n\t\t\"product\" in data &&\n\t\tisObject(data.product) &&\n\t\t\"id\" in data.product\n\t);\n}\n","/**\n * @fileoverview Domain type guards for NubeSDK (store, customer, payment, shipping).\n */\n\nimport type {\n\tCustomer,\n\tPayment,\n\tShipping,\n\tShippingOption,\n\tStore,\n} from \"@tiendanube/nube-sdk-types\";\nimport { isPlainObject } from \"../../internal/primitives\";\n\n/**\n * Type guard to check if a value is a valid store object\n *\n * @param value - The value to check\n * @returns True if the value is a Store\n *\n * @example\n * ```typescript\n * if (isStore(data)) {\n * // data is now typed as Store\n * console.log(data.name);\n * console.log(data.currency);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isStore(value: unknown): value is Store {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.id === \"number\" &&\n\t\ttypeof value.name === \"string\" &&\n\t\ttypeof value.domain === \"string\" &&\n\t\ttypeof value.currency === \"string\" &&\n\t\ttypeof value.language === \"string\"\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid customer object\n *\n * @param value - The value to check\n * @returns True if the value is a Customer\n *\n * @example\n * ```typescript\n * if (isCustomer(data)) {\n * // data is now typed as Customer\n * console.log(data.contact.email);\n * console.log(data.shipping_address.city);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCustomer(value: unknown): value is Customer {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\t(value.id === null || typeof value.id === \"number\") &&\n\t\tisPlainObject(value.contact) &&\n\t\tisPlainObject(value.shipping_address) &&\n\t\tisPlainObject(value.billing_address)\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid payment object\n *\n * @param value - The value to check\n * @returns True if the value is a Payment\n *\n * @example\n * ```typescript\n * if (isPayment(data)) {\n * // data is now typed as Payment\n * console.log(data.status);\n * console.log(data.selected?.method_name);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isPayment(value: unknown): value is Payment {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\t(value.status === null || typeof value.status === \"string\") &&\n\t\t(value.selected === null || isPlainObject(value.selected))\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid shipping object\n *\n * @param value - The value to check\n * @returns True if the value is a Shipping\n *\n * @example\n * ```typescript\n * if (isShipping(data)) {\n * // data is now typed as Shipping\n * console.log(data.selected);\n * console.log(data.options?.length);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isShipping(value: unknown): value is Shipping {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\t(value.selected === null || typeof value.selected === \"string\") &&\n\t\t(value.options === undefined || Array.isArray(value.options)) &&\n\t\t(value.custom_labels === undefined || isPlainObject(value.custom_labels))\n\t);\n}\n\n/**\n * Type guard to check if a value is a valid shipping option\n *\n * @param value - The value to check\n * @returns True if the value is a ShippingOption\n *\n * @example\n * ```typescript\n * if (isShippingOption(option)) {\n * // option is now typed as ShippingOption\n * console.log(option.name);\n * console.log(option.price);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isShippingOption(value: unknown): value is ShippingOption {\n\treturn (\n\t\tisPlainObject(value) &&\n\t\ttypeof value.id === \"string\" &&\n\t\ttypeof value.price === \"number\" &&\n\t\ttypeof value.currency === \"string\" &&\n\t\ttypeof value.phone_required === \"boolean\" &&\n\t\ttypeof value.id_required === \"boolean\" &&\n\t\ttypeof value.accepts_cod === \"boolean\" &&\n\t\ttypeof value.free_shipping_eligible === \"boolean\" &&\n\t\tisPlainObject(value.extra) &&\n\t\ttypeof value.hidden === \"boolean\" &&\n\t\ttypeof value.shippable === \"boolean\"\n\t);\n}\n","/**\n * @fileoverview Page type guards for NubeSDK.\n *\n * Runtime checks that narrow a `Page` to its specific page type.\n */\n\nimport type {\n\tAllProductsPage,\n\tCategoryPage,\n\tCheckoutPage,\n\tHomePage,\n\tPage,\n\tProductPage,\n\tSearchPage,\n} from \"@tiendanube/nube-sdk-types\";\n\n/**\n * Type guard to check if a page is a product page\n *\n * @param page - The page to check\n * @returns True if the page is a ProductPage\n *\n * @example\n * ```typescript\n * if (isProductPage(page)) {\n * // page is now typed as ProductPage\n * console.log(page.data.name);\n * console.log(page.data.variants);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isProductPage(page: Page): page is ProductPage {\n\treturn page.type === \"product\";\n}\n\n/**\n * Type guard to check if a page is a category page\n *\n * @param page - The page to check\n * @returns True if the page is a CategoryPage\n *\n * @example\n * ```typescript\n * if (isCategoryPage(page)) {\n * // page is now typed as CategoryPage\n * console.log(page.data.name);\n * console.log(page.data.id);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCategoryPage(page: Page): page is CategoryPage {\n\treturn page.type === \"category\";\n}\n\n/**\n * Type guard to check if a page is a checkout page\n *\n * @param page - The page to check\n * @returns True if the page is a CheckoutPage\n *\n * @example\n * ```typescript\n * if (isCheckoutPage(page)) {\n * // page is now typed as CheckoutPage\n * console.log(page.data.step);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isCheckoutPage(page: Page): page is CheckoutPage {\n\treturn page.type === \"checkout\";\n}\n\n/**\n * Type guard to check if a page is an all products page\n *\n * @param page - The page to check\n * @returns True if the page is an AllProductsPage\n *\n * @example\n * ```typescript\n * if (isAllProductsPage(page)) {\n * // page is now typed as AllProductsPage\n * console.log(page.data.id); // 0\n * console.log(page.data.products);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isAllProductsPage(page: Page): page is AllProductsPage {\n\treturn page.type === \"products\";\n}\n\n/**\n * Type guard to check if a page is a search page\n *\n * @param page - The page to check\n * @returns True if the page is a SearchPage\n *\n * @example\n * ```typescript\n * if (isSearchPage(page)) {\n * // page is now typed as SearchPage\n * console.log(page.data.q);\n * console.log(page.data.products);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isSearchPage(page: Page): page is SearchPage {\n\treturn page.type === \"search\";\n}\n\n/**\n * Type guard to check if a page is a home page\n *\n * @param page - The page to check\n * @returns True if the page is a HomePage\n *\n * @example\n * ```typescript\n * if (isHomePage(page)) {\n * // page is now typed as HomePage\n * console.log(page.data?.sections);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function isHomePage(page: Page): page is HomePage {\n\treturn page.type === \"home\";\n}\n","/**\n * @fileoverview Page matching system for NubeSDK\n *\n * This module provides a type-safe system for handling different page types\n * (product, category, checkout) and their respective data.\n * Includes functions for page matching and event handlers.\n */\n\nimport type {\n\tCategory,\n\tCheckout,\n\tHome,\n\tNubeSDKState,\n\tProductDetails,\n} from \"@tiendanube/nube-sdk-types\";\nimport {\n\tisCategoryPage,\n\tisCheckoutPage,\n\tisHomePage,\n\tisProductPage,\n} from \"./guards\";\nimport { getNubeInstance } from \"./instance\";\n\n/**\n * Maps each page type to its specific data payload.\n *\n * @example\n * ```typescript\n * // Product page data\n * const productData: PageDataMap['product'] = {\n * id: '123',\n * name: 'Example Product',\n * price: 29.99\n * };\n *\n * // Category page data\n * const categoryData: PageDataMap['category'] = {\n * id: 'cat-1',\n * name: 'Example Category',\n * products: []\n * };\n * ```\n *\n * @since 0.1.0\n */\nexport type PageDataMap = {\n\tproduct: ProductDetails;\n\tcategory: Category;\n\tcheckout: Checkout;\n\thome: Home;\n};\n\n/**\n * Typed handler for a given page type.\n *\n * @template T - The page type (product, category, checkout)\n * @param state - Current NubeSDK state\n * @param data - Page-specific data for the given page type\n *\n * @example\n * ```typescript\n * const productHandler: PageHandlerFunction<'product'> = (state, data) => {\n * console.log('Product viewed:', data.name);\n * trackProductView(data.id);\n * };\n *\n * const checkoutHandler: PageHandlerFunction<'checkout'> = (state, data) => {\n * if (data.step === 'success') {\n * trackPurchase(data.orderId);\n * }\n * };\n * ```\n *\n * @since 0.1.0\n */\nexport type PageHandlerFunction<T extends keyof PageDataMap> = (\n\tstate: NubeSDKState,\n\tdata: PageDataMap[T],\n) => void;\n\n/**\n * Partial set of handlers where only relevant page types need to be implemented.\n *\n * @example\n * ```typescript\n * const handlers: PageHandlers = {\n * product: (state, data) => trackProductView(data.id),\n * checkout: (state, data) => {\n * if (data.step === 'success') trackPurchase();\n * }\n * // category handler is optional\n * };\n * ```\n *\n * @since 0.1.0\n */\nexport type PageHandlers = {\n\t[K in keyof PageDataMap]?: PageHandlerFunction<K>;\n};\n\n/**\n * Dispatches to the appropriate handler based on the current page type.\n * Type inference guarantees that each handler receives the correct payload.\n *\n * @param state - Current NubeSDK state\n * @param handlers - Handlers mapped by page type\n *\n * @example\n * ```typescript\n * const state = getCurrentState();\n *\n * pageMatch(state, {\n * product: (state, data) => {\n * console.log('Product:', data.name, 'Price:', data.price);\n * },\n * category: (state, data) => {\n * console.log('Category:', data.name, 'Products:', data.products.length);\n * },\n * checkout: (state, data) => {\n * console.log('Checkout step:', data.step);\n * }\n * });\n * ```\n *\n * @since 0.1.0\n */\nexport function pageMatch(state: NubeSDKState, handlers: PageHandlers): void {\n\tconst { page } = state.location;\n\n\tif (isProductPage(page)) {\n\t\thandlers.product?.(state, page.data.product);\n\t\treturn;\n\t}\n\n\tif (isCategoryPage(page)) {\n\t\thandlers.category?.(state, page.data);\n\t\treturn;\n\t}\n\n\tif (isCheckoutPage(page)) {\n\t\thandlers.checkout?.(state, page.data);\n\t\treturn;\n\t}\n\n\tif (isHomePage(page)) {\n\t\thandlers.home?.(state, page.data);\n\t\treturn;\n\t}\n}\n\n/**\n * Subscribes to navigation changes and invokes handlers that match the current page.\n *\n * Functional pattern that detects the current page type and calls the\n * corresponding handler whenever navigation updates occur.\n *\n * @param handlers - Handlers mapped by page type\n * @returns An unsubscribe function that stops listening for navigation changes\n *\n * @example\n * ```typescript\n * const unsubscribe = onPage({\n * product: (state, data) => trackProductView(data.id),\n * checkout: (state, data) => {\n * if (data.step === 'success') trackPurchase();\n * }\n * });\n *\n * // Later, to stop listening:\n * unsubscribe();\n * ```\n *\n * @since 0.1.0\n */\nexport function onPage(handlers: PageHandlers): () => void {\n\tconst nube = getNubeInstance();\n\n\tconst currentState = nube.getState();\n\n\tpageMatch(currentState, handlers);\n\n\tconst listener = (state: NubeSDKState) => pageMatch(state, handlers);\n\tnube.on(\"location:updated\", listener);\n\n\treturn () => nube.off(\"location:updated\", listener);\n}\n\n/**\n * Union of all possible checkout steps.\n *\n * @since 0.1.0\n */\ntype CheckoutStep = Checkout[\"step\"];\n\n/**\n * Handlers per checkout step (e.g., 'cart', 'payment', 'success').\n * Only the steps you care about need to be provided.\n *\n * @example\n * ```typescript\n * const checkoutHandlers: CheckoutStepHandlers = {\n * cart: (state) => console.log('Cart step'),\n * payment: (state) => console.log('Payment step'),\n * success: (state) => console.log('Success step')\n * };\n * ```\n *\n * @since 0.1.0\n */\nexport type CheckoutStepHandlers = Partial<\n\tRecord<CheckoutStep, (state: NubeSDKState) => void>\n>;\n\n/**\n * Runs a handler when the checkout is ready and the current step matches.\n *\n * Listens to `checkout:ready` and, if the current page is a checkout,\n * invokes the handler registered for the current `Checkout.step`.\n *\n * @param handlers - Handlers keyed by checkout step\n * @returns An unsubscribe function that stops listening for checkout steps\n *\n * @example\n * ```typescript\n * const unsubscribe = onCheckoutStep({\n * cart: (state) => {\n * console.log('User is in cart step');\n * trackCartView();\n * },\n * success: (state) => {\n * console.log('Purchase completed');\n * trackPurchase();\n * }\n * });\n *\n * // Later, to stop listening:\n * unsubscribe();\n * ```\n *\n * @since 0.1.0\n */\nexport function onCheckoutStep(handlers: CheckoutStepHandlers): () => void {\n\tconst nube = getNubeInstance();\n\n\tconst currentState = nube.getState();\n\tconst currentPage = currentState.location.page;\n\n\tif (currentPage.type === \"checkout\") {\n\t\thandlers[currentPage?.data?.step]?.(currentState);\n\t}\n\n\tconst listener = (state: NubeSDKState) => {\n\t\tconst { page } = state.location;\n\t\tif (page.type !== \"checkout\") return;\n\t\tconst step: CheckoutStep = page.data.step;\n\t\thandlers[step]?.(state);\n\t};\n\tnube.on(\"checkout:ready\", listener);\n\n\treturn () => nube.off(\"checkout:ready\", listener);\n}\n","/**\n * @fileoverview Render helpers for NubeSDK\n *\n * This module provides utilities to extract products from state and\n * iterate over them for rendering (e.g., in grid slots).\n */\n\nimport type {\n\tNubeComponent,\n\tNubeSDKState,\n\tProductDetails,\n} from \"@tiendanube/nube-sdk-types\";\nimport {\n\thasProductList,\n\thasSections,\n\thasSingleProduct,\n\tisSectionWithProducts,\n} from \"./guards\";\n\n/**\n * Extracts all products from the NubeSDK state, regardless of the page type.\n * Strategy: \"Greedy\" (Aggressive Collection).\n *\n * This function collects products from multiple sources within the state:\n * - Direct product lists in category, products, and search pages\n * - Products within sections for home, product, category, and products pages\n * - The main product in product detail pages\n *\n * @param state - The current NubeSDK state containing location and page information\n * @returns An array of ProductDetails. Returns an empty array if no products are found\n * or if the page structure doesn't contain products.\n *\n * @example\n * ```typescript\n * const state = nube.getState();\n * const products = getProductsFromState(state);\n * products.forEach(product => console.log(product.id));\n * ```\n */\nexport function getProductsFromState(state: NubeSDKState): ProductDetails[] {\n\tconst { page } = state.location;\n\n\tif (!page || !(\"data\" in page) || !page.data) {\n\t\treturn [];\n\t}\n\n\tconst products: ProductDetails[] = [];\n\n\tif (hasProductList(page.data)) {\n\t\tproducts.push(...page.data.products);\n\t}\n\n\tif (hasSections(page.data)) {\n\t\tfor (const section of page.data.sections) {\n\t\t\tif (isSectionWithProducts(section)) {\n\t\t\t\tproducts.push(...section.products);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (hasSingleProduct(page.data)) {\n\t\tproducts.push(page.data.product);\n\t}\n\n\treturn products;\n}\n\n/**\n * Creates a higher-order function that iterates over products in grid slots.\n *\n * This helper abstracts page type checking, product iteration, and automatic key generation.\n * It extracts products from the state, maps them through a render factory function,\n * filters out null/undefined results, and automatically injects unique keys for each component.\n *\n * @param renderFactory - A function that receives a ProductDetails and returns a NubeComponent,\n * null, or undefined. Components returning null/undefined are filtered out.\n * @returns A function that accepts NubeSDKState and returns an array of NubeComponent instances\n * with automatically generated keys using the product ID.\n *\n * @example\n * ```typescript\n * nube.render(\n * \"product_grid_item_image_bottom_right\",\n * forEachProduct((product) => <MyBadge product={product} />)\n * );\n * ```\n */\nexport function forEachProduct(\n\trenderFactory: (product: ProductDetails) => NubeComponent | null | undefined,\n) {\n\treturn (state: NubeSDKState): NubeComponent[] => {\n\t\tconst products = getProductsFromState(state);\n\n\t\tif (!products.length) return [];\n\n\t\treturn products.reduce<NubeComponent[]>((acc, product) => {\n\t\t\tconst component = renderFactory(product);\n\n\t\t\tif (component) {\n\t\t\t\tacc.push(Object.assign({}, component, { key: product.id }));\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t}, []);\n\t};\n}\n","/**\n * @fileoverview State selectors for NubeSDK\n *\n * Small, focused accessors for the most frequently read slices of the SDK\n * state. Each selector accepts an optional `state`; when omitted it reads the\n * current state from the registered instance, so apps don't need to repeat\n * `const state = nube.getState()` everywhere.\n */\n\nimport type {\n\tCart,\n\tCartItem,\n\tCustomer,\n\tNubeSDKState,\n\tNullable,\n\tPage,\n} from \"@tiendanube/nube-sdk-types\";\nimport { getCurrentState } from \"./getters\";\n\n/**\n * Gets the current cart.\n *\n * @param state - Optional state; defaults to the current SDK state\n * @returns The cart\n *\n * @example\n * ```typescript\n * const cart = getCart();\n * console.log(\"Items:\", cart.items.length);\n * ```\n *\n * @since 0.1.0\n */\nexport function getCart(state: NubeSDKState = getCurrentState()): Cart {\n\treturn state.cart;\n}\n\n/**\n * Gets the items currently in the cart.\n *\n * @param state - Optional state; defaults to the current SDK state\n * @returns The list of cart items\n *\n * @example\n * ```typescript\n * for (const item of getCartItems()) {\n * console.log(item.name, item.quantity);\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function getCartItems(\n\tstate: NubeSDKState = getCurrentState(),\n): CartItem[] {\n\treturn state.cart.items;\n}\n\n/**\n * Gets the type of the current page (e.g. `\"home\"`, `\"product\"`, `\"checkout\"`).\n *\n * @param state - Optional state; defaults to the current SDK state\n * @returns The current page type\n *\n * @example\n * ```typescript\n * if (getPageType() === \"checkout\") {\n * // checkout-specific logic\n * }\n * ```\n *\n * @since 0.1.0\n */\nexport function getPageType(\n\tstate: NubeSDKState = getCurrentState(),\n): Page[\"type\"] {\n\treturn state.location.page.type;\n}\n\n/**\n * Gets the current customer, or `null` when not available on the current page.\n *\n * @param state - Optional state; defaults to the current SDK state\n * @returns The customer or `null`\n *\n * @example\n * ```typescript\n * const customer = getCustomer();\n * if (customer) console.log(customer.contact?.email);\n * ```\n *\n * @since 0.1.0\n */\nexport function getCustomer(\n\tstate: NubeSDKState = getCurrentState(),\n): Nullable<Customer> {\n\treturn state.customer;\n}\n","/**\n * @fileoverview General utility functions for NubeSDK\n *\n * This module provides general-purpose utility functions including\n * deep cloning, debouncing, and throttling capabilities.\n */\n\n/**\n * Deep clones a value.\n *\n * Uses the structured clone algorithm when available (it is, in the NubeSDK\n * Web Worker runtime), which correctly handles `Date`, `Map`, `Set`, typed\n * arrays and circular references. Falls back to JSON serialization in\n * environments without `structuredClone` (with the usual JSON limitations:\n * functions, symbols and `undefined` are dropped).\n *\n * @template T - The type of the value to clone\n * @param obj - The value to deep clone\n * @returns A deep clone of the input value\n *\n * @example\n * ```typescript\n * const original = { name: 'John', age: 30, hobbies: ['reading', 'coding'] };\n * const cloned = deepClone(original);\n *\n * cloned.name = 'Jane';\n * cloned.hobbies.push('gaming');\n *\n * console.log(original.name); // 'John' (unchanged)\n * console.log(original.hobbies); // ['reading', 'coding'] (unchanged)\n * ```\n *\n * @since 0.1.0\n */\nexport function deepClone<T>(obj: T): T {\n\tif (obj === null || typeof obj !== \"object\") {\n\t\treturn obj;\n\t}\n\tif (typeof structuredClone === \"function\") {\n\t\treturn structuredClone(obj);\n\t}\n\treturn JSON.parse(JSON.stringify(obj));\n}\n\n/**\n * Debounces a function call, ensuring it only executes after a specified\n * delay has passed since the last invocation.\n *\n * @template T - The function type\n * @param func - The function to debounce\n * @param wait - The number of milliseconds to delay\n * @returns A debounced version of the function\n *\n * @example\n * ```typescript\n * const debouncedSearch = debounce((query: string) => {\n * console.log('Searching for:', query);\n * // Perform search operation\n * }, 300);\n *\n * // Multiple rapid calls will only execute the last one after 300ms\n * debouncedSearch('a');\n * debouncedSearch('ab');\n * debouncedSearch('abc'); // Only this will execute\n * ```\n *\n * @since 0.1.0\n */\nexport function debounce<T extends (...args: never[]) => unknown>(\n\tfunc: T,\n\twait: number,\n): (...args: Parameters<T>) => void {\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\n\treturn (...args: Parameters<T>): void => {\n\t\tconst later = () => {\n\t\t\ttimeout = undefined;\n\t\t\tfunc(...args);\n\t\t};\n\n\t\tif (timeout) {\n\t\t\tclearTimeout(timeout);\n\t\t}\n\t\ttimeout = setTimeout(later, wait);\n\t};\n}\n\n/**\n * Creates a throttled version of a function that will only execute\n * at most once per specified time limit.\n *\n * @template T - The function type\n * @param func - The function to throttle\n * @param limit - The time limit in milliseconds\n * @returns A throttled version of the function\n *\n * @example\n * ```typescript\n * const throttledScroll = throttle((event: Event) => {\n * console.log('Scroll event:', event);\n * // Handle scroll event\n * }, 100);\n *\n * // Even with rapid scroll events, the function will only execute\n * // once every 100ms\n * window.addEventListener('scroll', throttledScroll);\n * ```\n *\n * @since 0.1.0\n */\nexport function throttle<T extends (...args: never[]) => unknown>(\n\tfunc: T,\n\tlimit: number,\n): (...args: Parameters<T>) => void {\n\tlet inThrottle: boolean;\n\n\treturn (...args: Parameters<T>): void => {\n\t\tif (!inThrottle) {\n\t\t\tfunc(...args);\n\t\t\tinThrottle = true;\n\t\t\tsetTimeout(() => {\n\t\t\t\tinThrottle = false;\n\t\t\t}, limit);\n\t\t}\n\t};\n}\n"],"mappings":";AAgBA,IAAI;AAMJ,SAAS,qBAAoD;AAC5D,SAAO,OAAO,SAAS,cAAc,KAAK,mBAAmB;AAC9D;AAyBO,SAAS,gBAAgB,MAA+B;AAC9D,uBAAqB;AACtB;AAsBO,SAAS,kBAAqC;AACpD,QAAMA,YAAW,sBAAsB,mBAAmB;AAE1D,MAAI,CAACA,WAAU;AACd,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,SAAOA;AACR;AASO,SAAS,oBAA0B;AACzC,uBAAqB;AACtB;;;ACnFA,IAAI,WAA6C;AAuB1C,IAAM,UAAU,IAAI,MAAM,CAAC,GAAgC;AAAA,EACjE,IAAI,GAAG,MAA6B;AAEnC,QAAI,aAAa,MAAM;AACtB,iBAAW,gBAAgB,EAAE,eAAe;AAAA,IAC7C;AAGA,WAAO,SAAS,IAAI;AAAA,EACrB;AACD,CAAC;AAmBM,SAAS,SAAS,OAA2B;AACnD,UAAQ,SAAS,KAAK;AACvB;AAmBO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AI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC5C,WAAO;AAAA,EACR;AACA,MAAI,OAAO,oBAAoB,YAAY;AAC1C,WAAO,gBAAgB,GAAG;AAAA,EAC3B;AACA,SAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AACtC;AA0BO,SAAS,SACf,MACA,MACmC;AACnC,MAAI;AAEJ,SAAO,IAAI,SAA8B;AACxC,UAAM,QAAQ,MAAM;AACnB,gBAAU;AACV,WAAK,GAAG,IAAI;AAAA,IACb;AAEA,QAAI,SAAS;AACZ,mBAAa,OAAO;AAAA,IACrB;AACA,cAAU,WAAW,OAAO,IAAI;AAAA,EACjC;AACD;AAyBO,SAAS,SACf,MACA,OACmC;AACnC,MAAI;AAEJ,SAAO,IAAI,SAA8B;AACxC,QAAI,CAAC,YAAY;AAChB,WAAK,GAAG,IAAI;AACZ,mBAAa;AACb,iBAAW,MAAM;AAChB,qBAAa;AAAA,MACd,GAAG,KAAK;AAAA,IACT;AAAA,EACD;AACD;","names":["instance"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tiendanube/nube-sdk-helper",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Utility functions, type guards, and SDK instance management for NubeSDK apps",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup",
|
|
10
|
+
"check": "biome check src",
|
|
11
|
+
"check:fix": "biome check --write src",
|
|
12
|
+
"test": "vitest run",
|
|
13
|
+
"test:watch": "vitest",
|
|
14
|
+
"test:coverage": "vitest run --coverage"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/TiendaNube/nube-sdk.git"
|
|
19
|
+
},
|
|
20
|
+
"author": "Nuvemshop / TiendaNube",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/TiendaNube/nube-sdk/issues"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://www.tiendanube.com",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@biomejs/biome": "1.8.3",
|
|
28
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
29
|
+
"tsup": "^8.3.5",
|
|
30
|
+
"typescript": "^5.6.2",
|
|
31
|
+
"vitest": "^3.2.4"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@tiendanube/nube-sdk-types": "*"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"./dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"CHANGELOG.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"keywords": [
|
|
43
|
+
"tiendanube",
|
|
44
|
+
"nuvemshop",
|
|
45
|
+
"nube-sdk",
|
|
46
|
+
"ecommerce",
|
|
47
|
+
"sdk",
|
|
48
|
+
"helper",
|
|
49
|
+
"utilities",
|
|
50
|
+
"typeguards"
|
|
51
|
+
]
|
|
52
|
+
}
|