@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.mjs CHANGED
@@ -30,45 +30,6 @@ var options = { allowEmptyDB: true };
30
30
  var local_db = new Dexie("stall-core-db", options);
31
31
  local_db.version(1).stores(schemas);
32
32
 
33
- // src/core/init.ts
34
- var initializeStallCore = (options2) => {
35
- const sdk = {
36
- options: options2,
37
- adapter: async () => getAdapter(sdk),
38
- refreshAdapter: async () => getAdapter(sdk, true)
39
- };
40
- void sdk.adapter();
41
- return sdk;
42
- };
43
- var getAdapter = async (sdk, force) => {
44
- const date = Date.now();
45
- let module_code;
46
- const cache_key = "connector-module";
47
- const cached = await local_db.connector_cache.get(cache_key);
48
- if (cached && !force) {
49
- module_code = cached.code;
50
- } else {
51
- const response = await fetch(sdk.options.connector_url, {
52
- mode: "cors",
53
- method: "GET"
54
- });
55
- if (!response.ok) {
56
- throw new Error(`Failed to fetch connector: ${response.statusText}`);
57
- }
58
- module_code = await response.text();
59
- await local_db.connector_cache.put({
60
- id: cache_key,
61
- code: module_code,
62
- timestamp: date
63
- });
64
- }
65
- const blob = new Blob([module_code], { type: "application/javascript" });
66
- const blobUrl = URL.createObjectURL(blob);
67
- const module = await import(blobUrl);
68
- URL.revokeObjectURL(blobUrl);
69
- return module;
70
- };
71
-
72
33
  // src/lib/utils.ts
73
34
  var generate_uuid = () => {
74
35
  return "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
@@ -77,6 +38,15 @@ var generate_uuid = () => {
77
38
  return v.toString(16);
78
39
  });
79
40
  };
41
+ var is_online = () => {
42
+ if (typeof navigator !== "undefined" && typeof navigator.onLine === "boolean") {
43
+ return navigator.onLine;
44
+ }
45
+ return true;
46
+ };
47
+ var is_offline = () => {
48
+ return !is_online();
49
+ };
80
50
 
81
51
  // src/db/helpers.ts
82
52
  var generate_offline_id = (table) => {
@@ -188,117 +158,606 @@ var get_recent_sync_logs = async (props) => {
188
158
  }
189
159
  return logs;
190
160
  };
161
+ var is_sync_queue_empty = async () => {
162
+ try {
163
+ const pending_items = await local_db.sync_queue.where("status").equals("pending").toArray();
164
+ return pending_items.length === 0;
165
+ } catch (error) {
166
+ console.error("Error checking sync queue status:", error);
167
+ return false;
168
+ }
169
+ };
191
170
  var cleanup_old_sync_logs = async (days = 30) => {
192
171
  const cutoff_time = Date.now() - days * 24 * 60 * 60 * 1e3;
193
172
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
194
173
  };
195
174
 
196
- // src/services/products.service.ts
197
- var list = async (props) => {
198
- try {
199
- const { sdk, query } = props;
200
- const adapter = await sdk.adapter();
201
- if (!adapter) throw new Error("Adapter not found");
202
- const products2 = await adapter.products.list({
203
- connector_config: sdk.options.configuration,
204
- query
205
- });
206
- await save_bulk_data({
207
- table: "products",
208
- data: products2
209
- });
210
- return products2;
211
- } catch (error) {
212
- throw error;
213
- }
175
+ // src/services/sync/sync-dependencies.ts
176
+ var SYNC_DEPENDENCY_LAYERS = {
177
+ 1: [
178
+ "tax_regions",
179
+ "tax_rates",
180
+ "categories",
181
+ "collections",
182
+ "locations",
183
+ "payment_providers",
184
+ "customers",
185
+ "promotions"
186
+ ],
187
+ 2: ["products"],
188
+ 3: ["variants", "inventory_levels"],
189
+ 4: ["orders", "order_notes"],
190
+ 5: ["payments", "refunds", "fulfillments"]
214
191
  };
215
- var retrieve = async (props) => {
216
- try {
217
- const { sdk, id } = props;
218
- const adapter = await sdk.adapter();
219
- if (!adapter) throw new Error("Adapter not found");
220
- const product = await adapter.products.retrieve({
221
- connector_config: sdk.options.configuration,
222
- id
223
- });
224
- await local_db.products.put(product);
225
- return product;
226
- } catch (error) {
227
- throw error;
192
+ var get_entity_dependencies = (table) => {
193
+ const dependencies = {
194
+ // Layer 1: Independent
195
+ tax_regions: [],
196
+ tax_rates: ["tax_regions"],
197
+ categories: [],
198
+ collections: [],
199
+ locations: [],
200
+ payment_providers: [],
201
+ customers: [],
202
+ promotions: [],
203
+ // Layer 2: Product
204
+ products: ["categories", "collections"],
205
+ // Layer 3: Variants & Inventory
206
+ variants: ["products"],
207
+ inventory_levels: ["products", "variants"],
208
+ inventory_history: ["products", "variants"],
209
+ // Layer 4: Orders
210
+ orders: ["customers", "products", "variants", "locations"],
211
+ order_notes: ["orders"],
212
+ // Layer 5: Order-related
213
+ payments: ["orders", "payment_providers"],
214
+ refunds: ["orders", "payments"],
215
+ fulfillments: ["orders"],
216
+ // Tags
217
+ tags: ["products"],
218
+ // Fulfillment config
219
+ fulfillment_types: [],
220
+ fulfillment_providers: []
221
+ };
222
+ return dependencies[table] || [];
223
+ };
224
+ var get_sync_layer = (table) => {
225
+ for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
226
+ if (tables.includes(table)) {
227
+ return parseInt(layer);
228
+ }
228
229
  }
230
+ return 99;
229
231
  };
230
- var create = async (props) => {
232
+ var sort_by_dependency_order = (items) => {
233
+ return items.sort((a, b) => {
234
+ const layer_a = get_sync_layer(a.table);
235
+ const layer_b = get_sync_layer(b.table);
236
+ if (layer_a !== layer_b) {
237
+ return layer_a - layer_b;
238
+ }
239
+ return 0;
240
+ });
241
+ };
242
+ var are_dependencies_satisfied = (table, synced_tables) => {
243
+ const dependencies = get_entity_dependencies(table);
244
+ return dependencies.every((dep) => synced_tables.has(dep));
245
+ };
246
+
247
+ // src/services/sync/sync.service.ts
248
+ var MAX_RETRIES = 3;
249
+ var SYNC_INTERVAL_MS = 2 * 60 * 1e3;
250
+ var sync_interval = null;
251
+ var is_syncing = false;
252
+ var replace_temporary_ids = async (props) => {
253
+ const { table, stall_offline_id, connector_id } = props;
231
254
  try {
232
- const { sdk, data } = props;
233
- const offline_id = generate_offline_id("product");
234
- const now = (/* @__PURE__ */ new Date()).toISOString();
235
- const local_product = {
236
- ...data,
237
- id: offline_id,
238
- metadata: {
239
- ...data.metadata,
240
- stall_offline_id: offline_id
241
- },
242
- stall_offline_id: offline_id,
243
- stall_offline_created_at: now,
244
- stall_offline_updated_at: now
245
- };
246
- await local_db.products.add(local_product);
247
- await add_to_sync_queue({
248
- action: "create",
249
- table: "products",
250
- document_id: offline_id,
251
- stall_offline_id: offline_id,
252
- data: local_product
255
+ const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
256
+ if (existing) {
257
+ await local_db[table].update(existing.id, {
258
+ id: connector_id
259
+ });
260
+ }
261
+ await update_dependent_references({
262
+ table,
263
+ old_id: stall_offline_id,
264
+ new_id: connector_id
253
265
  });
254
- return local_product;
255
266
  } catch (error) {
267
+ console.error(`Error replacing temporary IDs for ${table}:`, error);
256
268
  throw error;
257
269
  }
258
270
  };
259
- var update = async (props) => {
271
+ var update_dependent_references = async (props) => {
272
+ const { table, old_id, new_id } = props;
260
273
  try {
261
- const { sdk, id, data } = props;
262
- const existing = await local_db.products.get(id);
263
- if (!existing) {
264
- throw new Error(`Product with id ${id} not found locally`);
265
- }
266
- const now = (/* @__PURE__ */ new Date()).toISOString();
267
- const updated_product = {
268
- ...existing,
269
- ...data,
270
- id: existing.id,
271
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
- stall_offline_id: existing.stall_offline_id,
273
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
- stall_offline_updated_at: now
274
+ const reference_map = {
275
+ products: [
276
+ { table: "variants", field: "product_id" },
277
+ { table: "inventory_levels", field: "product_id" }
278
+ ],
279
+ variants: [{ table: "inventory_levels", field: "variant_id" }],
280
+ customers: [{ table: "orders", field: "customer_id" }],
281
+ orders: [
282
+ { table: "payments", field: "order_id" },
283
+ { table: "refunds", field: "order_id" },
284
+ { table: "order_notes", field: "order_id" },
285
+ { table: "fulfillments", field: "order_id" }
286
+ ],
287
+ payments: [{ table: "refunds", field: "payment_id" }],
288
+ locations: [{ table: "orders", field: "location_id" }],
289
+ categories: [{ table: "products", field: "category_id" }],
290
+ collections: [{ table: "products", field: "collection_id" }],
291
+ tax_regions: [{ table: "tax_rates", field: "region_id" }],
292
+ tax_rates: [],
293
+ tags: [],
294
+ inventory_levels: [],
295
+ inventory_history: [],
296
+ promotions: [],
297
+ order_notes: [],
298
+ refunds: [],
299
+ payment_providers: [],
300
+ fulfillments: [],
301
+ fulfillment_types: [],
302
+ fulfillment_providers: []
275
303
  };
276
- await local_db.products.put(updated_product);
277
- await add_to_sync_queue({
278
- action: "update",
279
- table: "products",
280
- document_id: id,
281
- stall_offline_id: existing.stall_offline_id,
282
- data: updated_product
283
- });
284
- return updated_product;
304
+ const references = reference_map[table] || [];
305
+ for (const ref of references) {
306
+ const records = await local_db[ref.table].toArray();
307
+ const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
308
+ ...record,
309
+ [ref.field]: new_id
310
+ }));
311
+ if (updates.length > 0) {
312
+ await local_db[ref.table].bulkPut(updates);
313
+ }
314
+ }
285
315
  } catch (error) {
286
- throw error;
316
+ console.error(`Error updating dependent references for ${table}:`, error);
287
317
  }
288
318
  };
289
- var _delete = async (props) => {
319
+ var sync_queue_item = async (props) => {
320
+ const { sdk, item, sync_batch_id } = props;
321
+ const start_time = Date.now();
290
322
  try {
291
- const { sdk, id } = props;
292
- const existing = await local_db.products.get(id);
293
- if (!existing) {
294
- throw new Error(`Product with id ${id} not found locally`);
323
+ const adapter = await sdk.adapter();
324
+ if (!adapter) {
325
+ throw new Error("Adapter not found");
295
326
  }
296
- await add_to_sync_queue({
297
- action: "delete",
327
+ const connector_config = sdk.options.configuration;
328
+ const table_module = adapter[item.table];
329
+ if (!table_module) {
330
+ throw new Error(`Module ${item.table} not found in adapter`);
331
+ }
332
+ let connector_id;
333
+ if (item.action === "create") {
334
+ const result = await table_module.create({
335
+ connector_config,
336
+ data: item.data
337
+ });
338
+ connector_id = result?.id;
339
+ if (connector_id) {
340
+ await replace_temporary_ids({
341
+ table: item.table,
342
+ stall_offline_id: item.stall_offline_id,
343
+ connector_id
344
+ });
345
+ }
346
+ } else if (item.action === "update") {
347
+ const result = await table_module.update({
348
+ connector_config,
349
+ id: item.document_id,
350
+ data: item.data
351
+ });
352
+ connector_id = result?.id || item.document_id;
353
+ } else if (item.action === "delete") {
354
+ await table_module.delete({
355
+ connector_config,
356
+ id: item.document_id
357
+ });
358
+ connector_id = item.document_id;
359
+ }
360
+ const duration = Date.now() - start_time;
361
+ await add_sync_log({
362
+ sync_batch_id,
363
+ table: item.table,
364
+ action: item.action,
365
+ document_id: item.document_id,
366
+ stall_offline_id: item.stall_offline_id,
367
+ connector_id,
368
+ status: "success",
369
+ duration_ms: duration
370
+ });
371
+ await remove_from_sync_queue(item.id);
372
+ return { success: true, connector_id };
373
+ } catch (error) {
374
+ const duration = Date.now() - start_time;
375
+ console.error(`Error syncing item ${item.id}:`, error);
376
+ const current_retries = item.retry_count || 0;
377
+ if (current_retries < MAX_RETRIES) {
378
+ await update_sync_queue_status({
379
+ id: item.id,
380
+ status: "pending",
381
+ error: error.message,
382
+ retry_count: current_retries + 1
383
+ });
384
+ } else {
385
+ await update_sync_queue_status({
386
+ id: item.id,
387
+ status: "failed",
388
+ error: `Max retries exceeded: ${error.message}`
389
+ });
390
+ }
391
+ await add_sync_log({
392
+ sync_batch_id,
393
+ table: item.table,
394
+ action: item.action,
395
+ document_id: item.document_id,
396
+ stall_offline_id: item.stall_offline_id,
397
+ status: "failed",
398
+ error: error.message,
399
+ duration_ms: duration
400
+ });
401
+ return { success: false, error: error.message };
402
+ }
403
+ };
404
+ var process_sync_queue = async (props) => {
405
+ const { sdk } = props;
406
+ const sync_batch_id = generate_uuid();
407
+ if (is_syncing) {
408
+ console.log("Sync already in progress, skipping...");
409
+ return {
410
+ sync_batch_id,
411
+ total: 0,
412
+ synced: 0,
413
+ failed: 0
414
+ };
415
+ }
416
+ is_syncing = true;
417
+ try {
418
+ const pending_items_by_table = await get_pending_sync_queue();
419
+ if (pending_items_by_table.size === 0) {
420
+ return {
421
+ sync_batch_id,
422
+ total: 0,
423
+ synced: 0,
424
+ failed: 0
425
+ };
426
+ }
427
+ let total_synced = 0;
428
+ let total_failed = 0;
429
+ const all_items = [];
430
+ pending_items_by_table.forEach((items) => {
431
+ items.forEach((item) => {
432
+ all_items.push(item);
433
+ });
434
+ });
435
+ const sorted_items = sort_by_dependency_order(
436
+ all_items
437
+ );
438
+ const synced_tables = /* @__PURE__ */ new Set();
439
+ const items_to_retry = [];
440
+ for (const item of sorted_items) {
441
+ if (!are_dependencies_satisfied(item.table, synced_tables)) {
442
+ items_to_retry.push(item);
443
+ continue;
444
+ }
445
+ await update_sync_queue_status({
446
+ id: item.id,
447
+ status: "syncing"
448
+ });
449
+ const result = await sync_queue_item({
450
+ sdk,
451
+ item,
452
+ sync_batch_id
453
+ });
454
+ if (result.success) {
455
+ total_synced++;
456
+ if (!synced_tables.has(item.table)) {
457
+ synced_tables.add(item.table);
458
+ }
459
+ } else {
460
+ total_failed++;
461
+ }
462
+ }
463
+ for (const item of items_to_retry) {
464
+ await update_sync_queue_status({
465
+ id: item.id,
466
+ status: "syncing"
467
+ });
468
+ const result = await sync_queue_item({
469
+ sdk,
470
+ item,
471
+ sync_batch_id
472
+ });
473
+ if (result.success) {
474
+ total_synced++;
475
+ } else {
476
+ total_failed++;
477
+ }
478
+ }
479
+ return {
480
+ sync_batch_id,
481
+ total: all_items.length,
482
+ synced: total_synced,
483
+ failed: total_failed
484
+ };
485
+ } catch (error) {
486
+ console.error("Error processing sync queue:", error);
487
+ return {
488
+ sync_batch_id,
489
+ total: 0,
490
+ synced: 0,
491
+ failed: 0
492
+ };
493
+ } finally {
494
+ is_syncing = false;
495
+ }
496
+ };
497
+ var get_sync_status = async () => {
498
+ try {
499
+ const all_items = await local_db.sync_queue.toArray();
500
+ const pending = all_items.filter((i) => i.status === "pending").length;
501
+ const syncing = all_items.filter((i) => i.status === "syncing").length;
502
+ const failed = all_items.filter((i) => i.status === "failed").length;
503
+ return {
504
+ pending,
505
+ syncing,
506
+ failed,
507
+ total: all_items.length,
508
+ is_sync_running: sync_interval !== null
509
+ };
510
+ } catch (error) {
511
+ console.error("Error getting sync status:", error);
512
+ return {
513
+ pending: 0,
514
+ syncing: 0,
515
+ failed: 0,
516
+ total: 0,
517
+ is_sync_running: false
518
+ };
519
+ }
520
+ };
521
+ var fix_sync_queue = async () => {
522
+ try {
523
+ const stuck_items = await local_db.sync_queue.where("status").equals("syncing").toArray();
524
+ for (const item of stuck_items) {
525
+ await update_sync_queue_status({
526
+ id: item.id,
527
+ status: "pending"
528
+ });
529
+ }
530
+ console.log(`Fixed ${stuck_items.length} stuck sync queue items`);
531
+ return {
532
+ fixed: stuck_items.length
533
+ };
534
+ } catch (error) {
535
+ console.error("Error fixing sync queue:", error);
536
+ return {
537
+ fixed: 0
538
+ };
539
+ }
540
+ };
541
+ var trigger_sync = async (props) => {
542
+ try {
543
+ const { sdk } = props;
544
+ return await process_sync_queue({ sdk });
545
+ } catch (error) {
546
+ console.error("Error triggering sync:", error);
547
+ return {
548
+ sync_batch_id: generate_uuid(),
549
+ total: 0,
550
+ synced: 0,
551
+ failed: 0
552
+ };
553
+ }
554
+ };
555
+ var start_sync = async (props) => {
556
+ const { sdk } = props;
557
+ if (sync_interval) {
558
+ console.warn("Background sync already running");
559
+ return;
560
+ }
561
+ console.log(
562
+ `Starting background sync service (${SYNC_INTERVAL_MS}ms interval)`
563
+ );
564
+ const initial_result = await process_sync_queue({ sdk });
565
+ if (initial_result.total > 0) {
566
+ console.log(
567
+ `Initial sync: ${initial_result.synced} synced, ${initial_result.failed} failed out of ${initial_result.total}`
568
+ );
569
+ }
570
+ sync_interval = setInterval(async () => {
571
+ const status = await get_sync_status();
572
+ if (status.pending > 0) {
573
+ const result = await process_sync_queue({ sdk });
574
+ if (result.total > 0) {
575
+ console.log(
576
+ `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
577
+ );
578
+ }
579
+ }
580
+ }, SYNC_INTERVAL_MS);
581
+ };
582
+ var stop_sync = () => {
583
+ if (sync_interval) {
584
+ clearInterval(sync_interval);
585
+ sync_interval = null;
586
+ console.log("Background sync service stopped");
587
+ } else {
588
+ console.warn("Background sync is not running");
589
+ }
590
+ };
591
+ var sync_service = {
592
+ get_sync_status,
593
+ fix_sync_queue,
594
+ trigger_sync,
595
+ start_sync,
596
+ stop_sync
597
+ };
598
+
599
+ // src/core/init.ts
600
+ var initializeStallCore = (options2) => {
601
+ const sdk = {
602
+ options: options2,
603
+ adapter: async () => getAdapter(sdk),
604
+ refreshAdapter: async () => getAdapter(sdk, true)
605
+ };
606
+ void sdk.adapter().then(() => {
607
+ void sync_service.start_sync({ sdk });
608
+ });
609
+ return sdk;
610
+ };
611
+ var getAdapter = async (sdk, force) => {
612
+ const date = Date.now();
613
+ let module_code;
614
+ const cache_key = "connector-module";
615
+ const cached = await local_db.connector_cache.get(cache_key);
616
+ if (cached && !force) {
617
+ module_code = cached.code;
618
+ } else {
619
+ const response = await fetch(sdk.options.connector_url, {
620
+ mode: "cors",
621
+ method: "GET"
622
+ });
623
+ if (!response.ok) {
624
+ throw new Error(`Failed to fetch connector: ${response.statusText}`);
625
+ }
626
+ module_code = await response.text();
627
+ await local_db.connector_cache.put({
628
+ id: cache_key,
629
+ code: module_code,
630
+ timestamp: date
631
+ });
632
+ }
633
+ const blob = new Blob([module_code], { type: "application/javascript" });
634
+ const blobUrl = URL.createObjectURL(blob);
635
+ const module = await import(blobUrl);
636
+ URL.revokeObjectURL(blobUrl);
637
+ return module;
638
+ };
639
+
640
+ // src/services/products.service.ts
641
+ var list = async (props) => {
642
+ try {
643
+ const { sdk, query } = props;
644
+ const queue_is_empty = await is_sync_queue_empty();
645
+ if (!queue_is_empty) {
646
+ throw new Error(
647
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
648
+ );
649
+ }
650
+ const adapter = await sdk.adapter();
651
+ if (!adapter) throw new Error("Adapter not found");
652
+ const products2 = await adapter.products.list({
653
+ connector_config: sdk.options.configuration,
654
+ query
655
+ });
656
+ await save_bulk_data({
657
+ table: "products",
658
+ data: products2
659
+ });
660
+ return products2;
661
+ } catch (error) {
662
+ throw error;
663
+ }
664
+ };
665
+ var retrieve = async (props) => {
666
+ try {
667
+ const { sdk, id } = props;
668
+ const queue_is_empty = await is_sync_queue_empty();
669
+ if (!queue_is_empty) {
670
+ throw new Error(
671
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
672
+ );
673
+ }
674
+ const adapter = await sdk.adapter();
675
+ if (!adapter) throw new Error("Adapter not found");
676
+ const product = await adapter.products.retrieve({
677
+ connector_config: sdk.options.configuration,
678
+ id
679
+ });
680
+ await local_db.products.put(product);
681
+ return product;
682
+ } catch (error) {
683
+ throw error;
684
+ }
685
+ };
686
+ var create = async (props) => {
687
+ try {
688
+ const { sdk, data } = props;
689
+ const offline_id = generate_offline_id("product");
690
+ const now = (/* @__PURE__ */ new Date()).toISOString();
691
+ const local_product = {
692
+ ...data,
693
+ id: offline_id,
694
+ metadata: {
695
+ ...data.metadata,
696
+ stall_offline_id: offline_id,
697
+ stall_offline_created_at: now,
698
+ stall_offline_updated_at: now,
699
+ stall_offline_deleted_at: ""
700
+ }
701
+ };
702
+ await local_db.products.add(local_product);
703
+ await add_to_sync_queue({
704
+ action: "create",
705
+ table: "products",
706
+ document_id: offline_id,
707
+ stall_offline_id: offline_id,
708
+ data: local_product
709
+ });
710
+ return local_product;
711
+ } catch (error) {
712
+ throw error;
713
+ }
714
+ };
715
+ var update = async (props) => {
716
+ try {
717
+ const { sdk, id, data } = props;
718
+ const existing = await local_db.products.get(id);
719
+ if (!existing) {
720
+ throw new Error(`Product with id ${id} not found locally`);
721
+ }
722
+ const now = (/* @__PURE__ */ new Date()).toISOString();
723
+ const updated_product = {
724
+ ...existing,
725
+ ...data,
726
+ id: existing.id,
727
+ metadata: {
728
+ ...existing.metadata,
729
+ ...data.metadata,
730
+ stall_offline_id: existing.metadata.stall_offline_id,
731
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
732
+ stall_offline_updated_at: now,
733
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
734
+ }
735
+ };
736
+ await local_db.products.put(updated_product);
737
+ await add_to_sync_queue({
738
+ action: "update",
739
+ table: "products",
740
+ document_id: id,
741
+ stall_offline_id: existing.metadata.stall_offline_id,
742
+ data: updated_product
743
+ });
744
+ return updated_product;
745
+ } catch (error) {
746
+ throw error;
747
+ }
748
+ };
749
+ var _delete = async (props) => {
750
+ try {
751
+ const { sdk, id } = props;
752
+ const existing = await local_db.products.get(id);
753
+ if (!existing) {
754
+ throw new Error(`Product with id ${id} not found locally`);
755
+ }
756
+ await add_to_sync_queue({
757
+ action: "delete",
298
758
  table: "products",
299
759
  document_id: id,
300
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
301
- stall_offline_id: existing.stall_offline_id,
760
+ stall_offline_id: existing.metadata.stall_offline_id,
302
761
  data: { id }
303
762
  });
304
763
  await local_db.products.delete(id);
@@ -319,11 +778,11 @@ var bulk_create = async (props) => {
319
778
  id: offline_id,
320
779
  metadata: {
321
780
  ...product.metadata,
322
- stall_offline_id: offline_id
323
- },
324
- stall_offline_id: offline_id,
325
- stall_offline_created_at: now,
326
- stall_offline_updated_at: now
781
+ stall_offline_id: offline_id,
782
+ stall_offline_created_at: now,
783
+ stall_offline_updated_at: now,
784
+ stall_offline_deleted_at: ""
785
+ }
327
786
  };
328
787
  await local_db.products.add(local_product);
329
788
  await add_to_sync_queue({
@@ -355,17 +814,21 @@ var bulk_update = async (props) => {
355
814
  ...existing,
356
815
  ...item.data,
357
816
  id: existing.id,
358
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
359
- stall_offline_id: existing.stall_offline_id,
360
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
361
- stall_offline_updated_at: now
817
+ metadata: {
818
+ ...existing.metadata,
819
+ ...item.data.metadata,
820
+ stall_offline_id: existing.metadata.stall_offline_id,
821
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
822
+ stall_offline_updated_at: now,
823
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
824
+ }
362
825
  };
363
826
  await local_db.products.put(updated_product);
364
827
  await add_to_sync_queue({
365
828
  action: "update",
366
829
  table: "products",
367
830
  document_id: item.id,
368
- stall_offline_id: existing.stall_offline_id,
831
+ stall_offline_id: existing.metadata.stall_offline_id,
369
832
  data: updated_product
370
833
  });
371
834
  updated_products.push(updated_product);
@@ -388,8 +851,7 @@ var bulk_delete = async (props) => {
388
851
  action: "delete",
389
852
  table: "products",
390
853
  document_id: id,
391
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
- stall_offline_id: existing.stall_offline_id,
854
+ stall_offline_id: existing.metadata.stall_offline_id,
393
855
  data: { id }
394
856
  });
395
857
  await local_db.products.delete(id);
@@ -414,6 +876,12 @@ var products = {
414
876
  var list2 = async (props) => {
415
877
  try {
416
878
  const { sdk, query } = props;
879
+ const queue_is_empty = await is_sync_queue_empty();
880
+ if (!queue_is_empty) {
881
+ throw new Error(
882
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
883
+ );
884
+ }
417
885
  const adapter = await sdk.adapter();
418
886
  if (!adapter) throw new Error("Adapter not found");
419
887
  const orders2 = await adapter.orders.list({
@@ -434,6 +902,12 @@ var list2 = async (props) => {
434
902
  var retrieve2 = async (props) => {
435
903
  try {
436
904
  const { sdk, id } = props;
905
+ const queue_is_empty = await is_sync_queue_empty();
906
+ if (!queue_is_empty) {
907
+ throw new Error(
908
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
909
+ );
910
+ }
437
911
  const adapter = await sdk.adapter();
438
912
  if (!adapter) throw new Error("Adapter not found");
439
913
  const order = await adapter.orders.retrieve({
@@ -458,11 +932,11 @@ var create2 = async (props) => {
458
932
  id: offline_id,
459
933
  metadata: {
460
934
  ...data.metadata,
461
- stall_offline_id: offline_id
462
- },
463
- stall_offline_id: offline_id,
464
- stall_offline_created_at: now,
465
- stall_offline_updated_at: now
935
+ stall_offline_id: offline_id,
936
+ stall_offline_created_at: now,
937
+ stall_offline_updated_at: now,
938
+ stall_offline_deleted_at: ""
939
+ }
466
940
  };
467
941
  await local_db.orders.add(local_order);
468
942
  await add_to_sync_queue({
@@ -491,17 +965,21 @@ var update2 = async (props) => {
491
965
  ...existing,
492
966
  ...data,
493
967
  id: existing.id,
494
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
495
- stall_offline_id: existing.stall_offline_id,
496
- stall_offline_updated_at: now
968
+ metadata: {
969
+ ...existing.metadata,
970
+ ...data.metadata,
971
+ stall_offline_id: existing.metadata.stall_offline_id,
972
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
973
+ stall_offline_updated_at: now,
974
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
975
+ }
497
976
  };
498
977
  await local_db.orders.put(updated_order);
499
978
  await add_to_sync_queue({
500
979
  action: "update",
501
980
  table: "orders",
502
981
  document_id: id,
503
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
504
- stall_offline_id: existing.stall_offline_id,
982
+ stall_offline_id: existing.metadata.stall_offline_id,
505
983
  data: updated_order
506
984
  });
507
985
  return updated_order;
@@ -522,8 +1000,7 @@ var _delete2 = async (props) => {
522
1000
  action: "delete",
523
1001
  table: "orders",
524
1002
  document_id: id,
525
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
526
- stall_offline_id: existing.stall_offline_id,
1003
+ stall_offline_id: existing.metadata.stall_offline_id,
527
1004
  data: { id }
528
1005
  });
529
1006
  await local_db.orders.delete(id);
@@ -546,11 +1023,11 @@ var bulk_create2 = async (props) => {
546
1023
  id: offline_id,
547
1024
  metadata: {
548
1025
  ...order.metadata,
549
- stall_offline_id: offline_id
550
- },
551
- stall_offline_id: offline_id,
552
- stall_offline_created_at: now,
553
- stall_offline_updated_at: now
1026
+ stall_offline_id: offline_id,
1027
+ stall_offline_created_at: now,
1028
+ stall_offline_updated_at: now,
1029
+ stall_offline_deleted_at: ""
1030
+ }
554
1031
  };
555
1032
  await local_db.orders.add(local_order);
556
1033
  await add_to_sync_queue({
@@ -584,17 +1061,21 @@ var bulk_update2 = async (props) => {
584
1061
  ...existing,
585
1062
  ...item.data,
586
1063
  id: existing.id,
587
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
588
- stall_offline_id: existing.stall_offline_id,
589
- stall_offline_updated_at: now
1064
+ metadata: {
1065
+ ...existing.metadata,
1066
+ ...item.data.metadata,
1067
+ stall_offline_id: existing.metadata.stall_offline_id,
1068
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1069
+ stall_offline_updated_at: now,
1070
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1071
+ }
590
1072
  };
591
1073
  await local_db.orders.put(updated_order);
592
1074
  await add_to_sync_queue({
593
1075
  action: "update",
594
1076
  table: "orders",
595
1077
  document_id: item.id,
596
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
597
- stall_offline_id: existing.stall_offline_id,
1078
+ stall_offline_id: existing.metadata.stall_offline_id,
598
1079
  data: updated_order
599
1080
  });
600
1081
  updated_orders.push(updated_order);
@@ -619,8 +1100,7 @@ var bulk_delete2 = async (props) => {
619
1100
  action: "delete",
620
1101
  table: "orders",
621
1102
  document_id: id,
622
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
623
- stall_offline_id: existing.stall_offline_id,
1103
+ stall_offline_id: existing.metadata.stall_offline_id,
624
1104
  data: { id }
625
1105
  });
626
1106
  await local_db.orders.delete(id);
@@ -647,6 +1127,12 @@ var orders = {
647
1127
  var list3 = async (props) => {
648
1128
  try {
649
1129
  const { sdk, query } = props;
1130
+ const queue_is_empty = await is_sync_queue_empty();
1131
+ if (!queue_is_empty) {
1132
+ throw new Error(
1133
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1134
+ );
1135
+ }
650
1136
  const adapter = await sdk.adapter();
651
1137
  if (!adapter) throw new Error("Adapter not found");
652
1138
  const customers2 = await adapter.customers.list({
@@ -665,6 +1151,12 @@ var list3 = async (props) => {
665
1151
  var retrieve3 = async (props) => {
666
1152
  try {
667
1153
  const { sdk, id } = props;
1154
+ const queue_is_empty = await is_sync_queue_empty();
1155
+ if (!queue_is_empty) {
1156
+ throw new Error(
1157
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1158
+ );
1159
+ }
668
1160
  const adapter = await sdk.adapter();
669
1161
  if (!adapter) throw new Error("Adapter not found");
670
1162
  const customer = await adapter.customers.retrieve({
@@ -687,11 +1179,11 @@ var create3 = async (props) => {
687
1179
  id: offline_id,
688
1180
  metadata: {
689
1181
  ...data.metadata,
690
- stall_offline_id: offline_id
691
- },
692
- stall_offline_id: offline_id,
693
- stall_offline_created_at: now,
694
- stall_offline_updated_at: now
1182
+ stall_offline_id: offline_id,
1183
+ stall_offline_created_at: now,
1184
+ stall_offline_updated_at: now,
1185
+ stall_offline_deleted_at: ""
1186
+ }
695
1187
  };
696
1188
  await local_db.customers.add(local_customer);
697
1189
  await add_to_sync_queue({
@@ -718,17 +1210,21 @@ var update3 = async (props) => {
718
1210
  ...existing,
719
1211
  ...data,
720
1212
  id: existing.id,
721
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
722
- stall_offline_id: existing.stall_offline_id,
723
- stall_offline_updated_at: now
1213
+ metadata: {
1214
+ ...existing.metadata,
1215
+ ...data.metadata,
1216
+ stall_offline_id: existing.metadata.stall_offline_id,
1217
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1218
+ stall_offline_updated_at: now,
1219
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1220
+ }
724
1221
  };
725
1222
  await local_db.customers.put(updated_customer);
726
1223
  await add_to_sync_queue({
727
1224
  action: "update",
728
1225
  table: "customers",
729
1226
  document_id: id,
730
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
731
- stall_offline_id: existing.stall_offline_id,
1227
+ stall_offline_id: existing.metadata.stall_offline_id,
732
1228
  data: updated_customer
733
1229
  });
734
1230
  return updated_customer;
@@ -747,8 +1243,7 @@ var _delete3 = async (props) => {
747
1243
  action: "delete",
748
1244
  table: "customers",
749
1245
  document_id: id,
750
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
751
- stall_offline_id: existing.stall_offline_id,
1246
+ stall_offline_id: existing.metadata.stall_offline_id,
752
1247
  data: { id }
753
1248
  });
754
1249
  await local_db.customers.delete(id);
@@ -769,11 +1264,11 @@ var bulk_create3 = async (props) => {
769
1264
  id: offline_id,
770
1265
  metadata: {
771
1266
  ...customer.metadata,
772
- stall_offline_id: offline_id
773
- },
774
- stall_offline_id: offline_id,
775
- stall_offline_created_at: now,
776
- stall_offline_updated_at: now
1267
+ stall_offline_id: offline_id,
1268
+ stall_offline_created_at: now,
1269
+ stall_offline_updated_at: now,
1270
+ stall_offline_deleted_at: ""
1271
+ }
777
1272
  };
778
1273
  await local_db.customers.add(local_customer);
779
1274
  await add_to_sync_queue({
@@ -805,17 +1300,21 @@ var bulk_update3 = async (props) => {
805
1300
  ...existing,
806
1301
  ...item.data,
807
1302
  id: existing.id,
808
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
809
- stall_offline_id: existing.stall_offline_id,
810
- stall_offline_updated_at: now
1303
+ metadata: {
1304
+ ...existing.metadata,
1305
+ ...item.data.metadata,
1306
+ stall_offline_id: existing.metadata.stall_offline_id,
1307
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1308
+ stall_offline_updated_at: now,
1309
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1310
+ }
811
1311
  };
812
1312
  await local_db.customers.put(updated_customer);
813
1313
  await add_to_sync_queue({
814
1314
  action: "update",
815
1315
  table: "customers",
816
1316
  document_id: item.id,
817
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
818
- stall_offline_id: existing.stall_offline_id,
1317
+ stall_offline_id: existing.metadata.stall_offline_id,
819
1318
  data: updated_customer
820
1319
  });
821
1320
  updated_customers.push(updated_customer);
@@ -838,8 +1337,7 @@ var bulk_delete3 = async (props) => {
838
1337
  action: "delete",
839
1338
  table: "customers",
840
1339
  document_id: id,
841
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
842
- stall_offline_id: existing.stall_offline_id,
1340
+ stall_offline_id: existing.metadata.stall_offline_id,
843
1341
  data: { id }
844
1342
  });
845
1343
  await local_db.customers.delete(id);
@@ -864,6 +1362,12 @@ var customers = {
864
1362
  var list4 = async (props) => {
865
1363
  try {
866
1364
  const { sdk, query } = props;
1365
+ const queue_is_empty = await is_sync_queue_empty();
1366
+ if (!queue_is_empty) {
1367
+ throw new Error(
1368
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1369
+ );
1370
+ }
867
1371
  const adapter = await sdk.adapter();
868
1372
  if (!adapter) throw new Error("Adapter not found");
869
1373
  const collections2 = await adapter.collections.list({
@@ -882,6 +1386,12 @@ var list4 = async (props) => {
882
1386
  var retrieve4 = async (props) => {
883
1387
  try {
884
1388
  const { sdk, id } = props;
1389
+ const queue_is_empty = await is_sync_queue_empty();
1390
+ if (!queue_is_empty) {
1391
+ throw new Error(
1392
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1393
+ );
1394
+ }
885
1395
  const adapter = await sdk.adapter();
886
1396
  if (!adapter) throw new Error("Adapter not found");
887
1397
  const collection = await adapter.collections.retrieve({
@@ -904,11 +1414,11 @@ var create4 = async (props) => {
904
1414
  id: offline_id,
905
1415
  metadata: {
906
1416
  ...data.metadata,
907
- stall_offline_id: offline_id
908
- },
909
- stall_offline_id: offline_id,
910
- stall_offline_created_at: now,
911
- stall_offline_updated_at: now
1417
+ stall_offline_id: offline_id,
1418
+ stall_offline_created_at: now,
1419
+ stall_offline_updated_at: now,
1420
+ stall_offline_deleted_at: ""
1421
+ }
912
1422
  };
913
1423
  await local_db.collections.add(local_collection);
914
1424
  await add_to_sync_queue({
@@ -935,17 +1445,21 @@ var update4 = async (props) => {
935
1445
  ...existing,
936
1446
  ...data,
937
1447
  id: existing.id,
938
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
939
- stall_offline_id: existing.stall_offline_id,
940
- stall_offline_updated_at: now
1448
+ metadata: {
1449
+ ...existing.metadata,
1450
+ ...data.metadata,
1451
+ stall_offline_id: existing.metadata.stall_offline_id,
1452
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1453
+ stall_offline_updated_at: now,
1454
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1455
+ }
941
1456
  };
942
1457
  await local_db.collections.put(updated_collection);
943
1458
  await add_to_sync_queue({
944
1459
  action: "update",
945
1460
  table: "collections",
946
1461
  document_id: id,
947
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
948
- stall_offline_id: existing.stall_offline_id,
1462
+ stall_offline_id: existing.metadata.stall_offline_id,
949
1463
  data: updated_collection
950
1464
  });
951
1465
  return updated_collection;
@@ -964,8 +1478,7 @@ var _delete4 = async (props) => {
964
1478
  action: "delete",
965
1479
  table: "collections",
966
1480
  document_id: id,
967
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
968
- stall_offline_id: existing.stall_offline_id,
1481
+ stall_offline_id: existing.metadata.stall_offline_id,
969
1482
  data: { id }
970
1483
  });
971
1484
  await local_db.collections.delete(id);
@@ -986,11 +1499,11 @@ var bulk_create4 = async (props) => {
986
1499
  id: offline_id,
987
1500
  metadata: {
988
1501
  ...collection.metadata,
989
- stall_offline_id: offline_id
990
- },
991
- stall_offline_id: offline_id,
992
- stall_offline_created_at: now,
993
- stall_offline_updated_at: now
1502
+ stall_offline_id: offline_id,
1503
+ stall_offline_created_at: now,
1504
+ stall_offline_updated_at: now,
1505
+ stall_offline_deleted_at: ""
1506
+ }
994
1507
  };
995
1508
  await local_db.collections.add(local_collection);
996
1509
  await add_to_sync_queue({
@@ -1024,17 +1537,21 @@ var bulk_update4 = async (props) => {
1024
1537
  ...existing,
1025
1538
  ...item.data,
1026
1539
  id: existing.id,
1027
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1028
- stall_offline_id: existing.stall_offline_id,
1029
- stall_offline_updated_at: now
1540
+ metadata: {
1541
+ ...existing.metadata,
1542
+ ...item.data.metadata,
1543
+ stall_offline_id: existing.metadata.stall_offline_id,
1544
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1545
+ stall_offline_updated_at: now,
1546
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1547
+ }
1030
1548
  };
1031
1549
  await local_db.collections.put(updated_collection);
1032
1550
  await add_to_sync_queue({
1033
1551
  action: "update",
1034
1552
  table: "collections",
1035
1553
  document_id: item.id,
1036
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1037
- stall_offline_id: existing.stall_offline_id,
1554
+ stall_offline_id: existing.metadata.stall_offline_id,
1038
1555
  data: updated_collection
1039
1556
  });
1040
1557
  updated_collections.push(updated_collection);
@@ -1057,8 +1574,7 @@ var bulk_delete4 = async (props) => {
1057
1574
  action: "delete",
1058
1575
  table: "collections",
1059
1576
  document_id: id,
1060
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1061
- stall_offline_id: existing.stall_offline_id,
1577
+ stall_offline_id: existing.metadata.stall_offline_id,
1062
1578
  data: { id }
1063
1579
  });
1064
1580
  await local_db.collections.delete(id);
@@ -1083,6 +1599,12 @@ var collections = {
1083
1599
  var list5 = async (props) => {
1084
1600
  try {
1085
1601
  const { sdk, query } = props;
1602
+ const queue_is_empty = await is_sync_queue_empty();
1603
+ if (!queue_is_empty) {
1604
+ throw new Error(
1605
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1606
+ );
1607
+ }
1086
1608
  const adapter = await sdk.adapter();
1087
1609
  if (!adapter) throw new Error("Adapter not found");
1088
1610
  const categories2 = await adapter.categories.list({
@@ -1101,6 +1623,12 @@ var list5 = async (props) => {
1101
1623
  var retrieve5 = async (props) => {
1102
1624
  try {
1103
1625
  const { sdk, id } = props;
1626
+ const queue_is_empty = await is_sync_queue_empty();
1627
+ if (!queue_is_empty) {
1628
+ throw new Error(
1629
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1630
+ );
1631
+ }
1104
1632
  const adapter = await sdk.adapter();
1105
1633
  if (!adapter) throw new Error("Adapter not found");
1106
1634
  const category = await adapter.categories.retrieve({
@@ -1123,11 +1651,11 @@ var create5 = async (props) => {
1123
1651
  id: offline_id,
1124
1652
  metadata: {
1125
1653
  ...data.metadata,
1126
- stall_offline_id: offline_id
1127
- },
1128
- stall_offline_id: offline_id,
1129
- stall_offline_created_at: now,
1130
- stall_offline_updated_at: now
1654
+ stall_offline_id: offline_id,
1655
+ stall_offline_created_at: now,
1656
+ stall_offline_updated_at: now,
1657
+ stall_offline_deleted_at: ""
1658
+ }
1131
1659
  };
1132
1660
  await local_db.categories.add(local_category);
1133
1661
  await add_to_sync_queue({
@@ -1154,17 +1682,21 @@ var update5 = async (props) => {
1154
1682
  ...existing,
1155
1683
  ...data,
1156
1684
  id: existing.id,
1157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1158
- stall_offline_id: existing.stall_offline_id,
1159
- stall_offline_updated_at: now
1685
+ metadata: {
1686
+ ...existing.metadata,
1687
+ ...data.metadata,
1688
+ stall_offline_id: existing.metadata.stall_offline_id,
1689
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1690
+ stall_offline_updated_at: now,
1691
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1692
+ }
1160
1693
  };
1161
1694
  await local_db.categories.put(updated_category);
1162
1695
  await add_to_sync_queue({
1163
1696
  action: "update",
1164
1697
  table: "categories",
1165
1698
  document_id: id,
1166
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1167
- stall_offline_id: existing.stall_offline_id,
1699
+ stall_offline_id: existing.metadata.stall_offline_id,
1168
1700
  data: updated_category
1169
1701
  });
1170
1702
  return updated_category;
@@ -1183,8 +1715,7 @@ var _delete5 = async (props) => {
1183
1715
  action: "delete",
1184
1716
  table: "categories",
1185
1717
  document_id: id,
1186
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1187
- stall_offline_id: existing.stall_offline_id,
1718
+ stall_offline_id: existing.metadata.stall_offline_id,
1188
1719
  data: { id }
1189
1720
  });
1190
1721
  await local_db.categories.delete(id);
@@ -1205,11 +1736,11 @@ var bulk_create5 = async (props) => {
1205
1736
  id: offline_id,
1206
1737
  metadata: {
1207
1738
  ...category.metadata,
1208
- stall_offline_id: offline_id
1209
- },
1210
- stall_offline_id: offline_id,
1211
- stall_offline_created_at: now,
1212
- stall_offline_updated_at: now
1739
+ stall_offline_id: offline_id,
1740
+ stall_offline_created_at: now,
1741
+ stall_offline_updated_at: now,
1742
+ stall_offline_deleted_at: ""
1743
+ }
1213
1744
  };
1214
1745
  await local_db.categories.add(local_category);
1215
1746
  await add_to_sync_queue({
@@ -1241,17 +1772,21 @@ var bulk_update5 = async (props) => {
1241
1772
  ...existing,
1242
1773
  ...item.data,
1243
1774
  id: existing.id,
1244
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1245
- stall_offline_id: existing.stall_offline_id,
1246
- stall_offline_updated_at: now
1775
+ metadata: {
1776
+ ...existing.metadata,
1777
+ ...item.data.metadata,
1778
+ stall_offline_id: existing.metadata.stall_offline_id,
1779
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1780
+ stall_offline_updated_at: now,
1781
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1782
+ }
1247
1783
  };
1248
1784
  await local_db.categories.put(updated_category);
1249
1785
  await add_to_sync_queue({
1250
1786
  action: "update",
1251
1787
  table: "categories",
1252
1788
  document_id: item.id,
1253
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1254
- stall_offline_id: existing.stall_offline_id,
1789
+ stall_offline_id: existing.metadata.stall_offline_id,
1255
1790
  data: updated_category
1256
1791
  });
1257
1792
  updated_categories.push(updated_category);
@@ -1274,8 +1809,7 @@ var bulk_delete5 = async (props) => {
1274
1809
  action: "delete",
1275
1810
  table: "categories",
1276
1811
  document_id: id,
1277
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1278
- stall_offline_id: existing.stall_offline_id,
1812
+ stall_offline_id: existing.metadata.stall_offline_id,
1279
1813
  data: { id }
1280
1814
  });
1281
1815
  await local_db.categories.delete(id);
@@ -1300,6 +1834,12 @@ var categories = {
1300
1834
  var list6 = async (props) => {
1301
1835
  try {
1302
1836
  const { sdk, query } = props;
1837
+ const queue_is_empty = await is_sync_queue_empty();
1838
+ if (!queue_is_empty) {
1839
+ throw new Error(
1840
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1841
+ );
1842
+ }
1303
1843
  const adapter = await sdk.adapter();
1304
1844
  if (!adapter) throw new Error("Adapter not found");
1305
1845
  const variants2 = await adapter.variants.list({
@@ -1318,6 +1858,12 @@ var list6 = async (props) => {
1318
1858
  var retrieve6 = async (props) => {
1319
1859
  try {
1320
1860
  const { sdk, id } = props;
1861
+ const queue_is_empty = await is_sync_queue_empty();
1862
+ if (!queue_is_empty) {
1863
+ throw new Error(
1864
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1865
+ );
1866
+ }
1321
1867
  const adapter = await sdk.adapter();
1322
1868
  if (!adapter) throw new Error("Adapter not found");
1323
1869
  const variant = await adapter.variants.retrieve({
@@ -1340,11 +1886,11 @@ var create6 = async (props) => {
1340
1886
  id: offline_id,
1341
1887
  metadata: {
1342
1888
  ...data.metadata,
1343
- stall_offline_id: offline_id
1344
- },
1345
- stall_offline_id: offline_id,
1346
- stall_offline_created_at: now,
1347
- stall_offline_updated_at: now
1889
+ stall_offline_id: offline_id,
1890
+ stall_offline_created_at: now,
1891
+ stall_offline_updated_at: now,
1892
+ stall_offline_deleted_at: ""
1893
+ }
1348
1894
  };
1349
1895
  await local_db.variants.add(local_variant);
1350
1896
  await add_to_sync_queue({
@@ -1371,17 +1917,21 @@ var update6 = async (props) => {
1371
1917
  ...existing,
1372
1918
  ...data,
1373
1919
  id: existing.id,
1374
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1375
- stall_offline_id: existing.stall_offline_id,
1376
- stall_offline_updated_at: now
1920
+ metadata: {
1921
+ ...existing.metadata,
1922
+ ...data.metadata,
1923
+ stall_offline_id: existing.metadata.stall_offline_id,
1924
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1925
+ stall_offline_updated_at: now,
1926
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1927
+ }
1377
1928
  };
1378
1929
  await local_db.variants.put(updated_variant);
1379
1930
  await add_to_sync_queue({
1380
1931
  action: "update",
1381
1932
  table: "variants",
1382
1933
  document_id: id,
1383
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1384
- stall_offline_id: existing.stall_offline_id,
1934
+ stall_offline_id: existing.metadata.stall_offline_id,
1385
1935
  data: updated_variant
1386
1936
  });
1387
1937
  return updated_variant;
@@ -1400,8 +1950,7 @@ var _delete6 = async (props) => {
1400
1950
  action: "delete",
1401
1951
  table: "variants",
1402
1952
  document_id: id,
1403
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1404
- stall_offline_id: existing.stall_offline_id,
1953
+ stall_offline_id: existing.metadata.stall_offline_id,
1405
1954
  data: { id }
1406
1955
  });
1407
1956
  await local_db.variants.delete(id);
@@ -1422,11 +1971,11 @@ var bulk_create6 = async (props) => {
1422
1971
  id: offline_id,
1423
1972
  metadata: {
1424
1973
  ...variant.metadata,
1425
- stall_offline_id: offline_id
1426
- },
1427
- stall_offline_id: offline_id,
1428
- stall_offline_created_at: now,
1429
- stall_offline_updated_at: now
1974
+ stall_offline_id: offline_id,
1975
+ stall_offline_created_at: now,
1976
+ stall_offline_updated_at: now,
1977
+ stall_offline_deleted_at: ""
1978
+ }
1430
1979
  };
1431
1980
  await local_db.variants.add(local_variant);
1432
1981
  await add_to_sync_queue({
@@ -1458,17 +2007,21 @@ var bulk_update6 = async (props) => {
1458
2007
  ...existing,
1459
2008
  ...item.data,
1460
2009
  id: existing.id,
1461
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1462
- stall_offline_id: existing.stall_offline_id,
1463
- stall_offline_updated_at: now
2010
+ metadata: {
2011
+ ...existing.metadata,
2012
+ ...item.data.metadata,
2013
+ stall_offline_id: existing.metadata.stall_offline_id,
2014
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2015
+ stall_offline_updated_at: now,
2016
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2017
+ }
1464
2018
  };
1465
2019
  await local_db.variants.put(updated_variant);
1466
2020
  await add_to_sync_queue({
1467
2021
  action: "update",
1468
2022
  table: "variants",
1469
2023
  document_id: item.id,
1470
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1471
- stall_offline_id: existing.stall_offline_id,
2024
+ stall_offline_id: existing.metadata.stall_offline_id,
1472
2025
  data: updated_variant
1473
2026
  });
1474
2027
  updated_variants.push(updated_variant);
@@ -1491,8 +2044,7 @@ var bulk_delete6 = async (props) => {
1491
2044
  action: "delete",
1492
2045
  table: "variants",
1493
2046
  document_id: id,
1494
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1495
- stall_offline_id: existing.stall_offline_id,
2047
+ stall_offline_id: existing.metadata.stall_offline_id,
1496
2048
  data: { id }
1497
2049
  });
1498
2050
  await local_db.variants.delete(id);
@@ -1517,6 +2069,12 @@ var variants = {
1517
2069
  var list7 = async (props) => {
1518
2070
  try {
1519
2071
  const { sdk, query } = props;
2072
+ const queue_is_empty = await is_sync_queue_empty();
2073
+ if (!queue_is_empty) {
2074
+ throw new Error(
2075
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2076
+ );
2077
+ }
1520
2078
  const adapter = await sdk.adapter();
1521
2079
  if (!adapter) throw new Error("Adapter not found");
1522
2080
  const inventory_levels2 = await adapter.inventory_levels.list({
@@ -1535,6 +2093,12 @@ var list7 = async (props) => {
1535
2093
  var retrieve7 = async (props) => {
1536
2094
  try {
1537
2095
  const { sdk, id } = props;
2096
+ const queue_is_empty = await is_sync_queue_empty();
2097
+ if (!queue_is_empty) {
2098
+ throw new Error(
2099
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2100
+ );
2101
+ }
1538
2102
  const adapter = await sdk.adapter();
1539
2103
  if (!adapter) throw new Error("Adapter not found");
1540
2104
  const inventory_level = await adapter.inventory_levels.retrieve({
@@ -1557,12 +2121,11 @@ var create7 = async (props) => {
1557
2121
  id: offline_id,
1558
2122
  metadata: {
1559
2123
  ...data.metadata,
1560
- stall_offline_id: offline_id
1561
- },
1562
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1563
- stall_offline_id: offline_id,
1564
- stall_offline_created_at: now,
1565
- stall_offline_updated_at: now
2124
+ stall_offline_id: offline_id,
2125
+ stall_offline_created_at: now,
2126
+ stall_offline_updated_at: now,
2127
+ stall_offline_deleted_at: ""
2128
+ }
1566
2129
  };
1567
2130
  await local_db.inventory_levels.add(local_inventory_level);
1568
2131
  await add_to_sync_queue({
@@ -1589,17 +2152,21 @@ var update7 = async (props) => {
1589
2152
  ...existing,
1590
2153
  ...data,
1591
2154
  id: existing.id,
1592
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1593
- stall_offline_id: existing.stall_offline_id,
1594
- stall_offline_updated_at: now
2155
+ metadata: {
2156
+ ...existing.metadata,
2157
+ ...data.metadata,
2158
+ stall_offline_id: existing.metadata.stall_offline_id,
2159
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2160
+ stall_offline_updated_at: now,
2161
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2162
+ }
1595
2163
  };
1596
2164
  await local_db.inventory_levels.put(updated_inventory_level);
1597
2165
  await add_to_sync_queue({
1598
2166
  action: "update",
1599
2167
  table: "inventory_levels",
1600
2168
  document_id: id,
1601
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1602
- stall_offline_id: existing.stall_offline_id,
2169
+ stall_offline_id: existing.metadata.stall_offline_id,
1603
2170
  data: updated_inventory_level
1604
2171
  });
1605
2172
  return updated_inventory_level;
@@ -1618,8 +2185,7 @@ var _delete7 = async (props) => {
1618
2185
  action: "delete",
1619
2186
  table: "inventory_levels",
1620
2187
  document_id: id,
1621
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1622
- stall_offline_id: existing.stall_offline_id,
2188
+ stall_offline_id: existing.metadata.stall_offline_id,
1623
2189
  data: { id }
1624
2190
  });
1625
2191
  await local_db.inventory_levels.delete(id);
@@ -1640,12 +2206,11 @@ var bulk_create7 = async (props) => {
1640
2206
  id: offline_id,
1641
2207
  metadata: {
1642
2208
  ...inventory_level.metadata,
1643
- stall_offline_id: offline_id
1644
- },
1645
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1646
- stall_offline_id: offline_id,
1647
- stall_offline_created_at: now,
1648
- stall_offline_updated_at: now
2209
+ stall_offline_id: offline_id,
2210
+ stall_offline_created_at: now,
2211
+ stall_offline_updated_at: now,
2212
+ stall_offline_deleted_at: ""
2213
+ }
1649
2214
  };
1650
2215
  await local_db.inventory_levels.add(local_inventory_level);
1651
2216
  await add_to_sync_queue({
@@ -1679,17 +2244,21 @@ var bulk_update7 = async (props) => {
1679
2244
  ...existing,
1680
2245
  ...item.data,
1681
2246
  id: existing.id,
1682
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1683
- stall_offline_id: existing.stall_offline_id,
1684
- stall_offline_updated_at: now
2247
+ metadata: {
2248
+ ...existing.metadata,
2249
+ ...item.data.metadata,
2250
+ stall_offline_id: existing.metadata.stall_offline_id,
2251
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2252
+ stall_offline_updated_at: now,
2253
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2254
+ }
1685
2255
  };
1686
2256
  await local_db.inventory_levels.put(updated_inventory_level);
1687
2257
  await add_to_sync_queue({
1688
2258
  action: "update",
1689
2259
  table: "inventory_levels",
1690
2260
  document_id: item.id,
1691
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1692
- stall_offline_id: existing.stall_offline_id,
2261
+ stall_offline_id: existing.metadata.stall_offline_id,
1693
2262
  data: updated_inventory_level
1694
2263
  });
1695
2264
  updated_inventory_levels.push(updated_inventory_level);
@@ -1714,8 +2283,7 @@ var bulk_delete7 = async (props) => {
1714
2283
  action: "delete",
1715
2284
  table: "inventory_levels",
1716
2285
  document_id: id,
1717
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1718
- stall_offline_id: existing.stall_offline_id,
2286
+ stall_offline_id: existing.metadata.stall_offline_id,
1719
2287
  data: { id }
1720
2288
  });
1721
2289
  await local_db.inventory_levels.delete(id);
@@ -1740,6 +2308,12 @@ var inventory_levels = {
1740
2308
  var list8 = async (props) => {
1741
2309
  try {
1742
2310
  const { sdk, query } = props;
2311
+ const queue_is_empty = await is_sync_queue_empty();
2312
+ if (!queue_is_empty) {
2313
+ throw new Error(
2314
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2315
+ );
2316
+ }
1743
2317
  const adapter = await sdk.adapter();
1744
2318
  if (!adapter) throw new Error("Adapter not found");
1745
2319
  const promotions2 = await adapter.promotions.list({
@@ -1758,6 +2332,12 @@ var list8 = async (props) => {
1758
2332
  var retrieve8 = async (props) => {
1759
2333
  try {
1760
2334
  const { sdk, id } = props;
2335
+ const queue_is_empty = await is_sync_queue_empty();
2336
+ if (!queue_is_empty) {
2337
+ throw new Error(
2338
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2339
+ );
2340
+ }
1761
2341
  const adapter = await sdk.adapter();
1762
2342
  if (!adapter) throw new Error("Adapter not found");
1763
2343
  const promotion = await adapter.promotions.retrieve({
@@ -1780,12 +2360,11 @@ var create8 = async (props) => {
1780
2360
  id: offline_id,
1781
2361
  metadata: {
1782
2362
  ...data.metadata,
1783
- stall_offline_id: offline_id
1784
- },
1785
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1786
- stall_offline_id: offline_id,
1787
- stall_offline_created_at: now,
1788
- stall_offline_updated_at: now
2363
+ stall_offline_id: offline_id,
2364
+ stall_offline_created_at: now,
2365
+ stall_offline_updated_at: now,
2366
+ stall_offline_deleted_at: ""
2367
+ }
1789
2368
  };
1790
2369
  await local_db.promotions.add(local_promotion);
1791
2370
  await add_to_sync_queue({
@@ -1812,17 +2391,21 @@ var update8 = async (props) => {
1812
2391
  ...existing,
1813
2392
  ...data,
1814
2393
  id: existing.id,
1815
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1816
- stall_offline_id: existing.stall_offline_id,
1817
- stall_offline_updated_at: now
2394
+ metadata: {
2395
+ ...existing.metadata,
2396
+ ...data.metadata,
2397
+ stall_offline_id: existing.metadata.stall_offline_id,
2398
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2399
+ stall_offline_updated_at: now,
2400
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2401
+ }
1818
2402
  };
1819
2403
  await local_db.promotions.put(updated_promotion);
1820
2404
  await add_to_sync_queue({
1821
2405
  action: "update",
1822
2406
  table: "promotions",
1823
2407
  document_id: id,
1824
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1825
- stall_offline_id: existing.stall_offline_id,
2408
+ stall_offline_id: existing.metadata.stall_offline_id,
1826
2409
  data: updated_promotion
1827
2410
  });
1828
2411
  return updated_promotion;
@@ -1841,8 +2424,7 @@ var _delete8 = async (props) => {
1841
2424
  action: "delete",
1842
2425
  table: "promotions",
1843
2426
  document_id: id,
1844
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1845
- stall_offline_id: existing.stall_offline_id,
2427
+ stall_offline_id: existing.metadata.stall_offline_id,
1846
2428
  data: { id }
1847
2429
  });
1848
2430
  await local_db.promotions.delete(id);
@@ -1863,12 +2445,11 @@ var bulk_create8 = async (props) => {
1863
2445
  id: offline_id,
1864
2446
  metadata: {
1865
2447
  ...promotion.metadata,
1866
- stall_offline_id: offline_id
1867
- },
1868
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1869
- stall_offline_id: offline_id,
1870
- stall_offline_created_at: now,
1871
- stall_offline_updated_at: now
2448
+ stall_offline_id: offline_id,
2449
+ stall_offline_created_at: now,
2450
+ stall_offline_updated_at: now,
2451
+ stall_offline_deleted_at: ""
2452
+ }
1872
2453
  };
1873
2454
  await local_db.promotions.add(local_promotion);
1874
2455
  await add_to_sync_queue({
@@ -1902,17 +2483,21 @@ var bulk_update8 = async (props) => {
1902
2483
  ...existing,
1903
2484
  ...item.data,
1904
2485
  id: existing.id,
1905
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1906
- stall_offline_id: existing.stall_offline_id,
1907
- stall_offline_updated_at: now
2486
+ metadata: {
2487
+ ...existing.metadata,
2488
+ ...item.data.metadata,
2489
+ stall_offline_id: existing.metadata.stall_offline_id,
2490
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2491
+ stall_offline_updated_at: now,
2492
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2493
+ }
1908
2494
  };
1909
2495
  await local_db.promotions.put(updated_promotion);
1910
2496
  await add_to_sync_queue({
1911
2497
  action: "update",
1912
2498
  table: "promotions",
1913
2499
  document_id: item.id,
1914
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1915
- stall_offline_id: existing.stall_offline_id,
2500
+ stall_offline_id: existing.metadata.stall_offline_id,
1916
2501
  data: updated_promotion
1917
2502
  });
1918
2503
  updated_promotions.push(updated_promotion);
@@ -1935,8 +2520,7 @@ var bulk_delete8 = async (props) => {
1935
2520
  action: "delete",
1936
2521
  table: "promotions",
1937
2522
  document_id: id,
1938
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1939
- stall_offline_id: existing.stall_offline_id,
2523
+ stall_offline_id: existing.metadata.stall_offline_id,
1940
2524
  data: { id }
1941
2525
  });
1942
2526
  await local_db.promotions.delete(id);
@@ -1961,6 +2545,12 @@ var promotions = {
1961
2545
  var list9 = async (props) => {
1962
2546
  try {
1963
2547
  const { sdk, query } = props;
2548
+ const queue_is_empty = await is_sync_queue_empty();
2549
+ if (!queue_is_empty) {
2550
+ throw new Error(
2551
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2552
+ );
2553
+ }
1964
2554
  const adapter = await sdk.adapter();
1965
2555
  if (!adapter) throw new Error("Adapter not found");
1966
2556
  const order_notes2 = await adapter.order_notes.list({
@@ -1979,6 +2569,12 @@ var list9 = async (props) => {
1979
2569
  var retrieve9 = async (props) => {
1980
2570
  try {
1981
2571
  const { sdk, id } = props;
2572
+ const queue_is_empty = await is_sync_queue_empty();
2573
+ if (!queue_is_empty) {
2574
+ throw new Error(
2575
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2576
+ );
2577
+ }
1982
2578
  const adapter = await sdk.adapter();
1983
2579
  if (!adapter) throw new Error("Adapter not found");
1984
2580
  const order_note = await adapter.order_notes.retrieve({
@@ -2001,12 +2597,11 @@ var create9 = async (props) => {
2001
2597
  id: offline_id,
2002
2598
  metadata: {
2003
2599
  ...data.metadata,
2004
- stall_offline_id: offline_id
2005
- },
2006
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2007
- stall_offline_id: offline_id,
2008
- stall_offline_created_at: now,
2009
- stall_offline_updated_at: now
2600
+ stall_offline_id: offline_id,
2601
+ stall_offline_created_at: now,
2602
+ stall_offline_updated_at: now,
2603
+ stall_offline_deleted_at: ""
2604
+ }
2010
2605
  };
2011
2606
  await local_db.order_notes.add(local_order_note);
2012
2607
  await add_to_sync_queue({
@@ -2033,17 +2628,21 @@ var update9 = async (props) => {
2033
2628
  ...existing,
2034
2629
  ...data,
2035
2630
  id: existing.id,
2036
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2037
- stall_offline_id: existing.stall_offline_id,
2038
- stall_offline_updated_at: now
2631
+ metadata: {
2632
+ ...existing.metadata,
2633
+ ...data.metadata,
2634
+ stall_offline_id: existing.metadata.stall_offline_id,
2635
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2636
+ stall_offline_updated_at: now,
2637
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2638
+ }
2039
2639
  };
2040
2640
  await local_db.order_notes.put(updated_order_note);
2041
2641
  await add_to_sync_queue({
2042
2642
  action: "update",
2043
2643
  table: "order_notes",
2044
2644
  document_id: id,
2045
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2046
- stall_offline_id: existing.stall_offline_id,
2645
+ stall_offline_id: existing.metadata.stall_offline_id,
2047
2646
  data: updated_order_note
2048
2647
  });
2049
2648
  return updated_order_note;
@@ -2062,8 +2661,7 @@ var _delete9 = async (props) => {
2062
2661
  action: "delete",
2063
2662
  table: "order_notes",
2064
2663
  document_id: id,
2065
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2066
- stall_offline_id: existing.stall_offline_id,
2664
+ stall_offline_id: existing.metadata.stall_offline_id,
2067
2665
  data: { id }
2068
2666
  });
2069
2667
  await local_db.order_notes.delete(id);
@@ -2084,12 +2682,11 @@ var bulk_create9 = async (props) => {
2084
2682
  id: offline_id,
2085
2683
  metadata: {
2086
2684
  ...order_note.metadata,
2087
- stall_offline_id: offline_id
2088
- },
2089
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2090
- stall_offline_id: offline_id,
2091
- stall_offline_created_at: now,
2092
- stall_offline_updated_at: now
2685
+ stall_offline_id: offline_id,
2686
+ stall_offline_created_at: now,
2687
+ stall_offline_updated_at: now,
2688
+ stall_offline_deleted_at: ""
2689
+ }
2093
2690
  };
2094
2691
  await local_db.order_notes.add(local_order_note);
2095
2692
  await add_to_sync_queue({
@@ -2123,17 +2720,21 @@ var bulk_update9 = async (props) => {
2123
2720
  ...existing,
2124
2721
  ...item.data,
2125
2722
  id: existing.id,
2126
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2127
- stall_offline_id: existing.stall_offline_id,
2128
- stall_offline_updated_at: now
2723
+ metadata: {
2724
+ ...existing.metadata,
2725
+ ...item.data.metadata,
2726
+ stall_offline_id: existing.metadata.stall_offline_id,
2727
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2728
+ stall_offline_updated_at: now,
2729
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2730
+ }
2129
2731
  };
2130
2732
  await local_db.order_notes.put(updated_order_note);
2131
2733
  await add_to_sync_queue({
2132
2734
  action: "update",
2133
2735
  table: "order_notes",
2134
2736
  document_id: item.id,
2135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2136
- stall_offline_id: existing.stall_offline_id,
2737
+ stall_offline_id: existing.metadata.stall_offline_id,
2137
2738
  data: updated_order_note
2138
2739
  });
2139
2740
  updated_order_notes.push(updated_order_note);
@@ -2156,8 +2757,7 @@ var bulk_delete9 = async (props) => {
2156
2757
  action: "delete",
2157
2758
  table: "order_notes",
2158
2759
  document_id: id,
2159
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2160
- stall_offline_id: existing.stall_offline_id,
2760
+ stall_offline_id: existing.metadata.stall_offline_id,
2161
2761
  data: { id }
2162
2762
  });
2163
2763
  await local_db.order_notes.delete(id);
@@ -2182,6 +2782,12 @@ var order_notes = {
2182
2782
  var list10 = async (props) => {
2183
2783
  try {
2184
2784
  const { sdk, query } = props;
2785
+ const queue_is_empty = await is_sync_queue_empty();
2786
+ if (!queue_is_empty) {
2787
+ throw new Error(
2788
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2789
+ );
2790
+ }
2185
2791
  const adapter = await sdk.adapter();
2186
2792
  if (!adapter) throw new Error("Adapter not found");
2187
2793
  const refunds2 = await adapter.refunds.list({
@@ -2200,6 +2806,12 @@ var list10 = async (props) => {
2200
2806
  var retrieve10 = async (props) => {
2201
2807
  try {
2202
2808
  const { sdk, id } = props;
2809
+ const queue_is_empty = await is_sync_queue_empty();
2810
+ if (!queue_is_empty) {
2811
+ throw new Error(
2812
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2813
+ );
2814
+ }
2203
2815
  const adapter = await sdk.adapter();
2204
2816
  if (!adapter) throw new Error("Adapter not found");
2205
2817
  const refund = await adapter.refunds.retrieve({
@@ -2222,12 +2834,11 @@ var create10 = async (props) => {
2222
2834
  id: offline_id,
2223
2835
  metadata: {
2224
2836
  ...data.metadata,
2225
- stall_offline_id: offline_id
2226
- },
2227
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2228
- stall_offline_id: offline_id,
2229
- stall_offline_created_at: now,
2230
- stall_offline_updated_at: now
2837
+ stall_offline_id: offline_id,
2838
+ stall_offline_created_at: now,
2839
+ stall_offline_updated_at: now,
2840
+ stall_offline_deleted_at: ""
2841
+ }
2231
2842
  };
2232
2843
  await local_db.refunds.add(local_refund);
2233
2844
  await add_to_sync_queue({
@@ -2254,17 +2865,21 @@ var update10 = async (props) => {
2254
2865
  ...existing,
2255
2866
  ...data,
2256
2867
  id: existing.id,
2257
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2258
- stall_offline_id: existing.stall_offline_id,
2259
- stall_offline_updated_at: now
2868
+ metadata: {
2869
+ ...existing.metadata,
2870
+ ...data.metadata,
2871
+ stall_offline_id: existing.metadata.stall_offline_id,
2872
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2873
+ stall_offline_updated_at: now,
2874
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2875
+ }
2260
2876
  };
2261
2877
  await local_db.refunds.put(updated_refund);
2262
2878
  await add_to_sync_queue({
2263
2879
  action: "update",
2264
2880
  table: "refunds",
2265
2881
  document_id: id,
2266
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2267
- stall_offline_id: existing.stall_offline_id,
2882
+ stall_offline_id: existing.metadata.stall_offline_id,
2268
2883
  data: updated_refund
2269
2884
  });
2270
2885
  return updated_refund;
@@ -2283,8 +2898,7 @@ var _delete10 = async (props) => {
2283
2898
  action: "delete",
2284
2899
  table: "refunds",
2285
2900
  document_id: id,
2286
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2287
- stall_offline_id: existing.stall_offline_id,
2901
+ stall_offline_id: existing.metadata.stall_offline_id,
2288
2902
  data: { id }
2289
2903
  });
2290
2904
  await local_db.refunds.delete(id);
@@ -2305,12 +2919,11 @@ var bulk_create10 = async (props) => {
2305
2919
  id: offline_id,
2306
2920
  metadata: {
2307
2921
  ...refund.metadata,
2308
- stall_offline_id: offline_id
2309
- },
2310
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2311
- stall_offline_id: offline_id,
2312
- stall_offline_created_at: now,
2313
- stall_offline_updated_at: now
2922
+ stall_offline_id: offline_id,
2923
+ stall_offline_created_at: now,
2924
+ stall_offline_updated_at: now,
2925
+ stall_offline_deleted_at: ""
2926
+ }
2314
2927
  };
2315
2928
  await local_db.refunds.add(local_refund);
2316
2929
  await add_to_sync_queue({
@@ -2342,17 +2955,21 @@ var bulk_update10 = async (props) => {
2342
2955
  ...existing,
2343
2956
  ...item.data,
2344
2957
  id: existing.id,
2345
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2346
- stall_offline_id: existing.stall_offline_id,
2347
- stall_offline_updated_at: now
2958
+ metadata: {
2959
+ ...existing.metadata,
2960
+ ...item.data.metadata,
2961
+ stall_offline_id: existing.metadata.stall_offline_id,
2962
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2963
+ stall_offline_updated_at: now,
2964
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2965
+ }
2348
2966
  };
2349
2967
  await local_db.refunds.put(updated_refund);
2350
2968
  await add_to_sync_queue({
2351
2969
  action: "update",
2352
2970
  table: "refunds",
2353
2971
  document_id: item.id,
2354
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2355
- stall_offline_id: existing.stall_offline_id,
2972
+ stall_offline_id: existing.metadata.stall_offline_id,
2356
2973
  data: updated_refund
2357
2974
  });
2358
2975
  updated_refunds.push(updated_refund);
@@ -2375,8 +2992,7 @@ var bulk_delete10 = async (props) => {
2375
2992
  action: "delete",
2376
2993
  table: "refunds",
2377
2994
  document_id: id,
2378
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2379
- stall_offline_id: existing.stall_offline_id,
2995
+ stall_offline_id: existing.metadata.stall_offline_id,
2380
2996
  data: { id }
2381
2997
  });
2382
2998
  await local_db.refunds.delete(id);
@@ -2401,6 +3017,12 @@ var refunds = {
2401
3017
  var list11 = async (props) => {
2402
3018
  try {
2403
3019
  const { sdk, query } = props;
3020
+ const queue_is_empty = await is_sync_queue_empty();
3021
+ if (!queue_is_empty) {
3022
+ throw new Error(
3023
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3024
+ );
3025
+ }
2404
3026
  const adapter = await sdk.adapter();
2405
3027
  if (!adapter) throw new Error("Adapter not found");
2406
3028
  const payment_providers2 = await adapter.payment_providers.list({
@@ -2419,6 +3041,12 @@ var list11 = async (props) => {
2419
3041
  var retrieve11 = async (props) => {
2420
3042
  try {
2421
3043
  const { sdk, id } = props;
3044
+ const queue_is_empty = await is_sync_queue_empty();
3045
+ if (!queue_is_empty) {
3046
+ throw new Error(
3047
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3048
+ );
3049
+ }
2422
3050
  const adapter = await sdk.adapter();
2423
3051
  if (!adapter) throw new Error("Adapter not found");
2424
3052
  const payment_provider = await adapter.payment_providers.retrieve({
@@ -2440,14 +3068,12 @@ var create11 = async (props) => {
2440
3068
  ...data,
2441
3069
  id: offline_id,
2442
3070
  metadata: {
2443
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2444
3071
  ...data.metadata,
2445
- stall_offline_id: offline_id
2446
- },
2447
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2448
- stall_offline_id: offline_id,
2449
- stall_offline_created_at: now,
2450
- stall_offline_updated_at: now
3072
+ stall_offline_id: offline_id,
3073
+ stall_offline_created_at: now,
3074
+ stall_offline_updated_at: now,
3075
+ stall_offline_deleted_at: ""
3076
+ }
2451
3077
  };
2452
3078
  await local_db.payment_providers.add(local_payment_provider);
2453
3079
  await add_to_sync_queue({
@@ -2474,17 +3100,21 @@ var update11 = async (props) => {
2474
3100
  ...existing,
2475
3101
  ...data,
2476
3102
  id: existing.id,
2477
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2478
- stall_offline_id: existing.stall_offline_id,
2479
- stall_offline_updated_at: now
3103
+ metadata: {
3104
+ ...existing.metadata,
3105
+ ...data.metadata,
3106
+ stall_offline_id: existing.metadata.stall_offline_id,
3107
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3108
+ stall_offline_updated_at: now,
3109
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3110
+ }
2480
3111
  };
2481
3112
  await local_db.payment_providers.put(updated_payment_provider);
2482
3113
  await add_to_sync_queue({
2483
3114
  action: "update",
2484
3115
  table: "payment_providers",
2485
3116
  document_id: id,
2486
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2487
- stall_offline_id: existing.stall_offline_id,
3117
+ stall_offline_id: existing.metadata.stall_offline_id,
2488
3118
  data: updated_payment_provider
2489
3119
  });
2490
3120
  return updated_payment_provider;
@@ -2503,8 +3133,7 @@ var _delete11 = async (props) => {
2503
3133
  action: "delete",
2504
3134
  table: "payment_providers",
2505
3135
  document_id: id,
2506
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2507
- stall_offline_id: existing.stall_offline_id,
3136
+ stall_offline_id: existing.metadata.stall_offline_id,
2508
3137
  data: { id }
2509
3138
  });
2510
3139
  await local_db.payment_providers.delete(id);
@@ -2524,14 +3153,12 @@ var bulk_create11 = async (props) => {
2524
3153
  ...payment_provider,
2525
3154
  id: offline_id,
2526
3155
  metadata: {
2527
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2528
3156
  ...payment_provider.metadata,
2529
- stall_offline_id: offline_id
2530
- },
2531
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2532
- stall_offline_id: offline_id,
2533
- stall_offline_created_at: now,
2534
- stall_offline_updated_at: now
3157
+ stall_offline_id: offline_id,
3158
+ stall_offline_created_at: now,
3159
+ stall_offline_updated_at: now,
3160
+ stall_offline_deleted_at: ""
3161
+ }
2535
3162
  };
2536
3163
  await local_db.payment_providers.add(local_payment_provider);
2537
3164
  await add_to_sync_queue({
@@ -2565,17 +3192,21 @@ var bulk_update11 = async (props) => {
2565
3192
  ...existing,
2566
3193
  ...item.data,
2567
3194
  id: existing.id,
2568
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2569
- stall_offline_id: existing.stall_offline_id,
2570
- stall_offline_updated_at: now
3195
+ metadata: {
3196
+ ...existing.metadata,
3197
+ ...item.data.metadata,
3198
+ stall_offline_id: existing.metadata.stall_offline_id,
3199
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3200
+ stall_offline_updated_at: now,
3201
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3202
+ }
2571
3203
  };
2572
3204
  await local_db.payment_providers.put(updated_payment_provider);
2573
3205
  await add_to_sync_queue({
2574
3206
  action: "update",
2575
3207
  table: "payment_providers",
2576
3208
  document_id: item.id,
2577
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2578
- stall_offline_id: existing.stall_offline_id,
3209
+ stall_offline_id: existing.metadata.stall_offline_id,
2579
3210
  data: updated_payment_provider
2580
3211
  });
2581
3212
  updated_payment_providers.push(updated_payment_provider);
@@ -2600,8 +3231,7 @@ var bulk_delete11 = async (props) => {
2600
3231
  action: "delete",
2601
3232
  table: "payment_providers",
2602
3233
  document_id: id,
2603
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2604
- stall_offline_id: existing.stall_offline_id,
3234
+ stall_offline_id: existing.metadata.stall_offline_id,
2605
3235
  data: { id }
2606
3236
  });
2607
3237
  await local_db.payment_providers.delete(id);
@@ -2626,6 +3256,12 @@ var payment_providers = {
2626
3256
  var list12 = async (props) => {
2627
3257
  try {
2628
3258
  const { sdk, query } = props;
3259
+ const queue_is_empty = await is_sync_queue_empty();
3260
+ if (!queue_is_empty) {
3261
+ throw new Error(
3262
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3263
+ );
3264
+ }
2629
3265
  const adapter = await sdk.adapter();
2630
3266
  if (!adapter) throw new Error("Adapter not found");
2631
3267
  const payments2 = await adapter.payments.list({
@@ -2644,6 +3280,12 @@ var list12 = async (props) => {
2644
3280
  var retrieve12 = async (props) => {
2645
3281
  try {
2646
3282
  const { sdk, id } = props;
3283
+ const queue_is_empty = await is_sync_queue_empty();
3284
+ if (!queue_is_empty) {
3285
+ throw new Error(
3286
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3287
+ );
3288
+ }
2647
3289
  const adapter = await sdk.adapter();
2648
3290
  if (!adapter) throw new Error("Adapter not found");
2649
3291
  const payment = await adapter.payments.retrieve({
@@ -2666,12 +3308,11 @@ var create12 = async (props) => {
2666
3308
  id: offline_id,
2667
3309
  metadata: {
2668
3310
  ...data.metadata,
2669
- stall_offline_id: offline_id
2670
- },
2671
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2672
- stall_offline_id: offline_id,
2673
- stall_offline_created_at: now,
2674
- stall_offline_updated_at: now
3311
+ stall_offline_id: offline_id,
3312
+ stall_offline_created_at: now,
3313
+ stall_offline_updated_at: now,
3314
+ stall_offline_deleted_at: ""
3315
+ }
2675
3316
  };
2676
3317
  await local_db.payments.add(local_payment);
2677
3318
  await add_to_sync_queue({
@@ -2698,17 +3339,21 @@ var update12 = async (props) => {
2698
3339
  ...existing,
2699
3340
  ...data,
2700
3341
  id: existing.id,
2701
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2702
- stall_offline_id: existing.stall_offline_id,
2703
- stall_offline_updated_at: now
3342
+ metadata: {
3343
+ ...existing.metadata,
3344
+ ...data.metadata,
3345
+ stall_offline_id: existing.metadata.stall_offline_id,
3346
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3347
+ stall_offline_updated_at: now,
3348
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3349
+ }
2704
3350
  };
2705
3351
  await local_db.payments.put(updated_payment);
2706
3352
  await add_to_sync_queue({
2707
3353
  action: "update",
2708
3354
  table: "payments",
2709
3355
  document_id: id,
2710
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2711
- stall_offline_id: existing.stall_offline_id,
3356
+ stall_offline_id: existing.metadata.stall_offline_id,
2712
3357
  data: updated_payment
2713
3358
  });
2714
3359
  return updated_payment;
@@ -2727,8 +3372,7 @@ var _delete12 = async (props) => {
2727
3372
  action: "delete",
2728
3373
  table: "payments",
2729
3374
  document_id: id,
2730
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2731
- stall_offline_id: existing.stall_offline_id,
3375
+ stall_offline_id: existing.metadata.stall_offline_id,
2732
3376
  data: { id }
2733
3377
  });
2734
3378
  await local_db.payments.delete(id);
@@ -2749,12 +3393,11 @@ var bulk_create12 = async (props) => {
2749
3393
  id: offline_id,
2750
3394
  metadata: {
2751
3395
  ...payment.metadata,
2752
- stall_offline_id: offline_id
2753
- },
2754
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2755
- stall_offline_id: offline_id,
2756
- stall_offline_created_at: now,
2757
- stall_offline_updated_at: now
3396
+ stall_offline_id: offline_id,
3397
+ stall_offline_created_at: now,
3398
+ stall_offline_updated_at: now,
3399
+ stall_offline_deleted_at: ""
3400
+ }
2758
3401
  };
2759
3402
  await local_db.payments.add(local_payment);
2760
3403
  await add_to_sync_queue({
@@ -2786,17 +3429,21 @@ var bulk_update12 = async (props) => {
2786
3429
  ...existing,
2787
3430
  ...item.data,
2788
3431
  id: existing.id,
2789
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2790
- stall_offline_id: existing.stall_offline_id,
2791
- stall_offline_updated_at: now
3432
+ metadata: {
3433
+ ...existing.metadata,
3434
+ ...item.data.metadata,
3435
+ stall_offline_id: existing.metadata.stall_offline_id,
3436
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3437
+ stall_offline_updated_at: now,
3438
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3439
+ }
2792
3440
  };
2793
3441
  await local_db.payments.put(updated_payment);
2794
3442
  await add_to_sync_queue({
2795
3443
  action: "update",
2796
3444
  table: "payments",
2797
3445
  document_id: item.id,
2798
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2799
- stall_offline_id: existing.stall_offline_id,
3446
+ stall_offline_id: existing.metadata.stall_offline_id,
2800
3447
  data: updated_payment
2801
3448
  });
2802
3449
  updated_payments.push(updated_payment);
@@ -2819,8 +3466,7 @@ var bulk_delete12 = async (props) => {
2819
3466
  action: "delete",
2820
3467
  table: "payments",
2821
3468
  document_id: id,
2822
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2823
- stall_offline_id: existing.stall_offline_id,
3469
+ stall_offline_id: existing.metadata.stall_offline_id,
2824
3470
  data: { id }
2825
3471
  });
2826
3472
  await local_db.payments.delete(id);
@@ -2845,6 +3491,12 @@ var payments = {
2845
3491
  var list13 = async (props) => {
2846
3492
  try {
2847
3493
  const { sdk, query } = props;
3494
+ const queue_is_empty = await is_sync_queue_empty();
3495
+ if (!queue_is_empty) {
3496
+ throw new Error(
3497
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3498
+ );
3499
+ }
2848
3500
  const adapter = await sdk.adapter();
2849
3501
  if (!adapter) throw new Error("Adapter not found");
2850
3502
  const regions = await adapter.tax_regions.list({
@@ -2863,6 +3515,12 @@ var list13 = async (props) => {
2863
3515
  var retrieve13 = async (props) => {
2864
3516
  try {
2865
3517
  const { sdk, id } = props;
3518
+ const queue_is_empty = await is_sync_queue_empty();
3519
+ if (!queue_is_empty) {
3520
+ throw new Error(
3521
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3522
+ );
3523
+ }
2866
3524
  const adapter = await sdk.adapter();
2867
3525
  if (!adapter) throw new Error("Adapter not found");
2868
3526
  const region = await adapter.tax_regions.retrieve({
@@ -2885,11 +3543,11 @@ var create13 = async (props) => {
2885
3543
  id: offline_id,
2886
3544
  metadata: {
2887
3545
  ...data.metadata,
2888
- stall_offline_id: offline_id
2889
- },
2890
- stall_offline_id: offline_id,
2891
- stall_offline_created_at: now,
2892
- stall_offline_updated_at: now
3546
+ stall_offline_id: offline_id,
3547
+ stall_offline_created_at: now,
3548
+ stall_offline_updated_at: now,
3549
+ stall_offline_deleted_at: ""
3550
+ }
2893
3551
  };
2894
3552
  await local_db.tax_regions.add(local_region);
2895
3553
  await add_to_sync_queue({
@@ -2916,17 +3574,21 @@ var update13 = async (props) => {
2916
3574
  ...existing,
2917
3575
  ...data,
2918
3576
  id: existing.id,
2919
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2920
- stall_offline_id: existing.stall_offline_id,
2921
- stall_offline_updated_at: now
3577
+ metadata: {
3578
+ ...existing.metadata,
3579
+ ...data.metadata,
3580
+ stall_offline_id: existing.metadata.stall_offline_id,
3581
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3582
+ stall_offline_updated_at: now,
3583
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3584
+ }
2922
3585
  };
2923
3586
  await local_db.tax_regions.put(updated_region);
2924
3587
  await add_to_sync_queue({
2925
3588
  action: "update",
2926
3589
  table: "tax_regions",
2927
3590
  document_id: id,
2928
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2929
- stall_offline_id: existing.stall_offline_id,
3591
+ stall_offline_id: existing.metadata.stall_offline_id,
2930
3592
  data: updated_region
2931
3593
  });
2932
3594
  return updated_region;
@@ -2945,8 +3607,7 @@ var _delete13 = async (props) => {
2945
3607
  action: "delete",
2946
3608
  table: "tax_regions",
2947
3609
  document_id: id,
2948
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2949
- stall_offline_id: existing.stall_offline_id,
3610
+ stall_offline_id: existing.metadata.stall_offline_id,
2950
3611
  data: { id }
2951
3612
  });
2952
3613
  await local_db.tax_regions.delete(id);
@@ -2967,11 +3628,11 @@ var bulk_create13 = async (props) => {
2967
3628
  id: offline_id,
2968
3629
  metadata: {
2969
3630
  ...region.metadata,
2970
- stall_offline_id: offline_id
2971
- },
2972
- stall_offline_id: offline_id,
2973
- stall_offline_created_at: now,
2974
- stall_offline_updated_at: now
3631
+ stall_offline_id: offline_id,
3632
+ stall_offline_created_at: now,
3633
+ stall_offline_updated_at: now,
3634
+ stall_offline_deleted_at: ""
3635
+ }
2975
3636
  };
2976
3637
  await local_db.tax_regions.add(local_region);
2977
3638
  await add_to_sync_queue({
@@ -3005,17 +3666,21 @@ var bulk_update13 = async (props) => {
3005
3666
  ...existing,
3006
3667
  ...item.data,
3007
3668
  id: existing.id,
3008
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3009
- stall_offline_id: existing.stall_offline_id,
3010
- stall_offline_updated_at: now
3669
+ metadata: {
3670
+ ...existing.metadata,
3671
+ ...item.data.metadata,
3672
+ stall_offline_id: existing.metadata.stall_offline_id,
3673
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3674
+ stall_offline_updated_at: now,
3675
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3676
+ }
3011
3677
  };
3012
3678
  await local_db.tax_regions.put(updated_region);
3013
3679
  await add_to_sync_queue({
3014
3680
  action: "update",
3015
3681
  table: "tax_regions",
3016
3682
  document_id: item.id,
3017
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3018
- stall_offline_id: existing.stall_offline_id,
3683
+ stall_offline_id: existing.metadata.stall_offline_id,
3019
3684
  data: updated_region
3020
3685
  });
3021
3686
  updated_regions.push(updated_region);
@@ -3038,8 +3703,7 @@ var bulk_delete13 = async (props) => {
3038
3703
  action: "delete",
3039
3704
  table: "tax_regions",
3040
3705
  document_id: id,
3041
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3042
- stall_offline_id: existing.stall_offline_id,
3706
+ stall_offline_id: existing.metadata.stall_offline_id,
3043
3707
  data: { id }
3044
3708
  });
3045
3709
  await local_db.tax_regions.delete(id);
@@ -3064,6 +3728,12 @@ var tax_regions = {
3064
3728
  var list14 = async (props) => {
3065
3729
  try {
3066
3730
  const { sdk, query } = props;
3731
+ const queue_is_empty = await is_sync_queue_empty();
3732
+ if (!queue_is_empty) {
3733
+ throw new Error(
3734
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3735
+ );
3736
+ }
3067
3737
  const adapter = await sdk.adapter();
3068
3738
  if (!adapter) throw new Error("Adapter not found");
3069
3739
  const rates = await adapter.tax_rates.list({
@@ -3082,6 +3752,12 @@ var list14 = async (props) => {
3082
3752
  var retrieve14 = async (props) => {
3083
3753
  try {
3084
3754
  const { sdk, id } = props;
3755
+ const queue_is_empty = await is_sync_queue_empty();
3756
+ if (!queue_is_empty) {
3757
+ throw new Error(
3758
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3759
+ );
3760
+ }
3085
3761
  const adapter = await sdk.adapter();
3086
3762
  if (!adapter) throw new Error("Adapter not found");
3087
3763
  const rate = await adapter.tax_rates.retrieve({
@@ -3104,11 +3780,11 @@ var create14 = async (props) => {
3104
3780
  id: offline_id,
3105
3781
  metadata: {
3106
3782
  ...data.metadata,
3107
- stall_offline_id: offline_id
3108
- },
3109
- stall_offline_id: offline_id,
3110
- stall_offline_created_at: now,
3111
- stall_offline_updated_at: now
3783
+ stall_offline_id: offline_id,
3784
+ stall_offline_created_at: now,
3785
+ stall_offline_updated_at: now,
3786
+ stall_offline_deleted_at: ""
3787
+ }
3112
3788
  };
3113
3789
  await local_db.tax_rates.add(local_rate);
3114
3790
  await add_to_sync_queue({
@@ -3135,17 +3811,21 @@ var update14 = async (props) => {
3135
3811
  ...existing,
3136
3812
  ...data,
3137
3813
  id: existing.id,
3138
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3139
- stall_offline_id: existing.stall_offline_id,
3140
- stall_offline_updated_at: now
3814
+ metadata: {
3815
+ ...existing.metadata,
3816
+ ...data.metadata,
3817
+ stall_offline_id: existing.metadata.stall_offline_id,
3818
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3819
+ stall_offline_updated_at: now,
3820
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3821
+ }
3141
3822
  };
3142
3823
  await local_db.tax_rates.put(updated_rate);
3143
3824
  await add_to_sync_queue({
3144
3825
  action: "update",
3145
3826
  table: "tax_rates",
3146
3827
  document_id: id,
3147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3148
- stall_offline_id: existing.stall_offline_id,
3828
+ stall_offline_id: existing.metadata.stall_offline_id,
3149
3829
  data: updated_rate
3150
3830
  });
3151
3831
  return updated_rate;
@@ -3164,8 +3844,7 @@ var _delete14 = async (props) => {
3164
3844
  action: "delete",
3165
3845
  table: "tax_rates",
3166
3846
  document_id: id,
3167
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3168
- stall_offline_id: existing.stall_offline_id,
3847
+ stall_offline_id: existing.metadata.stall_offline_id,
3169
3848
  data: { id }
3170
3849
  });
3171
3850
  await local_db.tax_rates.delete(id);
@@ -3186,11 +3865,11 @@ var bulk_create14 = async (props) => {
3186
3865
  id: offline_id,
3187
3866
  metadata: {
3188
3867
  ...rate.metadata,
3189
- stall_offline_id: offline_id
3190
- },
3191
- stall_offline_id: offline_id,
3192
- stall_offline_created_at: now,
3193
- stall_offline_updated_at: now
3868
+ stall_offline_id: offline_id,
3869
+ stall_offline_created_at: now,
3870
+ stall_offline_updated_at: now,
3871
+ stall_offline_deleted_at: ""
3872
+ }
3194
3873
  };
3195
3874
  await local_db.tax_rates.add(local_rate);
3196
3875
  await add_to_sync_queue({
@@ -3222,17 +3901,21 @@ var bulk_update14 = async (props) => {
3222
3901
  ...existing,
3223
3902
  ...item.data,
3224
3903
  id: existing.id,
3225
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3226
- stall_offline_id: existing.stall_offline_id,
3227
- stall_offline_updated_at: now
3904
+ metadata: {
3905
+ ...existing.metadata,
3906
+ ...item.data.metadata,
3907
+ stall_offline_id: existing.metadata.stall_offline_id,
3908
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3909
+ stall_offline_updated_at: now,
3910
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3911
+ }
3228
3912
  };
3229
3913
  await local_db.tax_rates.put(updated_rate);
3230
3914
  await add_to_sync_queue({
3231
3915
  action: "update",
3232
3916
  table: "tax_rates",
3233
3917
  document_id: item.id,
3234
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3235
- stall_offline_id: existing.stall_offline_id,
3918
+ stall_offline_id: existing.metadata.stall_offline_id,
3236
3919
  data: updated_rate
3237
3920
  });
3238
3921
  updated_rates.push(updated_rate);
@@ -3255,8 +3938,7 @@ var bulk_delete14 = async (props) => {
3255
3938
  action: "delete",
3256
3939
  table: "tax_rates",
3257
3940
  document_id: id,
3258
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3259
- stall_offline_id: existing.stall_offline_id,
3941
+ stall_offline_id: existing.metadata.stall_offline_id,
3260
3942
  data: { id }
3261
3943
  });
3262
3944
  await local_db.tax_rates.delete(id);
@@ -3296,7 +3978,8 @@ var build_location = (data, offline_id, now) => {
3296
3978
  ...data.metadata,
3297
3979
  stall_offline_id: offline_id,
3298
3980
  stall_offline_created_at: now,
3299
- stall_offline_updated_at: now
3981
+ stall_offline_updated_at: now,
3982
+ stall_offline_deleted_at: ""
3300
3983
  }
3301
3984
  };
3302
3985
  };
@@ -3317,15 +4000,22 @@ var merge_location = (existing, updates, now) => {
3317
4000
  metadata: {
3318
4001
  ...existing.metadata,
3319
4002
  ...updates.metadata,
3320
- stall_offline_id: existing.metadata?.stall_offline_id,
3321
- stall_offline_created_at: existing.metadata?.stall_offline_created_at,
3322
- stall_offline_updated_at: now
4003
+ stall_offline_id: existing.metadata?.stall_offline_id || "",
4004
+ stall_offline_created_at: existing.metadata?.stall_offline_created_at || "",
4005
+ stall_offline_updated_at: now,
4006
+ stall_offline_deleted_at: existing.metadata?.stall_offline_deleted_at || ""
3323
4007
  }
3324
4008
  };
3325
4009
  };
3326
4010
  var list15 = async (props) => {
3327
4011
  try {
3328
4012
  const { sdk, query } = props;
4013
+ const queue_is_empty = await is_sync_queue_empty();
4014
+ if (!queue_is_empty) {
4015
+ throw new Error(
4016
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4017
+ );
4018
+ }
3329
4019
  const adapter = await sdk.adapter();
3330
4020
  if (!adapter) throw new Error("Adapter not found");
3331
4021
  const locations2 = await adapter.locations.list({
@@ -3344,6 +4034,12 @@ var list15 = async (props) => {
3344
4034
  var retrieve15 = async (props) => {
3345
4035
  try {
3346
4036
  const { sdk, id } = props;
4037
+ const queue_is_empty = await is_sync_queue_empty();
4038
+ if (!queue_is_empty) {
4039
+ throw new Error(
4040
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4041
+ );
4042
+ }
3347
4043
  const adapter = await sdk.adapter();
3348
4044
  if (!adapter) throw new Error("Adapter not found");
3349
4045
  const location = await adapter.locations.retrieve({
@@ -3473,657 +4169,269 @@ var bulk_delete15 = async (props) => {
3473
4169
  for (const id of ids) {
3474
4170
  const existing = await local_db.locations.get(id);
3475
4171
  if (!existing) {
3476
- console.warn(`Location with id ${id} not found locally, skipping`);
3477
- continue;
3478
- }
3479
- await add_to_sync_queue({
3480
- action: "delete",
3481
- table: "locations",
3482
- document_id: id,
3483
- stall_offline_id: existing.metadata?.stall_offline_id || id,
3484
- data: { id }
3485
- });
3486
- await local_db.locations.delete(id);
3487
- }
3488
- return;
3489
- } catch (error) {
3490
- throw error;
3491
- }
3492
- };
3493
- var locations = {
3494
- list: list15,
3495
- retrieve: retrieve15,
3496
- create: create15,
3497
- update: update15,
3498
- delete: _delete15,
3499
- bulk_create: bulk_create15,
3500
- bulk_update: bulk_update15,
3501
- bulk_delete: bulk_delete15
3502
- };
3503
-
3504
- // src/services/fulfillments.service.ts
3505
- var list16 = async (props) => {
3506
- try {
3507
- const { sdk, query } = props;
3508
- const adapter = await sdk.adapter();
3509
- if (!adapter) throw new Error("Adapter not found");
3510
- const fulfillments2 = await adapter.fulfillments.list({
3511
- connector_config: sdk.options.configuration,
3512
- query
3513
- });
3514
- await save_bulk_data({
3515
- table: "fulfillments",
3516
- data: fulfillments2
3517
- });
3518
- return fulfillments2;
3519
- } catch (error) {
3520
- throw error;
3521
- }
3522
- };
3523
- var retrieve16 = async (props) => {
3524
- try {
3525
- const { sdk, id } = props;
3526
- const adapter = await sdk.adapter();
3527
- if (!adapter) throw new Error("Adapter not found");
3528
- const fulfillment = await adapter.fulfillments.retrieve({
3529
- connector_config: sdk.options.configuration,
3530
- id
3531
- });
3532
- await local_db.fulfillments.put(fulfillment);
3533
- return fulfillment;
3534
- } catch (error) {
3535
- throw error;
3536
- }
3537
- };
3538
- var create16 = async (props) => {
3539
- try {
3540
- const { sdk, data } = props;
3541
- const offline_id = generate_offline_id("fulfillment");
3542
- const now = (/* @__PURE__ */ new Date()).toISOString();
3543
- const local_fulfillment = {
3544
- ...data,
3545
- id: offline_id,
3546
- metadata: {
3547
- ...data.metadata,
3548
- stall_offline_id: offline_id
3549
- },
3550
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3551
- stall_offline_id: offline_id,
3552
- stall_offline_created_at: now,
3553
- stall_offline_updated_at: now
3554
- };
3555
- await local_db.fulfillments.add(local_fulfillment);
3556
- await add_to_sync_queue({
3557
- action: "create",
3558
- table: "fulfillments",
3559
- document_id: offline_id,
3560
- stall_offline_id: offline_id,
3561
- data: local_fulfillment
3562
- });
3563
- return local_fulfillment;
3564
- } catch (error) {
3565
- throw error;
3566
- }
3567
- };
3568
- var update16 = async (props) => {
3569
- try {
3570
- const { sdk, id, data } = props;
3571
- const existing = await local_db.fulfillments.get(id);
3572
- if (!existing) {
3573
- throw new Error(`Fulfillment with id ${id} not found locally`);
3574
- }
3575
- const now = (/* @__PURE__ */ new Date()).toISOString();
3576
- const updated_fulfillment = {
3577
- ...existing,
3578
- ...data,
3579
- id: existing.id,
3580
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3581
- stall_offline_id: existing.stall_offline_id,
3582
- stall_offline_updated_at: now
3583
- };
3584
- await local_db.fulfillments.put(updated_fulfillment);
3585
- await add_to_sync_queue({
3586
- action: "update",
3587
- table: "fulfillments",
3588
- document_id: id,
3589
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3590
- stall_offline_id: existing.stall_offline_id,
3591
- data: updated_fulfillment
3592
- });
3593
- return updated_fulfillment;
3594
- } catch (error) {
3595
- throw error;
3596
- }
3597
- };
3598
- var _delete16 = async (props) => {
3599
- try {
3600
- const { sdk, id } = props;
3601
- const existing = await local_db.fulfillments.get(id);
3602
- if (!existing) {
3603
- throw new Error(`Fulfillment with id ${id} not found locally`);
3604
- }
3605
- await add_to_sync_queue({
3606
- action: "delete",
3607
- table: "fulfillments",
3608
- document_id: id,
3609
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3610
- stall_offline_id: existing.stall_offline_id,
3611
- data: { id }
3612
- });
3613
- await local_db.fulfillments.delete(id);
3614
- return;
3615
- } catch (error) {
3616
- throw error;
3617
- }
3618
- };
3619
- var bulk_create16 = async (props) => {
3620
- try {
3621
- const { sdk, data } = props;
3622
- const now = (/* @__PURE__ */ new Date()).toISOString();
3623
- const created_fulfillments = [];
3624
- for (const fulfillment of data) {
3625
- const offline_id = generate_offline_id("fulfillment");
3626
- const local_fulfillment = {
3627
- ...fulfillment,
3628
- id: offline_id,
3629
- metadata: {
3630
- ...fulfillment.metadata,
3631
- stall_offline_id: offline_id
3632
- },
3633
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3634
- stall_offline_id: offline_id,
3635
- stall_offline_created_at: now,
3636
- stall_offline_updated_at: now
3637
- };
3638
- await local_db.fulfillments.add(local_fulfillment);
3639
- await add_to_sync_queue({
3640
- action: "create",
3641
- table: "fulfillments",
3642
- document_id: offline_id,
3643
- stall_offline_id: offline_id,
3644
- data: local_fulfillment
3645
- });
3646
- created_fulfillments.push(local_fulfillment);
3647
- }
3648
- return created_fulfillments;
3649
- } catch (error) {
3650
- throw error;
3651
- }
3652
- };
3653
- var bulk_update16 = async (props) => {
3654
- try {
3655
- const { sdk, data } = props;
3656
- const now = (/* @__PURE__ */ new Date()).toISOString();
3657
- const updated_fulfillments = [];
3658
- for (const item of data) {
3659
- const existing = await local_db.fulfillments.get(item.id);
3660
- if (!existing) {
3661
- console.warn(
3662
- `Fulfillment with id ${item.id} not found locally, skipping`
3663
- );
3664
- continue;
3665
- }
3666
- const updated_fulfillment = {
3667
- ...existing,
3668
- ...item.data,
3669
- id: existing.id,
3670
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3671
- stall_offline_id: existing.stall_offline_id,
3672
- stall_offline_updated_at: now
3673
- };
3674
- await local_db.fulfillments.put(updated_fulfillment);
3675
- await add_to_sync_queue({
3676
- action: "update",
3677
- table: "fulfillments",
3678
- document_id: item.id,
3679
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3680
- stall_offline_id: existing.stall_offline_id,
3681
- data: updated_fulfillment
3682
- });
3683
- updated_fulfillments.push(updated_fulfillment);
3684
- }
3685
- return updated_fulfillments;
3686
- } catch (error) {
3687
- throw error;
3688
- }
3689
- };
3690
- var bulk_delete16 = async (props) => {
3691
- try {
3692
- const { sdk, ids } = props;
3693
- for (const id of ids) {
3694
- const existing = await local_db.fulfillments.get(id);
3695
- if (!existing) {
3696
- console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4172
+ console.warn(`Location with id ${id} not found locally, skipping`);
3697
4173
  continue;
3698
4174
  }
3699
4175
  await add_to_sync_queue({
3700
4176
  action: "delete",
3701
- table: "fulfillments",
4177
+ table: "locations",
3702
4178
  document_id: id,
3703
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3704
- stall_offline_id: existing.stall_offline_id,
4179
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3705
4180
  data: { id }
3706
4181
  });
3707
- await local_db.fulfillments.delete(id);
4182
+ await local_db.locations.delete(id);
3708
4183
  }
3709
4184
  return;
3710
4185
  } catch (error) {
3711
4186
  throw error;
3712
4187
  }
3713
4188
  };
3714
- var fulfillments = {
3715
- list: list16,
3716
- retrieve: retrieve16,
3717
- create: create16,
3718
- update: update16,
3719
- delete: _delete16,
3720
- bulk_create: bulk_create16,
3721
- bulk_update: bulk_update16,
3722
- bulk_delete: bulk_delete16
3723
- };
3724
-
3725
- // src/services/sync/sync-dependencies.ts
3726
- var SYNC_DEPENDENCY_LAYERS = {
3727
- 1: [
3728
- "tax_regions",
3729
- "tax_rates",
3730
- "categories",
3731
- "collections",
3732
- "locations",
3733
- "payment_providers",
3734
- "customers",
3735
- "promotions"
3736
- ],
3737
- 2: ["products"],
3738
- 3: ["variants", "inventory_levels"],
3739
- 4: ["orders", "order_notes"],
3740
- 5: ["payments", "refunds", "fulfillments"]
3741
- };
3742
- var get_entity_dependencies = (table) => {
3743
- const dependencies = {
3744
- // Layer 1: Independent
3745
- tax_regions: [],
3746
- tax_rates: ["tax_regions"],
3747
- categories: [],
3748
- collections: [],
3749
- locations: [],
3750
- payment_providers: [],
3751
- customers: [],
3752
- promotions: [],
3753
- // Layer 2: Product
3754
- products: ["categories", "collections"],
3755
- // Layer 3: Variants & Inventory
3756
- variants: ["products"],
3757
- inventory_levels: ["products", "variants"],
3758
- inventory_history: ["products", "variants"],
3759
- // Layer 4: Orders
3760
- orders: ["customers", "products", "variants", "locations"],
3761
- order_notes: ["orders"],
3762
- // Layer 5: Order-related
3763
- payments: ["orders", "payment_providers"],
3764
- refunds: ["orders", "payments"],
3765
- fulfillments: ["orders"],
3766
- // Tags
3767
- tags: ["products"],
3768
- // Fulfillment config
3769
- fulfillment_types: [],
3770
- fulfillment_providers: []
3771
- };
3772
- return dependencies[table] || [];
3773
- };
3774
- var get_sync_layer = (table) => {
3775
- for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
3776
- if (tables.includes(table)) {
3777
- return parseInt(layer);
3778
- }
3779
- }
3780
- return 99;
3781
- };
3782
- var sort_by_dependency_order = (items) => {
3783
- return items.sort((a, b) => {
3784
- const layer_a = get_sync_layer(a.table);
3785
- const layer_b = get_sync_layer(b.table);
3786
- if (layer_a !== layer_b) {
3787
- return layer_a - layer_b;
3788
- }
3789
- return 0;
3790
- });
3791
- };
3792
- var are_dependencies_satisfied = (table, synced_tables) => {
3793
- const dependencies = get_entity_dependencies(table);
3794
- return dependencies.every((dep) => synced_tables.has(dep));
4189
+ var locations = {
4190
+ list: list15,
4191
+ retrieve: retrieve15,
4192
+ create: create15,
4193
+ update: update15,
4194
+ delete: _delete15,
4195
+ bulk_create: bulk_create15,
4196
+ bulk_update: bulk_update15,
4197
+ bulk_delete: bulk_delete15
3795
4198
  };
3796
4199
 
3797
- // src/services/sync/sync.service.ts
3798
- var MAX_RETRIES = 3;
3799
- var replace_temporary_ids = async (props) => {
3800
- const { table, stall_offline_id, connector_id, local_data } = props;
4200
+ // src/services/fulfillments.service.ts
4201
+ var list16 = async (props) => {
3801
4202
  try {
3802
- const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
3803
- if (existing) {
3804
- await local_db[table].update(existing.id, {
3805
- id: connector_id
3806
- // Keep stall_offline_id for reference
3807
- });
4203
+ const { sdk, query } = props;
4204
+ const queue_is_empty = await is_sync_queue_empty();
4205
+ if (!queue_is_empty) {
4206
+ throw new Error(
4207
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4208
+ );
3808
4209
  }
3809
- await update_dependent_references({
3810
- table,
3811
- old_id: stall_offline_id,
3812
- new_id: connector_id
4210
+ const adapter = await sdk.adapter();
4211
+ if (!adapter) throw new Error("Adapter not found");
4212
+ const fulfillments2 = await adapter.fulfillments.list({
4213
+ connector_config: sdk.options.configuration,
4214
+ query
4215
+ });
4216
+ await save_bulk_data({
4217
+ table: "fulfillments",
4218
+ data: fulfillments2
3813
4219
  });
4220
+ return fulfillments2;
3814
4221
  } catch (error) {
3815
- console.error(`Error replacing temporary IDs for ${table}:`, error);
3816
4222
  throw error;
3817
4223
  }
3818
4224
  };
3819
- var update_dependent_references = async (props) => {
3820
- const { table, old_id, new_id } = props;
4225
+ var retrieve16 = async (props) => {
3821
4226
  try {
3822
- const reference_map = {
3823
- products: [
3824
- { table: "variants", field: "product_id" },
3825
- { table: "inventory_levels", field: "product_id" }
3826
- ],
3827
- variants: [{ table: "inventory_levels", field: "variant_id" }],
3828
- customers: [{ table: "orders", field: "customer_id" }],
3829
- orders: [
3830
- { table: "payments", field: "order_id" },
3831
- { table: "refunds", field: "order_id" },
3832
- { table: "order_notes", field: "order_id" },
3833
- { table: "fulfillments", field: "order_id" }
3834
- ],
3835
- payments: [{ table: "refunds", field: "payment_id" }],
3836
- locations: [{ table: "orders", field: "location_id" }],
3837
- categories: [{ table: "products", field: "category_id" }],
3838
- collections: [{ table: "products", field: "collection_id" }],
3839
- tax_regions: [{ table: "tax_rates", field: "region_id" }],
3840
- tax_rates: [],
3841
- tags: [],
3842
- inventory_levels: [],
3843
- inventory_history: [],
3844
- promotions: [],
3845
- order_notes: [],
3846
- refunds: [],
3847
- payment_providers: [],
3848
- fulfillments: [],
3849
- fulfillment_types: [],
3850
- fulfillment_providers: []
3851
- };
3852
- const references = reference_map[table] || [];
3853
- for (const ref of references) {
3854
- const records = await local_db[ref.table].toArray();
3855
- const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
3856
- ...record,
3857
- [ref.field]: new_id
3858
- }));
3859
- if (updates.length > 0) {
3860
- await local_db[ref.table].bulkPut(updates);
3861
- }
4227
+ const { sdk, id } = props;
4228
+ const queue_is_empty = await is_sync_queue_empty();
4229
+ if (!queue_is_empty) {
4230
+ throw new Error(
4231
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4232
+ );
3862
4233
  }
3863
- } catch (error) {
3864
- console.error(`Error updating dependent references for ${table}:`, error);
3865
- }
3866
- };
3867
- var sync_queue_item = async (props) => {
3868
- const { sdk, item, sync_batch_id } = props;
3869
- const start_time = Date.now();
3870
- try {
3871
4234
  const adapter = await sdk.adapter();
3872
- if (!adapter) {
3873
- throw new Error("Adapter not found");
3874
- }
3875
- const connector_config = sdk.options.configuration;
3876
- const table_module = adapter[item.table];
3877
- if (!table_module) {
3878
- throw new Error(`Module ${item.table} not found in adapter`);
3879
- }
3880
- let connector_id;
3881
- if (item.action === "create") {
3882
- const result = await table_module.create({
3883
- connector_config,
3884
- data: item.data
3885
- });
3886
- connector_id = result?.id;
3887
- if (connector_id) {
3888
- await replace_temporary_ids({
3889
- table: item.table,
3890
- stall_offline_id: item.stall_offline_id,
3891
- connector_id,
3892
- local_data: result
3893
- });
3894
- }
3895
- } else if (item.action === "update") {
3896
- const result = await table_module.update({
3897
- connector_config,
3898
- id: item.document_id,
3899
- data: item.data
3900
- });
3901
- connector_id = result?.id || item.document_id;
3902
- } else if (item.action === "delete") {
3903
- await table_module.delete({
3904
- connector_config,
3905
- id: item.document_id
3906
- });
3907
- connector_id = item.document_id;
3908
- }
3909
- const duration = Date.now() - start_time;
3910
- await add_sync_log({
3911
- sync_batch_id,
3912
- table: item.table,
3913
- action: item.action,
3914
- document_id: item.document_id,
3915
- stall_offline_id: item.stall_offline_id,
3916
- connector_id,
3917
- status: "success",
3918
- duration_ms: duration
3919
- });
3920
- await remove_from_sync_queue(item.id);
3921
- return { success: true, connector_id };
3922
- } catch (error) {
3923
- const duration = Date.now() - start_time;
3924
- console.error(`Error syncing item ${item.id}:`, error);
3925
- const current_retries = item.retry_count || 0;
3926
- if (current_retries < MAX_RETRIES) {
3927
- await update_sync_queue_status({
3928
- id: item.id,
3929
- status: "pending",
3930
- error: error.message,
3931
- retry_count: current_retries + 1
3932
- });
3933
- } else {
3934
- await update_sync_queue_status({
3935
- id: item.id,
3936
- status: "failed",
3937
- error: `Max retries exceeded: ${error.message}`
3938
- });
3939
- }
3940
- await add_sync_log({
3941
- sync_batch_id,
3942
- table: item.table,
3943
- action: item.action,
3944
- document_id: item.document_id,
3945
- stall_offline_id: item.stall_offline_id,
3946
- status: "failed",
3947
- error: error.message,
3948
- duration_ms: duration
4235
+ if (!adapter) throw new Error("Adapter not found");
4236
+ const fulfillment = await adapter.fulfillments.retrieve({
4237
+ connector_config: sdk.options.configuration,
4238
+ id
3949
4239
  });
3950
- return { success: false, error: error.message };
4240
+ await local_db.fulfillments.put(fulfillment);
4241
+ return fulfillment;
4242
+ } catch (error) {
4243
+ throw error;
3951
4244
  }
3952
4245
  };
3953
- var process_sync_queue = async (props) => {
3954
- const { sdk } = props;
3955
- const sync_batch_id = generate_uuid();
4246
+ var create16 = async (props) => {
3956
4247
  try {
3957
- const pending_items_by_table = await get_pending_sync_queue();
3958
- if (pending_items_by_table.size === 0) {
3959
- return {
3960
- sync_batch_id,
3961
- total: 0,
3962
- synced: 0,
3963
- failed: 0,
3964
- summary: []
3965
- };
3966
- }
3967
- let total_synced = 0;
3968
- let total_failed = 0;
3969
- const summary_data = [];
3970
- const all_items = [];
3971
- pending_items_by_table.forEach((items) => {
3972
- items.forEach((item) => {
3973
- all_items.push(item);
3974
- });
3975
- });
3976
- const sorted_items = sort_by_dependency_order(
3977
- all_items
3978
- );
3979
- const synced_tables = /* @__PURE__ */ new Set();
3980
- const items_to_retry = [];
3981
- for (const item of sorted_items) {
3982
- if (!are_dependencies_satisfied(item.table, synced_tables)) {
3983
- items_to_retry.push(item);
3984
- continue;
3985
- }
3986
- await update_sync_queue_status({
3987
- id: item.id,
3988
- status: "syncing"
3989
- });
3990
- const result = await sync_queue_item({
3991
- sdk,
3992
- item,
3993
- sync_batch_id
3994
- });
3995
- if (result.success) {
3996
- total_synced++;
3997
- if (!synced_tables.has(item.table)) {
3998
- synced_tables.add(item.table);
3999
- }
4000
- } else {
4001
- total_failed++;
4002
- }
4003
- const table_summary = summary_data.find((s) => s.table === item.table);
4004
- if (table_summary) {
4005
- if (result.success) {
4006
- table_summary.synced++;
4007
- } else {
4008
- table_summary.failed++;
4009
- }
4010
- } else {
4011
- summary_data.push({
4012
- table: item.table,
4013
- synced: result.success ? 1 : 0,
4014
- failed: result.success ? 0 : 1
4015
- });
4248
+ const { sdk, data } = props;
4249
+ const offline_id = generate_offline_id("fulfillment");
4250
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4251
+ const local_fulfillment = {
4252
+ ...data,
4253
+ id: offline_id,
4254
+ metadata: {
4255
+ ...data.metadata,
4256
+ stall_offline_id: offline_id,
4257
+ stall_offline_created_at: now,
4258
+ stall_offline_updated_at: now,
4259
+ stall_offline_deleted_at: ""
4016
4260
  }
4261
+ };
4262
+ await local_db.fulfillments.add(local_fulfillment);
4263
+ await add_to_sync_queue({
4264
+ action: "create",
4265
+ table: "fulfillments",
4266
+ document_id: offline_id,
4267
+ stall_offline_id: offline_id,
4268
+ data: local_fulfillment
4269
+ });
4270
+ return local_fulfillment;
4271
+ } catch (error) {
4272
+ throw error;
4273
+ }
4274
+ };
4275
+ var update16 = async (props) => {
4276
+ try {
4277
+ const { sdk, id, data } = props;
4278
+ const existing = await local_db.fulfillments.get(id);
4279
+ if (!existing) {
4280
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4017
4281
  }
4018
- for (const item of items_to_retry) {
4019
- await update_sync_queue_status({
4020
- id: item.id,
4021
- status: "syncing"
4022
- });
4023
- const result = await sync_queue_item({
4024
- sdk,
4025
- item,
4026
- sync_batch_id
4027
- });
4028
- if (result.success) {
4029
- total_synced++;
4030
- } else {
4031
- total_failed++;
4032
- }
4033
- const table_summary = summary_data.find((s) => s.table === item.table);
4034
- if (table_summary) {
4035
- if (result.success) {
4036
- table_summary.synced++;
4037
- } else {
4038
- table_summary.failed++;
4039
- }
4282
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4283
+ const updated_fulfillment = {
4284
+ ...existing,
4285
+ ...data,
4286
+ id: existing.id,
4287
+ metadata: {
4288
+ ...existing.metadata,
4289
+ ...data.metadata,
4290
+ stall_offline_id: existing.metadata.stall_offline_id,
4291
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4292
+ stall_offline_updated_at: now,
4293
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4040
4294
  }
4041
- }
4042
- return {
4043
- sync_batch_id,
4044
- total: all_items.length,
4045
- synced: total_synced,
4046
- failed: total_failed,
4047
- summary: summary_data
4048
4295
  };
4296
+ await local_db.fulfillments.put(updated_fulfillment);
4297
+ await add_to_sync_queue({
4298
+ action: "update",
4299
+ table: "fulfillments",
4300
+ document_id: id,
4301
+ stall_offline_id: existing.metadata.stall_offline_id,
4302
+ data: updated_fulfillment
4303
+ });
4304
+ return updated_fulfillment;
4049
4305
  } catch (error) {
4050
- console.error("Error processing sync queue:", error);
4051
- return {
4052
- sync_batch_id,
4053
- total: 0,
4054
- synced: 0,
4055
- failed: 0,
4056
- summary: []
4057
- };
4306
+ throw error;
4058
4307
  }
4059
4308
  };
4060
- var sync_interval = null;
4061
- var start_sync_service = async (props) => {
4062
- const { sdk, interval = 3e4 } = props;
4063
- if (sync_interval) {
4064
- console.warn("Sync service already running");
4309
+ var _delete16 = async (props) => {
4310
+ try {
4311
+ const { sdk, id } = props;
4312
+ const existing = await local_db.fulfillments.get(id);
4313
+ if (!existing) {
4314
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4315
+ }
4316
+ await add_to_sync_queue({
4317
+ action: "delete",
4318
+ table: "fulfillments",
4319
+ document_id: id,
4320
+ stall_offline_id: existing.metadata.stall_offline_id,
4321
+ data: { id }
4322
+ });
4323
+ await local_db.fulfillments.delete(id);
4065
4324
  return;
4325
+ } catch (error) {
4326
+ throw error;
4066
4327
  }
4067
- console.log(`Starting offline sync service with ${interval}ms interval`);
4068
- await process_sync_queue({ sdk });
4069
- sync_interval = setInterval(async () => {
4070
- const result = await process_sync_queue({ sdk });
4071
- if (result.total > 0) {
4072
- console.log(
4073
- `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
4074
- );
4075
- result.summary.forEach((s) => {
4076
- console.log(` ${s.table}: ${s.synced} synced, ${s.failed} failed`);
4328
+ };
4329
+ var bulk_create16 = async (props) => {
4330
+ try {
4331
+ const { sdk, data } = props;
4332
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4333
+ const created_fulfillments = [];
4334
+ for (const fulfillment of data) {
4335
+ const offline_id = generate_offline_id("fulfillment");
4336
+ const local_fulfillment = {
4337
+ ...fulfillment,
4338
+ id: offline_id,
4339
+ metadata: {
4340
+ ...fulfillment.metadata,
4341
+ stall_offline_id: offline_id,
4342
+ stall_offline_created_at: now,
4343
+ stall_offline_updated_at: now,
4344
+ stall_offline_deleted_at: ""
4345
+ }
4346
+ };
4347
+ await local_db.fulfillments.add(local_fulfillment);
4348
+ await add_to_sync_queue({
4349
+ action: "create",
4350
+ table: "fulfillments",
4351
+ document_id: offline_id,
4352
+ stall_offline_id: offline_id,
4353
+ data: local_fulfillment
4077
4354
  });
4355
+ created_fulfillments.push(local_fulfillment);
4078
4356
  }
4079
- }, interval);
4080
- };
4081
- var stop_sync_service = () => {
4082
- if (sync_interval) {
4083
- clearInterval(sync_interval);
4084
- sync_interval = null;
4085
- console.log("Offline sync service stopped");
4357
+ return created_fulfillments;
4358
+ } catch (error) {
4359
+ throw error;
4086
4360
  }
4087
4361
  };
4088
- var get_sync_stats = async () => {
4362
+ var bulk_update16 = async (props) => {
4089
4363
  try {
4090
- const all_items = await local_db.sync_queue.toArray();
4091
- const pending = all_items.filter((i) => i.status === "pending").length;
4092
- const syncing = all_items.filter((i) => i.status === "syncing").length;
4093
- const failed = all_items.filter((i) => i.status === "failed").length;
4094
- return {
4095
- pending,
4096
- syncing,
4097
- failed,
4098
- total: all_items.length
4099
- };
4364
+ const { sdk, data } = props;
4365
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4366
+ const updated_fulfillments = [];
4367
+ for (const item of data) {
4368
+ const existing = await local_db.fulfillments.get(item.id);
4369
+ if (!existing) {
4370
+ console.warn(
4371
+ `Fulfillment with id ${item.id} not found locally, skipping`
4372
+ );
4373
+ continue;
4374
+ }
4375
+ const updated_fulfillment = {
4376
+ ...existing,
4377
+ ...item.data,
4378
+ id: existing.id,
4379
+ metadata: {
4380
+ ...existing.metadata,
4381
+ ...item.data.metadata,
4382
+ stall_offline_id: existing.metadata.stall_offline_id,
4383
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4384
+ stall_offline_updated_at: now,
4385
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4386
+ }
4387
+ };
4388
+ await local_db.fulfillments.put(updated_fulfillment);
4389
+ await add_to_sync_queue({
4390
+ action: "update",
4391
+ table: "fulfillments",
4392
+ document_id: item.id,
4393
+ stall_offline_id: existing.metadata.stall_offline_id,
4394
+ data: updated_fulfillment
4395
+ });
4396
+ updated_fulfillments.push(updated_fulfillment);
4397
+ }
4398
+ return updated_fulfillments;
4100
4399
  } catch (error) {
4101
- console.error("Error getting sync stats:", error);
4102
- return { pending: 0, syncing: 0, failed: 0, total: 0 };
4400
+ throw error;
4103
4401
  }
4104
4402
  };
4105
- var trigger_sync = async (props) => {
4403
+ var bulk_delete16 = async (props) => {
4106
4404
  try {
4107
- const { sdk } = props;
4108
- return await process_sync_queue({ sdk });
4405
+ const { sdk, ids } = props;
4406
+ for (const id of ids) {
4407
+ const existing = await local_db.fulfillments.get(id);
4408
+ if (!existing) {
4409
+ console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4410
+ continue;
4411
+ }
4412
+ await add_to_sync_queue({
4413
+ action: "delete",
4414
+ table: "fulfillments",
4415
+ document_id: id,
4416
+ stall_offline_id: existing.metadata.stall_offline_id,
4417
+ data: { id }
4418
+ });
4419
+ await local_db.fulfillments.delete(id);
4420
+ }
4421
+ return;
4109
4422
  } catch (error) {
4110
- console.error("Error triggering sync:", error);
4111
- return {
4112
- sync_batch_id: generate_uuid(),
4113
- total: 0,
4114
- synced: 0,
4115
- failed: 0,
4116
- summary: []
4117
- };
4423
+ throw error;
4118
4424
  }
4119
4425
  };
4120
- var sync_service = {
4121
- process_sync_queue,
4122
- sync_queue_item,
4123
- start_sync_service,
4124
- stop_sync_service,
4125
- get_sync_stats,
4126
- trigger_sync
4426
+ var fulfillments = {
4427
+ list: list16,
4428
+ retrieve: retrieve16,
4429
+ create: create16,
4430
+ update: update16,
4431
+ delete: _delete16,
4432
+ bulk_create: bulk_create16,
4433
+ bulk_update: bulk_update16,
4434
+ bulk_delete: bulk_delete16
4127
4435
  };
4128
4436
  export {
4129
4437
  add_sync_log,
@@ -4139,6 +4447,9 @@ export {
4139
4447
  get_sync_logs_by_batch,
4140
4448
  initializeStallCore,
4141
4449
  inventory_levels,
4450
+ is_offline,
4451
+ is_online,
4452
+ is_sync_queue_empty,
4142
4453
  local_db,
4143
4454
  locations,
4144
4455
  order_notes,