@vard-app/sdk 0.1.3 → 0.1.4
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 +57 -71
- package/dist/index.d.mts +4 -17
- package/dist/index.d.ts +4 -17
- package/dist/index.js +161 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -11
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +2 -12
- package/dist/next.d.ts +2 -12
- package/dist/next.js +110 -10
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +110 -10
- package/dist/next.mjs.map +1 -1
- package/dist/{types-eJuYa65b.d.mts → types-Dd-I7jwP.d.mts} +93 -7
- package/dist/{types-eJuYa65b.d.ts → types-Dd-I7jwP.d.ts} +93 -7
- package/package.json +2 -2
|
@@ -1,3 +1,58 @@
|
|
|
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
|
+
|
|
1
56
|
type VardVariableType = "string" | "richtext" | "color" | "image" | "boolean" | "list";
|
|
2
57
|
type VardListItemSchema = Record<string, "string" | "richtext" | "color" | "image" | "boolean">;
|
|
3
58
|
type InferListItem<S extends VardListItemSchema> = {
|
|
@@ -26,26 +81,57 @@ interface VardVariableDefinition<T = unknown> {
|
|
|
26
81
|
interface VardStore {
|
|
27
82
|
/** Returns a stored value for the given key, or undefined if not set */
|
|
28
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>;
|
|
29
88
|
}
|
|
30
|
-
interface VardOptions {
|
|
89
|
+
interface VardOptions<S extends VardSchema = any> {
|
|
31
90
|
/**
|
|
32
91
|
* API Key for authentication. Read from VARD_API_KEY env var if not provided.
|
|
33
92
|
* This is the preferred way to configure the SDK as it's tied to your workspace.
|
|
34
93
|
*/
|
|
35
94
|
apiKey?: string;
|
|
36
95
|
/**
|
|
37
|
-
*
|
|
38
|
-
* Read from VARD_WORKSPACE_ID env var if not provided.
|
|
96
|
+
* Optional content schema for type-safe data access and auto-syncing.
|
|
39
97
|
*/
|
|
40
|
-
|
|
98
|
+
schema?: S;
|
|
41
99
|
/**
|
|
42
100
|
* Provide a custom store implementation. Used internally by the Next.js
|
|
43
101
|
* adapter and for testing. Defaults to a no-op in environments where
|
|
44
|
-
*
|
|
102
|
+
* VARD_API_KEY is unset (local dev without Vard).
|
|
45
103
|
*/
|
|
46
104
|
store?: VardStore;
|
|
47
105
|
}
|
|
48
|
-
interface VardClient {
|
|
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>>;
|
|
49
135
|
/**
|
|
50
136
|
* Access to global (project-wide) variables.
|
|
51
137
|
* e.g., vard.global.string("contact.email", "...")
|
|
@@ -110,4 +196,4 @@ interface VardVariableOptions {
|
|
|
110
196
|
group?: string;
|
|
111
197
|
}
|
|
112
198
|
|
|
113
|
-
export type
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vard-app/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Vard SDK —
|
|
3
|
+
"version": "0.1.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",
|
|
7
7
|
"types": "./dist/index.d.ts",
|