@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 CHANGED
@@ -46,7 +46,7 @@ try {
46
46
 
47
47
  ## 方式二:原生脚本(JSP、jQuery、纯 HTML 等无构建工具的页面)
48
48
 
49
- 与加载器等价的写法,加载结果相同:
49
+ 简化写法,只演示注入脚本与大版本校验;不含加载器的参数校验、同页单飞、失败后移除脚本以便重试等处理,有构建工具时优先使用方式一:
50
50
 
51
51
  ```html
52
52
  <div id="imk-panel"></div>
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, integrity].every((field) => typeof field === "string" && field !== "");
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("INVALID_ARGUMENT", "sdk \u9700\u5305\u542B\u975E\u7A7A\u7684 version\u3001url\u3001integrity");
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, integrity].every((field) => typeof field === "string" && field !== "");
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("INVALID_ARGUMENT", "sdk \u9700\u5305\u542B\u975E\u7A7A\u7684 version\u3001url\u3001integrity");
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztlink-imk/ztlinkcloud-agent-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "UNLICENSED",
5
5
  "description": "IMK 呼叫中心坐席 SDK 加载器与公共类型:按服务端下发的地址加载 SDK 运行时",
6
6
  "type": "module",