@appshell/runtime 1.0.0-alpha.45 → 1.0.0-alpha.47

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/main.js CHANGED
@@ -1 +1 @@
1
- !function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var s in t)("object"==typeof exports?exports:e)[s]=t[s]}}(this,(()=>(()=>{"use strict";var e={d:(r,t)=>{for(var s in t)e.o(t,s)&&!e.o(r,s)&&Object.defineProperty(r,s,{enumerable:!0,get:t[s]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{MissingScopeError:()=>o,MissingVarsError:()=>t,VarsConflictError:()=>s,hasVars:()=>c,readVars:()=>i,resetVars:()=>p,setVars:()=>n});class t extends Error{constructor(e,r){super(`No vars were delivered for '${e}'. ${r.length?`Vars are present for ${r.map((e=>`'${e}'`)).join(", ")} — check that '${e}' matches the module federation name the registry knows this package by.`:"Nothing has delivered vars on this page — check that the host and this package both declare '@appshell/runtime' as a shared singleton."}`),this.name="MissingVarsError",this.scope=e}}class s extends Error{constructor(e){super(`Vars for '${e}' were already delivered and cannot be replaced. A scope receives its vars once per page load.`),this.name="VarsConflictError",this.scope=e}}class o extends Error{constructor(){super("Cannot tell which package this is. '@appshell/runtime/vars' needs the scope that AppshellPlugin injects at build time — add it to this package's webpack plugins, or read the store directly with readVars(scope) from '@appshell/runtime'."),this.name="MissingScopeError"}}const a=new Map,n=(e,r)=>{const t=a.get(e);var o,n;if(t){if(o=t,n=r,![...new Set([...Object.keys(o),...Object.keys(n)])].every((e=>o[e]===n[e])))throw new s(e)}else a.set(e,Object.freeze({...r}))},i=e=>{const r=a.get(e);if(!r)throw new t(e,[...a.keys()]);return r},c=e=>a.has(e),p=()=>{a.clear()};return r})()));
1
+ !function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var s in t)("object"==typeof exports?exports:e)[s]=t[s]}}(this,(()=>(()=>{"use strict";var e={d:(r,t)=>{for(var s in t)e.o(t,s)&&!e.o(r,s)&&Object.defineProperty(r,s,{enumerable:!0,get:t[s]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{ANONYMOUS:()=>a,MissingScopeError:()=>o,MissingVarsError:()=>t,VarsConflictError:()=>s,getIdentity:()=>n,hasVars:()=>d,readVars:()=>p,resetVars:()=>l,setVars:()=>c});class t extends Error{constructor(e,r){super(`No vars were delivered for '${e}'. ${r.length?`Vars are present for ${r.map((e=>`'${e}'`)).join(", ")} — check that '${e}' matches the module federation name the registry knows this package by.`:"Nothing has delivered vars on this page — check that the host and this package both declare '@appshell/runtime' as a shared singleton."}`),this.name="MissingVarsError",this.scope=e}}class s extends Error{constructor(e){super(`Vars for '${e}' were already delivered and cannot be replaced. A scope receives its vars once per page load.`),this.name="VarsConflictError",this.scope=e}}class o extends Error{constructor(){super("Cannot tell which package this is. '@appshell/runtime/vars' needs the scope that AppshellPlugin injects at build time — add it to this package's webpack plugins, or read the store directly with readVars(scope) from '@appshell/runtime'."),this.name="MissingScopeError"}}const a={authenticated:!1},n=()=>{if("undefined"==typeof window)return a;const e=window.__appshell_identity__;return(e=>{if("object"!=typeof e||null===e)return!1;const r=e;return!1===r.authenticated||!0===r.authenticated&&"string"==typeof r.subject&&"string"==typeof r.username&&Array.isArray(r.roles)})(e)?e:a},i=new Map,c=(e,r)=>{const t=i.get(e);var o,a;if(t){if(o=t,a=r,![...new Set([...Object.keys(o),...Object.keys(a)])].every((e=>o[e]===a[e])))throw new s(e)}else i.set(e,Object.freeze({...r}))},p=e=>{const r=i.get(e);if(!r)throw new t(e,[...i.keys()]);return r},d=e=>i.has(e),l=()=>{i.clear()};return r})()));
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Who is looking at the page, as the registry was told by the gateway.
3
+ *
4
+ * Unlike vars this is not scope-specific — there is one visitor per page, not one
5
+ * per package — so it lives in the main entry rather than needing the subpath
6
+ * trick `@appshell/runtime/vars` uses to get a per-package scope substituted.
7
+ *
8
+ * It is also not delivered through the vars store, and that is a constraint rather
9
+ * than a preference: `setVars` freezes on first write and throws on replacement,
10
+ * which is what stops one package overwriting another's configuration. Identity
11
+ * changes — sign-in, sign-out, token refresh — so it cannot live behind a
12
+ * write-once door without either breaking that guarantee or never updating.
13
+ */
14
+ /**
15
+ * A discriminated union rather than an optional user, so `username` cannot be read
16
+ * without the anonymous case having been handled. The compiler enforces what a
17
+ * convention would only ask for.
18
+ */
19
+ export type Identity = {
20
+ authenticated: false;
21
+ } | {
22
+ authenticated: true;
23
+ subject: string;
24
+ username: string;
25
+ roles: string[];
26
+ };
27
+ export declare const ANONYMOUS: Identity;
28
+ declare global {
29
+ interface Window {
30
+ __appshell_identity__?: unknown;
31
+ }
32
+ }
33
+ /**
34
+ * The visitor, or the anonymous identity when there is none.
35
+ *
36
+ * Never throws and never returns undefined — an absent or malformed value is
37
+ * anonymous, which is a state every caller already has to handle. That is the
38
+ * opposite of `readVars`, which throws when a scope is missing, and the difference
39
+ * is deliberate: a package with no configuration cannot do its job, while a package
40
+ * with no signed-in user usually can and simply renders differently.
41
+ *
42
+ * This is a typed accessor, not a boundary. The value is inlined into the document
43
+ * and any script on the page can read it directly, exactly as with vars. Treat it
44
+ * as what the server said about the visitor, never as proof of anything: it carries
45
+ * no token and grants nothing. Anything that matters is re-checked server-side.
46
+ */
47
+ export declare const getIdentity: () => Identity;
@@ -1,4 +1,6 @@
1
1
  export { MissingScopeError, MissingVarsError, VarsConflictError } from './errors';
2
+ export { ANONYMOUS, getIdentity } from './identity';
3
+ export type { Identity } from './identity';
2
4
  export { hasVars, readVars, resetVars, setVars } from './store';
3
5
  export type { Vars } from './types';
4
6
  export type { AppshellIndex, AppshellRemote, Metadata } from './wire';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appshell/runtime",
3
- "version": "1.0.0-alpha.45",
3
+ "version": "1.0.0-alpha.47",
4
4
  "description": "The shared singleton that delivers a package's runtime configuration to it",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -48,5 +48,5 @@
48
48
  "appshell"
49
49
  ],
50
50
  "license": "MIT",
51
- "gitHead": "968404a6709a3aacb31b136e8a890dbe53a9bbcf"
51
+ "gitHead": "9299f50b31ded495f5e846731a940fe69299f8fe"
52
52
  }