@reopt-ai/brandapp-sdk 3.3.0 → 3.5.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +10 -1
  3. package/dist/abort--nOBFN4M.js +50 -0
  4. package/dist/ai/index.d.ts +2 -314
  5. package/dist/ai/index.js +3 -8
  6. package/dist/ai-provider/index.d.ts +79 -163
  7. package/dist/ai-provider/index.js +752 -685
  8. package/dist/auth/index.d.ts +27 -27
  9. package/dist/auth/index.js +41 -34
  10. package/dist/better-auth/client.d.ts +6 -5
  11. package/dist/better-auth/client.js +28 -5
  12. package/dist/better-auth/index.d.ts +19 -17
  13. package/dist/better-auth/index.js +180 -144
  14. package/dist/client-61ldOHMz.js +503 -0
  15. package/dist/client-7PCoxVhZ.js +28 -0
  16. package/dist/client-B7rZQ8Zi.d.ts +272 -0
  17. package/dist/client-BGGd_cpV.d.ts +103 -0
  18. package/dist/client-BoIuyx4S.js +273 -0
  19. package/dist/client-BruP5_nU.d.ts +147 -0
  20. package/dist/client-BxtZt405.js +305 -0
  21. package/dist/client-ByN3EQdk.js +83 -0
  22. package/dist/client-CAghoGD_.js +53 -0
  23. package/dist/client-C_pHsPlj.js +81 -0
  24. package/dist/client-D0eBxh8j.d.ts +284 -0
  25. package/dist/client-D6gs61w8.d.ts +53 -0
  26. package/dist/client-DDw5yz_h.d.ts +53 -0
  27. package/dist/client-Dxg8_DIH.d.ts +71 -0
  28. package/dist/client-aMR4CRB8.d.ts +211 -0
  29. package/dist/client-lk6wBu_0.d.ts +48 -0
  30. package/dist/client-wEVKLdly.js +55 -0
  31. package/dist/client-zF1RG2uA.js +86 -0
  32. package/dist/cms/index.d.ts +52 -108
  33. package/dist/cms/index.js +103 -86
  34. package/dist/config-CRytOPPl.d.ts +394 -0
  35. package/dist/config-aml9oQpX.js +487 -0
  36. package/dist/dev/index.d.ts +2 -528
  37. package/dist/dev/index.js +3047 -2967
  38. package/dist/eav/coerce.d.ts +3 -1
  39. package/dist/eav/coerce.js +72 -46
  40. package/dist/eav/index.d.ts +72 -100
  41. package/dist/eav/index.js +158 -126
  42. package/dist/eav/migrate.d.ts +112 -109
  43. package/dist/eav/migrate.js +230 -196
  44. package/dist/eav/schema.d.ts +111 -150
  45. package/dist/eav/schema.js +624 -603
  46. package/dist/encoding-Bwfm3iaE.js +21 -0
  47. package/dist/{errors-BjDFIyA6.d.ts → errors-CRCcErNC.d.ts} +55 -53
  48. package/dist/feedback/index.d.ts +2 -132
  49. package/dist/feedback/index.js +3 -6
  50. package/dist/files/index.d.ts +14 -14
  51. package/dist/files/index.js +41 -25
  52. package/dist/http-client-BZc2mngq.js +386 -0
  53. package/dist/index-1j_738qk.d.ts +470 -0
  54. package/dist/index-CeOLGdyL.d.ts +169 -0
  55. package/dist/index.d.ts +6 -230
  56. package/dist/index.js +119 -71
  57. package/dist/logout/index.d.ts +56 -53
  58. package/dist/logout/index.js +232 -289
  59. package/dist/plans/index.d.ts +2 -236
  60. package/dist/plans/index.js +3 -6
  61. package/dist/push/index.d.ts +2 -79
  62. package/dist/push/index.js +3 -6
  63. package/dist/query-xWqtfkvR.js +35 -0
  64. package/dist/react/hooks.d.ts +157 -100
  65. package/dist/react/hooks.js +862 -406
  66. package/dist/sse-parser-FMjxM7sY.js +86 -0
  67. package/dist/terms/index.d.ts +3 -79
  68. package/dist/terms/index.js +3 -6
  69. package/dist/testing/index.d.ts +52 -104
  70. package/dist/testing/index.js +94 -72
  71. package/dist/types-B-SMkH6s.d.ts +26 -0
  72. package/dist/types-BXDcoJHG.d.ts +131 -0
  73. package/dist/types-BrghN2rJ.d.ts +105 -0
  74. package/dist/types-DjDRszNj.js +11 -0
  75. package/dist/webhooks/index.d.ts +77 -50
  76. package/dist/webhooks/index.js +150 -127
  77. package/docs/api-reference.md +121 -8
  78. package/docs/errors.md +19 -0
  79. package/docs/files.md +165 -7
  80. package/package.json +7 -6
  81. package/dist/chunk-2LSCQHAU.js +0 -21
  82. package/dist/chunk-4U4ZPPL4.js +0 -599
  83. package/dist/chunk-55KHY5GH.js +0 -96
  84. package/dist/chunk-C5VTRZWX.js +0 -458
  85. package/dist/chunk-F7BXBTZI.js +0 -54
  86. package/dist/chunk-FJUCWXX3.js +0 -350
  87. package/dist/chunk-H33OTQEN.js +0 -112
  88. package/dist/chunk-L4DHB36G.js +0 -75
  89. package/dist/chunk-OG7R3UAR.js +0 -105
  90. package/dist/chunk-PF24XU54.js +0 -32
  91. package/dist/chunk-QN3QD67K.js +0 -49
  92. package/dist/chunk-REIKXSMY.js +0 -7
  93. package/dist/chunk-UGBBXCZE.js +0 -157
  94. package/dist/chunk-UVT2E6KD.js +0 -81
  95. package/dist/chunk-YPLT3RFL.js +0 -63
  96. package/dist/chunk-YTKSAWV2.js +0 -463
  97. package/dist/client-BkcO-0C2.d.ts +0 -216
  98. package/dist/client-CN5_tNOC.d.ts +0 -147
  99. package/dist/client-DttyeM_h.d.ts +0 -102
  100. package/dist/config-CtxyJsDR.d.ts +0 -397
  101. package/dist/typed-client-BxOVIiMU.d.ts +0 -40
  102. package/dist/types-6E3ZLL9X.d.ts +0 -24
  103. package/dist/types-DskYLVb8.d.ts +0 -104
  104. package/dist/types-ckmDDW3N.d.ts +0 -129
@@ -1,6 +1,5 @@
1
- export { L as LinkCurrentUserResult, R as ReoptAuthClient, U as UserInfoClaims, c as createReoptAuthClient } from '../client-DttyeM_h.js';
2
- import '../config-CtxyJsDR.js';
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
- user: {
42
- id: string;
43
- email: string;
44
- name: string;
45
- image: string | null;
46
- emailVerified?: boolean;
47
- };
48
- session: {
49
- id: string;
50
- expiresAt: string;
51
- /** Optional — Better Auth가 환경에 따라 포함하거나 빼는 필드들. */
52
- userId?: string;
53
- token?: string;
54
- ipAddress?: string | null;
55
- userAgent?: string | null;
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
- /** Better Auth handler가 마운트된 URL. e.g. "https://id.reopt.ai". */
60
- idServerUrl: string;
61
- /** 기본 `/api/auth/get-session`. 다른 path에 mount된 경우 override. */
62
- path?: string;
63
- /** Optional fetch override (테스트/SSR proxy 용). 기본 `globalThis.fetch`. */
64
- fetch?: typeof fetch;
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
@@ -1,41 +1,48 @@
1
- export { ReoptAuthClient, createReoptAuthClient } from '../chunk-YPLT3RFL.js';
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-CAghoGD_.js";
5
2
 
6
- // src/auth/session.ts
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
- if (!cookieHeader) return null;
9
- const path = opts.path ?? "/api/auth/get-session";
10
- const url = new URL(path, opts.idServerUrl).toString();
11
- const fetchImpl = opts.fetch ?? globalThis.fetch;
12
- let res;
13
- try {
14
- res = await fetchImpl(url, {
15
- method: "GET",
16
- headers: { cookie: cookieHeader, accept: "application/json" },
17
- cache: "no-store",
18
- credentials: "include"
19
- });
20
- } catch {
21
- return null;
22
- }
23
- if (!res.ok) return null;
24
- let body;
25
- try {
26
- body = await res.json();
27
- } catch {
28
- return null;
29
- }
30
- if (!body || typeof body !== "object") return null;
31
- const session = body;
32
- if (!session.user || typeof session.user.id !== "string") return null;
33
- return session;
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
- return getSessionFromCookies(request.headers.get("cookie"), opts);
43
+ return getSessionFromCookies(request.headers.get("cookie"), opts);
37
44
  }
38
45
 
39
- export { getSessionFromCookies, verifySession };
40
- //# sourceMappingURL=index.js.map
46
+ //#endregion
47
+ export { ReoptAuthClient, createReoptAuthClient, getSessionFromCookies, verifySession };
41
48
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
- import { genericOAuthClient } from 'better-auth/client/plugins';
2
- export { b as REOPT_PROVIDER_ID } from '../types-6E3ZLL9X.js';
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
- export { REOPT_PROVIDER_ID } from '../chunk-REIKXSMY.js';
2
- import { genericOAuthClient } from 'better-auth/client/plugins';
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
- return genericOAuthClient();
28
+ return genericOAuthClient();
6
29
  }
7
30
 
8
- export { createReoptOAuthClient };
9
- //# sourceMappingURL=client.js.map
31
+ //#endregion
32
+ export { REOPT_PROVIDER_ID, createReoptOAuthClient };
10
33
  //# sourceMappingURL=client.js.map
@@ -1,10 +1,9 @@
1
- import { AdapterFactory } from 'better-auth/adapters';
2
- import { BetterAuthOptions, BetterAuthPlugin } from 'better-auth';
3
- import { q as ReoptSDKConfig } from '../config-CtxyJsDR.js';
4
- export { R as REOPT_BASE_URLS } from '../config-CtxyJsDR.js';
5
- export { A as AdapterOperation, a as AdapterRequestBody, R as REOPT_DEFAULT_SCOPES, b as REOPT_PROVIDER_ID } from '../types-6E3ZLL9X.js';
6
- export { A as AuthError, R as RateLimitError, g as ReoptSDKError, S as ServerError, l as isReoptSDKError } from '../errors-BjDFIyA6.js';
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
- /** Additional OAuth scopes */
27
- additionalScopes?: string[];
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
- /** Additional OAuth scopes */
50
- additionalScopes?: string[];
50
+ /** Additional OAuth scopes */
51
+ additionalScopes?: string[];
51
52
  };
52
53
  type ReoptBetterAuthBundle = {
53
- database: AdapterFactory<BetterAuthOptions>;
54
- oauth: BetterAuthPlugin;
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 { REOPT_PROVIDER_ID, REOPT_DEFAULT_SCOPES } from '../chunk-REIKXSMY.js';
2
- export { REOPT_DEFAULT_SCOPES, REOPT_PROVIDER_ID } from '../chunk-REIKXSMY.js';
3
- import { BaseHttpClient } from '../chunk-YTKSAWV2.js';
4
- import '../chunk-2LSCQHAU.js';
5
- import { resolveIdBaseUrl } from '../chunk-C5VTRZWX.js';
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-aml9oQpX.js";
2
+ import { t as BaseHttpClient } from "../http-client-BZc2mngq.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
- var READ_ONLY = { idempotent: true };
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
- if (typeof window !== "undefined") {
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
- assertServerRuntime();
20
- const http = new BaseHttpClient(
21
- config,
22
- `/api/v1/brandapp/${config.brandappId}/auth/adapter`
23
- );
24
- async function request(body, options) {
25
- const json = await http.fetch("POST", "", body, options);
26
- return json.data;
27
- }
28
- return createAdapterFactory({
29
- config: {
30
- adapterId: "reopt-brandapp",
31
- adapterName: "Reopt Brandapp Adapter",
32
- supportsUUIDs: true,
33
- supportsArrays: true,
34
- debugLogs: false,
35
- usePlural: false
36
- },
37
- adapter: () => {
38
- return {
39
- async create({ model, data, select }) {
40
- return request({
41
- operation: "create",
42
- model,
43
- data,
44
- select
45
- });
46
- },
47
- async findOne({ model, where, select }) {
48
- return request(
49
- {
50
- operation: "findOne",
51
- model,
52
- where,
53
- select
54
- },
55
- READ_ONLY
56
- );
57
- },
58
- async findMany({ model, where, limit, offset, sortBy }) {
59
- return request(
60
- {
61
- operation: "findMany",
62
- model,
63
- where,
64
- limit,
65
- offset,
66
- sortBy
67
- },
68
- READ_ONLY
69
- );
70
- },
71
- async count({ model, where }) {
72
- return request(
73
- {
74
- operation: "count",
75
- model,
76
- where
77
- },
78
- READ_ONLY
79
- );
80
- },
81
- async update({ model, where, update }) {
82
- return request({
83
- operation: "update",
84
- model,
85
- where,
86
- update
87
- });
88
- },
89
- async updateMany({ model, where, update }) {
90
- return request({
91
- operation: "updateMany",
92
- model,
93
- where,
94
- update
95
- });
96
- },
97
- async delete({ model, where }) {
98
- await request({
99
- operation: "delete",
100
- model,
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
- if (typeof window !== "undefined") {
117
- throw new Error(
118
- "[@reopt-ai/brandapp-sdk] createReoptOAuth() must be called on the server. It uses clientSecret \u2014 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."
119
- );
120
- }
121
- if (!options.clientId || !options.clientSecret) {
122
- throw new Error(
123
- "[@reopt-ai/brandapp-sdk] createReoptOAuth() requires clientId and clientSecret."
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
- // src/better-auth/helper.ts
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
- return {
149
- database: createReoptAdapter(options),
150
- oauth: createReoptOAuth(options)
151
- };
184
+ return {
185
+ database: createReoptAdapter(options),
186
+ oauth: createReoptOAuth(options)
187
+ };
152
188
  }
153
189
 
154
- export { createReoptAdapter, createReoptBetterAuth, createReoptOAuth };
155
- //# sourceMappingURL=index.js.map
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