@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.
- package/CHANGELOG.md +159 -0
- package/LICENSE +20 -0
- package/README.md +532 -2
- package/build.config.json +28 -0
- package/dist/airich/airich.d.ts +180 -0
- package/dist/airich/airich.js +548 -0
- package/dist/airich/context.d.ts +24 -0
- package/dist/airich/context.js +48 -0
- package/dist/airich/encode.d.ts +3 -0
- package/dist/airich/encode.js +16 -0
- package/dist/airich/index.d.ts +20 -0
- package/dist/airich/index.js +11 -0
- package/dist/airich/inline.d.ts +45 -0
- package/dist/airich/inline.js +152 -0
- package/dist/airich/nodes.d.ts +30 -0
- package/dist/airich/nodes.js +121 -0
- package/dist/airich/primitives.d.ts +144 -0
- package/dist/airich/primitives.js +230 -0
- package/dist/airich/protocol.d.ts +35 -0
- package/dist/airich/protocol.js +65 -0
- package/dist/airich/table.d.ts +22 -0
- package/dist/airich/table.js +35 -0
- package/dist/airich/tokenizer.d.ts +13 -0
- package/dist/airich/tokenizer.js +717 -0
- package/dist/airich/transport.d.ts +15 -0
- package/dist/airich/transport.js +56 -0
- package/dist/branding.d.ts +5 -0
- package/dist/branding.js +9 -0
- package/dist/btn/builders.d.ts +246 -0
- package/dist/btn/builders.js +710 -0
- package/dist/btn/media-slot.d.ts +28 -0
- package/dist/btn/media-slot.js +323 -0
- package/dist/btn/media-source.d.ts +38 -0
- package/dist/btn/media-source.js +116 -0
- package/dist/btn/sharp-loader.d.ts +5 -0
- package/dist/btn/sharp-loader.js +18 -0
- package/dist/btn/thumbnail.d.ts +21 -0
- package/dist/btn/thumbnail.js +124 -0
- package/dist/btn/validators.d.ts +40 -0
- package/dist/btn/validators.js +135 -0
- package/dist/btn.d.ts +1 -0
- package/dist/btn.js +1 -0
- package/dist/core/async-send.d.ts +20 -0
- package/dist/core/async-send.js +1 -0
- package/dist/core/base-builder.d.ts +20 -0
- package/dist/core/base-builder.js +67 -0
- package/dist/core/errors.d.ts +30 -0
- package/dist/core/errors.js +61 -0
- package/dist/download.d.ts +24 -0
- package/dist/download.js +123 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +22 -0
- package/dist/integration/augment.d.ts +97 -0
- package/dist/integration/augment.js +1 -0
- package/dist/integration/auto.d.ts +8 -0
- package/dist/integration/auto.js +79 -0
- package/dist/integration/index.d.ts +4 -0
- package/dist/integration/index.js +2 -0
- package/dist/integration/methods.d.ts +25 -0
- package/dist/integration/methods.js +24 -0
- package/dist/interactive.d.ts +24 -0
- package/dist/interactive.js +121 -0
- package/dist/media-gate.d.ts +99 -0
- package/dist/media-gate.js +322 -0
- package/dist/message/album.d.ts +33 -0
- package/dist/message/album.js +107 -0
- package/dist/message/contact.d.ts +29 -0
- package/dist/message/contact.js +123 -0
- package/dist/message/forward.d.ts +23 -0
- package/dist/message/forward.js +77 -0
- package/dist/message/index.d.ts +26 -0
- package/dist/message/index.js +13 -0
- package/dist/message/link-preview.d.ts +28 -0
- package/dist/message/link-preview.js +98 -0
- package/dist/message/location.d.ts +24 -0
- package/dist/message/location.js +94 -0
- package/dist/message/media.d.ts +90 -0
- package/dist/message/media.js +123 -0
- package/dist/message/poll.d.ts +24 -0
- package/dist/message/poll.js +98 -0
- package/dist/message/reaction.d.ts +20 -0
- package/dist/message/reaction.js +71 -0
- package/dist/message/sticker.d.ts +29 -0
- package/dist/message/sticker.js +44 -0
- package/dist/message/target.d.ts +18 -0
- package/dist/message/target.js +24 -0
- package/dist/message/text.d.ts +17 -0
- package/dist/message/text.js +29 -0
- package/dist/message/vcard.d.ts +9 -0
- package/dist/message/vcard.js +23 -0
- package/dist/message/webp.d.ts +6 -0
- package/dist/message/webp.js +57 -0
- package/dist/payloads.d.ts +180 -0
- package/dist/payloads.js +1 -0
- package/dist/serialize.d.ts +41 -0
- package/dist/serialize.js +93 -0
- package/dist/status.d.ts +3 -0
- package/dist/status.js +21 -0
- package/dist/zapo-client.d.ts +44 -0
- package/dist/zapo-client.js +1 -0
- package/examples/airich.ts +59 -0
- package/examples/buttons.ts +48 -0
- package/examples/client-methods.ts +58 -0
- package/examples/hybrid.ts +133 -0
- package/examples/serialize.ts +61 -0
- package/package.json +271 -4
- package/scripts/check-no-comments.mjs +101 -0
- package/scripts/compare-golden.mjs +461 -0
- package/scripts/lib-config.mjs +9 -0
- package/scripts/smoke-auto.mjs +75 -0
- package/scripts/test-external-consumer.mjs +316 -0
- package/scripts/verify-package.mjs +78 -0
- package/src/airich/airich.ts +970 -0
- package/src/airich/context.ts +96 -0
- package/src/airich/encode.ts +25 -0
- package/src/airich/index.ts +98 -0
- package/src/airich/inline.ts +272 -0
- package/src/airich/nodes.ts +174 -0
- package/src/airich/primitives.ts +474 -0
- package/src/airich/protocol.ts +133 -0
- package/src/airich/table.ts +70 -0
- package/src/airich/tokenizer.ts +799 -0
- package/src/airich/transport.ts +106 -0
- package/src/branding.ts +23 -0
- package/src/btn/builders.ts +1073 -0
- package/src/btn/media-slot.ts +486 -0
- package/src/btn/media-source.ts +189 -0
- package/src/btn/sharp-loader.ts +23 -0
- package/src/btn/thumbnail.ts +182 -0
- package/src/btn/validators.ts +237 -0
- package/src/btn.ts +8 -0
- package/src/core/async-send.ts +28 -0
- package/src/core/base-builder.ts +104 -0
- package/src/core/errors.ts +82 -0
- package/src/download.ts +212 -0
- package/src/index.ts +229 -0
- package/src/integration/augment.ts +262 -0
- package/src/integration/auto.ts +103 -0
- package/src/integration/index.ts +8 -0
- package/src/integration/methods.ts +45 -0
- package/src/interactive.ts +188 -0
- package/src/media-gate.ts +499 -0
- package/src/message/album.ts +187 -0
- package/src/message/contact.ts +170 -0
- package/src/message/forward.ts +123 -0
- package/src/message/index.ts +83 -0
- package/src/message/link-preview.ts +148 -0
- package/src/message/location.ts +150 -0
- package/src/message/media.ts +323 -0
- package/src/message/poll.ts +158 -0
- package/src/message/reaction.ts +133 -0
- package/src/message/sticker.ts +100 -0
- package/src/message/target.ts +38 -0
- package/src/message/text.ts +61 -0
- package/src/message/vcard.ts +36 -0
- package/src/message/webp.ts +78 -0
- package/src/payloads.ts +204 -0
- package/src/serialize.ts +180 -0
- package/src/status.ts +29 -0
- package/src/zapo-client.ts +84 -0
- package/test/airich-inline.test.ts +200 -0
- package/test/airich-primitives.test.ts +226 -0
- package/test/airich-tokenizer.test.ts +145 -0
- package/test/airich.golden.test.ts +406 -0
- package/test/airich.test.ts +1006 -0
- package/test/btn-button.test.ts +416 -0
- package/test/btn-header.test.ts +646 -0
- package/test/btn-legacy.test.ts +342 -0
- package/test/btn-lifecycle.test.ts +295 -0
- package/test/btn-list.test.ts +261 -0
- package/test/btn-media-source.test.ts +150 -0
- package/test/btn-thumbnail.test.ts +160 -0
- package/test/builder-compat.test.ts +264 -0
- package/test/helpers.ts +27 -0
- package/test/hybrid-airich.test.ts +345 -0
- package/test/hybrid-client.test.ts +239 -0
- package/test/hybrid-errors.test.ts +557 -0
- package/test/hybrid-interactive.test.ts +455 -0
- package/test/hybrid.golden.test.ts +349 -0
- package/test/hybrid.test.ts +479 -0
- package/test/integration-auto.test.ts +159 -0
- package/test/integration.fakeserver.test.ts +440 -0
- package/test/media-gate.test.ts +215 -0
- package/test/message-album.test.ts +145 -0
- package/test/message-builders.test.ts +401 -0
- package/test/message-media.test.ts +303 -0
- package/test/message.fakeserver.test.ts +284 -0
- package/test/message.golden.test.ts +254 -0
- package/test/serializer.test.ts +448 -0
- package/tsconfig.json +26 -0
- package/tsconfig.test.json +10 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
mkdtempSync,
|
|
5
|
+
writeFileSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
cpSync,
|
|
8
|
+
existsSync,
|
|
9
|
+
readFileSync,
|
|
10
|
+
} from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join, dirname } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { readConfig } from "./lib-config.mjs";
|
|
15
|
+
|
|
16
|
+
const config = await readConfig();
|
|
17
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
18
|
+
const pkgVersion = JSON.parse(
|
|
19
|
+
readFileSync(join(packageRoot, "package.json"), "utf8"),
|
|
20
|
+
).version;
|
|
21
|
+
|
|
22
|
+
execFileSync("npm", ["pack", "--quiet"], {
|
|
23
|
+
cwd: packageRoot,
|
|
24
|
+
stdio: ["ignore", "pipe", "inherit"],
|
|
25
|
+
});
|
|
26
|
+
const tarball = join(packageRoot, `kyyinfinite-zapo-message-${pkgVersion}.tgz`);
|
|
27
|
+
|
|
28
|
+
const work = mkdtempSync(join(tmpdir(), "zapo-message-consumer-"));
|
|
29
|
+
try {
|
|
30
|
+
execFileSync("npm", ["init", "-y"], { cwd: work, stdio: "ignore" });
|
|
31
|
+
execFileSync(
|
|
32
|
+
"npm",
|
|
33
|
+
["install", tarball, "zapo-js@1.11.0", "--no-audit", "--no-fund"],
|
|
34
|
+
{ cwd: work, stdio: "inherit" },
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const consumer = `
|
|
38
|
+
import { button, legacyButton, listMessage, airich, messageKit, BaseBuilder, isClient } from '@kyyinfinite/zapo-message'
|
|
39
|
+
import { MessageError, ValidationError, ItemNotFoundError, DuplicateIdError, InvalidTargetError, ProtocolSendError, MediaError } from '@kyyinfinite/zapo-message'
|
|
40
|
+
import { AIRich, parseInline, toTable, tokenizeCode } from '@kyyinfinite/zapo-message'
|
|
41
|
+
import { encodeUnifiedResponse, decodeUnifiedResponse, stringifyEscaped } from '@kyyinfinite/zapo-message'
|
|
42
|
+
import { buildRichResponse, wrapBotForwarded, buildPlaceholderContent, buildEditContent, layout, ZWSP } from '@kyyinfinite/zapo-message'
|
|
43
|
+
import { forwardInfo, buildContextInfo, filterContextInfo, ALLOWED_CONTEXT_FIELDS, BUILDER_CONTROLLED_CONTEXT_FIELDS } from '@kyyinfinite/zapo-message'
|
|
44
|
+
import { sendViaZapo, sendPlaceholderThenEdit, sendAttributes, isZapoClient } from '@kyyinfinite/zapo-message'
|
|
45
|
+
import { EXPERIMENTAL_PRIMITIVES } from '@kyyinfinite/zapo-message'
|
|
46
|
+
import type { ButtonBuildResult, WrapBotForwardedResult, ZapoClient } from '@kyyinfinite/zapo-message'
|
|
47
|
+
import { mSerialize, qSerialize, extractText } from '@kyyinfinite/zapo-message/serialize.js'
|
|
48
|
+
import { extractInteractiveResponse, inspectInteractiveContext } from '@kyyinfinite/zapo-message/interactive.js'
|
|
49
|
+
import { toBoldSans, formatStatus } from '@kyyinfinite/zapo-message/status.js'
|
|
50
|
+
import { configureSharedMediaQueue, resetSharedMediaQueue, createMediaQueue, limitStreamBytes } from '@kyyinfinite/zapo-message/media-gate.js'
|
|
51
|
+
import { assertText, assertUrl, DISPLAY_TEXT_MAX } from '@kyyinfinite/zapo-message/btn/validators.js'
|
|
52
|
+
import assert from 'node:assert/strict'
|
|
53
|
+
|
|
54
|
+
const client: ZapoClient = {
|
|
55
|
+
message: {
|
|
56
|
+
send: async (to, content, options) => {
|
|
57
|
+
assert.equal(typeof to, 'string')
|
|
58
|
+
assert.ok(content !== undefined)
|
|
59
|
+
return { id: 'CONSUMER-1', attempts: 1, ack: { refreshLid: false }, ackNode: undefined as never }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
assert.equal(isClient(client), true)
|
|
65
|
+
assert.equal(isZapoClient(client), true)
|
|
66
|
+
|
|
67
|
+
const card = await button(client).title('Konsumen').body('Halo dari consumer').footer('F').quick_reply('OK', 'cmd ok').build()
|
|
68
|
+
assert.equal(card.interactiveMessage.nativeFlowMessage.buttons.length, 1)
|
|
69
|
+
assert.equal(JSON.parse(card.interactiveMessage.nativeFlowMessage.buttons[0].buttonParamsJson).id, 'cmd ok')
|
|
70
|
+
|
|
71
|
+
const legacy = await legacyButton(client).body('legacy').button('b1', 'Satu').build()
|
|
72
|
+
assert.equal(legacy.buttonsMessage.headerType, 1)
|
|
73
|
+
|
|
74
|
+
const list = listMessage(client).title('Menu').section('S', [{ id: 'r1', title: 'R1' }]).build()
|
|
75
|
+
assert.equal(list.listMessage.listType, 1)
|
|
76
|
+
|
|
77
|
+
const rich = airich(client).text('teks konsumen').code('javascript', 'const x = 1').table([['A'], ['b']]).build()
|
|
78
|
+
const richMessage = rich.botForwardedMessage.message.richResponseMessage
|
|
79
|
+
assert.equal(richMessage.messageType, 1)
|
|
80
|
+
const decoded = decodeUnifiedResponse(richMessage.unifiedResponse.data) as { sections: { view_model: { primitive: { text?: string } } }[] }
|
|
81
|
+
assert.equal(decoded.sections[0].view_model.primitive.text, 'teks konsumen')
|
|
82
|
+
|
|
83
|
+
const inline = parseInline('lihat [web](https://example.com)')
|
|
84
|
+
assert.equal(inline.entities.length, 1)
|
|
85
|
+
|
|
86
|
+
const tokens = tokenizeCode('const x = 1', 'javascript')
|
|
87
|
+
assert.equal(tokens.unified_codeBlock[0].type, 'KEYWORD')
|
|
88
|
+
|
|
89
|
+
const table = toTable([['H'], ['v']])
|
|
90
|
+
assert.equal(table.unified.length, 2)
|
|
91
|
+
|
|
92
|
+
const placeholder = airich(client).text('x').buildPlaceholder()
|
|
93
|
+
assert.equal(placeholder.messageContextInfo.deviceListMetadataVersion, 2)
|
|
94
|
+
|
|
95
|
+
const edit = airich(client).text('y').buildEdit('6281@s.whatsapp.net', 'ID1', { submessages: false })
|
|
96
|
+
assert.equal(edit.botForwardedMessage.message.protocolMessage.type, 14)
|
|
97
|
+
|
|
98
|
+
assert.equal(formatStatus('ok', 'done').startsWith('✅'), true)
|
|
99
|
+
assert.equal(formatStatus('ok', 'done').includes(toBoldSans('SUKSES')), true)
|
|
100
|
+
assert.equal(toBoldSans('AB'), '𝗔𝗕')
|
|
101
|
+
|
|
102
|
+
const interactive = extractInteractiveResponse({ buttonsResponseMessage: { selectedButtonId: 'menu tools' } })
|
|
103
|
+
assert.equal(interactive?.id, 'menu tools')
|
|
104
|
+
|
|
105
|
+
configureSharedMediaQueue({ concurrency: 1 })
|
|
106
|
+
resetSharedMediaQueue()
|
|
107
|
+
|
|
108
|
+
assert.equal(typeof EXPERIMENTAL_PRIMITIVES.source, 'string')
|
|
109
|
+
assert.equal(typeof ZWSP, 'string')
|
|
110
|
+
assert.equal(stringifyEscaped({ a: 'café' }), '{"a":"caf\\\\u00e9"}')
|
|
111
|
+
|
|
112
|
+
import { text, reaction, poll, contact, forward, linkPreview, mediaSlotToMessage, installZapoMessage, ZAPO_MESSAGE_METHOD_NAMES } from '@kyyinfinite/zapo-message'
|
|
113
|
+
|
|
114
|
+
const textPayload = text().body('Halo konsumen').build()
|
|
115
|
+
assert.deepEqual(textPayload, { conversation: 'Halo konsumen' })
|
|
116
|
+
|
|
117
|
+
const reactionPayload = reaction().target({ key: { remoteJid: '6281@s.whatsapp.net', id: 'MSG1' } }).emoji('🔥').build()
|
|
118
|
+
assert.equal(reactionPayload.type, 'reaction')
|
|
119
|
+
assert.equal(reactionPayload.emoji, '🔥')
|
|
120
|
+
|
|
121
|
+
const pollPayload = poll().question('Pilih').options(['A', 'B']).build()
|
|
122
|
+
assert.deepEqual(pollPayload, { type: 'poll', name: 'Pilih', options: ['A', 'B'], selectableCount: 1 })
|
|
123
|
+
|
|
124
|
+
const contactPayload = contact().name('Budi').phone('+628123').build()
|
|
125
|
+
assert.match(contactPayload.contactMessage.vcard, /BEGIN:VCARD/)
|
|
126
|
+
|
|
127
|
+
const linkPayload = linkPreview().body('buka https://example.com').title('Contoh').build()
|
|
128
|
+
assert.equal(linkPayload.extendedTextMessage.matchedText, 'https://example.com')
|
|
129
|
+
assert.equal(linkPayload.extendedTextMessage.previewType, 5)
|
|
130
|
+
|
|
131
|
+
const forwardSends: { to?: unknown; content?: unknown; options?: unknown }[] = []
|
|
132
|
+
const forwardClient: ZapoClient = {
|
|
133
|
+
message: {
|
|
134
|
+
send: async (to, content, options) => {
|
|
135
|
+
forwardSends.push({ to, content, options })
|
|
136
|
+
return { id: 'FWD1', attempts: 1, ack: {} } as never
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
await forward(forwardClient).message({ message: { conversation: 'asli' } }).send('6282@s.whatsapp.net')
|
|
141
|
+
assert.deepEqual((forwardSends[0]?.options as Record<string, unknown>).forward, true)
|
|
142
|
+
|
|
143
|
+
const slotMessage = mediaSlotToMessage({ field: 'stickerMessage', message: { mimetype: 'image/webp' } })
|
|
144
|
+
assert.deepEqual(slotMessage, { stickerMessage: { mimetype: 'image/webp' } })
|
|
145
|
+
|
|
146
|
+
assert.equal(ZAPO_MESSAGE_METHOD_NAMES.length, 18)
|
|
147
|
+
assert.equal(typeof installZapoMessage, 'function')
|
|
148
|
+
|
|
149
|
+
import { createStore, WaClient } from 'zapo-js'
|
|
150
|
+
import '@kyyinfinite/zapo-message'
|
|
151
|
+
|
|
152
|
+
const waClient = new WaClient({ store: createStore({}), sessionId: 'consumer-auto' })
|
|
153
|
+
for (const name of ['button', 'legacyButton', 'listMessage', 'airich', 'text', 'reaction', 'media', 'image', 'video', 'audio', 'document', 'sticker', 'contact', 'poll', 'album', 'linkPreview', 'forward', 'location']) {
|
|
154
|
+
assert.equal(typeof (waClient as unknown as Record<string, unknown>)[name], 'function', 'client.' + name + ' harus terpasang lewat import side-effect')
|
|
155
|
+
}
|
|
156
|
+
const viaMethod = waClient.text().body('via method').build()
|
|
157
|
+
assert.deepEqual(viaMethod, { conversation: 'via method' })
|
|
158
|
+
const viaLegacyButton = waClient.legacyButton().body('halo').button('b1', 'Satu').build()
|
|
159
|
+
assert.equal((await viaLegacyButton).buttonsMessage.headerType, 1)
|
|
160
|
+
|
|
161
|
+
import type { TextConfig, ButtonConfig, AIRichConfig, LocationConfig, MediaConfig, MessageSendOptions } from '@kyyinfinite/zapo-message'
|
|
162
|
+
|
|
163
|
+
const hybridSends: { to?: unknown; content?: unknown; options?: unknown }[] = []
|
|
164
|
+
const hybridClient: ZapoClient = {
|
|
165
|
+
message: {
|
|
166
|
+
upload: async () => ({
|
|
167
|
+
url: 'https://mmg.whatsapp.net/v/t62.7118-24/consumer',
|
|
168
|
+
directPath: '/v/t62.7118-24/consumer',
|
|
169
|
+
mediaKey: new Uint8Array(32).fill(1),
|
|
170
|
+
fileSha256: new Uint8Array(32).fill(2),
|
|
171
|
+
fileEncSha256: new Uint8Array(32).fill(3),
|
|
172
|
+
fileLength: 1000,
|
|
173
|
+
mediaKeyTimestamp: 1730000000,
|
|
174
|
+
}),
|
|
175
|
+
send: async (to, content, options) => {
|
|
176
|
+
hybridSends.push({ to, content, options })
|
|
177
|
+
return { id: 'HYB-' + hybridSends.length, attempts: 1, ack: {} } as never
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
installZapoMessage(hybridClient)
|
|
182
|
+
|
|
183
|
+
const textConfig: TextConfig = { body: 'async hybrid' }
|
|
184
|
+
const hybridText = await (hybridClient as unknown as { text(jid: string, config: TextConfig): Promise<{ id: string }> }).text('6281@s.whatsapp.net', textConfig)
|
|
185
|
+
assert.equal(hybridText.id, 'HYB-1')
|
|
186
|
+
assert.deepEqual(hybridSends[0]?.content, { conversation: 'async hybrid' })
|
|
187
|
+
|
|
188
|
+
const hybridDuck = installZapoMessage(hybridClient)
|
|
189
|
+
const buttonConfig: ButtonConfig = {
|
|
190
|
+
body: 'Pilih satu',
|
|
191
|
+
buttons: [
|
|
192
|
+
{ type: 'quick_reply', text: 'Profile', id: 'profile' },
|
|
193
|
+
{ type: 'cta_url', text: 'Website', url: 'https://example.com' },
|
|
194
|
+
{ type: 'cta_copy', text: 'Copy Code', copyCode: 'AVELYNA' },
|
|
195
|
+
{ type: 'cta_call', text: 'Contact', phoneNumber: '+628123456789' },
|
|
196
|
+
],
|
|
197
|
+
}
|
|
198
|
+
const hybridButton = await (hybridDuck as unknown as { button(jid: string, config: ButtonConfig): Promise<{ id: string }> }).button('6281@s.whatsapp.net', buttonConfig)
|
|
199
|
+
assert.equal(hybridButton.id, 'HYB-2')
|
|
200
|
+
const hybridCard = hybridSends[1]?.content as { interactiveMessage: { nativeFlowMessage: { buttons: { name: string }[] } } }
|
|
201
|
+
assert.equal(hybridCard.interactiveMessage.nativeFlowMessage.buttons.length, 4)
|
|
202
|
+
assert.equal(hybridCard.interactiveMessage.nativeFlowMessage.buttons[3].name, 'cta_call')
|
|
203
|
+
|
|
204
|
+
const locationConfig: LocationConfig = { latitude: -6.2, longitude: 106.8, name: 'Jakarta' }
|
|
205
|
+
await (hybridDuck as unknown as { location(jid: string, config: LocationConfig): Promise<unknown> }).location('6281@s.whatsapp.net', locationConfig)
|
|
206
|
+
assert.deepEqual((hybridSends[2]?.content as { locationMessage: Record<string, unknown> }).locationMessage, {
|
|
207
|
+
degreesLatitude: -6.2,
|
|
208
|
+
degreesLongitude: 106.8,
|
|
209
|
+
name: 'Jakarta',
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
const airichConfig: AIRichConfig = {
|
|
213
|
+
sections: [
|
|
214
|
+
{ type: 'text', text: 'Welcome' },
|
|
215
|
+
{ type: 'code', language: 'javascript', code: "console.log('Hello')" },
|
|
216
|
+
{ type: 'tip', text: 'Helpful information' },
|
|
217
|
+
],
|
|
218
|
+
footer: 'Powered by Avelyna',
|
|
219
|
+
}
|
|
220
|
+
await (hybridDuck as unknown as { airich(jid: string, config: AIRichConfig): Promise<unknown> }).airich('6281@s.whatsapp.net', airichConfig)
|
|
221
|
+
assert.equal(hybridSends.length, 5, 'airich dua-langkah: placeholder + edit')
|
|
222
|
+
assert.ok((hybridSends[3]?.content as Record<string, unknown>).messageContextInfo)
|
|
223
|
+
assert.ok((hybridSends[4]?.content as Record<string, unknown>).botForwardedMessage)
|
|
224
|
+
|
|
225
|
+
const sendOptions: MessageSendOptions = { mentions: ['6281@s.whatsapp.net'] }
|
|
226
|
+
await (hybridDuck as unknown as { text(jid: string, config: TextConfig, options?: MessageSendOptions): Promise<unknown> }).text('6281@s.whatsapp.net', { body: 'dengan opsi' }, sendOptions)
|
|
227
|
+
assert.deepEqual((hybridSends[5]?.options as Record<string, unknown>).mentions, ['6281@s.whatsapp.net'])
|
|
228
|
+
|
|
229
|
+
const mediaConfig: MediaConfig = { type: 'document', source: Buffer.from('konsumen-dok'), fileName: 'nota.txt' }
|
|
230
|
+
await (hybridDuck as unknown as { media(jid: string, config: MediaConfig): Promise<unknown> }).media('6281@s.whatsapp.net', mediaConfig)
|
|
231
|
+
assert.ok((hybridSends[6]?.content as Record<string, unknown>).documentMessage)
|
|
232
|
+
|
|
233
|
+
await waClient.disconnect().catch(() => {})
|
|
234
|
+
|
|
235
|
+
assert.equal(await import('@kyyinfinite/zapo-message/message/webp.js').then((m) => typeof m.probeWebp), 'function')
|
|
236
|
+
|
|
237
|
+
let sharpAbsentError: Error | undefined
|
|
238
|
+
try {
|
|
239
|
+
const sharpSpecifier = 'sharp'
|
|
240
|
+
await import(sharpSpecifier)
|
|
241
|
+
} catch (error) {
|
|
242
|
+
sharpAbsentError = error as Error
|
|
243
|
+
}
|
|
244
|
+
if (sharpAbsentError) {
|
|
245
|
+
let thumbnailError: unknown
|
|
246
|
+
try {
|
|
247
|
+
await import('@kyyinfinite/zapo-message/btn/thumbnail.js').then((m) => m.generateImageThumbnail(Buffer.from('bukan-gambar')))
|
|
248
|
+
} catch (error) {
|
|
249
|
+
thumbnailError = error
|
|
250
|
+
}
|
|
251
|
+
assert.ok(thumbnailError, 'tanpa sharp, generasi thumbnail harus error jelas')
|
|
252
|
+
assert.match(String((thumbnailError as Error).message), /sharp/)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
console.log('external consumer OK: imports compiled, payloads built, assertions passed')
|
|
256
|
+
`;
|
|
257
|
+
const consumerPackage = JSON.parse(
|
|
258
|
+
readFileSync(join(work, "package.json"), "utf8"),
|
|
259
|
+
);
|
|
260
|
+
consumerPackage.type = "module";
|
|
261
|
+
writeFileSync(
|
|
262
|
+
join(work, "package.json"),
|
|
263
|
+
JSON.stringify(consumerPackage, null, 2),
|
|
264
|
+
);
|
|
265
|
+
writeFileSync(join(work, config.consumer.compileFile), consumer);
|
|
266
|
+
execFileSync(
|
|
267
|
+
"npm",
|
|
268
|
+
[
|
|
269
|
+
"install",
|
|
270
|
+
"--no-save",
|
|
271
|
+
"typescript@5.7.2",
|
|
272
|
+
"@types/node@22.10.0",
|
|
273
|
+
"--no-audit",
|
|
274
|
+
"--no-fund",
|
|
275
|
+
],
|
|
276
|
+
{ cwd: work, stdio: "inherit" },
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const tsconfig = {
|
|
280
|
+
compilerOptions: {
|
|
281
|
+
target: "ES2023",
|
|
282
|
+
module: "NodeNext",
|
|
283
|
+
moduleResolution: "NodeNext",
|
|
284
|
+
strict: true,
|
|
285
|
+
noEmit: false,
|
|
286
|
+
outDir: "dist",
|
|
287
|
+
skipLibCheck: true,
|
|
288
|
+
},
|
|
289
|
+
include: [config.consumer.compileFile],
|
|
290
|
+
};
|
|
291
|
+
writeFileSync(join(work, "tsconfig.json"), JSON.stringify(tsconfig));
|
|
292
|
+
execFileSync("npx", ["tsc", "-p", "tsconfig.json"], {
|
|
293
|
+
cwd: work,
|
|
294
|
+
stdio: "inherit",
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const jsEntry = join(
|
|
298
|
+
work,
|
|
299
|
+
"dist",
|
|
300
|
+
config.consumer.compileFile.replace(/\.ts$/, ".js"),
|
|
301
|
+
);
|
|
302
|
+
execFileSync("node", [jsEntry], { cwd: work, stdio: "inherit" });
|
|
303
|
+
|
|
304
|
+
const installedPackageJson = JSON.parse(
|
|
305
|
+
readFileSync(
|
|
306
|
+
join(work, "node_modules", "@kyyinfinite/zapo-message", "package.json"),
|
|
307
|
+
"utf8",
|
|
308
|
+
),
|
|
309
|
+
);
|
|
310
|
+
assert.equal(installedPackageJson.name, "@kyyinfinite/zapo-message");
|
|
311
|
+
|
|
312
|
+
console.log("external consumer verification passed");
|
|
313
|
+
} finally {
|
|
314
|
+
rmSync(work, { recursive: true, force: true });
|
|
315
|
+
rmSync(tarball, { force: true });
|
|
316
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import {
|
|
3
|
+
readFileSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
rmSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
statSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { join, dirname } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { readConfig } from "./lib-config.mjs";
|
|
12
|
+
|
|
13
|
+
const config = await readConfig();
|
|
14
|
+
const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
15
|
+
const pkgVersion = JSON.parse(
|
|
16
|
+
readFileSync(join(packageRoot, "package.json"), "utf8"),
|
|
17
|
+
).version;
|
|
18
|
+
|
|
19
|
+
execFileSync("npm", ["pack", "--quiet"], {
|
|
20
|
+
cwd: packageRoot,
|
|
21
|
+
stdio: ["ignore", "pipe", "inherit"],
|
|
22
|
+
});
|
|
23
|
+
const tarballName = `kyyinfinite-zapo-message-${pkgVersion}.tgz`;
|
|
24
|
+
const tarball = join(packageRoot, tarballName);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const listing = execFileSync("tar", ["-tzf", tarball], { cwd: packageRoot })
|
|
28
|
+
.toString()
|
|
29
|
+
.trim()
|
|
30
|
+
.split("\n");
|
|
31
|
+
|
|
32
|
+
const stripped = listing
|
|
33
|
+
.map((line) => line.replace(/^package\//, ""))
|
|
34
|
+
.filter((line) => line.length > 0);
|
|
35
|
+
|
|
36
|
+
const topLevels = new Set(stripped.map((line) => line.split("/")[0]));
|
|
37
|
+
const allowed = new Set(config.package.allowedTopLevel);
|
|
38
|
+
const unexpected = [...topLevels].filter((item) => !allowed.has(item));
|
|
39
|
+
if (unexpected.length > 0) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`unexpected top-level entries in package: ${unexpected.join(", ")}`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const forbidden = stripped.filter(
|
|
46
|
+
(line) =>
|
|
47
|
+
line.includes("node_modules") ||
|
|
48
|
+
line.includes(".env") ||
|
|
49
|
+
line.includes(".git/") ||
|
|
50
|
+
line.includes("session") ||
|
|
51
|
+
line.includes(".tgz") ||
|
|
52
|
+
line.includes(".DS_Store"),
|
|
53
|
+
);
|
|
54
|
+
if (forbidden.length > 0) {
|
|
55
|
+
throw new Error(`forbidden files in package: ${forbidden.join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const required = [
|
|
59
|
+
"package.json",
|
|
60
|
+
"tsconfig.json",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md",
|
|
63
|
+
"LICENSE",
|
|
64
|
+
"dist/index.js",
|
|
65
|
+
"dist/index.d.ts",
|
|
66
|
+
];
|
|
67
|
+
for (const requiredFile of required) {
|
|
68
|
+
if (!stripped.includes(requiredFile)) {
|
|
69
|
+
throw new Error(`required file missing from package: ${requiredFile}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
console.log(
|
|
74
|
+
`package verification passed: ${stripped.length} files, top-level entries: ${[...topLevels].sort().join(", ")}`,
|
|
75
|
+
);
|
|
76
|
+
} finally {
|
|
77
|
+
rmSync(tarball, { force: true });
|
|
78
|
+
}
|