@ray-js/lock-sdk 1.1.3-beta.3 → 1.1.3-beta.4
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/lib/unlock-method.js +20 -11
- package/lib/utils/publishDps.js +13 -7
- package/package.json +1 -1
package/lib/unlock-method.js
CHANGED
|
@@ -380,6 +380,24 @@ const monitoringAddReport = (option) => {
|
|
|
380
380
|
export const startAddUnlockMethod = async (params) => {
|
|
381
381
|
const { unlockMethodConfig, lockUserId, dpData, sn, addDpCode, addDpMap, addDpReportMap, dpId, } = await getUnlockMethodBase(params.type, params.userId);
|
|
382
382
|
isCancelAddUnlockMethod = false;
|
|
383
|
+
let addReportMonitoringStarted = false;
|
|
384
|
+
const startAddReportMonitoring = (total) => {
|
|
385
|
+
if (addReportMonitoringStarted) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
addReportMonitoringStarted = true;
|
|
389
|
+
monitoringAddReport({
|
|
390
|
+
timeout: params.timeout,
|
|
391
|
+
unlockMethodConfig,
|
|
392
|
+
total,
|
|
393
|
+
dpCode: addDpCode,
|
|
394
|
+
dpMap: addDpReportMap,
|
|
395
|
+
sn,
|
|
396
|
+
lockUserId,
|
|
397
|
+
userId: params.userId,
|
|
398
|
+
unlockDpId: dpId,
|
|
399
|
+
});
|
|
400
|
+
};
|
|
383
401
|
const res = await publishDps({
|
|
384
402
|
[addDpCode]: dpUtils.format(dpData, addDpMap),
|
|
385
403
|
}, {
|
|
@@ -400,17 +418,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
400
418
|
console.warn("AddPassword: An invalid sn may have been reported");
|
|
401
419
|
}
|
|
402
420
|
if (result.stage === 0) {
|
|
403
|
-
|
|
404
|
-
timeout: params.timeout,
|
|
405
|
-
unlockMethodConfig,
|
|
406
|
-
total: res.total,
|
|
407
|
-
dpCode: addDpCode,
|
|
408
|
-
dpMap: addDpReportMap,
|
|
409
|
-
sn,
|
|
410
|
-
lockUserId,
|
|
411
|
-
userId: params.userId,
|
|
412
|
-
unlockDpId: dpId,
|
|
413
|
-
});
|
|
421
|
+
startAddReportMonitoring(result.total);
|
|
414
422
|
}
|
|
415
423
|
return result;
|
|
416
424
|
}
|
|
@@ -421,6 +429,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
421
429
|
},
|
|
422
430
|
});
|
|
423
431
|
if (res.stage === 0) {
|
|
432
|
+
startAddReportMonitoring(res.total);
|
|
424
433
|
return { total: res.total };
|
|
425
434
|
}
|
|
426
435
|
if (res.stage === 0xfd) {
|
package/lib/utils/publishDps.js
CHANGED
|
@@ -34,17 +34,20 @@ export const publishDpsOnly = async (dpData) => {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
export const publishDps = async (dpData, option) => {
|
|
37
|
-
await publishDpsOnly(dpData);
|
|
38
37
|
const { timeout = 15000, checkReport } = option || {};
|
|
39
38
|
return new Promise((resolve, reject) => {
|
|
40
39
|
const codes = Object.keys(dpData);
|
|
41
40
|
const result = {};
|
|
41
|
+
let timer;
|
|
42
|
+
const cleanup = () => {
|
|
43
|
+
emitter.off(DPCHANGE, handleChangeDp);
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
};
|
|
42
46
|
const handleChangeDp = (dpCodes) => {
|
|
43
47
|
if (checkReport) {
|
|
44
48
|
const pass = checkReport(dpCodes);
|
|
45
49
|
if (pass) {
|
|
46
|
-
|
|
47
|
-
clearTimeout(timer);
|
|
50
|
+
cleanup();
|
|
48
51
|
resolve(typeof pass !== "boolean" ? pass : dpCodes);
|
|
49
52
|
}
|
|
50
53
|
}
|
|
@@ -57,16 +60,19 @@ export const publishDps = async (dpData, option) => {
|
|
|
57
60
|
}
|
|
58
61
|
});
|
|
59
62
|
if (codes.length === 0) {
|
|
60
|
-
|
|
61
|
-
clearTimeout(timer);
|
|
63
|
+
cleanup();
|
|
62
64
|
resolve(result);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
timer = setTimeout(() => {
|
|
69
|
+
cleanup();
|
|
68
70
|
reject(getError(1002));
|
|
69
71
|
}, timeout);
|
|
70
72
|
emitter.on(DPCHANGE, handleChangeDp);
|
|
73
|
+
publishDpsOnly(dpData).catch((error) => {
|
|
74
|
+
cleanup();
|
|
75
|
+
reject(error);
|
|
76
|
+
});
|
|
71
77
|
});
|
|
72
78
|
};
|