@calimero-network/mero-react 11.0.4 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/index.cjs +101 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -11
- package/dist/index.d.ts +22 -11
- package/dist/index.js +102 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @calimero-network/mero-react
|
|
2
2
|
|
|
3
|
-
React bindings for **Calimero 1.0**, on the mero-js
|
|
3
|
+
React bindings for **Calimero 1.0**, on the mero-js client (`CalimeroClient`) and its generated method groups (`client.apps`, `client.orgs`, `client.auth`, ...).
|
|
4
4
|
|
|
5
5
|
A 1.0 node runs in an attested TDX cluster. The client verifies the node's attestation, seals every request to the node's attested key, and signs people in with **passkeys**. mero-react puts one client in context and builds the hooks on top of it:
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ A 1.0 node runs in an attested TDX cluster. The client verifies the node's attes
|
|
|
20
20
|
pnpm add @calimero-network/mero-react
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
`@calimero-network/mero-js` (^
|
|
23
|
+
`@calimero-network/mero-js` (^29.17) comes with it, and every mero-js export is re-exported, so apps need only this import. React 18 or 19 is a peer dependency.
|
|
24
24
|
|
|
25
25
|
## Quick start
|
|
26
26
|
|
|
@@ -180,9 +180,9 @@ How `useSubscription` behaves:
|
|
|
180
180
|
| `useTeam(org, team)` | `useGroupInfo` |
|
|
181
181
|
| `useCreateTeam().create({ orgId, name, join?, parent? })` | `useCreateGroupInNamespace` |
|
|
182
182
|
| `useUpdateTeam().update(org, team, { name?, join?, parent?, metadata? })` | `useSetGroupMetadata`, `useReparentGroup`, `useSetSubgroupVisibility` |
|
|
183
|
-
| `useDeleteTeam()`, `useSetTeamMember()`, `useRemoveTeamMember()` | `useDeleteGroup`, `useAddGroupMembers`, `useRemoveGroupMembers`. Setting and removing a team member ask for the passkey. |
|
|
183
|
+
| `useDeleteTeam()`, `useSetTeamMember()`, `useRemoveTeamMember()` | `useDeleteGroup`, `useAddGroupMembers`, `useRemoveGroupMembers`. Setting and removing a team member ask for the passkey; deleting a team asks for it when the team (or one below it) holds apps. |
|
|
184
184
|
|
|
185
|
-
**Passkey step-ups.** Since mero-js 28 the node approves membership changes, capabilities, invites, passkeys and API keys with the caller's passkey: it answers `412 CONFIRM_REQUIRED` and the
|
|
185
|
+
**Passkey step-ups.** Since mero-js 28 the node approves membership changes, capabilities, invites, passkeys and API keys (creating and revoking) with the caller's passkey: it answers `412 CONFIRM_REQUIRED` and the hook answers that with the provider's `passkey` (`browserPasskey()` by default, through mero-js `passkeyConfirm`), so the person sees a passkey prompt. A dismissed prompt fails the action with `failure.kind = 'cancelled'`.
|
|
186
186
|
|
|
187
187
|
### Invites
|
|
188
188
|
|
|
@@ -290,7 +290,7 @@ core 1.0 is a different node, and mero-js 28 is a different client, so 11.0 is a
|
|
|
290
290
|
- Keep `servedByNode`. Pass `appId` if the app works on one instance.
|
|
291
291
|
2. **Client.**
|
|
292
292
|
- `useMero().mero` (a `MeroJs` or relay client) is now `useMero().client` (a `CalimeroClient`).
|
|
293
|
-
- `mero.rpc.execute({ contextId, method, argsJson, executorPublicKey })` is now `client.call(
|
|
293
|
+
- `mero.rpc.execute({ contextId, method, argsJson, executorPublicKey })` is now `client.apps.call({ app, method, args })`, or `client.apps.view({ app, method, args })` for reads (or `useApp(appId).call` / `.view`).
|
|
294
294
|
3. **Vocabulary.**
|
|
295
295
|
- context is now app instance (`appId`);
|
|
296
296
|
- namespace is now organization;
|
|
@@ -326,7 +326,7 @@ core 1.0 is a different node, and mero-js 28 is a different client, so 11.0 is a
|
|
|
326
326
|
| `useRedeemInvitation`, `useJoinNamespace`, `useJoinGroup`, `useJoinContext` | `useRedeemInvite` |
|
|
327
327
|
| `useInviteRedemption`, `useJoinInvitation` | `useInviteRedemption` (no relay or sync step) |
|
|
328
328
|
| `useUpgradeGroup`, `useInstallFromRegistry` | `useUpgradeApp`, or `useConsent` + `upgradeConsent` from an app frontend |
|
|
329
|
-
| `useGroupUpgradeStatus`, `useRetryGroupUpgrade` | mero-js `client.
|
|
329
|
+
| `useGroupUpgradeStatus`, `useRetryGroupUpgrade` | mero-js `client.orgs.upgradeStatus({ org, run })` / `client.orgs.upgradeRetry({ org, run }, { confirm })` (org upgrade runs) |
|
|
330
330
|
| `useUploadBlob`, `useBlobInfo`, `useBlobUrl` | Same names, now per app (`{ appId }`) |
|
|
331
331
|
| `useEphemeral(contextId, opts)` | `useEphemeral(appId, opts)`: peers keyed by account |
|
|
332
332
|
| `useNodeIdentity` | `useAccount` |
|
package/dist/index.cjs
CHANGED
|
@@ -541,6 +541,9 @@ var NoAppError = class extends Error {
|
|
|
541
541
|
this.name = "NoAppError";
|
|
542
542
|
}
|
|
543
543
|
};
|
|
544
|
+
function confirmWith(passkey) {
|
|
545
|
+
return { confirm: meroJs.passkeyConfirm(passkey) };
|
|
546
|
+
}
|
|
544
547
|
function toError(error) {
|
|
545
548
|
return error instanceof Error ? error : new Error(String(error));
|
|
546
549
|
}
|
|
@@ -641,12 +644,21 @@ function useClientAction(options) {
|
|
|
641
644
|
);
|
|
642
645
|
return { withClient, loading: action.loading, error: action.error, failure: action.failure };
|
|
643
646
|
}
|
|
647
|
+
function viewOf(client, app, method, args, options) {
|
|
648
|
+
return client.apps.view({
|
|
649
|
+
app,
|
|
650
|
+
method,
|
|
651
|
+
args,
|
|
652
|
+
consistency: options.stale ? "stale" : void 0,
|
|
653
|
+
minIndex: options.minIndex
|
|
654
|
+
});
|
|
655
|
+
}
|
|
644
656
|
function useApp(appId) {
|
|
645
657
|
const { client: anyClient, passkey } = useMero();
|
|
646
658
|
const client = useSignedInClient();
|
|
647
659
|
const id = useAppId(appId);
|
|
648
660
|
const info = useResource(
|
|
649
|
-
client && id ? () => client.
|
|
661
|
+
client && id ? () => client.apps.get({ app: id }) : null,
|
|
650
662
|
null,
|
|
651
663
|
[client, id]
|
|
652
664
|
);
|
|
@@ -654,7 +666,10 @@ function useApp(appId) {
|
|
|
654
666
|
(method, args = {}, options = {}) => {
|
|
655
667
|
if (!anyClient) return Promise.reject(new NotConnectedError("connected"));
|
|
656
668
|
if (!id) return Promise.reject(new NoAppError());
|
|
657
|
-
return
|
|
669
|
+
return anyClient.apps.call(
|
|
670
|
+
{ app: id, method, args, idempotencyKey: options.idempotencyKey },
|
|
671
|
+
options.confirm ? confirmWith(passkey) : void 0
|
|
672
|
+
);
|
|
658
673
|
},
|
|
659
674
|
[anyClient, id, passkey]
|
|
660
675
|
);
|
|
@@ -662,7 +677,7 @@ function useApp(appId) {
|
|
|
662
677
|
(method, args = {}, options = {}) => {
|
|
663
678
|
if (!anyClient) return Promise.reject(new NotConnectedError("connected"));
|
|
664
679
|
if (!id) return Promise.reject(new NoAppError());
|
|
665
|
-
return anyClient
|
|
680
|
+
return viewOf(anyClient, id, method, args, options);
|
|
666
681
|
},
|
|
667
682
|
[anyClient, id]
|
|
668
683
|
);
|
|
@@ -690,7 +705,7 @@ function useView(method, args = {}, options = {}) {
|
|
|
690
705
|
const argsKey = JSON.stringify(args ?? {});
|
|
691
706
|
const { stale, minIndex, enabled = true } = options;
|
|
692
707
|
const resource = useResource(
|
|
693
|
-
client && id && enabled ? () => client
|
|
708
|
+
client && id && enabled ? () => viewOf(client, id, method, JSON.parse(argsKey), { stale, minIndex }) : null,
|
|
694
709
|
null,
|
|
695
710
|
[client, id, method, argsKey, stale, minIndex, enabled]
|
|
696
711
|
);
|
|
@@ -703,7 +718,11 @@ function useView(method, args = {}, options = {}) {
|
|
|
703
718
|
function useAppAbi(appId) {
|
|
704
719
|
const client = useSignedInClient();
|
|
705
720
|
const id = useAppId(appId);
|
|
706
|
-
return useResource(
|
|
721
|
+
return useResource(
|
|
722
|
+
client && id ? () => client.apps.abi({ app: id }) : null,
|
|
723
|
+
null,
|
|
724
|
+
[client, id]
|
|
725
|
+
);
|
|
707
726
|
}
|
|
708
727
|
var LIVE = Number.MAX_SAFE_INTEGER;
|
|
709
728
|
function position(id) {
|
|
@@ -803,16 +822,27 @@ function useSubscription(appIds, callback, options = {}) {
|
|
|
803
822
|
function useApps(filter = {}) {
|
|
804
823
|
const client = useSignedInClient();
|
|
805
824
|
const { package: pkg, bundle } = filter;
|
|
806
|
-
return useResource(
|
|
825
|
+
return useResource(
|
|
826
|
+
client ? async () => (await client.apps.list({ package: pkg || void 0, bundle: bundle || void 0 })).apps : null,
|
|
827
|
+
[],
|
|
828
|
+
[client, pkg, bundle]
|
|
829
|
+
);
|
|
807
830
|
}
|
|
808
831
|
function useCreateApp(options) {
|
|
809
832
|
const client = useSignedInClient();
|
|
810
833
|
const action = useAsyncAction(options);
|
|
811
834
|
const create = react.useCallback(
|
|
812
|
-
(input) => action.run(() => {
|
|
835
|
+
(input) => action.run(async () => {
|
|
813
836
|
if (!client) throw new NotConnectedError();
|
|
814
837
|
const { name, bundle, ...rest } = input;
|
|
815
|
-
|
|
838
|
+
const target = typeof bundle === "string" ? { bundle } : bundle;
|
|
839
|
+
const { appId } = await client.apps.create({
|
|
840
|
+
name,
|
|
841
|
+
...target,
|
|
842
|
+
...rest,
|
|
843
|
+
access: rest.access
|
|
844
|
+
});
|
|
845
|
+
return appId;
|
|
816
846
|
}),
|
|
817
847
|
[client, action.run]
|
|
818
848
|
);
|
|
@@ -824,7 +854,7 @@ function useDeleteApp(options) {
|
|
|
824
854
|
const remove = react.useCallback(
|
|
825
855
|
(appId) => action.run(async () => {
|
|
826
856
|
if (!client) throw new NotConnectedError();
|
|
827
|
-
await client.
|
|
857
|
+
await client.apps.delete({ app: appId });
|
|
828
858
|
return true;
|
|
829
859
|
}),
|
|
830
860
|
[client, action.run]
|
|
@@ -837,7 +867,7 @@ function useSetAppMetadata(options) {
|
|
|
837
867
|
const setMetadata = react.useCallback(
|
|
838
868
|
(appId, metadata) => action.run(async () => {
|
|
839
869
|
if (!client) throw new NotConnectedError();
|
|
840
|
-
await client.
|
|
870
|
+
await client.apps.metadata({ app: appId, metadata });
|
|
841
871
|
return true;
|
|
842
872
|
}),
|
|
843
873
|
[client, action.run]
|
|
@@ -850,10 +880,10 @@ function useUpgradeApp(appId, options) {
|
|
|
850
880
|
const id = useAppId(appId);
|
|
851
881
|
const action = useAsyncAction(options);
|
|
852
882
|
const upgrade = react.useCallback(
|
|
853
|
-
(target) => action.run(() => {
|
|
883
|
+
(target) => action.run(async () => {
|
|
854
884
|
if (!client) throw new NotConnectedError();
|
|
855
885
|
if (!id) throw new Error("No app to upgrade.");
|
|
856
|
-
return client.
|
|
886
|
+
return await client.apps.upgrade({ app: id, ...target }, confirmWith(passkey));
|
|
857
887
|
}),
|
|
858
888
|
[client, id, passkey, action.run]
|
|
859
889
|
);
|
|
@@ -861,15 +891,26 @@ function useUpgradeApp(appId, options) {
|
|
|
861
891
|
}
|
|
862
892
|
function usePackages() {
|
|
863
893
|
const client = useSignedInClient();
|
|
864
|
-
return useResource(
|
|
894
|
+
return useResource(
|
|
895
|
+
client ? async () => (await client.packages.list()).packages : null,
|
|
896
|
+
[],
|
|
897
|
+
[client]
|
|
898
|
+
);
|
|
865
899
|
}
|
|
866
900
|
function useOrg(orgId) {
|
|
867
901
|
const client = useSignedInClient();
|
|
868
|
-
return useResource(
|
|
902
|
+
return useResource(
|
|
903
|
+
client && orgId ? async () => await client.orgs.get({ org: orgId }) : null,
|
|
904
|
+
null,
|
|
905
|
+
[client, orgId]
|
|
906
|
+
);
|
|
869
907
|
}
|
|
870
908
|
function useCreateOrg(options) {
|
|
871
909
|
const { withClient, ...state } = useClientAction(options);
|
|
872
|
-
const create = react.useCallback(
|
|
910
|
+
const create = react.useCallback(
|
|
911
|
+
(name) => withClient(async (c) => (await c.orgs.create({ name })).orgId),
|
|
912
|
+
[withClient]
|
|
913
|
+
);
|
|
873
914
|
return { create, ...state };
|
|
874
915
|
}
|
|
875
916
|
function useDeleteOrg(options) {
|
|
@@ -877,7 +918,7 @@ function useDeleteOrg(options) {
|
|
|
877
918
|
const { withClient, ...state } = useClientAction(options);
|
|
878
919
|
const deleteOrg = react.useCallback(
|
|
879
920
|
(orgId) => withClient(async (c) => {
|
|
880
|
-
await c.
|
|
921
|
+
await c.orgs.delete({ org: orgId }, confirmWith(passkey));
|
|
881
922
|
return true;
|
|
882
923
|
}),
|
|
883
924
|
[withClient, passkey]
|
|
@@ -889,7 +930,7 @@ function useSetMember(options) {
|
|
|
889
930
|
const { withClient, ...state } = useClientAction(options);
|
|
890
931
|
const setMember = react.useCallback(
|
|
891
932
|
(orgId, account, role) => withClient(async (c) => {
|
|
892
|
-
await c.setMember(orgId, account, role, passkey);
|
|
933
|
+
await c.orgs.setMember({ org: orgId, account, role }, confirmWith(passkey));
|
|
893
934
|
return true;
|
|
894
935
|
}),
|
|
895
936
|
[withClient, passkey]
|
|
@@ -900,7 +941,9 @@ function useRemoveMember(options) {
|
|
|
900
941
|
const { passkey } = useMero();
|
|
901
942
|
const { withClient, ...state } = useClientAction(options);
|
|
902
943
|
const removeMember = react.useCallback(
|
|
903
|
-
(orgId, account) => withClient(
|
|
944
|
+
(orgId, account) => withClient(
|
|
945
|
+
async (c) => await c.orgs.removeMember({ org: orgId, account }, confirmWith(passkey))
|
|
946
|
+
),
|
|
904
947
|
[withClient, passkey]
|
|
905
948
|
);
|
|
906
949
|
return { removeMember, ...state };
|
|
@@ -909,7 +952,7 @@ function useSetOrgMetadata(options) {
|
|
|
909
952
|
const { withClient, ...state } = useClientAction(options);
|
|
910
953
|
const setMetadata = react.useCallback(
|
|
911
954
|
(orgId, metadata) => withClient(async (c) => {
|
|
912
|
-
await c.
|
|
955
|
+
await c.orgs.metadata({ org: orgId, metadata });
|
|
913
956
|
return true;
|
|
914
957
|
}),
|
|
915
958
|
[withClient]
|
|
@@ -920,7 +963,7 @@ function useSetMemberMetadata(options) {
|
|
|
920
963
|
const { withClient, ...state } = useClientAction(options);
|
|
921
964
|
const setMetadata = react.useCallback(
|
|
922
965
|
(orgId, account, metadata) => withClient(async (c) => {
|
|
923
|
-
await c.
|
|
966
|
+
await c.orgs.memberMetadata({ org: orgId, account, metadata });
|
|
924
967
|
return true;
|
|
925
968
|
}),
|
|
926
969
|
[withClient]
|
|
@@ -932,7 +975,7 @@ function useSetCapabilities(options) {
|
|
|
932
975
|
const { withClient, ...state } = useClientAction(options);
|
|
933
976
|
const setCapabilities = react.useCallback(
|
|
934
977
|
(orgId, capabilities, at = {}) => withClient(async (c) => {
|
|
935
|
-
await c.
|
|
978
|
+
await c.orgs.capabilities({ org: orgId, capabilities, ...at }, confirmWith(passkey));
|
|
936
979
|
return true;
|
|
937
980
|
}),
|
|
938
981
|
[withClient, passkey]
|
|
@@ -942,7 +985,7 @@ function useSetCapabilities(options) {
|
|
|
942
985
|
function useTeam(orgId, teamId) {
|
|
943
986
|
const client = useSignedInClient();
|
|
944
987
|
return useResource(
|
|
945
|
-
client && orgId && teamId ? () => client.
|
|
988
|
+
client && orgId && teamId ? () => client.orgs.teamGet({ org: orgId, team: teamId }) : null,
|
|
946
989
|
null,
|
|
947
990
|
[client, orgId, teamId]
|
|
948
991
|
);
|
|
@@ -950,7 +993,7 @@ function useTeam(orgId, teamId) {
|
|
|
950
993
|
function useCreateTeam(options) {
|
|
951
994
|
const { withClient, ...state } = useClientAction(options);
|
|
952
995
|
const create = react.useCallback(
|
|
953
|
-
({ orgId, name, join = "invite", parent }) => withClient((c) => c.
|
|
996
|
+
({ orgId, name, join = "invite", parent }) => withClient(async (c) => (await c.orgs.teamCreate({ org: orgId, name, join, parent })).teamId),
|
|
954
997
|
[withClient]
|
|
955
998
|
);
|
|
956
999
|
return { create, ...state };
|
|
@@ -959,7 +1002,7 @@ function useUpdateTeam(options) {
|
|
|
959
1002
|
const { withClient, ...state } = useClientAction(options);
|
|
960
1003
|
const update = react.useCallback(
|
|
961
1004
|
(orgId, teamId, change) => withClient(async (c) => {
|
|
962
|
-
await c.
|
|
1005
|
+
await c.orgs.teamUpdate({ org: orgId, team: teamId, ...change });
|
|
963
1006
|
return true;
|
|
964
1007
|
}),
|
|
965
1008
|
[withClient]
|
|
@@ -967,13 +1010,14 @@ function useUpdateTeam(options) {
|
|
|
967
1010
|
return { update, ...state };
|
|
968
1011
|
}
|
|
969
1012
|
function useDeleteTeam(options) {
|
|
1013
|
+
const { passkey } = useMero();
|
|
970
1014
|
const { withClient, ...state } = useClientAction(options);
|
|
971
1015
|
const deleteTeam = react.useCallback(
|
|
972
1016
|
(orgId, teamId) => withClient(async (c) => {
|
|
973
|
-
await c.
|
|
1017
|
+
await c.orgs.teamDelete({ org: orgId, team: teamId }, confirmWith(passkey));
|
|
974
1018
|
return true;
|
|
975
1019
|
}),
|
|
976
|
-
[withClient]
|
|
1020
|
+
[withClient, passkey]
|
|
977
1021
|
);
|
|
978
1022
|
return { deleteTeam, ...state };
|
|
979
1023
|
}
|
|
@@ -982,7 +1026,7 @@ function useSetTeamMember(options) {
|
|
|
982
1026
|
const { withClient, ...state } = useClientAction(options);
|
|
983
1027
|
const setTeamMember = react.useCallback(
|
|
984
1028
|
(orgId, teamId, account, row = {}) => withClient(async (c) => {
|
|
985
|
-
await c.
|
|
1029
|
+
await c.orgs.teamSetMember({ org: orgId, team: teamId, account, ...row }, confirmWith(passkey));
|
|
986
1030
|
return true;
|
|
987
1031
|
}),
|
|
988
1032
|
[withClient, passkey]
|
|
@@ -994,7 +1038,7 @@ function useRemoveTeamMember(options) {
|
|
|
994
1038
|
const { withClient, ...state } = useClientAction(options);
|
|
995
1039
|
const removeTeamMember = react.useCallback(
|
|
996
1040
|
(orgId, teamId, account) => withClient(async (c) => {
|
|
997
|
-
await c.
|
|
1041
|
+
await c.orgs.teamRemoveMember({ org: orgId, team: teamId, account }, confirmWith(passkey));
|
|
998
1042
|
return true;
|
|
999
1043
|
}),
|
|
1000
1044
|
[withClient, passkey]
|
|
@@ -1039,7 +1083,7 @@ function useCreateInvite(options) {
|
|
|
1039
1083
|
const { withClient, ...state } = useClientAction(options);
|
|
1040
1084
|
const create = react.useCallback(
|
|
1041
1085
|
({ orgId, role = "member", teams = [], ttlSecs, uses, linkBase }) => withClient(async (c) => {
|
|
1042
|
-
const token = await c.
|
|
1086
|
+
const { token } = await c.orgs.inviteCreate({ org: orgId, role, teams, ttlSecs, uses }, confirmWith(passkey));
|
|
1043
1087
|
return { token, link: inviteLink(token, linkBase) };
|
|
1044
1088
|
}),
|
|
1045
1089
|
[withClient, passkey]
|
|
@@ -1048,7 +1092,10 @@ function useCreateInvite(options) {
|
|
|
1048
1092
|
}
|
|
1049
1093
|
function useRedeemInvite(options) {
|
|
1050
1094
|
const { withClient, ...state } = useClientAction(options);
|
|
1051
|
-
const redeem = react.useCallback(
|
|
1095
|
+
const redeem = react.useCallback(
|
|
1096
|
+
(token) => withClient(async (c) => await c.orgs.inviteRedeem({ token })),
|
|
1097
|
+
[withClient]
|
|
1098
|
+
);
|
|
1052
1099
|
return { redeem, ...state };
|
|
1053
1100
|
}
|
|
1054
1101
|
function useInviteRedemption({ autoRedeem = true } = {}) {
|
|
@@ -1079,7 +1126,7 @@ function useInviteRedemption({ autoRedeem = true } = {}) {
|
|
|
1079
1126
|
setStatus("redeeming");
|
|
1080
1127
|
setFailure(null);
|
|
1081
1128
|
try {
|
|
1082
|
-
const answer = await client.
|
|
1129
|
+
const answer = await client.orgs.inviteRedeem({ token });
|
|
1083
1130
|
setResult(answer);
|
|
1084
1131
|
setStatus("redeemed");
|
|
1085
1132
|
session()?.removeItem(STASH_KEY);
|
|
@@ -1123,7 +1170,7 @@ function useConsent(options) {
|
|
|
1123
1170
|
}, []);
|
|
1124
1171
|
const request = react.useCallback(
|
|
1125
1172
|
(req) => withClient(async (c) => {
|
|
1126
|
-
const answer = await c.
|
|
1173
|
+
const answer = await c.consent.pageCreate({ body: req });
|
|
1127
1174
|
setStarted(answer);
|
|
1128
1175
|
setResult(null);
|
|
1129
1176
|
return answer;
|
|
@@ -1149,7 +1196,7 @@ function useConsent(options) {
|
|
|
1149
1196
|
);
|
|
1150
1197
|
const check = react.useCallback(
|
|
1151
1198
|
(requestId) => withClient(async (c) => {
|
|
1152
|
-
const answer = await c.
|
|
1199
|
+
const answer = await c.consent.pageResult({ request: requestId });
|
|
1153
1200
|
setResult(answer);
|
|
1154
1201
|
return answer;
|
|
1155
1202
|
}),
|
|
@@ -1199,7 +1246,7 @@ function useUploadBlob(options = {}) {
|
|
|
1199
1246
|
const upload = react.useCallback(
|
|
1200
1247
|
(data) => withClient(async (c) => {
|
|
1201
1248
|
if (!id) throw new Error("No app to store the blob in.");
|
|
1202
|
-
return c.
|
|
1249
|
+
return c.apps.blobUpload({ app: id, body: await bytesOf(data), contentType: "application/octet-stream" });
|
|
1203
1250
|
}),
|
|
1204
1251
|
[withClient, id]
|
|
1205
1252
|
);
|
|
@@ -1209,7 +1256,7 @@ function useBlobInfo(blobId, options = {}) {
|
|
|
1209
1256
|
const client = useSignedInClient();
|
|
1210
1257
|
const id = useAppId(options.appId);
|
|
1211
1258
|
return useResource(
|
|
1212
|
-
client && id && blobId ? () => client.blobInfo(id, blobId) : null,
|
|
1259
|
+
client && id && blobId ? () => client.apps.blobInfo({ app: id, id: blobId }) : null,
|
|
1213
1260
|
null,
|
|
1214
1261
|
[client, id, blobId]
|
|
1215
1262
|
);
|
|
@@ -1217,7 +1264,11 @@ function useBlobInfo(blobId, options = {}) {
|
|
|
1217
1264
|
function useBlobs(appId) {
|
|
1218
1265
|
const client = useSignedInClient();
|
|
1219
1266
|
const id = useAppId(appId);
|
|
1220
|
-
return useResource(
|
|
1267
|
+
return useResource(
|
|
1268
|
+
client && id ? async () => (await client.apps.blobList({ app: id })).blobs : null,
|
|
1269
|
+
[],
|
|
1270
|
+
[client, id]
|
|
1271
|
+
);
|
|
1221
1272
|
}
|
|
1222
1273
|
function useBlobUrl(blobId, options = {}) {
|
|
1223
1274
|
const client = useSignedInClient();
|
|
@@ -1246,7 +1297,7 @@ function useDeleteBlob(options = {}) {
|
|
|
1246
1297
|
const deleteBlob = react.useCallback(
|
|
1247
1298
|
(blobId) => withClient(async (c) => {
|
|
1248
1299
|
if (!id) throw new Error("No app.");
|
|
1249
|
-
await c.
|
|
1300
|
+
await c.apps.blobDelete({ app: id, id: blobId });
|
|
1250
1301
|
return true;
|
|
1251
1302
|
}),
|
|
1252
1303
|
[withClient, id]
|
|
@@ -1337,7 +1388,8 @@ function useEphemeral(appId, options = {}) {
|
|
|
1337
1388
|
seq.current += 1;
|
|
1338
1389
|
const bytes = value === null ? null : codecRef.current.encode(value);
|
|
1339
1390
|
lastSent.current = Date.now();
|
|
1340
|
-
|
|
1391
|
+
const state2 = meroJs.presenceState(bytes);
|
|
1392
|
+
client.apps.presencePublish({ app: id, seq: seq.current, state: state2 }).then(
|
|
1341
1393
|
() => setError(null),
|
|
1342
1394
|
(e) => setError(e instanceof Error ? e : new Error(String(e)))
|
|
1343
1395
|
);
|
|
@@ -1387,7 +1439,7 @@ function useEphemeral(appId, options = {}) {
|
|
|
1387
1439
|
function useAccount() {
|
|
1388
1440
|
const client = useSignedInClient();
|
|
1389
1441
|
const { accountId } = useMero();
|
|
1390
|
-
const me = useResource(client ? () => client.me() : null, null, [client, accountId]);
|
|
1442
|
+
const me = useResource(client ? () => client.auth.me() : null, null, [client, accountId]);
|
|
1391
1443
|
return { accountId, ...me };
|
|
1392
1444
|
}
|
|
1393
1445
|
function usePasskeys(options) {
|
|
@@ -1399,14 +1451,14 @@ function usePasskeys(options) {
|
|
|
1399
1451
|
);
|
|
1400
1452
|
const remove = react.useCallback(
|
|
1401
1453
|
(credentialId) => withClient(async (c) => {
|
|
1402
|
-
await c.
|
|
1454
|
+
await c.auth.passkeyRemove({ cred: credentialId }, confirmWith(passkey));
|
|
1403
1455
|
return true;
|
|
1404
1456
|
}),
|
|
1405
1457
|
[withClient, passkey]
|
|
1406
1458
|
);
|
|
1407
1459
|
const label = react.useCallback(
|
|
1408
1460
|
(credentialId, name) => withClient(async (c) => {
|
|
1409
|
-
await c.
|
|
1461
|
+
await c.auth.passkeyLabel({ cred: credentialId, label: name });
|
|
1410
1462
|
return true;
|
|
1411
1463
|
}),
|
|
1412
1464
|
[withClient]
|
|
@@ -1416,15 +1468,16 @@ function usePasskeys(options) {
|
|
|
1416
1468
|
function useApiKeys(options) {
|
|
1417
1469
|
const client = useSignedInClient();
|
|
1418
1470
|
const { passkey, accountId } = useMero();
|
|
1419
|
-
const keys = useResource(
|
|
1420
|
-
client,
|
|
1421
|
-
|
|
1422
|
-
|
|
1471
|
+
const keys = useResource(
|
|
1472
|
+
client ? async () => (await client.auth.apikeyList()).keys : null,
|
|
1473
|
+
[],
|
|
1474
|
+
[client, accountId]
|
|
1475
|
+
);
|
|
1423
1476
|
const { refetch } = keys;
|
|
1424
1477
|
const { withClient, ...state } = useClientAction(options);
|
|
1425
1478
|
const create = react.useCallback(
|
|
1426
1479
|
(input = {}) => withClient(async (c) => {
|
|
1427
|
-
const created = await c.
|
|
1480
|
+
const created = await c.auth.apikeyCreate({ ...input }, confirmWith(passkey));
|
|
1428
1481
|
void refetch();
|
|
1429
1482
|
return created;
|
|
1430
1483
|
}),
|
|
@@ -1432,11 +1485,11 @@ function useApiKeys(options) {
|
|
|
1432
1485
|
);
|
|
1433
1486
|
const revoke = react.useCallback(
|
|
1434
1487
|
(keyId) => withClient(async (c) => {
|
|
1435
|
-
await c.
|
|
1488
|
+
await c.auth.apikeyRevoke({ key: keyId }, confirmWith(passkey));
|
|
1436
1489
|
void refetch();
|
|
1437
1490
|
return true;
|
|
1438
1491
|
}),
|
|
1439
|
-
[withClient, refetch]
|
|
1492
|
+
[withClient, passkey, refetch]
|
|
1440
1493
|
);
|
|
1441
1494
|
return {
|
|
1442
1495
|
keys: keys.data,
|