Skip to content

feat(payments-next): use LoggerService within TypeCachable decorators#20215

Open
david1alvarez wants to merge 1 commit intomainfrom
PAY-3571
Open

feat(payments-next): use LoggerService within TypeCachable decorators#20215
david1alvarez wants to merge 1 commit intomainfrom
PAY-3571

Conversation

@david1alvarez
Copy link
Contributor

Because:

  • The LoggerService provides much more useful data for debugging issues, and was not being used in the TypeCachable decorator

This commit:

  • Adds the requirement for the LoggerService to be present on the consuming classes of the TypeCachable decorators
  • Moves the cacheManager excludeContext call out of the strapi client and into the type-cachable barrel file, as it's now needed in several places
  • Updates the consuming classes to pass the LoggerService through to the decorator

Closes #PAY-3571

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.

@david1alvarez david1alvarez requested a review from a team as a code owner March 18, 2026 19:10
Copilot AI review requested due to automatic review settings March 18, 2026 22:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the shared type-cacheable integration so cache strategy/client builder functions can use the consuming class’s LoggerService (via decorator context), and centralizes the required @type-cacheable/core global option configuration.

Changes:

  • Add a shared TypeCacheableLogger type and thread logger instances into cache strategies/adapters.
  • Move cacheManager.setOptions({ excludeContext: false }) into @fxa/shared/db/type-cacheable’s barrel to enable context-aware builders across consumers.
  • Update multiple consuming services (Stripe, CMS, UI actions) to inject/expose a logger for use inside @Cacheable decorators.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/fxa-auth-server/lib/payments/stripe.ts Passes a logger into StripeMapperService during manual construction.
packages/fxa-auth-server/lib/payments/initSubplat.ts Updates StripeClient construction to pass a logger.
libs/shared/db/type-cacheable/src/lib/type-cachable-stale-while-revalidate-with-fallback.ts Switches logger typing to shared TypeCacheableLogger.
libs/shared/db/type-cacheable/src/lib/type-cachable-cache-first.ts Switches logger typing to shared TypeCacheableLogger.
libs/shared/db/type-cacheable/src/lib/type-cachable-async-local-storage-init.ts Tightens decorator typing to require log presence on targets.
libs/shared/db/type-cacheable/src/lib/type-cachable-async-local-storage-adapter.ts Adds logger support to AsyncLocalStorage adapter + factory.
libs/shared/db/type-cacheable/src/index.ts Centralizes global excludeContext: false configuration.
libs/shared/cms/src/lib/strapi.client.ts Removes local cacheManager option setting (now centralized).
libs/shared/cms/src/lib/relying-party-configuration.manager.ts Passes the service logger into cache strategies.
libs/payments/ui/src/lib/nestapp/nextjs-actions.service.ts Exposes injected logger publicly for decorator context usage.
libs/payments/stripe/src/lib/stripe.client.ts Injects logger and uses context-aware strategy/client builders.
libs/payments/stripe/src/lib/stripe.client.spec.ts Updates unit test DI wiring to provide a Logger.
libs/payments/legacy/src/lib/stripe-mapper.service.ts Injects logger and uses context-aware strategy builder.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

this.productConfigurationManager,
{ ttl: this.config.cms.legacyMapper.mapperCacheTTL }
{ ttl: this.config.cms.legacyMapper.mapperCacheTTL },
{ ...this.log, log: (msg, fields) => this.log.info(msg, fields) } // StripeMapperService expects a log method, but the auth-server logger only has info, warn, and error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bad suggestion. Typecasting these fields to any is going to prevent typescript from catching breaking type changes.

Comment on lines +144 to +145
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
client: (_: any, context: StripeClient) => new AsyncLocalStorageAdapter(false, context.log),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a good idea. Typecasting to any hides type changes and incompatibilities from typescripts checks, and this code is significantly less maintainable.

Comment on lines 75 to 78
@Cacheable({
cacheKey: (args) => cacheKeyForMap(args[0], args[1]),
strategy: new CacheFirstStrategy(),
strategy: (_: any, context: StripeMapperService) => new CacheFirstStrategy(undefined, undefined, context.log),
ttlSeconds: (_, context: StripeMapperService) =>
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 is an unnecessary optimization for a legacy mapping service, and no performance hit has been seen as a result of the prior pattern.

Comment on lines +3 to +4
class TargetExposesLogger {
log!: TypeCacheableLogger;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +54 to +62
{
provide: Logger,
useValue: {
error: jest.fn(),
log: jest.fn(),
warn: jest.fn(),
debug: jest.fn(),
},
},
Copy link
Member

@julianpoy julianpoy Mar 19, 2026

Choose a reason for hiding this comment

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

This should use our Mock* provider pattern, rather than being mocked inline (this is repeated across multiple files)

Comment on lines +4 to +10
import cacheManager from '@type-cacheable/core';

// Must be disabled globally per https://github.com/joshuaslate/type-cacheable?tab=readme-ov-file#change-global-options
// otherwise @Cacheable context will be undefined when using strategy/client builder functions
cacheManager.setOptions({
excludeContext: false,
});
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the corresponding similar code within strapi.client.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already have :)

Because:

* The LoggerService provides much more useful data for debugging issues, and was not being used in the TypeCachable decorator

This commit:

* Adds the requirement for the LoggerService to be present on the consuming classes of the TypeCachable decorators
* Moves the cacheManager excludeContext call out of the strapi client and into the type-cachable barrel file, as it's now needed in several places
* Updates the consuming classes to pass the LoggerService through to the decorator

Closes #PAY-3571
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