@tomako/tools-runtime 0.1.7 → 0.1.8

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": "@tomako/tools-runtime",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Shared interactive tools runtime for Tomako-FE workspace dialogs and Tomako-SEO tool pages",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,36 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+
4
+ import { staticAsset } from "./static-asset.ts";
5
+
6
+ function withStaticOrigin(value: string | undefined, run: () => void) {
7
+ const previous = process.env.NEXT_PUBLIC_STATIC_ORIGIN;
8
+ if (value === undefined) delete process.env.NEXT_PUBLIC_STATIC_ORIGIN;
9
+ else process.env.NEXT_PUBLIC_STATIC_ORIGIN = value;
10
+ try {
11
+ run();
12
+ } finally {
13
+ if (previous === undefined) delete process.env.NEXT_PUBLIC_STATIC_ORIGIN;
14
+ else process.env.NEXT_PUBLIC_STATIC_ORIGIN = previous;
15
+ }
16
+ }
17
+
18
+ describe("staticAsset", () => {
19
+ it("keeps public assets same-origin until a CDN origin is explicitly configured", () => {
20
+ withStaticOrigin(undefined, () => {
21
+ assert.equal(
22
+ staticAsset("/tools/mrr-calculator-section-primary-8bit.webp"),
23
+ "/tools/mrr-calculator-section-primary-8bit.webp",
24
+ );
25
+ });
26
+ });
27
+
28
+ it("uses the configured CDN origin when it is available", () => {
29
+ withStaticOrigin("https://static.tomako.ai/", () => {
30
+ assert.equal(
31
+ staticAsset("/tools/mrr-calculator-section-primary-8bit.webp"),
32
+ "https://static.tomako.ai/static/tools/mrr-calculator-section-primary-8bit.webp",
33
+ );
34
+ });
35
+ });
36
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Resolve root-relative marketing asset paths to the static CDN.
2
+ * Resolve root-relative marketing asset paths to an explicitly configured static CDN.
3
3
  * Mirrors `@tomako/public-chrome` staticAsset so tools-runtime stays free of
4
4
  * a chrome peer dependency.
5
5
  *
@@ -10,8 +10,6 @@
10
10
  const STYLE_SUFFIX_PATTERN = /!(default|256|640|960|1600|2560)$/;
11
11
  const RASTER_EXT = /\.(png|jpe?g|webp|gif|bmp|tiff?)$/i;
12
12
 
13
- export const DEFAULT_STATIC_ORIGIN = "https://static.tomako.ai";
14
-
15
13
  export type OssImageStyle =
16
14
  | "default"
17
15
  | "256"
@@ -20,13 +18,9 @@ export type OssImageStyle =
20
18
  | "1600"
21
19
  | "2560";
22
20
 
23
- function readStaticOrigin(): string {
24
- const raw = process.env.NEXT_PUBLIC_STATIC_ORIGIN;
25
- if (raw !== undefined) {
26
- const value = raw.trim().replace(/\/$/, "");
27
- if (value.length > 0) return value;
28
- }
29
- return DEFAULT_STATIC_ORIGIN;
21
+ function readStaticOrigin(): string | undefined {
22
+ const value = process.env.NEXT_PUBLIC_STATIC_ORIGIN?.trim().replace(/\/$/, "");
23
+ return value || undefined;
30
24
  }
31
25
 
32
26
  export function staticAsset(path: string, style?: OssImageStyle): string {
@@ -39,6 +33,9 @@ export function staticAsset(path: string, style?: OssImageStyle): string {
39
33
 
40
34
  const normalized = path.startsWith("/") ? path : `/${path}`;
41
35
  const origin = readStaticOrigin();
36
+ // A deployed page always has the corresponding public/ asset. CDN is an
37
+ // optional performance layer, never the only way to render a tool visual.
38
+ if (!origin) return normalized;
42
39
  const absolute = `${origin}/static${normalized}`;
43
40
  if (!style || !RASTER_EXT.test(normalized.replace(STYLE_SUFFIX_PATTERN, ""))) {
44
41
  return absolute;