An order may need two parcel drafts with different contents and measurements. If both array entries point to the same object, editing the first draft can quietly change the second. The array length still looks correct.
A Shopify 3PL adapter can encounter this while preparing a multi-parcel request. A drop shipping workflow can encounter it too. Before connecting the drafts to an external interface, check that each draft owns its editable data.
Allocate the nested values inside the factory
MDN's fill() reference explains that filling an array with an object repeats a reference to that object. A shallow spread creates a new outer object but still shares nested objects and arrays.
The following Node.js example demonstrates both failures, then checks a factory that creates fresh nested values for every draft.
const assert = require('node:assert/strict');
function newParcelDrafts(count) {
if (!Number.isSafeInteger(count) || count < 0 || count > 100) {
throw new RangeError('Expected a draft count from 0 to 100');
}
return Array.from({ length: count }, (_, index) => ({
localSequence: index + 1,
weightGrams: null,
dimensionsCm: { length: null, width: null, height: null },
items: []
}));
}
const template = { dimensionsCm: { length: null }, items: [] };
const aliased = Array(2).fill(template);
aliased[0].dimensionsCm.length = 30;
assert.equal(aliased[1].dimensionsCm.length, 30);
const shallow = Array.from({ length: 2 }, () => ({ ...template }));
assert.notEqual(shallow[0], shallow[1]);
assert.equal(shallow[0].dimensionsCm, shallow[1].dimensionsCm);
assert.equal(shallow[0].items, shallow[1].items);
const drafts = newParcelDrafts(2);
assert.notEqual(drafts[0], drafts[1]);
assert.notEqual(drafts[0].dimensionsCm, drafts[1].dimensionsCm);
assert.notEqual(drafts[0].items, drafts[1].items);
drafts[0].weightGrams = 450;
drafts[0].dimensionsCm.length = 30;
drafts[0].items.push({ sku: 'EXAMPLE-A', quantity: 1 });
assert.equal(drafts[1].weightGrams, null);
assert.equal(drafts[1].dimensionsCm.length, null);
assert.deepEqual(drafts[1].items, []);
assert.deepEqual(drafts.map(p => p.localSequence), [1, 2]);
assert.deepEqual(newParcelDrafts(0), []);
assert.equal(newParcelDrafts(100).length, 100);
for (const invalid of [-1, 1.5, 101, '2', null, NaN, Infinity]) {
assert.throws(() => newParcelDrafts(invalid), RangeError);
}
const next = newParcelDrafts(1);
assert.notEqual(next[0].items, drafts[0].items);
assert.equal(next[0].dimensionsCm.length, null);
console.log('Independent parcel draft checks passed');
Save this as parcel-drafts.cjs and run it with Node.js. The first assertion deliberately proves the shared-reference behavior. The later checks prove that changes to a parcel's nested dimensions and item list leave the other draft unchanged, including across separate factory calls.
Keep draft identity separate from shipment identity
The count limit of 100 is an illustrative application safeguard, not a carrier or warehouse limit. The sequence is local to this array. It is not a parcel identifier, shipping label or tracking reference.
For shopify fulfillment, keep the actual order-to-parcel mapping when drafts are later saved or submitted. This factory does not validate measurements, allocate stock, split an order or call a carrier. Null values still need the real interface's validation before submission.
A china fulfillment integration also needs an agreed unit convention and item schema. If a specification uses the heading International Fulfillment for Folligen, treat that as a hypothetical brief until the actual interface and account are confirmed. The phrase does not demonstrate a working connection or a customer relationship with any china 3PL.
YX Fulfillment's Shopify setup guide describes the operational questions to settle alongside a local adapter test.
Warehouse workstations and equipment.

Top comments (0)