Added Sentry message logging for generating magic links (#20789)
ref https://linear.app/tryghost/issue/ONC-258
This commit is contained in:
parent
19b8674c3a
commit
ad9aa47400
@ -18,6 +18,7 @@ const newslettersService = require('../newsletters');
|
|||||||
const memberAttributionService = require('../member-attribution');
|
const memberAttributionService = require('../member-attribution');
|
||||||
const emailSuppressionList = require('../email-suppression-list');
|
const emailSuppressionList = require('../email-suppression-list');
|
||||||
const {t} = require('../i18n');
|
const {t} = require('../i18n');
|
||||||
|
const sentry = require('../../../shared/sentry');
|
||||||
|
|
||||||
const MAGIC_LINK_TOKEN_VALIDITY = 24 * 60 * 60 * 1000;
|
const MAGIC_LINK_TOKEN_VALIDITY = 24 * 60 * 60 * 1000;
|
||||||
const MAGIC_LINK_TOKEN_VALIDITY_AFTER_USAGE = 10 * 60 * 1000;
|
const MAGIC_LINK_TOKEN_VALIDITY_AFTER_USAGE = 10 * 60 * 1000;
|
||||||
@ -234,7 +235,8 @@ function createApiInstance(config) {
|
|||||||
newslettersService: newslettersService,
|
newslettersService: newslettersService,
|
||||||
memberAttributionService: memberAttributionService.service,
|
memberAttributionService: memberAttributionService.service,
|
||||||
emailSuppressionList,
|
emailSuppressionList,
|
||||||
settingsCache
|
settingsCache,
|
||||||
|
sentry
|
||||||
});
|
});
|
||||||
|
|
||||||
return membersApiInstance;
|
return membersApiInstance;
|
||||||
|
@ -5,6 +5,7 @@ const verifyEmailTemplate = require('./emails/verify-email');
|
|||||||
const debug = require('@tryghost/debug')('services:newsletters');
|
const debug = require('@tryghost/debug')('services:newsletters');
|
||||||
const tpl = require('@tryghost/tpl');
|
const tpl = require('@tryghost/tpl');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
|
const sentry = require('../../../shared/sentry');
|
||||||
|
|
||||||
const messages = {
|
const messages = {
|
||||||
nameAlreadyExists: 'A newsletter with the same name already exists',
|
nameAlreadyExists: 'A newsletter with the same name already exists',
|
||||||
@ -84,7 +85,8 @@ class NewslettersService {
|
|||||||
getSigninURL,
|
getSigninURL,
|
||||||
getText,
|
getText,
|
||||||
getHTML,
|
getHTML,
|
||||||
getSubject
|
getSubject,
|
||||||
|
sentry
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./setti
|
|||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
const MagicLink = require('@tryghost/magic-link');
|
const MagicLink = require('@tryghost/magic-link');
|
||||||
const verifyEmailTemplate = require('./emails/verify-email');
|
const verifyEmailTemplate = require('./emails/verify-email');
|
||||||
|
const sentry = require('../../../shared/sentry');
|
||||||
|
|
||||||
const EMAIL_KEYS = ['members_support_address'];
|
const EMAIL_KEYS = ['members_support_address'];
|
||||||
const messages = {
|
const messages = {
|
||||||
@ -80,7 +81,8 @@ class SettingsBREADService {
|
|||||||
getSigninURL,
|
getSigninURL,
|
||||||
getText,
|
getText,
|
||||||
getHTML,
|
getHTML,
|
||||||
getSubject
|
getSubject,
|
||||||
|
sentry
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class MagicLink {
|
|||||||
* @param {typeof defaultGetText} [options.getText]
|
* @param {typeof defaultGetText} [options.getText]
|
||||||
* @param {typeof defaultGetHTML} [options.getHTML]
|
* @param {typeof defaultGetHTML} [options.getHTML]
|
||||||
* @param {typeof defaultGetSubject} [options.getSubject]
|
* @param {typeof defaultGetSubject} [options.getSubject]
|
||||||
|
* @param {object} [options.sentry]
|
||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
if (!options || !options.transporter || !options.tokenProvider || !options.getSigninURL) {
|
if (!options || !options.transporter || !options.tokenProvider || !options.getSigninURL) {
|
||||||
@ -44,6 +45,7 @@ class MagicLink {
|
|||||||
this.getText = options.getText || defaultGetText;
|
this.getText = options.getText || defaultGetText;
|
||||||
this.getHTML = options.getHTML || defaultGetHTML;
|
this.getHTML = options.getHTML || defaultGetHTML;
|
||||||
this.getSubject = options.getSubject || defaultGetSubject;
|
this.getSubject = options.getSubject || defaultGetSubject;
|
||||||
|
this.sentry = options.sentry || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,6 +59,8 @@ class MagicLink {
|
|||||||
* @returns {Promise<{token: Token, info: SentMessageInfo}>}
|
* @returns {Promise<{token: Token, info: SentMessageInfo}>}
|
||||||
*/
|
*/
|
||||||
async sendMagicLink(options) {
|
async sendMagicLink(options) {
|
||||||
|
this.sentry?.captureMessage?.(`[Magic Link] Generating magic link`, {extra: options});
|
||||||
|
|
||||||
if (!isEmail(options.email)) {
|
if (!isEmail(options.email)) {
|
||||||
throw new BadRequestError({
|
throw new BadRequestError({
|
||||||
message: tpl(messages.invalidEmail)
|
message: tpl(messages.invalidEmail)
|
||||||
|
@ -71,7 +71,8 @@ module.exports = function MembersAPI({
|
|||||||
newslettersService,
|
newslettersService,
|
||||||
memberAttributionService,
|
memberAttributionService,
|
||||||
emailSuppressionList,
|
emailSuppressionList,
|
||||||
settingsCache
|
settingsCache,
|
||||||
|
sentry
|
||||||
}) {
|
}) {
|
||||||
const tokenService = new TokenService({
|
const tokenService = new TokenService({
|
||||||
privateKey,
|
privateKey,
|
||||||
@ -154,7 +155,8 @@ module.exports = function MembersAPI({
|
|||||||
getSigninURL,
|
getSigninURL,
|
||||||
getText,
|
getText,
|
||||||
getHTML,
|
getHTML,
|
||||||
getSubject
|
getSubject,
|
||||||
|
sentry
|
||||||
});
|
});
|
||||||
|
|
||||||
const paymentsService = new PaymentsService({
|
const paymentsService = new PaymentsService({
|
||||||
|
Loading…
Reference in New Issue
Block a user