@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
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemplatesEnum = void 0;
4
+ /*
5
+ * Copyright (C) 2024 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
+ var TemplatesEnum;
23
+ (function (TemplatesEnum) {
24
+ TemplatesEnum["INVITE_NEW_USER"] = "inviteNewUser";
25
+ TemplatesEnum["INVITE_EXISTING_USER"] = "inviteExistingUser";
26
+ TemplatesEnum["VERIFY_EMAIL"] = "verifyEmail";
27
+ TemplatesEnum["VERIFY_PHONE"] = "verifyPhone";
28
+ })(TemplatesEnum || (exports.TemplatesEnum = TemplatesEnum = {}));
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Verification Code</title>
5
+ <style>
6
+ body {
7
+ font-family: Arial, sans-serif;
8
+ background-color: #f4f4f4;
9
+ color: #333;
10
+ line-height: 1.6;
11
+ padding: 20px;
12
+ }
13
+ .container {
14
+ background: #fff;
15
+ padding: 20px;
16
+ }
17
+ .verification-code {
18
+ font-size: 1.5em;
19
+ font-weight: bold;
20
+ }
21
+ @media (prefers-color-scheme: dark) {
22
+ body {
23
+ background-color: #181818;
24
+ color: #f4f4f4;
25
+ }
26
+ .container {
27
+ background: #181818;
28
+ }
29
+ }
30
+ </style>
31
+ </head>
32
+ <body>
33
+ <div class="container">
34
+ <p>To continue, please verify your account with the code below:</p>
35
+ <p class="verification-code">{{verificationCode}}</p>
36
+ <p>If you didn’t request this code, you can ignore this message.</p>
37
+ </div>
38
+ </body>
39
+ </html>
@@ -0,0 +1,3 @@
1
+ To continue, please verify your account with the following code: {{verificationCode}}
2
+
3
+ If you didn't request this, please ignore this message.
@@ -48,5 +48,5 @@ function deleteUser(prisma) {
48
48
  });
49
49
  callback(null, { ref });
50
50
  });
51
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
51
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
52
52
  }
@@ -59,5 +59,5 @@ function getUser(prisma) {
59
59
  }
60
60
  callback(null, (0, common_1.datesMapper)(user));
61
61
  });
62
- return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.baseApiObjectSchema);
62
+ return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
63
63
  }
@@ -30,11 +30,15 @@ exports.upsertDefaultUser = upsertDefaultUser;
30
30
  */
31
31
  const logger_1 = require("@fonoster/logger");
32
32
  const zod_1 = require("zod");
33
+ const zod_validation_error_1 = require("zod-validation-error");
33
34
  const db_1 = require("../db");
34
35
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
35
36
  const createUserRequestSchema = zod_1.z.object({
36
- name: zod_1.z.string().min(3).max(50),
37
- email: zod_1.z.string().email(),
37
+ name: zod_1.z
38
+ .string()
39
+ .min(3, { message: "Name must be at least 3 characters long" })
40
+ .max(50, { message: "Name must be at most 50 characters long" }),
41
+ email: zod_1.z.string().email({ message: "Must be a valid email" }),
38
42
  password: zod_1.z.string().min(8).max(50).or(zod_1.z.string().optional().nullable())
39
43
  });
40
44
  const USER_REF = "00000000-0000-0000-0000-000000000000";
@@ -79,7 +83,14 @@ function upsertDefaultUser(request) {
79
83
  });
80
84
  }
81
85
  catch (error) {
82
- logger.error("error on upsertDefaultUser", { error });
86
+ if (error instanceof zod_1.z.ZodError) {
87
+ logger.error("validation error on upsertDefaultUser", {
88
+ error: (0, zod_validation_error_1.fromError)(error, { prefix: null }).toString()
89
+ });
90
+ }
91
+ else {
92
+ logger.error("error on upsertDefaultUser", { error });
93
+ }
83
94
  process.exit(1);
84
95
  }
85
96
  });
@@ -32,14 +32,14 @@ exports.createCallAccessToken = createCallAccessToken;
32
32
  * limitations under the License.
33
33
  */
34
34
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
35
+ const constants_1 = require("../constants");
35
36
  const TokenUseEnum_1 = require("../exchanges/TokenUseEnum");
36
37
  const roles_1 = require("../roles");
37
- const SIGN_ALGORITHM = "RS256";
38
38
  function createCallAccessToken(identityConfig) {
39
39
  return (params) => __awaiter(this, void 0, void 0, function* () {
40
40
  const { privateKey } = identityConfig;
41
41
  const accessTokenSignOptions = {
42
- algorithm: SIGN_ALGORITHM,
42
+ algorithm: constants_1.SIGN_ALGORITHM,
43
43
  // Just enough time to validate a request
44
44
  expiresIn: "30s"
45
45
  };
@@ -0,0 +1,7 @@
1
+ import { VerificationType } from "@prisma/identity-client";
2
+ import { Prisma } from "../db";
3
+ declare function createGenerateVerificationCode(prisma: Prisma): (params: {
4
+ type: VerificationType;
5
+ value: string;
6
+ }) => Promise<string>;
7
+ export { createGenerateVerificationCode };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createGenerateVerificationCode = createGenerateVerificationCode;
13
+ const constants_1 = require("../constants");
14
+ function createGenerateVerificationCode(prisma) {
15
+ return (params) => __awaiter(this, void 0, void 0, function* () {
16
+ const { type, value } = params;
17
+ const code = Math.floor(100000 + Math.random() * 900000).toString();
18
+ yield prisma.verificationCode.create({
19
+ data: {
20
+ type,
21
+ value,
22
+ code,
23
+ expiresAt: new Date(Date.now() + constants_1.VERIFICATION_CODE_EXPIRATION)
24
+ }
25
+ });
26
+ return code;
27
+ });
28
+ }
@@ -0,0 +1,3 @@
1
+ import { Prisma } from "../db";
2
+ declare function createIsUserContactVerified(prisma: Prisma): (accessKeyId: string) => Promise<boolean>;
3
+ export { createIsUserContactVerified };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createIsUserContactVerified = createIsUserContactVerified;
13
+ function createIsUserContactVerified(prisma) {
14
+ return (accessKeyId) => __awaiter(this, void 0, void 0, function* () {
15
+ const user = yield prisma.user.findUnique({
16
+ where: {
17
+ accessKeyId
18
+ }
19
+ });
20
+ if (!user) {
21
+ throw new Error("User not found");
22
+ }
23
+ return user.emailVerified || user.phoneNumberVerified;
24
+ });
25
+ }
@@ -0,0 +1,8 @@
1
+ import { VerificationType } from "@prisma/identity-client";
2
+ import { Prisma } from "../db";
3
+ declare function createIsValidVerificationCode(prisma: Prisma): (params: {
4
+ type: VerificationType;
5
+ value: string;
6
+ code: string;
7
+ }) => Promise<boolean>;
8
+ export { createIsValidVerificationCode };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createIsValidVerificationCode = createIsValidVerificationCode;
13
+ const constants_1 = require("../constants");
14
+ function createIsValidVerificationCode(prisma) {
15
+ return (params) => __awaiter(this, void 0, void 0, function* () {
16
+ const { type, value, code } = params;
17
+ // Delete old verification codes
18
+ yield prisma.verificationCode.deleteMany({
19
+ where: {
20
+ expiresAt: {
21
+ lt: new Date(Date.now() - constants_1.VERIFICATION_CODE_EXPIRATION)
22
+ }
23
+ }
24
+ });
25
+ const result = yield prisma.verificationCode.findFirst({
26
+ where: {
27
+ type,
28
+ value,
29
+ code
30
+ }
31
+ });
32
+ return !!result;
33
+ });
34
+ }
@@ -24,7 +24,7 @@ function createSendEmail(identityConfig) {
24
24
  const { smtpConfig } = identityConfig;
25
25
  const { host, port, secure, sender, auth } = smtpConfig;
26
26
  const { user, pass } = auth;
27
- return (0, common_1.createEmailSender)({
27
+ return (0, common_1.createSendEmail)({
28
28
  sender,
29
29
  host,
30
30
  port,
@@ -0,0 +1,8 @@
1
+ import { IdentityConfig } from "../exchanges/types";
2
+ declare function createWorkspaceInviteToken(identityConfig: IdentityConfig): (params: {
3
+ userRef: string;
4
+ memberRef: string;
5
+ accessKeyId: string;
6
+ expiresIn?: string;
7
+ }) => Promise<string>;
8
+ export { createWorkspaceInviteToken };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createWorkspaceInviteToken = createWorkspaceInviteToken;
16
+ /*
17
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
18
+ * http://github.com/fonoster/fonoster
19
+ *
20
+ * This file is part of Fonoster
21
+ *
22
+ * Licensed under the MIT License (the "License");
23
+ * you may not use this file except in compliance with
24
+ * the License. You may obtain a copy of the License at
25
+ *
26
+ * https://opensource.org/licenses/MIT
27
+ *
28
+ * Unless required by applicable law or agreed to in writing, software
29
+ * distributed under the License is distributed on an "AS IS" BASIS,
30
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ * See the License for the specific language governing permissions and
32
+ * limitations under the License.
33
+ */
34
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
35
+ const constants_1 = require("../constants");
36
+ function createWorkspaceInviteToken(identityConfig) {
37
+ return (params) => __awaiter(this, void 0, void 0, function* () {
38
+ const { privateKey } = identityConfig;
39
+ const { issuer, audience } = identityConfig;
40
+ const { userRef, memberRef, accessKeyId, expiresIn } = params;
41
+ const accessTokenSignOptions = {
42
+ algorithm: constants_1.SIGN_ALGORITHM,
43
+ expiresIn: expiresIn || "1d"
44
+ };
45
+ const unsignedToken = {
46
+ iss: issuer,
47
+ sub: userRef,
48
+ aud: audience,
49
+ memberRef: memberRef,
50
+ accessKeyId
51
+ };
52
+ return jsonwebtoken_1.default.sign(unsignedToken, privateKey, accessTokenSignOptions);
53
+ });
54
+ }
@@ -1,12 +1,12 @@
1
1
  import { Prisma } from "../db";
2
2
  declare function getApiKeyByAccessKeyId(prisma: Prisma): (accessKeyId: string) => Promise<{
3
3
  ref: string;
4
- createdAt: Date;
5
- updatedAt: Date;
6
- role: "WORKSPACE_ADMIN";
7
- expiresAt: Date;
8
4
  accessKeyId: string;
9
5
  accessKeySecret: string;
6
+ role: import("@prisma/identity-client").$Enums.ApiKeyRole;
7
+ createdAt: Date;
8
+ updatedAt: Date;
9
+ expiresAt: Date | null;
10
10
  workspaceRef: string;
11
11
  }>;
12
12
  export { getApiKeyByAccessKeyId };
@@ -2,14 +2,14 @@ import { Prisma } from "../db";
2
2
  declare function getUserByEmail(prisma: Prisma): (email: string) => Promise<{
3
3
  name: string;
4
4
  ref: string;
5
- email: string;
5
+ accessKeyId: string;
6
6
  createdAt: Date;
7
7
  updatedAt: Date;
8
- accessKeyId: string;
9
- password: string;
10
- avatar: string;
8
+ email: string;
11
9
  emailVerified: boolean;
12
- phoneNumber: string;
10
+ password: string;
11
+ phoneNumber: string | null;
13
12
  phoneNumberVerified: boolean;
13
+ avatar: string | null;
14
14
  }>;
15
15
  export { getUserByEmail };
@@ -1,4 +1,5 @@
1
1
  export * from "./createCallAccessToken";
2
+ export * from "./createSendEmail";
2
3
  export * from "./decodeToken";
3
4
  export * from "./generateAccessKeyId";
4
5
  export * from "./getAccessKeyIdFromCall";
@@ -8,4 +9,5 @@ export * from "./hasAccess";
8
9
  export * from "./hasAccessToResource";
9
10
  export * from "./isValidToken";
10
11
  export * from "./tokenHasAccessKeyId";
12
+ export * from "./updateMembershipStatus";
11
13
  export * from "./withAccess";
@@ -14,8 +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("./createCallAccessToken"), exports);
18
- __exportStar(require("./decodeToken"), exports);
19
17
  /*
20
18
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
21
19
  * http://github.com/fonoster/fonoster
@@ -34,6 +32,9 @@ __exportStar(require("./decodeToken"), exports);
34
32
  * See the License for the specific language governing permissions and
35
33
  * limitations under the License.
36
34
  */
35
+ __exportStar(require("./createCallAccessToken"), exports);
36
+ __exportStar(require("./createSendEmail"), exports);
37
+ __exportStar(require("./decodeToken"), exports);
37
38
  __exportStar(require("./generateAccessKeyId"), exports);
38
39
  __exportStar(require("./getAccessKeyIdFromCall"), exports);
39
40
  __exportStar(require("./getAccessKeyIdFromToken"), exports);
@@ -42,4 +43,5 @@ __exportStar(require("./hasAccess"), exports);
42
43
  __exportStar(require("./hasAccessToResource"), exports);
43
44
  __exportStar(require("./isValidToken"), exports);
44
45
  __exportStar(require("./tokenHasAccessKeyId"), exports);
46
+ __exportStar(require("./updateMembershipStatus"), exports);
45
47
  __exportStar(require("./withAccess"), exports);
@@ -0,0 +1,3 @@
1
+ import { IdentityConfig } from "../exchanges";
2
+ declare function updateMembershipStatus(identityConfig: IdentityConfig): (token: string) => Promise<void>;
3
+ export { updateMembershipStatus };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.updateMembershipStatus = updateMembershipStatus;
13
+ /*
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const types_1 = require("@fonoster/types");
32
+ const jwt_decode_1 = require("jwt-decode");
33
+ const isValidToken_1 = require("./isValidToken");
34
+ const db_1 = require("../db");
35
+ function updateMembershipStatus(identityConfig) {
36
+ return (token) => __awaiter(this, void 0, void 0, function* () {
37
+ if (!(0, isValidToken_1.isValidToken)(token, identityConfig.privateKey)) {
38
+ throw new Error("Invalid token");
39
+ }
40
+ const { memberRef } = (0, jwt_decode_1.jwtDecode)(token);
41
+ yield db_1.prisma.workspaceMember.update({
42
+ where: {
43
+ ref: memberRef
44
+ },
45
+ data: {
46
+ status: types_1.WorkspaceMemberStatus.ACTIVE,
47
+ updatedAt: new Date()
48
+ }
49
+ });
50
+ });
51
+ }
@@ -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) {
@@ -0,0 +1,3 @@
1
+ import { VerificationParams } from "./types";
2
+ declare function createBodyForVerificationEmail(params: Omit<VerificationParams, "recipient">): string;
3
+ export { createBodyForVerificationEmail };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createBodyForVerificationEmail = createBodyForVerificationEmail;
7
+ /*
8
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/fonoster
10
+ *
11
+ * This file is part of Fonoster
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const path_1 = __importDefault(require("path"));
26
+ const common_1 = require("@fonoster/common");
27
+ const TemplatesEnum_1 = require("../templates/TemplatesEnum");
28
+ function createBodyForVerificationEmail(params) {
29
+ const { verificationCode, templateDir: emailTemplateDir } = params;
30
+ const template = TemplatesEnum_1.TemplatesEnum.VERIFY_EMAIL;
31
+ const templateDir = emailTemplateDir || path_1.default.join(__dirname, "..", "templates");
32
+ const templatePath = `${templateDir}/${template}.hbs`;
33
+ return (0, common_1.compileTemplate)({
34
+ filePath: templatePath,
35
+ data: {
36
+ verificationCode
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,3 @@
1
+ import { VerificationParams } from "./types";
2
+ declare function createBodyForVerificationMessage(params: Omit<VerificationParams, "recipient">): string;
3
+ export { createBodyForVerificationMessage };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createBodyForVerificationMessage = createBodyForVerificationMessage;
7
+ /*
8
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/fonoster
10
+ *
11
+ * This file is part of Fonoster
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const path_1 = __importDefault(require("path"));
26
+ const common_1 = require("@fonoster/common");
27
+ const TemplatesEnum_1 = require("../templates/TemplatesEnum");
28
+ function createBodyForVerificationMessage(params) {
29
+ const { verificationCode, templateDir } = params;
30
+ const template = TemplatesEnum_1.TemplatesEnum.VERIFY_PHONE;
31
+ const actualTemplateDir = templateDir || path_1.default.join(__dirname, "..", "templates");
32
+ const templatePath = `${actualTemplateDir}/${template}.hbs`;
33
+ return (0, common_1.compileTemplate)({
34
+ filePath: templatePath,
35
+ data: {
36
+ verificationCode
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,7 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ import { IdentityConfig } from "../exchanges";
4
+ declare function createSendVerificationCode(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
+ request: unknown;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
+ export { createSendVerificationCode };