Skip to content

Refactor starter kit (part 1) #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 48 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
97aa96c
refactor(starter-kit): first commit of the starter kit
Yehonal Mar 25, 2023
fb8ecff
merge
Yehonal Mar 25, 2023
c61a5bc
fix package lock
Yehonal Mar 25, 2023
3a7f339
fix package lock again
Yehonal Mar 25, 2023
57d5d33
updates
Yehonal Mar 25, 2023
001cb28
fix build
Yehonal Mar 26, 2023
d2a2079
fix
Yehonal Mar 26, 2023
94deb49
fix package
Yehonal Mar 26, 2023
f8459e3
updates
Yehonal Mar 26, 2023
fcc7bd7
fix
Yehonal Mar 26, 2023
cdca068
Merge branch 'dev' of https://github.com/drassil/nestjs-yalc into ref…
Yehonal Apr 22, 2023
e67ef5e
update package json
Yehonal Apr 22, 2023
05ae056
merge
Yehonal May 11, 2023
af59c5a
updates
Yehonal May 26, 2023
fae666c
updates
Yehonal Jul 15, 2023
d897f0f
Merge branch 'dev' of https://github.com/drassil/nestjs-yalc into ref…
Yehonal Dec 22, 2023
07f880b
fix
Yehonal Dec 27, 2023
9048f8f
update
Yehonal Jan 2, 2024
00c47c3
updates
Yehonal Jan 21, 2024
2654e2d
Merge branches 'refactor-starter-kit' and 'dev' of https://github.com…
Yehonal Jan 21, 2024
5abd25f
updates
Yehonal Feb 2, 2024
c7f2364
fix
Yehonal Feb 2, 2024
eb9ebb9
Merge branch 'dev' of https://github.com/drassil/nestjs-yalc into ref…
Yehonal Feb 2, 2024
703112a
package fixes
Yehonal Feb 2, 2024
184b098
updates
Yehonal Feb 4, 2024
0d780dc
updates
Yehonal Mar 22, 2024
a57c9cc
fix build
Yehonal Mar 23, 2024
44fd264
update
Yehonal Mar 27, 2024
554f182
update
Yehonal Mar 27, 2024
c1a0022
updates
Yehonal Apr 2, 2024
8ad5dc8
merge
Yehonal Apr 2, 2024
0d4e928
update
Yehonal Apr 2, 2024
d6734a2
updates
Yehonal Apr 2, 2024
64fc77b
update
Yehonal Apr 2, 2024
48bba2b
update
Yehonal Apr 8, 2024
9d61fa0
update
Yehonal Apr 14, 2024
1c9fb9c
Merge branch 'dev' of https://github.com/drassil/nestjs-yalc into ref…
Yehonal Jun 4, 2024
b83e228
Merge branch 'dev' of https://github.com/drassil/nestjs-yalc into ref…
Yehonal Jun 4, 2024
f6b3c36
update
Yehonal Jun 4, 2024
6d1f422
update
Yehonal Jun 9, 2024
ae9fe3a
update
Yehonal Jun 11, 2024
26dbc56
fix webpack
Yehonal Jun 11, 2024
5692218
fix
Yehonal Jun 13, 2024
1a6cd56
Merge branch 'dev' of https://github.com/drassil/nestjs-yalc into ref…
Yehonal Jun 14, 2024
2741121
update
Yehonal Jun 14, 2024
62dd552
fix
Yehonal Jun 23, 2024
21a2ca9
updates
Yehonal Jun 24, 2024
c1bd259
updates
Yehonal Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 1 addition & 46 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,49 +1,4 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
parserOptions: {
project: 'tsconfig.dev.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'prettier/prettier': ['error', { singleQuote: true, trailingComma: 'all' }],
},
ignorePatterns: [
'**/node_modules',
'**/*spec.ts',
'**/__tests__',
'**/__mocks__',
'**/jest.config.ts',
'var',
],
overrides: [
{
files: ['**/*.cjs', '**/*.mjs', '**/*.js'],
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
},
{
files: ['**/*.ts'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': ['warn'],
'no-console': 'error',
'@typescript-eslint/no-unused-vars': 'off',
eqeqeq: 1,
},
},
],
extends: ['eslint-config-yalc'],
};
23 changes: 2 additions & 21 deletions .eslintrc.vscode.cjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
module.exports = {
extends: ['./.eslintrc.cjs'],
parserOptions: {
// by disabling the type-checking feature we exponentially increase the speed of the linting process
// while editing the code in the VSCode
// NOTE: this doesn't affect the lint command that is executed in the CI/CD pipeline
project: false,
EXPERIMENTAL_useProjectService: false,
},
overrides: [
{
files: ['**/*.ts'],
rules: {
/**
* The following rules do not work when the parserOptions.project is set to false.
* Because of missing type-checking feature
*/
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/naming-convention': 'off',
},
},
],
root: true,
extends: ['eslint-config-yalc-vscode'],
};
7 changes: 7 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ runs:
run: |
export JEST_WORKERS=${{ inputs.jest-workers }}
npm run test:cov

- name: Test platform-kit
shell: bash
working-directory: ${{ github.workspace }}/${{ inputs.working-directory }}/platform-kit
run: |
export JEST_WORKERS=${{ inputs.jest-workers }}
npm run ci:checks -- --only=test:apps:e2e
13 changes: 10 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[jsonc]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "vscode.json-language-features"
},
"[yaml]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "vscode.json-language-features"
},
"[html]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
Expand All @@ -22,9 +23,15 @@
"jest.runMode": "on-demand",
"jest.jestCommandLine": "npm run test:vscode --",
"jest.coverageFormatter": "DefaultFormatter",
"eslint.validate": [
"javascript",
"typescript"
],
"eslint.format.enable": true,
"eslint.codeActionsOnSave.mode": "problems",
"eslint.enable": true,
"eslint.options": {
"overrideConfigFile": ".eslintrc.vscode.cjs",
"ignore": false
},
}
}
5 changes: 5 additions & 0 deletions api-strategy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"type": "module",
"description": "",
"main": "src/index.ts",
"custom": {
"nest": {
"type": "library"
}
},
"exports": {
".": "./src/index.ts",
"./*.js": "./src/*.ts",
Expand Down
9 changes: 8 additions & 1 deletion api-strategy/src/strategies/http-abstract-call.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ export interface HttpOptions<
parameters?: TParams;
}

export interface IHttpCallStrategyResponse<T = any> {
export interface IHttpCallStrategyResponse<T = any, THeaders = any> {
data: T;
status: number;
statusText: string;
/**
* This are the headers transformed to be compatible with the standard OutgoingHttpHeaders
*/
headers: OutgoingHttpHeaders;
/**
* This are the headers as they are returned by the http library used
*/
rawHeaders: THeaders;
// config: AxiosRequestConfig<D>;
request?: any;
}
Expand Down
37 changes: 26 additions & 11 deletions api-strategy/src/strategies/nest-http-call.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
HttpOptions,
IHttpCallStrategyOptions,
} from './http-abstract-call.strategy.js';
import { AxiosRequestConfig } from 'axios';
import { AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios';
import { YalcGlobalClsService } from '@nestjs-yalc/app/cls.module.js';
import { filterHeaders } from '../header-whitelist.helper.js';
import { OutgoingHttpHeaders } from 'http';

export class NestHttpCallStrategy extends HttpAbstractStrategy {
constructor(
Expand All @@ -23,7 +24,7 @@
async call<TOptData, TParams extends Record<string, any>, TResData>(
path: string,
options?: HttpOptions<TOptData, TParams>,
): Promise<IHttpCallStrategyResponse<TResData>> {
): Promise<IHttpCallStrategyResponse<TResData, AxiosResponse['headers']>> {
const clsHeaders = filterHeaders(
this.clsService.get('headers'),
this.options.headersWhitelist,
Expand Down Expand Up @@ -51,18 +52,32 @@
_options.params = new URLSearchParams(options.parameters);
}

const { data, ...res } = await this.httpService.axiosRef.request({
headers: _options?.headers as any,
method: _options?.method,
signal: _options?.signal,
data: _options?.data,
params: _options?.params,
url: `${this.baseUrl}${path}`,
});
const { headers: axiosHeaders, ...res } =
await this.httpService.axiosRef.request({
headers: _options?.headers as any,
method: _options?.method,
signal: _options?.signal,
data: _options?.data,
params: _options?.params,
url: `${this.baseUrl}${path}`,
});

const outgoingHeaders = Object.entries(axiosHeaders).reduce(
(acc, [k, v]) => {
if (v instanceof AxiosHeaders) {
v = v.toJSON();
}

acc[k] = v;
return acc;
},
{} as OutgoingHttpHeaders,
);

return {
...res,
data,
headers: outgoingHeaders,
rawHeaders: axiosHeaders,

Check failure on line 80 in api-strategy/src/strategies/nest-http-call.strategy.ts

View workflow job for this annotation

GitHub Actions / Common libs build tests

Type 'Partial<RawAxiosHeaders & { Server: AxiosHeaderValue; "Content-Type": AxiosHeaderValue; "Content-Length": AxiosHeaderValue; "Cache-Control": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; } & { ...; }> | AxiosResponseHeaders' is not assignable to type 'AxiosResponseHeaders | Partial<RawAxiosHeaders & { Server: AxiosHeaderValue; "Content-Type": AxiosHeaderValue; "Content-Length": AxiosHeaderValue; "Cache-Control": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; } & { ...; }>'.
};
}
}
Expand Down
1 change: 1 addition & 0 deletions api-strategy/src/strategies/nest-local-call.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class NestLocalCallStrategy extends HttpAbstractStrategy {
return {
data,
headers: result.headers,
rawHeaders: result.headers,
status: result.statusCode,
statusText: result.statusMessage,
request: result.payload, // TODO: double check if it's the correct value
Expand Down
5 changes: 5 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"type": "module",
"description": "",
"main": "src/index.ts",
"custom": {
"nest": {
"type": "library"
}
},
"exports": {
".": "./src/index.ts",
"./*.js": "./src/*.ts",
Expand Down
5 changes: 4 additions & 1 deletion app/src/app-bootstrap-base.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { IServiceConf } from './conf.type.js';
import { SYSTEM_LOGGER_SERVICE } from './def.const.js';
import { YalcDefaultAppModule } from './base-app-module.helper.js';
import { ICreateOptions, INestCreateOptions } from './app-bootstrap.helper.js';
import { getAppConfigToken } from './app-config.service.js';
import { EventModule } from '@nestjs-yalc/event-manager/event.module.js';
import { LoggerServiceFactory } from '@nestjs-yalc/logger/logger.service.js';
import { FastifyInstance } from 'fastify';
Expand Down Expand Up @@ -66,7 +67,9 @@ export abstract class BaseAppBootstrap<
}

getConf() {
const configService = this.getApp().get<ConfigService>(ConfigService);
const configService = this.getApp().get<ConfigService>(
getAppConfigToken(this.appAlias),
);
return configService.get<IServiceConf>(this.appAlias);
}

Expand Down
20 changes: 11 additions & 9 deletions app/src/app-bootstrap.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ export class AppBootstrap<
async listen(callback?: {
(port: number, host: string, domain: string): void;
}) {
const port = this.getConf()?.port || 0;
const host = this.getConf()?.host || '0.0.0.0';
let apiPrefix = this.getConf()?.apiPrefix;
const conf = this.getConf();
const port = conf?.port || 0;
const host = conf?.host || '0.0.0.0';
let apiPrefix = conf?.apiPrefix;
apiPrefix = apiPrefix ? `/${apiPrefix}` : '';
const domain = this.getConf()?.domain || 'localhost';
const domain = conf?.domain || 'localhost';
await this.getApp().listen(port, host, async (_err, address) => {
// eslint-disable-next-line no-console
console.debug(`Server ${this.appAlias} listening on
Expand All @@ -205,11 +206,12 @@ export class AppBootstrap<
http://${domain}:${port}${apiPrefix}/
${address}`);

// // eslint-disable-next-line no-console
// console.debug(`GraphQL ${this.appAlias} listening on
// http://localhost:${port}${apiPrefix}/graphql
// http://127.0.0.1:${port}${apiPrefix}/graphql
// http://${domain}:${port}${apiPrefix}/graphql`);
// eslint-disable-next-line no-console
console.debug(`GraphQL ${this.appAlias} listening on
http://localhost:${port}${apiPrefix}/graphql
http://127.0.0.1:${port}${apiPrefix}/graphql
http://${domain}:${port}${apiPrefix}/graphql
${address}/graphql`);

if (this.isSwaggerEnabled) {
// eslint-disable-next-line no-console
Expand Down
18 changes: 9 additions & 9 deletions app/src/app-imports.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import { JwtModule } from '@nestjs/jwt';
import { EventEmitter2, EventEmitterModule } from '@nestjs/event-emitter';
import { IServiceConf } from './conf.type.js';
import { GraphQLError } from 'graphql/error';
import { GraphQLFormattedError } from 'graphql/error';
// import { AppLoggerModule } from '@nestjs-yalc/logger/app-logger.module.js';
import { TypeORMLogger } from '@nestjs-yalc/logger/typeorm-logger.js';
import { CURAPP_CONF_ALIAS } from './def.const.js';
import { AppEvents } from './app.events.js';
import { GqlComplexityPlugin } from '@nestjs-yalc/graphql/plugins/gql-complexity.plugin.js';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { ClassType } from '@nestjs-yalc/types/globals.d.js';
import { isClass } from '@nestjs-yalc/utils/class.helper.js';
import {
Expand All @@ -38,6 +36,7 @@
} from '@nestjs/apollo';

import * as dotenv from 'dotenv';
import { ApolloServerPlugin } from '@apollo/server';
dotenv.config(); // preload .env root file before all the others

export interface IAppImportsFactory {
Expand Down Expand Up @@ -166,7 +165,7 @@
GraphQLModule.forRootAsync<ApolloFederationDriverConfig>({
driver: ApolloFederationDriver,
imports: [ApolloPluginsModule.forRoot()],
useFactory: async (

Check failure on line 168 in app/src/app-imports.factory.ts

View workflow job for this annotation

GitHub Actions / Common libs build tests

Type '(configService: ConfigService<Record<string, unknown>, false>, appContext: AppContextService, eventEmitter: EventEmitter2, gqlPluginList: ApolloServerPlugin<...>[]) => Promise<...>' is not assignable to type '(...args: any[]) => Omit<ApolloDriverConfig, "driver"> | Promise<Omit<ApolloDriverConfig, "driver">>'.
configService: ConfigService,
appContext: AppContextService,
eventEmitter: EventEmitter2,
Expand Down Expand Up @@ -218,13 +217,14 @@
useGlobalPrefix: true,
// Makes sure not too much info. is revealed when reporting errors in non-dev stages
// @url: https://github.com/nestjs/graphql/issues/1053#issuecomment-740739410
formatError: (error: GraphQLError) => {
const exception: any = error.extensions?.exception;
const message = exception?.response?.message || error.message;
formatError: (formattedError: GraphQLFormattedError, error) => {
const exception: any = formattedError.extensions?.exception;
const message =
exception?.response?.message || formattedError.message;

if (conf && (conf.isDev || conf.isTest)) {
return {
...error,
...formattedError,
message, // override the message with meaningful info
};
}
Expand All @@ -233,9 +233,9 @@
const productionError: GraphQLFormattedError = {
message,
extensions: {
path: error.path,
code: error.extensions?.code,
exception: error.originalError, // error without stacktrace
path: formattedError.path,
code: formattedError.extensions?.code,
exception: error, // error without stacktrace
},
};

Expand Down
Loading
Loading