@farcaster/frame-core 0.0.21 → 0.0.22

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 (65) hide show
  1. package/dist/actions/AddFrame.d.ts +36 -0
  2. package/dist/actions/AddFrame.js +57 -0
  3. package/dist/actions/{signIn.d.ts → SignIn.d.ts} +7 -6
  4. package/dist/actions/{signIn.js → SignIn.js} +1 -1
  5. package/dist/actions/index.d.ts +2 -0
  6. package/dist/actions/index.js +38 -0
  7. package/dist/errors.js +1 -1
  8. package/dist/index.d.ts +3 -3
  9. package/dist/index.js +2 -25
  10. package/dist/internal/types.d.ts +3 -2
  11. package/dist/schemas/embeds.d.ts +1 -1
  12. package/dist/schemas/embeds.js +3 -3
  13. package/dist/schemas/events.d.ts +1 -1
  14. package/dist/schemas/events.js +5 -5
  15. package/dist/schemas/index.d.ts +5 -5
  16. package/dist/schemas/manifest.d.ts +1 -1
  17. package/dist/schemas/manifest.js +4 -4
  18. package/dist/schemas/notifications.d.ts +1 -1
  19. package/dist/schemas/shared.d.ts +1 -1
  20. package/dist/schemas/shared.js +4 -4
  21. package/dist/types.d.ts +42 -31
  22. package/esm/actions/AddFrame.d.ts +40 -0
  23. package/esm/actions/AddFrame.js +19 -0
  24. package/esm/actions/SignIn.d.ts +43 -0
  25. package/esm/actions/SignIn.js +10 -0
  26. package/esm/actions/index.d.ts +2 -0
  27. package/esm/actions/index.js +2 -0
  28. package/esm/errors.d.ts +9 -7
  29. package/esm/errors.js +6 -6
  30. package/esm/index.d.ts +3 -3
  31. package/esm/index.js +3 -3
  32. package/esm/internal/types.d.ts +19 -7
  33. package/esm/internal/types.js +1 -1
  34. package/esm/schemas/embeds.d.ts +231 -169
  35. package/esm/schemas/embeds.js +25 -19
  36. package/esm/schemas/events.d.ts +225 -129
  37. package/esm/schemas/events.js +18 -18
  38. package/esm/schemas/index.d.ts +5 -5
  39. package/esm/schemas/index.js +5 -5
  40. package/esm/schemas/manifest.d.ts +154 -110
  41. package/esm/schemas/manifest.js +29 -23
  42. package/esm/schemas/notifications.d.ts +86 -58
  43. package/esm/schemas/notifications.js +17 -17
  44. package/esm/schemas/shared.d.ts +49 -33
  45. package/esm/schemas/shared.js +20 -19
  46. package/esm/tsconfig.tsbuildinfo +1 -1
  47. package/esm/types.d.ts +180 -140
  48. package/esm/types.js +2 -2
  49. package/package.json +4 -5
  50. package/src/actions/AddFrame.ts +51 -0
  51. package/src/actions/SignIn.ts +51 -0
  52. package/src/actions/index.ts +2 -0
  53. package/src/errors.ts +4 -4
  54. package/src/index.ts +3 -3
  55. package/src/internal/types.ts +3 -4
  56. package/src/schemas/embeds.ts +13 -13
  57. package/src/schemas/events.ts +17 -17
  58. package/src/schemas/index.ts +5 -5
  59. package/src/schemas/manifest.ts +11 -11
  60. package/src/schemas/notifications.ts +8 -10
  61. package/src/schemas/shared.ts +13 -13
  62. package/src/types.ts +125 -124
  63. package/esm/actions/signIn.d.ts +0 -40
  64. package/esm/actions/signIn.js +0 -10
  65. package/src/actions/signIn.ts +0 -50
@@ -1,21 +1,21 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod'
2
2
  import {
3
- secureUrlSchema,
3
+ buttonTitleSchema,
4
+ encodedJsonFarcasterSignatureSchema,
4
5
  frameNameSchema,
5
6
  hexColorSchema,
6
- encodedJsonFarcasterSignatureSchema,
7
- buttonTitleSchema,
8
- } from "./shared";
7
+ secureUrlSchema,
8
+ } from './shared'
9
9
 
10
10
  export const domainFrameConfigSchema = z.object({
11
11
  // 0.0.0 and 0.0.1 are not technically part of the spec but kept for
12
12
  // backwards compatibilty. next should always resolve to the most recent
13
13
  // schema version.
14
14
  version: z.union([
15
- z.literal("0.0.0"),
16
- z.literal("0.0.1"),
17
- z.literal("1"),
18
- z.literal('next')
15
+ z.literal('0.0.0'),
16
+ z.literal('0.0.1'),
17
+ z.literal('1'),
18
+ z.literal('next'),
19
19
  ]),
20
20
  name: frameNameSchema,
21
21
  iconUrl: secureUrlSchema,
@@ -25,9 +25,9 @@ export const domainFrameConfigSchema = z.object({
25
25
  splashImageUrl: secureUrlSchema.optional(),
26
26
  splashBackgroundColor: hexColorSchema.optional(),
27
27
  webhookUrl: secureUrlSchema.optional(),
28
- });
28
+ })
29
29
 
30
30
  export const domainManifestSchema = z.object({
31
31
  accountAssociation: encodedJsonFarcasterSignatureSchema,
32
32
  frame: domainFrameConfigSchema.optional(),
33
- });
33
+ })
@@ -1,14 +1,12 @@
1
- import { z } from "zod";
2
- import { secureUrlSchema } from "./shared";
1
+ import { z } from 'zod'
2
+ import { secureUrlSchema } from './shared'
3
3
 
4
4
  export const notificationDetailsSchema = z.object({
5
5
  url: z.string(),
6
6
  token: z.string(),
7
- });
7
+ })
8
8
 
9
- export type FrameNotificationDetails = z.infer<
10
- typeof notificationDetailsSchema
11
- >;
9
+ export type FrameNotificationDetails = z.infer<typeof notificationDetailsSchema>
12
10
 
13
11
  export const sendNotificationRequestSchema = z.object({
14
12
  notificationId: z.string().max(128),
@@ -16,11 +14,11 @@ export const sendNotificationRequestSchema = z.object({
16
14
  body: z.string().max(128),
17
15
  targetUrl: secureUrlSchema,
18
16
  tokens: z.string().array().max(100),
19
- });
17
+ })
20
18
 
21
19
  export type SendNotificationRequest = z.infer<
22
20
  typeof sendNotificationRequestSchema
23
- >;
21
+ >
24
22
 
25
23
  export const sendNotificationResponseSchema = z.object({
26
24
  result: z.object({
@@ -28,8 +26,8 @@ export const sendNotificationResponseSchema = z.object({
28
26
  invalidTokens: z.array(z.string()),
29
27
  rateLimitedTokens: z.array(z.string()),
30
28
  }),
31
- });
29
+ })
32
30
 
33
31
  export type SendNotificationResponse = z.infer<
34
32
  typeof sendNotificationResponseSchema
35
- >;
33
+ >
@@ -1,37 +1,37 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod'
2
2
 
3
3
  export const secureUrlSchema = z
4
4
  .string()
5
5
  .url()
6
- .startsWith("https://", { message: "Must be an https url" })
7
- .max(512);
6
+ .startsWith('https://', { message: 'Must be an https url' })
7
+ .max(512)
8
8
 
9
- export const frameNameSchema = z.string().max(32);
10
- export const buttonTitleSchema = z.string().max(32);
9
+ export const frameNameSchema = z.string().max(32)
10
+ export const buttonTitleSchema = z.string().max(32)
11
11
 
12
12
  export const hexColorSchema = z
13
13
  .string()
14
14
  .regex(/^#([0-9A-F]{3}|[0-9A-F]{6})$/i, {
15
15
  message:
16
- "Invalid hex color code. It should be in the format #RRGGBB or #RGB.",
17
- });
16
+ 'Invalid hex color code. It should be in the format #RRGGBB or #RGB.',
17
+ })
18
18
 
19
19
  export const encodedJsonFarcasterSignatureSchema = z.object({
20
20
  header: z.string(),
21
21
  payload: z.string(),
22
22
  signature: z.string(),
23
- });
23
+ })
24
24
 
25
25
  export type EncodedJsonFarcasterSignatureSchema = z.infer<
26
26
  typeof encodedJsonFarcasterSignatureSchema
27
- >;
27
+ >
28
28
 
29
29
  export const jsonFarcasterSignatureHeaderSchema = z.object({
30
30
  fid: z.number(),
31
- type: z.literal("app_key"),
32
- key: z.string().startsWith("0x"),
33
- });
31
+ type: z.literal('app_key'),
32
+ key: z.string().startsWith('0x'),
33
+ })
34
34
 
35
35
  export type JsonFarcasterSignatureHeaderSchema = z.infer<
36
36
  typeof jsonFarcasterSignatureHeaderSchema
37
- >;
37
+ >
package/src/types.ts CHANGED
@@ -1,106 +1,85 @@
1
+ import type { Address, Provider, RpcRequest, RpcResponse, RpcSchema } from 'ox'
2
+ import type { AddFrame, SignIn } from './actions'
1
3
  import type {
2
- Address,
3
- Provider,
4
- RpcRequest,
5
- RpcResponse,
6
- RpcSchema,
7
- } from "ox";
8
- import {
9
- FrameNotificationDetails,
10
4
  EventFrameAdded,
11
5
  EventFrameRemoved,
12
- EventNotificationsEnabled,
13
6
  EventNotificationsDisabled,
14
- } from "./schemas";
15
- import * as SignIn from "./actions/signIn";
7
+ EventNotificationsEnabled,
8
+ FrameNotificationDetails,
9
+ } from './schemas'
16
10
 
17
- export type SetPrimaryButton = (options: {
18
- text: string;
19
- loading?: boolean;
20
- disabled?: boolean;
21
- hidden?: boolean;
22
- }) => void;
11
+ export type SetPrimaryButtonOptions = {
12
+ text: string
13
+ loading?: boolean
14
+ disabled?: boolean
15
+ hidden?: boolean
16
+ }
17
+
18
+ export type SetPrimaryButton = (options: SetPrimaryButtonOptions) => void
23
19
 
24
- export type EthProviderRequest = Provider.RequestFn<RpcSchema.Default>;
20
+ export type EthProviderRequest = Provider.RequestFn<RpcSchema.Default>
25
21
 
26
22
  export type AccountLocation = {
27
- placeId: string;
23
+ placeId: string
28
24
  /**
29
25
  * Human-readable string describing the location
30
26
  */
31
- description: string;
32
- };
27
+ description: string
28
+ }
33
29
 
34
30
  export type FrameLocationContextCastEmbed = {
35
- type: "cast_embed";
36
- embed: string;
31
+ type: 'cast_embed'
32
+ embed: string
37
33
  cast: {
38
- fid: number;
39
- hash: string;
40
- };
41
- };
34
+ fid: number
35
+ hash: string
36
+ }
37
+ }
42
38
 
43
39
  export type FrameLocationContextNotification = {
44
- type: "notification";
40
+ type: 'notification'
45
41
  notification: {
46
- notificationId: string;
47
- title: string;
48
- body: string;
49
- };
50
- };
42
+ notificationId: string
43
+ title: string
44
+ body: string
45
+ }
46
+ }
51
47
 
52
48
  export type FrameLocationContextLauncher = {
53
- type: "launcher";
54
- };
49
+ type: 'launcher'
50
+ }
55
51
 
56
52
  export type FrameLocationContext =
57
53
  | FrameLocationContextCastEmbed
58
54
  | FrameLocationContextNotification
59
- | FrameLocationContextLauncher;
60
-
55
+ | FrameLocationContextLauncher
61
56
 
62
57
  export type SafeAreaInsets = {
63
- top: number;
64
- bottom: number;
65
- left: number;
66
- right: number;
58
+ top: number
59
+ bottom: number
60
+ left: number
61
+ right: number
67
62
  }
68
63
 
69
64
  export type FrameContext = {
70
65
  user: {
71
- fid: number;
72
- username?: string;
73
- displayName?: string;
66
+ fid: number
67
+ username?: string
68
+ displayName?: string
74
69
  /**
75
70
  * Profile image URL
76
71
  */
77
- pfpUrl?: string;
78
- location?: AccountLocation;
79
- };
80
- location?: FrameLocationContext;
72
+ pfpUrl?: string
73
+ location?: AccountLocation
74
+ }
75
+ location?: FrameLocationContext
81
76
  client: {
82
- clientFid: number;
83
- added: boolean;
84
- notificationDetails?: FrameNotificationDetails;
85
- safeAreaInsets?: SafeAreaInsets;
86
- };
87
- };
88
-
89
- export type AddFrameRejectedReason =
90
- | "invalid_domain_manifest"
91
- | "rejected_by_user";
92
-
93
- export type AddFrameResult =
94
- | {
95
- added: true;
96
- notificationDetails?: FrameNotificationDetails;
97
- }
98
- | {
99
- added: false;
100
- reason: AddFrameRejectedReason;
101
- };
102
-
103
- export type AddFrame = () => Promise<AddFrameResult>;
77
+ clientFid: number
78
+ added: boolean
79
+ notificationDetails?: FrameNotificationDetails
80
+ safeAreaInsets?: SafeAreaInsets
81
+ }
82
+ }
104
83
 
105
84
  export type ReadyOptions = {
106
85
  /**
@@ -109,105 +88,126 @@ export type ReadyOptions = {
109
88
  *
110
89
  * @defaultValue false
111
90
  */
112
- disableNativeGestures: boolean;
113
- };
91
+ disableNativeGestures: boolean
92
+ }
114
93
 
115
94
  export const DEFAULT_READY_OPTIONS: ReadyOptions = {
116
95
  disableNativeGestures: false,
117
- };
96
+ }
118
97
 
119
98
  export type SignInOptions = {
120
99
  /**
121
100
  * A random string used to prevent replay attacks.
122
101
  */
123
- nonce: string;
102
+ nonce: string
124
103
 
125
104
  /**
126
105
  * Start time at which the signature becomes valid.
127
106
  * ISO 8601 datetime.
128
107
  */
129
- notBefore?: string;
108
+ notBefore?: string
130
109
 
131
110
  /**
132
111
  * Expiration time at which the signature is no longer valid.
133
112
  * ISO 8601 datetime.
134
113
  */
135
- expirationTime?: string;
136
- };
114
+ expirationTime?: string
115
+ }
137
116
 
138
117
  export type WireFrameHost = {
139
- context: FrameContext;
140
- close: () => void;
141
- ready: (options?: Partial<ReadyOptions>) => void;
142
- openUrl: (url: string) => void;
143
- signIn: SignIn.WireSignIn;
144
- setPrimaryButton: SetPrimaryButton;
145
- ethProviderRequest: EthProviderRequest;
146
- ethProviderRequestV2: RpcTransport;
147
- addFrame: AddFrame;
148
- };
118
+ context: FrameContext
119
+ close: () => void
120
+ ready: (options?: Partial<ReadyOptions>) => void
121
+ openUrl: (url: string) => void
122
+ signIn: SignIn.WireSignIn
123
+ setPrimaryButton: SetPrimaryButton
124
+ ethProviderRequest: EthProviderRequest
125
+ ethProviderRequestV2: RpcTransport
126
+ eip6963RequestProvider: () => void
127
+ addFrame: AddFrame.WireAddFrame
128
+ }
149
129
 
150
130
  export type FrameHost = {
151
- context: FrameContext;
152
- close: () => void;
153
- ready: (options?: Partial<ReadyOptions>) => void;
154
- openUrl: (url: string) => void;
155
- signIn: SignIn.SignIn;
156
- setPrimaryButton: SetPrimaryButton;
157
- ethProviderRequest: EthProviderRequest;
158
- ethProviderRequestV2: RpcTransport;
159
- addFrame: AddFrame;
160
- };
131
+ context: FrameContext
132
+ close: () => void
133
+ ready: (options?: Partial<ReadyOptions>) => void
134
+ openUrl: (url: string) => void
135
+ signIn: SignIn.SignIn
136
+ setPrimaryButton: SetPrimaryButton
137
+ ethProviderRequest: EthProviderRequest
138
+ ethProviderRequestV2: RpcTransport
139
+ /**
140
+ * Receive forwarded eip6963:requestProvider events from the frame document.
141
+ * Hosts must emit an EventEip6963AnnounceProvider in response.
142
+ */
143
+ eip6963RequestProvider: () => void
144
+ addFrame: AddFrame.AddFrame
145
+ }
161
146
 
162
147
  export type FrameEthProviderEventData = {
163
- type: "frame_eth_provider_event";
164
- } & EthProviderWireEvent;
148
+ type: 'frame_eth_provider_event'
149
+ } & EthProviderWireEvent
165
150
 
166
151
  export type RpcTransport = (
167
152
  request: RpcRequest.RpcRequest,
168
- ) => Promise<RpcResponse.RpcResponse>;
153
+ ) => Promise<RpcResponse.RpcResponse>
169
154
 
170
155
  export type ProviderRpcError = {
171
- code: number;
172
- details?: string;
173
- message?: string;
174
- };
156
+ code: number
157
+ details?: string
158
+ message?: string
159
+ }
175
160
 
176
161
  export type EthProviderWireEvent =
177
162
  | {
178
- event: "accountsChanged";
179
- params: [readonly Address.Address[]];
163
+ event: 'accountsChanged'
164
+ params: [readonly Address.Address[]]
180
165
  }
181
166
  | {
182
- event: "chainChanged";
183
- params: [string];
167
+ event: 'chainChanged'
168
+ params: [string]
184
169
  }
185
170
  | {
186
- event: "connect";
187
- params: [Provider.ConnectInfo];
171
+ event: 'connect'
172
+ params: [Provider.ConnectInfo]
188
173
  }
189
174
  | {
190
- event: "disconnect";
191
- params: [ProviderRpcError];
175
+ event: 'disconnect'
176
+ params: [ProviderRpcError]
192
177
  }
193
178
  | {
194
- event: "message";
195
- params: [Provider.Message];
196
- };
179
+ event: 'message'
180
+ params: [Provider.Message]
181
+ }
197
182
 
198
- export type EmitEthProvider = <event extends EthProviderWireEvent["event"]>(
183
+ export type EmitEthProvider = <event extends EthProviderWireEvent['event']>(
199
184
  event: event,
200
- params: Extract<EthProviderWireEvent, { event: event }>["params"],
201
- ) => void;
185
+ params: Extract<EthProviderWireEvent, { event: event }>['params'],
186
+ ) => void
202
187
 
203
188
  export type EventFrameAddRejected = {
204
- event: "frame_add_rejected";
205
- reason: AddFrameRejectedReason;
206
- };
189
+ event: 'frame_add_rejected'
190
+ reason: AddFrame.AddFrameRejectedReason
191
+ }
207
192
 
208
193
  export type EventPrimaryButtonClicked = {
209
- event: "primary_button_clicked";
210
- };
194
+ event: 'primary_button_clicked'
195
+ }
196
+
197
+ /**
198
+ * Metadata of the EIP-1193 Provider.
199
+ */
200
+ export interface EIP6963ProviderInfo {
201
+ icon: `data:image/${string}` // RFC-2397
202
+ name: string
203
+ rdns: string
204
+ uuid: string
205
+ }
206
+
207
+ export type EventEip6963AnnounceProvider = {
208
+ event: 'eip6963:announceProvider'
209
+ info: EIP6963ProviderInfo
210
+ }
211
211
 
212
212
  export type FrameClientEvent =
213
213
  | EventFrameAdded
@@ -215,4 +215,5 @@ export type FrameClientEvent =
215
215
  | EventFrameRemoved
216
216
  | EventNotificationsEnabled
217
217
  | EventNotificationsDisabled
218
- | EventPrimaryButtonClicked;
218
+ | EventPrimaryButtonClicked
219
+ | EventEip6963AnnounceProvider
@@ -1,40 +0,0 @@
1
- import * as Errors from '../errors';
2
- import { OneOf } from '../internal/types';
3
- export type SignInOptions = {
4
- /**
5
- * A random string used to prevent replay attacks.
6
- */
7
- nonce: string;
8
- /**
9
- * Start time at which the signature becomes valid.
10
- * ISO 8601 datetime.
11
- */
12
- notBefore?: string;
13
- /**
14
- * Expiration time at which the signature is no longer valid.
15
- * ISO 8601 datetime.
16
- */
17
- expirationTime?: string;
18
- };
19
- export type SignInResult = {
20
- signature: string;
21
- message: string;
22
- };
23
- export type SignIn = (options: SignInOptions) => Promise<SignInResult>;
24
- export type RejectedByUserError = {
25
- type: 'rejected_by_user';
26
- };
27
- export type JsonSignInError = RejectedByUserError;
28
- export type WireSignInResponse = OneOf<{
29
- result: SignInResult;
30
- } | {
31
- error: JsonSignInError;
32
- }>;
33
- export type WireSignIn = (options: SignInOptions) => Promise<WireSignInResponse>;
34
- /**
35
- * Thrown when a sign in action was rejected.
36
- */
37
- export declare class RejectedByUser extends Errors.BaseError {
38
- readonly name = "SignIn.RejectedByUser";
39
- constructor();
40
- }
@@ -1,10 +0,0 @@
1
- import * as Errors from '../errors';
2
- /**
3
- * Thrown when a sign in action was rejected.
4
- */
5
- export class RejectedByUser extends Errors.BaseError {
6
- name = 'SignIn.RejectedByUser';
7
- constructor() {
8
- super("Sign in rejected by user");
9
- }
10
- }
@@ -1,50 +0,0 @@
1
- import type { Address } from 'ox';
2
- import * as Errors from '../errors'
3
- import { OneOf } from '../internal/types';
4
-
5
- export type SignInOptions = {
6
- /**
7
- * A random string used to prevent replay attacks.
8
- */
9
- nonce: string;
10
-
11
- /**
12
- * Start time at which the signature becomes valid.
13
- * ISO 8601 datetime.
14
- */
15
- notBefore?: string;
16
-
17
- /**
18
- * Expiration time at which the signature is no longer valid.
19
- * ISO 8601 datetime.
20
- */
21
- expirationTime?: string;
22
- };
23
-
24
- export type SignInResult = {
25
- signature: string;
26
- message: string;
27
- }
28
-
29
- export type SignIn = (options: SignInOptions) => Promise<SignInResult>;
30
-
31
- export type RejectedByUserError = {
32
- type: 'rejected_by_user'
33
- };
34
-
35
- export type JsonSignInError = RejectedByUserError;
36
-
37
- export type WireSignInResponse = OneOf<{ result: SignInResult } | { error: JsonSignInError }>
38
-
39
- export type WireSignIn = (options: SignInOptions) => Promise<WireSignInResponse>;
40
-
41
- /**
42
- * Thrown when a sign in action was rejected.
43
- */
44
- export class RejectedByUser extends Errors.BaseError {
45
- override readonly name = 'SignIn.RejectedByUser'
46
-
47
- constructor() {
48
- super("Sign in rejected by user")
49
- }
50
- }