Workstations at YX Fulfillment.
An order payload contains giftWrap: "false". A JavaScript adapter checks if (payload.giftWrap) and creates the packing task anyway.
The problem is a mismatch between the source contract and JavaScript coercion. A nonempty string is truthy, including the string "false"; MDN's Boolean reference explains that conversion. Calling Boolean(value) or using !!value does not parse the word written inside a string.
Make the accepted representation explicit
For this example, the integration contract requires an own giftWrap field with the primitive value true or false. Missing fields and other representations are errors. The adapter does not infer a default from an empty string, accept 0 as an alternative spelling or turn an inherited property into an order instruction.
Object.hasOwn() distinguishes an object's own property from an inherited one. That check answers whether the field was supplied at this boundary; the following type check answers whether its value has the agreed representation.
'use strict';
const assert = require('node:assert/strict');
function readPackingOptions(payload) {
if (payload === null || typeof payload !== 'object' ||
Array.isArray(payload)) {
throw new Error('Packing options must be an object');
}
if (!Object.hasOwn(payload, 'giftWrap')) {
throw new Error('Missing giftWrap field');
}
if (typeof payload.giftWrap !== 'boolean') {
throw new Error('giftWrap must be a primitive boolean');
}
return { giftWrap: payload.giftWrap };
}
// A local test double, not a warehouse API call.
const tasks = [];
function handoff(payload) {
const options = readPackingOptions(payload);
if (options.giftWrap) tasks.push({ kind: 'gift-wrap' });
return options;
}
const off = { giftWrap: false };
const result = handoff(off);
assert.deepEqual(result, { giftWrap: false });
assert.notStrictEqual(result, off);
assert.deepEqual(off, { giftWrap: false });
assert.equal(tasks.length, 0);
assert.deepEqual(handoff({ giftWrap: true }), { giftWrap: true });
assert.deepEqual(tasks, [{ kind: 'gift-wrap' }]);
const badValues = ['false', 'true', '', ' false ', 0, 1,
null, undefined, [], {}, new Boolean(false)];
for (const value of badValues) {
const before = tasks.length;
assert.throws(() => handoff({ giftWrap: value }), /primitive boolean/);
assert.equal(tasks.length, before);
}
for (const payload of [{}, Object.create({ giftWrap: false })]) {
assert.throws(() => handoff(payload), /Missing giftWrap/);
}
for (const payload of [null, undefined, [], 'false']) {
assert.throws(() => handoff(payload), /must be an object/);
}
assert.equal(tasks.length, 1);
console.log('Packing boolean checks passed');
Save the example as packing-boolean.cjs and run node packing-boolean.cjs. It was executed with Node.js 24 during preparation. The assertions check that an explicit false produces no task, true creates one task, invalid values fail before the test double changes, and the accepted input is left intact.
Translate upstream conventions in a separate adapter
Some sources define strings or integers as flags. If that is the documented source format, translate only its accepted values at a named boundary and reject the rest. Keep the downstream packing contract consistent. Do not add a permissive coercion simply to make a failed import proceed.
This function validates one option. It does not validate product eligibility, packaging availability, order identity, duplicate requests or permission to purchase an extra service. A production handover must establish those conditions separately before creating real warehouse work.
I work with YX Fulfillment. Its order handling includes agreed packing instructions, but this standalone example is not a deployed connector or a promise that gift wrapping is available for every account. The operational point is to preserve an explicit “no” when an approved service instruction crosses a system boundary.

Top comments (0)