@farcaster/snap 1.3.1 → 1.3.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.
Files changed (64) hide show
  1. package/dist/schemas.d.ts +1 -1
  2. package/dist/schemas.js +1 -1
  3. package/dist/server/parseRequest.d.ts +1 -1
  4. package/dist/server/parseRequest.js +1 -1
  5. package/dist/ui/bar-chart.d.ts +30 -0
  6. package/dist/ui/bar-chart.js +14 -0
  7. package/dist/ui/button-group.d.ts +11 -0
  8. package/dist/ui/button-group.js +10 -0
  9. package/dist/ui/button.d.ts +32 -0
  10. package/dist/ui/button.js +10 -0
  11. package/dist/ui/catalog.d.ts +271 -0
  12. package/dist/ui/catalog.js +114 -0
  13. package/dist/ui/divider.d.ts +3 -0
  14. package/dist/ui/divider.js +2 -0
  15. package/dist/ui/grid.d.ts +22 -0
  16. package/dist/ui/grid.js +16 -0
  17. package/dist/ui/group.d.ts +8 -0
  18. package/dist/ui/group.js +4 -0
  19. package/dist/ui/image.d.ts +13 -0
  20. package/dist/ui/image.js +7 -0
  21. package/dist/ui/index.d.ts +32 -0
  22. package/dist/ui/index.js +17 -0
  23. package/dist/ui/list.d.ts +13 -0
  24. package/dist/ui/list.js +13 -0
  25. package/dist/ui/progress.d.ts +18 -0
  26. package/dist/ui/progress.js +8 -0
  27. package/dist/ui/schema.d.ts +32 -0
  28. package/dist/ui/schema.js +31 -0
  29. package/dist/ui/slider.d.ts +12 -0
  30. package/dist/ui/slider.js +11 -0
  31. package/dist/ui/spacer.d.ts +9 -0
  32. package/dist/ui/spacer.js +5 -0
  33. package/dist/ui/stack.d.ts +3 -0
  34. package/dist/ui/stack.js +2 -0
  35. package/dist/ui/text-input.d.ts +7 -0
  36. package/dist/ui/text-input.js +12 -0
  37. package/dist/ui/text.d.ts +16 -0
  38. package/dist/ui/text.js +7 -0
  39. package/dist/ui/toggle.d.ts +7 -0
  40. package/dist/ui/toggle.js +6 -0
  41. package/dist/validator.d.ts +1 -1
  42. package/package.json +83 -2
  43. package/src/schemas.ts +1 -1
  44. package/src/server/parseRequest.ts +1 -1
  45. package/src/ui/README.md +50 -0
  46. package/src/ui/bar-chart.ts +23 -0
  47. package/src/ui/button-group.ts +13 -0
  48. package/src/ui/button.ts +15 -0
  49. package/src/ui/catalog.ts +128 -0
  50. package/src/ui/divider.ts +5 -0
  51. package/src/ui/grid.ts +25 -0
  52. package/src/ui/group.ts +7 -0
  53. package/src/ui/image.ts +10 -0
  54. package/src/ui/index.ts +47 -0
  55. package/src/ui/list.ts +17 -0
  56. package/src/ui/progress.ts +11 -0
  57. package/src/ui/schema.ts +37 -0
  58. package/src/ui/slider.ts +14 -0
  59. package/src/ui/spacer.ts +8 -0
  60. package/src/ui/stack.ts +5 -0
  61. package/src/ui/text-input.ts +15 -0
  62. package/src/ui/text.ts +10 -0
  63. package/src/ui/toggle.ts +9 -0
  64. package/src/validator.ts +1 -1
@@ -0,0 +1,47 @@
1
+ export { snapJsonRenderSchema } from "./schema.js";
2
+ export { snapJsonRenderCatalog } from "./catalog.js";
3
+
4
+ export { textProps } from "./text.js";
5
+ export type { TextProps } from "./text.js";
6
+
7
+ export { imageProps } from "./image.js";
8
+ export type { ImageProps } from "./image.js";
9
+
10
+ export { dividerProps } from "./divider.js";
11
+ export type { DividerProps } from "./divider.js";
12
+
13
+ export { spacerProps } from "./spacer.js";
14
+ export type { SpacerProps } from "./spacer.js";
15
+
16
+ export { progressProps } from "./progress.js";
17
+ export type { ProgressProps } from "./progress.js";
18
+
19
+ export { listProps } from "./list.js";
20
+ export type { ListProps } from "./list.js";
21
+
22
+ export { gridProps } from "./grid.js";
23
+ export type { GridProps } from "./grid.js";
24
+
25
+ export { textInputProps } from "./text-input.js";
26
+ export type { TextInputProps } from "./text-input.js";
27
+
28
+ export { sliderProps } from "./slider.js";
29
+ export type { SliderProps } from "./slider.js";
30
+
31
+ export { buttonGroupProps } from "./button-group.js";
32
+ export type { ButtonGroupProps } from "./button-group.js";
33
+
34
+ export { toggleProps } from "./toggle.js";
35
+ export type { ToggleProps } from "./toggle.js";
36
+
37
+ export { barChartProps } from "./bar-chart.js";
38
+ export type { BarChartProps } from "./bar-chart.js";
39
+
40
+ export { groupProps } from "./group.js";
41
+ export type { GroupProps } from "./group.js";
42
+
43
+ export { stackProps } from "./stack.js";
44
+ export type { StackProps } from "./stack.js";
45
+
46
+ export { actionButtonProps, buttonProps } from "./button.js";
47
+ export type { ActionButtonProps, ButtonProps } from "./button.js";
package/src/ui/list.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ import { LIMITS, LIST_STYLE_VALUES } from "../constants.js";
3
+
4
+ const listItemZ = z.object({
5
+ content: z.string(),
6
+ trailing: z.string().optional(),
7
+ });
8
+
9
+ export const listProps = z.object({
10
+ style: z.enum(LIST_STYLE_VALUES).optional(),
11
+ items: z
12
+ .array(listItemZ)
13
+ .min(LIMITS.minListItems)
14
+ .max(LIMITS.maxListItems),
15
+ });
16
+
17
+ export type ListProps = z.infer<typeof listProps>;
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ import { PROGRESS_COLOR_VALUES } from "../constants.js";
3
+
4
+ export const progressProps = z.object({
5
+ value: z.number(),
6
+ max: z.number(),
7
+ label: z.string().optional(),
8
+ color: z.enum(PROGRESS_COLOR_VALUES).optional(),
9
+ });
10
+
11
+ export type ProgressProps = z.infer<typeof progressProps>;
@@ -0,0 +1,37 @@
1
+ import { defineSchema } from "@json-render/core";
2
+
3
+ /**
4
+ * json-render spec shape: flat `root` + `elements` map (see [json-render](https://json-render.dev/)).
5
+ * Component `type` strings must match keys in {@link ./catalog.ts}.
6
+ */
7
+ export const snapJsonRenderSchema = defineSchema(
8
+ (s) => ({
9
+ spec: s.object({
10
+ root: s.string(),
11
+ elements: s.record(
12
+ s.object({
13
+ type: s.ref("catalog.components"),
14
+ props: s.propsOf("catalog.components"),
15
+ children: { ...s.array(s.string()), optional: true },
16
+ }),
17
+ ),
18
+ }),
19
+ catalog: s.object({
20
+ components: s.map({
21
+ props: s.zod(),
22
+ description: s.string(),
23
+ }),
24
+ actions: s.map({
25
+ description: s.string(),
26
+ params: { ...s.zod(), optional: true },
27
+ }),
28
+ }),
29
+ }),
30
+ {
31
+ defaultRules: [
32
+ "You are generating auxiliary UI for a Farcaster Snap. Prefer components matching snap element types (Text, Image, ButtonGroup, …).",
33
+ "Snap pages use a Stack root with at most 5 body children and 1 media element (Image or Grid); keep generated trees small.",
34
+ "Bottom-of-card snap buttons are ActionButton components; use actions post / link / mini_app / sdk per SPEC.md.",
35
+ ],
36
+ },
37
+ );
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+
3
+ export const sliderProps = z.object({
4
+ name: z.string().min(1),
5
+ min: z.number(),
6
+ max: z.number(),
7
+ step: z.number().optional(),
8
+ value: z.number().optional(),
9
+ label: z.string().optional(),
10
+ minLabel: z.string().optional(),
11
+ maxLabel: z.string().optional(),
12
+ });
13
+
14
+ export type SliderProps = z.infer<typeof sliderProps>;
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ import { SPACER_SIZE_VALUES } from "../constants.js";
3
+
4
+ export const spacerProps = z.object({
5
+ size: z.enum(SPACER_SIZE_VALUES).optional(),
6
+ });
7
+
8
+ export type SpacerProps = z.infer<typeof spacerProps>;
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+
3
+ export const stackProps = z.object({});
4
+
5
+ export type StackProps = z.infer<typeof stackProps>;
@@ -0,0 +1,15 @@
1
+ import { z } from "zod";
2
+ import { LIMITS } from "../constants.js";
3
+
4
+ export const textInputProps = z.object({
5
+ name: z.string().min(1),
6
+ placeholder: z.string().optional(),
7
+ maxLength: z
8
+ .number()
9
+ .int()
10
+ .positive()
11
+ .max(LIMITS.maxTextInputChars)
12
+ .optional(),
13
+ });
14
+
15
+ export type TextInputProps = z.infer<typeof textInputProps>;
package/src/ui/text.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ import { TEXT_ALIGN_VALUES, TEXT_STYLE_VALUES } from "../constants.js";
3
+
4
+ export const textProps = z.object({
5
+ style: z.enum(TEXT_STYLE_VALUES),
6
+ content: z.string(),
7
+ align: z.enum(TEXT_ALIGN_VALUES).optional(),
8
+ });
9
+
10
+ export type TextProps = z.infer<typeof textProps>;
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+
3
+ export const toggleProps = z.object({
4
+ name: z.string().min(1),
5
+ label: z.string(),
6
+ value: z.boolean().optional(),
7
+ });
8
+
9
+ export type ToggleProps = z.infer<typeof toggleProps>;
package/src/validator.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from "zod/v4";
1
+ import { z } from "zod";
2
2
  import {
3
3
  BUTTON_GROUP_STYLE,
4
4
  DEFAULT_BUTTON_LAYOUT,