@sphereon/ssi-sdk.resource-resolver 0.33.1-feature.vcdm2.tsup.31 → 0.33.1-next.2
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/agent/ResourceResolver.d.ts +33 -0
- package/dist/agent/ResourceResolver.d.ts.map +1 -0
- package/dist/agent/ResourceResolver.js +202 -0
- package/dist/agent/ResourceResolver.js.map +1 -0
- package/dist/index.d.ts +4 -117
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -315
- package/dist/index.js.map +1 -1
- package/dist/types/IResourceResolver.d.ts +83 -0
- package/dist/types/IResourceResolver.d.ts.map +1 -0
- package/dist/types/IResourceResolver.js +3 -0
- package/dist/types/IResourceResolver.js.map +1 -0
- package/dist/utils/ResourceResolverUtils.d.ts +6 -0
- package/dist/utils/ResourceResolverUtils.d.ts.map +1 -0
- package/dist/utils/ResourceResolverUtils.js +79 -0
- package/dist/utils/ResourceResolverUtils.js.map +1 -0
- package/package.json +12 -23
- package/src/utils/ResourceResolverUtils.ts +3 -7
- package/dist/index.cjs +0 -348
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -121
package/dist/index.js
CHANGED
|
@@ -1,318 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// plugin.schema.json
|
|
9
|
-
var require_plugin_schema = __commonJS({
|
|
10
|
-
"plugin.schema.json"(exports, module) {
|
|
11
|
-
module.exports = {
|
|
12
|
-
IResourceResolver: {
|
|
13
|
-
components: {
|
|
14
|
-
schemas: {
|
|
15
|
-
ResourceResolverOptions: {
|
|
16
|
-
type: "object",
|
|
17
|
-
properties: {}
|
|
18
|
-
},
|
|
19
|
-
ResolveArgs: {
|
|
20
|
-
type: "object",
|
|
21
|
-
properties: {}
|
|
22
|
-
},
|
|
23
|
-
ResolveOptions: {
|
|
24
|
-
type: "object",
|
|
25
|
-
properties: {}
|
|
26
|
-
},
|
|
27
|
-
ResourceType: {
|
|
28
|
-
type: "object",
|
|
29
|
-
properties: {}
|
|
30
|
-
},
|
|
31
|
-
ClearAllResourcesArgs: {
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: {}
|
|
34
|
-
},
|
|
35
|
-
PersistResourceArgs: {
|
|
36
|
-
type: "object",
|
|
37
|
-
properties: {}
|
|
38
|
-
},
|
|
39
|
-
GetResourceArgs: {
|
|
40
|
-
type: "object",
|
|
41
|
-
properties: {}
|
|
42
|
-
},
|
|
43
|
-
StoreIdStrArgs: {
|
|
44
|
-
type: "object",
|
|
45
|
-
properties: {}
|
|
46
|
-
},
|
|
47
|
-
NamespaceStrArgs: {
|
|
48
|
-
type: "object",
|
|
49
|
-
properties: {}
|
|
50
|
-
},
|
|
51
|
-
PrefixArgs: {
|
|
52
|
-
type: "object",
|
|
53
|
-
properties: {}
|
|
54
|
-
},
|
|
55
|
-
StoreArgs: {
|
|
56
|
-
type: "object",
|
|
57
|
-
properties: {}
|
|
58
|
-
},
|
|
59
|
-
Resource: {
|
|
60
|
-
type: "object",
|
|
61
|
-
properties: {}
|
|
62
|
-
},
|
|
63
|
-
SerializedResponse: {
|
|
64
|
-
type: "object",
|
|
65
|
-
properties: {}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
methods: {
|
|
69
|
-
resourceResolve: {
|
|
70
|
-
description: "",
|
|
71
|
-
arguments: {
|
|
72
|
-
$ref: "#/components/schemas/ResolveArgs"
|
|
73
|
-
},
|
|
74
|
-
returnType: {}
|
|
75
|
-
},
|
|
76
|
-
resourceClearAllResources: {
|
|
77
|
-
description: "",
|
|
78
|
-
arguments: {
|
|
79
|
-
$ref: "#/components/schemas/ClearAllResourcesArgs"
|
|
80
|
-
},
|
|
81
|
-
returnType: {}
|
|
82
|
-
},
|
|
83
|
-
resourceDefaultStoreId: {
|
|
84
|
-
description: "",
|
|
85
|
-
returnType: {}
|
|
86
|
-
},
|
|
87
|
-
resourceDefaultNamespace: {
|
|
88
|
-
description: "",
|
|
89
|
-
returnType: {}
|
|
90
|
-
},
|
|
91
|
-
resourceDefaultTtl: {
|
|
92
|
-
description: "",
|
|
93
|
-
returnType: {}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// src/agent/ResourceResolver.ts
|
|
103
|
-
import { KeyValueStore } from "@sphereon/ssi-sdk.kv-store-temp";
|
|
104
|
-
import fetch, { Response as Response2, Headers as Headers2 } from "cross-fetch";
|
|
105
|
-
|
|
106
|
-
// src/utils/ResourceResolverUtils.ts
|
|
107
|
-
import { Headers, Response, Request as Request2 } from "cross-fetch";
|
|
108
|
-
import { fromString } from "uint8arrays/from-string";
|
|
109
|
-
import { toString } from "uint8arrays/to-string";
|
|
110
|
-
var getResourceIdentifier = /* @__PURE__ */ __name((input) => {
|
|
111
|
-
if (typeof input === "string") {
|
|
112
|
-
return input;
|
|
113
|
-
} else if (input instanceof Request2) {
|
|
114
|
-
return input.url;
|
|
115
|
-
} else if (input instanceof URL) {
|
|
116
|
-
return input.toString();
|
|
117
|
-
}
|
|
118
|
-
throw new Error("Invalid input type. Expected Request, string, or URL.");
|
|
119
|
-
}, "getResourceIdentifier");
|
|
120
|
-
var serializeResponse = /* @__PURE__ */ __name(async (response) => {
|
|
121
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
122
|
-
const base64Url = toString(new Uint8Array(arrayBuffer), "base64url");
|
|
123
|
-
return {
|
|
124
|
-
status: response.status,
|
|
125
|
-
statusText: response.statusText,
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
128
|
-
body: base64Url
|
|
129
|
-
};
|
|
130
|
-
}, "serializeResponse");
|
|
131
|
-
var deserializeResponse = /* @__PURE__ */ __name(async (data) => {
|
|
132
|
-
const { status, statusText, headers, body } = data;
|
|
133
|
-
const uint8Array = fromString(body, "base64url");
|
|
134
|
-
const arrayBuffer = uint8Array.buffer.slice(uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength);
|
|
135
|
-
return new Response(arrayBuffer, {
|
|
136
|
-
status,
|
|
137
|
-
statusText,
|
|
138
|
-
headers: new Headers(headers)
|
|
139
|
-
});
|
|
140
|
-
}, "deserializeResponse");
|
|
141
|
-
var isCacheWithinMaxAge = /* @__PURE__ */ __name((cachedResource, resolveOpts) => {
|
|
142
|
-
return cachedResource && (resolveOpts?.maxAgeMs === void 0 || Date.now() - cachedResource.insertedAt < resolveOpts.maxAgeMs);
|
|
143
|
-
}, "isCacheWithinMaxAge");
|
|
144
|
-
|
|
145
|
-
// src/agent/ResourceResolver.ts
|
|
146
|
-
var ResourceResolver = class {
|
|
147
|
-
static {
|
|
148
|
-
__name(this, "ResourceResolver");
|
|
149
|
-
}
|
|
150
|
-
schema = schema.IResourceResolver;
|
|
151
|
-
methods = {
|
|
152
|
-
resourceResolve: this.resourceResolve.bind(this),
|
|
153
|
-
resourceClearAllResources: this.resourceClearAllResources.bind(this),
|
|
154
|
-
resourceDefaultStoreId: this.resourceDefaultStoreId.bind(this),
|
|
155
|
-
resourceDefaultNamespace: this.resourceDefaultNamespace.bind(this),
|
|
156
|
-
resourceDefaultTtl: this.resourceDefaultTtl.bind(this)
|
|
157
|
-
};
|
|
158
|
-
defaultStoreId;
|
|
159
|
-
defaultNamespace;
|
|
160
|
-
defaultTtl;
|
|
161
|
-
detectLocation;
|
|
162
|
-
_resourceStores;
|
|
163
|
-
constructor(options) {
|
|
164
|
-
const { defaultStore, defaultNamespace, resourceStores, ttl, detectLocation } = options ?? {};
|
|
165
|
-
this.defaultStoreId = defaultStore ?? "_default";
|
|
166
|
-
this.defaultNamespace = defaultNamespace ?? "resources";
|
|
167
|
-
this.defaultTtl = ttl ?? 3600;
|
|
168
|
-
this.detectLocation = detectLocation ?? false;
|
|
169
|
-
if (resourceStores && resourceStores instanceof Map) {
|
|
170
|
-
this._resourceStores = resourceStores;
|
|
171
|
-
} else if (resourceStores) {
|
|
172
|
-
this._resourceStores = (/* @__PURE__ */ new Map()).set(this.defaultStoreId, resourceStores);
|
|
173
|
-
} else {
|
|
174
|
-
this._resourceStores = (/* @__PURE__ */ new Map()).set(this.defaultStoreId, new KeyValueStore({
|
|
175
|
-
namespace: this.defaultNamespace,
|
|
176
|
-
store: /* @__PURE__ */ new Map(),
|
|
177
|
-
ttl: this.defaultTtl
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/** {@inheritDoc IResourceResolver.resourceResolve} */
|
|
182
|
-
async resourceResolve(args, context) {
|
|
183
|
-
const { input, init, resourceType, resolveOpts, partyCorrelationId, storeId, namespace } = args;
|
|
184
|
-
const resourceIdentifier = getResourceIdentifier(input);
|
|
185
|
-
const cachedResource = await this.getResource({
|
|
186
|
-
resourceIdentifier,
|
|
187
|
-
storeId,
|
|
188
|
-
namespace
|
|
189
|
-
});
|
|
190
|
-
if (cachedResource.value && isCacheWithinMaxAge(cachedResource.value, resolveOpts)) {
|
|
191
|
-
return deserializeResponse(cachedResource.value.response);
|
|
192
|
-
}
|
|
193
|
-
if (resolveOpts?.onlyCache) {
|
|
194
|
-
return new Response2(JSON.stringify({
|
|
195
|
-
error: "Resource not found"
|
|
196
|
-
}), {
|
|
197
|
-
status: 404,
|
|
198
|
-
statusText: "Not Found",
|
|
199
|
-
headers: new Headers2({
|
|
200
|
-
"Content-Type": "application/json"
|
|
201
|
-
})
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
let location;
|
|
205
|
-
if (this.detectLocation) {
|
|
206
|
-
location = await this.retrieveLocation(input, context);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (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]; } };
|
|
207
7
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
insertedAt: Date.now(),
|
|
216
|
-
partyCorrelationId
|
|
217
|
-
};
|
|
218
|
-
const cachedResource2 = await this.persistResource({
|
|
219
|
-
resource,
|
|
220
|
-
resourceIdentifier,
|
|
221
|
-
namespace,
|
|
222
|
-
storeId
|
|
223
|
-
});
|
|
224
|
-
if (!cachedResource2.value) {
|
|
225
|
-
return Promise.reject(Error("Resource not present in persistence result"));
|
|
226
|
-
}
|
|
227
|
-
return deserializeResponse(cachedResource2.value.response);
|
|
228
|
-
}
|
|
229
|
-
return response;
|
|
230
|
-
}
|
|
231
|
-
async retrieveLocation(input, context) {
|
|
232
|
-
let url;
|
|
233
|
-
if (input instanceof Request && input.url !== void 0 && input.url !== null) {
|
|
234
|
-
url = new URL(input.url);
|
|
235
|
-
} else if (input instanceof URL) {
|
|
236
|
-
url = input;
|
|
237
|
-
} else {
|
|
238
|
-
throw Error(`input type is required to be RequestInfo | URL`);
|
|
239
|
-
}
|
|
240
|
-
return await context.agent.anomalyDetectionLookupLocation({
|
|
241
|
-
ipOrHostname: url.hostname
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
|
245
|
-
async resourceClearAllResources(args, context) {
|
|
246
|
-
const { storeId } = args;
|
|
247
|
-
return await this.store({
|
|
248
|
-
stores: this._resourceStores,
|
|
249
|
-
storeId
|
|
250
|
-
}).clear().then(() => true);
|
|
251
|
-
}
|
|
252
|
-
/** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
|
|
253
|
-
async resourceDefaultStoreId(context) {
|
|
254
|
-
return this.defaultStoreId;
|
|
255
|
-
}
|
|
256
|
-
/** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
|
|
257
|
-
async resourceDefaultNamespace(context) {
|
|
258
|
-
return this.defaultNamespace;
|
|
259
|
-
}
|
|
260
|
-
/** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
|
|
261
|
-
async resourceDefaultTtl(context) {
|
|
262
|
-
return this.defaultTtl;
|
|
263
|
-
}
|
|
264
|
-
async getResource(args) {
|
|
265
|
-
const { resourceIdentifier, storeId, namespace } = args;
|
|
266
|
-
return this.store({
|
|
267
|
-
stores: this._resourceStores,
|
|
268
|
-
storeId
|
|
269
|
-
}).getAsValueData(this.prefix({
|
|
270
|
-
namespace,
|
|
271
|
-
resourceIdentifier
|
|
272
|
-
}));
|
|
273
|
-
}
|
|
274
|
-
async persistResource(args) {
|
|
275
|
-
const { resource, resourceIdentifier, ttl } = args;
|
|
276
|
-
const namespace = this.namespaceStr(args);
|
|
277
|
-
const storeId = this.storeIdStr(args);
|
|
278
|
-
return await this.store({
|
|
279
|
-
stores: this._resourceStores,
|
|
280
|
-
storeId
|
|
281
|
-
}).set(this.prefix({
|
|
282
|
-
namespace,
|
|
283
|
-
resourceIdentifier
|
|
284
|
-
}), resource, ttl ?? this.defaultTtl);
|
|
285
|
-
}
|
|
286
|
-
store(args) {
|
|
287
|
-
const storeId = this.storeIdStr({
|
|
288
|
-
storeId: args.storeId
|
|
289
|
-
});
|
|
290
|
-
const store = args.stores.get(storeId);
|
|
291
|
-
if (!store) {
|
|
292
|
-
throw Error(`Could not get resource store: ${storeId}`);
|
|
293
|
-
}
|
|
294
|
-
return store;
|
|
295
|
-
}
|
|
296
|
-
storeIdStr(args) {
|
|
297
|
-
const { storeId } = args;
|
|
298
|
-
return storeId ?? this.defaultStoreId;
|
|
299
|
-
}
|
|
300
|
-
namespaceStr(args) {
|
|
301
|
-
const { namespace } = args;
|
|
302
|
-
return namespace ?? this.defaultNamespace;
|
|
303
|
-
}
|
|
304
|
-
prefix(args) {
|
|
305
|
-
const { namespace, resourceIdentifier } = args;
|
|
306
|
-
return `${this.namespaceStr({
|
|
307
|
-
namespace
|
|
308
|
-
})}:${resourceIdentifier}`;
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// src/index.ts
|
|
313
|
-
var schema = require_plugin_schema();
|
|
314
|
-
export {
|
|
315
|
-
ResourceResolver,
|
|
316
|
-
schema
|
|
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);
|
|
317
15
|
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ResourceResolver = exports.schema = void 0;
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
const schema = require('../plugin.schema.json');
|
|
22
|
+
exports.schema = schema;
|
|
23
|
+
var ResourceResolver_1 = require("./agent/ResourceResolver");
|
|
24
|
+
Object.defineProperty(exports, "ResourceResolver", { enumerable: true, get: function () { return ResourceResolver_1.ResourceResolver; } });
|
|
25
|
+
__exportStar(require("./types/IResourceResolver"), exports);
|
|
318
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../plugin.schema.json","../src/agent/ResourceResolver.ts","../src/utils/ResourceResolverUtils.ts","../src/index.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","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","/**\n * @public\n */\nconst schema = require('../plugin.schema.json')\nexport { schema }\nexport { ResourceResolver } from './agent/ResourceResolver'\nexport * from './types/IResourceResolver'\n"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;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;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,cAAgB;AAAA,cACd,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,uBAAyB;AAAA,cACvB,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,qBAAuB;AAAA,cACrB,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,iBAAmB;AAAA,cACjB,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,gBAAkB;AAAA,cAChB,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,kBAAoB;AAAA,cAClB,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,YAAc;AAAA,cACZ,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA,WAAa;AAAA,cACX,MAAQ;AAAA,cACR,YAAc,CAAC;AAAA,YACjB;AAAA,YACA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,IAAKM;AAC9C,UAAMF,YAAY,KAAKsD,aAAapD,IAAAA;AACpC,UAAMO,UAAU,KAAK8C,WAAWrD,IAAAA;AAEhC,WAAO,MAAM,KAAKD,MAAM;MAAEgD,QAAQ,KAAK1D;MAAiBkB;IAAQ,CAAA,EAAGX,IACjE,KAAKuD,OAAO;MACVrD;MACAU;IACF,CAAA,GACAuB,UACArC,OAAO,KAAKP,UAAU;EAE1B;EAEQY,MAAgCC,MAAuC;AAC7E,UAAMO,UAAU,KAAK8C,WAAW;MAAE9C,SAASP,KAAKO;IAAQ,CAAA;AACxD,UAAMR,QAAQC,KAAK+C,OAAOO,IAAI/C,OAAAA;AAC9B,QAAI,CAACR,OAAO;AACV,YAAMuC,MAAM,iCAAiC/B,OAAAA,EAAS;IACxD;AACA,WAAOR;EACT;EAEQsD,WAAWrD,MAA8B;AAC/C,UAAM,EAAEO,QAAO,IAAKP;AACpB,WAAOO,WAAW,KAAKtB;EACzB;EAEQmE,aAAapD,MAAgC;AACnD,UAAM,EAAEF,UAAS,IAAKE;AACtB,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;;;AEpMA,IAAM+C,SAASC;","names":["KeyValueStore","fetch","Response","Headers","Headers","Response","Request","fromString","toString","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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AACtC,wBAAM;AACf,6DAA2D;AAAlD,oHAAA,gBAAgB,OAAA;AACzB,4DAAyC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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';
|
|
4
|
+
export interface IResourceResolver extends IPluginMethodMap {
|
|
5
|
+
resourceResolve(args: ResolveArgs, context: RequiredContext): Promise<Response>;
|
|
6
|
+
resourceClearAllResources(args: ClearAllResourcesArgs, context: RequiredContext): Promise<boolean>;
|
|
7
|
+
resourceDefaultStoreId(context: RequiredContext): Promise<string>;
|
|
8
|
+
resourceDefaultNamespace(context: RequiredContext): Promise<string>;
|
|
9
|
+
resourceDefaultTtl(context: RequiredContext): Promise<number>;
|
|
10
|
+
}
|
|
11
|
+
export type ResourceResolverOptions = {
|
|
12
|
+
defaultStore?: string;
|
|
13
|
+
defaultNamespace?: string;
|
|
14
|
+
resourceStores?: Map<string, IKeyValueStore<Resource>> | IKeyValueStore<Resource>;
|
|
15
|
+
ttl?: number;
|
|
16
|
+
detectLocation?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type ResolveArgs = {
|
|
19
|
+
input: RequestInfo | URL;
|
|
20
|
+
init?: RequestInit;
|
|
21
|
+
resourceType: ResourceType;
|
|
22
|
+
partyCorrelationId?: string;
|
|
23
|
+
storeId?: string;
|
|
24
|
+
namespace?: string;
|
|
25
|
+
resolveOpts?: ResolveOptions;
|
|
26
|
+
};
|
|
27
|
+
export type ResolveOptions = {
|
|
28
|
+
ttl?: number;
|
|
29
|
+
maxAgeMs?: number;
|
|
30
|
+
onlyCache?: boolean;
|
|
31
|
+
skipPersistence?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type ResourceType = 'credential_branding_image' | 'issuer_branding_image' | 'oid4vci_metadata' | string;
|
|
34
|
+
export type ClearAllResourcesArgs = {
|
|
35
|
+
storeId?: string;
|
|
36
|
+
};
|
|
37
|
+
export type PersistResourceArgs = {
|
|
38
|
+
resource: Resource;
|
|
39
|
+
resourceIdentifier: string;
|
|
40
|
+
ttl?: number;
|
|
41
|
+
storeId?: string;
|
|
42
|
+
namespace?: string;
|
|
43
|
+
};
|
|
44
|
+
export type GetResourceArgs = {
|
|
45
|
+
resourceIdentifier: string;
|
|
46
|
+
storeId?: string;
|
|
47
|
+
namespace?: string;
|
|
48
|
+
};
|
|
49
|
+
export type StoreIdStrArgs = {
|
|
50
|
+
storeId?: string;
|
|
51
|
+
};
|
|
52
|
+
export type NamespaceStrArgs = {
|
|
53
|
+
namespace?: string;
|
|
54
|
+
};
|
|
55
|
+
export type PrefixArgs = {
|
|
56
|
+
namespace?: string;
|
|
57
|
+
resourceIdentifier: string;
|
|
58
|
+
};
|
|
59
|
+
export type StoreArgs<T extends ValueStoreType> = {
|
|
60
|
+
stores: Map<string, IKeyValueStore<T>>;
|
|
61
|
+
storeId?: string;
|
|
62
|
+
};
|
|
63
|
+
export type Location = {
|
|
64
|
+
continent?: string;
|
|
65
|
+
country?: string;
|
|
66
|
+
};
|
|
67
|
+
export type Resource = {
|
|
68
|
+
location?: Location | null;
|
|
69
|
+
response: SerializedResponse;
|
|
70
|
+
resourceType: ResourceType;
|
|
71
|
+
insertedAt: number;
|
|
72
|
+
partyCorrelationId?: string;
|
|
73
|
+
};
|
|
74
|
+
export type SerializedResponse = {
|
|
75
|
+
status: number;
|
|
76
|
+
statusText: string;
|
|
77
|
+
headers: {
|
|
78
|
+
[x: string]: string;
|
|
79
|
+
};
|
|
80
|
+
body: string;
|
|
81
|
+
};
|
|
82
|
+
export type RequiredContext = IAgentContext<IAnomalyDetection>;
|
|
83
|
+
//# sourceMappingURL=IResourceResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IResourceResolver.d.ts","sourceRoot":"","sources":["../../src/types/IResourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AAEvE,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,CAAC,MAAM,CAAC,CAAA;IACnE,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC9D;AAED,MAAM,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types/IResourceResolver.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ResolveOptions, Resource, SerializedResponse } from '../types/IResourceResolver';
|
|
2
|
+
export declare const getResourceIdentifier: (input: Request | string | URL) => string;
|
|
3
|
+
export declare const serializeResponse: (response: Response) => Promise<SerializedResponse>;
|
|
4
|
+
export declare const deserializeResponse: (data: SerializedResponse) => Promise<Response>;
|
|
5
|
+
export declare const isCacheWithinMaxAge: (cachedResource: Resource, resolveOpts?: ResolveOptions) => boolean;
|
|
6
|
+
//# sourceMappingURL=ResourceResolverUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceResolverUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ResourceResolverUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEzF,eAAO,MAAM,qBAAqB,UAAW,OAAO,GAAG,MAAM,GAAG,GAAG,KAAG,MAUrE,CAAA;AAED,eAAO,MAAM,iBAAiB,aAAoB,QAAQ,KAAG,OAAO,CAAC,kBAAkB,CAWtF,CAAA;AAED,eAAO,MAAM,mBAAmB,SAAgB,kBAAkB,KAAG,OAAO,CAAC,QAAQ,CAWpF,CAAA;AAGD,eAAO,MAAM,mBAAmB,mBAAoB,QAAQ,gBAAgB,cAAc,KAAG,OAE5F,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.isCacheWithinMaxAge = exports.deserializeResponse = exports.serializeResponse = exports.getResourceIdentifier = void 0;
|
|
36
|
+
const cross_fetch_1 = require("cross-fetch");
|
|
37
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
38
|
+
const getResourceIdentifier = (input) => {
|
|
39
|
+
if (typeof input === 'string') {
|
|
40
|
+
return input;
|
|
41
|
+
}
|
|
42
|
+
else if (input instanceof cross_fetch_1.Request) {
|
|
43
|
+
return input.url;
|
|
44
|
+
}
|
|
45
|
+
else if (input instanceof URL) {
|
|
46
|
+
return input.toString();
|
|
47
|
+
}
|
|
48
|
+
throw new Error('Invalid input type. Expected Request, string, or URL.');
|
|
49
|
+
};
|
|
50
|
+
exports.getResourceIdentifier = getResourceIdentifier;
|
|
51
|
+
const serializeResponse = (response) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const arrayBuffer = yield response.arrayBuffer();
|
|
53
|
+
const base64Url = u8a.toString(new Uint8Array(arrayBuffer), 'base64url');
|
|
54
|
+
return {
|
|
55
|
+
status: response.status,
|
|
56
|
+
statusText: response.statusText,
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
59
|
+
body: base64Url,
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
exports.serializeResponse = serializeResponse;
|
|
63
|
+
const deserializeResponse = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const { status, statusText, headers, body } = data;
|
|
65
|
+
const uint8Array = u8a.fromString(body, 'base64url');
|
|
66
|
+
const arrayBuffer = uint8Array.buffer.slice(uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength);
|
|
67
|
+
return new cross_fetch_1.Response(arrayBuffer, {
|
|
68
|
+
status,
|
|
69
|
+
statusText,
|
|
70
|
+
headers: new cross_fetch_1.Headers(headers),
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
exports.deserializeResponse = deserializeResponse;
|
|
74
|
+
// Check if the cache is still within the acceptable age
|
|
75
|
+
const isCacheWithinMaxAge = (cachedResource, resolveOpts) => {
|
|
76
|
+
return cachedResource && ((resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.maxAgeMs) === undefined || Date.now() - cachedResource.insertedAt < resolveOpts.maxAgeMs);
|
|
77
|
+
};
|
|
78
|
+
exports.isCacheWithinMaxAge = isCacheWithinMaxAge;
|
|
79
|
+
//# sourceMappingURL=ResourceResolverUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceResolverUtils.js","sourceRoot":"","sources":["../../src/utils/ResourceResolverUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwD;AACxD,iDAAkC;AAG3B,MAAM,qBAAqB,GAAG,CAAC,KAA6B,EAAU,EAAE;IAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;SAAM,IAAI,KAAK,YAAY,qBAAO,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC,GAAG,CAAA;IAClB,CAAC;SAAM,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;AAC1E,CAAC,CAAA;AAVY,QAAA,qBAAqB,yBAUjC;AAEM,MAAM,iBAAiB,GAAG,CAAO,QAAkB,EAA+B,EAAE;IACzF,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAA;IAChD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,CAAA;IAExE,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,aAAa;QACb,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACvD,IAAI,EAAE,SAAS;KAChB,CAAA;AACH,CAAC,CAAA,CAAA;AAXY,QAAA,iBAAiB,qBAW7B;AAEM,MAAM,mBAAmB,GAAG,CAAO,IAAwB,EAAqB,EAAE;IACvF,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;IAElD,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;IACpD,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAEjH,OAAO,IAAI,sBAAQ,CAAC,WAAW,EAAE;QAC/B,MAAM;QACN,UAAU;QACV,OAAO,EAAE,IAAI,qBAAO,CAAC,OAAO,CAAC;KAC9B,CAAC,CAAA;AACJ,CAAC,CAAA,CAAA;AAXY,QAAA,mBAAmB,uBAW/B;AAED,wDAAwD;AACjD,MAAM,mBAAmB,GAAG,CAAC,cAAwB,EAAE,WAA4B,EAAW,EAAE;IACrG,OAAO,cAAc,IAAI,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,MAAK,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;AACjI,CAAC,CAAA;AAFY,QAAA,mBAAmB,uBAE/B"}
|
package/package.json
CHANGED
|
@@ -1,47 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.resource-resolver",
|
|
3
|
-
"version": "0.33.1-
|
|
3
|
+
"version": "0.33.1-next.2+6f7f40b9",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
"import": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
15
|
-
"types": "./dist/index.d.cts",
|
|
16
|
-
"require": "./dist/index.cjs"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
19
7
|
"veramo": {
|
|
20
8
|
"pluginInterfaces": {
|
|
21
9
|
"IResourceResolverManager": "./src/types/IResourceResolverManager.ts"
|
|
22
10
|
}
|
|
23
11
|
},
|
|
24
12
|
"scripts": {
|
|
25
|
-
"build": "
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"build:clean": "tsc --build --clean && tsc --build"
|
|
26
15
|
},
|
|
27
16
|
"dependencies": {
|
|
28
|
-
"@sphereon/ssi-sdk.anomaly-detection": "
|
|
29
|
-
"@sphereon/ssi-sdk.kv-store-temp": "
|
|
17
|
+
"@sphereon/ssi-sdk.anomaly-detection": "0.33.1-next.2+6f7f40b9",
|
|
18
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.33.1-next.2+6f7f40b9",
|
|
30
19
|
"cross-fetch": "^3.1.8",
|
|
31
20
|
"debug": "^4.3.5",
|
|
32
|
-
"typeorm": "^0.3.
|
|
21
|
+
"typeorm": "^0.3.21",
|
|
33
22
|
"uint8arrays": "^3.1.1"
|
|
34
23
|
},
|
|
35
24
|
"devDependencies": {
|
|
36
|
-
"@sphereon/ssi-sdk.agent-config": "
|
|
25
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-next.2+6f7f40b9",
|
|
37
26
|
"@veramo/remote-client": "4.2.0",
|
|
38
27
|
"@veramo/remote-server": "4.2.0",
|
|
39
28
|
"nock": "^13.5.4",
|
|
40
29
|
"timekeeper": "^2.3.1"
|
|
41
30
|
},
|
|
42
31
|
"files": [
|
|
43
|
-
"dist",
|
|
44
|
-
"src",
|
|
32
|
+
"dist/**/*",
|
|
33
|
+
"src/**/*",
|
|
45
34
|
"README.md",
|
|
46
35
|
"plugin.schema.json",
|
|
47
36
|
"LICENSE"
|
|
@@ -60,5 +49,5 @@
|
|
|
60
49
|
"Resource Management",
|
|
61
50
|
"Caching"
|
|
62
51
|
],
|
|
63
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "6f7f40b94beb385369fede046c3912bd0c053408"
|
|
64
53
|
}
|