@elcarte/core 0.0.1 → 0.0.3
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/components/PageBuilder.js +18 -0
- package/dist/components/ProductDetail.js +4 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/lib/data.js +58 -108
- package/package.json +2 -2
- package/dist/components/PageBuilder.jsx +0 -32
- package/dist/components/ProductDetail.jsx +0 -18
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Hero, ProductGrid, TextBlock } from '@elcarte/blocks';
|
|
3
|
+
const DEFAULT_REGISTRY = {
|
|
4
|
+
hero: Hero,
|
|
5
|
+
product_grid: ProductGrid,
|
|
6
|
+
text_block: TextBlock,
|
|
7
|
+
};
|
|
8
|
+
export const PageBuilder = ({ blocks, customRegistry = {} }) => {
|
|
9
|
+
const registry = { ...DEFAULT_REGISTRY, ...customRegistry };
|
|
10
|
+
return (_jsx(_Fragment, { children: blocks.map((block) => {
|
|
11
|
+
const Component = registry[block.type];
|
|
12
|
+
if (!Component) {
|
|
13
|
+
console.warn(`Unknown block type: ${block.type}`);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return _jsx(Component, { ...block.data }, block.id);
|
|
17
|
+
}) }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export const ProductDetail = ({ data, locale }) => {
|
|
3
|
+
return (_jsx("div", { className: "container mx-auto p-4", children: _jsxs("div", { className: "bg-white shadow rounded-lg p-6 max-w-2xl mx-auto", children: [_jsx("h1", { className: "text-3xl font-bold mb-4", children: data.title }), _jsx("p", { className: "text-gray-600 mb-4", children: data.description }), _jsxs("div", { className: "flex items-center justify-between mt-6", children: [_jsx("span", { className: "text-2xl font-bold text-green-600", children: new Intl.NumberFormat(locale === 'cs' ? 'cs-CZ' : 'en-US', { style: 'currency', currency: locale === 'cs' ? 'CZK' : 'USD' }).format(data.price) }), _jsx("button", { className: "px-6 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition", children: locale === 'cs' ? 'Přidat do košíku' : 'Add to Cart' })] })] }) }));
|
|
4
|
+
};
|
package/dist/components/index.js
CHANGED
package/dist/lib/data.js
CHANGED
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
1
|
import { headers as nextHeaders } from 'next/headers';
|
|
38
2
|
/**
|
|
39
3
|
* Get the API base URL for server-side requests.
|
|
@@ -50,78 +14,64 @@ function getApiBaseUrl() {
|
|
|
50
14
|
// Only used server-side; client-side uses relative URLs
|
|
51
15
|
return process.env.ELCARTE_API_URL || 'http://127.0.0.1:8080';
|
|
52
16
|
}
|
|
53
|
-
export function getResolvedData(slug, host) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (!resolvedHost) {
|
|
88
|
-
resolvedHost = headersList.get('host') || undefined;
|
|
89
|
-
}
|
|
90
|
-
return [3 /*break*/, 5];
|
|
91
|
-
case 4:
|
|
92
|
-
_a = _b.sent();
|
|
93
|
-
return [3 /*break*/, 5];
|
|
94
|
-
case 5: return [3 /*break*/, 7];
|
|
95
|
-
case 6:
|
|
96
|
-
protocol = window.location.protocol.replace(':', '');
|
|
97
|
-
resolvedHost = resolvedHost || window.location.host;
|
|
98
|
-
_b.label = 7;
|
|
99
|
-
case 7:
|
|
100
|
-
headers = {};
|
|
101
|
-
if (resolvedHost) {
|
|
102
|
-
headers['X-Forwarded-Host'] = resolvedHost;
|
|
103
|
-
}
|
|
104
|
-
if (protocol) {
|
|
105
|
-
headers['X-Forwarded-Proto'] = protocol;
|
|
106
|
-
}
|
|
107
|
-
return [4 /*yield*/, fetch("".concat(baseUrl).concat(endpoint), {
|
|
108
|
-
next: { tags: ['pages'] },
|
|
109
|
-
headers: headers
|
|
110
|
-
})];
|
|
111
|
-
case 8:
|
|
112
|
-
res = _b.sent();
|
|
113
|
-
if (!res.ok) {
|
|
114
|
-
console.error("Failed to fetch data for ".concat(path, ": ").concat(res.status));
|
|
115
|
-
return [2 /*return*/, null];
|
|
116
|
-
}
|
|
117
|
-
return [4 /*yield*/, res.json()];
|
|
118
|
-
case 9: return [2 /*return*/, _b.sent()];
|
|
119
|
-
case 10:
|
|
120
|
-
error_1 = _b.sent();
|
|
121
|
-
console.error('Error fetching data:', error_1);
|
|
122
|
-
return [2 /*return*/, null];
|
|
123
|
-
case 11: return [2 /*return*/];
|
|
17
|
+
export async function getResolvedData(slug, host) {
|
|
18
|
+
const path = slug && slug.length > 0 ? slug.join('/') : '';
|
|
19
|
+
const endpoint = path ? `/data/resolve/${path}` : '/data/resolve';
|
|
20
|
+
try {
|
|
21
|
+
const isServer = typeof window === 'undefined';
|
|
22
|
+
// Server-side: use configured API URL (internal communication)
|
|
23
|
+
// Client-side: use relative URL (browser handles domain)
|
|
24
|
+
const baseUrl = isServer ? getApiBaseUrl() : '';
|
|
25
|
+
// Resolve host: prefer passed host, then try next/headers, finally window.location
|
|
26
|
+
let resolvedHost = host;
|
|
27
|
+
let protocol = 'http';
|
|
28
|
+
if (isServer) {
|
|
29
|
+
try {
|
|
30
|
+
const headersList = await nextHeaders();
|
|
31
|
+
// Get protocol: prefer x-forwarded-proto, fallback to referer
|
|
32
|
+
const forwardedProto = headersList.get('x-forwarded-proto');
|
|
33
|
+
const referer = headersList.get('referer');
|
|
34
|
+
if (forwardedProto && forwardedProto !== 'http') {
|
|
35
|
+
protocol = forwardedProto;
|
|
36
|
+
}
|
|
37
|
+
else if (referer) {
|
|
38
|
+
// Extract protocol from referer URL (e.g., "https://a.elcarte.test/")
|
|
39
|
+
protocol = referer.startsWith('https') ? 'https' : 'http';
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
protocol = forwardedProto || 'http';
|
|
43
|
+
}
|
|
44
|
+
if (!resolvedHost) {
|
|
45
|
+
resolvedHost = headersList.get('host') || undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// nextHeaders() might fail outside of React Server Component context
|
|
124
50
|
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
protocol = window.location.protocol.replace(':', '');
|
|
54
|
+
resolvedHost = resolvedHost || window.location.host;
|
|
55
|
+
}
|
|
56
|
+
const headers = {};
|
|
57
|
+
if (resolvedHost) {
|
|
58
|
+
headers['X-Forwarded-Host'] = resolvedHost;
|
|
59
|
+
}
|
|
60
|
+
if (protocol) {
|
|
61
|
+
headers['X-Forwarded-Proto'] = protocol;
|
|
62
|
+
}
|
|
63
|
+
const res = await fetch(`${baseUrl}${endpoint}`, {
|
|
64
|
+
next: { tags: ['pages'] },
|
|
65
|
+
headers
|
|
125
66
|
});
|
|
126
|
-
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
console.error(`Failed to fetch data for ${path}: ${res.status}`);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return await res.json();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error('Error fetching data:', error);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
127
77
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elcarte/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Core SDK for Elcarte e-commerce platform - API client, hooks, middleware",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"@types/react-dom": "^19.0.0",
|
|
46
46
|
"typescript": "^5.0.0"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import { Hero, ProductGrid, TextBlock } from '@elcarte/blocks';
|
|
14
|
-
var DEFAULT_REGISTRY = {
|
|
15
|
-
hero: Hero,
|
|
16
|
-
product_grid: ProductGrid,
|
|
17
|
-
text_block: TextBlock,
|
|
18
|
-
};
|
|
19
|
-
export var PageBuilder = function (_a) {
|
|
20
|
-
var blocks = _a.blocks, _b = _a.customRegistry, customRegistry = _b === void 0 ? {} : _b;
|
|
21
|
-
var registry = __assign(__assign({}, DEFAULT_REGISTRY), customRegistry);
|
|
22
|
-
return (<>
|
|
23
|
-
{blocks.map(function (block) {
|
|
24
|
-
var Component = registry[block.type];
|
|
25
|
-
if (!Component) {
|
|
26
|
-
console.warn("Unknown block type: ".concat(block.type));
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return <Component key={block.id} {...block.data}/>;
|
|
30
|
-
})}
|
|
31
|
-
</>);
|
|
32
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export var ProductDetail = function (_a) {
|
|
3
|
-
var data = _a.data, locale = _a.locale;
|
|
4
|
-
return (<div className="container mx-auto p-4">
|
|
5
|
-
<div className="bg-white shadow rounded-lg p-6 max-w-2xl mx-auto">
|
|
6
|
-
<h1 className="text-3xl font-bold mb-4">{data.title}</h1>
|
|
7
|
-
<p className="text-gray-600 mb-4">{data.description}</p>
|
|
8
|
-
<div className="flex items-center justify-between mt-6">
|
|
9
|
-
<span className="text-2xl font-bold text-green-600">
|
|
10
|
-
{new Intl.NumberFormat(locale === 'cs' ? 'cs-CZ' : 'en-US', { style: 'currency', currency: locale === 'cs' ? 'CZK' : 'USD' }).format(data.price)}
|
|
11
|
-
</span>
|
|
12
|
-
<button className="px-6 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 transition">
|
|
13
|
-
{locale === 'cs' ? 'Přidat do košíku' : 'Add to Cart'}
|
|
14
|
-
</button>
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
</div>);
|
|
18
|
-
};
|