@neta-art/cohub 2.5.0 → 2.6.0
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/chunks/http.d.ts +11 -0
- package/dist/chunks/http.js +6 -0
- package/dist/index.js +39 -0
- package/package.json +1 -1
package/dist/chunks/http.d.ts
CHANGED
|
@@ -1474,9 +1474,16 @@ declare class WorkRuntimeApi {
|
|
|
1474
1474
|
private token;
|
|
1475
1475
|
private readonly transport;
|
|
1476
1476
|
private readonly tokenStorageKey;
|
|
1477
|
+
private readonly scopesStorageKey;
|
|
1478
|
+
/** Scopes previously granted via requestAuthorization, retained so token
|
|
1479
|
+
* refreshes can re-authorize (preserving viewerScopes) instead of falling
|
|
1480
|
+
* back to a base session token that only carries workScopes. */
|
|
1481
|
+
private authorizedScopes;
|
|
1477
1482
|
constructor(transport?: WorkRuntimeTransport, workId?: string);
|
|
1478
1483
|
private readStoredToken;
|
|
1479
1484
|
private writeStoredToken;
|
|
1485
|
+
private readStoredScopes;
|
|
1486
|
+
private writeStoredScopes;
|
|
1480
1487
|
context(): Promise<WorkRuntimeContext | null>;
|
|
1481
1488
|
getAccessToken(options?: {
|
|
1482
1489
|
forceRefresh?: boolean;
|
|
@@ -2017,6 +2024,10 @@ declare class SpaceFilesApi {
|
|
|
2017
2024
|
* SDK can attach authorization headers.
|
|
2018
2025
|
*/
|
|
2019
2026
|
getDownloadUrl(path: string): string;
|
|
2027
|
+
createPreviewSession(customFetch?: Fetch): Promise<{
|
|
2028
|
+
token: string;
|
|
2029
|
+
expiresIn: number;
|
|
2030
|
+
}>;
|
|
2020
2031
|
download(path: string, customFetch?: Fetch): Promise<{
|
|
2021
2032
|
blob: Blob;
|
|
2022
2033
|
filename: string;
|
package/dist/chunks/http.js
CHANGED
|
@@ -1471,6 +1471,12 @@ var SpaceFilesApi = class {
|
|
|
1471
1471
|
const params = new URLSearchParams({ path });
|
|
1472
1472
|
return `/api/spaces/${this.spaceId}/fs/download?${params.toString()}`;
|
|
1473
1473
|
}
|
|
1474
|
+
createPreviewSession(customFetch) {
|
|
1475
|
+
return this.transport.request(`/api/spaces/${this.spaceId}/preview-session`, {
|
|
1476
|
+
method: "POST",
|
|
1477
|
+
fetch: customFetch
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1474
1480
|
async download(path, customFetch) {
|
|
1475
1481
|
const params = new URLSearchParams({ path });
|
|
1476
1482
|
const raw = await this.transport.raw(`/api/spaces/${this.spaceId}/fs/download?${params.toString()}`, { fetch: customFetch });
|
package/dist/index.js
CHANGED
|
@@ -274,14 +274,22 @@ var PopupBrokerTransport = class {
|
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
const TOKEN_STORAGE_PREFIX = "cohub:work-token";
|
|
277
|
+
const AUTHORIZED_SCOPES_STORAGE_PREFIX = "cohub:work-auth-scopes";
|
|
277
278
|
var WorkRuntimeApi = class {
|
|
278
279
|
token = null;
|
|
279
280
|
transport;
|
|
280
281
|
tokenStorageKey;
|
|
282
|
+
scopesStorageKey;
|
|
283
|
+
/** Scopes previously granted via requestAuthorization, retained so token
|
|
284
|
+
* refreshes can re-authorize (preserving viewerScopes) instead of falling
|
|
285
|
+
* back to a base session token that only carries workScopes. */
|
|
286
|
+
authorizedScopes = null;
|
|
281
287
|
constructor(transport = new ParentBridgeTransport(), workId) {
|
|
282
288
|
this.transport = transport;
|
|
283
289
|
this.tokenStorageKey = workId ? `${TOKEN_STORAGE_PREFIX}:${workId}` : null;
|
|
290
|
+
this.scopesStorageKey = workId ? `${AUTHORIZED_SCOPES_STORAGE_PREFIX}:${workId}` : null;
|
|
284
291
|
this.token = this.readStoredToken();
|
|
292
|
+
this.authorizedScopes = this.readStoredScopes();
|
|
285
293
|
}
|
|
286
294
|
readStoredToken() {
|
|
287
295
|
if (!this.tokenStorageKey || typeof localStorage === "undefined") return null;
|
|
@@ -298,6 +306,24 @@ var WorkRuntimeApi = class {
|
|
|
298
306
|
else localStorage.removeItem(this.tokenStorageKey);
|
|
299
307
|
} catch {}
|
|
300
308
|
}
|
|
309
|
+
readStoredScopes() {
|
|
310
|
+
if (!this.scopesStorageKey || typeof localStorage === "undefined") return null;
|
|
311
|
+
try {
|
|
312
|
+
const raw = localStorage.getItem(this.scopesStorageKey);
|
|
313
|
+
if (!raw) return null;
|
|
314
|
+
const parsed = JSON.parse(raw);
|
|
315
|
+
return Array.isArray(parsed) && parsed.every((s) => typeof s === "string") ? parsed : null;
|
|
316
|
+
} catch {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
writeStoredScopes(scopes) {
|
|
321
|
+
if (!this.scopesStorageKey || typeof localStorage === "undefined") return;
|
|
322
|
+
try {
|
|
323
|
+
if (scopes && scopes.length > 0) localStorage.setItem(this.scopesStorageKey, JSON.stringify(scopes));
|
|
324
|
+
else localStorage.removeItem(this.scopesStorageKey);
|
|
325
|
+
} catch {}
|
|
326
|
+
}
|
|
301
327
|
async context() {
|
|
302
328
|
return (await this.transport.request({ type: "cohub.work.context" }, {
|
|
303
329
|
timeoutMs: 8e3,
|
|
@@ -310,6 +336,15 @@ var WorkRuntimeApi = class {
|
|
|
310
336
|
this.token = null;
|
|
311
337
|
this.writeStoredToken(null);
|
|
312
338
|
}
|
|
339
|
+
if (options?.forceRefresh && this.authorizedScopes && this.authorizedScopes.length > 0) {
|
|
340
|
+
const response = await this.transport.request({
|
|
341
|
+
type: "cohub.work.authorize",
|
|
342
|
+
scopes: this.authorizedScopes
|
|
343
|
+
}, { timeoutMs: 12e4 });
|
|
344
|
+
this.token = response?.token ?? null;
|
|
345
|
+
this.writeStoredToken(this.token);
|
|
346
|
+
return this.token;
|
|
347
|
+
}
|
|
313
348
|
const response = await this.transport.request({
|
|
314
349
|
type: "cohub.work.token",
|
|
315
350
|
forceRefresh: Boolean(options?.forceRefresh)
|
|
@@ -326,6 +361,10 @@ var WorkRuntimeApi = class {
|
|
|
326
361
|
}, { timeoutMs: 12e4 });
|
|
327
362
|
this.token = response?.token ?? null;
|
|
328
363
|
this.writeStoredToken(this.token);
|
|
364
|
+
if (this.token) {
|
|
365
|
+
this.authorizedScopes = input.scopes;
|
|
366
|
+
this.writeStoredScopes(input.scopes);
|
|
367
|
+
}
|
|
329
368
|
return Boolean(this.token);
|
|
330
369
|
}
|
|
331
370
|
async purchase(input) {
|