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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install dependencies
run: yarn install --immutable
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Change core version
uses: jossef/action-set-json-field@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-deploy-contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install dependencies
run: yarn --immutable
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Networks list
id: networks
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-logger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install dependencies
run: yarn install --immutable
- name: Build logger package
run: yarn build:logger
run: yarn workspace @human-protocol/logger build
- name: Publish package
run: yarn workspace @human-protocol/logger npm publish --access public
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-node-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: yarn install --immutable
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Change Node.js SDK version from release tag
uses: jossef/action-set-json-field@v2
if: ${{ github.event_name != 'workflow_dispatch' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-python-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install dependencies
run: yarn install
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: yarn install --immutable
- name: Build core package
if: steps.filter_networks.outputs.continue == 'true'
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Generate and build Subgraph
if: steps.filter_networks.outputs.continue == 'true'
run: yarn generate && yarn build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-node-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Install dependencies
run: yarn install --immutable
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Run Node.js SDK test
run: yarn workspace @human-protocol/sdk test
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-python-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install core package dependencies
run: yarn install --immutable
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install dependencies
run: yarn install --immutable
- name: Build core package
run: yarn build:core
run: yarn workspace @human-protocol/core build
- name: Generate manifest for Polygon for tests
run: NETWORK=polygon yarn workspace @human-protocol/subgraph generate
- name: Run subgraph test
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"scripts": {
"clean": "yarn workspaces foreach --all -p run clean",
"lint": "yarn workspaces foreach --all -p run lint",
"build:core": "yarn workspace @human-protocol/core build",
"build:sdk": "yarn workspace @human-protocol/sdk build",
"build:logger": "yarn workspace @human-protocol/logger build",
Comment thread
dnechay marked this conversation as resolved.
"build:libs": "yarn build:core && yarn build:sdk && yarn build:logger",
"build:libs": "yarn workspaces foreach -Rpt --from '{@human-protocol/sdk,packages/libs/*}' run build",
"docker:infra-up": "make -C ./docker-setup -f Makefile.dev infra-up",
"docker:infra-stop": "make -C ./docker-setup -f Makefile.dev infra-stop",
"docker:infra-down": "make -C ./docker-setup -f Makefile.dev infra-down",
Expand Down
4 changes: 1 addition & 3 deletions packages/apps/job-launcher/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ HCAPTCHA_SECRET=0x0000000000000000000000000000000000000000

# Stripe
PAYMENT_PROVIDER_SECRET_KEY=disabled
PAYMENT_PROVIDER_APP_NAME=Launcher Server Local
PAYMENT_PROVIDER_APP_VERSION=1.0.0
PAYMENT_PROVIDER_APP_NAME=Job Launcher Server Local
PAYMENT_PROVIDER_APP_INFO_URL=http://local.app
PAYMENT_PROVIDER_API_VERSION=2022-11-15

# Sendgrid
SENDGRID_API_KEY=sendgrid-disabled
Expand Down
1 change: 1 addition & 0 deletions packages/apps/job-launcher/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY ${APP_PATH}/package.json ./${APP_PATH}/
# so we need to copy and build them
COPY packages/core ./packages/core
COPY packages/sdk ./packages/sdk
COPY packages/libs ./packages/libs

RUN yarn install

Expand Down
1 change: 1 addition & 0 deletions packages/apps/job-launcher/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"@google-cloud/storage": "^7.15.0",
"@google-cloud/vision": "^4.3.2",
"@human-protocol/logger": "workspace:*",
"@human-protocol/sdk": "workspace:*",
"@nestjs/axios": "^3.1.2",
"@nestjs/common": "^10.2.7",
Expand Down
10 changes: 6 additions & 4 deletions packages/apps/job-launcher/server/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Module } from '@nestjs/common';
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
import { ServeStaticModule } from '@nestjs/serve-static';
import { ScheduleModule } from '@nestjs/schedule';
import { ConfigModule } from '@nestjs/config';
import { join } from 'path';

import { AppController } from './app.controller';
import { DatabaseModule } from './database/database.module';
import { JwtAuthGuard } from './common/guards';
Expand All @@ -12,18 +16,16 @@ import { JobModule } from './modules/job/job.module';
import { PaymentModule } from './modules/payment/payment.module';
import { Web3Module } from './modules/web3/web3.module';
import { envValidator } from './common/config/env-schema';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { StorageModule } from './modules/storage/storage.module';
import { CronJobModule } from './modules/cron-job/cron-job.module';
import { SnakeCaseInterceptor } from './common/interceptors/snake-case';
import { WebhookModule } from './modules/webhook/webhook.module';
import { EnvConfigModule } from './common/config/config.module';
import { ExceptionFilter } from './common/exceptions/exception.filter';
import { ScheduleModule } from '@nestjs/schedule';
import { StatisticModule } from './modules/statistic/statistic.module';
import { QualificationModule } from './modules/qualification/qualification.module';
import { TransformEnumInterceptor } from './common/interceptors/transform-enum.interceptor';
import Environment from './common/utils/environment';

@Module({
providers: [
Expand Down Expand Up @@ -54,7 +56,7 @@ import { TransformEnumInterceptor } from './common/interceptors/transform-enum.i
/**
* First value found takes precendece
*/
envFilePath: [`.env.${process.env.NODE_ENV}`, '.env.local', '.env'],
envFilePath: [`.env.${Environment.name}`, '.env.local', '.env'],
validationSchema: envValidator,
}),
DatabaseModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Joi from 'joi';

export const envValidator = Joi.object({
// General
NODE_ENV: Joi.string(),
HOST: Joi.string(),
PORT: Joi.string(),
FE_URL: Joi.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ export class PaymentProviderConfigService {

/**
* The name of the application interacting with the payment providers API.
* Default: 'Fortune'
* Default: 'Job Launcher Server'
*/
get appName(): string {
return this.configService.get<string>(
'PAYMENT_PROVIDER_APP_NAME',
'Fortune',
'Job Launcher Server',
);
}

/**
* The version of the application interacting with the payment providers API.
* Default: '0.0.1'
* Default: '1.0.0'
*/
get appVersion(): string {
return this.configService.get<string>(
'PAYMENT_PROVIDER_APP_VERSION',
'0.0.1',
'1.0.0',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import { ConfigService } from '@nestjs/config';
export class ServerConfigService {
constructor(private configService: ConfigService) {}

/**
* The environment in which the server is running (e.g., 'development', 'production').
* Default: 'development'
*/
get nodeEnv(): string {
return this.configService.get<string>('NODE_ENV', 'development');
}

/**
* The hostname or IP address on which the server will run.
* Default: 'localhost'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
Catch,
ExceptionFilter as IExceptionFilter,
HttpStatus,
Logger,
} from '@nestjs/common';
import { Request, Response } from 'express';

import {
ValidationError,
AuthError,
Expand All @@ -15,10 +15,11 @@ import {
ServerError,
DatabaseError,
} from '../errors';
import logger from '../../logger';

@Catch()
export class ExceptionFilter implements IExceptionFilter {
private logger = new Logger(ExceptionFilter.name);
private readonly logger = logger.child({ context: ExceptionFilter.name });

private getStatus(exception: any): number {
if (exception instanceof ValidationError) {
Expand Down Expand Up @@ -49,10 +50,7 @@ export class ExceptionFilter implements IExceptionFilter {
const status = this.getStatus(exception);
const message = exception.message || 'Internal server error';

this.logger.error(
`Exception caught: ${message}`,
exception.stack || 'No stack trace available',
);
this.logger.error('Unhandled exception', exception);

response.status(status).json({
statusCode: status,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { EscrowUtils } from '@human-protocol/sdk';
import {
CanActivate,
ExecutionContext,
Injectable,
Logger,
} from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';

import { HEADER_SIGNATURE_KEY } from '../constants';
import { Role } from '../enums/role';
import { AuthError } from '../errors';
import { verifySignature } from '../utils/signature';
import logger from '../../logger';

@Injectable()
export class SignatureAuthGuard implements CanActivate {
private readonly logger = new Logger(SignatureAuthGuard.name);
private readonly logger = logger.child({ context: SignatureAuthGuard.name });

constructor(private role: Role[]) {}

Expand Down Expand Up @@ -49,10 +46,7 @@ export class SignatureAuthGuard implements CanActivate {
return true;
}
} catch (error) {
this.logger.error(
`Error verifying signature: ${error.message}`,
error.stack,
);
this.logger.error('Error verifying signature', error);
}

throw new AuthError('Unauthorized');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {
CanActivate,
ExecutionContext,
Injectable,
Logger,
} from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';

import { WhitelistService } from '../../modules/whitelist/whitelist.service';
import { AuthError } from '../errors';
import logger from '../../logger';

@Injectable()
export class WhitelistAuthGuard implements CanActivate {
private readonly logger = new Logger(WhitelistAuthGuard.name);
private readonly logger = logger.child({ context: WhitelistAuthGuard.name });

constructor(private readonly whitelistService: WhitelistService) {}

Expand All @@ -18,7 +15,7 @@ export class WhitelistAuthGuard implements CanActivate {
const user = request.user;

if (!user) {
this.logger.error('User object is missing in the request.', request);
this.logger.error('User object is missing in the request');
throw new AuthError('User not found.');
}

Expand Down
26 changes: 26 additions & 0 deletions packages/apps/job-launcher/server/src/common/utils/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
enum EnvironmentName {
LOCAL = 'local',
DEVELOPMENT = 'development',
TEST = 'test',
STAGING = 'staging',
PRODUCTION = 'production',
}

class Environment {
static readonly name: string =
process.env.NODE_ENV || EnvironmentName.DEVELOPMENT;

static isDevelopment(): boolean {
return [
EnvironmentName.DEVELOPMENT,
EnvironmentName.TEST,
EnvironmentName.LOCAL,
].includes(Environment.name as EnvironmentName);
}

static isTest(): boolean {
return Environment.name === EnvironmentName.TEST;
}
}

export default Environment;
13 changes: 7 additions & 6 deletions packages/apps/job-launcher/server/src/common/utils/slack.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Logger } from '@nestjs/common';
import axios from 'axios';

import logger from '../../logger';

const slackLogger = logger.child({ context: 'sendSlackNotification' });

export async function sendSlackNotification(
webhookUrl: string,
message: string,
): Promise<boolean> {
const logger = new Logger('Slack');

const payload = {
text: message,
};
Expand All @@ -17,10 +18,10 @@ export async function sendSlackNotification(

try {
await axios.post(webhookUrl, payload);
logger.log('Slack notification sent:', payload);
slackLogger.debug('Slack notification sent', payload);
return true;
} catch (e) {
logger.error('Error sending Slack notification:', e);
} catch (error) {
slackLogger.error('Error sending Slack notification', error);
return false;
}
}
Loading
Loading