@social-mail/social-mail-web-server 1.4.820 → 1.4.821

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.4.820",
3
+ "version": "1.4.821",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -27,6 +27,11 @@ export const globalEnv = {
27
27
  wildcardDomain: process.env.SOCIAL_MAIL_WILDCARD_DOMAIN,
28
28
  name: process.env.SOCIAL_MAIL_NAME || "Social Mail",
29
29
  secretKey: process.env.SOCIAL_MAIL_SECRET_KEY,
30
+ otpIn:{
31
+ host: process.env.SOCIAL_MAIL_OTP_IN_HOST,
32
+ key: process.env.SOCIAL_MAIL_OTP_IN_KEY,
33
+ secret: process.env.SOCIAL_MAIL_OTP_IN_SECRET,
34
+ },
30
35
  port,
31
36
  serverID: process.env.SOCIAL_MAIL_SERVER_ID,
32
37
  parentApiToken: process.env.SOCIAL_MAIL_PARENT_API_TOKEN,
@@ -99,7 +99,7 @@ export default class LoginSession {
99
99
  public oneTimePassword: string;
100
100
 
101
101
  @JsonProperty({ help: "SMS URL to Display"})
102
- public smsConfig: { prefix: string, code: string, url: string }[];
102
+ public smsConfig: any;
103
103
 
104
104
  public user: User;
105
105
 
@@ -11,6 +11,8 @@ export default class AccessTokenEvents extends AuthenticatedEvents<AccessToken>
11
11
  this.sessionUser.ensureLoggedIn();
12
12
  }
13
13
 
14
+ entity.userID ??= this.sessionUser.userID;
15
+
14
16
  entity.secret = "sm-at-" + randomUUID().replaceAll("-", "");
15
17
  entity.displaySecret = entity.secret;
16
18
  }
@@ -18,6 +18,7 @@ import Sql from "@entity-access/entity-access/dist/sql/Sql.js";
18
18
  import { randomUUID } from "crypto";
19
19
  import { AppStringHelper } from "../../../common/AppStringHelper.js";
20
20
  import IncomingSmsService from "../../services/incoming-sms/IncomingSmsService.js";
21
+ import ExternalOtpInService from "../../services/external-otp-in/ExternalOtpInService.js";
21
22
 
22
23
  export default class LoginSessionEvents extends EntityEvents<LoginSession> {
23
24
 
@@ -140,9 +141,9 @@ export default class LoginSessionEvents extends EntityEvents<LoginSession> {
140
141
  .toArray();
141
142
 
142
143
  if (otpIn.length) {
143
- const code = entity.smsToken = AppStringHelper.last(DateTime.now.msSinceEpoch.toString(), 6);
144
- const idsCodes = otpIn.map((x) => x.isdCode.startsWith("+") ? x.isdCode : "+" + x.isdCode );
145
- entity.smsConfig = await ServiceProvider.resolve(this, IncomingSmsService).prepareCode(code, ... idsCodes);
144
+ const idsCodes = otpIn.map((x) => x.phoneNumber );
145
+ entity.smsConfig = await ServiceProvider.resolve(this, ExternalOtpInService).create(idsCodes);
146
+ entity.smsToken = entity.smsConfig.id;
146
147
  }
147
148
 
148
149
  return;
@@ -0,0 +1,36 @@
1
+ import { RegisterSingleton } from "@entity-access/entity-access/dist/di/di.js";
2
+ import { globalEnv } from "../../../common/globalEnv.js";
3
+
4
+ const headers = {
5
+ authorization: `basic ${Buffer.from(`${globalEnv.otpIn.key}:${globalEnv.otpIn.secret}`).toString("base64")}`
6
+ };
7
+
8
+ const postHeaders = {
9
+ ... headers,
10
+ "content-type": "application/json",
11
+ };
12
+
13
+ @RegisterSingleton
14
+ export default class ExternalOtpInService {
15
+
16
+ async create(phoneNumbers: string[]) {
17
+ const rs = await fetch(`https://${globalEnv.otpIn.host}/api/otp-in/create`, {
18
+ method: "POST",
19
+ headers: postHeaders,
20
+ body: JSON.stringify({
21
+ phoneNumbers
22
+ })
23
+ });
24
+ const { id, ui } = await rs.json();
25
+ return { id, ui };
26
+ }
27
+
28
+ async get(id) {
29
+ const rs = await fetch(`https://${globalEnv.otpIn.host}/api/otp-in/get/${id}`, {
30
+ method: "GET",
31
+ headers
32
+ });
33
+ const { success } = await rs.json();
34
+ return { success };
35
+ }
36
+ }