@calimero-network/mero-react 1.0.0-beta.1 → 1.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/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import React__default from 'react';
4
- import { MeroJs, TokenStorage } from '@calimero-network/mero-js';
5
- export { MeroJs, TokenData, TokenStorage } from '@calimero-network/mero-js';
4
+ import * as _calimero_network_mero_js from '@calimero-network/mero-js';
5
+ import { MeroJs, AddGroupMembersRequest, CreateContextRequest, CreateGroupInNamespaceRequest, CreateNamespaceRequest, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, DeleteGroupRequest, DeleteNamespaceRequest, DetachContextFromGroupRequest, GroupContextEntry, GroupInfo, CreateGroupInvitationRequest, GroupMember, GroupUpgradeStatusResponseData, JoinGroupRequest, JoinNamespaceRequest, Namespace, SubgroupEntry, NamespaceIdentity, NestGroupRequest, RegisterGroupSigningKeyRequest, RemoveGroupMembersRequest, RetryGroupUpgradeRequest, SetDefaultCapabilitiesRequest, SetDefaultVisibilityRequest, SetGroupAliasRequest, SetMemberAliasRequest, SetTeeAdmissionPolicyRequest, SseEventData, SyncGroupRequest, UnnestGroupRequest, UpdateGroupSettingsRequest, UpdateMemberRoleRequest, UpgradeGroupRequest, TokenData } from '@calimero-network/mero-js';
6
+ export * from '@calimero-network/mero-js';
6
7
 
7
8
  /**
8
9
  * Types for mero-react
@@ -39,13 +40,6 @@ interface CustomConnectionConfig {
39
40
  type: ConnectionType.Custom;
40
41
  url: string;
41
42
  }
42
- /**
43
- * Event streaming mode
44
- */
45
- declare enum EventStreamMode {
46
- WebSocket = "websocket",
47
- SSE = "sse"
48
- }
49
43
  /**
50
44
  * Context for an application
51
45
  */
@@ -62,6 +56,24 @@ interface ExecutionResult<T = unknown> {
62
56
  result?: T;
63
57
  error?: string;
64
58
  }
59
+ interface ApplicationContextRecord {
60
+ contextId: string;
61
+ applicationId: string;
62
+ }
63
+ interface ContextDiscoveryOptions {
64
+ applicationId: string;
65
+ knownContextIds?: string[];
66
+ targetAlias?: string;
67
+ pollIntervalMs?: number;
68
+ timeoutMs?: number;
69
+ }
70
+ interface ContextDiscoveryState {
71
+ context: ApplicationContextRecord | null;
72
+ loading: boolean;
73
+ error: Error | null;
74
+ discover: () => Promise<ApplicationContextRecord | null>;
75
+ reset: () => void;
76
+ }
65
77
  /**
66
78
  * Mero context value exposed by useMero hook
67
79
  */
@@ -78,6 +90,8 @@ interface MeroContextValue {
78
90
  applicationId: string | null;
79
91
  /** The context ID (from auth flow) */
80
92
  contextId: string | null;
93
+ /** The context identity / executor public key (from auth flow) */
94
+ contextIdentity: string | null;
81
95
  /** Connect to a node URL and start auth flow */
82
96
  connectToNode: (url: string) => void;
83
97
  /** Logout and clear tokens */
@@ -97,30 +111,15 @@ interface MeroProviderConfig {
97
111
  packageVersion?: string;
98
112
  /** Registry URL (optional) */
99
113
  registryUrl?: string;
100
- /** Legacy: Application ID (hash-based) */
101
- applicationId?: string;
102
- /** Application path for auth callback */
103
- applicationPath?: string;
104
- /** Event streaming mode */
105
- eventStreamMode?: EventStreamMode;
106
114
  /** Request timeout in milliseconds */
107
115
  timeoutMs?: number;
108
116
  }
109
117
 
110
- declare const MeroContext: React__default.Context<MeroContextValue>;
111
- /**
112
- * MeroProvider Props
113
- */
118
+ declare const MeroContext: React__default.Context<MeroContextValue | null>;
114
119
  interface MeroProviderProps extends MeroProviderConfig {
115
120
  children: React__default.ReactNode;
116
121
  }
117
- /**
118
- * MeroProvider - Provides MeroJs instance and auth state to the app
119
- */
120
- declare function MeroProvider({ children, mode, packageName, packageVersion, registryUrl, applicationId: propApplicationId, applicationPath, timeoutMs, }: MeroProviderProps): react_jsx_runtime.JSX.Element;
121
- /**
122
- * useMero hook - Access MeroJs and auth state
123
- */
122
+ declare function MeroProvider({ children, mode, packageName, packageVersion, registryUrl, timeoutMs, }: MeroProviderProps): react_jsx_runtime.JSX.Element;
124
123
  declare function useMero(): MeroContextValue;
125
124
 
126
125
  interface ConnectButtonProps {
@@ -151,16 +150,258 @@ interface LoginModalProps {
151
150
  */
152
151
  declare function LoginModal({ onConnect, onClose, connectionType, isOpen, }: LoginModalProps): React.ReactPortal | null;
153
152
 
153
+ /**
154
+ * Execute RPC methods against a context.
155
+ * Tracks loading/error state. Unmount-safe.
156
+ */
157
+ declare function useExecute(contextId: string | null, executorId: string | null): {
158
+ execute: <T = unknown>(method: string, params?: Record<string, unknown>) => Promise<T | null>;
159
+ loading: boolean;
160
+ error: Error | null;
161
+ };
162
+ /**
163
+ * Subscribe to SSE events for context IDs.
164
+ * StrictMode-safe: tracks the SseClient instance in a ref to avoid
165
+ * double-connect on mount/unmount/remount cycles.
166
+ */
167
+ declare function useSubscription(contextIds: string[], callback: (event: SseEventData) => void): void;
168
+ /**
169
+ * Fetch contexts for the current node, optionally filtered by application ID.
170
+ */
171
+ declare function useContexts(applicationId?: string | null): {
172
+ contexts: ApplicationContextRecord[];
173
+ loading: boolean;
174
+ error: Error | null;
175
+ refetch: () => Promise<void>;
176
+ };
177
+ declare function useApplicationContexts(applicationId?: string | null): {
178
+ contexts: ApplicationContextRecord[];
179
+ loading: boolean;
180
+ error: Error | null;
181
+ refetch: () => Promise<void>;
182
+ };
183
+ declare function useGroupMembers(groupId?: string | null): {
184
+ members: GroupMember[];
185
+ selfIdentity: string | null;
186
+ loading: boolean;
187
+ error: Error | null;
188
+ refetch: () => Promise<void>;
189
+ };
190
+ declare function useGroupContexts(groupId?: string | null): {
191
+ contexts: GroupContextEntry[];
192
+ loading: boolean;
193
+ error: Error | null;
194
+ refetch: () => Promise<void>;
195
+ };
196
+ declare function useGroupInvitations(): {
197
+ createInvitation: (groupId: string, request?: CreateGroupInvitationRequest) => Promise<_calimero_network_mero_js.CreateGroupInvitationResponseData | _calimero_network_mero_js.CreateRecursiveGroupInvitationResponseData | null>;
198
+ loading: boolean;
199
+ error: Error | null;
200
+ };
201
+ declare function useJoinGroup(): {
202
+ joinGroup: (request: JoinGroupRequest) => Promise<_calimero_network_mero_js.JoinGroupResponseData | null>;
203
+ loading: boolean;
204
+ error: Error | null;
205
+ };
206
+ declare function useGroupCapabilities(groupId?: string | null, memberId?: string | null): {
207
+ capabilities: number | null;
208
+ loading: boolean;
209
+ error: Error | null;
210
+ refetch: () => Promise<number | null>;
211
+ setCapabilities: (nextCapabilities: number) => Promise<number | null>;
212
+ };
213
+ declare function useContextDiscovery(options: ContextDiscoveryOptions): ContextDiscoveryState;
214
+ declare function useCreateContext(): {
215
+ createContext: (request: CreateContextRequest) => Promise<_calimero_network_mero_js.CreateContextResponseData | null>;
216
+ loading: boolean;
217
+ error: Error | null;
218
+ };
219
+ declare function useDeleteContext(): {
220
+ deleteContext: (contextId: string) => Promise<_calimero_network_mero_js.DeleteContextResponseData | null>;
221
+ loading: boolean;
222
+ error: Error | null;
223
+ };
224
+ declare function useJoinContext(): {
225
+ joinContext: (contextId: string) => Promise<_calimero_network_mero_js.JoinContextResponseData | null>;
226
+ loading: boolean;
227
+ error: Error | null;
228
+ };
229
+ declare function useContextGroup(contextId?: string | null): {
230
+ groupId: string | null;
231
+ loading: boolean;
232
+ error: Error | null;
233
+ refetch: () => Promise<void>;
234
+ };
235
+ declare function useGroupInfo(groupId?: string | null): {
236
+ groupInfo: GroupInfo | null;
237
+ loading: boolean;
238
+ error: Error | null;
239
+ refetch: () => Promise<void>;
240
+ };
241
+ declare function useDeleteGroup(): {
242
+ deleteGroup: (groupId: string, request?: DeleteGroupRequest) => Promise<_calimero_network_mero_js.DeleteGroupResponseData | null>;
243
+ loading: boolean;
244
+ error: Error | null;
245
+ };
246
+ declare function useSyncGroup(): {
247
+ syncGroup: (groupId: string, request?: SyncGroupRequest) => Promise<_calimero_network_mero_js.SyncGroupResponseData | null>;
248
+ loading: boolean;
249
+ error: Error | null;
250
+ };
251
+ declare function useAddGroupMembers(): {
252
+ addGroupMembers: (groupId: string, request: AddGroupMembersRequest) => Promise<void | null>;
253
+ loading: boolean;
254
+ error: Error | null;
255
+ };
256
+ declare function useRemoveGroupMembers(): {
257
+ removeGroupMembers: (groupId: string, request: RemoveGroupMembersRequest) => Promise<void | null>;
258
+ loading: boolean;
259
+ error: Error | null;
260
+ };
261
+ declare function useNamespaces(): {
262
+ namespaces: Namespace[];
263
+ loading: boolean;
264
+ error: Error | null;
265
+ refetch: () => Promise<void>;
266
+ };
267
+ declare function useNamespace(namespaceId?: string | null): {
268
+ namespace: Namespace | null;
269
+ loading: boolean;
270
+ error: Error | null;
271
+ refetch: () => Promise<void>;
272
+ };
273
+ declare function useNamespaceIdentity(namespaceId?: string | null): {
274
+ identity: NamespaceIdentity | null;
275
+ loading: boolean;
276
+ error: Error | null;
277
+ refetch: () => Promise<void>;
278
+ };
279
+ declare function useNamespacesForApplication(applicationId?: string | null): {
280
+ namespaces: Namespace[];
281
+ loading: boolean;
282
+ error: Error | null;
283
+ refetch: () => Promise<void>;
284
+ };
285
+ declare function useCreateNamespace(): {
286
+ createNamespace: (request: CreateNamespaceRequest) => Promise<_calimero_network_mero_js.CreateNamespaceResponseData | null>;
287
+ loading: boolean;
288
+ error: Error | null;
289
+ };
290
+ declare function useDeleteNamespace(): {
291
+ deleteNamespace: (namespaceId: string, request?: DeleteNamespaceRequest) => Promise<_calimero_network_mero_js.DeleteNamespaceResponseData | null>;
292
+ loading: boolean;
293
+ error: Error | null;
294
+ };
295
+ declare function useCreateNamespaceInvitation(): {
296
+ createNamespaceInvitation: (namespaceId: string, request?: CreateNamespaceInvitationRequest) => Promise<CreateNamespaceInvitationResponseData | CreateRecursiveInvitationResponseData | null>;
297
+ loading: boolean;
298
+ error: Error | null;
299
+ };
300
+ declare function useJoinNamespace(): {
301
+ joinNamespace: (namespaceId: string, request: JoinNamespaceRequest) => Promise<_calimero_network_mero_js.JoinNamespaceResponseData | null>;
302
+ loading: boolean;
303
+ error: Error | null;
304
+ };
305
+ declare function useCreateGroupInNamespace(): {
306
+ createGroupInNamespace: (namespaceId: string, request?: CreateGroupInNamespaceRequest) => Promise<_calimero_network_mero_js.CreateGroupInNamespaceResponseData | null>;
307
+ loading: boolean;
308
+ error: Error | null;
309
+ };
310
+ declare function useNamespaceGroups(namespaceId?: string | null): {
311
+ groups: SubgroupEntry[];
312
+ loading: boolean;
313
+ error: Error | null;
314
+ refetch: () => Promise<void>;
315
+ };
316
+ declare function useUpdateMemberRole(): {
317
+ updateMemberRole: (groupId: string, identity: string, request: UpdateMemberRoleRequest) => Promise<void | null>;
318
+ loading: boolean;
319
+ error: Error | null;
320
+ };
321
+ declare function useSetDefaultCapabilities(): {
322
+ setDefaultCapabilities: (groupId: string, request: SetDefaultCapabilitiesRequest) => Promise<void | null>;
323
+ loading: boolean;
324
+ error: Error | null;
325
+ };
326
+ declare function useSetDefaultVisibility(): {
327
+ setDefaultVisibility: (groupId: string, request: SetDefaultVisibilityRequest) => Promise<void | null>;
328
+ loading: boolean;
329
+ error: Error | null;
330
+ };
331
+ declare function useSetTeeAdmissionPolicy(): {
332
+ setTeeAdmissionPolicy: (groupId: string, request: SetTeeAdmissionPolicyRequest) => Promise<void | null>;
333
+ loading: boolean;
334
+ error: Error | null;
335
+ };
336
+ declare function useUpdateGroupSettings(): {
337
+ updateGroupSettings: (groupId: string, request: UpdateGroupSettingsRequest) => Promise<void | null>;
338
+ loading: boolean;
339
+ error: Error | null;
340
+ };
341
+ declare function useSetGroupAlias(): {
342
+ setGroupAlias: (groupId: string, request: SetGroupAliasRequest) => Promise<void | null>;
343
+ loading: boolean;
344
+ error: Error | null;
345
+ };
346
+ declare function useSetMemberAlias(): {
347
+ setMemberAlias: (groupId: string, identity: string, request: SetMemberAliasRequest) => Promise<void | null>;
348
+ loading: boolean;
349
+ error: Error | null;
350
+ };
351
+ declare function useRegisterGroupSigningKey(): {
352
+ registerGroupSigningKey: (groupId: string, request: RegisterGroupSigningKeyRequest) => Promise<_calimero_network_mero_js.RegisterGroupSigningKeyResponseData | null>;
353
+ loading: boolean;
354
+ error: Error | null;
355
+ };
356
+ declare function useUpgradeGroup(): {
357
+ upgradeGroup: (groupId: string, request: UpgradeGroupRequest) => Promise<_calimero_network_mero_js.UpgradeGroupResponseData | null>;
358
+ loading: boolean;
359
+ error: Error | null;
360
+ };
361
+ declare function useGroupUpgradeStatus(groupId?: string | null): {
362
+ upgradeStatus: GroupUpgradeStatusResponseData;
363
+ loading: boolean;
364
+ error: Error | null;
365
+ refetch: () => Promise<void>;
366
+ };
367
+ declare function useRetryGroupUpgrade(): {
368
+ retryGroupUpgrade: (groupId: string, request?: RetryGroupUpgradeRequest) => Promise<_calimero_network_mero_js.UpgradeGroupResponseData | null>;
369
+ loading: boolean;
370
+ error: Error | null;
371
+ };
372
+ declare function useNestGroup(): {
373
+ nestGroup: (parentGroupId: string, request: NestGroupRequest) => Promise<void | null>;
374
+ loading: boolean;
375
+ error: Error | null;
376
+ };
377
+ declare function useUnnestGroup(): {
378
+ unnestGroup: (parentGroupId: string, request: UnnestGroupRequest) => Promise<void | null>;
379
+ loading: boolean;
380
+ error: Error | null;
381
+ };
382
+ declare function useSubgroups(groupId?: string | null): {
383
+ subgroups: SubgroupEntry[];
384
+ loading: boolean;
385
+ error: Error | null;
386
+ refetch: () => Promise<void>;
387
+ };
388
+ declare function useDetachContextFromGroup(): {
389
+ detachContextFromGroup: (groupId: string, contextId: string, request?: DetachContextFromGroupRequest) => Promise<void | null>;
390
+ loading: boolean;
391
+ error: Error | null;
392
+ };
393
+
154
394
  /**
155
395
  * Storage utilities for mero-react
156
396
  *
157
397
  * Provides localStorage-based token storage and other persistence utilities.
158
398
  */
159
399
 
160
- /**
161
- * localStorage-based TokenStorage implementation for MeroJs
162
- */
163
- declare const localStorageTokenStorage: TokenStorage;
400
+ declare const localStorageTokenStorage: {
401
+ get(): Promise<TokenData | null>;
402
+ set(token: TokenData): Promise<void>;
403
+ clear(): Promise<void>;
404
+ };
164
405
  /**
165
406
  * Get the stored node URL
166
407
  */
@@ -185,9 +426,33 @@ declare function setApplicationId(id: string): void;
185
426
  * Clear the application ID
186
427
  */
187
428
  declare function clearApplicationId(): void;
429
+ /**
430
+ * Get the stored context ID
431
+ */
432
+ declare function getContextId(): string | null;
433
+ /**
434
+ * Set the context ID
435
+ */
436
+ declare function setContextId(id: string): void;
437
+ /**
438
+ * Clear the context ID
439
+ */
440
+ declare function clearContextId(): void;
441
+ /**
442
+ * Get the stored context identity
443
+ */
444
+ declare function getContextIdentity(): string | null;
445
+ /**
446
+ * Set the context identity
447
+ */
448
+ declare function setContextIdentity(id: string): void;
449
+ /**
450
+ * Clear the context identity
451
+ */
452
+ declare function clearContextIdentity(): void;
188
453
  /**
189
454
  * Clear all mero-react storage
190
455
  */
191
456
  declare function clearAllStorage(): void;
192
457
 
193
- export { type AppContext, AppMode, ConnectButton, type ConnectButtonProps, ConnectionType, type CustomConnectionConfig, EventStreamMode, type ExecutionResult, LoginModal, type LoginModalProps, MeroContext, type MeroContextValue, MeroProvider, type MeroProviderConfig, type MeroProviderProps, clearAllStorage, clearApplicationId, clearNodeUrl, getApplicationId, getNodeUrl, localStorageTokenStorage, setApplicationId, setNodeUrl, useMero };
458
+ export { type AppContext, AppMode, type ApplicationContextRecord, ConnectButton, type ConnectButtonProps, ConnectionType, type ContextDiscoveryOptions, type ContextDiscoveryState, type CustomConnectionConfig, type ExecutionResult, LoginModal, type LoginModalProps, MeroContext, type MeroContextValue, MeroProvider, type MeroProviderConfig, type MeroProviderProps, clearAllStorage, clearApplicationId, clearContextId, clearContextIdentity, clearNodeUrl, getApplicationId, getContextId, getContextIdentity, getNodeUrl, localStorageTokenStorage, setApplicationId, setContextId, setContextIdentity, setNodeUrl, useAddGroupMembers, useApplicationContexts, useContextDiscovery, useContextGroup, useContexts, useCreateContext, useCreateGroupInNamespace, useCreateNamespace, useCreateNamespaceInvitation, useDeleteContext, useDeleteGroup, useDeleteNamespace, useDetachContextFromGroup, useExecute, useGroupCapabilities, useGroupContexts, useGroupInfo, useGroupInvitations, useGroupMembers, useGroupUpgradeStatus, useJoinContext, useJoinGroup, useJoinNamespace, useMero, useNamespace, useNamespaceGroups, useNamespaceIdentity, useNamespaces, useNamespacesForApplication, useNestGroup, useRegisterGroupSigningKey, useRemoveGroupMembers, useRetryGroupUpgrade, useSetDefaultCapabilities, useSetDefaultVisibility, useSetGroupAlias, useSetMemberAlias, useSetTeeAdmissionPolicy, useSubgroups, useSubscription, useSyncGroup, useUnnestGroup, useUpdateGroupSettings, useUpdateMemberRole, useUpgradeGroup };