@amedia/user 0.3.2 → 0.4.1

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 (59) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc +8 -3
  3. package/dist/actions/authentication.d.ts +1 -1
  4. package/dist/actions/authorization.d.ts +6 -2
  5. package/dist/cache/engines/global.d.ts +15 -0
  6. package/dist/cache/engines/global.spec.d.ts +1 -0
  7. package/dist/cache/engines/indexeddb.d.ts +1 -0
  8. package/dist/cache/index.d.ts +1 -0
  9. package/dist/cache/index.spec.d.ts +4 -0
  10. package/dist/cache/types.d.ts +1 -0
  11. package/dist/eventHandlers/authentication.d.ts +5 -3
  12. package/dist/index-authentcation.spec.d.ts +4 -0
  13. package/dist/index-userdata.spec.d.ts +4 -0
  14. package/dist/index.d.ts +3 -1
  15. package/dist/index.js +1 -1
  16. package/dist/lib/cookie.d.ts +5 -0
  17. package/dist/lib/rpc.d.ts +1 -0
  18. package/dist/services/jupiter.spec.d.ts +1 -0
  19. package/dist/services/mercury.spec.d.ts +4 -0
  20. package/dist/services/pluto.d.ts +2 -2
  21. package/dist/services/pluto.spec.d.ts +1 -0
  22. package/dist/utils/log.d.ts +7 -0
  23. package/dist/utils/queue.d.ts +9 -2
  24. package/package.json +5 -4
  25. package/src/actions/authentication.ts +28 -5
  26. package/src/actions/authorization.ts +42 -38
  27. package/src/{lib/dataOrganizer.ts → actions/userData.ts} +5 -2
  28. package/src/cache/engines/global.spec.ts +62 -0
  29. package/src/cache/engines/global.ts +25 -7
  30. package/src/cache/engines/indexeddb.ts +3 -1
  31. package/src/cache/index.spec.ts +33 -1
  32. package/src/cache/index.ts +8 -1
  33. package/src/cache/types.ts +1 -0
  34. package/src/eventHandlers/authentication.ts +10 -5
  35. package/src/eventHandlers/userAttributes.ts +1 -1
  36. package/src/index-authentcation.spec.ts +44 -0
  37. package/src/{index.spec.ts → index-userdata.spec.ts} +8 -15
  38. package/src/index.ts +9 -6
  39. package/src/lib/cookie.ts +109 -0
  40. package/src/lib/rpc.ts +15 -0
  41. package/src/services/jupiter.spec.ts +5 -3
  42. package/src/services/jupiter.ts +5 -3
  43. package/src/services/pluto.ts +8 -6
  44. package/src/utils/log.ts +29 -2
  45. package/src/utils/queue.ts +19 -4
  46. package/tsconfig.json +2 -0
  47. package/webpack.config.js +1 -1
  48. package/.babelrc +0 -3
  49. package/dist/lib/authentication.d.ts +0 -20
  50. package/dist/lib/authorization.d.ts +0 -15
  51. package/dist/lib/cache/db.d.ts +0 -6
  52. package/dist/lib/cache/global.d.ts +0 -9
  53. package/dist/lib/cache/types.d.ts +0 -5
  54. package/dist/lib/eventHandler.d.ts +0 -3
  55. package/dist/lib/queue.d.ts +0 -5
  56. package/dist/lib/types.d.ts +0 -7
  57. package/dist/lib/userAttributes.d.ts +0 -12
  58. package/dist/services/cache.d.ts +0 -9
  59. /package/dist/{lib/dataOrganizer.d.ts → actions/userData.d.ts} +0 -0
@@ -1,10 +1,23 @@
1
- const queue: { [key: string]: unknown[] } = {};
1
+ import { Function } from 'runtypes';
2
2
 
3
- const add = (key: string, data: unknown): void => {
3
+ const queue: {
4
+ [key: string]: {
5
+ resolve: (PromiseLike) => void;
6
+ reject: (reason?) => void;
7
+ }[];
8
+ } = {};
9
+
10
+ const add = (
11
+ key: string,
12
+ promiseCallbacks: {
13
+ resolve: (PromiseLike) => void;
14
+ reject: (reason?) => void;
15
+ }
16
+ ): void => {
4
17
  if (!queue[key]) {
5
18
  queue[key] = [];
6
19
  }
7
- queue[key].push(data);
20
+ queue[key].push(promiseCallbacks);
8
21
  };
9
22
 
10
23
  const getAll = (key: string) => {
@@ -16,4 +29,6 @@ const getAll = (key: string) => {
16
29
  return keyQueue;
17
30
  };
18
31
 
19
- export default { add, getAll };
32
+ const peekQueueSize = (key: string): number => queue[key]?.length || 0;
33
+
34
+ export default { add, getAll, peekQueueSize };
package/tsconfig.json CHANGED
@@ -4,11 +4,13 @@
4
4
  "rootDir": "./src",
5
5
  "outDir": "./dist/",
6
6
  //"noImplicitAny": true,
7
+ "declaration": true,
7
8
  "typeRoots": [
8
9
  "./node_modules/@types"
9
10
  ],
10
11
  "lib": [
11
12
  "DOM"
12
13
  ],
14
+ "module": "ES2020"
13
15
  }
14
16
  }
package/webpack.config.js CHANGED
@@ -6,7 +6,7 @@ module.exports = {
6
6
  rules: [
7
7
  {
8
8
  test: /\.tsx?$/,
9
- use: 'babel-loader',
9
+ use: [/*'babel-loader',*/ 'ts-loader'],
10
10
  exclude: /node_modules/,
11
11
  },
12
12
  {
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@babel/typescript", ["@babel/env", {"modules": false}]]
3
- }
@@ -1,20 +0,0 @@
1
- import { Session } from '../services/pluto';
2
- export declare enum AuthenticationEvents {
3
- REQUEST_LOGIN = "amedia_user.authentication.request_login",
4
- REQUEST_LOGOUT = "amedia_user.authentication.request_logout",
5
- REQUEST_AUTH_STATE = "amedia_user.authentication.request_auth_state",
6
- ON_AUTH_STATE_UPDATED = "amedia_user.authentication.on_auth_state_updated"
7
- }
8
- declare global {
9
- interface WindowEventMap {
10
- [AuthenticationEvents.REQUEST_LOGIN]: CustomEvent<{
11
- requestedUrl?: string;
12
- }>;
13
- [AuthenticationEvents.REQUEST_LOGOUT]: CustomEvent<{
14
- requestedUrl?: string;
15
- }>;
16
- [AuthenticationEvents.REQUEST_AUTH_STATE]: CustomEvent<Session>;
17
- [AuthenticationEvents.ON_AUTH_STATE_UPDATED]: CustomEvent<Session>;
18
- }
19
- }
20
- export declare const listenForAuthenticationRequests: () => void;
@@ -1,15 +0,0 @@
1
- import { AccessFeatures, CheckAccessForPaper } from '../services/jupiter';
2
- export declare enum AuthorizationEvents {
3
- REQUEST_PUBLICATION_ACCESS_STATE_CHECK = "amedia_user.authorization.request_publication_access_state_check",
4
- ON_PUBLICATION_ACCESS_STATE_UPDATED = "amedia_user.authorization.on_publication_access_state_updated"
5
- }
6
- declare global {
7
- interface WindowEventMap {
8
- [AuthorizationEvents.REQUEST_PUBLICATION_ACCESS_STATE_CHECK]: CustomEvent<{
9
- publicationDomain: string;
10
- accessFeatures: AccessFeatures;
11
- }>;
12
- [AuthorizationEvents.ON_PUBLICATION_ACCESS_STATE_UPDATED]: CustomEvent<CheckAccessForPaper>;
13
- }
14
- }
15
- export declare const listenForAuthorizationRequests: () => void;
@@ -1,6 +0,0 @@
1
- import { Engine } from './types';
2
- export declare const get: (key: string) => Promise<unknown>;
3
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
4
- export declare const remove: (key: string) => Promise<void>;
5
- declare const _default: Engine;
6
- export default _default;
@@ -1,9 +0,0 @@
1
- export declare const get: (key: string) => Promise<unknown>;
2
- export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
3
- export declare const remove: (key: string) => Promise<void>;
4
- declare const _default: {
5
- get: (key: string) => Promise<unknown>;
6
- set: (key: string, data: unknown, expires: number) => Promise<void>;
7
- remove: (key: string) => Promise<void>;
8
- };
9
- export default _default;
@@ -1,5 +0,0 @@
1
- export declare type Engine = {
2
- get: (key: string) => Promise<unknown>;
3
- set: (key: string, data: unknown, expires: number) => Promise<void>;
4
- remove: (key: string) => Promise<void>;
5
- };
@@ -1,3 +0,0 @@
1
- export declare const setRootElement: (element: any) => void;
2
- export declare const listen: <T extends keyof WindowEventMap>(type: T, listener: (this: Window, ev: WindowEventMap[T]) => void) => void;
3
- export declare const dispatch: <T extends Event>(event: T) => void;
@@ -1,5 +0,0 @@
1
- declare const _default: {
2
- add: (key: string, data: unknown) => void;
3
- getAll: (key: string) => unknown[];
4
- };
5
- export default _default;
@@ -1,7 +0,0 @@
1
- export declare type UserAttributes = {
2
- isLoggedIn?: boolean;
3
- name?: string;
4
- email?: string;
5
- phone?: string;
6
- trackingKey?: string;
7
- };
@@ -1,12 +0,0 @@
1
- import { UserAttributes } from './types';
2
- export declare enum AmediaUserEvents {
3
- REQUEST_USER_ATTRIBUTES = "amedia-user.request-user-attributes",
4
- ON_USER_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated"
5
- }
6
- declare global {
7
- interface WindowEventMap {
8
- [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
9
- [AmediaUserEvents.ON_USER_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
10
- }
11
- }
12
- export declare const listenForUserAttributeRequests: () => void;
@@ -1,9 +0,0 @@
1
- import { Record, Static } from 'runtypes';
2
- import { Engine } from '../lib/cache/types';
3
- export declare const setCacheEngine: (engine: Engine) => void;
4
- declare const _default: {
5
- get: <T extends Record<any, any>>(key: string, validator: T) => Promise<void | Static<T>>;
6
- set: (key: string, value: unknown, expires: number) => Promise<void>;
7
- remove: (key: string) => Promise<void>;
8
- };
9
- export default _default;