@calimero-network/mero-react 4.6.1 → 5.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 +0 -1
- package/dist/index.cjs +182 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -15
- package/dist/index.d.ts +48 -15
- package/dist/index.js +182 -28
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -2,9 +2,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { CSSProperties, ReactNode } from 'react';
|
|
4
4
|
import * as _calimero_network_mero_js from '@calimero-network/mero-js';
|
|
5
|
-
import { MeroJs, TokenStore, SetMetadataRequest, SseEventData, GroupMembershipEventData, AddGroupMembersRequest, CreateContextRequest, CreateGroupInNamespaceRequest, CreateNamespaceRequest, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, DeleteGroupRequest, DeleteNamespaceRequest, DetachContextFromGroupRequest, GroupUpgradeStatusResponseData, GroupContextEntry, GroupInfo, CreateGroupInvitationRequest, MetadataRecord, JoinGroupRequest, JoinNamespaceRequest, MigrationStatus, MigrationStatusRollup, MemberMigrationStatusEntry, MigrateMyEntriesSummary, Namespace, SubgroupEntry, NamespaceIdentity,
|
|
5
|
+
import { MeroJs, TokenStore, SetMetadataRequest, SseEventData, GroupMembershipEventData, GroupMigrationEventData, Codec, AddGroupMembersRequest, CreateContextRequest, CreateGroupInNamespaceRequest, CreateNamespaceRequest, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, DeleteGroupRequest, DeleteNamespaceRequest, DetachContextFromGroupRequest, GroupUpgradeStatusResponseData, GroupContextEntry, GroupInfo, CreateGroupInvitationRequest, MetadataRecord, JoinGroupRequest, JoinNamespaceRequest, MigrationStatus, MigrationStatusRollup, MemberMigrationStatusEntry, MigrateMyEntriesSummary, Namespace, SubgroupEntry, NamespaceIdentity, RemoveGroupMembersRequest, ReparentGroupRequest, ResyncContextRequest, RetryGroupUpgradeRequest, SetDefaultCapabilitiesRequest, SetSubgroupVisibilityRequest, SetTeeAdmissionPolicyRequest, SyncGroupRequest, UpdateMemberRoleRequest, UpgradeGroupRequest, TokenData } from '@calimero-network/mero-js';
|
|
6
6
|
export * from '@calimero-network/mero-js';
|
|
7
|
-
export { CAPABILITIES, DEFAULT_LOCAL_NODE_PORTS, DiscoverLocalNodesOptions, MetadataRecord, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
|
|
7
|
+
export { CAPABILITIES, Codec, DEFAULT_LOCAL_NODE_PORTS, DiscoverLocalNodesOptions, EphemeralClient, EphemeralEntry, MetadataRecord, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Types for mero-react
|
|
@@ -336,6 +336,50 @@ interface MigrationAdminPanelProps {
|
|
|
336
336
|
*/
|
|
337
337
|
declare function MigrationAdminPanel({ namespaceId, pollIntervalMs, className }: MigrationAdminPanelProps): react_jsx_runtime.JSX.Element;
|
|
338
338
|
|
|
339
|
+
interface UseEphemeralOptions<T> {
|
|
340
|
+
/** Encoding for the presence slice. Defaults to JSON. */
|
|
341
|
+
codec?: Codec<T>;
|
|
342
|
+
/** Base value for the first `setPresence` merge. */
|
|
343
|
+
initial?: T;
|
|
344
|
+
/** Minimum ms between publishes. Trailing edge — the latest value wins. */
|
|
345
|
+
throttleMs?: number;
|
|
346
|
+
/** Include your own echoed presence in `peers`. Default false. */
|
|
347
|
+
includeSelf?: boolean;
|
|
348
|
+
}
|
|
349
|
+
/** Shape returned by {@link useEphemeral}. */
|
|
350
|
+
interface UseEphemeralResult<T> {
|
|
351
|
+
peers: Map<string, T>;
|
|
352
|
+
setPresence: (partial: Partial<T>) => void;
|
|
353
|
+
ageOf: (author: string) => number | undefined;
|
|
354
|
+
error: Error | null;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Observe and publish ephemeral presence (cursors, typing, online) for a
|
|
358
|
+
* context.
|
|
359
|
+
*
|
|
360
|
+
* ONE read path: the subscription. When a client subscribes, the node replays
|
|
361
|
+
* that context's current presence to that connection as ordinary entries
|
|
362
|
+
* before the live deltas start, so seeding and updating share a single shape
|
|
363
|
+
* ({@link EphemeralEntry}) and a reconnect — `SseClient` auto-reconnects and
|
|
364
|
+
* re-subscribes — re-seeds itself. There is no snapshot fetch and no
|
|
365
|
+
* client-side reconciliation pass.
|
|
366
|
+
*
|
|
367
|
+
* Freshness is computed entirely from local clock deltas: a replayed entry is
|
|
368
|
+
* current as of `Date.now() - ageMs`, a live delta as of `Date.now()`. No
|
|
369
|
+
* cross-machine clock comparison is ever performed.
|
|
370
|
+
*
|
|
371
|
+
* No client-side TTL or heartbeat: the node sweeps at 7s and emits removals,
|
|
372
|
+
* and re-publishes on your behalf every 2.5s. A replay is treated as
|
|
373
|
+
* AUTHORITATIVE — see the replay-reconcile pass in the read effect — so a peer
|
|
374
|
+
* swept while the SSE connection was down does not survive the reconnect.
|
|
375
|
+
*
|
|
376
|
+
* `error` is derived, not accumulated: standing conditions (no `ephemeral`
|
|
377
|
+
* surface) are recomputed every render, one-shot async failures are latched
|
|
378
|
+
* keyed by the context they happened in, and whether a latched failure is even
|
|
379
|
+
* relevant (an unresolved identity when `includeSelf` is true) is decided at
|
|
380
|
+
* read time. Nothing survives a context switch.
|
|
381
|
+
*/
|
|
382
|
+
declare function useEphemeral<T>(contextId: string | null, options?: UseEphemeralOptions<T>): UseEphemeralResult<T>;
|
|
339
383
|
/**
|
|
340
384
|
* Shape accepted by the metadata-setter hooks — re-exported from mero-js so
|
|
341
385
|
* callers have one canonical type. A `set*Metadata` call **replaces the whole
|
|
@@ -353,7 +397,7 @@ declare function useExecute(contextId: string | null, executorId: string | null)
|
|
|
353
397
|
error: Error | null;
|
|
354
398
|
};
|
|
355
399
|
/** Event payload delivered to a `useSubscription` callback. */
|
|
356
|
-
type SubscriptionEventData = SseEventData | GroupMembershipEventData;
|
|
400
|
+
type SubscriptionEventData = SseEventData | GroupMembershipEventData | GroupMigrationEventData;
|
|
357
401
|
/** Ids to subscribe to. Either can be omitted, but not both. */
|
|
358
402
|
interface SubscriptionInput {
|
|
359
403
|
contextIds?: string[];
|
|
@@ -383,7 +427,6 @@ declare function useApplicationContexts(applicationId?: string | null): {
|
|
|
383
427
|
};
|
|
384
428
|
declare function useGroupMembers(groupId?: string | null): {
|
|
385
429
|
members: _calimero_network_mero_js.GroupMember[];
|
|
386
|
-
selfIdentity: string | null;
|
|
387
430
|
loading: boolean;
|
|
388
431
|
error: Error | null;
|
|
389
432
|
refetch: () => Promise<void>;
|
|
@@ -551,11 +594,6 @@ declare function useSetTeeAdmissionPolicy(): {
|
|
|
551
594
|
loading: boolean;
|
|
552
595
|
error: Error | null;
|
|
553
596
|
};
|
|
554
|
-
declare function useUpdateGroupSettings(): {
|
|
555
|
-
updateGroupSettings: (groupId: string, request: UpdateGroupSettingsRequest) => Promise<void | null>;
|
|
556
|
-
loading: boolean;
|
|
557
|
-
error: Error | null;
|
|
558
|
-
};
|
|
559
597
|
declare function useSetGroupMetadata(): {
|
|
560
598
|
setGroupMetadata: (groupId: string, request: SetMetadataInput) => Promise<void | null>;
|
|
561
599
|
loading: boolean;
|
|
@@ -583,11 +621,6 @@ declare function useMemberMetadata(groupId?: string | null, identity?: string |
|
|
|
583
621
|
error: Error | null;
|
|
584
622
|
refetch: () => Promise<void>;
|
|
585
623
|
};
|
|
586
|
-
declare function useRegisterGroupSigningKey(): {
|
|
587
|
-
registerGroupSigningKey: (groupId: string, request: RegisterGroupSigningKeyRequest) => Promise<_calimero_network_mero_js.RegisterGroupSigningKeyResponseData | null>;
|
|
588
|
-
loading: boolean;
|
|
589
|
-
error: Error | null;
|
|
590
|
-
};
|
|
591
624
|
declare function useUpgradeGroup(): {
|
|
592
625
|
upgradeGroup: (groupId: string, request: UpgradeGroupRequest) => Promise<_calimero_network_mero_js.UpgradeGroupResponseData | null>;
|
|
593
626
|
loading: boolean;
|
|
@@ -814,4 +847,4 @@ declare function clearContextIdentity(): void;
|
|
|
814
847
|
*/
|
|
815
848
|
declare function clearAllStorage(): void;
|
|
816
849
|
|
|
817
|
-
export { type AppContext, AppMode, type ApplicationContextRecord, CalimeroLogo, type CalimeroLogoProps, ConnectButton, type ConnectButtonProps, ConnectionType, type ContextDiscoveryOptions, type ContextDiscoveryState, type CustomConnectionConfig, type ExecutionResult, LoginModal, type LoginModalProps, MERO_CSS_VARS, MeroContext, type MeroContextValue, MeroProvider, type MeroProviderConfig, type MeroProviderProps, type MeroTheme, MigrationAdminPanel, type MigrationAdminPanelProps, MigrationPendingBanner, type MigrationPendingBannerProps, type ResolvedMeroTheme, type SetMetadataInput, type SubscriptionEventData, type SubscriptionInput, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, clearTokenNodeUrl, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, localStorageTokenStorage, resolveMeroTheme, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAddGroupMembers, useAppVersion, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDefaultCapabilities, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication,
|
|
850
|
+
export { type AppContext, AppMode, type ApplicationContextRecord, CalimeroLogo, type CalimeroLogoProps, ConnectButton, type ConnectButtonProps, ConnectionType, type ContextDiscoveryOptions, type ContextDiscoveryState, type CustomConnectionConfig, type ExecutionResult, LoginModal, type LoginModalProps, MERO_CSS_VARS, MeroContext, type MeroContextValue, MeroProvider, type MeroProviderConfig, type MeroProviderProps, type MeroTheme, MigrationAdminPanel, type MigrationAdminPanelProps, MigrationPendingBanner, type MigrationPendingBannerProps, type ResolvedMeroTheme, type SetMetadataInput, type SubscriptionEventData, type SubscriptionInput, type UseEphemeralOptions, type UseEphemeralResult, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, clearTokenNodeUrl, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, localStorageTokenStorage, resolveMeroTheme, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAddGroupMembers, useAppVersion, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDefaultCapabilities, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useEphemeral, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication, useRemoveGroupMembers, useReparentGroup, useResyncContext, useRetryGroupUpgrade, useSetContextMetadata, useSetDefaultCapabilities, useSetGroupMetadata, useSetMemberMetadata, useSetSubgroupVisibility, useSetTeeAdmissionPolicy, useSubgroupVisibility, useSubgroups, useSubscription, useSyncGroup, useUpdateMemberRole, useUpgradeGroup };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { CSSProperties, ReactNode } from 'react';
|
|
4
4
|
import * as _calimero_network_mero_js from '@calimero-network/mero-js';
|
|
5
|
-
import { MeroJs, TokenStore, SetMetadataRequest, SseEventData, GroupMembershipEventData, AddGroupMembersRequest, CreateContextRequest, CreateGroupInNamespaceRequest, CreateNamespaceRequest, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, DeleteGroupRequest, DeleteNamespaceRequest, DetachContextFromGroupRequest, GroupUpgradeStatusResponseData, GroupContextEntry, GroupInfo, CreateGroupInvitationRequest, MetadataRecord, JoinGroupRequest, JoinNamespaceRequest, MigrationStatus, MigrationStatusRollup, MemberMigrationStatusEntry, MigrateMyEntriesSummary, Namespace, SubgroupEntry, NamespaceIdentity,
|
|
5
|
+
import { MeroJs, TokenStore, SetMetadataRequest, SseEventData, GroupMembershipEventData, GroupMigrationEventData, Codec, AddGroupMembersRequest, CreateContextRequest, CreateGroupInNamespaceRequest, CreateNamespaceRequest, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, DeleteGroupRequest, DeleteNamespaceRequest, DetachContextFromGroupRequest, GroupUpgradeStatusResponseData, GroupContextEntry, GroupInfo, CreateGroupInvitationRequest, MetadataRecord, JoinGroupRequest, JoinNamespaceRequest, MigrationStatus, MigrationStatusRollup, MemberMigrationStatusEntry, MigrateMyEntriesSummary, Namespace, SubgroupEntry, NamespaceIdentity, RemoveGroupMembersRequest, ReparentGroupRequest, ResyncContextRequest, RetryGroupUpgradeRequest, SetDefaultCapabilitiesRequest, SetSubgroupVisibilityRequest, SetTeeAdmissionPolicyRequest, SyncGroupRequest, UpdateMemberRoleRequest, UpgradeGroupRequest, TokenData } from '@calimero-network/mero-js';
|
|
6
6
|
export * from '@calimero-network/mero-js';
|
|
7
|
-
export { CAPABILITIES, DEFAULT_LOCAL_NODE_PORTS, DiscoverLocalNodesOptions, MetadataRecord, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
|
|
7
|
+
export { CAPABILITIES, Codec, DEFAULT_LOCAL_NODE_PORTS, DiscoverLocalNodesOptions, EphemeralClient, EphemeralEntry, MetadataRecord, discoverLocalNodes, hasCap, localNodeUrl, nodeEndpoint, probeNodeHealth, withCap, withoutCap } from '@calimero-network/mero-js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Types for mero-react
|
|
@@ -336,6 +336,50 @@ interface MigrationAdminPanelProps {
|
|
|
336
336
|
*/
|
|
337
337
|
declare function MigrationAdminPanel({ namespaceId, pollIntervalMs, className }: MigrationAdminPanelProps): react_jsx_runtime.JSX.Element;
|
|
338
338
|
|
|
339
|
+
interface UseEphemeralOptions<T> {
|
|
340
|
+
/** Encoding for the presence slice. Defaults to JSON. */
|
|
341
|
+
codec?: Codec<T>;
|
|
342
|
+
/** Base value for the first `setPresence` merge. */
|
|
343
|
+
initial?: T;
|
|
344
|
+
/** Minimum ms between publishes. Trailing edge — the latest value wins. */
|
|
345
|
+
throttleMs?: number;
|
|
346
|
+
/** Include your own echoed presence in `peers`. Default false. */
|
|
347
|
+
includeSelf?: boolean;
|
|
348
|
+
}
|
|
349
|
+
/** Shape returned by {@link useEphemeral}. */
|
|
350
|
+
interface UseEphemeralResult<T> {
|
|
351
|
+
peers: Map<string, T>;
|
|
352
|
+
setPresence: (partial: Partial<T>) => void;
|
|
353
|
+
ageOf: (author: string) => number | undefined;
|
|
354
|
+
error: Error | null;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Observe and publish ephemeral presence (cursors, typing, online) for a
|
|
358
|
+
* context.
|
|
359
|
+
*
|
|
360
|
+
* ONE read path: the subscription. When a client subscribes, the node replays
|
|
361
|
+
* that context's current presence to that connection as ordinary entries
|
|
362
|
+
* before the live deltas start, so seeding and updating share a single shape
|
|
363
|
+
* ({@link EphemeralEntry}) and a reconnect — `SseClient` auto-reconnects and
|
|
364
|
+
* re-subscribes — re-seeds itself. There is no snapshot fetch and no
|
|
365
|
+
* client-side reconciliation pass.
|
|
366
|
+
*
|
|
367
|
+
* Freshness is computed entirely from local clock deltas: a replayed entry is
|
|
368
|
+
* current as of `Date.now() - ageMs`, a live delta as of `Date.now()`. No
|
|
369
|
+
* cross-machine clock comparison is ever performed.
|
|
370
|
+
*
|
|
371
|
+
* No client-side TTL or heartbeat: the node sweeps at 7s and emits removals,
|
|
372
|
+
* and re-publishes on your behalf every 2.5s. A replay is treated as
|
|
373
|
+
* AUTHORITATIVE — see the replay-reconcile pass in the read effect — so a peer
|
|
374
|
+
* swept while the SSE connection was down does not survive the reconnect.
|
|
375
|
+
*
|
|
376
|
+
* `error` is derived, not accumulated: standing conditions (no `ephemeral`
|
|
377
|
+
* surface) are recomputed every render, one-shot async failures are latched
|
|
378
|
+
* keyed by the context they happened in, and whether a latched failure is even
|
|
379
|
+
* relevant (an unresolved identity when `includeSelf` is true) is decided at
|
|
380
|
+
* read time. Nothing survives a context switch.
|
|
381
|
+
*/
|
|
382
|
+
declare function useEphemeral<T>(contextId: string | null, options?: UseEphemeralOptions<T>): UseEphemeralResult<T>;
|
|
339
383
|
/**
|
|
340
384
|
* Shape accepted by the metadata-setter hooks — re-exported from mero-js so
|
|
341
385
|
* callers have one canonical type. A `set*Metadata` call **replaces the whole
|
|
@@ -353,7 +397,7 @@ declare function useExecute(contextId: string | null, executorId: string | null)
|
|
|
353
397
|
error: Error | null;
|
|
354
398
|
};
|
|
355
399
|
/** Event payload delivered to a `useSubscription` callback. */
|
|
356
|
-
type SubscriptionEventData = SseEventData | GroupMembershipEventData;
|
|
400
|
+
type SubscriptionEventData = SseEventData | GroupMembershipEventData | GroupMigrationEventData;
|
|
357
401
|
/** Ids to subscribe to. Either can be omitted, but not both. */
|
|
358
402
|
interface SubscriptionInput {
|
|
359
403
|
contextIds?: string[];
|
|
@@ -383,7 +427,6 @@ declare function useApplicationContexts(applicationId?: string | null): {
|
|
|
383
427
|
};
|
|
384
428
|
declare function useGroupMembers(groupId?: string | null): {
|
|
385
429
|
members: _calimero_network_mero_js.GroupMember[];
|
|
386
|
-
selfIdentity: string | null;
|
|
387
430
|
loading: boolean;
|
|
388
431
|
error: Error | null;
|
|
389
432
|
refetch: () => Promise<void>;
|
|
@@ -551,11 +594,6 @@ declare function useSetTeeAdmissionPolicy(): {
|
|
|
551
594
|
loading: boolean;
|
|
552
595
|
error: Error | null;
|
|
553
596
|
};
|
|
554
|
-
declare function useUpdateGroupSettings(): {
|
|
555
|
-
updateGroupSettings: (groupId: string, request: UpdateGroupSettingsRequest) => Promise<void | null>;
|
|
556
|
-
loading: boolean;
|
|
557
|
-
error: Error | null;
|
|
558
|
-
};
|
|
559
597
|
declare function useSetGroupMetadata(): {
|
|
560
598
|
setGroupMetadata: (groupId: string, request: SetMetadataInput) => Promise<void | null>;
|
|
561
599
|
loading: boolean;
|
|
@@ -583,11 +621,6 @@ declare function useMemberMetadata(groupId?: string | null, identity?: string |
|
|
|
583
621
|
error: Error | null;
|
|
584
622
|
refetch: () => Promise<void>;
|
|
585
623
|
};
|
|
586
|
-
declare function useRegisterGroupSigningKey(): {
|
|
587
|
-
registerGroupSigningKey: (groupId: string, request: RegisterGroupSigningKeyRequest) => Promise<_calimero_network_mero_js.RegisterGroupSigningKeyResponseData | null>;
|
|
588
|
-
loading: boolean;
|
|
589
|
-
error: Error | null;
|
|
590
|
-
};
|
|
591
624
|
declare function useUpgradeGroup(): {
|
|
592
625
|
upgradeGroup: (groupId: string, request: UpgradeGroupRequest) => Promise<_calimero_network_mero_js.UpgradeGroupResponseData | null>;
|
|
593
626
|
loading: boolean;
|
|
@@ -814,4 +847,4 @@ declare function clearContextIdentity(): void;
|
|
|
814
847
|
*/
|
|
815
848
|
declare function clearAllStorage(): void;
|
|
816
849
|
|
|
817
|
-
export { type AppContext, AppMode, type ApplicationContextRecord, CalimeroLogo, type CalimeroLogoProps, ConnectButton, type ConnectButtonProps, ConnectionType, type ContextDiscoveryOptions, type ContextDiscoveryState, type CustomConnectionConfig, type ExecutionResult, LoginModal, type LoginModalProps, MERO_CSS_VARS, MeroContext, type MeroContextValue, MeroProvider, type MeroProviderConfig, type MeroProviderProps, type MeroTheme, MigrationAdminPanel, type MigrationAdminPanelProps, MigrationPendingBanner, type MigrationPendingBannerProps, type ResolvedMeroTheme, type SetMetadataInput, type SubscriptionEventData, type SubscriptionInput, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, clearTokenNodeUrl, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, localStorageTokenStorage, resolveMeroTheme, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAddGroupMembers, useAppVersion, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDefaultCapabilities, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication,
|
|
850
|
+
export { type AppContext, AppMode, type ApplicationContextRecord, CalimeroLogo, type CalimeroLogoProps, ConnectButton, type ConnectButtonProps, ConnectionType, type ContextDiscoveryOptions, type ContextDiscoveryState, type CustomConnectionConfig, type ExecutionResult, LoginModal, type LoginModalProps, MERO_CSS_VARS, MeroContext, type MeroContextValue, MeroProvider, type MeroProviderConfig, type MeroProviderProps, type MeroTheme, MigrationAdminPanel, type MigrationAdminPanelProps, MigrationPendingBanner, type MigrationPendingBannerProps, type ResolvedMeroTheme, type SetMetadataInput, type SubscriptionEventData, type SubscriptionInput, type UseEphemeralOptions, type UseEphemeralResult, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, clearTokenNodeUrl, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, localStorageTokenStorage, resolveMeroTheme, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAddGroupMembers, useAppVersion, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDefaultCapabilities, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useEphemeral, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication, useRemoveGroupMembers, useReparentGroup, useResyncContext, useRetryGroupUpgrade, useSetContextMetadata, useSetDefaultCapabilities, useSetGroupMetadata, useSetMemberMetadata, useSetSubgroupVisibility, useSetTeeAdmissionPolicy, useSubgroupVisibility, useSubgroups, useSubscription, useSyncGroup, useUpdateMemberRole, useUpgradeGroup };
|
package/dist/index.js
CHANGED
|
@@ -1266,6 +1266,185 @@ function base58ToHex(input) {
|
|
|
1266
1266
|
}
|
|
1267
1267
|
|
|
1268
1268
|
// src/hooks/index.ts
|
|
1269
|
+
var NO_EPHEMERAL_SURFACE_MESSAGE = "useEphemeral: this client has no `mero.ephemeral` surface. Ephemeral presence requires @calimero-network/mero-js >= 9.1.0; upgrade the installed @calimero-network/mero-js (and any lockfile pin) to use it.";
|
|
1270
|
+
var COULD_NOT_RESOLVE_IDENTITY_MESSAGE = "useEphemeral: could not resolve a local context identity, so your own presence cannot be filtered out. Pass includeSelf: true to accept this.";
|
|
1271
|
+
var REPLAY_RECONCILE_MS = 50;
|
|
1272
|
+
function useEphemeral(contextId, options = {}) {
|
|
1273
|
+
const { includeSelf = false } = options;
|
|
1274
|
+
const { mero } = useMero();
|
|
1275
|
+
const ephemeral = mero ? mero.ephemeral ?? null : null;
|
|
1276
|
+
const [peers, setPeers] = useState(/* @__PURE__ */ new Map());
|
|
1277
|
+
const [latchedError, setLatchedError] = useState(null);
|
|
1278
|
+
const contextKeyRef = useRef(contextId);
|
|
1279
|
+
contextKeyRef.current = contextId;
|
|
1280
|
+
const setSourceError = useCallback(
|
|
1281
|
+
(source, err, key) => {
|
|
1282
|
+
if (key !== contextKeyRef.current) return;
|
|
1283
|
+
setLatchedError({ contextKey: key, source, error: err });
|
|
1284
|
+
},
|
|
1285
|
+
[]
|
|
1286
|
+
);
|
|
1287
|
+
const clearSourceError = useCallback((source, key) => {
|
|
1288
|
+
setLatchedError(
|
|
1289
|
+
(prev) => prev && prev.source === source && prev.contextKey === key ? null : prev
|
|
1290
|
+
);
|
|
1291
|
+
}, []);
|
|
1292
|
+
const surfaceError = useMemo(
|
|
1293
|
+
() => mero && !ephemeral ? new Error(NO_EPHEMERAL_SURFACE_MESSAGE) : null,
|
|
1294
|
+
[mero, ephemeral]
|
|
1295
|
+
);
|
|
1296
|
+
const error = surfaceError ?? (latchedError && latchedError.contextKey === contextId && !(latchedError.source === "identity" && includeSelf) ? latchedError.error : null);
|
|
1297
|
+
const receivedAtRef = useRef(/* @__PURE__ */ new Map());
|
|
1298
|
+
const codecRef = useRef(options.codec);
|
|
1299
|
+
codecRef.current = options.codec;
|
|
1300
|
+
const initialRef = useRef(options.initial);
|
|
1301
|
+
initialRef.current = options.initial;
|
|
1302
|
+
const selfRef = useRef(null);
|
|
1303
|
+
const lastLocalRef = useRef(options.initial);
|
|
1304
|
+
const pendingRef = useRef(void 0);
|
|
1305
|
+
const timerRef = useRef(null);
|
|
1306
|
+
const lastSentAtRef = useRef(Date.now());
|
|
1307
|
+
const replaySeenRef = useRef(null);
|
|
1308
|
+
const replayTimerRef = useRef(null);
|
|
1309
|
+
const ageOf = useCallback((author) => {
|
|
1310
|
+
const at = receivedAtRef.current.get(author);
|
|
1311
|
+
return at === void 0 ? void 0 : Date.now() - at;
|
|
1312
|
+
}, []);
|
|
1313
|
+
useEffect(() => {
|
|
1314
|
+
setPeers(/* @__PURE__ */ new Map());
|
|
1315
|
+
receivedAtRef.current = /* @__PURE__ */ new Map();
|
|
1316
|
+
if (timerRef.current) {
|
|
1317
|
+
clearTimeout(timerRef.current);
|
|
1318
|
+
timerRef.current = null;
|
|
1319
|
+
}
|
|
1320
|
+
if (replayTimerRef.current) {
|
|
1321
|
+
clearTimeout(replayTimerRef.current);
|
|
1322
|
+
replayTimerRef.current = null;
|
|
1323
|
+
}
|
|
1324
|
+
replaySeenRef.current = null;
|
|
1325
|
+
pendingRef.current = void 0;
|
|
1326
|
+
lastLocalRef.current = initialRef.current;
|
|
1327
|
+
selfRef.current = null;
|
|
1328
|
+
setLatchedError(null);
|
|
1329
|
+
}, [contextId]);
|
|
1330
|
+
useEffect(() => {
|
|
1331
|
+
if (!mero || !contextId) return;
|
|
1332
|
+
const key = contextId;
|
|
1333
|
+
let cancelled = false;
|
|
1334
|
+
mero.admin.getContextIdentitiesOwned(contextId).then((res) => {
|
|
1335
|
+
if (cancelled) return;
|
|
1336
|
+
const self = res.identities?.[0] ?? null;
|
|
1337
|
+
selfRef.current = self;
|
|
1338
|
+
if (!self) {
|
|
1339
|
+
setSourceError("identity", new Error(COULD_NOT_RESOLVE_IDENTITY_MESSAGE), key);
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
clearSourceError("identity", key);
|
|
1343
|
+
if (!includeSelf) {
|
|
1344
|
+
receivedAtRef.current.delete(self);
|
|
1345
|
+
setPeers((prev) => {
|
|
1346
|
+
if (!prev.has(self)) return prev;
|
|
1347
|
+
const next = new Map(prev);
|
|
1348
|
+
next.delete(self);
|
|
1349
|
+
return next;
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
}).catch((err) => {
|
|
1353
|
+
if (!cancelled) {
|
|
1354
|
+
setSourceError("identity", toError(err), key);
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
return () => {
|
|
1358
|
+
cancelled = true;
|
|
1359
|
+
};
|
|
1360
|
+
}, [mero, contextId, includeSelf, setSourceError, clearSourceError]);
|
|
1361
|
+
useEffect(() => {
|
|
1362
|
+
if (!ephemeral || !contextId) return;
|
|
1363
|
+
const closeReplayWindow = () => {
|
|
1364
|
+
replayTimerRef.current = null;
|
|
1365
|
+
const seen = replaySeenRef.current;
|
|
1366
|
+
replaySeenRef.current = null;
|
|
1367
|
+
if (!seen) return;
|
|
1368
|
+
setPeers((prev) => {
|
|
1369
|
+
let next = null;
|
|
1370
|
+
for (const author of prev.keys()) {
|
|
1371
|
+
if (seen.has(author)) continue;
|
|
1372
|
+
if (!next) next = new Map(prev);
|
|
1373
|
+
next.delete(author);
|
|
1374
|
+
receivedAtRef.current.delete(author);
|
|
1375
|
+
}
|
|
1376
|
+
return next ?? prev;
|
|
1377
|
+
});
|
|
1378
|
+
};
|
|
1379
|
+
const unsubscribe = ephemeral.subscribe(
|
|
1380
|
+
contextId,
|
|
1381
|
+
(entry) => {
|
|
1382
|
+
const { author, state } = entry;
|
|
1383
|
+
if (entry.ageMs !== void 0) {
|
|
1384
|
+
if (!replaySeenRef.current) replaySeenRef.current = /* @__PURE__ */ new Set();
|
|
1385
|
+
if (replayTimerRef.current) clearTimeout(replayTimerRef.current);
|
|
1386
|
+
replayTimerRef.current = setTimeout(closeReplayWindow, REPLAY_RECONCILE_MS);
|
|
1387
|
+
}
|
|
1388
|
+
if (entry.removed || state === void 0) {
|
|
1389
|
+
replaySeenRef.current?.delete(author);
|
|
1390
|
+
receivedAtRef.current.delete(author);
|
|
1391
|
+
setPeers((prev) => {
|
|
1392
|
+
if (!prev.has(author)) return prev;
|
|
1393
|
+
const next = new Map(prev);
|
|
1394
|
+
next.delete(author);
|
|
1395
|
+
return next;
|
|
1396
|
+
});
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (!includeSelf && author === selfRef.current) return;
|
|
1400
|
+
replaySeenRef.current?.add(author);
|
|
1401
|
+
receivedAtRef.current.set(author, Date.now() - (entry.ageMs ?? 0));
|
|
1402
|
+
setPeers((prev) => new Map(prev).set(author, state));
|
|
1403
|
+
},
|
|
1404
|
+
codecRef.current
|
|
1405
|
+
);
|
|
1406
|
+
return () => {
|
|
1407
|
+
if (replayTimerRef.current) {
|
|
1408
|
+
clearTimeout(replayTimerRef.current);
|
|
1409
|
+
replayTimerRef.current = null;
|
|
1410
|
+
}
|
|
1411
|
+
replaySeenRef.current = null;
|
|
1412
|
+
unsubscribe();
|
|
1413
|
+
};
|
|
1414
|
+
}, [ephemeral, contextId, includeSelf]);
|
|
1415
|
+
const publish = useCallback((value) => {
|
|
1416
|
+
if (!ephemeral || !contextId) return;
|
|
1417
|
+
const key = contextId;
|
|
1418
|
+
lastSentAtRef.current = Date.now();
|
|
1419
|
+
void ephemeral.set(key, value, codecRef.current).then(
|
|
1420
|
+
() => clearSourceError("publish", key),
|
|
1421
|
+
(err) => setSourceError("publish", toError(err), key)
|
|
1422
|
+
);
|
|
1423
|
+
}, [ephemeral, contextId, setSourceError, clearSourceError]);
|
|
1424
|
+
const setPresence = useCallback((partial) => {
|
|
1425
|
+
const next = { ...lastLocalRef.current ?? {}, ...partial };
|
|
1426
|
+
lastLocalRef.current = next;
|
|
1427
|
+
const throttleMs = options.throttleMs ?? 30;
|
|
1428
|
+
if (throttleMs <= 0) {
|
|
1429
|
+
publish(next);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
pendingRef.current = next;
|
|
1433
|
+
if (timerRef.current) return;
|
|
1434
|
+
const elapsed = Date.now() - lastSentAtRef.current;
|
|
1435
|
+
const delay = Math.max(throttleMs - elapsed, 0);
|
|
1436
|
+
timerRef.current = setTimeout(() => {
|
|
1437
|
+
timerRef.current = null;
|
|
1438
|
+
const queued = pendingRef.current;
|
|
1439
|
+
pendingRef.current = void 0;
|
|
1440
|
+
if (queued !== void 0) publish(queued);
|
|
1441
|
+
}, delay);
|
|
1442
|
+
}, [publish, options.throttleMs]);
|
|
1443
|
+
useEffect(() => () => {
|
|
1444
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
1445
|
+
}, []);
|
|
1446
|
+
return { peers, setPresence, ageOf, error };
|
|
1447
|
+
}
|
|
1269
1448
|
function toError(err) {
|
|
1270
1449
|
return err instanceof Error ? err : new Error(String(err));
|
|
1271
1450
|
}
|
|
@@ -1464,7 +1643,6 @@ function useGroupMembers(groupId) {
|
|
|
1464
1643
|
);
|
|
1465
1644
|
return {
|
|
1466
1645
|
members: data?.members ?? [],
|
|
1467
|
-
selfIdentity: data?.selfIdentity ?? null,
|
|
1468
1646
|
loading,
|
|
1469
1647
|
error,
|
|
1470
1648
|
refetch
|
|
@@ -1965,18 +2143,6 @@ function useSetTeeAdmissionPolicy() {
|
|
|
1965
2143
|
);
|
|
1966
2144
|
return { setTeeAdmissionPolicy, loading, error };
|
|
1967
2145
|
}
|
|
1968
|
-
function useUpdateGroupSettings() {
|
|
1969
|
-
const { mero } = useMero();
|
|
1970
|
-
const { loading, error, run } = useAsyncMutation();
|
|
1971
|
-
const updateGroupSettings = useCallback(
|
|
1972
|
-
async (groupId, request) => {
|
|
1973
|
-
if (!mero) return null;
|
|
1974
|
-
return run(() => mero.admin.updateGroupSettings(groupId, request));
|
|
1975
|
-
},
|
|
1976
|
-
[mero, run]
|
|
1977
|
-
);
|
|
1978
|
-
return { updateGroupSettings, loading, error };
|
|
1979
|
-
}
|
|
1980
2146
|
function useSetGroupMetadata() {
|
|
1981
2147
|
const { mero } = useMero();
|
|
1982
2148
|
const { loading, error, run } = useAsyncMutation();
|
|
@@ -2065,18 +2231,6 @@ function useMemberMetadata(groupId, identity) {
|
|
|
2065
2231
|
}, [run]);
|
|
2066
2232
|
return { metadata, loading, error, refetch };
|
|
2067
2233
|
}
|
|
2068
|
-
function useRegisterGroupSigningKey() {
|
|
2069
|
-
const { mero } = useMero();
|
|
2070
|
-
const { loading, error, run } = useAsyncMutation();
|
|
2071
|
-
const registerGroupSigningKey = useCallback(
|
|
2072
|
-
async (groupId, request) => {
|
|
2073
|
-
if (!mero) return null;
|
|
2074
|
-
return run(() => mero.admin.registerGroupSigningKey(groupId, request));
|
|
2075
|
-
},
|
|
2076
|
-
[mero, run]
|
|
2077
|
-
);
|
|
2078
|
-
return { registerGroupSigningKey, loading, error };
|
|
2079
|
-
}
|
|
2080
2234
|
function useUpgradeGroup() {
|
|
2081
2235
|
const { mero } = useMero();
|
|
2082
2236
|
const { loading, error, run } = useAsyncMutation();
|
|
@@ -2418,12 +2572,12 @@ function useGroupAppVersion(groupId) {
|
|
|
2418
2572
|
if (namespace) {
|
|
2419
2573
|
appKey = namespace.appKey;
|
|
2420
2574
|
applicationId = namespace.targetApplicationId;
|
|
2421
|
-
upgradePolicy = namespace.upgradePolicy;
|
|
2575
|
+
upgradePolicy = namespace.upgradePolicy ?? null;
|
|
2422
2576
|
} else {
|
|
2423
2577
|
const info = await mero.admin.getGroupInfo(groupId);
|
|
2424
2578
|
appKey = info.appKey;
|
|
2425
2579
|
applicationId = info.targetApplicationId;
|
|
2426
|
-
upgradePolicy = info.upgradePolicy;
|
|
2580
|
+
upgradePolicy = info.upgradePolicy ?? null;
|
|
2427
2581
|
activeUpgrade = info.activeUpgrade ?? null;
|
|
2428
2582
|
}
|
|
2429
2583
|
let version = null;
|
|
@@ -2608,6 +2762,6 @@ function MigrationAdminPanel({ namespaceId, pollIntervalMs, className }) {
|
|
|
2608
2762
|
] });
|
|
2609
2763
|
}
|
|
2610
2764
|
|
|
2611
|
-
export { AppMode, CalimeroLogo, ConnectButton, ConnectionType, LoginModal, MERO_CSS_VARS, MeroContext, MeroProvider, MigrationAdminPanel, MigrationPendingBanner, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, clearTokenNodeUrl, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, localStorageTokenStorage, resolveMeroTheme, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAddGroupMembers, useAppVersion, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDefaultCapabilities, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication,
|
|
2765
|
+
export { AppMode, CalimeroLogo, ConnectButton, ConnectionType, LoginModal, MERO_CSS_VARS, MeroContext, MeroProvider, MigrationAdminPanel, MigrationPendingBanner, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, clearTokenNodeUrl, cssVar, defaultMeroTheme, getApplicationId, getContextId, getContextIdentity, getNodeUrl, getTokenNodeUrl, localStorageTokenStorage, resolveMeroTheme, setApplicationId, setContextId, setContextIdentity, setNodeUrl, setTokenNodeUrl, themeToCssVars, useAddGroupMembers, useAppVersion, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDefaultCapabilities, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useEphemeral, useExecute, useGroupAppVersion, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupMetadata, useGroupUpgradeStatus, useInstallFromRegistry, useJoinContext, useJoinGroup, useJoinNamespace, useJoinSubgroupInheritance, useLatestVersion, useMemberMetadata, useMero, useMigrationStatus, useMyAuthoredMigration, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication, useRemoveGroupMembers, useReparentGroup, useResyncContext, useRetryGroupUpgrade, useSetContextMetadata, useSetDefaultCapabilities, useSetGroupMetadata, useSetMemberMetadata, useSetSubgroupVisibility, useSetTeeAdmissionPolicy, useSubgroupVisibility, useSubgroups, useSubscription, useSyncGroup, useUpdateMemberRole, useUpgradeGroup };
|
|
2612
2766
|
//# sourceMappingURL=index.js.map
|
|
2613
2767
|
//# sourceMappingURL=index.js.map
|