@sphereon/ssi-sdk.resource-resolver 0.30.2-next.329 → 0.30.2-next.363
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/agent/ResourceResolver.d.ts +2 -0
- package/dist/agent/ResourceResolver.d.ts.map +1 -1
- package/dist/agent/ResourceResolver.js +24 -1
- package/dist/agent/ResourceResolver.js.map +1 -1
- package/dist/types/IResourceResolver.d.ts +8 -1
- package/dist/types/IResourceResolver.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/agent/ResourceResolver.ts +25 -2
- package/src/types/IResourceResolver.ts +11 -3
@@ -9,10 +9,12 @@ export declare class ResourceResolver implements IAgentPlugin {
|
|
9
9
|
private readonly defaultStoreId;
|
10
10
|
private readonly defaultNamespace;
|
11
11
|
private readonly defaultTtl;
|
12
|
+
private readonly detectLocation;
|
12
13
|
private readonly _resourceStores;
|
13
14
|
constructor(options?: ResourceResolverOptions);
|
14
15
|
/** {@inheritDoc IResourceResolver.resourceResolve} */
|
15
16
|
private resourceResolve;
|
17
|
+
private retrieveLocation;
|
16
18
|
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
17
19
|
private resourceClearAllResources;
|
18
20
|
/** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ResourceResolver.d.ts","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAS3C,OAAO,EAIL,iBAAiB,EAKjB,uBAAuB,EAIxB,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAMlC;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuC;gBAE3D,OAAO,CAAC,EAAE,uBAAuB;
|
1
|
+
{"version":3,"file":"ResourceResolver.d.ts","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAS3C,OAAO,EAIL,iBAAiB,EAKjB,uBAAuB,EAIxB,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAMlC;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuC;gBAE3D,OAAO,CAAC,EAAE,uBAAuB;IA8B7C,sDAAsD;YACxC,eAAe;YA0Df,gBAAgB;IAc9B,gEAAgE;YAClD,yBAAyB;IAOvC,6DAA6D;YAC/C,sBAAsB;IAIpC,+DAA+D;YACjD,wBAAwB;IAItC,yDAAyD;YAC3C,kBAAkB;YAIlB,WAAW;YAUX,eAAe;IAe7B,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,MAAM;CAKf"}
|
@@ -50,10 +50,11 @@ class ResourceResolver {
|
|
50
50
|
resourceDefaultNamespace: this.resourceDefaultNamespace.bind(this),
|
51
51
|
resourceDefaultTtl: this.resourceDefaultTtl.bind(this),
|
52
52
|
};
|
53
|
-
const { defaultStore, defaultNamespace, resourceStores, ttl } = options !== null && options !== void 0 ? options : {};
|
53
|
+
const { defaultStore, defaultNamespace, resourceStores, ttl, detectLocation } = options !== null && options !== void 0 ? options : {};
|
54
54
|
this.defaultStoreId = defaultStore !== null && defaultStore !== void 0 ? defaultStore : '_default';
|
55
55
|
this.defaultNamespace = defaultNamespace !== null && defaultNamespace !== void 0 ? defaultNamespace : 'resources';
|
56
56
|
this.defaultTtl = ttl !== null && ttl !== void 0 ? ttl : 3600;
|
57
|
+
this.detectLocation = detectLocation !== null && detectLocation !== void 0 ? detectLocation : false;
|
57
58
|
if (resourceStores && resourceStores instanceof Map) {
|
58
59
|
this._resourceStores = resourceStores;
|
59
60
|
}
|
@@ -84,10 +85,15 @@ class ResourceResolver {
|
|
84
85
|
headers: new cross_fetch_1.Headers({ 'Content-Type': 'application/json' })
|
85
86
|
});
|
86
87
|
}
|
88
|
+
let location;
|
89
|
+
if (this.detectLocation) {
|
90
|
+
location = yield this.retrieveLocation(input, context);
|
91
|
+
}
|
87
92
|
const response = yield (0, cross_fetch_1.default)(input, init);
|
88
93
|
if (!(resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.skipPersistence) && (response.status >= 200 && response.status < 300)) {
|
89
94
|
const serializedResponse = yield (0, ResourceResolverUtils_1.serializeResponse)(response);
|
90
95
|
const resource = {
|
96
|
+
location,
|
91
97
|
response: serializedResponse,
|
92
98
|
resourceType,
|
93
99
|
insertedAt: Date.now(),
|
@@ -107,6 +113,23 @@ class ResourceResolver {
|
|
107
113
|
return response;
|
108
114
|
});
|
109
115
|
}
|
116
|
+
retrieveLocation(input, context) {
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
118
|
+
let url;
|
119
|
+
if (input instanceof Request && input.url !== undefined && input.url !== null) {
|
120
|
+
url = new URL(input.url);
|
121
|
+
}
|
122
|
+
else if (input instanceof URL) {
|
123
|
+
url = input;
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
throw Error(`input type is required to be RequestInfo | URL`);
|
127
|
+
}
|
128
|
+
return yield context.agent.anomalyDetectionLookupLocation({
|
129
|
+
ipOrHostname: url.hostname
|
130
|
+
});
|
131
|
+
});
|
132
|
+
}
|
110
133
|
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
111
134
|
resourceClearAllResources(args, context) {
|
112
135
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ResourceResolver.js","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EAKwC;AAExC,2DAAsD;AACtD,oCAAiC;AACjC,0EAKuC;AAgBvC;;GAEG;AACH,MAAa,gBAAgB;
|
1
|
+
{"version":3,"file":"ResourceResolver.js","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EAKwC;AAExC,2DAAsD;AACtD,oCAAiC;AACjC,0EAKuC;AAgBvC;;GAEG;AACH,MAAa,gBAAgB;IAgB3B,YAAY,OAAiC;QAfpC,WAAM,GAAG,cAAM,CAAC,iBAAiB,CAAA;QACjC,YAAO,GAAsB;YACpC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAChD,yBAAyB,EAAE,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;YACpE,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC9D,wBAAwB,EAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC;YAClE,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;SACvD,CAAA;QASC,MAAM,EACJ,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,GAAG,EACH,cAAc,EACf,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAA;QAEjB,IAAI,CAAC,cAAc,GAAG,YAAY,aAAZ,YAAY,cAAZ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AAK,EAAE,CAAC;YACX,MAAM,KAAK,CAAC,iCAAiC,OAAO,EAAE,CAAC,CAAA;QACzD,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAEO,UAAU,CAAC,IAAoB;QACrC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QACxB,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,cAAc,CAAA;IACvC,CAAC;IAEO,YAAY,CAAC,IAAsB;QACzC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAC1B,OAAO,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,gBAAgB,CAAA;IAC3C,CAAC;IAEO,MAAM,CAAC,IAAgB;QAC7B,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAA;QAC9C,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,IAAI,kBAAkB,EAAE,CAAA;IACpE,CAAC;CAEF;AA/LD,4CA+LC"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { IKeyValueStore, ValueStoreType } from '@sphereon/ssi-sdk.kv-store-temp';
|
2
2
|
import { IAgentContext, IPluginMethodMap } from '@veramo/core';
|
3
|
+
import { IAnomalyDetection } from "@sphereon/ssi-sdk.anomaly-detection";
|
3
4
|
export interface IResourceResolver extends IPluginMethodMap {
|
4
5
|
resourceResolve(args: ResolveArgs, context: RequiredContext): Promise<Response>;
|
5
6
|
resourceClearAllResources(args: ClearAllResourcesArgs, context: RequiredContext): Promise<boolean>;
|
@@ -12,6 +13,7 @@ export type ResourceResolverOptions = {
|
|
12
13
|
defaultNamespace?: string;
|
13
14
|
resourceStores?: Map<string, IKeyValueStore<Resource>> | IKeyValueStore<Resource>;
|
14
15
|
ttl?: number;
|
16
|
+
detectLocation?: boolean;
|
15
17
|
};
|
16
18
|
export type ResolveArgs = {
|
17
19
|
input: RequestInfo | URL;
|
@@ -58,7 +60,12 @@ export type StoreArgs<T extends ValueStoreType> = {
|
|
58
60
|
stores: Map<string, IKeyValueStore<T>>;
|
59
61
|
storeId?: string;
|
60
62
|
};
|
63
|
+
export type Location = {
|
64
|
+
continent?: string;
|
65
|
+
country?: string;
|
66
|
+
};
|
61
67
|
export type Resource = {
|
68
|
+
location?: Location | null;
|
62
69
|
response: SerializedResponse;
|
63
70
|
resourceType: ResourceType;
|
64
71
|
insertedAt: number;
|
@@ -72,5 +79,5 @@ export type SerializedResponse = {
|
|
72
79
|
};
|
73
80
|
body: string;
|
74
81
|
};
|
75
|
-
export type RequiredContext = IAgentContext<
|
82
|
+
export type RequiredContext = IAgentContext<IAnomalyDetection>;
|
76
83
|
//# sourceMappingURL=IResourceResolver.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"IResourceResolver.d.ts","sourceRoot":"","sources":["../../src/types/IResourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"IResourceResolver.d.ts","sourceRoot":"","sources":["../../src/types/IResourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,iCAAiC,CAAA;AAC9E,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAC,iBAAiB,EAAC,MAAM,qCAAqC,CAAC;AAEtE,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC/E,yBAAyB,CAAC,IAAI,EAAE,qBAAqB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAClG,sBAAsB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACjE,wBAAwB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO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G,aAAa,CAAC,iBAAiB,CAAC,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sphereon/ssi-sdk.resource-resolver",
|
3
|
-
"version": "0.30.2-next.
|
3
|
+
"version": "0.30.2-next.363+7d10b978",
|
4
4
|
"source": "src/index.ts",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -14,14 +14,15 @@
|
|
14
14
|
"build:clean": "tsc --build --clean && tsc --build"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@sphereon/ssi-sdk.
|
17
|
+
"@sphereon/ssi-sdk.anomaly-detection": "0.30.2-next.363+7d10b978",
|
18
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.30.2-next.363+7d10b978",
|
18
19
|
"cross-fetch": "^3.1.8",
|
19
20
|
"debug": "^4.3.5",
|
20
21
|
"typeorm": "^0.3.20",
|
21
22
|
"uint8arrays": "^3.1.1"
|
22
23
|
},
|
23
24
|
"devDependencies": {
|
24
|
-
"@sphereon/ssi-sdk.agent-config": "0.30.2-next.
|
25
|
+
"@sphereon/ssi-sdk.agent-config": "0.30.2-next.363+7d10b978",
|
25
26
|
"@veramo/remote-client": "4.2.0",
|
26
27
|
"@veramo/remote-server": "4.2.0",
|
27
28
|
"nock": "^13.5.4",
|
@@ -48,5 +49,5 @@
|
|
48
49
|
"Resource Management",
|
49
50
|
"Caching"
|
50
51
|
],
|
51
|
-
"gitHead": "
|
52
|
+
"gitHead": "7d10b978eff3a14bceda6bf81498dfd3d70e8eed"
|
52
53
|
}
|
@@ -44,6 +44,7 @@ export class ResourceResolver implements IAgentPlugin {
|
|
44
44
|
private readonly defaultStoreId: string
|
45
45
|
private readonly defaultNamespace: string
|
46
46
|
private readonly defaultTtl: number
|
47
|
+
private readonly detectLocation: boolean
|
47
48
|
private readonly _resourceStores: Map<string, IKeyValueStore<Resource>>
|
48
49
|
|
49
50
|
constructor(options?: ResourceResolverOptions) {
|
@@ -51,12 +52,14 @@ export class ResourceResolver implements IAgentPlugin {
|
|
51
52
|
defaultStore,
|
52
53
|
defaultNamespace,
|
53
54
|
resourceStores,
|
54
|
-
ttl
|
55
|
+
ttl,
|
56
|
+
detectLocation
|
55
57
|
} = options ?? {}
|
56
58
|
|
57
59
|
this.defaultStoreId = defaultStore ?? '_default'
|
58
60
|
this.defaultNamespace = defaultNamespace ?? 'resources'
|
59
61
|
this.defaultTtl = ttl ?? 3600
|
62
|
+
this.detectLocation = detectLocation ?? false
|
60
63
|
|
61
64
|
if (resourceStores && resourceStores instanceof Map) {
|
62
65
|
this._resourceStores = resourceStores
|
@@ -101,10 +104,16 @@ export class ResourceResolver implements IAgentPlugin {
|
|
101
104
|
});
|
102
105
|
}
|
103
106
|
|
107
|
+
let location
|
108
|
+
if (this.detectLocation) {
|
109
|
+
location = await this.retrieveLocation(input, context)
|
110
|
+
}
|
111
|
+
|
104
112
|
const response = await fetch(input, init)
|
105
113
|
if (!resolveOpts?.skipPersistence && (response.status >= 200 && response.status < 300)) {
|
106
114
|
const serializedResponse = await serializeResponse(response);
|
107
|
-
const resource = {
|
115
|
+
const resource: Resource = {
|
116
|
+
location,
|
108
117
|
response: serializedResponse,
|
109
118
|
resourceType,
|
110
119
|
insertedAt: Date.now(),
|
@@ -127,6 +136,20 @@ export class ResourceResolver implements IAgentPlugin {
|
|
127
136
|
return response
|
128
137
|
}
|
129
138
|
|
139
|
+
private async retrieveLocation(input: RequestInfo | URL, context: RequiredContext) {
|
140
|
+
let url: URL
|
141
|
+
if (input instanceof Request && input.url !== undefined && input.url !== null) {
|
142
|
+
url = new URL(input.url)
|
143
|
+
} else if (input instanceof URL) {
|
144
|
+
url = input
|
145
|
+
} else {
|
146
|
+
throw Error(`input type is required to be RequestInfo | URL`)
|
147
|
+
}
|
148
|
+
return await context.agent.anomalyDetectionLookupLocation({
|
149
|
+
ipOrHostname: url.hostname
|
150
|
+
})
|
151
|
+
}
|
152
|
+
|
130
153
|
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
131
154
|
private async resourceClearAllResources(args: ClearAllResourcesArgs, context: RequiredContext): Promise<boolean> {
|
132
155
|
const { storeId } = args
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import {IKeyValueStore, ValueStoreType} from '@sphereon/ssi-sdk.kv-store-temp'
|
2
|
+
import {IAgentContext, IPluginMethodMap} from '@veramo/core'
|
3
|
+
import {IAnomalyDetection} from "@sphereon/ssi-sdk.anomaly-detection";
|
3
4
|
|
4
5
|
export interface IResourceResolver extends IPluginMethodMap {
|
5
6
|
resourceResolve(args: ResolveArgs, context: RequiredContext): Promise<Response>
|
@@ -14,6 +15,7 @@ export type ResourceResolverOptions = {
|
|
14
15
|
defaultNamespace?: string
|
15
16
|
resourceStores?: Map<string, IKeyValueStore<Resource>> | IKeyValueStore<Resource>
|
16
17
|
ttl?: number
|
18
|
+
detectLocation?: boolean
|
17
19
|
}
|
18
20
|
|
19
21
|
export type ResolveArgs = {
|
@@ -71,7 +73,13 @@ export type StoreArgs<T extends ValueStoreType> = {
|
|
71
73
|
storeId?: string
|
72
74
|
}
|
73
75
|
|
76
|
+
export type Location = {
|
77
|
+
continent?: string
|
78
|
+
country?: string
|
79
|
+
}
|
80
|
+
|
74
81
|
export type Resource = {
|
82
|
+
location?: Location | null
|
75
83
|
response: SerializedResponse
|
76
84
|
resourceType: ResourceType
|
77
85
|
insertedAt: number
|
@@ -85,4 +93,4 @@ export type SerializedResponse = {
|
|
85
93
|
body: string
|
86
94
|
}
|
87
95
|
|
88
|
-
export type RequiredContext = IAgentContext<
|
96
|
+
export type RequiredContext = IAgentContext<IAnomalyDetection>
|