@openstax/ts-utils 1.6.0 → 1.6.2

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.
@@ -45,7 +45,7 @@ const makeRouteClient = (initializer, config, route, authProvider) => {
45
45
  status: response.status,
46
46
  acceptStatus: (...status) => {
47
47
  if (!status.includes(response.status)) {
48
- throw new Error('unexpected response from api');
48
+ throw new Error(`unexpected HTTP ${response.status} response from api`);
49
49
  }
50
50
  return { status: response.status, headers: response.headers, load: loadResponse(response) };
51
51
  },
@@ -29,6 +29,10 @@ export interface Window {
29
29
  export declare const browserAuthProvider: <C extends string = "auth">({ window, configSpace }: Initializer<C>) => (configProvider: { [key in C]: {
30
30
  accountsBase: import("../../config").ConfigValueProvider<string>;
31
31
  }; }) => {
32
+ /**
33
+ * gets the authentication token
34
+ */
35
+ getAuthToken: () => Promise<string | null>;
32
36
  /**
33
37
  * adds auth parameters to the url. this is only safe to use when using javascript to navigate
34
38
  * within the current window, eg `window.location = 'https://my.otherservice.com';` anchors
@@ -17,6 +17,9 @@ export const browserAuthProvider = ({ window, configSpace }) => (configProvider)
17
17
  let userData = {
18
18
  token: [null, embeddedQueryValue].includes(authQuery) ? null : authQuery
19
19
  };
20
+ const getAuthToken = async () => {
21
+ return (await getUserData()).token;
22
+ };
20
23
  const getAuthorizedLinkUrl = (urlString) => {
21
24
  const url = new URL(urlString);
22
25
  if (userData.token) {
@@ -89,6 +92,10 @@ export const browserAuthProvider = ({ window, configSpace }) => (configProvider)
89
92
  return (await getUserData()).user;
90
93
  };
91
94
  return {
95
+ /**
96
+ * gets the authentication token
97
+ */
98
+ getAuthToken,
92
99
  /**
93
100
  * adds auth parameters to the url. this is only safe to use when using javascript to navigate
94
101
  * within the current window, eg `window.location = 'https://my.otherservice.com';` anchors