Skip to content

Conversation

@nshirley
Copy link
Contributor

@nshirley nshirley commented Jan 16, 2026

Because

  • The types on fxa-email-renderer render functions make them difficult to use in auth-server
  • And there was some cleanup to do from the first integration with email-sender to auth-server

This pull request

  • Flattens the types on fxa-email-renderer functions
  • Updates snapshot tests (even though they're still skipped)
  • Updates the fxa-mailer to use the flattened type
  • Fixes first libs email sender test to use deepEquals assert on params passed to mailer
  • Adds a formatGeoData to convert app request geo location data to format expected by library

Issue that this pull request solves

Closes: FXA-12885

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

@nshirley nshirley requested a review from a team as a code owner January 16, 2026 20:35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all the snapshot tests updated after changing the renderer types

Of note too, I did away with the overly complex "renderAndSnapshotTest" function... I got too fancy and it made things too complex

import * as VerifySecondaryCode from '../templates/verifySecondaryCode';
import * as VerifyShortCode from '../templates/verifyShortCode';

export type WithFxaLayouts<T> = T & FxaLayouts.TemplateData;
Copy link
Contributor Author

@nshirley nshirley Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dschom - Since all of these need to be paired with the FxaLayouts.TemplateData this felt okay. The other idea I had was to declare/export all of the input types here, then they can be used in the fxa-mailer.ts explicitly, so they stay in sync, something like this:

export type RenderRecoveryInput = WithFxaLayouts<Recovery.TemplateData>;
// on and on

Feels a bit like overkill, but also means they can be used in the fxa-mailer and we don't have to then do the same WithFxaLayouts<Recovery.TemplateData>; inside the fxa-mailer on the send functions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, a bunch of redeclaration seems unnecessary to me and just adds maintenance work. And using WithFxaLayouts<Recovery.TemplateData> in fxa-mailer feels totally okay to.

OmitCommonLinks<renderer.TemplateData> &
OmitCommonLinks<renderer.passwordForgotOtp.TemplateData>
OmitCommonLinks<
renderer.WithFxaLayouts<renderer.passwordForgotOtp.TemplateData>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is where we could be simplier if we exported the input types

OmitCommonLinks<renderer.PasswordForgotOtpInput>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. I sort of wonder if just changing the import declaration would clean this up e.g. drop * as renderer thing and just do import { WithFxaLayouts, passwordFortgotOtp } from '@fxa/accounts/email-renderer';

* @param geoData Object containing city, state, and country
* @returns
*/
export function formatGeoData({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of feels like a helper for the sake of a helper... We could just align the type inside email-renderer with the same names... but I fear that would be more work than it's worth

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine approach.

@nshirley nshirley force-pushed the FXA-12885 branch 2 times, most recently from 3d970b6 to e87fdec Compare January 16, 2026 21:34
const uid = uuid.v4({}, Buffer.alloc(16)).toString('hex');
const passwordForgotTokenId = crypto.randomBytes(16).toString('hex');
const uid = '6bfe0db9d4b44ccaa7c175a889024b86';
const passwordForgotTokenId =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will sometimes make these values more 'test' like. ie Fill the string 1234678, or all zeros... When using a hard coded random values like this, I've seen code analysis will flag and generate a warning about committed token.

import * as VerifySecondaryCode from '../templates/verifySecondaryCode';
import * as VerifyShortCode from '../templates/verifyShortCode';

export type WithFxaLayouts<T> = T & FxaLayouts.TemplateData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, a bunch of redeclaration seems unnecessary to me and just adds maintenance work. And using WithFxaLayouts<Recovery.TemplateData> in fxa-mailer feels totally okay to.

sync: false,
}
);
const email = await r.renderAdminResetAccounts({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

country: geoData.location?.country,
stateCode: geoData.location?.state,
},
location: formatGeoData(geoData.location),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

OmitCommonLinks<renderer.TemplateData> &
OmitCommonLinks<renderer.passwordForgotOtp.TemplateData>
OmitCommonLinks<
renderer.WithFxaLayouts<renderer.passwordForgotOtp.TemplateData>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. I sort of wonder if just changing the import declaration would clean this up e.g. drop * as renderer thing and just do import { WithFxaLayouts, passwordFortgotOtp } from '@fxa/accounts/email-renderer';

- The types on fxa-email-renderer render functions make them difficult to use in auth-server
- And there was some cleanup to do from the first integration with email-sender to auth-server

- Flattens the types on fxa-email-renderer functions
- Updates snapshot tests (even though they're still skipped)
- Updates the fxa-mailer to use the flattened type
- Fixes first libs email sender test to use deepEquals assert on params passed to mailer
- Adds a formatGeoData to convert app request geo location data to format expected by library

Closes: FXA-12885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants