chore(libs): add injectable to all library classes, centralize nest

Because:

* We want to easily be able to consume library classes within NestJS.
Adding the injectable decorator to all library classes means we can do
so with ease, but also doesn't prevent us from using the class outside
of the NestJS DI system.
* We want all dependencies (such as nest) centralized to the main
package.json

This commit:

* Adds the injectable decorator to every library class.
* Centralizes the NestJS dependency to the root package.json.

Closes: no relevant issue - polish PR.
This commit is contained in:
Julian Poyourow 2023-08-25 17:46:25 +00:00
Родитель c7057c6f2a
Коммит 5b6060df51
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: EA0570ABC73D47D3
11 изменённых файлов: 41 добавлений и 65 удалений

Просмотреть файл

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { NotFoundError } from 'objection'; import { NotFoundError } from 'objection';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { Injectable } from '@nestjs/common';
import { AccountDatabase, CartState } from '@fxa/shared/db/mysql/account'; import { AccountDatabase, CartState } from '@fxa/shared/db/mysql/account';
import { Logger } from '@fxa/shared/log'; import { Logger } from '@fxa/shared/log';
@ -42,6 +43,7 @@ const ACTIONS_VALID_STATE = {
const isAction = (action: string): action is keyof typeof ACTIONS_VALID_STATE => const isAction = (action: string): action is keyof typeof ACTIONS_VALID_STATE =>
action in ACTIONS_VALID_STATE; action in ACTIONS_VALID_STATE;
@Injectable()
export class CartManager { export class CartManager {
constructor(private log: Logger, private db: AccountDatabase) {} constructor(private log: Logger, private db: AccountDatabase) {}

Просмотреть файл

@ -4,6 +4,7 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import pRetry from 'p-retry'; import pRetry from 'p-retry';
import superagent from 'superagent'; import superagent from 'superagent';
import { Injectable } from '@nestjs/common';
import { import {
PAYPAL_LIVE_API, PAYPAL_LIVE_API,
@ -37,6 +38,7 @@ import {
} from './types'; } from './types';
import { nvpToObject, objectToNVP, toIsoString } from './util'; import { nvpToObject, objectToNVP, toIsoString } from './util';
@Injectable()
export class PayPalClient { export class PayPalClient {
private url: string; private url: string;
private ipnUrl: string; private ipnUrl: string;

Просмотреть файл

@ -2,12 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { Injectable } from '@nestjs/common';
import { AccountDatabase } from '@fxa/shared/db/mysql/account'; import { AccountDatabase } from '@fxa/shared/db/mysql/account';
import { createAccount } from './account.repository'; import { createAccount } from './account.repository';
import { normalizeEmail, randomBytesAsync } from './account.util'; import { normalizeEmail, randomBytesAsync } from './account.util';
@Injectable()
export class AccountManager { export class AccountManager {
constructor(private db: AccountDatabase) {} constructor(private db: AccountDatabase) {}

Просмотреть файл

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { Injectable } from '@nestjs/common';
import { import {
ApolloClient, ApolloClient,
InMemoryCache, InMemoryCache,
@ -17,6 +18,7 @@ import {
} from './errors'; } from './errors';
import { BaseError } from '@fxa/shared/error'; import { BaseError } from '@fxa/shared/error';
@Injectable()
export class ContentfulClient { export class ContentfulClient {
client = new ApolloClient({ client = new ApolloClient({
uri: `${this.contentfulGraphqlApiUri}?access_token=${this.contentfulGraphqlApiKey}`, uri: `${this.contentfulGraphqlApiUri}?access_token=${this.contentfulGraphqlApiKey}`,

Просмотреть файл

@ -39,6 +39,14 @@
"dependencies": { "dependencies": {
"@faker-js/faker": "^8.0.2", "@faker-js/faker": "^8.0.2",
"@fluent/react": "^0.15.2", "@fluent/react": "^0.15.2",
"@nestjs/common": "^9.4.1",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^9.2.0",
"@nestjs/graphql": "^8.0.2",
"@nestjs/mapped-types": "^1.2.0",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^2.2.2",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"diffparser": "^2.0.1", "diffparser": "^2.0.1",
"hot-shots": "^10.0.0", "hot-shots": "^10.0.0",
@ -99,6 +107,9 @@
"@graphql-codegen/client-preset": "^4.1.0", "@graphql-codegen/client-preset": "^4.1.0",
"@graphql-codegen/typescript": "4.0.1", "@graphql-codegen/typescript": "4.0.1",
"@graphql-codegen/typescript-document-nodes": "4.0.1", "@graphql-codegen/typescript-document-nodes": "4.0.1",
"@nestjs/cli": "^9.4.0",
"@nestjs/schematics": "^9.2.0",
"@nestjs/testing": "^9.2.1",
"@nx/eslint-plugin": "16.6.0", "@nx/eslint-plugin": "16.6.0",
"@nx/jest": "16.6.0", "@nx/jest": "16.6.0",
"@nx/js": "16.6.0", "@nx/js": "16.6.0",

Просмотреть файл

@ -9,18 +9,16 @@ cd "$DIR/../../../"
mkdir -p ~/.pm2/logs mkdir -p ~/.pm2/logs
mkdir -p artifacts/tests mkdir -p artifacts/tests
CI=true yarn workspaces foreach \ CI=true npx nx run-many -p \
--verbose \ 123done \
--topological-dev \ browserid-verifier \
--include 123done \ fxa-auth-server \
--include browserid-verifier \ fxa-content-server \
--include fxa-auth-server \ fxa-graphql-api \
--include fxa-content-server \ fxa-payments-server \
--include fxa-graphql-api \ fxa-profile-server \
--include fxa-payments-server \ fxa-settings \
--include fxa-profile-server \ -t start > ~/.pm2/logs/startup.log
--include fxa-settings \
run start > ~/.pm2/logs/startup.log
# stop services that aren't needed. These are 'watching' services, and they just # stop services that aren't needed. These are 'watching' services, and they just
# consume memory. Ideally, we wouldn't even start these, but they are baked into # consume memory. Ideally, we wouldn't even start these, but they are baked into

Просмотреть файл

@ -6,7 +6,7 @@
"prebuild": "rimraf dist && yarn gql:allowlist", "prebuild": "rimraf dist && yarn gql:allowlist",
"copy-gql": "mkdir -p src/config/gql/allowlist && cp ../../configs/gql/allowlist/*.json src/config/gql/allowlist/.", "copy-gql": "mkdir -p src/config/gql/allowlist && cp ../../configs/gql/allowlist/*.json src/config/gql/allowlist/.",
"copy-config": "cp ./src/config/*.json ./dist/packages/fxa-admin-server/src/config", "copy-config": "cp ./src/config/*.json ./dist/packages/fxa-admin-server/src/config",
"build": "yarn prebuild && yarn nest build && yarn copy-config", "build": "yarn prebuild && nest build && yarn copy-config",
"compile": "tsc --noEmit", "compile": "tsc --noEmit",
"lint": "eslint .", "lint": "eslint .",
"audit": "npm audit --json | audit-filter --nsp-config=.nsprc --audit=-", "audit": "npm audit --json | audit-filter --nsp-config=.nsprc --audit=-",
@ -40,11 +40,6 @@
"dependencies": { "dependencies": {
"@golevelup/ts-jest": "^0.3.2", "@golevelup/ts-jest": "^0.3.2",
"@google-cloud/firestore": "^6.6.0", "@google-cloud/firestore": "^6.6.0",
"@nestjs/common": "^9.4.1",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^9.2.0",
"@nestjs/graphql": "^8.0.2",
"@nestjs/platform-express": "^9.4.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"convict": "^6.2.4", "convict": "^6.2.4",
@ -67,7 +62,6 @@
"tslib": "^2.5.0" "tslib": "^2.5.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^9.4.0",
"@types/chance": "^1.1.2", "@types/chance": "^1.1.2",
"@types/convict": "^6.1.1", "@types/convict": "^6.1.1",
"@types/node": "^18.14.2", "@types/node": "^18.14.2",

Просмотреть файл

@ -39,14 +39,6 @@
"@google-cloud/pubsub": "^2.19.4", "@google-cloud/pubsub": "^2.19.4",
"@grpc/grpc-js": "^1.1.3", "@grpc/grpc-js": "^1.1.3",
"@hapi/hoek": "^11.0.2", "@hapi/hoek": "^11.0.2",
"@nestjs/common": "^9.4.1",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^9.2.0",
"@nestjs/graphql": "^8.0.2",
"@nestjs/mapped-types": "^1.2.0",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^2.2.2",
"@sentry/integrations": "^6.19.1", "@sentry/integrations": "^6.19.1",
"@sentry/node": "^6.19.1", "@sentry/node": "^6.19.1",
"@types/sinon": "10.0.1", "@types/sinon": "10.0.1",
@ -74,9 +66,6 @@
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^9.4.0",
"@nestjs/schematics": "^9.2.0",
"@nestjs/testing": "^9.2.1",
"@types/chance": "^1.1.2", "@types/chance": "^1.1.2",
"@types/convict": "^5.2.2", "@types/convict": "^5.2.2",
"@types/express": "^4.17.12", "@types/express": "^4.17.12",

Просмотреть файл

@ -35,13 +35,6 @@
"homepage": "https://github.com/mozilla/fxa#readme", "homepage": "https://github.com/mozilla/fxa#readme",
"readmeFilename": "README.md", "readmeFilename": "README.md",
"dependencies": { "dependencies": {
"@nestjs/common": "^9.4.1",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^9.2.0",
"@nestjs/graphql": "^8.0.2",
"@nestjs/mapped-types": "^1.2.0",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-express": "^9.4.0",
"@sentry/integrations": "^6.19.1", "@sentry/integrations": "^6.19.1",
"@sentry/node": "^6.19.1", "@sentry/node": "^6.19.1",
"apollo-datasource": "^3.3.1", "apollo-datasource": "^3.3.1",
@ -82,7 +75,6 @@
"tslib": "^2.5.0" "tslib": "^2.5.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^9.4.0",
"@types/body-parser": "^1", "@types/body-parser": "^1",
"@types/chance": "^1.1.2", "@types/chance": "^1.1.2",
"@types/convict": "^5.2.2", "@types/convict": "^5.2.2",

Просмотреть файл

@ -239,7 +239,6 @@
}, },
"homepage": "https://github.com/mozilla/fxa/tree/main/packages/fxa-shared#readme", "homepage": "https://github.com/mozilla/fxa/tree/main/packages/fxa-shared#readme",
"devDependencies": { "devDependencies": {
"@nestjs/testing": "^9.2.1",
"@type-cacheable/core": "^11.0.0", "@type-cacheable/core": "^11.0.0",
"@type-cacheable/ioredis-adapter": "^10.0.4", "@type-cacheable/ioredis-adapter": "^10.0.4",
"@types/accept-language-parser": "^1.5.3", "@types/accept-language-parser": "^1.5.3",

Просмотреть файл

@ -31225,12 +31225,6 @@ fsevents@~2.1.1:
dependencies: dependencies:
"@golevelup/ts-jest": ^0.3.2 "@golevelup/ts-jest": ^0.3.2
"@google-cloud/firestore": ^6.6.0 "@google-cloud/firestore": ^6.6.0
"@nestjs/cli": ^9.4.0
"@nestjs/common": ^9.4.1
"@nestjs/config": ^3.0.0
"@nestjs/core": ^9.2.0
"@nestjs/graphql": ^8.0.2
"@nestjs/platform-express": ^9.4.0
"@types/chance": ^1.1.2 "@types/chance": ^1.1.2
"@types/convict": ^6.1.1 "@types/convict": ^6.1.1
"@types/node": ^18.14.2 "@types/node": ^18.14.2
@ -31714,17 +31708,6 @@ fsevents@~2.1.1:
"@google-cloud/pubsub": ^2.19.4 "@google-cloud/pubsub": ^2.19.4
"@grpc/grpc-js": ^1.1.3 "@grpc/grpc-js": ^1.1.3
"@hapi/hoek": ^11.0.2 "@hapi/hoek": ^11.0.2
"@nestjs/cli": ^9.4.0
"@nestjs/common": ^9.4.1
"@nestjs/config": ^3.0.0
"@nestjs/core": ^9.2.0
"@nestjs/graphql": ^8.0.2
"@nestjs/mapped-types": ^1.2.0
"@nestjs/passport": ^9.0.3
"@nestjs/platform-express": ^9.4.0
"@nestjs/schedule": ^2.2.2
"@nestjs/schematics": ^9.2.0
"@nestjs/testing": ^9.2.1
"@sentry/integrations": ^6.19.1 "@sentry/integrations": ^6.19.1
"@sentry/node": ^6.19.1 "@sentry/node": ^6.19.1
"@types/chance": ^1.1.2 "@types/chance": ^1.1.2
@ -31810,14 +31793,6 @@ fsevents@~2.1.1:
version: 0.0.0-use.local version: 0.0.0-use.local
resolution: "fxa-graphql-api@workspace:packages/fxa-graphql-api" resolution: "fxa-graphql-api@workspace:packages/fxa-graphql-api"
dependencies: dependencies:
"@nestjs/cli": ^9.4.0
"@nestjs/common": ^9.4.1
"@nestjs/config": ^3.0.0
"@nestjs/core": ^9.2.0
"@nestjs/graphql": ^8.0.2
"@nestjs/mapped-types": ^1.2.0
"@nestjs/passport": ^9.0.3
"@nestjs/platform-express": ^9.4.0
"@sentry/integrations": ^6.19.1 "@sentry/integrations": ^6.19.1
"@sentry/node": ^6.19.1 "@sentry/node": ^6.19.1
"@types/body-parser": ^1 "@types/body-parser": ^1
@ -32238,7 +32213,6 @@ fsevents@~2.1.1:
"@nestjs/core": ^9.2.0 "@nestjs/core": ^9.2.0
"@nestjs/graphql": ^8.0.2 "@nestjs/graphql": ^8.0.2
"@nestjs/mapped-types": ^1.2.0 "@nestjs/mapped-types": ^1.2.0
"@nestjs/testing": ^9.2.1
"@opentelemetry/api": ~1.4.0 "@opentelemetry/api": ~1.4.0
"@opentelemetry/auto-instrumentations-node": ~0.37.0 "@opentelemetry/auto-instrumentations-node": ~0.37.0
"@opentelemetry/context-zone": ~1.13.0 "@opentelemetry/context-zone": ~1.13.0
@ -32346,6 +32320,17 @@ fsevents@~2.1.1:
"@graphql-codegen/client-preset": ^4.1.0 "@graphql-codegen/client-preset": ^4.1.0
"@graphql-codegen/typescript": 4.0.1 "@graphql-codegen/typescript": 4.0.1
"@graphql-codegen/typescript-document-nodes": 4.0.1 "@graphql-codegen/typescript-document-nodes": 4.0.1
"@nestjs/cli": ^9.4.0
"@nestjs/common": ^9.4.1
"@nestjs/config": ^3.0.0
"@nestjs/core": ^9.2.0
"@nestjs/graphql": ^8.0.2
"@nestjs/mapped-types": ^1.2.0
"@nestjs/passport": ^9.0.3
"@nestjs/platform-express": ^9.4.0
"@nestjs/schedule": ^2.2.2
"@nestjs/schematics": ^9.2.0
"@nestjs/testing": ^9.2.1
"@nx/eslint-plugin": 16.6.0 "@nx/eslint-plugin": 16.6.0
"@nx/jest": 16.6.0 "@nx/jest": 16.6.0
"@nx/js": 16.6.0 "@nx/js": 16.6.0