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