acebase-server 1.16.0 → 1.16.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.
package/build-vars.js ADDED
@@ -0,0 +1,16 @@
1
+ // Executed by npm "version" hook
2
+ const { readFileSync, writeFileSync } = require('fs');
3
+ const { execSync } = require('child_process');
4
+ const packageInfo = require('./package.json');
5
+
6
+ const files = ['./dist/cjs/routes/meta-info.js', './dist/esm/routes/meta-info.js'];
7
+ files.forEach(file => {
8
+ const originalContent = readFileSync(file, 'utf8');
9
+ content = originalContent.replace(/%SERVER_VERSION%/g, packageInfo.version);
10
+ if (content !== originalContent) {
11
+ writeFileSync(file, content, 'utf8');
12
+ console.log(`Replaced variable %SERVER_VERSION% with ${packageInfo.version} in ${file}`);
13
+ }
14
+ });
15
+
16
+ execSync(`git add dist`);
@@ -2,14 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addRoute = void 0;
4
4
  const os = require("os");
5
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
- // @ts-ignore path to package.json is different in builds
7
- const package_json_1 = require("../../../package.json");
5
+ const SERVER_VERSION = '1.16.2'; // Loaded from package.json by npm scripts
8
6
  const addRoute = (env) => {
9
7
  // Add info endpoint
10
8
  env.app.get(`/info/${env.db.name}`, (req, res) => {
11
9
  const info = {
12
- version: package_json_1.default.version,
10
+ version: SERVER_VERSION,
13
11
  time: Date.now(),
14
12
  process: process.pid,
15
13
  };
@@ -16,24 +16,25 @@ const createPublicAccessToken = (uid, ip, dbToken, password) => {
16
16
  };
17
17
  exports.createPublicAccessToken = createPublicAccessToken;
18
18
  const decodePublicAccessToken = (accessToken, password) => {
19
+ let details;
19
20
  if (accessToken[0] === 'b') {
20
21
  // New signed version
21
22
  const obj = (0, exports.parseSignedPublicToken)(accessToken.slice(1), password);
22
- const details = {
23
+ details = {
23
24
  access_token: obj.t,
24
25
  uid: obj.u,
25
26
  created: obj.c,
26
27
  ip: obj.i,
27
28
  };
28
- if (!details.access_token || !details.uid || !details.created || !details.ip) {
29
- throw new Error('Invalid token');
30
- }
31
- return details;
32
29
  }
33
30
  else if (accessToken[0] === 'a') {
34
31
  // Old insecure version, previously allowed until August 1, 2020.
35
32
  throw new Error('Old token version not allowed');
36
33
  }
34
+ if (!details || !details.access_token || !details.uid || !details.created || !details.ip) {
35
+ throw new Error('Invalid token');
36
+ }
37
+ return details;
37
38
  };
38
39
  exports.decodePublicAccessToken = decodePublicAccessToken;
39
40
  const getSignature = (content, salt) => {
@@ -1,12 +1,10 @@
1
1
  import * as os from 'os';
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-ignore path to package.json is different in builds
4
- import meta from '../../../package.json' assert { type: 'json' };
2
+ const SERVER_VERSION = '1.16.2'; // Loaded from package.json by npm scripts
5
3
  export const addRoute = (env) => {
6
4
  // Add info endpoint
7
5
  env.app.get(`/info/${env.db.name}`, (req, res) => {
8
6
  const info = {
9
- version: meta.version,
7
+ version: SERVER_VERSION,
10
8
  time: Date.now(),
11
9
  process: process.pid,
12
10
  };
@@ -12,24 +12,25 @@ export const createPublicAccessToken = (uid, ip, dbToken, password) => {
12
12
  return 'b' + createSignedPublicToken(obj, password);
13
13
  };
14
14
  export const decodePublicAccessToken = (accessToken, password) => {
15
+ let details;
15
16
  if (accessToken[0] === 'b') {
16
17
  // New signed version
17
18
  const obj = parseSignedPublicToken(accessToken.slice(1), password);
18
- const details = {
19
+ details = {
19
20
  access_token: obj.t,
20
21
  uid: obj.u,
21
22
  created: obj.c,
22
23
  ip: obj.i,
23
24
  };
24
- if (!details.access_token || !details.uid || !details.created || !details.ip) {
25
- throw new Error('Invalid token');
26
- }
27
- return details;
28
25
  }
29
26
  else if (accessToken[0] === 'a') {
30
27
  // Old insecure version, previously allowed until August 1, 2020.
31
28
  throw new Error('Old token version not allowed');
32
29
  }
30
+ if (!details || !details.access_token || !details.uid || !details.created || !details.ip) {
31
+ throw new Error('Invalid token');
32
+ }
33
+ return details;
33
34
  };
34
35
  const getSignature = (content, salt) => {
35
36
  // Use fast md5 with salt to sign with. Large salt recommended!!
@@ -1,10 +1,11 @@
1
1
  export declare const createPublicAccessToken: (uid: string, ip: string, dbToken: string, password: string) => string;
2
- export declare const decodePublicAccessToken: (accessToken: string, password: string) => {
2
+ export declare type PublicAccessToken = {
3
3
  access_token: string;
4
4
  uid: string;
5
5
  created: number;
6
6
  ip: string;
7
7
  };
8
+ export declare const decodePublicAccessToken: (accessToken: string, password: string) => PublicAccessToken;
8
9
  /**
9
10
  * Sign objects with an md5 hash. An attacker might base4 decode it and see the content and generated checksum hash,
10
11
  * but will need to guess the password used to generate the hash to manipulate it. This is not impossible but will take
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acebase-server",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
4
4
  "description": "AceBase realtime database server (webserver endpoint to allow remote connections)",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -24,7 +24,8 @@
24
24
  "build:esm": "tsc -p tsconfig.json && npx tsc-esm-fix ---target='dist/esm'",
25
25
  "build:cjs": "tsc -p tsconfig-cjs.json",
26
26
  "build:packages": "bash ./create-package-files",
27
- "npmfix": "echo 'Regenerating package-lock.json...' && npm i --package-lock-only"
27
+ "preversion": "npm run build",
28
+ "version": "node ./build-vars.js"
28
29
  },
29
30
  "keywords": [
30
31
  "database",