25 lines
957 B
JavaScript
25 lines
957 B
JavaScript
(function (root) {
|
|
'use strict';
|
|
const ids = new Map();
|
|
const key = (email) => String(email || '').trim().toLowerCase();
|
|
const changed = () => new Error('Account state changed. Close this dialog, reload accounts, and select the account again.');
|
|
|
|
// adpanel:account-retry-identity - a refreshed token cannot retarget a
|
|
// pending action to a replacement row that reuses its email.
|
|
root.ADPanelAccountTargets = {
|
|
update(accounts) {
|
|
ids.clear();
|
|
for (const account of accounts || []) {
|
|
if (Number.isSafeInteger(account.id) && account.id > 0) ids.set(key(account.email), account.id);
|
|
}
|
|
},
|
|
select(email) {
|
|
const id = ids.get(key(email));
|
|
return Object.freeze({ email: key(email), id: id || 0 });
|
|
},
|
|
payload(target, body) {
|
|
if (!target || !target.id || ids.get(target.email) !== target.id) throw changed();
|
|
return { ...body, expectedTargetId: target.id };
|
|
}
|
|
};
|
|
})(window); |