@famir/database 0.0.3 → 0.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.
- package/README.md +187 -0
- package/dist/database.d.ts +0 -1
- package/dist/database.error.js.map +1 -1
- package/dist/database.functions.d.ts +16 -11
- package/dist/database.functions.js.map +1 -1
- package/dist/database.js +0 -1
- package/dist/database.js.map +1 -1
- package/dist/database.keys.d.ts +1 -1
- package/dist/database.keys.js +3 -3
- package/dist/database.keys.js.map +1 -1
- package/dist/database.schemas.js.map +1 -1
- package/dist/modules/base/redis-base.repository.d.ts +7 -7
- package/dist/modules/base/redis-base.repository.js +64 -44
- package/dist/modules/base/redis-base.repository.js.map +1 -1
- package/dist/modules/campaign/campaign.d.ts +2 -1
- package/dist/modules/campaign/campaign.functions.d.ts +4 -4
- package/dist/modules/campaign/campaign.functions.js +8 -8
- package/dist/modules/campaign/campaign.functions.js.map +1 -1
- package/dist/modules/campaign/campaign.js +1 -0
- package/dist/modules/campaign/campaign.js.map +1 -1
- package/dist/modules/campaign/campaign.models.js.map +1 -1
- package/dist/modules/campaign/campaign.schemas.d.ts +1 -0
- package/dist/modules/campaign/campaign.schemas.js +64 -110
- package/dist/modules/campaign/campaign.schemas.js.map +1 -1
- package/dist/modules/campaign/redis-campaign.repository.js +28 -12
- package/dist/modules/campaign/redis-campaign.repository.js.map +1 -1
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/lure/lure.functions.d.ts +2 -2
- package/dist/modules/lure/lure.functions.js +1 -1
- package/dist/modules/lure/lure.functions.js.map +1 -1
- package/dist/modules/lure/lure.js.map +1 -1
- package/dist/modules/lure/lure.models.js.map +1 -1
- package/dist/modules/lure/lure.schemas.js +13 -26
- package/dist/modules/lure/lure.schemas.js.map +1 -1
- package/dist/modules/lure/redis-lure.repository.js +19 -6
- package/dist/modules/lure/redis-lure.repository.js.map +1 -1
- package/dist/modules/message/message.functions.d.ts +4 -3
- package/dist/modules/message/message.functions.js +4 -4
- package/dist/modules/message/message.functions.js.map +1 -1
- package/dist/modules/message/message.js.map +1 -1
- package/dist/modules/message/message.models.js.map +1 -1
- package/dist/modules/message/message.schemas.js +35 -102
- package/dist/modules/message/message.schemas.js.map +1 -1
- package/dist/modules/message/redis-message.repository.js +10 -7
- package/dist/modules/message/redis-message.repository.js.map +1 -1
- package/dist/modules/proxy/proxy.functions.d.ts +2 -2
- package/dist/modules/proxy/proxy.functions.js +1 -1
- package/dist/modules/proxy/proxy.functions.js.map +1 -1
- package/dist/modules/proxy/proxy.js.map +1 -1
- package/dist/modules/proxy/proxy.models.js.map +1 -1
- package/dist/modules/proxy/proxy.schemas.js +12 -23
- package/dist/modules/proxy/proxy.schemas.js.map +1 -1
- package/dist/modules/proxy/redis-proxy.repository.js +19 -6
- package/dist/modules/proxy/redis-proxy.repository.js.map +1 -1
- package/dist/modules/redirector/redirector.functions.d.ts +1 -1
- package/dist/modules/redirector/redirector.functions.js +1 -1
- package/dist/modules/redirector/redirector.functions.js.map +1 -1
- package/dist/modules/redirector/redirector.js.map +1 -1
- package/dist/modules/redirector/redirector.models.js.map +1 -1
- package/dist/modules/redirector/redirector.schemas.js +26 -48
- package/dist/modules/redirector/redirector.schemas.js.map +1 -1
- package/dist/modules/redirector/redis-redirector.repository.js +22 -6
- package/dist/modules/redirector/redis-redirector.repository.js.map +1 -1
- package/dist/modules/session/redis-session.repository.js +15 -6
- package/dist/modules/session/redis-session.repository.js.map +1 -1
- package/dist/modules/session/session.functions.d.ts +3 -3
- package/dist/modules/session/session.functions.js +2 -2
- package/dist/modules/session/session.functions.js.map +1 -1
- package/dist/modules/session/session.js.map +1 -1
- package/dist/modules/session/session.models.js.map +1 -1
- package/dist/modules/session/session.schemas.js +21 -37
- package/dist/modules/session/session.schemas.js.map +1 -1
- package/dist/modules/target/redis-target.repository.d.ts +2 -2
- package/dist/modules/target/redis-target.repository.js +51 -30
- package/dist/modules/target/redis-target.repository.js.map +1 -1
- package/dist/modules/target/target.d.ts +2 -1
- package/dist/modules/target/target.functions.d.ts +13 -7
- package/dist/modules/target/target.functions.js +28 -21
- package/dist/modules/target/target.functions.js.map +1 -1
- package/dist/modules/target/target.js.map +1 -1
- package/dist/modules/target/target.models.d.ts +3 -1
- package/dist/modules/target/target.models.js +3 -3
- package/dist/modules/target/target.models.js.map +1 -1
- package/dist/modules/target/target.schemas.d.ts +3 -1
- package/dist/modules/target/target.schemas.js +110 -180
- package/dist/modules/target/target.schemas.js.map +1 -1
- package/dist/redis-database-connector.d.ts +1 -1
- package/dist/redis-database-connector.js +6 -6
- package/dist/redis-database-connector.js.map +1 -1
- package/dist/redis-database-manager.js +7 -2
- package/dist/redis-database-manager.js.map +1 -1
- package/dist/redis-functions.js +7 -7
- package/dist/redis-functions.js.map +1 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,3 +1,190 @@
|
|
|
1
1
|
# @famir/database
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@famir/database)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
|
|
3
6
|
Database infrastructure service.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @famir/database
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## An Architectural Overview
|
|
15
|
+
|
|
16
|
+
This document describes the core data models used by the Famir framework from an architectural
|
|
17
|
+
perspective. These models are managed via Redis Functions to ensure data integrity and atomicity.
|
|
18
|
+
|
|
19
|
+
The models form a strict hierarchy, with a **Campaign** at the root, containing and orchestrating
|
|
20
|
+
all other resources.
|
|
21
|
+
|
|
22
|
+
### Campaign
|
|
23
|
+
|
|
24
|
+
**Purpose:** The root of all resources. A Campaign represents a single, isolated mirroring
|
|
25
|
+
operation. It holds the primary configuration, cryptographic secrets, and aggregated statistics for
|
|
26
|
+
a project.
|
|
27
|
+
|
|
28
|
+
**Architectural Role:**
|
|
29
|
+
|
|
30
|
+
- **Container & Owner:** Owns every other model (Proxies, Targets, Redirectors, Lures, Sessions,
|
|
31
|
+
Messages). Deleting a campaign is possible only after deleting all related entities.
|
|
32
|
+
- **Locking Mechanism:** Acts as the root for a distributed lock. Any modification to a campaign or
|
|
33
|
+
any entity within it requires locking the parent Campaign. This prevents race conditions.
|
|
34
|
+
- **Uniqueness Scope:** Enforces global uniqueness for the campaign's public-facing `mirror_domain`
|
|
35
|
+
and its internal `session_cookie_name`.
|
|
36
|
+
|
|
37
|
+
**Key Relationships:**
|
|
38
|
+
|
|
39
|
+
- **Has many** `Proxy` entities (for handling traffic).
|
|
40
|
+
- **Has many** `Target` entities (for backend origin servers).
|
|
41
|
+
- **Has many** `Redirector` entities (for landing pages).
|
|
42
|
+
- **Has many** `Lure` entities (for specific URL paths).
|
|
43
|
+
- **Has many** `Session` entities (for client interactions).
|
|
44
|
+
- **Has many** `Message` entities (for HTTP transaction logs).
|
|
45
|
+
|
|
46
|
+
### Proxy
|
|
47
|
+
|
|
48
|
+
**Purpose:** An egress endpoint. A Proxy defines how traffic from a mirrored site is routed outwards
|
|
49
|
+
to donor site via HTTP or SOCKS proxies.
|
|
50
|
+
|
|
51
|
+
**Architectural Role:**
|
|
52
|
+
|
|
53
|
+
- **Traffic Forwarder:** Acts as an upstream proxy server. When a Session is created, it is
|
|
54
|
+
dynamically assigned to one of the enabled Proxies.
|
|
55
|
+
- **Load Balancing Target:** The `Session` creation logic uses a random method of obtaining an
|
|
56
|
+
available Proxy from the set of enabled ones, providing simple load balancing and failover.
|
|
57
|
+
- **Lifecycle Management:** Proxies can be individually enabled or disabled. Disabling a proxy
|
|
58
|
+
prevents new sessions from using it. Existing sessions that attempt to re-authorize will be
|
|
59
|
+
automatically re-assigned to a different enabled proxy.
|
|
60
|
+
|
|
61
|
+
**Key Relationships:**
|
|
62
|
+
|
|
63
|
+
- **Belongs to a** `Campaign`.
|
|
64
|
+
- **Is used by many** `Session` entities.
|
|
65
|
+
|
|
66
|
+
### Target
|
|
67
|
+
|
|
68
|
+
**Purpose:** The backend origin server. A Target defines the real website to be mirrored (e.g.,
|
|
69
|
+
`https://real-bank.com`). It is the source of truth for the content being impersonated.
|
|
70
|
+
|
|
71
|
+
**Architectural Role:**
|
|
72
|
+
|
|
73
|
+
- **Content Provider:** Contains full configuration for connecting to the donor (real) site,
|
|
74
|
+
including subdomains, ports, timeouts, and size limits.
|
|
75
|
+
- **Mirror Definition:** Defines the mapping from a public-facing mirror URL (e.g.,
|
|
76
|
+
`https://secure.bank.mirror-domain.com`) back to the original donor server's internal structure.
|
|
77
|
+
- **Lookup Hub:** The most critical role. When an HTTP request arrives at the mirror domain, Famir
|
|
78
|
+
uses a dedicated `target_mirror_hosts_key` to perform a direct O(1) lookup, instantly finding the
|
|
79
|
+
correct Target based on the requested `Host` header.
|
|
80
|
+
|
|
81
|
+
**Key Relationships:**
|
|
82
|
+
|
|
83
|
+
- **Belongs to a** `Campaign`.
|
|
84
|
+
- **Generates traffic logged as** `Message` entities.
|
|
85
|
+
|
|
86
|
+
### Redirector
|
|
87
|
+
|
|
88
|
+
**Purpose:** A "landing page" rule. A Redirector represents a specific logical page or template
|
|
89
|
+
(e.g., a login page, an error page) that can be served to a victim.
|
|
90
|
+
|
|
91
|
+
**Architectural Role:**
|
|
92
|
+
|
|
93
|
+
- **Template Container:** Holds the content (e.g., an HTML page) associated with a specific phishing
|
|
94
|
+
step.
|
|
95
|
+
- **Dynamic Fields Container:** Can have arbitrary key-value `fields` attached to it, allowing for
|
|
96
|
+
flexible template injection (e.g., `error_message`, `return_url`).
|
|
97
|
+
- **Relationship Hub for Lures:** A Redirector does not have a public URL itself but serves as the
|
|
98
|
+
target for one or more `Lure` entities. Different Lures can point to the same Redirector.
|
|
99
|
+
|
|
100
|
+
**Key Relationships:**
|
|
101
|
+
|
|
102
|
+
- **Belongs to a** `Campaign`.
|
|
103
|
+
- **Is the parent of many** `Lure` entities. Deleting a Redirector requires its associated Lure
|
|
104
|
+
count to be zero.
|
|
105
|
+
|
|
106
|
+
### Lure
|
|
107
|
+
|
|
108
|
+
**Purpose:** A specific, publicly accessible URL path (e.g., `/login`, `/reset-password`). A Lure is
|
|
109
|
+
the actual "phishing link" that a victim clicks.
|
|
110
|
+
|
|
111
|
+
**Architectural Role:**
|
|
112
|
+
|
|
113
|
+
- **Router:** The primary HTTP lookup mechanism. When a request arrives at a mirror domain, the
|
|
114
|
+
request's path (e.g., `/login`) is used as a key to instantly find the corresponding Lure via a
|
|
115
|
+
direct hash lookup.
|
|
116
|
+
- **Session Tracker:** Each Lure acts as a counter for the number of sessions that have been
|
|
117
|
+
"upgraded" (e.g., completed a login form) through that specific path.
|
|
118
|
+
- **Activation Switch:** Lures can be enabled or disabled. A disabled lure will not route traffic,
|
|
119
|
+
effectively turning off a specific phishing link without deleting its configuration.
|
|
120
|
+
|
|
121
|
+
**Key Relationships:**
|
|
122
|
+
|
|
123
|
+
- **Belongs to a** `Campaign`.
|
|
124
|
+
- **Points to a single** `Redirector`, which provides the content to serve.
|
|
125
|
+
- **Is the entry point for many** `Session` entities, incrementing its `session_count` when a
|
|
126
|
+
session is upgraded through it.
|
|
127
|
+
|
|
128
|
+
### Session
|
|
129
|
+
|
|
130
|
+
**Purpose:** A client's browsing "visit". A Session represents an individual victim's interaction
|
|
131
|
+
with the mirror, from the first click to the end of their activity.
|
|
132
|
+
|
|
133
|
+
**Architectural Role:**
|
|
134
|
+
|
|
135
|
+
- **State Container:** Holds the entire state of a client's journey, including assigned `Proxy` and
|
|
136
|
+
a `secret` for authentication.
|
|
137
|
+
- **Dynamic Proxy Assignment:** On creation, a session is randomly assigned one of the campaign's
|
|
138
|
+
enabled proxies. If the assigned proxy becomes disabled, the session will be automatically
|
|
139
|
+
re-assigned to a working proxy the next time it is authorized.
|
|
140
|
+
- **Lifecycle via TTL:** Sessions have two Time-To-Live (TTL) periods:
|
|
141
|
+
1. **Short TTL:** After creation, before authorization (e.g., user hasn't logged in yet).
|
|
142
|
+
2. **Long TTL:** After successful authorization (e.g., user is logged in).
|
|
143
|
+
- **Upgrade Tracking:** Tracks if a session has been "upgraded" (e.g., submitted a login form),
|
|
144
|
+
linking it back to the specific `Lure` used.
|
|
145
|
+
|
|
146
|
+
**Key Relationships:**
|
|
147
|
+
|
|
148
|
+
- **Belongs to a** `Campaign`.
|
|
149
|
+
- **Is assigned to one** `Proxy` at a time.
|
|
150
|
+
- **Initiates one or more** `Message` entities (its HTTP requests/responses).
|
|
151
|
+
|
|
152
|
+
### Message
|
|
153
|
+
|
|
154
|
+
**Purpose:** An immutable audit log entry. A Message represents a single HTTP transaction (request
|
|
155
|
+
and response) that passed through the mirror.
|
|
156
|
+
|
|
157
|
+
**Architectural Role:**
|
|
158
|
+
|
|
159
|
+
- **Forensic Record:** The lowest level of data, storing all technical details of an HTTP exchange:
|
|
160
|
+
method, URL, headers, body, status code, timing, and any errors.
|
|
161
|
+
- **Dummy Mode:** Supports creating a "dummy" message, which only increments counters without
|
|
162
|
+
storing any payload. This is useful for high-throughput logging where full details are not needed.
|
|
163
|
+
- **Automatic Expiration:** Messages are automatically deleted after a campaign-defined TTL,
|
|
164
|
+
preventing unbounded database growth.
|
|
165
|
+
|
|
166
|
+
**Key Relationships:**
|
|
167
|
+
|
|
168
|
+
- **Belongs to a** `Campaign`.
|
|
169
|
+
- **Originates from one** `Session`.
|
|
170
|
+
- **Is generated through one** `Proxy` and one `Target`.
|
|
171
|
+
- **Increments aggregated message counters on the Campaign, Proxy, Target, and Session.**
|
|
172
|
+
|
|
173
|
+
### Summary of Interactions (Typical User Flow)
|
|
174
|
+
|
|
175
|
+
1. A **Campaign** is created with a `mirror_domain` (e.g., `secure.bank.com`).
|
|
176
|
+
2. **Target(s)** are defined to point to the real bank's website.
|
|
177
|
+
3. A **Redirector** is created to hold a fake login page HTML.
|
|
178
|
+
4. A **Lure** is created with the path `/login`, linked to the Redirector. The path `/login` is now
|
|
179
|
+
ready to serve the fake login page.
|
|
180
|
+
5. **Proxy(s)** are created and enabled to forward traffic to the internet.
|
|
181
|
+
6. A victim clicks a link to `https://secure.bank.com/login`.
|
|
182
|
+
- The **Lure** finds its `Redirector` via the `/login` path.
|
|
183
|
+
- A new **Session** is created for the victim and is randomly assigned an enabled **Proxy**.
|
|
184
|
+
7. The victim submits their credentials. The **Session** is "upgraded" (marking the login as
|
|
185
|
+
complete), and this increments the **Lure's** `session_count`.
|
|
186
|
+
8. Every HTTP request and response (e.g., GET login page, POST credentials) is stored as a
|
|
187
|
+
**Message**, linked to the **Session**, **Proxy**, and **Target**. All related counters are
|
|
188
|
+
atomically incremented.
|
|
189
|
+
9. The **Campaign** provides a central view of all these activities through its aggregated counters
|
|
190
|
+
(`session_count`, `message_count`, etc.).
|
package/dist/database.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.error.js","sourceRoot":"","sources":["../src/database.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"database.error.js","sourceRoot":"","sources":["../src/database.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,MAAM,eAAe,CAAA;AAuB/D,MAAM,OAAO,aAAc,SAAQ,WAAW;IAE5C,IAAI,CAAmB;IAQvB,YAAY,OAAe,EAAE,OAA6B;QACxD,KAAK,CAAC,OAAO,EAAE;YACb,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAA;QAEF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IAC1B,CAAC;CACF"}
|
|
@@ -2,7 +2,7 @@ export declare const databaseFunctions: {
|
|
|
2
2
|
readonly message: {
|
|
3
3
|
readonly create_message: {
|
|
4
4
|
readonly NUMBER_OF_KEYS: 5;
|
|
5
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, messageId: string, proxyId: string, targetId: string, sessionId: string, type: string, method: string, url: string, requestHeaders: string, requestBody: string, status:
|
|
5
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, messageId: string, proxyId: string, targetId: string, sessionId: string, type: string, method: string, url: string, requestHeaders: string, requestBody: string, status: number, responseHeaders: string, responseBody: string, connection: string, payload: string, errors: string, analyze: string, startTime: number, finishTime: number, createdAt: number) => void;
|
|
6
6
|
readonly transformReply: () => unknown;
|
|
7
7
|
};
|
|
8
8
|
readonly create_dummy_message: {
|
|
@@ -24,7 +24,7 @@ export declare const databaseFunctions: {
|
|
|
24
24
|
readonly session: {
|
|
25
25
|
readonly create_session: {
|
|
26
26
|
readonly NUMBER_OF_KEYS: 3;
|
|
27
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, sessionId: string, secret: string, createdAt:
|
|
27
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, sessionId: string, secret: string, createdAt: number) => void;
|
|
28
28
|
readonly transformReply: () => unknown;
|
|
29
29
|
};
|
|
30
30
|
readonly read_session: {
|
|
@@ -34,7 +34,7 @@ export declare const databaseFunctions: {
|
|
|
34
34
|
};
|
|
35
35
|
readonly auth_session: {
|
|
36
36
|
readonly NUMBER_OF_KEYS: 3;
|
|
37
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, sessionId: string, authorizedAt:
|
|
37
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, sessionId: string, authorizedAt: number) => void;
|
|
38
38
|
readonly transformReply: () => unknown;
|
|
39
39
|
};
|
|
40
40
|
readonly upgrade_session: {
|
|
@@ -46,7 +46,7 @@ export declare const databaseFunctions: {
|
|
|
46
46
|
readonly lure: {
|
|
47
47
|
readonly create_lure: {
|
|
48
48
|
readonly NUMBER_OF_KEYS: 6;
|
|
49
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, lureId: string, path: string, redirectorId: string, createdAt:
|
|
49
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, lureId: string, path: string, redirectorId: string, createdAt: number, lockSecret: string) => void;
|
|
50
50
|
readonly transformReply: () => unknown;
|
|
51
51
|
};
|
|
52
52
|
readonly read_lure: {
|
|
@@ -83,7 +83,7 @@ export declare const databaseFunctions: {
|
|
|
83
83
|
readonly redirector: {
|
|
84
84
|
readonly create_redirector: {
|
|
85
85
|
readonly NUMBER_OF_KEYS: 4;
|
|
86
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, redirectorId: string, page: string, createdAt:
|
|
86
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, redirectorId: string, page: string, createdAt: number, lockSecret: string) => void;
|
|
87
87
|
readonly transformReply: () => unknown;
|
|
88
88
|
};
|
|
89
89
|
readonly read_redirector: {
|
|
@@ -125,7 +125,7 @@ export declare const databaseFunctions: {
|
|
|
125
125
|
readonly target: {
|
|
126
126
|
readonly create_target: {
|
|
127
127
|
readonly NUMBER_OF_KEYS: 7;
|
|
128
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, targetId: string, accessLevel: string, donorSecure:
|
|
128
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, targetId: string, accessLevel: string, donorSecure: boolean, donorSub: string, donorDomain: string, donorPort: number, mirrorSecure: boolean, mirrorSub: string, mirrorPort: number, connectTimeout: number, simpleTimeout: number, streamTimeout: number, headersSizeLimit: number, bodySizeLimit: number, mainPage: string, notFoundPage: string, faviconIco: string, robotsTxt: string, sitemapXml: string, allowWebSockets: boolean, createdAt: number, lockSecret: string) => void;
|
|
129
129
|
readonly transformReply: () => unknown;
|
|
130
130
|
};
|
|
131
131
|
readonly read_target: {
|
|
@@ -138,6 +138,11 @@ export declare const databaseFunctions: {
|
|
|
138
138
|
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, targetId: string) => void;
|
|
139
139
|
readonly transformReply: () => unknown;
|
|
140
140
|
};
|
|
141
|
+
readonly read_target_hosts: {
|
|
142
|
+
readonly NUMBER_OF_KEYS: 1;
|
|
143
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string) => void;
|
|
144
|
+
readonly transformReply: () => unknown;
|
|
145
|
+
};
|
|
141
146
|
readonly find_target_link: {
|
|
142
147
|
readonly NUMBER_OF_KEYS: 1;
|
|
143
148
|
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, mirrorHost: string) => void;
|
|
@@ -150,7 +155,7 @@ export declare const databaseFunctions: {
|
|
|
150
155
|
};
|
|
151
156
|
readonly update_target: {
|
|
152
157
|
readonly NUMBER_OF_KEYS: 3;
|
|
153
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, targetId: string, connectTimeout:
|
|
158
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, targetId: string, connectTimeout: number | null | undefined, simpleTimeout: number | null | undefined, streamTimeout: number | null | undefined, headersSizeLimit: number | null | undefined, bodySizeLimit: number | null | undefined, mainPage: string | null | undefined, notFoundPage: string | null | undefined, faviconIco: string | null | undefined, robotsTxt: string | null | undefined, sitemapXml: string | null | undefined, allowWebSockets: boolean | null | undefined, lockSecret: string) => void;
|
|
154
159
|
readonly transformReply: () => unknown;
|
|
155
160
|
};
|
|
156
161
|
readonly enable_target: {
|
|
@@ -182,7 +187,7 @@ export declare const databaseFunctions: {
|
|
|
182
187
|
readonly proxy: {
|
|
183
188
|
readonly create_proxy: {
|
|
184
189
|
readonly NUMBER_OF_KEYS: 5;
|
|
185
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, proxyId: string, url: string, createdAt:
|
|
190
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, proxyId: string, url: string, createdAt: number, lockSecret: string) => void;
|
|
186
191
|
readonly transformReply: () => unknown;
|
|
187
192
|
};
|
|
188
193
|
readonly read_proxy: {
|
|
@@ -214,7 +219,7 @@ export declare const databaseFunctions: {
|
|
|
214
219
|
readonly campaign: {
|
|
215
220
|
readonly create_campaign: {
|
|
216
221
|
readonly NUMBER_OF_KEYS: 4;
|
|
217
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, mirrorDomain: string, description: string, cryptSecret: string, upgradeSessionPath: string, sessionCookieName: string, sessionExpire:
|
|
222
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, mirrorDomain: string, description: string, cryptSecret: string, upgradeSessionPath: string, sessionCookieName: string, sessionExpire: number, newSessionExpire: number, messageExpire: number, createdAt: number) => void;
|
|
218
223
|
readonly transformReply: () => unknown;
|
|
219
224
|
};
|
|
220
225
|
readonly read_campaign: {
|
|
@@ -234,7 +239,7 @@ export declare const databaseFunctions: {
|
|
|
234
239
|
};
|
|
235
240
|
readonly lock_campaign: {
|
|
236
241
|
readonly NUMBER_OF_KEYS: 2;
|
|
237
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, lockSecret: string, lockTimeout:
|
|
242
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, lockSecret: string, lockTimeout: number) => void;
|
|
238
243
|
readonly transformReply: () => unknown;
|
|
239
244
|
};
|
|
240
245
|
readonly unlock_campaign: {
|
|
@@ -244,7 +249,7 @@ export declare const databaseFunctions: {
|
|
|
244
249
|
};
|
|
245
250
|
readonly update_campaign: {
|
|
246
251
|
readonly NUMBER_OF_KEYS: 2;
|
|
247
|
-
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, description: string | null, sessionExpire:
|
|
252
|
+
readonly parseCommand: (parser: import("redis").CommandParser, prefix: string, campaignId: string, description: string | null | undefined, sessionExpire: number | null | undefined, newSessionExpire: number | null | undefined, messageExpire: number | null | undefined, lockSecret: string) => void;
|
|
248
253
|
readonly transformReply: () => unknown;
|
|
249
254
|
};
|
|
250
255
|
readonly delete_campaign: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.functions.js","sourceRoot":"","sources":["../src/database.functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;
|
|
1
|
+
{"version":3,"file":"database.functions.js","sourceRoot":"","sources":["../src/database.functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AAQtE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,GAAG,iBAAiB;IACpB,GAAG,cAAc;IACjB,GAAG,eAAe;IAClB,GAAG,mBAAmB;IACtB,GAAG,aAAa;IAChB,GAAG,gBAAgB;IACnB,GAAG,gBAAgB;CACX,CAAA"}
|
package/dist/database.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export const DATABASE_CONNECTOR = Symbol('DatabaseConnector');
|
|
2
2
|
export const DATABASE_MANAGER = Symbol('DatabaseManager');
|
|
3
3
|
export const DATABASE_STATUS_CODES = ['OK', 'NOT_FOUND', 'CONFLICT', 'FORBIDDEN'];
|
|
4
|
-
export const DATABASE_LOCK_TIMEOUT = 5 * 60 * 1000;
|
|
5
4
|
//# sourceMappingURL=database.js.map
|
package/dist/database.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAQ7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA;AA0EzD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,CAAU,CAAA"}
|
package/dist/database.keys.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare const targetKey: (prefix: string, campaignId: string, targetId: s
|
|
|
11
11
|
export declare const targetLabelsKey: (prefix: string, campaignId: string, targetId: string) => string;
|
|
12
12
|
export declare const targetDonorsKey: (prefix: string, campaignId: string) => string;
|
|
13
13
|
export declare const targetMirrorsKey: (prefix: string, campaignId: string) => string;
|
|
14
|
-
export declare const targetMirrorHostsKey: (prefix: string) => string;
|
|
15
14
|
export declare const targetIndexKey: (prefix: string, campaignId: string) => string;
|
|
15
|
+
export declare const targetHostsKey: (prefix: string) => string;
|
|
16
16
|
export declare const redirectorKey: (prefix: string, campaignId: string, redirectorId: string) => string;
|
|
17
17
|
export declare const redirectorFieldsKey: (prefix: string, campaignId: string, redirectorId: string) => string;
|
|
18
18
|
export declare const redirectorIndexKey: (prefix: string, campaignId: string) => string;
|
package/dist/database.keys.js
CHANGED
|
@@ -40,12 +40,12 @@ export const targetDonorsKey = (prefix, campaignId) => {
|
|
|
40
40
|
export const targetMirrorsKey = (prefix, campaignId) => {
|
|
41
41
|
return buildKey(prefix, 'target-mirrors', campaignId);
|
|
42
42
|
};
|
|
43
|
-
export const targetMirrorHostsKey = (prefix) => {
|
|
44
|
-
return buildKey(prefix, 'target-mirror-hosts');
|
|
45
|
-
};
|
|
46
43
|
export const targetIndexKey = (prefix, campaignId) => {
|
|
47
44
|
return buildKey(prefix, 'target-index', campaignId);
|
|
48
45
|
};
|
|
46
|
+
export const targetHostsKey = (prefix) => {
|
|
47
|
+
return buildKey(prefix, 'target-hosts');
|
|
48
|
+
};
|
|
49
49
|
export const redirectorKey = (prefix, campaignId, redirectorId) => {
|
|
50
50
|
return buildKey(prefix, 'redirector', campaignId, redirectorId);
|
|
51
51
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.keys.js","sourceRoot":"","sources":["../src/database.keys.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.keys.js","sourceRoot":"","sources":["../src/database.keys.ts"],"names":[],"mappings":"AAOA,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAc,EAAU,EAAE;IAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC,CAAA;AAaD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,EAAE;IAChE,OAAO,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;AACjD,CAAC,CAAA;AAWD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,EAAE;IACpE,OAAO,QAAQ,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,CAAC,CAAA;AACtD,CAAC,CAAA;AAUD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAE,EAAE;IACzD,OAAO,QAAQ,CAAC,MAAM,EAAE,yBAAyB,C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E,UAAU,CAAC,CAAA;AACzD,CAAC,CAAA;AAcD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,MAAc,EAAE,EAAE;IAC5E,OAAO,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;AACrD,CAAC,CAAA;AAWD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,EAAE;IACjE,OAAO,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;AACnD,CAAC,CAAA;AAWD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,EAAE;IACjE,OAAO,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;AACnD,CAAC,CAAA;AAcD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,SAAiB,EAAE,EAAE;IAClF,OAAO,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;AAC3D,CAAC,CAAA;AAcD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,UAAkB,EAAE,SAAiB,EAAE,EAAE;IAClF,OAAO,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;AAC3D,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.schemas.js","sourceRoot":"","sources":["../src/database.schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.schemas.js","sourceRoot":"","sources":["../src/database.schemas.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,sCAAsC,GAA2B;IAC5E,IAAI,EAAE,QAAQ;CACN,CAAA;AAQV,MAAM,CAAC,MAAM,+BAA+B,GAA2B;IACrE,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,OAAO;CACR,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Config } from '@famir/config';
|
|
2
2
|
import { Logger } from '@famir/logger';
|
|
3
3
|
import { Validator } from '@famir/validator';
|
|
4
|
-
import { DatabaseConnector, RedisDatabaseConfig, RedisDatabaseConnection, RedisDatabaseRepositoryOptions } from '../../database.js';
|
|
4
|
+
import { DatabaseConnector, DatabaseStatusCode, RedisDatabaseConfig, RedisDatabaseConnection, RedisDatabaseRepositoryOptions } from '../../database.js';
|
|
5
5
|
export declare abstract class RedisBaseRepository {
|
|
6
6
|
protected readonly validator: Validator;
|
|
7
7
|
protected readonly config: Config<RedisDatabaseConfig>;
|
|
@@ -11,15 +11,15 @@ export declare abstract class RedisBaseRepository {
|
|
|
11
11
|
protected readonly options: RedisDatabaseRepositoryOptions;
|
|
12
12
|
protected readonly connection: RedisDatabaseConnection;
|
|
13
13
|
constructor(validator: Validator, config: Config<RedisDatabaseConfig>, logger: Logger, connector: DatabaseConnector, repositoryName: string);
|
|
14
|
+
protected encodeJson(obj: object): string;
|
|
15
|
+
protected decodeJson(str: string): unknown;
|
|
16
|
+
protected encodeBase64(buf: Buffer): string;
|
|
17
|
+
protected decodeBase64(str: string): Buffer;
|
|
14
18
|
protected validateStringReply(value: unknown): asserts value is string;
|
|
15
19
|
protected validateArrayReply(value: unknown): asserts value is unknown[];
|
|
16
20
|
protected validateArrayStringsReply(value: unknown): asserts value is string[];
|
|
17
|
-
protected
|
|
21
|
+
protected parseStatusReply(value: unknown): [DatabaseStatusCode, string];
|
|
18
22
|
protected validateRawData<T>(schema: string, value: unknown): asserts value is T;
|
|
19
|
-
protected
|
|
20
|
-
protected encodeJson(value: object): string;
|
|
21
|
-
protected decodeBase64(value: string): Buffer;
|
|
22
|
-
protected encodeBase64(value: Buffer): string;
|
|
23
|
-
protected raiseError(error: unknown, method: string, data: unknown): never;
|
|
23
|
+
protected raiseError(error: unknown, method: string, params: unknown): never;
|
|
24
24
|
private buildOptions;
|
|
25
25
|
}
|
|
@@ -18,109 +18,129 @@ export class RedisBaseRepository {
|
|
|
18
18
|
this.options = this.buildOptions(config.data);
|
|
19
19
|
this.connection = connector.getConnection();
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
encodeJson(obj) {
|
|
22
|
+
try {
|
|
23
|
+
return JSON.stringify(obj);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new DatabaseError(`Encode JSON failed`, {
|
|
27
|
+
cause: error,
|
|
24
28
|
code: 'INTERNAL_ERROR',
|
|
25
29
|
});
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
decodeJson(str) {
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(str);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw new DatabaseError(`Decode JSON failed`, {
|
|
38
|
+
cause: error,
|
|
31
39
|
code: 'INTERNAL_ERROR',
|
|
32
40
|
});
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
throw new DatabaseError(`
|
|
43
|
+
encodeBase64(buf) {
|
|
44
|
+
try {
|
|
45
|
+
return buf.toString('base64');
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new DatabaseError(`Encode Base64 failed`, {
|
|
49
|
+
cause: error,
|
|
41
50
|
code: 'INTERNAL_ERROR',
|
|
42
51
|
});
|
|
43
52
|
}
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
code: 'INTERNAL_ERROR',
|
|
49
|
-
});
|
|
54
|
+
decodeBase64(str) {
|
|
55
|
+
try {
|
|
56
|
+
return Buffer.from(str, 'base64');
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
catch (error) {
|
|
59
|
+
throw new DatabaseError(`Decode Base64 failed`, {
|
|
60
|
+
cause: error,
|
|
54
61
|
code: 'INTERNAL_ERROR',
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
|
-
if (code !== 'OK') {
|
|
58
|
-
throw new DatabaseError(message, {
|
|
59
|
-
code,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return message;
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
validateStringReply(value) {
|
|
65
66
|
try {
|
|
66
|
-
|
|
67
|
+
if (!(typeof value === 'string' && value.length > 0)) {
|
|
68
|
+
throw new Error(`Value is not a non-empty string`);
|
|
69
|
+
}
|
|
67
70
|
}
|
|
68
71
|
catch (error) {
|
|
69
|
-
throw new DatabaseError(`
|
|
72
|
+
throw new DatabaseError(`Validate string reply failed`, {
|
|
70
73
|
cause: error,
|
|
71
74
|
code: 'INTERNAL_ERROR',
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
|
|
78
|
+
validateArrayReply(value) {
|
|
76
79
|
try {
|
|
77
|
-
|
|
80
|
+
if (!(typeof value === 'object' && value != null && Array.isArray(value))) {
|
|
81
|
+
throw new Error(`Value is not an array`);
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
catch (error) {
|
|
80
|
-
throw new DatabaseError(`
|
|
85
|
+
throw new DatabaseError(`Validate array reply failed`, {
|
|
81
86
|
cause: error,
|
|
82
87
|
code: 'INTERNAL_ERROR',
|
|
83
88
|
});
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
|
-
|
|
91
|
+
validateArrayStringsReply(value) {
|
|
87
92
|
try {
|
|
88
|
-
|
|
93
|
+
if (!(typeof value === 'object' && value != null && Array.isArray(value))) {
|
|
94
|
+
throw new Error(`Value is not an array`);
|
|
95
|
+
}
|
|
96
|
+
if (!value.every((val) => typeof val === 'string' && val.length > 0)) {
|
|
97
|
+
throw new Error(`Value is not an array of non-empty strings`);
|
|
98
|
+
}
|
|
89
99
|
}
|
|
90
100
|
catch (error) {
|
|
91
|
-
throw new DatabaseError(`
|
|
101
|
+
throw new DatabaseError(`Validate array-strings reply failed`, {
|
|
92
102
|
cause: error,
|
|
93
103
|
code: 'INTERNAL_ERROR',
|
|
94
104
|
});
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
|
-
|
|
107
|
+
parseStatusReply(value) {
|
|
98
108
|
try {
|
|
99
|
-
|
|
109
|
+
if (!(typeof value === 'string' && value.length > 0)) {
|
|
110
|
+
throw new Error(`Value is not a non-empty string`);
|
|
111
|
+
}
|
|
112
|
+
const [code, mesg] = value.split(/\s+(.*)/, 2);
|
|
113
|
+
if (!(code && mesg)) {
|
|
114
|
+
throw new Error(`Value is not parsable to code and mesg`);
|
|
115
|
+
}
|
|
116
|
+
if (!arrayIncludes(DATABASE_STATUS_CODES, code)) {
|
|
117
|
+
throw new Error(`Status code not known: ${code}`);
|
|
118
|
+
}
|
|
119
|
+
return [code, mesg];
|
|
100
120
|
}
|
|
101
121
|
catch (error) {
|
|
102
|
-
throw new DatabaseError(`
|
|
122
|
+
throw new DatabaseError(`Parse status reply failed`, {
|
|
103
123
|
cause: error,
|
|
104
124
|
code: 'INTERNAL_ERROR',
|
|
105
125
|
});
|
|
106
126
|
}
|
|
107
127
|
}
|
|
108
|
-
|
|
128
|
+
validateRawData(schema, value) {
|
|
109
129
|
try {
|
|
110
|
-
|
|
130
|
+
this.validator.assertSchema(schema, value);
|
|
111
131
|
}
|
|
112
132
|
catch (error) {
|
|
113
|
-
throw new DatabaseError(`
|
|
133
|
+
throw new DatabaseError(`Validate raw-data failed`, {
|
|
114
134
|
cause: error,
|
|
115
135
|
code: 'INTERNAL_ERROR',
|
|
116
136
|
});
|
|
117
137
|
}
|
|
118
138
|
}
|
|
119
|
-
raiseError(error, method,
|
|
139
|
+
raiseError(error, method, params) {
|
|
120
140
|
if (error instanceof DatabaseError) {
|
|
121
141
|
error.context['repository'] = this.repositoryName;
|
|
122
142
|
error.context['method'] = method;
|
|
123
|
-
error.context['
|
|
143
|
+
error.context['params'] = params;
|
|
124
144
|
throw error;
|
|
125
145
|
}
|
|
126
146
|
else {
|
|
@@ -129,7 +149,7 @@ export class RedisBaseRepository {
|
|
|
129
149
|
context: {
|
|
130
150
|
repository: this.repositoryName,
|
|
131
151
|
method,
|
|
132
|
-
|
|
152
|
+
params,
|
|
133
153
|
},
|
|
134
154
|
code: 'INTERNAL_ERROR',
|
|
135
155
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-base.repository.js","sourceRoot":"","sources":["../../../src/modules/base/redis-base.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAI7C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EACL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"redis-base.repository.js","sourceRoot":"","sources":["../../../src/modules/base/redis-base.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAI7C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EACL,qBAAqB,GAMtB,MAAM,mBAAmB,CAAA;AAO1B,MAAM,OAAgB,mBAAmB;IAOlB;IACA;IACA;IACA;IACA;IATF,OAAO,CAAgC;IAEvC,UAAU,CAAyB;IAEtD,YACqB,SAAoB,EACpB,MAAmC,EACnC,MAAc,EACd,SAA4B,EAC5B,cAAsB;QAJtB,cAAS,GAAT,SAAS,CAAW;QACpB,WAAM,GAAN,MAAM,CAA6B;QACnC,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAmB;QAC5B,mBAAc,GAAd,cAAc,CAAQ;QAEzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAE7C,IAAI,CAAC,UAAU,GAAG,SAAS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