@farcaster/snap-hono 1.1.8 → 1.2.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 +3 -3
- package/dist/index.js +3 -3
- package/dist/payloadToResponse.d.ts +2 -2
- package/dist/payloadToResponse.js +3 -3
- package/dist/renderSnapPage.d.ts +2 -2
- package/package.json +2 -2
- package/src/index.ts +3 -3
- package/src/payloadToResponse.ts +6 -6
- package/src/renderSnapPage.ts +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -20,12 +20,12 @@ export type SnapHandlerOptions = {
|
|
|
20
20
|
/**
|
|
21
21
|
* Register GET and POST snap handlers on `app` at `options.path` (default `/`).
|
|
22
22
|
*
|
|
23
|
-
* - GET → calls `snapFn(
|
|
23
|
+
* - GET → calls `snapFn(ctx)` with `ctx.action.type === "get"` and returns the response.
|
|
24
24
|
* - POST → parses the JFS-shaped JSON body; verifies it via {@link verifyJFSRequestBody} unless
|
|
25
|
-
* `skipJFSVerification` is true, then calls `snapFn(
|
|
25
|
+
* `skipJFSVerification` is true, then calls `snapFn(ctx)` with the parsed post action and returns the response.
|
|
26
26
|
*
|
|
27
27
|
* All parsing, schema validation, signature verification, and error responses
|
|
28
|
-
* are handled automatically. `
|
|
28
|
+
* are handled automatically. `ctx.request` is the raw `Request` so handlers
|
|
29
29
|
* can read query params, headers, or the URL when needed.
|
|
30
30
|
*/
|
|
31
31
|
export declare function registerSnapHandler(app: Hono, snapFn: SnapFunction, options?: SnapHandlerOptions): void;
|
package/dist/index.js
CHANGED
|
@@ -6,12 +6,12 @@ import { renderSnapPage } from "./renderSnapPage.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Register GET and POST snap handlers on `app` at `options.path` (default `/`).
|
|
8
8
|
*
|
|
9
|
-
* - GET → calls `snapFn(
|
|
9
|
+
* - GET → calls `snapFn(ctx)` with `ctx.action.type === "get"` and returns the response.
|
|
10
10
|
* - POST → parses the JFS-shaped JSON body; verifies it via {@link verifyJFSRequestBody} unless
|
|
11
|
-
* `skipJFSVerification` is true, then calls `snapFn(
|
|
11
|
+
* `skipJFSVerification` is true, then calls `snapFn(ctx)` with the parsed post action and returns the response.
|
|
12
12
|
*
|
|
13
13
|
* All parsing, schema validation, signature verification, and error responses
|
|
14
|
-
* are handled automatically. `
|
|
14
|
+
* are handled automatically. `ctx.request` is the raw `Request` so handlers
|
|
15
15
|
* can read query params, headers, or the URL when needed.
|
|
16
16
|
*/
|
|
17
17
|
export function registerSnapHandler(app, snapFn, options = {}) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SnapHandlerResult } from "@farcaster/snap";
|
|
2
2
|
type PayloadToResponseOptions = {
|
|
3
3
|
resourcePath: string;
|
|
4
4
|
mediaTypes: string[];
|
|
5
5
|
};
|
|
6
|
-
export declare function payloadToResponse(payload:
|
|
6
|
+
export declare function payloadToResponse(payload: SnapHandlerResult, options?: Partial<PayloadToResponseOptions>): Response;
|
|
7
7
|
export declare function snapHeaders(resourcePath: string, currentMediaType: string, availableMediaTypes: string[]): {
|
|
8
8
|
"Content-Type": string;
|
|
9
9
|
Vary: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MEDIA_TYPE,
|
|
1
|
+
import { MEDIA_TYPE, validateSnapResponse, snapResponseSchema, } from "@farcaster/snap";
|
|
2
2
|
const DEFAULT_LINK_MEDIA_TYPES = [MEDIA_TYPE, "text/html"];
|
|
3
3
|
export function payloadToResponse(payload, options = {}) {
|
|
4
4
|
const resourcePath = options.resourcePath ?? "/";
|
|
5
5
|
const mediaTypes = options.mediaTypes ?? [...DEFAULT_LINK_MEDIA_TYPES];
|
|
6
|
-
const validation =
|
|
6
|
+
const validation = validateSnapResponse(payload);
|
|
7
7
|
if (!validation.valid) {
|
|
8
8
|
return new Response(JSON.stringify({
|
|
9
9
|
error: "invalid snap page",
|
|
@@ -15,7 +15,7 @@ export function payloadToResponse(payload, options = {}) {
|
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
const finalized =
|
|
18
|
+
const finalized = snapResponseSchema.parse(payload);
|
|
19
19
|
return new Response(JSON.stringify(finalized), {
|
|
20
20
|
status: 200,
|
|
21
21
|
headers: {
|
package/dist/renderSnapPage.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function renderSnapPage(snap:
|
|
1
|
+
import type { SnapHandlerResult } from "@farcaster/snap";
|
|
2
|
+
export declare function renderSnapPage(snap: SnapHandlerResult, snapOrigin: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farcaster/snap-hono",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Hono integration for Farcaster Snap servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@farcaster/snap": "1.
|
|
29
|
+
"@farcaster/snap": "1.4.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"hono": ">=4.0.0"
|
package/src/index.ts
CHANGED
|
@@ -28,12 +28,12 @@ export type SnapHandlerOptions = {
|
|
|
28
28
|
/**
|
|
29
29
|
* Register GET and POST snap handlers on `app` at `options.path` (default `/`).
|
|
30
30
|
*
|
|
31
|
-
* - GET → calls `snapFn(
|
|
31
|
+
* - GET → calls `snapFn(ctx)` with `ctx.action.type === "get"` and returns the response.
|
|
32
32
|
* - POST → parses the JFS-shaped JSON body; verifies it via {@link verifyJFSRequestBody} unless
|
|
33
|
-
* `skipJFSVerification` is true, then calls `snapFn(
|
|
33
|
+
* `skipJFSVerification` is true, then calls `snapFn(ctx)` with the parsed post action and returns the response.
|
|
34
34
|
*
|
|
35
35
|
* All parsing, schema validation, signature verification, and error responses
|
|
36
|
-
* are handled automatically. `
|
|
36
|
+
* are handled automatically. `ctx.request` is the raw `Request` so handlers
|
|
37
37
|
* can read query params, headers, or the URL when needed.
|
|
38
38
|
*/
|
|
39
39
|
export function registerSnapHandler(
|
package/src/payloadToResponse.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MEDIA_TYPE,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type SnapHandlerResult,
|
|
4
|
+
validateSnapResponse,
|
|
5
|
+
snapResponseSchema,
|
|
6
6
|
} from "@farcaster/snap";
|
|
7
7
|
|
|
8
8
|
type PayloadToResponseOptions = {
|
|
@@ -13,13 +13,13 @@ type PayloadToResponseOptions = {
|
|
|
13
13
|
const DEFAULT_LINK_MEDIA_TYPES = [MEDIA_TYPE, "text/html"] as const;
|
|
14
14
|
|
|
15
15
|
export function payloadToResponse(
|
|
16
|
-
payload:
|
|
16
|
+
payload: SnapHandlerResult,
|
|
17
17
|
options: Partial<PayloadToResponseOptions> = {},
|
|
18
18
|
): Response {
|
|
19
19
|
const resourcePath = options.resourcePath ?? "/";
|
|
20
20
|
const mediaTypes = options.mediaTypes ?? [...DEFAULT_LINK_MEDIA_TYPES];
|
|
21
21
|
|
|
22
|
-
const validation =
|
|
22
|
+
const validation = validateSnapResponse(payload);
|
|
23
23
|
if (!validation.valid) {
|
|
24
24
|
return new Response(
|
|
25
25
|
JSON.stringify({
|
|
@@ -35,7 +35,7 @@ export function payloadToResponse(
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const finalized =
|
|
38
|
+
const finalized = snapResponseSchema.parse(payload);
|
|
39
39
|
return new Response(JSON.stringify(finalized), {
|
|
40
40
|
status: 200,
|
|
41
41
|
headers: {
|
package/src/renderSnapPage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SnapHandlerResult } from "@farcaster/snap";
|
|
2
2
|
|
|
3
3
|
const PALETTE: Record<string, string> = {
|
|
4
4
|
gray: "#8F8F8F",
|
|
@@ -307,7 +307,10 @@ function renderButtons(
|
|
|
307
307
|
|
|
308
308
|
// ─── Main renderer ──────────────────────────────────────
|
|
309
309
|
|
|
310
|
-
export function renderSnapPage(
|
|
310
|
+
export function renderSnapPage(
|
|
311
|
+
snap: SnapHandlerResult,
|
|
312
|
+
snapOrigin: string,
|
|
313
|
+
): string {
|
|
311
314
|
const page = snap.page;
|
|
312
315
|
const accent = accentHex(page.theme?.accent);
|
|
313
316
|
|