basklee-nuxt 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basklee-nuxt",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "Nuxt 4 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",
@@ -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
  }
@@ -556,6 +556,9 @@ location / {
556
556
 
557
557
  Here localhost is your frontend process on your VPS. That process selects the
558
558
  remote personal API from the domain file. The proxy must overwrite those headers.
559
+ Behind Cloudflare, \`$remote_addr\` is a Cloudflare address: the storefront
560
+ notices it and sends the customer's own address from \`CF-Connecting-IP\`
561
+ instead, with nothing to set up.
559
562
  An unknown domain never falls back to another tenant. \`/robots.txt\` points
560
563
  crawlers to \`/sitemap.xml\`, which lists the public pages, categories, products
561
564
  on sale and journal publications in every storefront language (each publication
@@ -8,7 +8,7 @@ The supplied storefront uses this component at `/journal`.
8
8
 
9
9
  ## Contract and dependencies
10
10
 
11
- The supplied `app/pages/journal/[id].vue` loads the article during the server render with `blog_posts_get` and `filters.id = postId`, using the visitor's cookies, and passes it in `initialPost`; the browser shows it without another request. Without `initialPost` (after client-side navigation) the component sends the same request itself. Full text appears only when both `is_full` and `has_full_access` are true; otherwise the preview and the access panel remain. Article HTML is sanitized with DOMPurify in `app/utils/basklee/blogArticleHtml.ts` and keeps what the marketplace blog editor writes: headings, paragraphs and line breaks, bold, italic, underline, strikethrough, subscript and superscript, links, bullet, numbered and task lists, quotes, dividers, inline code and code blocks, tables with merged cells, images and galleries, video and audio with controls, collapsible sections, alignment, text color, highlight, font and size. External links open in a new tab with `rel="noopener noreferrer"`; editor links to other articles open `/journal/<id>`. Formulas are shown as their LaTeX source. Wide tables and code blocks scroll inside the article, and floated images stack on narrow screens. 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 `app/utils/basklee/blogProductPlacements.ts`. Frames, scripts, forms, event attributes and other styles are removed. The server render shows the text as plain paragraphs, which search engines can read; the formatted HTML replaces them in the browser.
11
+ The supplied `app/pages/journal/[id].vue` loads the article during the server render with `blog_posts_get` and `filters.id = postId`, using the visitor's cookies, and passes it in `initialPost`; the browser shows it without another request. Without `initialPost` (after client-side navigation) the component sends the same request itself. Full text appears only when both `is_full` and `has_full_access` are true; otherwise the preview and the access panel remain. Article HTML is sanitized with DOMPurify in `app/utils/basklee/blogArticleHtml.ts` and keeps what the marketplace blog editor writes: headings, paragraphs and line breaks, bold, italic, underline, strikethrough, subscript and superscript, links, bullet, numbered and task lists, quotes, dividers, inline code and code blocks, tables with merged cells, images and galleries, video and audio with controls, YouTube players, collapsible sections, alignment, text color, highlight, font and size. External links open in a new tab with `rel="noopener noreferrer"`; editor links to other articles open `/journal/<id>`. Formulas are shown as their LaTeX source. Wide tables and code blocks scroll inside the article, and floated images stack on narrow screens. 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 `app/utils/basklee/blogProductPlacements.ts`. A YouTube player the editor inserts is an `<iframe>` with a `youtube.com` or `youtube-nocookie.com` `/embed/<id>` address: it is kept, 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, event attributes and other styles are removed. The server render shows the text as plain paragraphs, which search engines can read; the formatted HTML replaces them in the browser.
12
12
 
13
13
  Reading accounting for an accessible paid article starts after interaction with its visible text. `blog_reading_start` starts a session; `blog_reading_heartbeat` follows the returned interval. Leaving, losing focus, hiding the text or 60 seconds without interaction stops requests. Resuming and delayed timers start a fresh baseline. Confirmed loss of access removes full text and offers a refresh.
14
14
 
@@ -880,6 +880,18 @@
880
880
  width: 100%;
881
881
  }
882
882
 
883
+ /* A YouTube player from the editor: the article's width, 16:9. */
884
+ .op-feature-prose :deep(iframe.blog-post-editor-youtube:where(:not([data-product-id] *, [data-product-ids] *))) {
885
+ display: block;
886
+ width: 100%;
887
+ height: auto;
888
+ margin: 1.5rem 0;
889
+ clear: both;
890
+ aspect-ratio: 16 / 9;
891
+ border: 0;
892
+ background: #000;
893
+ }
894
+
883
895
  .op-feature-prose :deep(figcaption:where(:not([data-product-id] *, [data-product-ids] *))) {
884
896
  margin-top: 0.5rem;
885
897
  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
- * The editor has no embedded frames, so iframes stay forbidden.
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 = [
@@ -31,6 +32,7 @@ export const blogArticleTags = [
31
32
  'img', 'figure', 'figcaption',
32
33
  'video', 'audio', 'source', 'track',
33
34
  'details', 'summary',
35
+ 'iframe',
34
36
  ];
35
37
 
36
38
  const attributes = [
@@ -46,6 +48,7 @@ const attributes = [
46
48
  'data-code-scheme', 'data-gallery-width', 'data-list-offset',
47
49
  'data-float', 'data-blog-video', 'data-details-content',
48
50
  'data-product-id', 'data-product-ids', 'data-product-hidden-badges',
51
+ 'allow', 'allowfullscreen', 'referrerpolicy',
49
52
  ];
50
53
 
51
54
  const marginLength = '(-?\\d+(\\.\\d+)?(px|em|rem|%)?|auto)';
@@ -57,6 +60,7 @@ const editorClasses = new Set([
57
60
  'blog-code-block',
58
61
  'blog-post-editor-image',
59
62
  'blog-post-editor-video',
63
+ 'blog-post-editor-youtube',
60
64
  ]);
61
65
 
62
66
  // The editor's named text and background colors.
@@ -104,6 +108,53 @@ const editorArticlePath =
104
108
 
105
109
  const authorRelTokens = new Set(['nofollow', 'sponsored', 'ugc']);
106
110
 
111
+ // A YouTube player the editor inserts: youtube.com or youtube-nocookie.com,
112
+ // /embed/ and an 11-character video ID, optionally a start second.
113
+ const youtubeEmbed =
114
+ /^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/([\w-]{11})(?:\?([^#]*))?$/i;
115
+
116
+ export const blogYoutubeAllow =
117
+ 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
118
+
119
+ /**
120
+ * The privacy-enhanced player address for a YouTube embed address, or an
121
+ * empty string for anything else (other sites, other YouTube pages).
122
+ */
123
+ export function blogYoutubeEmbedSource(value: string) {
124
+ const match = youtubeEmbed.exec(value.trim());
125
+
126
+ if (!match) {
127
+ return '';
128
+ }
129
+
130
+ const start = /(?:^|&)start=(\d{1,6})(?:&|$)/.exec(match[2] ?? '')?.[1];
131
+
132
+ return `https://www.youtube-nocookie.com/embed/${match[1]}${start && Number(start) > 0 ? `?start=${Number(start)}` : ''}`;
133
+ }
134
+
135
+ function prepareYoutubeFrame(node: Element) {
136
+ const source = blogYoutubeEmbedSource(node.getAttribute('src') ?? '');
137
+
138
+ if (!source) {
139
+ node.remove();
140
+ return;
141
+ }
142
+
143
+ const title = node.getAttribute('title')?.trim() || 'YouTube video';
144
+
145
+ for (const attribute of [...node.getAttributeNames()]) {
146
+ node.removeAttribute(attribute);
147
+ }
148
+
149
+ node.setAttribute('class', 'blog-post-editor-youtube');
150
+ node.setAttribute('src', source);
151
+ node.setAttribute('title', title);
152
+ node.setAttribute('allow', blogYoutubeAllow);
153
+ node.setAttribute('allowfullscreen', '');
154
+ node.setAttribute('loading', 'lazy');
155
+ node.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
156
+ }
157
+
107
158
  function normalizedHeadingText(value: string) {
108
159
  return htmlTextParagraphs(value)
109
160
  .join(' ')
@@ -230,6 +281,11 @@ let mediaOrigin = '';
230
281
  function prepareElement(node: Element) {
231
282
  const name = node.nodeName;
232
283
 
284
+ if (name === 'IFRAME') {
285
+ prepareYoutubeFrame(node);
286
+ return;
287
+ }
288
+
233
289
  if (name === 'A') {
234
290
  prepareLink(node);
235
291
  }