Skip to content
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

Human APP backend - 4th milestone #2170

Merged
merged 92 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
969973d
Merge pull request #17 from blockydevs/error_handling
MWBlocky Mar 5, 2024
10ef69b
Merge pull request #15 from blockydevs/10-jobs-discovery
MWBlocky Mar 5, 2024
bbeb5ad
Merge pull request #16 from blockydevs/11-job-assignment
MWBlocky Mar 5, 2024
964c586
Merge pull request #18 from blockydevs/authorization-token-handling
MWBlocky Mar 5, 2024
8d04a7d
Merge pull request #21 from blockydevs/unit_tests_fix
MWBlocky Mar 6, 2024
7b924e8
Merge pull request #14 from blockydevs/#13-Oracles-discovery
macnablocky Mar 6, 2024
0c1f48b
Merge pull request #20 from blockydevs/#Statistics-Exchange-oracle
macnablocky Mar 14, 2024
ee5e300
Naming covention alignemnt (#27)
macnablocky Mar 15, 2024
9c3c6dd
CI/CD workflow
MWBlocky Mar 22, 2024
7fd8cc6
fix(unit tests): Remove validationSchema from ConfigModule
MWBlocky Mar 22, 2024
0239b96
Merge pull request #28 from blockydevs/22-ci_cd_from_develop
MWBlocky Mar 22, 2024
190e7e9
Fixes after check
macnablocky Mar 26, 2024
f3f2daa
Removes unnecessary comment
macnablocky Mar 26, 2024
ac04436
Fixes SDK limitation
macnablocky Mar 26, 2024
6d40ce8
Removes unnecessary interceptor, changes Body to Query in request for…
macnablocky Mar 26, 2024
c90f510
Adds statistics related DTO interfaces with api mapping
macnablocky Mar 27, 2024
b1b42be
Changes in interface naming convention of received data
macnablocky Apr 3, 2024
4b9ab6c
Review fixes
macnablocky Apr 8, 2024
6d1e057
Review fixes
macnablocky Apr 8, 2024
0a3becc
Merge remote-tracking branch 'origin/fixes-after-testing-with-stage-e…
macnablocky Apr 8, 2024
5f79f24
Review fixes
macnablocky Apr 8, 2024
9c2f4a6
Review fixes
macnablocky Apr 16, 2024
030ef6d
Merge branch 'refs/heads/develop' into fixes-after-testing-with-stage…
macnablocky Apr 16, 2024
413a3e5
Changes logic of calling exchange oracle: url is obtained based on th…
macnablocky Apr 17, 2024
8ade9ab
Merge branch 'refs/heads/develop-human' into human-mainrepo-update
macnablocky Apr 18, 2024
885168a
Merge pull request #51 from blockydevs/human-mainrepo-update
macnablocky Apr 18, 2024
8f8c8a2
Merge branch 'refs/heads/develop' into fixes-after-testing-with-stage…
macnablocky Apr 18, 2024
a673b3f
Adds test coverage
macnablocky Apr 18, 2024
da0804a
Adds test coverage
macnablocky Apr 18, 2024
c3a75f2
Adds kv store to the modules that use it
macnablocky Apr 18, 2024
4d8c31f
minor fixes
macnablocky Apr 18, 2024
59e2fd3
minor fixes
macnablocky Apr 18, 2024
e6616f6
Alignment of the swagger and interface used in the project
macnablocky Apr 22, 2024
2cdff35
Alignment after testing with stage exchange oracle (#29)
macnablocky Apr 23, 2024
5bcf102
Add email verification endpoints and related logic.
MWBlocky Apr 23, 2024
10c4579
name: human-app -> human-app-server in package.json (#63)
macnablocky Apr 23, 2024
c65f09f
Implement password reset functionality.
MWBlocky Apr 23, 2024
6b95072
Add disableOperator and prepareSignature methods.
MWBlocky Apr 24, 2024
5ebf3da
A property has been set in the eslint config to avoid enforcing a lin…
MWBlocky Apr 24, 2024
1baf695
Implement KYC procedure start.
MWBlocky Apr 24, 2024
100e2b9
Merge branch 'develop' of github.com:blockydevs/human-protocol into 3…
MWBlocky Apr 24, 2024
c29be7b
Integration with the KYC procedure, password reset and disable operat…
MWBlocky Apr 24, 2024
20086ff
The variable name 'restorePasswordDto' in the sendRestorePassword fun…
MWBlocky Apr 25, 2024
4a83a78
Update 'type' field data type in PrepareSignature model.
MWBlocky Apr 25, 2024
b5c63a6
Refactor prepareSignature test and update response fixture.
MWBlocky Apr 25, 2024
2c8c15c
Refactor service injections in multiple controllers, renamed to a gen…
MWBlocky Apr 25, 2024
cef2dc8
Refactor services to use 'gateway' instead of 'reputationOracleService'.
MWBlocky Apr 25, 2024
aa1e065
Sets base paths in the controllers and simplify the path of each endp…
MWBlocky Apr 25, 2024
ccb46f2
Refactor email verification test fixtures.
MWBlocky Apr 25, 2024
0d7453c
Refactor 'h_captcha_token'.
MWBlocky Apr 25, 2024
b2fb862
Enhance test coverage for oracle gateway.
MWBlocky Apr 26, 2024
ad8646a
bug fixed
MWBlocky Apr 26, 2024
6731508
Remove hCaptcha token mapping in user-worker and password-reset mappers.
MWBlocky Apr 26, 2024
9cae000
Refactor code to separate PrepareSignature functionality into its own…
MWBlocky May 7, 2024
5e8bcc5
fix: Change naming conventions in password-reset mapper.
MWBlocky May 8, 2024
75e7831
Merge remote-tracking branch 'origin/3rd_milestone_features' into 3rd…
MWBlocky May 8, 2024
e7db099
Fixes after code review (2024-05-07) (#75)
MWBlocky May 9, 2024
df518b3
Fixes CR 2024-05-10 (#78)
MWBlocky May 10, 2024
9362c89
Fix typo in oracle-discovery.service file name and references.
MWBlocky May 13, 2024
7d18e7f
Merge pull request #80 from blockydevs/fix_typo
MWBlocky May 13, 2024
1fee79a
Merge develop
MWBlocky May 13, 2024
ef6a79b
Merge develop
MWBlocky May 13, 2024
22d7e36
Merge branch 'develop' of github.com:blockydevs/human-protocol into 3…
MWBlocky May 13, 2024
e5ad2cb
Merge conflict fixes
MWBlocky May 13, 2024
74cce2e
Adds Email Confirmation, KYC procedure, Password Reset and Disable O…
MWBlocky May 13, 2024
abc0164
Merge commit
MWBlocky May 13, 2024
25f6701
Merge branch '3rd_milestone_features' into develop
MWBlocky May 13, 2024
bd8c8dd
Fixes CR 2024-05-15 (#88)
MWBlocky May 15, 2024
8779a4f
Fixed reputation-oracle.gateway.spec.ts (#90)
MWBlocky May 15, 2024
34355b2
Removes authorisation from prepare-signature endpoint (#92)
macnablocky May 16, 2024
035e9b1
Merge branch 'humanprotocol:develop' into develop
BartoszSolkaBD May 27, 2024
179358e
4th milestone features (#79)
macnablocky Jun 20, 2024
129edc0
Merge remote-tracking branch 'refs/remotes/upstream/develop' into dev…
macnablocky Jun 20, 2024
83a1b59
fixes after merge
macnablocky Jun 20, 2024
41c4d19
fix(app/worker/jobs): fix jobs resigning (#138)
KacperKoza343 Jun 21, 2024
70ccdd1
Add TokenRefresh feature in reputation oracle integration (#141)
MWBlocky Jun 21, 2024
85225b0
Update mapping conventions for pagination and sorting (#144)
MWBlocky Jun 24, 2024
272c620
Fixes after client review (#150)
macnablocky Jun 26, 2024
acd2269
Modifies filtering in oracle discovery to be case insensitive (but wi…
macnablocky Jun 26, 2024
7e66275
Merge remote-tracking branch 'refs/remotes/upstream/develop' into dev…
macnablocky Jun 26, 2024
68953ae
Fixes in validators, fixes in parsing Oracle Discovery DTO
macnablocky Jun 27, 2024
bccd55f
Revert "Fixes in validators, fixes in parsing Oracle Discovery DTO"
macnablocky Jun 27, 2024
61ed73e
Validator fixes (#166)
macnablocky Jun 27, 2024
784b18f
Adds optional validator to jobsDiscoveryParamsDto.sort_field (#168)
macnablocky Jun 27, 2024
c0539de
Human app maintanance (#178)
macnablocky Jul 2, 2024
652acc5
HAM-16/30/31/32 (#181)
macnablocky Jul 3, 2024
6ce017e
Fixes in resing job (#187)
macnablocky Jul 4, 2024
08f5082
Changes assignment id back from number to string (#190)
macnablocky Jul 5, 2024
4436a37
Changes assignment id back from number to string (#188)
macnablocky Jul 5, 2024
3f183dd
Ham 8 backend implementation (#192)
macnablocky Jul 5, 2024
2249d8b
updates default allowed headers (#199)
macnablocky Jul 5, 2024
b4ca519
Reputation/Exchange oracle response parsing refactor (#203)
macnablocky Jul 9, 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
17 changes: 14 additions & 3 deletions packages/apps/human-app/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ REPUTATION_ORACLE_URL= # string
REPUTATION_ORACLE_ADDRESS= # string
REDIS_HOST= # string, example: localhost
REDIS_PORT= # number, example: 6379
RPC_URL= # string
CHAIN_IDS_ENABLED= # number array, example: 80002,80001
HCAPTCHA_LABELING_STATS_API_URL= # string
HCAPTCHA_LABELING_VERIFY_API_URL= # string
HCAPTCHA_LABELING_API_KEY= # string
DAILY_HMT_SPENT_KEY= # string
IS_AXIOS_REQUEST_LOGGING_ENABLED= #string, true if enabled, disabled otherwise
# CACHE TTL VALUES
CACHE_TTL_ORACLE_DISCOVERY= # number, example: 43200
CACHE_TTL_ORACLE_STATS= # number, example: 900
CACHE_TTL_USER_STATS= # number, example: 86400
CACHE_TTL_EXCHANGE_ORACLE_URL= # number: example 86400
CACHE_TTL_HCAPTCHA_USER_STATS= # number: example 86400
CACHE_TTL_DAILY_HMT_SPENT= # number: example 86400
# E2E TESTING
E2E_TESTING_EMAIL_ADDRESS= # string
E2E_TESTING_PASSWORD= # string
E2E_TESTING_EXCHANGE_ORACLE_URL= # string
E2E_TESTING_ESCROW_ADDRESS= # string
E2E_TESTING_ESCROW_CHAIN_ID= # number
RPC_URL= # string
CORS_ENABLED= # boolean, example: true
# CORS
CORS_ALLOWED_ORIGIN= # string example: http://localhost:5173
CORS_ALLOWED_HEADERS= # string, example: 'Content-Type,Accept'
CHAIN_IDS_ENABLED= # number array, example: 80002,80001
CORS_ENABLED= # boolean, example: true
31 changes: 25 additions & 6 deletions packages/apps/human-app/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,28 @@ Models are used to define the shape and responsibilities of the data:

### Additional Information Regarding Project Structure

- **Mappers**: There are two types of mappers. The first type is domain-specific, used in each module
to distinguish between DTO and Command datatypes. The second type is layer-specific and part of gateway integration.
This division of responsibilities is intentional, as gateways serve as the gathering point between many domain purposes.
Domain-specific mappers in this context would be overly convoluted and difficult to configure.
- **Gateway Configuration**: The configuration of the gateways' destination points is located
in the `gateway-config.service.ts` file.
- **Mappers**: There are two types of mappers. The first type is domain-specific, used in each module
to distinguish between DTO and Command datatypes. The second type is layer-specific and part of gateway integration.
This division of responsibilities is intentional, as gateways serve as the gathering point between many domain purposes.
Domain-specific mappers in this context would be overly convoluted and difficult to configure.
- **Gateway Configuration**: The configuration of the gateways' destination points is located
in the `gateway-config.service.ts` file.
- **Caching**: Cache persistence functionality was introduced in this project for optimization purposes. Redis was chosen
as the in-memory storage. The TTL can be checked and changed in the `.env.example` file, all `TTL` values are in seconds:
* `REDIS_HOST` - URL of the Redis host
* `REDIS_PORT` - port on which Redis is hosted
* `CACHE_TTL_ORACLE_DISCOVERY` - time of persisting found oracles
* `CACHE_TTL_ORACLE_STATS` - time of persisting statistics of the given oracle
* `CACHE_TTL_DAILY_HMT_SPENT` - time of persisting statistics of global daily HMT expenditures
* `CACHE_TTL_USER_STATS` - time of persisting statistics of the given user
* `CACHE_TTL_HCAPTCHA_USER_STATS` - time of persisting statistics related to h-captcha tasks for given user
* `CACHE_TTL_EXCHANGE_ORACLE_URL` - time of persisting exchange oracle URL

Caching is used for persisting the exchange oracle URL as well as responses from the following endpoints:
* `/h-captcha/daily-hmt-spent`
* `/h-captcha/user-stats`
* `/oracles`
* `/statistics/stats`
* `/statistics/stats/assignment`

Redis config may be found in: `./packages/apps/human-app/server/src/common/config/cache-factory.config.ts`
7 changes: 6 additions & 1 deletion packages/apps/human-app/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.8",
"@nestjs/platform-express": "^10.3.9",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/swagger": "^7.1.13",
"cache-manager": "^5.4.0",
"cache-manager-redis-store": "^3.0.1",
Expand All @@ -39,7 +41,9 @@
"ethers": "^6.12.1",
"joi": "^17.12.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
"rxjs": "^7.2.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1"
},
"devDependencies": {
"@nestjs/cli": "^10.3.2",
Expand All @@ -49,6 +53,7 @@
"@types/jest": "29.5.12",
"@types/node": "20.12.12",
"@types/supertest": "^2.0.15",
"@types/passport-jwt": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.55.0",
Expand Down
19 changes: 19 additions & 0 deletions packages/apps/human-app/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ import { PasswordResetModule } from './modules/password-reset/password-reset.mod
import { DisableOperatorModule } from './modules/disable-operator/disable-operator.module';
import { KycProcedureModule } from './modules/kyc-procedure/kyc-procedure.module';
import { PrepareSignatureModule } from './modules/prepare-signature/prepare-signature.module';
import { HCaptchaModule } from './modules/h-captcha/h-captcha.module';
import { HCaptchaLabelingModule } from './integrations/h-captcha-labeling/h-captcha-labeling.module';
import { HCaptchaController } from './modules/h-captcha/h-captcha.controller';
import { EscrowUtilsModule } from './integrations/escrow/escrow-utils.module';
import Joi from 'joi';
import { ChainId } from '@human-protocol/sdk';
import { RegisterAddressController } from './modules/register-address/register-address.controller';
import { RegisterAddressModule } from './modules/register-address/register-address.module';
import { InterceptorModule } from './common/interceptors/interceptor.module';
import { TokenRefreshModule } from './modules/token-refresh/token-refresh.module';
import { TokenRefreshController } from './modules/token-refresh/token-refresh.controller';

@Module({
imports: [
Expand All @@ -44,6 +52,9 @@ import { ChainId } from '@human-protocol/sdk';
REDIS_PORT: Joi.number().required(),
REDIS_HOST: Joi.string().required(),
RPC_URL: Joi.string().required(),
HCAPTCHA_LABELING_STATS_API_URL: Joi.string().required(),
HCAPTCHA_LABELING_VERIFY_API_URL: Joi.string().required(),
HCAPTCHA_LABELING_API_KEY: Joi.string().required(),
CHAIN_IDS_ENABLED: Joi.string()
.custom((value) => {
const chainIds = value.split(',');
Expand Down Expand Up @@ -79,7 +90,12 @@ import { ChainId } from '@human-protocol/sdk';
DisableOperatorModule,
KycProcedureModule,
PrepareSignatureModule,
HCaptchaModule,
HCaptchaLabelingModule,
EscrowUtilsModule,
RegisterAddressModule,
InterceptorModule,
TokenRefreshModule,
],
controllers: [
AppController,
Expand All @@ -89,6 +105,9 @@ import { ChainId } from '@human-protocol/sdk';
OracleDiscoveryController,
JobAssignmentController,
StatisticsController,
HCaptchaController,
RegisterAddressController,
TokenRefreshController,
],
exports: [HttpModule],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ConfigService } from '@nestjs/config';
import { Injectable } from '@nestjs/common';
const DEFAULT_CACHE_TTL_HCAPTCHA_USER_STATS = 12 * 60 * 60;
const DEFAULT_CACHE_TTL_ORACLE_STATS = 12 * 60 * 60;
const DEFAULT_CACHE_TTL_USER_STATS = 15 * 60;
const DEFAULT_CACHE_TTL_ORACLE_DISCOVERY = 24 * 60 * 60;
const DEFAULT_CACHE_TTL_DAILY_HMT_SPENT = 24 * 60 * 60;
const DEFAULT_CORS_ALLOWED_ORIGIN = 'http://localhost:5173';
const DEFAULT_CORS_ALLOWED_HEADERS = 'Content-Type, Accept';
const DEFAULT_CACHE_TTL_EXCHANGE_ORACLE_URL = 24 * 60 * 60;
@Injectable()
export class EnvironmentConfigService {
constructor(private configService: ConfigService) {}
Expand All @@ -18,7 +21,14 @@ export class EnvironmentConfigService {
return this.configService.getOrThrow<string>('REPUTATION_ORACLE_URL');
}
get reputationOracleAddress(): string {
return this.configService.getOrThrow<string>('REPUTATION_ORACLE_ADDRESS');
return this.configService
.getOrThrow<string>('REPUTATION_ORACLE_ADDRESS')
.toLowerCase();
}
get axiosRequestLoggingEnabled(): boolean {
return (
this.configService.get('IS_AXIOS_REQUEST_LOGGING_ENABLED') === 'true'
);
}
get cachePort(): number {
return this.configService.getOrThrow<number>('REDIS_PORT');
Expand All @@ -32,13 +42,27 @@ export class EnvironmentConfigService {
DEFAULT_CACHE_TTL_ORACLE_STATS,
);
}

get dailyHmtSpentKey(): string {
return this.configService.getOrThrow('DAILY_HMT_SPENT_KEY');
}
get cacheTtlUserStats(): number {
return this.configService.get<number>(
'CACHE_TTL_USER_STATS',
DEFAULT_CACHE_TTL_USER_STATS,
);
}
get cacheTtlDailyHmtSpent(): number {
return this.configService.get<number>(
'CACHE_TTL_DAILY_HMT_SPENT',
DEFAULT_CACHE_TTL_DAILY_HMT_SPENT,
);
}
get cacheTtlHCaptchaUserStats(): number {
return this.configService.get<number>(
'CACHE_TTL_HCAPTCHA_USER_STATS',
DEFAULT_CACHE_TTL_HCAPTCHA_USER_STATS,
);
}

get cacheTtlOracleDiscovery(): number {
return this.configService.get<number>(
Expand All @@ -64,6 +88,25 @@ export class EnvironmentConfigService {
DEFAULT_CORS_ALLOWED_HEADERS,
);
}
get cacheTtlExchangeOracleUrl(): number {
return this.configService.get<number>(
'CACHE_TTL_EXCHANGE_ORACLE_URL',
DEFAULT_CACHE_TTL_EXCHANGE_ORACLE_URL,
);
}
get hcaptchaLabelingStatsApiUrl(): string {
return this.configService.getOrThrow<string>(
'HCAPTCHA_LABELING_STATS_API_URL',
);
}
get hcaptchaLabelingVerifyApiUrl(): string {
return this.configService.getOrThrow<string>(
'HCAPTCHA_LABELING_VERIFY_API_URL',
);
}
get hcaptchaLabelingApiKey(): string {
return this.configService.getOrThrow<string>('HCAPTCHA_LABELING_API_KEY');
}
get chainIdsEnabled(): string[] {
const chainIds = this.configService.getOrThrow<string>('CHAIN_IDS_ENABLED');
return chainIds.split(',').map((id) => id.trim());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Injectable } from '@nestjs/common';
import { ExternalApiName } from '../enums/external-api-name';
import { GatewayConfig, Gateways } from '../interfaces/endpoint.interface';
import {
HCaptchaLabelingStatsEndpoints, HCaptchaLabelingVerifyEndpoints,
ReputationOracleEndpoints,
} from '../enums/reputation-oracle-endpoints';
import {
GatewayConfig,
GatewayEndpointConfig,
Gateways,
} from '../interfaces/endpoint.interface';
import { EnvironmentConfigService } from './environment-config.service';
import { HttpMethod } from '../enums/http-method';
import { ReputationOracleEndpoints } from '../enums/reputation-oracle-endpoints';

@Injectable()
export class GatewayConfigService {
Expand Down Expand Up @@ -68,7 +75,59 @@ export class GatewayConfigService {
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
},
[ReputationOracleEndpoints.ENABLE_LABELING]: {
endpoint: '/user/register-labeler',
method: HttpMethod.POST,
params: {
api_key: this.envConfig.hcaptchaLabelingApiKey,
portuu3 marked this conversation as resolved.
Show resolved Hide resolved
},
},
[ReputationOracleEndpoints.OPERATOR_SIGNIN]: {
endpoint: '/auth/web3/signin',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[ReputationOracleEndpoints.REGISTER_ADDRESS]: {
endpoint: '/user/register-address',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
[ReputationOracleEndpoints.TOKEN_REFRESH]: {
endpoint: '/auth/refresh',
method: HttpMethod.POST,
headers: this.JSON_HEADER,
},
} as Record<ReputationOracleEndpoints, GatewayEndpointConfig>,
},
[ExternalApiName.HCAPTCHA_LABELING_STATS]: {
url: this.envConfig.hcaptchaLabelingStatsApiUrl,
endpoints: {
[HCaptchaLabelingStatsEndpoints.USER_STATS]: {
endpoint: '/support/labeler/', // email to append as url param
method: HttpMethod.GET,
params: {
api_key: this.envConfig.hcaptchaLabelingApiKey,
},
},
[HCaptchaLabelingStatsEndpoints.DAILY_HMT_SPENT]: {
endpoint: '/requester/daily_hmt_spend',
method: HttpMethod.GET,
params: {
api_key: this.envConfig.hcaptchaLabelingApiKey,
actual: false,
},
},
} as Record<HCaptchaLabelingStatsEndpoints, GatewayEndpointConfig>,
},
[ExternalApiName.HCAPTCHA_LABELING_VERIFY]: {
url: this.envConfig.hcaptchaLabelingVerifyApiUrl,
endpoints: {
[HCaptchaLabelingVerifyEndpoints.TOKEN_VERIFY]: {
endpoint: '/siteverify',
method: HttpMethod.POST,
// params in this method are dynamic
},
} as Record<HCaptchaLabelingVerifyEndpoints, GatewayEndpointConfig>,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {
HCaptchaLabelingStatsEndpoints,
HCaptchaLabelingVerifyEndpoints,
ReputationOracleEndpoints,
} from '../enums/reputation-oracle-endpoints';

export type GatewayEndpoints =
| HCaptchaLabelingStatsEndpoints
| ReputationOracleEndpoints
| HCaptchaLabelingVerifyEndpoints;
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { jwtDecode } from 'jwt-decode';
import { JwtUserData } from '../interfaces/jwt-token.model';

export const Authorization = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
return request.headers['authorization'];
},
);
);
export const JwtPayload = createParamDecorator(
(data: unknown, ctx: ExecutionContext): any => {
const request = ctx.switchToHttp().getRequest();
const token = request.headers['authorization']?.split(' ')[1];
if (!token) return null;
try {
const decoded = jwtDecode(token);
return decoded as JwtUserData;
} catch (error) {
console.error('Error in decoding token: ', error);
return null;
}
},
);
Loading