nexus-shared 1.1.21 → 2.0.0
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/LICENSE +21 -0
- package/README.md +903 -0
- package/dist/Client.Index.d.ts +44 -0
- package/dist/Client.Index.js +49 -0
- package/dist/Components/Documents/Button.d.ts +29 -0
- package/dist/Components/Documents/Button.js +11 -0
- package/dist/Components/Documents/Menu.d.ts +102 -0
- package/dist/Components/Documents/Menu.js +238 -0
- package/dist/Components/Documents/SplitButton.d.ts +64 -0
- package/dist/Components/Documents/SplitButton.js +127 -0
- package/dist/Components/Documents/TabButtons.d.ts +62 -0
- package/dist/Components/Documents/TabButtons.js +19 -0
- package/dist/Components/Forms/ApiForm.d.ts +21 -0
- package/dist/Components/Forms/ApiForm.js +99 -0
- package/dist/Components/Forms/Crud.d.ts +17 -0
- package/dist/Components/Forms/Crud.js +556 -0
- package/dist/Components/Forms/CrudParts.d.ts +15 -0
- package/dist/Components/Forms/CrudParts.js +36 -0
- package/dist/Components/Forms/Form.d.ts +52 -0
- package/dist/Components/Forms/Form.js +319 -0
- package/dist/Components/Forms/SubmitForm.d.ts +65 -0
- package/dist/Components/Forms/SubmitForm.js +198 -0
- package/dist/Components/Inputs/Calendar.d.ts +69 -0
- package/dist/Components/Inputs/Calendar.js +258 -0
- package/dist/Components/Inputs/CheckBox.d.ts +53 -0
- package/dist/Components/Inputs/CheckBox.js +87 -0
- package/dist/Components/Inputs/CheckBoxGroup.d.ts +20 -0
- package/dist/Components/Inputs/CheckBoxGroup.js +80 -0
- package/dist/Components/Inputs/ChoiceField.d.ts +122 -0
- package/dist/Components/Inputs/ChoiceField.js +169 -0
- package/dist/Components/Inputs/DatePicker.d.ts +54 -0
- package/dist/Components/Inputs/DatePicker.js +246 -0
- package/dist/Components/Inputs/DateRangePicker.d.ts +62 -0
- package/dist/Components/Inputs/DateRangePicker.js +283 -0
- package/dist/Components/Inputs/DateTimePicker.d.ts +75 -0
- package/dist/Components/Inputs/DateTimePicker.js +399 -0
- package/dist/Components/Inputs/Dropdown.d.ts +117 -0
- package/dist/Components/Inputs/Dropdown.js +839 -0
- package/dist/Components/Inputs/DropdownParts.d.ts +84 -0
- package/dist/Components/Inputs/DropdownParts.js +102 -0
- package/dist/Components/Inputs/EditorShell.d.ts +45 -0
- package/dist/Components/Inputs/EditorShell.js +214 -0
- package/dist/Components/Inputs/Field.d.ts +53 -0
- package/dist/Components/Inputs/Field.js +16 -0
- package/dist/Components/Inputs/GroupForm.d.ts +20 -0
- package/dist/Components/Inputs/GroupForm.js +170 -0
- package/dist/Components/Inputs/InputField.d.ts +59 -0
- package/dist/Components/Inputs/InputField.js +169 -0
- package/dist/Components/Inputs/InputRenderer.d.ts +35 -0
- package/dist/Components/Inputs/InputRenderer.js +99 -0
- package/dist/Components/Inputs/MarkdownEditor.d.ts +67 -0
- package/dist/Components/Inputs/MarkdownEditor.js +289 -0
- package/dist/Components/Inputs/NumberBox.d.ts +53 -0
- package/dist/Components/Inputs/NumberBox.js +228 -0
- package/dist/Components/Inputs/RadioGroup.d.ts +20 -0
- package/dist/Components/Inputs/RadioGroup.js +43 -0
- package/dist/Components/Inputs/ReadOnlyNotice.d.ts +36 -0
- package/dist/Components/Inputs/ReadOnlyNotice.js +116 -0
- package/dist/Components/Inputs/RichTextEditor.d.ts +103 -0
- package/dist/Components/Inputs/RichTextEditor.js +1170 -0
- package/dist/Components/Inputs/RichTextParts.d.ts +63 -0
- package/dist/Components/Inputs/RichTextParts.js +157 -0
- package/dist/Components/Inputs/RowsInput.d.ts +104 -0
- package/dist/Components/Inputs/RowsInput.js +259 -0
- package/dist/Components/Inputs/Slider.d.ts +87 -0
- package/dist/Components/Inputs/Slider.js +216 -0
- package/dist/Components/Inputs/TabularForm.d.ts +23 -0
- package/dist/Components/Inputs/TabularForm.js +283 -0
- package/dist/Components/Inputs/TextArea.d.ts +43 -0
- package/dist/Components/Inputs/TextArea.js +31 -0
- package/dist/Components/Inputs/TextBox.d.ts +52 -0
- package/dist/Components/Inputs/TextBox.js +58 -0
- package/dist/Components/Inputs/TextField.d.ts +31 -0
- package/dist/Components/Inputs/TextField.js +35 -0
- package/dist/Components/Inputs/TimePanel.d.ts +34 -0
- package/dist/Components/Inputs/TimePanel.js +288 -0
- package/dist/Components/Inputs/TimePicker.d.ts +54 -0
- package/dist/Components/Inputs/TimePicker.js +239 -0
- package/dist/Components/Inputs/TreeView.d.ts +160 -0
- package/dist/Components/Inputs/TreeView.js +947 -0
- package/dist/Components/Layouts/MessageBox.d.ts +71 -0
- package/dist/Components/Layouts/MessageBox.js +104 -0
- package/dist/Components/Layouts/Popup.d.ts +92 -0
- package/dist/Components/Layouts/Popup.js +376 -0
- package/dist/Components/Layouts/PopupContext.d.ts +2 -0
- package/dist/Components/Layouts/PopupContext.js +4 -0
- package/dist/Components/Layouts/PopupDock.d.ts +22 -0
- package/dist/Components/Layouts/PopupDock.js +121 -0
- package/dist/Components/Layouts/PopupHost.d.ts +56 -0
- package/dist/Components/Layouts/PopupHost.js +163 -0
- package/dist/Components/Layouts/PopupRules.d.ts +30 -0
- package/dist/Components/Layouts/PopupRules.js +63 -0
- package/dist/Components/Layouts/ThemePicker.d.ts +13 -0
- package/dist/Components/Layouts/ThemePicker.js +22 -0
- package/dist/Components/Layouts/ThemeScript.d.ts +14 -0
- package/dist/Components/Layouts/ThemeScript.js +13 -0
- package/dist/Components/Layouts/ThemeSwitcher.d.ts +13 -0
- package/dist/Components/Layouts/ThemeSwitcher.js +29 -0
- package/dist/Components/Layouts/Toaster.d.ts +76 -0
- package/dist/Components/Layouts/Toaster.js +172 -0
- package/dist/Components/Viewers/DataTable.d.ts +25 -0
- package/dist/Components/Viewers/DataTable.js +542 -0
- package/dist/Components/Viewers/DataTableParts.d.ts +134 -0
- package/dist/Components/Viewers/DataTableParts.js +145 -0
- package/dist/Components/Viewers/MarkdownView.d.ts +26 -0
- package/dist/Components/Viewers/MarkdownView.js +79 -0
- package/dist/Components/Viewers/RichTextView.d.ts +18 -0
- package/dist/Components/Viewers/RichTextView.js +17 -0
- package/dist/Helpers/AnimationHelpers.d.ts +6 -0
- package/dist/Helpers/AnimationHelpers.js +35 -0
- package/dist/Helpers/ApiClient.d.ts +74 -0
- package/dist/Helpers/ApiClient.js +197 -0
- package/dist/Helpers/ApiFormHelpers.d.ts +26 -0
- package/dist/Helpers/ApiFormHelpers.js +56 -0
- package/dist/Helpers/ApiModules.d.ts +135 -0
- package/dist/Helpers/ApiModules.js +194 -0
- package/dist/Helpers/ApiResponses.d.ts +41 -0
- package/dist/Helpers/ApiResponses.js +159 -0
- package/dist/Helpers/ApiRoutes.d.ts +150 -0
- package/dist/Helpers/ApiRoutes.js +191 -0
- package/dist/Helpers/ApiToasts.d.ts +21 -0
- package/dist/Helpers/ApiToasts.js +22 -0
- package/dist/Helpers/ClassHelpers.d.ts +3 -0
- package/dist/Helpers/ClassHelpers.js +4 -0
- package/dist/Helpers/CrudBackend.d.ts +56 -0
- package/dist/Helpers/CrudBackend.js +119 -0
- package/dist/Helpers/CrudHelpers.d.ts +76 -0
- package/dist/Helpers/CrudHelpers.js +202 -0
- package/dist/Helpers/DateHelpers.d.ts +88 -0
- package/dist/Helpers/DateHelpers.js +363 -0
- package/dist/Helpers/DatePreferences.d.ts +14 -0
- package/dist/Helpers/DatePreferences.js +94 -0
- package/dist/Helpers/DateTimeHelpers.d.ts +87 -0
- package/dist/Helpers/DateTimeHelpers.js +286 -0
- package/dist/Helpers/DragHelpers.d.ts +129 -0
- package/dist/Helpers/DragHelpers.js +281 -0
- package/dist/Helpers/DropdownHelpers.d.ts +56 -0
- package/dist/Helpers/DropdownHelpers.js +180 -0
- package/dist/Helpers/FormDrafts.d.ts +18 -0
- package/dist/Helpers/FormDrafts.js +76 -0
- package/dist/Helpers/FormStore.d.ts +231 -0
- package/dist/Helpers/FormStore.js +734 -0
- package/dist/Helpers/InputParamsHelpers.d.ts +79 -0
- package/dist/Helpers/InputParamsHelpers.js +388 -0
- package/dist/Helpers/MarkdownEditing.d.ts +27 -0
- package/dist/Helpers/MarkdownEditing.js +250 -0
- package/dist/Helpers/MarkdownHelpers.d.ts +82 -0
- package/dist/Helpers/MarkdownHelpers.js +775 -0
- package/dist/Helpers/MessageBuilder.d.ts +74 -0
- package/dist/Helpers/MessageBuilder.js +254 -0
- package/dist/Helpers/NepaliCalendar.d.ts +25 -0
- package/dist/Helpers/NepaliCalendar.js +107 -0
- package/dist/Helpers/NumberHelpers.d.ts +71 -0
- package/dist/Helpers/NumberHelpers.js +202 -0
- package/dist/Helpers/Permissions.d.ts +62 -0
- package/dist/Helpers/Permissions.js +133 -0
- package/dist/Helpers/PopoverHelpers.d.ts +43 -0
- package/dist/Helpers/PopoverHelpers.js +91 -0
- package/dist/Helpers/RichTextHelpers.d.ts +77 -0
- package/dist/Helpers/RichTextHelpers.js +1072 -0
- package/dist/Helpers/RowsStore.d.ts +160 -0
- package/dist/Helpers/RowsStore.js +584 -0
- package/dist/Helpers/TableColumns.d.ts +40 -0
- package/dist/Helpers/TableColumns.js +254 -0
- package/dist/Helpers/TableExport.d.ts +30 -0
- package/dist/Helpers/TableExport.js +97 -0
- package/dist/Helpers/TableHelpers.d.ts +102 -0
- package/dist/Helpers/TableHelpers.js +281 -0
- package/dist/Helpers/TableStore.d.ts +142 -0
- package/dist/Helpers/TableStore.js +530 -0
- package/dist/Helpers/ThemeHelpers.d.ts +15 -0
- package/dist/Helpers/ThemeHelpers.js +16 -0
- package/dist/Helpers/TimeHelpers.d.ts +73 -0
- package/dist/Helpers/TimeHelpers.js +253 -0
- package/dist/Helpers/TreeStore.d.ts +188 -0
- package/dist/Helpers/TreeStore.js +577 -0
- package/dist/Helpers/ValidationHelpers.d.ts +124 -0
- package/dist/Helpers/ValidationHelpers.js +301 -0
- package/dist/Interfaces/ApiInterfaces.d.ts +149 -0
- package/dist/Interfaces/ApiInterfaces.js +24 -0
- package/dist/Interfaces/CrudInterfaces.d.ts +171 -0
- package/{src/sso-client.tsx → dist/Interfaces/CrudInterfaces.js} +1 -1
- package/dist/Interfaces/DateInterfaces.d.ts +154 -0
- package/dist/Interfaces/DateInterfaces.js +29 -0
- package/dist/Interfaces/FormInterfaces.d.ts +352 -0
- package/dist/Interfaces/FormInterfaces.js +1 -0
- package/dist/Interfaces/InputInterfaces.d.ts +141 -0
- package/dist/Interfaces/InputInterfaces.js +1 -0
- package/dist/Interfaces/MessageInterfaces.d.ts +111 -0
- package/dist/Interfaces/MessageInterfaces.js +5 -0
- package/dist/Interfaces/TableInterfaces.d.ts +291 -0
- package/dist/Interfaces/TableInterfaces.js +1 -0
- package/dist/Interfaces/ThemeInterfaces.d.ts +17 -0
- package/dist/Interfaces/ThemeInterfaces.js +17 -0
- package/dist/Interfaces/TypeInterfaces.d.ts +4 -0
- package/dist/Interfaces/TypeInterfaces.js +1 -0
- package/dist/Server.Index.d.ts +2 -0
- package/dist/Server.Index.js +5 -0
- package/dist/Services/ApiProxy.d.ts +32 -0
- package/dist/Services/ApiProxy.js +111 -0
- package/dist/Services/BrowserApi.d.ts +78 -0
- package/dist/Services/BrowserApi.js +111 -0
- package/dist/Services/ServerApi.d.ts +49 -0
- package/dist/Services/ServerApi.js +75 -0
- package/dist/Services/ThemeService.d.ts +17 -0
- package/dist/Services/ThemeService.js +83 -0
- package/dist/Shared.Index.d.ts +43 -0
- package/dist/Shared.Index.js +47 -0
- package/package.json +82 -33
- package/src/Styles/Nexus.Base.css +70 -0
- package/src/Styles/Nexus.Button.css +151 -0
- package/src/Styles/Nexus.Calendar.css +275 -0
- package/src/Styles/Nexus.Choice.css +345 -0
- package/src/Styles/Nexus.Crud.css +84 -0
- package/src/Styles/Nexus.DateTime.css +81 -0
- package/src/Styles/Nexus.Dropdown.css +774 -0
- package/src/Styles/Nexus.Editor.css +297 -0
- package/src/Styles/Nexus.Form.css +298 -0
- package/src/Styles/Nexus.Index.css +34 -0
- package/src/Styles/Nexus.Input.css +637 -0
- package/src/Styles/Nexus.Markdown.css +265 -0
- package/src/Styles/Nexus.Menu.css +249 -0
- package/src/Styles/Nexus.Popup.css +731 -0
- package/src/Styles/Nexus.RichText.css +463 -0
- package/src/Styles/Nexus.Rows.css +566 -0
- package/src/Styles/Nexus.Slider.css +278 -0
- package/src/Styles/Nexus.Tab.Buttons.css +364 -0
- package/src/Styles/Nexus.Table.css +1014 -0
- package/src/Styles/Nexus.Theme.Picker.css +159 -0
- package/src/Styles/Nexus.Themes.css +194 -0
- package/src/Styles/Nexus.Time.css +147 -0
- package/src/Styles/Nexus.Toast.css +265 -0
- package/src/Styles/Nexus.Tokens.css +72 -0
- package/src/Styles/Nexus.Tree.css +435 -0
- package/src/api-services/authentication-service.tsx +0 -23
- package/src/api-services/preference-service.tsx +0 -5
- package/src/api-services/system-service.tsx +0 -29
- package/src/client.ts +0 -31
- package/src/components/documents/button.tsx +0 -133
- package/src/components/documents/icon-box.tsx +0 -93
- package/src/components/documents/page-title.tsx +0 -7
- package/src/components/documents/tab-button.tsx +0 -172
- package/src/components/documents/tag.tsx +0 -30
- package/src/components/index.js +0 -0
- package/src/components/inputs/checkbox-input.tsx +0 -66
- package/src/components/inputs/input-box.tsx +0 -48
- package/src/components/inputs/input-element.tsx +0 -65
- package/src/components/inputs/input-form.tsx +0 -164
- package/src/components/inputs/input.tsx +0 -181
- package/src/components/inputs/number-input.tsx +0 -108
- package/src/components/inputs/radiobox-input.tsx +0 -53
- package/src/components/inputs/textarea-input.tsx +0 -47
- package/src/components/inputs/textbox-input.tsx +0 -45
- package/src/components/layouts/global-dialogbox.tsx +0 -431
- package/src/components/layouts/global-layout.tsx +0 -64
- package/src/components/layouts/layout-helpers.tsx +0 -20
- package/src/components/layouts/panels/user-panel.tsx +0 -112
- package/src/components/layouts/utility-menu.tsx +0 -49
- package/src/components/panels/theme-panel.tsx +0 -46
- package/src/helpers/bitwise-helpers.tsx +0 -11
- package/src/helpers/browser-helpers.tsx +0 -156
- package/src/helpers/datasource-helpers.tsx +0 -99
- package/src/helpers/element-helpers.tsx +0 -123
- package/src/helpers/input-helpers.tsx +0 -74
- package/src/helpers/string-helpers.tsx +0 -28
- package/src/helpers/utility-helpers.tsx +0 -45
- package/src/helpers/validation-helpers.tsx +0 -302
- package/src/index.ts +0 -26
- package/src/interface.ts +0 -19
- package/src/interfaces/auth-token-interfaces.tsx +0 -6
- package/src/interfaces/browser-interfaces.tsx +0 -36
- package/src/interfaces/button-interfaces.tsx +0 -63
- package/src/interfaces/datasource-interfaces.tsx +0 -22
- package/src/interfaces/datatable-interfaces.tsx +0 -25
- package/src/interfaces/dialogbox-interfaces.tsx +0 -5
- package/src/interfaces/exception-interfaces.tsx +0 -99
- package/src/interfaces/http-interfaces.tsx +0 -129
- package/src/interfaces/icon-interfaces.tsx +0 -129
- package/src/interfaces/input-interfaces.tsx +0 -410
- package/src/interfaces/layout-interfaces.tsx +0 -191
- package/src/interfaces/menu-interfaces.tsx +0 -53
- package/src/interfaces/message-interfaces.tsx +0 -32
- package/src/interfaces/permission-interfaces.tsx +0 -9
- package/src/interfaces/storage-interfaces.tsx +0 -5
- package/src/interfaces/system-interfaces.tsx +0 -22
- package/src/interfaces/theme-interfaces.tsx +0 -123
- package/src/interfaces/type-interfaces.tsx +0 -28
- package/src/interfaces/user-interfaces.tsx +0 -47
- package/src/nexus-client.tsx +0 -21
- package/src/nexus.environments.tsx +0 -66
- package/src/proxy-api/proxy-backend.tsx +0 -60
- package/src/proxy-api/proxy-constants.tsx +0 -28
- package/src/proxy-api/proxy-helpers.tsx +0 -91
- package/src/proxy-api-client.tsx +0 -1
- package/src/proxy-api-server.tsx +0 -2
- package/src/services/http-client-services.tsx +0 -75
- package/src/services/http-services.tsx +0 -158
- package/src/services/loader-service.tsx +0 -185
- package/src/services/localstorage-service.tsx +0 -119
- package/src/services/message-services.tsx +0 -383
- package/src/services/theme-service.tsx +0 -163
- package/src/services/user-services.tsx +0 -10
- package/src/sso-config/auth-token-validation.ts +0 -16
- package/src/sso-config/callback-route.tsx +0 -35
- package/src/sso-config/cookie-encryption.ts +0 -51
- package/src/sso-config/cookie-helpers.tsx +0 -102
- package/src/sso-config/forgot-password-route.tsx +0 -36
- package/src/sso-config/oauth-callback-state.ts +0 -61
- package/src/sso-config/pkce-helpers.ts +0 -9
- package/src/sso-config/provider-complete-route.tsx +0 -18
- package/src/sso-config/redirect-context-actions.tsx +0 -45
- package/src/sso-config/redirect-context-helpers.tsx +0 -159
- package/src/sso-config/redirect-context-persist.tsx +0 -18
- package/src/sso-config/redirect-context-route.tsx +0 -45
- package/src/sso-config/refresh-route.tsx +0 -23
- package/src/sso-config/sign-in-route.tsx +0 -74
- package/src/sso-config/sign-out-route.tsx +0 -57
- package/src/sso-config/sign-up-route.tsx +0 -57
- package/src/sso-config/sso-backend-flow.ts +0 -38
- package/src/sso-config/sso-complete-route.tsx +0 -50
- package/src/sso-config/sso-config.ts +0 -59
- package/src/sso-config/sso-interfaces.tsx +0 -99
- package/src/sso-config/sso-response-helpers.tsx +0 -20
- package/src/sso-server.tsx +0 -21
- package/src/styles/nexus.animation.css +0 -269
- package/src/styles/nexus.core.css +0 -119
- package/src/styles/nexus.dialog.css +0 -144
- package/src/styles/nexus.grid-view.css +0 -42
- package/src/styles/nexus.icon.css +0 -51
- package/src/styles/nexus.input.css +0 -207
- package/src/styles/nexus.loader.css +0 -11
- package/src/styles/nexus.logic.css +0 -47
- package/src/styles/nexus.utility.css +0 -347
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { EModules } from "../interfaces/system-interfaces";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/** HTTP methods supported by the backend proxy. */
|
|
5
|
-
export const PROXY_ALLOWED_METHODS = new Set(["GET", "POST", "PUT", "DELETE", "PATCH"]);
|
|
6
|
-
|
|
7
|
-
/** Request headers that must not be forwarded to the backend. */
|
|
8
|
-
export const PROXY_REQUEST_HEADERS_TO_SKIP = new Set(["host", "connection", "content-length", "transfer-encoding", "keep-alive", "upgrade", "cookie"]);
|
|
9
|
-
|
|
10
|
-
/** Response headers that must not be forwarded to the browser. */
|
|
11
|
-
export const PROXY_RESPONSE_HEADERS_TO_SKIP = new Set(["connection", "transfer-encoding", "keep-alive", "proxy-authenticate", "proxy-authorization", "te", "trailer", "upgrade"]);
|
|
12
|
-
|
|
13
|
-
/** Public path prefix the browser uses to reach the proxy. */
|
|
14
|
-
|
|
15
|
-
/** Allowed modules for proxy requests. */
|
|
16
|
-
|
|
17
|
-
export const ALLOWED_MODULES = [
|
|
18
|
-
EModules.Authentication.toString(),
|
|
19
|
-
EModules.Configuration.toString(),
|
|
20
|
-
EModules.Enterprise.toString(),
|
|
21
|
-
EModules.Drive.toString(),
|
|
22
|
-
EModules.Message.toString(),
|
|
23
|
-
EModules.Accounting.toString(),
|
|
24
|
-
EModules.Report.toString(),
|
|
25
|
-
EModules.Portfolio.toString(),
|
|
26
|
-
EModules.Subscription.toString(),
|
|
27
|
-
EModules.Reservation.toString(),
|
|
28
|
-
]
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
-
import { EErrorCodes, EExceptionCategories } from "../interfaces/exception-interfaces";
|
|
3
|
-
import { GetResponse, PROXY_PUBLIC_BASE_PATH } from "../interfaces/http-interfaces";
|
|
4
|
-
import { EModules } from "../interfaces/system-interfaces";
|
|
5
|
-
import { PROXY_REQUEST_HEADERS_TO_SKIP, PROXY_RESPONSE_HEADERS_TO_SKIP } from "./proxy-constants";
|
|
6
|
-
|
|
7
|
-
const BACKEND_NOT_CONFIGURED_ERROR = "Backend API is not configured.";
|
|
8
|
-
|
|
9
|
-
export function BuildBackendUrl(backendBase: string, pathSegments: string[], searchParams: URLSearchParams): string {
|
|
10
|
-
if (pathSegments.some((segment) => segment === ".." || segment === "." || segment.includes("\\"))) throw new Error("Invalid path.");
|
|
11
|
-
else if (!backendBase) throw new Error(BACKEND_NOT_CONFIGURED_ERROR);
|
|
12
|
-
|
|
13
|
-
const path = pathSegments.map(encodeURIComponent).join("/");
|
|
14
|
-
const query = searchParams.toString();
|
|
15
|
-
|
|
16
|
-
return query ? `${backendBase}/${path}?${query}` : `${backendBase}/${path}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function BuildForwardHeaders(req: NextRequest): Headers {
|
|
20
|
-
const headers = new Headers();
|
|
21
|
-
|
|
22
|
-
req.headers.forEach((value, key) => {
|
|
23
|
-
if (PROXY_REQUEST_HEADERS_TO_SKIP.has(key.toLowerCase())) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
headers.set(key, value);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return headers;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function ReadRequestBody(req: NextRequest, method: string): Promise<BodyInit | undefined> {
|
|
34
|
-
if (method === "GET" || method === "HEAD" || method === "OPTIONS") {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return await req.arrayBuffer();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function ProxyErrorResponse(message: string, status: number, messageCode = "PROXY_ERROR", errorCode: EErrorCodes = EErrorCodes.Unknown): NextResponse {
|
|
42
|
-
return NextResponse.json(GetResponse.ERROR(message, messageCode, EExceptionCategories.Application, errorCode, undefined, null, status), { status });
|
|
43
|
-
}
|
|
44
|
-
function stripBackendBasePath(pathname: string, backendBaseUrl: string): string {
|
|
45
|
-
try {
|
|
46
|
-
const basePath = new URL(backendBaseUrl).pathname.replace(/\/+$/, "");
|
|
47
|
-
if (pathname.startsWith(basePath)) {
|
|
48
|
-
return pathname.slice(basePath.length).replace(/^\/+/, "");
|
|
49
|
-
}
|
|
50
|
-
} catch {
|
|
51
|
-
// Fall through to pathname cleanup below.
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return pathname.replace(/^\/+/, "");
|
|
55
|
-
}
|
|
56
|
-
export function SanitizeResponseHeaders(headers: Headers, backendBaseUrl: string, module: EModules): Headers {
|
|
57
|
-
const sanitized = new Headers();
|
|
58
|
-
let backendHost: string | undefined;
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
backendHost = new URL(backendBaseUrl).host;
|
|
62
|
-
} catch {
|
|
63
|
-
backendHost = undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
headers.forEach((value, key) => {
|
|
67
|
-
const lowerKey = key.toLowerCase();
|
|
68
|
-
|
|
69
|
-
if (PROXY_RESPONSE_HEADERS_TO_SKIP.has(lowerKey)) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (lowerKey === "location" && backendHost) {
|
|
74
|
-
try {
|
|
75
|
-
const location = new URL(value, backendBaseUrl);
|
|
76
|
-
if (location.host === backendHost) {
|
|
77
|
-
const relativePath = stripBackendBasePath(location.pathname, backendBaseUrl);
|
|
78
|
-
const proxyPath = `${PROXY_PUBLIC_BASE_PATH}/${module}/${relativePath}${location.search}`;
|
|
79
|
-
sanitized.set(key, proxyPath);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
// Relative locations are forwarded as-is.
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
sanitized.set(key, value);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return sanitized;
|
|
91
|
-
}
|
package/src/proxy-api-client.tsx
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./proxy-api/proxy-constants";
|
package/src/proxy-api-server.tsx
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Client-side HTTP utilities for `"use client"` pages and components.
|
|
5
|
-
* Adds UI-level response handling (loader/toast hooks). For Route Handlers and
|
|
6
|
-
* Server Components use `http-services` (`HttpPost`, `HttpGet`, …) from `nexus-shared` instead.
|
|
7
|
-
*/
|
|
8
|
-
import { DatasourceTypes, EBody, GetApiInformations, GetResponse, IApiInformations, IErrorRespose, IInterface, ISuccessResponse, UN } from "../interface";
|
|
9
|
-
import { HttpDelete, HttpGet, HttpPost, HttpPut } from "./http-services";
|
|
10
|
-
import { ErrorMessage, SuccessMessage } from "./message-services";
|
|
11
|
-
|
|
12
|
-
/** // if same url is called multiple times, it will only send one request and return the same promise
|
|
13
|
-
// this is to prevent multiple requests to the same url at the same time
|
|
14
|
-
// this is useful for example when user is typing in a search box and multiple requests are sent to the server
|
|
15
|
-
// this will prevent multiple requests to the same url and return the same promise
|
|
16
|
-
// this will also prevent multiple requests to the same url when user is navigating to different pages and the same url is called in each page
|
|
17
|
-
// If country Dropdown is called multiple times, it will only send one request and return the same promise
|
|
18
|
-
// this is useful for example when user is typing in a search box and multiple requests are sent to the server
|
|
19
|
-
*/
|
|
20
|
-
const pendingRequests: { [url: string]: Promise<any> | undefined } = {};
|
|
21
|
-
export const Get = async (apiUrl: string, successMessage?: boolean | UN, errorMessage?: boolean | UN): Promise<ISuccessResponse | IErrorRespose> => {
|
|
22
|
-
if (pendingRequests[apiUrl] !== undefined) return pendingRequests[apiUrl]!;
|
|
23
|
-
|
|
24
|
-
pendingRequests[apiUrl] = HttpGet(apiUrl)
|
|
25
|
-
.then((response) => handleResponse(response, successMessage ?? false, errorMessage ?? true))
|
|
26
|
-
.finally(() => {
|
|
27
|
-
delete pendingRequests[apiUrl];
|
|
28
|
-
});
|
|
29
|
-
return pendingRequests[apiUrl]!;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const Put = async (apiUrl: string, body?: any | UN, bodyType?: EBody | UN, successMessage?: boolean | UN, errorMessage?: boolean | UN) => {
|
|
33
|
-
return await handleResponse(await HttpPut(apiUrl, body, bodyType, null, 0, null), successMessage ?? true, errorMessage ?? true);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const Post = async (apiUrl: string, body?: any | UN, bodyType?: EBody | UN, successMessage?: boolean | UN, errorMessage?: boolean | UN) => {
|
|
37
|
-
const isFindListing = Array.isArray(body) && apiUrl.endsWith("/FindListing");
|
|
38
|
-
|
|
39
|
-
if (!isFindListing) {
|
|
40
|
-
return await handleResponse(await HttpPost(apiUrl, body, bodyType, null, 0, null), successMessage ?? true, errorMessage ?? true);
|
|
41
|
-
} else {
|
|
42
|
-
const apiKey = `${apiUrl}__${(body as string[]).sort().join(",")}`;
|
|
43
|
-
|
|
44
|
-
if (pendingRequests[apiKey]) return pendingRequests[apiKey];
|
|
45
|
-
|
|
46
|
-
pendingRequests[apiKey] = HttpPost(apiUrl, body, bodyType, null, 0, null)
|
|
47
|
-
.then((response) => handleResponse(response, successMessage ?? true, errorMessage ?? true))
|
|
48
|
-
.finally(() => {
|
|
49
|
-
delete pendingRequests[apiKey];
|
|
50
|
-
});
|
|
51
|
-
return pendingRequests[apiKey];
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const Delete = async (apiUrl: string, successMessage?: boolean | UN, errorMessage?: boolean | UN) => {
|
|
56
|
-
return await handleResponse(await HttpDelete(apiUrl, null, 0, null), successMessage ?? true, errorMessage ?? true);
|
|
57
|
-
};
|
|
58
|
-
export const SubmitApi = async (api: DatasourceTypes | UN, parameters: IInterface | IInterface[] | UN, successMessage?: boolean | UN, errorMessage?: boolean | UN): Promise<IErrorRespose | ISuccessResponse> => {
|
|
59
|
-
if (!api || Array.isArray(api) || !GetApiInformations.IS_API(api)) return Promise.resolve(GetResponse.SUCCESS(api));
|
|
60
|
-
const apiInfo = api as IApiInformations;
|
|
61
|
-
|
|
62
|
-
const url = GetApiInformations.BUILD_API(apiInfo, parameters);
|
|
63
|
-
|
|
64
|
-
// TODO:
|
|
65
|
-
return Post(url, parameters, null, successMessage, errorMessage);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const handleResponse = async (result: ISuccessResponse | IErrorRespose, successMessage?: boolean, errorMessage?: boolean): Promise<ISuccessResponse | IErrorRespose> => {
|
|
69
|
-
if (result.isSuccess && !(result as IErrorRespose).exception) {
|
|
70
|
-
if (successMessage) SuccessMessage("Request Success!", result.message ?? "Success");
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
if (errorMessage) ErrorMessage("Request Failed!", result.message ?? "Failed");
|
|
74
|
-
return result;
|
|
75
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side HTTP utilities for Route Handlers, Server Components, and Server Actions.
|
|
3
|
-
* For browser/client components use `http-client-services` (`Post`, `Get`, …) via `nexus-shared/client`.
|
|
4
|
-
*/
|
|
5
|
-
import { Delay } from "../helpers/utility-helpers";
|
|
6
|
-
import { EActions, EBody, EModules, GetMethod, GetResponse, IErrorRespose, ISuccessResponse, UN } from "../interface";
|
|
7
|
-
import { EErrorCodes, EExceptionCategories } from "../interfaces/exception-interfaces";
|
|
8
|
-
import { APIS, NEXUS_CONFIG, NEXUS_INFO } from "../nexus.environments";
|
|
9
|
-
|
|
10
|
-
const MAX_RETRIES = NEXUS_INFO.IS_PRODUCTION ? 2 : 1;
|
|
11
|
-
const RETRY_DELAY_MS = NEXUS_INFO.IS_PRODUCTION ? 50 : 1;
|
|
12
|
-
|
|
13
|
-
export const BuildApiHeader = (formdata?: any, httpMethod?: EActions | string, bodyType: EBody | UN = EBody.JSON, token?: string | UN, revalidate?: number | UN, browserId?: string | UN): RequestInit & { next?: { revalidate: number } } => {
|
|
14
|
-
httpMethod = httpMethod ?? "GET";
|
|
15
|
-
bodyType = bodyType ?? EBody.JSON;
|
|
16
|
-
|
|
17
|
-
const headers = new Headers();
|
|
18
|
-
if (token && token.length > 50) headers.append("authorization", token.startsWith("Bearer ") ? token : `Bearer ${token}`);
|
|
19
|
-
if (browserId) headers.append("bid", browserId);
|
|
20
|
-
headers.append("Content-Type", bodyType);
|
|
21
|
-
|
|
22
|
-
const options: RequestInit & { next?: { revalidate: number } } = {
|
|
23
|
-
method: typeof httpMethod === "string" ? httpMethod : GetMethod(httpMethod),
|
|
24
|
-
headers,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (formdata) options.body = bodyType === EBody.JSON ? JSON.stringify(formdata) : formdata;
|
|
28
|
-
|
|
29
|
-
if (!revalidate || revalidate <= 0) {
|
|
30
|
-
// No caching
|
|
31
|
-
options.cache = "no-store";
|
|
32
|
-
} else {
|
|
33
|
-
// Use Next.js ISR caching
|
|
34
|
-
options.next = { revalidate: revalidate ?? 0 };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return options;
|
|
38
|
-
};
|
|
39
|
-
const shouldRetry = (error: any) => error.name === "AbortError" || error.code === "ECONNREFUSED" || error.message.includes("fetch") || error.message.includes("network");
|
|
40
|
-
const safeFetch = async (fetchFunc: () => Promise<Response>): Promise<ISuccessResponse | IErrorRespose> => {
|
|
41
|
-
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
|
42
|
-
try {
|
|
43
|
-
const response = await fetchFunc();
|
|
44
|
-
if (!response.ok) return await handleResponse(response);
|
|
45
|
-
return await response.json();
|
|
46
|
-
} catch (error: any) {
|
|
47
|
-
if (attempt < MAX_RETRIES - 1 && shouldRetry(error)) {
|
|
48
|
-
await Delay(RETRY_DELAY_MS * (attempt + 1));
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
return handleNetworkError(error);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return handleError({ status: 500, message: "Maximum retry attempts exceeded." });
|
|
55
|
-
};
|
|
56
|
-
const fetchWithTimeout = async (url: string, options?: RequestInit, timeout = NEXUS_CONFIG.DEFAULT_HTTP_REQUEST_TIMEOUT): Promise<Response> => {
|
|
57
|
-
const controller = new AbortController();
|
|
58
|
-
const id = setTimeout(() => controller.abort(), timeout);
|
|
59
|
-
try {
|
|
60
|
-
const response = await fetch(url, { ...options, signal: controller.signal });
|
|
61
|
-
return response;
|
|
62
|
-
} catch (error) {
|
|
63
|
-
throw error;
|
|
64
|
-
} finally {
|
|
65
|
-
clearTimeout(id);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
export const HttpGet = async (apiUrl: string, token?: string | UN, revalidate?: number | UN, browserId?: string | UN) => {
|
|
69
|
-
return await safeFetch(() => fetchWithTimeout(apiUrl, BuildApiHeader(undefined, EActions.Get, EBody.JSON, token, revalidate, browserId)));
|
|
70
|
-
};
|
|
71
|
-
export const HttpPost = async (apiUrl: string, body?: any | UN, bodyType?: EBody | UN, token?: string | UN, revalidate?: number | UN, browserId?: string | UN) => {
|
|
72
|
-
return await safeFetch(() => fetchWithTimeout(apiUrl, BuildApiHeader(body, EActions.Post, bodyType, token, revalidate, browserId)));
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const HttpPut = async (apiUrl: string, body?: any | UN, bodyType?: EBody | UN, token?: string | UN, revalidate?: number | UN, browserId?: string | UN) => {
|
|
76
|
-
return await safeFetch(() => fetchWithTimeout(apiUrl, BuildApiHeader(body, EActions.Put, bodyType, token, revalidate, browserId)));
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const HttpDelete = async (apiUrl: string, token?: string | UN, revalidate?: number | UN, browserId?: string | UN) => {
|
|
80
|
-
return await safeFetch(() => fetchWithTimeout(apiUrl, BuildApiHeader(undefined, EActions.Delete, undefined, token, revalidate, browserId)));
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const HttpFetch = async (apiUrl: string, method: EActions | string, body?: any, bodyType?: EBody, token?: string | UN, revalidate?: number, browserId?: string | UN): Promise<Response | Error> => {
|
|
84
|
-
try {
|
|
85
|
-
const response = await fetch(apiUrl, BuildApiHeader(body, method, bodyType, token, revalidate, browserId));
|
|
86
|
-
return response;
|
|
87
|
-
} catch (error: Error | any) {
|
|
88
|
-
return error;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const GetRootApi = (nexusModule: EModules) => {
|
|
93
|
-
switch (nexusModule) {
|
|
94
|
-
case EModules.None:
|
|
95
|
-
return "/api";
|
|
96
|
-
case EModules.Authentication:
|
|
97
|
-
return APIS.AUTHENTICATION;
|
|
98
|
-
case EModules.Configuration:
|
|
99
|
-
return APIS.CONFIGURATION;
|
|
100
|
-
case EModules.Enterprise:
|
|
101
|
-
return APIS.ENTERPRISE;
|
|
102
|
-
case EModules.Drive:
|
|
103
|
-
return APIS.DRIVE;
|
|
104
|
-
case EModules.Message:
|
|
105
|
-
return APIS.MESSAGE;
|
|
106
|
-
case EModules.Accounting:
|
|
107
|
-
return APIS.ACCOUNTING;
|
|
108
|
-
case EModules.Report:
|
|
109
|
-
return APIS.REPORT;
|
|
110
|
-
default:
|
|
111
|
-
throw new Error("Invalid Nexus Module");
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const handleResponse = async (response: Response): Promise<IErrorRespose> => {
|
|
115
|
-
const status = response.status;
|
|
116
|
-
try {
|
|
117
|
-
const errorData = await response.json();
|
|
118
|
-
|
|
119
|
-
return handleError({ ...errorData, code: status, status: status });
|
|
120
|
-
} catch (error: any) {
|
|
121
|
-
let message = "Unexpected server error.";
|
|
122
|
-
switch (status) {
|
|
123
|
-
case 401:
|
|
124
|
-
case 403:
|
|
125
|
-
message = "You do not have permission to access this resource.";
|
|
126
|
-
break;
|
|
127
|
-
case 404:
|
|
128
|
-
case 410:
|
|
129
|
-
message = "Resource not found.";
|
|
130
|
-
break;
|
|
131
|
-
case 405:
|
|
132
|
-
message = "Method not allowed.";
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
return handleError(GetResponse.ERROR(message, "GENERIC_ERROR", EExceptionCategories.Application, EErrorCodes.Unknown, undefined, undefined, status));
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
export const handleError = (error: any): IErrorRespose => {
|
|
139
|
-
return {
|
|
140
|
-
isSuccess: false,
|
|
141
|
-
code: error?.code,
|
|
142
|
-
message: error?.message || "An unknown error occurred.",
|
|
143
|
-
messageCode: error?.messageCode || "GENERIC_ERROR",
|
|
144
|
-
exceptionCategory: error?.exceptionCategory || EExceptionCategories.Application,
|
|
145
|
-
errorCode: error?.errorCode || EErrorCodes.Unknown,
|
|
146
|
-
inputName: error?.inputName || undefined,
|
|
147
|
-
exception: error?.exception || undefined,
|
|
148
|
-
result: error?.result || undefined,
|
|
149
|
-
};
|
|
150
|
-
};
|
|
151
|
-
const handleNetworkError = (error: any): IErrorRespose => {
|
|
152
|
-
return handleError({
|
|
153
|
-
status: 503,
|
|
154
|
-
message: "Unable to connect to the server. Please check your network or backend status.",
|
|
155
|
-
key: "NETWORK_ERROR",
|
|
156
|
-
exception: error,
|
|
157
|
-
});
|
|
158
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { FindChildElement, IsBrowser, RemoveElement } from "../helpers/browser-helpers";
|
|
2
|
-
import { EAnimationClasses, ESizes } from "../interfaces/layout-interfaces";
|
|
3
|
-
import { EBackgrounds } from "../interfaces/theme-interfaces";
|
|
4
|
-
import { UN } from "../interfaces/type-interfaces";
|
|
5
|
-
import { FILES } from "../nexus.environments";
|
|
6
|
-
|
|
7
|
-
const DEFAULT_LOADER_TYPE = EAnimationClasses.SPIN;
|
|
8
|
-
const DEFAULT_LOADER_SIZE = ESizes.Medium;
|
|
9
|
-
const DEFAULT_LOADER_DELAY = 0;
|
|
10
|
-
const LOADER_IDENTITY = "nexus-loader";
|
|
11
|
-
const LOADER_DATA_COUNT_ATTRIBUTE = "data-count";
|
|
12
|
-
const LOADER_DATA_TYPE_ATTRIBUTE = "data-type";
|
|
13
|
-
const LOADER_DATA_SIZE_ATTRIBUTE = "data-size";
|
|
14
|
-
const LOADER_DATA_DISABLED_INPUTS_ATTRIBUTE = "data-disabled-inputs";
|
|
15
|
-
const DISPOSED_LOADER_CLASS = "disposed";
|
|
16
|
-
const DEFAULT_LOADER_BACKGROUND = EBackgrounds.PopupBackgroundColor;
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param parent - Parent element to show loader on
|
|
20
|
-
* @param type - Animation type to use for showing loader
|
|
21
|
-
* @param disabledInputs - If true, all inputs will be disabled
|
|
22
|
-
* @param size - Size of the loader
|
|
23
|
-
* @param delay - Delay in milliseconds
|
|
24
|
-
* @returns - Returns the loader element
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const _findParentElement = (parent: String | HTMLElement | UN): HTMLElement => {
|
|
28
|
-
if (parent) {
|
|
29
|
-
if (typeof parent === "string") return document.getElementById(parent) ?? document.body;
|
|
30
|
-
else if (parent instanceof HTMLElement) return parent ?? document.body;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return document.body;
|
|
34
|
-
};
|
|
35
|
-
const _findExistingLoader = (parent: HTMLElement): HTMLElement | null => {
|
|
36
|
-
const loaderElement = FindChildElement(parent, `#${LOADER_IDENTITY}`);
|
|
37
|
-
return loaderElement as HTMLElement | null;
|
|
38
|
-
};
|
|
39
|
-
const _updateLoaderProperties = (loaderElement: HTMLElement, type: EAnimationClasses, size: ESizes, isInputLoader: boolean) => {
|
|
40
|
-
if (type === EAnimationClasses.SPIN) {
|
|
41
|
-
if (size === ESizes.VeryTiny) {
|
|
42
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", isInputLoader ? "1.5rem" : "2.5rem");
|
|
43
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", isInputLoader ? "0.28rem" : "0.34rem");
|
|
44
|
-
} else if (size === ESizes.Tiny) {
|
|
45
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", isInputLoader ? "2.0rem" : "2.8rem");
|
|
46
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", isInputLoader ? "0.31rem" : "0.36rem");
|
|
47
|
-
} else if (size === ESizes.VerySmall) {
|
|
48
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", isInputLoader ? "2.4rem" : "3rem");
|
|
49
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", isInputLoader ? "0.34rem" : "0.38rem");
|
|
50
|
-
} else if (size === ESizes.Small) {
|
|
51
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", "3.5rem");
|
|
52
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", "0.45rem");
|
|
53
|
-
} else if (size === ESizes.Medium) {
|
|
54
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", "4rem");
|
|
55
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", "0.5rem");
|
|
56
|
-
} else if (size === ESizes.Large) {
|
|
57
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", "4.8rem");
|
|
58
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", "0.55rem");
|
|
59
|
-
} else if (size === ESizes.ExtraLarge) {
|
|
60
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", "5.5rem");
|
|
61
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", "0.6rem");
|
|
62
|
-
} else if (size === ESizes.VeryExtraLarge) {
|
|
63
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", "6.5rem");
|
|
64
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", "0.7rem");
|
|
65
|
-
} else if (size === ESizes.FullSize) {
|
|
66
|
-
loaderElement.style.setProperty("--SPIN_BOX_SIZE", "8rem");
|
|
67
|
-
loaderElement.style.setProperty("--SPIN_BOX_BORDER_SIZE", "0.8rem");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const _updateLoaderAttributes = (loaderElement: HTMLElement, type: EAnimationClasses, size: ESizes, disabledInputs: boolean, count: number, isInputLoader: boolean) => {
|
|
72
|
-
loaderElement.setAttribute(LOADER_DATA_COUNT_ATTRIBUTE, count.toString());
|
|
73
|
-
loaderElement.setAttribute(LOADER_DATA_TYPE_ATTRIBUTE, type);
|
|
74
|
-
loaderElement.setAttribute(LOADER_DATA_SIZE_ATTRIBUTE, size);
|
|
75
|
-
loaderElement.setAttribute(LOADER_DATA_DISABLED_INPUTS_ATTRIBUTE, disabledInputs ? "true" : "false");
|
|
76
|
-
};
|
|
77
|
-
const _createLoaderElement = (parent: HTMLElement, type: EAnimationClasses, size: ESizes, showLogo: boolean, disabledInputs: boolean, background: EBackgrounds, defaultClass?: string | UN, isInputLoader?: boolean): HTMLElement | null => {
|
|
78
|
-
const loaderElement = _findExistingLoader(parent);
|
|
79
|
-
if (loaderElement && !loaderElement.classList.contains(DISPOSED_LOADER_CLASS)) {
|
|
80
|
-
const count = parseInt(loaderElement.getAttribute(LOADER_DATA_COUNT_ATTRIBUTE) ?? "0") + 1;
|
|
81
|
-
_updateLoaderAttributes(loaderElement, type, size, disabledInputs, count, isInputLoader ?? false);
|
|
82
|
-
_updateLoaderProperties(loaderElement, type, size, isInputLoader ?? false);
|
|
83
|
-
return loaderElement as HTMLElement;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const newLoaderElement = document.createElement("div");
|
|
87
|
-
newLoaderElement.id = LOADER_IDENTITY;
|
|
88
|
-
newLoaderElement.classList.add("nexus-container", "o0", EAnimationClasses.FADE_IN, background);
|
|
89
|
-
if (defaultClass) newLoaderElement.classList.add(...defaultClass.split(" "));
|
|
90
|
-
_updateLoaderAttributes(newLoaderElement, type, size, disabledInputs, 1, isInputLoader ?? false);
|
|
91
|
-
_updateLoaderProperties(newLoaderElement, type, size, isInputLoader ?? false);
|
|
92
|
-
|
|
93
|
-
newLoaderElement.style.maxHeight = "100%!important";
|
|
94
|
-
newLoaderElement.style.maxWidth = "100%!important";
|
|
95
|
-
|
|
96
|
-
const loader = document.createElement("div");
|
|
97
|
-
newLoaderElement.appendChild(loader);
|
|
98
|
-
loader.classList.add(size, type);
|
|
99
|
-
|
|
100
|
-
const isTextLoader = (type === EAnimationClasses.BOUNCE || type === EAnimationClasses.FADE_IN_OUT || type === EAnimationClasses.PULSE_IN_OUT) && parent === document.body;
|
|
101
|
-
if (isTextLoader && !showLogo) {
|
|
102
|
-
loader.innerText = "Loading...";
|
|
103
|
-
loader.classList.add("tx52");
|
|
104
|
-
loader.style.fontSize = "1.5rem";
|
|
105
|
-
} else if (showLogo && type !== EAnimationClasses.SLIDE_BAR && type !== EAnimationClasses.BOUNCE_BAR) {
|
|
106
|
-
const logoElement = document.createElement("img");
|
|
107
|
-
logoElement.src = FILES.LOGO.ICON;
|
|
108
|
-
logoElement.alt = "Logo";
|
|
109
|
-
logoElement.className = "pa bg52";
|
|
110
|
-
logoElement.style.width = "calc(var(--SPIN_BOX_SIZE) - var(--SPIN_BOX_BORDER_SIZE))";
|
|
111
|
-
logoElement.style.height = "calc(var(--SPIN_BOX_SIZE) - var(--SPIN_BOX_BORDER_SIZE))";
|
|
112
|
-
logoElement.style.zIndex = "-1";
|
|
113
|
-
|
|
114
|
-
if (isTextLoader) {
|
|
115
|
-
logoElement.style.padding = `var(--SPIN_BOX_BORDER_SIZE)`;
|
|
116
|
-
logoElement.classList.add("txy50", "r2");
|
|
117
|
-
loader.appendChild(logoElement);
|
|
118
|
-
} else {
|
|
119
|
-
logoElement.style.padding = `calc(var(--SPIN_BOX_BORDER_SIZE) * 1.3)`;
|
|
120
|
-
logoElement.style.borderRadius = `35%`;
|
|
121
|
-
newLoaderElement.appendChild(logoElement);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
parent.appendChild(newLoaderElement);
|
|
126
|
-
return newLoaderElement;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export const ShowLoader = async (parent?: String | HTMLElement | UN, type?: EAnimationClasses | UN, disabledInputs?: boolean | UN, size?: ESizes | UN, delay?: number | UN, showLogo?: boolean | UN, background?: EBackgrounds | UN, defaultClass?: string | UN, isInputLoader?: boolean | UN): Promise<HTMLElement | null> => {
|
|
130
|
-
if (!IsBrowser()) return Promise.resolve(null);
|
|
131
|
-
type = type ?? DEFAULT_LOADER_TYPE;
|
|
132
|
-
size = size ?? DEFAULT_LOADER_SIZE;
|
|
133
|
-
background = background ?? DEFAULT_LOADER_BACKGROUND;
|
|
134
|
-
|
|
135
|
-
return new Promise((resolve) => {
|
|
136
|
-
const timeout = setTimeout(() => {
|
|
137
|
-
clearTimeout(timeout);
|
|
138
|
-
const parentElement = _findParentElement(parent);
|
|
139
|
-
const loaderElement = _createLoaderElement(parentElement, type, size, showLogo ?? true, disabledInputs ?? false, background, defaultClass, isInputLoader ?? false);
|
|
140
|
-
resolve(loaderElement);
|
|
141
|
-
}, delay ?? DEFAULT_LOADER_DELAY);
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Hide loader if it is visible
|
|
147
|
-
* @param parent - Parent element to hide loader from
|
|
148
|
-
* @param type - Animation type to use for hiding loader
|
|
149
|
-
* @param force - This will dispose all loader elements
|
|
150
|
-
* @param delay - Delay in milliseconds
|
|
151
|
-
*/
|
|
152
|
-
export const HideLoader = (parent?: String | HTMLElement | UN, force?: boolean | UN, delay?: number | UN): Promise<boolean> => {
|
|
153
|
-
if (!IsBrowser()) return Promise.resolve(false);
|
|
154
|
-
const parentElement = _findParentElement(parent);
|
|
155
|
-
|
|
156
|
-
return new Promise((resolve) => {
|
|
157
|
-
const timeout = setTimeout(() => {
|
|
158
|
-
clearTimeout(timeout);
|
|
159
|
-
|
|
160
|
-
const loaderElement = _findExistingLoader(parentElement);
|
|
161
|
-
if (!loaderElement) return resolve(false);
|
|
162
|
-
|
|
163
|
-
const count = parseInt(loaderElement.getAttribute(LOADER_DATA_COUNT_ATTRIBUTE) ?? "0");
|
|
164
|
-
|
|
165
|
-
if (force || count <= 1) {
|
|
166
|
-
RemoveElement(loaderElement, 300);
|
|
167
|
-
} else loaderElement.setAttribute(LOADER_DATA_COUNT_ATTRIBUTE, (count - 1).toString());
|
|
168
|
-
return resolve(true);
|
|
169
|
-
}, delay ?? DEFAULT_LOADER_DELAY);
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
export const InputLoader = async (parent: String | HTMLElement, isShow: boolean, defaultClass?: string | UN): Promise<HTMLElement | null> => {
|
|
174
|
-
if (isShow !== false) {
|
|
175
|
-
const loaderElement = await ShowLoader(parent, EAnimationClasses.SPIN, false, ESizes.VeryTiny, null, false, EBackgrounds.None, defaultClass, true);
|
|
176
|
-
if (loaderElement) {
|
|
177
|
-
loaderElement.style.width = "100%";
|
|
178
|
-
loaderElement.style.height = "100%";
|
|
179
|
-
}
|
|
180
|
-
return loaderElement;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
HideLoader(parent);
|
|
184
|
-
return null;
|
|
185
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { CreateUpdatePreference } from "../api-services/preference-service";
|
|
2
|
-
import { IsBrowser } from "../helpers/browser-helpers";
|
|
3
|
-
import { Debounce } from "../helpers/utility-helpers";
|
|
4
|
-
import { EFlexPositions, UN } from "../interface";
|
|
5
|
-
import { LOCAL_STORAGE_KEYS } from "../interfaces/storage-interfaces";
|
|
6
|
-
import { EPreferenceTargets } from "../interfaces/system-interfaces";
|
|
7
|
-
import { IThemeInformation } from "../interfaces/theme-interfaces";
|
|
8
|
-
import { O } from "../nexus-client";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create a debounce function to update the preference in the server
|
|
12
|
-
* This is used to update the preference in the server
|
|
13
|
-
* @param CreateUpdatePreference The function to create the update preference
|
|
14
|
-
* @param debounceTime The debounce time in milliseconds
|
|
15
|
-
* @returns The debounce function
|
|
16
|
-
*/
|
|
17
|
-
const _createUpdatePreferenceDebounce = Debounce(CreateUpdatePreference, 1000);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Sync the value of the local storage to the server
|
|
21
|
-
* This is used to sync the value of the local storage to the server
|
|
22
|
-
* @param key The key of the local storage
|
|
23
|
-
* @param value The value to set
|
|
24
|
-
* @param isSyncWithServer Whether to sync with the server
|
|
25
|
-
* @param target The target of the local storage
|
|
26
|
-
*/
|
|
27
|
-
const _syncStorageToServer = async (key: string, value: string | UN, isSyncWithServer?: boolean | UN, target?: EPreferenceTargets | UN) => {
|
|
28
|
-
if (!IsBrowser() || !isSyncWithServer || !target) return;
|
|
29
|
-
|
|
30
|
-
await _createUpdatePreferenceDebounce(target, key, value ?? null);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Set the value of the local storage
|
|
35
|
-
* This is used to set the value of the local storage
|
|
36
|
-
* @param key The key of the local storage
|
|
37
|
-
* @param value The value to set
|
|
38
|
-
* @param isSyncWithServer Whether to sync with the server
|
|
39
|
-
* @param target The target of the local storage
|
|
40
|
-
*/
|
|
41
|
-
export const SetLocalStorage = (key: string, value: string | UN, isSyncWithServer?: boolean | UN, target?: EPreferenceTargets | UN) => {
|
|
42
|
-
if (!IsBrowser()) return;
|
|
43
|
-
|
|
44
|
-
_syncStorageToServer(key, value, isSyncWithServer, target);
|
|
45
|
-
|
|
46
|
-
if (value === null || value === undefined) RemoveLocalStorage(key, isSyncWithServer, target);
|
|
47
|
-
else localStorage.setItem(key, value);
|
|
48
|
-
};
|
|
49
|
-
export const SetSessionStorage = (key: string, value: string | UN) => {
|
|
50
|
-
if (!IsBrowser()) return;
|
|
51
|
-
if (value === null || value === undefined) RemoveSessionStorage(key);
|
|
52
|
-
else sessionStorage.setItem(key, value);
|
|
53
|
-
};
|
|
54
|
-
export const GetSessionStorage = (key: string): string | null => {
|
|
55
|
-
if (!IsBrowser()) return null;
|
|
56
|
-
const data = sessionStorage.getItem(key);
|
|
57
|
-
if (!data) return null;
|
|
58
|
-
return data;
|
|
59
|
-
};
|
|
60
|
-
export const RemoveSessionStorage = (key: string) => {
|
|
61
|
-
if (!IsBrowser()) return;
|
|
62
|
-
sessionStorage.removeItem(key);
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Remove the value of the local storage
|
|
66
|
-
* This is used to remove the value of the local storage
|
|
67
|
-
* @param key The key of the local storage
|
|
68
|
-
* @param isSyncWithServer Whether to sync with the server
|
|
69
|
-
* @param target The target of the local storage
|
|
70
|
-
*/
|
|
71
|
-
export const RemoveLocalStorage = (key: string, isSyncWithServer?: boolean | UN, target?: EPreferenceTargets | UN) => {
|
|
72
|
-
_syncStorageToServer(key, null, isSyncWithServer, target);
|
|
73
|
-
localStorage.removeItem(key);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get the value of the local storage
|
|
78
|
-
* This is used to get the value of the local storage
|
|
79
|
-
* @param key The key of the local storage
|
|
80
|
-
* @returns The value of the local storage
|
|
81
|
-
*/
|
|
82
|
-
export function GetLocalStorage(key: string): string | null {
|
|
83
|
-
if (!IsBrowser()) return null;
|
|
84
|
-
const data = localStorage.getItem(key);
|
|
85
|
-
if (!data) return null;
|
|
86
|
-
return data;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Set the current theme in the local storage
|
|
91
|
-
* This is used to determine the current theme in the application
|
|
92
|
-
* @param themeCode The code of the theme to set
|
|
93
|
-
*/
|
|
94
|
-
export const SetCurrentTheme = (themeCode: string) => SetLocalStorage(LOCAL_STORAGE_KEYS.ACTIVE_THEME, themeCode, true, EPreferenceTargets.User);
|
|
95
|
-
export const GetCurrentTheme = (): IThemeInformation => {
|
|
96
|
-
const themeInformations = O.systemThemes;
|
|
97
|
-
if (!themeInformations || themeInformations.length === 0) throw new Error("No theme information found");
|
|
98
|
-
const activeTheme = GetLocalStorage(LOCAL_STORAGE_KEYS.ACTIVE_THEME);
|
|
99
|
-
if (!activeTheme) return themeInformations[0];
|
|
100
|
-
return themeInformations.find((theme) => theme.systemName === activeTheme) || themeInformations[0];
|
|
101
|
-
};
|
|
102
|
-
export const GetCurrentThemeName = (): string => GetCurrentTheme().systemName;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Get the position of the form buttons from the local storage
|
|
106
|
-
* This is used to determine the position of the form buttons in the form
|
|
107
|
-
* @returns The position of the form buttons
|
|
108
|
-
*/
|
|
109
|
-
export const GetFormButtonPosition = (): EFlexPositions => {
|
|
110
|
-
const position = GetLocalStorage(LOCAL_STORAGE_KEYS.FORM_BUTTON_POSITION);
|
|
111
|
-
if (!position) return EFlexPositions.Left;
|
|
112
|
-
return position as EFlexPositions;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Set the position of the form buttons in the local storage
|
|
116
|
-
* This is used to determine the position of the form buttons in the form
|
|
117
|
-
* @param position The position of the form buttons
|
|
118
|
-
*/
|
|
119
|
-
export const SetFormButtonPosition = (position: EFlexPositions) => SetLocalStorage(LOCAL_STORAGE_KEYS.FORM_BUTTON_POSITION, position, true, EPreferenceTargets.User);
|