@amedia/user 0.14.115 → 0.14.116
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 +17 -1
- package/dist/user.d.ts +3 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -146,6 +146,10 @@ Once you have created a request and specified the data you need, the final step
|
|
|
146
146
|
|
|
147
147
|
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.
|
|
148
148
|
|
|
149
|
+
_Short note about caching_
|
|
150
|
+
To answer as fast as possible, we try to save cache to sessionStorage in the browser, then, on the next page load we have data available for instant delivery, but it's possible that it's outdated. To account for staleness we perform fetches in the background if we haven't fetched data this page load.
|
|
151
|
+
However, this means you may get stale data. If the validity of the data is paramount, you should consider using subscribe instead of fetch.
|
|
152
|
+
|
|
149
153
|
#### Subscribing to updates
|
|
150
154
|
|
|
151
155
|
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.
|
|
@@ -186,6 +190,7 @@ Full usage example:
|
|
|
186
190
|
import { UserDataRequest } from '@amedia/user';
|
|
187
191
|
|
|
188
192
|
new UserDataRequest()
|
|
193
|
+
.withContext('my-app') // Tell us who you are :) This helps with tracability.
|
|
189
194
|
.withAttributes(['name'])
|
|
190
195
|
.withStorage(['my_namespace'])
|
|
191
196
|
.withClientStorage('client-id', ['my-client-namespace'])
|
|
@@ -208,6 +213,7 @@ _FetchTimeoutError will include any data we might have gotten before we timed ou
|
|
|
208
213
|
|
|
209
214
|
```ts
|
|
210
215
|
new UserDataRequest()
|
|
216
|
+
.withContext('my-app')
|
|
211
217
|
.withAttributes(['name'])
|
|
212
218
|
.withStorage(['my_namespace'])
|
|
213
219
|
.fetch()
|
|
@@ -223,6 +229,7 @@ If you're running a background task and don't mind waiting longer than default (
|
|
|
223
229
|
|
|
224
230
|
```ts
|
|
225
231
|
new UserDataRequest()
|
|
232
|
+
.withContext('my-app')
|
|
226
233
|
.withAttributes(['name'])
|
|
227
234
|
.withStorage(['my_namespace'])
|
|
228
235
|
.fetch({ timeout: 60000 /* milliseconds */ });
|
|
@@ -242,6 +249,7 @@ Your app should act accordingly, eg:
|
|
|
242
249
|
|
|
243
250
|
```ts
|
|
244
251
|
new UserDataRequest()
|
|
252
|
+
.withContext('my-app')
|
|
245
253
|
.withAttributes(['name'])
|
|
246
254
|
.withStorage(['my_namespace'])
|
|
247
255
|
.fetch()
|
|
@@ -449,7 +457,15 @@ Since we now process from a single instance of the package it's easy to avoid fe
|
|
|
449
457
|
|
|
450
458
|
## Caching
|
|
451
459
|
|
|
452
|
-
@amedia/user has a caching layer that easily let ut switch out the caching mechanism
|
|
460
|
+
@amedia/user has a caching layer that easily let ut switch out the caching mechanism.
|
|
461
|
+
We have two strategies:
|
|
462
|
+
|
|
463
|
+
- SessionStorage: (to survive page loads) Used if available.
|
|
464
|
+
- Global: Stores to a global variable on the current page.
|
|
465
|
+
|
|
466
|
+
## Debugging
|
|
467
|
+
|
|
468
|
+
If you're curious about calls, response times etc, there is a debug flag you can set on the URL `debug=something`. If you'd like it to survive page loads, you can add a key to localStorage or sessionStorage: `localStorage.setItem('amedia-user:debug', 'something')`
|
|
453
469
|
|
|
454
470
|
## Contributing to @amedia/user
|
|
455
471
|
|
package/dist/user.d.ts
CHANGED
|
@@ -43,7 +43,9 @@ declare class UserDataRequest<TUserAttributes extends UserAttributes, TStorage e
|
|
|
43
43
|
private lastReceivedData?;
|
|
44
44
|
private subscriptionEventListeners;
|
|
45
45
|
private resolveNonUserAccess;
|
|
46
|
+
private context;
|
|
46
47
|
constructor(requestedAttributes?: TAttributes, requestedStorage?: TRequestedStorage, requestedNonUserAccess?: boolean);
|
|
48
|
+
withContext(context: string): this;
|
|
47
49
|
withAttributes<NewAttributes extends Array<keyof TUserAttributes>>(attributes: NewAttributes): UserDataRequest<TUserAttributes, TStorage, (TAttributes[number] & NewAttributes[number])[], TRequestedStorage, TSubscribeResponse & {
|
|
48
50
|
attributes: Pick<TUserAttributes, TAttributes[number] & NewAttributes[number]>;
|
|
49
51
|
}>;
|
|
@@ -67,6 +69,7 @@ declare class UserDataRequest<TUserAttributes extends UserAttributes, TStorage e
|
|
|
67
69
|
private processUserAttributesEvent;
|
|
68
70
|
private processStorageEventDetail;
|
|
69
71
|
private setupLocalCache;
|
|
72
|
+
private debugLogFetchCompleted;
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
declare enum AffiliationType {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amedia/user",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.116",
|
|
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)",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@changesets/cli": "^2.27.1",
|
|
56
56
|
"@eik/esbuild-plugin": "^1.1.46",
|
|
57
57
|
"@types/jest": "^29.5.12",
|
|
58
|
-
"@types/node": "^20.12.
|
|
58
|
+
"@types/node": "^20.12.4",
|
|
59
59
|
"concurrently": "^8.2.2",
|
|
60
60
|
"cors": "^2.8.5",
|
|
61
61
|
"esbuild": "0.20.2",
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"jest-fetch-mock": "^3.0.3",
|
|
67
67
|
"mockdate": "^3.0.5",
|
|
68
68
|
"npm-run-all": "^4.1.5",
|
|
69
|
-
"rollup": "4.
|
|
69
|
+
"rollup": "4.14.0",
|
|
70
70
|
"rollup-plugin-dts": "6.1.0",
|
|
71
71
|
"ts-jest": "^29.1.2",
|
|
72
72
|
"tslib": "^2.6.2",
|
|
73
|
-
"typescript": "^5.4.
|
|
73
|
+
"typescript": "^5.4.4"
|
|
74
74
|
}
|
|
75
75
|
}
|