@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.
- package/dist/user.cjs +15 -0
- package/dist/{index.js.map → user.cjs.map} +3 -3
- package/dist/{index.d.ts → user.d.ts} +12 -0
- package/dist/user.js +15 -0
- package/dist/{index.esm.js.map → user.js.map} +3 -3
- package/package.json +9 -6
- package/.codeclimate.yml +0 -8
- package/.eslintignore +0 -2
- package/.eslintrc +0 -11
- package/.prettierrc.json +0 -1
- package/@types/amedia-frontend-rpc.d.ts +0 -11
- package/@types/browserid.d.ts +0 -4
- package/build.js +0 -28
- package/checkVersion.cjs +0 -12
- package/cloudbuild.json +0 -29
- package/cop.json +0 -8
- package/dist/actions/authentication.d.ts +0 -4
- package/dist/actions/authentication.spec.d.ts +0 -1
- package/dist/actions/authorization.d.ts +0 -14
- package/dist/actions/authorization.spec.d.ts +0 -4
- package/dist/actions/preferences.d.ts +0 -9
- package/dist/actions/preferences.spec.d.ts +0 -1
- package/dist/actions/storage.d.ts +0 -7
- package/dist/actions/userData.d.ts +0 -2
- package/dist/actions/userData.spec.d.ts +0 -1
- package/dist/autologin/index.d.ts +0 -7
- package/dist/autologin/index.spec.d.ts +0 -1
- package/dist/autologin/thirdPartyCookie.d.ts +0 -3
- package/dist/autologin/thirdPartyCookie.spec.d.ts +0 -1
- package/dist/cache/engines/global.d.ts +0 -24
- package/dist/cache/engines/global.spec.d.ts +0 -1
- package/dist/cache/index.d.ts +0 -11
- package/dist/cache/index.spec.d.ts +0 -1
- package/dist/cache/types.d.ts +0 -11
- package/dist/clients/europa.d.ts +0 -24
- package/dist/clients/europa.spec.d.ts +0 -1
- package/dist/clients/jupiter.d.ts +0 -30
- package/dist/clients/jupiter.spec.d.ts +0 -1
- package/dist/clients/mercury.d.ts +0 -3
- package/dist/clients/mercury.spec.d.ts +0 -1
- package/dist/clients/mercuryLog.d.ts +0 -8
- package/dist/clients/mercuryLog.spec.d.ts +0 -1
- package/dist/clients/nebula.d.ts +0 -2
- package/dist/clients/nebula.spec.d.ts +0 -1
- package/dist/clients/pluto.d.ts +0 -4
- package/dist/clients/pluto.spec.d.ts +0 -1
- package/dist/eventHandlers/activation.d.ts +0 -15
- package/dist/eventHandlers/authentication.d.ts +0 -17
- package/dist/eventHandlers/eventMap.d.ts +0 -29
- package/dist/eventHandlers/state.d.ts +0 -1
- package/dist/eventHandlers/state.spec.d.ts +0 -1
- package/dist/eventHandlers/storage.d.ts +0 -1
- package/dist/eventHandlers/storage.spec.d.ts +0 -1
- package/dist/eventHandlers/userAttributes.d.ts +0 -1
- package/dist/eventHandlers/userAttributes.spec.d.ts +0 -1
- package/dist/exceptions/PaywallError.d.ts +0 -8
- package/dist/index-authentcation.spec.d.ts +0 -1
- package/dist/index-storage.spec.d.ts +0 -1
- package/dist/index-subscription.spec.d.ts +0 -1
- package/dist/index.esm.js +0 -15
- package/dist/index.js +0 -15
- package/dist/janitor/index.d.ts +0 -10
- package/dist/janitor/index.spec.d.ts +0 -1
- package/dist/janitor/jobs/accessCookieRefresher.d.ts +0 -1
- package/dist/janitor/jobs/accessCookieRefresher.spec.d.ts +0 -1
- package/dist/janitor/jobs/daxsubCookie.d.ts +0 -3
- package/dist/janitor/jobs/daxsubCookie.spec.d.ts +0 -1
- package/dist/janitor/jobs/removeUserStorage.d.ts +0 -1
- package/dist/janitor/jobs/removeUserStorage.spec.d.ts +0 -1
- package/dist/lib/PaywallUnlockRequest.d.ts +0 -17
- package/dist/lib/PaywallUnlockRequest.spec.d.ts +0 -1
- package/dist/lib/UserDataRequest.d.ts +0 -22
- package/dist/lib/UserDataRequest.spec.d.ts +0 -1
- package/dist/lib/cookie.d.ts +0 -9
- package/dist/lib/rpc.d.ts +0 -6
- package/dist/store/index.d.ts +0 -23
- package/dist/store/index.spec.d.ts +0 -1
- package/dist/types.d.ts +0 -22
- package/dist/utils/customEventWrapper.d.ts +0 -19
- package/dist/utils/debouncer.d.ts +0 -26
- package/dist/utils/debouncer.spec.d.ts +0 -1
- package/dist/utils/deepEquals.d.ts +0 -1
- package/dist/utils/expectBootLogs.d.ts +0 -2
- package/dist/utils/getOrUpdate.d.ts +0 -6
- package/dist/utils/getOrUpdate.spec.d.ts +0 -1
- package/dist/utils/localhostCheck.d.ts +0 -1
- package/dist/utils/location.d.ts +0 -3
- package/dist/utils/log.d.ts +0 -9
- package/dist/utils/log.spec.d.ts +0 -1
- package/dist/utils/loginState.d.ts +0 -2
- package/dist/utils/networkError.d.ts +0 -1
- package/dist/utils/queue.d.ts +0 -12
- package/dist/utils/type.d.ts +0 -6
- package/dist/utils/url.d.ts +0 -6
- package/dist/utils/url.spec.d.ts +0 -1
- package/eik.json +0 -10
- package/global.d.ts +0 -1
- package/jest.config.js +0 -7
- package/setupJest.js +0 -1
- package/src/actions/authentication.spec.ts +0 -51
- package/src/actions/authentication.ts +0 -43
- package/src/actions/authorization.spec.ts +0 -369
- package/src/actions/authorization.ts +0 -117
- 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 -239
- package/src/autologin/index.ts +0 -92
- 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 -48
- package/src/cache/index.spec.ts +0 -130
- 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 -179
- package/src/clients/jupiter.ts +0 -119
- package/src/clients/mercury.spec.ts +0 -59
- package/src/clients/mercury.ts +0 -48
- 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 -165
- package/src/clients/pluto.ts +0 -118
- package/src/eventHandlers/activation.ts +0 -35
- package/src/eventHandlers/authentication.ts +0 -34
- package/src/eventHandlers/eventMap.ts +0 -34
- 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/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 -59
- package/src/janitor/index.spec.ts +0 -18
- package/src/janitor/index.ts +0 -59
- package/src/janitor/jobs/accessCookieRefresher.spec.ts +0 -213
- package/src/janitor/jobs/accessCookieRefresher.ts +0 -98
- 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 -363
- package/src/lib/PaywallUnlockRequest.ts +0 -143
- package/src/lib/UserDataRequest.spec.ts +0 -77
- package/src/lib/UserDataRequest.ts +0 -213
- 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 -64
- package/src/types.ts +0 -22
- package/src/utils/customEventWrapper.ts +0 -58
- 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/getOrUpdate.spec.ts +0 -166
- package/src/utils/getOrUpdate.ts +0 -66
- package/src/utils/localhostCheck.ts +0 -9
- package/src/utils/location.ts +0 -31
- package/src/utils/log.spec.ts +0 -148
- package/src/utils/log.ts +0 -124
- 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 -35
- package/testSetup.js +0 -19
- package/tsconfig.eslint.json +0 -24
- package/tsconfig.json +0 -18
package/src/utils/log.spec.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import log, { Logger, setLogger } from './log';
|
|
2
|
-
|
|
3
|
-
describe('Log', () => {
|
|
4
|
-
let logger: Logger;
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
logger = {
|
|
7
|
-
debug: jest.fn(),
|
|
8
|
-
info: jest.fn(),
|
|
9
|
-
warn: jest.fn(),
|
|
10
|
-
error: jest.fn(),
|
|
11
|
-
};
|
|
12
|
-
setLogger(logger);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
function itShouldLogMessage(message: string, level: keyof Logger = 'error') {
|
|
16
|
-
it('should log message', () => {
|
|
17
|
-
expect(logger[level]).toHaveBeenCalledWith(message, expect.anything());
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function itShouldLogContext(context: Object, level: keyof Logger = 'error') {
|
|
22
|
-
it('should log context', () => {
|
|
23
|
-
expect(logger[level]).toHaveBeenCalledWith(expect.anything(), {
|
|
24
|
-
...context,
|
|
25
|
-
origin: '@amedia/user',
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function expectRewrittenError(message: string) {
|
|
31
|
-
const matcher = new RegExp(`Error: ${message}\n(^\\s+at .+$\\n){3,}`, 'm');
|
|
32
|
-
return {
|
|
33
|
-
message,
|
|
34
|
-
stack: expect.stringMatching(matcher),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe('with stringed message', () => {
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
log.error('Epic fail');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
itShouldLogMessage('Epic fail');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('with all error levels', () => {
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
log.debug('debug');
|
|
49
|
-
log.info('info');
|
|
50
|
-
log.warn('warn');
|
|
51
|
-
log.error('error');
|
|
52
|
-
});
|
|
53
|
-
itShouldLogMessage('debug', 'debug');
|
|
54
|
-
itShouldLogMessage('info', 'info');
|
|
55
|
-
itShouldLogMessage('warn', 'warn');
|
|
56
|
-
itShouldLogMessage('error', 'error');
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('with stringed message and context', () => {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
log.error('Epic fail', {
|
|
62
|
-
my: 'context',
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
itShouldLogMessage('Epic fail');
|
|
66
|
-
itShouldLogContext({
|
|
67
|
-
my: 'context',
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('with stringed message and complex context', () => {
|
|
72
|
-
beforeEach(() => {
|
|
73
|
-
log.error('Epic fail', {
|
|
74
|
-
my: 'context',
|
|
75
|
-
more: {
|
|
76
|
-
nested: 'context',
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
itShouldLogMessage('Epic fail');
|
|
81
|
-
itShouldLogContext({
|
|
82
|
-
my: 'context',
|
|
83
|
-
more: {
|
|
84
|
-
nested: 'context',
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('with Error as message', () => {
|
|
90
|
-
beforeEach(() => {
|
|
91
|
-
log.error(new Error('Epic fail'));
|
|
92
|
-
});
|
|
93
|
-
itShouldLogMessage('Epic fail');
|
|
94
|
-
itShouldLogContext({
|
|
95
|
-
error: expectRewrittenError('Epic fail'),
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('with Error as message and context', () => {
|
|
100
|
-
beforeEach(() => {
|
|
101
|
-
log.error(new Error('Epic fail'), {
|
|
102
|
-
my: 'context',
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
itShouldLogMessage('Epic fail');
|
|
106
|
-
itShouldLogContext({
|
|
107
|
-
my: 'context',
|
|
108
|
-
error: expectRewrittenError('Epic fail'),
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('with message as string and Errors in context', () => {
|
|
113
|
-
beforeEach(() => {
|
|
114
|
-
log.error('Epic fail', {
|
|
115
|
-
failError: new Error('Much fail'),
|
|
116
|
-
boomError: new Error('Very boom'),
|
|
117
|
-
my: 'context',
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
itShouldLogMessage('Epic fail');
|
|
121
|
-
itShouldLogContext({
|
|
122
|
-
my: 'context',
|
|
123
|
-
failError: expectRewrittenError('Much fail'),
|
|
124
|
-
boomError: expectRewrittenError('Very boom'),
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('with Error directly as context', () => {
|
|
129
|
-
beforeEach(() => {
|
|
130
|
-
log.error('Epic fail', new Error('Downhill from here'));
|
|
131
|
-
});
|
|
132
|
-
itShouldLogMessage('Epic fail');
|
|
133
|
-
itShouldLogContext({
|
|
134
|
-
error: expectRewrittenError('Downhill from here'),
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('with Error both at message and context', () => {
|
|
139
|
-
beforeEach(() => {
|
|
140
|
-
log.error(new Error('Epic fail'), new Error('Downhill from here'));
|
|
141
|
-
});
|
|
142
|
-
itShouldLogMessage('Epic fail');
|
|
143
|
-
itShouldLogContext({
|
|
144
|
-
error: expectRewrittenError('Epic fail'),
|
|
145
|
-
contextError: expectRewrittenError('Downhill from here'),
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
package/src/utils/log.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import mercury from '../clients/mercuryLog';
|
|
2
|
-
|
|
3
|
-
export type Logger = {
|
|
4
|
-
debug: (message: string | Error, context?: any) => void;
|
|
5
|
-
info: (message: string | Error, context?: any) => void;
|
|
6
|
-
warn: (message: string | Error, context?: any) => void;
|
|
7
|
-
error: (message: string | Error, context?: any) => void;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
let logger: Logger;
|
|
11
|
-
|
|
12
|
-
export const setLogger = (engine: Logger) => {
|
|
13
|
-
logger = engine;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const getLogger = () => logger || mercury;
|
|
17
|
-
|
|
18
|
-
const rewriteErrorObject = (
|
|
19
|
-
error: Error
|
|
20
|
-
): { [key: string]: unknown } & { message: string } => {
|
|
21
|
-
const rewrittenError: any = {
|
|
22
|
-
message: error.message,
|
|
23
|
-
};
|
|
24
|
-
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
rewrittenError[key] = error[key];
|
|
27
|
-
});
|
|
28
|
-
return rewrittenError;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const rewriteResponseObject = async (
|
|
32
|
-
response: Response
|
|
33
|
-
): Promise<
|
|
34
|
-
{ [key: string]: unknown } & {
|
|
35
|
-
url: string;
|
|
36
|
-
status: number;
|
|
37
|
-
statusText: string;
|
|
38
|
-
body: string;
|
|
39
|
-
}
|
|
40
|
-
> => {
|
|
41
|
-
const responseText = !response.bodyUsed
|
|
42
|
-
? await response.text()
|
|
43
|
-
: 'Response body not available for logging';
|
|
44
|
-
const rewrittenResponseObject: any = {
|
|
45
|
-
url: response.url,
|
|
46
|
-
status: response.status,
|
|
47
|
-
statusText: response.statusText,
|
|
48
|
-
body: responseText,
|
|
49
|
-
};
|
|
50
|
-
Object.getOwnPropertyNames(response).forEach((key) => {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
rewrittenResponseObject[key] = response[key];
|
|
53
|
-
});
|
|
54
|
-
return rewrittenResponseObject;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function isError(param: any): param is Error {
|
|
58
|
-
return param && param instanceof Error;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function isResponse(param: any): param is Response {
|
|
62
|
-
return param && param instanceof Response;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const processIncomingLogData = async (
|
|
66
|
-
message: string | Error,
|
|
67
|
-
context: any = {}
|
|
68
|
-
): Promise<{ message: string; context: any }> => {
|
|
69
|
-
let internalMessage = message;
|
|
70
|
-
let internalContext = context || {};
|
|
71
|
-
if (internalMessage instanceof Error) {
|
|
72
|
-
const rewrittenErrorObject = rewriteErrorObject(internalMessage);
|
|
73
|
-
internalMessage = rewrittenErrorObject.message;
|
|
74
|
-
internalContext = { ...internalContext, error: rewrittenErrorObject };
|
|
75
|
-
}
|
|
76
|
-
internalContext = { ...internalContext, origin: '@amedia/user' };
|
|
77
|
-
if (context instanceof Error) {
|
|
78
|
-
const parsedContextError = rewriteErrorObject(context);
|
|
79
|
-
internalContext = {
|
|
80
|
-
...internalContext,
|
|
81
|
-
...{
|
|
82
|
-
[Object.keys(internalContext).includes('error')
|
|
83
|
-
? 'contextError'
|
|
84
|
-
: 'error']: parsedContextError,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
} else if (internalContext instanceof Response) {
|
|
88
|
-
const rewritten = await rewriteResponseObject(internalContext);
|
|
89
|
-
internalContext = { ...internalContext, response: rewritten };
|
|
90
|
-
} else {
|
|
91
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
92
|
-
for (const key of Object.keys(internalContext)) {
|
|
93
|
-
const currentInternalContext = internalContext[key];
|
|
94
|
-
if (isError(currentInternalContext)) {
|
|
95
|
-
internalContext[key] = rewriteErrorObject(currentInternalContext);
|
|
96
|
-
} else if (isResponse(currentInternalContext)) {
|
|
97
|
-
// eslint-disable-next-line no-await-in-loop
|
|
98
|
-
const rewritten = await rewriteResponseObject(currentInternalContext);
|
|
99
|
-
internalContext[key] = rewritten;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
message: internalMessage,
|
|
105
|
-
context: internalContext,
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const processAndLog = (
|
|
110
|
-
level: keyof Logger,
|
|
111
|
-
message: string | Error,
|
|
112
|
-
context?: any
|
|
113
|
-
) => {
|
|
114
|
-
processIncomingLogData(message, context).then(({ message: m, context: c }) =>
|
|
115
|
-
getLogger()[level](m, c)
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export default <Logger>{
|
|
120
|
-
debug: (message, context) => processAndLog('debug', message, context),
|
|
121
|
-
info: (message, context) => processAndLog('info', message, context),
|
|
122
|
-
warn: (message, context) => processAndLog('warn', message, context),
|
|
123
|
-
error: (message, context) => processAndLog('error', message, context),
|
|
124
|
-
};
|
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
|
-
getCurrentPublicationDomain,
|
|
4
|
-
setCurrentHostname,
|
|
5
|
-
} from './url';
|
|
6
|
-
|
|
7
|
-
describe('URL utils', () => {
|
|
8
|
-
it('should get proper publication 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(getCurrentPublicationDomain()).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,35 +0,0 @@
|
|
|
1
|
-
let overriddenHostname: string;
|
|
2
|
-
export const setCurrentHostname = (hostname: string) => {
|
|
3
|
-
overriddenHostname = hostname;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export const getCurrentHostname = (): string =>
|
|
7
|
-
overriddenHostname || globalThis.location.hostname;
|
|
8
|
-
|
|
9
|
-
export const getCurrentUrl = (): string => globalThis.location.href;
|
|
10
|
-
|
|
11
|
-
export const getCurrentEnvironment = () => {
|
|
12
|
-
const matchBed = /^bed-([^.]+)\.api\.no$/.exec(getCurrentHostname());
|
|
13
|
-
const match = /\.([^.]+)\.api\.no/.exec(getCurrentHostname());
|
|
14
|
-
if (matchBed) {
|
|
15
|
-
return matchBed[1];
|
|
16
|
-
}
|
|
17
|
-
if (match) {
|
|
18
|
-
return match[1];
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const getCurrentPublicationDomain = () =>
|
|
24
|
-
getCurrentHostname().replace(/\.[^.]+\.api\.no/, '');
|
|
25
|
-
|
|
26
|
-
export const getAidDomain = (): string => {
|
|
27
|
-
const environment = getCurrentEnvironment();
|
|
28
|
-
let domain = 'www.aid.no';
|
|
29
|
-
if (environment === 'localhost') {
|
|
30
|
-
domain = 'www.aid.no.localhost.api.no';
|
|
31
|
-
} else if (environment) {
|
|
32
|
-
domain = `www-${environment}.aid.no`;
|
|
33
|
-
}
|
|
34
|
-
return domain;
|
|
35
|
-
};
|
package/testSetup.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require('jest-extended');
|
|
2
|
-
const fetchMocker = require('jest-fetch-mock');
|
|
3
|
-
const localhostCheck = require('./src/utils/localhostCheck');
|
|
4
|
-
const { setLogger } = require('./src/utils/log');
|
|
5
|
-
const { setRootElement } = require('./src/utils/customEventWrapper');
|
|
6
|
-
|
|
7
|
-
setLogger(console);
|
|
8
|
-
self.amediaUserTestMode = true;
|
|
9
|
-
|
|
10
|
-
fetchMocker.enableMocks();
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
fetchMocker.resetMocks();
|
|
14
|
-
jest.spyOn(localhostCheck, 'isRunningOnLocalhost').mockReturnValue(false);
|
|
15
|
-
|
|
16
|
-
// We cannot use window/globalThis as our event root during testing
|
|
17
|
-
// since tests are executed in parallel.
|
|
18
|
-
setRootElement(new Document().createElement('div'));
|
|
19
|
-
});
|
package/tsconfig.eslint.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@amedia/eslint-config-typescript/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"typeRoots": [
|
|
7
|
-
"./@types",
|
|
8
|
-
"./node_modules/@types"
|
|
9
|
-
],
|
|
10
|
-
"noImplicitAny": true,
|
|
11
|
-
"module": "ES6",
|
|
12
|
-
"lib": [
|
|
13
|
-
"DOM"
|
|
14
|
-
],
|
|
15
|
-
"declaration": true
|
|
16
|
-
},
|
|
17
|
-
"exclude": [
|
|
18
|
-
"node_modules",
|
|
19
|
-
"config",
|
|
20
|
-
],
|
|
21
|
-
"include": [
|
|
22
|
-
"src/**/*",
|
|
23
|
-
]
|
|
24
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@amedia/eslint-config-typescript/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"noImplicitAny": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"emitDeclarationOnly": true,
|
|
9
|
-
"typeRoots": [
|
|
10
|
-
"./@types",
|
|
11
|
-
"./node_modules/@types"
|
|
12
|
-
],
|
|
13
|
-
"lib": [
|
|
14
|
-
"DOM"
|
|
15
|
-
],
|
|
16
|
-
"module": "ES2020"
|
|
17
|
-
}
|
|
18
|
-
}
|