qumra-engine 2.0.50 → 2.0.52
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/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.js +3 -1
- package/dist/extensions/logic/content copy.d.ts +4 -1
- package/dist/extensions/logic/content copy.js +34 -13
- package/dist/extensions/logic/content.js +14 -1
- package/dist/extensions/logic/footer.d.ts +1 -1
- package/dist/extensions/logic/footer.js +4 -0
- package/dist/extensions/logic/header.d.ts +1 -1
- package/dist/extensions/logic/header.js +4 -0
- package/dist/extensions/logic/preview-widget.d.ts +10 -0
- package/dist/extensions/logic/preview-widget.js +52 -0
- package/dist/filters/logic/money/money_with_currency.d.ts +1 -1
- package/dist/filters/logic/money/money_with_currency.js +4 -2
- package/dist/middleware/init.middleware.js +4 -0
- package/dist/middleware/mergeData.middleware.js +6 -0
- package/dist/middleware/prepareData.middleware.js +15 -5
- package/dist/middleware/setGlobals.middleware.d.ts +2 -0
- package/dist/middleware/setGlobals.middleware.js +31 -0
- package/dist/middleware.js +2 -2
- package/dist/types/sharedTypes.d.ts +11 -0
- package/dist/types/sharedTypes.js +1 -1
- package/package.json +1 -1
|
@@ -7,3 +7,4 @@ export { default as content } from './logic/content';
|
|
|
7
7
|
export { default as qumra_head } from './logic/qumra-head';
|
|
8
8
|
export { default as qumra_scripts } from './logic/qumra-scripts';
|
|
9
9
|
export { default as include } from './logic/ui';
|
|
10
|
+
export { default as preview_widget } from './logic/preview-widget';
|
package/dist/extensions/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.include = exports.qumra_scripts = exports.qumra_head = exports.content = exports.footer = exports.header = exports.form = exports.widget = exports.seo = void 0;
|
|
6
|
+
exports.preview_widget = exports.include = exports.qumra_scripts = exports.qumra_head = exports.content = exports.footer = exports.header = exports.form = exports.widget = exports.seo = void 0;
|
|
7
7
|
var seo_1 = require("./logic/seo");
|
|
8
8
|
Object.defineProperty(exports, "seo", { enumerable: true, get: function () { return __importDefault(seo_1).default; } });
|
|
9
9
|
var widget_1 = require("./logic/widget");
|
|
@@ -22,3 +22,5 @@ var qumra_scripts_1 = require("./logic/qumra-scripts");
|
|
|
22
22
|
Object.defineProperty(exports, "qumra_scripts", { enumerable: true, get: function () { return __importDefault(qumra_scripts_1).default; } });
|
|
23
23
|
var ui_1 = require("./logic/ui");
|
|
24
24
|
Object.defineProperty(exports, "include", { enumerable: true, get: function () { return __importDefault(ui_1).default; } });
|
|
25
|
+
var preview_widget_1 = require("./logic/preview-widget");
|
|
26
|
+
Object.defineProperty(exports, "preview_widget", { enumerable: true, get: function () { return __importDefault(preview_widget_1).default; } });
|
|
@@ -2,6 +2,9 @@ import nunjucks from "nunjucks";
|
|
|
2
2
|
declare const _default: {
|
|
3
3
|
tags: string[];
|
|
4
4
|
parse(parser: any, nodes: any): any;
|
|
5
|
-
run({ ctx, env }:
|
|
5
|
+
run({ ctx, env }: {
|
|
6
|
+
ctx: any;
|
|
7
|
+
env: nunjucks.Environment;
|
|
8
|
+
}): nunjucks.runtime.SafeString;
|
|
6
9
|
};
|
|
7
10
|
export default _default;
|
|
@@ -7,7 +7,7 @@ const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
|
7
7
|
const normalizeWidgetPath_1 = require("../../utils/normalizeWidgetPath");
|
|
8
8
|
exports.default = new (class WidgetExtension {
|
|
9
9
|
constructor() {
|
|
10
|
-
this.tags = ["
|
|
10
|
+
this.tags = ["content"];
|
|
11
11
|
}
|
|
12
12
|
parse(parser, nodes) {
|
|
13
13
|
const tok = parser.nextToken();
|
|
@@ -15,18 +15,39 @@ exports.default = new (class WidgetExtension {
|
|
|
15
15
|
parser.advanceAfterBlockEnd(tok.value);
|
|
16
16
|
return new nodes.CallExtension(this, "run", args);
|
|
17
17
|
}
|
|
18
|
-
run({ ctx, env }
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
run({ ctx, env }) {
|
|
19
|
+
const widgets = env.getGlobal("widgets");
|
|
20
|
+
const renderedWidgets = [];
|
|
21
|
+
for (const widget of widgets) {
|
|
22
|
+
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
23
|
+
if (!widgetTemplatePath) {
|
|
24
|
+
return new nunjucks_1.default.runtime.SafeString(`
|
|
25
|
+
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
26
|
+
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widget}
|
|
27
|
+
</div>
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const html = env.render(widgetTemplatePath, {
|
|
32
|
+
context: ctx.context,
|
|
33
|
+
globals: ctx.globals,
|
|
34
|
+
widget: {
|
|
35
|
+
id: widget.id,
|
|
36
|
+
type: widget.widget,
|
|
37
|
+
data: widget.data,
|
|
38
|
+
blocks: widget.blocks ?? [],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
renderedWidgets.push(html);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
renderedWidgets.push(`
|
|
45
|
+
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
46
|
+
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
47
|
+
</div>
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
30
50
|
}
|
|
51
|
+
return new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
31
52
|
}
|
|
32
53
|
})();
|
|
@@ -16,7 +16,20 @@ exports.default = new (class WidgetExtension {
|
|
|
16
16
|
return new nodes.CallExtension(this, "run", args);
|
|
17
17
|
}
|
|
18
18
|
run({ ctx, env }) {
|
|
19
|
-
|
|
19
|
+
let widgetPreview = null;
|
|
20
|
+
if (env.getGlobal("widget")) {
|
|
21
|
+
widgetPreview = env.getGlobal("widget");
|
|
22
|
+
}
|
|
23
|
+
let widgets = [];
|
|
24
|
+
if (!widgetPreview) {
|
|
25
|
+
widgets = env.getGlobal("widgets");
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
widgets = [{
|
|
29
|
+
...widgetPreview,
|
|
30
|
+
widget: widgetPreview.widgetKey,
|
|
31
|
+
}];
|
|
32
|
+
}
|
|
20
33
|
const renderedWidgets = [];
|
|
21
34
|
for (const widget of widgets) {
|
|
22
35
|
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widget);
|
|
@@ -16,6 +16,10 @@ exports.default = new (class WidgetExtension {
|
|
|
16
16
|
return new nodes.CallExtension(this, "run", args);
|
|
17
17
|
}
|
|
18
18
|
run({ ctx, env }) {
|
|
19
|
+
const widgetPreview = env.getGlobal("widget");
|
|
20
|
+
if (widgetPreview) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
19
23
|
try {
|
|
20
24
|
const setting = env.getGlobal("settings");
|
|
21
25
|
const footer = setting?.footer;
|
|
@@ -16,6 +16,10 @@ exports.default = new (class HeaderExtension {
|
|
|
16
16
|
return new nodes.CallExtension(this, "run", args);
|
|
17
17
|
}
|
|
18
18
|
run({ ctx, env }) {
|
|
19
|
+
const widgetPreview = env.getGlobal("widget");
|
|
20
|
+
if (widgetPreview) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
19
23
|
try {
|
|
20
24
|
const setting = env.getGlobal("settings");
|
|
21
25
|
const header = setting?.header;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
const nunjucks_1 = __importDefault(require("nunjucks"));
|
|
7
|
+
const normalizeWidgetPath_1 = require("../../utils/normalizeWidgetPath");
|
|
8
|
+
exports.default = new (class WidgetExtension {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.tags = ["preview_widget"];
|
|
11
|
+
}
|
|
12
|
+
parse(parser, nodes) {
|
|
13
|
+
const tok = parser.nextToken();
|
|
14
|
+
const args = parser.parseSignature(true, true);
|
|
15
|
+
parser.advanceAfterBlockEnd(tok.value);
|
|
16
|
+
return new nodes.CallExtension(this, "run", args);
|
|
17
|
+
}
|
|
18
|
+
run({ ctx, env }) {
|
|
19
|
+
const widget = env.getGlobal("widget");
|
|
20
|
+
console.log("🚀 ~ run ~ widget:", widget);
|
|
21
|
+
const renderedWidgets = [];
|
|
22
|
+
const widgetTemplatePath = (0, normalizeWidgetPath_1.normalizeWidgetPath)(widget.widgetKey);
|
|
23
|
+
if (!widgetTemplatePath) {
|
|
24
|
+
return new nunjucks_1.default.runtime.SafeString(`
|
|
25
|
+
<div style="padding: 12px; background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; margin: 8px 0;">
|
|
26
|
+
⚠️ <strong>مسار الويجيت غير صالح:</strong> ${widget.widgetKey}
|
|
27
|
+
</div>
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const html = env.render(widgetTemplatePath, {
|
|
32
|
+
context: ctx.context,
|
|
33
|
+
globals: ctx.globals,
|
|
34
|
+
widget: {
|
|
35
|
+
id: widget.id,
|
|
36
|
+
type: widget.widgetKey,
|
|
37
|
+
data: widget.data,
|
|
38
|
+
blocks: widget.blocks ?? [],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
renderedWidgets.push(html);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
renderedWidgets.push(`
|
|
45
|
+
<div style="padding:10px;background:#ffe;border:1px solid #fc0;color:#aa0">
|
|
46
|
+
⚠️ Error rendering widget '${widget.widget}': ${err.message}
|
|
47
|
+
</div>
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
return new nunjucks_1.default.runtime.SafeString(renderedWidgets.join("\n"));
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function money_with_currency(amount: number
|
|
1
|
+
export default function money_with_currency(amount: number): string;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = money_with_currency;
|
|
4
|
-
|
|
4
|
+
const globals_1 = require("../../../store/globals");
|
|
5
|
+
function money_with_currency(amount) {
|
|
6
|
+
const currency = (0, globals_1.getGlobal)('currency');
|
|
5
7
|
if (typeof amount !== 'number')
|
|
6
8
|
return '';
|
|
7
|
-
return `${amount.toFixed(2)}
|
|
9
|
+
return `${amount.toFixed(2)}${currency.currencySymbol}`;
|
|
8
10
|
}
|
|
@@ -11,6 +11,10 @@ const initMiddleware = ({ mode, getRender, setRender, app, }) => {
|
|
|
11
11
|
: app?.url + req.originalUrl;
|
|
12
12
|
const parsedUrl = (0, qumra_utils_1.parseUrlString)(fullUrl);
|
|
13
13
|
res.locals.parsedUrl = parsedUrl;
|
|
14
|
+
if (req.query?.themeWidget) {
|
|
15
|
+
res.locals.themeWidget = req.query?.themeWidget;
|
|
16
|
+
res.locals.preview = Boolean(req.query?.preview) ?? false;
|
|
17
|
+
}
|
|
14
18
|
if (typeof getRender === "function") {
|
|
15
19
|
res.locals.cache.getRender = getRender;
|
|
16
20
|
}
|
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeDataMiddleware = void 0;
|
|
4
4
|
const mergeDataMiddleware = async (req, res, next) => {
|
|
5
5
|
try {
|
|
6
|
+
if (res.locals.preview && res.locals.themeWidget) {
|
|
7
|
+
res.locals.env.addGlobal("widget", res.locals.render.engine?.widget ?? []);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
res.locals.env.addGlobal("widget", null);
|
|
11
|
+
}
|
|
6
12
|
const widgets = res.locals.render.engine?.page?.widgets ?? [];
|
|
7
13
|
res.locals.env.addGlobal("engineData", res.locals.render.engine);
|
|
8
14
|
res.locals.env.addGlobal("widgets", widgets);
|
|
@@ -7,6 +7,7 @@ exports.prepareDataMiddleware = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const prepareDataMiddleware = (req, res, next) => {
|
|
9
9
|
const parsedUrl = res.locals.parsedUrl;
|
|
10
|
+
console.log("🚀 ~ prepareDataMiddleware ~ parsedUrl:", parsedUrl);
|
|
10
11
|
// ✅ تخطي الرندر في production لبعض المسارات
|
|
11
12
|
// if (res.locals.mode === "production") {
|
|
12
13
|
// if (isPathAllowedToRender(parsedUrl.pathname)) {
|
|
@@ -23,15 +24,23 @@ const prepareDataMiddleware = (req, res, next) => {
|
|
|
23
24
|
if (req.query?.appTheme) {
|
|
24
25
|
params.set("appTheme", String(req.query.appTheme));
|
|
25
26
|
}
|
|
27
|
+
if (res.locals.themeWidget) {
|
|
28
|
+
params.set("themeWidget", String(res.locals.themeWidget));
|
|
29
|
+
}
|
|
26
30
|
themePath = params.toString() ? `?${params.toString()}` : "";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
let api = "";
|
|
32
|
+
if (res.locals.preview && res.locals.themeWidget) {
|
|
33
|
+
api = `https://store-gate.qumra.cloud/render/preview-widget${themePath}`;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
api = true
|
|
37
|
+
? `https://store-gate.qumra.cloud/render${themePath}`
|
|
38
|
+
: `http://192.168.1.8:4019/v1/render${themePath}`;
|
|
39
|
+
}
|
|
30
40
|
const qdid = req.cookies.qdid || "";
|
|
31
41
|
const Authorization = req.cookies.authorization || "";
|
|
32
42
|
axios_1.default
|
|
33
|
-
.post(api, { url: parsedUrl.fullUrl },
|
|
34
|
-
{
|
|
43
|
+
.post(api, { url: parsedUrl.fullUrl }, {
|
|
35
44
|
headers: {
|
|
36
45
|
"Content-Type": "application/json",
|
|
37
46
|
Authorization,
|
|
@@ -45,6 +54,7 @@ const prepareDataMiddleware = (req, res, next) => {
|
|
|
45
54
|
next();
|
|
46
55
|
})
|
|
47
56
|
.catch((err) => {
|
|
57
|
+
console.log("🚀 ~ prepareDataMiddleware ~ err:", err);
|
|
48
58
|
console.log("❌ prepareDataMiddleware error:", err.message);
|
|
49
59
|
// next(err);
|
|
50
60
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeDataMiddleware = void 0;
|
|
4
|
+
const globals_1 = require("../store/globals");
|
|
5
|
+
const mergeDataMiddleware = async (req, res, next) => {
|
|
6
|
+
try {
|
|
7
|
+
if (res.locals.preview && res.locals.themeWidget) {
|
|
8
|
+
res.locals.env.addGlobal("widget", res.locals.render.engine?.widget ?? []);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
res.locals.env.addGlobal("widget", null);
|
|
12
|
+
}
|
|
13
|
+
const widgets = res.locals.render.engine?.page?.widgets ?? [];
|
|
14
|
+
(0, globals_1.setGlobal)("currency", res.locals.render.globals?.currency);
|
|
15
|
+
res.locals.env.addGlobal("engineData", res.locals.render.engine);
|
|
16
|
+
res.locals.env.addGlobal("widgets", widgets);
|
|
17
|
+
res.locals.env.addGlobal("pageData", {
|
|
18
|
+
layout: res.locals.render.engine?.page?.layout,
|
|
19
|
+
title: res.locals.render.engine?.page?.title,
|
|
20
|
+
handle: res.locals.render.engine?.page?.handle,
|
|
21
|
+
});
|
|
22
|
+
const settingsData = res.locals.render.engine?.settings;
|
|
23
|
+
res.locals.env.addGlobal("settings", settingsData);
|
|
24
|
+
next();
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.error("❌ mergeDataMiddleware error:", err);
|
|
28
|
+
return next(err);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.mergeDataMiddleware = mergeDataMiddleware;
|
package/dist/middleware.js
CHANGED
|
@@ -16,7 +16,7 @@ const locals_middleware_1 = require("./middleware/locals.middleware");
|
|
|
16
16
|
const globals_middleware_1 = require("./middleware/globals.middleware");
|
|
17
17
|
const extensions_middleware_1 = require("./middleware/extensions.middleware");
|
|
18
18
|
const isPathAllowedToRender_1 = require("./utils/isPathAllowedToRender");
|
|
19
|
-
const
|
|
19
|
+
const setGlobals_middleware_1 = require("./middleware/setGlobals.middleware");
|
|
20
20
|
const express_session_1 = __importDefault(require("express-session"));
|
|
21
21
|
const printServerLog_1 = require("./utils/printServerLog");
|
|
22
22
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
@@ -76,7 +76,7 @@ const startEngine = async ({ mode, getRender, setRender, port = 3000, themesRepo
|
|
|
76
76
|
});
|
|
77
77
|
app.use(prepareData_middleware_1.prepareDataMiddleware);
|
|
78
78
|
app.use(nunjucks_middleware_1.nunjucksMiddleWare);
|
|
79
|
-
app.use(
|
|
79
|
+
app.use(setGlobals_middleware_1.mergeDataMiddleware);
|
|
80
80
|
app.use(locals_middleware_1.localesMiddleware);
|
|
81
81
|
app.use(filters_middleware_1.nunjucksFiltersMiddleWare);
|
|
82
82
|
app.use(globals_middleware_1.nunjucksGlobalsMiddleWare);
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export interface Currency {
|
|
2
|
+
title: string;
|
|
3
|
+
currencySymbol: string;
|
|
4
|
+
currencyCode: string;
|
|
5
|
+
}
|
|
1
6
|
export interface Globals {
|
|
2
7
|
app: any;
|
|
3
8
|
Setting: any;
|
|
4
9
|
assets: string;
|
|
10
|
+
currency: Currency;
|
|
5
11
|
}
|
|
6
12
|
export interface RenderContext {
|
|
7
13
|
page: Page;
|
|
@@ -12,6 +18,11 @@ export interface MainData {
|
|
|
12
18
|
globals?: Globals;
|
|
13
19
|
context?: RenderContext;
|
|
14
20
|
engine?: {
|
|
21
|
+
widget: Array<{
|
|
22
|
+
type: string;
|
|
23
|
+
data: Record<string, any>;
|
|
24
|
+
id: string;
|
|
25
|
+
}>;
|
|
15
26
|
page: {
|
|
16
27
|
title: string;
|
|
17
28
|
handle: string;
|