@tomei/sso 0.2.0 → 0.2.2
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/__tests__/unit/components/login-history/login-history.repository.spec.d.ts +1 -0
- package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js +99 -0
- package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js.map +1 -0
- package/dist/__tests__/unit/components/login-user/user.repository.spec.d.ts +1 -0
- package/dist/__tests__/unit/components/login-user/user.repository.spec.js +78 -0
- package/dist/__tests__/unit/components/login-user/user.repository.spec.js.map +1 -0
- package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.d.ts +1 -0
- package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js +38 -0
- package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js.map +1 -0
- package/dist/__tests__/unit/components/system/system.repository.spec.d.ts +1 -0
- package/dist/__tests__/unit/components/system/system.repository.spec.js +85 -0
- package/dist/__tests__/unit/components/system/system.repository.spec.js.map +1 -0
- package/dist/__tests__/unit/components/system-access/system-access.repository.spec.d.ts +1 -0
- package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js +75 -0
- package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js.map +1 -0
- package/dist/__tests__/unit/redis-client/redis.service.spec.d.ts +1 -0
- package/dist/__tests__/unit/redis-client/redis.service.spec.js +32 -0
- package/dist/__tests__/unit/redis-client/redis.service.spec.js.map +1 -0
- package/dist/__tests__/unit/session/session.service.spec.d.ts +1 -0
- package/dist/__tests__/unit/session/session.service.spec.js +36 -0
- package/dist/__tests__/unit/session/session.service.spec.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/src/components/index.d.ts +7 -0
- package/dist/src/components/index.js +24 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/login-history/index.d.ts +1 -0
- package/dist/src/components/login-history/index.js +18 -0
- package/dist/src/components/login-history/index.js.map +1 -0
- package/dist/src/components/login-history/login-history.repository.d.ts +9 -0
- package/dist/src/components/login-history/login-history.repository.js +50 -0
- package/dist/src/components/login-history/login-history.repository.js.map +1 -0
- package/dist/src/components/login-user/index.d.ts +3 -0
- package/dist/src/components/login-user/index.js +20 -0
- package/dist/src/components/login-user/index.js.map +1 -0
- package/dist/src/components/login-user/interfaces/index.d.ts +1 -0
- package/dist/src/components/login-user/interfaces/index.js +18 -0
- package/dist/src/components/login-user/interfaces/index.js.map +1 -0
- package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +9 -0
- package/dist/src/components/login-user/interfaces/user-info.interface.js +3 -0
- package/dist/src/components/login-user/interfaces/user-info.interface.js.map +1 -0
- package/dist/src/components/login-user/login-user.d.ts +41 -0
- package/dist/src/components/login-user/login-user.js +333 -0
- package/dist/src/components/login-user/login-user.js.map +1 -0
- package/dist/src/components/login-user/user.repository.d.ts +9 -0
- package/dist/src/components/login-user/user.repository.js +50 -0
- package/dist/src/components/login-user/user.repository.js.map +1 -0
- package/dist/src/components/password-hash/index.d.ts +2 -0
- package/dist/src/components/password-hash/index.js +19 -0
- package/dist/src/components/password-hash/index.js.map +1 -0
- package/dist/src/components/password-hash/interfaces/index.d.ts +1 -0
- package/dist/src/components/password-hash/interfaces/index.js +18 -0
- package/dist/src/components/password-hash/interfaces/index.js.map +1 -0
- package/dist/src/components/password-hash/interfaces/password-hash-service.interface.d.ts +4 -0
- package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js +3 -0
- package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js.map +1 -0
- package/dist/src/components/password-hash/password-hash.service.d.ts +6 -0
- package/dist/src/components/password-hash/password-hash.service.js +28 -0
- package/dist/src/components/password-hash/password-hash.service.js.map +1 -0
- package/dist/src/components/system/index.d.ts +1 -0
- package/dist/src/components/system/index.js +18 -0
- package/dist/src/components/system/index.js.map +1 -0
- package/dist/src/components/system/system.repository.d.ts +9 -0
- package/dist/src/components/system/system.repository.js +50 -0
- package/dist/src/components/system/system.repository.js.map +1 -0
- package/dist/src/components/system-access/index.d.ts +1 -0
- package/dist/src/components/system-access/index.js +18 -0
- package/dist/src/components/system-access/index.js.map +1 -0
- package/dist/src/components/system-access/system-access.repository.d.ts +9 -0
- package/dist/src/components/system-access/system-access.repository.js +50 -0
- package/dist/src/components/system-access/system-access.repository.js.map +1 -0
- package/dist/src/components/user-group/index.d.ts +1 -0
- package/dist/src/components/user-group/index.js +18 -0
- package/dist/src/components/user-group/index.js.map +1 -0
- package/dist/src/components/user-group/user-group.repository.d.ts +9 -0
- package/dist/src/components/user-group/user-group.repository.js +50 -0
- package/dist/src/components/user-group/user-group.repository.js.map +1 -0
- package/dist/src/components/user-user-group/index.d.ts +1 -0
- package/dist/src/components/user-user-group/index.js +18 -0
- package/dist/src/components/user-user-group/index.js.map +1 -0
- package/dist/src/components/user-user-group/user-user-group.repository.d.ts +9 -0
- package/dist/src/components/user-user-group/user-user-group.repository.js +50 -0
- package/dist/src/components/user-user-group/user-user-group.repository.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +24 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/index.d.ts +2 -0
- package/dist/src/interfaces/index.js +19 -0
- package/dist/src/interfaces/index.js.map +1 -0
- package/dist/src/interfaces/system-login.interface.d.ts +6 -0
- package/dist/src/interfaces/system-login.interface.js +3 -0
- package/dist/src/interfaces/system-login.interface.js.map +1 -0
- package/dist/src/interfaces/user-session.interface.d.ts +4 -0
- package/dist/src/interfaces/user-session.interface.js +3 -0
- package/dist/src/interfaces/user-session.interface.js.map +1 -0
- package/dist/src/mail/index.d.ts +2 -0
- package/dist/src/mail/index.js +19 -0
- package/dist/src/mail/index.js.map +1 -0
- package/dist/src/mail/interfaces/index.d.ts +2 -0
- package/dist/src/mail/interfaces/index.js +19 -0
- package/dist/src/mail/interfaces/index.js.map +1 -0
- package/dist/src/mail/interfaces/send-mail.interface.d.ts +8 -0
- package/dist/src/mail/interfaces/send-mail.interface.js +3 -0
- package/dist/src/mail/interfaces/send-mail.interface.js.map +1 -0
- package/dist/src/mail/interfaces/send-new-login-alert.interface.d.ts +6 -0
- package/dist/src/mail/interfaces/send-new-login-alert.interface.js +3 -0
- package/dist/src/mail/interfaces/send-new-login-alert.interface.js.map +1 -0
- package/dist/src/mail/mail.d.ts +7 -0
- package/dist/src/mail/mail.js +49 -0
- package/dist/src/mail/mail.js.map +1 -0
- package/dist/src/mail/mail.service.d.ts +7 -0
- package/dist/src/mail/mail.service.js +42 -0
- package/dist/src/mail/mail.service.js.map +1 -0
- package/dist/src/prisma-client/__mocks__/prisma.d.ts +3 -0
- package/dist/src/prisma-client/__mocks__/prisma.js +14 -0
- package/dist/src/prisma-client/__mocks__/prisma.js.map +1 -0
- package/dist/src/prisma-client/client.d.ts +3 -0
- package/dist/src/prisma-client/client.js +6 -0
- package/dist/src/prisma-client/client.js.map +1 -0
- package/dist/src/prisma-client/index.d.ts +1 -0
- package/dist/src/prisma-client/index.js +18 -0
- package/dist/src/prisma-client/index.js.map +1 -0
- package/dist/src/redis-client/__mocks__/jest-initial-setup.d.ts +1 -0
- package/dist/src/redis-client/__mocks__/jest-initial-setup.js +5 -0
- package/dist/src/redis-client/__mocks__/jest-initial-setup.js.map +1 -0
- package/dist/src/redis-client/__mocks__/redis-mock.d.ts +2 -0
- package/dist/src/redis-client/__mocks__/redis-mock.js +23 -0
- package/dist/src/redis-client/__mocks__/redis-mock.js.map +1 -0
- package/dist/src/redis-client/index.d.ts +1 -0
- package/dist/src/redis-client/index.js +18 -0
- package/dist/src/redis-client/index.js.map +1 -0
- package/dist/src/redis-client/redis.service.d.ts +7 -0
- package/dist/src/redis-client/redis.service.js +56 -0
- package/dist/src/redis-client/redis.service.js.map +1 -0
- package/dist/src/session/index.d.ts +2 -0
- package/dist/src/session/index.js +19 -0
- package/dist/src/session/index.js.map +1 -0
- package/dist/src/session/interfaces/index.d.ts +1 -0
- package/dist/src/session/interfaces/index.js +18 -0
- package/dist/src/session/interfaces/index.js.map +1 -0
- package/dist/src/session/interfaces/session-service.interface.d.ts +5 -0
- package/dist/src/session/interfaces/session-service.interface.js +3 -0
- package/dist/src/session/interfaces/session-service.interface.js.map +1 -0
- package/dist/src/session/session.service.d.ts +9 -0
- package/dist/src/session/session.service.js +52 -0
- package/dist/src/session/session.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/index.ts +1 -0
- package/package.json +1 -1
- package/src/components/login-user/login-user.ts +4 -1
- package/tsconfig.build.json +2 -1
- package/tsconfig.json +2 -5
@@ -0,0 +1,49 @@
|
|
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
|
+
const nodemailer = require("nodemailer");
|
13
|
+
class Mail {
|
14
|
+
constructor() { }
|
15
|
+
static init() {
|
16
|
+
if (!Mail.transporter) {
|
17
|
+
Mail.transporter = nodemailer.createTransport({
|
18
|
+
host: process.env.SMTP_HOST,
|
19
|
+
port: Number(process.env.SMTP_PORT),
|
20
|
+
secure: Number(process.env.SMTP_PORT) === 465,
|
21
|
+
auth: {
|
22
|
+
user: process.env.EMAIL_SENDER,
|
23
|
+
pass: process.env.EMAIL_PASSWORD,
|
24
|
+
},
|
25
|
+
});
|
26
|
+
}
|
27
|
+
return new Mail();
|
28
|
+
}
|
29
|
+
sendMail(options) {
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
31
|
+
try {
|
32
|
+
yield Mail.transporter.sendMail({
|
33
|
+
from: process.env.EMAIL_SENDER,
|
34
|
+
to: options.to,
|
35
|
+
cc: options.cc,
|
36
|
+
bcc: options.bcc,
|
37
|
+
subject: options.subject,
|
38
|
+
text: options.text,
|
39
|
+
html: options.html,
|
40
|
+
});
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
throw error;
|
44
|
+
}
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
exports.default = Mail;
|
49
|
+
//# sourceMappingURL=mail.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mail.js","sourceRoot":"","sources":["../../../src/mail/mail.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yCAAyC;AAGzC,MAAqB,IAAI;IAGvB,gBAAe,CAAC;IAEhB,MAAM,CAAC,IAAI;QACT,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;gBAC5C,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;gBAC3B,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;gBACnC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG;gBAC7C,IAAI,EAAE;oBACJ,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;oBAC9B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;iBACjC;aACF,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,IAAI,EAAE,CAAC;IACpB,CAAC;IAGK,QAAQ,CAAC,OAAkC;;YAC/C,IAAI;gBACF,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;oBAC9B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;oBAC9B,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,EAAE,EAAE,OAAO,CAAC,EAAE;oBACd,GAAG,EAAE,OAAO,CAAC,GAAG;oBAChB,OAAO,EAAE,OAAO,CAAC,OAAO;oBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;oBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;iBACnB,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AApCD,uBAoCC"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { ISendNewLoginAlertOptions } from './interfaces/send-new-login-alert.interface';
|
2
|
+
import Mail from './mail';
|
3
|
+
export declare class MailService {
|
4
|
+
MailClient: Mail;
|
5
|
+
constructor();
|
6
|
+
sendNewLoginAlertEmail(options: ISendNewLoginAlertOptions): Promise<void>;
|
7
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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.MailService = void 0;
|
13
|
+
const mail_1 = require("./mail");
|
14
|
+
class MailService {
|
15
|
+
constructor() {
|
16
|
+
this.MailClient = mail_1.default.init();
|
17
|
+
}
|
18
|
+
sendNewLoginAlertEmail(options) {
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
20
|
+
try {
|
21
|
+
yield this.MailClient.sendMail({
|
22
|
+
to: options.Email,
|
23
|
+
subject: 'New Login Alert',
|
24
|
+
html: `<p>Dear ${options.Name},</p>
|
25
|
+
<p>There was a new login to your account from ${options.IpAddress} on ${options.LoginDate.toLocaleString()}.</p>
|
26
|
+
<p>If this was you, you can safely ignore this email.</p>
|
27
|
+
<p>If you suspect that someone else is trying to access your account, please contact us immediately at itd-support@tomei.com.my.</p>
|
28
|
+
<p>Thank you!,</p>
|
29
|
+
<p>
|
30
|
+
Best Regards,
|
31
|
+
IT Department
|
32
|
+
</p>`,
|
33
|
+
});
|
34
|
+
}
|
35
|
+
catch (error) {
|
36
|
+
throw error;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
}
|
40
|
+
}
|
41
|
+
exports.MailService = MailService;
|
42
|
+
//# sourceMappingURL=mail.service.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mail.service.js","sourceRoot":"","sources":["../../../src/mail/mail.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iCAA0B;AAE1B,MAAa,WAAW;IAEtB;QACE,IAAI,CAAC,UAAU,GAAG,cAAI,CAAC,IAAI,EAAE,CAAC;IAChC,CAAC;IAEY,sBAAsB,CACjC,OAAkC;;YAElC,IAAI;gBACF,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;oBAC7B,EAAE,EAAE,OAAO,CAAC,KAAK;oBACjB,OAAO,EAAE,iBAAiB;oBAC1B,IAAI,EAAE,WAAW,OAAO,CAAC,IAAI;gEAEnB,OAAO,CAAC,SACV,OAAO,OAAO,CAAC,SAAS,CAAC,cAAc,EAAE;;;;;;;qBAOpC;iBACd,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AA7BD,kCA6BC"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
2
|
+
import { DeepMockProxy } from 'jest-mock-extended';
|
3
|
+
export declare const prismaMock: DeepMockProxy<PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import(".prisma/client").Prisma.RejectOnNotFound | import(".prisma/client").Prisma.RejectPerOperation | undefined>>;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.prismaMock = void 0;
|
4
|
+
const jest_mock_extended_1 = require("jest-mock-extended");
|
5
|
+
const client_1 = require("../client");
|
6
|
+
jest.mock('../client', () => ({
|
7
|
+
__esModule: true,
|
8
|
+
default: (0, jest_mock_extended_1.mockDeep)(),
|
9
|
+
}));
|
10
|
+
beforeEach(() => {
|
11
|
+
(0, jest_mock_extended_1.mockReset)(exports.prismaMock);
|
12
|
+
});
|
13
|
+
exports.prismaMock = client_1.default;
|
14
|
+
//# sourceMappingURL=prisma.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"prisma.js","sourceRoot":"","sources":["../../../../src/prisma-client/__mocks__/prisma.ts"],"names":[],"mappings":";;;AACA,2DAAwE;AAExE,sCAA+B;AAE/B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5B,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,IAAA,6BAAQ,GAAgB;CAClC,CAAC,CAAC,CAAC;AAEJ,UAAU,CAAC,GAAG,EAAE;IACd,IAAA,8BAAS,EAAC,kBAAU,CAAC,CAAC;AACxB,CAAC,CAAC,CAAC;AAEU,QAAA,UAAU,GAAG,gBAAgD,CAAC"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
2
|
+
declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import(".prisma/client").Prisma.RejectOnNotFound | import(".prisma/client").Prisma.RejectPerOperation | undefined>;
|
3
|
+
export default prisma;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/prisma-client/client.ts"],"names":[],"mappings":";;AAAA,2CAA8C;AAC9C,MAAM,MAAM,GAAG,IAAI,qBAAY,EAAE,CAAC;AAClC,kBAAe,MAAM,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './client';
|
@@ -0,0 +1,18 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./client"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/prisma-client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"jest-initial-setup.js","sourceRoot":"","sources":["../../../../src/redis-client/__mocks__/jest-initial-setup.ts"],"names":[],"mappings":";;AAAA,6CAAiC;AACjC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,oBAAK,CAAC,CAAC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const redis_mock_1 = require("redis-mock");
|
4
|
+
const util_1 = require("util");
|
5
|
+
const client = (0, redis_mock_1.createClient)();
|
6
|
+
const setEx = (0, util_1.promisify)(client.setex).bind(client);
|
7
|
+
const v4Client = {
|
8
|
+
connect: () => undefined,
|
9
|
+
get: (0, util_1.promisify)(client.get).bind(client),
|
10
|
+
set: (0, util_1.promisify)(client.set).bind(client),
|
11
|
+
del: (0, util_1.promisify)(client.del).bind(client),
|
12
|
+
hSet: (0, util_1.promisify)(client.hset).bind(client),
|
13
|
+
hGet: (0, util_1.promisify)(client.hget).bind(client),
|
14
|
+
hDel: (0, util_1.promisify)(client.hdel).bind(client),
|
15
|
+
flushAll: (0, util_1.promisify)(client.flushall).bind(client),
|
16
|
+
setEx: (0, util_1.promisify)(client.setex).bind(client),
|
17
|
+
expire: (0, util_1.promisify)(client.expire).bind(client),
|
18
|
+
mGet: (0, util_1.promisify)(client.mget).bind(client),
|
19
|
+
pSetEx: (key, ms, value) => setEx(key, ms / 1000, value),
|
20
|
+
on: () => undefined,
|
21
|
+
};
|
22
|
+
exports.default = Object.assign(Object.assign({}, redis_mock_1.default), { createClient: () => v4Client });
|
23
|
+
//# sourceMappingURL=redis-mock.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redis-mock.js","sourceRoot":"","sources":["../../../../src/redis-client/__mocks__/redis-mock.ts"],"names":[],"mappings":";;AAIA,2CAAiD;AAGjD,+BAAiC;AACjC,MAAM,MAAM,GAAG,IAAA,yBAAY,GAA4B,CAAC;AACxD,MAAM,KAAK,GAAG,IAAA,gBAAS,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnD,MAAM,QAAQ,GAAG;IACf,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;IACxB,GAAG,EAAE,IAAA,gBAAS,EAAC,MAAM,CAAC,GAAG,CAAC,C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) || (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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./redis.service"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/redis-client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
|
@@ -0,0 +1,56 @@
|
|
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.RedisService = void 0;
|
13
|
+
const redis_1 = require("redis");
|
14
|
+
class RedisService {
|
15
|
+
constructor() { }
|
16
|
+
static init() {
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
18
|
+
if (!RedisService.client) {
|
19
|
+
RedisService.client = (0, redis_1.createClient)({
|
20
|
+
url: process.env.REDIS_URL,
|
21
|
+
password: process.env.REDIS_PASSWORD,
|
22
|
+
});
|
23
|
+
RedisService.client.on('error', (error) => {
|
24
|
+
console.error('Redis error:', error);
|
25
|
+
});
|
26
|
+
RedisService.client.on('connect', () => console.log('Redis connected'));
|
27
|
+
RedisService.client.on('reconnecting', () => console.log('Redis reconnecting'));
|
28
|
+
yield RedisService.client.connect();
|
29
|
+
}
|
30
|
+
return new RedisService();
|
31
|
+
});
|
32
|
+
}
|
33
|
+
set(key, value, expire = 3600 * 24 * 1) {
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
35
|
+
try {
|
36
|
+
const newList = typeof value === 'string' ? value : JSON.stringify(value);
|
37
|
+
yield RedisService.client.setEx(key, expire, newList);
|
38
|
+
}
|
39
|
+
catch (error) {
|
40
|
+
console.log(error);
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
get(key) {
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
46
|
+
try {
|
47
|
+
return yield RedisService.client.get(key);
|
48
|
+
}
|
49
|
+
catch (error) {
|
50
|
+
throw error;
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
55
|
+
exports.RedisService = RedisService;
|
56
|
+
//# sourceMappingURL=redis.service.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"redis.service.js","sourceRoot":"","sources":["../../../src/redis-client/redis.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAqC;AACrC,MAAa,YAAY;IAGvB,gBAAuB,CAAC;IAExB,MAAM,CAAO,IAAI;;YACf,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;gBAExB,YAAY,CAAC,MAAM,GAAG,IAAA,oBAAY,EAAC;oBACjC,GA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,CAAC;KAAA;CACF;AA9CD,oCA8CC"}
|
@@ -0,0 +1,19 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./interfaces"), exports);
|
18
|
+
__exportStar(require("./session.service"), exports);
|
19
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/session/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,oDAAkC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './session-service.interface';
|
@@ -0,0 +1,18 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./session-service.interface"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/session/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"session-service.interface.js","sourceRoot":"","sources":["../../../../src/session/interfaces/session-service.interface.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ISessionService } from './interfaces/session-service.interface';
|
2
|
+
import { IUserSession } from '../interfaces/user-session.interface';
|
3
|
+
export declare class SessionService implements ISessionService {
|
4
|
+
private static _RedisService;
|
5
|
+
private constructor();
|
6
|
+
static init(): Promise<SessionService>;
|
7
|
+
setUserSession(userId: string, sessionData: IUserSession): Promise<void>;
|
8
|
+
retrieveUserSession(userId: string): Promise<IUserSession>;
|
9
|
+
}
|
@@ -0,0 +1,52 @@
|
|
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.SessionService = void 0;
|
13
|
+
const redis_service_1 = require("../redis-client/redis.service");
|
14
|
+
class SessionService {
|
15
|
+
constructor() { }
|
16
|
+
static init() {
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
18
|
+
const sessionService = new SessionService();
|
19
|
+
SessionService._RedisService = yield redis_service_1.RedisService.init();
|
20
|
+
return sessionService;
|
21
|
+
});
|
22
|
+
}
|
23
|
+
setUserSession(userId, sessionData) {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
try {
|
26
|
+
const key = `tomei-sid:${userId}`;
|
27
|
+
yield SessionService._RedisService.set(key, sessionData, 60 * 60 * 24 * 1);
|
28
|
+
}
|
29
|
+
catch (error) {
|
30
|
+
throw error;
|
31
|
+
}
|
32
|
+
});
|
33
|
+
}
|
34
|
+
retrieveUserSession(userId) {
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
36
|
+
try {
|
37
|
+
const key = `tomei-sid:${userId}`;
|
38
|
+
const stringData = yield SessionService._RedisService.get(key);
|
39
|
+
if (!stringData)
|
40
|
+
return {
|
41
|
+
systemLogins: [],
|
42
|
+
};
|
43
|
+
return JSON.parse(stringData);
|
44
|
+
}
|
45
|
+
catch (error) {
|
46
|
+
throw error;
|
47
|
+
}
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}
|
51
|
+
exports.SessionService = SessionService;
|
52
|
+
//# sourceMappingURL=session.service.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"session.service.js","sourceRoot":"","sources":["../../../src/session/session.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAA6D;AAI7D,MAAa,cAAc;IAGzB,gBAAuB,CAAC;IAExB,MAAM,CAAO,IAAI;;YACf,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC;YAC5C,cAAc,CAAC,aAAa,GAAG,MAAM,4BAAY,CAAC,IAAI,EAAE,CAAC;YACzD,OAAO,cAAc,CAAC;QACxB,CAAC;KAAA;IAEK,cAAc,CAClB,MAAc,EACd,WAAyB;;YAEzB,IAAI;gBACF,MAAM,GAAG,GAAG,aAAa,MAAM,EAAE,CAAC;gBAClC,MAAM,cAAc,CAAC,aAAa,CAAC,GAAG,CACpC,GAAG,EACH,WAAW,EACX,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CACjB,CAAC;aACH;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;IAEK,mBAAmB,CAAC,MAAc;;YACtC,IAAI;gBACF,MAAM,GAAG,GAAG,aAAa,MAAM,EAAE,CAAC;gBAClC,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAC/D,IAAI,CAAC,UAAU;oBACb,OAAO;wBACL,YAAY,EAAE,EAAE;qBACjB,CAAC;gBACJ,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;aAC/B;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AAxCD,wCAwCC"}
|