@skroz/profile-api 1.0.28 → 1.0.30

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/dist/index.d.ts CHANGED
@@ -10,3 +10,5 @@ export * from './resolvers/ProfileResolver';
10
10
  export * from './resolvers/createOauthResolver';
11
11
  export * from './oauth';
12
12
  export { default as createEntityDataLoader } from './utils/createEntityDataLoader';
13
+ export { getEncryptor, getGlobalId } from './utils/encryptor';
14
+ export { default as password } from './utils/password';
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.createEntityDataLoader = void 0;
20
+ exports.password = exports.getGlobalId = exports.getEncryptor = exports.createEntityDataLoader = void 0;
21
21
  __exportStar(require("./types"), exports);
22
22
  __exportStar(require("./adapters/TypeOrmProfileAdapter"), exports);
23
23
  __exportStar(require("./entities/TypeOrmBaseEntity"), exports);
@@ -31,3 +31,8 @@ __exportStar(require("./resolvers/createOauthResolver"), exports);
31
31
  __exportStar(require("./oauth"), exports);
32
32
  var createEntityDataLoader_1 = require("./utils/createEntityDataLoader");
33
33
  Object.defineProperty(exports, "createEntityDataLoader", { enumerable: true, get: function () { return __importDefault(createEntityDataLoader_1).default; } });
34
+ var encryptor_1 = require("./utils/encryptor");
35
+ Object.defineProperty(exports, "getEncryptor", { enumerable: true, get: function () { return encryptor_1.getEncryptor; } });
36
+ Object.defineProperty(exports, "getGlobalId", { enumerable: true, get: function () { return encryptor_1.getGlobalId; } });
37
+ var password_1 = require("./utils/password");
38
+ Object.defineProperty(exports, "password", { enumerable: true, get: function () { return __importDefault(password_1).default; } });
@@ -0,0 +1,3 @@
1
+ import { Encryptor, GlobalId } from '@os-team/graphql-utils';
2
+ export declare const getEncryptor: () => Encryptor;
3
+ export declare const getGlobalId: () => GlobalId;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobalId = exports.getEncryptor = void 0;
4
+ const graphql_utils_1 = require("@os-team/graphql-utils");
5
+ let encryptor;
6
+ let globalId;
7
+ const getEncryptor = () => {
8
+ if (!encryptor) {
9
+ if (!process.env.ENCRYPTION_KEY) {
10
+ throw new Error('ENCRYPTION_KEY is not found');
11
+ }
12
+ if (!process.env.ENCRYPTION_IV) {
13
+ throw new Error('ENCRYPTION_IV is not found');
14
+ }
15
+ encryptor = new graphql_utils_1.Encryptor({
16
+ key: process.env.ENCRYPTION_KEY,
17
+ iv: process.env.ENCRYPTION_IV,
18
+ });
19
+ }
20
+ return encryptor;
21
+ };
22
+ exports.getEncryptor = getEncryptor;
23
+ const getGlobalId = () => {
24
+ if (!globalId) {
25
+ globalId = new graphql_utils_1.GlobalId((0, exports.getEncryptor)());
26
+ }
27
+ return globalId;
28
+ };
29
+ exports.getGlobalId = getGlobalId;
@@ -0,0 +1,5 @@
1
+ declare const password: {
2
+ hash: (password: string) => Promise<string>;
3
+ verify: (passwordHash: string, password: string) => Promise<boolean>;
4
+ };
5
+ export default password;
@@ -0,0 +1,15 @@
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
+ const argon2_1 = __importDefault(require("argon2"));
7
+ const hash = (password) => argon2_1.default.hash(password, {
8
+ type: argon2_1.default.argon2id,
9
+ });
10
+ const verify = (passwordHash, password) => argon2_1.default.verify(passwordHash, password);
11
+ const password = {
12
+ hash,
13
+ verify,
14
+ };
15
+ exports.default = password;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skroz/profile-api",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "license": "MIT",
5
5
  "repository": "git@gitlab.com:skroz/libs/utils.git",
6
6
  "main": "dist/index.js",
@@ -45,5 +45,5 @@
45
45
  "type-graphql": "^1.1.1",
46
46
  "typeorm": "^0.2.45"
47
47
  },
48
- "gitHead": "47d38c667bd718863616823d46460c74ad2fc5eb"
48
+ "gitHead": "5b98f9fd65dae98f6e297ed71a439820a12e96aa"
49
49
  }
package/src/index.ts CHANGED
@@ -10,3 +10,5 @@ export * from './resolvers/ProfileResolver';
10
10
  export * from './resolvers/createOauthResolver';
11
11
  export * from './oauth';
12
12
  export { default as createEntityDataLoader } from './utils/createEntityDataLoader';
13
+ export { getEncryptor, getGlobalId } from './utils/encryptor';
14
+ export { default as password } from './utils/password';
@@ -0,0 +1,27 @@
1
+ import { Encryptor, GlobalId } from '@os-team/graphql-utils';
2
+
3
+ let encryptor: Encryptor;
4
+ let globalId: GlobalId;
5
+
6
+ export const getEncryptor = () => {
7
+ if (!encryptor) {
8
+ if (!process.env.ENCRYPTION_KEY) {
9
+ throw new Error('ENCRYPTION_KEY is not found');
10
+ }
11
+ if (!process.env.ENCRYPTION_IV) {
12
+ throw new Error('ENCRYPTION_IV is not found');
13
+ }
14
+ encryptor = new Encryptor({
15
+ key: process.env.ENCRYPTION_KEY,
16
+ iv: process.env.ENCRYPTION_IV,
17
+ });
18
+ }
19
+ return encryptor;
20
+ };
21
+
22
+ export const getGlobalId = () => {
23
+ if (!globalId) {
24
+ globalId = new GlobalId(getEncryptor());
25
+ }
26
+ return globalId;
27
+ };
@@ -0,0 +1,16 @@
1
+ import argon2 from 'argon2';
2
+
3
+ const hash = (password: string) =>
4
+ argon2.hash(password, {
5
+ type: argon2.argon2id,
6
+ });
7
+
8
+ const verify = (passwordHash: string, password: string) =>
9
+ argon2.verify(passwordHash, password);
10
+
11
+ const password = {
12
+ hash,
13
+ verify,
14
+ };
15
+
16
+ export default password;