@reopt-ai/brandapp-sdk 3.0.0 → 3.3.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.
- package/CHANGELOG.md +111 -3
- package/README.md +29 -13
- package/dist/ai/index.js +4 -3
- package/dist/ai-provider/index.js +16 -2
- package/dist/auth/index.js +4 -3
- package/dist/better-auth/index.d.ts +1 -1
- package/dist/better-auth/index.js +35 -24
- package/dist/chunk-2LSCQHAU.js +21 -0
- package/dist/{chunk-E457LO5A.js → chunk-4U4ZPPL4.js} +4 -4
- package/dist/{chunk-K3YVJE6E.js → chunk-55KHY5GH.js} +3 -3
- package/dist/{chunk-J5Y2GSJF.js → chunk-C5VTRZWX.js} +43 -28
- package/dist/{chunk-KU2LN5SE.js → chunk-FJUCWXX3.js} +4 -4
- package/dist/{chunk-TUKIYH4Q.js → chunk-H33OTQEN.js} +3 -3
- package/dist/chunk-OG7R3UAR.js +105 -0
- package/dist/{chunk-6FLYVNZI.js → chunk-PF24XU54.js} +3 -3
- package/dist/{chunk-6KPKZ7ZB.js → chunk-QN3QD67K.js} +3 -3
- package/dist/{chunk-YRGLBM6V.js → chunk-UGBBXCZE.js} +6 -6
- package/dist/{chunk-WSEROZVO.js → chunk-UVT2E6KD.js} +6 -6
- package/dist/{chunk-PJZB4VP7.js → chunk-YPLT3RFL.js} +3 -3
- package/dist/{chunk-DI6QJPTQ.js → chunk-YTKSAWV2.js} +20 -6
- package/dist/cms/index.js +10 -6
- package/dist/dev/index.d.ts +19 -0
- package/dist/dev/index.js +107 -4
- package/dist/eav/index.d.ts +1 -1
- package/dist/eav/index.js +5 -4
- package/dist/{errors-5hd5ZR-M.d.ts → errors-BjDFIyA6.d.ts} +25 -3
- package/dist/feedback/index.js +4 -3
- package/dist/files/index.js +4 -3
- package/dist/index.d.ts +10 -1
- package/dist/index.js +14 -13
- package/dist/logout/index.d.ts +106 -0
- package/dist/logout/index.js +321 -0
- package/dist/plans/index.d.ts +107 -11
- package/dist/plans/index.js +4 -3
- package/dist/push/index.js +4 -3
- package/dist/react/hooks.d.ts +5 -1
- package/dist/react/hooks.js +63 -15
- package/dist/terms/index.js +4 -3
- package/dist/testing/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts +6 -3
- package/docs/api-reference.md +99 -3
- package/docs/cms.md +0 -1
- package/docs/dev-server.md +19 -18
- package/docs/errors.md +72 -15
- package/docs/logout.md +166 -0
- package/package.json +7 -1
- package/dist/chunk-T2WXHAAC.js +0 -54
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
|
|
2
|
+
|
|
3
|
+
type VerifyLogoutTokenOptions = {
|
|
4
|
+
/** 자기 OAuth client_id — logout_token `aud` 검증. 미지정 시 config/env에서 유도. */
|
|
5
|
+
clientId?: string;
|
|
6
|
+
/** id(IdP) 호스트 override. 미지정 시 resolveIdBaseUrl(config). */
|
|
7
|
+
idBaseUrl?: string;
|
|
8
|
+
/** SDK config (clientId·idBaseUrl 유도용). 개별 옵션이 우선. */
|
|
9
|
+
config?: ReoptSDKConfig;
|
|
10
|
+
/** iat 허용 나이(ms). 기본 5분. */
|
|
11
|
+
maxTokenAgeMs?: number;
|
|
12
|
+
};
|
|
13
|
+
type LogoutTokenClaims = {
|
|
14
|
+
/** 폐기된 IdP 세션 ID — RP 세션 종료 키. */
|
|
15
|
+
sid: string;
|
|
16
|
+
/** 사용자 식별자(선택). */
|
|
17
|
+
sub?: string;
|
|
18
|
+
/** 검증된 issuer. */
|
|
19
|
+
iss: string;
|
|
20
|
+
/** 검증된 audience(들). */
|
|
21
|
+
aud: string[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* logout_token을 검증하고 폐기 대상 클레임(sid·sub)을 반환한다.
|
|
25
|
+
* 검증 실패는 ReoptSDKError(400, invalid_logout_token)로 던진다.
|
|
26
|
+
*/
|
|
27
|
+
declare function verifyBackchannelLogoutToken(logoutToken: string, options?: VerifyLogoutTokenOptions): Promise<LogoutTokenClaims>;
|
|
28
|
+
/** 테스트·장수명 프로세스용 — JWKS/discovery 캐시와 refetch 스로틀 상태를 비운다. */
|
|
29
|
+
declare function clearLogoutTokenCaches(): void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* OIDC Back-Channel Logout 수신 핸들러 팩토리.
|
|
33
|
+
*
|
|
34
|
+
* reopt가 IdP 세션 폐기 시 등록된 `backchannel_logout_uri`로 보내는
|
|
35
|
+
* `application/x-www-form-urlencoded` POST(`logout_token=...`)를 받아 검증하고,
|
|
36
|
+
* 검증 성공 시 `onLogout({ sid, sub })` 콜백으로 RP(자기) 세션을 종료하게 한다.
|
|
37
|
+
*
|
|
38
|
+
* 웹 표준 `Request → Response` 시그니처라 Next.js Route Handler, Hono, 순수
|
|
39
|
+
* Fetch 서버 어디에나 그대로 마운트할 수 있다(webhooks 핸들러와 동일 패턴).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Next.js: app/api/auth/backchannel-logout/route.ts
|
|
43
|
+
* import { createBackchannelLogoutHandler } from "@reopt-ai/brandapp-sdk/logout";
|
|
44
|
+
* export const POST = createBackchannelLogoutHandler({
|
|
45
|
+
* onLogout: async ({ sid }) => { await revokeSessionsByReoptSid(sid); },
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
type BackchannelLogoutHandlerConfig = {
|
|
49
|
+
/**
|
|
50
|
+
* 폐기 대상 통지 콜백. `sid`(reopt IdP 세션 ID)로 그 세션에서 파생된 RP
|
|
51
|
+
* 세션을 모두 종료한다. 발급 시 sid를 자기 세션에 저장해 두면 역참조가 쉽다.
|
|
52
|
+
* 예외를 던지면 501을 반환해 reopt가 재시도한다(멱등하게 구현할 것).
|
|
53
|
+
*/
|
|
54
|
+
onLogout: (event: LogoutTokenClaims) => Promise<void> | void;
|
|
55
|
+
/** 자기 client_id — 미지정 시 config/BRANDAPP_CLIENT_ID. */
|
|
56
|
+
clientId?: string;
|
|
57
|
+
/** id 호스트 override — 미지정 시 resolveIdBaseUrl(config). */
|
|
58
|
+
idBaseUrl?: string;
|
|
59
|
+
/** SDK config (clientId·idBaseUrl 유도용). */
|
|
60
|
+
config?: ReoptSDKConfig;
|
|
61
|
+
/** logout_token iat 허용 나이(ms). 기본 5분. */
|
|
62
|
+
maxTokenAgeMs?: number;
|
|
63
|
+
};
|
|
64
|
+
declare function createBackchannelLogoutHandler(config: BackchannelLogoutHandlerConfig): (request: Request) => Promise<Response>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* RP-Initiated Logout — reopt의 `end_session_endpoint`로 보낼 URL을 조립한다.
|
|
68
|
+
*
|
|
69
|
+
* 외부 브랜드앱이 "reopt에서도 로그아웃" 같은 동작을 제공할 때, 사용자를 이
|
|
70
|
+
* URL로 보내면 reopt가 해당 id_token의 IdP 세션(및 그 세션에서 파생된 전
|
|
71
|
+
* RP 세션·토큰)을 폐기하고, 등록된 `post_logout_redirect_uri`로 되돌린다.
|
|
72
|
+
*
|
|
73
|
+
* 순수 URL 조립이라 서버·클라이언트 어디서나 쓸 수 있다.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* import { buildEndSessionUrl } from "@reopt-ai/brandapp-sdk/logout";
|
|
77
|
+
* const url = buildEndSessionUrl({
|
|
78
|
+
* idToken: session.idToken, // 로그인 시 받은 id_token
|
|
79
|
+
* postLogoutRedirectUri: "https://app.example.com/goodbye",
|
|
80
|
+
* state: csrfToken,
|
|
81
|
+
* });
|
|
82
|
+
* redirect(url); // 사용자를 reopt end-session으로 이동
|
|
83
|
+
*/
|
|
84
|
+
type BuildEndSessionUrlOptions = {
|
|
85
|
+
/**
|
|
86
|
+
* `id_token_hint` — 로그인 시 받은 id_token. 어느 세션을 끝낼지 식별한다.
|
|
87
|
+
* 없으면 reopt가 어떤 세션인지 알 수 없어 로그아웃이 무의미하므로 필수.
|
|
88
|
+
*/
|
|
89
|
+
idToken: string;
|
|
90
|
+
/** 자기 client_id(선택 — id_token_hint의 aud와 대조에 쓰이며 미지정 가능). */
|
|
91
|
+
clientId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* 로그아웃 후 복귀 URL. reopt OAuth 클라이언트의 `post_logout_redirect_uris`에
|
|
94
|
+
* 사전 등록된 값이어야 reopt가 redirect한다(미등록 시 종료만 하고 안 돌아옴).
|
|
95
|
+
*/
|
|
96
|
+
postLogoutRedirectUri?: string;
|
|
97
|
+
/** CSRF/상태 보존용 state — 복귀 URL에 그대로 실려 돌아온다. */
|
|
98
|
+
state?: string;
|
|
99
|
+
/** id 호스트 override — 미지정 시 resolveIdBaseUrl(config). */
|
|
100
|
+
idBaseUrl?: string;
|
|
101
|
+
/** SDK config (idBaseUrl 유도용). */
|
|
102
|
+
config?: ReoptSDKConfig;
|
|
103
|
+
};
|
|
104
|
+
declare function buildEndSessionUrl(options: BuildEndSessionUrlOptions): string;
|
|
105
|
+
|
|
106
|
+
export { type BackchannelLogoutHandlerConfig, type BuildEndSessionUrlOptions, type LogoutTokenClaims, type VerifyLogoutTokenOptions, buildEndSessionUrl, clearLogoutTokenCaches, createBackchannelLogoutHandler, verifyBackchannelLogoutToken };
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { resolveIdBaseUrl, ReoptSDKError } from '../chunk-C5VTRZWX.js';
|
|
2
|
+
|
|
3
|
+
// src/logout/verify.ts
|
|
4
|
+
var BACKCHANNEL_LOGOUT_EVENT = "http://schemas.openid.net/event/backchannel-logout";
|
|
5
|
+
var JWKS_CACHE_TTL_MS = 10 * 60 * 1e3;
|
|
6
|
+
var DEFAULT_MAX_TOKEN_AGE_MS = 5 * 60 * 1e3;
|
|
7
|
+
var VERIFICATION_FETCH_TIMEOUT_MS = 5 * 1e3;
|
|
8
|
+
var JWKS_MIN_FORCED_REFETCH_INTERVAL_MS = 30 * 1e3;
|
|
9
|
+
var jwksCache = /* @__PURE__ */ new Map();
|
|
10
|
+
var jwksInflight = /* @__PURE__ */ new Map();
|
|
11
|
+
var jwksLastForcedRefetch = /* @__PURE__ */ new Map();
|
|
12
|
+
var discoveryCache = /* @__PURE__ */ new Map();
|
|
13
|
+
function base64UrlDecode(input) {
|
|
14
|
+
const pad = input.length % 4 === 0 ? "" : "=".repeat(4 - input.length % 4);
|
|
15
|
+
const base64 = (input + pad).replace(/-/g, "+").replace(/_/g, "/");
|
|
16
|
+
const binary = atob(base64);
|
|
17
|
+
const bytes = new Uint8Array(binary.length);
|
|
18
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
19
|
+
return bytes;
|
|
20
|
+
}
|
|
21
|
+
function decodeJson(segment) {
|
|
22
|
+
return JSON.parse(new TextDecoder().decode(base64UrlDecode(segment)));
|
|
23
|
+
}
|
|
24
|
+
function fail(message, cause) {
|
|
25
|
+
throw new ReoptSDKError(message, 400, "invalid_logout_token", void 0, {
|
|
26
|
+
cause,
|
|
27
|
+
fix: "reopt\uAC00 \uBCF4\uB0B8 logout_token\uB9CC \uC774 \uD578\uB4E4\uB7EC\uB85C \uC804\uB2EC\uB418\uB294\uC9C0, client_id\xB7idBaseUrl \uC124\uC815\uC774 \uB9DE\uB294\uC9C0 \uD655\uC778\uD558\uC138\uC694.",
|
|
28
|
+
doc: "logout.md"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function failUnavailable(message, cause) {
|
|
32
|
+
throw new ReoptSDKError(
|
|
33
|
+
message,
|
|
34
|
+
503,
|
|
35
|
+
"logout_verification_unavailable",
|
|
36
|
+
void 0,
|
|
37
|
+
{
|
|
38
|
+
cause,
|
|
39
|
+
fix: "reopt IdP\uC758 discovery/JWKS \uC5D4\uB4DC\uD3EC\uC778\uD2B8\uAC00 \uC77C\uC2DC\uC801\uC73C\uB85C \uC751\uB2F5\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4. \uC7A0\uC2DC \uD6C4 \uC7AC\uC2DC\uB3C4\uD558\uC138\uC694.",
|
|
40
|
+
doc: "logout.md"
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
async function fetchDiscovery(idBaseUrl) {
|
|
45
|
+
const cached = discoveryCache.get(idBaseUrl);
|
|
46
|
+
if (cached && Date.now() - cached.fetchedAt < JWKS_CACHE_TTL_MS) {
|
|
47
|
+
return { issuer: cached.issuer, jwksUri: cached.jwksUri };
|
|
48
|
+
}
|
|
49
|
+
const discoveryUrl = `${idBaseUrl}/api/auth/.well-known/openid-configuration`;
|
|
50
|
+
let res;
|
|
51
|
+
try {
|
|
52
|
+
res = await fetch(discoveryUrl, {
|
|
53
|
+
cache: "no-store",
|
|
54
|
+
signal: AbortSignal.timeout(VERIFICATION_FETCH_TIMEOUT_MS)
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
failUnavailable(
|
|
58
|
+
"OIDC discovery\uB97C \uBD88\uB7EC\uC624\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.",
|
|
59
|
+
`discovery fetch \uC2E4\uD328: ${String(error)}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (!res.ok) {
|
|
63
|
+
failUnavailable(
|
|
64
|
+
"OIDC discovery \uC751\uB2F5\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
65
|
+
`discovery HTTP ${res.status}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const doc = await res.json();
|
|
69
|
+
if (!doc.issuer || !doc.jwks_uri) {
|
|
70
|
+
failUnavailable(
|
|
71
|
+
"OIDC discovery\uC5D0 issuer/jwks_uri\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.",
|
|
72
|
+
"discovery \uD544\uB4DC \uB204\uB77D"
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
discoveryCache.set(idBaseUrl, {
|
|
76
|
+
issuer: doc.issuer,
|
|
77
|
+
jwksUri: doc.jwks_uri,
|
|
78
|
+
fetchedAt: Date.now()
|
|
79
|
+
});
|
|
80
|
+
return { issuer: doc.issuer, jwksUri: doc.jwks_uri };
|
|
81
|
+
}
|
|
82
|
+
async function fetchJwks(jwksUri, forceRefresh) {
|
|
83
|
+
const cached = jwksCache.get(jwksUri);
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
if (!forceRefresh && cached && now - cached.fetchedAt < JWKS_CACHE_TTL_MS) {
|
|
86
|
+
return cached.keys;
|
|
87
|
+
}
|
|
88
|
+
const inflight = jwksInflight.get(jwksUri);
|
|
89
|
+
if (inflight) return inflight;
|
|
90
|
+
if (forceRefresh && cached) {
|
|
91
|
+
const lastForced = jwksLastForcedRefetch.get(jwksUri) ?? 0;
|
|
92
|
+
if (now - lastForced < JWKS_MIN_FORCED_REFETCH_INTERVAL_MS) {
|
|
93
|
+
return cached.keys;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (forceRefresh) jwksLastForcedRefetch.set(jwksUri, now);
|
|
97
|
+
const promise = fetchJwksUncached(jwksUri).finally(() => {
|
|
98
|
+
jwksInflight.delete(jwksUri);
|
|
99
|
+
});
|
|
100
|
+
jwksInflight.set(jwksUri, promise);
|
|
101
|
+
return promise;
|
|
102
|
+
}
|
|
103
|
+
async function fetchJwksUncached(jwksUri) {
|
|
104
|
+
let res;
|
|
105
|
+
try {
|
|
106
|
+
res = await fetch(jwksUri, {
|
|
107
|
+
cache: "no-store",
|
|
108
|
+
signal: AbortSignal.timeout(VERIFICATION_FETCH_TIMEOUT_MS)
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
failUnavailable(
|
|
112
|
+
"JWKS\uB97C \uBD88\uB7EC\uC624\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.",
|
|
113
|
+
`jwks fetch \uC2E4\uD328: ${String(error)}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (!res.ok) {
|
|
117
|
+
failUnavailable(
|
|
118
|
+
"JWKS \uC751\uB2F5\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
119
|
+
`jwks HTTP ${res.status}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
const doc = await res.json();
|
|
123
|
+
const keys = (doc.keys ?? []).filter(
|
|
124
|
+
(k) => k.kty === "OKP" && k.crv === "Ed25519" && typeof k.x === "string"
|
|
125
|
+
);
|
|
126
|
+
jwksCache.set(jwksUri, { keys, fetchedAt: Date.now(), jwksUri });
|
|
127
|
+
return keys;
|
|
128
|
+
}
|
|
129
|
+
async function verifyEd25519(jwk, signingInput, signature) {
|
|
130
|
+
try {
|
|
131
|
+
const key = await crypto.subtle.importKey(
|
|
132
|
+
"jwk",
|
|
133
|
+
{ kty: jwk.kty, crv: jwk.crv, x: jwk.x },
|
|
134
|
+
{ name: "Ed25519" },
|
|
135
|
+
false,
|
|
136
|
+
["verify"]
|
|
137
|
+
);
|
|
138
|
+
return await crypto.subtle.verify(
|
|
139
|
+
{ name: "Ed25519" },
|
|
140
|
+
key,
|
|
141
|
+
// TS 5.7의 Uint8Array<ArrayBufferLike>는 BufferSource와 직접 호환되지
|
|
142
|
+
// 않아 캐스팅한다(런타임 값은 표준 Uint8Array).
|
|
143
|
+
signature,
|
|
144
|
+
new TextEncoder().encode(signingInput)
|
|
145
|
+
);
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function verifyBackchannelLogoutToken(logoutToken, options = {}) {
|
|
151
|
+
const config = options.config ?? {};
|
|
152
|
+
const clientId = options.clientId ?? config.clientId ?? (typeof process !== "undefined" ? process.env?.BRANDAPP_CLIENT_ID : void 0);
|
|
153
|
+
if (!clientId) {
|
|
154
|
+
fail(
|
|
155
|
+
"client_id\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.",
|
|
156
|
+
"clientId \uBBF8\uC124\uC815 \u2014 options.clientId \uB610\uB294 BRANDAPP_CLIENT_ID env \uD544\uC694"
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const idBaseUrl = (options.idBaseUrl ?? resolveIdBaseUrl(config)).replace(
|
|
160
|
+
/\/$/,
|
|
161
|
+
""
|
|
162
|
+
);
|
|
163
|
+
const parts = logoutToken.split(".");
|
|
164
|
+
if (parts.length !== 3) {
|
|
165
|
+
fail("logout_token \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.", "JWT \uC138\uADF8\uBA3C\uD2B8 \uAC1C\uC218 \uC624\uB958");
|
|
166
|
+
}
|
|
167
|
+
const [headerB64, payloadB64, sigB64] = parts;
|
|
168
|
+
let header;
|
|
169
|
+
let payload;
|
|
170
|
+
try {
|
|
171
|
+
header = decodeJson(headerB64);
|
|
172
|
+
payload = decodeJson(payloadB64);
|
|
173
|
+
} catch {
|
|
174
|
+
fail("logout_token \uB514\uCF54\uB4DC\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.", "base64url/JSON \uD30C\uC2F1 \uC624\uB958");
|
|
175
|
+
}
|
|
176
|
+
if (header.alg !== "EdDSA") {
|
|
177
|
+
fail(
|
|
178
|
+
"\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC11C\uBA85 \uC54C\uACE0\uB9AC\uC998\uC785\uB2C8\uB2E4.",
|
|
179
|
+
`alg=${header.alg ?? "none"} (EdDSA\uB9CC \uD5C8\uC6A9)`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
const { issuer, jwksUri } = await fetchDiscovery(idBaseUrl);
|
|
183
|
+
const signature = base64UrlDecode(sigB64);
|
|
184
|
+
const signingInput = `${headerB64}.${payloadB64}`;
|
|
185
|
+
const tryVerify = async (forceRefresh) => {
|
|
186
|
+
const keys = await fetchJwks(jwksUri, forceRefresh);
|
|
187
|
+
const candidates = header.kid ? keys.filter((k) => k.kid === header.kid) : keys;
|
|
188
|
+
const pool = candidates.length > 0 ? candidates : keys;
|
|
189
|
+
for (const jwk of pool) {
|
|
190
|
+
if (await verifyEd25519(jwk, signingInput, signature)) return true;
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
};
|
|
194
|
+
let verified = await tryVerify(false);
|
|
195
|
+
if (!verified) verified = await tryVerify(true);
|
|
196
|
+
if (!verified) {
|
|
197
|
+
fail("logout_token \uC11C\uBA85 \uAC80\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.", "\uC11C\uBA85 \uBD88\uC77C\uCE58 \uB610\uB294 \uD0A4 \uC5C6\uC74C");
|
|
198
|
+
}
|
|
199
|
+
if (payload.iss !== issuer) {
|
|
200
|
+
fail("issuer\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.", `iss=${payload.iss} != ${issuer}`);
|
|
201
|
+
}
|
|
202
|
+
const aud = Array.isArray(payload.aud) ? payload.aud : payload.aud ? [payload.aud] : [];
|
|
203
|
+
if (!aud.includes(clientId)) {
|
|
204
|
+
fail("audience\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.", "aud\uC5D0 client_id \uC5C6\uC74C");
|
|
205
|
+
}
|
|
206
|
+
if (typeof payload.iat !== "number") {
|
|
207
|
+
fail("iat\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.", "iat \uD074\uB808\uC784 \uB204\uB77D");
|
|
208
|
+
}
|
|
209
|
+
const maxAge = options.maxTokenAgeMs ?? DEFAULT_MAX_TOKEN_AGE_MS;
|
|
210
|
+
if (Date.now() - payload.iat * 1e3 > maxAge) {
|
|
211
|
+
fail("logout_token\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4.", "iat\uAC00 \uD5C8\uC6A9 \uB098\uC774\uB97C \uCD08\uACFC");
|
|
212
|
+
}
|
|
213
|
+
if (payload.exp && Date.now() > payload.exp * 1e3) {
|
|
214
|
+
fail("logout_token\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4(exp).", "exp \uACBD\uACFC");
|
|
215
|
+
}
|
|
216
|
+
if (payload.nonce !== void 0) {
|
|
217
|
+
fail("logout_token\uC5D0 nonce\uAC00 \uC788\uC73C\uBA74 \uC548 \uB429\uB2C8\uB2E4.", "nonce \uD074\uB808\uC784 \uC874\uC7AC");
|
|
218
|
+
}
|
|
219
|
+
const hasEvent = !!payload.events && Object.prototype.hasOwnProperty.call(
|
|
220
|
+
payload.events,
|
|
221
|
+
BACKCHANNEL_LOGOUT_EVENT
|
|
222
|
+
);
|
|
223
|
+
if (!hasEvent) {
|
|
224
|
+
fail(
|
|
225
|
+
"back-channel logout \uC774\uBCA4\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.",
|
|
226
|
+
"events\uC5D0 backchannel-logout \uBA64\uBC84 \uC5C6\uC74C"
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (!payload.sid && !payload.sub) {
|
|
230
|
+
fail("sid \uB610\uB294 sub\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4.", "sid/sub \uBAA8\uB450 \uC5C6\uC74C");
|
|
231
|
+
}
|
|
232
|
+
if (!payload.sid) {
|
|
233
|
+
fail("sid\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.", "reopt logout_token\uC740 sid \uD544\uC218");
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
sid: payload.sid,
|
|
237
|
+
sub: payload.sub,
|
|
238
|
+
iss: issuer,
|
|
239
|
+
aud
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function clearLogoutTokenCaches() {
|
|
243
|
+
jwksCache.clear();
|
|
244
|
+
jwksInflight.clear();
|
|
245
|
+
jwksLastForcedRefetch.clear();
|
|
246
|
+
discoveryCache.clear();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/logout/handler.ts
|
|
250
|
+
function response(body, status) {
|
|
251
|
+
return new Response(JSON.stringify(body), {
|
|
252
|
+
status,
|
|
253
|
+
headers: {
|
|
254
|
+
"Content-Type": "application/json",
|
|
255
|
+
"Cache-Control": "no-store"
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function createBackchannelLogoutHandler(config) {
|
|
260
|
+
return async (request) => {
|
|
261
|
+
if (request.method !== "POST") {
|
|
262
|
+
return response({ error: "Method not allowed" }, 405);
|
|
263
|
+
}
|
|
264
|
+
let logoutToken = null;
|
|
265
|
+
try {
|
|
266
|
+
const form = await request.formData();
|
|
267
|
+
const value = form.get("logout_token");
|
|
268
|
+
logoutToken = typeof value === "string" ? value : null;
|
|
269
|
+
} catch {
|
|
270
|
+
return response({ error: "invalid_request" }, 400);
|
|
271
|
+
}
|
|
272
|
+
if (!logoutToken) {
|
|
273
|
+
return response({ error: "invalid_request" }, 400);
|
|
274
|
+
}
|
|
275
|
+
let claims;
|
|
276
|
+
try {
|
|
277
|
+
claims = await verifyBackchannelLogoutToken(logoutToken, {
|
|
278
|
+
clientId: config.clientId,
|
|
279
|
+
idBaseUrl: config.idBaseUrl,
|
|
280
|
+
config: config.config,
|
|
281
|
+
maxTokenAgeMs: config.maxTokenAgeMs
|
|
282
|
+
});
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (error instanceof ReoptSDKError && error.status >= 500) {
|
|
285
|
+
return response({ error: error.code }, 503);
|
|
286
|
+
}
|
|
287
|
+
const code = error instanceof ReoptSDKError ? error.code : "invalid_logout_token";
|
|
288
|
+
return response({ error: code }, 400);
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
await config.onLogout(claims);
|
|
292
|
+
} catch {
|
|
293
|
+
return response({ error: "logout_processing_failed" }, 501);
|
|
294
|
+
}
|
|
295
|
+
return response({ ok: true }, 200);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/logout/end-session.ts
|
|
300
|
+
function buildEndSessionUrl(options) {
|
|
301
|
+
const idBaseUrl = (options.idBaseUrl ?? resolveIdBaseUrl(options.config ?? {})).replace(/\/$/, "");
|
|
302
|
+
const url = new URL(`${idBaseUrl}/api/auth/oauth2/end-session`);
|
|
303
|
+
url.searchParams.set("id_token_hint", options.idToken);
|
|
304
|
+
if (options.clientId) {
|
|
305
|
+
url.searchParams.set("client_id", options.clientId);
|
|
306
|
+
}
|
|
307
|
+
if (options.postLogoutRedirectUri) {
|
|
308
|
+
url.searchParams.set(
|
|
309
|
+
"post_logout_redirect_uri",
|
|
310
|
+
options.postLogoutRedirectUri
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
if (options.state) {
|
|
314
|
+
url.searchParams.set("state", options.state);
|
|
315
|
+
}
|
|
316
|
+
return url.toString();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export { buildEndSessionUrl, clearLogoutTokenCaches, createBackchannelLogoutHandler, verifyBackchannelLogoutToken };
|
|
320
|
+
//# sourceMappingURL=index.js.map
|
|
321
|
+
//# sourceMappingURL=index.js.map
|
package/dist/plans/index.d.ts
CHANGED
|
@@ -65,6 +65,53 @@ type Plan = {
|
|
|
65
65
|
/** 구독 전에 동의가 필요한 필수 약관. `sdk.terms`로 본문 조회·동의. */
|
|
66
66
|
requiredTerms: PlanRequiredTerms[];
|
|
67
67
|
};
|
|
68
|
+
/** Prisma `BrandappCheckoutStatus`. */
|
|
69
|
+
type CheckoutStatus = "pending" | "completed" | "canceled" | "expired" | "failed";
|
|
70
|
+
/** `plans.createCheckout` 입력. */
|
|
71
|
+
type CreateCheckoutInput = {
|
|
72
|
+
/** 구독할 플랜 ID (`plans.list()`가 반환하는 `Plan.id`). */
|
|
73
|
+
planId: string;
|
|
74
|
+
/**
|
|
75
|
+
* 결제 성공 후 고객을 돌려보낼 **절대** URL (내 앱의 복귀 페이지). 이 브랜드앱
|
|
76
|
+
* OAuth 클라이언트에 등록된 redirect URI와 동일 origin이거나 reopt 호스트여야 한다.
|
|
77
|
+
*/
|
|
78
|
+
successUrl: string;
|
|
79
|
+
/** 결제 취소 시 돌려보낼 절대 URL (successUrl과 동일 검증). */
|
|
80
|
+
cancelUrl: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* hosted-checkout 세션.
|
|
84
|
+
*
|
|
85
|
+
* `createCheckout`가 반환하면 `checkoutUrl`로 브라우저를 리다이렉트한다. 샌드박스
|
|
86
|
+
* 모드에서 이 URL은 id.reopt.ai의 가상 결제 페이지이며, 결제를 승인하면 구독이
|
|
87
|
+
* 활성화되고 `successUrl`(취소 시 `cancelUrl`)로 복귀한다. 복귀 후
|
|
88
|
+
* `getCheckout(checkoutId)` 또는 `getMyPlan(token)`으로 결과를 확인한다.
|
|
89
|
+
*/
|
|
90
|
+
type CheckoutSession = {
|
|
91
|
+
checkoutId: string;
|
|
92
|
+
/**
|
|
93
|
+
* 브라우저를 리다이렉트할 결제 URL. `createCheckout` 응답에만 존재하고
|
|
94
|
+
* `getCheckout` 응답에서는 `null`이다(capability token 재노출 방지).
|
|
95
|
+
*/
|
|
96
|
+
checkoutUrl: string | null;
|
|
97
|
+
/** 결제 제공자 — 현재 "sandbox"(가상 결제). */
|
|
98
|
+
provider: string;
|
|
99
|
+
status: CheckoutStatus | string;
|
|
100
|
+
planId: string;
|
|
101
|
+
planName: string;
|
|
102
|
+
/** 결제 금액 (통화 최소 단위 정수). */
|
|
103
|
+
amount: number;
|
|
104
|
+
currency: string;
|
|
105
|
+
interval: PlanInterval | string;
|
|
106
|
+
/** ISO-8601 만료 시각 (pending 세션 TTL). */
|
|
107
|
+
expiresAt: string;
|
|
108
|
+
/** ISO-8601 완료 시각. 미완료면 `null`. */
|
|
109
|
+
completedAt: string | null;
|
|
110
|
+
};
|
|
111
|
+
/** `plans.cancel` 결과. */
|
|
112
|
+
type CancelSubscriptionResult = {
|
|
113
|
+
status: "canceled";
|
|
114
|
+
};
|
|
68
115
|
/**
|
|
69
116
|
* 현재 로그인 고객의 구독 플랜 + 엔타이틀먼트.
|
|
70
117
|
*
|
|
@@ -90,19 +137,28 @@ type CurrentPlan = {
|
|
|
90
137
|
};
|
|
91
138
|
|
|
92
139
|
/**
|
|
93
|
-
* Brandapp Plans client
|
|
94
|
-
*
|
|
95
|
-
* Lets a Brandapp read the subscription plans it offers to its own customers,
|
|
96
|
-
* and the signed-in customer's current plan / entitlement.
|
|
140
|
+
* Brandapp Plans client — read the plan catalog, the current customer's plan,
|
|
141
|
+
* and drive a hosted checkout to subscribe & pay.
|
|
97
142
|
*
|
|
98
143
|
* - `list()` — Basic or Bearer. Active plans (catalog).
|
|
99
144
|
* - `getMyPlan(accessToken)` — Bearer. The current customer's plan, or `null`.
|
|
145
|
+
* - `createCheckout(input, accessToken)` — Bearer. Start a hosted checkout;
|
|
146
|
+
* redirect the browser to the returned `checkoutUrl`.
|
|
147
|
+
* - `getCheckout(checkoutId, accessToken)` — Bearer. Poll a checkout session.
|
|
148
|
+
* - `cancel(accessToken)` — Bearer. Cancel the current sandbox subscription.
|
|
100
149
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
150
|
+
* ### Sandbox checkout (payment disabled)
|
|
151
|
+
* When the Brandapp has real payment disabled (the default), `createCheckout`
|
|
152
|
+
* returns a **sandbox** `checkoutUrl` — a virtual-payment page on id.reopt.ai
|
|
153
|
+
* that activates the subscription without any real charge and redirects back to
|
|
154
|
+
* your `successUrl`/`cancelUrl`. This is the built-in way to build and test the
|
|
155
|
+
* full "list → subscribe → pay → entitlement" flow with no Toss/Paddle setup.
|
|
156
|
+
*
|
|
157
|
+
* ⚠️ Live Toss/Paddle checkout is **not** driven through the SDK yet (it needs
|
|
158
|
+
* the provider browser SDK + host callbacks and stays in the first-party
|
|
159
|
+
* brandfront flow) — `createCheckout` returns HTTP 409 `LIVE_MODE_UNSUPPORTED`
|
|
160
|
+
* when the Brandapp is set to live payments. usage-model meters remain
|
|
161
|
+
* read-only metadata (usage billing not implemented).
|
|
106
162
|
*
|
|
107
163
|
* @example
|
|
108
164
|
* ```ts
|
|
@@ -111,7 +167,20 @@ type CurrentPlan = {
|
|
|
111
167
|
* // Render the plan catalog (no user context required):
|
|
112
168
|
* const plans = await sdk.plans.list();
|
|
113
169
|
*
|
|
114
|
-
* // After the customer signs in via OAuth:
|
|
170
|
+
* // After the customer signs in via OAuth, subscribe & pay:
|
|
171
|
+
* try {
|
|
172
|
+
* const checkout = await sdk.plans.createCheckout(
|
|
173
|
+
* { planId: plans[0].id, successUrl, cancelUrl },
|
|
174
|
+
* accessToken,
|
|
175
|
+
* );
|
|
176
|
+
* redirect(checkout.checkoutUrl!); // → sandbox payment page, then back to successUrl
|
|
177
|
+
* } catch (e) {
|
|
178
|
+
* if (isRequiredTermsError(e)) {
|
|
179
|
+
* // collect consent for e.missingTermsIds via sdk.terms, then retry
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
*
|
|
183
|
+
* // On the return page, confirm the entitlement:
|
|
115
184
|
* const current = await sdk.plans.getMyPlan(accessToken);
|
|
116
185
|
* if (current?.subscriptionStatus === "active") {
|
|
117
186
|
* // grant entitlement…
|
|
@@ -134,7 +203,34 @@ declare class ReoptPlansClient {
|
|
|
134
203
|
* `accessToken`. Returns `null` when the customer has no active plan.
|
|
135
204
|
*/
|
|
136
205
|
getMyPlan(accessToken: string): Promise<CurrentPlan | null>;
|
|
206
|
+
/**
|
|
207
|
+
* Start a hosted checkout to subscribe the current customer (identified by
|
|
208
|
+
* `accessToken`) to `input.planId`, then redirect the browser to the returned
|
|
209
|
+
* `checkoutUrl`. In sandbox mode that URL is a virtual-payment page on
|
|
210
|
+
* id.reopt.ai which activates the subscription and returns to your
|
|
211
|
+
* `successUrl` / `cancelUrl`.
|
|
212
|
+
*
|
|
213
|
+
* @throws {RequiredTermsError} when the plan has required terms the customer
|
|
214
|
+
* has not consented to. Read `missingTermsIds`, collect consent via
|
|
215
|
+
* `sdk.terms`, then call again.
|
|
216
|
+
* @throws {ReoptSDKError} `LIVE_MODE_UNSUPPORTED` (409) when the Brandapp is
|
|
217
|
+
* configured for live Toss/Paddle payments (use the brandfront checkout).
|
|
218
|
+
*/
|
|
219
|
+
createCheckout(input: CreateCheckoutInput, accessToken: string): Promise<CheckoutSession>;
|
|
220
|
+
/**
|
|
221
|
+
* Poll a checkout session by id (e.g. on your return page) to read its
|
|
222
|
+
* `status` — `completed` means the subscription is active. `checkoutUrl` is
|
|
223
|
+
* `null` here; use the URL from {@link createCheckout} to re-redirect.
|
|
224
|
+
*/
|
|
225
|
+
getCheckout(checkoutId: string, accessToken: string): Promise<CheckoutSession>;
|
|
226
|
+
/**
|
|
227
|
+
* Cancel the current customer's active **sandbox** subscription. Access is
|
|
228
|
+
* kept until the paid period ends (the billing state becomes `canceled`).
|
|
229
|
+
* Real Toss/Paddle subscriptions are not affected — those use the provider
|
|
230
|
+
* flow.
|
|
231
|
+
*/
|
|
232
|
+
cancel(accessToken: string): Promise<CancelSubscriptionResult>;
|
|
137
233
|
}
|
|
138
234
|
declare function createReoptPlansClient(config: ReoptSDKConfig): ReoptPlansClient;
|
|
139
235
|
|
|
140
|
-
export { type CurrentPlan, type MeterPricingMode, type Plan, type PlanBillingModel, type PlanInterval, type PlanMeter, type PlanMeterTier, type PlanRequiredTerms, ReoptPlansClient, createReoptPlansClient };
|
|
236
|
+
export { type CancelSubscriptionResult, type CheckoutSession, type CheckoutStatus, type CreateCheckoutInput, type CurrentPlan, type MeterPricingMode, type Plan, type PlanBillingModel, type PlanInterval, type PlanMeter, type PlanMeterTier, type PlanRequiredTerms, ReoptPlansClient, createReoptPlansClient };
|
package/dist/plans/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { ReoptPlansClient, createReoptPlansClient } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { ReoptPlansClient, createReoptPlansClient } from '../chunk-OG7R3UAR.js';
|
|
2
|
+
import '../chunk-YTKSAWV2.js';
|
|
3
|
+
import '../chunk-2LSCQHAU.js';
|
|
4
|
+
import '../chunk-C5VTRZWX.js';
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/push/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { ReoptPushClient, createReoptPushClient } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { ReoptPushClient, createReoptPushClient } from '../chunk-QN3QD67K.js';
|
|
2
|
+
import '../chunk-YTKSAWV2.js';
|
|
3
|
+
import '../chunk-2LSCQHAU.js';
|
|
4
|
+
import '../chunk-C5VTRZWX.js';
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/react/hooks.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _tanstack_react_query from '@tanstack/react-query';
|
|
|
2
2
|
import { UseQueryOptions, UseMutationOptions, UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
3
3
|
import { ReoptSDK } from '../index.js';
|
|
4
4
|
import { StreamDoneData, CompletionOptions, AgentInfo, CompletionResult, CreditInfo, ImageGenerateResult, ImageGenerateOptions, ModelInfo } from '../ai/index.js';
|
|
5
|
-
import { g as ReoptSDKError } from '../errors-
|
|
5
|
+
import { g as ReoptSDKError } from '../errors-BjDFIyA6.js';
|
|
6
6
|
import { L as ListRecordsQuery, m as EavRecord, g as CreateRecordInput, d as BulkUpdateItem, i as DeleteWhereInput, l as EavEntity, P as PaginatedResponse, s as UpdateRecordInput, u as UpsertRecordResult, t as UpsertRecordInput } from '../config-CtxyJsDR.js';
|
|
7
7
|
import { a as ListPostsQuery, L as ListPostGroupsQuery, b as ListTagsQuery, T as Tag, c as PostDetail, d as PostGroup, C as CmsPaginatedResponse, P as Post } from '../types-ckmDDW3N.js';
|
|
8
8
|
import { a as FileListQuery, F as FileInfo, b as FileListResponse, U as UploadOptions } from '../client-CN5_tNOC.js';
|
|
@@ -45,8 +45,12 @@ declare const keys: {
|
|
|
45
45
|
entities: (brandappId?: string) => readonly ["reopt", "entities", string | undefined];
|
|
46
46
|
entity: (entityId: string) => readonly ["reopt", "entity", string];
|
|
47
47
|
records: (entityId: string, query?: ListRecordsQuery) => readonly ["reopt", "records", string, ListRecordsQuery | undefined];
|
|
48
|
+
recordsInfinite: (entityId: string, query?: ListRecordsQuery) => readonly ["reopt", "recordsInfinite", string, ListRecordsQuery | undefined];
|
|
48
49
|
record: (entityId: string, recordId: string) => readonly ["reopt", "record", string, string];
|
|
49
50
|
recordCount: (entityId: string, query?: Pick<ListRecordsQuery, "filters" | "authUserId">) => readonly ["reopt", "recordCount", string, Pick<ListRecordsQuery, "filters" | "authUserId"> | undefined];
|
|
51
|
+
recordsPrefix: (entityId: string) => readonly ["reopt", "records", string];
|
|
52
|
+
recordsInfinitePrefix: (entityId: string) => readonly ["reopt", "recordsInfinite", string];
|
|
53
|
+
recordCountPrefix: (entityId: string) => readonly ["reopt", "recordCount", string];
|
|
50
54
|
aiCredits: (brandappId?: string) => readonly ["reopt", "ai", "credits", string | undefined];
|
|
51
55
|
aiModels: (brandappId?: string) => readonly ["reopt", "ai", "models", string | undefined];
|
|
52
56
|
aiAgents: (brandappId?: string) => readonly ["reopt", "ai", "agents", string | undefined];
|