@ztlink-imk/ztlinkcloud-agent-sdk 1.0.0 → 1.0.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/README.md +1 -1
- package/dist/index.cjs +6 -2
- package/dist/index.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -45,10 +45,11 @@ function majorOf(version) {
|
|
|
45
45
|
const match = /^(\d+)\.\d+\.\d+/.exec(version);
|
|
46
46
|
return match ? Number(match[1]) : null;
|
|
47
47
|
}
|
|
48
|
+
var INTEGRITY_PATTERN = /^sha384-[A-Za-z0-9+/]{64}$/;
|
|
48
49
|
function isDelivery(sdk) {
|
|
49
50
|
if (typeof sdk !== "object" || sdk === null) return false;
|
|
50
51
|
const { version, url, integrity } = sdk;
|
|
51
|
-
return [version, url
|
|
52
|
+
return [version, url].every((field) => typeof field === "string" && field !== "") && typeof integrity === "string" && INTEGRITY_PATTERN.test(integrity);
|
|
52
53
|
}
|
|
53
54
|
function adopt(runtime, sdk) {
|
|
54
55
|
if (majorOf(runtime.version) !== SUPPORTED_MAJOR)
|
|
@@ -84,7 +85,10 @@ function inject(sdk) {
|
|
|
84
85
|
}
|
|
85
86
|
async function loadAgentSdk(sdk) {
|
|
86
87
|
if (!isDelivery(sdk))
|
|
87
|
-
throw new AgentSdkLoadError(
|
|
88
|
+
throw new AgentSdkLoadError(
|
|
89
|
+
"INVALID_ARGUMENT",
|
|
90
|
+
"sdk \u9700\u5305\u542B\u975E\u7A7A\u7684 version\u3001url \u53CA sha384 \u683C\u5F0F\u7684 integrity"
|
|
91
|
+
);
|
|
88
92
|
if (majorOf(sdk.version) !== SUPPORTED_MAJOR)
|
|
89
93
|
throw new AgentSdkLoadError("MAJOR_VERSION_MISMATCH", "\u670D\u52A1\u7AEF\u4E0B\u53D1\u7684\u8FD0\u884C\u65F6\u5927\u7248\u672C\u4E0E\u52A0\u8F7D\u5668\u4E0D\u4E00\u81F4");
|
|
90
94
|
const loaded = window.ImkAgentSdk;
|
package/dist/index.js
CHANGED
|
@@ -18,10 +18,11 @@ function majorOf(version) {
|
|
|
18
18
|
const match = /^(\d+)\.\d+\.\d+/.exec(version);
|
|
19
19
|
return match ? Number(match[1]) : null;
|
|
20
20
|
}
|
|
21
|
+
var INTEGRITY_PATTERN = /^sha384-[A-Za-z0-9+/]{64}$/;
|
|
21
22
|
function isDelivery(sdk) {
|
|
22
23
|
if (typeof sdk !== "object" || sdk === null) return false;
|
|
23
24
|
const { version, url, integrity } = sdk;
|
|
24
|
-
return [version, url
|
|
25
|
+
return [version, url].every((field) => typeof field === "string" && field !== "") && typeof integrity === "string" && INTEGRITY_PATTERN.test(integrity);
|
|
25
26
|
}
|
|
26
27
|
function adopt(runtime, sdk) {
|
|
27
28
|
if (majorOf(runtime.version) !== SUPPORTED_MAJOR)
|
|
@@ -57,7 +58,10 @@ function inject(sdk) {
|
|
|
57
58
|
}
|
|
58
59
|
async function loadAgentSdk(sdk) {
|
|
59
60
|
if (!isDelivery(sdk))
|
|
60
|
-
throw new AgentSdkLoadError(
|
|
61
|
+
throw new AgentSdkLoadError(
|
|
62
|
+
"INVALID_ARGUMENT",
|
|
63
|
+
"sdk \u9700\u5305\u542B\u975E\u7A7A\u7684 version\u3001url \u53CA sha384 \u683C\u5F0F\u7684 integrity"
|
|
64
|
+
);
|
|
61
65
|
if (majorOf(sdk.version) !== SUPPORTED_MAJOR)
|
|
62
66
|
throw new AgentSdkLoadError("MAJOR_VERSION_MISMATCH", "\u670D\u52A1\u7AEF\u4E0B\u53D1\u7684\u8FD0\u884C\u65F6\u5927\u7248\u672C\u4E0E\u52A0\u8F7D\u5668\u4E0D\u4E00\u81F4");
|
|
63
67
|
const loaded = window.ImkAgentSdk;
|