@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,157 +0,0 @@
1
- import { createManagedAbort } from './chunk-F7BXBTZI.js';
2
- import { BaseHttpClient, parseFieldErrors } from './chunk-N5JVE4WX.js';
3
- import { validateConfig, SDK_VERSION, mapHttpStatusToError, ReoptSDKError } from './chunk-MRQY45U5.js';
4
-
5
- // src/files/client.ts
6
- var ReoptFileClient = class {
7
- http;
8
- timeout;
9
- constructor(config) {
10
- validateConfig(config);
11
- const pathPrefix = `/api/v1/brandapp/${config.brandappId}/files`;
12
- this.http = new BaseHttpClient(config, pathPrefix);
13
- this.timeout = config.timeout ?? 3e4;
14
- }
15
- /**
16
- * 파일 목록 조회
17
- *
18
- * @example
19
- * ```ts
20
- * const { data: files, meta } = await sdk.files.list({
21
- * page: 1,
22
- * limit: 20,
23
- * contentType: "image/*",
24
- * sortBy: "createdAt",
25
- * sortOrder: "desc",
26
- * });
27
- * console.log(`Total: ${meta.total}`);
28
- * ```
29
- */
30
- async list(query) {
31
- const params = new URLSearchParams();
32
- if (query?.page != null) params.set("page", String(query.page));
33
- if (query?.limit != null) params.set("limit", String(query.limit));
34
- if (query?.contentType) params.set("contentType", query.contentType);
35
- if (query?.sortBy) params.set("sortBy", query.sortBy);
36
- if (query?.sortOrder) params.set("sortOrder", query.sortOrder);
37
- const qs = params.toString();
38
- const path = qs ? `?${qs}` : "";
39
- return this.http.fetch("GET", path);
40
- }
41
- /**
42
- * 단일 파일 조회
43
- *
44
- * @example
45
- * ```ts
46
- * const file = await sdk.files.get("file-uuid");
47
- * console.log(file.name, file.url);
48
- * ```
49
- */
50
- async get(fileId) {
51
- const response = await this.http.fetch(
52
- "GET",
53
- `/${fileId}`
54
- );
55
- return response.data;
56
- }
57
- /**
58
- * 파일 삭제
59
- *
60
- * @example
61
- * ```ts
62
- * await sdk.files.delete("file-uuid");
63
- * ```
64
- */
65
- async delete(fileId) {
66
- await this.http.fetch("DELETE", `/${fileId}`);
67
- }
68
- /**
69
- * 파일 업로드
70
- *
71
- * FormData(multipart)로 파일을 전송합니다.
72
- * BaseHttpClient는 JSON 전용이므로 globalThis.fetch를 직접 사용합니다.
73
- *
74
- * @example
75
- * ```ts
76
- * // Blob 업로드
77
- * const blob = new Blob(["hello"], { type: "text/plain" });
78
- * const file = await sdk.files.upload(blob, { name: "hello.txt" });
79
- *
80
- * // File 업로드 (브라우저)
81
- * const file = await sdk.files.upload(inputEl.files[0]);
82
- *
83
- * // Buffer 업로드 (Node.js)
84
- * const buf = fs.readFileSync("image.png");
85
- * const file = await sdk.files.upload(buf, {
86
- * name: "image.png",
87
- * contentType: "image/png",
88
- * });
89
- * ```
90
- */
91
- async upload(file, options) {
92
- const formData = new FormData();
93
- if (file instanceof Blob) {
94
- const fileName = options?.name ?? ("name" in file ? file.name : "upload");
95
- formData.append("file", file, fileName);
96
- } else {
97
- const arrayBuffer = file.buffer.slice(
98
- file.byteOffset,
99
- file.byteOffset + file.byteLength
100
- );
101
- const blob = new Blob([arrayBuffer], {
102
- type: options?.contentType ?? "application/octet-stream"
103
- });
104
- formData.append("file", blob, options?.name ?? "upload");
105
- }
106
- if (options?.name) formData.append("name", options.name);
107
- if (options?.contentType)
108
- formData.append("contentType", options.contentType);
109
- const url = `${this.http.requestBaseUrl}/upload`;
110
- const managed = createManagedAbort({
111
- timeoutMs: options?.timeout ?? this.timeout,
112
- external: options?.signal
113
- });
114
- try {
115
- const response = await globalThis.fetch(url, {
116
- method: "POST",
117
- headers: {
118
- Authorization: this.http.authorizationHeader,
119
- "X-SDK-Version": `brandapp-sdk/${SDK_VERSION}`
120
- // Content-Type은 FormData가 자동 설정 (boundary 포함)
121
- },
122
- body: formData,
123
- signal: managed.signal
124
- });
125
- if (!response.ok) {
126
- const body = await response.json().catch(() => ({}));
127
- const errObj = typeof body.error === "object" ? body.error : void 0;
128
- const msg = errObj?.message ?? (typeof body.error === "string" ? body.error : void 0) ?? `Upload failed with status ${response.status}`;
129
- const fieldErrors = response.status === 422 ? parseFieldErrors(body) : [];
130
- throw mapHttpStatusToError(
131
- response.status,
132
- errObj?.code,
133
- msg,
134
- { method: "POST", url },
135
- fieldErrors
136
- );
137
- }
138
- const result = await response.json();
139
- return result.data;
140
- } catch (e) {
141
- if (e instanceof ReoptSDKError) throw e;
142
- if (e instanceof Error && e.name === "AbortError") {
143
- throw new ReoptSDKError("Upload request timed out", 408, "TIMEOUT");
144
- }
145
- throw e;
146
- } finally {
147
- managed.cleanup();
148
- }
149
- }
150
- };
151
- function createReoptFileClient(config) {
152
- return new ReoptFileClient(config);
153
- }
154
-
155
- export { ReoptFileClient, createReoptFileClient };
156
- //# sourceMappingURL=chunk-JWXUVQRC.js.map
157
- //# sourceMappingURL=chunk-JWXUVQRC.js.map
@@ -1,75 +0,0 @@
1
- // src/core/sse-parser.ts
2
- function createSSELineProcessor(onEvent) {
3
- let buffer = "";
4
- let currentEvent = "";
5
- let dataBuffer = "";
6
- function processLine(line) {
7
- const stripped = line.endsWith("\r") ? line.slice(0, -1) : line;
8
- if (stripped.startsWith("event:")) {
9
- const raw = stripped.slice(6);
10
- currentEvent = raw.startsWith(" ") ? raw.slice(1) : raw;
11
- } else if (stripped.startsWith("data:")) {
12
- const raw = stripped.slice(5);
13
- const data = raw.startsWith(" ") ? raw.slice(1) : raw;
14
- dataBuffer = dataBuffer ? dataBuffer + "\n" + data : data;
15
- } else if (stripped === "") {
16
- if (dataBuffer) {
17
- onEvent({ event: currentEvent, data: dataBuffer });
18
- }
19
- currentEvent = "";
20
- dataBuffer = "";
21
- }
22
- }
23
- return {
24
- feed(chunk) {
25
- buffer += chunk;
26
- const lines = buffer.split("\n");
27
- buffer = lines.pop() ?? "";
28
- for (const line of lines) processLine(line);
29
- },
30
- /**
31
- * Flush any buffered input at stream end.
32
- * Processes the last partial line (if any) and emits a final event
33
- * if a data buffer is still pending.
34
- */
35
- flush() {
36
- if (buffer.length > 0) {
37
- processLine(buffer);
38
- buffer = "";
39
- }
40
- if (dataBuffer) {
41
- onEvent({ event: currentEvent, data: dataBuffer });
42
- currentEvent = "";
43
- dataBuffer = "";
44
- }
45
- }
46
- };
47
- }
48
- async function* parseSSEStream(body) {
49
- const reader = body.getReader();
50
- const decoder = new TextDecoder();
51
- const pending = [];
52
- const processor = createSSELineProcessor((event) => {
53
- pending.push(event);
54
- });
55
- try {
56
- while (true) {
57
- const { done, value } = await reader.read();
58
- if (done) break;
59
- processor.feed(decoder.decode(value, { stream: true }));
60
- while (pending.length > 0) {
61
- yield pending.shift();
62
- }
63
- }
64
- processor.flush();
65
- while (pending.length > 0) {
66
- yield pending.shift();
67
- }
68
- } finally {
69
- reader.releaseLock();
70
- }
71
- }
72
-
73
- export { createSSELineProcessor, parseSSEStream };
74
- //# sourceMappingURL=chunk-L4DHB36G.js.map
75
- //# sourceMappingURL=chunk-L4DHB36G.js.map
@@ -1,465 +0,0 @@
1
- // src/core/errors.ts
2
- var ReoptSDKError = class extends Error {
3
- status;
4
- code;
5
- context;
6
- diagnostic;
7
- constructor(message, status, code, context, diagnostic) {
8
- const prefix = context?.method && context.url ? `[${context.method} ${context.url}] ` : "";
9
- super(`${prefix}${message}`);
10
- this.name = "ReoptSDKError";
11
- this.status = status;
12
- this.code = code;
13
- this.context = context;
14
- this.diagnostic = diagnostic;
15
- }
16
- };
17
- var AuthError = class extends ReoptSDKError {
18
- constructor(message = "Authentication failed", context) {
19
- super(message, 401, "AUTH_ERROR", context, {
20
- cause: "clientId \uB610\uB294 clientSecret\uC774 \uC798\uBABB\uB418\uC5C8\uAC70\uB098 OAuth \uD074\uB77C\uC774\uC5B8\uD2B8\uAC00 \uBE44\uD65C\uC131\uD654\uB428",
21
- fix: "Studio \u2192 BrandApp \u2192 \uC124\uC815 \u2192 OAuth \uD074\uB77C\uC774\uC5B8\uD2B8\uC5D0\uC11C \uC790\uACA9\uC99D\uBA85 \uD655\uC778",
22
- doc: "docs/errors.md#auth_error"
23
- });
24
- this.name = "AuthError";
25
- }
26
- };
27
- var RateLimitError = class extends ReoptSDKError {
28
- constructor(message = "Rate limit exceeded", retryAfterMs) {
29
- super(message, 429, "RATE_LIMIT", void 0, {
30
- cause: "\uBD84\uB2F9/\uC2DC\uAC04\uB2F9 \uC694\uCCAD \uD55C\uB3C4 \uCD08\uACFC",
31
- fix: retryAfterMs ? `${Math.ceil(retryAfterMs / 1e3)}\uCD08 \uD6C4 \uC7AC\uC2DC\uB3C4\uD558\uAC70\uB098, BrandApp AI \uC124\uC815\uC5D0\uC11C rateLimit \uC870\uC815` : "\uC694\uCCAD \uAC04\uACA9\uC744 \uB298\uB9AC\uAC70\uB098 BrandApp AI \uC124\uC815\uC5D0\uC11C rateLimit \uC870\uC815",
32
- doc: "docs/errors.md#rate_limit"
33
- });
34
- this.name = "RateLimitError";
35
- }
36
- };
37
- var ServerError = class extends ReoptSDKError {
38
- constructor(message = "Internal server error") {
39
- super(message, 500, "SERVER_ERROR", void 0, {
40
- cause: "\uC11C\uBC84 \uB0B4\uBD80 \uC624\uB958",
41
- fix: "\uC7A0\uC2DC \uD6C4 \uC7AC\uC2DC\uB3C4. \uBC18\uBCF5\uB418\uBA74 \uC11C\uBC84 \uC0C1\uD0DC \uD655\uC778",
42
- doc: "docs/errors.md#server_error"
43
- });
44
- this.name = "ServerError";
45
- }
46
- };
47
- var CreditLimitError = class extends ReoptSDKError {
48
- constructor(message = "Insufficient AI credits", context, code = "CREDIT_LIMIT") {
49
- super(message, 402, code, context, {
50
- cause: "BrandApp AI \uD06C\uB808\uB527 \uC794\uC561 \uBD80\uC871",
51
- fix: "Studio \u2192 BrandApp \u2192 AI \uD06C\uB808\uB527 \uD398\uC774\uC9C0\uC5D0\uC11C \uCDA9\uC804",
52
- doc: "docs/errors.md#credit_limit"
53
- });
54
- this.name = "CreditLimitError";
55
- }
56
- };
57
- var ModelAccessError = class extends ReoptSDKError {
58
- constructor(message = "Model not available for this plan tier", context) {
59
- super(message, 403, "MODEL_ACCESS_DENIED", context, {
60
- cause: "\uD604\uC7AC plan tier \uB610\uB294 BrandApp AI \uC124\uC815\uC5D0\uC11C \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uB294 \uBAA8\uB378",
61
- fix: "sdk.ai.models()\uB85C \uC0AC\uC6A9 \uAC00\uB2A5 \uBAA8\uB378 \uD655\uC778, \uB610\uB294 Studio \u2192 BrandApp \u2192 AI\uC5D0\uC11C \uBAA8\uB378 tier\xB7plan \uC5C5\uADF8\uB808\uC774\uB4DC",
62
- doc: "docs/errors.md#model_access_denied"
63
- });
64
- this.name = "ModelAccessError";
65
- }
66
- };
67
- var ModelNotFoundError = class extends ReoptSDKError {
68
- constructor(message = "Unknown model", context) {
69
- super(message, 404, "MODEL_NOT_FOUND", context, {
70
- cause: "\uC694\uCCAD\uD55C model ID\uAC00 \uCE74\uD0C8\uB85C\uADF8\uC5D0 \uC5C6\uC74C (\uC624\uD0C0 \uB610\uB294 \uD3D0\uAE30\uB41C \uBAA8\uB378)",
71
- fix: "sdk.ai.models()\uB85C \uC720\uD6A8\uD55C model ID\uB97C \uC870\uD68C",
72
- doc: "docs/errors.md#model_not_found"
73
- });
74
- this.name = "ModelNotFoundError";
75
- }
76
- };
77
- var ContentFilterError = class extends ReoptSDKError {
78
- constructor(message = "Content blocked by moderation policy", context) {
79
- super(message, 422, "CONTENT_FILTER", context, {
80
- cause: "\uD504\uB86C\uD504\uD2B8 \uB610\uB294 \uC0DD\uC131 \uACB0\uACFC\uAC00 \uCF58\uD150\uCE20 \uC815\uCC45\uC744 \uC704\uBC18",
81
- fix: "\uD504\uB86C\uD504\uD2B8\uB97C \uC218\uC815\uD574 \uC815\uCC45 \uC704\uBC18 \uC18C\uC9C0\uB97C \uC81C\uAC70",
82
- doc: "docs/errors.md#content_filter"
83
- });
84
- this.name = "ContentFilterError";
85
- }
86
- };
87
- var BadRequestError = class extends ReoptSDKError {
88
- constructor(message = "Bad request", context, code = "BAD_REQUEST") {
89
- super(message, 400, code, context, {
90
- cause: "\uC694\uCCAD \uD30C\uB77C\uBBF8\uD130\uAC00 \uC798\uBABB\uB428",
91
- fix: "\uC694\uCCAD \uBCF8\uBB38\uACFC \uCFFC\uB9AC \uD30C\uB77C\uBBF8\uD130\uB97C \uD655\uC778"
92
- });
93
- this.name = "BadRequestError";
94
- }
95
- };
96
- var ForbiddenError = class extends ReoptSDKError {
97
- constructor(message = "Forbidden", context, code = "FORBIDDEN") {
98
- super(message, 403, code, context, {
99
- cause: "\uD574\uB2F9 \uB9AC\uC18C\uC2A4\uC5D0 \uB300\uD55C \uC811\uADFC \uAD8C\uD55C\uC774 \uC5C6\uC74C",
100
- fix: "OAuth \uC2A4\uCF54\uD504, \uC6CC\uD06C\uC2A4\uD398\uC774\uC2A4 \uAD8C\uD55C, \uB610\uB294 authUserId\uB97C \uD655\uC778"
101
- });
102
- this.name = "ForbiddenError";
103
- }
104
- };
105
- var NotFoundError = class extends ReoptSDKError {
106
- constructor(message = "Not found", context, code = "NOT_FOUND") {
107
- super(message, 404, code, context, {
108
- cause: "\uC694\uCCAD\uD55C \uB9AC\uC18C\uC2A4\uAC00 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC74C",
109
- fix: "ID \uB610\uB294 \uACBD\uB85C\uAC00 \uC62C\uBC14\uB978\uC9C0 \uD655\uC778. \uC0AD\uC81C\uB41C \uB9AC\uC18C\uC2A4\uC77C \uC218 \uC788\uC74C"
110
- });
111
- this.name = "NotFoundError";
112
- }
113
- };
114
- var ConflictError = class extends ReoptSDKError {
115
- constructor(message = "Conflict", context, code = "CONFLICT") {
116
- super(message, 409, code, context, {
117
- cause: "\uD604\uC7AC \uB9AC\uC18C\uC2A4 \uC0C1\uD0DC\uC640 \uCDA9\uB3CC (\uC911\uBCF5 \uD0A4, \uB3D9\uC2DC \uC218\uC815 \uB4F1)",
118
- fix: "\uAE30\uC874 \uB370\uC774\uD130\uB97C \uB2E4\uC2DC \uC870\uD68C \uD6C4 \uC7AC\uC2DC\uB3C4"
119
- });
120
- this.name = "ConflictError";
121
- }
122
- };
123
- var AuthUserRecordExistsError = class extends ConflictError {
124
- constructor(message = "Auth user already has a record for this entity", context) {
125
- super(message, context, "AUTH_USER_RECORD_EXISTS");
126
- this.name = "AuthUserRecordExistsError";
127
- }
128
- };
129
- var DuplicateAuthUserError = class extends ConflictError {
130
- constructor(message = "Duplicate authUserId in bulk create", context) {
131
- super(message, context, "DUPLICATE_AUTH_USER");
132
- this.name = "DuplicateAuthUserError";
133
- }
134
- };
135
- var AuthUserNotFoundError = class extends ReoptSDKError {
136
- constructor(message = "Auth user not found in this brandapp", status = 422, context) {
137
- super(message, status, "AUTH_USER_NOT_FOUND", context, {
138
- cause: "\uCC38\uC870\uD55C authUserId\uAC00 \uC774 brandapp\uC5D0 \uB4F1\uB85D\uB418\uC9C0 \uC54A\uC74C",
139
- fix: "BrandappAuthUser\uAC00 \uBA3C\uC800 \uC0DD\uC131\uB418\uC5C8\uB294\uC9C0 \uD655\uC778. authUserId \uC624\uD0C0 \uC810\uAC80"
140
- });
141
- this.name = "AuthUserNotFoundError";
142
- }
143
- };
144
- var LimitExceededError = class extends ReoptSDKError {
145
- constructor(message, code, context) {
146
- super(message, 422, code, context, {
147
- cause: "EAV \uC790\uC6D0 \uD55C\uB3C4 \uCD08\uACFC (plan \uB610\uB294 \uC2DC\uC2A4\uD15C limit)",
148
- fix: "\uC624\uB798\uB41C \uB370\uC774\uD130 \uC815\uB9AC \uD6C4 \uC7AC\uC2DC\uB3C4\uD558\uAC70\uB098, plan \uC5C5\uADF8\uB808\uC774\uB4DC \uAC80\uD1A0"
149
- });
150
- this.name = "LimitExceededError";
151
- }
152
- };
153
- var RequiredTermsError = class extends ReoptSDKError {
154
- missingTermsIds;
155
- constructor(message = "\uD544\uC218 \uC57D\uAD00 \uB3D9\uC758\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4", missingTermsIds = [], context) {
156
- super(message, 422, "REQUIRED_TERMS", context, {
157
- cause: "\uC774 \uD50C\uB79C \uAD6C\uB3C5 \uC804\uC5D0 \uB3D9\uC758\uD574\uC57C \uD558\uB294 \uD544\uC218 \uC57D\uAD00\uC774 \uB0A8\uC544 \uC788\uC74C",
158
- fix: "sdk.terms.list()\uB85C \uC57D\uAD00\uC744 \uC870\uD68C\uD558\uACE0 sdk.terms.consent()\uB85C \uB3D9\uC758\uD55C \uB4A4 \uB2E4\uC2DC \uACB0\uC81C\uB97C \uC2DC\uC791",
159
- doc: "docs/errors.md#required_terms"
160
- });
161
- this.name = "RequiredTermsError";
162
- this.missingTermsIds = missingTermsIds;
163
- }
164
- };
165
- function isRequiredTermsError(error) {
166
- return error instanceof Error && error.name === "RequiredTermsError" && "missingTermsIds" in error;
167
- }
168
- var ValidationError = class extends ReoptSDKError {
169
- fieldErrors;
170
- constructor(message, fieldErrors, context) {
171
- super(message, 422, "VALIDATION_ERROR", context);
172
- this.name = "ValidationError";
173
- this.fieldErrors = fieldErrors;
174
- }
175
- /** 특정 필드의 에러 메시지 반환 */
176
- getFieldError(field) {
177
- return this.fieldErrors.find((e) => e.field === field)?.message;
178
- }
179
- /** 필드 → 메시지 맵 반환 */
180
- toFieldMap() {
181
- const map = {};
182
- for (const fe of this.fieldErrors) {
183
- map[fe.field] = fe.message;
184
- }
185
- return map;
186
- }
187
- };
188
- function isValidationError(error) {
189
- return error instanceof Error && error.name === "ValidationError" && "fieldErrors" in error;
190
- }
191
- function isReoptSDKError(error) {
192
- return error instanceof Error && typeof error.status === "number" && typeof error.code === "string";
193
- }
194
- function isCreditLimitError(error) {
195
- return error instanceof Error && error.name === "CreditLimitError";
196
- }
197
- function isModelAccessError(error) {
198
- return error instanceof Error && error.name === "ModelAccessError";
199
- }
200
- function mapHttpStatusToError(status, code, message, ctx, fieldErrors) {
201
- switch (status) {
202
- case 401:
203
- return new AuthError(message ?? "Authentication failed", ctx);
204
- case 402:
205
- return new CreditLimitError(
206
- message ?? "Insufficient AI credits",
207
- ctx,
208
- code ?? "CREDIT_LIMIT"
209
- );
210
- case 400:
211
- if (code === "AUTH_USER_NOT_FOUND") {
212
- return new AuthUserNotFoundError(
213
- message ?? "Auth user not found in this brandapp",
214
- 400,
215
- ctx
216
- );
217
- }
218
- return new BadRequestError(
219
- message ?? "Bad request",
220
- ctx,
221
- code ?? "BAD_REQUEST"
222
- );
223
- case 403:
224
- if (code === "MODEL_ACCESS_DENIED") {
225
- return new ModelAccessError(
226
- message ?? "Model not available for this plan tier",
227
- ctx
228
- );
229
- }
230
- return new ForbiddenError(
231
- message ?? "Forbidden",
232
- ctx,
233
- code ?? "FORBIDDEN"
234
- );
235
- case 404:
236
- if (code === "MODEL_NOT_FOUND") {
237
- return new ModelNotFoundError(message ?? "Unknown model", ctx);
238
- }
239
- return new NotFoundError(
240
- message ?? "Not found",
241
- ctx,
242
- code ?? "NOT_FOUND"
243
- );
244
- case 409:
245
- if (code === "AUTH_USER_RECORD_EXISTS") {
246
- return new AuthUserRecordExistsError(
247
- message ?? "Auth user already has a record for this entity",
248
- ctx
249
- );
250
- }
251
- if (code === "DUPLICATE_AUTH_USER") {
252
- return new DuplicateAuthUserError(
253
- message ?? "Duplicate authUserId in bulk create",
254
- ctx
255
- );
256
- }
257
- return new ConflictError(message ?? "Conflict", ctx, code ?? "CONFLICT");
258
- case 422:
259
- if (code === "REQUIRED_TERMS") {
260
- return new RequiredTermsError(
261
- message ?? "\uD544\uC218 \uC57D\uAD00 \uB3D9\uC758\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4",
262
- (fieldErrors ?? []).map((f) => f.field),
263
- ctx
264
- );
265
- }
266
- if (fieldErrors && fieldErrors.length > 0) {
267
- return new ValidationError(
268
- message ?? "Validation failed",
269
- fieldErrors,
270
- ctx
271
- );
272
- }
273
- if (code === "CONTENT_FILTER") {
274
- return new ContentFilterError(
275
- message ?? "Content blocked by moderation policy",
276
- ctx
277
- );
278
- }
279
- if (code === "LIMIT_EXCEEDED_ENTITIES" || code === "LIMIT_EXCEEDED_ATTRIBUTES" || code === "LIMIT_EXCEEDED_RECORDS") {
280
- return new LimitExceededError(
281
- message ?? "EAV limit exceeded",
282
- code,
283
- ctx
284
- );
285
- }
286
- if (code === "AUTH_USER_NOT_FOUND") {
287
- return new AuthUserNotFoundError(
288
- message ?? "Auth user not found in this brandapp",
289
- 422,
290
- ctx
291
- );
292
- }
293
- return new ReoptSDKError(
294
- message ?? `Request failed with status ${status}`,
295
- 422,
296
- code ?? "REQUEST_ERROR",
297
- ctx
298
- );
299
- case 429:
300
- return new RateLimitError(message ?? "Rate limit exceeded");
301
- default:
302
- if (status >= 500) {
303
- return new ServerError(message ?? "Internal server error");
304
- }
305
- return new ReoptSDKError(
306
- message ?? `Unexpected status: ${status}`,
307
- status,
308
- code ?? "UNEXPECTED_ERROR",
309
- ctx
310
- );
311
- }
312
- }
313
-
314
- // src/core/config.ts
315
- var SDK_VERSION = "3.1.0" ;
316
- var REOPT_BASE_URLS = {
317
- production: "https://brandapp.reopt.ai",
318
- development: "https://brand.reopt.de:3443"
319
- };
320
- var REOPT_ID_BASE_URLS = {
321
- production: "https://id.reopt.ai",
322
- development: "https://id.reopt.de:3443"
323
- };
324
- function validateConfig(config) {
325
- const hasToken = !!config.token?.trim();
326
- if (!hasToken) {
327
- if (!config.clientId?.trim()) {
328
- throw new ConfigError(
329
- "ReoptSDK: clientId is required (or pass a short-lived `token`). Set BRANDAPP_CLIENT_ID environment variable.",
330
- "BRANDAPP_CLIENT_ID"
331
- );
332
- }
333
- if (!config.clientSecret?.trim()) {
334
- throw new ConfigError(
335
- "ReoptSDK: clientSecret is required (or pass a short-lived `token`). Set BRANDAPP_CLIENT_SECRET environment variable.",
336
- "BRANDAPP_CLIENT_SECRET"
337
- );
338
- }
339
- }
340
- if (!config.brandappId?.trim()) {
341
- throw new ConfigError(
342
- "ReoptSDK: brandappId is required. Set BRANDAPP_ID environment variable.",
343
- "BRANDAPP_ID"
344
- );
345
- }
346
- if (/[\s/?#]/.test(config.brandappId)) {
347
- throw new ConfigInvalidError(
348
- "ReoptSDK: brandappId contains invalid characters (whitespace, '/', '?', or '#'). Use the BrandApp ID exactly as shown in Studio.",
349
- "BRANDAPP_ID"
350
- );
351
- }
352
- assertValidUrl(config.baseUrl, "baseUrl", "REOPT_BASE_URL");
353
- assertValidUrl(config.idBaseUrl, "idBaseUrl", "REOPT_ID_BASE_URL");
354
- }
355
- function assertBrowserSafe(config) {
356
- if (typeof window !== "undefined" && config.clientSecret) {
357
- throw new ReoptSDKError(
358
- "[@reopt-ai/brandapp-sdk] clientSecret must not be used in the browser. It is a long-lived admin credential \u2014 exposing it client-side leaks full app access. Construct the SDK on the server with clientId/clientSecret, or for client-side use mint a short-lived token on your server (POST /api/v1/brandapp/{id}/token/mint) and pass it as `{ token }`.",
359
- 0,
360
- "CONFIG_BROWSER_SECRET",
361
- void 0,
362
- {
363
- cause: "\uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C clientSecret \uC0AC\uC6A9 \u2014 \uC790\uACA9\uC99D\uBA85 \uC720\uCD9C \uC704\uD5D8",
364
- fix: "\uC11C\uBC84\uC5D0\uC11C \uB2E8\uAE30 \uD1A0\uD070\uC744 \uBC1C\uAE09\uD574 `{ token }`\uC73C\uB85C \uC804\uB2EC (clientSecret \uBBF8\uD3EC\uD568)",
365
- doc: "docs/environment.md"
366
- }
367
- );
368
- }
369
- }
370
- function assertValidUrl(value, field, envVar) {
371
- if (value == null) return;
372
- try {
373
- new URL(value);
374
- } catch {
375
- throw new ConfigInvalidError(
376
- `ReoptSDK: ${field} is not a valid URL: "${value}". Use an absolute URL like "https://brandapp.reopt.ai".`,
377
- envVar
378
- );
379
- }
380
- }
381
- var ConfigError = class extends ReoptSDKError {
382
- constructor(message, envVar) {
383
- super(message, 0, "CONFIG_MISSING", void 0, {
384
- cause: `${envVar} \uD658\uACBD\uBCC0\uC218\uAC00 \uC124\uC815\uB418\uC9C0 \uC54A\uC74C`,
385
- fix: `.env \uD30C\uC77C\uC5D0 ${envVar}=... \uCD94\uAC00. \uAC12\uC740 Studio \u2192 BrandApp \u2192 \uC124\uC815 \u2192 OAuth \uD074\uB77C\uC774\uC5B8\uD2B8\uC5D0\uC11C \uD655\uC778`,
386
- envVar,
387
- doc: "docs/errors.md#config_missing"
388
- });
389
- }
390
- };
391
- var ConfigInvalidError = class extends ReoptSDKError {
392
- constructor(message, envVar) {
393
- super(message, 0, "CONFIG_INVALID", void 0, {
394
- cause: `${envVar} \uAC12\uC758 \uD615\uC2DD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC74C`,
395
- fix: "Studio \u2192 BrandApp \u2192 \uC124\uC815\uC5D0\uC11C \uAC12\uC744 \uB2E4\uC2DC \uBCF5\uC0AC\uD558\uAC70\uB098, URL\uC740 \uC808\uB300 \uACBD\uB85C(https://...)\uB85C \uC9C0\uC815",
396
- envVar,
397
- doc: "docs/errors.md#config_invalid"
398
- });
399
- }
400
- };
401
- function readEnvUrl(name) {
402
- if (typeof process === "undefined") return void 0;
403
- const raw = process.env?.[name];
404
- if (!raw) return void 0;
405
- return raw.replace(/\/$/, "");
406
- }
407
- function resolveBaseUrl(config) {
408
- if (config.baseUrl) return config.baseUrl.replace(/\/$/, "");
409
- const envBaseUrl = readEnvUrl("REOPT_BASE_URL");
410
- if (envBaseUrl) return envBaseUrl;
411
- const isProduction = config.isProduction ?? (typeof process !== "undefined" && process.env?.NODE_ENV === "production");
412
- return isProduction ? REOPT_BASE_URLS.production : REOPT_BASE_URLS.development;
413
- }
414
- function resolveIdBaseUrl(config) {
415
- if (config.idBaseUrl) return config.idBaseUrl.replace(/\/$/, "");
416
- const envIdBaseUrl = readEnvUrl("REOPT_ID_BASE_URL");
417
- if (envIdBaseUrl) return envIdBaseUrl;
418
- if (config.baseUrl) return deriveIdFromBaseUrl(config.baseUrl);
419
- const envBaseUrl = readEnvUrl("REOPT_BASE_URL");
420
- if (envBaseUrl) return deriveIdFromBaseUrl(envBaseUrl);
421
- const isProduction = config.isProduction ?? (typeof process !== "undefined" && process.env?.NODE_ENV === "production");
422
- return isProduction ? REOPT_ID_BASE_URLS.production : REOPT_ID_BASE_URLS.development;
423
- }
424
- function deriveIdFromBaseUrl(baseUrl) {
425
- const clean = baseUrl.replace(/\/$/, "");
426
- try {
427
- const url = new URL(clean);
428
- const { hostname } = url;
429
- if (hostname === "reopt.ai" || hostname.endsWith(".reopt.ai")) {
430
- return REOPT_ID_BASE_URLS.production;
431
- }
432
- if (hostname === "reopt.io" || hostname.endsWith(".reopt.io")) {
433
- return "https://id.reopt.io";
434
- }
435
- if (hostname === "reopt.de" || hostname.endsWith(".reopt.de")) {
436
- return REOPT_ID_BASE_URLS.development;
437
- }
438
- if (hostname.startsWith("id.")) return url.origin;
439
- url.hostname = `id.${hostname.replace(/^www\./, "")}`;
440
- return url.origin;
441
- } catch {
442
- return clean;
443
- }
444
- }
445
-
446
- // src/core/encoding.ts
447
- function encodeBase64(str) {
448
- const bytes = new TextEncoder().encode(str);
449
- const binString = Array.from(bytes, (b) => String.fromCodePoint(b)).join("");
450
- return btoa(binString);
451
- }
452
- function createBasicAuthHeader(clientId, clientSecret) {
453
- return `Basic ${encodeBase64(`${clientId}:${clientSecret}`)}`;
454
- }
455
- function createAuthHeader(config) {
456
- if (config.token && config.token.length > 0) return `Bearer ${config.token}`;
457
- return createBasicAuthHeader(
458
- config.clientId ?? "",
459
- config.clientSecret ?? ""
460
- );
461
- }
462
-
463
- export { AuthError, AuthUserNotFoundError, AuthUserRecordExistsError, BadRequestError, ConflictError, ContentFilterError, CreditLimitError, DuplicateAuthUserError, ForbiddenError, LimitExceededError, ModelAccessError, ModelNotFoundError, NotFoundError, REOPT_BASE_URLS, RateLimitError, ReoptSDKError, RequiredTermsError, SDK_VERSION, ServerError, ValidationError, assertBrowserSafe, createAuthHeader, isCreditLimitError, isModelAccessError, isReoptSDKError, isRequiredTermsError, isValidationError, mapHttpStatusToError, resolveBaseUrl, resolveIdBaseUrl, validateConfig };
464
- //# sourceMappingURL=chunk-MRQY45U5.js.map
465
- //# sourceMappingURL=chunk-MRQY45U5.js.map