@use-stall/core 0.0.12 → 0.0.13

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) => {
@@ -193,122 +163,590 @@ var cleanup_old_sync_logs = async (days = 30) => {
193
163
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
194
164
  };
195
165
 
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
- }
166
+ // src/services/sync/sync-dependencies.ts
167
+ var SYNC_DEPENDENCY_LAYERS = {
168
+ 1: [
169
+ "tax_regions",
170
+ "tax_rates",
171
+ "categories",
172
+ "collections",
173
+ "locations",
174
+ "payment_providers",
175
+ "customers",
176
+ "promotions"
177
+ ],
178
+ 2: ["products"],
179
+ 3: ["variants", "inventory_levels"],
180
+ 4: ["orders", "order_notes"],
181
+ 5: ["payments", "refunds", "fulfillments"]
214
182
  };
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;
228
- }
183
+ var get_entity_dependencies = (table) => {
184
+ const dependencies = {
185
+ // Layer 1: Independent
186
+ tax_regions: [],
187
+ tax_rates: ["tax_regions"],
188
+ categories: [],
189
+ collections: [],
190
+ locations: [],
191
+ payment_providers: [],
192
+ customers: [],
193
+ promotions: [],
194
+ // Layer 2: Product
195
+ products: ["categories", "collections"],
196
+ // Layer 3: Variants & Inventory
197
+ variants: ["products"],
198
+ inventory_levels: ["products", "variants"],
199
+ inventory_history: ["products", "variants"],
200
+ // Layer 4: Orders
201
+ orders: ["customers", "products", "variants", "locations"],
202
+ order_notes: ["orders"],
203
+ // Layer 5: Order-related
204
+ payments: ["orders", "payment_providers"],
205
+ refunds: ["orders", "payments"],
206
+ fulfillments: ["orders"],
207
+ // Tags
208
+ tags: ["products"],
209
+ // Fulfillment config
210
+ fulfillment_types: [],
211
+ fulfillment_providers: []
212
+ };
213
+ return dependencies[table] || [];
229
214
  };
230
- var create = async (props) => {
231
- 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
253
- });
254
- return local_product;
255
- } catch (error) {
256
- throw error;
215
+ var get_sync_layer = (table) => {
216
+ for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
217
+ if (tables.includes(table)) {
218
+ return parseInt(layer);
219
+ }
257
220
  }
221
+ return 99;
258
222
  };
259
- var update = async (props) => {
223
+ var sort_by_dependency_order = (items) => {
224
+ return items.sort((a, b) => {
225
+ const layer_a = get_sync_layer(a.table);
226
+ const layer_b = get_sync_layer(b.table);
227
+ if (layer_a !== layer_b) {
228
+ return layer_a - layer_b;
229
+ }
230
+ return 0;
231
+ });
232
+ };
233
+ var are_dependencies_satisfied = (table, synced_tables) => {
234
+ const dependencies = get_entity_dependencies(table);
235
+ return dependencies.every((dep) => synced_tables.has(dep));
236
+ };
237
+
238
+ // src/services/sync/sync.service.ts
239
+ var MAX_RETRIES = 3;
240
+ var SYNC_INTERVAL_MS = 2 * 60 * 1e3;
241
+ var sync_interval = null;
242
+ var is_syncing = false;
243
+ var replace_temporary_ids = async (props) => {
244
+ const { table, stall_offline_id, connector_id } = props;
260
245
  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`);
246
+ const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
247
+ if (existing) {
248
+ await local_db[table].update(existing.id, {
249
+ id: connector_id
250
+ });
265
251
  }
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
275
- };
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
252
+ await update_dependent_references({
253
+ table,
254
+ old_id: stall_offline_id,
255
+ new_id: connector_id
283
256
  });
284
- return updated_product;
285
257
  } catch (error) {
258
+ console.error(`Error replacing temporary IDs for ${table}:`, error);
286
259
  throw error;
287
260
  }
288
261
  };
289
- var _delete = async (props) => {
262
+ var update_dependent_references = async (props) => {
263
+ const { table, old_id, new_id } = props;
290
264
  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`);
265
+ const reference_map = {
266
+ products: [
267
+ { table: "variants", field: "product_id" },
268
+ { table: "inventory_levels", field: "product_id" }
269
+ ],
270
+ variants: [{ table: "inventory_levels", field: "variant_id" }],
271
+ customers: [{ table: "orders", field: "customer_id" }],
272
+ orders: [
273
+ { table: "payments", field: "order_id" },
274
+ { table: "refunds", field: "order_id" },
275
+ { table: "order_notes", field: "order_id" },
276
+ { table: "fulfillments", field: "order_id" }
277
+ ],
278
+ payments: [{ table: "refunds", field: "payment_id" }],
279
+ locations: [{ table: "orders", field: "location_id" }],
280
+ categories: [{ table: "products", field: "category_id" }],
281
+ collections: [{ table: "products", field: "collection_id" }],
282
+ tax_regions: [{ table: "tax_rates", field: "region_id" }],
283
+ tax_rates: [],
284
+ tags: [],
285
+ inventory_levels: [],
286
+ inventory_history: [],
287
+ promotions: [],
288
+ order_notes: [],
289
+ refunds: [],
290
+ payment_providers: [],
291
+ fulfillments: [],
292
+ fulfillment_types: [],
293
+ fulfillment_providers: []
294
+ };
295
+ const references = reference_map[table] || [];
296
+ for (const ref of references) {
297
+ const records = await local_db[ref.table].toArray();
298
+ const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
299
+ ...record,
300
+ [ref.field]: new_id
301
+ }));
302
+ if (updates.length > 0) {
303
+ await local_db[ref.table].bulkPut(updates);
304
+ }
295
305
  }
296
- await add_to_sync_queue({
297
- action: "delete",
298
- table: "products",
299
- document_id: id,
300
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
301
- stall_offline_id: existing.stall_offline_id,
302
- data: { id }
303
- });
304
- await local_db.products.delete(id);
305
- return;
306
306
  } catch (error) {
307
- throw error;
307
+ console.error(`Error updating dependent references for ${table}:`, error);
308
308
  }
309
309
  };
310
- var bulk_create = async (props) => {
311
- try {
310
+ var sync_queue_item = async (props) => {
311
+ const { sdk, item, sync_batch_id } = props;
312
+ const start_time = Date.now();
313
+ try {
314
+ const adapter = await sdk.adapter();
315
+ if (!adapter) {
316
+ throw new Error("Adapter not found");
317
+ }
318
+ const connector_config = sdk.options.configuration;
319
+ const table_module = adapter[item.table];
320
+ if (!table_module) {
321
+ throw new Error(`Module ${item.table} not found in adapter`);
322
+ }
323
+ let connector_id;
324
+ if (item.action === "create") {
325
+ const result = await table_module.create({
326
+ connector_config,
327
+ data: item.data
328
+ });
329
+ connector_id = result?.id;
330
+ if (connector_id) {
331
+ await replace_temporary_ids({
332
+ table: item.table,
333
+ stall_offline_id: item.stall_offline_id,
334
+ connector_id
335
+ });
336
+ }
337
+ } else if (item.action === "update") {
338
+ const result = await table_module.update({
339
+ connector_config,
340
+ id: item.document_id,
341
+ data: item.data
342
+ });
343
+ connector_id = result?.id || item.document_id;
344
+ } else if (item.action === "delete") {
345
+ await table_module.delete({
346
+ connector_config,
347
+ id: item.document_id
348
+ });
349
+ connector_id = item.document_id;
350
+ }
351
+ const duration = Date.now() - start_time;
352
+ await add_sync_log({
353
+ sync_batch_id,
354
+ table: item.table,
355
+ action: item.action,
356
+ document_id: item.document_id,
357
+ stall_offline_id: item.stall_offline_id,
358
+ connector_id,
359
+ status: "success",
360
+ duration_ms: duration
361
+ });
362
+ await remove_from_sync_queue(item.id);
363
+ return { success: true, connector_id };
364
+ } catch (error) {
365
+ const duration = Date.now() - start_time;
366
+ console.error(`Error syncing item ${item.id}:`, error);
367
+ const current_retries = item.retry_count || 0;
368
+ if (current_retries < MAX_RETRIES) {
369
+ await update_sync_queue_status({
370
+ id: item.id,
371
+ status: "pending",
372
+ error: error.message,
373
+ retry_count: current_retries + 1
374
+ });
375
+ } else {
376
+ await update_sync_queue_status({
377
+ id: item.id,
378
+ status: "failed",
379
+ error: `Max retries exceeded: ${error.message}`
380
+ });
381
+ }
382
+ await add_sync_log({
383
+ sync_batch_id,
384
+ table: item.table,
385
+ action: item.action,
386
+ document_id: item.document_id,
387
+ stall_offline_id: item.stall_offline_id,
388
+ status: "failed",
389
+ error: error.message,
390
+ duration_ms: duration
391
+ });
392
+ return { success: false, error: error.message };
393
+ }
394
+ };
395
+ var process_sync_queue = async (props) => {
396
+ const { sdk } = props;
397
+ const sync_batch_id = generate_uuid();
398
+ if (is_syncing) {
399
+ console.log("Sync already in progress, skipping...");
400
+ return {
401
+ sync_batch_id,
402
+ total: 0,
403
+ synced: 0,
404
+ failed: 0
405
+ };
406
+ }
407
+ is_syncing = true;
408
+ try {
409
+ const pending_items_by_table = await get_pending_sync_queue();
410
+ if (pending_items_by_table.size === 0) {
411
+ return {
412
+ sync_batch_id,
413
+ total: 0,
414
+ synced: 0,
415
+ failed: 0
416
+ };
417
+ }
418
+ let total_synced = 0;
419
+ let total_failed = 0;
420
+ const all_items = [];
421
+ pending_items_by_table.forEach((items) => {
422
+ items.forEach((item) => {
423
+ all_items.push(item);
424
+ });
425
+ });
426
+ const sorted_items = sort_by_dependency_order(
427
+ all_items
428
+ );
429
+ const synced_tables = /* @__PURE__ */ new Set();
430
+ const items_to_retry = [];
431
+ for (const item of sorted_items) {
432
+ if (!are_dependencies_satisfied(item.table, synced_tables)) {
433
+ items_to_retry.push(item);
434
+ continue;
435
+ }
436
+ await update_sync_queue_status({
437
+ id: item.id,
438
+ status: "syncing"
439
+ });
440
+ const result = await sync_queue_item({
441
+ sdk,
442
+ item,
443
+ sync_batch_id
444
+ });
445
+ if (result.success) {
446
+ total_synced++;
447
+ if (!synced_tables.has(item.table)) {
448
+ synced_tables.add(item.table);
449
+ }
450
+ } else {
451
+ total_failed++;
452
+ }
453
+ }
454
+ for (const item of items_to_retry) {
455
+ await update_sync_queue_status({
456
+ id: item.id,
457
+ status: "syncing"
458
+ });
459
+ const result = await sync_queue_item({
460
+ sdk,
461
+ item,
462
+ sync_batch_id
463
+ });
464
+ if (result.success) {
465
+ total_synced++;
466
+ } else {
467
+ total_failed++;
468
+ }
469
+ }
470
+ return {
471
+ sync_batch_id,
472
+ total: all_items.length,
473
+ synced: total_synced,
474
+ failed: total_failed
475
+ };
476
+ } catch (error) {
477
+ console.error("Error processing sync queue:", error);
478
+ return {
479
+ sync_batch_id,
480
+ total: 0,
481
+ synced: 0,
482
+ failed: 0
483
+ };
484
+ } finally {
485
+ is_syncing = false;
486
+ }
487
+ };
488
+ var get_sync_status = async () => {
489
+ try {
490
+ const all_items = await local_db.sync_queue.toArray();
491
+ const pending = all_items.filter((i) => i.status === "pending").length;
492
+ const syncing = all_items.filter((i) => i.status === "syncing").length;
493
+ const failed = all_items.filter((i) => i.status === "failed").length;
494
+ return {
495
+ pending,
496
+ syncing,
497
+ failed,
498
+ total: all_items.length,
499
+ is_sync_running: sync_interval !== null
500
+ };
501
+ } catch (error) {
502
+ console.error("Error getting sync status:", error);
503
+ return {
504
+ pending: 0,
505
+ syncing: 0,
506
+ failed: 0,
507
+ total: 0,
508
+ is_sync_running: false
509
+ };
510
+ }
511
+ };
512
+ var fix_sync_queue = async () => {
513
+ try {
514
+ const stuck_items = await local_db.sync_queue.where("status").equals("syncing").toArray();
515
+ for (const item of stuck_items) {
516
+ await update_sync_queue_status({
517
+ id: item.id,
518
+ status: "pending"
519
+ });
520
+ }
521
+ console.log(`Fixed ${stuck_items.length} stuck sync queue items`);
522
+ return {
523
+ fixed: stuck_items.length
524
+ };
525
+ } catch (error) {
526
+ console.error("Error fixing sync queue:", error);
527
+ return {
528
+ fixed: 0
529
+ };
530
+ }
531
+ };
532
+ var trigger_sync = async (props) => {
533
+ try {
534
+ const { sdk } = props;
535
+ return await process_sync_queue({ sdk });
536
+ } catch (error) {
537
+ console.error("Error triggering sync:", error);
538
+ return {
539
+ sync_batch_id: generate_uuid(),
540
+ total: 0,
541
+ synced: 0,
542
+ failed: 0
543
+ };
544
+ }
545
+ };
546
+ var start_sync = async (props) => {
547
+ const { sdk } = props;
548
+ if (sync_interval) {
549
+ console.warn("Background sync already running");
550
+ return;
551
+ }
552
+ console.log(
553
+ `Starting background sync service (${SYNC_INTERVAL_MS}ms interval)`
554
+ );
555
+ const initial_result = await process_sync_queue({ sdk });
556
+ if (initial_result.total > 0) {
557
+ console.log(
558
+ `Initial sync: ${initial_result.synced} synced, ${initial_result.failed} failed out of ${initial_result.total}`
559
+ );
560
+ }
561
+ sync_interval = setInterval(async () => {
562
+ const status = await get_sync_status();
563
+ if (status.pending > 0) {
564
+ const result = await process_sync_queue({ sdk });
565
+ if (result.total > 0) {
566
+ console.log(
567
+ `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
568
+ );
569
+ }
570
+ }
571
+ }, SYNC_INTERVAL_MS);
572
+ };
573
+ var stop_sync = () => {
574
+ if (sync_interval) {
575
+ clearInterval(sync_interval);
576
+ sync_interval = null;
577
+ console.log("Background sync service stopped");
578
+ } else {
579
+ console.warn("Background sync is not running");
580
+ }
581
+ };
582
+ var sync_service = {
583
+ get_sync_status,
584
+ fix_sync_queue,
585
+ trigger_sync,
586
+ start_sync,
587
+ stop_sync
588
+ };
589
+
590
+ // src/core/init.ts
591
+ var initializeStallCore = (options2) => {
592
+ const sdk = {
593
+ options: options2,
594
+ adapter: async () => getAdapter(sdk),
595
+ refreshAdapter: async () => getAdapter(sdk, true)
596
+ };
597
+ void sdk.adapter().then(() => {
598
+ void sync_service.start_sync({ sdk });
599
+ });
600
+ return sdk;
601
+ };
602
+ var getAdapter = async (sdk, force) => {
603
+ const date = Date.now();
604
+ let module_code;
605
+ const cache_key = "connector-module";
606
+ const cached = await local_db.connector_cache.get(cache_key);
607
+ if (cached && !force) {
608
+ module_code = cached.code;
609
+ } else {
610
+ const response = await fetch(sdk.options.connector_url, {
611
+ mode: "cors",
612
+ method: "GET"
613
+ });
614
+ if (!response.ok) {
615
+ throw new Error(`Failed to fetch connector: ${response.statusText}`);
616
+ }
617
+ module_code = await response.text();
618
+ await local_db.connector_cache.put({
619
+ id: cache_key,
620
+ code: module_code,
621
+ timestamp: date
622
+ });
623
+ }
624
+ const blob = new Blob([module_code], { type: "application/javascript" });
625
+ const blobUrl = URL.createObjectURL(blob);
626
+ const module = await import(blobUrl);
627
+ URL.revokeObjectURL(blobUrl);
628
+ return module;
629
+ };
630
+
631
+ // src/services/products.service.ts
632
+ var list = async (props) => {
633
+ try {
634
+ const { sdk, query } = props;
635
+ const adapter = await sdk.adapter();
636
+ if (!adapter) throw new Error("Adapter not found");
637
+ const products2 = await adapter.products.list({
638
+ connector_config: sdk.options.configuration,
639
+ query
640
+ });
641
+ await save_bulk_data({
642
+ table: "products",
643
+ data: products2
644
+ });
645
+ return products2;
646
+ } catch (error) {
647
+ throw error;
648
+ }
649
+ };
650
+ var retrieve = async (props) => {
651
+ try {
652
+ const { sdk, id } = props;
653
+ const adapter = await sdk.adapter();
654
+ if (!adapter) throw new Error("Adapter not found");
655
+ const product = await adapter.products.retrieve({
656
+ connector_config: sdk.options.configuration,
657
+ id
658
+ });
659
+ await local_db.products.put(product);
660
+ return product;
661
+ } catch (error) {
662
+ throw error;
663
+ }
664
+ };
665
+ var create = async (props) => {
666
+ try {
667
+ const { sdk, data } = props;
668
+ const offline_id = generate_offline_id("product");
669
+ const now = (/* @__PURE__ */ new Date()).toISOString();
670
+ const local_product = {
671
+ ...data,
672
+ id: offline_id,
673
+ metadata: {
674
+ ...data.metadata,
675
+ stall_offline_id: offline_id,
676
+ stall_offline_created_at: now,
677
+ stall_offline_updated_at: now,
678
+ stall_offline_deleted_at: ""
679
+ }
680
+ };
681
+ await local_db.products.add(local_product);
682
+ await add_to_sync_queue({
683
+ action: "create",
684
+ table: "products",
685
+ document_id: offline_id,
686
+ stall_offline_id: offline_id,
687
+ data: local_product
688
+ });
689
+ return local_product;
690
+ } catch (error) {
691
+ throw error;
692
+ }
693
+ };
694
+ var update = async (props) => {
695
+ try {
696
+ const { sdk, id, data } = props;
697
+ const existing = await local_db.products.get(id);
698
+ if (!existing) {
699
+ throw new Error(`Product with id ${id} not found locally`);
700
+ }
701
+ const now = (/* @__PURE__ */ new Date()).toISOString();
702
+ const updated_product = {
703
+ ...existing,
704
+ ...data,
705
+ id: existing.id,
706
+ metadata: {
707
+ ...existing.metadata,
708
+ ...data.metadata,
709
+ stall_offline_id: existing.metadata.stall_offline_id,
710
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
711
+ stall_offline_updated_at: now,
712
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
713
+ }
714
+ };
715
+ await local_db.products.put(updated_product);
716
+ await add_to_sync_queue({
717
+ action: "update",
718
+ table: "products",
719
+ document_id: id,
720
+ stall_offline_id: existing.metadata.stall_offline_id,
721
+ data: updated_product
722
+ });
723
+ return updated_product;
724
+ } catch (error) {
725
+ throw error;
726
+ }
727
+ };
728
+ var _delete = async (props) => {
729
+ try {
730
+ const { sdk, id } = props;
731
+ const existing = await local_db.products.get(id);
732
+ if (!existing) {
733
+ throw new Error(`Product with id ${id} not found locally`);
734
+ }
735
+ await add_to_sync_queue({
736
+ action: "delete",
737
+ table: "products",
738
+ document_id: id,
739
+ stall_offline_id: existing.metadata.stall_offline_id,
740
+ data: { id }
741
+ });
742
+ await local_db.products.delete(id);
743
+ return;
744
+ } catch (error) {
745
+ throw error;
746
+ }
747
+ };
748
+ var bulk_create = async (props) => {
749
+ try {
312
750
  const { sdk, data } = props;
313
751
  const now = (/* @__PURE__ */ new Date()).toISOString();
314
752
  const created_products = [];
@@ -319,11 +757,11 @@ var bulk_create = async (props) => {
319
757
  id: offline_id,
320
758
  metadata: {
321
759
  ...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
760
+ stall_offline_id: offline_id,
761
+ stall_offline_created_at: now,
762
+ stall_offline_updated_at: now,
763
+ stall_offline_deleted_at: ""
764
+ }
327
765
  };
328
766
  await local_db.products.add(local_product);
329
767
  await add_to_sync_queue({
@@ -355,17 +793,21 @@ var bulk_update = async (props) => {
355
793
  ...existing,
356
794
  ...item.data,
357
795
  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
796
+ metadata: {
797
+ ...existing.metadata,
798
+ ...item.data.metadata,
799
+ stall_offline_id: existing.metadata.stall_offline_id,
800
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
801
+ stall_offline_updated_at: now,
802
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
803
+ }
362
804
  };
363
805
  await local_db.products.put(updated_product);
364
806
  await add_to_sync_queue({
365
807
  action: "update",
366
808
  table: "products",
367
809
  document_id: item.id,
368
- stall_offline_id: existing.stall_offline_id,
810
+ stall_offline_id: existing.metadata.stall_offline_id,
369
811
  data: updated_product
370
812
  });
371
813
  updated_products.push(updated_product);
@@ -388,8 +830,7 @@ var bulk_delete = async (props) => {
388
830
  action: "delete",
389
831
  table: "products",
390
832
  document_id: id,
391
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
- stall_offline_id: existing.stall_offline_id,
833
+ stall_offline_id: existing.metadata.stall_offline_id,
393
834
  data: { id }
394
835
  });
395
836
  await local_db.products.delete(id);
@@ -458,11 +899,11 @@ var create2 = async (props) => {
458
899
  id: offline_id,
459
900
  metadata: {
460
901
  ...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
902
+ stall_offline_id: offline_id,
903
+ stall_offline_created_at: now,
904
+ stall_offline_updated_at: now,
905
+ stall_offline_deleted_at: ""
906
+ }
466
907
  };
467
908
  await local_db.orders.add(local_order);
468
909
  await add_to_sync_queue({
@@ -491,17 +932,21 @@ var update2 = async (props) => {
491
932
  ...existing,
492
933
  ...data,
493
934
  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
935
+ metadata: {
936
+ ...existing.metadata,
937
+ ...data.metadata,
938
+ stall_offline_id: existing.metadata.stall_offline_id,
939
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
940
+ stall_offline_updated_at: now,
941
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
942
+ }
497
943
  };
498
944
  await local_db.orders.put(updated_order);
499
945
  await add_to_sync_queue({
500
946
  action: "update",
501
947
  table: "orders",
502
948
  document_id: id,
503
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
504
- stall_offline_id: existing.stall_offline_id,
949
+ stall_offline_id: existing.metadata.stall_offline_id,
505
950
  data: updated_order
506
951
  });
507
952
  return updated_order;
@@ -522,8 +967,7 @@ var _delete2 = async (props) => {
522
967
  action: "delete",
523
968
  table: "orders",
524
969
  document_id: id,
525
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
526
- stall_offline_id: existing.stall_offline_id,
970
+ stall_offline_id: existing.metadata.stall_offline_id,
527
971
  data: { id }
528
972
  });
529
973
  await local_db.orders.delete(id);
@@ -546,11 +990,11 @@ var bulk_create2 = async (props) => {
546
990
  id: offline_id,
547
991
  metadata: {
548
992
  ...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
993
+ stall_offline_id: offline_id,
994
+ stall_offline_created_at: now,
995
+ stall_offline_updated_at: now,
996
+ stall_offline_deleted_at: ""
997
+ }
554
998
  };
555
999
  await local_db.orders.add(local_order);
556
1000
  await add_to_sync_queue({
@@ -584,17 +1028,21 @@ var bulk_update2 = async (props) => {
584
1028
  ...existing,
585
1029
  ...item.data,
586
1030
  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
1031
+ metadata: {
1032
+ ...existing.metadata,
1033
+ ...item.data.metadata,
1034
+ stall_offline_id: existing.metadata.stall_offline_id,
1035
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1036
+ stall_offline_updated_at: now,
1037
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1038
+ }
590
1039
  };
591
1040
  await local_db.orders.put(updated_order);
592
1041
  await add_to_sync_queue({
593
1042
  action: "update",
594
1043
  table: "orders",
595
1044
  document_id: item.id,
596
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
597
- stall_offline_id: existing.stall_offline_id,
1045
+ stall_offline_id: existing.metadata.stall_offline_id,
598
1046
  data: updated_order
599
1047
  });
600
1048
  updated_orders.push(updated_order);
@@ -619,8 +1067,7 @@ var bulk_delete2 = async (props) => {
619
1067
  action: "delete",
620
1068
  table: "orders",
621
1069
  document_id: id,
622
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
623
- stall_offline_id: existing.stall_offline_id,
1070
+ stall_offline_id: existing.metadata.stall_offline_id,
624
1071
  data: { id }
625
1072
  });
626
1073
  await local_db.orders.delete(id);
@@ -687,11 +1134,11 @@ var create3 = async (props) => {
687
1134
  id: offline_id,
688
1135
  metadata: {
689
1136
  ...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
1137
+ stall_offline_id: offline_id,
1138
+ stall_offline_created_at: now,
1139
+ stall_offline_updated_at: now,
1140
+ stall_offline_deleted_at: ""
1141
+ }
695
1142
  };
696
1143
  await local_db.customers.add(local_customer);
697
1144
  await add_to_sync_queue({
@@ -718,17 +1165,21 @@ var update3 = async (props) => {
718
1165
  ...existing,
719
1166
  ...data,
720
1167
  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
1168
+ metadata: {
1169
+ ...existing.metadata,
1170
+ ...data.metadata,
1171
+ stall_offline_id: existing.metadata.stall_offline_id,
1172
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1173
+ stall_offline_updated_at: now,
1174
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1175
+ }
724
1176
  };
725
1177
  await local_db.customers.put(updated_customer);
726
1178
  await add_to_sync_queue({
727
1179
  action: "update",
728
1180
  table: "customers",
729
1181
  document_id: id,
730
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
731
- stall_offline_id: existing.stall_offline_id,
1182
+ stall_offline_id: existing.metadata.stall_offline_id,
732
1183
  data: updated_customer
733
1184
  });
734
1185
  return updated_customer;
@@ -747,8 +1198,7 @@ var _delete3 = async (props) => {
747
1198
  action: "delete",
748
1199
  table: "customers",
749
1200
  document_id: id,
750
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
751
- stall_offline_id: existing.stall_offline_id,
1201
+ stall_offline_id: existing.metadata.stall_offline_id,
752
1202
  data: { id }
753
1203
  });
754
1204
  await local_db.customers.delete(id);
@@ -769,11 +1219,11 @@ var bulk_create3 = async (props) => {
769
1219
  id: offline_id,
770
1220
  metadata: {
771
1221
  ...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
1222
+ stall_offline_id: offline_id,
1223
+ stall_offline_created_at: now,
1224
+ stall_offline_updated_at: now,
1225
+ stall_offline_deleted_at: ""
1226
+ }
777
1227
  };
778
1228
  await local_db.customers.add(local_customer);
779
1229
  await add_to_sync_queue({
@@ -805,17 +1255,21 @@ var bulk_update3 = async (props) => {
805
1255
  ...existing,
806
1256
  ...item.data,
807
1257
  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
1258
+ metadata: {
1259
+ ...existing.metadata,
1260
+ ...item.data.metadata,
1261
+ stall_offline_id: existing.metadata.stall_offline_id,
1262
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1263
+ stall_offline_updated_at: now,
1264
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1265
+ }
811
1266
  };
812
1267
  await local_db.customers.put(updated_customer);
813
1268
  await add_to_sync_queue({
814
1269
  action: "update",
815
1270
  table: "customers",
816
1271
  document_id: item.id,
817
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
818
- stall_offline_id: existing.stall_offline_id,
1272
+ stall_offline_id: existing.metadata.stall_offline_id,
819
1273
  data: updated_customer
820
1274
  });
821
1275
  updated_customers.push(updated_customer);
@@ -838,8 +1292,7 @@ var bulk_delete3 = async (props) => {
838
1292
  action: "delete",
839
1293
  table: "customers",
840
1294
  document_id: id,
841
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
842
- stall_offline_id: existing.stall_offline_id,
1295
+ stall_offline_id: existing.metadata.stall_offline_id,
843
1296
  data: { id }
844
1297
  });
845
1298
  await local_db.customers.delete(id);
@@ -904,11 +1357,11 @@ var create4 = async (props) => {
904
1357
  id: offline_id,
905
1358
  metadata: {
906
1359
  ...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
1360
+ stall_offline_id: offline_id,
1361
+ stall_offline_created_at: now,
1362
+ stall_offline_updated_at: now,
1363
+ stall_offline_deleted_at: ""
1364
+ }
912
1365
  };
913
1366
  await local_db.collections.add(local_collection);
914
1367
  await add_to_sync_queue({
@@ -935,17 +1388,21 @@ var update4 = async (props) => {
935
1388
  ...existing,
936
1389
  ...data,
937
1390
  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
1391
+ metadata: {
1392
+ ...existing.metadata,
1393
+ ...data.metadata,
1394
+ stall_offline_id: existing.metadata.stall_offline_id,
1395
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1396
+ stall_offline_updated_at: now,
1397
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1398
+ }
941
1399
  };
942
1400
  await local_db.collections.put(updated_collection);
943
1401
  await add_to_sync_queue({
944
1402
  action: "update",
945
1403
  table: "collections",
946
1404
  document_id: id,
947
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
948
- stall_offline_id: existing.stall_offline_id,
1405
+ stall_offline_id: existing.metadata.stall_offline_id,
949
1406
  data: updated_collection
950
1407
  });
951
1408
  return updated_collection;
@@ -964,8 +1421,7 @@ var _delete4 = async (props) => {
964
1421
  action: "delete",
965
1422
  table: "collections",
966
1423
  document_id: id,
967
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
968
- stall_offline_id: existing.stall_offline_id,
1424
+ stall_offline_id: existing.metadata.stall_offline_id,
969
1425
  data: { id }
970
1426
  });
971
1427
  await local_db.collections.delete(id);
@@ -986,11 +1442,11 @@ var bulk_create4 = async (props) => {
986
1442
  id: offline_id,
987
1443
  metadata: {
988
1444
  ...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
1445
+ stall_offline_id: offline_id,
1446
+ stall_offline_created_at: now,
1447
+ stall_offline_updated_at: now,
1448
+ stall_offline_deleted_at: ""
1449
+ }
994
1450
  };
995
1451
  await local_db.collections.add(local_collection);
996
1452
  await add_to_sync_queue({
@@ -1024,17 +1480,21 @@ var bulk_update4 = async (props) => {
1024
1480
  ...existing,
1025
1481
  ...item.data,
1026
1482
  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
1483
+ metadata: {
1484
+ ...existing.metadata,
1485
+ ...item.data.metadata,
1486
+ stall_offline_id: existing.metadata.stall_offline_id,
1487
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1488
+ stall_offline_updated_at: now,
1489
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1490
+ }
1030
1491
  };
1031
1492
  await local_db.collections.put(updated_collection);
1032
1493
  await add_to_sync_queue({
1033
1494
  action: "update",
1034
1495
  table: "collections",
1035
1496
  document_id: item.id,
1036
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1037
- stall_offline_id: existing.stall_offline_id,
1497
+ stall_offline_id: existing.metadata.stall_offline_id,
1038
1498
  data: updated_collection
1039
1499
  });
1040
1500
  updated_collections.push(updated_collection);
@@ -1057,8 +1517,7 @@ var bulk_delete4 = async (props) => {
1057
1517
  action: "delete",
1058
1518
  table: "collections",
1059
1519
  document_id: id,
1060
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1061
- stall_offline_id: existing.stall_offline_id,
1520
+ stall_offline_id: existing.metadata.stall_offline_id,
1062
1521
  data: { id }
1063
1522
  });
1064
1523
  await local_db.collections.delete(id);
@@ -1123,11 +1582,11 @@ var create5 = async (props) => {
1123
1582
  id: offline_id,
1124
1583
  metadata: {
1125
1584
  ...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
1585
+ stall_offline_id: offline_id,
1586
+ stall_offline_created_at: now,
1587
+ stall_offline_updated_at: now,
1588
+ stall_offline_deleted_at: ""
1589
+ }
1131
1590
  };
1132
1591
  await local_db.categories.add(local_category);
1133
1592
  await add_to_sync_queue({
@@ -1154,17 +1613,21 @@ var update5 = async (props) => {
1154
1613
  ...existing,
1155
1614
  ...data,
1156
1615
  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
1616
+ metadata: {
1617
+ ...existing.metadata,
1618
+ ...data.metadata,
1619
+ stall_offline_id: existing.metadata.stall_offline_id,
1620
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1621
+ stall_offline_updated_at: now,
1622
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1623
+ }
1160
1624
  };
1161
1625
  await local_db.categories.put(updated_category);
1162
1626
  await add_to_sync_queue({
1163
1627
  action: "update",
1164
1628
  table: "categories",
1165
1629
  document_id: id,
1166
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1167
- stall_offline_id: existing.stall_offline_id,
1630
+ stall_offline_id: existing.metadata.stall_offline_id,
1168
1631
  data: updated_category
1169
1632
  });
1170
1633
  return updated_category;
@@ -1183,8 +1646,7 @@ var _delete5 = async (props) => {
1183
1646
  action: "delete",
1184
1647
  table: "categories",
1185
1648
  document_id: id,
1186
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1187
- stall_offline_id: existing.stall_offline_id,
1649
+ stall_offline_id: existing.metadata.stall_offline_id,
1188
1650
  data: { id }
1189
1651
  });
1190
1652
  await local_db.categories.delete(id);
@@ -1205,11 +1667,11 @@ var bulk_create5 = async (props) => {
1205
1667
  id: offline_id,
1206
1668
  metadata: {
1207
1669
  ...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
1670
+ stall_offline_id: offline_id,
1671
+ stall_offline_created_at: now,
1672
+ stall_offline_updated_at: now,
1673
+ stall_offline_deleted_at: ""
1674
+ }
1213
1675
  };
1214
1676
  await local_db.categories.add(local_category);
1215
1677
  await add_to_sync_queue({
@@ -1241,17 +1703,21 @@ var bulk_update5 = async (props) => {
1241
1703
  ...existing,
1242
1704
  ...item.data,
1243
1705
  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
1706
+ metadata: {
1707
+ ...existing.metadata,
1708
+ ...item.data.metadata,
1709
+ stall_offline_id: existing.metadata.stall_offline_id,
1710
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1711
+ stall_offline_updated_at: now,
1712
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1713
+ }
1247
1714
  };
1248
1715
  await local_db.categories.put(updated_category);
1249
1716
  await add_to_sync_queue({
1250
1717
  action: "update",
1251
1718
  table: "categories",
1252
1719
  document_id: item.id,
1253
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1254
- stall_offline_id: existing.stall_offline_id,
1720
+ stall_offline_id: existing.metadata.stall_offline_id,
1255
1721
  data: updated_category
1256
1722
  });
1257
1723
  updated_categories.push(updated_category);
@@ -1274,8 +1740,7 @@ var bulk_delete5 = async (props) => {
1274
1740
  action: "delete",
1275
1741
  table: "categories",
1276
1742
  document_id: id,
1277
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1278
- stall_offline_id: existing.stall_offline_id,
1743
+ stall_offline_id: existing.metadata.stall_offline_id,
1279
1744
  data: { id }
1280
1745
  });
1281
1746
  await local_db.categories.delete(id);
@@ -1340,11 +1805,11 @@ var create6 = async (props) => {
1340
1805
  id: offline_id,
1341
1806
  metadata: {
1342
1807
  ...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
1808
+ stall_offline_id: offline_id,
1809
+ stall_offline_created_at: now,
1810
+ stall_offline_updated_at: now,
1811
+ stall_offline_deleted_at: ""
1812
+ }
1348
1813
  };
1349
1814
  await local_db.variants.add(local_variant);
1350
1815
  await add_to_sync_queue({
@@ -1371,17 +1836,21 @@ var update6 = async (props) => {
1371
1836
  ...existing,
1372
1837
  ...data,
1373
1838
  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
1839
+ metadata: {
1840
+ ...existing.metadata,
1841
+ ...data.metadata,
1842
+ stall_offline_id: existing.metadata.stall_offline_id,
1843
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1844
+ stall_offline_updated_at: now,
1845
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1846
+ }
1377
1847
  };
1378
1848
  await local_db.variants.put(updated_variant);
1379
1849
  await add_to_sync_queue({
1380
1850
  action: "update",
1381
1851
  table: "variants",
1382
1852
  document_id: id,
1383
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1384
- stall_offline_id: existing.stall_offline_id,
1853
+ stall_offline_id: existing.metadata.stall_offline_id,
1385
1854
  data: updated_variant
1386
1855
  });
1387
1856
  return updated_variant;
@@ -1400,8 +1869,7 @@ var _delete6 = async (props) => {
1400
1869
  action: "delete",
1401
1870
  table: "variants",
1402
1871
  document_id: id,
1403
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1404
- stall_offline_id: existing.stall_offline_id,
1872
+ stall_offline_id: existing.metadata.stall_offline_id,
1405
1873
  data: { id }
1406
1874
  });
1407
1875
  await local_db.variants.delete(id);
@@ -1422,11 +1890,11 @@ var bulk_create6 = async (props) => {
1422
1890
  id: offline_id,
1423
1891
  metadata: {
1424
1892
  ...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
1893
+ stall_offline_id: offline_id,
1894
+ stall_offline_created_at: now,
1895
+ stall_offline_updated_at: now,
1896
+ stall_offline_deleted_at: ""
1897
+ }
1430
1898
  };
1431
1899
  await local_db.variants.add(local_variant);
1432
1900
  await add_to_sync_queue({
@@ -1458,17 +1926,21 @@ var bulk_update6 = async (props) => {
1458
1926
  ...existing,
1459
1927
  ...item.data,
1460
1928
  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
1929
+ metadata: {
1930
+ ...existing.metadata,
1931
+ ...item.data.metadata,
1932
+ stall_offline_id: existing.metadata.stall_offline_id,
1933
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1934
+ stall_offline_updated_at: now,
1935
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1936
+ }
1464
1937
  };
1465
1938
  await local_db.variants.put(updated_variant);
1466
1939
  await add_to_sync_queue({
1467
1940
  action: "update",
1468
1941
  table: "variants",
1469
1942
  document_id: item.id,
1470
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1471
- stall_offline_id: existing.stall_offline_id,
1943
+ stall_offline_id: existing.metadata.stall_offline_id,
1472
1944
  data: updated_variant
1473
1945
  });
1474
1946
  updated_variants.push(updated_variant);
@@ -1491,8 +1963,7 @@ var bulk_delete6 = async (props) => {
1491
1963
  action: "delete",
1492
1964
  table: "variants",
1493
1965
  document_id: id,
1494
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1495
- stall_offline_id: existing.stall_offline_id,
1966
+ stall_offline_id: existing.metadata.stall_offline_id,
1496
1967
  data: { id }
1497
1968
  });
1498
1969
  await local_db.variants.delete(id);
@@ -1557,12 +2028,11 @@ var create7 = async (props) => {
1557
2028
  id: offline_id,
1558
2029
  metadata: {
1559
2030
  ...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
2031
+ stall_offline_id: offline_id,
2032
+ stall_offline_created_at: now,
2033
+ stall_offline_updated_at: now,
2034
+ stall_offline_deleted_at: ""
2035
+ }
1566
2036
  };
1567
2037
  await local_db.inventory_levels.add(local_inventory_level);
1568
2038
  await add_to_sync_queue({
@@ -1589,17 +2059,21 @@ var update7 = async (props) => {
1589
2059
  ...existing,
1590
2060
  ...data,
1591
2061
  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
2062
+ metadata: {
2063
+ ...existing.metadata,
2064
+ ...data.metadata,
2065
+ stall_offline_id: existing.metadata.stall_offline_id,
2066
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2067
+ stall_offline_updated_at: now,
2068
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2069
+ }
1595
2070
  };
1596
2071
  await local_db.inventory_levels.put(updated_inventory_level);
1597
2072
  await add_to_sync_queue({
1598
2073
  action: "update",
1599
2074
  table: "inventory_levels",
1600
2075
  document_id: id,
1601
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1602
- stall_offline_id: existing.stall_offline_id,
2076
+ stall_offline_id: existing.metadata.stall_offline_id,
1603
2077
  data: updated_inventory_level
1604
2078
  });
1605
2079
  return updated_inventory_level;
@@ -1618,8 +2092,7 @@ var _delete7 = async (props) => {
1618
2092
  action: "delete",
1619
2093
  table: "inventory_levels",
1620
2094
  document_id: id,
1621
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1622
- stall_offline_id: existing.stall_offline_id,
2095
+ stall_offline_id: existing.metadata.stall_offline_id,
1623
2096
  data: { id }
1624
2097
  });
1625
2098
  await local_db.inventory_levels.delete(id);
@@ -1640,12 +2113,11 @@ var bulk_create7 = async (props) => {
1640
2113
  id: offline_id,
1641
2114
  metadata: {
1642
2115
  ...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
2116
+ stall_offline_id: offline_id,
2117
+ stall_offline_created_at: now,
2118
+ stall_offline_updated_at: now,
2119
+ stall_offline_deleted_at: ""
2120
+ }
1649
2121
  };
1650
2122
  await local_db.inventory_levels.add(local_inventory_level);
1651
2123
  await add_to_sync_queue({
@@ -1679,17 +2151,21 @@ var bulk_update7 = async (props) => {
1679
2151
  ...existing,
1680
2152
  ...item.data,
1681
2153
  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
2154
+ metadata: {
2155
+ ...existing.metadata,
2156
+ ...item.data.metadata,
2157
+ stall_offline_id: existing.metadata.stall_offline_id,
2158
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2159
+ stall_offline_updated_at: now,
2160
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2161
+ }
1685
2162
  };
1686
2163
  await local_db.inventory_levels.put(updated_inventory_level);
1687
2164
  await add_to_sync_queue({
1688
2165
  action: "update",
1689
2166
  table: "inventory_levels",
1690
2167
  document_id: item.id,
1691
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1692
- stall_offline_id: existing.stall_offline_id,
2168
+ stall_offline_id: existing.metadata.stall_offline_id,
1693
2169
  data: updated_inventory_level
1694
2170
  });
1695
2171
  updated_inventory_levels.push(updated_inventory_level);
@@ -1714,8 +2190,7 @@ var bulk_delete7 = async (props) => {
1714
2190
  action: "delete",
1715
2191
  table: "inventory_levels",
1716
2192
  document_id: id,
1717
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1718
- stall_offline_id: existing.stall_offline_id,
2193
+ stall_offline_id: existing.metadata.stall_offline_id,
1719
2194
  data: { id }
1720
2195
  });
1721
2196
  await local_db.inventory_levels.delete(id);
@@ -1780,12 +2255,11 @@ var create8 = async (props) => {
1780
2255
  id: offline_id,
1781
2256
  metadata: {
1782
2257
  ...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
2258
+ stall_offline_id: offline_id,
2259
+ stall_offline_created_at: now,
2260
+ stall_offline_updated_at: now,
2261
+ stall_offline_deleted_at: ""
2262
+ }
1789
2263
  };
1790
2264
  await local_db.promotions.add(local_promotion);
1791
2265
  await add_to_sync_queue({
@@ -1812,17 +2286,21 @@ var update8 = async (props) => {
1812
2286
  ...existing,
1813
2287
  ...data,
1814
2288
  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
2289
+ metadata: {
2290
+ ...existing.metadata,
2291
+ ...data.metadata,
2292
+ stall_offline_id: existing.metadata.stall_offline_id,
2293
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2294
+ stall_offline_updated_at: now,
2295
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2296
+ }
1818
2297
  };
1819
2298
  await local_db.promotions.put(updated_promotion);
1820
2299
  await add_to_sync_queue({
1821
2300
  action: "update",
1822
2301
  table: "promotions",
1823
2302
  document_id: id,
1824
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1825
- stall_offline_id: existing.stall_offline_id,
2303
+ stall_offline_id: existing.metadata.stall_offline_id,
1826
2304
  data: updated_promotion
1827
2305
  });
1828
2306
  return updated_promotion;
@@ -1841,8 +2319,7 @@ var _delete8 = async (props) => {
1841
2319
  action: "delete",
1842
2320
  table: "promotions",
1843
2321
  document_id: id,
1844
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1845
- stall_offline_id: existing.stall_offline_id,
2322
+ stall_offline_id: existing.metadata.stall_offline_id,
1846
2323
  data: { id }
1847
2324
  });
1848
2325
  await local_db.promotions.delete(id);
@@ -1863,12 +2340,11 @@ var bulk_create8 = async (props) => {
1863
2340
  id: offline_id,
1864
2341
  metadata: {
1865
2342
  ...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
2343
+ stall_offline_id: offline_id,
2344
+ stall_offline_created_at: now,
2345
+ stall_offline_updated_at: now,
2346
+ stall_offline_deleted_at: ""
2347
+ }
1872
2348
  };
1873
2349
  await local_db.promotions.add(local_promotion);
1874
2350
  await add_to_sync_queue({
@@ -1902,17 +2378,21 @@ var bulk_update8 = async (props) => {
1902
2378
  ...existing,
1903
2379
  ...item.data,
1904
2380
  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
2381
+ metadata: {
2382
+ ...existing.metadata,
2383
+ ...item.data.metadata,
2384
+ stall_offline_id: existing.metadata.stall_offline_id,
2385
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2386
+ stall_offline_updated_at: now,
2387
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2388
+ }
1908
2389
  };
1909
2390
  await local_db.promotions.put(updated_promotion);
1910
2391
  await add_to_sync_queue({
1911
2392
  action: "update",
1912
2393
  table: "promotions",
1913
2394
  document_id: item.id,
1914
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1915
- stall_offline_id: existing.stall_offline_id,
2395
+ stall_offline_id: existing.metadata.stall_offline_id,
1916
2396
  data: updated_promotion
1917
2397
  });
1918
2398
  updated_promotions.push(updated_promotion);
@@ -1935,8 +2415,7 @@ var bulk_delete8 = async (props) => {
1935
2415
  action: "delete",
1936
2416
  table: "promotions",
1937
2417
  document_id: id,
1938
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1939
- stall_offline_id: existing.stall_offline_id,
2418
+ stall_offline_id: existing.metadata.stall_offline_id,
1940
2419
  data: { id }
1941
2420
  });
1942
2421
  await local_db.promotions.delete(id);
@@ -2001,12 +2480,11 @@ var create9 = async (props) => {
2001
2480
  id: offline_id,
2002
2481
  metadata: {
2003
2482
  ...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
2483
+ stall_offline_id: offline_id,
2484
+ stall_offline_created_at: now,
2485
+ stall_offline_updated_at: now,
2486
+ stall_offline_deleted_at: ""
2487
+ }
2010
2488
  };
2011
2489
  await local_db.order_notes.add(local_order_note);
2012
2490
  await add_to_sync_queue({
@@ -2033,17 +2511,21 @@ var update9 = async (props) => {
2033
2511
  ...existing,
2034
2512
  ...data,
2035
2513
  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
2514
+ metadata: {
2515
+ ...existing.metadata,
2516
+ ...data.metadata,
2517
+ stall_offline_id: existing.metadata.stall_offline_id,
2518
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2519
+ stall_offline_updated_at: now,
2520
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2521
+ }
2039
2522
  };
2040
2523
  await local_db.order_notes.put(updated_order_note);
2041
2524
  await add_to_sync_queue({
2042
2525
  action: "update",
2043
2526
  table: "order_notes",
2044
2527
  document_id: id,
2045
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2046
- stall_offline_id: existing.stall_offline_id,
2528
+ stall_offline_id: existing.metadata.stall_offline_id,
2047
2529
  data: updated_order_note
2048
2530
  });
2049
2531
  return updated_order_note;
@@ -2062,8 +2544,7 @@ var _delete9 = async (props) => {
2062
2544
  action: "delete",
2063
2545
  table: "order_notes",
2064
2546
  document_id: id,
2065
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2066
- stall_offline_id: existing.stall_offline_id,
2547
+ stall_offline_id: existing.metadata.stall_offline_id,
2067
2548
  data: { id }
2068
2549
  });
2069
2550
  await local_db.order_notes.delete(id);
@@ -2084,12 +2565,11 @@ var bulk_create9 = async (props) => {
2084
2565
  id: offline_id,
2085
2566
  metadata: {
2086
2567
  ...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
2568
+ stall_offline_id: offline_id,
2569
+ stall_offline_created_at: now,
2570
+ stall_offline_updated_at: now,
2571
+ stall_offline_deleted_at: ""
2572
+ }
2093
2573
  };
2094
2574
  await local_db.order_notes.add(local_order_note);
2095
2575
  await add_to_sync_queue({
@@ -2123,17 +2603,21 @@ var bulk_update9 = async (props) => {
2123
2603
  ...existing,
2124
2604
  ...item.data,
2125
2605
  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
2606
+ metadata: {
2607
+ ...existing.metadata,
2608
+ ...item.data.metadata,
2609
+ stall_offline_id: existing.metadata.stall_offline_id,
2610
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2611
+ stall_offline_updated_at: now,
2612
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2613
+ }
2129
2614
  };
2130
2615
  await local_db.order_notes.put(updated_order_note);
2131
2616
  await add_to_sync_queue({
2132
2617
  action: "update",
2133
2618
  table: "order_notes",
2134
2619
  document_id: item.id,
2135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2136
- stall_offline_id: existing.stall_offline_id,
2620
+ stall_offline_id: existing.metadata.stall_offline_id,
2137
2621
  data: updated_order_note
2138
2622
  });
2139
2623
  updated_order_notes.push(updated_order_note);
@@ -2156,8 +2640,7 @@ var bulk_delete9 = async (props) => {
2156
2640
  action: "delete",
2157
2641
  table: "order_notes",
2158
2642
  document_id: id,
2159
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2160
- stall_offline_id: existing.stall_offline_id,
2643
+ stall_offline_id: existing.metadata.stall_offline_id,
2161
2644
  data: { id }
2162
2645
  });
2163
2646
  await local_db.order_notes.delete(id);
@@ -2222,12 +2705,11 @@ var create10 = async (props) => {
2222
2705
  id: offline_id,
2223
2706
  metadata: {
2224
2707
  ...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
2708
+ stall_offline_id: offline_id,
2709
+ stall_offline_created_at: now,
2710
+ stall_offline_updated_at: now,
2711
+ stall_offline_deleted_at: ""
2712
+ }
2231
2713
  };
2232
2714
  await local_db.refunds.add(local_refund);
2233
2715
  await add_to_sync_queue({
@@ -2254,17 +2736,21 @@ var update10 = async (props) => {
2254
2736
  ...existing,
2255
2737
  ...data,
2256
2738
  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
2739
+ metadata: {
2740
+ ...existing.metadata,
2741
+ ...data.metadata,
2742
+ stall_offline_id: existing.metadata.stall_offline_id,
2743
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2744
+ stall_offline_updated_at: now,
2745
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2746
+ }
2260
2747
  };
2261
2748
  await local_db.refunds.put(updated_refund);
2262
2749
  await add_to_sync_queue({
2263
2750
  action: "update",
2264
2751
  table: "refunds",
2265
2752
  document_id: id,
2266
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2267
- stall_offline_id: existing.stall_offline_id,
2753
+ stall_offline_id: existing.metadata.stall_offline_id,
2268
2754
  data: updated_refund
2269
2755
  });
2270
2756
  return updated_refund;
@@ -2283,8 +2769,7 @@ var _delete10 = async (props) => {
2283
2769
  action: "delete",
2284
2770
  table: "refunds",
2285
2771
  document_id: id,
2286
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2287
- stall_offline_id: existing.stall_offline_id,
2772
+ stall_offline_id: existing.metadata.stall_offline_id,
2288
2773
  data: { id }
2289
2774
  });
2290
2775
  await local_db.refunds.delete(id);
@@ -2304,13 +2789,12 @@ var bulk_create10 = async (props) => {
2304
2789
  ...refund,
2305
2790
  id: offline_id,
2306
2791
  metadata: {
2307
- ...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
2792
+ ...refund.metadata,
2793
+ stall_offline_id: offline_id,
2794
+ stall_offline_created_at: now,
2795
+ stall_offline_updated_at: now,
2796
+ stall_offline_deleted_at: ""
2797
+ }
2314
2798
  };
2315
2799
  await local_db.refunds.add(local_refund);
2316
2800
  await add_to_sync_queue({
@@ -2342,17 +2826,21 @@ var bulk_update10 = async (props) => {
2342
2826
  ...existing,
2343
2827
  ...item.data,
2344
2828
  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
2829
+ metadata: {
2830
+ ...existing.metadata,
2831
+ ...item.data.metadata,
2832
+ stall_offline_id: existing.metadata.stall_offline_id,
2833
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2834
+ stall_offline_updated_at: now,
2835
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2836
+ }
2348
2837
  };
2349
2838
  await local_db.refunds.put(updated_refund);
2350
2839
  await add_to_sync_queue({
2351
2840
  action: "update",
2352
2841
  table: "refunds",
2353
2842
  document_id: item.id,
2354
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2355
- stall_offline_id: existing.stall_offline_id,
2843
+ stall_offline_id: existing.metadata.stall_offline_id,
2356
2844
  data: updated_refund
2357
2845
  });
2358
2846
  updated_refunds.push(updated_refund);
@@ -2375,8 +2863,7 @@ var bulk_delete10 = async (props) => {
2375
2863
  action: "delete",
2376
2864
  table: "refunds",
2377
2865
  document_id: id,
2378
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2379
- stall_offline_id: existing.stall_offline_id,
2866
+ stall_offline_id: existing.metadata.stall_offline_id,
2380
2867
  data: { id }
2381
2868
  });
2382
2869
  await local_db.refunds.delete(id);
@@ -2440,14 +2927,12 @@ var create11 = async (props) => {
2440
2927
  ...data,
2441
2928
  id: offline_id,
2442
2929
  metadata: {
2443
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2444
2930
  ...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
2931
+ stall_offline_id: offline_id,
2932
+ stall_offline_created_at: now,
2933
+ stall_offline_updated_at: now,
2934
+ stall_offline_deleted_at: ""
2935
+ }
2451
2936
  };
2452
2937
  await local_db.payment_providers.add(local_payment_provider);
2453
2938
  await add_to_sync_queue({
@@ -2474,17 +2959,21 @@ var update11 = async (props) => {
2474
2959
  ...existing,
2475
2960
  ...data,
2476
2961
  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
2962
+ metadata: {
2963
+ ...existing.metadata,
2964
+ ...data.metadata,
2965
+ stall_offline_id: existing.metadata.stall_offline_id,
2966
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2967
+ stall_offline_updated_at: now,
2968
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2969
+ }
2480
2970
  };
2481
2971
  await local_db.payment_providers.put(updated_payment_provider);
2482
2972
  await add_to_sync_queue({
2483
2973
  action: "update",
2484
2974
  table: "payment_providers",
2485
2975
  document_id: id,
2486
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2487
- stall_offline_id: existing.stall_offline_id,
2976
+ stall_offline_id: existing.metadata.stall_offline_id,
2488
2977
  data: updated_payment_provider
2489
2978
  });
2490
2979
  return updated_payment_provider;
@@ -2503,8 +2992,7 @@ var _delete11 = async (props) => {
2503
2992
  action: "delete",
2504
2993
  table: "payment_providers",
2505
2994
  document_id: id,
2506
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2507
- stall_offline_id: existing.stall_offline_id,
2995
+ stall_offline_id: existing.metadata.stall_offline_id,
2508
2996
  data: { id }
2509
2997
  });
2510
2998
  await local_db.payment_providers.delete(id);
@@ -2524,14 +3012,12 @@ var bulk_create11 = async (props) => {
2524
3012
  ...payment_provider,
2525
3013
  id: offline_id,
2526
3014
  metadata: {
2527
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2528
3015
  ...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
3016
+ stall_offline_id: offline_id,
3017
+ stall_offline_created_at: now,
3018
+ stall_offline_updated_at: now,
3019
+ stall_offline_deleted_at: ""
3020
+ }
2535
3021
  };
2536
3022
  await local_db.payment_providers.add(local_payment_provider);
2537
3023
  await add_to_sync_queue({
@@ -2565,17 +3051,21 @@ var bulk_update11 = async (props) => {
2565
3051
  ...existing,
2566
3052
  ...item.data,
2567
3053
  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
3054
+ metadata: {
3055
+ ...existing.metadata,
3056
+ ...item.data.metadata,
3057
+ stall_offline_id: existing.metadata.stall_offline_id,
3058
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3059
+ stall_offline_updated_at: now,
3060
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3061
+ }
2571
3062
  };
2572
3063
  await local_db.payment_providers.put(updated_payment_provider);
2573
3064
  await add_to_sync_queue({
2574
3065
  action: "update",
2575
3066
  table: "payment_providers",
2576
3067
  document_id: item.id,
2577
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2578
- stall_offline_id: existing.stall_offline_id,
3068
+ stall_offline_id: existing.metadata.stall_offline_id,
2579
3069
  data: updated_payment_provider
2580
3070
  });
2581
3071
  updated_payment_providers.push(updated_payment_provider);
@@ -2600,8 +3090,7 @@ var bulk_delete11 = async (props) => {
2600
3090
  action: "delete",
2601
3091
  table: "payment_providers",
2602
3092
  document_id: id,
2603
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2604
- stall_offline_id: existing.stall_offline_id,
3093
+ stall_offline_id: existing.metadata.stall_offline_id,
2605
3094
  data: { id }
2606
3095
  });
2607
3096
  await local_db.payment_providers.delete(id);
@@ -2666,12 +3155,11 @@ var create12 = async (props) => {
2666
3155
  id: offline_id,
2667
3156
  metadata: {
2668
3157
  ...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
3158
+ stall_offline_id: offline_id,
3159
+ stall_offline_created_at: now,
3160
+ stall_offline_updated_at: now,
3161
+ stall_offline_deleted_at: ""
3162
+ }
2675
3163
  };
2676
3164
  await local_db.payments.add(local_payment);
2677
3165
  await add_to_sync_queue({
@@ -2698,17 +3186,21 @@ var update12 = async (props) => {
2698
3186
  ...existing,
2699
3187
  ...data,
2700
3188
  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
3189
+ metadata: {
3190
+ ...existing.metadata,
3191
+ ...data.metadata,
3192
+ stall_offline_id: existing.metadata.stall_offline_id,
3193
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3194
+ stall_offline_updated_at: now,
3195
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3196
+ }
2704
3197
  };
2705
3198
  await local_db.payments.put(updated_payment);
2706
3199
  await add_to_sync_queue({
2707
3200
  action: "update",
2708
3201
  table: "payments",
2709
3202
  document_id: id,
2710
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2711
- stall_offline_id: existing.stall_offline_id,
3203
+ stall_offline_id: existing.metadata.stall_offline_id,
2712
3204
  data: updated_payment
2713
3205
  });
2714
3206
  return updated_payment;
@@ -2727,8 +3219,7 @@ var _delete12 = async (props) => {
2727
3219
  action: "delete",
2728
3220
  table: "payments",
2729
3221
  document_id: id,
2730
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2731
- stall_offline_id: existing.stall_offline_id,
3222
+ stall_offline_id: existing.metadata.stall_offline_id,
2732
3223
  data: { id }
2733
3224
  });
2734
3225
  await local_db.payments.delete(id);
@@ -2749,12 +3240,11 @@ var bulk_create12 = async (props) => {
2749
3240
  id: offline_id,
2750
3241
  metadata: {
2751
3242
  ...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
3243
+ stall_offline_id: offline_id,
3244
+ stall_offline_created_at: now,
3245
+ stall_offline_updated_at: now,
3246
+ stall_offline_deleted_at: ""
3247
+ }
2758
3248
  };
2759
3249
  await local_db.payments.add(local_payment);
2760
3250
  await add_to_sync_queue({
@@ -2786,17 +3276,21 @@ var bulk_update12 = async (props) => {
2786
3276
  ...existing,
2787
3277
  ...item.data,
2788
3278
  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
3279
+ metadata: {
3280
+ ...existing.metadata,
3281
+ ...item.data.metadata,
3282
+ stall_offline_id: existing.metadata.stall_offline_id,
3283
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3284
+ stall_offline_updated_at: now,
3285
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3286
+ }
2792
3287
  };
2793
3288
  await local_db.payments.put(updated_payment);
2794
3289
  await add_to_sync_queue({
2795
3290
  action: "update",
2796
3291
  table: "payments",
2797
3292
  document_id: item.id,
2798
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2799
- stall_offline_id: existing.stall_offline_id,
3293
+ stall_offline_id: existing.metadata.stall_offline_id,
2800
3294
  data: updated_payment
2801
3295
  });
2802
3296
  updated_payments.push(updated_payment);
@@ -2819,8 +3313,7 @@ var bulk_delete12 = async (props) => {
2819
3313
  action: "delete",
2820
3314
  table: "payments",
2821
3315
  document_id: id,
2822
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2823
- stall_offline_id: existing.stall_offline_id,
3316
+ stall_offline_id: existing.metadata.stall_offline_id,
2824
3317
  data: { id }
2825
3318
  });
2826
3319
  await local_db.payments.delete(id);
@@ -2885,11 +3378,11 @@ var create13 = async (props) => {
2885
3378
  id: offline_id,
2886
3379
  metadata: {
2887
3380
  ...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
3381
+ stall_offline_id: offline_id,
3382
+ stall_offline_created_at: now,
3383
+ stall_offline_updated_at: now,
3384
+ stall_offline_deleted_at: ""
3385
+ }
2893
3386
  };
2894
3387
  await local_db.tax_regions.add(local_region);
2895
3388
  await add_to_sync_queue({
@@ -2916,17 +3409,21 @@ var update13 = async (props) => {
2916
3409
  ...existing,
2917
3410
  ...data,
2918
3411
  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
3412
+ metadata: {
3413
+ ...existing.metadata,
3414
+ ...data.metadata,
3415
+ stall_offline_id: existing.metadata.stall_offline_id,
3416
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3417
+ stall_offline_updated_at: now,
3418
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3419
+ }
2922
3420
  };
2923
3421
  await local_db.tax_regions.put(updated_region);
2924
3422
  await add_to_sync_queue({
2925
3423
  action: "update",
2926
3424
  table: "tax_regions",
2927
3425
  document_id: id,
2928
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2929
- stall_offline_id: existing.stall_offline_id,
3426
+ stall_offline_id: existing.metadata.stall_offline_id,
2930
3427
  data: updated_region
2931
3428
  });
2932
3429
  return updated_region;
@@ -2945,8 +3442,7 @@ var _delete13 = async (props) => {
2945
3442
  action: "delete",
2946
3443
  table: "tax_regions",
2947
3444
  document_id: id,
2948
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2949
- stall_offline_id: existing.stall_offline_id,
3445
+ stall_offline_id: existing.metadata.stall_offline_id,
2950
3446
  data: { id }
2951
3447
  });
2952
3448
  await local_db.tax_regions.delete(id);
@@ -2967,11 +3463,11 @@ var bulk_create13 = async (props) => {
2967
3463
  id: offline_id,
2968
3464
  metadata: {
2969
3465
  ...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
3466
+ stall_offline_id: offline_id,
3467
+ stall_offline_created_at: now,
3468
+ stall_offline_updated_at: now,
3469
+ stall_offline_deleted_at: ""
3470
+ }
2975
3471
  };
2976
3472
  await local_db.tax_regions.add(local_region);
2977
3473
  await add_to_sync_queue({
@@ -3005,17 +3501,21 @@ var bulk_update13 = async (props) => {
3005
3501
  ...existing,
3006
3502
  ...item.data,
3007
3503
  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
3504
+ metadata: {
3505
+ ...existing.metadata,
3506
+ ...item.data.metadata,
3507
+ stall_offline_id: existing.metadata.stall_offline_id,
3508
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3509
+ stall_offline_updated_at: now,
3510
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3511
+ }
3011
3512
  };
3012
3513
  await local_db.tax_regions.put(updated_region);
3013
3514
  await add_to_sync_queue({
3014
3515
  action: "update",
3015
3516
  table: "tax_regions",
3016
3517
  document_id: item.id,
3017
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3018
- stall_offline_id: existing.stall_offline_id,
3518
+ stall_offline_id: existing.metadata.stall_offline_id,
3019
3519
  data: updated_region
3020
3520
  });
3021
3521
  updated_regions.push(updated_region);
@@ -3038,8 +3538,7 @@ var bulk_delete13 = async (props) => {
3038
3538
  action: "delete",
3039
3539
  table: "tax_regions",
3040
3540
  document_id: id,
3041
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3042
- stall_offline_id: existing.stall_offline_id,
3541
+ stall_offline_id: existing.metadata.stall_offline_id,
3043
3542
  data: { id }
3044
3543
  });
3045
3544
  await local_db.tax_regions.delete(id);
@@ -3104,11 +3603,11 @@ var create14 = async (props) => {
3104
3603
  id: offline_id,
3105
3604
  metadata: {
3106
3605
  ...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
3606
+ stall_offline_id: offline_id,
3607
+ stall_offline_created_at: now,
3608
+ stall_offline_updated_at: now,
3609
+ stall_offline_deleted_at: ""
3610
+ }
3112
3611
  };
3113
3612
  await local_db.tax_rates.add(local_rate);
3114
3613
  await add_to_sync_queue({
@@ -3135,17 +3634,21 @@ var update14 = async (props) => {
3135
3634
  ...existing,
3136
3635
  ...data,
3137
3636
  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
3637
+ metadata: {
3638
+ ...existing.metadata,
3639
+ ...data.metadata,
3640
+ stall_offline_id: existing.metadata.stall_offline_id,
3641
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3642
+ stall_offline_updated_at: now,
3643
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3644
+ }
3141
3645
  };
3142
3646
  await local_db.tax_rates.put(updated_rate);
3143
3647
  await add_to_sync_queue({
3144
3648
  action: "update",
3145
3649
  table: "tax_rates",
3146
3650
  document_id: id,
3147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3148
- stall_offline_id: existing.stall_offline_id,
3651
+ stall_offline_id: existing.metadata.stall_offline_id,
3149
3652
  data: updated_rate
3150
3653
  });
3151
3654
  return updated_rate;
@@ -3164,8 +3667,7 @@ var _delete14 = async (props) => {
3164
3667
  action: "delete",
3165
3668
  table: "tax_rates",
3166
3669
  document_id: id,
3167
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3168
- stall_offline_id: existing.stall_offline_id,
3670
+ stall_offline_id: existing.metadata.stall_offline_id,
3169
3671
  data: { id }
3170
3672
  });
3171
3673
  await local_db.tax_rates.delete(id);
@@ -3186,11 +3688,11 @@ var bulk_create14 = async (props) => {
3186
3688
  id: offline_id,
3187
3689
  metadata: {
3188
3690
  ...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
3691
+ stall_offline_id: offline_id,
3692
+ stall_offline_created_at: now,
3693
+ stall_offline_updated_at: now,
3694
+ stall_offline_deleted_at: ""
3695
+ }
3194
3696
  };
3195
3697
  await local_db.tax_rates.add(local_rate);
3196
3698
  await add_to_sync_queue({
@@ -3222,17 +3724,21 @@ var bulk_update14 = async (props) => {
3222
3724
  ...existing,
3223
3725
  ...item.data,
3224
3726
  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
3727
+ metadata: {
3728
+ ...existing.metadata,
3729
+ ...item.data.metadata,
3730
+ stall_offline_id: existing.metadata.stall_offline_id,
3731
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3732
+ stall_offline_updated_at: now,
3733
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3734
+ }
3228
3735
  };
3229
3736
  await local_db.tax_rates.put(updated_rate);
3230
3737
  await add_to_sync_queue({
3231
3738
  action: "update",
3232
3739
  table: "tax_rates",
3233
3740
  document_id: item.id,
3234
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3235
- stall_offline_id: existing.stall_offline_id,
3741
+ stall_offline_id: existing.metadata.stall_offline_id,
3236
3742
  data: updated_rate
3237
3743
  });
3238
3744
  updated_rates.push(updated_rate);
@@ -3255,8 +3761,7 @@ var bulk_delete14 = async (props) => {
3255
3761
  action: "delete",
3256
3762
  table: "tax_rates",
3257
3763
  document_id: id,
3258
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3259
- stall_offline_id: existing.stall_offline_id,
3764
+ stall_offline_id: existing.metadata.stall_offline_id,
3260
3765
  data: { id }
3261
3766
  });
3262
3767
  await local_db.tax_rates.delete(id);
@@ -3296,7 +3801,8 @@ var build_location = (data, offline_id, now) => {
3296
3801
  ...data.metadata,
3297
3802
  stall_offline_id: offline_id,
3298
3803
  stall_offline_created_at: now,
3299
- stall_offline_updated_at: now
3804
+ stall_offline_updated_at: now,
3805
+ stall_offline_deleted_at: ""
3300
3806
  }
3301
3807
  };
3302
3808
  };
@@ -3317,9 +3823,10 @@ var merge_location = (existing, updates, now) => {
3317
3823
  metadata: {
3318
3824
  ...existing.metadata,
3319
3825
  ...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
3826
+ stall_offline_id: existing.metadata?.stall_offline_id || "",
3827
+ stall_offline_created_at: existing.metadata?.stall_offline_created_at || "",
3828
+ stall_offline_updated_at: now,
3829
+ stall_offline_deleted_at: existing.metadata?.stall_offline_deleted_at || ""
3323
3830
  }
3324
3831
  };
3325
3832
  };
@@ -3473,657 +3980,257 @@ var bulk_delete15 = async (props) => {
3473
3980
  for (const id of ids) {
3474
3981
  const existing = await local_db.locations.get(id);
3475
3982
  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`);
3983
+ console.warn(`Location with id ${id} not found locally, skipping`);
3697
3984
  continue;
3698
3985
  }
3699
3986
  await add_to_sync_queue({
3700
3987
  action: "delete",
3701
- table: "fulfillments",
3988
+ table: "locations",
3702
3989
  document_id: id,
3703
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3704
- stall_offline_id: existing.stall_offline_id,
3990
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3705
3991
  data: { id }
3706
3992
  });
3707
- await local_db.fulfillments.delete(id);
3993
+ await local_db.locations.delete(id);
3708
3994
  }
3709
3995
  return;
3710
3996
  } catch (error) {
3711
3997
  throw error;
3712
3998
  }
3713
3999
  };
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));
4000
+ var locations = {
4001
+ list: list15,
4002
+ retrieve: retrieve15,
4003
+ create: create15,
4004
+ update: update15,
4005
+ delete: _delete15,
4006
+ bulk_create: bulk_create15,
4007
+ bulk_update: bulk_update15,
4008
+ bulk_delete: bulk_delete15
3795
4009
  };
3796
4010
 
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;
4011
+ // src/services/fulfillments.service.ts
4012
+ var list16 = async (props) => {
3801
4013
  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
- });
3808
- }
3809
- await update_dependent_references({
3810
- table,
3811
- old_id: stall_offline_id,
3812
- new_id: connector_id
4014
+ const { sdk, query } = props;
4015
+ const adapter = await sdk.adapter();
4016
+ if (!adapter) throw new Error("Adapter not found");
4017
+ const fulfillments2 = await adapter.fulfillments.list({
4018
+ connector_config: sdk.options.configuration,
4019
+ query
4020
+ });
4021
+ await save_bulk_data({
4022
+ table: "fulfillments",
4023
+ data: fulfillments2
3813
4024
  });
4025
+ return fulfillments2;
3814
4026
  } catch (error) {
3815
- console.error(`Error replacing temporary IDs for ${table}:`, error);
3816
4027
  throw error;
3817
4028
  }
3818
4029
  };
3819
- var update_dependent_references = async (props) => {
3820
- const { table, old_id, new_id } = props;
3821
- 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
- }
3862
- }
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();
4030
+ var retrieve16 = async (props) => {
3870
4031
  try {
4032
+ const { sdk, id } = props;
3871
4033
  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
4034
+ if (!adapter) throw new Error("Adapter not found");
4035
+ const fulfillment = await adapter.fulfillments.retrieve({
4036
+ connector_config: sdk.options.configuration,
4037
+ id
3949
4038
  });
3950
- return { success: false, error: error.message };
4039
+ await local_db.fulfillments.put(fulfillment);
4040
+ return fulfillment;
4041
+ } catch (error) {
4042
+ throw error;
3951
4043
  }
3952
4044
  };
3953
- var process_sync_queue = async (props) => {
3954
- const { sdk } = props;
3955
- const sync_batch_id = generate_uuid();
4045
+ var create16 = async (props) => {
3956
4046
  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
- });
4047
+ const { sdk, data } = props;
4048
+ const offline_id = generate_offline_id("fulfillment");
4049
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4050
+ const local_fulfillment = {
4051
+ ...data,
4052
+ id: offline_id,
4053
+ metadata: {
4054
+ ...data.metadata,
4055
+ stall_offline_id: offline_id,
4056
+ stall_offline_created_at: now,
4057
+ stall_offline_updated_at: now,
4058
+ stall_offline_deleted_at: ""
4016
4059
  }
4060
+ };
4061
+ await local_db.fulfillments.add(local_fulfillment);
4062
+ await add_to_sync_queue({
4063
+ action: "create",
4064
+ table: "fulfillments",
4065
+ document_id: offline_id,
4066
+ stall_offline_id: offline_id,
4067
+ data: local_fulfillment
4068
+ });
4069
+ return local_fulfillment;
4070
+ } catch (error) {
4071
+ throw error;
4072
+ }
4073
+ };
4074
+ var update16 = async (props) => {
4075
+ try {
4076
+ const { sdk, id, data } = props;
4077
+ const existing = await local_db.fulfillments.get(id);
4078
+ if (!existing) {
4079
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4017
4080
  }
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
- }
4081
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4082
+ const updated_fulfillment = {
4083
+ ...existing,
4084
+ ...data,
4085
+ id: existing.id,
4086
+ metadata: {
4087
+ ...existing.metadata,
4088
+ ...data.metadata,
4089
+ stall_offline_id: existing.metadata.stall_offline_id,
4090
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4091
+ stall_offline_updated_at: now,
4092
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4040
4093
  }
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
4094
  };
4095
+ await local_db.fulfillments.put(updated_fulfillment);
4096
+ await add_to_sync_queue({
4097
+ action: "update",
4098
+ table: "fulfillments",
4099
+ document_id: id,
4100
+ stall_offline_id: existing.metadata.stall_offline_id,
4101
+ data: updated_fulfillment
4102
+ });
4103
+ return updated_fulfillment;
4049
4104
  } 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
- };
4105
+ throw error;
4058
4106
  }
4059
4107
  };
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");
4108
+ var _delete16 = async (props) => {
4109
+ try {
4110
+ const { sdk, id } = props;
4111
+ const existing = await local_db.fulfillments.get(id);
4112
+ if (!existing) {
4113
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4114
+ }
4115
+ await add_to_sync_queue({
4116
+ action: "delete",
4117
+ table: "fulfillments",
4118
+ document_id: id,
4119
+ stall_offline_id: existing.metadata.stall_offline_id,
4120
+ data: { id }
4121
+ });
4122
+ await local_db.fulfillments.delete(id);
4065
4123
  return;
4124
+ } catch (error) {
4125
+ throw error;
4066
4126
  }
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`);
4127
+ };
4128
+ var bulk_create16 = async (props) => {
4129
+ try {
4130
+ const { sdk, data } = props;
4131
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4132
+ const created_fulfillments = [];
4133
+ for (const fulfillment of data) {
4134
+ const offline_id = generate_offline_id("fulfillment");
4135
+ const local_fulfillment = {
4136
+ ...fulfillment,
4137
+ id: offline_id,
4138
+ metadata: {
4139
+ ...fulfillment.metadata,
4140
+ stall_offline_id: offline_id,
4141
+ stall_offline_created_at: now,
4142
+ stall_offline_updated_at: now,
4143
+ stall_offline_deleted_at: ""
4144
+ }
4145
+ };
4146
+ await local_db.fulfillments.add(local_fulfillment);
4147
+ await add_to_sync_queue({
4148
+ action: "create",
4149
+ table: "fulfillments",
4150
+ document_id: offline_id,
4151
+ stall_offline_id: offline_id,
4152
+ data: local_fulfillment
4077
4153
  });
4154
+ created_fulfillments.push(local_fulfillment);
4078
4155
  }
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");
4156
+ return created_fulfillments;
4157
+ } catch (error) {
4158
+ throw error;
4086
4159
  }
4087
4160
  };
4088
- var get_sync_stats = async () => {
4161
+ var bulk_update16 = async (props) => {
4089
4162
  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
- };
4163
+ const { sdk, data } = props;
4164
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4165
+ const updated_fulfillments = [];
4166
+ for (const item of data) {
4167
+ const existing = await local_db.fulfillments.get(item.id);
4168
+ if (!existing) {
4169
+ console.warn(
4170
+ `Fulfillment with id ${item.id} not found locally, skipping`
4171
+ );
4172
+ continue;
4173
+ }
4174
+ const updated_fulfillment = {
4175
+ ...existing,
4176
+ ...item.data,
4177
+ id: existing.id,
4178
+ metadata: {
4179
+ ...existing.metadata,
4180
+ ...item.data.metadata,
4181
+ stall_offline_id: existing.metadata.stall_offline_id,
4182
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4183
+ stall_offline_updated_at: now,
4184
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4185
+ }
4186
+ };
4187
+ await local_db.fulfillments.put(updated_fulfillment);
4188
+ await add_to_sync_queue({
4189
+ action: "update",
4190
+ table: "fulfillments",
4191
+ document_id: item.id,
4192
+ stall_offline_id: existing.metadata.stall_offline_id,
4193
+ data: updated_fulfillment
4194
+ });
4195
+ updated_fulfillments.push(updated_fulfillment);
4196
+ }
4197
+ return updated_fulfillments;
4100
4198
  } catch (error) {
4101
- console.error("Error getting sync stats:", error);
4102
- return { pending: 0, syncing: 0, failed: 0, total: 0 };
4199
+ throw error;
4103
4200
  }
4104
4201
  };
4105
- var trigger_sync = async (props) => {
4202
+ var bulk_delete16 = async (props) => {
4106
4203
  try {
4107
- const { sdk } = props;
4108
- return await process_sync_queue({ sdk });
4204
+ const { sdk, ids } = props;
4205
+ for (const id of ids) {
4206
+ const existing = await local_db.fulfillments.get(id);
4207
+ if (!existing) {
4208
+ console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4209
+ continue;
4210
+ }
4211
+ await add_to_sync_queue({
4212
+ action: "delete",
4213
+ table: "fulfillments",
4214
+ document_id: id,
4215
+ stall_offline_id: existing.metadata.stall_offline_id,
4216
+ data: { id }
4217
+ });
4218
+ await local_db.fulfillments.delete(id);
4219
+ }
4220
+ return;
4109
4221
  } 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
- };
4222
+ throw error;
4118
4223
  }
4119
4224
  };
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
4225
+ var fulfillments = {
4226
+ list: list16,
4227
+ retrieve: retrieve16,
4228
+ create: create16,
4229
+ update: update16,
4230
+ delete: _delete16,
4231
+ bulk_create: bulk_create16,
4232
+ bulk_update: bulk_update16,
4233
+ bulk_delete: bulk_delete16
4127
4234
  };
4128
4235
  export {
4129
4236
  add_sync_log,
@@ -4139,6 +4246,8 @@ export {
4139
4246
  get_sync_logs_by_batch,
4140
4247
  initializeStallCore,
4141
4248
  inventory_levels,
4249
+ is_offline,
4250
+ is_online,
4142
4251
  local_db,
4143
4252
  locations,
4144
4253
  order_notes,