@spacelr/sdk 0.8.1 → 0.9.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.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1722,6 +1722,14 @@ interface SpacelrClient {
|
|
|
1722
1722
|
onAuthLost(listener: (reason: AuthLostReason) => void): () => void;
|
|
1723
1723
|
/** Subscribe to successful token refreshes. */
|
|
1724
1724
|
onTokenRefreshed(listener: (tokens: StoredTokens) => void): () => void;
|
|
1725
|
+
/**
|
|
1726
|
+
* Returns a currently-valid access token for making your own authenticated
|
|
1727
|
+
* requests. Blocks on a refresh only when the stored token is already
|
|
1728
|
+
* expired; within the refresh buffer it returns the current token and
|
|
1729
|
+
* refreshes in the background. Returns null when there is no refreshable
|
|
1730
|
+
* session.
|
|
1731
|
+
*/
|
|
1732
|
+
getAccessToken(): Promise<string | null>;
|
|
1725
1733
|
/**
|
|
1726
1734
|
* Subscribe to realtime socket connection-state changes. Fires on every
|
|
1727
1735
|
* transition (dedup: identical consecutive states are skipped). Returns
|
package/dist/index.d.ts
CHANGED
|
@@ -1722,6 +1722,14 @@ interface SpacelrClient {
|
|
|
1722
1722
|
onAuthLost(listener: (reason: AuthLostReason) => void): () => void;
|
|
1723
1723
|
/** Subscribe to successful token refreshes. */
|
|
1724
1724
|
onTokenRefreshed(listener: (tokens: StoredTokens) => void): () => void;
|
|
1725
|
+
/**
|
|
1726
|
+
* Returns a currently-valid access token for making your own authenticated
|
|
1727
|
+
* requests. Blocks on a refresh only when the stored token is already
|
|
1728
|
+
* expired; within the refresh buffer it returns the current token and
|
|
1729
|
+
* refreshes in the background. Returns null when there is no refreshable
|
|
1730
|
+
* session.
|
|
1731
|
+
*/
|
|
1732
|
+
getAccessToken(): Promise<string | null>;
|
|
1725
1733
|
/**
|
|
1726
1734
|
* Subscribe to realtime socket connection-state changes. Fires on every
|
|
1727
1735
|
* transition (dedup: identical consecutive states are skipped). Returns
|
package/dist/index.js
CHANGED
|
@@ -1304,6 +1304,16 @@ function localStorageCursorStorage(prefix = "spacelr:cursor:") {
|
|
|
1304
1304
|
}
|
|
1305
1305
|
|
|
1306
1306
|
// libs/sdk/src/modules/auth.module.ts
|
|
1307
|
+
function mapProfile(u) {
|
|
1308
|
+
const name = u.name ?? ([u.firstName, u.lastName].filter(Boolean).join(" ") || void 0) ?? u.displayName;
|
|
1309
|
+
return {
|
|
1310
|
+
id: u.id ?? u._id ?? u.userId ?? u.sub ?? "",
|
|
1311
|
+
email: u.email ?? "",
|
|
1312
|
+
username: u.username,
|
|
1313
|
+
name,
|
|
1314
|
+
roles: u.roles ?? []
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1307
1317
|
var AuthModule = class {
|
|
1308
1318
|
constructor(http, tokenManager, config) {
|
|
1309
1319
|
this.stateListeners = /* @__PURE__ */ new Set();
|
|
@@ -1427,11 +1437,12 @@ var AuthModule = class {
|
|
|
1427
1437
|
});
|
|
1428
1438
|
}
|
|
1429
1439
|
async getProfile() {
|
|
1430
|
-
|
|
1440
|
+
const data = await this.http.request({
|
|
1431
1441
|
method: "GET",
|
|
1432
1442
|
path: "/auth/me",
|
|
1433
1443
|
authenticated: true
|
|
1434
1444
|
});
|
|
1445
|
+
return mapProfile(data.user ?? data);
|
|
1435
1446
|
}
|
|
1436
1447
|
async logout() {
|
|
1437
1448
|
try {
|
|
@@ -3099,6 +3110,9 @@ function createClient(config) {
|
|
|
3099
3110
|
onTokenRefreshed(listener) {
|
|
3100
3111
|
return tokenManager.onTokenRefreshed(listener);
|
|
3101
3112
|
},
|
|
3113
|
+
getAccessToken() {
|
|
3114
|
+
return tokenManager.getAccessToken();
|
|
3115
|
+
},
|
|
3102
3116
|
onConnectionStateChanged(listener) {
|
|
3103
3117
|
return realtime.onConnectionStateChanged(listener);
|
|
3104
3118
|
},
|