@reopt-ai/workspace-sdk 0.0.0-stage → 0.1.0-rc.0

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,102 @@
1
+ import * as jose from "jose";
2
+
3
+ //#region src/machine/keys.ts
4
+ /**
5
+ * 기계 클라이언트 키 자재 (RFC-0034 §3.3) — 생성 · 공개키 추출 · JWKS 문서 · env 읽기.
6
+ *
7
+ * 서브 제품은 키쌍을 **자기 쪽에서** 만들고 개인키는 env(`REOPT_CLIENT_PRIVATE_KEY_JWK`)에만 둔다.
8
+ * 리옵트에는 공개키 주소(`jwksUri`)만 등록되므로 비밀이 전송되는 순간이 없다. 회전은 2단계다:
9
+ * ① `REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT`에 새 키를 두면 JWKS에 두 키가 실리고 서명은 NEXT로 간다
10
+ * ② 리옵트가 새 kid로 토큰을 발급하면(JWKS 캐시 5분) NEXT를 본 키로 승격하고 옛 키를 지운다.
11
+ *
12
+ * 🔑 kid는 **JWK 지문(RFC 7638)**이다 — 사람이 이름을 짓지 않고, 같은 키는 어디서 만들어도 같은 kid다.
13
+ */
14
+ const DEFAULT_CLIENT_KEY_ALGORITHM = "EdDSA";
15
+ const PRIVATE_FIELDS = [
16
+ "d",
17
+ "p",
18
+ "q",
19
+ "dp",
20
+ "dq",
21
+ "qi",
22
+ "oth"
23
+ ];
24
+ function assertAlgorithm(value) {
25
+ if (value !== "EdDSA" && value !== "ES256" && value !== "RS256") throw new Error(`[@reopt-ai/workspace-sdk/machine] unsupported client key algorithm: ${String(value)} (EdDSA · ES256 · RS256)`);
26
+ }
27
+ /** 새 키쌍 — 개인키 JWK(kid·alg 포함)와 공개키 JWK. 개인키는 env로만 가고 로그에 찍지 않는다. */
28
+ async function generateClientKeyPair(options = {}) {
29
+ const algorithm = options.algorithm ?? "EdDSA";
30
+ const pair = await jose.generateKeyPair(algorithm, algorithm === "EdDSA" ? {
31
+ crv: "Ed25519",
32
+ extractable: true
33
+ } : { extractable: true });
34
+ const privateJwk = await jose.exportJWK(pair.privateKey);
35
+ const publicJwk = await jose.exportJWK(pair.publicKey);
36
+ const kid = await jose.calculateJwkThumbprint(publicJwk);
37
+ return {
38
+ privateKeyJwk: {
39
+ ...privateJwk,
40
+ kid,
41
+ alg: algorithm,
42
+ use: "sig"
43
+ },
44
+ publicKeyJwk: {
45
+ ...publicJwk,
46
+ kid,
47
+ alg: algorithm,
48
+ use: "sig"
49
+ },
50
+ kid
51
+ };
52
+ }
53
+ /** 개인키 JWK에서 공개키만 — JWKS 응답·DPoP 증명 헤더(`jwk`)에 싣는 값. */
54
+ function toPublicJwk(privateKeyJwk) {
55
+ const copy = { ...privateKeyJwk };
56
+ for (const field of PRIVATE_FIELDS) delete copy[field];
57
+ return copy;
58
+ }
59
+ /** JSON 문자열(env 값)을 개인키 JWK로 — 모양이 틀리면 **어디가** 틀렸는지 말하고 값은 절대 되풀이하지 않는다. */
60
+ function parseClientPrivateJwk(raw, envName = "REOPT_CLIENT_PRIVATE_KEY_JWK") {
61
+ let parsed;
62
+ try {
63
+ parsed = JSON.parse(raw);
64
+ } catch {
65
+ throw new Error(`[@reopt-ai/workspace-sdk/machine] ${envName} is not valid JSON`);
66
+ }
67
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`[@reopt-ai/workspace-sdk/machine] ${envName} must be a JWK object`);
68
+ const jwk = parsed;
69
+ if (typeof jwk.kty !== "string") throw new Error(`[@reopt-ai/workspace-sdk/machine] ${envName} is missing "kty"`);
70
+ if (typeof jwk.d !== "string") throw new Error(`[@reopt-ai/workspace-sdk/machine] ${envName} is a public key — the private JWK (with "d") is required`);
71
+ if (typeof jwk.kid !== "string" || jwk.kid.length === 0) throw new Error(`[@reopt-ai/workspace-sdk/machine] ${envName} is missing "kid" (use generateClientKeyPair())`);
72
+ assertAlgorithm(jwk.alg);
73
+ return jwk;
74
+ }
75
+ /**
76
+ * env에서 키 링을 읽는다 — `REOPT_CLIENT_PRIVATE_KEY_JWK`(필수) + `REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT`(회전 중에만).
77
+ * 없으면 null(호출자가 "설정 안 됨"을 fail-closed로 다룬다).
78
+ */
79
+ function readClientKeyRing(env = typeof process === "undefined" ? {} : process.env, names = {}) {
80
+ const currentName = names.current ?? "REOPT_CLIENT_PRIVATE_KEY_JWK";
81
+ const nextName = names.next ?? "REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT";
82
+ const currentRaw = env[currentName]?.trim();
83
+ if (!currentRaw) return null;
84
+ const current = parseClientPrivateJwk(currentRaw, currentName);
85
+ const nextRaw = env[nextName]?.trim();
86
+ const next = nextRaw ? parseClientPrivateJwk(nextRaw, nextName) : null;
87
+ if (next && next.kid === current.kid) throw new Error(`[@reopt-ai/workspace-sdk/machine] ${nextName} has the same kid as ${currentName} — generate a new key for rotation`);
88
+ return {
89
+ signing: next ?? current,
90
+ published: next ? [current, next] : [current]
91
+ };
92
+ }
93
+ /** `/.well-known/reopt-client-jwks.json` 응답 본문 — 공개키만. */
94
+ function buildClientJwks(keys) {
95
+ return { keys: keys.map(toPublicJwk) };
96
+ }
97
+ /** JWKS 응답의 정본 경로 — 리옵트에 등록하는 `jwksUri`는 `${origin}${CLIENT_JWKS_PATH}`다. */
98
+ const CLIENT_JWKS_PATH = "/.well-known/reopt-client-jwks.json";
99
+
100
+ //#endregion
101
+ export { parseClientPrivateJwk as a, generateClientKeyPair as i, DEFAULT_CLIENT_KEY_ALGORITHM as n, readClientKeyRing as o, buildClientJwks as r, toPublicJwk as s, CLIENT_JWKS_PATH as t };
102
+ //# sourceMappingURL=keys-6gwtNd0g.js.map
@@ -0,0 +1,44 @@
1
+ import * as jose from "jose";
2
+ //#region src/machine/keys.d.ts
3
+ declare const DEFAULT_CLIENT_KEY_ALGORITHM: "EdDSA";
4
+ type ClientKeyAlgorithm = "EdDSA" | "ES256" | "RS256";
5
+ type ClientPrivateJwk = jose.JWK & {
6
+ kid: string;
7
+ alg: ClientKeyAlgorithm;
8
+ };
9
+ type ClientPublicJwk = Omit<ClientPrivateJwk, "d" | "p" | "q" | "dp" | "dq" | "qi" | "oth">;
10
+ /** 새 키쌍 — 개인키 JWK(kid·alg 포함)와 공개키 JWK. 개인키는 env로만 가고 로그에 찍지 않는다. */
11
+ declare function generateClientKeyPair(options?: {
12
+ algorithm?: ClientKeyAlgorithm;
13
+ }): Promise<{
14
+ privateKeyJwk: ClientPrivateJwk;
15
+ publicKeyJwk: ClientPublicJwk;
16
+ kid: string;
17
+ }>;
18
+ /** 개인키 JWK에서 공개키만 — JWKS 응답·DPoP 증명 헤더(`jwk`)에 싣는 값. */
19
+ declare function toPublicJwk(privateKeyJwk: ClientPrivateJwk): ClientPublicJwk;
20
+ /** JSON 문자열(env 값)을 개인키 JWK로 — 모양이 틀리면 **어디가** 틀렸는지 말하고 값은 절대 되풀이하지 않는다. */
21
+ declare function parseClientPrivateJwk(raw: string, envName?: string): ClientPrivateJwk;
22
+ type ClientKeyRing = {
23
+ /** 서명에 쓰는 키 — NEXT가 있으면 NEXT(회전 ①). */
24
+ signing: ClientPrivateJwk;
25
+ /** JWKS에 실을 키 전부(현재 + NEXT). */
26
+ published: ClientPrivateJwk[];
27
+ };
28
+ /**
29
+ * env에서 키 링을 읽는다 — `REOPT_CLIENT_PRIVATE_KEY_JWK`(필수) + `REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT`(회전 중에만).
30
+ * 없으면 null(호출자가 "설정 안 됨"을 fail-closed로 다룬다).
31
+ */
32
+ declare function readClientKeyRing(env?: Record<string, string | undefined>, names?: {
33
+ current?: string;
34
+ next?: string;
35
+ }): ClientKeyRing | null;
36
+ /** `/.well-known/reopt-client-jwks.json` 응답 본문 — 공개키만. */
37
+ declare function buildClientJwks(keys: readonly ClientPrivateJwk[]): {
38
+ keys: ClientPublicJwk[];
39
+ };
40
+ /** JWKS 응답의 정본 경로 — 리옵트에 등록하는 `jwksUri`는 `${origin}${CLIENT_JWKS_PATH}`다. */
41
+ declare const CLIENT_JWKS_PATH = "/.well-known/reopt-client-jwks.json";
42
+ //#endregion
43
+ export { ClientPublicJwk as a, generateClientKeyPair as c, toPublicJwk as d, ClientPrivateJwk as i, parseClientPrivateJwk as l, ClientKeyAlgorithm as n, DEFAULT_CLIENT_KEY_ALGORITHM as o, ClientKeyRing as r, buildClientJwks as s, CLIENT_JWKS_PATH as t, readClientKeyRing as u };
44
+ //# sourceMappingURL=keys-B2pA8EkU.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { a as ClientPublicJwk, c as generateClientKeyPair, d as toPublicJwk, i as ClientPrivateJwk, l as parseClientPrivateJwk, n as ClientKeyAlgorithm, o as DEFAULT_CLIENT_KEY_ALGORITHM, r as ClientKeyRing, s as buildClientJwks, t as CLIENT_JWKS_PATH, u as readClientKeyRing } from "../keys-B2pA8EkU.js";
2
+ import { a as createDpopProof, i as MachineTokenState, n as MachineClientConfig, o as createMachineClient, r as MachineTokenError, t as MachineClient } from "../client-DlgVNj3w.js";
3
+ export { CLIENT_JWKS_PATH, type ClientKeyAlgorithm, type ClientKeyRing, type ClientPrivateJwk, type ClientPublicJwk, DEFAULT_CLIENT_KEY_ALGORITHM, type MachineClient, type MachineClientConfig, MachineTokenError, type MachineTokenState, buildClientJwks, createDpopProof, createMachineClient, generateClientKeyPair, parseClientPrivateJwk, readClientKeyRing, toPublicJwk };
@@ -0,0 +1,4 @@
1
+ import { a as parseClientPrivateJwk, i as generateClientKeyPair, n as DEFAULT_CLIENT_KEY_ALGORITHM, o as readClientKeyRing, r as buildClientJwks, s as toPublicJwk, t as CLIENT_JWKS_PATH } from "../keys-6gwtNd0g.js";
2
+ import { n as createDpopProof, r as createMachineClient, t as MachineTokenError } from "../client-XAvKlbbn.js";
3
+
4
+ export { CLIENT_JWKS_PATH, DEFAULT_CLIENT_KEY_ALGORITHM, MachineTokenError, buildClientJwks, createDpopProof, createMachineClient, generateClientKeyPair, parseClientPrivateJwk, readClientKeyRing, toPublicJwk };
@@ -0,0 +1,7 @@
1
+ //#region src/machine/keygen-cli.d.ts
2
+ declare function runKeygen(argv: string[], out?: {
3
+ log: (line: string) => void;
4
+ }): Promise<number>;
5
+ //#endregion
6
+ export { runKeygen };
7
+ //# sourceMappingURL=keygen-cli.d.ts.map
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ import { i as generateClientKeyPair, t as CLIENT_JWKS_PATH } from "../keys-6gwtNd0g.js";
3
+
4
+ //#region src/machine/keygen-cli.ts
5
+ /**
6
+ * `npx -p @reopt-ai/workspace-sdk reopt-keygen` — 기계 클라이언트 키쌍을 만들고 **개인키는 stdout 한 줄**로만 낸다.
7
+ *
8
+ * 콘솔(platform.reopt.ai)이 개인키를 만들지 않는 이유가 여기 있다(RFC-0034 §6.5): 키가 화면을 한 번이라도
9
+ * 지나면 "한 번만 보이는 값"이 된다. 이 명령은 개발자의 터미널에서 돌고 출력은 env 파일로만 간다.
10
+ *
11
+ * --alg EdDSA|ES256|RS256 (기본 EdDSA)
12
+ * --next 회전 ①용 — env 이름을 REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT로 낸다
13
+ * --json { privateKeyJwk, publicKeyJwk, kid }를 JSON으로(스크립트용)
14
+ */
15
+ function readFlag(argv, name) {
16
+ const index = argv.indexOf(name);
17
+ if (index === -1) return void 0;
18
+ return argv[index + 1];
19
+ }
20
+ async function runKeygen(argv, out = console) {
21
+ const alg = readFlag(argv, "--alg") ?? "EdDSA";
22
+ if (alg !== "EdDSA" && alg !== "ES256" && alg !== "RS256") {
23
+ out.log(`reopt-keygen: unsupported --alg ${alg} (EdDSA · ES256 · RS256)`);
24
+ return 2;
25
+ }
26
+ const next = argv.includes("--next");
27
+ const json = argv.includes("--json");
28
+ const { privateKeyJwk, publicKeyJwk, kid } = await generateClientKeyPair({ algorithm: alg });
29
+ if (json) {
30
+ out.log(JSON.stringify({
31
+ privateKeyJwk,
32
+ publicKeyJwk,
33
+ kid
34
+ }));
35
+ return 0;
36
+ }
37
+ const envName = next ? "REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT" : "REOPT_CLIENT_PRIVATE_KEY_JWK";
38
+ out.log(`# reopt machine client key — kid ${kid} (${alg})`);
39
+ out.log(`# 1) 아래 한 줄을 서버 env에 넣는다 (브라우저 번들·로그·커밋 금지)`);
40
+ out.log(`${envName}='${JSON.stringify(privateKeyJwk)}'`);
41
+ out.log(`# 2) 공개키를 게시한다 — GET ${CLIENT_JWKS_PATH}`);
42
+ out.log(`# import { buildClientJwks, readClientKeyRing } from "@reopt-ai/workspace-sdk/machine";`);
43
+ out.log(`# export const GET = () => Response.json(buildClientJwks(readClientKeyRing()!.published));`);
44
+ out.log(`# 3) 리옵트 콘솔(연동 › 자격)의 jwksUri에 https://<your-host>${CLIENT_JWKS_PATH} 를 적는다`);
45
+ if (next) {
46
+ out.log(`# 회전 ①: 두 키가 JWKS에 함께 실리고 서명은 NEXT로 간다. 리옵트가 새 kid로 토큰을 주면(최대 5분)`);
47
+ out.log(`# NEXT 값을 REOPT_CLIENT_PRIVATE_KEY_JWK로 옮기고 NEXT를 지운다(회전 ②).`);
48
+ }
49
+ return 0;
50
+ }
51
+ if (typeof process !== "undefined" && Array.isArray(process.argv) && /reopt-keygen|keygen-cli/.test(process.argv[1] ?? "")) runKeygen(process.argv.slice(2)).then((code) => {
52
+ process.exitCode = code;
53
+ });
54
+
55
+ //#endregion
56
+ export { runKeygen };
57
+ //# sourceMappingURL=keygen-cli.js.map
@@ -0,0 +1,176 @@
1
+ import { DpopReplayStore, DpopReplayStore as DpopReplayStore$1 } from "@better-auth/core/oauth2";
2
+ import * as jose from "jose";
3
+ //#region src/resource/verify.d.ts
4
+ declare const MACHINE_TOKEN_ERROR_CODES: readonly ["missing_token", "not_a_jwt", "invalid_jwt", "token_expired", "wrong_issuer", "wrong_audience", "user_token_not_allowed", "dpop_missing", "dpop_invalid", "dpop_replayed", "insufficient_scope"];
5
+ type MachineTokenErrorCode = (typeof MACHINE_TOKEN_ERROR_CODES)[number];
6
+ type MachineTokenError = {
7
+ code: MachineTokenErrorCode;
8
+ message: string;
9
+ /** 토큰에서 읽을 수 있었다면 — 감사 로그의 principalRef. 서명 검증 전 값이라 신뢰하지 말 것. */
10
+ clientId?: string;
11
+ /**
12
+ * `user_token_not_allowed`에만 실린다 — 서명·iss·aud·exp를 **통과한** 위임 토큰의 payload.
13
+ * `createResourceVerifier`의 `allowUserTokens` 경로가 두 번째 검증 없이 이어받는다.
14
+ */
15
+ payload?: jose.JWTPayload;
16
+ };
17
+ type MachinePrincipal = {
18
+ kind: "machine";
19
+ clientId: string;
20
+ scopes: string[];
21
+ /** DPoP 바인딩 키 지문(`cnf.jkt`). 없으면 Bearer 토큰. */
22
+ jkt: string | null;
23
+ /** 토큰이 발급된 audience 전부 — 서비스는 자기 origin이 들어 있는지만 본다(불변식 8). */
24
+ audiences: string[];
25
+ payload: jose.JWTPayload;
26
+ };
27
+ type VerifyMachineTokenResult = {
28
+ ok: true;
29
+ principal: MachinePrincipal;
30
+ } | {
31
+ ok: false;
32
+ error: MachineTokenError;
33
+ };
34
+ type VerifyMachineTokenInput = {
35
+ authorization: string | null | undefined;
36
+ /** `DPoP` 요청 헤더 — 토큰이 DPoP 바인딩이면 필수. */
37
+ dpopProof?: string | null;
38
+ method: string;
39
+ /** 클라이언트가 부른 공개 URL(htu). */
40
+ url: string;
41
+ issuer: string;
42
+ /** 받아들이는 audience 전부(끝 슬래시 변형 포함). */
43
+ audiences: readonly string[];
44
+ jwks: jose.JWTVerifyGetKey;
45
+ /** 바인딩 없는 토큰도 거절할지 — 플랫폼·서비스 리소스는 true(불변식 2). */
46
+ requireDpop: boolean;
47
+ replayStore?: DpopReplayStore$1;
48
+ /** 요구 scope — 하나라도 있으면 통과(`requireScope` 규약). */
49
+ requiredScopes?: readonly string[];
50
+ clockToleranceSeconds?: number;
51
+ /** DPoP 증명 허용 나이(초). better-auth 기본 300. */
52
+ dpopProofMaxAgeSeconds?: number;
53
+ now?: Date;
54
+ };
55
+ declare const JWT_ACCESS_TOKEN_TYPE = "at+jwt";
56
+ declare function looksLikeJwt(token: string): boolean;
57
+ declare function readTokenScopes(payload: jose.JWTPayload): string[];
58
+ declare function readTokenAudiences(payload: jose.JWTPayload): string[];
59
+ declare function verifyMachineToken(input: VerifyMachineTokenInput): Promise<VerifyMachineTokenResult>;
60
+ /**
61
+ * 클라이언트가 실제로 부른 공개 URL — DPoP `htu` 대조용.
62
+ *
63
+ * Vercel·dev-proxy 뒤에서 `request.url`은 rewrite 뒤 내부 경로(호스트가 `localhost:3001` 등)라
64
+ * 그대로 쓰면 정당한 증명이 전부 `htu` 불일치로 죽는다. `x-forwarded-host`·`x-forwarded-proto`가
65
+ * 있으면 그것으로 origin을 되살리고 경로·쿼리는 요청 URL의 것을 쓴다(쿼리는 htu 비교에서 어차피
66
+ * 제거된다 — RFC 9449 §4.3).
67
+ */
68
+ declare function resolvePublicRequestUrl(input: {
69
+ url: string;
70
+ headers: {
71
+ get(name: string): string | null | undefined;
72
+ };
73
+ }): string;
74
+ //#endregion
75
+ //#region src/resource/replay-store.d.ts
76
+ /** ioredis·node-redis 공통 최소 표면 — `SET key value PX ttl NX`. */
77
+ type RedisLike = {
78
+ set: (key: string, value: string, mode: "PX", ttlMs: number, condition: "NX") => Promise<"OK" | null>;
79
+ };
80
+ declare function createMemoryDpopReplayStore(): DpopReplayStore;
81
+ declare function createRedisDpopReplayStore(redis: RedisLike | undefined, options?: {
82
+ onFallback?: (reason: string) => void;
83
+ keyPrefix?: string;
84
+ }): DpopReplayStore;
85
+ //#endregion
86
+ //#region src/resource/verifier.d.ts
87
+ declare const RESOURCE_AUTH_ERROR_CODES: readonly ["missing_token", "not_a_jwt", "invalid_jwt", "token_expired", "wrong_issuer", "wrong_audience", "user_token_not_allowed", "dpop_missing", "dpop_invalid", "dpop_replayed", "insufficient_scope", "membership_revoked"];
88
+ type ResourceAuthErrorCode = (typeof RESOURCE_AUTH_ERROR_CODES)[number];
89
+ /** 요청 하나의 최소 표면 — `Request`, Hono `c.req.raw`, Next `NextRequest` 전부 맞는다. */
90
+ type ResourceRequestLike = {
91
+ method: string;
92
+ url: string;
93
+ headers: {
94
+ get(name: string): string | null | undefined;
95
+ };
96
+ };
97
+ type UserPrincipal = {
98
+ kind: "user";
99
+ userId: string;
100
+ clientId: string;
101
+ scopes: string[];
102
+ audiences: string[];
103
+ payload: jose.JWTPayload;
104
+ /** `allowUserTokens.resolve`가 돌려준 값(워크스페이스·역할 등). */
105
+ context: Record<string, unknown>;
106
+ };
107
+ type ResourcePrincipal = MachinePrincipal | UserPrincipal;
108
+ declare class ResourceAuthError extends Error {
109
+ readonly code: ResourceAuthErrorCode;
110
+ /** 403은 `insufficient_scope`·`membership_revoked`뿐, 나머지는 401. */
111
+ readonly status: 401 | 403;
112
+ readonly clientId?: string;
113
+ constructor(code: ResourceAuthErrorCode, message: string, options?: {
114
+ clientId?: string;
115
+ });
116
+ /** RFC 6750 §3 / RFC 9449 §7.1 — 401·403 응답에 실을 `WWW-Authenticate` 값. */
117
+ wwwAuthenticate(options?: {
118
+ resourceMetadataUrl?: string;
119
+ }): string;
120
+ }
121
+ declare function isResourceAuthError(error: unknown): error is ResourceAuthError;
122
+ type ResourceVerifierOptions = {
123
+ /** id.reopt.ai — 토큰 `iss`. */
124
+ issuer: string;
125
+ /** 자기 서비스 origin(들). 끝 슬래시 변형은 자동으로 더한다(불변식 8). */
126
+ audience: string | readonly string[];
127
+ /** JWKS URL(캐시·쿨다운은 jose `createRemoteJWKSet`) 또는 이미 만든 키 리졸버. 생략하면 `${issuer}/api/auth/jwks`. */
128
+ jwks?: string | URL | jose.JWTVerifyGetKey;
129
+ dpop?: {
130
+ /** 바인딩 없는 토큰도 거절할지 — 서비스 리소스는 true(기본). */
131
+ required?: boolean;
132
+ replayStore?: DpopReplayStore$1;
133
+ proofMaxAgeSeconds?: number;
134
+ };
135
+ clockToleranceSeconds?: number;
136
+ /**
137
+ * 사용자 위임 토큰(`sub ≠ client_id`)을 받을지. 콜백이 사용자를 확인(멤버십 재검사)하고
138
+ * null을 돌려주면 `membership_revoked`. 기본은 거절(`user_token_not_allowed`).
139
+ */
140
+ allowUserTokens?: {
141
+ resolve: (input: {
142
+ userId: string;
143
+ clientId: string;
144
+ scopes: string[];
145
+ payload: jose.JWTPayload;
146
+ }) => Promise<Record<string, unknown> | null>;
147
+ };
148
+ /** 요청 → 클라이언트가 실제로 부른 공개 URL(htu). 기본은 `resolvePublicRequestUrl`. */
149
+ publicUrl?: (request: ResourceRequestLike) => string;
150
+ /** 테스트용 시계. */
151
+ now?: () => Date;
152
+ /** `jwks`가 URL일 때 jose가 쓰는 fetch(테스트에서 네트워크를 막을 때). */
153
+ jwksFetch?: typeof fetch;
154
+ };
155
+ type VerifyRequestOptions = {
156
+ /** 요구 scope — 하나라도 있으면 통과(any-of). */
157
+ scope?: string | readonly string[];
158
+ };
159
+ type ResourceVerifier = {
160
+ (request: ResourceRequestLike, options?: VerifyRequestOptions): Promise<ResourcePrincipal>;
161
+ /** 던지지 않는 변형 — 미들웨어가 봉투를 직접 쓸 때. */
162
+ safe(request: ResourceRequestLike, options?: VerifyRequestOptions): Promise<{
163
+ ok: true;
164
+ principal: ResourcePrincipal;
165
+ } | {
166
+ ok: false;
167
+ error: ResourceAuthError;
168
+ }>;
169
+ /** 토큰이 리옵트 발급 JWT 액세스 토큰(`typ=at+jwt`)처럼 생겼는지 — opaque 경로와 가를 때. */
170
+ looksLikeAccessToken(authorization: string | null | undefined): boolean;
171
+ };
172
+ declare function expandAudiences(audience: string | readonly string[]): string[];
173
+ declare function createResourceVerifier(options: ResourceVerifierOptions): ResourceVerifier;
174
+ //#endregion
175
+ export { type DpopReplayStore, JWT_ACCESS_TOKEN_TYPE, MACHINE_TOKEN_ERROR_CODES, type MachinePrincipal, type MachineTokenError, type MachineTokenErrorCode, RESOURCE_AUTH_ERROR_CODES, type RedisLike, ResourceAuthError, type ResourceAuthErrorCode, type ResourcePrincipal, type ResourceRequestLike, type ResourceVerifier, type ResourceVerifierOptions, type UserPrincipal, type VerifyMachineTokenInput, type VerifyMachineTokenResult, type VerifyRequestOptions, createMemoryDpopReplayStore, createRedisDpopReplayStore, createResourceVerifier, expandAudiences, isResourceAuthError, looksLikeJwt, readTokenAudiences, readTokenScopes, resolvePublicRequestUrl, verifyMachineToken };
176
+ //# sourceMappingURL=index.d.ts.map