basklee-svelte 0.9.1 → 0.9.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/package.json +1 -1
- package/runtime/marketplace.mjs +58 -4
- package/src/project-readme.mjs +3 -0
- package/templates/src/lib/basklee/appLoadServer.ts +1 -0
- package/templates/src/lib/components/basklee/blog/BlogArticle.README.md +2 -0
- package/templates/src/lib/components/basklee/blog/BlogArticle.svelte +12 -0
- package/templates/src/lib/utils/basklee/blogArticleHtml.ts +60 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basklee-svelte",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "SvelteKit 2 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/runtime/marketplace.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { chown, mkdir, readFile, readdir, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, relative, resolve } from 'node:path';
|
|
3
3
|
import {
|
|
4
|
+
BlockList,
|
|
4
5
|
getDefaultAutoSelectFamilyAttemptTimeout,
|
|
5
6
|
isIP,
|
|
6
7
|
setDefaultAutoSelectFamilyAttemptTimeout,
|
|
@@ -24,6 +25,62 @@ if (getDefaultAutoSelectFamilyAttemptTimeout() < connectTimeout) {
|
|
|
24
25
|
const requestTimeout = 30_000;
|
|
25
26
|
const uploadTimeout = 300_000;
|
|
26
27
|
|
|
28
|
+
// Cloudflare's edge addresses (https://www.cloudflare.com/ips-v4 and /ips-v6,
|
|
29
|
+
// checked 2026-11-18). A storefront behind Cloudflare is reached from one of
|
|
30
|
+
// them, so the address a proxy in front of it passes on is Cloudflare's, not
|
|
31
|
+
// the visitor's. Cloudflare puts the visitor's address into CF-Connecting-IP
|
|
32
|
+
// and overwrites any value a visitor sends; the header is taken only when the
|
|
33
|
+
// address it came with is a Cloudflare one. Nothing to set up: a storefront
|
|
34
|
+
// that is not behind Cloudflare keeps the address it gets.
|
|
35
|
+
const cloudflareRanges = [
|
|
36
|
+
'173.245.48.0/20', '103.21.244.0/22', '103.22.200.0/22', '103.31.4.0/22',
|
|
37
|
+
'141.101.64.0/18', '108.162.192.0/18', '190.93.240.0/20', '188.114.96.0/20',
|
|
38
|
+
'197.234.240.0/22', '198.41.128.0/17', '162.158.0.0/15', '104.16.0.0/13',
|
|
39
|
+
'104.24.0.0/14', '172.64.0.0/13', '131.0.72.0/22',
|
|
40
|
+
'2400:cb00::/32', '2606:4700::/32', '2803:f800::/32', '2405:b500::/32',
|
|
41
|
+
'2405:8100::/32', '2a06:98c0::/29', '2c0f:f248::/32',
|
|
42
|
+
];
|
|
43
|
+
const cloudflare = new BlockList();
|
|
44
|
+
for (const range of cloudflareRanges) {
|
|
45
|
+
const [address, prefix] = range.split('/');
|
|
46
|
+
cloudflare.addSubnet(address, Number(prefix), address.includes(':') ? 'ipv6' : 'ipv4');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One address written plainly ('::ffff:1.2.3.4' as 1.2.3.4), or ''. */
|
|
50
|
+
function plainAddress(value) {
|
|
51
|
+
let address = String(value ?? '').trim();
|
|
52
|
+
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(address);
|
|
53
|
+
if (mapped) {
|
|
54
|
+
address = mapped[1];
|
|
55
|
+
}
|
|
56
|
+
return isIP(address) ? address : '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** True for an address of Cloudflare's edge. */
|
|
60
|
+
export function isCloudflareAddress(value) {
|
|
61
|
+
const address = plainAddress(value);
|
|
62
|
+
if (!address) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return cloudflare.check(address, isIP(address) === 6 ? 'ipv6' : 'ipv4');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The visitor's address for the backend: X-Init-Ip, X-Real-IP or the first
|
|
70
|
+
* X-Forwarded-For entry, and CF-Connecting-IP instead when that address is a
|
|
71
|
+
* Cloudflare edge (or there is no proxy address at all) and Cloudflare sent one.
|
|
72
|
+
* @param {Headers} headers
|
|
73
|
+
*/
|
|
74
|
+
export function marketplaceClientIp(headers) {
|
|
75
|
+
const proxied = headers.get('x-init-ip') || headers.get('x-real-ip');
|
|
76
|
+
const forwarded = headers.get('x-forwarded-for')?.split(',')[0]?.trim();
|
|
77
|
+
const visitor = plainAddress(headers.get('cf-connecting-ip'));
|
|
78
|
+
if (visitor && (!proxied || isCloudflareAddress(proxied))) {
|
|
79
|
+
return visitor;
|
|
80
|
+
}
|
|
81
|
+
return proxied || forwarded || '';
|
|
82
|
+
}
|
|
83
|
+
|
|
27
84
|
/** @param {Request} request */
|
|
28
85
|
export function marketplaceRequestTimeout(request) {
|
|
29
86
|
const contentType = request.headers.get('content-type') ?? '';
|
|
@@ -320,10 +377,7 @@ export async function forwardMarketplace(request, configuration = {}) {
|
|
|
320
377
|
headers.set('origin', `https://${tenant.domain}`);
|
|
321
378
|
}
|
|
322
379
|
headers.set('Accept-Encoding', 'identity');
|
|
323
|
-
const clientIp =
|
|
324
|
-
request.headers.get('x-init-ip') ||
|
|
325
|
-
request.headers.get('x-real-ip') ||
|
|
326
|
-
request.headers.get('x-forwarded-for')?.split(',')[0]?.trim();
|
|
380
|
+
const clientIp = marketplaceClientIp(request.headers);
|
|
327
381
|
if (clientIp) {
|
|
328
382
|
headers.set('X-Init-Ip', clientIp);
|
|
329
383
|
}
|
package/src/project-readme.mjs
CHANGED
|
@@ -382,6 +382,9 @@ location / {
|
|
|
382
382
|
|
|
383
383
|
Here localhost is your frontend process on your VPS. That process selects the
|
|
384
384
|
remote personal API from the domain file. The proxy must overwrite those headers.
|
|
385
|
+
Behind Cloudflare, \`$remote_addr\` is a Cloudflare address: the storefront
|
|
386
|
+
notices it and sends the customer's own address from \`CF-Connecting-IP\`
|
|
387
|
+
instead, with nothing to set up.
|
|
385
388
|
An unknown domain never falls back to another tenant. \`/robots.txt\` points
|
|
386
389
|
crawlers to \`/sitemap.xml\`, which lists the public pages, categories, products
|
|
387
390
|
on sale and journal publications in every storefront language (each publication
|
|
@@ -6,6 +6,8 @@ The article page shows one journal article: its cover, its text, the products at
|
|
|
6
6
|
|
|
7
7
|
Article videos may come as the backend's own paths (`/ps3/...`). In an Android app build those paths (cover, videos, images and videos inside the text) load from the storefront address.
|
|
8
8
|
|
|
9
|
+
The text is sanitized with DOMPurify in `src/lib/utils/basklee/blogArticleHtml.ts`. A YouTube player the editor inserts (an `<iframe>` with a `youtube.com` or `youtube-nocookie.com` `/embed/<id>` address) is kept and played from `youtube-nocookie.com` at the article's width in 16:9, with fixed `allow`, `loading="lazy"` and referrer attributes and an optional start second. Other frames, scripts, forms and event attributes are removed.
|
|
10
|
+
|
|
9
11
|
The cover and the images of the text open larger: a click, Enter or Space on one opens `ProductReviewImageViewer` at that image, with the article's other images a step away and each image's caption (its `figcaption`, else its `title`, else its `alt`) under it. The images get `role="button"`, a keyboard stop and an «Open image» name; a zoom-in cursor marks them. Images inside a link, a button or a product placement keep their own action. The helper is `src/lib/utils/basklee/blogImageViewer.ts`.
|
|
10
12
|
|
|
11
13
|
Products the author places in the text appear at those positions: an empty block with `data-product-id="12"` shows one product card, `data-product-ids="12,15,9"` a row of up to 24 cards. The block keeps the editor's float or centred style, and `data-product-hidden-badges` (`new`, `popular`, `good-deal`) turns card badges off. Products missing from `related_products` are loaded with `products_search` and `filters.id_in`, up to 35 IDs per request, and stored with `store.setProduct()`; a block whose products are not found stays hidden. Article text styles do not reach the cards, and in a narrow article a floated card stands alone in the middle. The helper is `src/lib/utils/basklee/blogProductPlacements.ts`.
|
|
@@ -1048,6 +1048,18 @@
|
|
|
1048
1048
|
width: 100%;
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
1051
|
+
/* A YouTube player from the editor: the article's width, 16:9. */
|
|
1052
|
+
.op-feature-prose :global(iframe.blog-post-editor-youtube:where(:not([data-product-id] *, [data-product-ids] *))) {
|
|
1053
|
+
display: block;
|
|
1054
|
+
width: 100%;
|
|
1055
|
+
height: auto;
|
|
1056
|
+
margin: 1.5rem 0;
|
|
1057
|
+
clear: both;
|
|
1058
|
+
aspect-ratio: 16 / 9;
|
|
1059
|
+
border: 0;
|
|
1060
|
+
background: #000;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1051
1063
|
.op-feature-prose :global(figcaption:where(:not([data-product-id] *, [data-product-ids] *))) {
|
|
1052
1064
|
margin-top: 0.5rem;
|
|
1053
1065
|
font-size: 0.875rem;
|
|
@@ -14,8 +14,9 @@ type TStylePatterns = Record<string, RegExp>;
|
|
|
14
14
|
* the backend, so the storefront sanitizes it before display. The allowlist
|
|
15
15
|
* matches what that editor writes: text formatting, headings, lists and task
|
|
16
16
|
* lists, quotes, code blocks, tables, images and galleries, videos,
|
|
17
|
-
* collapsible sections, formulas and alignment, color and size styles
|
|
18
|
-
*
|
|
17
|
+
* collapsible sections, formulas and alignment, color and size styles,
|
|
18
|
+
* and YouTube players. A frame is kept only when its address is a YouTube
|
|
19
|
+
* embed (see blogYoutubeEmbedSource); every other frame is removed.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
export const blogArticleTags = [
|
|
@@ -78,6 +79,7 @@ export const blogArticleTags = [
|
|
|
78
79
|
'track',
|
|
79
80
|
'details',
|
|
80
81
|
'summary',
|
|
82
|
+
'iframe',
|
|
81
83
|
];
|
|
82
84
|
|
|
83
85
|
const attributes = [
|
|
@@ -135,6 +137,9 @@ const attributes = [
|
|
|
135
137
|
'data-product-id',
|
|
136
138
|
'data-product-ids',
|
|
137
139
|
'data-product-hidden-badges',
|
|
140
|
+
'allow',
|
|
141
|
+
'allowfullscreen',
|
|
142
|
+
'referrerpolicy',
|
|
138
143
|
];
|
|
139
144
|
|
|
140
145
|
const marginLength = '(-?\\d+(\\.\\d+)?(px|em|rem|%)?|auto)';
|
|
@@ -146,6 +151,7 @@ const editorClasses = new Set([
|
|
|
146
151
|
'blog-code-block',
|
|
147
152
|
'blog-post-editor-image',
|
|
148
153
|
'blog-post-editor-video',
|
|
154
|
+
'blog-post-editor-youtube',
|
|
149
155
|
]);
|
|
150
156
|
|
|
151
157
|
// The editor's named text and background colors.
|
|
@@ -193,6 +199,53 @@ const editorArticlePath =
|
|
|
193
199
|
|
|
194
200
|
const authorRelTokens = new Set(['nofollow', 'sponsored', 'ugc']);
|
|
195
201
|
|
|
202
|
+
// A YouTube player the editor inserts: youtube.com or youtube-nocookie.com,
|
|
203
|
+
// /embed/ and an 11-character video ID, optionally a start second.
|
|
204
|
+
const youtubeEmbed =
|
|
205
|
+
/^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/([\w-]{11})(?:\?([^#]*))?$/i;
|
|
206
|
+
|
|
207
|
+
export const blogYoutubeAllow =
|
|
208
|
+
'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The privacy-enhanced player address for a YouTube embed address, or an
|
|
212
|
+
* empty string for anything else (other sites, other YouTube pages).
|
|
213
|
+
*/
|
|
214
|
+
export function blogYoutubeEmbedSource(value: string) {
|
|
215
|
+
const match = youtubeEmbed.exec(value.trim());
|
|
216
|
+
|
|
217
|
+
if (!match) {
|
|
218
|
+
return '';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const start = /(?:^|&)start=(\d{1,6})(?:&|$)/.exec(match[2] ?? '')?.[1];
|
|
222
|
+
|
|
223
|
+
return `https://www.youtube-nocookie.com/embed/${match[1]}${start && Number(start) > 0 ? `?start=${Number(start)}` : ''}`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function prepareYoutubeFrame(node: Element) {
|
|
227
|
+
const source = blogYoutubeEmbedSource(node.getAttribute('src') ?? '');
|
|
228
|
+
|
|
229
|
+
if (!source) {
|
|
230
|
+
node.remove();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const title = node.getAttribute('title')?.trim() || 'YouTube video';
|
|
235
|
+
|
|
236
|
+
for (const attribute of [...node.getAttributeNames()]) {
|
|
237
|
+
node.removeAttribute(attribute);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
node.setAttribute('class', 'blog-post-editor-youtube');
|
|
241
|
+
node.setAttribute('src', source);
|
|
242
|
+
node.setAttribute('title', title);
|
|
243
|
+
node.setAttribute('allow', blogYoutubeAllow);
|
|
244
|
+
node.setAttribute('allowfullscreen', '');
|
|
245
|
+
node.setAttribute('loading', 'lazy');
|
|
246
|
+
node.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
247
|
+
}
|
|
248
|
+
|
|
196
249
|
function normalizedHeadingText(value: string) {
|
|
197
250
|
return htmlTextParagraphs(value)
|
|
198
251
|
.join(' ')
|
|
@@ -314,6 +367,11 @@ function prepareLink(link: Element) {
|
|
|
314
367
|
function prepareElement(node: Element) {
|
|
315
368
|
const name = node.nodeName;
|
|
316
369
|
|
|
370
|
+
if (name === 'IFRAME') {
|
|
371
|
+
prepareYoutubeFrame(node);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
317
375
|
if (name === 'A') {
|
|
318
376
|
prepareLink(node);
|
|
319
377
|
}
|