@pcg/core 1.0.0-alpha.1 → 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.
Files changed (98) hide show
  1. package/dist/index.d.ts +21 -1179
  2. package/dist/index.js +76 -1856
  3. package/dist/index.js.map +1 -1
  4. package/package.json +16 -4
  5. package/.turbo/turbo-build.log +0 -16
  6. package/CHANGELOG.md +0 -14
  7. package/src/abstracts/index.ts +0 -3
  8. package/src/abstracts/nestjs-resource-service.ts +0 -154
  9. package/src/abstracts/nestjs-service.ts +0 -25
  10. package/src/configs/app.config.ts +0 -185
  11. package/src/configs/db.config.ts +0 -122
  12. package/src/configs/index.ts +0 -4
  13. package/src/configs/logger.config.ts +0 -62
  14. package/src/context/action-context.ts +0 -34
  15. package/src/context/current-user.ts +0 -49
  16. package/src/context/index.ts +0 -5
  17. package/src/context/platform-method-context.ts +0 -5
  18. package/src/context/service-method-context.ts +0 -47
  19. package/src/db/snake-naming.strategy.ts +0 -277
  20. package/src/enums/app-env.enum.ts +0 -36
  21. package/src/enums/app-mode.enum.ts +0 -5
  22. package/src/enums/app-server.enum.ts +0 -39
  23. package/src/enums/index.ts +0 -4
  24. package/src/enums/worker-mode.enum.ts +0 -11
  25. package/src/errors/access-denied.error.ts +0 -18
  26. package/src/errors/bad-request.error.ts +0 -9
  27. package/src/errors/forbidden.error.ts +0 -9
  28. package/src/errors/index.ts +0 -8
  29. package/src/errors/input-validation.error.ts +0 -16
  30. package/src/errors/nest-error.filter.ts +0 -70
  31. package/src/errors/nest-error.ts +0 -63
  32. package/src/errors/not-found.error.ts +0 -9
  33. package/src/errors/unauthorized.error.ts +0 -9
  34. package/src/exceptions/http-exception-response.ts +0 -34
  35. package/src/exceptions/http-exceptions.filter.ts +0 -95
  36. package/src/index.ts +0 -32
  37. package/src/jwt/extractors.ts +0 -80
  38. package/src/jwt/types.ts +0 -209
  39. package/src/logger/classes/logger-factory.ts +0 -54
  40. package/src/logger/classes/logger.ts +0 -340
  41. package/src/logger/classes/nest-system-logger.ts +0 -63
  42. package/src/logger/classes/typeorm-logger.ts +0 -83
  43. package/src/logger/index.ts +0 -20
  44. package/src/logger/logger.constants.ts +0 -24
  45. package/src/logger/logger.interfaces.ts +0 -98
  46. package/src/logger/logger.module.ts +0 -45
  47. package/src/logger/logger.providers.ts +0 -140
  48. package/src/logger/winston.tools.ts +0 -241
  49. package/src/middlewares/app.middleware.ts +0 -26
  50. package/src/middlewares/index.ts +0 -1
  51. package/src/modules/hooks/base-hook.ts +0 -64
  52. package/src/modules/hooks/decorators/on-hook.decorator.ts +0 -19
  53. package/src/modules/hooks/hooks.module.ts +0 -10
  54. package/src/modules/hooks/hooks.service.ts +0 -28
  55. package/src/modules/hooks/index.ts +0 -11
  56. package/src/modules/id/id.module.ts +0 -26
  57. package/src/modules/id/id.service.ts +0 -57
  58. package/src/modules/id/index.ts +0 -2
  59. package/src/modules/postgres-pubsub/index.ts +0 -3
  60. package/src/modules/postgres-pubsub/postgres-pubsub.module.ts +0 -14
  61. package/src/modules/postgres-pubsub/postgres-pubsub.ts +0 -461
  62. package/src/pagination/constants.ts +0 -9
  63. package/src/pagination/cursor/cursor-pagination.exception.ts +0 -16
  64. package/src/pagination/cursor/cursor-pagination.helpers.ts +0 -145
  65. package/src/pagination/cursor/cursor-pagination.input.ts +0 -96
  66. package/src/pagination/cursor/cursor-pagination.types.ts +0 -127
  67. package/src/pagination/index.ts +0 -9
  68. package/src/pagination/offset/offset-pagination.exception.ts +0 -15
  69. package/src/pagination/offset/offset-pagination.helpers.ts +0 -122
  70. package/src/pagination/offset/offset-pagination.input.ts +0 -30
  71. package/src/pagination/offset/offset-pagination.types.ts +0 -82
  72. package/src/pagination/tools.ts +0 -53
  73. package/src/tools/compose.ts +0 -92
  74. package/src/tools/convert-to-bigint.ts +0 -27
  75. package/src/tools/create-list-meta.ts +0 -64
  76. package/src/tools/define-statuses.ts +0 -15
  77. package/src/tools/env.ts +0 -139
  78. package/src/tools/fetch-total-with-query.ts +0 -48
  79. package/src/tools/generate-entity-id.ts +0 -23
  80. package/src/tools/get-request-language.ts +0 -13
  81. package/src/tools/is-object.ts +0 -1
  82. package/src/tools/postgres/locale-to-pg-collate.ts +0 -21
  83. package/src/tools/remove-undefined-properties.ts +0 -20
  84. package/src/tools/request-id.ts +0 -25
  85. package/src/tools/stringify-opts.ts +0 -20
  86. package/src/tools/typeorm/add-filter.ts +0 -164
  87. package/src/tools/typeorm/ensure-inner-join.ts +0 -36
  88. package/src/tools/typeorm/ensure-left-join.ts +0 -36
  89. package/src/tools/typeorm/is-alias-already-busy.ts +0 -25
  90. package/src/tools/wait.ts +0 -26
  91. package/src/types/express-request.ts +0 -8
  92. package/src/types/list-mehod-options.ts +0 -32
  93. package/src/types/list-meta.ts +0 -16
  94. package/src/types/maybe.ts +0 -2
  95. package/src/validation/index.ts +0 -1
  96. package/src/validation/validation-pipe.ts +0 -14
  97. package/tsconfig.lib.json +0 -9
  98. 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
- };
@@ -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
- };
@@ -1,4 +0,0 @@
1
- export * from './app.config.js';
2
- export * from './db.config.js';
3
- export * from './logger.config.js';
4
-
@@ -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
- }
@@ -1,5 +0,0 @@
1
- export * from './action-context.js';
2
- export * from './current-user.js';
3
- export * from './platform-method-context.js';
4
- export * from './service-method-context.js';
5
-
@@ -1,5 +0,0 @@
1
- import { BaseServiceMethodContext } from './service-method-context.js';
2
-
3
- export interface BasePlatformMethodContext extends BaseServiceMethodContext {
4
- organizationId: string;
5
- }
@@ -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
- }