@amedia/user 1.5.0 → 1.6.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 CHANGED
@@ -1,5 +1,133 @@
1
1
  # @amedia/user
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1299](https://github.com/amedia/amedia-user-js/pull/1299) [`3d5a21a`](https://github.com/amedia/amedia-user-js/commit/3d5a21a72cecf1143581249c1eb326a403e73c9e) Thanks [@hennikul](https://github.com/hennikul)! - aID on-site verification and the On-Site API from a server, not just a browser
8
+
9
+ Everything verification-related moves into `@amedia/user-core`, and
10
+ `@amedia/user/node` gains the server half. The browser API is unchanged except
11
+ where noted under **Changed behaviour** — the same functions now call into core
12
+ rather than carrying their own copy.
13
+
14
+ **New: the On-Site API from a server**
15
+
16
+ `createOnSiteClient({ siteDomain, apiOrigin, token, headers, timeoutMs, signal })`
17
+ reads `getSelf`, `getSession` and `getAccessFeatures` for a reader whose
18
+ `aid.session` you hold, using two credentials: their session id in `X-Aid-Session`
19
+ and an m2m token for the `public-onsite-api` audience. Together these reach data
20
+ a browser session is not granted — the `*_verified_at` timestamps above all.
21
+ - The site travels in `X-Aid-Site`, because `Host` is a forbidden header name
22
+ that `fetch` drops without a word.
23
+ - `apiOrigin` is where the API answers when that is not the site's own domain:
24
+ the in-cluster router (`AID_ONSITE_API_URL`), or another environment's host.
25
+ Left out, a snap session sent to a canonical domain would reach production.
26
+ - `timeoutMs` defaults to 3000 and composes with your own `signal`. There is no
27
+ timeout below it, so a server rendering against an aID that never answers
28
+ would otherwise spend its whole request concurrency waiting.
29
+ - The client holds nothing and costs about a microsecond, so build one per
30
+ request from the site you are answering for. Keep the token provider outside
31
+ it — pass a function, and it is called per request.
32
+
33
+ **New: verification from a server**
34
+ - `buildVerificationUrl({ siteDomain, requestedUrl, ...requirement })` — the
35
+ `/aid/verify` link, so it is in the first render rather than after a script
36
+ loads. Throws for anything aID would refuse anyway.
37
+ - `readVerificationOutcome(url)` — the outcome off the URL the reader came back
38
+ to. Takes a whole URL or a bare path, which is what `req.url` is in
39
+ `node:http` and Express.
40
+ - The requirement vocabulary, shared with the browser:
41
+ `normalizeVerificationRequirement`, `verificationUrlFor`,
42
+ `verificationSourceOf`, `VERIFIABLE_ATTRIBUTES`, `VERIFICATION_SOURCES`,
43
+ `MAX_AGE_CEILING_SECONDS`.
44
+
45
+ **New: which provider the reader will meet**
46
+
47
+ `getVerificationProviders(requirement?)` in the browser and
48
+ `fetchVerificationProviders(requirement?, opts?)` on the server read aID's
49
+ registry, so a page can draw the logo it is about to send someone to rather than
50
+ assume BankID. A provider added on our side then appears without a release on
51
+ yours. Needs no credential, and narrows by the same requirement the verify
52
+ hand-off takes; omit it for the whole catalogue.
53
+
54
+ `icon_svg` is markup from the network — draw it as
55
+ `<img src="data:image/svg+xml;base64,…">` rather than through `innerHTML`.
56
+
57
+ **New: aID's problems, by name**
58
+
59
+ `namesNoReader(error)`, `isLoggedOut(error)` and `isAidProblem(error, ...types)`
60
+ take the error straight from a `catch` and duck-type what it carries, so an
61
+ error from another package's client works too. With `AidProblem` and
62
+ `LOGGED_OUT_PROBLEMS`, a caller matches a problem by name instead of by
63
+ substring.
64
+
65
+ All three are deliberately narrower than "any 4xx": an unapproved audience or a
66
+ missing scope is a configuration fault, and reading it as a signed-out reader
67
+ hides it behind a page that looks like it is working.
68
+
69
+ **Fixed: every reader read as unverified**
70
+
71
+ `ServiceUserSchema` declared neither `birth_date`, `email` and `phone` nor any of
72
+ their `*_verified_at` timestamps, and valibot strips what it does not declare. A
73
+ caller naming `birth_date_verified_at` in a `getSelf` filter got it back silently
74
+ removed — so a verified reader was indistinguishable from an unverified one.
75
+
76
+ **Changed behaviour**
77
+ - `getVerificationOutcome()` (and the new `readVerificationOutcome`) keep `error`
78
+ only when the status is `failed`.
79
+ `?verification=cancelled&verification_error=login_required` used to answer
80
+ `{ status: 'cancelled', error: 'login_required' }` and now answers
81
+ `{ status: 'cancelled' }`. eris never sends that pair — it answers an empty
82
+ error for both `completed` and `cancelled` — so nothing aID produces is lost.
83
+ What it stops is a stale `verification_error` surviving a back-button and
84
+ making `if (outcome.error)` report a failure for a verification that
85
+ completed.
86
+ - `requestedUrl` must be a path on your own site. `getVerificationUrl`,
87
+ `requireVerification` and `buildVerificationUrl` now throw for an absolute URL
88
+ or for `//`/`/\`, which a browser reads as the start of a host. eris keeps
89
+ only the path of `requested_url`, so these were never a redirect off-site —
90
+ they were a reader who finished verifying on the front page instead of where
91
+ they started, with nothing said.
92
+ - `AidRequestOptions` gains `signal`, passed through to `fetch` on every read.
93
+
94
+ **Docs**
95
+
96
+ README rewritten around both halves — browser and node — with setup for the
97
+ in-cluster, direct and non-production cases. The same for third parties in the
98
+ Confluence page. `AGENTS.md` becomes `CLAUDE.md`, and says that a feature here
99
+ is expected to work server-side as well as in the browser.
100
+
101
+ ## 1.5.1
102
+
103
+ ### Patch Changes
104
+
105
+ - [#1297](https://github.com/amedia/amedia-user-js/pull/1297) [`cd6b9a2`](https://github.com/amedia/amedia-user-js/commit/cd6b9a29d9f698676eee2f6208148442d1bb5bed) Thanks [@hennikul](https://github.com/hennikul)! - Point the CDN bundle's type reference at the declaration file that is actually published.
106
+
107
+ The browser bundle opened with `/// <reference types="./types.d.ts" />`, but `eik.files` publishes the declarations as `user.d.ts`. No `types.d.ts` has ever existed, so the reference resolved to a 404 at every released version.
108
+
109
+ TypeScript consumers were not affected, because TypeScript locates types for `user.js` through the sibling `user.d.ts` filename convention rather than through the reference directive. The directive only mattered to resolvers that treat it as a self-types pointer, and it was a dangling reference in every case. It now names the published file.
110
+
111
+ - [#1297](https://github.com/amedia/amedia-user-js/pull/1297) [`cd6b9a2`](https://github.com/amedia/amedia-user-js/commit/cd6b9a29d9f698676eee2f6208148442d1bb5bed) Thanks [@hennikul](https://github.com/hennikul)! - Fix unresolvable `@amedia/user-core` imports in the published type declarations.
112
+
113
+ Both `index.d.ts` and `user.node.d.ts` opened with an import from `@amedia/user-core`. That package is `private: true` and never published, so consumers hit `error TS2307: Cannot find module '@amedia/user-core'` on the first line of the declaration file and lost type safety for the whole package.
114
+
115
+ `rollup-plugin-dts` resolved the workspace package through its `node_modules` symlink, which makes TypeScript report the module as an external library import. The plugin then treats it as external and emits the bare specifier instead of inlining the types. A `paths` mapping to the package source keeps resolution out of `node_modules`, so the types are bundled into the declaration output.
116
+
117
+ The published declarations now import only `jose` and `valibot`, both of which are declared dependencies and resolve for consumers.
118
+
119
+ - [#1289](https://github.com/amedia/amedia-user-js/pull/1289) [`926a8ff`](https://github.com/amedia/amedia-user-js/commit/926a8ff960f8cfc7043da8909be6275c847386ed) Thanks [@mortenlocka](https://github.com/mortenlocka)! - Log something useful when a caught value is not an `Error`. Three `catch` blocks read `.message` off the caught value without checking it: the cache's schema-parse failure logged `undefined` as its message, the navigation handler did the same, and the FedCM job already had a `'Not an Error object'` fallback but never reached it. All three now narrow the value first, so a non-`Error` throw is logged as its string form instead of disappearing.
120
+
121
+ - [#1290](https://github.com/amedia/amedia-user-js/pull/1290) [`e4bde08`](https://github.com/amedia/amedia-user-js/commit/e4bde08004050637ad59f3c80f9a4ba1d97f8163) Thanks [@mortenlocka](https://github.com/mortenlocka)! - Fix a fetcher signature that was narrower than the contract it implemented. `CoreFetcher` accepts `string | URL | Request`, but the browser fetcher declared only `RequestInfo`, so a `URL` passed through core would have been handed to a function whose type said it could not take one. The implementation always could — it forwards straight to `fetch()` — so the signature was the thing that was wrong.
122
+
123
+ - [#1291](https://github.com/amedia/amedia-user-js/pull/1291) [`00456c5`](https://github.com/amedia/amedia-user-js/commit/00456c55440189153c38f3ff3e2728f99ef9c056) Thanks [@mortenlocka](https://github.com/mortenlocka)! - Fix two latent bugs found by turning on `strictNullChecks`.
124
+
125
+ `Debouncer`'s `deepCopy` reached `Object.entries()` for anything that was not a string or an array. That throws on `null` and returns `[]` for numbers and booleans, so a primitive inside debounced parameters was silently replaced by `{}` and a `null` crashed the copy outright. Primitives and `null` are now returned as they are.
126
+
127
+ `listenForAllEvents` read the module-level root element again inside the unsubscribe function it returns. If `setRootElement` ran in between, unsubscribing removed the listener from the wrong element and left the original attached. It now captures the element it subscribed to.
128
+
129
+ The published type surface is unchanged apart from one optional constructor parameter that now spells out `| undefined`.
130
+
3
131
  ## 1.5.0
4
132
 
5
133
  ### Minor Changes
package/index.d.ts CHANGED
@@ -1,5 +1,138 @@
1
- import { UserAttributes, ClientId, State, PrimarySite } from '@amedia/user-core';
2
- export { FetchTimeoutError, PaywallError, PrivacyPreferences, State, UserAttributes, ValidationError } from '@amedia/user-core';
1
+ import * as v from 'valibot';
2
+
3
+ type AccessFeatures = string[];
4
+ interface UserAttributes {
5
+ uuid: string | null;
6
+ name: string | null;
7
+ trackingKey: string | null;
8
+ avatar: string | null;
9
+ /** @deprecated Always returns empty. 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
+ interface 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
+ declare class PrivacyPreferences {
27
+ readonly allowResearchUsage: boolean;
28
+ readonly personalizedContent: boolean;
29
+ constructor(data: {
30
+ allowResearchUsage: boolean;
31
+ personalizedContent: boolean;
32
+ });
33
+ static default(): PrivacyPreferences;
34
+ }
35
+
36
+ declare class ValidationError extends Error {
37
+ readonly code: string;
38
+ constructor(code: string, message: string);
39
+ }
40
+
41
+ declare class FetchTimeoutError extends Error {
42
+ partialData: Record<string, unknown>;
43
+ constructor(message: string, partialData: Record<string, unknown>);
44
+ }
45
+
46
+ declare class PaywallError extends Error {
47
+ code: string;
48
+ static ERROR_RELOADED_NO_ACCESS: string;
49
+ static ERROR_ENABLING_ACCESS_FAILED: string;
50
+ static ERROR_NO_ACCESS_AFTER_SUCCESSFUL_ACTIVATION_WITH_REQUESTED_ACCESS_FEATURES: string;
51
+ constructor(message: string, code: string);
52
+ }
53
+
54
+ /**
55
+ * One provider as a chooser needs it: what to call it, what it proves, what it
56
+ * looks like. `icon_svg` is the registry's own artwork, and is serialised even
57
+ * when empty — an absent logo is a provider without one, not an older response.
58
+ *
59
+ * `acr_values` is deliberately absent from the public projection: naming the
60
+ * assurance level invites a caller to ask for a weaker one.
61
+ */
62
+ declare const VerificationProviderSchema: v.ObjectSchema<{
63
+ readonly id: v.StringSchema<undefined>;
64
+ readonly label: v.StringSchema<undefined>;
65
+ readonly source: v.StringSchema<undefined>;
66
+ readonly attributes: v.ArraySchema<v.StringSchema<undefined>, undefined>;
67
+ /**
68
+ * The provider's logo, as SVG markup.
69
+ *
70
+ * Markup from the network, so it goes in as an image rather than as nodes:
71
+ * `<img src="data:image/svg+xml;base64,…">` draws it with scripts inert,
72
+ * while `innerHTML = icon_svg` would run anything it carried. aID writes this
73
+ * and the trust is internal, which is why this is a rendering instruction and
74
+ * not a warning — but the safe rendering costs nothing.
75
+ */
76
+ readonly icon_svg: v.StringSchema<undefined>;
77
+ }, undefined>;
78
+ type VerificationProvider = v.InferOutput<typeof VerificationProviderSchema>;
79
+
80
+ declare enum AffiliationType {
81
+ ACCESS = "access",
82
+ FAMILY = "family",
83
+ SUBSCRIPTION = "subscription"
84
+ }
85
+ declare const PrimarySiteSchema: v.ObjectSchema<{
86
+ readonly domain: v.StringSchema<undefined>;
87
+ readonly name: v.StringSchema<undefined>;
88
+ readonly affiliation: v.LiteralSchema<AffiliationType.ACCESS, undefined>;
89
+ readonly affiliations: v.ArraySchema<v.UnionSchema<[v.LiteralSchema<AffiliationType.ACCESS, undefined>, v.LiteralSchema<AffiliationType.FAMILY, undefined>, v.LiteralSchema<AffiliationType.SUBSCRIPTION, undefined>], undefined>, undefined>;
90
+ }, undefined>;
91
+ type PrimarySite = v.InferOutput<typeof PrimarySiteSchema>;
92
+
93
+ declare const VERIFIABLE_ATTRIBUTES: readonly ["name", "birth_date", "email", "phone"];
94
+ type VerifiableAttribute = (typeof VERIFIABLE_ATTRIBUTES)[number];
95
+ declare const VERIFICATION_SOURCES: readonly ["eid", "otp"];
96
+ type VerificationSource = (typeof VERIFICATION_SOURCES)[number];
97
+ type VerificationRequirement = {
98
+ /** Attributes that must carry a verification timestamp on the user. */
99
+ attributes?: VerifiableAttribute[];
100
+ /** Whether the session must carry a verification stamp. */
101
+ verifiedSession?: boolean;
102
+ /** Which kinds of source are acceptable. Omitted, the attribute implies it. */
103
+ sources?: VerificationSource[];
104
+ /** Force a re-verify when the proof is older than this. Seconds, or `30m`. `0` means prove it now. */
105
+ maxAge?: string | number;
106
+ /** Where the reader lands afterwards. A path on your own site. */
107
+ requestedUrl?: string;
108
+ /** Tracking, as on `goToLoginPage`. */
109
+ context?: string;
110
+ };
111
+ type VerificationStatus = 'completed' | 'cancelled' | 'failed';
112
+ /**
113
+ * The closed set a failure can name. The first five are eris's
114
+ * `knownVerificationErrors`, which it normalises anything else down to;
115
+ * `unknown_outcome` is added here for a `verification` value this version does
116
+ * not recognise.
117
+ */
118
+ type VerificationError = 'invalid_request' | 'requirement_not_met' | 'state_mismatch' | 'provider_error' | 'login_required' | 'unknown_outcome';
119
+ type VerificationOutcome = {
120
+ status: VerificationStatus;
121
+ error?: VerificationError;
122
+ };
123
+
124
+ type ClientId = string;
125
+
126
+ /**
127
+ * The providers aID may offer this reader, in aID's own order — what to call
128
+ * each one and what it looks like, so a page can draw the logo it is about to
129
+ * send the reader to rather than guess which one that is.
130
+ *
131
+ * Narrowed by a requirement when given, the same one `requireVerification`
132
+ * takes. Answers aID's own origin rather than the site's: the registry knows no
133
+ * reader and needs no credential.
134
+ */
135
+ declare const getVerificationProviders: (requirement?: VerificationRequirement) => Promise<VerificationProvider[]>;
3
136
 
4
137
  type NamespaceList = Array<string>;
5
138
 
@@ -19,7 +152,7 @@ declare class UserDataRequest<TUserAttributes extends UserAttributes, TStorage e
19
152
  private fetchTimeoutId;
20
153
  private lastReceivedData?;
21
154
  private subscriptionEventListeners;
22
- constructor(requestedAttributes?: TAttributes, requestedStorage?: TRequestedStorage, requestedNonUserAccess?: boolean, context?: string);
155
+ constructor(requestedAttributes?: TAttributes | undefined, requestedStorage?: TRequestedStorage | undefined, requestedNonUserAccess?: boolean, context?: string);
23
156
  withContext(context: string): this;
24
157
  withAttributes<NewAttributes extends Array<keyof TUserAttributes>>(attributes: NewAttributes): UserDataRequest<TUserAttributes, TStorage, (TAttributes[number] & NewAttributes[number])[], TRequestedStorage, TSubscribeResponse & {
25
158
  attributes: Pick<TUserAttributes, TAttributes[number] & NewAttributes[number]>;
@@ -108,36 +241,6 @@ declare class TimeoutError extends Error {
108
241
  */
109
242
  declare const pollForAccess: (requiredAccessFeatures?: string[], timeout_millis?: number) => Promise<true>;
110
243
 
111
- declare const VERIFIABLE_ATTRIBUTES: readonly ["name", "birth_date", "email", "phone"];
112
- type VerifiableAttribute = (typeof VERIFIABLE_ATTRIBUTES)[number];
113
- declare const VERIFICATION_SOURCES: readonly ["eid", "otp"];
114
- type VerificationSource = (typeof VERIFICATION_SOURCES)[number];
115
- type VerificationRequirement = {
116
- /** Attributes that must be verified on the user. */
117
- attributes?: VerifiableAttribute[];
118
- /** Whether the browser session must carry a verification stamp. */
119
- verifiedSession?: boolean;
120
- /** Which kinds of source are acceptable. Omitted, the attribute implies it. */
121
- sources?: VerificationSource[];
122
- /** Force a re-verify when the proof is older than this. Seconds, or `30m`. `0` means prove it now. */
123
- maxAge?: string | number;
124
- /** Where the reader lands afterwards. Defaults to the current page. */
125
- requestedUrl?: string;
126
- /** Tracking, as on `goToLoginPage`. */
127
- context?: string;
128
- };
129
- type VerificationStatus = 'completed' | 'cancelled' | 'failed';
130
- /**
131
- * The closed set a failure can name. The first five are eris's
132
- * `knownVerificationErrors`, which it normalises anything else down to;
133
- * `unknown_outcome` is added here for a `verification` value this version does
134
- * not recognise.
135
- */
136
- type VerificationError = 'invalid_request' | 'requirement_not_met' | 'state_mismatch' | 'provider_error' | 'login_required' | 'unknown_outcome';
137
- type VerificationOutcome = {
138
- status: VerificationStatus;
139
- error?: VerificationError;
140
- };
141
244
  /**
142
245
  * Builds the aID Identity Verification URL for a requirement, for a link or a
143
246
  * button. See `requireVerification` for the requirement itself.
@@ -196,5 +299,5 @@ declare const aidUrls: {
196
299
  sites: URL;
197
300
  };
198
301
 
199
- export { EmergencyModeError, PaywallUnlockRequest, SiteAccessRequest, SiteAccessResponse, TimeoutError, UserDataRequest, aidUrls, getLoginUrl, getVerificationOutcome, getVerificationUrl, goToLoginPage, logout, pollForAccess, requestDataRefresh, requireVerification };
200
- export type { PaywallUnlockResponse, VerifiableAttribute, VerificationError, VerificationOutcome, VerificationRequirement, VerificationSource, VerificationStatus };
302
+ export { EmergencyModeError, FetchTimeoutError, PaywallError, PaywallUnlockRequest, PrivacyPreferences, SiteAccessRequest, SiteAccessResponse, TimeoutError, UserDataRequest, ValidationError, aidUrls, getLoginUrl, getVerificationOutcome, getVerificationProviders, getVerificationUrl, goToLoginPage, logout, pollForAccess, requestDataRefresh, requireVerification };
303
+ export type { PaywallUnlockResponse, State, UserAttributes, VerifiableAttribute, VerificationError, VerificationOutcome, VerificationRequirement, VerificationSource, VerificationStatus };
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/amedia/amedia-user-js.git"
7
7
  },
8
8
  "author": "Amedia Produkt og Teknologi AS (https://amedia.no)",
9
- "version": "1.5.0",
9
+ "version": "1.6.0",
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
@@ -41,7 +41,7 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "jose": "5.9.6",
44
- "valibot": "1.4.2"
44
+ "valibot": "1.5.0"
45
45
  },
46
46
  "eik": {
47
47
  "server": "https://assets.acdn.no",