@ic-reactor/react 3.12.5 → 4.0.0-beta.1
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 +236 -423
- package/dist/index.d.ts +259 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +470 -17
- package/dist/index.js.map +1 -1
- package/llms.txt +82 -54
- package/package.json +12 -28
- package/src/index.tsx +611 -0
- package/dist/auth/authentication-manager.d.ts +0 -123
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -767
- package/dist/auth/authentication-manager.js.map +0 -1
- package/dist/auth/constants.d.ts +0 -24
- package/dist/auth/constants.d.ts.map +0 -1
- package/dist/auth/constants.js +0 -24
- package/dist/auth/constants.js.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.js +0 -106
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -26
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -107
- package/dist/auth/identity-attributes-manager.js.map +0 -1
- package/dist/auth/identity-attributes.d.ts +0 -19
- package/dist/auth/identity-attributes.d.ts.map +0 -1
- package/dist/auth/identity-attributes.js +0 -170
- package/dist/auth/identity-attributes.js.map +0 -1
- package/dist/auth/index.d.ts +0 -8
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -8
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/local-ii-probe.d.ts +0 -46
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -102
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -179
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/createActorHooks.d.ts +0 -52
- package/dist/createActorHooks.d.ts.map +0 -1
- package/dist/createActorHooks.js +0 -17
- package/dist/createActorHooks.js.map +0 -1
- package/dist/createInfiniteQuery.d.ts +0 -144
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -174
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -30
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -192
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -30
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -117
- package/dist/createQuery.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -147
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -177
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -25
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -111
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -125
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -180
- package/dist/defineReactor.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -43
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -131
- package/dist/hooks/createAuthHooks.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -21
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -24
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +0 -39
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -56
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -115
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -250
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -48
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -69
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -32
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -46
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -39
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -56
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.js +0 -47
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/types.d.ts +0 -270
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -51
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -105
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -131
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -125
- package/dist/validation.js.map +0 -1
- package/src/auth/authentication-manager.ts +0 -860
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -143
- package/src/auth/identity-attributes-manager.ts +0 -131
- package/src/auth/identity-attributes.ts +0 -270
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -147
- package/src/auth/types.ts +0 -200
- package/src/createActorHooks.ts +0 -220
- package/src/createInfiniteQuery.ts +0 -578
- package/src/createMutation.ts +0 -341
- package/src/createQuery.ts +0 -237
- package/src/createSuspenseInfiniteQuery.ts +0 -601
- package/src/createSuspenseQuery.ts +0 -234
- package/src/defineReactor.ts +0 -324
- package/src/hooks/createAuthHooks.ts +0 -189
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -205
- package/src/hooks/useActorMethod.ts +0 -507
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -124
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -205
- package/src/hooks/useActorSuspenseQuery.ts +0 -132
- package/src/index.ts +0 -23
- package/src/types.ts +0 -499
- package/src/utils.ts +0 -121
- package/src/validation.ts +0 -202
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ask a locally deployed Internet Identity canister what it actually serves.
|
|
3
|
-
*
|
|
4
|
-
* `localInternetIdentityProvider` builds `http://<id>.localhost:<port>/authorize`,
|
|
5
|
-
* the id.ai-era path. Whether that works depends on which Internet Identity
|
|
6
|
-
* build is installed, and the window is narrow:
|
|
7
|
-
*
|
|
8
|
-
* - up to `release-2025-03-07`, the SPA lived at `/` and used a `#authorize`
|
|
9
|
-
* fragment; `/authorize` is not an asset
|
|
10
|
-
* - `release-2026-01-05` through `release-2026-03-16` serve `/authorize`
|
|
11
|
-
* - from `release-2026-03-23` the frontend left the canister entirely (the id.ai
|
|
12
|
-
* split), so `/authorize` 404s even on `.raw`
|
|
13
|
-
*
|
|
14
|
-
* Outside that window the login popup renders the gateway's
|
|
15
|
-
* "Response Verification Error" page and the app simply waits until the user
|
|
16
|
-
* closes it. Nothing points at the cause.
|
|
17
|
-
*
|
|
18
|
-
* Asking the canister over the agent avoids the gateway, so the answer is about
|
|
19
|
-
* the canister's assets rather than about how the gateway felt about them.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import { Actor, type HttpAgent } from "@icp-sdk/core/agent"
|
|
23
|
-
import { IDL } from "@icp-sdk/core/candid"
|
|
24
|
-
|
|
25
|
-
/** The `http_request` query every asset-serving canister exposes. */
|
|
26
|
-
const httpInterface: IDL.InterfaceFactory = ({ IDL }) => {
|
|
27
|
-
const HeaderField = IDL.Tuple(IDL.Text, IDL.Text)
|
|
28
|
-
return IDL.Service({
|
|
29
|
-
http_request: IDL.Func(
|
|
30
|
-
[
|
|
31
|
-
IDL.Record({
|
|
32
|
-
method: IDL.Text,
|
|
33
|
-
url: IDL.Text,
|
|
34
|
-
headers: IDL.Vec(HeaderField),
|
|
35
|
-
body: IDL.Vec(IDL.Nat8),
|
|
36
|
-
}),
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
IDL.Record({
|
|
40
|
-
status_code: IDL.Nat16,
|
|
41
|
-
headers: IDL.Vec(HeaderField),
|
|
42
|
-
body: IDL.Vec(IDL.Nat8),
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
["query"]
|
|
46
|
-
),
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface HttpCapableActor {
|
|
51
|
-
http_request: (request: {
|
|
52
|
-
method: string
|
|
53
|
-
url: string
|
|
54
|
-
headers: [string, string][]
|
|
55
|
-
body: Uint8Array
|
|
56
|
-
}) => Promise<{ status_code: number }>
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Where a given Internet Identity build expects the sign-in flow to start. */
|
|
60
|
-
export type AuthorizePath = "/authorize" | "/#authorize"
|
|
61
|
-
|
|
62
|
-
export interface LocalIiProbe {
|
|
63
|
-
/** The path that works, or `null` when the canister serves no sign-in UI. */
|
|
64
|
-
path: AuthorizePath | null
|
|
65
|
-
/**
|
|
66
|
-
* The probe could not reach a conclusion — the canister was unreachable, or
|
|
67
|
-
* it does not expose `http_request` at all. Callers keep their existing
|
|
68
|
-
* behaviour rather than blocking a login that might well work.
|
|
69
|
-
*/
|
|
70
|
-
inconclusive: boolean
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function statusOf(
|
|
74
|
-
actor: HttpCapableActor,
|
|
75
|
-
url: string
|
|
76
|
-
): Promise<number | undefined> {
|
|
77
|
-
try {
|
|
78
|
-
const response = await actor.http_request({
|
|
79
|
-
method: "GET",
|
|
80
|
-
url,
|
|
81
|
-
headers: [],
|
|
82
|
-
body: new Uint8Array(),
|
|
83
|
-
})
|
|
84
|
-
return response.status_code
|
|
85
|
-
} catch {
|
|
86
|
-
return undefined
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Determine which authorize path a locally deployed Internet Identity serves.
|
|
92
|
-
*
|
|
93
|
-
* Never throws. A probe that cannot answer returns `inconclusive`, because a
|
|
94
|
-
* diagnostic that blocks a working setup is worse than the failure it explains.
|
|
95
|
-
*/
|
|
96
|
-
export async function probeLocalInternetIdentity(
|
|
97
|
-
agent: HttpAgent,
|
|
98
|
-
canisterId: string
|
|
99
|
-
): Promise<LocalIiProbe> {
|
|
100
|
-
let actor: HttpCapableActor
|
|
101
|
-
try {
|
|
102
|
-
actor = Actor.createActor<HttpCapableActor>(httpInterface, {
|
|
103
|
-
agent,
|
|
104
|
-
canisterId,
|
|
105
|
-
})
|
|
106
|
-
} catch {
|
|
107
|
-
return { path: "/authorize", inconclusive: true }
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const authorize = await statusOf(actor, "/authorize")
|
|
111
|
-
|
|
112
|
-
// The canister does not answer http_request at all — not an asset canister,
|
|
113
|
-
// not deployed, or the replica is down. Not our call to make.
|
|
114
|
-
if (authorize === undefined) {
|
|
115
|
-
return { path: "/authorize", inconclusive: true }
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (authorize >= 200 && authorize < 300) {
|
|
119
|
-
return { path: "/authorize", inconclusive: false }
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Pre-2026 builds serve the SPA at the root and drive the flow from a
|
|
123
|
-
// `#authorize` fragment, which is a path the gateway never sees.
|
|
124
|
-
const root = await statusOf(actor, "/")
|
|
125
|
-
if (root !== undefined && root >= 200 && root < 300) {
|
|
126
|
-
return { path: "/#authorize", inconclusive: false }
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { path: null, inconclusive: false }
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The error a login gets when the installed build serves no sign-in UI, in
|
|
134
|
-
* place of a 503 page inside a popup the app cannot see.
|
|
135
|
-
*/
|
|
136
|
-
export function localInternetIdentityUnavailableError(
|
|
137
|
-
canisterId: string
|
|
138
|
-
): Error {
|
|
139
|
-
return new Error(
|
|
140
|
-
`[ic-reactor] The Internet Identity canister ${canisterId} does not serve a sign-in UI: ` +
|
|
141
|
-
`neither /authorize nor / returned a page. Internet Identity builds from ` +
|
|
142
|
-
`release-2026-03-23 onward moved their frontend out of the canister (the id.ai split) ` +
|
|
143
|
-
`and cannot be used locally. Install internet_identity_dev.wasm from release-2026-03-16, ` +
|
|
144
|
-
`the newest build that still self-serves /authorize, or point \`identityProvider\` at a ` +
|
|
145
|
-
`provider you host yourself.`
|
|
146
|
-
)
|
|
147
|
-
}
|
package/src/auth/types.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import type { Identity, SignIdentity } from "@icp-sdk/core/agent"
|
|
2
|
-
import type { PartialIdentity } from "@icp-sdk/core/identity"
|
|
3
|
-
import type { Principal } from "@icp-sdk/core/principal"
|
|
4
|
-
|
|
5
|
-
export interface SignedIdentityAttributes {
|
|
6
|
-
data: Uint8Array
|
|
7
|
-
signature: Uint8Array
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The 32-byte nonce issued by the relying-party canister.
|
|
12
|
-
*
|
|
13
|
-
* A function (or promise) lets the Internet Identity window open while the
|
|
14
|
-
* nonce is still being fetched, so the popup is opened inside the user gesture
|
|
15
|
-
* instead of after it. `@icp-sdk/auth` v8 requires the function form, and
|
|
16
|
-
* IC Reactor normalizes whichever of these you pass into that thunk.
|
|
17
|
-
*/
|
|
18
|
-
export type IdentityAttributeNonce =
|
|
19
|
-
Uint8Array | Promise<Uint8Array> | (() => Uint8Array | Promise<Uint8Array>)
|
|
20
|
-
|
|
21
|
-
export interface IdentityAttributeRequest {
|
|
22
|
-
keys: string[]
|
|
23
|
-
nonce: IdentityAttributeNonce
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface IdentityAttributeValues {
|
|
27
|
-
email?: string
|
|
28
|
-
name?: string
|
|
29
|
-
verified_email?: string
|
|
30
|
-
[key: string]: string | undefined
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface IdentityAttributeResult {
|
|
34
|
-
principal: string
|
|
35
|
-
requestedKeys: string[]
|
|
36
|
-
signedAttributes: SignedIdentityAttributes
|
|
37
|
-
decodedAttributes: IdentityAttributeValues
|
|
38
|
-
completedAt: string
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The providers that Internet Identity supports for one-click sign-in. Only
|
|
43
|
-
* these three reach the underlying auth client.
|
|
44
|
-
*/
|
|
45
|
-
type IdentityAttributeOpenIdProviderAlias = "google" | "apple" | "microsoft"
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* An OpenID provider, either as a well-known alias or as a raw issuer URL.
|
|
49
|
-
*
|
|
50
|
-
* The two forms are **not** interchangeable, and what each one does depends on
|
|
51
|
-
* where it is passed:
|
|
52
|
-
*
|
|
53
|
-
* - An alias (`"google" | "apple" | "microsoft"`) is forwarded to the auth
|
|
54
|
-
* client, which adds an `openid` search param to the identity provider URL so
|
|
55
|
-
* the user signs in through that provider directly.
|
|
56
|
-
* - Any other string is treated as a raw issuer URL and is **never** forwarded
|
|
57
|
-
* to the auth client, so it never affects how the user signs in. It is only
|
|
58
|
-
* meaningful when passed to {@link IdentityAttributesManager.requestOpenId}
|
|
59
|
-
* (or `identityAttributeKeys`), which scopes the requested keys to
|
|
60
|
-
* `openid:<issuer>:<key>`. Passed anywhere else it has no effect at all.
|
|
61
|
-
*/
|
|
62
|
-
export type IdentityAttributeOpenIdProvider =
|
|
63
|
-
IdentityAttributeOpenIdProviderAlias | (string & {})
|
|
64
|
-
|
|
65
|
-
/** Session key algorithm used for each sign-in. */
|
|
66
|
-
export type AuthClientKeyType = "ECDSA" | "Ed25519"
|
|
67
|
-
|
|
68
|
-
/** Structural shape of an `@icp-sdk/auth` `AuthClientStorage`. */
|
|
69
|
-
export interface AuthClientStorageLike {
|
|
70
|
-
get(key: string): Promise<string | CryptoKeyPair | null>
|
|
71
|
-
set(key: string, value: string | CryptoKeyPair): Promise<void>
|
|
72
|
-
remove(key: string): Promise<void>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Idle-session configuration forwarded to the underlying AuthClient. */
|
|
76
|
-
export interface AuthClientIdleOptions {
|
|
77
|
-
/** Called once the user has been idle for `idleTimeout` ms. */
|
|
78
|
-
onIdle?: () => unknown
|
|
79
|
-
/** Idle timeout in ms. @default 600_000 (10 minutes) */
|
|
80
|
-
idleTimeout?: number
|
|
81
|
-
/** Treat scroll events as activity. @default false */
|
|
82
|
-
captureScroll?: boolean
|
|
83
|
-
/** Scroll debounce in ms. @default 100 */
|
|
84
|
-
scrollDebounce?: number
|
|
85
|
-
/** Disable idle detection entirely. @default false */
|
|
86
|
-
disableIdle?: boolean
|
|
87
|
-
/**
|
|
88
|
-
* Disable the built-in idle callback, which signs the user out and reloads
|
|
89
|
-
* the page. @default false
|
|
90
|
-
*/
|
|
91
|
-
disableDefaultIdleCallback?: boolean
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface AuthenticationClientOptions {
|
|
95
|
-
/** Identity provider URL. @default "https://id.ai/authorize" */
|
|
96
|
-
identityProvider?: string | URL
|
|
97
|
-
/** `window.open` features string for the identity provider popup. */
|
|
98
|
-
windowOpenerFeatures?: string
|
|
99
|
-
/**
|
|
100
|
-
* Provider for one-click sign-in.
|
|
101
|
-
*
|
|
102
|
-
* Only the `"google" | "apple" | "microsoft"` aliases reach the auth client.
|
|
103
|
-
* Any other value is dropped here and has **no effect** — raw issuer URLs are
|
|
104
|
-
* only meaningful on `requestOpenId`, where they scope the requested keys.
|
|
105
|
-
* @see {@link IdentityAttributeOpenIdProvider}
|
|
106
|
-
*/
|
|
107
|
-
openIdProvider?: IdentityAttributeOpenIdProvider
|
|
108
|
-
/**
|
|
109
|
-
* Derivation origin for the identity provider.
|
|
110
|
-
*
|
|
111
|
-
* Required when the app is served from more than one origin (e.g. a custom
|
|
112
|
-
* domain plus `<canisterId>.icp0.io`) and every origin must resolve to the
|
|
113
|
-
* same principal.
|
|
114
|
-
* @see https://github.com/dfinity/internet-identity/blob/main/docs/internet-identity-spec.adoc
|
|
115
|
-
*/
|
|
116
|
-
derivationOrigin?: string | URL
|
|
117
|
-
/** Persistent storage backend. @default IndexedDB */
|
|
118
|
-
storage?: AuthClientStorageLike
|
|
119
|
-
/**
|
|
120
|
-
* Session key algorithm. Use `"Ed25519"` when the storage backend cannot
|
|
121
|
-
* hold a `CryptoKey`. @default "ECDSA"
|
|
122
|
-
*/
|
|
123
|
-
keyType?: AuthClientKeyType
|
|
124
|
-
/**
|
|
125
|
-
* Idle timeout configuration. Pass `{ disableIdle: true }` to opt out of the
|
|
126
|
-
* default behaviour, which signs the user out and reloads after 10 minutes.
|
|
127
|
-
*/
|
|
128
|
-
idleOptions?: AuthClientIdleOptions
|
|
129
|
-
/** An existing identity to authenticate via delegation. */
|
|
130
|
-
identity?: SignIdentity | PartialIdentity
|
|
131
|
-
/**
|
|
132
|
-
* How the client talks to the identity provider. `"redirect"` requires
|
|
133
|
-
* `@icp-sdk/auth` v8 or later and is ignored by older versions.
|
|
134
|
-
* @default "window"
|
|
135
|
-
*/
|
|
136
|
-
transport?: "window" | "redirect"
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface AuthClientSignInOptions {
|
|
140
|
-
maxTimeToLive?: bigint
|
|
141
|
-
targets?: Principal[]
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export interface AuthenticationSignInOptions
|
|
145
|
-
extends AuthClientSignInOptions, AuthenticationClientOptions {
|
|
146
|
-
onSuccess?: () => void | Promise<void>
|
|
147
|
-
onError?: (error?: string) => void | Promise<void>
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface RequestIdentityAttributesParameters extends AuthenticationClientOptions {
|
|
151
|
-
keys: string[]
|
|
152
|
-
nonce: IdentityAttributeNonce
|
|
153
|
-
/**
|
|
154
|
-
* Sign in as part of the same identity-provider interaction.
|
|
155
|
-
* @default true
|
|
156
|
-
*/
|
|
157
|
-
signIn?: boolean
|
|
158
|
-
maxTimeToLive?: bigint
|
|
159
|
-
targets?: Principal[]
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export interface RequestOpenIdIdentityAttributesParameters extends Omit<
|
|
163
|
-
RequestIdentityAttributesParameters,
|
|
164
|
-
"openIdProvider"
|
|
165
|
-
> {
|
|
166
|
-
/**
|
|
167
|
-
* Provider the requested `keys` are scoped to, producing
|
|
168
|
-
* `openid:<issuer>:<key>`.
|
|
169
|
-
*
|
|
170
|
-
* Passing one of the `"google" | "apple" | "microsoft"` aliases additionally
|
|
171
|
-
* routes sign-in through that provider, so the user grants attribute access
|
|
172
|
-
* in the same step. A raw issuer URL only scopes the keys.
|
|
173
|
-
* @see {@link IdentityAttributeOpenIdProvider}
|
|
174
|
-
*/
|
|
175
|
-
openIdProvider: IdentityAttributeOpenIdProvider
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Structural subset of `@icp-sdk/auth`'s `AuthClient` that IC Reactor relies
|
|
180
|
-
* on. Declared locally so `@icp-sdk/auth` stays an optional peer dependency.
|
|
181
|
-
*/
|
|
182
|
-
export interface AuthClientLike {
|
|
183
|
-
getIdentity(): Promise<Identity> | Identity
|
|
184
|
-
isAuthenticated(): Promise<boolean> | boolean
|
|
185
|
-
signIn(options?: AuthClientSignInOptions): Promise<Identity>
|
|
186
|
-
signOut(options?: { returnTo?: string }): Promise<void>
|
|
187
|
-
requestAttributes(params: {
|
|
188
|
-
keys: string[]
|
|
189
|
-
// `@icp-sdk/auth` v8 takes a thunk, so it can journal the value and replay
|
|
190
|
-
// the same bytes through a redirect flow.
|
|
191
|
-
nonce: () => Promise<Uint8Array>
|
|
192
|
-
}): Promise<SignedIdentityAttributes>
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export interface AuthState {
|
|
196
|
-
identity: Identity | null
|
|
197
|
-
isAuthenticating: boolean
|
|
198
|
-
isAuthenticated: boolean
|
|
199
|
-
error: Error | undefined
|
|
200
|
-
}
|
package/src/createActorHooks.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Actor Hooks Factory - Creates a full set of React hooks for a reactor instance.
|
|
3
|
-
*
|
|
4
|
-
* This is the primary entry point for using the library in React applications.
|
|
5
|
-
* It generates type-safe hooks for:
|
|
6
|
-
* - Queries (useActorQuery)
|
|
7
|
-
* - Suspense Queries (useActorSuspenseQuery)
|
|
8
|
-
* - Infinite Queries (useActorInfiniteQuery)
|
|
9
|
-
* - Suspense Infinite Queries (useActorSuspenseInfiniteQuery)
|
|
10
|
-
* - Mutations (useActorMutation)
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* const { useActorQuery, useActorMutation } = createActorHooks(reactor)
|
|
14
|
-
*
|
|
15
|
-
* // In component
|
|
16
|
-
* const { data } = useActorQuery({ functionName: 'get_user' })
|
|
17
|
-
* const { mutate } = useActorMutation({ functionName: 'update_user' })
|
|
18
|
-
*/
|
|
19
|
-
import {
|
|
20
|
-
Reactor,
|
|
21
|
-
DisplayReactor,
|
|
22
|
-
ReactorReturnErr,
|
|
23
|
-
ReactorReturnOk,
|
|
24
|
-
ReactorQueryData,
|
|
25
|
-
BaseActor,
|
|
26
|
-
FunctionName,
|
|
27
|
-
ReactorArgs,
|
|
28
|
-
TransformKey,
|
|
29
|
-
} from "@ic-reactor/core"
|
|
30
|
-
import {
|
|
31
|
-
UseQueryResult,
|
|
32
|
-
UseSuspenseQueryResult,
|
|
33
|
-
UseInfiniteQueryResult,
|
|
34
|
-
UseSuspenseInfiniteQueryResult,
|
|
35
|
-
UseMutationResult,
|
|
36
|
-
InfiniteData,
|
|
37
|
-
} from "@tanstack/react-query"
|
|
38
|
-
import { useActorQuery } from "./hooks/useActorQuery.js"
|
|
39
|
-
import { useActorSuspenseQuery } from "./hooks/useActorSuspenseQuery.js"
|
|
40
|
-
import { useActorInfiniteQuery } from "./hooks/useActorInfiniteQuery.js"
|
|
41
|
-
import { useActorSuspenseInfiniteQuery } from "./hooks/useActorSuspenseInfiniteQuery.js"
|
|
42
|
-
import { useActorMutation } from "./hooks/useActorMutation.js"
|
|
43
|
-
import {
|
|
44
|
-
useActorMethod,
|
|
45
|
-
UseActorMethodParameters,
|
|
46
|
-
} from "./hooks/useActorMethod.js"
|
|
47
|
-
import type { CallConfig } from "@icp-sdk/core/agent"
|
|
48
|
-
import { InfiniteQueryConfig } from "./createInfiniteQuery.js"
|
|
49
|
-
import { SuspenseInfiniteQueryConfig } from "./createSuspenseInfiniteQuery.js"
|
|
50
|
-
import { QueryConfig, SuspenseQueryConfig, MutationConfig } from "./types.js"
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The bound query hooks forward their config to `useActorQuery` and
|
|
54
|
-
* `useActorSuspenseQuery`, which take `callConfig`. `QueryConfig` is shared with
|
|
55
|
-
* `createQuery`, which does not use it, so it is added here and not there.
|
|
56
|
-
*/
|
|
57
|
-
type WithCallConfig<Config> = Config & {
|
|
58
|
-
/** Agent call configuration (canisterId override, effectiveCanisterId, etc.) */
|
|
59
|
-
callConfig?: CallConfig
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type ActorHooks<Service, Transform extends TransformKey> = {
|
|
63
|
-
useActorQuery: {
|
|
64
|
-
<Method extends FunctionName<Service>>(
|
|
65
|
-
config: WithCallConfig<
|
|
66
|
-
QueryConfig<
|
|
67
|
-
Service,
|
|
68
|
-
Method,
|
|
69
|
-
Transform,
|
|
70
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>
|
|
71
|
-
>
|
|
72
|
-
>
|
|
73
|
-
): UseQueryResult<
|
|
74
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
75
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
76
|
-
>
|
|
77
|
-
<Method extends FunctionName<Service>, TData>(
|
|
78
|
-
config: WithCallConfig<QueryConfig<Service, Method, Transform, TData>>
|
|
79
|
-
): UseQueryResult<TData, ReactorReturnErr<Service, Method, Transform>>
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
useActorSuspenseQuery: {
|
|
83
|
-
<Method extends FunctionName<Service>>(
|
|
84
|
-
config: WithCallConfig<
|
|
85
|
-
SuspenseQueryConfig<
|
|
86
|
-
Service,
|
|
87
|
-
Method,
|
|
88
|
-
Transform,
|
|
89
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>
|
|
90
|
-
>
|
|
91
|
-
>
|
|
92
|
-
): UseSuspenseQueryResult<
|
|
93
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
94
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
95
|
-
>
|
|
96
|
-
<Method extends FunctionName<Service>, TData>(
|
|
97
|
-
config: WithCallConfig<
|
|
98
|
-
SuspenseQueryConfig<Service, Method, Transform, TData>
|
|
99
|
-
>
|
|
100
|
-
): UseSuspenseQueryResult<
|
|
101
|
-
TData,
|
|
102
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
103
|
-
>
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// `Selected` is what `select` returns, so `select` can reshape the pages the
|
|
107
|
-
// way `createInfiniteQuery` allows. Without `select` it stays `InfiniteData`.
|
|
108
|
-
useActorInfiniteQuery: <
|
|
109
|
-
Method extends FunctionName<Service>,
|
|
110
|
-
TPageParam = unknown,
|
|
111
|
-
Selected = InfiniteData<
|
|
112
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
113
|
-
TPageParam
|
|
114
|
-
>,
|
|
115
|
-
>(
|
|
116
|
-
config: InfiniteQueryConfig<
|
|
117
|
-
Service,
|
|
118
|
-
Method,
|
|
119
|
-
Transform,
|
|
120
|
-
TPageParam,
|
|
121
|
-
Selected
|
|
122
|
-
>
|
|
123
|
-
) => UseInfiniteQueryResult<
|
|
124
|
-
Selected,
|
|
125
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
126
|
-
>
|
|
127
|
-
|
|
128
|
-
useActorSuspenseInfiniteQuery: <
|
|
129
|
-
Method extends FunctionName<Service>,
|
|
130
|
-
TPageParam = unknown,
|
|
131
|
-
Selected = InfiniteData<
|
|
132
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
133
|
-
TPageParam
|
|
134
|
-
>,
|
|
135
|
-
>(
|
|
136
|
-
config: SuspenseInfiniteQueryConfig<
|
|
137
|
-
Service,
|
|
138
|
-
Method,
|
|
139
|
-
Transform,
|
|
140
|
-
TPageParam,
|
|
141
|
-
Selected
|
|
142
|
-
>
|
|
143
|
-
) => UseSuspenseInfiniteQueryResult<
|
|
144
|
-
Selected,
|
|
145
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
146
|
-
>
|
|
147
|
-
|
|
148
|
-
useActorMutation: <
|
|
149
|
-
Method extends FunctionName<Service>,
|
|
150
|
-
TOnMutateResult = unknown,
|
|
151
|
-
>(
|
|
152
|
-
config: MutationConfig<Service, Method, Transform, TOnMutateResult>
|
|
153
|
-
) => UseMutationResult<
|
|
154
|
-
ReactorReturnOk<Service, Method, Transform>,
|
|
155
|
-
ReactorReturnErr<Service, Method, Transform>,
|
|
156
|
-
// Without this TVariables defaults to `unknown` and mutate/mutateAsync
|
|
157
|
-
// accept anything; the standalone hook and createMutation both pass it.
|
|
158
|
-
ReactorArgs<Service, Method, Transform>,
|
|
159
|
-
TOnMutateResult
|
|
160
|
-
>
|
|
161
|
-
|
|
162
|
-
useActorMethod: <Method extends FunctionName<Service>>(
|
|
163
|
-
config: Omit<
|
|
164
|
-
UseActorMethodParameters<Service, Method, Transform>,
|
|
165
|
-
"reactor"
|
|
166
|
-
>
|
|
167
|
-
) => ReturnType<typeof useActorMethod<Service, Method, Transform>>
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function createActorHooks<Service>(
|
|
171
|
-
reactor: DisplayReactor<Service>
|
|
172
|
-
): ActorHooks<Service, "display">
|
|
173
|
-
|
|
174
|
-
export function createActorHooks<
|
|
175
|
-
Service = BaseActor,
|
|
176
|
-
Transform extends TransformKey = "candid",
|
|
177
|
-
>(reactor: Reactor<Service, Transform>): ActorHooks<Service, Transform>
|
|
178
|
-
|
|
179
|
-
export function createActorHooks<Service, Transform extends TransformKey>(
|
|
180
|
-
reactor: Reactor<Service, Transform>
|
|
181
|
-
): ActorHooks<Service, Transform> {
|
|
182
|
-
return {
|
|
183
|
-
useActorQuery: ((config: any) =>
|
|
184
|
-
useActorQuery({ ...config, reactor })) as ActorHooks<
|
|
185
|
-
Service,
|
|
186
|
-
Transform
|
|
187
|
-
>["useActorQuery"],
|
|
188
|
-
|
|
189
|
-
useActorSuspenseQuery: ((config: any) =>
|
|
190
|
-
useActorSuspenseQuery({ ...config, reactor })) as ActorHooks<
|
|
191
|
-
Service,
|
|
192
|
-
Transform
|
|
193
|
-
>["useActorSuspenseQuery"],
|
|
194
|
-
|
|
195
|
-
useActorInfiniteQuery: ((config: any) =>
|
|
196
|
-
useActorInfiniteQuery({ ...config, reactor })) as ActorHooks<
|
|
197
|
-
Service,
|
|
198
|
-
Transform
|
|
199
|
-
>["useActorInfiniteQuery"],
|
|
200
|
-
|
|
201
|
-
useActorSuspenseInfiniteQuery: ((config: any) =>
|
|
202
|
-
useActorSuspenseInfiniteQuery({ ...config, reactor })) as ActorHooks<
|
|
203
|
-
Service,
|
|
204
|
-
Transform
|
|
205
|
-
>["useActorSuspenseInfiniteQuery"],
|
|
206
|
-
|
|
207
|
-
useActorMutation: ((config: any) =>
|
|
208
|
-
useActorMutation({ ...config, reactor })) as ActorHooks<
|
|
209
|
-
Service,
|
|
210
|
-
Transform
|
|
211
|
-
>["useActorMutation"],
|
|
212
|
-
|
|
213
|
-
useActorMethod: (config) =>
|
|
214
|
-
useActorMethod({ ...config, reactor } as UseActorMethodParameters<
|
|
215
|
-
Service,
|
|
216
|
-
any,
|
|
217
|
-
Transform
|
|
218
|
-
>),
|
|
219
|
-
}
|
|
220
|
-
}
|