@sphereon/ssi-sdk.anomaly-detection 0.33.0 → 0.33.1-feature.vcdm2.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.
|
@@ -1,89 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.AnomalyDetection = exports.anomalyDetectionMethods = void 0;
|
|
13
|
-
const ssi_sdk_agent_config_1 = require("@sphereon/ssi-sdk.agent-config");
|
|
14
|
-
const mmdb_lib_1 = require("mmdb-lib");
|
|
15
|
-
const index_1 = require("../index");
|
|
16
|
-
exports.anomalyDetectionMethods = ['lookupLocation'];
|
|
1
|
+
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config';
|
|
2
|
+
import { Reader } from 'mmdb-lib';
|
|
3
|
+
import { schema } from '../index';
|
|
4
|
+
export const anomalyDetectionMethods = ['lookupLocation'];
|
|
17
5
|
/**
|
|
18
6
|
* {@inheritDoc IAnomalyDetection}
|
|
19
7
|
*/
|
|
20
|
-
class AnomalyDetection {
|
|
8
|
+
export class AnomalyDetection {
|
|
9
|
+
schema = schema.IAnomalyDetection;
|
|
10
|
+
db;
|
|
11
|
+
dnsLookup;
|
|
12
|
+
methods = {
|
|
13
|
+
anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),
|
|
14
|
+
};
|
|
21
15
|
constructor(args) {
|
|
22
|
-
|
|
23
|
-
this.methods = {
|
|
24
|
-
anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),
|
|
25
|
-
};
|
|
26
|
-
const { geoIpDB, dnsLookupCallback } = Object.assign({}, args);
|
|
16
|
+
const { geoIpDB, dnsLookupCallback } = { ...args };
|
|
27
17
|
if (geoIpDB === undefined || geoIpDB === null) {
|
|
28
18
|
throw new Error('The geoIpDB argument is required');
|
|
29
19
|
}
|
|
30
20
|
this.db = geoIpDB;
|
|
31
21
|
this.dnsLookup = dnsLookupCallback;
|
|
32
22
|
}
|
|
33
|
-
anomalyDetectionLookupLocation(args, context) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
return Promise.resolve(lookupResult);
|
|
60
|
-
});
|
|
23
|
+
async anomalyDetectionLookupLocation(args, context) {
|
|
24
|
+
const { ipOrHostname, storeId, namespace } = { ...args };
|
|
25
|
+
const reader = new Reader(this.db);
|
|
26
|
+
const ipv4Reg = '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
|
|
27
|
+
const ipv6Reg = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
|
|
28
|
+
let result;
|
|
29
|
+
if (!new RegExp(ipv4Reg).test(ipOrHostname) && !new RegExp(ipv6Reg).test(ipOrHostname)) {
|
|
30
|
+
const ip = await this.resolveDns(ipOrHostname);
|
|
31
|
+
result = reader.get(ip);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result = reader.get(ipOrHostname);
|
|
35
|
+
}
|
|
36
|
+
const lookupResult = {
|
|
37
|
+
continent: result?.continent?.code,
|
|
38
|
+
country: result?.country?.iso_code,
|
|
39
|
+
};
|
|
40
|
+
if (contextHasPlugin(context, 'geolocationStorePersistLocation'))
|
|
41
|
+
await context.agent.geolocationStorePersistLocation({
|
|
42
|
+
namespace,
|
|
43
|
+
storeId,
|
|
44
|
+
ipOrHostname,
|
|
45
|
+
locationArgs: lookupResult,
|
|
46
|
+
});
|
|
47
|
+
return Promise.resolve(lookupResult);
|
|
61
48
|
}
|
|
62
|
-
resolveDns(hostname) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
resolve(address);
|
|
83
|
-
});
|
|
49
|
+
async resolveDns(hostname) {
|
|
50
|
+
if (this.dnsLookup) {
|
|
51
|
+
return this.dnsLookup(hostname);
|
|
52
|
+
}
|
|
53
|
+
// Fallback to Node.js dns
|
|
54
|
+
let dns;
|
|
55
|
+
try {
|
|
56
|
+
dns = eval('require("dns")');
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.error(e);
|
|
60
|
+
throw new Error(`DNS resolution not available on this platform, use the dnsLookupCallback in the AnomalyDetection constructor to implement DNS resolution for your platform.\r\n${e.message}`);
|
|
61
|
+
}
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
dns.lookup(hostname, (error, address, family) => {
|
|
64
|
+
if (error) {
|
|
65
|
+
reject(error);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
resolve(address);
|
|
84
69
|
});
|
|
85
70
|
});
|
|
86
71
|
}
|
|
87
72
|
}
|
|
88
|
-
exports.AnomalyDetection = AnomalyDetection;
|
|
89
73
|
//# sourceMappingURL=AnomalyDetection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnomalyDetection.js","sourceRoot":"","sources":["../../src/agent/AnomalyDetection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AnomalyDetection.js","sourceRoot":"","sources":["../../src/agent/AnomalyDetection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AAEjE,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAiH,MAAM,EAAE,MAAM,UAAU,CAAA;AAIhJ,MAAM,CAAC,MAAM,uBAAuB,GAAkB,CAAC,gBAAgB,CAAC,CAAA;AAExE;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAClB,MAAM,GAAG,MAAM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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
|
-
exports.anomalyDetectionMethods = exports.AnomalyDetection = exports.schema = void 0;
|
|
18
1
|
/**
|
|
19
2
|
* @public
|
|
20
3
|
*/
|
|
21
4
|
const schema = require('../plugin.schema.json');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(exports, "anomalyDetectionMethods", { enumerable: true, get: function () { return AnomalyDetection_1.anomalyDetectionMethods; } });
|
|
26
|
-
__exportStar(require("./types/IAnomalyDetection"), exports);
|
|
5
|
+
export { schema };
|
|
6
|
+
export { AnomalyDetection, anomalyDetectionMethods } from './agent/AnomalyDetection';
|
|
7
|
+
export * from './types/IAnomalyDetection';
|
|
27
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AACpF,cAAc,2BAA2B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.anomaly-detection",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"generate-plugin-schema": "ts-node ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sphereon/ssi-sdk.geolocation-store": "0.33.
|
|
19
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.33.
|
|
18
|
+
"@sphereon/ssi-sdk.geolocation-store": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
19
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
20
20
|
"cross-fetch": "^3.1.8",
|
|
21
21
|
"debug": "^4.3.5",
|
|
22
22
|
"dns-query": "^0.11.2",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"typeorm": "^0.3.21"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@sphereon/ssi-sdk.agent-config": "0.33.
|
|
27
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
28
28
|
"@types/node": "^20.17.1",
|
|
29
29
|
"@veramo/remote-client": "4.2.0",
|
|
30
30
|
"@veramo/remote-server": "4.2.0"
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"Anomaly Detection"
|
|
51
51
|
],
|
|
52
52
|
"nx": {},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "9f634bdb714061141e277508c124b08d626f6036"
|
|
54
54
|
}
|