@fonoster/common 0.8.64 → 0.9.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.
@@ -65,11 +65,11 @@ function createAuthInterceptor(identityPublicKey, publicPath) {
65
65
  logger.verbose("checking access for accessKeyId", {
66
66
  accessKeyId,
67
67
  path,
68
- hasAccess: (0, hasAccess_1.hasAccess)(decodedToken.access, path),
68
+ hasAccess: (0, hasAccess_1.hasAccess)(decodedToken, path),
69
69
  pathIsWorkspacePath: roles_1.workspaceAccess.includes(path),
70
70
  tokenHasAccessKeyId: (0, tokenHasAccessKeyId_1.tokenHasAccessKeyId)(token, accessKeyId)
71
71
  });
72
- if (!(0, hasAccess_1.hasAccess)(decodedToken.access, path) ||
72
+ if (!(0, hasAccess_1.hasAccess)(decodedToken, path) ||
73
73
  (roles_1.workspaceAccess.includes(path) &&
74
74
  !(0, tokenHasAccessKeyId_1.tokenHasAccessKeyId)(token, accessKeyId))) {
75
75
  return (0, errors_1.permissionDeniedError)(call);
@@ -1,3 +1,6 @@
1
1
  import { Access } from "./types";
2
- declare function hasAccess(access: Access[], method: string): boolean;
2
+ declare function hasAccess(decodedToken: {
3
+ access: Access[];
4
+ accessKeyId: string;
5
+ }, method: string): boolean;
3
6
  export { hasAccess };
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasAccess = hasAccess;
4
4
  const roles_1 = require("./roles");
5
5
  // This function only checks if the role has access to the grpc method
6
- function hasAccess(access, method) {
7
- const roleList = access.map((a) => a.role);
6
+ function hasAccess(decodedToken, method) {
7
+ const { access, accessKeyId } = decodedToken;
8
+ const roleList = accessKeyId.startsWith("US") // US is for user; user tokens only have USER role
9
+ ? [roles_1.USER_ROLE]
10
+ : access.map((a) => a.role);
8
11
  return roleList.some((r) => roles_1.roles.find((role) => role.name === r && role.access.includes(method)));
9
12
  }
@@ -1,5 +1,6 @@
1
1
  import { Role } from "./types";
2
2
  declare const VOICE_SERVICE_ROLE = "VOICE_SERVICE";
3
+ declare const USER_ROLE = "USER";
3
4
  declare const workspaceAccess: string[];
4
5
  declare const roles: Role[];
5
- export { VOICE_SERVICE_ROLE, roles, workspaceAccess };
6
+ export { USER_ROLE, VOICE_SERVICE_ROLE, roles, workspaceAccess };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.workspaceAccess = exports.roles = exports.VOICE_SERVICE_ROLE = void 0;
3
+ exports.workspaceAccess = exports.roles = exports.VOICE_SERVICE_ROLE = exports.USER_ROLE = void 0;
4
4
  /* eslint-disable sonarjs/no-duplicate-string */
5
5
  /*
6
6
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
@@ -23,6 +23,10 @@ exports.workspaceAccess = exports.roles = exports.VOICE_SERVICE_ROLE = void 0;
23
23
  const types_1 = require("@fonoster/types");
24
24
  const VOICE_SERVICE_ROLE = "VOICE_SERVICE";
25
25
  exports.VOICE_SERVICE_ROLE = VOICE_SERVICE_ROLE;
26
+ // The WorkspaceRoleEnum.USER is the same as the USER_ROLE constant
27
+ // We will split this two roles in the future
28
+ const USER_ROLE = "USER";
29
+ exports.USER_ROLE = USER_ROLE;
26
30
  const workspaceAccess = [
27
31
  "/fonoster.applications.v1beta2.Applications/CreateApplication",
28
32
  "/fonoster.applications.v1beta2.Applications/UpdateApplication",
@@ -101,7 +105,7 @@ const roles = [
101
105
  access: [...fullIdentityAccess, ...workspaceAccess]
102
106
  },
103
107
  {
104
- name: types_1.WorkspaceRoleEnum.USER,
108
+ name: USER_ROLE,
105
109
  description: "Access to User and Workspace endpoints",
106
110
  access: [
107
111
  "/fonoster.identity.v1beta2.Identity/GetUser",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/common",
3
- "version": "0.8.64",
3
+ "version": "0.9.3",
4
4
  "description": "Common library for Fonoster projects",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -18,7 +18,7 @@
18
18
  "clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
19
19
  },
20
20
  "dependencies": {
21
- "@fonoster/logger": "^0.8.59",
21
+ "@fonoster/logger": "^0.9.0",
22
22
  "@grpc/grpc-js": "~1.10.6",
23
23
  "@grpc/proto-loader": "^0.7.12",
24
24
  "@influxdata/influxdb-client": "^1.35.0",
@@ -48,5 +48,5 @@
48
48
  "devDependencies": {
49
49
  "@types/nodemailer": "^6.4.14"
50
50
  },
51
- "gitHead": "5f7a501c597926252e5fca8aa12818e2db70de16"
51
+ "gitHead": "b80bab4b14b87036525de21c90494a1b5c6fa02d"
52
52
  }