qumra-engine 2.0.146 → 2.0.149

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.
@@ -28,8 +28,7 @@ exports.default = new (class WidgetExtension {
28
28
  }
29
29
  try {
30
30
  const html = env.render(widgetTemplatePath, {
31
- context: ctx.context,
32
- globals: ctx.globals,
31
+ ...ctx,
33
32
  widget: {
34
33
  id: widget.id,
35
34
  type: widget.widgetKey,
@@ -43,11 +43,7 @@ exports.default = new (class WidgetExtension {
43
43
  }
44
44
  try {
45
45
  const html = env.render(widgetTemplatePath, {
46
- context: ctx.context,
47
- globals: ctx.globals,
48
- lang: ctx.lang,
49
- currency: ctx.currency,
50
- market: ctx.market,
46
+ ...ctx,
51
47
  widget: {
52
48
  id: widget._id,
53
49
  type: widget.widget,
@@ -30,11 +30,7 @@ exports.default = new (class WidgetExtension {
30
30
  }
31
31
  const validated = (0, validateUiData_1.validateUiData)(data);
32
32
  const rendered = env.render(filePath, {
33
- context: ctx.context,
34
- globals: ctx.globals,
35
- lang: ctx.lang,
36
- currency: ctx.currency,
37
- market: ctx.market,
33
+ ...ctx,
38
34
  data: validated,
39
35
  });
40
36
  return new nunjucks_1.default.runtime.SafeString(rendered);
@@ -1 +1 @@
1
- export default function first<T>(arr: T[]): T | undefined;
1
+ export default function first<T extends object, K extends keyof T>(arr: T[], key?: K): T[K] | undefined | object;
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = first;
4
- function first(arr) {
5
- return Array.isArray(arr) ? arr[0] : undefined;
4
+ function first(arr, key) {
5
+ if (!Array.isArray(arr) || arr.length === 0)
6
+ return undefined;
7
+ const firstItem = arr[0];
8
+ if (key !== undefined) {
9
+ return firstItem[key];
10
+ }
11
+ return firstItem;
6
12
  }
@@ -1 +1 @@
1
- export default function last(value: any[]): any;
1
+ export default function last(value: any[], key?: string): any;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = last;
4
- function last(value) {
5
- if (!Array.isArray(value))
6
- return null;
7
- return value[value.length - 1];
4
+ function last(value, key) {
5
+ if (!Array.isArray(value) || value.length === 0)
6
+ return undefined;
7
+ const lastItem = value[value.length - 1];
8
+ if (key) {
9
+ return lastItem[key];
10
+ }
11
+ return lastItem;
8
12
  }
@@ -10,7 +10,7 @@ function sort_natural(array) {
10
10
  return [];
11
11
  }
12
12
  try {
13
- const naturalSortCompare = (0, natural_sort_1.default)({ caseSensitive: true });
13
+ const naturalSortCompare = (0, natural_sort_1.default)({ caseSensitive: false });
14
14
  return [...array].sort(naturalSortCompare);
15
15
  }
16
16
  catch (error) {
@@ -1 +1,2 @@
1
- export default function highlight(text: string, terms: string | string[]): string;
1
+ import nunjucks from "nunjucks";
2
+ export default function highlight(text: string, terms: string | string[]): nunjucks.runtime.SafeString | string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.default = highlight;
7
+ const nunjucks_1 = __importDefault(require("nunjucks"));
4
8
  function highlight(text, terms) {
5
9
  if (!text || !terms)
6
10
  return text || '';
@@ -18,5 +22,5 @@ function highlight(text, terms) {
18
22
  termArr.sort((a, b) => b.length - a.length);
19
23
  const escapedTerms = termArr.map(t => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
20
24
  const regex = new RegExp(`(${escapedTerms.join('|')})`, 'gi');
21
- return text.replace(regex, '<strong class="highlight">$1</strong>');
25
+ return new nunjucks_1.default.runtime.SafeString(text.replace(regex, '<strong class="highlight">$1</strong>'));
22
26
  }
@@ -0,0 +1,4 @@
1
+ import { Locals } from "express";
2
+ type RenderInput = Partial<Locals>;
3
+ export default function renderHandler(locals: RenderInput): any;
4
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = renderHandler;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function renderHandler(locals) {
10
+ const render = locals?.render;
11
+ const settings = locals?.env?.getGlobal("settings");
12
+ const currency = locals?.currency;
13
+ const lang = locals?.lang;
14
+ const market = locals?.market;
15
+ const localesPath = locals?.localsPath;
16
+ let languages = [];
17
+ 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 (lang)
24
+ objectsData.local = lang;
25
+ if (currency)
26
+ objectsData.currency = currency;
27
+ if (market)
28
+ objectsData.market = market;
29
+ if (render?.globals?.app)
30
+ objectsData.store = render.globals?.app;
31
+ if (render?.context?.seo)
32
+ objectsData.seo = render.context?.seo;
33
+ if (render?.globals?.app?.generalSettings)
34
+ objectsData.settings = render?.globals?.app?.generalSettings;
35
+ if (render?.context?.query?.q)
36
+ objectsData.search = render?.context?.query?.q;
37
+ if (render?.context?.pagination)
38
+ objectsData.pagination = render?.context?.pagination;
39
+ if (render?.context?.products)
40
+ objectsData.products = render?.context?.products;
41
+ if (render?.context?.products?.collections || render?.context?.collections)
42
+ objectsData.collections = render?.context?.products?.collections || render?.context?.collections;
43
+ if (render?.context?.products?.collection)
44
+ objectsData.collections = render?.context?.products?.collection;
45
+ if (render?.context?.product)
46
+ objectsData.product = render?.context?.product;
47
+ if (render?.context?.product)
48
+ objectsData.product = render?.context?.product;
49
+ if (render?.context?.product_options_value)
50
+ objectsData.product_options_value = render?.context?.product.options.map((item) => item);
51
+ if (render?.context?.related_products)
52
+ objectsData.recommendations = render?.context?.related_products;
53
+ if (render?.context?.page)
54
+ objectsData.page = render?.context?.page;
55
+ if (render?.context?.page?.title)
56
+ objectsData.page_title = render?.context?.page.title;
57
+ if (render?.context?.page?.path)
58
+ objectsData.page_path = render?.context?.page.path;
59
+ if (render?.context?.page?.description)
60
+ objectsData.page_description = render?.context?.page?.description;
61
+ if (settings)
62
+ objectsData.settings = settings;
63
+ if (market || lang || currency)
64
+ objectsData.Localization = { market, lang, currency, languages };
65
+ return objectsData;
66
+ }
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.renderMiddleware = void 0;
4
7
  const resolveTranslations_1 = require("../utils/resolveTranslations");
5
8
  const globals_1 = require("../store/globals");
9
+ const render_handler_1 = __importDefault(require("../functions/render-handler"));
6
10
  const renderMiddleware = (req, res, next) => {
7
11
  const render = res.locals.render;
8
12
  const { context, globals, engine } = render;
13
+ const renderData = (0, render_handler_1.default)(res.locals);
9
14
  const jsonPreview = req.query?.jsonPreview ?? null;
10
15
  const widgetId = req.query?.widgetId ?? null;
11
16
  (0, globals_1.setGlobal)("injectionCode", engine?.injectionCode);
@@ -16,10 +21,7 @@ const renderMiddleware = (req, res, next) => {
16
21
  env.renderString(overrideLayout, (0, resolveTranslations_1.resolveTranslations)({
17
22
  context,
18
23
  globals,
19
- settings: env.getGlobal("settings"),
20
- market: res.locals.market || "",
21
- lang: res.locals.lang || "",
22
- currency: res.locals.currency || "",
24
+ ...renderData
23
25
  }, env.getGlobal("t")), (err, html) => {
24
26
  if (err) {
25
27
  return next(new Error(`❌ Nunjucks render error: ${err.message}`));
@@ -38,10 +40,7 @@ const renderMiddleware = (req, res, next) => {
38
40
  env.render(`layouts/${pageLayout}.njk`, (0, resolveTranslations_1.resolveTranslations)({
39
41
  context,
40
42
  globals,
41
- settings: env.getGlobal("settings"),
42
- market: res.locals.market || "",
43
- lang: res.locals.lang || "",
44
- currency: res.locals.currency || "",
43
+ ...renderData
45
44
  }, env.getGlobal("t")), (err, html) => {
46
45
  if (err) {
47
46
  return next(new Error(`❌ Nunjucks render error: ${err.message}`));
@@ -7,6 +7,7 @@ export interface Globals {
7
7
  app: any;
8
8
  Setting: any;
9
9
  assets: string;
10
+ customer: any;
10
11
  currency: Currency;
11
12
  cart?: any;
12
13
  themeDevMode?: boolean;
@@ -14,6 +15,9 @@ export interface Globals {
14
15
  }
15
16
  export interface RenderContext {
16
17
  page: Page;
18
+ query: {
19
+ q: string;
20
+ };
17
21
  [key: string]: any;
18
22
  }
19
23
  export type TMode = "production" | "devlopment";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qumra-engine",
3
- "version": "2.0.146",
3
+ "version": "2.0.149",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {