@amedia/user 0.6.0 → 0.7.0

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 (87) hide show
  1. package/.codeclimate.yml +7 -0
  2. package/cloudbuild.json +1 -1
  3. package/dist/index.d.ts +6 -17
  4. package/dist/index.js +7 -2
  5. package/dist/lib/authentication.d.ts +17 -0
  6. package/dist/lib/authentication.js +74 -0
  7. package/dist/lib/authorization.d.ts +14 -0
  8. package/dist/lib/authorization.js +51 -0
  9. package/dist/{cache/engines/indexeddb.d.ts → lib/cache/db.d.ts} +2 -3
  10. package/dist/lib/cache/db.js +13 -0
  11. package/dist/lib/cache/global.d.ts +9 -0
  12. package/dist/lib/cache/global.js +16 -0
  13. package/dist/lib/cache/types.d.ts +5 -0
  14. package/dist/lib/cache/types.js +2 -0
  15. package/dist/lib/queue.d.ts +5 -0
  16. package/dist/lib/queue.js +17 -0
  17. package/dist/lib/tools.d.ts +1 -0
  18. package/dist/lib/tools.js +2 -0
  19. package/dist/lib/user.d.ts +2 -0
  20. package/dist/lib/user.js +3 -0
  21. package/dist/services/cache.d.ts +9 -0
  22. package/dist/services/cache.js +34 -0
  23. package/dist/services/jupiter.d.ts +4 -4
  24. package/dist/services/jupiter.js +72 -0
  25. package/dist/services/pluto.d.ts +10 -6
  26. package/dist/services/pluto.js +40 -0
  27. package/package.json +2 -1
  28. package/src/actions/authentication.ts +5 -38
  29. package/src/actions/userData.ts +15 -19
  30. package/src/clients/europa.ts +5 -9
  31. package/src/clients/jupiter.spec.ts +5 -5
  32. package/src/clients/jupiter.ts +28 -22
  33. package/src/clients/nebula.spec.ts +11 -11
  34. package/src/clients/nebula.ts +33 -10
  35. package/src/clients/pluto.spec.ts +6 -3
  36. package/src/clients/pluto.ts +26 -16
  37. package/src/eventHandlers/userAttributes.ts +15 -8
  38. package/src/{index-userdata.spec.ts → index-subscription.spec.ts} +49 -57
  39. package/src/store/{store.spec.ts → index.spec.ts} +1 -1
  40. package/src/store/{store.ts → index.ts} +11 -6
  41. package/src/types.ts +1 -1
  42. package/src/utils/getOrUpdate.ts +12 -11
  43. package/dist/actions/authentication.d.ts +0 -4
  44. package/dist/actions/authorization.d.ts +0 -3
  45. package/dist/actions/preferences.d.ts +0 -9
  46. package/dist/actions/preferences.spec.d.ts +0 -1
  47. package/dist/actions/userData.d.ts +0 -2
  48. package/dist/cache/engines/global.d.ts +0 -21
  49. package/dist/cache/engines/global.spec.d.ts +0 -1
  50. package/dist/cache/index.d.ts +0 -11
  51. package/dist/cache/index.spec.d.ts +0 -4
  52. package/dist/cache/types.d.ts +0 -11
  53. package/dist/clients/europa.d.ts +0 -12
  54. package/dist/clients/europa.spec.d.ts +0 -1
  55. package/dist/clients/jupiter.d.ts +0 -29
  56. package/dist/clients/jupiter.spec.d.ts +0 -1
  57. package/dist/clients/mercury.d.ts +0 -18
  58. package/dist/clients/mercury.spec.d.ts +0 -4
  59. package/dist/clients/nebula.d.ts +0 -22
  60. package/dist/clients/nebula.spec.d.ts +0 -1
  61. package/dist/clients/pluto.d.ts +0 -8
  62. package/dist/clients/pluto.spec.d.ts +0 -1
  63. package/dist/eventHandlers/activation.d.ts +0 -15
  64. package/dist/eventHandlers/authentication.d.ts +0 -17
  65. package/dist/eventHandlers/userAttributes.d.ts +0 -14
  66. package/dist/index-authentcation.spec.d.ts +0 -4
  67. package/dist/index-userdata.spec.d.ts +0 -4
  68. package/dist/index.js.LICENSE.txt +0 -8
  69. package/dist/lib/cookie.d.ts +0 -5
  70. package/dist/lib/rpc.d.ts +0 -6
  71. package/dist/services/europa.d.ts +0 -12
  72. package/dist/services/europa.spec.d.ts +0 -1
  73. package/dist/services/jupiter.spec.d.ts +0 -1
  74. package/dist/services/mercury.d.ts +0 -18
  75. package/dist/services/mercury.spec.d.ts +0 -4
  76. package/dist/services/nebula.d.ts +0 -22
  77. package/dist/services/nebula.spec.d.ts +0 -1
  78. package/dist/services/pluto.spec.d.ts +0 -1
  79. package/dist/store/store.d.ts +0 -13
  80. package/dist/store/store.spec.d.ts +0 -1
  81. package/dist/types.d.ts +0 -22
  82. package/dist/utils/customEventWrapper.d.ts +0 -17
  83. package/dist/utils/getOrUpdate.d.ts +0 -3
  84. package/dist/utils/log.d.ts +0 -26
  85. package/dist/utils/queue.d.ts +0 -12
  86. package/dist/utils/url.d.ts +0 -3
  87. package/dist/utils/url.spec.d.ts +0 -1
@@ -8,6 +8,8 @@ import {
8
8
  Boolean,
9
9
  } from 'runtypes';
10
10
  import log from '../utils/log';
11
+ import getOrUpdate from '../utils/getOrUpdate';
12
+ import { UserAttributes } from '../types';
11
13
 
12
14
  const InfoSchema = Dictionary(Unknown, String).And(
13
15
  Partial({
@@ -30,22 +32,43 @@ const InfoSchema = Dictionary(Unknown, String).And(
30
32
  })
31
33
  );
32
34
 
33
- export type Info = Static<typeof InfoSchema>;
34
-
35
- export const getInfo = (
36
- userKey: string,
35
+ const getNebulaData = (
37
36
  publicationDomain: string,
38
- browserId: string
39
- ): Promise<Info> =>
40
- fetch(
41
- `https://services.gcloud.api.no/api/nebula/v1/info?user_key=${userKey}&domain=${publicationDomain}&browser_id=${browserId}`
42
- )
37
+ browserId: string,
38
+ trackingKey?: string
39
+ ) => {
40
+ const url = new URL('https://services.gcloud.api.no/api/nebula/v1/info');
41
+ url.searchParams.set('domain', publicationDomain);
42
+ url.searchParams.set('browser_id', browserId);
43
+ if (trackingKey) {
44
+ url.searchParams.set('user_key', trackingKey);
45
+ }
46
+ return fetch(url.toString())
43
47
  .then((response) => response.json())
44
48
  .then((json) => {
45
49
  try {
46
- return InfoSchema.check(json);
50
+ return {
51
+ ttl: 1000 * 60 * 60 * 5, // Cache 5 mins
52
+ data: InfoSchema.check(json),
53
+ };
47
54
  } catch (error) {
48
55
  log.error('Invalid schema', error);
49
56
  throw error;
50
57
  }
51
58
  });
59
+ };
60
+
61
+ const mapNebulaToUserData = (
62
+ data: Static<typeof InfoSchema>
63
+ ): Pick<UserAttributes, 'extraData'> => ({
64
+ extraData: data,
65
+ });
66
+
67
+ export const getInfo = (
68
+ publicationDomain: string,
69
+ browserId: string,
70
+ userKey?: string
71
+ ): Promise<Pick<UserAttributes, 'extraData'>> =>
72
+ getOrUpdate('getNebulaInfo', InfoSchema, () =>
73
+ getNebulaData(publicationDomain, browserId, userKey)
74
+ ).then(mapNebulaToUserData);
@@ -1,14 +1,16 @@
1
1
  import fetch from 'jest-fetch-mock';
2
+ import cache from '../cache';
2
3
  import { getCurrentSession, removeSession } from './pluto';
3
4
 
4
5
  fetch.enableMocks();
5
6
 
6
- beforeEach(() => {
7
+ beforeEach(async () => {
7
8
  fetch.resetMocks();
9
+ await cache.clear();
8
10
  });
9
11
 
10
12
  describe('Pluto service', () => {
11
- it('getCurrentSession() should return session data', () => {
13
+ it('getCurrentSession() should return session data', async () => {
12
14
  const data = {
13
15
  created_at:
14
16
  'Wed Apr 28 2021 16:02:04 GMT+0200 (Central European Summer Time)',
@@ -20,7 +22,8 @@ describe('Pluto service', () => {
20
22
  };
21
23
  fetch.mockResponseOnce(JSON.stringify(data));
22
24
 
23
- expect(getCurrentSession()).resolves.toEqual({
25
+ const currentSession = await getCurrentSession();
26
+ expect(currentSession).toEqual({
24
27
  name: 'Earl Hickey',
25
28
  trackingKey: 'some tracking key',
26
29
  });
@@ -1,47 +1,57 @@
1
1
  import { Record, Static, String } from 'runtypes';
2
2
  import log from '../utils/log';
3
+ import getOrUpdate from '../utils/getOrUpdate';
4
+ import store from '../store';
5
+ import { UserAttributes } from '../types';
3
6
 
4
7
  const ServiceSessionSchema = Record({
5
8
  user_name: String,
6
9
  tracking_key: String,
7
10
  });
8
11
 
9
- export const InternalSessionSchema = Record({
10
- name: String,
11
- trackingKey: String,
12
- });
13
-
14
- // eslint-disable-next-line @typescript-eslint/no-redeclare
15
- export type Session = Static<typeof InternalSessionSchema>;
16
-
17
- const mapSession = (session: Static<typeof ServiceSessionSchema>): Session => ({
12
+ const mapSessionToUserAttributes = (
13
+ session: Static<typeof ServiceSessionSchema>
14
+ ): UserAttributes => ({
18
15
  name: session.user_name,
19
16
  trackingKey: session.tracking_key,
20
17
  });
21
18
 
22
- export const getCurrentSession = async (): Promise<Session> =>
19
+ const fetchCurrentSession = () =>
23
20
  fetch(`/api/pluto/v1/sessions/current`)
24
21
  .then((response) => {
25
22
  if (!response.ok) {
26
23
  if (response.status === 403) {
27
- return Promise.reject();
24
+ store.set('state', { isLoggedIn: false });
25
+ return {};
28
26
  }
29
- // TODO Handle this.
30
- throw new Error(
31
- `Request not ok (${response.status}: ${response.statusText}).`
27
+ log.error(
28
+ `Unknown error (${response.status}: ${response.statusText}) when fetching current session`,
29
+ { response }
32
30
  );
31
+ return Promise.reject();
33
32
  }
33
+ store.set('state', { isLoggedIn: true });
34
34
  return response.json();
35
35
  })
36
36
  .then((json) => {
37
37
  try {
38
- return mapSession(ServiceSessionSchema.check(json));
38
+ return {
39
+ ttl: 10000,
40
+ data: ServiceSessionSchema.check(json),
41
+ };
39
42
  } catch (error) {
40
43
  log.error('Invalid schema', error);
41
44
  throw error;
42
45
  }
43
46
  });
44
47
 
48
+ export const getCurrentSession = async (): Promise<UserAttributes> =>
49
+ getOrUpdate(
50
+ 'getCurrentSession',
51
+ ServiceSessionSchema,
52
+ fetchCurrentSession
53
+ ).then(mapSessionToUserAttributes);
54
+
45
55
  export const removeSession = async (domain: string) =>
46
56
  fetch(`/api/pluto/v1/sessions/current?publication_domain=${domain}`, {
47
57
  method: 'DELETE',
@@ -55,5 +65,5 @@ export const removeSession = async (domain: string) =>
55
65
  `Error, could not perform deleteRequest. Status: ${res.status} Text: ${res.statusText}`
56
66
  );
57
67
  }
58
- // TODO Update state isLoggedIn
68
+ store.set('state', { isLoggedIn: false });
59
69
  });
@@ -1,6 +1,7 @@
1
- import { fetchDataBasedOnAttributes } from '../actions/userData';
1
+ import { requestAttributes } from '../actions/userData';
2
2
  import { dispatch, listenWithExclusivity } from '../utils/customEventWrapper';
3
3
  import { State, UserAttributes } from '../types';
4
+ import store from '../store';
4
5
 
5
6
  export enum AmediaUserEvents {
6
7
  REQUEST_USER_ATTRIBUTES = 'amedia-user.request-user-attributes',
@@ -19,14 +20,20 @@ declare global {
19
20
  }
20
21
 
21
22
  export const listenForUserAttributeRequests = () => {
23
+ store.on('userAttributes', (user) => {
24
+ dispatch(
25
+ new CustomEvent(AmediaUserEvents.ON_ATTRIBUTES_UPDATED, {
26
+ detail: user,
27
+ })
28
+ );
29
+ });
30
+ store.on('state', (state) => {
31
+ dispatch(
32
+ new CustomEvent(AmediaUserEvents.ON_STATE_UPDATED, { detail: state })
33
+ );
34
+ });
22
35
  listenWithExclusivity(AmediaUserEvents.REQUEST_USER_ATTRIBUTES, (evt) => {
23
- fetchDataBasedOnAttributes(evt.detail, (attributes) => {
24
- dispatch(
25
- new CustomEvent(AmediaUserEvents.ON_ATTRIBUTES_UPDATED, {
26
- detail: attributes,
27
- })
28
- );
29
- });
36
+ requestAttributes(evt.detail);
30
37
  });
31
38
  };
32
39
 
@@ -6,6 +6,7 @@ import { subscribeToUserAttributes } from './index';
6
6
  import * as userData from './actions/userData';
7
7
  import { setRootElement } from './utils/customEventWrapper';
8
8
  import { listenForUserAttributeRequests } from './eventHandlers/userAttributes';
9
+ import store from './store';
9
10
 
10
11
  beforeEach(() => {
11
12
  jest.resetAllMocks();
@@ -14,6 +15,9 @@ beforeEach(() => {
14
15
  // since tests are executed in parallel.
15
16
  setRootElement(new Document());
16
17
 
18
+ // Store must be cleared before we re-listen for user attribute requests
19
+ store.clear();
20
+
17
21
  // Also, since we keep creating new root elements, we also
18
22
  // need to attach to these new roots.
19
23
  listenForUserAttributeRequests();
@@ -21,13 +25,9 @@ beforeEach(() => {
21
25
 
22
26
  describe('Public endpoint - userdata', () => {
23
27
  it('should alert about user data', () => {
24
- jest
25
- .spyOn(userData, 'fetchDataBasedOnAttributes')
26
- .mockImplementation((_, callback: Function) => {
27
- callback({
28
- name: 'Donald Duck',
29
- });
30
- });
28
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
29
+ store.set('userAttributes', { name: 'Donald Duck' });
30
+ });
31
31
 
32
32
  const onUserUpdate = jest.fn();
33
33
  subscribeToUserAttributes(['name'], onUserUpdate);
@@ -38,13 +38,9 @@ describe('Public endpoint - userdata', () => {
38
38
  });
39
39
 
40
40
  it('should not alert on same data', () => {
41
- jest
42
- .spyOn(userData, 'fetchDataBasedOnAttributes')
43
- .mockImplementation((_, callback: Function) => {
44
- callback({
45
- name: 'Donald Duck',
46
- });
47
- });
41
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
42
+ store.set('userAttributes', { name: 'Donald Duck' });
43
+ });
48
44
 
49
45
  const onUserUpdate1 = jest.fn();
50
46
  subscribeToUserAttributes(['name'], onUserUpdate1);
@@ -64,17 +60,13 @@ describe('Public endpoint - userdata', () => {
64
60
 
65
61
  it('should alert when data changes', () => {
66
62
  jest
67
- .spyOn(userData, 'fetchDataBasedOnAttributes')
68
- .mockImplementationOnce((_, callback: Function) => {
69
- callback({
70
- name: undefined,
71
- });
72
- })
73
- .mockImplementationOnce((_, callback: Function) => {
74
- callback({
75
- name: 'Donald Duck',
76
- });
77
- });
63
+ .spyOn(userData, 'requestAttributes')
64
+ .mockImplementationOnce(() =>
65
+ store.set('userAttributes', { name: undefined })
66
+ )
67
+ .mockImplementationOnce(() =>
68
+ store.set('userAttributes', { name: 'Donald Duck' })
69
+ );
78
70
 
79
71
  const firstOnUserUpdate = jest.fn();
80
72
  subscribeToUserAttributes(['name'], firstOnUserUpdate);
@@ -94,15 +86,13 @@ describe('Public endpoint - userdata', () => {
94
86
  });
95
87
  });
96
88
 
97
- it('should not return more data that requested (except for login status)', () => {
98
- jest
99
- .spyOn(userData, 'fetchDataBasedOnAttributes')
100
- .mockImplementationOnce((_, callback: Function) => {
101
- callback({
102
- name: 'Donald Duck',
103
- email: 'donald.duck@andeby.no',
104
- });
89
+ it('should not return more data that requested', () => {
90
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
91
+ store.set('userAttributes', {
92
+ name: 'Donald Duck',
93
+ email: 'donald.duck@andeby.no',
105
94
  });
95
+ });
106
96
 
107
97
  const onUserUpdate = jest.fn();
108
98
  subscribeToUserAttributes(['name'], onUserUpdate);
@@ -113,15 +103,12 @@ describe('Public endpoint - userdata', () => {
113
103
  });
114
104
 
115
105
  it('should support returning multiple requested attributes', () => {
116
- jest
117
- .spyOn(userData, 'fetchDataBasedOnAttributes')
118
-
119
- .mockImplementationOnce((_, callback: Function) => {
120
- callback({
121
- name: 'Donald Duck',
122
- email: 'donald.duck@andeby.no',
123
- });
106
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
107
+ store.set('userAttributes', {
108
+ name: 'Donald Duck',
109
+ email: 'donald.duck@andeby.no',
124
110
  });
111
+ });
125
112
 
126
113
  const onUserUpdate = jest.fn();
127
114
  subscribeToUserAttributes(['name', 'email'], onUserUpdate);
@@ -133,15 +120,6 @@ describe('Public endpoint - userdata', () => {
133
120
  });
134
121
 
135
122
  it('should require at least one attribute', () => {
136
- jest
137
- .spyOn(userData, 'fetchDataBasedOnAttributes')
138
- .mockImplementationOnce((_, callback: Function) => {
139
- callback({
140
- name: 'Donald Duck',
141
- email: 'donald.duck@andeby.no',
142
- });
143
- });
144
-
145
123
  const onUserUpdate = jest.fn();
146
124
  expect(() => subscribeToUserAttributes([], onUserUpdate)).toThrowError(
147
125
  new Error('You must subscribe to at least one attribute')
@@ -149,14 +127,12 @@ describe('Public endpoint - userdata', () => {
149
127
  });
150
128
 
151
129
  it('should support requesting different attributes', () => {
152
- jest
153
- .spyOn(userData, 'fetchDataBasedOnAttributes')
154
- .mockImplementation((_, callback: Function) => {
155
- callback({
156
- name: 'Donald Duck',
157
- email: 'donald.duck@andeby.no',
158
- });
130
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
131
+ store.set('userAttributes', {
132
+ name: 'Donald Duck',
133
+ email: 'donald.duck@andeby.no',
159
134
  });
135
+ });
160
136
 
161
137
  const firstOnUserUpdate = jest.fn();
162
138
  subscribeToUserAttributes(['name', 'email'], firstOnUserUpdate);
@@ -175,4 +151,20 @@ describe('Public endpoint - userdata', () => {
175
151
  email: 'donald.duck@andeby.no',
176
152
  });
177
153
  });
154
+
155
+ it('should also report state changes', () => {
156
+ jest.spyOn(userData, 'requestAttributes').mockImplementation(() => {
157
+ store.set('userAttributes', {
158
+ name: 'Donald Duck',
159
+ });
160
+ store.set('state', { isLoggedIn: true });
161
+ });
162
+
163
+ const onUserUpdate = jest.fn();
164
+ const onStateUpdate = jest.fn();
165
+ subscribeToUserAttributes(['name'], onUserUpdate, onStateUpdate);
166
+
167
+ expect(onUserUpdate).toHaveBeenCalledWith({ name: 'Donald Duck' });
168
+ expect(onStateUpdate).toHaveBeenCalledWith({ isLoggedIn: true });
169
+ });
178
170
  });
@@ -1,4 +1,4 @@
1
- import store from './store';
1
+ import store from '.';
2
2
 
3
3
  beforeEach(() => {
4
4
  store.clear();
@@ -17,15 +17,15 @@ const emit = (key: keyof StoreDataMap): void => {
17
17
  listeners[key]?.forEach((listener) => listener(store[key]));
18
18
  };
19
19
 
20
- const on = (
21
- key: keyof StoreDataMap,
22
- listener: Listener<StoreDataMap[typeof key]>
20
+ const on = <K extends keyof StoreDataMap, T = StoreDataMap[K]>(
21
+ key: K,
22
+ listener: Listener<T>
23
23
  ) => {
24
24
  if (!listeners[key]) {
25
25
  listeners[key] = [];
26
26
  }
27
27
 
28
- // @ts-ignore todo How can this possibly be undefined?
28
+ // @ts-ignore todo How can this possibly be undefined given the statement above?
29
29
  listeners[key].push(listener);
30
30
  };
31
31
 
@@ -35,12 +35,17 @@ const set = (key: keyof StoreDataMap, value: StoreDataMap[typeof key]) => {
35
35
  emit(key);
36
36
  };
37
37
 
38
- const get = (key: keyof StoreDataMap): StoreDataMap[typeof key] | undefined =>
39
- store[key];
38
+ const get = <K extends keyof StoreDataMap, T = StoreDataMap[K]>(
39
+ key: K
40
+ // @ts-ignore Not sure why this fails
41
+ ): T | undefined => store[key];
40
42
 
41
43
  const clear = () => {
42
44
  store.state = undefined;
43
45
  store.userAttributes = undefined;
46
+ Object.keys(listeners).forEach((key) => {
47
+ listeners[key] = [];
48
+ });
44
49
  };
45
50
 
46
51
  export default { set, get, on, clear };
package/src/types.ts CHANGED
@@ -3,7 +3,7 @@ export type UserAttributes = {
3
3
  email?: string;
4
4
  phone?: string;
5
5
  trackingKey?: string;
6
- extraData?: [];
6
+ extraData?: { [index: string]: unknown };
7
7
  access?: string[];
8
8
  privacyPreferences?: PrivacyPreferences;
9
9
  };
@@ -2,15 +2,17 @@ import { Runtype, Static } from 'runtypes';
2
2
  import queue from './queue';
3
3
  import cache from '../cache';
4
4
 
5
- const DEFAULT_TTL_10_SECONDS = 10000;
6
- const cacheTTLMap: { [index: string]: number } = {};
5
+ export type DataFetcherWithCacheTTL<T extends Runtype> = Promise<{
6
+ ttl: number;
7
+ data: Static<T>;
8
+ }>;
7
9
 
8
- const getOrUpdate = <T extends Runtype>(
10
+ export default function getOrUpdate<T extends Runtype>(
9
11
  key: string,
10
12
  schema: T,
11
- action: () => Promise<Static<T>>
12
- ): Promise<Static<T>> =>
13
- new Promise((resolve, reject) => {
13
+ fetch: () => DataFetcherWithCacheTTL<T>
14
+ ): Promise<Static<T>> {
15
+ return new Promise((resolve, reject) => {
14
16
  queue.add(key, { resolve, reject });
15
17
  if (queue.peekQueueSize(key) > 1) {
16
18
  return;
@@ -23,11 +25,11 @@ const getOrUpdate = <T extends Runtype>(
23
25
  });
24
26
  return;
25
27
  }
26
- action()
28
+ fetch()
27
29
  .then((res) => {
28
- cache.set(key, res, cacheTTLMap[key] || DEFAULT_TTL_10_SECONDS);
30
+ cache.set(key, res.data, res.ttl);
29
31
  queue.getAll(key).forEach((promise) => {
30
- promise.resolve(res);
32
+ promise.resolve(res.data);
31
33
  });
32
34
  })
33
35
  .catch(() => {
@@ -37,5 +39,4 @@ const getOrUpdate = <T extends Runtype>(
37
39
  });
38
40
  });
39
41
  });
40
-
41
- export default getOrUpdate;
42
+ }
@@ -1,4 +0,0 @@
1
- import { Session } from '../clients/pluto';
2
- export declare const login: (requestedUrl: string) => void;
3
- export declare const logout: () => Promise<void>;
4
- export declare const getSession: () => Promise<Session | null>;
@@ -1,3 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getAccess: () => Promise<Pick<UserAttributes, 'access'>>;
3
- export declare const activate: (accessFeature: string) => Promise<boolean>;
@@ -1,9 +0,0 @@
1
- import { Record, Boolean } from 'runtypes';
2
- import { UserAttributes } from '../types';
3
- export declare const PrivacyPreferencesSchema: Record<{
4
- allowResearchUsage: Boolean;
5
- connectWithSurveys: Boolean;
6
- personalizedAds: Boolean;
7
- personalizedContent: Boolean;
8
- }, false>;
9
- export declare const getPrivacyPreferences: () => Promise<UserAttributes>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const fetchDataBasedOnAttributes: (attributes: Array<keyof UserAttributes>, onDataUpdated: (attributes: UserAttributes) => void) => void;
@@ -1,21 +0,0 @@
1
- import { CacheEntry, Engine } from '../types';
2
- declare global {
3
- interface Window {
4
- amediaUserCache?: {
5
- [index: string]: CacheEntry;
6
- };
7
- }
8
- namespace NodeJS {
9
- interface Global {
10
- amediaUserCache?: {
11
- [index: string]: CacheEntry;
12
- };
13
- }
14
- }
15
- }
16
- export declare const get: (key: string) => Promise<CacheEntry>;
17
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
18
- export declare const remove: (key: string) => Promise<void>;
19
- export declare const clear: () => Promise<void>;
20
- declare const _default: Engine;
21
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import { Static } from 'runtypes';
2
- import { RuntypeBase } from 'runtypes/lib/runtype';
3
- import { Engine } from './types';
4
- export declare const setCacheEngine: (engine: Engine) => void;
5
- declare const _default: {
6
- get: <T extends RuntypeBase<unknown>>(key: string, validator: T) => Promise<void | Static<T>>;
7
- set: (key: string, value: unknown, expires: number) => Promise<void>;
8
- remove: (key: string) => Promise<void>;
9
- clear: () => Promise<void>;
10
- };
11
- export default _default;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,11 +0,0 @@
1
- export declare type CacheEntry = {
2
- key: string;
3
- data: unknown;
4
- expires: number;
5
- };
6
- export declare type Engine = {
7
- get: (key: string) => Promise<CacheEntry | null>;
8
- set: (key: string, data: unknown, expires: number) => Promise<void>;
9
- remove: (key: string) => Promise<void>;
10
- clear: () => Promise<void>;
11
- };
@@ -1,12 +0,0 @@
1
- import { Record, Partial } from 'runtypes';
2
- export declare const EuropaSchema: Record<{
3
- namespaces: Partial<{}, false>;
4
- }, false>;
5
- export declare const clearLocalCache: () => Promise<void>;
6
- export declare const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
7
- export declare const getNamespace: (namespace: string, options?: {
8
- ignoreCache: boolean;
9
- }) => Promise<any>;
10
- export declare const saveNamespace: (namespace: string, data: Object) => Promise<any>;
11
- export declare const getAllNamespaces: () => Promise<{}>;
12
- export declare const deleteNamespaceKey: (namespace: string, key: string) => Promise<any>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- import { Array, Literal, Record, Static, String, Number, Union } from 'runtypes';
2
- export declare type AccessFeatures = string[];
3
- export declare const CheckAccessForPaperSchema: Record<{
4
- status: Literal<"success">;
5
- access: Union<[Literal<"granted">, Literal<"denied">]>;
6
- publication: Record<{
7
- id: Number;
8
- domain: String;
9
- }, false>;
10
- access_features: Array<String, false>;
11
- }, false>;
12
- export declare type CheckAccessForPaper = Static<typeof CheckAccessForPaperSchema>;
13
- declare const GetVstokenSchema: Record<{
14
- status: Literal<"success">;
15
- cookie: String;
16
- access_features: Array<String, false>;
17
- }, false>;
18
- export declare type GetVstoken = Static<typeof GetVstokenSchema>;
19
- declare const GetNonUserAccessSchema: Record<{
20
- status: Literal<"success">;
21
- vstoken_cookie: String;
22
- uuid: String;
23
- access_features: Array<String, false>;
24
- }, false>;
25
- export declare type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
26
- export declare const checkForAccess: (publicationDomain: string, accessFeatures: AccessFeatures) => Promise<CheckAccessForPaper>;
27
- export declare const getVstoken: (publicationDomain: string) => Promise<GetVstoken>;
28
- export declare const getNonUserAccess: (publicationDomain: string) => Promise<GetNonUserAccess>;
29
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- declare const log: {
2
- error: (message: string, context: {
3
- [index: string]: any;
4
- }) => void;
5
- warn: (message: string, context: {
6
- [index: string]: any;
7
- }) => void;
8
- info: (message: string, context: {
9
- [index: string]: any;
10
- }) => void;
11
- debug: (message: string, context: {
12
- [index: string]: any;
13
- }) => void;
14
- };
15
- export declare class UserDeactivatedError extends Error {
16
- }
17
- export declare const activateSubscription: (accessFeature: string) => Promise<boolean>;
18
- export default log;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};