chayns-api 3.6.0-beta.3 → 3.6.0
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/cjs/hooks/useFunctionsWithOverrides.js +33 -23
- package/dist/cjs/plugins/TrustedDomainsPlugins.js +6 -7
- package/dist/cjs/utils/loadTrustedDomains.js +6 -1
- package/dist/esm/hooks/useFunctionsWithOverrides.js +34 -24
- package/dist/esm/plugins/TrustedDomainsPlugins.js +6 -7
- package/dist/esm/utils/loadTrustedDomains.js +6 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ var _reactCompilerRuntime = require("react-compiler-runtime");
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _useFunctions = require("./useFunctions");
|
|
10
10
|
const useFunctionsWithOverrides = overrideFactory => {
|
|
11
|
-
const $ = (0, _reactCompilerRuntime.c)(
|
|
11
|
+
const $ = (0, _reactCompilerRuntime.c)(15);
|
|
12
12
|
const base = (0, _useFunctions.useFunctions)();
|
|
13
13
|
let t0;
|
|
14
14
|
if ($[0] !== base || $[1] !== overrideFactory) {
|
|
@@ -22,52 +22,62 @@ const useFunctionsWithOverrides = overrideFactory => {
|
|
|
22
22
|
const overrides = t0;
|
|
23
23
|
let t1;
|
|
24
24
|
if ($[3] !== base || $[4] !== overrides) {
|
|
25
|
-
t1 =
|
|
26
|
-
base,
|
|
27
|
-
overrides
|
|
28
|
-
};
|
|
25
|
+
t1 = () => [...new Set([...Object.keys(base), ...Object.keys(overrides)])];
|
|
29
26
|
$[3] = base;
|
|
30
27
|
$[4] = overrides;
|
|
31
28
|
$[5] = t1;
|
|
32
29
|
} else {
|
|
33
30
|
t1 = $[5];
|
|
34
31
|
}
|
|
35
|
-
const
|
|
32
|
+
const [functionNames] = (0, _react.useState)(t1);
|
|
36
33
|
let t2;
|
|
37
|
-
let t3;
|
|
38
34
|
if ($[6] !== base || $[7] !== overrides) {
|
|
39
|
-
t2 =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
overrides
|
|
43
|
-
};
|
|
35
|
+
t2 = {
|
|
36
|
+
base,
|
|
37
|
+
overrides
|
|
44
38
|
};
|
|
45
|
-
t3 = [base, overrides];
|
|
46
39
|
$[6] = base;
|
|
47
40
|
$[7] = overrides;
|
|
48
41
|
$[8] = t2;
|
|
49
|
-
$[9] = t3;
|
|
50
42
|
} else {
|
|
51
43
|
t2 = $[8];
|
|
52
|
-
t3 = $[9];
|
|
53
44
|
}
|
|
54
|
-
(0, _react.
|
|
45
|
+
const stateRef = (0, _react.useRef)(t2);
|
|
46
|
+
let t3;
|
|
47
|
+
let t4;
|
|
48
|
+
if ($[9] !== base || $[10] !== overrides) {
|
|
49
|
+
t3 = () => {
|
|
50
|
+
stateRef.current = {
|
|
51
|
+
base,
|
|
52
|
+
overrides
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
t4 = [base, overrides];
|
|
56
|
+
$[9] = base;
|
|
57
|
+
$[10] = overrides;
|
|
58
|
+
$[11] = t3;
|
|
59
|
+
$[12] = t4;
|
|
60
|
+
} else {
|
|
61
|
+
t3 = $[11];
|
|
62
|
+
t4 = $[12];
|
|
63
|
+
}
|
|
64
|
+
(0, _react.useEffect)(t3, t4);
|
|
55
65
|
let functions;
|
|
56
|
-
if ($[
|
|
66
|
+
if ($[13] !== functionNames) {
|
|
57
67
|
functions = {};
|
|
58
|
-
for (const key of
|
|
59
|
-
functions[key] = (...
|
|
68
|
+
for (const key of functionNames) {
|
|
69
|
+
functions[key] = (...t5) => {
|
|
60
70
|
var _stateRef$current$ove;
|
|
61
|
-
const args =
|
|
71
|
+
const args = t5;
|
|
62
72
|
const functionKey = key;
|
|
63
73
|
const implementation = (_stateRef$current$ove = stateRef.current.overrides[functionKey]) !== null && _stateRef$current$ove !== void 0 ? _stateRef$current$ove : stateRef.current.base[functionKey];
|
|
64
74
|
return implementation(...args);
|
|
65
75
|
};
|
|
66
76
|
}
|
|
67
|
-
$[
|
|
68
|
-
$[
|
|
77
|
+
$[13] = functionNames;
|
|
78
|
+
$[14] = functions;
|
|
69
79
|
} else {
|
|
70
|
-
functions = $[
|
|
80
|
+
functions = $[14];
|
|
71
81
|
}
|
|
72
82
|
return functions;
|
|
73
83
|
};
|
|
@@ -25,14 +25,13 @@ const TrustedDomainsPlugin = trustedDomains => {
|
|
|
25
25
|
name: 'trusted-domains',
|
|
26
26
|
async beforeRequest(args) {
|
|
27
27
|
const domains = await getTrustedDomains();
|
|
28
|
-
args.options.remotes.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
28
|
+
const remote = args.options.remotes.find(remote => (remote.alias || remote.name) === args.id);
|
|
29
|
+
if (remote && 'entry' in remote) {
|
|
30
|
+
const parsed = new URL(remote.entry);
|
|
31
|
+
if (!domains.some(domain => parsed.hostname.endsWith(domain))) {
|
|
32
|
+
throw new TrustedDomainsError(remote.entry);
|
|
34
33
|
}
|
|
35
|
-
}
|
|
34
|
+
}
|
|
36
35
|
return args;
|
|
37
36
|
}
|
|
38
37
|
};
|
|
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.loadTrustedDomains = void 0;
|
|
7
7
|
var _trustedDomains = require("../constants/trustedDomains");
|
|
8
8
|
const TRUSTED_DOMAINS_URL = 'https://service-rpc.chayns.net/ConfigurationSettings/TrustedDomains';
|
|
9
|
-
|
|
9
|
+
let trustedDomainsPromise;
|
|
10
|
+
const fetchTrustedDomains = async () => {
|
|
10
11
|
try {
|
|
11
12
|
var _AbortSignal$timeout, _AbortSignal;
|
|
12
13
|
const response = await fetch(TRUSTED_DOMAINS_URL, {
|
|
@@ -23,4 +24,8 @@ const loadTrustedDomains = async () => {
|
|
|
23
24
|
}
|
|
24
25
|
return _trustedDomains.DefaultTrustedDomains;
|
|
25
26
|
};
|
|
27
|
+
const loadTrustedDomains = () => {
|
|
28
|
+
trustedDomainsPromise !== null && trustedDomainsPromise !== void 0 ? trustedDomainsPromise : trustedDomainsPromise = fetchTrustedDomains();
|
|
29
|
+
return trustedDomainsPromise;
|
|
30
|
+
};
|
|
26
31
|
exports.loadTrustedDomains = loadTrustedDomains;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { c as _c } from "react-compiler-runtime";
|
|
2
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { useFunctions } from './useFunctions';
|
|
4
4
|
export const useFunctionsWithOverrides = overrideFactory => {
|
|
5
|
-
const $ = _c(
|
|
5
|
+
const $ = _c(15);
|
|
6
6
|
const base = useFunctions();
|
|
7
7
|
let t0;
|
|
8
8
|
if ($[0] !== base || $[1] !== overrideFactory) {
|
|
@@ -16,52 +16,62 @@ export const useFunctionsWithOverrides = overrideFactory => {
|
|
|
16
16
|
const overrides = t0;
|
|
17
17
|
let t1;
|
|
18
18
|
if ($[3] !== base || $[4] !== overrides) {
|
|
19
|
-
t1 =
|
|
20
|
-
base,
|
|
21
|
-
overrides
|
|
22
|
-
};
|
|
19
|
+
t1 = () => [...new Set([...Object.keys(base), ...Object.keys(overrides)])];
|
|
23
20
|
$[3] = base;
|
|
24
21
|
$[4] = overrides;
|
|
25
22
|
$[5] = t1;
|
|
26
23
|
} else {
|
|
27
24
|
t1 = $[5];
|
|
28
25
|
}
|
|
29
|
-
const
|
|
26
|
+
const [functionNames] = useState(t1);
|
|
30
27
|
let t2;
|
|
31
|
-
let t3;
|
|
32
28
|
if ($[6] !== base || $[7] !== overrides) {
|
|
33
|
-
t2 =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
overrides
|
|
37
|
-
};
|
|
29
|
+
t2 = {
|
|
30
|
+
base,
|
|
31
|
+
overrides
|
|
38
32
|
};
|
|
39
|
-
t3 = [base, overrides];
|
|
40
33
|
$[6] = base;
|
|
41
34
|
$[7] = overrides;
|
|
42
35
|
$[8] = t2;
|
|
43
|
-
$[9] = t3;
|
|
44
36
|
} else {
|
|
45
37
|
t2 = $[8];
|
|
46
|
-
t3 = $[9];
|
|
47
38
|
}
|
|
48
|
-
|
|
39
|
+
const stateRef = useRef(t2);
|
|
40
|
+
let t3;
|
|
41
|
+
let t4;
|
|
42
|
+
if ($[9] !== base || $[10] !== overrides) {
|
|
43
|
+
t3 = () => {
|
|
44
|
+
stateRef.current = {
|
|
45
|
+
base,
|
|
46
|
+
overrides
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
t4 = [base, overrides];
|
|
50
|
+
$[9] = base;
|
|
51
|
+
$[10] = overrides;
|
|
52
|
+
$[11] = t3;
|
|
53
|
+
$[12] = t4;
|
|
54
|
+
} else {
|
|
55
|
+
t3 = $[11];
|
|
56
|
+
t4 = $[12];
|
|
57
|
+
}
|
|
58
|
+
useEffect(t3, t4);
|
|
49
59
|
let functions;
|
|
50
|
-
if ($[
|
|
60
|
+
if ($[13] !== functionNames) {
|
|
51
61
|
functions = {};
|
|
52
|
-
for (const key of
|
|
53
|
-
functions[key] = (...
|
|
62
|
+
for (const key of functionNames) {
|
|
63
|
+
functions[key] = (...t5) => {
|
|
54
64
|
var _stateRef$current$ove;
|
|
55
|
-
const args =
|
|
65
|
+
const args = t5;
|
|
56
66
|
const functionKey = key;
|
|
57
67
|
const implementation = (_stateRef$current$ove = stateRef.current.overrides[functionKey]) !== null && _stateRef$current$ove !== void 0 ? _stateRef$current$ove : stateRef.current.base[functionKey];
|
|
58
68
|
return implementation(...args);
|
|
59
69
|
};
|
|
60
70
|
}
|
|
61
|
-
$[
|
|
62
|
-
$[
|
|
71
|
+
$[13] = functionNames;
|
|
72
|
+
$[14] = functions;
|
|
63
73
|
} else {
|
|
64
|
-
functions = $[
|
|
74
|
+
functions = $[14];
|
|
65
75
|
}
|
|
66
76
|
return functions;
|
|
67
77
|
};
|
|
@@ -21,14 +21,13 @@ export const TrustedDomainsPlugin = trustedDomains => {
|
|
|
21
21
|
name: 'trusted-domains',
|
|
22
22
|
async beforeRequest(args) {
|
|
23
23
|
const domains = await getTrustedDomains();
|
|
24
|
-
args.options.remotes.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
24
|
+
const remote = args.options.remotes.find(remote => (remote.alias || remote.name) === args.id);
|
|
25
|
+
if (remote && 'entry' in remote) {
|
|
26
|
+
const parsed = new URL(remote.entry);
|
|
27
|
+
if (!domains.some(domain => parsed.hostname.endsWith(domain))) {
|
|
28
|
+
throw new TrustedDomainsError(remote.entry);
|
|
30
29
|
}
|
|
31
|
-
}
|
|
30
|
+
}
|
|
32
31
|
return args;
|
|
33
32
|
}
|
|
34
33
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DefaultTrustedDomains } from '../constants/trustedDomains';
|
|
2
2
|
const TRUSTED_DOMAINS_URL = 'https://service-rpc.chayns.net/ConfigurationSettings/TrustedDomains';
|
|
3
|
-
|
|
3
|
+
let trustedDomainsPromise;
|
|
4
|
+
const fetchTrustedDomains = async () => {
|
|
4
5
|
try {
|
|
5
6
|
var _AbortSignal$timeout, _AbortSignal;
|
|
6
7
|
const response = await fetch(TRUSTED_DOMAINS_URL, {
|
|
@@ -16,4 +17,8 @@ export const loadTrustedDomains = async () => {
|
|
|
16
17
|
return DefaultTrustedDomains;
|
|
17
18
|
}
|
|
18
19
|
return DefaultTrustedDomains;
|
|
20
|
+
};
|
|
21
|
+
export const loadTrustedDomains = () => {
|
|
22
|
+
trustedDomainsPromise !== null && trustedDomainsPromise !== void 0 ? trustedDomainsPromise : trustedDomainsPromise = fetchTrustedDomains();
|
|
23
|
+
return trustedDomainsPromise;
|
|
19
24
|
};
|