@openstax/ts-utils 1.32.0 → 1.32.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.
- package/dist/cjs/services/authProvider/browser.d.ts +6 -38
- package/dist/cjs/services/authProvider/browser.js +1 -0
- package/dist/cjs/services/authProvider/index.d.ts +1 -0
- package/dist/cjs/services/authProvider/index.js +10 -5
- package/dist/cjs/services/authProvider/subrequest.js +8 -6
- package/dist/cjs/services/authProvider/utils/embeddedAuthProvider.d.ts +2 -2
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/authProvider/browser.d.ts +6 -38
- package/dist/esm/services/authProvider/browser.js +1 -0
- package/dist/esm/services/authProvider/index.d.ts +1 -0
- package/dist/esm/services/authProvider/index.js +10 -5
- package/dist/esm/services/authProvider/subrequest.js +8 -6
- package/dist/esm/services/authProvider/utils/embeddedAuthProvider.d.ts +2 -2
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigProviderForConfig } from '../../config';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { GenericFetch } from '../../fetch';
|
|
3
|
+
import { UserData } from './utils/embeddedAuthProvider';
|
|
4
|
+
import { ApiUser, AuthProvider } from '.';
|
|
4
5
|
type Config = {
|
|
5
6
|
accountsBase: string;
|
|
6
7
|
};
|
|
@@ -27,46 +28,13 @@ export interface Window {
|
|
|
27
28
|
removeEventListener: (event: 'message', callback: EventHandler) => void;
|
|
28
29
|
}
|
|
29
30
|
export type UpdatableUserFields = Partial<Pick<ApiUser, 'consent_preferences' | 'first_name' | 'last_name'>>;
|
|
30
|
-
export
|
|
31
|
-
/**
|
|
32
|
-
* gets the authentication token
|
|
33
|
-
*/
|
|
34
|
-
getAuthToken: () => Promise<string | null>;
|
|
35
|
-
/**
|
|
36
|
-
* adds auth parameters to the url. this is only safe to use when using javascript to navigate
|
|
37
|
-
* within the current window, eg `window.location = 'https://my.otherservice.com';` anchors
|
|
38
|
-
* should use getAuthorizedLinkUrl for their href.
|
|
39
|
-
*
|
|
40
|
-
* result unreliable unless `getUser` is resolved first.
|
|
41
|
-
*/
|
|
31
|
+
export type BrowserAuthProvider = AuthProvider & {
|
|
42
32
|
getAuthorizedUrl: (urlString: string) => string;
|
|
43
|
-
/**
|
|
44
|
-
* all link href-s must be rendered with auth tokens so that they work when opened in a new tab
|
|
45
|
-
*
|
|
46
|
-
* result unreliable unless `getUser` is resolved first.
|
|
47
|
-
*/
|
|
48
33
|
getAuthorizedLinkUrl: (urlString: string) => string;
|
|
49
|
-
/**
|
|
50
|
-
* gets an authorized url for an iframe src. sets params on the url and saves its
|
|
51
|
-
* origin to trust releasing user identity to it
|
|
52
|
-
*/
|
|
53
34
|
getAuthorizedEmbedUrl: (urlString: string, extraParams?: {
|
|
54
35
|
[key: string]: string;
|
|
55
36
|
}) => string;
|
|
56
|
-
|
|
57
|
-
* gets second argument for `fetch` that has authentication token or cookie
|
|
58
|
-
*/
|
|
59
|
-
getAuthorizedFetchConfig: () => Promise<FetchConfig>;
|
|
60
|
-
/**
|
|
61
|
-
* loads current user identity. does not reflect changes in identity after being called the first time.
|
|
62
|
-
*/
|
|
63
|
-
getUser: () => Promise<User | undefined>;
|
|
64
|
-
/**
|
|
65
|
-
* updates user settings, for example the cookie consent preferences
|
|
66
|
-
*/
|
|
67
|
-
updateUser: (updates: UpdatableUserFields) => Promise<{
|
|
68
|
-
user: ApiUser;
|
|
69
|
-
token: string | null;
|
|
70
|
-
}>;
|
|
37
|
+
updateUser: (updates: UpdatableUserFields) => Promise<UserData<ApiUser>>;
|
|
71
38
|
};
|
|
39
|
+
export declare const browserAuthProvider: <C extends string = "auth">({ window, configSpace }: Initializer<C>) => (configProvider: { [_key in C]: ConfigProviderForConfig<Config>; }) => BrowserAuthProvider;
|
|
72
40
|
export {};
|
|
@@ -145,6 +145,7 @@ const browserAuthProvider = ({ window, configSpace }) => (configProvider) => {
|
|
|
145
145
|
* loads current user identity. does not reflect changes in identity after being called the first time.
|
|
146
146
|
*/
|
|
147
147
|
getUser,
|
|
148
|
+
loadUserData: getUser,
|
|
148
149
|
/**
|
|
149
150
|
* updates user settings, for example the cookie consent preferences
|
|
150
151
|
*/
|
|
@@ -43,6 +43,7 @@ export type AuthProvider = {
|
|
|
43
43
|
* gets second argument for `fetch` that has authentication token or cookie
|
|
44
44
|
*/
|
|
45
45
|
getAuthorizedFetchConfig: () => Promise<FetchConfig>;
|
|
46
|
+
loadUserData: () => Promise<ApiUser | undefined>;
|
|
46
47
|
};
|
|
47
48
|
export type CookieAuthProviderRequest = {
|
|
48
49
|
cookies?: string[];
|
|
@@ -7,11 +7,16 @@ exports.getAuthTokenOrCookie = exports.stubAuthProvider = void 0;
|
|
|
7
7
|
const cookie_1 = __importDefault(require("cookie"));
|
|
8
8
|
const helpers_1 = require("../../misc/helpers");
|
|
9
9
|
const helpers_2 = require("../../routing/helpers");
|
|
10
|
-
const stubAuthProvider = (user) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const stubAuthProvider = (user) => {
|
|
11
|
+
const getUser = () => Promise.resolve(user);
|
|
12
|
+
return {
|
|
13
|
+
getAuthToken: () => Promise.resolve('authToken'),
|
|
14
|
+
getUser,
|
|
15
|
+
getAuthorizedFetchConfig: () => Promise.resolve(user ? { headers: { Authorization: user.uuid } } : {}),
|
|
16
|
+
// This is not technically correct, but most tests won't care
|
|
17
|
+
loadUserData: getUser
|
|
18
|
+
};
|
|
19
|
+
};
|
|
15
20
|
exports.stubAuthProvider = stubAuthProvider;
|
|
16
21
|
const getAuthTokenOrCookie = (request, cookieName, queryKey = 'auth') => {
|
|
17
22
|
var _a, _b;
|
|
@@ -32,15 +32,17 @@ const subrequestAuthProvider = (initializer) => (configProvider) => {
|
|
|
32
32
|
}
|
|
33
33
|
return user;
|
|
34
34
|
};
|
|
35
|
+
const getUser = async () => {
|
|
36
|
+
if (!user) {
|
|
37
|
+
user = await loadUser();
|
|
38
|
+
}
|
|
39
|
+
return user;
|
|
40
|
+
};
|
|
35
41
|
return {
|
|
36
42
|
getAuthToken,
|
|
37
43
|
getAuthorizedFetchConfig,
|
|
38
|
-
getUser
|
|
39
|
-
|
|
40
|
-
user = await loadUser();
|
|
41
|
-
}
|
|
42
|
-
return user;
|
|
43
|
-
}
|
|
44
|
+
getUser,
|
|
45
|
+
loadUserData: getUser
|
|
44
46
|
};
|
|
45
47
|
};
|
|
46
48
|
};
|