@fonoster/identity 0.9.16 → 0.9.20

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,32 +66,18 @@ const logger_1 = require("@fonoster/logger");
66
66
  const grpc = __importStar(require("@grpc/grpc-js"));
67
67
  const exchangeTokens_1 = require("./exchangeTokens");
68
68
  const createGetUserByEmail_1 = require("../utils/createGetUserByEmail");
69
+ const getGitHubUserWithOauth2Code_1 = require("../utils/getGitHubUserWithOauth2Code");
69
70
  const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
70
71
  function createExchangeOauth2Code(prisma, identityConfig) {
71
72
  const exchangeOauth2Code = (call, callback) => __awaiter(this, void 0, void 0, function* () {
72
73
  const { request } = call;
73
74
  const { provider, code } = request;
74
75
  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
- })
76
+ const userData = yield (0, getGitHubUserWithOauth2Code_1.getGitHubUserWithOauth2Code)({
77
+ clientId: identityConfig.githubOauth2Config.clientId,
78
+ clientSecret: identityConfig.githubOauth2Config.clientSecret,
79
+ code
86
80
  });
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
81
  const user = yield (0, createGetUserByEmail_1.createGetUserByEmail)(prisma)(userData.email);
96
82
  if (!user) {
97
83
  return callback({
@@ -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
@@ -44,6 +44,9 @@ declare function buildIdentityService(identityConfig: IdentityConfig): {
44
44
  createUser: (call: {
45
45
  request: unknown;
46
46
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
47
+ createUserWithOauth2Code: (call: {
48
+ request: unknown;
49
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
47
50
  getUser: (call: {
48
51
  request: unknown;
49
52
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
@@ -53,6 +56,12 @@ declare function buildIdentityService(identityConfig: IdentityConfig): {
53
56
  updateUser: (call: {
54
57
  request: unknown;
55
58
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
59
+ sendResetPasswordCode: (call: {
60
+ request: unknown;
61
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
62
+ resetPassword: (call: {
63
+ request: unknown;
64
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
56
65
  createApiKey: (call: {
57
66
  request: unknown;
58
67
  }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
package/dist/service.js CHANGED
@@ -49,9 +49,12 @@ function buildIdentityService(identityConfig) {
49
49
  removeUserFromWorkspace: (0, _1.createRemoveUserFromWorkspace)(prisma),
50
50
  // User operations
51
51
  createUser: (0, _1.createCreateUser)(prisma),
52
+ createUserWithOauth2Code: (0, _1.createCreateUserWithOauth2Code)(prisma, identityConfig),
52
53
  getUser: (0, _1.createGetUser)(prisma),
53
54
  deleteUser: (0, _1.createDeleteUser)(prisma),
54
55
  updateUser: (0, _1.createUpdateUser)(prisma),
56
+ sendResetPasswordCode: (0, _1.createSendResetPasswordCode)(prisma, identityConfig),
57
+ resetPassword: (0, _1.createResetPassword)(prisma),
55
58
  // ApiKey operations
56
59
  createApiKey: (0, _1.createCreateApiKey)(prisma),
57
60
  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,7 @@
1
+ import { GrpcErrorMessage } from "@fonoster/common";
2
+ import { Prisma } from "../db";
3
+ import { IdentityConfig } from "../exchanges/types";
4
+ declare function createCreateUserWithOauth2Code(prisma: Prisma, identityConfig: IdentityConfig): (call: {
5
+ request: unknown;
6
+ }, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
7
+ export { createCreateUserWithOauth2Code };
@@ -0,0 +1,109 @@
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.createCreateUserWithOauth2Code = createCreateUserWithOauth2Code;
46
+ /*
47
+ * Copyright (C) 2025 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 generateAccessKeyId_1 = require("../utils/generateAccessKeyId");
67
+ const getGitHubUserWithOauth2Code_1 = require("../utils/getGitHubUserWithOauth2Code");
68
+ const createGetUserByEmail_1 = require("../utils/createGetUserByEmail");
69
+ const grpc = __importStar(require("@grpc/grpc-js"));
70
+ const nanoid_1 = require("nanoid");
71
+ const exchangeTokens_1 = require("../exchanges/exchangeTokens");
72
+ const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
73
+ function createCreateUserWithOauth2Code(prisma, identityConfig) {
74
+ const createUserWithOauth2Code = (call, callback) => __awaiter(this, void 0, void 0, function* () {
75
+ const { request } = call;
76
+ const { code } = request;
77
+ logger.verbose("call to createCreateUserWithOauth2Code");
78
+ const userData = yield (0, getGitHubUserWithOauth2Code_1.getGitHubUserWithOauth2Code)({
79
+ clientId: identityConfig.githubOauth2Config.clientId,
80
+ clientSecret: identityConfig.githubOauth2Config.clientSecret,
81
+ code
82
+ });
83
+ if (!userData.email) {
84
+ return callback({
85
+ code: grpc.status.PERMISSION_DENIED,
86
+ message: "Failed to get user data from GitHub"
87
+ });
88
+ }
89
+ const userFromDB = yield (0, createGetUserByEmail_1.createGetUserByEmail)(prisma)(userData === null || userData === void 0 ? void 0 : userData.email);
90
+ if (userFromDB) {
91
+ return callback({
92
+ code: grpc.status.ALREADY_EXISTS,
93
+ message: "User already exists"
94
+ });
95
+ }
96
+ const user = yield prisma.user.create({
97
+ data: {
98
+ name: userData.name,
99
+ email: userData.email,
100
+ accessKeyId: (0, generateAccessKeyId_1.generateAccessKeyId)(generateAccessKeyId_1.AccessKeyIdType.USER),
101
+ emailVerified: true,
102
+ password: (0, nanoid_1.customAlphabet)("1234567890abcdef", 10)(),
103
+ avatar: userData.avatar_url
104
+ }
105
+ });
106
+ callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
107
+ });
108
+ return (0, common_1.withErrorHandlingAndValidation)(createUserWithOauth2Code, common_1.Validators.createUserWithOauth2CodeRequestSchema);
109
+ }
@@ -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
+ }
@@ -1,5 +1,8 @@
1
1
  export * from "./createCreateUser";
2
+ export * from "./createCreateUserWithOauth2Code";
2
3
  export * from "./createDeleteUser";
3
4
  export * from "./createGetUser";
4
5
  export * from "./createUpdateUser";
5
6
  export * from "./upsertDefaultUser";
7
+ export * from "./createSendResetPasswordCode";
8
+ export * from "./createResetPassword";
@@ -33,7 +33,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  * limitations under the License.
34
34
  */
35
35
  __exportStar(require("./createCreateUser"), exports);
36
+ __exportStar(require("./createCreateUserWithOauth2Code"), exports);
36
37
  __exportStar(require("./createDeleteUser"), exports);
37
38
  __exportStar(require("./createGetUser"), exports);
38
39
  __exportStar(require("./createUpdateUser"), exports);
39
40
  __exportStar(require("./upsertDefaultUser"), exports);
41
+ __exportStar(require("./createSendResetPasswordCode"), exports);
42
+ __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 });
@@ -0,0 +1,6 @@
1
+ declare function getGitHubUserWithOauth2Code(params: {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ code: string;
5
+ }): Promise<any>;
6
+ export { getGitHubUserWithOauth2Code };
@@ -0,0 +1,57 @@
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.getGitHubUserWithOauth2Code = getGitHubUserWithOauth2Code;
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 GITHUB_API_URL = "https://github.com/login/oauth/access_token";
32
+ const GITHUB_USER_API_URL = "https://api.github.com/user";
33
+ function getGitHubUserWithOauth2Code(params) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const { clientId, clientSecret, code } = params;
36
+ const tokenResponse = yield fetch(GITHUB_API_URL, {
37
+ method: "POST",
38
+ headers: {
39
+ "Content-Type": "application/json",
40
+ Accept: "application/json"
41
+ },
42
+ body: JSON.stringify({
43
+ client_id: clientId,
44
+ client_secret: clientSecret,
45
+ code
46
+ })
47
+ });
48
+ const tokenData = yield tokenResponse.json();
49
+ const accessToken = tokenData === null || tokenData === void 0 ? void 0 : tokenData.access_token;
50
+ const userResponse = yield fetch(GITHUB_USER_API_URL, {
51
+ headers: {
52
+ Authorization: `token ${accessToken}`
53
+ }
54
+ });
55
+ return userResponse.json();
56
+ });
57
+ }
@@ -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.20",
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.20",
24
24
  "@fonoster/logger": "^0.9.12",
25
- "@fonoster/types": "^0.9.15",
25
+ "@fonoster/types": "^0.9.20",
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": "d48ba5f00cf72b81a1ed6d9fcc34036a99e3cc8e"
52
52
  }