@fluid-app/portal-core 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 (195) hide show
  1. package/dist/chunk-CKQMccvm.cjs +28 -0
  2. package/dist/data-sources/DataAwareWidget.cjs +50 -0
  3. package/dist/data-sources/DataAwareWidget.cjs.map +1 -0
  4. package/dist/data-sources/DataAwareWidget.d.cts +24 -0
  5. package/dist/data-sources/DataAwareWidget.d.cts.map +1 -0
  6. package/dist/data-sources/DataAwareWidget.d.mts +24 -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 +20 -0
  11. package/dist/data-sources/ErrorState.cjs.map +1 -0
  12. package/dist/data-sources/ErrorState.d.cts +7 -0
  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 +24 -0
  19. package/dist/data-sources/context.cjs.map +1 -0
  20. package/dist/data-sources/context.d.cts +21 -0
  21. package/dist/data-sources/context.d.cts.map +1 -0
  22. package/dist/data-sources/context.d.mts +21 -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 +65 -0
  27. package/dist/data-sources/fetchers/api.cjs.map +1 -0
  28. package/dist/data-sources/fetchers/api.d.cts +10 -0
  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 +108 -0
  35. package/dist/data-sources/fetchers/custom.cjs.map +1 -0
  36. package/dist/data-sources/fetchers/custom.d.cts +17 -0
  37. package/dist/data-sources/fetchers/custom.d.cts.map +1 -0
  38. package/dist/data-sources/fetchers/custom.d.mts +17 -0
  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 +161 -0
  43. package/dist/data-sources/fetchers/static.cjs.map +1 -0
  44. package/dist/data-sources/fetchers/static.d.cts +40 -0
  45. package/dist/data-sources/fetchers/static.d.cts.map +1 -0
  46. package/dist/data-sources/fetchers/static.d.mts +40 -0
  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 +21 -0
  51. package/dist/data-sources/preview-context.cjs.map +1 -0
  52. package/dist/data-sources/preview-context.d.cts +13 -0
  53. package/dist/data-sources/preview-context.d.cts.map +1 -0
  54. package/dist/data-sources/preview-context.d.mts +13 -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 +53 -0
  59. package/dist/data-sources/registry-context.cjs.map +1 -0
  60. package/dist/data-sources/registry-context.d.cts +48 -0
  61. package/dist/data-sources/registry-context.d.cts.map +1 -0
  62. package/dist/data-sources/registry-context.d.mts +48 -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 +31 -0
  67. package/dist/data-sources/registry.cjs.map +1 -0
  68. package/dist/data-sources/registry.d.cts +19 -0
  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 +154 -0
  75. package/dist/data-sources/transformers.cjs.map +1 -0
  76. package/dist/data-sources/transformers.d.cts +10 -0
  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 -0
  83. package/dist/data-sources/types.d.cts +2 -0
  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 +111 -0
  87. package/dist/data-sources/use-widget-data.cjs.map +1 -0
  88. package/dist/data-sources/use-widget-data.d.cts +17 -0
  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-B5cTNde-.d.cts +246 -0
  95. package/dist/index-B5cTNde-.d.cts.map +1 -0
  96. package/dist/index-Cqt2JzkQ.d.mts +246 -0
  97. package/dist/index-Cqt2JzkQ.d.mts.map +1 -0
  98. package/dist/registries/index.cjs +243 -0
  99. package/dist/registries/index.cjs.map +1 -0
  100. package/dist/registries/index.d.cts +338 -0
  101. package/dist/registries/index.d.cts.map +1 -0
  102. package/dist/registries/index.d.mts +338 -0
  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 +49 -0
  107. package/dist/shell/AppShellLayout.cjs.map +1 -0
  108. package/dist/shell/AppShellLayout.d.cts +39 -0
  109. package/dist/shell/AppShellLayout.d.cts.map +1 -0
  110. package/dist/shell/AppShellLayout.d.mts +39 -0
  111. package/dist/shell/AppShellLayout.d.mts.map +1 -0
  112. package/dist/shell/AppShellLayout.mjs +46 -0
  113. package/dist/shell/AppShellLayout.mjs.map +1 -0
  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 +35 -0
  125. package/dist/shell/ScreenHeaderContext.d.cts.map +1 -0
  126. package/dist/shell/ScreenHeaderContext.d.mts +35 -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 +70 -0
  131. package/dist/shell/ThemeModeContext.cjs.map +1 -0
  132. package/dist/shell/ThemeModeContext.d.cts +33 -0
  133. package/dist/shell/ThemeModeContext.d.cts.map +1 -0
  134. package/dist/shell/ThemeModeContext.d.mts +33 -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 -0
  139. package/dist/shell/index.d.cts +7 -0
  140. package/dist/shell/index.d.mts +7 -0
  141. package/dist/shell/index.mjs +7 -0
  142. package/dist/shell/sidebar.cjs +390 -0
  143. package/dist/shell/sidebar.cjs.map +1 -0
  144. package/dist/shell/sidebar.d.cts +85 -0
  145. package/dist/shell/sidebar.d.cts.map +1 -0
  146. package/dist/shell/sidebar.d.mts +85 -0
  147. package/dist/shell/sidebar.d.mts.map +1 -0
  148. package/dist/shell/sidebar.mjs +364 -0
  149. package/dist/shell/sidebar.mjs.map +1 -0
  150. package/dist/shell/use-mobile.cjs +51 -0
  151. package/dist/shell/use-mobile.cjs.map +1 -0
  152. package/dist/shell/use-mobile.d.cts +7 -0
  153. package/dist/shell/use-mobile.d.cts.map +1 -0
  154. package/dist/shell/use-mobile.d.mts +7 -0
  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 +758 -0
  159. package/dist/theme/index.cjs.map +1 -0
  160. package/dist/theme/index.d.cts +131 -0
  161. package/dist/theme/index.d.cts.map +1 -0
  162. package/dist/theme/index.d.mts +131 -0
  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 -0
  167. package/dist/types/index.d.cts +4 -0
  168. package/dist/types/index.d.mts +4 -0
  169. package/dist/types/index.mjs +2 -0
  170. package/dist/types-27AHMek-.d.cts +85 -0
  171. package/dist/types-27AHMek-.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-C5Zs5V3E.d.mts +155 -0
  177. package/dist/types-C5Zs5V3E.d.mts.map +1 -0
  178. package/dist/types-CeCPKvOv.d.mts +85 -0
  179. package/dist/types-CeCPKvOv.d.mts.map +1 -0
  180. package/dist/types-DrzvahW8.d.cts +155 -0
  181. package/dist/types-DrzvahW8.d.cts.map +1 -0
  182. package/dist/widget-schema-BKZgsNG7.d.mts +119 -0
  183. package/dist/widget-schema-BKZgsNG7.d.mts.map +1 -0
  184. package/dist/widget-schema-BSX2fVhW.d.cts +119 -0
  185. package/dist/widget-schema-BSX2fVhW.d.cts.map +1 -0
  186. package/dist/widget-utils/index.cjs +130 -0
  187. package/dist/widget-utils/index.cjs.map +1 -0
  188. package/dist/widget-utils/index.d.cts +47 -0
  189. package/dist/widget-utils/index.d.cts.map +1 -0
  190. package/dist/widget-utils/index.d.mts +47 -0
  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 +200 -0
  195. package/src/styles/globals.css +1 -0
@@ -0,0 +1,108 @@
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;
107
+
108
+ //# sourceMappingURL=custom.cjs.map
@@ -0,0 +1 @@
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,a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AK,KACtD;GACR;;;;;;;;;;;;;AAcL,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"}
@@ -0,0 +1,17 @@
1
+ import { n as CustomDataSource, o as DataSourceContext } from "../../types-DrzvahW8.cjs";
2
+
3
+ //#region src/data-sources/fetchers/custom.d.ts
4
+ /**
5
+ * Custom fetcher that fetches selected items.
6
+ *
7
+ * Fetches items from individual resource endpoints using the configured
8
+ * getApiHeaders for authentication.
9
+ *
10
+ * Fetches all items in parallel for performance.
11
+ * Returns an array of successfully fetched items, preserving order.
12
+ * Logs warnings for failed fetches but doesn't throw.
13
+ */
14
+ declare function customFetcher(source: CustomDataSource, context: DataSourceContext): Promise<unknown[]>;
15
+ //#endregion
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"}
@@ -0,0 +1,17 @@
1
+ import { n as CustomDataSource, o as DataSourceContext } from "../../types-C5Zs5V3E.mjs";
2
+
3
+ //#region src/data-sources/fetchers/custom.d.ts
4
+ /**
5
+ * Custom fetcher that fetches selected items.
6
+ *
7
+ * Fetches items from individual resource endpoints using the configured
8
+ * getApiHeaders for authentication.
9
+ *
10
+ * Fetches all items in parallel for performance.
11
+ * Returns an array of successfully fetched items, preserving order.
12
+ * Logs warnings for failed fetches but doesn't throw.
13
+ */
14
+ declare function customFetcher(source: CustomDataSource, context: DataSourceContext): Promise<unknown[]>;
15
+ //#endregion
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,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ACtD;GACR;;;;;;;;;;;;;AAcL,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"}
@@ -0,0 +1,161 @@
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;
160
+
161
+ //# sourceMappingURL=static.cjs.map
@@ -0,0 +1 @@
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,MAAM,MAAM,IAAI,UAAU,EAAE;GAC3C,QAAQ;GACR,SAAS;IACP,GAAG,QAAQ,iBAAiB;IAC5B,gBAAgB;IACjB;GACD,QAAQ,QAAQ;GACjB,CAAC;AAEF,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MACR,gCAAgC,WAAW,GAAG,WAAW,IAAI,SAAS,OAAO,GAAG,SAAS,aAC1F;AAIH,SAAO,gBADM,MAAM,SAAS,MAAM,CACN;UACrB,O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AS;GAGtE,MAAM,iBADO,MAAM,SAAS,MAAM,EACP,OAAO;AAMlC,OAAI,CAAC,MAAM,QAAQ,cAAc,EAAE;AACjC,YAAQ,KACN,6CAA6C,OAAO,UAAU,aAC9D,OAAO,cACR;AACD,QAAI,CAAC,YACH,UAAS,EAAE,CAAC;AAEd;;AAGF,OAAI,CAAC,YACH,UACE,cAAc,KAAK,UAAU;IAC3B,IAAI,KAAK;IACT,OAAO,KAAK;IACZ,UAAU,KAAK;IAChB,EAAE,CACJ;IAEH,CACD,OAAO,QAAQ;AACd,OAAI,eAAe,SAAS,IAAI,SAAS,aACvC;AAIF,WAAQ,MACN,0CAA0C,WAAW,IACrD,IACD;AAED,OAAI,YAAa;AAEjB,YAAS,kDAAkD;AAC3D,YAAS,EAAE,CAAC;IACZ,CACD,cAAc;AACb,OAAI,CAAC,YACH,cAAa,MAAM;IAErB;AAEJ,eAAa;AACX,iBAAc;AACd,mBAAgB,OAAO;;IAExB;EAAC;EAAY;EAAQ;EAAQ,CAAC;AAEjC,QAAO;EAAE;EAAO;EAAW;EAAO"}
@@ -0,0 +1,40 @@
1
+ import { f as StaticDataSource, m as StaticSourceType, o as DataSourceContext, p as StaticItem } from "../../types-DrzvahW8.cjs";
2
+
3
+ //#region src/data-sources/fetchers/static.d.ts
4
+ /**
5
+ * Static data source fetcher.
6
+ *
7
+ * Fetches products filtered by collection or category ID.
8
+ * Tags are not yet supported (requires backend API changes).
9
+ *
10
+ * @param source - The static data source configuration
11
+ * @param context - The data source context with baseUrl and headers
12
+ * @returns Array of products matching the filter criteria
13
+ */
14
+ declare function staticFetcher(source: StaticDataSource, context: DataSourceContext): Promise<unknown[]>;
15
+ /**
16
+ * Result type for useStaticSourceItems hook.
17
+ */
18
+ interface UseStaticSourceItemsResult {
19
+ /** The fetched items */
20
+ items: StaticItem[];
21
+ /** True while items are being fetched */
22
+ isLoading: boolean;
23
+ /** Error message if fetch failed */
24
+ error: string | null;
25
+ }
26
+ /**
27
+ * React hook for fetching static source items (collections, categories).
28
+ * Handles loading state, error state, abort on cleanup, and search filtering.
29
+ *
30
+ * @param staticType - The type of static source to fetch, or null to reset
31
+ * @param context - Context with baseUrl and getApiHeaders
32
+ * @param params - Optional search parameters
33
+ * @returns Object with items, isLoading, and error state
34
+ */
35
+ declare function useStaticSourceItems(staticType: StaticSourceType | null, context: Pick<DataSourceContext, "baseUrl" | "getApiHeaders">, params?: {
36
+ search?: string;
37
+ }): UseStaticSourceItemsResult;
38
+ //#endregion
39
+ export { UseStaticSourceItemsResult, staticFetcher, useStaticSourceItems };
40
+ //# sourceMappingURL=static.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static.d.cts","names":[],"sources":["../../../src/data-sources/fetchers/static.ts"],"mappings":";;;;;AAwDA;;;;;;;;iBAAsB,aAAA,CACpB,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,iBAAA,GACR,OAAA;;;;UA0Ec,0BAAA;;EAEf,KAAA,EAAO,UAAA;EAFT;EAIE,SAAA;;EAEA,KAAA;AAAA;;;;;;AAYF;;;;iBAAgB,oBAAA,CACd,UAAA,EAAY,gBAAA,SACZ,OAAA,EAAS,IAAA,CAAK,iBAAA,gCACd,MAAA;EAAW,MAAA;AAAA,IACV,0BAAA"}
@@ -0,0 +1,40 @@
1
+ import { f as StaticDataSource, m as StaticSourceType, o as DataSourceContext, p as StaticItem } from "../../types-C5Zs5V3E.mjs";
2
+
3
+ //#region src/data-sources/fetchers/static.d.ts
4
+ /**
5
+ * Static data source fetcher.
6
+ *
7
+ * Fetches products filtered by collection or category ID.
8
+ * Tags are not yet supported (requires backend API changes).
9
+ *
10
+ * @param source - The static data source configuration
11
+ * @param context - The data source context with baseUrl and headers
12
+ * @returns Array of products matching the filter criteria
13
+ */
14
+ declare function staticFetcher(source: StaticDataSource, context: DataSourceContext): Promise<unknown[]>;
15
+ /**
16
+ * Result type for useStaticSourceItems hook.
17
+ */
18
+ interface UseStaticSourceItemsResult {
19
+ /** The fetched items */
20
+ items: StaticItem[];
21
+ /** True while items are being fetched */
22
+ isLoading: boolean;
23
+ /** Error message if fetch failed */
24
+ error: string | null;
25
+ }
26
+ /**
27
+ * React hook for fetching static source items (collections, categories).
28
+ * Handles loading state, error state, abort on cleanup, and search filtering.
29
+ *
30
+ * @param staticType - The type of static source to fetch, or null to reset
31
+ * @param context - Context with baseUrl and getApiHeaders
32
+ * @param params - Optional search parameters
33
+ * @returns Object with items, isLoading, and error state
34
+ */
35
+ declare function useStaticSourceItems(staticType: StaticSourceType | null, context: Pick<DataSourceContext, "baseUrl" | "getApiHeaders">, params?: {
36
+ search?: string;
37
+ }): UseStaticSourceItemsResult;
38
+ //#endregion
39
+ export { UseStaticSourceItemsResult, staticFetcher, useStaticSourceItems };
40
+ //# sourceMappingURL=static.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static.d.mts","names":[],"sources":["../../../src/data-sources/fetchers/static.ts"],"mappings":";;;;;AAwDA;;;;;;;;iBAAsB,aAAA,CACpB,MAAA,EAAQ,gBAAA,EACR,OAAA,EAAS,iBAAA,GACR,OAAA;;;;UA0Ec,0BAAA;;EAEf,KAAA,EAAO,UAAA;EAFT;EAIE,SAAA;;EAEA,KAAA;AAAA;;;;;;AAYF;;;;iBAAgB,oBAAA,CACd,UAAA,EAAY,gBAAA,SACZ,OAAA,EAAS,IAAA,CAAK,iBAAA,gCACd,MAAA;EAAW,MAAA;AAAA,IACV,0BAAA"}