@boost33/shell-data 0.0.0-stage → 0.1.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/CHANGELOG.md +48 -0
- package/README.md +80 -2
- package/dist/index.d.ts +46 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/links.d.ts +11 -0
- package/dist/links.js +29 -0
- package/dist/links.js.map +1 -0
- package/dist/person.d.ts +9 -0
- package/dist/person.js +30 -0
- package/dist/person.js.map +1 -0
- package/dist/products.d.ts +17 -0
- package/dist/products.js +96 -0
- package/dist/products.js.map +1 -0
- package/dist/profile.d.ts +10 -0
- package/dist/profile.js +32 -0
- package/dist/profile.js.map +1 -0
- package/dist/session.d.ts +252 -0
- package/dist/session.js +376 -0
- package/dist/session.js.map +1 -0
- package/dist/tokens.d.ts +36 -0
- package/dist/tokens.js +92 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Changes to the published surface of `@boost33/shell-data`. Consumers upgrade by hand, as with `@boost33/ui`, so this file is the only notice they get.
|
|
4
|
+
|
|
5
|
+
## 0.1.1 — 2026-11-13
|
|
6
|
+
|
|
7
|
+
### Added — `gate()` and `isNavigation()`, for an app whose proxy does more than refresh
|
|
8
|
+
|
|
9
|
+
**Not breaking.** `gateRequest` behaves exactly as in 0.1.0; it is now built on `gate()`.
|
|
10
|
+
|
|
11
|
+
- **`gate(request, options) → GateResult`**: the same §5.1 decision without building a response. It takes any `Request` and returns one of five outcomes:
|
|
12
|
+
- `none`: no session cookie.
|
|
13
|
+
- `live`: the short-lived cookie is not near expiry. This is an unverified check, so verify it yourself.
|
|
14
|
+
- `refreshed`: the new token, already verified, plus the cookies to forward verbatim and the rewritten Cookie header.
|
|
15
|
+
- `dead`: a ready 307 to sign in that clears both cookies.
|
|
16
|
+
- `unwell`: forward nothing.
|
|
17
|
+
|
|
18
|
+
This is for apps that verify `b33_ctx` in their own proxy and hand claims to the page, as Results does.
|
|
19
|
+
- **`isNavigation(request)`**: the matcher's rule in code, for an app whose proxy must run on every request and so cannot narrow its matcher.
|
|
20
|
+
- **`CLAIMS_PROXY_MATCHER` and `isPrefetch(request)`, for an app whose proxy hands claims to its pages in a request header.** `SESSION_GATE_MATCHER` is safe only where pages verify `b33_ctx` themselves. Its prefetch exclusions read headers the client sets, so in a header-passing app a request marked as a prefetch would skip the proxy, and the page would trust a forged header. `CLAIMS_PROXY_MATCHER` runs the proxy on every request but Next's static assets. `isPrefetch` (Next's router, `purpose` and `sec-purpose`) and `isNavigation` then skip only the refresh. The README, and each matcher's JSDoc, name the architecture it assumes. Found by activity-jmini and hub-jmini.
|
|
21
|
+
- `isNavigation` now also treats `sec-purpose: prefetch` (a browser's speculative load) as a prefetch. `SESSION_GATE_MATCHER` is unchanged, so an app's existing literal copy still passes `matcherIsNavigationOnly`.
|
|
22
|
+
- **A viewer-credential mode for apps with no service keys** (Results, from activity-jmini). `identityKey`, `appId` and `ledger` are now optional.
|
|
23
|
+
- Without `identityKey`, there is no profile read: `profileName` resolves null and the name claim stands.
|
|
24
|
+
- Without a ledger `key` and `app`, the tokens are read as the viewer through `@boost33/ledger-client`'s `tokenSplitForViewer(b33_ctx)`, which is read-only and keyless.
|
|
25
|
+
- The product list was already read as the viewer.
|
|
26
|
+
- In viewer mode, an expired `b33_ctx` gives `unknown` with no retry, and the ledger's `no_wallet` gives `none`.
|
|
27
|
+
|
|
28
|
+
An app with keys passes them exactly as in 0.1.0, and nothing changes for it. The output shape is unchanged.
|
|
29
|
+
- **Fixed: a ledger URL ending in `/api/v1` read every token as "unknown".** The package appended `/api/v1` to whatever it was given, so an app whose `BOOST33_LEDGER_URL` already ends in it (Outbound, B33-660) asked for `/api/v1/api/v1/…`. The URL is now accepted with or without the suffix and trailing slashes, and never doubled. Found by outbound-jmini on 0.1.0.
|
|
30
|
+
- `appId` is documented as Identity's `APPS` slug (`outbound`), not the product slug (`boostoutbound`).
|
|
31
|
+
- **A compile-time check against `@boost33/ui` 0.11.0's `BackdropStandardChromeProps`** (both directions), so the data this package returns and what the chrome takes cannot drift apart without this package's build failing. `@boost33/ui` is a types-only devDependency; a test holds that `src/` never imports it. The check compiles with `moduleResolution: "bundler"`, as a Next app does (`tsconfig.drift.json`). Under this package's own NodeNext setting, `@boost33/ui`'s types silently resolve to `any` and the check could never fail; a negative control proved that before the fix.
|
|
32
|
+
- **`client` is identity's caller slug** from `APPS` in boost33-identity `src/config/apps.ts`, not a product slug: `outbound`, `passport`, `hub`, `boostscore`… An unlisted value still works; identity logs it as `unrecognised`.
|
|
33
|
+
|
|
34
|
+
## 0.1.0 — 2026-11-13
|
|
35
|
+
|
|
36
|
+
### Added — `getBackdropChromeData`, everything the Backdrop chrome draws, from one call (B33-1726)
|
|
37
|
+
|
|
38
|
+
- `person` (sync, from the claims), `profileName`, `products` and `tokens` (promises that never reject), and `links` (sync, absolute). The shapes match `BackdropStandardChrome`'s props in `@boost33/ui`.
|
|
39
|
+
- Scope is the Backdrop chrome only. The 0.8 shell's switcher and wallet chip are not covered: that shell is removed after the Backdrop launch.
|
|
40
|
+
- Server only (`server-only`). It reads no secret of its own; every key arrives in `config`.
|
|
41
|
+
- Depends on `@boost33/ledger-client` 2.3.0, pinned exactly. It has no peer dependencies.
|
|
42
|
+
|
|
43
|
+
### Added — `@boost33/shell-data/session`, the session gate every app runs before it decides the design
|
|
44
|
+
|
|
45
|
+
- `gateRequest(request, { identityUrl, client, verify })` for `proxy.ts` / middleware, plus `refreshSession`, `ctxLooksExpired`, `cookiePair`, `SESSION_GATE_MATCHER`, `matcherIsNavigationOnly`, `markBounce` and `isRepeatBounce`.
|
|
46
|
+
- Lifted from Passport's production gate (boost33-passport, B33-1751), itself a copy of Boost Voice's. It follows boost33-identity's contract §5.1 point by point. The only changes are parameters for what was Passport's own: the caller slug, the verifier, and the fallback host. It adds the §5.1.7 one-bounce guard helpers.
|
|
47
|
+
- `next` (>=15) and `jose` (>=6) are optional peer dependencies, needed for this entry only.
|
|
48
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @boost33/shell-data
|
|
2
|
+
|
|
3
|
+
Server-only reads that hand the Backdrop chrome in `@boost33/ui` exactly the data it draws, so no app assembles its rail, account menu or token chip by hand (B33-1726).
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { getBackdropChromeData } from '@boost33/shell-data'
|
|
7
|
+
import { BackdropStandardChrome } from '@boost33/ui/backdrop'
|
|
8
|
+
|
|
9
|
+
const data = getBackdropChromeData({ claims, cookies: { sid, ctx }, config })
|
|
10
|
+
return <BackdropStandardChrome {...data} variant="app" place="boostscore" labels={labels} linkComponent={Link}>{page}</BackdropStandardChrome>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- **`claims`**: the claims your app already verified from `b33_ctx`. This package does not verify them again, and it never reads `design`. Deciding which design a person sees is your app's `isBackdropPreview`, and only that.
|
|
14
|
+
- **`cookies`**: the request's `b33_sid` and `b33_ctx` values.
|
|
15
|
+
- **`config`**: origins, and keys if your app has them, from your server environment: `identityUrl`, `hubUrl`, and optionally `identityKey` with `appId`, `ledger: { url, key, app }`, `docsUrl` and `supportEmail`.
|
|
16
|
+
|
|
17
|
+
**Two credential modes, chosen by what you pass.**
|
|
18
|
+
- **An app with service keys** (it is in Identity's `APPS`, with a ledger key) passes `identityKey`, `appId` and `ledger: { url, key, app }`. **`appId` is your slug in Identity's `APPS`** (boost33-identity `src/config/apps.ts`), not your product slug: Outbound passes `outbound`, not `boostoutbound`. The ledger `url` may be the origin or end in `/api/v1`; either works. The profile is read with the Identity key, and the tokens with the ledger key.
|
|
19
|
+
- **An app without them** (Results, for one) leaves the keys out and reads everything as the viewer, with the cookies it was given:
|
|
20
|
+
- the product list, which is always read this way;
|
|
21
|
+
- the tokens, through the ledger's `tokenSplitForViewer` with the viewer's `b33_ctx`.
|
|
22
|
+
|
|
23
|
+
The profile read is skipped, so `profileName` resolves null and the `name` claim stands. This needs no new secret and grants the least privilege.
|
|
24
|
+
|
|
25
|
+
`person` and `links` are ready at once. `profileName`, `products` and `tokens` are promises. All three start together and none ever rejects, so the chrome streams each one in its own Suspense boundary. Each read fails alone, and the chrome always renders.
|
|
26
|
+
|
|
27
|
+
| Read | Source | On failure |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `products` | Identity `GET /api/v1/products`, as the viewer (their cookies) | the last good list, `stale: true`; else `null` (global rail items only) |
|
|
30
|
+
| `profileName` | Identity `GET /api/v1/profile`, with your service key (skipped without one) | `null`: the `name` claim stays |
|
|
31
|
+
| `tokens` | `@boost33/ledger-client` `tokenSplit()` with your key, else `tokenSplitForViewer()` with the viewer's `b33_ctx` | `{ kind: 'unknown' }`; no wallet gives `{ kind: 'none' }` |
|
|
32
|
+
|
|
33
|
+
The package returns no words. Labels, date formats and the mailto subject are your app's, in its language. App order is Identity's, as returned; nothing here hardcodes a product list.
|
|
34
|
+
|
|
35
|
+
## The session gate: `@boost33/shell-data/session`
|
|
36
|
+
|
|
37
|
+
> [!warning] Pick the matcher for how your pages trust the session
|
|
38
|
+
> **Your pages verify `b33_ctx` themselves** (every page runs its own `jwtVerify`, and your proxy sets no request header a page trusts; the Hub is one). Use `gateRequest` behind `SESSION_GATE_MATCHER`.
|
|
39
|
+
>
|
|
40
|
+
> **Your proxy hands claims to the page in a request header** (Results' `x-results-claims`). Use `gate()` behind `CLAIMS_PROXY_MATCHER`, and call it only when `isNavigation(request)` is true. Delete the claims header from every incoming request first.
|
|
41
|
+
>
|
|
42
|
+
> **Why the second kind cannot use `SESSION_GATE_MATCHER`.** Its prefetch exclusions read headers the client sets. A client can send an ordinary page request marked as a prefetch. That request skips your proxy, and the page then trusts a claims header the client wrote. `isPrefetch` and `isNavigation` decide only whether to spend a refresh, never whether your proxy runs.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Refreshes an expired `b33_ctx` before the page renders, exactly as boost33-identity's contract §5.1 requires. It is lifted from Passport's production gate (B33-1751). Without it, a person on the Backdrop preview flips back to the classic design whenever their ten-minute `b33_ctx` runs out.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// src/proxy.ts (Next 16) or middleware.ts
|
|
49
|
+
import type { NextRequest } from 'next/server'
|
|
50
|
+
import { gateRequest } from '@boost33/shell-data/session'
|
|
51
|
+
|
|
52
|
+
export function proxy(request: NextRequest) {
|
|
53
|
+
return gateRequest(request, { identityUrl, client: 'boostscore', verify })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Copy SESSION_GATE_MATCHER here AS A LITERAL. Next ignores an imported matcher.
|
|
57
|
+
export const config = { matcher: [ /* … */ ] }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- **`client`**: your slug in Identity's `APPS`, sent as `x-boost33-client`.
|
|
61
|
+
- **`verify(token)`**: your full `jwtVerify` of a `b33_ctx`, returning `true` or `false`. No claim crosses back, and the gate never reads `design`.
|
|
62
|
+
- **Outcomes**: one call to Identity, capped at 1.5s.
|
|
63
|
+
- Refreshed: both cookies are forwarded verbatim, and this request is rewritten so the page sees the new token.
|
|
64
|
+
- `401`: both cookies are cleared and the person goes to sign in.
|
|
65
|
+
- Timeout, `5xx` or `429`: nothing changes and nothing is forwarded.
|
|
66
|
+
- **The matcher**: `matcherIsNavigationOnly(config.matcher)` in your tests checks your copy. You may narrow its paths, but you may not drop the prefetch, `_next/` or `api/` exclusions.
|
|
67
|
+
- **One-bounce guard (§5.1.7)**: if your page redirects to Identity when it finds no claims, pass `markBounce(returnUrl)` as the return URL. On arrival, send `isRepeatBounce(url)` to a terminal page instead of back to Identity.
|
|
68
|
+
|
|
69
|
+
`next` and `jose` are optional peer dependencies, needed only for this entry.
|
|
70
|
+
|
|
71
|
+
### When your proxy does more than refresh
|
|
72
|
+
|
|
73
|
+
If your proxy also verifies `b33_ctx` and hands claims to the page, use `gate(request, options)`. It returns a decision rather than a response; see `GateResult`.
|
|
74
|
+
|
|
75
|
+
- `refreshed` gives you `freshCtx` (already verified), the `setCookies` to forward verbatim, and the `cookieHeader` to render this request with.
|
|
76
|
+
- `dead` gives you a `redirect` to return as is.
|
|
77
|
+
|
|
78
|
+
Use it behind `CLAIMS_PROXY_MATCHER`, which runs your proxy on every request except Next's static assets, and call `gate` only when `isNavigation(request)` is true. **Delete your claims header from the incoming request first, on every path**, and set it only from claims your proxy verified (a live `b33_ctx` you verified, or `freshCtx`).
|
|
79
|
+
|
|
80
|
+
`client` is your slug in Identity's `APPS` (`src/config/apps.ts` in boost33-identity), not your product slug.
|
|
2
81
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { type TokenSplitReader } from './tokens.js';
|
|
3
|
+
import type { BackdropChromeData, ChromeClaims, ChromeConfig } from './types.js';
|
|
4
|
+
export type { BackdropChromeData, ChromeClaims, ChromeConfig, ChromeLinks, ChromePerson, ChromeProduct, ChromeProducts, ChromeTokens, } from './types.js';
|
|
5
|
+
export type GetBackdropChromeDataInput = {
|
|
6
|
+
/** Claims the app has already verified from `b33_ctx`. The package does not verify them again. */
|
|
7
|
+
claims: ChromeClaims;
|
|
8
|
+
/** The request's two session cookies. `ctx` may be null when only `b33_sid` was sent. */
|
|
9
|
+
cookies: {
|
|
10
|
+
sid: string;
|
|
11
|
+
ctx: string | null;
|
|
12
|
+
};
|
|
13
|
+
config: ChromeConfig;
|
|
14
|
+
};
|
|
15
|
+
/** Overrides for tests. An app passes nothing. */
|
|
16
|
+
export type GetBackdropChromeDataDeps = {
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
tokenSplit?: TokenSplitReader;
|
|
19
|
+
};
|
|
20
|
+
export type { TokenSplitReader } from './tokens.js';
|
|
21
|
+
/**
|
|
22
|
+
* Everything the Backdrop chrome draws, from one call (B33-1726).
|
|
23
|
+
*
|
|
24
|
+
* Spread the result onto `BackdropStandardChrome` in @boost33/ui. `person`
|
|
25
|
+
* and `links` are ready at once. `profileName`, `products` and `tokens` are
|
|
26
|
+
* promises, started together here and never rejecting, so the chrome can
|
|
27
|
+
* stream each inside its own Suspense boundary instead of waiting for the
|
|
28
|
+
* slowest read. Each read fails alone, and the chrome always renders:
|
|
29
|
+
*
|
|
30
|
+
* - Identity's products unreachable: the last good list (`stale: true`), or
|
|
31
|
+
* else null, which draws the rail's global items and no apps.
|
|
32
|
+
* - Identity's profile unreachable, or no `identityKey`: null, so the `name` claim stays.
|
|
33
|
+
* - The ledger unreachable or unclear: tokens `{ kind: 'unknown' }`.
|
|
34
|
+
*
|
|
35
|
+
* Two credential modes, chosen by `config`. An app with service keys reads the
|
|
36
|
+
* profile with `identityKey` and the tokens with `ledger.key`. An app without
|
|
37
|
+
* them (one not in Identity's `APPS`) reads everything as the viewer, with the
|
|
38
|
+
* cookies it was given: the product list, and the tokens through
|
|
39
|
+
* `tokenSplitForViewer`; the profile read is skipped. Least privilege, and no
|
|
40
|
+
* new secret.
|
|
41
|
+
*
|
|
42
|
+
* Server only: it reads service keys and must never reach a browser bundle.
|
|
43
|
+
* It reads no secret of its own; every key comes in `config`, from the app's
|
|
44
|
+
* server environment.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getBackdropChromeData(input: GetBackdropChromeDataInput, deps?: GetBackdropChromeDataDeps): BackdropChromeData;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { linksFrom } from './links.js';
|
|
3
|
+
import { personFrom } from './person.js';
|
|
4
|
+
import { readProducts } from './products.js';
|
|
5
|
+
import { readProfileName } from './profile.js';
|
|
6
|
+
import { ledgerReader, readTokens } from './tokens.js';
|
|
7
|
+
/**
|
|
8
|
+
* Everything the Backdrop chrome draws, from one call (B33-1726).
|
|
9
|
+
*
|
|
10
|
+
* Spread the result onto `BackdropStandardChrome` in @boost33/ui. `person`
|
|
11
|
+
* and `links` are ready at once. `profileName`, `products` and `tokens` are
|
|
12
|
+
* promises, started together here and never rejecting, so the chrome can
|
|
13
|
+
* stream each inside its own Suspense boundary instead of waiting for the
|
|
14
|
+
* slowest read. Each read fails alone, and the chrome always renders:
|
|
15
|
+
*
|
|
16
|
+
* - Identity's products unreachable: the last good list (`stale: true`), or
|
|
17
|
+
* else null, which draws the rail's global items and no apps.
|
|
18
|
+
* - Identity's profile unreachable, or no `identityKey`: null, so the `name` claim stays.
|
|
19
|
+
* - The ledger unreachable or unclear: tokens `{ kind: 'unknown' }`.
|
|
20
|
+
*
|
|
21
|
+
* Two credential modes, chosen by `config`. An app with service keys reads the
|
|
22
|
+
* profile with `identityKey` and the tokens with `ledger.key`. An app without
|
|
23
|
+
* them (one not in Identity's `APPS`) reads everything as the viewer, with the
|
|
24
|
+
* cookies it was given: the product list, and the tokens through
|
|
25
|
+
* `tokenSplitForViewer`; the profile read is skipped. Least privilege, and no
|
|
26
|
+
* new secret.
|
|
27
|
+
*
|
|
28
|
+
* Server only: it reads service keys and must never reach a browser bundle.
|
|
29
|
+
* It reads no secret of its own; every key comes in `config`, from the app's
|
|
30
|
+
* server environment.
|
|
31
|
+
*/
|
|
32
|
+
export function getBackdropChromeData(input, deps = {}) {
|
|
33
|
+
const fetchImpl = deps.fetch ?? fetch;
|
|
34
|
+
return {
|
|
35
|
+
person: personFrom(input.claims),
|
|
36
|
+
profileName: readProfileName({ sid: input.cookies.sid, config: input.config }, fetchImpl),
|
|
37
|
+
products: readProducts(input, fetchImpl),
|
|
38
|
+
tokens: readTokens(input.claims, input.cookies.ctx, deps.tokenSplit ?? ledgerReader(input.config)),
|
|
39
|
+
links: linksFrom(input.config),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAyB,MAAM,aAAa,CAAA;AA8B7E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAiC,EACjC,OAAkC,EAAE;IAEpC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAA;IACrC,OAAO;QACL,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC;QAChC,WAAW,EAAE,eAAe,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC;QACzF,QAAQ,EAAE,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC;QACxC,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAClG,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;KAC/B,CAAA;AACH,CAAC"}
|
package/dist/links.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ChromeConfig, ChromeLinks } from './types.js';
|
|
2
|
+
export declare const DEFAULT_DOCS_URL = "https://docs.boost33.com";
|
|
3
|
+
export declare const DEFAULT_SUPPORT_EMAIL = "support@boost33.com";
|
|
4
|
+
/**
|
|
5
|
+
* Every link the chrome draws that no read decides. Absolute, so the same
|
|
6
|
+
* account menu works from every app and from the Hub itself; the paths are
|
|
7
|
+
* the Hub's and Identity's own routes (boost33-hub src/app/backdrop/panels.tsx).
|
|
8
|
+
* The Wallet and buy links are not here: whether they exist depends on the
|
|
9
|
+
* product list, so they arrive with it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function linksFrom(config: ChromeConfig): ChromeLinks;
|
package/dist/links.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const DEFAULT_DOCS_URL = 'https://docs.boost33.com';
|
|
2
|
+
export const DEFAULT_SUPPORT_EMAIL = 'support@boost33.com';
|
|
3
|
+
const origin = (url) => url.replace(/\/+$/, '');
|
|
4
|
+
/**
|
|
5
|
+
* Every link the chrome draws that no read decides. Absolute, so the same
|
|
6
|
+
* account menu works from every app and from the Hub itself; the paths are
|
|
7
|
+
* the Hub's and Identity's own routes (boost33-hub src/app/backdrop/panels.tsx).
|
|
8
|
+
* The Wallet and buy links are not here: whether they exist depends on the
|
|
9
|
+
* product list, so they arrive with it.
|
|
10
|
+
*/
|
|
11
|
+
export function linksFrom(config) {
|
|
12
|
+
const hub = origin(config.hubUrl);
|
|
13
|
+
const identity = origin(config.identityUrl);
|
|
14
|
+
return {
|
|
15
|
+
home: `${hub}/`,
|
|
16
|
+
settings: `${hub}/settings`,
|
|
17
|
+
profile: `${hub}/settings/profile`,
|
|
18
|
+
company: `${hub}/settings/org/general`,
|
|
19
|
+
team: `${hub}/settings/org/team`,
|
|
20
|
+
billing: `${hub}/settings/org/billing`,
|
|
21
|
+
notifications: `${hub}/settings/notifications`,
|
|
22
|
+
security: `${identity}/account/security`,
|
|
23
|
+
chooseAccount: `${identity}/choose-account`,
|
|
24
|
+
signOut: `${identity}/signout`,
|
|
25
|
+
docs: config.docsUrl ?? DEFAULT_DOCS_URL,
|
|
26
|
+
support: `mailto:${config.supportEmail ?? DEFAULT_SUPPORT_EMAIL}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAA;AAC1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAA;AAE1D,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC3C,OAAO;QACL,IAAI,EAAE,GAAG,GAAG,GAAG;QACf,QAAQ,EAAE,GAAG,GAAG,WAAW;QAC3B,OAAO,EAAE,GAAG,GAAG,mBAAmB;QAClC,OAAO,EAAE,GAAG,GAAG,uBAAuB;QACtC,IAAI,EAAE,GAAG,GAAG,oBAAoB;QAChC,OAAO,EAAE,GAAG,GAAG,uBAAuB;QACtC,aAAa,EAAE,GAAG,GAAG,yBAAyB;QAC9C,QAAQ,EAAE,GAAG,QAAQ,mBAAmB;QACxC,aAAa,EAAE,GAAG,QAAQ,iBAAiB;QAC3C,OAAO,EAAE,GAAG,QAAQ,UAAU;QAC9B,IAAI,EAAE,MAAM,CAAC,OAAO,IAAI,gBAAgB;QACxC,OAAO,EAAE,UAAU,MAAM,CAAC,YAAY,IAAI,qBAAqB,EAAE;KAClE,CAAA;AACH,CAAC"}
|
package/dist/person.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ChromeClaims, ChromePerson } from './types.js';
|
|
2
|
+
/** The account this person is acting in, or undefined when they are on none. */
|
|
3
|
+
export declare function actingAccount(claims: ChromeClaims): ChromeClaims['accounts'][number] | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* One or two letters for the avatar: the first and last word of the name, or
|
|
6
|
+
* else the first letter of the email. Never empty, so the avatar always draws.
|
|
7
|
+
*/
|
|
8
|
+
export declare function initialsOf(name: string | null, email: string): string;
|
|
9
|
+
export declare function personFrom(claims: ChromeClaims): ChromePerson;
|
package/dist/person.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The account this person is acting in, or undefined when they are on none. */
|
|
2
|
+
export function actingAccount(claims) {
|
|
3
|
+
return claims.act === null ? undefined : claims.accounts.find((account) => account.id === claims.act);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* One or two letters for the avatar: the first and last word of the name, or
|
|
7
|
+
* else the first letter of the email. Never empty, so the avatar always draws.
|
|
8
|
+
*/
|
|
9
|
+
export function initialsOf(name, email) {
|
|
10
|
+
const words = (name ?? '').trim().split(/\s+/).filter(Boolean);
|
|
11
|
+
const first = words[0]?.[0];
|
|
12
|
+
const last = words.length > 1 ? words[words.length - 1]?.[0] : undefined;
|
|
13
|
+
const fromName = `${first ?? ''}${last ?? ''}`;
|
|
14
|
+
if (fromName)
|
|
15
|
+
return fromName.toUpperCase();
|
|
16
|
+
return (email.trim()[0] ?? '?').toUpperCase();
|
|
17
|
+
}
|
|
18
|
+
export function personFrom(claims) {
|
|
19
|
+
const account = actingAccount(claims);
|
|
20
|
+
const orgName = claims.orgName?.trim();
|
|
21
|
+
return {
|
|
22
|
+
name: claims.name,
|
|
23
|
+
email: claims.email,
|
|
24
|
+
initials: initialsOf(claims.name, claims.email),
|
|
25
|
+
org: orgName ? { name: orgName } : null,
|
|
26
|
+
role: account?.role ?? null,
|
|
27
|
+
otherAccounts: Math.max(0, claims.accounts.length - (account ? 1 : 0)),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=person.js.map
|
|
@@ -0,0 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,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC;QAC/C,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI;QACvC,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,IAAI;QAC3B,aAAa,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACvE,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ChromeClaims, ChromeConfig, ChromeProducts } from './types.js';
|
|
2
|
+
export declare const READ_TIMEOUT_MS = 5000;
|
|
3
|
+
/** For tests: forget every cached list. */
|
|
4
|
+
export declare function forgetProducts(): void;
|
|
5
|
+
/**
|
|
6
|
+
* Identity's `GET /api/v1/products`, as this person, by forwarding their two
|
|
7
|
+
* session cookies (no service key: Identity filters the list by audience for
|
|
8
|
+
* the viewer, B33-1725). Five seconds, then the last good list, then null.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readProducts(input: {
|
|
11
|
+
claims: ChromeClaims;
|
|
12
|
+
cookies: {
|
|
13
|
+
sid: string;
|
|
14
|
+
ctx: string | null;
|
|
15
|
+
};
|
|
16
|
+
config: ChromeConfig;
|
|
17
|
+
}, fetchImpl: typeof fetch): Promise<ChromeProducts | null>;
|
package/dist/products.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { actingAccount } from './person.js';
|
|
2
|
+
import { DEFAULT_SUPPORT_EMAIL } from './links.js';
|
|
3
|
+
const WALLET_SLUG = 'wallet';
|
|
4
|
+
const PINNED = 4;
|
|
5
|
+
export const READ_TIMEOUT_MS = 5_000;
|
|
6
|
+
/**
|
|
7
|
+
* The last list that read cleanly, per Identity origin, without `entitled`:
|
|
8
|
+
* that half is per person and is rebuilt from the claims on a fallback.
|
|
9
|
+
* Module scope, so it lives as long as the server process, as the Hub's does.
|
|
10
|
+
*/
|
|
11
|
+
const lastGood = new Map();
|
|
12
|
+
/** For tests: forget every cached list. */
|
|
13
|
+
export function forgetProducts() {
|
|
14
|
+
lastGood.clear();
|
|
15
|
+
}
|
|
16
|
+
function parseRegistry(body) {
|
|
17
|
+
if (!body || typeof body !== 'object')
|
|
18
|
+
return null;
|
|
19
|
+
const products = body.products;
|
|
20
|
+
if (!Array.isArray(products) || products.length === 0)
|
|
21
|
+
return null;
|
|
22
|
+
const entries = [];
|
|
23
|
+
for (const p of products) {
|
|
24
|
+
if (!p || typeof p !== 'object')
|
|
25
|
+
return null;
|
|
26
|
+
const { slug, name, url, live, entitled } = p;
|
|
27
|
+
if (typeof slug !== 'string' || typeof name !== 'string' || typeof url !== 'string')
|
|
28
|
+
return null;
|
|
29
|
+
if (typeof live !== 'boolean' || typeof entitled !== 'boolean')
|
|
30
|
+
return null;
|
|
31
|
+
entries.push({ slug, name, url, live, entitled });
|
|
32
|
+
}
|
|
33
|
+
return entries;
|
|
34
|
+
}
|
|
35
|
+
/** The Hub's `cardState`, without its words: open, soon, or ask support. */
|
|
36
|
+
function stateOf(entry, hasAccount, supportEmail) {
|
|
37
|
+
if (!entry.live || !hasAccount)
|
|
38
|
+
return { state: 'soon', href: null };
|
|
39
|
+
if (!entry.entitled)
|
|
40
|
+
return { state: 'ask', href: `mailto:${supportEmail}` };
|
|
41
|
+
return { state: 'open', href: entry.url };
|
|
42
|
+
}
|
|
43
|
+
const shortNameOf = (name) => name.replace(/^Boost\s+/i, '') || name;
|
|
44
|
+
function shape(entries, hasAccount, supportEmail, stale) {
|
|
45
|
+
const wallet = entries.find((entry) => entry.slug === WALLET_SLUG);
|
|
46
|
+
const walletHref = wallet?.live ? wallet.url : null;
|
|
47
|
+
const all = entries
|
|
48
|
+
.filter((entry) => entry.slug !== WALLET_SLUG)
|
|
49
|
+
.map((entry) => ({ slug: entry.slug, name: entry.name, shortName: shortNameOf(entry.name), ...stateOf(entry, hasAccount, supportEmail) }));
|
|
50
|
+
return {
|
|
51
|
+
all,
|
|
52
|
+
pinned: all.slice(0, PINNED).map((product) => product.slug),
|
|
53
|
+
walletHref,
|
|
54
|
+
buyTokensHref: walletHref ? `${walletHref.replace(/\/+$/, '')}/subscribe` : null,
|
|
55
|
+
stale,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Identity's `GET /api/v1/products`, as this person, by forwarding their two
|
|
60
|
+
* session cookies (no service key: Identity filters the list by audience for
|
|
61
|
+
* the viewer, B33-1725). Five seconds, then the last good list, then null.
|
|
62
|
+
*/
|
|
63
|
+
export async function readProducts(input, fetchImpl) {
|
|
64
|
+
const identity = input.config.identityUrl.replace(/\/+$/, '');
|
|
65
|
+
const supportEmail = input.config.supportEmail ?? DEFAULT_SUPPORT_EMAIL;
|
|
66
|
+
const account = actingAccount(input.claims);
|
|
67
|
+
const hasAccount = account !== undefined;
|
|
68
|
+
const fallback = () => {
|
|
69
|
+
const cached = lastGood.get(identity);
|
|
70
|
+
if (!cached)
|
|
71
|
+
return null;
|
|
72
|
+
const entitled = (slug) => slug === WALLET_SLUG ? hasAccount : hasAccount && (account?.products ?? []).includes(slug);
|
|
73
|
+
return shape(cached.map((entry) => ({ ...entry, entitled: entitled(entry.slug) })), hasAccount, supportEmail, true);
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const cookie = [`b33_sid=${input.cookies.sid}`, input.cookies.ctx ? `b33_ctx=${input.cookies.ctx}` : null]
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join('; ');
|
|
79
|
+
const res = await fetchImpl(`${identity}/api/v1/products`, {
|
|
80
|
+
headers: { cookie },
|
|
81
|
+
cache: 'no-store',
|
|
82
|
+
signal: AbortSignal.timeout(READ_TIMEOUT_MS),
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok)
|
|
85
|
+
return fallback();
|
|
86
|
+
const entries = parseRegistry(await res.json().catch(() => null));
|
|
87
|
+
if (!entries)
|
|
88
|
+
return fallback();
|
|
89
|
+
lastGood.set(identity, entries.map(({ slug, name, url, live }) => ({ slug, name, url, live })));
|
|
90
|
+
return shape(entries, hasAccount, supportEmail, false);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return fallback();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=products.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"products.js","sourceRoot":"","sources":["../src/products.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAGlD,MAAM,WAAW,GAAG,QAAQ,CAAA;AAC5B,MAAM,MAAM,GAAG,CAAC,CAAA;AAChB,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAA;AAIpC;;;;GAIG;AACH,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6C,CAAA;AAErE,2CAA2C;AAC3C,MAAM,UAAU,cAAc;IAC5B,QAAQ,CAAC,KAAK,EAAE,CAAA;AAClB,CAAC;AAED,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAClD,MAAM,QAAQ,GAAI,IAA+B,CAAC,QAAQ,CAAA;IAC1D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAClE,MAAM,OAAO,GAAoB,EAAE,CAAA;IACnC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB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AAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QACjE,IAAI,CAAC,OAAO;YAAE,OAAO,QAAQ,EAAE,CAAA;QAC/B,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/F,OAAO,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,CAAC,CAAA;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,EAAE,CAAA;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChromeConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Identity's `GET /api/v1/profile`, with this app's service key acting for the
|
|
4
|
+
* person's session. Only `person.displayName` is read. Null on anything else,
|
|
5
|
+
* which tells the chrome to keep the `name` claim.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readProfileName(input: {
|
|
8
|
+
sid: string;
|
|
9
|
+
config: ChromeConfig;
|
|
10
|
+
}, fetchImpl: typeof fetch): Promise<string | null>;
|
package/dist/profile.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { READ_TIMEOUT_MS } from './products.js';
|
|
2
|
+
/**
|
|
3
|
+
* Identity's `GET /api/v1/profile`, with this app's service key acting for the
|
|
4
|
+
* person's session. Only `person.displayName` is read. Null on anything else,
|
|
5
|
+
* which tells the chrome to keep the `name` claim.
|
|
6
|
+
*/
|
|
7
|
+
export async function readProfileName(input, fetchImpl) {
|
|
8
|
+
// Viewer-only mode: no service key, so no profile read. The name claim stands.
|
|
9
|
+
const { identityKey, appId } = input.config;
|
|
10
|
+
if (!identityKey || !appId)
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetchImpl(`${input.config.identityUrl.replace(/\/+$/, '')}/api/v1/profile`, {
|
|
14
|
+
headers: {
|
|
15
|
+
authorization: `Bearer ${identityKey}`,
|
|
16
|
+
'x-boost33-app': appId,
|
|
17
|
+
'x-boost33-actor-session': input.sid,
|
|
18
|
+
},
|
|
19
|
+
cache: 'no-store',
|
|
20
|
+
signal: AbortSignal.timeout(READ_TIMEOUT_MS),
|
|
21
|
+
});
|
|
22
|
+
if (!res.ok)
|
|
23
|
+
return null;
|
|
24
|
+
const body = (await res.json().catch(() => null));
|
|
25
|
+
const name = body?.person?.displayName;
|
|
26
|
+
return typeof name === 'string' && name.trim() ? name.trim() : null;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../src/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAG/C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAA4C,EAC5C,SAAuB;IAEvB,+EAA+E;IAC/E,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,MAAM,CAAA;IAC3C,IAAI,CAAC,WAAW,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,EAAE;YAC5F,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,WAAW,EAAE;gBACtC,eAAe,EAAE,KAAK;gBACtB,yBAAyB,EAAE,KAAK,CAAC,GAAG;aACrC;YACD,KAAK,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