@wdywdy/electric-open-platform 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +585 -2
- package/dist/cjs/client.js +173 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/core/api.js +518 -0
- package/dist/cjs/core/api.js.map +1 -0
- package/dist/cjs/core/auth.js +293 -0
- package/dist/cjs/core/auth.js.map +1 -0
- package/dist/cjs/core/crypto.js +160 -0
- package/dist/cjs/core/crypto.js.map +1 -0
- package/dist/cjs/core/errors.js +114 -0
- package/dist/cjs/core/errors.js.map +1 -0
- package/dist/cjs/core/http.js +70 -0
- package/dist/cjs/core/http.js.map +1 -0
- package/dist/cjs/core/models.js +105 -0
- package/dist/cjs/core/models.js.map +1 -0
- package/dist/cjs/core/push.js +79 -0
- package/dist/cjs/core/push.js.map +1 -0
- package/dist/cjs/core/router.js +124 -0
- package/dist/cjs/core/router.js.map +1 -0
- package/dist/cjs/core/runtime.js +37 -0
- package/dist/cjs/core/runtime.js.map +1 -0
- package/dist/cjs/core/sign.js +75 -0
- package/dist/cjs/core/sign.js.map +1 -0
- package/dist/cjs/core/storage.js +152 -0
- package/dist/cjs/core/storage.js.map +1 -0
- package/dist/cjs/core/transport-fetch.js +57 -0
- package/dist/cjs/core/transport-fetch.js.map +1 -0
- package/dist/cjs/core/transport.js +41 -0
- package/dist/cjs/core/transport.js.map +1 -0
- package/dist/cjs/core/types.js +5 -0
- package/dist/cjs/core/types.js.map +1 -0
- package/dist/cjs/index.js +111 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/client.d.ts +73 -0
- package/dist/esm/client.js +169 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/core/api.d.ts +377 -0
- package/dist/esm/core/api.js +506 -0
- package/dist/esm/core/api.js.map +1 -0
- package/dist/esm/core/auth.d.ts +69 -0
- package/dist/esm/core/auth.js +289 -0
- package/dist/esm/core/auth.js.map +1 -0
- package/dist/esm/core/crypto.d.ts +24 -0
- package/dist/esm/core/crypto.js +154 -0
- package/dist/esm/core/crypto.js.map +1 -0
- package/dist/esm/core/errors.d.ts +86 -0
- package/dist/esm/core/errors.js +108 -0
- package/dist/esm/core/errors.js.map +1 -0
- package/dist/esm/core/http.d.ts +24 -0
- package/dist/esm/core/http.js +56 -0
- package/dist/esm/core/http.js.map +1 -0
- package/dist/esm/core/models.d.ts +441 -0
- package/dist/esm/core/models.js +102 -0
- package/dist/esm/core/models.js.map +1 -0
- package/dist/esm/core/push.d.ts +54 -0
- package/dist/esm/core/push.js +74 -0
- package/dist/esm/core/push.js.map +1 -0
- package/dist/esm/core/router.d.ts +44 -0
- package/dist/esm/core/router.js +120 -0
- package/dist/esm/core/router.js.map +1 -0
- package/dist/esm/core/runtime.d.ts +23 -0
- package/dist/esm/core/runtime.js +33 -0
- package/dist/esm/core/runtime.js.map +1 -0
- package/dist/esm/core/sign.d.ts +54 -0
- package/dist/esm/core/sign.js +67 -0
- package/dist/esm/core/sign.js.map +1 -0
- package/dist/esm/core/storage.d.ts +73 -0
- package/dist/esm/core/storage.js +141 -0
- package/dist/esm/core/storage.js.map +1 -0
- package/dist/esm/core/transport-fetch.d.ts +2 -0
- package/dist/esm/core/transport-fetch.js +54 -0
- package/dist/esm/core/transport-fetch.js.map +1 -0
- package/dist/esm/core/transport.d.ts +23 -0
- package/dist/esm/core/transport.js +36 -0
- package/dist/esm/core/transport.js.map +1 -0
- package/dist/esm/core/types.d.ts +76 -0
- package/dist/esm/core/types.js +2 -0
- package/dist/esm/core/types.js.map +1 -0
- package/dist/esm/index.d.ts +37 -0
- package/dist/esm/index.js +47 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +63 -4
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* OAuth2 lifecycle for the open platform.
|
|
6
|
+
*
|
|
7
|
+
* Two ways to obtain a token, both documented:
|
|
8
|
+
* 1. Redirect flow (`/oauth/authorize.as?client_id=…&response_type=code`) for a
|
|
9
|
+
* full web-login experience — the host app receives `?code=` and calls
|
|
10
|
+
* {@link AuthManager.exchangeCode}.
|
|
11
|
+
* 2. Headless flow (`POST /oauth/authverify2.as` with `uname`/`passwd`) — used
|
|
12
|
+
* by the plugin's `login()` convenience method.
|
|
13
|
+
*
|
|
14
|
+
* Once a token exists it is kept warm with the refresh endpoint, so a background
|
|
15
|
+
* poller never has to handle expiry itself.
|
|
16
|
+
*/
|
|
17
|
+
const errors_js_1 = require("./errors.js");
|
|
18
|
+
const http_js_1 = require("./http.js");
|
|
19
|
+
const sign_js_1 = require("./sign.js");
|
|
20
|
+
const types_js_1 = require("./types.js");
|
|
21
|
+
const MIN_EXPIRES_IN_SECONDS = 60;
|
|
22
|
+
class AuthManager {
|
|
23
|
+
constructor(store, config) {
|
|
24
|
+
this.tokens = null;
|
|
25
|
+
this.inflight = null;
|
|
26
|
+
this.timer = null;
|
|
27
|
+
this.store = store;
|
|
28
|
+
this.logger = config.logger;
|
|
29
|
+
this.config = {
|
|
30
|
+
appKey: config.appKey,
|
|
31
|
+
appSecret: config.appSecret,
|
|
32
|
+
redirectUri: config.redirectUri,
|
|
33
|
+
baseUrl: (config.baseUrl ?? types_js_1.DEFAULT_BASE_URL).replace(/\/+$/, ''),
|
|
34
|
+
timeoutMs: config.timeoutMs ?? 20000,
|
|
35
|
+
tokenRefreshSkewMs: config.tokenRefreshSkewMs ?? 60000,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Hydrates tokens persisted by a previous app session. */
|
|
39
|
+
async restore() {
|
|
40
|
+
const saved = await this.store.readTokens();
|
|
41
|
+
if (saved && saved.accessToken) {
|
|
42
|
+
this.tokens = saved;
|
|
43
|
+
if (!this.isExpired(saved))
|
|
44
|
+
this.scheduleRefresh();
|
|
45
|
+
else
|
|
46
|
+
this.tokens = null;
|
|
47
|
+
return this.tokens;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
get current() {
|
|
52
|
+
return this.tokens;
|
|
53
|
+
}
|
|
54
|
+
/** The redirect-flow login URL, for opening in a browser / InAppBrowser. */
|
|
55
|
+
getAuthorizeUrl(options = {}) {
|
|
56
|
+
const qs = (0, sign_js_1.encodeForm)({
|
|
57
|
+
client_id: this.config.appKey,
|
|
58
|
+
response_type: 'code',
|
|
59
|
+
redirect_uri: this.config.redirectUri,
|
|
60
|
+
...(options.state ? { state: options.state } : {}),
|
|
61
|
+
});
|
|
62
|
+
return `${this.config.baseUrl}/oauth/authorize.as?${qs}`;
|
|
63
|
+
}
|
|
64
|
+
/** Extracts `code` from a redirect URL such as `http://host/receive?code=abc`. */
|
|
65
|
+
static extractCode(url) {
|
|
66
|
+
const match = /[?&#]code=([^&#]+)/.exec(url);
|
|
67
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
68
|
+
}
|
|
69
|
+
/** Step 1 of the headless flow: POST `/oauth/authverify2.as` for a temporary code. */
|
|
70
|
+
async fetchCode(credentials) {
|
|
71
|
+
const body = (0, sign_js_1.encodeForm)({
|
|
72
|
+
response_type: 'code',
|
|
73
|
+
client_id: this.config.appKey,
|
|
74
|
+
redirect_uri: this.config.redirectUri,
|
|
75
|
+
uname: credentials.username,
|
|
76
|
+
passwd: credentials.password,
|
|
77
|
+
});
|
|
78
|
+
const res = await (0, http_js_1.postForm)({
|
|
79
|
+
url: `${this.config.baseUrl}/oauth/authverify2.as`,
|
|
80
|
+
body,
|
|
81
|
+
timeoutMs: this.config.timeoutMs,
|
|
82
|
+
});
|
|
83
|
+
const payload = res.data;
|
|
84
|
+
if (!payload || typeof payload !== 'object' || !payload.code || String(payload.success) !== 'true') {
|
|
85
|
+
throw new errors_js_1.ElectricOpenPlatformError(errors_js_1.TransportCodes.OAUTH, `获取授权码失败:${(payload && payload.message) || '账号或密码不正确'}`, { details: res.data });
|
|
86
|
+
}
|
|
87
|
+
this.logger?.({ type: 'token', message: '已获取临时授权码 code', at: new Date().toISOString() });
|
|
88
|
+
return payload.code;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Steps 1+2 in one call: headless login with username/password, then store the token.
|
|
92
|
+
* Concurrent calls share the same in-flight handshake.
|
|
93
|
+
*/
|
|
94
|
+
async loginWithPassword(username, password) {
|
|
95
|
+
const code = await this.fetchCode({ username, password });
|
|
96
|
+
return this.exchangeCode(code);
|
|
97
|
+
}
|
|
98
|
+
/** Step 2: exchange a code for an access token (`POST /oauth/token.as`). */
|
|
99
|
+
async exchangeCode(code) {
|
|
100
|
+
if (this.inflight)
|
|
101
|
+
return this.inflight;
|
|
102
|
+
this.inflight = this.doExchangeCode(code).finally(() => {
|
|
103
|
+
this.inflight = null;
|
|
104
|
+
});
|
|
105
|
+
return this.inflight;
|
|
106
|
+
}
|
|
107
|
+
async doExchangeCode(code) {
|
|
108
|
+
const clientSecret = (0, sign_js_1.signAuthCodeSecret)({
|
|
109
|
+
appKey: this.config.appKey,
|
|
110
|
+
appSecret: this.config.appSecret,
|
|
111
|
+
redirectUri: this.config.redirectUri,
|
|
112
|
+
code,
|
|
113
|
+
});
|
|
114
|
+
const body = (0, sign_js_1.encodeForm)({
|
|
115
|
+
client_id: this.config.appKey,
|
|
116
|
+
client_secret: clientSecret,
|
|
117
|
+
grant_type: 'authorization_code',
|
|
118
|
+
redirect_uri: this.config.redirectUri,
|
|
119
|
+
code,
|
|
120
|
+
});
|
|
121
|
+
const res = await (0, http_js_1.postForm)({
|
|
122
|
+
url: `${this.config.baseUrl}/oauth/token.as`,
|
|
123
|
+
body,
|
|
124
|
+
timeoutMs: this.config.timeoutMs,
|
|
125
|
+
});
|
|
126
|
+
return this.absorb(res.data, 'accessToken');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Returns a usable access token, renewing it first when it is within the skew
|
|
130
|
+
* window. Falls back to a full re-login when the refresh token is gone.
|
|
131
|
+
*/
|
|
132
|
+
async getAccessToken(credentials) {
|
|
133
|
+
if (this.tokens && !this.isExpired(this.tokens))
|
|
134
|
+
return this.tokens.accessToken;
|
|
135
|
+
if (this.inflight)
|
|
136
|
+
return (await this.inflight).accessToken;
|
|
137
|
+
if (this.tokens?.refreshToken) {
|
|
138
|
+
try {
|
|
139
|
+
return (await this.refresh()).accessToken;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
// A dead refresh token is indistinguishable from an expired session;
|
|
143
|
+
// drop it and fall through to a full login when credentials exist.
|
|
144
|
+
this.emit('error', `刷新 accessToken 失败:${err.message}`);
|
|
145
|
+
this.tokens = null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (credentials?.username && credentials.password) {
|
|
149
|
+
return (await this.loginWithPassword(credentials.username, credentials.password)).accessToken;
|
|
150
|
+
}
|
|
151
|
+
throw new errors_js_1.ElectricOpenPlatformError(errors_js_1.TransportCodes.NOT_CONFIGURED, 'accessToken 已过期,请重新登录');
|
|
152
|
+
}
|
|
153
|
+
/** `POST /oauth/refresh.as` */
|
|
154
|
+
async refresh() {
|
|
155
|
+
if (this.inflight)
|
|
156
|
+
return this.inflight;
|
|
157
|
+
this.inflight = this.doRefresh().finally(() => {
|
|
158
|
+
this.inflight = null;
|
|
159
|
+
});
|
|
160
|
+
return this.inflight;
|
|
161
|
+
}
|
|
162
|
+
async doRefresh() {
|
|
163
|
+
const refreshToken = this.tokens?.refreshToken;
|
|
164
|
+
if (!refreshToken) {
|
|
165
|
+
throw new errors_js_1.ElectricOpenPlatformError(errors_js_1.TransportCodes.OAUTH, '缺少 refreshToken,无法刷新');
|
|
166
|
+
}
|
|
167
|
+
const clientSecret = (0, sign_js_1.signRefreshSecret)({
|
|
168
|
+
appKey: this.config.appKey,
|
|
169
|
+
appSecret: this.config.appSecret,
|
|
170
|
+
redirectUri: this.config.redirectUri,
|
|
171
|
+
refreshToken,
|
|
172
|
+
});
|
|
173
|
+
const body = (0, sign_js_1.encodeForm)({
|
|
174
|
+
client_id: this.config.appKey,
|
|
175
|
+
client_secret: clientSecret,
|
|
176
|
+
grant_type: 'refresh_token',
|
|
177
|
+
redirect_uri: this.config.redirectUri,
|
|
178
|
+
refresh_token: refreshToken,
|
|
179
|
+
});
|
|
180
|
+
const res = await (0, http_js_1.postForm)({
|
|
181
|
+
url: `${this.config.baseUrl}/oauth/refresh.as`,
|
|
182
|
+
body,
|
|
183
|
+
timeoutMs: this.config.timeoutMs,
|
|
184
|
+
});
|
|
185
|
+
return this.absorb(res.data, 'refresh');
|
|
186
|
+
}
|
|
187
|
+
/** Invalidates the platform-side session? No such endpoint exists — clear locally. */
|
|
188
|
+
async logout() {
|
|
189
|
+
this.tokens = null;
|
|
190
|
+
this.clearTimer();
|
|
191
|
+
await this.store.clear();
|
|
192
|
+
this.emit('token', '已清除本地授权');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Converts a platform "token invalid" answer into a fresh access token.
|
|
196
|
+
*
|
|
197
|
+
* Prefers the refresh token (no credential round-trip); falls back to a full
|
|
198
|
+
* headless login when credentials were configured.
|
|
199
|
+
*/
|
|
200
|
+
async recover(credentials) {
|
|
201
|
+
if (this.tokens?.refreshToken) {
|
|
202
|
+
try {
|
|
203
|
+
return (await this.refresh()).accessToken;
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
this.emit('error', `refresh 失败,改用账号密码重新登录:${err.message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (credentials?.username && credentials.password) {
|
|
210
|
+
return (await this.loginWithPassword(credentials.username, credentials.password)).accessToken;
|
|
211
|
+
}
|
|
212
|
+
await this.invalidate();
|
|
213
|
+
throw new errors_js_1.ElectricOpenPlatformError(errors_js_1.TransportCodes.NOT_CONFIGURED, '会话已失效,请重新登录');
|
|
214
|
+
}
|
|
215
|
+
/** Called by the client after the platform answers with code `"2"`. */
|
|
216
|
+
async invalidate() {
|
|
217
|
+
this.tokens = null;
|
|
218
|
+
this.clearTimer();
|
|
219
|
+
await this.store.clear();
|
|
220
|
+
}
|
|
221
|
+
dispose() {
|
|
222
|
+
this.clearTimer();
|
|
223
|
+
}
|
|
224
|
+
absorb(payload, origin) {
|
|
225
|
+
const envelope = payload;
|
|
226
|
+
if (!envelope || typeof envelope !== 'object' || !envelope.data) {
|
|
227
|
+
throw new errors_js_1.ElectricOpenPlatformError(errors_js_1.TransportCodes.OAUTH, '授权响应格式异常', { details: payload });
|
|
228
|
+
}
|
|
229
|
+
if (envelope.code !== undefined && envelope.code !== errors_js_1.PlatformCodes.OK) {
|
|
230
|
+
throw new errors_js_1.ElectricOpenPlatformError(envelope.code, envelope.message || '授权失败', {
|
|
231
|
+
details: payload,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const d = envelope.data;
|
|
235
|
+
const accessToken = d.accessToken ?? d.access_token;
|
|
236
|
+
const refreshToken = d.refreshToken ?? d.refresh_token ?? '';
|
|
237
|
+
const rawExpires = d.expiresIn ?? d.expires_in;
|
|
238
|
+
const expiresIn = Number(rawExpires ?? 3600);
|
|
239
|
+
if (!accessToken) {
|
|
240
|
+
throw new errors_js_1.ElectricOpenPlatformError(errors_js_1.TransportCodes.OAUTH, '授权响应中缺少 accessToken', {
|
|
241
|
+
details: payload,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const ttlSeconds = Number.isFinite(expiresIn) && expiresIn > 0 ? expiresIn : 3600;
|
|
245
|
+
const tokens = {
|
|
246
|
+
accessToken,
|
|
247
|
+
refreshToken,
|
|
248
|
+
tokenType: (d.tokenType ?? 'BEARER').toUpperCase(),
|
|
249
|
+
expiresAt: Date.now() + Math.max(ttlSeconds, MIN_EXPIRES_IN_SECONDS) * 1000,
|
|
250
|
+
};
|
|
251
|
+
this.tokens = tokens;
|
|
252
|
+
this.scheduleRefresh();
|
|
253
|
+
void this.store.writeTokens(tokens);
|
|
254
|
+
this.emit('token', origin === 'refresh' ? 'accessToken 已刷新' : 'accessToken 已获取', {
|
|
255
|
+
expiresIn: ttlSeconds,
|
|
256
|
+
});
|
|
257
|
+
return tokens;
|
|
258
|
+
}
|
|
259
|
+
isExpired(tokens) {
|
|
260
|
+
return tokens.expiresAt - this.config.tokenRefreshSkewMs <= Date.now();
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Proactively refreshes shortly before expiry so that a 60 s poller never
|
|
264
|
+
* hits code `"2"`. Browsers throttle long timers, so the client *also* checks
|
|
265
|
+
* lazily on every request — belt and braces.
|
|
266
|
+
*/
|
|
267
|
+
scheduleRefresh() {
|
|
268
|
+
this.clearTimer();
|
|
269
|
+
if (!this.tokens?.refreshToken)
|
|
270
|
+
return;
|
|
271
|
+
const delay = this.tokens.expiresAt - this.config.tokenRefreshSkewMs - Date.now();
|
|
272
|
+
if (delay <= 0 || delay > 2 ** 31 - 1)
|
|
273
|
+
return;
|
|
274
|
+
this.timer = setTimeout(() => {
|
|
275
|
+
this.refresh().catch((err) => {
|
|
276
|
+
this.emit('error', `定时刷新失败:${err.message}`);
|
|
277
|
+
});
|
|
278
|
+
}, delay);
|
|
279
|
+
// Node/SSR safety: an unref'd timer must not keep the test process alive.
|
|
280
|
+
this.timer.unref?.();
|
|
281
|
+
}
|
|
282
|
+
clearTimer() {
|
|
283
|
+
if (this.timer) {
|
|
284
|
+
clearTimeout(this.timer);
|
|
285
|
+
this.timer = null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
emit(type, message, detail) {
|
|
289
|
+
this.logger?.({ type, message, detail, at: new Date().toISOString() });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.AuthManager = AuthManager;
|
|
293
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/core/auth.ts"],"names":[],"mappings":";;;AAAA;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kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAClF,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;YAAE,OAAO;QAC9C,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3B,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAW,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,KAAK,CAAC,CAAC;QACV,0EAA0E;QACzE,IAAI,CAAC,KAA2C,CAAC,KAAK,EAAE,EAAE,CAAC;IAC9D,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,IAAuB,EAAE,OAAe,EAAE,MAAgC;QACrF,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACzE,CAAC;CACF;AArTD,kCAqTC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Small, dependency-free crypto/time helpers.
|
|
4
|
+
*
|
|
5
|
+
* The plugin must stay framework free (no node:crypto, no js-sha1) because the
|
|
6
|
+
* exact same code runs inside a WebView, in the Vite demo page and in Node
|
|
7
|
+
* based unit tests.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.md5 = md5;
|
|
11
|
+
exports.formatTimestamp = formatTimestamp;
|
|
12
|
+
exports.formatAlarmTime = formatAlarmTime;
|
|
13
|
+
exports.randomId = randomId;
|
|
14
|
+
const HEX = '0123456789abcdef';
|
|
15
|
+
/**
|
|
16
|
+
* MD5 of the UTF-8 encoding of `input`, lowercase hex (32 chars).
|
|
17
|
+
*
|
|
18
|
+
* The platform specifies MD5 over the UTF-8 byte stream (see the Java reference
|
|
19
|
+
* implementation in the docs: `md.update(param.getBytes("utf-8"))`), so the
|
|
20
|
+
* conversion below must be done on UTF-8 bytes, not on code units.
|
|
21
|
+
*/
|
|
22
|
+
function md5(input) {
|
|
23
|
+
const bytes = utf8Bytes(input);
|
|
24
|
+
const words = toWords(bytes);
|
|
25
|
+
const digest = md5Words(words, bytes.length);
|
|
26
|
+
let out = '';
|
|
27
|
+
for (let i = 0; i < 4; i++) {
|
|
28
|
+
const word = digest[i];
|
|
29
|
+
for (let j = 0; j < 4; j++) {
|
|
30
|
+
out += HEX.charAt((word >>> (j * 8 + 4)) & 0x0f);
|
|
31
|
+
out += HEX.charAt((word >>> (j * 8)) & 0x0f);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function utf8Bytes(input) {
|
|
37
|
+
const out = [];
|
|
38
|
+
for (let i = 0; i < input.length; i++) {
|
|
39
|
+
let cp = input.charCodeAt(i);
|
|
40
|
+
if (cp >= 0xd800 && cp <= 0xdbff && i + 1 < input.length) {
|
|
41
|
+
const next = input.charCodeAt(i + 1);
|
|
42
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
43
|
+
cp = ((cp - 0xd800) << 10) + (next - 0xdc00) + 0x10000;
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (cp < 0x80) {
|
|
48
|
+
out.push(cp);
|
|
49
|
+
}
|
|
50
|
+
else if (cp < 0x800) {
|
|
51
|
+
out.push(0xc0 | (cp >> 6), 0x80 | (cp & 0x3f));
|
|
52
|
+
}
|
|
53
|
+
else if (cp < 0x10000) {
|
|
54
|
+
out.push(0xe0 | (cp >> 12), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
out.push(0xf0 | (cp >> 18), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
function toWords(bytes) {
|
|
63
|
+
const bitLen = bytes.length * 8;
|
|
64
|
+
const withPadding = bytes.slice();
|
|
65
|
+
withPadding.push(0x80);
|
|
66
|
+
while (withPadding.length % 64 !== 56)
|
|
67
|
+
withPadding.push(0);
|
|
68
|
+
// 64-bit little-endian length; JS numbers stop being exact above 2^53, which
|
|
69
|
+
// is far beyond any string we would ever sign.
|
|
70
|
+
withPadding.push(bitLen & 0xff, (bitLen >>> 8) & 0xff, (bitLen >>> 16) & 0xff, (bitLen >>> 24) & 0xff);
|
|
71
|
+
withPadding.push(0, 0, 0, 0);
|
|
72
|
+
const words = [];
|
|
73
|
+
for (let i = 0; i < withPadding.length; i += 4) {
|
|
74
|
+
words.push(withPadding[i] | (withPadding[i + 1] << 8) | (withPadding[i + 2] << 16) | (withPadding[i + 3] << 24));
|
|
75
|
+
}
|
|
76
|
+
return words;
|
|
77
|
+
}
|
|
78
|
+
const S = [
|
|
79
|
+
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9,
|
|
80
|
+
14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15,
|
|
81
|
+
21, 6, 10, 15, 21,
|
|
82
|
+
];
|
|
83
|
+
const K = (() => {
|
|
84
|
+
const k = [];
|
|
85
|
+
for (let i = 0; i < 64; i++)
|
|
86
|
+
k.push(Math.floor(Math.abs(Math.sin(i + 1)) * 0x100000000) | 0);
|
|
87
|
+
return k;
|
|
88
|
+
})();
|
|
89
|
+
function md5Words(words, byteLen) {
|
|
90
|
+
let a0 = 0x67452301;
|
|
91
|
+
let b0 = 0xefcdab89;
|
|
92
|
+
let c0 = 0x98badcfe;
|
|
93
|
+
let d0 = 0x10325476;
|
|
94
|
+
for (let chunk = 0; chunk < words.length; chunk += 16) {
|
|
95
|
+
const M = words.slice(chunk, chunk + 16);
|
|
96
|
+
let A = a0;
|
|
97
|
+
let B = b0;
|
|
98
|
+
let C = c0;
|
|
99
|
+
let D = d0;
|
|
100
|
+
for (let i = 0; i < 64; i++) {
|
|
101
|
+
let F;
|
|
102
|
+
let g;
|
|
103
|
+
if (i < 16) {
|
|
104
|
+
F = (B & C) | (~B & D);
|
|
105
|
+
g = i;
|
|
106
|
+
}
|
|
107
|
+
else if (i < 32) {
|
|
108
|
+
F = (D & B) | (~D & C);
|
|
109
|
+
g = (5 * i + 1) % 16;
|
|
110
|
+
}
|
|
111
|
+
else if (i < 48) {
|
|
112
|
+
F = B ^ C ^ D;
|
|
113
|
+
g = (3 * i + 5) % 16;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
F = C ^ (B | ~D);
|
|
117
|
+
g = (7 * i) % 16;
|
|
118
|
+
}
|
|
119
|
+
F = (F + A + K[i] + M[g]) | 0;
|
|
120
|
+
A = D;
|
|
121
|
+
D = C;
|
|
122
|
+
C = B;
|
|
123
|
+
B = (B + ((F << S[i]) | (F >>> (32 - S[i])))) | 0;
|
|
124
|
+
}
|
|
125
|
+
a0 = (a0 + A) | 0;
|
|
126
|
+
b0 = (b0 + B) | 0;
|
|
127
|
+
c0 = (c0 + C) | 0;
|
|
128
|
+
d0 = (d0 + D) | 0;
|
|
129
|
+
}
|
|
130
|
+
void byteLen;
|
|
131
|
+
return [a0, b0, c0, d0];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The platform's `timestamp` parameter: `yyyyMMddHHmmss` in **local time**
|
|
135
|
+
* (the docs say "当前时间截"), padded to two digits.
|
|
136
|
+
*/
|
|
137
|
+
function formatTimestamp(date = new Date()) {
|
|
138
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
139
|
+
return (String(date.getFullYear()) +
|
|
140
|
+
pad(date.getMonth() + 1) +
|
|
141
|
+
pad(date.getDate()) +
|
|
142
|
+
pad(date.getHours()) +
|
|
143
|
+
pad(date.getMinutes()) +
|
|
144
|
+
pad(date.getSeconds()));
|
|
145
|
+
}
|
|
146
|
+
/** Local `yyyy-MM-dd HH:mm` — the format GET_BOX_ALARM expects for start/end. */
|
|
147
|
+
function formatAlarmTime(date) {
|
|
148
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
149
|
+
return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` +
|
|
150
|
+
` ${pad(date.getHours())}:${pad(date.getMinutes())}`);
|
|
151
|
+
}
|
|
152
|
+
/** A stable, deterministic non-cryptographic id used for request correlation. */
|
|
153
|
+
function randomId(length = 12) {
|
|
154
|
+
let out = '';
|
|
155
|
+
const alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
156
|
+
for (let i = 0; i < length; i++)
|
|
157
|
+
out += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/core/crypto.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAWH,kBAaC;AAgHD,0CAUC;AAGD,0CAMC;AAGD,4BAKC;AAjKD,MAAM,GAAG,GAAG,kBAAkB,CAAC;AAE/B;;;;;;GAMG;AACH,SAAgB,GAAG,CAAC,KAAa;IAC/B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/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E,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,CACL,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE;QAC1E,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,CACrD,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,SAAgB,QAAQ,CAAC,MAAM,GAAG,EAAE;IAClC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,QAAQ,GAAG,sCAAsC,CAAC;IACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACrG,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error model for the Mtsci (snd02) open platform.
|
|
4
|
+
*
|
|
5
|
+
* Every failure — transport, OAuth or business return code — surfaces as an
|
|
6
|
+
* `ElectricOpenPlatformError` so callers can branch on `code` instead of
|
|
7
|
+
* parsing `message` strings.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ElectricOpenPlatformError = exports.TransportCodes = exports.PlatformCodes = void 0;
|
|
11
|
+
exports.isElectricOpenPlatformError = isElectricOpenPlatformError;
|
|
12
|
+
exports.describeCode = describeCode;
|
|
13
|
+
exports.PlatformCodes = {
|
|
14
|
+
OK: '0',
|
|
15
|
+
NOT_LOGGED_IN: '-1',
|
|
16
|
+
FAILED: '1',
|
|
17
|
+
TOKEN_EXPIRED: '2',
|
|
18
|
+
BOX_OFFLINE: '1001',
|
|
19
|
+
ILLEGAL_PARAM: '1002',
|
|
20
|
+
ILLEGAL_OWNERSHIP: '1003',
|
|
21
|
+
REMOTE_CONTROL_FORBIDDEN: '1004',
|
|
22
|
+
INCOMPLETE_PROPERTY: '1005',
|
|
23
|
+
VERIFY_FAILED: '1006',
|
|
24
|
+
ALREADY_EXISTS: '1007',
|
|
25
|
+
NOT_FOUND: '1008',
|
|
26
|
+
OVER_LIMIT: '1009',
|
|
27
|
+
DUPLICATE_OPERATION: '1010',
|
|
28
|
+
};
|
|
29
|
+
const CODE_MESSAGES = {
|
|
30
|
+
'-1': '未登录或会话已过期',
|
|
31
|
+
'1': '接口调用失败',
|
|
32
|
+
'2': 'accessToken 已过期',
|
|
33
|
+
'1001': '设备不在线',
|
|
34
|
+
'1002': '不合法的参数',
|
|
35
|
+
'1003': '不合法的归属',
|
|
36
|
+
'1004': '不允许远程控制',
|
|
37
|
+
'1005': '不完整的设备属性',
|
|
38
|
+
'1006': '校验失败(例如密码错误)',
|
|
39
|
+
'1007': '资源已存在',
|
|
40
|
+
'1008': '相关资源不存在',
|
|
41
|
+
'1009': '资源超过最大限制',
|
|
42
|
+
'1010': '不能重复操作',
|
|
43
|
+
};
|
|
44
|
+
/** Failure classes that never come from the platform itself. */
|
|
45
|
+
exports.TransportCodes = {
|
|
46
|
+
/** The device could not reach the server at all. */
|
|
47
|
+
NETWORK: 'E_NETWORK',
|
|
48
|
+
/** The server answered with a non-2xx status. */
|
|
49
|
+
HTTP: 'E_HTTP',
|
|
50
|
+
/** Response body was not the expected JSON envelope. */
|
|
51
|
+
PARSE: 'E_PARSE',
|
|
52
|
+
/** The plugin was used before `configure()` / `login()`. */
|
|
53
|
+
NOT_CONFIGURED: 'E_NOT_CONFIGURED',
|
|
54
|
+
/** Local guard rail rejected the call before hitting the network. */
|
|
55
|
+
INVALID_ARGUMENT: 'E_INVALID_ARGUMENT',
|
|
56
|
+
/** OAuth handshake (authverify2 / token / refresh) failed. */
|
|
57
|
+
OAUTH: 'E_OAUTH',
|
|
58
|
+
/** Daily per-interface quota exhausted (platform rejects with "限额"). */
|
|
59
|
+
QUOTA: 'E_QUOTA',
|
|
60
|
+
/**
|
|
61
|
+
* The method exists but this appKey is not authorized for it.
|
|
62
|
+
*
|
|
63
|
+
* The platform reports unprovisioned methods in two misleading ways:
|
|
64
|
+
* - `接口名称(X)无效!`
|
|
65
|
+
* - `无效的接口方法参数签名!` — which looks like a signing bug but, verified
|
|
66
|
+
* against the live server, is what you get for a method that is not
|
|
67
|
+
* enabled for the key. Only treat it as this code when the same key's
|
|
68
|
+
* other calls succeed, which the client knows.
|
|
69
|
+
*/
|
|
70
|
+
NOT_PROVISIONED: 'E_NOT_PROVISIONED',
|
|
71
|
+
/** The call was aborted by the caller (AbortSignal). */
|
|
72
|
+
ABORTED: 'E_ABORTED',
|
|
73
|
+
};
|
|
74
|
+
class ElectricOpenPlatformError extends Error {
|
|
75
|
+
constructor(code, message, options = {}) {
|
|
76
|
+
super(message || CODE_MESSAGES[code] || `调用失败 (code=${code})`);
|
|
77
|
+
this.name = 'ElectricOpenPlatformError';
|
|
78
|
+
this.code = code;
|
|
79
|
+
this.method = options.method;
|
|
80
|
+
this.details = options.details;
|
|
81
|
+
this.httpStatus = options.httpStatus;
|
|
82
|
+
if (options.cause !== undefined)
|
|
83
|
+
this.cause = options.cause;
|
|
84
|
+
}
|
|
85
|
+
/** True when the platform says the access token must be renewed. */
|
|
86
|
+
get isTokenExpired() {
|
|
87
|
+
return this.code === exports.PlatformCodes.TOKEN_EXPIRED || this.code === exports.PlatformCodes.NOT_LOGGED_IN;
|
|
88
|
+
}
|
|
89
|
+
/** True when a retry after a short delay is likely to succeed. */
|
|
90
|
+
get isRetryable() {
|
|
91
|
+
return (this.code === exports.TransportCodes.NETWORK ||
|
|
92
|
+
this.code === exports.PlatformCodes.BOX_OFFLINE ||
|
|
93
|
+
(this.httpStatus !== undefined && this.httpStatus >= 500));
|
|
94
|
+
}
|
|
95
|
+
toJSON() {
|
|
96
|
+
return {
|
|
97
|
+
name: this.name,
|
|
98
|
+
code: this.code,
|
|
99
|
+
message: this.message,
|
|
100
|
+
method: this.method,
|
|
101
|
+
httpStatus: this.httpStatus,
|
|
102
|
+
details: this.details,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.ElectricOpenPlatformError = ElectricOpenPlatformError;
|
|
107
|
+
function isElectricOpenPlatformError(e) {
|
|
108
|
+
return e instanceof ElectricOpenPlatformError;
|
|
109
|
+
}
|
|
110
|
+
/** Human readable Chinese description for a platform code. */
|
|
111
|
+
function describeCode(code) {
|
|
112
|
+
return CODE_MESSAGES[String(code)] || `未知返回码 (${code})`;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/core/errors.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAwHH,kEAEC;AAGD,oCAEC;AA7HY,QAAA,aAAa,GAAG;IAC3B,EAAE,EAAE,GAAG;IACP,aAAa,EAAE,IAAI;IACnB,MAAM,EAAE,GAAG;IACX,aAAa,EAAE,GAAG;IAClB,WAAW,EAAE,MAAM;IACnB,aAAa,EAAE,MAAM;IACrB,iBAAiB,EAAE,MAAM;IACzB,wBAAwB,EAAE,MAAM;IAChC,mBAAmB,EAAE,MAAM;IAC3B,aAAa,EAAE,MAAM;IACrB,cAAc,EAAE,MAAM;IACtB,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,MAAM;IAClB,mBAAmB,EAAE,MAAM;CACnB,CAAC;AAIX,MAAM,aAAa,GAA2B;IAC5C,IAAI,EAAE,WAAW;IACjB,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,iBAAiB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