@pcg/core 1.0.0-alpha.0 → 1.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +21 -1189
- package/dist/index.js +76 -1867
- package/dist/index.js.map +1 -1
- package/package.json +16 -3
- package/.turbo/turbo-build.log +0 -15
- package/CHANGELOG.md +0 -7
- package/src/abstracts/index.ts +0 -3
- package/src/abstracts/nestjs-resource-service.ts +0 -154
- package/src/abstracts/nestjs-service.ts +0 -25
- package/src/configs/app.config.ts +0 -185
- package/src/configs/db.config.ts +0 -122
- package/src/configs/index.ts +0 -4
- package/src/configs/logger.config.ts +0 -62
- package/src/context/action-context.ts +0 -34
- package/src/context/current-user.ts +0 -49
- package/src/context/index.ts +0 -5
- package/src/context/platform-method-context.ts +0 -5
- package/src/context/service-method-context.ts +0 -47
- package/src/db/snake-naming.strategy.ts +0 -277
- package/src/enums/app-env.enum.ts +0 -36
- package/src/enums/app-mode.enum.ts +0 -5
- package/src/enums/app-server.enum.ts +0 -39
- package/src/enums/index.ts +0 -4
- package/src/enums/worker-mode.enum.ts +0 -11
- package/src/errors/access-denied.error.ts +0 -18
- package/src/errors/bad-request.error.ts +0 -9
- package/src/errors/forbidden.error.ts +0 -9
- package/src/errors/index.ts +0 -8
- package/src/errors/input-validation.error.ts +0 -16
- package/src/errors/nest-error.filter.ts +0 -70
- package/src/errors/nest-error.ts +0 -63
- package/src/errors/not-found.error.ts +0 -9
- package/src/errors/unauthorized.error.ts +0 -9
- package/src/exceptions/http-exception-response.ts +0 -34
- package/src/exceptions/http-exceptions.filter.ts +0 -95
- package/src/index.ts +0 -32
- package/src/jwt/extractors.ts +0 -80
- package/src/jwt/types.ts +0 -209
- package/src/logger/classes/logger-factory.ts +0 -54
- package/src/logger/classes/logger.ts +0 -340
- package/src/logger/classes/nest-system-logger.ts +0 -63
- package/src/logger/classes/typeorm-logger.ts +0 -83
- package/src/logger/index.ts +0 -20
- package/src/logger/logger.constants.ts +0 -24
- package/src/logger/logger.interfaces.ts +0 -98
- package/src/logger/logger.module.ts +0 -45
- package/src/logger/logger.providers.ts +0 -140
- package/src/logger/winston.tools.ts +0 -241
- package/src/middlewares/app.middleware.ts +0 -26
- package/src/middlewares/index.ts +0 -1
- package/src/modules/hooks/base-hook.ts +0 -64
- package/src/modules/hooks/decorators/on-hook.decorator.ts +0 -19
- package/src/modules/hooks/hooks.module.ts +0 -10
- package/src/modules/hooks/hooks.service.ts +0 -28
- package/src/modules/hooks/index.ts +0 -11
- package/src/modules/id/id.module.ts +0 -26
- package/src/modules/id/id.service.ts +0 -57
- package/src/modules/id/index.ts +0 -2
- package/src/modules/postgres-pubsub/index.ts +0 -3
- package/src/modules/postgres-pubsub/postgres-pubsub.module.ts +0 -14
- package/src/modules/postgres-pubsub/postgres-pubsub.ts +0 -461
- package/src/pagination/constants.ts +0 -9
- package/src/pagination/cursor/cursor-pagination.exception.ts +0 -16
- package/src/pagination/cursor/cursor-pagination.helpers.ts +0 -145
- package/src/pagination/cursor/cursor-pagination.input.ts +0 -96
- package/src/pagination/cursor/cursor-pagination.types.ts +0 -127
- package/src/pagination/index.ts +0 -9
- package/src/pagination/offset/offset-pagination.exception.ts +0 -15
- package/src/pagination/offset/offset-pagination.helpers.ts +0 -122
- package/src/pagination/offset/offset-pagination.input.ts +0 -30
- package/src/pagination/offset/offset-pagination.types.ts +0 -82
- package/src/pagination/tools.ts +0 -53
- package/src/tools/compose.ts +0 -92
- package/src/tools/convert-to-bigint.ts +0 -27
- package/src/tools/create-list-meta.ts +0 -64
- package/src/tools/define-statuses.ts +0 -15
- package/src/tools/env.ts +0 -139
- package/src/tools/fetch-total-with-query.ts +0 -48
- package/src/tools/generate-entity-id.ts +0 -23
- package/src/tools/get-request-language.ts +0 -13
- package/src/tools/is-object.ts +0 -10
- package/src/tools/postgres/locale-to-pg-collate.ts +0 -21
- package/src/tools/remove-undefined-properties.ts +0 -20
- package/src/tools/request-id.ts +0 -25
- package/src/tools/stringify-opts.ts +0 -20
- package/src/tools/typeorm/add-filter.ts +0 -164
- package/src/tools/typeorm/ensure-inner-join.ts +0 -36
- package/src/tools/typeorm/ensure-left-join.ts +0 -36
- package/src/tools/typeorm/is-alias-already-busy.ts +0 -25
- package/src/tools/wait.ts +0 -26
- package/src/types/express-request.ts +0 -8
- package/src/types/list-mehod-options.ts +0 -32
- package/src/types/list-meta.ts +0 -16
- package/src/types/maybe.ts +0 -2
- package/src/validation/index.ts +0 -1
- package/src/validation/validation-pipe.ts +0 -14
- package/tsconfig.lib.json +0 -9
- package/tsdown.config.ts +0 -15
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { Inject } from '@nestjs/common';
|
|
2
|
-
import { getConfigToken, registerAs } from '@nestjs/config';
|
|
3
|
-
import { Type } from 'class-transformer';
|
|
4
|
-
import {
|
|
5
|
-
IsEnum, IsNumber, IsOptional, IsString,
|
|
6
|
-
} from 'class-validator';
|
|
7
|
-
|
|
8
|
-
import { AppEnv } from '../enums/app-env.enum.js';
|
|
9
|
-
import { AppMode } from '../enums/app-mode.enum.js';
|
|
10
|
-
import { validateEnv } from '../tools/env.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* NestJS injection token for app config
|
|
14
|
-
*/
|
|
15
|
-
export const APP_CONFIG_TOKEN = 'APP_CONFIG_TOKEN';
|
|
16
|
-
|
|
17
|
-
export const InjectAppConfig = () => Inject(getConfigToken(APP_CONFIG_TOKEN));
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Application config environment variables
|
|
21
|
-
*/
|
|
22
|
-
export class AppConfigEnvironmentVariables {
|
|
23
|
-
/**
|
|
24
|
-
* Application port
|
|
25
|
-
* @example
|
|
26
|
-
* ```yaml
|
|
27
|
-
* PORT: 3000
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
@Type(() => Number)
|
|
31
|
-
@IsNumber()
|
|
32
|
-
PORT = 3000;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Application host
|
|
36
|
-
* @example
|
|
37
|
-
* ```yaml
|
|
38
|
-
* APP_HOST: 'https://app-api.example.com'
|
|
39
|
-
* # or
|
|
40
|
-
* APP_HOST: 'http://localhost:3000'
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
@IsOptional()
|
|
44
|
-
@IsString()
|
|
45
|
-
APP_HOST!: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Application UI host
|
|
49
|
-
* @example
|
|
50
|
-
* ```yaml
|
|
51
|
-
* APP_UI_HOST: 'https://app.example.com'
|
|
52
|
-
* # or
|
|
53
|
-
* APP_UI_HOST: 'http://localhost:4200'
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
@IsOptional()
|
|
57
|
-
@IsString()
|
|
58
|
-
APP_UI_HOST!: string;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Application environment. Can be 'local', 'development', 'stage', 'production'
|
|
62
|
-
* @example
|
|
63
|
-
* ```yaml
|
|
64
|
-
* APP_ENV: 'local'
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
@IsEnum(AppEnv)
|
|
68
|
-
APP_ENV!: AppEnv;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Application service account id (user with type SA in users table)
|
|
72
|
-
* @example
|
|
73
|
-
* ```yaml
|
|
74
|
-
* APP_SERVICE_ACCOUNT_ID: 'hcu:xxxxxxxxxxx'
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
@IsOptional()
|
|
78
|
-
@IsString()
|
|
79
|
-
APP_SERVICE_ACCOUNT_ID?: string;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Application fallback language
|
|
83
|
-
* @example
|
|
84
|
-
* ```yaml
|
|
85
|
-
* FALLBACK_LANGUAGE: 'es'
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
@IsOptional()
|
|
89
|
-
@IsString()
|
|
90
|
-
FALLBACK_LANGUAGE = 'en';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface AppConfigType {
|
|
94
|
-
/**
|
|
95
|
-
* Application environment
|
|
96
|
-
* @example 'local', 'development', 'stage', 'production'
|
|
97
|
-
*/
|
|
98
|
-
env: AppEnv;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Application name
|
|
102
|
-
* @example 'Jetstream'
|
|
103
|
-
*/
|
|
104
|
-
name: string;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Application shortname
|
|
108
|
-
* @example 'js'
|
|
109
|
-
*/
|
|
110
|
-
shortname: string;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Application port
|
|
114
|
-
* @example 3000
|
|
115
|
-
*/
|
|
116
|
-
port: number;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Application mode
|
|
120
|
-
* @example 'standalone'
|
|
121
|
-
*/
|
|
122
|
-
mode: AppMode;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Application host
|
|
126
|
-
* @example 'https://app-api.example.com or http://localhost:3000'
|
|
127
|
-
*/
|
|
128
|
-
host?: string;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Application UI host
|
|
132
|
-
* @example 'https://app.example.com or http://localhost:8080'
|
|
133
|
-
*/
|
|
134
|
-
uiHost?: string;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Application fallback language
|
|
138
|
-
* @example 'en'
|
|
139
|
-
*/
|
|
140
|
-
fallbackLanguage: string;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Application service account id (user with type SA in users table)
|
|
144
|
-
* @example 'hcu:xxxxxxxxxxx'
|
|
145
|
-
*/
|
|
146
|
-
appServiceAccountId?: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export interface AppConfigOptions {
|
|
150
|
-
name: string;
|
|
151
|
-
shortname: string;
|
|
152
|
-
mode?: AppMode;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Create Main Application Config
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* // src/config/index.ts
|
|
160
|
-
*
|
|
161
|
-
* import { createAppConfig } from '#/dist/configs';
|
|
162
|
-
*
|
|
163
|
-
* export const appConfig = createAppConfig({
|
|
164
|
-
* name: 'Jetstream',
|
|
165
|
-
* shortname: 'js',
|
|
166
|
-
* });
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
export const createAppConfig = (opts: AppConfigOptions) => {
|
|
170
|
-
return registerAs(APP_CONFIG_TOKEN, (): AppConfigType => {
|
|
171
|
-
const env = validateEnv(AppConfigEnvironmentVariables);
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
env: env.APP_ENV,
|
|
175
|
-
name: opts.name,
|
|
176
|
-
shortname: opts.shortname,
|
|
177
|
-
port: env.PORT,
|
|
178
|
-
host: env.APP_HOST,
|
|
179
|
-
mode: opts.mode || AppMode.STANDALONE,
|
|
180
|
-
uiHost: env.APP_UI_HOST,
|
|
181
|
-
appServiceAccountId: env.APP_SERVICE_ACCOUNT_ID,
|
|
182
|
-
fallbackLanguage: env.FALLBACK_LANGUAGE,
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
};
|
package/src/configs/db.config.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { Inject } from '@nestjs/common';
|
|
2
|
-
import { getConfigToken, registerAs } from '@nestjs/config';
|
|
3
|
-
import { Type } from 'class-transformer';
|
|
4
|
-
import {
|
|
5
|
-
IsBoolean,
|
|
6
|
-
IsNumber, IsOptional, IsString,
|
|
7
|
-
} from 'class-validator';
|
|
8
|
-
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions.js';
|
|
9
|
-
|
|
10
|
-
import { SnakeNamingStrategy } from '#/db/snake-naming.strategy';
|
|
11
|
-
import { validateEnv } from '#/tools/env';
|
|
12
|
-
import fg from 'fast-glob';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* NestJS injection token for postgres db config
|
|
16
|
-
*/
|
|
17
|
-
export const DB_CONFIG_TOKEN = 'DB_CONFIG_TOKEN';
|
|
18
|
-
|
|
19
|
-
export const InjectDbConfig = () => Inject(getConfigToken(DB_CONFIG_TOKEN));
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Postgres db config environment variables
|
|
23
|
-
*/
|
|
24
|
-
class DbConfigEnvironmentVariables {
|
|
25
|
-
/**
|
|
26
|
-
* Postgres host
|
|
27
|
-
* @example
|
|
28
|
-
* ```yaml
|
|
29
|
-
* POSTGRES_HOST: 'localhost'
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
@IsString()
|
|
33
|
-
POSTGRES_HOST!: string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Postgres port
|
|
37
|
-
* @example
|
|
38
|
-
* ```yaml
|
|
39
|
-
* POSTGRES_PORT: 5432
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
@Type(() => Number)
|
|
43
|
-
@IsNumber()
|
|
44
|
-
POSTGRES_PORT!: number;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Postgres user
|
|
48
|
-
* @example
|
|
49
|
-
* ```yaml
|
|
50
|
-
* POSTGRES_USER: 'app'
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
@IsString()
|
|
54
|
-
POSTGRES_USER!: string;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Postgres password
|
|
58
|
-
* @example
|
|
59
|
-
* ```yaml
|
|
60
|
-
* POSTGRES_PASS: 'qwerty'
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
@IsString()
|
|
64
|
-
POSTGRES_PASS!: string;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Postgres database name
|
|
68
|
-
* @example
|
|
69
|
-
* ```yaml
|
|
70
|
-
* POSTGRES_DB: 'jetstream'
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
@IsString()
|
|
74
|
-
POSTGRES_DB!: string;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Enable postgres logging
|
|
78
|
-
* @example
|
|
79
|
-
* ```yaml
|
|
80
|
-
* POSTGRES_IS_LOGGING_ENABLED: "true"
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
@Type(() => Boolean)
|
|
84
|
-
@IsOptional()
|
|
85
|
-
@IsBoolean()
|
|
86
|
-
POSTGRES_IS_LOGGING_ENABLED?: boolean;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Postgres Database Config
|
|
91
|
-
*/
|
|
92
|
-
export const createDbConfig = (opts?: Partial<PostgresConnectionOptions>) => {
|
|
93
|
-
return registerAs(DB_CONFIG_TOKEN, (): PostgresConnectionOptions => {
|
|
94
|
-
const env = validateEnv(DbConfigEnvironmentVariables);
|
|
95
|
-
|
|
96
|
-
const baseEntities = [
|
|
97
|
-
'dist/**/*.entity.js',
|
|
98
|
-
'node_modules/@deep/nest-kit/dist/modules/**/*.entity.js',
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
const entities = [
|
|
102
|
-
...(opts?.entities as string[] ?? baseEntities),
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
type: 'postgres',
|
|
107
|
-
logging: env.POSTGRES_IS_LOGGING_ENABLED,
|
|
108
|
-
host: env.POSTGRES_HOST,
|
|
109
|
-
port: env.POSTGRES_PORT,
|
|
110
|
-
username: env.POSTGRES_USER,
|
|
111
|
-
password: env.POSTGRES_PASS,
|
|
112
|
-
database: env.POSTGRES_DB,
|
|
113
|
-
synchronize: false,
|
|
114
|
-
migrations: ['dist/migrations/*.js'],
|
|
115
|
-
subscribers: ['dist/**/*.entity-subscriber.js'],
|
|
116
|
-
migrationsRun: true,
|
|
117
|
-
namingStrategy: new SnakeNamingStrategy(),
|
|
118
|
-
...opts,
|
|
119
|
-
entities: fg.sync(entities),
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
};
|
package/src/configs/index.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Inject } from '@nestjs/common';
|
|
2
|
-
import { getConfigToken, registerAs } from '@nestjs/config';
|
|
3
|
-
import * as winston from 'winston';
|
|
4
|
-
|
|
5
|
-
import { nestLikeConsoleFormat } from '#/logger';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* NestJS injection token for Logger config
|
|
9
|
-
*/
|
|
10
|
-
export const LOGGER_CONFIG_TOKEN = 'LOGGER_CONFIG_TOKEN';
|
|
11
|
-
|
|
12
|
-
export const InjectLoggerConfig = () => Inject(getConfigToken(LOGGER_CONFIG_TOKEN));
|
|
13
|
-
|
|
14
|
-
export interface CreateLoggerConfigOptions {
|
|
15
|
-
appName: string;
|
|
16
|
-
useConsole?: boolean;
|
|
17
|
-
consoleLevel?: winston.LoggerOptions['level'];
|
|
18
|
-
transports?: winston.transport[];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Create NestJS Logger config
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* // src/config/index.ts
|
|
25
|
-
*
|
|
26
|
-
* import { createLoggerConfig } from '#/dist/configs';
|
|
27
|
-
*
|
|
28
|
-
* export const LoggerConfig = createLoggerConfig();
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const createLoggerConfig = (opts: CreateLoggerConfigOptions) => {
|
|
32
|
-
return registerAs(LOGGER_CONFIG_TOKEN, () => {
|
|
33
|
-
const format = [
|
|
34
|
-
winston.format.splat(),
|
|
35
|
-
winston.format.timestamp(),
|
|
36
|
-
nestLikeConsoleFormat(opts.appName),
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
const winstonOptions: winston.LoggerOptions = {
|
|
40
|
-
transports: [],
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
if (!Array.isArray(winstonOptions.transports)) {
|
|
44
|
-
return winstonOptions;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (opts.useConsole) {
|
|
48
|
-
winstonOptions.transports.push(
|
|
49
|
-
new winston.transports.Console({
|
|
50
|
-
level: opts.consoleLevel ?? 'debug',
|
|
51
|
-
format: winston.format.combine(...format),
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (opts.transports) {
|
|
57
|
-
winstonOptions.transports.push(...opts.transports);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return winstonOptions;
|
|
61
|
-
});
|
|
62
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { ActionScopes, ActionScopesArray } from '@pcg/auth';
|
|
2
|
-
import { CurrentUser } from './current-user.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* GraphQL base action context
|
|
6
|
-
* Used for mutations and queries
|
|
7
|
-
*/
|
|
8
|
-
export interface IBaseActionContext {
|
|
9
|
-
/**
|
|
10
|
-
* Request ID
|
|
11
|
-
* Used for logging to track request
|
|
12
|
-
*/
|
|
13
|
-
requestId: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Current user who executes action
|
|
17
|
-
*/
|
|
18
|
-
user: CurrentUser;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Check if current user from context has permission
|
|
22
|
-
* @param action - action string
|
|
23
|
-
* @param actionScopes - scopes where action was executed
|
|
24
|
-
*/
|
|
25
|
-
isGranted(action: string, actionScopes?: ActionScopes | ActionScopesArray): boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Check permission and throw AccessDenied error if user doesn't have permission
|
|
29
|
-
* @param action - action string
|
|
30
|
-
* @param scopes - scopes where action was executed
|
|
31
|
-
* @throws AccessDenied error if the user doesn't have the permission
|
|
32
|
-
*/
|
|
33
|
-
validateAccess(action: string, scopes?: ActionScopes | ActionScopesArray): void;
|
|
34
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { IUser } from '@pcg/auth';
|
|
2
|
-
|
|
3
|
-
export interface CurrentUser extends IUser {
|
|
4
|
-
/**
|
|
5
|
-
* User email address
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* 'john.doe@example.com'
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
email: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* User's first name
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* 'John'
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
firstName: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* User's last name
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* 'Doe'
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
lastName: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* User's full name
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* 'John Doe'
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
fullName: string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Indicates who logged in as this user
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* 'hcu:78thsjvx24hrx' // ID of user who impersonated this user
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
impersonatedByUserId?: string | null;
|
|
48
|
-
|
|
49
|
-
}
|
package/src/context/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ActionScopes, ActionScopesArray } from '@pcg/auth';
|
|
2
|
-
import { EntityManager } from 'typeorm';
|
|
3
|
-
import { CurrentUser } from './current-user.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Context object for base service methods.
|
|
7
|
-
*/
|
|
8
|
-
export interface BaseServiceMethodContext {
|
|
9
|
-
/**
|
|
10
|
-
* The current user making the request.
|
|
11
|
-
*/
|
|
12
|
-
user: CurrentUser;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* An optional request ID.
|
|
16
|
-
*/
|
|
17
|
-
requestId?: string;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Make the request silent, meaning no notifications and actions will be sent.
|
|
21
|
-
*/
|
|
22
|
-
isSilent?: boolean;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the user has permission to perform the specified action.
|
|
26
|
-
* @param action The action to check permission for.
|
|
27
|
-
* @param actionScopes Optional scopes to check permission against.
|
|
28
|
-
* @returns True if the user has permission, false otherwise.
|
|
29
|
-
*/
|
|
30
|
-
isGranted(action: string, actionScopes?: ActionScopes | ActionScopesArray): boolean;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Check permission and throw AccessDenied error if user doesn't have permission
|
|
34
|
-
* @param action - action string
|
|
35
|
-
* @param scopes - scopes where action was executed
|
|
36
|
-
* @throws AccessDenied error if the user doesn't have the permission
|
|
37
|
-
*/
|
|
38
|
-
validateAccess(action: string, scopes?: ActionScopes | ActionScopesArray): void;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Check permission and throw AccessDenied error if user doesn't have permission
|
|
42
|
-
* @param action - action string
|
|
43
|
-
* @param actionScopes - scopes where action was executed
|
|
44
|
-
* @throws AccessDenied error if the user doesn't have the permission
|
|
45
|
-
*/
|
|
46
|
-
transaction?: EntityManager;
|
|
47
|
-
}
|