diff --git a/.circleci/config.yml b/.circleci/config.yml index 998a5e9997b..6a91ca30a7e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -932,6 +932,7 @@ workflows: - fail-fast - unit-test: name: Unit Test (PR) + resource_class: xlarge nx_run: affected --base=main --head=$CIRCLE_SHA1 workflow: test_pull_request requires: diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7d5c91a4db4..67212c3f1af 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -16,7 +16,6 @@ updates: - '@mozilla/fxa-devs' ignore: - dependency-name: 'jest-watch-typeahead' # To be removed after react-scripts update - - dependency-name: 'esbuild' # See FXA-5948 - dependency-name: 'mailparser' # Used as a test helper only, see #FXA-5351 - dependency-name: '*' update-types: ['version-update:semver-patch'] diff --git a/apps/payments/api/src/app/app.module.ts b/apps/payments/api/src/app/app.module.ts index d76156addc4..8f7ff1a477f 100644 --- a/apps/payments/api/src/app/app.module.ts +++ b/apps/payments/api/src/app/app.module.ts @@ -51,14 +51,12 @@ import { ProductConfigurationManager, StrapiClient, } from '@fxa/shared/cms'; -import { - PaymentsGleanManager, - PaymentsGleanService, -} from '@fxa/payments/metrics'; +import { PaymentsGleanManager } from '@fxa/payments/metrics'; import { PaymentsGleanFactory } from '@fxa/payments/metrics/provider'; import { PaymentsEmitterService } from '@fxa/payments/events'; import { NimbusManager, NimbusManagerConfig } from '@fxa/payments/experiments'; import { NimbusClient, NimbusClientConfig } from '@fxa/shared/experiments'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; @Module({ imports: [ @@ -97,7 +95,7 @@ import { NimbusClient, NimbusClientConfig } from '@fxa/shared/experiments'; SubscriptionEventsService, PaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaymentsEmitterService, PriceManager, ProductManager, diff --git a/libs/accounts/email-renderer/package.json b/libs/accounts/email-renderer/package.json index 442b6f90173..3c999ae6cd9 100644 --- a/libs/accounts/email-renderer/package.json +++ b/libs/accounts/email-renderer/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/accounts/email-renderer", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "private": true + "version": "0.0.1" } diff --git a/libs/accounts/email-renderer/project.json b/libs/accounts/email-renderer/project.json index 2fc7d3616a7..10021de09fe 100644 --- a/libs/accounts/email-renderer/project.json +++ b/libs/accounts/email-renderer/project.json @@ -19,7 +19,7 @@ } }, "build-ts": { - "executor": "@nx/esbuild:esbuild", + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "dependsOn": ["l10n-prime"], "options": { @@ -31,11 +31,18 @@ "libs/accounts/email-renderer/src/**/*.txt", "libs/accounts/email-renderer/src/**/*.mjml" ], - "format": ["cjs"] + "generatePackageJson": true } }, "build-css": { + "cache": true, "executor": "nx:run-commands", + "inputs": [ + "{projectRoot}/src/**/*.scss" + ], + "outputs": [ + "{projectRoot}/src/css" + ], "options": { "commands": [ "ts-node libs/accounts/email-renderer/src/sass-compile-files.ts" @@ -125,6 +132,7 @@ ] }, "l10n-merge": { + "cache": true, "dependsOn": ["l10n-prime"], "executor": "nx:run-commands", "options": { diff --git a/libs/accounts/email-sender/package.json b/libs/accounts/email-sender/package.json index d7f86331311..744adfb2460 100644 --- a/libs/accounts/email-sender/package.json +++ b/libs/accounts/email-sender/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/accounts/email-sender", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "private": true + "version": "0.0.1" } diff --git a/libs/accounts/email-sender/project.json b/libs/accounts/email-sender/project.json index 277c1bcf9cc..a0531e4d6ef 100644 --- a/libs/accounts/email-sender/project.json +++ b/libs/accounts/email-sender/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/accounts/email-sender", "main": "libs/accounts/email-sender/src/index.ts", "tsConfig": "libs/accounts/email-sender/tsconfig.lib.json", "assets": ["libs/accounts/email-sender/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/accounts/errors/package.json b/libs/accounts/errors/package.json index a4033ae3b7f..427b34d15b7 100644 --- a/libs/accounts/errors/package.json +++ b/libs/accounts/errors/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/accounts/errors", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "private": true + "version": "0.0.1" } diff --git a/libs/accounts/errors/project.json b/libs/accounts/errors/project.json index c1b0e5b1f7c..8cc5697dc6a 100644 --- a/libs/accounts/errors/project.json +++ b/libs/accounts/errors/project.json @@ -6,14 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { - "outputPath": "dist/libs/accounts/errors", "main": "libs/accounts/errors/src/index.ts", + "outputPath": "dist/libs/accounts/errors", "tsConfig": "libs/accounts/errors/tsconfig.lib.json", - "assets": ["libs/accounts/errors/*.md"], - "format": ["cjs"] + "assets": [ + { + "glob": "libs/accounts/errors/*.md", + "input": ".", + "output": "." + } + ] } }, "test-unit": { diff --git a/libs/accounts/errors/tsconfig.lib.json b/libs/accounts/errors/tsconfig.lib.json index 4befa7f0990..d9c5f01ebc2 100644 --- a/libs/accounts/errors/tsconfig.lib.json +++ b/libs/accounts/errors/tsconfig.lib.json @@ -1,6 +1,8 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "rootDir": "../../..", + "module": "commonjs", "outDir": "../../../dist/out-tsc", "declaration": true, "types": ["node"] diff --git a/libs/accounts/oauth/package.json b/libs/accounts/oauth/package.json index 9ac7f7ca2d6..851f4da7dfd 100644 --- a/libs/accounts/oauth/package.json +++ b/libs/accounts/oauth/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/accounts/oauth", - "version": "0.0.1", - "private": true, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "dependencies": {} + "version": "0.0.1" } diff --git a/libs/accounts/oauth/project.json b/libs/accounts/oauth/project.json index fa7f0ef7ec6..e6b8167592b 100644 --- a/libs/accounts/oauth/project.json +++ b/libs/accounts/oauth/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/accounts/oauth", "main": "libs/accounts/oauth/src/index.ts", "tsConfig": "libs/accounts/oauth/tsconfig.lib.json", "assets": ["libs/accounts/oauth/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test": { diff --git a/libs/accounts/passkey/package.json b/libs/accounts/passkey/package.json index a6bf5849166..97efe5f097b 100644 --- a/libs/accounts/passkey/package.json +++ b/libs/accounts/passkey/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/accounts/passkey", - "version": "0.0.1", - "private": true, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "dependencies": {} + "version": "0.0.1" } diff --git a/libs/accounts/passkey/project.json b/libs/accounts/passkey/project.json index 8e9d342a4f0..999c8870c4f 100644 --- a/libs/accounts/passkey/project.json +++ b/libs/accounts/passkey/project.json @@ -6,15 +6,20 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/accounts/passkey", "main": "libs/accounts/passkey/src/index.ts", "tsConfig": "libs/accounts/passkey/tsconfig.lib.json", - "assets": ["libs/accounts/passkey/*.md"], - "format": ["cjs"], - "declaration": true + "assets": ["libs/accounts/passkey/*.md"] } }, "test-unit": { diff --git a/libs/accounts/passkey/tsconfig.lib.json b/libs/accounts/passkey/tsconfig.lib.json index 4befa7f0990..6836ea5b7f0 100644 --- a/libs/accounts/passkey/tsconfig.lib.json +++ b/libs/accounts/passkey/tsconfig.lib.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "rootDir": "../../..", "outDir": "../../../dist/out-tsc", "declaration": true, "types": ["node"] diff --git a/libs/accounts/rate-limit/package.json b/libs/accounts/rate-limit/package.json index e4050681e71..e20213f674c 100644 --- a/libs/accounts/rate-limit/package.json +++ b/libs/accounts/rate-limit/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/accounts/rate-limit", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "private": true + "version": "0.0.1" } diff --git a/libs/accounts/rate-limit/project.json b/libs/accounts/rate-limit/project.json index cc632f848ae..58bb4374753 100644 --- a/libs/accounts/rate-limit/project.json +++ b/libs/accounts/rate-limit/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/accounts/rate-limit", "main": "libs/accounts/rate-limit/src/index.ts", "tsConfig": "libs/accounts/rate-limit/tsconfig.lib.json", "assets": ["libs/accounts/rate-limit/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/accounts/recovery-phone/package.json b/libs/accounts/recovery-phone/package.json index 78842ea4fc9..68b92a5dd53 100644 --- a/libs/accounts/recovery-phone/package.json +++ b/libs/accounts/recovery-phone/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/accounts/recovery-phone", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/accounts/recovery-phone/project.json b/libs/accounts/recovery-phone/project.json index f3b18446937..378fd654ad2 100644 --- a/libs/accounts/recovery-phone/project.json +++ b/libs/accounts/recovery-phone/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/accounts/recovery-phone", "main": "libs/accounts/recovery-phone/src/index.ts", "tsConfig": "libs/accounts/recovery-phone/tsconfig.lib.json", "assets": ["libs/accounts/recovery-phone/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/accounts/two-factor/project.json b/libs/accounts/two-factor/project.json index 2f5a7034338..f7214556a42 100644 --- a/libs/accounts/two-factor/project.json +++ b/libs/accounts/two-factor/project.json @@ -6,24 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "outputPath": "dist/libs/accounts/two-factor", "tsConfig": "libs/accounts/two-factor/tsconfig.lib.json", "packageJson": "libs/accounts/two-factor/package.json", "main": "libs/accounts/two-factor/src/index.ts", - "assets": ["libs/accounts/two-factor/*.md"], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + "assets": ["libs/accounts/two-factor/*.md"] } }, "test-unit": { diff --git a/libs/google/project.json b/libs/google/project.json index 465778aae6c..d70a4b0158a 100644 --- a/libs/google/project.json +++ b/libs/google/project.json @@ -6,16 +6,20 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/google/src/index.ts", "outputPath": "dist/libs/google", - "outputFileName": "main.js", "tsConfig": "libs/google/tsconfig.lib.json", - "assets": ["libs/google/*.md"], - "declaration": true + "assets": ["libs/google/*.md"] } }, "lint": { diff --git a/libs/payments/api-server/project.json b/libs/payments/api-server/project.json index 8a743445588..3ba1acb42ab 100644 --- a/libs/payments/api-server/project.json +++ b/libs/payments/api-server/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "defaultConfiguration": "production", "options": { - "main": "libs/payments/api-server/src/index.ts", + "tsConfig": "libs/payments/api-server/tsconfig.lib.json", "outputPath": "dist/libs/payments/api-server", + "main": "libs/payments/api-server/src/index.ts", "outputFileName": "main.js", - "tsConfig": "libs/payments/api-server/tsconfig.lib.json", "declaration": true, "assets": [ { diff --git a/libs/payments/auth/project.json b/libs/payments/auth/project.json index 25c46831fd1..72180c0d5de 100644 --- a/libs/payments/auth/project.json +++ b/libs/payments/auth/project.json @@ -6,14 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { - "outputPath": "dist/libs/payments/auth", "main": "libs/payments/auth/src/index.ts", + "outputPath": "dist/libs/payments/auth", "tsConfig": "libs/payments/auth/tsconfig.lib.json", - "assets": ["libs/payments/auth/*.md"], - "format": ["cjs"] + "assets": [ + { + "glob": "libs/payments/auth/*.md", + "input": ".", + "output": "." + } + ] } }, "test-unit": { diff --git a/libs/payments/capability/project.json b/libs/payments/capability/project.json index 14f212c9947..b39354d0c0c 100644 --- a/libs/payments/capability/project.json +++ b/libs/payments/capability/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/capability/src/index.ts", "outputPath": "dist/libs/payments/capability", - "outputFileName": "main.js", "tsConfig": "libs/payments/capability/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/capability/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/cart/project.json b/libs/payments/cart/project.json index a98a594cb56..bc040ed82fa 100644 --- a/libs/payments/cart/project.json +++ b/libs/payments/cart/project.json @@ -6,13 +6,18 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/cart/src/index.ts", "outputPath": "dist/libs/payments/cart", - "outputFileName": "main.js", "tsConfig": "libs/payments/cart/tsconfig.lib.json", "assets": [ { @@ -20,16 +25,7 @@ "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/cart/src/lib/cart.service.spec.ts b/libs/payments/cart/src/lib/cart.service.spec.ts index 02c6f17d1e4..6cdbf67f6f0 100644 --- a/libs/payments/cart/src/lib/cart.service.spec.ts +++ b/libs/payments/cart/src/lib/cart.service.spec.ts @@ -136,8 +136,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { MockNimbusManagerConfigProvider, NimbusManager, @@ -238,7 +238,7 @@ describe('CartService', () => { PaymentIntentManager, PaymentMethodManager, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaypalBillingAgreementManager, PayPalClient, PaypalCustomerManager, diff --git a/libs/payments/cart/src/lib/cart.service.ts b/libs/payments/cart/src/lib/cart.service.ts index 5eed09d71d9..075a0fba3e2 100644 --- a/libs/payments/cart/src/lib/cart.service.ts +++ b/libs/payments/cart/src/lib/cart.service.ts @@ -113,7 +113,7 @@ import { isPaymentIntentId } from './util/isPaymentIntentId'; import { isPaymentIntent } from './util/isPaymentIntent'; import { throwIntentFailedError } from './util/throwIntentFailedError'; import type { SubscriptionAttributionParams } from './checkout.types'; -import { handleException } from 'libs/shared/error/src/lib/sanitizeExceptionsDecorator'; +import { handleException } from '@fxa/shared/error'; import type { AsyncLocalStorage } from 'async_hooks'; import { AsyncLocalStorageCart } from './cart-als.provider'; import type { CartStore } from './cart-als.types'; diff --git a/libs/payments/cart/src/lib/checkout.service.spec.ts b/libs/payments/cart/src/lib/checkout.service.spec.ts index adecf94048e..b603b98b850 100644 --- a/libs/payments/cart/src/lib/checkout.service.spec.ts +++ b/libs/payments/cart/src/lib/checkout.service.spec.ts @@ -136,8 +136,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { MockNimbusManagerConfigProvider, NimbusManager, @@ -172,7 +172,7 @@ describe('CheckoutService', () => { let statsd: StatsD; let subscriptionManager: SubscriptionManager; let paymentMethodManager: PaymentMethodManager; - let gleanService: PaymentsGleanService; + let gleanService: PaymentsMetricsAggregatorService; let freeTrialManager: FreeTrialManager; let nimbusManager: NimbusManager; @@ -230,7 +230,7 @@ describe('CheckoutService', () => { PaymentIntentManager, PaymentMethodManager, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaypalBillingAgreementManager, PayPalClient, PaypalClientConfig, @@ -277,7 +277,7 @@ describe('CheckoutService', () => { statsd = moduleRef.get(StatsDService); subscriptionManager = moduleRef.get(SubscriptionManager); paymentMethodManager = moduleRef.get(PaymentMethodManager); - gleanService = moduleRef.get(PaymentsGleanService); + gleanService = moduleRef.get(PaymentsMetricsAggregatorService); freeTrialManager = moduleRef.get(FreeTrialManager); nimbusManager = moduleRef.get(NimbusManager); }); diff --git a/libs/payments/cart/src/lib/checkout.service.ts b/libs/payments/cart/src/lib/checkout.service.ts index b5dd6d09487..7987718df95 100644 --- a/libs/payments/cart/src/lib/checkout.service.ts +++ b/libs/payments/cart/src/lib/checkout.service.ts @@ -92,10 +92,8 @@ import { throwIntentFailedError } from './util/throwIntentFailedError'; import type { AsyncLocalStorage } from 'async_hooks'; import { AsyncLocalStorageCart } from './cart-als.provider'; import type { CartStore } from './cart-als.types'; -import { - type CommonMetrics, - PaymentsGleanService, -} from '@fxa/payments/metrics'; +import { type CommonMetrics } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { isCancelInterstitialOffer } from './util/isCancelInterstitialOffer'; import { FreeTrialManager } from './free-trial.manager'; import type { PaymentsSearchParams } from './searchParams.schema'; @@ -127,7 +125,7 @@ export class CheckoutService { private paymentMethodManager: PaymentMethodManager, private freeTrialManager: FreeTrialManager, private nimbusManager: NimbusManager, - private gleanService: PaymentsGleanService, + private gleanService: PaymentsMetricsAggregatorService, @Inject(StatsDService) private statsd: StatsD ) {} diff --git a/libs/payments/content-server/project.json b/libs/payments/content-server/project.json index f464da66072..901f750c787 100644 --- a/libs/payments/content-server/project.json +++ b/libs/payments/content-server/project.json @@ -6,13 +6,18 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/content-server/src/index.ts", "outputPath": "dist/libs/payments/content-server", - "outputFileName": "main.js", "tsConfig": "libs/payments/content-server/tsconfig.lib.json", "assets": [ { @@ -20,16 +25,7 @@ "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/currency/project.json b/libs/payments/currency/project.json index 36bde406d00..ea68cd8070e 100644 --- a/libs/payments/currency/project.json +++ b/libs/payments/currency/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/currency/src/index.ts", "outputPath": "dist/libs/payments/currency", - "outputFileName": "main.js", "tsConfig": "libs/payments/currency/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/currency/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/customer/package.json b/libs/payments/customer/package.json index 919acd56fb0..66b0c09805f 100644 --- a/libs/payments/customer/package.json +++ b/libs/payments/customer/package.json @@ -1,4 +1,4 @@ { - "name": "payments/customer", + "name": "@fxa/payments/customer", "version": "0.0.0" } diff --git a/libs/payments/customer/project.json b/libs/payments/customer/project.json index dac3a734533..94915423a23 100644 --- a/libs/payments/customer/project.json +++ b/libs/payments/customer/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/customer/src/index.ts", "outputPath": "dist/libs/payments/customer", - "outputFileName": "main.js", "tsConfig": "libs/payments/customer/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/customer/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/customer/src/lib/types.ts b/libs/payments/customer/src/lib/types.ts index 9056a051fc6..37e7c61ac5d 100644 --- a/libs/payments/customer/src/lib/types.ts +++ b/libs/payments/customer/src/lib/types.ts @@ -37,6 +37,7 @@ export enum PaymentProvider { Stripe = 'stripe', } +// Duplicated as enum SubPlatPaymentMethodType in @fxa/payments/metrics — keep in sync. export enum SubPlatPaymentMethodType { PayPal = 'external_paypal', Stripe = 'stripe', @@ -77,6 +78,7 @@ export interface AccountCreditBalance { currency: string | null; } +// Duplicated as type PaymentProvidersType in @fxa/payments/metrics — keep in sync. export type PaymentProvidersType = | 'stripe' | 'google_iap' @@ -203,6 +205,7 @@ export type StripeInvoiceMetadata = StripeMetadata; export type StripeInvoiceMetadataInput = StripeMetadataInput; +// Duplicated as enum SubplatInterval in @fxa/payments/metrics — keep in sync. export enum SubplatInterval { Daily = 'daily', Weekly = 'weekly', @@ -211,6 +214,7 @@ export enum SubplatInterval { Yearly = 'yearly', } +// Duplicated as interface TaxAddress in @fxa/payments/metrics — keep in sync. export interface TaxAddress { countryCode: string; postalCode: string; diff --git a/libs/payments/customer/src/lib/util/getPaymentMethodErrorContent.ts b/libs/payments/customer/src/lib/util/getPaymentMethodErrorContent.ts index e8ee94a7e93..96efd38c253 100644 --- a/libs/payments/customer/src/lib/util/getPaymentMethodErrorContent.ts +++ b/libs/payments/customer/src/lib/util/getPaymentMethodErrorContent.ts @@ -6,7 +6,7 @@ import { BannerVariant, PaymentMethodErrorType, SubPlatPaymentMethodType, -} from '@fxa/payments/customer'; +} from '../..'; export function getPaymentMethodErrorContent( error: PaymentMethodErrorType, diff --git a/libs/payments/eligibility/project.json b/libs/payments/eligibility/project.json index c068dfcac5c..c868e7bfaa7 100644 --- a/libs/payments/eligibility/project.json +++ b/libs/payments/eligibility/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/eligibility/src/index.ts", "outputPath": "dist/libs/payments/eligibility", - "outputFileName": "main.js", "tsConfig": "libs/payments/eligibility/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/eligibility/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/events/package.json b/libs/payments/events/package.json index 4985c13d894..eecbc3279af 100644 --- a/libs/payments/events/package.json +++ b/libs/payments/events/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/payments/events", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/payments/events/project.json b/libs/payments/events/project.json index 5313e75450c..51b11a05b03 100644 --- a/libs/payments/events/project.json +++ b/libs/payments/events/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/payments/events", "main": "libs/payments/events/src/index.ts", "tsConfig": "libs/payments/events/tsconfig.lib.json", "assets": ["libs/payments/events/*.md"], - "declaration": true + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/payments/events/src/lib/emitter.service.spec.ts b/libs/payments/events/src/lib/emitter.service.spec.ts index 12c1ca4c060..b3b60cc1434 100644 --- a/libs/payments/events/src/lib/emitter.service.spec.ts +++ b/libs/payments/events/src/lib/emitter.service.spec.ts @@ -42,8 +42,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { CartManager } from '@fxa/payments/cart'; import { PaymentsEmitterService } from './emitter.service'; import { @@ -101,7 +101,7 @@ describe('PaymentsEmitterService', () => { let statsd: StatsD; let logger: Logger; let subscriptionManager: SubscriptionManager; - let paymentsGleanService: PaymentsGleanService; + let paymentsGleanService: PaymentsMetricsAggregatorService; const additionalMetricsData = AdditionalMetricsDataFactory(); const mockCommonMetricsData = CommonMetricsFactory({ @@ -139,7 +139,7 @@ describe('PaymentsEmitterService', () => { StripeClient, PriceManager, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, ProductConfigurationManager, PaypalBillingAgreementManager, PayPalClient, @@ -166,7 +166,7 @@ describe('PaymentsEmitterService', () => { statsd = moduleRef.get(StatsDService); logger = moduleRef.get(Logger); subscriptionManager = moduleRef.get(SubscriptionManager); - paymentsGleanService = moduleRef.get(PaymentsGleanService); + paymentsGleanService = moduleRef.get(PaymentsMetricsAggregatorService); }); it('should be defined', () => { diff --git a/libs/payments/events/src/lib/emitter.service.ts b/libs/payments/events/src/lib/emitter.service.ts index 4a6f6ad7808..6abf246a767 100644 --- a/libs/payments/events/src/lib/emitter.service.ts +++ b/libs/payments/events/src/lib/emitter.service.ts @@ -8,8 +8,8 @@ import { CartManager, TaxChangeAllowedStatus } from '@fxa/payments/cart'; import { PaymentsGleanManager, type GenericGleanSubManageEvent, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { LocationStatus } from '@fxa/payments/eligibility'; import { CheckoutEvents, @@ -46,7 +46,7 @@ export class PaymentsEmitterService { private log: Logger, private nimbusManager: NimbusManager, private paymentsGleanManager: PaymentsGleanManager, - private paymentsGleanService: PaymentsGleanService, + private paymentsGleanService: PaymentsMetricsAggregatorService, private paymentMethodManager: PaymentMethodManager, private productConfigurationManager: ProductConfigurationManager, @Inject(StatsDService) public statsd: StatsD, diff --git a/libs/payments/experiments/package.json b/libs/payments/experiments/package.json index 5b05d511707..a3286e78257 100644 --- a/libs/payments/experiments/package.json +++ b/libs/payments/experiments/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/payments/experiments", - "version": "0.0.1", - "private": true, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "dependencies": {} + "version": "0.0.1" } diff --git a/libs/payments/experiments/project.json b/libs/payments/experiments/project.json index 0a2010b22c0..227bbc4a1b4 100644 --- a/libs/payments/experiments/project.json +++ b/libs/payments/experiments/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/payments/experiments", "main": "libs/payments/experiments/src/index.ts", "tsConfig": "libs/payments/experiments/tsconfig.lib.json", "assets": ["libs/payments/experiments/*.md"], - "declaration": true + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/payments/iap/project.json b/libs/payments/iap/project.json index 9efc9aaaca0..f7a1ef20660 100644 --- a/libs/payments/iap/project.json +++ b/libs/payments/iap/project.json @@ -12,31 +12,26 @@ } }, "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/iap/src/index.ts", "outputPath": "dist/libs/payments/iap", - "outputFileName": "main.js", "tsConfig": "libs/payments/iap/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/iap/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/legacy/project.json b/libs/payments/legacy/project.json index 66f0b73fdbb..dd13fa9d19b 100644 --- a/libs/payments/legacy/project.json +++ b/libs/payments/legacy/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/legacy/src/index.ts", "outputPath": "dist/libs/payments/legacy", - "outputFileName": "main.js", "tsConfig": "libs/payments/legacy/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/legacy/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/management/project.json b/libs/payments/management/project.json index 227c3b70203..7d3b554ca6e 100644 --- a/libs/payments/management/project.json +++ b/libs/payments/management/project.json @@ -6,13 +6,18 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/management/src/index.ts", "outputPath": "dist/libs/payments/management", - "outputFileName": "main.js", "tsConfig": "libs/payments/management/tsconfig.lib.json", "assets": [ { @@ -20,17 +25,7 @@ "input": ".", "output": "." } - ], - "platform": "node", - "declaration" : true - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/nestjs/customs/.eslintrc.json b/libs/payments/metrics-aggregator/.eslintrc.json similarity index 85% rename from libs/shared/nestjs/customs/.eslintrc.json rename to libs/payments/metrics-aggregator/.eslintrc.json index 632e9b0e222..3456be9b903 100644 --- a/libs/shared/nestjs/customs/.eslintrc.json +++ b/libs/payments/metrics-aggregator/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["../../../../.eslintrc.json"], + "extends": ["../../../.eslintrc.json"], "ignorePatterns": ["!**/*"], "overrides": [ { diff --git a/libs/payments/metrics-aggregator/.swcrc b/libs/payments/metrics-aggregator/.swcrc new file mode 100644 index 00000000000..f52b4e44979 --- /dev/null +++ b/libs/payments/metrics-aggregator/.swcrc @@ -0,0 +1,14 @@ +{ + "jsc": { + "target": "es2017", + "parser": { + "syntax": "typescript", + "decorators": true, + "dynamicImport": true + }, + "transform": { + "decoratorMetadata": true, + "legacyDecorator": true + } + } +} diff --git a/libs/payments/metrics-aggregator/README.md b/libs/payments/metrics-aggregator/README.md new file mode 100644 index 00000000000..71271db9ecd --- /dev/null +++ b/libs/payments/metrics-aggregator/README.md @@ -0,0 +1,26 @@ +# payments-metrics-aggregator + +This library was generated with [Nx](https://nx.dev). + +It contains the orchestration service that aggregates data from multiple +domain managers (customer, subscription, account, CMS, experiments) to +assemble payloads for Glean metrics events. The low-level Glean recording +primitives (manager, generated events, types, factories) live in +`@fxa/payments/metrics`. + +This split exists so that domain libraries (e.g. `@fxa/payments/customer`, +`@fxa/payments/experiments`, `@fxa/shared/cms`) can depend on +`@fxa/payments/metrics` for plain event recording without pulling in the +managers that the aggregator orchestrates. + +## Building + +Run `nx build payments-metrics-aggregator` to build the library. + +## Running unit tests + +Run `nx test-unit payments-metrics-aggregator` to execute the unit tests via [Jest](https://jestjs.io). + +## Running integration tests + +Run `nx test-integration payments-metrics-aggregator` to execute the integration tests via [Jest](https://jestjs.io). diff --git a/libs/payments/metrics-aggregator/jest.config.ts b/libs/payments/metrics-aggregator/jest.config.ts new file mode 100644 index 00000000000..83253925886 --- /dev/null +++ b/libs/payments/metrics-aggregator/jest.config.ts @@ -0,0 +1,43 @@ +/* eslint-disable */ +import { readFileSync } from 'fs'; +import { Config } from 'jest'; + +// Reading the SWC compilation config and remove the "exclude" +// for the test files to be compiled by SWC +const { exclude: _, ...swcJestConfig } = JSON.parse( + readFileSync(`${__dirname}/.swcrc`, 'utf-8') +); + +// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. +// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" +if (swcJestConfig.swcrc === undefined) { + swcJestConfig.swcrc = false; +} + +// Uncomment if using global setup/teardown files being transformed via swc +// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries +// jest needs EsModule Interop to find the default exported setup/teardown functions +// swcJestConfig.module.noInterop = false; + +const config: Config = { + displayName: 'payments-metrics-aggregator', + preset: '../../../jest.preset.js', + transform: { + '^.+\\.[tj]s$': ['@swc/jest', swcJestConfig], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + testEnvironment: 'node', + coverageDirectory: '../../../coverage/libs/payments/metrics-aggregator', + reporters: [ + 'default', + [ + 'jest-junit', + { + outputDirectory: 'artifacts/tests/payments-metrics-aggregator', + outputName: 'payments-metrics-aggregator-jest-unit-results.xml', + }, + ], + ], +}; + +export default config; diff --git a/libs/payments/metrics-aggregator/package.json b/libs/payments/metrics-aggregator/package.json new file mode 100644 index 00000000000..ab4cae4d391 --- /dev/null +++ b/libs/payments/metrics-aggregator/package.json @@ -0,0 +1,4 @@ +{ + "name": "@fxa/payments/metrics-aggregator", + "version": "0.0.1" +} diff --git a/libs/payments/metrics-aggregator/project.json b/libs/payments/metrics-aggregator/project.json new file mode 100644 index 00000000000..f047f35fd1c --- /dev/null +++ b/libs/payments/metrics-aggregator/project.json @@ -0,0 +1,55 @@ +{ + "name": "payments-metrics-aggregator", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/payments/metrics-aggregator/src", + "projectType": "library", + "tags": ["scope:shared:lib:payments"], + "targets": { + "build": { + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", + "outputs": ["{options.outputPath}"], + "options": { + "main": "libs/payments/metrics-aggregator/src/index.ts", + "outputPath": "dist/libs/payments/metrics-aggregator", + "tsConfig": "libs/payments/metrics-aggregator/tsconfig.lib.json", + "assets": [ + { + "glob": "libs/payments/metrics-aggregator/README.md", + "input": ".", + "output": "." + } + ] + } + }, + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/payments/metrics-aggregator/**/*.ts"] + } + }, + "test-unit": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/payments/metrics-aggregator/jest.config.ts", + "testPathPattern": ["^(?!.*\\.in\\.spec\\.ts$).*$"] + } + }, + "test-integration": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/payments/metrics-aggregator/jest.config.ts", + "testPathPattern": ["\\.in\\.spec\\.ts$"] + } + } + } +} diff --git a/libs/payments/metrics-aggregator/src/index.ts b/libs/payments/metrics-aggregator/src/index.ts new file mode 100644 index 00000000000..8ae56210c2c --- /dev/null +++ b/libs/payments/metrics-aggregator/src/index.ts @@ -0,0 +1,6 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +export * from './lib/payments-metrics-aggregator.service'; +export * from './lib/payments-metrics-aggregator.test-provider'; diff --git a/libs/payments/metrics/src/lib/glean/glean.service.spec.ts b/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.service.spec.ts similarity index 79% rename from libs/payments/metrics/src/lib/glean/glean.service.spec.ts rename to libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.service.spec.ts index 05f13f57c1e..54bebdb8053 100644 --- a/libs/payments/metrics/src/lib/glean/glean.service.spec.ts +++ b/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.service.spec.ts @@ -3,19 +3,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Test } from '@nestjs/testing'; -import { PaymentsGleanManager } from './glean.manager'; -import { PaymentsGleanService } from './glean.service'; -import { MockPaymentsGleanFactory } from './glean.test-provider'; -import { - MockPaymentsGleanConfigProvider, - PaymentsGleanConfig, -} from './glean.config'; import { AccountsMetricsDataFactory, CommonMetricsFactory, GenericGleanSubManageEventFactory, GleanMetricsDataFactory, -} from './glean.factory'; + MockPaymentsGleanConfigProvider, + MockPaymentsGleanFactory, + PaymentsGleanConfig, + PaymentsGleanManager, +} from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from './payments-metrics-aggregator.service'; import { AccountManager } from '@fxa/shared/account/account'; import { CustomerManager, @@ -55,10 +53,9 @@ import { } from '@fxa/shared/experiments'; import { MockFirestoreProvider } from '@fxa/shared/db/firestore'; import { MockStatsDProvider } from '@fxa/shared/metrics/statsd'; -import { AsyncLocalStorageCartProvider } from '@fxa/payments/cart'; -describe('PaymentsGleanService', () => { - let paymentsGleanService: PaymentsGleanService; +describe('PaymentsMetricsAggregatorService', () => { + let aggregatorService: PaymentsMetricsAggregatorService; let paymentsGleanManager: PaymentsGleanManager; let subscriptionManager: SubscriptionManager; let productConfigurationManager: ProductConfigurationManager; @@ -72,7 +69,6 @@ describe('PaymentsGleanService', () => { const moduleRef = await Test.createTestingModule({ providers: [ AccountManager, - AsyncLocalStorageCartProvider, CustomerManager, Logger, MockFirestoreProvider, @@ -88,7 +84,7 @@ describe('PaymentsGleanService', () => { NimbusManager, PriceManager, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, ProductConfigurationManager, StrapiClient, StripeClient, @@ -97,7 +93,7 @@ describe('PaymentsGleanService', () => { ], }).compile(); - paymentsGleanService = moduleRef.get(PaymentsGleanService); + aggregatorService = moduleRef.get(PaymentsMetricsAggregatorService); paymentsGleanManager = moduleRef.get(PaymentsGleanManager); subscriptionManager = moduleRef.get(SubscriptionManager); productConfigurationManager = moduleRef.get(ProductConfigurationManager); @@ -120,7 +116,7 @@ describe('PaymentsGleanService', () => { }); it('logs one entry per nimbus user id', () => { - paymentsGleanService.handleUserDelete(mockUid); + aggregatorService.handleUserDelete(mockUid); expect( nimbusManager.generateAllNimbusIdsForDeletion @@ -137,7 +133,7 @@ describe('PaymentsGleanService', () => { it('still logs deletion even when glean is disabled', () => { gleanConfig.enabled = false; - paymentsGleanService.handleUserDelete(mockUid); + aggregatorService.handleUserDelete(mockUid); expect( nimbusManager.generateAllNimbusIdsForDeletion @@ -158,7 +154,7 @@ describe('PaymentsGleanService', () => { .spyOn(nimbusManager, 'generateAllNimbusIdsForDeletion') .mockReturnValue(['single-nimbus-id']); - paymentsGleanService.handleUserDelete(mockUid); + aggregatorService.handleUserDelete(mockUid); expect(logger.log).toHaveBeenCalledTimes(1); expect(logger.log).toHaveBeenCalledWith('glean.user.delete', { @@ -174,7 +170,7 @@ describe('PaymentsGleanService', () => { beforeEach(() => { jest.spyOn(paymentsGleanManager, 'recordGenericEvent').mockReturnValue(); jest - .spyOn(paymentsGleanService, 'retrieveSubManageMetricsData') + .spyOn(aggregatorService, 'retrieveSubManageMetricsData') .mockResolvedValue( GleanMetricsDataFactory({ accounts: AccountsMetricsDataFactory({ metricsOptOut: false }), @@ -183,10 +179,10 @@ describe('PaymentsGleanService', () => { }); it('successfully calls GleanManager', async () => { - await paymentsGleanService.recordGenericSubManageEvent(mockEventData); + await aggregatorService.recordGenericSubManageEvent(mockEventData); expect( - paymentsGleanService.retrieveSubManageMetricsData + aggregatorService.retrieveSubManageMetricsData ).toHaveBeenCalledWith( mockEventData.commonMetrics, mockEventData.uid, @@ -200,16 +196,16 @@ describe('PaymentsGleanService', () => { it('does not call GleanManager if opted out', async () => { jest - .spyOn(paymentsGleanService, 'retrieveSubManageMetricsData') + .spyOn(aggregatorService, 'retrieveSubManageMetricsData') .mockResolvedValue( GleanMetricsDataFactory({ accounts: AccountsMetricsDataFactory({ metricsOptOut: true }), }) ); - await paymentsGleanService.recordGenericSubManageEvent(mockEventData); + await aggregatorService.recordGenericSubManageEvent(mockEventData); expect( - paymentsGleanService.retrieveSubManageMetricsData + aggregatorService.retrieveSubManageMetricsData ).toHaveBeenCalledWith( mockEventData.commonMetrics, mockEventData.uid, @@ -254,18 +250,18 @@ describe('PaymentsGleanService', () => { jest .spyOn(productConfigurationManager, 'getPageContentByPriceIds') .mockResolvedValue(mockPageContentUtil); - jest.spyOn(paymentsGleanService, 'mapExperimentationMetricsData'); - jest.spyOn(paymentsGleanService, 'mapStripeMetricsData'); - jest.spyOn(paymentsGleanService, 'mapAccountsMetricsData'); - jest.spyOn(paymentsGleanService, 'mapSubPlatCmsMetricsData'); - jest.spyOn(paymentsGleanService, 'mapSessionMetricsData'); + jest.spyOn(aggregatorService, 'mapExperimentationMetricsData'); + jest.spyOn(aggregatorService, 'mapStripeMetricsData'); + jest.spyOn(aggregatorService, 'mapAccountsMetricsData'); + jest.spyOn(aggregatorService, 'mapSubPlatCmsMetricsData'); + jest.spyOn(aggregatorService, 'mapSessionMetricsData'); jest .spyOn(nimbusManager, 'fetchExperiments') .mockResolvedValue(SubPlatNimbusResultFactory()); }); it('successfully retrieves all data', async () => { - await paymentsGleanService.retrieveSubManageMetricsData( + await aggregatorService.retrieveSubManageMetricsData( mockCommonMetrics, mockUid, mockSubscriptionId @@ -282,27 +278,27 @@ describe('PaymentsGleanService', () => { productConfigurationManager.getPageContentByPriceIds ).toHaveBeenCalledWith([mockPrice.id]); expect( - paymentsGleanService.mapExperimentationMetricsData + aggregatorService.mapExperimentationMetricsData ).toHaveBeenCalledWith(mockUid, mockCommonMetrics, mockCustomer); - expect(paymentsGleanService.mapStripeMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapStripeMetricsData).toHaveBeenCalledWith( mockCustomer, mockPrice, mockSubscription ); - expect(paymentsGleanService.mapAccountsMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapAccountsMetricsData).toHaveBeenCalledWith( mockUid, mockAccount ); expect( - paymentsGleanService.mapSubPlatCmsMetricsData + aggregatorService.mapSubPlatCmsMetricsData ).toHaveBeenCalledWith(mockSubscription, mockPageContentUtil); - expect(paymentsGleanService.mapSessionMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapSessionMetricsData).toHaveBeenCalledWith( mockCommonMetrics ); }); it('successfully complets without calling Stripe data', async () => { - await paymentsGleanService.retrieveSubManageMetricsData( + await aggregatorService.retrieveSubManageMetricsData( mockCommonMetrics, mockUid ); @@ -314,21 +310,21 @@ describe('PaymentsGleanService', () => { ).not.toHaveBeenCalled(); expect( - paymentsGleanService.mapExperimentationMetricsData + aggregatorService.mapExperimentationMetricsData ).toHaveBeenCalledWith(mockUid, mockCommonMetrics, undefined); - expect(paymentsGleanService.mapStripeMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapStripeMetricsData).toHaveBeenCalledWith( undefined, undefined, undefined ); - expect(paymentsGleanService.mapAccountsMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapAccountsMetricsData).toHaveBeenCalledWith( mockUid, mockAccount ); expect( - paymentsGleanService.mapSubPlatCmsMetricsData + aggregatorService.mapSubPlatCmsMetricsData ).toHaveBeenCalledWith(undefined, undefined); - expect(paymentsGleanService.mapSessionMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapSessionMetricsData).toHaveBeenCalledWith( mockCommonMetrics ); }); @@ -337,28 +333,28 @@ describe('PaymentsGleanService', () => { jest .spyOn(customerManager, 'retrieve') .mockRejectedValue(new Error('testing')); - await paymentsGleanService.retrieveSubManageMetricsData( + await aggregatorService.retrieveSubManageMetricsData( mockCommonMetrics, mockUid, mockSubscriptionId ); expect( - paymentsGleanService.mapExperimentationMetricsData + aggregatorService.mapExperimentationMetricsData ).toHaveBeenCalledWith(mockUid, mockCommonMetrics, undefined); - expect(paymentsGleanService.mapStripeMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapStripeMetricsData).toHaveBeenCalledWith( undefined, mockPrice, mockSubscription ); - expect(paymentsGleanService.mapAccountsMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapAccountsMetricsData).toHaveBeenCalledWith( mockUid, mockAccount ); expect( - paymentsGleanService.mapSubPlatCmsMetricsData + aggregatorService.mapSubPlatCmsMetricsData ).toHaveBeenCalledWith(mockSubscription, mockPageContentUtil); - expect(paymentsGleanService.mapSessionMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapSessionMetricsData).toHaveBeenCalledWith( mockCommonMetrics ); }); @@ -368,28 +364,28 @@ describe('PaymentsGleanService', () => { .spyOn(productConfigurationManager, 'getPageContentByPriceIds') .mockRejectedValue(new Error('testing')); - await paymentsGleanService.retrieveSubManageMetricsData( + await aggregatorService.retrieveSubManageMetricsData( mockCommonMetrics, mockUid, mockSubscriptionId ); expect( - paymentsGleanService.mapExperimentationMetricsData + aggregatorService.mapExperimentationMetricsData ).toHaveBeenCalledWith(mockUid, mockCommonMetrics, mockCustomer); - expect(paymentsGleanService.mapStripeMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapStripeMetricsData).toHaveBeenCalledWith( mockCustomer, mockPrice, mockSubscription ); - expect(paymentsGleanService.mapAccountsMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapAccountsMetricsData).toHaveBeenCalledWith( mockUid, mockAccount ); expect( - paymentsGleanService.mapSubPlatCmsMetricsData + aggregatorService.mapSubPlatCmsMetricsData ).toHaveBeenCalledWith(mockSubscription, undefined); - expect(paymentsGleanService.mapSessionMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapSessionMetricsData).toHaveBeenCalledWith( mockCommonMetrics ); }); @@ -399,28 +395,28 @@ describe('PaymentsGleanService', () => { .spyOn(accountManager, 'getAccounts') .mockRejectedValue(new Error('testing')); - await paymentsGleanService.retrieveSubManageMetricsData( + await aggregatorService.retrieveSubManageMetricsData( mockCommonMetrics, mockUid, mockSubscriptionId ); expect( - paymentsGleanService.mapExperimentationMetricsData + aggregatorService.mapExperimentationMetricsData ).toHaveBeenCalledWith(mockUid, mockCommonMetrics, mockCustomer); - expect(paymentsGleanService.mapStripeMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapStripeMetricsData).toHaveBeenCalledWith( mockCustomer, mockPrice, mockSubscription ); - expect(paymentsGleanService.mapAccountsMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapAccountsMetricsData).toHaveBeenCalledWith( mockUid, undefined ); expect( - paymentsGleanService.mapSubPlatCmsMetricsData + aggregatorService.mapSubPlatCmsMetricsData ).toHaveBeenCalledWith(mockSubscription, mockPageContentUtil); - expect(paymentsGleanService.mapSessionMetricsData).toHaveBeenCalledWith( + expect(aggregatorService.mapSessionMetricsData).toHaveBeenCalledWith( mockCommonMetrics ); }); @@ -464,7 +460,7 @@ describe('PaymentsGleanService', () => { ); it('successfully returns all data', () => { - const result = paymentsGleanService.mapStripeMetricsData( + const result = aggregatorService.mapStripeMetricsData( mockCustomer, mockPrice, mockSubscription @@ -484,7 +480,7 @@ describe('PaymentsGleanService', () => { }); it('successfully returns undefined data', () => { - const result = paymentsGleanService.mapStripeMetricsData( + const result = aggregatorService.mapStripeMetricsData( undefined, undefined, undefined @@ -507,7 +503,7 @@ describe('PaymentsGleanService', () => { const mockUid = mockAccount.uid.toString(); it('successfully returns all data', () => { - const result = paymentsGleanService.mapAccountsMetricsData( + const result = aggregatorService.mapAccountsMetricsData( mockUid, mockAccount ); @@ -520,7 +516,7 @@ describe('PaymentsGleanService', () => { }); it('successfully returns undefined data', () => { - const result = paymentsGleanService.mapAccountsMetricsData( + const result = aggregatorService.mapAccountsMetricsData( mockUid, undefined ); @@ -551,7 +547,7 @@ describe('PaymentsGleanService', () => { PageContentByPriceIdByPriceIdsResultFactory() ); it('successfully returns all data', () => { - const result = paymentsGleanService.mapSubPlatCmsMetricsData( + const result = aggregatorService.mapSubPlatCmsMetricsData( mockSubscription, mockPageContentUtil ); @@ -563,7 +559,7 @@ describe('PaymentsGleanService', () => { }); it('successfully returns undefined data', () => { - const result = paymentsGleanService.mapSubPlatCmsMetricsData(); + const result = aggregatorService.mapSubPlatCmsMetricsData(); expect(result).toEqual({ offeringId: undefined, @@ -580,7 +576,7 @@ describe('PaymentsGleanService', () => { }); const result = - paymentsGleanService.mapSessionMetricsData(mockCommonMetrics); + aggregatorService.mapSessionMetricsData(mockCommonMetrics); expect(result).toEqual({ locale: 'en', ipAddress: mockCommonMetrics.ipAddress, @@ -593,7 +589,7 @@ describe('PaymentsGleanService', () => { const mockCommonMetrics = CommonMetricsFactory(); const result = - paymentsGleanService.mapSessionMetricsData(mockCommonMetrics); + aggregatorService.mapSessionMetricsData(mockCommonMetrics); expect(result).toEqual({ locale: undefined, ipAddress: mockCommonMetrics.ipAddress, @@ -636,7 +632,7 @@ describe('PaymentsGleanService', () => { }); it('successfully returns data fetched from nimbus', async () => { - const result = await paymentsGleanService.mapExperimentationMetricsData( + const result = await aggregatorService.mapExperimentationMetricsData( mockUid, mockCommonMetrics, mockCustomer @@ -651,7 +647,7 @@ describe('PaymentsGleanService', () => { jest .spyOn(nimbusManager, 'fetchExperiments') .mockRejectedValue(new Error('testing')); - const result = await paymentsGleanService.mapExperimentationMetricsData( + const result = await aggregatorService.mapExperimentationMetricsData( mockUid, mockCommonMetrics, mockCustomer diff --git a/libs/payments/metrics/src/lib/glean/glean.service.ts b/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.service.ts similarity index 94% rename from libs/payments/metrics/src/lib/glean/glean.service.ts rename to libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.service.ts index ce7ade2c2ef..645ce0d8864 100644 --- a/libs/payments/metrics/src/lib/glean/glean.service.ts +++ b/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.service.ts @@ -13,27 +13,27 @@ import { PageContentByPriceIdsResultUtil, ProductConfigurationManager, } from '@fxa/shared/cms'; -import type { - AccountsMetricsData, - CommonMetrics, - ExperimentationData, - GenericGleanSubManageEvent, - GleanMetricsData, - SessionMetricsData, - StripeMetricsData, - SubPlatCmsMetricsData, -} from './glean.types'; +import { + PaymentsGleanManager, + type AccountsMetricsData, + type CommonMetrics, + type ExperimentationData, + type GenericGleanSubManageEvent, + type GleanMetricsData, + type SessionMetricsData, + type StripeMetricsData, + type SubPlatCmsMetricsData, +} from '@fxa/payments/metrics'; import type { StripeCustomer, StripePrice, StripeSubscription, } from '@fxa/payments/stripe'; -import { getPriceFromSubscription } from 'libs/payments/customer/src/lib/util/getPriceFromSubscription'; -import { PaymentsGleanManager } from './glean.manager'; +import { getPriceFromSubscription } from '@fxa/payments/customer'; import { Logger, Injectable } from '@nestjs/common'; @Injectable() -export class PaymentsGleanService { +export class PaymentsMetricsAggregatorService { constructor( private accountManager: AccountManager, private customerManager: CustomerManager, diff --git a/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.test-provider.ts b/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.test-provider.ts new file mode 100644 index 00000000000..85067ac7110 --- /dev/null +++ b/libs/payments/metrics-aggregator/src/lib/payments-metrics-aggregator.test-provider.ts @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 { PaymentsMetricsAggregatorService } from './payments-metrics-aggregator.service'; + +export const MockPaymentsMetricsAggregatorServiceFactory = { + provide: PaymentsMetricsAggregatorService, + useFactory: () => + ({ + handleUserDelete: () => {}, + recordGenericSubManageEvent: () => {}, + retrieveSubManageMetricsData: () => {}, + mapStripeMetricsData: () => {}, + mapAccountsMetricsData: () => {}, + mapSubPlatCmsMetricsData: () => {}, + mapSessionMetricsData: () => {}, + mapExperimentationMetricsData: () => {}, + }) as any, +}; diff --git a/libs/payments/metrics-aggregator/tsconfig.json b/libs/payments/metrics-aggregator/tsconfig.json new file mode 100644 index 00000000000..25f7201d870 --- /dev/null +++ b/libs/payments/metrics-aggregator/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs" + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/shared/nestjs/customs/tsconfig.lib.json b/libs/payments/metrics-aggregator/tsconfig.lib.json similarity index 83% rename from libs/shared/nestjs/customs/tsconfig.lib.json rename to libs/payments/metrics-aggregator/tsconfig.lib.json index 18f2d37a19a..4befa7f0990 100644 --- a/libs/shared/nestjs/customs/tsconfig.lib.json +++ b/libs/payments/metrics-aggregator/tsconfig.lib.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "declaration": true, "types": ["node"] }, diff --git a/libs/shared/nestjs/customs/tsconfig.spec.json b/libs/payments/metrics-aggregator/tsconfig.spec.json similarity index 84% rename from libs/shared/nestjs/customs/tsconfig.spec.json rename to libs/payments/metrics-aggregator/tsconfig.spec.json index 6668655fc39..69a251f328c 100644 --- a/libs/shared/nestjs/customs/tsconfig.spec.json +++ b/libs/payments/metrics-aggregator/tsconfig.spec.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../../../dist/out-tsc", + "outDir": "../../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"] }, diff --git a/libs/payments/metrics/package.json b/libs/payments/metrics/package.json index 749e02e1b97..232da79bb5f 100644 --- a/libs/payments/metrics/package.json +++ b/libs/payments/metrics/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/payments/metrics", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/payments/metrics/project.json b/libs/payments/metrics/project.json index 229178fcce4..b2e6fd0a124 100644 --- a/libs/payments/metrics/project.json +++ b/libs/payments/metrics/project.json @@ -6,16 +6,22 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "dependsOn": ["^build", "glean-generate", "glean-generate-frontend"], + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/payments/metrics", "main": "libs/payments/metrics/src/index.ts", "tsConfig": "libs/payments/metrics/tsconfig.lib.json", - "assets": ["libs/payments/metrics/*.md"], - "declaration": true - }, - "dependsOn": ["glean-generate", "glean-generate-frontend"] + "assets": ["libs/payments/metrics/*.md"] + } }, "compile": { "command": "tsc -p libs/payments/metrics/tsconfig.json --noEmit", @@ -23,16 +29,38 @@ }, "glean-generate": { "dependsOn": ["glean-lint"], + "cache": true, + "inputs": [ + "{workspaceRoot}/libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml" + ], + "outputs": [ + "{projectRoot}/src/lib/glean/__generated__/server_events.ts" + ], "command": "yarn glean translate libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml -f typescript_server -o libs/payments/metrics/src/lib/glean/__generated__" }, "glean-lint": { + "cache": true, + "inputs": [ + "{workspaceRoot}/libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml" + ], "command": "yarn glean glinter libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml" }, "glean-generate-frontend": { "dependsOn": ["glean-lint-frontend"], + "cache": true, + "inputs": [ + "{workspaceRoot}/libs/shared/metrics/glean/src/registry/subplat-frontend-metrics.yaml" + ], + "outputs": [ + "{projectRoot}/src/lib/glean/__generated__/subscriptions.ts" + ], "command": "yarn glean translate libs/shared/metrics/glean/src/registry/subplat-frontend-metrics.yaml -f typescript -o libs/payments/metrics/src/lib/glean/__generated__" }, "glean-lint-frontend": { + "cache": true, + "inputs": [ + "{workspaceRoot}/libs/shared/metrics/glean/src/registry/subplat-frontend-metrics.yaml" + ], "command": "yarn glean glinter libs/shared/metrics/glean/src/registry/subplat-frontend-metrics.yaml" }, "test-unit": { diff --git a/libs/payments/metrics/src/index.ts b/libs/payments/metrics/src/index.ts index 499a442e2a2..5c3d1e9914d 100644 --- a/libs/payments/metrics/src/index.ts +++ b/libs/payments/metrics/src/index.ts @@ -4,7 +4,6 @@ export * from './lib/glean/glean.types'; export * from './lib/glean/glean.manager'; -export * from './lib/glean/glean.service'; export * from './lib/glean/glean.config'; export * from './lib/glean/glean.factory'; export * from './lib/glean/glean.test-provider'; diff --git a/libs/payments/metrics/src/lib/glean/glean.factory.ts b/libs/payments/metrics/src/lib/glean/glean.factory.ts index 588c0206b83..f29df3ddbda 100644 --- a/libs/payments/metrics/src/lib/glean/glean.factory.ts +++ b/libs/payments/metrics/src/lib/glean/glean.factory.ts @@ -26,9 +26,9 @@ import { type SessionMetricsData, type StripeMetricsData, type SubPlatCmsMetricsData, + TaxAddress, + SubplatInterval, } from './glean.types'; -import { ResultCartFactory } from '@fxa/payments/cart'; -import { SubplatInterval, TaxAddressFactory } from '@fxa/payments/customer'; export const CheckoutParamsFactory = ( override?: Record @@ -61,21 +61,15 @@ export const CommonMetricsFactory = ( export const CartMetricsFactory = ( override?: Partial -): CartMetrics => { - const resultCart = ResultCartFactory({ - ...override, - }); - - return { - uid: resultCart.uid, - errorReasonId: resultCart.errorReasonId, - couponCode: resultCart.couponCode, - currency: faker.finance.currencyCode().toLowerCase(), - stripeCustomerId: `cus_${faker.string.alphanumeric({ length: 14 })}`, - taxAddress: resultCart.taxAddress, - ...override, - }; -}; +): CartMetrics => ({ + uid: undefined, + errorReasonId: null, + couponCode: undefined, + currency: faker.finance.currencyCode().toLowerCase(), + stripeCustomerId: `cus_${faker.string.alphanumeric({ length: 14 })}`, + taxAddress: undefined, + ...override, +}); export const CmsMetricsDataFactory = ( override?: Partial @@ -106,10 +100,7 @@ export const SubscriptionCancellationDataFactory = ( export const TrialConversionDataFactory = ( override?: Partial ): TrialConversionData => ({ - conversionStatus: faker.helpers.arrayElement([ - 'successful', - 'unsuccessful', - ]), + conversionStatus: faker.helpers.arrayElement(['successful', 'unsuccessful']), providerEventId: `evt_${faker.string.alphanumeric({ length: 24 })}`, productId: `prod_${faker.string.alphanumeric({ length: 14 })}`, billingCountry: faker.location.countryCode(), @@ -132,6 +123,14 @@ export const SubManageMetricsArgsFactory = ( ...override, }); +export const TaxAddressFactory = ( + override?: Partial +): TaxAddress => ({ + countryCode: faker.location.countryCode(), + postalCode: faker.location.zipCode(), + ...override, +}); + export const GenericGleanSubManageEventFactory = ( override?: Partial ): GenericGleanSubManageEvent => ({ diff --git a/libs/payments/metrics/src/lib/glean/glean.manager.spec.ts b/libs/payments/metrics/src/lib/glean/glean.manager.spec.ts index f8f044fc57f..4d5c334c754 100644 --- a/libs/payments/metrics/src/lib/glean/glean.manager.spec.ts +++ b/libs/payments/metrics/src/lib/glean/glean.manager.spec.ts @@ -11,13 +11,15 @@ import { SubscriptionCancellationDataFactory, TrialConversionDataFactory, } from './glean.factory'; -import { PaymentsGleanProvider } from './glean.types'; +import { + PaymentsGleanProvider, + SubPlatPaymentMethodType, +} from './glean.types'; import { MockPaymentsGleanFactory } from './glean.test-provider'; import { MockPaymentsGleanConfigProvider, PaymentsGleanConfig, } from './glean.config'; -import { SubPlatPaymentMethodType } from '@fxa/payments/customer'; const mockCommonMetricsData = { commonMetricsData: CommonMetricsFactory(), diff --git a/libs/payments/metrics/src/lib/glean/glean.manager.ts b/libs/payments/metrics/src/lib/glean/glean.manager.ts index 35eb3b15b36..14b065c4496 100644 --- a/libs/payments/metrics/src/lib/glean/glean.manager.ts +++ b/libs/payments/metrics/src/lib/glean/glean.manager.ts @@ -7,6 +7,7 @@ import { CartMetrics, CmsMetricsData, CommonMetrics, + PaymentProvidersType, PaymentsGleanProvider, SubscriptionCancellationData, TrialConversionData, @@ -15,12 +16,9 @@ import { type SessionMetricsData, type StripeMetricsData, type SubPlatCmsMetricsData, + type SubPlatPaymentMethodType, } from './glean.types'; import { Inject, Injectable } from '@nestjs/common'; -import { - PaymentProvidersType, - type SubPlatPaymentMethodType, -} from '@fxa/payments/customer'; import { type PaymentsGleanServerEventsLogger } from './glean.provider'; import { mapSession } from './utils/mapSession'; import { mapUtm } from './utils/mapUtm'; diff --git a/libs/payments/metrics/src/lib/glean/glean.test-provider.ts b/libs/payments/metrics/src/lib/glean/glean.test-provider.ts index a8b864d4341..e151dc56449 100644 --- a/libs/payments/metrics/src/lib/glean/glean.test-provider.ts +++ b/libs/payments/metrics/src/lib/glean/glean.test-provider.ts @@ -1,4 +1,7 @@ -import { PaymentsGleanService } from './glean.service'; +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 { PaymentsGleanProvider } from './glean.types'; /** @@ -19,18 +22,3 @@ export const MockPaymentsGleanFactory = { recordSubscriptionTrialConverted: () => {}, }) as any, }; - -export const MockPaymentsGleanServiceFactory = { - provide: PaymentsGleanService, - useFactory: () => - ({ - handleUserDelete: () => {}, - recordGenericSubManageEvent: () => {}, - retrieveSubManageMetricsData: () => {}, - mapStripeMetricsData: () => {}, - mapAccountsMetricsData: () => {}, - mapSubPlatCmsMetricsData: () => {}, - mapSessionMetricsData: () => {}, - mapExperimentationMetricsData: () => {}, - }) as any, -}; diff --git a/libs/payments/metrics/src/lib/glean/glean.types.ts b/libs/payments/metrics/src/lib/glean/glean.types.ts index d4a9789e180..c62c15d46bf 100644 --- a/libs/payments/metrics/src/lib/glean/glean.types.ts +++ b/libs/payments/metrics/src/lib/glean/glean.types.ts @@ -2,9 +2,6 @@ * 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 type { ResultCart } from '@fxa/payments/cart'; -import type { SubplatInterval } from '@fxa/payments/customer'; - export const CheckoutTypes = [ 'new_account', 'existing_account', @@ -12,7 +9,21 @@ export const CheckoutTypes = [ 'unknown', ] as const; export type CheckoutTypesType = (typeof CheckoutTypes)[number]; -import type { TaxAddress } from '@fxa/payments/customer'; + +// Should match type TaxAddress in @fxa/payments/customer +export interface TaxAddress { + countryCode: string; + postalCode: string; +} + +// Should match enum SubplatInterval in @fxa/payments/customer +export enum SubplatInterval { + Daily = 'daily', + Weekly = 'weekly', + Monthly = 'monthly', + HalfYearly = 'halfyearly', + Yearly = 'yearly', +} export const PaymentProvidersTypePartial = [ 'stripe', @@ -21,6 +32,19 @@ export const PaymentProvidersTypePartial = [ 'paypal', ] as const; +// Should match type PaymentProvidersType in @fxa/payments/customer +export type PaymentProvidersType = (typeof PaymentProvidersTypePartial)[number]; + +// Should match enum SubPlatPaymentMethodType in @fxa/payments/customer +export enum SubPlatPaymentMethodType { + PayPal = 'external_paypal', + Stripe = 'stripe', + Card = 'card', + ApplePay = 'apple_pay', + GooglePay = 'google_pay', + Link = 'link', +} + export type CommonMetrics = { ipAddress: string; deviceType: string; @@ -31,15 +55,14 @@ export type CommonMetrics = { searchParams: Record; }; -export type CartMetrics = Pick< - ResultCart, - | 'uid' - | 'errorReasonId' - | 'couponCode' - | 'currency' - | 'stripeCustomerId' - | 'taxAddress' ->; +export type CartMetrics = { + uid?: string; + errorReasonId?: string | null; + couponCode?: string | null; + currency?: string | null; + stripeCustomerId?: string | null; + taxAddress?: TaxAddress | null; +}; export type ExperimentationData = { nimbusUserId: string; diff --git a/libs/payments/metrics/src/lib/glean/utils/mapParams.ts b/libs/payments/metrics/src/lib/glean/utils/mapParams.ts index 2157c19c095..3857efaa28d 100644 --- a/libs/payments/metrics/src/lib/glean/utils/mapParams.ts +++ b/libs/payments/metrics/src/lib/glean/utils/mapParams.ts @@ -1,7 +1,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * 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 { SubplatInterval } from '@fxa/payments/customer'; +import { SubplatInterval } from '../glean.types'; import { normalizeGleanFalsyValues } from './normalizeGleanFalsyValues'; export function mapParams(params: Record) { diff --git a/libs/payments/metrics/src/lib/glean/utils/mapSubscription.spec.ts b/libs/payments/metrics/src/lib/glean/utils/mapSubscription.spec.ts index 3c7eb3b8cb1..56cf62e031e 100644 --- a/libs/payments/metrics/src/lib/glean/utils/mapSubscription.spec.ts +++ b/libs/payments/metrics/src/lib/glean/utils/mapSubscription.spec.ts @@ -9,7 +9,7 @@ import { CheckoutParamsFactory, } from '../glean.factory'; import { mapSubscription } from './mapSubscription'; -import { SubPlatPaymentMethodType } from '@fxa/payments/customer'; +import { SubPlatPaymentMethodType } from '../glean.types'; describe('mapSubscription', () => { it('should map all values', () => { diff --git a/libs/payments/metrics/src/lib/glean/utils/mapSubscription.ts b/libs/payments/metrics/src/lib/glean/utils/mapSubscription.ts index 890ddca2ebc..a302f6ff38b 100644 --- a/libs/payments/metrics/src/lib/glean/utils/mapSubscription.ts +++ b/libs/payments/metrics/src/lib/glean/utils/mapSubscription.ts @@ -5,9 +5,10 @@ import { CartMetrics, CmsMetricsData, CommonMetrics, + type PaymentProvidersType, + type SubPlatPaymentMethodType, type SubscriptionCancellationData, } from '../glean.types'; -import { PaymentProvidersType, SubPlatPaymentMethodType } from '@fxa/payments/customer'; import { determineCheckoutType } from './determineCheckoutType'; import { mapParams } from './mapParams'; import { normalizeGleanFalsyValues } from './normalizeGleanFalsyValues'; diff --git a/libs/payments/paypal/project.json b/libs/payments/paypal/project.json index 6b054faf470..4ad3086e4f7 100644 --- a/libs/payments/paypal/project.json +++ b/libs/payments/paypal/project.json @@ -6,13 +6,18 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/paypal/src/index.ts", "outputPath": "dist/libs/payments/paypal", - "outputFileName": "main.js", "tsConfig": "libs/payments/paypal/tsconfig.lib.json", "assets": [ { @@ -20,16 +25,7 @@ "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/stripe/package.json b/libs/payments/stripe/package.json index a7bee9df242..d6e657f0991 100644 --- a/libs/payments/stripe/package.json +++ b/libs/payments/stripe/package.json @@ -1,4 +1,4 @@ { - "name": "payments/stripe", + "name": "@fxa/payments/stripe", "version": "0.0.0" } diff --git a/libs/payments/stripe/project.json b/libs/payments/stripe/project.json index 799281ebbe6..192924b3c58 100644 --- a/libs/payments/stripe/project.json +++ b/libs/payments/stripe/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib:payments"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/payments/stripe/src/index.ts", "outputPath": "dist/libs/payments/stripe", - "outputFileName": "main.js", "tsConfig": "libs/payments/stripe/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/payments/stripe/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/payments/stripe/src/lib/factories/price.factory.ts b/libs/payments/stripe/src/lib/factories/price.factory.ts index 5d4aa9ee623..cf7f3324070 100644 --- a/libs/payments/stripe/src/lib/factories/price.factory.ts +++ b/libs/payments/stripe/src/lib/factories/price.factory.ts @@ -22,7 +22,8 @@ export const StripePriceFactory = ( const currency = override?.currency?.toLowerCase() || faker.finance.currencyCode().toLowerCase(); - const unit_amount = override?.unit_amount || faker.number.int({ max: 1000 }); + const unit_amount = + override?.unit_amount || faker.number.int({ min: 1, max: 1000 }); const unit_amount_decimal = override?.unit_amount_decimal || faker.commerce.price({ min: 1000 }); return { diff --git a/libs/payments/ui/src/lib/nestapp/app.module.ts b/libs/payments/ui/src/lib/nestapp/app.module.ts index fd9f7b47194..01899573897 100644 --- a/libs/payments/ui/src/lib/nestapp/app.module.ts +++ b/libs/payments/ui/src/lib/nestapp/app.module.ts @@ -42,10 +42,8 @@ import { CustomerSessionManager, SetupIntentManager, } from '@fxa/payments/customer'; -import { - PaymentsGleanManager, - PaymentsGleanService, -} from '@fxa/payments/metrics'; +import { PaymentsGleanManager } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { PaymentsGleanFactory } from '@fxa/payments/metrics/provider'; import { AccountCustomerManager, StripeClient } from '@fxa/payments/stripe'; import { @@ -156,7 +154,7 @@ import { NimbusManager } from '@fxa/payments/experiments'; SubscriptionManager, PaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaymentsEmitterService, StripeEventManager, SubscriptionEventsService, diff --git a/libs/payments/webhooks/package.json b/libs/payments/webhooks/package.json index ab7319314da..b3b861f0b1e 100644 --- a/libs/payments/webhooks/package.json +++ b/libs/payments/webhooks/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/payments/webhooks", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/payments/webhooks/project.json b/libs/payments/webhooks/project.json index c87a34748a6..c04f6bb1814 100644 --- a/libs/payments/webhooks/project.json +++ b/libs/payments/webhooks/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/payments/webhooks", "main": "libs/payments/webhooks/src/index.ts", "tsConfig": "libs/payments/webhooks/tsconfig.lib.json", "assets": ["libs/payments/webhooks/*.md"], - "declaration": true + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/payments/webhooks/src/lib/fxa-webhooks.controller.spec.ts b/libs/payments/webhooks/src/lib/fxa-webhooks.controller.spec.ts index 3d49fadcb66..ae4e5532fe5 100644 --- a/libs/payments/webhooks/src/lib/fxa-webhooks.controller.spec.ts +++ b/libs/payments/webhooks/src/lib/fxa-webhooks.controller.spec.ts @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Test } from '@nestjs/testing'; -import { MockPaymentsGleanServiceFactory } from '@fxa/payments/metrics'; +import { MockPaymentsMetricsAggregatorServiceFactory } from '@fxa/payments/metrics-aggregator'; import { AccountCustomerManager, MockStripeConfigProvider, @@ -29,7 +29,7 @@ describe('FxaWebhooksController', () => { MockFxaWebhookConfigProvider, MockStatsDProvider, MockLoggerProvider, - MockPaymentsGleanServiceFactory, + MockPaymentsMetricsAggregatorServiceFactory, AccountCustomerManager, MockAccountDatabaseNestFactory, CustomerManager, diff --git a/libs/payments/webhooks/src/lib/fxa-webhooks.service.spec.ts b/libs/payments/webhooks/src/lib/fxa-webhooks.service.spec.ts index 2c899f359f9..5a04bdafe7e 100644 --- a/libs/payments/webhooks/src/lib/fxa-webhooks.service.spec.ts +++ b/libs/payments/webhooks/src/lib/fxa-webhooks.service.spec.ts @@ -15,9 +15,9 @@ import { MockLoggerProvider } from '@fxa/shared/log'; import { MockAccountDatabaseNestFactory } from '@fxa/shared/db/mysql/account'; import type { StatsD } from 'hot-shots'; import { - MockPaymentsGleanServiceFactory, - PaymentsGleanService, -} from '@fxa/payments/metrics'; + MockPaymentsMetricsAggregatorServiceFactory, + PaymentsMetricsAggregatorService, +} from '@fxa/payments/metrics-aggregator'; import { AccountCustomerManager, AccountCustomerNotFoundError, @@ -149,7 +149,7 @@ describe('FxaWebhookService', () => { let service: FxaWebhookService; let statsd: StatsD; let logger: LoggerService; - let paymentsGleanService: PaymentsGleanService; + let paymentsGleanService: PaymentsMetricsAggregatorService; let accountCustomerManager: AccountCustomerManager; let customerManager: CustomerManager; let originalFetch: typeof global.fetch; @@ -164,7 +164,7 @@ describe('FxaWebhookService', () => { MockFxaWebhookConfigProvider, MockStatsDProvider, MockLoggerProvider, - MockPaymentsGleanServiceFactory, + MockPaymentsMetricsAggregatorServiceFactory, AccountCustomerManager, MockAccountDatabaseNestFactory, CustomerManager, @@ -176,7 +176,7 @@ describe('FxaWebhookService', () => { service = module.get(FxaWebhookService); statsd = module.get(StatsDService); logger = module.get(Logger); - paymentsGleanService = module.get(PaymentsGleanService); + paymentsGleanService = module.get(PaymentsMetricsAggregatorService); accountCustomerManager = module.get(AccountCustomerManager); customerManager = module.get(CustomerManager); diff --git a/libs/payments/webhooks/src/lib/fxa-webhooks.service.ts b/libs/payments/webhooks/src/lib/fxa-webhooks.service.ts index 7e7a794dba0..61197d68ceb 100644 --- a/libs/payments/webhooks/src/lib/fxa-webhooks.service.ts +++ b/libs/payments/webhooks/src/lib/fxa-webhooks.service.ts @@ -15,7 +15,7 @@ import { StaleWhileRevalidateWithFallbackStrategy, } from '@fxa/shared/db/type-cacheable'; import { StatsDService } from '@fxa/shared/metrics/statsd'; -import { PaymentsGleanService } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { AccountCustomerManager, AccountCustomerNotFoundError, @@ -67,7 +67,7 @@ export class FxaWebhookService { private fxaWebhookConfig: FxaWebhookConfig, @Inject(StatsDService) private statsd: StatsD, @Inject(Logger) private log: LoggerService, - private paymentsGleanService: PaymentsGleanService, + private paymentsGleanService: PaymentsMetricsAggregatorService, private accountCustomerManager: AccountCustomerManager, private customerManager: CustomerManager ) { diff --git a/libs/payments/webhooks/src/lib/stripe-event.manager.spec.ts b/libs/payments/webhooks/src/lib/stripe-event.manager.spec.ts index 86f1cb34e63..b62a9d3d5c7 100644 --- a/libs/payments/webhooks/src/lib/stripe-event.manager.spec.ts +++ b/libs/payments/webhooks/src/lib/stripe-event.manager.spec.ts @@ -33,8 +33,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { MockStrapiClientConfigProvider, ProductConfigurationManager, @@ -112,7 +112,7 @@ describe('StripeEventManager', () => { CurrencyManager, MockCurrencyConfigProvider, PaymentsGleanManager, - PaymentsGleanService, + PaymentsMetricsAggregatorService, MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, ProductConfigurationManager, diff --git a/libs/payments/webhooks/src/lib/stripe-webhooks.controller.spec.ts b/libs/payments/webhooks/src/lib/stripe-webhooks.controller.spec.ts index 893e9e9fb4a..d019fc1266a 100644 --- a/libs/payments/webhooks/src/lib/stripe-webhooks.controller.spec.ts +++ b/libs/payments/webhooks/src/lib/stripe-webhooks.controller.spec.ts @@ -29,8 +29,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { MockStrapiClientConfigProvider, ProductConfigurationManager, @@ -89,7 +89,7 @@ describe('StripeWebhooksController', () => { PayPalClient, CurrencyManager, MockCurrencyConfigProvider, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaymentsGleanManager, MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, diff --git a/libs/payments/webhooks/src/lib/stripe-webhooks.service.spec.ts b/libs/payments/webhooks/src/lib/stripe-webhooks.service.spec.ts index afc31c3ee4d..177e06e15c1 100644 --- a/libs/payments/webhooks/src/lib/stripe-webhooks.service.spec.ts +++ b/libs/payments/webhooks/src/lib/stripe-webhooks.service.spec.ts @@ -32,8 +32,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { MockStrapiClientConfigProvider, ProductConfigurationManager, @@ -102,7 +102,7 @@ describe('StripeWebhookService', () => { PayPalClient, CurrencyManager, MockCurrencyConfigProvider, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaymentsGleanManager, MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, diff --git a/libs/payments/webhooks/src/lib/subscription-handler.service.spec.ts b/libs/payments/webhooks/src/lib/subscription-handler.service.spec.ts index 9d3dcc3cadf..048106948c9 100644 --- a/libs/payments/webhooks/src/lib/subscription-handler.service.spec.ts +++ b/libs/payments/webhooks/src/lib/subscription-handler.service.spec.ts @@ -39,8 +39,8 @@ import { MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, PaymentsGleanManager, - PaymentsGleanService, } from '@fxa/payments/metrics'; +import { PaymentsMetricsAggregatorService } from '@fxa/payments/metrics-aggregator'; import { MockStrapiClientConfigProvider, ProductConfigurationManager, @@ -113,7 +113,7 @@ describe('SubscriptionEventsService', () => { PayPalClient, CurrencyManager, MockCurrencyConfigProvider, - PaymentsGleanService, + PaymentsMetricsAggregatorService, PaymentsGleanManager, MockPaymentsGleanConfigProvider, MockPaymentsGleanFactory, diff --git a/libs/profile/client/package.json b/libs/profile/client/package.json index b0b290dfe74..93ed58cc369 100644 --- a/libs/profile/client/package.json +++ b/libs/profile/client/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/profile/client", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/profile/client/project.json b/libs/profile/client/project.json index d2f189825bf..bd7c0843a7f 100644 --- a/libs/profile/client/project.json +++ b/libs/profile/client/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/profile/client", "main": "libs/profile/client/src/index.ts", "tsConfig": "libs/profile/client/tsconfig.lib.json", "assets": ["libs/profile/client/*.md"], - "declaration": true + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/account/account/project.json b/libs/shared/account/account/project.json index f25982c12be..b544a652515 100644 --- a/libs/shared/account/account/project.json +++ b/libs/shared/account/account/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/account/account/src/index.ts", "outputPath": "dist/libs/shared/account/account", - "outputFileName": "main.js", "tsConfig": "libs/shared/account/account/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/account/account/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/assets/project.json b/libs/shared/assets/project.json index 6b053260ef2..6b7209bc7ec 100644 --- a/libs/shared/assets/project.json +++ b/libs/shared/assets/project.json @@ -5,6 +5,13 @@ "projectType": "library", "targets": { "build": { + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { diff --git a/libs/shared/cloud-tasks/project.json b/libs/shared/cloud-tasks/project.json index 1d68b8010af..fd98fb75622 100644 --- a/libs/shared/cloud-tasks/project.json +++ b/libs/shared/cloud-tasks/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/cloud-tasks/src/index.ts", "outputPath": "dist/libs/shared/cloud-tasks", - "outputFileName": "main.js", "tsConfig": "libs/shared/cloud-tasks/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/cloud-tasks/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/cms/project.json b/libs/shared/cms/project.json index c0d56d735dc..63a46aa3064 100644 --- a/libs/shared/cms/project.json +++ b/libs/shared/cms/project.json @@ -12,31 +12,26 @@ } }, "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/cms/src/index.ts", "outputPath": "dist/libs/shared/cms", - "outputFileName": "main.js", "tsConfig": "libs/shared/cms/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/cms/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/db/firestore/project.json b/libs/shared/db/firestore/project.json index 2dc1dbde25f..ad0fa418ffb 100644 --- a/libs/shared/db/firestore/project.json +++ b/libs/shared/db/firestore/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/db/firestore/src/index.ts", "outputPath": "dist/libs/shared/db/firestore", - "outputFileName": "main.js", "tsConfig": "libs/shared/db/firestore/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/db/firestore/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/db/mysql/account/project.json b/libs/shared/db/mysql/account/project.json index 4623aa4d9a1..34d11fcd98b 100644 --- a/libs/shared/db/mysql/account/project.json +++ b/libs/shared/db/mysql/account/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/db/mysql/account/src/index.ts", "outputPath": "dist/libs/shared/db/mysql/account", - "outputFileName": "main.js", "tsConfig": "libs/shared/db/mysql/account/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/db/mysql/account/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/db/mysql/core/project.json b/libs/shared/db/mysql/core/project.json index fbdd06f8ac8..25cf734ac2f 100644 --- a/libs/shared/db/mysql/core/project.json +++ b/libs/shared/db/mysql/core/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/db/mysql/core/src/index.ts", "outputPath": "dist/libs/shared/db/mysql/core", - "outputFileName": "main.js", "tsConfig": "libs/shared/db/mysql/core/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/db/mysql/core/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/db/type-cacheable/project.json b/libs/shared/db/type-cacheable/project.json index dd14ab15ede..10d4b7a8cf9 100644 --- a/libs/shared/db/type-cacheable/project.json +++ b/libs/shared/db/type-cacheable/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/db/type-cacheable/src/index.ts", "outputPath": "dist/libs/shared/db/type-cacheable", - "outputFileName": "main.js", "tsConfig": "libs/shared/db/type-cacheable/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/db/type-cacheable/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/error/project.json b/libs/shared/error/project.json index 496b5868925..f07017606bd 100644 --- a/libs/shared/error/project.json +++ b/libs/shared/error/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/error/src/index.ts", "outputPath": "dist/libs/shared/error", - "outputFileName": "main.js", "tsConfig": "libs/shared/error/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/error/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/error/src/index.ts b/libs/shared/error/src/index.ts index c0a5997d9e1..b8c9a63102b 100644 --- a/libs/shared/error/src/index.ts +++ b/libs/shared/error/src/index.ts @@ -1,5 +1,13 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * 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/. */ -export { BaseError, BaseMultiError, TypeError, GENERIC_ERROR_MESSAGE } from './lib/error'; -export { SanitizeExceptions } from './lib/sanitizeExceptionsDecorator'; +export { + BaseError, + BaseMultiError, + TypeError, + GENERIC_ERROR_MESSAGE, +} from './lib/error'; +export { + SanitizeExceptions, + handleException, +} from './lib/sanitizeExceptionsDecorator'; diff --git a/libs/shared/experiments/package.json b/libs/shared/experiments/package.json index 320007c223e..8a7d93cfe00 100644 --- a/libs/shared/experiments/package.json +++ b/libs/shared/experiments/package.json @@ -1,9 +1,4 @@ { "name": "@fxa/shared/experiments", - "version": "0.0.1", - "private": true, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "dependencies": {} + "version": "0.0.1" } diff --git a/libs/shared/experiments/project.json b/libs/shared/experiments/project.json index ebbdc29183f..841a2073736 100644 --- a/libs/shared/experiments/project.json +++ b/libs/shared/experiments/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/experiments", "main": "libs/shared/experiments/src/index.ts", "tsConfig": "libs/shared/experiments/tsconfig.lib.json", "assets": ["libs/shared/experiments/*.md"], - "declaration": true + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/geodb/project.json b/libs/shared/geodb/project.json index 743ceee36e5..26775351ada 100644 --- a/libs/shared/geodb/project.json +++ b/libs/shared/geodb/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/geodb/src/index.ts", "outputPath": "dist/libs/shared/geodb", - "outputFileName": "main.js", "tsConfig": "libs/shared/geodb/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/geodb/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test-unit": { diff --git a/libs/shared/guards/project.json b/libs/shared/guards/project.json index 484c7621f17..2802301053b 100644 --- a/libs/shared/guards/project.json +++ b/libs/shared/guards/project.json @@ -6,14 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/guards", "main": "libs/shared/guards/src/index.ts", "tsConfig": "libs/shared/guards/tsconfig.lib.json", "assets": ["libs/shared/guards/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/l10n/project.json b/libs/shared/l10n/project.json index 4fafde9e7b9..23700dc0421 100644 --- a/libs/shared/l10n/project.json +++ b/libs/shared/l10n/project.json @@ -6,32 +6,31 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/l10n/src/index.ts", "outputPath": "dist/libs/shared/l10n", - "outputFileName": "main.js", "tsConfig": "libs/shared/l10n/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/l10n/README.md", "input": ".", "output": "." + }, + { + "glob": "src/**/*.json", + "input": "libs/shared/l10n", + "output": "." } - ], - "platform": "node", - "format": ["cjs", "esm"] - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/l10n/src/lib/l10n.utils.spec.ts b/libs/shared/l10n/src/lib/l10n.utils.spec.ts index 681a7a3449f..a7048fa3e34 100644 --- a/libs/shared/l10n/src/lib/l10n.utils.spec.ts +++ b/libs/shared/l10n/src/lib/l10n.utils.spec.ts @@ -2,7 +2,7 @@ * 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 supportedLanguages from './supported-languages.json'; +const supportedLanguages: string[] = require('./supported-languages.json'); import { determineDirection, determineLocale, diff --git a/libs/shared/l10n/src/lib/l10n.utils.ts b/libs/shared/l10n/src/lib/l10n.utils.ts index b15a8352497..a0f2a420035 100644 --- a/libs/shared/l10n/src/lib/l10n.utils.ts +++ b/libs/shared/l10n/src/lib/l10n.utils.ts @@ -2,7 +2,7 @@ * 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 { negotiateLanguages } from '@fluent/langneg'; -import availableLocales from './supported-languages.json'; +const availableLocales: string[] = require('./supported-languages.json'); import moment from 'moment'; import { LocalizeOptions } from './l10n.types'; import { DEFAULT_LOCALE, EN_GB_LOCALES } from './l10n.constants'; @@ -162,7 +162,7 @@ export function determineLocale( )[0]; } -import rtlLocales from './rtl-locales.json'; +const rtlLocales: string[] = require('./rtl-locales.json'); /** * Given a set of supported languages and an accept-language http header value, this resolves the direction of the language that fits best. diff --git a/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.spec.ts b/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.spec.ts index e69d2647d22..0f76b11b597 100644 --- a/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.spec.ts +++ b/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.spec.ts @@ -5,7 +5,7 @@ import { Test } from '@nestjs/testing'; import { LocalizerRscFactory } from './localizer.rsc.factory'; import { ILocalizerBindings } from './localizer.interfaces'; -import supportedLanguages from '../supported-languages.json'; +const supportedLanguages: string[] = require('../supported-languages.json'); import { LocalizerRsc } from './localizer.rsc'; describe('LocalizerRscFactory', () => { diff --git a/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.ts b/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.ts index a80312bc18b..f552fff5cab 100644 --- a/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.ts +++ b/libs/shared/l10n/src/lib/localizer/localizer.rsc.factory.ts @@ -5,7 +5,7 @@ import 'server-only'; import { Injectable } from '@nestjs/common'; import { LocalizerBase } from './localizer.base'; import type { ILocalizerBindings } from './localizer.interfaces'; -import supportedLanguages from '../supported-languages.json'; +const supportedLanguages: string[] = require('../supported-languages.json'); import { FluentBundle } from '@fluent/bundle'; import { LocalizerRsc } from './localizer.rsc'; import { JSDOM } from 'jsdom'; diff --git a/libs/shared/l10n/src/lib/supported-languages.spec.ts b/libs/shared/l10n/src/lib/supported-languages.spec.ts index cbfdede42c6..7306862e879 100644 --- a/libs/shared/l10n/src/lib/supported-languages.spec.ts +++ b/libs/shared/l10n/src/lib/supported-languages.spec.ts @@ -2,7 +2,7 @@ * 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 supportedLanguages from './supported-languages.json'; +const supportedLanguages: string[] = require('./supported-languages.json'); describe('l10n/supportedLanguages:', () => { it('returns an array of languages', () => { diff --git a/libs/shared/l10n/tsconfig.lib.json b/libs/shared/l10n/tsconfig.lib.json index 4befa7f0990..6836ea5b7f0 100644 --- a/libs/shared/l10n/tsconfig.lib.json +++ b/libs/shared/l10n/tsconfig.lib.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "rootDir": "../../..", "outDir": "../../../dist/out-tsc", "declaration": true, "types": ["node"] diff --git a/libs/shared/log/project.json b/libs/shared/log/project.json index abe5a80584d..8a863f92a71 100644 --- a/libs/shared/log/project.json +++ b/libs/shared/log/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/log/src/index.ts", "outputPath": "dist/libs/shared/log", - "outputFileName": "main.js", "tsConfig": "libs/shared/log/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/log/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/metrics/glean/package.json b/libs/shared/metrics/glean/package.json index d290f411949..92f661e3459 100644 --- a/libs/shared/metrics/glean/package.json +++ b/libs/shared/metrics/glean/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/shared/glean", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/shared/metrics/glean/project.json b/libs/shared/metrics/glean/project.json index 15e93ffb155..a4aca87ec4a 100644 --- a/libs/shared/metrics/glean/project.json +++ b/libs/shared/metrics/glean/project.json @@ -6,15 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/metrics/glean", "main": "libs/shared/metrics/glean/src/index.ts", "tsConfig": "libs/shared/metrics/glean/tsconfig.lib.json", "assets": ["libs/shared/metrics/glean/*.md"], - "declaration": true, - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/metrics/statsd/project.json b/libs/shared/metrics/statsd/project.json index 5f24cd072ff..1ae0ef1ad33 100644 --- a/libs/shared/metrics/statsd/project.json +++ b/libs/shared/metrics/statsd/project.json @@ -6,31 +6,26 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/metrics/statsd/src/index.ts", "outputPath": "dist/libs/shared/metrics/statsd", - "outputFileName": "main.js", "tsConfig": "libs/shared/metrics/statsd/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/metrics/statsd/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/mozlog/project.json b/libs/shared/mozlog/project.json index 031dca5c9b1..795f4231457 100644 --- a/libs/shared/mozlog/project.json +++ b/libs/shared/mozlog/project.json @@ -6,36 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/mozlog/src/index.ts", "outputPath": "dist/libs/shared/mozlog", - "outputFileName": "main.js", "tsConfig": "libs/shared/mozlog/tsconfig.lib.json", - "declaration": true, - "external": [ - "@nestjs/websockets/socket-module", - "@nestjs/microservices/microservices-module", - "@nestjs/microservices" - ], "assets": [ { "glob": "libs/shared/mozlog/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/nestjs/customs/README.md b/libs/shared/nestjs/customs/README.md deleted file mode 100644 index 05cfa4fdf0a..00000000000 --- a/libs/shared/nestjs/customs/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Customs - -This library supports adding customs (i.e. rate-limiting) as a nestjs service. It was initially designed to work with -FxA's graphql-api, but could be repurposed to work else where. - -## Building - -Run `nx build customs` to build the library. - -## Running unit tests - -Run `nx test-unit customs` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/shared/nestjs/customs/jest.config.ts b/libs/shared/nestjs/customs/jest.config.ts deleted file mode 100644 index 6a96e5baef0..00000000000 --- a/libs/shared/nestjs/customs/jest.config.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Config } from 'jest'; - -/* eslint-disable */ -const config: Config = { - displayName: 'shared-nestjs-customs', - preset: '../../../../jest.preset.js', - testEnvironment: 'node', - transform: { - '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], - }, - moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../../../coverage/libs/nestjs/customs', - reporters: [ - 'default', - [ - 'jest-junit', - { - outputDirectory: 'artifacts/tests/lib/shared/nestjs/customs', - outputName: 'nestjs-customs-jest-unit-results.xml', - }, - ], - ], -}; - -export default config; diff --git a/libs/shared/nestjs/customs/package.json b/libs/shared/nestjs/customs/package.json deleted file mode 100644 index cc51ecb6f51..00000000000 --- a/libs/shared/nestjs/customs/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@fxa/shared/nestjs/customs", - "version": "0.0.1", - "private": true, - "type": "commonjs", - "main": "./index.cjs", - "types": "./index.d.ts", - "dependencies": {} -} diff --git a/libs/shared/nestjs/customs/project.json b/libs/shared/nestjs/customs/project.json deleted file mode 100644 index e24c5acaa12..00000000000 --- a/libs/shared/nestjs/customs/project.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "shared-nestjs-customs", - "$schema": "../../../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/shared/nestjs/customs/src", - "projectType": "library", - "tags": ["scope:shared:lib"], - "targets": { - "build": { - "executor": "@nx/esbuild:esbuild", - "outputs": ["{options.outputPath}"], - "options": { - "outputPath": "dist/libs/shared/nestjs/customs", - "main": "libs/shared/nestjs/customs/src/index.ts", - "tsConfig": "libs/shared/nestjs/customs/tsconfig.lib.json", - "external": [ - "@nestjs/websockets/socket-module", - "@nestjs/microservices/microservices-module", - "@nestjs/microservices" - ], - "assets": ["libs/shared/nestjs/customs/*.md"], - "format": ["cjs"] - } - }, - "test-unit": { - "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "jestConfig": "libs/shared/nestjs/customs/jest.config.ts", - "testPathPattern": ["^(?!.*\\.in\\.spec\\.ts$).*$"] - } - } - } -} diff --git a/libs/shared/nestjs/customs/src/index.ts b/libs/shared/nestjs/customs/src/index.ts deleted file mode 100644 index b0b7823b157..00000000000 --- a/libs/shared/nestjs/customs/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './lib/customs.module'; -export * from './lib/customs.service'; diff --git a/libs/shared/nestjs/customs/src/lib/customs.module.ts b/libs/shared/nestjs/customs/src/lib/customs.module.ts deleted file mode 100644 index abb9f02c06e..00000000000 --- a/libs/shared/nestjs/customs/src/lib/customs.module.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 { Module } from '@nestjs/common'; -import { LegacyStatsDProvider } from '@fxa/shared/metrics/statsd'; -import { LOGGER_PROVIDER } from '@fxa/shared/log'; -import { CustomsService } from './customs.service'; -import { - RateLimitProvider, - RateLimitRedisProvider, -} from '@fxa/accounts/rate-limit'; -import { MozLoggerService } from '@fxa/shared/mozlog'; - -@Module({ - providers: [ - CustomsService, - RateLimitRedisProvider, - RateLimitProvider, - MozLoggerService, - LegacyStatsDProvider, - { - provide: LOGGER_PROVIDER, - useClass: MozLoggerService, - }, - ], - exports: [CustomsService], -}) -export class CustomsModule {} diff --git a/libs/shared/nestjs/customs/src/lib/customs.service.spec.ts b/libs/shared/nestjs/customs/src/lib/customs.service.spec.ts deleted file mode 100644 index edbbf73be32..00000000000 --- a/libs/shared/nestjs/customs/src/lib/customs.service.spec.ts +++ /dev/null @@ -1,202 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 { Test, TestingModule } from '@nestjs/testing'; -import { GraphQLError } from 'graphql'; - -import { CustomsService } from './customs.service'; -import { MozLoggerService } from '@fxa/shared/mozlog'; -import { RateLimitClient } from '../../../../../accounts/rate-limit/src'; -import { ConfigService } from '@nestjs/config'; -import * as superagent from 'superagent'; -import { LOGGER_PROVIDER } from '../../../../log/src'; -import { StatsD, StatsDService } from '../../../../metrics/statsd/src'; - -jest.mock('superagent', () => ({ - post: jest.fn(), -})); - -describe('Customs Service', () => { - const mockConfig = new ConfigService({ - customsUrl: 'http://localhost:7000', - l10n: { - defaultLanguage: 'en', - supportedLanguages: ['en', 'fr'], - }, - }); - const mockLogger = { - debug: jest.fn(), - warn: jest.fn(), - }; - const mockStatsd = { - increment: jest.fn(), - } as unknown as StatsD; - const mockRateLimit = { - supportsAction: jest.fn(), - skip: jest.fn(), - check: jest.fn(), - }; - const mockL10nTsFormatter = { - format: jest.fn(), - }; - - let service: CustomsService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - { provide: ConfigService, useValue: mockConfig }, - { provide: 'L10N_TS_FORMATTER', useValue: mockL10nTsFormatter }, - { provide: RateLimitClient, useValue: mockRateLimit }, - { provide: StatsDService, useValue: mockStatsd }, - { provide: LOGGER_PROVIDER, useValue: mockLogger }, - { provide: MozLoggerService, useValue: mockLogger }, - CustomsService, - ], - }).compile(); - service = module.get(CustomsService); - - jest.resetAllMocks(); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); - - describe('for rate limit rule', () => { - it('can call rate limiter when rate limit rule is defined', async () => { - mockRateLimit.supportsAction.mockImplementation(() => true); - await service.check({ - action: 'test', - ip: '127.0.0.1', - }); - - expect(superagent.post).toBeCalledTimes(0); - expect(mockRateLimit.check).toBeCalledTimes(1); - expect(mockStatsd.increment).toBeCalledWith('customs.check.v2', [ - 'action:test', - ]); - }); - - it('should throw too many requests error, when rate limit rule is defined', async () => { - mockRateLimit.supportsAction.mockImplementation(() => true); - mockRateLimit.check.mockImplementation(async (action) => { - if (action === 'unblockEmail') { - return null; - } - - return { - retryAfter: 100, - block: true, - }; - }); - - let error: GraphQLError | null = null; - try { - await service.check({ - action: 'test', - ip: '127.0.0.1', - email: 'foo@mozilla.com', - uid: '123', - // Important! Trigger and check localized error message state! - acceptLanguage: 'fr', - }); - } catch (err) { - error = err; - } - - expect(mockRateLimit.check).toHaveBeenCalled(); - expect(mockRateLimit.check).toHaveBeenCalledWith('test', { - ip: '127.0.0.1', - email: 'foo@mozilla.com', - uid: '123', - ip_email: '127.0.0.1_foo@mozilla.com', - ip_uid: '127.0.0.1_123', - }); - expect(mockRateLimit.check).toHaveBeenCalledWith('unblockEmail', { - ip: '127.0.0.1', - email: 'foo@mozilla.com', - ip_email: '127.0.0.1_foo@mozilla.com', - uid: '123', - ip_uid: '127.0.0.1_123', - }); - - expect(error).toBeDefined(); - expect(error?.message).toEqual('Client has sent too many requests'); - expect(error?.extensions).toEqual({ - code: 429, - errno: 114, - error: 'Too Many Requests', - 'retry-after': 100, - // Since an 'acceptLanguage' of 'fr' was provided - retryAfterLocalized: 'dans quelques secondes', - // Since we mocked an unblock being allowed. - verificationMethod: 'email-captcha', - verificationReason: 'login', - }); - }); - }); - - describe('for customs service', () => { - it('can call customs', async () => { - (superagent.post as unknown as jest.SpyInstance).mockReturnValue({ - send: () => ({ - ok: () => ({ - status: 200, - body: { - blocked: false, - }, - }), - }), - }); - - await service.check({ - action: 'test', - ip: '127.0.0.1', - }); - - expect(superagent.post).toBeCalledTimes(1); - expect(mockRateLimit.check).toBeCalledTimes(0); - expect(mockStatsd.increment).toBeCalledWith('customs.check.v1', [ - 'action:test', - ]); - }); - - it('should throw too many requests error, when rate limit rule is defined', async () => { - (superagent.post as unknown as jest.SpyInstance).mockReturnValue({ - send: () => ({ - ok: () => ({ - status: 200, - body: { - block: true, - retryAfter: 101, - }, - }), - }), - }); - - let error: GraphQLError | null = null; - try { - await service.check({ - action: 'test', - ip: '127.0.0.1', - // Important! Trigger and check localized error message state! - acceptLanguage: 'fr', - }); - } catch (err) { - error = err; - } - - expect(error).toBeDefined(); - expect(error?.message).toEqual('Client has sent too many requests'); - expect(error?.extensions).toEqual({ - code: 429, - errno: 114, - error: 'Too Many Requests', - 'retry-after': 101, - retryAfterLocalized: 'dans quelques secondes', - }); - }); - }); -}); diff --git a/libs/shared/nestjs/customs/src/lib/customs.service.ts b/libs/shared/nestjs/customs/src/lib/customs.service.ts deleted file mode 100644 index d87e760c085..00000000000 --- a/libs/shared/nestjs/customs/src/lib/customs.service.ts +++ /dev/null @@ -1,240 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * 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 { BadRequestException, Inject, Injectable } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import superagent from 'superagent'; -import { - BlockOnOpts, - RateLimit, - RateLimitClient, -} from '@fxa/accounts/rate-limit'; -import { MozLoggerService } from '@fxa/shared/mozlog'; -import { LOGGER_PROVIDER } from '@fxa/shared/log'; -import { localizeTimestamp } from '@fxa/shared/l10n'; -import { StatsD, StatsDService } from '@fxa/shared/metrics/statsd'; -import { GraphQLError } from 'graphql'; - -type AnyObject = Record; - -export type CheckOptions = BlockOnOpts & { - action: string; - headers?: AnyObject; - query?: AnyObject; - payload?: AnyObject; - acceptLanguage?: string; -}; - -type CheckResponse = { - block: boolean; - blockReason?: string; - suspect?: boolean; - unblock?: boolean; - retryAfter?: number; -}; - -@Injectable() -export class CustomsService { - private customsUrl: string; - private l10nTimestampFormatter: ReturnType; - - constructor( - config: ConfigService, - @Inject(RateLimitClient) private readonly rateLimit: RateLimit, - @Inject(LOGGER_PROVIDER) private readonly log: MozLoggerService, - @Inject(StatsDService) private readonly statsd: StatsD - ) { - // Customs service url - const customsUrl = config.get('customsUrl'); - if (!customsUrl) { - throw new Error('No customs URL provided.'); - } - this.customsUrl = customsUrl; - - // l10nTimestampFormatter - const defaultLanguage = config.get('l10n.defaultLanguage'); - if (!defaultLanguage) { - throw new Error('Config missing l10n.defaultLanguage.'); - } - const supportedLanguages = config.get('l10n.supportedLanguages'); - if (!supportedLanguages) { - throw new Error('Config missing l10n.supportedLanguages'); - } - this.l10nTimestampFormatter = localizeTimestamp({ - defaultLanguage, - supportedLanguages, - }); - } - - async check(options: CheckOptions): Promise { - let response: CheckResponse = { block: false }; - - // If a rate limit is configured for the supplied action, use this rate limit instead. - // Otherwise call the legacy customs service. - const supported = this.rateLimit.supportsAction(options.action); - if (supported) { - if (options.ip && options.email) { - options.ip_email = `${options.ip}_${options.email}`; - } - if (options.ip && options.uid) { - options.ip_uid = `${options.ip}_${options.uid}`; - } - - response = await this.checkRateLimit(options); - } else { - // TODO: Remove legacy calls to customs. FXA-11635 - // If the customs service wasn't configured, short circuit. - if (!this.customsUrl || this.customsUrl === 'none') { - return response; - } - response = await this.checkCustomsService(options); - } - - if (response.block) { - if (response.retryAfter) { - const extraData: any = { - // Not using pascal case to maintain backwards compat with auth-server - 'retry-after': response.retryAfter, - }; - - // Respect user's preferred locale - if (options.acceptLanguage) { - const retryAfterLocalized = this.l10nTimestampFormatter.format( - Date.now() + response.retryAfter, - options.acceptLanguage - ); - extraData.retryAfterLocalized = retryAfterLocalized; - } - - // If the response, can be unblocked, signal these options. Again, this maintains - // backward compatibility with auth server. - if (response.unblock) { - extraData.verificationMethod = 'email-captcha'; - extraData.verificationReason = 'login'; - } - - throw new GraphQLError('Client has sent too many requests', { - extensions: { - code: 429, - error: 'Too Many Requests', - errno: 114, - ...extraData, - }, - }); - } - - // TODO: Remove legacy calls to customs. FXA-11635 - // Note that for the v2 rate limiter, we always return a retry after! So the following is no longer needed. - const errorStr = 'The request was blocked for security reasons'; - throw new BadRequestException( - { error: 'Request blocked', errno: 125, code: 400, message: errorStr }, - errorStr - ); - } - - return response; - } - - private async checkRateLimit(options: CheckOptions): Promise { - const { action, ip, email, uid, ip_email, ip_uid } = options; - - // Check if we can ignore the user - const skip = this.rateLimit.skip({ - ip, - email, - uid, - }); - if (skip) { - this.statsd.increment( - `customs.check.v2.skip`, - [ip ? 'ip' : '', email ? 'email' : '', uid ? 'uid' : ''].filter( - (x) => !!x - ) - ); - return { block: false }; - } - - // Run the rate limit check. If the response is null, we do not block. - this.statsd.increment(`customs.check.v2`, [`action:${action}`]); - const result = await this.rateLimit.check(action, { - ip, - email, - uid, - ip_email, - ip_uid, - }); - this.log.debug('customs', { - msg: `Rate Limiting checked`, - ip, - email, - uid, - action, - blocked: result !== null, - }); - - this.statsd.increment( - `customs.request.v2.check`, - [ - action, - result != null ? 'blocked' : '', - result?.reason ? `blockReason:${result.reason}` : '', - ].filter((x) => !!x) - ); - - if (result == null) { - return { block: false }; - } - - // We use the rate limiter to allow X number unblock attempts per day. Once - // unblock attempts have been exhausted, the user cannot request an unblock - // code and must wait until the unblockEmail ban duration has expired. Similar - // logic existed in the old customs server, but these sorts of decisions are - // actually domain of the service using customs and not customs itself, so - // this is the revised approach. - let canUnblock = false; - if ( - ip_email && - ip && - email && - this.rateLimit.supportsAction('unblockEmail') - ) { - const unblockResult = await this.rateLimit.check('unblockEmail', { - ip, - email, - uid, - ip_email, - ip_uid, - }); - canUnblock = unblockResult == null; - } - - return { - block: true, - unblock: canUnblock, - retryAfter: result.retryAfter, - }; - } - - private async checkCustomsService(options: CheckOptions) { - // Record stat so we can monitor conversion from v1 to v2 - this.statsd.increment(`customs.check.v1`, [`action:${options.action}`]); - - const result = await superagent - .post(this.customsUrl + '/check') - .send(options) - .ok((res) => res.status < 600); - - if (result.status < 200 || result.status >= 300) { - throw new Error('Customs server failed to respond as expected.'); - } - const response = result.body as CheckResponse; - - this.log.debug('customs', { - msg: `Customs service checked`, - ...options, - ...response, - }); - - return response; - } -} diff --git a/libs/shared/nestjs/customs/tsconfig.json b/libs/shared/nestjs/customs/tsconfig.json deleted file mode 100644 index 4022fd4d0ad..00000000000 --- a/libs/shared/nestjs/customs/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "extends": "../../../../tsconfig.base.json", - "compilerOptions": { - "module": "commonjs", - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true - }, - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.lib.json" - }, - { - "path": "./tsconfig.spec.json" - } - ] -} diff --git a/libs/shared/notifier/project.json b/libs/shared/notifier/project.json index f0acd5c3064..8e013d90245 100644 --- a/libs/shared/notifier/project.json +++ b/libs/shared/notifier/project.json @@ -6,36 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/notifier/src/index.ts", "outputPath": "dist/libs/shared/notifier", - "outputFileName": "main.js", "tsConfig": "libs/shared/notifier/tsconfig.lib.json", - "declaration": true, - "external": [ - "@nestjs/websockets/socket-module", - "@nestjs/microservices/microservices-module", - "@nestjs/microservices" - ], "assets": [ { "glob": "libs/shared/notifier/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/shared/otel/project.json b/libs/shared/otel/project.json index 67916bf7d7d..7deaabb0264 100644 --- a/libs/shared/otel/project.json +++ b/libs/shared/otel/project.json @@ -6,15 +6,21 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/otel", "main": "libs/shared/otel/src/index.ts", "tsConfig": "libs/shared/otel/tsconfig.lib.json", "assets": ["libs/shared/otel/*.md"], - "declaration": true, - "platform": "node" + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/otp/project.json b/libs/shared/otp/project.json index bf78883db2b..5801db3fa8a 100644 --- a/libs/shared/otp/project.json +++ b/libs/shared/otp/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/otp/src/index.ts", "outputPath": "dist/libs/shared/otp", - "outputFileName": "main.js", "tsConfig": "libs/shared/otp/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/otp/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test-unit": { diff --git a/libs/shared/pem-jwk/project.json b/libs/shared/pem-jwk/project.json index 93704d09ee2..25173bce781 100644 --- a/libs/shared/pem-jwk/project.json +++ b/libs/shared/pem-jwk/project.json @@ -6,32 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/pem-jwk/src/index.ts", "outputPath": "dist/libs/shared/pem-jwk", - "outputFileName": "main.js", "tsConfig": "libs/shared/pem-jwk/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/shared/pem-jwk/README.md", "input": ".", "output": "." } - ], - "platform": "node", - "format": ["cjs", "esm"] - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test-unit": { diff --git a/libs/shared/react/project.json b/libs/shared/react/project.json index 42a3602c6d3..7ad10d30282 100644 --- a/libs/shared/react/project.json +++ b/libs/shared/react/project.json @@ -6,6 +6,13 @@ "tags": [], "targets": { "build": { + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { diff --git a/libs/shared/sentry-browser/package.json b/libs/shared/sentry-browser/package.json index 01e83c4837f..4aab946b116 100644 --- a/libs/shared/sentry-browser/package.json +++ b/libs/shared/sentry-browser/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/shared/sentry-browser", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/shared/sentry-browser/project.json b/libs/shared/sentry-browser/project.json index 221ce77e56a..2d6c013c74d 100644 --- a/libs/shared/sentry-browser/project.json +++ b/libs/shared/sentry-browser/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/sentry-browser", "main": "libs/shared/sentry-browser/src/index.ts", "tsConfig": "libs/shared/sentry-browser/tsconfig.lib.json", "assets": ["libs/shared/sentry-browser/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/sentry-nest/package.json b/libs/shared/sentry-nest/package.json index 2edc7f50612..64a1c31ca13 100644 --- a/libs/shared/sentry-nest/package.json +++ b/libs/shared/sentry-nest/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/shared/sentry-nest", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/shared/sentry-nest/project.json b/libs/shared/sentry-nest/project.json index 62995b8ed65..e05bef50fae 100644 --- a/libs/shared/sentry-nest/project.json +++ b/libs/shared/sentry-nest/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/sentry-nest", "main": "libs/shared/sentry-nest/src/index.ts", "tsConfig": "libs/shared/sentry-nest/tsconfig.lib.json", "assets": ["libs/shared/sentry-nest/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/sentry-next/package.json b/libs/shared/sentry-next/package.json index 3a7fa353c82..454aa639fb0 100644 --- a/libs/shared/sentry-next/package.json +++ b/libs/shared/sentry-next/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/shared/sentry-next", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/shared/sentry-next/project.json b/libs/shared/sentry-next/project.json index 3c9b27f34a8..31ebbd9ccfd 100644 --- a/libs/shared/sentry-next/project.json +++ b/libs/shared/sentry-next/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/sentry-next", "main": "libs/shared/sentry-next/src/index.ts", "tsConfig": "libs/shared/sentry-next/tsconfig.lib.json", "assets": ["libs/shared/sentry-next/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/sentry-node/package.json b/libs/shared/sentry-node/package.json index e171c04c158..ce087b8577e 100644 --- a/libs/shared/sentry-node/package.json +++ b/libs/shared/sentry-node/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/shared/sentry-node", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/shared/sentry-node/project.json b/libs/shared/sentry-node/project.json index 17bc52aded5..3317d9d95a7 100644 --- a/libs/shared/sentry-node/project.json +++ b/libs/shared/sentry-node/project.json @@ -6,14 +6,21 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/sentry-node", "main": "libs/shared/sentry-node/src/index.ts", "tsConfig": "libs/shared/sentry-node/tsconfig.lib.json", "assets": ["libs/shared/sentry-node/*.md"], - "format": ["cjs"] + "generatePackageJson": true } }, "test-unit": { diff --git a/libs/shared/sentry-utils/package.json b/libs/shared/sentry-utils/package.json index 1a8293c67b0..93c4df10f91 100644 --- a/libs/shared/sentry-utils/package.json +++ b/libs/shared/sentry-utils/package.json @@ -1,8 +1,4 @@ { "name": "@fxa/shared/sentry-utils", - "version": "0.0.1", - "dependencies": {}, - "type": "commonjs", - "main": "./index.cjs", - "private": true + "version": "0.0.1" } diff --git a/libs/shared/sentry-utils/project.json b/libs/shared/sentry-utils/project.json index 06dcb58a9eb..f45f5ebe0d2 100644 --- a/libs/shared/sentry-utils/project.json +++ b/libs/shared/sentry-utils/project.json @@ -6,14 +6,20 @@ "tags": ["scope:shared:lib"], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], "options": { "outputPath": "dist/libs/shared/sentry-utils", "main": "libs/shared/sentry-utils/src/index.ts", "tsConfig": "libs/shared/sentry-utils/tsconfig.lib.json", - "assets": ["libs/shared/sentry-utils/*.md"], - "format": ["cjs"] + "assets": ["libs/shared/sentry-utils/*.md"] } }, "test-unit": { diff --git a/libs/shared/sentry/project.json b/libs/shared/sentry/project.json index 5278bb2a734..f7987b90c9b 100644 --- a/libs/shared/sentry/project.json +++ b/libs/shared/sentry/project.json @@ -6,39 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/shared/sentry/src/index.ts", "outputPath": "dist/libs/shared/sentry", - "outputFileName": "main.js", "tsConfig": "libs/shared/sentry/tsconfig.lib.json", - "declaration": true, - "external": [ - "@apollo/gateway", - "@apollo/subgraph", - "@as-integrations/fastify", - "@nestjs/websockets/socket-module", - "@nestjs/microservices/microservices-module", - "@nestjs/microservices" - ], "assets": [ { "glob": "libs/shared/sentry/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "lint": { diff --git a/libs/vendored/common-password-list/project.json b/libs/vendored/common-password-list/project.json index 1af294361df..3fed226ccab 100644 --- a/libs/vendored/common-password-list/project.json +++ b/libs/vendored/common-password-list/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/vendored/common-password-list/src/index.ts", "outputPath": "dist/libs/vendored/common-password-list", - "outputFileName": "main.js", "tsConfig": "libs/vendored/common-password-list/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/vendored/common-password-list/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test-unit": { diff --git a/libs/vendored/crypto-relier/project.json b/libs/vendored/crypto-relier/project.json index b2f123fdeca..f7aebabc949 100644 --- a/libs/vendored/crypto-relier/project.json +++ b/libs/vendored/crypto-relier/project.json @@ -6,32 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/vendored/crypto-relier/src/index.ts", "outputPath": "dist/libs/vendored/crypto-relier", - "outputFileName": "main.js", "tsConfig": "libs/vendored/crypto-relier/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/vendored/crypto-relier/README.md", "input": ".", "output": "." } - ], - "platform": "node", - "format": ["cjs", "esm"] - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test": { diff --git a/libs/vendored/incremental-encoder/project.json b/libs/vendored/incremental-encoder/project.json index 0a84e392f1f..743a3de4778 100644 --- a/libs/vendored/incremental-encoder/project.json +++ b/libs/vendored/incremental-encoder/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/vendored/incremental-encoder/src/index.ts", "outputPath": "dist/libs/vendored/incremental-encoder", - "outputFileName": "main.js", "tsConfig": "libs/vendored/incremental-encoder/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/vendored/incremental-encoder/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test-unit": { diff --git a/libs/vendored/jwtool/project.json b/libs/vendored/jwtool/project.json index 7bd9c8c5ef0..ff7cb55cf21 100644 --- a/libs/vendored/jwtool/project.json +++ b/libs/vendored/jwtool/project.json @@ -6,32 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/vendored/jwtool/src/index.ts", "outputPath": "dist/libs/vendored/jwtool", - "outputFileName": "main.js", "tsConfig": "libs/vendored/jwtool/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/vendored/jwtool/README.md", "input": ".", "output": "." } - ], - "platform": "node", - "format": ["cjs", "esm"] - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test-unit": { diff --git a/libs/vendored/typesafe-node-firestore/project.json b/libs/vendored/typesafe-node-firestore/project.json index 732adbc9193..2fb64d0992c 100644 --- a/libs/vendored/typesafe-node-firestore/project.json +++ b/libs/vendored/typesafe-node-firestore/project.json @@ -6,31 +6,26 @@ "tags": [], "targets": { "build": { - "executor": "@nx/esbuild:esbuild", + "dependsOn": ["build-ts"], + "executor": "nx:run-commands", + "options": { + "command": "echo Build complete" + } + }, + "build-ts": { + "executor": "@nx/js:tsc", "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", "options": { "main": "libs/vendored/typesafe-node-firestore/src/index.ts", "outputPath": "dist/libs/vendored/typesafe-node-firestore", - "outputFileName": "main.js", "tsConfig": "libs/vendored/typesafe-node-firestore/tsconfig.lib.json", - "declaration": true, "assets": [ { "glob": "libs/vendored/typesafe-node-firestore/README.md", "input": ".", "output": "." } - ], - "platform": "node" - }, - "configurations": { - "development": { - "minify": false - }, - "production": { - "minify": true - } + ] } }, "test": { diff --git a/nx.json b/nx.json index d7ce2918c39..1a72f824561 100644 --- a/nx.json +++ b/nx.json @@ -147,11 +147,6 @@ "cache": true, "dependsOn": ["^build"], "inputs": ["production", "^production"] - }, - "@nx/esbuild:esbuild": { - "cache": true, - "dependsOn": ["^build"], - "inputs": ["production", "^production"] } }, "namedInputs": { diff --git a/package.json b/package.json index f7de2f9dfb9..5802604e6ce 100644 --- a/package.json +++ b/package.json @@ -189,7 +189,6 @@ "@nestjs/cli": "^11.0.1", "@nestjs/schematics": "11.0.9", "@nestjs/testing": "^10.3.4", - "@nx/esbuild": "21.2.4", "@nx/eslint-plugin": "21.2.4", "@nx/jest": "21.2.4", "@nx/js": "21.2.4", @@ -248,8 +247,6 @@ "babel-eslint": "^10.1.0", "babel-jest": "29.7.0", "copyfiles": "^2.4.1", - "esbuild": "^0.17.15", - "esbuild-register": "^3.5.0", "eslint": "^8.57.1", "eslint-config-next": "15.5.14", "eslint-config-prettier": "^10.1.5", @@ -318,12 +315,5 @@ "resolutionComments": { "multer": "^2.1.1 — remove when @nestjs/platform-express is upgraded to 11.x (ships multer 2.1.1 natively)" }, - "packageManager": "yarn@4.9.2", - "_moduleAliases": { - "@fxa/vendored/jwtool": "./dist/libs/vendored/jwtool/main.cjs", - "@fxa/vendored/crypto-relier": "./dist/libs/vendored/crypto-relier/main.cjs", - "@fxa/vendored/crypto-relier/esm": "./dist/libs/vendored/crypto-relier/main.js", - "@fxa/shared/pem-jwk": "./dist/libs/shared/pem-jwk/main.cjs", - "@fxa/shared/l10n": "./dist/libs/shared/l10n/main.cjs" - } + "packageManager": "yarn@4.9.2" } diff --git a/packages/fxa-admin-server/tsconfig.build.json b/packages/fxa-admin-server/tsconfig.build.json index c88e755c48a..23340d3499d 100644 --- a/packages/fxa-admin-server/tsconfig.build.json +++ b/packages/fxa-admin-server/tsconfig.build.json @@ -16,6 +16,9 @@ "@fxa/payments/experiments": ["libs/payments/experiments/src/index"], "@fxa/payments/iap": ["libs/payments/iap/src/index"], "@fxa/payments/metrics": ["libs/payments/metrics/src/index"], + "@fxa/payments/metrics-aggregator": [ + "libs/payments/metrics-aggregator/src/index" + ], "@fxa/shared/account/account": ["libs/shared/account/account/src/index"], "@fxa/profile/client": ["libs/profile/client/src/index"], "@fxa/shared/cms": ["libs/shared/cms/src/index"], diff --git a/packages/fxa-content-server/server/lib/beta-settings.js b/packages/fxa-content-server/server/lib/beta-settings.js index a1dc7758b5c..4872b07b63b 100644 --- a/packages/fxa-content-server/server/lib/beta-settings.js +++ b/packages/fxa-content-server/server/lib/beta-settings.js @@ -8,7 +8,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware'); const { supportedLanguages, rtlLocales, -} = require('../../../../dist/libs/shared/l10n/main.js'); +} = require('../../../../dist/libs/shared/l10n'); const config = require('./configuration'); const FLOW_ID_KEY = config.get('flow_id_key'); const flowMetrics = require('./flow-metrics'); diff --git a/packages/fxa-content-server/webpack.config.js b/packages/fxa-content-server/webpack.config.js index 74b37c7ea2f..4d12082a051 100644 --- a/packages/fxa-content-server/webpack.config.js +++ b/packages/fxa-content-server/webpack.config.js @@ -65,7 +65,7 @@ const webpackConfig = { 'fast-text-encoding': require.resolve('fast-text-encoding'), fxaCryptoDeriver: path.resolve( __dirname, - '../../dist/libs/vendored/crypto-relier/main.js' + '../../dist/libs/vendored/crypto-relier/src/index.js' ), fxaPairingChannel: require.resolve( 'fxa-pairing-channel/dist/FxAccountsPairingChannel.babel.umd.js' diff --git a/tsconfig.base.json b/tsconfig.base.json index a3d4528e817..f6f1eca05d0 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,5 +1,10 @@ { "compileOnSave": false, + "ts-node": { + "compilerOptions": { + "module": "commonjs" + } + }, "compilerOptions": { "rootDir": ".", "allowJs": false, @@ -53,6 +58,9 @@ "@fxa/payments/legacy": ["libs/payments/legacy/src/index.ts"], "@fxa/payments/management": ["libs/payments/management/src/index.ts"], "@fxa/payments/metrics": ["libs/payments/metrics/src/index.ts"], + "@fxa/payments/metrics-aggregator": [ + "libs/payments/metrics-aggregator/src/index.ts" + ], "@fxa/payments/metrics/client": ["libs/payments/metrics/src/client.ts"], "@fxa/payments/metrics/provider": [ "libs/payments/metrics/src/provider.ts" diff --git a/yarn.lock b/yarn.lock index b901e32602f..6b3522b9881 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9939,25 +9939,6 @@ __metadata: languageName: node linkType: hard -"@nx/esbuild@npm:21.2.4": - version: 21.2.4 - resolution: "@nx/esbuild@npm:21.2.4" - dependencies: - "@nx/devkit": "npm:21.2.4" - "@nx/js": "npm:21.2.4" - picocolors: "npm:^1.1.0" - tinyglobby: "npm:^0.2.12" - tsconfig-paths: "npm:^4.1.2" - tslib: "npm:^2.3.0" - peerDependencies: - esbuild: ">=0.19.2 <1.0.0" - peerDependenciesMeta: - esbuild: - optional: true - checksum: 10c0/05fa3875ae9a5fc36e2f4675af08630e6c34cd50310cd7d52532794f3016aac0d01ac60a3b5b5b08e4ae1673d14fe67c253a83b6afaf385af0779cf3d20b63cc - languageName: node - linkType: hard - "@nx/eslint-plugin@npm:21.2.4": version: 21.2.4 resolution: "@nx/eslint-plugin@npm:21.2.4" @@ -31744,7 +31725,6 @@ __metadata: "@nestjs/schematics": "npm:11.0.9" "@nestjs/testing": "npm:^10.3.4" "@next/bundle-analyzer": "npm:^15.1.6" - "@nx/esbuild": "npm:21.2.4" "@nx/eslint-plugin": "npm:21.2.4" "@nx/jest": "npm:21.2.4" "@nx/js": "npm:21.2.4" @@ -31837,8 +31817,6 @@ __metadata: copyfiles: "npm:^2.4.1" diffparser: "npm:^2.0.1" dotenv: "npm:^16.4.5" - esbuild: "npm:^0.17.15" - esbuild-register: "npm:^3.5.0" eslint: "npm:^8.57.1" eslint-config-next: "npm:15.5.14" eslint-config-prettier: "npm:^10.1.5"