@amedia/user 0.1.1 → 0.2.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 (54) hide show
  1. package/dist/actions/authentication.d.ts +4 -0
  2. package/dist/actions/authorization.d.ts +3 -0
  3. package/dist/cache/engines/global.d.ts +6 -0
  4. package/dist/cache/engines/indexeddb.d.ts +6 -0
  5. package/dist/cache/index.d.ts +9 -0
  6. package/dist/cache/types.d.ts +10 -0
  7. package/dist/eventHandlers/activation.d.ts +13 -0
  8. package/dist/eventHandlers/authentication.d.ts +15 -0
  9. package/dist/eventHandlers/userAttributes.d.ts +12 -0
  10. package/dist/index.d.ts +21 -206
  11. package/dist/index.js +1 -497
  12. package/dist/lib/authentication.d.ts +20 -0
  13. package/dist/lib/authorization.d.ts +15 -0
  14. package/dist/lib/cache/db.d.ts +6 -0
  15. package/dist/lib/cache/global.d.ts +9 -0
  16. package/dist/lib/cache/types.d.ts +5 -0
  17. package/dist/lib/dataOrganizer.d.ts +2 -0
  18. package/dist/lib/eventHandler.d.ts +3 -0
  19. package/dist/lib/queue.d.ts +5 -0
  20. package/dist/lib/types.d.ts +7 -0
  21. package/dist/lib/userAttributes.d.ts +12 -0
  22. package/dist/services/cache.d.ts +9 -0
  23. package/dist/services/jupiter.d.ts +29 -0
  24. package/dist/services/mercury.d.ts +15 -0
  25. package/dist/services/pluto.d.ts +8 -0
  26. package/dist/types.d.ts +12 -0
  27. package/dist/utils/customEventWrapper.d.ts +3 -0
  28. package/dist/utils/queue.d.ts +5 -0
  29. package/package.json +8 -5
  30. package/src/actions/authentication.ts +37 -0
  31. package/src/actions/authorization.ts +51 -0
  32. package/src/{lib/cache → cache/engines}/global.ts +5 -3
  33. package/src/{lib/cache/db.ts → cache/engines/indexeddb.ts} +5 -5
  34. package/src/cache/index.spec.ts +82 -0
  35. package/src/{services/cache.ts → cache/index.ts} +25 -13
  36. package/src/{lib/cache → cache}/types.ts +7 -1
  37. package/src/eventHandlers/activation.ts +29 -0
  38. package/src/eventHandlers/authentication.ts +29 -0
  39. package/src/{lib → eventHandlers}/userAttributes.ts +11 -12
  40. package/src/index.spec.ts +49 -30
  41. package/src/index.ts +14 -5
  42. package/src/lib/dataOrganizer.ts +33 -14
  43. package/src/services/pluto.spec.ts +3 -2
  44. package/src/services/pluto.ts +14 -10
  45. package/src/types.ts +13 -0
  46. package/src/utils/customEventWrapper.ts +42 -0
  47. package/src/utils/log.ts +7 -0
  48. package/tsconfig.json +2 -4
  49. package/webpack.config.js +25 -0
  50. package/src/lib/authentication.ts +0 -94
  51. package/src/lib/authorization.ts +0 -86
  52. package/src/lib/eventHandler.ts +0 -16
  53. package/src/lib/types.ts +0 -7
  54. /package/src/{lib → utils}/queue.ts +0 -0
package/src/index.spec.ts CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { subscribeToUserUpdates } from './index';
6
6
  import * as dataOrganizer from './lib/dataOrganizer';
7
- import { setRootElement } from './lib/eventHandler';
8
- import { listenForUserAttributeRequests } from './lib/userAttributes';
7
+ import { setRootElement } from './utils/customEventWrapper';
8
+ import { listenForUserAttributeRequests } from './eventHandlers/userAttributes';
9
9
 
10
10
  beforeEach(() => {
11
11
  jest.resetAllMocks();
@@ -21,10 +21,14 @@ beforeEach(() => {
21
21
 
22
22
  describe('Public endpoint', () => {
23
23
  it('should alert about user data', () => {
24
- jest.spyOn(dataOrganizer, 'fetchDataBasedOnAttributes').mockReturnValue({
25
- name: 'Donald Duck',
26
- isLoggedIn: true,
27
- });
24
+ jest
25
+ .spyOn(dataOrganizer, 'fetchDataBasedOnAttributes')
26
+ .mockImplementation((_, callback: Function) => {
27
+ callback({
28
+ name: 'Donald Duck',
29
+ isLoggedIn: true,
30
+ });
31
+ });
28
32
 
29
33
  const onUserUpdate = jest.fn();
30
34
  subscribeToUserUpdates(['name'], onUserUpdate);
@@ -38,13 +42,17 @@ describe('Public endpoint', () => {
38
42
  it('should alert when others also ask about data', () => {
39
43
  jest
40
44
  .spyOn(dataOrganizer, 'fetchDataBasedOnAttributes')
41
- .mockReturnValueOnce({
42
- name: undefined,
43
- isLoggedIn: false,
45
+ .mockImplementationOnce((_, callback: Function) => {
46
+ callback({
47
+ name: undefined,
48
+ isLoggedIn: false,
49
+ });
44
50
  })
45
- .mockReturnValueOnce({
46
- name: 'Donald Duck',
47
- isLoggedIn: true,
51
+ .mockImplementationOnce((_, callback: Function) => {
52
+ callback({
53
+ name: 'Donald Duck',
54
+ isLoggedIn: true,
55
+ });
48
56
  });
49
57
 
50
58
  const firstOnUserUpdate = jest.fn();
@@ -73,10 +81,12 @@ describe('Public endpoint', () => {
73
81
  it('should not return more data that requested (except for login status)', () => {
74
82
  jest
75
83
  .spyOn(dataOrganizer, 'fetchDataBasedOnAttributes')
76
- .mockReturnValueOnce({
77
- name: 'Donald Duck',
78
- email: 'donald.duck@andeby.no',
79
- isLoggedIn: true,
84
+ .mockImplementationOnce((_, callback: Function) => {
85
+ callback({
86
+ name: 'Donald Duck',
87
+ email: 'donald.duck@andeby.no',
88
+ isLoggedIn: true,
89
+ });
80
90
  });
81
91
 
82
92
  const onUserUpdate = jest.fn();
@@ -91,10 +101,13 @@ describe('Public endpoint', () => {
91
101
  it('should support returning multiple requested attributes', () => {
92
102
  jest
93
103
  .spyOn(dataOrganizer, 'fetchDataBasedOnAttributes')
94
- .mockReturnValueOnce({
95
- name: 'Donald Duck',
96
- email: 'donald.duck@andeby.no',
97
- isLoggedIn: true,
104
+
105
+ .mockImplementationOnce((_, callback: Function) => {
106
+ callback({
107
+ name: 'Donald Duck',
108
+ email: 'donald.duck@andeby.no',
109
+ isLoggedIn: true,
110
+ });
98
111
  });
99
112
 
100
113
  const onUserUpdate = jest.fn();
@@ -110,10 +123,12 @@ describe('Public endpoint', () => {
110
123
  it('should support no attributes, returning only logged in state', () => {
111
124
  jest
112
125
  .spyOn(dataOrganizer, 'fetchDataBasedOnAttributes')
113
- .mockReturnValueOnce({
114
- name: 'Donald Duck',
115
- email: 'donald.duck@andeby.no',
116
- isLoggedIn: true,
126
+ .mockImplementationOnce((_, callback: Function) => {
127
+ callback({
128
+ name: 'Donald Duck',
129
+ email: 'donald.duck@andeby.no',
130
+ isLoggedIn: true,
131
+ });
117
132
  });
118
133
 
119
134
  const onUserUpdate = jest.fn();
@@ -124,12 +139,16 @@ describe('Public endpoint', () => {
124
139
  });
125
140
  });
126
141
 
127
- it('should support requesting difference amount of attributes', () => {
128
- jest.spyOn(dataOrganizer, 'fetchDataBasedOnAttributes').mockReturnValue({
129
- name: 'Donald Duck',
130
- email: 'donald.duck@andeby.no',
131
- isLoggedIn: true,
132
- });
142
+ it('should support requesting different attributes', () => {
143
+ jest
144
+ .spyOn(dataOrganizer, 'fetchDataBasedOnAttributes')
145
+ .mockImplementation((_, callback: Function) => {
146
+ callback({
147
+ name: 'Donald Duck',
148
+ email: 'donald.duck@andeby.no',
149
+ isLoggedIn: true,
150
+ });
151
+ });
133
152
 
134
153
  const firstOnUserUpdate = jest.fn();
135
154
  subscribeToUserUpdates([], firstOnUserUpdate);
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { AuthenticationEvents } from './lib/authentication';
2
- import { AmediaUserEvents } from './lib/userAttributes';
3
- import { dispatch, listen } from './lib/eventHandler';
4
- import { UserAttributes } from './lib/types';
1
+ import { AuthenticationEvents } from './eventHandlers/authentication';
2
+ import { AmediaUserEvents } from './eventHandlers/userAttributes';
3
+ import { ActivationEvents } from './eventHandlers/activation';
4
+ import { dispatch, listenForAllEvents } from './utils/customEventWrapper';
5
+ import { UserAttributes } from './types';
5
6
 
6
7
  /**
7
8
  * Enables you to subscribe to the user attributes you care about and
@@ -22,7 +23,7 @@ export const subscribeToUserUpdates = <T extends Array<keyof UserAttributes>>(
22
23
  attributes: Pick<UserAttributes, T[number] | 'isLoggedIn'>
23
24
  ) => void
24
25
  ) => {
25
- listen(AmediaUserEvents.ON_USER_ATTRIBUTES_UPDATED, (evt) => {
26
+ listenForAllEvents(AmediaUserEvents.ON_USER_ATTRIBUTES_UPDATED, (evt) => {
26
27
  const userAttributes = evt.detail;
27
28
  // @ts-ignore
28
29
  const responseAttributes: Pick<UserAttributes, T[number] | 'isLoggedIn'> = {
@@ -56,3 +57,11 @@ export const requestLogin = (requestedUrl?: string) =>
56
57
  detail: { requestedUrl },
57
58
  })
58
59
  );
60
+
61
+ export const activate = (): Promise<unknown> =>
62
+ new Promise((resolve, reject) => {
63
+ listenForAllEvents(ActivationEvents.ON_ACTIVATION_COMPLETE, (result) => {
64
+ resolve(result);
65
+ });
66
+ dispatch(new CustomEvent(ActivationEvents.REQUEST_ACTIVATION));
67
+ });
@@ -1,18 +1,37 @@
1
- import { UserAttributes } from './types';
1
+ import { UserAttributes } from '../types';
2
+ import { getSession } from '../actions/authentication';
2
3
 
3
- /**
4
- * Jeg tror ikke vi burde gjøre det slik som dette.
5
- * Denne funksjonen var hentet ut fra userAttribute kun for å
6
- * kunne mocke implementasjonen så jeg kunne teste event-callback mekanismen.
7
- *
8
- * En implementasjon som dette vil gjøre det vanskelig svare etterhvert som vi får data.
9
- */
4
+ // TODO We may want actions to tell us what they can deliver and not have this "organizer" (wohoo-bad-name) tell the actions..
5
+ const dataServiceMap: {
6
+ // TODO Must get proper type here. Perhaps all actions should return UserAttribute-compatible response?
7
+ [key in keyof UserAttributes]?: () => Promise<any>;
8
+ } = {
9
+ name: getSession,
10
+ trackingKey: getSession,
11
+ };
10
12
 
11
13
  export const fetchDataBasedOnAttributes = (
12
- attributes: (keyof UserAttributes)[]
13
- ): UserAttributes =>
14
- // TODO: Implement fetching based on attributes
15
- ({
16
- isLoggedIn: true,
17
- name: 'Donald Duck',
14
+ attributes: Array<keyof UserAttributes>,
15
+ onDataUpdated: (attributes: UserAttributes) => void
16
+ ) => {
17
+ const requiredServices: Array<() => Promise<UserAttributes>> = [];
18
+ attributes.forEach((attribute) => {
19
+ const service = dataServiceMap[attribute];
20
+ if (!service) {
21
+ console.warn('Unknown attribute was requested');
22
+ return;
23
+ }
24
+ if (!requiredServices.includes(service)) {
25
+ requiredServices.push(service);
26
+ }
18
27
  });
28
+
29
+ while (requiredServices.length > 0) {
30
+ const service = requiredServices.pop();
31
+ if (service) {
32
+ service().then((a) => {
33
+ onDataUpdated(a);
34
+ });
35
+ }
36
+ }
37
+ };
@@ -20,8 +20,9 @@ describe('Pluto service', () => {
20
20
  };
21
21
  fetch.mockResponseOnce(JSON.stringify(data));
22
22
 
23
- getCurrentSession().then((res) => {
24
- expect(res).toEqual(data);
23
+ expect(getCurrentSession()).resolves.toEqual({
24
+ name: 'Earl Hickey',
25
+ trackingKey: 'some tracking key',
25
26
  });
26
27
  expect(fetch).toHaveBeenCalledTimes(1);
27
28
  });
@@ -1,17 +1,21 @@
1
- import { Optional, Record, Static, String } from 'runtypes';
1
+ import { Record, Static, String } from 'runtypes';
2
2
 
3
- export const SessionSchema = Record({
4
- created_at: String,
5
- updated_at: String,
6
- user_uuid: String,
3
+ const SessionSchema = Record({
7
4
  user_name: String,
8
5
  tracking_key: String,
9
- user_agent: Optional(String),
6
+ });
7
+
8
+ export const Session = Record({
9
+ name: String,
10
+ trackingKey: String,
11
+ });
12
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
13
+ export type Session = Static<typeof Session>;
10
14
 
11
- // @deprecated Use tracking_key
12
- user_key: Optional(String),
15
+ const mapSession = (session: Static<typeof SessionSchema>): Session => ({
16
+ name: session.user_name,
17
+ trackingKey: session.tracking_key,
13
18
  });
14
- export type Session = Static<typeof SessionSchema>;
15
19
 
16
20
  export const getCurrentSession = async (): Promise<Session> =>
17
21
  fetch(`/api/pluto/v1/sessions/current`)
@@ -26,7 +30,7 @@ export const getCurrentSession = async (): Promise<Session> =>
26
30
  })
27
31
  .then((json) => {
28
32
  try {
29
- return SessionSchema.check(json);
33
+ return mapSession(SessionSchema.check(json));
30
34
  } catch (error) {
31
35
  console.error('Invalid schema', error);
32
36
  throw error;
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+ export type UserAttributes = {
2
+ isLoggedIn: boolean;
3
+ name?: string;
4
+ email?: string;
5
+ phone?: string;
6
+ trackingKey?: string;
7
+ extraData: [];
8
+ access: string[];
9
+ };
10
+
11
+ export type AnonymousAttributes = {
12
+ age: number;
13
+ };
@@ -0,0 +1,42 @@
1
+ let rootElement = window || global;
2
+
3
+ export const setRootElement = (element) => {
4
+ rootElement = element;
5
+ };
6
+
7
+ /**
8
+ * This listener MUST be used by all listeners in ../eventHandlers
9
+ * We want to ensure that only _one_ instance of this package actually
10
+ * orchestrates data and performs requests against backends.
11
+ * @param type
12
+ * @param listener
13
+ */
14
+ export const listenWithExclusivity = <T extends keyof WindowEventMap>(
15
+ type: T,
16
+ listener: (this: Window, ev: WindowEventMap[T]) => void
17
+ ) => {
18
+ rootElement.addEventListener(type, (evt) => {
19
+ // Since this lib might me loaded multiple times, we need to prevent all other processing of this event.
20
+ evt.stopImmediatePropagation();
21
+ listener.apply(window, [evt]);
22
+ });
23
+ };
24
+
25
+ /**
26
+ * Use this for response listeners. (../index.ts) where we want
27
+ * all updates with data - no matter who sent the actual request
28
+ * @param type
29
+ * @param listener
30
+ */
31
+ export const listenForAllEvents = <T extends keyof WindowEventMap>(
32
+ type: T,
33
+ listener: (this: Window, ev: WindowEventMap[T]) => void
34
+ ) => {
35
+ rootElement.addEventListener(type, (evt) => {
36
+ listener.apply(window, [evt]);
37
+ });
38
+ };
39
+
40
+ export const dispatch = <T extends Event>(event: T) => {
41
+ rootElement.dispatchEvent(event);
42
+ };
@@ -0,0 +1,7 @@
1
+ // TODO: Actually support logging in some form..
2
+ export default {
3
+ debug: console.debug,
4
+ info: console.log,
5
+ warning: console.warn,
6
+ error: console.error,
7
+ };
package/tsconfig.json CHANGED
@@ -1,14 +1,12 @@
1
1
  {
2
2
  "extends": "@amedia/eslint-config-typescript/tsconfig.json",
3
3
  "compilerOptions": {
4
- //"outDir": "./dist/",
5
- "outFile": "./dist/index.js",
4
+ "outDir": "./dist/",
6
5
  "rootDir": "./src",
7
6
  "typeRoots": [
8
7
  "./node_modules/@types"
9
8
  ],
10
- //"module": "ES6",
11
- "module": "AMD",
9
+ "module": "ES6",
12
10
  "lib": [
13
11
  "DOM"
14
12
  ],
@@ -0,0 +1,25 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './src/index.ts',
5
+ module: {
6
+ rules: [
7
+ {
8
+ test: /\.tsx?$/,
9
+ use: 'ts-loader',
10
+ exclude: /node_modules/,
11
+ },
12
+ ],
13
+ },
14
+ resolve: {
15
+ extensions: ['.tsx', '.ts', '.js'],
16
+ },
17
+ output: {
18
+ path: path.resolve(__dirname, 'dist'),
19
+ filename: 'index.js',
20
+ library: {
21
+ name: 'user',
22
+ type: 'umd',
23
+ },
24
+ },
25
+ };
@@ -1,94 +0,0 @@
1
- import cache from '../services/cache';
2
- import { getCurrentSession, Session, SessionSchema } from '../services/pluto';
3
- import { dispatch, listen } from './eventHandler';
4
-
5
- const EXPIRES_OFFSET = 10000; // 10 seconds
6
-
7
- export enum AuthenticationEvents {
8
- REQUEST_LOGIN = 'amedia_user.authentication.request_login',
9
- REQUEST_LOGOUT = 'amedia_user.authentication.request_logout',
10
- REQUEST_AUTH_STATE = 'amedia_user.authentication.request_auth_state',
11
- ON_AUTH_STATE_UPDATED = 'amedia_user.authentication.on_auth_state_updated',
12
- }
13
-
14
- declare global {
15
- interface WindowEventMap {
16
- [AuthenticationEvents.REQUEST_LOGIN]: CustomEvent<{
17
- requestedUrl?: string;
18
- }>;
19
- [AuthenticationEvents.REQUEST_LOGOUT]: CustomEvent<{
20
- requestedUrl?: string;
21
- }>;
22
- [AuthenticationEvents.REQUEST_AUTH_STATE]: CustomEvent<Session>;
23
- [AuthenticationEvents.ON_AUTH_STATE_UPDATED]: CustomEvent<Session>;
24
- }
25
- }
26
-
27
- const login = (requestedUrl: string) => {
28
- // TODO Need to get environment smarts from incentive embed
29
- const url = new URL('https://aid.no/logg_inn/');
30
- url.searchParams.set('requestedUrl', requestedUrl || window.location.href);
31
- window.location.href = url.href;
32
- };
33
-
34
- const logout = () => {
35
- // TODO Perform logout
36
- };
37
-
38
- let isFetchingSession = false;
39
- const IS_LOGGED_IN_CACHE_KEY = 'is_logged_in';
40
- const getSession = async (): Promise<Session | null> => {
41
- if (isFetchingSession) {
42
- return null;
43
- }
44
- isFetchingSession = true;
45
-
46
- // Try the cache first
47
- const cacheResponse = await cache.get(IS_LOGGED_IN_CACHE_KEY, SessionSchema);
48
- if (cacheResponse) {
49
- isFetchingSession = false;
50
- return cacheResponse;
51
- }
52
-
53
- // Actually perform a request against backend for the session
54
- const session = await getCurrentSession();
55
- cache.set(IS_LOGGED_IN_CACHE_KEY, session, Date.now() + EXPIRES_OFFSET);
56
- isFetchingSession = false;
57
- return session;
58
- };
59
-
60
- export const listenForAuthenticationRequests = () => {
61
- listen(AuthenticationEvents.REQUEST_LOGIN, (evt) => {
62
- if (!window) {
63
- throw new Error('Cannot perform login in node-context yet!');
64
- }
65
- login(evt.detail.requestedUrl || window.location.href);
66
- });
67
-
68
- listen(AuthenticationEvents.REQUEST_LOGOUT, () => {
69
- if (!window) {
70
- throw new Error('Cannot perform login in node-context yet!');
71
- }
72
- logout();
73
- });
74
-
75
- listen(AuthenticationEvents.REQUEST_AUTH_STATE, (evt) => {
76
- // Since this lib might me loaded multiple times, we need to prevent all other processing of this event.
77
- evt.stopImmediatePropagation();
78
-
79
- getSession().then((session) => {
80
- // Supports not getting a response. We're probably working on it already and will emit
81
- // events on window / global when complete.
82
- if (session === null) {
83
- return;
84
- }
85
- dispatch(
86
- new CustomEvent(AuthenticationEvents.ON_AUTH_STATE_UPDATED, {
87
- detail: session,
88
- })
89
- );
90
- });
91
- });
92
- };
93
-
94
- listenForAuthenticationRequests();
@@ -1,86 +0,0 @@
1
- import {
2
- AccessFeatures,
3
- CheckAccessForPaper,
4
- CheckAccessForPaperSchema,
5
- checkForAccess,
6
- } from '../services/jupiter';
7
- import cache from '../services/cache';
8
- import { dispatch, listen } from './eventHandler';
9
-
10
- const EXPIRES_OFFSET = 10000; // 10 seconds
11
- const CHECK_FOR_ACCESS_CACHE_KEY = 'check_for_access_to_publication';
12
- let isCheckingForAccess: boolean = false;
13
-
14
- export enum AuthorizationEvents {
15
- REQUEST_PUBLICATION_ACCESS_STATE_CHECK = 'amedia_user.authorization.request_publication_access_state_check',
16
- ON_PUBLICATION_ACCESS_STATE_UPDATED = 'amedia_user.authorization.on_publication_access_state_updated',
17
- }
18
-
19
- declare global {
20
- interface WindowEventMap {
21
- [AuthorizationEvents.REQUEST_PUBLICATION_ACCESS_STATE_CHECK]: CustomEvent<{
22
- publicationDomain: string;
23
- accessFeatures: AccessFeatures;
24
- }>;
25
- [AuthorizationEvents.ON_PUBLICATION_ACCESS_STATE_UPDATED]: CustomEvent<CheckAccessForPaper>;
26
- }
27
- }
28
-
29
- const checkForAccessToPublication = async (
30
- publicationDomain: string,
31
- accessFeatures: AccessFeatures
32
- ): Promise<CheckAccessForPaper | null> => {
33
- if (isCheckingForAccess) {
34
- return null;
35
- }
36
- isCheckingForAccess = true;
37
-
38
- // Try the cache first
39
- const cacheResponse = await cache.get(
40
- CHECK_FOR_ACCESS_CACHE_KEY,
41
- CheckAccessForPaperSchema
42
- );
43
- if (cacheResponse) {
44
- isCheckingForAccess = false;
45
- return cacheResponse;
46
- }
47
-
48
- // Actually perform a request against backend for the accessState
49
- const accessState = await checkForAccess(publicationDomain, accessFeatures);
50
- cache.set(
51
- CHECK_FOR_ACCESS_CACHE_KEY,
52
- accessState,
53
- Date.now() + EXPIRES_OFFSET
54
- );
55
-
56
- isCheckingForAccess = false;
57
-
58
- return accessState;
59
- };
60
-
61
- export const listenForAuthorizationRequests = () => {
62
- listen(AuthorizationEvents.REQUEST_PUBLICATION_ACCESS_STATE_CHECK, (evt) => {
63
- // Since this lib might me loaded multiple times, we need to prevent all other processing of this event.
64
- evt.stopImmediatePropagation();
65
- checkForAccessToPublication(
66
- evt.detail.publicationDomain,
67
- evt.detail.accessFeatures
68
- ).then((accessState) => {
69
- // Supports not getting a response. We're probably working on it already and will emit
70
- // events on window / global when complete.
71
- if (!accessState) {
72
- return;
73
- }
74
- dispatch(
75
- new CustomEvent(
76
- AuthorizationEvents.ON_PUBLICATION_ACCESS_STATE_UPDATED,
77
- {
78
- detail: accessState,
79
- }
80
- )
81
- );
82
- });
83
- });
84
- };
85
-
86
- listenForAuthorizationRequests();
@@ -1,16 +0,0 @@
1
- let rootElement = window || global;
2
-
3
- export const setRootElement = (element) => {
4
- rootElement = element;
5
- };
6
-
7
- export const listen = <T extends keyof WindowEventMap>(
8
- type: T,
9
- listener: (this: Window, ev: WindowEventMap[T]) => void
10
- ) => {
11
- rootElement.addEventListener(type, listener);
12
- };
13
-
14
- export const dispatch = <T extends Event>(event: T) => {
15
- rootElement.dispatchEvent(event);
16
- };
package/src/lib/types.ts DELETED
@@ -1,7 +0,0 @@
1
- export type UserAttributes = {
2
- isLoggedIn?: boolean;
3
- name?: string;
4
- email?: string;
5
- phone?: string;
6
- trackingKey?: string;
7
- };
File without changes