@fluid-app/rep-core 0.1.14 → 0.1.15
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.
- package/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/data-sources/DataAwareWidget.cjs +47 -56
- package/dist/data-sources/DataAwareWidget.cjs.map +1 -1
- package/dist/data-sources/DataAwareWidget.d.cts +27 -19
- package/dist/data-sources/DataAwareWidget.d.cts.map +1 -0
- package/dist/data-sources/DataAwareWidget.d.mts +38 -0
- package/dist/data-sources/DataAwareWidget.d.mts.map +1 -0
- package/dist/data-sources/DataAwareWidget.mjs +48 -0
- package/dist/data-sources/DataAwareWidget.mjs.map +1 -0
- package/dist/data-sources/ErrorState.cjs +18 -10
- package/dist/data-sources/ErrorState.cjs.map +1 -1
- package/dist/data-sources/ErrorState.d.cts +5 -3
- package/dist/data-sources/ErrorState.d.cts.map +1 -0
- package/dist/data-sources/ErrorState.d.mts +7 -0
- package/dist/data-sources/ErrorState.d.mts.map +1 -0
- package/dist/data-sources/ErrorState.mjs +18 -0
- package/dist/data-sources/ErrorState.mjs.map +1 -0
- package/dist/data-sources/context.cjs +22 -14
- package/dist/data-sources/context.cjs.map +1 -1
- package/dist/data-sources/context.d.cts +16 -10
- package/dist/data-sources/context.d.cts.map +1 -0
- package/dist/data-sources/context.d.mts +22 -0
- package/dist/data-sources/context.d.mts.map +1 -0
- package/dist/data-sources/context.mjs +21 -0
- package/dist/data-sources/context.mjs.map +1 -0
- package/dist/data-sources/fetchers/api.cjs +63 -10
- package/dist/data-sources/fetchers/api.cjs.map +1 -1
- package/dist/data-sources/fetchers/api.d.cts +4 -2
- package/dist/data-sources/fetchers/api.d.cts.map +1 -0
- package/dist/data-sources/fetchers/api.d.mts +10 -0
- package/dist/data-sources/fetchers/api.d.mts.map +1 -0
- package/dist/data-sources/fetchers/api.mjs +64 -0
- package/dist/data-sources/fetchers/api.mjs.map +1 -0
- package/dist/data-sources/fetchers/custom.cjs +106 -10
- package/dist/data-sources/fetchers/custom.cjs.map +1 -1
- package/dist/data-sources/fetchers/custom.d.cts +4 -2
- package/dist/data-sources/fetchers/custom.d.cts.map +1 -0
- package/dist/data-sources/fetchers/{custom.d.ts → custom.d.mts} +4 -2
- package/dist/data-sources/fetchers/custom.d.mts.map +1 -0
- package/dist/data-sources/fetchers/custom.mjs +107 -0
- package/dist/data-sources/fetchers/custom.mjs.map +1 -0
- package/dist/data-sources/fetchers/static.cjs +159 -14
- package/dist/data-sources/fetchers/static.cjs.map +1 -1
- package/dist/data-sources/fetchers/static.d.cts +12 -10
- package/dist/data-sources/fetchers/static.d.cts.map +1 -0
- package/dist/data-sources/fetchers/{static.d.ts → static.d.mts} +12 -10
- package/dist/data-sources/fetchers/static.d.mts.map +1 -0
- package/dist/data-sources/fetchers/static.mjs +158 -0
- package/dist/data-sources/fetchers/static.mjs.map +1 -0
- package/dist/data-sources/preview-context.cjs +15 -15
- package/dist/data-sources/preview-context.cjs.map +1 -1
- package/dist/data-sources/preview-context.d.cts +10 -6
- package/dist/data-sources/preview-context.d.cts.map +1 -0
- package/dist/data-sources/preview-context.d.mts +15 -0
- package/dist/data-sources/preview-context.d.mts.map +1 -0
- package/dist/data-sources/preview-context.mjs +18 -0
- package/dist/data-sources/preview-context.mjs.map +1 -0
- package/dist/data-sources/registry-context.cjs +51 -24
- package/dist/data-sources/registry-context.cjs.map +1 -1
- package/dist/data-sources/registry-context.d.cts +30 -22
- package/dist/data-sources/registry-context.d.cts.map +1 -0
- package/dist/data-sources/registry-context.d.mts +49 -0
- package/dist/data-sources/registry-context.d.mts.map +1 -0
- package/dist/data-sources/registry-context.mjs +49 -0
- package/dist/data-sources/registry-context.mjs.map +1 -0
- package/dist/data-sources/registry.cjs +29 -18
- package/dist/data-sources/registry.cjs.map +1 -1
- package/dist/data-sources/registry.d.cts +9 -7
- package/dist/data-sources/registry.d.cts.map +1 -0
- package/dist/data-sources/registry.d.mts +19 -0
- package/dist/data-sources/registry.d.mts.map +1 -0
- package/dist/data-sources/registry.mjs +29 -0
- package/dist/data-sources/registry.mjs.map +1 -0
- package/dist/data-sources/transformers.cjs +152 -10
- package/dist/data-sources/transformers.cjs.map +1 -1
- package/dist/data-sources/transformers.d.cts +4 -17
- package/dist/data-sources/transformers.d.cts.map +1 -0
- package/dist/data-sources/transformers.d.mts +10 -0
- package/dist/data-sources/transformers.d.mts.map +1 -0
- package/dist/data-sources/transformers.mjs +153 -0
- package/dist/data-sources/transformers.mjs.map +1 -0
- package/dist/data-sources/types.cjs +0 -4
- package/dist/data-sources/types.d.cts +2 -157
- package/dist/data-sources/types.d.mts +2 -0
- package/dist/data-sources/types.mjs +1 -0
- package/dist/data-sources/use-widget-data.cjs +109 -17
- package/dist/data-sources/use-widget-data.cjs.map +1 -1
- package/dist/data-sources/use-widget-data.d.cts +9 -8
- package/dist/data-sources/use-widget-data.d.cts.map +1 -0
- package/dist/data-sources/use-widget-data.d.mts +17 -0
- package/dist/data-sources/use-widget-data.d.mts.map +1 -0
- package/dist/data-sources/use-widget-data.mjs +109 -0
- package/dist/data-sources/use-widget-data.mjs.map +1 -0
- package/dist/index-Bxe_LIi8.d.cts +287 -0
- package/dist/index-Bxe_LIi8.d.cts.map +1 -0
- package/dist/index-CCAu2n19.d.mts +287 -0
- package/dist/index-CCAu2n19.d.mts.map +1 -0
- package/dist/registries/index.cjs +212 -127
- package/dist/registries/index.cjs.map +1 -1
- package/dist/registries/index.d.cts +146 -149
- package/dist/registries/index.d.cts.map +1 -0
- package/dist/registries/{index.d.ts → index.d.mts} +146 -149
- package/dist/registries/index.d.mts.map +1 -0
- package/dist/registries/index.mjs +229 -0
- package/dist/registries/index.mjs.map +1 -0
- package/dist/shell/AppShellLayout.cjs +47 -12
- package/dist/shell/AppShellLayout.cjs.map +1 -1
- package/dist/shell/AppShellLayout.d.cts +29 -19
- package/dist/shell/AppShellLayout.d.cts.map +1 -0
- package/dist/shell/AppShellLayout.d.mts +40 -0
- package/dist/shell/AppShellLayout.d.mts.map +1 -0
- package/dist/shell/AppShellLayout.mjs +46 -0
- package/dist/{chunk-45BCVWQK.cjs.map → shell/AppShellLayout.mjs.map} +1 -1
- package/dist/shell/ScreenHeader.cjs +44 -0
- package/dist/shell/ScreenHeader.cjs.map +1 -0
- package/dist/shell/ScreenHeader.d.cts +12 -0
- package/dist/shell/ScreenHeader.d.cts.map +1 -0
- package/dist/shell/ScreenHeader.d.mts +12 -0
- package/dist/shell/ScreenHeader.d.mts.map +1 -0
- package/dist/shell/ScreenHeader.mjs +42 -0
- package/dist/shell/ScreenHeader.mjs.map +1 -0
- package/dist/shell/ScreenHeaderContext.cjs +91 -0
- package/dist/shell/ScreenHeaderContext.cjs.map +1 -0
- package/dist/shell/ScreenHeaderContext.d.cts +36 -0
- package/dist/shell/ScreenHeaderContext.d.cts.map +1 -0
- package/dist/shell/ScreenHeaderContext.d.mts +36 -0
- package/dist/shell/ScreenHeaderContext.d.mts.map +1 -0
- package/dist/shell/ScreenHeaderContext.mjs +86 -0
- package/dist/shell/ScreenHeaderContext.mjs.map +1 -0
- package/dist/shell/ThemeModeContext.cjs +68 -18
- package/dist/shell/ThemeModeContext.cjs.map +1 -1
- package/dist/shell/ThemeModeContext.d.cts +23 -16
- package/dist/shell/ThemeModeContext.d.cts.map +1 -0
- package/dist/shell/ThemeModeContext.d.mts +34 -0
- package/dist/shell/ThemeModeContext.d.mts.map +1 -0
- package/dist/shell/ThemeModeContext.mjs +66 -0
- package/dist/shell/ThemeModeContext.mjs.map +1 -0
- package/dist/shell/index.cjs +43 -205
- package/dist/shell/index.d.cts +7 -43
- package/dist/shell/index.d.mts +7 -0
- package/dist/shell/index.mjs +7 -0
- package/dist/shell/sidebar.cjs +372 -87
- package/dist/shell/sidebar.cjs.map +1 -1
- package/dist/shell/sidebar.d.cts +38 -36
- package/dist/shell/sidebar.d.cts.map +1 -0
- package/dist/shell/{sidebar.d.ts → sidebar.d.mts} +38 -36
- package/dist/shell/sidebar.d.mts.map +1 -0
- package/dist/shell/sidebar.mjs +364 -0
- package/dist/{chunk-PFDBULOI.cjs.map → shell/sidebar.mjs.map} +1 -1
- package/dist/shell/use-mobile.cjs +49 -18
- package/dist/shell/use-mobile.cjs.map +1 -1
- package/dist/shell/use-mobile.d.cts +3 -1
- package/dist/shell/use-mobile.d.cts.map +1 -0
- package/dist/shell/{use-mobile.d.ts → use-mobile.d.mts} +3 -1
- package/dist/shell/use-mobile.d.mts.map +1 -0
- package/dist/shell/use-mobile.mjs +47 -0
- package/dist/shell/use-mobile.mjs.map +1 -0
- package/dist/theme/index.cjs +662 -549
- package/dist/theme/index.cjs.map +1 -1
- package/dist/theme/index.d.cts +32 -32
- package/dist/theme/index.d.cts.map +1 -0
- package/dist/theme/{index.d.ts → index.d.mts} +32 -32
- package/dist/theme/index.d.mts.map +1 -0
- package/dist/theme/index.mjs +727 -0
- package/dist/theme/index.mjs.map +1 -0
- package/dist/types/index.cjs +18 -72
- package/dist/types/index.d.cts +4 -268
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types-BIXtQlHB.d.cts +155 -0
- package/dist/types-BIXtQlHB.d.cts.map +1 -0
- package/dist/types-BXFX9bXp.cjs +303 -0
- package/dist/types-BXFX9bXp.cjs.map +1 -0
- package/dist/types-Bjmd7Fdx.mjs +208 -0
- package/dist/types-Bjmd7Fdx.mjs.map +1 -0
- package/dist/types-ByG6Xy3C.d.mts +85 -0
- package/dist/types-ByG6Xy3C.d.mts.map +1 -0
- package/dist/types-C5OFJy-O.d.mts +155 -0
- package/dist/types-C5OFJy-O.d.mts.map +1 -0
- package/dist/types-Ctu-Zio6.d.cts +85 -0
- package/dist/types-Ctu-Zio6.d.cts.map +1 -0
- package/dist/{widget-schema-D-ca3--K.d.ts → widget-schema--PY1uMWx.d.cts} +38 -41
- package/dist/widget-schema--PY1uMWx.d.cts.map +1 -0
- package/dist/{widget-schema-DvJdg1-B.d.cts → widget-schema-YkD5p3v4.d.mts} +38 -41
- package/dist/widget-schema-YkD5p3v4.d.mts.map +1 -0
- package/dist/widget-utils/index.cjs +96 -89
- package/dist/widget-utils/index.cjs.map +1 -1
- package/dist/widget-utils/index.d.cts +8 -6
- package/dist/widget-utils/index.d.cts.map +1 -0
- package/dist/widget-utils/{index.d.ts → index.d.mts} +8 -6
- package/dist/widget-utils/index.d.mts.map +1 -0
- package/dist/widget-utils/index.mjs +119 -0
- package/dist/widget-utils/index.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/chunk-2SPTFZRC.js +0 -72
- package/dist/chunk-2SPTFZRC.js.map +0 -1
- package/dist/chunk-3I5Y3PEO.js +0 -23
- package/dist/chunk-3I5Y3PEO.js.map +0 -1
- package/dist/chunk-3ZRE7GX6.js +0 -620
- package/dist/chunk-3ZRE7GX6.js.map +0 -1
- package/dist/chunk-45BCVWQK.cjs +0 -38
- package/dist/chunk-46PUWB7C.cjs +0 -69
- package/dist/chunk-46PUWB7C.cjs.map +0 -1
- package/dist/chunk-5NYM4UTW.cjs +0 -58
- package/dist/chunk-5NYM4UTW.cjs.map +0 -1
- package/dist/chunk-B2NTWEDF.cjs +0 -130
- package/dist/chunk-B2NTWEDF.cjs.map +0 -1
- package/dist/chunk-GDY76JA6.cjs +0 -153
- package/dist/chunk-GDY76JA6.cjs.map +0 -1
- package/dist/chunk-HGVSPZEL.cjs +0 -119
- package/dist/chunk-HGVSPZEL.cjs.map +0 -1
- package/dist/chunk-HIDJYVKJ.js +0 -54
- package/dist/chunk-HIDJYVKJ.js.map +0 -1
- package/dist/chunk-KTXGU7OP.cjs +0 -136
- package/dist/chunk-KTXGU7OP.cjs.map +0 -1
- package/dist/chunk-KW5E2H5T.js +0 -128
- package/dist/chunk-KW5E2H5T.js.map +0 -1
- package/dist/chunk-LBLHDGMT.js +0 -25
- package/dist/chunk-LBLHDGMT.js.map +0 -1
- package/dist/chunk-MNVDL4FX.js +0 -134
- package/dist/chunk-MNVDL4FX.js.map +0 -1
- package/dist/chunk-MOTOSPAO.cjs +0 -15
- package/dist/chunk-MOTOSPAO.cjs.map +0 -1
- package/dist/chunk-N2K6W7FX.cjs +0 -169
- package/dist/chunk-N2K6W7FX.cjs.map +0 -1
- package/dist/chunk-PFDBULOI.cjs +0 -665
- package/dist/chunk-PVTQWD4I.js +0 -166
- package/dist/chunk-PVTQWD4I.js.map +0 -1
- package/dist/chunk-SJQPHJL4.cjs +0 -26
- package/dist/chunk-SJQPHJL4.cjs.map +0 -1
- package/dist/chunk-TML66UEU.js +0 -13
- package/dist/chunk-TML66UEU.js.map +0 -1
- package/dist/chunk-U3CQLX2Z.cjs +0 -28
- package/dist/chunk-U3CQLX2Z.cjs.map +0 -1
- package/dist/chunk-UUNEVOA5.js +0 -36
- package/dist/chunk-UUNEVOA5.js.map +0 -1
- package/dist/chunk-VRF7QEID.js +0 -67
- package/dist/chunk-VRF7QEID.js.map +0 -1
- package/dist/chunk-VSZWXSQA.js +0 -38
- package/dist/chunk-VSZWXSQA.js.map +0 -1
- package/dist/chunk-WYOHFNNW.js +0 -117
- package/dist/chunk-WYOHFNNW.js.map +0 -1
- package/dist/chunk-YKF5ZFF5.js +0 -136
- package/dist/chunk-YKF5ZFF5.js.map +0 -1
- package/dist/chunk-YXJMBVXO.cjs +0 -76
- package/dist/chunk-YXJMBVXO.cjs.map +0 -1
- package/dist/chunk-ZA4AE7KF.cjs +0 -42
- package/dist/chunk-ZA4AE7KF.cjs.map +0 -1
- package/dist/data-sources/DataAwareWidget.d.ts +0 -30
- package/dist/data-sources/DataAwareWidget.js +0 -57
- package/dist/data-sources/DataAwareWidget.js.map +0 -1
- package/dist/data-sources/ErrorState.d.ts +0 -5
- package/dist/data-sources/ErrorState.js +0 -3
- package/dist/data-sources/ErrorState.js.map +0 -1
- package/dist/data-sources/context.d.ts +0 -16
- package/dist/data-sources/context.js +0 -3
- package/dist/data-sources/context.js.map +0 -1
- package/dist/data-sources/fetchers/api.d.ts +0 -8
- package/dist/data-sources/fetchers/api.js +0 -3
- package/dist/data-sources/fetchers/api.js.map +0 -1
- package/dist/data-sources/fetchers/custom.js +0 -3
- package/dist/data-sources/fetchers/custom.js.map +0 -1
- package/dist/data-sources/fetchers/static.js +0 -3
- package/dist/data-sources/fetchers/static.js.map +0 -1
- package/dist/data-sources/preview-context.d.ts +0 -11
- package/dist/data-sources/preview-context.js +0 -18
- package/dist/data-sources/preview-context.js.map +0 -1
- package/dist/data-sources/registry-context.d.ts +0 -41
- package/dist/data-sources/registry-context.js +0 -9
- package/dist/data-sources/registry-context.js.map +0 -1
- package/dist/data-sources/registry.d.ts +0 -17
- package/dist/data-sources/registry.js +0 -7
- package/dist/data-sources/registry.js.map +0 -1
- package/dist/data-sources/transformers.d.ts +0 -23
- package/dist/data-sources/transformers.js +0 -3
- package/dist/data-sources/transformers.js.map +0 -1
- package/dist/data-sources/types.cjs.map +0 -1
- package/dist/data-sources/types.d.ts +0 -157
- package/dist/data-sources/types.js +0 -3
- package/dist/data-sources/types.js.map +0 -1
- package/dist/data-sources/use-widget-data.d.ts +0 -16
- package/dist/data-sources/use-widget-data.js +0 -10
- package/dist/data-sources/use-widget-data.js.map +0 -1
- package/dist/registries/index.js +0 -144
- package/dist/registries/index.js.map +0 -1
- package/dist/shareable-item-DkgWpwoU.d.cts +0 -21
- package/dist/shareable-item-DkgWpwoU.d.ts +0 -21
- package/dist/shell/AppShellLayout.d.ts +0 -30
- package/dist/shell/AppShellLayout.js +0 -5
- package/dist/shell/AppShellLayout.js.map +0 -1
- package/dist/shell/ThemeModeContext.d.ts +0 -27
- package/dist/shell/ThemeModeContext.js +0 -3
- package/dist/shell/ThemeModeContext.js.map +0 -1
- package/dist/shell/index.cjs.map +0 -1
- package/dist/shell/index.d.ts +0 -43
- package/dist/shell/index.js +0 -76
- package/dist/shell/index.js.map +0 -1
- package/dist/shell/sidebar.js +0 -4
- package/dist/shell/sidebar.js.map +0 -1
- package/dist/shell/use-mobile.js +0 -3
- package/dist/shell/use-mobile.js.map +0 -1
- package/dist/theme/index.js +0 -611
- package/dist/theme/index.js.map +0 -1
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.ts +0 -268
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
- package/dist/types-CNIhy4JD.d.cts +0 -83
- package/dist/types-CNIhy4JD.d.ts +0 -83
- package/dist/widget-utils/index.js +0 -111
- package/dist/widget-utils/index.js.map +0 -1
|
@@ -1,157 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type ShareableType = "Medium" | "Page" | "EnrollmentPack" | "Library" | "Product";
|
|
4
|
-
interface SelectedItem {
|
|
5
|
-
/** The unique ID of the selected item */
|
|
6
|
-
id: string | number;
|
|
7
|
-
/** The type of shareable content */
|
|
8
|
-
shareableType: ShareableType;
|
|
9
|
-
/** Optional cached data for preview/display purposes in the editor UI */
|
|
10
|
-
cachedData?: {
|
|
11
|
-
title?: string;
|
|
12
|
-
imageUrl?: string;
|
|
13
|
-
kind?: string;
|
|
14
|
-
};
|
|
15
|
-
/** Widget-specific per-item configuration overrides */
|
|
16
|
-
widgetConfig?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
interface ApiDataSource {
|
|
19
|
-
type: "api";
|
|
20
|
-
/** API endpoint URL (can include {variable} placeholders, e.g., /api/reps/{rep_id}/items) */
|
|
21
|
-
endpoint: string;
|
|
22
|
-
/** HTTP method (defaults to GET) */
|
|
23
|
-
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
24
|
-
/** Request headers */
|
|
25
|
-
headers?: Record<string, string>;
|
|
26
|
-
/** Request body for POST/PUT (will be JSON.stringify'd) */
|
|
27
|
-
body?: unknown;
|
|
28
|
-
/**
|
|
29
|
-
* Path to extract from response using dot notation
|
|
30
|
-
* e.g., "data.items" extracts response.data.items
|
|
31
|
-
*/
|
|
32
|
-
resultPath?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Which widget props this source populates
|
|
35
|
-
* e.g., ['data'] means the fetched result goes to props.data
|
|
36
|
-
*/
|
|
37
|
-
targetProps: string[];
|
|
38
|
-
/**
|
|
39
|
-
* Name of a registered transform function to process the data
|
|
40
|
-
* Transform is applied after resultPath extraction
|
|
41
|
-
*/
|
|
42
|
-
transform?: string;
|
|
43
|
-
/** Per-source variables for endpoint template interpolation (e.g., { limit: "10" }) */
|
|
44
|
-
variables?: Record<string, string>;
|
|
45
|
-
/**
|
|
46
|
-
* Auto-refresh interval in milliseconds
|
|
47
|
-
* 0 or undefined = no auto-refresh
|
|
48
|
-
*/
|
|
49
|
-
refreshInterval?: number;
|
|
50
|
-
}
|
|
51
|
-
interface CustomDataSource {
|
|
52
|
-
type: "custom";
|
|
53
|
-
/** Array of selected items to fetch */
|
|
54
|
-
selectedItems: SelectedItem[];
|
|
55
|
-
/**
|
|
56
|
-
* Which widget props this source populates
|
|
57
|
-
* e.g., ['slides'] means the fetched results go to props.slides
|
|
58
|
-
*/
|
|
59
|
-
targetProps: string[];
|
|
60
|
-
/**
|
|
61
|
-
* Name of a registered transform function to process the data
|
|
62
|
-
* Transform is applied after all items are fetched
|
|
63
|
-
*/
|
|
64
|
-
transform?: string;
|
|
65
|
-
/**
|
|
66
|
-
* Auto-refresh interval in milliseconds
|
|
67
|
-
* 0 or undefined = no auto-refresh
|
|
68
|
-
*/
|
|
69
|
-
refreshInterval?: number;
|
|
70
|
-
}
|
|
71
|
-
interface StaticDataSource {
|
|
72
|
-
type: "static";
|
|
73
|
-
/** The type of static data (collections, categories, tags) */
|
|
74
|
-
staticType: StaticSourceType;
|
|
75
|
-
/** The selected item ID */
|
|
76
|
-
selectedId: string | number;
|
|
77
|
-
/** Cached data for preview/display in editor UI */
|
|
78
|
-
cachedData?: {
|
|
79
|
-
title?: string;
|
|
80
|
-
imageUrl?: string;
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Which widget props this source populates
|
|
84
|
-
*/
|
|
85
|
-
targetProps: string[];
|
|
86
|
-
/**
|
|
87
|
-
* Name of a registered transform function to process the data
|
|
88
|
-
*/
|
|
89
|
-
transform?: string;
|
|
90
|
-
/**
|
|
91
|
-
* Auto-refresh interval in milliseconds
|
|
92
|
-
* 0 or undefined = no auto-refresh
|
|
93
|
-
*/
|
|
94
|
-
refreshInterval?: number;
|
|
95
|
-
}
|
|
96
|
-
type DataSource = ApiDataSource | CustomDataSource | StaticDataSource;
|
|
97
|
-
interface DataSourceConfig {
|
|
98
|
-
/** Array of data sources (usually just one, but supports multiple) */
|
|
99
|
-
sources: DataSource[];
|
|
100
|
-
/** Loading state configuration */
|
|
101
|
-
loading?: {
|
|
102
|
-
/** Show skeleton placeholder while loading (default: true) */
|
|
103
|
-
showSkeleton?: boolean;
|
|
104
|
-
};
|
|
105
|
-
/** Error handling configuration */
|
|
106
|
-
error?: {
|
|
107
|
-
/** Fallback props to use when fetch fails */
|
|
108
|
-
fallback?: Record<string, unknown>;
|
|
109
|
-
/** Number of retry attempts (default: 0) */
|
|
110
|
-
retryCount?: number;
|
|
111
|
-
/** Delay between retries in ms (default: 1000) */
|
|
112
|
-
retryDelay?: number;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/** Item returned by static data fetchers */
|
|
116
|
-
interface StaticItem {
|
|
117
|
-
id: string | number;
|
|
118
|
-
title: string;
|
|
119
|
-
imageUrl?: string | undefined;
|
|
120
|
-
}
|
|
121
|
-
/** Context passed to fetchers and transforms */
|
|
122
|
-
interface DataSourceContext {
|
|
123
|
-
/** The widget's unique ID */
|
|
124
|
-
widgetId: string;
|
|
125
|
-
/** The widget type (e.g., "ChartWidget") */
|
|
126
|
-
widgetType: string;
|
|
127
|
-
/** AbortSignal for request cancellation */
|
|
128
|
-
signal: AbortSignal;
|
|
129
|
-
/** Base URL for API calls (e.g., "https://api.fluid.app/api") */
|
|
130
|
-
baseUrl?: string | undefined;
|
|
131
|
-
/** Get API headers function */
|
|
132
|
-
getApiHeaders?: (() => Record<string, string>) | undefined;
|
|
133
|
-
/** Dynamic variables for endpoint path substitution (e.g., { rep_id: "123" }) */
|
|
134
|
-
variables?: Record<string, string> | undefined;
|
|
135
|
-
}
|
|
136
|
-
/** Function signature for data fetchers */
|
|
137
|
-
type DataFetcher<T extends DataSource = DataSource> = (source: T, context: DataSourceContext) => Promise<unknown>;
|
|
138
|
-
/** Function signature for data transforms */
|
|
139
|
-
type DataTransformer = (data: unknown, source?: DataSource, context?: DataSourceContext) => unknown;
|
|
140
|
-
/** The data source registry configuration */
|
|
141
|
-
interface DataSourceRegistry {
|
|
142
|
-
fetchers: Record<DataSourceType, DataFetcher>;
|
|
143
|
-
transformers: Record<string, DataTransformer>;
|
|
144
|
-
}
|
|
145
|
-
/** Result from useWidgetData hook */
|
|
146
|
-
interface WidgetDataResult<T = unknown> {
|
|
147
|
-
/** The resolved data (undefined while loading) */
|
|
148
|
-
data: T | undefined;
|
|
149
|
-
/** True while any source is loading */
|
|
150
|
-
isLoading: boolean;
|
|
151
|
-
/** Error if any source failed */
|
|
152
|
-
error: Error | null;
|
|
153
|
-
/** Manually trigger a refetch */
|
|
154
|
-
refetch: () => void;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export type { ApiDataSource, CustomDataSource, DataFetcher, DataSource, DataSourceConfig, DataSourceContext, DataSourceRegistry, DataSourceType, DataTransformer, SelectedItem, ShareableType, StaticDataSource, StaticItem, StaticSourceType, WidgetDataResult };
|
|
1
|
+
import { a as DataSourceConfig, c as DataSourceType, d as ShareableType, f as StaticDataSource, h as WidgetDataResult, i as DataSource, l as DataTransformer, m as StaticSourceType, n as CustomDataSource, o as DataSourceContext, p as StaticItem, r as DataFetcher, s as DataSourceRegistry, t as ApiDataSource, u as SelectedItem } from "../types-BIXtQlHB.cjs";
|
|
2
|
+
export { ApiDataSource, CustomDataSource, DataFetcher, DataSource, DataSourceConfig, DataSourceContext, DataSourceRegistry, DataSourceType, DataTransformer, SelectedItem, ShareableType, StaticDataSource, StaticItem, StaticSourceType, WidgetDataResult };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as DataSourceConfig, c as DataSourceType, d as ShareableType, f as StaticDataSource, h as WidgetDataResult, i as DataSource, l as DataTransformer, m as StaticSourceType, n as CustomDataSource, o as DataSourceContext, p as StaticItem, r as DataFetcher, s as DataSourceRegistry, t as ApiDataSource, u as SelectedItem } from "../types-C5OFJy-O.mjs";
|
|
2
|
+
export { ApiDataSource, CustomDataSource, DataFetcher, DataSource, DataSourceConfig, DataSourceContext, DataSourceRegistry, DataSourceType, DataTransformer, SelectedItem, ShareableType, StaticDataSource, StaticItem, StaticSourceType, WidgetDataResult };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,19 +1,111 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../chunk-CKQMccvm.cjs");
|
|
3
|
+
const require_data_sources_registry_context = require("./registry-context.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let _tanstack_react_query = require("@tanstack/react-query");
|
|
6
|
+
//#region src/data-sources/use-widget-data.ts
|
|
7
|
+
/**
|
|
8
|
+
* Generates a unique key for a data source to use in query caching.
|
|
9
|
+
*/
|
|
10
|
+
function getSourceKey(source) {
|
|
11
|
+
if (source.type === "api") {
|
|
12
|
+
const varsKey = source.variables ? `:${JSON.stringify(source.variables)}` : "";
|
|
13
|
+
return `${source.endpoint}${varsKey}`;
|
|
14
|
+
}
|
|
15
|
+
if (source.type === "custom") return `custom:${(source.selectedItems?.map((item) => {
|
|
16
|
+
return `${item.shareableType}:${item.id}`;
|
|
17
|
+
}) ?? []).join(",")}`;
|
|
18
|
+
if (source.type === "static") return `static:${source.staticType}:${source.selectedId}`;
|
|
19
|
+
return "unknown";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves query results into widget props by mapping each source's result
|
|
23
|
+
* to its target props.
|
|
24
|
+
*/
|
|
25
|
+
function resolvePropsFromQueries(queryResults, sources, errorConfig) {
|
|
26
|
+
if (sources.length === 0) return void 0;
|
|
27
|
+
if (queryResults.some((q) => q.isLoading && !q.data)) return void 0;
|
|
28
|
+
const hasError = !!queryResults.find((q) => q.error)?.error;
|
|
29
|
+
if (hasError && errorConfig?.fallback) return errorConfig.fallback;
|
|
30
|
+
if (hasError) return;
|
|
31
|
+
const resolvedProps = {};
|
|
32
|
+
for (const query of queryResults) {
|
|
33
|
+
if (!query.data) continue;
|
|
34
|
+
const { source, result } = query.data;
|
|
35
|
+
if (!source?.targetProps) continue;
|
|
36
|
+
if (result !== null && typeof result === "object" && !Array.isArray(result) && source.targetProps.length > 1) {
|
|
37
|
+
const resultObj = result;
|
|
38
|
+
for (const prop of source.targetProps) if (prop in resultObj) resolvedProps[prop] = resultObj[prop];
|
|
39
|
+
} else for (const prop of source.targetProps) resolvedProps[prop] = result;
|
|
40
|
+
}
|
|
41
|
+
return resolvedProps;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hook that fetches and resolves data sources for a widget using React Query.
|
|
45
|
+
*/
|
|
46
|
+
function useWidgetData(widget, options) {
|
|
47
|
+
const config = require_data_sources_registry_context.useDataSourceRegistryConfig();
|
|
48
|
+
const registry = options?.registry ?? config.registry;
|
|
49
|
+
const baseUrl = options?.baseUrl ?? config.baseUrl;
|
|
50
|
+
const getApiHeaders = config.getApiHeaders;
|
|
51
|
+
const variables = config.variables;
|
|
52
|
+
const sources = widget.dataSource?.sources ?? [];
|
|
53
|
+
const errorConfig = widget.dataSource?.error;
|
|
54
|
+
const widgetId = widget.id ?? "unknown";
|
|
55
|
+
const widgetType = widget.type;
|
|
56
|
+
const queryResultsRef = (0, react.useRef)([]);
|
|
57
|
+
const results = (0, _tanstack_react_query.useQueries)({ queries: sources.map((source) => ({
|
|
58
|
+
queryKey: [
|
|
59
|
+
"rep-widget-data",
|
|
60
|
+
getSourceKey(source),
|
|
61
|
+
baseUrl,
|
|
62
|
+
variables
|
|
63
|
+
],
|
|
64
|
+
queryFn: async ({ signal }) => {
|
|
65
|
+
const context = {
|
|
66
|
+
widgetId,
|
|
67
|
+
widgetType,
|
|
68
|
+
signal,
|
|
69
|
+
baseUrl,
|
|
70
|
+
getApiHeaders,
|
|
71
|
+
variables
|
|
72
|
+
};
|
|
73
|
+
const fetcher = registry.fetchers[source.type];
|
|
74
|
+
if (!fetcher) throw new Error(`No fetcher registered for source type: ${source.type}`);
|
|
75
|
+
let result = await fetcher(source, context);
|
|
76
|
+
if (source.transform) {
|
|
77
|
+
const transformer = registry.transformers[source.transform];
|
|
78
|
+
if (transformer) result = transformer(result, source);
|
|
79
|
+
else console.warn(`Transform "${source.transform}" not found in registry`);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
source,
|
|
83
|
+
result
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
enabled: sources.length > 0,
|
|
87
|
+
retry: errorConfig?.retryCount ?? 0,
|
|
88
|
+
retryDelay: errorConfig?.retryDelay ?? 1e3,
|
|
89
|
+
refetchInterval: source.refreshInterval || false
|
|
90
|
+
})) });
|
|
91
|
+
queryResultsRef.current = results;
|
|
92
|
+
const isLoading = results.some((q) => q.isLoading);
|
|
93
|
+
const failedQuery = results.find((q) => q.error);
|
|
94
|
+
const error = failedQuery?.error instanceof Error ? failedQuery.error : failedQuery?.error ? new Error(String(failedQuery.error)) : null;
|
|
95
|
+
return {
|
|
96
|
+
data: resolvePropsFromQueries(results.map((q) => ({
|
|
97
|
+
data: q.data,
|
|
98
|
+
isLoading: q.isLoading,
|
|
99
|
+
error: q.error instanceof Error ? q.error : null
|
|
100
|
+
})), sources, errorConfig),
|
|
101
|
+
isLoading,
|
|
102
|
+
error,
|
|
103
|
+
refetch: (0, react.useCallback)(() => {
|
|
104
|
+
queryResultsRef.current.forEach((q) => q.refetch());
|
|
105
|
+
}, [])
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
exports.useWidgetData = useWidgetData;
|
|
2
110
|
|
|
3
|
-
var chunkKTXGU7OP_cjs = require('../chunk-KTXGU7OP.cjs');
|
|
4
|
-
require('../chunk-ZA4AE7KF.cjs');
|
|
5
|
-
require('../chunk-SJQPHJL4.cjs');
|
|
6
|
-
require('../chunk-U3CQLX2Z.cjs');
|
|
7
|
-
require('../chunk-46PUWB7C.cjs');
|
|
8
|
-
require('../chunk-HGVSPZEL.cjs');
|
|
9
|
-
require('../chunk-N2K6W7FX.cjs');
|
|
10
|
-
require('../chunk-B2NTWEDF.cjs');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, "useWidgetData", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return chunkKTXGU7OP_cjs.useWidgetData; }
|
|
17
|
-
});
|
|
18
|
-
//# sourceMappingURL=use-widget-data.cjs.map
|
|
19
111
|
//# sourceMappingURL=use-widget-data.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"use-widget-data.cjs","names":["useDataSourceRegistryConfig"],"sources":["../../src/data-sources/use-widget-data.ts"],"sourcesContent":["import { useQueries } from \"@tanstack/react-query\";\nimport { useCallback, useRef } from \"react\";\nimport type { WidgetSchema } from \"../types/widget-schema\";\nimport type {\n DataSourceRegistry,\n WidgetDataResult,\n DataSourceContext,\n DataSource,\n} from \"./types\";\nimport { useDataSourceRegistryConfig } from \"./registry-context\";\n\ninterface UseWidgetDataOptions {\n /** Override the default registry from context */\n registry?: DataSourceRegistry | undefined;\n /** Base URL for API calls (e.g., \"https://api.fluid.app/api\") */\n baseUrl?: string | undefined;\n}\n\n/** Result shape from a single source query */\ninterface SourceQueryResult {\n source: DataSource;\n result: unknown;\n}\n\n/**\n * Generates a unique key for a data source to use in query caching.\n */\nfunction getSourceKey(source: DataSource): string {\n if (source.type === \"api\") {\n const varsKey = source.variables\n ? `:${JSON.stringify(source.variables)}`\n : \"\";\n return `${source.endpoint}${varsKey}`;\n }\n if (source.type === \"custom\") {\n const itemKeys =\n source.selectedItems?.map((item) => {\n return `${item.shareableType}:${item.id}`;\n }) ?? [];\n return `custom:${itemKeys.join(\",\")}`;\n }\n if (source.type === \"static\") {\n return `static:${source.staticType}:${source.selectedId}`;\n }\n return \"unknown\";\n}\n\n/**\n * Resolves query results into widget props by mapping each source's result\n * to its target props.\n */\nfunction resolvePropsFromQueries<T>(\n queryResults: ReadonlyArray<{\n data?: SourceQueryResult | undefined;\n isLoading: boolean;\n error: Error | null;\n }>,\n sources: DataSource[],\n errorConfig?: { fallback?: unknown },\n): T | undefined {\n if (sources.length === 0) return undefined;\n if (queryResults.some((q) => q.isLoading && !q.data)) return undefined;\n\n const failedQuery = queryResults.find((q) => q.error);\n const hasError = !!failedQuery?.error;\n\n if (hasError && errorConfig?.fallback) {\n return errorConfig.fallback as T;\n }\n\n if (hasError) {\n return undefined;\n }\n\n const resolvedProps: Record<string, unknown> = {};\n\n for (const query of queryResults) {\n if (!query.data) continue;\n const { source, result } = query.data;\n\n // Sentry fix: FLUID-ADMIN-1DH — source or targetProps can be undefined from malformed widget config\n if (!source?.targetProps) continue;\n\n if (\n result !== null &&\n typeof result === \"object\" &&\n !Array.isArray(result) &&\n source.targetProps.length > 1\n ) {\n const resultObj = result as Record<string, unknown>;\n for (const prop of source.targetProps) {\n if (prop in resultObj) {\n resolvedProps[prop] = resultObj[prop];\n }\n }\n } else {\n for (const prop of source.targetProps) {\n resolvedProps[prop] = result;\n }\n }\n }\n\n return resolvedProps as T;\n}\n\n/**\n * Hook that fetches and resolves data sources for a widget using React Query.\n */\nexport function useWidgetData<T = Record<string, unknown>>(\n widget: WidgetSchema,\n options?: UseWidgetDataOptions,\n): WidgetDataResult<T> {\n const config = useDataSourceRegistryConfig();\n const registry = options?.registry ?? config.registry;\n const baseUrl = options?.baseUrl ?? config.baseUrl;\n const getApiHeaders = config.getApiHeaders;\n const variables = config.variables;\n\n const sources = widget.dataSource?.sources ?? [];\n const errorConfig = widget.dataSource?.error;\n const widgetId = widget.id ?? \"unknown\";\n const widgetType = widget.type;\n\n const queryResultsRef = useRef<Array<{ refetch: () => void }>>([]);\n\n const results = useQueries({\n queries: sources.map((source: DataSource) => ({\n queryKey: [\n \"rep-widget-data\",\n getSourceKey(source),\n baseUrl,\n variables,\n ] as const,\n queryFn: async ({\n signal,\n }: {\n signal: AbortSignal;\n }): Promise<SourceQueryResult> => {\n const context: DataSourceContext = {\n widgetId,\n widgetType,\n signal,\n baseUrl,\n getApiHeaders,\n variables,\n };\n\n const fetcher = registry.fetchers[source.type];\n if (!fetcher) {\n throw new Error(\n `No fetcher registered for source type: ${source.type}`,\n );\n }\n\n const rawData = await fetcher(source, context);\n\n // Apply transform\n let result = rawData;\n if (source.transform) {\n const transformer = registry.transformers[source.transform];\n if (transformer) {\n result = transformer(result, source);\n } else {\n console.warn(\n `Transform \"${source.transform}\" not found in registry`,\n );\n }\n }\n return { source, result };\n },\n enabled: sources.length > 0,\n retry: errorConfig?.retryCount ?? 0,\n retryDelay: errorConfig?.retryDelay ?? 1000,\n refetchInterval: source.refreshInterval || false,\n })),\n });\n\n // Update ref for refetch callback\n queryResultsRef.current = results;\n\n // Aggregate loading state\n const isLoading = results.some((q) => q.isLoading);\n\n // Get first error from any failed query\n const failedQuery = results.find((q) => q.error);\n const error =\n failedQuery?.error instanceof Error\n ? failedQuery.error\n : failedQuery?.error\n ? new Error(String(failedQuery.error))\n : null;\n\n // Resolve data from all queries\n const data = resolvePropsFromQueries<T>(\n results.map((q) => ({\n data: q.data as SourceQueryResult | undefined,\n isLoading: q.isLoading,\n error: q.error instanceof Error ? q.error : null,\n })),\n sources,\n errorConfig,\n );\n\n // Stable refetch callback using ref\n const refetch = useCallback(() => {\n queryResultsRef.current.forEach((q) => q.refetch());\n }, []);\n\n return {\n data,\n isLoading,\n error,\n refetch,\n };\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAS,aAAa,QAA4B;AAChD,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,UAAU,OAAO,YACnB,IAAI,KAAK,UAAU,OAAO,U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AAE,SAAS,CAAC;KAClD,EAAE,CAAC;EAOL"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import 'react';
|
|
1
|
+
import { h as WidgetDataResult, s as DataSourceRegistry } from "../types-BIXtQlHB.cjs";
|
|
2
|
+
import { a as WidgetSchema } from "../widget-schema--PY1uMWx.cjs";
|
|
4
3
|
|
|
4
|
+
//#region src/data-sources/use-widget-data.d.ts
|
|
5
5
|
interface UseWidgetDataOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** Override the default registry from context */
|
|
7
|
+
registry?: DataSourceRegistry | undefined;
|
|
8
|
+
/** Base URL for API calls (e.g., "https://api.fluid.app/api") */
|
|
9
|
+
baseUrl?: string | undefined;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Hook that fetches and resolves data sources for a widget using React Query.
|
|
13
13
|
*/
|
|
14
14
|
declare function useWidgetData<T = Record<string, unknown>>(widget: WidgetSchema, options?: UseWidgetDataOptions): WidgetDataResult<T>;
|
|
15
|
-
|
|
15
|
+
//#endregion
|
|
16
16
|
export { useWidgetData };
|
|
17
|
+
//# sourceMappingURL=use-widget-data.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-data.d.cts","names":[],"sources":["../../src/data-sources/use-widget-data.ts"],"mappings":";;;;UAWU,oBAAA;;EAER,QAAA,GAAW,kBAAA;EAFiB;EAI5B,OAAA;AAAA;;;;iBA6Fc,aAAA,KAAkB,MAAA,kBAAA,CAChC,MAAA,EAAQ,YAAA,EACR,OAAA,GAAU,oBAAA,GACT,gBAAA,CAAiB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { h as WidgetDataResult, s as DataSourceRegistry } from "../types-C5OFJy-O.mjs";
|
|
2
|
+
import { a as WidgetSchema } from "../widget-schema-YkD5p3v4.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/data-sources/use-widget-data.d.ts
|
|
5
|
+
interface UseWidgetDataOptions {
|
|
6
|
+
/** Override the default registry from context */
|
|
7
|
+
registry?: DataSourceRegistry | undefined;
|
|
8
|
+
/** Base URL for API calls (e.g., "https://api.fluid.app/api") */
|
|
9
|
+
baseUrl?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook that fetches and resolves data sources for a widget using React Query.
|
|
13
|
+
*/
|
|
14
|
+
declare function useWidgetData<T = Record<string, unknown>>(widget: WidgetSchema, options?: UseWidgetDataOptions): WidgetDataResult<T>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { useWidgetData };
|
|
17
|
+
//# sourceMappingURL=use-widget-data.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-data.d.mts","names":[],"sources":["../../src/data-sources/use-widget-data.ts"],"mappings":";;;;UAWU,oBAAA;;EAER,QAAA,GAAW,kBAAA;EAFiB;EAI5B,OAAA;AAAA;;;;iBA6Fc,aAAA,KAAkB,MAAA,kBAAA,CAChC,MAAA,EAAQ,YAAA,EACR,OAAA,GAAU,oBAAA,GACT,gBAAA,CAAiB,CAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useDataSourceRegistryConfig } from "./registry-context.mjs";
|
|
2
|
+
import { useCallback, useRef } from "react";
|
|
3
|
+
import { useQueries } from "@tanstack/react-query";
|
|
4
|
+
//#region src/data-sources/use-widget-data.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generates a unique key for a data source to use in query caching.
|
|
7
|
+
*/
|
|
8
|
+
function getSourceKey(source) {
|
|
9
|
+
if (source.type === "api") {
|
|
10
|
+
const varsKey = source.variables ? `:${JSON.stringify(source.variables)}` : "";
|
|
11
|
+
return `${source.endpoint}${varsKey}`;
|
|
12
|
+
}
|
|
13
|
+
if (source.type === "custom") return `custom:${(source.selectedItems?.map((item) => {
|
|
14
|
+
return `${item.shareableType}:${item.id}`;
|
|
15
|
+
}) ?? []).join(",")}`;
|
|
16
|
+
if (source.type === "static") return `static:${source.staticType}:${source.selectedId}`;
|
|
17
|
+
return "unknown";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves query results into widget props by mapping each source's result
|
|
21
|
+
* to its target props.
|
|
22
|
+
*/
|
|
23
|
+
function resolvePropsFromQueries(queryResults, sources, errorConfig) {
|
|
24
|
+
if (sources.length === 0) return void 0;
|
|
25
|
+
if (queryResults.some((q) => q.isLoading && !q.data)) return void 0;
|
|
26
|
+
const hasError = !!queryResults.find((q) => q.error)?.error;
|
|
27
|
+
if (hasError && errorConfig?.fallback) return errorConfig.fallback;
|
|
28
|
+
if (hasError) return;
|
|
29
|
+
const resolvedProps = {};
|
|
30
|
+
for (const query of queryResults) {
|
|
31
|
+
if (!query.data) continue;
|
|
32
|
+
const { source, result } = query.data;
|
|
33
|
+
if (!source?.targetProps) continue;
|
|
34
|
+
if (result !== null && typeof result === "object" && !Array.isArray(result) && source.targetProps.length > 1) {
|
|
35
|
+
const resultObj = result;
|
|
36
|
+
for (const prop of source.targetProps) if (prop in resultObj) resolvedProps[prop] = resultObj[prop];
|
|
37
|
+
} else for (const prop of source.targetProps) resolvedProps[prop] = result;
|
|
38
|
+
}
|
|
39
|
+
return resolvedProps;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Hook that fetches and resolves data sources for a widget using React Query.
|
|
43
|
+
*/
|
|
44
|
+
function useWidgetData(widget, options) {
|
|
45
|
+
const config = useDataSourceRegistryConfig();
|
|
46
|
+
const registry = options?.registry ?? config.registry;
|
|
47
|
+
const baseUrl = options?.baseUrl ?? config.baseUrl;
|
|
48
|
+
const getApiHeaders = config.getApiHeaders;
|
|
49
|
+
const variables = config.variables;
|
|
50
|
+
const sources = widget.dataSource?.sources ?? [];
|
|
51
|
+
const errorConfig = widget.dataSource?.error;
|
|
52
|
+
const widgetId = widget.id ?? "unknown";
|
|
53
|
+
const widgetType = widget.type;
|
|
54
|
+
const queryResultsRef = useRef([]);
|
|
55
|
+
const results = useQueries({ queries: sources.map((source) => ({
|
|
56
|
+
queryKey: [
|
|
57
|
+
"rep-widget-data",
|
|
58
|
+
getSourceKey(source),
|
|
59
|
+
baseUrl,
|
|
60
|
+
variables
|
|
61
|
+
],
|
|
62
|
+
queryFn: async ({ signal }) => {
|
|
63
|
+
const context = {
|
|
64
|
+
widgetId,
|
|
65
|
+
widgetType,
|
|
66
|
+
signal,
|
|
67
|
+
baseUrl,
|
|
68
|
+
getApiHeaders,
|
|
69
|
+
variables
|
|
70
|
+
};
|
|
71
|
+
const fetcher = registry.fetchers[source.type];
|
|
72
|
+
if (!fetcher) throw new Error(`No fetcher registered for source type: ${source.type}`);
|
|
73
|
+
let result = await fetcher(source, context);
|
|
74
|
+
if (source.transform) {
|
|
75
|
+
const transformer = registry.transformers[source.transform];
|
|
76
|
+
if (transformer) result = transformer(result, source);
|
|
77
|
+
else console.warn(`Transform "${source.transform}" not found in registry`);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
source,
|
|
81
|
+
result
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
enabled: sources.length > 0,
|
|
85
|
+
retry: errorConfig?.retryCount ?? 0,
|
|
86
|
+
retryDelay: errorConfig?.retryDelay ?? 1e3,
|
|
87
|
+
refetchInterval: source.refreshInterval || false
|
|
88
|
+
})) });
|
|
89
|
+
queryResultsRef.current = results;
|
|
90
|
+
const isLoading = results.some((q) => q.isLoading);
|
|
91
|
+
const failedQuery = results.find((q) => q.error);
|
|
92
|
+
const error = failedQuery?.error instanceof Error ? failedQuery.error : failedQuery?.error ? new Error(String(failedQuery.error)) : null;
|
|
93
|
+
return {
|
|
94
|
+
data: resolvePropsFromQueries(results.map((q) => ({
|
|
95
|
+
data: q.data,
|
|
96
|
+
isLoading: q.isLoading,
|
|
97
|
+
error: q.error instanceof Error ? q.error : null
|
|
98
|
+
})), sources, errorConfig),
|
|
99
|
+
isLoading,
|
|
100
|
+
error,
|
|
101
|
+
refetch: useCallback(() => {
|
|
102
|
+
queryResultsRef.current.forEach((q) => q.refetch());
|
|
103
|
+
}, [])
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { useWidgetData };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=use-widget-data.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-widget-data.mjs","names":[],"sources":["../../src/data-sources/use-widget-data.ts"],"sourcesContent":["import { useQueries } from \"@tanstack/react-query\";\nimport { useCallback, useRef } from \"react\";\nimport type { WidgetSchema } from \"../types/widget-schema\";\nimport type {\n DataSourceRegistry,\n WidgetDataResult,\n DataSourceContext,\n DataSource,\n} from \"./types\";\nimport { useDataSourceRegistryConfig } from \"./registry-context\";\n\ninterface UseWidgetDataOptions {\n /** Override the default registry from context */\n registry?: DataSourceRegistry | undefined;\n /** Base URL for API calls (e.g., \"https://api.fluid.app/api\") */\n baseUrl?: string | undefined;\n}\n\n/** Result shape from a single source query */\ninterface SourceQueryResult {\n source: DataSource;\n result: unknown;\n}\n\n/**\n * Generates a unique key for a data source to use in query caching.\n */\nfunction getSourceKey(source: DataSource): string {\n if (source.type === \"api\") {\n const varsKey = source.variables\n ? `:${JSON.stringify(source.variables)}`\n : \"\";\n return `${source.endpoint}${varsKey}`;\n }\n if (source.type === \"custom\") {\n const itemKeys =\n source.selectedItems?.map((item) => {\n return `${item.shareableType}:${item.id}`;\n }) ?? [];\n return `custom:${itemKeys.join(\",\")}`;\n }\n if (source.type === \"static\") {\n return `static:${source.staticType}:${source.selectedId}`;\n }\n return \"unknown\";\n}\n\n/**\n * Resolves query results into widget props by mapping each source's result\n * to its target props.\n */\nfunction resolvePropsFromQueries<T>(\n queryResults: ReadonlyArray<{\n data?: SourceQueryResult | undefined;\n isLoading: boolean;\n error: Error | null;\n }>,\n sources: DataSource[],\n errorConfig?: { fallback?: unknown },\n): T | undefined {\n if (sources.length === 0) return undefined;\n if (queryResults.some((q) => q.isLoading && !q.data)) return undefined;\n\n const failedQuery = queryResults.find((q) => q.error);\n const hasError = !!failedQuery?.error;\n\n if (hasError && errorConfig?.fallback) {\n return errorConfig.fallback as T;\n }\n\n if (hasError) {\n return undefined;\n }\n\n const resolvedProps: Record<string, unknown> = {};\n\n for (const query of queryResults) {\n if (!query.data) continue;\n const { source, result } = query.data;\n\n // Sentry fix: FLUID-ADMIN-1DH — source or targetProps can be undefined from malformed widget config\n if (!source?.targetProps) continue;\n\n if (\n result !== null &&\n typeof result === \"object\" &&\n !Array.isArray(result) &&\n source.targetProps.length > 1\n ) {\n const resultObj = result as Record<string, unknown>;\n for (const prop of source.targetProps) {\n if (prop in resultObj) {\n resolvedProps[prop] = resultObj[prop];\n }\n }\n } else {\n for (const prop of source.targetProps) {\n resolvedProps[prop] = result;\n }\n }\n }\n\n return resolvedProps as T;\n}\n\n/**\n * Hook that fetches and resolves data sources for a widget using React Query.\n */\nexport function useWidgetData<T = Record<string, unknown>>(\n widget: WidgetSchema,\n options?: UseWidgetDataOptions,\n): WidgetDataResult<T> {\n const config = useDataSourceRegistryConfig();\n const registry = options?.registry ?? config.registry;\n const baseUrl = options?.baseUrl ?? config.baseUrl;\n const getApiHeaders = config.getApiHeaders;\n const variables = config.variables;\n\n const sources = widget.dataSource?.sources ?? [];\n const errorConfig = widget.dataSource?.error;\n const widgetId = widget.id ?? \"unknown\";\n const widgetType = widget.type;\n\n const queryResultsRef = useRef<Array<{ refetch: () => void }>>([]);\n\n const results = useQueries({\n queries: sources.map((source: DataSource) => ({\n queryKey: [\n \"rep-widget-data\",\n getSourceKey(source),\n baseUrl,\n variables,\n ] as const,\n queryFn: async ({\n signal,\n }: {\n signal: AbortSignal;\n }): Promise<SourceQueryResult> => {\n const context: DataSourceContext = {\n widgetId,\n widgetType,\n signal,\n baseUrl,\n getApiHeaders,\n variables,\n };\n\n const fetcher = registry.fetchers[source.type];\n if (!fetcher) {\n throw new Error(\n `No fetcher registered for source type: ${source.type}`,\n );\n }\n\n const rawData = await fetcher(source, context);\n\n // Apply transform\n let result = rawData;\n if (source.transform) {\n const transformer = registry.transformers[source.transform];\n if (transformer) {\n result = transformer(result, source);\n } else {\n console.warn(\n `Transform \"${source.transform}\" not found in registry`,\n );\n }\n }\n return { source, result };\n },\n enabled: sources.length > 0,\n retry: errorConfig?.retryCount ?? 0,\n retryDelay: errorConfig?.retryDelay ?? 1000,\n refetchInterval: source.refreshInterval || false,\n })),\n });\n\n // Update ref for refetch callback\n queryResultsRef.current = results;\n\n // Aggregate loading state\n const isLoading = results.some((q) => q.isLoading);\n\n // Get first error from any failed query\n const failedQuery = results.find((q) => q.error);\n const error =\n failedQuery?.error instanceof Error\n ? failedQuery.error\n : failedQuery?.error\n ? new Error(String(failedQuery.error))\n : null;\n\n // Resolve data from all queries\n const data = resolvePropsFromQueries<T>(\n results.map((q) => ({\n data: q.data as SourceQueryResult | undefined,\n isLoading: q.isLoading,\n error: q.error instanceof Error ? q.error : null,\n })),\n sources,\n errorConfig,\n );\n\n // Stable refetch callback using ref\n const refetch = useCallback(() => {\n queryResultsRef.current.forEach((q) => q.refetch());\n }, []);\n\n return {\n data,\n isLoading,\n error,\n refetch,\n };\n}\n"],"mappings":";;;;;;;AA2BA,SAAS,aAAa,QAA4B;AAChD,KAAI,OAAO,SAAS,OAAO;EACzB,MAAM,UAAU,OAAO,YACnB,IAAI,KAAK,UAAU,OAAO,UAAU,KACpC;AACJ,SAAO,GAAG,OAAO,WAAW;;AAE9B,KAAI,OAAO,SAAS,SAKlB,QAAO,WAHL,OAAO,eAAe,KAAK,SAAS;AAClC,SAAO,GAAG,KAAK,cAAc,GAAG,KAAK;GACrC,IAAI,EAAE,EACgB,KAAK,IAAI;AAErC,KAAI,OAAO,SAAS,SAClB,QAAO,UAAU,OAAO,WAAW,GAAG,OAAO;AAE/C,QAAO;;;;;;AAOT,SAAS,wBACP,cAKA,SACA,aACe;AACf,KAAI,QAAQ,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