Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(sdk): exercise the client request path in the Node 18 smoke check (#1842)
Yudhi Armyndharis81f3515602a7
diff --git a/.github/workflows/js-sdk-release.yml b/.github/workflows/js-sdk-release.ymlindex e130ac082..851cb9a6f 100644--- a/.github/workflows/js-sdk-release.yml+++ b/.github/workflows/js-sdk-release.yml@@ -91,7 +91,7 @@ jobs:- run: npm test- run: npm run typecheck- run: npm run build- - run: npm run smoke # dual CJS+ESM consumable — must run after build+ - run: npm run smoke # packaging plus request smoke; must run after build- name: Publish to npm (trusted publishing, provenance automatic)# No --provenance flag: npm attaches provenance on its own for a trusted-publisher release, anddiff --git a/.github/workflows/sdk-ci.yml b/.github/workflows/sdk-ci.ymlindex d9b258494..4d4f95af2 100644--- a/.github/workflows/sdk-ci.yml+++ b/.github/workflows/sdk-ci.yml@@ -4,7 +4,7 @@ name: SDK CI# the server contract surfaces the SDK types mirror (DTOs, controllers, services + the engine# interface), so a backend DTO change also re-runs the SDK suites and surfaces contract drift. The# JavaScript job also builds and runs the dual-format packaging smoke test (require() + import() both-# consumable).+# consumable) plus real requests through each build's client.on:push:branches: [main]@@ -41,7 +41,8 @@ jobs:fail-fast: falsematrix:# 18 is the published package's engines floor; vitest 4 needs Node 20+, so 18 only gates the- # typecheck, build and packaging smoke, and the unit tests run on 20 and 22.+ # typecheck, build and smoke (packaging plus real requests through each build's client), and+ # the unit tests run on 20 and 22.node: ['18', '20', '22']defaults:run:@@ -60,7 +61,7 @@ jobs:# type-level wire contract in test/*.test-d.ts only gates if tsc runs over test/ too (#754).- run: npm run typecheck- run: npm run build- - run: npm run smoke # dual CJS+ESM consumable — must run after build+ - run: npm run smoke # packaging plus request smoke; must run after buildpython:name: Python SDK (${{ matrix.python }})diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bd2a34e84..8c019b9b9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed+- The JavaScript SDK smoke check sends requests through both built clients, so the Node 18 CI lane covers the request path.- Retire the whatsapp-web.js download-mimetype install patch; inbound media downloads now pass the mimetype themselves.- CI and the weekly security scan run `npm audit` over the JavaScript SDK, and Dependabot watches its lockfile.diff --git a/docs/09-testing-strategy.md b/docs/09-testing-strategy.mdindex 02348004f..ef69907e9 100644--- a/docs/09-testing-strategy.md+++ b/docs/09-testing-strategy.md@@ -57,7 +57,7 @@ npm --prefix dashboard run test:unit| `cd dashboard && npm run i18n:check` | Verify dashboard locale key parity || `cd dashboard && npm run build` | Type-check and build the dashboard || `cd sdk/javascript && npm test && npm run typecheck` | Type-check and unit-test the JavaScript SDK |-| `cd sdk/javascript && npm run build && npm run smoke` | Build and dual CJS/ESM package-smoke the JavaScript SDK |+| `cd sdk/javascript && npm run build && npm run smoke` | Build the JavaScript SDK, then smoke-load both builds and send requests through each client || `cd sdk/python && pytest` | Run the Python SDK tests || `cd sdk/php && ./vendor/bin/phpunit` | Run the PHP SDK tests || `cd sdk/java && mvn -B verify` | Run the Java SDK tests |@@ -271,7 +271,7 @@ contract surfaces that SDKs mirror (`src/**/dto/**`, `src/**/*.controller.ts`, ``src/engine/interfaces/whatsapp-engine.interface.ts`), so any backend controller or service change alsore-runs the SDK suites. It runs:-- JavaScript SDK type-check, build, and dual CJS/ESM smoke test on Node 18 (the `engines` floor), 20 and 22, with unit tests on 20 and 22 (vitest 4 needs Node 20+).+- JavaScript SDK type-check, build, and dual CJS/ESM smoke test (module loading plus requests through each build's client) on Node 18 (the `engines` floor), 20 and 22, with unit tests on 20 and 22 (vitest 4 needs Node 20+).- Python SDK type check with `mypy` and tests with `pytest` on Python 3.9 and 3.12.- PHP SDK tests with PHPUnit.- Java SDK tests with Maven.diff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.mdindex 8c5c87dc7..929a73634 100644--- a/docs/18-sdk-design.md+++ b/docs/18-sdk-design.md@@ -1175,7 +1175,7 @@ The wire types live in a dedicated module (`types.ts` / `types.py`) so they can```bash# JavaScript-cd sdk/javascript && npm test && npm run build && npm run smoke # smoke = require()+import() packaging check+cd sdk/javascript && npm test && npm run build && npm run smoke # smoke = require()+import() packaging plus request check# Pythoncd sdk/python && python -m pytest -q# PHPdiff --git a/sdk/javascript/README.md b/sdk/javascript/README.mdindex a732fbbf8..463a8ec49 100644--- a/sdk/javascript/README.md+++ b/sdk/javascript/README.md@@ -121,8 +121,9 @@ Cutting a release:The SDK has its own version line — the monorepo's `v*` tags are the appversion and never trigger an SDK publish.3. The workflow re-runs the SDK's tests, typecheck, build and dual CJS/ESM- smoke check, then publishes. The published tarball is the one those gates- passed, not a later rebuild.+ smoke check (packaging plus requests through each build's client), then+ publishes. The published tarball is the one those gates passed, not a+ later rebuild.## Licensediff --git a/sdk/javascript/scripts/smoke.mjs b/sdk/javascript/scripts/smoke.mjsindex 8026fdca8..1c236a6d3 100644--- a/sdk/javascript/scripts/smoke.mjs+++ b/sdk/javascript/scripts/smoke.mjs@@ -1,11 +1,13 @@/**- * Packaging smoke test: load the BUILT dist/ through Node's real CJS and ESM- * loaders. Unit tests run under vitest's bundler-like resolver and cannot catch- * a dual-format misconfig (CJS parsed as ESM, or extensionless ESM specifiers),- * so this guards `npm publish` against shipping an unconsumable package.- * Run after `npm run build`.+ * Packaging and request smoke test: load the BUILT dist/ through Node's real CJS+ * and ESM loaders, then send real requests through each build's client. Unit+ * tests run under vitest's bundler-like resolver and cannot catch a dual-format+ * misconfig (CJS parsed as ESM, or extensionless ESM specifiers), so this guards+ * `npm publish` against shipping an unconsumable package. Run after `npm run build`.*/import { createHmac } from 'node:crypto';+import { readFileSync } from 'node:fs';+import { createServer } from 'node:http';import { createRequire } from 'node:module';const require = createRequire(import.meta.url);@@ -29,13 +31,54 @@ for (const [format, mod] of [}}+// Request smoke: the Node 18 lane skips the unit tests (vitest 4 needs Node 20+), and the typecheck+// accepts DOM-declared globals Node 18 lacks, so send real requests through each build's client over+// the default global fetch: a parsed 2xx body, a typed error for a non-2xx, and the abort timeout.+const server = createServer((req, res) => {+ if (req.url === '/api/health') {+ res.writeHead(200, { 'Content-Type': 'application/json' });+ res.end(JSON.stringify({ apiKey: req.headers['x-api-key'] }));+ } else if (req.url === '/api/health/live') {+ res.writeHead(404, { 'Content-Type': 'application/json' });+ res.end('{"statusCode":404,"message":"Not here","error":"Not Found"}');+ } else {+ // Never answer, so only the client timeout can settle the request. If that timeout is broken,+ // dropping the socket later rejects with a non-timeout error instead of hanging the job.+ setTimeout(() => res.destroy(), 5000).unref();+ }+});+await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));+try {+ const baseUrl = `http://127.0.0.1:${server.address().port}`;+ for (const [format, mod] of [+ ['CJS', cjs],+ ['ESM', esm],+ ]) {+ const client = new mod.OpenWAClient({ baseUrl, apiKey: 'smoke-key' });+ const health = await client.health.check();+ if (health?.apiKey !== 'smoke-key') {+ throw new Error(`${format}: health.check() did not send the key or parse JSON: ${JSON.stringify(health)}`);+ }+ const notFound = await client.health.live().catch(err => err);+ if (!(notFound instanceof mod.OpenWANotFoundError) || notFound.status !== 404) {+ throw new Error(`${format}: a 404 did not raise OpenWANotFoundError (got ${notFound})`);+ }+ const unanswered = await client.request({ method: 'GET', path: '/hang', timeoutMs: 100 }).catch(err => err);+ if (!(unanswered instanceof mod.OpenWATimeoutError)) {+ throw new Error(`${format}: an unanswered request did not raise OpenWATimeoutError (got ${unanswered})`);+ }+ }+} finally {+ server.closeAllConnections?.(); // Node 18.2++ server.close();+}+// Typings smoke: each runtime condition must carry its OWN types entry pointing at the matching// build. A single top-level "types" condition ahead of "require" makes a node16-family CommonJS// TypeScript consumer resolve the ESM declaration while linking the CJS build, which fails with// TS1479 ("The current file is a CommonJS module whose imports will produce 'require' calls")// against the ESM declarations' `export ... from` syntax. The runtime loaders above cannot see// this; only the exports-map shape does.-import { readFileSync } from 'node:fs';const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));const dot = pkg.exports?.['.'];for (const [condition, dist] of [@@ -54,4 +97,4 @@ if (dot?.types !== undefined) {throw new Error('exports["."] must not carry a top-level "types" condition (see TS1479 note above)');}-console.log('smoke OK: require() + import() both resolve OpenWAClient, and each condition types itself');+console.log('smoke OK: require() + import() both resolve OpenWAClient and send requests, each condition types itself');