@ray-js/lock-sdk 1.1.3-beta.2 → 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 +22 -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
|
}, {
|
|
@@ -399,6 +417,9 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
399
417
|
if (result.sn !== sn) {
|
|
400
418
|
console.warn("AddPassword: An invalid sn may have been reported");
|
|
401
419
|
}
|
|
420
|
+
if (result.stage === 0) {
|
|
421
|
+
startAddReportMonitoring(result.total);
|
|
422
|
+
}
|
|
402
423
|
return result;
|
|
403
424
|
}
|
|
404
425
|
return false;
|
|
@@ -408,17 +429,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
408
429
|
},
|
|
409
430
|
});
|
|
410
431
|
if (res.stage === 0) {
|
|
411
|
-
|
|
412
|
-
timeout: params.timeout,
|
|
413
|
-
unlockMethodConfig,
|
|
414
|
-
total: res.total,
|
|
415
|
-
dpCode: addDpCode,
|
|
416
|
-
dpMap: addDpReportMap,
|
|
417
|
-
sn,
|
|
418
|
-
lockUserId,
|
|
419
|
-
userId: params.userId,
|
|
420
|
-
unlockDpId: dpId,
|
|
421
|
-
});
|
|
432
|
+
startAddReportMonitoring(res.total);
|
|
422
433
|
return { total: res.total };
|
|
423
434
|
}
|
|
424
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
|
};
|