@ic-reactor/react 3.13.0 → 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 +234 -787
- package/dist/index.d.ts +259 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +470 -23
- package/dist/index.js.map +1 -1
- package/llms.txt +80 -278
- package/package.json +11 -39
- package/src/index.tsx +611 -0
- package/dist/auth/auth-client-compat.d.ts +0 -122
- package/dist/auth/auth-client-compat.d.ts.map +0 -1
- package/dist/auth/auth-client-compat.js +0 -162
- package/dist/auth/auth-client-compat.js.map +0 -1
- package/dist/auth/authentication-manager.d.ts +0 -405
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -1537
- 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 -122
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -27
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -191
- 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 -227
- 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 -57
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -121
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -222
- 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 -41
- 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 -185
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -198
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -33
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -199
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -63
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -204
- package/dist/createQuery.js.map +0 -1
- package/dist/createReactorProvider.d.ts +0 -158
- package/dist/createReactorProvider.d.ts.map +0 -1
- package/dist/createReactorProvider.js +0 -256
- package/dist/createReactorProvider.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -209
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -46
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -158
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineDisplayReactor.d.ts +0 -43
- package/dist/defineDisplayReactor.d.ts.map +0 -1
- package/dist/defineDisplayReactor.js +0 -42
- package/dist/defineDisplayReactor.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -99
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -15
- package/dist/defineReactor.js.map +0 -1
- package/dist/defineReactorShared.d.ts +0 -84
- package/dist/defineReactorShared.d.ts.map +0 -1
- package/dist/defineReactorShared.js +0 -139
- package/dist/defineReactorShared.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -50
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -291
- 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 -67
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -89
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -148
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -394
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -51
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -70
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -45
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -67
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
- 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 -58
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/ownedAuthentication.d.ts +0 -52
- package/dist/ownedAuthentication.d.ts.map +0 -1
- package/dist/ownedAuthentication.js +0 -49
- package/dist/ownedAuthentication.js.map +0 -1
- package/dist/server.d.ts +0 -21
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -23
- package/dist/server.js.map +0 -1
- package/dist/testing.d.ts +0 -19
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -19
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -671
- 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 -207
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -405
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -136
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -144
- package/dist/validation.js.map +0 -1
- package/src/auth/auth-client-compat.ts +0 -273
- package/src/auth/authentication-manager.ts +0 -1682
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -169
- package/src/auth/identity-attributes-manager.ts +0 -226
- package/src/auth/identity-attributes.ts +0 -345
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -173
- package/src/auth/types.ts +0 -243
- package/src/createActorHooks.ts +0 -208
- package/src/createInfiniteQuery.ts +0 -670
- package/src/createMutation.ts +0 -324
- package/src/createQuery.ts +0 -369
- package/src/createReactorProvider.ts +0 -365
- package/src/createSuspenseInfiniteQuery.ts +0 -651
- package/src/createSuspenseQuery.ts +0 -304
- package/src/defineDisplayReactor.ts +0 -62
- package/src/defineReactor.ts +0 -142
- package/src/defineReactorShared.ts +0 -268
- package/src/hooks/createAuthHooks.ts +0 -371
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -278
- package/src/hooks/useActorMethod.ts +0 -710
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -157
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
- package/src/hooks/useActorSuspenseQuery.ts +0 -147
- package/src/index.ts +0 -31
- package/src/ownedAuthentication.ts +0 -81
- package/src/server.ts +0 -23
- package/src/testing.ts +0 -18
- package/src/types.ts +0 -948
- package/src/utils.ts +0 -505
- package/src/validation.ts +0 -226
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { DisplayReactor } from "@ic-reactor/core";
|
|
2
|
-
import { defineReactorWith } from "./defineReactorShared.js";
|
|
3
|
-
/**
|
|
4
|
-
* One-call bootstrap for a {@link DisplayReactor} and its React hooks: the
|
|
5
|
-
* display counterpart of `defineReactor`, taking the same options.
|
|
6
|
-
*
|
|
7
|
-
* A DisplayReactor takes and returns UI-friendly values — text for
|
|
8
|
-
* `Principal`, `nat`, `int` and 64-bit integers, hex for blobs — which suits
|
|
9
|
-
* forms and components. Its codecs are built on zod, so this adds zod to the
|
|
10
|
-
* bundle. `defineReactor`, which builds a plain `Reactor` with raw Candid
|
|
11
|
-
* values, does not need zod, but until its deprecated `display` flag is removed
|
|
12
|
-
* at the next major it bundles zod anyway; `createActorHooks(new Reactor(...))`
|
|
13
|
-
* is the setup without it.
|
|
14
|
-
*
|
|
15
|
-
* Replaces `defineReactor({ display: true })`, which is deprecated.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { defineDisplayReactor } from "@ic-reactor/react"
|
|
20
|
-
* import { idlFactory, type _SERVICE } from "./declarations/backend"
|
|
21
|
-
*
|
|
22
|
-
* export const { reactor, useActorQuery, useActorMutation, useAuth } =
|
|
23
|
-
* defineDisplayReactor<_SERVICE>({
|
|
24
|
-
* name: "backend",
|
|
25
|
-
* idlFactory,
|
|
26
|
-
* canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
27
|
-
* })
|
|
28
|
-
*
|
|
29
|
-
* function Balance() {
|
|
30
|
-
* // `nat` arrives as text, ready to render.
|
|
31
|
-
* const { data } = useActorQuery({ functionName: "get_balance" })
|
|
32
|
-
* return <span>{data}</span>
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export function defineDisplayReactor(params) {
|
|
37
|
-
return defineReactorWith("defineDisplayReactor", params, (config) => new DisplayReactor({
|
|
38
|
-
...config,
|
|
39
|
-
validators: params.validators,
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=defineDisplayReactor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineDisplayReactor.js","sourceRoot":"","sources":["../src/defineDisplayReactor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAc5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA4C;IAE5C,OAAO,iBAAiB,CACtB,sBAAsB,EACtB,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CACT,IAAI,cAAc,CAAU;QAC1B,GAAG,MAAM;QACT,UAAU,EAAE,MAAM,CAAC,UAAU;KAC9B,CAAC,CACL,CAAA;AACH,CAAC"}
|
package/dist/defineReactor.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { DisplayReactor, Reactor } from "@ic-reactor/core";
|
|
2
|
-
import type { BaseActor } from "@ic-reactor/core";
|
|
3
|
-
import type { DefineReactorSharedParameters, DefineReactorResult } from "./defineReactorShared.js";
|
|
4
|
-
import type { DefineDisplayReactorOptions } from "./defineDisplayReactor.js";
|
|
5
|
-
export type { DefineReactorSharedParameters, DefineReactorResult, } from "./defineReactorShared.js";
|
|
6
|
-
/** Parameters for a standard (raw Candid types) reactor. */
|
|
7
|
-
export interface DefineReactorParameters extends DefineReactorSharedParameters {
|
|
8
|
-
display?: false;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Parameters for `defineReactor({ display: true })`.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated Call `defineDisplayReactor` with the same options, without
|
|
14
|
-
* `display`: see {@link DefineDisplayReactorOptions}.
|
|
15
|
-
*/
|
|
16
|
-
export interface DefineDisplayReactorParameters<Service> extends DefineDisplayReactorOptions<Service> {
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated Use `defineDisplayReactor(...)` instead of
|
|
19
|
-
* `defineReactor({ display: true, ... })`. The flag keeps working until the
|
|
20
|
-
* next major, but it makes every bundle that calls `defineReactor` carry
|
|
21
|
-
* `DisplayReactor` and zod, even when it never sets the flag.
|
|
22
|
-
*/
|
|
23
|
-
display: true;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The `display: true` form: builds a DisplayReactor and its hooks.
|
|
27
|
-
*
|
|
28
|
-
* @deprecated `defineReactor({ display: true })` is deprecated: pass the same
|
|
29
|
-
* options, without `display`, to `defineDisplayReactor(...)`. Only this form
|
|
30
|
-
* is; `defineReactor` without `display` builds a plain `Reactor` and is not
|
|
31
|
-
* deprecated. The flag keeps working until the next major, but it makes every
|
|
32
|
-
* bundle that calls `defineReactor` carry `DisplayReactor` and zod, even when
|
|
33
|
-
* it never sets the flag.
|
|
34
|
-
*/
|
|
35
|
-
export declare function defineReactor<Service = BaseActor>(params: DefineDisplayReactorParameters<Service>): DefineReactorResult<Service, "display", DisplayReactor<Service>>;
|
|
36
|
-
/**
|
|
37
|
-
* One-call bootstrap for a canister reactor + its React hooks.
|
|
38
|
-
*
|
|
39
|
-
* Collapses the four manual steps (QueryClient → ClientManager → Reactor →
|
|
40
|
-
* createActorHooks) into a single call. It builds a `Reactor`, which takes and
|
|
41
|
-
* returns raw Candid values; `defineDisplayReactor` takes the same options and
|
|
42
|
-
* builds a `DisplayReactor` for UI-friendly ones.
|
|
43
|
-
* Use this when one-call bootstrap is enough. If you need reusable
|
|
44
|
-
* method-specific operations outside React, compose with query/mutation
|
|
45
|
-
* factories after setup.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { defineReactor } from "@ic-reactor/react"
|
|
50
|
-
* import { idlFactory, type _SERVICE } from "./declarations/backend"
|
|
51
|
-
*
|
|
52
|
-
* const { reactor, useActorQuery, useActorMutation } = defineReactor<_SERVICE>({
|
|
53
|
-
* name: "backend",
|
|
54
|
-
* idlFactory,
|
|
55
|
-
* canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
56
|
-
* })
|
|
57
|
-
*
|
|
58
|
-
* function Profile() {
|
|
59
|
-
* const { data } = useActorQuery({ functionName: "get_profile" })
|
|
60
|
-
* return <div>{data?.name}</div>
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
|
-
* @example Reuse an existing ClientManager (multiple canisters share one agent)
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const ledger = defineReactor<_LEDGER>({
|
|
67
|
-
* name: "ledger",
|
|
68
|
-
* idlFactory: ledgerIdl,
|
|
69
|
-
* canisterId: "ryjl3-tyaaa-aaaaa-aaaba-cai",
|
|
70
|
-
* })
|
|
71
|
-
* const index = defineReactor<_INDEX>({
|
|
72
|
-
* name: "index",
|
|
73
|
-
* idlFactory: indexIdl,
|
|
74
|
-
* canisterId: "qhbym-qaaaa-aaaaa-aaafq-cai",
|
|
75
|
-
* clientManager: ledger.clientManager,
|
|
76
|
-
* authentication: ledger.authentication, // one Internet Identity session
|
|
77
|
-
* })
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @example Internet Identity is wired up out of the box
|
|
81
|
-
* ```typescript
|
|
82
|
-
* const { useAuth, useIdentityAttributes } = defineReactor<_SERVICE>({
|
|
83
|
-
* name: "backend",
|
|
84
|
-
* idlFactory,
|
|
85
|
-
* canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
|
|
86
|
-
* // Needed when the app is served from more than one origin.
|
|
87
|
-
* auth: { derivationOrigin: "https://app.example.com" },
|
|
88
|
-
* })
|
|
89
|
-
*
|
|
90
|
-
* function LoginButton() {
|
|
91
|
-
* const { login, logout, isAuthenticated, principal } = useAuth()
|
|
92
|
-
* return isAuthenticated
|
|
93
|
-
* ? <button onClick={() => logout()}>{principal?.toText()}</button>
|
|
94
|
-
* : <button onClick={() => login()}>Sign in</button>
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export declare function defineReactor<Service = BaseActor>(params: DefineReactorParameters): DefineReactorResult<Service, "candid", Reactor<Service, "candid">>;
|
|
99
|
-
//# sourceMappingURL=defineReactor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineReactor.d.ts","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEjD,OAAO,KAAK,EACV,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAE5E,YAAY,EACV,6BAA6B,EAC7B,mBAAmB,GACpB,MAAM,0BAA0B,CAAA;AAEjC,4DAA4D;AAC5D,MAAM,WAAW,uBAAwB,SAAQ,6BAA6B;IAC5E,OAAO,CAAC,EAAE,KAAK,CAAA;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,8BAA8B,CAC7C,OAAO,CACP,SAAQ,2BAA2B,CAAC,OAAO,CAAC;IAC5C;;;;;OAKG;IACH,OAAO,EAAE,IAAI,CAAA;CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAG,SAAS,EAC/C,MAAM,EAAE,8BAA8B,CAAC,OAAO,CAAC,GAC9C,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAG,SAAS,EAC/C,MAAM,EAAE,uBAAuB,GAC9B,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA"}
|
package/dist/defineReactor.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// DisplayReactor is only for the deprecated `display: true` path. It is what
|
|
2
|
-
// puts DisplayReactor and zod in every bundle that uses defineReactor; drop it
|
|
3
|
-
// with that path.
|
|
4
|
-
import { DisplayReactor, Reactor } from "@ic-reactor/core";
|
|
5
|
-
import { defineReactorWith } from "./defineReactorShared.js";
|
|
6
|
-
export function defineReactor(params) {
|
|
7
|
-
if (params.display) {
|
|
8
|
-
// What defineDisplayReactor builds, but under this function's name, so an
|
|
9
|
-
// error names the call the app actually made.
|
|
10
|
-
const { validators } = params;
|
|
11
|
-
return defineReactorWith("defineReactor", params, (config) => new DisplayReactor({ ...config, validators }));
|
|
12
|
-
}
|
|
13
|
-
return defineReactorWith("defineReactor", params, (config) => new Reactor(config));
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=defineReactor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineReactor.js","sourceRoot":"","sources":["../src/defineReactor.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,+EAA+E;AAC/E,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAmH5D,MAAM,UAAU,aAAa,CAC3B,MAAyE;IAIzE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,0EAA0E;QAC1E,8CAA8C;QAC9C,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;QAC7B,OAAO,iBAAiB,CACtB,eAAe,EACf,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,cAAc,CAAU,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC,CACnE,CAAA;IACH,CAAC;IAED,OAAO,iBAAiB,CACtB,eAAe,EACf,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,OAAO,CAAU,MAAM,CAAC,CACzC,CAAA;AACH,CAAC"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The body `defineReactor` and `defineDisplayReactor` share.
|
|
3
|
-
*
|
|
4
|
-
* It takes the reactor's construction as a callback, so this module imports
|
|
5
|
-
* neither reactor class. That matters for bundle size: `DisplayReactor` builds
|
|
6
|
-
* its codecs on zod, and a module that imported it here would put zod in every
|
|
7
|
-
* app that calls `defineReactor`, whether or not it ever builds a
|
|
8
|
-
* DisplayReactor. Keep it that way — no `DisplayReactor` import in this file.
|
|
9
|
-
*/
|
|
10
|
-
import { ClientManager } from "@ic-reactor/core";
|
|
11
|
-
import type { Reactor, TransformKey, ReactorParameters, ClientManagerParameters } from "@ic-reactor/core";
|
|
12
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
13
|
-
import { ActorHooks } from "./createActorHooks.js";
|
|
14
|
-
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
15
|
-
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
16
|
-
import type { UseIdentityAttributesReturn } from "./auth/createIdentityAttributeHooks.js";
|
|
17
|
-
import type { CreateAuthHooksReturn } from "./hooks/createAuthHooks.js";
|
|
18
|
-
import type { AuthenticationManagerParameters } from "./auth/authentication-manager.js";
|
|
19
|
-
/** Options shared by both the standard and display variants of defineReactor. */
|
|
20
|
-
export interface DefineReactorSharedParameters extends Omit<ReactorParameters, "clientManager">, Omit<ClientManagerParameters, "queryClient"> {
|
|
21
|
-
/**
|
|
22
|
-
* Reuse an existing ClientManager (e.g. to share one agent across canisters).
|
|
23
|
-
* When omitted, a ClientManager is created from the agent options below.
|
|
24
|
-
*
|
|
25
|
-
* A supplied or adopted manager brings its own agent and QueryClient, so
|
|
26
|
-
* `agentOptions`, `queryClient` and `allowEnvConfig` apply only when this
|
|
27
|
-
* call creates one.
|
|
28
|
-
*/
|
|
29
|
-
clientManager?: ClientManager;
|
|
30
|
-
/**
|
|
31
|
-
* QueryClient for a ClientManager created by this call.
|
|
32
|
-
*
|
|
33
|
-
* Ignored when `clientManager` or `authentication` is supplied — queries run
|
|
34
|
-
* against that manager's own QueryClient, which is what is returned.
|
|
35
|
-
*/
|
|
36
|
-
queryClient?: QueryClient;
|
|
37
|
-
/**
|
|
38
|
-
* Reuse an existing AuthenticationManager, so several reactors share one
|
|
39
|
-
* Internet Identity session. When omitted, one is created for this reactor.
|
|
40
|
-
*
|
|
41
|
-
* Its `clientManager` is adopted for this reactor, so sign-in updates the
|
|
42
|
-
* same agent the reactor calls through. Supplying a different `clientManager`
|
|
43
|
-
* alongside it is rejected.
|
|
44
|
-
*/
|
|
45
|
-
authentication?: AuthenticationManager;
|
|
46
|
-
/**
|
|
47
|
-
* Internet Identity options forwarded to the AuthenticationManager
|
|
48
|
-
* (`identityProvider`, `derivationOrigin`, `idleOptions`, `storage`, …).
|
|
49
|
-
*
|
|
50
|
-
* Not every option reaches both `@icp-sdk/auth` majors. `idleOptions`,
|
|
51
|
-
* `storage`, `keyType` and `identity` are honoured only by v8: v10 has no
|
|
52
|
-
* equivalent, so IC Reactor drops each with a one-time warning. For idle
|
|
53
|
-
* handling on v10, pass `maxTimeToIdle` to `login()` and set
|
|
54
|
-
* `disableBrowserActivity` here. `disableBrowserActivity` is v10-only.
|
|
55
|
-
*
|
|
56
|
-
* Mutually exclusive with `authentication`: a manager built elsewhere is
|
|
57
|
-
* already configured, so these could not be applied to it.
|
|
58
|
-
*/
|
|
59
|
-
auth?: Omit<AuthenticationManagerParameters, "clientManager">;
|
|
60
|
-
}
|
|
61
|
-
/** The reactor instance plus its bound hooks and shared infrastructure. */
|
|
62
|
-
export type DefineReactorResult<Service, Transform extends TransformKey, R extends Reactor<Service, Transform>> = ActorHooks<Service, Transform> & CreateAuthHooksReturn & {
|
|
63
|
-
reactor: R;
|
|
64
|
-
clientManager: ClientManager;
|
|
65
|
-
queryClient: QueryClient;
|
|
66
|
-
/** Internet Identity session manager backing `useAuth`. */
|
|
67
|
-
authentication: AuthenticationManager;
|
|
68
|
-
/** Signed identity attribute requests backing `useIdentityAttributes`. */
|
|
69
|
-
identityAttributes: IdentityAttributesManager;
|
|
70
|
-
useIdentityAttributes: () => UseIdentityAttributesReturn;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Builds the ClientManager, the reactor `createReactor` returns, its hooks and
|
|
74
|
-
* the lazily created auth managers, for `defineReactor` and
|
|
75
|
-
* `defineDisplayReactor`. Not part of the public API.
|
|
76
|
-
*
|
|
77
|
-
* `caller` is the function the app called; the errors below name it, so an
|
|
78
|
-
* app that called `defineDisplayReactor` is not sent looking for a
|
|
79
|
-
* `defineReactor` call it never made.
|
|
80
|
-
*
|
|
81
|
-
* @internal
|
|
82
|
-
*/
|
|
83
|
-
export declare function defineReactorWith<Service, Transform extends TransformKey, R extends Reactor<Service, Transform>>(caller: "defineReactor" | "defineDisplayReactor", params: DefineReactorSharedParameters, createReactor: (config: ReactorParameters) => R): DefineReactorResult<Service, Transform, R>;
|
|
84
|
-
//# sourceMappingURL=defineReactorShared.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineReactorShared.d.ts","sourceRoot":"","sources":["../src/defineReactorShared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAgB,MAAM,kBAAkB,CAAA;AAC9D,OAAO,KAAK,EACV,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO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YAAY,EAC9B,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,EAErC,MAAM,EAAE,eAAe,GAAG,sBAAsB,EAChD,MAAM,EAAE,6BAA6B,EACrC,aAAa,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,CAAC,GAC9C,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CA6I5C"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The body `defineReactor` and `defineDisplayReactor` share.
|
|
3
|
-
*
|
|
4
|
-
* It takes the reactor's construction as a callback, so this module imports
|
|
5
|
-
* neither reactor class. That matters for bundle size: `DisplayReactor` builds
|
|
6
|
-
* its codecs on zod, and a module that imported it here would put zod in every
|
|
7
|
-
* app that calls `defineReactor`, whether or not it ever builds a
|
|
8
|
-
* DisplayReactor. Keep it that way — no `DisplayReactor` import in this file.
|
|
9
|
-
*/
|
|
10
|
-
import { ClientManager, reactorRetry } from "@ic-reactor/core";
|
|
11
|
-
import { QueryClient } from "@tanstack/react-query";
|
|
12
|
-
import { createActorHooks } from "./createActorHooks.js";
|
|
13
|
-
import { AuthenticationManager } from "./auth/authentication-manager.js";
|
|
14
|
-
import { IdentityAttributesManager } from "./auth/identity-attributes-manager.js";
|
|
15
|
-
import { createIdentityAttributeHooks } from "./auth/createIdentityAttributeHooks.js";
|
|
16
|
-
import { createAuthHooks } from "./hooks/createAuthHooks.js";
|
|
17
|
-
import { registerAuthentication } from "./ownedAuthentication.js";
|
|
18
|
-
/**
|
|
19
|
-
* The QueryClient this module creates when the caller does not supply one.
|
|
20
|
-
*
|
|
21
|
-
* React Query retries every failure three times by default, which for canister
|
|
22
|
-
* calls means four attempts and several seconds of backoff on outcomes that
|
|
23
|
-
* cannot change — a canister `Err`, a validation failure, a Candid encode
|
|
24
|
-
* error that never reached the network. `reactorRetry` keeps the same three
|
|
25
|
-
* attempts for transport failures and stops immediately on the rest.
|
|
26
|
-
*
|
|
27
|
-
* A caller-supplied `queryClient` is left exactly as given; opt in there with
|
|
28
|
-
* `defaultOptions: { queries: { retry: reactorRetry } }`.
|
|
29
|
-
*/
|
|
30
|
-
const createDefaultQueryClient = () => new QueryClient({
|
|
31
|
-
defaultOptions: { queries: { retry: reactorRetry } },
|
|
32
|
-
});
|
|
33
|
-
/**
|
|
34
|
-
* Builds the ClientManager, the reactor `createReactor` returns, its hooks and
|
|
35
|
-
* the lazily created auth managers, for `defineReactor` and
|
|
36
|
-
* `defineDisplayReactor`. Not part of the public API.
|
|
37
|
-
*
|
|
38
|
-
* `caller` is the function the app called; the errors below name it, so an
|
|
39
|
-
* app that called `defineDisplayReactor` is not sent looking for a
|
|
40
|
-
* `defineReactor` call it never made.
|
|
41
|
-
*
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
export function defineReactorWith(caller, params, createReactor) {
|
|
45
|
-
const { clientManager: providedClientManager, queryClient: providedQueryClient, authentication: providedAuthentication, auth, agentOptions, allowEnvConfig, allowEnvRootKey, name, idlFactory, canisterId, pollingOptions, } = params;
|
|
46
|
-
// A shared AuthenticationManager updates the identity on its own
|
|
47
|
-
// ClientManager. Giving this reactor a different one would leave its calls
|
|
48
|
-
// anonymous after sign-in, so adopt the manager's rather than building a new
|
|
49
|
-
// one, and refuse an explicit mismatch instead of splitting them silently.
|
|
50
|
-
if (providedClientManager &&
|
|
51
|
-
providedAuthentication &&
|
|
52
|
-
providedAuthentication.clientManager !== providedClientManager) {
|
|
53
|
-
throw new Error(`[ic-reactor] ${caller}("${name}") received an \`authentication\` manager bound to a different \`clientManager\`. ` +
|
|
54
|
-
`Sign-in would update the authentication manager's agent while this reactor calls through another one, ` +
|
|
55
|
-
`leaving its calls anonymous. Pass \`clientManager: authentication.clientManager\`, or omit \`clientManager\` to adopt it.`);
|
|
56
|
-
}
|
|
57
|
-
// `auth` configures a manager this call would build; an existing one is
|
|
58
|
-
// already constructed, so these options could only be dropped on the floor.
|
|
59
|
-
if (providedAuthentication && auth) {
|
|
60
|
-
throw new Error(`[ic-reactor] ${caller}("${name}") received both \`authentication\` and \`auth\`. ` +
|
|
61
|
-
`The supplied manager is already configured, so \`auth\` (${Object.keys(auth).join(", ")}) would be ignored. ` +
|
|
62
|
-
`Pass those options where that AuthenticationManager is created, or drop \`authentication\` to build one here.`);
|
|
63
|
-
}
|
|
64
|
-
// Same reasoning as `auth`, and it matters more here: an ignored
|
|
65
|
-
// `allowEnvConfig: false` reads as "I locked the cookie out" while the
|
|
66
|
-
// supplied manager carries whatever decision it was built with.
|
|
67
|
-
if ((providedClientManager || providedAuthentication) &&
|
|
68
|
-
(allowEnvConfig !== undefined || allowEnvRootKey !== undefined)) {
|
|
69
|
-
const passed = [
|
|
70
|
-
allowEnvConfig !== undefined && "allowEnvConfig",
|
|
71
|
-
allowEnvRootKey !== undefined && "allowEnvRootKey",
|
|
72
|
-
]
|
|
73
|
-
.filter(Boolean)
|
|
74
|
-
.join(", ");
|
|
75
|
-
throw new Error(`[ic-reactor] ${caller}("${name}") received both a ClientManager and \`${passed}\`. ` +
|
|
76
|
-
`That option is resolved when a ClientManager is constructed, so the supplied one already carries its own ` +
|
|
77
|
-
`decision and this would be ignored — silently changing nothing about whether the ic_env cookie is trusted. ` +
|
|
78
|
-
`Pass it where that ClientManager is created, or drop \`clientManager\` to build one here.`);
|
|
79
|
-
}
|
|
80
|
-
const clientManager = providedClientManager ??
|
|
81
|
-
providedAuthentication?.clientManager ??
|
|
82
|
-
new ClientManager({
|
|
83
|
-
queryClient: providedQueryClient ?? createDefaultQueryClient(),
|
|
84
|
-
agentOptions,
|
|
85
|
-
// Forwarded, not dropped: the type has always accepted these (it extends
|
|
86
|
-
// ClientManagerParameters) while the call ignored them, so the one
|
|
87
|
-
// documented setup path silently discarded the ic_env opt-in it advertised.
|
|
88
|
-
allowEnvConfig,
|
|
89
|
-
allowEnvRootKey,
|
|
90
|
-
});
|
|
91
|
-
// Always report the QueryClient actually in use: when a ClientManager is
|
|
92
|
-
// supplied or adopted, its own QueryClient is the one queries run against.
|
|
93
|
-
const queryClient = clientManager.queryClient;
|
|
94
|
-
const reactor = createReactor({
|
|
95
|
-
clientManager,
|
|
96
|
-
name,
|
|
97
|
-
idlFactory,
|
|
98
|
-
canisterId,
|
|
99
|
-
pollingOptions,
|
|
100
|
-
});
|
|
101
|
-
const hooks = createActorHooks(reactor);
|
|
102
|
-
// Auth is built on first use. `AuthenticationManager` dynamically imports the
|
|
103
|
-
// optional `@icp-sdk/auth` peer as soon as it is constructed, and reactors
|
|
104
|
-
// that never touch authentication should not pay for that.
|
|
105
|
-
let authenticationInstance;
|
|
106
|
-
const getAuthentication = () => (authenticationInstance ?? (authenticationInstance = providedAuthentication ??
|
|
107
|
-
new AuthenticationManager({ ...auth, clientManager })));
|
|
108
|
-
let identityAttributesInstance;
|
|
109
|
-
const getIdentityAttributes = () => (identityAttributesInstance ?? (identityAttributesInstance = new IdentityAttributesManager(getAuthentication())));
|
|
110
|
-
let authHooks;
|
|
111
|
-
const getAuthHooks = () => (authHooks ?? (authHooks = createAuthHooks(getAuthentication())));
|
|
112
|
-
let attributeHooks;
|
|
113
|
-
const getAttributeHooks = () => (attributeHooks ?? (attributeHooks = createIdentityAttributeHooks(getIdentityAttributes())));
|
|
114
|
-
const result = {
|
|
115
|
-
...hooks,
|
|
116
|
-
reactor,
|
|
117
|
-
clientManager,
|
|
118
|
-
queryClient,
|
|
119
|
-
// Stable wrappers: the hook call order inside them never changes, so the
|
|
120
|
-
// rules of hooks still hold.
|
|
121
|
-
useAuth: () => getAuthHooks().useAuth(),
|
|
122
|
-
useAgentState: () => getAuthHooks().useAgentState(),
|
|
123
|
-
useUserPrincipal: () => getAuthHooks().useUserPrincipal(),
|
|
124
|
-
useIdentityAttributes: () => getAttributeHooks().useIdentityAttributes(),
|
|
125
|
-
get authentication() {
|
|
126
|
-
return getAuthentication();
|
|
127
|
-
},
|
|
128
|
-
get identityAttributes() {
|
|
129
|
-
return getIdentityAttributes();
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
// For `createReactorProvider`, which disposes the manager this result
|
|
133
|
-
// builds when its tree unmounts. It reads the manager without the getter
|
|
134
|
-
// above, so a tree that never touched authentication does not build one
|
|
135
|
-
// just to release it. A supplied manager is not this result's to release.
|
|
136
|
-
registerAuthentication(result, () => providedAuthentication ? undefined : authenticationInstance);
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
//# sourceMappingURL=defineReactorShared.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineReactorShared.js","sourceRoot":"","sources":["../src/defineReactorShared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAO9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAc,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAA;AAErF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAiEjE;;;;;;;;;;;GAWG;AACH,MAAM,wBAAwB,GAAG,GAAG,EAAE,CACpC,IAAI,WAAW,CAAC;IACd,cAAc,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE;CACrD,CAAC,CAAA;AAEJ;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAK/B,MAAgD,EAChD,MAAqC,EACrC,aAA+C;IAE/C,MAAM,EACJ,aAAa,EAAE,qBAAqB,EACpC,WAAW,EAAE,mBAAmB,EAChC,cAAc,EAAE,sBAAsB,EACtC,IAAI,EACJ,Y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E,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,aAAa,EAAE;QACnD,gBAAgB,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,gBAAgB,EAAE;QACzD,qBAAqB,EAAE,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,qBAAqB,EAAE;QACxE,IAAI,cAAc;YAChB,OAAO,iBAAiB,EAAE,CAAA;QAC5B,CAAC;QACD,IAAI,kBAAkB;YACpB,OAAO,qBAAqB,EAAE,CAAA;QAChC,CAAC;KACF,CAAA;IAED,sEAAsE;IACtE,yEAAyE;IACzE,wEAAwE;IACxE,0EAA0E;IAC1E,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,CAClC,sBAAsB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAC5D,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { AuthenticationManager } from "../auth/authentication-manager.js";
|
|
2
|
-
import type { AuthenticationSignInOptions } from "../auth/types.js";
|
|
3
|
-
import type { AgentState } from "@ic-reactor/core";
|
|
4
|
-
import type { Principal } from "@icp-sdk/core/principal";
|
|
5
|
-
import type { Identity } from "@icp-sdk/core/agent";
|
|
6
|
-
export interface UseAuthReturn {
|
|
7
|
-
authenticate: () => Promise<Identity | undefined>;
|
|
8
|
-
login: (options?: AuthenticationSignInOptions) => Promise<void>;
|
|
9
|
-
logout: (options?: {
|
|
10
|
-
returnTo?: string;
|
|
11
|
-
}) => Promise<void>;
|
|
12
|
-
isAuthenticated: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* `true` while a sign-in or sign-out is in progress, and until the session
|
|
15
|
-
* restore the first `useAuth()` starts has settled: on the first render, in
|
|
16
|
-
* a server render and while the stored session is read. A restore that fails
|
|
17
|
-
* settles it too. Show a loading state while it is `true` rather than
|
|
18
|
-
* treating `isAuthenticated: false` as signed out.
|
|
19
|
-
*/
|
|
20
|
-
isAuthenticating: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* The signed-in user's principal, or `null` while signed out. A signed-out
|
|
23
|
-
* session still holds an anonymous `identity`, and its principal is not
|
|
24
|
-
* returned here.
|
|
25
|
-
*/
|
|
26
|
-
principal: Principal | null;
|
|
27
|
-
identity: Identity | null;
|
|
28
|
-
error: Error | undefined;
|
|
29
|
-
}
|
|
30
|
-
export interface CreateAuthHooksReturn {
|
|
31
|
-
useAgentState: () => AgentState;
|
|
32
|
-
useUserPrincipal: () => Principal | null;
|
|
33
|
-
useAuth: () => UseAuthReturn;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Create authentication hooks for managing user sessions with Internet Identity.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* const { useAuth, useUserPrincipal, useAgentState } = createAuthHooks(authentication)
|
|
40
|
-
*
|
|
41
|
-
* function App() {
|
|
42
|
-
* const { login, logout, principal, isAuthenticated } = useAuth()
|
|
43
|
-
*
|
|
44
|
-
* return isAuthenticated
|
|
45
|
-
* ? <button onClick={() => logout()}>Logout {principal?.toText()}</button>
|
|
46
|
-
* : <button onClick={() => login()}>Login with II</button>
|
|
47
|
-
* }
|
|
48
|
-
*/
|
|
49
|
-
export declare const createAuthHooks: (authentication: AuthenticationManager) => CreateAuthHooksReturn;
|
|
50
|
-
//# sourceMappingURL=createAuthHooks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAuthHooks.d.ts","sourceRoot":"","sources":["../../src/hooks/createAuthHooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,KAAK,EAAa,2BAA2B,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAA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