@use-stall/core 0.0.11 → 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.js CHANGED
@@ -43,6 +43,8 @@ __export(index_exports, {
43
43
  get_sync_logs_by_batch: () => get_sync_logs_by_batch,
44
44
  initializeStallCore: () => initializeStallCore,
45
45
  inventory_levels: () => inventory_levels,
46
+ is_offline: () => is_offline,
47
+ is_online: () => is_online,
46
48
  local_db: () => local_db,
47
49
  locations: () => locations,
48
50
  order_notes: () => order_notes,
@@ -68,7 +70,7 @@ var import_dexie = __toESM(require("dexie"));
68
70
  // src/db/schema.ts
69
71
  var schemas = {
70
72
  connector_cache: "id",
71
- sync_queue: "++id, status, timestamp",
73
+ sync_queue: "++id, status, timestamp, priority",
72
74
  sync_logs: "++id, sync_batch_id, timestamp",
73
75
  products: "++id",
74
76
  variants: "++id",
@@ -94,45 +96,6 @@ var options = { allowEmptyDB: true };
94
96
  var local_db = new import_dexie.default("stall-core-db", options);
95
97
  local_db.version(1).stores(schemas);
96
98
 
97
- // src/core/init.ts
98
- var initializeStallCore = (options2) => {
99
- const sdk = {
100
- options: options2,
101
- adapter: async () => getAdapter(sdk),
102
- refreshAdapter: async () => getAdapter(sdk, true)
103
- };
104
- void sdk.adapter();
105
- return sdk;
106
- };
107
- var getAdapter = async (sdk, force) => {
108
- const date = Date.now();
109
- let module_code;
110
- const cache_key = "connector-module";
111
- const cached = await local_db.connector_cache.get(cache_key);
112
- if (cached && !force) {
113
- module_code = cached.code;
114
- } else {
115
- const response = await fetch(sdk.options.connector_url, {
116
- mode: "cors",
117
- method: "GET"
118
- });
119
- if (!response.ok) {
120
- throw new Error(`Failed to fetch connector: ${response.statusText}`);
121
- }
122
- module_code = await response.text();
123
- await local_db.connector_cache.put({
124
- id: cache_key,
125
- code: module_code,
126
- timestamp: date
127
- });
128
- }
129
- const blob = new Blob([module_code], { type: "application/javascript" });
130
- const blobUrl = URL.createObjectURL(blob);
131
- const module2 = await import(blobUrl);
132
- URL.revokeObjectURL(blobUrl);
133
- return module2;
134
- };
135
-
136
99
  // src/lib/utils.ts
137
100
  var generate_uuid = () => {
138
101
  return "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
@@ -141,11 +104,32 @@ var generate_uuid = () => {
141
104
  return v.toString(16);
142
105
  });
143
106
  };
107
+ var is_online = () => {
108
+ if (typeof navigator !== "undefined" && typeof navigator.onLine === "boolean") {
109
+ return navigator.onLine;
110
+ }
111
+ return true;
112
+ };
113
+ var is_offline = () => {
114
+ return !is_online();
115
+ };
144
116
 
145
117
  // src/db/helpers.ts
146
118
  var generate_offline_id = (table) => {
147
119
  return `stall_${table}_${generate_uuid()}_${Date.now()}`;
148
120
  };
121
+ var get_action_priority = (action) => {
122
+ switch (action) {
123
+ case "create":
124
+ return 1;
125
+ case "update":
126
+ return 2;
127
+ case "delete":
128
+ return 3;
129
+ default:
130
+ return 2;
131
+ }
132
+ };
149
133
  var save_bulk_data = async (props) => {
150
134
  await local_db.transaction("rw", props.table, async () => {
151
135
  await local_db?.[props.table].clear();
@@ -164,15 +148,25 @@ var add_to_sync_queue = async (props) => {
164
148
  data: props.data,
165
149
  timestamp: Date.now(),
166
150
  status: "pending",
167
- retry_count: 0
151
+ retry_count: 0,
152
+ priority: get_action_priority(props.action)
168
153
  };
169
154
  await local_db.sync_queue.add(queue_item);
170
155
  return queue_item;
171
156
  };
172
157
  var get_pending_sync_queue = async () => {
173
158
  const pending_items = await local_db.sync_queue.where("status").equals("pending").toArray();
159
+ const sorted_items = pending_items.sort((a, b) => {
160
+ if (a.table !== b.table) {
161
+ return a.table.localeCompare(b.table);
162
+ }
163
+ if (a.priority !== b.priority) {
164
+ return a.priority - b.priority;
165
+ }
166
+ return a.timestamp - b.timestamp;
167
+ });
174
168
  const grouped = /* @__PURE__ */ new Map();
175
- pending_items.forEach((item) => {
169
+ sorted_items.forEach((item) => {
176
170
  if (!grouped.has(item.table)) {
177
171
  grouped.set(item.table, []);
178
172
  }
@@ -235,112 +229,580 @@ var cleanup_old_sync_logs = async (days = 30) => {
235
229
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
236
230
  };
237
231
 
238
- // src/services/products.service.ts
239
- var list = async (props) => {
240
- try {
241
- const { sdk, query } = props;
242
- const adapter = await sdk.adapter();
243
- if (!adapter) throw new Error("Adapter not found");
244
- const products2 = await adapter.products.list({
245
- connector_config: sdk.options.configuration,
246
- query
247
- });
248
- await save_bulk_data({
249
- table: "products",
250
- data: products2
251
- });
252
- return products2;
253
- } catch (error) {
254
- throw error;
255
- }
232
+ // src/services/sync/sync-dependencies.ts
233
+ var SYNC_DEPENDENCY_LAYERS = {
234
+ 1: [
235
+ "tax_regions",
236
+ "tax_rates",
237
+ "categories",
238
+ "collections",
239
+ "locations",
240
+ "payment_providers",
241
+ "customers",
242
+ "promotions"
243
+ ],
244
+ 2: ["products"],
245
+ 3: ["variants", "inventory_levels"],
246
+ 4: ["orders", "order_notes"],
247
+ 5: ["payments", "refunds", "fulfillments"]
256
248
  };
257
- var retrieve = async (props) => {
258
- try {
259
- const { sdk, id } = props;
260
- const adapter = await sdk.adapter();
261
- if (!adapter) throw new Error("Adapter not found");
262
- const product = await adapter.products.retrieve({
263
- connector_config: sdk.options.configuration,
264
- id
265
- });
266
- await local_db.products.put(product);
267
- return product;
268
- } catch (error) {
269
- throw error;
249
+ var get_entity_dependencies = (table) => {
250
+ const dependencies = {
251
+ // Layer 1: Independent
252
+ tax_regions: [],
253
+ tax_rates: ["tax_regions"],
254
+ categories: [],
255
+ collections: [],
256
+ locations: [],
257
+ payment_providers: [],
258
+ customers: [],
259
+ promotions: [],
260
+ // Layer 2: Product
261
+ products: ["categories", "collections"],
262
+ // Layer 3: Variants & Inventory
263
+ variants: ["products"],
264
+ inventory_levels: ["products", "variants"],
265
+ inventory_history: ["products", "variants"],
266
+ // Layer 4: Orders
267
+ orders: ["customers", "products", "variants", "locations"],
268
+ order_notes: ["orders"],
269
+ // Layer 5: Order-related
270
+ payments: ["orders", "payment_providers"],
271
+ refunds: ["orders", "payments"],
272
+ fulfillments: ["orders"],
273
+ // Tags
274
+ tags: ["products"],
275
+ // Fulfillment config
276
+ fulfillment_types: [],
277
+ fulfillment_providers: []
278
+ };
279
+ return dependencies[table] || [];
280
+ };
281
+ var get_sync_layer = (table) => {
282
+ for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
283
+ if (tables.includes(table)) {
284
+ return parseInt(layer);
285
+ }
270
286
  }
287
+ return 99;
271
288
  };
272
- var create = async (props) => {
289
+ var sort_by_dependency_order = (items) => {
290
+ return items.sort((a, b) => {
291
+ const layer_a = get_sync_layer(a.table);
292
+ const layer_b = get_sync_layer(b.table);
293
+ if (layer_a !== layer_b) {
294
+ return layer_a - layer_b;
295
+ }
296
+ return 0;
297
+ });
298
+ };
299
+ var are_dependencies_satisfied = (table, synced_tables) => {
300
+ const dependencies = get_entity_dependencies(table);
301
+ return dependencies.every((dep) => synced_tables.has(dep));
302
+ };
303
+
304
+ // src/services/sync/sync.service.ts
305
+ var MAX_RETRIES = 3;
306
+ var SYNC_INTERVAL_MS = 2 * 60 * 1e3;
307
+ var sync_interval = null;
308
+ var is_syncing = false;
309
+ var replace_temporary_ids = async (props) => {
310
+ const { table, stall_offline_id, connector_id } = props;
273
311
  try {
274
- const { sdk, data } = props;
275
- const offline_id = generate_offline_id("product");
276
- const now = (/* @__PURE__ */ new Date()).toISOString();
277
- const local_product = {
278
- ...data,
279
- id: offline_id,
280
- metadata: {
281
- ...data.metadata,
282
- stall_offline_id: offline_id
283
- },
284
- stall_offline_id: offline_id,
285
- stall_offline_created_at: now,
286
- stall_offline_updated_at: now
287
- };
288
- await local_db.products.add(local_product);
289
- await add_to_sync_queue({
290
- action: "create",
291
- table: "products",
292
- document_id: offline_id,
293
- stall_offline_id: offline_id,
294
- data: local_product
312
+ const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
313
+ if (existing) {
314
+ await local_db[table].update(existing.id, {
315
+ id: connector_id
316
+ });
317
+ }
318
+ await update_dependent_references({
319
+ table,
320
+ old_id: stall_offline_id,
321
+ new_id: connector_id
295
322
  });
296
- return local_product;
297
323
  } catch (error) {
324
+ console.error(`Error replacing temporary IDs for ${table}:`, error);
298
325
  throw error;
299
326
  }
300
327
  };
301
- var update = async (props) => {
328
+ var update_dependent_references = async (props) => {
329
+ const { table, old_id, new_id } = props;
302
330
  try {
303
- const { sdk, id, data } = props;
304
- const existing = await local_db.products.get(id);
305
- if (!existing) {
306
- throw new Error(`Product with id ${id} not found locally`);
307
- }
308
- const now = (/* @__PURE__ */ new Date()).toISOString();
309
- const updated_product = {
310
- ...existing,
311
- ...data,
312
- id: existing.id,
313
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
314
- stall_offline_id: existing.stall_offline_id,
315
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
316
- stall_offline_updated_at: now
331
+ const reference_map = {
332
+ products: [
333
+ { table: "variants", field: "product_id" },
334
+ { table: "inventory_levels", field: "product_id" }
335
+ ],
336
+ variants: [{ table: "inventory_levels", field: "variant_id" }],
337
+ customers: [{ table: "orders", field: "customer_id" }],
338
+ orders: [
339
+ { table: "payments", field: "order_id" },
340
+ { table: "refunds", field: "order_id" },
341
+ { table: "order_notes", field: "order_id" },
342
+ { table: "fulfillments", field: "order_id" }
343
+ ],
344
+ payments: [{ table: "refunds", field: "payment_id" }],
345
+ locations: [{ table: "orders", field: "location_id" }],
346
+ categories: [{ table: "products", field: "category_id" }],
347
+ collections: [{ table: "products", field: "collection_id" }],
348
+ tax_regions: [{ table: "tax_rates", field: "region_id" }],
349
+ tax_rates: [],
350
+ tags: [],
351
+ inventory_levels: [],
352
+ inventory_history: [],
353
+ promotions: [],
354
+ order_notes: [],
355
+ refunds: [],
356
+ payment_providers: [],
357
+ fulfillments: [],
358
+ fulfillment_types: [],
359
+ fulfillment_providers: []
317
360
  };
318
- await local_db.products.put(updated_product);
319
- await add_to_sync_queue({
320
- action: "update",
321
- table: "products",
322
- document_id: id,
323
- stall_offline_id: existing.stall_offline_id,
324
- data: updated_product
325
- });
326
- return updated_product;
361
+ const references = reference_map[table] || [];
362
+ for (const ref of references) {
363
+ const records = await local_db[ref.table].toArray();
364
+ const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
365
+ ...record,
366
+ [ref.field]: new_id
367
+ }));
368
+ if (updates.length > 0) {
369
+ await local_db[ref.table].bulkPut(updates);
370
+ }
371
+ }
327
372
  } catch (error) {
328
- throw error;
373
+ console.error(`Error updating dependent references for ${table}:`, error);
329
374
  }
330
375
  };
331
- var _delete = async (props) => {
376
+ var sync_queue_item = async (props) => {
377
+ const { sdk, item, sync_batch_id } = props;
378
+ const start_time = Date.now();
332
379
  try {
333
- const { sdk, id } = props;
334
- const existing = await local_db.products.get(id);
335
- if (!existing) {
336
- throw new Error(`Product with id ${id} not found locally`);
380
+ const adapter = await sdk.adapter();
381
+ if (!adapter) {
382
+ throw new Error("Adapter not found");
337
383
  }
338
- await add_to_sync_queue({
384
+ const connector_config = sdk.options.configuration;
385
+ const table_module = adapter[item.table];
386
+ if (!table_module) {
387
+ throw new Error(`Module ${item.table} not found in adapter`);
388
+ }
389
+ let connector_id;
390
+ if (item.action === "create") {
391
+ const result = await table_module.create({
392
+ connector_config,
393
+ data: item.data
394
+ });
395
+ connector_id = result?.id;
396
+ if (connector_id) {
397
+ await replace_temporary_ids({
398
+ table: item.table,
399
+ stall_offline_id: item.stall_offline_id,
400
+ connector_id
401
+ });
402
+ }
403
+ } else if (item.action === "update") {
404
+ const result = await table_module.update({
405
+ connector_config,
406
+ id: item.document_id,
407
+ data: item.data
408
+ });
409
+ connector_id = result?.id || item.document_id;
410
+ } else if (item.action === "delete") {
411
+ await table_module.delete({
412
+ connector_config,
413
+ id: item.document_id
414
+ });
415
+ connector_id = item.document_id;
416
+ }
417
+ const duration = Date.now() - start_time;
418
+ await add_sync_log({
419
+ sync_batch_id,
420
+ table: item.table,
421
+ action: item.action,
422
+ document_id: item.document_id,
423
+ stall_offline_id: item.stall_offline_id,
424
+ connector_id,
425
+ status: "success",
426
+ duration_ms: duration
427
+ });
428
+ await remove_from_sync_queue(item.id);
429
+ return { success: true, connector_id };
430
+ } catch (error) {
431
+ const duration = Date.now() - start_time;
432
+ console.error(`Error syncing item ${item.id}:`, error);
433
+ const current_retries = item.retry_count || 0;
434
+ if (current_retries < MAX_RETRIES) {
435
+ await update_sync_queue_status({
436
+ id: item.id,
437
+ status: "pending",
438
+ error: error.message,
439
+ retry_count: current_retries + 1
440
+ });
441
+ } else {
442
+ await update_sync_queue_status({
443
+ id: item.id,
444
+ status: "failed",
445
+ error: `Max retries exceeded: ${error.message}`
446
+ });
447
+ }
448
+ await add_sync_log({
449
+ sync_batch_id,
450
+ table: item.table,
451
+ action: item.action,
452
+ document_id: item.document_id,
453
+ stall_offline_id: item.stall_offline_id,
454
+ status: "failed",
455
+ error: error.message,
456
+ duration_ms: duration
457
+ });
458
+ return { success: false, error: error.message };
459
+ }
460
+ };
461
+ var process_sync_queue = async (props) => {
462
+ const { sdk } = props;
463
+ const sync_batch_id = generate_uuid();
464
+ if (is_syncing) {
465
+ console.log("Sync already in progress, skipping...");
466
+ return {
467
+ sync_batch_id,
468
+ total: 0,
469
+ synced: 0,
470
+ failed: 0
471
+ };
472
+ }
473
+ is_syncing = true;
474
+ try {
475
+ const pending_items_by_table = await get_pending_sync_queue();
476
+ if (pending_items_by_table.size === 0) {
477
+ return {
478
+ sync_batch_id,
479
+ total: 0,
480
+ synced: 0,
481
+ failed: 0
482
+ };
483
+ }
484
+ let total_synced = 0;
485
+ let total_failed = 0;
486
+ const all_items = [];
487
+ pending_items_by_table.forEach((items) => {
488
+ items.forEach((item) => {
489
+ all_items.push(item);
490
+ });
491
+ });
492
+ const sorted_items = sort_by_dependency_order(
493
+ all_items
494
+ );
495
+ const synced_tables = /* @__PURE__ */ new Set();
496
+ const items_to_retry = [];
497
+ for (const item of sorted_items) {
498
+ if (!are_dependencies_satisfied(item.table, synced_tables)) {
499
+ items_to_retry.push(item);
500
+ continue;
501
+ }
502
+ await update_sync_queue_status({
503
+ id: item.id,
504
+ status: "syncing"
505
+ });
506
+ const result = await sync_queue_item({
507
+ sdk,
508
+ item,
509
+ sync_batch_id
510
+ });
511
+ if (result.success) {
512
+ total_synced++;
513
+ if (!synced_tables.has(item.table)) {
514
+ synced_tables.add(item.table);
515
+ }
516
+ } else {
517
+ total_failed++;
518
+ }
519
+ }
520
+ for (const item of items_to_retry) {
521
+ await update_sync_queue_status({
522
+ id: item.id,
523
+ status: "syncing"
524
+ });
525
+ const result = await sync_queue_item({
526
+ sdk,
527
+ item,
528
+ sync_batch_id
529
+ });
530
+ if (result.success) {
531
+ total_synced++;
532
+ } else {
533
+ total_failed++;
534
+ }
535
+ }
536
+ return {
537
+ sync_batch_id,
538
+ total: all_items.length,
539
+ synced: total_synced,
540
+ failed: total_failed
541
+ };
542
+ } catch (error) {
543
+ console.error("Error processing sync queue:", error);
544
+ return {
545
+ sync_batch_id,
546
+ total: 0,
547
+ synced: 0,
548
+ failed: 0
549
+ };
550
+ } finally {
551
+ is_syncing = false;
552
+ }
553
+ };
554
+ var get_sync_status = async () => {
555
+ try {
556
+ const all_items = await local_db.sync_queue.toArray();
557
+ const pending = all_items.filter((i) => i.status === "pending").length;
558
+ const syncing = all_items.filter((i) => i.status === "syncing").length;
559
+ const failed = all_items.filter((i) => i.status === "failed").length;
560
+ return {
561
+ pending,
562
+ syncing,
563
+ failed,
564
+ total: all_items.length,
565
+ is_sync_running: sync_interval !== null
566
+ };
567
+ } catch (error) {
568
+ console.error("Error getting sync status:", error);
569
+ return {
570
+ pending: 0,
571
+ syncing: 0,
572
+ failed: 0,
573
+ total: 0,
574
+ is_sync_running: false
575
+ };
576
+ }
577
+ };
578
+ var fix_sync_queue = async () => {
579
+ try {
580
+ const stuck_items = await local_db.sync_queue.where("status").equals("syncing").toArray();
581
+ for (const item of stuck_items) {
582
+ await update_sync_queue_status({
583
+ id: item.id,
584
+ status: "pending"
585
+ });
586
+ }
587
+ console.log(`Fixed ${stuck_items.length} stuck sync queue items`);
588
+ return {
589
+ fixed: stuck_items.length
590
+ };
591
+ } catch (error) {
592
+ console.error("Error fixing sync queue:", error);
593
+ return {
594
+ fixed: 0
595
+ };
596
+ }
597
+ };
598
+ var trigger_sync = async (props) => {
599
+ try {
600
+ const { sdk } = props;
601
+ return await process_sync_queue({ sdk });
602
+ } catch (error) {
603
+ console.error("Error triggering sync:", error);
604
+ return {
605
+ sync_batch_id: generate_uuid(),
606
+ total: 0,
607
+ synced: 0,
608
+ failed: 0
609
+ };
610
+ }
611
+ };
612
+ var start_sync = async (props) => {
613
+ const { sdk } = props;
614
+ if (sync_interval) {
615
+ console.warn("Background sync already running");
616
+ return;
617
+ }
618
+ console.log(
619
+ `Starting background sync service (${SYNC_INTERVAL_MS}ms interval)`
620
+ );
621
+ const initial_result = await process_sync_queue({ sdk });
622
+ if (initial_result.total > 0) {
623
+ console.log(
624
+ `Initial sync: ${initial_result.synced} synced, ${initial_result.failed} failed out of ${initial_result.total}`
625
+ );
626
+ }
627
+ sync_interval = setInterval(async () => {
628
+ const status = await get_sync_status();
629
+ if (status.pending > 0) {
630
+ const result = await process_sync_queue({ sdk });
631
+ if (result.total > 0) {
632
+ console.log(
633
+ `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
634
+ );
635
+ }
636
+ }
637
+ }, SYNC_INTERVAL_MS);
638
+ };
639
+ var stop_sync = () => {
640
+ if (sync_interval) {
641
+ clearInterval(sync_interval);
642
+ sync_interval = null;
643
+ console.log("Background sync service stopped");
644
+ } else {
645
+ console.warn("Background sync is not running");
646
+ }
647
+ };
648
+ var sync_service = {
649
+ get_sync_status,
650
+ fix_sync_queue,
651
+ trigger_sync,
652
+ start_sync,
653
+ stop_sync
654
+ };
655
+
656
+ // src/core/init.ts
657
+ var initializeStallCore = (options2) => {
658
+ const sdk = {
659
+ options: options2,
660
+ adapter: async () => getAdapter(sdk),
661
+ refreshAdapter: async () => getAdapter(sdk, true)
662
+ };
663
+ void sdk.adapter().then(() => {
664
+ void sync_service.start_sync({ sdk });
665
+ });
666
+ return sdk;
667
+ };
668
+ var getAdapter = async (sdk, force) => {
669
+ const date = Date.now();
670
+ let module_code;
671
+ const cache_key = "connector-module";
672
+ const cached = await local_db.connector_cache.get(cache_key);
673
+ if (cached && !force) {
674
+ module_code = cached.code;
675
+ } else {
676
+ const response = await fetch(sdk.options.connector_url, {
677
+ mode: "cors",
678
+ method: "GET"
679
+ });
680
+ if (!response.ok) {
681
+ throw new Error(`Failed to fetch connector: ${response.statusText}`);
682
+ }
683
+ module_code = await response.text();
684
+ await local_db.connector_cache.put({
685
+ id: cache_key,
686
+ code: module_code,
687
+ timestamp: date
688
+ });
689
+ }
690
+ const blob = new Blob([module_code], { type: "application/javascript" });
691
+ const blobUrl = URL.createObjectURL(blob);
692
+ const module2 = await import(blobUrl);
693
+ URL.revokeObjectURL(blobUrl);
694
+ return module2;
695
+ };
696
+
697
+ // src/services/products.service.ts
698
+ var list = async (props) => {
699
+ try {
700
+ const { sdk, query } = props;
701
+ const adapter = await sdk.adapter();
702
+ if (!adapter) throw new Error("Adapter not found");
703
+ const products2 = await adapter.products.list({
704
+ connector_config: sdk.options.configuration,
705
+ query
706
+ });
707
+ await save_bulk_data({
708
+ table: "products",
709
+ data: products2
710
+ });
711
+ return products2;
712
+ } catch (error) {
713
+ throw error;
714
+ }
715
+ };
716
+ var retrieve = async (props) => {
717
+ try {
718
+ const { sdk, id } = props;
719
+ const adapter = await sdk.adapter();
720
+ if (!adapter) throw new Error("Adapter not found");
721
+ const product = await adapter.products.retrieve({
722
+ connector_config: sdk.options.configuration,
723
+ id
724
+ });
725
+ await local_db.products.put(product);
726
+ return product;
727
+ } catch (error) {
728
+ throw error;
729
+ }
730
+ };
731
+ var create = async (props) => {
732
+ try {
733
+ const { sdk, data } = props;
734
+ const offline_id = generate_offline_id("product");
735
+ const now = (/* @__PURE__ */ new Date()).toISOString();
736
+ const local_product = {
737
+ ...data,
738
+ id: offline_id,
739
+ metadata: {
740
+ ...data.metadata,
741
+ stall_offline_id: offline_id,
742
+ stall_offline_created_at: now,
743
+ stall_offline_updated_at: now,
744
+ stall_offline_deleted_at: ""
745
+ }
746
+ };
747
+ await local_db.products.add(local_product);
748
+ await add_to_sync_queue({
749
+ action: "create",
750
+ table: "products",
751
+ document_id: offline_id,
752
+ stall_offline_id: offline_id,
753
+ data: local_product
754
+ });
755
+ return local_product;
756
+ } catch (error) {
757
+ throw error;
758
+ }
759
+ };
760
+ var update = async (props) => {
761
+ try {
762
+ const { sdk, id, data } = props;
763
+ const existing = await local_db.products.get(id);
764
+ if (!existing) {
765
+ throw new Error(`Product with id ${id} not found locally`);
766
+ }
767
+ const now = (/* @__PURE__ */ new Date()).toISOString();
768
+ const updated_product = {
769
+ ...existing,
770
+ ...data,
771
+ id: existing.id,
772
+ metadata: {
773
+ ...existing.metadata,
774
+ ...data.metadata,
775
+ stall_offline_id: existing.metadata.stall_offline_id,
776
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
777
+ stall_offline_updated_at: now,
778
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
779
+ }
780
+ };
781
+ await local_db.products.put(updated_product);
782
+ await add_to_sync_queue({
783
+ action: "update",
784
+ table: "products",
785
+ document_id: id,
786
+ stall_offline_id: existing.metadata.stall_offline_id,
787
+ data: updated_product
788
+ });
789
+ return updated_product;
790
+ } catch (error) {
791
+ throw error;
792
+ }
793
+ };
794
+ var _delete = async (props) => {
795
+ try {
796
+ const { sdk, id } = props;
797
+ const existing = await local_db.products.get(id);
798
+ if (!existing) {
799
+ throw new Error(`Product with id ${id} not found locally`);
800
+ }
801
+ await add_to_sync_queue({
339
802
  action: "delete",
340
803
  table: "products",
341
804
  document_id: id,
342
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
343
- stall_offline_id: existing.stall_offline_id,
805
+ stall_offline_id: existing.metadata.stall_offline_id,
344
806
  data: { id }
345
807
  });
346
808
  await local_db.products.delete(id);
@@ -361,11 +823,11 @@ var bulk_create = async (props) => {
361
823
  id: offline_id,
362
824
  metadata: {
363
825
  ...product.metadata,
364
- stall_offline_id: offline_id
365
- },
366
- stall_offline_id: offline_id,
367
- stall_offline_created_at: now,
368
- stall_offline_updated_at: now
826
+ stall_offline_id: offline_id,
827
+ stall_offline_created_at: now,
828
+ stall_offline_updated_at: now,
829
+ stall_offline_deleted_at: ""
830
+ }
369
831
  };
370
832
  await local_db.products.add(local_product);
371
833
  await add_to_sync_queue({
@@ -397,17 +859,21 @@ var bulk_update = async (props) => {
397
859
  ...existing,
398
860
  ...item.data,
399
861
  id: existing.id,
400
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
401
- stall_offline_id: existing.stall_offline_id,
402
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
403
- stall_offline_updated_at: now
862
+ metadata: {
863
+ ...existing.metadata,
864
+ ...item.data.metadata,
865
+ stall_offline_id: existing.metadata.stall_offline_id,
866
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
867
+ stall_offline_updated_at: now,
868
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
869
+ }
404
870
  };
405
871
  await local_db.products.put(updated_product);
406
872
  await add_to_sync_queue({
407
873
  action: "update",
408
874
  table: "products",
409
875
  document_id: item.id,
410
- stall_offline_id: existing.stall_offline_id,
876
+ stall_offline_id: existing.metadata.stall_offline_id,
411
877
  data: updated_product
412
878
  });
413
879
  updated_products.push(updated_product);
@@ -430,8 +896,7 @@ var bulk_delete = async (props) => {
430
896
  action: "delete",
431
897
  table: "products",
432
898
  document_id: id,
433
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
434
- stall_offline_id: existing.stall_offline_id,
899
+ stall_offline_id: existing.metadata.stall_offline_id,
435
900
  data: { id }
436
901
  });
437
902
  await local_db.products.delete(id);
@@ -500,11 +965,11 @@ var create2 = async (props) => {
500
965
  id: offline_id,
501
966
  metadata: {
502
967
  ...data.metadata,
503
- stall_offline_id: offline_id
504
- },
505
- stall_offline_id: offline_id,
506
- stall_offline_created_at: now,
507
- stall_offline_updated_at: now
968
+ stall_offline_id: offline_id,
969
+ stall_offline_created_at: now,
970
+ stall_offline_updated_at: now,
971
+ stall_offline_deleted_at: ""
972
+ }
508
973
  };
509
974
  await local_db.orders.add(local_order);
510
975
  await add_to_sync_queue({
@@ -533,17 +998,21 @@ var update2 = async (props) => {
533
998
  ...existing,
534
999
  ...data,
535
1000
  id: existing.id,
536
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
537
- stall_offline_id: existing.stall_offline_id,
538
- stall_offline_updated_at: now
1001
+ metadata: {
1002
+ ...existing.metadata,
1003
+ ...data.metadata,
1004
+ stall_offline_id: existing.metadata.stall_offline_id,
1005
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1006
+ stall_offline_updated_at: now,
1007
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1008
+ }
539
1009
  };
540
1010
  await local_db.orders.put(updated_order);
541
1011
  await add_to_sync_queue({
542
1012
  action: "update",
543
1013
  table: "orders",
544
1014
  document_id: id,
545
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
546
- stall_offline_id: existing.stall_offline_id,
1015
+ stall_offline_id: existing.metadata.stall_offline_id,
547
1016
  data: updated_order
548
1017
  });
549
1018
  return updated_order;
@@ -564,8 +1033,7 @@ var _delete2 = async (props) => {
564
1033
  action: "delete",
565
1034
  table: "orders",
566
1035
  document_id: id,
567
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
568
- stall_offline_id: existing.stall_offline_id,
1036
+ stall_offline_id: existing.metadata.stall_offline_id,
569
1037
  data: { id }
570
1038
  });
571
1039
  await local_db.orders.delete(id);
@@ -588,11 +1056,11 @@ var bulk_create2 = async (props) => {
588
1056
  id: offline_id,
589
1057
  metadata: {
590
1058
  ...order.metadata,
591
- stall_offline_id: offline_id
592
- },
593
- stall_offline_id: offline_id,
594
- stall_offline_created_at: now,
595
- stall_offline_updated_at: now
1059
+ stall_offline_id: offline_id,
1060
+ stall_offline_created_at: now,
1061
+ stall_offline_updated_at: now,
1062
+ stall_offline_deleted_at: ""
1063
+ }
596
1064
  };
597
1065
  await local_db.orders.add(local_order);
598
1066
  await add_to_sync_queue({
@@ -626,17 +1094,21 @@ var bulk_update2 = async (props) => {
626
1094
  ...existing,
627
1095
  ...item.data,
628
1096
  id: existing.id,
629
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
630
- stall_offline_id: existing.stall_offline_id,
631
- stall_offline_updated_at: now
1097
+ metadata: {
1098
+ ...existing.metadata,
1099
+ ...item.data.metadata,
1100
+ stall_offline_id: existing.metadata.stall_offline_id,
1101
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1102
+ stall_offline_updated_at: now,
1103
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1104
+ }
632
1105
  };
633
1106
  await local_db.orders.put(updated_order);
634
1107
  await add_to_sync_queue({
635
1108
  action: "update",
636
1109
  table: "orders",
637
1110
  document_id: item.id,
638
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
639
- stall_offline_id: existing.stall_offline_id,
1111
+ stall_offline_id: existing.metadata.stall_offline_id,
640
1112
  data: updated_order
641
1113
  });
642
1114
  updated_orders.push(updated_order);
@@ -661,8 +1133,7 @@ var bulk_delete2 = async (props) => {
661
1133
  action: "delete",
662
1134
  table: "orders",
663
1135
  document_id: id,
664
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
665
- stall_offline_id: existing.stall_offline_id,
1136
+ stall_offline_id: existing.metadata.stall_offline_id,
666
1137
  data: { id }
667
1138
  });
668
1139
  await local_db.orders.delete(id);
@@ -729,11 +1200,11 @@ var create3 = async (props) => {
729
1200
  id: offline_id,
730
1201
  metadata: {
731
1202
  ...data.metadata,
732
- stall_offline_id: offline_id
733
- },
734
- stall_offline_id: offline_id,
735
- stall_offline_created_at: now,
736
- stall_offline_updated_at: now
1203
+ stall_offline_id: offline_id,
1204
+ stall_offline_created_at: now,
1205
+ stall_offline_updated_at: now,
1206
+ stall_offline_deleted_at: ""
1207
+ }
737
1208
  };
738
1209
  await local_db.customers.add(local_customer);
739
1210
  await add_to_sync_queue({
@@ -760,17 +1231,21 @@ var update3 = async (props) => {
760
1231
  ...existing,
761
1232
  ...data,
762
1233
  id: existing.id,
763
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
764
- stall_offline_id: existing.stall_offline_id,
765
- stall_offline_updated_at: now
1234
+ metadata: {
1235
+ ...existing.metadata,
1236
+ ...data.metadata,
1237
+ stall_offline_id: existing.metadata.stall_offline_id,
1238
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1239
+ stall_offline_updated_at: now,
1240
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1241
+ }
766
1242
  };
767
1243
  await local_db.customers.put(updated_customer);
768
1244
  await add_to_sync_queue({
769
1245
  action: "update",
770
1246
  table: "customers",
771
1247
  document_id: id,
772
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
773
- stall_offline_id: existing.stall_offline_id,
1248
+ stall_offline_id: existing.metadata.stall_offline_id,
774
1249
  data: updated_customer
775
1250
  });
776
1251
  return updated_customer;
@@ -789,8 +1264,7 @@ var _delete3 = async (props) => {
789
1264
  action: "delete",
790
1265
  table: "customers",
791
1266
  document_id: id,
792
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
793
- stall_offline_id: existing.stall_offline_id,
1267
+ stall_offline_id: existing.metadata.stall_offline_id,
794
1268
  data: { id }
795
1269
  });
796
1270
  await local_db.customers.delete(id);
@@ -811,11 +1285,11 @@ var bulk_create3 = async (props) => {
811
1285
  id: offline_id,
812
1286
  metadata: {
813
1287
  ...customer.metadata,
814
- stall_offline_id: offline_id
815
- },
816
- stall_offline_id: offline_id,
817
- stall_offline_created_at: now,
818
- stall_offline_updated_at: now
1288
+ stall_offline_id: offline_id,
1289
+ stall_offline_created_at: now,
1290
+ stall_offline_updated_at: now,
1291
+ stall_offline_deleted_at: ""
1292
+ }
819
1293
  };
820
1294
  await local_db.customers.add(local_customer);
821
1295
  await add_to_sync_queue({
@@ -847,17 +1321,21 @@ var bulk_update3 = async (props) => {
847
1321
  ...existing,
848
1322
  ...item.data,
849
1323
  id: existing.id,
850
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
851
- stall_offline_id: existing.stall_offline_id,
852
- stall_offline_updated_at: now
1324
+ metadata: {
1325
+ ...existing.metadata,
1326
+ ...item.data.metadata,
1327
+ stall_offline_id: existing.metadata.stall_offline_id,
1328
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1329
+ stall_offline_updated_at: now,
1330
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1331
+ }
853
1332
  };
854
1333
  await local_db.customers.put(updated_customer);
855
1334
  await add_to_sync_queue({
856
1335
  action: "update",
857
1336
  table: "customers",
858
1337
  document_id: item.id,
859
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
860
- stall_offline_id: existing.stall_offline_id,
1338
+ stall_offline_id: existing.metadata.stall_offline_id,
861
1339
  data: updated_customer
862
1340
  });
863
1341
  updated_customers.push(updated_customer);
@@ -880,8 +1358,7 @@ var bulk_delete3 = async (props) => {
880
1358
  action: "delete",
881
1359
  table: "customers",
882
1360
  document_id: id,
883
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
884
- stall_offline_id: existing.stall_offline_id,
1361
+ stall_offline_id: existing.metadata.stall_offline_id,
885
1362
  data: { id }
886
1363
  });
887
1364
  await local_db.customers.delete(id);
@@ -946,11 +1423,11 @@ var create4 = async (props) => {
946
1423
  id: offline_id,
947
1424
  metadata: {
948
1425
  ...data.metadata,
949
- stall_offline_id: offline_id
950
- },
951
- stall_offline_id: offline_id,
952
- stall_offline_created_at: now,
953
- stall_offline_updated_at: now
1426
+ stall_offline_id: offline_id,
1427
+ stall_offline_created_at: now,
1428
+ stall_offline_updated_at: now,
1429
+ stall_offline_deleted_at: ""
1430
+ }
954
1431
  };
955
1432
  await local_db.collections.add(local_collection);
956
1433
  await add_to_sync_queue({
@@ -977,17 +1454,21 @@ var update4 = async (props) => {
977
1454
  ...existing,
978
1455
  ...data,
979
1456
  id: existing.id,
980
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
981
- stall_offline_id: existing.stall_offline_id,
982
- stall_offline_updated_at: now
1457
+ metadata: {
1458
+ ...existing.metadata,
1459
+ ...data.metadata,
1460
+ stall_offline_id: existing.metadata.stall_offline_id,
1461
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1462
+ stall_offline_updated_at: now,
1463
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1464
+ }
983
1465
  };
984
1466
  await local_db.collections.put(updated_collection);
985
1467
  await add_to_sync_queue({
986
1468
  action: "update",
987
1469
  table: "collections",
988
1470
  document_id: id,
989
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
990
- stall_offline_id: existing.stall_offline_id,
1471
+ stall_offline_id: existing.metadata.stall_offline_id,
991
1472
  data: updated_collection
992
1473
  });
993
1474
  return updated_collection;
@@ -1006,8 +1487,7 @@ var _delete4 = async (props) => {
1006
1487
  action: "delete",
1007
1488
  table: "collections",
1008
1489
  document_id: id,
1009
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1010
- stall_offline_id: existing.stall_offline_id,
1490
+ stall_offline_id: existing.metadata.stall_offline_id,
1011
1491
  data: { id }
1012
1492
  });
1013
1493
  await local_db.collections.delete(id);
@@ -1028,11 +1508,11 @@ var bulk_create4 = async (props) => {
1028
1508
  id: offline_id,
1029
1509
  metadata: {
1030
1510
  ...collection.metadata,
1031
- stall_offline_id: offline_id
1032
- },
1033
- stall_offline_id: offline_id,
1034
- stall_offline_created_at: now,
1035
- stall_offline_updated_at: now
1511
+ stall_offline_id: offline_id,
1512
+ stall_offline_created_at: now,
1513
+ stall_offline_updated_at: now,
1514
+ stall_offline_deleted_at: ""
1515
+ }
1036
1516
  };
1037
1517
  await local_db.collections.add(local_collection);
1038
1518
  await add_to_sync_queue({
@@ -1066,17 +1546,21 @@ var bulk_update4 = async (props) => {
1066
1546
  ...existing,
1067
1547
  ...item.data,
1068
1548
  id: existing.id,
1069
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1070
- stall_offline_id: existing.stall_offline_id,
1071
- stall_offline_updated_at: now
1549
+ metadata: {
1550
+ ...existing.metadata,
1551
+ ...item.data.metadata,
1552
+ stall_offline_id: existing.metadata.stall_offline_id,
1553
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1554
+ stall_offline_updated_at: now,
1555
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1556
+ }
1072
1557
  };
1073
1558
  await local_db.collections.put(updated_collection);
1074
1559
  await add_to_sync_queue({
1075
1560
  action: "update",
1076
1561
  table: "collections",
1077
1562
  document_id: item.id,
1078
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1079
- stall_offline_id: existing.stall_offline_id,
1563
+ stall_offline_id: existing.metadata.stall_offline_id,
1080
1564
  data: updated_collection
1081
1565
  });
1082
1566
  updated_collections.push(updated_collection);
@@ -1099,8 +1583,7 @@ var bulk_delete4 = async (props) => {
1099
1583
  action: "delete",
1100
1584
  table: "collections",
1101
1585
  document_id: id,
1102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1103
- stall_offline_id: existing.stall_offline_id,
1586
+ stall_offline_id: existing.metadata.stall_offline_id,
1104
1587
  data: { id }
1105
1588
  });
1106
1589
  await local_db.collections.delete(id);
@@ -1165,11 +1648,11 @@ var create5 = async (props) => {
1165
1648
  id: offline_id,
1166
1649
  metadata: {
1167
1650
  ...data.metadata,
1168
- stall_offline_id: offline_id
1169
- },
1170
- stall_offline_id: offline_id,
1171
- stall_offline_created_at: now,
1172
- stall_offline_updated_at: now
1651
+ stall_offline_id: offline_id,
1652
+ stall_offline_created_at: now,
1653
+ stall_offline_updated_at: now,
1654
+ stall_offline_deleted_at: ""
1655
+ }
1173
1656
  };
1174
1657
  await local_db.categories.add(local_category);
1175
1658
  await add_to_sync_queue({
@@ -1196,17 +1679,21 @@ var update5 = async (props) => {
1196
1679
  ...existing,
1197
1680
  ...data,
1198
1681
  id: existing.id,
1199
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1200
- stall_offline_id: existing.stall_offline_id,
1201
- stall_offline_updated_at: now
1682
+ metadata: {
1683
+ ...existing.metadata,
1684
+ ...data.metadata,
1685
+ stall_offline_id: existing.metadata.stall_offline_id,
1686
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1687
+ stall_offline_updated_at: now,
1688
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1689
+ }
1202
1690
  };
1203
1691
  await local_db.categories.put(updated_category);
1204
1692
  await add_to_sync_queue({
1205
1693
  action: "update",
1206
1694
  table: "categories",
1207
1695
  document_id: id,
1208
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1209
- stall_offline_id: existing.stall_offline_id,
1696
+ stall_offline_id: existing.metadata.stall_offline_id,
1210
1697
  data: updated_category
1211
1698
  });
1212
1699
  return updated_category;
@@ -1225,8 +1712,7 @@ var _delete5 = async (props) => {
1225
1712
  action: "delete",
1226
1713
  table: "categories",
1227
1714
  document_id: id,
1228
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1229
- stall_offline_id: existing.stall_offline_id,
1715
+ stall_offline_id: existing.metadata.stall_offline_id,
1230
1716
  data: { id }
1231
1717
  });
1232
1718
  await local_db.categories.delete(id);
@@ -1247,11 +1733,11 @@ var bulk_create5 = async (props) => {
1247
1733
  id: offline_id,
1248
1734
  metadata: {
1249
1735
  ...category.metadata,
1250
- stall_offline_id: offline_id
1251
- },
1252
- stall_offline_id: offline_id,
1253
- stall_offline_created_at: now,
1254
- stall_offline_updated_at: now
1736
+ stall_offline_id: offline_id,
1737
+ stall_offline_created_at: now,
1738
+ stall_offline_updated_at: now,
1739
+ stall_offline_deleted_at: ""
1740
+ }
1255
1741
  };
1256
1742
  await local_db.categories.add(local_category);
1257
1743
  await add_to_sync_queue({
@@ -1283,17 +1769,21 @@ var bulk_update5 = async (props) => {
1283
1769
  ...existing,
1284
1770
  ...item.data,
1285
1771
  id: existing.id,
1286
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1287
- stall_offline_id: existing.stall_offline_id,
1288
- stall_offline_updated_at: now
1772
+ metadata: {
1773
+ ...existing.metadata,
1774
+ ...item.data.metadata,
1775
+ stall_offline_id: existing.metadata.stall_offline_id,
1776
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1777
+ stall_offline_updated_at: now,
1778
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1779
+ }
1289
1780
  };
1290
1781
  await local_db.categories.put(updated_category);
1291
1782
  await add_to_sync_queue({
1292
1783
  action: "update",
1293
1784
  table: "categories",
1294
1785
  document_id: item.id,
1295
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1296
- stall_offline_id: existing.stall_offline_id,
1786
+ stall_offline_id: existing.metadata.stall_offline_id,
1297
1787
  data: updated_category
1298
1788
  });
1299
1789
  updated_categories.push(updated_category);
@@ -1316,8 +1806,7 @@ var bulk_delete5 = async (props) => {
1316
1806
  action: "delete",
1317
1807
  table: "categories",
1318
1808
  document_id: id,
1319
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1320
- stall_offline_id: existing.stall_offline_id,
1809
+ stall_offline_id: existing.metadata.stall_offline_id,
1321
1810
  data: { id }
1322
1811
  });
1323
1812
  await local_db.categories.delete(id);
@@ -1382,11 +1871,11 @@ var create6 = async (props) => {
1382
1871
  id: offline_id,
1383
1872
  metadata: {
1384
1873
  ...data.metadata,
1385
- stall_offline_id: offline_id
1386
- },
1387
- stall_offline_id: offline_id,
1388
- stall_offline_created_at: now,
1389
- stall_offline_updated_at: now
1874
+ stall_offline_id: offline_id,
1875
+ stall_offline_created_at: now,
1876
+ stall_offline_updated_at: now,
1877
+ stall_offline_deleted_at: ""
1878
+ }
1390
1879
  };
1391
1880
  await local_db.variants.add(local_variant);
1392
1881
  await add_to_sync_queue({
@@ -1413,17 +1902,21 @@ var update6 = async (props) => {
1413
1902
  ...existing,
1414
1903
  ...data,
1415
1904
  id: existing.id,
1416
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1417
- stall_offline_id: existing.stall_offline_id,
1418
- stall_offline_updated_at: now
1905
+ metadata: {
1906
+ ...existing.metadata,
1907
+ ...data.metadata,
1908
+ stall_offline_id: existing.metadata.stall_offline_id,
1909
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1910
+ stall_offline_updated_at: now,
1911
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1912
+ }
1419
1913
  };
1420
1914
  await local_db.variants.put(updated_variant);
1421
1915
  await add_to_sync_queue({
1422
1916
  action: "update",
1423
1917
  table: "variants",
1424
1918
  document_id: id,
1425
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1426
- stall_offline_id: existing.stall_offline_id,
1919
+ stall_offline_id: existing.metadata.stall_offline_id,
1427
1920
  data: updated_variant
1428
1921
  });
1429
1922
  return updated_variant;
@@ -1442,8 +1935,7 @@ var _delete6 = async (props) => {
1442
1935
  action: "delete",
1443
1936
  table: "variants",
1444
1937
  document_id: id,
1445
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1446
- stall_offline_id: existing.stall_offline_id,
1938
+ stall_offline_id: existing.metadata.stall_offline_id,
1447
1939
  data: { id }
1448
1940
  });
1449
1941
  await local_db.variants.delete(id);
@@ -1464,11 +1956,11 @@ var bulk_create6 = async (props) => {
1464
1956
  id: offline_id,
1465
1957
  metadata: {
1466
1958
  ...variant.metadata,
1467
- stall_offline_id: offline_id
1468
- },
1469
- stall_offline_id: offline_id,
1470
- stall_offline_created_at: now,
1471
- stall_offline_updated_at: now
1959
+ stall_offline_id: offline_id,
1960
+ stall_offline_created_at: now,
1961
+ stall_offline_updated_at: now,
1962
+ stall_offline_deleted_at: ""
1963
+ }
1472
1964
  };
1473
1965
  await local_db.variants.add(local_variant);
1474
1966
  await add_to_sync_queue({
@@ -1500,17 +1992,21 @@ var bulk_update6 = async (props) => {
1500
1992
  ...existing,
1501
1993
  ...item.data,
1502
1994
  id: existing.id,
1503
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1504
- stall_offline_id: existing.stall_offline_id,
1505
- stall_offline_updated_at: now
1995
+ metadata: {
1996
+ ...existing.metadata,
1997
+ ...item.data.metadata,
1998
+ stall_offline_id: existing.metadata.stall_offline_id,
1999
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2000
+ stall_offline_updated_at: now,
2001
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2002
+ }
1506
2003
  };
1507
2004
  await local_db.variants.put(updated_variant);
1508
2005
  await add_to_sync_queue({
1509
2006
  action: "update",
1510
2007
  table: "variants",
1511
2008
  document_id: item.id,
1512
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1513
- stall_offline_id: existing.stall_offline_id,
2009
+ stall_offline_id: existing.metadata.stall_offline_id,
1514
2010
  data: updated_variant
1515
2011
  });
1516
2012
  updated_variants.push(updated_variant);
@@ -1533,8 +2029,7 @@ var bulk_delete6 = async (props) => {
1533
2029
  action: "delete",
1534
2030
  table: "variants",
1535
2031
  document_id: id,
1536
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1537
- stall_offline_id: existing.stall_offline_id,
2032
+ stall_offline_id: existing.metadata.stall_offline_id,
1538
2033
  data: { id }
1539
2034
  });
1540
2035
  await local_db.variants.delete(id);
@@ -1599,12 +2094,11 @@ var create7 = async (props) => {
1599
2094
  id: offline_id,
1600
2095
  metadata: {
1601
2096
  ...data.metadata,
1602
- stall_offline_id: offline_id
1603
- },
1604
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1605
- stall_offline_id: offline_id,
1606
- stall_offline_created_at: now,
1607
- stall_offline_updated_at: now
2097
+ stall_offline_id: offline_id,
2098
+ stall_offline_created_at: now,
2099
+ stall_offline_updated_at: now,
2100
+ stall_offline_deleted_at: ""
2101
+ }
1608
2102
  };
1609
2103
  await local_db.inventory_levels.add(local_inventory_level);
1610
2104
  await add_to_sync_queue({
@@ -1631,17 +2125,21 @@ var update7 = async (props) => {
1631
2125
  ...existing,
1632
2126
  ...data,
1633
2127
  id: existing.id,
1634
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1635
- stall_offline_id: existing.stall_offline_id,
1636
- stall_offline_updated_at: now
2128
+ metadata: {
2129
+ ...existing.metadata,
2130
+ ...data.metadata,
2131
+ stall_offline_id: existing.metadata.stall_offline_id,
2132
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2133
+ stall_offline_updated_at: now,
2134
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2135
+ }
1637
2136
  };
1638
2137
  await local_db.inventory_levels.put(updated_inventory_level);
1639
2138
  await add_to_sync_queue({
1640
2139
  action: "update",
1641
2140
  table: "inventory_levels",
1642
2141
  document_id: id,
1643
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1644
- stall_offline_id: existing.stall_offline_id,
2142
+ stall_offline_id: existing.metadata.stall_offline_id,
1645
2143
  data: updated_inventory_level
1646
2144
  });
1647
2145
  return updated_inventory_level;
@@ -1660,8 +2158,7 @@ var _delete7 = async (props) => {
1660
2158
  action: "delete",
1661
2159
  table: "inventory_levels",
1662
2160
  document_id: id,
1663
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1664
- stall_offline_id: existing.stall_offline_id,
2161
+ stall_offline_id: existing.metadata.stall_offline_id,
1665
2162
  data: { id }
1666
2163
  });
1667
2164
  await local_db.inventory_levels.delete(id);
@@ -1682,12 +2179,11 @@ var bulk_create7 = async (props) => {
1682
2179
  id: offline_id,
1683
2180
  metadata: {
1684
2181
  ...inventory_level.metadata,
1685
- stall_offline_id: offline_id
1686
- },
1687
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1688
- stall_offline_id: offline_id,
1689
- stall_offline_created_at: now,
1690
- stall_offline_updated_at: now
2182
+ stall_offline_id: offline_id,
2183
+ stall_offline_created_at: now,
2184
+ stall_offline_updated_at: now,
2185
+ stall_offline_deleted_at: ""
2186
+ }
1691
2187
  };
1692
2188
  await local_db.inventory_levels.add(local_inventory_level);
1693
2189
  await add_to_sync_queue({
@@ -1721,17 +2217,21 @@ var bulk_update7 = async (props) => {
1721
2217
  ...existing,
1722
2218
  ...item.data,
1723
2219
  id: existing.id,
1724
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1725
- stall_offline_id: existing.stall_offline_id,
1726
- stall_offline_updated_at: now
2220
+ metadata: {
2221
+ ...existing.metadata,
2222
+ ...item.data.metadata,
2223
+ stall_offline_id: existing.metadata.stall_offline_id,
2224
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2225
+ stall_offline_updated_at: now,
2226
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2227
+ }
1727
2228
  };
1728
2229
  await local_db.inventory_levels.put(updated_inventory_level);
1729
2230
  await add_to_sync_queue({
1730
2231
  action: "update",
1731
2232
  table: "inventory_levels",
1732
2233
  document_id: item.id,
1733
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1734
- stall_offline_id: existing.stall_offline_id,
2234
+ stall_offline_id: existing.metadata.stall_offline_id,
1735
2235
  data: updated_inventory_level
1736
2236
  });
1737
2237
  updated_inventory_levels.push(updated_inventory_level);
@@ -1756,8 +2256,7 @@ var bulk_delete7 = async (props) => {
1756
2256
  action: "delete",
1757
2257
  table: "inventory_levels",
1758
2258
  document_id: id,
1759
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1760
- stall_offline_id: existing.stall_offline_id,
2259
+ stall_offline_id: existing.metadata.stall_offline_id,
1761
2260
  data: { id }
1762
2261
  });
1763
2262
  await local_db.inventory_levels.delete(id);
@@ -1822,12 +2321,11 @@ var create8 = async (props) => {
1822
2321
  id: offline_id,
1823
2322
  metadata: {
1824
2323
  ...data.metadata,
1825
- stall_offline_id: offline_id
1826
- },
1827
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1828
- stall_offline_id: offline_id,
1829
- stall_offline_created_at: now,
1830
- stall_offline_updated_at: now
2324
+ stall_offline_id: offline_id,
2325
+ stall_offline_created_at: now,
2326
+ stall_offline_updated_at: now,
2327
+ stall_offline_deleted_at: ""
2328
+ }
1831
2329
  };
1832
2330
  await local_db.promotions.add(local_promotion);
1833
2331
  await add_to_sync_queue({
@@ -1854,17 +2352,21 @@ var update8 = async (props) => {
1854
2352
  ...existing,
1855
2353
  ...data,
1856
2354
  id: existing.id,
1857
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1858
- stall_offline_id: existing.stall_offline_id,
1859
- stall_offline_updated_at: now
2355
+ metadata: {
2356
+ ...existing.metadata,
2357
+ ...data.metadata,
2358
+ stall_offline_id: existing.metadata.stall_offline_id,
2359
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2360
+ stall_offline_updated_at: now,
2361
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2362
+ }
1860
2363
  };
1861
2364
  await local_db.promotions.put(updated_promotion);
1862
2365
  await add_to_sync_queue({
1863
2366
  action: "update",
1864
2367
  table: "promotions",
1865
2368
  document_id: id,
1866
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1867
- stall_offline_id: existing.stall_offline_id,
2369
+ stall_offline_id: existing.metadata.stall_offline_id,
1868
2370
  data: updated_promotion
1869
2371
  });
1870
2372
  return updated_promotion;
@@ -1883,8 +2385,7 @@ var _delete8 = async (props) => {
1883
2385
  action: "delete",
1884
2386
  table: "promotions",
1885
2387
  document_id: id,
1886
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1887
- stall_offline_id: existing.stall_offline_id,
2388
+ stall_offline_id: existing.metadata.stall_offline_id,
1888
2389
  data: { id }
1889
2390
  });
1890
2391
  await local_db.promotions.delete(id);
@@ -1905,12 +2406,11 @@ var bulk_create8 = async (props) => {
1905
2406
  id: offline_id,
1906
2407
  metadata: {
1907
2408
  ...promotion.metadata,
1908
- stall_offline_id: offline_id
1909
- },
1910
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1911
- stall_offline_id: offline_id,
1912
- stall_offline_created_at: now,
1913
- stall_offline_updated_at: now
2409
+ stall_offline_id: offline_id,
2410
+ stall_offline_created_at: now,
2411
+ stall_offline_updated_at: now,
2412
+ stall_offline_deleted_at: ""
2413
+ }
1914
2414
  };
1915
2415
  await local_db.promotions.add(local_promotion);
1916
2416
  await add_to_sync_queue({
@@ -1944,17 +2444,21 @@ var bulk_update8 = async (props) => {
1944
2444
  ...existing,
1945
2445
  ...item.data,
1946
2446
  id: existing.id,
1947
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1948
- stall_offline_id: existing.stall_offline_id,
1949
- stall_offline_updated_at: now
2447
+ metadata: {
2448
+ ...existing.metadata,
2449
+ ...item.data.metadata,
2450
+ stall_offline_id: existing.metadata.stall_offline_id,
2451
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2452
+ stall_offline_updated_at: now,
2453
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2454
+ }
1950
2455
  };
1951
2456
  await local_db.promotions.put(updated_promotion);
1952
2457
  await add_to_sync_queue({
1953
2458
  action: "update",
1954
2459
  table: "promotions",
1955
2460
  document_id: item.id,
1956
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1957
- stall_offline_id: existing.stall_offline_id,
2461
+ stall_offline_id: existing.metadata.stall_offline_id,
1958
2462
  data: updated_promotion
1959
2463
  });
1960
2464
  updated_promotions.push(updated_promotion);
@@ -1977,8 +2481,7 @@ var bulk_delete8 = async (props) => {
1977
2481
  action: "delete",
1978
2482
  table: "promotions",
1979
2483
  document_id: id,
1980
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1981
- stall_offline_id: existing.stall_offline_id,
2484
+ stall_offline_id: existing.metadata.stall_offline_id,
1982
2485
  data: { id }
1983
2486
  });
1984
2487
  await local_db.promotions.delete(id);
@@ -2043,12 +2546,11 @@ var create9 = async (props) => {
2043
2546
  id: offline_id,
2044
2547
  metadata: {
2045
2548
  ...data.metadata,
2046
- stall_offline_id: offline_id
2047
- },
2048
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2049
- stall_offline_id: offline_id,
2050
- stall_offline_created_at: now,
2051
- stall_offline_updated_at: now
2549
+ stall_offline_id: offline_id,
2550
+ stall_offline_created_at: now,
2551
+ stall_offline_updated_at: now,
2552
+ stall_offline_deleted_at: ""
2553
+ }
2052
2554
  };
2053
2555
  await local_db.order_notes.add(local_order_note);
2054
2556
  await add_to_sync_queue({
@@ -2075,17 +2577,21 @@ var update9 = async (props) => {
2075
2577
  ...existing,
2076
2578
  ...data,
2077
2579
  id: existing.id,
2078
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2079
- stall_offline_id: existing.stall_offline_id,
2080
- stall_offline_updated_at: now
2580
+ metadata: {
2581
+ ...existing.metadata,
2582
+ ...data.metadata,
2583
+ stall_offline_id: existing.metadata.stall_offline_id,
2584
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2585
+ stall_offline_updated_at: now,
2586
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2587
+ }
2081
2588
  };
2082
2589
  await local_db.order_notes.put(updated_order_note);
2083
2590
  await add_to_sync_queue({
2084
2591
  action: "update",
2085
2592
  table: "order_notes",
2086
2593
  document_id: id,
2087
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2088
- stall_offline_id: existing.stall_offline_id,
2594
+ stall_offline_id: existing.metadata.stall_offline_id,
2089
2595
  data: updated_order_note
2090
2596
  });
2091
2597
  return updated_order_note;
@@ -2104,8 +2610,7 @@ var _delete9 = async (props) => {
2104
2610
  action: "delete",
2105
2611
  table: "order_notes",
2106
2612
  document_id: id,
2107
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2108
- stall_offline_id: existing.stall_offline_id,
2613
+ stall_offline_id: existing.metadata.stall_offline_id,
2109
2614
  data: { id }
2110
2615
  });
2111
2616
  await local_db.order_notes.delete(id);
@@ -2126,12 +2631,11 @@ var bulk_create9 = async (props) => {
2126
2631
  id: offline_id,
2127
2632
  metadata: {
2128
2633
  ...order_note.metadata,
2129
- stall_offline_id: offline_id
2130
- },
2131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2132
- stall_offline_id: offline_id,
2133
- stall_offline_created_at: now,
2134
- stall_offline_updated_at: now
2634
+ stall_offline_id: offline_id,
2635
+ stall_offline_created_at: now,
2636
+ stall_offline_updated_at: now,
2637
+ stall_offline_deleted_at: ""
2638
+ }
2135
2639
  };
2136
2640
  await local_db.order_notes.add(local_order_note);
2137
2641
  await add_to_sync_queue({
@@ -2165,17 +2669,21 @@ var bulk_update9 = async (props) => {
2165
2669
  ...existing,
2166
2670
  ...item.data,
2167
2671
  id: existing.id,
2168
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2169
- stall_offline_id: existing.stall_offline_id,
2170
- stall_offline_updated_at: now
2672
+ metadata: {
2673
+ ...existing.metadata,
2674
+ ...item.data.metadata,
2675
+ stall_offline_id: existing.metadata.stall_offline_id,
2676
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2677
+ stall_offline_updated_at: now,
2678
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2679
+ }
2171
2680
  };
2172
2681
  await local_db.order_notes.put(updated_order_note);
2173
2682
  await add_to_sync_queue({
2174
2683
  action: "update",
2175
2684
  table: "order_notes",
2176
2685
  document_id: item.id,
2177
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2178
- stall_offline_id: existing.stall_offline_id,
2686
+ stall_offline_id: existing.metadata.stall_offline_id,
2179
2687
  data: updated_order_note
2180
2688
  });
2181
2689
  updated_order_notes.push(updated_order_note);
@@ -2198,8 +2706,7 @@ var bulk_delete9 = async (props) => {
2198
2706
  action: "delete",
2199
2707
  table: "order_notes",
2200
2708
  document_id: id,
2201
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2202
- stall_offline_id: existing.stall_offline_id,
2709
+ stall_offline_id: existing.metadata.stall_offline_id,
2203
2710
  data: { id }
2204
2711
  });
2205
2712
  await local_db.order_notes.delete(id);
@@ -2264,12 +2771,11 @@ var create10 = async (props) => {
2264
2771
  id: offline_id,
2265
2772
  metadata: {
2266
2773
  ...data.metadata,
2267
- stall_offline_id: offline_id
2268
- },
2269
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2270
- stall_offline_id: offline_id,
2271
- stall_offline_created_at: now,
2272
- stall_offline_updated_at: now
2774
+ stall_offline_id: offline_id,
2775
+ stall_offline_created_at: now,
2776
+ stall_offline_updated_at: now,
2777
+ stall_offline_deleted_at: ""
2778
+ }
2273
2779
  };
2274
2780
  await local_db.refunds.add(local_refund);
2275
2781
  await add_to_sync_queue({
@@ -2296,17 +2802,21 @@ var update10 = async (props) => {
2296
2802
  ...existing,
2297
2803
  ...data,
2298
2804
  id: existing.id,
2299
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2300
- stall_offline_id: existing.stall_offline_id,
2301
- stall_offline_updated_at: now
2805
+ metadata: {
2806
+ ...existing.metadata,
2807
+ ...data.metadata,
2808
+ stall_offline_id: existing.metadata.stall_offline_id,
2809
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2810
+ stall_offline_updated_at: now,
2811
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2812
+ }
2302
2813
  };
2303
2814
  await local_db.refunds.put(updated_refund);
2304
2815
  await add_to_sync_queue({
2305
2816
  action: "update",
2306
2817
  table: "refunds",
2307
2818
  document_id: id,
2308
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2309
- stall_offline_id: existing.stall_offline_id,
2819
+ stall_offline_id: existing.metadata.stall_offline_id,
2310
2820
  data: updated_refund
2311
2821
  });
2312
2822
  return updated_refund;
@@ -2325,8 +2835,7 @@ var _delete10 = async (props) => {
2325
2835
  action: "delete",
2326
2836
  table: "refunds",
2327
2837
  document_id: id,
2328
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2329
- stall_offline_id: existing.stall_offline_id,
2838
+ stall_offline_id: existing.metadata.stall_offline_id,
2330
2839
  data: { id }
2331
2840
  });
2332
2841
  await local_db.refunds.delete(id);
@@ -2347,12 +2856,11 @@ var bulk_create10 = async (props) => {
2347
2856
  id: offline_id,
2348
2857
  metadata: {
2349
2858
  ...refund.metadata,
2350
- stall_offline_id: offline_id
2351
- },
2352
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2353
- stall_offline_id: offline_id,
2354
- stall_offline_created_at: now,
2355
- stall_offline_updated_at: now
2859
+ stall_offline_id: offline_id,
2860
+ stall_offline_created_at: now,
2861
+ stall_offline_updated_at: now,
2862
+ stall_offline_deleted_at: ""
2863
+ }
2356
2864
  };
2357
2865
  await local_db.refunds.add(local_refund);
2358
2866
  await add_to_sync_queue({
@@ -2384,17 +2892,21 @@ var bulk_update10 = async (props) => {
2384
2892
  ...existing,
2385
2893
  ...item.data,
2386
2894
  id: existing.id,
2387
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2388
- stall_offline_id: existing.stall_offline_id,
2389
- stall_offline_updated_at: now
2895
+ metadata: {
2896
+ ...existing.metadata,
2897
+ ...item.data.metadata,
2898
+ stall_offline_id: existing.metadata.stall_offline_id,
2899
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2900
+ stall_offline_updated_at: now,
2901
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2902
+ }
2390
2903
  };
2391
2904
  await local_db.refunds.put(updated_refund);
2392
2905
  await add_to_sync_queue({
2393
2906
  action: "update",
2394
2907
  table: "refunds",
2395
2908
  document_id: item.id,
2396
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2397
- stall_offline_id: existing.stall_offline_id,
2909
+ stall_offline_id: existing.metadata.stall_offline_id,
2398
2910
  data: updated_refund
2399
2911
  });
2400
2912
  updated_refunds.push(updated_refund);
@@ -2417,8 +2929,7 @@ var bulk_delete10 = async (props) => {
2417
2929
  action: "delete",
2418
2930
  table: "refunds",
2419
2931
  document_id: id,
2420
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2421
- stall_offline_id: existing.stall_offline_id,
2932
+ stall_offline_id: existing.metadata.stall_offline_id,
2422
2933
  data: { id }
2423
2934
  });
2424
2935
  await local_db.refunds.delete(id);
@@ -2482,14 +2993,12 @@ var create11 = async (props) => {
2482
2993
  ...data,
2483
2994
  id: offline_id,
2484
2995
  metadata: {
2485
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2486
2996
  ...data.metadata,
2487
- stall_offline_id: offline_id
2488
- },
2489
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2490
- stall_offline_id: offline_id,
2491
- stall_offline_created_at: now,
2492
- stall_offline_updated_at: now
2997
+ stall_offline_id: offline_id,
2998
+ stall_offline_created_at: now,
2999
+ stall_offline_updated_at: now,
3000
+ stall_offline_deleted_at: ""
3001
+ }
2493
3002
  };
2494
3003
  await local_db.payment_providers.add(local_payment_provider);
2495
3004
  await add_to_sync_queue({
@@ -2516,17 +3025,21 @@ var update11 = async (props) => {
2516
3025
  ...existing,
2517
3026
  ...data,
2518
3027
  id: existing.id,
2519
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2520
- stall_offline_id: existing.stall_offline_id,
2521
- stall_offline_updated_at: now
3028
+ metadata: {
3029
+ ...existing.metadata,
3030
+ ...data.metadata,
3031
+ stall_offline_id: existing.metadata.stall_offline_id,
3032
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3033
+ stall_offline_updated_at: now,
3034
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3035
+ }
2522
3036
  };
2523
3037
  await local_db.payment_providers.put(updated_payment_provider);
2524
3038
  await add_to_sync_queue({
2525
3039
  action: "update",
2526
3040
  table: "payment_providers",
2527
3041
  document_id: id,
2528
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2529
- stall_offline_id: existing.stall_offline_id,
3042
+ stall_offline_id: existing.metadata.stall_offline_id,
2530
3043
  data: updated_payment_provider
2531
3044
  });
2532
3045
  return updated_payment_provider;
@@ -2545,8 +3058,7 @@ var _delete11 = async (props) => {
2545
3058
  action: "delete",
2546
3059
  table: "payment_providers",
2547
3060
  document_id: id,
2548
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2549
- stall_offline_id: existing.stall_offline_id,
3061
+ stall_offline_id: existing.metadata.stall_offline_id,
2550
3062
  data: { id }
2551
3063
  });
2552
3064
  await local_db.payment_providers.delete(id);
@@ -2566,14 +3078,12 @@ var bulk_create11 = async (props) => {
2566
3078
  ...payment_provider,
2567
3079
  id: offline_id,
2568
3080
  metadata: {
2569
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2570
3081
  ...payment_provider.metadata,
2571
- stall_offline_id: offline_id
2572
- },
2573
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2574
- stall_offline_id: offline_id,
2575
- stall_offline_created_at: now,
2576
- stall_offline_updated_at: now
3082
+ stall_offline_id: offline_id,
3083
+ stall_offline_created_at: now,
3084
+ stall_offline_updated_at: now,
3085
+ stall_offline_deleted_at: ""
3086
+ }
2577
3087
  };
2578
3088
  await local_db.payment_providers.add(local_payment_provider);
2579
3089
  await add_to_sync_queue({
@@ -2607,17 +3117,21 @@ var bulk_update11 = async (props) => {
2607
3117
  ...existing,
2608
3118
  ...item.data,
2609
3119
  id: existing.id,
2610
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2611
- stall_offline_id: existing.stall_offline_id,
2612
- stall_offline_updated_at: now
3120
+ metadata: {
3121
+ ...existing.metadata,
3122
+ ...item.data.metadata,
3123
+ stall_offline_id: existing.metadata.stall_offline_id,
3124
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3125
+ stall_offline_updated_at: now,
3126
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3127
+ }
2613
3128
  };
2614
3129
  await local_db.payment_providers.put(updated_payment_provider);
2615
3130
  await add_to_sync_queue({
2616
3131
  action: "update",
2617
3132
  table: "payment_providers",
2618
3133
  document_id: item.id,
2619
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2620
- stall_offline_id: existing.stall_offline_id,
3134
+ stall_offline_id: existing.metadata.stall_offline_id,
2621
3135
  data: updated_payment_provider
2622
3136
  });
2623
3137
  updated_payment_providers.push(updated_payment_provider);
@@ -2642,8 +3156,7 @@ var bulk_delete11 = async (props) => {
2642
3156
  action: "delete",
2643
3157
  table: "payment_providers",
2644
3158
  document_id: id,
2645
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2646
- stall_offline_id: existing.stall_offline_id,
3159
+ stall_offline_id: existing.metadata.stall_offline_id,
2647
3160
  data: { id }
2648
3161
  });
2649
3162
  await local_db.payment_providers.delete(id);
@@ -2708,12 +3221,11 @@ var create12 = async (props) => {
2708
3221
  id: offline_id,
2709
3222
  metadata: {
2710
3223
  ...data.metadata,
2711
- stall_offline_id: offline_id
2712
- },
2713
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2714
- stall_offline_id: offline_id,
2715
- stall_offline_created_at: now,
2716
- stall_offline_updated_at: now
3224
+ stall_offline_id: offline_id,
3225
+ stall_offline_created_at: now,
3226
+ stall_offline_updated_at: now,
3227
+ stall_offline_deleted_at: ""
3228
+ }
2717
3229
  };
2718
3230
  await local_db.payments.add(local_payment);
2719
3231
  await add_to_sync_queue({
@@ -2740,17 +3252,21 @@ var update12 = async (props) => {
2740
3252
  ...existing,
2741
3253
  ...data,
2742
3254
  id: existing.id,
2743
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2744
- stall_offline_id: existing.stall_offline_id,
2745
- stall_offline_updated_at: now
3255
+ metadata: {
3256
+ ...existing.metadata,
3257
+ ...data.metadata,
3258
+ stall_offline_id: existing.metadata.stall_offline_id,
3259
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3260
+ stall_offline_updated_at: now,
3261
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3262
+ }
2746
3263
  };
2747
3264
  await local_db.payments.put(updated_payment);
2748
3265
  await add_to_sync_queue({
2749
3266
  action: "update",
2750
3267
  table: "payments",
2751
3268
  document_id: id,
2752
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2753
- stall_offline_id: existing.stall_offline_id,
3269
+ stall_offline_id: existing.metadata.stall_offline_id,
2754
3270
  data: updated_payment
2755
3271
  });
2756
3272
  return updated_payment;
@@ -2769,8 +3285,7 @@ var _delete12 = async (props) => {
2769
3285
  action: "delete",
2770
3286
  table: "payments",
2771
3287
  document_id: id,
2772
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2773
- stall_offline_id: existing.stall_offline_id,
3288
+ stall_offline_id: existing.metadata.stall_offline_id,
2774
3289
  data: { id }
2775
3290
  });
2776
3291
  await local_db.payments.delete(id);
@@ -2791,12 +3306,11 @@ var bulk_create12 = async (props) => {
2791
3306
  id: offline_id,
2792
3307
  metadata: {
2793
3308
  ...payment.metadata,
2794
- stall_offline_id: offline_id
2795
- },
2796
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2797
- stall_offline_id: offline_id,
2798
- stall_offline_created_at: now,
2799
- stall_offline_updated_at: now
3309
+ stall_offline_id: offline_id,
3310
+ stall_offline_created_at: now,
3311
+ stall_offline_updated_at: now,
3312
+ stall_offline_deleted_at: ""
3313
+ }
2800
3314
  };
2801
3315
  await local_db.payments.add(local_payment);
2802
3316
  await add_to_sync_queue({
@@ -2828,17 +3342,21 @@ var bulk_update12 = async (props) => {
2828
3342
  ...existing,
2829
3343
  ...item.data,
2830
3344
  id: existing.id,
2831
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2832
- stall_offline_id: existing.stall_offline_id,
2833
- stall_offline_updated_at: now
3345
+ metadata: {
3346
+ ...existing.metadata,
3347
+ ...item.data.metadata,
3348
+ stall_offline_id: existing.metadata.stall_offline_id,
3349
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3350
+ stall_offline_updated_at: now,
3351
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3352
+ }
2834
3353
  };
2835
3354
  await local_db.payments.put(updated_payment);
2836
3355
  await add_to_sync_queue({
2837
3356
  action: "update",
2838
3357
  table: "payments",
2839
3358
  document_id: item.id,
2840
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2841
- stall_offline_id: existing.stall_offline_id,
3359
+ stall_offline_id: existing.metadata.stall_offline_id,
2842
3360
  data: updated_payment
2843
3361
  });
2844
3362
  updated_payments.push(updated_payment);
@@ -2861,8 +3379,7 @@ var bulk_delete12 = async (props) => {
2861
3379
  action: "delete",
2862
3380
  table: "payments",
2863
3381
  document_id: id,
2864
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2865
- stall_offline_id: existing.stall_offline_id,
3382
+ stall_offline_id: existing.metadata.stall_offline_id,
2866
3383
  data: { id }
2867
3384
  });
2868
3385
  await local_db.payments.delete(id);
@@ -2927,11 +3444,11 @@ var create13 = async (props) => {
2927
3444
  id: offline_id,
2928
3445
  metadata: {
2929
3446
  ...data.metadata,
2930
- stall_offline_id: offline_id
2931
- },
2932
- stall_offline_id: offline_id,
2933
- stall_offline_created_at: now,
2934
- stall_offline_updated_at: now
3447
+ stall_offline_id: offline_id,
3448
+ stall_offline_created_at: now,
3449
+ stall_offline_updated_at: now,
3450
+ stall_offline_deleted_at: ""
3451
+ }
2935
3452
  };
2936
3453
  await local_db.tax_regions.add(local_region);
2937
3454
  await add_to_sync_queue({
@@ -2958,17 +3475,21 @@ var update13 = async (props) => {
2958
3475
  ...existing,
2959
3476
  ...data,
2960
3477
  id: existing.id,
2961
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2962
- stall_offline_id: existing.stall_offline_id,
2963
- stall_offline_updated_at: now
3478
+ metadata: {
3479
+ ...existing.metadata,
3480
+ ...data.metadata,
3481
+ stall_offline_id: existing.metadata.stall_offline_id,
3482
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3483
+ stall_offline_updated_at: now,
3484
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3485
+ }
2964
3486
  };
2965
3487
  await local_db.tax_regions.put(updated_region);
2966
3488
  await add_to_sync_queue({
2967
3489
  action: "update",
2968
3490
  table: "tax_regions",
2969
3491
  document_id: id,
2970
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2971
- stall_offline_id: existing.stall_offline_id,
3492
+ stall_offline_id: existing.metadata.stall_offline_id,
2972
3493
  data: updated_region
2973
3494
  });
2974
3495
  return updated_region;
@@ -2987,8 +3508,7 @@ var _delete13 = async (props) => {
2987
3508
  action: "delete",
2988
3509
  table: "tax_regions",
2989
3510
  document_id: id,
2990
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2991
- stall_offline_id: existing.stall_offline_id,
3511
+ stall_offline_id: existing.metadata.stall_offline_id,
2992
3512
  data: { id }
2993
3513
  });
2994
3514
  await local_db.tax_regions.delete(id);
@@ -3009,11 +3529,11 @@ var bulk_create13 = async (props) => {
3009
3529
  id: offline_id,
3010
3530
  metadata: {
3011
3531
  ...region.metadata,
3012
- stall_offline_id: offline_id
3013
- },
3014
- stall_offline_id: offline_id,
3015
- stall_offline_created_at: now,
3016
- stall_offline_updated_at: now
3532
+ stall_offline_id: offline_id,
3533
+ stall_offline_created_at: now,
3534
+ stall_offline_updated_at: now,
3535
+ stall_offline_deleted_at: ""
3536
+ }
3017
3537
  };
3018
3538
  await local_db.tax_regions.add(local_region);
3019
3539
  await add_to_sync_queue({
@@ -3047,17 +3567,21 @@ var bulk_update13 = async (props) => {
3047
3567
  ...existing,
3048
3568
  ...item.data,
3049
3569
  id: existing.id,
3050
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3051
- stall_offline_id: existing.stall_offline_id,
3052
- stall_offline_updated_at: now
3570
+ metadata: {
3571
+ ...existing.metadata,
3572
+ ...item.data.metadata,
3573
+ stall_offline_id: existing.metadata.stall_offline_id,
3574
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3575
+ stall_offline_updated_at: now,
3576
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3577
+ }
3053
3578
  };
3054
3579
  await local_db.tax_regions.put(updated_region);
3055
3580
  await add_to_sync_queue({
3056
3581
  action: "update",
3057
3582
  table: "tax_regions",
3058
3583
  document_id: item.id,
3059
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3060
- stall_offline_id: existing.stall_offline_id,
3584
+ stall_offline_id: existing.metadata.stall_offline_id,
3061
3585
  data: updated_region
3062
3586
  });
3063
3587
  updated_regions.push(updated_region);
@@ -3080,8 +3604,7 @@ var bulk_delete13 = async (props) => {
3080
3604
  action: "delete",
3081
3605
  table: "tax_regions",
3082
3606
  document_id: id,
3083
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3084
- stall_offline_id: existing.stall_offline_id,
3607
+ stall_offline_id: existing.metadata.stall_offline_id,
3085
3608
  data: { id }
3086
3609
  });
3087
3610
  await local_db.tax_regions.delete(id);
@@ -3146,11 +3669,11 @@ var create14 = async (props) => {
3146
3669
  id: offline_id,
3147
3670
  metadata: {
3148
3671
  ...data.metadata,
3149
- stall_offline_id: offline_id
3150
- },
3151
- stall_offline_id: offline_id,
3152
- stall_offline_created_at: now,
3153
- stall_offline_updated_at: now
3672
+ stall_offline_id: offline_id,
3673
+ stall_offline_created_at: now,
3674
+ stall_offline_updated_at: now,
3675
+ stall_offline_deleted_at: ""
3676
+ }
3154
3677
  };
3155
3678
  await local_db.tax_rates.add(local_rate);
3156
3679
  await add_to_sync_queue({
@@ -3177,17 +3700,21 @@ var update14 = async (props) => {
3177
3700
  ...existing,
3178
3701
  ...data,
3179
3702
  id: existing.id,
3180
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3181
- stall_offline_id: existing.stall_offline_id,
3182
- stall_offline_updated_at: now
3703
+ metadata: {
3704
+ ...existing.metadata,
3705
+ ...data.metadata,
3706
+ stall_offline_id: existing.metadata.stall_offline_id,
3707
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3708
+ stall_offline_updated_at: now,
3709
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3710
+ }
3183
3711
  };
3184
3712
  await local_db.tax_rates.put(updated_rate);
3185
3713
  await add_to_sync_queue({
3186
3714
  action: "update",
3187
3715
  table: "tax_rates",
3188
3716
  document_id: id,
3189
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3190
- stall_offline_id: existing.stall_offline_id,
3717
+ stall_offline_id: existing.metadata.stall_offline_id,
3191
3718
  data: updated_rate
3192
3719
  });
3193
3720
  return updated_rate;
@@ -3206,8 +3733,7 @@ var _delete14 = async (props) => {
3206
3733
  action: "delete",
3207
3734
  table: "tax_rates",
3208
3735
  document_id: id,
3209
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3210
- stall_offline_id: existing.stall_offline_id,
3736
+ stall_offline_id: existing.metadata.stall_offline_id,
3211
3737
  data: { id }
3212
3738
  });
3213
3739
  await local_db.tax_rates.delete(id);
@@ -3228,11 +3754,11 @@ var bulk_create14 = async (props) => {
3228
3754
  id: offline_id,
3229
3755
  metadata: {
3230
3756
  ...rate.metadata,
3231
- stall_offline_id: offline_id
3232
- },
3233
- stall_offline_id: offline_id,
3234
- stall_offline_created_at: now,
3235
- stall_offline_updated_at: now
3757
+ stall_offline_id: offline_id,
3758
+ stall_offline_created_at: now,
3759
+ stall_offline_updated_at: now,
3760
+ stall_offline_deleted_at: ""
3761
+ }
3236
3762
  };
3237
3763
  await local_db.tax_rates.add(local_rate);
3238
3764
  await add_to_sync_queue({
@@ -3264,17 +3790,21 @@ var bulk_update14 = async (props) => {
3264
3790
  ...existing,
3265
3791
  ...item.data,
3266
3792
  id: existing.id,
3267
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3268
- stall_offline_id: existing.stall_offline_id,
3269
- stall_offline_updated_at: now
3793
+ metadata: {
3794
+ ...existing.metadata,
3795
+ ...item.data.metadata,
3796
+ stall_offline_id: existing.metadata.stall_offline_id,
3797
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3798
+ stall_offline_updated_at: now,
3799
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3800
+ }
3270
3801
  };
3271
3802
  await local_db.tax_rates.put(updated_rate);
3272
3803
  await add_to_sync_queue({
3273
3804
  action: "update",
3274
3805
  table: "tax_rates",
3275
3806
  document_id: item.id,
3276
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3277
- stall_offline_id: existing.stall_offline_id,
3807
+ stall_offline_id: existing.metadata.stall_offline_id,
3278
3808
  data: updated_rate
3279
3809
  });
3280
3810
  updated_rates.push(updated_rate);
@@ -3297,8 +3827,7 @@ var bulk_delete14 = async (props) => {
3297
3827
  action: "delete",
3298
3828
  table: "tax_rates",
3299
3829
  document_id: id,
3300
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3301
- stall_offline_id: existing.stall_offline_id,
3830
+ stall_offline_id: existing.metadata.stall_offline_id,
3302
3831
  data: { id }
3303
3832
  });
3304
3833
  await local_db.tax_rates.delete(id);
@@ -3320,6 +3849,53 @@ var tax_rates = {
3320
3849
  };
3321
3850
 
3322
3851
  // src/services/locations.service.ts
3852
+ var build_location = (data, offline_id, now) => {
3853
+ return {
3854
+ id: offline_id,
3855
+ name: data.name || "",
3856
+ address: data.address || "",
3857
+ city: data.city || "",
3858
+ country: data.country || "",
3859
+ region: data.region || "",
3860
+ base_currency: data.base_currency || "",
3861
+ timezone: data.timezone || "",
3862
+ organization_id: data.organization_id || "",
3863
+ created_at: data.created_at || now,
3864
+ updated_at: data.updated_at || now,
3865
+ active: data.active ?? true,
3866
+ metadata: {
3867
+ ...data.metadata,
3868
+ stall_offline_id: offline_id,
3869
+ stall_offline_created_at: now,
3870
+ stall_offline_updated_at: now,
3871
+ stall_offline_deleted_at: ""
3872
+ }
3873
+ };
3874
+ };
3875
+ var merge_location = (existing, updates, now) => {
3876
+ return {
3877
+ id: existing.id,
3878
+ name: updates.name ?? existing.name,
3879
+ address: updates.address ?? existing.address,
3880
+ city: updates.city ?? existing.city,
3881
+ country: updates.country ?? existing.country,
3882
+ region: updates.region ?? existing.region,
3883
+ base_currency: updates.base_currency ?? existing.base_currency,
3884
+ timezone: updates.timezone ?? existing.timezone,
3885
+ organization_id: updates.organization_id ?? existing.organization_id,
3886
+ created_at: existing.created_at,
3887
+ updated_at: now,
3888
+ active: updates.active ?? existing.active,
3889
+ metadata: {
3890
+ ...existing.metadata,
3891
+ ...updates.metadata,
3892
+ stall_offline_id: existing.metadata?.stall_offline_id || "",
3893
+ stall_offline_created_at: existing.metadata?.stall_offline_created_at || "",
3894
+ stall_offline_updated_at: now,
3895
+ stall_offline_deleted_at: existing.metadata?.stall_offline_deleted_at || ""
3896
+ }
3897
+ };
3898
+ };
3323
3899
  var list15 = async (props) => {
3324
3900
  try {
3325
3901
  const { sdk, query } = props;
@@ -3358,18 +3934,7 @@ var create15 = async (props) => {
3358
3934
  const { sdk, data } = props;
3359
3935
  const offline_id = generate_offline_id("location");
3360
3936
  const now = (/* @__PURE__ */ new Date()).toISOString();
3361
- const local_location = {
3362
- ...data,
3363
- id: offline_id,
3364
- metadata: {
3365
- ...data.metadata,
3366
- stall_offline_id: offline_id
3367
- },
3368
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3369
- stall_offline_id: offline_id,
3370
- stall_offline_created_at: now,
3371
- stall_offline_updated_at: now
3372
- };
3937
+ const local_location = build_location(data, offline_id, now);
3373
3938
  await local_db.locations.add(local_location);
3374
3939
  await add_to_sync_queue({
3375
3940
  action: "create",
@@ -3391,21 +3956,13 @@ var update15 = async (props) => {
3391
3956
  throw new Error(`Location with id ${id} not found locally`);
3392
3957
  }
3393
3958
  const now = (/* @__PURE__ */ new Date()).toISOString();
3394
- const updated_location = {
3395
- ...existing,
3396
- ...data,
3397
- id: existing.id,
3398
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3399
- stall_offline_id: existing.stall_offline_id,
3400
- stall_offline_updated_at: now
3401
- };
3959
+ const updated_location = merge_location(existing, data, now);
3402
3960
  await local_db.locations.put(updated_location);
3403
3961
  await add_to_sync_queue({
3404
3962
  action: "update",
3405
3963
  table: "locations",
3406
3964
  document_id: id,
3407
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3408
- stall_offline_id: existing.stall_offline_id,
3965
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3409
3966
  data: updated_location
3410
3967
  });
3411
3968
  return updated_location;
@@ -3424,8 +3981,7 @@ var _delete15 = async (props) => {
3424
3981
  action: "delete",
3425
3982
  table: "locations",
3426
3983
  document_id: id,
3427
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3428
- stall_offline_id: existing.stall_offline_id,
3984
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3429
3985
  data: { id }
3430
3986
  });
3431
3987
  await local_db.locations.delete(id);
@@ -3441,18 +3997,7 @@ var bulk_create15 = async (props) => {
3441
3997
  const created_locations = [];
3442
3998
  for (const location of data) {
3443
3999
  const offline_id = generate_offline_id("location");
3444
- const local_location = {
3445
- ...location,
3446
- id: offline_id,
3447
- metadata: {
3448
- ...location.metadata,
3449
- stall_offline_id: offline_id
3450
- },
3451
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3452
- stall_offline_id: offline_id,
3453
- stall_offline_created_at: now,
3454
- stall_offline_updated_at: now
3455
- };
4000
+ const local_location = build_location(location, offline_id, now);
3456
4001
  await local_db.locations.add(local_location);
3457
4002
  await add_to_sync_queue({
3458
4003
  action: "create",
@@ -3479,21 +4024,13 @@ var bulk_update15 = async (props) => {
3479
4024
  console.warn(`Location with id ${item.id} not found locally, skipping`);
3480
4025
  continue;
3481
4026
  }
3482
- const updated_location = {
3483
- ...existing,
3484
- ...item.data,
3485
- id: existing.id,
3486
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3487
- stall_offline_id: existing.stall_offline_id,
3488
- stall_offline_updated_at: now
3489
- };
4027
+ const updated_location = merge_location(existing, item.data, now);
3490
4028
  await local_db.locations.put(updated_location);
3491
4029
  await add_to_sync_queue({
3492
4030
  action: "update",
3493
4031
  table: "locations",
3494
4032
  document_id: item.id,
3495
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3496
- stall_offline_id: existing.stall_offline_id,
4033
+ stall_offline_id: existing.metadata?.stall_offline_id || item.id,
3497
4034
  data: updated_location
3498
4035
  });
3499
4036
  updated_locations.push(updated_location);
@@ -3507,660 +4044,259 @@ var bulk_delete15 = async (props) => {
3507
4044
  try {
3508
4045
  const { sdk, ids } = props;
3509
4046
  for (const id of ids) {
3510
- const existing = await local_db.locations.get(id);
3511
- if (!existing) {
3512
- console.warn(`Location with id ${id} not found locally, skipping`);
3513
- continue;
3514
- }
3515
- await add_to_sync_queue({
3516
- action: "delete",
3517
- table: "locations",
3518
- document_id: id,
3519
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3520
- stall_offline_id: existing.stall_offline_id,
3521
- data: { id }
3522
- });
3523
- await local_db.locations.delete(id);
3524
- }
3525
- return;
3526
- } catch (error) {
3527
- throw error;
3528
- }
3529
- };
3530
- var locations = {
3531
- list: list15,
3532
- retrieve: retrieve15,
3533
- create: create15,
3534
- update: update15,
3535
- delete: _delete15,
3536
- bulk_create: bulk_create15,
3537
- bulk_update: bulk_update15,
3538
- bulk_delete: bulk_delete15
3539
- };
3540
-
3541
- // src/services/fulfillments.service.ts
3542
- var list16 = async (props) => {
3543
- try {
3544
- const { sdk, query } = props;
3545
- const adapter = await sdk.adapter();
3546
- if (!adapter) throw new Error("Adapter not found");
3547
- const fulfillments2 = await adapter.fulfillments.list({
3548
- connector_config: sdk.options.configuration,
3549
- query
3550
- });
3551
- await save_bulk_data({
3552
- table: "fulfillments",
3553
- data: fulfillments2
3554
- });
3555
- return fulfillments2;
3556
- } catch (error) {
3557
- throw error;
3558
- }
3559
- };
3560
- var retrieve16 = async (props) => {
3561
- try {
3562
- const { sdk, id } = props;
3563
- const adapter = await sdk.adapter();
3564
- if (!adapter) throw new Error("Adapter not found");
3565
- const fulfillment = await adapter.fulfillments.retrieve({
3566
- connector_config: sdk.options.configuration,
3567
- id
3568
- });
3569
- await local_db.fulfillments.put(fulfillment);
3570
- return fulfillment;
3571
- } catch (error) {
3572
- throw error;
3573
- }
3574
- };
3575
- var create16 = async (props) => {
3576
- try {
3577
- const { sdk, data } = props;
3578
- const offline_id = generate_offline_id("fulfillment");
3579
- const now = (/* @__PURE__ */ new Date()).toISOString();
3580
- const local_fulfillment = {
3581
- ...data,
3582
- id: offline_id,
3583
- metadata: {
3584
- ...data.metadata,
3585
- stall_offline_id: offline_id
3586
- },
3587
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3588
- stall_offline_id: offline_id,
3589
- stall_offline_created_at: now,
3590
- stall_offline_updated_at: now
3591
- };
3592
- await local_db.fulfillments.add(local_fulfillment);
3593
- await add_to_sync_queue({
3594
- action: "create",
3595
- table: "fulfillments",
3596
- document_id: offline_id,
3597
- stall_offline_id: offline_id,
3598
- data: local_fulfillment
3599
- });
3600
- return local_fulfillment;
3601
- } catch (error) {
3602
- throw error;
3603
- }
3604
- };
3605
- var update16 = async (props) => {
3606
- try {
3607
- const { sdk, id, data } = props;
3608
- const existing = await local_db.fulfillments.get(id);
3609
- if (!existing) {
3610
- throw new Error(`Fulfillment with id ${id} not found locally`);
3611
- }
3612
- const now = (/* @__PURE__ */ new Date()).toISOString();
3613
- const updated_fulfillment = {
3614
- ...existing,
3615
- ...data,
3616
- id: existing.id,
3617
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3618
- stall_offline_id: existing.stall_offline_id,
3619
- stall_offline_updated_at: now
3620
- };
3621
- await local_db.fulfillments.put(updated_fulfillment);
3622
- await add_to_sync_queue({
3623
- action: "update",
3624
- table: "fulfillments",
3625
- document_id: id,
3626
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3627
- stall_offline_id: existing.stall_offline_id,
3628
- data: updated_fulfillment
3629
- });
3630
- return updated_fulfillment;
3631
- } catch (error) {
3632
- throw error;
3633
- }
3634
- };
3635
- var _delete16 = async (props) => {
3636
- try {
3637
- const { sdk, id } = props;
3638
- const existing = await local_db.fulfillments.get(id);
3639
- if (!existing) {
3640
- throw new Error(`Fulfillment with id ${id} not found locally`);
3641
- }
3642
- await add_to_sync_queue({
3643
- action: "delete",
3644
- table: "fulfillments",
3645
- document_id: id,
3646
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3647
- stall_offline_id: existing.stall_offline_id,
3648
- data: { id }
3649
- });
3650
- await local_db.fulfillments.delete(id);
3651
- return;
3652
- } catch (error) {
3653
- throw error;
3654
- }
3655
- };
3656
- var bulk_create16 = async (props) => {
3657
- try {
3658
- const { sdk, data } = props;
3659
- const now = (/* @__PURE__ */ new Date()).toISOString();
3660
- const created_fulfillments = [];
3661
- for (const fulfillment of data) {
3662
- const offline_id = generate_offline_id("fulfillment");
3663
- const local_fulfillment = {
3664
- ...fulfillment,
3665
- id: offline_id,
3666
- metadata: {
3667
- ...fulfillment.metadata,
3668
- stall_offline_id: offline_id
3669
- },
3670
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3671
- stall_offline_id: offline_id,
3672
- stall_offline_created_at: now,
3673
- stall_offline_updated_at: now
3674
- };
3675
- await local_db.fulfillments.add(local_fulfillment);
3676
- await add_to_sync_queue({
3677
- action: "create",
3678
- table: "fulfillments",
3679
- document_id: offline_id,
3680
- stall_offline_id: offline_id,
3681
- data: local_fulfillment
3682
- });
3683
- created_fulfillments.push(local_fulfillment);
3684
- }
3685
- return created_fulfillments;
3686
- } catch (error) {
3687
- throw error;
3688
- }
3689
- };
3690
- var bulk_update16 = async (props) => {
3691
- try {
3692
- const { sdk, data } = props;
3693
- const now = (/* @__PURE__ */ new Date()).toISOString();
3694
- const updated_fulfillments = [];
3695
- for (const item of data) {
3696
- const existing = await local_db.fulfillments.get(item.id);
3697
- if (!existing) {
3698
- console.warn(
3699
- `Fulfillment with id ${item.id} not found locally, skipping`
3700
- );
3701
- continue;
3702
- }
3703
- const updated_fulfillment = {
3704
- ...existing,
3705
- ...item.data,
3706
- id: existing.id,
3707
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3708
- stall_offline_id: existing.stall_offline_id,
3709
- stall_offline_updated_at: now
3710
- };
3711
- await local_db.fulfillments.put(updated_fulfillment);
3712
- await add_to_sync_queue({
3713
- action: "update",
3714
- table: "fulfillments",
3715
- document_id: item.id,
3716
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3717
- stall_offline_id: existing.stall_offline_id,
3718
- data: updated_fulfillment
3719
- });
3720
- updated_fulfillments.push(updated_fulfillment);
3721
- }
3722
- return updated_fulfillments;
3723
- } catch (error) {
3724
- throw error;
3725
- }
3726
- };
3727
- var bulk_delete16 = async (props) => {
3728
- try {
3729
- const { sdk, ids } = props;
3730
- for (const id of ids) {
3731
- const existing = await local_db.fulfillments.get(id);
4047
+ const existing = await local_db.locations.get(id);
3732
4048
  if (!existing) {
3733
- console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4049
+ console.warn(`Location with id ${id} not found locally, skipping`);
3734
4050
  continue;
3735
4051
  }
3736
4052
  await add_to_sync_queue({
3737
4053
  action: "delete",
3738
- table: "fulfillments",
4054
+ table: "locations",
3739
4055
  document_id: id,
3740
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3741
- stall_offline_id: existing.stall_offline_id,
4056
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3742
4057
  data: { id }
3743
4058
  });
3744
- await local_db.fulfillments.delete(id);
4059
+ await local_db.locations.delete(id);
3745
4060
  }
3746
4061
  return;
3747
4062
  } catch (error) {
3748
4063
  throw error;
3749
4064
  }
3750
4065
  };
3751
- var fulfillments = {
3752
- list: list16,
3753
- retrieve: retrieve16,
3754
- create: create16,
3755
- update: update16,
3756
- delete: _delete16,
3757
- bulk_create: bulk_create16,
3758
- bulk_update: bulk_update16,
3759
- bulk_delete: bulk_delete16
3760
- };
3761
-
3762
- // src/services/sync/sync-dependencies.ts
3763
- var SYNC_DEPENDENCY_LAYERS = {
3764
- 1: [
3765
- "tax_regions",
3766
- "tax_rates",
3767
- "categories",
3768
- "collections",
3769
- "locations",
3770
- "payment_providers",
3771
- "customers",
3772
- "promotions"
3773
- ],
3774
- 2: ["products"],
3775
- 3: ["variants", "inventory_levels"],
3776
- 4: ["orders", "order_notes"],
3777
- 5: ["payments", "refunds", "fulfillments"]
3778
- };
3779
- var get_entity_dependencies = (table) => {
3780
- const dependencies = {
3781
- // Layer 1: Independent
3782
- tax_regions: [],
3783
- tax_rates: ["tax_regions"],
3784
- categories: [],
3785
- collections: [],
3786
- locations: [],
3787
- payment_providers: [],
3788
- customers: [],
3789
- promotions: [],
3790
- // Layer 2: Product
3791
- products: ["categories", "collections"],
3792
- // Layer 3: Variants & Inventory
3793
- variants: ["products"],
3794
- inventory_levels: ["products", "variants"],
3795
- inventory_history: ["products", "variants"],
3796
- // Layer 4: Orders
3797
- orders: ["customers", "products", "variants", "locations"],
3798
- order_notes: ["orders"],
3799
- // Layer 5: Order-related
3800
- payments: ["orders", "payment_providers"],
3801
- refunds: ["orders", "payments"],
3802
- fulfillments: ["orders"],
3803
- // Tags
3804
- tags: ["products"],
3805
- // Fulfillment config
3806
- fulfillment_types: [],
3807
- fulfillment_providers: []
3808
- };
3809
- return dependencies[table] || [];
3810
- };
3811
- var get_sync_layer = (table) => {
3812
- for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
3813
- if (tables.includes(table)) {
3814
- return parseInt(layer);
3815
- }
3816
- }
3817
- return 99;
3818
- };
3819
- var sort_by_dependency_order = (items) => {
3820
- return items.sort((a, b) => {
3821
- const layer_a = get_sync_layer(a.table);
3822
- const layer_b = get_sync_layer(b.table);
3823
- if (layer_a !== layer_b) {
3824
- return layer_a - layer_b;
3825
- }
3826
- return 0;
3827
- });
3828
- };
3829
- var are_dependencies_satisfied = (table, synced_tables) => {
3830
- const dependencies = get_entity_dependencies(table);
3831
- return dependencies.every((dep) => synced_tables.has(dep));
4066
+ var locations = {
4067
+ list: list15,
4068
+ retrieve: retrieve15,
4069
+ create: create15,
4070
+ update: update15,
4071
+ delete: _delete15,
4072
+ bulk_create: bulk_create15,
4073
+ bulk_update: bulk_update15,
4074
+ bulk_delete: bulk_delete15
3832
4075
  };
3833
4076
 
3834
- // src/services/sync/sync.service.ts
3835
- var MAX_RETRIES = 3;
3836
- var replace_temporary_ids = async (props) => {
3837
- const { table, stall_offline_id, connector_id, local_data } = props;
4077
+ // src/services/fulfillments.service.ts
4078
+ var list16 = async (props) => {
3838
4079
  try {
3839
- const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
3840
- if (existing) {
3841
- await local_db[table].update(existing.id, {
3842
- id: connector_id
3843
- // Keep stall_offline_id for reference
3844
- });
3845
- }
3846
- await update_dependent_references({
3847
- table,
3848
- old_id: stall_offline_id,
3849
- new_id: connector_id
4080
+ const { sdk, query } = props;
4081
+ const adapter = await sdk.adapter();
4082
+ if (!adapter) throw new Error("Adapter not found");
4083
+ const fulfillments2 = await adapter.fulfillments.list({
4084
+ connector_config: sdk.options.configuration,
4085
+ query
4086
+ });
4087
+ await save_bulk_data({
4088
+ table: "fulfillments",
4089
+ data: fulfillments2
3850
4090
  });
4091
+ return fulfillments2;
3851
4092
  } catch (error) {
3852
- console.error(`Error replacing temporary IDs for ${table}:`, error);
3853
4093
  throw error;
3854
4094
  }
3855
4095
  };
3856
- var update_dependent_references = async (props) => {
3857
- const { table, old_id, new_id } = props;
3858
- try {
3859
- const reference_map = {
3860
- products: [
3861
- { table: "variants", field: "product_id" },
3862
- { table: "inventory_levels", field: "product_id" }
3863
- ],
3864
- variants: [{ table: "inventory_levels", field: "variant_id" }],
3865
- customers: [{ table: "orders", field: "customer_id" }],
3866
- orders: [
3867
- { table: "payments", field: "order_id" },
3868
- { table: "refunds", field: "order_id" },
3869
- { table: "order_notes", field: "order_id" },
3870
- { table: "fulfillments", field: "order_id" }
3871
- ],
3872
- payments: [{ table: "refunds", field: "payment_id" }],
3873
- locations: [{ table: "orders", field: "location_id" }],
3874
- categories: [{ table: "products", field: "category_id" }],
3875
- collections: [{ table: "products", field: "collection_id" }],
3876
- tax_regions: [{ table: "tax_rates", field: "region_id" }],
3877
- tax_rates: [],
3878
- tags: [],
3879
- inventory_levels: [],
3880
- inventory_history: [],
3881
- promotions: [],
3882
- order_notes: [],
3883
- refunds: [],
3884
- payment_providers: [],
3885
- fulfillments: [],
3886
- fulfillment_types: [],
3887
- fulfillment_providers: []
3888
- };
3889
- const references = reference_map[table] || [];
3890
- for (const ref of references) {
3891
- const records = await local_db[ref.table].toArray();
3892
- const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
3893
- ...record,
3894
- [ref.field]: new_id
3895
- }));
3896
- if (updates.length > 0) {
3897
- await local_db[ref.table].bulkPut(updates);
3898
- }
3899
- }
3900
- } catch (error) {
3901
- console.error(`Error updating dependent references for ${table}:`, error);
3902
- }
3903
- };
3904
- var sync_queue_item = async (props) => {
3905
- const { sdk, item, sync_batch_id } = props;
3906
- const start_time = Date.now();
4096
+ var retrieve16 = async (props) => {
3907
4097
  try {
4098
+ const { sdk, id } = props;
3908
4099
  const adapter = await sdk.adapter();
3909
- if (!adapter) {
3910
- throw new Error("Adapter not found");
3911
- }
3912
- const connector_config = sdk.options.configuration;
3913
- const table_module = adapter[item.table];
3914
- if (!table_module) {
3915
- throw new Error(`Module ${item.table} not found in adapter`);
3916
- }
3917
- let connector_id;
3918
- if (item.action === "create") {
3919
- const result = await table_module.create({
3920
- connector_config,
3921
- data: item.data
3922
- });
3923
- connector_id = result?.id;
3924
- if (connector_id) {
3925
- await replace_temporary_ids({
3926
- table: item.table,
3927
- stall_offline_id: item.stall_offline_id,
3928
- connector_id,
3929
- local_data: result
3930
- });
3931
- }
3932
- } else if (item.action === "update") {
3933
- const result = await table_module.update({
3934
- connector_config,
3935
- id: item.document_id,
3936
- data: item.data
3937
- });
3938
- connector_id = result?.id || item.document_id;
3939
- } else if (item.action === "delete") {
3940
- await table_module.delete({
3941
- connector_config,
3942
- id: item.document_id
3943
- });
3944
- connector_id = item.document_id;
3945
- }
3946
- const duration = Date.now() - start_time;
3947
- await add_sync_log({
3948
- sync_batch_id,
3949
- table: item.table,
3950
- action: item.action,
3951
- document_id: item.document_id,
3952
- stall_offline_id: item.stall_offline_id,
3953
- connector_id,
3954
- status: "success",
3955
- duration_ms: duration
3956
- });
3957
- await remove_from_sync_queue(item.id);
3958
- return { success: true, connector_id };
3959
- } catch (error) {
3960
- const duration = Date.now() - start_time;
3961
- console.error(`Error syncing item ${item.id}:`, error);
3962
- const current_retries = item.retry_count || 0;
3963
- if (current_retries < MAX_RETRIES) {
3964
- await update_sync_queue_status({
3965
- id: item.id,
3966
- status: "pending",
3967
- error: error.message,
3968
- retry_count: current_retries + 1
3969
- });
3970
- } else {
3971
- await update_sync_queue_status({
3972
- id: item.id,
3973
- status: "failed",
3974
- error: `Max retries exceeded: ${error.message}`
3975
- });
3976
- }
3977
- await add_sync_log({
3978
- sync_batch_id,
3979
- table: item.table,
3980
- action: item.action,
3981
- document_id: item.document_id,
3982
- stall_offline_id: item.stall_offline_id,
3983
- status: "failed",
3984
- error: error.message,
3985
- duration_ms: duration
4100
+ if (!adapter) throw new Error("Adapter not found");
4101
+ const fulfillment = await adapter.fulfillments.retrieve({
4102
+ connector_config: sdk.options.configuration,
4103
+ id
3986
4104
  });
3987
- return { success: false, error: error.message };
4105
+ await local_db.fulfillments.put(fulfillment);
4106
+ return fulfillment;
4107
+ } catch (error) {
4108
+ throw error;
3988
4109
  }
3989
4110
  };
3990
- var process_sync_queue = async (props) => {
3991
- const { sdk } = props;
3992
- const sync_batch_id = generate_uuid();
4111
+ var create16 = async (props) => {
3993
4112
  try {
3994
- const pending_items_by_table = await get_pending_sync_queue();
3995
- if (pending_items_by_table.size === 0) {
3996
- return {
3997
- sync_batch_id,
3998
- total: 0,
3999
- synced: 0,
4000
- failed: 0,
4001
- summary: []
4002
- };
4003
- }
4004
- let total_synced = 0;
4005
- let total_failed = 0;
4006
- const summary_data = [];
4007
- const all_items = [];
4008
- pending_items_by_table.forEach((items) => {
4009
- items.forEach((item) => {
4010
- all_items.push(item);
4011
- });
4012
- });
4013
- const sorted_items = sort_by_dependency_order(
4014
- all_items
4015
- );
4016
- const synced_tables = /* @__PURE__ */ new Set();
4017
- const items_to_retry = [];
4018
- for (const item of sorted_items) {
4019
- if (!are_dependencies_satisfied(item.table, synced_tables)) {
4020
- items_to_retry.push(item);
4021
- continue;
4022
- }
4023
- await update_sync_queue_status({
4024
- id: item.id,
4025
- status: "syncing"
4026
- });
4027
- const result = await sync_queue_item({
4028
- sdk,
4029
- item,
4030
- sync_batch_id
4031
- });
4032
- if (result.success) {
4033
- total_synced++;
4034
- if (!synced_tables.has(item.table)) {
4035
- synced_tables.add(item.table);
4036
- }
4037
- } else {
4038
- total_failed++;
4039
- }
4040
- const table_summary = summary_data.find((s) => s.table === item.table);
4041
- if (table_summary) {
4042
- if (result.success) {
4043
- table_summary.synced++;
4044
- } else {
4045
- table_summary.failed++;
4046
- }
4047
- } else {
4048
- summary_data.push({
4049
- table: item.table,
4050
- synced: result.success ? 1 : 0,
4051
- failed: result.success ? 0 : 1
4052
- });
4113
+ const { sdk, data } = props;
4114
+ const offline_id = generate_offline_id("fulfillment");
4115
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4116
+ const local_fulfillment = {
4117
+ ...data,
4118
+ id: offline_id,
4119
+ metadata: {
4120
+ ...data.metadata,
4121
+ stall_offline_id: offline_id,
4122
+ stall_offline_created_at: now,
4123
+ stall_offline_updated_at: now,
4124
+ stall_offline_deleted_at: ""
4053
4125
  }
4126
+ };
4127
+ await local_db.fulfillments.add(local_fulfillment);
4128
+ await add_to_sync_queue({
4129
+ action: "create",
4130
+ table: "fulfillments",
4131
+ document_id: offline_id,
4132
+ stall_offline_id: offline_id,
4133
+ data: local_fulfillment
4134
+ });
4135
+ return local_fulfillment;
4136
+ } catch (error) {
4137
+ throw error;
4138
+ }
4139
+ };
4140
+ var update16 = async (props) => {
4141
+ try {
4142
+ const { sdk, id, data } = props;
4143
+ const existing = await local_db.fulfillments.get(id);
4144
+ if (!existing) {
4145
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4054
4146
  }
4055
- for (const item of items_to_retry) {
4056
- await update_sync_queue_status({
4057
- id: item.id,
4058
- status: "syncing"
4059
- });
4060
- const result = await sync_queue_item({
4061
- sdk,
4062
- item,
4063
- sync_batch_id
4064
- });
4065
- if (result.success) {
4066
- total_synced++;
4067
- } else {
4068
- total_failed++;
4069
- }
4070
- const table_summary = summary_data.find((s) => s.table === item.table);
4071
- if (table_summary) {
4072
- if (result.success) {
4073
- table_summary.synced++;
4074
- } else {
4075
- table_summary.failed++;
4076
- }
4147
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4148
+ const updated_fulfillment = {
4149
+ ...existing,
4150
+ ...data,
4151
+ id: existing.id,
4152
+ metadata: {
4153
+ ...existing.metadata,
4154
+ ...data.metadata,
4155
+ stall_offline_id: existing.metadata.stall_offline_id,
4156
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4157
+ stall_offline_updated_at: now,
4158
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4077
4159
  }
4078
- }
4079
- return {
4080
- sync_batch_id,
4081
- total: all_items.length,
4082
- synced: total_synced,
4083
- failed: total_failed,
4084
- summary: summary_data
4085
4160
  };
4161
+ await local_db.fulfillments.put(updated_fulfillment);
4162
+ await add_to_sync_queue({
4163
+ action: "update",
4164
+ table: "fulfillments",
4165
+ document_id: id,
4166
+ stall_offline_id: existing.metadata.stall_offline_id,
4167
+ data: updated_fulfillment
4168
+ });
4169
+ return updated_fulfillment;
4086
4170
  } catch (error) {
4087
- console.error("Error processing sync queue:", error);
4088
- return {
4089
- sync_batch_id,
4090
- total: 0,
4091
- synced: 0,
4092
- failed: 0,
4093
- summary: []
4094
- };
4171
+ throw error;
4095
4172
  }
4096
4173
  };
4097
- var sync_interval = null;
4098
- var start_sync_service = async (props) => {
4099
- const { sdk, interval = 3e4 } = props;
4100
- if (sync_interval) {
4101
- console.warn("Sync service already running");
4174
+ var _delete16 = async (props) => {
4175
+ try {
4176
+ const { sdk, id } = props;
4177
+ const existing = await local_db.fulfillments.get(id);
4178
+ if (!existing) {
4179
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4180
+ }
4181
+ await add_to_sync_queue({
4182
+ action: "delete",
4183
+ table: "fulfillments",
4184
+ document_id: id,
4185
+ stall_offline_id: existing.metadata.stall_offline_id,
4186
+ data: { id }
4187
+ });
4188
+ await local_db.fulfillments.delete(id);
4102
4189
  return;
4190
+ } catch (error) {
4191
+ throw error;
4103
4192
  }
4104
- console.log(`Starting offline sync service with ${interval}ms interval`);
4105
- await process_sync_queue({ sdk });
4106
- sync_interval = setInterval(async () => {
4107
- const result = await process_sync_queue({ sdk });
4108
- if (result.total > 0) {
4109
- console.log(
4110
- `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
4111
- );
4112
- result.summary.forEach((s) => {
4113
- console.log(` ${s.table}: ${s.synced} synced, ${s.failed} failed`);
4193
+ };
4194
+ var bulk_create16 = async (props) => {
4195
+ try {
4196
+ const { sdk, data } = props;
4197
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4198
+ const created_fulfillments = [];
4199
+ for (const fulfillment of data) {
4200
+ const offline_id = generate_offline_id("fulfillment");
4201
+ const local_fulfillment = {
4202
+ ...fulfillment,
4203
+ id: offline_id,
4204
+ metadata: {
4205
+ ...fulfillment.metadata,
4206
+ stall_offline_id: offline_id,
4207
+ stall_offline_created_at: now,
4208
+ stall_offline_updated_at: now,
4209
+ stall_offline_deleted_at: ""
4210
+ }
4211
+ };
4212
+ await local_db.fulfillments.add(local_fulfillment);
4213
+ await add_to_sync_queue({
4214
+ action: "create",
4215
+ table: "fulfillments",
4216
+ document_id: offline_id,
4217
+ stall_offline_id: offline_id,
4218
+ data: local_fulfillment
4114
4219
  });
4220
+ created_fulfillments.push(local_fulfillment);
4115
4221
  }
4116
- }, interval);
4117
- };
4118
- var stop_sync_service = () => {
4119
- if (sync_interval) {
4120
- clearInterval(sync_interval);
4121
- sync_interval = null;
4122
- console.log("Offline sync service stopped");
4222
+ return created_fulfillments;
4223
+ } catch (error) {
4224
+ throw error;
4123
4225
  }
4124
4226
  };
4125
- var get_sync_stats = async () => {
4227
+ var bulk_update16 = async (props) => {
4126
4228
  try {
4127
- const all_items = await local_db.sync_queue.toArray();
4128
- const pending = all_items.filter((i) => i.status === "pending").length;
4129
- const syncing = all_items.filter((i) => i.status === "syncing").length;
4130
- const failed = all_items.filter((i) => i.status === "failed").length;
4131
- return {
4132
- pending,
4133
- syncing,
4134
- failed,
4135
- total: all_items.length
4136
- };
4229
+ const { sdk, data } = props;
4230
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4231
+ const updated_fulfillments = [];
4232
+ for (const item of data) {
4233
+ const existing = await local_db.fulfillments.get(item.id);
4234
+ if (!existing) {
4235
+ console.warn(
4236
+ `Fulfillment with id ${item.id} not found locally, skipping`
4237
+ );
4238
+ continue;
4239
+ }
4240
+ const updated_fulfillment = {
4241
+ ...existing,
4242
+ ...item.data,
4243
+ id: existing.id,
4244
+ metadata: {
4245
+ ...existing.metadata,
4246
+ ...item.data.metadata,
4247
+ stall_offline_id: existing.metadata.stall_offline_id,
4248
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4249
+ stall_offline_updated_at: now,
4250
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4251
+ }
4252
+ };
4253
+ await local_db.fulfillments.put(updated_fulfillment);
4254
+ await add_to_sync_queue({
4255
+ action: "update",
4256
+ table: "fulfillments",
4257
+ document_id: item.id,
4258
+ stall_offline_id: existing.metadata.stall_offline_id,
4259
+ data: updated_fulfillment
4260
+ });
4261
+ updated_fulfillments.push(updated_fulfillment);
4262
+ }
4263
+ return updated_fulfillments;
4137
4264
  } catch (error) {
4138
- console.error("Error getting sync stats:", error);
4139
- return { pending: 0, syncing: 0, failed: 0, total: 0 };
4265
+ throw error;
4140
4266
  }
4141
4267
  };
4142
- var trigger_sync = async (props) => {
4268
+ var bulk_delete16 = async (props) => {
4143
4269
  try {
4144
- const { sdk } = props;
4145
- return await process_sync_queue({ sdk });
4270
+ const { sdk, ids } = props;
4271
+ for (const id of ids) {
4272
+ const existing = await local_db.fulfillments.get(id);
4273
+ if (!existing) {
4274
+ console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4275
+ continue;
4276
+ }
4277
+ await add_to_sync_queue({
4278
+ action: "delete",
4279
+ table: "fulfillments",
4280
+ document_id: id,
4281
+ stall_offline_id: existing.metadata.stall_offline_id,
4282
+ data: { id }
4283
+ });
4284
+ await local_db.fulfillments.delete(id);
4285
+ }
4286
+ return;
4146
4287
  } catch (error) {
4147
- console.error("Error triggering sync:", error);
4148
- return {
4149
- sync_batch_id: generate_uuid(),
4150
- total: 0,
4151
- synced: 0,
4152
- failed: 0,
4153
- summary: []
4154
- };
4288
+ throw error;
4155
4289
  }
4156
4290
  };
4157
- var sync_service = {
4158
- process_sync_queue,
4159
- sync_queue_item,
4160
- start_sync_service,
4161
- stop_sync_service,
4162
- get_sync_stats,
4163
- trigger_sync
4291
+ var fulfillments = {
4292
+ list: list16,
4293
+ retrieve: retrieve16,
4294
+ create: create16,
4295
+ update: update16,
4296
+ delete: _delete16,
4297
+ bulk_create: bulk_create16,
4298
+ bulk_update: bulk_update16,
4299
+ bulk_delete: bulk_delete16
4164
4300
  };
4165
4301
  // Annotate the CommonJS export names for ESM import in node:
4166
4302
  0 && (module.exports = {
@@ -4177,6 +4313,8 @@ var sync_service = {
4177
4313
  get_sync_logs_by_batch,
4178
4314
  initializeStallCore,
4179
4315
  inventory_levels,
4316
+ is_offline,
4317
+ is_online,
4180
4318
  local_db,
4181
4319
  locations,
4182
4320
  order_notes,