@microsoft/fabric-embedded-host 1.31.0 → 1.32.0

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.
@@ -11,6 +11,19 @@
11
11
  * 3. A `sessionStorage` flag persisted after step 2, so that
12
12
  * client-side navigations that strip query params keep working.
13
13
  */
14
+ /**
15
+ * Persists the embedded-mode flag to `sessionStorage` if the current
16
+ * URL contains `?fabricEmbedded=true`.
17
+ *
18
+ * Safe to call multiple times and on any page load. Returns `true`
19
+ * when the URL flag was present (whether or not it was newly written).
20
+ *
21
+ * This is invoked eagerly at module load below so that the flag is
22
+ * captured even when no consumer calls {@link isEmbeddedMode} on the
23
+ * initial render — for example when an existing session resumes from
24
+ * a refresh token and the embedded auth path is short-circuited.
25
+ */
26
+ export declare function persistEmbeddedModeFromUrl(): boolean;
14
27
  /**
15
28
  * Options accepted by {@link isEmbeddedMode}.
16
29
  *
@@ -13,6 +13,44 @@
13
13
  */
14
14
  const EMBEDDED_QUERY_PARAM = 'fabricEmbedded';
15
15
  const EMBEDDED_STORAGE_KEY = 'fabricEmbedded';
16
+ /**
17
+ * Persists the embedded-mode flag to `sessionStorage` if the current
18
+ * URL contains `?fabricEmbedded=true`.
19
+ *
20
+ * Safe to call multiple times and on any page load. Returns `true`
21
+ * when the URL flag was present (whether or not it was newly written).
22
+ *
23
+ * This is invoked eagerly at module load below so that the flag is
24
+ * captured even when no consumer calls {@link isEmbeddedMode} on the
25
+ * initial render — for example when an existing session resumes from
26
+ * a refresh token and the embedded auth path is short-circuited.
27
+ */
28
+ export function persistEmbeddedModeFromUrl() {
29
+ if (typeof window === 'undefined') {
30
+ return false;
31
+ }
32
+ try {
33
+ if (new URLSearchParams(window.location.search).get(EMBEDDED_QUERY_PARAM) ===
34
+ 'true') {
35
+ try {
36
+ sessionStorage.setItem(EMBEDDED_STORAGE_KEY, 'true');
37
+ }
38
+ catch (err) {
39
+ // sessionStorage may be unavailable in sandboxed iframes
40
+ console.warn('Unable to persist embedded mode flag to sessionStorage', err);
41
+ }
42
+ return true;
43
+ }
44
+ }
45
+ catch {
46
+ // window.location may be unavailable in some non-browser hosts
47
+ }
48
+ return false;
49
+ }
50
+ // Eagerly capture the URL flag at module load so client-side
51
+ // navigations or refresh-token resumes that bypass isEmbeddedMode()
52
+ // still leave the flag persisted for later auth calls.
53
+ persistEmbeddedModeFromUrl();
16
54
  /**
17
55
  * Detects whether the app is running in embedded mode.
18
56
  *
@@ -29,14 +67,9 @@ export function isEmbeddedMode(options) {
29
67
  if (options.fabricEmbedded === true) {
30
68
  return true;
31
69
  }
32
- if (new URLSearchParams(window.location.search).get(EMBEDDED_QUERY_PARAM) ===
33
- 'true') {
34
- try {
35
- sessionStorage.setItem(EMBEDDED_STORAGE_KEY, 'true');
36
- }
37
- catch {
38
- // sessionStorage may be unavailable in sandboxed iframes
39
- }
70
+ // Re-check the URL (and persist if present) in case the module was
71
+ // loaded before navigation added the query param.
72
+ if (persistEmbeddedModeFromUrl()) {
40
73
  return true;
41
74
  }
42
75
  try {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export type { MessageEnvelope, ResponseError, SuccessResponse, ErrorResponse, BridgeResponse, } from './MessageProtocol';
2
- export { isMessageEnvelope } from './MessageProtocol';
3
- export type { EmbeddedModeOptions } from './embeddedMode';
4
- export { isEmbeddedMode, clearEmbeddedMode } from './embeddedMode';
5
- export type { BridgeRequestOptions } from './postMessageBridge';
6
- export { BridgeError, sendBridgeRequest } from './postMessageBridge';
1
+ export type { MessageEnvelope, ResponseError, SuccessResponse, ErrorResponse, BridgeResponse, } from './MessageProtocol.js';
2
+ export { isMessageEnvelope } from './MessageProtocol.js';
3
+ export type { EmbeddedModeOptions } from './embeddedMode.js';
4
+ export { isEmbeddedMode, clearEmbeddedMode, persistEmbeddedModeFromUrl, } from './embeddedMode.js';
5
+ export type { BridgeRequestOptions } from './postMessageBridge.js';
6
+ export { BridgeError, sendBridgeRequest } from './postMessageBridge.js';
7
7
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { isMessageEnvelope } from './MessageProtocol';
2
- export { isEmbeddedMode, clearEmbeddedMode } from './embeddedMode';
3
- export { BridgeError, sendBridgeRequest } from './postMessageBridge';
1
+ export { isMessageEnvelope } from './MessageProtocol.js';
2
+ export { isEmbeddedMode, clearEmbeddedMode, persistEmbeddedModeFromUrl, } from './embeddedMode.js';
3
+ export { BridgeError, sendBridgeRequest } from './postMessageBridge.js';
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/fabric-embedded-host",
3
- "version": "1.31.0",
3
+ "version": "1.32.0",
4
4
  "description": "Shared postMessage bridge protocol and embedded mode detection for Rayfin SDKs hosted inside Fabric iframes",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "type": "module",
14
14
  "dependencies": {
15
- "@microsoft/rayfin-lib": "1.31.0"
15
+ "@microsoft/rayfin-lib": "1.32.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "typescript": "^5.8.3",
@@ -33,7 +33,7 @@
33
33
  "author": "",
34
34
  "license": "MIT",
35
35
  "scripts": {
36
- "build": "tsc",
36
+ "build": "tsc && node ../scripts/fix-esm-extensions.mjs ./dist",
37
37
  "build:watch": "tsc --watch",
38
38
  "clean": "rimraf dist && rimraf .tsbuildinfo",
39
39
  "test": "vitest run",