@sphereon/ssi-sdk.anomaly-detection 0.30.2-next.373 → 0.31.0

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 CHANGED
@@ -38,7 +38,7 @@ const agent = createAgent<IAnomalyDetection>({
38
38
 
39
39
  ```typescript
40
40
  const result = await agent.lookupLocation({
41
- ipOrHostname: '2001:0000:130F:0000:0000:09C0:876A:130B'
41
+ ipOrHostname: '2001:0000:130F:0000:0000:09C0:876A:130B',
42
42
  })
43
43
  ```
44
44
 
@@ -1 +1 @@
1
- {"version":3,"file":"AnomalyDetection.d.ts","sourceRoot":"","sources":["../../src/agent/AnomalyDetection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAA;AACzC,OAAO,EACL,iBAAiB,EAIlB,MAAM,UAAU,CAAA;AAGjB,KAAK,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;AAExD,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,MAAM,CAAsB,CAAA;AAExE;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAQ;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAa;IACxC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAElC;gBAEW,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,WAAW,CAAA;KAAE;YASxD,8BAA8B;YA+B9B,UAAU;CA0BzB"}
1
+ {"version":3,"file":"AnomalyDetection.d.ts","sourceRoot":"","sources":["../../src/agent/AnomalyDetection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAGL,iBAAiB,EAGlB,MAAM,UAAU,CAAA;AAEjB,KAAK,WAAW,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;AAExD,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,MAAM,CAAsB,CAAA;AAExE;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAQ;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAa;IACxC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAElC;gBAEW,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,iBAAiB,CAAC,EAAE,WAAW,CAAA;KAAE;YASxD,8BAA8B;YAiC9B,UAAU;CA0BzB"}
@@ -10,8 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AnomalyDetection = exports.anomalyDetectionMethods = void 0;
13
- const index_1 = require("../index");
13
+ const ssi_sdk_agent_config_1 = require("@sphereon/ssi-sdk.agent-config");
14
14
  const mmdb_lib_1 = require("mmdb-lib");
15
+ const index_1 = require("../index");
15
16
  exports.anomalyDetectionMethods = ['lookupLocation'];
16
17
  /**
17
18
  * {@inheritDoc IAnomalyDetection}
@@ -20,7 +21,7 @@ class AnomalyDetection {
20
21
  constructor(args) {
21
22
  this.schema = index_1.schema.IAnomalyDetection;
22
23
  this.methods = {
23
- anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),
24
+ anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this)
24
25
  };
25
26
  const { geoIpDB, dnsLookupCallback } = Object.assign({}, args);
26
27
  if (geoIpDB === undefined || geoIpDB === null) {
@@ -31,7 +32,7 @@ class AnomalyDetection {
31
32
  }
32
33
  anomalyDetectionLookupLocation(args, context) {
33
34
  return __awaiter(this, void 0, void 0, function* () {
34
- var _a, _b, _c, _d;
35
+ var _a, _b;
35
36
  const { ipOrHostname, storeId, namespace } = Object.assign({}, args);
36
37
  const reader = new mmdb_lib_1.Reader(this.db);
37
38
  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])';
@@ -46,16 +47,15 @@ class AnomalyDetection {
46
47
  }
47
48
  const lookupResult = {
48
49
  continent: (_a = result === null || result === void 0 ? void 0 : result.continent) === null || _a === void 0 ? void 0 : _a.code,
49
- country: (_b = result === null || result === void 0 ? void 0 : result.country) === null || _b === void 0 ? void 0 : _b.iso_code,
50
+ country: (_b = result === null || result === void 0 ? void 0 : result.country) === null || _b === void 0 ? void 0 : _b.iso_code
50
51
  };
51
- if (((_c = context.agent) === null || _c === void 0 ? void 0 : _c.anomalyDetectionStorePersistLocation) !== undefined && ((_d = context.agent) === null || _d === void 0 ? void 0 : _d.anomalyDetectionStorePersistLocation) !== null) {
52
- yield context.agent.anomalyDetectionStorePersistLocation({
52
+ if ((0, ssi_sdk_agent_config_1.contextHasPlugin)(context, 'geolocationStorePersistLocation'))
53
+ yield context.agent.geolocationStorePersistLocation({
53
54
  namespace,
54
55
  storeId,
55
56
  ipOrHostname,
56
- locationArgs: lookupResult,
57
+ locationArgs: lookupResult
57
58
  });
58
- }
59
59
  return Promise.resolve(lookupResult);
60
60
  });
61
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AnomalyDetection.js","sourceRoot":"","sources":["../../src/agent/AnomalyDetection.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAKiB;AACjB,uCAAgD;AAInC,QAAA,uBAAuB,GAAkB,CAAC,gBAAgB,CAAC,CAAA;AAExE;;GAEG;AACH,MAAa,gBAAgB;IAQ3B,YAAY,IAA0D;QAP7D,WAAM,GAAG,cAAM,CAAC,iBAAiB,CAAA;QAGjC,YAA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;wBACV,MAAM,CAAC,KAAK,CAAC,CAAA;wBACb,OAAM;oBACR,CAAC;oBACD,OAAO,CAAC,OAAO,CAAC,CAAA;gBAClB,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AA5ED,4CA4EC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.anomaly-detection",
3
- "version": "0.30.2-next.373+f0e1a58a",
3
+ "version": "0.31.0",
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.30.2-next.373+f0e1a58a",
19
- "@sphereon/ssi-sdk.kv-store-temp": "0.30.2-next.373+f0e1a58a",
18
+ "@sphereon/ssi-sdk.geolocation-store": "0.31.0",
19
+ "@sphereon/ssi-sdk.kv-store-temp": "0.31.0",
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.20"
25
25
  },
26
26
  "devDependencies": {
27
- "@sphereon/ssi-sdk.agent-config": "0.30.2-next.373+f0e1a58a",
27
+ "@sphereon/ssi-sdk.agent-config": "0.31.0",
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": "f0e1a58a7c8fcacf64411c0f60da8eec0c0d9085"
53
+ "gitHead": "3010f7bc57ed5f8d7953b6bf893e3164ea1821e8"
54
54
  }
@@ -1,11 +1,13 @@
1
- import {IAgentPlugin} from '@veramo/core'
1
+ import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
2
+ import { IAgentPlugin } from '@veramo/core'
3
+ import { CountryResponse, Reader } from 'mmdb-lib'
2
4
  import {
3
- IAnomalyDetection,
4
5
  AnomalyDetectionLookupLocationArgs,
5
- schema,
6
- AnomalyDetectionLookupLocationResult, IRequiredContext
6
+ AnomalyDetectionLookupLocationResult,
7
+ IAnomalyDetection,
8
+ IRequiredContext,
9
+ schema
7
10
  } from '../index'
8
- import {CountryResponse, Reader} from 'mmdb-lib'
9
11
 
10
12
  type DnsLookupFn = (hostname: string) => Promise<string>
11
13
 
@@ -19,7 +21,7 @@ export class AnomalyDetection implements IAgentPlugin {
19
21
  private readonly db: Buffer
20
22
  private readonly dnsLookup?: DnsLookupFn
21
23
  readonly methods: IAnomalyDetection = {
22
- anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),
24
+ anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this)
23
25
  }
24
26
 
25
27
  constructor(args: { geoIpDB: Buffer; dnsLookupCallback?: DnsLookupFn }) {
@@ -31,7 +33,10 @@ export class AnomalyDetection implements IAgentPlugin {
31
33
  this.dnsLookup = dnsLookupCallback
32
34
  }
33
35
 
34
- private async anomalyDetectionLookupLocation(args: AnomalyDetectionLookupLocationArgs, context: IRequiredContext): Promise<AnomalyDetectionLookupLocationResult> {
36
+ private async anomalyDetectionLookupLocation(
37
+ args: AnomalyDetectionLookupLocationArgs,
38
+ context: IRequiredContext
39
+ ): Promise<AnomalyDetectionLookupLocationResult> {
35
40
  const { ipOrHostname, storeId, namespace } = { ...args }
36
41
  const reader = new Reader<CountryResponse>(this.db)
37
42
  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])'
@@ -48,17 +53,16 @@ export class AnomalyDetection implements IAgentPlugin {
48
53
 
49
54
  const lookupResult = {
50
55
  continent: result?.continent?.code,
51
- country: result?.country?.iso_code,
56
+ country: result?.country?.iso_code
52
57
  }
53
58
 
54
- if (context.agent?.anomalyDetectionStorePersistLocation !== undefined && context.agent?.anomalyDetectionStorePersistLocation !== null) {
55
- await context.agent.anomalyDetectionStorePersistLocation({
59
+ if (contextHasPlugin(context, 'geolocationStorePersistLocation'))
60
+ await context.agent.geolocationStorePersistLocation({
56
61
  namespace,
57
62
  storeId,
58
63
  ipOrHostname,
59
- locationArgs: lookupResult,
64
+ locationArgs: lookupResult
60
65
  })
61
- }
62
66
  return Promise.resolve(lookupResult)
63
67
  }
64
68
 
@@ -74,7 +78,7 @@ export class AnomalyDetection implements IAgentPlugin {
74
78
  } catch (e) {
75
79
  console.error(e)
76
80
  throw new Error(
77
- `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}`,
81
+ `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}`
78
82
  )
79
83
  }
80
84