@fibery/url-utils 2.3.2 → 2.3.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/lib/index.js +11 -2
- package/lib/parse-page-location.js +5 -3
- package/lib/routes.d.ts +4 -1
- package/lib/routes.js +11 -9
- package/lib/url-constants.d.ts +2 -1
- package/lib/url-constants.js +2 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -15,13 +15,22 @@ const getFlagValue = (flag) => new URLSearchParams(window.location.search).get(f
|
|
|
15
15
|
const getSharingKey = () => {
|
|
16
16
|
return getFlagValue("sharing-key") || getFlagValue("sk");
|
|
17
17
|
};
|
|
18
|
+
const hasQueryParam = (url, key) => {
|
|
19
|
+
const queryStart = url.indexOf("?");
|
|
20
|
+
return queryStart !== -1 && new URLSearchParams(url.slice(queryStart + 1)).has(key);
|
|
21
|
+
};
|
|
18
22
|
const appendSharingKey = (url, sharingKey = getSharingKey()) => {
|
|
19
23
|
if (!url) return url || "";
|
|
24
|
+
const [location] = url.split("#");
|
|
25
|
+
if (hasQueryParam(location, "sharing-key")) return url;
|
|
20
26
|
return appendQueryParameter(url, sharingParamName, sharingKey);
|
|
21
27
|
};
|
|
22
28
|
const appendIsPublicParam = (url) => {
|
|
23
|
-
if (isPublicSpaceMode)
|
|
24
|
-
|
|
29
|
+
if (isPublicSpaceMode) {
|
|
30
|
+
const [location] = url.split("#");
|
|
31
|
+
if (hasQueryParam(location, "is-public")) return url;
|
|
32
|
+
return appendQueryParameter(url, publicParamName, "1");
|
|
33
|
+
} else return url;
|
|
25
34
|
};
|
|
26
35
|
const signedFileUrl = (url) => {
|
|
27
36
|
return url?.startsWith("/api/files/") && !url?.startsWith("/api/files/r/") ? url.replace("/api/files", "/api/files/r") : url;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ORDERED_AUX_ROUTES, ORDERED_PAGE_ROUTES, ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP } from "./routes.js";
|
|
1
|
+
import { ORDERED_AUX_ROUTES, ORDERED_PAGE_ROUTES, ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP, ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP, isNonSpaPath } from "./routes.js";
|
|
2
2
|
import { matchPath } from "react-router-dom";
|
|
3
3
|
//#region src/parse-page-location.ts
|
|
4
4
|
const decodeDashesToSpaces = (str = "") => str.replace(/–/g, " ");
|
|
@@ -21,9 +21,11 @@ function safeDecodeURIComponent(maybeEncodedPath) {
|
|
|
21
21
|
}
|
|
22
22
|
function findPageMatch(maybeEncodedPath) {
|
|
23
23
|
const path = safeDecodeURIComponent(maybeEncodedPath);
|
|
24
|
-
|
|
24
|
+
if (isNonSpaPath(path)) return null;
|
|
25
|
+
const dashDecodedPath = decodeDashesToSpaces(path);
|
|
26
|
+
const processedPath = decodeUnderscoresToSpaces(dashDecodedPath);
|
|
25
27
|
return findTruthy(ORDERED_PAGE_ROUTES, ([page, route]) => {
|
|
26
|
-
const match = matchPath(processedPath, {
|
|
28
|
+
const match = matchPath(ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP[route] ? dashDecodedPath : processedPath, {
|
|
27
29
|
path: route,
|
|
28
30
|
exact: true
|
|
29
31
|
});
|
package/lib/routes.d.ts
CHANGED
|
@@ -20,8 +20,11 @@ declare const highlightTypePage = "/fibery/settings/:subsection(highlights)/:typ
|
|
|
20
20
|
declare const highlightTypeFieldEditPage = "/fibery/settings/:subsection(highlights)/:typeWithoutNamespace/fields/:fieldWithoutNamespace/edit";
|
|
21
21
|
declare const integrationSettingPage = "/fibery/settings/:subsection(integrations)/:templateId";
|
|
22
22
|
declare const personalIntegrationSettingPage = "/fibery/settings/:subsection(personal-integrations)/:integrationId";
|
|
23
|
+
declare const oauthApplicationSettingPage = "/fibery/settings/:subsection(oauth-applications)/:applicationId";
|
|
23
24
|
declare const typeAccessTemplateSettingPage = "/fibery/settings/:subsection(database-access-templates)/:templateId";
|
|
24
25
|
declare const isSettingsPage: (page?: string) => boolean;
|
|
26
|
+
declare const NON_SPA_PATH_PREFIXES: string[];
|
|
27
|
+
declare const isNonSpaPath: (path: string) => boolean;
|
|
25
28
|
declare const ORDERED_PAGE_ROUTES: Array<[string, string]>;
|
|
26
29
|
declare const PAGE_ROUTES: import("lodash").Dictionary<string>;
|
|
27
30
|
declare const ORDERED_COMMON_AUX_ROUTES: Array<[string, string]>;
|
|
@@ -35,4 +38,4 @@ declare const ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP: {
|
|
|
35
38
|
[k: string]: boolean;
|
|
36
39
|
};
|
|
37
40
|
//#endregion
|
|
38
|
-
export { AUX_ROUTES, AUX_ROUTES_PATTERNS, ORDERED_AUX_ROUTES, ORDERED_COMMON_AUX_ROUTES, ORDERED_PAGE_ROUTES, PAGE_ROUTES, ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP, ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP, appIndexViewLocator, appModePage, appTypeModeAccessTemplatePage, appTypeModeAutomationBasePage, appTypeModeAutomationSpecificPage, appTypeModeFieldEditPage, appTypeModeFormPage, appTypeModeGroupEditPage, appTypeModePage, appTypeModePageView, appTypeModeSubPage, deprecatedSpecificObjectEditorViewLocator, formsPublicPage, highlightTypeFieldEditPage, highlightTypePage, integrationSettingPage, isSettingsPage, personalIntegrationSettingPage, specificObjectEditorViewLocator, specificObjectUnknownObjectLocator, specificObjectViewsCatalogViewLocator, typeAccessTemplateSettingPage, userAccessViewLocator };
|
|
41
|
+
export { AUX_ROUTES, AUX_ROUTES_PATTERNS, NON_SPA_PATH_PREFIXES, ORDERED_AUX_ROUTES, ORDERED_COMMON_AUX_ROUTES, ORDERED_PAGE_ROUTES, PAGE_ROUTES, ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP, ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP, appIndexViewLocator, appModePage, appTypeModeAccessTemplatePage, appTypeModeAutomationBasePage, appTypeModeAutomationSpecificPage, appTypeModeFieldEditPage, appTypeModeFormPage, appTypeModeGroupEditPage, appTypeModePage, appTypeModePageView, appTypeModeSubPage, deprecatedSpecificObjectEditorViewLocator, formsPublicPage, highlightTypeFieldEditPage, highlightTypePage, integrationSettingPage, isNonSpaPath, isSettingsPage, oauthApplicationSettingPage, personalIntegrationSettingPage, specificObjectEditorViewLocator, specificObjectUnknownObjectLocator, specificObjectViewsCatalogViewLocator, typeAccessTemplateSettingPage, userAccessViewLocator };
|
package/lib/routes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeRegExpChar } from "./locator-utils.js";
|
|
2
|
-
import { formsUrlPrefix, publicUrlPrefix } from "./url-constants.js";
|
|
2
|
+
import { appsUrlPrefix, formsUrlPrefix, publicAppsUrlPrefix, publicUrlPrefix } from "./url-constants.js";
|
|
3
3
|
import fromPairs from "lodash/fromPairs.js";
|
|
4
4
|
//#region src/routes.ts
|
|
5
5
|
const titleWithPublicIdLocatorPattern = `[^/=]+?-\\d+`;
|
|
@@ -37,6 +37,7 @@ const highlightTypePage = "/fibery/settings/:subsection(highlights)/:typeWithout
|
|
|
37
37
|
const highlightTypeFieldEditPage = `${highlightTypePage}/fields/:fieldWithoutNamespace/edit`;
|
|
38
38
|
const integrationSettingPage = "/fibery/settings/:subsection(integrations)/:templateId";
|
|
39
39
|
const personalIntegrationSettingPage = "/fibery/settings/:subsection(personal-integrations)/:integrationId";
|
|
40
|
+
const oauthApplicationSettingPage = "/fibery/settings/:subsection(oauth-applications)/:applicationId";
|
|
40
41
|
const typeAccessTemplateSettingPage = "/fibery/settings/:subsection(database-access-templates)/:templateId";
|
|
41
42
|
const settingsPage = ":page/settings";
|
|
42
43
|
const appPage = ":page/app";
|
|
@@ -74,6 +75,7 @@ const orderedRoutes = [
|
|
|
74
75
|
[settingsPage, integrationSettingPage],
|
|
75
76
|
[settingsPage, highlightTypeFieldEditPage],
|
|
76
77
|
[settingsPage, personalIntegrationSettingPage],
|
|
78
|
+
[settingsPage, oauthApplicationSettingPage],
|
|
77
79
|
[settingsPage, typeAccessTemplateSettingPage],
|
|
78
80
|
[settingsPage, "/fibery/settings/:subsection"],
|
|
79
81
|
[settingsPage, "/fibery/settings"],
|
|
@@ -104,7 +106,10 @@ const orderedRoutes = [
|
|
|
104
106
|
[":page/app-root", `/:appNamespace`],
|
|
105
107
|
[":page/root", `/`]
|
|
106
108
|
];
|
|
107
|
-
const
|
|
109
|
+
const NON_SPA_PATH_PREFIXES = [appsUrlPrefix, publicAppsUrlPrefix];
|
|
110
|
+
const isNonSpaPath = (path) => NON_SPA_PATH_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
|
|
111
|
+
const withPublicPrefix = (route) => `${publicUrlPrefix}${route === "/" ? "" : route}`;
|
|
112
|
+
const ORDERED_PAGE_ROUTES = orderedRoutes.map(([page, route]) => [page, withPublicPrefix(route)]).concat(orderedRoutes);
|
|
108
113
|
const PAGE_ROUTES = fromPairs(ORDERED_PAGE_ROUTES);
|
|
109
114
|
const ORDERED_COMMON_AUX_ROUTES = [
|
|
110
115
|
[":aux/no-panel-support", `no-panel/:type`],
|
|
@@ -143,13 +148,10 @@ const ORDERED_COMMON_AUX_ROUTES = [
|
|
|
143
148
|
const ORDERED_AUX_ROUTES = [...ORDERED_COMMON_AUX_ROUTES, [":aux/view-config-raw", "config/raw"]];
|
|
144
149
|
const AUX_ROUTES = fromPairs(ORDERED_AUX_ROUTES);
|
|
145
150
|
const AUX_ROUTES_PATTERNS = ORDERED_AUX_ROUTES.map(([, pattern]) => pattern);
|
|
146
|
-
const ROUTES_WITH_PRESERVED_UNDERSCORES = [
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
":aux/upgrade-to-plan"
|
|
150
|
-
];
|
|
151
|
-
const ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS = ORDERED_AUX_ROUTES.filter(([route]) => ROUTES_WITH_PRESERVED_UNDERSCORES.includes(route)).map(([, pattern]) => pattern);
|
|
151
|
+
const ROUTES_WITH_PRESERVED_UNDERSCORES = [":aux/type-object-editor-for-composite-type", ":aux/object-editor-for-composite-type"];
|
|
152
|
+
const PAGE_ROUTES_WITH_PRESERVED_UNDERSCORES = [oauthApplicationSettingPage];
|
|
153
|
+
const ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS = ORDERED_AUX_ROUTES.filter(([route]) => ROUTES_WITH_PRESERVED_UNDERSCORES.includes(route)).map(([, pattern]) => pattern).concat(PAGE_ROUTES_WITH_PRESERVED_UNDERSCORES.flatMap((route) => [route, withPublicPrefix(route)]));
|
|
152
154
|
const ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP = Object.fromEntries(ROUTES_WITH_PRESERVED_UNDERSCORES.map((x) => [x, true]));
|
|
153
155
|
const ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP = Object.fromEntries(ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS.map((x) => [x, true]));
|
|
154
156
|
//#endregion
|
|
155
|
-
export { AUX_ROUTES, AUX_ROUTES_PATTERNS, ORDERED_AUX_ROUTES, ORDERED_COMMON_AUX_ROUTES, ORDERED_PAGE_ROUTES, PAGE_ROUTES, ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP, ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP, appIndexViewLocator, appModePage, appTypeModeAccessTemplatePage, appTypeModeAutomationBasePage, appTypeModeAutomationSpecificPage, appTypeModeFieldEditPage, appTypeModeFormPage, appTypeModeGroupEditPage, appTypeModePage, appTypeModePageView, appTypeModeSubPage, deprecatedSpecificObjectEditorViewLocator, formsPublicPage, highlightTypeFieldEditPage, highlightTypePage, integrationSettingPage, isSettingsPage, personalIntegrationSettingPage, specificObjectEditorViewLocator, specificObjectUnknownObjectLocator, specificObjectViewsCatalogViewLocator, typeAccessTemplateSettingPage, userAccessViewLocator };
|
|
157
|
+
export { AUX_ROUTES, AUX_ROUTES_PATTERNS, NON_SPA_PATH_PREFIXES, ORDERED_AUX_ROUTES, ORDERED_COMMON_AUX_ROUTES, ORDERED_PAGE_ROUTES, PAGE_ROUTES, ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP, ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP, appIndexViewLocator, appModePage, appTypeModeAccessTemplatePage, appTypeModeAutomationBasePage, appTypeModeAutomationSpecificPage, appTypeModeFieldEditPage, appTypeModeFormPage, appTypeModeGroupEditPage, appTypeModePage, appTypeModePageView, appTypeModeSubPage, deprecatedSpecificObjectEditorViewLocator, formsPublicPage, highlightTypeFieldEditPage, highlightTypePage, integrationSettingPage, isNonSpaPath, isSettingsPage, oauthApplicationSettingPage, personalIntegrationSettingPage, specificObjectEditorViewLocator, specificObjectUnknownObjectLocator, specificObjectViewsCatalogViewLocator, typeAccessTemplateSettingPage, userAccessViewLocator };
|
package/lib/url-constants.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ declare const publicUrlPrefix = "/@public";
|
|
|
5
5
|
declare const formsUrlPrefix = "/@public/forms";
|
|
6
6
|
declare const formKeyParamName = "form-key";
|
|
7
7
|
declare const appsUrlPrefix = "/apps";
|
|
8
|
+
declare const publicAppsUrlPrefix = "/@public/apps";
|
|
8
9
|
declare const containerTypeParamName = "container-type";
|
|
9
10
|
type DocumentContainerType = "entity" | "comment" | "view" | "canvas-comment";
|
|
10
11
|
//#endregion
|
|
11
|
-
export { DocumentContainerType, appsUrlPrefix, containerTypeParamName, formKeyParamName, formsUrlPrefix, publicParamName, publicUrlPrefix, sharingParamName };
|
|
12
|
+
export { DocumentContainerType, appsUrlPrefix, containerTypeParamName, formKeyParamName, formsUrlPrefix, publicAppsUrlPrefix, publicParamName, publicUrlPrefix, sharingParamName };
|
package/lib/url-constants.js
CHANGED
|
@@ -5,6 +5,7 @@ const publicUrlPrefix = "/@public";
|
|
|
5
5
|
const formsUrlPrefix = "/@public/forms";
|
|
6
6
|
const formKeyParamName = "form-key";
|
|
7
7
|
const appsUrlPrefix = "/apps";
|
|
8
|
+
const publicAppsUrlPrefix = `${publicUrlPrefix}${appsUrlPrefix}`;
|
|
8
9
|
const containerTypeParamName = "container-type";
|
|
9
10
|
//#endregion
|
|
10
|
-
export { appsUrlPrefix, containerTypeParamName, formKeyParamName, formsUrlPrefix, publicParamName, publicUrlPrefix, sharingParamName };
|
|
11
|
+
export { appsUrlPrefix, containerTypeParamName, formKeyParamName, formsUrlPrefix, publicAppsUrlPrefix, publicParamName, publicUrlPrefix, sharingParamName };
|