@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vard-app/sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Vard SDK — modern, schema-first content layer for Next.js",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -37,9 +37,13 @@
37
37
  "optional": true
38
38
  }
39
39
  },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
40
43
  "scripts": {
41
44
  "build": "tsup",
42
45
  "dev": "tsup --watch",
43
- "type-check": "tsc --noEmit"
46
+ "type-check": "tsc --noEmit",
47
+ "test:types": "tsc --noEmit src/test-types.ts --esModuleInterop --skipLibCheck --target esnext --moduleResolution node"
44
48
  }
45
49
  }
@@ -1,199 +0,0 @@
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 | {
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> = {
53
- [K in keyof T]: T[K] extends VardField<infer U> ? U : T[K] extends VardCollection<infer S> ? InferSchema<S>[] : T[K] extends object ? InferSchema<T[K]> : never;
54
- };
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
- * Provide a custom store implementation. Used internally by the Next.js
101
- * adapter and for testing. Defaults to a no-op in environments where
102
- * VARD_API_KEY is unset (local dev without Vard).
103
- */
104
- store?: VardStore;
105
- }
106
- interface VardClient<S extends VardSchema = any> {
107
- /**
108
- * Define your content structure for type-safe data access and auto-syncing.
109
- *
110
- * @example
111
- * const content = vard.define({
112
- * hero: { title: v.string("Welcome") }
113
- * });
114
- */
115
- define<NS extends VardSchema>(schema: NS): InferSchema<NS>;
116
- /**
117
- * Returns a type-safe object containing all variable values matching the schema.
118
- */
119
- get(): Promise<InferSchema<S>>;
120
- /**
121
- * Returns a new scoped client with the given schema fragment merged in.
122
- * Shares the same underlying store and registry as the parent client.
123
- * Use this to co-locate page-specific schema definitions with their pages.
124
- *
125
- * @example
126
- * // app/therapists/schema.ts
127
- * export const therapistSchema = v.schema({
128
- * therapists: v.collection({ name: v.string() }),
129
- * });
130
- *
131
- * // app/therapists/page.tsx
132
- * const { therapists, global } = await vard.extend(therapistSchema).get();
133
- */
134
- extend<E extends VardSchema>(fragment: VardSchemaFragment<E>): VardClient<MergeSchema<S, E>>;
135
- /**
136
- * Access to global (project-wide) variables.
137
- * e.g., vard.global.string("contact.email", "...")
138
- */
139
- global: VardGlobalClient;
140
- /**
141
- * Define a reusable content pool/collection.
142
- */
143
- collection<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
144
- /**
145
- * A plain string variable. e.g. a hero headline, a CTA label.
146
- *
147
- * @param key Dot-notation identifier, unique within the workspace
148
- * @param fallback Default value when no client value is stored
149
- * @param options Optional label, description, permission
150
- */
151
- string(key: string, fallback: string, options?: VardVariableOptions): string;
152
- /**
153
- * A rich text (markdown) variable. Rendered as HTML at build time.
154
- */
155
- richtext(key: string, fallback: string, options?: VardVariableOptions): string;
156
- /**
157
- * A CSS color string (hex, hsl, rgb).
158
- */
159
- color(key: string, fallback: string, options?: VardVariableOptions): string;
160
- /**
161
- * A URL pointing to an uploaded asset (image, video).
162
- */
163
- image(key: string, fallback: string, options?: VardVariableOptions): string;
164
- /**
165
- * A boolean feature flag. e.g. show/hide a section.
166
- */
167
- boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type">): boolean;
168
- /**
169
- * An ordered list of typed objects. e.g. team members, testimonials.
170
- *
171
- * @param schema Defines the shape of each list item
172
- */
173
- list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
174
- /**
175
- * Returns all registered variable definitions. Used by the CLI scanner
176
- * and the build pipeline to sync definitions to the Vard API.
177
- */
178
- getDefinitions(): VardVariableDefinition[];
179
- /**
180
- * Access to the underlying store.
181
- */
182
- readonly store: VardStore;
183
- }
184
- interface VardGlobalClient {
185
- string(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
186
- richtext(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
187
- color(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
188
- image(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
189
- boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type" | "group">): boolean;
190
- list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type" | "group">): InferListItem<S>[];
191
- }
192
- interface VardVariableOptions {
193
- label?: string;
194
- description?: string;
195
- editableBy?: VardRole;
196
- group?: string;
197
- }
198
-
199
- export { type InferListItem as I, type MergeSchema as M, type VardSchema as V, type VardOptions as a, type VardClient as b, type VardStore as c, type InferSchema as d, type VardListItemSchema as e, type VardRole as f, type VardSchemaFragment as g, type VardVariableDefinition as h, type VardVariableOptions as i, type VardVariableType as j, v };
@@ -1,199 +0,0 @@
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 | {
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> = {
53
- [K in keyof T]: T[K] extends VardField<infer U> ? U : T[K] extends VardCollection<infer S> ? InferSchema<S>[] : T[K] extends object ? InferSchema<T[K]> : never;
54
- };
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
- * Provide a custom store implementation. Used internally by the Next.js
101
- * adapter and for testing. Defaults to a no-op in environments where
102
- * VARD_API_KEY is unset (local dev without Vard).
103
- */
104
- store?: VardStore;
105
- }
106
- interface VardClient<S extends VardSchema = any> {
107
- /**
108
- * Define your content structure for type-safe data access and auto-syncing.
109
- *
110
- * @example
111
- * const content = vard.define({
112
- * hero: { title: v.string("Welcome") }
113
- * });
114
- */
115
- define<NS extends VardSchema>(schema: NS): InferSchema<NS>;
116
- /**
117
- * Returns a type-safe object containing all variable values matching the schema.
118
- */
119
- get(): Promise<InferSchema<S>>;
120
- /**
121
- * Returns a new scoped client with the given schema fragment merged in.
122
- * Shares the same underlying store and registry as the parent client.
123
- * Use this to co-locate page-specific schema definitions with their pages.
124
- *
125
- * @example
126
- * // app/therapists/schema.ts
127
- * export const therapistSchema = v.schema({
128
- * therapists: v.collection({ name: v.string() }),
129
- * });
130
- *
131
- * // app/therapists/page.tsx
132
- * const { therapists, global } = await vard.extend(therapistSchema).get();
133
- */
134
- extend<E extends VardSchema>(fragment: VardSchemaFragment<E>): VardClient<MergeSchema<S, E>>;
135
- /**
136
- * Access to global (project-wide) variables.
137
- * e.g., vard.global.string("contact.email", "...")
138
- */
139
- global: VardGlobalClient;
140
- /**
141
- * Define a reusable content pool/collection.
142
- */
143
- collection<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
144
- /**
145
- * A plain string variable. e.g. a hero headline, a CTA label.
146
- *
147
- * @param key Dot-notation identifier, unique within the workspace
148
- * @param fallback Default value when no client value is stored
149
- * @param options Optional label, description, permission
150
- */
151
- string(key: string, fallback: string, options?: VardVariableOptions): string;
152
- /**
153
- * A rich text (markdown) variable. Rendered as HTML at build time.
154
- */
155
- richtext(key: string, fallback: string, options?: VardVariableOptions): string;
156
- /**
157
- * A CSS color string (hex, hsl, rgb).
158
- */
159
- color(key: string, fallback: string, options?: VardVariableOptions): string;
160
- /**
161
- * A URL pointing to an uploaded asset (image, video).
162
- */
163
- image(key: string, fallback: string, options?: VardVariableOptions): string;
164
- /**
165
- * A boolean feature flag. e.g. show/hide a section.
166
- */
167
- boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type">): boolean;
168
- /**
169
- * An ordered list of typed objects. e.g. team members, testimonials.
170
- *
171
- * @param schema Defines the shape of each list item
172
- */
173
- list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type">): InferListItem<S>[];
174
- /**
175
- * Returns all registered variable definitions. Used by the CLI scanner
176
- * and the build pipeline to sync definitions to the Vard API.
177
- */
178
- getDefinitions(): VardVariableDefinition[];
179
- /**
180
- * Access to the underlying store.
181
- */
182
- readonly store: VardStore;
183
- }
184
- interface VardGlobalClient {
185
- string(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
186
- richtext(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
187
- color(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
188
- image(key: string, fallback: string, options?: Omit<VardVariableOptions, "group">): string;
189
- boolean(key: string, fallback: boolean, options?: Omit<VardVariableOptions, "type" | "group">): boolean;
190
- list<S extends VardListItemSchema>(key: string, schema: S, fallback: InferListItem<S>[], options?: Omit<VardVariableOptions, "type" | "group">): InferListItem<S>[];
191
- }
192
- interface VardVariableOptions {
193
- label?: string;
194
- description?: string;
195
- editableBy?: VardRole;
196
- group?: string;
197
- }
198
-
199
- export { type InferListItem as I, type MergeSchema as M, type VardSchema as V, type VardOptions as a, type VardClient as b, type VardStore as c, type InferSchema as d, type VardListItemSchema as e, type VardRole as f, type VardSchemaFragment as g, type VardVariableDefinition as h, type VardVariableOptions as i, type VardVariableType as j, v };