@ecomiq/storefront 0.1.1 → 0.1.2
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 +144 -47
- package/dist/..d.ts +30 -0
- package/dist/core.d.ts +47 -42
- package/dist/core.js +324 -212
- package/dist/core.js.map +1 -1
- package/dist/{find-storefront-cms-page-c8CktSz7.d.ts → find-storefront-cms-page-DNwLo1iV.d.ts} +17 -3
- package/dist/index.d.ts +30 -0
- package/dist/index.js +103 -0
- package/dist/index.js.map +1 -0
- package/dist/nextjs.d.ts +119 -111
- package/dist/nextjs.js +336 -43
- package/dist/nextjs.js.map +1 -1
- package/dist/react.d.ts +84 -83
- package/dist/react.js +342 -238
- package/dist/react.js.map +1 -1
- package/package.json +5 -1
- package/dist/{store-to_vuWRF.d.ts → collection-anMkdWa7.d.ts} +2666 -2666
package/dist/react.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { Modal } from '@ecomiq/ui/components/modal';
|
|
3
|
-
import { formatCurrency as formatCurrency$1, StorefrontPageDetailSchema as StorefrontPageDetailSchema$1, useCart as useCart$1, useStore as useStore$1, useStorefrontAuthClient as useStorefrontAuthClient$1, useStorefrontSession as useStorefrontSession$1, SignInForm, SignUpForm,
|
|
3
|
+
import { formatCurrency as formatCurrency$1, StorefrontPageDetailSchema as StorefrontPageDetailSchema$1, useCart as useCart$1, useStore as useStore$1, useStorefrontAuthClient as useStorefrontAuthClient$1, useStorefrontSession as useStorefrontSession$1, SignInForm, SignUpForm, signInWithEcomiqCredentials } from '@ecomiq/storefront/react';
|
|
4
4
|
import { toast, Toaster as Toaster$1 } from 'sonner';
|
|
5
5
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
6
6
|
import { useTheme } from 'next-themes';
|
|
7
7
|
import axios from 'axios';
|
|
8
|
+
import { existsSync } from 'fs';
|
|
9
|
+
import { createRequire } from 'module';
|
|
10
|
+
import { join } from 'path';
|
|
11
|
+
import '@opennextjs/cloudflare';
|
|
12
|
+
import '@ecomiq/storefront/core';
|
|
8
13
|
import { QueryClient, hydrate, QueryClientProvider, useMutation, useQuery, useQueryClient, useInfiniteQuery } from '@tanstack/react-query';
|
|
9
14
|
import React2, { createContext, useRef, useEffect, useContext, useState, useMemo, useCallback } from 'react';
|
|
10
15
|
import { create } from 'zustand';
|
|
@@ -249,31 +254,8 @@ var init_modals_factory = __esm({
|
|
|
249
254
|
const authClient = useStorefrontAuthClient$1();
|
|
250
255
|
const { refetch } = useStorefrontSession$1();
|
|
251
256
|
const handlerLogin = async (values) => {
|
|
252
|
-
const settings = store.data;
|
|
253
|
-
const record = storefrontStoreRecord$1(settings);
|
|
254
|
-
const checkout = record?.checkoutSettings;
|
|
255
|
-
if (!record?.id) {
|
|
256
|
-
toast.error("Tienda no disponible");
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
const identityScope = checkout?.identityScope === "tenant" ? "tenant" : "store";
|
|
260
|
-
const identityHeaders = {
|
|
261
|
-
"x-Identity-Scope": identityScope,
|
|
262
|
-
"x-Store-Id": record.id
|
|
263
|
-
};
|
|
264
|
-
if (record.tenantId) {
|
|
265
|
-
identityHeaders["x-Tenant-Id"] = record.tenantId;
|
|
266
|
-
}
|
|
267
257
|
try {
|
|
268
|
-
|
|
269
|
-
method: "POST",
|
|
270
|
-
headers: identityHeaders,
|
|
271
|
-
body: { email: values.email, password: values.password }
|
|
272
|
-
});
|
|
273
|
-
if (response.error) {
|
|
274
|
-
toast.error(response.error.message);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
258
|
+
await signInWithEcomiqCredentials(authClient, store.data, values);
|
|
277
259
|
const me = await getCustomerMe();
|
|
278
260
|
const displayName = `${me.firstName} ${me.lastName}`.trim() || me.email;
|
|
279
261
|
const updateUserResponse = await authClient.$fetch("/update-user", {
|
|
@@ -431,6 +413,232 @@ function formatCurrency(amount, currency = "USD") {
|
|
|
431
413
|
currency
|
|
432
414
|
}).format(amount);
|
|
433
415
|
}
|
|
416
|
+
var StorefrontCheckoutSettingsSchema = z.object({
|
|
417
|
+
allowGuestCheckout: z.boolean().optional(),
|
|
418
|
+
identityScope: z.enum(["store", "tenant", "global"]).optional(),
|
|
419
|
+
signInMethods: z.array(z.string()).optional()
|
|
420
|
+
});
|
|
421
|
+
var looseRecord = z.record(z.string(), z.unknown());
|
|
422
|
+
var StorefrontThemeConfigSchema = z.object({
|
|
423
|
+
name: z.string().nullable().optional(),
|
|
424
|
+
mode: z.string().nullable().optional(),
|
|
425
|
+
colors: looseRecord.optional(),
|
|
426
|
+
fonts: looseRecord.optional(),
|
|
427
|
+
assets: looseRecord.optional()
|
|
428
|
+
}).passthrough();
|
|
429
|
+
var StorefrontFeaturesEnabledSchema = z.object({
|
|
430
|
+
flags: looseRecord.optional()
|
|
431
|
+
}).passthrough();
|
|
432
|
+
var StorefrontCmsBrandingSchema = z.object({
|
|
433
|
+
logoUrl: z.string().nullable().optional(),
|
|
434
|
+
logoDarkUrl: z.string().nullable().optional(),
|
|
435
|
+
faviconUrl: z.string().nullable().optional(),
|
|
436
|
+
socialImageUrl: z.string().nullable().optional()
|
|
437
|
+
});
|
|
438
|
+
var StorefrontCmsSeoSchema = z.object({
|
|
439
|
+
siteName: z.string().nullable().optional(),
|
|
440
|
+
metaTitle: z.string().nullable().optional(),
|
|
441
|
+
metaDescription: z.string().nullable().optional(),
|
|
442
|
+
titleTemplate: z.string().nullable().optional(),
|
|
443
|
+
robotsIndex: z.boolean().optional()
|
|
444
|
+
});
|
|
445
|
+
var StorefrontCmsSocialLinksSchema = z.object({
|
|
446
|
+
instagram: z.string().nullable().optional(),
|
|
447
|
+
facebook: z.string().nullable().optional(),
|
|
448
|
+
tiktok: z.string().nullable().optional(),
|
|
449
|
+
youtube: z.string().nullable().optional(),
|
|
450
|
+
x: z.string().nullable().optional()
|
|
451
|
+
});
|
|
452
|
+
var StorefrontCmsContactSchema = z.object({
|
|
453
|
+
supportEmail: z.string().nullable().optional(),
|
|
454
|
+
phone: z.string().nullable().optional(),
|
|
455
|
+
whatsapp: z.string().nullable().optional(),
|
|
456
|
+
address: z.string().nullable().optional(),
|
|
457
|
+
socialLinks: StorefrontCmsSocialLinksSchema.optional()
|
|
458
|
+
});
|
|
459
|
+
var StorefrontCmsTrackingSchema = z.object({
|
|
460
|
+
googleAnalyticsMeasurementId: z.string().nullable().optional(),
|
|
461
|
+
metaPixelId: z.string().nullable().optional(),
|
|
462
|
+
googleTagManagerContainerId: z.string().nullable().optional()
|
|
463
|
+
});
|
|
464
|
+
var StorefrontCmsCustomScriptsSchema = z.object({
|
|
465
|
+
enabled: z.boolean().optional(),
|
|
466
|
+
head: z.string().nullable().optional(),
|
|
467
|
+
bodyEnd: z.string().nullable().optional()
|
|
468
|
+
});
|
|
469
|
+
var StorefrontCmsSettingsSchema = z.object({
|
|
470
|
+
themeKey: z.string().optional(),
|
|
471
|
+
branding: StorefrontCmsBrandingSchema.optional(),
|
|
472
|
+
seo: StorefrontCmsSeoSchema.optional(),
|
|
473
|
+
contact: StorefrontCmsContactSchema.optional(),
|
|
474
|
+
tracking: StorefrontCmsTrackingSchema.optional(),
|
|
475
|
+
customScripts: StorefrontCmsCustomScriptsSchema.optional(),
|
|
476
|
+
updatedOn: z.string().nullable().optional()
|
|
477
|
+
});
|
|
478
|
+
var StorefrontCmsPageSchema = z.object({
|
|
479
|
+
id: z.string(),
|
|
480
|
+
name: z.string(),
|
|
481
|
+
slug: z.string(),
|
|
482
|
+
layout: z.string().optional(),
|
|
483
|
+
version: z.number().optional(),
|
|
484
|
+
settings: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
485
|
+
sections: z.array(z.unknown()).optional(),
|
|
486
|
+
status: z.string().optional(),
|
|
487
|
+
hasPublishedVersion: z.boolean().optional(),
|
|
488
|
+
publishedOn: z.string().nullable().optional(),
|
|
489
|
+
publishedBy: z.string().nullable().optional(),
|
|
490
|
+
createdOn: z.string().nullable().optional(),
|
|
491
|
+
updatedOn: z.string().nullable().optional(),
|
|
492
|
+
createdBy: z.string().nullable().optional(),
|
|
493
|
+
updatedBy: z.string().nullable().optional(),
|
|
494
|
+
lastModifiedBy: z.string().nullable().optional()
|
|
495
|
+
}).passthrough();
|
|
496
|
+
var StorefrontSettingsLegacyFlatSchema = z.object({
|
|
497
|
+
id: z.coerce.string(),
|
|
498
|
+
tenantId: z.string().nullable().optional(),
|
|
499
|
+
name: z.string(),
|
|
500
|
+
slug: z.coerce.string().optional(),
|
|
501
|
+
description: z.string().nullable().optional(),
|
|
502
|
+
visibility: z.string().nullable().optional(),
|
|
503
|
+
logo: z.string().nullable().optional(),
|
|
504
|
+
favicon: z.string().nullable().optional(),
|
|
505
|
+
icon: z.string().nullable().optional(),
|
|
506
|
+
currency: z.string().nullable().optional(),
|
|
507
|
+
language: z.string().nullable().optional(),
|
|
508
|
+
themeConfig: z.unknown().optional().nullable(),
|
|
509
|
+
featuresEnabled: z.unknown().optional().nullable(),
|
|
510
|
+
checkoutSettings: StorefrontCheckoutSettingsSchema.optional().nullable()
|
|
511
|
+
}).passthrough();
|
|
512
|
+
function unwrapSettingsResponseBody(v) {
|
|
513
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return v;
|
|
514
|
+
const o = v;
|
|
515
|
+
if ("data" in o && o.data != null && typeof o.data === "object" && !Array.isArray(o.data)) {
|
|
516
|
+
return o.data;
|
|
517
|
+
}
|
|
518
|
+
return v;
|
|
519
|
+
}
|
|
520
|
+
function isLegacyFlatSettingsPayload(v) {
|
|
521
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
522
|
+
const o = v;
|
|
523
|
+
if ("store" in o || "schemaVersion" in o || "cms" in o) return false;
|
|
524
|
+
return (typeof o.id === "string" || typeof o.id === "number") && typeof o.name === "string";
|
|
525
|
+
}
|
|
526
|
+
function normalizeStorefrontSettingsPayload(v) {
|
|
527
|
+
const body = unwrapSettingsResponseBody(v);
|
|
528
|
+
if (!isLegacyFlatSettingsPayload(body)) return body;
|
|
529
|
+
const raw = body;
|
|
530
|
+
const parsed = StorefrontSettingsLegacyFlatSchema.safeParse(raw);
|
|
531
|
+
if (!parsed.success) return body;
|
|
532
|
+
const l = parsed.data;
|
|
533
|
+
const currency = l.currency?.trim() ? l.currency : "PEN";
|
|
534
|
+
const language = l.language?.trim() ? l.language : "es";
|
|
535
|
+
const slug = l.slug?.trim() ? l.slug : l.id;
|
|
536
|
+
return {
|
|
537
|
+
schemaVersion: 0,
|
|
538
|
+
generatedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
539
|
+
store: {
|
|
540
|
+
id: l.id,
|
|
541
|
+
tenantId: l.tenantId ?? void 0,
|
|
542
|
+
name: l.name,
|
|
543
|
+
slug,
|
|
544
|
+
description: l.description ?? null,
|
|
545
|
+
logo: l.logo ?? null,
|
|
546
|
+
icon: l.icon ?? null,
|
|
547
|
+
visibility: l.visibility ?? void 0,
|
|
548
|
+
currency,
|
|
549
|
+
language,
|
|
550
|
+
themeConfig: l.themeConfig ?? void 0,
|
|
551
|
+
featuresEnabled: l.featuresEnabled ?? void 0,
|
|
552
|
+
checkoutSettings: l.checkoutSettings ?? void 0
|
|
553
|
+
},
|
|
554
|
+
cms: {
|
|
555
|
+
settings: {
|
|
556
|
+
branding: {
|
|
557
|
+
faviconUrl: l.favicon ?? null,
|
|
558
|
+
logoUrl: l.logo ?? null,
|
|
559
|
+
logoDarkUrl: null,
|
|
560
|
+
socialImageUrl: null
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
pages: []
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
var StorefrontStoreSchema = z.object({
|
|
568
|
+
id: z.string(),
|
|
569
|
+
tenantId: z.string().optional(),
|
|
570
|
+
sellerId: z.string().optional(),
|
|
571
|
+
plan: z.string().optional(),
|
|
572
|
+
storageLimitBytes: z.number().optional(),
|
|
573
|
+
monthlyTransferLimitBytes: z.number().optional(),
|
|
574
|
+
maxUploadSizeBytes: z.number().optional(),
|
|
575
|
+
maxStores: z.number().optional(),
|
|
576
|
+
maxMembers: z.number().optional(),
|
|
577
|
+
maxProducts: z.number().optional(),
|
|
578
|
+
maxCategories: z.number().optional(),
|
|
579
|
+
maxBrands: z.number().optional(),
|
|
580
|
+
maxAttributes: z.number().optional(),
|
|
581
|
+
maxCollections: z.number().optional(),
|
|
582
|
+
enableApi: z.boolean().optional(),
|
|
583
|
+
isActive: z.boolean().optional(),
|
|
584
|
+
name: z.string(),
|
|
585
|
+
description: z.string().nullable().optional(),
|
|
586
|
+
avatarUrl: z.string().nullable().optional(),
|
|
587
|
+
logo: z.string().nullable().optional(),
|
|
588
|
+
icon: z.string().nullable().optional(),
|
|
589
|
+
slug: z.string(),
|
|
590
|
+
domain: z.string().nullable().optional(),
|
|
591
|
+
domains: z.array(z.string()).optional(),
|
|
592
|
+
timeZone: z.string().nullable().optional(),
|
|
593
|
+
currency: z.string(),
|
|
594
|
+
language: z.string(),
|
|
595
|
+
visibility: z.string().optional(),
|
|
596
|
+
privateAccessHash: z.string().nullable().optional(),
|
|
597
|
+
privateAccessVersion: z.number().optional(),
|
|
598
|
+
themeConfig: StorefrontThemeConfigSchema.optional(),
|
|
599
|
+
featuresEnabled: StorefrontFeaturesEnabledSchema.optional(),
|
|
600
|
+
checkoutSettings: StorefrontCheckoutSettingsSchema.optional().nullable()
|
|
601
|
+
}).passthrough();
|
|
602
|
+
var StorefrontSettingsEnvelopeSchema = z.object({
|
|
603
|
+
schemaVersion: z.number(),
|
|
604
|
+
generatedAt: z.string(),
|
|
605
|
+
store: StorefrontStoreSchema,
|
|
606
|
+
cms: z.object({
|
|
607
|
+
settings: StorefrontCmsSettingsSchema,
|
|
608
|
+
pages: z.array(StorefrontCmsPageSchema)
|
|
609
|
+
})
|
|
610
|
+
}).passthrough();
|
|
611
|
+
var StorefrontSettingsSchema = z.preprocess(
|
|
612
|
+
normalizeStorefrontSettingsPayload,
|
|
613
|
+
StorefrontSettingsEnvelopeSchema
|
|
614
|
+
);
|
|
615
|
+
function storefrontStoreRecord(settings) {
|
|
616
|
+
return settings?.store ?? null;
|
|
617
|
+
}
|
|
618
|
+
function storefrontFaviconUrl(settings) {
|
|
619
|
+
const b = settings?.cms?.settings?.branding;
|
|
620
|
+
return b?.faviconUrl ?? settings?.store?.logo ?? settings?.store?.icon ?? null;
|
|
621
|
+
}
|
|
622
|
+
function storefrontOgImageUrl(settings) {
|
|
623
|
+
const b = settings?.cms?.settings?.branding;
|
|
624
|
+
return b?.socialImageUrl ?? settings?.store?.logo ?? null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/core/lib/ecomiq-oauth-identity.ts
|
|
628
|
+
function buildEcomiqOAuthIdentityHeaders(settings) {
|
|
629
|
+
const record = storefrontStoreRecord(settings);
|
|
630
|
+
if (!record?.id) {
|
|
631
|
+
throw new Error("Tienda no disponible para iniciar sesi\xF3n");
|
|
632
|
+
}
|
|
633
|
+
const checkout = record.checkoutSettings;
|
|
634
|
+
const identityScope = checkout?.identityScope === "tenant" ? "tenant" : "store";
|
|
635
|
+
const headers = {
|
|
636
|
+
"x-Identity-Scope": identityScope,
|
|
637
|
+
"x-Store-Id": record.id
|
|
638
|
+
};
|
|
639
|
+
if (record.tenantId) headers["x-Tenant-Id"] = record.tenantId;
|
|
640
|
+
return headers;
|
|
641
|
+
}
|
|
434
642
|
|
|
435
643
|
// src/core/lib/customer-order-labels.ts
|
|
436
644
|
var ORDER_STATUS_LABELS = {
|
|
@@ -1005,216 +1213,6 @@ var PageService = class _PageService {
|
|
|
1005
1213
|
}
|
|
1006
1214
|
};
|
|
1007
1215
|
var pageService = PageService.getInstance();
|
|
1008
|
-
var StorefrontCheckoutSettingsSchema = z.object({
|
|
1009
|
-
allowGuestCheckout: z.boolean().optional(),
|
|
1010
|
-
identityScope: z.enum(["store", "tenant", "global"]).optional(),
|
|
1011
|
-
signInMethods: z.array(z.string()).optional()
|
|
1012
|
-
});
|
|
1013
|
-
var looseRecord = z.record(z.string(), z.unknown());
|
|
1014
|
-
var StorefrontThemeConfigSchema = z.object({
|
|
1015
|
-
name: z.string().nullable().optional(),
|
|
1016
|
-
mode: z.string().nullable().optional(),
|
|
1017
|
-
colors: looseRecord.optional(),
|
|
1018
|
-
fonts: looseRecord.optional(),
|
|
1019
|
-
assets: looseRecord.optional()
|
|
1020
|
-
}).passthrough();
|
|
1021
|
-
var StorefrontFeaturesEnabledSchema = z.object({
|
|
1022
|
-
flags: looseRecord.optional()
|
|
1023
|
-
}).passthrough();
|
|
1024
|
-
var StorefrontCmsBrandingSchema = z.object({
|
|
1025
|
-
logoUrl: z.string().nullable().optional(),
|
|
1026
|
-
logoDarkUrl: z.string().nullable().optional(),
|
|
1027
|
-
faviconUrl: z.string().nullable().optional(),
|
|
1028
|
-
socialImageUrl: z.string().nullable().optional()
|
|
1029
|
-
});
|
|
1030
|
-
var StorefrontCmsSeoSchema = z.object({
|
|
1031
|
-
siteName: z.string().nullable().optional(),
|
|
1032
|
-
metaTitle: z.string().nullable().optional(),
|
|
1033
|
-
metaDescription: z.string().nullable().optional(),
|
|
1034
|
-
titleTemplate: z.string().nullable().optional(),
|
|
1035
|
-
robotsIndex: z.boolean().optional()
|
|
1036
|
-
});
|
|
1037
|
-
var StorefrontCmsSocialLinksSchema = z.object({
|
|
1038
|
-
instagram: z.string().nullable().optional(),
|
|
1039
|
-
facebook: z.string().nullable().optional(),
|
|
1040
|
-
tiktok: z.string().nullable().optional(),
|
|
1041
|
-
youtube: z.string().nullable().optional(),
|
|
1042
|
-
x: z.string().nullable().optional()
|
|
1043
|
-
});
|
|
1044
|
-
var StorefrontCmsContactSchema = z.object({
|
|
1045
|
-
supportEmail: z.string().nullable().optional(),
|
|
1046
|
-
phone: z.string().nullable().optional(),
|
|
1047
|
-
whatsapp: z.string().nullable().optional(),
|
|
1048
|
-
address: z.string().nullable().optional(),
|
|
1049
|
-
socialLinks: StorefrontCmsSocialLinksSchema.optional()
|
|
1050
|
-
});
|
|
1051
|
-
var StorefrontCmsTrackingSchema = z.object({
|
|
1052
|
-
googleAnalyticsMeasurementId: z.string().nullable().optional(),
|
|
1053
|
-
metaPixelId: z.string().nullable().optional(),
|
|
1054
|
-
googleTagManagerContainerId: z.string().nullable().optional()
|
|
1055
|
-
});
|
|
1056
|
-
var StorefrontCmsCustomScriptsSchema = z.object({
|
|
1057
|
-
enabled: z.boolean().optional(),
|
|
1058
|
-
head: z.string().nullable().optional(),
|
|
1059
|
-
bodyEnd: z.string().nullable().optional()
|
|
1060
|
-
});
|
|
1061
|
-
var StorefrontCmsSettingsSchema = z.object({
|
|
1062
|
-
themeKey: z.string().optional(),
|
|
1063
|
-
branding: StorefrontCmsBrandingSchema.optional(),
|
|
1064
|
-
seo: StorefrontCmsSeoSchema.optional(),
|
|
1065
|
-
contact: StorefrontCmsContactSchema.optional(),
|
|
1066
|
-
tracking: StorefrontCmsTrackingSchema.optional(),
|
|
1067
|
-
customScripts: StorefrontCmsCustomScriptsSchema.optional(),
|
|
1068
|
-
updatedOn: z.string().nullable().optional()
|
|
1069
|
-
});
|
|
1070
|
-
var StorefrontCmsPageSchema = z.object({
|
|
1071
|
-
id: z.string(),
|
|
1072
|
-
name: z.string(),
|
|
1073
|
-
slug: z.string(),
|
|
1074
|
-
layout: z.string().optional(),
|
|
1075
|
-
version: z.number().optional(),
|
|
1076
|
-
settings: z.record(z.string(), z.unknown()).optional().nullable(),
|
|
1077
|
-
sections: z.array(z.unknown()).optional(),
|
|
1078
|
-
status: z.string().optional(),
|
|
1079
|
-
hasPublishedVersion: z.boolean().optional(),
|
|
1080
|
-
publishedOn: z.string().nullable().optional(),
|
|
1081
|
-
publishedBy: z.string().nullable().optional(),
|
|
1082
|
-
createdOn: z.string().nullable().optional(),
|
|
1083
|
-
updatedOn: z.string().nullable().optional(),
|
|
1084
|
-
createdBy: z.string().nullable().optional(),
|
|
1085
|
-
updatedBy: z.string().nullable().optional(),
|
|
1086
|
-
lastModifiedBy: z.string().nullable().optional()
|
|
1087
|
-
}).passthrough();
|
|
1088
|
-
var StorefrontSettingsLegacyFlatSchema = z.object({
|
|
1089
|
-
id: z.coerce.string(),
|
|
1090
|
-
tenantId: z.string().nullable().optional(),
|
|
1091
|
-
name: z.string(),
|
|
1092
|
-
slug: z.coerce.string().optional(),
|
|
1093
|
-
description: z.string().nullable().optional(),
|
|
1094
|
-
visibility: z.string().nullable().optional(),
|
|
1095
|
-
logo: z.string().nullable().optional(),
|
|
1096
|
-
favicon: z.string().nullable().optional(),
|
|
1097
|
-
icon: z.string().nullable().optional(),
|
|
1098
|
-
currency: z.string().nullable().optional(),
|
|
1099
|
-
language: z.string().nullable().optional(),
|
|
1100
|
-
themeConfig: z.unknown().optional().nullable(),
|
|
1101
|
-
featuresEnabled: z.unknown().optional().nullable(),
|
|
1102
|
-
checkoutSettings: StorefrontCheckoutSettingsSchema.optional().nullable()
|
|
1103
|
-
}).passthrough();
|
|
1104
|
-
function unwrapSettingsResponseBody(v) {
|
|
1105
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return v;
|
|
1106
|
-
const o = v;
|
|
1107
|
-
if ("data" in o && o.data != null && typeof o.data === "object" && !Array.isArray(o.data)) {
|
|
1108
|
-
return o.data;
|
|
1109
|
-
}
|
|
1110
|
-
return v;
|
|
1111
|
-
}
|
|
1112
|
-
function isLegacyFlatSettingsPayload(v) {
|
|
1113
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
1114
|
-
const o = v;
|
|
1115
|
-
if ("store" in o || "schemaVersion" in o || "cms" in o) return false;
|
|
1116
|
-
return (typeof o.id === "string" || typeof o.id === "number") && typeof o.name === "string";
|
|
1117
|
-
}
|
|
1118
|
-
function normalizeStorefrontSettingsPayload(v) {
|
|
1119
|
-
const body = unwrapSettingsResponseBody(v);
|
|
1120
|
-
if (!isLegacyFlatSettingsPayload(body)) return body;
|
|
1121
|
-
const raw = body;
|
|
1122
|
-
const parsed = StorefrontSettingsLegacyFlatSchema.safeParse(raw);
|
|
1123
|
-
if (!parsed.success) return body;
|
|
1124
|
-
const l = parsed.data;
|
|
1125
|
-
const currency = l.currency?.trim() ? l.currency : "PEN";
|
|
1126
|
-
const language = l.language?.trim() ? l.language : "es";
|
|
1127
|
-
const slug = l.slug?.trim() ? l.slug : l.id;
|
|
1128
|
-
return {
|
|
1129
|
-
schemaVersion: 0,
|
|
1130
|
-
generatedAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1131
|
-
store: {
|
|
1132
|
-
id: l.id,
|
|
1133
|
-
tenantId: l.tenantId ?? void 0,
|
|
1134
|
-
name: l.name,
|
|
1135
|
-
slug,
|
|
1136
|
-
description: l.description ?? null,
|
|
1137
|
-
logo: l.logo ?? null,
|
|
1138
|
-
icon: l.icon ?? null,
|
|
1139
|
-
visibility: l.visibility ?? void 0,
|
|
1140
|
-
currency,
|
|
1141
|
-
language,
|
|
1142
|
-
themeConfig: l.themeConfig ?? void 0,
|
|
1143
|
-
featuresEnabled: l.featuresEnabled ?? void 0,
|
|
1144
|
-
checkoutSettings: l.checkoutSettings ?? void 0
|
|
1145
|
-
},
|
|
1146
|
-
cms: {
|
|
1147
|
-
settings: {
|
|
1148
|
-
branding: {
|
|
1149
|
-
faviconUrl: l.favicon ?? null,
|
|
1150
|
-
logoUrl: l.logo ?? null,
|
|
1151
|
-
logoDarkUrl: null,
|
|
1152
|
-
socialImageUrl: null
|
|
1153
|
-
}
|
|
1154
|
-
},
|
|
1155
|
-
pages: []
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
var StorefrontStoreSchema = z.object({
|
|
1160
|
-
id: z.string(),
|
|
1161
|
-
tenantId: z.string().optional(),
|
|
1162
|
-
sellerId: z.string().optional(),
|
|
1163
|
-
plan: z.string().optional(),
|
|
1164
|
-
storageLimitBytes: z.number().optional(),
|
|
1165
|
-
monthlyTransferLimitBytes: z.number().optional(),
|
|
1166
|
-
maxUploadSizeBytes: z.number().optional(),
|
|
1167
|
-
maxStores: z.number().optional(),
|
|
1168
|
-
maxMembers: z.number().optional(),
|
|
1169
|
-
maxProducts: z.number().optional(),
|
|
1170
|
-
maxCategories: z.number().optional(),
|
|
1171
|
-
maxBrands: z.number().optional(),
|
|
1172
|
-
maxAttributes: z.number().optional(),
|
|
1173
|
-
maxCollections: z.number().optional(),
|
|
1174
|
-
enableApi: z.boolean().optional(),
|
|
1175
|
-
isActive: z.boolean().optional(),
|
|
1176
|
-
name: z.string(),
|
|
1177
|
-
description: z.string().nullable().optional(),
|
|
1178
|
-
avatarUrl: z.string().nullable().optional(),
|
|
1179
|
-
logo: z.string().nullable().optional(),
|
|
1180
|
-
icon: z.string().nullable().optional(),
|
|
1181
|
-
slug: z.string(),
|
|
1182
|
-
domain: z.string().nullable().optional(),
|
|
1183
|
-
domains: z.array(z.string()).optional(),
|
|
1184
|
-
timeZone: z.string().nullable().optional(),
|
|
1185
|
-
currency: z.string(),
|
|
1186
|
-
language: z.string(),
|
|
1187
|
-
visibility: z.string().optional(),
|
|
1188
|
-
privateAccessHash: z.string().nullable().optional(),
|
|
1189
|
-
privateAccessVersion: z.number().optional(),
|
|
1190
|
-
themeConfig: StorefrontThemeConfigSchema.optional(),
|
|
1191
|
-
featuresEnabled: StorefrontFeaturesEnabledSchema.optional(),
|
|
1192
|
-
checkoutSettings: StorefrontCheckoutSettingsSchema.optional().nullable()
|
|
1193
|
-
}).passthrough();
|
|
1194
|
-
var StorefrontSettingsEnvelopeSchema = z.object({
|
|
1195
|
-
schemaVersion: z.number(),
|
|
1196
|
-
generatedAt: z.string(),
|
|
1197
|
-
store: StorefrontStoreSchema,
|
|
1198
|
-
cms: z.object({
|
|
1199
|
-
settings: StorefrontCmsSettingsSchema,
|
|
1200
|
-
pages: z.array(StorefrontCmsPageSchema)
|
|
1201
|
-
})
|
|
1202
|
-
}).passthrough();
|
|
1203
|
-
var StorefrontSettingsSchema = z.preprocess(
|
|
1204
|
-
normalizeStorefrontSettingsPayload,
|
|
1205
|
-
StorefrontSettingsEnvelopeSchema
|
|
1206
|
-
);
|
|
1207
|
-
function storefrontStoreRecord(settings) {
|
|
1208
|
-
return settings?.store ?? null;
|
|
1209
|
-
}
|
|
1210
|
-
function storefrontFaviconUrl(settings) {
|
|
1211
|
-
const b = settings?.cms?.settings?.branding;
|
|
1212
|
-
return b?.faviconUrl ?? settings?.store?.logo ?? settings?.store?.icon ?? null;
|
|
1213
|
-
}
|
|
1214
|
-
function storefrontOgImageUrl(settings) {
|
|
1215
|
-
const b = settings?.cms?.settings?.branding;
|
|
1216
|
-
return b?.socialImageUrl ?? settings?.store?.logo ?? null;
|
|
1217
|
-
}
|
|
1218
1216
|
|
|
1219
1217
|
// src/core/services/store.service.ts
|
|
1220
1218
|
var StoreService = class _StoreService {
|
|
@@ -1528,6 +1526,97 @@ var CartService = class _CartService {
|
|
|
1528
1526
|
}
|
|
1529
1527
|
};
|
|
1530
1528
|
var cartService = CartService.getInstance();
|
|
1529
|
+
var ECOMIQ_APP_APEX = "ecomiq.app";
|
|
1530
|
+
var ECOMIQ_APP_SUFFIX = [`.${ECOMIQ_APP_APEX}`, `.localhost`];
|
|
1531
|
+
function normalizeStoreHost(hostHeader) {
|
|
1532
|
+
let h = hostHeader.trim().toLowerCase();
|
|
1533
|
+
const colon = h.indexOf(":");
|
|
1534
|
+
if (colon !== -1) h = h.slice(0, colon);
|
|
1535
|
+
if (h.startsWith("www.")) h = h.slice(4);
|
|
1536
|
+
return h;
|
|
1537
|
+
}
|
|
1538
|
+
function resolveStorefrontSettingsHost(hostHeader) {
|
|
1539
|
+
const host = normalizeStoreHost(hostHeader);
|
|
1540
|
+
if (!host) {
|
|
1541
|
+
throw Object.assign(new Error("Host inv\xE1lido para tienda"), { status: 400 });
|
|
1542
|
+
}
|
|
1543
|
+
if (host === ECOMIQ_APP_APEX) {
|
|
1544
|
+
throw Object.assign(new Error("Host apex ecomiq.app sin slug de tienda"), { status: 400 });
|
|
1545
|
+
}
|
|
1546
|
+
if (ECOMIQ_APP_SUFFIX.some((suffix) => host.endsWith(suffix))) {
|
|
1547
|
+
const slug = host.slice(0, -(ECOMIQ_APP_SUFFIX.find((suffix) => host.endsWith(suffix))?.length ?? 0));
|
|
1548
|
+
if (!slug) {
|
|
1549
|
+
throw Object.assign(new Error("Host sin slug para ecomiq.app"), { status: 400 });
|
|
1550
|
+
}
|
|
1551
|
+
return slug;
|
|
1552
|
+
}
|
|
1553
|
+
return host;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// src/core/config/ecomiq-config.ts
|
|
1557
|
+
var CONFIG_FILENAMES = [
|
|
1558
|
+
"ecomiq.config.js",
|
|
1559
|
+
"ecomiq.config.cjs",
|
|
1560
|
+
"ecomiq.config.mjs"
|
|
1561
|
+
];
|
|
1562
|
+
var EcomiqConfigSchema = z.object({
|
|
1563
|
+
/**
|
|
1564
|
+
* Slug de tienda en Ecomiq (p. ej. `mi-tienda` para `mi-tienda.ecomiq.app`).
|
|
1565
|
+
* Si está definido, tiene prioridad sobre el `Host` de la request (útil en `localhost`).
|
|
1566
|
+
*/
|
|
1567
|
+
slugStore: z.string().min(1).optional()
|
|
1568
|
+
});
|
|
1569
|
+
var cachedConfig;
|
|
1570
|
+
function parseExportedConfig(raw) {
|
|
1571
|
+
const candidate = raw && typeof raw === "object" && "default" in raw ? raw.default : raw;
|
|
1572
|
+
const parsed = EcomiqConfigSchema.safeParse(candidate);
|
|
1573
|
+
if (!parsed.success) {
|
|
1574
|
+
console.warn(
|
|
1575
|
+
"[ecomiq] ecomiq.config.* inv\xE1lido:",
|
|
1576
|
+
parsed.error.flatten().fieldErrors
|
|
1577
|
+
);
|
|
1578
|
+
return null;
|
|
1579
|
+
}
|
|
1580
|
+
const slugStore = parsed.data.slugStore?.trim();
|
|
1581
|
+
return slugStore ? { slugStore } : {};
|
|
1582
|
+
}
|
|
1583
|
+
function loadEcomiqConfig(cwd = process.cwd()) {
|
|
1584
|
+
if (cachedConfig !== void 0) return cachedConfig;
|
|
1585
|
+
for (const filename of CONFIG_FILENAMES) {
|
|
1586
|
+
const configPath = join(cwd, filename);
|
|
1587
|
+
if (!existsSync(configPath)) continue;
|
|
1588
|
+
try {
|
|
1589
|
+
const requireFromApp = createRequire(join(cwd, "package.json"));
|
|
1590
|
+
const loaded = requireFromApp(configPath);
|
|
1591
|
+
const parsed = parseExportedConfig(loaded);
|
|
1592
|
+
cachedConfig = parsed;
|
|
1593
|
+
return cachedConfig;
|
|
1594
|
+
} catch (error) {
|
|
1595
|
+
console.warn(`[ecomiq] No se pudo cargar ${configPath}:`, error);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
cachedConfig = null;
|
|
1599
|
+
return null;
|
|
1600
|
+
}
|
|
1601
|
+
function clearEcomiqConfigCache() {
|
|
1602
|
+
cachedConfig = void 0;
|
|
1603
|
+
}
|
|
1604
|
+
function resolvePublicStoreKey(hostHeader, cwd) {
|
|
1605
|
+
const slugFromConfig = loadEcomiqConfig(cwd)?.slugStore?.trim();
|
|
1606
|
+
if (slugFromConfig) return slugFromConfig;
|
|
1607
|
+
if (!hostHeader?.trim()) {
|
|
1608
|
+
throw Object.assign(
|
|
1609
|
+
new Error(
|
|
1610
|
+
"Host is required, o define slugStore en ecomiq.config.js en la ra\xEDz del proyecto"
|
|
1611
|
+
),
|
|
1612
|
+
{ status: 400 }
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
return resolveStorefrontSettingsHost(hostHeader);
|
|
1616
|
+
}
|
|
1617
|
+
function hasEcomiqSlugStoreConfig(cwd) {
|
|
1618
|
+
return Boolean(loadEcomiqConfig(cwd)?.slugStore?.trim());
|
|
1619
|
+
}
|
|
1531
1620
|
var defaultOptions = {
|
|
1532
1621
|
queries: {
|
|
1533
1622
|
staleTime: 60 * 1e3
|
|
@@ -2129,10 +2218,12 @@ function EcomiqProvider({
|
|
|
2129
2218
|
return () => setClientStoreId(null);
|
|
2130
2219
|
}, [store]);
|
|
2131
2220
|
const [queryClient] = useState(() => new QueryClient());
|
|
2132
|
-
|
|
2221
|
+
const tree = /* @__PURE__ */ jsxs(QueryClientProvider, { client: queryClient, children: [
|
|
2133
2222
|
children,
|
|
2134
2223
|
withShellUi ? /* @__PURE__ */ jsx(EcomiqShellUi2, {}) : null
|
|
2135
|
-
] })
|
|
2224
|
+
] });
|
|
2225
|
+
if (!authClient) return tree;
|
|
2226
|
+
return /* @__PURE__ */ jsx(StorefrontAuthProvider, { authClient, children: tree });
|
|
2136
2227
|
}
|
|
2137
2228
|
function EcomiqShellUi2() {
|
|
2138
2229
|
const [ui, setUi] = useState(null);
|
|
@@ -2438,6 +2529,19 @@ function ecomiqOAuthPasswordClient() {
|
|
|
2438
2529
|
]
|
|
2439
2530
|
};
|
|
2440
2531
|
}
|
|
2532
|
+
|
|
2533
|
+
// src/react/auth/ecomiq-storefront-sign-in.ts
|
|
2534
|
+
async function signInWithEcomiqCredentials2(authClient, settings, credentials) {
|
|
2535
|
+
const response = await authClient.$fetch("/ecomiq-oauth/sign-in", {
|
|
2536
|
+
method: "POST",
|
|
2537
|
+
headers: buildEcomiqOAuthIdentityHeaders(settings),
|
|
2538
|
+
body: credentials
|
|
2539
|
+
});
|
|
2540
|
+
if (response.error) {
|
|
2541
|
+
throw new Error(response.error.message ?? "Error al iniciar sesi\xF3n");
|
|
2542
|
+
}
|
|
2543
|
+
return response;
|
|
2544
|
+
}
|
|
2441
2545
|
function buildOptionGroups(variants) {
|
|
2442
2546
|
const map = /* @__PURE__ */ new Map();
|
|
2443
2547
|
for (const v of variants) {
|
|
@@ -2561,6 +2665,6 @@ function findStorefrontCmsPageBySlug(settings, slug) {
|
|
|
2561
2665
|
return parsed.success ? parsed.data : null;
|
|
2562
2666
|
}
|
|
2563
2667
|
|
|
2564
|
-
export { CartAddressesRequestSchema, CartBuyerRequestSchema, CartCheckoutPaymentActionSchema, CartCheckoutPaymentSchema, CartCheckoutReadResponseSchema, CartCheckoutRequestSchema, CartCheckoutResponseSchema, CartCouponRequestSchema, CartCreateRequestSchema, CartItemModifierRequestSchema, CartItemRequestSchema, CartPaymentMethodSchema, CartPaymentMethodsResponseSchema, CartPaymentReceiptResponseSchema, CartResponseBundleItemSchema, CartResponseItemSchema, CartResponseSchema, CartShippingMethodPutRequestSchema, EcomiqProvider, ProductSchema, ProductVariantSchema, ProductVariantSelector, ProductsFiltersSchema, ProductsResponseSchema, QueryProvider, STOREFRONT_API_PATH_PREFIX, STOREFRONT_ECOMIQ_OAUTH_COOKIE_NAME, STOREFRONT_ECOMIQ_OAUTH_COOKIE_PATH, ShippingOptionGroupSchema, ShippingOptionsResponseSchema, ShippingRateSchema, StorefrontAuthProvider, StorefrontBundleItemSchema, StorefrontCheckoutSettingsSchema, StorefrontCollectionDetailSchema, StorefrontCollectionSchema, StorefrontCollectionsResponseSchema, StorefrontPageDetailSchema, StorefrontPageListItemSchema, StorefrontPriceTierSchema, StorefrontProductDetailSchema, StorefrontProductSchema, StorefrontProductsParamsSchema, StorefrontProductsResponseSchema, StorefrontSettingsLegacyFlatSchema, StorefrontSettingsSchema, StorefrontStoreSchema, apiClient, cartService, collectionService, countryCurrency, customerOrderStatusTone, ecomiqOAuthPassword, ecomiqOAuthPasswordClient, fetchStorefrontGeoDistricts, fetchStorefrontGeoProvinces, findStorefrontCmsPageBySlug, formatCurrency, formatCustomerOrderStatus, formatOrderDate, formatOrderDateTime, loadStorefrontGeoDepartments, normalizeStorefrontSettingsPayload, pageService, productService, resolveIneiCodesFromLabels, storeService, storefrontAccessTokenNeedsRefresh, storefrontFaviconUrl, storefrontOgImageUrl, storefrontSessionEndsSoon, storefrontStoreRecord, toGeoItems, useCart, useCartAddresses, useCartCreate, useCartGet, useCollections, useConfig, usePages, useProducts, useStore, useStorefrontAuthClient, useStorefrontGeoInei, useStorefrontSession, useUser };
|
|
2668
|
+
export { CartAddressesRequestSchema, CartBuyerRequestSchema, CartCheckoutPaymentActionSchema, CartCheckoutPaymentSchema, CartCheckoutReadResponseSchema, CartCheckoutRequestSchema, CartCheckoutResponseSchema, CartCouponRequestSchema, CartCreateRequestSchema, CartItemModifierRequestSchema, CartItemRequestSchema, CartPaymentMethodSchema, CartPaymentMethodsResponseSchema, CartPaymentReceiptResponseSchema, CartResponseBundleItemSchema, CartResponseItemSchema, CartResponseSchema, CartShippingMethodPutRequestSchema, EcomiqConfigSchema, EcomiqProvider, ProductSchema, ProductVariantSchema, ProductVariantSelector, ProductsFiltersSchema, ProductsResponseSchema, QueryProvider, STOREFRONT_API_PATH_PREFIX, STOREFRONT_ECOMIQ_OAUTH_COOKIE_NAME, STOREFRONT_ECOMIQ_OAUTH_COOKIE_PATH, ShippingOptionGroupSchema, ShippingOptionsResponseSchema, ShippingRateSchema, StorefrontAuthProvider, StorefrontBundleItemSchema, StorefrontCheckoutSettingsSchema, StorefrontCollectionDetailSchema, StorefrontCollectionSchema, StorefrontCollectionsResponseSchema, StorefrontPageDetailSchema, StorefrontPageListItemSchema, StorefrontPriceTierSchema, StorefrontProductDetailSchema, StorefrontProductSchema, StorefrontProductsParamsSchema, StorefrontProductsResponseSchema, StorefrontSettingsLegacyFlatSchema, StorefrontSettingsSchema, StorefrontStoreSchema, apiClient, buildEcomiqOAuthIdentityHeaders, cartService, clearEcomiqConfigCache, collectionService, countryCurrency, customerOrderStatusTone, ecomiqOAuthPassword, ecomiqOAuthPasswordClient, fetchStorefrontGeoDistricts, fetchStorefrontGeoProvinces, findStorefrontCmsPageBySlug, formatCurrency, formatCustomerOrderStatus, formatOrderDate, formatOrderDateTime, hasEcomiqSlugStoreConfig, loadEcomiqConfig, loadStorefrontGeoDepartments, normalizeStorefrontSettingsPayload, pageService, productService, resolveIneiCodesFromLabels, resolvePublicStoreKey, signInWithEcomiqCredentials2 as signInWithEcomiqCredentials, storeService, storefrontAccessTokenNeedsRefresh, storefrontFaviconUrl, storefrontOgImageUrl, storefrontSessionEndsSoon, storefrontStoreRecord, toGeoItems, useCart, useCartAddresses, useCartCreate, useCartGet, useCollections, useConfig, usePages, useProducts, useStore, useStorefrontAuthClient, useStorefrontGeoInei, useStorefrontSession, useUser };
|
|
2565
2669
|
//# sourceMappingURL=react.js.map
|
|
2566
2670
|
//# sourceMappingURL=react.js.map
|