@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 +5 -4
- package/dist/module.d.mts +17 -10
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -11
- package/dist/runtime/server/utils/cv.js +3 -3
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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 `
|
|
14
|
+
/** Storyblok API region. Ignored when `endpoint` is set. */
|
|
15
15
|
region?: 'eu' | 'us' | 'ap' | 'ca' | 'cn';
|
|
16
|
-
/**
|
|
17
|
-
|
|
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
|
|
25
|
-
|
|
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
|
|
35
|
-
* refresh. Required on serverless/edge
|
|
36
|
-
* and multi-instance setups without
|
|
37
|
-
* reach every isolate. `false`
|
|
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
|
-
|
|
56
|
+
endpoint: string;
|
|
50
57
|
storage: string;
|
|
51
58
|
ttl: number;
|
|
52
59
|
onStartup: boolean;
|
package/dist/module.json
CHANGED
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
|
|
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
|
-
|
|
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
|
-
|
|
45
|
+
endpoint: options.endpoint || API_ENDPOINTS[options.region] || API_ENDPOINTS.eu,
|
|
46
46
|
storage: options.storage,
|
|
47
|
-
|
|
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.
|
|
58
|
+
if (options.statusRoute) {
|
|
57
59
|
addServerHandler({
|
|
58
|
-
route: options.
|
|
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,
|
|
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("
|
|
11
|
-
baseURL:
|
|
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.
|
|
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": {
|