@hanzo/rooms 0.1.70 → 0.1.71
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/lib/session.js +15 -5
- package/dist/where.d.ts +6 -0
- package/package.json +1 -1
package/dist/lib/session.js
CHANGED
|
@@ -15,12 +15,22 @@
|
|
|
15
15
|
* Two derivations of one name never agree; this is the one derivation.
|
|
16
16
|
*/
|
|
17
17
|
import { api } from './api.js';
|
|
18
|
+
import { where } from '../where.js';
|
|
18
19
|
/** The SDK's own keys, `hanzo_iam_`-prefixed. The far side of a boundary. */
|
|
19
20
|
const PREFIX = 'hanzo_iam_';
|
|
20
21
|
const ACCESS = `${PREFIX}access_token`;
|
|
21
22
|
const REFRESH = `${PREFIX}refresh_token`;
|
|
22
23
|
const EXPIRES = `${PREFIX}expires_at`;
|
|
23
24
|
const KEYS = [ACCESS, REFRESH, `${PREFIX}id_token`, EXPIRES];
|
|
25
|
+
/**
|
|
26
|
+
* The store the SDK keeps the session in: the host's (`configure({ session })`,
|
|
27
|
+
* Hanzo Desktop's keychain, where no token reaches the webview's localStorage),
|
|
28
|
+
* else this page's localStorage. Only the SDK's own keys are read from it; the
|
|
29
|
+
* rooms' own choices (the organization, the person) stay in localStorage.
|
|
30
|
+
*/
|
|
31
|
+
function tokens() {
|
|
32
|
+
return where().session ?? window.localStorage;
|
|
33
|
+
}
|
|
24
34
|
/**
|
|
25
35
|
* The access token, or null.
|
|
26
36
|
*
|
|
@@ -32,7 +42,7 @@ export function bearer() {
|
|
|
32
42
|
if (typeof window === 'undefined')
|
|
33
43
|
return null;
|
|
34
44
|
try {
|
|
35
|
-
return
|
|
45
|
+
return tokens().getItem(ACCESS);
|
|
36
46
|
}
|
|
37
47
|
catch {
|
|
38
48
|
return null;
|
|
@@ -48,7 +58,7 @@ export function live() {
|
|
|
48
58
|
if (typeof window === 'undefined')
|
|
49
59
|
return false;
|
|
50
60
|
try {
|
|
51
|
-
const expires =
|
|
61
|
+
const expires = tokens().getItem(EXPIRES);
|
|
52
62
|
return Boolean(bearer()) && (!expires || Date.now() < Number(expires));
|
|
53
63
|
}
|
|
54
64
|
catch {
|
|
@@ -386,7 +396,7 @@ export function scope() {
|
|
|
386
396
|
*/
|
|
387
397
|
export function renew() {
|
|
388
398
|
try {
|
|
389
|
-
|
|
399
|
+
tokens().setItem(EXPIRES, '0');
|
|
390
400
|
}
|
|
391
401
|
catch {
|
|
392
402
|
/* no store to renew */
|
|
@@ -459,8 +469,8 @@ export async function support(org) {
|
|
|
459
469
|
const exp = claimsOf(next ?? null)?.exp;
|
|
460
470
|
if (!res.ok || !next || typeof exp !== 'number')
|
|
461
471
|
throw new Error(body?.msg || `IAM answered ${res.status}.`);
|
|
462
|
-
|
|
463
|
-
|
|
472
|
+
tokens().setItem(ACCESS, next);
|
|
473
|
+
tokens().setItem(EXPIRES, String(exp * 1000));
|
|
464
474
|
pick(org ?? homeOf(next));
|
|
465
475
|
window.location.reload();
|
|
466
476
|
}
|
package/dist/where.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface Addresses {
|
|
|
33
33
|
brand?: string;
|
|
34
34
|
/** The publishable key anonymous calls carry. */
|
|
35
35
|
key?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Where the IAM session is kept when it is not this page's `localStorage`:
|
|
38
|
+
* the `storage` the host hands its IamProvider (Hanzo Desktop's keychain).
|
|
39
|
+
* The rooms read the access token, its expiry and its claims from it.
|
|
40
|
+
*/
|
|
41
|
+
session?: Storage;
|
|
36
42
|
/** The plan catalogue as the host's build last read it: the first paint. */
|
|
37
43
|
plans?: BillingPlan[];
|
|
38
44
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/rooms",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"description": "The workspace rooms — Home, Chat, Inbox, Contacts, Meet, Cal, Drive, Board, Work, Bots — and the frame that holds them, once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|