@prototypevip/baileys 0.0.1

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 (118) hide show
  1. package/LICENSE +23 -0
  2. package/WAProto/index.js +131118 -0
  3. package/engine-requirements.js +1 -0
  4. package/lib/Defaults/index.js +187 -0
  5. package/lib/Signal/Group/ciphertext-message.js +11 -0
  6. package/lib/Signal/Group/group-session-builder.js +41 -0
  7. package/lib/Signal/Group/group_cipher.js +108 -0
  8. package/lib/Signal/Group/index.js +11 -0
  9. package/lib/Signal/Group/keyhelper.js +14 -0
  10. package/lib/Signal/Group/sender-chain-key.js +31 -0
  11. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  12. package/lib/Signal/Group/sender-key-message.js +79 -0
  13. package/lib/Signal/Group/sender-key-name.js +49 -0
  14. package/lib/Signal/Group/sender-key-record.js +46 -0
  15. package/lib/Signal/Group/sender-key-state.js +104 -0
  16. package/lib/Signal/Group/sender-message-key.js +29 -0
  17. package/lib/Signal/libsignal.js +532 -0
  18. package/lib/Signal/lid-mapping.js +312 -0
  19. package/lib/Socket/Client/index.js +2 -0
  20. package/lib/Socket/Client/types.js +10 -0
  21. package/lib/Socket/Client/websocket.js +64 -0
  22. package/lib/Socket/business.js +293 -0
  23. package/lib/Socket/chats.js +1124 -0
  24. package/lib/Socket/communities.js +528 -0
  25. package/lib/Socket/groups.js +465 -0
  26. package/lib/Socket/index.js +14 -0
  27. package/lib/Socket/messages-recv.js +2325 -0
  28. package/lib/Socket/messages-send.js +1746 -0
  29. package/lib/Socket/mex.js +55 -0
  30. package/lib/Socket/newsletter.js +317 -0
  31. package/lib/Socket/socket.js +1185 -0
  32. package/lib/Store/cache-factory.js +20 -0
  33. package/lib/Store/index.js +5 -0
  34. package/lib/Store/make-in-memory-store.js +523 -0
  35. package/lib/Store/make-ordered-dictionary.js +203 -0
  36. package/lib/Store/object-repository.js +23 -0
  37. package/lib/Store/prototype-store.js +958 -0
  38. package/lib/Types/Auth.js +1 -0
  39. package/lib/Types/Bussines.js +1 -0
  40. package/lib/Types/Call.js +1 -0
  41. package/lib/Types/Chat.js +7 -0
  42. package/lib/Types/Contact.js +1 -0
  43. package/lib/Types/Events.js +1 -0
  44. package/lib/Types/GroupMetadata.js +1 -0
  45. package/lib/Types/Label.js +24 -0
  46. package/lib/Types/LabelAssociation.js +6 -0
  47. package/lib/Types/Message.js +18 -0
  48. package/lib/Types/Mex.js +37 -0
  49. package/lib/Types/Newsletter.js +36 -0
  50. package/lib/Types/Product.js +1 -0
  51. package/lib/Types/RichType.js +25 -0
  52. package/lib/Types/Signal.js +1 -0
  53. package/lib/Types/Socket.js +2 -0
  54. package/lib/Types/State.js +78 -0
  55. package/lib/Types/USync.js +1 -0
  56. package/lib/Types/index.js +33 -0
  57. package/lib/Utils/auth-utils.js +303 -0
  58. package/lib/Utils/browser-utils.js +32 -0
  59. package/lib/Utils/business.js +245 -0
  60. package/lib/Utils/chat-utils.js +971 -0
  61. package/lib/Utils/companion-reg-client-utils.js +54 -0
  62. package/lib/Utils/constants.js +24 -0
  63. package/lib/Utils/crypto.js +133 -0
  64. package/lib/Utils/cstoken-utils.js +41 -0
  65. package/lib/Utils/decode-wa-message.js +406 -0
  66. package/lib/Utils/event-buffer.js +616 -0
  67. package/lib/Utils/generics.js +438 -0
  68. package/lib/Utils/history.js +147 -0
  69. package/lib/Utils/identity-change-handler.js +63 -0
  70. package/lib/Utils/index.js +29 -0
  71. package/lib/Utils/interactive-message-handler.js +478 -0
  72. package/lib/Utils/link-preview.js +91 -0
  73. package/lib/Utils/logger.js +2 -0
  74. package/lib/Utils/lt-hash.js +6 -0
  75. package/lib/Utils/make-mutex.js +31 -0
  76. package/lib/Utils/message-retry-manager.js +291 -0
  77. package/lib/Utils/messages-media.js +881 -0
  78. package/lib/Utils/messages.js +1434 -0
  79. package/lib/Utils/noise-handler.js +229 -0
  80. package/lib/Utils/normalize-message-identity.js +73 -0
  81. package/lib/Utils/offline-node-processor.js +50 -0
  82. package/lib/Utils/pre-key-manager.js +119 -0
  83. package/lib/Utils/process-message.js +648 -0
  84. package/lib/Utils/reporting-utils.js +355 -0
  85. package/lib/Utils/rich-message-utils.js +264 -0
  86. package/lib/Utils/signal.js +233 -0
  87. package/lib/Utils/stanza-ack.js +33 -0
  88. package/lib/Utils/sticker-utils.js +221 -0
  89. package/lib/Utils/sync-action-utils.js +53 -0
  90. package/lib/Utils/tc-token-utils.js +182 -0
  91. package/lib/Utils/use-multi-file-auth-state.js +118 -0
  92. package/lib/Utils/use-prototype-auth-state.js +217 -0
  93. package/lib/Utils/use-single-file-auth-state.js +94 -0
  94. package/lib/Utils/validate-connection.js +235 -0
  95. package/lib/WABinary/constants.js +1468 -0
  96. package/lib/WABinary/decode.js +258 -0
  97. package/lib/WABinary/encode.js +219 -0
  98. package/lib/WABinary/generic-utils.js +202 -0
  99. package/lib/WABinary/index.js +5 -0
  100. package/lib/WABinary/jid-utils.js +94 -0
  101. package/lib/WABinary/types.js +1 -0
  102. package/lib/WAM/BinaryInfo.js +9 -0
  103. package/lib/WAM/constants.js +20669 -0
  104. package/lib/WAM/encode.js +151 -0
  105. package/lib/WAM/index.js +3 -0
  106. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  107. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -0
  108. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -0
  109. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +29 -0
  110. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  111. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +59 -0
  112. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +21 -0
  113. package/lib/WAUSync/Protocols/index.js +4 -0
  114. package/lib/WAUSync/USyncQuery.js +133 -0
  115. package/lib/WAUSync/USyncUser.js +22 -0
  116. package/lib/WAUSync/index.js +3 -0
  117. package/lib/index.js +12 -0
  118. package/package.json +78 -0
@@ -0,0 +1,203 @@
1
+ export function makeOrderedDictionary(idGetter) {
2
+ const map = new Map();
3
+
4
+ let head = null;
5
+ let tail = null;
6
+
7
+ let cached = [];
8
+ let dirty = true;
9
+
10
+ const hooks = {
11
+ add: new Set(),
12
+ update: new Set(),
13
+ remove: new Set(),
14
+ batch: new Set(),
15
+ };
16
+
17
+ const emit = (type, payload) => {
18
+ const set = hooks[type];
19
+ if (!set) return;
20
+ for (const fn of set) {
21
+ try {
22
+ fn(payload);
23
+ } catch {}
24
+ }
25
+ };
26
+
27
+ const rebuild = () => {
28
+ const arr = [];
29
+ let curr = head;
30
+ while (curr) {
31
+ arr.push(curr.item);
32
+ curr = curr.next;
33
+ }
34
+ cached = arr;
35
+ dirty = false;
36
+ };
37
+
38
+ const get = (id) => map.get(id)?.item;
39
+
40
+ const upsert = (item, mode = "append") => {
41
+ const id = idGetter(item);
42
+
43
+ const existing = map.get(id);
44
+
45
+ if (existing) {
46
+ existing.item = item;
47
+ dirty = true;
48
+ emit("update", item);
49
+ return;
50
+ }
51
+
52
+ const node = { id, item, prev: null, next: null };
53
+
54
+ map.set(id, node);
55
+
56
+ if (!head) {
57
+ head = tail = node;
58
+ } else if (mode === "append") {
59
+ tail.next = node;
60
+ node.prev = tail;
61
+ tail = node;
62
+ } else {
63
+ node.next = head;
64
+ head.prev = node;
65
+ head = node;
66
+ }
67
+
68
+ dirty = true;
69
+ emit("add", item);
70
+ };
71
+
72
+ const update = (item) => {
73
+ const id = idGetter(item);
74
+ const node = map.get(id);
75
+ if (!node) return false;
76
+
77
+ node.item = item;
78
+ dirty = true;
79
+
80
+ emit("update", item);
81
+ return true;
82
+ };
83
+
84
+ const remove = (item) => {
85
+ const id = idGetter(item);
86
+ const node = map.get(id);
87
+ if (!node) return false;
88
+
89
+ if (node.prev) node.prev.next = node.next;
90
+ else head = node.next;
91
+
92
+ if (node.next) node.next.prev = node.prev;
93
+ else tail = node.prev;
94
+
95
+ map.delete(id);
96
+
97
+ node.prev = node.next = null;
98
+
99
+ dirty = true;
100
+ emit("remove", item);
101
+
102
+ return true;
103
+ };
104
+
105
+ const updateAssign = (id, patch) => {
106
+ const node = map.get(id);
107
+ if (!node) return false;
108
+
109
+ const data = typeof patch === "function" ? patch(node.item) : patch;
110
+
111
+ Object.assign(node.item, data);
112
+
113
+ const newId = idGetter(node.item);
114
+
115
+ if (newId !== id) {
116
+ map.delete(id);
117
+ map.set(newId, node);
118
+ node.id = newId;
119
+ }
120
+
121
+ dirty = true;
122
+ emit("update", node.item);
123
+
124
+ return true;
125
+ };
126
+
127
+ const clear = () => {
128
+ map.clear();
129
+ head = tail = null;
130
+ cached = [];
131
+ dirty = false;
132
+ };
133
+
134
+ const filter = (fn) => {
135
+ let curr = head;
136
+
137
+ while (curr) {
138
+ const next = curr.next;
139
+
140
+ if (!fn(curr.item)) {
141
+ map.delete(curr.id);
142
+
143
+ if (curr.prev) curr.prev.next = curr.next;
144
+ else head = curr.next;
145
+
146
+ if (curr.next) curr.next.prev = curr.prev;
147
+ else tail = curr.prev;
148
+
149
+ curr.prev = curr.next = null;
150
+
151
+ dirty = true;
152
+ emit("remove", curr.item);
153
+ }
154
+
155
+ curr = next;
156
+ }
157
+ };
158
+
159
+ const snapshot = () => {
160
+ return {
161
+ data: dirty ? (rebuild(), cached) : cached,
162
+ size: map.size,
163
+ };
164
+ };
165
+
166
+ const iterator = function* () {
167
+ let curr = head;
168
+ while (curr) {
169
+ yield curr.item;
170
+ curr = curr.next;
171
+ }
172
+ };
173
+
174
+ const on = (type, fn) => {
175
+ if (hooks[type]) hooks[type].add(fn);
176
+ };
177
+
178
+ const off = (type, fn) => {
179
+ hooks[type]?.delete(fn);
180
+ };
181
+
182
+ const array = () => {
183
+ if (dirty) rebuild();
184
+ return cached;
185
+ };
186
+
187
+ return {
188
+ get,
189
+ upsert,
190
+ update,
191
+ remove,
192
+ updateAssign,
193
+ clear,
194
+ filter,
195
+
196
+ array,
197
+ snapshot,
198
+ iterator,
199
+
200
+ on,
201
+ off,
202
+ };
203
+ }
@@ -0,0 +1,23 @@
1
+ export class ObjectRepository {
2
+ constructor(entities = {}) {
3
+ this.entityMap = new Map(Object.entries(entities));
4
+ }
5
+ findById(id) {
6
+ return this.entityMap.get(id);
7
+ }
8
+ findAll() {
9
+ return Array.from(this.entityMap.values());
10
+ }
11
+ upsertById(id, entity) {
12
+ return this.entityMap.set(id, { ...entity });
13
+ }
14
+ deleteById(id) {
15
+ return this.entityMap.delete(id);
16
+ }
17
+ count() {
18
+ return this.entityMap.size;
19
+ }
20
+ toJSON() {
21
+ return this.findAll();
22
+ }
23
+ }