@openstax/ts-utils 1.15.3 → 1.15.5

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.
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.browserAuthProvider = void 0;
4
- const lodash_1 = require("lodash");
5
4
  const __1 = require("../..");
6
5
  const config_1 = require("../../config");
7
- const errors_1 = require("../../errors");
8
6
  const guards_1 = require("../../guards");
9
7
  const helpers_1 = require("../../routing/helpers");
10
8
  const embeddedAuthProvider_1 = require("./utils/embeddedAuthProvider");
@@ -99,20 +97,7 @@ const browserAuthProvider = ({ window, configSpace }) => (configProvider) => {
99
97
  return getParentWindowUser();
100
98
  }
101
99
  // getFetchUser() will throw here if authQuery is not set
102
- if (embeddedQuery !== embeddedQueryValue) {
103
- return getFetchUser();
104
- }
105
- const userDataFromParentWindow = await getParentWindowUser();
106
- if (!authQuery) {
107
- return userDataFromParentWindow;
108
- }
109
- const userDataFromAuthQuery = await getFetchUser();
110
- // userDataFromParentWindow has an extra field (role)
111
- if (userDataFromAuthQuery.token === userDataFromParentWindow.token &&
112
- (0, lodash_1.isEqual)(userDataFromAuthQuery.user, userDataFromParentWindow.user)) {
113
- return userDataFromParentWindow;
114
- }
115
- throw new errors_1.UnauthorizedError();
100
+ return await (embeddedQuery === embeddedQueryValue ? getParentWindowUser() : getFetchUser());
116
101
  });
117
102
  const getUser = async () => {
118
103
  return (await getUserData()).user;
@@ -66,6 +66,9 @@ const dynamoUnversionedDocumentStore = (initializer) => () => (configProvider) =
66
66
  throw new errors_1.NotFoundError(`Item with ${key} "${id}" does not exist`);
67
67
  }
68
68
  return parseFloat(result);
69
+ }).catch((error) => {
70
+ throw error.name === 'ConditionalCheckFailedException' ?
71
+ new errors_1.NotFoundError(`Item with ${key} "${id}" does not exist`) : error;
69
72
  });
70
73
  },
71
74
  /* replaces only specified attributes with the given data */
@@ -98,9 +101,12 @@ const dynamoUnversionedDocumentStore = (initializer) => () => (configProvider) =
98
101
  });
99
102
  return dynamodb().send(cmd).then((item) => {
100
103
  if (!item.Attributes) {
101
- throw new Error(`Item with ${key} "${id}" does not exist`);
104
+ throw new errors_1.NotFoundError(`Item with ${key} "${id}" does not exist`);
102
105
  }
103
106
  return (0, dynamoEncoding_1.decodeDynamoDocument)(item.Attributes);
107
+ }).catch((error) => {
108
+ throw error.name === 'ConditionalCheckFailedException' ?
109
+ new errors_1.NotFoundError(`Item with ${key} "${id}" does not exist`) : error;
104
110
  });
105
111
  },
106
112
  /* replaces the entire document with the given data */