@vard-app/sdk 0.1.0 → 0.1.2
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 +30 -26
- package/dist/index.d.mts +30 -4
- package/dist/index.d.ts +30 -4
- package/dist/index.js +120 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -10
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +13 -19
- package/dist/next.d.ts +13 -19
- package/dist/next.js +185 -16
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +183 -17
- package/dist/next.mjs.map +1 -1
- package/dist/{types-DLM7i_Qr.d.mts → types-eJuYa65b.d.mts} +33 -2
- package/dist/{types-DLM7i_Qr.d.ts → types-eJuYa65b.d.ts} +33 -2
- package/package.json +1 -1
package/dist/next.mjs
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
function
|
|
1
|
+
// src/fetch-store.ts
|
|
2
|
+
function createVardFetchStore(options = {}) {
|
|
3
3
|
const {
|
|
4
4
|
apiBase = "https://api.vard.app",
|
|
5
|
-
workspaceId = process.env.VARD_WORKSPACE_ID,
|
|
6
|
-
apiKey = process.env.VARD_API_KEY,
|
|
7
|
-
|
|
8
|
-
revalidate = 60
|
|
5
|
+
workspaceId = options.workspaceId ?? process.env.VARD_WORKSPACE_ID,
|
|
6
|
+
apiKey = options.apiKey ?? process.env.VARD_API_KEY,
|
|
7
|
+
fetchOptions = {}
|
|
9
8
|
} = options;
|
|
10
9
|
let resolvedValues = null;
|
|
11
10
|
let fetchPromise = null;
|
|
12
11
|
async function fetchValues() {
|
|
12
|
+
const isDevelopment = process.env.NODE_ENV === "development";
|
|
13
13
|
if (!apiKey && !workspaceId) {
|
|
14
|
+
if (!isDevelopment) {
|
|
15
|
+
console.error(
|
|
16
|
+
"\x1B[31m[vard] Missing configuration! VARD_API_KEY is not set.\x1B[0m\nPlease set this environment variable in your production environment."
|
|
17
|
+
);
|
|
18
|
+
} else {
|
|
19
|
+
console.warn(
|
|
20
|
+
"[vard] No API Key found. Running in local fallback mode (using default values)."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
14
23
|
return /* @__PURE__ */ new Map();
|
|
15
24
|
}
|
|
16
25
|
const url = apiKey ? `${apiBase}/api/content/variables` : `${apiBase}/v1/workspaces/${workspaceId}/variables`;
|
|
17
26
|
try {
|
|
18
27
|
const res = await fetch(url, {
|
|
19
|
-
|
|
28
|
+
...fetchOptions,
|
|
20
29
|
headers: {
|
|
30
|
+
...fetchOptions.headers,
|
|
21
31
|
...apiKey ? { "X-Vard-API-Key": apiKey } : {}
|
|
22
|
-
}
|
|
23
|
-
// Next.js specific: revalidation hint
|
|
24
|
-
...revalidate !== void 0 && cache === "force-cache" ? { next: { revalidate } } : {}
|
|
32
|
+
}
|
|
25
33
|
});
|
|
26
34
|
if (!res.ok) {
|
|
27
|
-
console.warn(
|
|
28
|
-
`[vard] Failed to fetch variables: ${res.status}`
|
|
29
|
-
);
|
|
35
|
+
console.warn(`[vard] Failed to fetch variables: ${res.status}`);
|
|
30
36
|
return /* @__PURE__ */ new Map();
|
|
31
37
|
}
|
|
32
38
|
const data = await res.json();
|
|
@@ -40,8 +46,6 @@ function createVardNextAdapter(options = {}) {
|
|
|
40
46
|
get(key) {
|
|
41
47
|
return resolvedValues?.get(key);
|
|
42
48
|
},
|
|
43
|
-
// Extended method — not on base VardStore interface, but available
|
|
44
|
-
// for Next.js users who import from @vard/sdk/next
|
|
45
49
|
async prefetch() {
|
|
46
50
|
if (resolvedValues) return;
|
|
47
51
|
if (!fetchPromise) {
|
|
@@ -51,10 +55,172 @@ function createVardNextAdapter(options = {}) {
|
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
|
|
59
|
+
// src/client.ts
|
|
60
|
+
var hasLoggedNoop = false;
|
|
61
|
+
var noopStore = {
|
|
62
|
+
get: () => {
|
|
63
|
+
if (!hasLoggedNoop && process.env.NODE_ENV !== "test") {
|
|
64
|
+
console.warn(
|
|
65
|
+
"[vard] Using default values for all variables because no Store was provided to createVard()."
|
|
66
|
+
);
|
|
67
|
+
hasLoggedNoop = true;
|
|
68
|
+
}
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function createVard(options = {}) {
|
|
73
|
+
const store = options.store ?? (options.apiKey || options.workspaceId ? createVardFetchStore(options) : noopStore);
|
|
74
|
+
const registry = [];
|
|
75
|
+
function register(def) {
|
|
76
|
+
if (!registry.find((d) => d.key === def.key)) {
|
|
77
|
+
registry.push(def);
|
|
78
|
+
}
|
|
79
|
+
const stored = store.get(def.key);
|
|
80
|
+
if (stored !== void 0 && stored !== null) {
|
|
81
|
+
return stored;
|
|
82
|
+
}
|
|
83
|
+
return def.defaultValue;
|
|
84
|
+
}
|
|
85
|
+
const client = {
|
|
86
|
+
string(key, fallback, opts = {}) {
|
|
87
|
+
return register({
|
|
88
|
+
key,
|
|
89
|
+
label: opts.label ?? labelFromKey(key),
|
|
90
|
+
description: opts.description,
|
|
91
|
+
type: "string",
|
|
92
|
+
defaultValue: fallback,
|
|
93
|
+
editableBy: opts.editableBy ?? "member",
|
|
94
|
+
group: opts.group
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
richtext(key, fallback, opts = {}) {
|
|
98
|
+
return register({
|
|
99
|
+
key,
|
|
100
|
+
label: opts.label ?? labelFromKey(key),
|
|
101
|
+
description: opts.description,
|
|
102
|
+
type: "richtext",
|
|
103
|
+
defaultValue: fallback,
|
|
104
|
+
editableBy: opts.editableBy ?? "member",
|
|
105
|
+
group: opts.group
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
color(key, fallback, opts = {}) {
|
|
109
|
+
return register({
|
|
110
|
+
key,
|
|
111
|
+
label: opts.label ?? labelFromKey(key),
|
|
112
|
+
description: opts.description,
|
|
113
|
+
type: "color",
|
|
114
|
+
defaultValue: fallback,
|
|
115
|
+
editableBy: opts.editableBy ?? "member",
|
|
116
|
+
group: opts.group
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
image(key, fallback, opts = {}) {
|
|
120
|
+
return register({
|
|
121
|
+
key,
|
|
122
|
+
label: opts.label ?? labelFromKey(key),
|
|
123
|
+
description: opts.description,
|
|
124
|
+
type: "image",
|
|
125
|
+
defaultValue: fallback,
|
|
126
|
+
editableBy: opts.editableBy ?? "member",
|
|
127
|
+
group: opts.group
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
boolean(key, fallback, opts = {}) {
|
|
131
|
+
return register({
|
|
132
|
+
key,
|
|
133
|
+
label: opts.label ?? labelFromKey(key),
|
|
134
|
+
description: opts.description,
|
|
135
|
+
type: "boolean",
|
|
136
|
+
defaultValue: fallback,
|
|
137
|
+
editableBy: opts.editableBy ?? "member",
|
|
138
|
+
group: opts.group
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
list(key, schema, fallback, opts = {}) {
|
|
142
|
+
return register({
|
|
143
|
+
key,
|
|
144
|
+
label: opts.label ?? labelFromKey(key),
|
|
145
|
+
description: opts.description,
|
|
146
|
+
type: "list",
|
|
147
|
+
defaultValue: fallback,
|
|
148
|
+
editableBy: opts.editableBy ?? "member",
|
|
149
|
+
listItemSchema: schema,
|
|
150
|
+
group: opts.group
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
collection(key, schema, fallback, opts = {}) {
|
|
154
|
+
return register({
|
|
155
|
+
key,
|
|
156
|
+
label: opts.label ?? labelFromKey(key),
|
|
157
|
+
description: opts.description,
|
|
158
|
+
type: "list",
|
|
159
|
+
defaultValue: fallback,
|
|
160
|
+
editableBy: opts.editableBy ?? "member",
|
|
161
|
+
listItemSchema: schema,
|
|
162
|
+
group: opts.group,
|
|
163
|
+
isCollection: true
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
global: {
|
|
167
|
+
string(key, fallback, opts = {}) {
|
|
168
|
+
return client.string(key, fallback, { ...opts, group: "Global" });
|
|
169
|
+
},
|
|
170
|
+
richtext(key, fallback, opts = {}) {
|
|
171
|
+
return client.richtext(key, fallback, { ...opts, group: "Global" });
|
|
172
|
+
},
|
|
173
|
+
color(key, fallback, opts = {}) {
|
|
174
|
+
return client.color(key, fallback, { ...opts, group: "Global" });
|
|
175
|
+
},
|
|
176
|
+
image(key, fallback, opts = {}) {
|
|
177
|
+
return client.image(key, fallback, { ...opts, group: "Global" });
|
|
178
|
+
},
|
|
179
|
+
boolean(key, fallback, opts = {}) {
|
|
180
|
+
return client.boolean(key, fallback, { ...opts, group: "Global" });
|
|
181
|
+
},
|
|
182
|
+
list(key, schema, fallback, opts = {}) {
|
|
183
|
+
return client.list(key, schema, fallback, { ...opts, group: "Global" });
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
getDefinitions() {
|
|
187
|
+
return [...registry];
|
|
188
|
+
},
|
|
189
|
+
store
|
|
190
|
+
};
|
|
191
|
+
return client;
|
|
192
|
+
}
|
|
193
|
+
function labelFromKey(key) {
|
|
194
|
+
const lastSegment = key.split(".").pop() ?? key;
|
|
195
|
+
return lastSegment.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase()).trim();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/next.ts
|
|
199
|
+
function createVardNextAdapter(options = {}) {
|
|
200
|
+
const { cache = "force-cache", revalidate = 60, ...rest } = options;
|
|
201
|
+
return createVardFetchStore({
|
|
202
|
+
...rest,
|
|
203
|
+
fetchOptions: {
|
|
204
|
+
cache,
|
|
205
|
+
...revalidate !== void 0 && cache === "force-cache" ? { next: { revalidate } } : {}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function createVardNext(options = {}) {
|
|
210
|
+
const adapter = createVardNextAdapter(options);
|
|
211
|
+
return createVard({
|
|
212
|
+
...options,
|
|
213
|
+
store: adapter
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async function prefetchVardValues(target) {
|
|
217
|
+
const adapter = target.prefetch ? target : target.store;
|
|
218
|
+
if (adapter && typeof adapter.prefetch === "function") {
|
|
219
|
+
await adapter.prefetch();
|
|
220
|
+
}
|
|
56
221
|
}
|
|
57
222
|
export {
|
|
223
|
+
createVardNext,
|
|
58
224
|
createVardNextAdapter,
|
|
59
225
|
prefetchVardValues
|
|
60
226
|
};
|
package/dist/next.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/next.ts"],"sourcesContent":["/**\n * @vard/sdk — Next.js adapter\n *\n * This module provides a VardStore implementation that reads variable values\n * from the Vard API at request time (App Router) or build time (static export).\n *\n * Usage in your Next.js site:\n *\n * // lib/vard.ts\n * import { createVardNextAdapter } from \"@vard/sdk/next\"\n * import { createVard } from \"@vard/sdk\"\n *\n * export const vard = createVard({\n * workspaceId: process.env.VARD_WORKSPACE_ID,\n * store: createVardNextAdapter(),\n * })\n *\n * The adapter fetches variable values from the Vard API:\n * GET https://api.vard.app/v1/workspaces/{workspaceId}/variables\n *\n * In local development (no VARD_WORKSPACE_ID set) it silently falls back\n * to default values so your site works without any Vard account.\n */\n\nimport type { VardStore } from \"./types\";\n\nexport interface VardNextAdapterOptions {\n /**\n * Base URL of the Vard API. Defaults to https://api.vard.app\n */\n apiBase?: string;\n\n /**\n * Workspace ID. Falls back to process.env.VARD_WORKSPACE_ID.\n */\n workspaceId?: string;\n\n /**\n * API Key for authentication. Falls back to process.env.VARD_API_KEY.\n */\n apiKey?: string;\n\n /**\n * Next.js fetch cache strategy. Defaults to \"force-cache\" (SSG-friendly).\n * Use \"no-store\" for fully dynamic pages.\n */\n cache?: RequestCache;\n\n /**\n * Next.js ISR revalidation interval in seconds.\n * Only applies when cache is \"force-cache\".\n */\n revalidate?: number;\n}\n\n/**\n * Creates a VardStore that fetches live variable values from the Vard API.\n * Designed for use inside Next.js App Router (server components, server actions).\n *\n * Values are fetched once per request and cached in a simple Map.\n * In local dev with no workspaceId, returns undefined for every key (defaults take over).\n */\nexport function createVardNextAdapter(\n options: VardNextAdapterOptions = {}\n): VardStore {\n const {\n apiBase = \"https://api.vard.app\",\n workspaceId = process.env.VARD_WORKSPACE_ID,\n apiKey = process.env.VARD_API_KEY,\n cache = \"force-cache\",\n revalidate = 60,\n } = options;\n\n // In-memory cache per module instance (one Node.js process = one workspace)\n let resolvedValues: Map<string, unknown> | null = null;\n let fetchPromise: Promise<Map<string, unknown>> | null = null;\n\n async function fetchValues(): Promise<Map<string, unknown>> {\n if (!apiKey && !workspaceId) {\n return new Map();\n }\n\n // New format uses API Key and points to a generic content endpoint\n // Old format uses workspaceId and points to a workspace-specific endpoint\n const url = apiKey \n ? `${apiBase}/api/content/variables`\n : `${apiBase}/v1/workspaces/${workspaceId}/variables`;\n\n try {\n const res = await fetch(url, {\n cache,\n headers: {\n ...(apiKey ? { \"X-Vard-API-Key\": apiKey } : {}),\n },\n // Next.js specific: revalidation hint\n ...(revalidate !== undefined && cache === \"force-cache\"\n ? { next: { revalidate } }\n : {}),\n });\n\n if (!res.ok) {\n console.warn(\n `[vard] Failed to fetch variables: ${res.status}`\n );\n return new Map();\n }\n\n const data = (await res.json()) as { key: string; value: unknown }[];\n return new Map(data.map((v) => [v.key, v.value]));\n } catch (err) {\n console.warn(\"[vard] Error fetching variable values:\", err);\n return new Map();\n }\n }\n\n return {\n get(key: string): unknown {\n // Synchronous path — values must have been pre-fetched.\n // In Next.js App Router, call vard.prefetch() in your layout/page\n // before rendering, or use the async helper below.\n return resolvedValues?.get(key);\n },\n\n // Extended method — not on base VardStore interface, but available\n // for Next.js users who import from @vard/sdk/next\n async prefetch(): Promise<void> {\n if (resolvedValues) return;\n if (!fetchPromise) {\n fetchPromise = fetchValues();\n }\n resolvedValues = await fetchPromise;\n },\n } as VardStore & { prefetch(): Promise<void> };\n}\n\n/**\n * A convenience wrapper that creates a Vard client pre-loaded with live values.\n * Call this once in your Next.js layout before rendering any server component\n * that uses vard variables.\n *\n * @example\n * // app/layout.tsx\n * import { prefetchVardValues } from \"@vard/sdk/next\"\n * import { vard } from \"@/lib/vard\"\n *\n * export default async function RootLayout({ children }) {\n * await prefetchVardValues(vard)\n * return <html>...</html>\n * }\n */\nexport async function prefetchVardValues(\n adapter: { prefetch(): Promise<void> }\n): Promise<void> {\n await adapter.prefetch();\n}\n"],"mappings":";AA8DO,SAAS,sBACd,UAAkC,CAAC,GACxB;AACX,QAAM;AAAA,IACJ,UAAU;AAAA,IACV,cAAc,QAAQ,IAAI;AAAA,IAC1B,SAAS,QAAQ,IAAI;AAAA,IACrB,QAAQ;AAAA,IACR,aAAa;AAAA,EACf,IAAI;AAGJ,MAAI,iBAA8C;AAClD,MAAI,eAAqD;AAEzD,iBAAe,cAA6C;AAC1D,QAAI,CAAC,UAAU,CAAC,aAAa;AAC3B,aAAO,oBAAI,IAAI;AAAA,IACjB;AAIA,UAAM,MAAM,SACR,GAAG,OAAO,2BACV,GAAG,OAAO,kBAAkB,WAAW;AAE3C,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,KAAK;AAAA,QAC3B;AAAA,QACA,SAAS;AAAA,UACP,GAAI,SAAS,EAAE,kBAAkB,OAAO,IAAI,CAAC;AAAA,QAC/C;AAAA;AAAA,QAEA,GAAI,eAAe,UAAa,UAAU,gBACtC,EAAE,MAAM,EAAE,WAAW,EAAE,IACvB,CAAC;AAAA,MACP,CAAC;AAED,UAAI,CAAC,IAAI,IAAI;AACX,gBAAQ;AAAA,UACN,qCAAqC,IAAI,MAAM;AAAA,QACjD;AACA,eAAO,oBAAI,IAAI;AAAA,MACjB;AAEA,YAAM,OAAQ,MAAM,IAAI,KAAK;AAC7B,aAAO,IAAI,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAAA,IAClD,SAAS,KAAK;AACZ,cAAQ,KAAK,0CAA0C,GAAG;AAC1D,aAAO,oBAAI,IAAI;AAAA,IACjB;AAAA,EACF;AAEA,SAAO;AAAA,IACL,IAAI,KAAsB;AAIxB,aAAO,gBAAgB,IAAI,GAAG;AAAA,IAChC;AAAA;AAAA;AAAA,IAIA,MAAM,WAA0B;AAC9B,UAAI,eAAgB;AACpB,UAAI,CAAC,cAAc;AACjB,uBAAe,YAAY;AAAA,MAC7B;AACA,uBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AACF;AAiBA,eAAsB,mBACpB,SACe;AACf,QAAM,QAAQ,SAAS;AACzB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/fetch-store.ts","../src/client.ts","../src/next.ts"],"sourcesContent":["import type { VardStore } from \"./types\";\n\nexport interface VardFetchStoreOptions {\n /**\n * Base URL of the Vard API. Defaults to https://api.vard.app\n */\n apiBase?: string;\n\n /**\n * Workspace ID (Legacy). Defaults to process.env.VARD_WORKSPACE_ID.\n */\n workspaceId?: string;\n\n /**\n * API Key for authentication. Defaults to process.env.VARD_API_KEY.\n */\n apiKey?: string;\n\n /**\n * Custom fetch options (headers, etc.)\n */\n fetchOptions?: RequestInit;\n}\n\n/**\n * Creates a universal VardStore that fetches variable values from the Vard API.\n * Works in any environment with a global `fetch` (Browsers, Node 18+, Bun, Deno).\n */\nexport function createVardFetchStore(\n options: VardFetchStoreOptions = {}\n): VardStore & { prefetch(): Promise<void> } {\n const {\n apiBase = \"https://api.vard.app\",\n workspaceId = options.workspaceId ?? process.env.VARD_WORKSPACE_ID,\n apiKey = options.apiKey ?? process.env.VARD_API_KEY,\n fetchOptions = {},\n } = options;\n\n let resolvedValues: Map<string, unknown> | null = null;\n let fetchPromise: Promise<Map<string, unknown>> | null = null;\n\n async function fetchValues(): Promise<Map<string, unknown>> {\n const isDevelopment = process.env.NODE_ENV === \"development\";\n\n if (!apiKey && !workspaceId) {\n if (!isDevelopment) {\n console.error(\n \"\\x1b[31m[vard] Missing configuration! VARD_API_KEY is not set.\\x1b[0m\\n\" +\n \"Please set this environment variable in your production environment.\"\n );\n } else {\n console.warn(\n \"[vard] No API Key found. Running in local fallback mode (using default values).\"\n );\n }\n return new Map();\n }\n\n const url = apiKey\n ? `${apiBase}/api/content/variables`\n : `${apiBase}/v1/workspaces/${workspaceId}/variables`;\n\n try {\n const res = await fetch(url, {\n ...fetchOptions,\n headers: {\n ...fetchOptions.headers,\n ...(apiKey ? { \"X-Vard-API-Key\": apiKey } : {}),\n },\n });\n\n if (!res.ok) {\n console.warn(`[vard] Failed to fetch variables: ${res.status}`);\n return new Map();\n }\n\n const data = (await res.json()) as { key: string; value: unknown }[];\n return new Map(data.map((v) => [v.key, v.value]));\n } catch (err) {\n console.warn(\"[vard] Error fetching variable values:\", err);\n return new Map();\n }\n }\n\n return {\n get(key: string): unknown {\n return resolvedValues?.get(key);\n },\n\n async prefetch(): Promise<void> {\n if (resolvedValues) return;\n if (!fetchPromise) {\n fetchPromise = fetchValues();\n }\n resolvedValues = await fetchPromise;\n },\n };\n}\n","import type {\n VardClient,\n VardOptions,\n VardStore,\n VardVariableDefinition,\n VardVariableOptions,\n VardListItemSchema,\n InferListItem,\n VardRole,\n} from \"./types\";\n\n// ─────────────────────────────────────────────\n// No-op store (used in local dev when no workspaceId is set)\n// ─────────────────────────────────────────────\n\nlet hasLoggedNoop = false;\nconst noopStore: VardStore = {\n get: () => {\n if (!hasLoggedNoop && process.env.NODE_ENV !== \"test\") {\n console.warn(\n \"[vard] Using default values for all variables because no Store was provided to createVard().\"\n );\n hasLoggedNoop = true;\n }\n return undefined;\n },\n};\n\n// ─────────────────────────────────────────────\n// createVard — the main SDK factory\n// ─────────────────────────────────────────────\n\nimport { createVardFetchStore } from \"./fetch-store\";\n\n/**\n * Creates a Vard client instance. Call this once at the top of your site\n * (e.g. in `lib/vard.ts`) and export the result.\n *\n * @example\n * // lib/vard.ts\n * import { createVard } from \"@vard/sdk\"\n * export const vard = createVard({ apiKey: \"...\" })\n *\n * // app/page.tsx\n * import { vard } from \"@/lib/vard\"\n * const title = vard.string(\"hero.title\", \"Hello, world\")\n */\nexport function createVard(options: VardOptions = {}): VardClient {\n const store: VardStore =\n options.store ??\n (options.apiKey || options.workspaceId ? createVardFetchStore(options) : noopStore);\n\n // Registry of all declared variables — used by CLI + build pipeline\n const registry: VardVariableDefinition[] = [];\n\n function register<T>(def: VardVariableDefinition<T>): T {\n // Avoid double-registering the same key (e.g. in hot-reload scenarios)\n if (!registry.find((d) => d.key === def.key)) {\n registry.push(def as VardVariableDefinition);\n }\n\n // Resolve value: stored client value takes precedence over the default\n const stored = store.get(def.key);\n if (stored !== undefined && stored !== null) {\n return stored as T;\n }\n\n return def.defaultValue;\n }\n\n const client: VardClient = {\n string(key, fallback, opts: VardVariableOptions = {}) {\n return register<string>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"string\",\n defaultValue: fallback,\n editableBy: opts.editableBy ?? \"member\",\n group: opts.group,\n });\n },\n\n richtext(key, fallback, opts: VardVariableOptions = {}) {\n return register<string>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"richtext\",\n defaultValue: fallback,\n editableBy: opts.editableBy ?? \"member\",\n group: opts.group,\n });\n },\n\n color(key, fallback, opts: VardVariableOptions = {}) {\n return register<string>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"color\",\n defaultValue: fallback,\n editableBy: opts.editableBy ?? \"member\",\n group: opts.group,\n });\n },\n\n image(key, fallback, opts: VardVariableOptions = {}) {\n return register<string>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"image\",\n defaultValue: fallback,\n editableBy: opts.editableBy ?? \"member\",\n group: opts.group,\n });\n },\n\n boolean(key, fallback, opts: VardVariableOptions = {}) {\n return register<boolean>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"boolean\",\n defaultValue: fallback,\n editableBy: (opts.editableBy as VardRole) ?? \"member\",\n group: opts.group,\n });\n },\n\n list<S extends VardListItemSchema>(\n key: string,\n schema: S,\n fallback: InferListItem<S>[],\n opts: VardVariableOptions = {}\n ): InferListItem<S>[] {\n return register<InferListItem<S>[]>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"list\",\n defaultValue: fallback,\n editableBy: (opts.editableBy as VardRole) ?? \"member\",\n listItemSchema: schema,\n group: opts.group,\n });\n },\n\n collection<S extends VardListItemSchema>(\n key: string,\n schema: S,\n fallback: InferListItem<S>[],\n opts: Omit<VardVariableOptions, \"type\"> = {}\n ): InferListItem<S>[] {\n return register<InferListItem<S>[]>({\n key,\n label: opts.label ?? labelFromKey(key),\n description: opts.description,\n type: \"list\",\n defaultValue: fallback,\n editableBy: (opts.editableBy as VardRole) ?? \"member\",\n listItemSchema: schema,\n group: opts.group,\n isCollection: true,\n });\n },\n\n global: {\n string(key, fallback, opts = {}) {\n return client.string(key, fallback, { ...opts, group: \"Global\" } as VardVariableOptions);\n },\n richtext(key, fallback, opts = {}) {\n return client.richtext(key, fallback, { ...opts, group: \"Global\" } as VardVariableOptions);\n },\n color(key, fallback, opts = {}) {\n return client.color(key, fallback, { ...opts, group: \"Global\" } as VardVariableOptions);\n },\n image(key, fallback, opts = {}) {\n return client.image(key, fallback, { ...opts, group: \"Global\" } as VardVariableOptions);\n },\n boolean(key, fallback, opts = {}) {\n return client.boolean(key, fallback, { ...opts, group: \"Global\" } as Omit<\n VardVariableOptions,\n \"type\"\n >);\n },\n list(key, schema, fallback, opts = {}) {\n return client.list(key, schema, fallback, { ...opts, group: \"Global\" } as Omit<\n VardVariableOptions,\n \"type\"\n >);\n },\n },\n\n getDefinitions() {\n return [...registry];\n },\n store,\n };\n\n return client;\n}\n\n// ─────────────────────────────────────────────\n// Helpers\n// ─────────────────────────────────────────────\n\n/**\n * Converts a dot-notation key to a human-readable label.\n * e.g. \"hero.primaryTitle\" → \"Hero Primary Title\"\n */\nfunction labelFromKey(key: string): string {\n const lastSegment = key.split(\".\").pop() ?? key;\n // Split on camelCase boundaries and capitalise\n return lastSegment\n .replace(/([A-Z])/g, \" $1\")\n .replace(/^./, (c) => c.toUpperCase())\n .trim();\n}\n","/**\n * @vard/sdk — Next.js adapter\n *\n * This module provides a VardStore implementation that reads variable values\n * from the Vard API at request time (App Router) or build time (static export).\n *\n * Usage in your Next.js site:\n *\n * // lib/vard.ts\n * import { createVardNextAdapter } from \"@vard/sdk/next\"\n * import { createVard } from \"@vard/sdk\"\n *\n * export const vard = createVard({\n * workspaceId: process.env.VARD_WORKSPACE_ID,\n * store: createVardNextAdapter(),\n * })\n *\n * The adapter fetches variable values from the Vard API:\n * GET https://api.vard.app/v1/workspaces/{workspaceId}/variables\n *\n * In local development (no VARD_WORKSPACE_ID set) it silently falls back\n * to default values so your site works without any Vard account.\n */\n\nimport type { VardStore } from \"./types\";\n\nexport interface VardNextAdapterOptions {\n /**\n * Base URL of the Vard API. Defaults to https://api.vard.app\n */\n apiBase?: string;\n\n /**\n * Workspace ID. Falls back to process.env.VARD_WORKSPACE_ID.\n */\n workspaceId?: string;\n\n /**\n * API Key for authentication. Falls back to process.env.VARD_API_KEY.\n */\n apiKey?: string;\n\n /**\n * Next.js fetch cache strategy. Defaults to \"force-cache\" (SSG-friendly).\n * Use \"no-store\" for fully dynamic pages.\n */\n cache?: RequestCache;\n\n /**\n * Next.js ISR revalidation interval in seconds.\n * Only applies when cache is \"force-cache\".\n */\n revalidate?: number;\n}\n\nimport { createVardFetchStore, VardFetchStoreOptions } from \"./fetch-store\";\n\n/**\n * Creates a VardStore that fetches live variable values from the Vard API.\n * Designed for use inside Next.js App Router (server components, server actions).\n */\nexport function createVardNextAdapter(\n options: VardNextAdapterOptions = {}\n): VardStore & { prefetch(): Promise<void> } {\n const { cache = \"force-cache\", revalidate = 60, ...rest } = options;\n\n return createVardFetchStore({\n ...rest,\n fetchOptions: {\n cache,\n ...(revalidate !== undefined && cache === \"force-cache\"\n ? ({ next: { revalidate } } as any)\n : {}),\n },\n });\n}\n\n/**\n * A convenience wrapper that creates a Vard client pre-loaded with live values.\n * Call this once in your Next.js layout before rendering any server component\n * that uses vard variables.\n *\n * @example\n * // app/layout.tsx\n * import { prefetchVardValues } from \"@vard/sdk/next\"\n * import { vard } from \"@/lib/vard\"\n *\n * export default async function RootLayout({ children }) {\n * await prefetchVardValues(vard)\n * return <html>...</html>\n * }\n */\nimport { createVard } from \"./client\";\nimport type { VardClient, VardOptions } from \"./types\";\n\n/**\n * A convenience wrapper for createVard that automatically uses the Next.js adapter.\n *\n * @example\n * // lib/vard.ts\n * import { createVardNext } from \"@vard/sdk/next\"\n * export const vard = createVardNext({ revalidate: 60 })\n */\nexport function createVardNext(options: VardNextAdapterOptions & VardOptions = {}): VardClient {\n const adapter = createVardNextAdapter(options);\n return createVard({\n ...options,\n store: adapter,\n });\n}\n\nexport async function prefetchVardValues(\n target: { prefetch(): Promise<void> } | VardClient\n): Promise<void> {\n const adapter = (target as any).prefetch ? target : (target as VardClient).store;\n if (adapter && typeof (adapter as any).prefetch === \"function\") {\n await (adapter as any).prefetch();\n }\n}\n"],"mappings":";AA4BO,SAAS,qBACd,UAAiC,CAAC,GACS;AAC3C,QAAM;AAAA,IACJ,UAAU;AAAA,IACV,cAAc,QAAQ,eAAe,QAAQ,IAAI;AAAA,IACjD,SAAS,QAAQ,UAAU,QAAQ,IAAI;AAAA,IACvC,eAAe,CAAC;AAAA,EAClB,IAAI;AAEJ,MAAI,iBAA8C;AAClD,MAAI,eAAqD;AAEzD,iBAAe,cAA6C;AAC1D,UAAM,gBAAgB,QAAQ,IAAI,aAAa;AAE/C,QAAI,CAAC,UAAU,CAAC,aAAa;AAC3B,UAAI,CAAC,eAAe;AAClB,gBAAQ;AAAA,UACN;AAAA,QAEF;AAAA,MACF,OAAO;AACL,gBAAQ;AAAA,UACN;AAAA,QACF;AAAA,MACF;AACA,aAAO,oBAAI,IAAI;AAAA,IACjB;AAEA,UAAM,MAAM,SACR,GAAG,OAAO,2BACV,GAAG,OAAO,kBAAkB,WAAW;AAE3C,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,KAAK;AAAA,QAC3B,GAAG;AAAA,QAC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O,QAAgB,SAAS;AAAA,EAClC;AACF;","names":[]}
|
|
@@ -18,6 +18,10 @@ interface VardVariableDefinition<T = unknown> {
|
|
|
18
18
|
description?: string;
|
|
19
19
|
/** For list variables — the schema of each item */
|
|
20
20
|
listItemSchema?: VardListItemSchema;
|
|
21
|
+
/** Optional grouping for the dashboard UI */
|
|
22
|
+
group?: string;
|
|
23
|
+
/** Indicates this is a reusable content pool/collection */
|
|
24
|
+
isCollection?: boolean;
|
|
21
25
|
}
|
|
22
26
|
interface VardStore {
|
|
23
27
|
/** Returns a stored value for the given key, or undefined if not set */
|
|
@@ -25,7 +29,12 @@ interface VardStore {
|
|
|
25
29
|
}
|
|
26
30
|
interface VardOptions {
|
|
27
31
|
/**
|
|
28
|
-
*
|
|
32
|
+
* API Key for authentication. Read from VARD_API_KEY env var if not provided.
|
|
33
|
+
* This is the preferred way to configure the SDK as it's tied to your workspace.
|
|
34
|
+
*/
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Workspace ID (Legacy). Required only if not using an API Key.
|
|
29
38
|
* Read from VARD_WORKSPACE_ID env var if not provided.
|
|
30
39
|
*/
|
|
31
40
|
workspaceId?: string;
|
|
@@ -37,6 +46,15 @@ interface VardOptions {
|
|
|
37
46
|
store?: VardStore;
|
|
38
47
|
}
|
|
39
48
|
interface VardClient {
|
|
49
|
+
/**
|
|
50
|
+
* Access to global (project-wide) variables.
|
|
51
|
+
* e.g., vard.global.string("contact.email", "...")
|
|
52
|
+
*/
|
|
53
|
+
global: VardGlobalClient;
|
|
54
|
+
/**
|
|
55
|
+
* Define a reusable content pool/collection.
|
|
56
|
+
*/
|
|
57
|
+
collection<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
|
|
40
58
|
/**
|
|
41
59
|
* A plain string variable. e.g. a hero headline, a CTA label.
|
|
42
60
|
*
|
|
@@ -72,11 +90,24 @@ interface VardClient {
|
|
|
72
90
|
* and the build pipeline to sync definitions to the Vard API.
|
|
73
91
|
*/
|
|
74
92
|
getDefinitions(): VardVariableDefinition[];
|
|
93
|
+
/**
|
|
94
|
+
* Access to the underlying store.
|
|
95
|
+
*/
|
|
96
|
+
readonly store: VardStore;
|
|
97
|
+
}
|
|
98
|
+
interface VardGlobalClient {
|
|
99
|
+
string(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
100
|
+
richtext(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
101
|
+
color(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
102
|
+
image(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
103
|
+
boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type" | "group">): boolean;
|
|
104
|
+
list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type" | "group">): InferListItem<S>[];
|
|
75
105
|
}
|
|
76
106
|
interface VardVariableOptions {
|
|
77
107
|
label?: string;
|
|
78
108
|
description?: string;
|
|
79
109
|
editableBy?: VardRole;
|
|
110
|
+
group?: string;
|
|
80
111
|
}
|
|
81
112
|
|
|
82
|
-
export type { InferListItem as I, VardOptions as V, VardClient as a,
|
|
113
|
+
export type { InferListItem as I, VardOptions as V, VardClient as a, VardStore as b, VardListItemSchema as c, VardRole as d, VardVariableDefinition as e, VardVariableOptions as f, VardVariableType as g };
|
|
@@ -18,6 +18,10 @@ interface VardVariableDefinition<T = unknown> {
|
|
|
18
18
|
description?: string;
|
|
19
19
|
/** For list variables — the schema of each item */
|
|
20
20
|
listItemSchema?: VardListItemSchema;
|
|
21
|
+
/** Optional grouping for the dashboard UI */
|
|
22
|
+
group?: string;
|
|
23
|
+
/** Indicates this is a reusable content pool/collection */
|
|
24
|
+
isCollection?: boolean;
|
|
21
25
|
}
|
|
22
26
|
interface VardStore {
|
|
23
27
|
/** Returns a stored value for the given key, or undefined if not set */
|
|
@@ -25,7 +29,12 @@ interface VardStore {
|
|
|
25
29
|
}
|
|
26
30
|
interface VardOptions {
|
|
27
31
|
/**
|
|
28
|
-
*
|
|
32
|
+
* API Key for authentication. Read from VARD_API_KEY env var if not provided.
|
|
33
|
+
* This is the preferred way to configure the SDK as it's tied to your workspace.
|
|
34
|
+
*/
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Workspace ID (Legacy). Required only if not using an API Key.
|
|
29
38
|
* Read from VARD_WORKSPACE_ID env var if not provided.
|
|
30
39
|
*/
|
|
31
40
|
workspaceId?: string;
|
|
@@ -37,6 +46,15 @@ interface VardOptions {
|
|
|
37
46
|
store?: VardStore;
|
|
38
47
|
}
|
|
39
48
|
interface VardClient {
|
|
49
|
+
/**
|
|
50
|
+
* Access to global (project-wide) variables.
|
|
51
|
+
* e.g., vard.global.string("contact.email", "...")
|
|
52
|
+
*/
|
|
53
|
+
global: VardGlobalClient;
|
|
54
|
+
/**
|
|
55
|
+
* Define a reusable content pool/collection.
|
|
56
|
+
*/
|
|
57
|
+
collection<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
|
|
40
58
|
/**
|
|
41
59
|
* A plain string variable. e.g. a hero headline, a CTA label.
|
|
42
60
|
*
|
|
@@ -72,11 +90,24 @@ interface VardClient {
|
|
|
72
90
|
* and the build pipeline to sync definitions to the Vard API.
|
|
73
91
|
*/
|
|
74
92
|
getDefinitions(): VardVariableDefinition[];
|
|
93
|
+
/**
|
|
94
|
+
* Access to the underlying store.
|
|
95
|
+
*/
|
|
96
|
+
readonly store: VardStore;
|
|
97
|
+
}
|
|
98
|
+
interface VardGlobalClient {
|
|
99
|
+
string(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
100
|
+
richtext(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
101
|
+
color(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
102
|
+
image(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
|
|
103
|
+
boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type" | "group">): boolean;
|
|
104
|
+
list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type" | "group">): InferListItem<S>[];
|
|
75
105
|
}
|
|
76
106
|
interface VardVariableOptions {
|
|
77
107
|
label?: string;
|
|
78
108
|
description?: string;
|
|
79
109
|
editableBy?: VardRole;
|
|
110
|
+
group?: string;
|
|
80
111
|
}
|
|
81
112
|
|
|
82
|
-
export type { InferListItem as I, VardOptions as V, VardClient as a,
|
|
113
|
+
export type { InferListItem as I, VardOptions as V, VardClient as a, VardStore as b, VardListItemSchema as c, VardRole as d, VardVariableDefinition as e, VardVariableOptions as f, VardVariableType as g };
|