@runlot/access 0.1.0-rc.11

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,19 @@
1
+ export type AccessMode = "public" | "org" | "password" | "bypass";
2
+ export type OrgRole = "admin" | "member" | "viewer";
3
+ export interface Identity {
4
+ /** front 가 판정한 모드. `public` 이면 나머지는 비어 있다. */
5
+ mode: AccessMode;
6
+ /** 사용자 id. `password` 모드는 `pw:…`, `bypass` 는 `bypass`. */
7
+ subject: string | null;
8
+ email: string | null;
9
+ orgRole: OrgRole | null;
10
+ }
11
+ /**
12
+ * 요청의 신원. 헤더가 아예 없으면(front 밖에서 돈다 — 로컬 `wrangler dev` 류)
13
+ * `public` 으로 읽는다: front 가 Mode 를 **항상** 붙이므로, 없는 것은 "판정이
14
+ * 없었다" 이고 그것은 열린 것과 같다.
15
+ */
16
+ export declare function identity(request: Request): Identity;
17
+ /** 로그인이 있는가 — `public` 도 `bypass` 도 아닌 사람. */
18
+ export declare function isSignedIn(who: Identity): boolean;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,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,8CAA8C;IAC9C,IAAI,EAAE,UAAU,CAAC;IACjB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACzB;AAKD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAYnD;AAED,8CAA8C;AAC9C,wBAAgB,UAAU,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAEjD"}
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ // `identity(request)` — front 가 붙인 신원을 읽는다 (docs/access.md §4.2).
2
+ //
3
+ // `env.auth` 가 아니라 요청에서 읽는 이유는 취향이 아니라 제약이다: `env` 는
4
+ // 워커 수명 동안 고정된 묶음이고 신원은 요청마다 다른 값이다. 요청에서 읽으면
5
+ // 암묵 저장소(AsyncLocalStorage)가 스트리밍·waitUntil 경계에서 끊기는 문제가
6
+ // 아예 없다.
7
+ //
8
+ // 헤더는 front 가 인바운드 `Runlot-*` 를 전부 지운 뒤 붙이므로 위조가 안 된다
9
+ // (proto/front-headers.md). 이 함수는 그것을 **믿는다** — 워커가 front 를 지나지
10
+ // 않고 직접 열리는 배치는 없다.
11
+ const MODES = new Set(["public", "org", "password", "bypass"]);
12
+ const ROLES = new Set(["admin", "member", "viewer"]);
13
+ /**
14
+ * 요청의 신원. 헤더가 아예 없으면(front 밖에서 돈다 — 로컬 `wrangler dev` 류)
15
+ * `public` 으로 읽는다: front 가 Mode 를 **항상** 붙이므로, 없는 것은 "판정이
16
+ * 없었다" 이고 그것은 열린 것과 같다.
17
+ */
18
+ export function identity(request) {
19
+ const h = request.headers;
20
+ const rawMode = h.get("Runlot-Access-Mode") ?? "public";
21
+ const mode = (MODES.has(rawMode) ? rawMode : "public");
22
+ if (mode === "public")
23
+ return { mode, subject: null, email: null, orgRole: null };
24
+ const rawRole = h.get("Runlot-Access-Org-Role");
25
+ return {
26
+ mode,
27
+ subject: h.get("Runlot-Access-Subject"),
28
+ email: h.get("Runlot-Access-Email"),
29
+ orgRole: rawRole !== null && ROLES.has(rawRole) ? rawRole : null,
30
+ };
31
+ }
32
+ /** 로그인이 있는가 — `public` 도 `bypass` 도 아닌 사람. */
33
+ export function isSignedIn(who) {
34
+ return who.mode === "org";
35
+ }
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@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;AAC9C,MAAM,UAAU,UAAU,CAAC,GAAa;IACtC,OAAO,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC;AAC5B,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@runlot/access",
3
+ "version": "0.1.0-rc.11",
4
+ "description": "front 가 붙인 접근 신원(Runlot-Access-*)을 읽는다 (docs/access.md §4.2)",
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.11"
30
+ },
31
+ "scripts": {
32
+ "test": "node build.mjs",
33
+ "typecheck": "tsc --noEmit",
34
+ "build": "tsc -p tsconfig.build.json"
35
+ }
36
+ }