@fonoster/identity 0.9.16 → 0.9.19

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.
@@ -14,6 +14,7 @@ type IdentityConfig = {
14
14
  workspaceInviteUrl: string;
15
15
  workspaceInviteFailUrl: string;
16
16
  userVerificationRequired: boolean;
17
+ resetPasswordUrl: string;
17
18
  smtpConfig: {
18
19
  sender: string;
19
20
  host: string;
@@ -16,7 +16,7 @@ function sendInvite(sendEmail, request) {
16
16
  const { recipient, inviteUrl, oneTimePassword, isExistingUser, workspaceName, templateDir } = request;
17
17
  yield sendEmail({
18
18
  to: recipient,
19
- subject: "Invite to join a Fonoster workspace",
19
+ subject: "Invitation to join a Fonoster workspace",
20
20
  html: (0, createInviteBody_1.createInviteBody)({
21
21
  templateDir,
22
22
  isExistingUser,
package/dist/service.d.ts CHANGED
@@ -53,6 +53,12 @@ declare function buildIdentityService(identityConfig: IdentityConfig): {
53
53
  updateUser: (call: {
54
54
  request: unknown;
55
55
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
56
+ sendResetPasswordCode: (call: {
57
+ request: unknown;
58
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
59
+ resetPassword: (call: {
60
+ request: unknown;
61
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
56
62
  createApiKey: (call: {
57
63
  request: unknown;
58
64
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
package/dist/service.js CHANGED
@@ -52,6 +52,8 @@ function buildIdentityService(identityConfig) {
52
52
  getUser: (0, _1.createGetUser)(prisma),
53
53
  deleteUser: (0, _1.createDeleteUser)(prisma),
54
54
  updateUser: (0, _1.createUpdateUser)(prisma),
55
+ sendResetPasswordCode: (0, _1.createSendResetPasswordCode)(prisma, identityConfig),
56
+ resetPassword: (0, _1.createResetPassword)(prisma),
55
57
  // ApiKey operations
56
58
  createApiKey: (0, _1.createCreateApiKey)(prisma),
57
59
  deleteApiKey: (0, _1.createDeleteApiKey)(prisma),
@@ -2,6 +2,7 @@ declare enum TemplatesEnum {
2
2
  INVITE_NEW_USER = "inviteNewUser",
3
3
  INVITE_EXISTING_USER = "inviteExistingUser",
4
4
  VERIFY_EMAIL = "verifyEmail",
5
- VERIFY_PHONE = "verifyPhone"
5
+ VERIFY_PHONE = "verifyPhone",
6
+ RESET_PASSWORD = "resetPassword"
6
7
  }
7
8
  export { TemplatesEnum };
@@ -25,4 +25,5 @@ var TemplatesEnum;
25
25
  TemplatesEnum["INVITE_EXISTING_USER"] = "inviteExistingUser";
26
26
  TemplatesEnum["VERIFY_EMAIL"] = "verifyEmail";
27
27
  TemplatesEnum["VERIFY_PHONE"] = "verifyPhone";
28
+ TemplatesEnum["RESET_PASSWORD"] = "resetPassword";
28
29
  })(TemplatesEnum || (exports.TemplatesEnum = TemplatesEnum = {}));
@@ -0,0 +1,48 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Reset Password</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
+ .button {
18
+ display: inline-block;
19
+ padding: 10px 20px;
20
+ line-height: 20px;
21
+ background: linear-gradient(323deg, #008751 30.56%, #3ae19e 118.19%);
22
+ color: white !important;
23
+ text-decoration: none;
24
+ border-radius: 5px;
25
+ font-weight: bold;
26
+ text-align: center;
27
+ border: none;
28
+ cursor: pointer;
29
+ }
30
+ @media (prefers-color-scheme: dark) {
31
+ body {
32
+ background-color: #181818;
33
+ color: #f4f4f4;
34
+ }
35
+ .container {
36
+ background: #181818;
37
+ }
38
+ }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <div class="container">
43
+ <p>You have requested a password reset for your Fonoster account.</p>
44
+ <p>To reset your password, please click on the button below:</p>
45
+ <a href="{{resetPasswordUrl}}" class="button">Reset Password</a>
46
+ </div>
47
+ </body>
48
+ </html>
@@ -0,0 +1,6 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ declare function createResetPassword(prisma: Prisma): (call: {
4
+ request: unknown;
5
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
6
+ export { createResetPassword };
@@ -0,0 +1,65 @@
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.createResetPassword = createResetPassword;
13
+ /*
14
+ * Copyright (C) 2025 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 common_1 = require("@fonoster/common");
32
+ const logger_1 = require("@fonoster/logger");
33
+ const types_1 = require("@fonoster/types");
34
+ const createIsValidVerificationCode_1 = require("../utils/createIsValidVerificationCode");
35
+ const grpc_js_1 = require("@grpc/grpc-js");
36
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
37
+ function createResetPassword(prisma) {
38
+ const isValidVerificationCode = (0, createIsValidVerificationCode_1.createIsValidVerificationCode)(prisma);
39
+ const resetPassword = (call, callback) => __awaiter(this, void 0, void 0, function* () {
40
+ const { request } = call;
41
+ const { username, password, verificationCode } = request;
42
+ logger.verbose("call to resetPassword", {
43
+ username,
44
+ password,
45
+ verificationCode
46
+ });
47
+ const isValid = yield isValidVerificationCode({
48
+ type: types_1.ContactType.EMAIL,
49
+ value: username,
50
+ code: verificationCode
51
+ });
52
+ if (!isValid) {
53
+ return callback({
54
+ code: grpc_js_1.status.PERMISSION_DENIED,
55
+ message: "Invalid verification code"
56
+ });
57
+ }
58
+ yield prisma.user.update({
59
+ where: { email: username },
60
+ data: { password }
61
+ });
62
+ callback(null);
63
+ });
64
+ return (0, common_1.withErrorHandlingAndValidation)(resetPassword, common_1.Validators.resetPasswordRequestSchema);
65
+ }
@@ -0,0 +1,3 @@
1
+ import { SendResetPasswordEmailRequest } from "./types";
2
+ declare function createResetPasswordBody(params: Omit<SendResetPasswordEmailRequest, "recipient">): string;
3
+ export { createResetPasswordBody };
@@ -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.createResetPasswordBody = createResetPasswordBody;
7
+ /*
8
+ * Copyright (C) 2025 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 createResetPasswordBody(params) {
29
+ const { templateDir: emailTemplateDir, resetPasswordUrl } = params;
30
+ const template = TemplatesEnum_1.TemplatesEnum.RESET_PASSWORD;
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
+ resetPasswordUrl
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,7 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ import { IdentityConfig } from "../exchanges/types";
4
+ declare function createSendResetPasswordCode(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
+ request: unknown;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
+ export { createSendResetPasswordCode };
@@ -0,0 +1,55 @@
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.createSendResetPasswordCode = createSendResetPasswordCode;
13
+ /*
14
+ * Copyright (C) 2025 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 common_1 = require("@fonoster/common");
32
+ const logger_1 = require("@fonoster/logger");
33
+ const types_1 = require("@fonoster/types");
34
+ const createGenerateVerificationCode_1 = require("../utils/createGenerateVerificationCode");
35
+ const utils_1 = require("../utils");
36
+ const sendResetPasswordEmail_1 = require("./sendResetPasswordEmail");
37
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
38
+ function createSendResetPasswordCode(prisma, identityConfig) {
39
+ const generateVerificationCode = (0, createGenerateVerificationCode_1.createGenerateVerificationCode)(prisma);
40
+ const sendResetPasswordCode = (call, callback) => __awaiter(this, void 0, void 0, function* () {
41
+ const { request } = call;
42
+ const { username } = request;
43
+ logger.verbose("call to sendResetPasswordCode", { username });
44
+ const verificationCode = yield generateVerificationCode({
45
+ type: types_1.ContactType.EMAIL,
46
+ value: username
47
+ });
48
+ yield (0, sendResetPasswordEmail_1.sendResetPasswordEmail)((0, utils_1.createSendEmail)(identityConfig), {
49
+ recipient: username,
50
+ resetPasswordUrl: `${identityConfig.resetPasswordUrl}?code=${verificationCode}`
51
+ });
52
+ callback(null);
53
+ });
54
+ return (0, common_1.withErrorHandlingAndValidation)(sendResetPasswordCode, common_1.Validators.sendResetPasswordCodeRequestSchema);
55
+ }
@@ -3,3 +3,5 @@ export * from "./createDeleteUser";
3
3
  export * from "./createGetUser";
4
4
  export * from "./createUpdateUser";
5
5
  export * from "./upsertDefaultUser";
6
+ export * from "./createSendResetPasswordCode";
7
+ export * from "./createResetPassword";
@@ -37,3 +37,5 @@ __exportStar(require("./createDeleteUser"), exports);
37
37
  __exportStar(require("./createGetUser"), exports);
38
38
  __exportStar(require("./createUpdateUser"), exports);
39
39
  __exportStar(require("./upsertDefaultUser"), exports);
40
+ __exportStar(require("./createSendResetPasswordCode"), exports);
41
+ __exportStar(require("./createResetPassword"), exports);
@@ -0,0 +1,4 @@
1
+ import { EmailParams } from "@fonoster/common";
2
+ import { SendResetPasswordEmailRequest } from "./types";
3
+ declare function sendResetPasswordEmail(sendEmail: (params: EmailParams) => Promise<void>, request: SendResetPasswordEmailRequest): Promise<void>;
4
+ export { sendResetPasswordEmail };
@@ -0,0 +1,26 @@
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.sendResetPasswordEmail = sendResetPasswordEmail;
13
+ const createResetPasswordBody_1 = require("./createResetPasswordBody");
14
+ function sendResetPasswordEmail(sendEmail, request) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { recipient, resetPasswordUrl, templateDir } = request;
17
+ yield sendEmail({
18
+ to: recipient,
19
+ subject: "Reset Password",
20
+ html: (0, createResetPasswordBody_1.createResetPasswordBody)({
21
+ templateDir,
22
+ resetPasswordUrl
23
+ })
24
+ });
25
+ });
26
+ }
@@ -0,0 +1,6 @@
1
+ type SendResetPasswordEmailRequest = {
2
+ recipient: string;
3
+ templateDir?: string;
4
+ resetPasswordUrl: string;
5
+ };
6
+ export { SendResetPasswordEmailRequest };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -40,8 +40,8 @@ function createVerifyCode(prisma) {
40
40
  const actualContactType = contactType !== null && contactType !== void 0 ? contactType : types_1.ContactType.EMAIL;
41
41
  const isValid = yield isValidVerificationCode({
42
42
  type: actualContactType,
43
- code: verificationCode,
44
- value
43
+ value,
44
+ code: verificationCode
45
45
  });
46
46
  if (!isValid) {
47
47
  return callback({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/identity",
3
- "version": "0.9.16",
3
+ "version": "0.9.19",
4
4
  "description": "Identity service for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -20,9 +20,9 @@
20
20
  "fonoster": "./dist/index.js"
21
21
  },
22
22
  "dependencies": {
23
- "@fonoster/common": "^0.9.16",
23
+ "@fonoster/common": "^0.9.19",
24
24
  "@fonoster/logger": "^0.9.12",
25
- "@fonoster/types": "^0.9.15",
25
+ "@fonoster/types": "^0.9.19",
26
26
  "@grpc/grpc-js": "~1.10.6",
27
27
  "@prisma/client": "^6.4.1",
28
28
  "jsonwebtoken": "^9.0.2",
@@ -48,5 +48,5 @@
48
48
  "devDependencies": {
49
49
  "@types/jsonwebtoken": "^9.0.6"
50
50
  },
51
- "gitHead": "351223b8851c88b46fa633ab4f47286e4ae0a561"
51
+ "gitHead": "b1798a2fdd50288ae37024fc6bf341d66d0f7d12"
52
52
  }