@fibery/url-utils 2.2.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/LICENSE +214 -0
- package/index.ts +168 -0
- package/lib/babel.config.d.ts +1 -0
- package/lib/babel.config.js +4 -0
- package/lib/diactrics.d.ts +1 -0
- package/lib/diactrics.js +115 -0
- package/lib/index.d.ts +36 -0
- package/lib/index.js +142 -0
- package/lib/jest.config.d.ts +7 -0
- package/lib/jest.config.js +10 -0
- package/lib/locator-utils.d.ts +18 -0
- package/lib/locator-utils.js +71 -0
- package/lib/make-path.d.ts +1 -0
- package/lib/make-path.js +42 -0
- package/lib/parse-page-location.d.ts +16 -0
- package/lib/parse-page-location.js +78 -0
- package/lib/routes.d.ts +34 -0
- package/lib/routes.js +182 -0
- package/lib/url-constants.d.ts +5 -0
- package/lib/url-constants.js +8 -0
- package/lib/workspaces.d.ts +12 -0
- package/lib/workspaces.js +31 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
|
|
2
|
+
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
|
|
3
|
+
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
|
4
|
+
|
|
5
|
+
1. DEFINITIONS
|
|
6
|
+
|
|
7
|
+
"Contribution" means:
|
|
8
|
+
|
|
9
|
+
a) in the case of the initial Contributor, the initial code and
|
|
10
|
+
documentation distributed under this Agreement, and
|
|
11
|
+
|
|
12
|
+
b) in the case of each subsequent Contributor:
|
|
13
|
+
|
|
14
|
+
i) changes to the Program, and
|
|
15
|
+
|
|
16
|
+
ii) additions to the Program;
|
|
17
|
+
|
|
18
|
+
where such changes and/or additions to the Program originate from and are
|
|
19
|
+
distributed by that particular Contributor. A Contribution 'originates' from
|
|
20
|
+
a Contributor if it was added to the Program by such Contributor itself or
|
|
21
|
+
anyone acting on such Contributor's behalf. Contributions do not include
|
|
22
|
+
additions to the Program which: (i) are separate modules of software
|
|
23
|
+
distributed in conjunction with the Program under their own license
|
|
24
|
+
agreement, and (ii) are not derivative works of the Program.
|
|
25
|
+
|
|
26
|
+
"Contributor" means any person or entity that distributes the Program.
|
|
27
|
+
|
|
28
|
+
"Licensed Patents" mean patent claims licensable by a Contributor which are
|
|
29
|
+
necessarily infringed by the use or sale of its Contribution alone or when
|
|
30
|
+
combined with the Program.
|
|
31
|
+
|
|
32
|
+
"Program" means the Contributions distributed in accordance with this
|
|
33
|
+
Agreement.
|
|
34
|
+
|
|
35
|
+
"Recipient" means anyone who receives the Program under this Agreement,
|
|
36
|
+
including all Contributors.
|
|
37
|
+
|
|
38
|
+
2. GRANT OF RIGHTS
|
|
39
|
+
|
|
40
|
+
a) Subject to the terms of this Agreement, each Contributor hereby grants
|
|
41
|
+
Recipient a non-exclusive, worldwide, royalty-free copyright license to
|
|
42
|
+
reproduce, prepare derivative works of, publicly display, publicly perform,
|
|
43
|
+
distribute and sublicense the Contribution of such Contributor, if any, and
|
|
44
|
+
such derivative works, in source code and object code form.
|
|
45
|
+
|
|
46
|
+
b) Subject to the terms of this Agreement, each Contributor hereby grants
|
|
47
|
+
Recipient a non-exclusive, worldwide, royalty-free patent license under
|
|
48
|
+
Licensed Patents to make, use, sell, offer to sell, import and otherwise
|
|
49
|
+
transfer the Contribution of such Contributor, if any, in source code and
|
|
50
|
+
object code form. This patent license shall apply to the combination of the
|
|
51
|
+
Contribution and the Program if, at the time the Contribution is added by the
|
|
52
|
+
Contributor, such addition of the Contribution causes such combination to be
|
|
53
|
+
covered by the Licensed Patents. The patent license shall not apply to any
|
|
54
|
+
other combinations which include the Contribution. No hardware per se is
|
|
55
|
+
licensed hereunder.
|
|
56
|
+
|
|
57
|
+
c) Recipient understands that although each Contributor grants the licenses
|
|
58
|
+
to its Contributions set forth herein, no assurances are provided by any
|
|
59
|
+
Contributor that the Program does not infringe the patent or other
|
|
60
|
+
intellectual property rights of any other entity. Each Contributor disclaims
|
|
61
|
+
any liability to Recipient for claims brought by any other entity based on
|
|
62
|
+
infringement of intellectual property rights or otherwise. As a condition to
|
|
63
|
+
exercising the rights and licenses granted hereunder, each Recipient hereby
|
|
64
|
+
assumes sole responsibility to secure any other intellectual property rights
|
|
65
|
+
needed, if any. For example, if a third party patent license is required to
|
|
66
|
+
allow Recipient to distribute the Program, it is Recipient's responsibility
|
|
67
|
+
to acquire that license before distributing the Program.
|
|
68
|
+
|
|
69
|
+
d) Each Contributor represents that to its knowledge it has sufficient
|
|
70
|
+
copyright rights in its Contribution, if any, to grant the copyright license
|
|
71
|
+
set forth in this Agreement.
|
|
72
|
+
|
|
73
|
+
3. REQUIREMENTS
|
|
74
|
+
|
|
75
|
+
A Contributor may choose to distribute the Program in object code form under
|
|
76
|
+
its own license agreement, provided that:
|
|
77
|
+
|
|
78
|
+
a) it complies with the terms and conditions of this Agreement; and
|
|
79
|
+
|
|
80
|
+
b) its license agreement:
|
|
81
|
+
|
|
82
|
+
i) effectively disclaims on behalf of all Contributors all warranties and
|
|
83
|
+
conditions, express and implied, including warranties or conditions of title
|
|
84
|
+
and non-infringement, and implied warranties or conditions of merchantability
|
|
85
|
+
and fitness for a particular purpose;
|
|
86
|
+
|
|
87
|
+
ii) effectively excludes on behalf of all Contributors all liability for
|
|
88
|
+
damages, including direct, indirect, special, incidental and consequential
|
|
89
|
+
damages, such as lost profits;
|
|
90
|
+
|
|
91
|
+
iii) states that any provisions which differ from this Agreement are offered
|
|
92
|
+
by that Contributor alone and not by any other party; and
|
|
93
|
+
|
|
94
|
+
iv) states that source code for the Program is available from such
|
|
95
|
+
Contributor, and informs licensees how to obtain it in a reasonable manner on
|
|
96
|
+
or through a medium customarily used for software exchange.
|
|
97
|
+
|
|
98
|
+
When the Program is made available in source code form:
|
|
99
|
+
|
|
100
|
+
a) it must be made available under this Agreement; and
|
|
101
|
+
|
|
102
|
+
b) a copy of this Agreement must be included with each copy of the Program.
|
|
103
|
+
|
|
104
|
+
Contributors may not remove or alter any copyright notices contained within
|
|
105
|
+
the Program.
|
|
106
|
+
|
|
107
|
+
Each Contributor must identify itself as the originator of its Contribution,
|
|
108
|
+
if any, in a manner that reasonably allows subsequent Recipients to identify
|
|
109
|
+
the originator of the Contribution.
|
|
110
|
+
|
|
111
|
+
4. COMMERCIAL DISTRIBUTION
|
|
112
|
+
|
|
113
|
+
Commercial distributors of software may accept certain responsibilities with
|
|
114
|
+
respect to end users, business partners and the like. While this license is
|
|
115
|
+
intended to facilitate the commercial use of the Program, the Contributor who
|
|
116
|
+
includes the Program in a commercial product offering should do so in a
|
|
117
|
+
manner which does not create potential liability for other Contributors.
|
|
118
|
+
Therefore, if a Contributor includes the Program in a commercial product
|
|
119
|
+
offering, such Contributor ("Commercial Contributor") hereby agrees to defend
|
|
120
|
+
and indemnify every other Contributor ("Indemnified Contributor") against any
|
|
121
|
+
losses, damages and costs (collectively "Losses") arising from claims,
|
|
122
|
+
lawsuits and other legal actions brought by a third party against the
|
|
123
|
+
Indemnified Contributor to the extent caused by the acts or omissions of such
|
|
124
|
+
Commercial Contributor in connection with its distribution of the Program in
|
|
125
|
+
a commercial product offering. The obligations in this section do not apply
|
|
126
|
+
to any claims or Losses relating to any actual or alleged intellectual
|
|
127
|
+
property infringement. In order to qualify, an Indemnified Contributor must:
|
|
128
|
+
a) promptly notify the Commercial Contributor in writing of such claim, and
|
|
129
|
+
b) allow the Commercial Contributor to control, and cooperate with the
|
|
130
|
+
Commercial Contributor in, the defense and any related settlement
|
|
131
|
+
negotiations. The Indemnified Contributor may participate in any such claim
|
|
132
|
+
at its own expense.
|
|
133
|
+
|
|
134
|
+
For example, a Contributor might include the Program in a commercial product
|
|
135
|
+
offering, Product X. That Contributor is then a Commercial Contributor. If
|
|
136
|
+
that Commercial Contributor then makes performance claims, or offers
|
|
137
|
+
warranties related to Product X, those performance claims and warranties are
|
|
138
|
+
such Commercial Contributor's responsibility alone. Under this section, the
|
|
139
|
+
Commercial Contributor would have to defend claims against the other
|
|
140
|
+
Contributors related to those performance claims and warranties, and if a
|
|
141
|
+
court requires any other Contributor to pay any damages as a result, the
|
|
142
|
+
Commercial Contributor must pay those damages.
|
|
143
|
+
|
|
144
|
+
5. NO WARRANTY
|
|
145
|
+
|
|
146
|
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
|
|
147
|
+
AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
|
|
148
|
+
EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
|
|
149
|
+
CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
|
|
151
|
+
appropriateness of using and distributing the Program and assumes all risks
|
|
152
|
+
associated with its exercise of rights under this Agreement , including but
|
|
153
|
+
not limited to the risks and costs of program errors, compliance with
|
|
154
|
+
applicable laws, damage to or loss of data, programs or equipment, and
|
|
155
|
+
unavailability or interruption of operations.
|
|
156
|
+
|
|
157
|
+
6. DISCLAIMER OF LIABILITY
|
|
158
|
+
|
|
159
|
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
|
|
160
|
+
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
161
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
|
|
162
|
+
LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
163
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
164
|
+
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
|
165
|
+
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
|
|
166
|
+
OF SUCH DAMAGES.
|
|
167
|
+
|
|
168
|
+
7. GENERAL
|
|
169
|
+
|
|
170
|
+
If any provision of this Agreement is invalid or unenforceable under
|
|
171
|
+
applicable law, it shall not affect the validity or enforceability of the
|
|
172
|
+
remainder of the terms of this Agreement, and without further action by the
|
|
173
|
+
parties hereto, such provision shall be reformed to the minimum extent
|
|
174
|
+
necessary to make such provision valid and enforceable.
|
|
175
|
+
|
|
176
|
+
If Recipient institutes patent litigation against any entity (including a
|
|
177
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
|
|
178
|
+
(excluding combinations of the Program with other software or hardware)
|
|
179
|
+
infringes such Recipient's patent(s), then such Recipient's rights granted
|
|
180
|
+
under Section 2(b) shall terminate as of the date such litigation is filed.
|
|
181
|
+
|
|
182
|
+
All Recipient's rights under this Agreement shall terminate if it fails to
|
|
183
|
+
comply with any of the material terms or conditions of this Agreement and
|
|
184
|
+
does not cure such failure in a reasonable period of time after becoming
|
|
185
|
+
aware of such noncompliance. If all Recipient's rights under this Agreement
|
|
186
|
+
terminate, Recipient agrees to cease use and distribution of the Program as
|
|
187
|
+
soon as reasonably practicable. However, Recipient's obligations under this
|
|
188
|
+
Agreement and any licenses granted by Recipient relating to the Program shall
|
|
189
|
+
continue and survive.
|
|
190
|
+
|
|
191
|
+
Everyone is permitted to copy and distribute copies of this Agreement, but in
|
|
192
|
+
order to avoid inconsistency the Agreement is copyrighted and may only be
|
|
193
|
+
modified in the following manner. The Agreement Steward reserves the right to
|
|
194
|
+
publish new versions (including revisions) of this Agreement from time to
|
|
195
|
+
time. No one other than the Agreement Steward has the right to modify this
|
|
196
|
+
Agreement. The Eclipse Foundation is the initial Agreement Steward. The
|
|
197
|
+
Eclipse Foundation may assign the responsibility to serve as the Agreement
|
|
198
|
+
Steward to a suitable separate entity. Each new version of the Agreement will
|
|
199
|
+
be given a distinguishing version number. The Program (including
|
|
200
|
+
Contributions) may always be distributed subject to the version of the
|
|
201
|
+
Agreement under which it was received. In addition, after a new version of
|
|
202
|
+
the Agreement is published, Contributor may elect to distribute the Program
|
|
203
|
+
(including its Contributions) under the new version. Except as expressly
|
|
204
|
+
stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
|
|
205
|
+
licenses to the intellectual property of any Contributor under this
|
|
206
|
+
Agreement, whether expressly, by implication, estoppel or otherwise. All
|
|
207
|
+
rights in the Program not expressly granted under this Agreement are
|
|
208
|
+
reserved.
|
|
209
|
+
|
|
210
|
+
This Agreement is governed by the laws of the State of New York and the
|
|
211
|
+
intellectual property laws of the United States of America. No party to this
|
|
212
|
+
Agreement will bring a legal action under this Agreement more than one year
|
|
213
|
+
after the cause of action arose. Each party waives its rights to a jury trial
|
|
214
|
+
in any resulting litigation.
|
package/index.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {formsUrlPrefix, publicParamName, publicUrlPrefix, sharingParamName} from "./url-constants";
|
|
2
|
+
import {getAuxMatch, getPageMatch, safeDecodeURIComponent} from "./parse-page-location";
|
|
3
|
+
import {parseLocator, parseScrollLocator} from "./locator-utils";
|
|
4
|
+
|
|
5
|
+
export const appendQueryFlag = (url: string, key: string) => {
|
|
6
|
+
const [location, ...hash] = url.split("#");
|
|
7
|
+
const prefix = location.indexOf("?") >= 0 ? "&" : "?";
|
|
8
|
+
return [`${location}${prefix}${key}`, ...hash].join("#");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const appendQueryParameter = (url: string, key: string, value: string | null) => {
|
|
12
|
+
if (!value) {
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
const [location, ...hash] = url.split("#");
|
|
16
|
+
const prefix = location.indexOf("?") >= 0 ? "&" : "?";
|
|
17
|
+
return [`${location}${prefix}${key}=${value}`, ...hash].join("#");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const getFlagValue = (flag: string) => new URLSearchParams(window.location.search).get(flag);
|
|
21
|
+
|
|
22
|
+
export const getSharingKey = () => {
|
|
23
|
+
return getFlagValue(sharingParamName) || getFlagValue("sk");
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const appendSharingKey = (
|
|
27
|
+
url?: string | null,
|
|
28
|
+
sharingKey: undefined | string | null = getSharingKey()
|
|
29
|
+
): string => {
|
|
30
|
+
if (!url) {
|
|
31
|
+
return url || "";
|
|
32
|
+
}
|
|
33
|
+
return appendQueryParameter(url, sharingParamName, sharingKey);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const appendIsPublicParam = (url: string): string => {
|
|
37
|
+
if (isPublicSpaceMode) {
|
|
38
|
+
//TODO: rework "appendQueryParameter" to URL class.
|
|
39
|
+
return appendQueryParameter(url, publicParamName, "1");
|
|
40
|
+
} else {
|
|
41
|
+
return url;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const signedFileUrl = (url?: string | null) => {
|
|
46
|
+
return url?.startsWith("/api/files/") && !url?.startsWith("/api/files/r/")
|
|
47
|
+
? url.replace("/api/files", "/api/files/r")
|
|
48
|
+
: url;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const getRefURL = (location: {href: string; origin: string} = window.location) =>
|
|
52
|
+
location.href.replace(location.origin, "");
|
|
53
|
+
|
|
54
|
+
export const isSharingMode = Boolean(getSharingKey());
|
|
55
|
+
|
|
56
|
+
const decodedLocationPathName = safeDecodeURIComponent(window.location.pathname || "");
|
|
57
|
+
export const isPublicSpaceMode =
|
|
58
|
+
decodedLocationPathName.startsWith(publicUrlPrefix) && !decodedLocationPathName.startsWith(formsUrlPrefix);
|
|
59
|
+
|
|
60
|
+
export const isPublicForm =
|
|
61
|
+
decodedLocationPathName.startsWith(publicUrlPrefix) && decodedLocationPathName.startsWith(formsUrlPrefix);
|
|
62
|
+
|
|
63
|
+
export const isPublicAccessMode = isSharingMode || isPublicSpaceMode;
|
|
64
|
+
|
|
65
|
+
const validPageMatchSet = new Set([":page/app-view", ":page/specific-object-view"]);
|
|
66
|
+
|
|
67
|
+
export const isRelativeUrl = (url: string) => {
|
|
68
|
+
return url.startsWith("/");
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const isPublicUrlInPrivateMode = (absoluteUrl: string, location = window.location) => {
|
|
72
|
+
const isPublic = location.pathname.startsWith(publicUrlPrefix);
|
|
73
|
+
let urlObject = null;
|
|
74
|
+
try {
|
|
75
|
+
urlObject = new URL(absoluteUrl);
|
|
76
|
+
} catch (ex) {
|
|
77
|
+
// not a valid URL
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return !isPublic && urlObject.pathname.startsWith(publicUrlPrefix);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const getRelativeUrlFromAbsolute = (absoluteUrl: string, location = window.location) => {
|
|
84
|
+
return absoluteUrl.replace(location.origin, "");
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const knownScrollLocatorParams = new Set(["field", "comment", "anchor"]);
|
|
88
|
+
type Context = {contextEntityTypeName: string; contextEntityPublicId: string};
|
|
89
|
+
export const createPureFiberyEntityUrlMatcher =
|
|
90
|
+
({ownHost}: {ownHost: string}) =>
|
|
91
|
+
(
|
|
92
|
+
originalUrl: string,
|
|
93
|
+
matchUserAsWell = false
|
|
94
|
+
): null | {
|
|
95
|
+
publicId: string;
|
|
96
|
+
typeName: string;
|
|
97
|
+
scrollLocator?: string | null;
|
|
98
|
+
scrollLocatorParams?: {field?: string; comment?: string; anchor?: string};
|
|
99
|
+
context?: Context;
|
|
100
|
+
} => {
|
|
101
|
+
let urlObject = null;
|
|
102
|
+
try {
|
|
103
|
+
urlObject = new URL(originalUrl);
|
|
104
|
+
} catch (ex) {
|
|
105
|
+
// not a valid URL
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (urlObject.host !== ownHost) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const auxMatch = getAuxMatch(urlObject.hash, "");
|
|
114
|
+
if (auxMatch !== null) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const pageMatch = getPageMatch(urlObject.pathname);
|
|
119
|
+
if (pageMatch === null) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const {page, params} = pageMatch;
|
|
124
|
+
if (!validPageMatchSet.has(page)) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let typeName = [params.appNamespace, params.typeWithoutNamespace].join("/");
|
|
129
|
+
if (typeName === "fibery/user" && !matchUserAsWell) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
let publicId = null;
|
|
133
|
+
let context: Context | undefined = undefined;
|
|
134
|
+
if (page === ":page/specific-object-view" && !params.viewLocator) {
|
|
135
|
+
const objectOrViewLocator = String(params.objectLocator);
|
|
136
|
+
publicId = parseLocator(objectOrViewLocator).publicId;
|
|
137
|
+
} else if (params.viewLocator) {
|
|
138
|
+
const objectOrViewLocator = String(params.viewLocator);
|
|
139
|
+
publicId = parseLocator(objectOrViewLocator).publicId;
|
|
140
|
+
typeName = "fibery/view";
|
|
141
|
+
const objectLocator = String(params.objectLocator);
|
|
142
|
+
const contextEntityPublicId = parseLocator(objectLocator).publicId;
|
|
143
|
+
if (contextEntityPublicId && params.appNamespace && params.typeWithoutNamespace) {
|
|
144
|
+
context = {
|
|
145
|
+
contextEntityTypeName: `${params.appNamespace}/${params.typeWithoutNamespace}`,
|
|
146
|
+
contextEntityPublicId: contextEntityPublicId,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (publicId === null) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const scrollLocatorParams = Object.fromEntries(
|
|
156
|
+
Object.entries(parseScrollLocator(pageMatch.params.scrollLocator as string)).filter(([key, value]) => {
|
|
157
|
+
return knownScrollLocatorParams.has(key) && value;
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
publicId,
|
|
163
|
+
typeName,
|
|
164
|
+
scrollLocator: pageMatch.params.scrollLocator as string,
|
|
165
|
+
scrollLocatorParams: Object.keys(scrollLocatorParams).length ? scrollLocatorParams : undefined,
|
|
166
|
+
context,
|
|
167
|
+
};
|
|
168
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let presets: string[][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const replaceDiactrics: (str?: string) => string;
|
package/lib/diactrics.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.replaceDiactrics = void 0;
|
|
4
|
+
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",
|
|
108
|
+
};
|
|
109
|
+
const replaceDiactrics = (str = "") => {
|
|
110
|
+
return str
|
|
111
|
+
.split("")
|
|
112
|
+
.map((char) => DIACTRICS_REPLACEMENT_MAP[char] || char)
|
|
113
|
+
.join("");
|
|
114
|
+
};
|
|
115
|
+
exports.replaceDiactrics = replaceDiactrics;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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;
|
|
11
|
+
}) => 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;
|
|
19
|
+
type Context = {
|
|
20
|
+
contextEntityTypeName: string;
|
|
21
|
+
contextEntityPublicId: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const createPureFiberyEntityUrlMatcher: ({ ownHost }: {
|
|
24
|
+
ownHost: string;
|
|
25
|
+
}) => (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;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
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");
|
|
7
|
+
const appendQueryFlag = (url, key) => {
|
|
8
|
+
const [location, ...hash] = url.split("#");
|
|
9
|
+
const prefix = location.indexOf("?") >= 0 ? "&" : "?";
|
|
10
|
+
return [`${location}${prefix}${key}`, ...hash].join("#");
|
|
11
|
+
};
|
|
12
|
+
exports.appendQueryFlag = appendQueryFlag;
|
|
13
|
+
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("#");
|
|
20
|
+
};
|
|
21
|
+
exports.appendQueryParameter = appendQueryParameter;
|
|
22
|
+
const getFlagValue = (flag) => new URLSearchParams(window.location.search).get(flag);
|
|
23
|
+
exports.getFlagValue = getFlagValue;
|
|
24
|
+
const getSharingKey = () => {
|
|
25
|
+
return (0, exports.getFlagValue)(url_constants_1.sharingParamName) || (0, exports.getFlagValue)("sk");
|
|
26
|
+
};
|
|
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);
|
|
33
|
+
};
|
|
34
|
+
exports.appendSharingKey = appendSharingKey;
|
|
35
|
+
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
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.appendIsPublicParam = appendIsPublicParam;
|
|
45
|
+
const signedFileUrl = (url) => {
|
|
46
|
+
return url?.startsWith("/api/files/") && !url?.startsWith("/api/files/r/")
|
|
47
|
+
? url.replace("/api/files", "/api/files/r")
|
|
48
|
+
: url;
|
|
49
|
+
};
|
|
50
|
+
exports.signedFileUrl = signedFileUrl;
|
|
51
|
+
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"]);
|
|
59
|
+
const isRelativeUrl = (url) => {
|
|
60
|
+
return url.startsWith("/");
|
|
61
|
+
};
|
|
62
|
+
exports.isRelativeUrl = isRelativeUrl;
|
|
63
|
+
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);
|
|
74
|
+
};
|
|
75
|
+
exports.isPublicUrlInPrivateMode = isPublicUrlInPrivateMode;
|
|
76
|
+
const getRelativeUrlFromAbsolute = (absoluteUrl, location = window.location) => {
|
|
77
|
+
return absoluteUrl.replace(location.origin, "");
|
|
78
|
+
};
|
|
79
|
+
exports.getRelativeUrlFromAbsolute = getRelativeUrlFromAbsolute;
|
|
80
|
+
const knownScrollLocatorParams = new Set(["field", "comment", "anchor"]);
|
|
81
|
+
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
|
+
};
|
|
141
|
+
};
|
|
142
|
+
exports.createPureFiberyEntityUrlMatcher = createPureFiberyEntityUrlMatcher;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export let testEnvironment: string;
|
|
2
|
+
export let coveragePathIgnorePatterns: string[];
|
|
3
|
+
export let collectCoverageFrom: string[];
|
|
4
|
+
export let coverageReporters: string[];
|
|
5
|
+
export let testRunner: string;
|
|
6
|
+
export let setupFiles: string[];
|
|
7
|
+
export let transformIgnorePatterns: string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = {
|
|
3
|
+
testEnvironment: "jsdom",
|
|
4
|
+
coveragePathIgnorePatterns: ["/node_modules/", "<rootDir>/src/mocks", "<rootDir>/src/components/icons"],
|
|
5
|
+
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
|
|
6
|
+
coverageReporters: ["text", "cobertura"],
|
|
7
|
+
testRunner: "jest-circus/runner",
|
|
8
|
+
setupFiles: [require.resolve("whatwg-fetch")],
|
|
9
|
+
transformIgnorePatterns: ["node_modules/.pnpm/(?!(screenfull|lowlight|devlop|fault)@)"],
|
|
10
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const escapeRegExpChar: (x: string) => string;
|
|
2
|
+
export declare const parseLocator: (locator: string) => {
|
|
3
|
+
publicId: string | null;
|
|
4
|
+
title: null;
|
|
5
|
+
} | {
|
|
6
|
+
publicId: string;
|
|
7
|
+
title: string;
|
|
8
|
+
};
|
|
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;
|
|
13
|
+
}) => string;
|
|
14
|
+
export declare const createAnchorScrollLocatorValue: (params: {
|
|
15
|
+
id: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
}) => string;
|
|
18
|
+
export declare const parseScrollLocatorValue: (key: string, originalValue: string) => string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseScrollLocatorValue = exports.createAnchorScrollLocatorValue = exports.makeLocator = exports.parseScrollLocator = exports.parseLocator = exports.escapeRegExpChar = void 0;
|
|
4
|
+
const diactrics_1 = require("./diactrics");
|
|
5
|
+
const urlAllowedChars = [`$`, `-`, `_`, `.`, `+`, `!`, `*`, `'`, `(`, `)`, `,`];
|
|
6
|
+
const escapeRegExpChar = (x) => `\\${x}`;
|
|
7
|
+
exports.escapeRegExpChar = escapeRegExpChar;
|
|
8
|
+
const urlAllowedCharsPatternGroup = `a-zA-Z0-9${urlAllowedChars.map(exports.escapeRegExpChar).join("")}`;
|
|
9
|
+
const nonUrlChars = new RegExp(`[^${urlAllowedCharsPatternGroup}]+`, "g");
|
|
10
|
+
const threeNonUrlChars = new RegExp(`[^${urlAllowedCharsPatternGroup}]{3}`);
|
|
11
|
+
const parseLocator = (locator) => {
|
|
12
|
+
const lastDashIndex = locator.lastIndexOf("-");
|
|
13
|
+
if (lastDashIndex === -1) {
|
|
14
|
+
return { publicId: locator || null, title: null };
|
|
15
|
+
}
|
|
16
|
+
const publicId = locator.slice(lastDashIndex + 1);
|
|
17
|
+
const title = locator.slice(0, lastDashIndex).replace(/-/g, " ");
|
|
18
|
+
return { publicId, title };
|
|
19
|
+
};
|
|
20
|
+
exports.parseLocator = parseLocator;
|
|
21
|
+
const TITLE_MAX_LENGTH = 100;
|
|
22
|
+
const normalizeLocatorTitle = (title, maxLength = TITLE_MAX_LENGTH) => {
|
|
23
|
+
const normalizedTitle = (0, diactrics_1.replaceDiactrics)(title.trim());
|
|
24
|
+
const titleWithoutSpaces = normalizedTitle.split(" ").filter(Boolean).join("-");
|
|
25
|
+
return titleWithoutSpaces.match(threeNonUrlChars)
|
|
26
|
+
? ""
|
|
27
|
+
: normalizedTitle.replace(nonUrlChars, " ").trim().replace(/\s+/g, "-").substr(0, maxLength).replace(/-+$/, "");
|
|
28
|
+
};
|
|
29
|
+
const parseScrollLocator = (locator) => {
|
|
30
|
+
const defaultResult = {
|
|
31
|
+
field: null,
|
|
32
|
+
};
|
|
33
|
+
if (locator) {
|
|
34
|
+
const searchParams = new URLSearchParams(locator);
|
|
35
|
+
const entries = [...searchParams.entries()].map(([key, value]) => {
|
|
36
|
+
return [key, (0, exports.parseScrollLocatorValue)(key, value)];
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
...defaultResult,
|
|
40
|
+
...Object.fromEntries(entries),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return defaultResult;
|
|
44
|
+
};
|
|
45
|
+
exports.parseScrollLocator = parseScrollLocator;
|
|
46
|
+
const makeLocator = ({ publicId, title }) => {
|
|
47
|
+
if (!publicId) {
|
|
48
|
+
throw new Error("publicId is required");
|
|
49
|
+
}
|
|
50
|
+
const titleToUse = normalizeLocatorTitle(title || "");
|
|
51
|
+
return [titleToUse, publicId].filter(Boolean).join("-");
|
|
52
|
+
};
|
|
53
|
+
exports.makeLocator = makeLocator;
|
|
54
|
+
const anchorScrollLocatorDelimiter = "--";
|
|
55
|
+
const createAnchorScrollLocatorValue = (params) => {
|
|
56
|
+
const { id, text } = params;
|
|
57
|
+
const title = normalizeLocatorTitle(text || "", 40)
|
|
58
|
+
.split(anchorScrollLocatorDelimiter)
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.join("-");
|
|
61
|
+
return [title, id].filter(Boolean).join(anchorScrollLocatorDelimiter);
|
|
62
|
+
};
|
|
63
|
+
exports.createAnchorScrollLocatorValue = createAnchorScrollLocatorValue;
|
|
64
|
+
const parseScrollLocatorValue = (key, originalValue) => {
|
|
65
|
+
if (key === "anchor") {
|
|
66
|
+
const [anchorId] = originalValue.split(anchorScrollLocatorDelimiter).reverse();
|
|
67
|
+
return anchorId;
|
|
68
|
+
}
|
|
69
|
+
return originalValue;
|
|
70
|
+
};
|
|
71
|
+
exports.parseScrollLocatorValue = parseScrollLocatorValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makePath(route?: string | void, params?: Record<string, unknown> | null | void): string;
|
package/lib/make-path.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makePath = makePath;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const path_to_regexp_1 = __importDefault(require("path-to-regexp"));
|
|
9
|
+
const routes_1 = require("./routes");
|
|
10
|
+
const index_1 = require("./index");
|
|
11
|
+
const url_constants_1 = require("./url-constants");
|
|
12
|
+
const throwError = (message) => {
|
|
13
|
+
throw new Error(message);
|
|
14
|
+
};
|
|
15
|
+
const memoizedCompile = lodash_1.default.memoize(path_to_regexp_1.default.compile);
|
|
16
|
+
// History lesson: at some point we've encoded space with "–" and then decided to use "_"
|
|
17
|
+
// Need to support both old URLs and new ones
|
|
18
|
+
const encodeSpacesWithDashes = (str = "") => str.replace(/ /g, "–");
|
|
19
|
+
const encodeSpacesWithUnderscores = (str = "") => str.replace(/ /g, "_");
|
|
20
|
+
const makeEncodeURIComponentPretty = (spacesEncoder) => {
|
|
21
|
+
return (str) => {
|
|
22
|
+
return lodash_1.default.flow([
|
|
23
|
+
spacesEncoder,
|
|
24
|
+
encodeURI,
|
|
25
|
+
// old encodePretty implementation from prev version of path-to-regexp
|
|
26
|
+
(encodedStr) => encodedStr.replace(/[/?#]/g, function (c) {
|
|
27
|
+
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
|
|
28
|
+
}),
|
|
29
|
+
])(str);
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const makeEncodeURIComponentPrettyUnderscores = makeEncodeURIComponentPretty(encodeSpacesWithUnderscores);
|
|
33
|
+
const makeEncodeURIComponentPrettyDashes = makeEncodeURIComponentPretty(encodeSpacesWithDashes);
|
|
34
|
+
const shouldAddPublicPrefix = (route) => {
|
|
35
|
+
return !routes_1.AUX_ROUTES_PATTERNS.includes(route) && !route.startsWith(url_constants_1.formsUrlPrefix);
|
|
36
|
+
};
|
|
37
|
+
function makePath(route = throwError("route arg is missing"), params = throwError("params arg is missing")) {
|
|
38
|
+
const encodeFn = routes_1.ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP[route]
|
|
39
|
+
? makeEncodeURIComponentPrettyDashes
|
|
40
|
+
: makeEncodeURIComponentPrettyUnderscores;
|
|
41
|
+
return memoizedCompile((index_1.isPublicSpaceMode && shouldAddPublicPrefix(route) ? `${url_constants_1.publicUrlPrefix}${route}` : route))(params, { encode: encodeFn });
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type PageMatch<P, PARAMS> = {
|
|
2
|
+
page: P;
|
|
3
|
+
params: PARAMS;
|
|
4
|
+
isFavorite: boolean;
|
|
5
|
+
matchedPath: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function safeDecodeURIComponent(maybeEncodedPath: string): string;
|
|
8
|
+
export declare function findPageMatch(maybeEncodedPath: string): PageMatch<string, Record<string, unknown>> | null;
|
|
9
|
+
export type AuxMatch<AUX, PARAMS> = {
|
|
10
|
+
aux: AUX;
|
|
11
|
+
params: PARAMS;
|
|
12
|
+
pageAppNamespace: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function findAuxMatch(path: string, pageAppNamespace: string): AuxMatch<string, Record<string, unknown>> | null;
|
|
15
|
+
export declare function getPageMatch(pathname: string): null | PageMatch<string, Record<string, unknown>>;
|
|
16
|
+
export declare function getAuxMatch(hash: string | null | undefined, implicitAppNamespace: string): AuxMatch<string, Record<string, unknown>> | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeDecodeURIComponent = safeDecodeURIComponent;
|
|
4
|
+
exports.findPageMatch = findPageMatch;
|
|
5
|
+
exports.findAuxMatch = findAuxMatch;
|
|
6
|
+
exports.getPageMatch = getPageMatch;
|
|
7
|
+
exports.getAuxMatch = getAuxMatch;
|
|
8
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
9
|
+
const routes_1 = require("./routes");
|
|
10
|
+
// History lesson: at some point we've encoded space with "–" and then decided to use "_"
|
|
11
|
+
// Need to support both old URLs and new ones
|
|
12
|
+
const decodeDashesToSpaces = (str = "") => str.replace(/–/g, " ");
|
|
13
|
+
const decodeUnderscoresToSpaces = (str = "") => str.replace(/_/g, " ");
|
|
14
|
+
const isTest = process.env.NODE_ENV === "test";
|
|
15
|
+
function notEmpty(value) {
|
|
16
|
+
return value !== null && value !== undefined;
|
|
17
|
+
}
|
|
18
|
+
const findTruthy = (items, transform) => {
|
|
19
|
+
const results = items.map(transform).filter(notEmpty);
|
|
20
|
+
if (isTest && results.length > 1) {
|
|
21
|
+
throw new Error(`Found more than one route: ` + JSON.stringify(results, null, 2));
|
|
22
|
+
}
|
|
23
|
+
return results[0] || null;
|
|
24
|
+
};
|
|
25
|
+
function safeDecodeURIComponent(maybeEncodedPath) {
|
|
26
|
+
let path = maybeEncodedPath;
|
|
27
|
+
try {
|
|
28
|
+
path = decodeURIComponent(maybeEncodedPath);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// we don't care, expected to fail in case already decoded path was provided, but includes %, e.g. '% Done'
|
|
32
|
+
// all react-router code (useLocation, usePageMatch) provides already decoded value
|
|
33
|
+
// but we also sometimes make path manually using makePath (which is encoded) and then trying to findPageMatch which provides wrong results
|
|
34
|
+
}
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
// As it is written right now doesn't work with enums (Object Editor in fullscreen)
|
|
38
|
+
function findPageMatch(maybeEncodedPath) {
|
|
39
|
+
const path = safeDecodeURIComponent(maybeEncodedPath);
|
|
40
|
+
const processedPath = decodeUnderscoresToSpaces(decodeDashesToSpaces(path));
|
|
41
|
+
return findTruthy(routes_1.ORDERED_PAGE_ROUTES, ([page, route]) => {
|
|
42
|
+
const match = (0, react_router_dom_1.matchPath)(processedPath, { path: route, exact: true });
|
|
43
|
+
return match ? { page, params: match.params, isFavorite: false, matchedPath: match.path } : null;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function findAuxMatch(path, pageAppNamespace) {
|
|
47
|
+
const decodedPath = decodeDashesToSpaces(path);
|
|
48
|
+
return findTruthy(routes_1.ORDERED_AUX_ROUTES, ([aux, route]) => {
|
|
49
|
+
const match = (0, react_router_dom_1.matchPath)(decodedPath, { path: route, exact: true });
|
|
50
|
+
if (!match) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (routes_1.ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP[aux]) {
|
|
54
|
+
return { aux, params: match.params, pageAppNamespace };
|
|
55
|
+
}
|
|
56
|
+
const nonEnumRouteMatch = (0, react_router_dom_1.matchPath)(decodeUnderscoresToSpaces(decodedPath), { path: route, exact: true });
|
|
57
|
+
return { aux, params: nonEnumRouteMatch?.params ?? {}, pageAppNamespace };
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function getPageMatch(pathname) {
|
|
61
|
+
const pageMatch = findPageMatch(pathname);
|
|
62
|
+
if (pageMatch === null) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (pageMatch.page === ":page/favorite") {
|
|
66
|
+
const partsPageMatch = findPageMatch(`/${pageMatch.params.parts}`);
|
|
67
|
+
if (partsPageMatch === null) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return { ...partsPageMatch, isFavorite: true };
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return { ...pageMatch, isFavorite: false };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function getAuxMatch(hash, implicitAppNamespace) {
|
|
77
|
+
return hash ? findAuxMatch(decodeURIComponent(hash.slice(1)), implicitAppNamespace) : null;
|
|
78
|
+
}
|
package/lib/routes.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
export declare const appIndexViewLocator = "views";
|
|
3
|
+
export declare const userAccessViewLocator = "access";
|
|
4
|
+
export declare const specificObjectViewsCatalogViewLocator = "views";
|
|
5
|
+
export declare const deprecatedSpecificObjectEditorViewLocator = "edit";
|
|
6
|
+
export declare const specificObjectUnknownObjectLocator = "any";
|
|
7
|
+
export declare const specificObjectEditorViewLocator: null;
|
|
8
|
+
export declare const appTypeModePage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace";
|
|
9
|
+
export declare const appTypeModeSubPage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage";
|
|
10
|
+
export declare const appTypeModeAutomationBasePage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage/:automationType/:automationItemId";
|
|
11
|
+
export declare const appTypeModeAccessTemplatePage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage/access-templates/:accessTemplateId";
|
|
12
|
+
export declare const appTypeModeAutomationSpecificPage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage/:automationType/:automationItemId/:automationMode";
|
|
13
|
+
export declare const appTypeModeFieldEditPage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage/:fieldTitle/edit";
|
|
14
|
+
export declare const appTypeModeGroupEditPage = "/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage/:typeId/members";
|
|
15
|
+
export declare const appModePage = "/fibery/space/:appNamespace/:mode";
|
|
16
|
+
export declare const appTypeModePageView: string;
|
|
17
|
+
export declare const formsPublicPage = "/@public/forms/:formKey";
|
|
18
|
+
export declare const highlightTypePage = "/fibery/settings/:subsection(highlights)/:typeWithoutNamespace";
|
|
19
|
+
export declare const highlightTypeFieldEditPage = "/fibery/settings/:subsection(highlights)/:typeWithoutNamespace/fields/:fieldWithoutNamespace/edit";
|
|
20
|
+
export declare const integrationSettingPage = "/fibery/settings/:subsection(integrations)/:templateId";
|
|
21
|
+
export declare const personalIntegrationSettingPage = "/fibery/settings/:subsection(personal-integrations)/:integrationId";
|
|
22
|
+
export declare const isSettingsPage: (page?: string) => boolean;
|
|
23
|
+
export declare const ORDERED_PAGE_ROUTES: Array<[string, string]>;
|
|
24
|
+
export declare const PAGE_ROUTES: _.Dictionary<string>;
|
|
25
|
+
export declare const ORDERED_COMMON_AUX_ROUTES: Array<[string, string]>;
|
|
26
|
+
export declare const ORDERED_AUX_ROUTES: Array<[string, string]>;
|
|
27
|
+
export declare const AUX_ROUTES: _.Dictionary<string>;
|
|
28
|
+
export declare const AUX_ROUTES_PATTERNS: string[];
|
|
29
|
+
export declare const ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP: {
|
|
30
|
+
[k: string]: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare const ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP: {
|
|
33
|
+
[k: string]: boolean;
|
|
34
|
+
};
|
package/lib/routes.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP = exports.ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP = exports.AUX_ROUTES_PATTERNS = exports.AUX_ROUTES = exports.ORDERED_AUX_ROUTES = exports.ORDERED_COMMON_AUX_ROUTES = exports.PAGE_ROUTES = exports.ORDERED_PAGE_ROUTES = exports.isSettingsPage = exports.personalIntegrationSettingPage = exports.integrationSettingPage = exports.highlightTypeFieldEditPage = exports.highlightTypePage = exports.formsPublicPage = exports.appTypeModePageView = exports.appModePage = exports.appTypeModeGroupEditPage = exports.appTypeModeFieldEditPage = exports.appTypeModeAutomationSpecificPage = exports.appTypeModeAccessTemplatePage = exports.appTypeModeAutomationBasePage = exports.appTypeModeSubPage = exports.appTypeModePage = exports.specificObjectEditorViewLocator = exports.specificObjectUnknownObjectLocator = exports.deprecatedSpecificObjectEditorViewLocator = exports.specificObjectViewsCatalogViewLocator = exports.userAccessViewLocator = exports.appIndexViewLocator = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const locator_utils_1 = require("./locator-utils");
|
|
9
|
+
const url_constants_1 = require("./url-constants");
|
|
10
|
+
const titleWithPublicIdLocatorPattern = `[^/=]+?-\\d+`;
|
|
11
|
+
const transientIdPattern = "...".split("").map(locator_utils_1.escapeRegExpChar).join("");
|
|
12
|
+
const titleWithTransientIdLocatorPattern = `[^/]+?-${transientIdPattern}`;
|
|
13
|
+
const transientIdLocatorPattern = transientIdPattern;
|
|
14
|
+
const idLocatorPattern = `\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}`;
|
|
15
|
+
const publicIdLocatorPattern = `\\d+`;
|
|
16
|
+
const viewLocatorPattern = `${titleWithPublicIdLocatorPattern}|${titleWithTransientIdLocatorPattern}|${transientIdLocatorPattern}|${publicIdLocatorPattern}`;
|
|
17
|
+
const auxLocatorPattern = `${titleWithPublicIdLocatorPattern}|${idLocatorPattern}|${publicIdLocatorPattern}`;
|
|
18
|
+
const titleWithGuidLocatorPattern = `[^/]+?--${idLocatorPattern}`;
|
|
19
|
+
const commentLocatorPattern = `comment=${publicIdLocatorPattern}`;
|
|
20
|
+
const extendedCommentLocatorPattern = `parentComment=${publicIdLocatorPattern}&comment=${publicIdLocatorPattern}`;
|
|
21
|
+
const anchorLocatorPattern = `anchor=${idLocatorPattern}`;
|
|
22
|
+
const anchorWithTitleLocatorPattern = `anchor=${titleWithGuidLocatorPattern}`;
|
|
23
|
+
const anchorWB = `anchor=wb-[^/]+`;
|
|
24
|
+
const fieldLocatorPattern = `field=${idLocatorPattern}`;
|
|
25
|
+
const scrollLocatorPattern = `${extendedCommentLocatorPattern}|${commentLocatorPattern}|${fieldLocatorPattern}|${anchorLocatorPattern}|${anchorWithTitleLocatorPattern}|${anchorWB}`;
|
|
26
|
+
exports.appIndexViewLocator = "views";
|
|
27
|
+
exports.userAccessViewLocator = "access";
|
|
28
|
+
exports.specificObjectViewsCatalogViewLocator = "views";
|
|
29
|
+
exports.deprecatedSpecificObjectEditorViewLocator = "edit";
|
|
30
|
+
exports.specificObjectUnknownObjectLocator = "any";
|
|
31
|
+
exports.specificObjectEditorViewLocator = null;
|
|
32
|
+
exports.appTypeModePage = `/fibery/space/:appNamespace/:mode/:typeWithoutNamespace`;
|
|
33
|
+
exports.appTypeModeSubPage = `/fibery/space/:appNamespace/:mode/:typeWithoutNamespace/:subPage`;
|
|
34
|
+
exports.appTypeModeAutomationBasePage = `${exports.appTypeModeSubPage}/:automationType/:automationItemId`;
|
|
35
|
+
exports.appTypeModeAccessTemplatePage = `${exports.appTypeModeSubPage}/access-templates/:accessTemplateId`;
|
|
36
|
+
exports.appTypeModeAutomationSpecificPage = `${exports.appTypeModeAutomationBasePage}/:automationMode`;
|
|
37
|
+
exports.appTypeModeFieldEditPage = `${exports.appTypeModeSubPage}/:fieldTitle/edit`;
|
|
38
|
+
exports.appTypeModeGroupEditPage = `${exports.appTypeModeSubPage}/:typeId/members`;
|
|
39
|
+
exports.appModePage = `/fibery/space/:appNamespace/:mode`;
|
|
40
|
+
exports.appTypeModePageView = `${exports.appTypeModePage}/${exports.appIndexViewLocator}/:viewLocator(${viewLocatorPattern})`;
|
|
41
|
+
exports.formsPublicPage = `${url_constants_1.formsUrlPrefix}/:formKey`;
|
|
42
|
+
exports.highlightTypePage = "/fibery/settings/:subsection(highlights)/:typeWithoutNamespace";
|
|
43
|
+
exports.highlightTypeFieldEditPage = `${exports.highlightTypePage}/fields/:fieldWithoutNamespace/edit`;
|
|
44
|
+
exports.integrationSettingPage = "/fibery/settings/:subsection(integrations)/:templateId";
|
|
45
|
+
exports.personalIntegrationSettingPage = "/fibery/settings/:subsection(personal-integrations)/:integrationId";
|
|
46
|
+
const settingsPage = ":page/settings";
|
|
47
|
+
const appPage = ":page/app";
|
|
48
|
+
const typePage = ":page/type";
|
|
49
|
+
const settingsPages = new Set([settingsPage, appPage, typePage]);
|
|
50
|
+
const isSettingsPage = (page) => {
|
|
51
|
+
if (!page) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return settingsPages.has(page);
|
|
55
|
+
};
|
|
56
|
+
exports.isSettingsPage = isSettingsPage;
|
|
57
|
+
const orderedRoutes = [
|
|
58
|
+
[":page/apps-gallery", `/fibery/apps-gallery/:appCategory`],
|
|
59
|
+
[":page/app", `/fibery/space/:appNamespace`],
|
|
60
|
+
[":page/app-access", `/fibery/space/:appNamespace/access`],
|
|
61
|
+
[":page/app-import", `/fibery/space/:appNamespace/import/:connectorId?/:mode?`],
|
|
62
|
+
[":page/app-sync", `/fibery/space/:appNamespace/sync/:connectorId?/:mode?`],
|
|
63
|
+
[":page/database-import", `/fibery/space/:appNamespace/database/:databaseName/import/:connectorId?`],
|
|
64
|
+
[typePage, exports.appModePage],
|
|
65
|
+
[":page/type-view", exports.appTypeModePageView],
|
|
66
|
+
[typePage, exports.appTypeModeFieldEditPage],
|
|
67
|
+
[typePage, exports.appTypeModeGroupEditPage],
|
|
68
|
+
[typePage, exports.appTypeModeAutomationSpecificPage],
|
|
69
|
+
[typePage, exports.appTypeModeAccessTemplatePage],
|
|
70
|
+
[typePage, exports.appTypeModeAutomationBasePage],
|
|
71
|
+
[typePage, exports.appTypeModeSubPage],
|
|
72
|
+
[typePage, exports.appTypeModePage],
|
|
73
|
+
[":page/schema", `/:appNamespace(fibery)/settings/domain`],
|
|
74
|
+
[":page/me", `/:appNamespace(fibery)/me`],
|
|
75
|
+
[settingsPage, exports.highlightTypePage],
|
|
76
|
+
[settingsPage, exports.integrationSettingPage],
|
|
77
|
+
[settingsPage, exports.highlightTypeFieldEditPage],
|
|
78
|
+
[settingsPage, exports.personalIntegrationSettingPage],
|
|
79
|
+
[settingsPage, "/fibery/settings/:subsection"],
|
|
80
|
+
[settingsPage, "/fibery/settings"],
|
|
81
|
+
[
|
|
82
|
+
":page/app-view",
|
|
83
|
+
`/:appNamespace/:viewLocator(${exports.appIndexViewLocator}|${viewLocatorPattern})/:scrollLocator(${scrollLocatorPattern})?`,
|
|
84
|
+
],
|
|
85
|
+
[":page/favorite", `/favorites/:parts+`],
|
|
86
|
+
[":page/audit-log", "/audit-log"],
|
|
87
|
+
[":page/home", "/home"],
|
|
88
|
+
[":page/activity-log", "/activity-log"],
|
|
89
|
+
[":page/audit-soft-deleted-fields", "/audit-soft-deleted-fields"],
|
|
90
|
+
[":page/global-search", "/search"],
|
|
91
|
+
[":page/global-notifications", "/inbox"],
|
|
92
|
+
[":page/desktop-app-redirect", "/desktop"],
|
|
93
|
+
[":page/search", "/search/:id"],
|
|
94
|
+
[":page/watchlist", "/watchlist"],
|
|
95
|
+
[":page/ai-assistant", "/ai-assistant/:agentId"],
|
|
96
|
+
[":page/shared-with-me", "/shared-with-me"],
|
|
97
|
+
[":page/trash", "/trash"],
|
|
98
|
+
[":page/trash-bin", "/trash-bin"],
|
|
99
|
+
[":page/not-found", "/not-found"],
|
|
100
|
+
[
|
|
101
|
+
":page/specific-object-view",
|
|
102
|
+
[
|
|
103
|
+
`/:appNamespace/:typeWithoutNamespace`,
|
|
104
|
+
`:objectLocator(${exports.specificObjectUnknownObjectLocator}|${titleWithPublicIdLocatorPattern}|${publicIdLocatorPattern})`,
|
|
105
|
+
`:viewLocator(${exports.specificObjectViewsCatalogViewLocator}|${exports.deprecatedSpecificObjectEditorViewLocator}|${viewLocatorPattern})?`,
|
|
106
|
+
`:scrollLocator(${scrollLocatorPattern})?`,
|
|
107
|
+
].join("/"),
|
|
108
|
+
],
|
|
109
|
+
[":page/public-form", `/forms/:formKey`],
|
|
110
|
+
[":page/app-root", `/:appNamespace`],
|
|
111
|
+
[":page/root", `/`],
|
|
112
|
+
];
|
|
113
|
+
exports.ORDERED_PAGE_ROUTES = orderedRoutes
|
|
114
|
+
.map(([page, route]) => [page, `${url_constants_1.publicUrlPrefix}${route === "/" ? "" : route}`])
|
|
115
|
+
.concat(orderedRoutes);
|
|
116
|
+
exports.PAGE_ROUTES = lodash_1.default.fromPairs(exports.ORDERED_PAGE_ROUTES);
|
|
117
|
+
exports.ORDERED_COMMON_AUX_ROUTES = [
|
|
118
|
+
[":aux/no-panel-support", `no-panel/:type`],
|
|
119
|
+
[":aux/notifications", `notifications`],
|
|
120
|
+
[":aux/not-found", "not-found"],
|
|
121
|
+
[":aux/tutorial", `tutorial/:auxLocator(${auxLocatorPattern})/view`],
|
|
122
|
+
[":aux/ai-assistant-history", `ai-assistant-history`],
|
|
123
|
+
[":aux/ai-assistant", `ai-assistant/:agentId/:conversationId`],
|
|
124
|
+
[":aux/ai-assistant", `ai-assistant/:agentId`],
|
|
125
|
+
[":aux/user-access", `user-access/:userPublicId`],
|
|
126
|
+
[":aux/user-group-access", `user-group-access/:auxTypeNamespace/:auxTypeName/:publicId`],
|
|
127
|
+
[":aux/type-access", `:auxTypeNamespace/:auxTypeName/type-access`],
|
|
128
|
+
[":aux/type-object-editor", `:auxTypeNamespace/:auxTypeName/edit`],
|
|
129
|
+
[":aux/type-object-editor-implicit-namespace", `:auxTypeName/edit`],
|
|
130
|
+
[":aux/type-object-editor-for-composite-type", `:nsA/:nameA\\_:nsB/:nameB/edit`],
|
|
131
|
+
[
|
|
132
|
+
":aux/app-view-with-context",
|
|
133
|
+
`:appNamespace/views/:viewType/:viewLocator(${viewLocatorPattern})/context/:auxTypeNamespace/:auxTypeName/:auxLocator(${auxLocatorPattern})/:scrollLocator(${scrollLocatorPattern})?`,
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
":aux/app-view",
|
|
137
|
+
`:appNamespace/views/:viewType/:viewLocator(${viewLocatorPattern})/:scrollLocator(${scrollLocatorPattern})?`,
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
":aux/object-editor",
|
|
141
|
+
`:auxTypeNamespace/:auxTypeName/:auxLocator(${auxLocatorPattern})/:scrollLocator(${scrollLocatorPattern})?`,
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
":aux/object-editor-implicit-namespace",
|
|
145
|
+
`:auxTypeName/:auxLocator(${auxLocatorPattern})/:scrollLocator(${scrollLocatorPattern})?`,
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
":aux/object-editor-for-composite-type",
|
|
149
|
+
`:nsA/:nameA\\_:nsB/:nameB/:auxLocator(${auxLocatorPattern})/:scrollLocator(${scrollLocatorPattern})?`,
|
|
150
|
+
],
|
|
151
|
+
[":aux/gallery-app", `gallery/:auxAppNamespace`],
|
|
152
|
+
[":aux/search", `search/:id`],
|
|
153
|
+
[":aux/shared-with-me", `shared-with-me`],
|
|
154
|
+
[":aux/import", `import`],
|
|
155
|
+
[":aux/app-export", `app-export/:auxAppNamespace/share`],
|
|
156
|
+
[":aux/install-integration-app", `app-sync/:auxAppNamespace`],
|
|
157
|
+
[":aux/users-invite", `invite-users`],
|
|
158
|
+
[":aux/upgrade-to-plan", `upgrade/:auxPlanId`],
|
|
159
|
+
[":aux/update-payment-info", `update-payment-info`],
|
|
160
|
+
[":aux/share-workspace", "share-workspace"],
|
|
161
|
+
[":aux/ai-create-space", "ai-create-space"],
|
|
162
|
+
[":aux/ai-create-view", "ai-create-view/:appNamespace"],
|
|
163
|
+
[":aux/ai-update-view-filter", `ai-update-view-filter-:viewId(${idLocatorPattern})`],
|
|
164
|
+
[":aux/book-demo", `book-demo`],
|
|
165
|
+
[":aux/create-entity", `create-entity`],
|
|
166
|
+
];
|
|
167
|
+
exports.ORDERED_AUX_ROUTES = [
|
|
168
|
+
...exports.ORDERED_COMMON_AUX_ROUTES,
|
|
169
|
+
[":aux/view-config-raw", "config/raw"],
|
|
170
|
+
];
|
|
171
|
+
exports.AUX_ROUTES = lodash_1.default.fromPairs(exports.ORDERED_AUX_ROUTES);
|
|
172
|
+
exports.AUX_ROUTES_PATTERNS = exports.ORDERED_AUX_ROUTES.map(([, pattern]) => pattern);
|
|
173
|
+
const ROUTES_WITH_PRESERVED_UNDERSCORES = [
|
|
174
|
+
// enums
|
|
175
|
+
":aux/type-object-editor-for-composite-type",
|
|
176
|
+
":aux/object-editor-for-composite-type",
|
|
177
|
+
// other
|
|
178
|
+
":aux/upgrade-to-plan",
|
|
179
|
+
];
|
|
180
|
+
const ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS = exports.ORDERED_AUX_ROUTES.filter(([route]) => ROUTES_WITH_PRESERVED_UNDERSCORES.includes(route)).map(([, pattern]) => pattern);
|
|
181
|
+
exports.ROUTES_WITH_PRESERVED_UNDERSCORES_LOOKUP = Object.fromEntries(ROUTES_WITH_PRESERVED_UNDERSCORES.map((x) => [x, true]));
|
|
182
|
+
exports.ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS_LOOKUP = Object.fromEntries(ROUTES_WITH_PRESERVED_UNDERSCORES_PATTERNS.map((x) => [x, true]));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const sharingParamName = "sharing-key";
|
|
2
|
+
export declare const publicParamName = "is-public";
|
|
3
|
+
export declare const publicUrlPrefix = "/@public";
|
|
4
|
+
export declare const formsUrlPrefix = "/@public/forms";
|
|
5
|
+
export declare const formKeyParamName = "form-key";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formKeyParamName = exports.formsUrlPrefix = exports.publicUrlPrefix = exports.publicParamName = exports.sharingParamName = void 0;
|
|
4
|
+
exports.sharingParamName = "sharing-key";
|
|
5
|
+
exports.publicParamName = "is-public";
|
|
6
|
+
exports.publicUrlPrefix = "/@public";
|
|
7
|
+
exports.formsUrlPrefix = "/@public/forms";
|
|
8
|
+
exports.formKeyParamName = "form-key";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type UiSettings = {
|
|
2
|
+
display_name: string | null;
|
|
3
|
+
logo?: string | null;
|
|
4
|
+
};
|
|
5
|
+
export type Workspace = {
|
|
6
|
+
ui_settings: UiSettings | null;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function getWorkspaceTitle(workspace: Workspace): string;
|
|
10
|
+
export declare function isCurrentWorkspace(workspace: Workspace, hostname: string): boolean;
|
|
11
|
+
export declare function getCurrentWorkspaceTitle(workspace: Workspace | null, hostname: string, remoteHost?: string): string;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkspaceTitle = getWorkspaceTitle;
|
|
4
|
+
exports.isCurrentWorkspace = isCurrentWorkspace;
|
|
5
|
+
exports.getCurrentWorkspaceTitle = getCurrentWorkspaceTitle;
|
|
6
|
+
const capitalizeFirstChar = (input) => {
|
|
7
|
+
const str = input || "";
|
|
8
|
+
return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
|
|
9
|
+
};
|
|
10
|
+
function getWorkspaceTitle(workspace) {
|
|
11
|
+
if (workspace.ui_settings?.display_name) {
|
|
12
|
+
return workspace.ui_settings.display_name;
|
|
13
|
+
}
|
|
14
|
+
const titleMatches = workspace.name.match(/(.+?)\.fibery\..+/);
|
|
15
|
+
const name = titleMatches ? titleMatches[1] : workspace.name;
|
|
16
|
+
return name.split(`-`).map(capitalizeFirstChar).join(" ");
|
|
17
|
+
}
|
|
18
|
+
function isCurrentWorkspace(workspace, hostname) {
|
|
19
|
+
return workspace.name === hostname;
|
|
20
|
+
}
|
|
21
|
+
function getCurrentWorkspaceTitle(workspace, hostname, remoteHost) {
|
|
22
|
+
if (hostname === "localhost") {
|
|
23
|
+
if (remoteHost) {
|
|
24
|
+
return `Remote ${remoteHost}`;
|
|
25
|
+
}
|
|
26
|
+
return "Local Development";
|
|
27
|
+
}
|
|
28
|
+
return workspace
|
|
29
|
+
? getWorkspaceTitle(workspace)
|
|
30
|
+
: hostname.split(".")[0].split("-").map(capitalizeFirstChar).join(" ");
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fibery/url-utils",
|
|
3
|
+
"version": "2.2.4",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"browser": "index.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"/lib"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./lib/index.js",
|
|
11
|
+
"./parse-page-location": "./lib/parse-page-location.js",
|
|
12
|
+
"./routes": "./lib/routes.js",
|
|
13
|
+
"./locator-utils": "./lib/locator-utils.js",
|
|
14
|
+
"./url-constants": "./lib/url-constants.js",
|
|
15
|
+
"./workspaces": "./lib/workspaces.js",
|
|
16
|
+
"./make-path": "./make-path.js"
|
|
17
|
+
},
|
|
18
|
+
"fiberyDevExports": {
|
|
19
|
+
".": "./index.ts",
|
|
20
|
+
"./parse-page-location": "./parse-page-location.ts",
|
|
21
|
+
"./routes": "./routes.ts",
|
|
22
|
+
"./locator-utils": "./locator-utils.ts",
|
|
23
|
+
"./url-constants": "./url-constants.ts",
|
|
24
|
+
"./workspaces": "./workspaces.ts",
|
|
25
|
+
"./make-path": "./make-path.ts"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"path-to-regexp": "3.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/jest": "27.0.1",
|
|
32
|
+
"@types/lodash": "4.14.172",
|
|
33
|
+
"@types/node": "18.11.17",
|
|
34
|
+
"@types/react-router-dom": "5.3.2",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "6.10.0",
|
|
36
|
+
"@typescript-eslint/parser": "6.10.0",
|
|
37
|
+
"eslint": "8.53.0",
|
|
38
|
+
"eslint-plugin-unicorn": "46.0.0",
|
|
39
|
+
"jest": "27.5.1",
|
|
40
|
+
"jest-circus": "27.5.1",
|
|
41
|
+
"jest-junit": "13.0.0",
|
|
42
|
+
"lodash": "4.17.21",
|
|
43
|
+
"react": "18.2.0",
|
|
44
|
+
"react-router-dom": "5.3.0",
|
|
45
|
+
"typescript": "5.8.3",
|
|
46
|
+
"@fibery/babel-preset": "7.4.0",
|
|
47
|
+
"@fibery/eslint-config": "8.6.1"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"lodash": "^4.17.21",
|
|
51
|
+
"react-router-dom": "^5.3.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"test": "jest",
|
|
55
|
+
"build": "rm -rf lib && tsc --project ./tsconfig.build.json",
|
|
56
|
+
"test:ci": "jest --reporters=default --reporters=jest-junit",
|
|
57
|
+
"lint": "eslint ."
|
|
58
|
+
}
|
|
59
|
+
}
|