@sphereon/ssi-sdk.resource-resolver 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.3

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.
@@ -0,0 +1,33 @@
1
+ import { IAgentPlugin } from '@veramo/core';
2
+ import { IResourceResolver, ResourceResolverOptions } from '../types/IResourceResolver';
3
+ /**
4
+ * {@inheritDoc IResourceResolver}
5
+ */
6
+ export declare class ResourceResolver implements IAgentPlugin {
7
+ readonly schema: any;
8
+ readonly methods: IResourceResolver;
9
+ private readonly defaultStoreId;
10
+ private readonly defaultNamespace;
11
+ private readonly defaultTtl;
12
+ private readonly detectLocation;
13
+ private readonly _resourceStores;
14
+ constructor(options?: ResourceResolverOptions);
15
+ /** {@inheritDoc IResourceResolver.resourceResolve} */
16
+ private resourceResolve;
17
+ private retrieveLocation;
18
+ /** {@inheritDoc IResourceResolver.resourceClearAllResources} */
19
+ private resourceClearAllResources;
20
+ /** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
21
+ private resourceDefaultStoreId;
22
+ /** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
23
+ private resourceDefaultNamespace;
24
+ /** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
25
+ private resourceDefaultTtl;
26
+ private getResource;
27
+ private persistResource;
28
+ private store;
29
+ private storeIdStr;
30
+ private namespaceStr;
31
+ private prefix;
32
+ }
33
+ //# sourceMappingURL=ResourceResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourceResolver.d.ts","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAI3C,OAAO,EAIL,iBAAiB,EAKjB,uBAAuB,EAIxB,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAMlC;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuC;gBAE3D,OAAO,CAAC,EAAE,uBAAuB;IAwB7C,sDAAsD;YACxC,eAAe;YAkDf,gBAAgB;IAc9B,gEAAgE;YAClD,yBAAyB;IAOvC,6DAA6D;YAC/C,sBAAsB;IAIpC,+DAA+D;YACjD,wBAAwB;IAItC,yDAAyD;YAC3C,kBAAkB;YAIlB,WAAW;YAUX,eAAe;IAe7B,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,MAAM;CAIf"}
@@ -0,0 +1,202 @@
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.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");
40
+ /**
41
+ * {@inheritDoc IResourceResolver}
42
+ */
43
+ class ResourceResolver {
44
+ constructor(options) {
45
+ this.schema = index_1.schema.IResourceResolver;
46
+ this.methods = {
47
+ resourceResolve: this.resourceResolve.bind(this),
48
+ resourceClearAllResources: this.resourceClearAllResources.bind(this),
49
+ resourceDefaultStoreId: this.resourceDefaultStoreId.bind(this),
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;
58
+ if (resourceStores && resourceStores instanceof Map) {
59
+ this._resourceStores = resourceStores;
60
+ }
61
+ else if (resourceStores) {
62
+ this._resourceStores = new Map().set(this.defaultStoreId, resourceStores);
63
+ }
64
+ else {
65
+ this._resourceStores = new Map().set(this.defaultStoreId, new ssi_sdk_kv_store_temp_1.KeyValueStore({
66
+ namespace: this.defaultNamespace,
67
+ store: new Map(),
68
+ ttl: this.defaultTtl,
69
+ }));
70
+ }
71
+ }
72
+ /** {@inheritDoc IResourceResolver.resourceResolve} */
73
+ resourceResolve(args, context) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const { input, init, resourceType, resolveOpts, partyCorrelationId, storeId, namespace } = args;
76
+ const resourceIdentifier = (0, ResourceResolverUtils_1.getResourceIdentifier)(input);
77
+ const cachedResource = yield this.getResource({ resourceIdentifier, storeId, namespace });
78
+ if (cachedResource.value && (0, ResourceResolverUtils_1.isCacheWithinMaxAge)(cachedResource.value, resolveOpts)) {
79
+ return (0, ResourceResolverUtils_1.deserializeResponse)(cachedResource.value.response);
80
+ }
81
+ if (resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.onlyCache) {
82
+ return new cross_fetch_1.Response(JSON.stringify({ error: 'Resource not found' }), {
83
+ status: 404,
84
+ statusText: 'Not Found',
85
+ headers: new cross_fetch_1.Headers({ 'Content-Type': 'application/json' }),
86
+ });
87
+ }
88
+ let location;
89
+ if (this.detectLocation) {
90
+ location = yield this.retrieveLocation(input, context);
91
+ }
92
+ const response = yield (0, cross_fetch_1.default)(input, init);
93
+ if (!(resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.skipPersistence) && response.status >= 200 && response.status < 300) {
94
+ const serializedResponse = yield (0, ResourceResolverUtils_1.serializeResponse)(response);
95
+ const resource = {
96
+ location,
97
+ response: serializedResponse,
98
+ resourceType,
99
+ insertedAt: Date.now(),
100
+ partyCorrelationId,
101
+ };
102
+ const cachedResource = yield this.persistResource({
103
+ resource,
104
+ resourceIdentifier,
105
+ namespace,
106
+ storeId,
107
+ });
108
+ if (!cachedResource.value) {
109
+ return Promise.reject(Error('Resource not present in persistence result'));
110
+ }
111
+ return (0, ResourceResolverUtils_1.deserializeResponse)(cachedResource.value.response);
112
+ }
113
+ return response;
114
+ });
115
+ }
116
+ retrieveLocation(input, context) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ let url;
119
+ if (input instanceof Request && input.url !== undefined && input.url !== null) {
120
+ url = new URL(input.url);
121
+ }
122
+ else if (input instanceof URL) {
123
+ url = input;
124
+ }
125
+ else {
126
+ throw Error(`input type is required to be RequestInfo | URL`);
127
+ }
128
+ return yield context.agent.anomalyDetectionLookupLocation({
129
+ ipOrHostname: url.hostname,
130
+ });
131
+ });
132
+ }
133
+ /** {@inheritDoc IResourceResolver.resourceClearAllResources} */
134
+ resourceClearAllResources(args, context) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const { storeId } = args;
137
+ return yield this.store({ stores: this._resourceStores, storeId })
138
+ .clear()
139
+ .then(() => true);
140
+ });
141
+ }
142
+ /** {@inheritDoc IResourceResolver.resourceDefaultStoreId} */
143
+ resourceDefaultStoreId(context) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ return this.defaultStoreId;
146
+ });
147
+ }
148
+ /** {@inheritDoc IResourceResolver.resourceDefaultNamespace} */
149
+ resourceDefaultNamespace(context) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ return this.defaultNamespace;
152
+ });
153
+ }
154
+ /** {@inheritDoc IResourceResolver.resourceDefaultTtl} */
155
+ resourceDefaultTtl(context) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ return this.defaultTtl;
158
+ });
159
+ }
160
+ getResource(args) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ const { resourceIdentifier, storeId, namespace } = args;
163
+ return this.store({ stores: this._resourceStores, storeId }).getAsValueData(this.prefix({
164
+ namespace,
165
+ resourceIdentifier,
166
+ }));
167
+ });
168
+ }
169
+ persistResource(args) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ const { resource, resourceIdentifier, ttl } = args;
172
+ const namespace = this.namespaceStr(args);
173
+ const storeId = this.storeIdStr(args);
174
+ return yield this.store({ stores: this._resourceStores, storeId }).set(this.prefix({
175
+ namespace,
176
+ resourceIdentifier,
177
+ }), resource, ttl !== null && ttl !== void 0 ? ttl : this.defaultTtl);
178
+ });
179
+ }
180
+ store(args) {
181
+ const storeId = this.storeIdStr({ storeId: args.storeId });
182
+ const store = args.stores.get(storeId);
183
+ if (!store) {
184
+ throw Error(`Could not get resource store: ${storeId}`);
185
+ }
186
+ return store;
187
+ }
188
+ storeIdStr(args) {
189
+ const { storeId } = args;
190
+ return storeId !== null && storeId !== void 0 ? storeId : this.defaultStoreId;
191
+ }
192
+ namespaceStr(args) {
193
+ const { namespace } = args;
194
+ return namespace !== null && namespace !== void 0 ? namespace : this.defaultNamespace;
195
+ }
196
+ prefix(args) {
197
+ const { namespace, resourceIdentifier } = args;
198
+ return `${this.namespaceStr({ namespace })}:${resourceIdentifier}`;
199
+ }
200
+ }
201
+ exports.ResourceResolver = ResourceResolver;
202
+ //# sourceMappingURL=ResourceResolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourceResolver.js","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EAA2G;AAE3G,2DAAsD;AACtD,oCAAiC;AACjC,0EAAmI;AAgBnI;;GAEG;AACH,MAAa,gBAAgB;IAgB3B,YAAY,OAAiC;QAfpC,WAAM,GAAG,cAAM,CAAC,iBAAiB,CAAA;QACjC,YAAO,GAAsB;YACpC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAChD,yBAAyB,EAAE,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;YACpE,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC9D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,CAAC,EACF,QAAQ,EACR,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,IAAI,CAAC,UAAU,CACvB,CAAA;QACH,CAAC;KAAA;IAEO,KAAK,CAA2B,IAAkB;QACxD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QACtC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,KAAK,CAAC,iCAAiC,OAAO,EAAE,CAAC,CAAA;QACzD,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAEO,UAAU,CAAC,IAAoB;QACrC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QACxB,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,cAAc,CAAA;IACvC,CAAC;IAEO,YAAY,CAAC,IAAsB;QACzC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAC1B,OAAO,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,gBAAgB,CAAA;IAC3C,CAAC;IAEO,MAAM,CAAC,IAAgB;QAC7B,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAA;QAC9C,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,IAAI,kBAAkB,EAAE,CAAA;IACpE,CAAC;CACF;AAhLD,4CAgLC"}
package/dist/index.d.ts CHANGED
@@ -1,121 +1,8 @@
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
1
  /**
117
2
  * @public
118
3
  */
119
4
  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 };
5
+ export { schema };
6
+ export { ResourceResolver } from './agent/ResourceResolver';
7
+ export * from './types/IResourceResolver';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,MAAM,KAAmC,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,cAAc,2BAA2B,CAAA"}