@amedia/user 0.13.34 → 0.13.36

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 (180) hide show
  1. package/dist/user.cjs +15 -0
  2. package/dist/{index.js.map → user.cjs.map} +3 -3
  3. package/dist/{index.d.ts → user.d.ts} +12 -0
  4. package/dist/user.js +15 -0
  5. package/dist/{index.esm.js.map → user.js.map} +3 -3
  6. package/package.json +9 -6
  7. package/.codeclimate.yml +0 -8
  8. package/.eslintignore +0 -2
  9. package/.eslintrc +0 -11
  10. package/.prettierrc.json +0 -1
  11. package/@types/amedia-frontend-rpc.d.ts +0 -11
  12. package/@types/browserid.d.ts +0 -4
  13. package/build.js +0 -28
  14. package/checkVersion.cjs +0 -12
  15. package/cloudbuild.json +0 -29
  16. package/cop.json +0 -8
  17. package/dist/actions/authentication.d.ts +0 -4
  18. package/dist/actions/authentication.spec.d.ts +0 -1
  19. package/dist/actions/authorization.d.ts +0 -14
  20. package/dist/actions/authorization.spec.d.ts +0 -4
  21. package/dist/actions/preferences.d.ts +0 -9
  22. package/dist/actions/preferences.spec.d.ts +0 -1
  23. package/dist/actions/storage.d.ts +0 -7
  24. package/dist/actions/userData.d.ts +0 -2
  25. package/dist/actions/userData.spec.d.ts +0 -1
  26. package/dist/autologin/index.d.ts +0 -7
  27. package/dist/autologin/index.spec.d.ts +0 -1
  28. package/dist/autologin/thirdPartyCookie.d.ts +0 -3
  29. package/dist/autologin/thirdPartyCookie.spec.d.ts +0 -1
  30. package/dist/cache/engines/global.d.ts +0 -24
  31. package/dist/cache/engines/global.spec.d.ts +0 -1
  32. package/dist/cache/index.d.ts +0 -11
  33. package/dist/cache/index.spec.d.ts +0 -1
  34. package/dist/cache/types.d.ts +0 -11
  35. package/dist/clients/europa.d.ts +0 -24
  36. package/dist/clients/europa.spec.d.ts +0 -1
  37. package/dist/clients/jupiter.d.ts +0 -30
  38. package/dist/clients/jupiter.spec.d.ts +0 -1
  39. package/dist/clients/mercury.d.ts +0 -3
  40. package/dist/clients/mercury.spec.d.ts +0 -1
  41. package/dist/clients/mercuryLog.d.ts +0 -8
  42. package/dist/clients/mercuryLog.spec.d.ts +0 -1
  43. package/dist/clients/nebula.d.ts +0 -2
  44. package/dist/clients/nebula.spec.d.ts +0 -1
  45. package/dist/clients/pluto.d.ts +0 -4
  46. package/dist/clients/pluto.spec.d.ts +0 -1
  47. package/dist/eventHandlers/activation.d.ts +0 -15
  48. package/dist/eventHandlers/authentication.d.ts +0 -17
  49. package/dist/eventHandlers/eventMap.d.ts +0 -29
  50. package/dist/eventHandlers/state.d.ts +0 -1
  51. package/dist/eventHandlers/state.spec.d.ts +0 -1
  52. package/dist/eventHandlers/storage.d.ts +0 -1
  53. package/dist/eventHandlers/storage.spec.d.ts +0 -1
  54. package/dist/eventHandlers/userAttributes.d.ts +0 -1
  55. package/dist/eventHandlers/userAttributes.spec.d.ts +0 -1
  56. package/dist/exceptions/PaywallError.d.ts +0 -8
  57. package/dist/index-authentcation.spec.d.ts +0 -1
  58. package/dist/index-storage.spec.d.ts +0 -1
  59. package/dist/index-subscription.spec.d.ts +0 -1
  60. package/dist/index.esm.js +0 -15
  61. package/dist/index.js +0 -15
  62. package/dist/janitor/index.d.ts +0 -10
  63. package/dist/janitor/index.spec.d.ts +0 -1
  64. package/dist/janitor/jobs/accessCookieRefresher.d.ts +0 -1
  65. package/dist/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -1
  66. package/dist/janitor/jobs/daxsubCookie.d.ts +0 -3
  67. package/dist/janitor/jobs/daxsubCookie.spec.d.ts +0 -1
  68. package/dist/janitor/jobs/removeUserStorage.d.ts +0 -1
  69. package/dist/janitor/jobs/removeUserStorage.spec.d.ts +0 -1
  70. package/dist/lib/PaywallUnlockRequest.d.ts +0 -17
  71. package/dist/lib/PaywallUnlockRequest.spec.d.ts +0 -1
  72. package/dist/lib/UserDataRequest.d.ts +0 -22
  73. package/dist/lib/UserDataRequest.spec.d.ts +0 -1
  74. package/dist/lib/cookie.d.ts +0 -9
  75. package/dist/lib/rpc.d.ts +0 -6
  76. package/dist/store/index.d.ts +0 -23
  77. package/dist/store/index.spec.d.ts +0 -1
  78. package/dist/types.d.ts +0 -22
  79. package/dist/utils/customEventWrapper.d.ts +0 -19
  80. package/dist/utils/debouncer.d.ts +0 -26
  81. package/dist/utils/debouncer.spec.d.ts +0 -1
  82. package/dist/utils/deepEquals.d.ts +0 -1
  83. package/dist/utils/expectBootLogs.d.ts +0 -2
  84. package/dist/utils/getOrUpdate.d.ts +0 -6
  85. package/dist/utils/getOrUpdate.spec.d.ts +0 -1
  86. package/dist/utils/localhostCheck.d.ts +0 -1
  87. package/dist/utils/location.d.ts +0 -3
  88. package/dist/utils/log.d.ts +0 -9
  89. package/dist/utils/log.spec.d.ts +0 -1
  90. package/dist/utils/loginState.d.ts +0 -2
  91. package/dist/utils/networkError.d.ts +0 -1
  92. package/dist/utils/queue.d.ts +0 -12
  93. package/dist/utils/type.d.ts +0 -6
  94. package/dist/utils/url.d.ts +0 -6
  95. package/dist/utils/url.spec.d.ts +0 -1
  96. package/eik.json +0 -10
  97. package/global.d.ts +0 -1
  98. package/jest.config.js +0 -7
  99. package/setupJest.js +0 -1
  100. package/src/actions/authentication.spec.ts +0 -51
  101. package/src/actions/authentication.ts +0 -43
  102. package/src/actions/authorization.spec.ts +0 -369
  103. package/src/actions/authorization.ts +0 -117
  104. package/src/actions/preferences.spec.ts +0 -41
  105. package/src/actions/preferences.ts +0 -41
  106. package/src/actions/storage.ts +0 -22
  107. package/src/actions/userData.spec.ts +0 -133
  108. package/src/actions/userData.ts +0 -68
  109. package/src/autologin/index.spec.ts +0 -239
  110. package/src/autologin/index.ts +0 -92
  111. package/src/autologin/thirdPartyCookie.spec.ts +0 -95
  112. package/src/autologin/thirdPartyCookie.ts +0 -55
  113. package/src/cache/engines/global.spec.ts +0 -62
  114. package/src/cache/engines/global.ts +0 -48
  115. package/src/cache/index.spec.ts +0 -130
  116. package/src/cache/index.ts +0 -48
  117. package/src/cache/types.ts +0 -12
  118. package/src/clients/europa.spec.ts +0 -209
  119. package/src/clients/europa.ts +0 -183
  120. package/src/clients/jupiter.spec.ts +0 -179
  121. package/src/clients/jupiter.ts +0 -119
  122. package/src/clients/mercury.spec.ts +0 -59
  123. package/src/clients/mercury.ts +0 -48
  124. package/src/clients/mercuryLog.spec.ts +0 -20
  125. package/src/clients/mercuryLog.ts +0 -67
  126. package/src/clients/nebula.spec.ts +0 -70
  127. package/src/clients/nebula.ts +0 -83
  128. package/src/clients/pluto.spec.ts +0 -165
  129. package/src/clients/pluto.ts +0 -118
  130. package/src/eventHandlers/activation.ts +0 -35
  131. package/src/eventHandlers/authentication.ts +0 -34
  132. package/src/eventHandlers/eventMap.ts +0 -34
  133. package/src/eventHandlers/state.spec.ts +0 -48
  134. package/src/eventHandlers/state.ts +0 -23
  135. package/src/eventHandlers/storage.spec.ts +0 -114
  136. package/src/eventHandlers/storage.ts +0 -45
  137. package/src/eventHandlers/userAttributes.spec.ts +0 -93
  138. package/src/eventHandlers/userAttributes.ts +0 -31
  139. package/src/exceptions/PaywallError.ts +0 -16
  140. package/src/index-authentcation.spec.ts +0 -26
  141. package/src/index-storage.spec.ts +0 -144
  142. package/src/index-subscription.spec.ts +0 -213
  143. package/src/index.ts +0 -59
  144. package/src/janitor/index.spec.ts +0 -18
  145. package/src/janitor/index.ts +0 -59
  146. package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
  147. package/src/janitor/jobs/accessCookieRefresher.ts +0 -98
  148. package/src/janitor/jobs/daxsubCookie.spec.ts +0 -109
  149. package/src/janitor/jobs/daxsubCookie.ts +0 -38
  150. package/src/janitor/jobs/removeUserStorage.spec.ts +0 -34
  151. package/src/janitor/jobs/removeUserStorage.ts +0 -12
  152. package/src/lib/PaywallUnlockRequest.spec.ts +0 -363
  153. package/src/lib/PaywallUnlockRequest.ts +0 -143
  154. package/src/lib/UserDataRequest.spec.ts +0 -77
  155. package/src/lib/UserDataRequest.ts +0 -213
  156. package/src/lib/cookie.ts +0 -121
  157. package/src/lib/rpc.ts +0 -19
  158. package/src/store/index.spec.ts +0 -49
  159. package/src/store/index.ts +0 -64
  160. package/src/types.ts +0 -22
  161. package/src/utils/customEventWrapper.ts +0 -58
  162. package/src/utils/debouncer.spec.ts +0 -252
  163. package/src/utils/debouncer.ts +0 -123
  164. package/src/utils/deepEquals.ts +0 -42
  165. package/src/utils/expectBootLogs.ts +0 -9
  166. package/src/utils/getOrUpdate.spec.ts +0 -166
  167. package/src/utils/getOrUpdate.ts +0 -66
  168. package/src/utils/localhostCheck.ts +0 -9
  169. package/src/utils/location.ts +0 -31
  170. package/src/utils/log.spec.ts +0 -148
  171. package/src/utils/log.ts +0 -124
  172. package/src/utils/loginState.ts +0 -24
  173. package/src/utils/networkError.ts +0 -11
  174. package/src/utils/queue.ts +0 -32
  175. package/src/utils/type.ts +0 -19
  176. package/src/utils/url.spec.ts +0 -33
  177. package/src/utils/url.ts +0 -35
  178. package/testSetup.js +0 -19
  179. package/tsconfig.eslint.json +0 -24
  180. package/tsconfig.json +0 -18
@@ -1,22 +0,0 @@
1
- import { State, UserAttributes } from '../types';
2
- declare class UserDataRequest<UA extends UserAttributes, S extends {
3
- [index: string]: unknown;
4
- }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, object> = {
5
- state: State;
6
- }> {
7
- private attributes?;
8
- private namespaces?;
9
- constructor(attributes?: Attributes | undefined, namespaces?: Namespaces | undefined);
10
- withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): UserDataRequest<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
11
- attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
12
- }>;
13
- withStorage<NewNamespaces extends Array<string>>(namespaces: NewNamespaces): UserDataRequest<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
14
- storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
15
- }>;
16
- subscribe(onData: (data: SubscribeResponse) => void): void;
17
- fetch(): Promise<SubscribeResponse>;
18
- private processUserAttributesEvent;
19
- private processStorageEvent;
20
- private setupLocalCache;
21
- }
22
- export default UserDataRequest;
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- export declare const getCookie: (name: string) => string | {
2
- [index: string]: unknown;
3
- } | null | undefined;
4
- export declare function setCookie(name: string, value?: unknown, validTimeInDateOrDays?: Date | number, path?: string, secure?: boolean): string;
5
- export declare function removeCookie(name: string): void;
6
- /**
7
- * This function should only be used in tests, as it will remove all cookies a user has on the domain.
8
- */
9
- export declare function removeAllCookies(): void;
package/dist/lib/rpc.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { RPCclient } from '@amedia/frontend-rpc';
2
- interface LocalRPCclient extends RPCclient {
3
- userAuthenticated: (isLoggedIn: boolean) => void;
4
- }
5
- export declare const getRPCClient: () => LocalRPCclient;
6
- export {};
@@ -1,23 +0,0 @@
1
- import { State, UserAttributes } from '../types';
2
- declare type StoreDataMap = {
3
- userAttributes: UserAttributes;
4
- state: State;
5
- storage: {
6
- [namespace: string]: {
7
- [index: string]: unknown;
8
- };
9
- };
10
- };
11
- declare type Listener<T> = (data: T) => void;
12
- declare const _default: {
13
- merge: <K extends keyof StoreDataMap>(key: K, value: Partial<StoreDataMap[K]>) => void;
14
- set: (key: keyof StoreDataMap, value: UserAttributes | State | {
15
- [namespace: string]: {
16
- [index: string]: unknown;
17
- };
18
- }) => void;
19
- get: <K_1 extends keyof StoreDataMap, T = StoreDataMap[K_1]>(key: K_1) => T | undefined;
20
- on: <K_2 extends keyof StoreDataMap, T_1 = StoreDataMap[K_2]>(key: K_2, listener: Listener<T_1>) => void;
21
- clear: () => void;
22
- };
23
- export default _default;
@@ -1 +0,0 @@
1
- export {};
package/dist/types.d.ts DELETED
@@ -1,22 +0,0 @@
1
- export declare type UserAttributes = {
2
- uuid?: string | null;
3
- name?: string | null;
4
- email?: string | null;
5
- phone?: string | null;
6
- trackingKey?: string | null;
7
- extraData?: {
8
- [index: string]: unknown;
9
- };
10
- access?: string[];
11
- privacyPreferences?: PrivacyPreferences | null;
12
- };
13
- export declare type State = {
14
- isLoggedIn: boolean;
15
- emergencyMode?: string[];
16
- };
17
- export declare type PrivacyPreferences = {
18
- allowResearchUsage: boolean;
19
- connectWithSurveys: boolean;
20
- personalizedAds: boolean;
21
- personalizedContent: boolean;
22
- };
@@ -1,19 +0,0 @@
1
- declare let rootElement: Window | Element | typeof globalThis;
2
- export declare const setRootElement: (element: typeof rootElement) => void;
3
- /**
4
- * This listener MUST be used by all listeners in ../eventHandlers
5
- * We want to ensure that only _one_ instance of this package actually
6
- * orchestrates data and performs requests against backends.
7
- * @param type
8
- * @param listener
9
- */
10
- export declare const listenWithExclusivity: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
11
- /**
12
- * Use this for response listeners. (../index.ts) where we want
13
- * all updates with data - no matter who sent the actual request
14
- * @param type
15
- * @param listener
16
- */
17
- export declare const listenForAllEvents: <T extends keyof WindowEventMap>(type: T, listener: (this: typeof rootElement, ev: WindowEventMap[T]) => void) => void;
18
- export declare const dispatch: <T extends Event>(event: T) => void;
19
- export {};
@@ -1,26 +0,0 @@
1
- /**
2
- * The Debouncer can be used when we want a clean way to say 'I want to fetch this and that, and once it's done,
3
- * resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
4
- * request other stuff. This will keep us from performing lots of individual fetches to the backend.
5
- *
6
- * Our main use case is a standard publication front page where one component on the page requests the euucp namespace
7
- * from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
8
- * calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
9
- * aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
10
- * to both components will be both namespaces (which the Europa client can filter before it actually reaches the
11
- * component).
12
- */
13
- declare class Debouncer<ParamsType, ResultType> {
14
- private timeoutMs;
15
- private defaultParams;
16
- private paramAccumulator;
17
- private workload;
18
- private timer;
19
- private params;
20
- private queue;
21
- constructor(timeoutMs: number, defaultParams: ParamsType, paramAccumulator: (previousParams: ParamsType, newParams: ParamsType) => ParamsType, workload: (params: ParamsType) => Promise<ResultType>);
22
- perform(newParams: ParamsType): Promise<ResultType>;
23
- static stringListParamsAccumulator(accumulatedParams: string[], newParams: string[]): string[];
24
- static stringMapParamsAccumulator(previousParams: Record<string, any>, newParams: Record<string, any>): Record<string, any>;
25
- }
26
- export default Debouncer;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const deepEquals: (a: unknown, b: unknown) => boolean;
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,6 +0,0 @@
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>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const isRunningOnLocalhost: () => boolean;
@@ -1,3 +0,0 @@
1
- export declare const reload: () => void;
2
- export declare const replace: (requestedUrl: string) => void;
3
- export declare const navigateTo: (url: string) => void;
@@ -1,9 +0,0 @@
1
- export declare type Logger = {
2
- debug: (message: string | Error, context?: any) => void;
3
- info: (message: string | Error, context?: any) => void;
4
- warn: (message: string | Error, context?: any) => void;
5
- error: (message: string | Error, context?: any) => void;
6
- };
7
- export declare const setLogger: (engine: Logger) => void;
8
- declare const _default: Logger;
9
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export declare const whenLoginStateResolved: () => Promise<boolean>;
2
- export declare const whenIsLoggedIn: () => Promise<void>;
@@ -1 +0,0 @@
1
- export declare const isAbortedNetworkError: (message: string) => boolean;
@@ -1,12 +0,0 @@
1
- declare const _default: {
2
- add: (key: string, promiseCallbacks: {
3
- resolve: (arg0?: any) => void;
4
- reject: (reason?: any) => void;
5
- }) => void;
6
- getAll: (key: string) => {
7
- resolve: (arg0?: any) => void;
8
- reject: (reason?: any) => void;
9
- }[];
10
- peekQueueSize: (key: string) => number;
11
- };
12
- export default _default;
@@ -1,6 +0,0 @@
1
- export declare const isFunction: (argument: unknown) => argument is Function;
2
- export declare const isRecord: (argument: unknown) => argument is Record<string, unknown>;
3
- export declare const isError: (argument: unknown) => argument is Error;
4
- export declare const isString: (argument: unknown) => argument is string;
5
- export declare const isNumber: (argument: unknown) => argument is number;
6
- export declare const isBoolean: (argument: unknown) => argument is boolean;
@@ -1,6 +0,0 @@
1
- export declare const setCurrentHostname: (hostname: string) => void;
2
- export declare const getCurrentHostname: () => string;
3
- export declare const getCurrentUrl: () => string;
4
- export declare const getCurrentEnvironment: () => string | null;
5
- export declare const getCurrentPublicationDomain: () => string;
6
- export declare const getAidDomain: () => string;
@@ -1 +0,0 @@
1
- export {};
package/eik.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@amedia/user",
3
- "version": "0.13.34",
4
- "server": "https://assets.acdn.no",
5
- "files": {
6
- "user.js": "./dist/index.esm.js",
7
- "user.js.map": "./dist/index.esm.js.map",
8
- "user.d.ts": "./dist/index.d.ts"
9
- }
10
- }
package/global.d.ts DELETED
@@ -1 +0,0 @@
1
- import 'jest-extended';
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- export default {
2
- preset: 'ts-jest',
3
- testEnvironment: 'jsdom',
4
- restoreMocks: true,
5
- setupFilesAfterEnv: ['./testSetup.js'],
6
- setupFiles: ['./setupJest.js'],
7
- };
package/setupJest.js DELETED
@@ -1 +0,0 @@
1
- self = global || window;
@@ -1,51 +0,0 @@
1
- import * as url from '../utils/url';
2
- import * as location from '../utils/location';
3
- import { login } from './authentication';
4
-
5
- beforeEach(() => {
6
- spyOn(url, 'getCurrentUrl').and.returnValue('https://www.telen.no/artikkel/');
7
- spyOn(url, 'getCurrentPublicationDomain').and.returnValue('www.telen.no');
8
- spyOn(location, 'navigateTo');
9
- });
10
-
11
- describe('authentication', () => {
12
- describe('goToLoginPage', () => {
13
- describe('when using URL or string for param', () => {
14
- it('should return expected url for string', () => {
15
- login('https://my.url/');
16
- expect(location.navigateTo).toHaveBeenCalledWith(
17
- 'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=https%3A%2F%2Fmy.url%2F'
18
- );
19
- });
20
- it('should return expected url for URL', () => {
21
- login(new URL('https://my.url'));
22
- expect(location.navigateTo).toHaveBeenCalledWith(
23
- 'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=https%3A%2F%2Fmy.url%2F'
24
- );
25
- });
26
- });
27
- describe('when changing environment', () => {
28
- it('should resolve dev env', () => {
29
- spyOn(url, 'getCurrentEnvironment').and.returnValue('localhost');
30
- login('current');
31
- expect(location.navigateTo).toHaveBeenCalledWith(
32
- 'https://www.aid.no.localhost.api.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
33
- );
34
- });
35
- it('should resolve snap5 env', () => {
36
- spyOn(url, 'getCurrentEnvironment').and.returnValue('snap5');
37
- login('current');
38
- expect(location.navigateTo).toHaveBeenCalledWith(
39
- 'https://www-snap5.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
40
- );
41
- });
42
- it('should resolve prod env', () => {
43
- spyOn(url, 'getCurrentEnvironment').and.returnValue('');
44
- login('current');
45
- expect(location.navigateTo).toHaveBeenCalledWith(
46
- 'https://www.aid.no/aid/logg_inn/www.telen.no/?requestedUrl=current'
47
- );
48
- });
49
- });
50
- });
51
- });
@@ -1,43 +0,0 @@
1
- import { getCurrentSession, removeSession } from '../clients/pluto';
2
- import cache from '../cache';
3
- import { getRPCClient } from '../lib/rpc';
4
- import { removeCookie } from '../lib/cookie';
5
- import { getAidDomain, getCurrentPublicationDomain } from '../utils/url';
6
- import log from '../utils/log';
7
- import { UserAttributes } from '../types';
8
- import { navigateTo } from '../utils/location';
9
-
10
- export const login = (requestedUrl: URL | string) => {
11
- const url = new URL(
12
- `https://${getAidDomain()}/aid/logg_inn/${getCurrentPublicationDomain()}/`
13
- );
14
- url.searchParams.set(
15
- 'requestedUrl',
16
- requestedUrl instanceof URL ? requestedUrl.href : requestedUrl
17
- );
18
- navigateTo(url.href);
19
- };
20
-
21
- function clearCookies() {
22
- removeCookie('VSTOKEN');
23
- removeCookie('aid.session');
24
- removeCookie('aid_invitation_code');
25
- removeCookie('aid-reload-article');
26
- removeCookie('daxsub');
27
- }
28
-
29
- export const logout = async () =>
30
- // TODO: It now clears the entire cache. Might be too aggressive.
31
- Promise.all([removeSession(getCurrentPublicationDomain()), cache.clear()])
32
- .then(() => {
33
- // TODO This should be separated from logout and instead be setup to listen on state changes on storage
34
- getRPCClient().userAuthenticated(false);
35
- clearCookies();
36
- // In addition to removing the regular cookies we also want to remove VSTOKEN2 on explicit logout
37
- removeCookie('VSTOKEN2');
38
- })
39
- .catch((reason) => {
40
- log.error('Failure while logging out', reason);
41
- });
42
-
43
- export const getSession = (): Promise<UserAttributes> => getCurrentSession();