Release 1.3.0: configurable start order ID for import

Saving a new "start order ID" in the import block moves the import
cursor to X-1, so the next run imports from order X inclusive.
The block also shows the current cursor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EDD4j8Y2gTf72v7dMgSHz8
This commit is contained in:
2026-10-15 14:46:57 +02:00
co-authored by Claude Opus 5.5
parent cc3ab1fd4a
commit 6ffbd2effa
8 changed files with 109 additions and 11 deletions
+45 -1
View File
@@ -32,7 +32,7 @@ function loadConfigModule({ states = [], cachedStates = [], saved = {}, provider
});
}
const Config = {
PropertyType: { INFO: 'info', STRING: 'string' },
PropertyType: { INFO: 'info', STRING: 'string', NUMBER: 'number' },
DisplayFormat: { URL: 'url', SECRET: 'secret' },
registerConfigBlocks: async value => { blocks = value; },
get: async (key, fallback) => Object.hasOwn(store, key) ? store[key] : fallback,
@@ -233,3 +233,47 @@ test('separate shop instances keep their own target IDs and options', async () =
assert.equal(a.store[`mapping.orbito_${STATUS_A}`], '2');
assert.equal(b.store[`mapping.orbito_${STATUS_A}`], '7');
});
test('import block shows the import cursor or the first-import hint', async () => {
const withCursor = await (await loadConfigModule({ saved: { 'runtime.lastOrderId': 100 } }).register()).import.schema();
assert.match(withCursor.cursor.name.pl, /#100 — następny import zacznie od #101/);
assert.match(withCursor.cursor.name.en, /#100 — the next import starts from #101/);
assert.equal(withCursor.startOrderId.type, 'number');
const withoutCursor = await (await loadConfigModule().register()).import.schema();
assert.match(withoutCursor.cursor.name.pl, /Pierwszy import zacznie od najnowszego zamówienia/);
});
test('a changed start order ID moves the import cursor to the previous order, forwards and backwards', async () => {
const module = loadConfigModule({ saved: { 'runtime.lastOrderId': 100, 'import.startOrderId': 50 } });
const blocks = await module.register();
const errors = [];
const report = { addError: (...args) => errors.push(args) };
await blocks.import.validate({ orderStatus: STATUS_A, startOrderId: 150 }, report);
assert.equal(module.store['runtime.lastOrderId'], 149);
module.store['import.startOrderId'] = 150;
await blocks.import.validate({ orderStatus: STATUS_A, startOrderId: '20' }, report);
assert.equal(module.store['runtime.lastOrderId'], 19);
assert.deepEqual(errors, []);
});
test('an unchanged or cleared start order ID keeps the import cursor', async () => {
const module = loadConfigModule({ saved: { 'runtime.lastOrderId': 100, 'import.startOrderId': 50 } });
const blocks = await module.register();
const errors = [];
for (const startOrderId of [50, '50', '', null, undefined]) {
await blocks.import.validate({ orderStatus: STATUS_B, startOrderId }, { addError: (...args) => errors.push(args) });
}
assert.equal(module.store['runtime.lastOrderId'], 100);
assert.deepEqual(errors, []);
});
test('an invalid start order ID is reported and keeps the import cursor', async () => {
const module = loadConfigModule({ saved: { 'runtime.lastOrderId': 100 } });
const blocks = await module.register();
for (const startOrderId of [0, -5, 1.5, 'abc']) {
const errors = [];
await blocks.import.validate({ startOrderId }, { addError: (...args) => errors.push(args) });
assert.deepEqual(errors.map(([field]) => field), ['startOrderId']);
}
assert.equal(module.store['runtime.lastOrderId'], 100);
});