@raisindb/client 0.4.5 → 0.4.7
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/{conversation-list-store-CfK-DEYd.d.mts → conversation-list-store-CcsnbqWp.d.mts} +23 -1
- package/dist/{conversation-list-store-CfK-DEYd.d.ts → conversation-list-store-CcsnbqWp.d.ts} +23 -1
- package/dist/{index-D2Vw7FpW.d.mts → index-CafciIjp.d.mts} +1 -1
- package/dist/{index-BfP-1PoU.d.ts → index-CrfRIFc7.d.ts} +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +46 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -3
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{svelte-sql-Cg1Jo0Fs.d.ts → svelte-sql-BI1jVnoo.d.ts} +1 -1
- package/dist/{svelte-sql-B_YbYl-Q.d.mts → svelte-sql-Car7CGb8.d.mts} +1 -1
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -239,7 +239,7 @@ var LocalStorageTokenStorage = class {
|
|
|
239
239
|
function isJwtCredentials(credentials) {
|
|
240
240
|
return "type" in credentials && credentials.type === "jwt";
|
|
241
241
|
}
|
|
242
|
-
var AuthManager = class {
|
|
242
|
+
var AuthManager = class _AuthManager {
|
|
243
243
|
constructor(storage) {
|
|
244
244
|
this.expiresAt = null;
|
|
245
245
|
this._storage = storage ?? new MemoryTokenStorage();
|
|
@@ -262,6 +262,31 @@ var AuthManager = class {
|
|
|
262
262
|
this.expiresAt = Date.now() + expiresInMs;
|
|
263
263
|
this.scheduleTokenRefresh(expiresInMs);
|
|
264
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Learn a bare token's expiry FROM THE TOKEN.
|
|
267
|
+
*
|
|
268
|
+
* `setTokens` is the only other writer of `expiresAt`, and it needs a whole
|
|
269
|
+
* `AuthenticateResponse`. Several paths hold nothing but a JWT string — a
|
|
270
|
+
* session restored from storage, `authenticate({type:'jwt'})`,
|
|
271
|
+
* `setIdentityTokens(token)` — and left `expiresAt` null. `isTokenExpired()`
|
|
272
|
+
* reads null as EXPIRED, so `isAuthenticated()` answered false for the whole
|
|
273
|
+
* life of every restored session, i.e. every page load after the first.
|
|
274
|
+
*
|
|
275
|
+
* It failed silently, and it had already been routed around three times
|
|
276
|
+
* rather than fixed: both HTTP send paths were made to stop consulting
|
|
277
|
+
* `isAuthenticated()` (see `request()` and `mcpStream()` in http-client),
|
|
278
|
+
* and Studio grew its own token parse to tell a 404 apart from a logged-out
|
|
279
|
+
* read. This is the missing writer those workarounds existed for.
|
|
280
|
+
*
|
|
281
|
+
* Same 60s safety margin as `setTokens`, so both writers agree on when a
|
|
282
|
+
* token stops counting as good.
|
|
283
|
+
*
|
|
284
|
+
* @param token - A JWT held in storage or handed to us
|
|
285
|
+
*/
|
|
286
|
+
adoptToken(token) {
|
|
287
|
+
const exp = _AuthManager.parseToken(token)?.exp;
|
|
288
|
+
this.expiresAt = typeof exp === "number" ? exp * 1e3 - 6e4 : null;
|
|
289
|
+
}
|
|
265
290
|
/**
|
|
266
291
|
* Get current access token
|
|
267
292
|
*/
|
|
@@ -3327,9 +3352,18 @@ var ConversationManager = class {
|
|
|
3327
3352
|
async createUserMessage(conversationPath, content) {
|
|
3328
3353
|
logger.debug("[ConversationManager] Creating user message", { path: conversationPath });
|
|
3329
3354
|
const workspace = "raisin:access_control";
|
|
3355
|
+
const properties = await this.loadConversationProperties(conversationPath, workspace);
|
|
3356
|
+
const flowInstanceId = typeof properties?.flow_instance_id === "string" ? properties.flow_instance_id.trim() : "";
|
|
3357
|
+
if (flowInstanceId) {
|
|
3358
|
+
await this.httpRequest({
|
|
3359
|
+
method: "POST",
|
|
3360
|
+
path: `/api/flows/${this.repository}/instances/${encodeURIComponent(flowInstanceId)}/resume`,
|
|
3361
|
+
body: { resume_data: { message: content } }
|
|
3362
|
+
});
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3330
3365
|
const { userId, userHome } = await this.ensureCurrentUser();
|
|
3331
3366
|
const messageId = crypto.randomUUID();
|
|
3332
|
-
const properties = await this.loadConversationProperties(conversationPath, workspace);
|
|
3333
3367
|
const participants = Array.isArray(properties?.participants) ? properties.participants : [];
|
|
3334
3368
|
let recipientId = participants.find(
|
|
3335
3369
|
(p) => typeof p === "string" && p.length > 0 && p !== userId && p !== userHome
|
|
@@ -5834,6 +5868,7 @@ var RaisinHttpClient = class extends EventEmitter {
|
|
|
5834
5868
|
async authenticate(credentials, repository) {
|
|
5835
5869
|
if (isJwtCredentials(credentials)) {
|
|
5836
5870
|
this.authManager.storage.setAccessToken(credentials.token);
|
|
5871
|
+
this.authManager.adoptToken(credentials.token);
|
|
5837
5872
|
if (repository) {
|
|
5838
5873
|
try {
|
|
5839
5874
|
const userInfo = await this.fetchCurrentUser(repository);
|
|
@@ -6240,6 +6275,7 @@ var RaisinHttpClient = class extends EventEmitter {
|
|
|
6240
6275
|
setIdentityTokens(accessTokenOrResult, refreshToken) {
|
|
6241
6276
|
if (typeof accessTokenOrResult === "string") {
|
|
6242
6277
|
this.authManager.storage.setAccessToken(accessTokenOrResult);
|
|
6278
|
+
this.authManager.adoptToken(accessTokenOrResult);
|
|
6243
6279
|
if (refreshToken) this.authManager.storage.setRefreshToken(refreshToken);
|
|
6244
6280
|
return;
|
|
6245
6281
|
}
|
|
@@ -7360,6 +7396,7 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
|
|
|
7360
7396
|
async authenticate(credentials) {
|
|
7361
7397
|
if (isJwtCredentials(credentials)) {
|
|
7362
7398
|
logger.info("[authenticate] Starting JWT authentication...");
|
|
7399
|
+
this.authManager.adoptToken(credentials.token);
|
|
7363
7400
|
const payload = { token: credentials.token };
|
|
7364
7401
|
const response = await this.sendRequestInternal(
|
|
7365
7402
|
payload,
|
|
@@ -7854,7 +7891,13 @@ var _RaisinClient = class _RaisinClient extends EventEmitter2 {
|
|
|
7854
7891
|
logger.debug(`[scheduleAutoRefresh] Scheduling refresh in ${Math.round(clamped / 1e3 / 60)} minutes`);
|
|
7855
7892
|
this._refreshTimer = setTimeout(async () => {
|
|
7856
7893
|
logger.info("[autoRefresh] Auto-refreshing token...");
|
|
7857
|
-
await this.refreshToken();
|
|
7894
|
+
const user = await this.refreshToken();
|
|
7895
|
+
if (!user) {
|
|
7896
|
+
logger.error("[autoRefresh] Refresh failed, clearing session");
|
|
7897
|
+
this.authManager.clear();
|
|
7898
|
+
this._currentUser = null;
|
|
7899
|
+
this._emitAuthEvent("SESSION_EXPIRED");
|
|
7900
|
+
}
|
|
7858
7901
|
}, clamped);
|
|
7859
7902
|
}
|
|
7860
7903
|
/**
|