@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,7 +1,5 @@
1
- import { isEqual } from 'lodash';
2
1
  import { once } from '../..';
3
2
  import { resolveConfigValue } from '../../config';
4
- import { UnauthorizedError } from '../../errors';
5
3
  import { ifDefined } from '../../guards';
6
4
  import { unsafePayloadValidator } from '../../routing/helpers';
7
5
  import { embeddedAuthProvider, PostMessageTypes } from './utils/embeddedAuthProvider';
@@ -96,20 +94,7 @@ export const browserAuthProvider = ({ window, configSpace }) => (configProvider)
96
94
  return getParentWindowUser();
97
95
  }
98
96
  // getFetchUser() will throw here if authQuery is not set
99
- if (embeddedQuery !== embeddedQueryValue) {
100
- return getFetchUser();
101
- }
102
- const userDataFromParentWindow = await getParentWindowUser();
103
- if (!authQuery) {
104
- return userDataFromParentWindow;
105
- }
106
- const userDataFromAuthQuery = await getFetchUser();
107
- // userDataFromParentWindow has an extra field (role)
108
- if (userDataFromAuthQuery.token === userDataFromParentWindow.token &&
109
- isEqual(userDataFromAuthQuery.user, userDataFromParentWindow.user)) {
110
- return userDataFromParentWindow;
111
- }
112
- throw new UnauthorizedError();
97
+ return await (embeddedQuery === embeddedQueryValue ? getParentWindowUser() : getFetchUser());
113
98
  });
114
99
  const getUser = async () => {
115
100
  return (await getUserData()).user;
@@ -63,6 +63,9 @@ export const dynamoUnversionedDocumentStore = (initializer) => () => (configProv
63
63
  throw new NotFoundError(`Item with ${key} "${id}" does not exist`);
64
64
  }
65
65
  return parseFloat(result);
66
+ }).catch((error) => {
67
+ throw error.name === 'ConditionalCheckFailedException' ?
68
+ new NotFoundError(`Item with ${key} "${id}" does not exist`) : error;
66
69
  });
67
70
  },
68
71
  /* replaces only specified attributes with the given data */
@@ -95,9 +98,12 @@ export const dynamoUnversionedDocumentStore = (initializer) => () => (configProv
95
98
  });
96
99
  return dynamodb().send(cmd).then((item) => {
97
100
  if (!item.Attributes) {
98
- throw new Error(`Item with ${key} "${id}" does not exist`);
101
+ throw new NotFoundError(`Item with ${key} "${id}" does not exist`);
99
102
  }
100
103
  return decodeDynamoDocument(item.Attributes);
104
+ }).catch((error) => {
105
+ throw error.name === 'ConditionalCheckFailedException' ?
106
+ new NotFoundError(`Item with ${key} "${id}" does not exist`) : error;
101
107
  });
102
108
  },
103
109
  /* replaces the entire document with the given data */