@dfns/sdk 0.1.0-beta.6 → 0.1.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/fetch.js +11 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfns/sdk",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0-beta.7",
4
4
  "dependencies": {
5
5
  "buffer": "6.0.3",
6
6
  "cross-fetch": "3.1.6",
package/utils/fetch.js CHANGED
@@ -27,13 +27,15 @@ const jsonSerializer = (fetch) => {
27
27
  };
28
28
  const errorHandler = (fetch) => {
29
29
  return async (resource, options) => {
30
+ var _a;
30
31
  const response = await fetch(resource, options);
31
32
  if (response.ok) {
32
33
  return response;
33
34
  }
34
35
  else {
35
36
  const body = await response.json();
36
- throw new dfnsError_1.DfnsError(response.status, body.error.message, body.error);
37
+ 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);
38
+ throw new dfnsError_1.DfnsError(response.status, errorMessage, body.error);
37
39
  }
38
40
  };
39
41
  };
@@ -65,18 +67,21 @@ const userAction = (fetch) => {
65
67
  return async (resource, options) => {
66
68
  var _a, _b;
67
69
  if (options.method !== 'GET') {
70
+ const apiOptions = {
71
+ ...options.apiOptions,
72
+ baseUrl: options.apiOptions.baseAuthUrl || options.apiOptions.baseUrl,
73
+ };
68
74
  const { challenge, challengeIdentifier, allowCredentials } = await baseAuthApi_1.BaseAuthApi.createUserActionChallenge({
69
75
  userActionPayload: (_a = options.body) !== null && _a !== void 0 ? _a : '',
70
76
  userActionHttpMethod: options.method,
71
77
  userActionHttpPath: resource.pathname,
72
- userActionServerKind: 'Api',
73
- }, options.apiOptions);
74
- const { signer } = options.apiOptions;
75
- const assertion = await signer.sign(challenge, allowCredentials);
78
+ userActionServerKind: (apiOptions === null || apiOptions === void 0 ? void 0 : apiOptions.userActionServerKind) || 'Api',
79
+ }, apiOptions);
80
+ const assertion = await apiOptions.signer.sign(challenge, allowCredentials);
76
81
  const { userAction } = await baseAuthApi_1.BaseAuthApi.signUserActionChallenge({
77
82
  challengeIdentifier,
78
83
  firstFactor: assertion,
79
- }, options.apiOptions);
84
+ }, apiOptions);
80
85
  options.headers = {
81
86
  'x-dfns-useraction': userAction,
82
87
  ...((_b = options.headers) !== null && _b !== void 0 ? _b : {}),