@use-stall/core 0.0.4 → 0.0.6

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,6 +4,8 @@ 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",
8
+ sync_logs: "++id, sync_batch_id, timestamp",
7
9
  products: "++id",
8
10
  variants: "++id",
9
11
  collections: "++id",
@@ -67,6 +69,101 @@ var getAdapter = async (sdk, force) => {
67
69
  return module;
68
70
  };
69
71
 
72
+ // src/db/helpers.ts
73
+ import { randomUUID } from "crypto";
74
+ var uuid = () => randomUUID();
75
+ var generate_offline_id = (table) => {
76
+ return `stall_${table}_${uuid()}_${Date.now()}`;
77
+ };
78
+ var save_bulk_data = async (props) => {
79
+ await local_db.transaction("rw", props.table, async () => {
80
+ await local_db?.[props.table].clear();
81
+ await local_db?.[props.table].bulkAdd(
82
+ props.data || []
83
+ );
84
+ });
85
+ };
86
+ var add_to_sync_queue = async (props) => {
87
+ const queue_item = {
88
+ id: uuid(),
89
+ action: props.action,
90
+ table: props.table,
91
+ document_id: props.document_id,
92
+ stall_offline_id: props.stall_offline_id,
93
+ data: props.data,
94
+ timestamp: Date.now(),
95
+ status: "pending",
96
+ retry_count: 0
97
+ };
98
+ await local_db.sync_queue.add(queue_item);
99
+ return queue_item;
100
+ };
101
+ var get_pending_sync_queue = async () => {
102
+ const pending_items = await local_db.sync_queue.where("status").equals("pending").toArray();
103
+ const grouped = /* @__PURE__ */ new Map();
104
+ pending_items.forEach((item) => {
105
+ if (!grouped.has(item.table)) {
106
+ grouped.set(item.table, []);
107
+ }
108
+ grouped.get(item.table).push(item);
109
+ });
110
+ return grouped;
111
+ };
112
+ var update_sync_queue_status = async (props) => {
113
+ const updates = {
114
+ status: props.status
115
+ };
116
+ if (props.error) {
117
+ updates.error = props.error;
118
+ }
119
+ if (props.retry_count !== void 0) {
120
+ updates.retry_count = props.retry_count;
121
+ updates.last_retry_at = Date.now();
122
+ }
123
+ await local_db.sync_queue.update(props.id, updates);
124
+ };
125
+ var remove_from_sync_queue = async (id) => {
126
+ await local_db.sync_queue.delete(id);
127
+ };
128
+ var add_sync_log = async (props) => {
129
+ const log = {
130
+ id: uuid(),
131
+ sync_batch_id: props.sync_batch_id,
132
+ table: props.table,
133
+ action: props.action,
134
+ document_id: props.document_id,
135
+ stall_offline_id: props.stall_offline_id,
136
+ connector_id: props.connector_id,
137
+ status: props.status,
138
+ error: props.error,
139
+ timestamp: Date.now(),
140
+ duration_ms: props.duration_ms
141
+ };
142
+ await local_db.sync_logs.add(log);
143
+ return log;
144
+ };
145
+ var get_sync_logs_by_batch = async (sync_batch_id) => {
146
+ return await local_db.sync_logs.where("sync_batch_id").equals(sync_batch_id).toArray();
147
+ };
148
+ var get_recent_sync_logs = async (props) => {
149
+ let query = local_db.sync_logs.orderBy("timestamp").reverse();
150
+ if (props?.table) {
151
+ query = query.filter((log) => log.table === props.table);
152
+ }
153
+ if (props?.status) {
154
+ query = query.filter((log) => log.status === props.status);
155
+ }
156
+ const logs = await query.toArray();
157
+ if (props?.limit) {
158
+ return logs.slice(0, props.limit);
159
+ }
160
+ return logs;
161
+ };
162
+ var cleanup_old_sync_logs = async (days = 30) => {
163
+ const cutoff_time = Date.now() - days * 24 * 60 * 60 * 1e3;
164
+ await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
165
+ };
166
+
70
167
  // src/services/products.service.ts
71
168
  var list = async (props) => {
72
169
  try {
@@ -77,6 +174,10 @@ var list = async (props) => {
77
174
  connector_config: sdk.options.configuration,
78
175
  query
79
176
  });
177
+ await save_bulk_data({
178
+ table: "products",
179
+ data: products2
180
+ });
80
181
  return products2;
81
182
  } catch (error) {
82
183
  throw error;
@@ -91,6 +192,7 @@ var retrieve = async (props) => {
91
192
  connector_config: sdk.options.configuration,
92
193
  id
93
194
  });
195
+ await local_db.products.put(product);
94
196
  return product;
95
197
  } catch (error) {
96
198
  throw error;
@@ -99,13 +201,28 @@ var retrieve = async (props) => {
99
201
  var create = async (props) => {
100
202
  try {
101
203
  const { sdk, data } = props;
102
- const adapter = await sdk.adapter();
103
- if (!adapter) throw new Error("Adapter not found");
104
- const product = await adapter.products.create({
105
- connector_config: sdk.options.configuration,
106
- data
107
- });
108
- return product;
204
+ const offline_id = generate_offline_id("product");
205
+ const now = (/* @__PURE__ */ new Date()).toISOString();
206
+ const local_product = {
207
+ ...data,
208
+ id: offline_id,
209
+ metadata: {
210
+ ...data.metadata,
211
+ stall_offline_id: offline_id
212
+ },
213
+ stall_offline_id: offline_id,
214
+ stall_offline_created_at: now,
215
+ stall_offline_updated_at: now
216
+ };
217
+ await local_db.products.add(local_product);
218
+ await add_to_sync_queue({
219
+ action: "create",
220
+ table: "products",
221
+ document_id: offline_id,
222
+ stall_offline_id: offline_id,
223
+ data: local_product
224
+ });
225
+ return local_product;
109
226
  } catch (error) {
110
227
  throw error;
111
228
  }
@@ -113,14 +230,29 @@ var create = async (props) => {
113
230
  var update = async (props) => {
114
231
  try {
115
232
  const { sdk, id, data } = props;
116
- const adapter = await sdk.adapter();
117
- if (!adapter) throw new Error("Adapter not found");
118
- const product = await adapter.products.update({
119
- connector_config: sdk.options.configuration,
120
- id,
121
- data
122
- });
123
- return product;
233
+ const existing = await local_db.products.get(id);
234
+ if (!existing) {
235
+ throw new Error(`Product with id ${id} not found locally`);
236
+ }
237
+ const now = (/* @__PURE__ */ new Date()).toISOString();
238
+ const updated_product = {
239
+ ...existing,
240
+ ...data,
241
+ id: existing.id,
242
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
243
+ stall_offline_id: existing.stall_offline_id,
244
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
245
+ stall_offline_updated_at: now
246
+ };
247
+ await local_db.products.put(updated_product);
248
+ await add_to_sync_queue({
249
+ action: "update",
250
+ table: "products",
251
+ document_id: id,
252
+ stall_offline_id: existing.stall_offline_id,
253
+ data: updated_product
254
+ });
255
+ return updated_product;
124
256
  } catch (error) {
125
257
  throw error;
126
258
  }
@@ -128,12 +260,19 @@ var update = async (props) => {
128
260
  var _delete = async (props) => {
129
261
  try {
130
262
  const { sdk, id } = props;
131
- const adapter = await sdk.adapter();
132
- if (!adapter) throw new Error("Adapter not found");
133
- await adapter.products.delete({
134
- connector_config: sdk.options.configuration,
135
- id
136
- });
263
+ const existing = await local_db.products.get(id);
264
+ if (!existing) {
265
+ throw new Error(`Product with id ${id} not found locally`);
266
+ }
267
+ await add_to_sync_queue({
268
+ action: "delete",
269
+ table: "products",
270
+ document_id: id,
271
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
+ stall_offline_id: existing.stall_offline_id,
273
+ data: { id }
274
+ });
275
+ await local_db.products.delete(id);
137
276
  return;
138
277
  } catch (error) {
139
278
  throw error;
@@ -142,13 +281,32 @@ var _delete = async (props) => {
142
281
  var bulk_create = async (props) => {
143
282
  try {
144
283
  const { sdk, data } = props;
145
- const adapter = await sdk.adapter();
146
- if (!adapter) throw new Error("Adapter not found");
147
- const products2 = await adapter.products.bulk_create({
148
- connector_config: sdk.options.configuration,
149
- data
150
- });
151
- return products2;
284
+ const now = (/* @__PURE__ */ new Date()).toISOString();
285
+ const created_products = [];
286
+ for (const product of data) {
287
+ const offline_id = generate_offline_id("product");
288
+ const local_product = {
289
+ ...product,
290
+ id: offline_id,
291
+ metadata: {
292
+ ...product.metadata,
293
+ stall_offline_id: offline_id
294
+ },
295
+ stall_offline_id: offline_id,
296
+ stall_offline_created_at: now,
297
+ stall_offline_updated_at: now
298
+ };
299
+ await local_db.products.add(local_product);
300
+ await add_to_sync_queue({
301
+ action: "create",
302
+ table: "products",
303
+ document_id: offline_id,
304
+ stall_offline_id: offline_id,
305
+ data: local_product
306
+ });
307
+ created_products.push(local_product);
308
+ }
309
+ return created_products;
152
310
  } catch (error) {
153
311
  throw error;
154
312
  }
@@ -156,13 +314,34 @@ var bulk_create = async (props) => {
156
314
  var bulk_update = async (props) => {
157
315
  try {
158
316
  const { sdk, data } = props;
159
- const adapter = await sdk.adapter();
160
- if (!adapter) throw new Error("Adapter not found");
161
- const products2 = await adapter.products.bulk_update({
162
- connector_config: sdk.options.configuration,
163
- data
164
- });
165
- return products2;
317
+ const now = (/* @__PURE__ */ new Date()).toISOString();
318
+ const updated_products = [];
319
+ for (const item of data) {
320
+ const existing = await local_db.products.get(item.id);
321
+ if (!existing) {
322
+ console.warn(`Product with id ${item.id} not found locally, skipping`);
323
+ continue;
324
+ }
325
+ const updated_product = {
326
+ ...existing,
327
+ ...item.data,
328
+ id: existing.id,
329
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
330
+ stall_offline_id: existing.stall_offline_id,
331
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
332
+ stall_offline_updated_at: now
333
+ };
334
+ await local_db.products.put(updated_product);
335
+ await add_to_sync_queue({
336
+ action: "update",
337
+ table: "products",
338
+ document_id: item.id,
339
+ stall_offline_id: existing.stall_offline_id,
340
+ data: updated_product
341
+ });
342
+ updated_products.push(updated_product);
343
+ }
344
+ return updated_products;
166
345
  } catch (error) {
167
346
  throw error;
168
347
  }
@@ -170,12 +349,22 @@ var bulk_update = async (props) => {
170
349
  var bulk_delete = async (props) => {
171
350
  try {
172
351
  const { sdk, ids } = props;
173
- const adapter = await sdk.adapter();
174
- if (!adapter) throw new Error("Adapter not found");
175
- await adapter.products.bulk_delete({
176
- connector_config: sdk.options.configuration,
177
- ids
178
- });
352
+ for (const id of ids) {
353
+ const existing = await local_db.products.get(id);
354
+ if (!existing) {
355
+ console.warn(`Product with id ${id} not found locally, skipping`);
356
+ continue;
357
+ }
358
+ await add_to_sync_queue({
359
+ action: "delete",
360
+ table: "products",
361
+ document_id: id,
362
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
363
+ stall_offline_id: existing.stall_offline_id,
364
+ data: { id }
365
+ });
366
+ await local_db.products.delete(id);
367
+ }
179
368
  return;
180
369
  } catch (error) {
181
370
  throw error;
@@ -202,6 +391,10 @@ var list2 = async (props) => {
202
391
  connector_config: sdk.options.configuration,
203
392
  query
204
393
  });
394
+ await save_bulk_data({
395
+ table: "orders",
396
+ data: orders2
397
+ });
205
398
  return orders2;
206
399
  } catch (error) {
207
400
  throw new Error(
@@ -218,6 +411,7 @@ var retrieve2 = async (props) => {
218
411
  connector_config: sdk.options.configuration,
219
412
  id
220
413
  });
414
+ await local_db.orders.put(order);
221
415
  return order;
222
416
  } catch (error) {
223
417
  throw new Error(
@@ -228,13 +422,28 @@ var retrieve2 = async (props) => {
228
422
  var create2 = async (props) => {
229
423
  try {
230
424
  const { sdk, data } = props;
231
- const adapter = await sdk.adapter();
232
- if (!adapter) throw new Error("Adapter not found");
233
- const order = await adapter.orders.create({
234
- connector_config: sdk.options.configuration,
235
- data
236
- });
237
- return order;
425
+ const offline_id = generate_offline_id("order");
426
+ const now = (/* @__PURE__ */ new Date()).toISOString();
427
+ const local_order = {
428
+ ...data,
429
+ id: offline_id,
430
+ metadata: {
431
+ ...data.metadata,
432
+ stall_offline_id: offline_id
433
+ },
434
+ stall_offline_id: offline_id,
435
+ stall_offline_created_at: now,
436
+ stall_offline_updated_at: now
437
+ };
438
+ await local_db.orders.add(local_order);
439
+ await add_to_sync_queue({
440
+ action: "create",
441
+ table: "orders",
442
+ document_id: offline_id,
443
+ stall_offline_id: offline_id,
444
+ data: local_order
445
+ });
446
+ return local_order;
238
447
  } catch (error) {
239
448
  throw new Error(
240
449
  `Failed to create order: ${error instanceof Error ? error.message : String(error)}`
@@ -244,14 +453,29 @@ var create2 = async (props) => {
244
453
  var update2 = async (props) => {
245
454
  try {
246
455
  const { sdk, id, data } = props;
247
- const adapter = await sdk.adapter();
248
- if (!adapter) throw new Error("Adapter not found");
249
- const order = await adapter.orders.update({
250
- connector_config: sdk.options.configuration,
251
- id,
252
- data
253
- });
254
- return order;
456
+ const existing = await local_db.orders.get(id);
457
+ if (!existing) {
458
+ throw new Error(`Order with id ${id} not found locally`);
459
+ }
460
+ const now = (/* @__PURE__ */ new Date()).toISOString();
461
+ const updated_order = {
462
+ ...existing,
463
+ ...data,
464
+ id: existing.id,
465
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
466
+ stall_offline_id: existing.stall_offline_id,
467
+ stall_offline_updated_at: now
468
+ };
469
+ await local_db.orders.put(updated_order);
470
+ await add_to_sync_queue({
471
+ action: "update",
472
+ table: "orders",
473
+ document_id: id,
474
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
475
+ stall_offline_id: existing.stall_offline_id,
476
+ data: updated_order
477
+ });
478
+ return updated_order;
255
479
  } catch (error) {
256
480
  throw new Error(
257
481
  `Failed to update order: ${error instanceof Error ? error.message : String(error)}`
@@ -261,12 +485,19 @@ var update2 = async (props) => {
261
485
  var _delete2 = async (props) => {
262
486
  try {
263
487
  const { sdk, id } = props;
264
- const adapter = await sdk.adapter();
265
- if (!adapter) throw new Error("Adapter not found");
266
- await adapter.orders.delete({
267
- connector_config: sdk.options.configuration,
268
- id
269
- });
488
+ const existing = await local_db.orders.get(id);
489
+ if (!existing) {
490
+ throw new Error(`Order with id ${id} not found locally`);
491
+ }
492
+ await add_to_sync_queue({
493
+ action: "delete",
494
+ table: "orders",
495
+ document_id: id,
496
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
497
+ stall_offline_id: existing.stall_offline_id,
498
+ data: { id }
499
+ });
500
+ await local_db.orders.delete(id);
270
501
  return;
271
502
  } catch (error) {
272
503
  throw new Error(
@@ -277,13 +508,32 @@ var _delete2 = async (props) => {
277
508
  var bulk_create2 = async (props) => {
278
509
  try {
279
510
  const { sdk, data } = props;
280
- const adapter = await sdk.adapter();
281
- if (!adapter) throw new Error("Adapter not found");
282
- const orders2 = await adapter.orders.bulk_create({
283
- connector_config: sdk.options.configuration,
284
- data
285
- });
286
- return orders2;
511
+ const now = (/* @__PURE__ */ new Date()).toISOString();
512
+ const created_orders = [];
513
+ for (const order of data) {
514
+ const offline_id = generate_offline_id("order");
515
+ const local_order = {
516
+ ...order,
517
+ id: offline_id,
518
+ metadata: {
519
+ ...order.metadata,
520
+ stall_offline_id: offline_id
521
+ },
522
+ stall_offline_id: offline_id,
523
+ stall_offline_created_at: now,
524
+ stall_offline_updated_at: now
525
+ };
526
+ await local_db.orders.add(local_order);
527
+ await add_to_sync_queue({
528
+ action: "create",
529
+ table: "orders",
530
+ document_id: offline_id,
531
+ stall_offline_id: offline_id,
532
+ data: local_order
533
+ });
534
+ created_orders.push(local_order);
535
+ }
536
+ return created_orders;
287
537
  } catch (error) {
288
538
  throw new Error(
289
539
  `Failed to bulk create orders: ${error instanceof Error ? error.message : String(error)}`
@@ -293,13 +543,34 @@ var bulk_create2 = async (props) => {
293
543
  var bulk_update2 = async (props) => {
294
544
  try {
295
545
  const { sdk, data } = props;
296
- const adapter = await sdk.adapter();
297
- if (!adapter) throw new Error("Adapter not found");
298
- const orders2 = await adapter.orders.bulk_update({
299
- connector_config: sdk.options.configuration,
300
- data
301
- });
302
- return orders2;
546
+ const now = (/* @__PURE__ */ new Date()).toISOString();
547
+ const updated_orders = [];
548
+ for (const item of data) {
549
+ const existing = await local_db.orders.get(item.id);
550
+ if (!existing) {
551
+ console.warn(`Order with id ${item.id} not found locally, skipping`);
552
+ continue;
553
+ }
554
+ const updated_order = {
555
+ ...existing,
556
+ ...item.data,
557
+ id: existing.id,
558
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
559
+ stall_offline_id: existing.stall_offline_id,
560
+ stall_offline_updated_at: now
561
+ };
562
+ await local_db.orders.put(updated_order);
563
+ await add_to_sync_queue({
564
+ action: "update",
565
+ table: "orders",
566
+ document_id: item.id,
567
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
568
+ stall_offline_id: existing.stall_offline_id,
569
+ data: updated_order
570
+ });
571
+ updated_orders.push(updated_order);
572
+ }
573
+ return updated_orders;
303
574
  } catch (error) {
304
575
  throw new Error(
305
576
  `Failed to bulk update orders: ${error instanceof Error ? error.message : String(error)}`
@@ -309,12 +580,22 @@ var bulk_update2 = async (props) => {
309
580
  var bulk_delete2 = async (props) => {
310
581
  try {
311
582
  const { sdk, ids } = props;
312
- const adapter = await sdk.adapter();
313
- if (!adapter) throw new Error("Adapter not found");
314
- await adapter.orders.bulk_delete({
315
- connector_config: sdk.options.configuration,
316
- ids
317
- });
583
+ for (const id of ids) {
584
+ const existing = await local_db.orders.get(id);
585
+ if (!existing) {
586
+ console.warn(`Order with id ${id} not found locally, skipping`);
587
+ continue;
588
+ }
589
+ await add_to_sync_queue({
590
+ action: "delete",
591
+ table: "orders",
592
+ document_id: id,
593
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
594
+ stall_offline_id: existing.stall_offline_id,
595
+ data: { id }
596
+ });
597
+ await local_db.orders.delete(id);
598
+ }
318
599
  return;
319
600
  } catch (error) {
320
601
  throw new Error(
@@ -343,6 +624,10 @@ var list3 = async (props) => {
343
624
  connector_config: sdk.options.configuration,
344
625
  query
345
626
  });
627
+ await save_bulk_data({
628
+ table: "customers",
629
+ data: customers2
630
+ });
346
631
  return customers2;
347
632
  } catch (error) {
348
633
  throw error;
@@ -357,6 +642,7 @@ var retrieve3 = async (props) => {
357
642
  connector_config: sdk.options.configuration,
358
643
  id
359
644
  });
645
+ await local_db.customers.put(customer);
360
646
  return customer;
361
647
  } catch (error) {
362
648
  throw error;
@@ -365,13 +651,28 @@ var retrieve3 = async (props) => {
365
651
  var create3 = async (props) => {
366
652
  try {
367
653
  const { sdk, data } = props;
368
- const adapter = await sdk.adapter();
369
- if (!adapter) throw new Error("Adapter not found");
370
- const customer = await adapter.customers.create({
371
- connector_config: sdk.options.configuration,
372
- data
373
- });
374
- return customer;
654
+ const offline_id = generate_offline_id("customer");
655
+ const now = (/* @__PURE__ */ new Date()).toISOString();
656
+ const local_customer = {
657
+ ...data,
658
+ id: offline_id,
659
+ metadata: {
660
+ ...data.metadata,
661
+ stall_offline_id: offline_id
662
+ },
663
+ stall_offline_id: offline_id,
664
+ stall_offline_created_at: now,
665
+ stall_offline_updated_at: now
666
+ };
667
+ await local_db.customers.add(local_customer);
668
+ await add_to_sync_queue({
669
+ action: "create",
670
+ table: "customers",
671
+ document_id: offline_id,
672
+ stall_offline_id: offline_id,
673
+ data: local_customer
674
+ });
675
+ return local_customer;
375
676
  } catch (error) {
376
677
  throw error;
377
678
  }
@@ -379,14 +680,29 @@ var create3 = async (props) => {
379
680
  var update3 = async (props) => {
380
681
  try {
381
682
  const { sdk, id, data } = props;
382
- const adapter = await sdk.adapter();
383
- if (!adapter) throw new Error("Adapter not found");
384
- const customer = await adapter.customers.update({
385
- connector_config: sdk.options.configuration,
386
- id,
387
- data
388
- });
389
- return customer;
683
+ const existing = await local_db.customers.get(id);
684
+ if (!existing) {
685
+ throw new Error(`Customer with id ${id} not found locally`);
686
+ }
687
+ const now = (/* @__PURE__ */ new Date()).toISOString();
688
+ const updated_customer = {
689
+ ...existing,
690
+ ...data,
691
+ id: existing.id,
692
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
693
+ stall_offline_id: existing.stall_offline_id,
694
+ stall_offline_updated_at: now
695
+ };
696
+ await local_db.customers.put(updated_customer);
697
+ await add_to_sync_queue({
698
+ action: "update",
699
+ table: "customers",
700
+ document_id: id,
701
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
702
+ stall_offline_id: existing.stall_offline_id,
703
+ data: updated_customer
704
+ });
705
+ return updated_customer;
390
706
  } catch (error) {
391
707
  throw error;
392
708
  }
@@ -394,12 +710,19 @@ var update3 = async (props) => {
394
710
  var _delete3 = async (props) => {
395
711
  try {
396
712
  const { sdk, id } = props;
397
- const adapter = await sdk.adapter();
398
- if (!adapter) throw new Error("Adapter not found");
399
- await adapter.customers.delete({
400
- connector_config: sdk.options.configuration,
401
- id
402
- });
713
+ const existing = await local_db.customers.get(id);
714
+ if (!existing) {
715
+ throw new Error(`Customer with id ${id} not found locally`);
716
+ }
717
+ await add_to_sync_queue({
718
+ action: "delete",
719
+ table: "customers",
720
+ document_id: id,
721
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
722
+ stall_offline_id: existing.stall_offline_id,
723
+ data: { id }
724
+ });
725
+ await local_db.customers.delete(id);
403
726
  return;
404
727
  } catch (error) {
405
728
  throw error;
@@ -408,13 +731,32 @@ var _delete3 = async (props) => {
408
731
  var bulk_create3 = async (props) => {
409
732
  try {
410
733
  const { sdk, data } = props;
411
- const adapter = await sdk.adapter();
412
- if (!adapter) throw new Error("Adapter not found");
413
- const customers2 = await adapter.customers.bulk_create({
414
- connector_config: sdk.options.configuration,
415
- data
416
- });
417
- return customers2;
734
+ const now = (/* @__PURE__ */ new Date()).toISOString();
735
+ const created_customers = [];
736
+ for (const customer of data) {
737
+ const offline_id = generate_offline_id("customer");
738
+ const local_customer = {
739
+ ...customer,
740
+ id: offline_id,
741
+ metadata: {
742
+ ...customer.metadata,
743
+ stall_offline_id: offline_id
744
+ },
745
+ stall_offline_id: offline_id,
746
+ stall_offline_created_at: now,
747
+ stall_offline_updated_at: now
748
+ };
749
+ await local_db.customers.add(local_customer);
750
+ await add_to_sync_queue({
751
+ action: "create",
752
+ table: "customers",
753
+ document_id: offline_id,
754
+ stall_offline_id: offline_id,
755
+ data: local_customer
756
+ });
757
+ created_customers.push(local_customer);
758
+ }
759
+ return created_customers;
418
760
  } catch (error) {
419
761
  throw error;
420
762
  }
@@ -422,13 +764,34 @@ var bulk_create3 = async (props) => {
422
764
  var bulk_update3 = async (props) => {
423
765
  try {
424
766
  const { sdk, data } = props;
425
- const adapter = await sdk.adapter();
426
- if (!adapter) throw new Error("Adapter not found");
427
- const customers2 = await adapter.customers.bulk_update({
428
- connector_config: sdk.options.configuration,
429
- data
430
- });
431
- return customers2;
767
+ const now = (/* @__PURE__ */ new Date()).toISOString();
768
+ const updated_customers = [];
769
+ for (const item of data) {
770
+ const existing = await local_db.customers.get(item.id);
771
+ if (!existing) {
772
+ console.warn(`Customer with id ${item.id} not found locally, skipping`);
773
+ continue;
774
+ }
775
+ const updated_customer = {
776
+ ...existing,
777
+ ...item.data,
778
+ id: existing.id,
779
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
780
+ stall_offline_id: existing.stall_offline_id,
781
+ stall_offline_updated_at: now
782
+ };
783
+ await local_db.customers.put(updated_customer);
784
+ await add_to_sync_queue({
785
+ action: "update",
786
+ table: "customers",
787
+ document_id: item.id,
788
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
789
+ stall_offline_id: existing.stall_offline_id,
790
+ data: updated_customer
791
+ });
792
+ updated_customers.push(updated_customer);
793
+ }
794
+ return updated_customers;
432
795
  } catch (error) {
433
796
  throw error;
434
797
  }
@@ -436,12 +799,22 @@ var bulk_update3 = async (props) => {
436
799
  var bulk_delete3 = async (props) => {
437
800
  try {
438
801
  const { sdk, ids } = props;
439
- const adapter = await sdk.adapter();
440
- if (!adapter) throw new Error("Adapter not found");
441
- await adapter.customers.bulk_delete({
442
- connector_config: sdk.options.configuration,
443
- ids
444
- });
802
+ for (const id of ids) {
803
+ const existing = await local_db.customers.get(id);
804
+ if (!existing) {
805
+ console.warn(`Customer with id ${id} not found locally, skipping`);
806
+ continue;
807
+ }
808
+ await add_to_sync_queue({
809
+ action: "delete",
810
+ table: "customers",
811
+ document_id: id,
812
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
813
+ stall_offline_id: existing.stall_offline_id,
814
+ data: { id }
815
+ });
816
+ await local_db.customers.delete(id);
817
+ }
445
818
  return;
446
819
  } catch (error) {
447
820
  throw error;
@@ -468,6 +841,10 @@ var list4 = async (props) => {
468
841
  connector_config: sdk.options.configuration,
469
842
  query
470
843
  });
844
+ await save_bulk_data({
845
+ table: "collections",
846
+ data: collections2
847
+ });
471
848
  return collections2;
472
849
  } catch (error) {
473
850
  throw error;
@@ -482,6 +859,7 @@ var retrieve4 = async (props) => {
482
859
  connector_config: sdk.options.configuration,
483
860
  id
484
861
  });
862
+ await local_db.collections.put(collection);
485
863
  return collection;
486
864
  } catch (error) {
487
865
  throw error;
@@ -490,13 +868,28 @@ var retrieve4 = async (props) => {
490
868
  var create4 = async (props) => {
491
869
  try {
492
870
  const { sdk, data } = props;
493
- const adapter = await sdk.adapter();
494
- if (!adapter) throw new Error("Adapter not found");
495
- const collection = await adapter.collections.create({
496
- connector_config: sdk.options.configuration,
497
- data
498
- });
499
- return collection;
871
+ const offline_id = generate_offline_id("collection");
872
+ const now = (/* @__PURE__ */ new Date()).toISOString();
873
+ const local_collection = {
874
+ ...data,
875
+ id: offline_id,
876
+ metadata: {
877
+ ...data.metadata,
878
+ stall_offline_id: offline_id
879
+ },
880
+ stall_offline_id: offline_id,
881
+ stall_offline_created_at: now,
882
+ stall_offline_updated_at: now
883
+ };
884
+ await local_db.collections.add(local_collection);
885
+ await add_to_sync_queue({
886
+ action: "create",
887
+ table: "collections",
888
+ document_id: offline_id,
889
+ stall_offline_id: offline_id,
890
+ data: local_collection
891
+ });
892
+ return local_collection;
500
893
  } catch (error) {
501
894
  throw error;
502
895
  }
@@ -504,14 +897,29 @@ var create4 = async (props) => {
504
897
  var update4 = async (props) => {
505
898
  try {
506
899
  const { sdk, id, data } = props;
507
- const adapter = await sdk.adapter();
508
- if (!adapter) throw new Error("Adapter not found");
509
- const collection = await adapter.collections.update({
510
- connector_config: sdk.options.configuration,
511
- id,
512
- data
513
- });
514
- return collection;
900
+ const existing = await local_db.collections.get(id);
901
+ if (!existing) {
902
+ throw new Error(`Collection with id ${id} not found locally`);
903
+ }
904
+ const now = (/* @__PURE__ */ new Date()).toISOString();
905
+ const updated_collection = {
906
+ ...existing,
907
+ ...data,
908
+ id: existing.id,
909
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
910
+ stall_offline_id: existing.stall_offline_id,
911
+ stall_offline_updated_at: now
912
+ };
913
+ await local_db.collections.put(updated_collection);
914
+ await add_to_sync_queue({
915
+ action: "update",
916
+ table: "collections",
917
+ document_id: id,
918
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
919
+ stall_offline_id: existing.stall_offline_id,
920
+ data: updated_collection
921
+ });
922
+ return updated_collection;
515
923
  } catch (error) {
516
924
  throw error;
517
925
  }
@@ -519,12 +927,19 @@ var update4 = async (props) => {
519
927
  var _delete4 = async (props) => {
520
928
  try {
521
929
  const { sdk, id } = props;
522
- const adapter = await sdk.adapter();
523
- if (!adapter) throw new Error("Adapter not found");
524
- await adapter.collections.delete({
525
- connector_config: sdk.options.configuration,
526
- id
527
- });
930
+ const existing = await local_db.collections.get(id);
931
+ if (!existing) {
932
+ throw new Error(`Collection with id ${id} not found locally`);
933
+ }
934
+ await add_to_sync_queue({
935
+ action: "delete",
936
+ table: "collections",
937
+ document_id: id,
938
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
939
+ stall_offline_id: existing.stall_offline_id,
940
+ data: { id }
941
+ });
942
+ await local_db.collections.delete(id);
528
943
  return;
529
944
  } catch (error) {
530
945
  throw error;
@@ -533,13 +948,32 @@ var _delete4 = async (props) => {
533
948
  var bulk_create4 = async (props) => {
534
949
  try {
535
950
  const { sdk, data } = props;
536
- const adapter = await sdk.adapter();
537
- if (!adapter) throw new Error("Adapter not found");
538
- const collections2 = await adapter.collections.bulk_create({
539
- connector_config: sdk.options.configuration,
540
- data
541
- });
542
- return collections2;
951
+ const now = (/* @__PURE__ */ new Date()).toISOString();
952
+ const created_collections = [];
953
+ for (const collection of data) {
954
+ const offline_id = generate_offline_id("collection");
955
+ const local_collection = {
956
+ ...collection,
957
+ id: offline_id,
958
+ metadata: {
959
+ ...collection.metadata,
960
+ stall_offline_id: offline_id
961
+ },
962
+ stall_offline_id: offline_id,
963
+ stall_offline_created_at: now,
964
+ stall_offline_updated_at: now
965
+ };
966
+ await local_db.collections.add(local_collection);
967
+ await add_to_sync_queue({
968
+ action: "create",
969
+ table: "collections",
970
+ document_id: offline_id,
971
+ stall_offline_id: offline_id,
972
+ data: local_collection
973
+ });
974
+ created_collections.push(local_collection);
975
+ }
976
+ return created_collections;
543
977
  } catch (error) {
544
978
  throw error;
545
979
  }
@@ -547,13 +981,36 @@ var bulk_create4 = async (props) => {
547
981
  var bulk_update4 = async (props) => {
548
982
  try {
549
983
  const { sdk, data } = props;
550
- const adapter = await sdk.adapter();
551
- if (!adapter) throw new Error("Adapter not found");
552
- const collections2 = await adapter.collections.bulk_update({
553
- connector_config: sdk.options.configuration,
554
- data
555
- });
556
- return collections2;
984
+ const now = (/* @__PURE__ */ new Date()).toISOString();
985
+ const updated_collections = [];
986
+ for (const item of data) {
987
+ const existing = await local_db.collections.get(item.id);
988
+ if (!existing) {
989
+ console.warn(
990
+ `Collection with id ${item.id} not found locally, skipping`
991
+ );
992
+ continue;
993
+ }
994
+ const updated_collection = {
995
+ ...existing,
996
+ ...item.data,
997
+ id: existing.id,
998
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
999
+ stall_offline_id: existing.stall_offline_id,
1000
+ stall_offline_updated_at: now
1001
+ };
1002
+ await local_db.collections.put(updated_collection);
1003
+ await add_to_sync_queue({
1004
+ action: "update",
1005
+ table: "collections",
1006
+ document_id: item.id,
1007
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1008
+ stall_offline_id: existing.stall_offline_id,
1009
+ data: updated_collection
1010
+ });
1011
+ updated_collections.push(updated_collection);
1012
+ }
1013
+ return updated_collections;
557
1014
  } catch (error) {
558
1015
  throw error;
559
1016
  }
@@ -561,12 +1018,22 @@ var bulk_update4 = async (props) => {
561
1018
  var bulk_delete4 = async (props) => {
562
1019
  try {
563
1020
  const { sdk, ids } = props;
564
- const adapter = await sdk.adapter();
565
- if (!adapter) throw new Error("Adapter not found");
566
- await adapter.collections.bulk_delete({
567
- connector_config: sdk.options.configuration,
568
- ids
569
- });
1021
+ for (const id of ids) {
1022
+ const existing = await local_db.collections.get(id);
1023
+ if (!existing) {
1024
+ console.warn(`Collection with id ${id} not found locally, skipping`);
1025
+ continue;
1026
+ }
1027
+ await add_to_sync_queue({
1028
+ action: "delete",
1029
+ table: "collections",
1030
+ document_id: id,
1031
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1032
+ stall_offline_id: existing.stall_offline_id,
1033
+ data: { id }
1034
+ });
1035
+ await local_db.collections.delete(id);
1036
+ }
570
1037
  return;
571
1038
  } catch (error) {
572
1039
  throw error;
@@ -593,6 +1060,10 @@ var list5 = async (props) => {
593
1060
  connector_config: sdk.options.configuration,
594
1061
  query
595
1062
  });
1063
+ await save_bulk_data({
1064
+ table: "categories",
1065
+ data: categories2
1066
+ });
596
1067
  return categories2;
597
1068
  } catch (error) {
598
1069
  throw error;
@@ -607,6 +1078,7 @@ var retrieve5 = async (props) => {
607
1078
  connector_config: sdk.options.configuration,
608
1079
  id
609
1080
  });
1081
+ await local_db.categories.put(category);
610
1082
  return category;
611
1083
  } catch (error) {
612
1084
  throw error;
@@ -615,13 +1087,28 @@ var retrieve5 = async (props) => {
615
1087
  var create5 = async (props) => {
616
1088
  try {
617
1089
  const { sdk, data } = props;
618
- const adapter = await sdk.adapter();
619
- if (!adapter) throw new Error("Adapter not found");
620
- const category = await adapter.categories.create({
621
- connector_config: sdk.options.configuration,
622
- data
623
- });
624
- return category;
1090
+ const offline_id = generate_offline_id("category");
1091
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1092
+ const local_category = {
1093
+ ...data,
1094
+ id: offline_id,
1095
+ metadata: {
1096
+ ...data.metadata,
1097
+ stall_offline_id: offline_id
1098
+ },
1099
+ stall_offline_id: offline_id,
1100
+ stall_offline_created_at: now,
1101
+ stall_offline_updated_at: now
1102
+ };
1103
+ await local_db.categories.add(local_category);
1104
+ await add_to_sync_queue({
1105
+ action: "create",
1106
+ table: "categories",
1107
+ document_id: offline_id,
1108
+ stall_offline_id: offline_id,
1109
+ data: local_category
1110
+ });
1111
+ return local_category;
625
1112
  } catch (error) {
626
1113
  throw error;
627
1114
  }
@@ -629,14 +1116,29 @@ var create5 = async (props) => {
629
1116
  var update5 = async (props) => {
630
1117
  try {
631
1118
  const { sdk, id, data } = props;
632
- const adapter = await sdk.adapter();
633
- if (!adapter) throw new Error("Adapter not found");
634
- const category = await adapter.categories.update({
635
- connector_config: sdk.options.configuration,
636
- id,
637
- data
638
- });
639
- return category;
1119
+ const existing = await local_db.categories.get(id);
1120
+ if (!existing) {
1121
+ throw new Error(`Category with id ${id} not found locally`);
1122
+ }
1123
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1124
+ const updated_category = {
1125
+ ...existing,
1126
+ ...data,
1127
+ id: existing.id,
1128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1129
+ stall_offline_id: existing.stall_offline_id,
1130
+ stall_offline_updated_at: now
1131
+ };
1132
+ await local_db.categories.put(updated_category);
1133
+ await add_to_sync_queue({
1134
+ action: "update",
1135
+ table: "categories",
1136
+ document_id: id,
1137
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1138
+ stall_offline_id: existing.stall_offline_id,
1139
+ data: updated_category
1140
+ });
1141
+ return updated_category;
640
1142
  } catch (error) {
641
1143
  throw error;
642
1144
  }
@@ -644,12 +1146,19 @@ var update5 = async (props) => {
644
1146
  var _delete5 = async (props) => {
645
1147
  try {
646
1148
  const { sdk, id } = props;
647
- const adapter = await sdk.adapter();
648
- if (!adapter) throw new Error("Adapter not found");
649
- await adapter.categories.delete({
650
- connector_config: sdk.options.configuration,
651
- id
652
- });
1149
+ const existing = await local_db.categories.get(id);
1150
+ if (!existing) {
1151
+ throw new Error(`Category with id ${id} not found locally`);
1152
+ }
1153
+ await add_to_sync_queue({
1154
+ action: "delete",
1155
+ table: "categories",
1156
+ document_id: id,
1157
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1158
+ stall_offline_id: existing.stall_offline_id,
1159
+ data: { id }
1160
+ });
1161
+ await local_db.categories.delete(id);
653
1162
  return;
654
1163
  } catch (error) {
655
1164
  throw error;
@@ -658,13 +1167,32 @@ var _delete5 = async (props) => {
658
1167
  var bulk_create5 = async (props) => {
659
1168
  try {
660
1169
  const { sdk, data } = props;
661
- const adapter = await sdk.adapter();
662
- if (!adapter) throw new Error("Adapter not found");
663
- const categories2 = await adapter.categories.bulk_create({
664
- connector_config: sdk.options.configuration,
665
- data
666
- });
667
- return categories2;
1170
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1171
+ const created_categories = [];
1172
+ for (const category of data) {
1173
+ const offline_id = generate_offline_id("category");
1174
+ const local_category = {
1175
+ ...category,
1176
+ id: offline_id,
1177
+ metadata: {
1178
+ ...category.metadata,
1179
+ stall_offline_id: offline_id
1180
+ },
1181
+ stall_offline_id: offline_id,
1182
+ stall_offline_created_at: now,
1183
+ stall_offline_updated_at: now
1184
+ };
1185
+ await local_db.categories.add(local_category);
1186
+ await add_to_sync_queue({
1187
+ action: "create",
1188
+ table: "categories",
1189
+ document_id: offline_id,
1190
+ stall_offline_id: offline_id,
1191
+ data: local_category
1192
+ });
1193
+ created_categories.push(local_category);
1194
+ }
1195
+ return created_categories;
668
1196
  } catch (error) {
669
1197
  throw error;
670
1198
  }
@@ -672,13 +1200,34 @@ var bulk_create5 = async (props) => {
672
1200
  var bulk_update5 = async (props) => {
673
1201
  try {
674
1202
  const { sdk, data } = props;
675
- const adapter = await sdk.adapter();
676
- if (!adapter) throw new Error("Adapter not found");
677
- const categories2 = await adapter.categories.bulk_update({
678
- connector_config: sdk.options.configuration,
679
- data
680
- });
681
- return categories2;
1203
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1204
+ const updated_categories = [];
1205
+ for (const item of data) {
1206
+ const existing = await local_db.categories.get(item.id);
1207
+ if (!existing) {
1208
+ console.warn(`Category with id ${item.id} not found locally, skipping`);
1209
+ continue;
1210
+ }
1211
+ const updated_category = {
1212
+ ...existing,
1213
+ ...item.data,
1214
+ id: existing.id,
1215
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1216
+ stall_offline_id: existing.stall_offline_id,
1217
+ stall_offline_updated_at: now
1218
+ };
1219
+ await local_db.categories.put(updated_category);
1220
+ await add_to_sync_queue({
1221
+ action: "update",
1222
+ table: "categories",
1223
+ document_id: item.id,
1224
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1225
+ stall_offline_id: existing.stall_offline_id,
1226
+ data: updated_category
1227
+ });
1228
+ updated_categories.push(updated_category);
1229
+ }
1230
+ return updated_categories;
682
1231
  } catch (error) {
683
1232
  throw error;
684
1233
  }
@@ -686,12 +1235,22 @@ var bulk_update5 = async (props) => {
686
1235
  var bulk_delete5 = async (props) => {
687
1236
  try {
688
1237
  const { sdk, ids } = props;
689
- const adapter = await sdk.adapter();
690
- if (!adapter) throw new Error("Adapter not found");
691
- await adapter.categories.bulk_delete({
692
- connector_config: sdk.options.configuration,
693
- ids
694
- });
1238
+ for (const id of ids) {
1239
+ const existing = await local_db.categories.get(id);
1240
+ if (!existing) {
1241
+ console.warn(`Category with id ${id} not found locally, skipping`);
1242
+ continue;
1243
+ }
1244
+ await add_to_sync_queue({
1245
+ action: "delete",
1246
+ table: "categories",
1247
+ document_id: id,
1248
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1249
+ stall_offline_id: existing.stall_offline_id,
1250
+ data: { id }
1251
+ });
1252
+ await local_db.categories.delete(id);
1253
+ }
695
1254
  return;
696
1255
  } catch (error) {
697
1256
  throw error;
@@ -718,6 +1277,10 @@ var list6 = async (props) => {
718
1277
  connector_config: sdk.options.configuration,
719
1278
  query
720
1279
  });
1280
+ await save_bulk_data({
1281
+ table: "variants",
1282
+ data: variants2
1283
+ });
721
1284
  return variants2;
722
1285
  } catch (error) {
723
1286
  throw error;
@@ -732,6 +1295,7 @@ var retrieve6 = async (props) => {
732
1295
  connector_config: sdk.options.configuration,
733
1296
  id
734
1297
  });
1298
+ await local_db.variants.put(variant);
735
1299
  return variant;
736
1300
  } catch (error) {
737
1301
  throw error;
@@ -740,13 +1304,28 @@ var retrieve6 = async (props) => {
740
1304
  var create6 = async (props) => {
741
1305
  try {
742
1306
  const { sdk, data } = props;
743
- const adapter = await sdk.adapter();
744
- if (!adapter) throw new Error("Adapter not found");
745
- const variant = await adapter.variants.create({
746
- connector_config: sdk.options.configuration,
747
- data
748
- });
749
- return variant;
1307
+ const offline_id = generate_offline_id("variant");
1308
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1309
+ const local_variant = {
1310
+ ...data,
1311
+ id: offline_id,
1312
+ metadata: {
1313
+ ...data.metadata,
1314
+ stall_offline_id: offline_id
1315
+ },
1316
+ stall_offline_id: offline_id,
1317
+ stall_offline_created_at: now,
1318
+ stall_offline_updated_at: now
1319
+ };
1320
+ await local_db.variants.add(local_variant);
1321
+ await add_to_sync_queue({
1322
+ action: "create",
1323
+ table: "variants",
1324
+ document_id: offline_id,
1325
+ stall_offline_id: offline_id,
1326
+ data: local_variant
1327
+ });
1328
+ return local_variant;
750
1329
  } catch (error) {
751
1330
  throw error;
752
1331
  }
@@ -754,14 +1333,29 @@ var create6 = async (props) => {
754
1333
  var update6 = async (props) => {
755
1334
  try {
756
1335
  const { sdk, id, data } = props;
757
- const adapter = await sdk.adapter();
758
- if (!adapter) throw new Error("Adapter not found");
759
- const variant = await adapter.variants.update({
760
- connector_config: sdk.options.configuration,
761
- id,
762
- data
763
- });
764
- return variant;
1336
+ const existing = await local_db.variants.get(id);
1337
+ if (!existing) {
1338
+ throw new Error(`Variant with id ${id} not found locally`);
1339
+ }
1340
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1341
+ const updated_variant = {
1342
+ ...existing,
1343
+ ...data,
1344
+ id: existing.id,
1345
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1346
+ stall_offline_id: existing.stall_offline_id,
1347
+ stall_offline_updated_at: now
1348
+ };
1349
+ await local_db.variants.put(updated_variant);
1350
+ await add_to_sync_queue({
1351
+ action: "update",
1352
+ table: "variants",
1353
+ document_id: id,
1354
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1355
+ stall_offline_id: existing.stall_offline_id,
1356
+ data: updated_variant
1357
+ });
1358
+ return updated_variant;
765
1359
  } catch (error) {
766
1360
  throw error;
767
1361
  }
@@ -769,12 +1363,19 @@ var update6 = async (props) => {
769
1363
  var _delete6 = async (props) => {
770
1364
  try {
771
1365
  const { sdk, id } = props;
772
- const adapter = await sdk.adapter();
773
- if (!adapter) throw new Error("Adapter not found");
774
- await adapter.variants.delete({
775
- connector_config: sdk.options.configuration,
776
- id
777
- });
1366
+ const existing = await local_db.variants.get(id);
1367
+ if (!existing) {
1368
+ throw new Error(`Variant with id ${id} not found locally`);
1369
+ }
1370
+ await add_to_sync_queue({
1371
+ action: "delete",
1372
+ table: "variants",
1373
+ document_id: id,
1374
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1375
+ stall_offline_id: existing.stall_offline_id,
1376
+ data: { id }
1377
+ });
1378
+ await local_db.variants.delete(id);
778
1379
  return;
779
1380
  } catch (error) {
780
1381
  throw error;
@@ -783,13 +1384,32 @@ var _delete6 = async (props) => {
783
1384
  var bulk_create6 = async (props) => {
784
1385
  try {
785
1386
  const { sdk, data } = props;
786
- const adapter = await sdk.adapter();
787
- if (!adapter) throw new Error("Adapter not found");
788
- const variants2 = await adapter.variants.bulk_create({
789
- connector_config: sdk.options.configuration,
790
- data
791
- });
792
- return variants2;
1387
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1388
+ const created_variants = [];
1389
+ for (const variant of data) {
1390
+ const offline_id = generate_offline_id("variant");
1391
+ const local_variant = {
1392
+ ...variant,
1393
+ id: offline_id,
1394
+ metadata: {
1395
+ ...variant.metadata,
1396
+ stall_offline_id: offline_id
1397
+ },
1398
+ stall_offline_id: offline_id,
1399
+ stall_offline_created_at: now,
1400
+ stall_offline_updated_at: now
1401
+ };
1402
+ await local_db.variants.add(local_variant);
1403
+ await add_to_sync_queue({
1404
+ action: "create",
1405
+ table: "variants",
1406
+ document_id: offline_id,
1407
+ stall_offline_id: offline_id,
1408
+ data: local_variant
1409
+ });
1410
+ created_variants.push(local_variant);
1411
+ }
1412
+ return created_variants;
793
1413
  } catch (error) {
794
1414
  throw error;
795
1415
  }
@@ -797,13 +1417,34 @@ var bulk_create6 = async (props) => {
797
1417
  var bulk_update6 = async (props) => {
798
1418
  try {
799
1419
  const { sdk, data } = props;
800
- const adapter = await sdk.adapter();
801
- if (!adapter) throw new Error("Adapter not found");
802
- const variants2 = await adapter.variants.bulk_update({
803
- connector_config: sdk.options.configuration,
804
- data
805
- });
806
- return variants2;
1420
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1421
+ const updated_variants = [];
1422
+ for (const item of data) {
1423
+ const existing = await local_db.variants.get(item.id);
1424
+ if (!existing) {
1425
+ console.warn(`Variant with id ${item.id} not found locally, skipping`);
1426
+ continue;
1427
+ }
1428
+ const updated_variant = {
1429
+ ...existing,
1430
+ ...item.data,
1431
+ id: existing.id,
1432
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1433
+ stall_offline_id: existing.stall_offline_id,
1434
+ stall_offline_updated_at: now
1435
+ };
1436
+ await local_db.variants.put(updated_variant);
1437
+ await add_to_sync_queue({
1438
+ action: "update",
1439
+ table: "variants",
1440
+ document_id: item.id,
1441
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1442
+ stall_offline_id: existing.stall_offline_id,
1443
+ data: updated_variant
1444
+ });
1445
+ updated_variants.push(updated_variant);
1446
+ }
1447
+ return updated_variants;
807
1448
  } catch (error) {
808
1449
  throw error;
809
1450
  }
@@ -811,12 +1452,22 @@ var bulk_update6 = async (props) => {
811
1452
  var bulk_delete6 = async (props) => {
812
1453
  try {
813
1454
  const { sdk, ids } = props;
814
- const adapter = await sdk.adapter();
815
- if (!adapter) throw new Error("Adapter not found");
816
- await adapter.variants.bulk_delete({
817
- connector_config: sdk.options.configuration,
818
- ids
819
- });
1455
+ for (const id of ids) {
1456
+ const existing = await local_db.variants.get(id);
1457
+ if (!existing) {
1458
+ console.warn(`Variant with id ${id} not found locally, skipping`);
1459
+ continue;
1460
+ }
1461
+ await add_to_sync_queue({
1462
+ action: "delete",
1463
+ table: "variants",
1464
+ document_id: id,
1465
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1466
+ stall_offline_id: existing.stall_offline_id,
1467
+ data: { id }
1468
+ });
1469
+ await local_db.variants.delete(id);
1470
+ }
820
1471
  return;
821
1472
  } catch (error) {
822
1473
  throw error;
@@ -839,11 +1490,15 @@ var list7 = async (props) => {
839
1490
  const { sdk, query } = props;
840
1491
  const adapter = await sdk.adapter();
841
1492
  if (!adapter) throw new Error("Adapter not found");
842
- const inventories = await adapter.inventory_levels.list({
1493
+ const inventory_levels2 = await adapter.inventory_levels.list({
843
1494
  connector_config: sdk.options.configuration,
844
1495
  query
845
1496
  });
846
- return inventories;
1497
+ await save_bulk_data({
1498
+ table: "inventory_levels",
1499
+ data: inventory_levels2
1500
+ });
1501
+ return inventory_levels2;
847
1502
  } catch (error) {
848
1503
  throw error;
849
1504
  }
@@ -853,11 +1508,12 @@ var retrieve7 = async (props) => {
853
1508
  const { sdk, id } = props;
854
1509
  const adapter = await sdk.adapter();
855
1510
  if (!adapter) throw new Error("Adapter not found");
856
- const inventory = await adapter.inventory_levels.retrieve({
1511
+ const inventory_level = await adapter.inventory_levels.retrieve({
857
1512
  connector_config: sdk.options.configuration,
858
1513
  id
859
1514
  });
860
- return inventory;
1515
+ await local_db.inventory_levels.put(inventory_level);
1516
+ return inventory_level;
861
1517
  } catch (error) {
862
1518
  throw error;
863
1519
  }
@@ -865,13 +1521,29 @@ var retrieve7 = async (props) => {
865
1521
  var create7 = async (props) => {
866
1522
  try {
867
1523
  const { sdk, data } = props;
868
- const adapter = await sdk.adapter();
869
- if (!adapter) throw new Error("Adapter not found");
870
- const inventory = await adapter.inventory_levels.create({
871
- connector_config: sdk.options.configuration,
872
- data
873
- });
874
- return inventory;
1524
+ const offline_id = generate_offline_id("inventory_level");
1525
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1526
+ const local_inventory_level = {
1527
+ ...data,
1528
+ id: offline_id,
1529
+ metadata: {
1530
+ ...data.metadata,
1531
+ stall_offline_id: offline_id
1532
+ },
1533
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1534
+ stall_offline_id: offline_id,
1535
+ stall_offline_created_at: now,
1536
+ stall_offline_updated_at: now
1537
+ };
1538
+ await local_db.inventory_levels.add(local_inventory_level);
1539
+ await add_to_sync_queue({
1540
+ action: "create",
1541
+ table: "inventory_levels",
1542
+ document_id: offline_id,
1543
+ stall_offline_id: offline_id,
1544
+ data: local_inventory_level
1545
+ });
1546
+ return local_inventory_level;
875
1547
  } catch (error) {
876
1548
  throw error;
877
1549
  }
@@ -879,14 +1551,29 @@ var create7 = async (props) => {
879
1551
  var update7 = async (props) => {
880
1552
  try {
881
1553
  const { sdk, id, data } = props;
882
- const adapter = await sdk.adapter();
883
- if (!adapter) throw new Error("Adapter not found");
884
- const inventory = await adapter.inventory_levels.update({
885
- connector_config: sdk.options.configuration,
886
- id,
887
- data
888
- });
889
- return inventory;
1554
+ const existing = await local_db.inventory_levels.get(id);
1555
+ if (!existing) {
1556
+ throw new Error(`Inventory level with id ${id} not found locally`);
1557
+ }
1558
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1559
+ const updated_inventory_level = {
1560
+ ...existing,
1561
+ ...data,
1562
+ id: existing.id,
1563
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1564
+ stall_offline_id: existing.stall_offline_id,
1565
+ stall_offline_updated_at: now
1566
+ };
1567
+ await local_db.inventory_levels.put(updated_inventory_level);
1568
+ await add_to_sync_queue({
1569
+ action: "update",
1570
+ table: "inventory_levels",
1571
+ document_id: id,
1572
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1573
+ stall_offline_id: existing.stall_offline_id,
1574
+ data: updated_inventory_level
1575
+ });
1576
+ return updated_inventory_level;
890
1577
  } catch (error) {
891
1578
  throw error;
892
1579
  }
@@ -894,12 +1581,19 @@ var update7 = async (props) => {
894
1581
  var _delete7 = async (props) => {
895
1582
  try {
896
1583
  const { sdk, id } = props;
897
- const adapter = await sdk.adapter();
898
- if (!adapter) throw new Error("Adapter not found");
899
- await adapter.inventory_levels.delete({
900
- connector_config: sdk.options.configuration,
901
- id
902
- });
1584
+ const existing = await local_db.inventory_levels.get(id);
1585
+ if (!existing) {
1586
+ throw new Error(`Inventory level with id ${id} not found locally`);
1587
+ }
1588
+ await add_to_sync_queue({
1589
+ action: "delete",
1590
+ table: "inventory_levels",
1591
+ document_id: id,
1592
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1593
+ stall_offline_id: existing.stall_offline_id,
1594
+ data: { id }
1595
+ });
1596
+ await local_db.inventory_levels.delete(id);
903
1597
  return;
904
1598
  } catch (error) {
905
1599
  throw error;
@@ -908,13 +1602,33 @@ var _delete7 = async (props) => {
908
1602
  var bulk_create7 = async (props) => {
909
1603
  try {
910
1604
  const { sdk, data } = props;
911
- const adapter = await sdk.adapter();
912
- if (!adapter) throw new Error("Adapter not found");
913
- const inventories = await adapter.inventory_levels.bulk_create({
914
- connector_config: sdk.options.configuration,
915
- data
916
- });
917
- return inventories;
1605
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1606
+ const created_inventory_levels = [];
1607
+ for (const inventory_level of data) {
1608
+ const offline_id = generate_offline_id("inventory_level");
1609
+ const local_inventory_level = {
1610
+ ...inventory_level,
1611
+ id: offline_id,
1612
+ metadata: {
1613
+ ...inventory_level.metadata,
1614
+ stall_offline_id: offline_id
1615
+ },
1616
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1617
+ stall_offline_id: offline_id,
1618
+ stall_offline_created_at: now,
1619
+ stall_offline_updated_at: now
1620
+ };
1621
+ await local_db.inventory_levels.add(local_inventory_level);
1622
+ await add_to_sync_queue({
1623
+ action: "create",
1624
+ table: "inventory_levels",
1625
+ document_id: offline_id,
1626
+ stall_offline_id: offline_id,
1627
+ data: local_inventory_level
1628
+ });
1629
+ created_inventory_levels.push(local_inventory_level);
1630
+ }
1631
+ return created_inventory_levels;
918
1632
  } catch (error) {
919
1633
  throw error;
920
1634
  }
@@ -922,13 +1636,36 @@ var bulk_create7 = async (props) => {
922
1636
  var bulk_update7 = async (props) => {
923
1637
  try {
924
1638
  const { sdk, data } = props;
925
- const adapter = await sdk.adapter();
926
- if (!adapter) throw new Error("Adapter not found");
927
- const inventories = await adapter.inventory_levels.bulk_update({
928
- connector_config: sdk.options.configuration,
929
- data
930
- });
931
- return inventories;
1639
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1640
+ const updated_inventory_levels = [];
1641
+ for (const item of data) {
1642
+ const existing = await local_db.inventory_levels.get(item.id);
1643
+ if (!existing) {
1644
+ console.warn(
1645
+ `Inventory level with id ${item.id} not found locally, skipping`
1646
+ );
1647
+ continue;
1648
+ }
1649
+ const updated_inventory_level = {
1650
+ ...existing,
1651
+ ...item.data,
1652
+ id: existing.id,
1653
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1654
+ stall_offline_id: existing.stall_offline_id,
1655
+ stall_offline_updated_at: now
1656
+ };
1657
+ await local_db.inventory_levels.put(updated_inventory_level);
1658
+ await add_to_sync_queue({
1659
+ action: "update",
1660
+ table: "inventory_levels",
1661
+ document_id: item.id,
1662
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1663
+ stall_offline_id: existing.stall_offline_id,
1664
+ data: updated_inventory_level
1665
+ });
1666
+ updated_inventory_levels.push(updated_inventory_level);
1667
+ }
1668
+ return updated_inventory_levels;
932
1669
  } catch (error) {
933
1670
  throw error;
934
1671
  }
@@ -936,12 +1673,24 @@ var bulk_update7 = async (props) => {
936
1673
  var bulk_delete7 = async (props) => {
937
1674
  try {
938
1675
  const { sdk, ids } = props;
939
- const adapter = await sdk.adapter();
940
- if (!adapter) throw new Error("Adapter not found");
941
- await adapter.inventory_levels.bulk_delete({
942
- connector_config: sdk.options.configuration,
943
- ids
944
- });
1676
+ for (const id of ids) {
1677
+ const existing = await local_db.inventory_levels.get(id);
1678
+ if (!existing) {
1679
+ console.warn(
1680
+ `Inventory level with id ${id} not found locally, skipping`
1681
+ );
1682
+ continue;
1683
+ }
1684
+ await add_to_sync_queue({
1685
+ action: "delete",
1686
+ table: "inventory_levels",
1687
+ document_id: id,
1688
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1689
+ stall_offline_id: existing.stall_offline_id,
1690
+ data: { id }
1691
+ });
1692
+ await local_db.inventory_levels.delete(id);
1693
+ }
945
1694
  return;
946
1695
  } catch (error) {
947
1696
  throw error;
@@ -968,6 +1717,10 @@ var list8 = async (props) => {
968
1717
  connector_config: sdk.options.configuration,
969
1718
  query
970
1719
  });
1720
+ await save_bulk_data({
1721
+ table: "promotions",
1722
+ data: promotions2
1723
+ });
971
1724
  return promotions2;
972
1725
  } catch (error) {
973
1726
  throw error;
@@ -982,6 +1735,7 @@ var retrieve8 = async (props) => {
982
1735
  connector_config: sdk.options.configuration,
983
1736
  id
984
1737
  });
1738
+ await local_db.promotions.put(promotion);
985
1739
  return promotion;
986
1740
  } catch (error) {
987
1741
  throw error;
@@ -990,13 +1744,29 @@ var retrieve8 = async (props) => {
990
1744
  var create8 = async (props) => {
991
1745
  try {
992
1746
  const { sdk, data } = props;
993
- const adapter = await sdk.adapter();
994
- if (!adapter) throw new Error("Adapter not found");
995
- const promotion = await adapter.promotions.create({
996
- connector_config: sdk.options.configuration,
997
- data
998
- });
999
- return promotion;
1747
+ const offline_id = generate_offline_id("promotion");
1748
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1749
+ const local_promotion = {
1750
+ ...data,
1751
+ id: offline_id,
1752
+ metadata: {
1753
+ ...data.metadata,
1754
+ stall_offline_id: offline_id
1755
+ },
1756
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1757
+ stall_offline_id: offline_id,
1758
+ stall_offline_created_at: now,
1759
+ stall_offline_updated_at: now
1760
+ };
1761
+ await local_db.promotions.add(local_promotion);
1762
+ await add_to_sync_queue({
1763
+ action: "create",
1764
+ table: "promotions",
1765
+ document_id: offline_id,
1766
+ stall_offline_id: offline_id,
1767
+ data: local_promotion
1768
+ });
1769
+ return local_promotion;
1000
1770
  } catch (error) {
1001
1771
  throw error;
1002
1772
  }
@@ -1004,14 +1774,29 @@ var create8 = async (props) => {
1004
1774
  var update8 = async (props) => {
1005
1775
  try {
1006
1776
  const { sdk, id, data } = props;
1007
- const adapter = await sdk.adapter();
1008
- if (!adapter) throw new Error("Adapter not found");
1009
- const promotion = await adapter.promotions.update({
1010
- connector_config: sdk.options.configuration,
1011
- id,
1012
- data
1013
- });
1014
- return promotion;
1777
+ const existing = await local_db.promotions.get(id);
1778
+ if (!existing) {
1779
+ throw new Error(`Promotion with id ${id} not found locally`);
1780
+ }
1781
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1782
+ const updated_promotion = {
1783
+ ...existing,
1784
+ ...data,
1785
+ id: existing.id,
1786
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1787
+ stall_offline_id: existing.stall_offline_id,
1788
+ stall_offline_updated_at: now
1789
+ };
1790
+ await local_db.promotions.put(updated_promotion);
1791
+ await add_to_sync_queue({
1792
+ action: "update",
1793
+ table: "promotions",
1794
+ document_id: id,
1795
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1796
+ stall_offline_id: existing.stall_offline_id,
1797
+ data: updated_promotion
1798
+ });
1799
+ return updated_promotion;
1015
1800
  } catch (error) {
1016
1801
  throw error;
1017
1802
  }
@@ -1019,12 +1804,19 @@ var update8 = async (props) => {
1019
1804
  var _delete8 = async (props) => {
1020
1805
  try {
1021
1806
  const { sdk, id } = props;
1022
- const adapter = await sdk.adapter();
1023
- if (!adapter) throw new Error("Adapter not found");
1024
- await adapter.promotions.delete({
1025
- connector_config: sdk.options.configuration,
1026
- id
1027
- });
1807
+ const existing = await local_db.promotions.get(id);
1808
+ if (!existing) {
1809
+ throw new Error(`Promotion with id ${id} not found locally`);
1810
+ }
1811
+ await add_to_sync_queue({
1812
+ action: "delete",
1813
+ table: "promotions",
1814
+ document_id: id,
1815
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1816
+ stall_offline_id: existing.stall_offline_id,
1817
+ data: { id }
1818
+ });
1819
+ await local_db.promotions.delete(id);
1028
1820
  return;
1029
1821
  } catch (error) {
1030
1822
  throw error;
@@ -1033,13 +1825,33 @@ var _delete8 = async (props) => {
1033
1825
  var bulk_create8 = async (props) => {
1034
1826
  try {
1035
1827
  const { sdk, data } = props;
1036
- const adapter = await sdk.adapter();
1037
- if (!adapter) throw new Error("Adapter not found");
1038
- const promotions2 = await adapter.promotions.bulk_create({
1039
- connector_config: sdk.options.configuration,
1040
- data
1041
- });
1042
- return promotions2;
1828
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1829
+ const created_promotions = [];
1830
+ for (const promotion of data) {
1831
+ const offline_id = generate_offline_id("promotion");
1832
+ const local_promotion = {
1833
+ ...promotion,
1834
+ id: offline_id,
1835
+ metadata: {
1836
+ ...promotion.metadata,
1837
+ stall_offline_id: offline_id
1838
+ },
1839
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1840
+ stall_offline_id: offline_id,
1841
+ stall_offline_created_at: now,
1842
+ stall_offline_updated_at: now
1843
+ };
1844
+ await local_db.promotions.add(local_promotion);
1845
+ await add_to_sync_queue({
1846
+ action: "create",
1847
+ table: "promotions",
1848
+ document_id: offline_id,
1849
+ stall_offline_id: offline_id,
1850
+ data: local_promotion
1851
+ });
1852
+ created_promotions.push(local_promotion);
1853
+ }
1854
+ return created_promotions;
1043
1855
  } catch (error) {
1044
1856
  throw error;
1045
1857
  }
@@ -1047,13 +1859,36 @@ var bulk_create8 = async (props) => {
1047
1859
  var bulk_update8 = async (props) => {
1048
1860
  try {
1049
1861
  const { sdk, data } = props;
1050
- const adapter = await sdk.adapter();
1051
- if (!adapter) throw new Error("Adapter not found");
1052
- const promotions2 = await adapter.promotions.bulk_update({
1053
- connector_config: sdk.options.configuration,
1054
- data
1055
- });
1056
- return promotions2;
1862
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1863
+ const updated_promotions = [];
1864
+ for (const item of data) {
1865
+ const existing = await local_db.promotions.get(item.id);
1866
+ if (!existing) {
1867
+ console.warn(
1868
+ `Promotion with id ${item.id} not found locally, skipping`
1869
+ );
1870
+ continue;
1871
+ }
1872
+ const updated_promotion = {
1873
+ ...existing,
1874
+ ...item.data,
1875
+ id: existing.id,
1876
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1877
+ stall_offline_id: existing.stall_offline_id,
1878
+ stall_offline_updated_at: now
1879
+ };
1880
+ await local_db.promotions.put(updated_promotion);
1881
+ await add_to_sync_queue({
1882
+ action: "update",
1883
+ table: "promotions",
1884
+ document_id: item.id,
1885
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1886
+ stall_offline_id: existing.stall_offline_id,
1887
+ data: updated_promotion
1888
+ });
1889
+ updated_promotions.push(updated_promotion);
1890
+ }
1891
+ return updated_promotions;
1057
1892
  } catch (error) {
1058
1893
  throw error;
1059
1894
  }
@@ -1061,12 +1896,22 @@ var bulk_update8 = async (props) => {
1061
1896
  var bulk_delete8 = async (props) => {
1062
1897
  try {
1063
1898
  const { sdk, ids } = props;
1064
- const adapter = await sdk.adapter();
1065
- if (!adapter) throw new Error("Adapter not found");
1066
- await adapter.promotions.bulk_delete({
1067
- connector_config: sdk.options.configuration,
1068
- ids
1069
- });
1899
+ for (const id of ids) {
1900
+ const existing = await local_db.promotions.get(id);
1901
+ if (!existing) {
1902
+ console.warn(`Promotion with id ${id} not found locally, skipping`);
1903
+ continue;
1904
+ }
1905
+ await add_to_sync_queue({
1906
+ action: "delete",
1907
+ table: "promotions",
1908
+ document_id: id,
1909
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1910
+ stall_offline_id: existing.stall_offline_id,
1911
+ data: { id }
1912
+ });
1913
+ await local_db.promotions.delete(id);
1914
+ }
1070
1915
  return;
1071
1916
  } catch (error) {
1072
1917
  throw error;
@@ -1089,11 +1934,15 @@ var list9 = async (props) => {
1089
1934
  const { sdk, query } = props;
1090
1935
  const adapter = await sdk.adapter();
1091
1936
  if (!adapter) throw new Error("Adapter not found");
1092
- const notes = await adapter.order_notes.list({
1937
+ const order_notes2 = await adapter.order_notes.list({
1093
1938
  connector_config: sdk.options.configuration,
1094
1939
  query
1095
1940
  });
1096
- return notes;
1941
+ await save_bulk_data({
1942
+ table: "order_notes",
1943
+ data: order_notes2
1944
+ });
1945
+ return order_notes2;
1097
1946
  } catch (error) {
1098
1947
  throw error;
1099
1948
  }
@@ -1103,11 +1952,12 @@ var retrieve9 = async (props) => {
1103
1952
  const { sdk, id } = props;
1104
1953
  const adapter = await sdk.adapter();
1105
1954
  if (!adapter) throw new Error("Adapter not found");
1106
- const note = await adapter.order_notes.retrieve({
1955
+ const order_note = await adapter.order_notes.retrieve({
1107
1956
  connector_config: sdk.options.configuration,
1108
1957
  id
1109
1958
  });
1110
- return note;
1959
+ await local_db.order_notes.put(order_note);
1960
+ return order_note;
1111
1961
  } catch (error) {
1112
1962
  throw error;
1113
1963
  }
@@ -1115,13 +1965,29 @@ var retrieve9 = async (props) => {
1115
1965
  var create9 = async (props) => {
1116
1966
  try {
1117
1967
  const { sdk, data } = props;
1118
- const adapter = await sdk.adapter();
1119
- if (!adapter) throw new Error("Adapter not found");
1120
- const note = await adapter.order_notes.create({
1121
- connector_config: sdk.options.configuration,
1122
- data
1123
- });
1124
- return note;
1968
+ const offline_id = generate_offline_id("order_note");
1969
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1970
+ const local_order_note = {
1971
+ ...data,
1972
+ id: offline_id,
1973
+ metadata: {
1974
+ ...data.metadata,
1975
+ stall_offline_id: offline_id
1976
+ },
1977
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1978
+ stall_offline_id: offline_id,
1979
+ stall_offline_created_at: now,
1980
+ stall_offline_updated_at: now
1981
+ };
1982
+ await local_db.order_notes.add(local_order_note);
1983
+ await add_to_sync_queue({
1984
+ action: "create",
1985
+ table: "order_notes",
1986
+ document_id: offline_id,
1987
+ stall_offline_id: offline_id,
1988
+ data: local_order_note
1989
+ });
1990
+ return local_order_note;
1125
1991
  } catch (error) {
1126
1992
  throw error;
1127
1993
  }
@@ -1129,14 +1995,29 @@ var create9 = async (props) => {
1129
1995
  var update9 = async (props) => {
1130
1996
  try {
1131
1997
  const { sdk, id, data } = props;
1132
- const adapter = await sdk.adapter();
1133
- if (!adapter) throw new Error("Adapter not found");
1134
- const note = await adapter.order_notes.update({
1135
- connector_config: sdk.options.configuration,
1136
- id,
1137
- data
1138
- });
1139
- return note;
1998
+ const existing = await local_db.order_notes.get(id);
1999
+ if (!existing) {
2000
+ throw new Error(`Order note with id ${id} not found locally`);
2001
+ }
2002
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2003
+ const updated_order_note = {
2004
+ ...existing,
2005
+ ...data,
2006
+ id: existing.id,
2007
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2008
+ stall_offline_id: existing.stall_offline_id,
2009
+ stall_offline_updated_at: now
2010
+ };
2011
+ await local_db.order_notes.put(updated_order_note);
2012
+ await add_to_sync_queue({
2013
+ action: "update",
2014
+ table: "order_notes",
2015
+ document_id: id,
2016
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2017
+ stall_offline_id: existing.stall_offline_id,
2018
+ data: updated_order_note
2019
+ });
2020
+ return updated_order_note;
1140
2021
  } catch (error) {
1141
2022
  throw error;
1142
2023
  }
@@ -1144,12 +2025,19 @@ var update9 = async (props) => {
1144
2025
  var _delete9 = async (props) => {
1145
2026
  try {
1146
2027
  const { sdk, id } = props;
1147
- const adapter = await sdk.adapter();
1148
- if (!adapter) throw new Error("Adapter not found");
1149
- await adapter.order_notes.delete({
1150
- connector_config: sdk.options.configuration,
1151
- id
1152
- });
2028
+ const existing = await local_db.order_notes.get(id);
2029
+ if (!existing) {
2030
+ throw new Error(`Order note with id ${id} not found locally`);
2031
+ }
2032
+ await add_to_sync_queue({
2033
+ action: "delete",
2034
+ table: "order_notes",
2035
+ document_id: id,
2036
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2037
+ stall_offline_id: existing.stall_offline_id,
2038
+ data: { id }
2039
+ });
2040
+ await local_db.order_notes.delete(id);
1153
2041
  return;
1154
2042
  } catch (error) {
1155
2043
  throw error;
@@ -1158,13 +2046,33 @@ var _delete9 = async (props) => {
1158
2046
  var bulk_create9 = async (props) => {
1159
2047
  try {
1160
2048
  const { sdk, data } = props;
1161
- const adapter = await sdk.adapter();
1162
- if (!adapter) throw new Error("Adapter not found");
1163
- const notes = await adapter.order_notes.bulk_create({
1164
- connector_config: sdk.options.configuration,
1165
- data
1166
- });
1167
- return notes;
2049
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2050
+ const created_order_notes = [];
2051
+ for (const order_note of data) {
2052
+ const offline_id = generate_offline_id("order_note");
2053
+ const local_order_note = {
2054
+ ...order_note,
2055
+ id: offline_id,
2056
+ metadata: {
2057
+ ...order_note.metadata,
2058
+ stall_offline_id: offline_id
2059
+ },
2060
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2061
+ stall_offline_id: offline_id,
2062
+ stall_offline_created_at: now,
2063
+ stall_offline_updated_at: now
2064
+ };
2065
+ await local_db.order_notes.add(local_order_note);
2066
+ await add_to_sync_queue({
2067
+ action: "create",
2068
+ table: "order_notes",
2069
+ document_id: offline_id,
2070
+ stall_offline_id: offline_id,
2071
+ data: local_order_note
2072
+ });
2073
+ created_order_notes.push(local_order_note);
2074
+ }
2075
+ return created_order_notes;
1168
2076
  } catch (error) {
1169
2077
  throw error;
1170
2078
  }
@@ -1172,13 +2080,36 @@ var bulk_create9 = async (props) => {
1172
2080
  var bulk_update9 = async (props) => {
1173
2081
  try {
1174
2082
  const { sdk, data } = props;
1175
- const adapter = await sdk.adapter();
1176
- if (!adapter) throw new Error("Adapter not found");
1177
- const notes = await adapter.order_notes.bulk_update({
1178
- connector_config: sdk.options.configuration,
1179
- data
1180
- });
1181
- return notes;
2083
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2084
+ const updated_order_notes = [];
2085
+ for (const item of data) {
2086
+ const existing = await local_db.order_notes.get(item.id);
2087
+ if (!existing) {
2088
+ console.warn(
2089
+ `Order note with id ${item.id} not found locally, skipping`
2090
+ );
2091
+ continue;
2092
+ }
2093
+ const updated_order_note = {
2094
+ ...existing,
2095
+ ...item.data,
2096
+ id: existing.id,
2097
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2098
+ stall_offline_id: existing.stall_offline_id,
2099
+ stall_offline_updated_at: now
2100
+ };
2101
+ await local_db.order_notes.put(updated_order_note);
2102
+ await add_to_sync_queue({
2103
+ action: "update",
2104
+ table: "order_notes",
2105
+ document_id: item.id,
2106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2107
+ stall_offline_id: existing.stall_offline_id,
2108
+ data: updated_order_note
2109
+ });
2110
+ updated_order_notes.push(updated_order_note);
2111
+ }
2112
+ return updated_order_notes;
1182
2113
  } catch (error) {
1183
2114
  throw error;
1184
2115
  }
@@ -1186,12 +2117,22 @@ var bulk_update9 = async (props) => {
1186
2117
  var bulk_delete9 = async (props) => {
1187
2118
  try {
1188
2119
  const { sdk, ids } = props;
1189
- const adapter = await sdk.adapter();
1190
- if (!adapter) throw new Error("Adapter not found");
1191
- await adapter.order_notes.bulk_delete({
1192
- connector_config: sdk.options.configuration,
1193
- ids
1194
- });
2120
+ for (const id of ids) {
2121
+ const existing = await local_db.order_notes.get(id);
2122
+ if (!existing) {
2123
+ console.warn(`Order note with id ${id} not found locally, skipping`);
2124
+ continue;
2125
+ }
2126
+ await add_to_sync_queue({
2127
+ action: "delete",
2128
+ table: "order_notes",
2129
+ document_id: id,
2130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2131
+ stall_offline_id: existing.stall_offline_id,
2132
+ data: { id }
2133
+ });
2134
+ await local_db.order_notes.delete(id);
2135
+ }
1195
2136
  return;
1196
2137
  } catch (error) {
1197
2138
  throw error;
@@ -1218,6 +2159,10 @@ var list10 = async (props) => {
1218
2159
  connector_config: sdk.options.configuration,
1219
2160
  query
1220
2161
  });
2162
+ await save_bulk_data({
2163
+ table: "refunds",
2164
+ data: refunds2
2165
+ });
1221
2166
  return refunds2;
1222
2167
  } catch (error) {
1223
2168
  throw error;
@@ -1232,6 +2177,7 @@ var retrieve10 = async (props) => {
1232
2177
  connector_config: sdk.options.configuration,
1233
2178
  id
1234
2179
  });
2180
+ await local_db.refunds.put(refund);
1235
2181
  return refund;
1236
2182
  } catch (error) {
1237
2183
  throw error;
@@ -1240,13 +2186,29 @@ var retrieve10 = async (props) => {
1240
2186
  var create10 = async (props) => {
1241
2187
  try {
1242
2188
  const { sdk, data } = props;
1243
- const adapter = await sdk.adapter();
1244
- if (!adapter) throw new Error("Adapter not found");
1245
- const refund = await adapter.refunds.create({
1246
- connector_config: sdk.options.configuration,
1247
- data
1248
- });
1249
- return refund;
2189
+ const offline_id = generate_offline_id("refund");
2190
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2191
+ const local_refund = {
2192
+ ...data,
2193
+ id: offline_id,
2194
+ metadata: {
2195
+ ...data.metadata,
2196
+ stall_offline_id: offline_id
2197
+ },
2198
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2199
+ stall_offline_id: offline_id,
2200
+ stall_offline_created_at: now,
2201
+ stall_offline_updated_at: now
2202
+ };
2203
+ await local_db.refunds.add(local_refund);
2204
+ await add_to_sync_queue({
2205
+ action: "create",
2206
+ table: "refunds",
2207
+ document_id: offline_id,
2208
+ stall_offline_id: offline_id,
2209
+ data: local_refund
2210
+ });
2211
+ return local_refund;
1250
2212
  } catch (error) {
1251
2213
  throw error;
1252
2214
  }
@@ -1254,14 +2216,29 @@ var create10 = async (props) => {
1254
2216
  var update10 = async (props) => {
1255
2217
  try {
1256
2218
  const { sdk, id, data } = props;
1257
- const adapter = await sdk.adapter();
1258
- if (!adapter) throw new Error("Adapter not found");
1259
- const refund = await adapter.refunds.update({
1260
- connector_config: sdk.options.configuration,
1261
- id,
1262
- data
1263
- });
1264
- return refund;
2219
+ const existing = await local_db.refunds.get(id);
2220
+ if (!existing) {
2221
+ throw new Error(`Refund with id ${id} not found locally`);
2222
+ }
2223
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2224
+ const updated_refund = {
2225
+ ...existing,
2226
+ ...data,
2227
+ id: existing.id,
2228
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2229
+ stall_offline_id: existing.stall_offline_id,
2230
+ stall_offline_updated_at: now
2231
+ };
2232
+ await local_db.refunds.put(updated_refund);
2233
+ await add_to_sync_queue({
2234
+ action: "update",
2235
+ table: "refunds",
2236
+ document_id: id,
2237
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2238
+ stall_offline_id: existing.stall_offline_id,
2239
+ data: updated_refund
2240
+ });
2241
+ return updated_refund;
1265
2242
  } catch (error) {
1266
2243
  throw error;
1267
2244
  }
@@ -1269,12 +2246,19 @@ var update10 = async (props) => {
1269
2246
  var _delete10 = async (props) => {
1270
2247
  try {
1271
2248
  const { sdk, id } = props;
1272
- const adapter = await sdk.adapter();
1273
- if (!adapter) throw new Error("Adapter not found");
1274
- await adapter.refunds.delete({
1275
- connector_config: sdk.options.configuration,
1276
- id
1277
- });
2249
+ const existing = await local_db.refunds.get(id);
2250
+ if (!existing) {
2251
+ throw new Error(`Refund with id ${id} not found locally`);
2252
+ }
2253
+ await add_to_sync_queue({
2254
+ action: "delete",
2255
+ table: "refunds",
2256
+ document_id: id,
2257
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2258
+ stall_offline_id: existing.stall_offline_id,
2259
+ data: { id }
2260
+ });
2261
+ await local_db.refunds.delete(id);
1278
2262
  return;
1279
2263
  } catch (error) {
1280
2264
  throw error;
@@ -1283,13 +2267,33 @@ var _delete10 = async (props) => {
1283
2267
  var bulk_create10 = async (props) => {
1284
2268
  try {
1285
2269
  const { sdk, data } = props;
1286
- const adapter = await sdk.adapter();
1287
- if (!adapter) throw new Error("Adapter not found");
1288
- const refunds2 = await adapter.refunds.bulk_create({
1289
- connector_config: sdk.options.configuration,
1290
- data
1291
- });
1292
- return refunds2;
2270
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2271
+ const created_refunds = [];
2272
+ for (const refund of data) {
2273
+ const offline_id = generate_offline_id("refund");
2274
+ const local_refund = {
2275
+ ...refund,
2276
+ id: offline_id,
2277
+ metadata: {
2278
+ ...refund.metadata,
2279
+ stall_offline_id: offline_id
2280
+ },
2281
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2282
+ stall_offline_id: offline_id,
2283
+ stall_offline_created_at: now,
2284
+ stall_offline_updated_at: now
2285
+ };
2286
+ await local_db.refunds.add(local_refund);
2287
+ await add_to_sync_queue({
2288
+ action: "create",
2289
+ table: "refunds",
2290
+ document_id: offline_id,
2291
+ stall_offline_id: offline_id,
2292
+ data: local_refund
2293
+ });
2294
+ created_refunds.push(local_refund);
2295
+ }
2296
+ return created_refunds;
1293
2297
  } catch (error) {
1294
2298
  throw error;
1295
2299
  }
@@ -1297,13 +2301,34 @@ var bulk_create10 = async (props) => {
1297
2301
  var bulk_update10 = async (props) => {
1298
2302
  try {
1299
2303
  const { sdk, data } = props;
1300
- const adapter = await sdk.adapter();
1301
- if (!adapter) throw new Error("Adapter not found");
1302
- const refunds2 = await adapter.refunds.bulk_update({
1303
- connector_config: sdk.options.configuration,
1304
- data
1305
- });
1306
- return refunds2;
2304
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2305
+ const updated_refunds = [];
2306
+ for (const item of data) {
2307
+ const existing = await local_db.refunds.get(item.id);
2308
+ if (!existing) {
2309
+ console.warn(`Refund with id ${item.id} not found locally, skipping`);
2310
+ continue;
2311
+ }
2312
+ const updated_refund = {
2313
+ ...existing,
2314
+ ...item.data,
2315
+ id: existing.id,
2316
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2317
+ stall_offline_id: existing.stall_offline_id,
2318
+ stall_offline_updated_at: now
2319
+ };
2320
+ await local_db.refunds.put(updated_refund);
2321
+ await add_to_sync_queue({
2322
+ action: "update",
2323
+ table: "refunds",
2324
+ document_id: item.id,
2325
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2326
+ stall_offline_id: existing.stall_offline_id,
2327
+ data: updated_refund
2328
+ });
2329
+ updated_refunds.push(updated_refund);
2330
+ }
2331
+ return updated_refunds;
1307
2332
  } catch (error) {
1308
2333
  throw error;
1309
2334
  }
@@ -1311,12 +2336,22 @@ var bulk_update10 = async (props) => {
1311
2336
  var bulk_delete10 = async (props) => {
1312
2337
  try {
1313
2338
  const { sdk, ids } = props;
1314
- const adapter = await sdk.adapter();
1315
- if (!adapter) throw new Error("Adapter not found");
1316
- await adapter.refunds.bulk_delete({
1317
- connector_config: sdk.options.configuration,
1318
- ids
1319
- });
2339
+ for (const id of ids) {
2340
+ const existing = await local_db.refunds.get(id);
2341
+ if (!existing) {
2342
+ console.warn(`Refund with id ${id} not found locally, skipping`);
2343
+ continue;
2344
+ }
2345
+ await add_to_sync_queue({
2346
+ action: "delete",
2347
+ table: "refunds",
2348
+ document_id: id,
2349
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2350
+ stall_offline_id: existing.stall_offline_id,
2351
+ data: { id }
2352
+ });
2353
+ await local_db.refunds.delete(id);
2354
+ }
1320
2355
  return;
1321
2356
  } catch (error) {
1322
2357
  throw error;
@@ -1339,11 +2374,15 @@ var list11 = async (props) => {
1339
2374
  const { sdk, query } = props;
1340
2375
  const adapter = await sdk.adapter();
1341
2376
  if (!adapter) throw new Error("Adapter not found");
1342
- const providers = await adapter.payment_providers.list({
2377
+ const payment_providers2 = await adapter.payment_providers.list({
1343
2378
  connector_config: sdk.options.configuration,
1344
2379
  query
1345
2380
  });
1346
- return providers;
2381
+ await save_bulk_data({
2382
+ table: "payment_providers",
2383
+ data: payment_providers2
2384
+ });
2385
+ return payment_providers2;
1347
2386
  } catch (error) {
1348
2387
  throw error;
1349
2388
  }
@@ -1353,11 +2392,12 @@ var retrieve11 = async (props) => {
1353
2392
  const { sdk, id } = props;
1354
2393
  const adapter = await sdk.adapter();
1355
2394
  if (!adapter) throw new Error("Adapter not found");
1356
- const provider = await adapter.payment_providers.retrieve({
2395
+ const payment_provider = await adapter.payment_providers.retrieve({
1357
2396
  connector_config: sdk.options.configuration,
1358
2397
  id
1359
2398
  });
1360
- return provider;
2399
+ await local_db.payment_providers.put(payment_provider);
2400
+ return payment_provider;
1361
2401
  } catch (error) {
1362
2402
  throw error;
1363
2403
  }
@@ -1365,13 +2405,30 @@ var retrieve11 = async (props) => {
1365
2405
  var create11 = async (props) => {
1366
2406
  try {
1367
2407
  const { sdk, data } = props;
1368
- const adapter = await sdk.adapter();
1369
- if (!adapter) throw new Error("Adapter not found");
1370
- const provider = await adapter.payment_providers.create({
1371
- connector_config: sdk.options.configuration,
1372
- data
1373
- });
1374
- return provider;
2408
+ const offline_id = generate_offline_id("payment_provider");
2409
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2410
+ const local_payment_provider = {
2411
+ ...data,
2412
+ id: offline_id,
2413
+ metadata: {
2414
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2415
+ ...data.metadata,
2416
+ stall_offline_id: offline_id
2417
+ },
2418
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2419
+ stall_offline_id: offline_id,
2420
+ stall_offline_created_at: now,
2421
+ stall_offline_updated_at: now
2422
+ };
2423
+ await local_db.payment_providers.add(local_payment_provider);
2424
+ await add_to_sync_queue({
2425
+ action: "create",
2426
+ table: "payment_providers",
2427
+ document_id: offline_id,
2428
+ stall_offline_id: offline_id,
2429
+ data: local_payment_provider
2430
+ });
2431
+ return local_payment_provider;
1375
2432
  } catch (error) {
1376
2433
  throw error;
1377
2434
  }
@@ -1379,14 +2436,29 @@ var create11 = async (props) => {
1379
2436
  var update11 = async (props) => {
1380
2437
  try {
1381
2438
  const { sdk, id, data } = props;
1382
- const adapter = await sdk.adapter();
1383
- if (!adapter) throw new Error("Adapter not found");
1384
- const provider = await adapter.payment_providers.update({
1385
- connector_config: sdk.options.configuration,
1386
- id,
1387
- data
1388
- });
1389
- return provider;
2439
+ const existing = await local_db.payment_providers.get(id);
2440
+ if (!existing) {
2441
+ throw new Error(`Payment provider with id ${id} not found locally`);
2442
+ }
2443
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2444
+ const updated_payment_provider = {
2445
+ ...existing,
2446
+ ...data,
2447
+ id: existing.id,
2448
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2449
+ stall_offline_id: existing.stall_offline_id,
2450
+ stall_offline_updated_at: now
2451
+ };
2452
+ await local_db.payment_providers.put(updated_payment_provider);
2453
+ await add_to_sync_queue({
2454
+ action: "update",
2455
+ table: "payment_providers",
2456
+ document_id: id,
2457
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2458
+ stall_offline_id: existing.stall_offline_id,
2459
+ data: updated_payment_provider
2460
+ });
2461
+ return updated_payment_provider;
1390
2462
  } catch (error) {
1391
2463
  throw error;
1392
2464
  }
@@ -1394,12 +2466,19 @@ var update11 = async (props) => {
1394
2466
  var _delete11 = async (props) => {
1395
2467
  try {
1396
2468
  const { sdk, id } = props;
1397
- const adapter = await sdk.adapter();
1398
- if (!adapter) throw new Error("Adapter not found");
1399
- await adapter.payment_providers.delete({
1400
- connector_config: sdk.options.configuration,
1401
- id
1402
- });
2469
+ const existing = await local_db.payment_providers.get(id);
2470
+ if (!existing) {
2471
+ throw new Error(`Payment provider with id ${id} not found locally`);
2472
+ }
2473
+ await add_to_sync_queue({
2474
+ action: "delete",
2475
+ table: "payment_providers",
2476
+ document_id: id,
2477
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2478
+ stall_offline_id: existing.stall_offline_id,
2479
+ data: { id }
2480
+ });
2481
+ await local_db.payment_providers.delete(id);
1403
2482
  return;
1404
2483
  } catch (error) {
1405
2484
  throw error;
@@ -1408,13 +2487,34 @@ var _delete11 = async (props) => {
1408
2487
  var bulk_create11 = async (props) => {
1409
2488
  try {
1410
2489
  const { sdk, data } = props;
1411
- const adapter = await sdk.adapter();
1412
- if (!adapter) throw new Error("Adapter not found");
1413
- const providers = await adapter.payment_providers.bulk_create({
1414
- connector_config: sdk.options.configuration,
1415
- data
1416
- });
1417
- return providers;
2490
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2491
+ const created_payment_providers = [];
2492
+ for (const payment_provider of data) {
2493
+ const offline_id = generate_offline_id("payment_provider");
2494
+ const local_payment_provider = {
2495
+ ...payment_provider,
2496
+ id: offline_id,
2497
+ metadata: {
2498
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2499
+ ...payment_provider.metadata,
2500
+ stall_offline_id: offline_id
2501
+ },
2502
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2503
+ stall_offline_id: offline_id,
2504
+ stall_offline_created_at: now,
2505
+ stall_offline_updated_at: now
2506
+ };
2507
+ await local_db.payment_providers.add(local_payment_provider);
2508
+ await add_to_sync_queue({
2509
+ action: "create",
2510
+ table: "payment_providers",
2511
+ document_id: offline_id,
2512
+ stall_offline_id: offline_id,
2513
+ data: local_payment_provider
2514
+ });
2515
+ created_payment_providers.push(local_payment_provider);
2516
+ }
2517
+ return created_payment_providers;
1418
2518
  } catch (error) {
1419
2519
  throw error;
1420
2520
  }
@@ -1422,13 +2522,36 @@ var bulk_create11 = async (props) => {
1422
2522
  var bulk_update11 = async (props) => {
1423
2523
  try {
1424
2524
  const { sdk, data } = props;
1425
- const adapter = await sdk.adapter();
1426
- if (!adapter) throw new Error("Adapter not found");
1427
- const providers = await adapter.payment_providers.bulk_update({
1428
- connector_config: sdk.options.configuration,
1429
- data
1430
- });
1431
- return providers;
2525
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2526
+ const updated_payment_providers = [];
2527
+ for (const item of data) {
2528
+ const existing = await local_db.payment_providers.get(item.id);
2529
+ if (!existing) {
2530
+ console.warn(
2531
+ `Payment provider with id ${item.id} not found locally, skipping`
2532
+ );
2533
+ continue;
2534
+ }
2535
+ const updated_payment_provider = {
2536
+ ...existing,
2537
+ ...item.data,
2538
+ id: existing.id,
2539
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2540
+ stall_offline_id: existing.stall_offline_id,
2541
+ stall_offline_updated_at: now
2542
+ };
2543
+ await local_db.payment_providers.put(updated_payment_provider);
2544
+ await add_to_sync_queue({
2545
+ action: "update",
2546
+ table: "payment_providers",
2547
+ document_id: item.id,
2548
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2549
+ stall_offline_id: existing.stall_offline_id,
2550
+ data: updated_payment_provider
2551
+ });
2552
+ updated_payment_providers.push(updated_payment_provider);
2553
+ }
2554
+ return updated_payment_providers;
1432
2555
  } catch (error) {
1433
2556
  throw error;
1434
2557
  }
@@ -1436,12 +2559,24 @@ var bulk_update11 = async (props) => {
1436
2559
  var bulk_delete11 = async (props) => {
1437
2560
  try {
1438
2561
  const { sdk, ids } = props;
1439
- const adapter = await sdk.adapter();
1440
- if (!adapter) throw new Error("Adapter not found");
1441
- await adapter.payment_providers.bulk_delete({
1442
- connector_config: sdk.options.configuration,
1443
- ids
1444
- });
2562
+ for (const id of ids) {
2563
+ const existing = await local_db.payment_providers.get(id);
2564
+ if (!existing) {
2565
+ console.warn(
2566
+ `Payment provider with id ${id} not found locally, skipping`
2567
+ );
2568
+ continue;
2569
+ }
2570
+ await add_to_sync_queue({
2571
+ action: "delete",
2572
+ table: "payment_providers",
2573
+ document_id: id,
2574
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2575
+ stall_offline_id: existing.stall_offline_id,
2576
+ data: { id }
2577
+ });
2578
+ await local_db.payment_providers.delete(id);
2579
+ }
1445
2580
  return;
1446
2581
  } catch (error) {
1447
2582
  throw error;
@@ -1468,6 +2603,10 @@ var list12 = async (props) => {
1468
2603
  connector_config: sdk.options.configuration,
1469
2604
  query
1470
2605
  });
2606
+ await save_bulk_data({
2607
+ table: "payments",
2608
+ data: payments2
2609
+ });
1471
2610
  return payments2;
1472
2611
  } catch (error) {
1473
2612
  throw error;
@@ -1482,6 +2621,7 @@ var retrieve12 = async (props) => {
1482
2621
  connector_config: sdk.options.configuration,
1483
2622
  id
1484
2623
  });
2624
+ await local_db.payments.put(payment);
1485
2625
  return payment;
1486
2626
  } catch (error) {
1487
2627
  throw error;
@@ -1490,13 +2630,29 @@ var retrieve12 = async (props) => {
1490
2630
  var create12 = async (props) => {
1491
2631
  try {
1492
2632
  const { sdk, data } = props;
1493
- const adapter = await sdk.adapter();
1494
- if (!adapter) throw new Error("Adapter not found");
1495
- const payment = await adapter.payments.create({
1496
- connector_config: sdk.options.configuration,
1497
- data
1498
- });
1499
- return payment;
2633
+ const offline_id = generate_offline_id("payment");
2634
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2635
+ const local_payment = {
2636
+ ...data,
2637
+ id: offline_id,
2638
+ metadata: {
2639
+ ...data.metadata,
2640
+ stall_offline_id: offline_id
2641
+ },
2642
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2643
+ stall_offline_id: offline_id,
2644
+ stall_offline_created_at: now,
2645
+ stall_offline_updated_at: now
2646
+ };
2647
+ await local_db.payments.add(local_payment);
2648
+ await add_to_sync_queue({
2649
+ action: "create",
2650
+ table: "payments",
2651
+ document_id: offline_id,
2652
+ stall_offline_id: offline_id,
2653
+ data: local_payment
2654
+ });
2655
+ return local_payment;
1500
2656
  } catch (error) {
1501
2657
  throw error;
1502
2658
  }
@@ -1504,14 +2660,29 @@ var create12 = async (props) => {
1504
2660
  var update12 = async (props) => {
1505
2661
  try {
1506
2662
  const { sdk, id, data } = props;
1507
- const adapter = await sdk.adapter();
1508
- if (!adapter) throw new Error("Adapter not found");
1509
- const payment = await adapter.payments.update({
1510
- connector_config: sdk.options.configuration,
1511
- id,
1512
- data
1513
- });
1514
- return payment;
2663
+ const existing = await local_db.payments.get(id);
2664
+ if (!existing) {
2665
+ throw new Error(`Payment with id ${id} not found locally`);
2666
+ }
2667
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2668
+ const updated_payment = {
2669
+ ...existing,
2670
+ ...data,
2671
+ id: existing.id,
2672
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2673
+ stall_offline_id: existing.stall_offline_id,
2674
+ stall_offline_updated_at: now
2675
+ };
2676
+ await local_db.payments.put(updated_payment);
2677
+ await add_to_sync_queue({
2678
+ action: "update",
2679
+ table: "payments",
2680
+ document_id: id,
2681
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2682
+ stall_offline_id: existing.stall_offline_id,
2683
+ data: updated_payment
2684
+ });
2685
+ return updated_payment;
1515
2686
  } catch (error) {
1516
2687
  throw error;
1517
2688
  }
@@ -1519,12 +2690,19 @@ var update12 = async (props) => {
1519
2690
  var _delete12 = async (props) => {
1520
2691
  try {
1521
2692
  const { sdk, id } = props;
1522
- const adapter = await sdk.adapter();
1523
- if (!adapter) throw new Error("Adapter not found");
1524
- await adapter.payments.delete({
1525
- connector_config: sdk.options.configuration,
1526
- id
1527
- });
2693
+ const existing = await local_db.payments.get(id);
2694
+ if (!existing) {
2695
+ throw new Error(`Payment with id ${id} not found locally`);
2696
+ }
2697
+ await add_to_sync_queue({
2698
+ action: "delete",
2699
+ table: "payments",
2700
+ document_id: id,
2701
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2702
+ stall_offline_id: existing.stall_offline_id,
2703
+ data: { id }
2704
+ });
2705
+ await local_db.payments.delete(id);
1528
2706
  return;
1529
2707
  } catch (error) {
1530
2708
  throw error;
@@ -1533,13 +2711,33 @@ var _delete12 = async (props) => {
1533
2711
  var bulk_create12 = async (props) => {
1534
2712
  try {
1535
2713
  const { sdk, data } = props;
1536
- const adapter = await sdk.adapter();
1537
- if (!adapter) throw new Error("Adapter not found");
1538
- const payments2 = await adapter.payments.bulk_create({
1539
- connector_config: sdk.options.configuration,
1540
- data
1541
- });
1542
- return payments2;
2714
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2715
+ const created_payments = [];
2716
+ for (const payment of data) {
2717
+ const offline_id = generate_offline_id("payment");
2718
+ const local_payment = {
2719
+ ...payment,
2720
+ id: offline_id,
2721
+ metadata: {
2722
+ ...payment.metadata,
2723
+ stall_offline_id: offline_id
2724
+ },
2725
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2726
+ stall_offline_id: offline_id,
2727
+ stall_offline_created_at: now,
2728
+ stall_offline_updated_at: now
2729
+ };
2730
+ await local_db.payments.add(local_payment);
2731
+ await add_to_sync_queue({
2732
+ action: "create",
2733
+ table: "payments",
2734
+ document_id: offline_id,
2735
+ stall_offline_id: offline_id,
2736
+ data: local_payment
2737
+ });
2738
+ created_payments.push(local_payment);
2739
+ }
2740
+ return created_payments;
1543
2741
  } catch (error) {
1544
2742
  throw error;
1545
2743
  }
@@ -1547,13 +2745,34 @@ var bulk_create12 = async (props) => {
1547
2745
  var bulk_update12 = async (props) => {
1548
2746
  try {
1549
2747
  const { sdk, data } = props;
1550
- const adapter = await sdk.adapter();
1551
- if (!adapter) throw new Error("Adapter not found");
1552
- const payments2 = await adapter.payments.bulk_update({
1553
- connector_config: sdk.options.configuration,
1554
- data
1555
- });
1556
- return payments2;
2748
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2749
+ const updated_payments = [];
2750
+ for (const item of data) {
2751
+ const existing = await local_db.payments.get(item.id);
2752
+ if (!existing) {
2753
+ console.warn(`Payment with id ${item.id} not found locally, skipping`);
2754
+ continue;
2755
+ }
2756
+ const updated_payment = {
2757
+ ...existing,
2758
+ ...item.data,
2759
+ id: existing.id,
2760
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2761
+ stall_offline_id: existing.stall_offline_id,
2762
+ stall_offline_updated_at: now
2763
+ };
2764
+ await local_db.payments.put(updated_payment);
2765
+ await add_to_sync_queue({
2766
+ action: "update",
2767
+ table: "payments",
2768
+ document_id: item.id,
2769
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2770
+ stall_offline_id: existing.stall_offline_id,
2771
+ data: updated_payment
2772
+ });
2773
+ updated_payments.push(updated_payment);
2774
+ }
2775
+ return updated_payments;
1557
2776
  } catch (error) {
1558
2777
  throw error;
1559
2778
  }
@@ -1561,12 +2780,22 @@ var bulk_update12 = async (props) => {
1561
2780
  var bulk_delete12 = async (props) => {
1562
2781
  try {
1563
2782
  const { sdk, ids } = props;
1564
- const adapter = await sdk.adapter();
1565
- if (!adapter) throw new Error("Adapter not found");
1566
- await adapter.payments.bulk_delete({
1567
- connector_config: sdk.options.configuration,
1568
- ids
1569
- });
2783
+ for (const id of ids) {
2784
+ const existing = await local_db.payments.get(id);
2785
+ if (!existing) {
2786
+ console.warn(`Payment with id ${id} not found locally, skipping`);
2787
+ continue;
2788
+ }
2789
+ await add_to_sync_queue({
2790
+ action: "delete",
2791
+ table: "payments",
2792
+ document_id: id,
2793
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2794
+ stall_offline_id: existing.stall_offline_id,
2795
+ data: { id }
2796
+ });
2797
+ await local_db.payments.delete(id);
2798
+ }
1570
2799
  return;
1571
2800
  } catch (error) {
1572
2801
  throw error;
@@ -1593,6 +2822,10 @@ var list13 = async (props) => {
1593
2822
  connector_config: sdk.options.configuration,
1594
2823
  query
1595
2824
  });
2825
+ await save_bulk_data({
2826
+ table: "tax_regions",
2827
+ data: regions
2828
+ });
1596
2829
  return regions;
1597
2830
  } catch (error) {
1598
2831
  throw error;
@@ -1607,6 +2840,7 @@ var retrieve13 = async (props) => {
1607
2840
  connector_config: sdk.options.configuration,
1608
2841
  id
1609
2842
  });
2843
+ await local_db.tax_regions.put(region);
1610
2844
  return region;
1611
2845
  } catch (error) {
1612
2846
  throw error;
@@ -1615,13 +2849,28 @@ var retrieve13 = async (props) => {
1615
2849
  var create13 = async (props) => {
1616
2850
  try {
1617
2851
  const { sdk, data } = props;
1618
- const adapter = await sdk.adapter();
1619
- if (!adapter) throw new Error("Adapter not found");
1620
- const region = await adapter.tax_regions.create({
1621
- connector_config: sdk.options.configuration,
1622
- data
1623
- });
1624
- return region;
2852
+ const offline_id = generate_offline_id("tax_region");
2853
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2854
+ const local_region = {
2855
+ ...data,
2856
+ id: offline_id,
2857
+ metadata: {
2858
+ ...data.metadata,
2859
+ stall_offline_id: offline_id
2860
+ },
2861
+ stall_offline_id: offline_id,
2862
+ stall_offline_created_at: now,
2863
+ stall_offline_updated_at: now
2864
+ };
2865
+ await local_db.tax_regions.add(local_region);
2866
+ await add_to_sync_queue({
2867
+ action: "create",
2868
+ table: "tax_regions",
2869
+ document_id: offline_id,
2870
+ stall_offline_id: offline_id,
2871
+ data: local_region
2872
+ });
2873
+ return local_region;
1625
2874
  } catch (error) {
1626
2875
  throw error;
1627
2876
  }
@@ -1629,14 +2878,29 @@ var create13 = async (props) => {
1629
2878
  var update13 = async (props) => {
1630
2879
  try {
1631
2880
  const { sdk, id, data } = props;
1632
- const adapter = await sdk.adapter();
1633
- if (!adapter) throw new Error("Adapter not found");
1634
- const region = await adapter.tax_regions.update({
1635
- connector_config: sdk.options.configuration,
1636
- id,
1637
- data
1638
- });
1639
- return region;
2881
+ const existing = await local_db.tax_regions.get(id);
2882
+ if (!existing) {
2883
+ throw new Error(`Tax region with id ${id} not found locally`);
2884
+ }
2885
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2886
+ const updated_region = {
2887
+ ...existing,
2888
+ ...data,
2889
+ id: existing.id,
2890
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2891
+ stall_offline_id: existing.stall_offline_id,
2892
+ stall_offline_updated_at: now
2893
+ };
2894
+ await local_db.tax_regions.put(updated_region);
2895
+ await add_to_sync_queue({
2896
+ action: "update",
2897
+ table: "tax_regions",
2898
+ document_id: id,
2899
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2900
+ stall_offline_id: existing.stall_offline_id,
2901
+ data: updated_region
2902
+ });
2903
+ return updated_region;
1640
2904
  } catch (error) {
1641
2905
  throw error;
1642
2906
  }
@@ -1644,12 +2908,19 @@ var update13 = async (props) => {
1644
2908
  var _delete13 = async (props) => {
1645
2909
  try {
1646
2910
  const { sdk, id } = props;
1647
- const adapter = await sdk.adapter();
1648
- if (!adapter) throw new Error("Adapter not found");
1649
- await adapter.tax_regions.delete({
1650
- connector_config: sdk.options.configuration,
1651
- id
1652
- });
2911
+ const existing = await local_db.tax_regions.get(id);
2912
+ if (!existing) {
2913
+ throw new Error(`Tax region with id ${id} not found locally`);
2914
+ }
2915
+ await add_to_sync_queue({
2916
+ action: "delete",
2917
+ table: "tax_regions",
2918
+ document_id: id,
2919
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2920
+ stall_offline_id: existing.stall_offline_id,
2921
+ data: { id }
2922
+ });
2923
+ await local_db.tax_regions.delete(id);
1653
2924
  return;
1654
2925
  } catch (error) {
1655
2926
  throw error;
@@ -1658,13 +2929,32 @@ var _delete13 = async (props) => {
1658
2929
  var bulk_create13 = async (props) => {
1659
2930
  try {
1660
2931
  const { sdk, data } = props;
1661
- const adapter = await sdk.adapter();
1662
- if (!adapter) throw new Error("Adapter not found");
1663
- const regions = await adapter.tax_regions.bulk_create({
1664
- connector_config: sdk.options.configuration,
1665
- data
1666
- });
1667
- return regions;
2932
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2933
+ const created_regions = [];
2934
+ for (const region of data) {
2935
+ const offline_id = generate_offline_id("tax_region");
2936
+ const local_region = {
2937
+ ...region,
2938
+ id: offline_id,
2939
+ metadata: {
2940
+ ...region.metadata,
2941
+ stall_offline_id: offline_id
2942
+ },
2943
+ stall_offline_id: offline_id,
2944
+ stall_offline_created_at: now,
2945
+ stall_offline_updated_at: now
2946
+ };
2947
+ await local_db.tax_regions.add(local_region);
2948
+ await add_to_sync_queue({
2949
+ action: "create",
2950
+ table: "tax_regions",
2951
+ document_id: offline_id,
2952
+ stall_offline_id: offline_id,
2953
+ data: local_region
2954
+ });
2955
+ created_regions.push(local_region);
2956
+ }
2957
+ return created_regions;
1668
2958
  } catch (error) {
1669
2959
  throw error;
1670
2960
  }
@@ -1672,13 +2962,36 @@ var bulk_create13 = async (props) => {
1672
2962
  var bulk_update13 = async (props) => {
1673
2963
  try {
1674
2964
  const { sdk, data } = props;
1675
- const adapter = await sdk.adapter();
1676
- if (!adapter) throw new Error("Adapter not found");
1677
- const regions = await adapter.tax_regions.bulk_update({
1678
- connector_config: sdk.options.configuration,
1679
- data
1680
- });
1681
- return regions;
2965
+ const now = (/* @__PURE__ */ new Date()).toISOString();
2966
+ const updated_regions = [];
2967
+ for (const item of data) {
2968
+ const existing = await local_db.tax_regions.get(item.id);
2969
+ if (!existing) {
2970
+ console.warn(
2971
+ `Tax region with id ${item.id} not found locally, skipping`
2972
+ );
2973
+ continue;
2974
+ }
2975
+ const updated_region = {
2976
+ ...existing,
2977
+ ...item.data,
2978
+ id: existing.id,
2979
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2980
+ stall_offline_id: existing.stall_offline_id,
2981
+ stall_offline_updated_at: now
2982
+ };
2983
+ await local_db.tax_regions.put(updated_region);
2984
+ await add_to_sync_queue({
2985
+ action: "update",
2986
+ table: "tax_regions",
2987
+ document_id: item.id,
2988
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2989
+ stall_offline_id: existing.stall_offline_id,
2990
+ data: updated_region
2991
+ });
2992
+ updated_regions.push(updated_region);
2993
+ }
2994
+ return updated_regions;
1682
2995
  } catch (error) {
1683
2996
  throw error;
1684
2997
  }
@@ -1686,12 +2999,22 @@ var bulk_update13 = async (props) => {
1686
2999
  var bulk_delete13 = async (props) => {
1687
3000
  try {
1688
3001
  const { sdk, ids } = props;
1689
- const adapter = await sdk.adapter();
1690
- if (!adapter) throw new Error("Adapter not found");
1691
- await adapter.tax_regions.bulk_delete({
1692
- connector_config: sdk.options.configuration,
1693
- ids
1694
- });
3002
+ for (const id of ids) {
3003
+ const existing = await local_db.tax_regions.get(id);
3004
+ if (!existing) {
3005
+ console.warn(`Tax region with id ${id} not found locally, skipping`);
3006
+ continue;
3007
+ }
3008
+ await add_to_sync_queue({
3009
+ action: "delete",
3010
+ table: "tax_regions",
3011
+ document_id: id,
3012
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3013
+ stall_offline_id: existing.stall_offline_id,
3014
+ data: { id }
3015
+ });
3016
+ await local_db.tax_regions.delete(id);
3017
+ }
1695
3018
  return;
1696
3019
  } catch (error) {
1697
3020
  throw error;
@@ -1718,6 +3041,10 @@ var list14 = async (props) => {
1718
3041
  connector_config: sdk.options.configuration,
1719
3042
  query
1720
3043
  });
3044
+ await save_bulk_data({
3045
+ table: "tax_rates",
3046
+ data: rates
3047
+ });
1721
3048
  return rates;
1722
3049
  } catch (error) {
1723
3050
  throw error;
@@ -1732,6 +3059,7 @@ var retrieve14 = async (props) => {
1732
3059
  connector_config: sdk.options.configuration,
1733
3060
  id
1734
3061
  });
3062
+ await local_db.tax_rates.put(rate);
1735
3063
  return rate;
1736
3064
  } catch (error) {
1737
3065
  throw error;
@@ -1740,13 +3068,28 @@ var retrieve14 = async (props) => {
1740
3068
  var create14 = async (props) => {
1741
3069
  try {
1742
3070
  const { sdk, data } = props;
1743
- const adapter = await sdk.adapter();
1744
- if (!adapter) throw new Error("Adapter not found");
1745
- const rate = await adapter.tax_rates.create({
1746
- connector_config: sdk.options.configuration,
1747
- data
1748
- });
1749
- return rate;
3071
+ const offline_id = generate_offline_id("tax_rate");
3072
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3073
+ const local_rate = {
3074
+ ...data,
3075
+ id: offline_id,
3076
+ metadata: {
3077
+ ...data.metadata,
3078
+ stall_offline_id: offline_id
3079
+ },
3080
+ stall_offline_id: offline_id,
3081
+ stall_offline_created_at: now,
3082
+ stall_offline_updated_at: now
3083
+ };
3084
+ await local_db.tax_rates.add(local_rate);
3085
+ await add_to_sync_queue({
3086
+ action: "create",
3087
+ table: "tax_rates",
3088
+ document_id: offline_id,
3089
+ stall_offline_id: offline_id,
3090
+ data: local_rate
3091
+ });
3092
+ return local_rate;
1750
3093
  } catch (error) {
1751
3094
  throw error;
1752
3095
  }
@@ -1754,14 +3097,29 @@ var create14 = async (props) => {
1754
3097
  var update14 = async (props) => {
1755
3098
  try {
1756
3099
  const { sdk, id, data } = props;
1757
- const adapter = await sdk.adapter();
1758
- if (!adapter) throw new Error("Adapter not found");
1759
- const rate = await adapter.tax_rates.update({
1760
- connector_config: sdk.options.configuration,
1761
- id,
1762
- data
1763
- });
1764
- return rate;
3100
+ const existing = await local_db.tax_rates.get(id);
3101
+ if (!existing) {
3102
+ throw new Error(`Tax rate with id ${id} not found locally`);
3103
+ }
3104
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3105
+ const updated_rate = {
3106
+ ...existing,
3107
+ ...data,
3108
+ id: existing.id,
3109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3110
+ stall_offline_id: existing.stall_offline_id,
3111
+ stall_offline_updated_at: now
3112
+ };
3113
+ await local_db.tax_rates.put(updated_rate);
3114
+ await add_to_sync_queue({
3115
+ action: "update",
3116
+ table: "tax_rates",
3117
+ document_id: id,
3118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3119
+ stall_offline_id: existing.stall_offline_id,
3120
+ data: updated_rate
3121
+ });
3122
+ return updated_rate;
1765
3123
  } catch (error) {
1766
3124
  throw error;
1767
3125
  }
@@ -1769,12 +3127,19 @@ var update14 = async (props) => {
1769
3127
  var _delete14 = async (props) => {
1770
3128
  try {
1771
3129
  const { sdk, id } = props;
1772
- const adapter = await sdk.adapter();
1773
- if (!adapter) throw new Error("Adapter not found");
1774
- await adapter.tax_rates.delete({
1775
- connector_config: sdk.options.configuration,
1776
- id
1777
- });
3130
+ const existing = await local_db.tax_rates.get(id);
3131
+ if (!existing) {
3132
+ throw new Error(`Tax rate with id ${id} not found locally`);
3133
+ }
3134
+ await add_to_sync_queue({
3135
+ action: "delete",
3136
+ table: "tax_rates",
3137
+ document_id: id,
3138
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3139
+ stall_offline_id: existing.stall_offline_id,
3140
+ data: { id }
3141
+ });
3142
+ await local_db.tax_rates.delete(id);
1778
3143
  return;
1779
3144
  } catch (error) {
1780
3145
  throw error;
@@ -1783,13 +3148,32 @@ var _delete14 = async (props) => {
1783
3148
  var bulk_create14 = async (props) => {
1784
3149
  try {
1785
3150
  const { sdk, data } = props;
1786
- const adapter = await sdk.adapter();
1787
- if (!adapter) throw new Error("Adapter not found");
1788
- const rates = await adapter.tax_rates.bulk_create({
1789
- connector_config: sdk.options.configuration,
1790
- data
1791
- });
1792
- return rates;
3151
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3152
+ const created_rates = [];
3153
+ for (const rate of data) {
3154
+ const offline_id = generate_offline_id("tax_rate");
3155
+ const local_rate = {
3156
+ ...rate,
3157
+ id: offline_id,
3158
+ metadata: {
3159
+ ...rate.metadata,
3160
+ stall_offline_id: offline_id
3161
+ },
3162
+ stall_offline_id: offline_id,
3163
+ stall_offline_created_at: now,
3164
+ stall_offline_updated_at: now
3165
+ };
3166
+ await local_db.tax_rates.add(local_rate);
3167
+ await add_to_sync_queue({
3168
+ action: "create",
3169
+ table: "tax_rates",
3170
+ document_id: offline_id,
3171
+ stall_offline_id: offline_id,
3172
+ data: local_rate
3173
+ });
3174
+ created_rates.push(local_rate);
3175
+ }
3176
+ return created_rates;
1793
3177
  } catch (error) {
1794
3178
  throw error;
1795
3179
  }
@@ -1797,13 +3181,34 @@ var bulk_create14 = async (props) => {
1797
3181
  var bulk_update14 = async (props) => {
1798
3182
  try {
1799
3183
  const { sdk, data } = props;
1800
- const adapter = await sdk.adapter();
1801
- if (!adapter) throw new Error("Adapter not found");
1802
- const rates = await adapter.tax_rates.bulk_update({
1803
- connector_config: sdk.options.configuration,
1804
- data
1805
- });
1806
- return rates;
3184
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3185
+ const updated_rates = [];
3186
+ for (const item of data) {
3187
+ const existing = await local_db.tax_rates.get(item.id);
3188
+ if (!existing) {
3189
+ console.warn(`Tax rate with id ${item.id} not found locally, skipping`);
3190
+ continue;
3191
+ }
3192
+ const updated_rate = {
3193
+ ...existing,
3194
+ ...item.data,
3195
+ id: existing.id,
3196
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3197
+ stall_offline_id: existing.stall_offline_id,
3198
+ stall_offline_updated_at: now
3199
+ };
3200
+ await local_db.tax_rates.put(updated_rate);
3201
+ await add_to_sync_queue({
3202
+ action: "update",
3203
+ table: "tax_rates",
3204
+ document_id: item.id,
3205
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3206
+ stall_offline_id: existing.stall_offline_id,
3207
+ data: updated_rate
3208
+ });
3209
+ updated_rates.push(updated_rate);
3210
+ }
3211
+ return updated_rates;
1807
3212
  } catch (error) {
1808
3213
  throw error;
1809
3214
  }
@@ -1811,12 +3216,22 @@ var bulk_update14 = async (props) => {
1811
3216
  var bulk_delete14 = async (props) => {
1812
3217
  try {
1813
3218
  const { sdk, ids } = props;
1814
- const adapter = await sdk.adapter();
1815
- if (!adapter) throw new Error("Adapter not found");
1816
- await adapter.tax_rates.bulk_delete({
1817
- connector_config: sdk.options.configuration,
1818
- ids
1819
- });
3219
+ for (const id of ids) {
3220
+ const existing = await local_db.tax_rates.get(id);
3221
+ if (!existing) {
3222
+ console.warn(`Tax rate with id ${id} not found locally, skipping`);
3223
+ continue;
3224
+ }
3225
+ await add_to_sync_queue({
3226
+ action: "delete",
3227
+ table: "tax_rates",
3228
+ document_id: id,
3229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3230
+ stall_offline_id: existing.stall_offline_id,
3231
+ data: { id }
3232
+ });
3233
+ await local_db.tax_rates.delete(id);
3234
+ }
1820
3235
  return;
1821
3236
  } catch (error) {
1822
3237
  throw error;
@@ -1843,6 +3258,10 @@ var list15 = async (props) => {
1843
3258
  connector_config: sdk.options.configuration,
1844
3259
  query
1845
3260
  });
3261
+ await save_bulk_data({
3262
+ table: "locations",
3263
+ data: locations2
3264
+ });
1846
3265
  return locations2;
1847
3266
  } catch (error) {
1848
3267
  throw error;
@@ -1857,6 +3276,7 @@ var retrieve15 = async (props) => {
1857
3276
  connector_config: sdk.options.configuration,
1858
3277
  id
1859
3278
  });
3279
+ await local_db.locations.put(location);
1860
3280
  return location;
1861
3281
  } catch (error) {
1862
3282
  throw error;
@@ -1865,13 +3285,29 @@ var retrieve15 = async (props) => {
1865
3285
  var create15 = async (props) => {
1866
3286
  try {
1867
3287
  const { sdk, data } = props;
1868
- const adapter = await sdk.adapter();
1869
- if (!adapter) throw new Error("Adapter not found");
1870
- const location = await adapter.locations.create({
1871
- connector_config: sdk.options.configuration,
1872
- data
1873
- });
1874
- return location;
3288
+ const offline_id = generate_offline_id("location");
3289
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3290
+ const local_location = {
3291
+ ...data,
3292
+ id: offline_id,
3293
+ metadata: {
3294
+ ...data.metadata,
3295
+ stall_offline_id: offline_id
3296
+ },
3297
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3298
+ stall_offline_id: offline_id,
3299
+ stall_offline_created_at: now,
3300
+ stall_offline_updated_at: now
3301
+ };
3302
+ await local_db.locations.add(local_location);
3303
+ await add_to_sync_queue({
3304
+ action: "create",
3305
+ table: "locations",
3306
+ document_id: offline_id,
3307
+ stall_offline_id: offline_id,
3308
+ data: local_location
3309
+ });
3310
+ return local_location;
1875
3311
  } catch (error) {
1876
3312
  throw error;
1877
3313
  }
@@ -1879,14 +3315,29 @@ var create15 = async (props) => {
1879
3315
  var update15 = async (props) => {
1880
3316
  try {
1881
3317
  const { sdk, id, data } = props;
1882
- const adapter = await sdk.adapter();
1883
- if (!adapter) throw new Error("Adapter not found");
1884
- const location = await adapter.locations.update({
1885
- connector_config: sdk.options.configuration,
1886
- id,
1887
- data
1888
- });
1889
- return location;
3318
+ const existing = await local_db.locations.get(id);
3319
+ if (!existing) {
3320
+ throw new Error(`Location with id ${id} not found locally`);
3321
+ }
3322
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3323
+ const updated_location = {
3324
+ ...existing,
3325
+ ...data,
3326
+ id: existing.id,
3327
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3328
+ stall_offline_id: existing.stall_offline_id,
3329
+ stall_offline_updated_at: now
3330
+ };
3331
+ await local_db.locations.put(updated_location);
3332
+ await add_to_sync_queue({
3333
+ action: "update",
3334
+ table: "locations",
3335
+ document_id: id,
3336
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3337
+ stall_offline_id: existing.stall_offline_id,
3338
+ data: updated_location
3339
+ });
3340
+ return updated_location;
1890
3341
  } catch (error) {
1891
3342
  throw error;
1892
3343
  }
@@ -1894,12 +3345,19 @@ var update15 = async (props) => {
1894
3345
  var _delete15 = async (props) => {
1895
3346
  try {
1896
3347
  const { sdk, id } = props;
1897
- const adapter = await sdk.adapter();
1898
- if (!adapter) throw new Error("Adapter not found");
1899
- await adapter.locations.delete({
1900
- connector_config: sdk.options.configuration,
1901
- id
1902
- });
3348
+ const existing = await local_db.locations.get(id);
3349
+ if (!existing) {
3350
+ throw new Error(`Location with id ${id} not found locally`);
3351
+ }
3352
+ await add_to_sync_queue({
3353
+ action: "delete",
3354
+ table: "locations",
3355
+ document_id: id,
3356
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3357
+ stall_offline_id: existing.stall_offline_id,
3358
+ data: { id }
3359
+ });
3360
+ await local_db.locations.delete(id);
1903
3361
  return;
1904
3362
  } catch (error) {
1905
3363
  throw error;
@@ -1908,13 +3366,33 @@ var _delete15 = async (props) => {
1908
3366
  var bulk_create15 = async (props) => {
1909
3367
  try {
1910
3368
  const { sdk, data } = props;
1911
- const adapter = await sdk.adapter();
1912
- if (!adapter) throw new Error("Adapter not found");
1913
- const locations2 = await adapter.locations.bulk_create({
1914
- connector_config: sdk.options.configuration,
1915
- data
1916
- });
1917
- return locations2;
3369
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3370
+ const created_locations = [];
3371
+ for (const location of data) {
3372
+ const offline_id = generate_offline_id("location");
3373
+ const local_location = {
3374
+ ...location,
3375
+ id: offline_id,
3376
+ metadata: {
3377
+ ...location.metadata,
3378
+ stall_offline_id: offline_id
3379
+ },
3380
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3381
+ stall_offline_id: offline_id,
3382
+ stall_offline_created_at: now,
3383
+ stall_offline_updated_at: now
3384
+ };
3385
+ await local_db.locations.add(local_location);
3386
+ await add_to_sync_queue({
3387
+ action: "create",
3388
+ table: "locations",
3389
+ document_id: offline_id,
3390
+ stall_offline_id: offline_id,
3391
+ data: local_location
3392
+ });
3393
+ created_locations.push(local_location);
3394
+ }
3395
+ return created_locations;
1918
3396
  } catch (error) {
1919
3397
  throw error;
1920
3398
  }
@@ -1922,13 +3400,34 @@ var bulk_create15 = async (props) => {
1922
3400
  var bulk_update15 = async (props) => {
1923
3401
  try {
1924
3402
  const { sdk, data } = props;
1925
- const adapter = await sdk.adapter();
1926
- if (!adapter) throw new Error("Adapter not found");
1927
- const locations2 = await adapter.locations.bulk_update({
1928
- connector_config: sdk.options.configuration,
1929
- data
1930
- });
1931
- return locations2;
3403
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3404
+ const updated_locations = [];
3405
+ for (const item of data) {
3406
+ const existing = await local_db.locations.get(item.id);
3407
+ if (!existing) {
3408
+ console.warn(`Location with id ${item.id} not found locally, skipping`);
3409
+ continue;
3410
+ }
3411
+ const updated_location = {
3412
+ ...existing,
3413
+ ...item.data,
3414
+ id: existing.id,
3415
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3416
+ stall_offline_id: existing.stall_offline_id,
3417
+ stall_offline_updated_at: now
3418
+ };
3419
+ await local_db.locations.put(updated_location);
3420
+ await add_to_sync_queue({
3421
+ action: "update",
3422
+ table: "locations",
3423
+ document_id: item.id,
3424
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3425
+ stall_offline_id: existing.stall_offline_id,
3426
+ data: updated_location
3427
+ });
3428
+ updated_locations.push(updated_location);
3429
+ }
3430
+ return updated_locations;
1932
3431
  } catch (error) {
1933
3432
  throw error;
1934
3433
  }
@@ -1936,12 +3435,22 @@ var bulk_update15 = async (props) => {
1936
3435
  var bulk_delete15 = async (props) => {
1937
3436
  try {
1938
3437
  const { sdk, ids } = props;
1939
- const adapter = await sdk.adapter();
1940
- if (!adapter) throw new Error("Adapter not found");
1941
- await adapter.locations.bulk_delete({
1942
- connector_config: sdk.options.configuration,
1943
- ids
1944
- });
3438
+ for (const id of ids) {
3439
+ const existing = await local_db.locations.get(id);
3440
+ if (!existing) {
3441
+ console.warn(`Location with id ${id} not found locally, skipping`);
3442
+ continue;
3443
+ }
3444
+ await add_to_sync_queue({
3445
+ action: "delete",
3446
+ table: "locations",
3447
+ document_id: id,
3448
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3449
+ stall_offline_id: existing.stall_offline_id,
3450
+ data: { id }
3451
+ });
3452
+ await local_db.locations.delete(id);
3453
+ }
1945
3454
  return;
1946
3455
  } catch (error) {
1947
3456
  throw error;
@@ -1968,6 +3477,10 @@ var list16 = async (props) => {
1968
3477
  connector_config: sdk.options.configuration,
1969
3478
  query
1970
3479
  });
3480
+ await save_bulk_data({
3481
+ table: "fulfillments",
3482
+ data: fulfillments2
3483
+ });
1971
3484
  return fulfillments2;
1972
3485
  } catch (error) {
1973
3486
  throw error;
@@ -1982,6 +3495,7 @@ var retrieve16 = async (props) => {
1982
3495
  connector_config: sdk.options.configuration,
1983
3496
  id
1984
3497
  });
3498
+ await local_db.fulfillments.put(fulfillment);
1985
3499
  return fulfillment;
1986
3500
  } catch (error) {
1987
3501
  throw error;
@@ -1990,13 +3504,29 @@ var retrieve16 = async (props) => {
1990
3504
  var create16 = async (props) => {
1991
3505
  try {
1992
3506
  const { sdk, data } = props;
1993
- const adapter = await sdk.adapter();
1994
- if (!adapter) throw new Error("Adapter not found");
1995
- const fulfillment = await adapter.fulfillments.create({
1996
- connector_config: sdk.options.configuration,
1997
- data
1998
- });
1999
- return fulfillment;
3507
+ const offline_id = generate_offline_id("fulfillment");
3508
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3509
+ const local_fulfillment = {
3510
+ ...data,
3511
+ id: offline_id,
3512
+ metadata: {
3513
+ ...data.metadata,
3514
+ stall_offline_id: offline_id
3515
+ },
3516
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3517
+ stall_offline_id: offline_id,
3518
+ stall_offline_created_at: now,
3519
+ stall_offline_updated_at: now
3520
+ };
3521
+ await local_db.fulfillments.add(local_fulfillment);
3522
+ await add_to_sync_queue({
3523
+ action: "create",
3524
+ table: "fulfillments",
3525
+ document_id: offline_id,
3526
+ stall_offline_id: offline_id,
3527
+ data: local_fulfillment
3528
+ });
3529
+ return local_fulfillment;
2000
3530
  } catch (error) {
2001
3531
  throw error;
2002
3532
  }
@@ -2004,14 +3534,29 @@ var create16 = async (props) => {
2004
3534
  var update16 = async (props) => {
2005
3535
  try {
2006
3536
  const { sdk, id, data } = props;
2007
- const adapter = await sdk.adapter();
2008
- if (!adapter) throw new Error("Adapter not found");
2009
- const fulfillment = await adapter.fulfillments.update({
2010
- connector_config: sdk.options.configuration,
2011
- id,
2012
- data
2013
- });
2014
- return fulfillment;
3537
+ const existing = await local_db.fulfillments.get(id);
3538
+ if (!existing) {
3539
+ throw new Error(`Fulfillment with id ${id} not found locally`);
3540
+ }
3541
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3542
+ const updated_fulfillment = {
3543
+ ...existing,
3544
+ ...data,
3545
+ id: existing.id,
3546
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3547
+ stall_offline_id: existing.stall_offline_id,
3548
+ stall_offline_updated_at: now
3549
+ };
3550
+ await local_db.fulfillments.put(updated_fulfillment);
3551
+ await add_to_sync_queue({
3552
+ action: "update",
3553
+ table: "fulfillments",
3554
+ document_id: id,
3555
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3556
+ stall_offline_id: existing.stall_offline_id,
3557
+ data: updated_fulfillment
3558
+ });
3559
+ return updated_fulfillment;
2015
3560
  } catch (error) {
2016
3561
  throw error;
2017
3562
  }
@@ -2019,12 +3564,19 @@ var update16 = async (props) => {
2019
3564
  var _delete16 = async (props) => {
2020
3565
  try {
2021
3566
  const { sdk, id } = props;
2022
- const adapter = await sdk.adapter();
2023
- if (!adapter) throw new Error("Adapter not found");
2024
- await adapter.fulfillments.delete({
2025
- connector_config: sdk.options.configuration,
2026
- id
2027
- });
3567
+ const existing = await local_db.fulfillments.get(id);
3568
+ if (!existing) {
3569
+ throw new Error(`Fulfillment with id ${id} not found locally`);
3570
+ }
3571
+ await add_to_sync_queue({
3572
+ action: "delete",
3573
+ table: "fulfillments",
3574
+ document_id: id,
3575
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3576
+ stall_offline_id: existing.stall_offline_id,
3577
+ data: { id }
3578
+ });
3579
+ await local_db.fulfillments.delete(id);
2028
3580
  return;
2029
3581
  } catch (error) {
2030
3582
  throw error;
@@ -2033,13 +3585,33 @@ var _delete16 = async (props) => {
2033
3585
  var bulk_create16 = async (props) => {
2034
3586
  try {
2035
3587
  const { sdk, data } = props;
2036
- const adapter = await sdk.adapter();
2037
- if (!adapter) throw new Error("Adapter not found");
2038
- const fulfillments2 = await adapter.fulfillments.bulk_create({
2039
- connector_config: sdk.options.configuration,
2040
- data
2041
- });
2042
- return fulfillments2;
3588
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3589
+ const created_fulfillments = [];
3590
+ for (const fulfillment of data) {
3591
+ const offline_id = generate_offline_id("fulfillment");
3592
+ const local_fulfillment = {
3593
+ ...fulfillment,
3594
+ id: offline_id,
3595
+ metadata: {
3596
+ ...fulfillment.metadata,
3597
+ stall_offline_id: offline_id
3598
+ },
3599
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3600
+ stall_offline_id: offline_id,
3601
+ stall_offline_created_at: now,
3602
+ stall_offline_updated_at: now
3603
+ };
3604
+ await local_db.fulfillments.add(local_fulfillment);
3605
+ await add_to_sync_queue({
3606
+ action: "create",
3607
+ table: "fulfillments",
3608
+ document_id: offline_id,
3609
+ stall_offline_id: offline_id,
3610
+ data: local_fulfillment
3611
+ });
3612
+ created_fulfillments.push(local_fulfillment);
3613
+ }
3614
+ return created_fulfillments;
2043
3615
  } catch (error) {
2044
3616
  throw error;
2045
3617
  }
@@ -2047,13 +3619,36 @@ var bulk_create16 = async (props) => {
2047
3619
  var bulk_update16 = async (props) => {
2048
3620
  try {
2049
3621
  const { sdk, data } = props;
2050
- const adapter = await sdk.adapter();
2051
- if (!adapter) throw new Error("Adapter not found");
2052
- const fulfillments2 = await adapter.fulfillments.bulk_update({
2053
- connector_config: sdk.options.configuration,
2054
- data
2055
- });
2056
- return fulfillments2;
3622
+ const now = (/* @__PURE__ */ new Date()).toISOString();
3623
+ const updated_fulfillments = [];
3624
+ for (const item of data) {
3625
+ const existing = await local_db.fulfillments.get(item.id);
3626
+ if (!existing) {
3627
+ console.warn(
3628
+ `Fulfillment with id ${item.id} not found locally, skipping`
3629
+ );
3630
+ continue;
3631
+ }
3632
+ const updated_fulfillment = {
3633
+ ...existing,
3634
+ ...item.data,
3635
+ id: existing.id,
3636
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3637
+ stall_offline_id: existing.stall_offline_id,
3638
+ stall_offline_updated_at: now
3639
+ };
3640
+ await local_db.fulfillments.put(updated_fulfillment);
3641
+ await add_to_sync_queue({
3642
+ action: "update",
3643
+ table: "fulfillments",
3644
+ document_id: item.id,
3645
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3646
+ stall_offline_id: existing.stall_offline_id,
3647
+ data: updated_fulfillment
3648
+ });
3649
+ updated_fulfillments.push(updated_fulfillment);
3650
+ }
3651
+ return updated_fulfillments;
2057
3652
  } catch (error) {
2058
3653
  throw error;
2059
3654
  }
@@ -2061,12 +3656,22 @@ var bulk_update16 = async (props) => {
2061
3656
  var bulk_delete16 = async (props) => {
2062
3657
  try {
2063
3658
  const { sdk, ids } = props;
2064
- const adapter = await sdk.adapter();
2065
- if (!adapter) throw new Error("Adapter not found");
2066
- await adapter.fulfillments.bulk_delete({
2067
- connector_config: sdk.options.configuration,
2068
- ids
2069
- });
3659
+ for (const id of ids) {
3660
+ const existing = await local_db.fulfillments.get(id);
3661
+ if (!existing) {
3662
+ console.warn(`Fulfillment with id ${id} not found locally, skipping`);
3663
+ continue;
3664
+ }
3665
+ await add_to_sync_queue({
3666
+ action: "delete",
3667
+ table: "fulfillments",
3668
+ document_id: id,
3669
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3670
+ stall_offline_id: existing.stall_offline_id,
3671
+ data: { id }
3672
+ });
3673
+ await local_db.fulfillments.delete(id);
3674
+ }
2070
3675
  return;
2071
3676
  } catch (error) {
2072
3677
  throw error;
@@ -2082,13 +3687,429 @@ var fulfillments = {
2082
3687
  bulk_update: bulk_update16,
2083
3688
  bulk_delete: bulk_delete16
2084
3689
  };
3690
+
3691
+ // src/services/sync/sync.service.ts
3692
+ import { randomUUID as randomUUID2 } from "crypto";
3693
+
3694
+ // src/services/sync/sync-dependencies.ts
3695
+ var SYNC_DEPENDENCY_LAYERS = {
3696
+ 1: [
3697
+ "tax_regions",
3698
+ "tax_rates",
3699
+ "categories",
3700
+ "collections",
3701
+ "locations",
3702
+ "payment_providers",
3703
+ "customers",
3704
+ "promotions"
3705
+ ],
3706
+ 2: ["products"],
3707
+ 3: ["variants", "inventory_levels"],
3708
+ 4: ["orders", "order_notes"],
3709
+ 5: ["payments", "refunds", "fulfillments"]
3710
+ };
3711
+ var get_entity_dependencies = (table) => {
3712
+ const dependencies = {
3713
+ // Layer 1: Independent
3714
+ tax_regions: [],
3715
+ tax_rates: ["tax_regions"],
3716
+ categories: [],
3717
+ collections: [],
3718
+ locations: [],
3719
+ payment_providers: [],
3720
+ customers: [],
3721
+ promotions: [],
3722
+ // Layer 2: Product
3723
+ products: ["categories", "collections"],
3724
+ // Layer 3: Variants & Inventory
3725
+ variants: ["products"],
3726
+ inventory_levels: ["products", "variants"],
3727
+ inventory_history: ["products", "variants"],
3728
+ // Layer 4: Orders
3729
+ orders: ["customers", "products", "variants", "locations"],
3730
+ order_notes: ["orders"],
3731
+ // Layer 5: Order-related
3732
+ payments: ["orders", "payment_providers"],
3733
+ refunds: ["orders", "payments"],
3734
+ fulfillments: ["orders"],
3735
+ // Tags
3736
+ tags: ["products"],
3737
+ // Fulfillment config
3738
+ fulfillment_types: [],
3739
+ fulfillment_providers: []
3740
+ };
3741
+ return dependencies[table] || [];
3742
+ };
3743
+ var get_sync_layer = (table) => {
3744
+ for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
3745
+ if (tables.includes(table)) {
3746
+ return parseInt(layer);
3747
+ }
3748
+ }
3749
+ return 99;
3750
+ };
3751
+ var sort_by_dependency_order = (items) => {
3752
+ return items.sort((a, b) => {
3753
+ const layer_a = get_sync_layer(a.table);
3754
+ const layer_b = get_sync_layer(b.table);
3755
+ if (layer_a !== layer_b) {
3756
+ return layer_a - layer_b;
3757
+ }
3758
+ return 0;
3759
+ });
3760
+ };
3761
+ var are_dependencies_satisfied = (table, synced_tables) => {
3762
+ const dependencies = get_entity_dependencies(table);
3763
+ return dependencies.every((dep) => synced_tables.has(dep));
3764
+ };
3765
+
3766
+ // src/services/sync/sync.service.ts
3767
+ var uuid2 = () => randomUUID2();
3768
+ var MAX_RETRIES = 3;
3769
+ var replace_temporary_ids = async (props) => {
3770
+ const { table, stall_offline_id, connector_id, local_data } = props;
3771
+ try {
3772
+ const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
3773
+ if (existing) {
3774
+ await local_db[table].update(existing.id, {
3775
+ id: connector_id
3776
+ // Keep stall_offline_id for reference
3777
+ });
3778
+ }
3779
+ await update_dependent_references({
3780
+ table,
3781
+ old_id: stall_offline_id,
3782
+ new_id: connector_id
3783
+ });
3784
+ } catch (error) {
3785
+ console.error(`Error replacing temporary IDs for ${table}:`, error);
3786
+ throw error;
3787
+ }
3788
+ };
3789
+ var update_dependent_references = async (props) => {
3790
+ const { table, old_id, new_id } = props;
3791
+ try {
3792
+ const reference_map = {
3793
+ products: [
3794
+ { table: "variants", field: "product_id" },
3795
+ { table: "inventory_levels", field: "product_id" }
3796
+ ],
3797
+ variants: [{ table: "inventory_levels", field: "variant_id" }],
3798
+ customers: [{ table: "orders", field: "customer_id" }],
3799
+ orders: [
3800
+ { table: "payments", field: "order_id" },
3801
+ { table: "refunds", field: "order_id" },
3802
+ { table: "order_notes", field: "order_id" },
3803
+ { table: "fulfillments", field: "order_id" }
3804
+ ],
3805
+ payments: [{ table: "refunds", field: "payment_id" }],
3806
+ locations: [{ table: "orders", field: "location_id" }],
3807
+ categories: [{ table: "products", field: "category_id" }],
3808
+ collections: [{ table: "products", field: "collection_id" }],
3809
+ tax_regions: [{ table: "tax_rates", field: "region_id" }],
3810
+ tax_rates: [],
3811
+ tags: [],
3812
+ inventory_levels: [],
3813
+ inventory_history: [],
3814
+ promotions: [],
3815
+ order_notes: [],
3816
+ refunds: [],
3817
+ payment_providers: [],
3818
+ fulfillments: [],
3819
+ fulfillment_types: [],
3820
+ fulfillment_providers: []
3821
+ };
3822
+ const references = reference_map[table] || [];
3823
+ for (const ref of references) {
3824
+ const records = await local_db[ref.table].toArray();
3825
+ const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
3826
+ ...record,
3827
+ [ref.field]: new_id
3828
+ }));
3829
+ if (updates.length > 0) {
3830
+ await local_db[ref.table].bulkPut(updates);
3831
+ }
3832
+ }
3833
+ } catch (error) {
3834
+ console.error(`Error updating dependent references for ${table}:`, error);
3835
+ }
3836
+ };
3837
+ var sync_queue_item = async (props) => {
3838
+ const { sdk, item, sync_batch_id } = props;
3839
+ const start_time = Date.now();
3840
+ try {
3841
+ const adapter = await sdk.adapter();
3842
+ if (!adapter) {
3843
+ throw new Error("Adapter not found");
3844
+ }
3845
+ const connector_config = sdk.options.configuration;
3846
+ const table_module = adapter[item.table];
3847
+ if (!table_module) {
3848
+ throw new Error(`Module ${item.table} not found in adapter`);
3849
+ }
3850
+ let connector_id;
3851
+ if (item.action === "create") {
3852
+ const result = await table_module.create({
3853
+ connector_config,
3854
+ data: item.data
3855
+ });
3856
+ connector_id = result?.id;
3857
+ if (connector_id) {
3858
+ await replace_temporary_ids({
3859
+ table: item.table,
3860
+ stall_offline_id: item.stall_offline_id,
3861
+ connector_id,
3862
+ local_data: result
3863
+ });
3864
+ }
3865
+ } else if (item.action === "update") {
3866
+ const result = await table_module.update({
3867
+ connector_config,
3868
+ id: item.document_id,
3869
+ data: item.data
3870
+ });
3871
+ connector_id = result?.id || item.document_id;
3872
+ } else if (item.action === "delete") {
3873
+ await table_module.delete({
3874
+ connector_config,
3875
+ id: item.document_id
3876
+ });
3877
+ connector_id = item.document_id;
3878
+ }
3879
+ const duration = Date.now() - start_time;
3880
+ await add_sync_log({
3881
+ sync_batch_id,
3882
+ table: item.table,
3883
+ action: item.action,
3884
+ document_id: item.document_id,
3885
+ stall_offline_id: item.stall_offline_id,
3886
+ connector_id,
3887
+ status: "success",
3888
+ duration_ms: duration
3889
+ });
3890
+ await remove_from_sync_queue(item.id);
3891
+ return { success: true, connector_id };
3892
+ } catch (error) {
3893
+ const duration = Date.now() - start_time;
3894
+ console.error(`Error syncing item ${item.id}:`, error);
3895
+ const current_retries = item.retry_count || 0;
3896
+ if (current_retries < MAX_RETRIES) {
3897
+ await update_sync_queue_status({
3898
+ id: item.id,
3899
+ status: "pending",
3900
+ error: error.message,
3901
+ retry_count: current_retries + 1
3902
+ });
3903
+ } else {
3904
+ await update_sync_queue_status({
3905
+ id: item.id,
3906
+ status: "failed",
3907
+ error: `Max retries exceeded: ${error.message}`
3908
+ });
3909
+ }
3910
+ await add_sync_log({
3911
+ sync_batch_id,
3912
+ table: item.table,
3913
+ action: item.action,
3914
+ document_id: item.document_id,
3915
+ stall_offline_id: item.stall_offline_id,
3916
+ status: "failed",
3917
+ error: error.message,
3918
+ duration_ms: duration
3919
+ });
3920
+ return { success: false, error: error.message };
3921
+ }
3922
+ };
3923
+ var process_sync_queue = async (props) => {
3924
+ const { sdk } = props;
3925
+ const sync_batch_id = uuid2();
3926
+ try {
3927
+ const pending_items_by_table = await get_pending_sync_queue();
3928
+ if (pending_items_by_table.size === 0) {
3929
+ return {
3930
+ sync_batch_id,
3931
+ total: 0,
3932
+ synced: 0,
3933
+ failed: 0,
3934
+ summary: []
3935
+ };
3936
+ }
3937
+ let total_synced = 0;
3938
+ let total_failed = 0;
3939
+ const summary_data = [];
3940
+ const all_items = [];
3941
+ pending_items_by_table.forEach((items) => {
3942
+ items.forEach((item) => {
3943
+ all_items.push(item);
3944
+ });
3945
+ });
3946
+ const sorted_items = sort_by_dependency_order(
3947
+ all_items
3948
+ );
3949
+ const synced_tables = /* @__PURE__ */ new Set();
3950
+ const items_to_retry = [];
3951
+ for (const item of sorted_items) {
3952
+ if (!are_dependencies_satisfied(item.table, synced_tables)) {
3953
+ items_to_retry.push(item);
3954
+ continue;
3955
+ }
3956
+ await update_sync_queue_status({
3957
+ id: item.id,
3958
+ status: "syncing"
3959
+ });
3960
+ const result = await sync_queue_item({
3961
+ sdk,
3962
+ item,
3963
+ sync_batch_id
3964
+ });
3965
+ if (result.success) {
3966
+ total_synced++;
3967
+ if (!synced_tables.has(item.table)) {
3968
+ synced_tables.add(item.table);
3969
+ }
3970
+ } else {
3971
+ total_failed++;
3972
+ }
3973
+ const table_summary = summary_data.find((s) => s.table === item.table);
3974
+ if (table_summary) {
3975
+ if (result.success) {
3976
+ table_summary.synced++;
3977
+ } else {
3978
+ table_summary.failed++;
3979
+ }
3980
+ } else {
3981
+ summary_data.push({
3982
+ table: item.table,
3983
+ synced: result.success ? 1 : 0,
3984
+ failed: result.success ? 0 : 1
3985
+ });
3986
+ }
3987
+ }
3988
+ for (const item of items_to_retry) {
3989
+ await update_sync_queue_status({
3990
+ id: item.id,
3991
+ status: "syncing"
3992
+ });
3993
+ const result = await sync_queue_item({
3994
+ sdk,
3995
+ item,
3996
+ sync_batch_id
3997
+ });
3998
+ if (result.success) {
3999
+ total_synced++;
4000
+ } else {
4001
+ total_failed++;
4002
+ }
4003
+ const table_summary = summary_data.find((s) => s.table === item.table);
4004
+ if (table_summary) {
4005
+ if (result.success) {
4006
+ table_summary.synced++;
4007
+ } else {
4008
+ table_summary.failed++;
4009
+ }
4010
+ }
4011
+ }
4012
+ return {
4013
+ sync_batch_id,
4014
+ total: all_items.length,
4015
+ synced: total_synced,
4016
+ failed: total_failed,
4017
+ summary: summary_data
4018
+ };
4019
+ } catch (error) {
4020
+ console.error("Error processing sync queue:", error);
4021
+ return {
4022
+ sync_batch_id,
4023
+ total: 0,
4024
+ synced: 0,
4025
+ failed: 0,
4026
+ summary: []
4027
+ };
4028
+ }
4029
+ };
4030
+ var sync_interval = null;
4031
+ var start_sync_service = async (props) => {
4032
+ const { sdk, interval = 3e4 } = props;
4033
+ if (sync_interval) {
4034
+ console.warn("Sync service already running");
4035
+ return;
4036
+ }
4037
+ console.log(`Starting offline sync service with ${interval}ms interval`);
4038
+ await process_sync_queue({ sdk });
4039
+ sync_interval = setInterval(async () => {
4040
+ const result = await process_sync_queue({ sdk });
4041
+ if (result.total > 0) {
4042
+ console.log(
4043
+ `Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
4044
+ );
4045
+ result.summary.forEach((s) => {
4046
+ console.log(` ${s.table}: ${s.synced} synced, ${s.failed} failed`);
4047
+ });
4048
+ }
4049
+ }, interval);
4050
+ };
4051
+ var stop_sync_service = () => {
4052
+ if (sync_interval) {
4053
+ clearInterval(sync_interval);
4054
+ sync_interval = null;
4055
+ console.log("Offline sync service stopped");
4056
+ }
4057
+ };
4058
+ var get_sync_stats = async () => {
4059
+ try {
4060
+ const all_items = await local_db.sync_queue.toArray();
4061
+ const pending = all_items.filter((i) => i.status === "pending").length;
4062
+ const syncing = all_items.filter((i) => i.status === "syncing").length;
4063
+ const failed = all_items.filter((i) => i.status === "failed").length;
4064
+ return {
4065
+ pending,
4066
+ syncing,
4067
+ failed,
4068
+ total: all_items.length
4069
+ };
4070
+ } catch (error) {
4071
+ console.error("Error getting sync stats:", error);
4072
+ return { pending: 0, syncing: 0, failed: 0, total: 0 };
4073
+ }
4074
+ };
4075
+ var trigger_sync = async (props) => {
4076
+ try {
4077
+ const { sdk } = props;
4078
+ return await process_sync_queue({ sdk });
4079
+ } catch (error) {
4080
+ console.error("Error triggering sync:", error);
4081
+ return {
4082
+ sync_batch_id: uuid2(),
4083
+ total: 0,
4084
+ synced: 0,
4085
+ failed: 0,
4086
+ summary: []
4087
+ };
4088
+ }
4089
+ };
4090
+ var sync_service = {
4091
+ process_sync_queue,
4092
+ sync_queue_item,
4093
+ start_sync_service,
4094
+ stop_sync_service,
4095
+ get_sync_stats,
4096
+ trigger_sync
4097
+ };
2085
4098
  export {
4099
+ add_sync_log,
4100
+ add_to_sync_queue,
2086
4101
  categories,
4102
+ cleanup_old_sync_logs,
2087
4103
  collections,
2088
4104
  customers,
2089
4105
  fulfillments,
4106
+ generate_offline_id,
4107
+ get_pending_sync_queue,
4108
+ get_recent_sync_logs,
4109
+ get_sync_logs_by_batch,
2090
4110
  initializeStallCore,
2091
4111
  inventory_levels,
4112
+ local_db,
2092
4113
  locations,
2093
4114
  order_notes,
2094
4115
  orders,
@@ -2097,7 +4118,11 @@ export {
2097
4118
  products,
2098
4119
  promotions,
2099
4120
  refunds,
4121
+ remove_from_sync_queue,
4122
+ save_bulk_data,
4123
+ sync_service,
2100
4124
  tax_rates,
2101
4125
  tax_regions,
4126
+ update_sync_queue_status,
2102
4127
  variants
2103
4128
  };