},
max: {
major: 1,
- minor: 1,
+ minor: 2,
patch: 0,
},
};
}
+ static _almanacErrorThrow() {
+ throw new DBErrors.UnexpectedResult('did not update almanac');
+ }
+
+
async almanacGetAll(dbCtx) {
const _scope = _fileScope('almanacGetAll');
this.logger.debug(_scope, 'called');
try {
const result = await dbCtx.result(this.statement.almanacUpsert, { event, date: date ?? new Date() });
if (result.rowCount != 1) {
- throw new DBErrors.UnexpectedResult('did not upsert almanac event');
+ this.constructor._almanacErrorThrow();
}
} catch (e) {
this.logger.error(_scope, 'failed', { error: e, event, date });
}
- async authenticationUpsert(dbCtx, identifier, credential) {
+ async authenticationUpsert(dbCtx, identifier, credential, otpKey) {
const _scope = _fileScope('authenticationUpsert');
const scrubbedCredential = '*'.repeat((credential || '').length);
- this.logger.debug(_scope, 'called', { identifier, scrubbedCredential });
+ const scrubbedOTPKey = '*'.repeat((otpKey || '').length);
+ this.logger.debug(_scope, 'called', { identifier, scrubbedCredential, scrubbedOTPKey });
try {
- const result = await dbCtx.result(this.statement.authenticationUpsert, { identifier, credential });
+ const result = await dbCtx.result(this.statement.authenticationUpsert, { identifier, credential, otpKey });
if (result.rowCount != 1) {
throw new DBErrors.UnexpectedResult('did not upsert authentication');
}
+ } catch (e) {
+ this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential, scrubbedOTPKey });
+ throw e;
+ }
+ }
+
+
+ async authenticationUpdateOTPKey(dbCtx, identifier, otpKey = null) {
+ const _scope = _fileScope('authenticationUpdateOTPKey');
+ const scrubbedOTPKey = '*'.repeat((otpKey || '').length);
+ this.logger.debug(_scope, 'called', { identifier, scrubbedOTPKey });
+
+ try {
+ const result = await dbCtx.result(this.statement.authenticationUpdateOtpKey, { identifier, otpKey });
+ if (result.rowCount != 1) {
+ throw new DBErrors.UnexpectedResult('did not update otpKey');
+ }
+ } catch (e) {
+ this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedOTPKey });
+ throw e;
+ }
+ }
+
+
+ async authenticationUpdateCredential(dbCtx, identifier, credential) {
+ const _scope = _fileScope('authenticationUpdateCredential');
+ const scrubbedCredential = '*'.repeat((credential || '').length);
+ this.logger.debug(_scope, 'called', { identifier, scrubbedCredential });
+
+ try {
+ const result = await dbCtx.result(this.statement.authenticationUpdateCredential, { identifier, credential });
+ if (result.rowCount != 1) {
+ throw new DBErrors.UnexpectedResult('did not update credential');
+ }
} catch (e) {
this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential });
throw e;
}
+
}
// Update the last cleanup time
const result = await txCtx.result(this.statement.almanacUpsert, { event: almanacEvent, date: now });
if (result.rowCount != 1) {
- throw new DBErrors.UnexpectedResult('did not update almanac');
+ this.constructor._almanacErrorThrow();
}
this.logger.debug(_scope, 'completed', { scopesRemoved, atLeastMsSinceLast });
// Update the last cleanup time
const result = await txCtx.result(this.statement.almanacUpsert, { event: almanacEvent, date: now });
if (result.rowCount != 1) {
- throw new DBErrors.UnexpectedResult('did not update almanac');
+ this.constructor._almanacErrorThrow();
}
this.logger.debug(_scope, 'completed', { tokensRemoved, codeLifespanSeconds, atLeastMsSinceLast });
}
const almanacResult = await dbCtx.result(this.statement.almanacUpsert, { event: almanacEvent, date: new Date() });
if (almanacResult.rowCount != 1) {
- throw new DBErrors.UnexpectedResult('did not update almanac');
+ this.constructor._almanacErrorThrow();
}
} catch (e) {
this.logger.error(_scope, 'failed', { error: e, ...redeemedData });