@vard-app/sdk 0.1.4 → 0.1.6

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/dist/index.d.mts CHANGED
@@ -1,5 +1,203 @@
1
- import { V as VardSchema, a as VardOptions, b as VardClient, c as VardStore } from './types-Dd-I7jwP.mjs';
2
- export { I as InferListItem, d as InferSchema, M as MergeSchema, e as VardListItemSchema, f as VardRole, g as VardSchemaFragment, h as VardVariableDefinition, i as VardVariableOptions, j as VardVariableType, v } from './types-Dd-I7jwP.mjs';
1
+ interface VardFieldOptions<T = any> {
2
+ label?: string;
3
+ description?: string;
4
+ editableBy?: VardRole;
5
+ group?: string;
6
+ default?: T;
7
+ }
8
+ interface VardField<T = any> extends VardFieldOptions<T> {
9
+ type: VardVariableType;
10
+ }
11
+ interface VardCollection<S extends Record<string, VardField | any> = any> {
12
+ type: "collection";
13
+ schema: S;
14
+ }
15
+ type VardSchemaValue = VardField | VardCollection | boolean | {
16
+ [key: string]: VardSchemaValue;
17
+ };
18
+ type VardSchema = Record<string, VardSchemaValue>;
19
+ /**
20
+ * A branded schema fragment created with `v.schema()`. Use with `vard.extend()`
21
+ * to compose schemas defined across multiple files.
22
+ */
23
+ type VardSchemaFragment<S extends VardSchema> = S & {
24
+ readonly __fragment: true;
25
+ };
26
+ /**
27
+ * Merges two VardSchema types, with B's keys overriding A on collision.
28
+ */
29
+ type MergeSchema<A extends VardSchema, B extends VardSchema> = Omit<A, keyof B> & B;
30
+ declare const v: {
31
+ string: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
32
+ richtext: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
33
+ color: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
34
+ image: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
35
+ boolean: (defaultValue?: boolean, opts?: Omit<VardFieldOptions<boolean>, "default">) => VardField<boolean>;
36
+ collection: <S extends Record<string, VardField | any>>(schema: S) => VardCollection<S>;
37
+ /**
38
+ * Creates a reusable schema fragment that can be merged into a Vard client
39
+ * via `vard.extend(fragment)`. Co-locate this with your page/component.
40
+ *
41
+ * @example
42
+ * // app/therapists/schema.ts
43
+ * export const therapistSchema = v.schema({
44
+ * therapists: v.collection({ name: v.string(), photo: v.image() }),
45
+ * });
46
+ *
47
+ * // app/therapists/page.tsx
48
+ * const { therapists } = await vard.extend(therapistSchema).get();
49
+ */
50
+ schema: <S extends VardSchema>(schema: S) => VardSchemaFragment<S>;
51
+ };
52
+ type InferSchema<T> = 0 extends 1 & T ? any : T extends VardField<infer U> ? U : T extends VardCollection<infer S> ? InferSchema<S>[] : T extends VardSchemaFragment<infer S> ? InferSchema<S> : T extends Record<string, any> ? {
53
+ [K in keyof T as K extends "__fragment" ? never : K]: InferSchema<T[K]>;
54
+ } : T;
55
+
56
+ type VardVariableType = "string" | "richtext" | "color" | "image" | "boolean" | "list";
57
+ type VardListItemSchema = Record<string, "string" | "richtext" | "color" | "image" | "boolean">;
58
+ type InferListItem<S extends VardListItemSchema> = {
59
+ [K in keyof S]: S[K] extends "string" ? string : S[K] extends "richtext" ? string : S[K] extends "color" ? string : S[K] extends "image" ? string : S[K] extends "boolean" ? boolean : never;
60
+ };
61
+ type VardRole = "owner" | "developer" | "member" | "viewer";
62
+ interface VardVariableDefinition<T = unknown> {
63
+ /** Dot-notation key, e.g. "hero.title" */
64
+ key: string;
65
+ /** Human-readable label shown in the client portal */
66
+ label: string;
67
+ type: VardVariableType;
68
+ /** The default value baked into the codebase */
69
+ defaultValue: T;
70
+ /** Minimum role required to edit this variable. Defaults to "member". */
71
+ editableBy: VardRole;
72
+ /** Optional description shown as a hint in the client portal */
73
+ description?: string;
74
+ /** For list variables — the schema of each item */
75
+ listItemSchema?: VardListItemSchema;
76
+ /** Optional grouping for the dashboard UI */
77
+ group?: string;
78
+ /** Indicates this is a reusable content pool/collection */
79
+ isCollection?: boolean;
80
+ }
81
+ interface VardStore {
82
+ /** Returns a stored value for the given key, or undefined if not set */
83
+ get(key: string): unknown;
84
+ /** Returns the full structured content object */
85
+ getStructured?(): any;
86
+ /** Ensures all values are loaded from the backend */
87
+ prefetch?(): Promise<void>;
88
+ }
89
+ interface VardOptions<S extends VardSchema = any> {
90
+ /**
91
+ * API Key for authentication. Read from VARD_API_KEY env var if not provided.
92
+ * This is the preferred way to configure the SDK as it's tied to your workspace.
93
+ */
94
+ apiKey?: string;
95
+ /**
96
+ * Optional content schema for type-safe data access and auto-syncing.
97
+ */
98
+ schema?: S;
99
+ /**
100
+ * VARD_API_KEY is unset (local dev without Vard).
101
+ */
102
+ store?: VardStore;
103
+ /**
104
+ * Enable verbose logging for requests and responses.
105
+ * Useful for debugging connection issues and verifying data flow.
106
+ */
107
+ debug?: boolean;
108
+ }
109
+ interface VardClient<S extends VardSchema = any> {
110
+ /**
111
+ * Define your content structure for type-safe data access and auto-syncing.
112
+ *
113
+ * @example
114
+ * const content = vard.define({
115
+ * hero: { title: v.string("Welcome") }
116
+ * });
117
+ */
118
+ define<NS extends VardSchema>(schema: NS): InferSchema<NS>;
119
+ /**
120
+ * Returns a type-safe object containing all variable values matching the schema.
121
+ */
122
+ get(): Promise<InferSchema<S>>;
123
+ /**
124
+ * Returns a new scoped client with the given schema fragment merged in.
125
+ * Shares the same underlying store and registry as the parent client.
126
+ * Use this to co-locate page-specific schema definitions with their pages.
127
+ *
128
+ * @example
129
+ * // app/therapists/schema.ts
130
+ * export const therapistSchema = v.schema({
131
+ * therapists: v.collection({ name: v.string() }),
132
+ * });
133
+ *
134
+ * // app/therapists/page.tsx
135
+ * const { therapists, global } = await vard.extend(therapistSchema).get();
136
+ */
137
+ extend<E extends VardSchema>(fragment: VardSchemaFragment<E>): VardClient<MergeSchema<S, E>>;
138
+ /**
139
+ * Access to global (project-wide) variables.
140
+ * e.g., vard.global.string("contact.email", "...")
141
+ */
142
+ global: VardGlobalClient;
143
+ /**
144
+ * Define a reusable content pool/collection.
145
+ */
146
+ collection<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
147
+ /**
148
+ * A plain string variable. e.g. a hero headline, a CTA label.
149
+ *
150
+ * @param key Dot-notation identifier, unique within the workspace
151
+ * @param fallback Default value when no client value is stored
152
+ * @param options Optional label, description, permission
153
+ */
154
+ string(key: string, fallback: string, options?: VardVariableOptions): string;
155
+ /**
156
+ * A rich text (markdown) variable. Rendered as HTML at build time.
157
+ */
158
+ richtext(key: string, fallback: string, options?: VardVariableOptions): string;
159
+ /**
160
+ * A CSS color string (hex, hsl, rgb).
161
+ */
162
+ color(key: string, fallback: string, options?: VardVariableOptions): string;
163
+ /**
164
+ * A URL pointing to an uploaded asset (image, video).
165
+ */
166
+ image(key: string, fallback: string, options?: VardVariableOptions): string;
167
+ /**
168
+ * A boolean feature flag. e.g. show/hide a section.
169
+ */
170
+ boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type">): boolean;
171
+ /**
172
+ * An ordered list of typed objects. e.g. team members, testimonials.
173
+ *
174
+ * @param schema Defines the shape of each list item
175
+ */
176
+ list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
177
+ /**
178
+ * Returns all registered variable definitions. Used by the CLI scanner
179
+ * and the build pipeline to sync definitions to the Vard API.
180
+ */
181
+ getDefinitions(): VardVariableDefinition[];
182
+ /**
183
+ * Access to the underlying store.
184
+ */
185
+ readonly store: VardStore;
186
+ }
187
+ interface VardGlobalClient {
188
+ string(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
189
+ richtext(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
190
+ color(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
191
+ image(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
192
+ boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type" | "group">): boolean;
193
+ list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type" | "group">): InferListItem<S>[];
194
+ }
195
+ interface VardVariableOptions {
196
+ label?: string;
197
+ description?: string;
198
+ editableBy?: VardRole;
199
+ group?: string;
200
+ }
3
201
 
4
202
  /**
5
203
  * Creates a Vard client instance. Call this once at the top of your site
@@ -20,6 +218,10 @@ interface VardFetchStoreOptions {
20
218
  * Custom fetch options (headers, etc.)
21
219
  */
22
220
  fetchOptions?: RequestInit;
221
+ /**
222
+ * Enable verbose logging for requests and responses.
223
+ */
224
+ debug?: boolean;
23
225
  }
24
226
  /**
25
227
  * Creates a universal VardStore that fetches variable values from the Vard API.
@@ -29,4 +231,4 @@ declare function createVardFetchStore(options?: VardFetchStoreOptions): VardStor
29
231
  prefetch(): Promise<void>;
30
232
  };
31
233
 
32
- export { VardClient, VardOptions, VardSchema, VardStore, createVard, createVardFetchStore };
234
+ export { type InferListItem, type InferSchema, type MergeSchema, type VardClient, type VardListItemSchema, type VardOptions, type VardRole, type VardSchema, type VardSchemaFragment, type VardStore, type VardVariableDefinition, type VardVariableOptions, type VardVariableType, createVard, createVardFetchStore, v };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,203 @@
1
- import { V as VardSchema, a as VardOptions, b as VardClient, c as VardStore } from './types-Dd-I7jwP.js';
2
- export { I as InferListItem, d as InferSchema, M as MergeSchema, e as VardListItemSchema, f as VardRole, g as VardSchemaFragment, h as VardVariableDefinition, i as VardVariableOptions, j as VardVariableType, v } from './types-Dd-I7jwP.js';
1
+ interface VardFieldOptions<T = any> {
2
+ label?: string;
3
+ description?: string;
4
+ editableBy?: VardRole;
5
+ group?: string;
6
+ default?: T;
7
+ }
8
+ interface VardField<T = any> extends VardFieldOptions<T> {
9
+ type: VardVariableType;
10
+ }
11
+ interface VardCollection<S extends Record<string, VardField | any> = any> {
12
+ type: "collection";
13
+ schema: S;
14
+ }
15
+ type VardSchemaValue = VardField | VardCollection | boolean | {
16
+ [key: string]: VardSchemaValue;
17
+ };
18
+ type VardSchema = Record<string, VardSchemaValue>;
19
+ /**
20
+ * A branded schema fragment created with `v.schema()`. Use with `vard.extend()`
21
+ * to compose schemas defined across multiple files.
22
+ */
23
+ type VardSchemaFragment<S extends VardSchema> = S & {
24
+ readonly __fragment: true;
25
+ };
26
+ /**
27
+ * Merges two VardSchema types, with B's keys overriding A on collision.
28
+ */
29
+ type MergeSchema<A extends VardSchema, B extends VardSchema> = Omit<A, keyof B> & B;
30
+ declare const v: {
31
+ string: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
32
+ richtext: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
33
+ color: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
34
+ image: (defaultValue?: string, opts?: Omit<VardFieldOptions<string>, "default">) => VardField<string>;
35
+ boolean: (defaultValue?: boolean, opts?: Omit<VardFieldOptions<boolean>, "default">) => VardField<boolean>;
36
+ collection: <S extends Record<string, VardField | any>>(schema: S) => VardCollection<S>;
37
+ /**
38
+ * Creates a reusable schema fragment that can be merged into a Vard client
39
+ * via `vard.extend(fragment)`. Co-locate this with your page/component.
40
+ *
41
+ * @example
42
+ * // app/therapists/schema.ts
43
+ * export const therapistSchema = v.schema({
44
+ * therapists: v.collection({ name: v.string(), photo: v.image() }),
45
+ * });
46
+ *
47
+ * // app/therapists/page.tsx
48
+ * const { therapists } = await vard.extend(therapistSchema).get();
49
+ */
50
+ schema: <S extends VardSchema>(schema: S) => VardSchemaFragment<S>;
51
+ };
52
+ type InferSchema<T> = 0 extends 1 & T ? any : T extends VardField<infer U> ? U : T extends VardCollection<infer S> ? InferSchema<S>[] : T extends VardSchemaFragment<infer S> ? InferSchema<S> : T extends Record<string, any> ? {
53
+ [K in keyof T as K extends "__fragment" ? never : K]: InferSchema<T[K]>;
54
+ } : T;
55
+
56
+ type VardVariableType = "string" | "richtext" | "color" | "image" | "boolean" | "list";
57
+ type VardListItemSchema = Record<string, "string" | "richtext" | "color" | "image" | "boolean">;
58
+ type InferListItem<S extends VardListItemSchema> = {
59
+ [K in keyof S]: S[K] extends "string" ? string : S[K] extends "richtext" ? string : S[K] extends "color" ? string : S[K] extends "image" ? string : S[K] extends "boolean" ? boolean : never;
60
+ };
61
+ type VardRole = "owner" | "developer" | "member" | "viewer";
62
+ interface VardVariableDefinition<T = unknown> {
63
+ /** Dot-notation key, e.g. "hero.title" */
64
+ key: string;
65
+ /** Human-readable label shown in the client portal */
66
+ label: string;
67
+ type: VardVariableType;
68
+ /** The default value baked into the codebase */
69
+ defaultValue: T;
70
+ /** Minimum role required to edit this variable. Defaults to "member". */
71
+ editableBy: VardRole;
72
+ /** Optional description shown as a hint in the client portal */
73
+ description?: string;
74
+ /** For list variables — the schema of each item */
75
+ listItemSchema?: VardListItemSchema;
76
+ /** Optional grouping for the dashboard UI */
77
+ group?: string;
78
+ /** Indicates this is a reusable content pool/collection */
79
+ isCollection?: boolean;
80
+ }
81
+ interface VardStore {
82
+ /** Returns a stored value for the given key, or undefined if not set */
83
+ get(key: string): unknown;
84
+ /** Returns the full structured content object */
85
+ getStructured?(): any;
86
+ /** Ensures all values are loaded from the backend */
87
+ prefetch?(): Promise<void>;
88
+ }
89
+ interface VardOptions<S extends VardSchema = any> {
90
+ /**
91
+ * API Key for authentication. Read from VARD_API_KEY env var if not provided.
92
+ * This is the preferred way to configure the SDK as it's tied to your workspace.
93
+ */
94
+ apiKey?: string;
95
+ /**
96
+ * Optional content schema for type-safe data access and auto-syncing.
97
+ */
98
+ schema?: S;
99
+ /**
100
+ * VARD_API_KEY is unset (local dev without Vard).
101
+ */
102
+ store?: VardStore;
103
+ /**
104
+ * Enable verbose logging for requests and responses.
105
+ * Useful for debugging connection issues and verifying data flow.
106
+ */
107
+ debug?: boolean;
108
+ }
109
+ interface VardClient<S extends VardSchema = any> {
110
+ /**
111
+ * Define your content structure for type-safe data access and auto-syncing.
112
+ *
113
+ * @example
114
+ * const content = vard.define({
115
+ * hero: { title: v.string("Welcome") }
116
+ * });
117
+ */
118
+ define<NS extends VardSchema>(schema: NS): InferSchema<NS>;
119
+ /**
120
+ * Returns a type-safe object containing all variable values matching the schema.
121
+ */
122
+ get(): Promise<InferSchema<S>>;
123
+ /**
124
+ * Returns a new scoped client with the given schema fragment merged in.
125
+ * Shares the same underlying store and registry as the parent client.
126
+ * Use this to co-locate page-specific schema definitions with their pages.
127
+ *
128
+ * @example
129
+ * // app/therapists/schema.ts
130
+ * export const therapistSchema = v.schema({
131
+ * therapists: v.collection({ name: v.string() }),
132
+ * });
133
+ *
134
+ * // app/therapists/page.tsx
135
+ * const { therapists, global } = await vard.extend(therapistSchema).get();
136
+ */
137
+ extend<E extends VardSchema>(fragment: VardSchemaFragment<E>): VardClient<MergeSchema<S, E>>;
138
+ /**
139
+ * Access to global (project-wide) variables.
140
+ * e.g., vard.global.string("contact.email", "...")
141
+ */
142
+ global: VardGlobalClient;
143
+ /**
144
+ * Define a reusable content pool/collection.
145
+ */
146
+ collection<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
147
+ /**
148
+ * A plain string variable. e.g. a hero headline, a CTA label.
149
+ *
150
+ * @param key Dot-notation identifier, unique within the workspace
151
+ * @param fallback Default value when no client value is stored
152
+ * @param options Optional label, description, permission
153
+ */
154
+ string(key: string, fallback: string, options?: VardVariableOptions): string;
155
+ /**
156
+ * A rich text (markdown) variable. Rendered as HTML at build time.
157
+ */
158
+ richtext(key: string, fallback: string, options?: VardVariableOptions): string;
159
+ /**
160
+ * A CSS color string (hex, hsl, rgb).
161
+ */
162
+ color(key: string, fallback: string, options?: VardVariableOptions): string;
163
+ /**
164
+ * A URL pointing to an uploaded asset (image, video).
165
+ */
166
+ image(key: string, fallback: string, options?: VardVariableOptions): string;
167
+ /**
168
+ * A boolean feature flag. e.g. show/hide a section.
169
+ */
170
+ boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type">): boolean;
171
+ /**
172
+ * An ordered list of typed objects. e.g. team members, testimonials.
173
+ *
174
+ * @param schema Defines the shape of each list item
175
+ */
176
+ list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
177
+ /**
178
+ * Returns all registered variable definitions. Used by the CLI scanner
179
+ * and the build pipeline to sync definitions to the Vard API.
180
+ */
181
+ getDefinitions(): VardVariableDefinition[];
182
+ /**
183
+ * Access to the underlying store.
184
+ */
185
+ readonly store: VardStore;
186
+ }
187
+ interface VardGlobalClient {
188
+ string(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
189
+ richtext(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
190
+ color(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
191
+ image(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
192
+ boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type" | "group">): boolean;
193
+ list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type" | "group">): InferListItem<S>[];
194
+ }
195
+ interface VardVariableOptions {
196
+ label?: string;
197
+ description?: string;
198
+ editableBy?: VardRole;
199
+ group?: string;
200
+ }
3
201
 
4
202
  /**
5
203
  * Creates a Vard client instance. Call this once at the top of your site
@@ -20,6 +218,10 @@ interface VardFetchStoreOptions {
20
218
  * Custom fetch options (headers, etc.)
21
219
  */
22
220
  fetchOptions?: RequestInit;
221
+ /**
222
+ * Enable verbose logging for requests and responses.
223
+ */
224
+ debug?: boolean;
23
225
  }
24
226
  /**
25
227
  * Creates a universal VardStore that fetches variable values from the Vard API.
@@ -29,4 +231,4 @@ declare function createVardFetchStore(options?: VardFetchStoreOptions): VardStor
29
231
  prefetch(): Promise<void>;
30
232
  };
31
233
 
32
- export { VardClient, VardOptions, VardSchema, VardStore, createVard, createVardFetchStore };
234
+ export { type InferListItem, type InferSchema, type MergeSchema, type VardClient, type VardListItemSchema, type VardOptions, type VardRole, type VardSchema, type VardSchemaFragment, type VardStore, type VardVariableDefinition, type VardVariableOptions, type VardVariableType, createVard, createVardFetchStore, v };
package/dist/index.js CHANGED
@@ -18,20 +18,21 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  createVard: () => createVard,
24
24
  createVardFetchStore: () => createVardFetchStore,
25
25
  v: () => v
26
26
  });
27
- module.exports = __toCommonJS(src_exports);
27
+ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/fetch-store.ts
30
30
  function createVardFetchStore(options = {}) {
31
31
  const {
32
- apiBase = options.apiBase ?? process.env.VARD_API_BASE ?? process.env.NEXT_PUBLIC_VARD_API_BASE ?? "https://dash.vard.app",
32
+ apiBase = options.apiBase ?? process.env.VARD_API_HOST ?? "https://dash.vard.app",
33
33
  apiKey = options.apiKey ?? process.env.VARD_API_KEY,
34
- fetchOptions = {}
34
+ fetchOptions = {},
35
+ debug = options.debug ?? false
35
36
  } = options;
36
37
  let resolvedValues = null;
37
38
  let structuredContent = null;
@@ -50,7 +51,14 @@ function createVardFetchStore(options = {}) {
50
51
  }
51
52
  return { variables: /* @__PURE__ */ new Map(), structured: {} };
52
53
  }
53
- const url = `${apiBase}/api/content/variables?structured=true`;
54
+ const url = `${apiBase}/api/content/variables`;
55
+ if (debug) {
56
+ console.log(`[vard] Request: GET ${url}`);
57
+ console.log(`[vard] Headers:`, {
58
+ "X-Vard-API-Key": apiKey.substring(0, 10) + "...",
59
+ ...fetchOptions.headers
60
+ });
61
+ }
54
62
  try {
55
63
  const res = await fetch(url, {
56
64
  ...fetchOptions,
@@ -60,24 +68,39 @@ function createVardFetchStore(options = {}) {
60
68
  }
61
69
  });
62
70
  if (!res.ok) {
63
- console.warn(`[vard] Failed to fetch variables: ${res.status}`);
71
+ const errorMsg = `[vard] Failed to fetch variables from ${url} (Status: ${res.status} ${res.statusText})`;
72
+ console.error(`\x1B[31m${errorMsg}\x1B[0m`);
64
73
  return { variables: /* @__PURE__ */ new Map(), structured: {} };
65
74
  }
66
75
  const data = await res.json();
67
- if (Array.isArray(data)) {
68
- return {
69
- variables: new Map(data.map((v2) => [v2.key, v2.value])),
70
- structured: {}
71
- };
76
+ if (debug) {
77
+ console.log(`[vard] Response (${res.status}):`, data);
72
78
  }
79
+ const variablesMap = /* @__PURE__ */ new Map();
80
+ flattenObject(data, "", variablesMap);
73
81
  return {
74
- variables: new Map(data.variables.map((v2) => [v2.key, v2.value])),
75
- structured: data.structured || {}
82
+ variables: variablesMap,
83
+ structured: data
76
84
  };
77
85
  } catch (err) {
86
+ const errorMsg = `[vard] Network error fetching variables from ${url}`;
87
+ console.error(`\x1B[31m${errorMsg}\x1B[0m`, err);
78
88
  return { variables: /* @__PURE__ */ new Map(), structured: {} };
79
89
  }
80
90
  }
91
+ function flattenObject(obj, prefix, map) {
92
+ if (typeof obj !== "object" || obj === null) return;
93
+ for (const [key, value] of Object.entries(obj)) {
94
+ const fullKey = prefix ? `${prefix}.${key}` : key;
95
+ if (Array.isArray(value)) {
96
+ map.set(fullKey, value);
97
+ } else if (typeof value === "object" && value !== null) {
98
+ flattenObject(value, fullKey, map);
99
+ } else {
100
+ map.set(fullKey, value);
101
+ }
102
+ }
103
+ }
81
104
  return {
82
105
  get(key) {
83
106
  return resolvedValues?.get(key);
@@ -173,7 +196,7 @@ function createVard(options = {}) {
173
196
  if (options.schema && process.env.NODE_ENV === "development" && options.apiKey) {
174
197
  flattenSchema(options.schema);
175
198
  const definitions = [...registry];
176
- const apiBase = process.env.VARD_API_BASE ?? process.env.NEXT_PUBLIC_VARD_API_BASE ?? "https://dash.vard.app";
199
+ const apiBase = process.env.VARD_API_HOST ?? "https://dash.vard.app";
177
200
  fetch(`${apiBase}/api/content/variables/sync`, {
178
201
  method: "POST",
179
202
  headers: {