@frontera-sdk/core 1.52.39 → 1.52.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontera-sdk/core",
3
- "version": "1.52.39",
3
+ "version": "1.52.41",
4
4
  "description": "Frontera app runtime: the platform bridge client, app bootstrap and typed platform client.",
5
5
  "keywords": [
6
6
  "frontera",
@@ -64,7 +64,17 @@ async function fetchSession(
64
64
  credentials: 'include',
65
65
  headers: { accept: 'application/json' },
66
66
  })
67
- if (!response.ok) throw new Error(`Frontera session request failed with ${response.status}`)
67
+ if (!response.ok) {
68
+ // The local dev server says why (`{ error }`): the runtime no longer has the App, or its credential.
69
+ let reason = ''
70
+ try {
71
+ const body = (await response.json()) as { error?: unknown }
72
+ if (typeof body?.error === 'string' && body.error) reason = `: ${body.error}`
73
+ } catch {
74
+ // No JSON body: the status is all there is.
75
+ }
76
+ throw new Error(`Frontera session request failed with ${response.status}${reason}`)
77
+ }
68
78
  return parseSessionResponse(await response.json())
69
79
  }
70
80
 
@@ -45,6 +45,14 @@ export interface BridgeInit {
45
45
  * may do is decided server-side from the token.
46
46
  */
47
47
  viewer?: FronteraViewer | null
48
+ /**
49
+ * Whether the frame shows the App's production deployment or a preview (a
50
+ * branch or session link, or one deployment opened by its own link). A
51
+ * preview reads and writes the same workspace data as production; Action
52
+ * requests it raises are labelled as coming from a preview. Absent on a
53
+ * host that predates it: treat that as production.
54
+ */
55
+ deployment?: 'production' | 'preview'
48
56
  }
49
57
 
50
58
  export interface FronteraViewer {
@@ -62,6 +62,11 @@ export interface FronteraAppValue {
62
62
  * show and prefill; never to decide what the person may do.
63
63
  */
64
64
  viewer: FronteraViewer | null
65
+ /**
66
+ * True when the host says this frame shows a preview deployment rather than
67
+ * production. Data is real either way; use it to show a "Preview" marker.
68
+ */
69
+ isPreview: boolean
65
70
  }
66
71
 
67
72
  const FronteraAppReactContext = createContext<FronteraAppValue | null>(null)
@@ -86,6 +91,14 @@ export function useViewer(): FronteraViewer | null {
86
91
  return useFronteraApp().viewer
87
92
  }
88
93
 
94
+ /**
95
+ * Whether the App is open from a preview deployment, as the host said at
96
+ * handshake. Shorthand for `useFronteraApp().isPreview`.
97
+ */
98
+ export function useIsPreview(): boolean {
99
+ return useFronteraApp().isPreview
100
+ }
101
+
89
102
  /**
90
103
  * A wrapper contributed by a domain package.
91
104
  *
@@ -519,6 +532,7 @@ function FronteraRoot({
519
532
  if (mode === 'embedded') session.send({ type: 'frontera:navigate', path })
520
533
  },
521
534
  viewer: viewerOf(init.viewer),
535
+ isPreview: init.deployment === 'preview',
522
536
  }
523
537
 
524
538
  let tree: ReactNode = children
package/src/react.ts CHANGED
@@ -2,6 +2,7 @@ export {
2
2
  FronteraAppProvider,
3
3
  useFronteraApp,
4
4
  useViewer,
5
+ useIsPreview,
5
6
  type FronteraAppProviderProps,
6
7
  type FronteraAppValue,
7
8
  type FronteraProvider,