qumra-engine 2.0.178 → 2.0.179

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.
@@ -1,2 +1,2 @@
1
- import nunjucks from 'nunjucks';
1
+ import nunjucks from "nunjucks";
2
2
  export default function json(value: any): nunjucks.runtime.SafeString;
@@ -7,9 +7,17 @@ exports.default = json;
7
7
  const nunjucks_1 = __importDefault(require("nunjucks"));
8
8
  function json(value) {
9
9
  try {
10
- return new nunjucks_1.default.runtime.SafeString(JSON.stringify(value, null, 2));
10
+ const formatted = JSON.stringify(value, null, 2);
11
+ const safe = escapeHtml(formatted);
12
+ return new nunjucks_1.default.runtime.SafeString(`<pre dir="ltr" style="text-align:left;"><code>${safe}</code></pre>`);
11
13
  }
12
14
  catch {
13
- return new nunjucks_1.default.runtime.SafeString('');
15
+ return new nunjucks_1.default.runtime.SafeString(`<pre dir="ltr" style="text-align:left;"><code></code></pre>`);
14
16
  }
15
17
  }
18
+ function escapeHtml(str) {
19
+ return str
20
+ .replace(/&/g, "&amp;")
21
+ .replace(/</g, "&lt;")
22
+ .replace(/>/g, "&gt;");
23
+ }
@@ -1,4 +1,16 @@
1
1
  import { Locals } from "express";
2
2
  type RenderInput = Partial<Locals>;
3
- export default function renderHandler(locals: RenderInput): any;
3
+ export default function renderHandler(locals: RenderInput): {
4
+ customer?: any;
5
+ store?: any;
6
+ cart?: any;
7
+ settings?: any;
8
+ market?: any;
9
+ localization: {
10
+ market?: any;
11
+ language?: string;
12
+ currency?: any;
13
+ availableLanguages?: string[];
14
+ };
15
+ };
4
16
  export {};
@@ -7,92 +7,43 @@ exports.default = renderHandler;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  function renderHandler(locals) {
10
- const render = locals?.render;
11
- const settings = locals?.env?.getGlobal("settings");
12
- const language = locals?.lang;
13
- const market = locals?.render?.market;
14
- const currency = locals?.render?.globals?.currency;
15
- const localesPath = locals?.localesPath;
16
- let languages = [];
10
+ const render = locals.render;
11
+ const globals = render?.globals;
12
+ const settings = locals.env?.getGlobal("settings");
13
+ const language = locals.lang;
14
+ const market = render?.market;
15
+ const currency = globals?.currency;
16
+ const localesPath = locals.localesPath;
17
+ /** available languages */
18
+ let availableLanguages = [];
17
19
  if (localesPath && fs_1.default.existsSync(localesPath)) {
18
- languages = fs_1.default.readdirSync(localesPath).map(lang => path_1.default.basename(lang, '.json'));
19
- }
20
- const objectsData = {};
21
- if (render?.globals?.customer)
22
- objectsData.customer = render.globals?.customer;
23
- if (render?.context?.product_options_value)
24
- objectsData.product_options_value = render?.context?.product.options.map((item) => item);
25
- if (market)
26
- objectsData.market = market;
27
- if (render?.globals?.app)
28
- objectsData.store = render.globals?.app;
29
- if (render?.context?.seo)
30
- objectsData.seo = render.context?.seo;
31
- if (render?.globals?.app?.generalSettings)
32
- objectsData.settings = render?.globals?.app?.generalSettings;
33
- if (render?.context?.query?.q)
34
- objectsData.search = render?.context?.query?.q;
35
- if (render?.context?.pagination)
36
- objectsData.pagination = render?.context?.pagination;
37
- if (render?.context?.products)
38
- objectsData.products = render?.context?.products;
39
- if (render?.context?.products && Array.isArray(render.context.products)) {
40
- const allCollections = render.context.products
41
- .flatMap((product) => Array.isArray(product.collections) ? product.collections : [])
42
- .filter((c, i, arr) => c && arr.indexOf(c) === i);
43
- if (allCollections.length > 0) {
44
- objectsData.collections = allCollections;
45
- }
46
- else if (render?.context?.product?.collections) {
47
- objectsData.collections = render.context.product.collections;
48
- }
49
- else if (render?.context?.collections) {
50
- objectsData.collections = render.context.collections;
51
- }
52
- }
53
- else if (render?.context?.product?.collections) {
54
- objectsData.collections = render.context.product.collections;
55
- }
56
- else if (render?.context?.collections) {
57
- objectsData.collections = render.context.collections;
58
- }
59
- if (render?.context?.collection || render?.context?.product?.collections?.length > 0)
60
- objectsData.collection = render?.context?.collection || render?.context?.product?.collections;
61
- if (render?.context?.product)
62
- objectsData.product = render?.context?.product;
63
- if (render?.context?.product)
64
- objectsData.product = render?.context?.product;
65
- if (render?.context?.product_options_value)
66
- objectsData.product_options_value = render?.context?.product.options.map((item) => item);
67
- if (render?.context?.related_products)
68
- objectsData.recommendations = render?.context?.related_products;
69
- if (render?.context?.page)
70
- objectsData.localizationpage = render?.context?.page;
71
- if (render?.context?.page?.title)
72
- objectsData.page_title = render?.context?.page.title;
73
- if (render?.context?.page?.path)
74
- objectsData.page_path = render?.context?.page.path;
75
- if (render?.context?.page?.description)
76
- objectsData.page_description = render?.context?.page?.description;
77
- if (render?.globals?.cart)
78
- objectsData.cart = render?.globals?.cart;
20
+ availableLanguages = fs_1.default
21
+ .readdirSync(localesPath)
22
+ .map((file) => path_1.default.basename(file, ".json"));
23
+ }
24
+ const objectsData = {
25
+ localization: {},
26
+ };
27
+ /** globals */
28
+ if (globals?.customer)
29
+ objectsData.customer = globals.customer;
30
+ if (globals?.app)
31
+ objectsData.store = globals.app;
32
+ if (globals?.cart)
33
+ objectsData.cart = globals.cart;
79
34
  if (settings)
80
35
  objectsData.settings = settings;
81
36
  if (market)
82
37
  objectsData.market = market;
83
- objectsData.localization = {};
84
- if (market) {
38
+ /** localization */
39
+ if (market)
85
40
  objectsData.localization.market = market;
86
- }
87
- if (language) {
41
+ if (language)
88
42
  objectsData.localization.language = language;
89
- }
90
- if (currency) {
43
+ if (currency)
91
44
  objectsData.localization.currency = currency;
45
+ if (availableLanguages.length) {
46
+ objectsData.localization.availableLanguages = availableLanguages;
92
47
  }
93
- if (languages) {
94
- objectsData.localization.availableLanguages = languages;
95
- }
96
- console.log("🚀 ~ renderHandler ~ objectsData:", objectsData);
97
48
  return objectsData;
98
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qumra-engine",
3
- "version": "2.0.178",
3
+ "version": "2.0.179",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {