@massalabs/gossip-sdk 0.0.2-dev.20260128094509 → 0.0.2-dev.20260128160824

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.
Files changed (148) hide show
  1. package/dist/api/messageProtocol/index.d.ts +19 -0
  2. package/dist/api/messageProtocol/index.js +26 -0
  3. package/dist/api/messageProtocol/mock.d.ts +12 -0
  4. package/{src/api/messageProtocol/mock.ts → dist/api/messageProtocol/mock.js} +2 -3
  5. package/dist/api/messageProtocol/rest.d.ts +22 -0
  6. package/dist/api/messageProtocol/rest.js +161 -0
  7. package/dist/api/messageProtocol/types.d.ts +61 -0
  8. package/dist/api/messageProtocol/types.js +6 -0
  9. package/dist/assets/generated/wasm/README.md +281 -0
  10. package/dist/assets/generated/wasm/gossip_wasm.d.ts +638 -0
  11. package/dist/assets/generated/wasm/gossip_wasm.js +1557 -0
  12. package/dist/assets/generated/wasm/gossip_wasm_bg.wasm +0 -0
  13. package/dist/assets/generated/wasm/gossip_wasm_bg.wasm.d.ts +164 -0
  14. package/dist/assets/generated/wasm/package.json +15 -0
  15. package/dist/assets/generated/wasm-node/README.md +281 -0
  16. package/dist/assets/generated/wasm-node/gossip_wasm.d.ts +443 -0
  17. package/dist/assets/generated/wasm-node/gossip_wasm.js +1488 -0
  18. package/dist/assets/generated/wasm-node/gossip_wasm_bg.wasm +0 -0
  19. package/dist/assets/generated/wasm-node/gossip_wasm_bg.wasm.d.ts +164 -0
  20. package/dist/assets/generated/wasm-node/package.json +11 -0
  21. package/dist/config/protocol.d.ts +36 -0
  22. package/dist/config/protocol.js +77 -0
  23. package/dist/config/sdk.d.ts +82 -0
  24. package/dist/config/sdk.js +55 -0
  25. package/{src/contacts.ts → dist/contacts.d.ts} +11 -95
  26. package/dist/contacts.js +166 -0
  27. package/dist/core/SdkEventEmitter.d.ts +36 -0
  28. package/dist/core/SdkEventEmitter.js +59 -0
  29. package/dist/core/SdkPolling.d.ts +35 -0
  30. package/dist/core/SdkPolling.js +100 -0
  31. package/{src/core/index.ts → dist/core/index.d.ts} +0 -2
  32. package/dist/core/index.js +5 -0
  33. package/dist/crypto/bip39.d.ts +34 -0
  34. package/dist/crypto/bip39.js +62 -0
  35. package/dist/crypto/encryption.d.ts +37 -0
  36. package/dist/crypto/encryption.js +46 -0
  37. package/dist/db.d.ts +190 -0
  38. package/dist/db.js +311 -0
  39. package/dist/gossipSdk.d.ts +274 -0
  40. package/dist/gossipSdk.js +690 -0
  41. package/dist/index.d.ts +59 -0
  42. package/dist/index.js +61 -0
  43. package/dist/services/announcement.d.ts +43 -0
  44. package/dist/services/announcement.js +491 -0
  45. package/dist/services/auth.d.ts +37 -0
  46. package/dist/services/auth.js +76 -0
  47. package/dist/services/discussion.d.ts +63 -0
  48. package/dist/services/discussion.js +297 -0
  49. package/dist/services/message.d.ts +74 -0
  50. package/dist/services/message.js +826 -0
  51. package/dist/services/refresh.d.ts +41 -0
  52. package/dist/services/refresh.js +205 -0
  53. package/{src/sw.ts → dist/sw.d.ts} +1 -8
  54. package/dist/sw.js +10 -0
  55. package/dist/types/events.d.ts +80 -0
  56. package/dist/types/events.js +7 -0
  57. package/dist/types.d.ts +32 -0
  58. package/dist/types.js +7 -0
  59. package/dist/utils/base64.d.ts +10 -0
  60. package/dist/utils/base64.js +30 -0
  61. package/dist/utils/contacts.d.ts +42 -0
  62. package/dist/utils/contacts.js +113 -0
  63. package/dist/utils/discussions.d.ts +24 -0
  64. package/dist/utils/discussions.js +38 -0
  65. package/dist/utils/logs.d.ts +19 -0
  66. package/dist/utils/logs.js +89 -0
  67. package/dist/utils/messageSerialization.d.ts +64 -0
  68. package/dist/utils/messageSerialization.js +184 -0
  69. package/dist/utils/queue.d.ts +50 -0
  70. package/dist/utils/queue.js +110 -0
  71. package/dist/utils/type.d.ts +10 -0
  72. package/dist/utils/type.js +4 -0
  73. package/dist/utils/userId.d.ts +40 -0
  74. package/dist/utils/userId.js +90 -0
  75. package/dist/utils/validation.d.ts +50 -0
  76. package/dist/utils/validation.js +112 -0
  77. package/dist/utils.d.ts +30 -0
  78. package/{src/utils.ts → dist/utils.js} +9 -19
  79. package/dist/wasm/encryption.d.ts +56 -0
  80. package/{src/wasm/encryption.ts → dist/wasm/encryption.js} +22 -51
  81. package/dist/wasm/index.d.ts +10 -0
  82. package/{src/wasm/index.ts → dist/wasm/index.js} +1 -8
  83. package/dist/wasm/loader.d.ts +22 -0
  84. package/dist/wasm/loader.js +78 -0
  85. package/dist/wasm/session.d.ts +85 -0
  86. package/dist/wasm/session.js +226 -0
  87. package/dist/wasm/userKeys.d.ts +17 -0
  88. package/{src/wasm/userKeys.ts → dist/wasm/userKeys.js} +6 -13
  89. package/package.json +15 -2
  90. package/src/api/messageProtocol/index.ts +0 -53
  91. package/src/api/messageProtocol/rest.ts +0 -209
  92. package/src/api/messageProtocol/types.ts +0 -70
  93. package/src/config/protocol.ts +0 -97
  94. package/src/config/sdk.ts +0 -131
  95. package/src/core/SdkEventEmitter.ts +0 -91
  96. package/src/core/SdkPolling.ts +0 -134
  97. package/src/crypto/bip39.ts +0 -84
  98. package/src/crypto/encryption.ts +0 -77
  99. package/src/db.ts +0 -465
  100. package/src/gossipSdk.ts +0 -994
  101. package/src/index.ts +0 -211
  102. package/src/services/announcement.ts +0 -653
  103. package/src/services/auth.ts +0 -95
  104. package/src/services/discussion.ts +0 -380
  105. package/src/services/message.ts +0 -1055
  106. package/src/services/refresh.ts +0 -234
  107. package/src/types/events.ts +0 -108
  108. package/src/types.ts +0 -70
  109. package/src/utils/base64.ts +0 -39
  110. package/src/utils/contacts.ts +0 -161
  111. package/src/utils/discussions.ts +0 -55
  112. package/src/utils/logs.ts +0 -86
  113. package/src/utils/messageSerialization.ts +0 -257
  114. package/src/utils/queue.ts +0 -106
  115. package/src/utils/type.ts +0 -7
  116. package/src/utils/userId.ts +0 -114
  117. package/src/utils/validation.ts +0 -144
  118. package/src/wasm/loader.ts +0 -123
  119. package/src/wasm/session.ts +0 -276
  120. package/test/config/protocol.spec.ts +0 -31
  121. package/test/config/sdk.spec.ts +0 -163
  122. package/test/db/helpers.spec.ts +0 -142
  123. package/test/db/operations.spec.ts +0 -128
  124. package/test/db/states.spec.ts +0 -535
  125. package/test/integration/discussion-flow.spec.ts +0 -422
  126. package/test/integration/messaging-flow.spec.ts +0 -708
  127. package/test/integration/sdk-lifecycle.spec.ts +0 -325
  128. package/test/mocks/index.ts +0 -9
  129. package/test/mocks/mockMessageProtocol.ts +0 -100
  130. package/test/services/auth.spec.ts +0 -311
  131. package/test/services/discussion.spec.ts +0 -279
  132. package/test/services/message-deduplication.spec.ts +0 -299
  133. package/test/services/message-startup.spec.ts +0 -331
  134. package/test/services/message.spec.ts +0 -817
  135. package/test/services/refresh.spec.ts +0 -199
  136. package/test/services/session-status.spec.ts +0 -349
  137. package/test/session/wasm.spec.ts +0 -227
  138. package/test/setup.ts +0 -52
  139. package/test/utils/contacts.spec.ts +0 -156
  140. package/test/utils/discussions.spec.ts +0 -66
  141. package/test/utils/queue.spec.ts +0 -52
  142. package/test/utils/serialization.spec.ts +0 -120
  143. package/test/utils/userId.spec.ts +0 -120
  144. package/test/utils/validation.spec.ts +0 -223
  145. package/test/utils.ts +0 -212
  146. package/tsconfig.json +0 -26
  147. package/tsconfig.tsbuildinfo +0 -1
  148. package/vitest.config.ts +0 -28
@@ -0,0 +1,164 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_announcementresult_free: (a: number, b: number) => void;
5
+ export const __wbg_encryptionkey_free: (a: number, b: number) => void;
6
+ export const __wbg_nonce_free: (a: number, b: number) => void;
7
+ export const __wbg_receivemessageoutput_free: (a: number, b: number) => void;
8
+ export const __wbg_sendmessageoutput_free: (a: number, b: number) => void;
9
+ export const __wbg_sessionconfig_free: (a: number, b: number) => void;
10
+ export const __wbg_sessionmanagerwrapper_free: (a: number, b: number) => void;
11
+ export const __wbg_userkeys_free: (a: number, b: number) => void;
12
+ export const __wbg_userpublickeys_free: (a: number, b: number) => void;
13
+ export const __wbg_usersecretkeys_free: (a: number, b: number) => void;
14
+ export const aead_decrypt: (
15
+ a: number,
16
+ b: number,
17
+ c: number,
18
+ d: number,
19
+ e: number,
20
+ f: number
21
+ ) => [number, number];
22
+ export const aead_encrypt: (
23
+ a: number,
24
+ b: number,
25
+ c: number,
26
+ d: number,
27
+ e: number,
28
+ f: number
29
+ ) => [number, number];
30
+ export const announcementresult_announcer_public_keys: (a: number) => number;
31
+ export const announcementresult_timestamp: (a: number) => number;
32
+ export const announcementresult_user_data: (a: number) => [number, number];
33
+ export const encryptionkey_from_bytes: (
34
+ a: number,
35
+ b: number
36
+ ) => [number, number, number];
37
+ export const encryptionkey_from_seed: (
38
+ a: number,
39
+ b: number,
40
+ c: number,
41
+ d: number
42
+ ) => [number, number, number];
43
+ export const encryptionkey_generate: () => number;
44
+ export const encryptionkey_to_bytes: (a: number) => [number, number];
45
+ export const generate_user_keys: (
46
+ a: number,
47
+ b: number
48
+ ) => [number, number, number];
49
+ export const nonce_from_bytes: (
50
+ a: number,
51
+ b: number
52
+ ) => [number, number, number];
53
+ export const nonce_generate: () => number;
54
+ export const nonce_to_bytes: (a: number) => [number, number];
55
+ export const receivemessageoutput_acknowledged_seekers: (a: number) => any;
56
+ export const receivemessageoutput_message: (a: number) => [number, number];
57
+ export const receivemessageoutput_timestamp: (a: number) => number;
58
+ export const receivemessageoutput_user_id: (a: number) => [number, number];
59
+ export const sendmessageoutput_data: (a: number) => [number, number];
60
+ export const sendmessageoutput_seeker: (a: number) => [number, number];
61
+ export const sessionconfig_new: (
62
+ a: number,
63
+ b: number,
64
+ c: number,
65
+ d: number,
66
+ e: number,
67
+ f: number,
68
+ g: bigint
69
+ ) => number;
70
+ export const sessionconfig_new_default: () => number;
71
+ export const sessionmanagerwrapper_establish_outgoing_session: (
72
+ a: number,
73
+ b: number,
74
+ c: number,
75
+ d: number,
76
+ e: number,
77
+ f: number
78
+ ) => [number, number];
79
+ export const sessionmanagerwrapper_feed_incoming_announcement: (
80
+ a: number,
81
+ b: number,
82
+ c: number,
83
+ d: number,
84
+ e: number
85
+ ) => number;
86
+ export const sessionmanagerwrapper_feed_incoming_message_board_read: (
87
+ a: number,
88
+ b: number,
89
+ c: number,
90
+ d: number,
91
+ e: number,
92
+ f: number
93
+ ) => number;
94
+ export const sessionmanagerwrapper_from_encrypted_blob: (
95
+ a: number,
96
+ b: number,
97
+ c: number
98
+ ) => [number, number, number];
99
+ export const sessionmanagerwrapper_get_message_board_read_keys: (
100
+ a: number
101
+ ) => any;
102
+ export const sessionmanagerwrapper_new: (a: number) => number;
103
+ export const sessionmanagerwrapper_peer_discard: (
104
+ a: number,
105
+ b: number,
106
+ c: number
107
+ ) => [number, number];
108
+ export const sessionmanagerwrapper_peer_list: (a: number) => any;
109
+ export const sessionmanagerwrapper_peer_session_status: (
110
+ a: number,
111
+ b: number,
112
+ c: number
113
+ ) => [number, number, number];
114
+ export const sessionmanagerwrapper_refresh: (a: number) => any;
115
+ export const sessionmanagerwrapper_send_message: (
116
+ a: number,
117
+ b: number,
118
+ c: number,
119
+ d: number,
120
+ e: number
121
+ ) => [number, number, number];
122
+ export const sessionmanagerwrapper_to_encrypted_blob: (
123
+ a: number,
124
+ b: number
125
+ ) => [number, number, number, number];
126
+ export const userkeys_public_keys: (a: number) => [number, number, number];
127
+ export const userkeys_secret_keys: (a: number) => [number, number, number];
128
+ export const userpublickeys_derive_id: (a: number) => [number, number];
129
+ export const userpublickeys_dsa_verification_key: (
130
+ a: number
131
+ ) => [number, number];
132
+ export const userpublickeys_from_bytes: (
133
+ a: number,
134
+ b: number
135
+ ) => [number, number, number];
136
+ export const userpublickeys_kem_public_key: (a: number) => [number, number];
137
+ export const userpublickeys_massa_public_key: (a: number) => [number, number];
138
+ export const userpublickeys_to_bytes: (
139
+ a: number
140
+ ) => [number, number, number, number];
141
+ export const usersecretkeys_dsa_signing_key: (a: number) => [number, number];
142
+ export const usersecretkeys_from_bytes: (
143
+ a: number,
144
+ b: number
145
+ ) => [number, number, number];
146
+ export const usersecretkeys_kem_secret_key: (a: number) => [number, number];
147
+ export const usersecretkeys_massa_secret_key: (a: number) => [number, number];
148
+ export const usersecretkeys_to_bytes: (
149
+ a: number
150
+ ) => [number, number, number, number];
151
+ export const start: () => void;
152
+ export const __wbindgen_exn_store: (a: number) => void;
153
+ export const __externref_table_alloc: () => number;
154
+ export const __wbindgen_export_2: WebAssembly.Table;
155
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
156
+ export const __wbindgen_malloc: (a: number, b: number) => number;
157
+ export const __wbindgen_realloc: (
158
+ a: number,
159
+ b: number,
160
+ c: number,
161
+ d: number
162
+ ) => number;
163
+ export const __externref_table_dealloc: (a: number) => void;
164
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "gossip-wasm",
3
+ "version": "0.1.0",
4
+ "files": [
5
+ "gossip_wasm_bg.wasm",
6
+ "gossip_wasm.js",
7
+ "gossip_wasm.d.ts"
8
+ ],
9
+ "main": "gossip_wasm.js",
10
+ "types": "gossip_wasm.d.ts"
11
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Protocol API Configuration
3
+ *
4
+ * Centralized configuration for the message protocol API endpoints.
5
+ * This allows easy switching between different protocol implementations.
6
+ */
7
+ export interface ProtocolConfig {
8
+ baseUrl: string;
9
+ timeout: number;
10
+ retryAttempts: number;
11
+ }
12
+ export declare const protocolConfig: ProtocolConfig;
13
+ export declare enum MessageProtocolType {
14
+ REST = "rest",
15
+ MOCK = "mock"
16
+ }
17
+ export declare const defaultMessageProtocol: MessageProtocolType;
18
+ /**
19
+ * Set the base URL for the protocol API at runtime.
20
+ * This overrides environment variables and defaults.
21
+ *
22
+ * @param baseUrl - The base URL to use (e.g., 'https://api.example.com/api')
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { setProtocolBaseUrl } from 'gossip-sdk';
27
+ *
28
+ * // Set custom API endpoint
29
+ * setProtocolBaseUrl('https://my-server.com/api');
30
+ * ```
31
+ */
32
+ export declare function setProtocolBaseUrl(baseUrl: string): void;
33
+ /**
34
+ * Reset the base URL to use environment variables or defaults.
35
+ */
36
+ export declare function resetProtocolBaseUrl(): void;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Protocol API Configuration
3
+ *
4
+ * Centralized configuration for the message protocol API endpoints.
5
+ * This allows easy switching between different protocol implementations.
6
+ */
7
+ // Default API URL for the hosted REST protocol.
8
+ // Override via setProtocolBaseUrl() or environment variables.
9
+ const DEFAULT_API_URL = 'https://api.usegossip.com';
10
+ // Mutable config that can be updated at runtime
11
+ let currentBaseUrl = null;
12
+ function buildProtocolApiBaseUrl() {
13
+ // If runtime override is set, use it
14
+ if (currentBaseUrl !== null) {
15
+ return currentBaseUrl;
16
+ }
17
+ // Try to get from environment variable (Vite)
18
+ let apiUrl;
19
+ try {
20
+ // Check if import.meta.env is available (Vite environment)
21
+ if (typeof import.meta !== 'undefined' &&
22
+ import.meta.env?.VITE_GOSSIP_API_URL) {
23
+ apiUrl = import.meta.env.VITE_GOSSIP_API_URL;
24
+ }
25
+ }
26
+ catch {
27
+ // import.meta.env not available (Node.js without Vite)
28
+ }
29
+ // Check process.env for Node.js environment
30
+ if (!apiUrl &&
31
+ typeof process !== 'undefined' &&
32
+ process.env?.GOSSIP_API_URL) {
33
+ apiUrl = process.env.GOSSIP_API_URL;
34
+ }
35
+ // Fall back to default
36
+ if (!apiUrl)
37
+ apiUrl = DEFAULT_API_URL;
38
+ // Normalize trailing slashes to avoid `//api`
39
+ const trimmed = apiUrl.replace(/\/+$/, '');
40
+ return `${trimmed}/api`;
41
+ }
42
+ export const protocolConfig = {
43
+ get baseUrl() {
44
+ return buildProtocolApiBaseUrl();
45
+ },
46
+ timeout: 10000,
47
+ retryAttempts: 3,
48
+ };
49
+ export var MessageProtocolType;
50
+ (function (MessageProtocolType) {
51
+ MessageProtocolType["REST"] = "rest";
52
+ MessageProtocolType["MOCK"] = "mock";
53
+ })(MessageProtocolType || (MessageProtocolType = {}));
54
+ export const defaultMessageProtocol = MessageProtocolType.REST;
55
+ /**
56
+ * Set the base URL for the protocol API at runtime.
57
+ * This overrides environment variables and defaults.
58
+ *
59
+ * @param baseUrl - The base URL to use (e.g., 'https://api.example.com/api')
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { setProtocolBaseUrl } from 'gossip-sdk';
64
+ *
65
+ * // Set custom API endpoint
66
+ * setProtocolBaseUrl('https://my-server.com/api');
67
+ * ```
68
+ */
69
+ export function setProtocolBaseUrl(baseUrl) {
70
+ currentBaseUrl = baseUrl;
71
+ }
72
+ /**
73
+ * Reset the base URL to use environment variables or defaults.
74
+ */
75
+ export function resetProtocolBaseUrl() {
76
+ currentBaseUrl = null;
77
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * SDK Configuration
3
+ *
4
+ * Centralized configuration for the Gossip SDK.
5
+ * All values have sensible defaults that can be overridden.
6
+ */
7
+ /**
8
+ * Protocol configuration for network requests
9
+ */
10
+ export interface ProtocolConfig {
11
+ /** API base URL (default: from environment or https://api.usegossip.com) */
12
+ baseUrl?: string;
13
+ /** Request timeout in milliseconds (default: 10000) */
14
+ timeout: number;
15
+ /** Number of retry attempts for failed requests (default: 3) */
16
+ retryAttempts: number;
17
+ }
18
+ /**
19
+ * Polling configuration for automatic message/announcement fetching
20
+ */
21
+ export interface PollingConfig {
22
+ /** Enable automatic polling (default: false) */
23
+ enabled: boolean;
24
+ /** Interval for fetching messages in milliseconds (default: 5000) */
25
+ messagesIntervalMs: number;
26
+ /** Interval for fetching announcements in milliseconds (default: 10000) */
27
+ announcementsIntervalMs: number;
28
+ /** Interval for session refresh/keep-alive in milliseconds (default: 30000) */
29
+ sessionRefreshIntervalMs: number;
30
+ }
31
+ /**
32
+ * Message fetching configuration
33
+ */
34
+ export interface MessagesConfig {
35
+ /** Delay between fetch iterations in milliseconds (default: 100) */
36
+ fetchDelayMs: number;
37
+ /** Maximum number of fetch iterations per call (default: 30) */
38
+ maxFetchIterations: number;
39
+ /**
40
+ * Time window in milliseconds for duplicate detection (default: 30000 = 30 seconds).
41
+ * Messages with same content from same sender within this window are considered duplicates.
42
+ * This handles edge case where app crashes after network send but before DB update,
43
+ * resulting in message being re-sent on restart.
44
+ */
45
+ deduplicationWindowMs: number;
46
+ }
47
+ /**
48
+ * Announcement configuration
49
+ */
50
+ export interface AnnouncementsConfig {
51
+ /** Maximum announcements to fetch per request (default: 500) */
52
+ fetchLimit: number;
53
+ /** Time before marking failed announcements as broken in ms (default: 3600000 = 1 hour) */
54
+ brokenThresholdMs: number;
55
+ }
56
+ /**
57
+ * Complete SDK configuration
58
+ */
59
+ export interface SdkConfig {
60
+ /** Network/protocol settings */
61
+ protocol: ProtocolConfig;
62
+ /** Automatic polling settings */
63
+ polling: PollingConfig;
64
+ /** Message fetching settings */
65
+ messages: MessagesConfig;
66
+ /** Announcement settings */
67
+ announcements: AnnouncementsConfig;
68
+ }
69
+ /**
70
+ * Default SDK configuration values
71
+ */
72
+ export declare const defaultSdkConfig: SdkConfig;
73
+ /**
74
+ * Deep merge partial config with defaults
75
+ */
76
+ export declare function mergeConfig(partial?: DeepPartial<SdkConfig>): SdkConfig;
77
+ /**
78
+ * Helper type for deep partial objects
79
+ */
80
+ export type DeepPartial<T> = {
81
+ [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
82
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * SDK Configuration
3
+ *
4
+ * Centralized configuration for the Gossip SDK.
5
+ * All values have sensible defaults that can be overridden.
6
+ */
7
+ /**
8
+ * Default SDK configuration values
9
+ */
10
+ export const defaultSdkConfig = {
11
+ protocol: {
12
+ timeout: 10000,
13
+ retryAttempts: 3,
14
+ },
15
+ polling: {
16
+ enabled: false,
17
+ messagesIntervalMs: 5000,
18
+ announcementsIntervalMs: 10000,
19
+ sessionRefreshIntervalMs: 30000,
20
+ },
21
+ messages: {
22
+ fetchDelayMs: 100,
23
+ maxFetchIterations: 30,
24
+ deduplicationWindowMs: 30000, // 30 seconds
25
+ },
26
+ announcements: {
27
+ fetchLimit: 500,
28
+ brokenThresholdMs: 60 * 60 * 1000, // 1 hour
29
+ },
30
+ };
31
+ /**
32
+ * Deep merge partial config with defaults
33
+ */
34
+ export function mergeConfig(partial) {
35
+ if (!partial)
36
+ return { ...defaultSdkConfig };
37
+ return {
38
+ protocol: {
39
+ ...defaultSdkConfig.protocol,
40
+ ...partial.protocol,
41
+ },
42
+ polling: {
43
+ ...defaultSdkConfig.polling,
44
+ ...partial.polling,
45
+ },
46
+ messages: {
47
+ ...defaultSdkConfig.messages,
48
+ ...partial.messages,
49
+ },
50
+ announcements: {
51
+ ...defaultSdkConfig.announcements,
52
+ ...partial.announcements,
53
+ },
54
+ };
55
+ }
@@ -17,22 +17,11 @@
17
17
  * await deleteContact(userId, contactUserId);
18
18
  * ```
19
19
  */
20
-
21
- import {
22
- updateContactName as updateContactNameUtil,
23
- deleteContact as deleteContactUtil,
24
- } from './utils/contacts';
25
20
  import { type Contact, type GossipDatabase } from './db';
26
- import type {
27
- UpdateContactNameResult,
28
- DeleteContactResult,
29
- } from './utils/contacts';
30
- import type { UserPublicKeys } from './assets/generated/wasm/gossip_wasm';
21
+ import type { UpdateContactNameResult, DeleteContactResult } from './utils/contacts';
22
+ import type { UserPublicKeys } from '#wasm';
31
23
  import type { SessionModule } from './wasm/session';
32
-
33
- // Re-export result types
34
24
  export type { UpdateContactNameResult, DeleteContactResult };
35
-
36
25
  /**
37
26
  * Get all contacts for an owner.
38
27
  *
@@ -46,18 +35,7 @@ export type { UpdateContactNameResult, DeleteContactResult };
46
35
  * contacts.forEach(c => console.log(c.name, c.userId));
47
36
  * ```
48
37
  */
49
- export async function getContacts(
50
- ownerUserId: string,
51
- db: GossipDatabase
52
- ): Promise<Contact[]> {
53
- try {
54
- return await db.getContactsByOwner(ownerUserId);
55
- } catch (error) {
56
- console.error('Error getting contacts:', error);
57
- return [];
58
- }
59
- }
60
-
38
+ export declare function getContacts(ownerUserId: string, db: GossipDatabase): Promise<Contact[]>;
61
39
  /**
62
40
  * Get a specific contact by owner and contact user IDs.
63
41
  *
@@ -74,23 +52,7 @@ export async function getContacts(
74
52
  * }
75
53
  * ```
76
54
  */
77
- export async function getContact(
78
- ownerUserId: string,
79
- contactUserId: string,
80
- db: GossipDatabase
81
- ): Promise<Contact | null> {
82
- try {
83
- const contact = await db.getContactByOwnerAndUserId(
84
- ownerUserId,
85
- contactUserId
86
- );
87
- return contact ?? null;
88
- } catch (error) {
89
- console.error('Error getting contact:', error);
90
- return null;
91
- }
92
- }
93
-
55
+ export declare function getContact(ownerUserId: string, contactUserId: string, db: GossipDatabase): Promise<Contact | null>;
94
56
  /**
95
57
  * Add a new contact.
96
58
  *
@@ -117,42 +79,11 @@ export async function getContact(
117
79
  * }
118
80
  * ```
119
81
  */
120
- export async function addContact(
121
- ownerUserId: string,
122
- userId: string,
123
- name: string,
124
- publicKeys: UserPublicKeys,
125
- db: GossipDatabase
126
- ): Promise<{ success: boolean; error?: string; contact?: Contact }> {
127
- try {
128
- // Check if contact already exists
129
- const existing = await db.getContactByOwnerAndUserId(ownerUserId, userId);
130
- if (existing) {
131
- return { success: false, error: 'Contact already exists' };
132
- }
133
-
134
- const contact: Contact = {
135
- ownerUserId,
136
- userId,
137
- name,
138
- publicKeys: publicKeys.to_bytes(),
139
- isOnline: false,
140
- lastSeen: new Date(),
141
- createdAt: new Date(),
142
- };
143
-
144
- const id = await db.contacts.add(contact);
145
- const newContact = await db.contacts.get(id);
146
- return { success: true, contact: newContact };
147
- } catch (error) {
148
- console.error('Error adding contact:', error);
149
- return {
150
- success: false,
151
- error: error instanceof Error ? error.message : 'Unknown error',
152
- };
153
- }
154
- }
155
-
82
+ export declare function addContact(ownerUserId: string, userId: string, name: string, publicKeys: UserPublicKeys, db: GossipDatabase): Promise<{
83
+ success: boolean;
84
+ error?: string;
85
+ contact?: Contact;
86
+ }>;
156
87
  /**
157
88
  * Update contact name.
158
89
  *
@@ -172,15 +103,7 @@ export async function addContact(
172
103
  * }
173
104
  * ```
174
105
  */
175
- export async function updateContactName(
176
- ownerUserId: string,
177
- contactUserId: string,
178
- newName: string,
179
- db: GossipDatabase
180
- ): Promise<UpdateContactNameResult> {
181
- return await updateContactNameUtil(ownerUserId, contactUserId, newName, db);
182
- }
183
-
106
+ export declare function updateContactName(ownerUserId: string, contactUserId: string, newName: string, db: GossipDatabase): Promise<UpdateContactNameResult>;
184
107
  /**
185
108
  * Delete a contact and all associated discussions and messages.
186
109
  *
@@ -200,11 +123,4 @@ export async function updateContactName(
200
123
  * }
201
124
  * ```
202
125
  */
203
- export async function deleteContact(
204
- ownerUserId: string,
205
- contactUserId: string,
206
- db: GossipDatabase,
207
- session: SessionModule
208
- ): Promise<DeleteContactResult> {
209
- return await deleteContactUtil(ownerUserId, contactUserId, db, session);
210
- }
126
+ export declare function deleteContact(ownerUserId: string, contactUserId: string, db: GossipDatabase, session: SessionModule): Promise<DeleteContactResult>;