@famir/database 0.0.1
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/README.md +4 -0
- package/dist/database.d.ts +27 -0
- package/dist/database.error.d.ts +9 -0
- package/dist/database.error.js +13 -0
- package/dist/database.error.js.map +1 -0
- package/dist/database.functions.d.ts +242 -0
- package/dist/database.functions.js +17 -0
- package/dist/database.functions.js.map +1 -0
- package/dist/database.js +5 -0
- package/dist/database.js.map +1 -0
- package/dist/database.keys.d.ts +21 -0
- package/dist/database.keys.js +67 -0
- package/dist/database.keys.js.map +1 -0
- package/dist/database.schemas.d.ts +3 -0
- package/dist/database.schemas.js +12 -0
- package/dist/database.schemas.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/models/campaign/campaign.d.ts +24 -0
- package/dist/models/campaign/campaign.js +47 -0
- package/dist/models/campaign/campaign.js.map +1 -0
- package/dist/models/campaign/index.d.ts +1 -0
- package/dist/models/campaign/index.js +2 -0
- package/dist/models/campaign/index.js.map +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.js +8 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/lure/index.d.ts +1 -0
- package/dist/models/lure/index.js +2 -0
- package/dist/models/lure/index.js.map +1 -0
- package/dist/models/lure/lure.d.ts +17 -0
- package/dist/models/lure/lure.js +25 -0
- package/dist/models/lure/lure.js.map +1 -0
- package/dist/models/message/index.d.ts +1 -0
- package/dist/models/message/index.js +2 -0
- package/dist/models/message/index.js.map +1 -0
- package/dist/models/message/message.d.ts +38 -0
- package/dist/models/message/message.js +58 -0
- package/dist/models/message/message.js.map +1 -0
- package/dist/models/proxy/index.d.ts +1 -0
- package/dist/models/proxy/index.js +2 -0
- package/dist/models/proxy/index.js.map +1 -0
- package/dist/models/proxy/proxy.d.ts +16 -0
- package/dist/models/proxy/proxy.js +23 -0
- package/dist/models/proxy/proxy.js.map +1 -0
- package/dist/models/redirector/index.d.ts +1 -0
- package/dist/models/redirector/index.js +2 -0
- package/dist/models/redirector/index.js.map +1 -0
- package/dist/models/redirector/redirector.d.ts +12 -0
- package/dist/models/redirector/redirector.js +23 -0
- package/dist/models/redirector/redirector.js.map +1 -0
- package/dist/models/session/index.d.ts +1 -0
- package/dist/models/session/index.js +2 -0
- package/dist/models/session/index.js.map +1 -0
- package/dist/models/session/session.d.ts +13 -0
- package/dist/models/session/session.js +27 -0
- package/dist/models/session/session.js.map +1 -0
- package/dist/models/target/index.d.ts +1 -0
- package/dist/models/target/index.js +2 -0
- package/dist/models/target/index.js.map +1 -0
- package/dist/models/target/target.d.ts +51 -0
- package/dist/models/target/target.js +110 -0
- package/dist/models/target/target.js.map +1 -0
- package/dist/redis-database-connector.d.ts +15 -0
- package/dist/redis-database-connector.js +47 -0
- package/dist/redis-database-connector.js.map +1 -0
- package/dist/redis-database-manager.d.ts +11 -0
- package/dist/redis-database-manager.js +27 -0
- package/dist/redis-database-manager.js.map +1 -0
- package/dist/redis-functions.d.ts +1 -0
- package/dist/redis-functions.js +1396 -0
- package/dist/redis-functions.js.map +1 -0
- package/dist/repositories/base/index.d.ts +1 -0
- package/dist/repositories/base/index.js +2 -0
- package/dist/repositories/base/index.js.map +1 -0
- package/dist/repositories/base/redis-base.repository.d.ts +23 -0
- package/dist/repositories/base/redis-base.repository.js +140 -0
- package/dist/repositories/base/redis-base.repository.js.map +1 -0
- package/dist/repositories/campaign/campaign.d.ts +13 -0
- package/dist/repositories/campaign/campaign.functions.d.ts +66 -0
- package/dist/repositories/campaign/campaign.functions.js +111 -0
- package/dist/repositories/campaign/campaign.functions.js.map +1 -0
- package/dist/repositories/campaign/campaign.js +2 -0
- package/dist/repositories/campaign/campaign.js.map +1 -0
- package/dist/repositories/campaign/campaign.schemas.d.ts +9 -0
- package/dist/repositories/campaign/campaign.schemas.js +148 -0
- package/dist/repositories/campaign/campaign.schemas.js.map +1 -0
- package/dist/repositories/campaign/index.d.ts +3 -0
- package/dist/repositories/campaign/index.js +4 -0
- package/dist/repositories/campaign/index.js.map +1 -0
- package/dist/repositories/campaign/redis-campaign.repository.d.ts +25 -0
- package/dist/repositories/campaign/redis-campaign.repository.js +138 -0
- package/dist/repositories/campaign/redis-campaign.repository.js.map +1 -0
- package/dist/repositories/index.d.ts +8 -0
- package/dist/repositories/index.js +9 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/repositories/lure/index.d.ts +3 -0
- package/dist/repositories/lure/index.js +4 -0
- package/dist/repositories/lure/index.js.map +1 -0
- package/dist/repositories/lure/lure.d.ts +11 -0
- package/dist/repositories/lure/lure.functions.d.ts +49 -0
- package/dist/repositories/lure/lure.functions.js +82 -0
- package/dist/repositories/lure/lure.functions.js.map +1 -0
- package/dist/repositories/lure/lure.js +2 -0
- package/dist/repositories/lure/lure.js.map +1 -0
- package/dist/repositories/lure/lure.schemas.d.ts +3 -0
- package/dist/repositories/lure/lure.schemas.js +45 -0
- package/dist/repositories/lure/lure.schemas.js.map +1 -0
- package/dist/repositories/lure/redis-lure.repository.d.ts +21 -0
- package/dist/repositories/lure/redis-lure.repository.js +107 -0
- package/dist/repositories/lure/redis-lure.repository.js.map +1 -0
- package/dist/repositories/message/index.d.ts +3 -0
- package/dist/repositories/message/index.js +4 -0
- package/dist/repositories/message/index.js.map +1 -0
- package/dist/repositories/message/message.d.ts +6 -0
- package/dist/repositories/message/message.functions.d.ts +44 -0
- package/dist/repositories/message/message.functions.js +53 -0
- package/dist/repositories/message/message.functions.js.map +1 -0
- package/dist/repositories/message/message.js +2 -0
- package/dist/repositories/message/message.js.map +1 -0
- package/dist/repositories/message/message.schemas.d.ts +2 -0
- package/dist/repositories/message/message.schemas.js +206 -0
- package/dist/repositories/message/message.schemas.js.map +1 -0
- package/dist/repositories/message/redis-message.repository.d.ts +20 -0
- package/dist/repositories/message/redis-message.repository.js +72 -0
- package/dist/repositories/message/redis-message.repository.js.map +1 -0
- package/dist/repositories/proxy/index.d.ts +3 -0
- package/dist/repositories/proxy/index.js +4 -0
- package/dist/repositories/proxy/index.js.map +1 -0
- package/dist/repositories/proxy/proxy.d.ts +10 -0
- package/dist/repositories/proxy/proxy.functions.d.ts +43 -0
- package/dist/repositories/proxy/proxy.functions.js +72 -0
- package/dist/repositories/proxy/proxy.functions.js.map +1 -0
- package/dist/repositories/proxy/proxy.js +2 -0
- package/dist/repositories/proxy/proxy.js.map +1 -0
- package/dist/repositories/proxy/proxy.schemas.d.ts +3 -0
- package/dist/repositories/proxy/proxy.schemas.js +34 -0
- package/dist/repositories/proxy/proxy.schemas.js.map +1 -0
- package/dist/repositories/proxy/redis-proxy.repository.d.ts +20 -0
- package/dist/repositories/proxy/redis-proxy.repository.js +93 -0
- package/dist/repositories/proxy/redis-proxy.repository.js.map +1 -0
- package/dist/repositories/redirector/index.d.ts +3 -0
- package/dist/repositories/redirector/index.js +4 -0
- package/dist/repositories/redirector/index.js.map +1 -0
- package/dist/repositories/redirector/redirector.d.ts +11 -0
- package/dist/repositories/redirector/redirector.functions.d.ts +44 -0
- package/dist/repositories/redirector/redirector.functions.js +70 -0
- package/dist/repositories/redirector/redirector.functions.js.map +1 -0
- package/dist/repositories/redirector/redirector.js +2 -0
- package/dist/repositories/redirector/redirector.js.map +1 -0
- package/dist/repositories/redirector/redirector.schemas.d.ts +3 -0
- package/dist/repositories/redirector/redirector.schemas.js +51 -0
- package/dist/repositories/redirector/redirector.schemas.js.map +1 -0
- package/dist/repositories/redirector/redis-redirector.repository.d.ts +23 -0
- package/dist/repositories/redirector/redis-redirector.repository.js +121 -0
- package/dist/repositories/redirector/redis-redirector.repository.js.map +1 -0
- package/dist/repositories/session/index.d.ts +3 -0
- package/dist/repositories/session/index.js +4 -0
- package/dist/repositories/session/index.js.map +1 -0
- package/dist/repositories/session/redis-session.repository.d.ts +18 -0
- package/dist/repositories/session/redis-session.repository.js +85 -0
- package/dist/repositories/session/redis-session.repository.js.map +1 -0
- package/dist/repositories/session/session.d.ts +8 -0
- package/dist/repositories/session/session.functions.d.ts +35 -0
- package/dist/repositories/session/session.functions.js +47 -0
- package/dist/repositories/session/session.functions.js.map +1 -0
- package/dist/repositories/session/session.js +2 -0
- package/dist/repositories/session/session.js.map +1 -0
- package/dist/repositories/session/session.schemas.d.ts +2 -0
- package/dist/repositories/session/session.schemas.js +44 -0
- package/dist/repositories/session/session.schemas.js.map +1 -0
- package/dist/repositories/target/index.d.ts +3 -0
- package/dist/repositories/target/index.js +4 -0
- package/dist/repositories/target/index.js.map +1 -0
- package/dist/repositories/target/redis-target.repository.d.ts +30 -0
- package/dist/repositories/target/redis-target.repository.js +198 -0
- package/dist/repositories/target/redis-target.repository.js.map +1 -0
- package/dist/repositories/target/target.d.ts +17 -0
- package/dist/repositories/target/target.functions.d.ts +89 -0
- package/dist/repositories/target/target.functions.js +184 -0
- package/dist/repositories/target/target.functions.js.map +1 -0
- package/dist/repositories/target/target.js +2 -0
- package/dist/repositories/target/target.js.map +1 -0
- package/dist/repositories/target/target.schemas.d.ts +13 -0
- package/dist/repositories/target/target.schemas.js +241 -0
- package/dist/repositories/target/target.schemas.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CONFIG } from '@famir/config';
|
|
2
|
+
import { LOGGER } from '@famir/logger';
|
|
3
|
+
import { VALIDATOR } from '@famir/validator';
|
|
4
|
+
import { DATABASE_CONNECTOR } from '../../database.js';
|
|
5
|
+
import { ProxyModel } from '../../models/index.js';
|
|
6
|
+
import { RedisBaseRepository } from '../base/index.js';
|
|
7
|
+
import { PROXY_REPOSITORY } from './proxy.js';
|
|
8
|
+
import { proxySchemas } from './proxy.schemas.js';
|
|
9
|
+
export class RedisProxyRepository extends RedisBaseRepository {
|
|
10
|
+
static inject(container) {
|
|
11
|
+
container.registerSingleton(PROXY_REPOSITORY, (c) => new RedisProxyRepository(c.resolve(VALIDATOR), c.resolve(CONFIG), c.resolve(LOGGER), c.resolve(DATABASE_CONNECTOR).connection()));
|
|
12
|
+
}
|
|
13
|
+
constructor(validator, config, logger, connection) {
|
|
14
|
+
super(validator, config, logger, connection, 'proxy');
|
|
15
|
+
this.validator.addSchemas(proxySchemas);
|
|
16
|
+
this.logger.debug(`ProxyRepository initialized`);
|
|
17
|
+
}
|
|
18
|
+
async create(campaignId, proxyId, url, lockSecret) {
|
|
19
|
+
try {
|
|
20
|
+
const statusReply = await this.connection.proxy.create_proxy(this.options.prefix, campaignId, proxyId, url, lockSecret);
|
|
21
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
22
|
+
this.logger.info(mesg, { proxy: { campaignId, proxyId } });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
this.raiseError(error, 'create', { campaignId, proxyId });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async read(campaignId, proxyId) {
|
|
29
|
+
try {
|
|
30
|
+
const rawModel = await this.connection.proxy.read_proxy(this.options.prefix, campaignId, proxyId);
|
|
31
|
+
return this.buildModel(rawModel);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.raiseError(error, 'read', { campaignId, proxyId });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async enable(campaignId, proxyId, lockSecret) {
|
|
38
|
+
try {
|
|
39
|
+
const statusReply = await this.connection.proxy.enable_proxy(this.options.prefix, campaignId, proxyId, lockSecret);
|
|
40
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
41
|
+
this.logger.info(mesg, { proxy: { campaignId, proxyId } });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
this.raiseError(error, 'enable', { campaignId, proxyId });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async disable(campaignId, proxyId, lockSecret) {
|
|
48
|
+
try {
|
|
49
|
+
const statusReply = await this.connection.proxy.disable_proxy(this.options.prefix, campaignId, proxyId, lockSecret);
|
|
50
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
51
|
+
this.logger.info(mesg, { proxy: { campaignId, proxyId } });
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.raiseError(error, 'disable', { campaignId, proxyId });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async delete(campaignId, proxyId, lockSecret) {
|
|
58
|
+
try {
|
|
59
|
+
const statusReply = await this.connection.proxy.delete_proxy(this.options.prefix, campaignId, proxyId, lockSecret);
|
|
60
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
61
|
+
this.logger.info(mesg, { proxy: { campaignId, proxyId } });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.raiseError(error, 'delete', { campaignId, proxyId });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async list(campaignId) {
|
|
68
|
+
try {
|
|
69
|
+
const index = await this.connection.proxy.read_proxy_index(this.options.prefix, campaignId);
|
|
70
|
+
if (index === null) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
this.validateArrayStringsReply(index);
|
|
74
|
+
const rawCollection = await Promise.all(index.map((proxyId) => this.connection.proxy.read_proxy(this.options.prefix, campaignId, proxyId)));
|
|
75
|
+
return this.buildCollection(rawCollection);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.raiseError(error, 'list', { campaignId });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
buildModel(rawModel) {
|
|
82
|
+
if (rawModel === null) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
this.validateRawData('database-raw-proxy', rawModel);
|
|
86
|
+
return new ProxyModel(rawModel.campaign_id, rawModel.proxy_id, rawModel.url, !!rawModel.is_enabled, rawModel.message_count, new Date(rawModel.created_at));
|
|
87
|
+
}
|
|
88
|
+
buildCollection(rawCollection) {
|
|
89
|
+
this.validateArrayReply(rawCollection);
|
|
90
|
+
return rawCollection.map((rawModel) => this.buildModel(rawModel)).filter(ProxyModel.isNotNull);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=redis-proxy.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-proxy.repository.js","sourceRoot":"","sources":["../../../src/repositories/proxy/redis-proxy.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAU,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAU,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAa,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAInB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,gBAAgB,EAAmB,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,OAAO,oBAAqB,SAAQ,mBAAmB;IAC3D,MAAM,CAAC,MAAM,CAAC,SAAsB;QAClC,SAAS,CAAC,iBAAiB,CACzB,gBAAgB,EAChB,CAAC,CAAC,EAAE,EAAE,CACJ,IAAI,oBAAoB,CACtB,CAAC,CAAC,OAAO,CAAY,SAAS,CAAC,EAC/B,CAAC,CAAC,OAAO,CAA8B,MAAM,CAAC,EAC9C,CAAC,CAAC,OAAO,CAAS,MAAM,CAAC,EACzB,CAAC,CAAC,OAAO,CAAoB,kBAAkB,CAAC,CAAC,UAAU,EAA2B,CACvF,CACJ,CAAA;IACH,CAAC;IAED,YACE,SAAoB,EACpB,MAAmC,EACnC,MAAc,EACd,UAAmC;QAEnC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;QAErD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;QAEvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAClD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AAC,CAAA;QAE9D,OAAO,IAAI,UAAU,CACnB,QAAQ,CAAC,WAAW,EACpB,QAAQ,CAAC,QAAQ,EACjB,QAAQ,CAAC,GAAG,EACZ,CAAC,CAAC,QAAQ,CAAC,UAAU,EACrB,QAAQ,CAAC,aAAa,EACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAC9B,CAAA;IACH,CAAC;IAES,eAAe,CAAC,aAAsB;QAC9C,IAAI,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAA;QAEtC,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAChG,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/repositories/redirector/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FullRedirectorModel, RedirectorModel } from '../../models/index.js';
|
|
2
|
+
export declare const REDIRECTOR_REPOSITORY: unique symbol;
|
|
3
|
+
export interface RedirectorRepository {
|
|
4
|
+
create(campaignId: string, redirectorId: string, page: string, lockSecret: string): Promise<void>;
|
|
5
|
+
read(campaignId: string, redirectorId: string): Promise<RedirectorModel | null>;
|
|
6
|
+
readFull(campaignId: string, redirectorId: string): Promise<FullRedirectorModel | null>;
|
|
7
|
+
update(campaignId: string, redirectorId: string, page: string | null | undefined, lockSecret: string): Promise<void>;
|
|
8
|
+
delete(campaignId: string, redirectorId: string, lockSecret: string): Promise<void>;
|
|
9
|
+
list(campaignId: string): Promise<RedirectorModel[] | null>;
|
|
10
|
+
listFull(campaignId: string): Promise<FullRedirectorModel[] | null>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CommandParser } from '@redis/client';
|
|
2
|
+
export interface RawRedirector {
|
|
3
|
+
campaign_id: string;
|
|
4
|
+
redirector_id: string;
|
|
5
|
+
lure_count: number;
|
|
6
|
+
created_at: number;
|
|
7
|
+
}
|
|
8
|
+
export interface RawFullRedirector extends RawRedirector {
|
|
9
|
+
page: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const redirectorFunctions: {
|
|
12
|
+
readonly redirector: {
|
|
13
|
+
readonly create_redirector: {
|
|
14
|
+
readonly NUMBER_OF_KEYS: 4;
|
|
15
|
+
readonly parseCommand: (parser: CommandParser, prefix: string, campaignId: string, redirectorId: string, page: string, lockSecret: string) => void;
|
|
16
|
+
readonly transformReply: () => unknown;
|
|
17
|
+
};
|
|
18
|
+
readonly read_redirector: {
|
|
19
|
+
readonly NUMBER_OF_KEYS: 2;
|
|
20
|
+
readonly parseCommand: (parser: CommandParser, prefix: string, campaignId: string, redirectorId: string) => void;
|
|
21
|
+
readonly transformReply: () => unknown;
|
|
22
|
+
};
|
|
23
|
+
readonly read_full_redirector: {
|
|
24
|
+
readonly NUMBER_OF_KEYS: 2;
|
|
25
|
+
readonly parseCommand: (parser: CommandParser, prefix: string, campaignId: string, redirectorId: string) => void;
|
|
26
|
+
readonly transformReply: () => unknown;
|
|
27
|
+
};
|
|
28
|
+
readonly read_redirector_index: {
|
|
29
|
+
readonly NUMBER_OF_KEYS: 2;
|
|
30
|
+
readonly parseCommand: (parser: CommandParser, prefix: string, campaignId: string) => void;
|
|
31
|
+
readonly transformReply: () => unknown;
|
|
32
|
+
};
|
|
33
|
+
readonly update_redirector: {
|
|
34
|
+
readonly NUMBER_OF_KEYS: 3;
|
|
35
|
+
readonly parseCommand: (parser: CommandParser, prefix: string, campaignId: string, redirectorId: string, page: string | null | undefined, lockSecret: string) => void;
|
|
36
|
+
readonly transformReply: () => unknown;
|
|
37
|
+
};
|
|
38
|
+
readonly delete_redirector: {
|
|
39
|
+
readonly NUMBER_OF_KEYS: 4;
|
|
40
|
+
readonly parseCommand: (parser: CommandParser, prefix: string, campaignId: string, redirectorId: string, lockSecret: string) => void;
|
|
41
|
+
readonly transformReply: () => unknown;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { campaignKey, campaignLockKey, redirectorIndexKey, redirectorKey } from '../../database.keys.js';
|
|
2
|
+
export const redirectorFunctions = {
|
|
3
|
+
redirector: {
|
|
4
|
+
create_redirector: {
|
|
5
|
+
NUMBER_OF_KEYS: 4,
|
|
6
|
+
parseCommand(parser, prefix, campaignId, redirectorId, page, lockSecret) {
|
|
7
|
+
parser.pushKey(campaignKey(prefix, campaignId));
|
|
8
|
+
parser.pushKey(campaignLockKey(prefix, campaignId));
|
|
9
|
+
parser.pushKey(redirectorKey(prefix, campaignId, redirectorId));
|
|
10
|
+
parser.pushKey(redirectorIndexKey(prefix, campaignId));
|
|
11
|
+
parser.push(campaignId);
|
|
12
|
+
parser.push(redirectorId);
|
|
13
|
+
parser.push(page);
|
|
14
|
+
parser.push(Date.now().toString());
|
|
15
|
+
parser.push(lockSecret);
|
|
16
|
+
},
|
|
17
|
+
transformReply: undefined
|
|
18
|
+
},
|
|
19
|
+
read_redirector: {
|
|
20
|
+
NUMBER_OF_KEYS: 2,
|
|
21
|
+
parseCommand(parser, prefix, campaignId, redirectorId) {
|
|
22
|
+
parser.pushKey(campaignKey(prefix, campaignId));
|
|
23
|
+
parser.pushKey(redirectorKey(prefix, campaignId, redirectorId));
|
|
24
|
+
},
|
|
25
|
+
transformReply: undefined
|
|
26
|
+
},
|
|
27
|
+
read_full_redirector: {
|
|
28
|
+
NUMBER_OF_KEYS: 2,
|
|
29
|
+
parseCommand(parser, prefix, campaignId, redirectorId) {
|
|
30
|
+
parser.pushKey(campaignKey(prefix, campaignId));
|
|
31
|
+
parser.pushKey(redirectorKey(prefix, campaignId, redirectorId));
|
|
32
|
+
},
|
|
33
|
+
transformReply: undefined
|
|
34
|
+
},
|
|
35
|
+
read_redirector_index: {
|
|
36
|
+
NUMBER_OF_KEYS: 2,
|
|
37
|
+
parseCommand(parser, prefix, campaignId) {
|
|
38
|
+
parser.pushKey(campaignKey(prefix, campaignId));
|
|
39
|
+
parser.pushKey(redirectorIndexKey(prefix, campaignId));
|
|
40
|
+
},
|
|
41
|
+
transformReply: undefined
|
|
42
|
+
},
|
|
43
|
+
update_redirector: {
|
|
44
|
+
NUMBER_OF_KEYS: 3,
|
|
45
|
+
parseCommand(parser, prefix, campaignId, redirectorId, page, lockSecret) {
|
|
46
|
+
parser.pushKey(campaignKey(prefix, campaignId));
|
|
47
|
+
parser.pushKey(campaignLockKey(prefix, campaignId));
|
|
48
|
+
parser.pushKey(redirectorKey(prefix, campaignId, redirectorId));
|
|
49
|
+
if (page != null) {
|
|
50
|
+
parser.push('page');
|
|
51
|
+
parser.push(page);
|
|
52
|
+
}
|
|
53
|
+
parser.push(lockSecret);
|
|
54
|
+
},
|
|
55
|
+
transformReply: undefined
|
|
56
|
+
},
|
|
57
|
+
delete_redirector: {
|
|
58
|
+
NUMBER_OF_KEYS: 4,
|
|
59
|
+
parseCommand(parser, prefix, campaignId, redirectorId, lockSecret) {
|
|
60
|
+
parser.pushKey(campaignKey(prefix, campaignId));
|
|
61
|
+
parser.pushKey(campaignLockKey(prefix, campaignId));
|
|
62
|
+
parser.pushKey(redirectorKey(prefix, campaignId, redirectorId));
|
|
63
|
+
parser.pushKey(redirectorIndexKey(prefix, campaignId));
|
|
64
|
+
parser.push(lockSecret);
|
|
65
|
+
},
|
|
66
|
+
transformReply: undefined
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=redirector.functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirector.functions.js","sourceRoot":"","sources":["../../../src/repositories/redirector/redirector.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAC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,cAAc,EAAE,SAAqC;SACtD;QAED,iBAAiB,EAAE;YACjB,cAAc,EAAE,CAAC;YAEjB,YAAY,CACV,MAAqB,EACrB,MAAc,EACd,UAAkB,EAClB,YAAoB,EACpB,UAAkB;gBAElB,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;gBAC/C,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;gBACnD,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAA;gBAC/D,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAA;gBAEtD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YACzB,CAAC;YAED,cAAc,EAAE,SAAqC;SACtD;KACF;CACO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirector.js","sourceRoot":"","sources":["../../../src/repositories/redirector/redirector.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const rawRedirectorSchema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
required: ['campaign_id', 'redirector_id', 'lure_count', 'created_at'],
|
|
4
|
+
properties: {
|
|
5
|
+
campaign_id: {
|
|
6
|
+
type: 'string'
|
|
7
|
+
},
|
|
8
|
+
redirector_id: {
|
|
9
|
+
type: 'string'
|
|
10
|
+
},
|
|
11
|
+
lure_count: {
|
|
12
|
+
type: 'integer'
|
|
13
|
+
},
|
|
14
|
+
created_at: {
|
|
15
|
+
type: 'integer'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
additionalProperties: false
|
|
19
|
+
};
|
|
20
|
+
const rawFullRedirectorSchema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
required: ['campaign_id', 'redirector_id', 'page', 'lure_count', 'created_at'],
|
|
23
|
+
properties: {
|
|
24
|
+
campaign_id: {
|
|
25
|
+
type: 'string'
|
|
26
|
+
},
|
|
27
|
+
redirector_id: {
|
|
28
|
+
type: 'string'
|
|
29
|
+
},
|
|
30
|
+
page: {
|
|
31
|
+
type: 'string'
|
|
32
|
+
},
|
|
33
|
+
lure_count: {
|
|
34
|
+
type: 'integer'
|
|
35
|
+
},
|
|
36
|
+
created_at: {
|
|
37
|
+
type: 'integer'
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
additionalProperties: false
|
|
41
|
+
};
|
|
42
|
+
export const redirectorSchemas = {
|
|
43
|
+
'database-raw-redirector': rawRedirectorSchema,
|
|
44
|
+
'database-raw-full-redirector': rawFullRedirectorSchema
|
|
45
|
+
};
|
|
46
|
+
export const redirectorPageSchema = {
|
|
47
|
+
type: 'string',
|
|
48
|
+
minLength: 0,
|
|
49
|
+
maxLength: 10485760
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=redirector.schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirector.schemas.js","sourceRoot":"","sources":["../../../src/repositories/redirector/redirector.schemas.ts"],"names":[],"mappings":"AAGA,MAAM,mBAAmB,GAAkC;IACzD,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,CAAC;IACtE,UAAU,EAAE;QACV,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;SACf;QACD,aAAa,EAAE;YACb,IAAI,EAAE,QAAQ;SACf;QACD,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;SAChB;QACD,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;SAChB;KACF;IACD,oBAAoB,EAAE,KAAK;CACnB,CAAA;AAEV,MAAM,uBAAuB,GAAsC;IACjE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,aAAa,EAAE,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC;IAC9E,UAAU,EAAE;QACV,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;SACf;QACD,aAAa,EAAE;YACb,IAAI,EAAE,QAAQ;SACf;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;SACf;QACD,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;SAChB;QACD,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;SAChB;KACF;IACD,oBAAoB,EAAE,KAAK;CACnB,CAAA;AAEV,MAAM,CAAC,MAAM,iBAAiB,GAAqB;IACjD,yBAAyB,EAAE,mBAAmB;IAC9C,8BAA8B,EAAE,uBAAuB;CAC/C,CAAA;AAEV,MAAM,CAAC,MAAM,oBAAoB,GAA2B;IAC1D,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,QAAQ;CACX,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DIContainer } from '@famir/common';
|
|
2
|
+
import { Config } from '@famir/config';
|
|
3
|
+
import { Logger } from '@famir/logger';
|
|
4
|
+
import { Validator } from '@famir/validator';
|
|
5
|
+
import { RedisDatabaseConfig, RedisDatabaseConnection } from '../../database.js';
|
|
6
|
+
import { FullRedirectorModel, RedirectorModel } from '../../models/index.js';
|
|
7
|
+
import { RedisBaseRepository } from '../base/index.js';
|
|
8
|
+
import { RedirectorRepository } from './redirector.js';
|
|
9
|
+
export declare class RedisRedirectorRepository extends RedisBaseRepository implements RedirectorRepository {
|
|
10
|
+
static inject(container: DIContainer): void;
|
|
11
|
+
constructor(validator: Validator, config: Config<RedisDatabaseConfig>, logger: Logger, connection: RedisDatabaseConnection);
|
|
12
|
+
create(campaignId: string, redirectorId: string, page: string, lockSecret: string): Promise<void>;
|
|
13
|
+
read(campaignId: string, redirectorId: string): Promise<RedirectorModel | null>;
|
|
14
|
+
readFull(campaignId: string, redirectorId: string): Promise<FullRedirectorModel | null>;
|
|
15
|
+
update(campaignId: string, redirectorId: string, page: string | null | undefined, lockSecret: string): Promise<void>;
|
|
16
|
+
delete(campaignId: string, redirectorId: string, lockSecret: string): Promise<void>;
|
|
17
|
+
list(campaignId: string): Promise<RedirectorModel[] | null>;
|
|
18
|
+
listFull(campaignId: string): Promise<FullRedirectorModel[] | null>;
|
|
19
|
+
protected buildModel(rawModel: unknown): RedirectorModel | null;
|
|
20
|
+
protected buildFullModel(rawModel: unknown): FullRedirectorModel | null;
|
|
21
|
+
protected buildCollection(rawCollection: unknown): RedirectorModel[];
|
|
22
|
+
protected buildFullCollection(rawCollection: unknown): FullRedirectorModel[];
|
|
23
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { CONFIG } from '@famir/config';
|
|
2
|
+
import { LOGGER } from '@famir/logger';
|
|
3
|
+
import { VALIDATOR } from '@famir/validator';
|
|
4
|
+
import { DATABASE_CONNECTOR } from '../../database.js';
|
|
5
|
+
import { FullRedirectorModel, RedirectorModel } from '../../models/index.js';
|
|
6
|
+
import { RedisBaseRepository } from '../base/index.js';
|
|
7
|
+
import { REDIRECTOR_REPOSITORY } from './redirector.js';
|
|
8
|
+
import { redirectorSchemas } from './redirector.schemas.js';
|
|
9
|
+
export class RedisRedirectorRepository extends RedisBaseRepository {
|
|
10
|
+
static inject(container) {
|
|
11
|
+
container.registerSingleton(REDIRECTOR_REPOSITORY, (c) => new RedisRedirectorRepository(c.resolve(VALIDATOR), c.resolve(CONFIG), c.resolve(LOGGER), c.resolve(DATABASE_CONNECTOR).connection()));
|
|
12
|
+
}
|
|
13
|
+
constructor(validator, config, logger, connection) {
|
|
14
|
+
super(validator, config, logger, connection, 'redirector');
|
|
15
|
+
this.validator.addSchemas(redirectorSchemas);
|
|
16
|
+
this.logger.debug(`RedirectorRepository initialized`);
|
|
17
|
+
}
|
|
18
|
+
async create(campaignId, redirectorId, page, lockSecret) {
|
|
19
|
+
try {
|
|
20
|
+
const statusReply = await this.connection.redirector.create_redirector(this.options.prefix, campaignId, redirectorId, page, lockSecret);
|
|
21
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
22
|
+
this.logger.info(mesg, { redirector: { campaignId, redirectorId } });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
this.raiseError(error, 'create', { campaignId, redirectorId });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async read(campaignId, redirectorId) {
|
|
29
|
+
try {
|
|
30
|
+
const rawModel = await this.connection.redirector.read_redirector(this.options.prefix, campaignId, redirectorId);
|
|
31
|
+
return this.buildModel(rawModel);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.raiseError(error, 'read', { campaignId, redirectorId });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async readFull(campaignId, redirectorId) {
|
|
38
|
+
try {
|
|
39
|
+
const rawModel = await this.connection.redirector.read_full_redirector(this.options.prefix, campaignId, redirectorId);
|
|
40
|
+
return this.buildFullModel(rawModel);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
this.raiseError(error, 'readFull', { campaignId, redirectorId });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async update(campaignId, redirectorId, page, lockSecret) {
|
|
47
|
+
try {
|
|
48
|
+
const statusReply = await this.connection.redirector.update_redirector(this.options.prefix, campaignId, redirectorId, page, lockSecret);
|
|
49
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
50
|
+
this.logger.info(mesg, { redirector: { campaignId, redirectorId } });
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
this.raiseError(error, 'update', { campaignId, redirectorId });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async delete(campaignId, redirectorId, lockSecret) {
|
|
57
|
+
try {
|
|
58
|
+
const statusReply = await this.connection.redirector.delete_redirector(this.options.prefix, campaignId, redirectorId, lockSecret);
|
|
59
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
60
|
+
this.logger.info(mesg, { redirector: { campaignId, redirectorId } });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
this.raiseError(error, 'delete', { campaignId, redirectorId });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async list(campaignId) {
|
|
67
|
+
try {
|
|
68
|
+
const index = await this.connection.redirector.read_redirector_index(this.options.prefix, campaignId);
|
|
69
|
+
if (index === null) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
this.validateArrayStringsReply(index);
|
|
73
|
+
const rawCollection = await Promise.all(index.map((redirectorId) => this.connection.redirector.read_redirector(this.options.prefix, campaignId, redirectorId)));
|
|
74
|
+
return this.buildCollection(rawCollection);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.raiseError(error, 'list', { campaignId });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async listFull(campaignId) {
|
|
81
|
+
try {
|
|
82
|
+
const index = await this.connection.redirector.read_redirector_index(this.options.prefix, campaignId);
|
|
83
|
+
if (index === null) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
this.validateArrayStringsReply(index);
|
|
87
|
+
const rawCollection = await Promise.all(index.map((redirectorId) => this.connection.redirector.read_full_redirector(this.options.prefix, campaignId, redirectorId)));
|
|
88
|
+
return this.buildFullCollection(rawCollection);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.raiseError(error, 'listFull', { campaignId });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
buildModel(rawModel) {
|
|
95
|
+
if (rawModel === null) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
this.validateRawData('database-raw-redirector', rawModel);
|
|
99
|
+
return new RedirectorModel(rawModel.campaign_id, rawModel.redirector_id, rawModel.lure_count, new Date(rawModel.created_at));
|
|
100
|
+
}
|
|
101
|
+
buildFullModel(rawModel) {
|
|
102
|
+
if (rawModel === null) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
this.validateRawData('database-raw-full-redirector', rawModel);
|
|
106
|
+
return new FullRedirectorModel(rawModel.campaign_id, rawModel.redirector_id, rawModel.page, rawModel.lure_count, new Date(rawModel.created_at));
|
|
107
|
+
}
|
|
108
|
+
buildCollection(rawCollection) {
|
|
109
|
+
this.validateArrayReply(rawCollection);
|
|
110
|
+
return rawCollection
|
|
111
|
+
.map((rawModel) => this.buildModel(rawModel))
|
|
112
|
+
.filter(RedirectorModel.isNotNull);
|
|
113
|
+
}
|
|
114
|
+
buildFullCollection(rawCollection) {
|
|
115
|
+
this.validateArrayReply(rawCollection);
|
|
116
|
+
return rawCollection
|
|
117
|
+
.map((rawModel) => this.buildFullModel(rawModel))
|
|
118
|
+
.filter(RedirectorModel.isNotNull);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=redis-redirector.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-redirector.repository.js","sourceRoot":"","sources":["../../../src/repositories/redirector/redis-redirector.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAU,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAU,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAa,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAInB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAE3D,MAAM,OAAO,yBAA0B,SAAQ,mBAAmB;IAChE,MAAM,CAAC,MAAM,CAAC,SAAsB;QAClC,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0 +1,18 @@
|
|
|
1
|
+
import { DIContainer } from '@famir/common';
|
|
2
|
+
import { Config } from '@famir/config';
|
|
3
|
+
import { Logger } from '@famir/logger';
|
|
4
|
+
import { Validator } from '@famir/validator';
|
|
5
|
+
import { RedisDatabaseConfig, RedisDatabaseConnection } from '../../database.js';
|
|
6
|
+
import { SessionModel } from '../../models/index.js';
|
|
7
|
+
import { RedisBaseRepository } from '../base/index.js';
|
|
8
|
+
import { SessionRepository } from './session.js';
|
|
9
|
+
export declare class RedisSessionRepository extends RedisBaseRepository implements SessionRepository {
|
|
10
|
+
static inject(container: DIContainer): void;
|
|
11
|
+
constructor(validator: Validator, config: Config<RedisDatabaseConfig>, logger: Logger, connection: RedisDatabaseConnection);
|
|
12
|
+
create(campaignId: string): Promise<SessionModel>;
|
|
13
|
+
read(campaignId: string, sessionId: string): Promise<SessionModel | null>;
|
|
14
|
+
auth(campaignId: string, sessionId: string): Promise<SessionModel>;
|
|
15
|
+
upgrade(campaignId: string, lureId: string, sessionId: string, secret: string): Promise<void>;
|
|
16
|
+
protected buildModel(rawModel: unknown): SessionModel | null;
|
|
17
|
+
protected buildModelStrict(rawModel: unknown): SessionModel;
|
|
18
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { randomIdent } from '@famir/common';
|
|
2
|
+
import { CONFIG } from '@famir/config';
|
|
3
|
+
import { LOGGER } from '@famir/logger';
|
|
4
|
+
import { VALIDATOR } from '@famir/validator';
|
|
5
|
+
import { DatabaseError } from '../../database.error.js';
|
|
6
|
+
import { DATABASE_CONNECTOR } from '../../database.js';
|
|
7
|
+
import { SessionModel } from '../../models/index.js';
|
|
8
|
+
import { RedisBaseRepository } from '../base/index.js';
|
|
9
|
+
import { SESSION_REPOSITORY } from './session.js';
|
|
10
|
+
import { sessionSchemas } from './session.schemas.js';
|
|
11
|
+
export class RedisSessionRepository extends RedisBaseRepository {
|
|
12
|
+
static inject(container) {
|
|
13
|
+
container.registerSingleton(SESSION_REPOSITORY, (c) => new RedisSessionRepository(c.resolve(VALIDATOR), c.resolve(CONFIG), c.resolve(LOGGER), c.resolve(DATABASE_CONNECTOR).connection()));
|
|
14
|
+
}
|
|
15
|
+
constructor(validator, config, logger, connection) {
|
|
16
|
+
super(validator, config, logger, connection, 'session');
|
|
17
|
+
this.validator.addSchemas(sessionSchemas);
|
|
18
|
+
this.logger.debug(`SessionRepository initialized`);
|
|
19
|
+
}
|
|
20
|
+
async create(campaignId) {
|
|
21
|
+
const [sessionId, secret] = [randomIdent(), randomIdent()];
|
|
22
|
+
try {
|
|
23
|
+
const [statusReply, rawModel] = await Promise.all([
|
|
24
|
+
this.connection.session.create_session(this.options.prefix, campaignId, sessionId, secret),
|
|
25
|
+
this.connection.session.read_session(this.options.prefix, campaignId, sessionId)
|
|
26
|
+
]);
|
|
27
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
28
|
+
this.logger.info(mesg, { session: { campaignId, sessionId } });
|
|
29
|
+
return this.buildModelStrict(rawModel);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
this.raiseError(error, 'create', { campaignId, sessionId });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async read(campaignId, sessionId) {
|
|
36
|
+
try {
|
|
37
|
+
const rawModel = await this.connection.session.read_session(this.options.prefix, campaignId, sessionId);
|
|
38
|
+
return this.buildModel(rawModel);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.raiseError(error, 'read', { campaignId, sessionId });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async auth(campaignId, sessionId) {
|
|
45
|
+
try {
|
|
46
|
+
const [statusReply, rawModel] = await Promise.all([
|
|
47
|
+
this.connection.session.auth_session(this.options.prefix, campaignId, sessionId),
|
|
48
|
+
this.connection.session.read_session(this.options.prefix, campaignId, sessionId)
|
|
49
|
+
]);
|
|
50
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
51
|
+
this.logger.info(mesg, { session: { campaignId, sessionId } });
|
|
52
|
+
return this.buildModelStrict(rawModel);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.raiseError(error, 'auth', { campaignId, sessionId });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async upgrade(campaignId, lureId, sessionId, secret) {
|
|
59
|
+
try {
|
|
60
|
+
const statusReply = await this.connection.session.upgrade_session(this.options.prefix, campaignId, lureId, sessionId, secret);
|
|
61
|
+
const mesg = this.handleStatusReply(statusReply);
|
|
62
|
+
this.logger.info(mesg, { session: { campaignId, lureId, sessionId } });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
this.raiseError(error, 'upgrade', { campaignId, lureId, sessionId });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
buildModel(rawModel) {
|
|
69
|
+
if (rawModel === null) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
this.validateRawData('database-raw-session', rawModel);
|
|
73
|
+
return new SessionModel(rawModel.campaign_id, rawModel.session_id, rawModel.proxy_id, rawModel.secret, !!rawModel.is_landing, rawModel.message_count, new Date(rawModel.created_at), new Date(rawModel.last_auth_at));
|
|
74
|
+
}
|
|
75
|
+
buildModelStrict(rawModel) {
|
|
76
|
+
const model = this.buildModel(rawModel);
|
|
77
|
+
if (!SessionModel.isNotNull(model)) {
|
|
78
|
+
throw new DatabaseError(`Session unexpected lost`, {
|
|
79
|
+
code: 'INTERNAL_ERROR'
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return model;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=redis-session.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-session.repository.js","sourceRoot":"","sources":["../../../src/repositories/session/redis-session.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,MAAM,EAAU,MAAM,eAAe,CAA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OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;IAES,UAAU,CAAC,QAAiB;QACpC,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,CAAC,eAAe,CAAa,sBAAsB,EAAE,QAAQ,CAAC,CAAA;QAElE,OAAO,IAAI,YAAY,CACrB,QAAQ,CAAC,WAAW,EACpB,QAAQ,CAAC,UAAU,EACnB,QAAQ,CAAC,QAAQ,EACjB,QAAQ,CAAC,MAAM,EACf,CAAC,CAAC,QAAQ,CAAC,UAAU,EACrB,QAAQ,CAAC,aAAa,EACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAChC,CAAA;IACH,CAAC;IAES,gBAAgB,CAAC,QAAiB;QAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QAEvC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,aAAa,CAAC,yBAAyB,EAAE;gBACjD,IAAI,EAAE,gBAAgB;aACvB,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SessionModel } from '../../models/index.js';
|
|
2
|
+
export declare const SESSION_REPOSITORY: unique symbol;
|
|
3
|
+
export interface SessionRepository {
|
|
4
|
+
create(campaignId: string): Promise<SessionModel>;
|
|
5
|
+
read(campaignId: string, sessionId: string): Promise<SessionModel | null>;
|
|
6
|
+
auth(campaignId: string, sessionId: string): Promise<SessionModel>;
|
|
7
|
+
upgrade(campaignId: string, lureId: string, sessionId: string, secret: string): Promise<void>;
|
|
8
|
+
}
|