@amedia/user 0.10.1 → 0.12.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 (84) hide show
  1. package/.eik/integrity.json +36 -0
  2. package/amedia-user-js.iml +9 -0
  3. package/dist/actions/authorization.d.ts +3 -1
  4. package/dist/actions/storage.d.ts +3 -0
  5. package/dist/autologin/index.d.ts +1 -0
  6. package/dist/autologin/thirdPartyCookie.d.ts +3 -0
  7. package/{esm/cache/engines/global.spec.d.ts → dist/autologin/thirdPartyCookie.spec.d.ts} +1 -1
  8. package/dist/eventHandlers/userAttributes.d.ts +4 -0
  9. package/{esm/cache/index.spec.d.ts → dist/index-storage.spec.d.ts} +4 -4
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +1 -1
  12. package/dist/janitor/index.d.ts +10 -0
  13. package/dist/janitor/jobs/accessCookieRefresher.d.ts +1 -0
  14. package/{esm/clients/mercury.spec.d.ts → dist/janitor/jobs/accessCookieRefresher.spec.d.ts} +4 -4
  15. package/dist/types.d.ts +1 -0
  16. package/dist/utils/url.d.ts +3 -0
  17. package/eik.json +9 -0
  18. package/package.json +12 -2
  19. package/rollup.config.js +14 -0
  20. package/src/actions/authentication.ts +4 -9
  21. package/src/actions/authorization.ts +18 -5
  22. package/src/actions/storage.ts +6 -1
  23. package/src/actions/userData.ts +2 -1
  24. package/src/autologin/index.ts +7 -0
  25. package/src/autologin/thirdPartyCookie.spec.ts +108 -0
  26. package/src/autologin/thirdPartyCookie.ts +69 -0
  27. package/src/clients/mercury.ts +7 -3
  28. package/src/clients/pluto.spec.ts +1 -0
  29. package/src/clients/pluto.ts +2 -0
  30. package/src/eventHandlers/userAttributes.ts +8 -1
  31. package/src/index-storage.spec.ts +96 -0
  32. package/src/index-subscription.spec.ts +0 -54
  33. package/src/index.ts +11 -1
  34. package/src/janitor/index.ts +39 -0
  35. package/src/janitor/jobs/accessCookieRefresher.spec.ts +230 -0
  36. package/src/janitor/jobs/accessCookieRefresher.ts +96 -0
  37. package/src/types.ts +1 -0
  38. package/src/utils/url.ts +14 -1
  39. package/test.html +12 -0
  40. package/esm/actions/authentication.d.ts +0 -5
  41. package/esm/actions/authorization.d.ts +0 -7
  42. package/esm/actions/preferences.d.ts +0 -9
  43. package/esm/actions/preferences.spec.d.ts +0 -1
  44. package/esm/actions/storage.d.ts +0 -1
  45. package/esm/actions/userData.d.ts +0 -2
  46. package/esm/cache/engines/global.d.ts +0 -21
  47. package/esm/cache/engines/indexeddb.d.ts +0 -7
  48. package/esm/cache/index.d.ts +0 -11
  49. package/esm/cache/types.d.ts +0 -11
  50. package/esm/clients/europa.d.ts +0 -28
  51. package/esm/clients/europa.spec.d.ts +0 -1
  52. package/esm/clients/jupiter.d.ts +0 -30
  53. package/esm/clients/jupiter.spec.d.ts +0 -1
  54. package/esm/clients/mercury.d.ts +0 -18
  55. package/esm/clients/nebula.d.ts +0 -2
  56. package/esm/clients/nebula.spec.d.ts +0 -1
  57. package/esm/clients/pluto.d.ts +0 -3
  58. package/esm/clients/pluto.spec.d.ts +0 -1
  59. package/esm/eventHandlers/activation.d.ts +0 -15
  60. package/esm/eventHandlers/authentication.d.ts +0 -17
  61. package/esm/eventHandlers/userAttributes.d.ts +0 -20
  62. package/esm/exceptions/PaywallError.d.ts +0 -7
  63. package/esm/index-authentcation.spec.d.ts +0 -4
  64. package/esm/index-subscription.spec.d.ts +0 -4
  65. package/esm/index.d.ts +0 -23
  66. package/esm/lib/PaywallUnlocker.d.ts +0 -16
  67. package/esm/lib/PaywallUnlocker.spec.d.ts +0 -4
  68. package/esm/lib/User.d.ts +0 -21
  69. package/esm/lib/cookie.d.ts +0 -5
  70. package/esm/lib/rpc.d.ts +0 -6
  71. package/esm/store/index.d.ts +0 -22
  72. package/esm/store/index.spec.d.ts +0 -1
  73. package/esm/types.d.ts +0 -21
  74. package/esm/user.js +0 -2
  75. package/esm/user.js.map +0 -1
  76. package/esm/utils/customEventWrapper.d.ts +0 -17
  77. package/esm/utils/deepEquals.d.ts +0 -4
  78. package/esm/utils/getOrUpdate.d.ts +0 -6
  79. package/esm/utils/getOrUpdate.spec.d.ts +0 -1
  80. package/esm/utils/location.d.ts +0 -2
  81. package/esm/utils/log.d.ts +0 -26
  82. package/esm/utils/queue.d.ts +0 -12
  83. package/esm/utils/url.d.ts +0 -3
  84. package/esm/utils/url.spec.d.ts +0 -1
@@ -0,0 +1,230 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import accessCookieRefresher from './accessCookieRefresher';
6
+ import * as url from '../../utils/url';
7
+ import User from '../../lib/User';
8
+ import * as cookie from '../../lib/cookie';
9
+ import * as authorization from '../../actions/authorization';
10
+ import { setRootElement } from '../../utils/customEventWrapper';
11
+ import restoreAllMocks = jest.restoreAllMocks;
12
+ import spyOn = jest.spyOn;
13
+
14
+ const mockUuid = '3-1-33-7';
15
+
16
+ beforeEach(() => {
17
+ setRootElement(new Document());
18
+ restoreAllMocks();
19
+ spyOn(url, 'getCurrentPublicationDomain').mockReturnValue('www.avisnavn.no');
20
+ url.setCurrentHostname('www.avisnavn.no');
21
+ jest
22
+ .spyOn(authorization, 'setUserAccessCookie')
23
+ .mockImplementation(() => Promise.resolve(true));
24
+ jest
25
+ .spyOn(authorization, 'setNonUserAccessCookie')
26
+ .mockImplementation(() => Promise.resolve(true));
27
+ });
28
+
29
+ function mockAccessCookie(validHours, uuid, accessFeatures, domain) {
30
+ const validTo = new Date();
31
+ validTo.setHours(validTo.getHours() + validHours);
32
+ return `signature:${Math.round(
33
+ validTo.getTime() / 1000
34
+ )}:${accessFeatures.join(',')}:${uuid}:${domain}:jupiter`;
35
+ }
36
+
37
+ describe('accessCookieRefresher', () => {
38
+ describe('User is logged in', () => {
39
+ beforeEach(() => {
40
+ jest.spyOn(User.prototype, 'subscribe').mockImplementation((callback) => {
41
+ callback({
42
+ attributes: {
43
+ uuid: mockUuid,
44
+ },
45
+ state: {
46
+ isLoggedIn: true,
47
+ },
48
+ });
49
+ });
50
+ });
51
+
52
+ describe('without any cookies', () => {
53
+ beforeEach(() => {
54
+ jest.spyOn(cookie, 'getCookie').mockReturnValue(null);
55
+ });
56
+ it('Should set user access cookie and non user access cookie', () => {
57
+ expect(accessCookieRefresher()).resolves.toEqual([
58
+ undefined,
59
+ undefined,
60
+ ]);
61
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
62
+ expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
63
+ });
64
+ });
65
+
66
+ describe('with only user access cookie', () => {
67
+ beforeEach(() => {
68
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
69
+ if (name === 'VSTOKEN') {
70
+ return mockAccessCookie(25, mockUuid, ['newspaper'], 'avisnavn.no');
71
+ }
72
+ return null;
73
+ });
74
+ });
75
+ it('Should set user access cookie and non user access cookie', () => {
76
+ expect(accessCookieRefresher()).resolves.toEqual([
77
+ undefined,
78
+ undefined,
79
+ ]);
80
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(0);
81
+ expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
82
+ });
83
+ });
84
+
85
+ describe('with only non user access cookie', () => {
86
+ beforeEach(() => {
87
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
88
+ if (name === 'VSTOKEN2') {
89
+ return mockAccessCookie(1, mockUuid, ['newspaper'], 'avisnavn.no');
90
+ }
91
+ return null;
92
+ });
93
+ });
94
+ it('Should set user access cookie and non user access cookie', () => {
95
+ expect(accessCookieRefresher()).resolves.toEqual([
96
+ undefined,
97
+ undefined,
98
+ ]);
99
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
100
+ expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(0);
101
+ });
102
+ });
103
+
104
+ describe('with user access cookie set for another domain', () => {
105
+ beforeEach(() => {
106
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
107
+ if (name === 'VSTOKEN') {
108
+ return mockAccessCookie(
109
+ 25,
110
+ mockUuid,
111
+ ['newspaper'],
112
+ 'evildomain.no'
113
+ );
114
+ }
115
+ return null;
116
+ });
117
+ });
118
+ it('Should set user access cookie and non user access cookie', () => {
119
+ expect(accessCookieRefresher()).resolves.toEqual([
120
+ undefined,
121
+ undefined,
122
+ ]);
123
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
124
+ });
125
+ });
126
+
127
+ describe('with user access cookie valid for less than 24 hours', () => {
128
+ beforeEach(() => {
129
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
130
+ if (name === 'VSTOKEN') {
131
+ return mockAccessCookie(23, mockUuid, ['newspaper'], 'avisnavn.no');
132
+ }
133
+ return null;
134
+ });
135
+ });
136
+ it('Should set user access cookie and non user access cookie', () => {
137
+ expect(accessCookieRefresher()).resolves.toEqual([
138
+ undefined,
139
+ undefined,
140
+ ]);
141
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(1);
142
+ });
143
+ });
144
+
145
+ describe('with non user access cookie set for another domain', () => {
146
+ beforeEach(() => {
147
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
148
+ if (name === 'VSTOKEN2') {
149
+ return mockAccessCookie(
150
+ 25,
151
+ mockUuid,
152
+ ['newspaper'],
153
+ 'evildomain.no'
154
+ );
155
+ }
156
+ return null;
157
+ });
158
+ });
159
+ it('Should set user access cookie and non user access cookie', () => {
160
+ expect(accessCookieRefresher()).resolves.toEqual([
161
+ undefined,
162
+ undefined,
163
+ ]);
164
+ expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
165
+ });
166
+ });
167
+
168
+ describe('with non user access cookie valid for less than 30 minutes', () => {
169
+ beforeEach(() => {
170
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
171
+ if (name === 'VSTOKEN2') {
172
+ return mockAccessCookie(0, mockUuid, ['newspaper'], 'avisnavn.no');
173
+ }
174
+ return null;
175
+ });
176
+ });
177
+ it('Should set user access cookie and non user access cookie', () => {
178
+ expect(accessCookieRefresher()).resolves.toEqual([
179
+ undefined,
180
+ undefined,
181
+ ]);
182
+ expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
183
+ });
184
+ });
185
+ });
186
+ describe('User is logged in', () => {
187
+ beforeEach(() => {
188
+ jest.spyOn(User.prototype, 'subscribe').mockImplementation((callback) => {
189
+ callback({
190
+ attributes: {},
191
+ state: {
192
+ isLoggedIn: false,
193
+ },
194
+ });
195
+ });
196
+ });
197
+ describe('without any cookies', () => {
198
+ beforeEach(() => {
199
+ jest.spyOn(cookie, 'getCookie').mockReturnValue(null);
200
+ });
201
+ it('Should set only non user access cookie', () => {
202
+ expect(accessCookieRefresher()).resolves.toEqual([
203
+ undefined,
204
+ undefined,
205
+ ]);
206
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(0);
207
+ expect(authorization.setNonUserAccessCookie).toHaveBeenCalledTimes(1);
208
+ });
209
+ });
210
+ describe('User has user access cookie', () => {
211
+ beforeEach(() => {
212
+ jest.spyOn(cookie, 'getCookie').mockImplementation((name) => {
213
+ if (name === 'VSTOKEN') {
214
+ return mockAccessCookie(25, mockUuid, ['newspaper'], 'avisnavn.no');
215
+ }
216
+ return null;
217
+ });
218
+ jest.spyOn(cookie, 'removeCookie').mockImplementation();
219
+ });
220
+ it('Should remove user access cookie', () => {
221
+ expect(accessCookieRefresher()).resolves.toEqual([
222
+ undefined,
223
+ undefined,
224
+ ]);
225
+ expect(authorization.setUserAccessCookie).toHaveBeenCalledTimes(0);
226
+ expect(cookie.removeCookie).toHaveBeenCalledWith('VSTOKEN');
227
+ });
228
+ });
229
+ });
230
+ });
@@ -0,0 +1,96 @@
1
+ import { getCookie, removeCookie } from '../../lib/cookie';
2
+ import User from '../../lib/User';
3
+ import {
4
+ setNonUserAccessCookie,
5
+ setUserAccessCookie,
6
+ } from '../../actions/authorization';
7
+ import { getCurrentPublicationDomain } from '../../utils/url';
8
+
9
+ async function verifyAndSetUserAccessCookie() {
10
+ const publicationDomain = getCurrentPublicationDomain();
11
+ const cookie = getCookie('VSTOKEN');
12
+ let hasVerifiedVstoken = false;
13
+
14
+ new User()
15
+ .withAttributes(['uuid'])
16
+ .subscribe(async ({ attributes, state }) => {
17
+ if (state.isLoggedIn === false) {
18
+ if (typeof cookie === 'string') {
19
+ // We don't want logged out users to have lingering VSTOKEN cookies
20
+ removeCookie('VSTOKEN');
21
+ }
22
+ return;
23
+ }
24
+
25
+ if (
26
+ !attributes.uuid ||
27
+ state.isLoggedIn === undefined ||
28
+ hasVerifiedVstoken
29
+ ) {
30
+ // We only want to perform this job once, so we wait until we have all the data we need.
31
+ return;
32
+ }
33
+
34
+ hasVerifiedVstoken = true; // Make sure we do this only once!
35
+
36
+ if (typeof cookie !== 'string') {
37
+ // We want to set a VSTOKEN cookie for the user so it's ready upon next page load
38
+ await setUserAccessCookie(publicationDomain);
39
+ return;
40
+ }
41
+
42
+ /* The format of the cookie is:
43
+ * <0 - signature>:<1 - timestamp when cookie stops being valid>:<2 - access_features>:<3 - user_id>:<4 - second level domain>:<5 - generator name (jupiter)> */
44
+ const cookieParts = cookie.split(':');
45
+
46
+ const validTo = new Date(parseInt(cookieParts[1], 10) * 1000);
47
+ validTo.setDate(
48
+ validTo.getDate() - 1
49
+ ); /* Set the time one day back so we can update it if it's only valid for one more day */
50
+
51
+ // Make sure that current cookie is not too old, is created for logged in user for this domain by jupiter
52
+ if (
53
+ validTo.getTime() > Date.now() &&
54
+ cookieParts[3] === attributes.uuid &&
55
+ publicationDomain.includes(cookieParts[4]) &&
56
+ cookieParts[5] === 'jupiter'
57
+ ) {
58
+ return; // Cookie is valid for more than 24 hours, keep it as it is
59
+ }
60
+ await setUserAccessCookie(publicationDomain);
61
+ });
62
+ }
63
+
64
+ async function verifyAndSetNonUserAccessCookie() {
65
+ const publicationDomain = getCurrentPublicationDomain();
66
+ const cookie = getCookie('VSTOKEN2');
67
+
68
+ if (typeof cookie !== 'string') {
69
+ await setNonUserAccessCookie(publicationDomain);
70
+ return;
71
+ }
72
+ /* The format of the cookie is:
73
+ * <0 - signature>:<1 - timestamp when cookie stops being valid>:<2 - access_features>:<3 - uuid>:<4 - second level domain>:<5 - generator name (jupiter)>
74
+ */
75
+ const cookieParts = cookie.split(':');
76
+ const validTo = new Date(parseInt(cookieParts[1], 10) * 1000);
77
+ // // Check that token is valid for the next 30 minutes otherwise we need to update it
78
+ validTo.setMinutes(validTo.getMinutes() - 30);
79
+
80
+ // Make sure that current cookie is not too old and is created for this domain by jupiter
81
+ if (
82
+ validTo.getTime() > Date.now() &&
83
+ publicationDomain.includes(cookieParts[4]) &&
84
+ cookieParts[5] === 'jupiter'
85
+ ) {
86
+ return;
87
+ }
88
+ await setNonUserAccessCookie(publicationDomain);
89
+ }
90
+
91
+ export default function accessCookieRefresher() {
92
+ return Promise.all([
93
+ verifyAndSetUserAccessCookie(),
94
+ verifyAndSetNonUserAccessCookie(),
95
+ ]);
96
+ }
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type UserAttributes = {
2
+ uuid?: string;
2
3
  name?: string;
3
4
  email?: string;
4
5
  phone?: string;
package/src/utils/url.ts CHANGED
@@ -3,9 +3,11 @@ export const setCurrentHostname = (hostname: string) => {
3
3
  overriddenHostname = hostname;
4
4
  };
5
5
 
6
- const getCurrentHostname = (): string =>
6
+ export const getCurrentHostname = (): string =>
7
7
  overriddenHostname || window.location.hostname;
8
8
 
9
+ export const getCurrentUrl = (): string => window.location.href;
10
+
9
11
  export const getCurrentEnvironment = () => {
10
12
  const matchBed = /^bed-([^.]+)\.api\.no$/.exec(getCurrentHostname());
11
13
  const match = /\.([^.]+)\.api\.no/.exec(getCurrentHostname());
@@ -20,3 +22,14 @@ export const getCurrentEnvironment = () => {
20
22
 
21
23
  export const getCurrentPublicationDomain = () =>
22
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/test.html ADDED
@@ -0,0 +1,12 @@
1
+ <html>
2
+ <head>
3
+ <script type="module">
4
+ import { user } from 'https://assets.acdn.no/pkg/user-js/0.0.1/files/user.js'
5
+ console.log(user)
6
+ </script>
7
+ </head>
8
+ <body>
9
+
10
+ </body>
11
+
12
+ </html>
@@ -1,5 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const login: (requestedUrl: URL | string) => void;
3
- export declare const logout: () => Promise<void>;
4
- export declare const getSession: () => Promise<UserAttributes>;
5
- export declare const isLoggedIn: () => boolean;
@@ -1,7 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getAccess: (accessFeatures?: string[]) => Promise<Pick<UserAttributes, 'access'>>;
3
- export declare const activate: (accessFeatures: string[]) => Promise<boolean>;
4
- export declare const hasAccess: (currentAccessFeatures: string[], requestedAccessFeatures: string[]) => boolean;
5
- export declare const setAccessCookies: (publicationDomain: any) => Promise<boolean>;
6
- export declare const hasRecentlyTriedToUnlockPaywall: () => boolean;
7
- export declare const setHasTriedToUnlockPaywall: () => void;
@@ -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<Pick<UserAttributes, 'privacyPreferences'>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const requestStorage: (namespaces: string[]) => void;
@@ -1,2 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const requestAttributes: (attributes: Array<keyof UserAttributes>) => 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,7 +0,0 @@
1
- import { CacheEntry, Engine } from '../types';
2
- export declare const get: (key: string) => Promise<CacheEntry>;
3
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
4
- export declare const remove: (key: string) => Promise<void>;
5
- export declare const clear: () => Promise<void>;
6
- declare const _default: Engine;
7
- export default _default;
@@ -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,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,28 +0,0 @@
1
- import { Record, Unknown, Dictionary } from 'runtypes';
2
- export declare const EuropaSchema: Record<{
3
- namespaces: Dictionary<Unknown, string>;
4
- }, false>;
5
- export declare const clearLocalCache: () => Promise<void>;
6
- export declare const updateNamespace: (namespace: string, data: Object) => Promise<void | {}>;
7
- export declare const getNamespaces: <S extends {
8
- [namespace: string]: {
9
- [index: string]: unknown;
10
- };
11
- }, Namespaces extends (keyof S)[]>(namespaces: Namespaces, options?: {
12
- ignoreCache: boolean;
13
- }) => Promise<Pick<S, Namespaces[number]>>;
14
- export declare const saveNamespace: (namespace: string, data: Object) => Promise<Pick<{
15
- [namespace: string]: {
16
- [index: string]: unknown;
17
- };
18
- }, string>>;
19
- export declare const getAllNamespaces: () => Promise<{
20
- namespaces: {
21
- [x: string]: unknown;
22
- };
23
- }>;
24
- export declare const deleteNamespaceKey: (namespace: string, key: string) => Promise<Pick<{
25
- [namespace: string]: {
26
- [index: string]: unknown;
27
- };
28
- }, string>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import { Array, Literal, Record, Static, String, Number, Union } from 'runtypes';
2
- import { UserAttributes } from '../types';
3
- export declare type AccessFeatures = string[];
4
- export declare const CheckAccessForPaperSchema: Record<{
5
- status: Literal<"success">;
6
- access: Union<[Literal<"granted">, Literal<"denied">]>;
7
- publication: Record<{
8
- id: Number;
9
- domain: String;
10
- }, false>;
11
- access_features: Array<String, false>;
12
- }, false>;
13
- export declare type CheckAccessForPaper = Static<typeof CheckAccessForPaperSchema>;
14
- declare const GetVstokenSchema: Record<{
15
- status: Literal<"success">;
16
- cookie: String;
17
- access_features: Array<String, false>;
18
- }, false>;
19
- export declare type GetVstoken = Static<typeof GetVstokenSchema>;
20
- declare const GetNonUserAccessSchema: Record<{
21
- status: Literal<"success">;
22
- vstoken_cookie: String;
23
- uuid: String;
24
- access_features: Array<String, false>;
25
- }, false>;
26
- export declare type GetNonUserAccess = Static<typeof GetNonUserAccessSchema>;
27
- export declare const checkForAccess: (publicationDomain: string, accessFeatures: AccessFeatures) => Promise<Pick<UserAttributes, 'access'>>;
28
- export declare const getVstoken: (publicationDomain: string) => Promise<GetVstoken>;
29
- export declare const getNonUserAccess: (publicationDomain: string) => Promise<GetNonUserAccess>;
30
- 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: (accessFeatures: string[]) => Promise<boolean>;
18
- export default log;
@@ -1,2 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getInfo: (publicationDomain: string, browserId: string, userKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { UserAttributes } from '../types';
2
- export declare const getCurrentSession: () => Promise<UserAttributes>;
3
- export declare const removeSession: (domain: string) => Promise<void>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- export declare enum ActivationEvents {
2
- REQUEST_ACTIVATION = "amedia-user.activation.request-activation",
3
- ON_ACTIVATION_COMPLETE = "amedia-user.activation.on-activation-complete"
4
- }
5
- declare global {
6
- interface WindowEventMap {
7
- [ActivationEvents.REQUEST_ACTIVATION]: CustomEvent<{
8
- accessFeatures: string[];
9
- }>;
10
- [ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
11
- hasAccess: boolean;
12
- }>;
13
- }
14
- }
15
- export declare const listenForActivationRequests: () => void;
@@ -1,17 +0,0 @@
1
- export declare enum AuthenticationEvents {
2
- REQUEST_LOGIN = "amedia-user.authentication.request-login",
3
- REQUEST_LOGOUT = "amedia-user.authentication.request-logout",
4
- ON_LOGGED_OUT = "amedia-user.authentication.on-logged-out"
5
- }
6
- declare global {
7
- interface WindowEventMap {
8
- [AuthenticationEvents.REQUEST_LOGIN]: CustomEvent<{
9
- requestedUrl: string;
10
- }>;
11
- [AuthenticationEvents.REQUEST_LOGOUT]: CustomEvent<{
12
- onLoggedOut: () => void;
13
- }>;
14
- [AuthenticationEvents.ON_LOGGED_OUT]: CustomEvent;
15
- }
16
- }
17
- export declare const listenForAuthenticationRequests: () => void;
@@ -1,20 +0,0 @@
1
- import { State, UserAttributes } from '../types';
2
- export declare enum AmediaUserEvents {
3
- REQUEST_USER_ATTRIBUTES = "amedia-user.request-user-attributes",
4
- REQUEST_STORAGE_NAMESPACES = "amedia-user.request-storage-namespaces",
5
- ON_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated",
6
- ON_STATE_UPDATED = "amedia-user.on-state-updated",
7
- ON_STORAGE_UPDATED = "amedia-user.on-storage-updated"
8
- }
9
- declare global {
10
- interface WindowEventMap {
11
- [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
12
- [AmediaUserEvents.REQUEST_STORAGE_NAMESPACES]: CustomEvent<Array<string>>;
13
- [AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
14
- [AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
15
- [AmediaUserEvents.ON_STORAGE_UPDATED]: CustomEvent<{
16
- [index: string]: unknown;
17
- }>;
18
- }
19
- }
20
- export declare const listenForUserAttributeRequests: () => void;
@@ -1,7 +0,0 @@
1
- declare class PaywallError extends Error {
2
- static ERROR_RELOADED_NO_ACCESS: string;
3
- static ERROR_ENABLING_ACCESS_FAILED: string;
4
- code: string;
5
- constructor(message: string, code: string);
6
- }
7
- export default PaywallError;
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};