@reopt-ai/brandapp-sdk 3.4.0 → 3.6.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 (65) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +2 -0
  3. package/dist/ai/index.d.ts +1 -1
  4. package/dist/ai/index.js +1 -1
  5. package/dist/ai-provider/index.js +1 -1
  6. package/dist/auth/index.d.ts +1 -1
  7. package/dist/auth/index.js +1 -1
  8. package/dist/better-auth/index.d.ts +1 -1
  9. package/dist/better-auth/index.js +2 -2
  10. package/dist/client-A4YrHjDc.d.ts +272 -0
  11. package/dist/{client-D-yNxNfk.js → client-B84P9y2F.js} +2 -2
  12. package/dist/{client-DPmoKuR9.js → client-BFM7OGqI.js} +4 -4
  13. package/dist/{client-D3RHHUUW.d.ts → client-BGLDrf3N.d.ts} +12 -8
  14. package/dist/{client-DDw5yz_h.d.ts → client-BTS6Ewv_.d.ts} +2 -2
  15. package/dist/{client-BGGd_cpV.d.ts → client-CAGo56KO.d.ts} +2 -2
  16. package/dist/{client-B1q5P8rv.js → client-C_YUxs_X.js} +2 -2
  17. package/dist/{client-Beivhucf.js → client-CiCPE2MW.js} +3 -3
  18. package/dist/{client-BruP5_nU.d.ts → client-Ckm-i_Du.d.ts} +2 -2
  19. package/dist/{client-DBnK7ooQ.js → client-CxyXO_0C.js} +2 -2
  20. package/dist/{client-EbhUIhHq.js → client-D4Z2xj4t.js} +2 -2
  21. package/dist/{client-lk6wBu_0.d.ts → client-DHZ484kb.d.ts} +3 -3
  22. package/dist/{client-D0eBxh8j.d.ts → client-DPbXH8tr.d.ts} +2 -2
  23. package/dist/{client-DsdakibF.js → client-DVydvzc2.js} +3 -3
  24. package/dist/{client-D6gs61w8.d.ts → client-DfEeaOsQ.d.ts} +2 -2
  25. package/dist/{client-B9QHVhdM.js → client-WP3Xsxri.js} +11 -7
  26. package/dist/client-m29R8F0R.js +273 -0
  27. package/dist/{client-Dxg8_DIH.d.ts → client-yBQen4Yi.d.ts} +2 -2
  28. package/dist/cms/index.d.ts +1 -1
  29. package/dist/cms/index.js +1 -1
  30. package/dist/{config-Cw0a3-C8.js → config-BV8Fn7Uo.js} +2 -2
  31. package/dist/{config-CRytOPPl.d.ts → config-C7WQtC3l.d.ts} +3 -1
  32. package/dist/dev/index.d.ts +1 -1
  33. package/dist/dev/index.js +351 -6
  34. package/dist/eav/index.d.ts +2 -2
  35. package/dist/eav/index.js +2 -2
  36. package/dist/eav/migrate.d.ts +2 -2
  37. package/dist/eav/schema.d.ts +2 -2
  38. package/dist/feedback/index.d.ts +1 -1
  39. package/dist/feedback/index.js +1 -1
  40. package/dist/files/index.d.ts +2 -2
  41. package/dist/files/index.js +1 -1
  42. package/dist/{http-client-QKUvvirs.js → http-client-6XUgrg3k.js} +2 -2
  43. package/dist/{index-Z6OGcurJ.d.ts → index-CvNJ8zp1.d.ts} +11 -11
  44. package/dist/{index-DrVaKfhs.d.ts → index-DV_OWwx5.d.ts} +16 -2
  45. package/dist/index.d.ts +4 -4
  46. package/dist/index.js +11 -11
  47. package/dist/logout/index.d.ts +1 -1
  48. package/dist/logout/index.js +1 -1
  49. package/dist/plans/index.d.ts +1 -1
  50. package/dist/plans/index.js +1 -1
  51. package/dist/push/index.d.ts +1 -1
  52. package/dist/push/index.js +1 -1
  53. package/dist/{query-BvbCiGWb.js → query-C98fDfVW.js} +2 -2
  54. package/dist/react/hooks.d.ts +64 -5
  55. package/dist/react/hooks.js +121 -3
  56. package/dist/terms/index.d.ts +2 -2
  57. package/dist/terms/index.js +1 -1
  58. package/dist/testing/index.d.ts +2 -2
  59. package/dist/{types-BrghN2rJ.d.ts → types-C69OzBn6.d.ts} +2 -2
  60. package/docs/api-reference.md +41 -2
  61. package/docs/errors.md +19 -0
  62. package/docs/files.md +165 -7
  63. package/package.json +2 -2
  64. package/dist/client-BJcy1V1a.js +0 -140
  65. package/dist/client-p49ol9pg.d.ts +0 -124
package/dist/dev/index.js CHANGED
@@ -20,6 +20,7 @@ var InMemoryStore = class {
20
20
  authAccounts = /* @__PURE__ */ new Map();
21
21
  authVerifications = /* @__PURE__ */ new Map();
22
22
  files = /* @__PURE__ */ new Map();
23
+ folders = /* @__PURE__ */ new Map();
23
24
  posts = /* @__PURE__ */ new Map();
24
25
  postGroups = /* @__PURE__ */ new Map();
25
26
  terms = /* @__PURE__ */ new Map();
@@ -72,6 +73,7 @@ var InMemoryStore = class {
72
73
  authAccounts: clone(this.authAccounts.values()),
73
74
  authVerifications: clone(this.authVerifications.values()),
74
75
  files: clone(this.files.values()),
76
+ folders: clone(this.folders.values()),
75
77
  posts: clone(this.posts.values()),
76
78
  postGroups: clone(this.postGroups.values()),
77
79
  terms: clone(this.terms.values()),
@@ -131,8 +133,15 @@ var InMemoryStore = class {
131
133
  for (const f of snapshot.files) {
132
134
  f.createdAt = toDate(f.createdAt);
133
135
  f.updatedAt = toDate(f.updatedAt);
136
+ f.folderId = f.folderId ?? null;
134
137
  this.files.set(f.id, f);
135
138
  }
139
+ for (const folder of snapshot.folders ?? []) {
140
+ folder.createdAt = toDate(folder.createdAt);
141
+ folder.updatedAt = toDate(folder.updatedAt);
142
+ folder.parentId = folder.parentId ?? null;
143
+ this.folders.set(folder.id, folder);
144
+ }
136
145
  for (const p of snapshot.posts) {
137
146
  p.createdAt = toDate(p.createdAt);
138
147
  p.updatedAt = toDate(p.updatedAt);
@@ -200,6 +209,7 @@ var InMemoryStore = class {
200
209
  this.authAccounts.clear();
201
210
  this.authVerifications.clear();
202
211
  this.files.clear();
212
+ this.folders.clear();
203
213
  this.posts.clear();
204
214
  this.postGroups.clear();
205
215
  this.terms.clear();
@@ -400,9 +410,12 @@ function sortRecords(records, sortBy, sortOrder) {
400
410
  });
401
411
  return sorted;
402
412
  }
403
- function transformRecord(record) {
413
+ function transformRecord(record, selectedAttributeIds) {
404
414
  const values = {};
405
- for (const v of record.values) values[v.attributeId] = parseStoredValue(v.value);
415
+ for (const v of record.values) {
416
+ if (selectedAttributeIds && !selectedAttributeIds.has(v.attributeId)) continue;
417
+ values[v.attributeId] = parseStoredValue(v.value);
418
+ }
406
419
  return {
407
420
  id: record.id,
408
421
  entityId: record.entityId,
@@ -421,6 +434,16 @@ function parseFilters(filtersJson) {
421
434
  return [];
422
435
  }
423
436
  }
437
+ function parseSelectedAttributeIds(selectJson) {
438
+ if (selectJson === void 0) return void 0;
439
+ try {
440
+ const parsed = JSON.parse(selectJson);
441
+ if (!Array.isArray(parsed) || parsed.length > 100 || parsed.some((value) => typeof value !== "string" || value.length === 0 || value.length > 200)) return null;
442
+ return new Set(parsed);
443
+ } catch {
444
+ return null;
445
+ }
446
+ }
424
447
  function createEavRoutes(store, brandappId) {
425
448
  const app = new Hono();
426
449
  app.get("/entities", (c) => {
@@ -651,6 +674,14 @@ function createEavRoutes(store, brandappId) {
651
674
  const sortBy = c.req.query("sortBy");
652
675
  const sortOrder = c.req.query("sortOrder") || "desc";
653
676
  const filtersJson = c.req.query("filters");
677
+ const selectedAttributeIds = parseSelectedAttributeIds(c.req.query("select"));
678
+ if (selectedAttributeIds === null) return c.json({
679
+ ok: false,
680
+ error: {
681
+ code: "VALIDATION_ERROR",
682
+ message: "select must be a JSON array containing at most 100 attribute IDs"
683
+ }
684
+ }, 400);
654
685
  let records = store.getRecordsByEntity(entityId);
655
686
  if (authUserId) records = records.filter((r) => r.brandappAuthUserId === authUserId);
656
687
  records = filterRecords(records, parseFilters(filtersJson));
@@ -660,7 +691,7 @@ function createEavRoutes(store, brandappId) {
660
691
  return c.json({
661
692
  ok: true,
662
693
  data: {
663
- records: paged.map(transformRecord),
694
+ records: paged.map((record) => transformRecord(record, selectedAttributeIds)),
664
695
  total,
665
696
  page,
666
697
  limit,
@@ -1064,6 +1095,14 @@ function createEavRoutes(store, brandappId) {
1064
1095
  const page = Number(c.req.query("page") || "1");
1065
1096
  const limit = Math.min(Number(c.req.query("limit") || "50"), 100);
1066
1097
  const sortOrder = c.req.query("sortOrder") || "desc";
1098
+ const selectedAttributeIds = parseSelectedAttributeIds(c.req.query("select"));
1099
+ if (selectedAttributeIds === null) return c.json({
1100
+ ok: false,
1101
+ error: {
1102
+ code: "VALIDATION_ERROR",
1103
+ message: "select must be a JSON array containing at most 100 attribute IDs"
1104
+ }
1105
+ }, 400);
1067
1106
  const entityIds = new Set(store.getEntitiesByBrandapp(brandappId).map((e) => e.id));
1068
1107
  let records = store.findMany(store.records, (r) => r.brandappAuthUserId === authUserId && entityIds.has(r.entityId));
1069
1108
  records = sortRecords(records, "createdAt", sortOrder);
@@ -1072,7 +1111,7 @@ function createEavRoutes(store, brandappId) {
1072
1111
  return c.json({
1073
1112
  ok: true,
1074
1113
  data: {
1075
- records: paged.map(transformRecord),
1114
+ records: paged.map((record) => transformRecord(record, selectedAttributeIds)),
1076
1115
  total,
1077
1116
  page,
1078
1117
  limit,
@@ -1375,6 +1414,15 @@ function createAiRoutes() {
1375
1414
  * `ok()` helpers): `{ data, meta? }` for success and `{ error: { code,
1376
1415
  * message } }` for failures — so the SDK's `FileListResponse` type and its
1377
1416
  * `sdk.files.get()` / `sdk.files.upload()` unwrappers work unchanged.
1417
+ *
1418
+ * Endpoint parity with `apps/web/server/hono/routes/brandapp-files.ts`:
1419
+ * GET / — list (?folderId=, contentType incl. wildcard)
1420
+ * GET /usage — storage usage (in-memory size sum)
1421
+ * GET /:fileId — detail
1422
+ * GET /:fileId/content — text content read (text whitelist + 1MB cap)
1423
+ * PATCH /:fileId — rename / move
1424
+ * DELETE /:fileId — delete
1425
+ * POST /upload — upload (folderId form field supported)
1378
1426
  */
1379
1427
  function toFileInfo(f) {
1380
1428
  return {
@@ -1384,17 +1432,51 @@ function toFileInfo(f) {
1384
1432
  size: f.size,
1385
1433
  contentType: f.contentType,
1386
1434
  pathname: `dev/${f.id}/${f.name}`,
1435
+ folderId: f.folderId,
1387
1436
  createdAt: f.createdAt.toISOString(),
1388
1437
  updatedAt: f.updatedAt.toISOString()
1389
1438
  };
1390
1439
  }
1440
+ /** production `contentTypeWhere` 미러 — "image/*" 와일드카드 = prefix 매치 */
1441
+ function matchesContentType(fileType, filter) {
1442
+ if (!filter) return true;
1443
+ if (filter.endsWith("/*")) return fileType.startsWith(filter.slice(0, -1));
1444
+ return fileType === filter;
1445
+ }
1446
+ /** production `isTextReadableContentType` 미러 */
1447
+ const TEXT_READABLE_MIME = /* @__PURE__ */ new Set([
1448
+ "application/json",
1449
+ "application/x-ndjson",
1450
+ "application/javascript",
1451
+ "application/typescript",
1452
+ "application/yaml",
1453
+ "application/x-yaml",
1454
+ "application/toml"
1455
+ ]);
1456
+ function isTextReadableContentType(contentType) {
1457
+ const base = (contentType ?? "").split(";")[0]?.trim().toLowerCase() ?? "";
1458
+ if (!base) return false;
1459
+ if (base.startsWith("text/")) return true;
1460
+ return TEXT_READABLE_MIME.has(base);
1461
+ }
1462
+ const MAX_TEXT_CONTENT_SIZE = 1024 * 1024;
1391
1463
  function createFilesRoutes(store, brandappId) {
1392
1464
  const fileContents = /* @__PURE__ */ new Map();
1393
1465
  const app = new Hono();
1394
1466
  app.get("/", (c) => {
1395
1467
  const page = Number(c.req.query("page") || "1");
1396
1468
  const limit = Math.min(Number(c.req.query("limit") || "50"), 100);
1397
- const files = store.findMany(store.files, (f) => f.brandappId === brandappId).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
1469
+ const contentType = c.req.query("contentType");
1470
+ const folderIdRaw = c.req.query("folderId");
1471
+ const files = store.findMany(store.files, (f) => {
1472
+ if (f.brandappId !== brandappId) return false;
1473
+ if (!matchesContentType(f.contentType, contentType)) return false;
1474
+ if (folderIdRaw !== void 0) {
1475
+ const wanted = folderIdRaw === "" ? null : folderIdRaw;
1476
+ if (f.folderId !== wanted) return false;
1477
+ }
1478
+ return true;
1479
+ }).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
1398
1480
  const total = files.length;
1399
1481
  const paged = files.slice((page - 1) * limit, page * limit);
1400
1482
  return c.json({
@@ -1406,6 +1488,15 @@ function createFilesRoutes(store, brandappId) {
1406
1488
  }
1407
1489
  });
1408
1490
  });
1491
+ app.get("/usage", (c) => {
1492
+ const files = store.findMany(store.files, (f) => f.brandappId === brandappId);
1493
+ const usedBytes = files.reduce((sum, f) => sum + f.size, 0);
1494
+ return c.json({ data: {
1495
+ usedBytes,
1496
+ limitBytes: null,
1497
+ fileCount: files.length
1498
+ } });
1499
+ });
1409
1500
  app.get("/:fileId", (c) => {
1410
1501
  const fileId = c.req.param("fileId");
1411
1502
  const file = store.files.get(fileId);
@@ -1415,13 +1506,83 @@ function createFilesRoutes(store, brandappId) {
1415
1506
  } }, 404);
1416
1507
  return c.json({ data: toFileInfo(file) });
1417
1508
  });
1509
+ app.get("/:fileId/content", (c) => {
1510
+ const fileId = c.req.param("fileId");
1511
+ const file = store.files.get(fileId);
1512
+ if (!file || file.brandappId !== brandappId) return c.json({ error: {
1513
+ code: "NOT_FOUND",
1514
+ message: "File not found"
1515
+ } }, 404);
1516
+ if (!isTextReadableContentType(file.contentType)) return c.json({ error: {
1517
+ code: "UNSUPPORTED_CONTENT_TYPE",
1518
+ message: `Content read is only supported for text files (got: ${file.contentType || "unknown"})`
1519
+ } }, 415);
1520
+ if (file.size > MAX_TEXT_CONTENT_SIZE) return c.json({ error: {
1521
+ code: "CONTENT_TOO_LARGE",
1522
+ message: "File exceeds content read limit of 1MB"
1523
+ } }, 413);
1524
+ const buffer = fileContents.get(fileId);
1525
+ if (!buffer) return c.json({ error: {
1526
+ code: "NOT_FOUND",
1527
+ message: "File content not found"
1528
+ } }, 404);
1529
+ const baseType = file.contentType.split(";")[0]?.trim() || "text/plain";
1530
+ return c.newResponse(new TextDecoder().decode(buffer), 200, {
1531
+ "Content-Type": `${baseType}; charset=utf-8`,
1532
+ "X-Content-Type-Options": "nosniff"
1533
+ });
1534
+ });
1535
+ app.patch("/:fileId", async (c) => {
1536
+ const fileId = c.req.param("fileId");
1537
+ const file = store.files.get(fileId);
1538
+ if (!file || file.brandappId !== brandappId) return c.json({ error: {
1539
+ code: "NOT_FOUND",
1540
+ message: "File not found"
1541
+ } }, 404);
1542
+ let body;
1543
+ try {
1544
+ body = await c.req.json();
1545
+ } catch {
1546
+ return c.json({ error: {
1547
+ code: "BAD_REQUEST",
1548
+ message: "Invalid JSON body"
1549
+ } }, 400);
1550
+ }
1551
+ const hasName = body.name !== void 0;
1552
+ const hasFolderId = body.folderId !== void 0;
1553
+ if (!hasName && !hasFolderId) return c.json({ error: {
1554
+ code: "BAD_REQUEST",
1555
+ message: "At least one of \"name\" or \"folderId\" is required"
1556
+ } }, 400);
1557
+ if (hasName && (typeof body.name !== "string" || !body.name.trim())) return c.json({ error: {
1558
+ code: "BAD_REQUEST",
1559
+ message: "Invalid name"
1560
+ } }, 400);
1561
+ if (hasFolderId && body.folderId !== null) {
1562
+ if (typeof body.folderId !== "string") return c.json({ error: {
1563
+ code: "BAD_REQUEST",
1564
+ message: "Invalid folderId"
1565
+ } }, 400);
1566
+ const folder = store.folders.get(body.folderId);
1567
+ if (!folder || folder.brandappId !== brandappId) return c.json({ error: {
1568
+ code: "NOT_FOUND",
1569
+ message: "Folder not found"
1570
+ } }, 404);
1571
+ }
1572
+ if (hasName) file.name = body.name.trim();
1573
+ if (hasFolderId) file.folderId = body.folderId;
1574
+ file.updatedAt = store.now();
1575
+ return c.json({ data: toFileInfo(file) });
1576
+ });
1418
1577
  app.post("/upload", async (c) => {
1419
1578
  const contentType = c.req.header("content-type") || "";
1420
1579
  let name = "untitled";
1421
1580
  let fileContentType = "application/octet-stream";
1581
+ let folderId = null;
1422
1582
  let buffer;
1423
1583
  if (contentType.includes("multipart/form-data")) {
1424
- const file = (await c.req.formData()).get("file");
1584
+ const formData = await c.req.formData();
1585
+ const file = formData.get("file");
1425
1586
  if (!file) return c.json({ error: {
1426
1587
  code: "VALIDATION_ERROR",
1427
1588
  message: "No file provided"
@@ -1429,6 +1590,15 @@ function createFilesRoutes(store, brandappId) {
1429
1590
  name = file.name;
1430
1591
  fileContentType = file.type || "application/octet-stream";
1431
1592
  buffer = await file.arrayBuffer();
1593
+ const folderIdField = formData.get("folderId");
1594
+ if (typeof folderIdField === "string" && folderIdField.length > 0) {
1595
+ const folder = store.folders.get(folderIdField);
1596
+ if (!folder || folder.brandappId !== brandappId) return c.json({ error: {
1597
+ code: "NOT_FOUND",
1598
+ message: "Folder not found"
1599
+ } }, 404);
1600
+ folderId = folder.id;
1601
+ }
1432
1602
  } else {
1433
1603
  buffer = await c.req.arrayBuffer();
1434
1604
  name = c.req.query("name") || "untitled";
@@ -1442,6 +1612,7 @@ function createFilesRoutes(store, brandappId) {
1442
1612
  contentType: fileContentType,
1443
1613
  size: buffer.byteLength,
1444
1614
  url: `http://localhost/dev-files/${store.generateId()}`,
1615
+ folderId,
1445
1616
  createdAt: now,
1446
1617
  updatedAt: now
1447
1618
  };
@@ -1463,6 +1634,178 @@ function createFilesRoutes(store, brandappId) {
1463
1634
  return app;
1464
1635
  }
1465
1636
 
1637
+ //#endregion
1638
+ //#region src/dev/folders-handler.ts
1639
+ /**
1640
+ * Folders Handler for Dev Server
1641
+ *
1642
+ * In-memory mirror of `apps/web/server/hono/routes/brandapp-folders.ts`:
1643
+ * GET / — direct children (?parentId=, empty/absent = root)
1644
+ * POST / — create { name, parentId? } (sibling name conflict → 409)
1645
+ * PATCH /:folderId — rename + move (self/descendant move → 400)
1646
+ * DELETE /:folderId — delete (non-empty → 409 FOLDER_NOT_EMPTY)
1647
+ */
1648
+ function toFolderInfo(store, folder) {
1649
+ const childCount = store.count(store.folders, (f) => f.brandappId === folder.brandappId && f.parentId === folder.id);
1650
+ const fileCount = store.count(store.files, (f) => f.brandappId === folder.brandappId && f.folderId === folder.id);
1651
+ return {
1652
+ id: folder.id,
1653
+ name: folder.name,
1654
+ parentId: folder.parentId,
1655
+ childCount,
1656
+ fileCount,
1657
+ createdAt: folder.createdAt.toISOString(),
1658
+ updatedAt: folder.updatedAt.toISOString()
1659
+ };
1660
+ }
1661
+ /** production `wouldCreateFolderCycle` 미러 — 조상 체인 역주행 */
1662
+ function wouldCreateCycle(store, folderId, newParentId) {
1663
+ let cursor = newParentId;
1664
+ let guard = 0;
1665
+ while (cursor && guard < 1e4) {
1666
+ if (cursor === folderId) return true;
1667
+ cursor = store.folders.get(cursor)?.parentId ?? null;
1668
+ guard++;
1669
+ }
1670
+ return false;
1671
+ }
1672
+ function hasSiblingNameConflict(store, brandappId, parentId, name, excludeId) {
1673
+ return store.findFirst(store.folders, (f) => f.brandappId === brandappId && f.parentId === parentId && f.name === name && f.id !== excludeId) !== null;
1674
+ }
1675
+ function createFoldersRoutes(store, brandappId) {
1676
+ const app = new Hono();
1677
+ app.get("/", (c) => {
1678
+ const parentIdRaw = c.req.query("parentId");
1679
+ const parentId = parentIdRaw ? parentIdRaw : null;
1680
+ if (parentId && !isScopedFolder(store, brandappId, parentId)) return c.json({ error: {
1681
+ code: "NOT_FOUND",
1682
+ message: "Folder not found"
1683
+ } }, 404);
1684
+ const folders = store.findMany(store.folders, (f) => f.brandappId === brandappId && f.parentId === parentId).sort((a, b) => a.name.localeCompare(b.name));
1685
+ return c.json({ data: folders.map((f) => toFolderInfo(store, f)) });
1686
+ });
1687
+ app.post("/", async (c) => {
1688
+ let body;
1689
+ try {
1690
+ body = await c.req.json();
1691
+ } catch {
1692
+ return c.json({ error: {
1693
+ code: "BAD_REQUEST",
1694
+ message: "Invalid JSON body"
1695
+ } }, 400);
1696
+ }
1697
+ const name = typeof body.name === "string" ? body.name.trim() : "";
1698
+ if (!name || name.length > 255) return c.json({ error: {
1699
+ code: "BAD_REQUEST",
1700
+ message: "Invalid folder name"
1701
+ } }, 400);
1702
+ let parentId = null;
1703
+ if (body.parentId != null) {
1704
+ if (typeof body.parentId !== "string" || !isScopedFolder(store, brandappId, body.parentId)) return c.json({ error: {
1705
+ code: "NOT_FOUND",
1706
+ message: "Parent folder not found"
1707
+ } }, 404);
1708
+ parentId = body.parentId;
1709
+ }
1710
+ if (hasSiblingNameConflict(store, brandappId, parentId, name)) return c.json({ error: {
1711
+ code: "CONFLICT",
1712
+ message: "A folder with the same name already exists here"
1713
+ } }, 409);
1714
+ const now = store.now();
1715
+ const folder = {
1716
+ id: store.generateId(),
1717
+ brandappId,
1718
+ name,
1719
+ parentId,
1720
+ createdAt: now,
1721
+ updatedAt: now
1722
+ };
1723
+ store.folders.set(folder.id, folder);
1724
+ return c.json({ data: toFolderInfo(store, folder) }, 201);
1725
+ });
1726
+ app.patch("/:folderId", async (c) => {
1727
+ const folderId = c.req.param("folderId");
1728
+ const folder = store.folders.get(folderId);
1729
+ if (!folder || folder.brandappId !== brandappId) return c.json({ error: {
1730
+ code: "NOT_FOUND",
1731
+ message: "Folder not found"
1732
+ } }, 404);
1733
+ let body;
1734
+ try {
1735
+ body = await c.req.json();
1736
+ } catch {
1737
+ return c.json({ error: {
1738
+ code: "BAD_REQUEST",
1739
+ message: "Invalid JSON body"
1740
+ } }, 400);
1741
+ }
1742
+ const hasName = body.name !== void 0;
1743
+ const hasParentId = body.parentId !== void 0;
1744
+ if (!hasName && !hasParentId) return c.json({ error: {
1745
+ code: "BAD_REQUEST",
1746
+ message: "At least one of \"name\" or \"parentId\" is required"
1747
+ } }, 400);
1748
+ let nextName = folder.name;
1749
+ if (hasName) {
1750
+ nextName = typeof body.name === "string" ? body.name.trim() : "";
1751
+ if (!nextName || nextName.length > 255) return c.json({ error: {
1752
+ code: "BAD_REQUEST",
1753
+ message: "Invalid folder name"
1754
+ } }, 400);
1755
+ }
1756
+ let nextParentId = folder.parentId;
1757
+ if (hasParentId) if (body.parentId === null) nextParentId = null;
1758
+ else {
1759
+ if (typeof body.parentId !== "string") return c.json({ error: {
1760
+ code: "BAD_REQUEST",
1761
+ message: "Invalid parentId"
1762
+ } }, 400);
1763
+ if (body.parentId === folderId) return c.json({ error: {
1764
+ code: "BAD_REQUEST",
1765
+ message: "Cannot move a folder into itself"
1766
+ } }, 400);
1767
+ if (!isScopedFolder(store, brandappId, body.parentId)) return c.json({ error: {
1768
+ code: "NOT_FOUND",
1769
+ message: "Parent folder not found"
1770
+ } }, 404);
1771
+ if (wouldCreateCycle(store, folderId, body.parentId)) return c.json({ error: {
1772
+ code: "BAD_REQUEST",
1773
+ message: "Cannot move a folder into its own descendant"
1774
+ } }, 400);
1775
+ nextParentId = body.parentId;
1776
+ }
1777
+ if (hasSiblingNameConflict(store, brandappId, nextParentId, nextName, folderId)) return c.json({ error: {
1778
+ code: "CONFLICT",
1779
+ message: "A folder with the same name already exists here"
1780
+ } }, 409);
1781
+ folder.name = nextName;
1782
+ folder.parentId = nextParentId;
1783
+ folder.updatedAt = store.now();
1784
+ return c.json({ data: toFolderInfo(store, folder) });
1785
+ });
1786
+ app.delete("/:folderId", (c) => {
1787
+ const folderId = c.req.param("folderId");
1788
+ const folder = store.folders.get(folderId);
1789
+ if (!folder || folder.brandappId !== brandappId) return c.json({ error: {
1790
+ code: "NOT_FOUND",
1791
+ message: "Folder not found"
1792
+ } }, 404);
1793
+ const childCount = store.count(store.folders, (f) => f.brandappId === brandappId && f.parentId === folderId);
1794
+ const fileCount = store.count(store.files, (f) => f.brandappId === brandappId && f.folderId === folderId);
1795
+ if (childCount > 0 || fileCount > 0) return c.json({ error: {
1796
+ code: "FOLDER_NOT_EMPTY",
1797
+ message: `Folder is not empty: ${fileCount} file(s), ${childCount} subfolder(s). Move or delete the contents first`
1798
+ } }, 409);
1799
+ store.folders.delete(folderId);
1800
+ return c.json({ data: { deleted: true } });
1801
+ });
1802
+ return app;
1803
+ }
1804
+ function isScopedFolder(store, brandappId, folderId) {
1805
+ const folder = store.folders.get(folderId);
1806
+ return !!folder && folder.brandappId === brandappId;
1807
+ }
1808
+
1466
1809
  //#endregion
1467
1810
  //#region src/dev/cms-handler.ts
1468
1811
  /**
@@ -2440,12 +2783,14 @@ async function createDevServer(options = {}) {
2440
2783
  app.route(`${basePath}/auth`, routeFor("auth", createAuthRoutes(store, brandappId)));
2441
2784
  app.route(`${basePath}/ai`, routeFor("ai", createAiRoutes()));
2442
2785
  app.route(`${basePath}/files`, routeFor("files", createFilesRoutes(store, brandappId)));
2786
+ app.route(`${basePath}/folders`, routeFor("files", createFoldersRoutes(store, brandappId)));
2443
2787
  app.route(`${basePath}/cms`, routeFor("cms", createCmsRoutes(store, brandappId)));
2444
2788
  app.route(`${basePath}/terms`, routeFor("terms", createTermsRoutes(store, brandappId)));
2445
2789
  app.route("/api/v1/brandapp/:brandappId/eav", routeFor("eav", createEavRoutes(store, brandappId)));
2446
2790
  app.route("/api/v1/brandapp/:brandappId/auth", routeFor("auth", createAuthRoutes(store, brandappId)));
2447
2791
  app.route("/api/v1/brandapp/:brandappId/ai", routeFor("ai", createAiRoutes()));
2448
2792
  app.route("/api/v1/brandapp/:brandappId/files", routeFor("files", createFilesRoutes(store, brandappId)));
2793
+ app.route("/api/v1/brandapp/:brandappId/folders", routeFor("files", createFoldersRoutes(store, brandappId)));
2449
2794
  app.route("/api/v1/brandapp/:brandappId/cms", routeFor("cms", createCmsRoutes(store, brandappId)));
2450
2795
  app.route("/api/v1/brandapp/:brandappId/terms", routeFor("terms", createTermsRoutes(store, brandappId)));
2451
2796
  app.get("/", (c) => {
@@ -1,6 +1,6 @@
1
- import { A as UpdateEntityInput, C as EavEntity, D as ListRecordsQuery, E as EavValidation, M as UpsertRecordInput, N as UpsertRecordResult, O as PaginatedResponse, S as EavDataType, T as EavSchemaLinkedTo, _ as CreateEntityInput, b as EavAttribute, d as AttributeFilterOperator, g as CreateAttributeInput, h as CountRecordsQuery, j as UpdateRecordInput, k as UpdateAttributeInput, m as BulkUpdateItem, n as ReoptSDKConfig, u as AttributeFilter, v as CreateRecordInput, w as EavRecord, x as EavAttributeOption, y as DeleteWhereInput } from "../config-CRytOPPl.js";
1
+ import { A as UpdateEntityInput, C as EavEntity, D as ListRecordsQuery, E as EavValidation, M as UpsertRecordInput, N as UpsertRecordResult, O as PaginatedResponse, S as EavDataType, T as EavSchemaLinkedTo, _ as CreateEntityInput, b as EavAttribute, d as AttributeFilterOperator, g as CreateAttributeInput, h as CountRecordsQuery, j as UpdateRecordInput, k as UpdateAttributeInput, m as BulkUpdateItem, n as ReoptSDKConfig, u as AttributeFilter, v as CreateRecordInput, w as EavRecord, x as EavAttributeOption, y as DeleteWhereInput } from "../config-C7WQtC3l.js";
2
2
  import { c as DuplicateAuthUserError, f as LimitExceededError, n as AuthUserNotFoundError, r as AuthUserRecordExistsError } from "../errors-CRCcErNC.js";
3
- import { i as TypedEavRecord, n as createReoptEavClient, r as EntityClient, t as ReoptEavClient } from "../client-BGGd_cpV.js";
3
+ import { i as TypedEavRecord, n as createReoptEavClient, r as EntityClient, t as ReoptEavClient } from "../client-CAGo56KO.js";
4
4
  //#region src/eav/verify.d.ts
5
5
  /**
6
6
  * Runtime drift check between a deployed bundle and the live server schema
package/dist/eav/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { c as AuthUserNotFoundError, g as LimitExceededError, l as AuthUserRecordExistsError, m as DuplicateAuthUserError } from "../config-Cw0a3-C8.js";
2
- import { t as createReoptEavClient } from "../client-DsdakibF.js";
1
+ import { c as AuthUserNotFoundError, g as LimitExceededError, l as AuthUserRecordExistsError, m as DuplicateAuthUserError } from "../config-BV8Fn7Uo.js";
2
+ import { t as createReoptEavClient } from "../client-DVydvzc2.js";
3
3
 
4
4
  //#region src/eav/verify.ts
5
5
  async function verifyEavSchema(input) {
@@ -1,5 +1,5 @@
1
- import { o as AttributeDef, s as EntityDef } from "../config-CRytOPPl.js";
2
- import { t as ReoptEavClient } from "../client-BGGd_cpV.js";
1
+ import { o as AttributeDef, s as EntityDef } from "../config-C7WQtC3l.js";
2
+ import { t as ReoptEavClient } from "../client-CAGo56KO.js";
3
3
  //#region src/eav/migrate/types.d.ts
4
4
  /**
5
5
  * Subset of `ReoptEavClient.records` exposed inside a migration's `up`/`down`.
@@ -1,5 +1,5 @@
1
- import { C as EavEntity, S as EavDataType, b as EavAttribute, c as InferValues, l as SchemaDef, o as AttributeDef, s as EntityDef } from "../config-CRytOPPl.js";
2
- import { t as ReoptEavClient } from "../client-BGGd_cpV.js";
1
+ import { C as EavEntity, S as EavDataType, b as EavAttribute, c as InferValues, l as SchemaDef, o as AttributeDef, s as EntityDef } from "../config-C7WQtC3l.js";
2
+ import { t as ReoptEavClient } from "../client-CAGo56KO.js";
3
3
  //#region src/eav/schema/define.d.ts
4
4
  declare function defineEntity<const A extends Record<string, AttributeDef>>(def: EntityDef<A>): EntityDef<A>;
5
5
  declare function defineSchema<const E extends Record<string, EntityDef>>(def: SchemaDef<E>): SchemaDef<E>;
@@ -1,2 +1,2 @@
1
- import { a as CreateFeedbackResult, c as FeedbackListMeta, d as FeedbackReplyAuthor, f as FeedbackStatus, i as CreateFeedbackReplyResult, l as FeedbackListResult, m as RateFeedbackReplyResult, n as createReoptFeedbackClient, o as Feedback, p as ListFeedbackQuery, r as CreateFeedbackInput, s as FeedbackDetail, t as ReoptFeedbackClient, u as FeedbackReply } from "../client-BruP5_nU.js";
1
+ import { a as CreateFeedbackResult, c as FeedbackListMeta, d as FeedbackReplyAuthor, f as FeedbackStatus, i as CreateFeedbackReplyResult, l as FeedbackListResult, m as RateFeedbackReplyResult, n as createReoptFeedbackClient, o as Feedback, p as ListFeedbackQuery, r as CreateFeedbackInput, s as FeedbackDetail, t as ReoptFeedbackClient, u as FeedbackReply } from "../client-Ckm-i_Du.js";
2
2
  export { type CreateFeedbackInput, type CreateFeedbackReplyResult, type CreateFeedbackResult, type Feedback, type FeedbackDetail, type FeedbackListMeta, type FeedbackListResult, type FeedbackReply, type FeedbackReplyAuthor, type FeedbackStatus, type ListFeedbackQuery, type RateFeedbackReplyResult, ReoptFeedbackClient, createReoptFeedbackClient };
@@ -1,3 +1,3 @@
1
- import { n as createReoptFeedbackClient, t as ReoptFeedbackClient } from "../client-DBnK7ooQ.js";
1
+ import { n as createReoptFeedbackClient, t as ReoptFeedbackClient } from "../client-CxyXO_0C.js";
2
2
 
3
3
  export { ReoptFeedbackClient, createReoptFeedbackClient };
@@ -1,4 +1,4 @@
1
- import { a as FileListResponse, i as FileListQuery, n as createReoptFileClient, o as UploadOptions, r as FileInfo, t as ReoptFileClient } from "../client-p49ol9pg.js";
1
+ import { a as FileListQuery, c as FolderInfo, d as UpdateFolderInput, f as UploadOptions, i as FileInfo, l as FolderListQuery, n as createReoptFileClient, o as FileListResponse, r as CreateFolderInput, s as FileUsageInfo, t as ReoptFileClient, u as UpdateFileInput } from "../client-A4YrHjDc.js";
2
2
  //#region src/files/helpers.d.ts
3
3
  /**
4
4
  * 이미지 URL 헬퍼 — Next.js `<Image>`와 결합해 사용.
@@ -50,5 +50,5 @@ declare function optimizeUrl(src: string, opts: OptimizeUrlOptions): string;
50
50
  */
51
51
  declare function createImageLoader(defaults?: OptimizeUrlOptions): ({ src, width, quality }: ImageLoaderArgs) => string;
52
52
  //#endregion
53
- export { type FileInfo, type FileListQuery, type FileListResponse, type ImageLoaderArgs, type ImageRemotePattern, type OptimizeUrlOptions, REOPT_IMAGE_REMOTE_PATTERNS, ReoptFileClient, type UploadOptions, createImageLoader, createReoptFileClient, optimizeUrl };
53
+ export { type CreateFolderInput, type FileInfo, type FileListQuery, type FileListResponse, type FileUsageInfo, type FolderInfo, type FolderListQuery, type ImageLoaderArgs, type ImageRemotePattern, type OptimizeUrlOptions, REOPT_IMAGE_REMOTE_PATTERNS, ReoptFileClient, type UpdateFileInput, type UpdateFolderInput, type UploadOptions, createImageLoader, createReoptFileClient, optimizeUrl };
54
54
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { n as createReoptFileClient, t as ReoptFileClient } from "../client-BJcy1V1a.js";
1
+ import { n as createReoptFileClient, t as ReoptFileClient } from "../client-m29R8F0R.js";
2
2
 
3
3
  //#region src/files/helpers.ts
4
4
  const REOPT_IMAGE_REMOTE_PATTERNS = [{
@@ -1,4 +1,4 @@
1
- import { A as mapHttpStatusToError, C as ServerError, a as resolveIdBaseUrl, b as RateLimitError, i as resolveBaseUrl, n as SDK_VERSION, o as validateConfig, x as ReoptSDKError } from "./config-Cw0a3-C8.js";
1
+ import { A as mapHttpStatusToError, C as ServerError, a as resolveIdBaseUrl, b as RateLimitError, i as resolveBaseUrl, n as SDK_VERSION, o as validateConfig, x as ReoptSDKError } from "./config-BV8Fn7Uo.js";
2
2
  import { t as createAuthHeader } from "./encoding-Bwfm3iaE.js";
3
3
 
4
4
  //#region src/core/debug.ts
@@ -383,4 +383,4 @@ function parseFieldErrors(body) {
383
383
 
384
384
  //#endregion
385
385
  export { parseFieldErrors as n, BaseHttpClient as t };
386
- //# sourceMappingURL=http-client-QKUvvirs.js.map
386
+ //# sourceMappingURL=http-client-6XUgrg3k.js.map
@@ -1,13 +1,13 @@
1
- import { l as SchemaDef, n as ReoptSDKConfig } from "./config-CRytOPPl.js";
2
- import { t as ReoptAiClient } from "./client-D0eBxh8j.js";
3
- import { t as ReoptAuthClient } from "./client-Dxg8_DIH.js";
4
- import { t as ReoptCmsClient } from "./client-DDw5yz_h.js";
5
- import { t as ReoptEavClient } from "./client-BGGd_cpV.js";
6
- import { t as ReoptFeedbackClient } from "./client-BruP5_nU.js";
7
- import { t as ReoptFileClient } from "./client-p49ol9pg.js";
8
- import { t as ReoptPlansClient } from "./client-D3RHHUUW.js";
9
- import { t as ReoptPushClient } from "./client-D6gs61w8.js";
10
- import { t as ReoptTermsClient } from "./client-lk6wBu_0.js";
1
+ import { l as SchemaDef, n as ReoptSDKConfig } from "./config-C7WQtC3l.js";
2
+ import { t as ReoptAiClient } from "./client-DPbXH8tr.js";
3
+ import { t as ReoptAuthClient } from "./client-yBQen4Yi.js";
4
+ import { t as ReoptCmsClient } from "./client-BTS6Ewv_.js";
5
+ import { t as ReoptEavClient } from "./client-CAGo56KO.js";
6
+ import { t as ReoptFeedbackClient } from "./client-Ckm-i_Du.js";
7
+ import { t as ReoptFileClient } from "./client-A4YrHjDc.js";
8
+ import { t as ReoptPlansClient } from "./client-BGLDrf3N.js";
9
+ import { t as ReoptPushClient } from "./client-DfEeaOsQ.js";
10
+ import { t as ReoptTermsClient } from "./client-DHZ484kb.js";
11
11
  //#region src/core/http-client.d.ts
12
12
  type FetchOptions = {
13
13
  /** Abort the request via an external AbortSignal (merged with timeout signal). */
@@ -166,4 +166,4 @@ type ReoptSDK<S extends SchemaDef = SchemaDef> = {
166
166
  declare function createReoptSDK<S extends SchemaDef = SchemaDef>(config: ReoptSDKConfig<S>): ReoptSDK<S>;
167
167
  //#endregion
168
168
  export { initReoptSDK as a, getReoptSDK as i, createReoptSDK as n, resetSDK as o, createLazySDK as r, BaseHttpClient as s, ReoptSDK as t };
169
- //# sourceMappingURL=index-Z6OGcurJ.d.ts.map
169
+ //# sourceMappingURL=index-CvNJ8zp1.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { n as EditorSpec } from "./types-BXDcoJHG.js";
2
- import { c as TermsJurisdiction } from "./types-BrghN2rJ.js";
2
+ import { c as TermsJurisdiction } from "./types-C69OzBn6.js";
3
3
  //#region src/dev/store.d.ts
4
4
  type DevEntity = {
5
5
  id: string;
@@ -94,6 +94,17 @@ type DevFile = {
94
94
  contentType: string;
95
95
  size: number;
96
96
  url: string;
97
+ /** 소속 폴더 ID (루트면 null) — production FileInfo.folderId 미러 */
98
+ folderId: string | null;
99
+ createdAt: Date;
100
+ updatedAt: Date;
101
+ };
102
+ /** production FolderInfo 미러 — 카운트는 응답 시점에 계산 */
103
+ type DevFolder = {
104
+ id: string;
105
+ brandappId: string;
106
+ name: string;
107
+ parentId: string | null;
97
108
  createdAt: Date;
98
109
  updatedAt: Date;
99
110
  };
@@ -205,6 +216,8 @@ type StoreSnapshot = {
205
216
  authAccounts: DevAuthAccount[];
206
217
  authVerifications: DevAuthVerification[];
207
218
  files: DevFile[];
219
+ /** 스냅샷 하위 호환 — 폴더 도입 전 스냅샷엔 없다 */
220
+ folders?: DevFolder[];
208
221
  posts: DevPost[];
209
222
  postGroups: DevPostGroup[];
210
223
  terms: DevTerms[];
@@ -220,6 +233,7 @@ declare class InMemoryStore {
220
233
  authAccounts: Map<string, DevAuthAccount>;
221
234
  authVerifications: Map<string, DevAuthVerification>;
222
235
  files: Map<string, DevFile>;
236
+ folders: Map<string, DevFolder>;
223
237
  posts: Map<string, DevPost>;
224
238
  postGroups: Map<string, DevPostGroup>;
225
239
  terms: Map<string, DevTerms>;
@@ -453,4 +467,4 @@ type DevServer = {
453
467
  declare function createDevServer(options?: DevServerOptions): Promise<DevServer>;
454
468
  //#endregion
455
469
  export { DevPost as _, SeedAllInput as a, InMemoryStore as b, SeedPostGroupInput as c, SeedTermsItem as d, createDevServer as f, DevEntity as g, DevAttribute as h, ProxyConfig as i, SeedPostInput as l, markdownToEditorSpecMany as m, DevServer as n, SeedData as o, markdownToEditorSpec as p, DevServerOptions as r, SeedOptions as s, DevSchema as t, SeedRecordInput as u, DevPostGroup as v, StoreSnapshot as x, DevRecord as y };
456
- //# sourceMappingURL=index-DrVaKfhs.d.ts.map
470
+ //# sourceMappingURL=index-DV_OWwx5.d.ts.map