@reopt-ai/brandapp-sdk 3.1.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +39 -14
  3. package/dist/abort--nOBFN4M.js +50 -0
  4. package/dist/ai/index.d.ts +2 -314
  5. package/dist/ai/index.js +3 -7
  6. package/dist/ai-provider/index.d.ts +79 -163
  7. package/dist/ai-provider/index.js +752 -671
  8. package/dist/auth/index.d.ts +27 -27
  9. package/dist/auth/index.js +41 -33
  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 -133
  14. package/dist/client-B1q5P8rv.js +83 -0
  15. package/dist/client-B9QHVhdM.js +77 -0
  16. package/dist/client-BGGd_cpV.d.ts +103 -0
  17. package/dist/client-BJcy1V1a.js +140 -0
  18. package/dist/client-Beivhucf.js +55 -0
  19. package/dist/client-BruP5_nU.d.ts +147 -0
  20. package/dist/client-D-yNxNfk.js +28 -0
  21. package/dist/client-D0eBxh8j.d.ts +284 -0
  22. package/dist/client-D3RHHUUW.d.ts +207 -0
  23. package/dist/client-D6gs61w8.d.ts +53 -0
  24. package/dist/client-DBnK7ooQ.js +86 -0
  25. package/dist/client-DDw5yz_h.d.ts +53 -0
  26. package/dist/client-DPmoKuR9.js +305 -0
  27. package/dist/client-DsdakibF.js +503 -0
  28. package/dist/client-Dxg8_DIH.d.ts +71 -0
  29. package/dist/client-EbhUIhHq.js +53 -0
  30. package/dist/client-lk6wBu_0.d.ts +48 -0
  31. package/dist/client-p49ol9pg.d.ts +124 -0
  32. package/dist/cms/index.d.ts +52 -108
  33. package/dist/cms/index.js +105 -84
  34. package/dist/config-CRytOPPl.d.ts +394 -0
  35. package/dist/config-Cw0a3-C8.js +487 -0
  36. package/dist/dev/index.d.ts +2 -509
  37. package/dist/dev/index.js +2740 -2873
  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 -125
  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-DIAS8Rsl.d.ts → errors-CRCcErNC.d.ts} +55 -53
  48. package/dist/feedback/index.d.ts +2 -132
  49. package/dist/feedback/index.js +3 -5
  50. package/dist/files/index.d.ts +14 -14
  51. package/dist/files/index.js +41 -24
  52. package/dist/http-client-QKUvvirs.js +386 -0
  53. package/dist/index-DrVaKfhs.d.ts +456 -0
  54. package/dist/index-Z6OGcurJ.d.ts +169 -0
  55. package/dist/index.d.ts +6 -221
  56. package/dist/index.js +119 -70
  57. package/dist/logout/index.d.ts +109 -0
  58. package/dist/logout/index.js +264 -0
  59. package/dist/plans/index.d.ts +2 -236
  60. package/dist/plans/index.js +3 -5
  61. package/dist/push/index.d.ts +2 -79
  62. package/dist/push/index.js +3 -5
  63. package/dist/query-BvbCiGWb.js +35 -0
  64. package/dist/react/hooks.d.ts +97 -95
  65. package/dist/react/hooks.js +742 -356
  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 -5
  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 -47
  76. package/dist/webhooks/index.js +150 -127
  77. package/docs/api-reference.md +179 -2
  78. package/docs/dev-server.md +19 -18
  79. package/docs/errors.md +72 -15
  80. package/docs/logout.md +166 -0
  81. package/package.json +10 -5
  82. package/dist/chunk-2Q654O63.js +0 -350
  83. package/dist/chunk-F7BXBTZI.js +0 -54
  84. package/dist/chunk-IJOXTBIE.js +0 -599
  85. package/dist/chunk-JWXUVQRC.js +0 -157
  86. package/dist/chunk-L4DHB36G.js +0 -75
  87. package/dist/chunk-MRQY45U5.js +0 -465
  88. package/dist/chunk-N5JVE4WX.js +0 -449
  89. package/dist/chunk-O3PUWIDJ.js +0 -105
  90. package/dist/chunk-POLKEOYH.js +0 -63
  91. package/dist/chunk-R5CCGDUH.js +0 -49
  92. package/dist/chunk-RBHP7IZF.js +0 -96
  93. package/dist/chunk-REIKXSMY.js +0 -7
  94. package/dist/chunk-T7YTITRJ.js +0 -112
  95. package/dist/chunk-V73GORO3.js +0 -81
  96. package/dist/chunk-VRNBYSWU.js +0 -32
  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,40 +1,48 @@
1
- export { ReoptAuthClient, createReoptAuthClient } from '../chunk-POLKEOYH.js';
2
- import '../chunk-N5JVE4WX.js';
3
- import '../chunk-MRQY45U5.js';
1
+ import { n as createReoptAuthClient, t as ReoptAuthClient } from "../client-EbhUIhHq.js";
4
2
 
5
- // src/auth/session.ts
3
+ //#region src/auth/session.ts
4
+ /**
5
+ * `Cookie` 헤더에 있는 reopt 세션을 id 서버에 위임 검증. 인증되지 않았거나
6
+ * id 서버가 응답하지 않으면 `null`. Edge runtime / Node 둘 다에서 동작.
7
+ */
6
8
  async function getSessionFromCookies(cookieHeader, opts) {
7
- if (!cookieHeader) return null;
8
- const path = opts.path ?? "/api/auth/get-session";
9
- const url = new URL(path, opts.idServerUrl).toString();
10
- const fetchImpl = opts.fetch ?? globalThis.fetch;
11
- let res;
12
- try {
13
- res = await fetchImpl(url, {
14
- method: "GET",
15
- headers: { cookie: cookieHeader, accept: "application/json" },
16
- cache: "no-store",
17
- credentials: "include"
18
- });
19
- } catch {
20
- return null;
21
- }
22
- if (!res.ok) return null;
23
- let body;
24
- try {
25
- body = await res.json();
26
- } catch {
27
- return null;
28
- }
29
- if (!body || typeof body !== "object") return null;
30
- const session = body;
31
- if (!session.user || typeof session.user.id !== "string") return null;
32
- 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;
33
38
  }
39
+ /**
40
+ * 편의 wrapper — `Request` 객체에서 `cookie` 헤더를 꺼내 검증.
41
+ */
34
42
  async function verifySession(request, opts) {
35
- return getSessionFromCookies(request.headers.get("cookie"), opts);
43
+ return getSessionFromCookies(request.headers.get("cookie"), opts);
36
44
  }
37
45
 
38
- export { getSessionFromCookies, verifySession };
39
- //# sourceMappingURL=index.js.map
46
+ //#endregion
47
+ export { ReoptAuthClient, createReoptAuthClient, getSessionFromCookies, verifySession };
40
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-DIAS8Rsl.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,145 +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-N5JVE4WX.js';
4
- import { resolveIdBaseUrl } from '../chunk-MRQY45U5.js';
5
- export { AuthError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, ServerError, isReoptSDKError } from '../chunk-MRQY45U5.js';
6
- import { createAdapterFactory } from 'better-auth/adapters';
7
- 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";
8
6
 
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
+ */
9
22
  function assertServerRuntime() {
10
- if (typeof window !== "undefined") {
11
- throw new Error(
12
- "[@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')."
13
- );
14
- }
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').");
15
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
+ */
16
40
  function createReoptAdapter(config) {
17
- assertServerRuntime();
18
- const http = new BaseHttpClient(
19
- config,
20
- `/api/v1/brandapp/${config.brandappId}/auth/adapter`
21
- );
22
- async function request(body) {
23
- const json = await http.fetch("POST", "", body);
24
- return json.data;
25
- }
26
- return createAdapterFactory({
27
- config: {
28
- adapterId: "reopt-brandapp",
29
- adapterName: "Reopt Brandapp Adapter",
30
- supportsUUIDs: true,
31
- supportsArrays: true,
32
- debugLogs: false,
33
- usePlural: false
34
- },
35
- adapter: () => {
36
- return {
37
- async create({ model, data, select }) {
38
- return request({
39
- operation: "create",
40
- model,
41
- data,
42
- select
43
- });
44
- },
45
- async findOne({ model, where, select }) {
46
- return request({
47
- operation: "findOne",
48
- model,
49
- where,
50
- select
51
- });
52
- },
53
- async findMany({ model, where, limit, offset, sortBy }) {
54
- return request({
55
- operation: "findMany",
56
- model,
57
- where,
58
- limit,
59
- offset,
60
- sortBy
61
- });
62
- },
63
- async count({ model, where }) {
64
- return request({
65
- operation: "count",
66
- model,
67
- where
68
- });
69
- },
70
- async update({ model, where, update }) {
71
- return request({
72
- operation: "update",
73
- model,
74
- where,
75
- update
76
- });
77
- },
78
- async updateMany({ model, where, update }) {
79
- return request({
80
- operation: "updateMany",
81
- model,
82
- where,
83
- update
84
- });
85
- },
86
- async delete({ model, where }) {
87
- await request({
88
- operation: "delete",
89
- model,
90
- where
91
- });
92
- },
93
- async deleteMany({ model, where }) {
94
- return request({
95
- operation: "deleteMany",
96
- model,
97
- where
98
- });
99
- }
100
- };
101
- }
102
- });
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
+ });
103
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
+ */
104
144
  function createReoptOAuth(options) {
105
- if (typeof window !== "undefined") {
106
- throw new Error(
107
- "[@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."
108
- );
109
- }
110
- if (!options.clientId || !options.clientSecret) {
111
- throw new Error(
112
- "[@reopt-ai/brandapp-sdk] createReoptOAuth() requires clientId and clientSecret."
113
- );
114
- }
115
- const idBaseUrl = resolveIdBaseUrl(options);
116
- return genericOAuth({
117
- config: [
118
- {
119
- providerId: REOPT_PROVIDER_ID,
120
- discoveryUrl: `${idBaseUrl}/api/auth/.well-known/openid-configuration`,
121
- clientId: options.clientId,
122
- clientSecret: options.clientSecret,
123
- scopes: Array.from(
124
- /* @__PURE__ */ new Set([
125
- ...REOPT_DEFAULT_SCOPES,
126
- ...options.additionalScopes ?? []
127
- ])
128
- ),
129
- pkce: true
130
- }
131
- ]
132
- });
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
+ }] });
133
155
  }
134
156
 
135
- // 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
+ */
136
183
  function createReoptBetterAuth(options) {
137
- return {
138
- database: createReoptAdapter(options),
139
- oauth: createReoptOAuth(options)
140
- };
184
+ return {
185
+ database: createReoptAdapter(options),
186
+ oauth: createReoptOAuth(options)
187
+ };
141
188
  }
142
189
 
143
- export { createReoptAdapter, createReoptBetterAuth, createReoptOAuth };
144
- //# 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 };
145
192
  //# sourceMappingURL=index.js.map