@calimero-network/mero-react 9.1.3 → 9.2.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 +2 -2
- package/dist/index.cjs +39 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -4
- package/dist/index.d.ts +52 -4
- package/dist/index.js +40 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -394,14 +394,14 @@ useSetSubgroupVisibility, useSubgroupVisibility, useSetTeeAdmissionPolicy
|
|
|
394
394
|
useDetachContextFromGroup
|
|
395
395
|
useNamespaces, useNamespace, useNamespaceGroups, useNamespaceIdentity
|
|
396
396
|
useNamespacesForApplication, useCreateNamespace, useDeleteNamespace
|
|
397
|
-
useJoinNamespace, useCreateNamespaceInvitation, useCreateGroupInNamespace
|
|
397
|
+
useJoinNamespace, useRedeemInvitation, useCreateNamespaceInvitation, useCreateGroupInNamespace
|
|
398
398
|
useBlobInfo, useBlobUrl, useUploadBlob
|
|
399
399
|
|
|
400
400
|
// Types (mero-react)
|
|
401
401
|
MeroContextValue, MeroProviderConfig, MeroProviderProps
|
|
402
402
|
CustomConnectionConfig, AppContext, ExecutionResult
|
|
403
403
|
ApplicationContextRecord, ContextDiscoveryOptions, ContextDiscoveryState
|
|
404
|
-
BlobHookOptions, UseBlobUrlOptions
|
|
404
|
+
BlobHookOptions, UseBlobUrlOptions, MutationOptions
|
|
405
405
|
|
|
406
406
|
// Storage (mero-react)
|
|
407
407
|
localStorageTokenStorage
|
package/dist/index.cjs
CHANGED
|
@@ -1508,23 +1508,26 @@ function useMountedRef() {
|
|
|
1508
1508
|
}, []);
|
|
1509
1509
|
return mountedRef;
|
|
1510
1510
|
}
|
|
1511
|
-
function useAsyncMutation() {
|
|
1511
|
+
function useAsyncMutation({ throwOnError = false } = {}) {
|
|
1512
1512
|
const mountedRef = useMountedRef();
|
|
1513
1513
|
const [loading, setLoading] = react.useState(false);
|
|
1514
1514
|
const [error, setError] = react.useState(null);
|
|
1515
|
+
const [failure, setFailure] = react.useState(null);
|
|
1515
1516
|
const run = react.useCallback(
|
|
1516
1517
|
async (action) => {
|
|
1517
1518
|
if (mountedRef.current) {
|
|
1518
1519
|
setLoading(true);
|
|
1519
1520
|
setError(null);
|
|
1521
|
+
setFailure(null);
|
|
1520
1522
|
}
|
|
1521
1523
|
try {
|
|
1522
1524
|
return await action();
|
|
1523
1525
|
} catch (err) {
|
|
1524
|
-
const errorValue = toError(err);
|
|
1525
1526
|
if (mountedRef.current) {
|
|
1526
|
-
setError(
|
|
1527
|
+
setError(toError(err));
|
|
1528
|
+
setFailure(meroJs.classifyError(err));
|
|
1527
1529
|
}
|
|
1530
|
+
if (throwOnError) throw err;
|
|
1528
1531
|
return null;
|
|
1529
1532
|
} finally {
|
|
1530
1533
|
if (mountedRef.current) {
|
|
@@ -1532,9 +1535,9 @@ function useAsyncMutation() {
|
|
|
1532
1535
|
}
|
|
1533
1536
|
}
|
|
1534
1537
|
},
|
|
1535
|
-
[mountedRef]
|
|
1538
|
+
[mountedRef, throwOnError]
|
|
1536
1539
|
);
|
|
1537
|
-
return { loading, error, run, setError };
|
|
1540
|
+
return { loading, error, failure, run, setError };
|
|
1538
1541
|
}
|
|
1539
1542
|
function useAsyncResource(fetcher, initialValue, deps) {
|
|
1540
1543
|
const mountedRef = useMountedRef();
|
|
@@ -1928,9 +1931,9 @@ function useDeleteContext() {
|
|
|
1928
1931
|
);
|
|
1929
1932
|
return { deleteContext, loading, error };
|
|
1930
1933
|
}
|
|
1931
|
-
function useJoinContext() {
|
|
1934
|
+
function useJoinContext(options = {}) {
|
|
1932
1935
|
const { mero } = useMero();
|
|
1933
|
-
const { loading, error, run } = useAsyncMutation();
|
|
1936
|
+
const { loading, error, failure, run } = useAsyncMutation(options);
|
|
1934
1937
|
const joinContext = react.useCallback(
|
|
1935
1938
|
async (contextId) => {
|
|
1936
1939
|
if (!mero) return null;
|
|
@@ -1938,7 +1941,7 @@ function useJoinContext() {
|
|
|
1938
1941
|
},
|
|
1939
1942
|
[mero, run]
|
|
1940
1943
|
);
|
|
1941
|
-
return { joinContext, loading, error };
|
|
1944
|
+
return { joinContext, loading, error, failure };
|
|
1942
1945
|
}
|
|
1943
1946
|
function useJoinSubgroupInheritance() {
|
|
1944
1947
|
const { mero } = useMero();
|
|
@@ -2099,9 +2102,9 @@ function useCreateNamespaceInvitation() {
|
|
|
2099
2102
|
);
|
|
2100
2103
|
return { createNamespaceInvitation, loading, error };
|
|
2101
2104
|
}
|
|
2102
|
-
function useJoinNamespace() {
|
|
2105
|
+
function useJoinNamespace(options = {}) {
|
|
2103
2106
|
const { mero } = useMero();
|
|
2104
|
-
const { loading, error, run } = useAsyncMutation();
|
|
2107
|
+
const { loading, error, failure, run } = useAsyncMutation(options);
|
|
2105
2108
|
const joinNamespace = react.useCallback(
|
|
2106
2109
|
async (namespaceId, request) => {
|
|
2107
2110
|
if (!mero) return null;
|
|
@@ -2109,7 +2112,31 @@ function useJoinNamespace() {
|
|
|
2109
2112
|
},
|
|
2110
2113
|
[mero, run]
|
|
2111
2114
|
);
|
|
2112
|
-
return { joinNamespace, loading, error };
|
|
2115
|
+
return { joinNamespace, loading, error, failure };
|
|
2116
|
+
}
|
|
2117
|
+
function useRedeemInvitation() {
|
|
2118
|
+
const { mero } = useMero();
|
|
2119
|
+
const mountedRef = useMountedRef();
|
|
2120
|
+
const [loading, setLoading] = react.useState(false);
|
|
2121
|
+
const [outcome, setOutcome] = react.useState(null);
|
|
2122
|
+
const redeem = react.useCallback(
|
|
2123
|
+
async (namespaceId, invitation, options = {}) => {
|
|
2124
|
+
if (!mero) return null;
|
|
2125
|
+
if (mountedRef.current) {
|
|
2126
|
+
setLoading(true);
|
|
2127
|
+
setOutcome(null);
|
|
2128
|
+
}
|
|
2129
|
+
try {
|
|
2130
|
+
const result = await mero.admin.redeemInvitation(namespaceId, invitation, options);
|
|
2131
|
+
if (mountedRef.current) setOutcome(result);
|
|
2132
|
+
return result;
|
|
2133
|
+
} finally {
|
|
2134
|
+
if (mountedRef.current) setLoading(false);
|
|
2135
|
+
}
|
|
2136
|
+
},
|
|
2137
|
+
[mero, mountedRef]
|
|
2138
|
+
);
|
|
2139
|
+
return { redeem, outcome, loading };
|
|
2113
2140
|
}
|
|
2114
2141
|
function useCreateGroupInNamespace() {
|
|
2115
2142
|
const { mero } = useMero();
|
|
@@ -3042,6 +3069,7 @@ exports.useNamespaceIdentity = useNamespaceIdentity;
|
|
|
3042
3069
|
exports.useNamespaces = useNamespaces;
|
|
3043
3070
|
exports.useNamespacesForApplication = useNamespacesForApplication;
|
|
3044
3071
|
exports.useNodeIdentity = useNodeIdentity;
|
|
3072
|
+
exports.useRedeemInvitation = useRedeemInvitation;
|
|
3045
3073
|
exports.useRemoveGroupMembers = useRemoveGroupMembers;
|
|
3046
3074
|
exports.useReparentGroup = useReparentGroup;
|
|
3047
3075
|
exports.useResyncContext = useResyncContext;
|