@axinom/mosaic-service-common 0.27.0-rc.9 → 0.27.0
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/package.json +4 -3
- package/src/common/config/basic-config-definitions.spec.ts +200 -0
- package/src/common/config/basic-config-definitions.ts +517 -0
- package/src/common/config/config-validation.spec.ts +79 -0
- package/src/common/config/config-validation.ts +108 -0
- package/src/common/config/env-var-extensions.spec.ts +74 -0
- package/src/common/config/env-var-extensions.ts +88 -0
- package/src/common/config/index.ts +3 -0
- package/src/common/errors/assert-error.spec.ts +133 -0
- package/src/common/errors/assert-error.ts +14 -0
- package/src/common/errors/default-pg-error-mapper.ts +81 -0
- package/src/common/errors/default-write-log-mapper.ts +36 -0
- package/src/common/errors/deprecated/api-error.ts +19 -0
- package/src/common/errors/deprecated/default-errors.ts +160 -0
- package/src/common/errors/deprecated/error-code.ts +50 -0
- package/src/common/errors/deprecated/error-data-mapper.ts +13 -0
- package/src/common/errors/deprecated/error-data.ts +19 -0
- package/src/common/errors/deprecated/general-error.ts +19 -0
- package/src/common/errors/deprecated/index.ts +7 -0
- package/src/common/errors/deprecated/startup-error.ts +19 -0
- package/src/common/errors/graphql-errors-handler.spec.ts +1311 -0
- package/src/common/errors/graphql-errors-handler.ts +194 -0
- package/src/common/errors/handle-global-errors.ts +32 -0
- package/src/common/errors/index.ts +11 -0
- package/src/common/errors/mosaic-error-mapping-factory.ts +45 -0
- package/src/common/errors/mosaic-errors.ts +53 -0
- package/src/common/errors/pg-error-code.ts +84 -0
- package/src/common/errors/trim-http-error.spec.ts +171 -0
- package/src/common/errors/trim-http-error.ts +43 -0
- package/src/common/errors/types/errors.ts +105 -0
- package/src/common/errors/types/index.ts +3 -0
- package/src/common/errors/types/models.ts +90 -0
- package/src/common/errors/types/unreachable-case-error.ts +10 -0
- package/src/common/helpers/array-helpers.spec.ts +170 -0
- package/src/common/helpers/array-helpers.ts +75 -0
- package/src/common/helpers/async-helpers.ts +5 -0
- package/src/common/helpers/base36.spec.ts +47 -0
- package/src/common/helpers/base36.ts +35 -0
- package/src/common/helpers/base58.spec.ts +42 -0
- package/src/common/helpers/base58.ts +35 -0
- package/src/common/helpers/generics-helpers.ts +24 -0
- package/src/common/helpers/index.ts +9 -0
- package/src/common/helpers/object-helpers.spec.ts +138 -0
- package/src/common/helpers/object-helpers.ts +91 -0
- package/src/common/helpers/random-helpers.ts +36 -0
- package/src/common/helpers/string-helpers.spec.ts +96 -0
- package/src/common/helpers/string-helpers.ts +114 -0
- package/src/common/helpers/test-helpers.spec.ts +239 -0
- package/src/common/helpers/test-helpers.ts +248 -0
- package/src/common/index.ts +5 -0
- package/src/common/logging/generate-log.ts +124 -0
- package/src/common/logging/index.ts +11 -0
- package/src/common/logging/log-level.ts +11 -0
- package/src/common/logging/log-message.ts +19 -0
- package/src/common/logging/log-retention.ts +17 -0
- package/src/common/logging/log.ts +16 -0
- package/src/common/logging/logger.spec.ts +1367 -0
- package/src/common/logging/logger.ts +330 -0
- package/src/common/logging/mask-middleware.spec.ts +574 -0
- package/src/common/logging/mask-middleware.ts +285 -0
- package/src/common/logging/setup-global-console-override.spec.ts +268 -0
- package/src/common/logging/setup-global-console-override.ts +84 -0
- package/src/common/logging/skip-mask-middleware.spec.ts +157 -0
- package/src/common/logging/skip-mask-middleware.ts +108 -0
- package/src/common/logging/tenant-environment-ids-log-middleware.spec.ts +50 -0
- package/src/common/logging/tenant-environment-ids-log-middleware.ts +21 -0
- package/src/common/logging/test-log-config.ts +22 -0
- package/src/common/types/dict.ts +6 -0
- package/src/common/types/index.ts +2 -0
- package/src/common/types/json-object.type.ts +6 -0
- package/src/index.ts +7 -0
- package/src/middleware/http-server-with-websockets-middleware.ts +55 -0
- package/src/middleware/index.ts +5 -0
- package/src/middleware/liveness-readiness-middleware.ts +171 -0
- package/src/middleware/maintenance-middleware.ts +149 -0
- package/src/middleware/monitoring-middleware.ts +101 -0
- package/src/middleware/shutdown-actions-middleware.ts +136 -0
- package/src/plugins/add-error-codes-enum-plugin.ts +101 -0
- package/src/plugins/annotate-types-with-permissions-plugin.spec.ts +158 -0
- package/src/plugins/annotate-types-with-permissions-plugin.ts +205 -0
- package/src/plugins/generic-bulk-plugin-factory.ts +313 -0
- package/src/plugins/graphiql-dark-mode-plugin-hook.ts +224 -0
- package/src/plugins/graphiql-management-mode-plugin-hook.ts +46 -0
- package/src/plugins/index.ts +9 -0
- package/src/plugins/omit-from-query-root-plugin.ts +69 -0
- package/src/plugins/operations-enum-generator-plugin-factory.ts +130 -0
- package/src/plugins/subscriptions-plugin-factory.ts +114 -0
- package/src/plugins/validation-directives-plugin.ts +141 -0
- package/src/postgraphile/index.ts +1 -0
- package/src/postgraphile/postgraphile-options-builder.spec.ts +749 -0
- package/src/postgraphile/postgraphile-options-builder.ts +520 -0
- package/src/publishing/index.ts +2 -0
- package/src/publishing/models.ts +86 -0
- package/src/publishing/utils.spec.ts +305 -0
- package/src/publishing/utils.ts +181 -0
- package/src/seed-data/index.ts +2 -0
- package/src/seed-data/populate-seed-data.ts +13 -0
- package/src/seed-data/seed-data-handler.interface.ts +6 -0
- package/src/webhooks/constants.ts +4 -0
- package/src/webhooks/generate-webhook-request.spec.ts +123 -0
- package/src/webhooks/generate-webhook-request.ts +60 -0
- package/src/webhooks/generate-webhook-response.spec.ts +124 -0
- package/src/webhooks/generate-webhook-response.ts +32 -0
- package/src/webhooks/generate-webhook-signature.ts +21 -0
- package/src/webhooks/handle-webhook-error-middleware.spec.ts +180 -0
- package/src/webhooks/handle-webhook-error-middleware.ts +34 -0
- package/src/webhooks/index.ts +9 -0
- package/src/webhooks/models.ts +165 -0
- package/src/webhooks/validate-webhook-request-middleware.ts +32 -0
- package/src/webhooks/validate-webhook-request.spec.ts +390 -0
- package/src/webhooks/validate-webhook-request.ts +73 -0
- package/src/webhooks/webhook-errors.ts +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-service-common",
|
|
3
|
-
"version": "0.27.0
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Common helpers and PostgreSQL-related functionality",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"axinom mosaic"
|
|
11
11
|
],
|
|
12
12
|
"files": [
|
|
13
|
-
"dist"
|
|
13
|
+
"dist",
|
|
14
|
+
"src"
|
|
14
15
|
],
|
|
15
16
|
"main": "dist/index.js",
|
|
16
17
|
"types": "dist/index.d.ts",
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"publishConfig": {
|
|
70
71
|
"access": "public"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "3f6c3692341670efa37fc109a382b88ef2a65209"
|
|
73
74
|
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import 'jest-extended';
|
|
2
|
+
import { pick } from '../helpers';
|
|
3
|
+
import { defaultMaskKeywordsArray } from '../logging';
|
|
4
|
+
import {
|
|
5
|
+
getBasicConfigDefinitions,
|
|
6
|
+
getBasicDbConfigDefinitions,
|
|
7
|
+
getBasicManagedConfigDefinitions,
|
|
8
|
+
} from './basic-config-definitions';
|
|
9
|
+
import { getValidatedConfig } from './config-validation';
|
|
10
|
+
|
|
11
|
+
describe('getBasicConfigDefinitions', () => {
|
|
12
|
+
it.each([
|
|
13
|
+
'SECRETS_HIDDEN',
|
|
14
|
+
'UNSAFE_DEBUG_UNSAFE',
|
|
15
|
+
'UNSAFE_SECRETS_NOT_HIDDEN_UNSAFE',
|
|
16
|
+
])(
|
|
17
|
+
'SECURE_LOGGING_MODE with %p value -> keywords defined',
|
|
18
|
+
(secureLoggingValue) => {
|
|
19
|
+
// Arrange
|
|
20
|
+
const env = {
|
|
21
|
+
NODE_ENV: 'production',
|
|
22
|
+
SERVICE_ID: 'test-service',
|
|
23
|
+
SECURE_LOGGING_MODE: secureLoggingValue,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Act
|
|
27
|
+
const config = getValidatedConfig(getBasicConfigDefinitions(env));
|
|
28
|
+
|
|
29
|
+
// Assert
|
|
30
|
+
expect(config).toEqual({
|
|
31
|
+
environment: 'production',
|
|
32
|
+
healthEndpointPort: 9000,
|
|
33
|
+
isDev: false,
|
|
34
|
+
isProd: true,
|
|
35
|
+
logLevel: 'INFO',
|
|
36
|
+
logMaskKeywords: defaultMaskKeywordsArray,
|
|
37
|
+
secureLoggingMode: secureLoggingValue,
|
|
38
|
+
serviceId: 'test-service',
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
it('SECURE_LOGGING_MODE not explicitly set and NODE_ENV is production -> keywords defined and SECRETS_HIDDEN mode used', () => {
|
|
44
|
+
// Arrange
|
|
45
|
+
const env = {
|
|
46
|
+
NODE_ENV: 'production',
|
|
47
|
+
SERVICE_ID: 'test-service',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Act
|
|
51
|
+
const config = getValidatedConfig(getBasicConfigDefinitions(env));
|
|
52
|
+
|
|
53
|
+
// Assert
|
|
54
|
+
expect(config).toEqual(
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
logMaskKeywords: defaultMaskKeywordsArray,
|
|
57
|
+
secureLoggingMode: 'SECRETS_HIDDEN',
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('SECURE_LOGGING_MODE not explicitly set and NODE_ENV is development -> UNSAFE_DEBUG_UNSAFE mode used', () => {
|
|
63
|
+
// Arrange
|
|
64
|
+
const env = {
|
|
65
|
+
NODE_ENV: 'development',
|
|
66
|
+
SERVICE_ID: 'test-service',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Act
|
|
70
|
+
const config = getValidatedConfig(getBasicConfigDefinitions(env));
|
|
71
|
+
|
|
72
|
+
// Assert
|
|
73
|
+
expect(config).toEqual(
|
|
74
|
+
expect.objectContaining({
|
|
75
|
+
secureLoggingMode: 'UNSAFE_DEBUG_UNSAFE',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('SECURE_LOGGING_MODE with invalid value -> error is thrown', () => {
|
|
81
|
+
// Arrange
|
|
82
|
+
const env = {
|
|
83
|
+
NODE_ENV: 'production',
|
|
84
|
+
SERVICE_ID: 'test-service',
|
|
85
|
+
SECURE_LOGGING_MODE: 'Show Everything!',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Assert
|
|
89
|
+
expect(() => {
|
|
90
|
+
getValidatedConfig(getBasicConfigDefinitions(env));
|
|
91
|
+
}).toThrow(
|
|
92
|
+
'Environment variable validation failed:\n- env-var: "SECURE_LOGGING_MODE" should be one of [SECRETS_HIDDEN, UNSAFE_SECRETS_NOT_HIDDEN_UNSAFE, UNSAFE_DEBUG_UNSAFE]',
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('getBasicDbConfigDefinitions', () => {
|
|
98
|
+
it.each([
|
|
99
|
+
'a',
|
|
100
|
+
'_',
|
|
101
|
+
'_a',
|
|
102
|
+
'_a_',
|
|
103
|
+
'test_custom_service_owner',
|
|
104
|
+
'value_with_valid_characters_with_length_exactly_63_characters_',
|
|
105
|
+
'media_128fcad0cc2fa2cabf63cc19_login',
|
|
106
|
+
])('DATABASE_LOGIN with valid values -> config is valid', (value) => {
|
|
107
|
+
// Arrange
|
|
108
|
+
const env = {
|
|
109
|
+
DATABASE_LOGIN: value,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Act
|
|
113
|
+
const validatedConfig = getValidatedConfig(
|
|
114
|
+
pick(getBasicDbConfigDefinitions(env), 'dbLogin'),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
// Assert
|
|
118
|
+
expect(validatedConfig).toEqual({ dbLogin: value });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it.each([
|
|
122
|
+
'stringWithCapitalLetters',
|
|
123
|
+
'string-with-dashes',
|
|
124
|
+
'5tarts_with_number',
|
|
125
|
+
'value_with_all_valid_characters_but_with_length_longer_than_63_characters',
|
|
126
|
+
])('DATABASE_LOGIN with invalid value -> error is thrown', (value) => {
|
|
127
|
+
// Arrange
|
|
128
|
+
const env = {
|
|
129
|
+
DATABASE_LOGIN: value,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Assert
|
|
133
|
+
expect(() => {
|
|
134
|
+
getValidatedConfig(pick(getBasicDbConfigDefinitions(env), 'dbLogin'));
|
|
135
|
+
}).toThrow(
|
|
136
|
+
'Environment variable validation failed:\n- env-var: "DATABASE_LOGIN" must only contain lowercase letters, numbers, or underscores. It must not be longer than 63 characters and must not start with a number.',
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('All db identifier config keys with valid values -> config is valid', () => {
|
|
141
|
+
// Arrange
|
|
142
|
+
const env = {
|
|
143
|
+
POSTGRESQL_ROOT: 'a',
|
|
144
|
+
DATABASE_OWNER: '_',
|
|
145
|
+
DATABASE_LOGIN: 'test_custom_service_owner',
|
|
146
|
+
DATABASE_GQL_ROLE:
|
|
147
|
+
'value_with_valid_characters_with_length_exactly_63_characters_',
|
|
148
|
+
DATABASE_ENV_OWNER: 'media_128fcad0cc2fa2cabf63cc19_login',
|
|
149
|
+
};
|
|
150
|
+
const config = {
|
|
151
|
+
...getBasicManagedConfigDefinitions(env),
|
|
152
|
+
...getBasicDbConfigDefinitions(env),
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Act
|
|
156
|
+
const validatedConfig = getValidatedConfig(
|
|
157
|
+
pick(config, 'pgRoot', 'dbOwner', 'dbLogin', 'dbGqlRole', 'dbEnvOwner'),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Assert
|
|
161
|
+
expect(validatedConfig).toEqual({
|
|
162
|
+
dbEnvOwner: 'media_128fcad0cc2fa2cabf63cc19_login',
|
|
163
|
+
dbGqlRole:
|
|
164
|
+
'value_with_valid_characters_with_length_exactly_63_characters_',
|
|
165
|
+
dbLogin: 'test_custom_service_owner',
|
|
166
|
+
dbOwner: '_',
|
|
167
|
+
pgRoot: 'a',
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('All db identifier config keys with invalid values -> error is thrown', () => {
|
|
172
|
+
// Arrange
|
|
173
|
+
const env = {
|
|
174
|
+
POSTGRESQL_ROOT: 'stringWithCapitalLetters',
|
|
175
|
+
DATABASE_OWNER: 'string-with-dashes',
|
|
176
|
+
DATABASE_LOGIN: '12345',
|
|
177
|
+
DATABASE_GQL_ROLE: '5tarts_with_number',
|
|
178
|
+
DATABASE_ENV_OWNER:
|
|
179
|
+
'value_with_all_valid_characters_but_with_length_longer_than_63_characters',
|
|
180
|
+
};
|
|
181
|
+
const config = {
|
|
182
|
+
...getBasicManagedConfigDefinitions(env),
|
|
183
|
+
...getBasicDbConfigDefinitions(env),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Assert
|
|
187
|
+
expect(() => {
|
|
188
|
+
getValidatedConfig(
|
|
189
|
+
pick(config, 'pgRoot', 'dbOwner', 'dbLogin', 'dbGqlRole', 'dbEnvOwner'),
|
|
190
|
+
);
|
|
191
|
+
}).toThrow(
|
|
192
|
+
`Environment variable validation failed:
|
|
193
|
+
- env-var: "POSTGRESQL_ROOT" must only contain lowercase letters, numbers, or underscores. It must not be longer than 63 characters and must not start with a number.
|
|
194
|
+
- env-var: "DATABASE_OWNER" must only contain lowercase letters, numbers, or underscores. It must not be longer than 63 characters and must not start with a number.
|
|
195
|
+
- env-var: "DATABASE_LOGIN" must only contain lowercase letters, numbers, or underscores. It must not be longer than 63 characters and must not start with a number.
|
|
196
|
+
- env-var: "DATABASE_GQL_ROLE" must only contain lowercase letters, numbers, or underscores. It must not be longer than 63 characters and must not start with a number.
|
|
197
|
+
- env-var: "DATABASE_ENV_OWNER" must only contain lowercase letters, numbers, or underscores. It must not be longer than 63 characters and must not start with a number.`,
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
});
|