@farcaster/snap 1.3.1 → 1.3.3
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.ts +1 -1
- package/dist/schemas.d.ts +3 -2
- package/dist/schemas.js +1 -1
- package/dist/server/parseRequest.d.ts +1 -1
- package/dist/server/parseRequest.js +1 -1
- package/dist/ui/bar-chart.d.ts +30 -0
- package/dist/ui/bar-chart.js +14 -0
- package/dist/ui/button-group.d.ts +11 -0
- package/dist/ui/button-group.js +10 -0
- package/dist/ui/button.d.ts +32 -0
- package/dist/ui/button.js +10 -0
- package/dist/ui/catalog.d.ts +271 -0
- package/dist/ui/catalog.js +114 -0
- package/dist/ui/divider.d.ts +3 -0
- package/dist/ui/divider.js +2 -0
- package/dist/ui/grid.d.ts +22 -0
- package/dist/ui/grid.js +16 -0
- package/dist/ui/group.d.ts +8 -0
- package/dist/ui/group.js +4 -0
- package/dist/ui/image.d.ts +13 -0
- package/dist/ui/image.js +7 -0
- package/dist/ui/index.d.ts +32 -0
- package/dist/ui/index.js +17 -0
- package/dist/ui/list.d.ts +13 -0
- package/dist/ui/list.js +13 -0
- package/dist/ui/progress.d.ts +18 -0
- package/dist/ui/progress.js +8 -0
- package/dist/ui/schema.d.ts +32 -0
- package/dist/ui/schema.js +31 -0
- package/dist/ui/slider.d.ts +12 -0
- package/dist/ui/slider.js +11 -0
- package/dist/ui/spacer.d.ts +9 -0
- package/dist/ui/spacer.js +5 -0
- package/dist/ui/stack.d.ts +3 -0
- package/dist/ui/stack.js +2 -0
- package/dist/ui/text-input.d.ts +7 -0
- package/dist/ui/text-input.js +12 -0
- package/dist/ui/text.d.ts +16 -0
- package/dist/ui/text.js +7 -0
- package/dist/ui/toggle.d.ts +7 -0
- package/dist/ui/toggle.js +6 -0
- package/dist/validator.d.ts +1 -1
- package/package.json +83 -2
- package/src/index.ts +1 -0
- package/src/schemas.ts +3 -2
- package/src/server/parseRequest.ts +1 -1
- package/src/ui/README.md +50 -0
- package/src/ui/bar-chart.ts +23 -0
- package/src/ui/button-group.ts +13 -0
- package/src/ui/button.ts +15 -0
- package/src/ui/catalog.ts +128 -0
- package/src/ui/divider.ts +5 -0
- package/src/ui/grid.ts +25 -0
- package/src/ui/group.ts +7 -0
- package/src/ui/image.ts +10 -0
- package/src/ui/index.ts +47 -0
- package/src/ui/list.ts +17 -0
- package/src/ui/progress.ts +11 -0
- package/src/ui/schema.ts +37 -0
- package/src/ui/slider.ts +14 -0
- package/src/ui/spacer.ts +8 -0
- package/src/ui/stack.ts +5 -0
- package/src/ui/text-input.ts +15 -0
- package/src/ui/text.ts +10 -0
- package/src/ui/toggle.ts +9 -0
- package/src/validator.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { POST_GRID_TAP_KEY, PAGE_ROOT_TYPE, ELEMENT_TYPE, MEDIA_TYPE, DEFAULT_THEME_ACCENT, DEFAULT_LIST_STYLE, DEFAULT_SLIDER_STEP, PALETTE_COLOR, PALETTE_COLOR_VALUES, PALETTE_LIGHT_HEX, PALETTE_DARK_HEX, type PaletteColor, } from "./constants.js";
|
|
2
|
-
export { rootSchema, firstPageRootSchema, payloadSchema, type SnapAction, type SnapContext, type SnapResponse, type SnapFunction, type SnapPayload, } from "./schemas.js";
|
|
2
|
+
export { rootSchema, firstPageRootSchema, payloadSchema, type SnapAction, type SnapContext, type SnapResponse, type SnapResponseInput, type SnapFunction, type SnapPayload, } from "./schemas.js";
|
|
3
3
|
export { validatePage, validateFirstPage, type ValidationResult, } from "./validator.js";
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
declare const buttonSchema: z.ZodObject<{
|
|
3
3
|
label: z.ZodString;
|
|
4
4
|
action: z.ZodEnum<{
|
|
@@ -1362,6 +1362,7 @@ export declare const payloadSchema: z.ZodObject<{
|
|
|
1362
1362
|
timestamp: z.ZodNumber;
|
|
1363
1363
|
}, z.core.$strict>;
|
|
1364
1364
|
export type SnapResponse = z.infer<typeof rootSchema>;
|
|
1365
|
+
export type SnapResponseInput = z.input<typeof rootSchema>;
|
|
1365
1366
|
export type SnapPage = SnapResponse["page"];
|
|
1366
1367
|
export type SnapPayload = z.infer<typeof payloadSchema>;
|
|
1367
1368
|
declare const snapPostActionSchema: z.ZodObject<{
|
|
@@ -1382,5 +1383,5 @@ export type SnapContext = {
|
|
|
1382
1383
|
action: SnapAction;
|
|
1383
1384
|
request: Request;
|
|
1384
1385
|
};
|
|
1385
|
-
export type SnapFunction = (ctx: SnapContext) => Promise<
|
|
1386
|
+
export type SnapFunction = (ctx: SnapContext) => Promise<SnapResponseInput>;
|
|
1386
1387
|
export {};
|
package/dist/schemas.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import { BAR_CHART_COLOR_VALUES, BUTTON_ACTION, BUTTON_ACTION_VALUES, BUTTON_GROUP_STYLE, BUTTON_GROUP_STYLE_VALUES, BUTTON_LAYOUT_VALUES, BUTTON_STYLE_VALUES, DEFAULT_BUTTON_LAYOUT, DEFAULT_LIST_STYLE, DEFAULT_SLIDER_STEP, DEFAULT_THEME_ACCENT, EFFECT_VALUES, ELEMENT_TYPE, GRID_CELL_SIZE_VALUES, GRID_GAP_VALUES, GROUP_LAYOUT_VALUES, HEX_COLOR_6_RE, HTTP_PREFIX, HTTPS_PREFIX, IMAGE_ASPECT_VALUES, INTERACTIVE_ELEMENT_TYPES, LIMITS, LIST_STYLE_VALUES, MEDIA_ELEMENT_TYPES, PAGE_ROOT_TYPE, PALETTE_COLOR_VALUES, PROGRESS_COLOR_VALUES, SLIDER_STEP_ALIGN_EPS, SPACER_SIZE, SPACER_SIZE_VALUES, SPEC_VERSION, TEXT_ALIGN_VALUES, TEXT_CONTENT_MAX, TEXT_STYLE, TEXT_STYLE_VALUES, } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* post/link/mini_app targets must be HTTPS in production; allow HTTP only for
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { payloadSchema } from "../schemas.js";
|
|
2
2
|
import { decodePayload, verifyJFSRequestBody } from "./verify.js";
|
|
3
|
-
import { z } from "zod
|
|
3
|
+
import { z } from "zod";
|
|
4
4
|
/** Default replay window per SPEC.md § Replay Protection (5 minutes). */
|
|
5
5
|
const DEFAULT_SNAP_POST_MAX_SKEW_SECONDS = 300;
|
|
6
6
|
const requestBodySchema = z.object({
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const barChartProps: z.ZodObject<{
|
|
3
|
+
bars: z.ZodArray<z.ZodObject<{
|
|
4
|
+
label: z.ZodString;
|
|
5
|
+
value: z.ZodNumber;
|
|
6
|
+
color: z.ZodOptional<z.ZodEnum<{
|
|
7
|
+
gray: "gray";
|
|
8
|
+
blue: "blue";
|
|
9
|
+
red: "red";
|
|
10
|
+
amber: "amber";
|
|
11
|
+
green: "green";
|
|
12
|
+
teal: "teal";
|
|
13
|
+
purple: "purple";
|
|
14
|
+
pink: "pink";
|
|
15
|
+
}>>;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
color: z.ZodOptional<z.ZodEnum<{
|
|
19
|
+
gray: "gray";
|
|
20
|
+
blue: "blue";
|
|
21
|
+
red: "red";
|
|
22
|
+
amber: "amber";
|
|
23
|
+
green: "green";
|
|
24
|
+
teal: "teal";
|
|
25
|
+
purple: "purple";
|
|
26
|
+
pink: "pink";
|
|
27
|
+
accent: "accent";
|
|
28
|
+
}>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type BarChartProps = z.infer<typeof barChartProps>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BAR_CHART_COLOR_VALUES, LIMITS, PALETTE_COLOR_VALUES, } from "../constants.js";
|
|
3
|
+
export const barChartProps = z.object({
|
|
4
|
+
bars: z
|
|
5
|
+
.array(z.object({
|
|
6
|
+
label: z.string(),
|
|
7
|
+
value: z.number().nonnegative(),
|
|
8
|
+
color: z.enum(PALETTE_COLOR_VALUES).optional(),
|
|
9
|
+
}))
|
|
10
|
+
.min(1)
|
|
11
|
+
.max(LIMITS.maxBarChartBars),
|
|
12
|
+
max: z.number().nonnegative().optional(),
|
|
13
|
+
color: z.enum(BAR_CHART_COLOR_VALUES).optional(),
|
|
14
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const buttonGroupProps: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
options: z.ZodArray<z.ZodString>;
|
|
5
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
row: "row";
|
|
7
|
+
stack: "stack";
|
|
8
|
+
grid: "grid";
|
|
9
|
+
}>>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export type ButtonGroupProps = z.infer<typeof buttonGroupProps>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BUTTON_GROUP_STYLE_VALUES, LIMITS } from "../constants.js";
|
|
3
|
+
export const buttonGroupProps = z.object({
|
|
4
|
+
name: z.string().min(1),
|
|
5
|
+
options: z
|
|
6
|
+
.array(z.string())
|
|
7
|
+
.min(LIMITS.minButtonGroupOptions)
|
|
8
|
+
.max(LIMITS.maxButtonGroupOptions),
|
|
9
|
+
style: z.enum(BUTTON_GROUP_STYLE_VALUES).optional(),
|
|
10
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const actionButtonProps: z.ZodObject<{
|
|
3
|
+
label: z.ZodString;
|
|
4
|
+
action: z.ZodEnum<{
|
|
5
|
+
post: "post";
|
|
6
|
+
link: "link";
|
|
7
|
+
mini_app: "mini_app";
|
|
8
|
+
sdk: "sdk";
|
|
9
|
+
}>;
|
|
10
|
+
target: z.ZodString;
|
|
11
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
12
|
+
primary: "primary";
|
|
13
|
+
secondary: "secondary";
|
|
14
|
+
}>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type ActionButtonProps = z.infer<typeof actionButtonProps>;
|
|
17
|
+
/** Same schema as `actionButtonProps` (legacy export name). */
|
|
18
|
+
export declare const buttonProps: z.ZodObject<{
|
|
19
|
+
label: z.ZodString;
|
|
20
|
+
action: z.ZodEnum<{
|
|
21
|
+
post: "post";
|
|
22
|
+
link: "link";
|
|
23
|
+
mini_app: "mini_app";
|
|
24
|
+
sdk: "sdk";
|
|
25
|
+
}>;
|
|
26
|
+
target: z.ZodString;
|
|
27
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
primary: "primary";
|
|
29
|
+
secondary: "secondary";
|
|
30
|
+
}>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type ButtonProps = ActionButtonProps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BUTTON_ACTION_VALUES, BUTTON_STYLE_VALUES } from "../constants.js";
|
|
3
|
+
export const actionButtonProps = z.object({
|
|
4
|
+
label: z.string(),
|
|
5
|
+
action: z.enum(BUTTON_ACTION_VALUES),
|
|
6
|
+
target: z.string(),
|
|
7
|
+
style: z.enum(BUTTON_STYLE_VALUES).optional(),
|
|
8
|
+
});
|
|
9
|
+
/** Same schema as `actionButtonProps` (legacy export name). */
|
|
10
|
+
export const buttonProps = actionButtonProps;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Basic catalog: one json-render component per snap element type, plus ActionButton for snap buttons.
|
|
4
|
+
* Does not validate cross-field rules (media count, height budget); snap JSON still goes through `@farcaster/snap` validation.
|
|
5
|
+
*/
|
|
6
|
+
export declare const snapJsonRenderCatalog: import("@json-render/core").Catalog<{
|
|
7
|
+
spec: import("@json-render/core").SchemaType<"object", {
|
|
8
|
+
root: import("@json-render/core").SchemaType<"string", unknown>;
|
|
9
|
+
elements: import("@json-render/core").SchemaType<"record", import("@json-render/core").SchemaType<"object", {
|
|
10
|
+
type: import("@json-render/core").SchemaType<"ref", string>;
|
|
11
|
+
props: import("@json-render/core").SchemaType<"propsOf", string>;
|
|
12
|
+
children: {
|
|
13
|
+
optional: true;
|
|
14
|
+
kind: "array";
|
|
15
|
+
inner?: import("@json-render/core").SchemaType<"string", unknown> | undefined;
|
|
16
|
+
};
|
|
17
|
+
}>>;
|
|
18
|
+
}>;
|
|
19
|
+
catalog: import("@json-render/core").SchemaType<"object", {
|
|
20
|
+
components: import("@json-render/core").SchemaType<"map", {
|
|
21
|
+
props: import("@json-render/core").SchemaType<"zod", unknown>;
|
|
22
|
+
description: import("@json-render/core").SchemaType<"string", unknown>;
|
|
23
|
+
}>;
|
|
24
|
+
actions: import("@json-render/core").SchemaType<"map", {
|
|
25
|
+
description: import("@json-render/core").SchemaType<"string", unknown>;
|
|
26
|
+
params: {
|
|
27
|
+
optional: true;
|
|
28
|
+
kind: "zod";
|
|
29
|
+
inner?: unknown;
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
32
|
+
}>;
|
|
33
|
+
}, {
|
|
34
|
+
components: {
|
|
35
|
+
Text: {
|
|
36
|
+
props: z.ZodObject<{
|
|
37
|
+
style: z.ZodEnum<{
|
|
38
|
+
title: "title";
|
|
39
|
+
body: "body";
|
|
40
|
+
caption: "caption";
|
|
41
|
+
label: "label";
|
|
42
|
+
}>;
|
|
43
|
+
content: z.ZodString;
|
|
44
|
+
align: z.ZodOptional<z.ZodEnum<{
|
|
45
|
+
left: "left";
|
|
46
|
+
center: "center";
|
|
47
|
+
right: "right";
|
|
48
|
+
}>>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
52
|
+
Image: {
|
|
53
|
+
props: z.ZodObject<{
|
|
54
|
+
url: z.ZodString;
|
|
55
|
+
aspect: z.ZodEnum<{
|
|
56
|
+
"1:1": "1:1";
|
|
57
|
+
"16:9": "16:9";
|
|
58
|
+
"4:3": "4:3";
|
|
59
|
+
"3:4": "3:4";
|
|
60
|
+
"9:16": "9:16";
|
|
61
|
+
}>;
|
|
62
|
+
alt: z.ZodOptional<z.ZodString>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
description: string;
|
|
65
|
+
};
|
|
66
|
+
Divider: {
|
|
67
|
+
props: z.ZodObject<{}, z.core.$strip>;
|
|
68
|
+
description: string;
|
|
69
|
+
};
|
|
70
|
+
Spacer: {
|
|
71
|
+
props: z.ZodObject<{
|
|
72
|
+
size: z.ZodOptional<z.ZodEnum<{
|
|
73
|
+
small: "small";
|
|
74
|
+
medium: "medium";
|
|
75
|
+
large: "large";
|
|
76
|
+
}>>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
description: string;
|
|
79
|
+
};
|
|
80
|
+
Progress: {
|
|
81
|
+
props: z.ZodObject<{
|
|
82
|
+
value: z.ZodNumber;
|
|
83
|
+
max: z.ZodNumber;
|
|
84
|
+
label: z.ZodOptional<z.ZodString>;
|
|
85
|
+
color: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
gray: "gray";
|
|
87
|
+
blue: "blue";
|
|
88
|
+
red: "red";
|
|
89
|
+
amber: "amber";
|
|
90
|
+
green: "green";
|
|
91
|
+
teal: "teal";
|
|
92
|
+
purple: "purple";
|
|
93
|
+
pink: "pink";
|
|
94
|
+
accent: "accent";
|
|
95
|
+
}>>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
description: string;
|
|
98
|
+
};
|
|
99
|
+
List: {
|
|
100
|
+
props: z.ZodObject<{
|
|
101
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
102
|
+
ordered: "ordered";
|
|
103
|
+
unordered: "unordered";
|
|
104
|
+
plain: "plain";
|
|
105
|
+
}>>;
|
|
106
|
+
items: z.ZodArray<z.ZodObject<{
|
|
107
|
+
content: z.ZodString;
|
|
108
|
+
trailing: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, z.core.$strip>>;
|
|
110
|
+
}, z.core.$strip>;
|
|
111
|
+
description: string;
|
|
112
|
+
};
|
|
113
|
+
Grid: {
|
|
114
|
+
props: z.ZodObject<{
|
|
115
|
+
cols: z.ZodNumber;
|
|
116
|
+
rows: z.ZodNumber;
|
|
117
|
+
cells: z.ZodArray<z.ZodObject<{
|
|
118
|
+
row: z.ZodNumber;
|
|
119
|
+
col: z.ZodNumber;
|
|
120
|
+
color: z.ZodOptional<z.ZodString>;
|
|
121
|
+
content: z.ZodOptional<z.ZodString>;
|
|
122
|
+
}, z.core.$strip>>;
|
|
123
|
+
cellSize: z.ZodOptional<z.ZodEnum<{
|
|
124
|
+
auto: "auto";
|
|
125
|
+
square: "square";
|
|
126
|
+
}>>;
|
|
127
|
+
gap: z.ZodOptional<z.ZodEnum<{
|
|
128
|
+
small: "small";
|
|
129
|
+
medium: "medium";
|
|
130
|
+
none: "none";
|
|
131
|
+
}>>;
|
|
132
|
+
interactive: z.ZodOptional<z.ZodBoolean>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
description: string;
|
|
135
|
+
};
|
|
136
|
+
TextInput: {
|
|
137
|
+
props: z.ZodObject<{
|
|
138
|
+
name: z.ZodString;
|
|
139
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
140
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
description: string;
|
|
143
|
+
};
|
|
144
|
+
Slider: {
|
|
145
|
+
props: z.ZodObject<{
|
|
146
|
+
name: z.ZodString;
|
|
147
|
+
min: z.ZodNumber;
|
|
148
|
+
max: z.ZodNumber;
|
|
149
|
+
step: z.ZodOptional<z.ZodNumber>;
|
|
150
|
+
value: z.ZodOptional<z.ZodNumber>;
|
|
151
|
+
label: z.ZodOptional<z.ZodString>;
|
|
152
|
+
minLabel: z.ZodOptional<z.ZodString>;
|
|
153
|
+
maxLabel: z.ZodOptional<z.ZodString>;
|
|
154
|
+
}, z.core.$strip>;
|
|
155
|
+
description: string;
|
|
156
|
+
};
|
|
157
|
+
ButtonGroup: {
|
|
158
|
+
props: z.ZodObject<{
|
|
159
|
+
name: z.ZodString;
|
|
160
|
+
options: z.ZodArray<z.ZodString>;
|
|
161
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
162
|
+
row: "row";
|
|
163
|
+
stack: "stack";
|
|
164
|
+
grid: "grid";
|
|
165
|
+
}>>;
|
|
166
|
+
}, z.core.$strip>;
|
|
167
|
+
description: string;
|
|
168
|
+
};
|
|
169
|
+
Toggle: {
|
|
170
|
+
props: z.ZodObject<{
|
|
171
|
+
name: z.ZodString;
|
|
172
|
+
label: z.ZodString;
|
|
173
|
+
value: z.ZodOptional<z.ZodBoolean>;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
description: string;
|
|
176
|
+
};
|
|
177
|
+
BarChart: {
|
|
178
|
+
props: z.ZodObject<{
|
|
179
|
+
bars: z.ZodArray<z.ZodObject<{
|
|
180
|
+
label: z.ZodString;
|
|
181
|
+
value: z.ZodNumber;
|
|
182
|
+
color: z.ZodOptional<z.ZodEnum<{
|
|
183
|
+
gray: "gray";
|
|
184
|
+
blue: "blue";
|
|
185
|
+
red: "red";
|
|
186
|
+
amber: "amber";
|
|
187
|
+
green: "green";
|
|
188
|
+
teal: "teal";
|
|
189
|
+
purple: "purple";
|
|
190
|
+
pink: "pink";
|
|
191
|
+
}>>;
|
|
192
|
+
}, z.core.$strip>>;
|
|
193
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
194
|
+
color: z.ZodOptional<z.ZodEnum<{
|
|
195
|
+
gray: "gray";
|
|
196
|
+
blue: "blue";
|
|
197
|
+
red: "red";
|
|
198
|
+
amber: "amber";
|
|
199
|
+
green: "green";
|
|
200
|
+
teal: "teal";
|
|
201
|
+
purple: "purple";
|
|
202
|
+
pink: "pink";
|
|
203
|
+
accent: "accent";
|
|
204
|
+
}>>;
|
|
205
|
+
}, z.core.$strip>;
|
|
206
|
+
description: string;
|
|
207
|
+
};
|
|
208
|
+
Group: {
|
|
209
|
+
props: z.ZodObject<{
|
|
210
|
+
layout: z.ZodEnum<{
|
|
211
|
+
row: "row";
|
|
212
|
+
grid: "grid";
|
|
213
|
+
}>;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
description: string;
|
|
216
|
+
};
|
|
217
|
+
Stack: {
|
|
218
|
+
props: z.ZodObject<{}, z.core.$strip>;
|
|
219
|
+
description: string;
|
|
220
|
+
};
|
|
221
|
+
ActionButton: {
|
|
222
|
+
props: z.ZodObject<{
|
|
223
|
+
label: z.ZodString;
|
|
224
|
+
action: z.ZodEnum<{
|
|
225
|
+
post: "post";
|
|
226
|
+
link: "link";
|
|
227
|
+
mini_app: "mini_app";
|
|
228
|
+
sdk: "sdk";
|
|
229
|
+
}>;
|
|
230
|
+
target: z.ZodString;
|
|
231
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
232
|
+
primary: "primary";
|
|
233
|
+
secondary: "secondary";
|
|
234
|
+
}>>;
|
|
235
|
+
}, z.core.$strip>;
|
|
236
|
+
description: string;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
actions: {
|
|
240
|
+
snap_post: {
|
|
241
|
+
description: string;
|
|
242
|
+
params: z.ZodObject<{
|
|
243
|
+
buttonIndex: z.ZodNumber;
|
|
244
|
+
target: z.ZodString;
|
|
245
|
+
label: z.ZodOptional<z.ZodString>;
|
|
246
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
247
|
+
primary: "primary";
|
|
248
|
+
secondary: "secondary";
|
|
249
|
+
}>>;
|
|
250
|
+
}, z.core.$strip>;
|
|
251
|
+
};
|
|
252
|
+
snap_link: {
|
|
253
|
+
description: string;
|
|
254
|
+
params: z.ZodObject<{
|
|
255
|
+
target: z.ZodString;
|
|
256
|
+
}, z.core.$strip>;
|
|
257
|
+
};
|
|
258
|
+
snap_mini_app: {
|
|
259
|
+
description: string;
|
|
260
|
+
params: z.ZodObject<{
|
|
261
|
+
target: z.ZodString;
|
|
262
|
+
}, z.core.$strip>;
|
|
263
|
+
};
|
|
264
|
+
snap_sdk: {
|
|
265
|
+
description: string;
|
|
266
|
+
params: z.ZodObject<{
|
|
267
|
+
target: z.ZodString;
|
|
268
|
+
}, z.core.$strip>;
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
}>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { defineCatalog } from "@json-render/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { BUTTON_STYLE_VALUES } from "../constants.js";
|
|
4
|
+
import { snapJsonRenderSchema } from "./schema.js";
|
|
5
|
+
import { textProps } from "./text.js";
|
|
6
|
+
import { imageProps } from "./image.js";
|
|
7
|
+
import { dividerProps } from "./divider.js";
|
|
8
|
+
import { spacerProps } from "./spacer.js";
|
|
9
|
+
import { progressProps } from "./progress.js";
|
|
10
|
+
import { listProps } from "./list.js";
|
|
11
|
+
import { gridProps } from "./grid.js";
|
|
12
|
+
import { textInputProps } from "./text-input.js";
|
|
13
|
+
import { sliderProps } from "./slider.js";
|
|
14
|
+
import { buttonGroupProps } from "./button-group.js";
|
|
15
|
+
import { toggleProps } from "./toggle.js";
|
|
16
|
+
import { barChartProps } from "./bar-chart.js";
|
|
17
|
+
import { groupProps } from "./group.js";
|
|
18
|
+
import { stackProps } from "./stack.js";
|
|
19
|
+
import { actionButtonProps } from "./button.js";
|
|
20
|
+
const snapPostParams = z.object({
|
|
21
|
+
buttonIndex: z.number().int().nonnegative(),
|
|
22
|
+
target: z.string(),
|
|
23
|
+
label: z.string().optional(),
|
|
24
|
+
style: z.enum(BUTTON_STYLE_VALUES).optional(),
|
|
25
|
+
});
|
|
26
|
+
const snapTargetParams = z.object({
|
|
27
|
+
target: z.string(),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Basic catalog: one json-render component per snap element type, plus ActionButton for snap buttons.
|
|
31
|
+
* Does not validate cross-field rules (media count, height budget); snap JSON still goes through `@farcaster/snap` validation.
|
|
32
|
+
*/
|
|
33
|
+
export const snapJsonRenderCatalog = defineCatalog(snapJsonRenderSchema, {
|
|
34
|
+
components: {
|
|
35
|
+
Text: {
|
|
36
|
+
props: textProps,
|
|
37
|
+
description: "Snap text block — style: title | body | caption | label; optional align.",
|
|
38
|
+
},
|
|
39
|
+
Image: {
|
|
40
|
+
props: imageProps,
|
|
41
|
+
description: "HTTPS image with fixed aspect ratio.",
|
|
42
|
+
},
|
|
43
|
+
Divider: {
|
|
44
|
+
props: dividerProps,
|
|
45
|
+
description: "Horizontal rule between blocks.",
|
|
46
|
+
},
|
|
47
|
+
Spacer: {
|
|
48
|
+
props: spacerProps,
|
|
49
|
+
description: "Vertical whitespace — size small | medium | large.",
|
|
50
|
+
},
|
|
51
|
+
Progress: {
|
|
52
|
+
props: progressProps,
|
|
53
|
+
description: "Horizontal progress bar (value/max, optional label and color).",
|
|
54
|
+
},
|
|
55
|
+
List: {
|
|
56
|
+
props: listProps,
|
|
57
|
+
description: "Ordered / unordered / plain list; max 4 items per snap spec.",
|
|
58
|
+
},
|
|
59
|
+
Grid: {
|
|
60
|
+
props: gridProps,
|
|
61
|
+
description: "Rows×cols cell grid; optional interactive empty cells for games.",
|
|
62
|
+
},
|
|
63
|
+
TextInput: {
|
|
64
|
+
props: textInputProps,
|
|
65
|
+
description: "Single-line input; `name` becomes POST inputs key.",
|
|
66
|
+
},
|
|
67
|
+
Slider: {
|
|
68
|
+
props: sliderProps,
|
|
69
|
+
description: "Numeric slider; `name` becomes POST inputs key.",
|
|
70
|
+
},
|
|
71
|
+
ButtonGroup: {
|
|
72
|
+
props: buttonGroupProps,
|
|
73
|
+
description: "Exclusive choice; `name` and selected option go into POST inputs.",
|
|
74
|
+
},
|
|
75
|
+
Toggle: {
|
|
76
|
+
props: toggleProps,
|
|
77
|
+
description: "Boolean toggle; `name` becomes POST inputs key.",
|
|
78
|
+
},
|
|
79
|
+
BarChart: {
|
|
80
|
+
props: barChartProps,
|
|
81
|
+
description: "Vertical bar chart for labeled values — poll results, rankings, breakdowns.",
|
|
82
|
+
},
|
|
83
|
+
Group: {
|
|
84
|
+
props: groupProps,
|
|
85
|
+
description: "Button row (`layout: row`) or 2-column grid (`layout: grid`); use `children` element ids only (no nested JSON objects).",
|
|
86
|
+
},
|
|
87
|
+
Stack: {
|
|
88
|
+
props: stackProps,
|
|
89
|
+
description: "Vertical stack for snap page body; maps from snap `page.elements` (`type: stack`). Children are element ids in order top to bottom.",
|
|
90
|
+
},
|
|
91
|
+
ActionButton: {
|
|
92
|
+
props: actionButtonProps,
|
|
93
|
+
description: "Snap action button: post (next page), link (browser), mini_app, sdk — target is HTTPS URL or SDK id.",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
actions: {
|
|
97
|
+
snap_post: {
|
|
98
|
+
description: "POST to snap `target` with signed body (fid, inputs, button_index, timestamp, signature); response is next snap page JSON.",
|
|
99
|
+
params: snapPostParams,
|
|
100
|
+
},
|
|
101
|
+
snap_link: {
|
|
102
|
+
description: "Open `target` in the system browser; no server round-trip.",
|
|
103
|
+
params: snapTargetParams,
|
|
104
|
+
},
|
|
105
|
+
snap_mini_app: {
|
|
106
|
+
description: "Open `target` as an in-app Farcaster mini app.",
|
|
107
|
+
params: snapTargetParams,
|
|
108
|
+
},
|
|
109
|
+
snap_sdk: {
|
|
110
|
+
description: "Run a Farcaster client SDK action (cast:view, user:follow, …).",
|
|
111
|
+
params: snapTargetParams,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const gridProps: z.ZodObject<{
|
|
3
|
+
cols: z.ZodNumber;
|
|
4
|
+
rows: z.ZodNumber;
|
|
5
|
+
cells: z.ZodArray<z.ZodObject<{
|
|
6
|
+
row: z.ZodNumber;
|
|
7
|
+
col: z.ZodNumber;
|
|
8
|
+
color: z.ZodOptional<z.ZodString>;
|
|
9
|
+
content: z.ZodOptional<z.ZodString>;
|
|
10
|
+
}, z.core.$strip>>;
|
|
11
|
+
cellSize: z.ZodOptional<z.ZodEnum<{
|
|
12
|
+
auto: "auto";
|
|
13
|
+
square: "square";
|
|
14
|
+
}>>;
|
|
15
|
+
gap: z.ZodOptional<z.ZodEnum<{
|
|
16
|
+
small: "small";
|
|
17
|
+
medium: "medium";
|
|
18
|
+
none: "none";
|
|
19
|
+
}>>;
|
|
20
|
+
interactive: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type GridProps = z.infer<typeof gridProps>;
|
package/dist/ui/grid.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { GRID_CELL_SIZE_VALUES, GRID_GAP_VALUES, HEX_COLOR_6_RE, LIMITS, } from "../constants.js";
|
|
3
|
+
const gridCellZ = z.object({
|
|
4
|
+
row: z.number().int().nonnegative(),
|
|
5
|
+
col: z.number().int().nonnegative(),
|
|
6
|
+
color: z.string().regex(HEX_COLOR_6_RE).optional(),
|
|
7
|
+
content: z.string().optional(),
|
|
8
|
+
});
|
|
9
|
+
export const gridProps = z.object({
|
|
10
|
+
cols: z.number().int().min(LIMITS.minGridCols).max(LIMITS.maxGridCols),
|
|
11
|
+
rows: z.number().int().min(LIMITS.minGridRows).max(LIMITS.maxGridRows),
|
|
12
|
+
cells: z.array(gridCellZ),
|
|
13
|
+
cellSize: z.enum(GRID_CELL_SIZE_VALUES).optional(),
|
|
14
|
+
gap: z.enum(GRID_GAP_VALUES).optional(),
|
|
15
|
+
interactive: z.boolean().optional(),
|
|
16
|
+
});
|
package/dist/ui/group.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const imageProps: z.ZodObject<{
|
|
3
|
+
url: z.ZodString;
|
|
4
|
+
aspect: z.ZodEnum<{
|
|
5
|
+
"1:1": "1:1";
|
|
6
|
+
"16:9": "16:9";
|
|
7
|
+
"4:3": "4:3";
|
|
8
|
+
"3:4": "3:4";
|
|
9
|
+
"9:16": "9:16";
|
|
10
|
+
}>;
|
|
11
|
+
alt: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export type ImageProps = z.infer<typeof imageProps>;
|