@kangwifi-pro/waliwa 1.1.13 → 1.1.14

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 (70) hide show
  1. package/dist/core/client-payload.d.ts +30 -0
  2. package/dist/core/client-payload.d.ts.map +1 -0
  3. package/dist/core/client-payload.js +203 -0
  4. package/dist/core/client-payload.js.map +1 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/socket/wa-socket.d.ts.map +1 -1
  8. package/dist/socket/wa-socket.js +3 -5
  9. package/dist/socket/wa-socket.js.map +1 -1
  10. package/dist/socket/ws-socket.d.ts +4 -1
  11. package/dist/socket/ws-socket.d.ts.map +1 -1
  12. package/dist/socket/ws-socket.js +21 -18
  13. package/dist/socket/ws-socket.js.map +1 -1
  14. package/package.json +16 -10
  15. package/proto/WAProto.proto +3344 -0
  16. package/docs/API.md +0 -745
  17. package/docs/ARCHITECTURE.md +0 -307
  18. package/docs/BAILEYS_FIXES.md +0 -360
  19. package/docs/COMMUNITY.md +0 -613
  20. package/docs/FEATURES.md +0 -532
  21. package/docs/PROTOCOL.md +0 -489
  22. package/docs/RECOVERY.md +0 -409
  23. package/docs/SKDM.md +0 -233
  24. package/examples/ai-bot/index.ts +0 -479
  25. package/examples/ai-bot/package.json +0 -17
  26. package/examples/echo-bot/index.ts +0 -171
  27. package/examples/echo-bot/package.json +0 -18
  28. package/examples/group-bot/index.ts +0 -557
  29. package/examples/group-bot/package.json +0 -17
  30. package/examples/rest-gateway/index.ts +0 -499
  31. package/examples/rest-gateway/package.json +0 -19
  32. package/src/advanced/features.ts +0 -817
  33. package/src/auth/auth-state.ts +0 -342
  34. package/src/auth/pairing-code.ts +0 -246
  35. package/src/auth/qr-code.ts +0 -191
  36. package/src/calls/handler.ts +0 -153
  37. package/src/community/audio-transcription.ts +0 -121
  38. package/src/community/bulk-operations.ts +0 -329
  39. package/src/community/community-fixes.ts +0 -771
  40. package/src/community/contacts-manager.ts +0 -282
  41. package/src/community/disappearing.ts +0 -218
  42. package/src/community/index.ts +0 -169
  43. package/src/community/live-location.ts +0 -287
  44. package/src/community/message-extras.ts +0 -523
  45. package/src/community/newsletter-extended.ts +0 -614
  46. package/src/community/privacy-manager.ts +0 -310
  47. package/src/community/profile-manager.ts +0 -402
  48. package/src/community/status-extended.ts +0 -518
  49. package/src/community/sticker-manager.ts +0 -305
  50. package/src/core/binary.ts +0 -464
  51. package/src/core/crypto.ts +0 -197
  52. package/src/core/noise.ts +0 -421
  53. package/src/events/emitter.ts +0 -88
  54. package/src/features/index.ts +0 -921
  55. package/src/fixes/index.ts +0 -882
  56. package/src/groups/management.ts +0 -497
  57. package/src/index.ts +0 -339
  58. package/src/messages/media.ts +0 -372
  59. package/src/messages/message-encoder.ts +0 -520
  60. package/src/messages/send.ts +0 -521
  61. package/src/recovery/index.ts +0 -704
  62. package/src/skdm/index.ts +0 -693
  63. package/src/socket/hybrid.ts +0 -414
  64. package/src/socket/wa-socket.ts +0 -1735
  65. package/src/socket/ws-socket.ts +0 -486
  66. package/src/types/index.ts +0 -457
  67. package/src/utils/jid.ts +0 -156
  68. package/src/utils/logger.ts +0 -84
  69. package/src/utils/retry.ts +0 -205
  70. package/tsconfig.json +0 -30
@@ -1,205 +0,0 @@
1
- /**
2
- * Waliwa - Retry & throttle utilities
3
- * Implementasi efficient untuk retry exponential backoff dan rate limiting
4
- */
5
-
6
- import { getRandomBytes } from '../core/crypto.js';
7
-
8
- // ============== Retry ==============
9
-
10
- export interface RetryOptions {
11
- retries?: number;
12
- minTimeout?: number;
13
- maxTimeout?: number;
14
- factor?: number;
15
- randomize?: boolean;
16
- onFailedAttempt?: (error: Error, attempt: number) => void;
17
- }
18
-
19
- /**
20
- * Exponential backoff retry dengan jitter
21
- */
22
- export async function retry<T>(
23
- fn: () => Promise<T>,
24
- options: RetryOptions = {}
25
- ): Promise<T> {
26
- const {
27
- retries = 5,
28
- minTimeout = 500,
29
- maxTimeout = 30000,
30
- factor = 2,
31
- randomize = true,
32
- onFailedAttempt
33
- } = options;
34
-
35
- let attempt = 0;
36
- let lastError: Error;
37
-
38
- while (attempt <= retries) {
39
- try {
40
- return await fn();
41
- } catch (err) {
42
- lastError = err as Error;
43
- attempt++;
44
- if (attempt > retries) {
45
- throw lastError;
46
- }
47
- if (onFailedAttempt) {
48
- onFailedAttempt(lastError, attempt);
49
- }
50
- // Exponential backoff dengan jitter
51
- let delay = minTimeout * Math.pow(factor, attempt - 1);
52
- if (randomize) {
53
- const jitter = (getRandomBytes(1)[0] / 255) * 0.3;
54
- delay = delay * (1 + jitter);
55
- }
56
- delay = Math.min(delay, maxTimeout);
57
- await sleep(delay);
58
- }
59
- }
60
- throw lastError!;
61
- }
62
-
63
- export function sleep(ms: number): Promise<void> {
64
- return new Promise(resolve => setTimeout(resolve, ms));
65
- }
66
-
67
- // ============== Throttle / Rate Limiter ==============
68
-
69
- /**
70
- * Token bucket rate limiter - RAM-efficient (single object per limiter)
71
- */
72
- export class RateLimiter {
73
- private tokens: number;
74
- private lastRefill: number;
75
- private readonly maxTokens: number;
76
- private readonly refillRate: number; // tokens per ms
77
- private readonly queue: Array<{ resolve: () => void; reject: (err: Error) => void }> = [];
78
- private processing: boolean = false;
79
-
80
- constructor(maxTokensPerSecond: number) {
81
- this.maxTokens = maxTokensPerSecond;
82
- this.tokens = maxTokensPerSecond;
83
- this.refillRate = maxTokensPerSecond / 1000;
84
- this.lastRefill = Date.now();
85
- }
86
-
87
- private refill(): void {
88
- const now = Date.now();
89
- const elapsed = now - this.lastRefill;
90
- this.tokens = Math.min(this.maxTokens, this.tokens + elapsed * this.refillRate);
91
- this.lastRefill = now;
92
- }
93
-
94
- async acquire(): Promise<void> {
95
- this.refill();
96
- if (this.tokens >= 1) {
97
- this.tokens -= 1;
98
- return;
99
- }
100
- // Queue
101
- return new Promise((resolve, reject) => {
102
- this.queue.push({ resolve, reject });
103
- this.processQueue();
104
- });
105
- }
106
-
107
- private processQueue(): void {
108
- if (this.processing) return;
109
- this.processing = true;
110
- const tick = () => {
111
- this.refill();
112
- while (this.queue.length > 0 && this.tokens >= 1) {
113
- this.tokens -= 1;
114
- const item = this.queue.shift()!;
115
- item.resolve();
116
- }
117
- if (this.queue.length > 0) {
118
- setTimeout(tick, 50);
119
- } else {
120
- this.processing = false;
121
- }
122
- };
123
- tick();
124
- }
125
-
126
- /** Destroy limiter dan reject semua queued requests */
127
- destroy(): void {
128
- while (this.queue.length > 0) {
129
- const item = this.queue.shift()!;
130
- item.reject(new Error('Rate limiter destroyed'));
131
- }
132
- }
133
- }
134
-
135
- // ============== Debounce ==============
136
-
137
- export function debounce<T extends (...args: any[]) => void>(
138
- fn: T,
139
- wait: number
140
- ): (...args: Parameters<T>) => void {
141
- let timeout: NodeJS.Timeout | null = null;
142
- return (...args: Parameters<T>) => {
143
- if (timeout) clearTimeout(timeout);
144
- timeout = setTimeout(() => fn(...args), wait);
145
- };
146
- }
147
-
148
- // ============== Throttle (leading edge) ==============
149
-
150
- export function throttle<T extends (...args: any[]) => void>(
151
- fn: T,
152
- wait: number
153
- ): (...args: Parameters<T>) => void {
154
- let lastCall = 0;
155
- let timeout: NodeJS.Timeout | null = null;
156
- return (...args: Parameters<T>) => {
157
- const now = Date.now();
158
- const remaining = wait - (now - lastCall);
159
- if (remaining <= 0) {
160
- if (timeout) {
161
- clearTimeout(timeout);
162
- timeout = null;
163
- }
164
- lastCall = now;
165
- fn(...args);
166
- } else if (!timeout) {
167
- timeout = setTimeout(() => {
168
- lastCall = Date.now();
169
- timeout = null;
170
- fn(...args);
171
- }, remaining);
172
- }
173
- };
174
- }
175
-
176
- // ============== Promise Queue (sequential execution) ==============
177
-
178
- export class PromiseQueue {
179
- private queue: Array<() => Promise<void>> = [];
180
- private running: boolean = false;
181
-
182
- async add<T>(fn: () => Promise<T>): Promise<T> {
183
- return new Promise<T>((resolve, reject) => {
184
- this.queue.push(async () => {
185
- try {
186
- const result = await fn();
187
- resolve(result);
188
- } catch (err) {
189
- reject(err);
190
- }
191
- });
192
- this.process();
193
- });
194
- }
195
-
196
- private async process(): Promise<void> {
197
- if (this.running) return;
198
- this.running = true;
199
- while (this.queue.length > 0) {
200
- const task = this.queue.shift()!;
201
- await task();
202
- }
203
- this.running = false;
204
- }
205
- }
package/tsconfig.json DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "NodeNext",
5
- "moduleResolution": "NodeNext",
6
- "lib": ["ES2022"],
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "declaration": true,
10
- "declarationMap": true,
11
- "sourceMap": true,
12
- "strict": true,
13
- "noImplicitAny": true,
14
- "strictNullChecks": true,
15
- "strictFunctionTypes": true,
16
- "noUnusedLocals": false,
17
- "noUnusedParameters": false,
18
- "noImplicitReturns": true,
19
- "noFallthroughCasesInSwitch": true,
20
- "esModuleInterop": true,
21
- "allowSyntheticDefaultImports": true,
22
- "forceConsistentCasingInFileNames": true,
23
- "skipLibCheck": true,
24
- "resolveJsonModule": true,
25
- "experimentalDecorators": true,
26
- "emitDecoratorMetadata": true
27
- },
28
- "include": ["src/**/*.ts"],
29
- "exclude": ["node_modules", "dist", "examples", "**/*.test.ts"]
30
- }