@amedia/user 0.13.26 → 0.13.28

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 (80) hide show
  1. package/amedia-user-js.iml +9 -0
  2. package/checkVersion.js +12 -0
  3. package/dist/cache/engines/indexeddb.d.ts +7 -0
  4. package/dist/clients/europa.d.ts +3 -7
  5. package/dist/index.d.ts +36 -7
  6. package/dist/index.esm.js +1 -1
  7. package/dist/index.esm.js.map +3 -3
  8. package/dist/index.js +1 -1
  9. package/dist/index.js.LICENSE.txt +14 -0
  10. package/dist/index.js.map +3 -3
  11. package/dist/janitor/index.spec.d.ts +4 -0
  12. package/dist/lib/PaywallUnlocker.d.ts +16 -0
  13. package/dist/lib/PaywallUnlocker.spec.d.ts +4 -0
  14. package/dist/lib/User.d.ts +21 -0
  15. package/dist/utils/debouncer.d.ts +26 -0
  16. package/dist/utils/debouncer.spec.d.ts +1 -0
  17. package/dist/utils/logValidationError.d.ts +1 -0
  18. package/eik.json +1 -1
  19. package/esm/actions/authentication.d.ts +5 -0
  20. package/esm/actions/authentication.spec.d.ts +4 -0
  21. package/esm/actions/authorization.d.ts +9 -0
  22. package/esm/actions/preferences.d.ts +9 -0
  23. package/esm/actions/preferences.spec.d.ts +1 -0
  24. package/esm/actions/storage.d.ts +4 -0
  25. package/esm/actions/userData.d.ts +2 -0
  26. package/esm/autologin/index.d.ts +1 -0
  27. package/esm/autologin/thirdPartyCookie.d.ts +3 -0
  28. package/esm/autologin/thirdPartyCookie.spec.d.ts +1 -0
  29. package/esm/cache/engines/global.d.ts +21 -0
  30. package/esm/cache/engines/global.spec.d.ts +1 -0
  31. package/esm/cache/engines/indexeddb.d.ts +7 -0
  32. package/esm/cache/index.d.ts +11 -0
  33. package/esm/cache/index.spec.d.ts +4 -0
  34. package/esm/cache/types.d.ts +11 -0
  35. package/esm/clients/europa.d.ts +28 -0
  36. package/esm/clients/europa.spec.d.ts +1 -0
  37. package/esm/clients/jupiter.d.ts +30 -0
  38. package/esm/clients/jupiter.spec.d.ts +1 -0
  39. package/esm/clients/mercury.d.ts +18 -0
  40. package/esm/clients/mercury.spec.d.ts +4 -0
  41. package/esm/clients/nebula.d.ts +2 -0
  42. package/esm/clients/nebula.spec.d.ts +1 -0
  43. package/esm/clients/pluto.d.ts +3 -0
  44. package/esm/clients/pluto.spec.d.ts +1 -0
  45. package/esm/eventHandlers/activation.d.ts +15 -0
  46. package/esm/eventHandlers/authentication.d.ts +17 -0
  47. package/esm/eventHandlers/userAttributes.d.ts +24 -0
  48. package/esm/exceptions/PaywallError.d.ts +7 -0
  49. package/esm/index-authentcation.spec.d.ts +4 -0
  50. package/esm/index-storage.spec.d.ts +4 -0
  51. package/esm/index-subscription.spec.d.ts +4 -0
  52. package/esm/index.d.ts +26 -0
  53. package/esm/janitor/index.d.ts +10 -0
  54. package/esm/janitor/jobs/accessCookieRefresher.d.ts +1 -0
  55. package/esm/janitor/jobs/accessCookieRefresher.spec.d.ts +4 -0
  56. package/esm/lib/PaywallUnlocker.d.ts +16 -0
  57. package/esm/lib/PaywallUnlocker.spec.d.ts +4 -0
  58. package/esm/lib/User.d.ts +21 -0
  59. package/esm/lib/cookie.d.ts +5 -0
  60. package/esm/lib/rpc.d.ts +6 -0
  61. package/esm/store/index.d.ts +22 -0
  62. package/esm/store/index.spec.d.ts +1 -0
  63. package/esm/types.d.ts +22 -0
  64. package/esm/user.js +2 -0
  65. package/esm/user.js.map +1 -0
  66. package/esm/utils/customEventWrapper.d.ts +17 -0
  67. package/esm/utils/deepEquals.d.ts +4 -0
  68. package/esm/utils/getOrUpdate.d.ts +6 -0
  69. package/esm/utils/getOrUpdate.spec.d.ts +1 -0
  70. package/esm/utils/location.d.ts +3 -0
  71. package/esm/utils/log.d.ts +26 -0
  72. package/esm/utils/queue.d.ts +12 -0
  73. package/esm/utils/url.d.ts +6 -0
  74. package/esm/utils/url.spec.d.ts +1 -0
  75. package/package.json +3 -2
  76. package/src/clients/europa.spec.ts +8 -13
  77. package/src/clients/europa.ts +41 -40
  78. package/src/clients/mercuryLog.ts +3 -1
  79. package/src/utils/debouncer.spec.ts +257 -0
  80. package/src/utils/debouncer.ts +123 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,16 @@
1
+ declare class PaywallUnlocker {
2
+ private requestedAccessFeatures;
3
+ private reload;
4
+ private requestedUrl;
5
+ withAccessFeatures(accessFeatures: string[]): this;
6
+ reloadOnAccess(): this;
7
+ redirectOnAccess(requestedUrl: string): this;
8
+ tryUnlock(): Promise<{
9
+ isLoggedIn: boolean;
10
+ hasAccess: boolean;
11
+ accessFeatures: string[];
12
+ }>;
13
+ private resolveActualAccessFeatures;
14
+ private setAccessCookiesAndPerformRequestedActions;
15
+ }
16
+ export default PaywallUnlocker;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,21 @@
1
+ import { State, UserAttributes } from '../types';
2
+ declare class User<UA extends UserAttributes, S extends {
3
+ [index: string]: unknown;
4
+ }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends {} = {
5
+ state: State;
6
+ }> {
7
+ private attributes?;
8
+ private namespaces?;
9
+ constructor(attributes?: Attributes | undefined, namespaces?: Namespaces | undefined);
10
+ withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): User<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
11
+ attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
12
+ }>;
13
+ withStorage<NewNamespaces extends Array<string>>(...namespace: NewNamespaces): User<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
14
+ storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
15
+ }>;
16
+ subscribe(onData: (data: SubscribeResponse) => void): void;
17
+ private processUserAttributesEvent;
18
+ private processStorageEvent;
19
+ private setupLocalCache;
20
+ }
21
+ export default User;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The Debouncer can be used when we want a clean way to say 'I want to fetch this and that, and once it's done,
3
+ * resolve my promise', but instead of the fetch being performed right away, we want to wait for more users to
4
+ * request other stuff. This will keep us from performing lots of individual fetches to the backend.
5
+ *
6
+ * Our main use case is a standard publication front page where one component on the page requests the euucp namespace
7
+ * from Europa, and then another component requests the privacy_preferences namespace. Instead of the Europa client
8
+ * calling two fetches to the server, one for euucp and another for privacy_preferences, we want the Debouncer to
9
+ * aggregate these calls into one call to the backend, that requests both euucp AND privacy_preferences, so the response
10
+ * to both components will be both namespaces (which the Europa client can filter before it actually reaches the
11
+ * component).
12
+ */
13
+ declare class Debouncer<ParamsType, ResultType> {
14
+ private timeoutMs;
15
+ private defaultParams;
16
+ private paramAccumulator;
17
+ private workload;
18
+ private timer;
19
+ private params;
20
+ private queue;
21
+ constructor(timeoutMs: number, defaultParams: ParamsType, paramAccumulator: (previousParams: ParamsType, newParams: ParamsType) => ParamsType, workload: (params: ParamsType) => Promise<ResultType>);
22
+ perform(newParams: ParamsType): Promise<ResultType>;
23
+ static stringListParamsAccumulator(accumulatedParams: string[], newParams: string[]): string[];
24
+ static stringMapParamsAccumulator(previousParams: Record<string, any>, newParams: Record<string, any>): Record<string, any>;
25
+ }
26
+ export default Debouncer;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export default function logValidationError(name: string, error: Error, extra?: Object): void;
package/eik.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "user",
3
- "version": "0.13.26",
3
+ "version": "0.13.28",
4
4
  "server": "https://assets.acdn.no",
5
5
  "files": {
6
6
  "user.js": "./dist/index.esm.js",
@@ -0,0 +1,5 @@
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;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,9 @@
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 setUserAccessCookie: (publicationDomain: any) => Promise<boolean>;
6
+ export declare const setNonUserAccessCookie: (publicationDomain: any) => Promise<boolean>;
7
+ export declare const hasRecentlyTriedToUnlockPaywall: () => boolean;
8
+ export declare const setAccessCookies: (publicationDomain: any) => Promise<boolean>;
9
+ export declare const setHasTriedToUnlockPaywall: () => void;
@@ -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<Pick<UserAttributes, 'privacyPreferences'>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export declare const requestStorage: (namespaces: string[]) => void;
2
+ export declare const updateStorage: (storage: {
3
+ [namespace: string]: object;
4
+ }) => void;
@@ -0,0 +1,2 @@
1
+ import { UserAttributes } from '../types';
2
+ export declare const requestAttributes: (attributes: Array<keyof UserAttributes>) => void;
@@ -0,0 +1 @@
1
+ export declare const attemptAutologin: () => Promise<void>;
@@ -0,0 +1,3 @@
1
+ export declare const CACHE_KEY = "haveTriedThirdPartyLoginCheck";
2
+ export declare const CACHE_TTL: number;
3
+ export default function thirdPartyCookie(): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -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 {};
@@ -0,0 +1,7 @@
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;
@@ -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,28 @@
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>>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
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 {};
@@ -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: (accessFeatures: 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
+ accessFeatures: string[];
9
+ }>;
10
+ [ActivationEvents.ON_ACTIVATION_COMPLETE]: CustomEvent<{
11
+ accessFeatures: string[];
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,24 @@
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
+ UPDATE_STORAGE = "amedua-user.update-storage-namespaces",
6
+ ON_ATTRIBUTES_UPDATED = "amedia-user.on-user-attributes-updated",
7
+ ON_STATE_UPDATED = "amedia-user.on-state-updated",
8
+ ON_STORAGE_UPDATED = "amedia-user.on-storage-updated"
9
+ }
10
+ declare global {
11
+ interface WindowEventMap {
12
+ [AmediaUserEvents.REQUEST_USER_ATTRIBUTES]: CustomEvent<Array<keyof UserAttributes>>;
13
+ [AmediaUserEvents.REQUEST_STORAGE_NAMESPACES]: CustomEvent<Array<string>>;
14
+ [AmediaUserEvents.UPDATE_STORAGE]: CustomEvent<{
15
+ [namespace: string]: object;
16
+ }>;
17
+ [AmediaUserEvents.ON_ATTRIBUTES_UPDATED]: CustomEvent<UserAttributes>;
18
+ [AmediaUserEvents.ON_STATE_UPDATED]: CustomEvent<State>;
19
+ [AmediaUserEvents.ON_STORAGE_UPDATED]: CustomEvent<{
20
+ [index: string]: unknown;
21
+ }>;
22
+ }
23
+ }
24
+ export declare const listenForUserAttributeRequests: () => void;
@@ -0,0 +1,7 @@
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;
@@ -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/esm/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import 'regenerator-runtime';
2
+ import User from './lib/User';
3
+ import PaywallUnlocker from './lib/PaywallUnlocker';
4
+ /**
5
+ * Enables you to subscribe to the user attributes you care about and
6
+ * get notified when something changes
7
+ */
8
+ export declare const user: () => User<import("./types").UserAttributes, {
9
+ [index: string]: unknown;
10
+ }, (keyof import("./types").UserAttributes)[], string[], {
11
+ state: import("./types").State;
12
+ }>;
13
+ /**
14
+ * This will, if necessary, trigger a redirect to www.aid.no and return
15
+ * to the requestedUrl if supplied or the current url before redirecting away if not.
16
+ * @param requestedUrl
17
+ */
18
+ export declare const goToLoginPage: (requestedUrl?: string | undefined) => void;
19
+ export declare const logout: () => Promise<void>;
20
+ export declare const tryActivateSubscriptionAccess: (accessFeatures: string[]) => Promise<{
21
+ hasAccess: boolean;
22
+ }>;
23
+ export declare const paywall: () => PaywallUnlocker;
24
+ export declare const updateStorage: (storage: {
25
+ [index: string]: Object;
26
+ }) => void;
@@ -0,0 +1,10 @@
1
+ declare enum JanitorEvents {
2
+ LOADED = "amedia-user.janitor.loaded"
3
+ }
4
+ declare global {
5
+ interface WindowEventMap {
6
+ [JanitorEvents.LOADED]: CustomEvent<{}>;
7
+ }
8
+ }
9
+ export declare const runJanitor: () => Promise<void>;
10
+ export {};
@@ -0,0 +1 @@
1
+ export default function accessCookieRefresher(): Promise<[void, void]>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,16 @@
1
+ declare class PaywallUnlocker {
2
+ private requestedAccessFeatures;
3
+ private reload;
4
+ private requestedUrl;
5
+ withAccessFeatures(accessFeatures: string[]): this;
6
+ reloadOnAccess(): this;
7
+ redirectOnAccess(requestedUrl: string): this;
8
+ tryUnlock(): Promise<{
9
+ isLoggedIn: boolean;
10
+ hasAccess: boolean;
11
+ accessFeatures: string[];
12
+ }>;
13
+ private resolveActualAccessFeatures;
14
+ private setAccessCookiesAndPerformRequestedActions;
15
+ }
16
+ export default PaywallUnlocker;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ export {};
@@ -0,0 +1,21 @@
1
+ import { State, UserAttributes } from '../types';
2
+ declare class User<UA extends UserAttributes, S extends {
3
+ [index: string]: unknown;
4
+ }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends {} = {
5
+ state: State;
6
+ }> {
7
+ private attributes?;
8
+ private namespaces?;
9
+ constructor(attributes?: Attributes | undefined, namespaces?: Namespaces | undefined);
10
+ withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): User<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
11
+ attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
12
+ }>;
13
+ withStorage<NewNamespaces extends Array<string>>(...namespace: NewNamespaces): User<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
14
+ storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
15
+ }>;
16
+ subscribe(onData: (data: SubscribeResponse) => void): void;
17
+ private processUserAttributesEvent;
18
+ private processStorageEvent;
19
+ private setupLocalCache;
20
+ }
21
+ export default User;
@@ -0,0 +1,5 @@
1
+ export declare const getCookie: (name: string) => string | {
2
+ [index: string]: unknown;
3
+ } | null | undefined;
4
+ export declare function setCookie(name: string, value?: unknown, validTimeInDateOrDays?: Date | number, path?: string, secure?: boolean): string;
5
+ export declare function removeCookie(name: string): void;
@@ -0,0 +1,6 @@
1
+ declare let rpcSessionClient: {
2
+ addMethod: (methodName: string) => void;
3
+ userAuthenticated: (boolean: any) => void;
4
+ };
5
+ export declare const getRPCClient: () => Pick<typeof rpcSessionClient, 'userAuthenticated'>;
6
+ export {};
@@ -0,0 +1,22 @@
1
+ import { State, UserAttributes } from '../types';
2
+ declare type StoreDataMap = {
3
+ userAttributes: UserAttributes;
4
+ state: State;
5
+ storage: {
6
+ [namespace: string]: {
7
+ [index: string]: unknown;
8
+ };
9
+ };
10
+ };
11
+ declare type Listener<T> = (data: T) => void;
12
+ declare const _default: {
13
+ set: (key: keyof StoreDataMap, value: UserAttributes | State | {
14
+ [namespace: string]: {
15
+ [index: string]: unknown;
16
+ };
17
+ }) => void;
18
+ get: <K extends keyof StoreDataMap, T = StoreDataMap[K]>(key: K) => T | undefined;
19
+ on: <K_1 extends keyof StoreDataMap, T_1 = StoreDataMap[K_1]>(key: K_1, listener: Listener<T_1>) => void;
20
+ clear: () => void;
21
+ };
22
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
package/esm/types.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export declare type UserAttributes = {
2
+ uuid?: string;
3
+ name?: string;
4
+ email?: string;
5
+ phone?: string;
6
+ trackingKey?: string;
7
+ extraData?: {
8
+ [index: string]: unknown;
9
+ };
10
+ access?: string[];
11
+ privacyPreferences?: PrivacyPreferences;
12
+ };
13
+ export declare type State = {
14
+ isLoggedIn: boolean;
15
+ emergencyMode?: string[];
16
+ };
17
+ export declare type PrivacyPreferences = {
18
+ allowResearchUsage: boolean;
19
+ connectWithSurveys: boolean;
20
+ personalizedAds: boolean;
21
+ personalizedContent: boolean;
22
+ };