@reopt-ai/brandapp-sdk 3.3.0 → 3.4.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 +67 -0
- package/README.md +10 -1
- package/dist/abort--nOBFN4M.js +50 -0
- package/dist/ai/index.d.ts +2 -314
- package/dist/ai/index.js +3 -8
- package/dist/ai-provider/index.d.ts +79 -163
- package/dist/ai-provider/index.js +752 -685
- package/dist/auth/index.d.ts +27 -27
- package/dist/auth/index.js +41 -34
- package/dist/better-auth/client.d.ts +6 -5
- package/dist/better-auth/client.js +28 -5
- package/dist/better-auth/index.d.ts +19 -17
- package/dist/better-auth/index.js +180 -144
- package/dist/client-B1q5P8rv.js +83 -0
- package/dist/client-B9QHVhdM.js +77 -0
- package/dist/client-BGGd_cpV.d.ts +103 -0
- package/dist/client-BJcy1V1a.js +140 -0
- package/dist/client-Beivhucf.js +55 -0
- package/dist/client-BruP5_nU.d.ts +147 -0
- package/dist/client-D-yNxNfk.js +28 -0
- package/dist/client-D0eBxh8j.d.ts +284 -0
- package/dist/client-D3RHHUUW.d.ts +207 -0
- package/dist/client-D6gs61w8.d.ts +53 -0
- package/dist/client-DBnK7ooQ.js +86 -0
- package/dist/client-DDw5yz_h.d.ts +53 -0
- package/dist/client-DPmoKuR9.js +305 -0
- package/dist/client-DsdakibF.js +503 -0
- package/dist/client-Dxg8_DIH.d.ts +71 -0
- package/dist/client-EbhUIhHq.js +53 -0
- package/dist/client-lk6wBu_0.d.ts +48 -0
- package/dist/client-p49ol9pg.d.ts +124 -0
- package/dist/cms/index.d.ts +52 -108
- package/dist/cms/index.js +103 -86
- package/dist/config-CRytOPPl.d.ts +394 -0
- package/dist/config-Cw0a3-C8.js +487 -0
- package/dist/dev/index.d.ts +2 -528
- package/dist/dev/index.js +2731 -2967
- package/dist/eav/coerce.d.ts +3 -1
- package/dist/eav/coerce.js +72 -46
- package/dist/eav/index.d.ts +72 -100
- package/dist/eav/index.js +158 -126
- package/dist/eav/migrate.d.ts +112 -109
- package/dist/eav/migrate.js +230 -196
- package/dist/eav/schema.d.ts +111 -150
- package/dist/eav/schema.js +624 -603
- package/dist/encoding-Bwfm3iaE.js +21 -0
- package/dist/{errors-BjDFIyA6.d.ts → errors-CRCcErNC.d.ts} +55 -53
- package/dist/feedback/index.d.ts +2 -132
- package/dist/feedback/index.js +3 -6
- package/dist/files/index.d.ts +14 -14
- package/dist/files/index.js +41 -25
- package/dist/http-client-QKUvvirs.js +386 -0
- package/dist/index-DrVaKfhs.d.ts +456 -0
- package/dist/index-Z6OGcurJ.d.ts +169 -0
- package/dist/index.d.ts +6 -230
- package/dist/index.js +119 -71
- package/dist/logout/index.d.ts +56 -53
- package/dist/logout/index.js +232 -289
- package/dist/plans/index.d.ts +2 -236
- package/dist/plans/index.js +3 -6
- package/dist/push/index.d.ts +2 -79
- package/dist/push/index.js +3 -6
- package/dist/query-BvbCiGWb.js +35 -0
- package/dist/react/hooks.d.ts +97 -99
- package/dist/react/hooks.js +742 -404
- package/dist/sse-parser-FMjxM7sY.js +86 -0
- package/dist/terms/index.d.ts +3 -79
- package/dist/terms/index.js +3 -6
- package/dist/testing/index.d.ts +52 -104
- package/dist/testing/index.js +94 -72
- package/dist/types-B-SMkH6s.d.ts +26 -0
- package/dist/types-BXDcoJHG.d.ts +131 -0
- package/dist/types-BrghN2rJ.d.ts +105 -0
- package/dist/types-DjDRszNj.js +11 -0
- package/dist/webhooks/index.d.ts +77 -50
- package/dist/webhooks/index.js +150 -127
- package/docs/api-reference.md +87 -6
- package/package.json +6 -5
- package/dist/chunk-2LSCQHAU.js +0 -21
- package/dist/chunk-4U4ZPPL4.js +0 -599
- package/dist/chunk-55KHY5GH.js +0 -96
- package/dist/chunk-C5VTRZWX.js +0 -458
- package/dist/chunk-F7BXBTZI.js +0 -54
- package/dist/chunk-FJUCWXX3.js +0 -350
- package/dist/chunk-H33OTQEN.js +0 -112
- package/dist/chunk-L4DHB36G.js +0 -75
- package/dist/chunk-OG7R3UAR.js +0 -105
- package/dist/chunk-PF24XU54.js +0 -32
- package/dist/chunk-QN3QD67K.js +0 -49
- package/dist/chunk-REIKXSMY.js +0 -7
- package/dist/chunk-UGBBXCZE.js +0 -157
- package/dist/chunk-UVT2E6KD.js +0 -81
- package/dist/chunk-YPLT3RFL.js +0 -63
- package/dist/chunk-YTKSAWV2.js +0 -463
- package/dist/client-BkcO-0C2.d.ts +0 -216
- package/dist/client-CN5_tNOC.d.ts +0 -147
- package/dist/client-DttyeM_h.d.ts +0 -102
- package/dist/config-CtxyJsDR.d.ts +0 -397
- package/dist/typed-client-BxOVIiMU.d.ts +0 -40
- package/dist/types-6E3ZLL9X.d.ts +0 -24
- package/dist/types-DskYLVb8.d.ts +0 -104
- package/dist/types-ckmDDW3N.d.ts +0 -129
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { i as UserInfoClaims, n as createReoptAuthClient, r as LinkCurrentUserResult, t as ReoptAuthClient } from "../client-Dxg8_DIH.js";
|
|
2
|
+
//#region src/auth/session.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* 세션 쿠키 검증 — apps/id의 Better Auth `/api/auth/get-session`을 호출해
|
|
6
5
|
* 외부 마케팅 사이트가 `.reopt.ai` 서브도메인 쿠키 세션을 인식할 수 있게 한다.
|
|
@@ -38,30 +37,30 @@ import '../config-CtxyJsDR.js';
|
|
|
38
37
|
* ```
|
|
39
38
|
*/
|
|
40
39
|
type Session = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
user: {
|
|
41
|
+
id: string;
|
|
42
|
+
email: string;
|
|
43
|
+
name: string;
|
|
44
|
+
image: string | null;
|
|
45
|
+
emailVerified?: boolean;
|
|
46
|
+
};
|
|
47
|
+
session: {
|
|
48
|
+
id: string;
|
|
49
|
+
expiresAt: string;
|
|
50
|
+
/** Optional — Better Auth가 환경에 따라 포함하거나 빼는 필드들. */
|
|
51
|
+
userId?: string;
|
|
52
|
+
token?: string;
|
|
53
|
+
ipAddress?: string | null;
|
|
54
|
+
userAgent?: string | null;
|
|
55
|
+
};
|
|
57
56
|
};
|
|
58
57
|
type GetSessionOptions = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
/** Better Auth handler가 마운트된 URL. e.g. "https://id.reopt.ai". */
|
|
59
|
+
idServerUrl: string;
|
|
60
|
+
/** 기본 `/api/auth/get-session`. 다른 path에 mount된 경우 override. */
|
|
61
|
+
path?: string;
|
|
62
|
+
/** Optional fetch override (테스트/SSR proxy 용). 기본 `globalThis.fetch`. */
|
|
63
|
+
fetch?: typeof fetch;
|
|
65
64
|
};
|
|
66
65
|
/**
|
|
67
66
|
* `Cookie` 헤더에 있는 reopt 세션을 id 서버에 위임 검증. 인증되지 않았거나
|
|
@@ -72,5 +71,6 @@ declare function getSessionFromCookies(cookieHeader: string | null | undefined,
|
|
|
72
71
|
* 편의 wrapper — `Request` 객체에서 `cookie` 헤더를 꺼내 검증.
|
|
73
72
|
*/
|
|
74
73
|
declare function verifySession(request: Request, opts: GetSessionOptions): Promise<Session | null>;
|
|
75
|
-
|
|
76
|
-
export { type GetSessionOptions, type Session, getSessionFromCookies, verifySession };
|
|
74
|
+
//#endregion
|
|
75
|
+
export { type GetSessionOptions, type LinkCurrentUserResult, ReoptAuthClient, type Session, type UserInfoClaims, createReoptAuthClient, getSessionFromCookies, verifySession };
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.js
CHANGED
|
@@ -1,41 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
import '../chunk-YTKSAWV2.js';
|
|
3
|
-
import '../chunk-2LSCQHAU.js';
|
|
4
|
-
import '../chunk-C5VTRZWX.js';
|
|
1
|
+
import { n as createReoptAuthClient, t as ReoptAuthClient } from "../client-EbhUIhHq.js";
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
//#region src/auth/session.ts
|
|
4
|
+
/**
|
|
5
|
+
* `Cookie` 헤더에 있는 reopt 세션을 id 서버에 위임 검증. 인증되지 않았거나
|
|
6
|
+
* id 서버가 응답하지 않으면 `null`. Edge runtime / Node 둘 다에서 동작.
|
|
7
|
+
*/
|
|
7
8
|
async function getSessionFromCookies(cookieHeader, opts) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
if (!cookieHeader) return null;
|
|
10
|
+
const path = opts.path ?? "/api/auth/get-session";
|
|
11
|
+
const url = new URL(path, opts.idServerUrl).toString();
|
|
12
|
+
const fetchImpl = opts.fetch ?? globalThis.fetch;
|
|
13
|
+
let res;
|
|
14
|
+
try {
|
|
15
|
+
res = await fetchImpl(url, {
|
|
16
|
+
method: "GET",
|
|
17
|
+
headers: {
|
|
18
|
+
cookie: cookieHeader,
|
|
19
|
+
accept: "application/json"
|
|
20
|
+
},
|
|
21
|
+
cache: "no-store",
|
|
22
|
+
credentials: "include"
|
|
23
|
+
});
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!res.ok) return null;
|
|
28
|
+
let body;
|
|
29
|
+
try {
|
|
30
|
+
body = await res.json();
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (!body || typeof body !== "object") return null;
|
|
35
|
+
const session = body;
|
|
36
|
+
if (!session.user || typeof session.user.id !== "string") return null;
|
|
37
|
+
return session;
|
|
34
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 편의 wrapper — `Request` 객체에서 `cookie` 헤더를 꺼내 검증.
|
|
41
|
+
*/
|
|
35
42
|
async function verifySession(request, opts) {
|
|
36
|
-
|
|
43
|
+
return getSessionFromCookies(request.headers.get("cookie"), opts);
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
//#endregion
|
|
47
|
+
export { ReoptAuthClient, createReoptAuthClient, getSessionFromCookies, verifySession };
|
|
41
48
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { i as REOPT_PROVIDER_ID } from "../types-B-SMkH6s.js";
|
|
2
|
+
import { genericOAuthClient } from "better-auth/client/plugins";
|
|
3
|
+
//#region src/better-auth/client.d.ts
|
|
4
4
|
type GenericOAuthClientPlugin = ReturnType<typeof genericOAuthClient>;
|
|
5
5
|
/**
|
|
6
6
|
* Reopt OAuth Client Plugin
|
|
@@ -25,5 +25,6 @@ type GenericOAuthClientPlugin = ReturnType<typeof genericOAuthClient>;
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
declare function createReoptOAuthClient(): GenericOAuthClientPlugin;
|
|
28
|
-
|
|
29
|
-
export { createReoptOAuthClient };
|
|
28
|
+
//#endregion
|
|
29
|
+
export { REOPT_PROVIDER_ID, createReoptOAuthClient };
|
|
30
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
import { genericOAuthClient } from
|
|
1
|
+
import { n as REOPT_PROVIDER_ID } from "../types-DjDRszNj.js";
|
|
2
|
+
import { genericOAuthClient } from "better-auth/client/plugins";
|
|
3
3
|
|
|
4
|
+
//#region src/better-auth/client.ts
|
|
5
|
+
/**
|
|
6
|
+
* Reopt OAuth Client Plugin
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createReoptOAuthClient, REOPT_PROVIDER_ID } from "@reopt-ai/brandapp-sdk/better-auth/client";
|
|
11
|
+
*
|
|
12
|
+
* const authClient = createAuthClient({
|
|
13
|
+
* plugins: [createReoptOAuthClient()],
|
|
14
|
+
* // ⚡ 탭 포커스마다 /api/auth/get-session을 재요청하는 better-auth 기본
|
|
15
|
+
* // 동작(refetchOnWindowFocus: true)을 끈다. 세션은 cross-subdomain 쿠키로
|
|
16
|
+
* // 공유되고 로그인/로그아웃은 명시적 전환·브로드캐스트로 동기화되므로
|
|
17
|
+
* // focus 단위 재검증은 불필요한 요청 폭주만 만든다.
|
|
18
|
+
* sessionOptions: { refetchOnWindowFocus: false },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* authClient.signIn.oauth2({
|
|
22
|
+
* providerId: REOPT_PROVIDER_ID,
|
|
23
|
+
* callbackURL: "/dashboard",
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
4
27
|
function createReoptOAuthClient() {
|
|
5
|
-
|
|
28
|
+
return genericOAuthClient();
|
|
6
29
|
}
|
|
7
30
|
|
|
8
|
-
|
|
9
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
export { REOPT_PROVIDER_ID, createReoptOAuthClient };
|
|
10
33
|
//# sourceMappingURL=client.js.map
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { n as ReoptSDKConfig, t as REOPT_BASE_URLS } from "../config-CRytOPPl.js";
|
|
2
|
+
import { i as REOPT_PROVIDER_ID, n as AdapterRequestBody, r as REOPT_DEFAULT_SCOPES, t as AdapterOperation } from "../types-B-SMkH6s.js";
|
|
3
|
+
import { _ as ReoptSDKError, b as ServerError, g as RateLimitError, t as AuthError, w as isReoptSDKError } from "../errors-CRCcErNC.js";
|
|
4
|
+
import { AdapterFactory } from "better-auth/adapters";
|
|
5
|
+
import { BetterAuthOptions, BetterAuthPlugin } from "better-auth";
|
|
6
|
+
//#region src/better-auth/adapter.d.ts
|
|
8
7
|
/**
|
|
9
8
|
* Reopt Better Auth Remote Database Adapter
|
|
10
9
|
*
|
|
@@ -21,10 +20,11 @@ export { A as AuthError, R as RateLimitError, g as ReoptSDKError, S as ServerErr
|
|
|
21
20
|
* ```
|
|
22
21
|
*/
|
|
23
22
|
declare function createReoptAdapter(config: ReoptSDKConfig): AdapterFactory<BetterAuthOptions>;
|
|
24
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/better-auth/oauth.d.ts
|
|
25
25
|
type ReoptOAuthOptions = ReoptSDKConfig & {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/** Additional OAuth scopes */
|
|
27
|
+
additionalScopes?: string[];
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Reopt OAuth Login Plugin
|
|
@@ -44,14 +44,15 @@ type ReoptOAuthOptions = ReoptSDKConfig & {
|
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
46
|
declare function createReoptOAuth(options: ReoptOAuthOptions): BetterAuthPlugin;
|
|
47
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/better-auth/helper.d.ts
|
|
48
49
|
type ReoptBetterAuthOptions = ReoptSDKConfig & {
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
/** Additional OAuth scopes */
|
|
51
|
+
additionalScopes?: string[];
|
|
51
52
|
};
|
|
52
53
|
type ReoptBetterAuthBundle = {
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
database: AdapterFactory<BetterAuthOptions>;
|
|
55
|
+
oauth: BetterAuthPlugin;
|
|
55
56
|
};
|
|
56
57
|
/**
|
|
57
58
|
* Config 한 번으로 adapter + OAuth plugin을 함께 생성
|
|
@@ -78,5 +79,6 @@ type ReoptBetterAuthBundle = {
|
|
|
78
79
|
* ```
|
|
79
80
|
*/
|
|
80
81
|
declare function createReoptBetterAuth(options: ReoptBetterAuthOptions): ReoptBetterAuthBundle;
|
|
81
|
-
|
|
82
|
-
export { type ReoptBetterAuthOptions, type ReoptOAuthOptions, ReoptSDKConfig, createReoptAdapter, createReoptBetterAuth, createReoptOAuth };
|
|
82
|
+
//#endregion
|
|
83
|
+
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 };
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,156 +1,192 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
export { AuthError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, ServerError, isReoptSDKError } from '../chunk-C5VTRZWX.js';
|
|
7
|
-
import { createAdapterFactory } from 'better-auth/adapters';
|
|
8
|
-
import { genericOAuth } from 'better-auth/plugins';
|
|
1
|
+
import { C as ServerError, D as isReoptSDKError, a as resolveIdBaseUrl, b as RateLimitError, s as AuthError, t as REOPT_BASE_URLS, x as ReoptSDKError } from "../config-Cw0a3-C8.js";
|
|
2
|
+
import { t as BaseHttpClient } from "../http-client-QKUvvirs.js";
|
|
3
|
+
import { n as REOPT_PROVIDER_ID, t as REOPT_DEFAULT_SCOPES } from "../types-DjDRszNj.js";
|
|
4
|
+
import { createAdapterFactory } from "better-auth/adapters";
|
|
5
|
+
import { genericOAuth } from "better-auth/plugins";
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
//#region src/better-auth/adapter.ts
|
|
8
|
+
/**
|
|
9
|
+
* Read-style adapter operations tunnel over POST (the adapter has a single
|
|
10
|
+
* endpoint), so the shared client would not retry them on a transient 5xx /
|
|
11
|
+
* network blip by default — turning a brief reopt-API hiccup on the hot auth
|
|
12
|
+
* path (a `session` findOne per request when `cookieCache` is off) into a hard
|
|
13
|
+
* failure. Mark them idempotent so they retry, while genuine mutations
|
|
14
|
+
* (create/update/delete) stay non-retried to avoid duplicating a committed
|
|
15
|
+
* write. See helper.ts for the `session.cookieCache` recommendation.
|
|
16
|
+
*/
|
|
17
|
+
const READ_ONLY = { idempotent: true };
|
|
18
|
+
/**
|
|
19
|
+
* Runtime guard — adapter holds clientSecret and must never run in the browser.
|
|
20
|
+
* Fails fast if bundled into client code by accident.
|
|
21
|
+
*/
|
|
11
22
|
function assertServerRuntime() {
|
|
12
|
-
|
|
13
|
-
throw new Error(
|
|
14
|
-
"[@reopt-ai/brandapp-sdk] createReoptAdapter() must be called on the server. It uses clientSecret \u2014 exposing it to the browser is a security risk. Move this call behind a server-only module (e.g. a Next.js route handler, server action, or file marked with 'use server')."
|
|
15
|
-
);
|
|
16
|
-
}
|
|
23
|
+
if (typeof window !== "undefined") throw new Error("[@reopt-ai/brandapp-sdk] createReoptAdapter() must be called on the server. It uses clientSecret — exposing it to the browser is a security risk. Move this call behind a server-only module (e.g. a Next.js route handler, server action, or file marked with 'use server').");
|
|
17
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Reopt Better Auth Remote Database Adapter
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { createReoptAdapter } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
31
|
+
*
|
|
32
|
+
* export const auth = betterAuth({
|
|
33
|
+
* database: createReoptAdapter({
|
|
34
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
35
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
36
|
+
* }),
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
18
40
|
function createReoptAdapter(config) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
where
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
async deleteMany({ model, where }) {
|
|
105
|
-
return request({
|
|
106
|
-
operation: "deleteMany",
|
|
107
|
-
model,
|
|
108
|
-
where
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
41
|
+
assertServerRuntime();
|
|
42
|
+
const http = new BaseHttpClient(config, `/api/v1/brandapp/${config.brandappId}/auth/adapter`);
|
|
43
|
+
async function request(body, options) {
|
|
44
|
+
return (await http.fetch("POST", "", body, options)).data;
|
|
45
|
+
}
|
|
46
|
+
return createAdapterFactory({
|
|
47
|
+
config: {
|
|
48
|
+
adapterId: "reopt-brandapp",
|
|
49
|
+
adapterName: "Reopt Brandapp Adapter",
|
|
50
|
+
supportsUUIDs: true,
|
|
51
|
+
supportsArrays: true,
|
|
52
|
+
debugLogs: false,
|
|
53
|
+
usePlural: false
|
|
54
|
+
},
|
|
55
|
+
adapter: () => {
|
|
56
|
+
return {
|
|
57
|
+
async create({ model, data, select }) {
|
|
58
|
+
return request({
|
|
59
|
+
operation: "create",
|
|
60
|
+
model,
|
|
61
|
+
data,
|
|
62
|
+
select
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
async findOne({ model, where, select }) {
|
|
66
|
+
return request({
|
|
67
|
+
operation: "findOne",
|
|
68
|
+
model,
|
|
69
|
+
where,
|
|
70
|
+
select
|
|
71
|
+
}, READ_ONLY);
|
|
72
|
+
},
|
|
73
|
+
async findMany({ model, where, limit, offset, sortBy }) {
|
|
74
|
+
return request({
|
|
75
|
+
operation: "findMany",
|
|
76
|
+
model,
|
|
77
|
+
where,
|
|
78
|
+
limit,
|
|
79
|
+
offset,
|
|
80
|
+
sortBy
|
|
81
|
+
}, READ_ONLY);
|
|
82
|
+
},
|
|
83
|
+
async count({ model, where }) {
|
|
84
|
+
return request({
|
|
85
|
+
operation: "count",
|
|
86
|
+
model,
|
|
87
|
+
where
|
|
88
|
+
}, READ_ONLY);
|
|
89
|
+
},
|
|
90
|
+
async update({ model, where, update }) {
|
|
91
|
+
return request({
|
|
92
|
+
operation: "update",
|
|
93
|
+
model,
|
|
94
|
+
where,
|
|
95
|
+
update
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
async updateMany({ model, where, update }) {
|
|
99
|
+
return request({
|
|
100
|
+
operation: "updateMany",
|
|
101
|
+
model,
|
|
102
|
+
where,
|
|
103
|
+
update
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
async delete({ model, where }) {
|
|
107
|
+
await request({
|
|
108
|
+
operation: "delete",
|
|
109
|
+
model,
|
|
110
|
+
where
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
async deleteMany({ model, where }) {
|
|
114
|
+
return request({
|
|
115
|
+
operation: "deleteMany",
|
|
116
|
+
model,
|
|
117
|
+
where
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
});
|
|
114
123
|
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/better-auth/oauth.ts
|
|
127
|
+
/**
|
|
128
|
+
* Reopt OAuth Login Plugin
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { createReoptOAuth } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
133
|
+
*
|
|
134
|
+
* export const auth = betterAuth({
|
|
135
|
+
* plugins: [
|
|
136
|
+
* createReoptOAuth({
|
|
137
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
138
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
139
|
+
* }),
|
|
140
|
+
* ],
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
115
144
|
function createReoptOAuth(options) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const idBaseUrl = resolveIdBaseUrl(options);
|
|
127
|
-
return genericOAuth({
|
|
128
|
-
config: [
|
|
129
|
-
{
|
|
130
|
-
providerId: REOPT_PROVIDER_ID,
|
|
131
|
-
discoveryUrl: `${idBaseUrl}/api/auth/.well-known/openid-configuration`,
|
|
132
|
-
clientId: options.clientId,
|
|
133
|
-
clientSecret: options.clientSecret,
|
|
134
|
-
scopes: Array.from(
|
|
135
|
-
/* @__PURE__ */ new Set([
|
|
136
|
-
...REOPT_DEFAULT_SCOPES,
|
|
137
|
-
...options.additionalScopes ?? []
|
|
138
|
-
])
|
|
139
|
-
),
|
|
140
|
-
pkce: true
|
|
141
|
-
}
|
|
142
|
-
]
|
|
143
|
-
});
|
|
145
|
+
if (typeof window !== "undefined") throw new Error("[@reopt-ai/brandapp-sdk] createReoptOAuth() must be called on the server. It uses clientSecret — exposing it to the browser is a security risk. For client-side OAuth sign-in, use createReoptOAuthClient() from '@reopt-ai/brandapp-sdk/better-auth/client' instead.");
|
|
146
|
+
if (!options.clientId || !options.clientSecret) throw new Error("[@reopt-ai/brandapp-sdk] createReoptOAuth() requires clientId and clientSecret.");
|
|
147
|
+
return genericOAuth({ config: [{
|
|
148
|
+
providerId: REOPT_PROVIDER_ID,
|
|
149
|
+
discoveryUrl: `${resolveIdBaseUrl(options)}/api/auth/.well-known/openid-configuration`,
|
|
150
|
+
clientId: options.clientId,
|
|
151
|
+
clientSecret: options.clientSecret,
|
|
152
|
+
scopes: Array.from(/* @__PURE__ */ new Set([...REOPT_DEFAULT_SCOPES, ...options.additionalScopes ?? []])),
|
|
153
|
+
pkce: true
|
|
154
|
+
}] });
|
|
144
155
|
}
|
|
145
156
|
|
|
146
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/better-auth/helper.ts
|
|
159
|
+
/**
|
|
160
|
+
* Config 한 번으로 adapter + OAuth plugin을 함께 생성
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { createReoptBetterAuth } from "@reopt-ai/brandapp-sdk/better-auth";
|
|
165
|
+
*
|
|
166
|
+
* const reopt = createReoptBetterAuth({
|
|
167
|
+
* clientId: process.env.BRANDAPP_CLIENT_ID!,
|
|
168
|
+
* clientSecret: process.env.BRANDAPP_CLIENT_SECRET!,
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* export const auth = betterAuth({
|
|
172
|
+
* database: reopt.database,
|
|
173
|
+
* // ⚡ 세션 쿠키 캐시 권장 — reopt 어댑터는 세션 읽기를 매번 reopt API로
|
|
174
|
+
* // 네트워크 위임한다(findOne "session"). cookieCache를 켜면 better-auth가
|
|
175
|
+
* // 서명된 쿠키에서 세션을 읽어 maxAge(초) 동안 어댑터/네트워크 호출을
|
|
176
|
+
* // 생략한다. (트레이드오프: 세션 강제 무효화가 maxAge 만큼 지연.)
|
|
177
|
+
* // secret이 설정돼 있어야 쿠키 서명이 동작한다.
|
|
178
|
+
* session: { cookieCache: { enabled: true, maxAge: 300 } },
|
|
179
|
+
* plugins: [reopt.oauth, nextCookies()], // nextCookies() must be last
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
147
183
|
function createReoptBetterAuth(options) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
184
|
+
return {
|
|
185
|
+
database: createReoptAdapter(options),
|
|
186
|
+
oauth: createReoptOAuth(options)
|
|
187
|
+
};
|
|
152
188
|
}
|
|
153
189
|
|
|
154
|
-
|
|
155
|
-
|
|
190
|
+
//#endregion
|
|
191
|
+
export { AuthError, REOPT_BASE_URLS, REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID, RateLimitError, ReoptSDKError, ServerError, createReoptAdapter, createReoptBetterAuth, createReoptOAuth, isReoptSDKError };
|
|
156
192
|
//# sourceMappingURL=index.js.map
|