Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch http handler to use http-client instead of fetch global. #11

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading