@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.
Files changed (55) hide show
  1. package/dist/actions/authentication.spec.d.ts +4 -0
  2. package/dist/index.js +1 -1
  3. package/dist/utils/location.d.ts +1 -0
  4. package/esm/actions/authentication.d.ts +5 -0
  5. package/esm/actions/authorization.d.ts +7 -0
  6. package/esm/actions/preferences.d.ts +9 -0
  7. package/esm/actions/preferences.spec.d.ts +1 -0
  8. package/esm/actions/storage.d.ts +1 -0
  9. package/esm/actions/userData.d.ts +2 -0
  10. package/esm/cache/engines/global.d.ts +21 -0
  11. package/esm/cache/engines/global.spec.d.ts +1 -0
  12. package/esm/cache/engines/indexeddb.d.ts +7 -0
  13. package/esm/cache/index.d.ts +11 -0
  14. package/esm/cache/index.spec.d.ts +4 -0
  15. package/esm/cache/types.d.ts +11 -0
  16. package/esm/clients/europa.d.ts +28 -0
  17. package/esm/clients/europa.spec.d.ts +1 -0
  18. package/esm/clients/jupiter.d.ts +30 -0
  19. package/esm/clients/jupiter.spec.d.ts +1 -0
  20. package/esm/clients/mercury.d.ts +18 -0
  21. package/esm/clients/mercury.spec.d.ts +4 -0
  22. package/esm/clients/nebula.d.ts +2 -0
  23. package/esm/clients/nebula.spec.d.ts +1 -0
  24. package/esm/clients/pluto.d.ts +3 -0
  25. package/esm/clients/pluto.spec.d.ts +1 -0
  26. package/esm/eventHandlers/activation.d.ts +15 -0
  27. package/esm/eventHandlers/authentication.d.ts +17 -0
  28. package/esm/eventHandlers/userAttributes.d.ts +20 -0
  29. package/esm/exceptions/PaywallError.d.ts +7 -0
  30. package/esm/index-authentcation.spec.d.ts +4 -0
  31. package/esm/index-subscription.spec.d.ts +4 -0
  32. package/esm/index.d.ts +23 -0
  33. package/esm/lib/PaywallUnlocker.d.ts +16 -0
  34. package/esm/lib/PaywallUnlocker.spec.d.ts +4 -0
  35. package/esm/lib/User.d.ts +21 -0
  36. package/esm/lib/cookie.d.ts +5 -0
  37. package/esm/lib/rpc.d.ts +6 -0
  38. package/esm/store/index.d.ts +22 -0
  39. package/esm/store/index.spec.d.ts +1 -0
  40. package/esm/types.d.ts +21 -0
  41. package/esm/user.js +1 -6498
  42. package/esm/user.js.map +1 -1
  43. package/esm/utils/customEventWrapper.d.ts +17 -0
  44. package/esm/utils/deepEquals.d.ts +4 -0
  45. package/esm/utils/getOrUpdate.d.ts +6 -0
  46. package/esm/utils/getOrUpdate.spec.d.ts +1 -0
  47. package/esm/utils/location.d.ts +2 -0
  48. package/esm/utils/log.d.ts +26 -0
  49. package/esm/utils/queue.d.ts +12 -0
  50. package/esm/utils/url.d.ts +3 -0
  51. package/esm/utils/url.spec.d.ts +1 -0
  52. package/package.json +1 -1
  53. package/src/actions/authentication.spec.ts +41 -0
  54. package/src/actions/authentication.ts +8 -4
  55. 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,4 @@
1
+ /**
2
+ * @see https://dev.to/sanderdebr/deep-equality-checking-of-objects-in-vanilla-javascript-5592
3
+ */
4
+ export declare const deepEquals: (a: unknown, b: unknown) => boolean;
@@ -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,2 @@
1
+ export declare const reload: () => void;
2
+ export declare const replace: (requestedUrl: string) => void;
@@ -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,3 @@
1
+ export declare const setCurrentHostname: (hostname: string) => void;
2
+ export declare const getCurrentEnvironment: () => string | null;
3
+ export declare const getCurrentPublicationDomain: () => string;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Client lib for working with aID user and associated data",
5
5
  "repository": "https://github.com/amedia/amedia-user-js",
6
6
  "author": "Amedia Utvikling (ID og data)",
@@ -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
- const url = new URL(
16
- `https://aid.no${environment && `.${environment}.api.no`}/aid/logg_inn/`
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
- window.location.href = url.href;
28
+ navigateTo(url.href);
25
29
  };
26
30
 
27
31
  function clearCookies() {
@@ -1,6 +1,8 @@
1
- export const reload = () => {
2
- console.trace('hi');
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
+ };