akeyless-server-commons 1.0.2 → 1.0.4

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.
@@ -1,7 +1,3 @@
1
- import { NxUser, DefaultClient } from "akeyless-types-commons";
1
+ import { NxUser } from "akeyless-types-commons";
2
2
  export declare const convert_to_short_phone_number: (phone_number: string) => string;
3
- interface Users {
4
- nx_user?: NxUser;
5
- }
6
- export declare const get_users_by_phone: (phone_number: string, default_client_key?: DefaultClient) => Promise<Users>;
7
- export {};
3
+ export declare const get_user_by_identifier: (identifier: string) => Promise<NxUser>;
@@ -9,28 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.get_users_by_phone = exports.convert_to_short_phone_number = void 0;
13
- const akeyless_types_commons_1 = require("akeyless-types-commons");
12
+ exports.get_user_by_identifier = exports.convert_to_short_phone_number = void 0;
14
13
  const firebase_helpers_1 = require("./firebase_helpers");
15
14
  const convert_to_short_phone_number = (phone_number) => {
16
15
  return `0${phone_number.split("+972")[1]}`;
17
16
  };
18
17
  exports.convert_to_short_phone_number = convert_to_short_phone_number;
19
- const get_users_by_phone = (phone_number_1, ...args_1) => __awaiter(void 0, [phone_number_1, ...args_1], void 0, function* (phone_number, default_client_key = akeyless_types_commons_1.DefaultClient.default) {
20
- let nx_user;
21
- const nx_user_q = yield (0, firebase_helpers_1.query_document_optional)("nx-users", "phone_number", "in", [
22
- (0, exports.convert_to_short_phone_number)(phone_number),
23
- phone_number,
18
+ const get_user_by_identifier = (identifier) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const phone_query = yield (0, firebase_helpers_1.query_document_optional)("nx-users", "phone_number", "in", [
20
+ (0, exports.convert_to_short_phone_number)(identifier),
21
+ identifier,
24
22
  ]);
25
- if (!nx_user_q) {
26
- throw "User not found";
23
+ if (!phone_query) {
24
+ const email_query = yield (0, firebase_helpers_1.query_document_optional)("nx-users", "email", "==", identifier);
25
+ if (!email_query) {
26
+ throw "User not found";
27
+ }
28
+ return email_query;
27
29
  }
28
- if (nx_user_q) {
29
- nx_user = nx_user_q;
30
- }
31
- return {
32
- nx_user,
33
- };
30
+ return phone_query;
34
31
  });
35
- exports.get_users_by_phone = get_users_by_phone;
32
+ exports.get_user_by_identifier = get_user_by_identifier;
36
33
  //# sourceMappingURL=login_helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"login_helpers.js","sourceRoot":"","sources":["../../../src/helpers/login_helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mEAA+D;AAC/D,yDAA6E;AAEtE,MAAM,6BAA6B,GAAG,CAAC,YAAoB,EAAU,EAAE;IAC1E,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,6BAA6B,iCAExC;AAIK,MAAM,kBAAkB,GAAG,4BAAwG,EAAE,mEAAnG,YAAoB,EAAE,qBAAoC,sCAAa,CAAC,OAAO;IACpH,IAAI,OAAO,CAAC;IAEZ,MAAM,SAAS,GAAkB,MAAM,IAAA,0CAAuB,EAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE;QAC7F,IAAA,qCAA6B,EAAC,YAAY,CAAC;QAC3C,YAAY;KACf,CAAC,CAAC;IACH,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,gBAAgB,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACZ,OAAO,GAAG,SAAS,CAAC;IACxB,CAAC;IACD,OAAO;QACH,OAAO;KACV,CAAC;AACN,CAAC,CAAA,CAAC;AAjBW,QAAA,kBAAkB,sBAiB7B"}
1
+ {"version":3,"file":"login_helpers.js","sourceRoot":"","sources":["../../../src/helpers/login_helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yDAA6E;AAEtE,MAAM,6BAA6B,GAAG,CAAC,YAAoB,EAAU,EAAE;IAC1E,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,6BAA6B,iCAExC;AAEK,MAAM,sBAAsB,GAAG,CAAO,UAAkB,EAAmB,EAAE;IAChF,MAAM,WAAW,GAAkB,MAAM,IAAA,0CAAuB,EAAC,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE;QAC/F,IAAA,qCAA6B,EAAC,UAAU,CAAC;QACzC,UAAU;KACb,CAAC,CAAC;IAEH,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,MAAM,WAAW,GAAkB,MAAM,IAAA,0CAAuB,EAAC,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QACxG,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,MAAM,gBAAgB,CAAC;QAC3B,CAAC;QACD,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC,CAAA,CAAC;AAdW,QAAA,sBAAsB,0BAcjC"}
@@ -1,5 +1,4 @@
1
1
  import { MW } from "../types";
2
2
  export declare const verify_user_auth: MW;
3
- export declare const get_users_login: MW;
4
3
  export declare const nx_user_login: MW;
5
4
  export declare const client_login: MW;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.client_login = exports.nx_user_login = exports.get_users_login = exports.verify_user_auth = void 0;
12
+ exports.client_login = exports.nx_user_login = exports.verify_user_auth = void 0;
13
13
  const helpers_1 = require("../helpers");
14
14
  const managers_1 = require("../managers");
15
15
  const verify_user_auth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
@@ -24,34 +24,16 @@ const verify_user_auth = (req, res, next) => __awaiter(void 0, void 0, void 0, f
24
24
  }
25
25
  });
26
26
  exports.verify_user_auth = verify_user_auth;
27
- const get_users_login = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
28
- try {
29
- const authorization = req.headers.authorization;
30
- const user_data = yield (0, helpers_1.verify_token)(authorization);
31
- const { phone_number } = user_data;
32
- if (!phone_number) {
33
- return next();
34
- }
35
- const users = yield (0, helpers_1.get_users_by_phone)(phone_number);
36
- req.body = Object.assign(Object.assign({}, req.body), users);
37
- next();
38
- }
39
- catch (error) {
40
- managers_1.logger.error("error from verify user auth", error);
41
- res.status(403).send((0, helpers_1.json_failed)(error));
42
- }
43
- });
44
- exports.get_users_login = get_users_login;
45
27
  const nx_user_login = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
46
28
  try {
47
29
  const authorization = req.headers.authorization;
48
30
  const user_data = yield (0, helpers_1.verify_token)(authorization);
49
- const { phone_number } = user_data;
50
- if (!phone_number) {
31
+ const { phone_number, email } = user_data;
32
+ if (!phone_number && !email) {
51
33
  throw "Invalid authorization token";
52
34
  }
53
- const nx_user = yield (0, helpers_1.query_document)("nx-users", "phone_number", "in", [(0, helpers_1.convert_to_short_phone_number)(phone_number), phone_number]);
54
- req.body.nx_user = nx_user;
35
+ const nx_user = yield (0, helpers_1.get_user_by_identifier)(phone_number || email);
36
+ req.body.user = nx_user;
55
37
  next();
56
38
  }
57
39
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"auth_mw.js","sourceRoot":"","sources":["../../../src/middlewares/auth_mw.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAmJ;AACnJ,0CAAqC;AAI9B,MAAM,gBAAgB,GAAO,CAAO,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACzD,IAAI,CAAC;QACD,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;QAChD,MAAM,IAAA,sBAAY,EAAC,aAAa,CAAC,CAAC;QAClC,IAAI,EAAE,CAAC;IACX,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACl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xB,IAAI,EAAE,CAAC;IACX,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,qBAAW,EAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC,CAAA,CAAC;AAdW,QAAA,aAAa,iBAcxB;AAEK,MAAM,YAAY,GAAO,CAAO,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACrD,IAAI,CAAC;QACD,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,WAAW,GAAG,CAAC,MAAM,IAAA,iCAAuB,EAAC,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,CAAuB,CAAC;QAClH,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,IAAI,CAAC,CAAC;QAC9D,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;QAC9B,IAAI,EAAE,CAAC;IACX,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,qBAAW,EAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;IAC9D,CAAC;AACL,CAAC,CAAA,CAAC;AAfW,QAAA,YAAY,gBAevB"}
@@ -1,7 +1,3 @@
1
- import { NxUser, DefaultClient } from "akeyless-types-commons";
1
+ import { NxUser } from "akeyless-types-commons";
2
2
  export declare const convert_to_short_phone_number: (phone_number: string) => string;
3
- interface Users {
4
- nx_user?: NxUser;
5
- }
6
- export declare const get_users_by_phone: (phone_number: string, default_client_key?: DefaultClient) => Promise<Users>;
7
- export {};
3
+ export declare const get_user_by_identifier: (identifier: string) => Promise<NxUser>;
@@ -7,25 +7,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { DefaultClient } from "akeyless-types-commons";
11
10
  import { query_document_optional } from "./firebase_helpers";
12
11
  export const convert_to_short_phone_number = (phone_number) => {
13
12
  return `0${phone_number.split("+972")[1]}`;
14
13
  };
15
- export const get_users_by_phone = (phone_number_1, ...args_1) => __awaiter(void 0, [phone_number_1, ...args_1], void 0, function* (phone_number, default_client_key = DefaultClient.default) {
16
- let nx_user;
17
- const nx_user_q = yield query_document_optional("nx-users", "phone_number", "in", [
18
- convert_to_short_phone_number(phone_number),
19
- phone_number,
14
+ export const get_user_by_identifier = (identifier) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const phone_query = yield query_document_optional("nx-users", "phone_number", "in", [
16
+ convert_to_short_phone_number(identifier),
17
+ identifier,
20
18
  ]);
21
- if (!nx_user_q) {
22
- throw "User not found";
19
+ if (!phone_query) {
20
+ const email_query = yield query_document_optional("nx-users", "email", "==", identifier);
21
+ if (!email_query) {
22
+ throw "User not found";
23
+ }
24
+ return email_query;
23
25
  }
24
- if (nx_user_q) {
25
- nx_user = nx_user_q;
26
- }
27
- return {
28
- nx_user,
29
- };
26
+ return phone_query;
30
27
  });
31
28
  //# sourceMappingURL=login_helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"login_helpers.js","sourceRoot":"","sources":["../../../src/helpers/login_helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAkB,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,YAAoB,EAAU,EAAE;IAC1E,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CA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AAC;QAC3B,CAAC;QACD,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC,CAAA,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { MW } from "../types";
2
2
  export declare const verify_user_auth: MW;
3
- export declare const get_users_login: MW;
4
3
  export declare const nx_user_login: MW;
5
4
  export declare const client_login: MW;
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { verify_token, json_failed, get_users_by_phone, query_document, convert_to_short_phone_number, query_document_optional } from "../helpers";
10
+ import { verify_token, json_failed, query_document_optional, get_user_by_identifier, } from "../helpers";
11
11
  import { logger } from "../managers";
12
12
  export const verify_user_auth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
13
13
  try {
@@ -20,33 +20,16 @@ export const verify_user_auth = (req, res, next) => __awaiter(void 0, void 0, vo
20
20
  res.status(403).send(json_failed(error));
21
21
  }
22
22
  });
23
- export const get_users_login = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
24
- try {
25
- const authorization = req.headers.authorization;
26
- const user_data = yield verify_token(authorization);
27
- const { phone_number } = user_data;
28
- if (!phone_number) {
29
- return next();
30
- }
31
- const users = yield get_users_by_phone(phone_number);
32
- req.body = Object.assign(Object.assign({}, req.body), users);
33
- next();
34
- }
35
- catch (error) {
36
- logger.error("error from verify user auth", error);
37
- res.status(403).send(json_failed(error));
38
- }
39
- });
40
23
  export const nx_user_login = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
41
24
  try {
42
25
  const authorization = req.headers.authorization;
43
26
  const user_data = yield verify_token(authorization);
44
- const { phone_number } = user_data;
45
- if (!phone_number) {
27
+ const { phone_number, email } = user_data;
28
+ if (!phone_number && !email) {
46
29
  throw "Invalid authorization token";
47
30
  }
48
- const nx_user = yield query_document("nx-users", "phone_number", "in", [convert_to_short_phone_number(phone_number), phone_number]);
49
- req.body.nx_user = nx_user;
31
+ const nx_user = yield get_user_by_identifier(phone_number || email);
32
+ req.body.user = nx_user;
50
33
  next();
51
34
  }
52
35
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"auth_mw.js","sourceRoot":"","sources":["../../../src/middlewares/auth_mw.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACnJ,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,MAAM,CAAC,MAAM,gBAAgB,GAAO,CAAO,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACzD,IAAI,CAAC;QACD,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;QAChD,MAAM,YAAY,CAAC,aAAa,CAAC,CAAC;QAClC,IAAI,EAAE,CAAC;IACX,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACnD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAO,CAAO,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACxD,IAAI,CAAC;QACD,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;QAChD,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;QACnC,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,kBAA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AAI,CAAC,CAAC;QAC9D,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC;QAC9B,IAAI,EAAE,CAAC;IACX,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;IAC9D,CAAC;AACL,CAAC,CAAA,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-server-commons",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "scripts": {
5
5
  "build:cjs": "tsc --project tsconfig.cjs.json",
6
6
  "build:esm": "tsc --project tsconfig.esm.json",