@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.
- package/api-services/es5.js +1016 -1014
- package/api-services/index.js +775 -771
- package/api-services/index.js.gz +0 -0
- package/api-services/modules/app-manage/es5.js +1110 -1122
- package/api-services/modules/app-manage/index.js +918 -936
- package/api-services/modules/app-manage/index.js.gz +0 -0
- package/api-services/modules/authentication/es5.js +1122 -1132
- package/api-services/modules/authentication/index.js +930 -944
- package/api-services/modules/authentication/index.js.gz +0 -0
- package/api-services/modules/bems/es5.js +1153 -1141
- package/api-services/modules/bems/index.js +964 -946
- package/api-services/modules/bems/index.js.gz +0 -0
- package/api-services/modules/duty-manage/es5.js +1120 -1108
- package/api-services/modules/duty-manage/index.js +935 -917
- package/api-services/modules/duty-manage/index.js.gz +0 -0
- package/api-services/modules/enterpriseright/es5.js +857 -860
- package/api-services/modules/enterpriseright/index.js +670 -674
- package/api-services/modules/enterpriseright/index.js.gz +0 -0
- package/api-services/modules/file/es5.js +1266 -1275
- package/api-services/modules/file/index.js +1026 -1040
- package/api-services/modules/file/index.js.gz +0 -0
- package/api-services/modules/gateway-edge/es5.js +1134 -1122
- package/api-services/modules/gateway-edge/index.js +948 -930
- package/api-services/modules/gateway-edge/index.js.gz +0 -0
- package/api-services/modules/iot/es5.js +1241 -1229
- package/api-services/modules/iot/index.js +1039 -1021
- package/api-services/modules/iot/index.js.gz +0 -0
- package/api-services/modules/knowledge/es5.js +1134 -1122
- package/api-services/modules/knowledge/index.js +948 -930
- package/api-services/modules/knowledge/index.js.gz +0 -0
- package/api-services/modules/link/es5.js +860 -857
- package/api-services/modules/link/index.js +674 -670
- package/api-services/modules/link/index.js.gz +0 -0
- package/api-services/modules/platformManage/es5.js +1238 -1226
- package/api-services/modules/platformManage/index.js +1032 -1014
- package/api-services/modules/platformManage/index.js.gz +0 -0
- package/api-services/modules/super-admin/es5.js +1128 -1137
- package/api-services/modules/super-admin/index.js +935 -949
- package/api-services/modules/super-admin/index.js.gz +0 -0
- package/api-services/modules/supplier/es5.js +1114 -1126
- package/api-services/modules/supplier/index.js +920 -938
- package/api-services/modules/supplier/index.js.gz +0 -0
- package/api-services/modules/supplychain-manage/es5.js +1134 -1122
- package/api-services/modules/supplychain-manage/index.js +948 -930
- package/api-services/modules/supplychain-manage/index.js.gz +0 -0
- package/api-services/modules/systemConfiguration/es5.js +1122 -1134
- package/api-services/modules/systemConfiguration/index.js +930 -948
- package/api-services/modules/systemConfiguration/index.js.gz +0 -0
- package/api-services/src/create-service/es5.js +1120 -1132
- package/api-services/src/create-service/index.js +929 -947
- package/api-services/src/create-service/index.js.gz +0 -0
- package/browser-importmap.json +40 -0
- package/browser.d.ts +16 -0
- package/browser.js +267 -0
- package/browser.js.gz +0 -0
- package/common-info/es5.js +1293 -1281
- package/common-info/getPermissionMethod/es5.js +1388 -1376
- package/common-info/getPermissionMethod/index.js +1155 -1137
- package/common-info/getPermissionMethod/index.js.gz +0 -0
- package/common-info/index.js +1073 -1055
- package/common-info/index.js.gz +0 -0
- package/package.json +7 -7
- package/realtime-connection/es5.d.ts +12 -1
- package/realtime-connection/es5.js +205 -129
- package/realtime-connection/index.d.ts +12 -1
- package/realtime-connection/index.js +139 -91
- package/realtime-connection/index.js.gz +0 -0
- package/release-meta.json +4 -4
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { getConfig as
|
|
2
|
-
import { objectToUrlparams as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
return String(
|
|
6
|
-
},
|
|
7
|
-
const
|
|
8
|
-
return
|
|
9
|
-
},
|
|
10
|
-
class
|
|
11
|
-
constructor(
|
|
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.
|
|
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(
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
39
|
-
if (this.manualClosed) return;
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
64
|
-
this.
|
|
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
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
|
81
|
-
if (this.
|
|
82
|
-
this.
|
|
83
|
-
|
|
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
|
|
89
|
-
(
|
|
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
|
|
93
|
-
!(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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(
|
|
151
|
+
this.setState(e);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this.reconnectTimer) {
|
|
155
|
+
this.setState(e);
|
|
113
156
|
return;
|
|
114
157
|
}
|
|
115
|
-
const { maxAttempts:
|
|
116
|
-
if (typeof
|
|
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
|
|
122
|
-
this.setState(
|
|
123
|
-
|
|
124
|
-
|
|
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
|
|
132
|
-
return Math.min(
|
|
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.
|
|
177
|
+
this.manualClosed || (this.cancelPendingOpen(), this.clearTimers(), this.closeSocket(), this.setState("reconnecting"));
|
|
139
178
|
}
|
|
140
|
-
setState(
|
|
141
|
-
var
|
|
142
|
-
this.state !==
|
|
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
|
|
146
|
-
|
|
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
|
|
212
|
+
const A = (n) => new y(n);
|
|
165
213
|
export {
|
|
166
|
-
|
|
167
|
-
|
|
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.
|
|
3
|
+
"releaseVersion": "6.4.0-dev.292",
|
|
4
4
|
"distTag": "dev",
|
|
5
5
|
"releaseType": "publish",
|
|
6
|
-
"publishedAt": "2026-07-
|
|
6
|
+
"publishedAt": "2026-07-14T06:46:37.761Z",
|
|
7
7
|
"sourceBranch": "dev",
|
|
8
|
-
"sourceCommit": "
|
|
9
|
-
"gitTag": "upf-release/v6.4.0-dev.
|
|
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"
|