@das-fed/upf-utils 6.4.0-dev.290 → 6.4.0-dev.292

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.
Files changed (68) hide show
  1. package/api-services/es5.js +1016 -1014
  2. package/api-services/index.js +775 -771
  3. package/api-services/index.js.gz +0 -0
  4. package/api-services/modules/app-manage/es5.js +1110 -1122
  5. package/api-services/modules/app-manage/index.js +918 -936
  6. package/api-services/modules/app-manage/index.js.gz +0 -0
  7. package/api-services/modules/authentication/es5.js +1122 -1132
  8. package/api-services/modules/authentication/index.js +930 -944
  9. package/api-services/modules/authentication/index.js.gz +0 -0
  10. package/api-services/modules/bems/es5.js +1153 -1141
  11. package/api-services/modules/bems/index.js +964 -946
  12. package/api-services/modules/bems/index.js.gz +0 -0
  13. package/api-services/modules/duty-manage/es5.js +1120 -1108
  14. package/api-services/modules/duty-manage/index.js +935 -917
  15. package/api-services/modules/duty-manage/index.js.gz +0 -0
  16. package/api-services/modules/enterpriseright/es5.js +857 -860
  17. package/api-services/modules/enterpriseright/index.js +670 -674
  18. package/api-services/modules/enterpriseright/index.js.gz +0 -0
  19. package/api-services/modules/file/es5.js +1266 -1275
  20. package/api-services/modules/file/index.js +1026 -1040
  21. package/api-services/modules/file/index.js.gz +0 -0
  22. package/api-services/modules/gateway-edge/es5.js +1134 -1122
  23. package/api-services/modules/gateway-edge/index.js +948 -930
  24. package/api-services/modules/gateway-edge/index.js.gz +0 -0
  25. package/api-services/modules/iot/es5.js +1241 -1229
  26. package/api-services/modules/iot/index.js +1039 -1021
  27. package/api-services/modules/iot/index.js.gz +0 -0
  28. package/api-services/modules/knowledge/es5.js +1134 -1122
  29. package/api-services/modules/knowledge/index.js +948 -930
  30. package/api-services/modules/knowledge/index.js.gz +0 -0
  31. package/api-services/modules/link/es5.js +860 -857
  32. package/api-services/modules/link/index.js +674 -670
  33. package/api-services/modules/link/index.js.gz +0 -0
  34. package/api-services/modules/platformManage/es5.js +1238 -1226
  35. package/api-services/modules/platformManage/index.js +1032 -1014
  36. package/api-services/modules/platformManage/index.js.gz +0 -0
  37. package/api-services/modules/super-admin/es5.js +1128 -1137
  38. package/api-services/modules/super-admin/index.js +935 -949
  39. package/api-services/modules/super-admin/index.js.gz +0 -0
  40. package/api-services/modules/supplier/es5.js +1114 -1126
  41. package/api-services/modules/supplier/index.js +920 -938
  42. package/api-services/modules/supplier/index.js.gz +0 -0
  43. package/api-services/modules/supplychain-manage/es5.js +1134 -1122
  44. package/api-services/modules/supplychain-manage/index.js +948 -930
  45. package/api-services/modules/supplychain-manage/index.js.gz +0 -0
  46. package/api-services/modules/systemConfiguration/es5.js +1122 -1134
  47. package/api-services/modules/systemConfiguration/index.js +930 -948
  48. package/api-services/modules/systemConfiguration/index.js.gz +0 -0
  49. package/api-services/src/create-service/es5.js +1120 -1132
  50. package/api-services/src/create-service/index.js +929 -947
  51. package/api-services/src/create-service/index.js.gz +0 -0
  52. package/browser-importmap.json +40 -0
  53. package/browser.d.ts +16 -0
  54. package/browser.js +267 -0
  55. package/browser.js.gz +0 -0
  56. package/common-info/es5.js +1293 -1281
  57. package/common-info/getPermissionMethod/es5.js +1388 -1376
  58. package/common-info/getPermissionMethod/index.js +1155 -1137
  59. package/common-info/getPermissionMethod/index.js.gz +0 -0
  60. package/common-info/index.js +1073 -1055
  61. package/common-info/index.js.gz +0 -0
  62. package/package.json +7 -7
  63. package/realtime-connection/es5.d.ts +12 -1
  64. package/realtime-connection/es5.js +205 -129
  65. package/realtime-connection/index.d.ts +12 -1
  66. package/realtime-connection/index.js +139 -91
  67. package/realtime-connection/index.js.gz +0 -0
  68. package/release-meta.json +4 -4
@@ -1,15 +1,15 @@
1
- import { getConfig as c } from "@das-fed/upf-utils/config";
2
- import { objectToUrlparams as h } from "@das-fed/upf-utils/common-tools";
3
- const l = 3e3, u = 3e4, m = () => {
4
- const i = c(), t = i.wsBaseURL || i.baseURL || location.origin;
5
- return String(t || "").replace(/^https:/i, "wss:").replace(/^http:/i, "ws:").replace(/\/+$/, "");
6
- }, d = (i) => /^wss?:\/\//i.test(i), f = (i) => /^https?:\/\//i.test(i), p = (i, t) => {
7
- const e = String(i || "").trim(), s = d(e) ? e : f(e) ? e.replace(/^https:/i, "wss:").replace(/^http:/i, "ws:") : `${m()}${e.startsWith("/") ? e : `/${e}`}`, r = h(t);
8
- return r ? `${s}${s.includes("?") ? "&" : "?"}${r}` : s;
9
- }, T = (i, t) => t ? (Array.isArray(t) ? t : [t]).includes(String(i ?? "")) : !1, b = (i) => typeof i.data == "string" ? JSON.parse(i.data) : i.data;
10
- class S {
11
- constructor(t) {
12
- this.ws = null, this.state = "idle", this.heartbeatTimer = null, this.heartbeatTimeoutTimer = null, this.reconnectTimer = null, this.reconnectAttempts = 0, this.manualClosed = !1, this.started = !1, this.lastHeartbeatAck = !0, this.options = t, this.handleOnline = this.handleOnline.bind(this), this.handleOffline = this.handleOffline.bind(this);
1
+ import { getConfig as l } from "@das-fed/upf-utils/config";
2
+ import { objectToUrlparams as u } from "@das-fed/upf-utils/common-tools";
3
+ const m = 3e3, d = 3e4, f = 2147483647, p = () => {
4
+ const n = l(), e = n.wsBaseURL || n.baseURL || location.origin;
5
+ return String(e || "").replace(/^https:/i, "wss:").replace(/^http:/i, "ws:").replace(/\/+$/, "");
6
+ }, T = (n) => /^wss?:\/\//i.test(n), S = (n) => /^https?:\/\//i.test(n), g = (n, e) => {
7
+ const t = String(n || "").trim(), s = T(t) ? t : S(t) ? t.replace(/^https:/i, "wss:").replace(/^http:/i, "ws:") : `${p()}${t.startsWith("/") ? t : `/${t}`}`, i = u(e);
8
+ return i ? `${s}${s.includes("?") ? "&" : "?"}${i}` : s;
9
+ }, b = (n, e) => e ? (Array.isArray(e) ? e : [e]).includes(String(n ?? "")) : !1, w = (n) => (Array.isArray(n) || typeof n == "string") && n.length > 0, c = (n) => Number.isFinite(n) && n >= 1 && n <= f, k = (n) => typeof n.data == "string" ? JSON.parse(n.data) : n.data;
10
+ class y {
11
+ constructor(e) {
12
+ this.ws = null, this.state = "idle", this.heartbeatTimer = null, this.heartbeatTimeoutTimer = null, this.reconnectTimer = null, this.reconnectAttempts = 0, this.manualClosed = !1, this.started = !1, this.opening = !1, this.openVersion = 0, this.heartbeatSequence = 0, this.options = e, this.handleOnline = this.handleOnline.bind(this), this.handleOffline = this.handleOffline.bind(this);
13
13
  }
14
14
  /** 获取当前连接状态,供业务显示或调试兜底使用。 */
15
15
  getState() {
@@ -17,7 +17,7 @@ class S {
17
17
  }
18
18
  /** 建立连接;重复调用不会创建多个活动 WebSocket。 */
19
19
  async connect() {
20
- if (!(this.started && (this.state === "connecting" || this.state === "open" || this.state === "reconnecting"))) {
20
+ if (!(this.started && (this.state === "waiting-token" || this.state === "connecting" || this.state === "open" || this.state === "reconnecting"))) {
21
21
  if (this.started = !0, this.manualClosed = !1, typeof WebSocket > "u") {
22
22
  this.setState("unsupported");
23
23
  return;
@@ -26,29 +26,47 @@ class S {
26
26
  }
27
27
  }
28
28
  /** 仅在连接已打开时发送消息,失败时返回 false。 */
29
- send(t) {
30
- var e;
31
- return ((e = this.ws) == null ? void 0 : e.readyState) !== WebSocket.OPEN ? !1 : (this.ws.send(t), !0);
29
+ send(e) {
30
+ const t = this.ws;
31
+ if (!t || t.readyState !== WebSocket.OPEN) return !1;
32
+ try {
33
+ return t.send(e), !0;
34
+ } catch {
35
+ return !1;
36
+ }
32
37
  }
33
38
  /** 主动关闭连接,并清理心跳、重连和网络监听。 */
34
39
  close() {
35
- this.manualClosed = !0, this.started = !1, this.clearTimers(), this.removeNetworkListeners(), this.closeSocket(), this.setState("closed");
40
+ this.manualClosed = !0, this.started = !1, this.cancelPendingOpen(), this.clearTimers(), this.removeNetworkListeners(), this.closeSocket(), this.setState("closed");
36
41
  }
37
42
  async openSocket() {
38
- var s, r;
39
- if (this.manualClosed) return;
40
- this.clearReconnectTimer(), this.closeSocket(), this.setState(this.reconnectAttempts > 0 ? "reconnecting" : "connecting");
41
- const t = { ...this.options.params || {} }, e = await this.resolveToken();
42
- if (this.options.tokenProvider && !e) {
43
- this.scheduleReconnect("waiting-token");
43
+ var i, o;
44
+ if (!this.started || this.manualClosed || this.opening) return;
45
+ if (typeof navigator < "u" && navigator.onLine === !1) {
46
+ this.setState(this.reconnectAttempts > 0 ? "reconnecting" : "waiting-token");
44
47
  return;
45
48
  }
46
- e && (t[this.options.tokenParamName || "access_token"] = e);
47
- try {
48
- const n = new WebSocket(p(this.options.url, t));
49
- this.ws = n, n.onopen = (o) => this.handleOpen(o), n.onmessage = (o) => this.handleMessage(o), n.onclose = (o) => this.handleClose(o), n.onerror = (o) => this.handleError(o);
50
- } catch (n) {
51
- (r = (s = this.options).onInvalidMessage) == null || r.call(s, n, {}), this.scheduleReconnect();
49
+ const e = ++this.openVersion;
50
+ this.opening = !0, this.clearReconnectTimer(), this.clearHeartbeatTimers(), this.closeSocket(), this.setState(this.reconnectAttempts > 0 ? "reconnecting" : "connecting");
51
+ const t = { ...this.options.params || {} }, s = await this.resolveToken();
52
+ if (this.isCurrentOpen(e)) {
53
+ if (this.options.tokenProvider && !s) {
54
+ this.opening = !1, this.scheduleReconnect("waiting-token");
55
+ return;
56
+ }
57
+ s && (t[this.options.tokenParamName || "access_token"] = s);
58
+ try {
59
+ const r = new WebSocket(g(this.options.url, t));
60
+ if (!this.isCurrentOpen(e)) {
61
+ r.close();
62
+ return;
63
+ }
64
+ this.ws = r, r.onopen = (a) => this.handleOpen(r, a), r.onmessage = (a) => this.handleMessage(r, a), r.onclose = (a) => this.handleClose(r, a), r.onerror = (a) => this.handleError(r, a);
65
+ } catch (r) {
66
+ this.isCurrentOpen(e) && ((o = (i = this.options).onInvalidMessage) == null || o.call(i, r, {}), this.scheduleReconnect());
67
+ } finally {
68
+ this.openVersion === e && (this.opening = !1);
69
+ }
52
70
  }
53
71
  }
54
72
  async resolveToken() {
@@ -59,100 +77,130 @@ class S {
59
77
  return "";
60
78
  }
61
79
  }
62
- handleOpen(t) {
63
- var e, s;
64
- this.reconnectAttempts = 0, this.lastHeartbeatAck = !0, this.setState("open"), (s = (e = this.options).onOpen) == null || s.call(e, t), this.startHeartbeat();
80
+ handleOpen(e, t) {
81
+ var s, i;
82
+ this.isCurrentSocket(e) && (this.reconnectAttempts = 0, this.setState("open"), (i = (s = this.options).onOpen) == null || i.call(s, t), this.startHeartbeat());
65
83
  }
66
- handleMessage(t) {
67
- var e, s, r, n, o;
68
- if (T(t.data, (e = this.options.heartbeat) == null ? void 0 : e.response)) {
69
- this.lastHeartbeatAck = !0, this.clearHeartbeatTimeoutTimer();
70
- return;
71
- }
72
- try {
73
- const a = this.options.parser || b;
74
- (r = (s = this.options).onMessage) == null || r.call(s, a(t), t);
75
- } catch (a) {
76
- (o = (n = this.options).onInvalidMessage) == null || o.call(n, a, t);
84
+ handleMessage(e, t) {
85
+ var s, i, o, r, a;
86
+ if (this.isCurrentSocket(e)) {
87
+ if (b(t.data, (s = this.options.heartbeat) == null ? void 0 : s.response)) {
88
+ this.clearHeartbeatTimeoutTimer();
89
+ return;
90
+ }
91
+ try {
92
+ const h = this.options.parser || k;
93
+ (o = (i = this.options).onMessage) == null || o.call(i, h(t), t);
94
+ } catch (h) {
95
+ (a = (r = this.options).onInvalidMessage) == null || a.call(r, h, t);
96
+ }
77
97
  }
78
98
  }
79
- handleClose(t) {
80
- var e, s;
81
- if (this.clearHeartbeatTimers(), (s = (e = this.options).onClose) == null || s.call(e, t), this.manualClosed) {
82
- this.setState("closed");
83
- return;
99
+ handleClose(e, t) {
100
+ var s, i;
101
+ if (this.isCurrentSocket(e)) {
102
+ if (this.clearHeartbeatTimers(), this.ws = null, (i = (s = this.options).onClose) == null || i.call(s, t), this.manualClosed) {
103
+ this.setState("closed");
104
+ return;
105
+ }
106
+ this.scheduleReconnect();
84
107
  }
85
- this.scheduleReconnect();
86
108
  }
87
- handleError(t) {
88
- var e, s;
89
- (s = (e = this.options).onError) == null || s.call(e, t);
109
+ handleError(e, t) {
110
+ var s, i;
111
+ this.isCurrentSocket(e) && ((i = (s = this.options).onError) == null || i.call(s, t));
90
112
  }
113
+ /** 启动单实例心跳;等待应答期间不重复发送,避免 interval 与 timeout 竞争。 */
91
114
  startHeartbeat() {
92
- const t = this.options.heartbeat;
93
- !(t != null && t.message) || !t.interval || (this.clearHeartbeatTimers(), this.heartbeatTimer = setInterval(() => {
94
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
95
- if (t.timeout && !this.lastHeartbeatAck) {
96
- this.closeSocket(), this.scheduleReconnect();
115
+ const e = this.options.heartbeat, t = Number(e == null ? void 0 : e.interval);
116
+ if (!(e != null && e.message) || !c(t)) return;
117
+ const s = Number(e.timeout), i = w(e.response) && c(s);
118
+ this.clearHeartbeatTimers(), this.heartbeatTimer = setInterval(() => {
119
+ const o = this.ws;
120
+ if (!o || o.readyState !== WebSocket.OPEN || i && this.heartbeatTimeoutTimer !== null) return;
121
+ let r;
122
+ try {
123
+ r = typeof e.message == "function" ? e.message() : e.message;
124
+ } catch {
125
+ this.handleHeartbeatFailure(o);
97
126
  return;
98
127
  }
99
- const e = typeof t.message == "function" ? t.message() : t.message;
100
- this.lastHeartbeatAck = !1, this.send(e), t.timeout && (this.clearHeartbeatTimeoutTimer(), this.heartbeatTimeoutTimer = setTimeout(() => {
101
- this.lastHeartbeatAck || this.manualClosed || (this.closeSocket(), this.scheduleReconnect());
102
- }, t.timeout));
103
- }, t.interval));
104
- }
105
- scheduleReconnect(t = "reconnecting") {
106
- var n;
107
- if (this.manualClosed || !((n = this.options.reconnect) != null && n.enabled)) {
128
+ if (!this.send(r)) {
129
+ this.handleHeartbeatFailure(o);
130
+ return;
131
+ }
132
+ if (!i) return;
133
+ this.clearHeartbeatTimeoutTimer();
134
+ const a = this.heartbeatSequence;
135
+ this.heartbeatTimeoutTimer = setTimeout(() => {
136
+ this.heartbeatSequence !== a || this.manualClosed || !this.isCurrentSocket(o) || this.handleHeartbeatFailure(o);
137
+ }, s);
138
+ }, t);
139
+ }
140
+ /** 心跳发送或应答超时后,仅关闭当前连接并进入既有重连流程。 */
141
+ handleHeartbeatFailure(e) {
142
+ this.manualClosed || !this.isCurrentSocket(e) || (this.clearHeartbeatTimers(), this.closeSocket(), this.scheduleReconnect());
143
+ }
144
+ scheduleReconnect(e = "reconnecting") {
145
+ var o;
146
+ if (this.manualClosed || !((o = this.options.reconnect) != null && o.enabled)) {
108
147
  this.setState("closed");
109
148
  return;
110
149
  }
111
150
  if (typeof navigator < "u" && navigator.onLine === !1) {
112
- this.setState(t);
151
+ this.setState(e);
152
+ return;
153
+ }
154
+ if (this.reconnectTimer) {
155
+ this.setState(e);
113
156
  return;
114
157
  }
115
- const { maxAttempts: e, jitter: s } = this.options.reconnect;
116
- if (typeof e == "number" && e >= 0 && this.reconnectAttempts >= e) {
158
+ const { maxAttempts: t, jitter: s } = this.options.reconnect;
159
+ if (typeof t == "number" && t >= 0 && this.reconnectAttempts >= t) {
117
160
  this.setState("closed");
118
161
  return;
119
162
  }
120
163
  this.reconnectAttempts += 1;
121
- const r = this.getReconnectDelay();
122
- this.setState(t), this.clearReconnectTimer(), this.reconnectTimer = setTimeout(() => {
123
- if (s) {
124
- setTimeout(() => this.openSocket(), Math.floor(Math.random() * 300));
125
- return;
126
- }
127
- this.openSocket();
128
- }, r);
164
+ const i = this.getReconnectDelay();
165
+ this.setState(e), this.clearReconnectTimer(), this.reconnectTimer = setTimeout(() => {
166
+ this.reconnectTimer = null, this.openSocket();
167
+ }, i + (s ? Math.floor(Math.random() * 300) : 0));
129
168
  }
130
169
  getReconnectDelay() {
131
- const t = this.options.reconnect || { enabled: !1 }, e = t.delay || l, s = t.maxDelay || u;
132
- return Math.min(e * Math.pow(2, Math.max(0, this.reconnectAttempts - 1)), s);
170
+ const e = this.options.reconnect || { enabled: !1 }, t = e.delay || m, s = e.maxDelay || d;
171
+ return Math.min(t * Math.pow(2, Math.max(0, this.reconnectAttempts - 1)), s);
133
172
  }
134
173
  handleOnline() {
135
- !this.started || this.manualClosed || this.state === "open" || this.state === "connecting" || this.openSocket();
174
+ !this.started || this.manualClosed || this.opening || this.state === "open" || this.state === "connecting" || this.openSocket();
136
175
  }
137
176
  handleOffline() {
138
- this.manualClosed || (this.clearReconnectTimer(), this.closeSocket(), this.setState("reconnecting"));
177
+ this.manualClosed || (this.cancelPendingOpen(), this.clearTimers(), this.closeSocket(), this.setState("reconnecting"));
139
178
  }
140
- setState(t) {
141
- var e, s;
142
- this.state !== t && (this.state = t, (s = (e = this.options).onStateChange) == null || s.call(e, t));
179
+ setState(e) {
180
+ var t, s;
181
+ this.state !== e && (this.state = e, (s = (t = this.options).onStateChange) == null || s.call(t, e));
143
182
  }
144
183
  closeSocket() {
145
- const t = this.ws;
146
- t && (t.onopen = null, t.onmessage = null, t.onclose = null, t.onerror = null, (t.readyState === WebSocket.OPEN || t.readyState === WebSocket.CONNECTING) && t.close(), this.ws = null);
184
+ const e = this.ws;
185
+ e && (e.onopen = null, e.onmessage = null, e.onclose = null, e.onerror = null, (e.readyState === WebSocket.OPEN || e.readyState === WebSocket.CONNECTING) && e.close(), this.ws = null);
186
+ }
187
+ cancelPendingOpen() {
188
+ this.openVersion += 1, this.opening = !1;
189
+ }
190
+ isCurrentOpen(e) {
191
+ return this.started && !this.manualClosed && this.openVersion === e;
192
+ }
193
+ isCurrentSocket(e) {
194
+ return this.ws === e;
147
195
  }
148
196
  clearTimers() {
149
197
  this.clearHeartbeatTimers(), this.clearReconnectTimer();
150
198
  }
151
199
  clearHeartbeatTimers() {
152
- this.heartbeatTimer && clearInterval(this.heartbeatTimer), this.heartbeatTimer = null, this.clearHeartbeatTimeoutTimer();
200
+ this.heartbeatTimer !== null && clearInterval(this.heartbeatTimer), this.heartbeatTimer = null, this.clearHeartbeatTimeoutTimer();
153
201
  }
154
202
  clearHeartbeatTimeoutTimer() {
155
- this.heartbeatTimeoutTimer && clearTimeout(this.heartbeatTimeoutTimer), this.heartbeatTimeoutTimer = null;
203
+ this.heartbeatSequence += 1, this.heartbeatTimeoutTimer !== null && clearTimeout(this.heartbeatTimeoutTimer), this.heartbeatTimeoutTimer = null;
156
204
  }
157
205
  clearReconnectTimer() {
158
206
  this.reconnectTimer && clearTimeout(this.reconnectTimer), this.reconnectTimer = null;
@@ -161,8 +209,8 @@ class S {
161
209
  typeof window > "u" || (window.removeEventListener("online", this.handleOnline), window.removeEventListener("offline", this.handleOffline));
162
210
  }
163
211
  }
164
- const g = (i) => new S(i);
212
+ const A = (n) => new y(n);
165
213
  export {
166
- S as RealtimeSocketClient,
167
- g as createRealtimeSocketClient
214
+ y as RealtimeSocketClient,
215
+ A as createRealtimeSocketClient
168
216
  };
Binary file
package/release-meta.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "packageName": "@das-fed/upf-utils",
3
- "releaseVersion": "6.4.0-dev.290",
3
+ "releaseVersion": "6.4.0-dev.292",
4
4
  "distTag": "dev",
5
5
  "releaseType": "publish",
6
- "publishedAt": "2026-07-09T03:00:15.744Z",
6
+ "publishedAt": "2026-07-14T06:46:37.761Z",
7
7
  "sourceBranch": "dev",
8
- "sourceCommit": "35dd6e1ad7cc4a7a90b7c6e0018d58b993abc811",
9
- "gitTag": "upf-release/v6.4.0-dev.290",
8
+ "sourceCommit": "9766fa3af4bca90be90632cab0c7653f16f56bfe",
9
+ "gitTag": "upf-release/v6.4.0-dev.292",
10
10
  "gitRemote": "origin",
11
11
  "gitRemoteUrl": "http://gitlab.dasiot.cn/foundation/frontend/framework.git",
12
12
  "releaseStatus": "success"