@massalabs/gossip-sdk 0.0.2-dev.20260220052333 → 0.0.2-dev.20260220053835

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 (60) hide show
  1. package/README.md +2 -2
  2. package/dist/config/sdk.js +1 -1
  3. package/dist/contacts.d.ts +11 -17
  4. package/dist/contacts.js +20 -26
  5. package/dist/core/SdkEventEmitter.d.ts +2 -0
  6. package/dist/core/SdkEventEmitter.js +2 -0
  7. package/dist/core/SdkPolling.d.ts +2 -5
  8. package/dist/core/SdkPolling.js +1 -4
  9. package/dist/core/index.d.ts +1 -1
  10. package/dist/core/index.js +1 -0
  11. package/dist/db.d.ts +34 -56
  12. package/dist/db.js +39 -229
  13. package/dist/gossip.d.ts +54 -23
  14. package/dist/gossip.js +149 -120
  15. package/dist/index.d.ts +13 -4
  16. package/dist/index.js +13 -4
  17. package/dist/queries/activeSeekers.d.ts +2 -0
  18. package/dist/queries/activeSeekers.js +18 -0
  19. package/dist/queries/announcementCursors.d.ts +2 -0
  20. package/dist/queries/announcementCursors.js +20 -0
  21. package/dist/queries/contacts.d.ts +13 -0
  22. package/dist/queries/contacts.js +43 -0
  23. package/dist/queries/discussions.d.ts +21 -0
  24. package/dist/queries/discussions.js +73 -0
  25. package/dist/queries/index.d.ts +7 -0
  26. package/dist/queries/index.js +7 -0
  27. package/dist/queries/messages.d.ts +27 -0
  28. package/dist/queries/messages.js +120 -0
  29. package/dist/queries/pendingAnnouncements.d.ts +4 -0
  30. package/dist/queries/pendingAnnouncements.js +11 -0
  31. package/dist/queries/userProfile.d.ts +22 -0
  32. package/dist/queries/userProfile.js +116 -0
  33. package/dist/schema.d.ts +1280 -0
  34. package/dist/schema.js +164 -0
  35. package/dist/services/announcement.d.ts +8 -7
  36. package/dist/services/announcement.js +95 -121
  37. package/dist/services/auth.d.ts +1 -3
  38. package/dist/services/auth.js +4 -11
  39. package/dist/services/discussion.d.ts +8 -15
  40. package/dist/services/discussion.js +62 -62
  41. package/dist/services/message.d.ts +15 -26
  42. package/dist/services/message.js +282 -270
  43. package/dist/services/refresh.d.ts +3 -5
  44. package/dist/services/refresh.js +10 -13
  45. package/dist/sqlite-worker.d.ts +12 -0
  46. package/dist/sqlite-worker.js +106 -0
  47. package/dist/sqlite.d.ts +79 -0
  48. package/dist/sqlite.js +448 -0
  49. package/dist/utils/contacts.d.ts +2 -5
  50. package/dist/utils/contacts.js +23 -39
  51. package/dist/utils/discussions.d.ts +7 -2
  52. package/dist/utils/discussions.js +24 -5
  53. package/dist/utils/logs.js +1 -3
  54. package/dist/utils/validation.d.ts +2 -4
  55. package/dist/utils/validation.js +5 -10
  56. package/package.json +5 -7
  57. package/dist/api/messageProtocol/mock.d.ts +0 -12
  58. package/dist/api/messageProtocol/mock.js +0 -12
  59. package/dist/types/events.d.ts +0 -80
  60. package/dist/types/events.js +0 -7
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * Functions for validating user input like usernames, passwords, and user IDs.
5
5
  */
6
- import { type GossipDatabase } from '../db';
7
6
  export type ValidationResult = {
8
7
  valid: true;
9
8
  error?: never;
@@ -29,10 +28,9 @@ export declare function validateUsernameFormat(value: string): ValidationResult;
29
28
  * Validate a username is available (not already in use)
30
29
  *
31
30
  * @param value - The username to check
32
- * @param db - Database instance
33
31
  * @returns Validation result
34
32
  */
35
- export declare function validateUsernameAvailability(value: string, db: GossipDatabase): Promise<ValidationResult>;
33
+ export declare function validateUsernameAvailability(value: string): Promise<ValidationResult>;
36
34
  /**
37
35
  * Validate a username format and availability
38
36
  *
@@ -40,7 +38,7 @@ export declare function validateUsernameAvailability(value: string, db: GossipDa
40
38
  * @param db - Database instance
41
39
  * @returns Validation result
42
40
  */
43
- export declare function validateUsernameFormatAndAvailability(value: string, db: GossipDatabase): Promise<ValidationResult>;
41
+ export declare function validateUsernameFormatAndAvailability(value: string): Promise<ValidationResult>;
44
42
  /**
45
43
  * Validate a user ID format (Bech32 gossip1... format)
46
44
  *
@@ -4,6 +4,7 @@
4
4
  * Functions for validating user input like usernames, passwords, and user IDs.
5
5
  */
6
6
  import { isValidUserId } from './userId';
7
+ import { getUserProfileByUsernameLower } from '../queries';
7
8
  /**
8
9
  * Validate a password meets requirements
9
10
  *
@@ -52,17 +53,11 @@ export function validateUsernameFormat(value) {
52
53
  * Validate a username is available (not already in use)
53
54
  *
54
55
  * @param value - The username to check
55
- * @param db - Database instance
56
56
  * @returns Validation result
57
57
  */
58
- export async function validateUsernameAvailability(value, db) {
58
+ export async function validateUsernameAvailability(value) {
59
59
  try {
60
- if (!db.isOpen()) {
61
- await db.open();
62
- }
63
- const existingProfile = await db.userProfile
64
- .filter((profile) => profile.username.trim().toLowerCase() === value.trim().toLowerCase())
65
- .first();
60
+ const existingProfile = await getUserProfileByUsernameLower(value);
66
61
  if (existingProfile) {
67
62
  return {
68
63
  valid: false,
@@ -87,12 +82,12 @@ export async function validateUsernameAvailability(value, db) {
87
82
  * @param db - Database instance
88
83
  * @returns Validation result
89
84
  */
90
- export async function validateUsernameFormatAndAvailability(value, db) {
85
+ export async function validateUsernameFormatAndAvailability(value) {
91
86
  const result = validateUsernameFormat(value);
92
87
  if (!result.valid) {
93
88
  return result;
94
89
  }
95
- return await validateUsernameAvailability(value, db);
90
+ return await validateUsernameAvailability(value);
96
91
  }
97
92
  /**
98
93
  * Validate a user ID format (Bech32 gossip1... format)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massalabs/gossip-sdk",
3
- "version": "0.0.2-dev.20260220052333",
3
+ "version": "0.0.2-dev.20260220053835",
4
4
  "description": "Gossip SDK for automation, chatbot, and integration use cases",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,18 +39,16 @@
39
39
  ],
40
40
  "license": "MIT",
41
41
  "devDependencies": {
42
- "fake-indexeddb": "^6.2.5",
42
+ "drizzle-kit": "^0.31.1",
43
43
  "rimraf": "^6.1.2",
44
44
  "typescript": "^5.9.3",
45
45
  "vitest": "^4.0.17"
46
46
  },
47
- "peerDependencies": {
48
- "dexie": "^4.0.0",
49
- "zustand": "^5.0.0"
50
- },
51
47
  "dependencies": {
52
48
  "@massalabs/massa-web3": "^5.3.0",
53
49
  "@scure/base": "^2.0.0",
54
- "@scure/bip39": "^2.0.1"
50
+ "@scure/bip39": "^2.0.1",
51
+ "drizzle-orm": "^0.45.1",
52
+ "wa-sqlite": "^1.0.0"
55
53
  }
56
54
  }
@@ -1,12 +0,0 @@
1
- /**
2
- * Message Protocol Implementation
3
- *
4
- * Provides a concrete protocol class backed by the REST implementation.
5
- * This uses the real Gossip API rather than a mock transport.
6
- */
7
- import { RestMessageProtocol } from './rest';
8
- /**
9
- * Create a MessageProtocol instance backed by REST.
10
- */
11
- export declare class MessageProtocol extends RestMessageProtocol {
12
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Message Protocol Implementation
3
- *
4
- * Provides a concrete protocol class backed by the REST implementation.
5
- * This uses the real Gossip API rather than a mock transport.
6
- */
7
- import { RestMessageProtocol } from './rest';
8
- /**
9
- * Create a MessageProtocol instance backed by REST.
10
- */
11
- export class MessageProtocol extends RestMessageProtocol {
12
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * SDK Event Types
3
- *
4
- * Event handlers for SDK events. These are used by the SDK to notify
5
- * the host application about state changes.
6
- */
7
- import { Message, Discussion, Contact } from '../db';
8
- /**
9
- * Event handlers for SDK events.
10
- *
11
- * The SDK emits events when things happen (messages received, discussions created, etc.)
12
- * Your app can listen to these events and update its own state (zustand, redux, etc.)
13
- *
14
- * This pattern keeps the SDK decoupled from any specific state management solution.
15
- */
16
- export interface GossipSdkEvents {
17
- /**
18
- * Called when a new message is received from a contact.
19
- * Use this to update your message list UI.
20
- */
21
- onMessageReceived?: (message: Message) => void;
22
- /**
23
- * Called when a message is successfully sent.
24
- * Use this to update message status in UI (sending → sent).
25
- */
26
- onMessageSent?: (message: Message) => void;
27
- /**
28
- * Called when sending a message fails.
29
- * Use this to show error state and allow retry.
30
- */
31
- onMessageFailed?: (message: Message, error: Error) => void;
32
- /**
33
- * Called when someone sends you a discussion request (announcement).
34
- * Use this to show the request in your discussion list.
35
- */
36
- onDiscussionRequest?: (discussion: Discussion, contact: Contact) => void;
37
- /**
38
- * Called when a discussion status changes (accepted, broken, etc.).
39
- * Use this to update discussion state in UI.
40
- */
41
- onDiscussionStatusChanged?: (discussion: Discussion) => void;
42
- /**
43
- * Called when a session with a contact is broken and needs renewal.
44
- * Use this to show appropriate UI state.
45
- * @deprecated Use onSessionRenewalNeeded for auto-renewal flow
46
- */
47
- onSessionBroken?: (discussion: Discussion) => void;
48
- /**
49
- * Called when a session is successfully renewed.
50
- */
51
- onSessionRenewed?: (discussion: Discussion) => void;
52
- /**
53
- * Called when a session needs to be renewed (auto-renewal).
54
- * The SDK will automatically attempt to renew the session.
55
- * Messages are queued with WAITING_SESSION status until session is active.
56
- */
57
- onSessionRenewalNeeded?: (contactUserId: string) => void;
58
- /**
59
- * Called when a peer has requested a session and we need to accept it.
60
- * This is different from renewal - the peer has sent us an announcement
61
- * and we need to respond (via DiscussionService.accept()).
62
- * NOT calling this correctly can cause stuck sessions (both sides waiting).
63
- */
64
- onSessionAcceptNeeded?: (contactUserId: string) => void;
65
- /**
66
- * Called when a session becomes Active after peer accepts our announcement.
67
- * This happens when we initiated a session (SelfRequested) and the peer
68
- * accepted it by sending their announcement back.
69
- * Use this to process any messages that were queued as WAITING_SESSION.
70
- */
71
- onSessionBecameActive?: (contactUserId: string) => void;
72
- /**
73
- * Called when an error occurs in any SDK operation.
74
- * Use this for logging, error reporting, or showing error toasts.
75
- *
76
- * @param error - The error that occurred
77
- * @param context - Where the error occurred (e.g., 'message.send', 'announcement.fetch')
78
- */
79
- onError?: (error: Error, context: string) => void;
80
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * SDK Event Types
3
- *
4
- * Event handlers for SDK events. These are used by the SDK to notify
5
- * the host application about state changes.
6
- */
7
- export {};