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/. */
import { NotFoundError } from 'objection';
import { v4 as uuidv4 } from 'uuid';
import { Injectable } from '@nestjs/common';
import { AccountDatabase, CartState } from '@fxa/shared/db/mysql/account';
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 =>
action in ACTIONS_VALID_STATE;
@Injectable()
export class CartManager {
constructor(private log: Logger, private db: AccountDatabase) {}

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

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

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

@ -2,12 +2,14 @@
* 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 { v4 as uuidv4 } from 'uuid';
import { Injectable } from '@nestjs/common';
import { AccountDatabase } from '@fxa/shared/db/mysql/account';
import { createAccount } from './account.repository';
import { normalizeEmail, randomBytesAsync } from './account.util';
@Injectable()
export class AccountManager {
constructor(private db: AccountDatabase) {}

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

@ -2,6 +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 { Injectable } from '@nestjs/common';
import {
ApolloClient,
InMemoryCache,
@ -17,6 +18,7 @@ import {
} from './errors';
import { BaseError } from '@fxa/shared/error';
@Injectable()
export class ContentfulClient {
client = new ApolloClient({
uri: `${this.contentfulGraphqlApiUri}?access_token=${this.contentfulGraphqlApiKey}`,

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

@ -39,6 +39,14 @@
"dependencies": {
"@faker-js/faker": "^8.0.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",
"diffparser": "^2.0.1",
"hot-shots": "^10.0.0",
@ -99,6 +107,9 @@
"@graphql-codegen/client-preset": "^4.1.0",
"@graphql-codegen/typescript": "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/jest": "16.6.0",
"@nx/js": "16.6.0",

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

@ -9,18 +9,16 @@ cd "$DIR/../../../"
mkdir -p ~/.pm2/logs
mkdir -p artifacts/tests
CI=true yarn workspaces foreach \
--verbose \
--topological-dev \
--include 123done \
--include browserid-verifier \
--include fxa-auth-server \
--include fxa-content-server \
--include fxa-graphql-api \
--include fxa-payments-server \
--include fxa-profile-server \
--include fxa-settings \
run start > ~/.pm2/logs/startup.log
CI=true npx nx run-many -p \
123done \
browserid-verifier \
fxa-auth-server \
fxa-content-server \
fxa-graphql-api \
fxa-payments-server \
fxa-profile-server \
fxa-settings \
-t start > ~/.pm2/logs/startup.log
# 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

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

@ -6,7 +6,7 @@
"prebuild": "rimraf dist && yarn 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",
"build": "yarn prebuild && yarn nest build && yarn copy-config",
"build": "yarn prebuild && nest build && yarn copy-config",
"compile": "tsc --noEmit",
"lint": "eslint .",
"audit": "npm audit --json | audit-filter --nsp-config=.nsprc --audit=-",
@ -40,11 +40,6 @@
"dependencies": {
"@golevelup/ts-jest": "^0.3.2",
"@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-validator": "^0.14.0",
"convict": "^6.2.4",
@ -67,7 +62,6 @@
"tslib": "^2.5.0"
},
"devDependencies": {
"@nestjs/cli": "^9.4.0",
"@types/chance": "^1.1.2",
"@types/convict": "^6.1.1",
"@types/node": "^18.14.2",

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

@ -39,14 +39,6 @@
"@google-cloud/pubsub": "^2.19.4",
"@grpc/grpc-js": "^1.1.3",
"@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/node": "^6.19.1",
"@types/sinon": "10.0.1",
@ -74,9 +66,6 @@
"uuid": "^9.0.0"
},
"devDependencies": {
"@nestjs/cli": "^9.4.0",
"@nestjs/schematics": "^9.2.0",
"@nestjs/testing": "^9.2.1",
"@types/chance": "^1.1.2",
"@types/convict": "^5.2.2",
"@types/express": "^4.17.12",

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

@ -35,13 +35,6 @@
"homepage": "https://github.com/mozilla/fxa#readme",
"readmeFilename": "README.md",
"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/node": "^6.19.1",
"apollo-datasource": "^3.3.1",
@ -82,7 +75,6 @@
"tslib": "^2.5.0"
},
"devDependencies": {
"@nestjs/cli": "^9.4.0",
"@types/body-parser": "^1",
"@types/chance": "^1.1.2",
"@types/convict": "^5.2.2",

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

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

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

@ -31225,12 +31225,6 @@ fsevents@~2.1.1:
dependencies:
"@golevelup/ts-jest": ^0.3.2
"@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/convict": ^6.1.1
"@types/node": ^18.14.2
@ -31714,17 +31708,6 @@ fsevents@~2.1.1:
"@google-cloud/pubsub": ^2.19.4
"@grpc/grpc-js": ^1.1.3
"@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/node": ^6.19.1
"@types/chance": ^1.1.2
@ -31810,14 +31793,6 @@ fsevents@~2.1.1:
version: 0.0.0-use.local
resolution: "fxa-graphql-api@workspace:packages/fxa-graphql-api"
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/node": ^6.19.1
"@types/body-parser": ^1
@ -32238,7 +32213,6 @@ fsevents@~2.1.1:
"@nestjs/core": ^9.2.0
"@nestjs/graphql": ^8.0.2
"@nestjs/mapped-types": ^1.2.0
"@nestjs/testing": ^9.2.1
"@opentelemetry/api": ~1.4.0
"@opentelemetry/auto-instrumentations-node": ~0.37.0
"@opentelemetry/context-zone": ~1.13.0
@ -32346,6 +32320,17 @@ fsevents@~2.1.1:
"@graphql-codegen/client-preset": ^4.1.0
"@graphql-codegen/typescript": 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/jest": 16.6.0
"@nx/js": 16.6.0