@fibery/url-utils 2.2.7 → 2.3.2

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.
@@ -1 +1,4 @@
1
- export declare const replaceDiactrics: (str?: string) => string;
1
+ //#region src/diactrics.d.ts
2
+ declare const replaceDiactrics: (str?: string) => string;
3
+ //#endregion
4
+ export { replaceDiactrics };
package/lib/diactrics.js CHANGED
@@ -1,115 +1,111 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceDiactrics = void 0;
1
+ //#region src/diactrics.ts
4
2
  const DIACTRICS_REPLACEMENT_MAP = {
5
- à: "a",
6
- á: "a",
7
- â: "a",
8
- ã: "a",
9
- ä: "a",
10
- å: "a",
11
- ā: "a",
12
- ą: "a",
13
- À: "A",
14
- Á: "A",
15
- Â: "A",
16
- Ã: "A",
17
- Ä: "A",
18
- Å: "A",
19
- Ā: "A",
20
- Ą: "A",
21
- ç: "c",
22
- ć: "c",
23
- č: "c",
24
- Ç: "C",
25
- Ć: "C",
26
- Č: "C",
27
- đ: "d",
28
- ď: "d",
29
- Đ: "D",
30
- Ď: "D",
31
- è: "e",
32
- é: "e",
33
- ê: "e",
34
- ë: "e",
35
- ě: "e",
36
- ē: "e",
37
- ę: "e",
38
- È: "E",
39
- É: "E",
40
- Ê: "E",
41
- Ë: "E",
42
- Ě: "E",
43
- Ē: "E",
44
- Ę: "E",
45
- ì: "i",
46
- í: "i",
47
- î: "i",
48
- ï: "i",
49
- ī: "i",
50
- Ì: "I",
51
- Í: "I",
52
- Î: "I",
53
- Ï: "I",
54
- Ī: "I",
55
- ł: "l",
56
- Ł: "L",
57
- ñ: "n",
58
- ň: "n",
59
- ń: "n",
60
- Ñ: "N",
61
- Ň: "N",
62
- Ń: "N",
63
- ò: "o",
64
- ó: "o",
65
- ô: "o",
66
- õ: "o",
67
- ö: "o",
68
- ø: "o",
69
- ō: "o",
70
- Ò: "O",
71
- Ó: "O",
72
- Ô: "O",
73
- Õ: "O",
74
- Ö: "O",
75
- Ø: "O",
76
- Ō: "O",
77
- ř: "r",
78
- Ř: "R",
79
- š: "s",
80
- ś: "s",
81
- Š: "S",
82
- Ś: "S",
83
- ť: "t",
84
- Ť: "T",
85
- ù: "u",
86
- ú: "u",
87
- û: "u",
88
- ü: "u",
89
- ů: "u",
90
- ū: "u",
91
- Ù: "U",
92
- Ú: "U",
93
- Û: "U",
94
- Ü: "U",
95
- Ů: "U",
96
- Ū: "U",
97
- ÿ: "y",
98
- ý: "y",
99
- Ÿ: "Y",
100
- Ý: "Y",
101
- ž: "z",
102
- ż: "z",
103
- ź: "z",
104
- Ž: "Z",
105
- Ż: "Z",
106
- Ź: "Z",
107
- ß: "ss",
3
+ à: "a",
4
+ á: "a",
5
+ â: "a",
6
+ ã: "a",
7
+ ä: "a",
8
+ å: "a",
9
+ ā: "a",
10
+ ą: "a",
11
+ À: "A",
12
+ Á: "A",
13
+ Â: "A",
14
+ Ã: "A",
15
+ Ä: "A",
16
+ Å: "A",
17
+ Ā: "A",
18
+ Ą: "A",
19
+ ç: "c",
20
+ ć: "c",
21
+ č: "c",
22
+ Ç: "C",
23
+ Ć: "C",
24
+ Č: "C",
25
+ đ: "d",
26
+ ď: "d",
27
+ Đ: "D",
28
+ Ď: "D",
29
+ è: "e",
30
+ é: "e",
31
+ ê: "e",
32
+ ë: "e",
33
+ ě: "e",
34
+ ē: "e",
35
+ ę: "e",
36
+ È: "E",
37
+ É: "E",
38
+ Ê: "E",
39
+ Ë: "E",
40
+ Ě: "E",
41
+ Ē: "E",
42
+ Ę: "E",
43
+ ì: "i",
44
+ í: "i",
45
+ î: "i",
46
+ ï: "i",
47
+ ī: "i",
48
+ Ì: "I",
49
+ Í: "I",
50
+ Î: "I",
51
+ Ï: "I",
52
+ Ī: "I",
53
+ ł: "l",
54
+ Ł: "L",
55
+ ñ: "n",
56
+ ň: "n",
57
+ ń: "n",
58
+ Ñ: "N",
59
+ Ň: "N",
60
+ Ń: "N",
61
+ ò: "o",
62
+ ó: "o",
63
+ ô: "o",
64
+ õ: "o",
65
+ ö: "o",
66
+ ø: "o",
67
+ ō: "o",
68
+ Ò: "O",
69
+ Ó: "O",
70
+ Ô: "O",
71
+ Õ: "O",
72
+ Ö: "O",
73
+ Ø: "O",
74
+ Ō: "O",
75
+ ř: "r",
76
+ Ř: "R",
77
+ š: "s",
78
+ ś: "s",
79
+ Š: "S",
80
+ Ś: "S",
81
+ ť: "t",
82
+ Ť: "T",
83
+ ù: "u",
84
+ ú: "u",
85
+ û: "u",
86
+ ü: "u",
87
+ ů: "u",
88
+ ū: "u",
89
+ Ù: "U",
90
+ Ú: "U",
91
+ Û: "U",
92
+ Ü: "U",
93
+ Ů: "U",
94
+ Ū: "U",
95
+ ÿ: "y",
96
+ ý: "y",
97
+ Ÿ: "Y",
98
+ Ý: "Y",
99
+ ž: "z",
100
+ ż: "z",
101
+ ź: "z",
102
+ Ž: "Z",
103
+ Ż: "Z",
104
+ Ź: "Z",
105
+ ß: "ss"
108
106
  };
109
107
  const replaceDiactrics = (str = "") => {
110
- return str
111
- .split("")
112
- .map((char) => DIACTRICS_REPLACEMENT_MAP[char] || char)
113
- .join("");
108
+ return str.split("").map((char) => DIACTRICS_REPLACEMENT_MAP[char] || char).join("");
114
109
  };
115
- exports.replaceDiactrics = replaceDiactrics;
110
+ //#endregion
111
+ export { replaceDiactrics };
package/lib/index.d.ts CHANGED
@@ -1,36 +1,38 @@
1
- export declare const appendQueryFlag: (url: string, key: string) => string;
2
- export declare const appendQueryParameter: (url: string, key: string, value: string | null) => string;
3
- export declare const getFlagValue: (flag: string) => string | null;
4
- export declare const getSharingKey: () => string | null;
5
- export declare const appendSharingKey: (url?: string | null, sharingKey?: undefined | string | null) => string;
6
- export declare const appendIsPublicParam: (url: string) => string;
7
- export declare const signedFileUrl: (url?: string | null) => string | null | undefined;
8
- export declare const getRefURL: (location?: {
9
- href: string;
10
- origin: string;
1
+ //#region src/index.d.ts
2
+ declare const appendQueryFlag: (url: string, key: string) => string;
3
+ declare const appendQueryParameter: (url: string, key: string, value: string | null) => string;
4
+ declare const getFlagValue: (flag: string) => string | null;
5
+ declare const getSharingKey: () => string | null;
6
+ declare const appendSharingKey: (url?: string | null, sharingKey?: undefined | string | null) => string;
7
+ declare const appendIsPublicParam: (url: string) => string;
8
+ declare const signedFileUrl: (url?: string | null) => string | null | undefined;
9
+ declare const getRefURL: (location?: {
10
+ href: string;
11
+ origin: string;
11
12
  }) => string;
12
- export declare const isSharingMode: boolean;
13
- export declare const isPublicSpaceMode: boolean;
14
- export declare const isPublicForm: boolean;
15
- export declare const isPublicAccessMode: boolean;
16
- export declare const isRelativeUrl: (url: string) => boolean;
17
- export declare const isPublicUrlInPrivateMode: (absoluteUrl: string, location?: Location) => boolean;
18
- export declare const getRelativeUrlFromAbsolute: (absoluteUrl: string, location?: Location) => string;
13
+ declare const isSharingMode: boolean;
14
+ declare const isPublicSpaceMode: boolean;
15
+ declare const isPublicForm: boolean;
16
+ declare const isPublicAccessMode: boolean;
17
+ declare const isRelativeUrl: (url: string) => boolean;
18
+ declare const isPublicUrlInPrivateMode: (absoluteUrl: string, location?: Location) => boolean;
19
+ declare const getRelativeUrlFromAbsolute: (absoluteUrl: string, location?: Location) => string;
19
20
  type Context = {
20
- contextEntityTypeName: string;
21
- contextEntityPublicId: string;
21
+ contextEntityTypeName: string;
22
+ contextEntityPublicId: string;
22
23
  };
23
- export declare const createPureFiberyEntityUrlMatcher: ({ ownHost }: {
24
- ownHost: string;
24
+ declare const createPureFiberyEntityUrlMatcher: ({ ownHost }: {
25
+ ownHost: string;
25
26
  }) => (originalUrl: string, matchUserAsWell?: boolean) => null | {
26
- publicId: string;
27
- typeName: string;
28
- scrollLocator?: string | null;
29
- scrollLocatorParams?: {
30
- field?: string;
31
- comment?: string;
32
- anchor?: string;
33
- };
34
- context?: Context;
27
+ publicId: string;
28
+ typeName: string;
29
+ scrollLocator?: string | null;
30
+ scrollLocatorParams?: {
31
+ field?: string;
32
+ comment?: string;
33
+ anchor?: string;
34
+ };
35
+ context?: Context;
35
36
  };
36
- export {};
37
+ //#endregion
38
+ export { appendIsPublicParam, appendQueryFlag, appendQueryParameter, appendSharingKey, createPureFiberyEntityUrlMatcher, getFlagValue, getRefURL, getRelativeUrlFromAbsolute, getSharingKey, isPublicAccessMode, isPublicForm, isPublicSpaceMode, isPublicUrlInPrivateMode, isRelativeUrl, isSharingMode, signedFileUrl };
package/lib/index.js CHANGED
@@ -1,142 +1,101 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPureFiberyEntityUrlMatcher = exports.getRelativeUrlFromAbsolute = exports.isPublicUrlInPrivateMode = exports.isRelativeUrl = exports.isPublicAccessMode = exports.isPublicForm = exports.isPublicSpaceMode = exports.isSharingMode = exports.getRefURL = exports.signedFileUrl = exports.appendIsPublicParam = exports.appendSharingKey = exports.getSharingKey = exports.getFlagValue = exports.appendQueryParameter = exports.appendQueryFlag = void 0;
4
- const url_constants_1 = require("./url-constants");
5
- const parse_page_location_1 = require("./parse-page-location");
6
- const locator_utils_1 = require("./locator-utils");
1
+ import { parseLocator, parseScrollLocator } from "./locator-utils.js";
2
+ import { publicParamName, publicUrlPrefix, sharingParamName } from "./url-constants.js";
3
+ import { getAuxMatch, getPageMatch, safeDecodeURIComponent } from "./parse-page-location.js";
4
+ //#region src/index.ts
7
5
  const appendQueryFlag = (url, key) => {
8
- const [location, ...hash] = url.split("#");
9
- const prefix = location.indexOf("?") >= 0 ? "&" : "?";
10
- return [`${location}${prefix}${key}`, ...hash].join("#");
6
+ const [location, ...hash] = url.split("#");
7
+ return [`${location}${location.includes("?") ? "&" : "?"}${key}`, ...hash].join("#");
11
8
  };
12
- exports.appendQueryFlag = appendQueryFlag;
13
9
  const appendQueryParameter = (url, key, value) => {
14
- if (!value) {
15
- return url;
16
- }
17
- const [location, ...hash] = url.split("#");
18
- const prefix = location.indexOf("?") >= 0 ? "&" : "?";
19
- return [`${location}${prefix}${key}=${value}`, ...hash].join("#");
10
+ if (!value) return url;
11
+ const [location, ...hash] = url.split("#");
12
+ return [`${location}${location.includes("?") ? "&" : "?"}${key}=${value}`, ...hash].join("#");
20
13
  };
21
- exports.appendQueryParameter = appendQueryParameter;
22
14
  const getFlagValue = (flag) => new URLSearchParams(window.location.search).get(flag);
23
- exports.getFlagValue = getFlagValue;
24
15
  const getSharingKey = () => {
25
- return (0, exports.getFlagValue)(url_constants_1.sharingParamName) || (0, exports.getFlagValue)("sk");
16
+ return getFlagValue("sharing-key") || getFlagValue("sk");
26
17
  };
27
- exports.getSharingKey = getSharingKey;
28
- const appendSharingKey = (url, sharingKey = (0, exports.getSharingKey)()) => {
29
- if (!url) {
30
- return url || "";
31
- }
32
- return (0, exports.appendQueryParameter)(url, url_constants_1.sharingParamName, sharingKey);
18
+ const appendSharingKey = (url, sharingKey = getSharingKey()) => {
19
+ if (!url) return url || "";
20
+ return appendQueryParameter(url, sharingParamName, sharingKey);
33
21
  };
34
- exports.appendSharingKey = appendSharingKey;
35
22
  const appendIsPublicParam = (url) => {
36
- if (exports.isPublicSpaceMode) {
37
- //TODO: rework "appendQueryParameter" to URL class.
38
- return (0, exports.appendQueryParameter)(url, url_constants_1.publicParamName, "1");
39
- }
40
- else {
41
- return url;
42
- }
23
+ if (isPublicSpaceMode) return appendQueryParameter(url, publicParamName, "1");
24
+ else return url;
43
25
  };
44
- exports.appendIsPublicParam = appendIsPublicParam;
45
26
  const signedFileUrl = (url) => {
46
- return url?.startsWith("/api/files/") && !url?.startsWith("/api/files/r/")
47
- ? url.replace("/api/files", "/api/files/r")
48
- : url;
27
+ return url?.startsWith("/api/files/") && !url?.startsWith("/api/files/r/") ? url.replace("/api/files", "/api/files/r") : url;
49
28
  };
50
- exports.signedFileUrl = signedFileUrl;
51
29
  const getRefURL = (location = window.location) => location.href.replace(location.origin, "");
52
- exports.getRefURL = getRefURL;
53
- exports.isSharingMode = Boolean((0, exports.getSharingKey)());
54
- const decodedLocationPathName = (0, parse_page_location_1.safeDecodeURIComponent)(window.location.pathname || "");
55
- exports.isPublicSpaceMode = decodedLocationPathName.startsWith(url_constants_1.publicUrlPrefix) && !decodedLocationPathName.startsWith(url_constants_1.formsUrlPrefix);
56
- exports.isPublicForm = decodedLocationPathName.startsWith(url_constants_1.publicUrlPrefix) && decodedLocationPathName.startsWith(url_constants_1.formsUrlPrefix);
57
- exports.isPublicAccessMode = exports.isSharingMode || exports.isPublicSpaceMode;
58
- const validPageMatchSet = new Set([":page/app-view", ":page/specific-object-view"]);
30
+ const isSharingMode = Boolean(getSharingKey());
31
+ const decodedLocationPathName = safeDecodeURIComponent(window.location.pathname || "");
32
+ const isPublicSpaceMode = decodedLocationPathName.startsWith("/@public") && !decodedLocationPathName.startsWith("/@public/forms");
33
+ const isPublicForm = decodedLocationPathName.startsWith("/@public") && decodedLocationPathName.startsWith("/@public/forms");
34
+ const isPublicAccessMode = isSharingMode || isPublicSpaceMode;
35
+ const validPageMatchSet = /* @__PURE__ */ new Set([":page/app-view", ":page/specific-object-view"]);
59
36
  const isRelativeUrl = (url) => {
60
- return url.startsWith("/");
37
+ return url.startsWith("/");
61
38
  };
62
- exports.isRelativeUrl = isRelativeUrl;
63
39
  const isPublicUrlInPrivateMode = (absoluteUrl, location = window.location) => {
64
- const isPublic = location.pathname.startsWith(url_constants_1.publicUrlPrefix);
65
- let urlObject = null;
66
- try {
67
- urlObject = new URL(absoluteUrl);
68
- }
69
- catch (ex) {
70
- // not a valid URL
71
- return false;
72
- }
73
- return !isPublic && urlObject.pathname.startsWith(url_constants_1.publicUrlPrefix);
40
+ const isPublic = location.pathname.startsWith(publicUrlPrefix);
41
+ let urlObject = null;
42
+ try {
43
+ urlObject = new URL(absoluteUrl);
44
+ } catch {
45
+ return false;
46
+ }
47
+ return !isPublic && urlObject.pathname.startsWith("/@public");
74
48
  };
75
- exports.isPublicUrlInPrivateMode = isPublicUrlInPrivateMode;
76
49
  const getRelativeUrlFromAbsolute = (absoluteUrl, location = window.location) => {
77
- return absoluteUrl.replace(location.origin, "");
50
+ return absoluteUrl.replace(location.origin, "");
78
51
  };
79
- exports.getRelativeUrlFromAbsolute = getRelativeUrlFromAbsolute;
80
- const knownScrollLocatorParams = new Set(["field", "comment", "anchor"]);
52
+ const knownScrollLocatorParams = /* @__PURE__ */ new Set([
53
+ "field",
54
+ "comment",
55
+ "anchor"
56
+ ]);
81
57
  const createPureFiberyEntityUrlMatcher = ({ ownHost }) => (originalUrl, matchUserAsWell = false) => {
82
- let urlObject = null;
83
- try {
84
- urlObject = new URL(originalUrl);
85
- }
86
- catch (ex) {
87
- // not a valid URL
88
- return null;
89
- }
90
- if (urlObject.host !== ownHost) {
91
- return null;
92
- }
93
- const auxMatch = (0, parse_page_location_1.getAuxMatch)(urlObject.hash, "");
94
- if (auxMatch !== null) {
95
- return null;
96
- }
97
- const pageMatch = (0, parse_page_location_1.getPageMatch)(urlObject.pathname);
98
- if (pageMatch === null) {
99
- return null;
100
- }
101
- const { page, params } = pageMatch;
102
- if (!validPageMatchSet.has(page)) {
103
- return null;
104
- }
105
- let typeName = [params.appNamespace, params.typeWithoutNamespace].join("/");
106
- if (typeName === "fibery/user" && !matchUserAsWell) {
107
- return null;
108
- }
109
- let publicId = null;
110
- let context = undefined;
111
- if (page === ":page/specific-object-view" && !params.viewLocator) {
112
- const objectOrViewLocator = String(params.objectLocator);
113
- publicId = (0, locator_utils_1.parseLocator)(objectOrViewLocator).publicId;
114
- }
115
- else if (params.viewLocator) {
116
- const objectOrViewLocator = String(params.viewLocator);
117
- publicId = (0, locator_utils_1.parseLocator)(objectOrViewLocator).publicId;
118
- typeName = "fibery/view";
119
- const objectLocator = String(params.objectLocator);
120
- const contextEntityPublicId = (0, locator_utils_1.parseLocator)(objectLocator).publicId;
121
- if (contextEntityPublicId && params.appNamespace && params.typeWithoutNamespace) {
122
- context = {
123
- contextEntityTypeName: `${params.appNamespace}/${params.typeWithoutNamespace}`,
124
- contextEntityPublicId: contextEntityPublicId,
125
- };
126
- }
127
- }
128
- if (publicId === null) {
129
- return null;
130
- }
131
- const scrollLocatorParams = Object.fromEntries(Object.entries((0, locator_utils_1.parseScrollLocator)(pageMatch.params.scrollLocator)).filter(([key, value]) => {
132
- return knownScrollLocatorParams.has(key) && value;
133
- }));
134
- return {
135
- publicId,
136
- typeName,
137
- scrollLocator: pageMatch.params.scrollLocator,
138
- scrollLocatorParams: Object.keys(scrollLocatorParams).length ? scrollLocatorParams : undefined,
139
- context,
140
- };
58
+ let urlObject = null;
59
+ try {
60
+ urlObject = new URL(originalUrl);
61
+ } catch {
62
+ return null;
63
+ }
64
+ if (urlObject.host !== ownHost) return null;
65
+ if (getAuxMatch(urlObject.hash, "") !== null) return null;
66
+ const pageMatch = getPageMatch(urlObject.pathname);
67
+ if (pageMatch === null) return null;
68
+ const { page, params } = pageMatch;
69
+ if (!validPageMatchSet.has(page)) return null;
70
+ let typeName = [params.appNamespace, params.typeWithoutNamespace].join("/");
71
+ if (typeName === "fibery/user" && !matchUserAsWell) return null;
72
+ let publicId = null;
73
+ let context = void 0;
74
+ if (page === ":page/specific-object-view" && !params.viewLocator) {
75
+ const objectOrViewLocator = String(params.objectLocator);
76
+ publicId = parseLocator(objectOrViewLocator).publicId;
77
+ } else if (params.viewLocator) {
78
+ const objectOrViewLocator = String(params.viewLocator);
79
+ publicId = parseLocator(objectOrViewLocator).publicId;
80
+ typeName = "fibery/view";
81
+ const objectLocator = String(params.objectLocator);
82
+ const contextEntityPublicId = parseLocator(objectLocator).publicId;
83
+ if (contextEntityPublicId && params.appNamespace && params.typeWithoutNamespace) context = {
84
+ contextEntityTypeName: `${params.appNamespace}/${params.typeWithoutNamespace}`,
85
+ contextEntityPublicId
86
+ };
87
+ }
88
+ if (publicId === null) return null;
89
+ const scrollLocatorParams = Object.fromEntries(Object.entries(parseScrollLocator(pageMatch.params.scrollLocator)).filter(([key, value]) => {
90
+ return knownScrollLocatorParams.has(key) && value;
91
+ }));
92
+ return {
93
+ publicId,
94
+ typeName,
95
+ scrollLocator: pageMatch.params.scrollLocator,
96
+ scrollLocatorParams: Object.keys(scrollLocatorParams).length ? scrollLocatorParams : void 0,
97
+ context
98
+ };
141
99
  };
142
- exports.createPureFiberyEntityUrlMatcher = createPureFiberyEntityUrlMatcher;
100
+ //#endregion
101
+ export { appendIsPublicParam, appendQueryFlag, appendQueryParameter, appendSharingKey, createPureFiberyEntityUrlMatcher, getFlagValue, getRefURL, getRelativeUrlFromAbsolute, getSharingKey, isPublicAccessMode, isPublicForm, isPublicSpaceMode, isPublicUrlInPrivateMode, isRelativeUrl, isSharingMode, signedFileUrl };
@@ -1,18 +1,21 @@
1
- export declare const escapeRegExpChar: (x: string) => string;
2
- export declare const parseLocator: (locator: string) => {
3
- publicId: string | null;
4
- title: null;
1
+ //#region src/locator-utils.d.ts
2
+ declare const escapeRegExpChar: (x: string) => string;
3
+ declare const parseLocator: (locator: string) => {
4
+ publicId: string | null;
5
+ title: null;
5
6
  } | {
6
- publicId: string;
7
- title: string;
7
+ publicId: string;
8
+ title: string;
8
9
  };
9
- export declare const parseScrollLocator: (locator?: string | null) => Record<string, string | null>;
10
- export declare const makeLocator: ({ publicId, title }: {
11
- publicId: string | number | null;
12
- title?: string | null;
10
+ declare const parseScrollLocator: (locator?: string | null) => Record<string, string | null>;
11
+ declare const makeLocator: ({ publicId, title }: {
12
+ publicId: string | number | null;
13
+ title?: string | null;
13
14
  }) => string;
14
- export declare const createAnchorScrollLocatorValue: (params: {
15
- id: string;
16
- text?: string;
15
+ declare const createAnchorScrollLocatorValue: (params: {
16
+ id: string;
17
+ text?: string;
17
18
  }) => string;
18
- export declare const parseScrollLocatorValue: (key: string, originalValue: string) => string;
19
+ declare const parseScrollLocatorValue: (key: string, originalValue: string) => string;
20
+ //#endregion
21
+ export { createAnchorScrollLocatorValue, escapeRegExpChar, makeLocator, parseLocator, parseScrollLocator, parseScrollLocatorValue };