@amedia/user 0.14.18 → 0.14.20

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 (85) hide show
  1. package/package.json +2 -3
  2. package/src/actions/authentication.spec.ts +0 -51
  3. package/src/actions/authentication.ts +0 -49
  4. package/src/actions/authorization.spec.ts +0 -377
  5. package/src/actions/authorization.ts +0 -120
  6. package/src/actions/preferences.spec.ts +0 -41
  7. package/src/actions/preferences.ts +0 -41
  8. package/src/actions/storage.ts +0 -22
  9. package/src/actions/userData.spec.ts +0 -133
  10. package/src/actions/userData.ts +0 -68
  11. package/src/autologin/index.spec.ts +0 -264
  12. package/src/autologin/index.ts +0 -113
  13. package/src/autologin/thirdPartyCookie.spec.ts +0 -95
  14. package/src/autologin/thirdPartyCookie.ts +0 -55
  15. package/src/cache/engines/global.spec.ts +0 -62
  16. package/src/cache/engines/global.ts +0 -49
  17. package/src/cache/index.spec.ts +0 -132
  18. package/src/cache/index.ts +0 -48
  19. package/src/cache/types.ts +0 -12
  20. package/src/clients/europa.spec.ts +0 -209
  21. package/src/clients/europa.ts +0 -183
  22. package/src/clients/jupiter.spec.ts +0 -178
  23. package/src/clients/jupiter.ts +0 -119
  24. package/src/clients/mercury.spec.ts +0 -126
  25. package/src/clients/mercury.ts +0 -105
  26. package/src/clients/mercuryLog.spec.ts +0 -20
  27. package/src/clients/mercuryLog.ts +0 -67
  28. package/src/clients/nebula.spec.ts +0 -70
  29. package/src/clients/nebula.ts +0 -83
  30. package/src/clients/pluto.spec.ts +0 -262
  31. package/src/clients/pluto.ts +0 -126
  32. package/src/eventHandlers/activation.ts +0 -40
  33. package/src/eventHandlers/authentication.ts +0 -34
  34. package/src/eventHandlers/eventMap.ts +0 -40
  35. package/src/eventHandlers/navigation.spec.ts +0 -189
  36. package/src/eventHandlers/navigation.ts +0 -58
  37. package/src/eventHandlers/state.spec.ts +0 -48
  38. package/src/eventHandlers/state.ts +0 -23
  39. package/src/eventHandlers/storage.spec.ts +0 -114
  40. package/src/eventHandlers/storage.ts +0 -45
  41. package/src/eventHandlers/userAttributes.spec.ts +0 -93
  42. package/src/eventHandlers/userAttributes.ts +0 -31
  43. package/src/exceptions/FetchTimeoutError.ts +0 -8
  44. package/src/exceptions/PaywallError.ts +0 -16
  45. package/src/index-authentcation.spec.ts +0 -26
  46. package/src/index-storage.spec.ts +0 -144
  47. package/src/index-subscription.spec.ts +0 -213
  48. package/src/index.ts +0 -46
  49. package/src/janitor/index.spec.ts +0 -18
  50. package/src/janitor/index.ts +0 -60
  51. package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
  52. package/src/janitor/jobs/accessCookieRefresher.ts +0 -96
  53. package/src/janitor/jobs/daxsubCookie.spec.ts +0 -109
  54. package/src/janitor/jobs/daxsubCookie.ts +0 -38
  55. package/src/janitor/jobs/removeUserStorage.spec.ts +0 -34
  56. package/src/janitor/jobs/removeUserStorage.ts +0 -12
  57. package/src/lib/PaywallUnlockRequest.spec.ts +0 -446
  58. package/src/lib/PaywallUnlockRequest.ts +0 -161
  59. package/src/lib/UserDataRequest.spec.ts +0 -231
  60. package/src/lib/UserDataRequest.ts +0 -267
  61. package/src/lib/cookie.ts +0 -121
  62. package/src/lib/rpc.ts +0 -19
  63. package/src/store/index.spec.ts +0 -49
  64. package/src/store/index.ts +0 -66
  65. package/src/types.ts +0 -22
  66. package/src/utils/customEventWrapper.spec.ts +0 -237
  67. package/src/utils/customEventWrapper.ts +0 -77
  68. package/src/utils/debouncer.spec.ts +0 -252
  69. package/src/utils/debouncer.ts +0 -123
  70. package/src/utils/deepEquals.ts +0 -42
  71. package/src/utils/expectBootLogs.ts +0 -9
  72. package/src/utils/getGlobalThis.ts +0 -17
  73. package/src/utils/getOrUpdate.spec.ts +0 -166
  74. package/src/utils/getOrUpdate.ts +0 -66
  75. package/src/utils/localhostCheck.ts +0 -10
  76. package/src/utils/location.spec.ts +0 -61
  77. package/src/utils/location.ts +0 -16
  78. package/src/utils/log.spec.ts +0 -177
  79. package/src/utils/log.ts +0 -112
  80. package/src/utils/loginState.ts +0 -24
  81. package/src/utils/networkError.ts +0 -11
  82. package/src/utils/queue.ts +0 -32
  83. package/src/utils/type.ts +0 -19
  84. package/src/utils/url.spec.ts +0 -33
  85. package/src/utils/url.ts +0 -37
package/src/utils/log.ts DELETED
@@ -1,112 +0,0 @@
1
- import mercury from '../clients/mercuryLog';
2
- // @ts-ignore
3
- import { version } from '../../eik.json';
4
-
5
- export type Logger = {
6
- debug: (message: string | Error, context?: any) => void;
7
- info: (message: string | Error, context?: any) => void;
8
- warn: (message: string | Error, context?: any) => void;
9
- error: (message: string | Error, context?: any) => void;
10
- };
11
-
12
- let logger: Logger;
13
-
14
- export const setLogger = (engine: Logger) => {
15
- logger = engine;
16
- };
17
-
18
- const getLogger = () => logger || mercury;
19
-
20
- const rewriteErrorObject = (
21
- error: Error
22
- ): { [key: string]: unknown } & { message: string } => {
23
- const rewrittenError: any = {
24
- message: error.message,
25
- };
26
- Object.getOwnPropertyNames(error).forEach((key) => {
27
- rewrittenError[key] = error[key as keyof typeof error];
28
- });
29
- return rewrittenError;
30
- };
31
-
32
- const rewriteResponseObject = async (
33
- response: Response
34
- ): Promise<Record<string, unknown>> => {
35
- const responseText = !response.bodyUsed
36
- ? await response.text()
37
- : 'Response body not available for logging';
38
- const headers: Record<string, string> = {};
39
- response.headers.forEach((value, key) => {
40
- headers[key] = value;
41
- });
42
- return {
43
- url: response.url,
44
- status: response.status,
45
- statusText: response.statusText,
46
- headers,
47
- body: responseText,
48
- };
49
- };
50
-
51
- function isError(param: any): param is Error {
52
- return param && param instanceof Error;
53
- }
54
-
55
- function isResponse(param: any): param is Response {
56
- return param && param instanceof Response;
57
- }
58
-
59
- const processIncomingLogData = async (
60
- message: string | Error,
61
- context: any = {}
62
- ): Promise<{ message: string; context: any }> => {
63
- const internalMessage: string =
64
- typeof message === 'string' ? message : message.message;
65
- const internalContext: Record<string, unknown> = {
66
- origin: '@amedia/user',
67
- originVersion: version,
68
- };
69
- if (message instanceof Error) {
70
- internalContext.error = rewriteErrorObject(message);
71
- }
72
-
73
- if (context instanceof Error) {
74
- internalContext[
75
- Object.keys(internalContext).includes('error') ? 'contextError' : 'error'
76
- ] = rewriteErrorObject(context);
77
- } else if (context instanceof Response) {
78
- internalContext.response = await rewriteResponseObject(context);
79
- } else {
80
- Object.keys(context).forEach((key) => {
81
- const currentContext = context[key];
82
- if (isError(currentContext)) {
83
- internalContext[key] = rewriteErrorObject(currentContext);
84
- } else if (isResponse(currentContext)) {
85
- internalContext[key] = rewriteResponseObject(currentContext);
86
- } else {
87
- internalContext[key] = currentContext;
88
- }
89
- });
90
- }
91
- return {
92
- message: internalMessage,
93
- context: internalContext,
94
- };
95
- };
96
-
97
- const processAndLog = (
98
- level: keyof Logger,
99
- message: string | Error,
100
- context?: any
101
- ) => {
102
- processIncomingLogData(message, context).then(({ message: m, context: c }) =>
103
- getLogger()[level](m, c)
104
- );
105
- };
106
-
107
- export default <Logger>{
108
- debug: (message, context) => processAndLog('debug', message, context),
109
- info: (message, context) => processAndLog('info', message, context),
110
- warn: (message, context) => processAndLog('warn', message, context),
111
- error: (message, context) => processAndLog('error', message, context),
112
- };
@@ -1,24 +0,0 @@
1
- import store from '../store';
2
-
3
- export const whenLoginStateResolved = (): Promise<boolean> =>
4
- new Promise((resolve) => {
5
- const currentLoggedInState = store.get('state')?.isLoggedIn;
6
- if (currentLoggedInState === false || currentLoggedInState === true) {
7
- resolve(currentLoggedInState);
8
- return;
9
- }
10
- store.on('state', ({ isLoggedIn }) => {
11
- if (isLoggedIn === false || isLoggedIn === true) {
12
- resolve(isLoggedIn);
13
- }
14
- });
15
- });
16
-
17
- export const whenIsLoggedIn = (): Promise<void> =>
18
- new Promise((resolve) =>
19
- whenLoginStateResolved().then((isLoggedIn) => {
20
- if (isLoggedIn) {
21
- resolve();
22
- }
23
- })
24
- );
@@ -1,11 +0,0 @@
1
- const ABORTED_WORDS = [
2
- 'avbrutt',
3
- 'kansellert',
4
- 'cancelled',
5
- 'aborted',
6
- 'failed to fetch',
7
- 'abgebrochen',
8
- 'the operation was aborted.',
9
- ];
10
- export const isAbortedNetworkError = (message: string) =>
11
- ABORTED_WORDS.includes(message.toLowerCase().trim());
@@ -1,32 +0,0 @@
1
- const queue: {
2
- [key: string]: {
3
- resolve: (arg0?: any) => void;
4
- reject: (reason?: any) => void;
5
- }[];
6
- } = {};
7
-
8
- const add = (
9
- key: string,
10
- promiseCallbacks: {
11
- resolve: (arg0?: any) => void;
12
- reject: (reason?: any) => void;
13
- }
14
- ): void => {
15
- if (!queue[key]) {
16
- queue[key] = [];
17
- }
18
- queue[key].push(promiseCallbacks);
19
- };
20
-
21
- const getAll = (key: string) => {
22
- const keyQueue = queue[key];
23
- if (!keyQueue) {
24
- return [];
25
- }
26
- delete queue[key];
27
- return keyQueue;
28
- };
29
-
30
- const peekQueueSize = (key: string): number => queue[key]?.length || 0;
31
-
32
- export default { add, getAll, peekQueueSize };
package/src/utils/type.ts DELETED
@@ -1,19 +0,0 @@
1
- export const isFunction = (argument: unknown): argument is Function =>
2
- !!argument && typeof argument === 'function';
3
-
4
- export const isRecord = (
5
- argument: unknown
6
- ): argument is Record<string, unknown> =>
7
- !!argument && typeof argument === 'object';
8
-
9
- export const isError = (argument: unknown): argument is Error =>
10
- !!argument && argument instanceof Error;
11
-
12
- export const isString = (argument: unknown): argument is string =>
13
- !!argument && typeof argument === 'string';
14
-
15
- export const isNumber = (argument: unknown): argument is number =>
16
- !!argument && typeof argument === 'number';
17
-
18
- export const isBoolean = (argument: unknown): argument is boolean =>
19
- !!argument && typeof argument === 'boolean';
@@ -1,33 +0,0 @@
1
- import {
2
- getCurrentEnvironment,
3
- getCurrentSiteDomain,
4
- setCurrentHostname,
5
- } from './url';
6
-
7
- describe('URL utils', () => {
8
- it('should get proper site domain', () => {
9
- const domains = [
10
- 'www.telen.no.localhost.api.no',
11
- 'www.telen.no.snap5.api.no',
12
- 'www.telen.no',
13
- ];
14
- expect.assertions(domains.length);
15
- domains.forEach((domain) => {
16
- setCurrentHostname(domain);
17
- expect(getCurrentSiteDomain()).toEqual('www.telen.no');
18
- });
19
- });
20
-
21
- it('should get current environment', () => {
22
- const domains = {
23
- 'www.telen.no.localhost.api.no': 'localhost',
24
- 'www.telen.no.snap5.api.no': 'snap5',
25
- 'www.telen.no': null,
26
- };
27
- expect.assertions(Object.keys(domains).length);
28
- Object.entries(domains).forEach(([domain, expectedEnvironment]) => {
29
- setCurrentHostname(domain);
30
- expect(getCurrentEnvironment()).toEqual(expectedEnvironment);
31
- });
32
- });
33
- });
package/src/utils/url.ts DELETED
@@ -1,37 +0,0 @@
1
- import getGlobalThis from './getGlobalThis';
2
-
3
- let overriddenHostname: string;
4
- export const setCurrentHostname = (hostname: string) => {
5
- overriddenHostname = hostname;
6
- };
7
-
8
- export const getCurrentHostname = (): string =>
9
- overriddenHostname || getGlobalThis().location.hostname;
10
-
11
- export const getCurrentUrl = (): string => getGlobalThis().location.href;
12
-
13
- export const getCurrentEnvironment = () => {
14
- const matchBed = /^bed-([^.]+)\.api\.no$/.exec(getCurrentHostname());
15
- const match = /\.([^.]+)\.api\.no/.exec(getCurrentHostname());
16
- if (matchBed) {
17
- return matchBed[1];
18
- }
19
- if (match) {
20
- return match[1];
21
- }
22
- return null;
23
- };
24
-
25
- export const getCurrentSiteDomain = () =>
26
- getCurrentHostname().replace(/\.[^.]+\.api\.no/, '');
27
-
28
- export const getAidDomain = (): string => {
29
- const environment = getCurrentEnvironment();
30
- let domain = 'www.aid.no';
31
- if (environment === 'localhost') {
32
- domain = 'www.aid.no.localhost.api.no';
33
- } else if (environment) {
34
- domain = `www-${environment}.aid.no`;
35
- }
36
- return domain;
37
- };