@naturalcycles/backend-lib 9.28.0 → 9.30.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.
@@ -0,0 +1,103 @@
1
+ import type { NonNegativeInteger, NumberOfMilliseconds, NumberOfSeconds, PositiveInteger, UnixTimestamp } from '@naturalcycles/js-lib/types';
2
+ export interface CloudRunDeployInfo {
3
+ gcpProject: string;
4
+ /**
5
+ * Name of the Cloud Run service.
6
+ */
7
+ cloudRunService: string;
8
+ cloudRunServiceBase: string;
9
+ runtimeServiceAccount: string;
10
+ /**
11
+ * GCP region where the Cloud Run service is deployed. Example: 'europe-west1'
12
+ */
13
+ cloudRunRegion: string;
14
+ sqlInstance: string;
15
+ vpcConnector: string;
16
+ /**
17
+ * Service URL that is used to access the service externally (through load balancer)
18
+ * todo: overlaps with env.K_EXTERNAL_URL
19
+ */
20
+ externalUrl: string;
21
+ serviceUrl: string;
22
+ buildVersion: string;
23
+ /**
24
+ * Unix timestamp of the build/deployment time.
25
+ */
26
+ tsUnix: UnixTimestamp;
27
+ targetDockerImageId: string;
28
+ dockerImageTag: string;
29
+ /**
30
+ * Short SHA of the commit used for this deployment.
31
+ */
32
+ gitRev: string;
33
+ gitBranch: string;
34
+ /**
35
+ * Example: 'APP_ENV=prod,BUILD_VERSION=abcd,a=b'
36
+ */
37
+ envString: string;
38
+ /**
39
+ * Example: httpGet.path='/',httpGet.port=8080,initialDelaySeconds=3,failureThreshold=50,timeoutSeconds=1,periodSeconds=2
40
+ */
41
+ startupProbeConfigString: string;
42
+ minInstances: NonNegativeInteger;
43
+ maxInstances: PositiveInteger;
44
+ /**
45
+ * CloudRun concurrency setting.
46
+ * Example: 80
47
+ */
48
+ concurrency: PositiveInteger;
49
+ /**
50
+ * Example: '512Mi'
51
+ */
52
+ memoryPerInstance: string;
53
+ }
54
+ export interface CloudRunStartupProbeConfig {
55
+ /**
56
+ * Example: '/'
57
+ */
58
+ 'httpGet.path': string;
59
+ 'httpGet.port': PositiveInteger;
60
+ initialDelaySeconds: NumberOfSeconds;
61
+ failureThreshold: PositiveInteger;
62
+ timeoutSeconds: NumberOfSeconds;
63
+ periodSeconds: NumberOfSeconds;
64
+ }
65
+ /**
66
+ * Experimental, subject to change.
67
+ */
68
+ export declare const defaultStartupProbeConfig: CloudRunStartupProbeConfig;
69
+ export interface CloudRunEnv {
70
+ APP_ENV: string;
71
+ /**
72
+ * Example: '--max-old-space-size=864'
73
+ */
74
+ NODE_OPTIONS: string;
75
+ /**
76
+ * Example: '2025-09-01T15:23:20.769Z'
77
+ * The result of running `new Date().toISOString()`
78
+ */
79
+ DEPLOY_BUILD_TIME: string;
80
+ /**
81
+ * Example: 'abcd'
82
+ * Should match the name of the GCP project.
83
+ */
84
+ GOOGLE_CLOUD_PROJECT: string;
85
+ /**
86
+ * Anything (a string) that would identify the build.
87
+ */
88
+ BUILD_VERSION: string;
89
+ /**
90
+ * External url of the deployed service.
91
+ */
92
+ K_EXTERNAL_URL?: string;
93
+ OTEL_SERVICE_NAME?: string;
94
+ OTEL_METRICS_EXPORTER?: 'console' | 'otlp' | string;
95
+ OTEL_METRIC_EXPORT_INTERVAL?: NumberOfMilliseconds;
96
+ OTEL_METRIC_EXPORT_TIMEOUT?: NumberOfMilliseconds;
97
+ OTEL_EXPORTER_OTLP_PROTOCOL?: 'http/protobuf' | string;
98
+ /**
99
+ * Example: 'http://localhost:4317'
100
+ */
101
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string;
102
+ OTEL_LOG_LEVEL?: 'INFO' | 'DEBUG';
103
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Experimental, subject to change.
3
+ */
4
+ export const defaultStartupProbeConfig = {
5
+ 'httpGet.path': '/',
6
+ 'httpGet.port': 8080,
7
+ initialDelaySeconds: 3,
8
+ failureThreshold: 50,
9
+ timeoutSeconds: 1,
10
+ periodSeconds: 2,
11
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.28.0",
4
+ "version": "9.30.0",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -29,13 +29,13 @@
29
29
  "@sentry/node": "^10",
30
30
  "@types/ejs": "^3",
31
31
  "fastify": "^5",
32
- "@naturalcycles/dev-lib": "19.27.0"
32
+ "@naturalcycles/dev-lib": "18.4.2"
33
33
  },
34
34
  "exports": {
35
35
  ".": "./dist/index.js",
36
- "./cfg/tsconfig.json": "./cfg/tsconfig.json",
37
36
  "./admin": "./dist/admin/index.js",
38
37
  "./admin/*.js": "./dist/admin/*.js",
38
+ "./cloudrun": "./dist/cloudrun/cloudRun.util.js",
39
39
  "./db": "./dist/db/index.js",
40
40
  "./deploy": "./dist/deploy/index.js",
41
41
  "./deploy/*.js": "./dist/deploy/*.js",
@@ -0,0 +1,140 @@
1
+ import type {
2
+ NonNegativeInteger,
3
+ NumberOfMilliseconds,
4
+ NumberOfSeconds,
5
+ PositiveInteger,
6
+ UnixTimestamp,
7
+ } from '@naturalcycles/js-lib/types'
8
+
9
+ export interface CloudRunDeployInfo {
10
+ //
11
+ // GCP settings
12
+ //
13
+ gcpProject: string
14
+ /**
15
+ * Name of the Cloud Run service.
16
+ */
17
+ cloudRunService: string
18
+ cloudRunServiceBase: string // todo: review
19
+ runtimeServiceAccount: string
20
+ /**
21
+ * GCP region where the Cloud Run service is deployed. Example: 'europe-west1'
22
+ */
23
+ cloudRunRegion: string
24
+ sqlInstance: string
25
+ vpcConnector: string
26
+ //
27
+ // Urls
28
+ //
29
+ /**
30
+ * Service URL that is used to access the service externally (through load balancer)
31
+ * todo: overlaps with env.K_EXTERNAL_URL
32
+ */
33
+ externalUrl: string
34
+ serviceUrl: string
35
+ //
36
+ // Versioning
37
+ //
38
+ buildVersion: string // todo: overlaps with env.BUILD_VERSION
39
+ /**
40
+ * Unix timestamp of the build/deployment time.
41
+ */
42
+ tsUnix: UnixTimestamp
43
+ //
44
+ // Docker
45
+ //
46
+ targetDockerImageId: string
47
+ dockerImageTag: string
48
+ //
49
+ // Git
50
+ //
51
+ /**
52
+ * Short SHA of the commit used for this deployment.
53
+ */
54
+ gitRev: string
55
+ gitBranch: string
56
+ //
57
+ // Cloud Run environment settings
58
+ //
59
+ /**
60
+ * Example: 'APP_ENV=prod,BUILD_VERSION=abcd,a=b'
61
+ */
62
+ envString: string
63
+ /**
64
+ * Example: httpGet.path='/',httpGet.port=8080,initialDelaySeconds=3,failureThreshold=50,timeoutSeconds=1,periodSeconds=2
65
+ */
66
+ startupProbeConfigString: string
67
+ minInstances: NonNegativeInteger
68
+ maxInstances: PositiveInteger
69
+ /**
70
+ * CloudRun concurrency setting.
71
+ * Example: 80
72
+ */
73
+ concurrency: PositiveInteger
74
+ /**
75
+ * Example: '512Mi'
76
+ */
77
+ memoryPerInstance: string
78
+ }
79
+
80
+ export interface CloudRunStartupProbeConfig {
81
+ /**
82
+ * Example: '/'
83
+ */
84
+ 'httpGet.path': string
85
+ 'httpGet.port': PositiveInteger
86
+ initialDelaySeconds: NumberOfSeconds
87
+ failureThreshold: PositiveInteger
88
+ timeoutSeconds: NumberOfSeconds
89
+ periodSeconds: NumberOfSeconds
90
+ }
91
+
92
+ /**
93
+ * Experimental, subject to change.
94
+ */
95
+ export const defaultStartupProbeConfig: CloudRunStartupProbeConfig = {
96
+ 'httpGet.path': '/',
97
+ 'httpGet.port': 8080,
98
+ initialDelaySeconds: 3,
99
+ failureThreshold: 50,
100
+ timeoutSeconds: 1,
101
+ periodSeconds: 2,
102
+ }
103
+
104
+ export interface CloudRunEnv {
105
+ APP_ENV: string
106
+ /**
107
+ * Example: '--max-old-space-size=864'
108
+ */
109
+ NODE_OPTIONS: string
110
+ /**
111
+ * Example: '2025-09-01T15:23:20.769Z'
112
+ * The result of running `new Date().toISOString()`
113
+ */
114
+ DEPLOY_BUILD_TIME: string
115
+ /**
116
+ * Example: 'abcd'
117
+ * Should match the name of the GCP project.
118
+ */
119
+ GOOGLE_CLOUD_PROJECT: string
120
+ /**
121
+ * Anything (a string) that would identify the build.
122
+ */
123
+ BUILD_VERSION: string
124
+ /**
125
+ * External url of the deployed service.
126
+ */
127
+ K_EXTERNAL_URL?: string
128
+ // UV_THREADPOOL_SIZE?: number
129
+
130
+ OTEL_SERVICE_NAME?: string
131
+ OTEL_METRICS_EXPORTER?: 'console' | 'otlp' | string
132
+ OTEL_METRIC_EXPORT_INTERVAL?: NumberOfMilliseconds
133
+ OTEL_METRIC_EXPORT_TIMEOUT?: NumberOfMilliseconds
134
+ OTEL_EXPORTER_OTLP_PROTOCOL?: 'http/protobuf' | string
135
+ /**
136
+ * Example: 'http://localhost:4317'
137
+ */
138
+ OTEL_EXPORTER_OTLP_ENDPOINT?: string
139
+ OTEL_LOG_LEVEL?: 'INFO' | 'DEBUG'
140
+ }
package/cfg/tsconfig.json DELETED
@@ -1,71 +0,0 @@
1
- //
2
- // @naturalcycles/backend-lib/cfg/tsconfig.json
3
- //
4
- // Shared tsconfig for Backend services
5
- //
6
- {
7
- "compilerOptions": {
8
- // Target/module
9
- "target": "es2023",
10
- "lib": ["esnext"], // add "dom" if needed
11
- // module `nodenext` is a modern mode that auto-detects cjs/esm
12
- // it also defaults `esModuleInterop` and `allowSyntheticDefaultImports` to true
13
- "module": "nodenext",
14
- "moduleResolution": "nodenext",
15
- "moduleDetection": "force",
16
- // specifying these explicitly for better IDE compatibility (but they're on by default with module=nodenext)
17
- "esModuleInterop": true,
18
- "allowSyntheticDefaultImports": true,
19
- "verbatimModuleSyntax": true,
20
- // Faster compilation in general
21
- // Support for external compilers (e.g esbuild)
22
- // Speedup in Jest by using "isolatedModules" in 'ts-jest' config
23
- "isolatedModules": true,
24
-
25
- // Emit
26
- "sourceMap": false,
27
- "declaration": false,
28
- // Otherwise since es2022 it defaults to true
29
- // and starts to produce different/unexpected behavior
30
- // https://angular.schule/blog/2022-11-use-define-for-class-fields
31
- "useDefineForClassFields": true,
32
- "importHelpers": true,
33
-
34
- // Strictness
35
- "strict": true,
36
- "noFallthroughCasesInSwitch": true,
37
- "forceConsistentCasingInFileNames": true,
38
- "resolveJsonModule": true,
39
- "suppressImplicitAnyIndexErrors": false,
40
- "noImplicitOverride": true,
41
- "noUncheckedIndexedAccess": true,
42
- "noUncheckedSideEffectImports": true,
43
- "noPropertyAccessFromIndexSignature": true,
44
-
45
- // Enabled should be faster, but will catch less errors
46
- // "skipLibCheck": true,
47
-
48
- // Disabled because of https://github.com/Microsoft/TypeScript/issues/29172
49
- // Need to be specified in the project tsconfig
50
- // "outDir": "dist",
51
- // "rootDir": "./src",
52
- // "baseUrl": "./",
53
- // "paths": {
54
- // "@src/*": ["src/*"]
55
- // },
56
- // "typeRoots": [
57
- // "node_modules/@types",
58
- // "src/@types"
59
- // ],
60
-
61
- // Other
62
- "incremental": true,
63
- "tsBuildInfoFile": "${configDir}/node_modules/.cache/src.tsbuildinfo",
64
- "pretty": true,
65
- "newLine": "lf",
66
- "experimentalDecorators": true
67
- }
68
- // Need to be specified in the project tsconfig
69
- // "include": ["src"],
70
- // "exclude": ["**/__exclude"]
71
- }