@farcaster/frame-sdk 0.0.18 → 0.0.20
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/endpoint.js +2 -3
- package/dist/frameHost.d.ts +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +4 -4
- package/dist/provider.js +1 -1
- package/dist/sdk.js +54 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +13 -1
- package/package.json +2 -2
- package/src/frameHost.ts +2 -2
- package/src/sdk.ts +46 -2
- package/src/types.ts +17 -0
package/src/sdk.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { EventEmitter } from "eventemitter3";
|
|
|
2
2
|
import { FrameSDK, Emitter, EventMap } from "./types";
|
|
3
3
|
import { frameHost } from "./frameHost";
|
|
4
4
|
import { provider } from "./provider";
|
|
5
|
+
import { FrameClientEvent, SignIn } from "@farcaster/frame-core";
|
|
5
6
|
|
|
6
7
|
export function createEmitter(): Emitter {
|
|
7
8
|
const emitter = new EventEmitter<EventMap>();
|
|
@@ -35,6 +36,19 @@ export const sdk: FrameSDK = {
|
|
|
35
36
|
setPrimaryButton: frameHost.setPrimaryButton.bind(frameHost),
|
|
36
37
|
ready: frameHost.ready.bind(frameHost),
|
|
37
38
|
close: frameHost.close.bind(frameHost),
|
|
39
|
+
signIn: async (options) => {
|
|
40
|
+
const response = await frameHost.signIn(options);
|
|
41
|
+
console.log(response);
|
|
42
|
+
if (response.result) {
|
|
43
|
+
return response.result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (response.error.type === "rejected_by_user") {
|
|
47
|
+
throw new SignIn.RejectedByUser();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error("Unreachable");
|
|
51
|
+
},
|
|
38
52
|
openUrl: (url: string) => {
|
|
39
53
|
return frameHost.openUrl(url.trim());
|
|
40
54
|
},
|
|
@@ -50,8 +64,23 @@ if (typeof document !== "undefined") {
|
|
|
50
64
|
// react native webview events
|
|
51
65
|
document.addEventListener("FarcasterFrameEvent", (event) => {
|
|
52
66
|
if (event instanceof MessageEvent) {
|
|
53
|
-
|
|
67
|
+
const frameEvent = event.data as FrameClientEvent;
|
|
68
|
+
if (frameEvent.event === "primary_button_clicked") {
|
|
54
69
|
emitter.emit("primaryButtonClicked");
|
|
70
|
+
} else if (frameEvent.event === "frame_added") {
|
|
71
|
+
emitter.emit("frameAdded", {
|
|
72
|
+
notificationDetails: frameEvent.notificationDetails,
|
|
73
|
+
});
|
|
74
|
+
} else if (frameEvent.event === "frame_add_rejected") {
|
|
75
|
+
emitter.emit("frameAddRejected", { reason: frameEvent.reason });
|
|
76
|
+
} else if (frameEvent.event === "frame_removed") {
|
|
77
|
+
emitter.emit("frameRemoved");
|
|
78
|
+
} else if (frameEvent.event === "notifications_enabled") {
|
|
79
|
+
emitter.emit("notificationsEnabled", {
|
|
80
|
+
notificationDetails: frameEvent.notificationDetails,
|
|
81
|
+
});
|
|
82
|
+
} else if (frameEvent.event === "notifications_disabled") {
|
|
83
|
+
emitter.emit("notificationsDisabled");
|
|
55
84
|
}
|
|
56
85
|
}
|
|
57
86
|
});
|
|
@@ -63,8 +92,23 @@ if (typeof window !== "undefined") {
|
|
|
63
92
|
window.addEventListener("message", (event) => {
|
|
64
93
|
if (event instanceof MessageEvent) {
|
|
65
94
|
if (event.data.type === "frameEvent") {
|
|
66
|
-
|
|
95
|
+
const frameEvent = event.data.event as FrameClientEvent;
|
|
96
|
+
if (frameEvent.event === "primary_button_clicked") {
|
|
67
97
|
emitter.emit("primaryButtonClicked");
|
|
98
|
+
} else if (frameEvent.event === "frame_added") {
|
|
99
|
+
emitter.emit("frameAdded", {
|
|
100
|
+
notificationDetails: frameEvent.notificationDetails,
|
|
101
|
+
});
|
|
102
|
+
} else if (frameEvent.event === "frame_add_rejected") {
|
|
103
|
+
emitter.emit("frameAddRejected", { reason: frameEvent.reason });
|
|
104
|
+
} else if (frameEvent.event === "frame_removed") {
|
|
105
|
+
emitter.emit("frameRemoved");
|
|
106
|
+
} else if (frameEvent.event === "notifications_enabled") {
|
|
107
|
+
emitter.emit("notificationsEnabled", {
|
|
108
|
+
notificationDetails: frameEvent.notificationDetails,
|
|
109
|
+
});
|
|
110
|
+
} else if (frameEvent.event === "notifications_disabled") {
|
|
111
|
+
emitter.emit("notificationsDisabled");
|
|
68
112
|
}
|
|
69
113
|
}
|
|
70
114
|
}
|
package/src/types.ts
CHANGED
|
@@ -4,6 +4,9 @@ import type {
|
|
|
4
4
|
FrameContext,
|
|
5
5
|
AddFrame,
|
|
6
6
|
ReadyOptions,
|
|
7
|
+
SignIn,
|
|
8
|
+
FrameNotificationDetails,
|
|
9
|
+
AddFrameRejectedReason,
|
|
7
10
|
} from "@farcaster/frame-core";
|
|
8
11
|
|
|
9
12
|
declare global {
|
|
@@ -21,6 +24,19 @@ export type Compute<type> = { [key in keyof type]: type[key] } & unknown;
|
|
|
21
24
|
|
|
22
25
|
export type EventMap = {
|
|
23
26
|
primaryButtonClicked: () => void;
|
|
27
|
+
frameAdded: ({
|
|
28
|
+
notificationDetails,
|
|
29
|
+
}: {
|
|
30
|
+
notificationDetails?: FrameNotificationDetails;
|
|
31
|
+
}) => void;
|
|
32
|
+
frameAddRejected: ({ reason }: { reason: AddFrameRejectedReason }) => void;
|
|
33
|
+
frameRemoved: () => void;
|
|
34
|
+
notificationsEnabled: ({
|
|
35
|
+
notificationDetails,
|
|
36
|
+
}: {
|
|
37
|
+
notificationDetails: FrameNotificationDetails;
|
|
38
|
+
}) => void;
|
|
39
|
+
notificationsDisabled: () => void;
|
|
24
40
|
};
|
|
25
41
|
|
|
26
42
|
export type Emitter = Compute<EventEmitter<EventMap>>;
|
|
@@ -37,6 +53,7 @@ export type FrameSDK = {
|
|
|
37
53
|
actions: {
|
|
38
54
|
ready: (options?: Partial<ReadyOptions>) => Promise<void>;
|
|
39
55
|
openUrl: (url: string) => Promise<void>;
|
|
56
|
+
signIn: SignIn.SignIn;
|
|
40
57
|
close: () => Promise<void>;
|
|
41
58
|
setPrimaryButton: SetPrimaryButton;
|
|
42
59
|
addFrame: AddFrame;
|