@zohofinance/commerce 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/VALIDATIONS.md +122 -0
  2. package/package.json +2 -2
  3. package/public/dev-error.liquid +49 -0
  4. package/ts-dist/commands/build-theme.d.ts.map +1 -1
  5. package/ts-dist/commands/build-theme.js +38 -11
  6. package/ts-dist/commands/serve-theme.d.ts.map +1 -1
  7. package/ts-dist/commands/serve-theme.js +414 -70
  8. package/ts-dist/index.js +0 -0
  9. package/ts-dist/mocks/global-objects.d.ts.map +1 -1
  10. package/ts-dist/mocks/global-objects.js +1 -0
  11. package/ts-dist/mocks/init-theme/i18n/en.schema.json +2 -1
  12. package/ts-dist/mocks/init-theme/sections/footer.liquid +3 -1
  13. package/ts-dist/mocks/init-theme/sections/header-topbar.liquid +3 -1
  14. package/ts-dist/mocks/init-theme/sections/product-collection.liquid +3 -1
  15. package/ts-dist/mocks/init-theme/sections/promo-banner.liquid +5 -1
  16. package/ts-dist/mocks/reviews.d.ts +6 -0
  17. package/ts-dist/mocks/reviews.d.ts.map +1 -0
  18. package/ts-dist/mocks/reviews.js +52 -0
  19. package/ts-dist/routes/storefront-routes.js +1 -1
  20. package/ts-dist/utils/api-handler.d.ts +6 -1
  21. package/ts-dist/utils/api-handler.d.ts.map +1 -1
  22. package/ts-dist/utils/api-handler.js +91 -35
  23. package/ts-dist/utils/editor-attributes.d.ts.map +1 -1
  24. package/ts-dist/utils/editor-attributes.js +2 -4
  25. package/ts-dist/utils/error-report.d.ts +1 -1
  26. package/ts-dist/utils/error-report.d.ts.map +1 -1
  27. package/ts-dist/utils/error-report.js +58 -18
  28. package/ts-dist/utils/load-theme-globals.d.ts +1 -1
  29. package/ts-dist/utils/load-theme-globals.d.ts.map +1 -1
  30. package/ts-dist/utils/load-theme-globals.js +42 -2
  31. package/ts-dist/utils/resolve-schema-settings.d.ts.map +1 -1
  32. package/ts-dist/utils/resolve-schema-settings.js +0 -1
  33. package/ts-dist/utils/resolve-schema-translations.d.ts +1 -0
  34. package/ts-dist/utils/resolve-schema-translations.d.ts.map +1 -1
  35. package/ts-dist/utils/resolve-schema-translations.js +3 -0
  36. package/ts-dist/utils/schema-validation.d.ts +34 -0
  37. package/ts-dist/utils/schema-validation.d.ts.map +1 -0
  38. package/ts-dist/utils/schema-validation.js +544 -0
  39. package/ts-dist/utils/serve-theme-utils.d.ts +1 -1
  40. package/ts-dist/utils/serve-theme-utils.d.ts.map +1 -1
  41. package/ts-dist/utils/serve-theme-utils.js +1 -1
  42. package/ts-dist/utils/template-reference-validation.d.ts +11 -0
  43. package/ts-dist/utils/template-reference-validation.d.ts.map +1 -0
  44. package/ts-dist/utils/template-reference-validation.js +466 -0
  45. package/ts-dist/utils/theme-block-schema.d.ts +5 -0
  46. package/ts-dist/utils/theme-block-schema.d.ts.map +1 -0
  47. package/ts-dist/utils/theme-block-schema.js +35 -0
  48. package/ts-dist/utils/theme-validation.d.ts +8 -1
  49. package/ts-dist/utils/theme-validation.d.ts.map +1 -1
  50. package/ts-dist/utils/theme-validation.js +84 -143
@@ -1 +1 @@
1
- {"version":3,"file":"load-theme-globals.d.ts","sourceRoot":"","sources":["../../src/utils/load-theme-globals.ts"],"names":[],"mappings":"AAUA,wBAAgB,gBAAgB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0B1D;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkBzB"}
1
+ {"version":3,"file":"load-theme-globals.d.ts","sourceRoot":"","sources":["../../src/utils/load-theme-globals.ts"],"names":[],"mappings":"AAwBA,wBAAgB,gBAAgB,CAAC,IAAI,UAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwCtE;AAqBD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkBzB"}
@@ -1,8 +1,33 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import globalObjectsMock from '../mocks/global-objects.js';
4
- export function loadThemeGlobals() {
4
+ // Sample data in the mock globals that must never leak into a live-store preview.
5
+ const MOCK_DATA_KEYS = ['products', 'collections', 'menu', 'seo', 'page_title'];
6
+ // Feature flags default to "on" when previewing a live store, so UI such as the
7
+ // menu, sorting and reviews is not hidden just because the response omitted a flag.
8
+ const LIVE_PREFERENCE_DEFAULTS = {
9
+ is_menu_enabled: true,
10
+ is_sorting_enabled: true,
11
+ is_product_filters_enabled: true,
12
+ is_product_reviews_enabled: true,
13
+ search_box_enabled: true,
14
+ is_footer_enabled: true
15
+ };
16
+ export function loadThemeGlobals(live = false) {
5
17
  let globals = { ...globalObjectsMock };
18
+ if (live) {
19
+ for (const key of MOCK_DATA_KEYS) {
20
+ delete globals[key];
21
+ }
22
+ const mockStore = (globals.store ?? {});
23
+ globals.store = {
24
+ ...mockStore,
25
+ preferences: {
26
+ ...(mockStore.preferences ?? {}),
27
+ ...LIVE_PREFERENCE_DEFAULTS
28
+ }
29
+ };
30
+ }
6
31
  try {
7
32
  const themeSettingsPath = path.join(process.cwd(), 'settings', 'theme.json');
8
33
  const themeSettingsFile = JSON.parse(fs.readFileSync(themeSettingsPath, 'utf-8'));
@@ -20,13 +45,28 @@ export function loadThemeGlobals() {
20
45
  }
21
46
  return globals;
22
47
  }
48
+ function mergeStore(globals, pageData) {
49
+ const liveStore = pageData.store;
50
+ if (!liveStore || typeof liveStore !== 'object') {
51
+ return globals.store;
52
+ }
53
+ const baseStore = (globals.store ?? {});
54
+ return {
55
+ ...baseStore,
56
+ ...liveStore,
57
+ preferences: {
58
+ ...(baseStore.preferences ?? {}),
59
+ ...(liveStore.preferences ?? {})
60
+ }
61
+ };
62
+ }
23
63
  export function mergePageData(globals, pageData) {
24
64
  return {
25
65
  ...globals,
26
66
  ...pageData,
27
67
  routes: pageData.routes ?? globals.routes,
28
68
  settings: globals.settings ?? pageData.settings,
29
- store: pageData.store ?? globals.store,
69
+ store: mergeStore(globals, pageData),
30
70
  menu: pageData.menu ?? globals.menu,
31
71
  analytics: pageData.analytics ?? globals.analytics,
32
72
  content_for_header: pageData.content_for_header ?? globals.content_for_header ?? '',
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-schema-settings.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-schema-settings.ts"],"names":[],"mappings":"AAiBA,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAqEF,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAgND,wBAAsB,qBAAqB,CACzC,cAAc,EAAE,aAAa,EAAE,EAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAW,GACzE,OAAO,CAAC,IAAI,CAAC,CAIf"}
1
+ {"version":3,"file":"resolve-schema-settings.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-schema-settings.ts"],"names":[],"mappings":"AAiBA,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAqEF,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AA+MD,wBAAsB,qBAAqB,CACzC,cAAc,EAAE,aAAa,EAAE,EAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAW,GACzE,OAAO,CAAC,IAAI,CAAC,CAIf"}
@@ -211,7 +211,6 @@ async function resolveSettingByType(schemaSetting, settings, data, fetcher) {
211
211
  break;
212
212
  case 'url':
213
213
  case 'select':
214
- case 'preview_layout':
215
214
  case 'radio':
216
215
  settings[id] = parseJsonSetting(raw);
217
216
  break;
@@ -1,3 +1,4 @@
1
+ export declare function invalidateSchemaLocaleCache(): void;
1
2
  export declare function resolveSchemaTranslations<T>(schema: T, cwd: string): T;
2
3
  export declare function resolveSchemaName(name: string | undefined, fallback: string, cwd: string): string;
3
4
  //# sourceMappingURL=resolve-schema-translations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-schema-translations.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-schema-translations.ts"],"names":[],"mappings":"AA+CA,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAItE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMjG"}
1
+ {"version":3,"file":"resolve-schema-translations.d.ts","sourceRoot":"","sources":["../../src/utils/resolve-schema-translations.ts"],"names":[],"mappings":"AAKA,wBAAgB,2BAA2B,IAAI,IAAI,CAElD;AA4CD,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAItE;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMjG"}
@@ -1,6 +1,9 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs-extra';
3
3
  const localeCache = new Map();
4
+ export function invalidateSchemaLocaleCache() {
5
+ localeCache.clear();
6
+ }
4
7
  function loadSchemaLocale(cwd) {
5
8
  if (localeCache.has(cwd))
6
9
  return localeCache.get(cwd);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Schema checks aligned with storefront_template_engine SchemaValidator
3
+ * on patch_storefront_logging_and_error_handling. color_scheme is included
4
+ * because SchemaSettingsUtil resolves it. Findings the storefront still
5
+ * renders are warnings.
6
+ */
7
+ export declare const MAX_BLOCK_NESTING_DEPTH = 5;
8
+ export declare const EDITABLE_PAGE_KEYS: readonly ["index", "cart", "product", "page", "blog", "blogs", "collection", "category", "checkout", "orders", "search", "404"];
9
+ export declare const SECTION_GROUP_KEYS: readonly ["header-group", "footer-group"];
10
+ /** Engine SchemaValidator.KNOWN_SETTING_TYPES plus color_scheme. */
11
+ export declare const SUPPORTED_SETTING_TYPES: Set<string>;
12
+ export type JsonRecord = Record<string, unknown>;
13
+ export declare function isRecord(value: unknown): value is JsonRecord;
14
+ export type SchemaFinding = {
15
+ message: string;
16
+ severity: 'error' | 'warning';
17
+ };
18
+ export declare function validateSchemaDocument(schema: JsonRecord, options?: {
19
+ requireAvailableIn?: boolean;
20
+ requirePresets?: boolean;
21
+ /** Severity for a missing available_in or a missing named preset. */
22
+ requirementSeverity?: 'error' | 'warning';
23
+ themeBlockSchemas?: Map<string, JsonRecord>;
24
+ }): SchemaFinding[];
25
+ export declare function isBlockTypeAllowed(containerSchema: JsonRecord | null, blockType: string): boolean;
26
+ /**
27
+ * Schema whose `blocks` allow a placed block's children.
28
+ * Theme-block files are resolved by the caller via `themeBlockSchemas`.
29
+ */
30
+ export declare function resolveChildContainerSchema(containerSchema: JsonRecord | null, blockType: string, themeBlockSchemas?: Map<string, JsonRecord>): JsonRecord | null;
31
+ export declare function declaredThemeBlockNames(schema: JsonRecord): string[];
32
+ export declare function validateThemeSettingsGroups(groups: unknown): SchemaFinding[];
33
+ export declare function validateThemeSettingsData(data: unknown): SchemaFinding[];
34
+ //# sourceMappingURL=schema-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-validation.d.ts","sourceRoot":"","sources":["../../src/utils/schema-validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,eAAO,MAAM,kBAAkB,iIAarB,CAAC;AAEX,eAAO,MAAM,kBAAkB,2CAA4C,CAAC;AAO5E,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,aAqBlC,CAAC;AAiBH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE5D;AAUD,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B,CAAC;AAUF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE;IACP,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qEAAqE;IACrE,mBAAmB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1C,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACxC,GACL,aAAa,EAAE,CAsCjB;AAogBD,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,UAAU,GAAG,IAAI,EAClC,SAAS,EAAE,MAAM,GAChB,OAAO,CAoCT;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,UAAU,GAAG,IAAI,EAClC,SAAS,EAAE,MAAM,EACjB,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAC1C,UAAU,GAAG,IAAI,CAoBnB;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,CAgBpE;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,EAAE,CA2B5E;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,EAAE,CA4CxE"}