Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): give the JS package exports per-condition types entries

Yudhi Armyndharisa8d7516f1d9e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c46339f9..1256fc72b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- JS SDK: the exports map carries per-condition `types` entries, so a CommonJS TypeScript project under `node16`-family resolution resolves the CJS declarations instead of failing with TS1479.
- Both bundled Compose files forward every documented runtime knob; `WEBHOOK_SSRF_REDIRECTS`, `PLUGIN_INSTALL_REQUIRE_PIN` and ~75 other `.env` settings were unreachable in the container. A spec now derives the required list from `.env.example`.
- Ingress delivery ids BullMQ refuses at enqueue (numeric, `redrive:<uuid>`, `0:`-led) are hashed to a legal job id, namespaced by plugin/instance; the old refusal read as a Redis failure and silently degraded the delivery to inline dispatch with no retry.
- One precise unique-violation predicate (`23505`, `SQLITE_CONSTRAINT_UNIQUE`/`_PRIMARYKEY`): the old prefix match treated every SQLite constraint failure (FK/NOT NULL/CHECK) as a duplicate, swallowing genuine persistence failures and answering misleading 409s.
diff --git a/sdk/javascript/package.json b/sdk/javascript/package.json
index 7f98d3495..978d0d768 100644
--- a/sdk/javascript/package.json
+++ b/sdk/javascript/package.json
@@ -5,13 +5,17 @@
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
- "types": "./dist/esm/index.d.ts",
+ "types": "./dist/cjs/index.d.ts",
"exports": {
".": {
- "types": "./dist/esm/index.d.ts",
- "import": "./dist/esm/index.js",
- "require": "./dist/cjs/index.js",
- "default": "./dist/esm/index.js"
+ "import": {
+ "types": "./dist/esm/index.d.ts",
+ "default": "./dist/esm/index.js"
+ },
+ "require": {
+ "types": "./dist/cjs/index.d.ts",
+ "default": "./dist/cjs/index.js"
+ }
}
},
"files": [
diff --git a/sdk/javascript/scripts/smoke.mjs b/sdk/javascript/scripts/smoke.mjs
index d7b9b094f..679936bc1 100644
--- a/sdk/javascript/scripts/smoke.mjs
+++ b/sdk/javascript/scripts/smoke.mjs
@@ -14,4 +14,29 @@ if (typeof cjs.OpenWAClient !== 'function') throw new Error('CJS: OpenWAClient m
const esm = await import(new URL('../dist/esm/index.js', import.meta.url).href);
if (typeof esm.OpenWAClient !== 'function') throw new Error('ESM: OpenWAClient missing');
-console.log('smoke OK: require() + import() both resolve OpenWAClient');
+// 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 [
+ ['import', 'esm'],
+ ['require', 'cjs'],
+]) {
+ const types = dot?.[condition]?.types;
+ if (types !== `./dist/${dist}/index.d.ts`) {
+ throw new Error(`exports["."].${condition}.types must point at ./dist/${dist}/index.d.ts (got ${types})`);
+ }
+ if (dot?.[condition]?.default !== `./dist/${dist}/index.js`) {
+ throw new Error(`exports["."].${condition}.default must point at ./dist/${dist}/index.js`);
+ }
+}
+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');