asma-helpers 0.3.17 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/checkForRegisteredSubdomains.d.ts +6 -2
- package/lib/helpers/checkForRegisteredSubdomains.d.ts.map +1 -1
- package/lib/helpers/checkForRegisteredSubdomains.js +29 -3
- package/lib/helpers/checkForRegisteredSubdomains.js.map +1 -1
- package/lib/helpers/getSubdomain.d.ts.map +1 -1
- package/lib/helpers/getSubdomain.js +11 -9
- package/lib/helpers/getSubdomain.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/checkForRegisteredSubdomains.ts +45 -2
- package/src/helpers/getSubdomain.ts +13 -15
|
@@ -13,9 +13,13 @@ export declare function onThemeChange(callback: (val: {
|
|
|
13
13
|
};
|
|
14
14
|
export declare function getTheme(): string;
|
|
15
15
|
export declare function setTheme(theme: string): void;
|
|
16
|
-
export declare function checkForRegisteredSubdomain({ redirect_if_not_exists, setSelectedCustomer, srvAuthGet, }: {
|
|
16
|
+
export declare function checkForRegisteredSubdomain({ redirect_if_not_exists, setSelectedCustomer, srvAuthGet, logos, }: {
|
|
17
17
|
redirect_if_not_exists?: boolean;
|
|
18
18
|
setSelectedCustomer?: (customer_id: string) => void;
|
|
19
19
|
srvAuthGet: <R>(url: string, headers?: Record<string, string> | undefined) => Promise<R>;
|
|
20
|
-
|
|
20
|
+
logos: {
|
|
21
|
+
fretexLogo: string;
|
|
22
|
+
carasentLogo: string;
|
|
23
|
+
};
|
|
24
|
+
}): Promise<[registeredSubdomain: boolean, unregister: () => void]>;
|
|
21
25
|
//# sourceMappingURL=checkForRegisteredSubdomains.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkForRegisteredSubdomains.d.ts","sourceRoot":"","sources":["../../src/helpers/checkForRegisteredSubdomains.ts"],"names":[],"mappings":"AAwBA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,eAA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AAC,CAAC,CAAC,CAAA;IACxF,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAA;CACtD,4DA4BsF,IAAI,GAC1F"}
|
|
@@ -30,7 +30,7 @@ export function setTheme(theme) {
|
|
|
30
30
|
}
|
|
31
31
|
setThemeLocal(theme);
|
|
32
32
|
}
|
|
33
|
-
export async function checkForRegisteredSubdomain({ redirect_if_not_exists = true, setSelectedCustomer, srvAuthGet, }) {
|
|
33
|
+
export async function checkForRegisteredSubdomain({ redirect_if_not_exists = true, setSelectedCustomer, srvAuthGet, logos, }) {
|
|
34
34
|
const res = await srvAuthGet('/check?context=subdomain', {
|
|
35
35
|
'asma-origin': window.location.origin,
|
|
36
36
|
});
|
|
@@ -38,10 +38,36 @@ export async function checkForRegisteredSubdomain({ redirect_if_not_exists = tru
|
|
|
38
38
|
if (res === null || res === void 0 ? void 0 : res.id) {
|
|
39
39
|
setSelectedCustomer === null || setSelectedCustomer === void 0 ? void 0 : setSelectedCustomer(res.id);
|
|
40
40
|
}
|
|
41
|
-
(res === null || res === void 0 ? void 0 : res.theme)
|
|
41
|
+
if (res === null || res === void 0 ? void 0 : res.theme) {
|
|
42
|
+
setTheme(res.theme);
|
|
43
|
+
}
|
|
44
|
+
appendAsmaLogoLink(getTheme(), logos);
|
|
42
45
|
if (!!!(res === null || res === void 0 ? void 0 : res.id) && redirect_if_not_exists) {
|
|
43
46
|
redirectFromSubdomainToDomain();
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
const { unregister } = onThemeChange(({ theme }) => {
|
|
49
|
+
appendAsmaLogoLink(theme, logos);
|
|
50
|
+
});
|
|
51
|
+
return [!!(res === null || res === void 0 ? void 0 : res.id), unregister];
|
|
52
|
+
}
|
|
53
|
+
function appendAsmaLogoLink(theme = 'default', { carasentLogo, fretexLogo }) {
|
|
54
|
+
var _a;
|
|
55
|
+
const body = document.body;
|
|
56
|
+
body.dataset['theme'] = theme;
|
|
57
|
+
(_a = document.getElementById('asma-theme-link')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
58
|
+
const link = document.createElement('link');
|
|
59
|
+
link.setAttribute('id', 'asma-logo-link');
|
|
60
|
+
if (theme === 'fretex') {
|
|
61
|
+
document.title = 'Fretex';
|
|
62
|
+
link.setAttribute('href', fretexLogo);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
document.title = 'Carasent';
|
|
66
|
+
link.setAttribute('href', carasentLogo);
|
|
67
|
+
}
|
|
68
|
+
link.setAttribute('rel', 'icon');
|
|
69
|
+
link.setAttribute('type', 'image/png');
|
|
70
|
+
link.setAttribute('sizes', '32x32');
|
|
71
|
+
document.head.appendChild(link);
|
|
46
72
|
}
|
|
47
73
|
//# sourceMappingURL=checkForRegisteredSubdomains.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkForRegisteredSubdomains.js","sourceRoot":"","sources":["../../src/helpers/checkForRegisteredSubdomains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAA;AAE9D;;GAEG;AACH,IAAI,KAAK,GAAG,SAAS,CAAA;AAErB,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,QAAQ,CACjE,YAAY,CACf,CAAA;AAED,SAAS,aAAa;IAClB,OAAO,KAAK,CAAA;AAChB,CAAC;AACD,SAAS,aAAa,CAAC,WAAmB;IACtC,IAAI,KAAK,KAAK,WAAW,EAAE;QACvB,aAAa,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,KAAK,CAAC,CAAA;QAE/D,KAAK,GAAG,WAAW,CAAA;KACtB;AACL,CAAC;AACD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,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C,CAAA;AACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSubdomain.d.ts","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSubdomain.d.ts","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,SAAS,QAAiB,CAAA;AAEvC,wBAAgB,6BAA6B,SAM5C;AAED,wBAAgB,4BAA4B,WAe3C"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
const hostname_arr = window.location.hostname.split('.'); // fretex-dfsf.advoca.no
|
|
1
|
+
const hostname_arr = () => window.location.hostname.split('.'); // fretex-dfsf.advoca.no
|
|
2
2
|
function getSubdomain() {
|
|
3
3
|
let subdomain = '';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const host_arr = hostname_arr();
|
|
5
|
+
if (host_arr.length === 3 &&
|
|
6
|
+
host_arr[0] &&
|
|
7
|
+
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === host_arr[0])) {
|
|
8
|
+
subdomain = host_arr[0];
|
|
8
9
|
const subdomain_arr = subdomain.split('-');
|
|
9
10
|
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
10
11
|
subdomain = subdomain_arr[0];
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
else if (
|
|
14
|
-
subdomain =
|
|
14
|
+
else if (host_arr.length === 4 && host_arr[0]) {
|
|
15
|
+
subdomain = host_arr[0];
|
|
15
16
|
}
|
|
16
17
|
return subdomain;
|
|
17
18
|
}
|
|
@@ -23,13 +24,14 @@ export function redirectFromSubdomainToDomain() {
|
|
|
23
24
|
}
|
|
24
25
|
export function createDomainUrlFromSubdomain() {
|
|
25
26
|
let hostname = window.location.hostname.replace(subdomain, '');
|
|
27
|
+
const hostname_arr_length = hostname_arr().length;
|
|
26
28
|
//TODO first if statment will be removed in the future when we all asma will move to nested subdomains
|
|
27
|
-
if (
|
|
29
|
+
if (hostname_arr_length === 3) {
|
|
28
30
|
;
|
|
29
31
|
(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
30
32
|
(hostname.startsWith('.') && (hostname = 'www' + hostname));
|
|
31
33
|
}
|
|
32
|
-
else if (
|
|
34
|
+
else if (hostname_arr_length === 4) {
|
|
33
35
|
// deepcode ignore GlobalReplacementRegex: <this is intended>
|
|
34
36
|
hostname = hostname.replace('.', '');
|
|
35
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSubdomain.js","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,
|
|
1
|
+
{"version":3,"file":"getSubdomain.js","sourceRoot":"","sources":["../../src/helpers/getSubdomain.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAC,wBAAwB;AAEvF,SAAS,YAAY;IACjB,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,MAAM,QAAQ,GAAG,YAAY,EAAE,CAAA;IAC/B,IACI,QAAQ,CAAC,MAAM,KAAK,CAAC;QACrB,QAAQ,CAAC,CAAC,CAAC;QACX,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAC/E;QACE,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QAEvB,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE1C,IAAI,aA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Q,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAA;IAE1C,OAAO,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAChE,CAAC"}
|
package/package.json
CHANGED
|
@@ -50,10 +50,12 @@ export async function checkForRegisteredSubdomain({
|
|
|
50
50
|
redirect_if_not_exists = true,
|
|
51
51
|
setSelectedCustomer,
|
|
52
52
|
srvAuthGet,
|
|
53
|
+
logos,
|
|
53
54
|
}: {
|
|
54
55
|
redirect_if_not_exists?: boolean
|
|
55
56
|
setSelectedCustomer?: (customer_id: string) => void
|
|
56
57
|
srvAuthGet: <R>(url: string, headers?: Record<string, string> | undefined) => Promise<R>
|
|
58
|
+
logos: { fretexLogo: string; carasentLogo: string }
|
|
57
59
|
}) {
|
|
58
60
|
const res = await srvAuthGet<{ id?: string; theme?: string }>(
|
|
59
61
|
'/check?context=subdomain',
|
|
@@ -68,10 +70,51 @@ export async function checkForRegisteredSubdomain({
|
|
|
68
70
|
setSelectedCustomer?.(res.id)
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
if (res?.theme) {
|
|
74
|
+
setTheme(res.theme)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
appendAsmaLogoLink(getTheme(), logos)
|
|
72
78
|
|
|
73
79
|
if (!!!res?.id && redirect_if_not_exists) {
|
|
74
80
|
redirectFromSubdomainToDomain()
|
|
75
81
|
}
|
|
76
|
-
|
|
82
|
+
|
|
83
|
+
const { unregister } = onThemeChange(({ theme }) => {
|
|
84
|
+
appendAsmaLogoLink(theme, logos)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
return [!!res?.id, unregister] as [registeredSubdomain: boolean, unregister: () => void]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function appendAsmaLogoLink(
|
|
91
|
+
theme = 'default',
|
|
92
|
+
{ carasentLogo, fretexLogo }: { fretexLogo: string; carasentLogo: string },
|
|
93
|
+
) {
|
|
94
|
+
const body = document.body!
|
|
95
|
+
|
|
96
|
+
body.dataset['theme'] = theme
|
|
97
|
+
|
|
98
|
+
document.getElementById('asma-theme-link')?.remove()
|
|
99
|
+
|
|
100
|
+
const link = document.createElement('link')
|
|
101
|
+
|
|
102
|
+
link.setAttribute('id', 'asma-logo-link')
|
|
103
|
+
|
|
104
|
+
if (theme === 'fretex') {
|
|
105
|
+
document.title = 'Fretex'
|
|
106
|
+
link.setAttribute('href', fretexLogo)
|
|
107
|
+
} else {
|
|
108
|
+
document.title = 'Carasent'
|
|
109
|
+
|
|
110
|
+
link.setAttribute('href', carasentLogo)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
link.setAttribute('rel', 'icon')
|
|
114
|
+
|
|
115
|
+
link.setAttribute('type', 'image/png')
|
|
116
|
+
|
|
117
|
+
link.setAttribute('sizes', '32x32')
|
|
118
|
+
|
|
119
|
+
document.head.appendChild(link)
|
|
77
120
|
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
const hostname_arr = window.location.hostname.split('.')// fretex-dfsf.advoca.no
|
|
1
|
+
const hostname_arr = () => window.location.hostname.split('.') // fretex-dfsf.advoca.no
|
|
2
2
|
|
|
3
3
|
function getSubdomain() {
|
|
4
|
-
|
|
5
4
|
let subdomain = ''
|
|
6
|
-
|
|
5
|
+
const host_arr = hostname_arr()
|
|
7
6
|
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub ===
|
|
7
|
+
host_arr.length === 3 &&
|
|
8
|
+
host_arr[0] &&
|
|
9
|
+
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === host_arr[0])
|
|
11
10
|
) {
|
|
12
|
-
subdomain =
|
|
11
|
+
subdomain = host_arr[0]
|
|
13
12
|
|
|
14
13
|
const subdomain_arr = subdomain.split('-')
|
|
15
14
|
|
|
16
15
|
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
17
16
|
subdomain = subdomain_arr[0]
|
|
18
17
|
}
|
|
19
|
-
}else if(
|
|
20
|
-
subdomain =
|
|
18
|
+
} else if (host_arr.length === 4 && host_arr[0]) {
|
|
19
|
+
subdomain = host_arr[0]
|
|
21
20
|
}
|
|
22
21
|
return subdomain
|
|
23
22
|
}
|
|
@@ -34,18 +33,17 @@ export function redirectFromSubdomainToDomain() {
|
|
|
34
33
|
|
|
35
34
|
export function createDomainUrlFromSubdomain() {
|
|
36
35
|
let hostname = window.location.hostname.replace(subdomain, '')
|
|
36
|
+
const hostname_arr_length = hostname_arr().length
|
|
37
37
|
//TODO first if statment will be removed in the future when we all asma will move to nested subdomains
|
|
38
|
-
if(
|
|
39
|
-
|
|
38
|
+
if (hostname_arr_length === 3) {
|
|
40
39
|
;(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
41
40
|
(hostname.startsWith('.') && (hostname = 'www' + hostname))
|
|
42
|
-
}
|
|
43
|
-
else if(hostname_arr.length === 4){
|
|
41
|
+
} else if (hostname_arr_length === 4) {
|
|
44
42
|
// deepcode ignore GlobalReplacementRegex: <this is intended>
|
|
45
|
-
hostname = hostname.replace('.','')
|
|
43
|
+
hostname = hostname.replace('.', '')
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
const { port, protocol } = window.location
|
|
49
47
|
|
|
50
48
|
return protocol + '//' + hostname + (port ? `:${port}` : '')
|
|
51
|
-
}
|
|
49
|
+
}
|