@farcaster/frame-core 0.0.20 → 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 +43 -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 -139
  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 -123
  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,105 +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";
31
+ type: 'cast_embed'
32
+ embed: string
36
33
  cast: {
37
- fid: number;
38
- hash: string;
39
- };
40
- };
34
+ fid: number
35
+ hash: string
36
+ }
37
+ }
41
38
 
42
39
  export type FrameLocationContextNotification = {
43
- type: "notification";
40
+ type: 'notification'
44
41
  notification: {
45
- notificationId: string;
46
- title: string;
47
- body: string;
48
- };
49
- };
42
+ notificationId: string
43
+ title: string
44
+ body: string
45
+ }
46
+ }
50
47
 
51
48
  export type FrameLocationContextLauncher = {
52
- type: "launcher";
53
- };
49
+ type: 'launcher'
50
+ }
54
51
 
55
52
  export type FrameLocationContext =
56
53
  | FrameLocationContextCastEmbed
57
54
  | FrameLocationContextNotification
58
- | FrameLocationContextLauncher;
59
-
55
+ | FrameLocationContextLauncher
60
56
 
61
57
  export type SafeAreaInsets = {
62
- top: number;
63
- bottom: number;
64
- left: number;
65
- right: number;
58
+ top: number
59
+ bottom: number
60
+ left: number
61
+ right: number
66
62
  }
67
63
 
68
64
  export type FrameContext = {
69
65
  user: {
70
- fid: number;
71
- username?: string;
72
- displayName?: string;
66
+ fid: number
67
+ username?: string
68
+ displayName?: string
73
69
  /**
74
70
  * Profile image URL
75
71
  */
76
- pfpUrl?: string;
77
- location?: AccountLocation;
78
- };
79
- location?: FrameLocationContext;
72
+ pfpUrl?: string
73
+ location?: AccountLocation
74
+ }
75
+ location?: FrameLocationContext
80
76
  client: {
81
- clientFid: number;
82
- added: boolean;
83
- notificationDetails?: FrameNotificationDetails;
84
- safeAreaInsets?: SafeAreaInsets;
85
- };
86
- };
87
-
88
- export type AddFrameRejectedReason =
89
- | "invalid_domain_manifest"
90
- | "rejected_by_user";
91
-
92
- export type AddFrameResult =
93
- | {
94
- added: true;
95
- notificationDetails?: FrameNotificationDetails;
96
- }
97
- | {
98
- added: false;
99
- reason: AddFrameRejectedReason;
100
- };
101
-
102
- export type AddFrame = () => Promise<AddFrameResult>;
77
+ clientFid: number
78
+ added: boolean
79
+ notificationDetails?: FrameNotificationDetails
80
+ safeAreaInsets?: SafeAreaInsets
81
+ }
82
+ }
103
83
 
104
84
  export type ReadyOptions = {
105
85
  /**
@@ -108,105 +88,126 @@ export type ReadyOptions = {
108
88
  *
109
89
  * @defaultValue false
110
90
  */
111
- disableNativeGestures: boolean;
112
- };
91
+ disableNativeGestures: boolean
92
+ }
113
93
 
114
94
  export const DEFAULT_READY_OPTIONS: ReadyOptions = {
115
95
  disableNativeGestures: false,
116
- };
96
+ }
117
97
 
118
98
  export type SignInOptions = {
119
99
  /**
120
100
  * A random string used to prevent replay attacks.
121
101
  */
122
- nonce: string;
102
+ nonce: string
123
103
 
124
104
  /**
125
105
  * Start time at which the signature becomes valid.
126
106
  * ISO 8601 datetime.
127
107
  */
128
- notBefore?: string;
108
+ notBefore?: string
129
109
 
130
110
  /**
131
111
  * Expiration time at which the signature is no longer valid.
132
112
  * ISO 8601 datetime.
133
113
  */
134
- expirationTime?: string;
135
- };
114
+ expirationTime?: string
115
+ }
136
116
 
137
117
  export type WireFrameHost = {
138
- context: FrameContext;
139
- close: () => void;
140
- ready: (options?: Partial<ReadyOptions>) => void;
141
- openUrl: (url: string) => void;
142
- signIn: SignIn.WireSignIn;
143
- setPrimaryButton: SetPrimaryButton;
144
- ethProviderRequest: EthProviderRequest;
145
- ethProviderRequestV2: RpcTransport;
146
- addFrame: AddFrame;
147
- };
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
+ }
148
129
 
149
130
  export type FrameHost = {
150
- context: FrameContext;
151
- close: () => void;
152
- ready: (options?: Partial<ReadyOptions>) => void;
153
- openUrl: (url: string) => void;
154
- signIn: SignIn.SignIn;
155
- setPrimaryButton: SetPrimaryButton;
156
- ethProviderRequest: EthProviderRequest;
157
- ethProviderRequestV2: RpcTransport;
158
- addFrame: AddFrame;
159
- };
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
+ }
160
146
 
161
147
  export type FrameEthProviderEventData = {
162
- type: "frame_eth_provider_event";
163
- } & EthProviderWireEvent;
148
+ type: 'frame_eth_provider_event'
149
+ } & EthProviderWireEvent
164
150
 
165
151
  export type RpcTransport = (
166
152
  request: RpcRequest.RpcRequest,
167
- ) => Promise<RpcResponse.RpcResponse>;
153
+ ) => Promise<RpcResponse.RpcResponse>
168
154
 
169
155
  export type ProviderRpcError = {
170
- code: number;
171
- details?: string;
172
- message?: string;
173
- };
156
+ code: number
157
+ details?: string
158
+ message?: string
159
+ }
174
160
 
175
161
  export type EthProviderWireEvent =
176
162
  | {
177
- event: "accountsChanged";
178
- params: [readonly Address.Address[]];
163
+ event: 'accountsChanged'
164
+ params: [readonly Address.Address[]]
179
165
  }
180
166
  | {
181
- event: "chainChanged";
182
- params: [string];
167
+ event: 'chainChanged'
168
+ params: [string]
183
169
  }
184
170
  | {
185
- event: "connect";
186
- params: [Provider.ConnectInfo];
171
+ event: 'connect'
172
+ params: [Provider.ConnectInfo]
187
173
  }
188
174
  | {
189
- event: "disconnect";
190
- params: [ProviderRpcError];
175
+ event: 'disconnect'
176
+ params: [ProviderRpcError]
191
177
  }
192
178
  | {
193
- event: "message";
194
- params: [Provider.Message];
195
- };
179
+ event: 'message'
180
+ params: [Provider.Message]
181
+ }
196
182
 
197
- export type EmitEthProvider = <event extends EthProviderWireEvent["event"]>(
183
+ export type EmitEthProvider = <event extends EthProviderWireEvent['event']>(
198
184
  event: event,
199
- params: Extract<EthProviderWireEvent, { event: event }>["params"],
200
- ) => void;
185
+ params: Extract<EthProviderWireEvent, { event: event }>['params'],
186
+ ) => void
201
187
 
202
188
  export type EventFrameAddRejected = {
203
- event: "frame_add_rejected";
204
- reason: AddFrameRejectedReason;
205
- };
189
+ event: 'frame_add_rejected'
190
+ reason: AddFrame.AddFrameRejectedReason
191
+ }
206
192
 
207
193
  export type EventPrimaryButtonClicked = {
208
- event: "primary_button_clicked";
209
- };
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
+ }
210
211
 
211
212
  export type FrameClientEvent =
212
213
  | EventFrameAdded
@@ -214,4 +215,5 @@ export type FrameClientEvent =
214
215
  | EventFrameRemoved
215
216
  | EventNotificationsEnabled
216
217
  | EventNotificationsDisabled
217
- | 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
- }