Skip to content

Commit

Permalink
Switch http handler to use http-client instead of fetch global.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrizagidulin committed Feb 11, 2024
1 parent 6717192 commit 86f96d7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'prettier/prettier': 'off',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
'@typescript-eslint/return-await': 'off'
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/restrict-template-expressions': 'off'
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"./package.json": "./package.json"
},
"dependencies": {
"@digitalbazaar/http-client": "^4.1.0",
"@digitalbazaar/vc-status-list-context": "^3.0.1",
"@digitalcredentials/crypto-ld": "^7.0.2",
"@digitalcredentials/dcc-context": "^1.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ declare module 'json-canonicalize';
declare module 'react-native-keychain';
declare module '@digitalcredentials/open-badges-context';
declare module '@digitalbazaar/credentials-v2-context';
declare module '@digitalbazaar/http-client';
7 changes: 4 additions & 3 deletions src/documentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CryptoLD } from '@digitalcredentials/crypto-ld';
import * as didWeb from '@interop/did-web-resolver';
import { parseResponseBody } from './parseResponse';
import obCtx from '@digitalcredentials/open-badges-context';
import { httpClient } from '@digitalbazaar/http-client';
// import vc2Context from '@digitalbazaar/credentials-v2-context';

const cryptoLd = new CryptoLD();
Expand Down Expand Up @@ -53,9 +54,9 @@ export const httpClientHandler = {
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
};
result = await fetch(params.url, { headers });
} catch(e) {
throw new Error('NotFoundError');
result = await httpClient.get(params.url, { headers });
} catch(e: any) {
throw new Error(`NotFoundError loading "${params.url}": ${e.message}`);
}

return parseResponseBody(result);
Expand Down
9 changes: 9 additions & 0 deletions test/documentLoader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ describe('documentLoader', () => {
expect(result.document).to.equal(contextObject)
})

it('should load a status VC from web', async () => {
const documentLoader = securityLoader({fetchRemoteContexts: true}).build();

const url = 'https://digitalcredentials.github.io/credential-status-playground/JWZM3H8WKU';
const result = await documentLoader(url);
expect(result.document.issuer).to
.equal('did:key:z6MkhVTX9BF3NGYX6cc7jWpbNnR7cAjH8LUffabZP8Qu4ysC');
});

it('supports beta OBv3 context', async () => {
const load = securityLoader().build()
const { document } = await load('https://purl.imsglobal.org/spec/ob/v3p0/context.json')
Expand Down

0 comments on commit 86f96d7

Please sign in to comment.