@use-stall/core 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -69
- package/dist/index.d.mts +37 -33
- package/dist/index.d.ts +37 -33
- package/dist/index.js +452 -220
- package/dist/index.mjs +451 -219
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -6,20 +6,20 @@ var schemas = {
|
|
|
6
6
|
connector_cache: "id",
|
|
7
7
|
sync_queue: "++id, status, timestamp, priority, table, stall_offline_id, action, retry_count",
|
|
8
8
|
sync_logs: "++id, sync_batch_id, timestamp, table, action, status, stall_offline_id",
|
|
9
|
-
products: "++id,
|
|
10
|
-
variants: "++id, product_id,
|
|
11
|
-
collections: "++id, name,
|
|
12
|
-
categories: "++id, name,
|
|
13
|
-
inventory_levels: "++id, product_id, variant_id,
|
|
14
|
-
inventory_history: "++id, product_id, variant_id,
|
|
9
|
+
products: "++id, sku, barcode, title, handle, description, body_html, created_at, updated_at, deleted_at, status, type, thumbnail, brand, tags, categories, attributes, collections, variants, price, sale_price, price_currency, cost_price, taxable, tax_class, on_sale, track_inventory, unavailable, committed, in_stock, on_hand, low_stock_threshold, locations, weight, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at",
|
|
10
|
+
variants: "++id, sku, barcode, product_id, date, title, description, price, cost_price, sale_price, on_sale, status, track_inventory, unavailable, committed, in_stock, on_hand, low_stock_threshold, weight, thumbnail, attributes, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at",
|
|
11
|
+
collections: "++id, name, description, thumbnail, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at, linked_products, linked_categories, createAt, lastUpdatedAt",
|
|
12
|
+
categories: "++id, name, description, thumbnail, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at, date, count, parent_id",
|
|
13
|
+
inventory_levels: "++id, location_id, product_id, variant_id, unavailable, committed, in_stock, on_hand, low_stock_threshold, last_updatedAt, created_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at",
|
|
14
|
+
inventory_history: "++id, location_id, product_id, variant_id, unavailable, committed, in_stock, on_hand, low_stock_threshold, last_updatedAt, created_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at",
|
|
15
15
|
promotions: "++id, name, type, active, start_date, end_date, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
16
16
|
orders: "++id, order_number, customer_id, location_id, status, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
17
17
|
order_notes: "++id, order_id, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
18
18
|
refunds: "++id, order_id, payment_id, status, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
19
19
|
payment_providers: "++id, name, type, active, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
20
20
|
payments: "++id, order_id, status, method, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
tax_rates: "++id, name, rate, type, calculation_base, application, priority, compound, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at",
|
|
22
|
+
tax_classes: "++id, name, tax_calculation, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at, metadata.stall_offline_deleted_at",
|
|
23
23
|
customers: "++id, email, phone, name, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
24
24
|
locations: "++id, name, city, country, region, active, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at",
|
|
25
25
|
fulfillments: "++id, order_id, status, created_at, updated_at, metadata.stall_offline_id, metadata.stall_offline_created_at, metadata.stall_offline_updated_at"
|
|
@@ -175,7 +175,7 @@ var cleanup_old_sync_logs = async (days = 30) => {
|
|
|
175
175
|
// src/services/sync/sync-dependencies.ts
|
|
176
176
|
var SYNC_DEPENDENCY_LAYERS = {
|
|
177
177
|
1: [
|
|
178
|
-
"
|
|
178
|
+
"tax_classes",
|
|
179
179
|
"tax_rates",
|
|
180
180
|
"categories",
|
|
181
181
|
"collections",
|
|
@@ -192,8 +192,8 @@ var SYNC_DEPENDENCY_LAYERS = {
|
|
|
192
192
|
var get_entity_dependencies = (table) => {
|
|
193
193
|
const dependencies = {
|
|
194
194
|
// Layer 1: Independent
|
|
195
|
-
|
|
196
|
-
tax_rates: ["
|
|
195
|
+
tax_classes: [],
|
|
196
|
+
tax_rates: ["tax_classes"],
|
|
197
197
|
categories: [],
|
|
198
198
|
collections: [],
|
|
199
199
|
locations: [],
|
|
@@ -201,7 +201,7 @@ var get_entity_dependencies = (table) => {
|
|
|
201
201
|
customers: [],
|
|
202
202
|
promotions: [],
|
|
203
203
|
// Layer 2: Product
|
|
204
|
-
products: ["categories", "collections"],
|
|
204
|
+
products: ["tax_classes", "categories", "collections"],
|
|
205
205
|
// Layer 3: Variants & Inventory
|
|
206
206
|
variants: ["products"],
|
|
207
207
|
inventory_levels: ["products", "variants"],
|
|
@@ -275,6 +275,7 @@ var update_dependent_references = async (props) => {
|
|
|
275
275
|
try {
|
|
276
276
|
const reference_map = {
|
|
277
277
|
products: [
|
|
278
|
+
{ table: "tax_classes", field: "class" },
|
|
278
279
|
{ table: "variants", field: "product_id" },
|
|
279
280
|
{ table: "inventory_levels", field: "product_id" }
|
|
280
281
|
],
|
|
@@ -290,8 +291,8 @@ var update_dependent_references = async (props) => {
|
|
|
290
291
|
locations: [{ table: "orders", field: "location_id" }],
|
|
291
292
|
categories: [{ table: "products", field: "category_id" }],
|
|
292
293
|
collections: [{ table: "products", field: "collection_id" }],
|
|
293
|
-
|
|
294
|
-
|
|
294
|
+
tax_rates: [{ table: "tax_classes", field: "class" }],
|
|
295
|
+
tax_classes: [],
|
|
295
296
|
tags: [],
|
|
296
297
|
inventory_levels: [],
|
|
297
298
|
inventory_history: [],
|
|
@@ -318,90 +319,271 @@ var update_dependent_references = async (props) => {
|
|
|
318
319
|
console.error(`Error updating dependent references for ${table}:`, error);
|
|
319
320
|
}
|
|
320
321
|
};
|
|
321
|
-
var
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (!
|
|
332
|
-
|
|
322
|
+
var group_items_by_action = (items) => {
|
|
323
|
+
return {
|
|
324
|
+
creates: items.filter((item) => item.action === "create"),
|
|
325
|
+
updates: items.filter((item) => item.action === "update"),
|
|
326
|
+
deletes: items.filter((item) => item.action === "delete")
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
var group_by_table = (items) => {
|
|
330
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
331
|
+
for (const item of items) {
|
|
332
|
+
if (!grouped.has(item.table)) {
|
|
333
|
+
grouped.set(item.table, []);
|
|
333
334
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
335
|
+
grouped.get(item.table).push(item);
|
|
336
|
+
}
|
|
337
|
+
return grouped;
|
|
338
|
+
};
|
|
339
|
+
var process_bulk_creates = async (props) => {
|
|
340
|
+
const { sdk, items, sync_batch_id } = props;
|
|
341
|
+
const connector_ids = /* @__PURE__ */ new Map();
|
|
342
|
+
let synced = 0;
|
|
343
|
+
let failed = 0;
|
|
344
|
+
if (items.length === 0) {
|
|
345
|
+
return { synced, failed, connector_ids };
|
|
346
|
+
}
|
|
347
|
+
const grouped = group_by_table(items);
|
|
348
|
+
for (const [table, table_items] of grouped) {
|
|
349
|
+
let start_time = Date.now();
|
|
350
|
+
try {
|
|
351
|
+
const adapter = await sdk.adapter();
|
|
352
|
+
if (!adapter) {
|
|
353
|
+
throw new Error("Adapter not found");
|
|
354
|
+
}
|
|
355
|
+
const connector_config = sdk.options.configuration;
|
|
356
|
+
const table_module = adapter[table];
|
|
357
|
+
if (!table_module) {
|
|
358
|
+
throw new Error(`Module ${table} not found in adapter`);
|
|
359
|
+
}
|
|
360
|
+
start_time = Date.now();
|
|
361
|
+
const create_data = table_items.map((item) => item.data);
|
|
362
|
+
const results = await table_module.bulk_create({
|
|
337
363
|
connector_config,
|
|
338
|
-
data:
|
|
364
|
+
data: create_data
|
|
339
365
|
});
|
|
340
|
-
|
|
341
|
-
if (
|
|
342
|
-
|
|
343
|
-
|
|
366
|
+
const duration = Date.now() - start_time;
|
|
367
|
+
if (Array.isArray(results)) {
|
|
368
|
+
for (let i = 0; i < table_items.length; i++) {
|
|
369
|
+
const item = table_items[i];
|
|
370
|
+
const result = results[i];
|
|
371
|
+
const connector_id = result?.id;
|
|
372
|
+
if (connector_id) {
|
|
373
|
+
connector_ids.set(item.stall_offline_id, connector_id);
|
|
374
|
+
await replace_temporary_ids({
|
|
375
|
+
table,
|
|
376
|
+
stall_offline_id: item.stall_offline_id,
|
|
377
|
+
connector_id
|
|
378
|
+
});
|
|
379
|
+
await add_sync_log({
|
|
380
|
+
sync_batch_id,
|
|
381
|
+
table,
|
|
382
|
+
action: "create",
|
|
383
|
+
document_id: item.document_id,
|
|
384
|
+
stall_offline_id: item.stall_offline_id,
|
|
385
|
+
connector_id,
|
|
386
|
+
status: "success",
|
|
387
|
+
duration_ms: duration
|
|
388
|
+
});
|
|
389
|
+
await remove_from_sync_queue(item.id);
|
|
390
|
+
synced++;
|
|
391
|
+
} else {
|
|
392
|
+
throw new Error(`No connector ID returned for item ${item.id}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
throw new Error("Unexpected result format from bulk_create");
|
|
397
|
+
}
|
|
398
|
+
} catch (error) {
|
|
399
|
+
const duration = Date.now() - start_time;
|
|
400
|
+
console.error(`Error bulk creating items for table ${table}:`, error);
|
|
401
|
+
for (const item of table_items) {
|
|
402
|
+
const current_retries = item.retry_count || 0;
|
|
403
|
+
if (current_retries < MAX_RETRIES) {
|
|
404
|
+
await update_sync_queue_status({
|
|
405
|
+
id: item.id,
|
|
406
|
+
status: "pending",
|
|
407
|
+
error: error.message,
|
|
408
|
+
retry_count: current_retries + 1
|
|
409
|
+
});
|
|
410
|
+
} else {
|
|
411
|
+
await update_sync_queue_status({
|
|
412
|
+
id: item.id,
|
|
413
|
+
status: "failed",
|
|
414
|
+
error: `Max retries exceeded: ${error.message}`
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
await add_sync_log({
|
|
418
|
+
sync_batch_id,
|
|
419
|
+
table,
|
|
420
|
+
action: "create",
|
|
421
|
+
document_id: item.document_id,
|
|
344
422
|
stall_offline_id: item.stall_offline_id,
|
|
345
|
-
|
|
423
|
+
status: "failed",
|
|
424
|
+
error: error.message,
|
|
425
|
+
duration_ms: duration
|
|
346
426
|
});
|
|
427
|
+
failed++;
|
|
347
428
|
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return { synced, failed, connector_ids };
|
|
432
|
+
};
|
|
433
|
+
var process_bulk_updates = async (props) => {
|
|
434
|
+
const { sdk, items, sync_batch_id } = props;
|
|
435
|
+
let synced = 0;
|
|
436
|
+
let failed = 0;
|
|
437
|
+
if (items.length === 0) {
|
|
438
|
+
return { synced, failed };
|
|
439
|
+
}
|
|
440
|
+
const grouped = group_by_table(items);
|
|
441
|
+
for (const [table, table_items] of grouped) {
|
|
442
|
+
let start_time = Date.now();
|
|
443
|
+
try {
|
|
444
|
+
const adapter = await sdk.adapter();
|
|
445
|
+
if (!adapter) {
|
|
446
|
+
throw new Error("Adapter not found");
|
|
447
|
+
}
|
|
448
|
+
const connector_config = sdk.options.configuration;
|
|
449
|
+
const table_module = adapter[table];
|
|
450
|
+
if (!table_module) {
|
|
451
|
+
throw new Error(`Module ${table} not found in adapter`);
|
|
452
|
+
}
|
|
453
|
+
start_time = Date.now();
|
|
454
|
+
const update_data = table_items.map((item) => ({
|
|
351
455
|
id: item.document_id,
|
|
352
456
|
data: item.data
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
} else if (item.action === "delete") {
|
|
356
|
-
await table_module.delete({
|
|
457
|
+
}));
|
|
458
|
+
await table_module.bulk_update({
|
|
357
459
|
connector_config,
|
|
358
|
-
|
|
460
|
+
data: update_data
|
|
359
461
|
});
|
|
360
|
-
|
|
462
|
+
const duration = Date.now() - start_time;
|
|
463
|
+
for (const item of table_items) {
|
|
464
|
+
await add_sync_log({
|
|
465
|
+
sync_batch_id,
|
|
466
|
+
table,
|
|
467
|
+
action: "update",
|
|
468
|
+
document_id: item.document_id,
|
|
469
|
+
stall_offline_id: item.stall_offline_id,
|
|
470
|
+
connector_id: item.document_id,
|
|
471
|
+
status: "success",
|
|
472
|
+
duration_ms: duration
|
|
473
|
+
});
|
|
474
|
+
await remove_from_sync_queue(item.id);
|
|
475
|
+
synced++;
|
|
476
|
+
}
|
|
477
|
+
} catch (error) {
|
|
478
|
+
const duration = Date.now() - start_time;
|
|
479
|
+
console.error(`Error bulk updating items for table ${table}:`, error);
|
|
480
|
+
for (const item of table_items) {
|
|
481
|
+
const current_retries = item.retry_count || 0;
|
|
482
|
+
if (current_retries < MAX_RETRIES) {
|
|
483
|
+
await update_sync_queue_status({
|
|
484
|
+
id: item.id,
|
|
485
|
+
status: "pending",
|
|
486
|
+
error: error.message,
|
|
487
|
+
retry_count: current_retries + 1
|
|
488
|
+
});
|
|
489
|
+
} else {
|
|
490
|
+
await update_sync_queue_status({
|
|
491
|
+
id: item.id,
|
|
492
|
+
status: "failed",
|
|
493
|
+
error: `Max retries exceeded: ${error.message}`
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
await add_sync_log({
|
|
497
|
+
sync_batch_id,
|
|
498
|
+
table,
|
|
499
|
+
action: "update",
|
|
500
|
+
document_id: item.document_id,
|
|
501
|
+
stall_offline_id: item.stall_offline_id,
|
|
502
|
+
status: "failed",
|
|
503
|
+
error: error.message,
|
|
504
|
+
duration_ms: duration
|
|
505
|
+
});
|
|
506
|
+
failed++;
|
|
507
|
+
}
|
|
361
508
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
await
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
error: `Max retries exceeded: ${error.message}`
|
|
509
|
+
}
|
|
510
|
+
return { synced, failed };
|
|
511
|
+
};
|
|
512
|
+
var process_bulk_deletes = async (props) => {
|
|
513
|
+
const { sdk, items, sync_batch_id } = props;
|
|
514
|
+
let synced = 0;
|
|
515
|
+
let failed = 0;
|
|
516
|
+
if (items.length === 0) {
|
|
517
|
+
return { synced, failed };
|
|
518
|
+
}
|
|
519
|
+
const grouped = group_by_table(items);
|
|
520
|
+
for (const [table, table_items] of grouped) {
|
|
521
|
+
let start_time = Date.now();
|
|
522
|
+
try {
|
|
523
|
+
const adapter = await sdk.adapter();
|
|
524
|
+
if (!adapter) {
|
|
525
|
+
throw new Error("Adapter not found");
|
|
526
|
+
}
|
|
527
|
+
const connector_config = sdk.options.configuration;
|
|
528
|
+
const table_module = adapter[table];
|
|
529
|
+
if (!table_module) {
|
|
530
|
+
throw new Error(`Module ${table} not found in adapter`);
|
|
531
|
+
}
|
|
532
|
+
start_time = Date.now();
|
|
533
|
+
const ids = table_items.map((item) => item.document_id);
|
|
534
|
+
await table_module.bulk_delete({
|
|
535
|
+
connector_config,
|
|
536
|
+
ids
|
|
391
537
|
});
|
|
538
|
+
const duration = Date.now() - start_time;
|
|
539
|
+
for (const item of table_items) {
|
|
540
|
+
await add_sync_log({
|
|
541
|
+
sync_batch_id,
|
|
542
|
+
table,
|
|
543
|
+
action: "delete",
|
|
544
|
+
document_id: item.document_id,
|
|
545
|
+
stall_offline_id: item.stall_offline_id,
|
|
546
|
+
connector_id: item.document_id,
|
|
547
|
+
status: "success",
|
|
548
|
+
duration_ms: duration
|
|
549
|
+
});
|
|
550
|
+
await remove_from_sync_queue(item.id);
|
|
551
|
+
synced++;
|
|
552
|
+
}
|
|
553
|
+
} catch (error) {
|
|
554
|
+
const duration = Date.now() - start_time;
|
|
555
|
+
console.error(`Error bulk deleting items for table ${table}:`, error);
|
|
556
|
+
for (const item of table_items) {
|
|
557
|
+
const current_retries = item.retry_count || 0;
|
|
558
|
+
if (current_retries < MAX_RETRIES) {
|
|
559
|
+
await update_sync_queue_status({
|
|
560
|
+
id: item.id,
|
|
561
|
+
status: "pending",
|
|
562
|
+
error: error.message,
|
|
563
|
+
retry_count: current_retries + 1
|
|
564
|
+
});
|
|
565
|
+
} else {
|
|
566
|
+
await update_sync_queue_status({
|
|
567
|
+
id: item.id,
|
|
568
|
+
status: "failed",
|
|
569
|
+
error: `Max retries exceeded: ${error.message}`
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
await add_sync_log({
|
|
573
|
+
sync_batch_id,
|
|
574
|
+
table,
|
|
575
|
+
action: "delete",
|
|
576
|
+
document_id: item.document_id,
|
|
577
|
+
stall_offline_id: item.stall_offline_id,
|
|
578
|
+
status: "failed",
|
|
579
|
+
error: error.message,
|
|
580
|
+
duration_ms: duration
|
|
581
|
+
});
|
|
582
|
+
failed++;
|
|
583
|
+
}
|
|
392
584
|
}
|
|
393
|
-
await add_sync_log({
|
|
394
|
-
sync_batch_id,
|
|
395
|
-
table: item.table,
|
|
396
|
-
action: item.action,
|
|
397
|
-
document_id: item.document_id,
|
|
398
|
-
stall_offline_id: item.stall_offline_id,
|
|
399
|
-
status: "failed",
|
|
400
|
-
error: error.message,
|
|
401
|
-
duration_ms: duration
|
|
402
|
-
});
|
|
403
|
-
return { success: false, error: error.message };
|
|
404
585
|
}
|
|
586
|
+
return { synced, failed };
|
|
405
587
|
};
|
|
406
588
|
var process_sync_queue = async (props) => {
|
|
407
589
|
const { sdk } = props;
|
|
@@ -439,43 +621,92 @@ var process_sync_queue = async (props) => {
|
|
|
439
621
|
);
|
|
440
622
|
const synced_tables = /* @__PURE__ */ new Set();
|
|
441
623
|
const items_to_retry = [];
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
const
|
|
624
|
+
const connector_ids = /* @__PURE__ */ new Map();
|
|
625
|
+
const { creates, updates, deletes } = group_items_by_action(sorted_items);
|
|
626
|
+
if (creates.length > 0) {
|
|
627
|
+
const create_items = creates.filter(
|
|
628
|
+
(item) => are_dependencies_satisfied(item.table, synced_tables)
|
|
629
|
+
);
|
|
630
|
+
const create_retry_items = creates.filter(
|
|
631
|
+
(item) => !are_dependencies_satisfied(item.table, synced_tables)
|
|
632
|
+
);
|
|
633
|
+
const create_result = await process_bulk_creates({
|
|
452
634
|
sdk,
|
|
453
|
-
|
|
635
|
+
items: create_items,
|
|
454
636
|
sync_batch_id
|
|
455
637
|
});
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
638
|
+
total_synced += create_result.synced;
|
|
639
|
+
total_failed += create_result.failed;
|
|
640
|
+
connector_ids.forEach((v, k) => connector_ids.set(k, v));
|
|
641
|
+
create_items.forEach((item) => synced_tables.add(item.table));
|
|
642
|
+
items_to_retry.push(...create_retry_items);
|
|
643
|
+
}
|
|
644
|
+
if (updates.length > 0) {
|
|
645
|
+
const update_items = updates.filter(
|
|
646
|
+
(item) => are_dependencies_satisfied(item.table, synced_tables)
|
|
647
|
+
);
|
|
648
|
+
const update_retry_items = updates.filter(
|
|
649
|
+
(item) => !are_dependencies_satisfied(item.table, synced_tables)
|
|
650
|
+
);
|
|
651
|
+
const update_result = await process_bulk_updates({
|
|
652
|
+
sdk,
|
|
653
|
+
items: update_items,
|
|
654
|
+
sync_batch_id
|
|
469
655
|
});
|
|
470
|
-
|
|
656
|
+
total_synced += update_result.synced;
|
|
657
|
+
total_failed += update_result.failed;
|
|
658
|
+
update_items.forEach((item) => synced_tables.add(item.table));
|
|
659
|
+
items_to_retry.push(...update_retry_items);
|
|
660
|
+
}
|
|
661
|
+
if (deletes.length > 0) {
|
|
662
|
+
const delete_items = deletes.filter(
|
|
663
|
+
(item) => are_dependencies_satisfied(item.table, synced_tables)
|
|
664
|
+
);
|
|
665
|
+
const delete_retry_items = deletes.filter(
|
|
666
|
+
(item) => !are_dependencies_satisfied(item.table, synced_tables)
|
|
667
|
+
);
|
|
668
|
+
const delete_result = await process_bulk_deletes({
|
|
471
669
|
sdk,
|
|
472
|
-
|
|
670
|
+
items: delete_items,
|
|
473
671
|
sync_batch_id
|
|
474
672
|
});
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
673
|
+
total_synced += delete_result.synced;
|
|
674
|
+
total_failed += delete_result.failed;
|
|
675
|
+
delete_items.forEach((item) => synced_tables.add(item.table));
|
|
676
|
+
items_to_retry.push(...delete_retry_items);
|
|
677
|
+
}
|
|
678
|
+
if (items_to_retry.length > 0) {
|
|
679
|
+
const {
|
|
680
|
+
creates: retry_creates,
|
|
681
|
+
updates: retry_updates,
|
|
682
|
+
deletes: retry_deletes
|
|
683
|
+
} = group_items_by_action(items_to_retry);
|
|
684
|
+
if (retry_creates.length > 0) {
|
|
685
|
+
const create_result = await process_bulk_creates({
|
|
686
|
+
sdk,
|
|
687
|
+
items: retry_creates,
|
|
688
|
+
sync_batch_id
|
|
689
|
+
});
|
|
690
|
+
total_synced += create_result.synced;
|
|
691
|
+
total_failed += create_result.failed;
|
|
692
|
+
}
|
|
693
|
+
if (retry_updates.length > 0) {
|
|
694
|
+
const update_result = await process_bulk_updates({
|
|
695
|
+
sdk,
|
|
696
|
+
items: retry_updates,
|
|
697
|
+
sync_batch_id
|
|
698
|
+
});
|
|
699
|
+
total_synced += update_result.synced;
|
|
700
|
+
total_failed += update_result.failed;
|
|
701
|
+
}
|
|
702
|
+
if (retry_deletes.length > 0) {
|
|
703
|
+
const delete_result = await process_bulk_deletes({
|
|
704
|
+
sdk,
|
|
705
|
+
items: retry_deletes,
|
|
706
|
+
sync_batch_id
|
|
707
|
+
});
|
|
708
|
+
total_synced += delete_result.synced;
|
|
709
|
+
total_failed += delete_result.failed;
|
|
479
710
|
}
|
|
480
711
|
}
|
|
481
712
|
return {
|
|
@@ -605,13 +836,16 @@ var clear_core_db = async () => {
|
|
|
605
836
|
"refunds",
|
|
606
837
|
"payment_providers",
|
|
607
838
|
"payments",
|
|
608
|
-
"
|
|
839
|
+
"tax_classes",
|
|
609
840
|
"tax_rates",
|
|
610
841
|
"customers",
|
|
611
842
|
"locations",
|
|
612
843
|
"fulfillment_types",
|
|
613
844
|
"fulfillment_providers",
|
|
614
|
-
"fulfillments"
|
|
845
|
+
"fulfillments",
|
|
846
|
+
"connector_cache",
|
|
847
|
+
"sync_queue",
|
|
848
|
+
"sync_logs"
|
|
615
849
|
];
|
|
616
850
|
for (const table of tables) {
|
|
617
851
|
await local_db?.[table]?.clear();
|
|
@@ -3526,7 +3760,7 @@ var payments = {
|
|
|
3526
3760
|
bulk_delete: bulk_delete12
|
|
3527
3761
|
};
|
|
3528
3762
|
|
|
3529
|
-
// src/services/tax-
|
|
3763
|
+
// src/services/tax-rates.service.ts
|
|
3530
3764
|
var list13 = async (props) => {
|
|
3531
3765
|
try {
|
|
3532
3766
|
const { sdk, query } = props;
|
|
@@ -3538,15 +3772,15 @@ var list13 = async (props) => {
|
|
|
3538
3772
|
}
|
|
3539
3773
|
const adapter = await sdk.adapter();
|
|
3540
3774
|
if (!adapter) throw new Error("Adapter not found");
|
|
3541
|
-
const
|
|
3775
|
+
const rates = await adapter.tax_rates.list({
|
|
3542
3776
|
connector_config: sdk.options.configuration,
|
|
3543
3777
|
query
|
|
3544
3778
|
});
|
|
3545
3779
|
await save_bulk_data({
|
|
3546
|
-
table: "
|
|
3547
|
-
data:
|
|
3780
|
+
table: "tax_rates",
|
|
3781
|
+
data: rates
|
|
3548
3782
|
});
|
|
3549
|
-
return
|
|
3783
|
+
return rates;
|
|
3550
3784
|
} catch (error) {
|
|
3551
3785
|
throw error;
|
|
3552
3786
|
}
|
|
@@ -3562,12 +3796,12 @@ var retrieve13 = async (props) => {
|
|
|
3562
3796
|
}
|
|
3563
3797
|
const adapter = await sdk.adapter();
|
|
3564
3798
|
if (!adapter) throw new Error("Adapter not found");
|
|
3565
|
-
const
|
|
3799
|
+
const rate = await adapter.tax_rates.retrieve({
|
|
3566
3800
|
connector_config: sdk.options.configuration,
|
|
3567
3801
|
id
|
|
3568
3802
|
});
|
|
3569
|
-
await local_db.
|
|
3570
|
-
return
|
|
3803
|
+
await local_db.tax_rates.put(rate);
|
|
3804
|
+
return rate;
|
|
3571
3805
|
} catch (error) {
|
|
3572
3806
|
throw error;
|
|
3573
3807
|
}
|
|
@@ -3575,9 +3809,9 @@ var retrieve13 = async (props) => {
|
|
|
3575
3809
|
var create13 = async (props) => {
|
|
3576
3810
|
try {
|
|
3577
3811
|
const { sdk, data } = props;
|
|
3578
|
-
const offline_id = generate_offline_id("
|
|
3812
|
+
const offline_id = generate_offline_id("tax_rate");
|
|
3579
3813
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3580
|
-
const
|
|
3814
|
+
const local_rate = {
|
|
3581
3815
|
...data,
|
|
3582
3816
|
id: offline_id,
|
|
3583
3817
|
metadata: {
|
|
@@ -3588,15 +3822,15 @@ var create13 = async (props) => {
|
|
|
3588
3822
|
stall_offline_deleted_at: ""
|
|
3589
3823
|
}
|
|
3590
3824
|
};
|
|
3591
|
-
await local_db.
|
|
3825
|
+
await local_db.tax_rates.add(local_rate);
|
|
3592
3826
|
await add_to_sync_queue({
|
|
3593
3827
|
action: "create",
|
|
3594
|
-
table: "
|
|
3828
|
+
table: "tax_rates",
|
|
3595
3829
|
document_id: offline_id,
|
|
3596
3830
|
stall_offline_id: offline_id,
|
|
3597
|
-
data:
|
|
3831
|
+
data: local_rate
|
|
3598
3832
|
});
|
|
3599
|
-
return
|
|
3833
|
+
return local_rate;
|
|
3600
3834
|
} catch (error) {
|
|
3601
3835
|
throw error;
|
|
3602
3836
|
}
|
|
@@ -3604,12 +3838,12 @@ var create13 = async (props) => {
|
|
|
3604
3838
|
var update13 = async (props) => {
|
|
3605
3839
|
try {
|
|
3606
3840
|
const { sdk, id, data } = props;
|
|
3607
|
-
const existing = await local_db.
|
|
3841
|
+
const existing = await local_db.tax_rates.get(id);
|
|
3608
3842
|
if (!existing) {
|
|
3609
|
-
throw new Error(`Tax
|
|
3843
|
+
throw new Error(`Tax rate with id ${id} not found locally`);
|
|
3610
3844
|
}
|
|
3611
3845
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3612
|
-
const
|
|
3846
|
+
const updated_rate = {
|
|
3613
3847
|
...existing,
|
|
3614
3848
|
...data,
|
|
3615
3849
|
id: existing.id,
|
|
@@ -3622,15 +3856,15 @@ var update13 = async (props) => {
|
|
|
3622
3856
|
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3623
3857
|
}
|
|
3624
3858
|
};
|
|
3625
|
-
await local_db.
|
|
3859
|
+
await local_db.tax_rates.put(updated_rate);
|
|
3626
3860
|
await add_to_sync_queue({
|
|
3627
3861
|
action: "update",
|
|
3628
|
-
table: "
|
|
3862
|
+
table: "tax_rates",
|
|
3629
3863
|
document_id: id,
|
|
3630
3864
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3631
|
-
data:
|
|
3865
|
+
data: updated_rate
|
|
3632
3866
|
});
|
|
3633
|
-
return
|
|
3867
|
+
return updated_rate;
|
|
3634
3868
|
} catch (error) {
|
|
3635
3869
|
throw error;
|
|
3636
3870
|
}
|
|
@@ -3638,18 +3872,18 @@ var update13 = async (props) => {
|
|
|
3638
3872
|
var _delete13 = async (props) => {
|
|
3639
3873
|
try {
|
|
3640
3874
|
const { sdk, id } = props;
|
|
3641
|
-
const existing = await local_db.
|
|
3875
|
+
const existing = await local_db.tax_rates.get(id);
|
|
3642
3876
|
if (!existing) {
|
|
3643
|
-
throw new Error(`Tax
|
|
3877
|
+
throw new Error(`Tax rate with id ${id} not found locally`);
|
|
3644
3878
|
}
|
|
3645
3879
|
await add_to_sync_queue({
|
|
3646
3880
|
action: "delete",
|
|
3647
|
-
table: "
|
|
3881
|
+
table: "tax_rates",
|
|
3648
3882
|
document_id: id,
|
|
3649
3883
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3650
3884
|
data: { id }
|
|
3651
3885
|
});
|
|
3652
|
-
await local_db.
|
|
3886
|
+
await local_db.tax_rates.delete(id);
|
|
3653
3887
|
return;
|
|
3654
3888
|
} catch (error) {
|
|
3655
3889
|
throw error;
|
|
@@ -3659,31 +3893,31 @@ var bulk_create13 = async (props) => {
|
|
|
3659
3893
|
try {
|
|
3660
3894
|
const { sdk, data } = props;
|
|
3661
3895
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3662
|
-
const
|
|
3663
|
-
for (const
|
|
3664
|
-
const offline_id = generate_offline_id("
|
|
3665
|
-
const
|
|
3666
|
-
...
|
|
3896
|
+
const created_rates = [];
|
|
3897
|
+
for (const rate of data) {
|
|
3898
|
+
const offline_id = generate_offline_id("tax_rate");
|
|
3899
|
+
const local_rate = {
|
|
3900
|
+
...rate,
|
|
3667
3901
|
id: offline_id,
|
|
3668
3902
|
metadata: {
|
|
3669
|
-
...
|
|
3903
|
+
...rate.metadata,
|
|
3670
3904
|
stall_offline_id: offline_id,
|
|
3671
3905
|
stall_offline_created_at: now,
|
|
3672
3906
|
stall_offline_updated_at: now,
|
|
3673
3907
|
stall_offline_deleted_at: ""
|
|
3674
3908
|
}
|
|
3675
3909
|
};
|
|
3676
|
-
await local_db.
|
|
3910
|
+
await local_db.tax_rates.add(local_rate);
|
|
3677
3911
|
await add_to_sync_queue({
|
|
3678
3912
|
action: "create",
|
|
3679
|
-
table: "
|
|
3913
|
+
table: "tax_rates",
|
|
3680
3914
|
document_id: offline_id,
|
|
3681
3915
|
stall_offline_id: offline_id,
|
|
3682
|
-
data:
|
|
3916
|
+
data: local_rate
|
|
3683
3917
|
});
|
|
3684
|
-
|
|
3918
|
+
created_rates.push(local_rate);
|
|
3685
3919
|
}
|
|
3686
|
-
return
|
|
3920
|
+
return created_rates;
|
|
3687
3921
|
} catch (error) {
|
|
3688
3922
|
throw error;
|
|
3689
3923
|
}
|
|
@@ -3692,16 +3926,14 @@ var bulk_update13 = async (props) => {
|
|
|
3692
3926
|
try {
|
|
3693
3927
|
const { sdk, data } = props;
|
|
3694
3928
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3695
|
-
const
|
|
3929
|
+
const updated_rates = [];
|
|
3696
3930
|
for (const item of data) {
|
|
3697
|
-
const existing = await local_db.
|
|
3931
|
+
const existing = await local_db.tax_rates.get(item.id);
|
|
3698
3932
|
if (!existing) {
|
|
3699
|
-
console.warn(
|
|
3700
|
-
`Tax region with id ${item.id} not found locally, skipping`
|
|
3701
|
-
);
|
|
3933
|
+
console.warn(`Tax rate with id ${item.id} not found locally, skipping`);
|
|
3702
3934
|
continue;
|
|
3703
3935
|
}
|
|
3704
|
-
const
|
|
3936
|
+
const updated_rate = {
|
|
3705
3937
|
...existing,
|
|
3706
3938
|
...item.data,
|
|
3707
3939
|
id: existing.id,
|
|
@@ -3714,17 +3946,17 @@ var bulk_update13 = async (props) => {
|
|
|
3714
3946
|
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3715
3947
|
}
|
|
3716
3948
|
};
|
|
3717
|
-
await local_db.
|
|
3949
|
+
await local_db.tax_rates.put(updated_rate);
|
|
3718
3950
|
await add_to_sync_queue({
|
|
3719
3951
|
action: "update",
|
|
3720
|
-
table: "
|
|
3952
|
+
table: "tax_rates",
|
|
3721
3953
|
document_id: item.id,
|
|
3722
3954
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3723
|
-
data:
|
|
3955
|
+
data: updated_rate
|
|
3724
3956
|
});
|
|
3725
|
-
|
|
3957
|
+
updated_rates.push(updated_rate);
|
|
3726
3958
|
}
|
|
3727
|
-
return
|
|
3959
|
+
return updated_rates;
|
|
3728
3960
|
} catch (error) {
|
|
3729
3961
|
throw error;
|
|
3730
3962
|
}
|
|
@@ -3733,26 +3965,26 @@ var bulk_delete13 = async (props) => {
|
|
|
3733
3965
|
try {
|
|
3734
3966
|
const { sdk, ids } = props;
|
|
3735
3967
|
for (const id of ids) {
|
|
3736
|
-
const existing = await local_db.
|
|
3968
|
+
const existing = await local_db.tax_rates.get(id);
|
|
3737
3969
|
if (!existing) {
|
|
3738
|
-
console.warn(`Tax
|
|
3970
|
+
console.warn(`Tax rate with id ${id} not found locally, skipping`);
|
|
3739
3971
|
continue;
|
|
3740
3972
|
}
|
|
3741
3973
|
await add_to_sync_queue({
|
|
3742
3974
|
action: "delete",
|
|
3743
|
-
table: "
|
|
3975
|
+
table: "tax_rates",
|
|
3744
3976
|
document_id: id,
|
|
3745
3977
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3746
3978
|
data: { id }
|
|
3747
3979
|
});
|
|
3748
|
-
await local_db.
|
|
3980
|
+
await local_db.tax_rates.delete(id);
|
|
3749
3981
|
}
|
|
3750
3982
|
return;
|
|
3751
3983
|
} catch (error) {
|
|
3752
3984
|
throw error;
|
|
3753
3985
|
}
|
|
3754
3986
|
};
|
|
3755
|
-
var
|
|
3987
|
+
var tax_rates = {
|
|
3756
3988
|
list: list13,
|
|
3757
3989
|
retrieve: retrieve13,
|
|
3758
3990
|
create: create13,
|
|
@@ -3763,7 +3995,7 @@ var tax_regions = {
|
|
|
3763
3995
|
bulk_delete: bulk_delete13
|
|
3764
3996
|
};
|
|
3765
3997
|
|
|
3766
|
-
// src/services/tax-
|
|
3998
|
+
// src/services/tax-classes.service.ts
|
|
3767
3999
|
var list14 = async (props) => {
|
|
3768
4000
|
try {
|
|
3769
4001
|
const { sdk, query } = props;
|
|
@@ -3775,15 +4007,15 @@ var list14 = async (props) => {
|
|
|
3775
4007
|
}
|
|
3776
4008
|
const adapter = await sdk.adapter();
|
|
3777
4009
|
if (!adapter) throw new Error("Adapter not found");
|
|
3778
|
-
const
|
|
4010
|
+
const classes = await adapter.tax_classes.list({
|
|
3779
4011
|
connector_config: sdk.options.configuration,
|
|
3780
4012
|
query
|
|
3781
4013
|
});
|
|
3782
4014
|
await save_bulk_data({
|
|
3783
|
-
table: "
|
|
3784
|
-
data:
|
|
4015
|
+
table: "tax_classes",
|
|
4016
|
+
data: classes
|
|
3785
4017
|
});
|
|
3786
|
-
return
|
|
4018
|
+
return classes;
|
|
3787
4019
|
} catch (error) {
|
|
3788
4020
|
throw error;
|
|
3789
4021
|
}
|
|
@@ -3799,12 +4031,12 @@ var retrieve14 = async (props) => {
|
|
|
3799
4031
|
}
|
|
3800
4032
|
const adapter = await sdk.adapter();
|
|
3801
4033
|
if (!adapter) throw new Error("Adapter not found");
|
|
3802
|
-
const
|
|
4034
|
+
const tax_class = await adapter.tax_classes.retrieve({
|
|
3803
4035
|
connector_config: sdk.options.configuration,
|
|
3804
4036
|
id
|
|
3805
4037
|
});
|
|
3806
|
-
await local_db.
|
|
3807
|
-
return
|
|
4038
|
+
await local_db.tax_classes.put(tax_class);
|
|
4039
|
+
return tax_class;
|
|
3808
4040
|
} catch (error) {
|
|
3809
4041
|
throw error;
|
|
3810
4042
|
}
|
|
@@ -3812,9 +4044,9 @@ var retrieve14 = async (props) => {
|
|
|
3812
4044
|
var create14 = async (props) => {
|
|
3813
4045
|
try {
|
|
3814
4046
|
const { sdk, data } = props;
|
|
3815
|
-
const offline_id = generate_offline_id("
|
|
4047
|
+
const offline_id = generate_offline_id("tax_class");
|
|
3816
4048
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3817
|
-
const
|
|
4049
|
+
const local_class = {
|
|
3818
4050
|
...data,
|
|
3819
4051
|
id: offline_id,
|
|
3820
4052
|
metadata: {
|
|
@@ -3825,15 +4057,15 @@ var create14 = async (props) => {
|
|
|
3825
4057
|
stall_offline_deleted_at: ""
|
|
3826
4058
|
}
|
|
3827
4059
|
};
|
|
3828
|
-
await local_db.
|
|
4060
|
+
await local_db.tax_classes.add(local_class);
|
|
3829
4061
|
await add_to_sync_queue({
|
|
3830
4062
|
action: "create",
|
|
3831
|
-
table: "
|
|
4063
|
+
table: "tax_classes",
|
|
3832
4064
|
document_id: offline_id,
|
|
3833
4065
|
stall_offline_id: offline_id,
|
|
3834
|
-
data:
|
|
4066
|
+
data: local_class
|
|
3835
4067
|
});
|
|
3836
|
-
return
|
|
4068
|
+
return local_class;
|
|
3837
4069
|
} catch (error) {
|
|
3838
4070
|
throw error;
|
|
3839
4071
|
}
|
|
@@ -3841,12 +4073,12 @@ var create14 = async (props) => {
|
|
|
3841
4073
|
var update14 = async (props) => {
|
|
3842
4074
|
try {
|
|
3843
4075
|
const { sdk, id, data } = props;
|
|
3844
|
-
const existing = await local_db.
|
|
4076
|
+
const existing = await local_db.tax_classes.get(id);
|
|
3845
4077
|
if (!existing) {
|
|
3846
|
-
throw new Error(`Tax
|
|
4078
|
+
throw new Error(`Tax class with id ${id} not found locally`);
|
|
3847
4079
|
}
|
|
3848
4080
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3849
|
-
const
|
|
4081
|
+
const updated_class = {
|
|
3850
4082
|
...existing,
|
|
3851
4083
|
...data,
|
|
3852
4084
|
id: existing.id,
|
|
@@ -3859,15 +4091,15 @@ var update14 = async (props) => {
|
|
|
3859
4091
|
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3860
4092
|
}
|
|
3861
4093
|
};
|
|
3862
|
-
await local_db.
|
|
4094
|
+
await local_db.tax_classes.put(updated_class);
|
|
3863
4095
|
await add_to_sync_queue({
|
|
3864
4096
|
action: "update",
|
|
3865
|
-
table: "
|
|
4097
|
+
table: "tax_classes",
|
|
3866
4098
|
document_id: id,
|
|
3867
4099
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3868
|
-
data:
|
|
4100
|
+
data: updated_class
|
|
3869
4101
|
});
|
|
3870
|
-
return
|
|
4102
|
+
return updated_class;
|
|
3871
4103
|
} catch (error) {
|
|
3872
4104
|
throw error;
|
|
3873
4105
|
}
|
|
@@ -3875,18 +4107,18 @@ var update14 = async (props) => {
|
|
|
3875
4107
|
var _delete14 = async (props) => {
|
|
3876
4108
|
try {
|
|
3877
4109
|
const { sdk, id } = props;
|
|
3878
|
-
const existing = await local_db.
|
|
4110
|
+
const existing = await local_db.tax_classes.get(id);
|
|
3879
4111
|
if (!existing) {
|
|
3880
|
-
throw new Error(`Tax
|
|
4112
|
+
throw new Error(`Tax class with id ${id} not found locally`);
|
|
3881
4113
|
}
|
|
3882
4114
|
await add_to_sync_queue({
|
|
3883
4115
|
action: "delete",
|
|
3884
|
-
table: "
|
|
4116
|
+
table: "tax_classes",
|
|
3885
4117
|
document_id: id,
|
|
3886
4118
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3887
4119
|
data: { id }
|
|
3888
4120
|
});
|
|
3889
|
-
await local_db.
|
|
4121
|
+
await local_db.tax_classes.delete(id);
|
|
3890
4122
|
return;
|
|
3891
4123
|
} catch (error) {
|
|
3892
4124
|
throw error;
|
|
@@ -3896,31 +4128,31 @@ var bulk_create14 = async (props) => {
|
|
|
3896
4128
|
try {
|
|
3897
4129
|
const { sdk, data } = props;
|
|
3898
4130
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3899
|
-
const
|
|
3900
|
-
for (const
|
|
3901
|
-
const offline_id = generate_offline_id("
|
|
3902
|
-
const
|
|
3903
|
-
...
|
|
4131
|
+
const created_classes = [];
|
|
4132
|
+
for (const tax_class of data) {
|
|
4133
|
+
const offline_id = generate_offline_id("tax_class");
|
|
4134
|
+
const local_class = {
|
|
4135
|
+
...tax_class,
|
|
3904
4136
|
id: offline_id,
|
|
3905
4137
|
metadata: {
|
|
3906
|
-
...
|
|
4138
|
+
...tax_class.metadata,
|
|
3907
4139
|
stall_offline_id: offline_id,
|
|
3908
4140
|
stall_offline_created_at: now,
|
|
3909
4141
|
stall_offline_updated_at: now,
|
|
3910
4142
|
stall_offline_deleted_at: ""
|
|
3911
4143
|
}
|
|
3912
4144
|
};
|
|
3913
|
-
await local_db.
|
|
4145
|
+
await local_db.tax_classes.add(local_class);
|
|
3914
4146
|
await add_to_sync_queue({
|
|
3915
4147
|
action: "create",
|
|
3916
|
-
table: "
|
|
4148
|
+
table: "tax_classes",
|
|
3917
4149
|
document_id: offline_id,
|
|
3918
4150
|
stall_offline_id: offline_id,
|
|
3919
|
-
data:
|
|
4151
|
+
data: local_class
|
|
3920
4152
|
});
|
|
3921
|
-
|
|
4153
|
+
created_classes.push(local_class);
|
|
3922
4154
|
}
|
|
3923
|
-
return
|
|
4155
|
+
return created_classes;
|
|
3924
4156
|
} catch (error) {
|
|
3925
4157
|
throw error;
|
|
3926
4158
|
}
|
|
@@ -3929,14 +4161,14 @@ var bulk_update14 = async (props) => {
|
|
|
3929
4161
|
try {
|
|
3930
4162
|
const { sdk, data } = props;
|
|
3931
4163
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3932
|
-
const
|
|
4164
|
+
const updated_classes = [];
|
|
3933
4165
|
for (const item of data) {
|
|
3934
|
-
const existing = await local_db.
|
|
4166
|
+
const existing = await local_db.tax_classes.get(item.id);
|
|
3935
4167
|
if (!existing) {
|
|
3936
|
-
console.warn(`Tax
|
|
4168
|
+
console.warn(`Tax class with id ${item.id} not found locally, skipping`);
|
|
3937
4169
|
continue;
|
|
3938
4170
|
}
|
|
3939
|
-
const
|
|
4171
|
+
const updated_class = {
|
|
3940
4172
|
...existing,
|
|
3941
4173
|
...item.data,
|
|
3942
4174
|
id: existing.id,
|
|
@@ -3949,17 +4181,17 @@ var bulk_update14 = async (props) => {
|
|
|
3949
4181
|
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3950
4182
|
}
|
|
3951
4183
|
};
|
|
3952
|
-
await local_db.
|
|
4184
|
+
await local_db.tax_classes.put(updated_class);
|
|
3953
4185
|
await add_to_sync_queue({
|
|
3954
4186
|
action: "update",
|
|
3955
|
-
table: "
|
|
4187
|
+
table: "tax_classes",
|
|
3956
4188
|
document_id: item.id,
|
|
3957
4189
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3958
|
-
data:
|
|
4190
|
+
data: updated_class
|
|
3959
4191
|
});
|
|
3960
|
-
|
|
4192
|
+
updated_classes.push(updated_class);
|
|
3961
4193
|
}
|
|
3962
|
-
return
|
|
4194
|
+
return updated_classes;
|
|
3963
4195
|
} catch (error) {
|
|
3964
4196
|
throw error;
|
|
3965
4197
|
}
|
|
@@ -3968,26 +4200,26 @@ var bulk_delete14 = async (props) => {
|
|
|
3968
4200
|
try {
|
|
3969
4201
|
const { sdk, ids } = props;
|
|
3970
4202
|
for (const id of ids) {
|
|
3971
|
-
const existing = await local_db.
|
|
4203
|
+
const existing = await local_db.tax_classes.get(id);
|
|
3972
4204
|
if (!existing) {
|
|
3973
|
-
console.warn(`Tax
|
|
4205
|
+
console.warn(`Tax class with id ${id} not found locally, skipping`);
|
|
3974
4206
|
continue;
|
|
3975
4207
|
}
|
|
3976
4208
|
await add_to_sync_queue({
|
|
3977
4209
|
action: "delete",
|
|
3978
|
-
table: "
|
|
4210
|
+
table: "tax_classes",
|
|
3979
4211
|
document_id: id,
|
|
3980
4212
|
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3981
4213
|
data: { id }
|
|
3982
4214
|
});
|
|
3983
|
-
await local_db.
|
|
4215
|
+
await local_db.tax_classes.delete(id);
|
|
3984
4216
|
}
|
|
3985
4217
|
return;
|
|
3986
4218
|
} catch (error) {
|
|
3987
4219
|
throw error;
|
|
3988
4220
|
}
|
|
3989
4221
|
};
|
|
3990
|
-
var
|
|
4222
|
+
var tax_classes = {
|
|
3991
4223
|
list: list14,
|
|
3992
4224
|
retrieve: retrieve14,
|
|
3993
4225
|
create: create14,
|
|
@@ -4503,8 +4735,8 @@ export {
|
|
|
4503
4735
|
remove_from_sync_queue,
|
|
4504
4736
|
save_bulk_data,
|
|
4505
4737
|
sync_service,
|
|
4738
|
+
tax_classes,
|
|
4506
4739
|
tax_rates,
|
|
4507
|
-
tax_regions,
|
|
4508
4740
|
update_sync_queue_status,
|
|
4509
4741
|
variants
|
|
4510
4742
|
};
|