@lowdefy/api 4.7.1 → 4.7.3

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.
@@ -18,6 +18,11 @@ function createAuthorize({ session }) {
18
18
  // else session will be null
19
19
  const authenticated = !!session;
20
20
  const roles = session?.user?.roles ?? [];
21
+ if (!Array.isArray(roles)) {
22
+ throw new ConfigError('session.user.roles must be an array of strings.', {
23
+ received: roles
24
+ });
25
+ }
21
26
  function authorize(config) {
22
27
  const { auth } = config;
23
28
  if (auth.public === true) return true;
@@ -15,6 +15,7 @@
15
15
  */ import crypto from 'crypto';
16
16
  import addUserFieldsToSession from './addUserFieldsToSession.js';
17
17
  import createCallbackPlugins from './createCallbackPlugins.js';
18
+ import validateSessionRoles from './validateSessionRoles.js';
18
19
  function createSessionCallback({ authConfig, plugins }) {
19
20
  const sessionCallbackPlugins = createCallbackPlugins({
20
21
  authConfig,
@@ -67,6 +68,9 @@ function createSessionCallback({ authConfig, plugins }) {
67
68
  user
68
69
  });
69
70
  }
71
+ validateSessionRoles({
72
+ session
73
+ });
70
74
  // TODO: Should this be session.hashed_id or session.user.hashed_id
71
75
  // Only session.user will be available using the _user operator
72
76
  session.hashed_id = crypto.createHash('sha256').update(identifier ?? '').digest('base64');
@@ -0,0 +1,33 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
+ import { type } from '@lowdefy/helpers';
17
+ function validateSessionRoles({ session }) {
18
+ const roles = session?.user?.roles;
19
+ if (type.isNone(roles)) return;
20
+ if (!Array.isArray(roles)) {
21
+ throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
22
+ received: roles
23
+ });
24
+ }
25
+ for (const role of roles){
26
+ if (!type.isString(role)) {
27
+ throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
28
+ received: roles
29
+ });
30
+ }
31
+ }
32
+ }
33
+ export default validateSessionRoles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/api",
3
- "version": "4.7.1",
3
+ "version": "4.7.3",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -34,13 +34,13 @@
34
34
  "dist/*"
35
35
  ],
36
36
  "dependencies": {
37
- "@lowdefy/ajv": "4.7.1",
38
- "@lowdefy/errors": "4.7.1",
39
- "@lowdefy/helpers": "4.7.1",
40
- "@lowdefy/node-utils": "4.7.1",
41
- "@lowdefy/nunjucks": "4.7.1",
42
- "@lowdefy/operators": "4.7.1",
43
- "@lowdefy/operators-js": "4.7.1"
37
+ "@lowdefy/ajv": "4.7.3",
38
+ "@lowdefy/errors": "4.7.3",
39
+ "@lowdefy/helpers": "4.7.3",
40
+ "@lowdefy/node-utils": "4.7.3",
41
+ "@lowdefy/nunjucks": "4.7.3",
42
+ "@lowdefy/operators": "4.7.3",
43
+ "@lowdefy/operators-js": "4.7.3"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "28.1.3",