Skip to content

Commit 4aea9c3

Browse files
Switch http handler to use http-client instead of fetch global.
1 parent 6717192 commit 4aea9c3

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'prettier/prettier': 'off',
1212
'arrow-body-style': 'off',
1313
'prefer-arrow-callback': 'off',
14-
'@typescript-eslint/return-await': 'off'
14+
'@typescript-eslint/return-await': 'off',
15+
'@typescript-eslint/restrict-template-expressions': 'off'
1516
}
1617
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"./package.json": "./package.json"
3232
},
3333
"dependencies": {
34+
"@digitalbazaar/http-client": "^4.1.0",
3435
"@digitalbazaar/vc-status-list-context": "^3.0.1",
3536
"@digitalcredentials/crypto-ld": "^7.0.2",
3637
"@digitalcredentials/dcc-context": "^1.0.0",

src/declarations.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ declare module 'json-canonicalize';
1919
declare module 'react-native-keychain';
2020
declare module '@digitalcredentials/open-badges-context';
2121
declare module '@digitalbazaar/credentials-v2-context';
22+
declare module '@digitalbazaar/http-client';

src/documentLoader.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { CryptoLD } from '@digitalcredentials/crypto-ld';
1818
import * as didWeb from '@interop/did-web-resolver';
1919
import { parseResponseBody } from './parseResponse';
2020
import obCtx from '@digitalcredentials/open-badges-context';
21+
import { httpClient } from '@digitalbazaar/http-client';
2122
// import vc2Context from '@digitalbazaar/credentials-v2-context';
2223

2324
const cryptoLd = new CryptoLD();
@@ -53,9 +54,9 @@ export const httpClientHandler = {
5354
'Cache-Control': 'no-cache',
5455
'Pragma': 'no-cache'
5556
};
56-
result = await fetch(params.url, { headers });
57-
} catch(e) {
58-
throw new Error('NotFoundError');
57+
result = await httpClient.get(params.url, { headers });
58+
} catch(e: any) {
59+
throw new Error(`NotFoundError loading "${params.url}": ${e.message}`);
5960
}
6061

6162
return parseResponseBody(result);

test/documentLoader.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ describe('documentLoader', () => {
1515
expect(result.document).to.equal(contextObject)
1616
})
1717

18+
it('should load a status VC from web', async () => {
19+
const documentLoader = securityLoader({fetchRemoteContexts: true}).build();
20+
21+
const url = 'https://digitalcredentials.github.io/credential-status-playground/JWZM3H8WKU';
22+
const result = await documentLoader(url);
23+
expect(result.document.issuer).to
24+
.equal('did:key:z6MkhVTX9BF3NGYX6cc7jWpbNnR7cAjH8LUffabZP8Qu4ysC');
25+
});
26+
1827
it('supports beta OBv3 context', async () => {
1928
const load = securityLoader().build()
2029
const { document } = await load('https://purl.imsglobal.org/spec/ob/v3p0/context.json')

0 commit comments

Comments
 (0)