@sphereon/ssi-sdk.resource-resolver 0.33.0 → 0.33.1-feature.vcdm2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/ResourceResolver.js +103 -150
- package/dist/agent/ResourceResolver.js.map +1 -1
- package/dist/index.js +3 -21
- package/dist/index.js.map +1 -1
- package/dist/types/IResourceResolver.js +1 -2
- package/dist/utils/ResourceResolverUtils.js +13 -52
- package/dist/utils/ResourceResolverUtils.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,60 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.ResourceResolver = void 0;
|
|
36
|
-
const ssi_sdk_kv_store_temp_1 = require("@sphereon/ssi-sdk.kv-store-temp");
|
|
37
|
-
const cross_fetch_1 = __importStar(require("cross-fetch"));
|
|
38
|
-
const index_1 = require("../index");
|
|
39
|
-
const ResourceResolverUtils_1 = require("../utils/ResourceResolverUtils");
|
|
1
|
+
import { KeyValueStore } from '@sphereon/ssi-sdk.kv-store-temp';
|
|
2
|
+
import fetch, { Response, Headers } from 'cross-fetch';
|
|
3
|
+
import { schema } from '../index';
|
|
4
|
+
import { deserializeResponse, getResourceIdentifier, isCacheWithinMaxAge, serializeResponse } from '../utils/ResourceResolverUtils';
|
|
40
5
|
/**
|
|
41
6
|
* {@inheritDoc IResourceResolver}
|
|
42
7
|
*/
|
|
43
|
-
class ResourceResolver {
|
|
8
|
+
export class ResourceResolver {
|
|
9
|
+
schema = schema.IResourceResolver;
|
|
10
|
+
methods = {
|
|
11
|
+
resourceResolve: this.resourceResolve.bind(this),
|
|
12
|
+
resourceClearAllResources: this.resourceClearAllResources.bind(this),
|
|
13
|
+
resourceDefaultStoreId: this.resourceDefaultStoreId.bind(this),
|
|
14
|
+
resourceDefaultNamespace: this.resourceDefaultNamespace.bind(this),
|
|
15
|
+
resourceDefaultTtl: this.resourceDefaultTtl.bind(this),
|
|
16
|
+
};
|
|
17
|
+
defaultStoreId;
|
|
18
|
+
defaultNamespace;
|
|
19
|
+
defaultTtl;
|
|
20
|
+
detectLocation;
|
|
21
|
+
_resourceStores;
|
|
44
22
|
constructor(options) {
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
resourceDefaultNamespace: this.resourceDefaultNamespace.bind(this),
|
|
51
|
-
resourceDefaultTtl: this.resourceDefaultTtl.bind(this),
|
|
52
|
-
};
|
|
53
|
-
const { defaultStore, defaultNamespace, resourceStores, ttl, detectLocation } = options !== null && options !== void 0 ? options : {};
|
|
54
|
-
this.defaultStoreId = defaultStore !== null && defaultStore !== void 0 ? defaultStore : '_default';
|
|
55
|
-
this.defaultNamespace = defaultNamespace !== null && defaultNamespace !== void 0 ? defaultNamespace : 'resources';
|
|
56
|
-
this.defaultTtl = ttl !== null && ttl !== void 0 ? ttl : 3600;
|
|
57
|
-
this.detectLocation = detectLocation !== null && detectLocation !== void 0 ? detectLocation : false;
|
|
23
|
+
const { defaultStore, defaultNamespace, resourceStores, ttl, detectLocation } = options ?? {};
|
|
24
|
+
this.defaultStoreId = defaultStore ?? '_default';
|
|
25
|
+
this.defaultNamespace = defaultNamespace ?? 'resources';
|
|
26
|
+
this.defaultTtl = ttl ?? 3600;
|
|
27
|
+
this.detectLocation = detectLocation ?? false;
|
|
58
28
|
if (resourceStores && resourceStores instanceof Map) {
|
|
59
29
|
this._resourceStores = resourceStores;
|
|
60
30
|
}
|
|
@@ -62,7 +32,7 @@ class ResourceResolver {
|
|
|
62
32
|
this._resourceStores = new Map().set(this.defaultStoreId, resourceStores);
|
|
63
33
|
}
|
|
64
34
|
else {
|
|
65
|
-
this._resourceStores = new Map().set(this.defaultStoreId, new
|
|
35
|
+
this._resourceStores = new Map().set(this.defaultStoreId, new KeyValueStore({
|
|
66
36
|
namespace: this.defaultNamespace,
|
|
67
37
|
store: new Map(),
|
|
68
38
|
ttl: this.defaultTtl,
|
|
@@ -70,112 +40,96 @@ class ResourceResolver {
|
|
|
70
40
|
}
|
|
71
41
|
}
|
|
72
42
|
/** {@inheritDoc IResourceResolver.resourceResolve} */
|
|
73
|
-
resourceResolve(args, context) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return Promise.reject(Error('Resource not present in persistence result'));
|
|
110
|
-
}
|
|
111
|
-
return (0, ResourceResolverUtils_1.deserializeResponse)(cachedResource.value.response);
|
|
43
|
+
async resourceResolve(args, context) {
|
|
44
|
+
const { input, init, resourceType, resolveOpts, partyCorrelationId, storeId, namespace } = args;
|
|
45
|
+
const resourceIdentifier = getResourceIdentifier(input);
|
|
46
|
+
const cachedResource = await this.getResource({ resourceIdentifier, storeId, namespace });
|
|
47
|
+
if (cachedResource.value && isCacheWithinMaxAge(cachedResource.value, resolveOpts)) {
|
|
48
|
+
return deserializeResponse(cachedResource.value.response);
|
|
49
|
+
}
|
|
50
|
+
if (resolveOpts?.onlyCache) {
|
|
51
|
+
return new Response(JSON.stringify({ error: 'Resource not found' }), {
|
|
52
|
+
status: 404,
|
|
53
|
+
statusText: 'Not Found',
|
|
54
|
+
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
let location;
|
|
58
|
+
if (this.detectLocation) {
|
|
59
|
+
location = await this.retrieveLocation(input, context);
|
|
60
|
+
}
|
|
61
|
+
const response = await fetch(input, init);
|
|
62
|
+
if (!resolveOpts?.skipPersistence && response.status >= 200 && response.status < 300) {
|
|
63
|
+
const serializedResponse = await serializeResponse(response);
|
|
64
|
+
const resource = {
|
|
65
|
+
location,
|
|
66
|
+
response: serializedResponse,
|
|
67
|
+
resourceType,
|
|
68
|
+
insertedAt: Date.now(),
|
|
69
|
+
partyCorrelationId,
|
|
70
|
+
};
|
|
71
|
+
const cachedResource = await this.persistResource({
|
|
72
|
+
resource,
|
|
73
|
+
resourceIdentifier,
|
|
74
|
+
namespace,
|
|
75
|
+
storeId,
|
|
76
|
+
});
|
|
77
|
+
if (!cachedResource.value) {
|
|
78
|
+
return Promise.reject(Error('Resource not present in persistence result'));
|
|
112
79
|
}
|
|
113
|
-
return response;
|
|
114
|
-
}
|
|
80
|
+
return deserializeResponse(cachedResource.value.response);
|
|
81
|
+
}
|
|
82
|
+
return response;
|
|
115
83
|
}
|
|
116
|
-
retrieveLocation(input, context) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
ipOrHostname: url.hostname,
|
|
130
|
-
});
|
|
84
|
+
async retrieveLocation(input, context) {
|
|
85
|
+
let url;
|
|
86
|
+
if (input instanceof Request && input.url !== undefined && input.url !== null) {
|
|
87
|
+
url = new URL(input.url);
|
|
88
|
+
}
|
|
89
|
+
else if (input instanceof URL) {
|
|
90
|
+
url = input;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw Error(`input type is required to be RequestInfo | URL`);
|
|
94
|
+
}
|
|
95
|
+
return await context.agent.anomalyDetectionLookupLocation({
|
|
96
|
+
ipOrHostname: url.hostname,
|
|
131
97
|
});
|
|
132
98
|
}
|
|
133
99
|
/** {@inheritDoc IResourceResolver.resourceClearAllResources} */
|
|
134
|
-
resourceClearAllResources(args, context) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.then(() => true);
|
|
140
|
-
});
|
|
100
|
+
async resourceClearAllResources(args, context) {
|
|
101
|
+
const { storeId } = args;
|
|
102
|
+
return await this.store({ stores: this._resourceStores, storeId })
|
|
103
|
+
.clear()
|
|
104
|
+
.then(() => true);
|
|
141
105
|
}
|
|
142
106
|
/** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
|
|
143
|
-
resourceDefaultStoreId(context) {
|
|
144
|
-
return
|
|
145
|
-
return this.defaultStoreId;
|
|
146
|
-
});
|
|
107
|
+
async resourceDefaultStoreId(context) {
|
|
108
|
+
return this.defaultStoreId;
|
|
147
109
|
}
|
|
148
110
|
/** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
|
|
149
|
-
resourceDefaultNamespace(context) {
|
|
150
|
-
return
|
|
151
|
-
return this.defaultNamespace;
|
|
152
|
-
});
|
|
111
|
+
async resourceDefaultNamespace(context) {
|
|
112
|
+
return this.defaultNamespace;
|
|
153
113
|
}
|
|
154
114
|
/** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
|
|
155
|
-
resourceDefaultTtl(context) {
|
|
156
|
-
return
|
|
157
|
-
return this.defaultTtl;
|
|
158
|
-
});
|
|
115
|
+
async resourceDefaultTtl(context) {
|
|
116
|
+
return this.defaultTtl;
|
|
159
117
|
}
|
|
160
|
-
getResource(args) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}));
|
|
167
|
-
});
|
|
118
|
+
async getResource(args) {
|
|
119
|
+
const { resourceIdentifier, storeId, namespace } = args;
|
|
120
|
+
return this.store({ stores: this._resourceStores, storeId }).getAsValueData(this.prefix({
|
|
121
|
+
namespace,
|
|
122
|
+
resourceIdentifier,
|
|
123
|
+
}));
|
|
168
124
|
}
|
|
169
|
-
persistResource(args) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}), resource, ttl !== null && ttl !== void 0 ? ttl : this.defaultTtl);
|
|
178
|
-
});
|
|
125
|
+
async persistResource(args) {
|
|
126
|
+
const { resource, resourceIdentifier, ttl } = args;
|
|
127
|
+
const namespace = this.namespaceStr(args);
|
|
128
|
+
const storeId = this.storeIdStr(args);
|
|
129
|
+
return await this.store({ stores: this._resourceStores, storeId }).set(this.prefix({
|
|
130
|
+
namespace,
|
|
131
|
+
resourceIdentifier,
|
|
132
|
+
}), resource, ttl ?? this.defaultTtl);
|
|
179
133
|
}
|
|
180
134
|
store(args) {
|
|
181
135
|
const storeId = this.storeIdStr({ storeId: args.storeId });
|
|
@@ -187,16 +141,15 @@ class ResourceResolver {
|
|
|
187
141
|
}
|
|
188
142
|
storeIdStr(args) {
|
|
189
143
|
const { storeId } = args;
|
|
190
|
-
return storeId
|
|
144
|
+
return storeId ?? this.defaultStoreId;
|
|
191
145
|
}
|
|
192
146
|
namespaceStr(args) {
|
|
193
147
|
const { namespace } = args;
|
|
194
|
-
return namespace
|
|
148
|
+
return namespace ?? this.defaultNamespace;
|
|
195
149
|
}
|
|
196
150
|
prefix(args) {
|
|
197
151
|
const { namespace, resourceIdentifier } = args;
|
|
198
152
|
return `${this.namespaceStr({ namespace })}:${resourceIdentifier}`;
|
|
199
153
|
}
|
|
200
154
|
}
|
|
201
|
-
exports.ResourceResolver = ResourceResolver;
|
|
202
155
|
//# sourceMappingURL=ResourceResolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceResolver.js","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ResourceResolver.js","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,aAAa,EAAkB,MAAM,iCAAiC,CAAA;AAE3G,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAA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ANGED
|
@@ -1,26 +1,8 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ResourceResolver = exports.schema = void 0;
|
|
18
1
|
/**
|
|
19
2
|
* @public
|
|
20
3
|
*/
|
|
21
4
|
const schema = require('../plugin.schema.json');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
__exportStar(require("./types/IResourceResolver"), exports);
|
|
5
|
+
export { schema };
|
|
6
|
+
export { ResourceResolver } from './agent/ResourceResolver';
|
|
7
|
+
export * from './types/IResourceResolver';
|
|
26
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,cAAc,2BAA2B,CAAA"}
|
|
@@ -1,45 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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) => {
|
|
1
|
+
import { Headers, Response, Request } from 'cross-fetch';
|
|
2
|
+
import * as u8a from 'uint8arrays';
|
|
3
|
+
export const getResourceIdentifier = (input) => {
|
|
39
4
|
if (typeof input === 'string') {
|
|
40
5
|
return input;
|
|
41
6
|
}
|
|
42
|
-
else if (input instanceof
|
|
7
|
+
else if (input instanceof Request) {
|
|
43
8
|
return input.url;
|
|
44
9
|
}
|
|
45
10
|
else if (input instanceof URL) {
|
|
@@ -47,9 +12,8 @@ const getResourceIdentifier = (input) => {
|
|
|
47
12
|
}
|
|
48
13
|
throw new Error('Invalid input type. Expected Request, string, or URL.');
|
|
49
14
|
};
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const arrayBuffer = yield response.arrayBuffer();
|
|
15
|
+
export const serializeResponse = async (response) => {
|
|
16
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
53
17
|
const base64Url = u8a.toString(new Uint8Array(arrayBuffer), 'base64url');
|
|
54
18
|
return {
|
|
55
19
|
status: response.status,
|
|
@@ -58,22 +22,19 @@ const serializeResponse = (response) => __awaiter(void 0, void 0, void 0, functi
|
|
|
58
22
|
headers: Object.fromEntries(response.headers.entries()),
|
|
59
23
|
body: base64Url,
|
|
60
24
|
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const deserializeResponse = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
};
|
|
26
|
+
export const deserializeResponse = async (data) => {
|
|
64
27
|
const { status, statusText, headers, body } = data;
|
|
65
28
|
const uint8Array = u8a.fromString(body, 'base64url');
|
|
66
29
|
const arrayBuffer = uint8Array.buffer.slice(uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength);
|
|
67
|
-
return new
|
|
30
|
+
return new Response(arrayBuffer, {
|
|
68
31
|
status,
|
|
69
32
|
statusText,
|
|
70
|
-
headers: new
|
|
33
|
+
headers: new Headers(headers),
|
|
71
34
|
});
|
|
72
|
-
}
|
|
73
|
-
exports.deserializeResponse = deserializeResponse;
|
|
35
|
+
};
|
|
74
36
|
// Check if the cache is still within the acceptable age
|
|
75
|
-
const isCacheWithinMaxAge = (cachedResource, resolveOpts) => {
|
|
76
|
-
return cachedResource && (
|
|
37
|
+
export const isCacheWithinMaxAge = (cachedResource, resolveOpts) => {
|
|
38
|
+
return cachedResource && (resolveOpts?.maxAgeMs === undefined || Date.now() - cachedResource.insertedAt < resolveOpts.maxAgeMs);
|
|
77
39
|
};
|
|
78
|
-
exports.isCacheWithinMaxAge = isCacheWithinMaxAge;
|
|
79
40
|
//# sourceMappingURL=ResourceResolverUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceResolverUtils.js","sourceRoot":"","sources":["../../src/utils/ResourceResolverUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ResourceResolverUtils.js","sourceRoot":"","sources":["../../src/utils/ResourceResolverUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAA;AAGlC,MAAM,CAAC,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,OAAO,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC,GAAG,CAAA;IAClB,CAAC;SAAM,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QAChC,O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AAW,EAAE,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;AACjI,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.resource-resolver",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"build:clean": "tsc --build --clean && tsc --build"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@sphereon/ssi-sdk.anomaly-detection": "0.33.
|
|
18
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.33.
|
|
17
|
+
"@sphereon/ssi-sdk.anomaly-detection": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
18
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
19
19
|
"cross-fetch": "^3.1.8",
|
|
20
20
|
"debug": "^4.3.5",
|
|
21
21
|
"typeorm": "^0.3.21",
|
|
22
22
|
"uint8arrays": "^3.1.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@sphereon/ssi-sdk.agent-config": "0.33.
|
|
25
|
+
"@sphereon/ssi-sdk.agent-config": "0.33.1-feature.vcdm2.4+9f634bdb",
|
|
26
26
|
"@veramo/remote-client": "4.2.0",
|
|
27
27
|
"@veramo/remote-server": "4.2.0",
|
|
28
28
|
"nock": "^13.5.4",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"Resource Management",
|
|
50
50
|
"Caching"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "9f634bdb714061141e277508c124b08d626f6036"
|
|
53
53
|
}
|