acebase-server 1.18.2 → 1.19.1

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.
Files changed (93) hide show
  1. package/.eslintrc.json +49 -49
  2. package/.github/workflows/publish.yml +125 -0
  3. package/Dockerfile +26 -26
  4. package/LICENSE +21 -21
  5. package/bin/acebase-server.js +8 -8
  6. package/create-package-files.sh +25 -0
  7. package/dist/cjs/middleware/admin-only.js +2 -1
  8. package/dist/cjs/middleware/user.js +1 -0
  9. package/dist/cjs/routes/auth-delete.js +3 -2
  10. package/dist/cjs/routes/auth-signup.js +11 -11
  11. package/dist/cjs/routes/auth-update.js +2 -1
  12. package/dist/cjs/routes/auth.js +0 -3
  13. package/dist/cjs/routes/data-exists.js +2 -2
  14. package/dist/cjs/routes/data-export.js +2 -2
  15. package/dist/cjs/routes/data-get.js +2 -2
  16. package/dist/cjs/routes/data-reflect.js +4 -4
  17. package/dist/cjs/routes/data-set.js +4 -3
  18. package/dist/cjs/routes/data-transaction.js +4 -3
  19. package/dist/cjs/routes/data-update.js +4 -3
  20. package/dist/cjs/routes/docs.js +1 -1
  21. package/dist/cjs/routes/meta-info.js +3 -2
  22. package/dist/cjs/rules.js +2 -1
  23. package/dist/cjs/schema/user.js +2 -1
  24. package/dist/cjs/server.js +12 -3
  25. package/dist/cjs/settings/index.js +6 -0
  26. package/dist/cjs/shared/admin.js +8 -0
  27. package/dist/cjs/websocket/index.js +2 -1
  28. package/dist/esm/middleware/admin-only.js +2 -1
  29. package/dist/esm/middleware/user.js +1 -0
  30. package/dist/esm/routes/auth-delete.js +3 -2
  31. package/dist/esm/routes/auth-signup.js +4 -4
  32. package/dist/esm/routes/auth-update.js +2 -1
  33. package/dist/esm/routes/auth.js +0 -3
  34. package/dist/esm/routes/data-exists.js +1 -2
  35. package/dist/esm/routes/data-export.js +1 -2
  36. package/dist/esm/routes/data-get.js +1 -1
  37. package/dist/esm/routes/data-reflect.js +3 -3
  38. package/dist/esm/routes/data-set.js +2 -1
  39. package/dist/esm/routes/data-transaction.js +2 -1
  40. package/dist/esm/routes/data-update.js +2 -1
  41. package/dist/esm/routes/docs.js +1 -1
  42. package/dist/esm/routes/meta-info.js +3 -2
  43. package/dist/esm/rules.js +2 -1
  44. package/dist/esm/schema/user.js +1 -0
  45. package/dist/esm/server.js +12 -3
  46. package/dist/esm/settings/index.js +6 -0
  47. package/dist/esm/shared/admin.js +4 -0
  48. package/dist/esm/websocket/index.js +1 -1
  49. package/dist/types/middleware/user.d.ts +1 -0
  50. package/dist/types/routes/auth-update.d.ts +2 -0
  51. package/dist/types/rules.d.ts +1 -1
  52. package/dist/types/schema/user.d.ts +4 -0
  53. package/dist/types/settings/index.d.ts +14 -2
  54. package/dist/types/shared/admin.d.ts +3 -0
  55. package/package.json +4 -5
  56. package/release_notes.md +4 -0
  57. package/src/routes/auth-change-password.yaml +73 -73
  58. package/src/routes/auth-delete.yaml +77 -77
  59. package/src/routes/auth-forgot-password.yaml +49 -49
  60. package/src/routes/auth-reset-password.yaml +53 -53
  61. package/src/routes/auth-signin.yaml +129 -129
  62. package/src/routes/auth-signout.yaml +46 -46
  63. package/src/routes/auth-signup.yaml +135 -135
  64. package/src/routes/auth-state.yaml +28 -28
  65. package/src/routes/auth-update.yaml +151 -151
  66. package/src/routes/auth-verify-email.yaml +52 -52
  67. package/src/routes/data-exists.yaml +44 -44
  68. package/src/routes/data-export.yaml +63 -63
  69. package/src/routes/data-import.yaml +74 -74
  70. package/src/routes/data-index-create.yaml +105 -105
  71. package/src/routes/data-index-delete.yaml +51 -51
  72. package/src/routes/data-index-list.yaml +84 -84
  73. package/src/routes/data-query.yaml +165 -165
  74. package/src/routes/data-reflect.yaml +124 -124
  75. package/src/routes/data-schema-get.yaml +53 -53
  76. package/src/routes/data-schema-set.yaml +64 -64
  77. package/src/routes/data-schema-test.yaml +66 -66
  78. package/src/routes/data-schemas-list.yaml +41 -41
  79. package/src/routes/data-set.yaml +77 -77
  80. package/src/routes/data-sync-changes.yaml +66 -66
  81. package/src/routes/data-sync-mutations.yaml +66 -66
  82. package/src/routes/data-transaction-finish.yaml +82 -82
  83. package/src/routes/data-transaction-start.yaml +58 -58
  84. package/src/routes/data-update.yaml +77 -77
  85. package/src/routes/meta-info.yaml +40 -40
  86. package/src/routes/meta-ping.yaml +22 -22
  87. package/src/routes/meta-stats.yaml +40 -40
  88. package/src/routes/oauth2-init.yaml +62 -62
  89. package/src/routes/oauth2-refresh.yaml +64 -64
  90. package/src/routes/oauth2-signin.yaml +65 -65
  91. package/webmanager/acebase-client-browser.min.js +12 -12
  92. package/webmanager/index.html +271 -271
  93. package/webmanager/index.js +437 -437
package/.eslintrc.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2021": true,
5
- "node": true
6
- },
7
- "extends": [
8
- "plugin:@typescript-eslint/recommended"
9
- ],
10
- "parser": "@typescript-eslint/parser",
11
- "parserOptions": {
12
- "ecmaVersion": "latest",
13
- "sourceType": "module"
14
- },
15
- "plugins": [
16
- "@typescript-eslint"
17
- ],
18
- "rules": {
19
- "indent": [ "error", 4, { "SwitchCase": 1, "VariableDeclarator": 1, "MemberExpression": 1, "CallExpression": { "arguments": 1 } }],
20
- "quotes": ["error", "single", { "avoidEscape": false, "allowTemplateLiterals": true }],
21
- "semi": ["error", "always"],
22
- "@typescript-eslint/no-explicit-any": [
23
- "off", // "error" if we want to enforce usage of `unknown` instead
24
- {
25
- "ignoreRestArgs": false,
26
- "fixToUnknown": true
27
- }
28
- ],
29
- "comma-dangle": "off",
30
- "@typescript-eslint/comma-dangle": ["error", {
31
- "arrays": "always-multiline",
32
- "objects": "always-multiline",
33
- "imports": "always-multiline",
34
- "exports": "always-multiline",
35
- "enums": "always-multiline",
36
- "functions": "only-multiline"
37
- }],
38
- "no-trailing-spaces": "error",
39
- "eol-last": "error",
40
- "curly": "error"
41
- },
42
- "overrides": [{
43
- "files": "*.js",
44
- "rules": {
45
- "@typescript-eslint/no-var-requires": "off"
46
- }
47
- }],
48
- "ignorePatterns": ["dist/**/*.*", "webmanager/*.min.js"]
49
- }
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "node": true
6
+ },
7
+ "extends": [
8
+ "plugin:@typescript-eslint/recommended"
9
+ ],
10
+ "parser": "@typescript-eslint/parser",
11
+ "parserOptions": {
12
+ "ecmaVersion": "latest",
13
+ "sourceType": "module"
14
+ },
15
+ "plugins": [
16
+ "@typescript-eslint"
17
+ ],
18
+ "rules": {
19
+ "indent": [ "error", 4, { "SwitchCase": 1, "VariableDeclarator": 1, "MemberExpression": 1, "CallExpression": { "arguments": 1 } }],
20
+ "quotes": ["error", "single", { "avoidEscape": false, "allowTemplateLiterals": true }],
21
+ "semi": ["error", "always"],
22
+ "@typescript-eslint/no-explicit-any": [
23
+ "off", // "error" if we want to enforce usage of `unknown` instead
24
+ {
25
+ "ignoreRestArgs": false,
26
+ "fixToUnknown": true
27
+ }
28
+ ],
29
+ "comma-dangle": "off",
30
+ "@typescript-eslint/comma-dangle": ["error", {
31
+ "arrays": "always-multiline",
32
+ "objects": "always-multiline",
33
+ "imports": "always-multiline",
34
+ "exports": "always-multiline",
35
+ "enums": "always-multiline",
36
+ "functions": "only-multiline"
37
+ }],
38
+ "no-trailing-spaces": "error",
39
+ "eol-last": "error",
40
+ "curly": "error"
41
+ },
42
+ "overrides": [{
43
+ "files": "*.js",
44
+ "rules": {
45
+ "@typescript-eslint/no-var-requires": "off"
46
+ }
47
+ }],
48
+ "ignorePatterns": ["dist/**/*.*", "webmanager/*.min.js"]
49
+ }
@@ -0,0 +1,125 @@
1
+ name: Publish Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v[0-9]+.[0-9]+.[0-9]+'
7
+ - 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'
8
+
9
+ jobs:
10
+ publish:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write # needed to create GitHub releases
14
+ id-token: write # needed for npm provenance attestation
15
+
16
+ steps:
17
+ - name: Checkout
18
+ uses: actions/checkout@v4
19
+ with:
20
+ fetch-depth: 0 # full history needed for release notes
21
+
22
+ - name: Setup Node.js
23
+ uses: actions/setup-node@v4
24
+ with:
25
+ node-version: '24'
26
+
27
+ - name: Extract version from tag
28
+ id: version
29
+ run: |
30
+ echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
31
+ if [[ "${GITHUB_REF_NAME}" == *"-rc."* ]]; then
32
+ echo "IS_RC=true" >> "$GITHUB_OUTPUT"
33
+ else
34
+ echo "IS_RC=false" >> "$GITHUB_OUTPUT"
35
+ fi
36
+
37
+ - name: Set version in package.json
38
+ run: npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version
39
+
40
+ - name: Commit version bump
41
+ run: |
42
+ git config user.name "github-actions[bot]"
43
+ git config user.email "github-actions[bot]@users.noreply.github.com"
44
+
45
+ # Find which branch tip matches the tagged commit.
46
+ TAGGED_COMMIT=$(git rev-parse "$GITHUB_REF_NAME")
47
+ TARGET_BRANCH=$(git for-each-ref --format='%(refname:short)' refs/remotes/origin \
48
+ --points-at "$TAGGED_COMMIT" | sed 's|^origin/||' | grep -v '^HEAD$' | head -1)
49
+
50
+ if [ -z "$TARGET_BRANCH" ]; then
51
+ echo "::error::Tag $GITHUB_REF_NAME is not at the tip of any branch. Create tags only at the latest commit of a branch."
52
+ exit 1
53
+ fi
54
+
55
+ echo "Pushing version bump to branch: $TARGET_BRANCH"
56
+ git add package.json package-lock.json
57
+ git commit -m "chore: release ${{ github.ref_name }} [skip ci]"
58
+ git push origin HEAD:"$TARGET_BRANCH"
59
+
60
+ - name: Resolve file dependencies to npm versions
61
+ # Replaces any "file:..." dependency entries with the latest published
62
+ # npm version. This is needed because acebase-core is referenced as a
63
+ # local path during development but must be a real semver range in the
64
+ # published package.
65
+ run: |
66
+ node - <<'EOF'
67
+ const fs = require('fs');
68
+ const { execSync } = require('child_process');
69
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
70
+ const toInstall = [];
71
+ for (const section of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']) {
72
+ if (!pkg[section]) continue;
73
+ for (const [name, version] of Object.entries(pkg[section])) {
74
+ if (version.startsWith('file:')) {
75
+ console.log(`Queuing ${name} for npm install`);
76
+ toInstall.push(name + '@latest');
77
+ }
78
+ }
79
+ }
80
+ if (toInstall.length > 0) {
81
+ execSync(`npm install ${toInstall.join(' ')}`, { stdio: 'inherit' });
82
+ }
83
+ EOF
84
+
85
+ - name: Install dependencies
86
+ run: npm install
87
+
88
+ - name: Build
89
+ run: npm run build
90
+
91
+ - name: Generate release notes
92
+ id: notes
93
+ run: |
94
+ CURRENT_TAG="${GITHUB_REF_NAME}"
95
+ PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^${CURRENT_TAG}$" | head -1)
96
+
97
+ if [ -n "$PREVIOUS_TAG" ]; then
98
+ echo "Generating notes from ${PREVIOUS_TAG} to ${CURRENT_TAG}"
99
+ NOTES=$(git log "${PREVIOUS_TAG}..${CURRENT_TAG}" --pretty=format:"- %s (%h)" --no-merges)
100
+ else
101
+ echo "No previous tag found, using all commits"
102
+ NOTES=$(git log --pretty=format:"- %s (%h)" --no-merges)
103
+ fi
104
+
105
+ # Write to a file to avoid quoting/escaping issues
106
+ printf '%s\n' "$NOTES" > release_notes.md
107
+ cat release_notes.md
108
+
109
+ - name: Create GitHub release
110
+ env:
111
+ GH_TOKEN: ${{ github.token }}
112
+ run: |
113
+ gh release create "$GITHUB_REF_NAME" \
114
+ --title "$GITHUB_REF_NAME" \
115
+ --notes-file release_notes.md \
116
+ ${{ steps.version.outputs.IS_RC == 'true' && '--prerelease' || '' }}
117
+
118
+ - name: Publish to npm
119
+ run: |
120
+ if [[ "${{ steps.version.outputs.IS_RC }}" == "true" ]]; then
121
+ echo "RC tag detected — running npm publish --dry-run"
122
+ npm publish --access public --dry-run
123
+ else
124
+ npm publish --access public
125
+ fi
package/Dockerfile CHANGED
@@ -1,26 +1,26 @@
1
- # experimenting running in docker container.
2
- # WARNING: running 1 instance is currently supported per db, running multiple will corrupt your data!
3
- # To build a docker image, execute:
4
- # docker build -t acebase-server .
5
- # To run:
6
- # docker volume create acebase-server-data
7
- # docker run --name MyAceBaseServer1 -p 3000:3000 -p 4000:4000 -v acebase-server-data:/default.acebase acebase-server
8
-
9
- FROM node:10-alpine
10
- WORKDIR /app
11
- COPY package.json .
12
- RUN npm install
13
- COPY src ./src
14
-
15
- # Initialize build arguments passed to docker build --build-arg DBNAME=data ...
16
- ARG DBNAME="data"
17
- ARG PORT=3000
18
- ARG CLUSTER_PORT=4000
19
- ARG HOST="0.0.0.0"
20
- ARG DBPATH="."
21
-
22
- # Set defaults for runtime environment variables, can be overriden by: docker run --env DBNAME=mydb ...
23
- ENV DBNAME=${DBNAME} HOST=${HOST} PORT=${PORT} CLUSTER_PORT=${CLUSTER_PORT} DBPATH=${DBPATH}
24
-
25
- # Start server without arguments, environment variables will be used
26
- CMD ["node", "src/start.js"]
1
+ # experimenting running in docker container.
2
+ # WARNING: running 1 instance is currently supported per db, running multiple will corrupt your data!
3
+ # To build a docker image, execute:
4
+ # docker build -t acebase-server .
5
+ # To run:
6
+ # docker volume create acebase-server-data
7
+ # docker run --name MyAceBaseServer1 -p 3000:3000 -p 4000:4000 -v acebase-server-data:/default.acebase acebase-server
8
+
9
+ FROM node:10-alpine
10
+ WORKDIR /app
11
+ COPY package.json .
12
+ RUN npm install
13
+ COPY src ./src
14
+
15
+ # Initialize build arguments passed to docker build --build-arg DBNAME=data ...
16
+ ARG DBNAME="data"
17
+ ARG PORT=3000
18
+ ARG CLUSTER_PORT=4000
19
+ ARG HOST="0.0.0.0"
20
+ ARG DBPATH="."
21
+
22
+ # Set defaults for runtime environment variables, can be overriden by: docker run --env DBNAME=mydb ...
23
+ ENV DBNAME=${DBNAME} HOST=${HOST} PORT=${PORT} CLUSTER_PORT=${CLUSTER_PORT} DBPATH=${DBPATH}
24
+
25
+ # Start server without arguments, environment variables will be used
26
+ CMD ["node", "src/start.js"]
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Ewout Stortenbeker (me@appy.one)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ewout Stortenbeker (me@appy.one)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env node
2
-
3
- if (process.argv[2] === 'start') {
4
- require('../dist/cjs/start');
5
- }
6
- else {
7
- console.log(`[acebase-server CLI] unknown instruction. Did you mean "npx acebase-server start"?`);
8
- }
1
+ #!/usr/bin/env node
2
+
3
+ if (process.argv[2] === 'start') {
4
+ require('../dist/cjs/start');
5
+ }
6
+ else {
7
+ console.log(`[acebase-server CLI] unknown instruction. Did you mean "npx acebase-server start"?`);
8
+ }
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+
3
+ # Create CommonJS package.json
4
+ cat >dist/cjs/package.json <<!JSON
5
+ {
6
+ "type": "commonjs"
7
+ }
8
+ !JSON
9
+
10
+ # Write typings to support Node16 module resolution
11
+ cat >dist/cjs/index.d.ts <<!TYPESCRIPT
12
+ export * from '../types/index.js';
13
+ !TYPESCRIPT
14
+
15
+ # Create ESM package.json
16
+ cat >dist/esm/package.json <<!JSON
17
+ {
18
+ "type": "module"
19
+ }
20
+ !JSON
21
+
22
+ # Write typings to support Node16 module resolution
23
+ cat >dist/esm/index.d.ts <<!TYPESCRIPT
24
+ export * from '../types/index.js';
25
+ !TYPESCRIPT
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.adminOnly = void 0;
4
4
  const error_1 = require("../shared/error");
5
+ const admin_1 = require("../shared/admin");
5
6
  /**
6
7
  * Middleware function that checks if the current user is `admin`. An 403 Forbidden error will be sent in the response if
7
8
  * authentication is enabled on the server and the user is not signed in as admin.
@@ -18,7 +19,7 @@ const error_1 = require("../shared/error");
18
19
  */
19
20
  const adminOnly = (env, errorMessage = 'only admin can perform this operation') => {
20
21
  return (req, res, next) => {
21
- if (env.config.auth.enabled && (!req.user || req.user.uid !== 'admin')) {
22
+ if (env.config.auth.enabled && !(0, admin_1.isAdmin)(req.user)) {
22
23
  return (0, error_1.sendUnauthorizedError)(res, 'admin_only', errorMessage);
23
24
  }
24
25
  next();
@@ -55,4 +55,5 @@ const addMiddleware = (env) => {
55
55
  }));
56
56
  };
57
57
  exports.addMiddleware = addMiddleware;
58
+ exports.default = exports.addMiddleware;
58
59
  //# sourceMappingURL=user.js.map
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = exports.DeleteError = void 0;
13
+ const admin_1 = require("../shared/admin");
13
14
  const error_1 = require("../shared/error");
14
15
  class DeleteError extends Error {
15
16
  constructor(code, message) {
@@ -28,14 +29,14 @@ const addRoute = (env) => {
28
29
  env.log.error(LOG_ACTION, 'unauthenticated_delete', LOG_DETAILS);
29
30
  return (0, error_1.sendNotAuthenticatedError)(res, 'unauthenticated_delete', 'You are not authorized to perform this operation, your attempt has been logged');
30
31
  }
31
- if (req.user.uid !== 'admin' && details.uid !== req.user.uid) {
32
+ if (!(0, admin_1.isAdmin)(req.user) && details.uid !== req.user.uid) {
32
33
  env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
33
34
  return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'You are not authorized to perform this operation, your attempt has been logged');
34
35
  }
35
36
  const uid = (_c = details.uid) !== null && _c !== void 0 ? _c : req.user.uid;
36
37
  if (uid === 'admin') {
37
38
  env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
38
- return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'The admin account cannot be deleted, your attempt has been logged');
39
+ return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'The default admin account cannot be deleted, your attempt has been logged');
39
40
  }
40
41
  try {
41
42
  yield env.authRef.child(uid).remove();
@@ -16,6 +16,7 @@ const password_1 = require("../shared/password");
16
16
  const acebase_core_1 = require("acebase-core");
17
17
  const tokens_1 = require("../shared/tokens");
18
18
  const error_1 = require("../shared/error");
19
+ const admin_1 = require("../shared/admin");
19
20
  class SignupError extends Error {
20
21
  constructor(code, message) {
21
22
  super(message);
@@ -25,12 +26,12 @@ class SignupError extends Error {
25
26
  exports.SignupError = SignupError;
26
27
  const addRoute = (env) => {
27
28
  env.router.post(`/auth/${env.db.name}/signup`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
28
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
29
+ var _a, _b, _c, _d, _e, _f, _g, _h;
29
30
  const LOG_ACTION = 'auth.signup';
30
31
  const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null };
31
- if (!env.config.auth.allowUserSignup && ((_c = req.user) === null || _c === void 0 ? void 0 : _c.uid) !== 'admin') {
32
+ if (!env.config.auth.allowUserSignup && !(0, admin_1.isAdmin)(req.user)) {
32
33
  env.log.error(LOG_ACTION, 'user_signup_disabled', LOG_DETAILS);
33
- return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'Only admin is allowed to create users');
34
+ return (0, error_1.sendUnauthorizedError)(res, 'admin_only', 'Only admins are allowed to create users');
34
35
  }
35
36
  // Create user if it doesn't exist yet.
36
37
  // TODO: Rate-limit nr of signups per IP to prevent abuse
@@ -75,7 +76,7 @@ const addRoute = (env) => {
75
76
  }
76
77
  else if (err) {
77
78
  // Log failure
78
- env.log.error(LOG_ACTION, (_d = err.code) !== null && _d !== void 0 ? _d : 'unexpected', LOG_DETAILS);
79
+ env.log.error(LOG_ACTION, (_c = err.code) !== null && _c !== void 0 ? _c : 'unexpected', LOG_DETAILS);
79
80
  res.statusCode = 422; // Unprocessable Entity
80
81
  return res.send(err);
81
82
  }
@@ -84,8 +85,8 @@ const addRoute = (env) => {
84
85
  const pwd = (0, password_1.createPasswordHash)(details.password);
85
86
  const user = {
86
87
  uid: null,
87
- username: (_e = details.username) !== null && _e !== void 0 ? _e : null,
88
- email: (_f = details.email) !== null && _f !== void 0 ? _f : null,
88
+ username: (_d = details.username) !== null && _d !== void 0 ? _d : null,
89
+ email: (_e = details.email) !== null && _e !== void 0 ? _e : null,
89
90
  email_verified: false,
90
91
  display_name: details.displayName,
91
92
  password: pwd.hash,
@@ -96,8 +97,8 @@ const addRoute = (env) => {
96
97
  access_token_created: new Date(),
97
98
  last_signin: new Date(),
98
99
  last_signin_ip: req.ip,
99
- picture: (_g = details.picture) !== null && _g !== void 0 ? _g : null,
100
- settings: (_h = details.settings) !== null && _h !== void 0 ? _h : {},
100
+ picture: (_f = details.picture) !== null && _f !== void 0 ? _f : null,
101
+ settings: (_g = details.settings) !== null && _g !== void 0 ? _g : {},
101
102
  };
102
103
  const userRef = yield env.authRef.push(user);
103
104
  user.uid = userRef.key;
@@ -122,13 +123,12 @@ const addRoute = (env) => {
122
123
  activationCode: (0, tokens_1.createSignedPublicToken)({ uid: user.uid }, env.tokenSalt),
123
124
  emailVerified: false,
124
125
  };
125
- (_j = env.config.email) === null || _j === void 0 ? void 0 : _j.send(request).catch(err => {
126
+ (_h = env.config.email) === null || _h === void 0 ? void 0 : _h.send(request).catch(err => {
126
127
  env.log.error(LOG_ACTION + '.email', 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { request }), err);
127
128
  });
128
129
  // Return the positive news
129
- const isAdmin = req.user && req.user.uid === 'admin';
130
130
  res.send({
131
- access_token: isAdmin ? '' : (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt),
131
+ access_token: (0, admin_1.isAdmin)(req.user) ? '' : (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt),
132
132
  user: (0, user_1.getPublicAccountDetails)(user),
133
133
  });
134
134
  }
@@ -13,6 +13,7 @@ exports.addRoute = exports.UpdateError = void 0;
13
13
  const user_1 = require("../schema/user");
14
14
  const validate_1 = require("../shared/validate");
15
15
  const error_1 = require("../shared/error");
16
+ const admin_1 = require("../shared/admin");
16
17
  class UpdateError extends Error {
17
18
  constructor(code, message) {
18
19
  super(message);
@@ -31,7 +32,7 @@ const addRoute = (env) => {
31
32
  return (0, error_1.sendNotAuthenticatedError)(res, 'unauthenticated_update', 'Sign in to change details');
32
33
  }
33
34
  const uid = details.uid || req.user.uid;
34
- if (req.user.uid !== 'admin' && (uid !== req.user.uid || typeof details.is_disabled === 'boolean')) {
35
+ if (!(0, admin_1.isAdmin)(req.user) && (uid !== req.user.uid || typeof details.is_disabled === 'boolean' || details.roles)) {
35
36
  env.log.error(LOG_ACTION, 'unauthorized_update', LOG_DETAILS);
36
37
  return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_update', 'You are not authorized to perform this update. This attempt has been logged.');
37
38
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addAuthenticionRoutes = void 0;
4
- const user_1 = require("../middleware/user");
5
4
  const auth_state_1 = require("./auth-state");
6
5
  const auth_signin_1 = require("./auth-signin");
7
6
  const auth_signout_1 = require("./auth-signout");
@@ -19,8 +18,6 @@ const addAuthenticionRoutes = (env) => {
19
18
  if (!env.config.auth.enabled) {
20
19
  throw new Error('Authentication not enabled in the server settings');
21
20
  }
22
- // Bearer authentication middleware
23
- (0, user_1.addMiddleware)(env);
24
21
  // Auth state endpoint
25
22
  (0, auth_state_1.addRoute)(env);
26
23
  // signin endpoint
@@ -13,6 +13,7 @@ exports.addRoute = void 0;
13
13
  const error_1 = require("../shared/error");
14
14
  const addRoute = (env) => {
15
15
  env.router.get(`/exists/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ var _a, _b;
16
17
  // Exists query
17
18
  const path = req.path.slice(env.db.name.length + 9);
18
19
  const access = yield env.rules.isOperationAllowed(req.user, path, 'exists', { context: req.context });
@@ -24,8 +25,7 @@ const addRoute = (env) => {
24
25
  res.send({ exists });
25
26
  }
26
27
  catch (err) {
27
- res.statusCode = 500;
28
- res.send(err);
28
+ res.status(500).send(`${(_b = (_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : err}`);
29
29
  }
30
30
  }));
31
31
  };
@@ -13,6 +13,7 @@ exports.addRoute = void 0;
13
13
  const error_1 = require("../shared/error");
14
14
  const addRoute = (env) => {
15
15
  env.router.get(`/export/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
16
+ var _a, _b;
16
17
  // Export API
17
18
  const path = req.path.slice(env.db.name.length + 9);
18
19
  const access = yield env.rules.isOperationAllowed(req.user, path, 'export', { context: req.context });
@@ -35,8 +36,7 @@ const addRoute = (env) => {
35
36
  catch (err) {
36
37
  env.debug.error(`Error exporting data for path "/${path}": `, err);
37
38
  if (!res.headersSent) {
38
- res.statusCode = 500;
39
- res.send(err);
39
+ res.status(500).send(`${(_b = (_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : err}`);
40
40
  }
41
41
  }
42
42
  finally {
@@ -14,7 +14,7 @@ const acebase_core_1 = require("acebase-core");
14
14
  const error_1 = require("../shared/error");
15
15
  const addRoute = (env) => {
16
16
  env.router.get(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
- var _a;
17
+ var _a, _b, _c;
18
18
  // Request data
19
19
  const path = req.path.slice(env.db.name.length + 7);
20
20
  // Pre-check read access
@@ -63,7 +63,7 @@ const addRoute = (env) => {
63
63
  });
64
64
  }
65
65
  catch (err) {
66
- res.status(500).send(err);
66
+ res.status(500).send(`${(_c = (_b = err === null || err === void 0 ? void 0 : err.stack) !== null && _b !== void 0 ? _b : err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : err}`);
67
67
  }
68
68
  }));
69
69
  };
@@ -12,9 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addRoute = void 0;
13
13
  const acebase_core_1 = require("acebase-core");
14
14
  const error_1 = require("../shared/error");
15
+ const admin_1 = require("../shared/admin");
15
16
  const addRoute = (env) => {
16
17
  env.router.get(`/reflect/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
17
- var _a;
18
+ var _a, _b;
18
19
  // Reflection API
19
20
  const path = req.path.slice(env.db.name.length + 10);
20
21
  const access = yield env.rules.isOperationAllowed(req.user, path, 'reflect', { context: req.context, type: req.query.type });
@@ -22,7 +23,7 @@ const addRoute = (env) => {
22
23
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
23
24
  }
24
25
  const impersonatedAccess = {
25
- uid: ((_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== 'admin' ? null : req.query.impersonate,
26
+ uid: !(0, admin_1.isAdmin)(req.user) ? null : req.query.impersonate,
26
27
  /**
27
28
  * NEW, check all possible operations
28
29
  */
@@ -88,8 +89,7 @@ const addRoute = (env) => {
88
89
  res.send(result);
89
90
  }
90
91
  catch (err) {
91
- res.statusCode = 500;
92
- res.send(err);
92
+ res.status(500).send(`${(_b = (_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : err}`);
93
93
  }
94
94
  }));
95
95
  };
@@ -14,6 +14,7 @@ const acebase_1 = require("acebase");
14
14
  const acebase_core_1 = require("acebase-core");
15
15
  const rules_1 = require("../rules");
16
16
  const error_1 = require("../shared/error");
17
+ const admin_1 = require("../shared/admin");
17
18
  class SetDataError extends Error {
18
19
  constructor(code, message) {
19
20
  super(message);
@@ -23,7 +24,7 @@ class SetDataError extends Error {
23
24
  exports.SetDataError = SetDataError;
24
25
  const addRoute = (env) => {
25
26
  env.router.put(`/data/${env.db.name}/*`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
26
- var _a, _b, _c, _d, _e, _f;
27
+ var _a, _b, _c, _d, _e;
27
28
  const path = req.path.slice(env.db.name.length + 7);
28
29
  const LOG_ACTION = 'data.set';
29
30
  const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, path };
@@ -38,7 +39,7 @@ const addRoute = (env) => {
38
39
  throw new SetDataError('invalid_serialized_value', 'The sent value is not properly serialized');
39
40
  }
40
41
  const val = acebase_core_1.Transport.deserialize(data);
41
- if (path === '' && ((_c = req.user) === null || _c === void 0 ? void 0 : _c.uid) !== 'admin' && val !== null && typeof val === 'object') {
42
+ if (path === '' && !(0, admin_1.isAdmin)(req.user) && val !== null && typeof val === 'object') {
42
43
  // Non-admin user: remove any private properties from the update object
43
44
  Object.keys(val).filter(key => key.startsWith('__')).forEach(key => delete val[key]);
44
45
  }
@@ -62,7 +63,7 @@ const addRoute = (env) => {
62
63
  catch (err) {
63
64
  if (err instanceof rules_1.AccessRuleValidationError) {
64
65
  const access = err.result;
65
- env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_d = access.rulePath) !== null && _d !== void 0 ? _d : null, rule_error: (_f = (_e = access.details) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : null }));
66
+ env.log.error(LOG_ACTION, 'unauthorized', Object.assign(Object.assign({}, LOG_DETAILS), { rule_code: access.code, rule_path: (_c = access.rulePath) !== null && _c !== void 0 ? _c : null, rule_error: (_e = (_d = access.details) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : null }));
66
67
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
67
68
  }
68
69
  else if (err instanceof acebase_1.SchemaValidationError) {