@kyyinfinite/zapo-message 0.0.0-stage → 1.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 (191) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/LICENSE +20 -0
  3. package/README.md +1401 -2
  4. package/build.config.json +28 -0
  5. package/dist/airich/airich.d.ts +180 -0
  6. package/dist/airich/airich.js +548 -0
  7. package/dist/airich/context.d.ts +24 -0
  8. package/dist/airich/context.js +48 -0
  9. package/dist/airich/encode.d.ts +3 -0
  10. package/dist/airich/encode.js +16 -0
  11. package/dist/airich/index.d.ts +20 -0
  12. package/dist/airich/index.js +11 -0
  13. package/dist/airich/inline.d.ts +45 -0
  14. package/dist/airich/inline.js +152 -0
  15. package/dist/airich/nodes.d.ts +30 -0
  16. package/dist/airich/nodes.js +121 -0
  17. package/dist/airich/primitives.d.ts +144 -0
  18. package/dist/airich/primitives.js +230 -0
  19. package/dist/airich/protocol.d.ts +35 -0
  20. package/dist/airich/protocol.js +65 -0
  21. package/dist/airich/table.d.ts +22 -0
  22. package/dist/airich/table.js +35 -0
  23. package/dist/airich/tokenizer.d.ts +13 -0
  24. package/dist/airich/tokenizer.js +717 -0
  25. package/dist/airich/transport.d.ts +15 -0
  26. package/dist/airich/transport.js +56 -0
  27. package/dist/branding.d.ts +5 -0
  28. package/dist/branding.js +9 -0
  29. package/dist/btn/builders.d.ts +246 -0
  30. package/dist/btn/builders.js +710 -0
  31. package/dist/btn/media-slot.d.ts +28 -0
  32. package/dist/btn/media-slot.js +323 -0
  33. package/dist/btn/media-source.d.ts +36 -0
  34. package/dist/btn/media-source.js +116 -0
  35. package/dist/btn/sharp-loader.d.ts +5 -0
  36. package/dist/btn/sharp-loader.js +18 -0
  37. package/dist/btn/thumbnail.d.ts +21 -0
  38. package/dist/btn/thumbnail.js +124 -0
  39. package/dist/btn/validators.d.ts +40 -0
  40. package/dist/btn/validators.js +135 -0
  41. package/dist/btn.d.ts +1 -0
  42. package/dist/btn.js +1 -0
  43. package/dist/core/async-send.d.ts +20 -0
  44. package/dist/core/async-send.js +1 -0
  45. package/dist/core/base-builder.d.ts +20 -0
  46. package/dist/core/base-builder.js +67 -0
  47. package/dist/core/errors.d.ts +30 -0
  48. package/dist/core/errors.js +61 -0
  49. package/dist/download.d.ts +24 -0
  50. package/dist/download.js +123 -0
  51. package/dist/index.d.ts +38 -0
  52. package/dist/index.js +22 -0
  53. package/dist/integration/augment.d.ts +97 -0
  54. package/dist/integration/augment.js +1 -0
  55. package/dist/integration/auto.d.ts +8 -0
  56. package/dist/integration/auto.js +79 -0
  57. package/dist/integration/index.d.ts +4 -0
  58. package/dist/integration/index.js +2 -0
  59. package/dist/integration/methods.d.ts +25 -0
  60. package/dist/integration/methods.js +24 -0
  61. package/dist/interactive.d.ts +24 -0
  62. package/dist/interactive.js +121 -0
  63. package/dist/media-gate.d.ts +99 -0
  64. package/dist/media-gate.js +322 -0
  65. package/dist/message/album.d.ts +33 -0
  66. package/dist/message/album.js +107 -0
  67. package/dist/message/contact.d.ts +29 -0
  68. package/dist/message/contact.js +123 -0
  69. package/dist/message/forward.d.ts +23 -0
  70. package/dist/message/forward.js +77 -0
  71. package/dist/message/index.d.ts +26 -0
  72. package/dist/message/index.js +13 -0
  73. package/dist/message/link-preview.d.ts +28 -0
  74. package/dist/message/link-preview.js +98 -0
  75. package/dist/message/location.d.ts +24 -0
  76. package/dist/message/location.js +94 -0
  77. package/dist/message/media.d.ts +90 -0
  78. package/dist/message/media.js +123 -0
  79. package/dist/message/poll.d.ts +24 -0
  80. package/dist/message/poll.js +98 -0
  81. package/dist/message/reaction.d.ts +20 -0
  82. package/dist/message/reaction.js +71 -0
  83. package/dist/message/sticker.d.ts +29 -0
  84. package/dist/message/sticker.js +44 -0
  85. package/dist/message/target.d.ts +18 -0
  86. package/dist/message/target.js +24 -0
  87. package/dist/message/text.d.ts +17 -0
  88. package/dist/message/text.js +29 -0
  89. package/dist/message/vcard.d.ts +9 -0
  90. package/dist/message/vcard.js +23 -0
  91. package/dist/message/webp.d.ts +6 -0
  92. package/dist/message/webp.js +57 -0
  93. package/dist/payloads.d.ts +180 -0
  94. package/dist/payloads.js +1 -0
  95. package/dist/serialize.d.ts +41 -0
  96. package/dist/serialize.js +93 -0
  97. package/dist/status.d.ts +3 -0
  98. package/dist/status.js +21 -0
  99. package/dist/zapo-client.d.ts +44 -0
  100. package/dist/zapo-client.js +1 -0
  101. package/examples/airich.ts +59 -0
  102. package/examples/buttons.ts +48 -0
  103. package/examples/client-methods.ts +58 -0
  104. package/examples/hybrid.ts +133 -0
  105. package/examples/serialize.ts +61 -0
  106. package/package.json +271 -4
  107. package/scripts/check-no-comments.mjs +101 -0
  108. package/scripts/compare-golden.mjs +461 -0
  109. package/scripts/lib-config.mjs +9 -0
  110. package/scripts/smoke-auto.mjs +75 -0
  111. package/scripts/test-external-consumer.mjs +316 -0
  112. package/scripts/verify-package.mjs +78 -0
  113. package/src/airich/airich.ts +970 -0
  114. package/src/airich/context.ts +96 -0
  115. package/src/airich/encode.ts +25 -0
  116. package/src/airich/index.ts +98 -0
  117. package/src/airich/inline.ts +272 -0
  118. package/src/airich/nodes.ts +174 -0
  119. package/src/airich/primitives.ts +474 -0
  120. package/src/airich/protocol.ts +133 -0
  121. package/src/airich/table.ts +70 -0
  122. package/src/airich/tokenizer.ts +799 -0
  123. package/src/airich/transport.ts +106 -0
  124. package/src/branding.ts +23 -0
  125. package/src/btn/builders.ts +1073 -0
  126. package/src/btn/media-slot.ts +486 -0
  127. package/src/btn/media-source.ts +189 -0
  128. package/src/btn/sharp-loader.ts +23 -0
  129. package/src/btn/thumbnail.ts +182 -0
  130. package/src/btn/validators.ts +237 -0
  131. package/src/btn.ts +8 -0
  132. package/src/core/async-send.ts +28 -0
  133. package/src/core/base-builder.ts +104 -0
  134. package/src/core/errors.ts +82 -0
  135. package/src/download.ts +212 -0
  136. package/src/index.ts +229 -0
  137. package/src/integration/augment.ts +262 -0
  138. package/src/integration/auto.ts +103 -0
  139. package/src/integration/index.ts +8 -0
  140. package/src/integration/methods.ts +45 -0
  141. package/src/interactive.ts +188 -0
  142. package/src/media-gate.ts +499 -0
  143. package/src/message/album.ts +187 -0
  144. package/src/message/contact.ts +170 -0
  145. package/src/message/forward.ts +123 -0
  146. package/src/message/index.ts +83 -0
  147. package/src/message/link-preview.ts +148 -0
  148. package/src/message/location.ts +150 -0
  149. package/src/message/media.ts +323 -0
  150. package/src/message/poll.ts +158 -0
  151. package/src/message/reaction.ts +133 -0
  152. package/src/message/sticker.ts +100 -0
  153. package/src/message/target.ts +38 -0
  154. package/src/message/text.ts +61 -0
  155. package/src/message/vcard.ts +36 -0
  156. package/src/message/webp.ts +78 -0
  157. package/src/payloads.ts +204 -0
  158. package/src/serialize.ts +180 -0
  159. package/src/status.ts +29 -0
  160. package/src/zapo-client.ts +84 -0
  161. package/test/airich-inline.test.ts +200 -0
  162. package/test/airich-primitives.test.ts +226 -0
  163. package/test/airich-tokenizer.test.ts +145 -0
  164. package/test/airich.golden.test.ts +406 -0
  165. package/test/airich.test.ts +1006 -0
  166. package/test/btn-button.test.ts +416 -0
  167. package/test/btn-header.test.ts +646 -0
  168. package/test/btn-legacy.test.ts +342 -0
  169. package/test/btn-lifecycle.test.ts +295 -0
  170. package/test/btn-list.test.ts +261 -0
  171. package/test/btn-media-source.test.ts +150 -0
  172. package/test/btn-thumbnail.test.ts +160 -0
  173. package/test/builder-compat.test.ts +264 -0
  174. package/test/helpers.ts +27 -0
  175. package/test/hybrid-airich.test.ts +345 -0
  176. package/test/hybrid-client.test.ts +239 -0
  177. package/test/hybrid-errors.test.ts +557 -0
  178. package/test/hybrid-interactive.test.ts +455 -0
  179. package/test/hybrid.golden.test.ts +349 -0
  180. package/test/hybrid.test.ts +479 -0
  181. package/test/integration-auto.test.ts +159 -0
  182. package/test/integration.fakeserver.test.ts +440 -0
  183. package/test/media-gate.test.ts +215 -0
  184. package/test/message-album.test.ts +145 -0
  185. package/test/message-builders.test.ts +401 -0
  186. package/test/message-media.test.ts +303 -0
  187. package/test/message.fakeserver.test.ts +284 -0
  188. package/test/message.golden.test.ts +254 -0
  189. package/test/serializer.test.ts +448 -0
  190. package/tsconfig.json +26 -0
  191. package/tsconfig.test.json +10 -0
@@ -0,0 +1,239 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { createStore, WaClient } from "zapo-js";
4
+
5
+ import {
6
+ installZapoMessage,
7
+ ZAPO_MESSAGE_METHOD_NAMES,
8
+ type TextBuilder,
9
+ type MessageSendResult,
10
+ } from "@kyyinfinite/zapo-message";
11
+ import { asClient } from "./helpers.js";
12
+
13
+ const makeWaClient = () =>
14
+ new WaClient({ store: createStore({}), sessionId: "hybrid-test" });
15
+
16
+ const captureDuck = () => {
17
+ const sends: { to: unknown; content: unknown; options: unknown }[] = [];
18
+ const uploads: { source: unknown; options: unknown }[] = [];
19
+ const client = asClient({
20
+ message: {
21
+ upload: async (source: unknown, options: unknown) => {
22
+ uploads.push({ source, options });
23
+ return {
24
+ url: "https://mmg.whatsapp.net/v/t62.7118-24/golden",
25
+ directPath: "/v/t62.7118-24/golden",
26
+ mediaKey: new Uint8Array(32).fill(1),
27
+ fileSha256: new Uint8Array(32).fill(2),
28
+ fileEncSha256: new Uint8Array(32).fill(3),
29
+ fileLength: 1000,
30
+ mediaKeyTimestamp: 1730000000,
31
+ };
32
+ },
33
+ send: async (to: unknown, content: unknown, options: unknown) => {
34
+ sends.push({ to, content, options });
35
+ return { id: `ID-${sends.length}`, attempts: 1, ack: {} };
36
+ },
37
+ },
38
+ });
39
+ installZapoMessage(client);
40
+ return { client, sends, uploads };
41
+ };
42
+
43
+ const method = (
44
+ client: unknown,
45
+ name: string,
46
+ ): ((...args: unknown[]) => unknown) => {
47
+ const source = client as Record<string, (...args: unknown[]) => unknown>;
48
+ const fn = source[name];
49
+ assert.equal(typeof fn, "function", `${name} harus terpasang`);
50
+ return (fn as (...args: unknown[]) => unknown).bind(client);
51
+ };
52
+
53
+ test("client hybrid: text(jid, config) mengirim dan mengembalikan Promise", async () => {
54
+ const { client, sends } = captureDuck();
55
+ const result = (await method(client, "text")("6281@s.whatsapp.net", {
56
+ body: "Halo Dunia",
57
+ })) as MessageSendResult;
58
+ assert.equal(result.id, "ID-1");
59
+ assert.equal(sends.length, 1);
60
+ assert.equal(sends[0]?.to, "6281@s.whatsapp.net");
61
+ assert.deepEqual(sends[0]?.content, { conversation: "Halo Dunia" });
62
+ });
63
+
64
+ test("client hybrid: text() tetap mengembalikan builder", () => {
65
+ const { client } = captureDuck();
66
+ const builder = method(client, "text")() as TextBuilder;
67
+ assert.deepEqual(builder.body("halo").build(), { conversation: "halo" });
68
+ });
69
+
70
+ test("client hybrid: seluruh method async mengirim payload benar", async () => {
71
+ const duck = captureDuck();
72
+ const client = duck.client;
73
+
74
+ await method(client, "text")("6281@s.whatsapp.net", { body: "teks" });
75
+ await method(client, "linkPreview")("6281@s.whatsapp.net", {
76
+ body: "baca https://example.com",
77
+ });
78
+ await method(client, "contact")("6281@s.whatsapp.net", { name: "Budi" });
79
+ await method(client, "poll")("6281@s.whatsapp.net", {
80
+ question: "Q?",
81
+ options: ["A", "B"],
82
+ });
83
+ await method(client, "location")("6281@s.whatsapp.net", {
84
+ latitude: -6.2,
85
+ longitude: 106.8,
86
+ });
87
+ await method(client, "button")("6281@s.whatsapp.net", {
88
+ body: "Pilih",
89
+ buttons: [{ type: "quick_reply", text: "OK", id: "ok" }],
90
+ });
91
+ await method(client, "legacyButton")("6281@s.whatsapp.net", {
92
+ body: "Pilih",
93
+ buttons: [{ id: "ok", text: "OK" }],
94
+ });
95
+ await method(client, "listMessage")("6281@s.whatsapp.net", {
96
+ body: "Pilih",
97
+ buttonText: "Buka",
98
+ sections: [{ title: "Menu", rows: [{ id: "a", title: "A" }] }],
99
+ });
100
+ await method(client, "media")("6281@s.whatsapp.net", {
101
+ type: "document",
102
+ source: Buffer.from("dok"),
103
+ fileName: "nota.txt",
104
+ });
105
+ await method(client, "image")("6281@s.whatsapp.net", {
106
+ source: Buffer.from("png"),
107
+ mimetype: "image/png",
108
+ thumbnail: false,
109
+ });
110
+ await method(client, "video")("6281@s.whatsapp.net", {
111
+ source: Buffer.from("vid"),
112
+ mimetype: "video/mp4",
113
+ });
114
+ await method(client, "audio")("6281@s.whatsapp.net", {
115
+ source: Buffer.from("aud"),
116
+ mimetype: "audio/mp3",
117
+ });
118
+ await method(client, "document")("6281@s.whatsapp.net", {
119
+ source: Buffer.from("doc"),
120
+ fileName: "doc.pdf",
121
+ });
122
+ await method(client, "sticker")("6281@s.whatsapp.net", {
123
+ source: Buffer.concat([
124
+ Buffer.from([0x52, 0x49, 0x46, 0x46, 0x24, 0x00, 0x00, 0x00]),
125
+ Buffer.from("WEBPVP8 "),
126
+ Buffer.alloc(24, 1),
127
+ ]),
128
+ });
129
+ await method(client, "album")("6281@s.whatsapp.net", {
130
+ media: [
131
+ {
132
+ type: "image",
133
+ source: Buffer.from("a"),
134
+ options: { mimetype: "image/png", thumbnail: false },
135
+ },
136
+ ],
137
+ });
138
+ await method(client, "forward")("6281@s.whatsapp.net", {
139
+ message: {
140
+ key: { remoteJid: "628111@s.whatsapp.net", id: "M1", fromMe: false },
141
+ message: { conversation: "asal" },
142
+ },
143
+ });
144
+ await method(client, "reaction")("6281@s.whatsapp.net", {
145
+ target: {
146
+ key: { remoteJid: "6281@s.whatsapp.net", id: "M2", fromMe: false },
147
+ },
148
+ emoji: "🔥",
149
+ });
150
+ await method(client, "airich")("6281@s.whatsapp.net", {
151
+ sections: [{ type: "text", text: "rich" }],
152
+ });
153
+
154
+ assert.equal(
155
+ duck.sends.length,
156
+ 20,
157
+ "18 pesan + album 1 anak + airich 2 langkah",
158
+ );
159
+ assert.deepEqual(duck.sends[0]?.content, { conversation: "teks" });
160
+ assert.ok((duck.sends[14]?.content as Record<string, unknown>).albumMessage);
161
+ assert.ok(
162
+ (duck.sends[18]?.content as Record<string, unknown>).messageContextInfo,
163
+ );
164
+ assert.ok(
165
+ (duck.sends[19]?.content as Record<string, unknown>).botForwardedMessage,
166
+ );
167
+ });
168
+
169
+ test("client hybrid: WaClient asli mendapat seluruh method", () => {
170
+ const client = makeWaClient();
171
+ for (const name of ZAPO_MESSAGE_METHOD_NAMES) {
172
+ assert.equal(typeof method(client, name), "function", `${name} terpasang`);
173
+ }
174
+ assert.ok(ZAPO_MESSAGE_METHOD_NAMES.includes("image"));
175
+ assert.ok(ZAPO_MESSAGE_METHOD_NAMES.includes("location"));
176
+ assert.ok(ZAPO_MESSAGE_METHOD_NAMES.includes("video"));
177
+ assert.ok(ZAPO_MESSAGE_METHOD_NAMES.includes("audio"));
178
+ assert.ok(ZAPO_MESSAGE_METHOD_NAMES.includes("document"));
179
+ });
180
+
181
+ test("client hybrid: WaClient asli mengirim via async API", async () => {
182
+ const client = makeWaClient();
183
+ const originalSend = client.message.send.bind(client.message);
184
+ let captured: { to: unknown; content: unknown } | undefined;
185
+ client.message.send = async (to, content) => {
186
+ captured = { to, content };
187
+ return {
188
+ id: "WACLIENT-1",
189
+ attempts: 1,
190
+ ack: { refreshLid: false },
191
+ ackNode: undefined as never,
192
+ };
193
+ };
194
+ try {
195
+ const result = (await method(client, "text")("6281@s.whatsapp.net", {
196
+ body: "via wa",
197
+ })) as { id: string };
198
+ assert.equal(result.id, "WACLIENT-1");
199
+ assert.equal(captured?.to, "6281@s.whatsapp.net");
200
+ assert.deepEqual(captured?.content, { conversation: "via wa" });
201
+ } finally {
202
+ client.message.send = originalSend;
203
+ }
204
+ });
205
+
206
+ test("client hybrid: options quote diteruskan identik", async () => {
207
+ const { client, sends } = captureDuck();
208
+ const incoming = {
209
+ key: { remoteJid: "6281@s.whatsapp.net", id: "RE-1", fromMe: false },
210
+ message: { conversation: "asal" },
211
+ };
212
+ await method(client, "text")(
213
+ "6281@s.whatsapp.net",
214
+ { body: "balasan" },
215
+ { quote: incoming },
216
+ );
217
+ assert.equal(sends.length, 1);
218
+ assert.equal((sends[0]?.options as Record<string, unknown>).quote, incoming);
219
+ });
220
+
221
+ test("client hybrid: pemanggilan tanpa config tetap builder (kompatibilitas)", () => {
222
+ const { client } = captureDuck();
223
+ const builder = method(client, "text")("6281@s.whatsapp.net") as TextBuilder;
224
+ assert.equal(typeof (builder as TextBuilder).body, "function");
225
+ const reactionBuilder = method(client, "reaction")("6281@s.whatsapp.net");
226
+ assert.equal(typeof reactionBuilder, "object");
227
+ });
228
+
229
+ test("client hybrid: no-override tetap dihormati", () => {
230
+ const withNative = {
231
+ image() {
232
+ return "asli";
233
+ },
234
+ message: { send: async () => ({}) },
235
+ };
236
+ const fake = Object.create(withNative);
237
+ installZapoMessage(fake as never);
238
+ assert.equal(fake.image(), "asli", "method native tidak tertimpa");
239
+ });