@amedia/user 1.0.3 → 1.0.4
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/CHANGELOG.md +6 -0
- package/index.d.ts +185 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @amedia/user
|
|
2
2
|
|
|
3
|
+
## 1.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`6cb30de`](https://github.com/amedia/amedia-user-js/commit/6cb30de6b0e5cb66e11ee4f52a2a9393f6c6971e) Thanks [@emilhauk](https://github.com/emilhauk)! - Fix missing type definitions
|
|
8
|
+
|
|
3
9
|
## 1.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
type AccessFeatures = string[];
|
|
4
|
+
type UserAttributes = {
|
|
5
|
+
uuid: string | null;
|
|
6
|
+
name: string | null;
|
|
7
|
+
trackingKey: string | null;
|
|
8
|
+
avatar: string | null;
|
|
9
|
+
/** @deprecated use data from [@amedia/user-datapoints](https://github.com/amedia/amedia-user-datapoints) instead */
|
|
10
|
+
extraData: {
|
|
11
|
+
[index: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
access: AccessFeatures;
|
|
14
|
+
/** @deprecated Returns false for all keys. CMP data is now used. */
|
|
15
|
+
privacyPreferences: PrivacyPreferences | null;
|
|
16
|
+
sessionTrackingKey: string | null;
|
|
17
|
+
};
|
|
18
|
+
type State = {
|
|
19
|
+
isLoggedIn: boolean;
|
|
20
|
+
isCircuitBreakerTripped?: boolean;
|
|
21
|
+
emergencyMode?: string[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated This is set to false as default. CMP data is now used.
|
|
25
|
+
*/
|
|
26
|
+
type PrivacyPreferences = {
|
|
27
|
+
allowResearchUsage: boolean;
|
|
28
|
+
personalizedContent: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ClientId = string;
|
|
32
|
+
|
|
33
|
+
type NamespaceList = Array<string>;
|
|
34
|
+
|
|
35
|
+
type Millis = number;
|
|
36
|
+
type UnsubscribeFn = () => void;
|
|
37
|
+
declare class UserDataRequest<TUserAttributes extends UserAttributes, TStorage extends Record<ClientId, Record<string, string>>, TAttributes extends Array<keyof TUserAttributes>, TRequestedStorage extends Record<keyof TStorage, NamespaceList>, TSubscribeResponse extends Record<string, unknown> & {
|
|
38
|
+
state: State;
|
|
39
|
+
} = {
|
|
40
|
+
state: State;
|
|
41
|
+
}> {
|
|
42
|
+
private requestedAttributes?;
|
|
43
|
+
private requestedStorage?;
|
|
44
|
+
private requestedNonUserAccess;
|
|
45
|
+
private context;
|
|
46
|
+
static FETCH_TIMEOUT: Millis;
|
|
47
|
+
private static WITH_NON_USER_ACCESS;
|
|
48
|
+
private fetchTimeoutId;
|
|
49
|
+
private lastReceivedData?;
|
|
50
|
+
private subscriptionEventListeners;
|
|
51
|
+
constructor(requestedAttributes?: TAttributes, requestedStorage?: TRequestedStorage, requestedNonUserAccess?: boolean, context?: string);
|
|
52
|
+
withContext(context: string): this;
|
|
53
|
+
withAttributes<NewAttributes extends Array<keyof TUserAttributes>>(attributes: NewAttributes): UserDataRequest<TUserAttributes, TStorage, (TAttributes[number] & NewAttributes[number])[], TRequestedStorage, TSubscribeResponse & {
|
|
54
|
+
attributes: Pick<TUserAttributes, TAttributes[number] & NewAttributes[number]>;
|
|
55
|
+
}>;
|
|
56
|
+
withStorage(namespaces: Array<string>): UserDataRequest<TUserAttributes, TStorage, TAttributes, TRequestedStorage, TSubscribeResponse & {
|
|
57
|
+
storage: Record<string, Record<string, string>>;
|
|
58
|
+
}>;
|
|
59
|
+
withClientStorage(clientId: keyof TStorage, namespaces: Array<string>): UserDataRequest<TUserAttributes, TStorage, TAttributes, TRequestedStorage, TSubscribeResponse & {
|
|
60
|
+
clientStorage: Record<ClientId, (typeof namespaces)[number]>;
|
|
61
|
+
}>;
|
|
62
|
+
withNonUserAccess(): UserDataRequest<TUserAttributes, TStorage, TAttributes, TRequestedStorage, TSubscribeResponse & {
|
|
63
|
+
nonUserAccess: Array<Record<string, string>>;
|
|
64
|
+
}>;
|
|
65
|
+
subscribe(onData: (data: TSubscribeResponse) => void): UnsubscribeFn;
|
|
66
|
+
fetch(options?: {
|
|
67
|
+
timeout?: Millis;
|
|
68
|
+
}): Promise<TSubscribeResponse>;
|
|
69
|
+
private startFetchTimeout;
|
|
70
|
+
private clearFetchTimeout;
|
|
71
|
+
private restartFetchTimeout;
|
|
72
|
+
private unsubscribe;
|
|
73
|
+
private processUserAttributesEvent;
|
|
74
|
+
private processStorageEventDetail;
|
|
75
|
+
private setupLocalCache;
|
|
76
|
+
private debugLogFetchCompleted;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare enum AffiliationType {
|
|
80
|
+
ACCESS = "access",
|
|
81
|
+
FAMILY = "family",
|
|
82
|
+
SUBSCRIPTION = "subscription"
|
|
83
|
+
}
|
|
84
|
+
declare const PrimarySiteSchema: v.ObjectSchema<{
|
|
85
|
+
readonly domain: v.StringSchema<undefined>;
|
|
86
|
+
readonly name: v.StringSchema<undefined>;
|
|
87
|
+
readonly affiliation: v.LiteralSchema<AffiliationType.ACCESS, undefined>;
|
|
88
|
+
readonly affiliations: v.ArraySchema<v.UnionSchema<[v.LiteralSchema<AffiliationType.ACCESS, undefined>, v.LiteralSchema<AffiliationType.FAMILY, undefined>, v.LiteralSchema<AffiliationType.SUBSCRIPTION, undefined>], undefined>, undefined>;
|
|
89
|
+
}, undefined>;
|
|
90
|
+
type PrimarySite = v.InferOutput<typeof PrimarySiteSchema>;
|
|
91
|
+
|
|
92
|
+
type SiteAccessResponse = {
|
|
93
|
+
isLoggedIn: boolean;
|
|
94
|
+
hasAccess: boolean;
|
|
95
|
+
primarySite?: null | PrimarySite;
|
|
96
|
+
accessFeatures: string[];
|
|
97
|
+
};
|
|
98
|
+
declare class SiteAccessRequest {
|
|
99
|
+
private requiredAccessFeatures;
|
|
100
|
+
private siteDomain;
|
|
101
|
+
constructor(requiredAccessFeatures?: Array<string>);
|
|
102
|
+
withSiteDomain(siteDomain: string): this;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Required now. Set in constructor
|
|
105
|
+
*/
|
|
106
|
+
withAccessFeatures(accessFeatures: Array<string>): this;
|
|
107
|
+
requestAccess(): Promise<SiteAccessResponse>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type PaywallUnlockResponse = SiteAccessResponse;
|
|
111
|
+
declare class PaywallUnlockRequest {
|
|
112
|
+
private requestedAccessFeatures;
|
|
113
|
+
private reload;
|
|
114
|
+
private requestedUrl;
|
|
115
|
+
constructor(requestedAccessFeatures?: string[]);
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated Required now. Set in constructor
|
|
118
|
+
*/
|
|
119
|
+
withAccessFeatures(accessFeatures: string[]): this;
|
|
120
|
+
reloadOnAccess(): this;
|
|
121
|
+
redirectOnAccess(requestedUrl: string): this;
|
|
122
|
+
tryUnlock(): Promise<PaywallUnlockResponse>;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare class FetchTimeoutError extends Error {
|
|
126
|
+
partialData: Record<string, unknown>;
|
|
127
|
+
constructor(message: string, partialData: Record<string, unknown>);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare class PaywallError extends Error {
|
|
131
|
+
static ERROR_RELOADED_NO_ACCESS: string;
|
|
132
|
+
static ERROR_ENABLING_ACCESS_FAILED: string;
|
|
133
|
+
static ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES: string;
|
|
134
|
+
code: string;
|
|
135
|
+
constructor(message: string, code: string);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare class EmergencyModeError extends Error {
|
|
139
|
+
activeEmergencyModes: string[];
|
|
140
|
+
constructor(message?: string);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
declare class ValidationError extends Error {
|
|
144
|
+
readonly code: string;
|
|
145
|
+
constructor(code: string, message: string);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
declare class TimeoutError extends Error {
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Poll for access on current site.
|
|
152
|
+
* Use this when you expect the reader to have gained access, but need to
|
|
153
|
+
* be sure before telling the reader that everything's good.
|
|
154
|
+
*
|
|
155
|
+
* @throws EmergencyModeError if in emergency mode
|
|
156
|
+
* @throws TimeoutError if access cannot be attained within given timeout
|
|
157
|
+
* @throws Error if unknown error
|
|
158
|
+
* @returns true
|
|
159
|
+
*/
|
|
160
|
+
declare function pollForAccess(requiredAccessFeatures?: string[], timeout_millis?: number): Promise<true>;
|
|
161
|
+
|
|
162
|
+
type LoginPageParams = {
|
|
163
|
+
requestedUrl?: string;
|
|
164
|
+
context?: string;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* This will, if necessary, trigger a redirect to www.aid.no and return
|
|
168
|
+
* to the requestedUrl if supplied or the current url before redirecting away if not.
|
|
169
|
+
* @param requestedUrl
|
|
170
|
+
*/
|
|
171
|
+
declare const goToLoginPage: (requestedUrlOrParams?: string | LoginPageParams) => void;
|
|
172
|
+
declare const getLoginUrl: (requestedUrlOrParams?: string | LoginPageParams) => URL;
|
|
173
|
+
declare const logout: () => Promise<void>;
|
|
174
|
+
declare const requestDataRefresh: () => void;
|
|
175
|
+
declare const aidUrls: {
|
|
176
|
+
mainPage: URL;
|
|
177
|
+
privacyPolicy: URL;
|
|
178
|
+
termsOfService: URL;
|
|
179
|
+
family: URL;
|
|
180
|
+
profile: URL;
|
|
181
|
+
sites: URL;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export { EmergencyModeError, FetchTimeoutError, PaywallError, PaywallUnlockRequest, SiteAccessRequest, TimeoutError, UserDataRequest, ValidationError, aidUrls, getLoginUrl, goToLoginPage, logout, pollForAccess, requestDataRefresh };
|
|
185
|
+
export type { PaywallUnlockResponse, PrivacyPreferences, SiteAccessResponse, State, UserAttributes };
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amedia/user",
|
|
3
3
|
"description": "Client lib for working with aID user and associated data",
|
|
4
|
-
"repository":
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/amedia/amedia-user-js.git"
|
|
7
|
+
},
|
|
5
8
|
"author": "Amedia Produkt og Teknologi AS (https://amedia.no)",
|
|
6
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.4",
|
|
7
10
|
"type": "module",
|
|
8
11
|
"types": "./index.d.ts",
|
|
9
12
|
"private": false,
|
|
@@ -29,7 +32,7 @@
|
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
"scripts": {
|
|
32
|
-
"prepublishOnly": "(cd ../../ && npm run build) && cp ../../dist/user.d.ts .",
|
|
33
|
-
"postpublish": "npx @eik/cli publish && rm
|
|
35
|
+
"prepublishOnly": "(cd ../../ && npm run build) && cp ../../dist/user.d.ts index.d.ts",
|
|
36
|
+
"postpublish": "npx @eik/cli publish && rm index.d.ts"
|
|
34
37
|
}
|
|
35
38
|
}
|