@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.
@@ -75,7 +75,7 @@ const makeRouteClient = (initializer, config, route, authProvider) => {
75
75
  status: response.status,
76
76
  acceptStatus: (...status) => {
77
77
  if (!status.includes(response.status)) {
78
- throw new Error('unexpected response from api');
78
+ throw new Error(`unexpected HTTP ${response.status} response from api`);
79
79
  }
80
80
  return { status: response.status, headers: response.headers, load: (0, exports.loadResponse)(response) };
81
81
  },
@@ -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
@@ -20,6 +20,9 @@ const browserAuthProvider = ({ window, configSpace }) => (configProvider) => {
20
20
  let userData = {
21
21
  token: [null, embeddedQueryValue].includes(authQuery) ? null : authQuery
22
22
  };
23
+ const getAuthToken = async () => {
24
+ return (await getUserData()).token;
25
+ };
23
26
  const getAuthorizedLinkUrl = (urlString) => {
24
27
  const url = new URL(urlString);
25
28
  if (userData.token) {
@@ -92,6 +95,10 @@ const browserAuthProvider = ({ window, configSpace }) => (configProvider) => {
92
95
  return (await getUserData()).user;
93
96
  };
94
97
  return {
98
+ /**
99
+ * gets the authentication token
100
+ */
101
+ getAuthToken,
95
102
  /**
96
103
  * adds auth parameters to the url. this is only safe to use when using javascript to navigate
97
104
  * within the current window, eg `window.location = 'https://my.otherservice.com';` anchors