@amedia/user 0.14.51 → 0.14.53
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/README.md +100 -62
- package/dist/user.d.ts +13 -13
- package/dist/user.js +1 -0
- package/package.json +15 -22
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
[](https://codeclimate.com/repos/609b74f497caf801a000778d/test_coverage)
|
|
3
3
|
|
|
4
4
|
# @amedia/user
|
|
5
|
+
|
|
5
6
|
The goal of this module is to simplify the usage of aID data and services in Amedia frontend code. The module is designed to be used several places on a webpage independently, and the module will ensure that requests from different parts of the webpage are handled in an efficient manner.
|
|
6
7
|
|
|
7
8
|
An important requirement for this module is Eik. When used in production, this module should always be loaded from an alias in Eik. This is to ensure that all components on a page that uses this module will use same version. The normal way to load the module from Eik is through import maps.
|
|
@@ -9,14 +10,17 @@ An important requirement for this module is Eik. When used in production, this m
|
|
|
9
10
|
This module is owned by Team aID. If you, after having read this file, have any questions or comments; we are happy to help on slack #team-aid
|
|
10
11
|
|
|
11
12
|
# Usage
|
|
13
|
+
|
|
12
14
|
Please be advised that you are required to use ESM in order to use this module.
|
|
13
15
|
|
|
14
16
|
## Importing the module
|
|
17
|
+
|
|
15
18
|
Add this module to your project by running `npm install -d @amedia/user`. This will allow for type-hinting, but will not include the implementation. This means you must also set up import maps for loading the actual code. Just point `@amedia/user` to `https://assets.acdn.no/pkg/@amedia/user/v0/user.js`.
|
|
16
19
|
|
|
17
20
|
See Ego, Bacchus or Saturn for examples on how to use this module through Eik.
|
|
18
21
|
|
|
19
22
|
Once the module is installed, it can be imported in your source code using a standard import like this:
|
|
23
|
+
|
|
20
24
|
```ts
|
|
21
25
|
import {
|
|
22
26
|
UserDataRequest,
|
|
@@ -32,6 +36,7 @@ When your source code is bundled together for production, it's important that th
|
|
|
32
36
|
You can read more about Eik on [Slite](https://amedia.slite.com/app/channels/hOlqx3Miez/notes/iexhL4MZn3).
|
|
33
37
|
|
|
34
38
|
## Getting user data
|
|
39
|
+
|
|
35
40
|
The most common use case for aID on newspapers is to get some kind of data about a user, this could be the user's name, some stored preference, access or data that has been derived about the user.
|
|
36
41
|
|
|
37
42
|
To get user data you first need to create a `new UserDataRequest()`, then specify what data you need and lastly decide if you want to wait until all data is available, or you want to get partial updates.
|
|
@@ -39,11 +44,13 @@ To get user data you first need to create a `new UserDataRequest()`, then specif
|
|
|
39
44
|
This module tries to simplify the model representing various data about the user. We have introduced (and re-used) some concepts that are listed.
|
|
40
45
|
|
|
41
46
|
### Data model
|
|
47
|
+
|
|
42
48
|
#### Attributes
|
|
49
|
+
|
|
43
50
|
Attributes are data directly related to the user, with the exception of access. Supported attributes are:
|
|
44
51
|
|
|
45
52
|
| name | type | description |
|
|
46
|
-
|
|
53
|
+
| ------------------ | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
47
54
|
| uuid | string | The users unique ID. (NOT for tracking) |
|
|
48
55
|
| name | string | Users full name |
|
|
49
56
|
| trackingKey | string | Unique ID of user that can be used for tracking (pseudonym) This is also known as the legacy name user_key |
|
|
@@ -60,6 +67,7 @@ NOTE: Fetching each attribute has a cost, so keep the list to a minimum. Don't r
|
|
|
60
67
|
NOTE2: If you need to know if the current user is an employee, you are encouraged to use data from extraData rather than access as extraData is quicker.
|
|
61
68
|
|
|
62
69
|
#### Storage
|
|
70
|
+
|
|
63
71
|
Storage are namespaces stored in Europa. A namespace is a named set of key value pairs stored for a specific user. An example could be favourite_teams, which could contain team_id as key and timestamp it was stored as favourite as value.
|
|
64
72
|
|
|
65
73
|
Storage is requested by calling `.withStorage()` on a `UserDataRequest` with a list of namespaces you need.
|
|
@@ -67,60 +75,67 @@ Storage is requested by calling `.withStorage()` on a `UserDataRequest` with a l
|
|
|
67
75
|
In the response, `storage` is an object with each namespace as an attribute which leads to an object with attributes for each key in the namespace. So you can access `storage.favourite_teams.myteamid` and get the value stored for `teamid` in the `favourite_teams` namespace. This value will be whatever was saved there.
|
|
68
76
|
|
|
69
77
|
#### State
|
|
70
|
-
State is meant to describe the current context the user is in right now. It's not directly requested, but will always be a part of the response.
|
|
71
78
|
|
|
72
|
-
|
|
79
|
+
State is meant to describe the current context the user is in right now. It's not directly requested, but will always be a part of the response.
|
|
80
|
+
|
|
81
|
+
Current attributes in `state`:
|
|
73
82
|
|
|
74
83
|
| name | type | description |
|
|
75
|
-
|
|
84
|
+
| ------------- | ------------- | ----------------------------------------------------------------------------- |
|
|
76
85
|
| isLoggedIn | boolean | Is the user currently logged in? If not, most attributes will be undefined |
|
|
77
86
|
| emergencyMode | Array<string> | Current state of emergency mode in production environment (paywall, aid etc.) |
|
|
78
87
|
|
|
79
88
|
### Executing the request
|
|
89
|
+
|
|
80
90
|
Once you have created a request and specified the data you need, the final step is to decide how you want to get the data once it's available. You can either choose to subscribe to data as they get loaded from the various backends or wait until all fetching is done and get everything in one package.
|
|
81
91
|
|
|
82
|
-
The response to the request will be an object with attributes for state, attributes and storage. In the examples below these are unpacked for easier access.
|
|
92
|
+
The response to the request will be an object with attributes for state, attributes and storage. In the examples below these are unpacked for easier access.
|
|
83
93
|
|
|
84
94
|
#### Subscribing to updates
|
|
95
|
+
|
|
85
96
|
The most flexible way to get userdata is by subscribing to updates. This is done by calling `.subscribe()` on the `UserDataRequest` with a callback function that can handle the updates once they arrive. This is especially useful when the time it can take to get the data can vary. Getting the user's name is very fast, so you can display the user's name before you have received storage for example.
|
|
86
97
|
|
|
87
98
|
Full usage example:
|
|
99
|
+
|
|
88
100
|
```ts
|
|
89
101
|
import { UserDataRequest } from '...';
|
|
90
102
|
|
|
91
103
|
new UserDataRequest()
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
.withAttributes(['name', 'trackingKey'])
|
|
105
|
+
.withStorage(['my_namespace']) // You might know this as Europa
|
|
106
|
+
.subscribe(({ attributes, state, storage }) => {
|
|
107
|
+
console.log(attributes, state, storage);
|
|
108
|
+
});
|
|
97
109
|
```
|
|
98
110
|
|
|
99
|
-
The callback you supplied to subscribe is called whenever there are any changes to the properties you have requested, so be prepared to rerender.
|
|
111
|
+
The callback you supplied to subscribe is called whenever there are any changes to the properties you have requested, so be prepared to rerender.
|
|
100
112
|
|
|
101
113
|
Also, your requested properties might not arrive all at once. This callback will be called whenever we get data in from the various services.
|
|
102
114
|
|
|
103
115
|
#### Fetching all the data once (no rerenders)
|
|
104
|
-
|
|
116
|
+
|
|
117
|
+
In many use cases it's more convenient to just wait until everything is ready, so you don't have to handle multiple callbacks. In these cases it's easier to call `.fetch()`. This method will return a `Promise` that resolves the same object you would get in the `subscribe` callback.
|
|
105
118
|
|
|
106
119
|
Full usage example:
|
|
120
|
+
|
|
107
121
|
```ts
|
|
108
122
|
import { UserDataRequest } from '...';
|
|
109
123
|
|
|
110
124
|
new UserDataRequest()
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
.withAttributes(['name', 'email'])
|
|
126
|
+
.withStorage(['my_namespace']) // You might know this as Europa
|
|
127
|
+
.fetch()
|
|
128
|
+
.then(({ attributes, state, storage }) => {
|
|
129
|
+
console.log(attributes, state, storage);
|
|
130
|
+
});
|
|
117
131
|
```
|
|
118
132
|
|
|
119
|
-
Fetch will wait until it has all the data you requested before resolving, unless the user is not currently logged in. Internally `.fetch()` will use `.subscribe()` and just wait until everything is ready before resolving the returned promise.
|
|
133
|
+
Fetch will wait until it has all the data you requested before resolving, unless the user is not currently logged in. Internally `.fetch()` will use `.subscribe()` and just wait until everything is ready before resolving the returned promise.
|
|
120
134
|
|
|
121
|
-
If you really need to render the user's name or get its uuid etc. as fast as possible, use `.subscribe()`, if not, this is probably easier.
|
|
135
|
+
If you really need to render the user's name or get its uuid etc. as fast as possible, use `.subscribe()`, if not, this is probably easier.
|
|
122
136
|
|
|
123
137
|
##### Timeouts
|
|
138
|
+
|
|
124
139
|
Especially poor connections may result in almost eternal wait times - which is no good if your app is locked while waiting on the data. Because of this we have introduced a timeout. A timeout will cause the fetch to reject with FetchTimeoutError.
|
|
125
140
|
|
|
126
141
|
_FetchTimeoutError will include any data we might have gotten before we timed out_
|
|
@@ -135,58 +150,69 @@ _FetchTimeoutError will include any data we might have gotten before we timed ou
|
|
|
135
150
|
```
|
|
136
151
|
|
|
137
152
|
If you're running a background task and don't mind waiting longer than default (10 seconds), you may set a longer timeout in fetch:
|
|
153
|
+
|
|
138
154
|
```ts
|
|
139
155
|
.fetch({timeout: 60000 /* milliseconds */ })
|
|
140
156
|
```
|
|
157
|
+
|
|
141
158
|
This may also be lowered below the default, but network request do take some time, even on fast networks, so don't shoot your app in the foot by lowering it too much.
|
|
142
159
|
|
|
143
160
|
## Actions
|
|
161
|
+
|
|
144
162
|
The following methods are actions that the user needs to be able to perform in an environment using logged in users.
|
|
145
163
|
|
|
146
164
|
### `goToLoginPage(requestedUrl: string)`
|
|
165
|
+
|
|
147
166
|
This action will send the user to the aID login page. It will take care of building the correct URL, including your current site domain, so the login page is skinned correctly.
|
|
148
167
|
|
|
149
168
|
You may include a requestedUrl if you need to control where the user should end up after logging in. The default is to send the user back to the current URL where this action was called.
|
|
150
169
|
|
|
151
170
|
### `logout()`
|
|
171
|
+
|
|
152
172
|
This action will log the user out of aID. The logout is global, meaning it will log the session out of all sites and aid.no.
|
|
153
173
|
|
|
154
174
|
## Updating storage
|
|
175
|
+
|
|
155
176
|
If you need to store preferences, favourite teams etc for the user, you can choose between two methods. One will update only the attributes of a namespace that you specify, the other will update everything. The main difference is that if you opt for updating everything, attributes that are present on the backend, but not in the update, will be deleted.
|
|
156
177
|
|
|
157
178
|
### Update changed values (PATCH)
|
|
179
|
+
|
|
158
180
|
The safest way to update a value is to use `updateStorage()`. This will send a `PATCH` to Europa to only update the specified attributes of a namespace, and keep the rest as it is. This reduces concurrency issues where someone could have updated a different attribute after you read the namespace.
|
|
159
181
|
|
|
160
182
|
Example of use:
|
|
183
|
+
|
|
161
184
|
```ts
|
|
162
185
|
import { updateStorage } from '...';
|
|
163
186
|
|
|
164
187
|
updateStorage({
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
188
|
+
my_namespace: {
|
|
189
|
+
my: 'data',
|
|
190
|
+
},
|
|
168
191
|
});
|
|
169
192
|
```
|
|
170
193
|
|
|
171
194
|
In the example, only `my` in `my_namespace` would be updated to `data`. If the namespace also contained `{ your: 'loss' }`, this would be kept untouched, so the resulting namespace would now contain `{ my: 'data', your: 'loss' }`.
|
|
172
195
|
|
|
173
196
|
### Update the entire namespace (PUT)
|
|
197
|
+
|
|
174
198
|
If you're not afraid of concurrency issues, or you need to make sure that old attributes are removed, you should use `saveStorage()`. This works in the same way as `updateStorage()`, but it will send a `PUT` to Europa, which will then make sure that attributes that are stored in the namespaces in the request, but are not a part of the request, will be removed.
|
|
175
199
|
|
|
176
200
|
Example of use:
|
|
201
|
+
|
|
177
202
|
```ts
|
|
178
203
|
import { updateStorage } from '...';
|
|
179
204
|
|
|
180
205
|
saveStorage({
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
206
|
+
my_namespace: {
|
|
207
|
+
my: 'data',
|
|
208
|
+
},
|
|
184
209
|
});
|
|
185
210
|
```
|
|
186
211
|
|
|
187
212
|
In the example, `my` in `my_namespace` would be updated to `data`. If the namespace also contained `{ your: 'loss' }`, this would removed, so the resulting namespace would now contain `{ my: 'data' }`.
|
|
188
213
|
|
|
189
214
|
## Unlocking the paywall
|
|
215
|
+
|
|
190
216
|
Amedia's sites use a Paywall that's based on a cookie called VSTOKEN that is read by Varnish and used by the content system to decide if the content should be shown to the user or not. If not, the content will load what we call an incentive, a dialogue above the content, that will allow the user to log in and/or buy subscription. The incentive will use `PaywallUnlockRequest` to see if it can somehow grant access to the user.
|
|
191
217
|
|
|
192
218
|
In some cases it makes sense to create a different user interface for a paywall. If so we recommend that you use `PaywallUnlockRequest` in order to get the same functionality.
|
|
@@ -196,76 +222,85 @@ More information about the paywall can be found here: [How the Paywall works](ht
|
|
|
196
222
|
Information about the incentive can also be useful, since you probably need to replicate this functionality if you create a new user interface: [How the Incentive works](https://amedia.slite.com/app/channels/hOlqx3Miez/notes/SroHksU9u)
|
|
197
223
|
|
|
198
224
|
To unlock the paywall, you first need to create a new `PaywallUnlockRequest`. Once created, you can set some options by calling methods on this request:
|
|
225
|
+
|
|
199
226
|
- `reloadOnAccess()`: If the paywall unlocker finds sufficient access for the user it will reload the current page
|
|
200
227
|
- `redirectOnAccess(requestedUrl: string)`: If the paywall unlocker finds sufficient access for the user, it will send the user
|
|
201
|
-
|
|
202
|
-
- `withAccessFeatures(accessFeatures: string[])`: Specify what access features will give access to the current content.
|
|
203
|
-
|
|
228
|
+
to `requestedUrl`. (Provides more flexibility than `reloadOnAccess()`)
|
|
229
|
+
- `withAccessFeatures(accessFeatures: string[])`: Specify what access features will give access to the current content.
|
|
230
|
+
The default is [`newspaper`].
|
|
204
231
|
- `withSiteDomain(domain: string)`: Specify which site we to attempt activation against. The default is the current domain. This is mostly useful for direktesport.no which often knows what domain the user came from.
|
|
205
232
|
|
|
206
233
|
More details about the access model can be found here: [Access model](https://amedia.slite.com/app/channels/hOlqx3Miez/notes/nhG2Ok39BN)
|
|
207
234
|
|
|
208
|
-
Once your options have been set up, you can call `tryUnlock()`. This is when all the magic happens. The unlocker will try to auto login the user on the current domain, check access, activate subscriptions in the subscription system, check for stuff like IP based access etc. When this is done, it will resolve the `Promise` that was returned by `tryUnlock()`.
|
|
235
|
+
Once your options have been set up, you can call `tryUnlock()`. This is when all the magic happens. The unlocker will try to auto login the user on the current domain, check access, activate subscriptions in the subscription system, check for stuff like IP based access etc. When this is done, it will resolve the `Promise` that was returned by `tryUnlock()`.
|
|
209
236
|
|
|
210
237
|
The resolution to the promise contains an object with attributes you can use to get details about why the user did not get access (or if he had access if you don't opt for reload or redirect). The object contains the following:
|
|
238
|
+
|
|
211
239
|
- isLoggedIn: True if the user is logged in, false otherwise. Useful if you want to show a login button, which makes no sense for logged in users.
|
|
212
240
|
- hasAccess: True if the user has access. Always false if you called `reloadOnAccess()` or `redirectOnAccess()`.
|
|
213
241
|
- accessFeatures: List of access features the user has access to. Empty list if user is logged out or has no access. This list is useful if you want to upgrade from 'newspaper' to 'plussalt' for instance. You might want to give a different user experience to users with some access than users with no access.
|
|
214
242
|
|
|
215
243
|
Full usage example:
|
|
244
|
+
|
|
216
245
|
```ts
|
|
217
246
|
import { PaywallUnlockRequest } from '...';
|
|
218
247
|
|
|
219
248
|
new PaywallUnlockRequest()
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
+
.redirectOnAccess('https://my.neat/place') // Optional
|
|
250
|
+
.reloadOnAccess() // Optional
|
|
251
|
+
.tryUnlock()
|
|
252
|
+
.then(({ isLoggedIn, hasAccess, accessFeatures }) => {
|
|
253
|
+
// If you did not specify any "on access"-action above
|
|
254
|
+
// we will return here afterwards.
|
|
255
|
+
console.log({ isLoggedIn, hasAccess, accessFeatures });
|
|
256
|
+
})
|
|
257
|
+
.catch((error) => {
|
|
258
|
+
// Known potential errors are:
|
|
259
|
+
|
|
260
|
+
// This guards potential reload/redirect loop. Access should have been granted at this time
|
|
261
|
+
PaywallError(
|
|
262
|
+
'Unlock check already performed.',
|
|
263
|
+
PaywallError.ERROR_RELOADED_NO_ACCESS
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// Internal error. Access should have been granted at this time.
|
|
267
|
+
PaywallError(
|
|
268
|
+
'New subscription was attached and checked successfully, but internal systems disagree about current newspaper access.',
|
|
269
|
+
PaywallError.ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
// Internal error. We are unable to get access tokens/cookies to set.
|
|
273
|
+
PaywallError(
|
|
274
|
+
'Could not set access cookies',
|
|
275
|
+
PaywallError.ERROR_ENABLING_ACCESS_FAILED
|
|
276
|
+
);
|
|
277
|
+
});
|
|
249
278
|
```
|
|
250
279
|
|
|
251
|
-
Note that this
|
|
280
|
+
Note that this _might result in redirects/reloads_ if the user is not already logged in. In that case you will end up here again if logging in did not result in access.
|
|
252
281
|
|
|
253
282
|
## Performance
|
|
283
|
+
|
|
254
284
|
This app aims to be able to deliver a lot of data fast. Still, we might need to call several services in order to get what you need. We do try to cache whenever this makes sense, but please don't ask for data you don't need.
|
|
255
285
|
|
|
256
286
|
# Behind the scenes
|
|
287
|
+
|
|
257
288
|
There are a few techniques used to avoid overfetching and fetching multiple times when once would do.
|
|
258
289
|
|
|
259
290
|
## Event-based actions
|
|
291
|
+
|
|
260
292
|
Much like [node-userdata-browser/userdata-client](https://github.com/amedia/node-userdata-browser) did, we utilize events to message that data is being requested. This allowed us to decouple your request from the particular instance that will serve it. That in turn allows us to have this library loaded by multiple different components across the page, and only process the requests one place. In addition, if the component that's currently processing requests should be unloaded for whatever reason, one of the other instances will automatically take over.
|
|
261
293
|
|
|
262
294
|
## Request de-duping
|
|
295
|
+
|
|
263
296
|
Since we now process from a single instance of the package it's easy to avoid fetching the same resource multiple times.
|
|
264
297
|
|
|
265
|
-
## Caching
|
|
298
|
+
## Caching
|
|
299
|
+
|
|
266
300
|
@amedia/user has a caching layer that easily let ut switch out the caching mechanism, but p.t. we only use it to cache to a global object for the life of the page.
|
|
267
301
|
|
|
268
302
|
## Contributing to @amedia/user
|
|
303
|
+
|
|
269
304
|
Hey, thanks! :)
|
|
270
305
|
|
|
271
306
|
It's often nice to do development while testing on a real app. You may do so using `npm link`. When you run then `npm run build` (or `npm run dev` if you want to watch for changes and build automatically) this will expose actual code, letting you develop faster. This is because we still export user.js from the package, but replaces its content with an error if used directly.
|
|
@@ -273,9 +308,11 @@ It's often nice to do development while testing on a real app. You may do so usi
|
|
|
273
308
|
PS: Remember to comment-out the module in import maps ;-)
|
|
274
309
|
|
|
275
310
|
### Testing live!
|
|
311
|
+
|
|
276
312
|
You can test your version live by utilizing a browser extension like Requestly or similar. Run `npm run dev` (which will build and watch for changes locally _and_ starts a webserver listening on localhost:9999). Then add a rule in the extension that replaces requests for @amedia/user/v0/user.js with http://localhost:9999/user.js. Now reload and watch your wonderful change do its thing.
|
|
277
313
|
|
|
278
314
|
# Publishing new versions
|
|
315
|
+
|
|
279
316
|
NB: Please be advised, as with all packages in Eik, that once you update the alias, _every_ place that uses this module will get your version. It's therefore extra important that you don't break the API without creating a new major version! This can cause the front page not to load, users not being able to log in or get access to content they paid good money for etc.
|
|
280
317
|
|
|
281
318
|
Since not all IDEs, linters etc support import maps and certainly don't support loading types that way, yet; we must publish typings to npm and the implementation to Eik.
|
|
@@ -293,7 +330,8 @@ This has been built into the prepublishOnly and postpublish hooks in package.jso
|
|
|
293
330
|
Now the new version can be installed in a project by running `npm install -u @amedia/user@v<new version>`
|
|
294
331
|
|
|
295
332
|
When you are as sure as you can be that you didn't break anything to can update the Eik alias:
|
|
333
|
+
|
|
296
334
|
1. https://github.com/amedia/amedia-user-js/actions/workflows/deploy.yml
|
|
297
|
-
2. Run that workflow. If what you want is to
|
|
335
|
+
2. Run that workflow. If what you want is to update the latest alias with the latest version, you can leave the fields empty.
|
|
298
336
|
|
|
299
337
|
Note that the timeout for alias-caching is 20mins, so if you're unlucky you might have to wait awhile for now.
|
package/dist/user.d.ts
CHANGED
|
@@ -25,7 +25,9 @@ declare type PrivacyPreferences = {
|
|
|
25
25
|
declare type Millis = number;
|
|
26
26
|
declare class UserDataRequest<UA extends UserAttributes, S extends {
|
|
27
27
|
[index: string]: unknown;
|
|
28
|
-
}, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string,
|
|
28
|
+
}, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, unknown> & {
|
|
29
|
+
state: State;
|
|
30
|
+
} = {
|
|
29
31
|
state: State;
|
|
30
32
|
}> {
|
|
31
33
|
private attributes?;
|
|
@@ -33,7 +35,7 @@ declare class UserDataRequest<UA extends UserAttributes, S extends {
|
|
|
33
35
|
static FETCH_TIMEOUT: Millis;
|
|
34
36
|
private fetchTimeoutId;
|
|
35
37
|
private lastReceivedData?;
|
|
36
|
-
constructor(attributes?: Attributes
|
|
38
|
+
constructor(attributes?: Attributes, namespaces?: Namespaces);
|
|
37
39
|
withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): UserDataRequest<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
|
|
38
40
|
attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
|
|
39
41
|
}>;
|
|
@@ -83,8 +85,8 @@ declare class PaywallUnlockRequest {
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
declare class FetchTimeoutError extends Error {
|
|
86
|
-
partialData: Record<string,
|
|
87
|
-
constructor(message: string, partialData: Record<string,
|
|
88
|
+
partialData: Record<string, unknown>;
|
|
89
|
+
constructor(message: string, partialData: Record<string, unknown>);
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
declare class PaywallError extends Error {
|
|
@@ -95,19 +97,17 @@ declare class PaywallError extends Error {
|
|
|
95
97
|
constructor(message: string, code: string);
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
declare type Storage = Record<string, Record<string, unknown>>;
|
|
98
101
|
/**
|
|
99
102
|
* This will, if necessary, trigger a redirect to www.aid.no and return
|
|
100
103
|
* to the requestedUrl if supplied or the current url before redirecting away if not.
|
|
101
104
|
* @param requestedUrl
|
|
102
105
|
*/
|
|
103
|
-
declare const goToLoginPage: (requestedUrl?: string
|
|
104
|
-
declare const getLoginUrl: (requestedUrl?: string
|
|
106
|
+
declare const goToLoginPage: (requestedUrl?: string) => void;
|
|
107
|
+
declare const getLoginUrl: (requestedUrl?: string) => URL;
|
|
105
108
|
declare const logout: () => Promise<void>;
|
|
106
|
-
declare const updateStorage: (storage:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
declare const saveStorage: (storage: {
|
|
110
|
-
[index: string]: Object;
|
|
111
|
-
}) => void;
|
|
109
|
+
declare const updateStorage: (storage: Storage) => void;
|
|
110
|
+
declare const saveStorage: (storage: Storage) => void;
|
|
111
|
+
declare const requestDataRefresh: () => void;
|
|
112
112
|
|
|
113
|
-
export { FetchTimeoutError, PaywallError, PaywallUnlockRequest, PrivacyPreferences, State, UserAttributes, UserDataRequest, getLoginUrl, goToLoginPage, logout, saveStorage, updateStorage };
|
|
113
|
+
export { FetchTimeoutError, PaywallError, PaywallUnlockRequest, PrivacyPreferences, State, UserAttributes, UserDataRequest, getLoginUrl, goToLoginPage, logout, requestDataRefresh, saveStorage, updateStorage };
|
package/dist/user.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amedia/user",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.53",
|
|
4
4
|
"description": "Client lib for working with aID user and associated data",
|
|
5
5
|
"repository": "https://github.com/amedia/amedia-user-js",
|
|
6
6
|
"author": "Amedia Utvikling (ID og data)",
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
"changeset": "changeset",
|
|
29
29
|
"release": "changeset publish",
|
|
30
30
|
"test": "jest --coverage",
|
|
31
|
+
"format": "kragl format",
|
|
32
|
+
"lint": "kragl lint",
|
|
33
|
+
"lint-fix": "kragl lint --fix",
|
|
31
34
|
"clean-dist": "rm -rf ./dist",
|
|
32
|
-
"lint": "eslint ./src --ext .ts",
|
|
33
35
|
"build": "npm install && node build.js & npm run build:types",
|
|
34
36
|
"build:types": "npx rollup -c ./types.js",
|
|
35
37
|
"dev": "concurrently --kill-others \"node build.js --watch\" \"node server.js\"",
|
|
36
|
-
"typings": "tsc --noEmit",
|
|
38
|
+
"typings": "tsc --noEmit --resolveJsonModule",
|
|
37
39
|
"checkVersion": "node --experimental-json-modules checkVersion.js",
|
|
38
40
|
"stub-npmjs-package": "find ./dist -type f ! -name '*.d.ts' -delete && cp -v stubs/* dist/.",
|
|
39
41
|
"eik:package": "run-p typings lint && npm run test && npm run build && npx eik package",
|
|
@@ -47,35 +49,26 @@
|
|
|
47
49
|
"ts-deepmerge": "^2.0.1"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@amedia/
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@changesets/changelog-github": "^0.4.4",
|
|
54
|
-
"@changesets/cli": "^2.22.0",
|
|
52
|
+
"@amedia/kragl": "^1.0.2",
|
|
53
|
+
"@changesets/changelog-github": "^0.4.5",
|
|
54
|
+
"@changesets/cli": "^2.23.0",
|
|
55
55
|
"@eik/cli": "^2.0.22",
|
|
56
|
-
"@eik/esbuild-plugin": "^1.1.
|
|
56
|
+
"@eik/esbuild-plugin": "^1.1.13",
|
|
57
57
|
"@types/jest": "^27.4.1",
|
|
58
|
-
"
|
|
59
|
-
"@typescript-eslint/parser": "^5.25.0",
|
|
60
|
-
"concurrently": "^7.2.0",
|
|
58
|
+
"concurrently": "^7.2.2",
|
|
61
59
|
"cors": "^2.8.5",
|
|
62
|
-
"esbuild": "0.
|
|
63
|
-
"eslint": "^8.15.0",
|
|
64
|
-
"eslint-config-airbnb-typescript": "^17.0.0",
|
|
65
|
-
"eslint-config-prettier": "^8.5.0",
|
|
66
|
-
"eslint-plugin-import": "^2.26.0",
|
|
67
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
60
|
+
"esbuild": "0.15.3",
|
|
68
61
|
"express": "^4.18.1",
|
|
69
62
|
"jest": "^27.5.1",
|
|
70
63
|
"jest-extended": "^2.0.0",
|
|
71
64
|
"jest-fetch-mock": "^3.0.3",
|
|
72
65
|
"mockdate": "^3.0.5",
|
|
73
66
|
"npm-run-all": "^4.1.5",
|
|
74
|
-
"prettier": "^2.
|
|
75
|
-
"rollup": "2.
|
|
76
|
-
"rollup-plugin-dts": "4.2.
|
|
67
|
+
"prettier": "^2.7.1",
|
|
68
|
+
"rollup": "2.75.7",
|
|
69
|
+
"rollup-plugin-dts": "4.2.2",
|
|
77
70
|
"ts-jest": "^27.1.4",
|
|
78
71
|
"tslib": "^2.4.0",
|
|
79
|
-
"typescript": "^4.
|
|
72
|
+
"typescript": "^4.7.4"
|
|
80
73
|
}
|
|
81
74
|
}
|