@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.mjs CHANGED
@@ -4,7 +4,7 @@ import Dexie from "dexie";
4
4
  // src/db/schema.ts
5
5
  var schemas = {
6
6
  connector_cache: "id",
7
- sync_queue: "++id, status, timestamp",
7
+ sync_queue: "++id, status, timestamp, priority",
8
8
  sync_logs: "++id, sync_batch_id, timestamp",
9
9
  products: "++id",
10
10
  variants: "++id",
@@ -30,45 +30,6 @@ var options = { allowEmptyDB: true };
30
30
  var local_db = new Dexie("stall-core-db", options);
31
31
  local_db.version(1).stores(schemas);
32
32
 
33
- // src/core/init.ts
34
- var initializeStallCore = (options2) => {
35
- const sdk = {
36
- options: options2,
37
- adapter: async () => getAdapter(sdk),
38
- refreshAdapter: async () => getAdapter(sdk, true)
39
- };
40
- void sdk.adapter();
41
- return sdk;
42
- };
43
- var getAdapter = async (sdk, force) => {
44
- const date = Date.now();
45
- let module_code;
46
- const cache_key = "connector-module";
47
- const cached = await local_db.connector_cache.get(cache_key);
48
- if (cached && !force) {
49
- module_code = cached.code;
50
- } else {
51
- const response = await fetch(sdk.options.connector_url, {
52
- mode: "cors",
53
- method: "GET"
54
- });
55
- if (!response.ok) {
56
- throw new Error(`Failed to fetch connector: ${response.statusText}`);
57
- }
58
- module_code = await response.text();
59
- await local_db.connector_cache.put({
60
- id: cache_key,
61
- code: module_code,
62
- timestamp: date
63
- });
64
- }
65
- const blob = new Blob([module_code], { type: "application/javascript" });
66
- const blobUrl = URL.createObjectURL(blob);
67
- const module = await import(blobUrl);
68
- URL.revokeObjectURL(blobUrl);
69
- return module;
70
- };
71
-
72
33
  // src/lib/utils.ts
73
34
  var generate_uuid = () => {
74
35
  return "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
@@ -77,11 +38,32 @@ var generate_uuid = () => {
77
38
  return v.toString(16);
78
39
  });
79
40
  };
41
+ var is_online = () => {
42
+ if (typeof navigator !== "undefined" && typeof navigator.onLine === "boolean") {
43
+ return navigator.onLine;
44
+ }
45
+ return true;
46
+ };
47
+ var is_offline = () => {
48
+ return !is_online();
49
+ };
80
50
 
81
51
  // src/db/helpers.ts
82
52
  var generate_offline_id = (table) => {
83
53
  return `stall_${table}_${generate_uuid()}_${Date.now()}`;
84
54
  };
55
+ var get_action_priority = (action) => {
56
+ switch (action) {
57
+ case "create":
58
+ return 1;
59
+ case "update":
60
+ return 2;
61
+ case "delete":
62
+ return 3;
63
+ default:
64
+ return 2;
65
+ }
66
+ };
85
67
  var save_bulk_data = async (props) => {
86
68
  await local_db.transaction("rw", props.table, async () => {
87
69
  await local_db?.[props.table].clear();
@@ -100,15 +82,25 @@ var add_to_sync_queue = async (props) => {
100
82
  data: props.data,
101
83
  timestamp: Date.now(),
102
84
  status: "pending",
103
- retry_count: 0
85
+ retry_count: 0,
86
+ priority: get_action_priority(props.action)
104
87
  };
105
88
  await local_db.sync_queue.add(queue_item);
106
89
  return queue_item;
107
90
  };
108
91
  var get_pending_sync_queue = async () => {
109
92
  const pending_items = await local_db.sync_queue.where("status").equals("pending").toArray();
93
+ const sorted_items = pending_items.sort((a, b) => {
94
+ if (a.table !== b.table) {
95
+ return a.table.localeCompare(b.table);
96
+ }
97
+ if (a.priority !== b.priority) {
98
+ return a.priority - b.priority;
99
+ }
100
+ return a.timestamp - b.timestamp;
101
+ });
110
102
  const grouped = /* @__PURE__ */ new Map();
111
- pending_items.forEach((item) => {
103
+ sorted_items.forEach((item) => {
112
104
  if (!grouped.has(item.table)) {
113
105
  grouped.set(item.table, []);
114
106
  }
@@ -171,112 +163,580 @@ var cleanup_old_sync_logs = async (days = 30) => {
171
163
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
172
164
  };
173
165
 
174
- // src/services/products.service.ts
175
- var list = async (props) => {
176
- try {
177
- const { sdk, query } = props;
178
- const adapter = await sdk.adapter();
179
- if (!adapter) throw new Error("Adapter not found");
180
- const products2 = await adapter.products.list({
181
- connector_config: sdk.options.configuration,
182
- query
183
- });
184
- await save_bulk_data({
185
- table: "products",
186
- data: products2
187
- });
188
- return products2;
189
- } catch (error) {
190
- throw error;
191
- }
166
+ // src/services/sync/sync-dependencies.ts
167
+ var SYNC_DEPENDENCY_LAYERS = {
168
+ 1: [
169
+ "tax_regions",
170
+ "tax_rates",
171
+ "categories",
172
+ "collections",
173
+ "locations",
174
+ "payment_providers",
175
+ "customers",
176
+ "promotions"
177
+ ],
178
+ 2: ["products"],
179
+ 3: ["variants", "inventory_levels"],
180
+ 4: ["orders", "order_notes"],
181
+ 5: ["payments", "refunds", "fulfillments"]
192
182
  };
193
- var retrieve = async (props) => {
194
- try {
195
- const { sdk, id } = props;
196
- const adapter = await sdk.adapter();
197
- if (!adapter) throw new Error("Adapter not found");
198
- const product = await adapter.products.retrieve({
199
- connector_config: sdk.options.configuration,
200
- id
201
- });
202
- await local_db.products.put(product);
203
- return product;
204
- } catch (error) {
205
- throw error;
183
+ var get_entity_dependencies = (table) => {
184
+ const dependencies = {
185
+ // Layer 1: Independent
186
+ tax_regions: [],
187
+ tax_rates: ["tax_regions"],
188
+ categories: [],
189
+ collections: [],
190
+ locations: [],
191
+ payment_providers: [],
192
+ customers: [],
193
+ promotions: [],
194
+ // Layer 2: Product
195
+ products: ["categories", "collections"],
196
+ // Layer 3: Variants & Inventory
197
+ variants: ["products"],
198
+ inventory_levels: ["products", "variants"],
199
+ inventory_history: ["products", "variants"],
200
+ // Layer 4: Orders
201
+ orders: ["customers", "products", "variants", "locations"],
202
+ order_notes: ["orders"],
203
+ // Layer 5: Order-related
204
+ payments: ["orders", "payment_providers"],
205
+ refunds: ["orders", "payments"],
206
+ fulfillments: ["orders"],
207
+ // Tags
208
+ tags: ["products"],
209
+ // Fulfillment config
210
+ fulfillment_types: [],
211
+ fulfillment_providers: []
212
+ };
213
+ return dependencies[table] || [];
214
+ };
215
+ var get_sync_layer = (table) => {
216
+ for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
217
+ if (tables.includes(table)) {
218
+ return parseInt(layer);
219
+ }
206
220
  }
221
+ return 99;
207
222
  };
208
- var create = async (props) => {
223
+ var sort_by_dependency_order = (items) => {
224
+ return items.sort((a, b) => {
225
+ const layer_a = get_sync_layer(a.table);
226
+ const layer_b = get_sync_layer(b.table);
227
+ if (layer_a !== layer_b) {
228
+ return layer_a - layer_b;
229
+ }
230
+ return 0;
231
+ });
232
+ };
233
+ var are_dependencies_satisfied = (table, synced_tables) => {
234
+ const dependencies = get_entity_dependencies(table);
235
+ return dependencies.every((dep) => synced_tables.has(dep));
236
+ };
237
+
238
+ // src/services/sync/sync.service.ts
239
+ var MAX_RETRIES = 3;
240
+ var SYNC_INTERVAL_MS = 2 * 60 * 1e3;
241
+ var sync_interval = null;
242
+ var is_syncing = false;
243
+ var replace_temporary_ids = async (props) => {
244
+ const { table, stall_offline_id, connector_id } = props;
209
245
  try {
210
- const { sdk, data } = props;
211
- const offline_id = generate_offline_id("product");
212
- const now = (/* @__PURE__ */ new Date()).toISOString();
213
- const local_product = {
214
- ...data,
215
- id: offline_id,
216
- metadata: {
217
- ...data.metadata,
218
- stall_offline_id: offline_id
219
- },
220
- stall_offline_id: offline_id,
221
- stall_offline_created_at: now,
222
- stall_offline_updated_at: now
223
- };
224
- await local_db.products.add(local_product);
225
- await add_to_sync_queue({
226
- action: "create",
227
- table: "products",
228
- document_id: offline_id,
229
- stall_offline_id: offline_id,
230
- data: local_product
246
+ const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
247
+ if (existing) {
248
+ await local_db[table].update(existing.id, {
249
+ id: connector_id
250
+ });
251
+ }
252
+ await update_dependent_references({
253
+ table,
254
+ old_id: stall_offline_id,
255
+ new_id: connector_id
231
256
  });
232
- return local_product;
233
257
  } catch (error) {
258
+ console.error(`Error replacing temporary IDs for ${table}:`, error);
234
259
  throw error;
235
260
  }
236
261
  };
237
- var update = async (props) => {
262
+ var update_dependent_references = async (props) => {
263
+ const { table, old_id, new_id } = props;
238
264
  try {
239
- const { sdk, id, data } = props;
240
- const existing = await local_db.products.get(id);
241
- if (!existing) {
242
- throw new Error(`Product with id ${id} not found locally`);
243
- }
244
- const now = (/* @__PURE__ */ new Date()).toISOString();
245
- const updated_product = {
246
- ...existing,
247
- ...data,
248
- id: existing.id,
249
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
- stall_offline_id: existing.stall_offline_id,
251
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
- stall_offline_updated_at: now
265
+ const reference_map = {
266
+ products: [
267
+ { table: "variants", field: "product_id" },
268
+ { table: "inventory_levels", field: "product_id" }
269
+ ],
270
+ variants: [{ table: "inventory_levels", field: "variant_id" }],
271
+ customers: [{ table: "orders", field: "customer_id" }],
272
+ orders: [
273
+ { table: "payments", field: "order_id" },
274
+ { table: "refunds", field: "order_id" },
275
+ { table: "order_notes", field: "order_id" },
276
+ { table: "fulfillments", field: "order_id" }
277
+ ],
278
+ payments: [{ table: "refunds", field: "payment_id" }],
279
+ locations: [{ table: "orders", field: "location_id" }],
280
+ categories: [{ table: "products", field: "category_id" }],
281
+ collections: [{ table: "products", field: "collection_id" }],
282
+ tax_regions: [{ table: "tax_rates", field: "region_id" }],
283
+ tax_rates: [],
284
+ tags: [],
285
+ inventory_levels: [],
286
+ inventory_history: [],
287
+ promotions: [],
288
+ order_notes: [],
289
+ refunds: [],
290
+ payment_providers: [],
291
+ fulfillments: [],
292
+ fulfillment_types: [],
293
+ fulfillment_providers: []
253
294
  };
254
- await local_db.products.put(updated_product);
255
- await add_to_sync_queue({
256
- action: "update",
257
- table: "products",
258
- document_id: id,
259
- stall_offline_id: existing.stall_offline_id,
260
- data: updated_product
261
- });
262
- return updated_product;
295
+ const references = reference_map[table] || [];
296
+ for (const ref of references) {
297
+ const records = await local_db[ref.table].toArray();
298
+ const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
299
+ ...record,
300
+ [ref.field]: new_id
301
+ }));
302
+ if (updates.length > 0) {
303
+ await local_db[ref.table].bulkPut(updates);
304
+ }
305
+ }
263
306
  } catch (error) {
264
- throw error;
307
+ console.error(`Error updating dependent references for ${table}:`, error);
265
308
  }
266
309
  };
267
- var _delete = async (props) => {
310
+ var sync_queue_item = async (props) => {
311
+ const { sdk, item, sync_batch_id } = props;
312
+ const start_time = Date.now();
268
313
  try {
269
- const { sdk, id } = props;
270
- const existing = await local_db.products.get(id);
271
- if (!existing) {
272
- throw new Error(`Product with id ${id} not found locally`);
314
+ const adapter = await sdk.adapter();
315
+ if (!adapter) {
316
+ throw new Error("Adapter not found");
273
317
  }
274
- await add_to_sync_queue({
318
+ const connector_config = sdk.options.configuration;
319
+ const table_module = adapter[item.table];
320
+ if (!table_module) {
321
+ throw new Error(`Module ${item.table} not found in adapter`);
322
+ }
323
+ let connector_id;
324
+ if (item.action === "create") {
325
+ const result = await table_module.create({
326
+ connector_config,
327
+ data: item.data
328
+ });
329
+ connector_id = result?.id;
330
+ if (connector_id) {
331
+ await replace_temporary_ids({
332
+ table: item.table,
333
+ stall_offline_id: item.stall_offline_id,
334
+ connector_id
335
+ });
336
+ }
337
+ } else if (item.action === "update") {
338
+ const result = await table_module.update({
339
+ connector_config,
340
+ id: item.document_id,
341
+ data: item.data
342
+ });
343
+ connector_id = result?.id || item.document_id;
344
+ } else if (item.action === "delete") {
345
+ await table_module.delete({
346
+ connector_config,
347
+ id: item.document_id
348
+ });
349
+ connector_id = item.document_id;
350
+ }
351
+ const duration = Date.now() - start_time;
352
+ await add_sync_log({
353
+ sync_batch_id,
354
+ table: item.table,
355
+ action: item.action,
356
+ document_id: item.document_id,
357
+ stall_offline_id: item.stall_offline_id,
358
+ connector_id,
359
+ status: "success",
360
+ duration_ms: duration
361
+ });
362
+ await remove_from_sync_queue(item.id);
363
+ return { success: true, connector_id };
364
+ } catch (error) {
365
+ const duration = Date.now() - start_time;
366
+ console.error(`Error syncing item ${item.id}:`, error);
367
+ const current_retries = item.retry_count || 0;
368
+ if (current_retries < MAX_RETRIES) {
369
+ await update_sync_queue_status({
370
+ id: item.id,
371
+ status: "pending",
372
+ error: error.message,
373
+ retry_count: current_retries + 1
374
+ });
375
+ } else {
376
+ await update_sync_queue_status({
377
+ id: item.id,
378
+ status: "failed",
379
+ error: `Max retries exceeded: ${error.message}`
380
+ });
381
+ }
382
+ await add_sync_log({
383
+ sync_batch_id,
384
+ table: item.table,
385
+ action: item.action,
386
+ document_id: item.document_id,
387
+ stall_offline_id: item.stall_offline_id,
388
+ status: "failed",
389
+ error: error.message,
390
+ duration_ms: duration
391
+ });
392
+ return { success: false, error: error.message };
393
+ }
394
+ };
395
+ var process_sync_queue = async (props) => {
396
+ const { sdk } = props;
397
+ const sync_batch_id = generate_uuid();
398
+ if (is_syncing) {
399
+ console.log("Sync already in progress, skipping...");
400
+ return {
401
+ sync_batch_id,
402
+ total: 0,
403
+ synced: 0,
404
+ failed: 0
405
+ };
406
+ }
407
+ is_syncing = true;
408
+ try {
409
+ const pending_items_by_table = await get_pending_sync_queue();
410
+ if (pending_items_by_table.size === 0) {
411
+ return {
412
+ sync_batch_id,
413
+ total: 0,
414
+ synced: 0,
415
+ failed: 0
416
+ };
417
+ }
418
+ let total_synced = 0;
419
+ let total_failed = 0;
420
+ const all_items = [];
421
+ pending_items_by_table.forEach((items) => {
422
+ items.forEach((item) => {
423
+ all_items.push(item);
424
+ });
425
+ });
426
+ const sorted_items = sort_by_dependency_order(
427
+ all_items
428
+ );
429
+ const synced_tables = /* @__PURE__ */ new Set();
430
+ const items_to_retry = [];
431
+ for (const item of sorted_items) {
432
+ if (!are_dependencies_satisfied(item.table, synced_tables)) {
433
+ items_to_retry.push(item);
434
+ continue;
435
+ }
436
+ await update_sync_queue_status({
437
+ id: item.id,
438
+ status: "syncing"
439
+ });
440
+ const result = await sync_queue_item({
441
+ sdk,
442
+ item,
443
+ sync_batch_id
444
+ });
445
+ if (result.success) {
446
+ total_synced++;
447
+ if (!synced_tables.has(item.table)) {
448
+ synced_tables.add(item.table);
449
+ }
450
+ } else {
451
+ total_failed++;
452
+ }
453
+ }
454
+ for (const item of items_to_retry) {
455
+ await update_sync_queue_status({
456
+ id: item.id,
457
+ status: "syncing"
458
+ });
459
+ const result = await sync_queue_item({
460
+ sdk,
461
+ item,
462
+ sync_batch_id
463
+ });
464
+ if (result.success) {
465
+ total_synced++;
466
+ } else {
467
+ total_failed++;
468
+ }
469
+ }
470
+ return {
471
+ sync_batch_id,
472
+ total: all_items.length,
473
+ synced: total_synced,
474
+ failed: total_failed
475
+ };
476
+ } catch (error) {
477
+ console.error("Error processing sync queue:", error);
478
+ return {
479
+ sync_batch_id,
480
+ total: 0,
481
+ synced: 0,
482
+ failed: 0
483
+ };
484
+ } finally {
485
+ is_syncing = false;
486
+ }
487
+ };
488
+ var get_sync_status = async () => {
489
+ try {
490
+ const all_items = await local_db.sync_queue.toArray();
491
+ const pending = all_items.filter((i) => i.status === "pending").length;
492
+ const syncing = all_items.filter((i) => i.status === "syncing").length;
493
+ const failed = all_items.filter((i) => i.status === "failed").length;
494
+ return {
495
+ pending,
496
+ syncing,
497
+ failed,
498
+ total: all_items.length,
499
+ is_sync_running: sync_interval !== null
500
+ };
501
+ } catch (error) {
502
+ console.error("Error getting sync status:", error);
503
+ return {
504
+ pending: 0,
505
+ syncing: 0,
506
+ failed: 0,
507
+ total: 0,
508
+ is_sync_running: false
509
+ };
510
+ }
511
+ };
512
+ var fix_sync_queue = async () => {
513
+ try {
514
+ const stuck_items = await local_db.sync_queue.where("status").equals("syncing").toArray();
515
+ for (const item of stuck_items) {
516
+ await update_sync_queue_status({
517
+ id: item.id,
518
+ status: "pending"
519
+ });
520
+ }
521
+ console.log(`Fixed ${stuck_items.length} stuck sync queue items`);
522
+ return {
523
+ fixed: stuck_items.length
524
+ };
525
+ } catch (error) {
526
+ console.error("Error fixing sync queue:", error);
527
+ return {
528
+ fixed: 0
529
+ };
530
+ }
531
+ };
532
+ var trigger_sync = async (props) => {
533
+ try {
534
+ const { sdk } = props;
535
+ return await process_sync_queue({ sdk });
536
+ } catch (error) {
537
+ console.error("Error triggering sync:", error);
538
+ return {
539
+ sync_batch_id: generate_uuid(),
540
+ total: 0,
541
+ synced: 0,
542
+ failed: 0
543
+ };
544
+ }
545
+ };
546
+ var start_sync = async (props) => {
547
+ const { sdk } = props;
548
+ if (sync_interval) {
549
+ console.warn("Background sync already running");
550
+ return;
551
+ }
552
+ console.log(
553
+ `Starting background sync service (${SYNC_INTERVAL_MS}ms interval)`
554
+ );
555
+ const initial_result = await process_sync_queue({ sdk });
556
+ if (initial_result.total > 0) {
557
+ console.log(
558
+ `Initial sync: ${initial_result.synced} synced, ${initial_result.failed} failed out of ${initial_result.total}`
559
+ );
560
+ }
561
+ sync_interval = setInterval(async () => {
562
+ const status = await get_sync_status();
563
+ if (status.pending > 0) {
564
+ const result = await process_sync_queue({ sdk });
565
+ if (result.total > 0) {
566
+ console.log(
567
+ `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
568
+ );
569
+ }
570
+ }
571
+ }, SYNC_INTERVAL_MS);
572
+ };
573
+ var stop_sync = () => {
574
+ if (sync_interval) {
575
+ clearInterval(sync_interval);
576
+ sync_interval = null;
577
+ console.log("Background sync service stopped");
578
+ } else {
579
+ console.warn("Background sync is not running");
580
+ }
581
+ };
582
+ var sync_service = {
583
+ get_sync_status,
584
+ fix_sync_queue,
585
+ trigger_sync,
586
+ start_sync,
587
+ stop_sync
588
+ };
589
+
590
+ // src/core/init.ts
591
+ var initializeStallCore = (options2) => {
592
+ const sdk = {
593
+ options: options2,
594
+ adapter: async () => getAdapter(sdk),
595
+ refreshAdapter: async () => getAdapter(sdk, true)
596
+ };
597
+ void sdk.adapter().then(() => {
598
+ void sync_service.start_sync({ sdk });
599
+ });
600
+ return sdk;
601
+ };
602
+ var getAdapter = async (sdk, force) => {
603
+ const date = Date.now();
604
+ let module_code;
605
+ const cache_key = "connector-module";
606
+ const cached = await local_db.connector_cache.get(cache_key);
607
+ if (cached && !force) {
608
+ module_code = cached.code;
609
+ } else {
610
+ const response = await fetch(sdk.options.connector_url, {
611
+ mode: "cors",
612
+ method: "GET"
613
+ });
614
+ if (!response.ok) {
615
+ throw new Error(`Failed to fetch connector: ${response.statusText}`);
616
+ }
617
+ module_code = await response.text();
618
+ await local_db.connector_cache.put({
619
+ id: cache_key,
620
+ code: module_code,
621
+ timestamp: date
622
+ });
623
+ }
624
+ const blob = new Blob([module_code], { type: "application/javascript" });
625
+ const blobUrl = URL.createObjectURL(blob);
626
+ const module = await import(blobUrl);
627
+ URL.revokeObjectURL(blobUrl);
628
+ return module;
629
+ };
630
+
631
+ // src/services/products.service.ts
632
+ var list = async (props) => {
633
+ try {
634
+ const { sdk, query } = props;
635
+ const adapter = await sdk.adapter();
636
+ if (!adapter) throw new Error("Adapter not found");
637
+ const products2 = await adapter.products.list({
638
+ connector_config: sdk.options.configuration,
639
+ query
640
+ });
641
+ await save_bulk_data({
642
+ table: "products",
643
+ data: products2
644
+ });
645
+ return products2;
646
+ } catch (error) {
647
+ throw error;
648
+ }
649
+ };
650
+ var retrieve = async (props) => {
651
+ try {
652
+ const { sdk, id } = props;
653
+ const adapter = await sdk.adapter();
654
+ if (!adapter) throw new Error("Adapter not found");
655
+ const product = await adapter.products.retrieve({
656
+ connector_config: sdk.options.configuration,
657
+ id
658
+ });
659
+ await local_db.products.put(product);
660
+ return product;
661
+ } catch (error) {
662
+ throw error;
663
+ }
664
+ };
665
+ var create = async (props) => {
666
+ try {
667
+ const { sdk, data } = props;
668
+ const offline_id = generate_offline_id("product");
669
+ const now = (/* @__PURE__ */ new Date()).toISOString();
670
+ const local_product = {
671
+ ...data,
672
+ id: offline_id,
673
+ metadata: {
674
+ ...data.metadata,
675
+ stall_offline_id: offline_id,
676
+ stall_offline_created_at: now,
677
+ stall_offline_updated_at: now,
678
+ stall_offline_deleted_at: ""
679
+ }
680
+ };
681
+ await local_db.products.add(local_product);
682
+ await add_to_sync_queue({
683
+ action: "create",
684
+ table: "products",
685
+ document_id: offline_id,
686
+ stall_offline_id: offline_id,
687
+ data: local_product
688
+ });
689
+ return local_product;
690
+ } catch (error) {
691
+ throw error;
692
+ }
693
+ };
694
+ var update = async (props) => {
695
+ try {
696
+ const { sdk, id, data } = props;
697
+ const existing = await local_db.products.get(id);
698
+ if (!existing) {
699
+ throw new Error(`Product with id ${id} not found locally`);
700
+ }
701
+ const now = (/* @__PURE__ */ new Date()).toISOString();
702
+ const updated_product = {
703
+ ...existing,
704
+ ...data,
705
+ id: existing.id,
706
+ metadata: {
707
+ ...existing.metadata,
708
+ ...data.metadata,
709
+ stall_offline_id: existing.metadata.stall_offline_id,
710
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
711
+ stall_offline_updated_at: now,
712
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
713
+ }
714
+ };
715
+ await local_db.products.put(updated_product);
716
+ await add_to_sync_queue({
717
+ action: "update",
718
+ table: "products",
719
+ document_id: id,
720
+ stall_offline_id: existing.metadata.stall_offline_id,
721
+ data: updated_product
722
+ });
723
+ return updated_product;
724
+ } catch (error) {
725
+ throw error;
726
+ }
727
+ };
728
+ var _delete = async (props) => {
729
+ try {
730
+ const { sdk, id } = props;
731
+ const existing = await local_db.products.get(id);
732
+ if (!existing) {
733
+ throw new Error(`Product with id ${id} not found locally`);
734
+ }
735
+ await add_to_sync_queue({
275
736
  action: "delete",
276
737
  table: "products",
277
738
  document_id: id,
278
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
279
- stall_offline_id: existing.stall_offline_id,
739
+ stall_offline_id: existing.metadata.stall_offline_id,
280
740
  data: { id }
281
741
  });
282
742
  await local_db.products.delete(id);
@@ -297,11 +757,11 @@ var bulk_create = async (props) => {
297
757
  id: offline_id,
298
758
  metadata: {
299
759
  ...product.metadata,
300
- stall_offline_id: offline_id
301
- },
302
- stall_offline_id: offline_id,
303
- stall_offline_created_at: now,
304
- stall_offline_updated_at: now
760
+ stall_offline_id: offline_id,
761
+ stall_offline_created_at: now,
762
+ stall_offline_updated_at: now,
763
+ stall_offline_deleted_at: ""
764
+ }
305
765
  };
306
766
  await local_db.products.add(local_product);
307
767
  await add_to_sync_queue({
@@ -333,17 +793,21 @@ var bulk_update = async (props) => {
333
793
  ...existing,
334
794
  ...item.data,
335
795
  id: existing.id,
336
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
337
- stall_offline_id: existing.stall_offline_id,
338
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
339
- stall_offline_updated_at: now
796
+ metadata: {
797
+ ...existing.metadata,
798
+ ...item.data.metadata,
799
+ stall_offline_id: existing.metadata.stall_offline_id,
800
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
801
+ stall_offline_updated_at: now,
802
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
803
+ }
340
804
  };
341
805
  await local_db.products.put(updated_product);
342
806
  await add_to_sync_queue({
343
807
  action: "update",
344
808
  table: "products",
345
809
  document_id: item.id,
346
- stall_offline_id: existing.stall_offline_id,
810
+ stall_offline_id: existing.metadata.stall_offline_id,
347
811
  data: updated_product
348
812
  });
349
813
  updated_products.push(updated_product);
@@ -366,8 +830,7 @@ var bulk_delete = async (props) => {
366
830
  action: "delete",
367
831
  table: "products",
368
832
  document_id: id,
369
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
370
- stall_offline_id: existing.stall_offline_id,
833
+ stall_offline_id: existing.metadata.stall_offline_id,
371
834
  data: { id }
372
835
  });
373
836
  await local_db.products.delete(id);
@@ -436,11 +899,11 @@ var create2 = async (props) => {
436
899
  id: offline_id,
437
900
  metadata: {
438
901
  ...data.metadata,
439
- stall_offline_id: offline_id
440
- },
441
- stall_offline_id: offline_id,
442
- stall_offline_created_at: now,
443
- stall_offline_updated_at: now
902
+ stall_offline_id: offline_id,
903
+ stall_offline_created_at: now,
904
+ stall_offline_updated_at: now,
905
+ stall_offline_deleted_at: ""
906
+ }
444
907
  };
445
908
  await local_db.orders.add(local_order);
446
909
  await add_to_sync_queue({
@@ -469,17 +932,21 @@ var update2 = async (props) => {
469
932
  ...existing,
470
933
  ...data,
471
934
  id: existing.id,
472
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
473
- stall_offline_id: existing.stall_offline_id,
474
- stall_offline_updated_at: now
935
+ metadata: {
936
+ ...existing.metadata,
937
+ ...data.metadata,
938
+ stall_offline_id: existing.metadata.stall_offline_id,
939
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
940
+ stall_offline_updated_at: now,
941
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
942
+ }
475
943
  };
476
944
  await local_db.orders.put(updated_order);
477
945
  await add_to_sync_queue({
478
946
  action: "update",
479
947
  table: "orders",
480
948
  document_id: id,
481
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
482
- stall_offline_id: existing.stall_offline_id,
949
+ stall_offline_id: existing.metadata.stall_offline_id,
483
950
  data: updated_order
484
951
  });
485
952
  return updated_order;
@@ -500,8 +967,7 @@ var _delete2 = async (props) => {
500
967
  action: "delete",
501
968
  table: "orders",
502
969
  document_id: id,
503
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
504
- stall_offline_id: existing.stall_offline_id,
970
+ stall_offline_id: existing.metadata.stall_offline_id,
505
971
  data: { id }
506
972
  });
507
973
  await local_db.orders.delete(id);
@@ -524,11 +990,11 @@ var bulk_create2 = async (props) => {
524
990
  id: offline_id,
525
991
  metadata: {
526
992
  ...order.metadata,
527
- stall_offline_id: offline_id
528
- },
529
- stall_offline_id: offline_id,
530
- stall_offline_created_at: now,
531
- stall_offline_updated_at: now
993
+ stall_offline_id: offline_id,
994
+ stall_offline_created_at: now,
995
+ stall_offline_updated_at: now,
996
+ stall_offline_deleted_at: ""
997
+ }
532
998
  };
533
999
  await local_db.orders.add(local_order);
534
1000
  await add_to_sync_queue({
@@ -562,17 +1028,21 @@ var bulk_update2 = async (props) => {
562
1028
  ...existing,
563
1029
  ...item.data,
564
1030
  id: existing.id,
565
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
566
- stall_offline_id: existing.stall_offline_id,
567
- stall_offline_updated_at: now
1031
+ metadata: {
1032
+ ...existing.metadata,
1033
+ ...item.data.metadata,
1034
+ stall_offline_id: existing.metadata.stall_offline_id,
1035
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1036
+ stall_offline_updated_at: now,
1037
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1038
+ }
568
1039
  };
569
1040
  await local_db.orders.put(updated_order);
570
1041
  await add_to_sync_queue({
571
1042
  action: "update",
572
1043
  table: "orders",
573
1044
  document_id: item.id,
574
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
575
- stall_offline_id: existing.stall_offline_id,
1045
+ stall_offline_id: existing.metadata.stall_offline_id,
576
1046
  data: updated_order
577
1047
  });
578
1048
  updated_orders.push(updated_order);
@@ -597,8 +1067,7 @@ var bulk_delete2 = async (props) => {
597
1067
  action: "delete",
598
1068
  table: "orders",
599
1069
  document_id: id,
600
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
601
- stall_offline_id: existing.stall_offline_id,
1070
+ stall_offline_id: existing.metadata.stall_offline_id,
602
1071
  data: { id }
603
1072
  });
604
1073
  await local_db.orders.delete(id);
@@ -665,11 +1134,11 @@ var create3 = async (props) => {
665
1134
  id: offline_id,
666
1135
  metadata: {
667
1136
  ...data.metadata,
668
- stall_offline_id: offline_id
669
- },
670
- stall_offline_id: offline_id,
671
- stall_offline_created_at: now,
672
- stall_offline_updated_at: now
1137
+ stall_offline_id: offline_id,
1138
+ stall_offline_created_at: now,
1139
+ stall_offline_updated_at: now,
1140
+ stall_offline_deleted_at: ""
1141
+ }
673
1142
  };
674
1143
  await local_db.customers.add(local_customer);
675
1144
  await add_to_sync_queue({
@@ -696,17 +1165,21 @@ var update3 = async (props) => {
696
1165
  ...existing,
697
1166
  ...data,
698
1167
  id: existing.id,
699
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
700
- stall_offline_id: existing.stall_offline_id,
701
- stall_offline_updated_at: now
1168
+ metadata: {
1169
+ ...existing.metadata,
1170
+ ...data.metadata,
1171
+ stall_offline_id: existing.metadata.stall_offline_id,
1172
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1173
+ stall_offline_updated_at: now,
1174
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1175
+ }
702
1176
  };
703
1177
  await local_db.customers.put(updated_customer);
704
1178
  await add_to_sync_queue({
705
1179
  action: "update",
706
1180
  table: "customers",
707
1181
  document_id: id,
708
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
709
- stall_offline_id: existing.stall_offline_id,
1182
+ stall_offline_id: existing.metadata.stall_offline_id,
710
1183
  data: updated_customer
711
1184
  });
712
1185
  return updated_customer;
@@ -725,8 +1198,7 @@ var _delete3 = async (props) => {
725
1198
  action: "delete",
726
1199
  table: "customers",
727
1200
  document_id: id,
728
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
729
- stall_offline_id: existing.stall_offline_id,
1201
+ stall_offline_id: existing.metadata.stall_offline_id,
730
1202
  data: { id }
731
1203
  });
732
1204
  await local_db.customers.delete(id);
@@ -747,11 +1219,11 @@ var bulk_create3 = async (props) => {
747
1219
  id: offline_id,
748
1220
  metadata: {
749
1221
  ...customer.metadata,
750
- stall_offline_id: offline_id
751
- },
752
- stall_offline_id: offline_id,
753
- stall_offline_created_at: now,
754
- stall_offline_updated_at: now
1222
+ stall_offline_id: offline_id,
1223
+ stall_offline_created_at: now,
1224
+ stall_offline_updated_at: now,
1225
+ stall_offline_deleted_at: ""
1226
+ }
755
1227
  };
756
1228
  await local_db.customers.add(local_customer);
757
1229
  await add_to_sync_queue({
@@ -783,17 +1255,21 @@ var bulk_update3 = async (props) => {
783
1255
  ...existing,
784
1256
  ...item.data,
785
1257
  id: existing.id,
786
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
787
- stall_offline_id: existing.stall_offline_id,
788
- stall_offline_updated_at: now
1258
+ metadata: {
1259
+ ...existing.metadata,
1260
+ ...item.data.metadata,
1261
+ stall_offline_id: existing.metadata.stall_offline_id,
1262
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1263
+ stall_offline_updated_at: now,
1264
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1265
+ }
789
1266
  };
790
1267
  await local_db.customers.put(updated_customer);
791
1268
  await add_to_sync_queue({
792
1269
  action: "update",
793
1270
  table: "customers",
794
1271
  document_id: item.id,
795
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
796
- stall_offline_id: existing.stall_offline_id,
1272
+ stall_offline_id: existing.metadata.stall_offline_id,
797
1273
  data: updated_customer
798
1274
  });
799
1275
  updated_customers.push(updated_customer);
@@ -816,8 +1292,7 @@ var bulk_delete3 = async (props) => {
816
1292
  action: "delete",
817
1293
  table: "customers",
818
1294
  document_id: id,
819
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
820
- stall_offline_id: existing.stall_offline_id,
1295
+ stall_offline_id: existing.metadata.stall_offline_id,
821
1296
  data: { id }
822
1297
  });
823
1298
  await local_db.customers.delete(id);
@@ -882,11 +1357,11 @@ var create4 = async (props) => {
882
1357
  id: offline_id,
883
1358
  metadata: {
884
1359
  ...data.metadata,
885
- stall_offline_id: offline_id
886
- },
887
- stall_offline_id: offline_id,
888
- stall_offline_created_at: now,
889
- stall_offline_updated_at: now
1360
+ stall_offline_id: offline_id,
1361
+ stall_offline_created_at: now,
1362
+ stall_offline_updated_at: now,
1363
+ stall_offline_deleted_at: ""
1364
+ }
890
1365
  };
891
1366
  await local_db.collections.add(local_collection);
892
1367
  await add_to_sync_queue({
@@ -913,17 +1388,21 @@ var update4 = async (props) => {
913
1388
  ...existing,
914
1389
  ...data,
915
1390
  id: existing.id,
916
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
917
- stall_offline_id: existing.stall_offline_id,
918
- stall_offline_updated_at: now
1391
+ metadata: {
1392
+ ...existing.metadata,
1393
+ ...data.metadata,
1394
+ stall_offline_id: existing.metadata.stall_offline_id,
1395
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1396
+ stall_offline_updated_at: now,
1397
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1398
+ }
919
1399
  };
920
1400
  await local_db.collections.put(updated_collection);
921
1401
  await add_to_sync_queue({
922
1402
  action: "update",
923
1403
  table: "collections",
924
1404
  document_id: id,
925
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
926
- stall_offline_id: existing.stall_offline_id,
1405
+ stall_offline_id: existing.metadata.stall_offline_id,
927
1406
  data: updated_collection
928
1407
  });
929
1408
  return updated_collection;
@@ -942,8 +1421,7 @@ var _delete4 = async (props) => {
942
1421
  action: "delete",
943
1422
  table: "collections",
944
1423
  document_id: id,
945
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
946
- stall_offline_id: existing.stall_offline_id,
1424
+ stall_offline_id: existing.metadata.stall_offline_id,
947
1425
  data: { id }
948
1426
  });
949
1427
  await local_db.collections.delete(id);
@@ -964,11 +1442,11 @@ var bulk_create4 = async (props) => {
964
1442
  id: offline_id,
965
1443
  metadata: {
966
1444
  ...collection.metadata,
967
- stall_offline_id: offline_id
968
- },
969
- stall_offline_id: offline_id,
970
- stall_offline_created_at: now,
971
- stall_offline_updated_at: now
1445
+ stall_offline_id: offline_id,
1446
+ stall_offline_created_at: now,
1447
+ stall_offline_updated_at: now,
1448
+ stall_offline_deleted_at: ""
1449
+ }
972
1450
  };
973
1451
  await local_db.collections.add(local_collection);
974
1452
  await add_to_sync_queue({
@@ -1002,17 +1480,21 @@ var bulk_update4 = async (props) => {
1002
1480
  ...existing,
1003
1481
  ...item.data,
1004
1482
  id: existing.id,
1005
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1006
- stall_offline_id: existing.stall_offline_id,
1007
- stall_offline_updated_at: now
1483
+ metadata: {
1484
+ ...existing.metadata,
1485
+ ...item.data.metadata,
1486
+ stall_offline_id: existing.metadata.stall_offline_id,
1487
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1488
+ stall_offline_updated_at: now,
1489
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1490
+ }
1008
1491
  };
1009
1492
  await local_db.collections.put(updated_collection);
1010
1493
  await add_to_sync_queue({
1011
1494
  action: "update",
1012
1495
  table: "collections",
1013
1496
  document_id: item.id,
1014
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1015
- stall_offline_id: existing.stall_offline_id,
1497
+ stall_offline_id: existing.metadata.stall_offline_id,
1016
1498
  data: updated_collection
1017
1499
  });
1018
1500
  updated_collections.push(updated_collection);
@@ -1035,8 +1517,7 @@ var bulk_delete4 = async (props) => {
1035
1517
  action: "delete",
1036
1518
  table: "collections",
1037
1519
  document_id: id,
1038
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1039
- stall_offline_id: existing.stall_offline_id,
1520
+ stall_offline_id: existing.metadata.stall_offline_id,
1040
1521
  data: { id }
1041
1522
  });
1042
1523
  await local_db.collections.delete(id);
@@ -1101,11 +1582,11 @@ var create5 = async (props) => {
1101
1582
  id: offline_id,
1102
1583
  metadata: {
1103
1584
  ...data.metadata,
1104
- stall_offline_id: offline_id
1105
- },
1106
- stall_offline_id: offline_id,
1107
- stall_offline_created_at: now,
1108
- stall_offline_updated_at: now
1585
+ stall_offline_id: offline_id,
1586
+ stall_offline_created_at: now,
1587
+ stall_offline_updated_at: now,
1588
+ stall_offline_deleted_at: ""
1589
+ }
1109
1590
  };
1110
1591
  await local_db.categories.add(local_category);
1111
1592
  await add_to_sync_queue({
@@ -1132,17 +1613,21 @@ var update5 = async (props) => {
1132
1613
  ...existing,
1133
1614
  ...data,
1134
1615
  id: existing.id,
1135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1136
- stall_offline_id: existing.stall_offline_id,
1137
- stall_offline_updated_at: now
1616
+ metadata: {
1617
+ ...existing.metadata,
1618
+ ...data.metadata,
1619
+ stall_offline_id: existing.metadata.stall_offline_id,
1620
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1621
+ stall_offline_updated_at: now,
1622
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1623
+ }
1138
1624
  };
1139
1625
  await local_db.categories.put(updated_category);
1140
1626
  await add_to_sync_queue({
1141
1627
  action: "update",
1142
1628
  table: "categories",
1143
1629
  document_id: id,
1144
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1145
- stall_offline_id: existing.stall_offline_id,
1630
+ stall_offline_id: existing.metadata.stall_offline_id,
1146
1631
  data: updated_category
1147
1632
  });
1148
1633
  return updated_category;
@@ -1161,8 +1646,7 @@ var _delete5 = async (props) => {
1161
1646
  action: "delete",
1162
1647
  table: "categories",
1163
1648
  document_id: id,
1164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1165
- stall_offline_id: existing.stall_offline_id,
1649
+ stall_offline_id: existing.metadata.stall_offline_id,
1166
1650
  data: { id }
1167
1651
  });
1168
1652
  await local_db.categories.delete(id);
@@ -1183,11 +1667,11 @@ var bulk_create5 = async (props) => {
1183
1667
  id: offline_id,
1184
1668
  metadata: {
1185
1669
  ...category.metadata,
1186
- stall_offline_id: offline_id
1187
- },
1188
- stall_offline_id: offline_id,
1189
- stall_offline_created_at: now,
1190
- stall_offline_updated_at: now
1670
+ stall_offline_id: offline_id,
1671
+ stall_offline_created_at: now,
1672
+ stall_offline_updated_at: now,
1673
+ stall_offline_deleted_at: ""
1674
+ }
1191
1675
  };
1192
1676
  await local_db.categories.add(local_category);
1193
1677
  await add_to_sync_queue({
@@ -1219,17 +1703,21 @@ var bulk_update5 = async (props) => {
1219
1703
  ...existing,
1220
1704
  ...item.data,
1221
1705
  id: existing.id,
1222
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1223
- stall_offline_id: existing.stall_offline_id,
1224
- stall_offline_updated_at: now
1706
+ metadata: {
1707
+ ...existing.metadata,
1708
+ ...item.data.metadata,
1709
+ stall_offline_id: existing.metadata.stall_offline_id,
1710
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1711
+ stall_offline_updated_at: now,
1712
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1713
+ }
1225
1714
  };
1226
1715
  await local_db.categories.put(updated_category);
1227
1716
  await add_to_sync_queue({
1228
1717
  action: "update",
1229
1718
  table: "categories",
1230
1719
  document_id: item.id,
1231
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1232
- stall_offline_id: existing.stall_offline_id,
1720
+ stall_offline_id: existing.metadata.stall_offline_id,
1233
1721
  data: updated_category
1234
1722
  });
1235
1723
  updated_categories.push(updated_category);
@@ -1252,8 +1740,7 @@ var bulk_delete5 = async (props) => {
1252
1740
  action: "delete",
1253
1741
  table: "categories",
1254
1742
  document_id: id,
1255
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1256
- stall_offline_id: existing.stall_offline_id,
1743
+ stall_offline_id: existing.metadata.stall_offline_id,
1257
1744
  data: { id }
1258
1745
  });
1259
1746
  await local_db.categories.delete(id);
@@ -1318,11 +1805,11 @@ var create6 = async (props) => {
1318
1805
  id: offline_id,
1319
1806
  metadata: {
1320
1807
  ...data.metadata,
1321
- stall_offline_id: offline_id
1322
- },
1323
- stall_offline_id: offline_id,
1324
- stall_offline_created_at: now,
1325
- stall_offline_updated_at: now
1808
+ stall_offline_id: offline_id,
1809
+ stall_offline_created_at: now,
1810
+ stall_offline_updated_at: now,
1811
+ stall_offline_deleted_at: ""
1812
+ }
1326
1813
  };
1327
1814
  await local_db.variants.add(local_variant);
1328
1815
  await add_to_sync_queue({
@@ -1349,17 +1836,21 @@ var update6 = async (props) => {
1349
1836
  ...existing,
1350
1837
  ...data,
1351
1838
  id: existing.id,
1352
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1353
- stall_offline_id: existing.stall_offline_id,
1354
- stall_offline_updated_at: now
1839
+ metadata: {
1840
+ ...existing.metadata,
1841
+ ...data.metadata,
1842
+ stall_offline_id: existing.metadata.stall_offline_id,
1843
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1844
+ stall_offline_updated_at: now,
1845
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1846
+ }
1355
1847
  };
1356
1848
  await local_db.variants.put(updated_variant);
1357
1849
  await add_to_sync_queue({
1358
1850
  action: "update",
1359
1851
  table: "variants",
1360
1852
  document_id: id,
1361
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1362
- stall_offline_id: existing.stall_offline_id,
1853
+ stall_offline_id: existing.metadata.stall_offline_id,
1363
1854
  data: updated_variant
1364
1855
  });
1365
1856
  return updated_variant;
@@ -1378,8 +1869,7 @@ var _delete6 = async (props) => {
1378
1869
  action: "delete",
1379
1870
  table: "variants",
1380
1871
  document_id: id,
1381
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1382
- stall_offline_id: existing.stall_offline_id,
1872
+ stall_offline_id: existing.metadata.stall_offline_id,
1383
1873
  data: { id }
1384
1874
  });
1385
1875
  await local_db.variants.delete(id);
@@ -1400,11 +1890,11 @@ var bulk_create6 = async (props) => {
1400
1890
  id: offline_id,
1401
1891
  metadata: {
1402
1892
  ...variant.metadata,
1403
- stall_offline_id: offline_id
1404
- },
1405
- stall_offline_id: offline_id,
1406
- stall_offline_created_at: now,
1407
- stall_offline_updated_at: now
1893
+ stall_offline_id: offline_id,
1894
+ stall_offline_created_at: now,
1895
+ stall_offline_updated_at: now,
1896
+ stall_offline_deleted_at: ""
1897
+ }
1408
1898
  };
1409
1899
  await local_db.variants.add(local_variant);
1410
1900
  await add_to_sync_queue({
@@ -1436,17 +1926,21 @@ var bulk_update6 = async (props) => {
1436
1926
  ...existing,
1437
1927
  ...item.data,
1438
1928
  id: existing.id,
1439
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1440
- stall_offline_id: existing.stall_offline_id,
1441
- stall_offline_updated_at: now
1929
+ metadata: {
1930
+ ...existing.metadata,
1931
+ ...item.data.metadata,
1932
+ stall_offline_id: existing.metadata.stall_offline_id,
1933
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
1934
+ stall_offline_updated_at: now,
1935
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
1936
+ }
1442
1937
  };
1443
1938
  await local_db.variants.put(updated_variant);
1444
1939
  await add_to_sync_queue({
1445
1940
  action: "update",
1446
1941
  table: "variants",
1447
1942
  document_id: item.id,
1448
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1449
- stall_offline_id: existing.stall_offline_id,
1943
+ stall_offline_id: existing.metadata.stall_offline_id,
1450
1944
  data: updated_variant
1451
1945
  });
1452
1946
  updated_variants.push(updated_variant);
@@ -1469,8 +1963,7 @@ var bulk_delete6 = async (props) => {
1469
1963
  action: "delete",
1470
1964
  table: "variants",
1471
1965
  document_id: id,
1472
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1473
- stall_offline_id: existing.stall_offline_id,
1966
+ stall_offline_id: existing.metadata.stall_offline_id,
1474
1967
  data: { id }
1475
1968
  });
1476
1969
  await local_db.variants.delete(id);
@@ -1535,12 +2028,11 @@ var create7 = async (props) => {
1535
2028
  id: offline_id,
1536
2029
  metadata: {
1537
2030
  ...data.metadata,
1538
- stall_offline_id: offline_id
1539
- },
1540
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1541
- stall_offline_id: offline_id,
1542
- stall_offline_created_at: now,
1543
- stall_offline_updated_at: now
2031
+ stall_offline_id: offline_id,
2032
+ stall_offline_created_at: now,
2033
+ stall_offline_updated_at: now,
2034
+ stall_offline_deleted_at: ""
2035
+ }
1544
2036
  };
1545
2037
  await local_db.inventory_levels.add(local_inventory_level);
1546
2038
  await add_to_sync_queue({
@@ -1567,17 +2059,21 @@ var update7 = async (props) => {
1567
2059
  ...existing,
1568
2060
  ...data,
1569
2061
  id: existing.id,
1570
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1571
- stall_offline_id: existing.stall_offline_id,
1572
- stall_offline_updated_at: now
2062
+ metadata: {
2063
+ ...existing.metadata,
2064
+ ...data.metadata,
2065
+ stall_offline_id: existing.metadata.stall_offline_id,
2066
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2067
+ stall_offline_updated_at: now,
2068
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2069
+ }
1573
2070
  };
1574
2071
  await local_db.inventory_levels.put(updated_inventory_level);
1575
2072
  await add_to_sync_queue({
1576
2073
  action: "update",
1577
2074
  table: "inventory_levels",
1578
2075
  document_id: id,
1579
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1580
- stall_offline_id: existing.stall_offline_id,
2076
+ stall_offline_id: existing.metadata.stall_offline_id,
1581
2077
  data: updated_inventory_level
1582
2078
  });
1583
2079
  return updated_inventory_level;
@@ -1596,8 +2092,7 @@ var _delete7 = async (props) => {
1596
2092
  action: "delete",
1597
2093
  table: "inventory_levels",
1598
2094
  document_id: id,
1599
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1600
- stall_offline_id: existing.stall_offline_id,
2095
+ stall_offline_id: existing.metadata.stall_offline_id,
1601
2096
  data: { id }
1602
2097
  });
1603
2098
  await local_db.inventory_levels.delete(id);
@@ -1618,12 +2113,11 @@ var bulk_create7 = async (props) => {
1618
2113
  id: offline_id,
1619
2114
  metadata: {
1620
2115
  ...inventory_level.metadata,
1621
- stall_offline_id: offline_id
1622
- },
1623
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1624
- stall_offline_id: offline_id,
1625
- stall_offline_created_at: now,
1626
- stall_offline_updated_at: now
2116
+ stall_offline_id: offline_id,
2117
+ stall_offline_created_at: now,
2118
+ stall_offline_updated_at: now,
2119
+ stall_offline_deleted_at: ""
2120
+ }
1627
2121
  };
1628
2122
  await local_db.inventory_levels.add(local_inventory_level);
1629
2123
  await add_to_sync_queue({
@@ -1657,17 +2151,21 @@ var bulk_update7 = async (props) => {
1657
2151
  ...existing,
1658
2152
  ...item.data,
1659
2153
  id: existing.id,
1660
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1661
- stall_offline_id: existing.stall_offline_id,
1662
- stall_offline_updated_at: now
2154
+ metadata: {
2155
+ ...existing.metadata,
2156
+ ...item.data.metadata,
2157
+ stall_offline_id: existing.metadata.stall_offline_id,
2158
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2159
+ stall_offline_updated_at: now,
2160
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2161
+ }
1663
2162
  };
1664
2163
  await local_db.inventory_levels.put(updated_inventory_level);
1665
2164
  await add_to_sync_queue({
1666
2165
  action: "update",
1667
2166
  table: "inventory_levels",
1668
2167
  document_id: item.id,
1669
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1670
- stall_offline_id: existing.stall_offline_id,
2168
+ stall_offline_id: existing.metadata.stall_offline_id,
1671
2169
  data: updated_inventory_level
1672
2170
  });
1673
2171
  updated_inventory_levels.push(updated_inventory_level);
@@ -1692,8 +2190,7 @@ var bulk_delete7 = async (props) => {
1692
2190
  action: "delete",
1693
2191
  table: "inventory_levels",
1694
2192
  document_id: id,
1695
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1696
- stall_offline_id: existing.stall_offline_id,
2193
+ stall_offline_id: existing.metadata.stall_offline_id,
1697
2194
  data: { id }
1698
2195
  });
1699
2196
  await local_db.inventory_levels.delete(id);
@@ -1758,12 +2255,11 @@ var create8 = async (props) => {
1758
2255
  id: offline_id,
1759
2256
  metadata: {
1760
2257
  ...data.metadata,
1761
- stall_offline_id: offline_id
1762
- },
1763
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1764
- stall_offline_id: offline_id,
1765
- stall_offline_created_at: now,
1766
- stall_offline_updated_at: now
2258
+ stall_offline_id: offline_id,
2259
+ stall_offline_created_at: now,
2260
+ stall_offline_updated_at: now,
2261
+ stall_offline_deleted_at: ""
2262
+ }
1767
2263
  };
1768
2264
  await local_db.promotions.add(local_promotion);
1769
2265
  await add_to_sync_queue({
@@ -1790,17 +2286,21 @@ var update8 = async (props) => {
1790
2286
  ...existing,
1791
2287
  ...data,
1792
2288
  id: existing.id,
1793
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1794
- stall_offline_id: existing.stall_offline_id,
1795
- stall_offline_updated_at: now
2289
+ metadata: {
2290
+ ...existing.metadata,
2291
+ ...data.metadata,
2292
+ stall_offline_id: existing.metadata.stall_offline_id,
2293
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2294
+ stall_offline_updated_at: now,
2295
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2296
+ }
1796
2297
  };
1797
2298
  await local_db.promotions.put(updated_promotion);
1798
2299
  await add_to_sync_queue({
1799
2300
  action: "update",
1800
2301
  table: "promotions",
1801
2302
  document_id: id,
1802
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1803
- stall_offline_id: existing.stall_offline_id,
2303
+ stall_offline_id: existing.metadata.stall_offline_id,
1804
2304
  data: updated_promotion
1805
2305
  });
1806
2306
  return updated_promotion;
@@ -1819,8 +2319,7 @@ var _delete8 = async (props) => {
1819
2319
  action: "delete",
1820
2320
  table: "promotions",
1821
2321
  document_id: id,
1822
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1823
- stall_offline_id: existing.stall_offline_id,
2322
+ stall_offline_id: existing.metadata.stall_offline_id,
1824
2323
  data: { id }
1825
2324
  });
1826
2325
  await local_db.promotions.delete(id);
@@ -1841,12 +2340,11 @@ var bulk_create8 = async (props) => {
1841
2340
  id: offline_id,
1842
2341
  metadata: {
1843
2342
  ...promotion.metadata,
1844
- stall_offline_id: offline_id
1845
- },
1846
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1847
- stall_offline_id: offline_id,
1848
- stall_offline_created_at: now,
1849
- stall_offline_updated_at: now
2343
+ stall_offline_id: offline_id,
2344
+ stall_offline_created_at: now,
2345
+ stall_offline_updated_at: now,
2346
+ stall_offline_deleted_at: ""
2347
+ }
1850
2348
  };
1851
2349
  await local_db.promotions.add(local_promotion);
1852
2350
  await add_to_sync_queue({
@@ -1880,17 +2378,21 @@ var bulk_update8 = async (props) => {
1880
2378
  ...existing,
1881
2379
  ...item.data,
1882
2380
  id: existing.id,
1883
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1884
- stall_offline_id: existing.stall_offline_id,
1885
- stall_offline_updated_at: now
2381
+ metadata: {
2382
+ ...existing.metadata,
2383
+ ...item.data.metadata,
2384
+ stall_offline_id: existing.metadata.stall_offline_id,
2385
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2386
+ stall_offline_updated_at: now,
2387
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2388
+ }
1886
2389
  };
1887
2390
  await local_db.promotions.put(updated_promotion);
1888
2391
  await add_to_sync_queue({
1889
2392
  action: "update",
1890
2393
  table: "promotions",
1891
2394
  document_id: item.id,
1892
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1893
- stall_offline_id: existing.stall_offline_id,
2395
+ stall_offline_id: existing.metadata.stall_offline_id,
1894
2396
  data: updated_promotion
1895
2397
  });
1896
2398
  updated_promotions.push(updated_promotion);
@@ -1913,8 +2415,7 @@ var bulk_delete8 = async (props) => {
1913
2415
  action: "delete",
1914
2416
  table: "promotions",
1915
2417
  document_id: id,
1916
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1917
- stall_offline_id: existing.stall_offline_id,
2418
+ stall_offline_id: existing.metadata.stall_offline_id,
1918
2419
  data: { id }
1919
2420
  });
1920
2421
  await local_db.promotions.delete(id);
@@ -1979,12 +2480,11 @@ var create9 = async (props) => {
1979
2480
  id: offline_id,
1980
2481
  metadata: {
1981
2482
  ...data.metadata,
1982
- stall_offline_id: offline_id
1983
- },
1984
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1985
- stall_offline_id: offline_id,
1986
- stall_offline_created_at: now,
1987
- stall_offline_updated_at: now
2483
+ stall_offline_id: offline_id,
2484
+ stall_offline_created_at: now,
2485
+ stall_offline_updated_at: now,
2486
+ stall_offline_deleted_at: ""
2487
+ }
1988
2488
  };
1989
2489
  await local_db.order_notes.add(local_order_note);
1990
2490
  await add_to_sync_queue({
@@ -2011,17 +2511,21 @@ var update9 = async (props) => {
2011
2511
  ...existing,
2012
2512
  ...data,
2013
2513
  id: existing.id,
2014
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2015
- stall_offline_id: existing.stall_offline_id,
2016
- stall_offline_updated_at: now
2514
+ metadata: {
2515
+ ...existing.metadata,
2516
+ ...data.metadata,
2517
+ stall_offline_id: existing.metadata.stall_offline_id,
2518
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2519
+ stall_offline_updated_at: now,
2520
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2521
+ }
2017
2522
  };
2018
2523
  await local_db.order_notes.put(updated_order_note);
2019
2524
  await add_to_sync_queue({
2020
2525
  action: "update",
2021
2526
  table: "order_notes",
2022
2527
  document_id: id,
2023
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2024
- stall_offline_id: existing.stall_offline_id,
2528
+ stall_offline_id: existing.metadata.stall_offline_id,
2025
2529
  data: updated_order_note
2026
2530
  });
2027
2531
  return updated_order_note;
@@ -2040,8 +2544,7 @@ var _delete9 = async (props) => {
2040
2544
  action: "delete",
2041
2545
  table: "order_notes",
2042
2546
  document_id: id,
2043
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2044
- stall_offline_id: existing.stall_offline_id,
2547
+ stall_offline_id: existing.metadata.stall_offline_id,
2045
2548
  data: { id }
2046
2549
  });
2047
2550
  await local_db.order_notes.delete(id);
@@ -2062,12 +2565,11 @@ var bulk_create9 = async (props) => {
2062
2565
  id: offline_id,
2063
2566
  metadata: {
2064
2567
  ...order_note.metadata,
2065
- stall_offline_id: offline_id
2066
- },
2067
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2068
- stall_offline_id: offline_id,
2069
- stall_offline_created_at: now,
2070
- stall_offline_updated_at: now
2568
+ stall_offline_id: offline_id,
2569
+ stall_offline_created_at: now,
2570
+ stall_offline_updated_at: now,
2571
+ stall_offline_deleted_at: ""
2572
+ }
2071
2573
  };
2072
2574
  await local_db.order_notes.add(local_order_note);
2073
2575
  await add_to_sync_queue({
@@ -2101,17 +2603,21 @@ var bulk_update9 = async (props) => {
2101
2603
  ...existing,
2102
2604
  ...item.data,
2103
2605
  id: existing.id,
2104
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2105
- stall_offline_id: existing.stall_offline_id,
2106
- stall_offline_updated_at: now
2606
+ metadata: {
2607
+ ...existing.metadata,
2608
+ ...item.data.metadata,
2609
+ stall_offline_id: existing.metadata.stall_offline_id,
2610
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2611
+ stall_offline_updated_at: now,
2612
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2613
+ }
2107
2614
  };
2108
2615
  await local_db.order_notes.put(updated_order_note);
2109
2616
  await add_to_sync_queue({
2110
2617
  action: "update",
2111
2618
  table: "order_notes",
2112
2619
  document_id: item.id,
2113
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2114
- stall_offline_id: existing.stall_offline_id,
2620
+ stall_offline_id: existing.metadata.stall_offline_id,
2115
2621
  data: updated_order_note
2116
2622
  });
2117
2623
  updated_order_notes.push(updated_order_note);
@@ -2134,8 +2640,7 @@ var bulk_delete9 = async (props) => {
2134
2640
  action: "delete",
2135
2641
  table: "order_notes",
2136
2642
  document_id: id,
2137
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2138
- stall_offline_id: existing.stall_offline_id,
2643
+ stall_offline_id: existing.metadata.stall_offline_id,
2139
2644
  data: { id }
2140
2645
  });
2141
2646
  await local_db.order_notes.delete(id);
@@ -2200,12 +2705,11 @@ var create10 = async (props) => {
2200
2705
  id: offline_id,
2201
2706
  metadata: {
2202
2707
  ...data.metadata,
2203
- stall_offline_id: offline_id
2204
- },
2205
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2206
- stall_offline_id: offline_id,
2207
- stall_offline_created_at: now,
2208
- stall_offline_updated_at: now
2708
+ stall_offline_id: offline_id,
2709
+ stall_offline_created_at: now,
2710
+ stall_offline_updated_at: now,
2711
+ stall_offline_deleted_at: ""
2712
+ }
2209
2713
  };
2210
2714
  await local_db.refunds.add(local_refund);
2211
2715
  await add_to_sync_queue({
@@ -2232,17 +2736,21 @@ var update10 = async (props) => {
2232
2736
  ...existing,
2233
2737
  ...data,
2234
2738
  id: existing.id,
2235
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2236
- stall_offline_id: existing.stall_offline_id,
2237
- stall_offline_updated_at: now
2739
+ metadata: {
2740
+ ...existing.metadata,
2741
+ ...data.metadata,
2742
+ stall_offline_id: existing.metadata.stall_offline_id,
2743
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2744
+ stall_offline_updated_at: now,
2745
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2746
+ }
2238
2747
  };
2239
2748
  await local_db.refunds.put(updated_refund);
2240
2749
  await add_to_sync_queue({
2241
2750
  action: "update",
2242
2751
  table: "refunds",
2243
2752
  document_id: id,
2244
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2245
- stall_offline_id: existing.stall_offline_id,
2753
+ stall_offline_id: existing.metadata.stall_offline_id,
2246
2754
  data: updated_refund
2247
2755
  });
2248
2756
  return updated_refund;
@@ -2261,8 +2769,7 @@ var _delete10 = async (props) => {
2261
2769
  action: "delete",
2262
2770
  table: "refunds",
2263
2771
  document_id: id,
2264
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2265
- stall_offline_id: existing.stall_offline_id,
2772
+ stall_offline_id: existing.metadata.stall_offline_id,
2266
2773
  data: { id }
2267
2774
  });
2268
2775
  await local_db.refunds.delete(id);
@@ -2283,12 +2790,11 @@ var bulk_create10 = async (props) => {
2283
2790
  id: offline_id,
2284
2791
  metadata: {
2285
2792
  ...refund.metadata,
2286
- stall_offline_id: offline_id
2287
- },
2288
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2289
- stall_offline_id: offline_id,
2290
- stall_offline_created_at: now,
2291
- stall_offline_updated_at: now
2793
+ stall_offline_id: offline_id,
2794
+ stall_offline_created_at: now,
2795
+ stall_offline_updated_at: now,
2796
+ stall_offline_deleted_at: ""
2797
+ }
2292
2798
  };
2293
2799
  await local_db.refunds.add(local_refund);
2294
2800
  await add_to_sync_queue({
@@ -2320,17 +2826,21 @@ var bulk_update10 = async (props) => {
2320
2826
  ...existing,
2321
2827
  ...item.data,
2322
2828
  id: existing.id,
2323
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2324
- stall_offline_id: existing.stall_offline_id,
2325
- stall_offline_updated_at: now
2829
+ metadata: {
2830
+ ...existing.metadata,
2831
+ ...item.data.metadata,
2832
+ stall_offline_id: existing.metadata.stall_offline_id,
2833
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2834
+ stall_offline_updated_at: now,
2835
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2836
+ }
2326
2837
  };
2327
2838
  await local_db.refunds.put(updated_refund);
2328
2839
  await add_to_sync_queue({
2329
2840
  action: "update",
2330
2841
  table: "refunds",
2331
2842
  document_id: item.id,
2332
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2333
- stall_offline_id: existing.stall_offline_id,
2843
+ stall_offline_id: existing.metadata.stall_offline_id,
2334
2844
  data: updated_refund
2335
2845
  });
2336
2846
  updated_refunds.push(updated_refund);
@@ -2353,8 +2863,7 @@ var bulk_delete10 = async (props) => {
2353
2863
  action: "delete",
2354
2864
  table: "refunds",
2355
2865
  document_id: id,
2356
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2357
- stall_offline_id: existing.stall_offline_id,
2866
+ stall_offline_id: existing.metadata.stall_offline_id,
2358
2867
  data: { id }
2359
2868
  });
2360
2869
  await local_db.refunds.delete(id);
@@ -2418,14 +2927,12 @@ var create11 = async (props) => {
2418
2927
  ...data,
2419
2928
  id: offline_id,
2420
2929
  metadata: {
2421
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2422
2930
  ...data.metadata,
2423
- stall_offline_id: offline_id
2424
- },
2425
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2426
- stall_offline_id: offline_id,
2427
- stall_offline_created_at: now,
2428
- stall_offline_updated_at: now
2931
+ stall_offline_id: offline_id,
2932
+ stall_offline_created_at: now,
2933
+ stall_offline_updated_at: now,
2934
+ stall_offline_deleted_at: ""
2935
+ }
2429
2936
  };
2430
2937
  await local_db.payment_providers.add(local_payment_provider);
2431
2938
  await add_to_sync_queue({
@@ -2452,17 +2959,21 @@ var update11 = async (props) => {
2452
2959
  ...existing,
2453
2960
  ...data,
2454
2961
  id: existing.id,
2455
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2456
- stall_offline_id: existing.stall_offline_id,
2457
- stall_offline_updated_at: now
2962
+ metadata: {
2963
+ ...existing.metadata,
2964
+ ...data.metadata,
2965
+ stall_offline_id: existing.metadata.stall_offline_id,
2966
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
2967
+ stall_offline_updated_at: now,
2968
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
2969
+ }
2458
2970
  };
2459
2971
  await local_db.payment_providers.put(updated_payment_provider);
2460
2972
  await add_to_sync_queue({
2461
2973
  action: "update",
2462
2974
  table: "payment_providers",
2463
2975
  document_id: id,
2464
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2465
- stall_offline_id: existing.stall_offline_id,
2976
+ stall_offline_id: existing.metadata.stall_offline_id,
2466
2977
  data: updated_payment_provider
2467
2978
  });
2468
2979
  return updated_payment_provider;
@@ -2481,8 +2992,7 @@ var _delete11 = async (props) => {
2481
2992
  action: "delete",
2482
2993
  table: "payment_providers",
2483
2994
  document_id: id,
2484
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2485
- stall_offline_id: existing.stall_offline_id,
2995
+ stall_offline_id: existing.metadata.stall_offline_id,
2486
2996
  data: { id }
2487
2997
  });
2488
2998
  await local_db.payment_providers.delete(id);
@@ -2502,14 +3012,12 @@ var bulk_create11 = async (props) => {
2502
3012
  ...payment_provider,
2503
3013
  id: offline_id,
2504
3014
  metadata: {
2505
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2506
3015
  ...payment_provider.metadata,
2507
- stall_offline_id: offline_id
2508
- },
2509
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2510
- stall_offline_id: offline_id,
2511
- stall_offline_created_at: now,
2512
- stall_offline_updated_at: now
3016
+ stall_offline_id: offline_id,
3017
+ stall_offline_created_at: now,
3018
+ stall_offline_updated_at: now,
3019
+ stall_offline_deleted_at: ""
3020
+ }
2513
3021
  };
2514
3022
  await local_db.payment_providers.add(local_payment_provider);
2515
3023
  await add_to_sync_queue({
@@ -2543,17 +3051,21 @@ var bulk_update11 = async (props) => {
2543
3051
  ...existing,
2544
3052
  ...item.data,
2545
3053
  id: existing.id,
2546
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2547
- stall_offline_id: existing.stall_offline_id,
2548
- stall_offline_updated_at: now
3054
+ metadata: {
3055
+ ...existing.metadata,
3056
+ ...item.data.metadata,
3057
+ stall_offline_id: existing.metadata.stall_offline_id,
3058
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3059
+ stall_offline_updated_at: now,
3060
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3061
+ }
2549
3062
  };
2550
3063
  await local_db.payment_providers.put(updated_payment_provider);
2551
3064
  await add_to_sync_queue({
2552
3065
  action: "update",
2553
3066
  table: "payment_providers",
2554
3067
  document_id: item.id,
2555
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2556
- stall_offline_id: existing.stall_offline_id,
3068
+ stall_offline_id: existing.metadata.stall_offline_id,
2557
3069
  data: updated_payment_provider
2558
3070
  });
2559
3071
  updated_payment_providers.push(updated_payment_provider);
@@ -2578,8 +3090,7 @@ var bulk_delete11 = async (props) => {
2578
3090
  action: "delete",
2579
3091
  table: "payment_providers",
2580
3092
  document_id: id,
2581
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2582
- stall_offline_id: existing.stall_offline_id,
3093
+ stall_offline_id: existing.metadata.stall_offline_id,
2583
3094
  data: { id }
2584
3095
  });
2585
3096
  await local_db.payment_providers.delete(id);
@@ -2644,12 +3155,11 @@ var create12 = async (props) => {
2644
3155
  id: offline_id,
2645
3156
  metadata: {
2646
3157
  ...data.metadata,
2647
- stall_offline_id: offline_id
2648
- },
2649
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2650
- stall_offline_id: offline_id,
2651
- stall_offline_created_at: now,
2652
- stall_offline_updated_at: now
3158
+ stall_offline_id: offline_id,
3159
+ stall_offline_created_at: now,
3160
+ stall_offline_updated_at: now,
3161
+ stall_offline_deleted_at: ""
3162
+ }
2653
3163
  };
2654
3164
  await local_db.payments.add(local_payment);
2655
3165
  await add_to_sync_queue({
@@ -2676,17 +3186,21 @@ var update12 = async (props) => {
2676
3186
  ...existing,
2677
3187
  ...data,
2678
3188
  id: existing.id,
2679
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2680
- stall_offline_id: existing.stall_offline_id,
2681
- stall_offline_updated_at: now
3189
+ metadata: {
3190
+ ...existing.metadata,
3191
+ ...data.metadata,
3192
+ stall_offline_id: existing.metadata.stall_offline_id,
3193
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3194
+ stall_offline_updated_at: now,
3195
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3196
+ }
2682
3197
  };
2683
3198
  await local_db.payments.put(updated_payment);
2684
3199
  await add_to_sync_queue({
2685
3200
  action: "update",
2686
3201
  table: "payments",
2687
3202
  document_id: id,
2688
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2689
- stall_offline_id: existing.stall_offline_id,
3203
+ stall_offline_id: existing.metadata.stall_offline_id,
2690
3204
  data: updated_payment
2691
3205
  });
2692
3206
  return updated_payment;
@@ -2705,8 +3219,7 @@ var _delete12 = async (props) => {
2705
3219
  action: "delete",
2706
3220
  table: "payments",
2707
3221
  document_id: id,
2708
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2709
- stall_offline_id: existing.stall_offline_id,
3222
+ stall_offline_id: existing.metadata.stall_offline_id,
2710
3223
  data: { id }
2711
3224
  });
2712
3225
  await local_db.payments.delete(id);
@@ -2727,12 +3240,11 @@ var bulk_create12 = async (props) => {
2727
3240
  id: offline_id,
2728
3241
  metadata: {
2729
3242
  ...payment.metadata,
2730
- stall_offline_id: offline_id
2731
- },
2732
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2733
- stall_offline_id: offline_id,
2734
- stall_offline_created_at: now,
2735
- stall_offline_updated_at: now
3243
+ stall_offline_id: offline_id,
3244
+ stall_offline_created_at: now,
3245
+ stall_offline_updated_at: now,
3246
+ stall_offline_deleted_at: ""
3247
+ }
2736
3248
  };
2737
3249
  await local_db.payments.add(local_payment);
2738
3250
  await add_to_sync_queue({
@@ -2764,17 +3276,21 @@ var bulk_update12 = async (props) => {
2764
3276
  ...existing,
2765
3277
  ...item.data,
2766
3278
  id: existing.id,
2767
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2768
- stall_offline_id: existing.stall_offline_id,
2769
- stall_offline_updated_at: now
3279
+ metadata: {
3280
+ ...existing.metadata,
3281
+ ...item.data.metadata,
3282
+ stall_offline_id: existing.metadata.stall_offline_id,
3283
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3284
+ stall_offline_updated_at: now,
3285
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3286
+ }
2770
3287
  };
2771
3288
  await local_db.payments.put(updated_payment);
2772
3289
  await add_to_sync_queue({
2773
3290
  action: "update",
2774
3291
  table: "payments",
2775
3292
  document_id: item.id,
2776
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2777
- stall_offline_id: existing.stall_offline_id,
3293
+ stall_offline_id: existing.metadata.stall_offline_id,
2778
3294
  data: updated_payment
2779
3295
  });
2780
3296
  updated_payments.push(updated_payment);
@@ -2797,8 +3313,7 @@ var bulk_delete12 = async (props) => {
2797
3313
  action: "delete",
2798
3314
  table: "payments",
2799
3315
  document_id: id,
2800
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2801
- stall_offline_id: existing.stall_offline_id,
3316
+ stall_offline_id: existing.metadata.stall_offline_id,
2802
3317
  data: { id }
2803
3318
  });
2804
3319
  await local_db.payments.delete(id);
@@ -2863,11 +3378,11 @@ var create13 = async (props) => {
2863
3378
  id: offline_id,
2864
3379
  metadata: {
2865
3380
  ...data.metadata,
2866
- stall_offline_id: offline_id
2867
- },
2868
- stall_offline_id: offline_id,
2869
- stall_offline_created_at: now,
2870
- stall_offline_updated_at: now
3381
+ stall_offline_id: offline_id,
3382
+ stall_offline_created_at: now,
3383
+ stall_offline_updated_at: now,
3384
+ stall_offline_deleted_at: ""
3385
+ }
2871
3386
  };
2872
3387
  await local_db.tax_regions.add(local_region);
2873
3388
  await add_to_sync_queue({
@@ -2894,17 +3409,21 @@ var update13 = async (props) => {
2894
3409
  ...existing,
2895
3410
  ...data,
2896
3411
  id: existing.id,
2897
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2898
- stall_offline_id: existing.stall_offline_id,
2899
- stall_offline_updated_at: now
3412
+ metadata: {
3413
+ ...existing.metadata,
3414
+ ...data.metadata,
3415
+ stall_offline_id: existing.metadata.stall_offline_id,
3416
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3417
+ stall_offline_updated_at: now,
3418
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3419
+ }
2900
3420
  };
2901
3421
  await local_db.tax_regions.put(updated_region);
2902
3422
  await add_to_sync_queue({
2903
3423
  action: "update",
2904
3424
  table: "tax_regions",
2905
3425
  document_id: id,
2906
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2907
- stall_offline_id: existing.stall_offline_id,
3426
+ stall_offline_id: existing.metadata.stall_offline_id,
2908
3427
  data: updated_region
2909
3428
  });
2910
3429
  return updated_region;
@@ -2923,8 +3442,7 @@ var _delete13 = async (props) => {
2923
3442
  action: "delete",
2924
3443
  table: "tax_regions",
2925
3444
  document_id: id,
2926
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2927
- stall_offline_id: existing.stall_offline_id,
3445
+ stall_offline_id: existing.metadata.stall_offline_id,
2928
3446
  data: { id }
2929
3447
  });
2930
3448
  await local_db.tax_regions.delete(id);
@@ -2945,11 +3463,11 @@ var bulk_create13 = async (props) => {
2945
3463
  id: offline_id,
2946
3464
  metadata: {
2947
3465
  ...region.metadata,
2948
- stall_offline_id: offline_id
2949
- },
2950
- stall_offline_id: offline_id,
2951
- stall_offline_created_at: now,
2952
- stall_offline_updated_at: now
3466
+ stall_offline_id: offline_id,
3467
+ stall_offline_created_at: now,
3468
+ stall_offline_updated_at: now,
3469
+ stall_offline_deleted_at: ""
3470
+ }
2953
3471
  };
2954
3472
  await local_db.tax_regions.add(local_region);
2955
3473
  await add_to_sync_queue({
@@ -2983,17 +3501,21 @@ var bulk_update13 = async (props) => {
2983
3501
  ...existing,
2984
3502
  ...item.data,
2985
3503
  id: existing.id,
2986
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2987
- stall_offline_id: existing.stall_offline_id,
2988
- stall_offline_updated_at: now
3504
+ metadata: {
3505
+ ...existing.metadata,
3506
+ ...item.data.metadata,
3507
+ stall_offline_id: existing.metadata.stall_offline_id,
3508
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3509
+ stall_offline_updated_at: now,
3510
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3511
+ }
2989
3512
  };
2990
3513
  await local_db.tax_regions.put(updated_region);
2991
3514
  await add_to_sync_queue({
2992
3515
  action: "update",
2993
3516
  table: "tax_regions",
2994
3517
  document_id: item.id,
2995
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2996
- stall_offline_id: existing.stall_offline_id,
3518
+ stall_offline_id: existing.metadata.stall_offline_id,
2997
3519
  data: updated_region
2998
3520
  });
2999
3521
  updated_regions.push(updated_region);
@@ -3016,8 +3538,7 @@ var bulk_delete13 = async (props) => {
3016
3538
  action: "delete",
3017
3539
  table: "tax_regions",
3018
3540
  document_id: id,
3019
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3020
- stall_offline_id: existing.stall_offline_id,
3541
+ stall_offline_id: existing.metadata.stall_offline_id,
3021
3542
  data: { id }
3022
3543
  });
3023
3544
  await local_db.tax_regions.delete(id);
@@ -3082,11 +3603,11 @@ var create14 = async (props) => {
3082
3603
  id: offline_id,
3083
3604
  metadata: {
3084
3605
  ...data.metadata,
3085
- stall_offline_id: offline_id
3086
- },
3087
- stall_offline_id: offline_id,
3088
- stall_offline_created_at: now,
3089
- stall_offline_updated_at: now
3606
+ stall_offline_id: offline_id,
3607
+ stall_offline_created_at: now,
3608
+ stall_offline_updated_at: now,
3609
+ stall_offline_deleted_at: ""
3610
+ }
3090
3611
  };
3091
3612
  await local_db.tax_rates.add(local_rate);
3092
3613
  await add_to_sync_queue({
@@ -3113,17 +3634,21 @@ var update14 = async (props) => {
3113
3634
  ...existing,
3114
3635
  ...data,
3115
3636
  id: existing.id,
3116
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3117
- stall_offline_id: existing.stall_offline_id,
3118
- stall_offline_updated_at: now
3637
+ metadata: {
3638
+ ...existing.metadata,
3639
+ ...data.metadata,
3640
+ stall_offline_id: existing.metadata.stall_offline_id,
3641
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3642
+ stall_offline_updated_at: now,
3643
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3644
+ }
3119
3645
  };
3120
3646
  await local_db.tax_rates.put(updated_rate);
3121
3647
  await add_to_sync_queue({
3122
3648
  action: "update",
3123
3649
  table: "tax_rates",
3124
3650
  document_id: id,
3125
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3126
- stall_offline_id: existing.stall_offline_id,
3651
+ stall_offline_id: existing.metadata.stall_offline_id,
3127
3652
  data: updated_rate
3128
3653
  });
3129
3654
  return updated_rate;
@@ -3142,8 +3667,7 @@ var _delete14 = async (props) => {
3142
3667
  action: "delete",
3143
3668
  table: "tax_rates",
3144
3669
  document_id: id,
3145
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3146
- stall_offline_id: existing.stall_offline_id,
3670
+ stall_offline_id: existing.metadata.stall_offline_id,
3147
3671
  data: { id }
3148
3672
  });
3149
3673
  await local_db.tax_rates.delete(id);
@@ -3164,11 +3688,11 @@ var bulk_create14 = async (props) => {
3164
3688
  id: offline_id,
3165
3689
  metadata: {
3166
3690
  ...rate.metadata,
3167
- stall_offline_id: offline_id
3168
- },
3169
- stall_offline_id: offline_id,
3170
- stall_offline_created_at: now,
3171
- stall_offline_updated_at: now
3691
+ stall_offline_id: offline_id,
3692
+ stall_offline_created_at: now,
3693
+ stall_offline_updated_at: now,
3694
+ stall_offline_deleted_at: ""
3695
+ }
3172
3696
  };
3173
3697
  await local_db.tax_rates.add(local_rate);
3174
3698
  await add_to_sync_queue({
@@ -3200,17 +3724,21 @@ var bulk_update14 = async (props) => {
3200
3724
  ...existing,
3201
3725
  ...item.data,
3202
3726
  id: existing.id,
3203
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3204
- stall_offline_id: existing.stall_offline_id,
3205
- stall_offline_updated_at: now
3727
+ metadata: {
3728
+ ...existing.metadata,
3729
+ ...item.data.metadata,
3730
+ stall_offline_id: existing.metadata.stall_offline_id,
3731
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
3732
+ stall_offline_updated_at: now,
3733
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
3734
+ }
3206
3735
  };
3207
3736
  await local_db.tax_rates.put(updated_rate);
3208
3737
  await add_to_sync_queue({
3209
3738
  action: "update",
3210
3739
  table: "tax_rates",
3211
3740
  document_id: item.id,
3212
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3213
- stall_offline_id: existing.stall_offline_id,
3741
+ stall_offline_id: existing.metadata.stall_offline_id,
3214
3742
  data: updated_rate
3215
3743
  });
3216
3744
  updated_rates.push(updated_rate);
@@ -3233,8 +3761,7 @@ var bulk_delete14 = async (props) => {
3233
3761
  action: "delete",
3234
3762
  table: "tax_rates",
3235
3763
  document_id: id,
3236
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3237
- stall_offline_id: existing.stall_offline_id,
3764
+ stall_offline_id: existing.metadata.stall_offline_id,
3238
3765
  data: { id }
3239
3766
  });
3240
3767
  await local_db.tax_rates.delete(id);
@@ -3256,6 +3783,53 @@ var tax_rates = {
3256
3783
  };
3257
3784
 
3258
3785
  // src/services/locations.service.ts
3786
+ var build_location = (data, offline_id, now) => {
3787
+ return {
3788
+ id: offline_id,
3789
+ name: data.name || "",
3790
+ address: data.address || "",
3791
+ city: data.city || "",
3792
+ country: data.country || "",
3793
+ region: data.region || "",
3794
+ base_currency: data.base_currency || "",
3795
+ timezone: data.timezone || "",
3796
+ organization_id: data.organization_id || "",
3797
+ created_at: data.created_at || now,
3798
+ updated_at: data.updated_at || now,
3799
+ active: data.active ?? true,
3800
+ metadata: {
3801
+ ...data.metadata,
3802
+ stall_offline_id: offline_id,
3803
+ stall_offline_created_at: now,
3804
+ stall_offline_updated_at: now,
3805
+ stall_offline_deleted_at: ""
3806
+ }
3807
+ };
3808
+ };
3809
+ var merge_location = (existing, updates, now) => {
3810
+ return {
3811
+ id: existing.id,
3812
+ name: updates.name ?? existing.name,
3813
+ address: updates.address ?? existing.address,
3814
+ city: updates.city ?? existing.city,
3815
+ country: updates.country ?? existing.country,
3816
+ region: updates.region ?? existing.region,
3817
+ base_currency: updates.base_currency ?? existing.base_currency,
3818
+ timezone: updates.timezone ?? existing.timezone,
3819
+ organization_id: updates.organization_id ?? existing.organization_id,
3820
+ created_at: existing.created_at,
3821
+ updated_at: now,
3822
+ active: updates.active ?? existing.active,
3823
+ metadata: {
3824
+ ...existing.metadata,
3825
+ ...updates.metadata,
3826
+ stall_offline_id: existing.metadata?.stall_offline_id || "",
3827
+ stall_offline_created_at: existing.metadata?.stall_offline_created_at || "",
3828
+ stall_offline_updated_at: now,
3829
+ stall_offline_deleted_at: existing.metadata?.stall_offline_deleted_at || ""
3830
+ }
3831
+ };
3832
+ };
3259
3833
  var list15 = async (props) => {
3260
3834
  try {
3261
3835
  const { sdk, query } = props;
@@ -3294,18 +3868,7 @@ var create15 = async (props) => {
3294
3868
  const { sdk, data } = props;
3295
3869
  const offline_id = generate_offline_id("location");
3296
3870
  const now = (/* @__PURE__ */ new Date()).toISOString();
3297
- const local_location = {
3298
- ...data,
3299
- id: offline_id,
3300
- metadata: {
3301
- ...data.metadata,
3302
- stall_offline_id: offline_id
3303
- },
3304
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3305
- stall_offline_id: offline_id,
3306
- stall_offline_created_at: now,
3307
- stall_offline_updated_at: now
3308
- };
3871
+ const local_location = build_location(data, offline_id, now);
3309
3872
  await local_db.locations.add(local_location);
3310
3873
  await add_to_sync_queue({
3311
3874
  action: "create",
@@ -3327,21 +3890,13 @@ var update15 = async (props) => {
3327
3890
  throw new Error(`Location with id ${id} not found locally`);
3328
3891
  }
3329
3892
  const now = (/* @__PURE__ */ new Date()).toISOString();
3330
- const updated_location = {
3331
- ...existing,
3332
- ...data,
3333
- id: existing.id,
3334
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3335
- stall_offline_id: existing.stall_offline_id,
3336
- stall_offline_updated_at: now
3337
- };
3893
+ const updated_location = merge_location(existing, data, now);
3338
3894
  await local_db.locations.put(updated_location);
3339
3895
  await add_to_sync_queue({
3340
3896
  action: "update",
3341
3897
  table: "locations",
3342
3898
  document_id: id,
3343
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3344
- stall_offline_id: existing.stall_offline_id,
3899
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3345
3900
  data: updated_location
3346
3901
  });
3347
3902
  return updated_location;
@@ -3360,8 +3915,7 @@ var _delete15 = async (props) => {
3360
3915
  action: "delete",
3361
3916
  table: "locations",
3362
3917
  document_id: id,
3363
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3364
- stall_offline_id: existing.stall_offline_id,
3918
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3365
3919
  data: { id }
3366
3920
  });
3367
3921
  await local_db.locations.delete(id);
@@ -3377,18 +3931,7 @@ var bulk_create15 = async (props) => {
3377
3931
  const created_locations = [];
3378
3932
  for (const location of data) {
3379
3933
  const offline_id = generate_offline_id("location");
3380
- const local_location = {
3381
- ...location,
3382
- id: offline_id,
3383
- metadata: {
3384
- ...location.metadata,
3385
- stall_offline_id: offline_id
3386
- },
3387
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3388
- stall_offline_id: offline_id,
3389
- stall_offline_created_at: now,
3390
- stall_offline_updated_at: now
3391
- };
3934
+ const local_location = build_location(location, offline_id, now);
3392
3935
  await local_db.locations.add(local_location);
3393
3936
  await add_to_sync_queue({
3394
3937
  action: "create",
@@ -3415,21 +3958,13 @@ var bulk_update15 = async (props) => {
3415
3958
  console.warn(`Location with id ${item.id} not found locally, skipping`);
3416
3959
  continue;
3417
3960
  }
3418
- const updated_location = {
3419
- ...existing,
3420
- ...item.data,
3421
- id: existing.id,
3422
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3423
- stall_offline_id: existing.stall_offline_id,
3424
- stall_offline_updated_at: now
3425
- };
3961
+ const updated_location = merge_location(existing, item.data, now);
3426
3962
  await local_db.locations.put(updated_location);
3427
3963
  await add_to_sync_queue({
3428
3964
  action: "update",
3429
3965
  table: "locations",
3430
3966
  document_id: item.id,
3431
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3432
- stall_offline_id: existing.stall_offline_id,
3967
+ stall_offline_id: existing.metadata?.stall_offline_id || item.id,
3433
3968
  data: updated_location
3434
3969
  });
3435
3970
  updated_locations.push(updated_location);
@@ -3443,660 +3978,259 @@ var bulk_delete15 = async (props) => {
3443
3978
  try {
3444
3979
  const { sdk, ids } = props;
3445
3980
  for (const id of ids) {
3446
- const existing = await local_db.locations.get(id);
3447
- if (!existing) {
3448
- console.warn(`Location with id ${id} not found locally, skipping`);
3449
- continue;
3450
- }
3451
- await add_to_sync_queue({
3452
- action: "delete",
3453
- table: "locations",
3454
- document_id: id,
3455
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3456
- stall_offline_id: existing.stall_offline_id,
3457
- data: { id }
3458
- });
3459
- await local_db.locations.delete(id);
3460
- }
3461
- return;
3462
- } catch (error) {
3463
- throw error;
3464
- }
3465
- };
3466
- var locations = {
3467
- list: list15,
3468
- retrieve: retrieve15,
3469
- create: create15,
3470
- update: update15,
3471
- delete: _delete15,
3472
- bulk_create: bulk_create15,
3473
- bulk_update: bulk_update15,
3474
- bulk_delete: bulk_delete15
3475
- };
3476
-
3477
- // src/services/fulfillments.service.ts
3478
- var list16 = async (props) => {
3479
- try {
3480
- const { sdk, query } = props;
3481
- const adapter = await sdk.adapter();
3482
- if (!adapter) throw new Error("Adapter not found");
3483
- const fulfillments2 = await adapter.fulfillments.list({
3484
- connector_config: sdk.options.configuration,
3485
- query
3486
- });
3487
- await save_bulk_data({
3488
- table: "fulfillments",
3489
- data: fulfillments2
3490
- });
3491
- return fulfillments2;
3492
- } catch (error) {
3493
- throw error;
3494
- }
3495
- };
3496
- var retrieve16 = async (props) => {
3497
- try {
3498
- const { sdk, id } = props;
3499
- const adapter = await sdk.adapter();
3500
- if (!adapter) throw new Error("Adapter not found");
3501
- const fulfillment = await adapter.fulfillments.retrieve({
3502
- connector_config: sdk.options.configuration,
3503
- id
3504
- });
3505
- await local_db.fulfillments.put(fulfillment);
3506
- return fulfillment;
3507
- } catch (error) {
3508
- throw error;
3509
- }
3510
- };
3511
- var create16 = async (props) => {
3512
- try {
3513
- const { sdk, data } = props;
3514
- const offline_id = generate_offline_id("fulfillment");
3515
- const now = (/* @__PURE__ */ new Date()).toISOString();
3516
- const local_fulfillment = {
3517
- ...data,
3518
- id: offline_id,
3519
- metadata: {
3520
- ...data.metadata,
3521
- stall_offline_id: offline_id
3522
- },
3523
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3524
- stall_offline_id: offline_id,
3525
- stall_offline_created_at: now,
3526
- stall_offline_updated_at: now
3527
- };
3528
- await local_db.fulfillments.add(local_fulfillment);
3529
- await add_to_sync_queue({
3530
- action: "create",
3531
- table: "fulfillments",
3532
- document_id: offline_id,
3533
- stall_offline_id: offline_id,
3534
- data: local_fulfillment
3535
- });
3536
- return local_fulfillment;
3537
- } catch (error) {
3538
- throw error;
3539
- }
3540
- };
3541
- var update16 = async (props) => {
3542
- try {
3543
- const { sdk, id, data } = props;
3544
- const existing = await local_db.fulfillments.get(id);
3545
- if (!existing) {
3546
- throw new Error(`Fulfillment with id ${id} not found locally`);
3547
- }
3548
- const now = (/* @__PURE__ */ new Date()).toISOString();
3549
- const updated_fulfillment = {
3550
- ...existing,
3551
- ...data,
3552
- id: existing.id,
3553
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3554
- stall_offline_id: existing.stall_offline_id,
3555
- stall_offline_updated_at: now
3556
- };
3557
- await local_db.fulfillments.put(updated_fulfillment);
3558
- await add_to_sync_queue({
3559
- action: "update",
3560
- table: "fulfillments",
3561
- document_id: id,
3562
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3563
- stall_offline_id: existing.stall_offline_id,
3564
- data: updated_fulfillment
3565
- });
3566
- return updated_fulfillment;
3567
- } catch (error) {
3568
- throw error;
3569
- }
3570
- };
3571
- var _delete16 = async (props) => {
3572
- try {
3573
- const { sdk, id } = props;
3574
- const existing = await local_db.fulfillments.get(id);
3575
- if (!existing) {
3576
- throw new Error(`Fulfillment with id ${id} not found locally`);
3577
- }
3578
- await add_to_sync_queue({
3579
- action: "delete",
3580
- table: "fulfillments",
3581
- document_id: id,
3582
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3583
- stall_offline_id: existing.stall_offline_id,
3584
- data: { id }
3585
- });
3586
- await local_db.fulfillments.delete(id);
3587
- return;
3588
- } catch (error) {
3589
- throw error;
3590
- }
3591
- };
3592
- var bulk_create16 = async (props) => {
3593
- try {
3594
- const { sdk, data } = props;
3595
- const now = (/* @__PURE__ */ new Date()).toISOString();
3596
- const created_fulfillments = [];
3597
- for (const fulfillment of data) {
3598
- const offline_id = generate_offline_id("fulfillment");
3599
- const local_fulfillment = {
3600
- ...fulfillment,
3601
- id: offline_id,
3602
- metadata: {
3603
- ...fulfillment.metadata,
3604
- stall_offline_id: offline_id
3605
- },
3606
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3607
- stall_offline_id: offline_id,
3608
- stall_offline_created_at: now,
3609
- stall_offline_updated_at: now
3610
- };
3611
- await local_db.fulfillments.add(local_fulfillment);
3612
- await add_to_sync_queue({
3613
- action: "create",
3614
- table: "fulfillments",
3615
- document_id: offline_id,
3616
- stall_offline_id: offline_id,
3617
- data: local_fulfillment
3618
- });
3619
- created_fulfillments.push(local_fulfillment);
3620
- }
3621
- return created_fulfillments;
3622
- } catch (error) {
3623
- throw error;
3624
- }
3625
- };
3626
- var bulk_update16 = async (props) => {
3627
- try {
3628
- const { sdk, data } = props;
3629
- const now = (/* @__PURE__ */ new Date()).toISOString();
3630
- const updated_fulfillments = [];
3631
- for (const item of data) {
3632
- const existing = await local_db.fulfillments.get(item.id);
3633
- if (!existing) {
3634
- console.warn(
3635
- `Fulfillment with id ${item.id} not found locally, skipping`
3636
- );
3637
- continue;
3638
- }
3639
- const updated_fulfillment = {
3640
- ...existing,
3641
- ...item.data,
3642
- id: existing.id,
3643
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3644
- stall_offline_id: existing.stall_offline_id,
3645
- stall_offline_updated_at: now
3646
- };
3647
- await local_db.fulfillments.put(updated_fulfillment);
3648
- await add_to_sync_queue({
3649
- action: "update",
3650
- table: "fulfillments",
3651
- document_id: item.id,
3652
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3653
- stall_offline_id: existing.stall_offline_id,
3654
- data: updated_fulfillment
3655
- });
3656
- updated_fulfillments.push(updated_fulfillment);
3657
- }
3658
- return updated_fulfillments;
3659
- } catch (error) {
3660
- throw error;
3661
- }
3662
- };
3663
- var bulk_delete16 = async (props) => {
3664
- try {
3665
- const { sdk, ids } = props;
3666
- for (const id of ids) {
3667
- const existing = await local_db.fulfillments.get(id);
3981
+ const existing = await local_db.locations.get(id);
3668
3982
  if (!existing) {
3669
- console.warn(`Fulfillment with id ${id} not found locally, skipping`);
3983
+ console.warn(`Location with id ${id} not found locally, skipping`);
3670
3984
  continue;
3671
3985
  }
3672
3986
  await add_to_sync_queue({
3673
3987
  action: "delete",
3674
- table: "fulfillments",
3988
+ table: "locations",
3675
3989
  document_id: id,
3676
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3677
- stall_offline_id: existing.stall_offline_id,
3990
+ stall_offline_id: existing.metadata?.stall_offline_id || id,
3678
3991
  data: { id }
3679
3992
  });
3680
- await local_db.fulfillments.delete(id);
3993
+ await local_db.locations.delete(id);
3681
3994
  }
3682
3995
  return;
3683
3996
  } catch (error) {
3684
3997
  throw error;
3685
3998
  }
3686
3999
  };
3687
- var fulfillments = {
3688
- list: list16,
3689
- retrieve: retrieve16,
3690
- create: create16,
3691
- update: update16,
3692
- delete: _delete16,
3693
- bulk_create: bulk_create16,
3694
- bulk_update: bulk_update16,
3695
- bulk_delete: bulk_delete16
3696
- };
3697
-
3698
- // src/services/sync/sync-dependencies.ts
3699
- var SYNC_DEPENDENCY_LAYERS = {
3700
- 1: [
3701
- "tax_regions",
3702
- "tax_rates",
3703
- "categories",
3704
- "collections",
3705
- "locations",
3706
- "payment_providers",
3707
- "customers",
3708
- "promotions"
3709
- ],
3710
- 2: ["products"],
3711
- 3: ["variants", "inventory_levels"],
3712
- 4: ["orders", "order_notes"],
3713
- 5: ["payments", "refunds", "fulfillments"]
3714
- };
3715
- var get_entity_dependencies = (table) => {
3716
- const dependencies = {
3717
- // Layer 1: Independent
3718
- tax_regions: [],
3719
- tax_rates: ["tax_regions"],
3720
- categories: [],
3721
- collections: [],
3722
- locations: [],
3723
- payment_providers: [],
3724
- customers: [],
3725
- promotions: [],
3726
- // Layer 2: Product
3727
- products: ["categories", "collections"],
3728
- // Layer 3: Variants & Inventory
3729
- variants: ["products"],
3730
- inventory_levels: ["products", "variants"],
3731
- inventory_history: ["products", "variants"],
3732
- // Layer 4: Orders
3733
- orders: ["customers", "products", "variants", "locations"],
3734
- order_notes: ["orders"],
3735
- // Layer 5: Order-related
3736
- payments: ["orders", "payment_providers"],
3737
- refunds: ["orders", "payments"],
3738
- fulfillments: ["orders"],
3739
- // Tags
3740
- tags: ["products"],
3741
- // Fulfillment config
3742
- fulfillment_types: [],
3743
- fulfillment_providers: []
3744
- };
3745
- return dependencies[table] || [];
3746
- };
3747
- var get_sync_layer = (table) => {
3748
- for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
3749
- if (tables.includes(table)) {
3750
- return parseInt(layer);
3751
- }
3752
- }
3753
- return 99;
3754
- };
3755
- var sort_by_dependency_order = (items) => {
3756
- return items.sort((a, b) => {
3757
- const layer_a = get_sync_layer(a.table);
3758
- const layer_b = get_sync_layer(b.table);
3759
- if (layer_a !== layer_b) {
3760
- return layer_a - layer_b;
3761
- }
3762
- return 0;
3763
- });
3764
- };
3765
- var are_dependencies_satisfied = (table, synced_tables) => {
3766
- const dependencies = get_entity_dependencies(table);
3767
- return dependencies.every((dep) => synced_tables.has(dep));
4000
+ var locations = {
4001
+ list: list15,
4002
+ retrieve: retrieve15,
4003
+ create: create15,
4004
+ update: update15,
4005
+ delete: _delete15,
4006
+ bulk_create: bulk_create15,
4007
+ bulk_update: bulk_update15,
4008
+ bulk_delete: bulk_delete15
3768
4009
  };
3769
4010
 
3770
- // src/services/sync/sync.service.ts
3771
- var MAX_RETRIES = 3;
3772
- var replace_temporary_ids = async (props) => {
3773
- const { table, stall_offline_id, connector_id, local_data } = props;
4011
+ // src/services/fulfillments.service.ts
4012
+ var list16 = async (props) => {
3774
4013
  try {
3775
- const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
3776
- if (existing) {
3777
- await local_db[table].update(existing.id, {
3778
- id: connector_id
3779
- // Keep stall_offline_id for reference
3780
- });
3781
- }
3782
- await update_dependent_references({
3783
- table,
3784
- old_id: stall_offline_id,
3785
- new_id: connector_id
4014
+ const { sdk, query } = props;
4015
+ const adapter = await sdk.adapter();
4016
+ if (!adapter) throw new Error("Adapter not found");
4017
+ const fulfillments2 = await adapter.fulfillments.list({
4018
+ connector_config: sdk.options.configuration,
4019
+ query
4020
+ });
4021
+ await save_bulk_data({
4022
+ table: "fulfillments",
4023
+ data: fulfillments2
3786
4024
  });
4025
+ return fulfillments2;
3787
4026
  } catch (error) {
3788
- console.error(`Error replacing temporary IDs for ${table}:`, error);
3789
4027
  throw error;
3790
4028
  }
3791
4029
  };
3792
- var update_dependent_references = async (props) => {
3793
- const { table, old_id, new_id } = props;
3794
- try {
3795
- const reference_map = {
3796
- products: [
3797
- { table: "variants", field: "product_id" },
3798
- { table: "inventory_levels", field: "product_id" }
3799
- ],
3800
- variants: [{ table: "inventory_levels", field: "variant_id" }],
3801
- customers: [{ table: "orders", field: "customer_id" }],
3802
- orders: [
3803
- { table: "payments", field: "order_id" },
3804
- { table: "refunds", field: "order_id" },
3805
- { table: "order_notes", field: "order_id" },
3806
- { table: "fulfillments", field: "order_id" }
3807
- ],
3808
- payments: [{ table: "refunds", field: "payment_id" }],
3809
- locations: [{ table: "orders", field: "location_id" }],
3810
- categories: [{ table: "products", field: "category_id" }],
3811
- collections: [{ table: "products", field: "collection_id" }],
3812
- tax_regions: [{ table: "tax_rates", field: "region_id" }],
3813
- tax_rates: [],
3814
- tags: [],
3815
- inventory_levels: [],
3816
- inventory_history: [],
3817
- promotions: [],
3818
- order_notes: [],
3819
- refunds: [],
3820
- payment_providers: [],
3821
- fulfillments: [],
3822
- fulfillment_types: [],
3823
- fulfillment_providers: []
3824
- };
3825
- const references = reference_map[table] || [];
3826
- for (const ref of references) {
3827
- const records = await local_db[ref.table].toArray();
3828
- const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
3829
- ...record,
3830
- [ref.field]: new_id
3831
- }));
3832
- if (updates.length > 0) {
3833
- await local_db[ref.table].bulkPut(updates);
3834
- }
3835
- }
3836
- } catch (error) {
3837
- console.error(`Error updating dependent references for ${table}:`, error);
3838
- }
3839
- };
3840
- var sync_queue_item = async (props) => {
3841
- const { sdk, item, sync_batch_id } = props;
3842
- const start_time = Date.now();
4030
+ var retrieve16 = async (props) => {
3843
4031
  try {
4032
+ const { sdk, id } = props;
3844
4033
  const adapter = await sdk.adapter();
3845
- if (!adapter) {
3846
- throw new Error("Adapter not found");
3847
- }
3848
- const connector_config = sdk.options.configuration;
3849
- const table_module = adapter[item.table];
3850
- if (!table_module) {
3851
- throw new Error(`Module ${item.table} not found in adapter`);
3852
- }
3853
- let connector_id;
3854
- if (item.action === "create") {
3855
- const result = await table_module.create({
3856
- connector_config,
3857
- data: item.data
3858
- });
3859
- connector_id = result?.id;
3860
- if (connector_id) {
3861
- await replace_temporary_ids({
3862
- table: item.table,
3863
- stall_offline_id: item.stall_offline_id,
3864
- connector_id,
3865
- local_data: result
3866
- });
3867
- }
3868
- } else if (item.action === "update") {
3869
- const result = await table_module.update({
3870
- connector_config,
3871
- id: item.document_id,
3872
- data: item.data
3873
- });
3874
- connector_id = result?.id || item.document_id;
3875
- } else if (item.action === "delete") {
3876
- await table_module.delete({
3877
- connector_config,
3878
- id: item.document_id
3879
- });
3880
- connector_id = item.document_id;
3881
- }
3882
- const duration = Date.now() - start_time;
3883
- await add_sync_log({
3884
- sync_batch_id,
3885
- table: item.table,
3886
- action: item.action,
3887
- document_id: item.document_id,
3888
- stall_offline_id: item.stall_offline_id,
3889
- connector_id,
3890
- status: "success",
3891
- duration_ms: duration
3892
- });
3893
- await remove_from_sync_queue(item.id);
3894
- return { success: true, connector_id };
3895
- } catch (error) {
3896
- const duration = Date.now() - start_time;
3897
- console.error(`Error syncing item ${item.id}:`, error);
3898
- const current_retries = item.retry_count || 0;
3899
- if (current_retries < MAX_RETRIES) {
3900
- await update_sync_queue_status({
3901
- id: item.id,
3902
- status: "pending",
3903
- error: error.message,
3904
- retry_count: current_retries + 1
3905
- });
3906
- } else {
3907
- await update_sync_queue_status({
3908
- id: item.id,
3909
- status: "failed",
3910
- error: `Max retries exceeded: ${error.message}`
3911
- });
3912
- }
3913
- await add_sync_log({
3914
- sync_batch_id,
3915
- table: item.table,
3916
- action: item.action,
3917
- document_id: item.document_id,
3918
- stall_offline_id: item.stall_offline_id,
3919
- status: "failed",
3920
- error: error.message,
3921
- duration_ms: duration
4034
+ if (!adapter) throw new Error("Adapter not found");
4035
+ const fulfillment = await adapter.fulfillments.retrieve({
4036
+ connector_config: sdk.options.configuration,
4037
+ id
3922
4038
  });
3923
- return { success: false, error: error.message };
4039
+ await local_db.fulfillments.put(fulfillment);
4040
+ return fulfillment;
4041
+ } catch (error) {
4042
+ throw error;
3924
4043
  }
3925
4044
  };
3926
- var process_sync_queue = async (props) => {
3927
- const { sdk } = props;
3928
- const sync_batch_id = generate_uuid();
4045
+ var create16 = async (props) => {
3929
4046
  try {
3930
- const pending_items_by_table = await get_pending_sync_queue();
3931
- if (pending_items_by_table.size === 0) {
3932
- return {
3933
- sync_batch_id,
3934
- total: 0,
3935
- synced: 0,
3936
- failed: 0,
3937
- summary: []
3938
- };
3939
- }
3940
- let total_synced = 0;
3941
- let total_failed = 0;
3942
- const summary_data = [];
3943
- const all_items = [];
3944
- pending_items_by_table.forEach((items) => {
3945
- items.forEach((item) => {
3946
- all_items.push(item);
3947
- });
3948
- });
3949
- const sorted_items = sort_by_dependency_order(
3950
- all_items
3951
- );
3952
- const synced_tables = /* @__PURE__ */ new Set();
3953
- const items_to_retry = [];
3954
- for (const item of sorted_items) {
3955
- if (!are_dependencies_satisfied(item.table, synced_tables)) {
3956
- items_to_retry.push(item);
3957
- continue;
3958
- }
3959
- await update_sync_queue_status({
3960
- id: item.id,
3961
- status: "syncing"
3962
- });
3963
- const result = await sync_queue_item({
3964
- sdk,
3965
- item,
3966
- sync_batch_id
3967
- });
3968
- if (result.success) {
3969
- total_synced++;
3970
- if (!synced_tables.has(item.table)) {
3971
- synced_tables.add(item.table);
3972
- }
3973
- } else {
3974
- total_failed++;
3975
- }
3976
- const table_summary = summary_data.find((s) => s.table === item.table);
3977
- if (table_summary) {
3978
- if (result.success) {
3979
- table_summary.synced++;
3980
- } else {
3981
- table_summary.failed++;
3982
- }
3983
- } else {
3984
- summary_data.push({
3985
- table: item.table,
3986
- synced: result.success ? 1 : 0,
3987
- failed: result.success ? 0 : 1
3988
- });
4047
+ const { sdk, data } = props;
4048
+ const offline_id = generate_offline_id("fulfillment");
4049
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4050
+ const local_fulfillment = {
4051
+ ...data,
4052
+ id: offline_id,
4053
+ metadata: {
4054
+ ...data.metadata,
4055
+ stall_offline_id: offline_id,
4056
+ stall_offline_created_at: now,
4057
+ stall_offline_updated_at: now,
4058
+ stall_offline_deleted_at: ""
3989
4059
  }
4060
+ };
4061
+ await local_db.fulfillments.add(local_fulfillment);
4062
+ await add_to_sync_queue({
4063
+ action: "create",
4064
+ table: "fulfillments",
4065
+ document_id: offline_id,
4066
+ stall_offline_id: offline_id,
4067
+ data: local_fulfillment
4068
+ });
4069
+ return local_fulfillment;
4070
+ } catch (error) {
4071
+ throw error;
4072
+ }
4073
+ };
4074
+ var update16 = async (props) => {
4075
+ try {
4076
+ const { sdk, id, data } = props;
4077
+ const existing = await local_db.fulfillments.get(id);
4078
+ if (!existing) {
4079
+ throw new Error(`Fulfillment with id ${id} not found locally`);
3990
4080
  }
3991
- for (const item of items_to_retry) {
3992
- await update_sync_queue_status({
3993
- id: item.id,
3994
- status: "syncing"
3995
- });
3996
- const result = await sync_queue_item({
3997
- sdk,
3998
- item,
3999
- sync_batch_id
4000
- });
4001
- if (result.success) {
4002
- total_synced++;
4003
- } else {
4004
- total_failed++;
4005
- }
4006
- const table_summary = summary_data.find((s) => s.table === item.table);
4007
- if (table_summary) {
4008
- if (result.success) {
4009
- table_summary.synced++;
4010
- } else {
4011
- table_summary.failed++;
4012
- }
4081
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4082
+ const updated_fulfillment = {
4083
+ ...existing,
4084
+ ...data,
4085
+ id: existing.id,
4086
+ metadata: {
4087
+ ...existing.metadata,
4088
+ ...data.metadata,
4089
+ stall_offline_id: existing.metadata.stall_offline_id,
4090
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4091
+ stall_offline_updated_at: now,
4092
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4013
4093
  }
4014
- }
4015
- return {
4016
- sync_batch_id,
4017
- total: all_items.length,
4018
- synced: total_synced,
4019
- failed: total_failed,
4020
- summary: summary_data
4021
4094
  };
4095
+ await local_db.fulfillments.put(updated_fulfillment);
4096
+ await add_to_sync_queue({
4097
+ action: "update",
4098
+ table: "fulfillments",
4099
+ document_id: id,
4100
+ stall_offline_id: existing.metadata.stall_offline_id,
4101
+ data: updated_fulfillment
4102
+ });
4103
+ return updated_fulfillment;
4022
4104
  } catch (error) {
4023
- console.error("Error processing sync queue:", error);
4024
- return {
4025
- sync_batch_id,
4026
- total: 0,
4027
- synced: 0,
4028
- failed: 0,
4029
- summary: []
4030
- };
4105
+ throw error;
4031
4106
  }
4032
4107
  };
4033
- var sync_interval = null;
4034
- var start_sync_service = async (props) => {
4035
- const { sdk, interval = 3e4 } = props;
4036
- if (sync_interval) {
4037
- console.warn("Sync service already running");
4108
+ var _delete16 = async (props) => {
4109
+ try {
4110
+ const { sdk, id } = props;
4111
+ const existing = await local_db.fulfillments.get(id);
4112
+ if (!existing) {
4113
+ throw new Error(`Fulfillment with id ${id} not found locally`);
4114
+ }
4115
+ await add_to_sync_queue({
4116
+ action: "delete",
4117
+ table: "fulfillments",
4118
+ document_id: id,
4119
+ stall_offline_id: existing.metadata.stall_offline_id,
4120
+ data: { id }
4121
+ });
4122
+ await local_db.fulfillments.delete(id);
4038
4123
  return;
4124
+ } catch (error) {
4125
+ throw error;
4039
4126
  }
4040
- console.log(`Starting offline sync service with ${interval}ms interval`);
4041
- await process_sync_queue({ sdk });
4042
- sync_interval = setInterval(async () => {
4043
- const result = await process_sync_queue({ sdk });
4044
- if (result.total > 0) {
4045
- console.log(
4046
- `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
4047
- );
4048
- result.summary.forEach((s) => {
4049
- console.log(` ${s.table}: ${s.synced} synced, ${s.failed} failed`);
4127
+ };
4128
+ var bulk_create16 = async (props) => {
4129
+ try {
4130
+ const { sdk, data } = props;
4131
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4132
+ const created_fulfillments = [];
4133
+ for (const fulfillment of data) {
4134
+ const offline_id = generate_offline_id("fulfillment");
4135
+ const local_fulfillment = {
4136
+ ...fulfillment,
4137
+ id: offline_id,
4138
+ metadata: {
4139
+ ...fulfillment.metadata,
4140
+ stall_offline_id: offline_id,
4141
+ stall_offline_created_at: now,
4142
+ stall_offline_updated_at: now,
4143
+ stall_offline_deleted_at: ""
4144
+ }
4145
+ };
4146
+ await local_db.fulfillments.add(local_fulfillment);
4147
+ await add_to_sync_queue({
4148
+ action: "create",
4149
+ table: "fulfillments",
4150
+ document_id: offline_id,
4151
+ stall_offline_id: offline_id,
4152
+ data: local_fulfillment
4050
4153
  });
4154
+ created_fulfillments.push(local_fulfillment);
4051
4155
  }
4052
- }, interval);
4053
- };
4054
- var stop_sync_service = () => {
4055
- if (sync_interval) {
4056
- clearInterval(sync_interval);
4057
- sync_interval = null;
4058
- console.log("Offline sync service stopped");
4156
+ return created_fulfillments;
4157
+ } catch (error) {
4158
+ throw error;
4059
4159
  }
4060
4160
  };
4061
- var get_sync_stats = async () => {
4161
+ var bulk_update16 = async (props) => {
4062
4162
  try {
4063
- const all_items = await local_db.sync_queue.toArray();
4064
- const pending = all_items.filter((i) => i.status === "pending").length;
4065
- const syncing = all_items.filter((i) => i.status === "syncing").length;
4066
- const failed = all_items.filter((i) => i.status === "failed").length;
4067
- return {
4068
- pending,
4069
- syncing,
4070
- failed,
4071
- total: all_items.length
4072
- };
4163
+ const { sdk, data } = props;
4164
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4165
+ const updated_fulfillments = [];
4166
+ for (const item of data) {
4167
+ const existing = await local_db.fulfillments.get(item.id);
4168
+ if (!existing) {
4169
+ console.warn(
4170
+ `Fulfillment with id ${item.id} not found locally, skipping`
4171
+ );
4172
+ continue;
4173
+ }
4174
+ const updated_fulfillment = {
4175
+ ...existing,
4176
+ ...item.data,
4177
+ id: existing.id,
4178
+ metadata: {
4179
+ ...existing.metadata,
4180
+ ...item.data.metadata,
4181
+ stall_offline_id: existing.metadata.stall_offline_id,
4182
+ stall_offline_created_at: existing.metadata.stall_offline_created_at,
4183
+ stall_offline_updated_at: now,
4184
+ stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
4185
+ }
4186
+ };
4187
+ await local_db.fulfillments.put(updated_fulfillment);
4188
+ await add_to_sync_queue({
4189
+ action: "update",
4190
+ table: "fulfillments",
4191
+ document_id: item.id,
4192
+ stall_offline_id: existing.metadata.stall_offline_id,
4193
+ data: updated_fulfillment
4194
+ });
4195
+ updated_fulfillments.push(updated_fulfillment);
4196
+ }
4197
+ return updated_fulfillments;
4073
4198
  } catch (error) {
4074
- console.error("Error getting sync stats:", error);
4075
- return { pending: 0, syncing: 0, failed: 0, total: 0 };
4199
+ throw error;
4076
4200
  }
4077
4201
  };
4078
- var trigger_sync = async (props) => {
4202
+ var bulk_delete16 = async (props) => {
4079
4203
  try {
4080
- const { sdk } = props;
4081
- return await process_sync_queue({ sdk });
4204
+ const { sdk, ids } = props;
4205
+ for (const id of ids) {
4206
+ const existing = await local_db.fulfillments.get(id);
4207
+ if (!existing) {
4208
+ console.warn(`Fulfillment with id ${id} not found locally, skipping`);
4209
+ continue;
4210
+ }
4211
+ await add_to_sync_queue({
4212
+ action: "delete",
4213
+ table: "fulfillments",
4214
+ document_id: id,
4215
+ stall_offline_id: existing.metadata.stall_offline_id,
4216
+ data: { id }
4217
+ });
4218
+ await local_db.fulfillments.delete(id);
4219
+ }
4220
+ return;
4082
4221
  } catch (error) {
4083
- console.error("Error triggering sync:", error);
4084
- return {
4085
- sync_batch_id: generate_uuid(),
4086
- total: 0,
4087
- synced: 0,
4088
- failed: 0,
4089
- summary: []
4090
- };
4222
+ throw error;
4091
4223
  }
4092
4224
  };
4093
- var sync_service = {
4094
- process_sync_queue,
4095
- sync_queue_item,
4096
- start_sync_service,
4097
- stop_sync_service,
4098
- get_sync_stats,
4099
- trigger_sync
4225
+ var fulfillments = {
4226
+ list: list16,
4227
+ retrieve: retrieve16,
4228
+ create: create16,
4229
+ update: update16,
4230
+ delete: _delete16,
4231
+ bulk_create: bulk_create16,
4232
+ bulk_update: bulk_update16,
4233
+ bulk_delete: bulk_delete16
4100
4234
  };
4101
4235
  export {
4102
4236
  add_sync_log,
@@ -4112,6 +4246,8 @@ export {
4112
4246
  get_sync_logs_by_batch,
4113
4247
  initializeStallCore,
4114
4248
  inventory_levels,
4249
+ is_offline,
4250
+ is_online,
4115
4251
  local_db,
4116
4252
  locations,
4117
4253
  order_notes,