Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libs/payments/cart/src/lib/tax.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import {
AccountCustomerManager,
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('TaxService', () => {
MockStatsDProvider,
MockStripeConfigProvider,
StripeClient,
MockLoggerProvider,
MockAccountDatabaseNestFactory,
AccountCustomerManager,
CustomerManager,
Expand Down Expand Up @@ -139,7 +141,7 @@ describe('TaxService', () => {

jest
.spyOn(accountCustomerManager, 'getAccountCustomerByUid')
.mockRejectedValue(new AccountCustomerNotFoundError('not found'));
.mockRejectedValue(new AccountCustomerNotFoundError('not found', new Error()));
jest.spyOn(geodbManager, 'getTaxAddress').mockReturnValue(geoAddress);

const result = await taxService.getTaxAddress(ip, uid);
Expand Down
2 changes: 2 additions & 0 deletions libs/payments/customer/src/lib/customer.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import {
StripeClient,
Expand All @@ -28,6 +29,7 @@ describe('CustomerManager', () => {
StripeClient,
CustomerManager,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import { CustomerSessionManager } from './customerSession.manager';
import {
Expand All @@ -24,6 +25,7 @@ describe('CustomerSessionManager', () => {
CustomerSessionManager,
StripeClient,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
2 changes: 2 additions & 0 deletions libs/payments/customer/src/lib/invoice.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import {
StripeClient,
Expand Down Expand Up @@ -63,6 +64,7 @@ describe('InvoiceManager', () => {
MockStripeConfigProvider,
InvoiceManager,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import { PaymentIntentManager } from './paymentIntent.manager';
import {
Expand All @@ -24,6 +25,7 @@ describe('PaymentIntentManager', () => {
PaymentIntentManager,
StripeClient,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';
import { PaymentMethodManager } from './paymentMethod.manager';
import {
MockPaypalClientConfigProvider,
Expand Down Expand Up @@ -44,6 +45,7 @@ describe('PaymentMethodManager', () => {
PaypalCustomerManager,
StripeClient,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
2 changes: 2 additions & 0 deletions libs/payments/customer/src/lib/price.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import {
StripeClient,
Expand All @@ -29,6 +30,7 @@ describe('PriceManager', () => {
StripeClient,
PriceManager,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
2 changes: 2 additions & 0 deletions libs/payments/customer/src/lib/product.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import {
StripeClient,
Expand All @@ -24,6 +25,7 @@ describe('ProductManager', () => {
StripeClient,
ProductManager,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';
import { Stripe } from 'stripe';

import { ProductManager } from './product.manager';
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('PromotionCodeManager', () => {
PromotionCodeManager,
StripeClient,
SubscriptionManager,
MockLoggerProvider,
],
}).compile();

Expand Down
2 changes: 2 additions & 0 deletions libs/payments/customer/src/lib/setupIntent.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import { SetupIntentManager } from './setupIntent.manager';
import {
Expand All @@ -25,6 +26,7 @@ describe('SetupIntentManager', () => {
SetupIntentManager,
StripeClient,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
2 changes: 2 additions & 0 deletions libs/payments/customer/src/lib/subscription.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import {
StripeClient,
Expand Down Expand Up @@ -33,6 +34,7 @@ describe('SubscriptionManager', () => {
StripeClient,
SubscriptionManager,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
8 changes: 5 additions & 3 deletions libs/payments/legacy/src/lib/stripe-mapper.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import { Inject, Injectable, Logger } from '@nestjs/common';
import type { LoggerService } from '@nestjs/common';
import { Stripe } from 'stripe';
import { ProductConfigurationManager } from '@fxa/shared/cms';
import { PlanMapperUtil } from './plan-mapper.util';
Expand All @@ -22,7 +23,8 @@ export class StripeMapperService {
private successfulIds = new Set();
constructor(
private productConfigurationManager: ProductConfigurationManager,
private config: StripeMapperConfig
private config: StripeMapperConfig,
@Inject(Logger) public log: LoggerService
) {}

/**
Expand Down Expand Up @@ -72,7 +74,7 @@ export class StripeMapperService {
*/
@Cacheable({
cacheKey: (args) => cacheKeyForMap(args[0], args[1]),
strategy: new CacheFirstStrategy(),
strategy: (_: any, context: StripeMapperService) => new CacheFirstStrategy(undefined, undefined, context.log),
ttlSeconds: (_, context: StripeMapperService) =>
Comment on lines 75 to 78
Copy link
Copy Markdown
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.

context.config.ttl || DEFAULT_TTL_SECONDS,
client: new MemoryAdapter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';

import { MockStripeConfigProvider, StripeClient } from '@fxa/payments/stripe';
import { MockAccountDatabaseNestFactory } from '@fxa/shared/db/mysql/account';
Expand Down Expand Up @@ -37,6 +38,7 @@ describe('PaypalBillingAgreementManager', () => {
MockPaypalClientConfigProvider,
StripeClient,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

Expand Down
8 changes: 7 additions & 1 deletion libs/payments/stripe/src/lib/stripe.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { faker } from '@faker-js/faker';
import { Test } from '@nestjs/testing';
import { MockLoggerProvider } from '@fxa/shared/log';
import { Stripe } from 'stripe';

import {
Expand Down Expand Up @@ -102,7 +103,12 @@ describe('StripeClient', () => {

beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [MockStripeConfigProvider, StripeClient, MockStatsDProvider],
providers: [
MockStripeConfigProvider,
StripeClient,
MockStatsDProvider,
MockLoggerProvider,
],
}).compile();

stripeClient = module.get(StripeClient);
Expand Down
26 changes: 14 additions & 12 deletions libs/payments/stripe/src/lib/stripe.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { Inject, Injectable } from '@nestjs/common';
import { Inject, Injectable, Logger } from '@nestjs/common';
import type { LoggerService } from '@nestjs/common';
import { Stripe } from 'stripe';
import { Cacheable } from '@type-cacheable/core';

Expand Down Expand Up @@ -52,7 +53,8 @@ export class StripeClient {
private readonly stripe: Stripe;
constructor(
private stripeConfig: StripeConfig,
@Inject(StatsDService) public statsd: StatsD
@Inject(StatsDService) public statsd: StatsD,
@Inject(Logger) public log: LoggerService
) {
this.stripe = new Stripe(
// 'api_key_placeholder' is currently needed during build time
Expand Down Expand Up @@ -139,8 +141,8 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('subscriptionsList', undefined, args[0]),
strategy: new CacheFirstStrategy(),
client: new AsyncLocalStorageAdapter(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
client: (_: any, context: StripeClient) => new AsyncLocalStorageAdapter(false, context.log),
Comment on lines +144 to +145
Copy link
Copy Markdown
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.

})
@CaptureTimingWithStatsD()
async subscriptionsList(params?: Stripe.SubscriptionListParams) {
Expand Down Expand Up @@ -194,8 +196,8 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('subscriptionsRetrieve', args[0], args[1]),
strategy: new CacheFirstStrategy(),
client: new AsyncLocalStorageAdapter(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
client: (_: any, context: StripeClient) => new AsyncLocalStorageAdapter(false, context.log),
})
@CaptureTimingWithStatsD()
async subscriptionsRetrieve(
Expand Down Expand Up @@ -315,8 +317,8 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('paymentMethodsRetrieve', args[0], args[1]),
strategy: new CacheFirstStrategy(),
client: new AsyncLocalStorageAdapter(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
client: (_: any, context: StripeClient) => new AsyncLocalStorageAdapter(false, context.log),
})
@CaptureTimingWithStatsD()
async paymentMethodRetrieve(
Expand All @@ -343,7 +345,7 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('pricesRetrieve', args[0], args[1]),
strategy: new CacheFirstStrategy(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
ttlSeconds: 600,
client: new MemoryAdapter(),
})
Expand All @@ -359,7 +361,7 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('productsRetrieve', args[0], args[1]),
strategy: new CacheFirstStrategy(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
ttlSeconds: 600,
client: new MemoryAdapter(),
})
Expand All @@ -375,7 +377,7 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('promotionCodesList', undefined, args[0]),
strategy: new CacheFirstStrategy(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
ttlSeconds: 600,
client: new MemoryAdapter(),
})
Expand All @@ -391,7 +393,7 @@ export class StripeClient {
@Cacheable({
cacheKey: (args: any) =>
cacheKeyForClient('promotionCodesRetrieve', args[0], args[1]),
strategy: new CacheFirstStrategy(),
strategy: (_: any, context: StripeClient) => new CacheFirstStrategy(undefined, undefined, context.log),
ttlSeconds: 600,
client: new MemoryAdapter(),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class NextJSActionsService {
private paypalBillingAgreementManager: PaypalBillingAgreementManager,
private nimbusManager: NimbusManager,
@Inject(StatsDService) public statsd: StatsD,
@Inject(Logger) private log: LoggerService
@Inject(Logger) public log: LoggerService
) {}

@SanitizeExceptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export class RelyingPartyConfigurationManager {
locale: args[0],
});
}
}
},
context.log
),
ttlSeconds: (args: any) => {
// Get TTL from config, fallback to 5 minutes if not specified
Expand Down Expand Up @@ -147,7 +148,8 @@ export class RelyingPartyConfigurationManager {
cacheType: result,
locale: args[0],
});
}
},
context.log
);
},
ttlSeconds: (args: any) => {
Expand Down
8 changes: 1 addition & 7 deletions libs/shared/cms/src/lib/strapi.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Firestore } from '@google-cloud/firestore';
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { Inject, Injectable, Logger } from '@nestjs/common';
import type { LoggerService } from '@nestjs/common';
import cacheManager, { Cacheable, CacheClear } from '@type-cacheable/core';
import { Cacheable, CacheClear } from '@type-cacheable/core';
import EventEmitter from 'events';
import { GraphQLClient } from 'graphql-request';
import * as Sentry from '@sentry/node';
Expand All @@ -27,12 +27,6 @@ import { cacheKeyForQuery, CMS_QUERY_CACHE_KEY } from './util';
import { StrapiClientConfig } from './strapi.client.config';
import { localesQuery, LocalesResult } from './queries/locales';

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

const DEFAULT_FIRESTORE_OFFLINE_CACHE_TTL_SECONDS = 604800; // 604800 seconds is 7 days.
const DEFAULT_FIRESTORE_CACHE_TTL_SECONDS = 1800; // 1800 seconds is 30 minutes.
const DEFAULT_MEM_CACHE_TTL_SECONDS = 300; // 300 seconds is 5 minutes.
Expand Down
Loading
Loading