@base44-preview/sdk 0.8.48-pr.282.c69fdcd → 0.8.48-pr.283.2de4c8a
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/README.md +18 -0
- package/dist/client.js +21 -71
- package/dist/client.types.d.ts +1 -2
- package/dist/modules/agents.d.ts +1 -1
- package/dist/modules/agents.js +4 -3
- package/dist/modules/agents.types.d.ts +2 -2
- package/dist/modules/ai-gateway.d.ts +1 -1
- package/dist/modules/ai-gateway.js +3 -2
- package/dist/modules/ai-gateway.types.d.ts +2 -2
- package/dist/modules/auth.js +4 -17
- package/dist/modules/auth.types.d.ts +0 -26
- package/dist/platform/server/client.d.ts +29 -0
- package/dist/platform/server/client.js +57 -0
- package/dist/platform/server/errors.d.ts +28 -0
- package/dist/platform/server/errors.js +20 -0
- package/dist/platform/server/index.d.ts +9 -0
- package/dist/platform/server/index.js +4 -0
- package/dist/platform/server/modules/apps.d.ts +4 -0
- package/dist/platform/server/modules/apps.js +66 -0
- package/dist/platform/server/modules/apps.types.d.ts +87 -0
- package/dist/platform/server/modules/apps.types.js +1 -0
- package/dist/platform/server/modules/users.d.ts +4 -0
- package/dist/platform/server/modules/users.js +40 -0
- package/dist/platform/server/modules/users.types.d.ts +33 -0
- package/dist/platform/server/modules/users.types.js +1 -0
- package/dist/platform/server/token-store.d.ts +11 -0
- package/dist/platform/server/token-store.js +17 -0
- package/dist/platform/server/tokens.d.ts +16 -0
- package/dist/platform/server/tokens.js +80 -0
- package/dist/platform/server/transport.d.ts +10 -0
- package/dist/platform/server/transport.js +69 -0
- package/dist/platform/server/types.d.ts +60 -0
- package/dist/platform/server/types.js +1 -0
- package/dist/platform/server/validation.d.ts +9 -0
- package/dist/platform/server/validation.js +36 -0
- package/dist/utils/auth-utils.d.ts +0 -2
- package/dist/utils/auth-utils.js +0 -11
- package/dist/utils/socket-utils.d.ts +1 -3
- package/dist/utils/socket-utils.js +2 -1
- package/package.json +41 -5
- package/dist/utils/embed-session.d.ts +0 -50
- package/dist/utils/embed-session.js +0 -140
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sessions for apps embedded in a host platform.
|
|
3
|
-
*
|
|
4
|
-
* The platform's server mints a one-time token for one of its users and puts
|
|
5
|
-
* it on the iframe URL as `?ott=`. The client takes it off the URL as it is
|
|
6
|
-
* created, trades it for an app-user session through the OAuth token-exchange
|
|
7
|
-
* grant (RFC 8693), and keeps the result in memory only — never in storage — so
|
|
8
|
-
* the session lives and dies with the frame.
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
/** The query parameter a host platform puts the one-time token on. @internal */
|
|
13
|
-
export declare const EMBED_TOKEN_PARAM = "ott";
|
|
14
|
-
/**
|
|
15
|
-
* Reads the one-time token off the current URL and strips it, so it is never
|
|
16
|
-
* left in the address bar, in history, or in a shared link.
|
|
17
|
-
*
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export declare function takeEmbedTokenFromUrl(): string | null;
|
|
21
|
-
/**
|
|
22
|
-
* Whether this tab previously redeemed an embed token. Counts only inside a
|
|
23
|
-
* frame: a top-level tab that once carried a token must fall back to the
|
|
24
|
-
* regular login, or it could never sign in again.
|
|
25
|
-
*
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export declare function isEmbeddedTab(): boolean;
|
|
29
|
-
/** @internal */
|
|
30
|
-
export declare function markEmbeddedTab(): void;
|
|
31
|
-
/**
|
|
32
|
-
* Trades a one-time embed token for an app-user session token. Resolves to
|
|
33
|
-
* `null` when the platform refuses the token; never throws.
|
|
34
|
-
*
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export declare function exchangeEmbedToken({ serverUrl, appId, ott, fetchImpl, }: {
|
|
38
|
-
serverUrl: string;
|
|
39
|
-
appId: string;
|
|
40
|
-
ott: string;
|
|
41
|
-
fetchImpl?: typeof fetch;
|
|
42
|
-
}): Promise<string | null>;
|
|
43
|
-
/**
|
|
44
|
-
* Covers the page with a plain "session ended" notice. An embedded session can
|
|
45
|
-
* only be renewed by the host platform (by reloading its own page), so this
|
|
46
|
-
* stands in for the login redirect, which cannot complete inside a frame.
|
|
47
|
-
*
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
export declare function showEmbedSessionEnded(): void;
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sessions for apps embedded in a host platform.
|
|
3
|
-
*
|
|
4
|
-
* The platform's server mints a one-time token for one of its users and puts
|
|
5
|
-
* it on the iframe URL as `?ott=`. The client takes it off the URL as it is
|
|
6
|
-
* created, trades it for an app-user session through the OAuth token-exchange
|
|
7
|
-
* grant (RFC 8693), and keeps the result in memory only — never in storage — so
|
|
8
|
-
* the session lives and dies with the frame.
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
/** The query parameter a host platform puts the one-time token on. @internal */
|
|
13
|
-
export const EMBED_TOKEN_PARAM = "ott";
|
|
14
|
-
const EMBED_TAB_KEY = "base44_embed_session";
|
|
15
|
-
const GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange";
|
|
16
|
-
const SUBJECT_TOKEN_TYPE = "urn:base44:params:oauth:token-type:embed-ott";
|
|
17
|
-
const RATE_LIMITED = 429;
|
|
18
|
-
const RATE_LIMIT_RETRY_MS = 1000;
|
|
19
|
-
const SESSION_ENDED_ELEMENT_ID = "base44-embed-session-ended";
|
|
20
|
-
/**
|
|
21
|
-
* Reads the one-time token off the current URL and strips it, so it is never
|
|
22
|
-
* left in the address bar, in history, or in a shared link.
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export function takeEmbedTokenFromUrl() {
|
|
27
|
-
if (typeof window === "undefined" || !window.location) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const url = new URL(window.location.href);
|
|
32
|
-
const ott = url.searchParams.get(EMBED_TOKEN_PARAM);
|
|
33
|
-
if (!ott) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
url.searchParams.delete(EMBED_TOKEN_PARAM);
|
|
37
|
-
window.history.replaceState(window.history.state, "", url.toString());
|
|
38
|
-
return ott;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
console.error("Error retrieving embed token from URL:", e);
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Whether this tab previously redeemed an embed token. Counts only inside a
|
|
47
|
-
* frame: a top-level tab that once carried a token must fall back to the
|
|
48
|
-
* regular login, or it could never sign in again.
|
|
49
|
-
*
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
|
-
export function isEmbeddedTab() {
|
|
53
|
-
if (typeof window === "undefined") {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
// A cross-site frame is third-party storage, which some browsers block
|
|
57
|
-
// outright — every access can throw, and the marker is then unavailable.
|
|
58
|
-
try {
|
|
59
|
-
return (window.self !== window.top &&
|
|
60
|
-
window.sessionStorage.getItem(EMBED_TAB_KEY) === "1");
|
|
61
|
-
}
|
|
62
|
-
catch (_a) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** @internal */
|
|
67
|
-
export function markEmbeddedTab() {
|
|
68
|
-
try {
|
|
69
|
-
window.sessionStorage.setItem(EMBED_TAB_KEY, "1");
|
|
70
|
-
}
|
|
71
|
-
catch (_a) {
|
|
72
|
-
/* storage blocked */
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Trades a one-time embed token for an app-user session token. Resolves to
|
|
77
|
-
* `null` when the platform refuses the token; never throws.
|
|
78
|
-
*
|
|
79
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
export async function exchangeEmbedToken({ serverUrl, appId, ott, fetchImpl = fetch, }) {
|
|
82
|
-
const post = () => fetchImpl(`${serverUrl}/api/apps/${appId}/auth/embed/token`, {
|
|
83
|
-
method: "POST",
|
|
84
|
-
headers: { "X-App-Id": String(appId) },
|
|
85
|
-
body: new URLSearchParams({
|
|
86
|
-
grant_type: GRANT_TYPE,
|
|
87
|
-
subject_token: ott,
|
|
88
|
-
subject_token_type: SUBJECT_TOKEN_TYPE,
|
|
89
|
-
}),
|
|
90
|
-
});
|
|
91
|
-
try {
|
|
92
|
-
let response = await post();
|
|
93
|
-
// The limiter refuses before the token is redeemed, so it is still valid.
|
|
94
|
-
if (response.status === RATE_LIMITED) {
|
|
95
|
-
await new Promise((resolve) => setTimeout(resolve, RATE_LIMIT_RETRY_MS));
|
|
96
|
-
response = await post();
|
|
97
|
-
}
|
|
98
|
-
if (!response.ok) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
const { access_token: token } = (await response.json());
|
|
102
|
-
return token || null;
|
|
103
|
-
}
|
|
104
|
-
catch (e) {
|
|
105
|
-
console.error("Embed token exchange failed:", e);
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Covers the page with a plain "session ended" notice. An embedded session can
|
|
111
|
-
* only be renewed by the host platform (by reloading its own page), so this
|
|
112
|
-
* stands in for the login redirect, which cannot complete inside a frame.
|
|
113
|
-
*
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
export function showEmbedSessionEnded() {
|
|
117
|
-
if (typeof document === "undefined" || !document.body) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (document.getElementById(SESSION_ENDED_ELEMENT_ID)) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const overlay = document.createElement("div");
|
|
124
|
-
overlay.id = SESSION_ENDED_ELEMENT_ID;
|
|
125
|
-
overlay.setAttribute("role", "alert");
|
|
126
|
-
overlay.style.cssText =
|
|
127
|
-
"position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;" +
|
|
128
|
-
"justify-content:center;background:#fff;color:#0f172a;" +
|
|
129
|
-
"font-family:ui-sans-serif,system-ui,sans-serif;text-align:center;padding:2rem;";
|
|
130
|
-
const title = document.createElement("h1");
|
|
131
|
-
title.textContent = "Session ended";
|
|
132
|
-
title.style.cssText = "font-size:1.5rem;font-weight:700;margin:0 0 .75rem;";
|
|
133
|
-
const body = document.createElement("p");
|
|
134
|
-
body.textContent = "Refresh the page to continue.";
|
|
135
|
-
body.style.cssText = "margin:0;color:#475569;";
|
|
136
|
-
const card = document.createElement("div");
|
|
137
|
-
card.append(title, body);
|
|
138
|
-
overlay.append(card);
|
|
139
|
-
document.body.append(overlay);
|
|
140
|
-
}
|