@farcaster/snap 1.9.0 → 1.10.0

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 CHANGED
@@ -1,7 +1,6 @@
1
- export type { Spec as SnapSpec, UIElement as SnapUIElement } from "@json-render/core";
2
- export { SPEC_VERSION, MEDIA_TYPE, EFFECT_VALUES, } from "./constants.js";
1
+ export type { Spec as SnapSpec, UIElement as SnapUIElement, } from "@json-render/core";
2
+ export { SPEC_VERSION, MEDIA_TYPE, EFFECT_VALUES } from "./constants.js";
3
3
  export { DEFAULT_THEME_ACCENT, PALETTE_COLOR, PALETTE_COLOR_ACCENT, PALETTE_COLOR_VALUES, PALETTE_LIGHT_HEX, PALETTE_DARK_HEX, type PaletteColor, } from "./colors.js";
4
- export { ACTION_TYPE_GET, ACTION_TYPE_POST, snapResponseSchema, payloadSchema, type SnapAction, type SnapContext, type SnapResponse, type SnapHandlerResult, type SnapFunction, type SnapPayload, } from "./schemas.js";
5
- export { validateSnapResponse, type ValidationResult, } from "./validator.js";
6
- export { type DataStoreValue, type SnapDataStore, createDefaultDataStore, createInMemoryDataStore, } from "./dataStore.js";
4
+ export { ACTION_TYPE_GET, ACTION_TYPE_POST, snapResponseSchema, payloadSchema, type SnapAction, type SnapContext, type SnapResponse, type SnapHandlerResult, type SnapElementInput, type SnapSpecInput, type SnapFunction, type SnapPayload, } from "./schemas.js";
5
+ export { validateSnapResponse, type ValidationResult } from "./validator.js";
7
6
  export { type Middleware, useMiddleware } from "./middleware.js";
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
- export { SPEC_VERSION, MEDIA_TYPE, EFFECT_VALUES, } from "./constants.js";
1
+ export { SPEC_VERSION, MEDIA_TYPE, EFFECT_VALUES } from "./constants.js";
2
2
  export { DEFAULT_THEME_ACCENT, PALETTE_COLOR, PALETTE_COLOR_ACCENT, PALETTE_COLOR_VALUES, PALETTE_LIGHT_HEX, PALETTE_DARK_HEX, } from "./colors.js";
3
3
  export { ACTION_TYPE_GET, ACTION_TYPE_POST, snapResponseSchema, payloadSchema, } from "./schemas.js";
4
- export { validateSnapResponse, } from "./validator.js";
5
- export { createDefaultDataStore, createInMemoryDataStore, } from "./dataStore.js";
4
+ export { validateSnapResponse } from "./validator.js";
6
5
  export { useMiddleware } from "./middleware.js";
package/dist/schemas.d.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  import { z } from "zod";
2
2
  import type { Spec } from "@json-render/core";
3
- import { type SnapDataStore } from "./dataStore.js";
3
+ import { SPEC_VERSION } from "./constants.js";
4
+ declare const themeAccentSchema: z.ZodEnum<{
5
+ gray: "gray";
6
+ blue: "blue";
7
+ red: "red";
8
+ amber: "amber";
9
+ green: "green";
10
+ teal: "teal";
11
+ purple: "purple";
12
+ pink: "pink";
13
+ }>;
4
14
  export declare const snapResponseSchema: z.ZodObject<{
5
15
  version: z.ZodLiteral<"1.0">;
6
16
  theme: z.ZodDefault<z.ZodOptional<z.ZodObject<{
@@ -21,7 +31,40 @@ export declare const snapResponseSchema: z.ZodObject<{
21
31
  ui: z.ZodCustom<Spec, Spec>;
22
32
  }, z.core.$strict>;
23
33
  export type SnapResponse = z.infer<typeof snapResponseSchema>;
24
- export type SnapHandlerResult = z.input<typeof snapResponseSchema>;
34
+ /**
35
+ * Permissive element input type for snap handler authors.
36
+ * Allows dynamic element construction without requiring exact UIElement types.
37
+ */
38
+ export type SnapElementInput = {
39
+ type: string;
40
+ props?: Record<string, unknown>;
41
+ children?: string[];
42
+ on?: Record<string, unknown>;
43
+ [key: string]: unknown;
44
+ };
45
+ /**
46
+ * Permissive input type for the `ui` field in snap handler return values.
47
+ * Accepts dynamically-built element maps (e.g. `Record<string, SnapElementInput>`)
48
+ * without requiring exact UIElement types.
49
+ */
50
+ export type SnapSpecInput = {
51
+ root: string;
52
+ elements: Record<string, SnapElementInput>;
53
+ state?: Record<string, unknown>;
54
+ };
55
+ /**
56
+ * Return type for snap handler functions.
57
+ * Uses permissive input types so handlers can build elements dynamically
58
+ * without type casts. Runtime validation via the Zod schema still catches invalid shapes.
59
+ */
60
+ export type SnapHandlerResult = {
61
+ version: typeof SPEC_VERSION;
62
+ theme?: {
63
+ accent?: z.input<typeof themeAccentSchema>;
64
+ };
65
+ effects?: z.input<typeof snapResponseSchema>["effects"];
66
+ ui: SnapSpecInput;
67
+ };
25
68
  export declare const payloadSchema: z.ZodObject<{
26
69
  fid: z.ZodNumber;
27
70
  inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
@@ -56,7 +99,6 @@ export type SnapAction = z.infer<typeof snapActionSchema>;
56
99
  export type SnapContext = {
57
100
  action: SnapAction;
58
101
  request: Request;
59
- data: SnapDataStore;
60
102
  };
61
103
  export type SnapFunction = (ctx: SnapContext) => Promise<SnapHandlerResult>;
62
104
  export {};
package/dist/schemas.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- import { EFFECT_VALUES, SPEC_VERSION, } from "./constants.js";
3
- import { DEFAULT_THEME_ACCENT, PALETTE_COLOR_VALUES, } from "./colors.js";
2
+ import { EFFECT_VALUES, SPEC_VERSION } from "./constants.js";
3
+ import { DEFAULT_THEME_ACCENT, PALETTE_COLOR_VALUES } from "./colors.js";
4
4
  // ─── Theme ─────────────────────────────────────────────
5
5
  const themeAccentSchema = z.enum(PALETTE_COLOR_VALUES, {
6
6
  message: `accent must be a palette color: ${PALETTE_COLOR_VALUES.join(", ")}`,
package/llms.txt CHANGED
@@ -158,14 +158,14 @@ Plus the special value `"accent"` which references `theme.accent`.
158
158
  ```ts
159
159
  import { snapJsonRenderCatalog } from "@farcaster/snap/ui";
160
160
  import { parseRequest, verifyJFSRequestBody } from "@farcaster/snap/server";
161
- import { createInMemoryDataStore } from "@farcaster/snap";
161
+ import { withTursoServerless, createInMemoryDataStore } from "@farcaster/snap-turso";
162
162
  ```
163
163
 
164
- - `@farcaster/snap` — schemas, types, validation, data store
164
+ - `@farcaster/snap` — schemas, types, validation
165
165
  - `@farcaster/snap/ui` — json-render catalog, component schemas
166
166
  - `@farcaster/snap/server` — request parsing, JFS verification
167
167
  - `@farcaster/snap-hono` — Hono adapter (`registerSnapHandler`)
168
- - `@farcaster/snap-turso` — Turso data store middleware
168
+ - `@farcaster/snap-turso` — `withTursoServerless`, `DataStore` / `DataStoreValue`, in-memory and Turso helpers
169
169
 
170
170
  ## Full Documentation
171
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/snap",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Farcaster Snaps 🫰",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
- export type { Spec as SnapSpec, UIElement as SnapUIElement } from "@json-render/core";
2
- export {
3
- SPEC_VERSION,
4
- MEDIA_TYPE,
5
- EFFECT_VALUES,
6
- } from "./constants";
1
+ export type {
2
+ Spec as SnapSpec,
3
+ UIElement as SnapUIElement,
4
+ } from "@json-render/core";
5
+ export { SPEC_VERSION, MEDIA_TYPE, EFFECT_VALUES } from "./constants";
7
6
  export {
8
7
  DEFAULT_THEME_ACCENT,
9
8
  PALETTE_COLOR,
@@ -22,17 +21,10 @@ export {
22
21
  type SnapContext,
23
22
  type SnapResponse,
24
23
  type SnapHandlerResult,
24
+ type SnapElementInput,
25
+ type SnapSpecInput,
25
26
  type SnapFunction,
26
27
  type SnapPayload,
27
28
  } from "./schemas";
28
- export {
29
- validateSnapResponse,
30
- type ValidationResult,
31
- } from "./validator";
32
- export {
33
- type DataStoreValue,
34
- type SnapDataStore,
35
- createDefaultDataStore,
36
- createInMemoryDataStore,
37
- } from "./dataStore";
29
+ export { validateSnapResponse, type ValidationResult } from "./validator";
38
30
  export { type Middleware, useMiddleware } from "./middleware";
package/src/schemas.ts CHANGED
@@ -1,14 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import type { Spec } from "@json-render/core";
3
- import {
4
- EFFECT_VALUES,
5
- SPEC_VERSION,
6
- } from "./constants";
7
- import {
8
- DEFAULT_THEME_ACCENT,
9
- PALETTE_COLOR_VALUES,
10
- } from "./colors";
11
- import { type SnapDataStore } from "./dataStore";
3
+ import { EFFECT_VALUES, SPEC_VERSION } from "./constants";
4
+ import { DEFAULT_THEME_ACCENT, PALETTE_COLOR_VALUES } from "./colors";
12
5
 
13
6
  // ─── Theme ─────────────────────────────────────────────
14
7
 
@@ -43,7 +36,41 @@ export const snapResponseSchema = z
43
36
  .strict();
44
37
 
45
38
  export type SnapResponse = z.infer<typeof snapResponseSchema>;
46
- export type SnapHandlerResult = z.input<typeof snapResponseSchema>;
39
+
40
+ /**
41
+ * Permissive element input type for snap handler authors.
42
+ * Allows dynamic element construction without requiring exact UIElement types.
43
+ */
44
+ export type SnapElementInput = {
45
+ type: string;
46
+ props?: Record<string, unknown>;
47
+ children?: string[];
48
+ on?: Record<string, unknown>;
49
+ [key: string]: unknown;
50
+ };
51
+
52
+ /**
53
+ * Permissive input type for the `ui` field in snap handler return values.
54
+ * Accepts dynamically-built element maps (e.g. `Record<string, SnapElementInput>`)
55
+ * without requiring exact UIElement types.
56
+ */
57
+ export type SnapSpecInput = {
58
+ root: string;
59
+ elements: Record<string, SnapElementInput>;
60
+ state?: Record<string, unknown>;
61
+ };
62
+
63
+ /**
64
+ * Return type for snap handler functions.
65
+ * Uses permissive input types so handlers can build elements dynamically
66
+ * without type casts. Runtime validation via the Zod schema still catches invalid shapes.
67
+ */
68
+ export type SnapHandlerResult = {
69
+ version: typeof SPEC_VERSION;
70
+ theme?: { accent?: z.input<typeof themeAccentSchema> };
71
+ effects?: z.input<typeof snapResponseSchema>["effects"];
72
+ ui: SnapSpecInput;
73
+ };
47
74
 
48
75
  // ─── POST payload ──────────────────────────────────────
49
76
 
@@ -92,7 +119,6 @@ export type SnapAction = z.infer<typeof snapActionSchema>;
92
119
  export type SnapContext = {
93
120
  action: SnapAction;
94
121
  request: Request;
95
- data: SnapDataStore;
96
122
  };
97
123
 
98
124
  export type SnapFunction = (ctx: SnapContext) => Promise<SnapHandlerResult>;
@@ -1,9 +0,0 @@
1
- export type DataStoreValue = string | number | boolean | null | DataStoreValue[] | {
2
- [key: string]: DataStoreValue;
3
- };
4
- export type SnapDataStore = {
5
- get(key: string): Promise<DataStoreValue | null>;
6
- set(key: string, value: DataStoreValue): Promise<void>;
7
- };
8
- export declare function createDefaultDataStore(): SnapDataStore;
9
- export declare function createInMemoryDataStore(): SnapDataStore;
package/dist/dataStore.js DELETED
@@ -1,22 +0,0 @@
1
- export function createDefaultDataStore() {
2
- const err = new Error("Data store is not configured. Use withTursoServerless() from @farcaster/snap-turso or provide a data store implementation.");
3
- return {
4
- get(_key) {
5
- return Promise.reject(err);
6
- },
7
- set(_key, _value) {
8
- return Promise.reject(err);
9
- },
10
- };
11
- }
12
- export function createInMemoryDataStore() {
13
- const data = new Map();
14
- return {
15
- async get(key) {
16
- return data.get(key) ?? null;
17
- },
18
- async set(key, value) {
19
- data.set(key, value);
20
- },
21
- };
22
- }
package/src/dataStore.ts DELETED
@@ -1,38 +0,0 @@
1
- export type DataStoreValue =
2
- | string
3
- | number
4
- | boolean
5
- | null
6
- | DataStoreValue[]
7
- | { [key: string]: DataStoreValue };
8
-
9
- export type SnapDataStore = {
10
- get(key: string): Promise<DataStoreValue | null>;
11
- set(key: string, value: DataStoreValue): Promise<void>;
12
- };
13
-
14
- export function createDefaultDataStore(): SnapDataStore {
15
- const err = new Error(
16
- "Data store is not configured. Use withTursoServerless() from @farcaster/snap-turso or provide a data store implementation.",
17
- );
18
- return {
19
- get(_key: string): Promise<never> {
20
- return Promise.reject(err);
21
- },
22
- set(_key: string, _value: DataStoreValue): Promise<never> {
23
- return Promise.reject(err);
24
- },
25
- };
26
- }
27
-
28
- export function createInMemoryDataStore(): SnapDataStore {
29
- const data = new Map<string, DataStoreValue>();
30
- return {
31
- async get(key: string): Promise<DataStoreValue | null> {
32
- return data.get(key) ?? null;
33
- },
34
- async set(key: string, value: DataStoreValue): Promise<void> {
35
- data.set(key, value);
36
- },
37
- };
38
- }