@amedia/user 0.7.0 → 0.7.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 (74) hide show
  1. package/dist/actions/authentication.d.ts +4 -0
  2. package/dist/actions/authorization.d.ts +3 -0
  3. package/dist/actions/preferences.d.ts +9 -0
  4. package/dist/actions/preferences.spec.d.ts +1 -0
  5. package/dist/actions/userData.d.ts +2 -0
  6. package/dist/cache/engines/global.d.ts +21 -0
  7. package/dist/cache/engines/global.spec.d.ts +1 -0
  8. package/dist/{lib/cache/db.d.ts → cache/engines/indexeddb.d.ts} +3 -2
  9. package/dist/cache/index.d.ts +11 -0
  10. package/dist/cache/index.spec.d.ts +4 -0
  11. package/dist/cache/types.d.ts +11 -0
  12. package/dist/clients/europa.d.ts +12 -0
  13. package/dist/clients/europa.spec.d.ts +1 -0
  14. package/dist/clients/jupiter.d.ts +29 -0
  15. package/dist/clients/jupiter.spec.d.ts +1 -0
  16. package/dist/clients/mercury.d.ts +18 -0
  17. package/dist/clients/mercury.spec.d.ts +4 -0
  18. package/dist/clients/nebula.d.ts +2 -0
  19. package/dist/clients/nebula.spec.d.ts +1 -0
  20. package/dist/clients/pluto.d.ts +3 -0
  21. package/dist/clients/pluto.spec.d.ts +1 -0
  22. package/dist/eventHandlers/activation.d.ts +15 -0
  23. package/dist/eventHandlers/authentication.d.ts +17 -0
  24. package/dist/eventHandlers/userAttributes.d.ts +14 -0
  25. package/dist/index-authentcation.spec.d.ts +4 -0
  26. package/dist/index-subscription.spec.d.ts +4 -0
  27. package/dist/index-userdata.spec.d.ts +4 -0
  28. package/dist/index.d.ts +17 -6
  29. package/dist/index.js +2 -7
  30. package/dist/index.js.LICENSE.txt +23 -0
  31. package/dist/lib/cookie.d.ts +5 -0
  32. package/dist/lib/rpc.d.ts +6 -0
  33. package/dist/services/europa.d.ts +12 -0
  34. package/dist/services/europa.spec.d.ts +1 -0
  35. package/dist/services/jupiter.d.ts +4 -4
  36. package/dist/services/jupiter.spec.d.ts +1 -0
  37. package/dist/services/mercury.d.ts +18 -0
  38. package/dist/services/mercury.spec.d.ts +4 -0
  39. package/dist/services/nebula.d.ts +22 -0
  40. package/dist/services/nebula.spec.d.ts +1 -0
  41. package/dist/services/pluto.d.ts +6 -10
  42. package/dist/services/pluto.spec.d.ts +1 -0
  43. package/dist/store/index.d.ts +13 -0
  44. package/dist/store/index.spec.d.ts +1 -0
  45. package/dist/store/store.d.ts +13 -0
  46. package/dist/store/store.spec.d.ts +1 -0
  47. package/dist/types.d.ts +24 -0
  48. package/dist/utils/customEventWrapper.d.ts +17 -0
  49. package/dist/utils/getOrUpdate.d.ts +6 -0
  50. package/dist/utils/log.d.ts +26 -0
  51. package/dist/utils/queue.d.ts +12 -0
  52. package/dist/utils/url.d.ts +3 -0
  53. package/dist/utils/url.spec.d.ts +1 -0
  54. package/package.json +1 -1
  55. package/src/actions/userData.ts +10 -8
  56. package/dist/lib/authentication.d.ts +0 -17
  57. package/dist/lib/authentication.js +0 -74
  58. package/dist/lib/authorization.d.ts +0 -14
  59. package/dist/lib/authorization.js +0 -51
  60. package/dist/lib/cache/db.js +0 -13
  61. package/dist/lib/cache/global.d.ts +0 -9
  62. package/dist/lib/cache/global.js +0 -16
  63. package/dist/lib/cache/types.d.ts +0 -5
  64. package/dist/lib/cache/types.js +0 -2
  65. package/dist/lib/queue.d.ts +0 -5
  66. package/dist/lib/queue.js +0 -17
  67. package/dist/lib/tools.d.ts +0 -1
  68. package/dist/lib/tools.js +0 -2
  69. package/dist/lib/user.d.ts +0 -2
  70. package/dist/lib/user.js +0 -3
  71. package/dist/services/cache.d.ts +0 -9
  72. package/dist/services/cache.js +0 -34
  73. package/dist/services/jupiter.js +0 -72
  74. package/dist/services/pluto.js +0 -40
@@ -0,0 +1,4 @@
1
+ import { UserAttributes } from '../types';
2
+ export declare const login: (requestedUrl: string) => void;
3
+ export declare const logout: () => Promise<void>;
4
+ export declare const getSession: () => Promise<UserAttributes>;
@@ -0,0 +1,3 @@
1
+ import { UserAttributes } from '../types';
2
+ export declare const getAccess: () => Promise<Pick<UserAttributes, 'access'>>;
3
+ export declare const activate: (accessFeature: string) => Promise<boolean>;
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { UserAttributes } from '../types';
2
+ export declare const requestAttributes: (attributes: Array<keyof UserAttributes>) => void;
@@ -0,0 +1,21 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
- import { Engine } from './types';
2
- export declare const get: (key: string) => Promise<unknown>;
1
+ import { CacheEntry, Engine } from '../types';
2
+ export declare const get: (key: string) => Promise<CacheEntry>;
3
3
  export declare const set: (key: string, data: unknown, expires: number) => Promise<void>;
4
4
  export declare const remove: (key: string) => Promise<void>;
5
+ export declare const clear: () => Promise<void>;
5
6
  declare const _default: Engine;
6
7
  export default _default;
@@ -0,0 +1,11 @@
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;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,11 @@
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
+ };
@@ -0,0 +1,12 @@
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>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
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 {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
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;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,2 @@
1
+ import { UserAttributes } from '../types';
2
+ export declare const getInfo: (publicationDomain: string, browserId: string, userKey?: string | undefined) => Promise<Pick<UserAttributes, 'extraData'>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { UserAttributes } from '../types';
2
+ export declare const getCurrentSession: () => Promise<UserAttributes>;
3
+ export declare const removeSession: (domain: string) => Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
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
+ accessFeature: string;
9
+ }>;
10
+ [ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
11
+ hasAccess: boolean;
12
+ }>;
13
+ }
14
+ }
15
+ export declare const listenForActivationRequests: () => void;
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,14 @@
1
+ import { State, UserAttributes } from '../types';
2
+ export declare enum AmediaUserEvents {
3
+ REQUEST_USER_ATTRIBUTES = "amedia-user.request-user-attributes",
4
+ ON_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated",
5
+ ON_STATE_UPDATED = "amedia-user.on-state-updated"
6
+ }
7
+ declare global {
8
+ interface WindowEventMap {
9
+ [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
10
+ [AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
11
+ [AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
12
+ }
13
+ }
14
+ export declare const listenForUserAttributeRequests: () => void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,17 @@
1
- import { AuthorizationEvents } from './lib/authorization';
2
- import { AuthenticationEvents } from './lib/authentication';
3
- export declare const AmediaUserEvents: {
4
- authentication: typeof AuthenticationEvents;
5
- authorization: typeof AuthorizationEvents;
6
- };
1
+ import 'regenerator-runtime';
2
+ import { State, UserAttributes } from './types';
3
+ /**
4
+ * Enables you to subscribe to the user attributes you care about and
5
+ * get notified when something changes
6
+ */
7
+ export declare const subscribeToUserAttributes: <T extends (keyof UserAttributes)[]>(attributes: T, onUserUpdated: (attributes: Pick<UserAttributes, T[number]>) => void, onStateUpdated?: ((attributes: State) => void) | undefined) => void;
8
+ /**
9
+ * This will, if necessary, trigger a redirect to www.aid.no and return
10
+ * to the requestedUrl if supplied or the current url before redirecting away if not.
11
+ * @param requestedUrl
12
+ */
13
+ export declare const goToLoginPage: (requestedUrl?: string | undefined) => void;
14
+ export declare const logout: () => Promise<void>;
15
+ export declare const tryActivateSubscriptionAccess: (access: string) => Promise<{
16
+ hasAccess: boolean;
17
+ }>;