@towa-digital/storyblok-nuxt-cv 0.1.4 → 0.3.0

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/README.md CHANGED
@@ -69,11 +69,12 @@ Then create a **story publish webhook** in Storyblok
69
69
  export default defineNuxtConfig({
70
70
  storyblokCv: {
71
71
  token: undefined, // default: auto-detected from @storyblok/nuxt config; env NUXT_STORYBLOK_CV_TOKEN
72
- region: 'eu', // eu | us | ap | ca | cn — or apiHost: 'https://...'
72
+ region: 'eu', // eu | us | ap | ca | cn
73
+ endpoint: undefined, // full API endpoint incl. /v2 (like @storyblok/nuxt); overrides region — for proxied spaces
73
74
  storage: 'storyblok-cv', // nitro storage mount name
74
- endpoint: '/api/storyblok-cv', // GET current cv; false to disable
75
+ statusRoute: '/api/storyblok-cv', // GET current cv; false to disable
75
76
  webhook: true, // built-in route /api/storyblok-cv-webhook; string = custom route; false = use refreshStoryblokCv() yourself
76
- ttl: false, // e.g. 60_000 — background refresh when the stored cv is older (serverless/multi-instance)
77
+ ttl: false, // seconds, e.g. 60 — background refresh when the stored cv is older (serverless/multi-instance)
77
78
  onStartup: true, // populate the store once at boot
78
79
  },
79
80
  })
@@ -86,7 +87,7 @@ export default defineNuxtConfig({
86
87
  | Single Node process (DO app platform, plain node-server) | default (memory) | webhook (default setup) |
87
88
  | PM2 **cluster** on one host (`instances: 'max'`) | mount `fs` driver (shared disk) | webhook |
88
89
  | Multi-node / containers | mount Redis | webhook |
89
- | Cloudflare / Vercel Edge / Netlify (isolates) | default | **`ttl` (e.g. 60_000)** — a webhook can't reach every isolate |
90
+ | Cloudflare / Vercel Edge / Netlify (isolates) | default | **`ttl` (seconds, e.g. `60`)** — a webhook can't reach every isolate |
90
91
 
91
92
  ```ts
92
93
  // PM2 cluster example — the memory default is per worker, the webhook would
package/dist/module.d.mts CHANGED
@@ -11,18 +11,24 @@ interface ModuleOptions {
11
11
  * Overridable at runtime via `NUXT_STORYBLOK_CV_TOKEN`.
12
12
  */
13
13
  token?: string;
14
- /** Storyblok API region. Ignored when `apiHost` is set. */
14
+ /** Storyblok API region. Ignored when `endpoint` is set. */
15
15
  region?: 'eu' | 'us' | 'ap' | 'ca' | 'cn';
16
- /** Full API host override, e.g. for proxies. */
17
- apiHost?: string;
16
+ /**
17
+ * Full Storyblok API endpoint **including the version segment**, exactly as
18
+ * `@storyblok/nuxt` / storyblok-js-client expect it (e.g.
19
+ * `https://api.storyblok.com/v2`). Set this for proxied spaces — pass the
20
+ * same value as the render client's `apiOptions.endpoint`, no surgery. When
21
+ * unset, derived from `region`.
22
+ */
23
+ endpoint?: string;
18
24
  /**
19
25
  * Nitro storage mount the `cv` is stored under. The default (unmounted) is
20
26
  * per-process memory — fine for a single Node process. For PM2 cluster mount
21
27
  * an `fs` driver, for multi-node mount Redis, in the host's `nitro.storage`.
22
28
  */
23
29
  storage?: string;
24
- /** GET endpoint exposing the current `cv` (client re-pins, debugging). `false` disables. */
25
- endpoint?: string | false;
30
+ /** GET route exposing the current `cv` (client re-pins, debugging). `false` disables. */
31
+ statusRoute?: string | false;
26
32
  /**
27
33
  * Built-in Storyblok publish webhook. `true` registers it at
28
34
  * `/api/storyblok-cv-webhook`, a string sets the route, `false` disables it —
@@ -31,10 +37,11 @@ interface ModuleOptions {
31
37
  */
32
38
  webhook?: boolean | string;
33
39
  /**
34
- * Max age (ms) of the stored `cv` before a page render triggers a background
35
- * refresh. Required on serverless/edge targets (Cloudflare, Vercel, Netlify)
36
- * and multi-instance setups without shared storage, where a webhook cannot
37
- * reach every isolate. `false` disables (webhook/startup only).
40
+ * Max age of the stored `cv`, **in seconds**, before a page render triggers a
41
+ * background refresh (e.g. `60` = one minute). Required on serverless/edge
42
+ * targets (Cloudflare, Vercel, Netlify) and multi-instance setups without
43
+ * shared storage, where a webhook cannot reach every isolate. `false`
44
+ * disables (webhook/startup only).
38
45
  */
39
46
  ttl?: number | false;
40
47
  /** Populate the `cv` store once at boot (fire-and-forget). */
@@ -46,7 +53,7 @@ declare module '@nuxt/schema' {
46
53
  interface RuntimeConfig {
47
54
  storyblokCv: {
48
55
  token: string;
49
- apiHost: string;
56
+ endpoint: string;
50
57
  storage: string;
51
58
  ttl: number;
52
59
  onStartup: boolean;
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.10.0"
6
6
  },
7
- "version": "0.1.4",
7
+ "version": "0.3.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { defineNuxtModule, createResolver, useLogger, addServerHandler, addServerPlugin, addServerImports, addPlugin, addTypeTemplate } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
3
 
4
- const API_HOSTS = {
5
- eu: "https://api.storyblok.com",
6
- us: "https://api-us.storyblok.com",
7
- ap: "https://api-ap.storyblok.com",
8
- ca: "https://api-ca.storyblok.com",
9
- cn: "https://api.storyblokchina.cn"
4
+ const API_ENDPOINTS = {
5
+ eu: "https://api.storyblok.com/v2",
6
+ us: "https://api-us.storyblok.com/v2",
7
+ ap: "https://api-ap.storyblok.com/v2",
8
+ ca: "https://api-ca.storyblok.com/v2",
9
+ cn: "https://api.storyblokchina.cn/v2"
10
10
  };
11
11
  const module$1 = defineNuxtModule({
12
12
  meta: {
@@ -19,7 +19,7 @@ const module$1 = defineNuxtModule({
19
19
  debug: false,
20
20
  region: "eu",
21
21
  storage: "storyblok-cv",
22
- endpoint: "/api/storyblok-cv",
22
+ statusRoute: "/api/storyblok-cv",
23
23
  webhook: true,
24
24
  ttl: false,
25
25
  onStartup: true
@@ -42,9 +42,11 @@ const module$1 = defineNuxtModule({
42
42
  nuxt.options.runtimeConfig.storyblokCv,
43
43
  {
44
44
  token: token ?? "",
45
- apiHost: options.apiHost || API_HOSTS[options.region] || API_HOSTS.eu,
45
+ endpoint: options.endpoint || API_ENDPOINTS[options.region] || API_ENDPOINTS.eu,
46
46
  storage: options.storage,
47
- ttl: options.ttl === false ? 0 : options.ttl ?? 0,
47
+ // Option is in seconds (nicer DX); convert to ms for the runtime, which
48
+ // compares against `Date.now()`.
49
+ ttl: options.ttl === false ? 0 : (options.ttl ?? 0) * 1e3,
48
50
  onStartup: options.onStartup !== false,
49
51
  webhookSecret: ""
50
52
  }
@@ -53,9 +55,9 @@ const module$1 = defineNuxtModule({
53
55
  middleware: true,
54
56
  handler: resolver.resolve("./runtime/server/middleware/cv")
55
57
  });
56
- if (options.endpoint) {
58
+ if (options.statusRoute) {
57
59
  addServerHandler({
58
- route: options.endpoint,
60
+ route: options.statusRoute,
59
61
  method: "get",
60
62
  handler: resolver.resolve("./runtime/server/api/cv.get")
61
63
  });
@@ -3,12 +3,12 @@ import { useRuntimeConfig, useStorage } from "#imports";
3
3
  const KEY = "current";
4
4
  const store = () => useStorage(useRuntimeConfig().storyblokCv.storage);
5
5
  export async function getLiveStoryblokCv() {
6
- const { token, apiHost } = useRuntimeConfig().storyblokCv;
6
+ const { token, endpoint } = useRuntimeConfig().storyblokCv;
7
7
  if (!token) {
8
8
  throw new Error("[storyblok-cv] no access token configured");
9
9
  }
10
- const response = await $fetch("/v2/cdn/spaces/me", {
11
- baseURL: apiHost,
10
+ const response = await $fetch("cdn/spaces/me", {
11
+ baseURL: endpoint,
12
12
  query: { token }
13
13
  });
14
14
  return response?.space?.version ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@towa-digital/storyblok-nuxt-cv",
3
- "version": "0.1.4",
3
+ "version": "0.3.0",
4
4
  "description": "Keeps Storyblok published content fresh on long-running Nuxt servers by bridging the live cache version (cv) to the render client — no redeploy after publish.",
5
5
  "repository": "github:towa-digital/storyblok-nuxt-cv",
6
6
  "author": {