@kyyinfinite/zapo-message 0.0.0-stage → 1.0.0

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 +532 -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 +38 -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,461 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+
5
+ const avelynaArg = process.argv.find((arg) => arg.startsWith("--avelyna="));
6
+ if (!avelynaArg) {
7
+ console.error(
8
+ "usage: node scripts/compare-golden.mjs --avelyna=<path-to-avelyna-repo>",
9
+ );
10
+ process.exit(1);
11
+ }
12
+ const avelynaRoot = resolve(avelynaArg.replace("--avelyna=", ""));
13
+ const messageLib = resolve(avelynaRoot, "src/lib/message/index.js");
14
+ if (!existsSync(messageLib)) {
15
+ console.error(`avelyna message library not found at ${messageLib}`);
16
+ process.exit(1);
17
+ }
18
+
19
+ process.chdir(avelynaRoot);
20
+ const legacy = await import(pathToFileURL(messageLib));
21
+ const legacyInteractive = await import(
22
+ pathToFileURL(resolve(avelynaRoot, "src/lib/message/interactive.js"))
23
+ );
24
+
25
+ process.chdir(new URL("..", import.meta.url).pathname);
26
+ const modern = await import("@kyyinfinite/zapo-message");
27
+ const modernInteractive =
28
+ await import("@kyyinfinite/zapo-message/interactive.js");
29
+
30
+ const results = [];
31
+ const record = (name, ok, detail) => {
32
+ results.push({ name, ok, detail: detail ?? "" });
33
+ };
34
+
35
+ const compare = (name, a, b) => {
36
+ const sa = JSON.stringify(a);
37
+ const sb = JSON.stringify(b);
38
+ record(name, sa === sb, sa === sb ? "" : `legacy=${sa} modern=${sb}`);
39
+ };
40
+
41
+ const noopLegacy = {
42
+ message: {
43
+ async send() {
44
+ return { id: "X" };
45
+ },
46
+ },
47
+ };
48
+ const noopModern = {
49
+ message: {
50
+ async send() {
51
+ return { id: "X" };
52
+ },
53
+ },
54
+ };
55
+
56
+ {
57
+ const legacyPayload = await legacy
58
+ .button(noopLegacy)
59
+ .title("Judul")
60
+ .body("Isi")
61
+ .footer("Footer")
62
+ .quick_reply("QR", "cmd qr")
63
+ .cta_url("Buka", "https://example.com/path?x=1")
64
+ .cta_copy("Salin", "KODE123")
65
+ .cta_call("Telepon", "+628123456789")
66
+ .send_location("Kirim lokasi")
67
+ .single_select("Pilih", [
68
+ {
69
+ title: "Utama",
70
+ rows: [{ id: "row1", title: "Baris Satu", description: "desc" }],
71
+ },
72
+ ])
73
+ .bottom_sheet({ limit: 2, listTitle: "Daftar", buttonTitle: "Buka" })
74
+ .limited_time_offer({ copyCode: "OFFER", expiresIn: 3600 })
75
+ .build();
76
+
77
+ const modernPayload = await modern
78
+ .button(noopModern)
79
+ .title("Judul")
80
+ .body("Isi")
81
+ .footer("Footer")
82
+ .quick_reply("QR", "cmd qr")
83
+ .cta_url("Buka", "https://example.com/path?x=1")
84
+ .cta_copy("Salin", "KODE123")
85
+ .cta_call("Telepon", "+628123456789")
86
+ .send_location("Kirim lokasi")
87
+ .single_select("Pilih", [
88
+ {
89
+ title: "Utama",
90
+ rows: [{ id: "row1", title: "Baris Satu", description: "desc" }],
91
+ },
92
+ ])
93
+ .bottom_sheet({ limit: 2, listTitle: "Daftar", buttonTitle: "Buka" })
94
+ .limited_time_offer({ copyCode: "OFFER", expiresIn: 3600 })
95
+ .build();
96
+
97
+ const stripVolatile = (payload) => {
98
+ const flow = payload.interactiveMessage.nativeFlowMessage;
99
+ if (flow.messageParamsJson) {
100
+ const params = JSON.parse(flow.messageParamsJson);
101
+ if (params.limited_time_offer) {
102
+ delete params.limited_time_offer.expiration_time;
103
+ flow.messageParamsJson = JSON.stringify(params);
104
+ }
105
+ }
106
+ return payload;
107
+ };
108
+
109
+ compare(
110
+ "button: interactiveMessage payload (buttons, params, messageParamsJson)",
111
+ stripVolatile(legacyPayload),
112
+ stripVolatile(modernPayload),
113
+ );
114
+ compare(
115
+ "button: buttonParamsJson string-for-string",
116
+ legacyPayload.interactiveMessage.nativeFlowMessage.buttons.map(
117
+ (b) => b.buttonParamsJson,
118
+ ),
119
+ modernPayload.interactiveMessage.nativeFlowMessage.buttons.map(
120
+ (b) => b.buttonParamsJson,
121
+ ),
122
+ );
123
+ }
124
+
125
+ {
126
+ const legacyLegacy = await legacy
127
+ .legacyButton(noopLegacy)
128
+ .title("Judul Legacy")
129
+ .body("Konten")
130
+ .footer("Footer")
131
+ .button("b1", "Satu")
132
+ .button("b2", "Dua")
133
+ .build();
134
+
135
+ const modernLegacy = await modern
136
+ .legacyButton(noopModern)
137
+ .title("Judul Legacy")
138
+ .body("Konten")
139
+ .footer("Footer")
140
+ .button("b1", "Satu")
141
+ .button("b2", "Dua")
142
+ .build();
143
+
144
+ compare("legacyButton: buttonsMessage payload", legacyLegacy, modernLegacy);
145
+ }
146
+
147
+ {
148
+ const legacyList = legacy
149
+ .listMessage(noopLegacy)
150
+ .title("Menu")
151
+ .body("Deskripsi")
152
+ .buttonText("Pilih")
153
+ .footer("Footer")
154
+ .section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
155
+ .build();
156
+
157
+ const modernList = modern
158
+ .listMessage(noopModern)
159
+ .title("Menu")
160
+ .body("Deskripsi")
161
+ .buttonText("Pilih")
162
+ .footer("Footer")
163
+ .section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
164
+ .build();
165
+
166
+ compare("listMessage: classic payload", legacyList, modernList);
167
+
168
+ const legacyNative = legacy
169
+ .listMessage(noopLegacy)
170
+ .title("Menu")
171
+ .body("Deskripsi")
172
+ .buttonText("Pilih")
173
+ .footer("Footer")
174
+ .section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
175
+ .toNativeFlow();
176
+
177
+ const modernNative = modern
178
+ .listMessage(noopModern)
179
+ .title("Menu")
180
+ .body("Deskripsi")
181
+ .buttonText("Pilih")
182
+ .footer("Footer")
183
+ .section("Utama", [{ id: "r1", title: "Baris", description: "deskripsi" }])
184
+ .toNativeFlow();
185
+
186
+ compare("listMessage: native flow payload", legacyNative, modernNative);
187
+ }
188
+
189
+ {
190
+ const buildRich = (impl, client) =>
191
+ impl
192
+ .airich(client)
193
+ .text("unicode ☕ café — [link](https://example.com)")
194
+ .code("javascript", 'const x = "☕"')
195
+ .table([
196
+ ["H1", "H2"],
197
+ ["a", "b"],
198
+ ])
199
+ .suggest(["satu", "dua"])
200
+ .footer("catatan")
201
+ .build({ submessages: false });
202
+
203
+ const legacyRich = buildRich(legacy, noopLegacy);
204
+ const modernRich = buildRich(modern, noopModern);
205
+
206
+ const decode = (payload) =>
207
+ JSON.parse(
208
+ Buffer.from(
209
+ payload.botForwardedMessage.message.richResponseMessage.unifiedResponse
210
+ .data,
211
+ ).toString("utf8"),
212
+ );
213
+
214
+ const legacyDecoded = decode(legacyRich);
215
+ const modernDecoded = decode(modernRich);
216
+
217
+ delete legacyDecoded.response_id;
218
+ delete modernDecoded.response_id;
219
+ compare(
220
+ "airich: unified response sections (text/code/table/suggest/footer)",
221
+ legacyDecoded,
222
+ modernDecoded,
223
+ );
224
+
225
+ compare(
226
+ "airich: submessages",
227
+ legacyRich.botForwardedMessage.message.richResponseMessage.submessages,
228
+ modernRich.botForwardedMessage.message.richResponseMessage.submessages,
229
+ );
230
+
231
+ compare(
232
+ "airich: contextInfo",
233
+ legacyRich.botForwardedMessage.message.richResponseMessage.contextInfo,
234
+ modernRich.botForwardedMessage.message.richResponseMessage.contextInfo,
235
+ );
236
+
237
+ const legacyBytes =
238
+ legacyRich.botForwardedMessage.message.richResponseMessage.unifiedResponse
239
+ .data;
240
+ const modernBytes =
241
+ modernRich.botForwardedMessage.message.richResponseMessage.unifiedResponse
242
+ .data;
243
+ const legacyText = Buffer.from(legacyBytes).toString("utf8");
244
+ const modernText = Buffer.from(modernBytes).toString("utf8");
245
+ const legacyPatched = legacyText.replace(
246
+ /"response_id":"[0-9a-f-]{36}"/,
247
+ '"response_id":"FIXED"',
248
+ );
249
+ const modernPatched = modernText.replace(
250
+ /"response_id":"[0-9a-f-]{36}"/,
251
+ '"response_id":"FIXED"',
252
+ );
253
+ record(
254
+ "airich: unified response bytes byte-for-byte (response_id fixed)",
255
+ legacyPatched === modernPatched,
256
+ legacyPatched === modernPatched
257
+ ? ""
258
+ : `legacy=${legacyPatched} modern=${modernPatched}`,
259
+ );
260
+ }
261
+
262
+ {
263
+ const legacyPlaceholder = new legacy.AIRich(noopLegacy, {
264
+ botJid: "123@bot",
265
+ });
266
+ legacyPlaceholder.context({
267
+ mentionedJid: ["6281@s.whatsapp.net"],
268
+ expiration: 7776000,
269
+ });
270
+ const legacyP = legacyPlaceholder.buildPlaceholder();
271
+
272
+ const modernPlaceholder = new modern.AIRich(noopModern, {
273
+ botJid: "123@bot",
274
+ });
275
+ modernPlaceholder.context({
276
+ mentionedJid: ["6281@s.whatsapp.net"],
277
+ expiration: 7776000,
278
+ });
279
+ const modernP = modernPlaceholder.buildPlaceholder();
280
+
281
+ const stripSecret = (p) => {
282
+ const copy = JSON.parse(
283
+ JSON.stringify(p, (k, v) => (k === "messageSecret" ? "RANDOM" : v)),
284
+ );
285
+ const rich = copy.botForwardedMessage.message.richResponseMessage;
286
+ const text = Buffer.from(rich.unifiedResponse.data).toString("utf8");
287
+ rich.unifiedResponse.data = Buffer.from(
288
+ text.replace(/"response_id":"[0-9a-f-]{36}"/, '"response_id":"FIXED"'),
289
+ );
290
+ return copy;
291
+ };
292
+ compare(
293
+ "airich: placeholder payload (messageSecret + response_id masked)",
294
+ stripSecret(legacyP),
295
+ stripSecret(modernP),
296
+ );
297
+ }
298
+
299
+ {
300
+ const legacyEdit = legacy
301
+ .airich(noopLegacy)
302
+ .text("edit ini")
303
+ .buildEdit("6281@s.whatsapp.net", "PLACEHOLDER", { submessages: false });
304
+ const modernEdit = modern
305
+ .airich(noopModern)
306
+ .text("edit ini")
307
+ .buildEdit("6281@s.whatsapp.net", "PLACEHOLDER", { submessages: false });
308
+
309
+ const stripRichId = (payload) => {
310
+ const copy = JSON.parse(JSON.stringify(payload));
311
+ const rich =
312
+ copy.botForwardedMessage.message.protocolMessage.editedMessage
313
+ .botForwardedMessage.message.richResponseMessage;
314
+ const text = Buffer.from(rich.unifiedResponse.data).toString("utf8");
315
+ rich.unifiedResponse.data = Buffer.from(
316
+ text.replace(/"response_id":"[0-9a-f-]{36}"/, '"response_id":"FIXED"'),
317
+ );
318
+ return copy;
319
+ };
320
+ compare(
321
+ "airich: protocol edit payload (type 14, key, editedMessage)",
322
+ stripRichId(legacyEdit),
323
+ stripRichId(modernEdit),
324
+ );
325
+ }
326
+
327
+ {
328
+ const legacyTable = legacy.toTable([["A", "B"], ["c"]]);
329
+ const modernTable = modern.toTable([["A", "B"], ["c"]]);
330
+ compare("toTable: unified + legacy rows", legacyTable, modernTable);
331
+
332
+ const legacyInline = legacy.parseInline(
333
+ "lihat [web](https://a.com) ref [](https://b.com) [E|10]<https://c.com/i.png>",
334
+ );
335
+ const modernInline = modern.parseInline(
336
+ "lihat [web](https://a.com) ref [](https://b.com) [E|10]<https://c.com/i.png>",
337
+ );
338
+ compare("parseInline: entities + tags", legacyInline, modernInline);
339
+
340
+ const legacyTokens = legacy.tokenizeCode(
341
+ '=> conn.relayMessage(m.chat, { extendedTextMessage: { text: "x" } }, {})\nconst a = 1 // note',
342
+ "javascript",
343
+ );
344
+ const modernTokens = modern.tokenizeCode(
345
+ '=> conn.relayMessage(m.chat, { extendedTextMessage: { text: "x" } }, {})\nconst a = 1 // note',
346
+ "javascript",
347
+ );
348
+ compare("tokenizeCode: tokens", legacyTokens, modernTokens);
349
+
350
+ compare(
351
+ "layout: Single",
352
+ legacy.layout("Single", { text: "x" }),
353
+ modern.layout("Single", { text: "x" }),
354
+ );
355
+ compare(
356
+ "layout: HScroll + extra",
357
+ legacy.layout("HScroll", [{ a: 1 }], {
358
+ __typename: "GenAIUnifiedResponseSection",
359
+ }),
360
+ modern.layout("HScroll", [{ a: 1 }], {
361
+ __typename: "GenAIUnifiedResponseSection",
362
+ }),
363
+ );
364
+ compare(
365
+ "forwardInfo",
366
+ legacy.forwardInfo("1@bot"),
367
+ modern.forwardInfo("1@bot"),
368
+ );
369
+ compare(
370
+ "buildContextInfo",
371
+ legacy.buildContextInfo({
372
+ botJid: "1@bot",
373
+ quote: null,
374
+ contextInfo: { expiration: 1 },
375
+ }),
376
+ modern.buildContextInfo({
377
+ botJid: "1@bot",
378
+ quote: null,
379
+ contextInfo: { expiration: 1 },
380
+ }),
381
+ );
382
+ compare(
383
+ "sendAttributes",
384
+ legacy.sendAttributes({
385
+ additionalAttributes: { ephemerality: "ephemeral" },
386
+ }),
387
+ modern.sendAttributes({
388
+ additionalAttributes: { ephemerality: "ephemeral" },
389
+ }),
390
+ );
391
+ compare(
392
+ "stringifyEscaped",
393
+ legacy.stringifyEscaped({ k: "café ☕" }),
394
+ modern.stringifyEscaped({ k: "café ☕" }),
395
+ );
396
+ }
397
+
398
+ {
399
+ const buttonsResponse = {
400
+ buttonsResponseMessage: {
401
+ selectedButtonId: "menu tools",
402
+ selectedDisplayText: "Tools",
403
+ },
404
+ };
405
+ const listResponse = {
406
+ listResponseMessage: {
407
+ title: "T",
408
+ singleSelectReply: { selectedRowId: "menu owner" },
409
+ },
410
+ };
411
+ const nativeFlow = {
412
+ interactiveResponseMessage: {
413
+ nativeFlowResponseMessage: {
414
+ name: "quick_reply",
415
+ paramsJson: JSON.stringify({ display_text: "OK", id: "menu ok" }),
416
+ },
417
+ },
418
+ };
419
+
420
+ const legacyExtract = (message) =>
421
+ legacyInteractive.extractInteractiveResponse(message);
422
+ const modernExtract = (message) =>
423
+ modernInteractive.extractInteractiveResponse(message);
424
+
425
+ compare(
426
+ "interactive: buttonsResponseMessage",
427
+ legacyExtract(buttonsResponse),
428
+ modernExtract(buttonsResponse),
429
+ );
430
+ compare(
431
+ "interactive: listResponseMessage",
432
+ legacyExtract(listResponse),
433
+ modernExtract(listResponse),
434
+ );
435
+ compare(
436
+ "interactive: nativeFlow",
437
+ legacyExtract(nativeFlow),
438
+ modernExtract(nativeFlow),
439
+ );
440
+ compare(
441
+ "interactive: plain message",
442
+ legacyExtract({ conversation: "halo" }),
443
+ modernExtract({ conversation: "halo" }),
444
+ );
445
+ compare(
446
+ "interactive: envelope",
447
+ legacyExtract({ ephemeralMessage: { message: buttonsResponse } }),
448
+ modernExtract({ ephemeralMessage: { message: buttonsResponse } }),
449
+ );
450
+ }
451
+
452
+ const failures = results.filter((r) => !r.ok);
453
+ for (const result of results) {
454
+ console.log(
455
+ `${result.ok ? "MATCH" : "DIFF "} ${result.name}${result.ok ? "" : ` :: ${result.detail}`}`,
456
+ );
457
+ }
458
+ console.log(
459
+ `\ngolden comparison: ${results.length - failures.length}/${results.length} match, ${failures.length} differ`,
460
+ );
461
+ if (failures.length > 0) process.exit(1);
@@ -0,0 +1,9 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ export const readConfig = async () => {
4
+ const raw = readFileSync(
5
+ new URL("../build.config.json", import.meta.url),
6
+ "utf8",
7
+ );
8
+ return JSON.parse(raw);
9
+ };
@@ -0,0 +1,75 @@
1
+ import { createStore, WaClient } from "zapo-js";
2
+ import "../dist/index.js";
3
+
4
+ const store = createStore({});
5
+ const client = new WaClient({ store, sessionId: "smoke" });
6
+
7
+ const checks = [];
8
+ checks.push(["button", typeof client.button]);
9
+ checks.push(["legacyButton", typeof client.legacyButton]);
10
+ checks.push(["listMessage", typeof client.listMessage]);
11
+ checks.push(["airich", typeof client.airich]);
12
+ checks.push(["text", typeof client.text]);
13
+ checks.push(["reaction", typeof client.reaction]);
14
+ checks.push(["media", typeof client.media]);
15
+ checks.push(["sticker", typeof client.sticker]);
16
+ checks.push(["contact", typeof client.contact]);
17
+ checks.push(["poll", typeof client.poll]);
18
+ checks.push(["album", typeof client.album]);
19
+ checks.push(["linkPreview", typeof client.linkPreview]);
20
+ checks.push(["forward", typeof client.forward]);
21
+
22
+ for (const [name, kind] of checks) {
23
+ console.log(name, "=", kind);
24
+ }
25
+
26
+ const b = client.text().body("halo");
27
+ const payload = b.build();
28
+ console.log("text payload:", JSON.stringify(payload));
29
+
30
+ const second = new WaClient({ store, sessionId: "smoke2" });
31
+ console.log("second client text:", typeof second.text);
32
+
33
+ const enumerated = Object.getOwnPropertyNames(Object.getPrototypeOf(client))
34
+ .filter((n) => n !== "constructor")
35
+ .sort();
36
+ console.log(
37
+ "prototype methods sample:",
38
+ enumerated.filter((n) => ["button", "text", "poll", "forward"].includes(n)),
39
+ );
40
+
41
+ const reactionPayload = client
42
+ .reaction()
43
+ .target({
44
+ key: { remoteJid: "6281@s.whatsapp.net", id: "ABC", fromMe: false },
45
+ })
46
+ .emoji("🔥")
47
+ .build();
48
+ console.log("reaction payload:", JSON.stringify(reactionPayload));
49
+
50
+ const pollPayload = client.poll().question("Pilih").options(["A", "B"]).build();
51
+ console.log("poll payload:", JSON.stringify(pollPayload));
52
+
53
+ const contactPayload = client
54
+ .contact()
55
+ .name("Budi")
56
+ .phone("+628123456789")
57
+ .build();
58
+ console.log("contact payload:", JSON.stringify(contactPayload));
59
+
60
+ const forwardPayload = client
61
+ .forward()
62
+ .message({ message: { conversation: "hai" } })
63
+ .build();
64
+ console.log("forward payload:", JSON.stringify(forwardPayload));
65
+
66
+ const linkPayload = client
67
+ .linkPreview()
68
+ .body("kunjungi https://example.com ya")
69
+ .title("Contoh")
70
+ .build();
71
+ console.log("linkPreview payload:", JSON.stringify(linkPayload));
72
+
73
+ await client.disconnect().catch(() => {});
74
+ await second.disconnect().catch(() => {});
75
+ console.log("SMOKE OK");