@everysk/apps-sdk 0.2.0 → 0.3.0-beta-20261019175049
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/README.md +342 -12
- package/dist/EveryskApp.d.ts +34 -2
- package/dist/EveryskApp.d.ts.map +1 -1
- package/dist/EveryskApp.js +35 -2
- package/dist/EveryskApp.js.map +1 -1
- package/dist/agGrid/handleRowsScrollEnd.d.ts +53 -0
- package/dist/agGrid/handleRowsScrollEnd.d.ts.map +1 -0
- package/dist/agGrid/handleRowsScrollEnd.js +47 -0
- package/dist/agGrid/handleRowsScrollEnd.js.map +1 -0
- package/dist/agGrid/index.d.ts +2 -0
- package/dist/agGrid/index.d.ts.map +1 -1
- package/dist/agGrid/index.js +2 -1
- package/dist/api/datastore.d.ts +10 -8
- package/dist/api/datastore.d.ts.map +1 -1
- package/dist/api/datastore.js +24 -55
- package/dist/api/datastore.js.map +1 -1
- package/dist/api/entityQuery.d.ts +46 -41
- package/dist/api/entityQuery.d.ts.map +1 -1
- package/dist/api/entityQuery.js +55 -14
- package/dist/api/entityQuery.js.map +1 -1
- package/dist/api/file.d.ts +26 -9
- package/dist/api/file.d.ts.map +1 -1
- package/dist/api/file.js +45 -55
- package/dist/api/file.js.map +1 -1
- package/dist/api/portfolio.d.ts +11 -8
- package/dist/api/portfolio.d.ts.map +1 -1
- package/dist/api/portfolio.js +24 -55
- package/dist/api/portfolio.js.map +1 -1
- package/dist/api/profile.d.ts +3 -2
- package/dist/api/profile.d.ts.map +1 -1
- package/dist/api/profile.js +4 -9
- package/dist/api/profile.js.map +1 -1
- package/dist/api/request.d.ts +106 -0
- package/dist/api/request.d.ts.map +1 -0
- package/dist/api/request.js +132 -0
- package/dist/api/request.js.map +1 -0
- package/dist/api/websocketsConfig.d.ts +7 -2
- package/dist/api/websocketsConfig.d.ts.map +1 -1
- package/dist/api/websocketsConfig.js +2 -10
- package/dist/api/websocketsConfig.js.map +1 -1
- package/dist/api/workflow.d.ts +84 -89
- package/dist/api/workflow.d.ts.map +1 -1
- package/dist/api/workflow.js +121 -208
- package/dist/api/workflow.js.map +1 -1
- package/dist/api/workspace.d.ts +18 -8
- package/dist/api/workspace.d.ts.map +1 -1
- package/dist/api/workspace.js +21 -26
- package/dist/api/workspace.js.map +1 -1
- package/dist/components/ui/Footer/index.d.ts.map +1 -1
- package/dist/components/ui/Footer/index.js.map +1 -1
- package/dist/components/ui/GlobalLoading/index.d.ts.map +1 -1
- package/dist/components/ui/GlobalLoading/index.js.map +1 -1
- package/dist/components/ui/PageContainer/index.d.ts +1 -1
- package/dist/components/ui/PageContainer/index.d.ts.map +1 -1
- package/dist/components/ui/PageContainer/index.js.map +1 -1
- package/dist/components/ui/Toolbar/index.d.ts +40 -3
- package/dist/components/ui/Toolbar/index.d.ts.map +1 -1
- package/dist/components/ui/Toolbar/index.js +42 -15
- package/dist/components/ui/Toolbar/index.js.map +1 -1
- package/dist/contexts/appAlertContext/provider.js.map +1 -1
- package/dist/contexts/appAlertContext/types.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/index.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/index.js.map +1 -1
- package/dist/contexts/appConfigContext/provider.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/provider.js.map +1 -1
- package/dist/contexts/webSocketContext/handler.d.ts +3 -2
- package/dist/contexts/webSocketContext/handler.d.ts.map +1 -1
- package/dist/contexts/webSocketContext/handler.js.map +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.d.ts +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js.map +1 -1
- package/dist/contexts/webSocketContext/provider.d.ts +6 -3
- package/dist/contexts/webSocketContext/provider.d.ts.map +1 -1
- package/dist/contexts/webSocketContext/provider.js +42 -7
- package/dist/contexts/webSocketContext/provider.js.map +1 -1
- package/dist/contexts/webSocketContext/types.d.ts +7 -5
- package/dist/contexts/webSocketContext/types.d.ts.map +1 -1
- package/dist/file/index.d.ts +2 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/hooks/datastore/useDatastoreMutations.d.ts +4 -4
- package/dist/hooks/datastore/useDatastoreMutations.d.ts.map +1 -1
- package/dist/hooks/datastore/useDatastoreMutations.js +17 -55
- package/dist/hooks/datastore/useDatastoreMutations.js.map +1 -1
- package/dist/hooks/datastore/useFetchDatastore.d.ts +30 -41
- package/dist/hooks/datastore/useFetchDatastore.d.ts.map +1 -1
- package/dist/hooks/datastore/useFetchDatastore.js +25 -59
- package/dist/hooks/datastore/useFetchDatastore.js.map +1 -1
- package/dist/hooks/datastore/useFetchDatastores.d.ts +47 -52
- package/dist/hooks/datastore/useFetchDatastores.d.ts.map +1 -1
- package/dist/hooks/datastore/useFetchDatastores.js +55 -70
- package/dist/hooks/datastore/useFetchDatastores.js.map +1 -1
- package/dist/hooks/file/fileData.d.ts +17 -0
- package/dist/hooks/file/fileData.d.ts.map +1 -0
- package/dist/hooks/file/fileData.js +10 -0
- package/dist/hooks/file/fileData.js.map +1 -0
- package/dist/hooks/file/useFetchFile.d.ts +38 -58
- package/dist/hooks/file/useFetchFile.d.ts.map +1 -1
- package/dist/hooks/file/useFetchFile.js +26 -66
- package/dist/hooks/file/useFetchFile.js.map +1 -1
- package/dist/hooks/file/useFetchFiles.d.ts +18 -52
- package/dist/hooks/file/useFetchFiles.d.ts.map +1 -1
- package/dist/hooks/file/useFetchFiles.js +53 -69
- package/dist/hooks/file/useFetchFiles.js.map +1 -1
- package/dist/hooks/file/useFileMutations.d.ts +9 -8
- package/dist/hooks/file/useFileMutations.d.ts.map +1 -1
- package/dist/hooks/file/useFileMutations.js +23 -60
- package/dist/hooks/file/useFileMutations.js.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolio.d.ts +16 -50
- package/dist/hooks/portfolio/useFetchPortfolio.d.ts.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolio.js +15 -63
- package/dist/hooks/portfolio/useFetchPortfolio.js.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolios.d.ts +13 -52
- package/dist/hooks/portfolio/useFetchPortfolios.d.ts.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolios.js +29 -71
- package/dist/hooks/portfolio/useFetchPortfolios.js.map +1 -1
- package/dist/hooks/portfolio/usePortfolioMutations.d.ts +8 -8
- package/dist/hooks/portfolio/usePortfolioMutations.d.ts.map +1 -1
- package/dist/hooks/portfolio/usePortfolioMutations.js +20 -58
- package/dist/hooks/portfolio/usePortfolioMutations.js.map +1 -1
- package/dist/hooks/profile/useFetchProfile.d.ts +18 -44
- package/dist/hooks/profile/useFetchProfile.d.ts.map +1 -1
- package/dist/hooks/profile/useFetchProfile.js +16 -48
- package/dist/hooks/profile/useFetchProfile.js.map +1 -1
- package/dist/hooks/useAxios.js.map +1 -1
- package/dist/hooks/useEntityInfiniteQuery.d.ts +88 -0
- package/dist/hooks/useEntityInfiniteQuery.d.ts.map +1 -0
- package/dist/hooks/useEntityInfiniteQuery.js +111 -0
- package/dist/hooks/useEntityInfiniteQuery.js.map +1 -0
- package/dist/hooks/useEntityMutation.d.ts +47 -0
- package/dist/hooks/useEntityMutation.d.ts.map +1 -0
- package/dist/hooks/useEntityMutation.js +58 -0
- package/dist/hooks/useEntityMutation.js.map +1 -0
- package/dist/hooks/useEntityQuery.d.ts +68 -0
- package/dist/hooks/useEntityQuery.d.ts.map +1 -0
- package/dist/hooks/useEntityQuery.js +75 -0
- package/dist/hooks/useEntityQuery.js.map +1 -0
- package/dist/hooks/workflow/useFetchWorkerExecution.d.ts +17 -34
- package/dist/hooks/workflow/useFetchWorkerExecution.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecution.js +16 -46
- package/dist/hooks/workflow/useFetchWorkerExecution.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts +179 -41
- package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecutions.js +29 -62
- package/dist/hooks/workflow/useFetchWorkerExecutions.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflow.d.ts +16 -35
- package/dist/hooks/workflow/useFetchWorkflow.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflow.js +15 -48
- package/dist/hooks/workflow/useFetchWorkflow.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts +17 -34
- package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecution.js +16 -46
- package/dist/hooks/workflow/useFetchWorkflowExecution.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts +22 -36
- package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecutions.js +43 -56
- package/dist/hooks/workflow/useFetchWorkflowExecutions.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflows.d.ts +20 -37
- package/dist/hooks/workflow/useFetchWorkflows.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflows.js +32 -47
- package/dist/hooks/workflow/useFetchWorkflows.js.map +1 -1
- package/dist/hooks/workflow/useRunWorkflow.d.ts +21 -16
- package/dist/hooks/workflow/useRunWorkflow.d.ts.map +1 -1
- package/dist/hooks/workflow/useRunWorkflow.js +66 -29
- package/dist/hooks/workflow/useRunWorkflow.js.map +1 -1
- package/dist/hooks/workflow/useTriggerWorkflow.d.ts +20 -0
- package/dist/hooks/workflow/useTriggerWorkflow.d.ts.map +1 -0
- package/dist/hooks/workflow/useTriggerWorkflow.js +32 -0
- package/dist/hooks/workflow/useTriggerWorkflow.js.map +1 -0
- package/dist/hooks/workspace/useFetchWorkspace.d.ts +19 -34
- package/dist/hooks/workspace/useFetchWorkspace.d.ts.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspace.js +16 -46
- package/dist/hooks/workspace/useFetchWorkspace.js.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspaces.d.ts +17 -37
- package/dist/hooks/workspace/useFetchWorkspaces.d.ts.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspaces.js +25 -47
- package/dist/hooks/workspace/useFetchWorkspaces.js.map +1 -1
- package/dist/index.d.ts +13 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/lib/abort.d.ts +58 -0
- package/dist/lib/abort.d.ts.map +1 -0
- package/dist/lib/abort.js +112 -0
- package/dist/lib/abort.js.map +1 -0
- package/dist/lib/datastoreTable.d.ts +59 -54
- package/dist/lib/datastoreTable.d.ts.map +1 -1
- package/dist/lib/datastoreTable.js +58 -62
- package/dist/lib/datastoreTable.js.map +1 -1
- package/dist/lib/file.d.ts +34 -0
- package/dist/lib/file.d.ts.map +1 -0
- package/dist/lib/file.js +63 -0
- package/dist/lib/file.js.map +1 -0
- package/dist/lib/queryClient.d.ts.map +1 -1
- package/dist/lib/queryClient.js.map +1 -1
- package/dist/lib/workflowRun.d.ts +91 -0
- package/dist/lib/workflowRun.d.ts.map +1 -0
- package/dist/lib/workflowRun.js +224 -0
- package/dist/lib/workflowRun.js.map +1 -0
- package/dist/socket/index.d.ts +1 -3
- package/dist/socket/index.d.ts.map +1 -1
- package/dist/socket/index.js +3 -5
- package/dist/test/mocks/index.d.ts +1 -1
- package/dist/test/mocks/index.d.ts.map +1 -1
- package/dist/test/msw/fakeApi.d.ts +43 -0
- package/dist/test/msw/fakeApi.d.ts.map +1 -0
- package/dist/test/msw/fakeApi.js +74 -0
- package/dist/test/msw/fakeApi.js.map +1 -0
- package/dist/test/msw/handlers.d.ts +20 -0
- package/dist/test/msw/handlers.d.ts.map +1 -0
- package/dist/test/msw/handlers.js +279 -0
- package/dist/test/msw/handlers.js.map +1 -0
- package/dist/test/msw/index.d.ts +5 -0
- package/dist/test/msw/index.d.ts.map +1 -0
- package/dist/test/msw/index.js +2 -0
- package/dist/test/msw/query.d.ts +34 -0
- package/dist/test/msw/query.d.ts.map +1 -0
- package/dist/test/msw/query.js +96 -0
- package/dist/test/msw/query.js.map +1 -0
- package/dist/test/msw/recorder.d.ts +30 -0
- package/dist/test/msw/recorder.d.ts.map +1 -0
- package/dist/test/msw/recorder.js +65 -0
- package/dist/test/msw/recorder.js.map +1 -0
- package/dist/test/msw/store.d.ts +57 -0
- package/dist/test/msw/store.d.ts.map +1 -0
- package/dist/test/msw/store.js +145 -0
- package/dist/test/msw/store.js.map +1 -0
- package/dist/test/renderWithProviders.d.ts +2 -2
- package/dist/test/renderWithProviders.d.ts.map +1 -1
- package/dist/test/renderWithProviders.js.map +1 -1
- package/dist/test/setup.js.map +1 -1
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/overrides/index.d.ts +4 -2
- package/dist/theme/overrides/index.d.ts.map +1 -1
- package/dist/theme/overrides/index.js +5 -3
- package/dist/theme/overrides/index.js.map +1 -1
- package/dist/theme/overrides/muiButton.d.ts +2 -2
- package/dist/theme/overrides/muiButton.js.map +1 -1
- package/dist/theme/overrides/muiCssBaseline.d.ts.map +1 -1
- package/dist/theme/overrides/muiCssBaseline.js.map +1 -1
- package/dist/theme/overrides/muiDatePicker.js.map +1 -1
- package/dist/theme/overrides/muiFormControl.js.map +1 -1
- package/dist/theme/overrides/muiIconButton.d.ts +2 -2
- package/dist/theme/overrides/muiIconButton.js.map +1 -1
- package/dist/theme/overrides/muiSelect.d.ts.map +1 -1
- package/dist/theme/overrides/muiSelect.js.map +1 -1
- package/dist/theme/overrides/muiSvgIcon.d.ts.map +1 -1
- package/dist/theme/overrides/muiSvgIcon.js.map +1 -1
- package/dist/theme/overrides/muiTextField.js.map +1 -1
- package/dist/theme/overrides/muiToggleButton.d.ts +2 -2
- package/dist/theme/overrides/muiToggleButton.js.map +1 -1
- package/dist/theme/overrides/muiToggleButtonGroup.d.ts +2 -2
- package/dist/theme/overrides/muiToggleButtonGroup.js.map +1 -1
- package/dist/theme/themes/DefaultDark.js +2 -2
- package/dist/theme/themes/DefaultDark.js.map +1 -1
- package/dist/theme/themes/DefaultLight.js +2 -2
- package/dist/theme/themes/DefaultLight.js.map +1 -1
- package/dist/theme/themes/EveryskDark.js +2 -2
- package/dist/theme/themes/EveryskDark.js.map +1 -1
- package/dist/theme/themes/EveryskLight.js +2 -2
- package/dist/theme/themes/EveryskLight.js.map +1 -1
- package/dist/theme/themes/MidnightEmber.js +2 -2
- package/dist/theme/themes/MidnightEmber.js.map +1 -1
- package/dist/types/anyRecord.d.ts.map +1 -1
- package/dist/types/datastore.d.ts +35 -5
- package/dist/types/datastore.d.ts.map +1 -1
- package/dist/types/datastoreDataFormat.d.ts +13 -0
- package/dist/types/datastoreDataFormat.d.ts.map +1 -0
- package/dist/types/entityQuery.d.ts +86 -16
- package/dist/types/entityQuery.d.ts.map +1 -1
- package/dist/types/file.d.ts +7 -3
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/portfolio.d.ts +1 -3
- package/dist/types/portfolio.d.ts.map +1 -1
- package/dist/types/profile.d.ts +0 -10
- package/dist/types/profile.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +35 -6
- package/dist/types/workflow.d.ts.map +1 -1
- package/dist/types/workspace.d.ts +1 -2
- package/dist/types/workspace.d.ts.map +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/workflow/index.d.ts +2 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/package.json +10 -1
- package/src/EveryskApp.tsx +53 -2
- package/src/agGrid/handleRowsScrollEnd.ts +71 -0
- package/src/agGrid/index.ts +5 -1
- package/src/api/datastore.ts +79 -107
- package/src/api/entityQuery.ts +86 -17
- package/src/api/file.ts +110 -103
- package/src/api/portfolio.ts +82 -125
- package/src/api/profile.ts +25 -18
- package/src/api/request.ts +168 -0
- package/src/api/websocketsConfig.ts +11 -19
- package/src/api/workflow.ts +232 -334
- package/src/api/workspace.ts +43 -43
- package/src/components/ui/Footer/index.tsx +8 -7
- package/src/components/ui/GlobalLoading/index.tsx +13 -3
- package/src/components/ui/PageContainer/index.tsx +9 -2
- package/src/components/ui/Toolbar/index.tsx +105 -30
- package/src/contexts/appAlertContext/provider.tsx +1 -1
- package/src/contexts/appAlertContext/types.ts +3 -3
- package/src/contexts/appConfigContext/index.tsx +1 -1
- package/src/contexts/appConfigContext/provider.tsx +1 -5
- package/src/contexts/webSocketContext/handler.ts +8 -2
- package/src/contexts/webSocketContext/hooks/useWebSocket/index.ts +1 -1
- package/src/contexts/webSocketContext/provider.tsx +64 -14
- package/src/contexts/webSocketContext/types.ts +7 -6
- package/src/file/index.ts +2 -0
- package/src/hooks/datastore/useDatastoreMutations.ts +19 -60
- package/src/hooks/datastore/useFetchDatastore.ts +45 -73
- package/src/hooks/datastore/useFetchDatastores.ts +106 -131
- package/src/hooks/file/fileData.ts +19 -0
- package/src/hooks/file/useFetchFile.ts +41 -76
- package/src/hooks/file/useFetchFiles.ts +92 -87
- package/src/hooks/file/useFileMutations.ts +23 -73
- package/src/hooks/portfolio/useFetchPortfolio.ts +26 -78
- package/src/hooks/portfolio/useFetchPortfolios.ts +50 -93
- package/src/hooks/portfolio/usePortfolioMutations.ts +22 -72
- package/src/hooks/profile/useFetchProfile.ts +24 -65
- package/src/hooks/useAxios.ts +5 -5
- package/src/hooks/useEntityInfiniteQuery.ts +193 -0
- package/src/hooks/useEntityMutation.ts +70 -0
- package/src/hooks/useEntityQuery.ts +117 -0
- package/src/hooks/workflow/useFetchWorkerExecution.ts +27 -56
- package/src/hooks/workflow/useFetchWorkerExecutions.ts +54 -79
- package/src/hooks/workflow/useFetchWorkflow.ts +24 -58
- package/src/hooks/workflow/useFetchWorkflowExecution.ts +27 -57
- package/src/hooks/workflow/useFetchWorkflowExecutions.ts +64 -73
- package/src/hooks/workflow/useFetchWorkflows.ts +48 -64
- package/src/hooks/workflow/useRunWorkflow.ts +82 -36
- package/src/hooks/workflow/useTriggerWorkflow.ts +36 -0
- package/src/hooks/workspace/useFetchWorkspace.ts +25 -58
- package/src/hooks/workspace/useFetchWorkspaces.ts +38 -69
- package/src/index.ts +34 -19
- package/src/lib/abort.ts +131 -0
- package/src/lib/datastoreTable.ts +127 -74
- package/src/lib/file.ts +67 -0
- package/src/lib/queryClient.ts +11 -13
- package/src/lib/workflowRun.ts +329 -0
- package/src/socket/index.ts +1 -3
- package/src/test/mocks/index.ts +1 -5
- package/src/test/msw/fakeApi.ts +83 -0
- package/src/test/msw/handlers.ts +350 -0
- package/src/test/msw/index.ts +9 -0
- package/src/test/msw/query.ts +134 -0
- package/src/test/msw/recorder.ts +88 -0
- package/src/test/msw/store.ts +182 -0
- package/src/test/renderWithProviders.tsx +8 -3
- package/src/test/setup.ts +16 -16
- package/src/theme/index.ts +1 -1
- package/src/theme/overrides/index.ts +5 -3
- package/src/theme/overrides/muiButton.ts +3 -3
- package/src/theme/overrides/muiCssBaseline.ts +11 -12
- package/src/theme/overrides/muiDatePicker.ts +2 -2
- package/src/theme/overrides/muiFormControl.ts +2 -2
- package/src/theme/overrides/muiIconButton.ts +3 -3
- package/src/theme/overrides/muiSelect.ts +2 -2
- package/src/theme/overrides/muiSvgIcon.ts +2 -2
- package/src/theme/overrides/muiTextField.ts +1 -1
- package/src/theme/overrides/muiToggleButton.ts +4 -4
- package/src/theme/overrides/muiToggleButtonGroup.ts +4 -4
- package/src/theme/themes/DefaultDark.ts +2 -2
- package/src/theme/themes/DefaultLight.ts +2 -2
- package/src/theme/themes/EveryskDark.ts +2 -2
- package/src/theme/themes/EveryskLight.ts +2 -2
- package/src/theme/themes/MidnightEmber.ts +15 -15
- package/src/types/anyRecord.ts +2 -2
- package/src/types/datastore.ts +56 -22
- package/src/types/datastoreDataFormat.ts +12 -0
- package/src/types/entityQuery.ts +122 -38
- package/src/types/file.ts +8 -6
- package/src/types/portfolio.ts +70 -74
- package/src/types/profile.ts +0 -11
- package/src/types/workflow.ts +38 -9
- package/src/types/workspace.ts +2 -4
- package/src/ui/index.ts +1 -1
- package/src/workflow/index.ts +5 -0
package/src/api/file.ts
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
3
|
+
import type { EveryskFile, FileListResponse } from "@/types/file";
|
|
4
|
+
import type {
|
|
5
|
+
DeletedEntity,
|
|
6
|
+
DeleteEntityResponse,
|
|
7
|
+
EntitySingleResponse,
|
|
8
|
+
QueryObject,
|
|
9
|
+
} from "@/types/entityQuery";
|
|
10
|
+
import { listParams, request, requireWorkspace } from "./request";
|
|
6
11
|
|
|
7
12
|
const baseUrl = "files";
|
|
8
13
|
|
|
14
|
+
/** The endpoint's envelopes, private: every function here returns the entity itself. */
|
|
15
|
+
type FileSingleResponse = EntitySingleResponse<"file", EveryskFile>;
|
|
16
|
+
type DeleteFileResponse = DeleteEntityResponse<"file">;
|
|
17
|
+
|
|
18
|
+
export type GetFileParams = {
|
|
19
|
+
/**
|
|
20
|
+
* `false` leaves `data` out (`null`): sent as `with_data=false`, which the API reads as the
|
|
21
|
+
* projection `-data` (everysk/client `EveryskAPIEngine_V2._get_entity_by_id`). The content
|
|
22
|
+
* comes as base64, a third larger than the file. The file hooks leave it out by default;
|
|
23
|
+
* this function, which mirrors the API, includes it.
|
|
24
|
+
*/
|
|
25
|
+
withData?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
9
28
|
/**
|
|
10
29
|
* getFile
|
|
11
30
|
*
|
|
@@ -14,27 +33,27 @@ const baseUrl = "files";
|
|
|
14
33
|
* @param {AxiosInstance} api - Axios instance.
|
|
15
34
|
* @param {string} id - EveryskFile identifier.
|
|
16
35
|
* @param {string} workspace - Workspace the file belongs to.
|
|
36
|
+
* @param {GetFileParams} [options] - Whether to include the content.
|
|
37
|
+
* @param {AbortSignal} [signal] - Aborts the request itself; the entity hooks pass the query's own.
|
|
17
38
|
* @returns {Promise<EveryskFile>} The fetched file.
|
|
18
39
|
*
|
|
19
40
|
* @throws {Error} If the request fails.
|
|
20
41
|
*/
|
|
21
|
-
export const getFile = async (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw new Error("Error while fetching file", { cause: error });
|
|
37
|
-
}
|
|
42
|
+
export const getFile = async (
|
|
43
|
+
api: AxiosInstance,
|
|
44
|
+
id: string,
|
|
45
|
+
workspace: string,
|
|
46
|
+
{ withData }: GetFileParams = {},
|
|
47
|
+
signal?: AbortSignal,
|
|
48
|
+
): Promise<EveryskFile> => {
|
|
49
|
+
requireWorkspace(workspace, "fetch a file");
|
|
50
|
+
|
|
51
|
+
const params = { workspace, ...(withData === false && { with_data: false }) };
|
|
52
|
+
const body = await request(
|
|
53
|
+
() => api.get<FileSingleResponse>(`${baseUrl}/${id}`, { params, signal }),
|
|
54
|
+
"Error fetching file",
|
|
55
|
+
);
|
|
56
|
+
return body.file;
|
|
38
57
|
};
|
|
39
58
|
|
|
40
59
|
/**
|
|
@@ -47,34 +66,36 @@ export const getFile = async (api: AxiosInstance, id: string, workspace: string)
|
|
|
47
66
|
*
|
|
48
67
|
* @param {AxiosInstance} api - Axios instance.
|
|
49
68
|
* @param {QueryObject} query - Query object built via `buildQueryObject`.
|
|
50
|
-
* @
|
|
69
|
+
* @param {AbortSignal} [signal] - Aborts the request itself; the list hooks pass the query's own.
|
|
70
|
+
* @returns {Promise<FileListResponse>} Paginated list of files.
|
|
51
71
|
*
|
|
72
|
+
* @throws {Error} If the query has no workspace filter.
|
|
52
73
|
* @throws {Error} If the request fails.
|
|
53
74
|
*/
|
|
54
|
-
export const listFiles = async (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
export const listFiles = async (
|
|
76
|
+
api: AxiosInstance,
|
|
77
|
+
query: QueryObject,
|
|
78
|
+
signal?: AbortSignal,
|
|
79
|
+
): Promise<FileListResponse> => {
|
|
80
|
+
const params = listParams(query, "list files");
|
|
81
|
+
|
|
82
|
+
return request(
|
|
83
|
+
() => api.get<FileListResponse>(baseUrl, { params, signal }),
|
|
84
|
+
"Error listing files",
|
|
85
|
+
);
|
|
86
|
+
};
|
|
64
87
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Refuses content sent as a data URL. The API stores `data` as given, so the
|
|
90
|
+
* `data:<type>;base64,` prefix `FileReader` puts in front would become part of the file, which
|
|
91
|
+
* then comes out corrupt with no error anywhere.
|
|
92
|
+
*/
|
|
93
|
+
const requireRawBase64 = ({ data }: Partial<EveryskFile>) => {
|
|
94
|
+
if (data?.startsWith("data:")) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"A file's data must be raw base64, without the data: prefix: read it with fileToBase64",
|
|
97
|
+
);
|
|
74
98
|
}
|
|
75
|
-
|
|
76
|
-
throw new Error("Error while fetching files", { cause: error });
|
|
77
|
-
}
|
|
78
99
|
};
|
|
79
100
|
|
|
80
101
|
/**
|
|
@@ -83,30 +104,25 @@ export const listFiles = async (api: AxiosInstance, query: QueryObject): Promise
|
|
|
83
104
|
* Creates a new file.
|
|
84
105
|
*
|
|
85
106
|
* @param {AxiosInstance} api - Axios instance.
|
|
86
|
-
* @param {Partial<EveryskFile>} data - EveryskFile payload.
|
|
107
|
+
* @param {Partial<EveryskFile>} data - EveryskFile payload. Its `data` is the content as raw
|
|
108
|
+
* base64, as `fileToBase64` returns it from a `File`.
|
|
87
109
|
* @returns {Promise<EveryskFile>} The created file.
|
|
88
110
|
*
|
|
111
|
+
* @throws {Error} If `workspace` is missing, or `data` is a data URL rather than raw base64.
|
|
89
112
|
* @throws {Error} If the request fails.
|
|
90
113
|
*/
|
|
91
|
-
export const createFile = async (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (error instanceof Error) {
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
throw new Error("Error while creating file", { cause: error });
|
|
109
|
-
}
|
|
114
|
+
export const createFile = async (
|
|
115
|
+
api: AxiosInstance,
|
|
116
|
+
data: Partial<EveryskFile>,
|
|
117
|
+
): Promise<EveryskFile> => {
|
|
118
|
+
requireWorkspace(data.workspace, "create a file");
|
|
119
|
+
requireRawBase64(data);
|
|
120
|
+
|
|
121
|
+
const body = await request(
|
|
122
|
+
() => api.post<FileSingleResponse>(baseUrl, data),
|
|
123
|
+
"Error creating file",
|
|
124
|
+
);
|
|
125
|
+
return body.file;
|
|
110
126
|
};
|
|
111
127
|
|
|
112
128
|
/**
|
|
@@ -116,30 +132,26 @@ export const createFile = async (api: AxiosInstance, data: Partial<EveryskFile>)
|
|
|
116
132
|
*
|
|
117
133
|
* @param {AxiosInstance} api - Axios instance.
|
|
118
134
|
* @param {string} id - EveryskFile identifier.
|
|
119
|
-
* @param {Partial<EveryskFile>} data - Fields to update.
|
|
135
|
+
* @param {Partial<EveryskFile>} data - Fields to update. A new `data` is the content as raw
|
|
136
|
+
* base64, as `fileToBase64` returns it from a `File`.
|
|
120
137
|
* @returns {Promise<EveryskFile>} The updated file.
|
|
121
138
|
*
|
|
139
|
+
* @throws {Error} If `workspace` is missing, or `data` is a data URL rather than raw base64.
|
|
122
140
|
* @throws {Error} If the request fails.
|
|
123
141
|
*/
|
|
124
|
-
export const updateFile = async (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (error instanceof Error) {
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
throw new Error("Error while updating file", { cause: error });
|
|
142
|
-
}
|
|
142
|
+
export const updateFile = async (
|
|
143
|
+
api: AxiosInstance,
|
|
144
|
+
id: string,
|
|
145
|
+
data: Partial<EveryskFile>,
|
|
146
|
+
): Promise<EveryskFile> => {
|
|
147
|
+
requireWorkspace(data.workspace, "update a file");
|
|
148
|
+
requireRawBase64(data);
|
|
149
|
+
|
|
150
|
+
const body = await request(
|
|
151
|
+
() => api.put<FileSingleResponse>(`${baseUrl}/${id}`, data),
|
|
152
|
+
"Error updating file",
|
|
153
|
+
);
|
|
154
|
+
return body.file;
|
|
143
155
|
};
|
|
144
156
|
|
|
145
157
|
/**
|
|
@@ -150,25 +162,20 @@ export const updateFile = async (api: AxiosInstance, id: string, data: Partial<E
|
|
|
150
162
|
* @param {AxiosInstance} api - Axios instance.
|
|
151
163
|
* @param {string} id - EveryskFile identifier.
|
|
152
164
|
* @param {string} workspace - Workspace the file belongs to.
|
|
153
|
-
* @returns {Promise<
|
|
165
|
+
* @returns {Promise<DeletedEntity>} The deletion record: id, name and `deleted`.
|
|
154
166
|
*
|
|
155
167
|
* @throws {Error} If the request fails.
|
|
156
168
|
*/
|
|
157
|
-
export const deleteFile = async (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
throw new Error("Error while deleting file", { cause: error });
|
|
173
|
-
}
|
|
174
|
-
};
|
|
169
|
+
export const deleteFile = async (
|
|
170
|
+
api: AxiosInstance,
|
|
171
|
+
id: string,
|
|
172
|
+
workspace: string,
|
|
173
|
+
): Promise<DeletedEntity> => {
|
|
174
|
+
requireWorkspace(workspace, "delete a file");
|
|
175
|
+
|
|
176
|
+
const body = await request(
|
|
177
|
+
() => api.delete<DeleteFileResponse>(`${baseUrl}/${id}`, { params: { workspace } }),
|
|
178
|
+
"Error deleting file",
|
|
179
|
+
);
|
|
180
|
+
return body.file;
|
|
181
|
+
};
|
package/src/api/portfolio.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type {
|
|
4
|
+
DeletedEntity,
|
|
5
|
+
DeleteEntityResponse,
|
|
6
|
+
EntitySingleResponse,
|
|
7
|
+
QueryObject,
|
|
8
|
+
} from "@/types/entityQuery";
|
|
9
|
+
import type { Portfolio, PortfolioListResponse } from "@/types/portfolio";
|
|
10
|
+
import { listParams, request, requireWorkspace } from "./request";
|
|
7
11
|
|
|
8
12
|
const baseUrl = "portfolios";
|
|
9
13
|
|
|
14
|
+
/** The endpoint's envelopes, private: every function here returns the entity itself. */
|
|
15
|
+
type PortfolioSingleResponse = EntitySingleResponse<"portfolio", Portfolio>;
|
|
16
|
+
type DeletePortfolioResponse = DeleteEntityResponse<"portfolio">;
|
|
17
|
+
|
|
10
18
|
/**
|
|
11
19
|
* getPortfolio
|
|
12
20
|
*
|
|
@@ -15,31 +23,25 @@ const baseUrl = "portfolios";
|
|
|
15
23
|
* @param {AxiosInstance} api - Axios instance.
|
|
16
24
|
* @param {string} id - Portfolio identifier.
|
|
17
25
|
* @param {string} workspace - Workspace the portfolio belongs to.
|
|
18
|
-
* @
|
|
26
|
+
* @param {AbortSignal} [signal] - Aborts the request itself; the entity hooks pass the query's own.
|
|
27
|
+
* @returns {Promise<Portfolio>} The fetched portfolio.
|
|
19
28
|
*
|
|
20
29
|
* @throws {Error} If the request fails.
|
|
21
30
|
*/
|
|
22
|
-
export const getPortfolio = async (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (error instanceof Error) {
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new Error("Error while fetching portfolio", { cause: error });
|
|
42
|
-
}
|
|
31
|
+
export const getPortfolio = async (
|
|
32
|
+
api: AxiosInstance,
|
|
33
|
+
id: string,
|
|
34
|
+
workspace: string,
|
|
35
|
+
signal?: AbortSignal,
|
|
36
|
+
): Promise<Portfolio> => {
|
|
37
|
+
requireWorkspace(workspace, "fetch a portfolio");
|
|
38
|
+
|
|
39
|
+
const body = await request(
|
|
40
|
+
() =>
|
|
41
|
+
api.get<PortfolioSingleResponse>(`${baseUrl}/${id}`, { params: { workspace }, signal }),
|
|
42
|
+
"Error fetching portfolio",
|
|
43
|
+
);
|
|
44
|
+
return body.portfolio;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
/**
|
|
@@ -49,38 +51,24 @@ export const getPortfolio = async (api: AxiosInstance, id: string, workspace: st
|
|
|
49
51
|
*
|
|
50
52
|
* @param {AxiosInstance} api - Axios instance.
|
|
51
53
|
* @param {QueryObject} query - Query object built via `buildQueryObject`.
|
|
54
|
+
* @param {AbortSignal} [signal] - Aborts the request itself; the list hooks pass the query's own.
|
|
52
55
|
* @returns {Promise<PortfolioListResponse>} List of portfolios.
|
|
53
56
|
*
|
|
57
|
+
* @throws {Error} If the query has no workspace filter.
|
|
54
58
|
* @throws {Error} If the request fails.
|
|
55
59
|
*/
|
|
56
|
-
export const listPortfolios = async (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const response: AxiosResponse<PortfolioListResponse> = await api.get(baseUrl, { params });
|
|
71
|
-
return response.data;
|
|
72
|
-
} catch (error: unknown) {
|
|
73
|
-
if (isAxiosError<AnyRecord>(error)) {
|
|
74
|
-
throw new Error(error.message || "Error while fetching portfolios", { cause: error });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (error instanceof Error) {
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
throw new Error("Error while fetching portfolios", { cause: error });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
60
|
+
export const listPortfolios = async (
|
|
61
|
+
api: AxiosInstance,
|
|
62
|
+
query: QueryObject,
|
|
63
|
+
signal?: AbortSignal,
|
|
64
|
+
): Promise<PortfolioListResponse> => {
|
|
65
|
+
const params = listParams(query, "list portfolios");
|
|
66
|
+
|
|
67
|
+
return request(
|
|
68
|
+
() => api.get<PortfolioListResponse>(baseUrl, { params, signal }),
|
|
69
|
+
"Error listing portfolios",
|
|
70
|
+
);
|
|
71
|
+
};
|
|
84
72
|
|
|
85
73
|
/**
|
|
86
74
|
* createPortfolio
|
|
@@ -93,29 +81,18 @@ export const listPortfolios = async (api: AxiosInstance, query: QueryObject): Pr
|
|
|
93
81
|
*
|
|
94
82
|
* @throws {Error} If the request fails.
|
|
95
83
|
*/
|
|
96
|
-
export const createPortfolio = async (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
if (isAxiosError<AnyRecord>(error)) {
|
|
109
|
-
throw new Error(error.message || "Error while creating portfolio", { cause: error });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (error instanceof Error) {
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
throw new Error("Error while creating portfolio", { cause: error });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
84
|
+
export const createPortfolio = async (
|
|
85
|
+
api: AxiosInstance,
|
|
86
|
+
data: Partial<Portfolio>,
|
|
87
|
+
): Promise<Portfolio> => {
|
|
88
|
+
requireWorkspace(data.workspace, "create a portfolio");
|
|
89
|
+
|
|
90
|
+
const body = await request(
|
|
91
|
+
() => api.post<PortfolioSingleResponse>(baseUrl, data),
|
|
92
|
+
"Error creating portfolio",
|
|
93
|
+
);
|
|
94
|
+
return body.portfolio;
|
|
95
|
+
};
|
|
119
96
|
|
|
120
97
|
/**
|
|
121
98
|
* updatePortfolio
|
|
@@ -129,29 +106,19 @@ export const createPortfolio = async (api: AxiosInstance, data: Partial<Portfoli
|
|
|
129
106
|
*
|
|
130
107
|
* @throws {Error} If the request fails.
|
|
131
108
|
*/
|
|
132
|
-
export const updatePortfolio = async (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
throw new Error(error.message || "Error while updating portfolio", { cause: error });
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (error instanceof Error) {
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
throw new Error("Error while updating portfolio", { cause: error });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
109
|
+
export const updatePortfolio = async (
|
|
110
|
+
api: AxiosInstance,
|
|
111
|
+
id: string,
|
|
112
|
+
data: Partial<Portfolio>,
|
|
113
|
+
): Promise<Portfolio> => {
|
|
114
|
+
requireWorkspace(data.workspace, "update a portfolio");
|
|
115
|
+
|
|
116
|
+
const body = await request(
|
|
117
|
+
() => api.put<PortfolioSingleResponse>(`${baseUrl}/${id}`, data),
|
|
118
|
+
"Error updating portfolio",
|
|
119
|
+
);
|
|
120
|
+
return body.portfolio;
|
|
121
|
+
};
|
|
155
122
|
|
|
156
123
|
/**
|
|
157
124
|
* deletePortfolio
|
|
@@ -161,30 +128,20 @@ export const updatePortfolio = async (api: AxiosInstance, id: string, data: Part
|
|
|
161
128
|
* @param {AxiosInstance} api - Axios instance.
|
|
162
129
|
* @param {string} id - Portfolio identifier.
|
|
163
130
|
* @param {string} workspace - Workspace the portfolio belongs to.
|
|
164
|
-
* @returns {Promise<
|
|
131
|
+
* @returns {Promise<DeletedEntity>} The deletion record: id, name and `deleted`.
|
|
165
132
|
*
|
|
166
133
|
* @throws {Error} If the request fails.
|
|
167
134
|
*/
|
|
168
|
-
export const deletePortfolio = async (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
throw new Error(error.message || "Error while deleting portfolio", { cause: error });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (error instanceof Error) {
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
throw new Error("Error while deleting portfolio", { cause: error });
|
|
189
|
-
}
|
|
190
|
-
}
|
|
135
|
+
export const deletePortfolio = async (
|
|
136
|
+
api: AxiosInstance,
|
|
137
|
+
id: string,
|
|
138
|
+
workspace: string,
|
|
139
|
+
): Promise<DeletedEntity> => {
|
|
140
|
+
requireWorkspace(workspace, "delete a portfolio");
|
|
141
|
+
|
|
142
|
+
const body = await request(
|
|
143
|
+
() => api.delete<DeletePortfolioResponse>(`${baseUrl}/${id}`, { params: { workspace } }),
|
|
144
|
+
"Error deleting portfolio",
|
|
145
|
+
);
|
|
146
|
+
return body.portfolio;
|
|
147
|
+
};
|
package/src/api/profile.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AxiosInstance } from "axios";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
3
|
+
import type { Profile } from "@/types/profile";
|
|
4
|
+
import { request } from "./request";
|
|
5
5
|
|
|
6
6
|
const baseUrl = "profile";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The endpoint's envelope, private: `getProfile` returns the profile itself.
|
|
10
|
+
*
|
|
11
|
+
* It does not follow `EntitySingleResponse`: `/api/profile` is an app-only route rather than an
|
|
12
|
+
* entity, and carries a `status` beside the profile.
|
|
13
|
+
*/
|
|
14
|
+
type ProfileResponse = {
|
|
15
|
+
status: string;
|
|
16
|
+
profile: Profile;
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
/**
|
|
9
20
|
* DEV_PROFILE — the profile served while running the dev server.
|
|
10
21
|
*
|
|
@@ -56,25 +67,21 @@ export const DEV_PROFILE: Profile = {
|
|
|
56
67
|
*
|
|
57
68
|
* @param {AxiosInstance} api - Axios instance.
|
|
58
69
|
* @param {Profile} [fallback] - Returned instead of calling the API, when present.
|
|
70
|
+
* @param {AbortSignal} [signal] - Aborts the request itself; the entity hooks pass the query's own.
|
|
59
71
|
* @returns {Promise<Profile>} The logged user's profile.
|
|
60
72
|
*
|
|
61
73
|
* @throws {Error} If the request fails.
|
|
62
74
|
*/
|
|
63
|
-
export const getProfile = async (
|
|
75
|
+
export const getProfile = async (
|
|
76
|
+
api: AxiosInstance,
|
|
77
|
+
fallback?: Profile,
|
|
78
|
+
signal?: AbortSignal,
|
|
79
|
+
): Promise<Profile> => {
|
|
64
80
|
if (fallback) return fallback;
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw new Error(error.message || "Error while fetching profile", { cause: error });
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (error instanceof Error) {
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
throw new Error("Error while fetching profile", { cause: error });
|
|
79
|
-
}
|
|
82
|
+
const body = await request(
|
|
83
|
+
() => api.get<ProfileResponse>(baseUrl, { signal }),
|
|
84
|
+
"Error fetching profile",
|
|
85
|
+
);
|
|
86
|
+
return body.profile;
|
|
80
87
|
};
|