@naturalcycles/backend-lib 4.18.8 → 4.19.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/cfg/tsconfig.json +16 -12
- package/dist/admin/adminMiddleware.js +5 -4
- package/dist/admin/base.admin.service.d.ts +1 -1
- package/dist/admin/firebase.shared.service.d.ts +1 -1
- package/dist/bin/deploy-gae.js +3 -2
- package/dist/bin/deploy-health-check.js +3 -2
- package/dist/bin/deploy-prepare.js +3 -2
- package/dist/deploy/backend.cfg.util.js +3 -2
- package/dist/deploy/deploy.util.js +9 -8
- package/dist/paths.cnst.js +3 -2
- package/dist/server/deployInfo.util.js +3 -2
- package/dist/server/getDefaultRouter.js +2 -1
- package/package.json +1 -1
- package/src/admin/adminMiddleware.ts +2 -2
- package/src/admin/base.admin.service.ts +1 -1
- package/src/admin/firebase.shared.service.ts +1 -1
- package/src/bin/deploy-gae.ts +1 -1
- package/src/bin/deploy-health-check.ts +1 -1
- package/src/bin/deploy-prepare.ts +1 -1
- package/src/deploy/backend.cfg.util.ts +1 -1
- package/src/deploy/deploy.util.ts +2 -2
- package/src/paths.cnst.ts +1 -1
- package/src/server/deployInfo.util.ts +1 -1
package/cfg/tsconfig.json
CHANGED
|
@@ -8,13 +8,27 @@
|
|
|
8
8
|
// Target/module
|
|
9
9
|
"target": "es2022",
|
|
10
10
|
"lib": ["esnext"], // add "dom" if needed
|
|
11
|
-
|
|
12
|
-
|
|
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",
|
|
13
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
|
+
// Faster compilation in general
|
|
20
|
+
// Support for external compilers (e.g esbuild)
|
|
21
|
+
// Speedup in Jest by using "isolatedModules" in 'ts-jest' config
|
|
22
|
+
"isolatedModules": true,
|
|
14
23
|
|
|
15
24
|
// Emit
|
|
16
25
|
"sourceMap": false,
|
|
17
26
|
"declaration": false,
|
|
27
|
+
// Otherwise since es2022 it defaults to true
|
|
28
|
+
// and starts to produce different/unexpected behavior
|
|
29
|
+
// https://angular.schule/blog/2022-11-use-define-for-class-fields
|
|
30
|
+
"useDefineForClassFields": false,
|
|
31
|
+
"importHelpers": true,
|
|
18
32
|
|
|
19
33
|
// Strictness
|
|
20
34
|
"strict": true,
|
|
@@ -25,19 +39,10 @@
|
|
|
25
39
|
"noImplicitOverride": true,
|
|
26
40
|
"noUncheckedIndexedAccess": true,
|
|
27
41
|
"noPropertyAccessFromIndexSignature": true,
|
|
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": false,
|
|
32
42
|
|
|
33
43
|
// Enabled should be faster, but will catch less errors
|
|
34
44
|
// "skipLibCheck": true,
|
|
35
45
|
|
|
36
|
-
// Faster compilation in general
|
|
37
|
-
// Support for external compilers (e.g esbuild)
|
|
38
|
-
// Speedup in Jest by using "isolatedModules" in 'ts-jest' config
|
|
39
|
-
"isolatedModules": true,
|
|
40
|
-
|
|
41
46
|
// Disabled because of https://github.com/Microsoft/TypeScript/issues/29172
|
|
42
47
|
// Need to be specified in the project tsconfig
|
|
43
48
|
// "outDir": "dist",
|
|
@@ -54,7 +59,6 @@
|
|
|
54
59
|
// Other
|
|
55
60
|
"pretty": true,
|
|
56
61
|
"newLine": "lf",
|
|
57
|
-
"importHelpers": true,
|
|
58
62
|
"experimentalDecorators": true
|
|
59
63
|
}
|
|
60
64
|
// Need to be specified in the project tsconfig
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLoginHtmlRedirect = exports.loginHtml = exports.requireAdminPermissions = exports.createAdminMiddleware = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
-
const
|
|
7
|
+
const ejs_1 = tslib_1.__importDefault(require("ejs"));
|
|
7
8
|
function createAdminMiddleware(adminService, cfgDefaults = {}) {
|
|
8
9
|
return (reqPermissions, cfg) => requireAdminPermissions(adminService, reqPermissions, {
|
|
9
10
|
...cfgDefaults,
|
|
@@ -52,8 +53,8 @@ function loginHtml(firebaseServiceCfg) {
|
|
|
52
53
|
exports.loginHtml = loginHtml;
|
|
53
54
|
const getLoginHtml = (0, js_lib_1._memoFn)((cfg) => {
|
|
54
55
|
console.log(`reading login.html`);
|
|
55
|
-
const tmpl =
|
|
56
|
-
return
|
|
56
|
+
const tmpl = node_fs_1.default.readFileSync(`${__dirname}/login.html`, 'utf8');
|
|
57
|
+
return ejs_1.default.render(tmpl, cfg);
|
|
57
58
|
});
|
|
58
59
|
function getLoginHtmlRedirect(href) {
|
|
59
60
|
return `
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AppOptions, ServiceAccount } from 'firebase-admin';
|
|
2
|
-
import type
|
|
2
|
+
import type FirebaseAdmin from 'firebase-admin';
|
|
3
3
|
export interface FirebaseSharedServiceCfg {
|
|
4
4
|
/**
|
|
5
5
|
* If undefined - will try to use credential.applicationDefault()
|
package/dist/bin/deploy-gae.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
5
|
-
const
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
6
7
|
const deployGae_1 = require("../deploy/deployGae");
|
|
7
8
|
const deployHealthCheck_1 = require("../deploy/deployHealthCheck");
|
|
8
9
|
const deployPrepare_1 = require("../deploy/deployPrepare");
|
|
9
10
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
10
|
-
const opt =
|
|
11
|
+
const opt = yargs_1.default.options({
|
|
11
12
|
...deployPrepare_1.deployPrepareYargsOptions,
|
|
12
13
|
...deployHealthCheck_1.deployHealthCheckYargsOptions,
|
|
13
14
|
}).argv;
|
|
@@ -9,11 +9,12 @@ yarn deploy-health-check --url https://service-dot-yourproject.appspot.com
|
|
|
9
9
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
12
13
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
13
|
-
const
|
|
14
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
14
15
|
const deployHealthCheck_1 = require("../deploy/deployHealthCheck");
|
|
15
16
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
16
|
-
const { url, ...opt } =
|
|
17
|
+
const { url, ...opt } = yargs_1.default.options({
|
|
17
18
|
...deployHealthCheck_1.deployHealthCheckYargsOptions,
|
|
18
19
|
url: {
|
|
19
20
|
type: 'string',
|
|
@@ -6,11 +6,12 @@ yarn deploy-prepare
|
|
|
6
6
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
9
10
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
10
|
-
const
|
|
11
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
11
12
|
const deployPrepare_1 = require("../deploy/deployPrepare");
|
|
12
13
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
13
|
-
const opt =
|
|
14
|
+
const opt = yargs_1.default.options(deployPrepare_1.deployPrepareYargsOptions).argv;
|
|
14
15
|
await (0, deployPrepare_1.deployPrepare)(opt);
|
|
15
16
|
});
|
|
16
17
|
// deploy strategy
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBackendCfg = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
5
|
-
const
|
|
6
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
6
7
|
const paths_cnst_1 = require("../paths.cnst");
|
|
7
8
|
const backendCfgSchema = nodejs_lib_1.AjvSchema.readJsonSync(`${paths_cnst_1.resourcesDir}/backendCfg.schema.json`, {
|
|
8
9
|
objectName: 'backend.cfg.yaml',
|
|
@@ -12,7 +13,7 @@ function getBackendCfg(projectDir = '.') {
|
|
|
12
13
|
(0, nodejs_lib_1.requireFileToExist)(backendCfgYamlPath);
|
|
13
14
|
const backendCfg = {
|
|
14
15
|
serviceWithBranchName: true,
|
|
15
|
-
...
|
|
16
|
+
...js_yaml_1.default.load((0, nodejs_lib_1._readFileSync)(backendCfgYamlPath)),
|
|
16
17
|
};
|
|
17
18
|
backendCfgSchema.validate(backendCfg);
|
|
18
19
|
return backendCfg;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateGAEServiceName = exports.createAppYaml = exports.createAndSaveAppYaml = exports.createDeployInfo = exports.createAndSaveDeployInfo = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
7
|
-
const
|
|
8
|
+
const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
|
|
8
9
|
const APP_YAML_DEFAULT = () => ({
|
|
9
10
|
runtime: 'nodejs18',
|
|
10
11
|
service: 'default',
|
|
@@ -26,7 +27,7 @@ const APP_YAML_DEFAULT = () => ({
|
|
|
26
27
|
async function createAndSaveDeployInfo(backendCfg, targetDir) {
|
|
27
28
|
const deployInfo = await createDeployInfo(backendCfg);
|
|
28
29
|
const deployInfoPath = `${targetDir}/deployInfo.json`;
|
|
29
|
-
|
|
30
|
+
node_fs_1.default.writeFileSync(deployInfoPath, JSON.stringify(deployInfo, null, 2));
|
|
30
31
|
console.log(`saved ${(0, nodejs_lib_1.dimGrey)(deployInfoPath)}`);
|
|
31
32
|
return deployInfo;
|
|
32
33
|
}
|
|
@@ -73,7 +74,7 @@ exports.createDeployInfo = createDeployInfo;
|
|
|
73
74
|
function createAndSaveAppYaml(backendCfg, deployInfo, projectDir, targetDir, appYamlPassEnv = '') {
|
|
74
75
|
const appYaml = createAppYaml(backendCfg, deployInfo, projectDir, appYamlPassEnv);
|
|
75
76
|
const appYamlPath = `${targetDir}/app.yaml`;
|
|
76
|
-
|
|
77
|
+
node_fs_1.default.writeFileSync(appYamlPath, js_yaml_1.default.dump(appYaml));
|
|
77
78
|
console.log(`saved ${(0, nodejs_lib_1.dimGrey)(appYamlPath)}`);
|
|
78
79
|
return appYaml;
|
|
79
80
|
}
|
|
@@ -89,14 +90,14 @@ function createAppYaml(backendCfg, deployInfo, projectDir, appYamlPassEnv = '')
|
|
|
89
90
|
const appYaml = APP_YAML_DEFAULT();
|
|
90
91
|
// Check existing app.yaml
|
|
91
92
|
const appYamlPath = `${projectDir}/app.yaml`;
|
|
92
|
-
if (
|
|
93
|
+
if (node_fs_1.default.existsSync(appYamlPath)) {
|
|
93
94
|
console.log(`merging-in ${(0, nodejs_lib_1.dimGrey)(appYamlPath)}`);
|
|
94
|
-
(0, js_lib_1._merge)(appYaml,
|
|
95
|
+
(0, js_lib_1._merge)(appYaml, js_yaml_1.default.load(node_fs_1.default.readFileSync(appYamlPath, 'utf8')));
|
|
95
96
|
}
|
|
96
97
|
const appEnvYamlPath = `${projectDir}/app.${APP_ENV}.yaml`;
|
|
97
|
-
if (
|
|
98
|
+
if (node_fs_1.default.existsSync(appEnvYamlPath)) {
|
|
98
99
|
console.log(`merging-in ${(0, nodejs_lib_1.dimGrey)(appEnvYamlPath)}`);
|
|
99
|
-
(0, js_lib_1._merge)(appYaml,
|
|
100
|
+
(0, js_lib_1._merge)(appYaml, js_yaml_1.default.load(node_fs_1.default.readFileSync(appEnvYamlPath, 'utf8')));
|
|
100
101
|
}
|
|
101
102
|
// appYamlPassEnv
|
|
102
103
|
require('dotenv').config(); // ensure .env is read
|
package/dist/paths.cnst.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.testDir = exports.srcDir = exports.resourcesDir = exports.projectDir = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
+
exports.projectDir = node_path_1.default.join(__dirname, '/..');
|
|
6
7
|
exports.resourcesDir = `${exports.projectDir}/resources`;
|
|
7
8
|
exports.srcDir = `${exports.projectDir}/src`;
|
|
8
9
|
exports.testDir = `${exports.srcDir}/test`;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDeployInfo = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
7
|
exports.getDeployInfo = (0, js_lib_1._memoFn)((projectDir) => {
|
|
7
8
|
const deployInfoPath = `${projectDir}/deployInfo.json`;
|
|
8
9
|
try {
|
|
9
|
-
return JSON.parse(
|
|
10
|
+
return JSON.parse(node_fs_1.default.readFileSync(deployInfoPath, 'utf8'));
|
|
10
11
|
}
|
|
11
12
|
catch {
|
|
12
13
|
// console.error(`cannot read ${deployInfoPath}, returning empty version`)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDefaultRouter = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const express_promise_router_1 = tslib_1.__importDefault(require("express-promise-router"));
|
|
5
6
|
/**
|
|
6
7
|
* Convenience method.
|
|
7
8
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs'
|
|
2
2
|
import { _memoFn, AppError } from '@naturalcycles/js-lib'
|
|
3
|
-
import
|
|
3
|
+
import ejs from 'ejs'
|
|
4
4
|
import { BackendRequestHandler } from '../server/server.model'
|
|
5
5
|
import { BaseAdminService } from './base.admin.service'
|
|
6
6
|
import { FirebaseSharedServiceCfg } from './firebase.shared.service'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _assert, AppError } from '@naturalcycles/js-lib'
|
|
2
2
|
import { dimGrey, green, red } from '@naturalcycles/nodejs-lib'
|
|
3
|
-
import type
|
|
3
|
+
import type FirebaseAdmin from 'firebase-admin'
|
|
4
4
|
import { BackendRequest, BackendRequestHandler } from '../server/server.model'
|
|
5
5
|
|
|
6
6
|
export interface AdminServiceCfg {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _Memo } from '@naturalcycles/js-lib'
|
|
2
2
|
import type { AppOptions, ServiceAccount } from 'firebase-admin'
|
|
3
|
-
import type
|
|
3
|
+
import type FirebaseAdmin from 'firebase-admin'
|
|
4
4
|
|
|
5
5
|
export interface FirebaseSharedServiceCfg {
|
|
6
6
|
/**
|
package/src/bin/deploy-gae.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { runScript } from '@naturalcycles/nodejs-lib'
|
|
4
|
-
import
|
|
4
|
+
import yargs from 'yargs'
|
|
5
5
|
import { deployGae } from '../deploy/deployGae'
|
|
6
6
|
import { deployHealthCheckYargsOptions } from '../deploy/deployHealthCheck'
|
|
7
7
|
import { deployPrepareYargsOptions } from '../deploy/deployPrepare'
|
|
@@ -10,7 +10,7 @@ yarn deploy-health-check --url https://service-dot-yourproject.appspot.com
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { runScript } from '@naturalcycles/nodejs-lib'
|
|
13
|
-
import
|
|
13
|
+
import yargs from 'yargs'
|
|
14
14
|
import { deployHealthCheck, deployHealthCheckYargsOptions } from '../deploy/deployHealthCheck'
|
|
15
15
|
|
|
16
16
|
runScript(async () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StringMap } from '@naturalcycles/js-lib'
|
|
2
2
|
import { _readFileSync, AjvSchema, requireFileToExist } from '@naturalcycles/nodejs-lib'
|
|
3
|
-
import
|
|
3
|
+
import yaml from 'js-yaml'
|
|
4
4
|
import { resourcesDir } from '../paths.cnst'
|
|
5
5
|
|
|
6
6
|
export interface BackendCfg {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs'
|
|
2
2
|
import { _mapValues, _merge, _truncate, localTime } from '@naturalcycles/js-lib'
|
|
3
3
|
import { dimGrey, white } from '@naturalcycles/nodejs-lib'
|
|
4
|
-
import
|
|
4
|
+
import yaml from 'js-yaml'
|
|
5
5
|
import { BackendCfg } from './backend.cfg.util'
|
|
6
6
|
import { AppYaml, DeployInfo } from './deploy.model'
|
|
7
7
|
|
package/src/paths.cnst.ts
CHANGED