@carlonicora/nextjs-jsonapi 0.0.1 → 1.0.4
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/BlockNoteEditor-VFWG6LXI.js.map +1 -1
- package/dist/JsonApiRequest-ZZLSP26T.js.map +1 -1
- package/dist/atoms/index.js.map +1 -1
- package/dist/chunk-2K3Q24UF.js.map +1 -1
- package/dist/chunk-3FBCC4G3.js.map +1 -1
- package/dist/chunk-4HCRAOS5.js.map +1 -1
- package/dist/chunk-6GKHCVF6.js.map +1 -1
- package/dist/chunk-7QVYU63E.js.map +1 -1
- package/dist/chunk-A5DDIABK.js.map +1 -1
- package/dist/chunk-AWONBQQP.js.map +1 -1
- package/dist/chunk-CXQOWQSY.js.map +1 -1
- package/dist/chunk-DO2HLAZO.js.map +1 -1
- package/dist/chunk-EFJEWLRL.js.map +1 -1
- package/dist/chunk-FY4SXJGU.js.map +1 -1
- package/dist/chunk-H6FMOA6B.js.map +1 -1
- package/dist/chunk-I2REI7OA.js.map +1 -1
- package/dist/chunk-IBS6NI7D.js.map +1 -1
- package/dist/chunk-J4Q36PMP.js.map +1 -1
- package/dist/chunk-JC3WJK65.js.map +1 -1
- package/dist/chunk-LXKSUWAV.js.map +1 -1
- package/dist/chunk-RAF7PNLG.js.map +1 -1
- package/dist/chunk-RUR22SVM.js.map +1 -1
- package/dist/chunk-TEGF6ZWG.js.map +1 -1
- package/dist/chunk-TMVHSY3Y.js.map +1 -1
- package/dist/chunk-V2JJPI7N.js.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/contexts/index.js.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/features/index.js.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/permissions/index.js.map +1 -1
- package/dist/request-QFS7NEIE.js.map +1 -1
- package/dist/request-ZYY6RI5X.js.map +1 -1
- package/dist/roles/index.js.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/shadcnui/index.js.map +1 -1
- package/dist/token-MJMC26ON.js.map +1 -1
- package/dist/token-UYE7CV6X.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +6 -1
- package/src/atoms/index.ts +1 -0
- package/src/atoms/recentPagesAtom.ts +10 -0
- package/src/client/context/JsonApiContext.ts +61 -0
- package/src/client/context/JsonApiProvider.tsx +27 -0
- package/src/client/context/index.ts +2 -0
- package/src/client/hooks/index.ts +3 -0
- package/src/client/hooks/useJsonApiGet.ts +188 -0
- package/src/client/hooks/useJsonApiMutation.ts +193 -0
- package/src/client/hooks/useRehydration.ts +47 -0
- package/src/client/index.ts +11 -0
- package/src/client/request.ts +97 -0
- package/src/client/token.ts +10 -0
- package/src/components/containers/PageContainer.tsx +15 -0
- package/src/components/containers/ReactMarkdownContainer.tsx +119 -0
- package/src/components/containers/TabsContainer.tsx +93 -0
- package/src/components/containers/index.ts +3 -0
- package/src/components/contents/AttributeElement.tsx +20 -0
- package/src/components/contents/index.ts +1 -0
- package/src/components/details/AllowedUsersDetails.tsx +23 -0
- package/src/components/details/index.ts +1 -0
- package/src/components/editors/BlockNoteDiffInlineContent.tsx +152 -0
- package/src/components/editors/BlockNoteEditor.tsx +404 -0
- package/src/components/editors/BlockNoteEditorContainer.tsx +13 -0
- package/src/components/editors/BlockNoteEditorFormattingToolbar.tsx +38 -0
- package/src/components/editors/index.ts +1 -0
- package/src/components/errors/ErrorDetails.tsx +41 -0
- package/src/components/errors/errorToast.ts +9 -0
- package/src/components/errors/index.ts +2 -0
- package/src/components/forms/CommonAssociationForm.tsx +162 -0
- package/src/components/forms/CommonDeleter.tsx +94 -0
- package/src/components/forms/CommonEditorButtons.tsx +30 -0
- package/src/components/forms/CommonEditorHeader.tsx +35 -0
- package/src/components/forms/CommonEditorTrigger.tsx +26 -0
- package/src/components/forms/DatePickerPopover.tsx +219 -0
- package/src/components/forms/DateRangeSelector.tsx +110 -0
- package/src/components/forms/FileUploader.tsx +324 -0
- package/src/components/forms/FormCheckbox.tsx +66 -0
- package/src/components/forms/FormContainerGeneric.tsx +39 -0
- package/src/components/forms/FormDate.tsx +247 -0
- package/src/components/forms/FormDateTime.tsx +231 -0
- package/src/components/forms/FormInput.tsx +110 -0
- package/src/components/forms/FormPassword.tsx +54 -0
- package/src/components/forms/FormPlaceAutocomplete.tsx +286 -0
- package/src/components/forms/FormSelect.tsx +72 -0
- package/src/components/forms/FormSlider.tsx +51 -0
- package/src/components/forms/FormSwitch.tsx +25 -0
- package/src/components/forms/FormTextarea.tsx +44 -0
- package/src/components/forms/MultiFileUploader.tsx +107 -0
- package/src/components/forms/PasswordInput.tsx +47 -0
- package/src/components/forms/index.ts +21 -0
- package/src/components/index.ts +11 -0
- package/src/components/navigations/Breadcrumb.tsx +83 -0
- package/src/components/navigations/ContentTitle.tsx +39 -0
- package/src/components/navigations/Header.tsx +27 -0
- package/src/components/navigations/ModeToggleSwitch.tsx +25 -0
- package/src/components/navigations/PageSection.tsx +64 -0
- package/src/components/navigations/RecentPagesNavigator.tsx +52 -0
- package/src/components/navigations/index.ts +6 -0
- package/src/components/pages/PageContainerContentDetails.tsx +76 -0
- package/src/components/pages/PageContentContainer.tsx +31 -0
- package/src/components/pages/index.ts +2 -0
- package/src/components/tables/ContentListTable.tsx +165 -0
- package/src/components/tables/ContentTableSearch.tsx +105 -0
- package/src/components/tables/cells/cell.component.tsx +18 -0
- package/src/components/tables/cells/cell.date.tsx +16 -0
- package/src/components/tables/cells/cell.id.tsx +27 -0
- package/src/components/tables/cells/cell.link.tsx +18 -0
- package/src/components/tables/cells/cell.text.tsx +12 -0
- package/src/components/tables/cells/cell.url.tsx +13 -0
- package/src/components/tables/cells/index.ts +5 -0
- package/src/components/tables/index.ts +3 -0
- package/src/contexts/SharedContext.tsx +35 -0
- package/src/contexts/index.ts +2 -0
- package/src/core/abstracts/AbstractApiData.ts +138 -0
- package/src/core/abstracts/AbstractService.ts +263 -0
- package/src/core/abstracts/index.ts +2 -0
- package/src/core/endpoint/EndpointCreator.ts +97 -0
- package/src/core/endpoint/index.ts +1 -0
- package/src/core/factories/JsonApiDataFactory.ts +12 -0
- package/src/core/factories/RehydrationFactory.ts +30 -0
- package/src/core/factories/index.ts +2 -0
- package/src/core/fields/FieldSelector.ts +15 -0
- package/src/core/fields/index.ts +1 -0
- package/src/core/index.ts +20 -0
- package/src/core/interfaces/ApiData.ts +8 -0
- package/src/core/interfaces/ApiDataInterface.ts +15 -0
- package/src/core/interfaces/ApiRequestDataTypeInterface.ts +14 -0
- package/src/core/interfaces/ApiResponseInterface.ts +17 -0
- package/src/core/interfaces/JsonApiHydratedDataInterface.ts +5 -0
- package/src/core/interfaces/index.ts +5 -0
- package/src/core/registry/DataClassRegistry.ts +51 -0
- package/src/core/registry/ModuleRegistrar.ts +43 -0
- package/src/core/registry/ModuleRegistry.ts +64 -0
- package/src/core/registry/index.ts +3 -0
- package/src/core/utils/index.ts +2 -0
- package/src/core/utils/rehydrate.ts +24 -0
- package/src/core/utils/translateResponse.ts +125 -0
- package/src/features/auth/auth.module.ts +9 -0
- package/src/features/auth/config.ts +57 -0
- package/src/features/auth/data/auth.interface.ts +31 -0
- package/src/features/auth/data/auth.service.ts +159 -0
- package/src/features/auth/data/auth.ts +54 -0
- package/src/features/auth/data/index.ts +3 -0
- package/src/features/auth/index.ts +3 -0
- package/src/features/company/company.module.ts +10 -0
- package/src/features/company/data/company.fields.ts +6 -0
- package/src/features/company/data/company.interface.ts +28 -0
- package/src/features/company/data/company.service.ts +73 -0
- package/src/features/company/data/company.ts +104 -0
- package/src/features/company/data/index.ts +4 -0
- package/src/features/company/index.ts +2 -0
- package/src/features/content/content.module.ts +20 -0
- package/src/features/content/data/content.fields.ts +13 -0
- package/src/features/content/data/content.interface.ts +23 -0
- package/src/features/content/data/content.service.ts +75 -0
- package/src/features/content/data/content.ts +85 -0
- package/src/features/content/data/index.ts +4 -0
- package/src/features/content/index.ts +2 -0
- package/src/features/feature/components/forms/FormFeatures.tsx +149 -0
- package/src/features/feature/components/index.ts +1 -0
- package/src/features/feature/data/feature.interface.ts +9 -0
- package/src/features/feature/data/feature.service.ts +19 -0
- package/src/features/feature/data/feature.ts +33 -0
- package/src/features/feature/data/index.ts +3 -0
- package/src/features/feature/feature.module.ts +10 -0
- package/src/features/feature/index.ts +3 -0
- package/src/features/index.ts +12 -0
- package/src/features/module/data/index.ts +2 -0
- package/src/features/module/data/module.interface.ts +12 -0
- package/src/features/module/data/module.ts +42 -0
- package/src/features/module/index.ts +2 -0
- package/src/features/module/module.module.ts +10 -0
- package/src/features/notification/data/index.ts +4 -0
- package/src/features/notification/data/notification.fields.ts +8 -0
- package/src/features/notification/data/notification.interface.ts +14 -0
- package/src/features/notification/data/notification.service.ts +34 -0
- package/src/features/notification/data/notification.ts +51 -0
- package/src/features/notification/index.ts +2 -0
- package/src/features/notification/notification.module.ts +10 -0
- package/src/features/push/data/index.ts +3 -0
- package/src/features/push/data/push.interface.ts +8 -0
- package/src/features/push/data/push.service.ts +17 -0
- package/src/features/push/data/push.ts +18 -0
- package/src/features/push/index.ts +2 -0
- package/src/features/push/push.module.ts +10 -0
- package/src/features/role/data/index.ts +4 -0
- package/src/features/role/data/role.fields.ts +8 -0
- package/src/features/role/data/role.interface.ts +16 -0
- package/src/features/role/data/role.service.ts +117 -0
- package/src/features/role/data/role.ts +62 -0
- package/src/features/role/index.ts +2 -0
- package/src/features/role/role.module.ts +10 -0
- package/src/features/s3/data/index.ts +3 -0
- package/src/features/s3/data/s3.interface.ts +11 -0
- package/src/features/s3/data/s3.service.ts +30 -0
- package/src/features/s3/data/s3.ts +60 -0
- package/src/features/s3/index.ts +2 -0
- package/src/features/s3/s3.module.ts +10 -0
- package/src/features/search/index.ts +1 -0
- package/src/features/search/interfaces/index.ts +1 -0
- package/src/features/search/interfaces/search.result.interface.ts +3 -0
- package/src/features/user/author.module.ts +10 -0
- package/src/features/user/components/index.ts +2 -0
- package/src/features/user/components/lists/ContributorsList.tsx +41 -0
- package/src/features/user/components/lists/index.ts +1 -0
- package/src/features/user/components/widgets/UserAvatar.tsx +86 -0
- package/src/features/user/components/widgets/index.ts +1 -0
- package/src/features/user/contexts/CurrentUserContext.tsx +156 -0
- package/src/features/user/contexts/index.ts +1 -0
- package/src/features/user/data/index.ts +4 -0
- package/src/features/user/data/user.fields.ts +8 -0
- package/src/features/user/data/user.interface.ts +41 -0
- package/src/features/user/data/user.service.ts +246 -0
- package/src/features/user/data/user.ts +162 -0
- package/src/features/user/index.ts +4 -0
- package/src/features/user/user.module.ts +21 -0
- package/src/hooks/TableGeneratorRegistry.ts +53 -0
- package/src/hooks/index.ts +33 -0
- package/src/hooks/types.ts +35 -0
- package/src/hooks/url.rewriter.ts +22 -0
- package/src/hooks/useCustomD3Graph.tsx +705 -0
- package/src/hooks/useDataListRetriever.ts +349 -0
- package/src/hooks/useDebounce.ts +33 -0
- package/src/hooks/usePageUrlGenerator.ts +50 -0
- package/src/hooks/useTableGenerator.ts +16 -0
- package/src/i18n/config.ts +73 -0
- package/src/i18n/index.ts +18 -0
- package/src/index.ts +16 -0
- package/src/interfaces/breadcrumb.item.data.interface.ts +4 -0
- package/src/interfaces/d3.link.interface.ts +7 -0
- package/src/interfaces/d3.node.interface.ts +12 -0
- package/src/interfaces/index.ts +3 -0
- package/src/permissions/check.ts +127 -0
- package/src/permissions/index.ts +2 -0
- package/src/permissions/types.ts +109 -0
- package/src/roles/config.ts +46 -0
- package/src/roles/index.ts +1 -0
- package/src/server/cache.ts +28 -0
- package/src/server/index.ts +3 -0
- package/src/server/request.ts +113 -0
- package/src/server/token.ts +10 -0
- package/src/shadcnui/custom/kanban.tsx +1001 -0
- package/src/shadcnui/custom/link.tsx +18 -0
- package/src/shadcnui/custom/multi-select.tsx +382 -0
- package/src/shadcnui/index.ts +49 -0
- package/src/shadcnui/ui/accordion.tsx +52 -0
- package/src/shadcnui/ui/alert-dialog.tsx +141 -0
- package/src/shadcnui/ui/alert.tsx +43 -0
- package/src/shadcnui/ui/avatar.tsx +50 -0
- package/src/shadcnui/ui/badge.tsx +40 -0
- package/src/shadcnui/ui/breadcrumb.tsx +115 -0
- package/src/shadcnui/ui/button.tsx +51 -0
- package/src/shadcnui/ui/calendar.tsx +73 -0
- package/src/shadcnui/ui/card.tsx +43 -0
- package/src/shadcnui/ui/carousel.tsx +225 -0
- package/src/shadcnui/ui/chart.tsx +320 -0
- package/src/shadcnui/ui/checkbox.tsx +29 -0
- package/src/shadcnui/ui/collapsible.tsx +11 -0
- package/src/shadcnui/ui/command.tsx +155 -0
- package/src/shadcnui/ui/context-menu.tsx +179 -0
- package/src/shadcnui/ui/dialog.tsx +96 -0
- package/src/shadcnui/ui/drawer.tsx +89 -0
- package/src/shadcnui/ui/dropdown-menu.tsx +205 -0
- package/src/shadcnui/ui/form.tsx +138 -0
- package/src/shadcnui/ui/hover-card.tsx +29 -0
- package/src/shadcnui/ui/input.tsx +21 -0
- package/src/shadcnui/ui/label.tsx +26 -0
- package/src/shadcnui/ui/navigation-menu.tsx +168 -0
- package/src/shadcnui/ui/popover.tsx +33 -0
- package/src/shadcnui/ui/progress.tsx +25 -0
- package/src/shadcnui/ui/radio-group.tsx +37 -0
- package/src/shadcnui/ui/resizable.tsx +47 -0
- package/src/shadcnui/ui/scroll-area.tsx +40 -0
- package/src/shadcnui/ui/select.tsx +164 -0
- package/src/shadcnui/ui/separator.tsx +28 -0
- package/src/shadcnui/ui/sheet.tsx +139 -0
- package/src/shadcnui/ui/sidebar.tsx +677 -0
- package/src/shadcnui/ui/skeleton.tsx +13 -0
- package/src/shadcnui/ui/slider.tsx +25 -0
- package/src/shadcnui/ui/sonner.tsx +25 -0
- package/src/shadcnui/ui/switch.tsx +31 -0
- package/src/shadcnui/ui/table.tsx +120 -0
- package/src/shadcnui/ui/tabs.tsx +55 -0
- package/src/shadcnui/ui/textarea.tsx +24 -0
- package/src/shadcnui/ui/toggle.tsx +39 -0
- package/src/shadcnui/ui/tooltip.tsx +61 -0
- package/src/unified/JsonApiRequest.ts +325 -0
- package/src/unified/index.ts +1 -0
- package/src/utils/blocknote-diff.util.ts +815 -0
- package/src/utils/blocknote-word-diff-renderer.util.ts +413 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/compose-refs.ts +61 -0
- package/src/utils/date-formatter.ts +53 -0
- package/src/utils/exists.ts +7 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/schemas/entity.object.schema.ts +8 -0
- package/src/utils/schemas/index.ts +2 -0
- package/src/utils/schemas/user.object.schema.ts +9 -0
- package/src/utils/table-options.ts +67 -0
- package/src/utils/use-mobile.tsx +21 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { ApiData } from "../core/interfaces/ApiData";
|
|
2
|
+
import { ApiRequestDataTypeInterface } from "../core/interfaces/ApiRequestDataTypeInterface";
|
|
3
|
+
import { ApiResponseInterface } from "../core/interfaces/ApiResponseInterface";
|
|
4
|
+
import { JsonApiDataFactory } from "../core/factories/JsonApiDataFactory";
|
|
5
|
+
import { translateResponse } from "../core/utils/translateResponse";
|
|
6
|
+
|
|
7
|
+
// Type definitions for dynamically imported functions (avoiding typeof import to prevent bundling)
|
|
8
|
+
type DirectFetchFn = (params: {
|
|
9
|
+
method: string;
|
|
10
|
+
url: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
body?: any;
|
|
13
|
+
files?: { [key: string]: File | Blob } | File | Blob;
|
|
14
|
+
companyId?: string;
|
|
15
|
+
language: string;
|
|
16
|
+
additionalHeaders?: Record<string, string>;
|
|
17
|
+
}) => Promise<ApiData>;
|
|
18
|
+
|
|
19
|
+
type ServerRequestFn = (params: {
|
|
20
|
+
method: string;
|
|
21
|
+
url: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
cache?: string;
|
|
24
|
+
body?: any;
|
|
25
|
+
files?: { [key: string]: File | Blob } | File | Blob;
|
|
26
|
+
companyId?: string;
|
|
27
|
+
language: string;
|
|
28
|
+
additionalHeaders?: Record<string, string>;
|
|
29
|
+
}) => Promise<ApiData>;
|
|
30
|
+
|
|
31
|
+
type GetTokenFn = () => Promise<string | undefined>;
|
|
32
|
+
|
|
33
|
+
// These will be dynamically imported based on environment
|
|
34
|
+
let _directFetch: DirectFetchFn;
|
|
35
|
+
let _serverRequest: ServerRequestFn;
|
|
36
|
+
let _getClientToken: GetTokenFn;
|
|
37
|
+
let _getServerToken: GetTokenFn;
|
|
38
|
+
|
|
39
|
+
// Config storage for non-React contexts
|
|
40
|
+
let _staticConfig: {
|
|
41
|
+
apiUrl: string;
|
|
42
|
+
bootstrapper?: () => void;
|
|
43
|
+
additionalHeaders?: Record<string, string>;
|
|
44
|
+
} | null = null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Configure the JSON:API client for non-React contexts (e.g., server components).
|
|
48
|
+
* For React contexts, use JsonApiProvider instead.
|
|
49
|
+
*/
|
|
50
|
+
export function configureJsonApi(config: {
|
|
51
|
+
apiUrl: string;
|
|
52
|
+
bootstrapper?: () => void;
|
|
53
|
+
additionalHeaders?: Record<string, string>;
|
|
54
|
+
}): void {
|
|
55
|
+
_staticConfig = config;
|
|
56
|
+
// Call bootstrapper immediately to register all modules
|
|
57
|
+
if (config.bootstrapper) {
|
|
58
|
+
config.bootstrapper();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function getToken(): Promise<string | undefined> {
|
|
63
|
+
if (typeof window === "undefined") {
|
|
64
|
+
// Server-side
|
|
65
|
+
if (!_getServerToken) {
|
|
66
|
+
const serverModule = await import("../server/token");
|
|
67
|
+
_getServerToken = serverModule.getServerToken;
|
|
68
|
+
}
|
|
69
|
+
return _getServerToken();
|
|
70
|
+
} else {
|
|
71
|
+
// Client-side
|
|
72
|
+
if (!_getClientToken) {
|
|
73
|
+
const clientModule = await import("../client/token");
|
|
74
|
+
_getClientToken = clientModule.getClientToken;
|
|
75
|
+
}
|
|
76
|
+
return _getClientToken();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function makeRequest(params: {
|
|
81
|
+
method: string;
|
|
82
|
+
url: string;
|
|
83
|
+
token?: string;
|
|
84
|
+
cache?: string;
|
|
85
|
+
body?: any;
|
|
86
|
+
files?: { [key: string]: File | Blob } | File | Blob;
|
|
87
|
+
companyId?: string;
|
|
88
|
+
language: string;
|
|
89
|
+
additionalHeaders?: Record<string, string>;
|
|
90
|
+
}): Promise<ApiData> {
|
|
91
|
+
if (typeof window !== "undefined") {
|
|
92
|
+
// Client-side: use direct fetch
|
|
93
|
+
if (!_directFetch) {
|
|
94
|
+
const clientModule = await import("../client/request");
|
|
95
|
+
_directFetch = clientModule.directFetch;
|
|
96
|
+
}
|
|
97
|
+
return _directFetch({
|
|
98
|
+
method: params.method,
|
|
99
|
+
url: params.url,
|
|
100
|
+
token: params.token,
|
|
101
|
+
body: params.body,
|
|
102
|
+
files: params.files,
|
|
103
|
+
companyId: params.companyId,
|
|
104
|
+
language: params.language,
|
|
105
|
+
additionalHeaders: params.additionalHeaders,
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
// Server-side: use server request with caching
|
|
109
|
+
if (!_serverRequest) {
|
|
110
|
+
const serverModule = await import("../server/request");
|
|
111
|
+
_serverRequest = serverModule.serverRequest;
|
|
112
|
+
}
|
|
113
|
+
return _serverRequest({
|
|
114
|
+
method: params.method,
|
|
115
|
+
url: params.url,
|
|
116
|
+
token: params.token,
|
|
117
|
+
cache: params.cache,
|
|
118
|
+
body: params.body,
|
|
119
|
+
files: params.files,
|
|
120
|
+
companyId: params.companyId,
|
|
121
|
+
language: params.language,
|
|
122
|
+
additionalHeaders: params.additionalHeaders,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getApiUrl(): string {
|
|
128
|
+
if (_staticConfig?.apiUrl) {
|
|
129
|
+
return _staticConfig.apiUrl;
|
|
130
|
+
}
|
|
131
|
+
// Fallback to environment variable
|
|
132
|
+
const envUrl = process.env.NEXT_PUBLIC_API_URL;
|
|
133
|
+
if (!envUrl) {
|
|
134
|
+
throw new Error("API URL not configured. Use configureJsonApi() or set NEXT_PUBLIC_API_URL environment variable.");
|
|
135
|
+
}
|
|
136
|
+
return envUrl;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function runBootstrapper(): void {
|
|
140
|
+
if (_staticConfig?.bootstrapper) {
|
|
141
|
+
_staticConfig.bootstrapper();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function buildUrl(endpoint: string): string {
|
|
146
|
+
const apiUrl = getApiUrl();
|
|
147
|
+
return endpoint.startsWith("http") ? endpoint : `${apiUrl}${endpoint}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function JsonApiGet(params: {
|
|
151
|
+
classKey: ApiRequestDataTypeInterface;
|
|
152
|
+
endpoint: string;
|
|
153
|
+
companyId?: string;
|
|
154
|
+
language: string;
|
|
155
|
+
}): Promise<ApiResponseInterface> {
|
|
156
|
+
runBootstrapper();
|
|
157
|
+
const token = await getToken();
|
|
158
|
+
|
|
159
|
+
const apiResponse = await makeRequest({
|
|
160
|
+
method: "GET",
|
|
161
|
+
url: buildUrl(params.endpoint),
|
|
162
|
+
token,
|
|
163
|
+
cache: params.classKey.cache,
|
|
164
|
+
companyId: params.companyId,
|
|
165
|
+
language: params.language,
|
|
166
|
+
additionalHeaders: _staticConfig?.additionalHeaders,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return translateResponse({
|
|
170
|
+
classKey: params.classKey,
|
|
171
|
+
apiResponse,
|
|
172
|
+
companyId: params.companyId,
|
|
173
|
+
language: params.language,
|
|
174
|
+
paginationHandler: async (endpoint: string) =>
|
|
175
|
+
JsonApiGet({
|
|
176
|
+
classKey: params.classKey,
|
|
177
|
+
endpoint,
|
|
178
|
+
companyId: params.companyId,
|
|
179
|
+
language: params.language,
|
|
180
|
+
}),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function JsonApiPost(params: {
|
|
185
|
+
classKey: ApiRequestDataTypeInterface;
|
|
186
|
+
endpoint: string;
|
|
187
|
+
companyId?: string;
|
|
188
|
+
body?: any;
|
|
189
|
+
overridesJsonApiCreation?: boolean;
|
|
190
|
+
files?: { [key: string]: File | Blob } | File | Blob;
|
|
191
|
+
language: string;
|
|
192
|
+
responseType?: ApiRequestDataTypeInterface;
|
|
193
|
+
}): Promise<ApiResponseInterface> {
|
|
194
|
+
runBootstrapper();
|
|
195
|
+
const token = await getToken();
|
|
196
|
+
|
|
197
|
+
let body = params.body;
|
|
198
|
+
if (!body) {
|
|
199
|
+
body = {};
|
|
200
|
+
} else if (params.overridesJsonApiCreation !== true) {
|
|
201
|
+
body = JsonApiDataFactory.create(params.classKey, body);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const apiResponse = await makeRequest({
|
|
205
|
+
method: "POST",
|
|
206
|
+
url: buildUrl(params.endpoint),
|
|
207
|
+
token,
|
|
208
|
+
body,
|
|
209
|
+
files: params.files,
|
|
210
|
+
companyId: params.companyId,
|
|
211
|
+
language: params.language,
|
|
212
|
+
additionalHeaders: _staticConfig?.additionalHeaders,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
return translateResponse({
|
|
216
|
+
classKey: params.responseType ?? params.classKey,
|
|
217
|
+
apiResponse,
|
|
218
|
+
companyId: params.companyId,
|
|
219
|
+
language: params.language,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export async function JsonApiPut(params: {
|
|
224
|
+
classKey: ApiRequestDataTypeInterface;
|
|
225
|
+
endpoint: string;
|
|
226
|
+
companyId?: string;
|
|
227
|
+
body?: any;
|
|
228
|
+
files?: { [key: string]: File | Blob } | File | Blob;
|
|
229
|
+
language: string;
|
|
230
|
+
responseType?: ApiRequestDataTypeInterface;
|
|
231
|
+
}): Promise<ApiResponseInterface> {
|
|
232
|
+
runBootstrapper();
|
|
233
|
+
const token = await getToken();
|
|
234
|
+
|
|
235
|
+
let body = params.body;
|
|
236
|
+
if (!body) {
|
|
237
|
+
body = {};
|
|
238
|
+
} else {
|
|
239
|
+
body = JsonApiDataFactory.create(params.classKey, body);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const apiResponse = await makeRequest({
|
|
243
|
+
method: "PUT",
|
|
244
|
+
url: buildUrl(params.endpoint),
|
|
245
|
+
token,
|
|
246
|
+
body,
|
|
247
|
+
files: params.files,
|
|
248
|
+
companyId: params.companyId,
|
|
249
|
+
language: params.language,
|
|
250
|
+
additionalHeaders: _staticConfig?.additionalHeaders,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return translateResponse({
|
|
254
|
+
classKey: params.responseType ?? params.classKey,
|
|
255
|
+
apiResponse,
|
|
256
|
+
companyId: params.companyId,
|
|
257
|
+
language: params.language,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export async function JsonApiPatch(params: {
|
|
262
|
+
classKey: ApiRequestDataTypeInterface;
|
|
263
|
+
endpoint: string;
|
|
264
|
+
companyId?: string;
|
|
265
|
+
body?: any;
|
|
266
|
+
files?: { [key: string]: File | Blob } | File | Blob;
|
|
267
|
+
overridesJsonApiCreation?: boolean;
|
|
268
|
+
responseType?: ApiRequestDataTypeInterface;
|
|
269
|
+
language: string;
|
|
270
|
+
}): Promise<ApiResponseInterface> {
|
|
271
|
+
runBootstrapper();
|
|
272
|
+
const token = await getToken();
|
|
273
|
+
|
|
274
|
+
let body = params.body;
|
|
275
|
+
if (!body) {
|
|
276
|
+
body = {};
|
|
277
|
+
} else if (params.overridesJsonApiCreation !== true) {
|
|
278
|
+
body = JsonApiDataFactory.create(params.classKey, body);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const apiResponse = await makeRequest({
|
|
282
|
+
method: "PATCH",
|
|
283
|
+
url: buildUrl(params.endpoint),
|
|
284
|
+
token,
|
|
285
|
+
body,
|
|
286
|
+
files: params.files,
|
|
287
|
+
companyId: params.companyId,
|
|
288
|
+
language: params.language,
|
|
289
|
+
additionalHeaders: _staticConfig?.additionalHeaders,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return translateResponse({
|
|
293
|
+
classKey: params.responseType ?? params.classKey,
|
|
294
|
+
apiResponse,
|
|
295
|
+
companyId: params.companyId,
|
|
296
|
+
language: params.language,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export async function JsonApiDelete(params: {
|
|
301
|
+
classKey: ApiRequestDataTypeInterface;
|
|
302
|
+
endpoint: string;
|
|
303
|
+
companyId?: string;
|
|
304
|
+
language: string;
|
|
305
|
+
responseType?: ApiRequestDataTypeInterface;
|
|
306
|
+
}): Promise<ApiResponseInterface> {
|
|
307
|
+
runBootstrapper();
|
|
308
|
+
const token = await getToken();
|
|
309
|
+
|
|
310
|
+
const apiResponse = await makeRequest({
|
|
311
|
+
method: "DELETE",
|
|
312
|
+
url: buildUrl(params.endpoint),
|
|
313
|
+
token,
|
|
314
|
+
companyId: params.companyId,
|
|
315
|
+
language: params.language,
|
|
316
|
+
additionalHeaders: _staticConfig?.additionalHeaders,
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
return translateResponse({
|
|
320
|
+
classKey: params.responseType ?? params.classKey,
|
|
321
|
+
apiResponse,
|
|
322
|
+
companyId: params.companyId,
|
|
323
|
+
language: params.language,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./JsonApiRequest";
|