@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.
- package/package.json +2 -3
- package/src/actions/authentication.spec.ts +0 -51
- package/src/actions/authentication.ts +0 -49
- package/src/actions/authorization.spec.ts +0 -377
- package/src/actions/authorization.ts +0 -120
- package/src/actions/preferences.spec.ts +0 -41
- package/src/actions/preferences.ts +0 -41
- package/src/actions/storage.ts +0 -22
- package/src/actions/userData.spec.ts +0 -133
- package/src/actions/userData.ts +0 -68
- package/src/autologin/index.spec.ts +0 -264
- package/src/autologin/index.ts +0 -113
- package/src/autologin/thirdPartyCookie.spec.ts +0 -95
- package/src/autologin/thirdPartyCookie.ts +0 -55
- package/src/cache/engines/global.spec.ts +0 -62
- package/src/cache/engines/global.ts +0 -49
- package/src/cache/index.spec.ts +0 -132
- package/src/cache/index.ts +0 -48
- package/src/cache/types.ts +0 -12
- package/src/clients/europa.spec.ts +0 -209
- package/src/clients/europa.ts +0 -183
- package/src/clients/jupiter.spec.ts +0 -178
- package/src/clients/jupiter.ts +0 -119
- package/src/clients/mercury.spec.ts +0 -126
- package/src/clients/mercury.ts +0 -105
- package/src/clients/mercuryLog.spec.ts +0 -20
- package/src/clients/mercuryLog.ts +0 -67
- package/src/clients/nebula.spec.ts +0 -70
- package/src/clients/nebula.ts +0 -83
- package/src/clients/pluto.spec.ts +0 -262
- package/src/clients/pluto.ts +0 -126
- package/src/eventHandlers/activation.ts +0 -40
- package/src/eventHandlers/authentication.ts +0 -34
- package/src/eventHandlers/eventMap.ts +0 -40
- package/src/eventHandlers/navigation.spec.ts +0 -189
- package/src/eventHandlers/navigation.ts +0 -58
- package/src/eventHandlers/state.spec.ts +0 -48
- package/src/eventHandlers/state.ts +0 -23
- package/src/eventHandlers/storage.spec.ts +0 -114
- package/src/eventHandlers/storage.ts +0 -45
- package/src/eventHandlers/userAttributes.spec.ts +0 -93
- package/src/eventHandlers/userAttributes.ts +0 -31
- package/src/exceptions/FetchTimeoutError.ts +0 -8
- package/src/exceptions/PaywallError.ts +0 -16
- package/src/index-authentcation.spec.ts +0 -26
- package/src/index-storage.spec.ts +0 -144
- package/src/index-subscription.spec.ts +0 -213
- package/src/index.ts +0 -46
- package/src/janitor/index.spec.ts +0 -18
- package/src/janitor/index.ts +0 -60
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
- package/src/janitor/jobs/accessCookieRefresher.ts +0 -96
- package/src/janitor/jobs/daxsubCookie.spec.ts +0 -109
- package/src/janitor/jobs/daxsubCookie.ts +0 -38
- package/src/janitor/jobs/removeUserStorage.spec.ts +0 -34
- package/src/janitor/jobs/removeUserStorage.ts +0 -12
- package/src/lib/PaywallUnlockRequest.spec.ts +0 -446
- package/src/lib/PaywallUnlockRequest.ts +0 -161
- package/src/lib/UserDataRequest.spec.ts +0 -231
- package/src/lib/UserDataRequest.ts +0 -267
- package/src/lib/cookie.ts +0 -121
- package/src/lib/rpc.ts +0 -19
- package/src/store/index.spec.ts +0 -49
- package/src/store/index.ts +0 -66
- package/src/types.ts +0 -22
- package/src/utils/customEventWrapper.spec.ts +0 -237
- package/src/utils/customEventWrapper.ts +0 -77
- package/src/utils/debouncer.spec.ts +0 -252
- package/src/utils/debouncer.ts +0 -123
- package/src/utils/deepEquals.ts +0 -42
- package/src/utils/expectBootLogs.ts +0 -9
- package/src/utils/getGlobalThis.ts +0 -17
- package/src/utils/getOrUpdate.spec.ts +0 -166
- package/src/utils/getOrUpdate.ts +0 -66
- package/src/utils/localhostCheck.ts +0 -10
- package/src/utils/location.spec.ts +0 -61
- package/src/utils/location.ts +0 -16
- package/src/utils/log.spec.ts +0 -177
- package/src/utils/log.ts +0 -112
- package/src/utils/loginState.ts +0 -24
- package/src/utils/networkError.ts +0 -11
- package/src/utils/queue.ts +0 -32
- package/src/utils/type.ts +0 -19
- package/src/utils/url.spec.ts +0 -33
- 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
|
-
};
|
package/src/utils/loginState.ts
DELETED
|
@@ -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());
|
package/src/utils/queue.ts
DELETED
|
@@ -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';
|
package/src/utils/url.spec.ts
DELETED
|
@@ -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
|
-
};
|