orc-shared 5.8.0-dev.18 → 5.8.0-dev.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/buildUrl.js +14 -1
- package/package.json +1 -1
- package/src/utils/buildUrl.js +13 -0
- package/src/utils/buildUrl.test.js +27 -1
package/dist/utils/buildUrl.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.resetConfig = exports.loadConfig = exports.buildUrl = void 0;
|
|
4
|
+
exports.resetConfig = exports.loadConfig = exports.buildUrl = exports.buildExternalAppUrl = void 0;
|
|
5
5
|
(function () {
|
|
6
6
|
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
|
|
7
7
|
enterModule && enterModule(module);
|
|
@@ -60,6 +60,17 @@ var loadConfig = exports.loadConfig = function loadConfig() {
|
|
|
60
60
|
};
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
|
+
var buildExternalAppUrl = exports.buildExternalAppUrl = function buildExternalAppUrl(app, relativeUrl) {
|
|
64
|
+
var url = relativeUrl[0] === "/" ? relativeUrl.substring(1) : relativeUrl;
|
|
65
|
+
var lowercaseApp = app.toLowerCase();
|
|
66
|
+
switch (lowercaseApp) {
|
|
67
|
+
case "oms":
|
|
68
|
+
case "pim":
|
|
69
|
+
return "/".concat(lowercaseApp, "/app/").concat(url);
|
|
70
|
+
default:
|
|
71
|
+
throw new Error("Not implemented app '" + app + "'");
|
|
72
|
+
}
|
|
73
|
+
};
|
|
63
74
|
|
|
64
75
|
/* Reset function for testing, never use this in actual code */
|
|
65
76
|
var resetConfig = exports.resetConfig = function resetConfig() {
|
|
@@ -75,6 +86,7 @@ var resetConfig = exports.resetConfig = function resetConfig() {
|
|
|
75
86
|
reactHotLoader.register(placeholder, "placeholder", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
76
87
|
reactHotLoader.register(buildUrl, "buildUrl", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
77
88
|
reactHotLoader.register(loadConfig, "loadConfig", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
89
|
+
reactHotLoader.register(buildExternalAppUrl, "buildExternalAppUrl", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
78
90
|
reactHotLoader.register(resetConfig, "resetConfig", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
79
91
|
})();
|
|
80
92
|
;
|
|
@@ -92,6 +104,7 @@ var resetConfig = exports.resetConfig = function resetConfig() {
|
|
|
92
104
|
reactHotLoader.register(placeholder, "placeholder", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
93
105
|
reactHotLoader.register(buildUrl, "buildUrl", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
94
106
|
reactHotLoader.register(loadConfig, "loadConfig", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
107
|
+
reactHotLoader.register(buildExternalAppUrl, "buildExternalAppUrl", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
95
108
|
reactHotLoader.register(resetConfig, "resetConfig", "/home/vsts/work/1/s/src/utils/buildUrl.js");
|
|
96
109
|
})();
|
|
97
110
|
;
|
package/package.json
CHANGED
package/src/utils/buildUrl.js
CHANGED
|
@@ -32,6 +32,19 @@ export const loadConfig = () =>
|
|
|
32
32
|
`${host}/${pathParts.join("/")}` + (parameters ? "?" + buildParamString(parameters) : "");
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
export const buildExternalAppUrl = (app, relativeUrl) => {
|
|
36
|
+
const url = relativeUrl[0] === "/" ? relativeUrl.substring(1) : relativeUrl;
|
|
37
|
+
|
|
38
|
+
let lowercaseApp = app.toLowerCase();
|
|
39
|
+
switch (lowercaseApp) {
|
|
40
|
+
case "oms":
|
|
41
|
+
case "pim":
|
|
42
|
+
return `/${lowercaseApp}/app/${url}`;
|
|
43
|
+
default:
|
|
44
|
+
throw new Error("Not implemented app '" + app + "'");
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
35
48
|
/* Reset function for testing, never use this in actual code */
|
|
36
49
|
export const resetConfig = () => {
|
|
37
50
|
buildUrl = placeholder;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sinon from "sinon";
|
|
2
2
|
import { spyOnConsole } from "./testUtils";
|
|
3
|
-
import { loadConfig, resetConfig, buildUrl } from "./buildUrl";
|
|
3
|
+
import { loadConfig, resetConfig, buildUrl, buildExternalAppUrl } from "./buildUrl";
|
|
4
4
|
|
|
5
5
|
describe("loadConfig", () => {
|
|
6
6
|
spyOnConsole();
|
|
@@ -72,4 +72,30 @@ describe("loadConfig", () => {
|
|
|
72
72
|
));
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
|
+
|
|
76
|
+
describe("buildExternalAppUrl", () => {
|
|
77
|
+
it("throws an error if called with an unknown app", () => {
|
|
78
|
+
expect(
|
|
79
|
+
() => expect(buildExternalAppUrl, "when called with", ["unknown", "fakeurl"]),
|
|
80
|
+
"to throw",
|
|
81
|
+
"Not implemented app 'unknown'",
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should build an valid relative url with oms", () => {
|
|
86
|
+
expect(buildExternalAppUrl, "called with", ["oms", "fakeurl"], "to equal", "/oms/app/fakeurl");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should build an valid relative url with pim", () => {
|
|
90
|
+
expect(buildExternalAppUrl, "called with", ["pim", "fakeurl"], "to equal", "/pim/app/fakeurl");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should not be case sensitive about the app name", () => {
|
|
94
|
+
expect(buildExternalAppUrl, "called with", ["PIM", "fakeurl"], "to equal", "/pim/app/fakeurl");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should handle delimiter", () => {
|
|
98
|
+
expect(buildExternalAppUrl, "called with", ["pim", "/fakeurl"], "to equal", "/pim/app/fakeurl");
|
|
99
|
+
});
|
|
100
|
+
});
|
|
75
101
|
});
|