@use-stall/core 0.0.12 → 0.0.14

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/dist/index.js CHANGED
@@ -43,6 +43,9 @@ __export(index_exports, {
43
43
  get_sync_logs_by_batch: () => get_sync_logs_by_batch,
44
44
  initializeStallCore: () => initializeStallCore,
45
45
  inventory_levels: () => inventory_levels,
46
+ is_offline: () => is_offline,
47
+ is_online: () => is_online,
48
+ is_sync_queue_empty: () => is_sync_queue_empty,
46
49
  local_db: () => local_db,
47
50
  locations: () => locations,
48
51
  order_notes: () => order_notes,
@@ -94,45 +97,6 @@ var options = { allowEmptyDB: true };
94
97
  var local_db = new import_dexie.default("stall-core-db", options);
95
98
  local_db.version(1).stores(schemas);
96
99
 
97
- // src/core/init.ts
98
- var initializeStallCore = (options2) => {
99
- const sdk = {
100
- options: options2,
101
- adapter: async () => getAdapter(sdk),
102
- refreshAdapter: async () => getAdapter(sdk, true)
103
- };
104
- void sdk.adapter();
105
- return sdk;
106
- };
107
- var getAdapter = async (sdk, force) => {
108
- const date = Date.now();
109
- let module_code;
110
- const cache_key = "connector-module";
111
- const cached = await local_db.connector_cache.get(cache_key);
112
- if (cached && !force) {
113
- module_code = cached.code;
114
- } else {
115
- const response = await fetch(sdk.options.connector_url, {
116
- mode: "cors",
117
- method: "GET"
118
- });
119
- if (!response.ok) {
120
- throw new Error(`Failed to fetch connector: ${response.statusText}`);
121
- }
122
- module_code = await response.text();
123
- await local_db.connector_cache.put({
124
- id: cache_key,
125
- code: module_code,
126
- timestamp: date
127
- });
128
- }
129
- const blob = new Blob([module_code], { type: "application/javascript" });
130
- const blobUrl = URL.createObjectURL(blob);
131
- const module2 = await import(blobUrl);
132
- URL.revokeObjectURL(blobUrl);
133
- return module2;
134
- };
135
-
136
100
  // src/lib/utils.ts
137
101
  var generate_uuid = () => {
138
102
  return "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
@@ -141,6 +105,15 @@ var generate_uuid = () => {
141
105
  return v.toString(16);
142
106
  });
143
107
  };
108
+ var is_online = () => {
109
+ if (typeof navigator !== "undefined" && typeof navigator.onLine === "boolean") {
110
+ return navigator.onLine;
111
+ }
112
+ return true;
113
+ };
114
+ var is_offline = () => {
115
+ return !is_online();
116
+ };
144
117
 
145
118
  // src/db/helpers.ts
146
119
  var generate_offline_id = (table) => {
@@ -252,117 +225,606 @@ var get_recent_sync_logs = async (props) => {
252
225
  }
253
226
  return logs;
254
227
  };
228
+ var is_sync_queue_empty = async () => {
229
+ try {
230
+ const pending_items = await local_db.sync_queue.where("status").equals("pending").toArray();
231
+ return pending_items.length === 0;
232
+ } catch (error) {
233
+ console.error("Error checking sync queue status:", error);
234
+ return false;
235
+ }
236
+ };
255
237
  var cleanup_old_sync_logs = async (days = 30) => {
256
238
  const cutoff_time = Date.now() - days * 24 * 60 * 60 * 1e3;
257
239
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
258
240
  };
259
241
 
260
- // src/services/products.service.ts
261
- var list = async (props) => {
262
- try {
263
- const { sdk, query } = props;
264
- const adapter = await sdk.adapter();
265
- if (!adapter) throw new Error("Adapter not found");
266
- const products2 = await adapter.products.list({
267
- connector_config: sdk.options.configuration,
268
- query
269
- });
270
- await save_bulk_data({
271
- table: "products",
272
- data: products2
273
- });
274
- return products2;
275
- } catch (error) {
276
- throw error;
277
- }
242
+ // src/services/sync/sync-dependencies.ts
243
+ var SYNC_DEPENDENCY_LAYERS = {
244
+ 1: [
245
+ "tax_regions",
246
+ "tax_rates",
247
+ "categories",
248
+ "collections",
249
+ "locations",
250
+ "payment_providers",
251
+ "customers",
252
+ "promotions"
253
+ ],
254
+ 2: ["products"],
255
+ 3: ["variants", "inventory_levels"],
256
+ 4: ["orders", "order_notes"],
257
+ 5: ["payments", "refunds", "fulfillments"]
278
258
  };
279
- var retrieve = async (props) => {
280
- try {
281
- const { sdk, id } = props;
282
- const adapter = await sdk.adapter();
283
- if (!adapter) throw new Error("Adapter not found");
284
- const product = await adapter.products.retrieve({
285
- connector_config: sdk.options.configuration,
286
- id
287
- });
288
- await local_db.products.put(product);
289
- return product;
290
- } catch (error) {
291
- throw error;
259
+ var get_entity_dependencies = (table) => {
260
+ const dependencies = {
261
+ // Layer 1: Independent
262
+ tax_regions: [],
263
+ tax_rates: ["tax_regions"],
264
+ categories: [],
265
+ collections: [],
266
+ locations: [],
267
+ payment_providers: [],
268
+ customers: [],
269
+ promotions: [],
270
+ // Layer 2: Product
271
+ products: ["categories", "collections"],
272
+ // Layer 3: Variants & Inventory
273
+ variants: ["products"],
274
+ inventory_levels: ["products", "variants"],
275
+ inventory_history: ["products", "variants"],
276
+ // Layer 4: Orders
277
+ orders: ["customers", "products", "variants", "locations"],
278
+ order_notes: ["orders"],
279
+ // Layer 5: Order-related
280
+ payments: ["orders", "payment_providers"],
281
+ refunds: ["orders", "payments"],
282
+ fulfillments: ["orders"],
283
+ // Tags
284
+ tags: ["products"],
285
+ // Fulfillment config
286
+ fulfillment_types: [],
287
+ fulfillment_providers: []
288
+ };
289
+ return dependencies[table] || [];
290
+ };
291
+ var get_sync_layer = (table) => {
292
+ for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
293
+ if (tables.includes(table)) {
294
+ return parseInt(layer);
295
+ }
292
296
  }
297
+ return 99;
293
298
  };
294
- var create = async (props) => {
299
+ var sort_by_dependency_order = (items) => {
300
+ return items.sort((a, b) => {
301
+ const layer_a = get_sync_layer(a.table);
302
+ const layer_b = get_sync_layer(b.table);
303
+ if (layer_a !== layer_b) {
304
+ return layer_a - layer_b;
305
+ }
306
+ return 0;
307
+ });
308
+ };
309
+ var are_dependencies_satisfied = (table, synced_tables) => {
310
+ const dependencies = get_entity_dependencies(table);
311
+ return dependencies.every((dep) => synced_tables.has(dep));
312
+ };
313
+
314
+ // src/services/sync/sync.service.ts
315
+ var MAX_RETRIES = 3;
316
+ var SYNC_INTERVAL_MS = 2 * 60 * 1e3;
317
+ var sync_interval = null;
318
+ var is_syncing = false;
319
+ var replace_temporary_ids = async (props) => {
320
+ const { table, stall_offline_id, connector_id } = props;
295
321
  try {
296
- const { sdk, data } = props;
297
- const offline_id = generate_offline_id("product");
298
- const now = (/* @__PURE__ */ new Date()).toISOString();
299
- const local_product = {
300
- ...data,
301
- id: offline_id,
302
- metadata: {
303
- ...data.metadata,
304
- stall_offline_id: offline_id
305
- },
306
- stall_offline_id: offline_id,
307
- stall_offline_created_at: now,
308
- stall_offline_updated_at: now
309
- };
310
- await local_db.products.add(local_product);
311
- await add_to_sync_queue({
312
- action: "create",
313
- table: "products",
314
- document_id: offline_id,
315
- stall_offline_id: offline_id,
316
- data: local_product
322
+ const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
323
+ if (existing) {
324
+ await local_db[table].update(existing.id, {
325
+ id: connector_id
326
+ });
327
+ }
328
+ await update_dependent_references({
329
+ table,
330
+ old_id: stall_offline_id,
331
+ new_id: connector_id
317
332
  });
318
- return local_product;
319
333
  } catch (error) {
334
+ console.error(`Error replacing temporary IDs for ${table}:`, error);
320
335
  throw error;
321
336
  }
322
337
  };
323
- var update = async (props) => {
338
+ var update_dependent_references = async (props) => {
339
+ const { table, old_id, new_id } = props;
324
340
  try {
325
- const { sdk, id, data } = props;
326
- const existing = await local_db.products.get(id);
327
- if (!existing) {
328
- throw new Error(`Product with id ${id} not found locally`);
329
- }
330
- const now = (/* @__PURE__ */ new Date()).toISOString();
331
- const updated_product = {
332
- ...existing,
333
- ...data,
334
- id: existing.id,
335
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
336
- stall_offline_id: existing.stall_offline_id,
337
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
338
- stall_offline_updated_at: now
341
+ const reference_map = {
342
+ products: [
343
+ { table: "variants", field: "product_id" },
344
+ { table: "inventory_levels", field: "product_id" }
345
+ ],
346
+ variants: [{ table: "inventory_levels", field: "variant_id" }],
347
+ customers: [{ table: "orders", field: "customer_id" }],
348
+ orders: [
349
+ { table: "payments", field: "order_id" },
350
+ { table: "refunds", field: "order_id" },
351
+ { table: "order_notes", field: "order_id" },
352
+ { table: "fulfillments", field: "order_id" }
353
+ ],
354
+ payments: [{ table: "refunds", field: "payment_id" }],
355
+ locations: [{ table: "orders", field: "location_id" }],
356
+ categories: [{ table: "products", field: "category_id" }],
357
+ collections: [{ table: "products", field: "collection_id" }],
358
+ tax_regions: [{ table: "tax_rates", field: "region_id" }],
359
+ tax_rates: [],
360
+ tags: [],
361
+ inventory_levels: [],
362
+ inventory_history: [],
363
+ promotions: [],
364
+ order_notes: [],
365
+ refunds: [],
366
+ payment_providers: [],
367
+ fulfillments: [],
368
+ fulfillment_types: [],
369
+ fulfillment_providers: []
339
370
  };
340
- await local_db.products.put(updated_product);
341
- await add_to_sync_queue({
342
- action: "update",
343
- table: "products",
344
- document_id: id,
345
- stall_offline_id: existing.stall_offline_id,
346
- data: updated_product
347
- });
348
- return updated_product;
371
+ const references = reference_map[table] || [];
372
+ for (const ref of references) {
373
+ const records = await local_db[ref.table].toArray();
374
+ const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
375
+ ...record,
376
+ [ref.field]: new_id
377
+ }));
378
+ if (updates.length > 0) {
379
+ await local_db[ref.table].bulkPut(updates);
380
+ }
381
+ }
349
382
  } catch (error) {
350
- throw error;
383
+ console.error(`Error updating dependent references for ${table}:`, error);
351
384
  }
352
385
  };
353
- var _delete = async (props) => {
386
+ var sync_queue_item = async (props) => {
387
+ const { sdk, item, sync_batch_id } = props;
388
+ const start_time = Date.now();
354
389
  try {
355
- const { sdk, id } = props;
356
- const existing = await local_db.products.get(id);
357
- if (!existing) {
358
- throw new Error(`Product with id ${id} not found locally`);
390
+ const adapter = await sdk.adapter();
391
+ if (!adapter) {
392
+ throw new Error("Adapter not found");
359
393
  }
360
- await add_to_sync_queue({
361
- action: "delete",
394
+ const connector_config = sdk.options.configuration;
395
+ const table_module = adapter[item.table];
396
+ if (!table_module) {
397
+ throw new Error(`Module ${item.table} not found in adapter`);
398
+ }
399
+ let connector_id;
400
+ if (item.action === "create") {
401
+ const result = await table_module.create({
402
+ connector_config,
403
+ data: item.data
404
+ });
405
+ connector_id = result?.id;
406
+ if (connector_id) {
407
+ await replace_temporary_ids({
408
+ table: item.table,
409
+ stall_offline_id: item.stall_offline_id,
410
+ connector_id
411
+ });
412
+ }
413
+ } else if (item.action === "update") {
414
+ const result = await table_module.update({
415
+ connector_config,
416
+ id: item.document_id,
417
+ data: item.data
418
+ });
419
+ connector_id = result?.id || item.document_id;
420
+ } else if (item.action === "delete") {
421
+ await table_module.delete({
422
+ connector_config,
423
+ id: item.document_id
424
+ });
425
+ connector_id = item.document_id;
426
+ }
427
+ const duration = Date.now() - start_time;
428
+ await add_sync_log({
429
+ sync_batch_id,
430
+ table: item.table,
431
+ action: item.action,
432
+ document_id: item.document_id,
433
+ stall_offline_id: item.stall_offline_id,
434
+ connector_id,
435
+ status: "success",
436
+ duration_ms: duration
437
+ });
438
+ await remove_from_sync_queue(item.id);
439
+ return { success: true, connector_id };
440
+ } catch (error) {
441
+ const duration = Date.now() - start_time;
442
+ console.error(`Error syncing item ${item.id}:`, error);
443
+ const current_retries = item.retry_count || 0;
444
+ if (current_retries < MAX_RETRIES) {
445
+ await update_sync_queue_status({
446
+ id: item.id,
447
+ status: "pending",
448
+ error: error.message,
449
+ retry_count: current_retries + 1
450
+ });
451
+ } else {
452
+ await update_sync_queue_status({
453
+ id: item.id,
454
+ status: "failed",
455
+ error: `Max retries exceeded: ${error.message}`
456
+ });
457
+ }
458
+ await add_sync_log({
459
+ sync_batch_id,
460
+ table: item.table,
461
+ action: item.action,
462
+ document_id: item.document_id,
463
+ stall_offline_id: item.stall_offline_id,
464
+ status: "failed",
465
+ error: error.message,
466
+ duration_ms: duration
467
+ });
468
+ return { success: false, error: error.message };
469
+ }
470
+ };
471
+ var process_sync_queue = async (props) => {
472
+ const { sdk } = props;
473
+ const sync_batch_id = generate_uuid();
474
+ if (is_syncing) {
475
+ console.log("Sync already in progress, skipping...");
476
+ return {
477
+ sync_batch_id,
478
+ total: 0,
479
+ synced: 0,
480
+ failed: 0
481
+ };
482
+ }
483
+ is_syncing = true;
484
+ try {
485
+ const pending_items_by_table = await get_pending_sync_queue();
486
+ if (pending_items_by_table.size === 0) {
487
+ return {
488
+ sync_batch_id,
489
+ total: 0,
490
+ synced: 0,
491
+ failed: 0
492
+ };
493
+ }
494
+ let total_synced = 0;
495
+ let total_failed = 0;
496
+ const all_items = [];
497
+ pending_items_by_table.forEach((items) => {
498
+ items.forEach((item) => {
499
+ all_items.push(item);
500
+ });
501
+ });
502
+ const sorted_items = sort_by_dependency_order(
503
+ all_items
504
+ );
505
+ const synced_tables = /* @__PURE__ */ new Set();
506
+ const items_to_retry = [];
507
+ for (const item of sorted_items) {
508
+ if (!are_dependencies_satisfied(item.table, synced_tables)) {
509
+ items_to_retry.push(item);
510
+ continue;
511
+ }
512
+ await update_sync_queue_status({
513
+ id: item.id,
514
+ status: "syncing"
515
+ });
516
+ const result = await sync_queue_item({
517
+ sdk,
518
+ item,
519
+ sync_batch_id
520
+ });
521
+ if (result.success) {
522
+ total_synced++;
523
+ if (!synced_tables.has(item.table)) {
524
+ synced_tables.add(item.table);
525
+ }
526
+ } else {
527
+ total_failed++;
528
+ }
529
+ }
530
+ for (const item of items_to_retry) {
531
+ await update_sync_queue_status({
532
+ id: item.id,
533
+ status: "syncing"
534
+ });
535
+ const result = await sync_queue_item({
536
+ sdk,
537
+ item,
538
+ sync_batch_id
539
+ });
540
+ if (result.success) {
541
+ total_synced++;
542
+ } else {
543
+ total_failed++;
544
+ }
545
+ }
546
+ return {
547
+ sync_batch_id,
548
+ total: all_items.length,
549
+ synced: total_synced,
550
+ failed: total_failed
551
+ };
552
+ } catch (error) {
553
+ console.error("Error processing sync queue:", error);
554
+ return {
555
+ sync_batch_id,
556
+ total: 0,
557
+ synced: 0,
558
+ failed: 0
559
+ };
560
+ } finally {
561
+ is_syncing = false;
562
+ }
563
+ };
564
+ var get_sync_status = async () => {
565
+ try {
566
+ const all_items = await local_db.sync_queue.toArray();
567
+ const pending = all_items.filter((i) => i.status === "pending").length;
568
+ const syncing = all_items.filter((i) => i.status === "syncing").length;
569
+ const failed = all_items.filter((i) => i.status === "failed").length;
570
+ return {
571
+ pending,
572
+ syncing,
573
+ failed,
574
+ total: all_items.length,
575
+ is_sync_running: sync_interval !== null
576
+ };
577
+ } catch (error) {
578
+ console.error("Error getting sync status:", error);
579
+ return {
580
+ pending: 0,
581
+ syncing: 0,
582
+ failed: 0,
583
+ total: 0,
584
+ is_sync_running: false
585
+ };
586
+ }
587
+ };
588
+ var fix_sync_queue = async () => {
589
+ try {
590
+ const stuck_items = await local_db.sync_queue.where("status").equals("syncing").toArray();
591
+ for (const item of stuck_items) {
592
+ await update_sync_queue_status({
593
+ id: item.id,
594
+ status: "pending"
595
+ });
596
+ }
597
+ console.log(`Fixed ${stuck_items.length} stuck sync queue items`);
598
+ return {
599
+ fixed: stuck_items.length
600
+ };
601
+ } catch (error) {
602
+ console.error("Error fixing sync queue:", error);
603
+ return {
604
+ fixed: 0
605
+ };
606
+ }
607
+ };
608
+ var trigger_sync = async (props) => {
609
+ try {
610
+ const { sdk } = props;
611
+ return await process_sync_queue({ sdk });
612
+ } catch (error) {
613
+ console.error("Error triggering sync:", error);
614
+ return {
615
+ sync_batch_id: generate_uuid(),
616
+ total: 0,
617
+ synced: 0,
618
+ failed: 0
619
+ };
620
+ }
621
+ };
622
+ var start_sync = async (props) => {
623
+ const { sdk } = props;
624
+ if (sync_interval) {
625
+ console.warn("Background sync already running");
626
+ return;
627
+ }
628
+ console.log(
629
+ `Starting background sync service (${SYNC_INTERVAL_MS}ms interval)`
630
+ );
631
+ const initial_result = await process_sync_queue({ sdk });
632
+ if (initial_result.total > 0) {
633
+ console.log(
634
+ `Initial sync: ${initial_result.synced} synced, ${initial_result.failed} failed out of ${initial_result.total}`
635
+ );
636
+ }
637
+ sync_interval = setInterval(async () => {
638
+ const status = await get_sync_status();
639
+ if (status.pending > 0) {
640
+ const result = await process_sync_queue({ sdk });
641
+ if (result.total > 0) {
642
+ console.log(
643
+ `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
644
+ );
645
+ }
646
+ }
647
+ }, SYNC_INTERVAL_MS);
648
+ };
649
+ var stop_sync = () => {
650
+ if (sync_interval) {
651
+ clearInterval(sync_interval);
652
+ sync_interval = null;
653
+ console.log("Background sync service stopped");
654
+ } else {
655
+ console.warn("Background sync is not running");
656
+ }
657
+ };
658
+ var sync_service = {
659
+ get_sync_status,
660
+ fix_sync_queue,
661
+ trigger_sync,
662
+ start_sync,
663
+ stop_sync
664
+ };
665
+
666
+ // src/core/init.ts
667
+ var initializeStallCore = (options2) => {
668
+ const sdk = {
669
+ options: options2,
670
+ adapter: async () => getAdapter(sdk),
671
+ refreshAdapter: async () => getAdapter(sdk, true)
672
+ };
673
+ void sdk.adapter().then(() => {
674
+ void sync_service.start_sync({ sdk });
675
+ });
676
+ return sdk;
677
+ };
678
+ var getAdapter = async (sdk, force) => {
679
+ const date = Date.now();
680
+ let module_code;
681
+ const cache_key = "connector-module";
682
+ const cached = await local_db.connector_cache.get(cache_key);
683
+ if (cached && !force) {
684
+ module_code = cached.code;
685
+ } else {
686
+ const response = await fetch(sdk.options.connector_url, {
687
+ mode: "cors",
688
+ method: "GET"
689
+ });
690
+ if (!response.ok) {
691
+ throw new Error(`Failed to fetch connector: ${response.statusText}`);
692
+ }
693
+ module_code = await response.text();
694
+ await local_db.connector_cache.put({
695
+ id: cache_key,
696
+ code: module_code,
697
+ timestamp: date
698
+ });
699
+ }
700
+ const blob = new Blob([module_code], { type: "application/javascript" });
701
+ const blobUrl = URL.createObjectURL(blob);
702
+ const module2 = await import(blobUrl);
703
+ URL.revokeObjectURL(blobUrl);
704
+ return module2;
705
+ };
706
+
707
+ // src/services/products.service.ts
708
+ var list = async (props) => {
709
+ try {
710
+ const { sdk, query } = props;
711
+ const queue_is_empty = await is_sync_queue_empty();
712
+ if (!queue_is_empty) {
713
+ throw new Error(
714
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
715
+ );
716
+ }
717
+ const adapter = await sdk.adapter();
718
+ if (!adapter) throw new Error("Adapter not found");
719
+ const products2 = await adapter.products.list({
720
+ connector_config: sdk.options.configuration,
721
+ query
722
+ });
723
+ await save_bulk_data({
724
+ table: "products",
725
+ data: products2
726
+ });
727
+ return products2;
728
+ } catch (error) {
729
+ throw error;
730
+ }
731
+ };
732
+ var retrieve = async (props) => {
733
+ try {
734
+ const { sdk, id } = props;
735
+ const queue_is_empty = await is_sync_queue_empty();
736
+ if (!queue_is_empty) {
737
+ throw new Error(
738
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
739
+ );
740
+ }
741
+ const adapter = await sdk.adapter();
742
+ if (!adapter) throw new Error("Adapter not found");
743
+ const product = await adapter.products.retrieve({
744
+ connector_config: sdk.options.configuration,
745
+ id
746
+ });
747
+ await local_db.products.put(product);
748
+ return product;
749
+ } catch (error) {
750
+ throw error;
751
+ }
752
+ };
753
+ var create = async (props) => {
754
+ try {
755
+ const { sdk, data } = props;
756
+ const offline_id = generate_offline_id("product");
757
+ const now = (/* @__PURE__ */ new Date()).toISOString();
758
+ const local_product = {
759
+ ...data,
760
+ id: offline_id,
761
+ metadata: {
762
+ ...data.metadata,
763
+ stall_offline_id: offline_id,
764
+ stall_offline_created_at: now,
765
+ stall_offline_updated_at: now,
766
+ stall_offline_deleted_at: ""
767
+ }
768
+ };
769
+ await local_db.products.add(local_product);
770
+ await add_to_sync_queue({
771
+ action: "create",
772
+ table: "products",
773
+ document_id: offline_id,
774
+ stall_offline_id: offline_id,
775
+ data: local_product
776
+ });
777
+ return local_product;
778
+ } catch (error) {
779
+ throw error;
780
+ }
781
+ };
782
+ var update = async (props) => {
783
+ try {
784
+ const { sdk, id, data } = props;
785
+ const existing = await local_db.products.get(id);
786
+ if (!existing) {
787
+ throw new Error(`Product with id ${id} not found locally`);
788
+ }
789
+ const now = (/* @__PURE__ */ new Date()).toISOString();
790
+ const updated_product = {
791
+ ...existing,
792
+ ...data,
793
+ id: existing.id,
794
+ metadata: {
795
+ ...existing.metadata,
796
+ ...data.metadata,
797
+ stall_offline_id: existing.metadata.stall_offline_id,
798
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
799
+ stall_offline_updated_at: now,
800
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
801
+ }
802
+ };
803
+ await local_db.products.put(updated_product);
804
+ await add_to_sync_queue({
805
+ action: "update",
806
+ table: "products",
807
+ document_id: id,
808
+ stall_offline_id: existing.metadata.stall_offline_id,
809
+ data: updated_product
810
+ });
811
+ return updated_product;
812
+ } catch (error) {
813
+ throw error;
814
+ }
815
+ };
816
+ var _delete = async (props) => {
817
+ try {
818
+ const { sdk, id } = props;
819
+ const existing = await local_db.products.get(id);
820
+ if (!existing) {
821
+ throw new Error(`Product with id ${id} not found locally`);
822
+ }
823
+ await add_to_sync_queue({
824
+ action: "delete",
362
825
  table: "products",
363
826
  document_id: id,
364
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
365
- stall_offline_id: existing.stall_offline_id,
827
+ stall_offline_id: existing.metadata.stall_offline_id,
366
828
  data: { id }
367
829
  });
368
830
  await local_db.products.delete(id);
@@ -383,11 +845,11 @@ var bulk_create = async (props) => {
383
845
  id: offline_id,
384
846
  metadata: {
385
847
  ...product.metadata,
386
- stall_offline_id: offline_id
387
- },
388
- stall_offline_id: offline_id,
389
- stall_offline_created_at: now,
390
- stall_offline_updated_at: now
848
+ stall_offline_id: offline_id,
849
+ stall_offline_created_at: now,
850
+ stall_offline_updated_at: now,
851
+ stall_offline_deleted_at: ""
852
+ }
391
853
  };
392
854
  await local_db.products.add(local_product);
393
855
  await add_to_sync_queue({
@@ -419,17 +881,21 @@ var bulk_update = async (props) => {
419
881
  ...existing,
420
882
  ...item.data,
421
883
  id: existing.id,
422
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
423
- stall_offline_id: existing.stall_offline_id,
424
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
425
- stall_offline_updated_at: now
884
+ metadata: {
885
+ ...existing.metadata,
886
+ ...item.data.metadata,
887
+ stall_offline_id: existing.metadata.stall_offline_id,
888
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
889
+ stall_offline_updated_at: now,
890
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
891
+ }
426
892
  };
427
893
  await local_db.products.put(updated_product);
428
894
  await add_to_sync_queue({
429
895
  action: "update",
430
896
  table: "products",
431
897
  document_id: item.id,
432
- stall_offline_id: existing.stall_offline_id,
898
+ stall_offline_id: existing.metadata.stall_offline_id,
433
899
  data: updated_product
434
900
  });
435
901
  updated_products.push(updated_product);
@@ -452,8 +918,7 @@ var bulk_delete = async (props) => {
452
918
  action: "delete",
453
919
  table: "products",
454
920
  document_id: id,
455
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
456
- stall_offline_id: existing.stall_offline_id,
921
+ stall_offline_id: existing.metadata.stall_offline_id,
457
922
  data: { id }
458
923
  });
459
924
  await local_db.products.delete(id);
@@ -478,6 +943,12 @@ var products = {
478
943
  var list2 = async (props) => {
479
944
  try {
480
945
  const { sdk, query } = props;
946
+ const queue_is_empty = await is_sync_queue_empty();
947
+ if (!queue_is_empty) {
948
+ throw new Error(
949
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
950
+ );
951
+ }
481
952
  const adapter = await sdk.adapter();
482
953
  if (!adapter) throw new Error("Adapter not found");
483
954
  const orders2 = await adapter.orders.list({
@@ -498,6 +969,12 @@ var list2 = async (props) => {
498
969
  var retrieve2 = async (props) => {
499
970
  try {
500
971
  const { sdk, id } = props;
972
+ const queue_is_empty = await is_sync_queue_empty();
973
+ if (!queue_is_empty) {
974
+ throw new Error(
975
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
976
+ );
977
+ }
501
978
  const adapter = await sdk.adapter();
502
979
  if (!adapter) throw new Error("Adapter not found");
503
980
  const order = await adapter.orders.retrieve({
@@ -522,11 +999,11 @@ var create2 = async (props) => {
522
999
  id: offline_id,
523
1000
  metadata: {
524
1001
  ...data.metadata,
525
- stall_offline_id: offline_id
526
- },
527
- stall_offline_id: offline_id,
528
- stall_offline_created_at: now,
529
- stall_offline_updated_at: now
1002
+ stall_offline_id: offline_id,
1003
+ stall_offline_created_at: now,
1004
+ stall_offline_updated_at: now,
1005
+ stall_offline_deleted_at: ""
1006
+ }
530
1007
  };
531
1008
  await local_db.orders.add(local_order);
532
1009
  await add_to_sync_queue({
@@ -555,17 +1032,21 @@ var update2 = async (props) => {
555
1032
  ...existing,
556
1033
  ...data,
557
1034
  id: existing.id,
558
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
559
- stall_offline_id: existing.stall_offline_id,
560
- stall_offline_updated_at: now
1035
+ metadata: {
1036
+ ...existing.metadata,
1037
+ ...data.metadata,
1038
+ stall_offline_id: existing.metadata.stall_offline_id,
1039
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1040
+ stall_offline_updated_at: now,
1041
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1042
+ }
561
1043
  };
562
1044
  await local_db.orders.put(updated_order);
563
1045
  await add_to_sync_queue({
564
1046
  action: "update",
565
1047
  table: "orders",
566
1048
  document_id: id,
567
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
568
- stall_offline_id: existing.stall_offline_id,
1049
+ stall_offline_id: existing.metadata.stall_offline_id,
569
1050
  data: updated_order
570
1051
  });
571
1052
  return updated_order;
@@ -586,8 +1067,7 @@ var _delete2 = async (props) => {
586
1067
  action: "delete",
587
1068
  table: "orders",
588
1069
  document_id: id,
589
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
590
- stall_offline_id: existing.stall_offline_id,
1070
+ stall_offline_id: existing.metadata.stall_offline_id,
591
1071
  data: { id }
592
1072
  });
593
1073
  await local_db.orders.delete(id);
@@ -610,11 +1090,11 @@ var bulk_create2 = async (props) => {
610
1090
  id: offline_id,
611
1091
  metadata: {
612
1092
  ...order.metadata,
613
- stall_offline_id: offline_id
614
- },
615
- stall_offline_id: offline_id,
616
- stall_offline_created_at: now,
617
- stall_offline_updated_at: now
1093
+ stall_offline_id: offline_id,
1094
+ stall_offline_created_at: now,
1095
+ stall_offline_updated_at: now,
1096
+ stall_offline_deleted_at: ""
1097
+ }
618
1098
  };
619
1099
  await local_db.orders.add(local_order);
620
1100
  await add_to_sync_queue({
@@ -648,17 +1128,21 @@ var bulk_update2 = async (props) => {
648
1128
  ...existing,
649
1129
  ...item.data,
650
1130
  id: existing.id,
651
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
652
- stall_offline_id: existing.stall_offline_id,
653
- stall_offline_updated_at: now
1131
+ metadata: {
1132
+ ...existing.metadata,
1133
+ ...item.data.metadata,
1134
+ stall_offline_id: existing.metadata.stall_offline_id,
1135
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1136
+ stall_offline_updated_at: now,
1137
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1138
+ }
654
1139
  };
655
1140
  await local_db.orders.put(updated_order);
656
1141
  await add_to_sync_queue({
657
1142
  action: "update",
658
1143
  table: "orders",
659
1144
  document_id: item.id,
660
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
661
- stall_offline_id: existing.stall_offline_id,
1145
+ stall_offline_id: existing.metadata.stall_offline_id,
662
1146
  data: updated_order
663
1147
  });
664
1148
  updated_orders.push(updated_order);
@@ -683,8 +1167,7 @@ var bulk_delete2 = async (props) => {
683
1167
  action: "delete",
684
1168
  table: "orders",
685
1169
  document_id: id,
686
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
687
- stall_offline_id: existing.stall_offline_id,
1170
+ stall_offline_id: existing.metadata.stall_offline_id,
688
1171
  data: { id }
689
1172
  });
690
1173
  await local_db.orders.delete(id);
@@ -711,6 +1194,12 @@ var orders = {
711
1194
  var list3 = async (props) => {
712
1195
  try {
713
1196
  const { sdk, query } = props;
1197
+ const queue_is_empty = await is_sync_queue_empty();
1198
+ if (!queue_is_empty) {
1199
+ throw new Error(
1200
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1201
+ );
1202
+ }
714
1203
  const adapter = await sdk.adapter();
715
1204
  if (!adapter) throw new Error("Adapter not found");
716
1205
  const customers2 = await adapter.customers.list({
@@ -729,6 +1218,12 @@ var list3 = async (props) => {
729
1218
  var retrieve3 = async (props) => {
730
1219
  try {
731
1220
  const { sdk, id } = props;
1221
+ const queue_is_empty = await is_sync_queue_empty();
1222
+ if (!queue_is_empty) {
1223
+ throw new Error(
1224
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1225
+ );
1226
+ }
732
1227
  const adapter = await sdk.adapter();
733
1228
  if (!adapter) throw new Error("Adapter not found");
734
1229
  const customer = await adapter.customers.retrieve({
@@ -751,11 +1246,11 @@ var create3 = async (props) => {
751
1246
  id: offline_id,
752
1247
  metadata: {
753
1248
  ...data.metadata,
754
- stall_offline_id: offline_id
755
- },
756
- stall_offline_id: offline_id,
757
- stall_offline_created_at: now,
758
- stall_offline_updated_at: now
1249
+ stall_offline_id: offline_id,
1250
+ stall_offline_created_at: now,
1251
+ stall_offline_updated_at: now,
1252
+ stall_offline_deleted_at: ""
1253
+ }
759
1254
  };
760
1255
  await local_db.customers.add(local_customer);
761
1256
  await add_to_sync_queue({
@@ -782,17 +1277,21 @@ var update3 = async (props) => {
782
1277
  ...existing,
783
1278
  ...data,
784
1279
  id: existing.id,
785
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
786
- stall_offline_id: existing.stall_offline_id,
787
- stall_offline_updated_at: now
1280
+ metadata: {
1281
+ ...existing.metadata,
1282
+ ...data.metadata,
1283
+ stall_offline_id: existing.metadata.stall_offline_id,
1284
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1285
+ stall_offline_updated_at: now,
1286
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1287
+ }
788
1288
  };
789
1289
  await local_db.customers.put(updated_customer);
790
1290
  await add_to_sync_queue({
791
1291
  action: "update",
792
1292
  table: "customers",
793
1293
  document_id: id,
794
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
795
- stall_offline_id: existing.stall_offline_id,
1294
+ stall_offline_id: existing.metadata.stall_offline_id,
796
1295
  data: updated_customer
797
1296
  });
798
1297
  return updated_customer;
@@ -811,8 +1310,7 @@ var _delete3 = async (props) => {
811
1310
  action: "delete",
812
1311
  table: "customers",
813
1312
  document_id: id,
814
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
815
- stall_offline_id: existing.stall_offline_id,
1313
+ stall_offline_id: existing.metadata.stall_offline_id,
816
1314
  data: { id }
817
1315
  });
818
1316
  await local_db.customers.delete(id);
@@ -833,11 +1331,11 @@ var bulk_create3 = async (props) => {
833
1331
  id: offline_id,
834
1332
  metadata: {
835
1333
  ...customer.metadata,
836
- stall_offline_id: offline_id
837
- },
838
- stall_offline_id: offline_id,
839
- stall_offline_created_at: now,
840
- stall_offline_updated_at: now
1334
+ stall_offline_id: offline_id,
1335
+ stall_offline_created_at: now,
1336
+ stall_offline_updated_at: now,
1337
+ stall_offline_deleted_at: ""
1338
+ }
841
1339
  };
842
1340
  await local_db.customers.add(local_customer);
843
1341
  await add_to_sync_queue({
@@ -869,17 +1367,21 @@ var bulk_update3 = async (props) => {
869
1367
  ...existing,
870
1368
  ...item.data,
871
1369
  id: existing.id,
872
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
873
- stall_offline_id: existing.stall_offline_id,
874
- stall_offline_updated_at: now
1370
+ metadata: {
1371
+ ...existing.metadata,
1372
+ ...item.data.metadata,
1373
+ stall_offline_id: existing.metadata.stall_offline_id,
1374
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1375
+ stall_offline_updated_at: now,
1376
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1377
+ }
875
1378
  };
876
1379
  await local_db.customers.put(updated_customer);
877
1380
  await add_to_sync_queue({
878
1381
  action: "update",
879
1382
  table: "customers",
880
1383
  document_id: item.id,
881
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
882
- stall_offline_id: existing.stall_offline_id,
1384
+ stall_offline_id: existing.metadata.stall_offline_id,
883
1385
  data: updated_customer
884
1386
  });
885
1387
  updated_customers.push(updated_customer);
@@ -902,8 +1404,7 @@ var bulk_delete3 = async (props) => {
902
1404
  action: "delete",
903
1405
  table: "customers",
904
1406
  document_id: id,
905
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
906
- stall_offline_id: existing.stall_offline_id,
1407
+ stall_offline_id: existing.metadata.stall_offline_id,
907
1408
  data: { id }
908
1409
  });
909
1410
  await local_db.customers.delete(id);
@@ -928,6 +1429,12 @@ var customers = {
928
1429
  var list4 = async (props) => {
929
1430
  try {
930
1431
  const { sdk, query } = props;
1432
+ const queue_is_empty = await is_sync_queue_empty();
1433
+ if (!queue_is_empty) {
1434
+ throw new Error(
1435
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1436
+ );
1437
+ }
931
1438
  const adapter = await sdk.adapter();
932
1439
  if (!adapter) throw new Error("Adapter not found");
933
1440
  const collections2 = await adapter.collections.list({
@@ -946,6 +1453,12 @@ var list4 = async (props) => {
946
1453
  var retrieve4 = async (props) => {
947
1454
  try {
948
1455
  const { sdk, id } = props;
1456
+ const queue_is_empty = await is_sync_queue_empty();
1457
+ if (!queue_is_empty) {
1458
+ throw new Error(
1459
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1460
+ );
1461
+ }
949
1462
  const adapter = await sdk.adapter();
950
1463
  if (!adapter) throw new Error("Adapter not found");
951
1464
  const collection = await adapter.collections.retrieve({
@@ -968,11 +1481,11 @@ var create4 = async (props) => {
968
1481
  id: offline_id,
969
1482
  metadata: {
970
1483
  ...data.metadata,
971
- stall_offline_id: offline_id
972
- },
973
- stall_offline_id: offline_id,
974
- stall_offline_created_at: now,
975
- stall_offline_updated_at: now
1484
+ stall_offline_id: offline_id,
1485
+ stall_offline_created_at: now,
1486
+ stall_offline_updated_at: now,
1487
+ stall_offline_deleted_at: ""
1488
+ }
976
1489
  };
977
1490
  await local_db.collections.add(local_collection);
978
1491
  await add_to_sync_queue({
@@ -999,17 +1512,21 @@ var update4 = async (props) => {
999
1512
  ...existing,
1000
1513
  ...data,
1001
1514
  id: existing.id,
1002
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1003
- stall_offline_id: existing.stall_offline_id,
1004
- stall_offline_updated_at: now
1515
+ metadata: {
1516
+ ...existing.metadata,
1517
+ ...data.metadata,
1518
+ stall_offline_id: existing.metadata.stall_offline_id,
1519
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1520
+ stall_offline_updated_at: now,
1521
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1522
+ }
1005
1523
  };
1006
1524
  await local_db.collections.put(updated_collection);
1007
1525
  await add_to_sync_queue({
1008
1526
  action: "update",
1009
1527
  table: "collections",
1010
1528
  document_id: id,
1011
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1012
- stall_offline_id: existing.stall_offline_id,
1529
+ stall_offline_id: existing.metadata.stall_offline_id,
1013
1530
  data: updated_collection
1014
1531
  });
1015
1532
  return updated_collection;
@@ -1028,8 +1545,7 @@ var _delete4 = async (props) => {
1028
1545
  action: "delete",
1029
1546
  table: "collections",
1030
1547
  document_id: id,
1031
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1032
- stall_offline_id: existing.stall_offline_id,
1548
+ stall_offline_id: existing.metadata.stall_offline_id,
1033
1549
  data: { id }
1034
1550
  });
1035
1551
  await local_db.collections.delete(id);
@@ -1050,11 +1566,11 @@ var bulk_create4 = async (props) => {
1050
1566
  id: offline_id,
1051
1567
  metadata: {
1052
1568
  ...collection.metadata,
1053
- stall_offline_id: offline_id
1054
- },
1055
- stall_offline_id: offline_id,
1056
- stall_offline_created_at: now,
1057
- stall_offline_updated_at: now
1569
+ stall_offline_id: offline_id,
1570
+ stall_offline_created_at: now,
1571
+ stall_offline_updated_at: now,
1572
+ stall_offline_deleted_at: ""
1573
+ }
1058
1574
  };
1059
1575
  await local_db.collections.add(local_collection);
1060
1576
  await add_to_sync_queue({
@@ -1088,17 +1604,21 @@ var bulk_update4 = async (props) => {
1088
1604
  ...existing,
1089
1605
  ...item.data,
1090
1606
  id: existing.id,
1091
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1092
- stall_offline_id: existing.stall_offline_id,
1093
- stall_offline_updated_at: now
1607
+ metadata: {
1608
+ ...existing.metadata,
1609
+ ...item.data.metadata,
1610
+ stall_offline_id: existing.metadata.stall_offline_id,
1611
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1612
+ stall_offline_updated_at: now,
1613
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1614
+ }
1094
1615
  };
1095
1616
  await local_db.collections.put(updated_collection);
1096
1617
  await add_to_sync_queue({
1097
1618
  action: "update",
1098
1619
  table: "collections",
1099
1620
  document_id: item.id,
1100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1101
- stall_offline_id: existing.stall_offline_id,
1621
+ stall_offline_id: existing.metadata.stall_offline_id,
1102
1622
  data: updated_collection
1103
1623
  });
1104
1624
  updated_collections.push(updated_collection);
@@ -1121,8 +1641,7 @@ var bulk_delete4 = async (props) => {
1121
1641
  action: "delete",
1122
1642
  table: "collections",
1123
1643
  document_id: id,
1124
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1125
- stall_offline_id: existing.stall_offline_id,
1644
+ stall_offline_id: existing.metadata.stall_offline_id,
1126
1645
  data: { id }
1127
1646
  });
1128
1647
  await local_db.collections.delete(id);
@@ -1147,6 +1666,12 @@ var collections = {
1147
1666
  var list5 = async (props) => {
1148
1667
  try {
1149
1668
  const { sdk, query } = props;
1669
+ const queue_is_empty = await is_sync_queue_empty();
1670
+ if (!queue_is_empty) {
1671
+ throw new Error(
1672
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1673
+ );
1674
+ }
1150
1675
  const adapter = await sdk.adapter();
1151
1676
  if (!adapter) throw new Error("Adapter not found");
1152
1677
  const categories2 = await adapter.categories.list({
@@ -1165,6 +1690,12 @@ var list5 = async (props) => {
1165
1690
  var retrieve5 = async (props) => {
1166
1691
  try {
1167
1692
  const { sdk, id } = props;
1693
+ const queue_is_empty = await is_sync_queue_empty();
1694
+ if (!queue_is_empty) {
1695
+ throw new Error(
1696
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1697
+ );
1698
+ }
1168
1699
  const adapter = await sdk.adapter();
1169
1700
  if (!adapter) throw new Error("Adapter not found");
1170
1701
  const category = await adapter.categories.retrieve({
@@ -1187,11 +1718,11 @@ var create5 = async (props) => {
1187
1718
  id: offline_id,
1188
1719
  metadata: {
1189
1720
  ...data.metadata,
1190
- stall_offline_id: offline_id
1191
- },
1192
- stall_offline_id: offline_id,
1193
- stall_offline_created_at: now,
1194
- stall_offline_updated_at: now
1721
+ stall_offline_id: offline_id,
1722
+ stall_offline_created_at: now,
1723
+ stall_offline_updated_at: now,
1724
+ stall_offline_deleted_at: ""
1725
+ }
1195
1726
  };
1196
1727
  await local_db.categories.add(local_category);
1197
1728
  await add_to_sync_queue({
@@ -1218,17 +1749,21 @@ var update5 = async (props) => {
1218
1749
  ...existing,
1219
1750
  ...data,
1220
1751
  id: existing.id,
1221
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1222
- stall_offline_id: existing.stall_offline_id,
1223
- stall_offline_updated_at: now
1752
+ metadata: {
1753
+ ...existing.metadata,
1754
+ ...data.metadata,
1755
+ stall_offline_id: existing.metadata.stall_offline_id,
1756
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1757
+ stall_offline_updated_at: now,
1758
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1759
+ }
1224
1760
  };
1225
1761
  await local_db.categories.put(updated_category);
1226
1762
  await add_to_sync_queue({
1227
1763
  action: "update",
1228
1764
  table: "categories",
1229
1765
  document_id: id,
1230
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1231
- stall_offline_id: existing.stall_offline_id,
1766
+ stall_offline_id: existing.metadata.stall_offline_id,
1232
1767
  data: updated_category
1233
1768
  });
1234
1769
  return updated_category;
@@ -1247,8 +1782,7 @@ var _delete5 = async (props) => {
1247
1782
  action: "delete",
1248
1783
  table: "categories",
1249
1784
  document_id: id,
1250
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1251
- stall_offline_id: existing.stall_offline_id,
1785
+ stall_offline_id: existing.metadata.stall_offline_id,
1252
1786
  data: { id }
1253
1787
  });
1254
1788
  await local_db.categories.delete(id);
@@ -1269,11 +1803,11 @@ var bulk_create5 = async (props) => {
1269
1803
  id: offline_id,
1270
1804
  metadata: {
1271
1805
  ...category.metadata,
1272
- stall_offline_id: offline_id
1273
- },
1274
- stall_offline_id: offline_id,
1275
- stall_offline_created_at: now,
1276
- stall_offline_updated_at: now
1806
+ stall_offline_id: offline_id,
1807
+ stall_offline_created_at: now,
1808
+ stall_offline_updated_at: now,
1809
+ stall_offline_deleted_at: ""
1810
+ }
1277
1811
  };
1278
1812
  await local_db.categories.add(local_category);
1279
1813
  await add_to_sync_queue({
@@ -1305,17 +1839,21 @@ var bulk_update5 = async (props) => {
1305
1839
  ...existing,
1306
1840
  ...item.data,
1307
1841
  id: existing.id,
1308
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1309
- stall_offline_id: existing.stall_offline_id,
1310
- stall_offline_updated_at: now
1842
+ metadata: {
1843
+ ...existing.metadata,
1844
+ ...item.data.metadata,
1845
+ stall_offline_id: existing.metadata.stall_offline_id,
1846
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1847
+ stall_offline_updated_at: now,
1848
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1849
+ }
1311
1850
  };
1312
1851
  await local_db.categories.put(updated_category);
1313
1852
  await add_to_sync_queue({
1314
1853
  action: "update",
1315
1854
  table: "categories",
1316
1855
  document_id: item.id,
1317
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1318
- stall_offline_id: existing.stall_offline_id,
1856
+ stall_offline_id: existing.metadata.stall_offline_id,
1319
1857
  data: updated_category
1320
1858
  });
1321
1859
  updated_categories.push(updated_category);
@@ -1338,8 +1876,7 @@ var bulk_delete5 = async (props) => {
1338
1876
  action: "delete",
1339
1877
  table: "categories",
1340
1878
  document_id: id,
1341
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1342
- stall_offline_id: existing.stall_offline_id,
1879
+ stall_offline_id: existing.metadata.stall_offline_id,
1343
1880
  data: { id }
1344
1881
  });
1345
1882
  await local_db.categories.delete(id);
@@ -1364,6 +1901,12 @@ var categories = {
1364
1901
  var list6 = async (props) => {
1365
1902
  try {
1366
1903
  const { sdk, query } = props;
1904
+ const queue_is_empty = await is_sync_queue_empty();
1905
+ if (!queue_is_empty) {
1906
+ throw new Error(
1907
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1908
+ );
1909
+ }
1367
1910
  const adapter = await sdk.adapter();
1368
1911
  if (!adapter) throw new Error("Adapter not found");
1369
1912
  const variants2 = await adapter.variants.list({
@@ -1382,6 +1925,12 @@ var list6 = async (props) => {
1382
1925
  var retrieve6 = async (props) => {
1383
1926
  try {
1384
1927
  const { sdk, id } = props;
1928
+ const queue_is_empty = await is_sync_queue_empty();
1929
+ if (!queue_is_empty) {
1930
+ throw new Error(
1931
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1932
+ );
1933
+ }
1385
1934
  const adapter = await sdk.adapter();
1386
1935
  if (!adapter) throw new Error("Adapter not found");
1387
1936
  const variant = await adapter.variants.retrieve({
@@ -1404,11 +1953,11 @@ var create6 = async (props) => {
1404
1953
  id: offline_id,
1405
1954
  metadata: {
1406
1955
  ...data.metadata,
1407
- stall_offline_id: offline_id
1408
- },
1409
- stall_offline_id: offline_id,
1410
- stall_offline_created_at: now,
1411
- stall_offline_updated_at: now
1956
+ stall_offline_id: offline_id,
1957
+ stall_offline_created_at: now,
1958
+ stall_offline_updated_at: now,
1959
+ stall_offline_deleted_at: ""
1960
+ }
1412
1961
  };
1413
1962
  await local_db.variants.add(local_variant);
1414
1963
  await add_to_sync_queue({
@@ -1435,17 +1984,21 @@ var update6 = async (props) => {
1435
1984
  ...existing,
1436
1985
  ...data,
1437
1986
  id: existing.id,
1438
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1439
- stall_offline_id: existing.stall_offline_id,
1440
- stall_offline_updated_at: now
1987
+ metadata: {
1988
+ ...existing.metadata,
1989
+ ...data.metadata,
1990
+ stall_offline_id: existing.metadata.stall_offline_id,
1991
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1992
+ stall_offline_updated_at: now,
1993
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1994
+ }
1441
1995
  };
1442
1996
  await local_db.variants.put(updated_variant);
1443
1997
  await add_to_sync_queue({
1444
1998
  action: "update",
1445
1999
  table: "variants",
1446
2000
  document_id: id,
1447
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1448
- stall_offline_id: existing.stall_offline_id,
2001
+ stall_offline_id: existing.metadata.stall_offline_id,
1449
2002
  data: updated_variant
1450
2003
  });
1451
2004
  return updated_variant;
@@ -1464,8 +2017,7 @@ var _delete6 = async (props) => {
1464
2017
  action: "delete",
1465
2018
  table: "variants",
1466
2019
  document_id: id,
1467
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1468
- stall_offline_id: existing.stall_offline_id,
2020
+ stall_offline_id: existing.metadata.stall_offline_id,
1469
2021
  data: { id }
1470
2022
  });
1471
2023
  await local_db.variants.delete(id);
@@ -1486,11 +2038,11 @@ var bulk_create6 = async (props) => {
1486
2038
  id: offline_id,
1487
2039
  metadata: {
1488
2040
  ...variant.metadata,
1489
- stall_offline_id: offline_id
1490
- },
1491
- stall_offline_id: offline_id,
1492
- stall_offline_created_at: now,
1493
- stall_offline_updated_at: now
2041
+ stall_offline_id: offline_id,
2042
+ stall_offline_created_at: now,
2043
+ stall_offline_updated_at: now,
2044
+ stall_offline_deleted_at: ""
2045
+ }
1494
2046
  };
1495
2047
  await local_db.variants.add(local_variant);
1496
2048
  await add_to_sync_queue({
@@ -1522,17 +2074,21 @@ var bulk_update6 = async (props) => {
1522
2074
  ...existing,
1523
2075
  ...item.data,
1524
2076
  id: existing.id,
1525
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1526
- stall_offline_id: existing.stall_offline_id,
1527
- stall_offline_updated_at: now
2077
+ metadata: {
2078
+ ...existing.metadata,
2079
+ ...item.data.metadata,
2080
+ stall_offline_id: existing.metadata.stall_offline_id,
2081
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2082
+ stall_offline_updated_at: now,
2083
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2084
+ }
1528
2085
  };
1529
2086
  await local_db.variants.put(updated_variant);
1530
2087
  await add_to_sync_queue({
1531
2088
  action: "update",
1532
2089
  table: "variants",
1533
2090
  document_id: item.id,
1534
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1535
- stall_offline_id: existing.stall_offline_id,
2091
+ stall_offline_id: existing.metadata.stall_offline_id,
1536
2092
  data: updated_variant
1537
2093
  });
1538
2094
  updated_variants.push(updated_variant);
@@ -1555,8 +2111,7 @@ var bulk_delete6 = async (props) => {
1555
2111
  action: "delete",
1556
2112
  table: "variants",
1557
2113
  document_id: id,
1558
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1559
- stall_offline_id: existing.stall_offline_id,
2114
+ stall_offline_id: existing.metadata.stall_offline_id,
1560
2115
  data: { id }
1561
2116
  });
1562
2117
  await local_db.variants.delete(id);
@@ -1581,6 +2136,12 @@ var variants = {
1581
2136
  var list7 = async (props) => {
1582
2137
  try {
1583
2138
  const { sdk, query } = props;
2139
+ const queue_is_empty = await is_sync_queue_empty();
2140
+ if (!queue_is_empty) {
2141
+ throw new Error(
2142
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2143
+ );
2144
+ }
1584
2145
  const adapter = await sdk.adapter();
1585
2146
  if (!adapter) throw new Error("Adapter not found");
1586
2147
  const inventory_levels2 = await adapter.inventory_levels.list({
@@ -1599,6 +2160,12 @@ var list7 = async (props) => {
1599
2160
  var retrieve7 = async (props) => {
1600
2161
  try {
1601
2162
  const { sdk, id } = props;
2163
+ const queue_is_empty = await is_sync_queue_empty();
2164
+ if (!queue_is_empty) {
2165
+ throw new Error(
2166
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2167
+ );
2168
+ }
1602
2169
  const adapter = await sdk.adapter();
1603
2170
  if (!adapter) throw new Error("Adapter not found");
1604
2171
  const inventory_level = await adapter.inventory_levels.retrieve({
@@ -1621,12 +2188,11 @@ var create7 = async (props) => {
1621
2188
  id: offline_id,
1622
2189
  metadata: {
1623
2190
  ...data.metadata,
1624
- stall_offline_id: offline_id
1625
- },
1626
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1627
- stall_offline_id: offline_id,
1628
- stall_offline_created_at: now,
1629
- stall_offline_updated_at: now
2191
+ stall_offline_id: offline_id,
2192
+ stall_offline_created_at: now,
2193
+ stall_offline_updated_at: now,
2194
+ stall_offline_deleted_at: ""
2195
+ }
1630
2196
  };
1631
2197
  await local_db.inventory_levels.add(local_inventory_level);
1632
2198
  await add_to_sync_queue({
@@ -1653,17 +2219,21 @@ var update7 = async (props) => {
1653
2219
  ...existing,
1654
2220
  ...data,
1655
2221
  id: existing.id,
1656
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1657
- stall_offline_id: existing.stall_offline_id,
1658
- stall_offline_updated_at: now
2222
+ metadata: {
2223
+ ...existing.metadata,
2224
+ ...data.metadata,
2225
+ stall_offline_id: existing.metadata.stall_offline_id,
2226
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2227
+ stall_offline_updated_at: now,
2228
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2229
+ }
1659
2230
  };
1660
2231
  await local_db.inventory_levels.put(updated_inventory_level);
1661
2232
  await add_to_sync_queue({
1662
2233
  action: "update",
1663
2234
  table: "inventory_levels",
1664
2235
  document_id: id,
1665
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1666
- stall_offline_id: existing.stall_offline_id,
2236
+ stall_offline_id: existing.metadata.stall_offline_id,
1667
2237
  data: updated_inventory_level
1668
2238
  });
1669
2239
  return updated_inventory_level;
@@ -1682,8 +2252,7 @@ var _delete7 = async (props) => {
1682
2252
  action: "delete",
1683
2253
  table: "inventory_levels",
1684
2254
  document_id: id,
1685
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1686
- stall_offline_id: existing.stall_offline_id,
2255
+ stall_offline_id: existing.metadata.stall_offline_id,
1687
2256
  data: { id }
1688
2257
  });
1689
2258
  await local_db.inventory_levels.delete(id);
@@ -1704,12 +2273,11 @@ var bulk_create7 = async (props) => {
1704
2273
  id: offline_id,
1705
2274
  metadata: {
1706
2275
  ...inventory_level.metadata,
1707
- stall_offline_id: offline_id
1708
- },
1709
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1710
- stall_offline_id: offline_id,
1711
- stall_offline_created_at: now,
1712
- stall_offline_updated_at: now
2276
+ stall_offline_id: offline_id,
2277
+ stall_offline_created_at: now,
2278
+ stall_offline_updated_at: now,
2279
+ stall_offline_deleted_at: ""
2280
+ }
1713
2281
  };
1714
2282
  await local_db.inventory_levels.add(local_inventory_level);
1715
2283
  await add_to_sync_queue({
@@ -1743,17 +2311,21 @@ var bulk_update7 = async (props) => {
1743
2311
  ...existing,
1744
2312
  ...item.data,
1745
2313
  id: existing.id,
1746
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1747
- stall_offline_id: existing.stall_offline_id,
1748
- stall_offline_updated_at: now
2314
+ metadata: {
2315
+ ...existing.metadata,
2316
+ ...item.data.metadata,
2317
+ stall_offline_id: existing.metadata.stall_offline_id,
2318
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2319
+ stall_offline_updated_at: now,
2320
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2321
+ }
1749
2322
  };
1750
2323
  await local_db.inventory_levels.put(updated_inventory_level);
1751
2324
  await add_to_sync_queue({
1752
2325
  action: "update",
1753
2326
  table: "inventory_levels",
1754
2327
  document_id: item.id,
1755
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1756
- stall_offline_id: existing.stall_offline_id,
2328
+ stall_offline_id: existing.metadata.stall_offline_id,
1757
2329
  data: updated_inventory_level
1758
2330
  });
1759
2331
  updated_inventory_levels.push(updated_inventory_level);
@@ -1778,8 +2350,7 @@ var bulk_delete7 = async (props) => {
1778
2350
  action: "delete",
1779
2351
  table: "inventory_levels",
1780
2352
  document_id: id,
1781
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1782
- stall_offline_id: existing.stall_offline_id,
2353
+ stall_offline_id: existing.metadata.stall_offline_id,
1783
2354
  data: { id }
1784
2355
  });
1785
2356
  await local_db.inventory_levels.delete(id);
@@ -1804,6 +2375,12 @@ var inventory_levels = {
1804
2375
  var list8 = async (props) => {
1805
2376
  try {
1806
2377
  const { sdk, query } = props;
2378
+ const queue_is_empty = await is_sync_queue_empty();
2379
+ if (!queue_is_empty) {
2380
+ throw new Error(
2381
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2382
+ );
2383
+ }
1807
2384
  const adapter = await sdk.adapter();
1808
2385
  if (!adapter) throw new Error("Adapter not found");
1809
2386
  const promotions2 = await adapter.promotions.list({
@@ -1822,6 +2399,12 @@ var list8 = async (props) => {
1822
2399
  var retrieve8 = async (props) => {
1823
2400
  try {
1824
2401
  const { sdk, id } = props;
2402
+ const queue_is_empty = await is_sync_queue_empty();
2403
+ if (!queue_is_empty) {
2404
+ throw new Error(
2405
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2406
+ );
2407
+ }
1825
2408
  const adapter = await sdk.adapter();
1826
2409
  if (!adapter) throw new Error("Adapter not found");
1827
2410
  const promotion = await adapter.promotions.retrieve({
@@ -1844,12 +2427,11 @@ var create8 = async (props) => {
1844
2427
  id: offline_id,
1845
2428
  metadata: {
1846
2429
  ...data.metadata,
1847
- stall_offline_id: offline_id
1848
- },
1849
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1850
- stall_offline_id: offline_id,
1851
- stall_offline_created_at: now,
1852
- stall_offline_updated_at: now
2430
+ stall_offline_id: offline_id,
2431
+ stall_offline_created_at: now,
2432
+ stall_offline_updated_at: now,
2433
+ stall_offline_deleted_at: ""
2434
+ }
1853
2435
  };
1854
2436
  await local_db.promotions.add(local_promotion);
1855
2437
  await add_to_sync_queue({
@@ -1876,17 +2458,21 @@ var update8 = async (props) => {
1876
2458
  ...existing,
1877
2459
  ...data,
1878
2460
  id: existing.id,
1879
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1880
- stall_offline_id: existing.stall_offline_id,
1881
- stall_offline_updated_at: now
2461
+ metadata: {
2462
+ ...existing.metadata,
2463
+ ...data.metadata,
2464
+ stall_offline_id: existing.metadata.stall_offline_id,
2465
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2466
+ stall_offline_updated_at: now,
2467
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2468
+ }
1882
2469
  };
1883
2470
  await local_db.promotions.put(updated_promotion);
1884
2471
  await add_to_sync_queue({
1885
2472
  action: "update",
1886
2473
  table: "promotions",
1887
2474
  document_id: id,
1888
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1889
- stall_offline_id: existing.stall_offline_id,
2475
+ stall_offline_id: existing.metadata.stall_offline_id,
1890
2476
  data: updated_promotion
1891
2477
  });
1892
2478
  return updated_promotion;
@@ -1905,8 +2491,7 @@ var _delete8 = async (props) => {
1905
2491
  action: "delete",
1906
2492
  table: "promotions",
1907
2493
  document_id: id,
1908
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1909
- stall_offline_id: existing.stall_offline_id,
2494
+ stall_offline_id: existing.metadata.stall_offline_id,
1910
2495
  data: { id }
1911
2496
  });
1912
2497
  await local_db.promotions.delete(id);
@@ -1927,12 +2512,11 @@ var bulk_create8 = async (props) => {
1927
2512
  id: offline_id,
1928
2513
  metadata: {
1929
2514
  ...promotion.metadata,
1930
- stall_offline_id: offline_id
1931
- },
1932
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1933
- stall_offline_id: offline_id,
1934
- stall_offline_created_at: now,
1935
- stall_offline_updated_at: now
2515
+ stall_offline_id: offline_id,
2516
+ stall_offline_created_at: now,
2517
+ stall_offline_updated_at: now,
2518
+ stall_offline_deleted_at: ""
2519
+ }
1936
2520
  };
1937
2521
  await local_db.promotions.add(local_promotion);
1938
2522
  await add_to_sync_queue({
@@ -1966,17 +2550,21 @@ var bulk_update8 = async (props) => {
1966
2550
  ...existing,
1967
2551
  ...item.data,
1968
2552
  id: existing.id,
1969
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1970
- stall_offline_id: existing.stall_offline_id,
1971
- stall_offline_updated_at: now
2553
+ metadata: {
2554
+ ...existing.metadata,
2555
+ ...item.data.metadata,
2556
+ stall_offline_id: existing.metadata.stall_offline_id,
2557
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2558
+ stall_offline_updated_at: now,
2559
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2560
+ }
1972
2561
  };
1973
2562
  await local_db.promotions.put(updated_promotion);
1974
2563
  await add_to_sync_queue({
1975
2564
  action: "update",
1976
2565
  table: "promotions",
1977
2566
  document_id: item.id,
1978
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1979
- stall_offline_id: existing.stall_offline_id,
2567
+ stall_offline_id: existing.metadata.stall_offline_id,
1980
2568
  data: updated_promotion
1981
2569
  });
1982
2570
  updated_promotions.push(updated_promotion);
@@ -1999,8 +2587,7 @@ var bulk_delete8 = async (props) => {
1999
2587
  action: "delete",
2000
2588
  table: "promotions",
2001
2589
  document_id: id,
2002
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2003
- stall_offline_id: existing.stall_offline_id,
2590
+ stall_offline_id: existing.metadata.stall_offline_id,
2004
2591
  data: { id }
2005
2592
  });
2006
2593
  await local_db.promotions.delete(id);
@@ -2025,6 +2612,12 @@ var promotions = {
2025
2612
  var list9 = async (props) => {
2026
2613
  try {
2027
2614
  const { sdk, query } = props;
2615
+ const queue_is_empty = await is_sync_queue_empty();
2616
+ if (!queue_is_empty) {
2617
+ throw new Error(
2618
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2619
+ );
2620
+ }
2028
2621
  const adapter = await sdk.adapter();
2029
2622
  if (!adapter) throw new Error("Adapter not found");
2030
2623
  const order_notes2 = await adapter.order_notes.list({
@@ -2043,6 +2636,12 @@ var list9 = async (props) => {
2043
2636
  var retrieve9 = async (props) => {
2044
2637
  try {
2045
2638
  const { sdk, id } = props;
2639
+ const queue_is_empty = await is_sync_queue_empty();
2640
+ if (!queue_is_empty) {
2641
+ throw new Error(
2642
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2643
+ );
2644
+ }
2046
2645
  const adapter = await sdk.adapter();
2047
2646
  if (!adapter) throw new Error("Adapter not found");
2048
2647
  const order_note = await adapter.order_notes.retrieve({
@@ -2065,12 +2664,11 @@ var create9 = async (props) => {
2065
2664
  id: offline_id,
2066
2665
  metadata: {
2067
2666
  ...data.metadata,
2068
- stall_offline_id: offline_id
2069
- },
2070
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2071
- stall_offline_id: offline_id,
2072
- stall_offline_created_at: now,
2073
- stall_offline_updated_at: now
2667
+ stall_offline_id: offline_id,
2668
+ stall_offline_created_at: now,
2669
+ stall_offline_updated_at: now,
2670
+ stall_offline_deleted_at: ""
2671
+ }
2074
2672
  };
2075
2673
  await local_db.order_notes.add(local_order_note);
2076
2674
  await add_to_sync_queue({
@@ -2097,17 +2695,21 @@ var update9 = async (props) => {
2097
2695
  ...existing,
2098
2696
  ...data,
2099
2697
  id: existing.id,
2100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2101
- stall_offline_id: existing.stall_offline_id,
2102
- stall_offline_updated_at: now
2698
+ metadata: {
2699
+ ...existing.metadata,
2700
+ ...data.metadata,
2701
+ stall_offline_id: existing.metadata.stall_offline_id,
2702
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2703
+ stall_offline_updated_at: now,
2704
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2705
+ }
2103
2706
  };
2104
2707
  await local_db.order_notes.put(updated_order_note);
2105
2708
  await add_to_sync_queue({
2106
2709
  action: "update",
2107
2710
  table: "order_notes",
2108
2711
  document_id: id,
2109
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2110
- stall_offline_id: existing.stall_offline_id,
2712
+ stall_offline_id: existing.metadata.stall_offline_id,
2111
2713
  data: updated_order_note
2112
2714
  });
2113
2715
  return updated_order_note;
@@ -2126,8 +2728,7 @@ var _delete9 = async (props) => {
2126
2728
  action: "delete",
2127
2729
  table: "order_notes",
2128
2730
  document_id: id,
2129
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2130
- stall_offline_id: existing.stall_offline_id,
2731
+ stall_offline_id: existing.metadata.stall_offline_id,
2131
2732
  data: { id }
2132
2733
  });
2133
2734
  await local_db.order_notes.delete(id);
@@ -2148,12 +2749,11 @@ var bulk_create9 = async (props) => {
2148
2749
  id: offline_id,
2149
2750
  metadata: {
2150
2751
  ...order_note.metadata,
2151
- stall_offline_id: offline_id
2152
- },
2153
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2154
- stall_offline_id: offline_id,
2155
- stall_offline_created_at: now,
2156
- stall_offline_updated_at: now
2752
+ stall_offline_id: offline_id,
2753
+ stall_offline_created_at: now,
2754
+ stall_offline_updated_at: now,
2755
+ stall_offline_deleted_at: ""
2756
+ }
2157
2757
  };
2158
2758
  await local_db.order_notes.add(local_order_note);
2159
2759
  await add_to_sync_queue({
@@ -2187,17 +2787,21 @@ var bulk_update9 = async (props) => {
2187
2787
  ...existing,
2188
2788
  ...item.data,
2189
2789
  id: existing.id,
2190
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2191
- stall_offline_id: existing.stall_offline_id,
2192
- stall_offline_updated_at: now
2790
+ metadata: {
2791
+ ...existing.metadata,
2792
+ ...item.data.metadata,
2793
+ stall_offline_id: existing.metadata.stall_offline_id,
2794
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2795
+ stall_offline_updated_at: now,
2796
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2797
+ }
2193
2798
  };
2194
2799
  await local_db.order_notes.put(updated_order_note);
2195
2800
  await add_to_sync_queue({
2196
2801
  action: "update",
2197
2802
  table: "order_notes",
2198
2803
  document_id: item.id,
2199
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2200
- stall_offline_id: existing.stall_offline_id,
2804
+ stall_offline_id: existing.metadata.stall_offline_id,
2201
2805
  data: updated_order_note
2202
2806
  });
2203
2807
  updated_order_notes.push(updated_order_note);
@@ -2220,8 +2824,7 @@ var bulk_delete9 = async (props) => {
2220
2824
  action: "delete",
2221
2825
  table: "order_notes",
2222
2826
  document_id: id,
2223
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2224
- stall_offline_id: existing.stall_offline_id,
2827
+ stall_offline_id: existing.metadata.stall_offline_id,
2225
2828
  data: { id }
2226
2829
  });
2227
2830
  await local_db.order_notes.delete(id);
@@ -2246,6 +2849,12 @@ var order_notes = {
2246
2849
  var list10 = async (props) => {
2247
2850
  try {
2248
2851
  const { sdk, query } = props;
2852
+ const queue_is_empty = await is_sync_queue_empty();
2853
+ if (!queue_is_empty) {
2854
+ throw new Error(
2855
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2856
+ );
2857
+ }
2249
2858
  const adapter = await sdk.adapter();
2250
2859
  if (!adapter) throw new Error("Adapter not found");
2251
2860
  const refunds2 = await adapter.refunds.list({
@@ -2264,6 +2873,12 @@ var list10 = async (props) => {
2264
2873
  var retrieve10 = async (props) => {
2265
2874
  try {
2266
2875
  const { sdk, id } = props;
2876
+ const queue_is_empty = await is_sync_queue_empty();
2877
+ if (!queue_is_empty) {
2878
+ throw new Error(
2879
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2880
+ );
2881
+ }
2267
2882
  const adapter = await sdk.adapter();
2268
2883
  if (!adapter) throw new Error("Adapter not found");
2269
2884
  const refund = await adapter.refunds.retrieve({
@@ -2286,12 +2901,11 @@ var create10 = async (props) => {
2286
2901
  id: offline_id,
2287
2902
  metadata: {
2288
2903
  ...data.metadata,
2289
- stall_offline_id: offline_id
2290
- },
2291
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2292
- stall_offline_id: offline_id,
2293
- stall_offline_created_at: now,
2294
- stall_offline_updated_at: now
2904
+ stall_offline_id: offline_id,
2905
+ stall_offline_created_at: now,
2906
+ stall_offline_updated_at: now,
2907
+ stall_offline_deleted_at: ""
2908
+ }
2295
2909
  };
2296
2910
  await local_db.refunds.add(local_refund);
2297
2911
  await add_to_sync_queue({
@@ -2318,17 +2932,21 @@ var update10 = async (props) => {
2318
2932
  ...existing,
2319
2933
  ...data,
2320
2934
  id: existing.id,
2321
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2322
- stall_offline_id: existing.stall_offline_id,
2323
- stall_offline_updated_at: now
2935
+ metadata: {
2936
+ ...existing.metadata,
2937
+ ...data.metadata,
2938
+ stall_offline_id: existing.metadata.stall_offline_id,
2939
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2940
+ stall_offline_updated_at: now,
2941
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2942
+ }
2324
2943
  };
2325
2944
  await local_db.refunds.put(updated_refund);
2326
2945
  await add_to_sync_queue({
2327
2946
  action: "update",
2328
2947
  table: "refunds",
2329
2948
  document_id: id,
2330
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2331
- stall_offline_id: existing.stall_offline_id,
2949
+ stall_offline_id: existing.metadata.stall_offline_id,
2332
2950
  data: updated_refund
2333
2951
  });
2334
2952
  return updated_refund;
@@ -2347,8 +2965,7 @@ var _delete10 = async (props) => {
2347
2965
  action: "delete",
2348
2966
  table: "refunds",
2349
2967
  document_id: id,
2350
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2351
- stall_offline_id: existing.stall_offline_id,
2968
+ stall_offline_id: existing.metadata.stall_offline_id,
2352
2969
  data: { id }
2353
2970
  });
2354
2971
  await local_db.refunds.delete(id);
@@ -2369,12 +2986,11 @@ var bulk_create10 = async (props) => {
2369
2986
  id: offline_id,
2370
2987
  metadata: {
2371
2988
  ...refund.metadata,
2372
- stall_offline_id: offline_id
2373
- },
2374
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2375
- stall_offline_id: offline_id,
2376
- stall_offline_created_at: now,
2377
- stall_offline_updated_at: now
2989
+ stall_offline_id: offline_id,
2990
+ stall_offline_created_at: now,
2991
+ stall_offline_updated_at: now,
2992
+ stall_offline_deleted_at: ""
2993
+ }
2378
2994
  };
2379
2995
  await local_db.refunds.add(local_refund);
2380
2996
  await add_to_sync_queue({
@@ -2406,17 +3022,21 @@ var bulk_update10 = async (props) => {
2406
3022
  ...existing,
2407
3023
  ...item.data,
2408
3024
  id: existing.id,
2409
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2410
- stall_offline_id: existing.stall_offline_id,
2411
- stall_offline_updated_at: now
3025
+ metadata: {
3026
+ ...existing.metadata,
3027
+ ...item.data.metadata,
3028
+ stall_offline_id: existing.metadata.stall_offline_id,
3029
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3030
+ stall_offline_updated_at: now,
3031
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3032
+ }
2412
3033
  };
2413
3034
  await local_db.refunds.put(updated_refund);
2414
3035
  await add_to_sync_queue({
2415
3036
  action: "update",
2416
3037
  table: "refunds",
2417
3038
  document_id: item.id,
2418
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2419
- stall_offline_id: existing.stall_offline_id,
3039
+ stall_offline_id: existing.metadata.stall_offline_id,
2420
3040
  data: updated_refund
2421
3041
  });
2422
3042
  updated_refunds.push(updated_refund);
@@ -2439,8 +3059,7 @@ var bulk_delete10 = async (props) => {
2439
3059
  action: "delete",
2440
3060
  table: "refunds",
2441
3061
  document_id: id,
2442
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2443
- stall_offline_id: existing.stall_offline_id,
3062
+ stall_offline_id: existing.metadata.stall_offline_id,
2444
3063
  data: { id }
2445
3064
  });
2446
3065
  await local_db.refunds.delete(id);
@@ -2465,6 +3084,12 @@ var refunds = {
2465
3084
  var list11 = async (props) => {
2466
3085
  try {
2467
3086
  const { sdk, query } = props;
3087
+ const queue_is_empty = await is_sync_queue_empty();
3088
+ if (!queue_is_empty) {
3089
+ throw new Error(
3090
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3091
+ );
3092
+ }
2468
3093
  const adapter = await sdk.adapter();
2469
3094
  if (!adapter) throw new Error("Adapter not found");
2470
3095
  const payment_providers2 = await adapter.payment_providers.list({
@@ -2483,6 +3108,12 @@ var list11 = async (props) => {
2483
3108
  var retrieve11 = async (props) => {
2484
3109
  try {
2485
3110
  const { sdk, id } = props;
3111
+ const queue_is_empty = await is_sync_queue_empty();
3112
+ if (!queue_is_empty) {
3113
+ throw new Error(
3114
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3115
+ );
3116
+ }
2486
3117
  const adapter = await sdk.adapter();
2487
3118
  if (!adapter) throw new Error("Adapter not found");
2488
3119
  const payment_provider = await adapter.payment_providers.retrieve({
@@ -2504,14 +3135,12 @@ var create11 = async (props) => {
2504
3135
  ...data,
2505
3136
  id: offline_id,
2506
3137
  metadata: {
2507
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2508
3138
  ...data.metadata,
2509
- stall_offline_id: offline_id
2510
- },
2511
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2512
- stall_offline_id: offline_id,
2513
- stall_offline_created_at: now,
2514
- stall_offline_updated_at: now
3139
+ stall_offline_id: offline_id,
3140
+ stall_offline_created_at: now,
3141
+ stall_offline_updated_at: now,
3142
+ stall_offline_deleted_at: ""
3143
+ }
2515
3144
  };
2516
3145
  await local_db.payment_providers.add(local_payment_provider);
2517
3146
  await add_to_sync_queue({
@@ -2538,17 +3167,21 @@ var update11 = async (props) => {
2538
3167
  ...existing,
2539
3168
  ...data,
2540
3169
  id: existing.id,
2541
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2542
- stall_offline_id: existing.stall_offline_id,
2543
- stall_offline_updated_at: now
3170
+ metadata: {
3171
+ ...existing.metadata,
3172
+ ...data.metadata,
3173
+ stall_offline_id: existing.metadata.stall_offline_id,
3174
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3175
+ stall_offline_updated_at: now,
3176
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3177
+ }
2544
3178
  };
2545
3179
  await local_db.payment_providers.put(updated_payment_provider);
2546
3180
  await add_to_sync_queue({
2547
3181
  action: "update",
2548
3182
  table: "payment_providers",
2549
3183
  document_id: id,
2550
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2551
- stall_offline_id: existing.stall_offline_id,
3184
+ stall_offline_id: existing.metadata.stall_offline_id,
2552
3185
  data: updated_payment_provider
2553
3186
  });
2554
3187
  return updated_payment_provider;
@@ -2567,8 +3200,7 @@ var _delete11 = async (props) => {
2567
3200
  action: "delete",
2568
3201
  table: "payment_providers",
2569
3202
  document_id: id,
2570
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2571
- stall_offline_id: existing.stall_offline_id,
3203
+ stall_offline_id: existing.metadata.stall_offline_id,
2572
3204
  data: { id }
2573
3205
  });
2574
3206
  await local_db.payment_providers.delete(id);
@@ -2588,14 +3220,12 @@ var bulk_create11 = async (props) => {
2588
3220
  ...payment_provider,
2589
3221
  id: offline_id,
2590
3222
  metadata: {
2591
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2592
3223
  ...payment_provider.metadata,
2593
- stall_offline_id: offline_id
2594
- },
2595
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2596
- stall_offline_id: offline_id,
2597
- stall_offline_created_at: now,
2598
- stall_offline_updated_at: now
3224
+ stall_offline_id: offline_id,
3225
+ stall_offline_created_at: now,
3226
+ stall_offline_updated_at: now,
3227
+ stall_offline_deleted_at: ""
3228
+ }
2599
3229
  };
2600
3230
  await local_db.payment_providers.add(local_payment_provider);
2601
3231
  await add_to_sync_queue({
@@ -2629,17 +3259,21 @@ var bulk_update11 = async (props) => {
2629
3259
  ...existing,
2630
3260
  ...item.data,
2631
3261
  id: existing.id,
2632
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2633
- stall_offline_id: existing.stall_offline_id,
2634
- stall_offline_updated_at: now
3262
+ metadata: {
3263
+ ...existing.metadata,
3264
+ ...item.data.metadata,
3265
+ stall_offline_id: existing.metadata.stall_offline_id,
3266
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3267
+ stall_offline_updated_at: now,
3268
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3269
+ }
2635
3270
  };
2636
3271
  await local_db.payment_providers.put(updated_payment_provider);
2637
3272
  await add_to_sync_queue({
2638
3273
  action: "update",
2639
3274
  table: "payment_providers",
2640
3275
  document_id: item.id,
2641
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2642
- stall_offline_id: existing.stall_offline_id,
3276
+ stall_offline_id: existing.metadata.stall_offline_id,
2643
3277
  data: updated_payment_provider
2644
3278
  });
2645
3279
  updated_payment_providers.push(updated_payment_provider);
@@ -2664,8 +3298,7 @@ var bulk_delete11 = async (props) => {
2664
3298
  action: "delete",
2665
3299
  table: "payment_providers",
2666
3300
  document_id: id,
2667
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2668
- stall_offline_id: existing.stall_offline_id,
3301
+ stall_offline_id: existing.metadata.stall_offline_id,
2669
3302
  data: { id }
2670
3303
  });
2671
3304
  await local_db.payment_providers.delete(id);
@@ -2690,6 +3323,12 @@ var payment_providers = {
2690
3323
  var list12 = async (props) => {
2691
3324
  try {
2692
3325
  const { sdk, query } = props;
3326
+ const queue_is_empty = await is_sync_queue_empty();
3327
+ if (!queue_is_empty) {
3328
+ throw new Error(
3329
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3330
+ );
3331
+ }
2693
3332
  const adapter = await sdk.adapter();
2694
3333
  if (!adapter) throw new Error("Adapter not found");
2695
3334
  const payments2 = await adapter.payments.list({
@@ -2708,6 +3347,12 @@ var list12 = async (props) => {
2708
3347
  var retrieve12 = async (props) => {
2709
3348
  try {
2710
3349
  const { sdk, id } = props;
3350
+ const queue_is_empty = await is_sync_queue_empty();
3351
+ if (!queue_is_empty) {
3352
+ throw new Error(
3353
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3354
+ );
3355
+ }
2711
3356
  const adapter = await sdk.adapter();
2712
3357
  if (!adapter) throw new Error("Adapter not found");
2713
3358
  const payment = await adapter.payments.retrieve({
@@ -2730,12 +3375,11 @@ var create12 = async (props) => {
2730
3375
  id: offline_id,
2731
3376
  metadata: {
2732
3377
  ...data.metadata,
2733
- stall_offline_id: offline_id
2734
- },
2735
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2736
- stall_offline_id: offline_id,
2737
- stall_offline_created_at: now,
2738
- stall_offline_updated_at: now
3378
+ stall_offline_id: offline_id,
3379
+ stall_offline_created_at: now,
3380
+ stall_offline_updated_at: now,
3381
+ stall_offline_deleted_at: ""
3382
+ }
2739
3383
  };
2740
3384
  await local_db.payments.add(local_payment);
2741
3385
  await add_to_sync_queue({
@@ -2762,17 +3406,21 @@ var update12 = async (props) => {
2762
3406
  ...existing,
2763
3407
  ...data,
2764
3408
  id: existing.id,
2765
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2766
- stall_offline_id: existing.stall_offline_id,
2767
- stall_offline_updated_at: now
3409
+ metadata: {
3410
+ ...existing.metadata,
3411
+ ...data.metadata,
3412
+ stall_offline_id: existing.metadata.stall_offline_id,
3413
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3414
+ stall_offline_updated_at: now,
3415
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3416
+ }
2768
3417
  };
2769
3418
  await local_db.payments.put(updated_payment);
2770
3419
  await add_to_sync_queue({
2771
3420
  action: "update",
2772
3421
  table: "payments",
2773
3422
  document_id: id,
2774
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2775
- stall_offline_id: existing.stall_offline_id,
3423
+ stall_offline_id: existing.metadata.stall_offline_id,
2776
3424
  data: updated_payment
2777
3425
  });
2778
3426
  return updated_payment;
@@ -2791,8 +3439,7 @@ var _delete12 = async (props) => {
2791
3439
  action: "delete",
2792
3440
  table: "payments",
2793
3441
  document_id: id,
2794
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2795
- stall_offline_id: existing.stall_offline_id,
3442
+ stall_offline_id: existing.metadata.stall_offline_id,
2796
3443
  data: { id }
2797
3444
  });
2798
3445
  await local_db.payments.delete(id);
@@ -2813,12 +3460,11 @@ var bulk_create12 = async (props) => {
2813
3460
  id: offline_id,
2814
3461
  metadata: {
2815
3462
  ...payment.metadata,
2816
- stall_offline_id: offline_id
2817
- },
2818
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2819
- stall_offline_id: offline_id,
2820
- stall_offline_created_at: now,
2821
- stall_offline_updated_at: now
3463
+ stall_offline_id: offline_id,
3464
+ stall_offline_created_at: now,
3465
+ stall_offline_updated_at: now,
3466
+ stall_offline_deleted_at: ""
3467
+ }
2822
3468
  };
2823
3469
  await local_db.payments.add(local_payment);
2824
3470
  await add_to_sync_queue({
@@ -2850,17 +3496,21 @@ var bulk_update12 = async (props) => {
2850
3496
  ...existing,
2851
3497
  ...item.data,
2852
3498
  id: existing.id,
2853
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2854
- stall_offline_id: existing.stall_offline_id,
2855
- stall_offline_updated_at: now
3499
+ metadata: {
3500
+ ...existing.metadata,
3501
+ ...item.data.metadata,
3502
+ stall_offline_id: existing.metadata.stall_offline_id,
3503
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3504
+ stall_offline_updated_at: now,
3505
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3506
+ }
2856
3507
  };
2857
3508
  await local_db.payments.put(updated_payment);
2858
3509
  await add_to_sync_queue({
2859
3510
  action: "update",
2860
3511
  table: "payments",
2861
3512
  document_id: item.id,
2862
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2863
- stall_offline_id: existing.stall_offline_id,
3513
+ stall_offline_id: existing.metadata.stall_offline_id,
2864
3514
  data: updated_payment
2865
3515
  });
2866
3516
  updated_payments.push(updated_payment);
@@ -2883,8 +3533,7 @@ var bulk_delete12 = async (props) => {
2883
3533
  action: "delete",
2884
3534
  table: "payments",
2885
3535
  document_id: id,
2886
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2887
- stall_offline_id: existing.stall_offline_id,
3536
+ stall_offline_id: existing.metadata.stall_offline_id,
2888
3537
  data: { id }
2889
3538
  });
2890
3539
  await local_db.payments.delete(id);
@@ -2909,6 +3558,12 @@ var payments = {
2909
3558
  var list13 = async (props) => {
2910
3559
  try {
2911
3560
  const { sdk, query } = props;
3561
+ const queue_is_empty = await is_sync_queue_empty();
3562
+ if (!queue_is_empty) {
3563
+ throw new Error(
3564
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3565
+ );
3566
+ }
2912
3567
  const adapter = await sdk.adapter();
2913
3568
  if (!adapter) throw new Error("Adapter not found");
2914
3569
  const regions = await adapter.tax_regions.list({
@@ -2927,6 +3582,12 @@ var list13 = async (props) => {
2927
3582
  var retrieve13 = async (props) => {
2928
3583
  try {
2929
3584
  const { sdk, id } = props;
3585
+ const queue_is_empty = await is_sync_queue_empty();
3586
+ if (!queue_is_empty) {
3587
+ throw new Error(
3588
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3589
+ );
3590
+ }
2930
3591
  const adapter = await sdk.adapter();
2931
3592
  if (!adapter) throw new Error("Adapter not found");
2932
3593
  const region = await adapter.tax_regions.retrieve({
@@ -2949,11 +3610,11 @@ var create13 = async (props) => {
2949
3610
  id: offline_id,
2950
3611
  metadata: {
2951
3612
  ...data.metadata,
2952
- stall_offline_id: offline_id
2953
- },
2954
- stall_offline_id: offline_id,
2955
- stall_offline_created_at: now,
2956
- stall_offline_updated_at: now
3613
+ stall_offline_id: offline_id,
3614
+ stall_offline_created_at: now,
3615
+ stall_offline_updated_at: now,
3616
+ stall_offline_deleted_at: ""
3617
+ }
2957
3618
  };
2958
3619
  await local_db.tax_regions.add(local_region);
2959
3620
  await add_to_sync_queue({
@@ -2980,17 +3641,21 @@ var update13 = async (props) => {
2980
3641
  ...existing,
2981
3642
  ...data,
2982
3643
  id: existing.id,
2983
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2984
- stall_offline_id: existing.stall_offline_id,
2985
- stall_offline_updated_at: now
3644
+ metadata: {
3645
+ ...existing.metadata,
3646
+ ...data.metadata,
3647
+ stall_offline_id: existing.metadata.stall_offline_id,
3648
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3649
+ stall_offline_updated_at: now,
3650
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3651
+ }
2986
3652
  };
2987
3653
  await local_db.tax_regions.put(updated_region);
2988
3654
  await add_to_sync_queue({
2989
3655
  action: "update",
2990
3656
  table: "tax_regions",
2991
3657
  document_id: id,
2992
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2993
- stall_offline_id: existing.stall_offline_id,
3658
+ stall_offline_id: existing.metadata.stall_offline_id,
2994
3659
  data: updated_region
2995
3660
  });
2996
3661
  return updated_region;
@@ -3009,8 +3674,7 @@ var _delete13 = async (props) => {
3009
3674
  action: "delete",
3010
3675
  table: "tax_regions",
3011
3676
  document_id: id,
3012
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3013
- stall_offline_id: existing.stall_offline_id,
3677
+ stall_offline_id: existing.metadata.stall_offline_id,
3014
3678
  data: { id }
3015
3679
  });
3016
3680
  await local_db.tax_regions.delete(id);
@@ -3031,11 +3695,11 @@ var bulk_create13 = async (props) => {
3031
3695
  id: offline_id,
3032
3696
  metadata: {
3033
3697
  ...region.metadata,
3034
- stall_offline_id: offline_id
3035
- },
3036
- stall_offline_id: offline_id,
3037
- stall_offline_created_at: now,
3038
- stall_offline_updated_at: now
3698
+ stall_offline_id: offline_id,
3699
+ stall_offline_created_at: now,
3700
+ stall_offline_updated_at: now,
3701
+ stall_offline_deleted_at: ""
3702
+ }
3039
3703
  };
3040
3704
  await local_db.tax_regions.add(local_region);
3041
3705
  await add_to_sync_queue({
@@ -3069,17 +3733,21 @@ var bulk_update13 = async (props) => {
3069
3733
  ...existing,
3070
3734
  ...item.data,
3071
3735
  id: existing.id,
3072
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3073
- stall_offline_id: existing.stall_offline_id,
3074
- stall_offline_updated_at: now
3736
+ metadata: {
3737
+ ...existing.metadata,
3738
+ ...item.data.metadata,
3739
+ stall_offline_id: existing.metadata.stall_offline_id,
3740
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3741
+ stall_offline_updated_at: now,
3742
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3743
+ }
3075
3744
  };
3076
3745
  await local_db.tax_regions.put(updated_region);
3077
3746
  await add_to_sync_queue({
3078
3747
  action: "update",
3079
3748
  table: "tax_regions",
3080
3749
  document_id: item.id,
3081
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3082
- stall_offline_id: existing.stall_offline_id,
3750
+ stall_offline_id: existing.metadata.stall_offline_id,
3083
3751
  data: updated_region
3084
3752
  });
3085
3753
  updated_regions.push(updated_region);
@@ -3102,8 +3770,7 @@ var bulk_delete13 = async (props) => {
3102
3770
  action: "delete",
3103
3771
  table: "tax_regions",
3104
3772
  document_id: id,
3105
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3106
- stall_offline_id: existing.stall_offline_id,
3773
+ stall_offline_id: existing.metadata.stall_offline_id,
3107
3774
  data: { id }
3108
3775
  });
3109
3776
  await local_db.tax_regions.delete(id);
@@ -3128,6 +3795,12 @@ var tax_regions = {
3128
3795
  var list14 = async (props) => {
3129
3796
  try {
3130
3797
  const { sdk, query } = props;
3798
+ const queue_is_empty = await is_sync_queue_empty();
3799
+ if (!queue_is_empty) {
3800
+ throw new Error(
3801
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3802
+ );
3803
+ }
3131
3804
  const adapter = await sdk.adapter();
3132
3805
  if (!adapter) throw new Error("Adapter not found");
3133
3806
  const rates = await adapter.tax_rates.list({
@@ -3146,6 +3819,12 @@ var list14 = async (props) => {
3146
3819
  var retrieve14 = async (props) => {
3147
3820
  try {
3148
3821
  const { sdk, id } = props;
3822
+ const queue_is_empty = await is_sync_queue_empty();
3823
+ if (!queue_is_empty) {
3824
+ throw new Error(
3825
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3826
+ );
3827
+ }
3149
3828
  const adapter = await sdk.adapter();
3150
3829
  if (!adapter) throw new Error("Adapter not found");
3151
3830
  const rate = await adapter.tax_rates.retrieve({
@@ -3168,11 +3847,11 @@ var create14 = async (props) => {
3168
3847
  id: offline_id,
3169
3848
  metadata: {
3170
3849
  ...data.metadata,
3171
- stall_offline_id: offline_id
3172
- },
3173
- stall_offline_id: offline_id,
3174
- stall_offline_created_at: now,
3175
- stall_offline_updated_at: now
3850
+ stall_offline_id: offline_id,
3851
+ stall_offline_created_at: now,
3852
+ stall_offline_updated_at: now,
3853
+ stall_offline_deleted_at: ""
3854
+ }
3176
3855
  };
3177
3856
  await local_db.tax_rates.add(local_rate);
3178
3857
  await add_to_sync_queue({
@@ -3199,17 +3878,21 @@ var update14 = async (props) => {
3199
3878
  ...existing,
3200
3879
  ...data,
3201
3880
  id: existing.id,
3202
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3203
- stall_offline_id: existing.stall_offline_id,
3204
- stall_offline_updated_at: now
3881
+ metadata: {
3882
+ ...existing.metadata,
3883
+ ...data.metadata,
3884
+ stall_offline_id: existing.metadata.stall_offline_id,
3885
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3886
+ stall_offline_updated_at: now,
3887
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3888
+ }
3205
3889
  };
3206
3890
  await local_db.tax_rates.put(updated_rate);
3207
3891
  await add_to_sync_queue({
3208
3892
  action: "update",
3209
3893
  table: "tax_rates",
3210
3894
  document_id: id,
3211
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3212
- stall_offline_id: existing.stall_offline_id,
3895
+ stall_offline_id: existing.metadata.stall_offline_id,
3213
3896
  data: updated_rate
3214
3897
  });
3215
3898
  return updated_rate;
@@ -3228,8 +3911,7 @@ var _delete14 = async (props) => {
3228
3911
  action: "delete",
3229
3912
  table: "tax_rates",
3230
3913
  document_id: id,
3231
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3232
- stall_offline_id: existing.stall_offline_id,
3914
+ stall_offline_id: existing.metadata.stall_offline_id,
3233
3915
  data: { id }
3234
3916
  });
3235
3917
  await local_db.tax_rates.delete(id);
@@ -3250,11 +3932,11 @@ var bulk_create14 = async (props) => {
3250
3932
  id: offline_id,
3251
3933
  metadata: {
3252
3934
  ...rate.metadata,
3253
- stall_offline_id: offline_id
3254
- },
3255
- stall_offline_id: offline_id,
3256
- stall_offline_created_at: now,
3257
- stall_offline_updated_at: now
3935
+ stall_offline_id: offline_id,
3936
+ stall_offline_created_at: now,
3937
+ stall_offline_updated_at: now,
3938
+ stall_offline_deleted_at: ""
3939
+ }
3258
3940
  };
3259
3941
  await local_db.tax_rates.add(local_rate);
3260
3942
  await add_to_sync_queue({
@@ -3286,17 +3968,21 @@ var bulk_update14 = async (props) => {
3286
3968
  ...existing,
3287
3969
  ...item.data,
3288
3970
  id: existing.id,
3289
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3290
- stall_offline_id: existing.stall_offline_id,
3291
- stall_offline_updated_at: now
3971
+ metadata: {
3972
+ ...existing.metadata,
3973
+ ...item.data.metadata,
3974
+ stall_offline_id: existing.metadata.stall_offline_id,
3975
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3976
+ stall_offline_updated_at: now,
3977
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3978
+ }
3292
3979
  };
3293
3980
  await local_db.tax_rates.put(updated_rate);
3294
3981
  await add_to_sync_queue({
3295
3982
  action: "update",
3296
3983
  table: "tax_rates",
3297
3984
  document_id: item.id,
3298
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3299
- stall_offline_id: existing.stall_offline_id,
3985
+ stall_offline_id: existing.metadata.stall_offline_id,
3300
3986
  data: updated_rate
3301
3987
  });
3302
3988
  updated_rates.push(updated_rate);
@@ -3319,8 +4005,7 @@ var bulk_delete14 = async (props) => {
3319
4005
  action: "delete",
3320
4006
  table: "tax_rates",
3321
4007
  document_id: id,
3322
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3323
- stall_offline_id: existing.stall_offline_id,
4008
+ stall_offline_id: existing.metadata.stall_offline_id,
3324
4009
  data: { id }
3325
4010
  });
3326
4011
  await local_db.tax_rates.delete(id);
@@ -3360,7 +4045,8 @@ var build_location = (data, offline_id, now) => {
3360
4045
  ...data.metadata,
3361
4046
  stall_offline_id: offline_id,
3362
4047
  stall_offline_created_at: now,
3363
- stall_offline_updated_at: now
4048
+ stall_offline_updated_at: now,
4049
+ stall_offline_deleted_at: ""
3364
4050
  }
3365
4051
  };
3366
4052
  };
@@ -3381,15 +4067,22 @@ var merge_location = (existing, updates, now) => {
3381
4067
  metadata: {
3382
4068
  ...existing.metadata,
3383
4069
  ...updates.metadata,
3384
- stall_offline_id: existing.metadata?.stall_offline_id,
3385
- stall_offline_created_at: existing.metadata?.stall_offline_created_at,
3386
- stall_offline_updated_at: now
4070
+ stall_offline_id: existing.metadata?.stall_offline_id || "",
4071
+ stall_offline_created_at: existing.metadata?.stall_offline_created_at || "",
4072
+ stall_offline_updated_at: now,
4073
+ stall_offline_deleted_at: existing.metadata?.stall_offline_deleted_at || ""
3387
4074
  }
3388
4075
  };
3389
4076
  };
3390
4077
  var list15 = async (props) => {
3391
4078
  try {
3392
4079
  const { sdk, query } = props;
4080
+ const queue_is_empty = await is_sync_queue_empty();
4081
+ if (!queue_is_empty) {
4082
+ throw new Error(
4083
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4084
+ );
4085
+ }
3393
4086
  const adapter = await sdk.adapter();
3394
4087
  if (!adapter) throw new Error("Adapter not found");
3395
4088
  const locations2 = await adapter.locations.list({
@@ -3408,6 +4101,12 @@ var list15 = async (props) => {
3408
4101
  var retrieve15 = async (props) => {
3409
4102
  try {
3410
4103
  const { sdk, id } = props;
4104
+ const queue_is_empty = await is_sync_queue_empty();
4105
+ if (!queue_is_empty) {
4106
+ throw new Error(
4107
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4108
+ );
4109
+ }
3411
4110
  const adapter = await sdk.adapter();
3412
4111
  if (!adapter) throw new Error("Adapter not found");
3413
4112
  const location = await adapter.locations.retrieve({
@@ -3537,657 +4236,269 @@ var bulk_delete15 = async (props) => {
3537
4236
  for (const id of ids) {
3538
4237
  const existing = await local_db.locations.get(id);
3539
4238
  if (!existing) {
3540
- console.warn(`Location with id ${id} not found locally, skipping`);
3541
- continue;
3542
- }
3543
- await add_to_sync_queue({
3544
- action: "delete",
3545
- table: "locations",
3546
- document_id: id,
3547
- stall_offline_id: existing.metadata?.stall_offline_id || id,
3548
- data: { id }
3549
- });
3550
- await local_db.locations.delete(id);
3551
- }
3552
- return;
3553
- } catch (error) {
3554
- throw error;
3555
- }
3556
- };
3557
- var locations = {
3558
- list: list15,
3559
- retrieve: retrieve15,
3560
- create: create15,
3561
- update: update15,
3562
- delete: _delete15,
3563
- bulk_create: bulk_create15,
3564
- bulk_update: bulk_update15,
3565
- bulk_delete: bulk_delete15
3566
- };
3567
-
3568
- // src/services/fulfillments.service.ts
3569
- var list16 = async (props) => {
3570
- try {
3571
- const { sdk, query } = props;
3572
- const adapter = await sdk.adapter();
3573
- if (!adapter) throw new Error("Adapter not found");
3574
- const fulfillments2 = await adapter.fulfillments.list({
3575
- connector_config: sdk.options.configuration,
3576
- query
3577
- });
3578
- await save_bulk_data({
3579
- table: "fulfillments",
3580
- data: fulfillments2
3581
- });
3582
- return fulfillments2;
3583
- } catch (error) {
3584
- throw error;
3585
- }
3586
- };
3587
- var retrieve16 = async (props) => {
3588
- try {
3589
- const { sdk, id } = props;
3590
- const adapter = await sdk.adapter();
3591
- if (!adapter) throw new Error("Adapter not found");
3592
- const fulfillment = await adapter.fulfillments.retrieve({
3593
- connector_config: sdk.options.configuration,
3594
- id
3595
- });
3596
- await local_db.fulfillments.put(fulfillment);
3597
- return fulfillment;
3598
- } catch (error) {
3599
- throw error;
3600
- }
3601
- };
3602
- var create16 = async (props) => {
3603
- try {
3604
- const { sdk, data } = props;
3605
- const offline_id = generate_offline_id("fulfillment");
3606
- const now = (/* @__PURE__ */ new Date()).toISOString();
3607
- const local_fulfillment = {
3608
- ...data,
3609
- id: offline_id,
3610
- metadata: {
3611
- ...data.metadata,
3612
- stall_offline_id: offline_id
3613
- },
3614
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3615
- stall_offline_id: offline_id,
3616
- stall_offline_created_at: now,
3617
- stall_offline_updated_at: now
3618
- };
3619
- await local_db.fulfillments.add(local_fulfillment);
3620
- await add_to_sync_queue({
3621
- action: "create",
3622
- table: "fulfillments",
3623
- document_id: offline_id,
3624
- stall_offline_id: offline_id,
3625
- data: local_fulfillment
3626
- });
3627
- return local_fulfillment;
3628
- } catch (error) {
3629
- throw error;
3630
- }
3631
- };
3632
- var update16 = async (props) => {
3633
- try {
3634
- const { sdk, id, data } = props;
3635
- const existing = await local_db.fulfillments.get(id);
3636
- if (!existing) {
3637
- throw new Error(`Fulfillment with id ${id} not found locally`);
3638
- }
3639
- const now = (/* @__PURE__ */ new Date()).toISOString();
3640
- const updated_fulfillment = {
3641
- ...existing,
3642
- ...data,
3643
- id: existing.id,
3644
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3645
- stall_offline_id: existing.stall_offline_id,
3646
- stall_offline_updated_at: now
3647
- };
3648
- await local_db.fulfillments.put(updated_fulfillment);
3649
- await add_to_sync_queue({
3650
- action: "update",
3651
- table: "fulfillments",
3652
- document_id: id,
3653
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3654
- stall_offline_id: existing.stall_offline_id,
3655
- data: updated_fulfillment
3656
- });
3657
- return updated_fulfillment;
3658
- } catch (error) {
3659
- throw error;
3660
- }
3661
- };
3662
- var _delete16 = async (props) => {
3663
- try {
3664
- const { sdk, id } = props;
3665
- const existing = await local_db.fulfillments.get(id);
3666
- if (!existing) {
3667
- throw new Error(`Fulfillment with id ${id} not found locally`);
3668
- }
3669
- await add_to_sync_queue({
3670
- action: "delete",
3671
- table: "fulfillments",
3672
- document_id: id,
3673
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3674
- stall_offline_id: existing.stall_offline_id,
3675
- data: { id }
3676
- });
3677
- await local_db.fulfillments.delete(id);
3678
- return;
3679
- } catch (error) {
3680
- throw error;
3681
- }
3682
- };
3683
- var bulk_create16 = async (props) => {
3684
- try {
3685
- const { sdk, data } = props;
3686
- const now = (/* @__PURE__ */ new Date()).toISOString();
3687
- const created_fulfillments = [];
3688
- for (const fulfillment of data) {
3689
- const offline_id = generate_offline_id("fulfillment");
3690
- const local_fulfillment = {
3691
- ...fulfillment,
3692
- id: offline_id,
3693
- metadata: {
3694
- ...fulfillment.metadata,
3695
- stall_offline_id: offline_id
3696
- },
3697
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3698
- stall_offline_id: offline_id,
3699
- stall_offline_created_at: now,
3700
- stall_offline_updated_at: now
3701
- };
3702
- await local_db.fulfillments.add(local_fulfillment);
3703
- await add_to_sync_queue({
3704
- action: "create",
3705
- table: "fulfillments",
3706
- document_id: offline_id,
3707
- stall_offline_id: offline_id,
3708
- data: local_fulfillment
3709
- });
3710
- created_fulfillments.push(local_fulfillment);
3711
- }
3712
- return created_fulfillments;
3713
- } catch (error) {
3714
- throw error;
3715
- }
3716
- };
3717
- var bulk_update16 = async (props) => {
3718
- try {
3719
- const { sdk, data } = props;
3720
- const now = (/* @__PURE__ */ new Date()).toISOString();
3721
- const updated_fulfillments = [];
3722
- for (const item of data) {
3723
- const existing = await local_db.fulfillments.get(item.id);
3724
- if (!existing) {
3725
- console.warn(
3726
- `Fulfillment with id ${item.id} not found locally, skipping`
3727
- );
3728
- continue;
3729
- }
3730
- const updated_fulfillment = {
3731
- ...existing,
3732
- ...item.data,
3733
- id: existing.id,
3734
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3735
- stall_offline_id: existing.stall_offline_id,
3736
- stall_offline_updated_at: now
3737
- };
3738
- await local_db.fulfillments.put(updated_fulfillment);
3739
- await add_to_sync_queue({
3740
- action: "update",
3741
- table: "fulfillments",
3742
- document_id: item.id,
3743
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3744
- stall_offline_id: existing.stall_offline_id,
3745
- data: updated_fulfillment
3746
- });
3747
- updated_fulfillments.push(updated_fulfillment);
3748
- }
3749
- return updated_fulfillments;
3750
- } catch (error) {
3751
- throw error;
3752
- }
3753
- };
3754
- var bulk_delete16 = async (props) => {
3755
- try {
3756
- const { sdk, ids } = props;
3757
- for (const id of ids) {
3758
- const existing = await local_db.fulfillments.get(id);
3759
- if (!existing) {
3760
- console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4239
+ console.warn(`Location with id ${id} not found locally, skipping`);
3761
4240
  continue;
3762
4241
  }
3763
4242
  await add_to_sync_queue({
3764
4243
  action: "delete",
3765
- table: "fulfillments",
4244
+ table: "locations",
3766
4245
  document_id: id,
3767
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3768
- stall_offline_id: existing.stall_offline_id,
4246
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3769
4247
  data: { id }
3770
4248
  });
3771
- await local_db.fulfillments.delete(id);
4249
+ await local_db.locations.delete(id);
3772
4250
  }
3773
4251
  return;
3774
4252
  } catch (error) {
3775
4253
  throw error;
3776
4254
  }
3777
4255
  };
3778
- var fulfillments = {
3779
- list: list16,
3780
- retrieve: retrieve16,
3781
- create: create16,
3782
- update: update16,
3783
- delete: _delete16,
3784
- bulk_create: bulk_create16,
3785
- bulk_update: bulk_update16,
3786
- bulk_delete: bulk_delete16
3787
- };
3788
-
3789
- // src/services/sync/sync-dependencies.ts
3790
- var SYNC_DEPENDENCY_LAYERS = {
3791
- 1: [
3792
- "tax_regions",
3793
- "tax_rates",
3794
- "categories",
3795
- "collections",
3796
- "locations",
3797
- "payment_providers",
3798
- "customers",
3799
- "promotions"
3800
- ],
3801
- 2: ["products"],
3802
- 3: ["variants", "inventory_levels"],
3803
- 4: ["orders", "order_notes"],
3804
- 5: ["payments", "refunds", "fulfillments"]
3805
- };
3806
- var get_entity_dependencies = (table) => {
3807
- const dependencies = {
3808
- // Layer 1: Independent
3809
- tax_regions: [],
3810
- tax_rates: ["tax_regions"],
3811
- categories: [],
3812
- collections: [],
3813
- locations: [],
3814
- payment_providers: [],
3815
- customers: [],
3816
- promotions: [],
3817
- // Layer 2: Product
3818
- products: ["categories", "collections"],
3819
- // Layer 3: Variants & Inventory
3820
- variants: ["products"],
3821
- inventory_levels: ["products", "variants"],
3822
- inventory_history: ["products", "variants"],
3823
- // Layer 4: Orders
3824
- orders: ["customers", "products", "variants", "locations"],
3825
- order_notes: ["orders"],
3826
- // Layer 5: Order-related
3827
- payments: ["orders", "payment_providers"],
3828
- refunds: ["orders", "payments"],
3829
- fulfillments: ["orders"],
3830
- // Tags
3831
- tags: ["products"],
3832
- // Fulfillment config
3833
- fulfillment_types: [],
3834
- fulfillment_providers: []
3835
- };
3836
- return dependencies[table] || [];
3837
- };
3838
- var get_sync_layer = (table) => {
3839
- for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
3840
- if (tables.includes(table)) {
3841
- return parseInt(layer);
3842
- }
3843
- }
3844
- return 99;
3845
- };
3846
- var sort_by_dependency_order = (items) => {
3847
- return items.sort((a, b) => {
3848
- const layer_a = get_sync_layer(a.table);
3849
- const layer_b = get_sync_layer(b.table);
3850
- if (layer_a !== layer_b) {
3851
- return layer_a - layer_b;
3852
- }
3853
- return 0;
3854
- });
3855
- };
3856
- var are_dependencies_satisfied = (table, synced_tables) => {
3857
- const dependencies = get_entity_dependencies(table);
3858
- return dependencies.every((dep) => synced_tables.has(dep));
4256
+ var locations = {
4257
+ list: list15,
4258
+ retrieve: retrieve15,
4259
+ create: create15,
4260
+ update: update15,
4261
+ delete: _delete15,
4262
+ bulk_create: bulk_create15,
4263
+ bulk_update: bulk_update15,
4264
+ bulk_delete: bulk_delete15
3859
4265
  };
3860
4266
 
3861
- // src/services/sync/sync.service.ts
3862
- var MAX_RETRIES = 3;
3863
- var replace_temporary_ids = async (props) => {
3864
- const { table, stall_offline_id, connector_id, local_data } = props;
4267
+ // src/services/fulfillments.service.ts
4268
+ var list16 = async (props) => {
3865
4269
  try {
3866
- const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
3867
- if (existing) {
3868
- await local_db[table].update(existing.id, {
3869
- id: connector_id
3870
- // Keep stall_offline_id for reference
3871
- });
4270
+ const { sdk, query } = props;
4271
+ const queue_is_empty = await is_sync_queue_empty();
4272
+ if (!queue_is_empty) {
4273
+ throw new Error(
4274
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4275
+ );
3872
4276
  }
3873
- await update_dependent_references({
3874
- table,
3875
- old_id: stall_offline_id,
3876
- new_id: connector_id
4277
+ const adapter = await sdk.adapter();
4278
+ if (!adapter) throw new Error("Adapter not found");
4279
+ const fulfillments2 = await adapter.fulfillments.list({
4280
+ connector_config: sdk.options.configuration,
4281
+ query
4282
+ });
4283
+ await save_bulk_data({
4284
+ table: "fulfillments",
4285
+ data: fulfillments2
3877
4286
  });
4287
+ return fulfillments2;
3878
4288
  } catch (error) {
3879
- console.error(`Error replacing temporary IDs for ${table}:`, error);
3880
4289
  throw error;
3881
4290
  }
3882
4291
  };
3883
- var update_dependent_references = async (props) => {
3884
- const { table, old_id, new_id } = props;
4292
+ var retrieve16 = async (props) => {
3885
4293
  try {
3886
- const reference_map = {
3887
- products: [
3888
- { table: "variants", field: "product_id" },
3889
- { table: "inventory_levels", field: "product_id" }
3890
- ],
3891
- variants: [{ table: "inventory_levels", field: "variant_id" }],
3892
- customers: [{ table: "orders", field: "customer_id" }],
3893
- orders: [
3894
- { table: "payments", field: "order_id" },
3895
- { table: "refunds", field: "order_id" },
3896
- { table: "order_notes", field: "order_id" },
3897
- { table: "fulfillments", field: "order_id" }
3898
- ],
3899
- payments: [{ table: "refunds", field: "payment_id" }],
3900
- locations: [{ table: "orders", field: "location_id" }],
3901
- categories: [{ table: "products", field: "category_id" }],
3902
- collections: [{ table: "products", field: "collection_id" }],
3903
- tax_regions: [{ table: "tax_rates", field: "region_id" }],
3904
- tax_rates: [],
3905
- tags: [],
3906
- inventory_levels: [],
3907
- inventory_history: [],
3908
- promotions: [],
3909
- order_notes: [],
3910
- refunds: [],
3911
- payment_providers: [],
3912
- fulfillments: [],
3913
- fulfillment_types: [],
3914
- fulfillment_providers: []
3915
- };
3916
- const references = reference_map[table] || [];
3917
- for (const ref of references) {
3918
- const records = await local_db[ref.table].toArray();
3919
- const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
3920
- ...record,
3921
- [ref.field]: new_id
3922
- }));
3923
- if (updates.length > 0) {
3924
- await local_db[ref.table].bulkPut(updates);
3925
- }
4294
+ const { sdk, id } = props;
4295
+ const queue_is_empty = await is_sync_queue_empty();
4296
+ if (!queue_is_empty) {
4297
+ throw new Error(
4298
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4299
+ );
3926
4300
  }
3927
- } catch (error) {
3928
- console.error(`Error updating dependent references for ${table}:`, error);
3929
- }
3930
- };
3931
- var sync_queue_item = async (props) => {
3932
- const { sdk, item, sync_batch_id } = props;
3933
- const start_time = Date.now();
3934
- try {
3935
4301
  const adapter = await sdk.adapter();
3936
- if (!adapter) {
3937
- throw new Error("Adapter not found");
3938
- }
3939
- const connector_config = sdk.options.configuration;
3940
- const table_module = adapter[item.table];
3941
- if (!table_module) {
3942
- throw new Error(`Module ${item.table} not found in adapter`);
3943
- }
3944
- let connector_id;
3945
- if (item.action === "create") {
3946
- const result = await table_module.create({
3947
- connector_config,
3948
- data: item.data
3949
- });
3950
- connector_id = result?.id;
3951
- if (connector_id) {
3952
- await replace_temporary_ids({
3953
- table: item.table,
3954
- stall_offline_id: item.stall_offline_id,
3955
- connector_id,
3956
- local_data: result
3957
- });
3958
- }
3959
- } else if (item.action === "update") {
3960
- const result = await table_module.update({
3961
- connector_config,
3962
- id: item.document_id,
3963
- data: item.data
3964
- });
3965
- connector_id = result?.id || item.document_id;
3966
- } else if (item.action === "delete") {
3967
- await table_module.delete({
3968
- connector_config,
3969
- id: item.document_id
3970
- });
3971
- connector_id = item.document_id;
3972
- }
3973
- const duration = Date.now() - start_time;
3974
- await add_sync_log({
3975
- sync_batch_id,
3976
- table: item.table,
3977
- action: item.action,
3978
- document_id: item.document_id,
3979
- stall_offline_id: item.stall_offline_id,
3980
- connector_id,
3981
- status: "success",
3982
- duration_ms: duration
3983
- });
3984
- await remove_from_sync_queue(item.id);
3985
- return { success: true, connector_id };
3986
- } catch (error) {
3987
- const duration = Date.now() - start_time;
3988
- console.error(`Error syncing item ${item.id}:`, error);
3989
- const current_retries = item.retry_count || 0;
3990
- if (current_retries < MAX_RETRIES) {
3991
- await update_sync_queue_status({
3992
- id: item.id,
3993
- status: "pending",
3994
- error: error.message,
3995
- retry_count: current_retries + 1
3996
- });
3997
- } else {
3998
- await update_sync_queue_status({
3999
- id: item.id,
4000
- status: "failed",
4001
- error: `Max retries exceeded: ${error.message}`
4002
- });
4003
- }
4004
- await add_sync_log({
4005
- sync_batch_id,
4006
- table: item.table,
4007
- action: item.action,
4008
- document_id: item.document_id,
4009
- stall_offline_id: item.stall_offline_id,
4010
- status: "failed",
4011
- error: error.message,
4012
- duration_ms: duration
4302
+ if (!adapter) throw new Error("Adapter not found");
4303
+ const fulfillment = await adapter.fulfillments.retrieve({
4304
+ connector_config: sdk.options.configuration,
4305
+ id
4013
4306
  });
4014
- return { success: false, error: error.message };
4307
+ await local_db.fulfillments.put(fulfillment);
4308
+ return fulfillment;
4309
+ } catch (error) {
4310
+ throw error;
4015
4311
  }
4016
4312
  };
4017
- var process_sync_queue = async (props) => {
4018
- const { sdk } = props;
4019
- const sync_batch_id = generate_uuid();
4313
+ var create16 = async (props) => {
4020
4314
  try {
4021
- const pending_items_by_table = await get_pending_sync_queue();
4022
- if (pending_items_by_table.size === 0) {
4023
- return {
4024
- sync_batch_id,
4025
- total: 0,
4026
- synced: 0,
4027
- failed: 0,
4028
- summary: []
4029
- };
4030
- }
4031
- let total_synced = 0;
4032
- let total_failed = 0;
4033
- const summary_data = [];
4034
- const all_items = [];
4035
- pending_items_by_table.forEach((items) => {
4036
- items.forEach((item) => {
4037
- all_items.push(item);
4038
- });
4039
- });
4040
- const sorted_items = sort_by_dependency_order(
4041
- all_items
4042
- );
4043
- const synced_tables = /* @__PURE__ */ new Set();
4044
- const items_to_retry = [];
4045
- for (const item of sorted_items) {
4046
- if (!are_dependencies_satisfied(item.table, synced_tables)) {
4047
- items_to_retry.push(item);
4048
- continue;
4049
- }
4050
- await update_sync_queue_status({
4051
- id: item.id,
4052
- status: "syncing"
4053
- });
4054
- const result = await sync_queue_item({
4055
- sdk,
4056
- item,
4057
- sync_batch_id
4058
- });
4059
- if (result.success) {
4060
- total_synced++;
4061
- if (!synced_tables.has(item.table)) {
4062
- synced_tables.add(item.table);
4063
- }
4064
- } else {
4065
- total_failed++;
4066
- }
4067
- const table_summary = summary_data.find((s) => s.table === item.table);
4068
- if (table_summary) {
4069
- if (result.success) {
4070
- table_summary.synced++;
4071
- } else {
4072
- table_summary.failed++;
4073
- }
4074
- } else {
4075
- summary_data.push({
4076
- table: item.table,
4077
- synced: result.success ? 1 : 0,
4078
- failed: result.success ? 0 : 1
4079
- });
4315
+ const { sdk, data } = props;
4316
+ const offline_id = generate_offline_id("fulfillment");
4317
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4318
+ const local_fulfillment = {
4319
+ ...data,
4320
+ id: offline_id,
4321
+ metadata: {
4322
+ ...data.metadata,
4323
+ stall_offline_id: offline_id,
4324
+ stall_offline_created_at: now,
4325
+ stall_offline_updated_at: now,
4326
+ stall_offline_deleted_at: ""
4080
4327
  }
4328
+ };
4329
+ await local_db.fulfillments.add(local_fulfillment);
4330
+ await add_to_sync_queue({
4331
+ action: "create",
4332
+ table: "fulfillments",
4333
+ document_id: offline_id,
4334
+ stall_offline_id: offline_id,
4335
+ data: local_fulfillment
4336
+ });
4337
+ return local_fulfillment;
4338
+ } catch (error) {
4339
+ throw error;
4340
+ }
4341
+ };
4342
+ var update16 = async (props) => {
4343
+ try {
4344
+ const { sdk, id, data } = props;
4345
+ const existing = await local_db.fulfillments.get(id);
4346
+ if (!existing) {
4347
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4081
4348
  }
4082
- for (const item of items_to_retry) {
4083
- await update_sync_queue_status({
4084
- id: item.id,
4085
- status: "syncing"
4086
- });
4087
- const result = await sync_queue_item({
4088
- sdk,
4089
- item,
4090
- sync_batch_id
4091
- });
4092
- if (result.success) {
4093
- total_synced++;
4094
- } else {
4095
- total_failed++;
4096
- }
4097
- const table_summary = summary_data.find((s) => s.table === item.table);
4098
- if (table_summary) {
4099
- if (result.success) {
4100
- table_summary.synced++;
4101
- } else {
4102
- table_summary.failed++;
4103
- }
4349
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4350
+ const updated_fulfillment = {
4351
+ ...existing,
4352
+ ...data,
4353
+ id: existing.id,
4354
+ metadata: {
4355
+ ...existing.metadata,
4356
+ ...data.metadata,
4357
+ stall_offline_id: existing.metadata.stall_offline_id,
4358
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4359
+ stall_offline_updated_at: now,
4360
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4104
4361
  }
4105
- }
4106
- return {
4107
- sync_batch_id,
4108
- total: all_items.length,
4109
- synced: total_synced,
4110
- failed: total_failed,
4111
- summary: summary_data
4112
4362
  };
4363
+ await local_db.fulfillments.put(updated_fulfillment);
4364
+ await add_to_sync_queue({
4365
+ action: "update",
4366
+ table: "fulfillments",
4367
+ document_id: id,
4368
+ stall_offline_id: existing.metadata.stall_offline_id,
4369
+ data: updated_fulfillment
4370
+ });
4371
+ return updated_fulfillment;
4113
4372
  } catch (error) {
4114
- console.error("Error processing sync queue:", error);
4115
- return {
4116
- sync_batch_id,
4117
- total: 0,
4118
- synced: 0,
4119
- failed: 0,
4120
- summary: []
4121
- };
4373
+ throw error;
4122
4374
  }
4123
4375
  };
4124
- var sync_interval = null;
4125
- var start_sync_service = async (props) => {
4126
- const { sdk, interval = 3e4 } = props;
4127
- if (sync_interval) {
4128
- console.warn("Sync service already running");
4376
+ var _delete16 = async (props) => {
4377
+ try {
4378
+ const { sdk, id } = props;
4379
+ const existing = await local_db.fulfillments.get(id);
4380
+ if (!existing) {
4381
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4382
+ }
4383
+ await add_to_sync_queue({
4384
+ action: "delete",
4385
+ table: "fulfillments",
4386
+ document_id: id,
4387
+ stall_offline_id: existing.metadata.stall_offline_id,
4388
+ data: { id }
4389
+ });
4390
+ await local_db.fulfillments.delete(id);
4129
4391
  return;
4392
+ } catch (error) {
4393
+ throw error;
4130
4394
  }
4131
- console.log(`Starting offline sync service with ${interval}ms interval`);
4132
- await process_sync_queue({ sdk });
4133
- sync_interval = setInterval(async () => {
4134
- const result = await process_sync_queue({ sdk });
4135
- if (result.total > 0) {
4136
- console.log(
4137
- `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
4138
- );
4139
- result.summary.forEach((s) => {
4140
- console.log(` ${s.table}: ${s.synced} synced, ${s.failed} failed`);
4395
+ };
4396
+ var bulk_create16 = async (props) => {
4397
+ try {
4398
+ const { sdk, data } = props;
4399
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4400
+ const created_fulfillments = [];
4401
+ for (const fulfillment of data) {
4402
+ const offline_id = generate_offline_id("fulfillment");
4403
+ const local_fulfillment = {
4404
+ ...fulfillment,
4405
+ id: offline_id,
4406
+ metadata: {
4407
+ ...fulfillment.metadata,
4408
+ stall_offline_id: offline_id,
4409
+ stall_offline_created_at: now,
4410
+ stall_offline_updated_at: now,
4411
+ stall_offline_deleted_at: ""
4412
+ }
4413
+ };
4414
+ await local_db.fulfillments.add(local_fulfillment);
4415
+ await add_to_sync_queue({
4416
+ action: "create",
4417
+ table: "fulfillments",
4418
+ document_id: offline_id,
4419
+ stall_offline_id: offline_id,
4420
+ data: local_fulfillment
4141
4421
  });
4422
+ created_fulfillments.push(local_fulfillment);
4142
4423
  }
4143
- }, interval);
4144
- };
4145
- var stop_sync_service = () => {
4146
- if (sync_interval) {
4147
- clearInterval(sync_interval);
4148
- sync_interval = null;
4149
- console.log("Offline sync service stopped");
4424
+ return created_fulfillments;
4425
+ } catch (error) {
4426
+ throw error;
4150
4427
  }
4151
4428
  };
4152
- var get_sync_stats = async () => {
4429
+ var bulk_update16 = async (props) => {
4153
4430
  try {
4154
- const all_items = await local_db.sync_queue.toArray();
4155
- const pending = all_items.filter((i) => i.status === "pending").length;
4156
- const syncing = all_items.filter((i) => i.status === "syncing").length;
4157
- const failed = all_items.filter((i) => i.status === "failed").length;
4158
- return {
4159
- pending,
4160
- syncing,
4161
- failed,
4162
- total: all_items.length
4163
- };
4431
+ const { sdk, data } = props;
4432
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4433
+ const updated_fulfillments = [];
4434
+ for (const item of data) {
4435
+ const existing = await local_db.fulfillments.get(item.id);
4436
+ if (!existing) {
4437
+ console.warn(
4438
+ `Fulfillment with id ${item.id} not found locally, skipping`
4439
+ );
4440
+ continue;
4441
+ }
4442
+ const updated_fulfillment = {
4443
+ ...existing,
4444
+ ...item.data,
4445
+ id: existing.id,
4446
+ metadata: {
4447
+ ...existing.metadata,
4448
+ ...item.data.metadata,
4449
+ stall_offline_id: existing.metadata.stall_offline_id,
4450
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4451
+ stall_offline_updated_at: now,
4452
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4453
+ }
4454
+ };
4455
+ await local_db.fulfillments.put(updated_fulfillment);
4456
+ await add_to_sync_queue({
4457
+ action: "update",
4458
+ table: "fulfillments",
4459
+ document_id: item.id,
4460
+ stall_offline_id: existing.metadata.stall_offline_id,
4461
+ data: updated_fulfillment
4462
+ });
4463
+ updated_fulfillments.push(updated_fulfillment);
4464
+ }
4465
+ return updated_fulfillments;
4164
4466
  } catch (error) {
4165
- console.error("Error getting sync stats:", error);
4166
- return { pending: 0, syncing: 0, failed: 0, total: 0 };
4467
+ throw error;
4167
4468
  }
4168
4469
  };
4169
- var trigger_sync = async (props) => {
4470
+ var bulk_delete16 = async (props) => {
4170
4471
  try {
4171
- const { sdk } = props;
4172
- return await process_sync_queue({ sdk });
4472
+ const { sdk, ids } = props;
4473
+ for (const id of ids) {
4474
+ const existing = await local_db.fulfillments.get(id);
4475
+ if (!existing) {
4476
+ console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4477
+ continue;
4478
+ }
4479
+ await add_to_sync_queue({
4480
+ action: "delete",
4481
+ table: "fulfillments",
4482
+ document_id: id,
4483
+ stall_offline_id: existing.metadata.stall_offline_id,
4484
+ data: { id }
4485
+ });
4486
+ await local_db.fulfillments.delete(id);
4487
+ }
4488
+ return;
4173
4489
  } catch (error) {
4174
- console.error("Error triggering sync:", error);
4175
- return {
4176
- sync_batch_id: generate_uuid(),
4177
- total: 0,
4178
- synced: 0,
4179
- failed: 0,
4180
- summary: []
4181
- };
4490
+ throw error;
4182
4491
  }
4183
4492
  };
4184
- var sync_service = {
4185
- process_sync_queue,
4186
- sync_queue_item,
4187
- start_sync_service,
4188
- stop_sync_service,
4189
- get_sync_stats,
4190
- trigger_sync
4493
+ var fulfillments = {
4494
+ list: list16,
4495
+ retrieve: retrieve16,
4496
+ create: create16,
4497
+ update: update16,
4498
+ delete: _delete16,
4499
+ bulk_create: bulk_create16,
4500
+ bulk_update: bulk_update16,
4501
+ bulk_delete: bulk_delete16
4191
4502
  };
4192
4503
  // Annotate the CommonJS export names for ESM import in node:
4193
4504
  0 && (module.exports = {
@@ -4204,6 +4515,9 @@ var sync_service = {
4204
4515
  get_sync_logs_by_batch,
4205
4516
  initializeStallCore,
4206
4517
  inventory_levels,
4518
+ is_offline,
4519
+ is_online,
4520
+ is_sync_queue_empty,
4207
4521
  local_db,
4208
4522
  locations,
4209
4523
  order_notes,