@dfns/sdk
Advanced tools
Comparing version 0.1.0-beta.6 to 0.1.0-beta.7
{ | ||
"name": "@dfns/sdk", | ||
"version": "0.1.0-beta.6", | ||
"version": "0.1.0-beta.7", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "buffer": "6.0.3", |
@@ -30,2 +30,3 @@ "use strict"; | ||
return async (resource, options) => { | ||
var _a; | ||
const response = await fetch(resource, options); | ||
@@ -37,3 +38,4 @@ if (response.ok) { | ||
const body = await response.json(); | ||
throw new dfnsError_1.DfnsError(response.status, body.error.message, body.error); | ||
const errorMessage = ((_a = body === null || body === void 0 ? void 0 : body.error) === null || _a === void 0 ? void 0 : _a.message) || (body === null || body === void 0 ? void 0 : body.message) || JSON.stringify(body); | ||
throw new dfnsError_1.DfnsError(response.status, errorMessage, body.error); | ||
} | ||
@@ -70,2 +72,6 @@ }; | ||
if (options.method !== 'GET') { | ||
const apiOptions = { | ||
...options.apiOptions, | ||
baseUrl: options.apiOptions.baseAuthUrl || options.apiOptions.baseUrl, | ||
}; | ||
const { challenge, challengeIdentifier, allowCredentials } = await baseAuthApi_1.BaseAuthApi.createUserActionChallenge({ | ||
@@ -75,10 +81,9 @@ userActionPayload: (_a = options.body) !== null && _a !== void 0 ? _a : '', | ||
userActionHttpPath: resource.pathname, | ||
userActionServerKind: 'Api', | ||
}, options.apiOptions); | ||
const { signer } = options.apiOptions; | ||
const assertion = await signer.sign(challenge, allowCredentials); | ||
userActionServerKind: (apiOptions === null || apiOptions === void 0 ? void 0 : apiOptions.userActionServerKind) || 'Api', | ||
}, apiOptions); | ||
const assertion = await apiOptions.signer.sign(challenge, allowCredentials); | ||
const { userAction } = await baseAuthApi_1.BaseAuthApi.signUserActionChallenge({ | ||
challengeIdentifier, | ||
firstFactor: assertion, | ||
}, options.apiOptions); | ||
}, apiOptions); | ||
options.headers = { | ||
@@ -85,0 +90,0 @@ 'x-dfns-useraction': userAction, |
2247380
77846