@fluid-app/rep-core 0.1.14 → 0.1.16

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 (311) hide show
  1. package/dist/chunk-CKQMccvm.cjs +28 -0
  2. package/dist/data-sources/DataAwareWidget.cjs +47 -56
  3. package/dist/data-sources/DataAwareWidget.cjs.map +1 -1
  4. package/dist/data-sources/DataAwareWidget.d.cts +27 -19
  5. package/dist/data-sources/DataAwareWidget.d.cts.map +1 -0
  6. package/dist/data-sources/DataAwareWidget.d.mts +38 -0
  7. package/dist/data-sources/DataAwareWidget.d.mts.map +1 -0
  8. package/dist/data-sources/DataAwareWidget.mjs +48 -0
  9. package/dist/data-sources/DataAwareWidget.mjs.map +1 -0
  10. package/dist/data-sources/ErrorState.cjs +18 -10
  11. package/dist/data-sources/ErrorState.cjs.map +1 -1
  12. package/dist/data-sources/ErrorState.d.cts +5 -3
  13. package/dist/data-sources/ErrorState.d.cts.map +1 -0
  14. package/dist/data-sources/ErrorState.d.mts +7 -0
  15. package/dist/data-sources/ErrorState.d.mts.map +1 -0
  16. package/dist/data-sources/ErrorState.mjs +18 -0
  17. package/dist/data-sources/ErrorState.mjs.map +1 -0
  18. package/dist/data-sources/context.cjs +22 -14
  19. package/dist/data-sources/context.cjs.map +1 -1
  20. package/dist/data-sources/context.d.cts +16 -10
  21. package/dist/data-sources/context.d.cts.map +1 -0
  22. package/dist/data-sources/context.d.mts +22 -0
  23. package/dist/data-sources/context.d.mts.map +1 -0
  24. package/dist/data-sources/context.mjs +21 -0
  25. package/dist/data-sources/context.mjs.map +1 -0
  26. package/dist/data-sources/fetchers/api.cjs +63 -10
  27. package/dist/data-sources/fetchers/api.cjs.map +1 -1
  28. package/dist/data-sources/fetchers/api.d.cts +4 -2
  29. package/dist/data-sources/fetchers/api.d.cts.map +1 -0
  30. package/dist/data-sources/fetchers/api.d.mts +10 -0
  31. package/dist/data-sources/fetchers/api.d.mts.map +1 -0
  32. package/dist/data-sources/fetchers/api.mjs +64 -0
  33. package/dist/data-sources/fetchers/api.mjs.map +1 -0
  34. package/dist/data-sources/fetchers/custom.cjs +106 -10
  35. package/dist/data-sources/fetchers/custom.cjs.map +1 -1
  36. package/dist/data-sources/fetchers/custom.d.cts +4 -2
  37. package/dist/data-sources/fetchers/custom.d.cts.map +1 -0
  38. package/dist/data-sources/fetchers/{custom.d.ts → custom.d.mts} +4 -2
  39. package/dist/data-sources/fetchers/custom.d.mts.map +1 -0
  40. package/dist/data-sources/fetchers/custom.mjs +107 -0
  41. package/dist/data-sources/fetchers/custom.mjs.map +1 -0
  42. package/dist/data-sources/fetchers/static.cjs +159 -14
  43. package/dist/data-sources/fetchers/static.cjs.map +1 -1
  44. package/dist/data-sources/fetchers/static.d.cts +12 -10
  45. package/dist/data-sources/fetchers/static.d.cts.map +1 -0
  46. package/dist/data-sources/fetchers/{static.d.ts → static.d.mts} +12 -10
  47. package/dist/data-sources/fetchers/static.d.mts.map +1 -0
  48. package/dist/data-sources/fetchers/static.mjs +158 -0
  49. package/dist/data-sources/fetchers/static.mjs.map +1 -0
  50. package/dist/data-sources/preview-context.cjs +15 -15
  51. package/dist/data-sources/preview-context.cjs.map +1 -1
  52. package/dist/data-sources/preview-context.d.cts +10 -6
  53. package/dist/data-sources/preview-context.d.cts.map +1 -0
  54. package/dist/data-sources/preview-context.d.mts +15 -0
  55. package/dist/data-sources/preview-context.d.mts.map +1 -0
  56. package/dist/data-sources/preview-context.mjs +18 -0
  57. package/dist/data-sources/preview-context.mjs.map +1 -0
  58. package/dist/data-sources/registry-context.cjs +51 -24
  59. package/dist/data-sources/registry-context.cjs.map +1 -1
  60. package/dist/data-sources/registry-context.d.cts +30 -22
  61. package/dist/data-sources/registry-context.d.cts.map +1 -0
  62. package/dist/data-sources/registry-context.d.mts +49 -0
  63. package/dist/data-sources/registry-context.d.mts.map +1 -0
  64. package/dist/data-sources/registry-context.mjs +49 -0
  65. package/dist/data-sources/registry-context.mjs.map +1 -0
  66. package/dist/data-sources/registry.cjs +29 -18
  67. package/dist/data-sources/registry.cjs.map +1 -1
  68. package/dist/data-sources/registry.d.cts +9 -7
  69. package/dist/data-sources/registry.d.cts.map +1 -0
  70. package/dist/data-sources/registry.d.mts +19 -0
  71. package/dist/data-sources/registry.d.mts.map +1 -0
  72. package/dist/data-sources/registry.mjs +29 -0
  73. package/dist/data-sources/registry.mjs.map +1 -0
  74. package/dist/data-sources/transformers.cjs +152 -10
  75. package/dist/data-sources/transformers.cjs.map +1 -1
  76. package/dist/data-sources/transformers.d.cts +4 -17
  77. package/dist/data-sources/transformers.d.cts.map +1 -0
  78. package/dist/data-sources/transformers.d.mts +10 -0
  79. package/dist/data-sources/transformers.d.mts.map +1 -0
  80. package/dist/data-sources/transformers.mjs +153 -0
  81. package/dist/data-sources/transformers.mjs.map +1 -0
  82. package/dist/data-sources/types.cjs +0 -4
  83. package/dist/data-sources/types.d.cts +2 -157
  84. package/dist/data-sources/types.d.mts +2 -0
  85. package/dist/data-sources/types.mjs +1 -0
  86. package/dist/data-sources/use-widget-data.cjs +109 -17
  87. package/dist/data-sources/use-widget-data.cjs.map +1 -1
  88. package/dist/data-sources/use-widget-data.d.cts +9 -8
  89. package/dist/data-sources/use-widget-data.d.cts.map +1 -0
  90. package/dist/data-sources/use-widget-data.d.mts +17 -0
  91. package/dist/data-sources/use-widget-data.d.mts.map +1 -0
  92. package/dist/data-sources/use-widget-data.mjs +109 -0
  93. package/dist/data-sources/use-widget-data.mjs.map +1 -0
  94. package/dist/index-Bxe_LIi8.d.cts +287 -0
  95. package/dist/index-Bxe_LIi8.d.cts.map +1 -0
  96. package/dist/index-CCAu2n19.d.mts +287 -0
  97. package/dist/index-CCAu2n19.d.mts.map +1 -0
  98. package/dist/registries/index.cjs +212 -127
  99. package/dist/registries/index.cjs.map +1 -1
  100. package/dist/registries/index.d.cts +146 -149
  101. package/dist/registries/index.d.cts.map +1 -0
  102. package/dist/registries/{index.d.ts → index.d.mts} +146 -149
  103. package/dist/registries/index.d.mts.map +1 -0
  104. package/dist/registries/index.mjs +229 -0
  105. package/dist/registries/index.mjs.map +1 -0
  106. package/dist/shell/AppShellLayout.cjs +47 -12
  107. package/dist/shell/AppShellLayout.cjs.map +1 -1
  108. package/dist/shell/AppShellLayout.d.cts +29 -19
  109. package/dist/shell/AppShellLayout.d.cts.map +1 -0
  110. package/dist/shell/AppShellLayout.d.mts +40 -0
  111. package/dist/shell/AppShellLayout.d.mts.map +1 -0
  112. package/dist/shell/AppShellLayout.mjs +46 -0
  113. package/dist/{chunk-45BCVWQK.cjs.map → shell/AppShellLayout.mjs.map} +1 -1
  114. package/dist/shell/ScreenHeader.cjs +44 -0
  115. package/dist/shell/ScreenHeader.cjs.map +1 -0
  116. package/dist/shell/ScreenHeader.d.cts +12 -0
  117. package/dist/shell/ScreenHeader.d.cts.map +1 -0
  118. package/dist/shell/ScreenHeader.d.mts +12 -0
  119. package/dist/shell/ScreenHeader.d.mts.map +1 -0
  120. package/dist/shell/ScreenHeader.mjs +42 -0
  121. package/dist/shell/ScreenHeader.mjs.map +1 -0
  122. package/dist/shell/ScreenHeaderContext.cjs +91 -0
  123. package/dist/shell/ScreenHeaderContext.cjs.map +1 -0
  124. package/dist/shell/ScreenHeaderContext.d.cts +36 -0
  125. package/dist/shell/ScreenHeaderContext.d.cts.map +1 -0
  126. package/dist/shell/ScreenHeaderContext.d.mts +36 -0
  127. package/dist/shell/ScreenHeaderContext.d.mts.map +1 -0
  128. package/dist/shell/ScreenHeaderContext.mjs +86 -0
  129. package/dist/shell/ScreenHeaderContext.mjs.map +1 -0
  130. package/dist/shell/ThemeModeContext.cjs +68 -18
  131. package/dist/shell/ThemeModeContext.cjs.map +1 -1
  132. package/dist/shell/ThemeModeContext.d.cts +23 -16
  133. package/dist/shell/ThemeModeContext.d.cts.map +1 -0
  134. package/dist/shell/ThemeModeContext.d.mts +34 -0
  135. package/dist/shell/ThemeModeContext.d.mts.map +1 -0
  136. package/dist/shell/ThemeModeContext.mjs +66 -0
  137. package/dist/shell/ThemeModeContext.mjs.map +1 -0
  138. package/dist/shell/index.cjs +43 -205
  139. package/dist/shell/index.d.cts +7 -43
  140. package/dist/shell/index.d.mts +7 -0
  141. package/dist/shell/index.mjs +7 -0
  142. package/dist/shell/sidebar.cjs +372 -87
  143. package/dist/shell/sidebar.cjs.map +1 -1
  144. package/dist/shell/sidebar.d.cts +38 -36
  145. package/dist/shell/sidebar.d.cts.map +1 -0
  146. package/dist/shell/{sidebar.d.ts → sidebar.d.mts} +38 -36
  147. package/dist/shell/sidebar.d.mts.map +1 -0
  148. package/dist/shell/sidebar.mjs +364 -0
  149. package/dist/{chunk-PFDBULOI.cjs.map → shell/sidebar.mjs.map} +1 -1
  150. package/dist/shell/use-mobile.cjs +49 -18
  151. package/dist/shell/use-mobile.cjs.map +1 -1
  152. package/dist/shell/use-mobile.d.cts +3 -1
  153. package/dist/shell/use-mobile.d.cts.map +1 -0
  154. package/dist/shell/{use-mobile.d.ts → use-mobile.d.mts} +3 -1
  155. package/dist/shell/use-mobile.d.mts.map +1 -0
  156. package/dist/shell/use-mobile.mjs +47 -0
  157. package/dist/shell/use-mobile.mjs.map +1 -0
  158. package/dist/theme/index.cjs +663 -549
  159. package/dist/theme/index.cjs.map +1 -1
  160. package/dist/theme/index.d.cts +32 -32
  161. package/dist/theme/index.d.cts.map +1 -0
  162. package/dist/theme/{index.d.ts → index.d.mts} +32 -32
  163. package/dist/theme/index.d.mts.map +1 -0
  164. package/dist/theme/index.mjs +728 -0
  165. package/dist/theme/index.mjs.map +1 -0
  166. package/dist/types/index.cjs +18 -72
  167. package/dist/types/index.d.cts +4 -268
  168. package/dist/types/index.d.mts +4 -0
  169. package/dist/types/index.mjs +2 -0
  170. package/dist/types-BIXtQlHB.d.cts +155 -0
  171. package/dist/types-BIXtQlHB.d.cts.map +1 -0
  172. package/dist/types-BXFX9bXp.cjs +303 -0
  173. package/dist/types-BXFX9bXp.cjs.map +1 -0
  174. package/dist/types-Bjmd7Fdx.mjs +208 -0
  175. package/dist/types-Bjmd7Fdx.mjs.map +1 -0
  176. package/dist/types-ByG6Xy3C.d.mts +85 -0
  177. package/dist/types-ByG6Xy3C.d.mts.map +1 -0
  178. package/dist/types-C5OFJy-O.d.mts +155 -0
  179. package/dist/types-C5OFJy-O.d.mts.map +1 -0
  180. package/dist/types-Ctu-Zio6.d.cts +85 -0
  181. package/dist/types-Ctu-Zio6.d.cts.map +1 -0
  182. package/dist/{widget-schema-D-ca3--K.d.ts → widget-schema--PY1uMWx.d.cts} +38 -41
  183. package/dist/widget-schema--PY1uMWx.d.cts.map +1 -0
  184. package/dist/{widget-schema-DvJdg1-B.d.cts → widget-schema-YkD5p3v4.d.mts} +38 -41
  185. package/dist/widget-schema-YkD5p3v4.d.mts.map +1 -0
  186. package/dist/widget-utils/index.cjs +96 -89
  187. package/dist/widget-utils/index.cjs.map +1 -1
  188. package/dist/widget-utils/index.d.cts +8 -6
  189. package/dist/widget-utils/index.d.cts.map +1 -0
  190. package/dist/widget-utils/{index.d.ts → index.d.mts} +8 -6
  191. package/dist/widget-utils/index.d.mts.map +1 -0
  192. package/dist/widget-utils/index.mjs +119 -0
  193. package/dist/widget-utils/index.mjs.map +1 -0
  194. package/package.json +4 -4
  195. package/dist/chunk-2SPTFZRC.js +0 -72
  196. package/dist/chunk-2SPTFZRC.js.map +0 -1
  197. package/dist/chunk-3I5Y3PEO.js +0 -23
  198. package/dist/chunk-3I5Y3PEO.js.map +0 -1
  199. package/dist/chunk-3ZRE7GX6.js +0 -620
  200. package/dist/chunk-3ZRE7GX6.js.map +0 -1
  201. package/dist/chunk-45BCVWQK.cjs +0 -38
  202. package/dist/chunk-46PUWB7C.cjs +0 -69
  203. package/dist/chunk-46PUWB7C.cjs.map +0 -1
  204. package/dist/chunk-5NYM4UTW.cjs +0 -58
  205. package/dist/chunk-5NYM4UTW.cjs.map +0 -1
  206. package/dist/chunk-B2NTWEDF.cjs +0 -130
  207. package/dist/chunk-B2NTWEDF.cjs.map +0 -1
  208. package/dist/chunk-GDY76JA6.cjs +0 -153
  209. package/dist/chunk-GDY76JA6.cjs.map +0 -1
  210. package/dist/chunk-HGVSPZEL.cjs +0 -119
  211. package/dist/chunk-HGVSPZEL.cjs.map +0 -1
  212. package/dist/chunk-HIDJYVKJ.js +0 -54
  213. package/dist/chunk-HIDJYVKJ.js.map +0 -1
  214. package/dist/chunk-KTXGU7OP.cjs +0 -136
  215. package/dist/chunk-KTXGU7OP.cjs.map +0 -1
  216. package/dist/chunk-KW5E2H5T.js +0 -128
  217. package/dist/chunk-KW5E2H5T.js.map +0 -1
  218. package/dist/chunk-LBLHDGMT.js +0 -25
  219. package/dist/chunk-LBLHDGMT.js.map +0 -1
  220. package/dist/chunk-MNVDL4FX.js +0 -134
  221. package/dist/chunk-MNVDL4FX.js.map +0 -1
  222. package/dist/chunk-MOTOSPAO.cjs +0 -15
  223. package/dist/chunk-MOTOSPAO.cjs.map +0 -1
  224. package/dist/chunk-N2K6W7FX.cjs +0 -169
  225. package/dist/chunk-N2K6W7FX.cjs.map +0 -1
  226. package/dist/chunk-PFDBULOI.cjs +0 -665
  227. package/dist/chunk-PVTQWD4I.js +0 -166
  228. package/dist/chunk-PVTQWD4I.js.map +0 -1
  229. package/dist/chunk-SJQPHJL4.cjs +0 -26
  230. package/dist/chunk-SJQPHJL4.cjs.map +0 -1
  231. package/dist/chunk-TML66UEU.js +0 -13
  232. package/dist/chunk-TML66UEU.js.map +0 -1
  233. package/dist/chunk-U3CQLX2Z.cjs +0 -28
  234. package/dist/chunk-U3CQLX2Z.cjs.map +0 -1
  235. package/dist/chunk-UUNEVOA5.js +0 -36
  236. package/dist/chunk-UUNEVOA5.js.map +0 -1
  237. package/dist/chunk-VRF7QEID.js +0 -67
  238. package/dist/chunk-VRF7QEID.js.map +0 -1
  239. package/dist/chunk-VSZWXSQA.js +0 -38
  240. package/dist/chunk-VSZWXSQA.js.map +0 -1
  241. package/dist/chunk-WYOHFNNW.js +0 -117
  242. package/dist/chunk-WYOHFNNW.js.map +0 -1
  243. package/dist/chunk-YKF5ZFF5.js +0 -136
  244. package/dist/chunk-YKF5ZFF5.js.map +0 -1
  245. package/dist/chunk-YXJMBVXO.cjs +0 -76
  246. package/dist/chunk-YXJMBVXO.cjs.map +0 -1
  247. package/dist/chunk-ZA4AE7KF.cjs +0 -42
  248. package/dist/chunk-ZA4AE7KF.cjs.map +0 -1
  249. package/dist/data-sources/DataAwareWidget.d.ts +0 -30
  250. package/dist/data-sources/DataAwareWidget.js +0 -57
  251. package/dist/data-sources/DataAwareWidget.js.map +0 -1
  252. package/dist/data-sources/ErrorState.d.ts +0 -5
  253. package/dist/data-sources/ErrorState.js +0 -3
  254. package/dist/data-sources/ErrorState.js.map +0 -1
  255. package/dist/data-sources/context.d.ts +0 -16
  256. package/dist/data-sources/context.js +0 -3
  257. package/dist/data-sources/context.js.map +0 -1
  258. package/dist/data-sources/fetchers/api.d.ts +0 -8
  259. package/dist/data-sources/fetchers/api.js +0 -3
  260. package/dist/data-sources/fetchers/api.js.map +0 -1
  261. package/dist/data-sources/fetchers/custom.js +0 -3
  262. package/dist/data-sources/fetchers/custom.js.map +0 -1
  263. package/dist/data-sources/fetchers/static.js +0 -3
  264. package/dist/data-sources/fetchers/static.js.map +0 -1
  265. package/dist/data-sources/preview-context.d.ts +0 -11
  266. package/dist/data-sources/preview-context.js +0 -18
  267. package/dist/data-sources/preview-context.js.map +0 -1
  268. package/dist/data-sources/registry-context.d.ts +0 -41
  269. package/dist/data-sources/registry-context.js +0 -9
  270. package/dist/data-sources/registry-context.js.map +0 -1
  271. package/dist/data-sources/registry.d.ts +0 -17
  272. package/dist/data-sources/registry.js +0 -7
  273. package/dist/data-sources/registry.js.map +0 -1
  274. package/dist/data-sources/transformers.d.ts +0 -23
  275. package/dist/data-sources/transformers.js +0 -3
  276. package/dist/data-sources/transformers.js.map +0 -1
  277. package/dist/data-sources/types.cjs.map +0 -1
  278. package/dist/data-sources/types.d.ts +0 -157
  279. package/dist/data-sources/types.js +0 -3
  280. package/dist/data-sources/types.js.map +0 -1
  281. package/dist/data-sources/use-widget-data.d.ts +0 -16
  282. package/dist/data-sources/use-widget-data.js +0 -10
  283. package/dist/data-sources/use-widget-data.js.map +0 -1
  284. package/dist/registries/index.js +0 -144
  285. package/dist/registries/index.js.map +0 -1
  286. package/dist/shareable-item-DkgWpwoU.d.cts +0 -21
  287. package/dist/shareable-item-DkgWpwoU.d.ts +0 -21
  288. package/dist/shell/AppShellLayout.d.ts +0 -30
  289. package/dist/shell/AppShellLayout.js +0 -5
  290. package/dist/shell/AppShellLayout.js.map +0 -1
  291. package/dist/shell/ThemeModeContext.d.ts +0 -27
  292. package/dist/shell/ThemeModeContext.js +0 -3
  293. package/dist/shell/ThemeModeContext.js.map +0 -1
  294. package/dist/shell/index.cjs.map +0 -1
  295. package/dist/shell/index.d.ts +0 -43
  296. package/dist/shell/index.js +0 -76
  297. package/dist/shell/index.js.map +0 -1
  298. package/dist/shell/sidebar.js +0 -4
  299. package/dist/shell/sidebar.js.map +0 -1
  300. package/dist/shell/use-mobile.js +0 -3
  301. package/dist/shell/use-mobile.js.map +0 -1
  302. package/dist/theme/index.js +0 -611
  303. package/dist/theme/index.js.map +0 -1
  304. package/dist/types/index.cjs.map +0 -1
  305. package/dist/types/index.d.ts +0 -268
  306. package/dist/types/index.js +0 -3
  307. package/dist/types/index.js.map +0 -1
  308. package/dist/types-CNIhy4JD.d.cts +0 -83
  309. package/dist/types-CNIhy4JD.d.ts +0 -83
  310. package/dist/widget-utils/index.js +0 -111
  311. package/dist/widget-utils/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"api.cjs"}
1
+ {"version":3,"file":"api.cjs","names":[],"sources":["../../../src/data-sources/fetchers/api.ts"],"sourcesContent":["import type { ApiDataSource, DataSourceContext } from \"../types\";\n\n/**\n * Extracts a value from an object using dot notation path\n * e.g., getByPath({ data: { items: [1,2,3] } }, 'data.items') => [1,2,3]\n */\nfunction getByPath(obj: unknown, path: string): unknown {\n return path.split(\".\").reduce((current, key) => {\n if (current && typeof current === \"object\" && key in current) {\n return (current as Record<string, unknown>)[key];\n }\n return undefined;\n }, obj);\n}\n\n/**\n * Replaces {variable} placeholders in an endpoint path with values from the\n * variables map. E.g., \"/reps/{rep_id}/most_shared\" with { rep_id: \"42\" }\n * becomes \"/reps/42/most_shared\".\n */\nfunction interpolateVariables(\n endpoint: string,\n variables?: Record<string, string>,\n): string {\n if (!variables) return endpoint;\n const resolved = endpoint.replace(\n /\\{(\\w+)\\}/g,\n (match, key: string) => variables[key] ?? match,\n );\n const unresolved = resolved.match(/\\{(\\w+)\\}/g);\n if (unresolved) {\n console.warn(\n `[DataSource] Unresolved variable placeholders in endpoint: ${unresolved.join(\", \")}. ` +\n `Endpoint: \"${endpoint}\". Available variables: ${Object.keys(variables).join(\", \") || \"(none)\"}`,\n );\n }\n return resolved;\n}\n\n/**\n * Resolves the full URL for an endpoint.\n * - Substitutes {variable} placeholders from context variables\n * - Absolute URLs (starting with http:// or https://) are used as-is\n * - Relative paths are prefixed with the context's baseUrl\n */\nfunction resolveEndpointUrl(\n endpoint: string,\n baseUrl?: string,\n variables?: Record<string, string>,\n): string {\n const resolved = interpolateVariables(endpoint, variables);\n\n // If endpoint is already absolute, use it directly\n if (resolved.startsWith(\"http://\") || resolved.startsWith(\"https://\")) {\n return resolved;\n }\n\n // If we have a baseUrl, prepend it to the relative endpoint\n if (baseUrl) {\n // Ensure proper joining (no double slashes)\n const base = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n const path = resolved.startsWith(\"/\") ? resolved : `/${resolved}`;\n return `${base}${path}`;\n }\n\n // No baseUrl provided, return endpoint as-is (will likely fail for relative paths)\n return resolved;\n}\n\n/**\n * Default API fetcher implementation\n */\nexport async function apiFetcher(\n source: ApiDataSource,\n context: DataSourceContext,\n): Promise<unknown> {\n const { endpoint, method = \"GET\", headers = {}, body } = source;\n\n // Merge context variables with per-source variables (source overrides context)\n const mergedVariables = { ...context.variables, ...source.variables };\n\n // Resolve the full URL, substituting variables and using baseUrl for relative endpoints\n const url = resolveEndpointUrl(endpoint, context.baseUrl, mergedVariables);\n\n const fetchOptions: RequestInit = {\n method,\n headers: {\n \"content-type\": \"application/json\",\n ...context.getApiHeaders?.(),\n ...headers,\n },\n signal: context.signal,\n };\n\n if (body && (method === \"POST\" || method === \"PUT\")) {\n fetchOptions.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, fetchOptions);\n\n if (!response.ok) {\n throw new Error(\n `API request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n // Extract data at resultPath if specified\n if (source.resultPath) {\n return getByPath(data, source.resultPath);\n }\n\n return data;\n}\n"],"mappings":";;;;;;AAMA,SAAS,UAAU,KAAc,MAAuB;AACtD,QAAO,KAAK,MAAM,IAAI,CAAC,QAAQ,SAAS,QAAQ;AAC9C,MAAI,WAAW,OAAO,YAAY,YAAY,OAAO,QACnD,QAAQ,QAAoC;IAG7C,IAAI;;;;;;;AAQT,SAAS,qBACP,UACA,WACQ;AACR,KAAI,CAAC,UAAW,QAAO;CACvB,MAAM,WAAW,SAAS,QACxB,eACC,OAAO,QAAgB,UAAU,QAAQ,MAC3C;CACD,MAAM,aAAa,SAAS,MAAM,aAAa;AAC/C,KAAI,WACF,SAAQ,KACN,8DAA8D,WAAW,KAAK,KAAK,CAAC,eACpE,SAAS,0BAA0B,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,IAAI,WACzF;AAEH,QAAO;;;;;;;;AAST,SAAS,mBACP,UACA,SACA,WACQ;CACR,MAAM,WAAW,qBAAqB,UAAU,UAAU;AAG1D,KAAI,SAAS,WAAW,UAAU,IAAI,SAAS,WAAW,WAAW,CACnE,QAAO;AAIT,KAAI,QAIF,QAAO,GAFM,QAAQ,SAAS,IAAI,GAAG,QAAQ,MAAM,GAAG,GAAG,GAAG,UAC/C,SAAS,WAAW,IAAI,GAAG,WAAW,IAAI;AAKzD,QAAO;;;;;AAMT,eAAsB,WACpB,QACA,SACkB;CAClB,MAAM,EAAE,UAAU,SAAS,OAAO,UAAU,EAAE,EAAE,SAAS;CAGzD,MAAM,kBAAkB;EAAE,GAAG,QAAQ;EAAW,GAAG,OAAO;EAAW;CAGrE,MAAM,MAAM,mBAAmB,UAAU,QAAQ,SAAS,gBAAgB;CAE1E,MAAM,eAA4B;EAChC;EACA,SAAS;GACP,gBAAgB;GAChB,GAAG,QAAQ,iBAAiB;GAC5B,GAAG;GACJ;EACD,QAAQ,QAAQ;EACjB;AAED,KAAI,SAAS,WAAW,UAAU,WAAW,OAC3C,cAAa,OAAO,KAAK,UAAU,KAAK;CAG1C,MAAM,WAAW,MAAM,MAAM,KAAK,aAAa;AAE/C,KAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MACR,uBAAuB,SAAS,OAAO,GAAG,SAAS,aACpD;CAGH,MAAM,OAAO,MAAM,SAAS,MAAM;AAGlC,KAAI,OAAO,WACT,QAAO,UAAU,MAAM,OAAO,WAAW;AAG3C,QAAO"}
@@ -1,8 +1,10 @@
1
- import { ApiDataSource, DataSourceContext } from '../types.cjs';
1
+ import { o as DataSourceContext, t as ApiDataSource } from "../../types-BIXtQlHB.cjs";
2
2
 
3
+ //#region src/data-sources/fetchers/api.d.ts
3
4
  /**
4
5
  * Default API fetcher implementation
5
6
  */
6
7
  declare function apiFetcher(source: ApiDataSource, context: DataSourceContext): Promise<unknown>;
7
-
8
+ //#endregion
8
9
  export { apiFetcher };
10
+ //# sourceMappingURL=api.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.cts","names":[],"sources":["../../../src/data-sources/fetchers/api.ts"],"mappings":";;;;;AAwEA;iBAAsB,UAAA,CACpB,MAAA,EAAQ,aAAA,EACR,OAAA,EAAS,iBAAA,GACR,OAAA"}
@@ -0,0 +1,10 @@
1
+ import { o as DataSourceContext, t as ApiDataSource } from "../../types-C5OFJy-O.mjs";
2
+
3
+ //#region src/data-sources/fetchers/api.d.ts
4
+ /**
5
+ * Default API fetcher implementation
6
+ */
7
+ declare function apiFetcher(source: ApiDataSource, context: DataSourceContext): Promise<unknown>;
8
+ //#endregion
9
+ export { apiFetcher };
10
+ //# sourceMappingURL=api.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.mts","names":[],"sources":["../../../src/data-sources/fetchers/api.ts"],"mappings":";;;;;AAwEA;iBAAsB,UAAA,CACpB,MAAA,EAAQ,aAAA,EACR,OAAA,EAAS,iBAAA,GACR,OAAA"}
@@ -0,0 +1,64 @@
1
+ //#region src/data-sources/fetchers/api.ts
2
+ /**
3
+ * Extracts a value from an object using dot notation path
4
+ * e.g., getByPath({ data: { items: [1,2,3] } }, 'data.items') => [1,2,3]
5
+ */
6
+ function getByPath(obj, path) {
7
+ return path.split(".").reduce((current, key) => {
8
+ if (current && typeof current === "object" && key in current) return current[key];
9
+ }, obj);
10
+ }
11
+ /**
12
+ * Replaces {variable} placeholders in an endpoint path with values from the
13
+ * variables map. E.g., "/reps/{rep_id}/most_shared" with { rep_id: "42" }
14
+ * becomes "/reps/42/most_shared".
15
+ */
16
+ function interpolateVariables(endpoint, variables) {
17
+ if (!variables) return endpoint;
18
+ const resolved = endpoint.replace(/\{(\w+)\}/g, (match, key) => variables[key] ?? match);
19
+ const unresolved = resolved.match(/\{(\w+)\}/g);
20
+ if (unresolved) console.warn(`[DataSource] Unresolved variable placeholders in endpoint: ${unresolved.join(", ")}. Endpoint: "${endpoint}". Available variables: ${Object.keys(variables).join(", ") || "(none)"}`);
21
+ return resolved;
22
+ }
23
+ /**
24
+ * Resolves the full URL for an endpoint.
25
+ * - Substitutes {variable} placeholders from context variables
26
+ * - Absolute URLs (starting with http:// or https://) are used as-is
27
+ * - Relative paths are prefixed with the context's baseUrl
28
+ */
29
+ function resolveEndpointUrl(endpoint, baseUrl, variables) {
30
+ const resolved = interpolateVariables(endpoint, variables);
31
+ if (resolved.startsWith("http://") || resolved.startsWith("https://")) return resolved;
32
+ if (baseUrl) return `${baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl}${resolved.startsWith("/") ? resolved : `/${resolved}`}`;
33
+ return resolved;
34
+ }
35
+ /**
36
+ * Default API fetcher implementation
37
+ */
38
+ async function apiFetcher(source, context) {
39
+ const { endpoint, method = "GET", headers = {}, body } = source;
40
+ const mergedVariables = {
41
+ ...context.variables,
42
+ ...source.variables
43
+ };
44
+ const url = resolveEndpointUrl(endpoint, context.baseUrl, mergedVariables);
45
+ const fetchOptions = {
46
+ method,
47
+ headers: {
48
+ "content-type": "application/json",
49
+ ...context.getApiHeaders?.(),
50
+ ...headers
51
+ },
52
+ signal: context.signal
53
+ };
54
+ if (body && (method === "POST" || method === "PUT")) fetchOptions.body = JSON.stringify(body);
55
+ const response = await fetch(url, fetchOptions);
56
+ if (!response.ok) throw new Error(`API request failed: ${response.status} ${response.statusText}`);
57
+ const data = await response.json();
58
+ if (source.resultPath) return getByPath(data, source.resultPath);
59
+ return data;
60
+ }
61
+ //#endregion
62
+ export { apiFetcher };
63
+
64
+ //# sourceMappingURL=api.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.mjs","names":[],"sources":["../../../src/data-sources/fetchers/api.ts"],"sourcesContent":["import type { ApiDataSource, DataSourceContext } from \"../types\";\n\n/**\n * Extracts a value from an object using dot notation path\n * e.g., getByPath({ data: { items: [1,2,3] } }, 'data.items') => [1,2,3]\n */\nfunction getByPath(obj: unknown, path: string): unknown {\n return path.split(\".\").reduce((current, key) => {\n if (current && typeof current === \"object\" && key in current) {\n return (current as Record<string, unknown>)[key];\n }\n return undefined;\n }, obj);\n}\n\n/**\n * Replaces {variable} placeholders in an endpoint path with values from the\n * variables map. E.g., \"/reps/{rep_id}/most_shared\" with { rep_id: \"42\" }\n * becomes \"/reps/42/most_shared\".\n */\nfunction interpolateVariables(\n endpoint: string,\n variables?: Record<string, string>,\n): string {\n if (!variables) return endpoint;\n const resolved = endpoint.replace(\n /\\{(\\w+)\\}/g,\n (match, key: string) => variables[key] ?? match,\n );\n const unresolved = resolved.match(/\\{(\\w+)\\}/g);\n if (unresolved) {\n console.warn(\n `[DataSource] Unresolved variable placeholders in endpoint: ${unresolved.join(\", \")}. ` +\n `Endpoint: \"${endpoint}\". Available variables: ${Object.keys(variables).join(\", \") || \"(none)\"}`,\n );\n }\n return resolved;\n}\n\n/**\n * Resolves the full URL for an endpoint.\n * - Substitutes {variable} placeholders from context variables\n * - Absolute URLs (starting with http:// or https://) are used as-is\n * - Relative paths are prefixed with the context's baseUrl\n */\nfunction resolveEndpointUrl(\n endpoint: string,\n baseUrl?: string,\n variables?: Record<string, string>,\n): string {\n const resolved = interpolateVariables(endpoint, variables);\n\n // If endpoint is already absolute, use it directly\n if (resolved.startsWith(\"http://\") || resolved.startsWith(\"https://\")) {\n return resolved;\n }\n\n // If we have a baseUrl, prepend it to the relative endpoint\n if (baseUrl) {\n // Ensure proper joining (no double slashes)\n const base = baseUrl.endsWith(\"/\") ? baseUrl.slice(0, -1) : baseUrl;\n const path = resolved.startsWith(\"/\") ? resolved : `/${resolved}`;\n return `${base}${path}`;\n }\n\n // No baseUrl provided, return endpoint as-is (will likely fail for relative paths)\n return resolved;\n}\n\n/**\n * Default API fetcher implementation\n */\nexport async function apiFetcher(\n source: ApiDataSource,\n context: DataSourceContext,\n): Promise<unknown> {\n const { endpoint, method = \"GET\", headers = {}, body } = source;\n\n // Merge context variables with per-source variables (source overrides context)\n const mergedVariables = { ...context.variables, ...source.variables };\n\n // Resolve the full URL, substituting variables and using baseUrl for relative endpoints\n const url = resolveEndpointUrl(endpoint, context.baseUrl, mergedVariables);\n\n const fetchOptions: RequestInit = {\n method,\n headers: {\n \"content-type\": \"application/json\",\n ...context.getApiHeaders?.(),\n ...headers,\n },\n signal: context.signal,\n };\n\n if (body && (method === \"POST\" || method === \"PUT\")) {\n fetchOptions.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, fetchOptions);\n\n if (!response.ok) {\n throw new Error(\n `API request failed: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n // Extract data at resultPath if specified\n if (source.resultPath) {\n return getByPath(data, source.resultPath);\n }\n\n return data;\n}\n"],"mappings":";;;;;AAMA,SAAS,UAAU,KAAc,MAAuB;AACtD,QAAO,KAAK,MAAM,IAAI,CAAC,QAAQ,SAAS,QAAQ;AAC9C,MAAI,WAAW,OAAO,YAAY,YAAY,OAAO,QACnD,QAAQ,QAAoC;IAG7C,IAAI;;;;;;;AAQT,SAAS,qBACP,UACA,WACQ;AACR,KAAI,CAAC,UAAW,QAAO;CACvB,MAAM,WAAW,SAAS,QACxB,eACC,OAAO,QAAgB,UAAU,QAAQ,MAC3C;CACD,MAAM,aAAa,SAAS,MAAM,aAAa;AAC/C,KAAI,WACF,SAAQ,KACN,8DAA8D,WAAW,KAAK,KAAK,CAAC,eACpE,SAAS,0BAA0B,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,IAAI,WACzF;AAEH,QAAO;;;;;;;;AAST,SAAS,mBACP,UACA,SACA,WACQ;CACR,MAAM,WAAW,qBAAqB,UAAU,UAAU;AAG1D,KAAI,SAAS,WAAW,UAAU,IAAI,SAAS,WAAW,WAAW,CACnE,QAAO;AAIT,KAAI,QAIF,QAAO,GAFM,QAAQ,SAAS,IAAI,GAAG,QAAQ,MAAM,GAAG,GAAG,GAAG,UAC/C,SAAS,WAAW,IAAI,GAAG,WAAW,IAAI;AAKzD,QAAO;;;;;AAMT,eAAsB,WACpB,QACA,SACkB;CAClB,MAAM,EAAE,UAAU,SAAS,OAAO,UAAU,EAAE,EAAE,SAAS;CAGzD,MAAM,kBAAkB;EAAE,GAAG,QAAQ;EAAW,GAAG,OAAO;EAAW;CAGrE,MAAM,MAAM,mBAAmB,UAAU,QAAQ,SAAS,gBAAgB;CAE1E,MAAM,eAA4B;EAChC;EACA,SAAS;GACP,gBAAgB;GAChB,GAAG,QAAQ,iBAAiB;GAC5B,GAAG;GACJ;EACD,QAAQ,QAAQ;EACjB;AAED,KAAI,SAAS,WAAW,UAAU,WAAW,OAC3C,cAAa,OAAO,KAAK,UAAU,KAAK;CAG1C,MAAM,WAAW,MAAM,MAAM,KAAK,aAAa;AAE/C,KAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MACR,uBAAuB,SAAS,OAAO,GAAG,SAAS,aACpD;CAGH,MAAM,OAAO,MAAM,SAAS,MAAM;AAGlC,KAAI,OAAO,WACT,QAAO,UAAU,MAAM,OAAO,WAAW;AAG3C,QAAO"}
@@ -1,12 +1,108 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/data-sources/fetchers/custom.ts
3
+ /**
4
+ * Individual resource endpoints for each shareable type.
5
+ * These fetch single items by ID from the company API.
6
+ */
7
+ const SHAREABLE_ENDPOINTS = {
8
+ Medium: (id) => `/company/media/${id}`,
9
+ Page: (id) => `/company/pages/${id}`,
10
+ Library: (id) => `/company/libraries/${id}`,
11
+ Product: (id) => `/company/v1/products/${id}`,
12
+ EnrollmentPack: (id) => `/enrollment_packs/${id}`
13
+ };
14
+ /**
15
+ * Extract the actual resource data from various API response structures.
16
+ * Different endpoints wrap their data differently:
17
+ * - Product: { status, resource: { product: {...} } }
18
+ * - EnrollmentPack: { status, resource: { enrollment_pack: {...} } }
19
+ * - Medium/Page/Library: Direct root or { medium: {...} }
20
+ */
21
+ function extractResourceData(json, shareableType) {
22
+ const resource = json.resource;
23
+ if (resource) {
24
+ const typeKey = shareableType.toLowerCase().replace("pack", "_pack");
25
+ if (resource[typeKey]) return resource[typeKey];
26
+ if (resource.product) return resource.product;
27
+ if (resource.enrollment_pack) return resource.enrollment_pack;
28
+ }
29
+ const directKey = shareableType.toLowerCase().replace("pack", "_pack");
30
+ if (json[directKey]) return json[directKey];
31
+ if (json.data) return json.data;
32
+ if (json.medium) return json.medium;
33
+ if (json.page) return json.page;
34
+ if (json.library) return json.library;
35
+ if (json.product) return json.product;
36
+ if (json.enrollment_pack) return json.enrollment_pack;
37
+ return json;
38
+ }
39
+ /**
40
+ * Fetch a single shareable item by ID from the individual resource endpoint.
41
+ */
42
+ async function fetchSingleItem(item, signal, baseUrl = "", getApiHeaders) {
43
+ const getEndpoint = SHAREABLE_ENDPOINTS[item.shareableType];
44
+ if (!getEndpoint) return {
45
+ item,
46
+ data: null,
47
+ error: /* @__PURE__ */ new Error(`Unknown shareable type: ${item.shareableType}`)
48
+ };
49
+ const endpoint = `${baseUrl}${getEndpoint(item.id)}`;
50
+ try {
51
+ const response = await fetch(endpoint, {
52
+ method: "GET",
53
+ headers: {
54
+ ...getApiHeaders?.(),
55
+ "Content-Type": "application/json"
56
+ },
57
+ signal
58
+ });
59
+ if (!response.ok) return {
60
+ item,
61
+ data: null,
62
+ error: /* @__PURE__ */ new Error(`Failed to fetch ${item.shareableType} with ID ${item.id}: ${response.status}`)
63
+ };
64
+ const resourceData = extractResourceData(await response.json(), item.shareableType);
65
+ if (resourceData && typeof resourceData === "object") resourceData.shareable_type = item.shareableType;
66
+ return {
67
+ item,
68
+ data: resourceData
69
+ };
70
+ } catch (error) {
71
+ return {
72
+ item,
73
+ data: null,
74
+ error: error instanceof Error ? error : /* @__PURE__ */ new Error(`Unknown error fetching ${item.shareableType} ${item.id}`)
75
+ };
76
+ }
77
+ }
78
+ /**
79
+ * Custom fetcher that fetches selected items.
80
+ *
81
+ * Fetches items from individual resource endpoints using the configured
82
+ * getApiHeaders for authentication.
83
+ *
84
+ * Fetches all items in parallel for performance.
85
+ * Returns an array of successfully fetched items, preserving order.
86
+ * Logs warnings for failed fetches but doesn't throw.
87
+ */
88
+ async function customFetcher(source, context) {
89
+ const { selectedItems } = source;
90
+ if (!selectedItems || selectedItems.length === 0) return [];
91
+ const results = await Promise.all(selectedItems.map((item) => fetchSingleItem(item, context.signal, context.baseUrl, context.getApiHeaders)));
92
+ const successfulData = [];
93
+ const errors = [];
94
+ for (const result of results) {
95
+ if (result.error) {
96
+ console.warn(`[CustomFetcher] Failed to fetch ${result.item.shareableType} #${result.item.id}:`, result.error.message);
97
+ errors.push(result.error);
98
+ continue;
99
+ }
100
+ if (result.data) successfulData.push(result.data);
101
+ }
102
+ if (successfulData.length === 0 && errors.length > 0) throw new Error(`Failed to fetch all ${errors.length} item(s): ${errors[0]?.message || "Unknown error"}`);
103
+ return successfulData;
104
+ }
105
+ //#endregion
106
+ exports.customFetcher = customFetcher;
2
107
 
3
- var chunkHGVSPZEL_cjs = require('../../chunk-HGVSPZEL.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "customFetcher", {
8
- enumerable: true,
9
- get: function () { return chunkHGVSPZEL_cjs.customFetcher; }
10
- });
11
- //# sourceMappingURL=custom.cjs.map
12
108
  //# sourceMappingURL=custom.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"custom.cjs"}
1
+ {"version":3,"file":"custom.cjs","names":[],"sources":["../../../src/data-sources/fetchers/custom.ts"],"sourcesContent":["import type {\n CustomDataSource,\n DataSourceContext,\n SelectedItem,\n ShareableType,\n} from \"../types\";\n\n/**\n * Individual resource endpoints for each shareable type.\n * These fetch single items by ID from the company API.\n */\nconst SHAREABLE_ENDPOINTS: Record<\n ShareableType,\n (id: string | number) => string\n> = {\n Medium: (id) => `/company/media/${id}`,\n Page: (id) => `/company/pages/${id}`,\n Library: (id) => `/company/libraries/${id}`,\n Product: (id) => `/company/v1/products/${id}`,\n EnrollmentPack: (id) => `/enrollment_packs/${id}`,\n};\n\n/**\n * Extract the actual resource data from various API response structures.\n * Different endpoints wrap their data differently:\n * - Product: { status, resource: { product: {...} } }\n * - EnrollmentPack: { status, resource: { enrollment_pack: {...} } }\n * - Medium/Page/Library: Direct root or { medium: {...} }\n */\nfunction extractResourceData(\n json: Record<string, unknown>,\n shareableType: ShareableType,\n): Record<string, unknown> {\n // Try nested resource structure first (Product, EnrollmentPack)\n const resource = json.resource as Record<string, unknown> | undefined;\n if (resource) {\n // Check for type-specific key within resource\n const typeKey = shareableType.toLowerCase().replace(\"pack\", \"_pack\");\n if (resource[typeKey]) {\n return resource[typeKey] as Record<string, unknown>;\n }\n // Check common keys\n if (resource.product) return resource.product as Record<string, unknown>;\n if (resource.enrollment_pack)\n return resource.enrollment_pack as Record<string, unknown>;\n }\n\n // Try direct type key (e.g., { medium: {...} })\n const directKey = shareableType.toLowerCase().replace(\"pack\", \"_pack\");\n if (json[directKey]) {\n return json[directKey] as Record<string, unknown>;\n }\n\n // Try common response shapes\n if (json.data) return json.data as Record<string, unknown>;\n if (json.medium) return json.medium as Record<string, unknown>;\n if (json.page) return json.page as Record<string, unknown>;\n if (json.library) return json.library as Record<string, unknown>;\n if (json.product) return json.product as Record<string, unknown>;\n if (json.enrollment_pack)\n return json.enrollment_pack as Record<string, unknown>;\n\n // Return as-is if no wrapper found (Library uses direct serialization)\n return json;\n}\n\n/**\n * Result from fetching a single shareable item\n */\ninterface FetchResult {\n item: SelectedItem;\n data: unknown;\n error?: Error;\n}\n\n/**\n * Fetch a single shareable item by ID from the individual resource endpoint.\n */\nasync function fetchSingleItem(\n item: SelectedItem,\n signal: AbortSignal,\n baseUrl: string = \"\",\n getApiHeaders?: () => Record<string, string>,\n): Promise<FetchResult> {\n const getEndpoint = SHAREABLE_ENDPOINTS[item.shareableType];\n if (!getEndpoint) {\n return {\n item,\n data: null,\n error: new Error(`Unknown shareable type: ${item.shareableType}`),\n };\n }\n\n const endpoint = `${baseUrl}${getEndpoint(item.id)}`;\n\n try {\n const response = await fetch(endpoint, {\n method: \"GET\",\n headers: {\n ...getApiHeaders?.(),\n \"Content-Type\": \"application/json\",\n },\n signal,\n });\n\n if (!response.ok) {\n return {\n item,\n data: null,\n error: new Error(\n `Failed to fetch ${item.shareableType} with ID ${item.id}: ${response.status}`,\n ),\n };\n }\n\n const json = await response.json();\n\n // Extract the actual resource data from the response wrapper\n const resourceData = extractResourceData(json, item.shareableType);\n\n // Add shareable_type to the response for transformer compatibility\n if (resourceData && typeof resourceData === \"object\") {\n (resourceData as Record<string, unknown>).shareable_type =\n item.shareableType;\n }\n\n return { item, data: resourceData };\n } catch (error) {\n return {\n item,\n data: null,\n error:\n error instanceof Error\n ? error\n : new Error(\n `Unknown error fetching ${item.shareableType} ${item.id}`,\n ),\n };\n }\n}\n\n/**\n * Custom fetcher that fetches selected items.\n *\n * Fetches items from individual resource endpoints using the configured\n * getApiHeaders for authentication.\n *\n * Fetches all items in parallel for performance.\n * Returns an array of successfully fetched items, preserving order.\n * Logs warnings for failed fetches but doesn't throw.\n */\nexport async function customFetcher(\n source: CustomDataSource,\n context: DataSourceContext,\n): Promise<unknown[]> {\n const { selectedItems } = source;\n if (!selectedItems || selectedItems.length === 0) {\n return [];\n }\n\n // Fallback: fetch from individual endpoints (no auth)\n const results = await Promise.all(\n selectedItems.map((item) =>\n fetchSingleItem(\n item,\n context.signal,\n context.baseUrl,\n context.getApiHeaders,\n ),\n ),\n );\n\n // Process results, collecting successful data and tracking errors\n const successfulData: unknown[] = [];\n const errors: Error[] = [];\n\n for (const result of results) {\n if (result.error) {\n console.warn(\n `[CustomFetcher] Failed to fetch ${result.item.shareableType} #${result.item.id}:`,\n result.error.message,\n );\n errors.push(result.error);\n continue;\n }\n\n if (result.data) {\n successfulData.push(result.data);\n }\n }\n\n // Throw error if all fetches failed\n if (successfulData.length === 0 && errors.length > 0) {\n throw new Error(\n `Failed to fetch all ${errors.length} item(s): ${errors[0]?.message || \"Unknown error\"}`,\n );\n }\n\n return successfulData;\n}\n"],"mappings":";;;;;;AAWA,MAAM,sBAGF;CACF,SAAS,OAAO,kBAAkB;CAClC,OAAO,OAAO,kBAAkB;CAChC,UAAU,OAAO,sBAAsB;CACvC,UAAU,OAAO,wBAAwB;CACzC,iBAAiB,OAAO,qBAAqB;CAC9C;;;;;;;;AASD,SAAS,oBACP,MACA,eACyB;CAEzB,MAAM,WAAW,KAAK;AACtB,KAAI,UAAU;EAEZ,MAAM,UAAU,cAAc,aAAa,CAAC,QAAQ,QAAQ,QAAQ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cL,eAAsB,cACpB,QACA,SACoB;CACpB,MAAM,EAAE,kBAAkB;AAC1B,KAAI,CAAC,iBAAiB,cAAc,WAAW,EAC7C,QAAO,EAAE;CAIX,MAAM,UAAU,MAAM,QAAQ,IAC5B,cAAc,KAAK,SACjB,gBACE,MACA,QAAQ,QACR,QAAQ,SACR,QAAQ,cACT,CACF,CACF;CAGD,MAAM,iBAA4B,EAAE;CACpC,MAAM,SAAkB,EAAE;AAE1B,MAAK,MAAM,UAAU,SAAS;AAC5B,MAAI,OAAO,OAAO;AAChB,WAAQ,KACN,mCAAmC,OAAO,KAAK,cAAc,IAAI,OAAO,KAAK,GAAG,IAChF,OAAO,MAAM,QACd;AACD,UAAO,KAAK,OAAO,MAAM;AACzB;;AAGF,MAAI,OAAO,KACT,gBAAe,KAAK,OAAO,KAAK;;AAKpC,KAAI,eAAe,WAAW,KAAK,OAAO,SAAS,EACjD,OAAM,IAAI,MACR,uBAAuB,OAAO,OAAO,YAAY,OAAO,IAAI,WAAW,kBACxE;AAGH,QAAO"}
@@ -1,5 +1,6 @@
1
- import { CustomDataSource, DataSourceContext } from '../types.cjs';
1
+ import { n as CustomDataSource, o as DataSourceContext } from "../../types-BIXtQlHB.cjs";
2
2
 
3
+ //#region src/data-sources/fetchers/custom.d.ts
3
4
  /**
4
5
  * Custom fetcher that fetches selected items.
5
6
  *
@@ -11,5 +12,6 @@ import { CustomDataSource, DataSourceContext } from '../types.cjs';
11
12
  * Logs warnings for failed fetches but doesn't throw.
12
13
  */
13
14
  declare function customFetcher(source: CustomDataSource, context: DataSourceContext): Promise<unknown[]>;
14
-
15
+ //#endregion
15
16
  export { customFetcher };
17
+ //# sourceMappingURL=custom.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom.d.cts","names":[],"sources":["../../../src/data-sources/fetchers/custom.ts"],"mappings":";;;;;AAuJA;;;;;;;;iBAAsB,aAAA,CACpB,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,iBAAA,GACR,OAAA"}
@@ -1,5 +1,6 @@
1
- import { CustomDataSource, DataSourceContext } from '../types.js';
1
+ import { n as CustomDataSource, o as DataSourceContext } from "../../types-C5OFJy-O.mjs";
2
2
 
3
+ //#region src/data-sources/fetchers/custom.d.ts
3
4
  /**
4
5
  * Custom fetcher that fetches selected items.
5
6
  *
@@ -11,5 +12,6 @@ import { CustomDataSource, DataSourceContext } from '../types.js';
11
12
  * Logs warnings for failed fetches but doesn't throw.
12
13
  */
13
14
  declare function customFetcher(source: CustomDataSource, context: DataSourceContext): Promise<unknown[]>;
14
-
15
+ //#endregion
15
16
  export { customFetcher };
17
+ //# sourceMappingURL=custom.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom.d.mts","names":[],"sources":["../../../src/data-sources/fetchers/custom.ts"],"mappings":";;;;;AAuJA;;;;;;;;iBAAsB,aAAA,CACpB,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,iBAAA,GACR,OAAA"}
@@ -0,0 +1,107 @@
1
+ //#region src/data-sources/fetchers/custom.ts
2
+ /**
3
+ * Individual resource endpoints for each shareable type.
4
+ * These fetch single items by ID from the company API.
5
+ */
6
+ const SHAREABLE_ENDPOINTS = {
7
+ Medium: (id) => `/company/media/${id}`,
8
+ Page: (id) => `/company/pages/${id}`,
9
+ Library: (id) => `/company/libraries/${id}`,
10
+ Product: (id) => `/company/v1/products/${id}`,
11
+ EnrollmentPack: (id) => `/enrollment_packs/${id}`
12
+ };
13
+ /**
14
+ * Extract the actual resource data from various API response structures.
15
+ * Different endpoints wrap their data differently:
16
+ * - Product: { status, resource: { product: {...} } }
17
+ * - EnrollmentPack: { status, resource: { enrollment_pack: {...} } }
18
+ * - Medium/Page/Library: Direct root or { medium: {...} }
19
+ */
20
+ function extractResourceData(json, shareableType) {
21
+ const resource = json.resource;
22
+ if (resource) {
23
+ const typeKey = shareableType.toLowerCase().replace("pack", "_pack");
24
+ if (resource[typeKey]) return resource[typeKey];
25
+ if (resource.product) return resource.product;
26
+ if (resource.enrollment_pack) return resource.enrollment_pack;
27
+ }
28
+ const directKey = shareableType.toLowerCase().replace("pack", "_pack");
29
+ if (json[directKey]) return json[directKey];
30
+ if (json.data) return json.data;
31
+ if (json.medium) return json.medium;
32
+ if (json.page) return json.page;
33
+ if (json.library) return json.library;
34
+ if (json.product) return json.product;
35
+ if (json.enrollment_pack) return json.enrollment_pack;
36
+ return json;
37
+ }
38
+ /**
39
+ * Fetch a single shareable item by ID from the individual resource endpoint.
40
+ */
41
+ async function fetchSingleItem(item, signal, baseUrl = "", getApiHeaders) {
42
+ const getEndpoint = SHAREABLE_ENDPOINTS[item.shareableType];
43
+ if (!getEndpoint) return {
44
+ item,
45
+ data: null,
46
+ error: /* @__PURE__ */ new Error(`Unknown shareable type: ${item.shareableType}`)
47
+ };
48
+ const endpoint = `${baseUrl}${getEndpoint(item.id)}`;
49
+ try {
50
+ const response = await fetch(endpoint, {
51
+ method: "GET",
52
+ headers: {
53
+ ...getApiHeaders?.(),
54
+ "Content-Type": "application/json"
55
+ },
56
+ signal
57
+ });
58
+ if (!response.ok) return {
59
+ item,
60
+ data: null,
61
+ error: /* @__PURE__ */ new Error(`Failed to fetch ${item.shareableType} with ID ${item.id}: ${response.status}`)
62
+ };
63
+ const resourceData = extractResourceData(await response.json(), item.shareableType);
64
+ if (resourceData && typeof resourceData === "object") resourceData.shareable_type = item.shareableType;
65
+ return {
66
+ item,
67
+ data: resourceData
68
+ };
69
+ } catch (error) {
70
+ return {
71
+ item,
72
+ data: null,
73
+ error: error instanceof Error ? error : /* @__PURE__ */ new Error(`Unknown error fetching ${item.shareableType} ${item.id}`)
74
+ };
75
+ }
76
+ }
77
+ /**
78
+ * Custom fetcher that fetches selected items.
79
+ *
80
+ * Fetches items from individual resource endpoints using the configured
81
+ * getApiHeaders for authentication.
82
+ *
83
+ * Fetches all items in parallel for performance.
84
+ * Returns an array of successfully fetched items, preserving order.
85
+ * Logs warnings for failed fetches but doesn't throw.
86
+ */
87
+ async function customFetcher(source, context) {
88
+ const { selectedItems } = source;
89
+ if (!selectedItems || selectedItems.length === 0) return [];
90
+ const results = await Promise.all(selectedItems.map((item) => fetchSingleItem(item, context.signal, context.baseUrl, context.getApiHeaders)));
91
+ const successfulData = [];
92
+ const errors = [];
93
+ for (const result of results) {
94
+ if (result.error) {
95
+ console.warn(`[CustomFetcher] Failed to fetch ${result.item.shareableType} #${result.item.id}:`, result.error.message);
96
+ errors.push(result.error);
97
+ continue;
98
+ }
99
+ if (result.data) successfulData.push(result.data);
100
+ }
101
+ if (successfulData.length === 0 && errors.length > 0) throw new Error(`Failed to fetch all ${errors.length} item(s): ${errors[0]?.message || "Unknown error"}`);
102
+ return successfulData;
103
+ }
104
+ //#endregion
105
+ export { customFetcher };
106
+
107
+ //# sourceMappingURL=custom.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom.mjs","names":[],"sources":["../../../src/data-sources/fetchers/custom.ts"],"sourcesContent":["import type {\n CustomDataSource,\n DataSourceContext,\n SelectedItem,\n ShareableType,\n} from \"../types\";\n\n/**\n * Individual resource endpoints for each shareable type.\n * These fetch single items by ID from the company API.\n */\nconst SHAREABLE_ENDPOINTS: Record<\n ShareableType,\n (id: string | number) => string\n> = {\n Medium: (id) => `/company/media/${id}`,\n Page: (id) => `/company/pages/${id}`,\n Library: (id) => `/company/libraries/${id}`,\n Product: (id) => `/company/v1/products/${id}`,\n EnrollmentPack: (id) => `/enrollment_packs/${id}`,\n};\n\n/**\n * Extract the actual resource data from various API response structures.\n * Different endpoints wrap their data differently:\n * - Product: { status, resource: { product: {...} } }\n * - EnrollmentPack: { status, resource: { enrollment_pack: {...} } }\n * - Medium/Page/Library: Direct root or { medium: {...} }\n */\nfunction extractResourceData(\n json: Record<string, unknown>,\n shareableType: ShareableType,\n): Record<string, unknown> {\n // Try nested resource structure first (Product, EnrollmentPack)\n const resource = json.resource as Record<string, unknown> | undefined;\n if (resource) {\n // Check for type-specific key within resource\n const typeKey = shareableType.toLowerCase().replace(\"pack\", \"_pack\");\n if (resource[typeKey]) {\n return resource[typeKey] as Record<string, unknown>;\n }\n // Check common keys\n if (resource.product) return resource.product as Record<string, unknown>;\n if (resource.enrollment_pack)\n return resource.enrollment_pack as Record<string, unknown>;\n }\n\n // Try direct type key (e.g., { medium: {...} })\n const directKey = shareableType.toLowerCase().replace(\"pack\", \"_pack\");\n if (json[directKey]) {\n return json[directKey] as Record<string, unknown>;\n }\n\n // Try common response shapes\n if (json.data) return json.data as Record<string, unknown>;\n if (json.medium) return json.medium as Record<string, unknown>;\n if (json.page) return json.page as Record<string, unknown>;\n if (json.library) return json.library as Record<string, unknown>;\n if (json.product) return json.product as Record<string, unknown>;\n if (json.enrollment_pack)\n return json.enrollment_pack as Record<string, unknown>;\n\n // Return as-is if no wrapper found (Library uses direct serialization)\n return json;\n}\n\n/**\n * Result from fetching a single shareable item\n */\ninterface FetchResult {\n item: SelectedItem;\n data: unknown;\n error?: Error;\n}\n\n/**\n * Fetch a single shareable item by ID from the individual resource endpoint.\n */\nasync function fetchSingleItem(\n item: SelectedItem,\n signal: AbortSignal,\n baseUrl: string = \"\",\n getApiHeaders?: () => Record<string, string>,\n): Promise<FetchResult> {\n const getEndpoint = SHAREABLE_ENDPOINTS[item.shareableType];\n if (!getEndpoint) {\n return {\n item,\n data: null,\n error: new Error(`Unknown shareable type: ${item.shareableType}`),\n };\n }\n\n const endpoint = `${baseUrl}${getEndpoint(item.id)}`;\n\n try {\n const response = await fetch(endpoint, {\n method: \"GET\",\n headers: {\n ...getApiHeaders?.(),\n \"Content-Type\": \"application/json\",\n },\n signal,\n });\n\n if (!response.ok) {\n return {\n item,\n data: null,\n error: new Error(\n `Failed to fetch ${item.shareableType} with ID ${item.id}: ${response.status}`,\n ),\n };\n }\n\n const json = await response.json();\n\n // Extract the actual resource data from the response wrapper\n const resourceData = extractResourceData(json, item.shareableType);\n\n // Add shareable_type to the response for transformer compatibility\n if (resourceData && typeof resourceData === \"object\") {\n (resourceData as Record<string, unknown>).shareable_type =\n item.shareableType;\n }\n\n return { item, data: resourceData };\n } catch (error) {\n return {\n item,\n data: null,\n error:\n error instanceof Error\n ? error\n : new Error(\n `Unknown error fetching ${item.shareableType} ${item.id}`,\n ),\n };\n }\n}\n\n/**\n * Custom fetcher that fetches selected items.\n *\n * Fetches items from individual resource endpoints using the configured\n * getApiHeaders for authentication.\n *\n * Fetches all items in parallel for performance.\n * Returns an array of successfully fetched items, preserving order.\n * Logs warnings for failed fetches but doesn't throw.\n */\nexport async function customFetcher(\n source: CustomDataSource,\n context: DataSourceContext,\n): Promise<unknown[]> {\n const { selectedItems } = source;\n if (!selectedItems || selectedItems.length === 0) {\n return [];\n }\n\n // Fallback: fetch from individual endpoints (no auth)\n const results = await Promise.all(\n selectedItems.map((item) =>\n fetchSingleItem(\n item,\n context.signal,\n context.baseUrl,\n context.getApiHeaders,\n ),\n ),\n );\n\n // Process results, collecting successful data and tracking errors\n const successfulData: unknown[] = [];\n const errors: Error[] = [];\n\n for (const result of results) {\n if (result.error) {\n console.warn(\n `[CustomFetcher] Failed to fetch ${result.item.shareableType} #${result.item.id}:`,\n result.error.message,\n );\n errors.push(result.error);\n continue;\n }\n\n if (result.data) {\n successfulData.push(result.data);\n }\n }\n\n // Throw error if all fetches failed\n if (successfulData.length === 0 && errors.length > 0) {\n throw new Error(\n `Failed to fetch all ${errors.length} item(s): ${errors[0]?.message || \"Unknown error\"}`,\n );\n }\n\n return successfulData;\n}\n"],"mappings":";;;;;AAWA,MAAM,sBAGF;CACF,SAAS,OAAO,kBAAkB;CAClC,OAAO,OAAO,kBAAkB;CAChC,UAAU,OAAO,sBAAsB;CACvC,UAAU,OAAO,wBAAwB;CACzC,iBAAiB,OAAO,qBAAqB;CAC9C;;;;;;;;AASD,SAAS,oBACP,MACA,eACyB;CAEzB,MAAM,WAAW,KAAK;AACtB,KAAI,UAAU;EAEZ,MAAM,UAAU,cAAc,aAAa,CAAC,QAAQ,QAAQ,QAAQ;AACpE,MAAI,SAAS,SAC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SACoB;CACpB,MAAM,EAAE,kBAAkB;AAC1B,KAAI,CAAC,iBAAiB,cAAc,WAAW,EAC7C,QAAO,EAAE;CAIX,MAAM,UAAU,MAAM,QAAQ,IAC5B,cAAc,KAAK,SACjB,gBACE,MACA,QAAQ,QACR,QAAQ,SACR,QAAQ,cACT,CACF,CACF;CAGD,MAAM,iBAA4B,EAAE;CACpC,MAAM,SAAkB,EAAE;AAE1B,MAAK,MAAM,UAAU,SAAS;AAC5B,MAAI,OAAO,OAAO;AAChB,WAAQ,KACN,mCAAmC,OAAO,KAAK,cAAc,IAAI,OAAO,KAAK,GAAG,IAChF,OAAO,MAAM,QACd;AACD,UAAO,KAAK,OAAO,MAAM;AACzB;;AAGF,MAAI,OAAO,KACT,gBAAe,KAAK,OAAO,KAAK;;AAKpC,KAAI,eAAe,WAAW,KAAK,OAAO,SAAS,EACjD,OAAM,IAAI,MACR,uBAAuB,OAAO,OAAO,YAAY,OAAO,IAAI,WAAW,kBACxE;AAGH,QAAO"}
@@ -1,16 +1,161 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../chunk-CKQMccvm.cjs");
3
+ let react = require("react");
4
+ //#region src/data-sources/fetchers/static.ts
5
+ /**
6
+ * Endpoint patterns for fetching products by static source type.
7
+ * Tags require backend API support (not yet available).
8
+ */
9
+ const STATIC_ENDPOINTS = {
10
+ collections: "/company/v1/products",
11
+ categories: "/company/v1/products"
12
+ };
13
+ /**
14
+ * Query parameter names for each static source type.
15
+ */
16
+ const STATIC_QUERY_PARAMS = {
17
+ collections: "collection_id",
18
+ categories: "category_id"
19
+ };
20
+ /**
21
+ * Extract products array from API response.
22
+ * The /company/v1/products endpoint returns { products: [...], meta: {...} }
23
+ */
24
+ function extractProducts(json) {
25
+ if (Array.isArray(json.products)) return json.products;
26
+ if (Array.isArray(json.data)) return json.data;
27
+ if (Array.isArray(json)) return json;
28
+ console.warn("[extractProducts] Could not find products array. Available keys:", Object.keys(json));
29
+ return [];
30
+ }
31
+ /**
32
+ * Static data source fetcher.
33
+ *
34
+ * Fetches products filtered by collection or category ID.
35
+ * Tags are not yet supported (requires backend API changes).
36
+ *
37
+ * @param source - The static data source configuration
38
+ * @param context - The data source context with baseUrl and headers
39
+ * @returns Array of products matching the filter criteria
40
+ */
41
+ async function staticFetcher(source, context) {
42
+ const { staticType, selectedId } = source;
43
+ if (staticType === "tags") throw new Error("Tags data source is not yet supported. Please select Collections or Categories instead.");
44
+ const endpoint = STATIC_ENDPOINTS[staticType];
45
+ const queryParam = STATIC_QUERY_PARAMS[staticType];
46
+ if (!endpoint || !queryParam) throw new Error(`Invalid data source configuration: "${staticType}" is not a supported static source type.`);
47
+ const url = new URL(`${context.baseUrl ?? ""}${endpoint}`, context.baseUrl ? void 0 : window.location.origin);
48
+ url.searchParams.set(queryParam, String(selectedId));
49
+ try {
50
+ const response = await fetch(url.toString(), {
51
+ method: "GET",
52
+ headers: {
53
+ ...context.getApiHeaders?.(),
54
+ "Content-Type": "application/json"
55
+ },
56
+ signal: context.signal
57
+ });
58
+ if (!response.ok) throw new Error(`Failed to fetch products for ${staticType} ${selectedId}: ${response.status} ${response.statusText}`);
59
+ return extractProducts(await response.json());
60
+ } catch (error) {
61
+ if (error instanceof Error && error.name === "AbortError") return [];
62
+ console.error(`[staticFetcher] Error fetching ${staticType} ${selectedId}:`, error);
63
+ throw error;
64
+ }
65
+ }
66
+ /**
67
+ * Endpoints for listing static source items (collections, categories, tags).
68
+ */
69
+ const LIST_ENDPOINTS = {
70
+ collections: {
71
+ endpoint: "/company/v1/collections",
72
+ resultKey: "collections"
73
+ },
74
+ categories: {
75
+ endpoint: "/company/v1/categories",
76
+ resultKey: "categories"
77
+ },
78
+ tags: {
79
+ endpoint: "/company/v1/tags",
80
+ resultKey: "tags"
81
+ }
82
+ };
83
+ /**
84
+ * React hook for fetching static source items (collections, categories).
85
+ * Handles loading state, error state, abort on cleanup, and search filtering.
86
+ *
87
+ * @param staticType - The type of static source to fetch, or null to reset
88
+ * @param context - Context with baseUrl and getApiHeaders
89
+ * @param params - Optional search parameters
90
+ * @returns Object with items, isLoading, and error state
91
+ */
92
+ function useStaticSourceItems(staticType, context, params) {
93
+ const [items, setItems] = (0, react.useState)([]);
94
+ const [isLoading, setIsLoading] = (0, react.useState)(false);
95
+ const [error, setError] = (0, react.useState)(null);
96
+ const { baseUrl, getApiHeaders } = context;
97
+ const search = params?.search;
98
+ const getApiHeadersRef = (0, react.useRef)(getApiHeaders);
99
+ getApiHeadersRef.current = getApiHeaders;
100
+ (0, react.useEffect)(() => {
101
+ if (!staticType) {
102
+ setItems([]);
103
+ setError(null);
104
+ return;
105
+ }
106
+ let isCancelled = false;
107
+ const abortController = new AbortController();
108
+ setIsLoading(true);
109
+ setError(null);
110
+ const config = LIST_ENDPOINTS[staticType];
111
+ const url = new URL(`${baseUrl ?? ""}${config.endpoint}`, baseUrl ? void 0 : window.location.origin);
112
+ if (search) url.searchParams.set("search", search);
113
+ fetch(url.toString(), {
114
+ method: "GET",
115
+ headers: {
116
+ ...getApiHeadersRef.current?.(),
117
+ "Content-Type": "application/json"
118
+ },
119
+ signal: abortController.signal
120
+ }).then(async (response) => {
121
+ if (!response.ok) throw new Error(`Failed to fetch ${staticType}: ${response.status}`);
122
+ const responseItems = (await response.json())[config.resultKey];
123
+ if (!Array.isArray(responseItems)) {
124
+ console.warn(`[useStaticSourceItems] Expected array at "${config.resultKey}" but got:`, typeof responseItems);
125
+ if (!isCancelled) setItems([]);
126
+ return;
127
+ }
128
+ if (!isCancelled) setItems(responseItems.map((item) => ({
129
+ id: item.id,
130
+ title: item.title,
131
+ imageUrl: item.image_url
132
+ })));
133
+ }).catch((err) => {
134
+ if (err instanceof Error && err.name === "AbortError") return;
135
+ console.error(`[useStaticSourceItems] Failed to fetch ${staticType}:`, err);
136
+ if (isCancelled) return;
137
+ setError("An unexpected error occurred. Please try again.");
138
+ setItems([]);
139
+ }).finally(() => {
140
+ if (!isCancelled) setIsLoading(false);
141
+ });
142
+ return () => {
143
+ isCancelled = true;
144
+ abortController.abort();
145
+ };
146
+ }, [
147
+ staticType,
148
+ search,
149
+ baseUrl
150
+ ]);
151
+ return {
152
+ items,
153
+ isLoading,
154
+ error
155
+ };
156
+ }
157
+ //#endregion
158
+ exports.staticFetcher = staticFetcher;
159
+ exports.useStaticSourceItems = useStaticSourceItems;
2
160
 
3
- var chunkN2K6W7FX_cjs = require('../../chunk-N2K6W7FX.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "staticFetcher", {
8
- enumerable: true,
9
- get: function () { return chunkN2K6W7FX_cjs.staticFetcher; }
10
- });
11
- Object.defineProperty(exports, "useStaticSourceItems", {
12
- enumerable: true,
13
- get: function () { return chunkN2K6W7FX_cjs.useStaticSourceItems; }
14
- });
15
- //# sourceMappingURL=static.cjs.map
16
161
  //# sourceMappingURL=static.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"static.cjs"}
1
+ {"version":3,"file":"static.cjs","names":[],"sources":["../../../src/data-sources/fetchers/static.ts"],"sourcesContent":["import { useState, useEffect, useRef } from \"react\";\nimport type {\n StaticDataSource,\n DataSourceContext,\n StaticSourceType,\n StaticItem,\n} from \"../types\";\n\n/**\n * Endpoint patterns for fetching products by static source type.\n * Tags require backend API support (not yet available).\n */\nconst STATIC_ENDPOINTS: Record<\"collections\" | \"categories\", string> = {\n collections: \"/company/v1/products\",\n categories: \"/company/v1/products\",\n};\n\n/**\n * Query parameter names for each static source type.\n */\nconst STATIC_QUERY_PARAMS: Record<\"collections\" | \"categories\", string> = {\n collections: \"collection_id\",\n categories: \"category_id\",\n};\n\n/**\n * Extract products array from API response.\n * The /company/v1/products endpoint returns { products: [...], meta: {...} }\n */\nfunction extractProducts(json: Record<string, unknown>): unknown[] {\n if (Array.isArray(json.products)) {\n return json.products;\n }\n if (Array.isArray(json.data)) {\n return json.data;\n }\n if (Array.isArray(json)) {\n return json;\n }\n console.warn(\n \"[extractProducts] Could not find products array. Available keys:\",\n Object.keys(json),\n );\n return [];\n}\n\n/**\n * Static data source fetcher.\n *\n * Fetches products filtered by collection or category ID.\n * Tags are not yet supported (requires backend API changes).\n *\n * @param source - The static data source configuration\n * @param context - The data source context with baseUrl and headers\n * @returns Array of products matching the filter criteria\n */\nexport async function staticFetcher(\n source: StaticDataSource,\n context: DataSourceContext,\n): Promise<unknown[]> {\n const { staticType, selectedId } = source;\n\n // Tags require backend API support - not yet implemented\n if (staticType === \"tags\") {\n throw new Error(\n \"Tags data source is not yet supported. Please select Collections or Categories instead.\",\n );\n }\n\n const endpoint = STATIC_ENDPOINTS[staticType];\n const queryParam = STATIC_QUERY_PARAMS[staticType];\n\n if (!endpoint || !queryParam) {\n throw new Error(\n `Invalid data source configuration: \"${staticType}\" is not a supported static source type.`,\n );\n }\n\n const url = new URL(\n `${context.baseUrl ?? \"\"}${endpoint}`,\n context.baseUrl ? undefined : window.location.origin,\n );\n url.searchParams.set(queryParam, String(selectedId));\n\n try {\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: {\n ...context.getApiHeaders?.(),\n \"Content-Type\": \"application/json\",\n },\n signal: context.signal,\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch products for ${staticType} ${selectedId}: ${response.status} ${response.statusText}`,\n );\n }\n\n const json = await response.json();\n return extractProducts(json);\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n // Request was cancelled, don't log as error\n return [];\n }\n console.error(\n `[staticFetcher] Error fetching ${staticType} ${selectedId}:`,\n error,\n );\n throw error;\n }\n}\n\n/**\n * Endpoints for listing static source items (collections, categories, tags).\n */\nconst LIST_ENDPOINTS: Record<\n StaticSourceType,\n { endpoint: string; resultKey: string }\n> = {\n collections: {\n endpoint: \"/company/v1/collections\",\n resultKey: \"collections\",\n },\n categories: { endpoint: \"/company/v1/categories\", resultKey: \"categories\" },\n tags: { endpoint: \"/company/v1/tags\", resultKey: \"tags\" },\n};\n\n/**\n * Result type for useStaticSourceItems hook.\n */\nexport interface UseStaticSourceItemsResult {\n /** The fetched items */\n items: StaticItem[];\n /** True while items are being fetched */\n isLoading: boolean;\n /** Error message if fetch failed */\n error: string | null;\n}\n\n/**\n * React hook for fetching static source items (collections, categories).\n * Handles loading state, error state, abort on cleanup, and search filtering.\n *\n * @param staticType - The type of static source to fetch, or null to reset\n * @param context - Context with baseUrl and getApiHeaders\n * @param params - Optional search parameters\n * @returns Object with items, isLoading, and error state\n */\nexport function useStaticSourceItems(\n staticType: StaticSourceType | null,\n context: Pick<DataSourceContext, \"baseUrl\" | \"getApiHeaders\">,\n params?: { search?: string },\n): UseStaticSourceItemsResult {\n const [items, setItems] = useState<StaticItem[]>([]);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n // Extract stable references from context to avoid dependency issues\n const { baseUrl, getApiHeaders } = context;\n const search = params?.search;\n\n // Use ref to avoid infinite re-renders when getApiHeaders changes reference\n const getApiHeadersRef = useRef(getApiHeaders);\n getApiHeadersRef.current = getApiHeaders;\n\n useEffect(() => {\n if (!staticType) {\n setItems([]);\n setError(null);\n return;\n }\n\n let isCancelled = false;\n const abortController = new AbortController();\n setIsLoading(true);\n setError(null);\n\n const config = LIST_ENDPOINTS[staticType];\n const url = new URL(\n `${baseUrl ?? \"\"}${config.endpoint}`,\n baseUrl ? undefined : window.location.origin,\n );\n\n if (search) {\n url.searchParams.set(\"search\", search);\n }\n\n fetch(url.toString(), {\n method: \"GET\",\n headers: {\n ...getApiHeadersRef.current?.(),\n \"Content-Type\": \"application/json\",\n },\n signal: abortController.signal,\n })\n .then(async (response) => {\n if (!response.ok) {\n throw new Error(`Failed to fetch ${staticType}: ${response.status}`);\n }\n const json = await response.json();\n const responseItems = json[config.resultKey] as Array<{\n id: string | number;\n title: string;\n image_url?: string;\n }>;\n\n if (!Array.isArray(responseItems)) {\n console.warn(\n `[useStaticSourceItems] Expected array at \"${config.resultKey}\" but got:`,\n typeof responseItems,\n );\n if (!isCancelled) {\n setItems([]);\n }\n return;\n }\n\n if (!isCancelled) {\n setItems(\n responseItems.map((item) => ({\n id: item.id,\n title: item.title,\n imageUrl: item.image_url,\n })),\n );\n }\n })\n .catch((err) => {\n if (err instanceof Error && err.name === \"AbortError\") {\n return;\n }\n\n // Log for debugging\n console.error(\n `[useStaticSourceItems] Failed to fetch ${staticType}:`,\n err,\n );\n\n if (isCancelled) return;\n\n setError(\"An unexpected error occurred. Please try again.\");\n setItems([]);\n })\n .finally(() => {\n if (!isCancelled) {\n setIsLoading(false);\n }\n });\n\n return () => {\n isCancelled = true;\n abortController.abort();\n };\n }, [staticType, search, baseUrl]);\n\n return { items, isLoading, error };\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,mBAAiE;CACrE,aAAa;CACb,YAAY;CACb;;;;AAKD,MAAM,sBAAoE;CACxE,aAAa;CACb,YAAY;CACb;;;;;AAMD,SAAS,gBAAgB,MAA0C;AACjE,KAAI,MAAM,QAAQ,KAAK,SAAS,CAC9B,QAAO,KAAK;AAEd,KAAI,MAAM,QAAQ,KAAK,KAAK,CAC1B,QAAO,KAAK;AAEd,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO;AAET,SAAQ,KACN,oEACA,OAAO,KAAK,KAAK,CAClB;AACD,QAAO,EAAE;;;;;;;;;;;;AAaX,eAAsB,cACpB,QACA,SACoB;CACpB,MAAM,EAAE,YAAY,eAAe;AAGnC,KAAI,eAAe,OACjB,OAAM,IAAI,MACR,0FACD;CAGH,MAAM,WAAW,iBAAiB;CAClC,MAAM,aAAa,oBAAoB;AAEvC,KAAI,CAAC,YAAY,CAAC,WAChB,OAAM,IAAI,MACR,uCAAuC,WAAW,0CACnD;CAGH,MAAM,MAAM,IAAI,IACd,GAAG,QAAQ,WAAW,KAAK,YAC3B,QAAQ,UAAU,KAAA,IAAY,OAAO,SAAS,OAC/C;AACD,KAAI,aAAa,IAAI,YAAY,OAAO,WAAW,CAAC;AAEpD,KAAI;EACF,MAAM,WAAW,MAA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