@ic-reactor/react 3.12.5 → 3.13.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.
Files changed (152) hide show
  1. package/README.md +410 -44
  2. package/dist/auth/auth-client-compat.d.ts +122 -0
  3. package/dist/auth/auth-client-compat.d.ts.map +1 -0
  4. package/dist/auth/auth-client-compat.js +162 -0
  5. package/dist/auth/auth-client-compat.js.map +1 -0
  6. package/dist/auth/authentication-manager.d.ts +287 -5
  7. package/dist/auth/authentication-manager.d.ts.map +1 -1
  8. package/dist/auth/authentication-manager.js +920 -150
  9. package/dist/auth/authentication-manager.js.map +1 -1
  10. package/dist/auth/createIdentityAttributeHooks.d.ts.map +1 -1
  11. package/dist/auth/createIdentityAttributeHooks.js +36 -20
  12. package/dist/auth/createIdentityAttributeHooks.js.map +1 -1
  13. package/dist/auth/identity-attributes-manager.d.ts +2 -1
  14. package/dist/auth/identity-attributes-manager.d.ts.map +1 -1
  15. package/dist/auth/identity-attributes-manager.js +90 -6
  16. package/dist/auth/identity-attributes-manager.js.map +1 -1
  17. package/dist/auth/identity-attributes.d.ts.map +1 -1
  18. package/dist/auth/identity-attributes.js +57 -0
  19. package/dist/auth/identity-attributes.js.map +1 -1
  20. package/dist/auth/local-ii-probe.d.ts +12 -1
  21. package/dist/auth/local-ii-probe.d.ts.map +1 -1
  22. package/dist/auth/local-ii-probe.js +22 -3
  23. package/dist/auth/local-ii-probe.js.map +1 -1
  24. package/dist/auth/types.d.ts +48 -5
  25. package/dist/auth/types.d.ts.map +1 -1
  26. package/dist/createActorHooks.d.ts +7 -18
  27. package/dist/createActorHooks.d.ts.map +1 -1
  28. package/dist/createActorHooks.js.map +1 -1
  29. package/dist/createInfiniteQuery.d.ts +51 -10
  30. package/dist/createInfiniteQuery.d.ts.map +1 -1
  31. package/dist/createInfiniteQuery.js +39 -15
  32. package/dist/createInfiniteQuery.js.map +1 -1
  33. package/dist/createMutation.d.ts +3 -0
  34. package/dist/createMutation.d.ts.map +1 -1
  35. package/dist/createMutation.js +87 -80
  36. package/dist/createMutation.js.map +1 -1
  37. package/dist/createQuery.d.ts +35 -2
  38. package/dist/createQuery.d.ts.map +1 -1
  39. package/dist/createQuery.js +104 -17
  40. package/dist/createQuery.js.map +1 -1
  41. package/dist/createReactorProvider.d.ts +158 -0
  42. package/dist/createReactorProvider.d.ts.map +1 -0
  43. package/dist/createReactorProvider.js +256 -0
  44. package/dist/createReactorProvider.js.map +1 -0
  45. package/dist/createSuspenseInfiniteQuery.d.ts +16 -9
  46. package/dist/createSuspenseInfiniteQuery.d.ts.map +1 -1
  47. package/dist/createSuspenseInfiniteQuery.js +59 -27
  48. package/dist/createSuspenseInfiniteQuery.js.map +1 -1
  49. package/dist/createSuspenseQuery.d.ts +23 -2
  50. package/dist/createSuspenseQuery.d.ts.map +1 -1
  51. package/dist/createSuspenseQuery.js +68 -21
  52. package/dist/createSuspenseQuery.js.map +1 -1
  53. package/dist/defineDisplayReactor.d.ts +43 -0
  54. package/dist/defineDisplayReactor.d.ts.map +1 -0
  55. package/dist/defineDisplayReactor.js +42 -0
  56. package/dist/defineDisplayReactor.js.map +1 -0
  57. package/dist/defineReactor.d.ts +46 -72
  58. package/dist/defineReactor.d.ts.map +1 -1
  59. package/dist/defineReactor.js +11 -176
  60. package/dist/defineReactor.js.map +1 -1
  61. package/dist/defineReactorShared.d.ts +84 -0
  62. package/dist/defineReactorShared.d.ts.map +1 -0
  63. package/dist/defineReactorShared.js +139 -0
  64. package/dist/defineReactorShared.js.map +1 -0
  65. package/dist/hooks/createAuthHooks.d.ts +7 -0
  66. package/dist/hooks/createAuthHooks.d.ts.map +1 -1
  67. package/dist/hooks/createAuthHooks.js +180 -20
  68. package/dist/hooks/createAuthHooks.js.map +1 -1
  69. package/dist/hooks/useActorInfiniteQuery.d.ts +34 -6
  70. package/dist/hooks/useActorInfiniteQuery.d.ts.map +1 -1
  71. package/dist/hooks/useActorInfiniteQuery.js +54 -21
  72. package/dist/hooks/useActorInfiniteQuery.js.map +1 -1
  73. package/dist/hooks/useActorMethod.d.ts +37 -4
  74. package/dist/hooks/useActorMethod.d.ts.map +1 -1
  75. package/dist/hooks/useActorMethod.js +201 -57
  76. package/dist/hooks/useActorMethod.js.map +1 -1
  77. package/dist/hooks/useActorMutation.d.ts +10 -7
  78. package/dist/hooks/useActorMutation.d.ts.map +1 -1
  79. package/dist/hooks/useActorMutation.js +14 -13
  80. package/dist/hooks/useActorMutation.js.map +1 -1
  81. package/dist/hooks/useActorQuery.d.ts +17 -4
  82. package/dist/hooks/useActorQuery.d.ts.map +1 -1
  83. package/dist/hooks/useActorQuery.js +30 -9
  84. package/dist/hooks/useActorQuery.js.map +1 -1
  85. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +15 -3
  86. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +1 -1
  87. package/dist/hooks/useActorSuspenseInfiniteQuery.js +37 -17
  88. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +1 -1
  89. package/dist/hooks/useActorSuspenseQuery.d.ts +2 -2
  90. package/dist/hooks/useActorSuspenseQuery.d.ts.map +1 -1
  91. package/dist/hooks/useActorSuspenseQuery.js +20 -9
  92. package/dist/hooks/useActorSuspenseQuery.js.map +1 -1
  93. package/dist/index.d.ts +4 -0
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +6 -0
  96. package/dist/index.js.map +1 -1
  97. package/dist/ownedAuthentication.d.ts +52 -0
  98. package/dist/ownedAuthentication.d.ts.map +1 -0
  99. package/dist/ownedAuthentication.js +49 -0
  100. package/dist/ownedAuthentication.js.map +1 -0
  101. package/dist/server.d.ts +21 -0
  102. package/dist/server.d.ts.map +1 -0
  103. package/dist/server.js +23 -0
  104. package/dist/server.js.map +1 -0
  105. package/dist/testing.d.ts +19 -0
  106. package/dist/testing.d.ts.map +1 -0
  107. package/dist/testing.js +19 -0
  108. package/dist/testing.js.map +1 -0
  109. package/dist/types.d.ts +416 -15
  110. package/dist/types.d.ts.map +1 -1
  111. package/dist/types.js +1 -1
  112. package/dist/utils.d.ts +159 -3
  113. package/dist/utils.d.ts.map +1 -1
  114. package/dist/utils.js +301 -1
  115. package/dist/utils.js.map +1 -1
  116. package/dist/validation.d.ts +12 -7
  117. package/dist/validation.d.ts.map +1 -1
  118. package/dist/validation.js +34 -15
  119. package/dist/validation.js.map +1 -1
  120. package/llms.txt +259 -33
  121. package/package.json +17 -5
  122. package/src/auth/auth-client-compat.ts +273 -0
  123. package/src/auth/authentication-manager.ts +918 -96
  124. package/src/auth/createIdentityAttributeHooks.ts +47 -21
  125. package/src/auth/identity-attributes-manager.ts +100 -5
  126. package/src/auth/identity-attributes.ts +75 -0
  127. package/src/auth/local-ii-probe.ts +29 -3
  128. package/src/auth/types.ts +49 -6
  129. package/src/createActorHooks.ts +20 -32
  130. package/src/createInfiniteQuery.ts +120 -28
  131. package/src/createMutation.ts +161 -178
  132. package/src/createQuery.ts +164 -32
  133. package/src/createReactorProvider.ts +365 -0
  134. package/src/createSuspenseInfiniteQuery.ts +93 -43
  135. package/src/createSuspenseQuery.ts +102 -32
  136. package/src/defineDisplayReactor.ts +62 -0
  137. package/src/defineReactor.ts +81 -263
  138. package/src/defineReactorShared.ts +268 -0
  139. package/src/hooks/createAuthHooks.ts +206 -24
  140. package/src/hooks/useActorInfiniteQuery.ts +122 -49
  141. package/src/hooks/useActorMethod.ts +295 -92
  142. package/src/hooks/useActorMutation.ts +23 -23
  143. package/src/hooks/useActorQuery.ts +43 -10
  144. package/src/hooks/useActorSuspenseInfiniteQuery.ts +93 -50
  145. package/src/hooks/useActorSuspenseQuery.ts +30 -15
  146. package/src/index.ts +8 -0
  147. package/src/ownedAuthentication.ts +81 -0
  148. package/src/server.ts +23 -0
  149. package/src/testing.ts +18 -0
  150. package/src/types.ts +463 -14
  151. package/src/utils.ts +387 -3
  152. package/src/validation.ts +43 -19
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Bridges IC Reactor's stable authentication options onto whichever
3
+ * `@icp-sdk/auth` major is installed.
4
+ *
5
+ * `@icp-sdk/auth` v9 reshaped the `AuthClient` constructor and v10 moved its
6
+ * `@icp-sdk/core` peer to `^6`. The *method* surface IC Reactor calls --
7
+ * `signIn`, `signOut`, `getIdentity`, `isAuthenticated`, `requestAttributes`,
8
+ * `memoize` -- is byte-identical across v8 and v10, so only the option objects
9
+ * handed to the constructor and to `signIn` have to be translated.
10
+ *
11
+ * The translation lives here rather than in `AuthenticationManager` so that
12
+ * {@link AuthenticationClientOptions} stays IC Reactor's own contract. Callers
13
+ * keep writing `identityProvider: "https://id.ai/authorize"` whichever peer
14
+ * they installed, and the shapes diverge only at the boundary.
15
+ *
16
+ * Why both majors: v8 peers `@icp-sdk/core@^5` while IC Reactor needs `^6`, so
17
+ * a strict `npm install` resolving v8 fails with `ERESOLVE` unless the app adds
18
+ * an `overrides` block. v10 is the first release whose peer is `^6`, which
19
+ * removes that workaround -- but pinning v10 alone would break every app
20
+ * already installed on v8.
21
+ */
22
+ import type { AuthClientSignInOptions, AuthenticationClientOptions } from "./types.js";
23
+ /**
24
+ * Which options contract the installed `AuthClient` accepts.
25
+ *
26
+ * - `legacy` -- v8. `identityProvider` is a URL; `storage`, `keyType`,
27
+ * `idleOptions` and `identity` are constructor options; `signIn` takes
28
+ * `targets`.
29
+ * - `session` -- v9/v10. `identityProvider` is an `{ authorizeUrl, canisterId }`
30
+ * pair, credentials moved behind `credentialStorage`, idle moved to the
31
+ * identity provider canister, and `signIn` no longer takes `targets`.
32
+ */
33
+ export type AuthClientFlavor = "legacy" | "session";
34
+ /** The `{ authorizeUrl, canisterId }` pair a v9+ client names a deployment by. */
35
+ export interface SessionIdentityProvider {
36
+ authorizeUrl: string | URL;
37
+ canisterId: string;
38
+ }
39
+ /**
40
+ * Which canister a v9+ client should pair with the configured
41
+ * `identityProvider` URL, as `AuthenticationManager` works it out.
42
+ *
43
+ * - `mainnet`: the URL is mainnet's and nothing overrides the canister, so the
44
+ * option is omitted and the client uses mainnet for both halves.
45
+ * - `pair`: the canister is known, from `internetIdentityId` or because the URL
46
+ * is one IC Reactor derived for a local deployment.
47
+ * - `unknown`: a URL the caller configured with no canister to go with it.
48
+ */
49
+ export type IdentityProviderPairing = {
50
+ kind: "mainnet";
51
+ } | {
52
+ kind: "pair";
53
+ canisterId: string;
54
+ } | {
55
+ kind: "unknown";
56
+ };
57
+ /**
58
+ * Detects the contract from the constructor itself rather than from the
59
+ * module's exports.
60
+ *
61
+ * `getStatus`, `getPrincipal`, `subscribe` and `dispose` were added to
62
+ * `AuthClient` in v9 and have no v8 counterpart. Reading them off the prototype
63
+ * beats sniffing the module namespace: a bundler may drop an unreferenced named
64
+ * export (`IdbStorage`, `IdleManager`) from the namespace object it synthesizes
65
+ * for a dynamic import, but it never drops a class's own methods.
66
+ *
67
+ * Two markers rather than one, because a single name is a coincidence away from
68
+ * matching some future shim. An unrecognised constructor is treated as `legacy`
69
+ * -- the shape IC Reactor's own options already mirror, so a wrong guess there
70
+ * passes the values through untouched instead of rewriting them into a shape
71
+ * nothing understands.
72
+ */
73
+ export declare function detectAuthClientFlavor(AuthClient: unknown): AuthClientFlavor;
74
+ /**
75
+ * Detects the contract of a client the caller built and passed in.
76
+ *
77
+ * Such a client never goes through the module loader, so there is no
78
+ * constructor to hand {@link detectAuthClientFlavor}. The markers are the same
79
+ * two methods, reached through the instance instead of the prototype.
80
+ */
81
+ export declare function detectAuthClientInstanceFlavor(client: unknown): AuthClientFlavor;
82
+ /** @internal Test seam -- lets a suite assert the first warning every time. */
83
+ export declare function resetAuthCompatWarnings(): void;
84
+ /**
85
+ * Translates IC Reactor's constructor options into the installed client's shape.
86
+ *
87
+ * On `legacy` the object is already the right shape and is returned as-is,
88
+ * except for `disableBrowserActivity`. That option exists only on v10, so it is
89
+ * dropped with a one-time warning rather than handed to a v8 client that
90
+ * ignores it.
91
+ *
92
+ * On `session` the identity provider becomes a pair. The canister is not
93
+ * derived from the URL, because v9+ is explicit that the origin serving a
94
+ * ceremony is not a promise about which canister mints there. `pairing` says
95
+ * which canister goes with the URL. When nothing does, this throws rather than
96
+ * guessing: a guessed canister sends the delegation calls to a different
97
+ * deployment than the one the user signs in at, and sign-in fails later with an
98
+ * error that names neither.
99
+ *
100
+ * @param options - IC Reactor's resolved options, in the v8-shaped contract.
101
+ * @param flavor - The contract the installed client accepts.
102
+ * @param pairing - Which canister goes with `options.identityProvider`.
103
+ * @param agentOptions - Options for the agent a v9+ client mints delegations
104
+ * with. v8 has no such agent, so a `legacy` client never receives them.
105
+ */
106
+ export declare function toAuthClientConstructorOptions(options: AuthenticationClientOptions | undefined, flavor: AuthClientFlavor, pairing?: IdentityProviderPairing, agentOptions?: Record<string, unknown>): AuthenticationClientOptions | Record<string, unknown> | undefined;
107
+ /**
108
+ * Translates `signIn` options into the installed client's shape.
109
+ *
110
+ * `targets` is the one that matters. v8 forwards it to restrict the delegation
111
+ * to named canisters; v9+ removed it, and scoping is decided by the identity
112
+ * provider against the app's own canister. Passing it to a v9+ client does not
113
+ * fail -- it is simply ignored, and the delegation that comes back is broader
114
+ * than the caller asked for. That is a security-relevant difference, so it
115
+ * warns unconditionally rather than only in development.
116
+ *
117
+ * `maxTimeToIdle` goes the other way. It exists only on v10, so a v10 client
118
+ * receives it, and a v8 client, whose sign-in has no idle limit, gets it
119
+ * dropped with a one-time warning.
120
+ */
121
+ export declare function toAuthClientSignInOptions(options: AuthClientSignInOptions | undefined, flavor: AuthClientFlavor): AuthClientSignInOptions | undefined;
122
+ //# sourceMappingURL=auth-client-compat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-client-compat.d.ts","sourceRoot":"","sources":["../../src/auth/auth-client-compat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EACV,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEnD,kFAAkF;AAClF,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,GAAG,GAAG,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,uBAAuB,GAC/B;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAEvB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,OAAO,GAAG,gBAAgB,CAY5E;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,OAAO,GACd,gBAAgB,CAOlB;AA4BD,+EAA+E;AAC/E,wBAAgB,uBAAuB,SAEtC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,2BAA2B,GAAG,SAAS,EAChD,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE,uBAA6C,EACtD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA2DnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,uBAAuB,GAAG,SAAS,EAC5C,MAAM,EAAE,gBAAgB,GACvB,uBAAuB,GAAG,SAAS,CA6BrC"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Detects the contract from the constructor itself rather than from the
3
+ * module's exports.
4
+ *
5
+ * `getStatus`, `getPrincipal`, `subscribe` and `dispose` were added to
6
+ * `AuthClient` in v9 and have no v8 counterpart. Reading them off the prototype
7
+ * beats sniffing the module namespace: a bundler may drop an unreferenced named
8
+ * export (`IdbStorage`, `IdleManager`) from the namespace object it synthesizes
9
+ * for a dynamic import, but it never drops a class's own methods.
10
+ *
11
+ * Two markers rather than one, because a single name is a coincidence away from
12
+ * matching some future shim. An unrecognised constructor is treated as `legacy`
13
+ * -- the shape IC Reactor's own options already mirror, so a wrong guess there
14
+ * passes the values through untouched instead of rewriting them into a shape
15
+ * nothing understands.
16
+ */
17
+ export function detectAuthClientFlavor(AuthClient) {
18
+ const prototype = AuthClient
19
+ ?.prototype;
20
+ if (!prototype) {
21
+ return "legacy";
22
+ }
23
+ return typeof prototype.getStatus === "function" &&
24
+ typeof prototype.getPrincipal === "function"
25
+ ? "session"
26
+ : "legacy";
27
+ }
28
+ /**
29
+ * Detects the contract of a client the caller built and passed in.
30
+ *
31
+ * Such a client never goes through the module loader, so there is no
32
+ * constructor to hand {@link detectAuthClientFlavor}. The markers are the same
33
+ * two methods, reached through the instance instead of the prototype.
34
+ */
35
+ export function detectAuthClientInstanceFlavor(client) {
36
+ const instance = client;
37
+ return typeof instance?.getStatus === "function" &&
38
+ typeof instance?.getPrincipal === "function"
39
+ ? "session"
40
+ : "legacy";
41
+ }
42
+ /**
43
+ * Options a `session`-era client drops on the floor, and what replaced them.
44
+ *
45
+ * Each is a real capability in v8 with no v9+ constructor equivalent, so the
46
+ * only honest thing to do is say so rather than pass a key that is ignored.
47
+ */
48
+ const DROPPED_CONSTRUCTOR_OPTIONS = {
49
+ storage: "`storage` (an AuthClientStorage) has no v9+ equivalent: credentials moved behind `credentialStorage`, whose store also generates identities and holds a delegation alongside each key, so an AuthClientStorage cannot be adapted into one. Construct the client yourself and pass it as `authClient` to keep a custom store.",
50
+ keyType: "`keyType` was removed in v9+: the credential store decides the key type, because a store that has to serialise needs an extractable key and one that does not should not hold one.",
51
+ idleOptions: "`idleOptions` was removed in v9+: the idle timeout belongs to the identity provider canister. Pass `maxTimeToIdle` to `login()` instead, and set `disableBrowserActivity` in the AuthenticationManager options to stop the client watching the browser.",
52
+ identity: "`identity` was removed from v9+ constructor options: the agent signs as the session rather than as an identity handed in at construction.",
53
+ };
54
+ /** Emits each distinct warning once per process, so a render loop cannot spam. */
55
+ const warned = new Set();
56
+ function warnOnce(key, message) {
57
+ if (warned.has(key))
58
+ return;
59
+ warned.add(key);
60
+ console.warn(`[ic-reactor] ${message}`);
61
+ }
62
+ /** @internal Test seam -- lets a suite assert the first warning every time. */
63
+ export function resetAuthCompatWarnings() {
64
+ warned.clear();
65
+ }
66
+ /**
67
+ * Translates IC Reactor's constructor options into the installed client's shape.
68
+ *
69
+ * On `legacy` the object is already the right shape and is returned as-is,
70
+ * except for `disableBrowserActivity`. That option exists only on v10, so it is
71
+ * dropped with a one-time warning rather than handed to a v8 client that
72
+ * ignores it.
73
+ *
74
+ * On `session` the identity provider becomes a pair. The canister is not
75
+ * derived from the URL, because v9+ is explicit that the origin serving a
76
+ * ceremony is not a promise about which canister mints there. `pairing` says
77
+ * which canister goes with the URL. When nothing does, this throws rather than
78
+ * guessing: a guessed canister sends the delegation calls to a different
79
+ * deployment than the one the user signs in at, and sign-in fails later with an
80
+ * error that names neither.
81
+ *
82
+ * @param options - IC Reactor's resolved options, in the v8-shaped contract.
83
+ * @param flavor - The contract the installed client accepts.
84
+ * @param pairing - Which canister goes with `options.identityProvider`.
85
+ * @param agentOptions - Options for the agent a v9+ client mints delegations
86
+ * with. v8 has no such agent, so a `legacy` client never receives them.
87
+ */
88
+ export function toAuthClientConstructorOptions(options, flavor, pairing = { kind: "unknown" }, agentOptions) {
89
+ if (!options) {
90
+ return options;
91
+ }
92
+ if (flavor === "legacy") {
93
+ if (options.disableBrowserActivity === undefined) {
94
+ return options;
95
+ }
96
+ warnOnce("constructor:disableBrowserActivity", "`disableBrowserActivity` needs @icp-sdk/auth v10 and is ignored by v8, which has no equivalent. On v8, `idleOptions` controls idle handling.");
97
+ const { disableBrowserActivity: _disableBrowserActivity, ...legacy } = options;
98
+ return legacy;
99
+ }
100
+ // Prefixed with `_` because they are destructured only to keep them out of
101
+ // `carried`: a v9+ constructor has no equivalent for any of them, and the
102
+ // loop below is what actually reports each one that was set.
103
+ const { identityProvider, storage: _storage, keyType: _keyType, idleOptions: _idleOptions, identity: _identity, ...carried } = options;
104
+ for (const [name, explanation] of Object.entries(DROPPED_CONSTRUCTOR_OPTIONS)) {
105
+ if (options[name] !== undefined) {
106
+ warnOnce(`constructor:${name}`, explanation);
107
+ }
108
+ }
109
+ const translated = { ...carried };
110
+ if (agentOptions !== undefined) {
111
+ translated.agentOptions = agentOptions;
112
+ }
113
+ if (identityProvider !== undefined) {
114
+ if (pairing.kind === "unknown") {
115
+ throw new Error(`[ic-reactor] identityProvider ${String(identityProvider)} needs internetIdentityId with @icp-sdk/auth v10, which names a provider by its authorize URL and the canister that mints its delegations. Set internetIdentityId to the canister that serves that URL.`);
116
+ }
117
+ // An absent option is how v9+ says "both values are mainnet's".
118
+ if (pairing.kind === "pair") {
119
+ translated.identityProvider = {
120
+ authorizeUrl: identityProvider,
121
+ canisterId: pairing.canisterId,
122
+ };
123
+ }
124
+ }
125
+ return translated;
126
+ }
127
+ /**
128
+ * Translates `signIn` options into the installed client's shape.
129
+ *
130
+ * `targets` is the one that matters. v8 forwards it to restrict the delegation
131
+ * to named canisters; v9+ removed it, and scoping is decided by the identity
132
+ * provider against the app's own canister. Passing it to a v9+ client does not
133
+ * fail -- it is simply ignored, and the delegation that comes back is broader
134
+ * than the caller asked for. That is a security-relevant difference, so it
135
+ * warns unconditionally rather than only in development.
136
+ *
137
+ * `maxTimeToIdle` goes the other way. It exists only on v10, so a v10 client
138
+ * receives it, and a v8 client, whose sign-in has no idle limit, gets it
139
+ * dropped with a one-time warning.
140
+ */
141
+ export function toAuthClientSignInOptions(options, flavor) {
142
+ if (!options) {
143
+ return options;
144
+ }
145
+ if (flavor === "legacy") {
146
+ if (options.maxTimeToIdle === undefined) {
147
+ return options;
148
+ }
149
+ warnOnce("signIn:maxTimeToIdle", "`maxTimeToIdle` needs @icp-sdk/auth v10 and is ignored by v8, whose sign-in has no idle limit. On v8, set `idleOptions` instead.");
150
+ const { maxTimeToIdle: _maxTimeToIdle, ...legacy } = options;
151
+ return legacy;
152
+ }
153
+ const { targets, ...carried } = options;
154
+ if (targets !== undefined) {
155
+ // Every time, not once: each sign-in that passes `targets` receives a
156
+ // delegation broader than it asked for, and a warning spent on an earlier
157
+ // one says nothing about this one.
158
+ console.warn("[ic-reactor] `targets` was removed in @icp-sdk/auth v9+ and is ignored: the delegation you receive is NOT restricted to those canisters. The identity provider scopes a session to the application canister instead. Remove `targets`, or pin @icp-sdk/auth to ^8 if you depend on canister-scoped delegations.");
159
+ }
160
+ return carried;
161
+ }
162
+ //# sourceMappingURL=auth-client-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-client-compat.js","sourceRoot":"","sources":["../../src/auth/auth-client-compat.ts"],"names":[],"mappings":"AA2DA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAmB;IACxD,MAAM,SAAS,GAAI,UAAsD;QACvE,EAAE,SAAS,CAAA;IAEb,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,OAAO,SAAS,CAAC,SAAS,KAAK,UAAU;QAC9C,OAAO,SAAS,CAAC,YAAY,KAAK,UAAU;QAC5C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,QAAQ,CAAA;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAAe;IAEf,MAAM,QAAQ,GAAG,MAA6C,CAAA;IAE9D,OAAO,OAAO,QAAQ,EAAE,SAAS,KAAK,UAAU;QAC9C,OAAO,QAAQ,EAAE,YAAY,KAAK,UAAU;QAC5C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,QAAQ,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,2BAA2B,GAA2B;IAC1D,OAAO,EACL,8TAA8T;IAChU,OAAO,EACL,oLAAoL;IACtL,WAA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,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,OAAO,CAAA;IAEvC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,sEAAsE;QACtE,0EAA0E;QAC1E,mCAAmC;QACnC,OAAO,CAAC,IAAI,CACV,iTAAiT,CAClT,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -30,10 +30,29 @@ export declare class AuthenticationManager {
30
30
  private authClientConstructor?;
31
31
  private authClientConstructorPromise?;
32
32
  private authModuleMissing;
33
+ private authClientFlavor;
33
34
  private authClientOptions?;
34
35
  private authStateValue;
36
+ /** See {@link sessionChecked}. */
37
+ private sessionCheckedValue;
38
+ private sessionCheckedSubscribers;
39
+ /** Stops following the current client's session record; see `watchClient()`. */
40
+ private unwatchClient?;
41
+ /**
42
+ * Set when the client's session record changed while an operation of this
43
+ * manager's own was running; see `followClient()`.
44
+ */
45
+ private clientChangedDuringOperation;
46
+ /** Counts `followClient()` passes, so that only the latest one publishes. */
47
+ private followRevision;
48
+ /** Counts `dispose()` calls; see {@link releaseCount}. */
49
+ private releases;
35
50
  private readonly identityProvider?;
51
+ /** The provider taken from the `ic_env` cookie, when no caller set one. */
52
+ private readonly envIdentityProvider?;
36
53
  private readonly internetIdentityId?;
54
+ /** Whether `internetIdentityId` came from the caller rather than the cookie. */
55
+ private readonly internetIdentityIdIsExplicit;
37
56
  /**
38
57
  * Which authorize path the locally deployed Internet Identity serves, once
39
58
  * probed. `undefined` means not probed yet; `null` means it serves no sign-in
@@ -48,6 +67,91 @@ export declare class AuthenticationManager {
48
67
  constructor({ clientManager, authClient, identityProvider, internetIdentityId, ...clientOptions }: AuthenticationManagerParameters);
49
68
  /** @internal Used by IdentityAttributesManager. */
50
69
  get client(): AuthClientLike | undefined;
70
+ /**
71
+ * @internal Used by the auth hooks.
72
+ *
73
+ * Whether this manager has checked its client for a session: a restore has
74
+ * settled, whether it found a session, found none or failed, or a sign-in or
75
+ * sign-out has completed. Until then {@link authState} is the signed-out state
76
+ * the manager starts in, which says nothing about the session, so the auth
77
+ * hooks report `isAuthenticating: true` instead.
78
+ */
79
+ get sessionChecked(): boolean;
80
+ /**
81
+ * @internal Used by the auth hooks.
82
+ *
83
+ * Records that the session has been checked, and tells the auth hooks the
84
+ * first time. A restore that failed counts: waiting on one that will not be
85
+ * retried would leave the hooks reporting `isAuthenticating: true` for good.
86
+ */
87
+ markSessionChecked(): void;
88
+ /**
89
+ * @internal Used by the auth hooks.
90
+ *
91
+ * How many times {@link dispose} has run. A restore the hooks started
92
+ * compares it with the count it began with, to tell whether the manager was
93
+ * released while it ran.
94
+ */
95
+ get releaseCount(): number;
96
+ /**
97
+ * @internal Used by the auth hooks.
98
+ *
99
+ * Calls `callback` once, when {@link sessionChecked} turns true. Nothing else
100
+ * announces it when the check that settles it publishes no state, as a
101
+ * restore that failed before it read the client does not.
102
+ *
103
+ * @returns An unsubscribe function.
104
+ */
105
+ subscribeSessionChecked(callback: () => void): () => void;
106
+ /**
107
+ * Releases the `@icp-sdk/auth` client this manager built.
108
+ *
109
+ * A v10 client hooks the page when it is built: activity listeners on
110
+ * `document`, focus and visibility listeners, a watch on the session record
111
+ * that every tab shares and, once signed in, a refresh timer. Nothing
112
+ * releases them when the manager is dropped, so a manager built per mount,
113
+ * as a server-rendered app builds one in its provider, left one live client
114
+ * behind on each remount. Call this when you discard the manager, from the
115
+ * cleanup of whatever built it.
116
+ *
117
+ * The client is disposed and forgotten, so a later {@link prepareClient},
118
+ * {@link login}, {@link logout} or restore that needs a client builds a new
119
+ * one. That keeps it safe in an effect cleanup under React's StrictMode,
120
+ * which runs the cleanup and then the effect again on the same manager. With
121
+ * `@icp-sdk/auth` v8 there is nothing to release, and the manager only drops
122
+ * its reference. A client passed in as `authClient` belongs to the caller: it
123
+ * is never disposed, and the manager goes on using it, but stops following its
124
+ * session record until its next {@link prepareClient}, {@link login} or
125
+ * {@link authenticate}, so that the caller's client does not keep a
126
+ * discarded manager alive.
127
+ *
128
+ * The auth state and the identity on the agent are left as they are. A
129
+ * restore reading the client when it is released ends without publishing
130
+ * what it read, and a sign-in or sign-out under way ends with what the
131
+ * released client reports. A restore `useAuth()` started stops, and
132
+ * releases any client it built meanwhile, once no `useAuth()` of this
133
+ * manager is mounted; one mounted later restores again.
134
+ *
135
+ * @example
136
+ * ```tsx
137
+ * const [authentication] = useState(
138
+ * () => new AuthenticationManager({ clientManager })
139
+ * )
140
+ * useEffect(() => () => authentication.dispose(), [authentication])
141
+ * ```
142
+ */
143
+ dispose(): void;
144
+ /**
145
+ * Subscribes to auth state changes.
146
+ *
147
+ * Callbacks run in the order they subscribed, after the state has changed. A
148
+ * callback that throws does not stop the others; the first error is rethrown
149
+ * to whatever made the change once they have all run. When a callback itself
150
+ * changes the state, the newer state is the last each callback hears.
151
+ *
152
+ * @param callback - Function called with the new state.
153
+ * @returns An unsubscribe function.
154
+ */
51
155
  subscribeAuthState(callback: (state: AuthState) => void): () => void;
52
156
  /**
53
157
  * Preloads the auth module and creates an AuthClient ahead of time.
@@ -76,14 +180,116 @@ export declare class AuthenticationManager {
76
180
  */
77
181
  getPreparedClient(options?: AuthenticationClientOptions): AuthClientLike | undefined;
78
182
  authenticate: () => Promise<Identity | undefined>;
183
+ private checkSession;
79
184
  login: (loginOptions?: AuthenticationSignInOptions) => Promise<void>;
80
185
  logout: (options?: {
81
186
  returnTo?: string;
82
187
  }) => Promise<void>;
83
188
  private initializeClient;
189
+ /**
190
+ * Makes `client`, which this manager built for `options`, the current one.
191
+ *
192
+ * The client it replaces was built here too, for other options: a caller's
193
+ * `authClient` is never replaced. It was dropped with nothing released, so a
194
+ * v10 client kept its browser listeners, its state subscription and its
195
+ * session's refresh timer for the life of the page, one more for each switch
196
+ * between option sets, such as a one-click sign-in and a plain one (#729).
197
+ * v10 asks for `dispose()` on a client being discarded, and a new
198
+ * interaction already takes its signer channel from the old client, so this
199
+ * adds no failure of its own. A v8 client has nothing to dispose; see
200
+ * `withSharedIdleCallback()` for the callback it leaves registered.
201
+ */
202
+ private installClient;
203
+ /**
204
+ * Follows a v10 client's session record, which every tab of the origin
205
+ * shares.
206
+ *
207
+ * The manager learned about the session only through its own calls, while a
208
+ * v10 client follows the other tabs. After a sign-out in another tab, this
209
+ * tab's client dropped the session and its manager went on reporting the
210
+ * user signed in, with the replaced identity on the agent signing calls as
211
+ * the account the user had left. After a sign-in there as another account,
212
+ * the manager kept the old account while the client held the new one. When
213
+ * the old identity's app delegation then lapsed, its mint was refused and
214
+ * the client removed the record every tab reads, signing the new account out
215
+ * of every tab (#754). `subscribe()` fires after the record changes, here or
216
+ * in another tab, and the manager then reads the client again.
217
+ *
218
+ * v8 has no notification and never revokes a session, so a v8 client is not
219
+ * followed.
220
+ */
221
+ private watchClient;
222
+ private stopWatchingClient;
223
+ /**
224
+ * Reads the session from `client` after its record changed, and publishes
225
+ * it when it differs from what this manager holds, as `syncStateFromClient()`
226
+ * derives it. An error recorded for the session it replaces goes with it.
227
+ *
228
+ * An operation of the manager's own, which sets `isAuthenticating`, writes
229
+ * the record itself and publishes what the client holds when it ends, so a
230
+ * change during one is read again once it has. So is a change whose read
231
+ * something else published over.
232
+ */
233
+ private followClient;
234
+ /**
235
+ * The identity `client` hands out, and whether it vouches for it (see
236
+ * `vouchesFor()`). Both are read from the same client.
237
+ */
238
+ private readClientSession;
239
+ /**
240
+ * The session `client` holds, or `undefined` to leave the manager's as it is.
241
+ *
242
+ * v10 refuses to hand out an identity while the record names a sign-in it
243
+ * holds no credential for, as when restoring the account another tab signed
244
+ * in as failed. The session this manager holds is kept then only while the
245
+ * record still names its account. One for any other account must not stay
246
+ * on the agent.
247
+ */
248
+ private readFollowedSession;
84
249
  /** @internal Used by IdentityAttributesManager. */
85
250
  signInOrRecoverIdentity(options?: AuthClientSignInOptions): Promise<Identity>;
86
251
  private ensurePreparedClient;
252
+ /**
253
+ * Hands the installed client the option shape it actually accepts.
254
+ *
255
+ * `authClientOptions` keeps the untranslated values, and `shouldRecreateClient`
256
+ * compares them with the installed major in mind: two calls that differ only
257
+ * in a key that major drops count as the same options, so the client is not
258
+ * rebuilt for them.
259
+ */
260
+ private toClientOptions;
261
+ /**
262
+ * Options for the agent a v9+ client mints delegations with, off mainnet.
263
+ *
264
+ * That client makes its own calls to the Internet Identity canister, through
265
+ * an agent built from these options alone. Without a root key it checks every
266
+ * certificate against mainnet's, which a local replica or testnet cannot
267
+ * satisfy, so sign-in would fail at the first mint. Off mainnet it gets the
268
+ * replica this app already talks to and fetches that network's root key, the
269
+ * same trust the app's own agent needs there. When the app passed its own
270
+ * `agentOptions.rootKey`, which its agent keeps, the minting agent gets that
271
+ * key instead and verifies against it too. On mainnet nothing is passed, and
272
+ * the client keeps its defaults.
273
+ */
274
+ private sessionAgentOptions;
275
+ /**
276
+ * Which canister a v9+ client should pair with `identityProvider`.
277
+ *
278
+ * v9+ names a provider by its authorize URL and the canister that mints its
279
+ * delegations, and nothing about the canister follows from the URL. The
280
+ * mainnet URL goes with mainnet's canister unless the caller named another.
281
+ * A canister read from the `ic_env` cookie belongs to a local deployment, so
282
+ * it never overrides that. Any other URL takes `internetIdentityId`, or the
283
+ * well-known local canister when the URL is one IC Reactor derived for a
284
+ * local deployment. A URL the caller set with no canister stays `unknown`.
285
+ */
286
+ private identityProviderPairing;
287
+ /**
288
+ * Whether `identityProvider` is a local provider IC Reactor chose, from the
289
+ * `ic_env` cookie or built for the local replica, rather than one a caller
290
+ * configured.
291
+ */
292
+ private isDerivedLocalProvider;
87
293
  /**
88
294
  * Only rebuild the client when the effective options actually changed.
89
295
  *
@@ -100,11 +306,55 @@ export declare class AuthenticationManager {
100
306
  /** Whether the shared agent currently signs as the anonymous principal. */
101
307
  private agentIsAnonymous;
102
308
  /**
103
- * End a session whose delegation has lapsed: ask the client to forget it,
104
- * put the anonymous identity on the agent -- which also sweeps the previous
105
- * user's caller-scoped cache entries and refetches the rest anonymously --
106
- * and publish the signed-out state. `signOut` failing changes nothing here:
107
- * the delegation is already unusable, and the agent must not keep it.
309
+ * @internal Used by IdentityAttributesManager.
310
+ *
311
+ * Whether the client vouches for `identity`, given what its
312
+ * `isAuthenticated()` answered.
313
+ *
314
+ * A v8 client's answer is not about the identity it holds. It reads the
315
+ * delegation expiry v8 keeps in the `localStorage` every tab shares, while
316
+ * `getIdentity()` returns the identity this client restored or signed in
317
+ * with, and v8 never reads storage again once it has loaded. When the session
318
+ * lapses and the user signs in again in another tab, that tab writes a new
319
+ * expiry, and the answer is yes again for the delegation this tab still
320
+ * holds, which the replica refuses. So a v8 identity whose own delegation
321
+ * has expired is not vouched for, whatever the answer. Nor is the anonymous
322
+ * identity, which a v8 client that loaded signed out, or signed out, goes on
323
+ * handing out once another tab signs in and the answer turns yes. It signs
324
+ * no one in.
325
+ *
326
+ * A v10 client's answer is about the session it holds, and its identity
327
+ * replaces its short-lived delegation as it ages, so the delegation it holds
328
+ * can be past its expiry while the session is live. The answer stands alone.
329
+ */
330
+ vouchesFor(identity: Identity | null | undefined, isAuthenticated: boolean): boolean;
331
+ /**
332
+ * End a session the client no longer vouches for: put the anonymous
333
+ * identity on the agent -- which also sweeps the previous user's
334
+ * caller-scoped cache entries and refetches the rest anonymously -- and
335
+ * publish the signed-out state.
336
+ *
337
+ * A v8 client is also asked to forget the session when its
338
+ * `isAuthenticated()` answered no, since it keeps handing out the lapsed
339
+ * delegation until `signOut()` runs. That answer reads the expiry kept in
340
+ * the `localStorage` every tab shares, so it is no only once the session
341
+ * stored for every tab is over, and v8's `signOut()` takes no lock and
342
+ * revokes nothing. `signOut` failing changes nothing here: the delegation is
343
+ * already unusable, and the agent must not keep it. When the answer was yes,
344
+ * the delegation this tab holds lapsed under a session another tab has
345
+ * signed in to since, and `signOut()` would delete that session from the
346
+ * storage every tab shares. The client is left alone, and `vouchesFor()`
347
+ * keeps the lapsed delegation it goes on handing out off the agent.
348
+ *
349
+ * A v10 client is left alone, as `commitSignedOut()` leaves it. Its
350
+ * `signOut()` ends the sign-in for every tab of the origin: it takes the
351
+ * sign-in lock from a sign-in another tab has in progress, which then fails,
352
+ * revokes whatever session the shared store holds, and removes the record
353
+ * every tab reads. Another tab may have signed in again since this one last
354
+ * looked, and finding a session over is not the user asking to sign out.
355
+ * The client already stopped vouching for the session on its own.
356
+ *
357
+ * @param isAuthenticated - What the client's `isAuthenticated()` answered.
108
358
  */
109
359
  private expireSession;
110
360
  private syncStateFromClient;
@@ -116,7 +366,39 @@ export declare class AuthenticationManager {
116
366
  setAuthenticating(): void;
117
367
  /** @internal Used by IdentityAttributesManager. */
118
368
  setAuthenticationError(error: Error): void;
369
+ /** @internal Used by IdentityAttributesManager. */
370
+ settleAuthenticating(): void;
371
+ /**
372
+ * @internal Used by IdentityAttributesManager.
373
+ *
374
+ * Signs this manager out after the client lost its session under it, as when
375
+ * another tab signed out. The client itself is left alone: a v10 sign-out
376
+ * clears the storage every tab shares and takes the sign-in lock, so it would
377
+ * also end a sign-in the other tab has made or started since.
378
+ */
379
+ commitSignedOut(): void;
119
380
  private getDefaultIdentityProvider;
381
+ /**
382
+ * Publishes what a check of the session found, then marks the session
383
+ * checked. In that order, so the auth hooks never take the state before it
384
+ * for the answer.
385
+ */
386
+ private publishSession;
387
+ /**
388
+ * Records a change, then tells every subscriber about it.
389
+ *
390
+ * Every subscriber is called even when one throws, and the first error is
391
+ * rethrown once they all have been, so the caller still sees it. A throw
392
+ * used to end the loop: an app's subscriber registered at module scope comes
393
+ * before every `useAuth()`, and one that failed on a sign-in left them all
394
+ * showing `isAuthenticating: true` while the agent signed as the user.
395
+ *
396
+ * A subscriber that changes the state again from its callback has told every
397
+ * subscriber about that newer state, so the loop stops rather than deliver
398
+ * this older one after it. The list is copied first, so a subscriber added
399
+ * during the loop is first called for the next change. `ClientManager`
400
+ * notifies its subscribers the same way.
401
+ */
120
402
  private updateState;
121
403
  private loadAuthClientConstructor;
122
404
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authentication-manager.d.ts","sourceRoot":"","sources":["../../src/auth/authentication-manager.ts"],"names":[],"mapp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