@farcaster/miniapp-core 0.3.5 → 0.3.7

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/src/context.ts CHANGED
@@ -116,6 +116,7 @@ export type ClientContext = {
116
116
 
117
117
  export type ClientFeatures = {
118
118
  haptics: boolean
119
+ cameraAndMicrophoneAccess?: boolean
119
120
  }
120
121
 
121
122
  export type MiniAppContext = {
@@ -10,7 +10,7 @@ import {
10
10
  secureUrlSchema,
11
11
  } from './shared.ts'
12
12
 
13
- const primaryCategorySchema = z.enum([
13
+ export const primaryCategories = [
14
14
  'games',
15
15
  'social',
16
16
  'finance',
@@ -24,9 +24,38 @@ const primaryCategorySchema = z.enum([
24
24
  'developer-tools',
25
25
  'entertainment',
26
26
  'art-creativity',
27
+ ] as const
28
+
29
+ export type PrimaryCategory = (typeof primaryCategories)[number]
30
+
31
+ export const primaryCategorySchema = z.enum(primaryCategories)
32
+
33
+ export const versionSchema = z.union([
34
+ z.literal('0.0.0'),
35
+ z.literal('0.0.1'),
36
+ z.literal('1'),
37
+ z.literal('next'),
27
38
  ])
28
39
 
29
- const chainList = [
40
+ export const subtitleSchema = createSimpleStringSchema({ max: 30 })
41
+
42
+ export const descriptionSchema = createSimpleStringSchema({ max: 170 })
43
+
44
+ export const screenshotUrlsSchema = z.array(secureUrlSchema).max(3)
45
+
46
+ export const tagsSchema = z
47
+ .array(createSimpleStringSchema({ max: 20, noSpaces: true }))
48
+ .max(5)
49
+
50
+ export const taglineSchema = createSimpleStringSchema({ max: 30 })
51
+
52
+ export const ogTitleSchema = createSimpleStringSchema({ max: 30 })
53
+
54
+ export const ogDescriptionSchema = createSimpleStringSchema({ max: 100 })
55
+
56
+ export const noindexSchema = z.boolean()
57
+
58
+ export const chains = [
30
59
  'eip155:1', // Ethereum mainnet
31
60
  'eip155:8453', // Base mainnet
32
61
  'eip155:42161', // Arbitrum One
@@ -45,22 +74,27 @@ const chainList = [
45
74
  'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', // Solana
46
75
  ] as const
47
76
 
77
+ export type Chains = (typeof chains)[number]
78
+
48
79
  function removeArrayDuplicates<T>(arr: T[]) {
49
80
  const set = new Set(arr)
50
81
  return Array.from(set)
51
82
  }
52
83
 
84
+ export const requiredChainsSchema = z
85
+ .array(z.enum(chains))
86
+ .transform(removeArrayDuplicates)
87
+
88
+ export const requiredCapabilitiesSchema = z
89
+ .array(z.enum(miniAppHostCapabilityList))
90
+ .transform(removeArrayDuplicates)
91
+
53
92
  export const domainMiniAppConfigSchema = z
54
93
  .object({
55
94
  // 0.0.0 and 0.0.1 are not technically part of the spec but kept for
56
95
  // backwards compatibility. next should always resolve to the most recent
57
96
  // schema version.
58
- version: z.union([
59
- z.literal('0.0.0'),
60
- z.literal('0.0.1'),
61
- z.literal('1'),
62
- z.literal('next'),
63
- ]),
97
+ version: versionSchema,
64
98
  name: miniAppNameSchema,
65
99
  iconUrl: secureUrlSchema,
66
100
  homeUrl: secureUrlSchema,
@@ -72,30 +106,21 @@ export const domainMiniAppConfigSchema = z
72
106
  splashBackgroundColor: hexColorSchema.optional(),
73
107
  webhookUrl: secureUrlSchema.optional(),
74
108
  /** see: https://github.com/farcasterxyz/miniapps/discussions/191 */
75
- subtitle: createSimpleStringSchema({ max: 30 }).optional(),
76
- description: createSimpleStringSchema({ max: 170 }).optional(),
77
- screenshotUrls: z.array(secureUrlSchema).max(3).optional(),
109
+ subtitle: subtitleSchema.optional(),
110
+ description: descriptionSchema.optional(),
111
+ screenshotUrls: screenshotUrlsSchema.optional(),
78
112
  primaryCategory: primaryCategorySchema.optional(),
79
- tags: z
80
- .array(createSimpleStringSchema({ max: 20, noSpaces: true }))
81
- .max(5)
82
- .optional(),
113
+ tags: tagsSchema.optional(),
83
114
  heroImageUrl: secureUrlSchema.optional(),
84
- tagline: createSimpleStringSchema({ max: 30 }).optional(),
85
- ogTitle: createSimpleStringSchema({ max: 30 }).optional(),
86
- ogDescription: createSimpleStringSchema({ max: 100 }).optional(),
115
+ tagline: taglineSchema.optional(),
116
+ ogTitle: ogTitleSchema.optional(),
117
+ ogDescription: ogDescriptionSchema.optional(),
87
118
  ogImageUrl: secureUrlSchema.optional(),
88
119
  /** see: https://github.com/farcasterxyz/miniapps/discussions/204 */
89
- noindex: z.boolean().optional(),
120
+ noindex: noindexSchema.optional(),
90
121
  /** see https://github.com/farcasterxyz/miniapps/discussions/256 */
91
- requiredChains: z
92
- .array(z.enum(chainList))
93
- .transform(removeArrayDuplicates)
94
- .optional(),
95
- requiredCapabilities: z
96
- .array(z.enum(miniAppHostCapabilityList))
97
- .transform(removeArrayDuplicates)
98
- .optional(),
122
+ requiredChains: requiredChainsSchema.optional(),
123
+ requiredCapabilities: requiredCapabilitiesSchema.optional(),
99
124
  /** see https://github.com/farcasterxyz/miniapps/discussions/158 */
100
125
  /** Documentation will be added once this feature is finalized. */
101
126
  castShareUrl: secureUrlSchema.optional(),
package/src/types.ts CHANGED
@@ -8,6 +8,7 @@ import type {
8
8
  ComposeCast,
9
9
  OpenMiniApp,
10
10
  Ready,
11
+ RequestCameraAndMicrophoneAccess,
11
12
  SendToken,
12
13
  SignIn,
13
14
  SwapToken,
@@ -62,6 +63,7 @@ export const miniAppHostCapabilityList = [
62
63
  'actions.sendToken',
63
64
  'actions.swapToken',
64
65
  'actions.openMiniApp',
66
+ 'actions.requestCameraAndMicrophoneAccess',
65
67
  'haptics.impactOccurred',
66
68
  'haptics.notificationOccurred',
67
69
  'haptics.selectionChanged',
@@ -97,6 +99,7 @@ export type WireMiniAppHost = {
97
99
  composeCast: <close extends boolean | undefined = undefined>(
98
100
  options: ComposeCast.Options<close>,
99
101
  ) => Promise<ComposeCast.Result<close>>
102
+ requestCameraAndMicrophoneAccess: RequestCameraAndMicrophoneAccess.RequestCameraAndMicrophoneAccess
100
103
  impactOccurred: ImpactOccurred
101
104
  notificationOccurred: NotificationOccurred
102
105
  selectionChanged: SelectionChanged
@@ -131,6 +134,7 @@ export type MiniAppHost = {
131
134
  composeCast: <close extends boolean | undefined = undefined>(
132
135
  options: ComposeCast.Options<close>,
133
136
  ) => Promise<ComposeCast.Result<close>>
137
+ requestCameraAndMicrophoneAccess: RequestCameraAndMicrophoneAccess.RequestCameraAndMicrophoneAccess
134
138
  impactOccurred: ImpactOccurred
135
139
  notificationOccurred: NotificationOccurred
136
140
  selectionChanged: SelectionChanged