@sphereon/ssi-sdk.resource-resolver 0.33.1-next.3 → 0.33.1-next.73
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/index.cjs +348 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +121 -0
- package/dist/index.d.ts +117 -4
- package/dist/index.js +315 -23
- package/dist/index.js.map +1 -1
- package/package.json +24 -12
- package/src/utils/ResourceResolverUtils.ts +7 -3
- package/dist/agent/ResourceResolver.d.ts +0 -33
- package/dist/agent/ResourceResolver.d.ts.map +0 -1
- package/dist/agent/ResourceResolver.js +0 -202
- package/dist/agent/ResourceResolver.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/IResourceResolver.d.ts +0 -83
- package/dist/types/IResourceResolver.d.ts.map +0 -1
- package/dist/types/IResourceResolver.js +0 -3
- package/dist/types/IResourceResolver.js.map +0 -1
- package/dist/utils/ResourceResolverUtils.d.ts +0 -6
- package/dist/utils/ResourceResolverUtils.d.ts.map +0 -1
- package/dist/utils/ResourceResolverUtils.js +0 -79
- package/dist/utils/ResourceResolverUtils.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// plugin.schema.json
|
|
35
|
+
var require_plugin_schema = __commonJS({
|
|
36
|
+
"plugin.schema.json"(exports, module2) {
|
|
37
|
+
module2.exports = {
|
|
38
|
+
IResourceResolver: {
|
|
39
|
+
components: {
|
|
40
|
+
schemas: {
|
|
41
|
+
ResourceResolverOptions: {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {}
|
|
44
|
+
},
|
|
45
|
+
ResolveArgs: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {}
|
|
48
|
+
},
|
|
49
|
+
ResolveOptions: {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {}
|
|
52
|
+
},
|
|
53
|
+
ResourceType: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {}
|
|
56
|
+
},
|
|
57
|
+
ClearAllResourcesArgs: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {}
|
|
60
|
+
},
|
|
61
|
+
PersistResourceArgs: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {}
|
|
64
|
+
},
|
|
65
|
+
GetResourceArgs: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {}
|
|
68
|
+
},
|
|
69
|
+
StoreIdStrArgs: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {}
|
|
72
|
+
},
|
|
73
|
+
NamespaceStrArgs: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {}
|
|
76
|
+
},
|
|
77
|
+
PrefixArgs: {
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {}
|
|
80
|
+
},
|
|
81
|
+
StoreArgs: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {}
|
|
84
|
+
},
|
|
85
|
+
Resource: {
|
|
86
|
+
type: "object",
|
|
87
|
+
properties: {}
|
|
88
|
+
},
|
|
89
|
+
SerializedResponse: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
methods: {
|
|
95
|
+
resourceResolve: {
|
|
96
|
+
description: "",
|
|
97
|
+
arguments: {
|
|
98
|
+
$ref: "#/components/schemas/ResolveArgs"
|
|
99
|
+
},
|
|
100
|
+
returnType: {}
|
|
101
|
+
},
|
|
102
|
+
resourceClearAllResources: {
|
|
103
|
+
description: "",
|
|
104
|
+
arguments: {
|
|
105
|
+
$ref: "#/components/schemas/ClearAllResourcesArgs"
|
|
106
|
+
},
|
|
107
|
+
returnType: {}
|
|
108
|
+
},
|
|
109
|
+
resourceDefaultStoreId: {
|
|
110
|
+
description: "",
|
|
111
|
+
returnType: {}
|
|
112
|
+
},
|
|
113
|
+
resourceDefaultNamespace: {
|
|
114
|
+
description: "",
|
|
115
|
+
returnType: {}
|
|
116
|
+
},
|
|
117
|
+
resourceDefaultTtl: {
|
|
118
|
+
description: "",
|
|
119
|
+
returnType: {}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/index.ts
|
|
129
|
+
var index_exports = {};
|
|
130
|
+
__export(index_exports, {
|
|
131
|
+
ResourceResolver: () => ResourceResolver,
|
|
132
|
+
schema: () => schema
|
|
133
|
+
});
|
|
134
|
+
module.exports = __toCommonJS(index_exports);
|
|
135
|
+
|
|
136
|
+
// src/agent/ResourceResolver.ts
|
|
137
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.kv-store-temp");
|
|
138
|
+
var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
139
|
+
|
|
140
|
+
// src/utils/ResourceResolverUtils.ts
|
|
141
|
+
var import_cross_fetch = require("cross-fetch");
|
|
142
|
+
var import_from_string = require("uint8arrays/from-string");
|
|
143
|
+
var import_to_string = require("uint8arrays/to-string");
|
|
144
|
+
var getResourceIdentifier = /* @__PURE__ */ __name((input) => {
|
|
145
|
+
if (typeof input === "string") {
|
|
146
|
+
return input;
|
|
147
|
+
} else if (input instanceof import_cross_fetch.Request) {
|
|
148
|
+
return input.url;
|
|
149
|
+
} else if (input instanceof URL) {
|
|
150
|
+
return input.toString();
|
|
151
|
+
}
|
|
152
|
+
throw new Error("Invalid input type. Expected Request, string, or URL.");
|
|
153
|
+
}, "getResourceIdentifier");
|
|
154
|
+
var serializeResponse = /* @__PURE__ */ __name(async (response) => {
|
|
155
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
156
|
+
const base64Url = (0, import_to_string.toString)(new Uint8Array(arrayBuffer), "base64url");
|
|
157
|
+
return {
|
|
158
|
+
status: response.status,
|
|
159
|
+
statusText: response.statusText,
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
162
|
+
body: base64Url
|
|
163
|
+
};
|
|
164
|
+
}, "serializeResponse");
|
|
165
|
+
var deserializeResponse = /* @__PURE__ */ __name(async (data) => {
|
|
166
|
+
const { status, statusText, headers, body } = data;
|
|
167
|
+
const uint8Array = (0, import_from_string.fromString)(body, "base64url");
|
|
168
|
+
const arrayBuffer = uint8Array.buffer.slice(uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength);
|
|
169
|
+
return new import_cross_fetch.Response(arrayBuffer, {
|
|
170
|
+
status,
|
|
171
|
+
statusText,
|
|
172
|
+
headers: new import_cross_fetch.Headers(headers)
|
|
173
|
+
});
|
|
174
|
+
}, "deserializeResponse");
|
|
175
|
+
var isCacheWithinMaxAge = /* @__PURE__ */ __name((cachedResource, resolveOpts) => {
|
|
176
|
+
return cachedResource && (resolveOpts?.maxAgeMs === void 0 || Date.now() - cachedResource.insertedAt < resolveOpts.maxAgeMs);
|
|
177
|
+
}, "isCacheWithinMaxAge");
|
|
178
|
+
|
|
179
|
+
// src/agent/ResourceResolver.ts
|
|
180
|
+
var ResourceResolver = class {
|
|
181
|
+
static {
|
|
182
|
+
__name(this, "ResourceResolver");
|
|
183
|
+
}
|
|
184
|
+
schema = schema.IResourceResolver;
|
|
185
|
+
methods = {
|
|
186
|
+
resourceResolve: this.resourceResolve.bind(this),
|
|
187
|
+
resourceClearAllResources: this.resourceClearAllResources.bind(this),
|
|
188
|
+
resourceDefaultStoreId: this.resourceDefaultStoreId.bind(this),
|
|
189
|
+
resourceDefaultNamespace: this.resourceDefaultNamespace.bind(this),
|
|
190
|
+
resourceDefaultTtl: this.resourceDefaultTtl.bind(this)
|
|
191
|
+
};
|
|
192
|
+
defaultStoreId;
|
|
193
|
+
defaultNamespace;
|
|
194
|
+
defaultTtl;
|
|
195
|
+
detectLocation;
|
|
196
|
+
_resourceStores;
|
|
197
|
+
constructor(options) {
|
|
198
|
+
const { defaultStore, defaultNamespace, resourceStores, ttl, detectLocation } = options ?? {};
|
|
199
|
+
this.defaultStoreId = defaultStore ?? "_default";
|
|
200
|
+
this.defaultNamespace = defaultNamespace ?? "resources";
|
|
201
|
+
this.defaultTtl = ttl ?? 3600;
|
|
202
|
+
this.detectLocation = detectLocation ?? false;
|
|
203
|
+
if (resourceStores && resourceStores instanceof Map) {
|
|
204
|
+
this._resourceStores = resourceStores;
|
|
205
|
+
} else if (resourceStores) {
|
|
206
|
+
this._resourceStores = (/* @__PURE__ */ new Map()).set(this.defaultStoreId, resourceStores);
|
|
207
|
+
} else {
|
|
208
|
+
this._resourceStores = (/* @__PURE__ */ new Map()).set(this.defaultStoreId, new import_ssi_sdk.KeyValueStore({
|
|
209
|
+
namespace: this.defaultNamespace,
|
|
210
|
+
store: /* @__PURE__ */ new Map(),
|
|
211
|
+
ttl: this.defaultTtl
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** {@inheritDoc IResourceResolver.resourceResolve} */
|
|
216
|
+
async resourceResolve(args, context) {
|
|
217
|
+
const { input, init, resourceType, resolveOpts, partyCorrelationId, storeId, namespace } = args;
|
|
218
|
+
const resourceIdentifier = getResourceIdentifier(input);
|
|
219
|
+
const cachedResource = await this.getResource({
|
|
220
|
+
resourceIdentifier,
|
|
221
|
+
storeId,
|
|
222
|
+
namespace
|
|
223
|
+
});
|
|
224
|
+
if (cachedResource.value && isCacheWithinMaxAge(cachedResource.value, resolveOpts)) {
|
|
225
|
+
return deserializeResponse(cachedResource.value.response);
|
|
226
|
+
}
|
|
227
|
+
if (resolveOpts?.onlyCache) {
|
|
228
|
+
return new import_cross_fetch2.Response(JSON.stringify({
|
|
229
|
+
error: "Resource not found"
|
|
230
|
+
}), {
|
|
231
|
+
status: 404,
|
|
232
|
+
statusText: "Not Found",
|
|
233
|
+
headers: new import_cross_fetch2.Headers({
|
|
234
|
+
"Content-Type": "application/json"
|
|
235
|
+
})
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
let location;
|
|
239
|
+
if (this.detectLocation) {
|
|
240
|
+
location = await this.retrieveLocation(input, context);
|
|
241
|
+
}
|
|
242
|
+
const response = await (0, import_cross_fetch2.default)(input, init);
|
|
243
|
+
if (!resolveOpts?.skipPersistence && response.status >= 200 && response.status < 300) {
|
|
244
|
+
const serializedResponse = await serializeResponse(response);
|
|
245
|
+
const resource = {
|
|
246
|
+
location,
|
|
247
|
+
response: serializedResponse,
|
|
248
|
+
resourceType,
|
|
249
|
+
insertedAt: Date.now(),
|
|
250
|
+
partyCorrelationId
|
|
251
|
+
};
|
|
252
|
+
const cachedResource2 = await this.persistResource({
|
|
253
|
+
resource,
|
|
254
|
+
resourceIdentifier,
|
|
255
|
+
namespace,
|
|
256
|
+
storeId
|
|
257
|
+
});
|
|
258
|
+
if (!cachedResource2.value) {
|
|
259
|
+
return Promise.reject(Error("Resource not present in persistence result"));
|
|
260
|
+
}
|
|
261
|
+
return deserializeResponse(cachedResource2.value.response);
|
|
262
|
+
}
|
|
263
|
+
return response;
|
|
264
|
+
}
|
|
265
|
+
async retrieveLocation(input, context) {
|
|
266
|
+
let url;
|
|
267
|
+
if (input instanceof Request && input.url !== void 0 && input.url !== null) {
|
|
268
|
+
url = new URL(input.url);
|
|
269
|
+
} else if (input instanceof URL) {
|
|
270
|
+
url = input;
|
|
271
|
+
} else {
|
|
272
|
+
throw Error(`input type is required to be RequestInfo | URL`);
|
|
273
|
+
}
|
|
274
|
+
return await context.agent.anomalyDetectionLookupLocation({
|
|
275
|
+
ipOrHostname: url.hostname
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
|
279
|
+
async resourceClearAllResources(args, context) {
|
|
280
|
+
const { storeId } = args;
|
|
281
|
+
return await this.store({
|
|
282
|
+
stores: this._resourceStores,
|
|
283
|
+
storeId
|
|
284
|
+
}).clear().then(() => true);
|
|
285
|
+
}
|
|
286
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
|
|
287
|
+
async resourceDefaultStoreId(context) {
|
|
288
|
+
return this.defaultStoreId;
|
|
289
|
+
}
|
|
290
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
|
|
291
|
+
async resourceDefaultNamespace(context) {
|
|
292
|
+
return this.defaultNamespace;
|
|
293
|
+
}
|
|
294
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
|
|
295
|
+
async resourceDefaultTtl(context) {
|
|
296
|
+
return this.defaultTtl;
|
|
297
|
+
}
|
|
298
|
+
async getResource(args) {
|
|
299
|
+
const { resourceIdentifier, storeId, namespace } = args;
|
|
300
|
+
return this.store({
|
|
301
|
+
stores: this._resourceStores,
|
|
302
|
+
storeId
|
|
303
|
+
}).getAsValueData(this.prefix({
|
|
304
|
+
namespace,
|
|
305
|
+
resourceIdentifier
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
async persistResource(args) {
|
|
309
|
+
const { resource, resourceIdentifier, ttl } = args;
|
|
310
|
+
const namespace = this.namespaceStr(args);
|
|
311
|
+
const storeId = this.storeIdStr(args);
|
|
312
|
+
return await this.store({
|
|
313
|
+
stores: this._resourceStores,
|
|
314
|
+
storeId
|
|
315
|
+
}).set(this.prefix({
|
|
316
|
+
namespace,
|
|
317
|
+
resourceIdentifier
|
|
318
|
+
}), resource, ttl ?? this.defaultTtl);
|
|
319
|
+
}
|
|
320
|
+
store(args) {
|
|
321
|
+
const storeId = this.storeIdStr({
|
|
322
|
+
storeId: args.storeId
|
|
323
|
+
});
|
|
324
|
+
const store = args.stores.get(storeId);
|
|
325
|
+
if (!store) {
|
|
326
|
+
throw Error(`Could not get resource store: ${storeId}`);
|
|
327
|
+
}
|
|
328
|
+
return store;
|
|
329
|
+
}
|
|
330
|
+
storeIdStr(args) {
|
|
331
|
+
const { storeId } = args;
|
|
332
|
+
return storeId ?? this.defaultStoreId;
|
|
333
|
+
}
|
|
334
|
+
namespaceStr(args) {
|
|
335
|
+
const { namespace } = args;
|
|
336
|
+
return namespace ?? this.defaultNamespace;
|
|
337
|
+
}
|
|
338
|
+
prefix(args) {
|
|
339
|
+
const { namespace, resourceIdentifier } = args;
|
|
340
|
+
return `${this.namespaceStr({
|
|
341
|
+
namespace
|
|
342
|
+
})}:${resourceIdentifier}`;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// src/index.ts
|
|
347
|
+
var schema = require_plugin_schema();
|
|
348
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../plugin.schema.json","../src/index.ts","../src/agent/ResourceResolver.ts","../src/utils/ResourceResolverUtils.ts"],"sourcesContent":["{\n \"IResourceResolver\": {\n \"components\": {\n \"schemas\": {\n \"ResourceResolverOptions\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"ResolveArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"ResolveOptions\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"ResourceType\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"ClearAllResourcesArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"PersistResourceArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"GetResourceArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"StoreIdStrArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"NamespaceStrArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"PrefixArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"StoreArgs\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"Resource\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"SerializedResponse\": {\n \"type\": \"object\",\n \"properties\": {}\n }\n },\n \"methods\": {\n \"resourceResolve\": {\n \"description\": \"\",\n \"arguments\": {\n \"$ref\": \"#/components/schemas/ResolveArgs\"\n },\n \"returnType\": {}\n },\n \"resourceClearAllResources\": {\n \"description\": \"\",\n \"arguments\": {\n \"$ref\": \"#/components/schemas/ClearAllResourcesArgs\"\n },\n \"returnType\": {}\n },\n \"resourceDefaultStoreId\": {\n \"description\": \"\",\n \"returnType\": {}\n },\n \"resourceDefaultNamespace\": {\n \"description\": \"\",\n \"returnType\": {}\n },\n \"resourceDefaultTtl\": {\n \"description\": \"\",\n \"returnType\": {}\n }\n }\n }\n }\n}\n","/**\n * @public\n */\nconst schema = require('../plugin.schema.json')\nexport { schema }\nexport { ResourceResolver } from './agent/ResourceResolver'\nexport * from './types/IResourceResolver'\n","import { IKeyValueStore, IValueData, KeyValueStore, ValueStoreType } from '@sphereon/ssi-sdk.kv-store-temp'\nimport { IAgentPlugin } from '@veramo/core'\nimport fetch, { Response, Headers } from 'cross-fetch'\nimport { schema } from '../index'\nimport { deserializeResponse, getResourceIdentifier, isCacheWithinMaxAge, serializeResponse } from '../utils/ResourceResolverUtils'\nimport {\n ClearAllResourcesArgs,\n ResolveArgs,\n GetResourceArgs,\n IResourceResolver,\n NamespaceStrArgs,\n PersistResourceArgs,\n PrefixArgs,\n RequiredContext,\n ResourceResolverOptions,\n StoreArgs,\n StoreIdStrArgs,\n Resource,\n} from '../types/IResourceResolver'\n\n/**\n * {@inheritDoc IResourceResolver}\n */\nexport class ResourceResolver implements IAgentPlugin {\n readonly schema = schema.IResourceResolver\n readonly methods: IResourceResolver = {\n resourceResolve: this.resourceResolve.bind(this),\n resourceClearAllResources: this.resourceClearAllResources.bind(this),\n resourceDefaultStoreId: this.resourceDefaultStoreId.bind(this),\n resourceDefaultNamespace: this.resourceDefaultNamespace.bind(this),\n resourceDefaultTtl: this.resourceDefaultTtl.bind(this),\n }\n\n private readonly defaultStoreId: string\n private readonly defaultNamespace: string\n private readonly defaultTtl: number\n private readonly detectLocation: boolean\n private readonly _resourceStores: Map<string, IKeyValueStore<Resource>>\n\n constructor(options?: ResourceResolverOptions) {\n const { defaultStore, defaultNamespace, resourceStores, ttl, detectLocation } = options ?? {}\n\n this.defaultStoreId = defaultStore ?? '_default'\n this.defaultNamespace = defaultNamespace ?? 'resources'\n this.defaultTtl = ttl ?? 3600\n this.detectLocation = detectLocation ?? false\n\n if (resourceStores && resourceStores instanceof Map) {\n this._resourceStores = resourceStores\n } else if (resourceStores) {\n this._resourceStores = new Map().set(this.defaultStoreId, resourceStores)\n } else {\n this._resourceStores = new Map().set(\n this.defaultStoreId,\n new KeyValueStore({\n namespace: this.defaultNamespace,\n store: new Map<string, Resource>(),\n ttl: this.defaultTtl,\n }),\n )\n }\n }\n\n /** {@inheritDoc IResourceResolver.resourceResolve} */\n private async resourceResolve(args: ResolveArgs, context: RequiredContext): Promise<Response> {\n const { input, init, resourceType, resolveOpts, partyCorrelationId, storeId, namespace } = args\n\n const resourceIdentifier = getResourceIdentifier(input)\n\n const cachedResource = await this.getResource({ resourceIdentifier, storeId, namespace })\n if (cachedResource.value && isCacheWithinMaxAge(cachedResource.value, resolveOpts)) {\n return deserializeResponse(cachedResource.value.response)\n }\n\n if (resolveOpts?.onlyCache) {\n return new Response(JSON.stringify({ error: 'Resource not found' }), {\n status: 404,\n statusText: 'Not Found',\n headers: new Headers({ 'Content-Type': 'application/json' }),\n })\n }\n\n let location\n if (this.detectLocation) {\n location = await this.retrieveLocation(input, context)\n }\n\n const response = await fetch(input, init)\n if (!resolveOpts?.skipPersistence && response.status >= 200 && response.status < 300) {\n const serializedResponse = await serializeResponse(response)\n const resource: Resource = {\n location,\n response: serializedResponse,\n resourceType,\n insertedAt: Date.now(),\n partyCorrelationId,\n }\n const cachedResource = await this.persistResource({\n resource,\n resourceIdentifier,\n namespace,\n storeId,\n })\n\n if (!cachedResource.value) {\n return Promise.reject(Error('Resource not present in persistence result'))\n }\n\n return deserializeResponse(cachedResource.value.response)\n }\n\n return response\n }\n\n private async retrieveLocation(input: RequestInfo | URL, context: RequiredContext) {\n let url: URL\n if (input instanceof Request && input.url !== undefined && input.url !== null) {\n url = new URL(input.url)\n } else if (input instanceof URL) {\n url = input\n } else {\n throw Error(`input type is required to be RequestInfo | URL`)\n }\n return await context.agent.anomalyDetectionLookupLocation({\n ipOrHostname: url.hostname,\n })\n }\n\n /** {@inheritDoc IResourceResolver.resourceClearAllResources} */\n private async resourceClearAllResources(args: ClearAllResourcesArgs, context: RequiredContext): Promise<boolean> {\n const { storeId } = args\n return await this.store({ stores: this._resourceStores, storeId })\n .clear()\n .then(() => true)\n }\n\n /** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */\n private async resourceDefaultStoreId(context: RequiredContext): Promise<string> {\n return this.defaultStoreId\n }\n\n /** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */\n private async resourceDefaultNamespace(context: RequiredContext): Promise<string> {\n return this.defaultNamespace\n }\n\n /** {@inheritDoc IResourceResolver.resourceDefaultTtl} */\n private async resourceDefaultTtl(context: RequiredContext): Promise<number> {\n return this.defaultTtl\n }\n\n private async getResource(args: GetResourceArgs): Promise<IValueData<Resource>> {\n const { resourceIdentifier, storeId, namespace } = args\n return this.store({ stores: this._resourceStores, storeId }).getAsValueData(\n this.prefix({\n namespace,\n resourceIdentifier,\n }),\n )\n }\n\n private async persistResource(args: PersistResourceArgs): Promise<IValueData<Resource>> {\n const { resource, resourceIdentifier, ttl } = args\n const namespace = this.namespaceStr(args)\n const storeId = this.storeIdStr(args)\n\n return await this.store({ stores: this._resourceStores, storeId }).set(\n this.prefix({\n namespace,\n resourceIdentifier,\n }),\n resource,\n ttl ?? this.defaultTtl,\n )\n }\n\n private store<T extends ValueStoreType>(args: StoreArgs<T>): IKeyValueStore<T> {\n const storeId = this.storeIdStr({ storeId: args.storeId })\n const store = args.stores.get(storeId)\n if (!store) {\n throw Error(`Could not get resource store: ${storeId}`)\n }\n return store\n }\n\n private storeIdStr(args: StoreIdStrArgs): string {\n const { storeId } = args\n return storeId ?? this.defaultStoreId\n }\n\n private namespaceStr(args: NamespaceStrArgs): string {\n const { namespace } = args\n return namespace ?? this.defaultNamespace\n }\n\n private prefix(args: PrefixArgs): string {\n const { namespace, resourceIdentifier } = args\n return `${this.namespaceStr({ namespace })}:${resourceIdentifier}`\n }\n}\n","import { Headers, Response, Request } from 'cross-fetch'\n\n// @ts-ignore\nimport { fromString } from 'uint8arrays/from-string'\n// @ts-ignore\nimport { toString } from 'uint8arrays/to-string'\nimport { ResolveOptions, Resource, SerializedResponse } from '../types/IResourceResolver'\n\nexport const getResourceIdentifier = (input: Request | string | URL): string => {\n if (typeof input === 'string') {\n return input\n } else if (input instanceof Request) {\n return input.url\n } else if (input instanceof URL) {\n return input.toString()\n }\n\n throw new Error('Invalid input type. Expected Request, string, or URL.')\n}\n\nexport const serializeResponse = async (response: Response): Promise<SerializedResponse> => {\n const arrayBuffer = await response.arrayBuffer()\n const base64Url = toString(new Uint8Array(arrayBuffer), 'base64url')\n\n return {\n status: response.status,\n statusText: response.statusText,\n // @ts-ignore\n headers: Object.fromEntries(response.headers.entries()),\n body: base64Url,\n }\n}\n\nexport const deserializeResponse = async (data: SerializedResponse): Promise<Response> => {\n const { status, statusText, headers, body } = data\n\n const uint8Array = fromString(body, 'base64url')\n const arrayBuffer = uint8Array.buffer.slice(uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength)\n\n return new Response(arrayBuffer, {\n status,\n statusText,\n headers: new Headers(headers),\n })\n}\n\n// Check if the cache is still within the acceptable age\nexport const isCacheWithinMaxAge = (cachedResource: Resource, resolveOpts?: ResolveOptions): boolean => {\n return cachedResource && (resolveOpts?.maxAgeMs === undefined || Date.now() - cachedResource.insertedAt < resolveOpts.maxAgeMs)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,gCAAAA,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,mBAAqB;AAAA,QACnB,YAAc;AAAA,UACZ,SAAW;AAAA,YACT,yBAA2B;AAAA,cACzB,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,aAAe;AAAA,cACb,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,gBAAkB;AAAA,cAChB,MAAQ;AAA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ACtB,WAAOF,aAAa,KAAKZ;EAC3B;EAEQiE,OAAOnD,MAA0B;AACvC,UAAM,EAAEF,WAAWU,mBAAkB,IAAKR;AAC1C,WAAO,GAAG,KAAKoD,aAAa;MAAEtD;IAAU,CAAA,CAAA,IAAMU,kBAAAA;EAChD;AACF;;;ADpMA,IAAM+C,SAASC;","names":["module","import_cross_fetch","getResourceIdentifier","input","Request","url","URL","toString","Error","serializeResponse","response","arrayBuffer","base64Url","Uint8Array","status","statusText","headers","Object","fromEntries","entries","body","deserializeResponse","data","uint8Array","fromString","buffer","slice","byteOffset","byteLength","Response","Headers","isCacheWithinMaxAge","cachedResource","resolveOpts","maxAgeMs","undefined","Date","now","insertedAt","ResourceResolver","schema","IResourceResolver","methods","resourceResolve","bind","resourceClearAllResources","resourceDefaultStoreId","resourceDefaultNamespace","resourceDefaultTtl","defaultStoreId","defaultNamespace","defaultTtl","detectLocation","_resourceStores","constructor","options","defaultStore","resourceStores","ttl","Map","set","KeyValueStore","namespace","store","args","context","input","init","resourceType","resolveOpts","partyCorrelationId","storeId","resourceIdentifier","getResourceIdentifier","cachedResource","getResource","value","isCacheWithinMaxAge","deserializeResponse","response","onlyCache","Response","JSON","stringify","error","status","statusText","headers","Headers","location","retrieveLocation","fetch","skipPersistence","serializedResponse","serializeResponse","resource","insertedAt","Date","now","persistResource","Promise","reject","Error","url","Request","undefined","URL","agent","anomalyDetectionLookupLocation","ipOrHostname","hostname","stores","clear","then","getAsValueData","prefix","namespaceStr","storeIdStr","get","schema","require"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { IPluginMethodMap, IAgentContext, IAgentPlugin } from '@veramo/core';
|
|
2
|
+
import { IKeyValueStore, ValueStoreType } from '@sphereon/ssi-sdk.kv-store-temp';
|
|
3
|
+
import { IAnomalyDetection } from '@sphereon/ssi-sdk.anomaly-detection';
|
|
4
|
+
|
|
5
|
+
interface IResourceResolver extends IPluginMethodMap {
|
|
6
|
+
resourceResolve(args: ResolveArgs, context: RequiredContext): Promise<Response>;
|
|
7
|
+
resourceClearAllResources(args: ClearAllResourcesArgs, context: RequiredContext): Promise<boolean>;
|
|
8
|
+
resourceDefaultStoreId(context: RequiredContext): Promise<string>;
|
|
9
|
+
resourceDefaultNamespace(context: RequiredContext): Promise<string>;
|
|
10
|
+
resourceDefaultTtl(context: RequiredContext): Promise<number>;
|
|
11
|
+
}
|
|
12
|
+
type ResourceResolverOptions = {
|
|
13
|
+
defaultStore?: string;
|
|
14
|
+
defaultNamespace?: string;
|
|
15
|
+
resourceStores?: Map<string, IKeyValueStore<Resource>> | IKeyValueStore<Resource>;
|
|
16
|
+
ttl?: number;
|
|
17
|
+
detectLocation?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type ResolveArgs = {
|
|
20
|
+
input: RequestInfo | URL;
|
|
21
|
+
init?: RequestInit;
|
|
22
|
+
resourceType: ResourceType;
|
|
23
|
+
partyCorrelationId?: string;
|
|
24
|
+
storeId?: string;
|
|
25
|
+
namespace?: string;
|
|
26
|
+
resolveOpts?: ResolveOptions;
|
|
27
|
+
};
|
|
28
|
+
type ResolveOptions = {
|
|
29
|
+
ttl?: number;
|
|
30
|
+
maxAgeMs?: number;
|
|
31
|
+
onlyCache?: boolean;
|
|
32
|
+
skipPersistence?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type ResourceType = 'credential_branding_image' | 'issuer_branding_image' | 'oid4vci_metadata' | string;
|
|
35
|
+
type ClearAllResourcesArgs = {
|
|
36
|
+
storeId?: string;
|
|
37
|
+
};
|
|
38
|
+
type PersistResourceArgs = {
|
|
39
|
+
resource: Resource;
|
|
40
|
+
resourceIdentifier: string;
|
|
41
|
+
ttl?: number;
|
|
42
|
+
storeId?: string;
|
|
43
|
+
namespace?: string;
|
|
44
|
+
};
|
|
45
|
+
type GetResourceArgs = {
|
|
46
|
+
resourceIdentifier: string;
|
|
47
|
+
storeId?: string;
|
|
48
|
+
namespace?: string;
|
|
49
|
+
};
|
|
50
|
+
type StoreIdStrArgs = {
|
|
51
|
+
storeId?: string;
|
|
52
|
+
};
|
|
53
|
+
type NamespaceStrArgs = {
|
|
54
|
+
namespace?: string;
|
|
55
|
+
};
|
|
56
|
+
type PrefixArgs = {
|
|
57
|
+
namespace?: string;
|
|
58
|
+
resourceIdentifier: string;
|
|
59
|
+
};
|
|
60
|
+
type StoreArgs<T extends ValueStoreType> = {
|
|
61
|
+
stores: Map<string, IKeyValueStore<T>>;
|
|
62
|
+
storeId?: string;
|
|
63
|
+
};
|
|
64
|
+
type Location = {
|
|
65
|
+
continent?: string;
|
|
66
|
+
country?: string;
|
|
67
|
+
};
|
|
68
|
+
type Resource = {
|
|
69
|
+
location?: Location | null;
|
|
70
|
+
response: SerializedResponse;
|
|
71
|
+
resourceType: ResourceType;
|
|
72
|
+
insertedAt: number;
|
|
73
|
+
partyCorrelationId?: string;
|
|
74
|
+
};
|
|
75
|
+
type SerializedResponse = {
|
|
76
|
+
status: number;
|
|
77
|
+
statusText: string;
|
|
78
|
+
headers: {
|
|
79
|
+
[x: string]: string;
|
|
80
|
+
};
|
|
81
|
+
body: string;
|
|
82
|
+
};
|
|
83
|
+
type RequiredContext = IAgentContext<IAnomalyDetection>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* {@inheritDoc IResourceResolver}
|
|
87
|
+
*/
|
|
88
|
+
declare class ResourceResolver implements IAgentPlugin {
|
|
89
|
+
readonly schema: any;
|
|
90
|
+
readonly methods: IResourceResolver;
|
|
91
|
+
private readonly defaultStoreId;
|
|
92
|
+
private readonly defaultNamespace;
|
|
93
|
+
private readonly defaultTtl;
|
|
94
|
+
private readonly detectLocation;
|
|
95
|
+
private readonly _resourceStores;
|
|
96
|
+
constructor(options?: ResourceResolverOptions);
|
|
97
|
+
/** {@inheritDoc IResourceResolver.resourceResolve} */
|
|
98
|
+
private resourceResolve;
|
|
99
|
+
private retrieveLocation;
|
|
100
|
+
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
|
101
|
+
private resourceClearAllResources;
|
|
102
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
|
|
103
|
+
private resourceDefaultStoreId;
|
|
104
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
|
|
105
|
+
private resourceDefaultNamespace;
|
|
106
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
|
|
107
|
+
private resourceDefaultTtl;
|
|
108
|
+
private getResource;
|
|
109
|
+
private persistResource;
|
|
110
|
+
private store;
|
|
111
|
+
private storeIdStr;
|
|
112
|
+
private namespaceStr;
|
|
113
|
+
private prefix;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
declare const schema: any;
|
|
120
|
+
|
|
121
|
+
export { type ClearAllResourcesArgs, type GetResourceArgs, type IResourceResolver, type Location, type NamespaceStrArgs, type PersistResourceArgs, type PrefixArgs, type RequiredContext, type ResolveArgs, type ResolveOptions, type Resource, ResourceResolver, type ResourceResolverOptions, type ResourceType, type SerializedResponse, type StoreArgs, type StoreIdStrArgs, schema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,121 @@
|
|
|
1
|
+
import { IPluginMethodMap, IAgentContext, IAgentPlugin } from '@veramo/core';
|
|
2
|
+
import { IKeyValueStore, ValueStoreType } from '@sphereon/ssi-sdk.kv-store-temp';
|
|
3
|
+
import { IAnomalyDetection } from '@sphereon/ssi-sdk.anomaly-detection';
|
|
4
|
+
|
|
5
|
+
interface IResourceResolver extends IPluginMethodMap {
|
|
6
|
+
resourceResolve(args: ResolveArgs, context: RequiredContext): Promise<Response>;
|
|
7
|
+
resourceClearAllResources(args: ClearAllResourcesArgs, context: RequiredContext): Promise<boolean>;
|
|
8
|
+
resourceDefaultStoreId(context: RequiredContext): Promise<string>;
|
|
9
|
+
resourceDefaultNamespace(context: RequiredContext): Promise<string>;
|
|
10
|
+
resourceDefaultTtl(context: RequiredContext): Promise<number>;
|
|
11
|
+
}
|
|
12
|
+
type ResourceResolverOptions = {
|
|
13
|
+
defaultStore?: string;
|
|
14
|
+
defaultNamespace?: string;
|
|
15
|
+
resourceStores?: Map<string, IKeyValueStore<Resource>> | IKeyValueStore<Resource>;
|
|
16
|
+
ttl?: number;
|
|
17
|
+
detectLocation?: boolean;
|
|
18
|
+
};
|
|
19
|
+
type ResolveArgs = {
|
|
20
|
+
input: RequestInfo | URL;
|
|
21
|
+
init?: RequestInit;
|
|
22
|
+
resourceType: ResourceType;
|
|
23
|
+
partyCorrelationId?: string;
|
|
24
|
+
storeId?: string;
|
|
25
|
+
namespace?: string;
|
|
26
|
+
resolveOpts?: ResolveOptions;
|
|
27
|
+
};
|
|
28
|
+
type ResolveOptions = {
|
|
29
|
+
ttl?: number;
|
|
30
|
+
maxAgeMs?: number;
|
|
31
|
+
onlyCache?: boolean;
|
|
32
|
+
skipPersistence?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type ResourceType = 'credential_branding_image' | 'issuer_branding_image' | 'oid4vci_metadata' | string;
|
|
35
|
+
type ClearAllResourcesArgs = {
|
|
36
|
+
storeId?: string;
|
|
37
|
+
};
|
|
38
|
+
type PersistResourceArgs = {
|
|
39
|
+
resource: Resource;
|
|
40
|
+
resourceIdentifier: string;
|
|
41
|
+
ttl?: number;
|
|
42
|
+
storeId?: string;
|
|
43
|
+
namespace?: string;
|
|
44
|
+
};
|
|
45
|
+
type GetResourceArgs = {
|
|
46
|
+
resourceIdentifier: string;
|
|
47
|
+
storeId?: string;
|
|
48
|
+
namespace?: string;
|
|
49
|
+
};
|
|
50
|
+
type StoreIdStrArgs = {
|
|
51
|
+
storeId?: string;
|
|
52
|
+
};
|
|
53
|
+
type NamespaceStrArgs = {
|
|
54
|
+
namespace?: string;
|
|
55
|
+
};
|
|
56
|
+
type PrefixArgs = {
|
|
57
|
+
namespace?: string;
|
|
58
|
+
resourceIdentifier: string;
|
|
59
|
+
};
|
|
60
|
+
type StoreArgs<T extends ValueStoreType> = {
|
|
61
|
+
stores: Map<string, IKeyValueStore<T>>;
|
|
62
|
+
storeId?: string;
|
|
63
|
+
};
|
|
64
|
+
type Location = {
|
|
65
|
+
continent?: string;
|
|
66
|
+
country?: string;
|
|
67
|
+
};
|
|
68
|
+
type Resource = {
|
|
69
|
+
location?: Location | null;
|
|
70
|
+
response: SerializedResponse;
|
|
71
|
+
resourceType: ResourceType;
|
|
72
|
+
insertedAt: number;
|
|
73
|
+
partyCorrelationId?: string;
|
|
74
|
+
};
|
|
75
|
+
type SerializedResponse = {
|
|
76
|
+
status: number;
|
|
77
|
+
statusText: string;
|
|
78
|
+
headers: {
|
|
79
|
+
[x: string]: string;
|
|
80
|
+
};
|
|
81
|
+
body: string;
|
|
82
|
+
};
|
|
83
|
+
type RequiredContext = IAgentContext<IAnomalyDetection>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* {@inheritDoc IResourceResolver}
|
|
87
|
+
*/
|
|
88
|
+
declare class ResourceResolver implements IAgentPlugin {
|
|
89
|
+
readonly schema: any;
|
|
90
|
+
readonly methods: IResourceResolver;
|
|
91
|
+
private readonly defaultStoreId;
|
|
92
|
+
private readonly defaultNamespace;
|
|
93
|
+
private readonly defaultTtl;
|
|
94
|
+
private readonly detectLocation;
|
|
95
|
+
private readonly _resourceStores;
|
|
96
|
+
constructor(options?: ResourceResolverOptions);
|
|
97
|
+
/** {@inheritDoc IResourceResolver.resourceResolve} */
|
|
98
|
+
private resourceResolve;
|
|
99
|
+
private retrieveLocation;
|
|
100
|
+
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
|
101
|
+
private resourceClearAllResources;
|
|
102
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
|
|
103
|
+
private resourceDefaultStoreId;
|
|
104
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
|
|
105
|
+
private resourceDefaultNamespace;
|
|
106
|
+
/** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
|
|
107
|
+
private resourceDefaultTtl;
|
|
108
|
+
private getResource;
|
|
109
|
+
private persistResource;
|
|
110
|
+
private store;
|
|
111
|
+
private storeIdStr;
|
|
112
|
+
private namespaceStr;
|
|
113
|
+
private prefix;
|
|
114
|
+
}
|
|
115
|
+
|
|
1
116
|
/**
|
|
2
117
|
* @public
|
|
3
118
|
*/
|
|
4
119
|
declare const schema: any;
|
|
5
|
-
|
|
6
|
-
export { ResourceResolver
|
|
7
|
-
export * from './types/IResourceResolver';
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
120
|
+
|
|
121
|
+
export { type ClearAllResourcesArgs, type GetResourceArgs, type IResourceResolver, type Location, type NamespaceStrArgs, type PersistResourceArgs, type PrefixArgs, type RequiredContext, type ResolveArgs, type ResolveOptions, type Resource, ResourceResolver, type ResourceResolverOptions, type ResourceType, type SerializedResponse, type StoreArgs, type StoreIdStrArgs, schema };
|