@farcaster/frame-sdk 0.0.0-canary-20250430152807 → 0.0.0-canary-20250508001237

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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AddFrame, ComposeCast, Context, FrameNotificationDetails, Ready, SendToken, SetPrimaryButtonOptions, SignIn, SwapToken, ViewProfile, ViewToken } from '@farcaster/frame-core';
1
+ import type { AddFrame, ComposeCast, Context, FrameNotificationDetails, Ready, SendToken, SetPrimaryButtonOptions, ShareStateProvider, SignIn, SwapToken, ViewProfile, ViewToken } from '@farcaster/frame-core';
2
2
  import type { EventEmitter } from 'eventemitter3';
3
3
  import type * as Provider from 'ox/Provider';
4
4
  declare global {
@@ -29,6 +29,7 @@ export type EventMap = {
29
29
  export type Emitter = Compute<EventEmitter<EventMap>>;
30
30
  type SetPrimaryButton = (options: SetPrimaryButtonOptions) => Promise<void>;
31
31
  export type FrameSDK = {
32
+ isInMiniApp: () => Promise<boolean>;
32
33
  context: Promise<Context.FrameContext>;
33
34
  actions: {
34
35
  ready: (options?: Partial<Ready.ReadyOptions>) => Promise<void>;
@@ -48,5 +49,6 @@ export type FrameSDK = {
48
49
  wallet: {
49
50
  ethProvider: Provider.Provider;
50
51
  };
52
+ setShareStateProvider: (fn: ShareStateProvider) => void;
51
53
  } & Emitter;
52
54
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/frame-sdk",
3
- "version": "0.0.0-canary-20250430152807",
3
+ "version": "0.0.0-canary-20250508001237",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "comlink": "^4.4.2",
23
23
  "eventemitter3": "^5.0.1",
24
24
  "ox": "^0.4.4",
25
- "@farcaster/frame-core": "0.0.0-canary-20250430152807"
25
+ "@farcaster/frame-core": "0.0.0-canary-20250508001237"
26
26
  },
27
27
  "scripts": {
28
28
  "clean": "rm -rf dist",
package/src/sdk.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { AddFrame, type FrameClientEvent, SignIn } from '@farcaster/frame-core'
1
+ import {
2
+ AddFrame,
3
+ type FrameClientEvent,
4
+ type ShareStateProvider,
5
+ SignIn,
6
+ } from '@farcaster/frame-core'
7
+ import { proxy } from 'comlink'
2
8
  import { EventEmitter } from 'eventemitter3'
3
9
  import { frameHost } from './frameHost'
4
10
  import { provider } from './provider'
@@ -28,9 +34,52 @@ export function createEmitter(): Emitter {
28
34
  }
29
35
 
30
36
  const emitter = createEmitter()
37
+ let cachedIsInMiniAppResult: boolean | null = null
38
+
39
+ /**
40
+ * Determines if the current environment is a MiniApp context.
41
+ *
42
+ * @param timeoutMs - Optional timeout in milliseconds (default: 50)
43
+ * @returns Promise resolving to boolean indicating if in MiniApp context
44
+ */
45
+ async function isInMiniApp(timeoutMs = 50): Promise<boolean> {
46
+ // Return cached result if we've already determined we are in a MiniApp
47
+ if (cachedIsInMiniAppResult === true) {
48
+ return true
49
+ }
50
+
51
+ // Check for SSR environment - definitely not a MiniApp
52
+ if (typeof window === 'undefined') {
53
+ return false
54
+ }
55
+
56
+ // Short-circuit: definitely NOT a MiniApp
57
+ if (!window.ReactNativeWebView && window === window.parent) {
58
+ return false
59
+ }
60
+
61
+ // At this point, we MIGHT be in a MiniApp (iframe or RN WebView)
62
+ // but need to verify by checking for context communication.
63
+ const isInMiniApp = await Promise.race([
64
+ frameHost.context.then((context) => !!context), // Check if context resolves to truthy
65
+ new Promise<boolean>((resolve) => {
66
+ setTimeout(() => resolve(false), timeoutMs) // Timeout resolves to false
67
+ }),
68
+ ]).catch(() => {
69
+ return false
70
+ })
71
+
72
+ // Cache the result ONLY if true (we are confirmed to be in a MiniApp)
73
+ if (isInMiniApp) {
74
+ cachedIsInMiniAppResult = true
75
+ }
76
+
77
+ return isInMiniApp
78
+ }
31
79
 
32
80
  export const sdk: FrameSDK = {
33
81
  ...emitter,
82
+ isInMiniApp,
34
83
  context: frameHost.context,
35
84
  actions: {
36
85
  setPrimaryButton: frameHost.setPrimaryButton.bind(frameHost),
@@ -81,6 +130,9 @@ export const sdk: FrameSDK = {
81
130
  wallet: {
82
131
  ethProvider: provider,
83
132
  },
133
+ setShareStateProvider: (fn: ShareStateProvider) => {
134
+ frameHost.setShareStateProvider.bind(frameHost)(proxy(fn))
135
+ },
84
136
  }
85
137
 
86
138
  // Required to pass SSR
package/src/types.ts CHANGED
@@ -6,6 +6,7 @@ import type {
6
6
  Ready,
7
7
  SendToken,
8
8
  SetPrimaryButtonOptions,
9
+ ShareStateProvider,
9
10
  SignIn,
10
11
  SwapToken,
11
12
  ViewProfile,
@@ -51,6 +52,7 @@ export type Emitter = Compute<EventEmitter<EventMap>>
51
52
  type SetPrimaryButton = (options: SetPrimaryButtonOptions) => Promise<void>
52
53
 
53
54
  export type FrameSDK = {
55
+ isInMiniApp: () => Promise<boolean>
54
56
  context: Promise<Context.FrameContext>
55
57
  actions: {
56
58
  ready: (options?: Partial<Ready.ReadyOptions>) => Promise<void>
@@ -72,4 +74,5 @@ export type FrameSDK = {
72
74
  wallet: {
73
75
  ethProvider: Provider.Provider
74
76
  }
77
+ setShareStateProvider: (fn: ShareStateProvider) => void
75
78
  } & Emitter