@naturalcycles/backend-lib 9.34.2 → 9.36.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/dist/admin/base.admin.service.js +1 -1
- package/dist/cloudrun/cloudRun.d.ts +4 -2
- package/dist/cloudrun/cloudRun.js +12 -0
- package/dist/deploy/deploy.util.js +1 -1
- package/dist/validation/ajv/ajvValidateRequest.d.ts +5 -6
- package/dist/validation/ajv/ajvValidateRequest.js +1 -1
- package/package.json +1 -1
- package/src/admin/base.admin.service.ts +1 -1
- package/src/cloudrun/cloudRun.ts +16 -2
- package/src/deploy/deploy.util.ts +1 -1
- package/src/validation/ajv/ajvValidateRequest.ts +10 -7
|
@@ -40,7 +40,7 @@ export class BaseAdminService {
|
|
|
40
40
|
/**
|
|
41
41
|
* To be extended.
|
|
42
42
|
*/
|
|
43
|
-
//
|
|
43
|
+
// oxlint-disable-next-line max-params
|
|
44
44
|
async onPermissionCheck(req, email, reqPermissions, required, granted, meta = {}) {
|
|
45
45
|
req.log(`${dimGrey(email)} ${required ? 'required' : 'optional'} permissions check [${dimGrey(reqPermissions.join(', '))}]: ${granted ? green('GRANTED') : red('DENIED')}`, meta);
|
|
46
46
|
}
|
|
@@ -39,6 +39,7 @@ export interface CloudRunConfig {
|
|
|
39
39
|
* Example: httpGet.path='/',httpGet.port=8080,initialDelaySeconds=3,failureThreshold=50,timeoutSeconds=1,periodSeconds=2
|
|
40
40
|
*/
|
|
41
41
|
startupProbeConfigString: string;
|
|
42
|
+
livenessProbeConfigString?: string;
|
|
42
43
|
minInstances: NonNegativeInteger;
|
|
43
44
|
maxInstances: PositiveInteger;
|
|
44
45
|
/**
|
|
@@ -51,7 +52,7 @@ export interface CloudRunConfig {
|
|
|
51
52
|
*/
|
|
52
53
|
memoryPerInstance: string;
|
|
53
54
|
}
|
|
54
|
-
export interface
|
|
55
|
+
export interface CloudRunProbeConfig {
|
|
55
56
|
/**
|
|
56
57
|
* Example: '/'
|
|
57
58
|
*/
|
|
@@ -106,7 +107,8 @@ declare class CloudRunUtil {
|
|
|
106
107
|
* key-value pair is represented as `key1=value1,key2=value2,...`.
|
|
107
108
|
*/
|
|
108
109
|
stringifyObject(obj: AnyObject): string;
|
|
109
|
-
readonly defaultStartupProbeConfig:
|
|
110
|
+
readonly defaultStartupProbeConfig: CloudRunProbeConfig;
|
|
111
|
+
readonly defaultLivenessProbeConfig: CloudRunProbeConfig;
|
|
110
112
|
}
|
|
111
113
|
export declare const cloudRunUtil: CloudRunUtil;
|
|
112
114
|
export {};
|
|
@@ -21,5 +21,17 @@ class CloudRunUtil {
|
|
|
21
21
|
timeoutSeconds: 1,
|
|
22
22
|
periodSeconds: 2,
|
|
23
23
|
};
|
|
24
|
+
defaultLivenessProbeConfig = {
|
|
25
|
+
'httpGet.path': '/',
|
|
26
|
+
'httpGet.port': 8080,
|
|
27
|
+
// how long to wait before doing the first check, AFTER the startup probe has succeeded
|
|
28
|
+
initialDelaySeconds: 60,
|
|
29
|
+
// after how many failure it should kill/restart the container
|
|
30
|
+
failureThreshold: 5,
|
|
31
|
+
// how long to wait until liveness probe considers the endpoint unhealthy
|
|
32
|
+
timeoutSeconds: 30,
|
|
33
|
+
// check every periodSeconds
|
|
34
|
+
periodSeconds: 60,
|
|
35
|
+
};
|
|
24
36
|
}
|
|
25
37
|
export const cloudRunUtil = new CloudRunUtil();
|
|
@@ -110,7 +110,7 @@ export function createAppYaml(backendCfg, deployInfo, projectDir, appYamlPassEnv
|
|
|
110
110
|
const passEnv = appYamlPassEnv
|
|
111
111
|
.split(',')
|
|
112
112
|
.filter(Boolean)
|
|
113
|
-
//
|
|
113
|
+
// oxlint-disable-next-line unicorn/no-array-reduce
|
|
114
114
|
.reduce((map, key) => {
|
|
115
115
|
const v = process.env[key];
|
|
116
116
|
if (!v) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { AjvSchema, type AjvValidationError } from '@naturalcycles/nodejs-lib/ajv';
|
|
1
|
+
import { type AjvValidationError, type SchemaHandledByAjv } from '@naturalcycles/nodejs-lib/ajv';
|
|
3
2
|
import type { BackendRequest } from '../../server/server.model.js';
|
|
4
3
|
import { type ReqValidationOptions } from '../validateRequest.util.js';
|
|
5
4
|
declare class AjvValidateRequest {
|
|
6
|
-
body<T>(req: BackendRequest, schema:
|
|
7
|
-
query<T>(req: BackendRequest, schema:
|
|
8
|
-
params<T>(req: BackendRequest, schema:
|
|
5
|
+
body<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
|
|
6
|
+
query<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
|
|
7
|
+
params<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
|
|
9
8
|
/**
|
|
10
9
|
* Does NOT mutate `req.headers`,
|
|
11
10
|
* but returns validated/transformed headers.
|
|
@@ -14,7 +13,7 @@ declare class AjvValidateRequest {
|
|
|
14
13
|
* We want to non-mutate the `req.headers`, because we anticipate that
|
|
15
14
|
* there may be additional consumers for `req.headers` (e.g middlewares, etc).
|
|
16
15
|
*/
|
|
17
|
-
headers<T>(req: BackendRequest, schema:
|
|
16
|
+
headers<T>(req: BackendRequest, schema: SchemaHandledByAjv<T>, opt?: ReqValidationOptions<AjvValidationError>): T;
|
|
18
17
|
private validate;
|
|
19
18
|
}
|
|
20
19
|
export declare const ajvValidateRequest: AjvValidateRequest;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _deepCopy } from '@naturalcycles/js-lib/object';
|
|
2
|
-
import { AjvSchema } from '@naturalcycles/nodejs-lib/ajv';
|
|
2
|
+
import { AjvSchema, } from '@naturalcycles/nodejs-lib/ajv';
|
|
3
3
|
import { handleValidationError } from '../validateRequest.util.js';
|
|
4
4
|
class AjvValidateRequest {
|
|
5
5
|
body(req, schema, opt = {}) {
|
package/package.json
CHANGED
package/src/cloudrun/cloudRun.ts
CHANGED
|
@@ -66,6 +66,7 @@ export interface CloudRunConfig {
|
|
|
66
66
|
* Example: httpGet.path='/',httpGet.port=8080,initialDelaySeconds=3,failureThreshold=50,timeoutSeconds=1,periodSeconds=2
|
|
67
67
|
*/
|
|
68
68
|
startupProbeConfigString: string
|
|
69
|
+
livenessProbeConfigString?: string
|
|
69
70
|
minInstances: NonNegativeInteger
|
|
70
71
|
maxInstances: PositiveInteger
|
|
71
72
|
/**
|
|
@@ -79,7 +80,7 @@ export interface CloudRunConfig {
|
|
|
79
80
|
memoryPerInstance: string
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
export interface
|
|
83
|
+
export interface CloudRunProbeConfig {
|
|
83
84
|
/**
|
|
84
85
|
* Example: '/'
|
|
85
86
|
*/
|
|
@@ -144,7 +145,7 @@ class CloudRunUtil {
|
|
|
144
145
|
.join(',')
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
readonly defaultStartupProbeConfig:
|
|
148
|
+
readonly defaultStartupProbeConfig: CloudRunProbeConfig = {
|
|
148
149
|
'httpGet.path': '/',
|
|
149
150
|
'httpGet.port': 8080,
|
|
150
151
|
initialDelaySeconds: 3,
|
|
@@ -152,6 +153,19 @@ class CloudRunUtil {
|
|
|
152
153
|
timeoutSeconds: 1,
|
|
153
154
|
periodSeconds: 2,
|
|
154
155
|
}
|
|
156
|
+
|
|
157
|
+
readonly defaultLivenessProbeConfig: CloudRunProbeConfig = {
|
|
158
|
+
'httpGet.path': '/',
|
|
159
|
+
'httpGet.port': 8080,
|
|
160
|
+
// how long to wait before doing the first check, AFTER the startup probe has succeeded
|
|
161
|
+
initialDelaySeconds: 60,
|
|
162
|
+
// after how many failure it should kill/restart the container
|
|
163
|
+
failureThreshold: 5,
|
|
164
|
+
// how long to wait until liveness probe considers the endpoint unhealthy
|
|
165
|
+
timeoutSeconds: 30,
|
|
166
|
+
// check every periodSeconds
|
|
167
|
+
periodSeconds: 60,
|
|
168
|
+
}
|
|
155
169
|
}
|
|
156
170
|
|
|
157
171
|
export const cloudRunUtil = new CloudRunUtil()
|
|
@@ -161,7 +161,7 @@ export function createAppYaml(
|
|
|
161
161
|
const passEnv = appYamlPassEnv
|
|
162
162
|
.split(',')
|
|
163
163
|
.filter(Boolean)
|
|
164
|
-
//
|
|
164
|
+
// oxlint-disable-next-line unicorn/no-array-reduce
|
|
165
165
|
.reduce(
|
|
166
166
|
(map, key) => {
|
|
167
167
|
const v = process.env[key]
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { _deepCopy } from '@naturalcycles/js-lib/object'
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
AjvSchema,
|
|
4
|
+
type AjvValidationError,
|
|
5
|
+
type SchemaHandledByAjv,
|
|
6
|
+
} from '@naturalcycles/nodejs-lib/ajv'
|
|
4
7
|
import type { BackendRequest } from '../../server/server.model.js'
|
|
5
8
|
import { handleValidationError, type ReqValidationOptions } from '../validateRequest.util.js'
|
|
6
9
|
|
|
7
10
|
class AjvValidateRequest {
|
|
8
11
|
body<T>(
|
|
9
12
|
req: BackendRequest,
|
|
10
|
-
schema:
|
|
13
|
+
schema: SchemaHandledByAjv<T>,
|
|
11
14
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
12
15
|
): T {
|
|
13
16
|
return this.validate(req, 'body', schema, opt)
|
|
@@ -15,7 +18,7 @@ class AjvValidateRequest {
|
|
|
15
18
|
|
|
16
19
|
query<T>(
|
|
17
20
|
req: BackendRequest,
|
|
18
|
-
schema:
|
|
21
|
+
schema: SchemaHandledByAjv<T>,
|
|
19
22
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
20
23
|
): T {
|
|
21
24
|
return this.validate(req, 'query', schema, opt)
|
|
@@ -23,7 +26,7 @@ class AjvValidateRequest {
|
|
|
23
26
|
|
|
24
27
|
params<T>(
|
|
25
28
|
req: BackendRequest,
|
|
26
|
-
schema:
|
|
29
|
+
schema: SchemaHandledByAjv<T>,
|
|
27
30
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
28
31
|
): T {
|
|
29
32
|
return this.validate(req, 'params', schema, opt)
|
|
@@ -39,7 +42,7 @@ class AjvValidateRequest {
|
|
|
39
42
|
*/
|
|
40
43
|
headers<T>(
|
|
41
44
|
req: BackendRequest,
|
|
42
|
-
schema:
|
|
45
|
+
schema: SchemaHandledByAjv<T>,
|
|
43
46
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
44
47
|
): T {
|
|
45
48
|
const originalHeaders = _deepCopy(req.headers)
|
|
@@ -51,7 +54,7 @@ class AjvValidateRequest {
|
|
|
51
54
|
private validate<T>(
|
|
52
55
|
req: BackendRequest,
|
|
53
56
|
reqProperty: 'body' | 'params' | 'query' | 'headers',
|
|
54
|
-
schema:
|
|
57
|
+
schema: SchemaHandledByAjv<T>,
|
|
55
58
|
opt: ReqValidationOptions<AjvValidationError> = {},
|
|
56
59
|
): T {
|
|
57
60
|
const input: T = req[reqProperty] || {}
|