@reopt-ai/brandapp-sdk 4.7.0-rc.2 → 4.7.0-rc.3
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 +36 -0
- package/README.md +180 -59
- package/dist/ai/index.d.ts +1 -1
- package/dist/ai/index.js +1 -1
- package/dist/ai-provider/index.js +1 -1
- package/dist/analytics/index.d.ts +1 -1
- package/dist/analytics/index.js +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/better-auth/client.d.ts +7 -2
- package/dist/better-auth/client.js +5 -4
- package/dist/better-auth/index.d.ts +31 -5
- package/dist/better-auth/index.js +30 -9
- package/dist/{client-BVBl3gPQ.js → client-2CaNRYKb.js} +4 -4
- package/dist/{client-Cod87ThY.d.ts → client-BL-Ljwki.d.ts} +2 -2
- package/dist/{client-BQJepjoD.d.ts → client-BO7-GuXP.d.ts} +2 -2
- package/dist/{client-CsWSxMhB.d.ts → client-BbmslwWV.d.ts} +2 -2
- package/dist/{client--ELBxfna.js → client-BeNi8CJ8.js} +3 -3
- package/dist/{client-Cnq_X3Wp.d.ts → client-Bi-KSU_r.d.ts} +2 -2
- package/dist/{client-CGulAXhy.js → client-BwFaLqeU.js} +2 -2
- package/dist/{client-iyzEsEEg.js → client-C09GqOsD.js} +2 -2
- package/dist/{client-C6lx3RUQ.d.ts → client-CJFsLk3_.d.ts} +2 -2
- package/dist/{client-C2W4RAZV.d.ts → client-CJRjPSf7.d.ts} +2 -2
- package/dist/{client-C7X3w8t6.js → client-COD-OtO6.js} +2 -2
- package/dist/{client-DE1ynLgS.js → client-Cezzpa3v.js} +2 -2
- package/dist/{client-BeiMpmXQ.js → client-CnVCMyEO.js} +2 -2
- package/dist/{client-RPOH-LNC.js → client-D6WGQQw8.js} +3 -3
- package/dist/{client-MDNS9Ubf.d.ts → client-DF-tOyrY.d.ts} +2 -2
- package/dist/{client-DNZsyjA0.js → client-DHrZcdxq.js} +3 -3
- package/dist/client-DWUvj6iA.js +736 -0
- package/dist/client-DlgVNj3w.d.ts +72 -0
- package/dist/{client-CSl3o0s3.d.ts → client-Dwf6UuGH.d.ts} +2 -2
- package/dist/{client-D6333rpA.js → client-Dzux9iCO.js} +4 -4
- package/dist/{client-DfnaH99z.d.ts → client-NUhpPkl2.d.ts} +2 -2
- package/dist/client-seu-0lbh.d.ts +654 -0
- package/dist/{client-xblzWFAL.d.ts → client-wNzcgEJu.d.ts} +2 -2
- package/dist/{client-DFxq2GcS.js → client-xycvTLR7.js} +2 -2
- package/dist/cms/index.d.ts +1 -1
- package/dist/cms/index.js +1 -1
- package/dist/{config-CnFnzh7Q.d.ts → config-BGT9h1OW.d.ts} +7 -5
- package/dist/{config-B6U6kZxR.js → config-CCPAE9xX.js} +3 -3
- package/dist/eav/index.d.ts +2 -2
- package/dist/eav/index.js +2 -2
- package/dist/eav/migrate.d.ts +2 -2
- package/dist/eav/schema.d.ts +2 -2
- package/dist/feedback/index.d.ts +1 -1
- package/dist/feedback/index.js +1 -1
- package/dist/files/index.d.ts +1 -1
- package/dist/files/index.js +1 -1
- package/dist/{http-client-pEcJtik8.js → http-client-BTrQ0KrQ.js} +2 -2
- package/dist/{index-Bkci7euU.d.ts → index-CiZ5VkDS.d.ts} +22 -14
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/installation/index.d.ts +411 -0
- package/dist/installation/index.js +836 -0
- package/dist/logout/index.d.ts +1 -1
- package/dist/logout/index.js +1 -1
- package/dist/machine/index.d.ts +2 -71
- package/dist/machine/index.js +1 -1
- package/dist/plans/index.d.ts +1 -1
- package/dist/plans/index.js +1 -1
- package/dist/push/index.d.ts +1 -1
- package/dist/push/index.js +1 -1
- package/dist/{query-MrzuQOFF.js → query-BTPb66iO.js} +2 -2
- package/dist/react/hooks.d.ts +4 -4
- package/dist/resource/index.d.ts +176 -0
- package/dist/resource/index.js +345 -0
- package/dist/superadmin/index.d.ts +80 -0
- package/dist/superadmin/index.js +148 -0
- package/dist/terms/index.d.ts +1 -1
- package/dist/terms/index.js +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/types-DGAVaUCc.js +17 -0
- package/dist/{types-MXLudLBP.d.ts → types-FazBnzhg.d.ts} +8 -2
- package/dist/workspace/index.d.ts +2 -654
- package/dist/workspace/index.js +2 -735
- package/docs/environment.md +30 -15
- package/docs/installation.md +128 -0
- package/docs/resource.md +75 -0
- package/docs/superadmin.md +55 -0
- package/package.json +13 -1
- package/dist/types-DjDRszNj.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,42 @@ This project adheres to [Semantic Versioning](https://semver.org/).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.7.0-rc.3] — 2026-10-11
|
|
11
|
+
|
|
12
|
+
Pre-release (`npm i @reopt-ai/brandapp-sdk@next`) — RFC-0034 2·3단계: 리소스 서버 검증기와 운영자 가드.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **`@reopt-ai/brandapp-sdk/resource`** (RFC-0034 §4.3) — 서브 제품 API가 리옵트 id의 기계 토큰(`at+jwt` + DPoP)을 받는
|
|
17
|
+
검증기 **한 벌**. `createResourceVerifier({ issuer, audience, jwks?, dpop: { required, replayStore }, allowUserTokens?, publicUrl? })`
|
|
18
|
+
→ `verify(request, { scope })`는 `MachinePrincipal`을 주거나 `ResourceAuthError`(`code` 12종, `status` 401|403,
|
|
19
|
+
`wwwAuthenticate()`)를 던진다. `verify.safe()`·`verify.looksLikeAccessToken()`. 저수준 `verifyMachineToken(input)`(결과 유니언),
|
|
20
|
+
`createRedisDpopReplayStore(redis, { keyPrefix, onFallback })`(`SET NX PX`, fail-closed)·`createMemoryDpopReplayStore()`,
|
|
21
|
+
`resolvePublicRequestUrl()`(proxy 뒤 `x-forwarded-*` → DPoP `htu`). 리옵트 본체의 플랫폼·브랜드앱 미들웨어도 같은 구현을 쓴다.
|
|
22
|
+
- **`@reopt-ai/brandapp-sdk/superadmin`** (RFC-0034 §5.2) — 운영자 가드. 리옵트가 id token·userinfo·access token에
|
|
23
|
+
`reopt_operator`·`reopt_mfa`·`auth_time`을 싣고, `evaluateOperator(claims, { maxAuthAgeSeconds })`/`requireOperator()`가
|
|
24
|
+
① claim ② 운영자 ③ 2단계 인증 **수행** ④ 로그인 나이 순으로 판정한다(`OperatorAccessError`: `no_claims`·`not_operator`·
|
|
25
|
+
`mfa_not_performed`·`reauth_required`, 403). `decodeIdTokenClaims()`(백채널 id token 전용, 서명 미검증), `latestReoptAccount()`,
|
|
26
|
+
`stepUpAuthorizationParams()`, `OPERATOR_ACCESS_MESSAGES`. 서브 제품은 자기 allowlist를 지운다.
|
|
27
|
+
- **`@reopt-ai/brandapp-sdk/installation`** (RFC-0034 §6–§8) — 설치(리옵트 연결). `installationManifestSchema`·`manifestHash`·
|
|
28
|
+
`signManifest`/`verifyManifestJws`(본문의 `jwksUri`에서 키를 받아 검증, `ManifestVerifyError`), `deriveInstallationManifest`
|
|
29
|
+
(RFC-0030 선언 파일 → 매니페스트, 웹훅 `secret` 필수), `signInstallationAssertion`(`reopt-installation-assertion+jwt`),
|
|
30
|
+
`createInstallationClient`(`request`·`get`·`reinstall`·`revoke`·`refreshJwks`·`health` — 승인 전엔 단언, 활성 뒤엔 설치의
|
|
31
|
+
machine 토큰), `createInstallationBackchannelHandler`(`reopt-installation-event+jwt`, id JWKS·iss·aud·재생 검사),
|
|
32
|
+
`createReoptConnection`(§7.6 headless 상태 `unconnected|pending|connected|suspended|rejected|revoked` + `describe()` 문구),
|
|
33
|
+
`selfCheckJwks`, `planKeyRotation`/`confirmKeyRecognized`(회전 ②, 최대 5분 재시도). 서버 전용, `zod` 필요.
|
|
34
|
+
- `createMachineClient`: `scopes: []`면 토큰 요청에 `scope`를 **보내지 않는다** — id가 클라이언트 행에 등록된 scope 전부를 발급한다
|
|
35
|
+
(설치 클라이언트의 최소 권한). 예전엔 빈 문자열을 보냈다.
|
|
36
|
+
- `createReoptOAuth({ stepUp: true | seconds })` — step-up 재로그인 제공자 `reopt-step-up`(`prompt=login&max_age`)을 함께 등록한다.
|
|
37
|
+
`signInWithReopt(client, { stepUp: true })`가 그 제공자로 authorize를 다시 탄다. `REOPT_PROVIDER_IDS`를
|
|
38
|
+
`account.accountLinking.trustedProviders`에 넣고, 콜백 `/api/auth/callback/reopt-step-up`을 리옵트 클라이언트에 등록한다.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- 문서·예제를 서버 자격 기준으로 바꿨다 — README Quick Start·`createReoptSDK` JSDoc·`createReoptAdapter` JSDoc·설정 표·env 표가
|
|
43
|
+
`createMachineClient({ keyRing })` + `authorization: machine.headers`를 먼저 보여 주고, `clientSecret`은 로그인 클라이언트의
|
|
44
|
+
code 교환(과도기 Basic)으로만 남긴다. `validateConfig`의 자격 누락 메시지도 `authorization`을 첫 선택지로 안내한다(동작 변화 없음).
|
|
45
|
+
|
|
10
46
|
## [4.7.0-rc.2] — 2026-10-10
|
|
11
47
|
|
|
12
48
|
### Changed
|
package/README.md
CHANGED
|
@@ -18,22 +18,133 @@ npm install @reopt-ai/brandapp-sdk
|
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Two kinds of credential (RFC-0034): a **login client** (`purpose: web`) whose
|
|
22
|
+
secret is only used to exchange the login code, and **server credentials**
|
|
23
|
+
(`purpose: machine` for data/AI/files/platform calls, `purpose: adapter` for
|
|
24
|
+
the remote Better Auth adapter) that authenticate with a private key —
|
|
25
|
+
`private_key_jwt` assertions plus DPoP-bound tokens — so Reopt never holds a
|
|
26
|
+
shared secret for server-to-server calls. Login clients are issued in the
|
|
27
|
+
platform console; server credentials are registered by Reopt for now.
|
|
28
|
+
|
|
29
|
+
### Server credentials (4.7+, recommended for every server call)
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npx --package @reopt-ai/brandapp-sdk reopt-keygen # prints REOPT_CLIENT_PRIVATE_KEY_JWK='{…}'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// app/.well-known/reopt-client-jwks.json/route.ts — publish the public key
|
|
37
|
+
import {
|
|
38
|
+
buildClientJwks,
|
|
39
|
+
readClientKeyRing,
|
|
40
|
+
} from "@reopt-ai/brandapp-sdk/machine";
|
|
41
|
+
|
|
42
|
+
export const GET = () => {
|
|
43
|
+
const ring = readClientKeyRing();
|
|
44
|
+
return ring
|
|
45
|
+
? Response.json(buildClientJwks(ring.published))
|
|
46
|
+
: new Response(null, { status: 404 });
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
// lib/reopt.ts — the unified SDK with a machine credential
|
|
52
|
+
import { createReoptSDK } from "@reopt-ai/brandapp-sdk";
|
|
53
|
+
import {
|
|
54
|
+
createMachineClient,
|
|
55
|
+
readClientKeyRing,
|
|
56
|
+
} from "@reopt-ai/brandapp-sdk/machine";
|
|
57
|
+
|
|
58
|
+
const machine = createMachineClient({
|
|
59
|
+
clientId: process.env.BRANDAPP_MACHINE_CLIENT_ID!,
|
|
60
|
+
keyRing: readClientKeyRing()!, // REOPT_CLIENT_PRIVATE_KEY_JWK
|
|
61
|
+
resource: "https://brandapp.reopt.ai", // the token's audience — exactly one
|
|
62
|
+
scopes: ["brandapp:read", "brandapp:write"], // brandapp:write implies eav:*
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const sdk = createReoptSDK({
|
|
66
|
+
brandappId: process.env.BRANDAPP_ID!,
|
|
67
|
+
clientId: machine.clientId,
|
|
68
|
+
authorization: machine.headers, // Authorization: DPoP … + a DPoP proof per request
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const entities = await sdk.eav.entities.list();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Register `${origin}/.well-known/reopt-client-jwks.json` as the client's
|
|
75
|
+
`jwksUri`. Rotation, errors and the platform client are in
|
|
76
|
+
[`docs/machine.md`](./docs/machine.md).
|
|
77
|
+
|
|
78
|
+
### Connect to Reopt (installation, 4.7+)
|
|
79
|
+
|
|
80
|
+
A product declares its resources once (`reopt.workspace.ts`), signs the derived
|
|
81
|
+
manifest with the same private key, and asks Reopt to install it. An operator
|
|
82
|
+
approves in the console; the clients, API resources and webhooks are created
|
|
83
|
+
and their `client_id`s come back over the back-channel (or `refresh()`).
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import {
|
|
87
|
+
createInstallationClient,
|
|
88
|
+
createReoptConnection,
|
|
89
|
+
deriveInstallationManifest,
|
|
90
|
+
} from "@reopt-ai/brandapp-sdk/installation";
|
|
91
|
+
|
|
92
|
+
const manifest = deriveInstallationManifest({
|
|
93
|
+
declaration: workspace, // RFC-0030 declaration file
|
|
94
|
+
slug: "my-product",
|
|
95
|
+
name: "My Product",
|
|
96
|
+
workspaceId: process.env.REOPT_WORKSPACE_ID!,
|
|
97
|
+
jwksUri: "https://my-product.example/.well-known/reopt-client-jwks.json",
|
|
98
|
+
clients: [{ purpose: "machine", scopes: ["works:read", "works:write"] }],
|
|
99
|
+
});
|
|
100
|
+
const connection = createReoptConnection({
|
|
101
|
+
client: createInstallationClient({ keyRing: readClientKeyRing()! }),
|
|
102
|
+
manifest,
|
|
103
|
+
store, // one row in your DB holding the installation record
|
|
104
|
+
});
|
|
105
|
+
await connection.requestConnection(); // pending until an operator approves
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
States, the back-channel receiver and key rotation: [`docs/installation.md`](./docs/installation.md).
|
|
109
|
+
|
|
110
|
+
### Better Auth
|
|
111
|
+
|
|
112
|
+
Login goes through the login client; the remote adapter (users and sessions
|
|
113
|
+
stored in Reopt) authenticates as the `adapter` credential with the same key
|
|
114
|
+
ring.
|
|
22
115
|
|
|
23
116
|
```typescript
|
|
24
117
|
// auth.ts
|
|
25
118
|
import { betterAuth } from "better-auth";
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
119
|
+
import {
|
|
120
|
+
createReoptAdapter,
|
|
121
|
+
createReoptOAuth,
|
|
122
|
+
} from "@reopt-ai/brandapp-sdk/better-auth";
|
|
123
|
+
import {
|
|
124
|
+
createMachineClient,
|
|
125
|
+
readClientKeyRing,
|
|
126
|
+
} from "@reopt-ai/brandapp-sdk/machine";
|
|
127
|
+
|
|
128
|
+
const adapter = createMachineClient({
|
|
129
|
+
clientId: process.env.BRANDAPP_ADAPTER_CLIENT_ID!,
|
|
130
|
+
keyRing: readClientKeyRing()!,
|
|
131
|
+
resource: "https://brandapp.reopt.ai",
|
|
132
|
+
scopes: ["brandapp:auth-adapter"],
|
|
32
133
|
});
|
|
33
134
|
|
|
34
135
|
export const auth = betterAuth({
|
|
35
|
-
database:
|
|
36
|
-
|
|
136
|
+
database: createReoptAdapter({
|
|
137
|
+
brandappId: process.env.BRANDAPP_ID!,
|
|
138
|
+
clientId: adapter.clientId,
|
|
139
|
+
authorization: adapter.headers,
|
|
140
|
+
}),
|
|
141
|
+
plugins: [
|
|
142
|
+
createReoptOAuth({
|
|
143
|
+
clientId: process.env.BRANDAPP_CLIENT_ID!, // login client
|
|
144
|
+
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!, // code exchange only
|
|
145
|
+
brandappId: process.env.BRANDAPP_ID!,
|
|
146
|
+
}),
|
|
147
|
+
],
|
|
37
148
|
});
|
|
38
149
|
```
|
|
39
150
|
|
|
@@ -54,19 +165,11 @@ signInWithReopt(authClient, { callbackURL: "/dashboard" });
|
|
|
54
165
|
> registered; if you registered a custom redirect URI, add the new path in the
|
|
55
166
|
> studio before upgrading.
|
|
56
167
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const sdk = createReoptSDK({
|
|
63
|
-
clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
64
|
-
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
65
|
-
brandappId: process.env.BRANDAPP_ID!,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const entities = await sdk.eav.entities.list();
|
|
69
|
-
```
|
|
168
|
+
> **Shared secret (transitional).** `createReoptSDK({ clientId, clientSecret })`
|
|
169
|
+
> and `createReoptBetterAuth({ clientId, clientSecret })` still work for login
|
|
170
|
+
> clients that keep transitional machine scopes, but those scopes close once an
|
|
171
|
+
> app has moved to a key — new integrations should start with server
|
|
172
|
+
> credentials.
|
|
70
173
|
|
|
71
174
|
### External marketing site (1.8+)
|
|
72
175
|
|
|
@@ -175,9 +278,9 @@ const contacts = defineEntity({
|
|
|
175
278
|
const schema = defineSchema({ entities: { contacts } });
|
|
176
279
|
|
|
177
280
|
const sdk = createReoptSDK({
|
|
178
|
-
clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
179
|
-
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
180
281
|
brandappId: process.env.BRANDAPP_ID!,
|
|
282
|
+
clientId: machine.clientId, // see "Server credentials"
|
|
283
|
+
authorization: machine.headers,
|
|
181
284
|
schema,
|
|
182
285
|
});
|
|
183
286
|
|
|
@@ -200,9 +303,9 @@ import { createLazySDK } from "@reopt-ai/brandapp-sdk";
|
|
|
200
303
|
import schema from "./eav.schema";
|
|
201
304
|
|
|
202
305
|
export const sdk = createLazySDK(() => ({
|
|
203
|
-
clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
204
|
-
clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
205
306
|
brandappId: process.env.BRANDAPP_ID!,
|
|
307
|
+
clientId: machine.clientId,
|
|
308
|
+
authorization: machine.headers,
|
|
206
309
|
schema,
|
|
207
310
|
}));
|
|
208
311
|
|
|
@@ -216,7 +319,7 @@ Or use the explicit init/get pattern:
|
|
|
216
319
|
import { initReoptSDK, getReoptSDK } from "@reopt-ai/brandapp-sdk";
|
|
217
320
|
|
|
218
321
|
// At app startup
|
|
219
|
-
initReoptSDK({
|
|
322
|
+
initReoptSDK({ brandappId, clientId, authorization: machine.headers, schema });
|
|
220
323
|
|
|
221
324
|
// Anywhere else
|
|
222
325
|
const sdk = getReoptSDK();
|
|
@@ -281,28 +384,31 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
281
384
|
|
|
282
385
|
## Exports
|
|
283
386
|
|
|
284
|
-
| Path | Main Exports
|
|
285
|
-
| ---------------------------- |
|
|
286
|
-
| `"."` | `createReoptSDK`, `createLazySDK`, `initReoptSDK`, `getReoptSDK`, errors
|
|
287
|
-
| `"./better-auth"` | `createReoptBetterAuth`, `createReoptAdapter`, `createReoptOAuth`
|
|
288
|
-
| `"./better-auth/client"` | `signInWithReopt
|
|
289
|
-
| `"./eav"` | `createReoptEavClient`, `collectAll`, EAV types, `TypedEavRecord`, `EntityClient`
|
|
290
|
-
| `"./eav/schema"` | `defineEntity`, `defineSchema`, `syncSchema`, `computeDiff`, schema/sync types
|
|
291
|
-
| `"./eav/coerce"` | `asString`, `asNumber`, `asBoolean`, `asDate`, `asJson`, `asStringArray`
|
|
292
|
-
| `"./eav/migrate"` | `defineMigration`, `runMigrations`, migration types
|
|
293
|
-
| `"./ai"` / `"./ai-provider"` | `ReoptAiClient` / `createBrandappProvider` (Vercel AI SDK)
|
|
294
|
-
| `"./auth"` | `getSessionFromCookies`, `verifySession`, `sdk.auth` client
|
|
295
|
-
| `"./cms"` | `sdk.cms` types + `toMetadata` / `toSitemapItems` / `toRssFeed` / `EditorSpec`
|
|
296
|
-
| `"./files"` | file client types + `optimizeUrl`, `createImageLoader`
|
|
297
|
-
| `"./terms"` | Terms list / consent / withdraw types
|
|
298
|
-
| `"./plans"` | `createReoptPlansClient`, `Plan` / `CheckoutSession` / `CurrentPlan` types
|
|
299
|
-
| `"./push"` | Customer device token register / unregister / list types
|
|
300
|
-
| `"./feedback"` | Customer feedback submission types
|
|
301
|
-
| `"./logout"` | `createBackchannelLogoutHandler`, `verifyBackchannelLogoutToken`, `buildEndSessionUrl`
|
|
302
|
-
| `"./webhooks"` | `createWebhookHandler`, `verifySignature`
|
|
303
|
-
| `"./react/hooks"` | TanStack Query hooks (`useAiCredits`, `useEavRecords`, …)
|
|
304
|
-
| `"./workspace"` | `createPlatformClient` — workspace-scoped platform API (**server-only**)
|
|
305
|
-
| `"./
|
|
387
|
+
| Path | Main Exports | Requires `better-auth` |
|
|
388
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------ |
|
|
389
|
+
| `"."` | `createReoptSDK`, `createLazySDK`, `initReoptSDK`, `getReoptSDK`, errors | No |
|
|
390
|
+
| `"./better-auth"` | `createReoptBetterAuth`, `createReoptAdapter`, `createReoptOAuth` | Yes |
|
|
391
|
+
| `"./better-auth/client"` | `signInWithReopt` (`{ stepUp }`), `linkReoptAccount`, `REOPT_PROVIDER_ID(S)` | Yes |
|
|
392
|
+
| `"./eav"` | `createReoptEavClient`, `collectAll`, EAV types, `TypedEavRecord`, `EntityClient` | No |
|
|
393
|
+
| `"./eav/schema"` | `defineEntity`, `defineSchema`, `syncSchema`, `computeDiff`, schema/sync types | No |
|
|
394
|
+
| `"./eav/coerce"` | `asString`, `asNumber`, `asBoolean`, `asDate`, `asJson`, `asStringArray` | No |
|
|
395
|
+
| `"./eav/migrate"` | `defineMigration`, `runMigrations`, migration types | No |
|
|
396
|
+
| `"./ai"` / `"./ai-provider"` | `ReoptAiClient` / `createBrandappProvider` (Vercel AI SDK) | No |
|
|
397
|
+
| `"./auth"` | `getSessionFromCookies`, `verifySession`, `sdk.auth` client | No |
|
|
398
|
+
| `"./cms"` | `sdk.cms` types + `toMetadata` / `toSitemapItems` / `toRssFeed` / `EditorSpec` | No |
|
|
399
|
+
| `"./files"` | file client types + `optimizeUrl`, `createImageLoader` | No |
|
|
400
|
+
| `"./terms"` | Terms list / consent / withdraw types | No |
|
|
401
|
+
| `"./plans"` | `createReoptPlansClient`, `Plan` / `CheckoutSession` / `CurrentPlan` types | No |
|
|
402
|
+
| `"./push"` | Customer device token register / unregister / list types | No |
|
|
403
|
+
| `"./feedback"` | Customer feedback submission types | No |
|
|
404
|
+
| `"./logout"` | `createBackchannelLogoutHandler`, `verifyBackchannelLogoutToken`, `buildEndSessionUrl` | No |
|
|
405
|
+
| `"./webhooks"` | `createWebhookHandler`, `verifySignature` | No |
|
|
406
|
+
| `"./react/hooks"` | TanStack Query hooks (`useAiCredits`, `useEavRecords`, …) | No |
|
|
407
|
+
| `"./workspace"` | `createPlatformClient` — workspace-scoped platform API (**server-only**) | No |
|
|
408
|
+
| `"./machine"` | `createMachineClient`, `readClientKeyRing`, `buildClientJwks` — machine credentials (**server-only**) | No (`@better-auth/core`) |
|
|
409
|
+
| `"./resource"` | `createResourceVerifier`, `createRedisDpopReplayStore` — verify reopt machine tokens on your API (**server-only**) | No (`@better-auth/core`) |
|
|
410
|
+
| `"./superadmin"` | `requireOperator`, `evaluateOperator`, `decodeIdTokenClaims` — operator guard from reopt id-token claims | No |
|
|
411
|
+
| `"./dev"` / `"./testing"` | `createDevServer` / `createTestSDK` (local dev + fixtures) | No |
|
|
306
412
|
|
|
307
413
|
> Full signatures for every sub-path: [`docs/api-reference.md`](./docs/api-reference.md).
|
|
308
414
|
|
|
@@ -318,9 +424,15 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
318
424
|
|
|
319
425
|
```typescript
|
|
320
426
|
{
|
|
321
|
-
clientId: string; // OAuth Client ID (required)
|
|
322
|
-
clientSecret: string; // OAuth Client Secret (required)
|
|
323
427
|
brandappId: string; // Brandapp ID (required)
|
|
428
|
+
clientId: string; // OAuth Client ID (required unless `token`)
|
|
429
|
+
authorization?: (req: { method: string; url: string }) =>
|
|
430
|
+
Promise<Record<string, string>>;
|
|
431
|
+
// Per-request auth headers — pass a machine
|
|
432
|
+
// client's `headers` (private_key_jwt + DPoP).
|
|
433
|
+
// No clientSecret needed.
|
|
434
|
+
clientSecret?: string; // Shared secret (Basic) — transitional; only for
|
|
435
|
+
// login clients that still hold machine scopes
|
|
324
436
|
token?: string; // Short-lived Bearer token (Phase D-2b) —
|
|
325
437
|
// overrides Basic Auth when set
|
|
326
438
|
isProduction?: boolean; // true → brandapp.reopt.ai, false → brand.local.reopt.io
|
|
@@ -355,16 +467,25 @@ const meta = asJson<Meta>(record.values.meta); // Meta | undefined
|
|
|
355
467
|
|
|
356
468
|
## Environment Variables
|
|
357
469
|
|
|
358
|
-
SDK는 `process.env`를 자동으로 읽습니다.
|
|
470
|
+
SDK는 `process.env`를 자동으로 읽습니다. 자격 변수만 설정하면 나머지는
|
|
359
471
|
`NODE_ENV` 기반으로 알아서 분기합니다.
|
|
360
472
|
|
|
361
|
-
|
|
473
|
+
**자격 — 서버 자격(권장)**
|
|
474
|
+
|
|
475
|
+
| 변수 | 용도 |
|
|
476
|
+
| ----------------------------------- | -------------------------------------------------------------------------------------- |
|
|
477
|
+
| `REOPT_CLIENT_PRIVATE_KEY_JWK` | 개인키(JWK) — `reopt-keygen` 출력, 서버 전용. `readClientKeyRing()`이 읽는다 |
|
|
478
|
+
| `REOPT_CLIENT_PRIVATE_KEY_JWK_NEXT` | 회전 중 다음 키 — JWKS에 둘 다 실리고 서명은 NEXT로 옮겨 간다 |
|
|
479
|
+
| `BRANDAPP_MACHINE_CLIENT_ID` | 용도 machine 클라이언트 ID(데이터·AI·파일·플랫폼 API) — 이름은 관례, SDK가 읽지 않는다 |
|
|
480
|
+
| `BRANDAPP_ADAPTER_CLIENT_ID` | 용도 adapter 클라이언트 ID(원격 Better Auth 어댑터) — 위와 같음 |
|
|
481
|
+
| `BRANDAPP_ID` | BrandApp 고유 ID |
|
|
482
|
+
|
|
483
|
+
**자격 — 로그인 클라이언트**
|
|
362
484
|
|
|
363
|
-
| 변수 | 용도
|
|
364
|
-
| ------------------------ |
|
|
365
|
-
| `BRANDAPP_CLIENT_ID` |
|
|
366
|
-
| `BRANDAPP_CLIENT_SECRET` |
|
|
367
|
-
| `BRANDAPP_ID` | BrandApp 고유 ID |
|
|
485
|
+
| 변수 | 용도 |
|
|
486
|
+
| ------------------------ | ------------------------------------------------------------------- |
|
|
487
|
+
| `BRANDAPP_CLIENT_ID` | 로그인(용도 web) Client ID — 플랫폼 콘솔 → 브랜드앱 → 설정에서 발급 |
|
|
488
|
+
| `BRANDAPP_CLIENT_SECRET` | 로그인 Client Secret (1회 노출) — code 교환에만 |
|
|
368
489
|
|
|
369
490
|
**선택 (없으면 `NODE_ENV`로 자동 분기)**
|
|
370
491
|
|
|
@@ -380,7 +501,7 @@ SDK는 `process.env`를 자동으로 읽습니다. 필수 변수 3개만 설정
|
|
|
380
501
|
패턴은 **[docs/environment.md](./docs/environment.md)**.
|
|
381
502
|
|
|
382
503
|
> **네이밍 원칙** — `BRANDAPP_*`는 consumer 자격/식별자, `REOPT_*`는 reopt 플랫폼
|
|
383
|
-
> 호스트
|
|
504
|
+
> 호스트 정보와 서명 키, `BRANDAPP_SDK_*`는 SDK 자체 동작 제어.
|
|
384
505
|
|
|
385
506
|
## Error Handling
|
|
386
507
|
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as CompletionOptions, c as FinishReason, d as MessageRole, f as ModelInfo, i as ChatMessage, l as ImageGenerateOptions, m as StreamEvent, n as createReoptAiClient, o as CompletionResult, p as StreamDoneData, r as AgentInfo, s as CreditInfo, t as ReoptAiClient, u as ImageGenerateResult } from "../client-
|
|
1
|
+
import { a as CompletionOptions, c as FinishReason, d as MessageRole, f as ModelInfo, i as ChatMessage, l as ImageGenerateOptions, m as StreamEvent, n as createReoptAiClient, o as CompletionResult, p as StreamDoneData, r as AgentInfo, s as CreditInfo, t as ReoptAiClient, u as ImageGenerateResult } from "../client-Bi-KSU_r.js";
|
|
2
2
|
export { type AgentInfo, type ChatMessage, type CompletionOptions, type CompletionResult, type CreditInfo, type FinishReason, type ImageGenerateOptions, type ImageGenerateResult, type MessageRole, type ModelInfo, ReoptAiClient, type StreamDoneData, type StreamEvent, createReoptAiClient };
|
package/dist/ai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as resolveBaseUrl, j as mapHttpStatusToError, n as SDK_VERSION, o as validateConfig, r as assertBrowserSafe } from "../config-
|
|
1
|
+
import { i as resolveBaseUrl, j as mapHttpStatusToError, n as SDK_VERSION, o as validateConfig, r as assertBrowserSafe } from "../config-CCPAE9xX.js";
|
|
2
2
|
import { t as createManagedAbort } from "../abort--nOBFN4M.js";
|
|
3
3
|
import { t as createAuthHeader } from "../encoding-Bwfm3iaE.js";
|
|
4
4
|
import { t as createSSELineProcessor } from "../sse-parser-FMjxM7sY.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createReoptAnalyticsClient, r as AnalyticsConfig, t as ReoptAnalyticsClient } from "../client-
|
|
1
|
+
import { n as createReoptAnalyticsClient, r as AnalyticsConfig, t as ReoptAnalyticsClient } from "../client-CJFsLk3_.js";
|
|
2
2
|
import { identify, pageView, setConsent, track } from "@reopt-ai/data-sdk";
|
|
3
3
|
//#region src/analytics/browser.d.ts
|
|
4
4
|
type BrandappAnalytics = {
|
package/dist/analytics/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createReoptAnalyticsClient, t as ReoptAnalyticsClient } from "../client-
|
|
1
|
+
import { n as createReoptAnalyticsClient, t as ReoptAnalyticsClient } from "../client-xycvTLR7.js";
|
|
2
2
|
import { getInstance, identify, init, pageView, setConsent, track } from "@reopt-ai/data-sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/analytics/browser.ts
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as UserInfoClaims, n as createReoptAuthClient, r as LinkCurrentUserResult, t as ReoptAuthClient } from "../client-
|
|
1
|
+
import { i as UserInfoClaims, n as createReoptAuthClient, r as LinkCurrentUserResult, t as ReoptAuthClient } from "../client-BL-Ljwki.js";
|
|
2
2
|
//#region src/auth/session.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* 세션 쿠키 검증 — apps/id의 Better Auth `/api/auth/get-session`을 호출해
|
package/dist/auth/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as REOPT_PROVIDER_ID } from "../types-
|
|
1
|
+
import { a as REOPT_PROVIDER_IDS, i as REOPT_PROVIDER_ID, o as REOPT_STEP_UP_PROVIDER_ID } from "../types-FazBnzhg.js";
|
|
2
2
|
//#region src/better-auth/client.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Minimal shape of a Better Auth client that can start a social sign-in /
|
|
@@ -37,6 +37,11 @@ type ReoptSignInOptions = {
|
|
|
37
37
|
disableRedirect?: boolean;
|
|
38
38
|
/** Opaque client data round-tripped through the flow (read back server-side, treat as untrusted). */
|
|
39
39
|
additionalData?: Record<string, unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* RFC-0034 §5.2 step-up — `reopt-step-up` 제공자로 authorize를 다시 탄다(`prompt=login&max_age`).
|
|
42
|
+
* 서버가 `createReoptOAuth({ stepUp })`로 그 제공자를 등록해 두어야 한다.
|
|
43
|
+
*/
|
|
44
|
+
stepUp?: boolean;
|
|
40
45
|
};
|
|
41
46
|
/**
|
|
42
47
|
* Start Reopt sign-in through a Better Auth client.
|
|
@@ -70,5 +75,5 @@ declare function signInWithReopt(authClient: ReoptSocialAuthClient, options?: Re
|
|
|
70
75
|
*/
|
|
71
76
|
declare function linkReoptAccount(authClient: ReoptSocialAuthClient, options?: Pick<ReoptSignInOptions, "callbackURL" | "errorCallbackURL" | "disableRedirect">): Promise<unknown>;
|
|
72
77
|
//#endregion
|
|
73
|
-
export { REOPT_PROVIDER_ID, ReoptSignInOptions, ReoptSocialAuthClient, linkReoptAccount, signInWithReopt };
|
|
78
|
+
export { REOPT_PROVIDER_ID, REOPT_PROVIDER_IDS, REOPT_STEP_UP_PROVIDER_ID, ReoptSignInOptions, ReoptSocialAuthClient, linkReoptAccount, signInWithReopt };
|
|
74
79
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as REOPT_PROVIDER_ID } from "../types-
|
|
1
|
+
import { i as REOPT_STEP_UP_PROVIDER_ID, n as REOPT_PROVIDER_ID, r as REOPT_PROVIDER_IDS } from "../types-DGAVaUCc.js";
|
|
2
2
|
|
|
3
3
|
//#region src/better-auth/client.ts
|
|
4
4
|
/**
|
|
@@ -27,9 +27,10 @@ import { n as REOPT_PROVIDER_ID } from "../types-DjDRszNj.js";
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
function signInWithReopt(authClient, options = {}) {
|
|
30
|
+
const { stepUp, ...rest } = options;
|
|
30
31
|
return authClient.signIn.social({
|
|
31
|
-
provider:
|
|
32
|
-
...
|
|
32
|
+
provider: stepUp ? REOPT_STEP_UP_PROVIDER_ID : REOPT_PROVIDER_ID,
|
|
33
|
+
...rest
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
@@ -45,5 +46,5 @@ function linkReoptAccount(authClient, options = {}) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
//#endregion
|
|
48
|
-
export { REOPT_PROVIDER_ID, linkReoptAccount, signInWithReopt };
|
|
49
|
+
export { REOPT_PROVIDER_ID, REOPT_PROVIDER_IDS, REOPT_STEP_UP_PROVIDER_ID, linkReoptAccount, signInWithReopt };
|
|
49
50
|
//# sourceMappingURL=client.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as ReoptSDKConfig, t as REOPT_BASE_URLS } from "../config-
|
|
2
|
-
import { i as REOPT_PROVIDER_ID, n as AdapterRequestBody, r as REOPT_DEFAULT_SCOPES, t as AdapterOperation } from "../types-
|
|
1
|
+
import { n as ReoptSDKConfig, t as REOPT_BASE_URLS } from "../config-BGT9h1OW.js";
|
|
2
|
+
import { a as REOPT_PROVIDER_IDS, i as REOPT_PROVIDER_ID, n as AdapterRequestBody, o as REOPT_STEP_UP_PROVIDER_ID, r as REOPT_DEFAULT_SCOPES, s as STEP_UP_MAX_AUTH_AGE_SECONDS, t as AdapterOperation } from "../types-FazBnzhg.js";
|
|
3
3
|
import { i as ClientPrivateJwk } from "../keys-B2pA8EkU.js";
|
|
4
4
|
import { T as isReoptSDKError, _ as RateLimitError, t as AuthError, v as ReoptSDKError, x as ServerError } from "../errors-U3TsyWVq.js";
|
|
5
5
|
import { AdapterFactory } from "better-auth/adapters";
|
|
@@ -11,11 +11,22 @@ import { BetterAuthOptions, BetterAuthPlugin } from "better-auth";
|
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
13
|
* import { createReoptAdapter } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
14
|
+
* import { createMachineClient, readClientKeyRing } from "@reopt-ai/brandapp-sdk/machine";
|
|
15
|
+
*
|
|
16
|
+
* // RFC-0034: the adapter authenticates as the dedicated `adapter` credential
|
|
17
|
+
* // (private_key_jwt + DPoP, scope brandapp:auth-adapter) — not the login secret.
|
|
18
|
+
* const adapter = createMachineClient({
|
|
19
|
+
* clientId: process.env.BRANDAPP_ADAPTER_CLIENT_ID!,
|
|
20
|
+
* keyRing: readClientKeyRing()!,
|
|
21
|
+
* resource: "https://brandapp.reopt.ai",
|
|
22
|
+
* scopes: ["brandapp:auth-adapter"],
|
|
23
|
+
* });
|
|
14
24
|
*
|
|
15
25
|
* export const auth = betterAuth({
|
|
16
26
|
* database: createReoptAdapter({
|
|
17
|
-
*
|
|
18
|
-
*
|
|
27
|
+
* brandappId: process.env.BRANDAPP_ID!,
|
|
28
|
+
* clientId: adapter.clientId,
|
|
29
|
+
* authorization: adapter.headers,
|
|
19
30
|
* }),
|
|
20
31
|
* });
|
|
21
32
|
* ```
|
|
@@ -64,6 +75,18 @@ type ReoptOAuthOptions = ReoptSDKConfig & {
|
|
|
64
75
|
/** Where Reopt sends the browser after ending its session (must be registered). */
|
|
65
76
|
postLogoutRedirectURI?: string;
|
|
66
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* RFC-0034 §5.2 — **step-up 재로그인** 제공자(`reopt-step-up`)를 함께 등록한다. 그 제공자는 같은 클라이언트로
|
|
80
|
+
* `prompt=login&max_age=<초>`를 보내 리옵트가 2FA·패스키를 다시 요구하게 하고, 돌아온 id token의
|
|
81
|
+
* `reopt_mfa`·`auth_time`이 새 값이 된다. `signInWithReopt(client, { stepUp: true })`가 이 제공자를 쓴다.
|
|
82
|
+
*
|
|
83
|
+
* ⚠️ 콜백 `/api/auth/callback/reopt-step-up`이 리옵트 클라이언트의 redirectUri에 등록돼 있어야 하고,
|
|
84
|
+
* better-auth `account.accountLinking.trustedProviders`에 `REOPT_PROVIDER_IDS` 둘 다 넣어야 두 번째 로그인이
|
|
85
|
+
* 같은 사용자에 붙는다(운영자 가드는 `latestReoptAccount`로 최신 id token을 고른다).
|
|
86
|
+
*
|
|
87
|
+
* `true`면 300초(승인·해제·키 조작 상한), 숫자면 그 초.
|
|
88
|
+
*/
|
|
89
|
+
stepUp?: boolean | number;
|
|
67
90
|
};
|
|
68
91
|
/**
|
|
69
92
|
* Reopt OAuth Login Plugin
|
|
@@ -100,6 +123,9 @@ type ReoptBetterAuthBundle = {
|
|
|
100
123
|
* ```ts
|
|
101
124
|
* import { createReoptBetterAuth } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
102
125
|
*
|
|
126
|
+
* // One config for both: a login client that still holds transitional machine
|
|
127
|
+
* // scopes. Apps on a machine key wire createReoptAdapter({ authorization }) and
|
|
128
|
+
* // createReoptOAuth() separately (see README "Better Auth").
|
|
103
129
|
* const reopt = createReoptBetterAuth({
|
|
104
130
|
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
105
131
|
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
@@ -119,5 +145,5 @@ type ReoptBetterAuthBundle = {
|
|
|
119
145
|
*/
|
|
120
146
|
declare function createReoptBetterAuth(options: ReoptBetterAuthOptions): ReoptBetterAuthBundle;
|
|
121
147
|
//#endregion
|
|
122
|
-
export { type AdapterOperation, type AdapterRequestBody, AuthError, REOPT_BASE_URLS, REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID, RateLimitError, type ReoptBetterAuthOptions, type ReoptOAuthOptions, type ReoptSDKConfig, ReoptSDKError, ServerError, createReoptAdapter, createReoptBetterAuth, createReoptOAuth, isReoptSDKError };
|
|
148
|
+
export { type AdapterOperation, type AdapterRequestBody, AuthError, REOPT_BASE_URLS, REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID, REOPT_PROVIDER_IDS, REOPT_STEP_UP_PROVIDER_ID, RateLimitError, type ReoptBetterAuthOptions, type ReoptOAuthOptions, type ReoptSDKConfig, ReoptSDKError, STEP_UP_MAX_AUTH_AGE_SECONDS, ServerError, createReoptAdapter, createReoptBetterAuth, createReoptOAuth, isReoptSDKError };
|
|
123
149
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { O as isReoptSDKError, S as ReoptSDKError, a as resolveIdBaseUrl, s as AuthError, t as REOPT_BASE_URLS, w as ServerError, x as RateLimitError } from "../config-
|
|
2
|
-
import { t as BaseHttpClient } from "../http-client-
|
|
1
|
+
import { O as isReoptSDKError, S as ReoptSDKError, a as resolveIdBaseUrl, s as AuthError, t as REOPT_BASE_URLS, w as ServerError, x as RateLimitError } from "../config-CCPAE9xX.js";
|
|
2
|
+
import { t as BaseHttpClient } from "../http-client-BTrQ0KrQ.js";
|
|
3
3
|
import { o as readClientKeyRing } from "../keys-B_R_lsyF.js";
|
|
4
|
-
import { n as REOPT_PROVIDER_ID, t as REOPT_DEFAULT_SCOPES } from "../types-
|
|
4
|
+
import { a as STEP_UP_MAX_AUTH_AGE_SECONDS, i as REOPT_STEP_UP_PROVIDER_ID, n as REOPT_PROVIDER_ID, r as REOPT_PROVIDER_IDS, t as REOPT_DEFAULT_SCOPES } from "../types-DGAVaUCc.js";
|
|
5
5
|
import { createAdapterFactory } from "better-auth/adapters";
|
|
6
6
|
import { createPrivateKeyJwtClientAssertionGetter } from "@better-auth/core/oauth2";
|
|
7
7
|
import { genericOAuth } from "better-auth/plugins";
|
|
@@ -18,7 +18,7 @@ import { genericOAuth } from "better-auth/plugins";
|
|
|
18
18
|
*/
|
|
19
19
|
const READ_ONLY = { idempotent: true };
|
|
20
20
|
/**
|
|
21
|
-
* Runtime guard — adapter holds clientSecret and must never run in the browser.
|
|
21
|
+
* Runtime guard — adapter holds a credential (private key headers or clientSecret) and must never run in the browser.
|
|
22
22
|
* Fails fast if bundled into client code by accident.
|
|
23
23
|
*/
|
|
24
24
|
function assertServerRuntime() {
|
|
@@ -30,11 +30,22 @@ function assertServerRuntime() {
|
|
|
30
30
|
* @example
|
|
31
31
|
* ```ts
|
|
32
32
|
* import { createReoptAdapter } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
33
|
+
* import { createMachineClient, readClientKeyRing } from "@reopt-ai/brandapp-sdk/machine";
|
|
34
|
+
*
|
|
35
|
+
* // RFC-0034: the adapter authenticates as the dedicated `adapter` credential
|
|
36
|
+
* // (private_key_jwt + DPoP, scope brandapp:auth-adapter) — not the login secret.
|
|
37
|
+
* const adapter = createMachineClient({
|
|
38
|
+
* clientId: process.env.BRANDAPP_ADAPTER_CLIENT_ID!,
|
|
39
|
+
* keyRing: readClientKeyRing()!,
|
|
40
|
+
* resource: "https://brandapp.reopt.ai",
|
|
41
|
+
* scopes: ["brandapp:auth-adapter"],
|
|
42
|
+
* });
|
|
33
43
|
*
|
|
34
44
|
* export const auth = betterAuth({
|
|
35
45
|
* database: createReoptAdapter({
|
|
36
|
-
*
|
|
37
|
-
*
|
|
46
|
+
* brandappId: process.env.BRANDAPP_ID!,
|
|
47
|
+
* clientId: adapter.clientId,
|
|
48
|
+
* authorization: adapter.headers,
|
|
38
49
|
* }),
|
|
39
50
|
* });
|
|
40
51
|
* ```
|
|
@@ -167,7 +178,8 @@ function createReoptOAuth(options) {
|
|
|
167
178
|
if (method === "private_key_jwt" && !privateKey) throw new Error("[@reopt-ai/brandapp-sdk] createReoptOAuth() with private_key_jwt requires privateKeyJwk or REOPT_CLIENT_PRIVATE_KEY_JWK.");
|
|
168
179
|
if (method !== "private_key_jwt" && !options.clientSecret) throw new Error("[@reopt-ai/brandapp-sdk] createReoptOAuth() requires clientSecret for secret-based token endpoint auth (or use tokenEndpointAuthMethod: \"private_key_jwt\").");
|
|
169
180
|
const idBaseUrl = resolveIdBaseUrl(options);
|
|
170
|
-
|
|
181
|
+
const stepUpMaxAge = options.stepUp === true ? 300 : typeof options.stepUp === "number" ? Math.max(0, Math.floor(options.stepUp)) : null;
|
|
182
|
+
const providerConfig = {
|
|
171
183
|
providerId: REOPT_PROVIDER_ID,
|
|
172
184
|
discoveryUrl: `${idBaseUrl}/api/auth/.well-known/openid-configuration`,
|
|
173
185
|
authorizationUrl: `${idBaseUrl}/api/auth/oauth2/authorize`,
|
|
@@ -188,7 +200,13 @@ function createReoptOAuth(options) {
|
|
|
188
200
|
...typeof options.providerLogout === "object" && options.providerLogout.postLogoutRedirectURI ? { postLogoutRedirectURI: options.providerLogout.postLogoutRedirectURI } : {},
|
|
189
201
|
scopes: Array.from(/* @__PURE__ */ new Set([...REOPT_DEFAULT_SCOPES, ...options.additionalScopes ?? []])),
|
|
190
202
|
pkce: true
|
|
191
|
-
}
|
|
203
|
+
};
|
|
204
|
+
return genericOAuth({ config: [providerConfig, ...stepUpMaxAge === null ? [] : [{
|
|
205
|
+
...providerConfig,
|
|
206
|
+
providerId: REOPT_STEP_UP_PROVIDER_ID,
|
|
207
|
+
prompt: "login",
|
|
208
|
+
authorizationUrlParams: { max_age: String(stepUpMaxAge) }
|
|
209
|
+
}]] });
|
|
192
210
|
}
|
|
193
211
|
|
|
194
212
|
//#endregion
|
|
@@ -200,6 +218,9 @@ function createReoptOAuth(options) {
|
|
|
200
218
|
* ```ts
|
|
201
219
|
* import { createReoptBetterAuth } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
202
220
|
*
|
|
221
|
+
* // One config for both: a login client that still holds transitional machine
|
|
222
|
+
* // scopes. Apps on a machine key wire createReoptAdapter({ authorization }) and
|
|
223
|
+
* // createReoptOAuth() separately (see README "Better Auth").
|
|
203
224
|
* const reopt = createReoptBetterAuth({
|
|
204
225
|
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
205
226
|
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
@@ -225,5 +246,5 @@ function createReoptBetterAuth(options) {
|
|
|
225
246
|
}
|
|
226
247
|
|
|
227
248
|
//#endregion
|
|
228
|
-
export { AuthError, REOPT_BASE_URLS, REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID, RateLimitError, ReoptSDKError, ServerError, createReoptAdapter, createReoptBetterAuth, createReoptOAuth, isReoptSDKError };
|
|
249
|
+
export { AuthError, REOPT_BASE_URLS, REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID, REOPT_PROVIDER_IDS, REOPT_STEP_UP_PROVIDER_ID, RateLimitError, ReoptSDKError, STEP_UP_MAX_AUTH_AGE_SECONDS, ServerError, createReoptAdapter, createReoptBetterAuth, createReoptOAuth, isReoptSDKError };
|
|
229
250
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { u as BadRequestError } from "./config-
|
|
2
|
-
import { t as BaseHttpClient } from "./http-client-
|
|
3
|
-
import { t as buildQuery } from "./query-
|
|
1
|
+
import { u as BadRequestError } from "./config-CCPAE9xX.js";
|
|
2
|
+
import { t as BaseHttpClient } from "./http-client-BTrQ0KrQ.js";
|
|
3
|
+
import { t as buildQuery } from "./query-BTPb66iO.js";
|
|
4
4
|
|
|
5
5
|
//#region src/eav/cache.ts
|
|
6
6
|
var SchemaCache = class {
|
|
@@ -564,4 +564,4 @@ function createReoptEavClient(config) {
|
|
|
564
564
|
|
|
565
565
|
//#endregion
|
|
566
566
|
export { RECORDS_PAGE_LIMIT_MAX as i, ATTRIBUTE_FILTER_LIST_MAX as n, ATTRIBUTE_FILTER_OPERATORS as r, createReoptEavClient as t };
|
|
567
|
-
//# sourceMappingURL=client-
|
|
567
|
+
//# sourceMappingURL=client-2CaNRYKb.js.map
|