Skip to content

Commit c0e4055

Browse files
feat: parse all specs at once
1 parent bd4f30f commit c0e4055

File tree

4 files changed

+51
-39
lines changed

4 files changed

+51
-39
lines changed

packages/frames.js/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@
267267
"default": "./dist/hono/index.cjs"
268268
}
269269
},
270+
"./parseFramesWithReports": {
271+
"import": {
272+
"types": "./dist/parseFramesWithReports.d.ts",
273+
"default": "./dist/parseFramesWithReports.js"
274+
},
275+
"require": {
276+
"types": "./dist/parseFramesWithReports.d.cts",
277+
"default": "./dist/parseFramesWithReports.cjs"
278+
}
279+
},
270280
"./remix": {
271281
"import": {
272282
"types": "./dist/remix/index.d.ts",

packages/frames.js/src/frame-parsers/types.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ export type ParseResult =
6060
*/
6161
reports: Record<string, ParsingReport[]>;
6262
};
63+
64+
export type ParsedFrameworkDetails = {
65+
framesVersion?: string;
66+
framesDebugInfo?: {
67+
/**
68+
* Image URL of debug image.
69+
*/
70+
image?: string;
71+
};
72+
};
73+
74+
export type ParseResultWithFrameworkDetails = ParseResult &
75+
ParsedFrameworkDetails;
76+
77+
export type ParseFramesWithReportsResult = {
78+
[K in SupportedParsingSpecification]: ParseResultWithFrameworkDetails;
79+
};

packages/frames.js/src/getFrame.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import type {
2-
ParseResult,
32
SupportedParsingSpecification,
3+
ParseResultWithFrameworkDetails,
44
} from "./frame-parsers/types";
55
import { parseFramesWithReports } from "./parseFramesWithReports";
66

7-
type GetFrameResult = ParseResult & {
8-
framesVersion?: string;
9-
framesDebugInfo?: {
10-
/**
11-
* Image URL of debug image.
12-
*/
13-
image?: string;
14-
};
15-
};
7+
export type GetFrameResult = ParseResultWithFrameworkDetails;
168

179
type GetFrameOptions = {
1810
htmlString: string;
@@ -51,11 +43,5 @@ export function getFrame({
5143
fromRequestMethod,
5244
});
5345

54-
return {
55-
...parsedFrames[specification],
56-
framesVersion: parsedFrames.framesVersion,
57-
...(parsedFrames.framesDebugInfo
58-
? { framesDebugInfo: parsedFrames.framesDebugInfo }
59-
: {}),
60-
};
46+
return parsedFrames[specification];
6147
}

packages/frames.js/src/parseFramesWithReports.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { load as loadDocument } from "cheerio";
22
import { createReporter } from "./frame-parsers/reporter";
33
import type {
4-
ParseResult,
5-
SupportedParsingSpecification,
4+
ParsedFrameworkDetails,
5+
ParseFramesWithReportsResult,
66
} from "./frame-parsers/types";
77
import { parseFarcasterFrame } from "./frame-parsers/farcaster";
88
import { parseOpenFramesFrame } from "./frame-parsers/open-frames";
@@ -24,18 +24,6 @@ type ParseFramesWithReportsOptions = {
2424
fromRequestMethod?: "GET" | "POST";
2525
};
2626

27-
export type ParseFramesWithReportsResult = {
28-
[K in SupportedParsingSpecification]: ParseResult;
29-
} & {
30-
framesVersion?: string;
31-
framesDebugInfo?: {
32-
/**
33-
* Image URL of debug image.
34-
*/
35-
image?: string;
36-
};
37-
};
38-
3927
/**
4028
* Gets all supported frames and validation their respective validation reports.
4129
*/
@@ -62,14 +50,14 @@ export function parseFramesWithReports({
6250
`meta[name="${FRAMESJS_DEBUG_INFO_IMAGE_KEY}"], meta[property="${FRAMESJS_DEBUG_INFO_IMAGE_KEY}"]`
6351
).attr("content");
6452

65-
return {
66-
farcaster,
67-
openframes: parseOpenFramesFrame(document, {
68-
farcasterFrame: farcaster.frame,
69-
reporter: openFramesReporter,
70-
fallbackPostUrl,
71-
fromRequestMethod,
72-
}),
53+
const openframes = parseOpenFramesFrame(document, {
54+
farcasterFrame: farcaster.frame,
55+
reporter: openFramesReporter,
56+
fallbackPostUrl,
57+
fromRequestMethod,
58+
});
59+
60+
const frameworkDetails: ParsedFrameworkDetails = {
7361
framesVersion,
7462
...(debugImageUrl
7563
? {
@@ -79,4 +67,15 @@ export function parseFramesWithReports({
7967
}
8068
: {}),
8169
};
70+
71+
return {
72+
farcaster: {
73+
...farcaster,
74+
...frameworkDetails,
75+
},
76+
openframes: {
77+
...openframes,
78+
...frameworkDetails,
79+
},
80+
};
8281
}

0 commit comments

Comments
 (0)