@fonoster/identity 0.7.22 → 0.7.26

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 (78) hide show
  1. package/dist/apikeys/deleteApiKey.js +1 -1
  2. package/dist/apikeys/regenerateApiKey.js +1 -1
  3. package/dist/constants.d.ts +2 -0
  4. package/dist/{invites/EmailTemplatesEnum.js → constants.js} +3 -6
  5. package/dist/envs.d.ts +7 -0
  6. package/dist/envs.js +24 -3
  7. package/dist/exchanges/exchangeApiKey.js +17 -7
  8. package/dist/exchanges/exchangeCredentials.js +45 -10
  9. package/dist/exchanges/exchangeOauth2Code.d.ts +7 -0
  10. package/dist/exchanges/exchangeOauth2Code.js +105 -0
  11. package/dist/exchanges/exchangeRefreshToken.js +2 -2
  12. package/dist/exchanges/exchangeTokens.js +17 -7
  13. package/dist/exchanges/index.d.ts +1 -0
  14. package/dist/exchanges/index.js +1 -0
  15. package/dist/exchanges/payloads/users/getAccessTokenPayload.js +5 -4
  16. package/dist/exchanges/types.d.ts +11 -1
  17. package/dist/getPublicKeyClient.js +17 -7
  18. package/dist/invites/createInviteBody.d.ts +2 -7
  19. package/dist/invites/createInviteBody.js +5 -5
  20. package/dist/invites/index.d.ts +2 -1
  21. package/dist/invites/index.js +2 -1
  22. package/dist/invites/sendInvite.d.ts +2 -9
  23. package/dist/invites/sendInvite.js +2 -1
  24. package/dist/invites/types.d.ts +11 -0
  25. package/dist/invites/types.js +2 -0
  26. package/dist/service.d.ts +9 -0
  27. package/dist/service.js +7 -1
  28. package/dist/templates/TemplatesEnum.d.ts +7 -0
  29. package/dist/templates/TemplatesEnum.js +28 -0
  30. package/dist/templates/verifyEmail.hbs +39 -0
  31. package/dist/templates/verifyPhone.hbs +3 -0
  32. package/dist/users/deleteUser.js +1 -1
  33. package/dist/users/getUser.js +1 -1
  34. package/dist/users/upsertDefaultUser.js +14 -3
  35. package/dist/utils/createCallAccessToken.js +2 -2
  36. package/dist/utils/createGenerateVerificationCode.d.ts +7 -0
  37. package/dist/utils/createGenerateVerificationCode.js +28 -0
  38. package/dist/utils/createIsUserContactVerified.d.ts +3 -0
  39. package/dist/utils/createIsUserContactVerified.js +25 -0
  40. package/dist/utils/createIsValidVerificationCode.d.ts +8 -0
  41. package/dist/utils/createIsValidVerificationCode.js +34 -0
  42. package/dist/{workspaces → utils}/createSendEmail.js +1 -1
  43. package/dist/utils/createWorkspaceInviteToken.d.ts +8 -0
  44. package/dist/utils/createWorkspaceInviteToken.js +54 -0
  45. package/dist/utils/getApiKeyByAccessKeyId.d.ts +4 -4
  46. package/dist/utils/getUserByEmail.d.ts +5 -5
  47. package/dist/utils/index.d.ts +2 -0
  48. package/dist/utils/index.js +4 -2
  49. package/dist/utils/updateMembershipStatus.d.ts +3 -0
  50. package/dist/utils/updateMembershipStatus.js +51 -0
  51. package/dist/utils/withAccess.js +17 -7
  52. package/dist/verification/createBodyForVerificationEmail.d.ts +3 -0
  53. package/dist/verification/createBodyForVerificationEmail.js +39 -0
  54. package/dist/verification/createBodyForVerificationMessage.d.ts +3 -0
  55. package/dist/verification/createBodyForVerificationMessage.js +39 -0
  56. package/dist/verification/createSendVerificationCode.d.ts +7 -0
  57. package/dist/verification/createSendVerificationCode.js +63 -0
  58. package/dist/verification/createVerifyCode.d.ts +6 -0
  59. package/dist/verification/createVerifyCode.js +67 -0
  60. package/dist/verification/index.d.ts +6 -0
  61. package/dist/verification/index.js +40 -0
  62. package/dist/verification/sendVerificationEmail.d.ts +4 -0
  63. package/dist/verification/sendVerificationEmail.js +26 -0
  64. package/dist/verification/sendVerificationMessage.d.ts +4 -0
  65. package/dist/verification/sendVerificationMessage.js +25 -0
  66. package/dist/verification/types.d.ts +23 -0
  67. package/dist/verification/types.js +8 -0
  68. package/dist/workspaces/deleteWorkspace.js +1 -1
  69. package/dist/workspaces/getWorkspace.js +1 -1
  70. package/dist/workspaces/inviteUserToWorkspace.d.ts +1 -1
  71. package/dist/workspaces/inviteUserToWorkspace.js +11 -5
  72. package/dist/workspaces/resendWorkspaceMembershipInvitation.d.ts +1 -1
  73. package/dist/workspaces/resendWorkspaceMembershipInvitation.js +10 -4
  74. package/package.json +7 -6
  75. package/dist/invites/EmailTemplatesEnum.d.ts +0 -5
  76. /package/dist/{invites/templates → templates}/inviteExistingUser.hbs +0 -0
  77. /package/dist/{invites/templates → templates}/inviteNewUser.hbs +0 -0
  78. /package/dist/{workspaces → utils}/createSendEmail.d.ts +0 -0
@@ -43,5 +43,5 @@ function deleteApiKey(prisma) {
43
43
  });
44
44
  callback(null, { ref });
45
45
  });
46
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
46
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
47
47
  }
@@ -51,5 +51,5 @@ function regenerateApiKey(prisma) {
51
51
  accessKeySecret: response.accessKeySecret
52
52
  });
53
53
  });
54
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
54
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
55
55
  }
@@ -0,0 +1,2 @@
1
+ export declare const SIGN_ALGORITHM = "RS256";
2
+ export declare const VERIFICATION_CODE_EXPIRATION: number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailTemplatesEnum = void 0;
3
+ exports.VERIFICATION_CODE_EXPIRATION = exports.SIGN_ALGORITHM = void 0;
4
4
  /*
5
5
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -19,8 +19,5 @@ exports.EmailTemplatesEnum = void 0;
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
- var EmailTemplatesEnum;
23
- (function (EmailTemplatesEnum) {
24
- EmailTemplatesEnum["INVITE_NEW_USER"] = "inviteNewUser";
25
- EmailTemplatesEnum["INVITE_EXISTING_USER"] = "inviteExistingUser";
26
- })(EmailTemplatesEnum || (exports.EmailTemplatesEnum = EmailTemplatesEnum = {}));
22
+ exports.SIGN_ALGORITHM = "RS256";
23
+ exports.VERIFICATION_CODE_EXPIRATION = 5 * 60 * 1000;
package/dist/envs.d.ts CHANGED
@@ -1 +1,8 @@
1
1
  export declare const CLOAK_ENCRYPTION_KEY: string;
2
+ export declare const IDENTITY_MFA_REQUIRED: boolean;
3
+ export declare const IDENTITY_OAUTH2_GITHUB_CLIENT_ID: string;
4
+ export declare const IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET: string;
5
+ export declare const IDENTITY_OAUTH2_GITHUB_ENABLED: boolean;
6
+ export declare const IDENTITY_USER_VERIFICATION_REQUIRED: boolean;
7
+ export declare const IDENTITY_WORKSPACE_INVITATION_URL: string;
8
+ export declare const IDENTITY_WORKSPACE_INVITE_EXPIRATION: string;
package/dist/envs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLOAK_ENCRYPTION_KEY = void 0;
3
+ exports.IDENTITY_WORKSPACE_INVITE_EXPIRATION = exports.IDENTITY_WORKSPACE_INVITATION_URL = exports.IDENTITY_USER_VERIFICATION_REQUIRED = exports.IDENTITY_OAUTH2_GITHUB_ENABLED = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = exports.IDENTITY_MFA_REQUIRED = exports.CLOAK_ENCRYPTION_KEY = void 0;
4
4
  /*
5
5
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/fonoster
@@ -20,5 +20,26 @@ exports.CLOAK_ENCRYPTION_KEY = void 0;
20
20
  * limitations under the License.
21
21
  */
22
22
  const common_1 = require("@fonoster/common");
23
- (0, common_1.assertEnvsAreSet)(["CLOAK_ENCRYPTION_KEY"]);
24
- exports.CLOAK_ENCRYPTION_KEY = process.env.CLOAK_ENCRYPTION_KEY;
23
+ const e = process.env;
24
+ exports.CLOAK_ENCRYPTION_KEY = e.CLOAK_ENCRYPTION_KEY;
25
+ exports.IDENTITY_MFA_REQUIRED = e.IDENTITY_MFA_REQUIRED === "true";
26
+ exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = e.IDENTITY_OAUTH2_GITHUB_CLIENT_ID;
27
+ exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = e.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET;
28
+ exports.IDENTITY_OAUTH2_GITHUB_ENABLED = e.IDENTITY_OAUTH2_GITHUB_ENABLED === "true";
29
+ exports.IDENTITY_USER_VERIFICATION_REQUIRED = e.IDENTITY_USER_VERIFICATION_REQUIRED === "true";
30
+ exports.IDENTITY_WORKSPACE_INVITATION_URL = e.IDENTITY_WORKSPACE_INVITATION_URL;
31
+ exports.IDENTITY_WORKSPACE_INVITE_EXPIRATION = e.IDENTITY_WORKSPACE_INVITE_EXPIRATION || "1d";
32
+ (0, common_1.assertEnvsAreSet)(["CLOAK_ENCRYPTION_KEY", "IDENTITY_WORKSPACE_INVITATION_URL"]);
33
+ if (exports.IDENTITY_USER_VERIFICATION_REQUIRED) {
34
+ (0, common_1.assertEnvsAreSet)([
35
+ "TWILIO_ACCOUNT_SID",
36
+ "TWILIO_AUTH_TOKEN",
37
+ "TWILIO_PHONE_NUMBER"
38
+ ]);
39
+ }
40
+ if (exports.IDENTITY_OAUTH2_GITHUB_ENABLED) {
41
+ (0, common_1.assertEnvsAreSet)([
42
+ "IDENTITY_OAUTH2_GITHUB_CLIENT_ID",
43
+ "IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET"
44
+ ]);
45
+ }
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -55,20 +65,45 @@ const common_1 = require("@fonoster/common");
55
65
  const logger_1 = require("@fonoster/logger");
56
66
  const grpc = __importStar(require("@grpc/grpc-js"));
57
67
  const exchangeTokens_1 = require("./exchangeTokens");
68
+ const envs_1 = require("../envs");
69
+ const createIsValidVerificationCode_1 = require("../utils/createIsValidVerificationCode");
58
70
  const getUserByEmail_1 = require("../utils/getUserByEmail");
71
+ const verification_1 = require("../verification");
59
72
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
73
+ const verificationRequiredButNotProvided = (user) => envs_1.IDENTITY_USER_VERIFICATION_REQUIRED &&
74
+ (!user.emailVerified || !user.phoneNumberVerified);
60
75
  function exchangeCredentials(prisma, identityConfig) {
76
+ const isValidVerificationCode = (0, createIsValidVerificationCode_1.createIsValidVerificationCode)(prisma);
61
77
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
62
78
  const { request } = call;
63
- const { username, password } = request;
64
- logger.verbose("call to exchangeCredentials", { username });
65
- const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(username);
79
+ const { username: email, password, verificationCode } = request;
80
+ logger.verbose("call to exchangeCredentials", { username: email });
81
+ const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(email);
66
82
  if (!user || user.password !== (password === null || password === void 0 ? void 0 : password.trim())) {
67
83
  return callback({
68
84
  code: grpc.status.PERMISSION_DENIED,
69
85
  message: "Invalid credentials"
70
86
  });
71
87
  }
88
+ if (verificationRequiredButNotProvided(user)) {
89
+ return callback({
90
+ code: grpc.status.PERMISSION_DENIED,
91
+ message: "User contact information not verified"
92
+ });
93
+ }
94
+ if (envs_1.IDENTITY_USER_VERIFICATION_REQUIRED) {
95
+ const isValid = yield isValidVerificationCode({
96
+ type: verification_1.ContactType.EMAIL,
97
+ value: email,
98
+ code: verificationCode
99
+ });
100
+ if (!isValid) {
101
+ return callback({
102
+ code: grpc.status.PERMISSION_DENIED,
103
+ message: "Invalid verification code"
104
+ });
105
+ }
106
+ }
72
107
  callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
73
108
  });
74
109
  return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeCredentialsRequestSchema);
@@ -0,0 +1,7 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { IdentityConfig } from "./types";
3
+ import { Prisma } from "../db";
4
+ declare function exchangeOauth2Code(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
+ request: unknown;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
+ export { exchangeOauth2Code };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.exchangeOauth2Code = exchangeOauth2Code;
46
+ /*
47
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
48
+ * http://github.com/fonoster/fonoster
49
+ *
50
+ * This file is part of Fonoster
51
+ *
52
+ * Licensed under the MIT License (the "License");
53
+ * you may not use this file except in compliance with
54
+ * the License. You may obtain a copy of the License at
55
+ *
56
+ * https://opensource.org/licenses/MIT
57
+ *
58
+ * Unless required by applicable law or agreed to in writing, software
59
+ * distributed under the License is distributed on an "AS IS" BASIS,
60
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61
+ * See the License for the specific language governing permissions and
62
+ * limitations under the License.
63
+ */
64
+ const common_1 = require("@fonoster/common");
65
+ const logger_1 = require("@fonoster/logger");
66
+ const grpc = __importStar(require("@grpc/grpc-js"));
67
+ const exchangeTokens_1 = require("./exchangeTokens");
68
+ const getUserByEmail_1 = require("../utils/getUserByEmail");
69
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
70
+ function exchangeOauth2Code(prisma, identityConfig) {
71
+ const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
72
+ const { request } = call;
73
+ const { provider, username: email, code } = request;
74
+ logger.verbose("call to exchangeOauth2Code", { provider });
75
+ const tokenResponse = yield fetch("https://github.com/login/oauth/access_token", {
76
+ method: "POST",
77
+ headers: {
78
+ "Content-Type": "application/json",
79
+ Accept: "application/json"
80
+ },
81
+ body: JSON.stringify({
82
+ client_id: identityConfig.githubOauth2Config.clientId,
83
+ client_secret: identityConfig.githubOauth2Config.clientSecret,
84
+ code
85
+ })
86
+ });
87
+ const tokenData = yield tokenResponse.json();
88
+ const accessToken = tokenData === null || tokenData === void 0 ? void 0 : tokenData.access_token;
89
+ const userResponse = yield fetch("https://api.github.com/user", {
90
+ headers: {
91
+ Authorization: `token ${accessToken}`
92
+ }
93
+ });
94
+ const userData = yield userResponse.json();
95
+ const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(email);
96
+ if (userData.email !== email || !user) {
97
+ return callback({
98
+ code: grpc.status.PERMISSION_DENIED,
99
+ message: "Invalid credentials"
100
+ });
101
+ }
102
+ callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
103
+ });
104
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeOauth2RequestSchema);
105
+ }
@@ -35,15 +35,15 @@ const common_1 = require("@fonoster/common");
35
35
  const logger_1 = require("@fonoster/logger");
36
36
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
37
37
  const exchangeTokens_1 = require("./exchangeTokens");
38
+ const constants_1 = require("../constants");
38
39
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
39
- const SIGN_ALGORITHM = "RS256";
40
40
  function exchangeRefreshToken(prisma, identityConfig) {
41
41
  const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
42
42
  const { privateKey } = identityConfig;
43
43
  const { request } = call;
44
44
  const { refreshToken: oldRefreshToken } = request;
45
45
  const oldRefreshTokenDecoded = jsonwebtoken_1.default.verify(oldRefreshToken, privateKey, {
46
- algorithms: [SIGN_ALGORITHM]
46
+ algorithms: [constants_1.SIGN_ALGORITHM]
47
47
  });
48
48
  const { accessKeyId } = oldRefreshTokenDecoded;
49
49
  logger.verbose("call to exchangeRefreshToken", { accessKeyId });
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -1,5 +1,6 @@
1
1
  export * from "./TokenUseEnum";
2
2
  export * from "./exchangeApiKey";
3
3
  export * from "./exchangeCredentials";
4
+ export * from "./exchangeOauth2Code";
4
5
  export * from "./exchangeRefreshToken";
5
6
  export * from "./types";
@@ -35,5 +35,6 @@ __exportStar(require("./TokenUseEnum"), exports);
35
35
  */
36
36
  __exportStar(require("./exchangeApiKey"), exports);
37
37
  __exportStar(require("./exchangeCredentials"), exports);
38
+ __exportStar(require("./exchangeOauth2Code"), exports);
38
39
  __exportStar(require("./exchangeRefreshToken"), exports);
39
40
  __exportStar(require("./types"), exports);
@@ -55,10 +55,11 @@ function getAccessTokenPayload(prisma, identityConfig) {
55
55
  role: types_1.WorkspaceRoleEnum.OWNER
56
56
  }));
57
57
  memberships.forEach((membership) => {
58
- access.push({
59
- accessKeyId: membership.workspace.accessKeyId,
60
- role: membership.role
61
- });
58
+ membership.status === types_1.WorkspaceMemberStatus.ACTIVE &&
59
+ access.push({
60
+ accessKeyId: membership.workspace.accessKeyId,
61
+ role: membership.role
62
+ });
62
63
  });
63
64
  return {
64
65
  iss: issuer,
@@ -53,9 +53,19 @@ type IdentityConfig = {
53
53
  pass: string;
54
54
  };
55
55
  };
56
+ twilioSmsConfig?: {
57
+ accountSid: string;
58
+ authToken: string;
59
+ sender: string;
60
+ };
61
+ githubOauth2Config?: {
62
+ clientId: string;
63
+ clientSecret: string;
64
+ };
56
65
  };
57
66
  type DecodedToken<T extends TokenUseEnum> = T extends TokenUseEnum.ID ? IdToken : T extends TokenUseEnum.ACCESS ? AccessToken : T extends TokenUseEnum.REFRESH ? TokenUseEnum : never;
58
67
  type ExchangeApiKeysRequest = z.infer<typeof V.exchangeApiKeysRequestSchema>;
68
+ type ExchangeOauth2CodeRequest = z.infer<typeof V.exchangeOauth2RequestSchema>;
59
69
  type ExchangeCredentialsRequest = z.infer<typeof V.exchangeCredentialsRequestSchema>;
60
70
  type ExchangeResponse = {
61
71
  idToken: string;
@@ -63,4 +73,4 @@ type ExchangeResponse = {
63
73
  refreshToken: string;
64
74
  };
65
75
  type ExchangeRefreshTokenRequest = z.infer<typeof V.exchangeRefreshTokenRequestSchema>;
66
- export { Access, AccessToken, DecodedToken, ExchangeApiKeysRequest, ExchangeCredentialsRequest, ExchangeRefreshTokenRequest, ExchangeResponse, IdToken, IdentityConfig, RefreshToken, Role };
76
+ export { Access, AccessToken, DecodedToken, ExchangeApiKeysRequest, ExchangeCredentialsRequest, ExchangeOauth2CodeRequest, ExchangeRefreshTokenRequest, ExchangeResponse, IdToken, IdentityConfig, RefreshToken, Role };
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.getPublicKeyClient = getPublicKeyClient;
27
37
  /*
@@ -1,8 +1,3 @@
1
- declare function createInviteBody(params: {
2
- emailTemplateDir?: string;
3
- isExistingUser: boolean;
4
- workspaceName: string;
5
- oneTimePassword: string;
6
- inviteUrl: string;
7
- }): string;
1
+ import { InviteParams } from "./types";
2
+ declare function createInviteBody(params: Omit<InviteParams, "recipient">): string;
8
3
  export { createInviteBody };
@@ -24,13 +24,13 @@ exports.createInviteBody = createInviteBody;
24
24
  */
25
25
  const path_1 = __importDefault(require("path"));
26
26
  const common_1 = require("@fonoster/common");
27
- const EmailTemplatesEnum_1 = require("./EmailTemplatesEnum");
27
+ const TemplatesEnum_1 = require("../templates/TemplatesEnum");
28
28
  function createInviteBody(params) {
29
- const { emailTemplateDir, isExistingUser, workspaceName, oneTimePassword, inviteUrl } = params;
29
+ const { templateDir: emailTemplateDir, isExistingUser, workspaceName, oneTimePassword, inviteUrl } = params;
30
30
  const template = isExistingUser
31
- ? EmailTemplatesEnum_1.EmailTemplatesEnum.INVITE_EXISTING_USER
32
- : EmailTemplatesEnum_1.EmailTemplatesEnum.INVITE_NEW_USER;
33
- const templateDir = emailTemplateDir || path_1.default.join(__dirname, "templates");
31
+ ? TemplatesEnum_1.TemplatesEnum.INVITE_EXISTING_USER
32
+ : TemplatesEnum_1.TemplatesEnum.INVITE_NEW_USER;
33
+ const templateDir = emailTemplateDir || path_1.default.join(__dirname, "..", "templates");
34
34
  const templatePath = `${templateDir}/${template}.hbs`;
35
35
  return (0, common_1.compileTemplate)({
36
36
  filePath: templatePath,
@@ -1,3 +1,4 @@
1
- export * from "./EmailTemplatesEnum";
1
+ export * from "../templates/TemplatesEnum";
2
2
  export * from "./createInviteBody";
3
3
  export * from "./sendInvite";
4
+ export * from "./types";
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./EmailTemplatesEnum"), exports);
18
17
  /*
19
18
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
20
19
  * http://github.com/fonoster/fonoster
@@ -33,5 +32,7 @@ __exportStar(require("./EmailTemplatesEnum"), exports);
33
32
  * See the License for the specific language governing permissions and
34
33
  * limitations under the License.
35
34
  */
35
+ __exportStar(require("../templates/TemplatesEnum"), exports);
36
36
  __exportStar(require("./createInviteBody"), exports);
37
37
  __exportStar(require("./sendInvite"), exports);
38
+ __exportStar(require("./types"), exports);
@@ -1,11 +1,4 @@
1
1
  import { EmailParams } from "@fonoster/common";
2
- type InviteParams = {
3
- recipient: string;
4
- inviteUrl: string;
5
- oneTimePassword?: string;
6
- workspaceName: string;
7
- isExistingUser: boolean;
8
- };
9
- type SendInvite = (sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams) => Promise<void>;
2
+ import { InviteParams } from "./types";
10
3
  declare function sendInvite(sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams): Promise<void>;
11
- export { InviteParams, SendInvite, sendInvite };
4
+ export { sendInvite };
@@ -13,11 +13,12 @@ exports.sendInvite = sendInvite;
13
13
  const createInviteBody_1 = require("./createInviteBody");
14
14
  function sendInvite(sendEmail, request) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- const { recipient, inviteUrl, oneTimePassword, isExistingUser, workspaceName } = request;
16
+ const { recipient, inviteUrl, oneTimePassword, isExistingUser, workspaceName, templateDir } = request;
17
17
  yield sendEmail({
18
18
  to: recipient,
19
19
  subject: "Invite to join a Fonoster workspace",
20
20
  html: (0, createInviteBody_1.createInviteBody)({
21
+ templateDir,
21
22
  isExistingUser,
22
23
  workspaceName,
23
24
  oneTimePassword: isExistingUser ? undefined : oneTimePassword,
@@ -0,0 +1,11 @@
1
+ import { EmailParams } from "@fonoster/common";
2
+ type InviteParams = {
3
+ recipient: string;
4
+ templateDir?: string;
5
+ inviteUrl: string;
6
+ isExistingUser: boolean;
7
+ oneTimePassword?: string;
8
+ workspaceName: string;
9
+ };
10
+ type SendInvite = (sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams) => Promise<void>;
11
+ export { InviteParams, SendInvite };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/service.d.ts CHANGED
@@ -67,12 +67,21 @@ declare function buildIdentityService(identityConfig: IdentityConfig): {
67
67
  exchangeCredentials: (call: {
68
68
  request: unknown;
69
69
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
70
+ exchangeOauth2Code: (call: {
71
+ request: unknown;
72
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
70
73
  exchangeRefreshToken: (call: {
71
74
  request: unknown;
72
75
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
73
76
  getPublicKey: (_: unknown, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: {
74
77
  publicKey: string;
75
78
  }) => void) => Promise<void>;
79
+ sendVerificationCode: (call: {
80
+ request: unknown;
81
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
82
+ verifyCode: (call: {
83
+ request: unknown;
84
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
76
85
  };
77
86
  };
78
87
  export { buildIdentityService, serviceDefinitionParams };
package/dist/service.js CHANGED
@@ -21,7 +21,9 @@ exports.buildIdentityService = buildIdentityService;
21
21
  * limitations under the License.
22
22
  */
23
23
  const db_1 = require("./db");
24
+ const exchangeOauth2Code_1 = require("./exchanges/exchangeOauth2Code");
24
25
  const getPublicKey_1 = require("./getPublicKey");
26
+ const verification_1 = require("./verification");
25
27
  const _1 = require(".");
26
28
  const serviceDefinitionParams = {
27
29
  serviceName: "Identity",
@@ -56,8 +58,12 @@ function buildIdentityService(identityConfig) {
56
58
  // Exchanges
57
59
  exchangeApiKey: (0, _1.exchangeApiKey)(db_1.prisma, identityConfig),
58
60
  exchangeCredentials: (0, _1.exchangeCredentials)(db_1.prisma, identityConfig),
61
+ exchangeOauth2Code: (0, exchangeOauth2Code_1.exchangeOauth2Code)(db_1.prisma, identityConfig),
59
62
  exchangeRefreshToken: (0, _1.exchangeRefreshToken)(db_1.prisma, identityConfig),
60
- getPublicKey: (0, getPublicKey_1.getPublicKey)(identityConfig.publicKey)
63
+ getPublicKey: (0, getPublicKey_1.getPublicKey)(identityConfig.publicKey),
64
+ // Verification
65
+ sendVerificationCode: (0, verification_1.createSendVerificationCode)(db_1.prisma, identityConfig),
66
+ verifyCode: (0, verification_1.createVerifyCode)(db_1.prisma)
61
67
  }
62
68
  };
63
69
  }
@@ -0,0 +1,7 @@
1
+ declare enum TemplatesEnum {
2
+ INVITE_NEW_USER = "inviteNewUser",
3
+ INVITE_EXISTING_USER = "inviteExistingUser",
4
+ VERIFY_EMAIL = "verifyEmail",
5
+ VERIFY_PHONE = "verifyPhone"
6
+ }
7
+ export { TemplatesEnum };