@mitralab.io/platform-sdk 1.4.1 → 1.5.0-beta.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/CHANGELOG.md +22 -0
- package/README.md +57 -509
- package/dist/index.cjs +133 -24
- package/dist/index.d.cts +53 -3
- package/dist/index.d.ts +53 -3
- package/dist/index.js +133 -24
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -327,6 +327,9 @@ function resolveAuthPageUrl(apiUrl, configuredAuthPageUrl, browserWindow = globa
|
|
|
327
327
|
function stripBearer(token) {
|
|
328
328
|
return token.replace(/^\s*(?:bearer\s+)+/i, "").trim();
|
|
329
329
|
}
|
|
330
|
+
function toSessionTokens(session) {
|
|
331
|
+
return { token: stripBearer(session.token), refreshToken: session.refreshToken ?? null };
|
|
332
|
+
}
|
|
330
333
|
var LegacySessionBridge = class {
|
|
331
334
|
auth;
|
|
332
335
|
appId;
|
|
@@ -371,7 +374,7 @@ var LegacySessionBridge = class {
|
|
|
371
374
|
authUrl: this.legacyUrl,
|
|
372
375
|
authPageUrl,
|
|
373
376
|
projectId: this.appId,
|
|
374
|
-
onTokenRefresh: (session2) => this.
|
|
377
|
+
onTokenRefresh: (session2) => this.rotate(session2),
|
|
375
378
|
...session.token ? { token: session.token } : {},
|
|
376
379
|
...session.refreshToken ? { refreshToken: session.refreshToken } : {}
|
|
377
380
|
});
|
|
@@ -382,16 +385,24 @@ var LegacySessionBridge = class {
|
|
|
382
385
|
}
|
|
383
386
|
}
|
|
384
387
|
/**
|
|
385
|
-
* Stores a session produced by
|
|
388
|
+
* Stores a session produced by a legacy login. The AuthModule subscription
|
|
386
389
|
* then writes that session back to the process-wide legacy config and
|
|
387
390
|
* reinstates the refresh hook removed by legacy login.
|
|
388
391
|
*/
|
|
389
392
|
adopt(session) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
393
|
+
if (!this.auth.adoptSession(toSessionTokens(session))) {
|
|
394
|
+
this.syncToLegacy(this.auth.readSessionTokens());
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Stores tokens the legacy SDK silently refreshed for the session already in
|
|
399
|
+
* place. Unlike a legacy login, it keeps the extra login tokens of the client
|
|
400
|
+
* when the renewed token belongs to the same person.
|
|
401
|
+
*/
|
|
402
|
+
rotate(session) {
|
|
403
|
+
if (!this.auth.rotateSession(toSessionTokens(session))) {
|
|
404
|
+
this.syncToLegacy(this.auth.readSessionTokens());
|
|
405
|
+
}
|
|
395
406
|
}
|
|
396
407
|
};
|
|
397
408
|
var activeBridge = null;
|
|
@@ -474,6 +485,34 @@ var PROVIDERS = {
|
|
|
474
485
|
var POPUP_WIDTH = 480;
|
|
475
486
|
var POPUP_HEIGHT = 600;
|
|
476
487
|
var POPUP_CLOSED_POLL_MS = 500;
|
|
488
|
+
function isPlainObject(value) {
|
|
489
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
490
|
+
}
|
|
491
|
+
function isNonEmptyString(value) {
|
|
492
|
+
return typeof value === "string" && value.trim() !== "";
|
|
493
|
+
}
|
|
494
|
+
function readSessionPair(value) {
|
|
495
|
+
if (!isPlainObject(value)) return null;
|
|
496
|
+
const { accessToken, refreshToken, tokenType } = value;
|
|
497
|
+
if (!isNonEmptyString(accessToken) || !isNonEmptyString(refreshToken) || !isNonEmptyString(tokenType)) {
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
return Object.freeze({ accessToken, refreshToken, tokenType });
|
|
501
|
+
}
|
|
502
|
+
function readMitraSpaceToken(value) {
|
|
503
|
+
if (!isPlainObject(value)) return null;
|
|
504
|
+
const { token, tokenType } = value;
|
|
505
|
+
if (!isNonEmptyString(token) || !isNonEmptyString(tokenType)) return null;
|
|
506
|
+
return Object.freeze({ token, tokenType });
|
|
507
|
+
}
|
|
508
|
+
function normalizeAllTokens(value) {
|
|
509
|
+
if (!isPlainObject(value)) return void 0;
|
|
510
|
+
return Object.freeze({
|
|
511
|
+
platform: readSessionPair(value.platform),
|
|
512
|
+
mitraSpace: readMitraSpaceToken(value.mitraSpace),
|
|
513
|
+
b2bToken: readSessionPair(value.b2bToken)
|
|
514
|
+
});
|
|
515
|
+
}
|
|
477
516
|
function expectAuthTokenResponse(value) {
|
|
478
517
|
const response = (0, import_sdk_core2.expectObject)(
|
|
479
518
|
value,
|
|
@@ -481,16 +520,18 @@ function expectAuthTokenResponse(value) {
|
|
|
481
520
|
coreErrors
|
|
482
521
|
);
|
|
483
522
|
for (const field of ["accessToken", "refreshToken", "tokenType"]) {
|
|
484
|
-
if (
|
|
523
|
+
if (!isNonEmptyString(response[field])) {
|
|
485
524
|
throw coreErrors.invalidResponse(
|
|
486
525
|
`Authentication token response has an invalid ${field} field`
|
|
487
526
|
);
|
|
488
527
|
}
|
|
489
528
|
}
|
|
529
|
+
const allTokens = normalizeAllTokens(response.allTokens);
|
|
490
530
|
return {
|
|
491
531
|
accessToken: response.accessToken,
|
|
492
532
|
refreshToken: response.refreshToken,
|
|
493
|
-
tokenType: response.tokenType
|
|
533
|
+
tokenType: response.tokenType,
|
|
534
|
+
...allTokens ? { allTokens } : {}
|
|
494
535
|
};
|
|
495
536
|
}
|
|
496
537
|
var AuthPageFlow = class {
|
|
@@ -1075,11 +1116,27 @@ function belongsToApp(token, appId) {
|
|
|
1075
1116
|
if (!payload) return true;
|
|
1076
1117
|
return payload.app_id === appId;
|
|
1077
1118
|
}
|
|
1119
|
+
function subjectOf(token) {
|
|
1120
|
+
const sub = decodeJwtPayload(token)?.sub;
|
|
1121
|
+
return typeof sub === "string" && sub !== "" ? sub : null;
|
|
1122
|
+
}
|
|
1078
1123
|
function isTokenExpiring(token, minValidityMs) {
|
|
1079
1124
|
const exp = decodeJwtPayload(token)?.exp;
|
|
1080
1125
|
if (typeof exp !== "number" || !Number.isFinite(exp)) return false;
|
|
1081
1126
|
return exp * 1e3 - Date.now() < minValidityMs;
|
|
1082
1127
|
}
|
|
1128
|
+
function discardEmptyAllTokens(tokens) {
|
|
1129
|
+
if (!tokens || !tokens.platform && !tokens.mitraSpace && !tokens.b2bToken) return null;
|
|
1130
|
+
return tokens;
|
|
1131
|
+
}
|
|
1132
|
+
function mergeAllTokens(current, incoming) {
|
|
1133
|
+
if (!incoming) return null;
|
|
1134
|
+
return discardEmptyAllTokens(Object.freeze({
|
|
1135
|
+
platform: incoming.platform,
|
|
1136
|
+
mitraSpace: incoming.mitraSpace ?? current?.mitraSpace ?? null,
|
|
1137
|
+
b2bToken: incoming.b2bToken ?? current?.b2bToken ?? null
|
|
1138
|
+
}));
|
|
1139
|
+
}
|
|
1083
1140
|
function isDefinitiveRefreshFailure(error) {
|
|
1084
1141
|
return error instanceof MitraApiError && error.status >= 400 && error.status < 500 && error.status !== 408 && error.status !== 429;
|
|
1085
1142
|
}
|
|
@@ -1089,6 +1146,7 @@ var AuthModule = class {
|
|
|
1089
1146
|
_currentUser = null;
|
|
1090
1147
|
#accessToken = null;
|
|
1091
1148
|
#refreshToken = null;
|
|
1149
|
+
#allTokens = null;
|
|
1092
1150
|
sessionGeneration = 0;
|
|
1093
1151
|
refreshFlight = null;
|
|
1094
1152
|
transientRefreshFailureGeneration = null;
|
|
@@ -1154,7 +1212,8 @@ var AuthModule = class {
|
|
|
1154
1212
|
handleUnauthorized: (requestToken) => this.handleUnauthorized(requestToken),
|
|
1155
1213
|
readSessionTokens: () => this.readSessionTokens(),
|
|
1156
1214
|
onSessionChange: (callback) => this.onSessionChange(callback),
|
|
1157
|
-
adoptSession: (session) => this.adoptSession(session)
|
|
1215
|
+
adoptSession: (session) => this.adoptSession(session),
|
|
1216
|
+
rotateSession: (session) => this.rotateSession(session)
|
|
1158
1217
|
});
|
|
1159
1218
|
}
|
|
1160
1219
|
/** The currently authenticated user, or null. */
|
|
@@ -1165,16 +1224,32 @@ var AuthModule = class {
|
|
|
1165
1224
|
get accessToken() {
|
|
1166
1225
|
return this.#accessToken;
|
|
1167
1226
|
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Extra tokens IAM issues at login for apps enabled server-side, or `null`
|
|
1229
|
+
* when IAM did not send them. They are reset by every new session and updated
|
|
1230
|
+
* on each app refresh, and these changes are not announced to auth-state
|
|
1231
|
+
* listeners, so read them here right before use instead of caching them.
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```typescript
|
|
1235
|
+
* const b2bAccessToken = mitra.auth.allTokens?.b2bToken?.accessToken;
|
|
1236
|
+
* ```
|
|
1237
|
+
*/
|
|
1238
|
+
get allTokens() {
|
|
1239
|
+
return this.#allTokens;
|
|
1240
|
+
}
|
|
1168
1241
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
1169
1242
|
get isAuthenticated() {
|
|
1170
1243
|
return this._currentUser !== null && this.#accessToken !== null;
|
|
1171
1244
|
}
|
|
1172
1245
|
/** @deprecated Email/password authentication is not implemented by IAM. Use signInWithEmail() or SSO. */
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1246
|
+
signIn(_credentials) {
|
|
1247
|
+
return Promise.reject(
|
|
1248
|
+
new MitraApiError(
|
|
1249
|
+
"Email/password authentication is not available. Use signInWithEmail(), signInWithGoogle() or signInWithMicrosoft().",
|
|
1250
|
+
0,
|
|
1251
|
+
"UNSUPPORTED_AUTH_METHOD"
|
|
1252
|
+
)
|
|
1178
1253
|
);
|
|
1179
1254
|
}
|
|
1180
1255
|
/**
|
|
@@ -1247,6 +1322,7 @@ var AuthModule = class {
|
|
|
1247
1322
|
this.invalidatePendingRefreshes();
|
|
1248
1323
|
this.#accessToken = token;
|
|
1249
1324
|
this.#refreshToken = null;
|
|
1325
|
+
this.#allTokens = null;
|
|
1250
1326
|
const user = await this.getCurrentUser();
|
|
1251
1327
|
this._currentUser = user;
|
|
1252
1328
|
this.notifySessionListeners();
|
|
@@ -1415,11 +1491,13 @@ var AuthModule = class {
|
|
|
1415
1491
|
return tokenResponse ? this.establishSession(tokenResponse) : null;
|
|
1416
1492
|
}
|
|
1417
1493
|
/** @deprecated Email/password registration is not implemented by IAM. Use signInWithEmail() or SSO. */
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1494
|
+
signUp(_data) {
|
|
1495
|
+
return Promise.reject(
|
|
1496
|
+
new MitraApiError(
|
|
1497
|
+
"Email/password registration is not available. Use signInWithEmail(), signInWithGoogle() or signInWithMicrosoft().",
|
|
1498
|
+
0,
|
|
1499
|
+
"UNSUPPORTED_AUTH_METHOD"
|
|
1500
|
+
)
|
|
1423
1501
|
);
|
|
1424
1502
|
}
|
|
1425
1503
|
/**
|
|
@@ -1544,7 +1622,8 @@ var AuthModule = class {
|
|
|
1544
1622
|
/**
|
|
1545
1623
|
* Sets the access token manually (e.g., from SSO/OAuth callback).
|
|
1546
1624
|
*
|
|
1547
|
-
* Call `me()` afterwards to fetch the associated user data.
|
|
1625
|
+
* Call `me()` afterwards to fetch the associated user data. {@link allTokens}
|
|
1626
|
+
* goes back to `null`, because it belongs to the session being replaced.
|
|
1548
1627
|
*
|
|
1549
1628
|
* @param token - JWT access token.
|
|
1550
1629
|
* @param saveToStorage - Whether to persist to localStorage (default: true).
|
|
@@ -1562,6 +1641,7 @@ var AuthModule = class {
|
|
|
1562
1641
|
}
|
|
1563
1642
|
this.invalidatePendingRefreshes();
|
|
1564
1643
|
this.#accessToken = token;
|
|
1644
|
+
this.#allTokens = null;
|
|
1565
1645
|
if (saveToStorage) {
|
|
1566
1646
|
this.saveToStorage();
|
|
1567
1647
|
}
|
|
@@ -1586,6 +1666,8 @@ var AuthModule = class {
|
|
|
1586
1666
|
* This preserves the access and refresh tokens together so the normal refresh
|
|
1587
1667
|
* lifecycle continues after an embedded preview hands its session to the app.
|
|
1588
1668
|
* Call {@link checkAuth} afterward to validate the token and hydrate the user.
|
|
1669
|
+
* {@link allTokens} goes back to `null`, because it belongs to the session
|
|
1670
|
+
* being replaced.
|
|
1589
1671
|
*/
|
|
1590
1672
|
setSession(session) {
|
|
1591
1673
|
return this.adoptSession({
|
|
@@ -1641,18 +1723,37 @@ var AuthModule = class {
|
|
|
1641
1723
|
*
|
|
1642
1724
|
* Replaces the in-memory tokens and persists them under the same storage key
|
|
1643
1725
|
* the rest of the module uses. The current user is left untouched because the
|
|
1644
|
-
* legacy SDK does not return one; call `me()` to hydrate it.
|
|
1726
|
+
* legacy SDK does not return one; call `me()` to hydrate it. It is a new
|
|
1727
|
+
* session, so the extra login tokens of the previous one are dropped.
|
|
1645
1728
|
*
|
|
1646
1729
|
* @param session - Access token and, when the issuer returned one, refresh token.
|
|
1647
1730
|
*
|
|
1648
1731
|
* @internal
|
|
1649
1732
|
*/
|
|
1650
1733
|
adoptSession(session) {
|
|
1734
|
+
return this.applySession(session, false);
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Stores tokens another issuer rotated for the session already in place, such
|
|
1738
|
+
* as a silent refresh performed by the legacy SDK. The extra login tokens are
|
|
1739
|
+
* kept only when the rotated token belongs to the same person.
|
|
1740
|
+
*
|
|
1741
|
+
* @internal
|
|
1742
|
+
*/
|
|
1743
|
+
rotateSession(session) {
|
|
1744
|
+
return this.applySession(session, this.isSamePerson(session.token));
|
|
1745
|
+
}
|
|
1746
|
+
isSamePerson(token) {
|
|
1747
|
+
const current = this.#accessToken ? subjectOf(this.#accessToken) : null;
|
|
1748
|
+
return current !== null && current === subjectOf(token);
|
|
1749
|
+
}
|
|
1750
|
+
applySession(session, keepAllTokens) {
|
|
1651
1751
|
if (!this.belongsToConfiguredApp(session.token) || typeof session.refreshToken === "string" && !this.belongsToConfiguredApp(session.refreshToken)) {
|
|
1652
1752
|
this.clearAuthState();
|
|
1653
1753
|
return false;
|
|
1654
1754
|
}
|
|
1655
1755
|
this.invalidatePendingRefreshes();
|
|
1756
|
+
if (!keepAllTokens) this.#allTokens = null;
|
|
1656
1757
|
this.#accessToken = session.token;
|
|
1657
1758
|
if (session.refreshToken !== void 0) {
|
|
1658
1759
|
this.#refreshToken = session.refreshToken;
|
|
@@ -1728,6 +1829,7 @@ var AuthModule = class {
|
|
|
1728
1829
|
}
|
|
1729
1830
|
this.#accessToken = tokenResponse.accessToken;
|
|
1730
1831
|
this.#refreshToken = tokenResponse.refreshToken;
|
|
1832
|
+
this.#allTokens = mergeAllTokens(this.#allTokens, tokenResponse.allTokens);
|
|
1731
1833
|
this.transientRefreshFailureGeneration = null;
|
|
1732
1834
|
this.saveToStorage();
|
|
1733
1835
|
this.notifySessionListeners();
|
|
@@ -1742,6 +1844,7 @@ var AuthModule = class {
|
|
|
1742
1844
|
const generation = this.sessionGeneration;
|
|
1743
1845
|
this.#accessToken = tokenResponse.accessToken;
|
|
1744
1846
|
this.#refreshToken = tokenResponse.refreshToken;
|
|
1847
|
+
this.#allTokens = discardEmptyAllTokens(tokenResponse.allTokens);
|
|
1745
1848
|
try {
|
|
1746
1849
|
const user = await this.getCurrentUser();
|
|
1747
1850
|
if (generation !== this.sessionGeneration) {
|
|
@@ -1774,6 +1877,7 @@ var AuthModule = class {
|
|
|
1774
1877
|
this._currentUser = null;
|
|
1775
1878
|
this.#accessToken = null;
|
|
1776
1879
|
this.#refreshToken = null;
|
|
1880
|
+
this.#allTokens = null;
|
|
1777
1881
|
this.removeFromStorage();
|
|
1778
1882
|
if (hadAuthState) {
|
|
1779
1883
|
this.notifySessionListeners();
|
|
@@ -1829,7 +1933,11 @@ var AuthModule = class {
|
|
|
1829
1933
|
JSON.stringify({
|
|
1830
1934
|
user: this._currentUser,
|
|
1831
1935
|
token: this.#accessToken,
|
|
1832
|
-
refreshToken: this.#refreshToken
|
|
1936
|
+
refreshToken: this.#refreshToken,
|
|
1937
|
+
// Persisted with the session on purpose: IAM issues mitraSpace and
|
|
1938
|
+
// b2bToken only at login, so keeping them in memory alone would lose
|
|
1939
|
+
// them on the first reload.
|
|
1940
|
+
...this.#allTokens ? { allTokens: this.#allTokens } : {}
|
|
1833
1941
|
})
|
|
1834
1942
|
);
|
|
1835
1943
|
} catch {
|
|
@@ -1840,7 +1948,7 @@ var AuthModule = class {
|
|
|
1840
1948
|
try {
|
|
1841
1949
|
const stored = localStorage.getItem(this.storageKey);
|
|
1842
1950
|
if (stored) {
|
|
1843
|
-
const { user, token, refreshToken } = JSON.parse(stored);
|
|
1951
|
+
const { user, token, refreshToken, allTokens } = JSON.parse(stored);
|
|
1844
1952
|
if (typeof token !== "string" || refreshToken !== null && refreshToken !== void 0 && typeof refreshToken !== "string" || !this.belongsToConfiguredApp(token) || typeof refreshToken === "string" && !this.belongsToConfiguredApp(refreshToken)) {
|
|
1845
1953
|
this.clearAuthState();
|
|
1846
1954
|
return;
|
|
@@ -1848,6 +1956,7 @@ var AuthModule = class {
|
|
|
1848
1956
|
this._currentUser = user;
|
|
1849
1957
|
this.#accessToken = token;
|
|
1850
1958
|
this.#refreshToken = refreshToken ?? null;
|
|
1959
|
+
this.#allTokens = discardEmptyAllTokens(normalizeAllTokens(allTokens));
|
|
1851
1960
|
this.invalidatePendingRefreshes();
|
|
1852
1961
|
}
|
|
1853
1962
|
} catch {
|
package/dist/index.d.cts
CHANGED
|
@@ -252,6 +252,30 @@ interface EmailCodeVerification {
|
|
|
252
252
|
receipt: string;
|
|
253
253
|
code: string;
|
|
254
254
|
}
|
|
255
|
+
/** A one-hour IAM session pair, renewed at the `refresh-token` route of the IAM that issued it. */
|
|
256
|
+
interface PlatformSessionTokens {
|
|
257
|
+
readonly accessToken: string;
|
|
258
|
+
readonly refreshToken: string;
|
|
259
|
+
readonly tokenType: string;
|
|
260
|
+
}
|
|
261
|
+
/** Long-lived mitraSpace token issued at login. It has no refresh flow. */
|
|
262
|
+
interface MitraSpaceToken {
|
|
263
|
+
readonly token: string;
|
|
264
|
+
readonly tokenType: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Extra tokens IAM returns at login only for apps enabled server-side. The SDK
|
|
268
|
+
* hands out frozen instances: the object is persisted with the session, so a
|
|
269
|
+
* write into it would reach storage on the next save.
|
|
270
|
+
*/
|
|
271
|
+
interface AllTokens {
|
|
272
|
+
/** Session in the workspace IAM picked for the person, or null when there is none. */
|
|
273
|
+
readonly platform: PlatformSessionTokens | null;
|
|
274
|
+
/** Null when mitraSpace is unreachable or the person has no account there. */
|
|
275
|
+
readonly mitraSpace: MitraSpaceToken | null;
|
|
276
|
+
/** Session of the same person in the IAM of another environment, or null on any failure there. */
|
|
277
|
+
readonly b2bToken: PlatformSessionTokens | null;
|
|
278
|
+
}
|
|
255
279
|
/** Callback for auth state changes. Receives the user on login, null on logout. */
|
|
256
280
|
type AuthStateChangeCallback = (user: User | null) => void;
|
|
257
281
|
|
|
@@ -299,6 +323,18 @@ declare class AuthModule {
|
|
|
299
323
|
get currentUser(): User | null;
|
|
300
324
|
/** The current JWT access token, or null. */
|
|
301
325
|
get accessToken(): string | null;
|
|
326
|
+
/**
|
|
327
|
+
* Extra tokens IAM issues at login for apps enabled server-side, or `null`
|
|
328
|
+
* when IAM did not send them. They are reset by every new session and updated
|
|
329
|
+
* on each app refresh, and these changes are not announced to auth-state
|
|
330
|
+
* listeners, so read them here right before use instead of caching them.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* const b2bAccessToken = mitra.auth.allTokens?.b2bToken?.accessToken;
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
get allTokens(): AllTokens | null;
|
|
302
338
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
303
339
|
get isAuthenticated(): boolean;
|
|
304
340
|
/** @deprecated Email/password authentication is not implemented by IAM. Use signInWithEmail() or SSO. */
|
|
@@ -569,7 +605,8 @@ declare class AuthModule {
|
|
|
569
605
|
/**
|
|
570
606
|
* Sets the access token manually (e.g., from SSO/OAuth callback).
|
|
571
607
|
*
|
|
572
|
-
* Call `me()` afterwards to fetch the associated user data.
|
|
608
|
+
* Call `me()` afterwards to fetch the associated user data. {@link allTokens}
|
|
609
|
+
* goes back to `null`, because it belongs to the session being replaced.
|
|
573
610
|
*
|
|
574
611
|
* @param token - JWT access token.
|
|
575
612
|
* @param saveToStorage - Whether to persist to localStorage (default: true).
|
|
@@ -598,6 +635,8 @@ declare class AuthModule {
|
|
|
598
635
|
* This preserves the access and refresh tokens together so the normal refresh
|
|
599
636
|
* lifecycle continues after an embedded preview hands its session to the app.
|
|
600
637
|
* Call {@link checkAuth} afterward to validate the token and hydrate the user.
|
|
638
|
+
* {@link allTokens} goes back to `null`, because it belongs to the session
|
|
639
|
+
* being replaced.
|
|
601
640
|
*/
|
|
602
641
|
setSession(session: AuthSession): boolean;
|
|
603
642
|
/**
|
|
@@ -634,13 +673,24 @@ declare class AuthModule {
|
|
|
634
673
|
*
|
|
635
674
|
* Replaces the in-memory tokens and persists them under the same storage key
|
|
636
675
|
* the rest of the module uses. The current user is left untouched because the
|
|
637
|
-
* legacy SDK does not return one; call `me()` to hydrate it.
|
|
676
|
+
* legacy SDK does not return one; call `me()` to hydrate it. It is a new
|
|
677
|
+
* session, so the extra login tokens of the previous one are dropped.
|
|
638
678
|
*
|
|
639
679
|
* @param session - Access token and, when the issuer returned one, refresh token.
|
|
640
680
|
*
|
|
641
681
|
* @internal
|
|
642
682
|
*/
|
|
643
683
|
private adoptSession;
|
|
684
|
+
/**
|
|
685
|
+
* Stores tokens another issuer rotated for the session already in place, such
|
|
686
|
+
* as a silent refresh performed by the legacy SDK. The extra login tokens are
|
|
687
|
+
* kept only when the rotated token belongs to the same person.
|
|
688
|
+
*
|
|
689
|
+
* @internal
|
|
690
|
+
*/
|
|
691
|
+
private rotateSession;
|
|
692
|
+
private isSamePerson;
|
|
693
|
+
private applySession;
|
|
644
694
|
/**
|
|
645
695
|
* Redirects to `/login?returnUrl=...` for unauthenticated users.
|
|
646
696
|
*
|
|
@@ -1173,4 +1223,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
|
|
|
1173
1223
|
/** @deprecated Legacy compatibility type. */
|
|
1174
1224
|
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
1175
1225
|
|
|
1176
|
-
export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailCodeLanguage, type EmailCodeRequest, type EmailCodeRequestResult, type EmailCodeVerification, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
|
|
1226
|
+
export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AllTokens, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailCodeLanguage, type EmailCodeRequest, type EmailCodeRequestResult, type EmailCodeVerification, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type MitraSpaceToken, type PatchRecordOptions, type PlatformSessionTokens, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
|
package/dist/index.d.ts
CHANGED
|
@@ -252,6 +252,30 @@ interface EmailCodeVerification {
|
|
|
252
252
|
receipt: string;
|
|
253
253
|
code: string;
|
|
254
254
|
}
|
|
255
|
+
/** A one-hour IAM session pair, renewed at the `refresh-token` route of the IAM that issued it. */
|
|
256
|
+
interface PlatformSessionTokens {
|
|
257
|
+
readonly accessToken: string;
|
|
258
|
+
readonly refreshToken: string;
|
|
259
|
+
readonly tokenType: string;
|
|
260
|
+
}
|
|
261
|
+
/** Long-lived mitraSpace token issued at login. It has no refresh flow. */
|
|
262
|
+
interface MitraSpaceToken {
|
|
263
|
+
readonly token: string;
|
|
264
|
+
readonly tokenType: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Extra tokens IAM returns at login only for apps enabled server-side. The SDK
|
|
268
|
+
* hands out frozen instances: the object is persisted with the session, so a
|
|
269
|
+
* write into it would reach storage on the next save.
|
|
270
|
+
*/
|
|
271
|
+
interface AllTokens {
|
|
272
|
+
/** Session in the workspace IAM picked for the person, or null when there is none. */
|
|
273
|
+
readonly platform: PlatformSessionTokens | null;
|
|
274
|
+
/** Null when mitraSpace is unreachable or the person has no account there. */
|
|
275
|
+
readonly mitraSpace: MitraSpaceToken | null;
|
|
276
|
+
/** Session of the same person in the IAM of another environment, or null on any failure there. */
|
|
277
|
+
readonly b2bToken: PlatformSessionTokens | null;
|
|
278
|
+
}
|
|
255
279
|
/** Callback for auth state changes. Receives the user on login, null on logout. */
|
|
256
280
|
type AuthStateChangeCallback = (user: User | null) => void;
|
|
257
281
|
|
|
@@ -299,6 +323,18 @@ declare class AuthModule {
|
|
|
299
323
|
get currentUser(): User | null;
|
|
300
324
|
/** The current JWT access token, or null. */
|
|
301
325
|
get accessToken(): string | null;
|
|
326
|
+
/**
|
|
327
|
+
* Extra tokens IAM issues at login for apps enabled server-side, or `null`
|
|
328
|
+
* when IAM did not send them. They are reset by every new session and updated
|
|
329
|
+
* on each app refresh, and these changes are not announced to auth-state
|
|
330
|
+
* listeners, so read them here right before use instead of caching them.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```typescript
|
|
334
|
+
* const b2bAccessToken = mitra.auth.allTokens?.b2bToken?.accessToken;
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
get allTokens(): AllTokens | null;
|
|
302
338
|
/** Whether a user is currently authenticated (local check, not server-validated). */
|
|
303
339
|
get isAuthenticated(): boolean;
|
|
304
340
|
/** @deprecated Email/password authentication is not implemented by IAM. Use signInWithEmail() or SSO. */
|
|
@@ -569,7 +605,8 @@ declare class AuthModule {
|
|
|
569
605
|
/**
|
|
570
606
|
* Sets the access token manually (e.g., from SSO/OAuth callback).
|
|
571
607
|
*
|
|
572
|
-
* Call `me()` afterwards to fetch the associated user data.
|
|
608
|
+
* Call `me()` afterwards to fetch the associated user data. {@link allTokens}
|
|
609
|
+
* goes back to `null`, because it belongs to the session being replaced.
|
|
573
610
|
*
|
|
574
611
|
* @param token - JWT access token.
|
|
575
612
|
* @param saveToStorage - Whether to persist to localStorage (default: true).
|
|
@@ -598,6 +635,8 @@ declare class AuthModule {
|
|
|
598
635
|
* This preserves the access and refresh tokens together so the normal refresh
|
|
599
636
|
* lifecycle continues after an embedded preview hands its session to the app.
|
|
600
637
|
* Call {@link checkAuth} afterward to validate the token and hydrate the user.
|
|
638
|
+
* {@link allTokens} goes back to `null`, because it belongs to the session
|
|
639
|
+
* being replaced.
|
|
601
640
|
*/
|
|
602
641
|
setSession(session: AuthSession): boolean;
|
|
603
642
|
/**
|
|
@@ -634,13 +673,24 @@ declare class AuthModule {
|
|
|
634
673
|
*
|
|
635
674
|
* Replaces the in-memory tokens and persists them under the same storage key
|
|
636
675
|
* the rest of the module uses. The current user is left untouched because the
|
|
637
|
-
* legacy SDK does not return one; call `me()` to hydrate it.
|
|
676
|
+
* legacy SDK does not return one; call `me()` to hydrate it. It is a new
|
|
677
|
+
* session, so the extra login tokens of the previous one are dropped.
|
|
638
678
|
*
|
|
639
679
|
* @param session - Access token and, when the issuer returned one, refresh token.
|
|
640
680
|
*
|
|
641
681
|
* @internal
|
|
642
682
|
*/
|
|
643
683
|
private adoptSession;
|
|
684
|
+
/**
|
|
685
|
+
* Stores tokens another issuer rotated for the session already in place, such
|
|
686
|
+
* as a silent refresh performed by the legacy SDK. The extra login tokens are
|
|
687
|
+
* kept only when the rotated token belongs to the same person.
|
|
688
|
+
*
|
|
689
|
+
* @internal
|
|
690
|
+
*/
|
|
691
|
+
private rotateSession;
|
|
692
|
+
private isSamePerson;
|
|
693
|
+
private applySession;
|
|
644
694
|
/**
|
|
645
695
|
* Redirects to `/login?returnUrl=...` for unauthenticated users.
|
|
646
696
|
*
|
|
@@ -1173,4 +1223,4 @@ type StopServerFunctionExecutionResponse = LegacyTypes.StopServerFunctionExecuti
|
|
|
1173
1223
|
/** @deprecated Legacy compatibility type. */
|
|
1174
1224
|
type UpdateRecordOptions = LegacyTypes.UpdateRecordOptions;
|
|
1175
1225
|
|
|
1176
|
-
export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailCodeLanguage, type EmailCodeRequest, type EmailCodeRequestResult, type EmailCodeVerification, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type PatchRecordOptions, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
|
|
1226
|
+
export { type AgentChat, type AgentCredentialProvider, type AgentCredentialStatus, type AgentCredentialsModule, type AgentDeltaEvent, type AgentDeviceProvider, type AgentErrorEvent, type AgentMessage, type AgentModel, type AgentOAuthProvider, type AgentProvider, type AgentQueueChangeEvent, type AgentRawEvent, type AgentStatusChangeEvent, type AgentTaskCreatedEvent, type AgentTaskEventMap, type AgentTaskEventName, type AgentTaskSession, type AgentTaskStatus, type AgentTaskTransport, type AgentTimelineItem, type AgentToolEvent, type AgentTurnEndEvent, type AgentType, type AllTokens, type AuthAgentCredentialResult, type AuthPageSignInOptions, type CallIntegrationOptions, type CallIntegrationResponse, type ChatManageAction, type ConnectAgentCredentialResult, type CreateRecordOptions, type CreateRecordsBatchOptions, type CredentialAction, type DeleteAgentChatResult, type DeleteRecordOptions, type DeviceAuthAgentCredentialResult, type EmailCodeLanguage, type EmailCodeRequest, type EmailCodeRequestResult, type EmailCodeVerification, type EmailSignInOptions, type ExecutePublicServerFunctionAsyncResponse, type ExecutePublicServerFunctionOptions, type ExecutePublicServerFunctionResponse, type ExecuteServerFunctionAsyncOptions, type ExecuteServerFunctionAsyncResponse, type ExecuteServerFunctionOptions, type ExecuteServerFunctionResponse, type GetAgentTaskCreateOptions, type GetAgentTaskOpenOptions, type GetAgentTaskOptions, type GetPublicServerFunctionExecutionOptions, type GetPublicServerFunctionExecutionResponse, type GetRecordOptions, type GoogleSignInOptions, type IntegrationResponse, type ListAgentModelsResult, type ListAgentProvidersResult, type ListIntegrationsOptions, type ListRecordsOptions, type ListRecordsResponse, type LoginOptions, type LoginResponse, type ManageAgentChatDeleteOptions, type ManageAgentChatListOptions, type ManageAgentChatOptions, type ManageAgentChatRenameOptions, type ManageAgentCredentialOptions, type MicrosoftSignInOptions, MitraApiError, type MitraClient, type MitraClientConfig, type MitraConfig, type MitraInstance, type MitraSpaceToken, type PatchRecordOptions, type PlatformSessionTokens, type QueuedItem, type RenameAgentChatResult, type SendOptions, type SignInCredentials, type SignUpData, type StopServerFunctionExecutionOptions, type StopServerFunctionExecutionResponse, type UpdateRecordOptions, type User, createClient, exchangeSsoCodeMitra, loginMitra, loginWithGoogleMitra, loginWithMicrosoftMitra };
|