@fonoster/common 0.9.14 → 0.9.15

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.
@@ -66,11 +66,11 @@ function createAuthInterceptor(identityPublicKey, publicPath) {
66
66
  accessKeyId,
67
67
  path,
68
68
  hasAccess: (0, hasAccess_1.hasAccess)(decodedToken, path),
69
- pathIsWorkspacePath: roles_1.workspaceAccess.includes(path),
69
+ pathIsWorkspacePath: roles_1.workspaceResourceAccess.includes(path),
70
70
  tokenHasAccessKeyId: (0, tokenHasAccessKeyId_1.tokenHasAccessKeyId)(token, accessKeyId)
71
71
  });
72
72
  if (!(0, hasAccess_1.hasAccess)(decodedToken, path) ||
73
- (roles_1.workspaceAccess.includes(path) &&
73
+ (roles_1.workspaceResourceAccess.includes(path) &&
74
74
  !(0, tokenHasAccessKeyId_1.tokenHasAccessKeyId)(token, accessKeyId))) {
75
75
  return (0, errors_1.permissionDeniedError)(call);
76
76
  }
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasAccess = hasAccess;
4
+ /*
5
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const types_1 = require("@fonoster/types");
4
23
  const roles_1 = require("./roles");
5
24
  // This function only checks if the role has access to the grpc method
6
25
  function hasAccess(decodedToken, method) {
7
26
  const { access, accessKeyId } = decodedToken;
8
27
  const roleList = accessKeyId.startsWith("US") && // US is for user; user tokens only have USER role
9
28
  access.length === 0 // If it is a user token, and has no access, we still allow it in case it is a user method
10
- ? [roles_1.USER_ROLE]
29
+ ? [types_1.Role.USER]
11
30
  : access.map((a) => a.role);
12
31
  return roleList.some((r) => roles_1.roles.find((role) => role.name === r && role.access.includes(method)));
13
32
  }
@@ -1,6 +1,5 @@
1
- import { Role } from "./types";
1
+ import { RoleType } from "./types";
2
2
  declare const VOICE_SERVICE_ROLE = "VOICE_SERVICE";
3
- declare const USER_ROLE = "USER";
4
- declare const workspaceAccess: string[];
5
- declare const roles: Role[];
6
- export { USER_ROLE, VOICE_SERVICE_ROLE, roles, workspaceAccess };
3
+ declare const workspaceResourceAccess: string[];
4
+ declare const roles: RoleType[];
5
+ export { VOICE_SERVICE_ROLE, roles, workspaceResourceAccess };
@@ -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 = exports.USER_ROLE = void 0;
3
+ exports.workspaceResourceAccess = exports.roles = exports.VOICE_SERVICE_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,11 +23,7 @@ exports.workspaceAccess = exports.roles = exports.VOICE_SERVICE_ROLE = exports.U
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 WorkspaceRole.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;
30
- const workspaceAccess = [
26
+ const workspaceResourceAccess = [
31
27
  "/fonoster.applications.v1beta2.Applications/CreateApplication",
32
28
  "/fonoster.applications.v1beta2.Applications/UpdateApplication",
33
29
  "/fonoster.applications.v1beta2.Applications/GetApplication",
@@ -74,7 +70,7 @@ const workspaceAccess = [
74
70
  "/fonoster.calls.v1beta2.Calls/TrackCall",
75
71
  "/fonoster.voice.v1beta2.Voice/CreateSession"
76
72
  ];
77
- exports.workspaceAccess = workspaceAccess;
73
+ exports.workspaceResourceAccess = workspaceResourceAccess;
78
74
  const fullIdentityAccess = [
79
75
  "/fonoster.identity.v1beta2.Identity/GetUser",
80
76
  "/fonoster.identity.v1beta2.Identity/UpdateUser",
@@ -96,17 +92,7 @@ const fullIdentityAccess = [
96
92
  ];
97
93
  const roles = [
98
94
  {
99
- name: types_1.WorkspaceRole.OWNER,
100
- description: "Access to all endpoints",
101
- access: [...fullIdentityAccess, ...workspaceAccess]
102
- },
103
- {
104
- name: types_1.WorkspaceRole.ADMIN,
105
- description: "Access to all endpoints",
106
- access: [...fullIdentityAccess, ...workspaceAccess]
107
- },
108
- {
109
- name: USER_ROLE,
95
+ name: types_1.Role.USER,
110
96
  description: "Access to User and Workspace endpoints",
111
97
  access: [
112
98
  "/fonoster.identity.v1beta2.Identity/GetUser",
@@ -117,13 +103,27 @@ const roles = [
117
103
  "/fonoster.identity.v1beta2.Identity/UpdateWorkspace",
118
104
  "/fonoster.identity.v1beta2.Identity/ListWorkspaces",
119
105
  "/fonoster.identity.v1beta2.Identity/RefreshToken",
120
- ...workspaceAccess
106
+ ...workspaceResourceAccess
121
107
  ]
122
108
  },
123
109
  {
124
- name: types_1.ApiRole.WORKSPACE_ADMIN,
110
+ name: types_1.Role.WORKSPACE_OWNER,
111
+ description: "Access to all endpoints",
112
+ access: [...fullIdentityAccess, ...workspaceResourceAccess]
113
+ },
114
+ {
115
+ name: types_1.Role.WORKSPACE_ADMIN,
125
116
  description: "Access to all endpoints",
126
- access: [...fullIdentityAccess, ...workspaceAccess]
117
+ access: [...fullIdentityAccess, ...workspaceResourceAccess]
118
+ },
119
+ {
120
+ name: types_1.Role.WORKSPACE_MEMBER,
121
+ description: "Access to User and Workspace endpoints",
122
+ access: [
123
+ "/fonoster.identity.v1beta2.Identity/GetWorkspace",
124
+ "/fonoster.identity.v1beta2.Identity/ListWorkspaces",
125
+ ...workspaceResourceAccess
126
+ ]
127
127
  },
128
128
  {
129
129
  name: VOICE_SERVICE_ROLE,
@@ -1,4 +1,4 @@
1
- import { WorkspaceRole } from "@fonoster/types";
1
+ import { Role } from "@fonoster/types";
2
2
  declare enum TokenUseEnum {
3
3
  ID = "id",
4
4
  ACCESS = "access",
@@ -8,14 +8,14 @@ declare enum JsonWebErrorEnum {
8
8
  JsonWebTokenError = "JsonWebTokenError",
9
9
  TokenExpiredError = "TokenExpiredError"
10
10
  }
11
- type Role = {
11
+ type RoleType = {
12
12
  name: string;
13
13
  description: string;
14
14
  access: string[];
15
15
  };
16
16
  type Access = {
17
17
  accessKeyId: string;
18
- role: WorkspaceRole;
18
+ role: Role;
19
19
  };
20
20
  type BaseToken = {
21
21
  iss: string;
@@ -41,4 +41,4 @@ type RefreshToken = BaseToken & {
41
41
  tokenUse: TokenUseEnum.REFRESH;
42
42
  };
43
43
  type DecodedToken<T extends TokenUseEnum> = T extends TokenUseEnum.ID ? IdToken : T extends TokenUseEnum.ACCESS ? AccessToken : T extends TokenUseEnum.REFRESH ? TokenUseEnum : never;
44
- export { Access, AccessToken, DecodedToken, IdToken, RefreshToken, Role, TokenUseEnum, JsonWebErrorEnum };
44
+ export { Access, AccessToken, DecodedToken, IdToken, RefreshToken, RoleType, TokenUseEnum, JsonWebErrorEnum };
@@ -1,4 +1,4 @@
1
- import { ApiRole, WorkspaceRole } from "@fonoster/types";
1
+ import { Role } from "@fonoster/types";
2
2
  import { z } from "zod";
3
3
  declare const createWorkspaceRequestSchema: z.ZodObject<{
4
4
  name: z.ZodString;
@@ -8,13 +8,13 @@ declare const createWorkspaceRequestSchema: z.ZodObject<{
8
8
  name?: string;
9
9
  }>;
10
10
  declare const createApiKeyRequestSchema: z.ZodObject<{
11
- role: z.ZodEnum<[ApiRole]>;
11
+ role: z.ZodEnum<[Role.WORKSPACE_ADMIN]>;
12
12
  expiresAt: z.ZodOptional<z.ZodNumber>;
13
13
  }, "strip", z.ZodTypeAny, {
14
- role?: ApiRole;
14
+ role?: Role.WORKSPACE_ADMIN;
15
15
  expiresAt?: number;
16
16
  }, {
17
- role?: ApiRole;
17
+ role?: Role.WORKSPACE_ADMIN;
18
18
  expiresAt?: number;
19
19
  }>;
20
20
  declare const exchangeApiKeysRequestSchema: z.ZodObject<{
@@ -92,16 +92,16 @@ declare const updateUserRequestSchema: z.ZodObject<{
92
92
  declare const inviteUserToWorkspaceRequestSchema: z.ZodObject<{
93
93
  email: z.ZodString;
94
94
  name: z.ZodString;
95
- role: z.ZodEnum<[WorkspaceRole.ADMIN, WorkspaceRole.USER]>;
95
+ role: z.ZodEnum<[Role.WORKSPACE_ADMIN, Role.WORKSPACE_MEMBER]>;
96
96
  password: z.ZodUnion<[z.ZodString, z.ZodUndefined]>;
97
97
  }, "strip", z.ZodTypeAny, {
98
98
  name?: string;
99
- role?: WorkspaceRole.ADMIN | WorkspaceRole.USER;
99
+ role?: Role.WORKSPACE_ADMIN | Role.WORKSPACE_MEMBER;
100
100
  password?: string;
101
101
  email?: string;
102
102
  }, {
103
103
  name?: string;
104
- role?: WorkspaceRole.ADMIN | WorkspaceRole.USER;
104
+ role?: Role.WORKSPACE_ADMIN | Role.WORKSPACE_MEMBER;
105
105
  password?: string;
106
106
  email?: string;
107
107
  }>;
@@ -36,7 +36,7 @@ const createWorkspaceRequestSchema = zod_1.z.object({
36
36
  });
37
37
  exports.createWorkspaceRequestSchema = createWorkspaceRequestSchema;
38
38
  const createApiKeyRequestSchema = zod_1.z.object({
39
- role: zod_1.z.enum([types_1.ApiRole.WORKSPACE_ADMIN]),
39
+ role: zod_1.z.enum([types_1.Role.WORKSPACE_ADMIN]),
40
40
  expiresAt: zod_1.z
41
41
  .number()
42
42
  .int({ message: messages_1.POSITIVE_INTEGER_MESSAGE })
@@ -89,7 +89,7 @@ exports.updateUserRequestSchema = updateUserRequestSchema;
89
89
  const inviteUserToWorkspaceRequestSchema = zod_1.z.object({
90
90
  email: zod_1.z.string().email({ message: EMAIL_MESSAGE }),
91
91
  name: zod_1.z.string().max(50, { message: MAX_NAME_MESSAGE }),
92
- role: zod_1.z.enum([types_1.WorkspaceRole.ADMIN, types_1.WorkspaceRole.USER]),
92
+ role: zod_1.z.enum([types_1.Role.WORKSPACE_ADMIN, types_1.Role.WORKSPACE_MEMBER]),
93
93
  password: zod_1.z.string().min(8, { message: PASSWORD_MESSAGE }).or(zod_1.z.undefined())
94
94
  });
95
95
  exports.inviteUserToWorkspaceRequestSchema = inviteUserToWorkspaceRequestSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/common",
3
- "version": "0.9.14",
3
+ "version": "0.9.15",
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",
@@ -48,5 +48,5 @@
48
48
  "devDependencies": {
49
49
  "@types/nodemailer": "^6.4.14"
50
50
  },
51
- "gitHead": "ba1b5e9898fafef1d3c4d3f1e72d3c2326fcec7b"
51
+ "gitHead": "82708d0237fb1cd19a8188ee3f1c99d450a2c116"
52
52
  }