@sphereon/ssi-sdk.resource-resolver 0.30.2-unstable.19 → 0.30.2-unstable.22

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -25,8 +25,8 @@ A Veramo resource resolver plugin. This plugin has the option to cache resources
25
25
  ## Usage
26
26
 
27
27
  ```typescript
28
- import { ResourceResolver } from '@sphereon/ssi-sdk.resource-resolver'
29
- import { KeyValueStoreEntity, kvStoreMigrations, KeyValueStore } from '@sphereon/ssi-sdk.kv-store-temp'
28
+ import { IResourceResolver, ResourceResolver } from '@sphereon/ssi-sdk.resource-resolver'
29
+ import { KeyValueStoreEntity, kvStoreMigrations, KeyValueStore, KeyValueTypeORMStoreAdapter } from '@sphereon/ssi-sdk.kv-store-temp'
30
30
 
31
31
  const dbConnection = createConnection({
32
32
  type: 'react-native',
@@ -39,7 +39,7 @@ const dbConnection = createConnection({
39
39
  entities: [KeyValueStoreEntity],
40
40
  })
41
41
 
42
- const agent = createAgent<IContactManager>({
42
+ const agent = createAgent<IResourceResolver>({
43
43
  plugins: [
44
44
  new ResourceResolver({
45
45
  resourceStores: new KeyValueStore({
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceResolver.d.ts","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAQ3C,OAAO,EAIL,iBAAiB,EAKjB,uBAAuB,EAIxB,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAMlC;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuC;gBAE3D,OAAO,CAAC,EAAE,uBAAuB;IA4B7C,sDAAsD;YACxC,eAAe;IAoD7B,gEAAgE;YAClD,yBAAyB;IAOvC,6DAA6D;YAC/C,sBAAsB;IAIpC,+DAA+D;YACjD,wBAAwB;IAItC,yDAAyD;YAC3C,kBAAkB;YAIlB,WAAW;YAUX,eAAe;IAe7B,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,MAAM;CAKf"}
1
+ {"version":3,"file":"ResourceResolver.d.ts","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAU3C,OAAO,EAIL,iBAAiB,EAKjB,uBAAuB,EAIxB,MAAM,4BAA4B,CAAA;AAEnC;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACnD,QAAQ,CAAC,MAAM,MAA2B;IAC1C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAMlC;IAED,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAQ;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuC;gBAE3D,OAAO,CAAC,EAAE,uBAAuB;IA4B7C,sDAAsD;YACxC,eAAe;IAwD7B,gEAAgE;YAClD,yBAAyB;IAOvC,6DAA6D;YAC/C,sBAAsB;IAIpC,+DAA+D;YACjD,wBAAwB;IAItC,yDAAyD;YAC3C,kBAAkB;YAIlB,WAAW;YAUX,eAAe;IAe7B,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,MAAM;CAKf"}
@@ -74,7 +74,9 @@ class ResourceResolver {
74
74
  const { input, init, resourceType, resolveOpts, partyCorrelationId, storeId, namespace } = args;
75
75
  const resourceIdentifier = (0, ResourceResolverUtils_1.getResourceIdentifier)(input);
76
76
  const cachedResource = yield this.getResource({ resourceIdentifier, storeId, namespace });
77
- if (cachedResource.value && ((resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.maxAgeMs) === undefined || (Date.now() - cachedResource.value.insertedAt < resolveOpts.maxAgeMs))) {
77
+ if (cachedResource.value &&
78
+ (0, ResourceResolverUtils_1.isCacheWithinMaxAge)(cachedResource, resolveOpts) &&
79
+ (0, ResourceResolverUtils_1.isRequestCacheable)(input, resolveOpts)) {
78
80
  return (0, ResourceResolverUtils_1.deserializeResponse)(cachedResource.value.response);
79
81
  }
80
82
  if (resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.onlyCache) {
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceResolver.js","sourceRoot":"","sources":["../../src/agent/ResourceResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EAKwC;AAExC,2DAAsD;AACtD,oCAAiC;AACjC,0EAIuC;AAgBvC;;GAEG;AACH,MAAa,gBAAgB;IAe3B,YAAY,OAAiC;QAdpC,WAAM,GAAG,cAAM,CAAC,iBAAiB,CAAA;QACjC,YAAO,GAAsB;YACpC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAChD,yBAAyB,EAAE,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC;YACpE,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC9D,wBAAwB,EAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC;YAClE,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;SACvD,CAAA;QAQC,MAAM,EACJ,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,GAAG,EACJ,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EA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AC,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;CAEF;AA5KD,4CA4KC"}
@@ -1,6 +1,9 @@
1
+ import { IValueData } from '@sphereon/ssi-sdk.kv-store-temp';
1
2
  import { Response, Request } from 'cross-fetch';
2
- import { SerializedResponse } from '../types/IResourceResolver';
3
+ import { ResolveOptions, Resource, SerializedResponse } from '../types/IResourceResolver';
3
4
  export declare const getResourceIdentifier: (input: Request | string | URL) => string;
4
5
  export declare const serializeResponse: (response: Response) => Promise<SerializedResponse>;
5
6
  export declare const deserializeResponse: (data: SerializedResponse) => Promise<Response>;
7
+ export declare const isCacheWithinMaxAge: (cachedResource: IValueData<Resource>, resolveOpts?: ResolveOptions) => boolean;
8
+ export declare const isRequestCacheable: (input: RequestInfo | URL, resolveOpts?: ResolveOptions) => boolean;
6
9
  //# sourceMappingURL=ResourceResolverUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceResolverUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ResourceResolverUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAE/D,eAAO,MAAM,qBAAqB,UAAW,OAAO,GAAG,MAAM,GAAG,GAAG,KAAG,MAUrE,CAAA;AAED,eAAO,MAAM,iBAAiB,aAAoB,QAAQ,KAAG,QAAQ,kBAAkB,CAUtF,CAAA;AAED,eAAO,MAAM,mBAAmB,SAAgB,kBAAkB,KAAG,QAAQ,QAAQ,CAgBpF,CAAA"}
1
+ {"version":3,"file":"ResourceResolverUtils.d.ts","sourceRoot":"","sources":["../../src/utils/ResourceResolverUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,EAAW,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAExD,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,QAAQ,kBAAkB,CAUtF,CAAA;AAED,eAAO,MAAM,mBAAmB,SAAgB,kBAAkB,KAAG,QAAQ,QAAQ,CAgBpF,CAAA;AAGD,eAAO,MAAM,mBAAmB,mBAAoB,WAAW,QAAQ,CAAC,gBAAgB,cAAc,KAAG,OAExG,CAAA;AAGD,eAAO,MAAM,kBAAkB,UAAW,WAAW,GAAG,GAAG,gBAAgB,cAAc,KAAG,OAE3F,CAAA"}
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.deserializeResponse = exports.serializeResponse = exports.getResourceIdentifier = void 0;
35
+ exports.isRequestCacheable = exports.isCacheWithinMaxAge = exports.deserializeResponse = exports.serializeResponse = exports.getResourceIdentifier = void 0;
36
36
  const cross_fetch_1 = require("cross-fetch");
37
37
  const u8a = __importStar(require("uint8arrays"));
38
38
  const getResourceIdentifier = (input) => {
@@ -70,4 +70,14 @@ const deserializeResponse = (data) => __awaiter(void 0, void 0, void 0, function
70
70
  });
71
71
  });
72
72
  exports.deserializeResponse = deserializeResponse;
73
+ // Check if the cache is still within the acceptable age
74
+ const isCacheWithinMaxAge = (cachedResource, resolveOpts) => {
75
+ return !!cachedResource.value && ((resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.maxAgeMs) === undefined || (Date.now() - cachedResource.value.insertedAt < resolveOpts.maxAgeMs));
76
+ };
77
+ exports.isCacheWithinMaxAge = isCacheWithinMaxAge;
78
+ // Check if the request should use the cache
79
+ const isRequestCacheable = (input, resolveOpts) => {
80
+ return !(input instanceof cross_fetch_1.Request) || input.method === 'GET' || input.method === 'HEAD' || !!(resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.onlyCache);
81
+ };
82
+ exports.isRequestCacheable = isRequestCacheable;
73
83
  //# sourceMappingURL=ResourceResolverUtils.js.map
@@ -1 +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,CAAC;IACf,CAAC;SAAM,IAAI,KAAK,YAAY,qBAAO,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC,GAAG,CAAC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,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,CAAC;IAElH,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;AAhBY,QAAA,mBAAmB,uBAgB/B;AAED,wDAAwD;AACjD,MAAM,mBAAmB,GAAG,CAAC,cAAoC,EAAE,WAA4B,EAAW,EAAE;IACjH,OAAO,CAAC,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,MAAK,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAA;AACjJ,CAAC,CAAA;AAFY,QAAA,mBAAmB,uBAE/B;AAED,4CAA4C;AACrC,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,WAA4B,EAAW,EAAE;IACpG,OAAO,CAAC,CAAC,KAAK,YAAY,qBAAO,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,CAAA,CAAA;AACrH,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.resource-resolver",
3
- "version": "0.30.2-unstable.19+17aad525",
3
+ "version": "0.30.2-unstable.22+ee872952",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,14 +14,14 @@
14
14
  "build:clean": "tsc --build --clean && tsc --build"
15
15
  },
16
16
  "dependencies": {
17
- "@sphereon/ssi-sdk.kv-store-temp": "0.30.2-unstable.19+17aad525",
17
+ "@sphereon/ssi-sdk.kv-store-temp": "0.30.2-unstable.22+ee872952",
18
18
  "cross-fetch": "^3.1.8",
19
19
  "debug": "^4.3.5",
20
20
  "typeorm": "^0.3.20",
21
21
  "uint8arrays": "^3.1.1"
22
22
  },
23
23
  "devDependencies": {
24
- "@sphereon/ssi-sdk.agent-config": "0.30.2-unstable.19+17aad525",
24
+ "@sphereon/ssi-sdk.agent-config": "0.30.2-unstable.22+ee872952",
25
25
  "@veramo/remote-client": "4.2.0",
26
26
  "@veramo/remote-server": "4.2.0",
27
27
  "nock": "^13.5.4",
@@ -48,5 +48,5 @@
48
48
  "Resource Management",
49
49
  "Caching"
50
50
  ],
51
- "gitHead": "17aad525f38b31f85f9fbc1fa1f8370888d9f829"
51
+ "gitHead": "ee87295245bfea1a5f54355688d79f371f41d438"
52
52
  }
@@ -10,6 +10,8 @@ import { schema } from '../index'
10
10
  import {
11
11
  deserializeResponse,
12
12
  getResourceIdentifier,
13
+ isCacheWithinMaxAge,
14
+ isRequestCacheable,
13
15
  serializeResponse
14
16
  } from '../utils/ResourceResolverUtils'
15
17
  import {
@@ -88,7 +90,11 @@ export class ResourceResolver implements IAgentPlugin {
88
90
  const resourceIdentifier = getResourceIdentifier(input)
89
91
 
90
92
  const cachedResource = await this.getResource({ resourceIdentifier, storeId, namespace })
91
- if (cachedResource.value && (resolveOpts?.maxAgeMs === undefined || (Date.now() - cachedResource.value.insertedAt < resolveOpts.maxAgeMs))) {
93
+ if (
94
+ cachedResource.value &&
95
+ isCacheWithinMaxAge(cachedResource, resolveOpts) &&
96
+ isRequestCacheable(input, resolveOpts)
97
+ ) {
92
98
  return deserializeResponse(cachedResource.value.response);
93
99
  }
94
100
 
@@ -1,6 +1,7 @@
1
+ import { IValueData } from '@sphereon/ssi-sdk.kv-store-temp'
1
2
  import { Headers, Response, Request } from 'cross-fetch'
2
3
  import * as u8a from 'uint8arrays'
3
- import { SerializedResponse } from '../types/IResourceResolver'
4
+ import { ResolveOptions, Resource, SerializedResponse } from '../types/IResourceResolver'
4
5
 
5
6
  export const getResourceIdentifier = (input: Request | string | URL): string => {
6
7
  if (typeof input === 'string') {
@@ -43,3 +44,13 @@ export const deserializeResponse = async (data: SerializedResponse): Promise<Res
43
44
  headers: new Headers(headers)
44
45
  })
45
46
  }
47
+
48
+ // Check if the cache is still within the acceptable age
49
+ export const isCacheWithinMaxAge = (cachedResource: IValueData<Resource>, resolveOpts?: ResolveOptions): boolean => {
50
+ return !!cachedResource.value && (resolveOpts?.maxAgeMs === undefined || (Date.now() - cachedResource.value.insertedAt < resolveOpts.maxAgeMs))
51
+ }
52
+
53
+ // Check if the request should use the cache
54
+ export const isRequestCacheable = (input: RequestInfo | URL, resolveOpts?: ResolveOptions): boolean => {
55
+ return !(input instanceof Request) || input.method === 'GET' || input.method === 'HEAD' || !!resolveOpts?.onlyCache
56
+ }