@amedia/user 1.9.2 → 1.10.0
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 +31 -0
- package/README.md +49 -6
- package/index.d.ts +20 -0
- package/package.json +1 -1
- package/user.node.d.ts +12 -0
- package/user.node.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @amedia/user
|
|
2
2
|
|
|
3
|
+
## 1.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1333](https://github.com/amedia/amedia-user-js/pull/1333) [`e9e56d8`](https://github.com/amedia/amedia-user-js/commit/e9e56d8263d5584bc65fa4558d0a12ee7f4a6a12) Thanks [@hennikul](https://github.com/hennikul)! - `subscribe()` hears a logged-out reader at once, with two flags for logins that
|
|
8
|
+
may still happen: `isAutoLoginPending` while automatic login checks for an aID
|
|
9
|
+
session elsewhere, and `isFedCMPending` while FedCM may still log the reader in
|
|
10
|
+
on the page. Subscribers are called again as each turns `false`, so pages can
|
|
11
|
+
decide what to show meanwhile. On a page the edge rendered without a verified
|
|
12
|
+
reader, the logged-out answer comes from the page before aID is asked.
|
|
13
|
+
`fetch()` resolves when it did before: after automatic login, without waiting
|
|
14
|
+
for FedCM.
|
|
15
|
+
|
|
16
|
+
**Migration:** a `subscribe()` callback can now get `isLoggedIn: false` before
|
|
17
|
+
automatic login has run, with `isAutoLoginPending: true`. Code that treats any
|
|
18
|
+
`isLoggedIn: false` as final (shows login buttons, opens dialogs, calls
|
|
19
|
+
`goToLoginPage()`) should wait for `isAutoLoginPending` and `isFedCMPending`
|
|
20
|
+
to be `false`, or it may act just before automatic login navigates away.
|
|
21
|
+
`fetch()` callers need no change.
|
|
22
|
+
|
|
23
|
+
- [#1333](https://github.com/amedia/amedia-user-js/pull/1333) [`e9e56d8`](https://github.com/amedia/amedia-user-js/commit/e9e56d8263d5584bc65fa4558d0a12ee7f4a6a12) Thanks [@hennikul](https://github.com/hennikul)! - `subscribe()` answers from the reader the edge wrote into the page from a
|
|
24
|
+
verified `aid.jwt` (`aid:*` meta tags with `amedia:jwt-status` `verified`),
|
|
25
|
+
before aID has answered. aID is still asked, and subscribers are called again
|
|
26
|
+
only if it disagrees. `fetch()` keeps waiting for aID.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- [#1326](https://github.com/amedia/amedia-user-js/pull/1326) [`7374685`](https://github.com/amedia/amedia-user-js/commit/7374685ba8055153b29b9691b3b771bd13653099) Thanks [@hennikul](https://github.com/hennikul)! - The access refresh asks the provider about each feature once, so a feature
|
|
31
|
+
list with duplicates no longer risks a `400` from providers that require
|
|
32
|
+
unique items.
|
|
33
|
+
|
|
3
34
|
## 1.9.2
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -213,10 +213,53 @@ the various services.
|
|
|
213
213
|
|
|
214
214
|
You should check the state object for potential emergency modes and act accordingly.
|
|
215
215
|
|
|
216
|
-
A
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
A logged-out `state` reaches subscribers as soon as aID has answered, carrying two flags for logins that may still
|
|
217
|
+
happen:
|
|
218
|
+
|
|
219
|
+
- `isAutoLoginPending` is `true` while this page's automatic login checks for an aID session elsewhere. If it finds one,
|
|
220
|
+
the page navigates through aID and comes back logged in. It turns `false` when it will not. Only the first check on a
|
|
221
|
+
page counts: later logged-out answers, after a refresh on window focus, say, carry `false`.
|
|
222
|
+
- `isFedCMPending` is `true` while FedCM may still log the reader in on this page, without navigating. In browsers with
|
|
223
|
+
FedCM, the module asks the browser for a login once automatic login has had its turn, and the browser may show its
|
|
224
|
+
"continue as" prompt. It turns `false` once FedCM cannot log the reader in. Browsers delay most of these answers on
|
|
225
|
+
purpose, by a few seconds and sometimes much longer, so they look like a reader closing the prompt. FedCM runs at most
|
|
226
|
+
once per page, and only for a reader logged out at load; where it does not run, the flag is `false`.
|
|
227
|
+
|
|
228
|
+
Subscribers are called again as each flag turns `false`. Whether to show login buttons, CMP dialogs and the like while
|
|
229
|
+
either is `true` is up to you. Answers with `isAutoLoginPending: true` reach `.subscribe()` only: `.fetch()`, and any
|
|
230
|
+
older version of this module on the same page, hear logged out once automatic login is done, as before. `.fetch()`
|
|
231
|
+
does not wait for FedCM.
|
|
232
|
+
|
|
233
|
+
If FedCM logs the reader in, the module refreshes the reader from aID. There is no separate login event. Subscribers
|
|
234
|
+
are called again and end with `state.isLoggedIn: true`; a resolved `.fetch()` never hears about it. On the way, `state`
|
|
235
|
+
may briefly lack `isLoggedIn` because the refresh clears it — treat that as "not known yet", not as logged out.
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
new UserDataRequest()
|
|
239
|
+
.withAttributes(['name'])
|
|
240
|
+
.subscribe(({ attributes, state }) => {
|
|
241
|
+
if (state.isLoggedIn === undefined) return; // not known yet
|
|
242
|
+
if (state.isLoggedIn) renderName(attributes.name);
|
|
243
|
+
else if (!state.isAutoLoginPending && !state.isFedCMPending)
|
|
244
|
+
renderLoginButton();
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
On a page the edge rendered from `aid.jwt`, the first call can come straight from the page, before aID has been asked.
|
|
249
|
+
The edge writes `amedia:jwt-status` into `<head>`, and for a verified token the reader as `aid:uuid`, `aid:name`,
|
|
250
|
+
`aid:tracking-key` and `aid:access`.
|
|
251
|
+
|
|
252
|
+
- **Logged in:** a `verified` token with a uuid. The first call carries `state.isLoggedIn: true` and the attributes the
|
|
253
|
+
tags cover.
|
|
254
|
+
- **Logged out:** a `verified` token without a uuid, or a `client:*` status (no `aid.jwt`, or one that is expired or does
|
|
255
|
+
not verify). The first call carries `state.isLoggedIn: false`, with both flags as above, and `null` attributes. A
|
|
256
|
+
reader whose token expired while the session lived on is still logged in, so this one is corrected more often.
|
|
257
|
+
|
|
258
|
+
Either first call comes only if the tags cover every attribute you asked for: `sessionTrackingKey` is not in them, so
|
|
259
|
+
asking for it waits for aID as before. The module asks aID anyway and calls you again only if the answer differs.
|
|
260
|
+
Pages loaded from the back/forward history, pages while aID is in emergency mode, and `infra:*` or `not-processed`
|
|
261
|
+
statuses are not read. `.fetch()` never resolves on these tags; it waits for aID, and resolves logged out without
|
|
262
|
+
waiting for FedCM.
|
|
220
263
|
|
|
221
264
|
Should you wish to end your subscription, just call the returned function from `subscribe`.
|
|
222
265
|
|
|
@@ -244,8 +287,8 @@ new UserDataRequest()
|
|
|
244
287
|
```
|
|
245
288
|
|
|
246
289
|
Fetch will wait until it has all the data you requested before resolving, unless the user is not currently logged in.
|
|
247
|
-
Internally `.fetch()`
|
|
248
|
-
resolving the returned promise.
|
|
290
|
+
Internally `.fetch()` listens like `.subscribe()` and waits until everything is ready before unsubscribing and then
|
|
291
|
+
resolving the returned promise. Unlike `.subscribe()`, it does not take the reader from the page's `aid:*` tags.
|
|
249
292
|
|
|
250
293
|
If you really need to render the user's name or get their uuid etc. as fast as possible, use `.subscribe()`, if not,
|
|
251
294
|
this is probably easier.
|
package/index.d.ts
CHANGED
|
@@ -17,6 +17,18 @@ interface UserAttributes {
|
|
|
17
17
|
}
|
|
18
18
|
interface State {
|
|
19
19
|
isLoggedIn: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Set with `isLoggedIn: false`: `true` while FedCM may still log the reader
|
|
22
|
+
* in on this page, without navigating, and `false` once it cannot. Hold back
|
|
23
|
+
* login buttons and dialogs while it is `true`.
|
|
24
|
+
*/
|
|
25
|
+
isFedCMPending?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Set with `isLoggedIn: false`: `true` while automatic login may still send
|
|
28
|
+
* the reader through aID and back logged in, and `false` once it will not.
|
|
29
|
+
* `fetch()` waits for `false`.
|
|
30
|
+
*/
|
|
31
|
+
isAutoLoginPending?: boolean;
|
|
20
32
|
isCircuitBreakerTripped?: boolean;
|
|
21
33
|
emergencyMode?: string[];
|
|
22
34
|
}
|
|
@@ -166,7 +178,14 @@ declare class UserDataRequest<TUserAttributes extends UserAttributes, TStorage e
|
|
|
166
178
|
withNonUserAccess(): UserDataRequest<TUserAttributes, TStorage, TAttributes, TRequestedStorage, TSubscribeResponse & {
|
|
167
179
|
nonUserAccess: Array<Record<string, string>>;
|
|
168
180
|
}>;
|
|
181
|
+
/**
|
|
182
|
+
* Calls `onData` now with what is known and again on every change. On a page
|
|
183
|
+
* the edge rendered from a verified `aid.jwt`, the first call can come from
|
|
184
|
+
* that markup, before aID has answered; aID's answer follows only if it
|
|
185
|
+
* differs. `fetch()` waits for aID.
|
|
186
|
+
*/
|
|
169
187
|
subscribe(onData: (data: TSubscribeResponse) => void): UnsubscribeFn;
|
|
188
|
+
private listen;
|
|
170
189
|
fetch(options?: {
|
|
171
190
|
timeout?: Millis;
|
|
172
191
|
}): Promise<TSubscribeResponse>;
|
|
@@ -175,6 +194,7 @@ declare class UserDataRequest<TUserAttributes extends UserAttributes, TStorage e
|
|
|
175
194
|
private restartFetchTimeout;
|
|
176
195
|
private unsubscribe;
|
|
177
196
|
private processUserAttributesEvent;
|
|
197
|
+
private pickRequested;
|
|
178
198
|
private processStorageEventDetail;
|
|
179
199
|
private setupLocalCache;
|
|
180
200
|
private debugLogFetchCompleted;
|
package/package.json
CHANGED
package/user.node.d.ts
CHANGED
|
@@ -19,6 +19,18 @@ interface UserAttributes {
|
|
|
19
19
|
}
|
|
20
20
|
interface State {
|
|
21
21
|
isLoggedIn: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Set with `isLoggedIn: false`: `true` while FedCM may still log the reader
|
|
24
|
+
* in on this page, without navigating, and `false` once it cannot. Hold back
|
|
25
|
+
* login buttons and dialogs while it is `true`.
|
|
26
|
+
*/
|
|
27
|
+
isFedCMPending?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Set with `isLoggedIn: false`: `true` while automatic login may still send
|
|
30
|
+
* the reader through aID and back logged in, and `false` once it will not.
|
|
31
|
+
* `fetch()` waits for `false`.
|
|
32
|
+
*/
|
|
33
|
+
isAutoLoginPending?: boolean;
|
|
22
34
|
isCircuitBreakerTripped?: boolean;
|
|
23
35
|
emergencyMode?: string[];
|
|
24
36
|
}
|
package/user.node.js
CHANGED
|
@@ -754,6 +754,8 @@ const parseAccessRefreshRequest = (body) => {
|
|
|
754
754
|
return { accessFeatures: [...accessFeatures], url };
|
|
755
755
|
};
|
|
756
756
|
|
|
757
|
+
v.pipe(v.string(), v.trim(), v.uuid());
|
|
758
|
+
|
|
757
759
|
/**
|
|
758
760
|
* Reject URLs that are not absolute http(s) — protects against SSRF via
|
|
759
761
|
* `file:`, `gopher:`, missing scheme (empty → relative), or malformed input
|