@prosopo/database 0.2.29 → 0.2.33
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/cjs/eventsDatabase/eventsDatabase.cjs +37 -11
- package/dist/eventsDatabase/eventsDatabase.d.ts +1 -1
- package/dist/eventsDatabase/eventsDatabase.d.ts.map +1 -1
- package/dist/eventsDatabase/eventsDatabase.js +40 -16
- package/dist/eventsDatabase/eventsDatabase.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const common = require("@prosopo/common");
|
|
3
4
|
const mongoose = require("mongoose");
|
|
5
|
+
const logger = common.getLoggerDefault();
|
|
6
|
+
const MAX_RETRIES = 3;
|
|
4
7
|
const captchaEventSchema = new mongoose.Schema({
|
|
5
8
|
touchEvents: [
|
|
6
9
|
{
|
|
@@ -20,28 +23,51 @@ const captchaEventSchema = new mongoose.Schema({
|
|
|
20
23
|
{
|
|
21
24
|
key: String,
|
|
22
25
|
timestamp: Number,
|
|
23
|
-
isShiftKey: Boolean,
|
|
24
|
-
isCtrlKey: Boolean
|
|
26
|
+
isShiftKey: { type: Boolean, required: false },
|
|
27
|
+
isCtrlKey: { type: Boolean, required: false }
|
|
25
28
|
}
|
|
26
29
|
],
|
|
27
30
|
accountId: String
|
|
28
31
|
});
|
|
29
|
-
|
|
32
|
+
let CaptchaEvent;
|
|
33
|
+
try {
|
|
34
|
+
CaptchaEvent = mongoose.model("CaptchaEvent");
|
|
35
|
+
} catch (error) {
|
|
36
|
+
CaptchaEvent = mongoose.model("CaptchaEvent", captchaEventSchema);
|
|
37
|
+
}
|
|
30
38
|
const addCaptchaEventRecord = async (record) => {
|
|
31
39
|
try {
|
|
32
40
|
const newRecord = new CaptchaEvent(record);
|
|
33
41
|
await newRecord.save();
|
|
34
|
-
|
|
42
|
+
logger.info("Record added successfully");
|
|
35
43
|
} catch (error) {
|
|
36
|
-
|
|
44
|
+
logger.error("Error adding record to the database:", error);
|
|
37
45
|
}
|
|
38
46
|
};
|
|
39
47
|
const saveCaptchaEvent = async (events, accountId, atlasUri) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const connection = mongoose.createConnection(atlasUri);
|
|
50
|
+
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
51
|
+
connection.once("open", resolve).on("error", (e) => {
|
|
52
|
+
logger.warn(`Mongoose connection error`);
|
|
53
|
+
logger.error(e);
|
|
54
|
+
if (attempt === MAX_RETRIES) {
|
|
55
|
+
reject(
|
|
56
|
+
new common.ProsopoDBError("DATABASE.CONNECT_ERROR", {
|
|
57
|
+
context: { failedFuncName: saveCaptchaEvent.name, db: "events database" },
|
|
58
|
+
logger
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
} else {
|
|
62
|
+
connection == null ? void 0 : connection.removeAllListeners("error");
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const captchaEventData = {
|
|
67
|
+
...events,
|
|
68
|
+
accountId
|
|
69
|
+
};
|
|
70
|
+
addCaptchaEventRecord(captchaEventData).then(() => logger.info("Captcha event data saved")).catch((error) => logger.error("Error saving captcha event data:", error)).finally(() => connection.close());
|
|
71
|
+
});
|
|
46
72
|
};
|
|
47
73
|
exports.saveCaptchaEvent = saveCaptchaEvent;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { StoredEvents } from '@prosopo/types';
|
|
2
|
-
export declare const saveCaptchaEvent: (events: StoredEvents, accountId: string, atlasUri: string) => Promise<
|
|
2
|
+
export declare const saveCaptchaEvent: (events: StoredEvents, accountId: string, atlasUri: string) => Promise<unknown>;
|
|
3
3
|
//# sourceMappingURL=eventsDatabase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventsDatabase.d.ts","sourceRoot":"","sources":["../../src/eventsDatabase/eventsDatabase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eventsDatabase.d.ts","sourceRoot":"","sources":["../../src/eventsDatabase/eventsDatabase.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AA+ChE,eAAO,MAAM,gBAAgB,WAAkB,YAAY,aAAa,MAAM,YAAY,MAAM,qBAiC/F,CAAA"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { ProsopoDBError, getLoggerDefault } from '@prosopo/common';
|
|
1
2
|
import mongoose from 'mongoose';
|
|
3
|
+
const logger = getLoggerDefault();
|
|
4
|
+
const MAX_RETRIES = 3;
|
|
2
5
|
const captchaEventSchema = new mongoose.Schema({
|
|
3
6
|
touchEvents: [
|
|
4
7
|
{
|
|
@@ -18,34 +21,55 @@ const captchaEventSchema = new mongoose.Schema({
|
|
|
18
21
|
{
|
|
19
22
|
key: String,
|
|
20
23
|
timestamp: Number,
|
|
21
|
-
isShiftKey: Boolean,
|
|
22
|
-
isCtrlKey: Boolean,
|
|
24
|
+
isShiftKey: { type: Boolean, required: false },
|
|
25
|
+
isCtrlKey: { type: Boolean, required: false },
|
|
23
26
|
},
|
|
24
27
|
],
|
|
25
28
|
accountId: String,
|
|
26
29
|
});
|
|
27
|
-
|
|
30
|
+
let CaptchaEvent;
|
|
31
|
+
try {
|
|
32
|
+
CaptchaEvent = mongoose.model('CaptchaEvent');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
CaptchaEvent = mongoose.model('CaptchaEvent', captchaEventSchema);
|
|
36
|
+
}
|
|
28
37
|
const addCaptchaEventRecord = async (record) => {
|
|
29
38
|
try {
|
|
30
39
|
const newRecord = new CaptchaEvent(record);
|
|
31
40
|
await newRecord.save();
|
|
32
|
-
|
|
41
|
+
logger.info('Record added successfully');
|
|
33
42
|
}
|
|
34
43
|
catch (error) {
|
|
35
|
-
|
|
44
|
+
logger.error('Error adding record to the database:', error);
|
|
36
45
|
}
|
|
37
46
|
};
|
|
38
47
|
export const saveCaptchaEvent = async (events, accountId, atlasUri) => {
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const connection = mongoose.createConnection(atlasUri);
|
|
50
|
+
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
51
|
+
connection.once('open', resolve).on('error', (e) => {
|
|
52
|
+
logger.warn(`Mongoose connection error`);
|
|
53
|
+
logger.error(e);
|
|
54
|
+
if (attempt === MAX_RETRIES) {
|
|
55
|
+
reject(new ProsopoDBError('DATABASE.CONNECT_ERROR', {
|
|
56
|
+
context: { failedFuncName: saveCaptchaEvent.name, db: 'events database' },
|
|
57
|
+
logger: logger,
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
connection?.removeAllListeners('error');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const captchaEventData = {
|
|
66
|
+
...events,
|
|
67
|
+
accountId,
|
|
68
|
+
};
|
|
69
|
+
addCaptchaEventRecord(captchaEventData)
|
|
70
|
+
.then(() => logger.info('Captcha event data saved'))
|
|
71
|
+
.catch((error) => logger.error('Error saving captcha event data:', error))
|
|
72
|
+
.finally(() => connection.close());
|
|
73
|
+
});
|
|
50
74
|
};
|
|
51
75
|
//# sourceMappingURL=eventsDatabase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventsDatabase.js","sourceRoot":"","sources":["../../src/eventsDatabase/eventsDatabase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eventsDatabase.js","sourceRoot":"","sources":["../../src/e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GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/database",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.33",
|
|
4
4
|
"description": "Prosopo database plugins for provider",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@polkadot/util": "^12.5.1",
|
|
40
|
-
"@prosopo/captcha-contract": "0.2.
|
|
41
|
-
"@prosopo/common": "0.2.
|
|
42
|
-
"@prosopo/config": "0.2.
|
|
43
|
-
"@prosopo/types": "0.2.
|
|
44
|
-
"@prosopo/types-database": "0.2.
|
|
40
|
+
"@prosopo/captcha-contract": "0.2.33",
|
|
41
|
+
"@prosopo/common": "0.2.33",
|
|
42
|
+
"@prosopo/config": "0.2.33",
|
|
43
|
+
"@prosopo/types": "0.2.33",
|
|
44
|
+
"@prosopo/types-database": "0.2.33",
|
|
45
45
|
"mongodb": "5.8.0",
|
|
46
46
|
"mongodb-memory-server": "^8.7.2",
|
|
47
47
|
"mongoose": "^7.3.3"
|