@hanzo/rooms 0.1.71 → 0.1.73

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.
@@ -123,11 +123,20 @@ export declare function own(sub: string | undefined): void;
123
123
  */
124
124
  export declare function follow(was: string | undefined, moved: () => void): () => void;
125
125
  /**
126
- * The organizations the token says this person belongs to, home first.
127
- * Empty for an account that has not made one: the SDK's own list falls back to
128
- * the `owner` claim, which is the application's org and nobody's to work in.
126
+ * The brands' directories (hanzoai/authz `IsDirectory`): the org a customer's
127
+ * account lives in, its home, and nobody's to work in. IAM lists the home first
128
+ * in the token's `orgs`; cloud opens a directory to no one.
129
+ */
130
+ export declare const DIRECTORIES: readonly string[];
131
+ /**
132
+ * The organizations this person works in, as the token names them: every org of
133
+ * its `orgs` but a directory, which is a home and nobody's tenant. Empty for an
134
+ * account that has not made one: the SDK's own list falls back to the `owner`
135
+ * claim, which is the application's org and nobody's to work in.
129
136
  */
130
137
  export declare function orgs(): string[];
138
+ /** The org of the person's own row: the first entry of the token's `orgs`, a directory or not. */
139
+ export declare function home(): string | null;
131
140
  /**
132
141
  * The reader's role in one organization as IAM signed it into the token's `orgs`
133
142
  * claim — owner, admin or member — or null where the token names no such org.
@@ -171,16 +180,11 @@ export declare const PICKED = "hanzo:org:picked";
171
180
  * app's account menu — is one the gate does not ask for again.
172
181
  */
173
182
  export declare function pick(o: string): void;
174
- /** The reserved org whose own people are the platform's operators. */
175
- export declare const ADMIN_ORG = "admin";
176
- /**
177
- * Whether the signed-in person is a SUPERADMIN, as IAM signs it: the org of the
178
- * person's own row — the first entry of the token's `orgs`, which IAM always puts
179
- * first (hanzoai/iam internal/store/membership.go `MemberOrgRefs`) — is the
180
- * reserved `admin` org. It is the equality IAM decides `assume` and the
181
- * organization list on (pkg/schema/user.go `SuperAdmin`) and cloud's `Super`.
182
- * Not the `owner` claim: a sign-in token carries the APPLICATION's org there. A
183
- * membership of `admin` is not it either, and neither is being an org's admin.
183
+ /**
184
+ * Whether the signed-in person is a SUPERADMIN: @hanzo/iam's `superAdmin`, which is
185
+ * hanzoai/authz `Claims.Sudo` exactly — a person (never a program) whose own row's
186
+ * org, the first entry of the token's `orgs`, is the reserved `admin` org, compared
187
+ * verbatim. Not the `owner` claim, not a membership of `admin`, not an org's admin.
184
188
  * It decides only what is drawn: IAM refuses everyone else the list of every
185
189
  * organization and the step into one.
186
190
  */
@@ -14,6 +14,7 @@
14
14
  * who was signed in, which reads as a permissions problem rather than a typo.
15
15
  * Two derivations of one name never agree; this is the one derivation.
16
16
  */
17
+ import { superAdmin as sudo } from '@hanzo/iam/browser';
17
18
  import { api } from './api.js';
18
19
  import { where } from '../where.js';
19
20
  /** The SDK's own keys, `hanzo_iam_`-prefixed. The far side of a boundary. */
@@ -305,12 +306,14 @@ function claims() {
305
306
  return claimsOf(bearer());
306
307
  }
307
308
  /**
308
- * The organizations the token says this person belongs to, home first.
309
- * Empty for an account that has not made one: the SDK's own list falls back to
310
- * the `owner` claim, which is the application's org and nobody's to work in.
309
+ * The brands' directories (hanzoai/authz `IsDirectory`): the org a customer's
310
+ * account lives in, its home, and nobody's to work in. IAM lists the home first
311
+ * in the token's `orgs`; cloud opens a directory to no one.
311
312
  */
312
- export function orgs() {
313
- const set = claims()?.orgs;
313
+ export const DIRECTORIES = ['hanzo-id', 'lux-id', 'zoo-id', 'pars-id'];
314
+ /** Every org the token's `orgs` names, home first, each once. */
315
+ function listed(token) {
316
+ const set = claimsOf(token)?.orgs;
314
317
  const out = [];
315
318
  for (const ref of Array.isArray(set) ? set : []) {
316
319
  const o = ref?.org;
@@ -319,6 +322,19 @@ export function orgs() {
319
322
  }
320
323
  return out;
321
324
  }
325
+ /**
326
+ * The organizations this person works in, as the token names them: every org of
327
+ * its `orgs` but a directory, which is a home and nobody's tenant. Empty for an
328
+ * account that has not made one: the SDK's own list falls back to the `owner`
329
+ * claim, which is the application's org and nobody's to work in.
330
+ */
331
+ export function orgs() {
332
+ return listed(bearer()).filter((o) => !DIRECTORIES.includes(o));
333
+ }
334
+ /** The org of the person's own row: the first entry of the token's `orgs`, a directory or not. */
335
+ export function home() {
336
+ return listed(bearer())[0] ?? null;
337
+ }
322
338
  /**
323
339
  * The reader's role in one organization as IAM signed it into the token's `orgs`
324
340
  * claim — owner, admin or member — or null where the token names no such org.
@@ -354,8 +370,8 @@ export function named() {
354
370
  */
355
371
  export function me() {
356
372
  const name = claims()?.name;
357
- const home = orgs()[0];
358
- return typeof name === 'string' && name && home ? `${home}/${name}` : null;
373
+ const at = home();
374
+ return typeof name === 'string' && name && at ? `${at}/${name}` : null;
359
375
  }
360
376
  /** The organization this browser works in: the SDK's selection, when it is one of the token's. */
361
377
  export function org() {
@@ -421,21 +437,16 @@ export function pick(o) {
421
437
  }
422
438
  window.dispatchEvent(new Event(ORG));
423
439
  }
424
- /** The reserved org whose own people are the platform's operators. */
425
- export const ADMIN_ORG = 'admin';
426
440
  /**
427
- * Whether the signed-in person is a SUPERADMIN, as IAM signs it: the org of the
428
- * person's own row — the first entry of the token's `orgs`, which IAM always puts
429
- * first (hanzoai/iam internal/store/membership.go `MemberOrgRefs`) — is the
430
- * reserved `admin` org. It is the equality IAM decides `assume` and the
431
- * organization list on (pkg/schema/user.go `SuperAdmin`) and cloud's `Super`.
432
- * Not the `owner` claim: a sign-in token carries the APPLICATION's org there. A
433
- * membership of `admin` is not it either, and neither is being an org's admin.
441
+ * Whether the signed-in person is a SUPERADMIN: @hanzo/iam's `superAdmin`, which is
442
+ * hanzoai/authz `Claims.Sudo` exactly — a person (never a program) whose own row's
443
+ * org, the first entry of the token's `orgs`, is the reserved `admin` org, compared
444
+ * verbatim. Not the `owner` claim, not a membership of `admin`, not an org's admin.
434
445
  * It decides only what is drawn: IAM refuses everyone else the list of every
435
446
  * organization and the step into one.
436
447
  */
437
448
  export function superAdmin() {
438
- return orgs()[0] === ADMIN_ORG;
449
+ return sudo(claims());
439
450
  }
440
451
  /** The organization a SuperAdmin stepped into through IAM, from the token's `assumed` claim, or null. */
441
452
  export function assumed() {
@@ -471,15 +482,9 @@ export async function support(org) {
471
482
  throw new Error(body?.msg || `IAM answered ${res.status}.`);
472
483
  tokens().setItem(ACCESS, next);
473
484
  tokens().setItem(EXPIRES, String(exp * 1000));
474
- pick(org ?? homeOf(next));
485
+ pick(org ?? listed(next).find((o) => !DIRECTORIES.includes(o)) ?? '');
475
486
  window.location.reload();
476
487
  }
477
- /** The org of the person's own row: the first entry of a token's `orgs`. */
478
- function homeOf(token) {
479
- const set = claimsOf(token)?.orgs;
480
- const first = Array.isArray(set) ? set[0]?.org : undefined;
481
- return typeof first === 'string' ? first : '';
482
- }
483
488
  /**
484
489
  * Leave support mode when IAM cannot answer the step out: the stored token is
485
490
  * marked spent, so the SDK's refresh — which mints from the person's own grant
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/rooms",
3
- "version": "0.1.71",
3
+ "version": "0.1.73",
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",
@@ -53,7 +53,7 @@
53
53
  "@hanzo/composer": ">=0.2.0",
54
54
  "@hanzo/event": ">=0.3.56",
55
55
  "@hanzo/gui": "^8.3.5",
56
- "@hanzo/iam": ">=0.21.28",
56
+ "@hanzo/iam": ">=0.21.33",
57
57
  "@hanzo/logo": ">=1.0.26",
58
58
  "@hanzo/studio": ">=0.1.0",
59
59
  "@hanzo/ui": ">=8.27.67",
@@ -72,7 +72,7 @@
72
72
  "@hanzo/design": "0.5.34",
73
73
  "@hanzo/event": "0.3.56",
74
74
  "@hanzo/gui": "8.3.5",
75
- "@hanzo/iam": "0.21.28",
75
+ "@hanzo/iam": "0.21.33",
76
76
  "@hanzo/logo": "1.0.26",
77
77
  "@hanzo/studio": "0.1.0",
78
78
  "@hanzo/ui": "8.27.67",