@amedia/user 0.10.0 → 0.10.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.
- package/dist/actions/authentication.spec.d.ts +4 -0
- package/dist/index.js +1 -1
- package/dist/utils/location.d.ts +1 -0
- package/esm/actions/authentication.d.ts +5 -0
- package/esm/actions/authorization.d.ts +7 -0
- package/esm/actions/preferences.d.ts +9 -0
- package/esm/actions/preferences.spec.d.ts +1 -0
- package/esm/actions/storage.d.ts +1 -0
- package/esm/actions/userData.d.ts +2 -0
- package/esm/cache/engines/global.d.ts +21 -0
- package/esm/cache/engines/global.spec.d.ts +1 -0
- package/esm/cache/engines/indexeddb.d.ts +7 -0
- package/esm/cache/index.d.ts +11 -0
- package/esm/cache/index.spec.d.ts +4 -0
- package/esm/cache/types.d.ts +11 -0
- package/esm/clients/europa.d.ts +28 -0
- package/esm/clients/europa.spec.d.ts +1 -0
- package/esm/clients/jupiter.d.ts +30 -0
- package/esm/clients/jupiter.spec.d.ts +1 -0
- package/esm/clients/mercury.d.ts +18 -0
- package/esm/clients/mercury.spec.d.ts +4 -0
- package/esm/clients/nebula.d.ts +2 -0
- package/esm/clients/nebula.spec.d.ts +1 -0
- package/esm/clients/pluto.d.ts +3 -0
- package/esm/clients/pluto.spec.d.ts +1 -0
- package/esm/eventHandlers/activation.d.ts +15 -0
- package/esm/eventHandlers/authentication.d.ts +17 -0
- package/esm/eventHandlers/userAttributes.d.ts +20 -0
- package/esm/exceptions/PaywallError.d.ts +7 -0
- package/esm/index-authentcation.spec.d.ts +4 -0
- package/esm/index-subscription.spec.d.ts +4 -0
- package/esm/index.d.ts +23 -0
- package/esm/lib/PaywallUnlocker.d.ts +16 -0
- package/esm/lib/PaywallUnlocker.spec.d.ts +4 -0
- package/esm/lib/User.d.ts +21 -0
- package/esm/lib/cookie.d.ts +5 -0
- package/esm/lib/rpc.d.ts +6 -0
- package/esm/store/index.d.ts +22 -0
- package/esm/store/index.spec.d.ts +1 -0
- package/esm/types.d.ts +21 -0
- package/esm/user.js +1 -6498
- package/esm/user.js.map +1 -1
- package/esm/utils/customEventWrapper.d.ts +17 -0
- package/esm/utils/deepEquals.d.ts +4 -0
- package/esm/utils/getOrUpdate.d.ts +6 -0
- package/esm/utils/getOrUpdate.spec.d.ts +1 -0
- package/esm/utils/location.d.ts +2 -0
- package/esm/utils/log.d.ts +26 -0
- package/esm/utils/queue.d.ts +12 -0
- package/esm/utils/url.d.ts +3 -0
- package/esm/utils/url.spec.d.ts +1 -0
- package/package.json +1 -1
- package/src/actions/authentication.spec.ts +41 -0
- package/src/actions/authentication.ts +8 -4
- package/src/utils/location.ts +6 -4
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
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,20 @@
|
|
|
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;
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
@@ -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,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;
|
package/esm/lib/rpc.d.ts
ADDED
|
@@ -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,21 @@
|
|
|
1
|
+
export declare type UserAttributes = {
|
|
2
|
+
name?: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
phone?: string;
|
|
5
|
+
trackingKey?: string;
|
|
6
|
+
extraData?: {
|
|
7
|
+
[index: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
access?: string[];
|
|
10
|
+
privacyPreferences?: PrivacyPreferences;
|
|
11
|
+
};
|
|
12
|
+
export declare type State = {
|
|
13
|
+
isLoggedIn: boolean;
|
|
14
|
+
emergencyMode?: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare type PrivacyPreferences = {
|
|
17
|
+
allowResearchUsage: boolean;
|
|
18
|
+
connectWithSurveys: boolean;
|
|
19
|
+
personalizedAds: boolean;
|
|
20
|
+
personalizedContent: boolean;
|
|
21
|
+
};
|