@amedia/user 0.10.0 → 0.10.1
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/actions/authentication.spec.d.ts +4 -0
- package/dist/index.js +1 -1
- package/dist/utils/location.d.ts +1 -0
- package/esm/actions/authentication.d.ts +5 -0
- package/esm/actions/authorization.d.ts +7 -0
- package/esm/actions/preferences.d.ts +9 -0
- package/esm/actions/preferences.spec.d.ts +1 -0
- package/esm/actions/storage.d.ts +1 -0
- package/esm/actions/userData.d.ts +2 -0
- package/esm/cache/engines/global.d.ts +21 -0
- package/esm/cache/engines/global.spec.d.ts +1 -0
- package/esm/cache/engines/indexeddb.d.ts +7 -0
- package/esm/cache/index.d.ts +11 -0
- package/esm/cache/index.spec.d.ts +4 -0
- package/esm/cache/types.d.ts +11 -0
- package/esm/clients/europa.d.ts +28 -0
- package/esm/clients/europa.spec.d.ts +1 -0
- package/esm/clients/jupiter.d.ts +30 -0
- package/esm/clients/jupiter.spec.d.ts +1 -0
- package/esm/clients/mercury.d.ts +18 -0
- package/esm/clients/mercury.spec.d.ts +4 -0
- package/esm/clients/nebula.d.ts +2 -0
- package/esm/clients/nebula.spec.d.ts +1 -0
- package/esm/clients/pluto.d.ts +3 -0
- package/esm/clients/pluto.spec.d.ts +1 -0
- package/esm/eventHandlers/activation.d.ts +15 -0
- package/esm/eventHandlers/authentication.d.ts +17 -0
- package/esm/eventHandlers/userAttributes.d.ts +20 -0
- package/esm/exceptions/PaywallError.d.ts +7 -0
- package/esm/index-authentcation.spec.d.ts +4 -0
- package/esm/index-subscription.spec.d.ts +4 -0
- package/esm/index.d.ts +23 -0
- package/esm/lib/PaywallUnlocker.d.ts +16 -0
- package/esm/lib/PaywallUnlocker.spec.d.ts +4 -0
- package/esm/lib/User.d.ts +21 -0
- package/esm/lib/cookie.d.ts +5 -0
- package/esm/lib/rpc.d.ts +6 -0
- package/esm/store/index.d.ts +22 -0
- package/esm/store/index.spec.d.ts +1 -0
- package/esm/types.d.ts +21 -0
- package/esm/user.js +1 -6498
- package/esm/user.js.map +1 -1
- package/esm/utils/customEventWrapper.d.ts +17 -0
- package/esm/utils/deepEquals.d.ts +4 -0
- package/esm/utils/getOrUpdate.d.ts +6 -0
- package/esm/utils/getOrUpdate.spec.d.ts +1 -0
- package/esm/utils/location.d.ts +2 -0
- package/esm/utils/log.d.ts +26 -0
- package/esm/utils/queue.d.ts +12 -0
- package/esm/utils/url.d.ts +3 -0
- package/esm/utils/url.spec.d.ts +1 -0
- package/package.json +1 -1
- package/src/actions/authentication.spec.ts +41 -0
- package/src/actions/authentication.ts +8 -4
- package/src/utils/location.ts +6 -4
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const setRootElement: (element: any) => void;
|
|
2
|
+
/**
|
|
3
|
+
* This listener MUST be used by all listeners in ../eventHandlers
|
|
4
|
+
* We want to ensure that only _one_ instance of this package actually
|
|
5
|
+
* orchestrates data and performs requests against backends.
|
|
6
|
+
* @param type
|
|
7
|
+
* @param listener
|
|
8
|
+
*/
|
|
9
|
+
export declare const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this: Window, ev: WindowEventMap[T]) => void) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Use this for response listeners. (../index.ts) where we want
|
|
12
|
+
* all updates with data - no matter who sent the actual request
|
|
13
|
+
* @param type
|
|
14
|
+
* @param listener
|
|
15
|
+
*/
|
|
16
|
+
export declare const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this: Window, ev: WindowEventMap[T]) => void) => void;
|
|
17
|
+
export declare const dispatch: <T extends Event>(event: T) => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Runtype, Static } from 'runtypes';
|
|
2
|
+
export declare type DataFetcherWithCacheTTL<T extends Runtype> = Promise<{
|
|
3
|
+
ttl: number;
|
|
4
|
+
data: Static<T>;
|
|
5
|
+
}>;
|
|
6
|
+
export default function getOrUpdate<T extends Runtype>(key: string, schema: T, fetch: () => DataFetcherWithCacheTTL<T>, cacheQualifier?: (cacheData: Static<T>) => boolean): Promise<Static<T>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare type Logger = {
|
|
2
|
+
debug: (message: string | any, ...extra: any[]) => void;
|
|
3
|
+
info: (message: string | any, ...extra: any[]) => void;
|
|
4
|
+
warn: (message: string | any, ...extra: any[]) => void;
|
|
5
|
+
error: (message: string | any, ...extra: any[]) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const setLogger: (engine: Logger) => void;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
debug: {
|
|
10
|
+
(...data: any[]): void;
|
|
11
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
12
|
+
};
|
|
13
|
+
info: {
|
|
14
|
+
(...data: any[]): void;
|
|
15
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
16
|
+
};
|
|
17
|
+
warn: {
|
|
18
|
+
(...data: any[]): void;
|
|
19
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
20
|
+
};
|
|
21
|
+
error: {
|
|
22
|
+
(...data: any[]): void;
|
|
23
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
add: (key: string, promiseCallbacks: {
|
|
3
|
+
resolve: (PromiseLike: any) => void;
|
|
4
|
+
reject: (reason?: any) => void;
|
|
5
|
+
}) => void;
|
|
6
|
+
getAll: (key: string) => {
|
|
7
|
+
resolve: (PromiseLike: any) => void;
|
|
8
|
+
reject: (reason?: any) => void;
|
|
9
|
+
}[];
|
|
10
|
+
peekQueueSize: (key: string) => number;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as url from '../utils/url';
|
|
6
|
+
import * as location from '../utils/location';
|
|
7
|
+
import { login } from './authentication';
|
|
8
|
+
import restoreAllMocks = jest.restoreAllMocks;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
restoreAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('authentication', () => {
|
|
15
|
+
describe('goToLoginPage', () => {
|
|
16
|
+
it('should resolve dev env', () => {
|
|
17
|
+
spyOn(url, 'getCurrentEnvironment').and.returnValue('localhost');
|
|
18
|
+
spyOn(location, 'navigateTo');
|
|
19
|
+
login('current');
|
|
20
|
+
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
21
|
+
'https://www.aid.no.localhost.api.no/aid/logg_inn/?requestedUrl=current'
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
it('should resolve snap5 env', () => {
|
|
25
|
+
spyOn(url, 'getCurrentEnvironment').and.returnValue('snap5');
|
|
26
|
+
spyOn(location, 'navigateTo');
|
|
27
|
+
login('current');
|
|
28
|
+
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
29
|
+
'https://www-snap5.aid.no/aid/logg_inn/?requestedUrl=current'
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
it('should resolve prod env', () => {
|
|
33
|
+
spyOn(url, 'getCurrentEnvironment').and.returnValue('');
|
|
34
|
+
spyOn(location, 'navigateTo');
|
|
35
|
+
login('current');
|
|
36
|
+
expect(location.navigateTo).toHaveBeenCalledWith(
|
|
37
|
+
'https://www.aid.no/aid/logg_inn/?requestedUrl=current'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -9,19 +9,23 @@ import {
|
|
|
9
9
|
import log from '../utils/log';
|
|
10
10
|
import { UserAttributes } from '../types';
|
|
11
11
|
import store from '../store';
|
|
12
|
+
import { navigateTo } from '../utils/location';
|
|
12
13
|
|
|
13
14
|
export const login = (requestedUrl: URL | string) => {
|
|
15
|
+
let url = new URL(`https://www.aid.no/aid/logg_inn/`);
|
|
14
16
|
const environment = getCurrentEnvironment();
|
|
15
|
-
|
|
16
|
-
`https://aid.no
|
|
17
|
-
)
|
|
17
|
+
if (environment === 'localhost') {
|
|
18
|
+
url = new URL(`https://www.aid.no.localhost.api.no/aid/logg_inn/`);
|
|
19
|
+
} else if (environment) {
|
|
20
|
+
url = new URL(`https://www-${environment}.aid.no/aid/logg_inn/`);
|
|
21
|
+
}
|
|
18
22
|
url.searchParams.set(
|
|
19
23
|
'requestedUrl',
|
|
20
24
|
requestedUrl instanceof URL
|
|
21
25
|
? requestedUrl.href
|
|
22
26
|
: requestedUrl || window.location.href
|
|
23
27
|
);
|
|
24
|
-
|
|
28
|
+
navigateTo(url.href);
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
function clearCookies() {
|
package/src/utils/location.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export const reload = () =>
|
|
2
|
-
|
|
3
|
-
window.location.reload();
|
|
4
|
-
};
|
|
1
|
+
export const reload = () => window.location.reload();
|
|
2
|
+
|
|
5
3
|
export const replace = (requestedUrl: string) =>
|
|
6
4
|
window.location.replace(requestedUrl);
|
|
5
|
+
|
|
6
|
+
export const navigateTo = (url: string) => {
|
|
7
|
+
window.location.href = url;
|
|
8
|
+
};
|