@amedia/user 0.14.89 → 0.14.91

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.
Files changed (3) hide show
  1. package/README.md +10 -5
  2. package/dist/user.d.ts +30 -13
  3. package/package.json +7 -7
package/README.md CHANGED
@@ -124,19 +124,24 @@ Full usage example:
124
124
  ```ts
125
125
  import { UserDataRequest } from '...';
126
126
 
127
- new UserDataRequest()
127
+ const unsubscribe = new UserDataRequest()
128
128
  .withAttributes(['name', 'trackingKey'])
129
129
  .withStorage(['my_namespace']) // You might know this as Europa
130
130
  .subscribe(({ attributes, state, storage }) => {
131
131
  console.log(attributes, state, storage);
132
132
  });
133
+
134
+ // If you wish to unsubscribe from further updates:
135
+ unsubscribe();
133
136
  ```
134
137
 
135
- The callback you supplied to subscribe is called whenever there are any changes to the properties you have requested, so be prepared to rerender.
138
+ The callback you supplied to subscribe is called whenever there are any changes to the properties you have requested, so be prepared to re-render.
136
139
 
137
140
  Also, your requested properties might not arrive all at once. This callback will be called whenever we get data in from the various services.
138
141
 
139
- #### Fetching all the data once (no rerenders)
142
+ Should you wish to end your subscription, just call the returned function from subscribe.
143
+
144
+ #### Fetching all the data once (no re-renders)
140
145
 
141
146
  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.
142
147
 
@@ -154,9 +159,9 @@ new UserDataRequest()
154
159
  });
155
160
  ```
156
161
 
157
- 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.
162
+ 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 unsubscribing and then resolving the returned promise.
158
163
 
159
- 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.
164
+ If you really need to render the user's name or get their uuid etc. as fast as possible, use `.subscribe()`, if not, this is probably easier.
160
165
 
161
166
  ##### Timeouts
162
167
 
package/dist/user.d.ts CHANGED
@@ -22,32 +22,42 @@ type PrivacyPreferences = {
22
22
  personalizedContent: boolean;
23
23
  };
24
24
 
25
+ declare const DEFAULT_CLIENT_ID = "default";
26
+ type ClientId = string | typeof DEFAULT_CLIENT_ID;
27
+
28
+ type NamespaceList = Array<string>;
29
+
25
30
  type Millis = number;
26
- declare class UserDataRequest<UA extends UserAttributes, S extends {
27
- [index: string]: unknown;
28
- }, Attributes extends Array<keyof UA>, Namespaces extends Array<string>, SubscribeResponse extends Record<string, unknown> & {
31
+ type UnsubscribeFn = () => void;
32
+ 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> & {
29
33
  state: State;
30
34
  } = {
31
35
  state: State;
32
36
  }> {
33
- private attributes?;
34
- private namespaces?;
37
+ private requestedAttributes?;
38
+ private requestedStorage?;
35
39
  static FETCH_TIMEOUT: Millis;
36
40
  private fetchTimeoutId;
37
41
  private lastReceivedData?;
38
- constructor(attributes?: Attributes, namespaces?: Namespaces);
39
- withAttributes<NewAttributes extends Array<keyof UA>>(attributes: NewAttributes): UserDataRequest<UA, S, (Attributes[number] & NewAttributes[number])[], Namespaces, SubscribeResponse & {
40
- attributes: Pick<UA, Attributes[number] & NewAttributes[number]>;
42
+ private subscriptionEventListeners;
43
+ constructor(requestedAttributes?: TAttributes, requestedStorage?: TRequestedStorage);
44
+ withAttributes<NewAttributes extends Array<keyof TUserAttributes>>(attributes: NewAttributes): UserDataRequest<TUserAttributes, TStorage, (TAttributes[number] & NewAttributes[number])[], TRequestedStorage, TSubscribeResponse & {
45
+ attributes: Pick<TUserAttributes, TAttributes[number] & NewAttributes[number]>;
46
+ }>;
47
+ withStorage(namespaces: Array<string>): UserDataRequest<TUserAttributes, TStorage, TAttributes, TRequestedStorage, TSubscribeResponse & {
48
+ storage: Record<string, Record<string, string>>;
41
49
  }>;
42
- withStorage<NewNamespaces extends Array<string>>(namespaces: NewNamespaces): UserDataRequest<UA, S, Attributes, (Namespaces[number] & NewNamespaces[number])[], SubscribeResponse & {
43
- storage: Pick<S, Namespaces[number] & NewNamespaces[number]>;
50
+ withClientStorage(clientId: keyof TStorage, namespaces: Array<string>): UserDataRequest<TUserAttributes, TStorage, TAttributes, TRequestedStorage, TSubscribeResponse & {
51
+ clientStorage: Record<ClientId, (typeof namespaces)[number]>;
44
52
  }>;
45
- subscribe(onData: (data: SubscribeResponse) => void): void;
53
+ subscribe(onData: (data: TSubscribeResponse) => void): UnsubscribeFn;
46
54
  fetch(options?: {
47
55
  timeout?: Millis;
48
- }): Promise<SubscribeResponse>;
49
- private clearFetchTimeout;
56
+ }): Promise<TSubscribeResponse>;
50
57
  private startFetchTimeout;
58
+ private clearFetchTimeout;
59
+ private restartFetchTimeout;
60
+ private unsubscribe;
51
61
  private processUserAttributesEvent;
52
62
  private processStorageEvent;
53
63
  private setupLocalCache;
@@ -97,6 +107,7 @@ declare class PaywallError extends Error {
97
107
  constructor(message: string, code: string);
98
108
  }
99
109
 
110
+ /** @deprecated Should be deleted when removing saveStorage and updateStorage */
100
111
  type Storage = Record<string, Record<string, string>>;
101
112
  type LoginPageParams = {
102
113
  requestedUrl?: string;
@@ -110,7 +121,13 @@ type LoginPageParams = {
110
121
  declare const goToLoginPage: (requestedUrlOrParams?: string | LoginPageParams) => void;
111
122
  declare const getLoginUrl: (requestedUrlOrParams?: string | LoginPageParams) => URL;
112
123
  declare const logout: () => Promise<void>;
124
+ /**
125
+ * @deprecated Use Namespace.save() instead
126
+ */
113
127
  declare const updateStorage: (storage: Storage) => void;
128
+ /**
129
+ * @deprecated Use Namespace.save() instead
130
+ */
114
131
  declare const saveStorage: (storage: Storage) => void;
115
132
  declare const requestDataRefresh: () => void;
116
133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amedia/user",
3
- "version": "0.14.89",
3
+ "version": "0.14.91",
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)",
@@ -46,30 +46,30 @@
46
46
  "@amedia/browserid": "^1.0.17",
47
47
  "@amedia/frontend-rpc": "^0.0.12",
48
48
  "runtypes": "^6.6.0",
49
- "ts-deepmerge": "^5.0.0"
49
+ "ts-deepmerge": "^6.0.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@amedia/kragl": "^1.2.3",
53
53
  "@changesets/changelog-github": "^0.4.8",
54
54
  "@changesets/cli": "^2.26.0",
55
55
  "@eik/esbuild-plugin": "^1.1.27",
56
- "@types/jest": "^29.2.6",
56
+ "@types/jest": "^29.4.0",
57
57
  "@types/node": "^18.11.18",
58
58
  "concurrently": "^7.6.0",
59
59
  "cors": "^2.8.5",
60
60
  "esbuild": "0.17.4",
61
61
  "express": "^4.18.2",
62
- "jest": "^29.3.1",
63
- "jest-environment-jsdom": "^29.3.1",
62
+ "jest": "^29.4.1",
63
+ "jest-environment-jsdom": "^29.4.1",
64
64
  "jest-extended": "^3.2.3",
65
65
  "jest-fetch-mock": "^3.0.3",
66
66
  "mockdate": "^3.0.5",
67
67
  "npm-run-all": "^4.1.5",
68
68
  "prettier": "^2.8.3",
69
- "rollup": "3.10.1",
69
+ "rollup": "3.12.0",
70
70
  "rollup-plugin-dts": "5.1.1",
71
71
  "ts-jest": "^29.0.5",
72
- "tslib": "^2.4.1",
72
+ "tslib": "^2.5.0",
73
73
  "typescript": "^4.9.4"
74
74
  }
75
75
  }