@floegence/floe-webapp-boot 0.15.1
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/index.d.ts +15 -0
- package/dist/index.js +89 -0
- package/package.json +27 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type WaitForMessageOptions<T> = Readonly<{
|
|
2
|
+
expectedOrigins: string[];
|
|
3
|
+
expectedSource: Window;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
accept: (data: unknown) => T | null;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function base64UrlToBase64(s: string): string;
|
|
8
|
+
export declare function parseHashParam(key: string): string | null;
|
|
9
|
+
export declare function parseBase64UrlJsonFromHash<T>(key: string): T | null;
|
|
10
|
+
export declare function clearLocationHash(): void;
|
|
11
|
+
export declare function getSessionStorage(key: string): string;
|
|
12
|
+
export declare function setSessionStorage(key: string, value: string): void;
|
|
13
|
+
export declare function removeSessionStorage(key: string): void;
|
|
14
|
+
export declare function postMessageToOrigins(target: Window, origins: string[], message: unknown): void;
|
|
15
|
+
export declare function waitForMessage<T>(opts: WaitForMessageOptions<T>): Promise<T>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
function l(e) {
|
|
2
|
+
let t = String(e ?? "").replace(/-/g, "+").replace(/_/g, "/");
|
|
3
|
+
for (; t.length % 4 !== 0; ) t += "=";
|
|
4
|
+
return t;
|
|
5
|
+
}
|
|
6
|
+
function m(e) {
|
|
7
|
+
const t = String(e ?? "").trim();
|
|
8
|
+
if (!t) return null;
|
|
9
|
+
const r = String(window.location.hash ?? "").trim(), n = r.startsWith("#") ? r.slice(1) : r;
|
|
10
|
+
if (!n) return null;
|
|
11
|
+
try {
|
|
12
|
+
const o = new URLSearchParams(n);
|
|
13
|
+
return String(o.get(t) ?? "").trim() || null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function g(e) {
|
|
19
|
+
const t = m(e);
|
|
20
|
+
if (!t) return null;
|
|
21
|
+
try {
|
|
22
|
+
const r = atob(l(t));
|
|
23
|
+
return r ? JSON.parse(r) : null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function f() {
|
|
29
|
+
try {
|
|
30
|
+
history.replaceState(null, document.title, window.location.pathname + window.location.search);
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function h(e) {
|
|
35
|
+
try {
|
|
36
|
+
return String(sessionStorage.getItem(e) ?? "").trim();
|
|
37
|
+
} catch {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function w(e, t) {
|
|
42
|
+
try {
|
|
43
|
+
sessionStorage.setItem(e, t);
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function S(e) {
|
|
48
|
+
try {
|
|
49
|
+
sessionStorage.removeItem(e);
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function d(e, t, r) {
|
|
54
|
+
const n = Array.from(new Set((t ?? []).map((o) => String(o ?? "").trim()).filter(Boolean)));
|
|
55
|
+
for (const o of n)
|
|
56
|
+
try {
|
|
57
|
+
e.postMessage(r, o);
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function p(e) {
|
|
62
|
+
const t = Array.from(new Set((e.expectedOrigins ?? []).map((n) => String(n ?? "").trim()).filter(Boolean)));
|
|
63
|
+
if (t.length === 0) return Promise.reject(new Error("expectedOrigins is required"));
|
|
64
|
+
if (!e.expectedSource) return Promise.reject(new Error("expectedSource is required"));
|
|
65
|
+
const r = Math.max(0, Math.floor(e.timeoutMs ?? 8e3));
|
|
66
|
+
return new Promise((n, o) => {
|
|
67
|
+
const s = window.setTimeout(() => {
|
|
68
|
+
c(), o(new Error("Handshake timeout"));
|
|
69
|
+
}, r), a = (i) => {
|
|
70
|
+
if (!t.includes(i.origin) || i.source !== e.expectedSource) return;
|
|
71
|
+
const u = e.accept(i.data);
|
|
72
|
+
u != null && (c(), n(u));
|
|
73
|
+
}, c = () => {
|
|
74
|
+
window.clearTimeout(s), window.removeEventListener("message", a);
|
|
75
|
+
};
|
|
76
|
+
window.addEventListener("message", a);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
l as base64UrlToBase64,
|
|
81
|
+
f as clearLocationHash,
|
|
82
|
+
h as getSessionStorage,
|
|
83
|
+
g as parseBase64UrlJsonFromHash,
|
|
84
|
+
m as parseHashParam,
|
|
85
|
+
d as postMessageToOrigins,
|
|
86
|
+
S as removeSessionStorage,
|
|
87
|
+
w as setSessionStorage,
|
|
88
|
+
p as waitForMessage
|
|
89
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@floegence/floe-webapp-boot",
|
|
3
|
+
"version": "0.15.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"dev": "vite build --watch",
|
|
19
|
+
"build": "pnpm clean && vite build && tsc -p tsconfig.build.json",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"vite": "^7.3.1"
|
|
26
|
+
}
|
|
27
|
+
}
|