@runlot/access 0.1.0-rc.100

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.
@@ -0,0 +1,21 @@
1
+ export type AccessMode = "public" | "org" | "password" | "bypass";
2
+ export type OrgRole = "admin" | "member" | "viewer";
3
+ export interface Identity {
4
+ /** The mode the front decided. When it is `public`, the rest is empty. */
5
+ mode: AccessMode;
6
+ /** The user id. In `password` mode it is `pw:…`, in `bypass` it is
7
+ * `bypass`. */
8
+ subject: string | null;
9
+ email: string | null;
10
+ orgRole: OrgRole | null;
11
+ }
12
+ /**
13
+ * The identity of the request. When the headers are absent entirely (running
14
+ * outside the front — local `wrangler dev` and the like) it reads as `public`:
15
+ * the front **always** attaches Mode, so its absence means "there was no
16
+ * decision", and that is the same as open.
17
+ */
18
+ export declare function identity(request: Request): Identity;
19
+ /** Is there a login — somebody who is neither `public` nor `bypass`. */
20
+ export declare function isSignedIn(who: Identity): boolean;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,CAAC;AAClE,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEpD,MAAM,WAAW,QAAQ;IACvB,0EAA0E;IAC1E,IAAI,EAAE,UAAU,CAAC;IACjB;oBACgB;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACzB;AAKD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAYnD;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAEjD"}
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ // `identity(request)` — reads the identity the front attached
2
+ // (docs/access.md §4.2).
3
+ //
4
+ // Reading it from the request rather than from `env.auth` is a constraint, not
5
+ // a taste: `env` is a bundle fixed for the lifetime of the worker, and the
6
+ // identity is a different value on every request. Reading it from the request
7
+ // means the problem of an implicit store (AsyncLocalStorage) being cut at a
8
+ // streaming or waitUntil boundary does not exist at all.
9
+ //
10
+ // The headers cannot be forged, because the front attaches them after erasing
11
+ // every inbound `Runlot-*` (proto/front-headers.md). This function **trusts**
12
+ // that — there is no deployment where a worker is opened directly without
13
+ // passing through the front.
14
+ const MODES = new Set(["public", "org", "password", "bypass"]);
15
+ const ROLES = new Set(["admin", "member", "viewer"]);
16
+ /**
17
+ * The identity of the request. When the headers are absent entirely (running
18
+ * outside the front — local `wrangler dev` and the like) it reads as `public`:
19
+ * the front **always** attaches Mode, so its absence means "there was no
20
+ * decision", and that is the same as open.
21
+ */
22
+ export function identity(request) {
23
+ const h = request.headers;
24
+ const rawMode = h.get("Runlot-Access-Mode") ?? "public";
25
+ const mode = (MODES.has(rawMode) ? rawMode : "public");
26
+ if (mode === "public")
27
+ return { mode, subject: null, email: null, orgRole: null };
28
+ const rawRole = h.get("Runlot-Access-Org-Role");
29
+ return {
30
+ mode,
31
+ subject: h.get("Runlot-Access-Subject"),
32
+ email: h.get("Runlot-Access-Email"),
33
+ orgRole: rawRole !== null && ROLES.has(rawRole) ? rawRole : null,
34
+ };
35
+ }
36
+ /** Is there a login — somebody who is neither `public` nor `bypass`. */
37
+ export function isSignedIn(who) {
38
+ return who.mode === "org";
39
+ }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,yBAAyB;AACzB,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AA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ED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@runlot/access",
3
+ "version": "0.1.0-rc.100",
4
+ "description": "Reads the access identity (Runlot-Access-* headers) that Runlot attaches to a request",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/runlot/runlot",
11
+ "directory": "web/packages/access"
12
+ },
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "devDependencies": {
26
+ "@types/node": "^22.10.2",
27
+ "esbuild": "^0.24.2",
28
+ "typescript": "^5.7.2",
29
+ "@runlot/config": "0.1.0-rc.100"
30
+ },
31
+ "scripts": {
32
+ "test": "node build.mjs",
33
+ "typecheck": "tsc --noEmit",
34
+ "build": "tsc -p tsconfig.build.json"
35
+ }
36
+ }