@use-stall/core 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +36 -50
- package/dist/index.d.ts +36 -50
- package/dist/index.js +1196 -1085
- package/dist/index.mjs +1194 -1085
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -43,6 +43,8 @@ __export(index_exports, {
|
|
|
43
43
|
get_sync_logs_by_batch: () => get_sync_logs_by_batch,
|
|
44
44
|
initializeStallCore: () => initializeStallCore,
|
|
45
45
|
inventory_levels: () => inventory_levels,
|
|
46
|
+
is_offline: () => is_offline,
|
|
47
|
+
is_online: () => is_online,
|
|
46
48
|
local_db: () => local_db,
|
|
47
49
|
locations: () => locations,
|
|
48
50
|
order_notes: () => order_notes,
|
|
@@ -94,45 +96,6 @@ var options = { allowEmptyDB: true };
|
|
|
94
96
|
var local_db = new import_dexie.default("stall-core-db", options);
|
|
95
97
|
local_db.version(1).stores(schemas);
|
|
96
98
|
|
|
97
|
-
// src/core/init.ts
|
|
98
|
-
var initializeStallCore = (options2) => {
|
|
99
|
-
const sdk = {
|
|
100
|
-
options: options2,
|
|
101
|
-
adapter: async () => getAdapter(sdk),
|
|
102
|
-
refreshAdapter: async () => getAdapter(sdk, true)
|
|
103
|
-
};
|
|
104
|
-
void sdk.adapter();
|
|
105
|
-
return sdk;
|
|
106
|
-
};
|
|
107
|
-
var getAdapter = async (sdk, force) => {
|
|
108
|
-
const date = Date.now();
|
|
109
|
-
let module_code;
|
|
110
|
-
const cache_key = "connector-module";
|
|
111
|
-
const cached = await local_db.connector_cache.get(cache_key);
|
|
112
|
-
if (cached && !force) {
|
|
113
|
-
module_code = cached.code;
|
|
114
|
-
} else {
|
|
115
|
-
const response = await fetch(sdk.options.connector_url, {
|
|
116
|
-
mode: "cors",
|
|
117
|
-
method: "GET"
|
|
118
|
-
});
|
|
119
|
-
if (!response.ok) {
|
|
120
|
-
throw new Error(`Failed to fetch connector: ${response.statusText}`);
|
|
121
|
-
}
|
|
122
|
-
module_code = await response.text();
|
|
123
|
-
await local_db.connector_cache.put({
|
|
124
|
-
id: cache_key,
|
|
125
|
-
code: module_code,
|
|
126
|
-
timestamp: date
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
const blob = new Blob([module_code], { type: "application/javascript" });
|
|
130
|
-
const blobUrl = URL.createObjectURL(blob);
|
|
131
|
-
const module2 = await import(blobUrl);
|
|
132
|
-
URL.revokeObjectURL(blobUrl);
|
|
133
|
-
return module2;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
99
|
// src/lib/utils.ts
|
|
137
100
|
var generate_uuid = () => {
|
|
138
101
|
return "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
@@ -141,6 +104,15 @@ var generate_uuid = () => {
|
|
|
141
104
|
return v.toString(16);
|
|
142
105
|
});
|
|
143
106
|
};
|
|
107
|
+
var is_online = () => {
|
|
108
|
+
if (typeof navigator !== "undefined" && typeof navigator.onLine === "boolean") {
|
|
109
|
+
return navigator.onLine;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
};
|
|
113
|
+
var is_offline = () => {
|
|
114
|
+
return !is_online();
|
|
115
|
+
};
|
|
144
116
|
|
|
145
117
|
// src/db/helpers.ts
|
|
146
118
|
var generate_offline_id = (table) => {
|
|
@@ -257,122 +229,590 @@ var cleanup_old_sync_logs = async (days = 30) => {
|
|
|
257
229
|
await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
|
|
258
230
|
};
|
|
259
231
|
|
|
260
|
-
// src/services/
|
|
261
|
-
var
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
throw error;
|
|
277
|
-
}
|
|
232
|
+
// src/services/sync/sync-dependencies.ts
|
|
233
|
+
var SYNC_DEPENDENCY_LAYERS = {
|
|
234
|
+
1: [
|
|
235
|
+
"tax_regions",
|
|
236
|
+
"tax_rates",
|
|
237
|
+
"categories",
|
|
238
|
+
"collections",
|
|
239
|
+
"locations",
|
|
240
|
+
"payment_providers",
|
|
241
|
+
"customers",
|
|
242
|
+
"promotions"
|
|
243
|
+
],
|
|
244
|
+
2: ["products"],
|
|
245
|
+
3: ["variants", "inventory_levels"],
|
|
246
|
+
4: ["orders", "order_notes"],
|
|
247
|
+
5: ["payments", "refunds", "fulfillments"]
|
|
278
248
|
};
|
|
279
|
-
var
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
249
|
+
var get_entity_dependencies = (table) => {
|
|
250
|
+
const dependencies = {
|
|
251
|
+
// Layer 1: Independent
|
|
252
|
+
tax_regions: [],
|
|
253
|
+
tax_rates: ["tax_regions"],
|
|
254
|
+
categories: [],
|
|
255
|
+
collections: [],
|
|
256
|
+
locations: [],
|
|
257
|
+
payment_providers: [],
|
|
258
|
+
customers: [],
|
|
259
|
+
promotions: [],
|
|
260
|
+
// Layer 2: Product
|
|
261
|
+
products: ["categories", "collections"],
|
|
262
|
+
// Layer 3: Variants & Inventory
|
|
263
|
+
variants: ["products"],
|
|
264
|
+
inventory_levels: ["products", "variants"],
|
|
265
|
+
inventory_history: ["products", "variants"],
|
|
266
|
+
// Layer 4: Orders
|
|
267
|
+
orders: ["customers", "products", "variants", "locations"],
|
|
268
|
+
order_notes: ["orders"],
|
|
269
|
+
// Layer 5: Order-related
|
|
270
|
+
payments: ["orders", "payment_providers"],
|
|
271
|
+
refunds: ["orders", "payments"],
|
|
272
|
+
fulfillments: ["orders"],
|
|
273
|
+
// Tags
|
|
274
|
+
tags: ["products"],
|
|
275
|
+
// Fulfillment config
|
|
276
|
+
fulfillment_types: [],
|
|
277
|
+
fulfillment_providers: []
|
|
278
|
+
};
|
|
279
|
+
return dependencies[table] || [];
|
|
293
280
|
};
|
|
294
|
-
var
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const local_product = {
|
|
300
|
-
...data,
|
|
301
|
-
id: offline_id,
|
|
302
|
-
metadata: {
|
|
303
|
-
...data.metadata,
|
|
304
|
-
stall_offline_id: offline_id
|
|
305
|
-
},
|
|
306
|
-
stall_offline_id: offline_id,
|
|
307
|
-
stall_offline_created_at: now,
|
|
308
|
-
stall_offline_updated_at: now
|
|
309
|
-
};
|
|
310
|
-
await local_db.products.add(local_product);
|
|
311
|
-
await add_to_sync_queue({
|
|
312
|
-
action: "create",
|
|
313
|
-
table: "products",
|
|
314
|
-
document_id: offline_id,
|
|
315
|
-
stall_offline_id: offline_id,
|
|
316
|
-
data: local_product
|
|
317
|
-
});
|
|
318
|
-
return local_product;
|
|
319
|
-
} catch (error) {
|
|
320
|
-
throw error;
|
|
281
|
+
var get_sync_layer = (table) => {
|
|
282
|
+
for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
|
|
283
|
+
if (tables.includes(table)) {
|
|
284
|
+
return parseInt(layer);
|
|
285
|
+
}
|
|
321
286
|
}
|
|
287
|
+
return 99;
|
|
322
288
|
};
|
|
323
|
-
var
|
|
289
|
+
var sort_by_dependency_order = (items) => {
|
|
290
|
+
return items.sort((a, b) => {
|
|
291
|
+
const layer_a = get_sync_layer(a.table);
|
|
292
|
+
const layer_b = get_sync_layer(b.table);
|
|
293
|
+
if (layer_a !== layer_b) {
|
|
294
|
+
return layer_a - layer_b;
|
|
295
|
+
}
|
|
296
|
+
return 0;
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
var are_dependencies_satisfied = (table, synced_tables) => {
|
|
300
|
+
const dependencies = get_entity_dependencies(table);
|
|
301
|
+
return dependencies.every((dep) => synced_tables.has(dep));
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/services/sync/sync.service.ts
|
|
305
|
+
var MAX_RETRIES = 3;
|
|
306
|
+
var SYNC_INTERVAL_MS = 2 * 60 * 1e3;
|
|
307
|
+
var sync_interval = null;
|
|
308
|
+
var is_syncing = false;
|
|
309
|
+
var replace_temporary_ids = async (props) => {
|
|
310
|
+
const { table, stall_offline_id, connector_id } = props;
|
|
324
311
|
try {
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
312
|
+
const existing = await local_db[table].where("stall_offline_id").equals(stall_offline_id).first();
|
|
313
|
+
if (existing) {
|
|
314
|
+
await local_db[table].update(existing.id, {
|
|
315
|
+
id: connector_id
|
|
316
|
+
});
|
|
329
317
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
id: existing.id,
|
|
335
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
336
|
-
stall_offline_id: existing.stall_offline_id,
|
|
337
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
338
|
-
stall_offline_updated_at: now
|
|
339
|
-
};
|
|
340
|
-
await local_db.products.put(updated_product);
|
|
341
|
-
await add_to_sync_queue({
|
|
342
|
-
action: "update",
|
|
343
|
-
table: "products",
|
|
344
|
-
document_id: id,
|
|
345
|
-
stall_offline_id: existing.stall_offline_id,
|
|
346
|
-
data: updated_product
|
|
318
|
+
await update_dependent_references({
|
|
319
|
+
table,
|
|
320
|
+
old_id: stall_offline_id,
|
|
321
|
+
new_id: connector_id
|
|
347
322
|
});
|
|
348
|
-
return updated_product;
|
|
349
323
|
} catch (error) {
|
|
324
|
+
console.error(`Error replacing temporary IDs for ${table}:`, error);
|
|
350
325
|
throw error;
|
|
351
326
|
}
|
|
352
327
|
};
|
|
353
|
-
var
|
|
328
|
+
var update_dependent_references = async (props) => {
|
|
329
|
+
const { table, old_id, new_id } = props;
|
|
354
330
|
try {
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
331
|
+
const reference_map = {
|
|
332
|
+
products: [
|
|
333
|
+
{ table: "variants", field: "product_id" },
|
|
334
|
+
{ table: "inventory_levels", field: "product_id" }
|
|
335
|
+
],
|
|
336
|
+
variants: [{ table: "inventory_levels", field: "variant_id" }],
|
|
337
|
+
customers: [{ table: "orders", field: "customer_id" }],
|
|
338
|
+
orders: [
|
|
339
|
+
{ table: "payments", field: "order_id" },
|
|
340
|
+
{ table: "refunds", field: "order_id" },
|
|
341
|
+
{ table: "order_notes", field: "order_id" },
|
|
342
|
+
{ table: "fulfillments", field: "order_id" }
|
|
343
|
+
],
|
|
344
|
+
payments: [{ table: "refunds", field: "payment_id" }],
|
|
345
|
+
locations: [{ table: "orders", field: "location_id" }],
|
|
346
|
+
categories: [{ table: "products", field: "category_id" }],
|
|
347
|
+
collections: [{ table: "products", field: "collection_id" }],
|
|
348
|
+
tax_regions: [{ table: "tax_rates", field: "region_id" }],
|
|
349
|
+
tax_rates: [],
|
|
350
|
+
tags: [],
|
|
351
|
+
inventory_levels: [],
|
|
352
|
+
inventory_history: [],
|
|
353
|
+
promotions: [],
|
|
354
|
+
order_notes: [],
|
|
355
|
+
refunds: [],
|
|
356
|
+
payment_providers: [],
|
|
357
|
+
fulfillments: [],
|
|
358
|
+
fulfillment_types: [],
|
|
359
|
+
fulfillment_providers: []
|
|
360
|
+
};
|
|
361
|
+
const references = reference_map[table] || [];
|
|
362
|
+
for (const ref of references) {
|
|
363
|
+
const records = await local_db[ref.table].toArray();
|
|
364
|
+
const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
|
|
365
|
+
...record,
|
|
366
|
+
[ref.field]: new_id
|
|
367
|
+
}));
|
|
368
|
+
if (updates.length > 0) {
|
|
369
|
+
await local_db[ref.table].bulkPut(updates);
|
|
370
|
+
}
|
|
359
371
|
}
|
|
360
|
-
await add_to_sync_queue({
|
|
361
|
-
action: "delete",
|
|
362
|
-
table: "products",
|
|
363
|
-
document_id: id,
|
|
364
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
|
-
stall_offline_id: existing.stall_offline_id,
|
|
366
|
-
data: { id }
|
|
367
|
-
});
|
|
368
|
-
await local_db.products.delete(id);
|
|
369
|
-
return;
|
|
370
372
|
} catch (error) {
|
|
371
|
-
|
|
373
|
+
console.error(`Error updating dependent references for ${table}:`, error);
|
|
372
374
|
}
|
|
373
375
|
};
|
|
374
|
-
var
|
|
375
|
-
|
|
376
|
+
var sync_queue_item = async (props) => {
|
|
377
|
+
const { sdk, item, sync_batch_id } = props;
|
|
378
|
+
const start_time = Date.now();
|
|
379
|
+
try {
|
|
380
|
+
const adapter = await sdk.adapter();
|
|
381
|
+
if (!adapter) {
|
|
382
|
+
throw new Error("Adapter not found");
|
|
383
|
+
}
|
|
384
|
+
const connector_config = sdk.options.configuration;
|
|
385
|
+
const table_module = adapter[item.table];
|
|
386
|
+
if (!table_module) {
|
|
387
|
+
throw new Error(`Module ${item.table} not found in adapter`);
|
|
388
|
+
}
|
|
389
|
+
let connector_id;
|
|
390
|
+
if (item.action === "create") {
|
|
391
|
+
const result = await table_module.create({
|
|
392
|
+
connector_config,
|
|
393
|
+
data: item.data
|
|
394
|
+
});
|
|
395
|
+
connector_id = result?.id;
|
|
396
|
+
if (connector_id) {
|
|
397
|
+
await replace_temporary_ids({
|
|
398
|
+
table: item.table,
|
|
399
|
+
stall_offline_id: item.stall_offline_id,
|
|
400
|
+
connector_id
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
} else if (item.action === "update") {
|
|
404
|
+
const result = await table_module.update({
|
|
405
|
+
connector_config,
|
|
406
|
+
id: item.document_id,
|
|
407
|
+
data: item.data
|
|
408
|
+
});
|
|
409
|
+
connector_id = result?.id || item.document_id;
|
|
410
|
+
} else if (item.action === "delete") {
|
|
411
|
+
await table_module.delete({
|
|
412
|
+
connector_config,
|
|
413
|
+
id: item.document_id
|
|
414
|
+
});
|
|
415
|
+
connector_id = item.document_id;
|
|
416
|
+
}
|
|
417
|
+
const duration = Date.now() - start_time;
|
|
418
|
+
await add_sync_log({
|
|
419
|
+
sync_batch_id,
|
|
420
|
+
table: item.table,
|
|
421
|
+
action: item.action,
|
|
422
|
+
document_id: item.document_id,
|
|
423
|
+
stall_offline_id: item.stall_offline_id,
|
|
424
|
+
connector_id,
|
|
425
|
+
status: "success",
|
|
426
|
+
duration_ms: duration
|
|
427
|
+
});
|
|
428
|
+
await remove_from_sync_queue(item.id);
|
|
429
|
+
return { success: true, connector_id };
|
|
430
|
+
} catch (error) {
|
|
431
|
+
const duration = Date.now() - start_time;
|
|
432
|
+
console.error(`Error syncing item ${item.id}:`, error);
|
|
433
|
+
const current_retries = item.retry_count || 0;
|
|
434
|
+
if (current_retries < MAX_RETRIES) {
|
|
435
|
+
await update_sync_queue_status({
|
|
436
|
+
id: item.id,
|
|
437
|
+
status: "pending",
|
|
438
|
+
error: error.message,
|
|
439
|
+
retry_count: current_retries + 1
|
|
440
|
+
});
|
|
441
|
+
} else {
|
|
442
|
+
await update_sync_queue_status({
|
|
443
|
+
id: item.id,
|
|
444
|
+
status: "failed",
|
|
445
|
+
error: `Max retries exceeded: ${error.message}`
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
await add_sync_log({
|
|
449
|
+
sync_batch_id,
|
|
450
|
+
table: item.table,
|
|
451
|
+
action: item.action,
|
|
452
|
+
document_id: item.document_id,
|
|
453
|
+
stall_offline_id: item.stall_offline_id,
|
|
454
|
+
status: "failed",
|
|
455
|
+
error: error.message,
|
|
456
|
+
duration_ms: duration
|
|
457
|
+
});
|
|
458
|
+
return { success: false, error: error.message };
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
var process_sync_queue = async (props) => {
|
|
462
|
+
const { sdk } = props;
|
|
463
|
+
const sync_batch_id = generate_uuid();
|
|
464
|
+
if (is_syncing) {
|
|
465
|
+
console.log("Sync already in progress, skipping...");
|
|
466
|
+
return {
|
|
467
|
+
sync_batch_id,
|
|
468
|
+
total: 0,
|
|
469
|
+
synced: 0,
|
|
470
|
+
failed: 0
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
is_syncing = true;
|
|
474
|
+
try {
|
|
475
|
+
const pending_items_by_table = await get_pending_sync_queue();
|
|
476
|
+
if (pending_items_by_table.size === 0) {
|
|
477
|
+
return {
|
|
478
|
+
sync_batch_id,
|
|
479
|
+
total: 0,
|
|
480
|
+
synced: 0,
|
|
481
|
+
failed: 0
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
let total_synced = 0;
|
|
485
|
+
let total_failed = 0;
|
|
486
|
+
const all_items = [];
|
|
487
|
+
pending_items_by_table.forEach((items) => {
|
|
488
|
+
items.forEach((item) => {
|
|
489
|
+
all_items.push(item);
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
const sorted_items = sort_by_dependency_order(
|
|
493
|
+
all_items
|
|
494
|
+
);
|
|
495
|
+
const synced_tables = /* @__PURE__ */ new Set();
|
|
496
|
+
const items_to_retry = [];
|
|
497
|
+
for (const item of sorted_items) {
|
|
498
|
+
if (!are_dependencies_satisfied(item.table, synced_tables)) {
|
|
499
|
+
items_to_retry.push(item);
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
await update_sync_queue_status({
|
|
503
|
+
id: item.id,
|
|
504
|
+
status: "syncing"
|
|
505
|
+
});
|
|
506
|
+
const result = await sync_queue_item({
|
|
507
|
+
sdk,
|
|
508
|
+
item,
|
|
509
|
+
sync_batch_id
|
|
510
|
+
});
|
|
511
|
+
if (result.success) {
|
|
512
|
+
total_synced++;
|
|
513
|
+
if (!synced_tables.has(item.table)) {
|
|
514
|
+
synced_tables.add(item.table);
|
|
515
|
+
}
|
|
516
|
+
} else {
|
|
517
|
+
total_failed++;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
for (const item of items_to_retry) {
|
|
521
|
+
await update_sync_queue_status({
|
|
522
|
+
id: item.id,
|
|
523
|
+
status: "syncing"
|
|
524
|
+
});
|
|
525
|
+
const result = await sync_queue_item({
|
|
526
|
+
sdk,
|
|
527
|
+
item,
|
|
528
|
+
sync_batch_id
|
|
529
|
+
});
|
|
530
|
+
if (result.success) {
|
|
531
|
+
total_synced++;
|
|
532
|
+
} else {
|
|
533
|
+
total_failed++;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
sync_batch_id,
|
|
538
|
+
total: all_items.length,
|
|
539
|
+
synced: total_synced,
|
|
540
|
+
failed: total_failed
|
|
541
|
+
};
|
|
542
|
+
} catch (error) {
|
|
543
|
+
console.error("Error processing sync queue:", error);
|
|
544
|
+
return {
|
|
545
|
+
sync_batch_id,
|
|
546
|
+
total: 0,
|
|
547
|
+
synced: 0,
|
|
548
|
+
failed: 0
|
|
549
|
+
};
|
|
550
|
+
} finally {
|
|
551
|
+
is_syncing = false;
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
var get_sync_status = async () => {
|
|
555
|
+
try {
|
|
556
|
+
const all_items = await local_db.sync_queue.toArray();
|
|
557
|
+
const pending = all_items.filter((i) => i.status === "pending").length;
|
|
558
|
+
const syncing = all_items.filter((i) => i.status === "syncing").length;
|
|
559
|
+
const failed = all_items.filter((i) => i.status === "failed").length;
|
|
560
|
+
return {
|
|
561
|
+
pending,
|
|
562
|
+
syncing,
|
|
563
|
+
failed,
|
|
564
|
+
total: all_items.length,
|
|
565
|
+
is_sync_running: sync_interval !== null
|
|
566
|
+
};
|
|
567
|
+
} catch (error) {
|
|
568
|
+
console.error("Error getting sync status:", error);
|
|
569
|
+
return {
|
|
570
|
+
pending: 0,
|
|
571
|
+
syncing: 0,
|
|
572
|
+
failed: 0,
|
|
573
|
+
total: 0,
|
|
574
|
+
is_sync_running: false
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var fix_sync_queue = async () => {
|
|
579
|
+
try {
|
|
580
|
+
const stuck_items = await local_db.sync_queue.where("status").equals("syncing").toArray();
|
|
581
|
+
for (const item of stuck_items) {
|
|
582
|
+
await update_sync_queue_status({
|
|
583
|
+
id: item.id,
|
|
584
|
+
status: "pending"
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
console.log(`Fixed ${stuck_items.length} stuck sync queue items`);
|
|
588
|
+
return {
|
|
589
|
+
fixed: stuck_items.length
|
|
590
|
+
};
|
|
591
|
+
} catch (error) {
|
|
592
|
+
console.error("Error fixing sync queue:", error);
|
|
593
|
+
return {
|
|
594
|
+
fixed: 0
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
var trigger_sync = async (props) => {
|
|
599
|
+
try {
|
|
600
|
+
const { sdk } = props;
|
|
601
|
+
return await process_sync_queue({ sdk });
|
|
602
|
+
} catch (error) {
|
|
603
|
+
console.error("Error triggering sync:", error);
|
|
604
|
+
return {
|
|
605
|
+
sync_batch_id: generate_uuid(),
|
|
606
|
+
total: 0,
|
|
607
|
+
synced: 0,
|
|
608
|
+
failed: 0
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
var start_sync = async (props) => {
|
|
613
|
+
const { sdk } = props;
|
|
614
|
+
if (sync_interval) {
|
|
615
|
+
console.warn("Background sync already running");
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
console.log(
|
|
619
|
+
`Starting background sync service (${SYNC_INTERVAL_MS}ms interval)`
|
|
620
|
+
);
|
|
621
|
+
const initial_result = await process_sync_queue({ sdk });
|
|
622
|
+
if (initial_result.total > 0) {
|
|
623
|
+
console.log(
|
|
624
|
+
`Initial sync: ${initial_result.synced} synced, ${initial_result.failed} failed out of ${initial_result.total}`
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
sync_interval = setInterval(async () => {
|
|
628
|
+
const status = await get_sync_status();
|
|
629
|
+
if (status.pending > 0) {
|
|
630
|
+
const result = await process_sync_queue({ sdk });
|
|
631
|
+
if (result.total > 0) {
|
|
632
|
+
console.log(
|
|
633
|
+
`Sync batch ${result.sync_batch_id}: ${result.synced} synced, ${result.failed} failed out of ${result.total}`
|
|
634
|
+
);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}, SYNC_INTERVAL_MS);
|
|
638
|
+
};
|
|
639
|
+
var stop_sync = () => {
|
|
640
|
+
if (sync_interval) {
|
|
641
|
+
clearInterval(sync_interval);
|
|
642
|
+
sync_interval = null;
|
|
643
|
+
console.log("Background sync service stopped");
|
|
644
|
+
} else {
|
|
645
|
+
console.warn("Background sync is not running");
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var sync_service = {
|
|
649
|
+
get_sync_status,
|
|
650
|
+
fix_sync_queue,
|
|
651
|
+
trigger_sync,
|
|
652
|
+
start_sync,
|
|
653
|
+
stop_sync
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// src/core/init.ts
|
|
657
|
+
var initializeStallCore = (options2) => {
|
|
658
|
+
const sdk = {
|
|
659
|
+
options: options2,
|
|
660
|
+
adapter: async () => getAdapter(sdk),
|
|
661
|
+
refreshAdapter: async () => getAdapter(sdk, true)
|
|
662
|
+
};
|
|
663
|
+
void sdk.adapter().then(() => {
|
|
664
|
+
void sync_service.start_sync({ sdk });
|
|
665
|
+
});
|
|
666
|
+
return sdk;
|
|
667
|
+
};
|
|
668
|
+
var getAdapter = async (sdk, force) => {
|
|
669
|
+
const date = Date.now();
|
|
670
|
+
let module_code;
|
|
671
|
+
const cache_key = "connector-module";
|
|
672
|
+
const cached = await local_db.connector_cache.get(cache_key);
|
|
673
|
+
if (cached && !force) {
|
|
674
|
+
module_code = cached.code;
|
|
675
|
+
} else {
|
|
676
|
+
const response = await fetch(sdk.options.connector_url, {
|
|
677
|
+
mode: "cors",
|
|
678
|
+
method: "GET"
|
|
679
|
+
});
|
|
680
|
+
if (!response.ok) {
|
|
681
|
+
throw new Error(`Failed to fetch connector: ${response.statusText}`);
|
|
682
|
+
}
|
|
683
|
+
module_code = await response.text();
|
|
684
|
+
await local_db.connector_cache.put({
|
|
685
|
+
id: cache_key,
|
|
686
|
+
code: module_code,
|
|
687
|
+
timestamp: date
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
const blob = new Blob([module_code], { type: "application/javascript" });
|
|
691
|
+
const blobUrl = URL.createObjectURL(blob);
|
|
692
|
+
const module2 = await import(blobUrl);
|
|
693
|
+
URL.revokeObjectURL(blobUrl);
|
|
694
|
+
return module2;
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
// src/services/products.service.ts
|
|
698
|
+
var list = async (props) => {
|
|
699
|
+
try {
|
|
700
|
+
const { sdk, query } = props;
|
|
701
|
+
const adapter = await sdk.adapter();
|
|
702
|
+
if (!adapter) throw new Error("Adapter not found");
|
|
703
|
+
const products2 = await adapter.products.list({
|
|
704
|
+
connector_config: sdk.options.configuration,
|
|
705
|
+
query
|
|
706
|
+
});
|
|
707
|
+
await save_bulk_data({
|
|
708
|
+
table: "products",
|
|
709
|
+
data: products2
|
|
710
|
+
});
|
|
711
|
+
return products2;
|
|
712
|
+
} catch (error) {
|
|
713
|
+
throw error;
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
var retrieve = async (props) => {
|
|
717
|
+
try {
|
|
718
|
+
const { sdk, id } = props;
|
|
719
|
+
const adapter = await sdk.adapter();
|
|
720
|
+
if (!adapter) throw new Error("Adapter not found");
|
|
721
|
+
const product = await adapter.products.retrieve({
|
|
722
|
+
connector_config: sdk.options.configuration,
|
|
723
|
+
id
|
|
724
|
+
});
|
|
725
|
+
await local_db.products.put(product);
|
|
726
|
+
return product;
|
|
727
|
+
} catch (error) {
|
|
728
|
+
throw error;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
var create = async (props) => {
|
|
732
|
+
try {
|
|
733
|
+
const { sdk, data } = props;
|
|
734
|
+
const offline_id = generate_offline_id("product");
|
|
735
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
736
|
+
const local_product = {
|
|
737
|
+
...data,
|
|
738
|
+
id: offline_id,
|
|
739
|
+
metadata: {
|
|
740
|
+
...data.metadata,
|
|
741
|
+
stall_offline_id: offline_id,
|
|
742
|
+
stall_offline_created_at: now,
|
|
743
|
+
stall_offline_updated_at: now,
|
|
744
|
+
stall_offline_deleted_at: ""
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
await local_db.products.add(local_product);
|
|
748
|
+
await add_to_sync_queue({
|
|
749
|
+
action: "create",
|
|
750
|
+
table: "products",
|
|
751
|
+
document_id: offline_id,
|
|
752
|
+
stall_offline_id: offline_id,
|
|
753
|
+
data: local_product
|
|
754
|
+
});
|
|
755
|
+
return local_product;
|
|
756
|
+
} catch (error) {
|
|
757
|
+
throw error;
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
var update = async (props) => {
|
|
761
|
+
try {
|
|
762
|
+
const { sdk, id, data } = props;
|
|
763
|
+
const existing = await local_db.products.get(id);
|
|
764
|
+
if (!existing) {
|
|
765
|
+
throw new Error(`Product with id ${id} not found locally`);
|
|
766
|
+
}
|
|
767
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
768
|
+
const updated_product = {
|
|
769
|
+
...existing,
|
|
770
|
+
...data,
|
|
771
|
+
id: existing.id,
|
|
772
|
+
metadata: {
|
|
773
|
+
...existing.metadata,
|
|
774
|
+
...data.metadata,
|
|
775
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
776
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
777
|
+
stall_offline_updated_at: now,
|
|
778
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
await local_db.products.put(updated_product);
|
|
782
|
+
await add_to_sync_queue({
|
|
783
|
+
action: "update",
|
|
784
|
+
table: "products",
|
|
785
|
+
document_id: id,
|
|
786
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
787
|
+
data: updated_product
|
|
788
|
+
});
|
|
789
|
+
return updated_product;
|
|
790
|
+
} catch (error) {
|
|
791
|
+
throw error;
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
var _delete = async (props) => {
|
|
795
|
+
try {
|
|
796
|
+
const { sdk, id } = props;
|
|
797
|
+
const existing = await local_db.products.get(id);
|
|
798
|
+
if (!existing) {
|
|
799
|
+
throw new Error(`Product with id ${id} not found locally`);
|
|
800
|
+
}
|
|
801
|
+
await add_to_sync_queue({
|
|
802
|
+
action: "delete",
|
|
803
|
+
table: "products",
|
|
804
|
+
document_id: id,
|
|
805
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
806
|
+
data: { id }
|
|
807
|
+
});
|
|
808
|
+
await local_db.products.delete(id);
|
|
809
|
+
return;
|
|
810
|
+
} catch (error) {
|
|
811
|
+
throw error;
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
var bulk_create = async (props) => {
|
|
815
|
+
try {
|
|
376
816
|
const { sdk, data } = props;
|
|
377
817
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
378
818
|
const created_products = [];
|
|
@@ -383,11 +823,11 @@ var bulk_create = async (props) => {
|
|
|
383
823
|
id: offline_id,
|
|
384
824
|
metadata: {
|
|
385
825
|
...product.metadata,
|
|
386
|
-
stall_offline_id: offline_id
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
826
|
+
stall_offline_id: offline_id,
|
|
827
|
+
stall_offline_created_at: now,
|
|
828
|
+
stall_offline_updated_at: now,
|
|
829
|
+
stall_offline_deleted_at: ""
|
|
830
|
+
}
|
|
391
831
|
};
|
|
392
832
|
await local_db.products.add(local_product);
|
|
393
833
|
await add_to_sync_queue({
|
|
@@ -419,17 +859,21 @@ var bulk_update = async (props) => {
|
|
|
419
859
|
...existing,
|
|
420
860
|
...item.data,
|
|
421
861
|
id: existing.id,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
862
|
+
metadata: {
|
|
863
|
+
...existing.metadata,
|
|
864
|
+
...item.data.metadata,
|
|
865
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
866
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
867
|
+
stall_offline_updated_at: now,
|
|
868
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
869
|
+
}
|
|
426
870
|
};
|
|
427
871
|
await local_db.products.put(updated_product);
|
|
428
872
|
await add_to_sync_queue({
|
|
429
873
|
action: "update",
|
|
430
874
|
table: "products",
|
|
431
875
|
document_id: item.id,
|
|
432
|
-
stall_offline_id: existing.stall_offline_id,
|
|
876
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
433
877
|
data: updated_product
|
|
434
878
|
});
|
|
435
879
|
updated_products.push(updated_product);
|
|
@@ -452,8 +896,7 @@ var bulk_delete = async (props) => {
|
|
|
452
896
|
action: "delete",
|
|
453
897
|
table: "products",
|
|
454
898
|
document_id: id,
|
|
455
|
-
|
|
456
|
-
stall_offline_id: existing.stall_offline_id,
|
|
899
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
457
900
|
data: { id }
|
|
458
901
|
});
|
|
459
902
|
await local_db.products.delete(id);
|
|
@@ -522,11 +965,11 @@ var create2 = async (props) => {
|
|
|
522
965
|
id: offline_id,
|
|
523
966
|
metadata: {
|
|
524
967
|
...data.metadata,
|
|
525
|
-
stall_offline_id: offline_id
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
968
|
+
stall_offline_id: offline_id,
|
|
969
|
+
stall_offline_created_at: now,
|
|
970
|
+
stall_offline_updated_at: now,
|
|
971
|
+
stall_offline_deleted_at: ""
|
|
972
|
+
}
|
|
530
973
|
};
|
|
531
974
|
await local_db.orders.add(local_order);
|
|
532
975
|
await add_to_sync_queue({
|
|
@@ -555,17 +998,21 @@ var update2 = async (props) => {
|
|
|
555
998
|
...existing,
|
|
556
999
|
...data,
|
|
557
1000
|
id: existing.id,
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
1001
|
+
metadata: {
|
|
1002
|
+
...existing.metadata,
|
|
1003
|
+
...data.metadata,
|
|
1004
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1005
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1006
|
+
stall_offline_updated_at: now,
|
|
1007
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1008
|
+
}
|
|
561
1009
|
};
|
|
562
1010
|
await local_db.orders.put(updated_order);
|
|
563
1011
|
await add_to_sync_queue({
|
|
564
1012
|
action: "update",
|
|
565
1013
|
table: "orders",
|
|
566
1014
|
document_id: id,
|
|
567
|
-
|
|
568
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1015
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
569
1016
|
data: updated_order
|
|
570
1017
|
});
|
|
571
1018
|
return updated_order;
|
|
@@ -586,8 +1033,7 @@ var _delete2 = async (props) => {
|
|
|
586
1033
|
action: "delete",
|
|
587
1034
|
table: "orders",
|
|
588
1035
|
document_id: id,
|
|
589
|
-
|
|
590
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1036
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
591
1037
|
data: { id }
|
|
592
1038
|
});
|
|
593
1039
|
await local_db.orders.delete(id);
|
|
@@ -610,11 +1056,11 @@ var bulk_create2 = async (props) => {
|
|
|
610
1056
|
id: offline_id,
|
|
611
1057
|
metadata: {
|
|
612
1058
|
...order.metadata,
|
|
613
|
-
stall_offline_id: offline_id
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
1059
|
+
stall_offline_id: offline_id,
|
|
1060
|
+
stall_offline_created_at: now,
|
|
1061
|
+
stall_offline_updated_at: now,
|
|
1062
|
+
stall_offline_deleted_at: ""
|
|
1063
|
+
}
|
|
618
1064
|
};
|
|
619
1065
|
await local_db.orders.add(local_order);
|
|
620
1066
|
await add_to_sync_queue({
|
|
@@ -648,17 +1094,21 @@ var bulk_update2 = async (props) => {
|
|
|
648
1094
|
...existing,
|
|
649
1095
|
...item.data,
|
|
650
1096
|
id: existing.id,
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
1097
|
+
metadata: {
|
|
1098
|
+
...existing.metadata,
|
|
1099
|
+
...item.data.metadata,
|
|
1100
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1101
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1102
|
+
stall_offline_updated_at: now,
|
|
1103
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1104
|
+
}
|
|
654
1105
|
};
|
|
655
1106
|
await local_db.orders.put(updated_order);
|
|
656
1107
|
await add_to_sync_queue({
|
|
657
1108
|
action: "update",
|
|
658
1109
|
table: "orders",
|
|
659
1110
|
document_id: item.id,
|
|
660
|
-
|
|
661
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1111
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
662
1112
|
data: updated_order
|
|
663
1113
|
});
|
|
664
1114
|
updated_orders.push(updated_order);
|
|
@@ -683,8 +1133,7 @@ var bulk_delete2 = async (props) => {
|
|
|
683
1133
|
action: "delete",
|
|
684
1134
|
table: "orders",
|
|
685
1135
|
document_id: id,
|
|
686
|
-
|
|
687
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1136
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
688
1137
|
data: { id }
|
|
689
1138
|
});
|
|
690
1139
|
await local_db.orders.delete(id);
|
|
@@ -751,11 +1200,11 @@ var create3 = async (props) => {
|
|
|
751
1200
|
id: offline_id,
|
|
752
1201
|
metadata: {
|
|
753
1202
|
...data.metadata,
|
|
754
|
-
stall_offline_id: offline_id
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1203
|
+
stall_offline_id: offline_id,
|
|
1204
|
+
stall_offline_created_at: now,
|
|
1205
|
+
stall_offline_updated_at: now,
|
|
1206
|
+
stall_offline_deleted_at: ""
|
|
1207
|
+
}
|
|
759
1208
|
};
|
|
760
1209
|
await local_db.customers.add(local_customer);
|
|
761
1210
|
await add_to_sync_queue({
|
|
@@ -782,17 +1231,21 @@ var update3 = async (props) => {
|
|
|
782
1231
|
...existing,
|
|
783
1232
|
...data,
|
|
784
1233
|
id: existing.id,
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
1234
|
+
metadata: {
|
|
1235
|
+
...existing.metadata,
|
|
1236
|
+
...data.metadata,
|
|
1237
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1238
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1239
|
+
stall_offline_updated_at: now,
|
|
1240
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1241
|
+
}
|
|
788
1242
|
};
|
|
789
1243
|
await local_db.customers.put(updated_customer);
|
|
790
1244
|
await add_to_sync_queue({
|
|
791
1245
|
action: "update",
|
|
792
1246
|
table: "customers",
|
|
793
1247
|
document_id: id,
|
|
794
|
-
|
|
795
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1248
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
796
1249
|
data: updated_customer
|
|
797
1250
|
});
|
|
798
1251
|
return updated_customer;
|
|
@@ -811,8 +1264,7 @@ var _delete3 = async (props) => {
|
|
|
811
1264
|
action: "delete",
|
|
812
1265
|
table: "customers",
|
|
813
1266
|
document_id: id,
|
|
814
|
-
|
|
815
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1267
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
816
1268
|
data: { id }
|
|
817
1269
|
});
|
|
818
1270
|
await local_db.customers.delete(id);
|
|
@@ -833,11 +1285,11 @@ var bulk_create3 = async (props) => {
|
|
|
833
1285
|
id: offline_id,
|
|
834
1286
|
metadata: {
|
|
835
1287
|
...customer.metadata,
|
|
836
|
-
stall_offline_id: offline_id
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
1288
|
+
stall_offline_id: offline_id,
|
|
1289
|
+
stall_offline_created_at: now,
|
|
1290
|
+
stall_offline_updated_at: now,
|
|
1291
|
+
stall_offline_deleted_at: ""
|
|
1292
|
+
}
|
|
841
1293
|
};
|
|
842
1294
|
await local_db.customers.add(local_customer);
|
|
843
1295
|
await add_to_sync_queue({
|
|
@@ -869,17 +1321,21 @@ var bulk_update3 = async (props) => {
|
|
|
869
1321
|
...existing,
|
|
870
1322
|
...item.data,
|
|
871
1323
|
id: existing.id,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1324
|
+
metadata: {
|
|
1325
|
+
...existing.metadata,
|
|
1326
|
+
...item.data.metadata,
|
|
1327
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1328
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1329
|
+
stall_offline_updated_at: now,
|
|
1330
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1331
|
+
}
|
|
875
1332
|
};
|
|
876
1333
|
await local_db.customers.put(updated_customer);
|
|
877
1334
|
await add_to_sync_queue({
|
|
878
1335
|
action: "update",
|
|
879
1336
|
table: "customers",
|
|
880
1337
|
document_id: item.id,
|
|
881
|
-
|
|
882
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1338
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
883
1339
|
data: updated_customer
|
|
884
1340
|
});
|
|
885
1341
|
updated_customers.push(updated_customer);
|
|
@@ -902,8 +1358,7 @@ var bulk_delete3 = async (props) => {
|
|
|
902
1358
|
action: "delete",
|
|
903
1359
|
table: "customers",
|
|
904
1360
|
document_id: id,
|
|
905
|
-
|
|
906
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1361
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
907
1362
|
data: { id }
|
|
908
1363
|
});
|
|
909
1364
|
await local_db.customers.delete(id);
|
|
@@ -968,11 +1423,11 @@ var create4 = async (props) => {
|
|
|
968
1423
|
id: offline_id,
|
|
969
1424
|
metadata: {
|
|
970
1425
|
...data.metadata,
|
|
971
|
-
stall_offline_id: offline_id
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1426
|
+
stall_offline_id: offline_id,
|
|
1427
|
+
stall_offline_created_at: now,
|
|
1428
|
+
stall_offline_updated_at: now,
|
|
1429
|
+
stall_offline_deleted_at: ""
|
|
1430
|
+
}
|
|
976
1431
|
};
|
|
977
1432
|
await local_db.collections.add(local_collection);
|
|
978
1433
|
await add_to_sync_queue({
|
|
@@ -999,17 +1454,21 @@ var update4 = async (props) => {
|
|
|
999
1454
|
...existing,
|
|
1000
1455
|
...data,
|
|
1001
1456
|
id: existing.id,
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1457
|
+
metadata: {
|
|
1458
|
+
...existing.metadata,
|
|
1459
|
+
...data.metadata,
|
|
1460
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1461
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1462
|
+
stall_offline_updated_at: now,
|
|
1463
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1464
|
+
}
|
|
1005
1465
|
};
|
|
1006
1466
|
await local_db.collections.put(updated_collection);
|
|
1007
1467
|
await add_to_sync_queue({
|
|
1008
1468
|
action: "update",
|
|
1009
1469
|
table: "collections",
|
|
1010
1470
|
document_id: id,
|
|
1011
|
-
|
|
1012
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1471
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1013
1472
|
data: updated_collection
|
|
1014
1473
|
});
|
|
1015
1474
|
return updated_collection;
|
|
@@ -1028,8 +1487,7 @@ var _delete4 = async (props) => {
|
|
|
1028
1487
|
action: "delete",
|
|
1029
1488
|
table: "collections",
|
|
1030
1489
|
document_id: id,
|
|
1031
|
-
|
|
1032
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1490
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1033
1491
|
data: { id }
|
|
1034
1492
|
});
|
|
1035
1493
|
await local_db.collections.delete(id);
|
|
@@ -1050,11 +1508,11 @@ var bulk_create4 = async (props) => {
|
|
|
1050
1508
|
id: offline_id,
|
|
1051
1509
|
metadata: {
|
|
1052
1510
|
...collection.metadata,
|
|
1053
|
-
stall_offline_id: offline_id
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1511
|
+
stall_offline_id: offline_id,
|
|
1512
|
+
stall_offline_created_at: now,
|
|
1513
|
+
stall_offline_updated_at: now,
|
|
1514
|
+
stall_offline_deleted_at: ""
|
|
1515
|
+
}
|
|
1058
1516
|
};
|
|
1059
1517
|
await local_db.collections.add(local_collection);
|
|
1060
1518
|
await add_to_sync_queue({
|
|
@@ -1088,17 +1546,21 @@ var bulk_update4 = async (props) => {
|
|
|
1088
1546
|
...existing,
|
|
1089
1547
|
...item.data,
|
|
1090
1548
|
id: existing.id,
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1549
|
+
metadata: {
|
|
1550
|
+
...existing.metadata,
|
|
1551
|
+
...item.data.metadata,
|
|
1552
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1553
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1554
|
+
stall_offline_updated_at: now,
|
|
1555
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1556
|
+
}
|
|
1094
1557
|
};
|
|
1095
1558
|
await local_db.collections.put(updated_collection);
|
|
1096
1559
|
await add_to_sync_queue({
|
|
1097
1560
|
action: "update",
|
|
1098
1561
|
table: "collections",
|
|
1099
1562
|
document_id: item.id,
|
|
1100
|
-
|
|
1101
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1563
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1102
1564
|
data: updated_collection
|
|
1103
1565
|
});
|
|
1104
1566
|
updated_collections.push(updated_collection);
|
|
@@ -1121,8 +1583,7 @@ var bulk_delete4 = async (props) => {
|
|
|
1121
1583
|
action: "delete",
|
|
1122
1584
|
table: "collections",
|
|
1123
1585
|
document_id: id,
|
|
1124
|
-
|
|
1125
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1586
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1126
1587
|
data: { id }
|
|
1127
1588
|
});
|
|
1128
1589
|
await local_db.collections.delete(id);
|
|
@@ -1187,11 +1648,11 @@ var create5 = async (props) => {
|
|
|
1187
1648
|
id: offline_id,
|
|
1188
1649
|
metadata: {
|
|
1189
1650
|
...data.metadata,
|
|
1190
|
-
stall_offline_id: offline_id
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1651
|
+
stall_offline_id: offline_id,
|
|
1652
|
+
stall_offline_created_at: now,
|
|
1653
|
+
stall_offline_updated_at: now,
|
|
1654
|
+
stall_offline_deleted_at: ""
|
|
1655
|
+
}
|
|
1195
1656
|
};
|
|
1196
1657
|
await local_db.categories.add(local_category);
|
|
1197
1658
|
await add_to_sync_queue({
|
|
@@ -1218,17 +1679,21 @@ var update5 = async (props) => {
|
|
|
1218
1679
|
...existing,
|
|
1219
1680
|
...data,
|
|
1220
1681
|
id: existing.id,
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1682
|
+
metadata: {
|
|
1683
|
+
...existing.metadata,
|
|
1684
|
+
...data.metadata,
|
|
1685
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1686
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1687
|
+
stall_offline_updated_at: now,
|
|
1688
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1689
|
+
}
|
|
1224
1690
|
};
|
|
1225
1691
|
await local_db.categories.put(updated_category);
|
|
1226
1692
|
await add_to_sync_queue({
|
|
1227
1693
|
action: "update",
|
|
1228
1694
|
table: "categories",
|
|
1229
1695
|
document_id: id,
|
|
1230
|
-
|
|
1231
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1696
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1232
1697
|
data: updated_category
|
|
1233
1698
|
});
|
|
1234
1699
|
return updated_category;
|
|
@@ -1247,8 +1712,7 @@ var _delete5 = async (props) => {
|
|
|
1247
1712
|
action: "delete",
|
|
1248
1713
|
table: "categories",
|
|
1249
1714
|
document_id: id,
|
|
1250
|
-
|
|
1251
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1715
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1252
1716
|
data: { id }
|
|
1253
1717
|
});
|
|
1254
1718
|
await local_db.categories.delete(id);
|
|
@@ -1269,11 +1733,11 @@ var bulk_create5 = async (props) => {
|
|
|
1269
1733
|
id: offline_id,
|
|
1270
1734
|
metadata: {
|
|
1271
1735
|
...category.metadata,
|
|
1272
|
-
stall_offline_id: offline_id
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1736
|
+
stall_offline_id: offline_id,
|
|
1737
|
+
stall_offline_created_at: now,
|
|
1738
|
+
stall_offline_updated_at: now,
|
|
1739
|
+
stall_offline_deleted_at: ""
|
|
1740
|
+
}
|
|
1277
1741
|
};
|
|
1278
1742
|
await local_db.categories.add(local_category);
|
|
1279
1743
|
await add_to_sync_queue({
|
|
@@ -1305,17 +1769,21 @@ var bulk_update5 = async (props) => {
|
|
|
1305
1769
|
...existing,
|
|
1306
1770
|
...item.data,
|
|
1307
1771
|
id: existing.id,
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1772
|
+
metadata: {
|
|
1773
|
+
...existing.metadata,
|
|
1774
|
+
...item.data.metadata,
|
|
1775
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1776
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1777
|
+
stall_offline_updated_at: now,
|
|
1778
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1779
|
+
}
|
|
1311
1780
|
};
|
|
1312
1781
|
await local_db.categories.put(updated_category);
|
|
1313
1782
|
await add_to_sync_queue({
|
|
1314
1783
|
action: "update",
|
|
1315
1784
|
table: "categories",
|
|
1316
1785
|
document_id: item.id,
|
|
1317
|
-
|
|
1318
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1786
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1319
1787
|
data: updated_category
|
|
1320
1788
|
});
|
|
1321
1789
|
updated_categories.push(updated_category);
|
|
@@ -1338,8 +1806,7 @@ var bulk_delete5 = async (props) => {
|
|
|
1338
1806
|
action: "delete",
|
|
1339
1807
|
table: "categories",
|
|
1340
1808
|
document_id: id,
|
|
1341
|
-
|
|
1342
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1809
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1343
1810
|
data: { id }
|
|
1344
1811
|
});
|
|
1345
1812
|
await local_db.categories.delete(id);
|
|
@@ -1404,11 +1871,11 @@ var create6 = async (props) => {
|
|
|
1404
1871
|
id: offline_id,
|
|
1405
1872
|
metadata: {
|
|
1406
1873
|
...data.metadata,
|
|
1407
|
-
stall_offline_id: offline_id
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1874
|
+
stall_offline_id: offline_id,
|
|
1875
|
+
stall_offline_created_at: now,
|
|
1876
|
+
stall_offline_updated_at: now,
|
|
1877
|
+
stall_offline_deleted_at: ""
|
|
1878
|
+
}
|
|
1412
1879
|
};
|
|
1413
1880
|
await local_db.variants.add(local_variant);
|
|
1414
1881
|
await add_to_sync_queue({
|
|
@@ -1435,17 +1902,21 @@ var update6 = async (props) => {
|
|
|
1435
1902
|
...existing,
|
|
1436
1903
|
...data,
|
|
1437
1904
|
id: existing.id,
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1905
|
+
metadata: {
|
|
1906
|
+
...existing.metadata,
|
|
1907
|
+
...data.metadata,
|
|
1908
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1909
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
1910
|
+
stall_offline_updated_at: now,
|
|
1911
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
1912
|
+
}
|
|
1441
1913
|
};
|
|
1442
1914
|
await local_db.variants.put(updated_variant);
|
|
1443
1915
|
await add_to_sync_queue({
|
|
1444
1916
|
action: "update",
|
|
1445
1917
|
table: "variants",
|
|
1446
1918
|
document_id: id,
|
|
1447
|
-
|
|
1448
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1919
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1449
1920
|
data: updated_variant
|
|
1450
1921
|
});
|
|
1451
1922
|
return updated_variant;
|
|
@@ -1464,8 +1935,7 @@ var _delete6 = async (props) => {
|
|
|
1464
1935
|
action: "delete",
|
|
1465
1936
|
table: "variants",
|
|
1466
1937
|
document_id: id,
|
|
1467
|
-
|
|
1468
|
-
stall_offline_id: existing.stall_offline_id,
|
|
1938
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1469
1939
|
data: { id }
|
|
1470
1940
|
});
|
|
1471
1941
|
await local_db.variants.delete(id);
|
|
@@ -1486,11 +1956,11 @@ var bulk_create6 = async (props) => {
|
|
|
1486
1956
|
id: offline_id,
|
|
1487
1957
|
metadata: {
|
|
1488
1958
|
...variant.metadata,
|
|
1489
|
-
stall_offline_id: offline_id
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1959
|
+
stall_offline_id: offline_id,
|
|
1960
|
+
stall_offline_created_at: now,
|
|
1961
|
+
stall_offline_updated_at: now,
|
|
1962
|
+
stall_offline_deleted_at: ""
|
|
1963
|
+
}
|
|
1494
1964
|
};
|
|
1495
1965
|
await local_db.variants.add(local_variant);
|
|
1496
1966
|
await add_to_sync_queue({
|
|
@@ -1522,17 +1992,21 @@ var bulk_update6 = async (props) => {
|
|
|
1522
1992
|
...existing,
|
|
1523
1993
|
...item.data,
|
|
1524
1994
|
id: existing.id,
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1995
|
+
metadata: {
|
|
1996
|
+
...existing.metadata,
|
|
1997
|
+
...item.data.metadata,
|
|
1998
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1999
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2000
|
+
stall_offline_updated_at: now,
|
|
2001
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2002
|
+
}
|
|
1528
2003
|
};
|
|
1529
2004
|
await local_db.variants.put(updated_variant);
|
|
1530
2005
|
await add_to_sync_queue({
|
|
1531
2006
|
action: "update",
|
|
1532
2007
|
table: "variants",
|
|
1533
2008
|
document_id: item.id,
|
|
1534
|
-
|
|
1535
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2009
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1536
2010
|
data: updated_variant
|
|
1537
2011
|
});
|
|
1538
2012
|
updated_variants.push(updated_variant);
|
|
@@ -1555,8 +2029,7 @@ var bulk_delete6 = async (props) => {
|
|
|
1555
2029
|
action: "delete",
|
|
1556
2030
|
table: "variants",
|
|
1557
2031
|
document_id: id,
|
|
1558
|
-
|
|
1559
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2032
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1560
2033
|
data: { id }
|
|
1561
2034
|
});
|
|
1562
2035
|
await local_db.variants.delete(id);
|
|
@@ -1621,12 +2094,11 @@ var create7 = async (props) => {
|
|
|
1621
2094
|
id: offline_id,
|
|
1622
2095
|
metadata: {
|
|
1623
2096
|
...data.metadata,
|
|
1624
|
-
stall_offline_id: offline_id
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
stall_offline_updated_at: now
|
|
2097
|
+
stall_offline_id: offline_id,
|
|
2098
|
+
stall_offline_created_at: now,
|
|
2099
|
+
stall_offline_updated_at: now,
|
|
2100
|
+
stall_offline_deleted_at: ""
|
|
2101
|
+
}
|
|
1630
2102
|
};
|
|
1631
2103
|
await local_db.inventory_levels.add(local_inventory_level);
|
|
1632
2104
|
await add_to_sync_queue({
|
|
@@ -1653,17 +2125,21 @@ var update7 = async (props) => {
|
|
|
1653
2125
|
...existing,
|
|
1654
2126
|
...data,
|
|
1655
2127
|
id: existing.id,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
2128
|
+
metadata: {
|
|
2129
|
+
...existing.metadata,
|
|
2130
|
+
...data.metadata,
|
|
2131
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2132
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2133
|
+
stall_offline_updated_at: now,
|
|
2134
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2135
|
+
}
|
|
1659
2136
|
};
|
|
1660
2137
|
await local_db.inventory_levels.put(updated_inventory_level);
|
|
1661
2138
|
await add_to_sync_queue({
|
|
1662
2139
|
action: "update",
|
|
1663
2140
|
table: "inventory_levels",
|
|
1664
2141
|
document_id: id,
|
|
1665
|
-
|
|
1666
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2142
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1667
2143
|
data: updated_inventory_level
|
|
1668
2144
|
});
|
|
1669
2145
|
return updated_inventory_level;
|
|
@@ -1682,8 +2158,7 @@ var _delete7 = async (props) => {
|
|
|
1682
2158
|
action: "delete",
|
|
1683
2159
|
table: "inventory_levels",
|
|
1684
2160
|
document_id: id,
|
|
1685
|
-
|
|
1686
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2161
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1687
2162
|
data: { id }
|
|
1688
2163
|
});
|
|
1689
2164
|
await local_db.inventory_levels.delete(id);
|
|
@@ -1704,12 +2179,11 @@ var bulk_create7 = async (props) => {
|
|
|
1704
2179
|
id: offline_id,
|
|
1705
2180
|
metadata: {
|
|
1706
2181
|
...inventory_level.metadata,
|
|
1707
|
-
stall_offline_id: offline_id
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
stall_offline_updated_at: now
|
|
2182
|
+
stall_offline_id: offline_id,
|
|
2183
|
+
stall_offline_created_at: now,
|
|
2184
|
+
stall_offline_updated_at: now,
|
|
2185
|
+
stall_offline_deleted_at: ""
|
|
2186
|
+
}
|
|
1713
2187
|
};
|
|
1714
2188
|
await local_db.inventory_levels.add(local_inventory_level);
|
|
1715
2189
|
await add_to_sync_queue({
|
|
@@ -1743,17 +2217,21 @@ var bulk_update7 = async (props) => {
|
|
|
1743
2217
|
...existing,
|
|
1744
2218
|
...item.data,
|
|
1745
2219
|
id: existing.id,
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
2220
|
+
metadata: {
|
|
2221
|
+
...existing.metadata,
|
|
2222
|
+
...item.data.metadata,
|
|
2223
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2224
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2225
|
+
stall_offline_updated_at: now,
|
|
2226
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2227
|
+
}
|
|
1749
2228
|
};
|
|
1750
2229
|
await local_db.inventory_levels.put(updated_inventory_level);
|
|
1751
2230
|
await add_to_sync_queue({
|
|
1752
2231
|
action: "update",
|
|
1753
2232
|
table: "inventory_levels",
|
|
1754
2233
|
document_id: item.id,
|
|
1755
|
-
|
|
1756
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2234
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1757
2235
|
data: updated_inventory_level
|
|
1758
2236
|
});
|
|
1759
2237
|
updated_inventory_levels.push(updated_inventory_level);
|
|
@@ -1778,8 +2256,7 @@ var bulk_delete7 = async (props) => {
|
|
|
1778
2256
|
action: "delete",
|
|
1779
2257
|
table: "inventory_levels",
|
|
1780
2258
|
document_id: id,
|
|
1781
|
-
|
|
1782
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2259
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1783
2260
|
data: { id }
|
|
1784
2261
|
});
|
|
1785
2262
|
await local_db.inventory_levels.delete(id);
|
|
@@ -1844,12 +2321,11 @@ var create8 = async (props) => {
|
|
|
1844
2321
|
id: offline_id,
|
|
1845
2322
|
metadata: {
|
|
1846
2323
|
...data.metadata,
|
|
1847
|
-
stall_offline_id: offline_id
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
stall_offline_updated_at: now
|
|
2324
|
+
stall_offline_id: offline_id,
|
|
2325
|
+
stall_offline_created_at: now,
|
|
2326
|
+
stall_offline_updated_at: now,
|
|
2327
|
+
stall_offline_deleted_at: ""
|
|
2328
|
+
}
|
|
1853
2329
|
};
|
|
1854
2330
|
await local_db.promotions.add(local_promotion);
|
|
1855
2331
|
await add_to_sync_queue({
|
|
@@ -1876,17 +2352,21 @@ var update8 = async (props) => {
|
|
|
1876
2352
|
...existing,
|
|
1877
2353
|
...data,
|
|
1878
2354
|
id: existing.id,
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
2355
|
+
metadata: {
|
|
2356
|
+
...existing.metadata,
|
|
2357
|
+
...data.metadata,
|
|
2358
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2359
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2360
|
+
stall_offline_updated_at: now,
|
|
2361
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2362
|
+
}
|
|
1882
2363
|
};
|
|
1883
2364
|
await local_db.promotions.put(updated_promotion);
|
|
1884
2365
|
await add_to_sync_queue({
|
|
1885
2366
|
action: "update",
|
|
1886
2367
|
table: "promotions",
|
|
1887
2368
|
document_id: id,
|
|
1888
|
-
|
|
1889
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2369
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1890
2370
|
data: updated_promotion
|
|
1891
2371
|
});
|
|
1892
2372
|
return updated_promotion;
|
|
@@ -1905,8 +2385,7 @@ var _delete8 = async (props) => {
|
|
|
1905
2385
|
action: "delete",
|
|
1906
2386
|
table: "promotions",
|
|
1907
2387
|
document_id: id,
|
|
1908
|
-
|
|
1909
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2388
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1910
2389
|
data: { id }
|
|
1911
2390
|
});
|
|
1912
2391
|
await local_db.promotions.delete(id);
|
|
@@ -1927,12 +2406,11 @@ var bulk_create8 = async (props) => {
|
|
|
1927
2406
|
id: offline_id,
|
|
1928
2407
|
metadata: {
|
|
1929
2408
|
...promotion.metadata,
|
|
1930
|
-
stall_offline_id: offline_id
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
stall_offline_updated_at: now
|
|
2409
|
+
stall_offline_id: offline_id,
|
|
2410
|
+
stall_offline_created_at: now,
|
|
2411
|
+
stall_offline_updated_at: now,
|
|
2412
|
+
stall_offline_deleted_at: ""
|
|
2413
|
+
}
|
|
1936
2414
|
};
|
|
1937
2415
|
await local_db.promotions.add(local_promotion);
|
|
1938
2416
|
await add_to_sync_queue({
|
|
@@ -1966,17 +2444,21 @@ var bulk_update8 = async (props) => {
|
|
|
1966
2444
|
...existing,
|
|
1967
2445
|
...item.data,
|
|
1968
2446
|
id: existing.id,
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
2447
|
+
metadata: {
|
|
2448
|
+
...existing.metadata,
|
|
2449
|
+
...item.data.metadata,
|
|
2450
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2451
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2452
|
+
stall_offline_updated_at: now,
|
|
2453
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2454
|
+
}
|
|
1972
2455
|
};
|
|
1973
2456
|
await local_db.promotions.put(updated_promotion);
|
|
1974
2457
|
await add_to_sync_queue({
|
|
1975
2458
|
action: "update",
|
|
1976
2459
|
table: "promotions",
|
|
1977
2460
|
document_id: item.id,
|
|
1978
|
-
|
|
1979
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2461
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
1980
2462
|
data: updated_promotion
|
|
1981
2463
|
});
|
|
1982
2464
|
updated_promotions.push(updated_promotion);
|
|
@@ -1999,8 +2481,7 @@ var bulk_delete8 = async (props) => {
|
|
|
1999
2481
|
action: "delete",
|
|
2000
2482
|
table: "promotions",
|
|
2001
2483
|
document_id: id,
|
|
2002
|
-
|
|
2003
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2484
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2004
2485
|
data: { id }
|
|
2005
2486
|
});
|
|
2006
2487
|
await local_db.promotions.delete(id);
|
|
@@ -2065,12 +2546,11 @@ var create9 = async (props) => {
|
|
|
2065
2546
|
id: offline_id,
|
|
2066
2547
|
metadata: {
|
|
2067
2548
|
...data.metadata,
|
|
2068
|
-
stall_offline_id: offline_id
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
stall_offline_updated_at: now
|
|
2549
|
+
stall_offline_id: offline_id,
|
|
2550
|
+
stall_offline_created_at: now,
|
|
2551
|
+
stall_offline_updated_at: now,
|
|
2552
|
+
stall_offline_deleted_at: ""
|
|
2553
|
+
}
|
|
2074
2554
|
};
|
|
2075
2555
|
await local_db.order_notes.add(local_order_note);
|
|
2076
2556
|
await add_to_sync_queue({
|
|
@@ -2097,17 +2577,21 @@ var update9 = async (props) => {
|
|
|
2097
2577
|
...existing,
|
|
2098
2578
|
...data,
|
|
2099
2579
|
id: existing.id,
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2580
|
+
metadata: {
|
|
2581
|
+
...existing.metadata,
|
|
2582
|
+
...data.metadata,
|
|
2583
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2584
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2585
|
+
stall_offline_updated_at: now,
|
|
2586
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2587
|
+
}
|
|
2103
2588
|
};
|
|
2104
2589
|
await local_db.order_notes.put(updated_order_note);
|
|
2105
2590
|
await add_to_sync_queue({
|
|
2106
2591
|
action: "update",
|
|
2107
2592
|
table: "order_notes",
|
|
2108
2593
|
document_id: id,
|
|
2109
|
-
|
|
2110
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2594
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2111
2595
|
data: updated_order_note
|
|
2112
2596
|
});
|
|
2113
2597
|
return updated_order_note;
|
|
@@ -2126,8 +2610,7 @@ var _delete9 = async (props) => {
|
|
|
2126
2610
|
action: "delete",
|
|
2127
2611
|
table: "order_notes",
|
|
2128
2612
|
document_id: id,
|
|
2129
|
-
|
|
2130
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2613
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2131
2614
|
data: { id }
|
|
2132
2615
|
});
|
|
2133
2616
|
await local_db.order_notes.delete(id);
|
|
@@ -2148,12 +2631,11 @@ var bulk_create9 = async (props) => {
|
|
|
2148
2631
|
id: offline_id,
|
|
2149
2632
|
metadata: {
|
|
2150
2633
|
...order_note.metadata,
|
|
2151
|
-
stall_offline_id: offline_id
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
stall_offline_updated_at: now
|
|
2634
|
+
stall_offline_id: offline_id,
|
|
2635
|
+
stall_offline_created_at: now,
|
|
2636
|
+
stall_offline_updated_at: now,
|
|
2637
|
+
stall_offline_deleted_at: ""
|
|
2638
|
+
}
|
|
2157
2639
|
};
|
|
2158
2640
|
await local_db.order_notes.add(local_order_note);
|
|
2159
2641
|
await add_to_sync_queue({
|
|
@@ -2187,17 +2669,21 @@ var bulk_update9 = async (props) => {
|
|
|
2187
2669
|
...existing,
|
|
2188
2670
|
...item.data,
|
|
2189
2671
|
id: existing.id,
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2672
|
+
metadata: {
|
|
2673
|
+
...existing.metadata,
|
|
2674
|
+
...item.data.metadata,
|
|
2675
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2676
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2677
|
+
stall_offline_updated_at: now,
|
|
2678
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2679
|
+
}
|
|
2193
2680
|
};
|
|
2194
2681
|
await local_db.order_notes.put(updated_order_note);
|
|
2195
2682
|
await add_to_sync_queue({
|
|
2196
2683
|
action: "update",
|
|
2197
2684
|
table: "order_notes",
|
|
2198
2685
|
document_id: item.id,
|
|
2199
|
-
|
|
2200
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2686
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2201
2687
|
data: updated_order_note
|
|
2202
2688
|
});
|
|
2203
2689
|
updated_order_notes.push(updated_order_note);
|
|
@@ -2220,8 +2706,7 @@ var bulk_delete9 = async (props) => {
|
|
|
2220
2706
|
action: "delete",
|
|
2221
2707
|
table: "order_notes",
|
|
2222
2708
|
document_id: id,
|
|
2223
|
-
|
|
2224
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2709
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2225
2710
|
data: { id }
|
|
2226
2711
|
});
|
|
2227
2712
|
await local_db.order_notes.delete(id);
|
|
@@ -2286,12 +2771,11 @@ var create10 = async (props) => {
|
|
|
2286
2771
|
id: offline_id,
|
|
2287
2772
|
metadata: {
|
|
2288
2773
|
...data.metadata,
|
|
2289
|
-
stall_offline_id: offline_id
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
stall_offline_updated_at: now
|
|
2774
|
+
stall_offline_id: offline_id,
|
|
2775
|
+
stall_offline_created_at: now,
|
|
2776
|
+
stall_offline_updated_at: now,
|
|
2777
|
+
stall_offline_deleted_at: ""
|
|
2778
|
+
}
|
|
2295
2779
|
};
|
|
2296
2780
|
await local_db.refunds.add(local_refund);
|
|
2297
2781
|
await add_to_sync_queue({
|
|
@@ -2318,17 +2802,21 @@ var update10 = async (props) => {
|
|
|
2318
2802
|
...existing,
|
|
2319
2803
|
...data,
|
|
2320
2804
|
id: existing.id,
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2805
|
+
metadata: {
|
|
2806
|
+
...existing.metadata,
|
|
2807
|
+
...data.metadata,
|
|
2808
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2809
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2810
|
+
stall_offline_updated_at: now,
|
|
2811
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2812
|
+
}
|
|
2324
2813
|
};
|
|
2325
2814
|
await local_db.refunds.put(updated_refund);
|
|
2326
2815
|
await add_to_sync_queue({
|
|
2327
2816
|
action: "update",
|
|
2328
2817
|
table: "refunds",
|
|
2329
2818
|
document_id: id,
|
|
2330
|
-
|
|
2331
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2819
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2332
2820
|
data: updated_refund
|
|
2333
2821
|
});
|
|
2334
2822
|
return updated_refund;
|
|
@@ -2347,8 +2835,7 @@ var _delete10 = async (props) => {
|
|
|
2347
2835
|
action: "delete",
|
|
2348
2836
|
table: "refunds",
|
|
2349
2837
|
document_id: id,
|
|
2350
|
-
|
|
2351
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2838
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2352
2839
|
data: { id }
|
|
2353
2840
|
});
|
|
2354
2841
|
await local_db.refunds.delete(id);
|
|
@@ -2368,13 +2855,12 @@ var bulk_create10 = async (props) => {
|
|
|
2368
2855
|
...refund,
|
|
2369
2856
|
id: offline_id,
|
|
2370
2857
|
metadata: {
|
|
2371
|
-
...refund.metadata,
|
|
2372
|
-
stall_offline_id: offline_id
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
stall_offline_updated_at: now
|
|
2858
|
+
...refund.metadata,
|
|
2859
|
+
stall_offline_id: offline_id,
|
|
2860
|
+
stall_offline_created_at: now,
|
|
2861
|
+
stall_offline_updated_at: now,
|
|
2862
|
+
stall_offline_deleted_at: ""
|
|
2863
|
+
}
|
|
2378
2864
|
};
|
|
2379
2865
|
await local_db.refunds.add(local_refund);
|
|
2380
2866
|
await add_to_sync_queue({
|
|
@@ -2406,17 +2892,21 @@ var bulk_update10 = async (props) => {
|
|
|
2406
2892
|
...existing,
|
|
2407
2893
|
...item.data,
|
|
2408
2894
|
id: existing.id,
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2895
|
+
metadata: {
|
|
2896
|
+
...existing.metadata,
|
|
2897
|
+
...item.data.metadata,
|
|
2898
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2899
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
2900
|
+
stall_offline_updated_at: now,
|
|
2901
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
2902
|
+
}
|
|
2412
2903
|
};
|
|
2413
2904
|
await local_db.refunds.put(updated_refund);
|
|
2414
2905
|
await add_to_sync_queue({
|
|
2415
2906
|
action: "update",
|
|
2416
2907
|
table: "refunds",
|
|
2417
2908
|
document_id: item.id,
|
|
2418
|
-
|
|
2419
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2909
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2420
2910
|
data: updated_refund
|
|
2421
2911
|
});
|
|
2422
2912
|
updated_refunds.push(updated_refund);
|
|
@@ -2439,8 +2929,7 @@ var bulk_delete10 = async (props) => {
|
|
|
2439
2929
|
action: "delete",
|
|
2440
2930
|
table: "refunds",
|
|
2441
2931
|
document_id: id,
|
|
2442
|
-
|
|
2443
|
-
stall_offline_id: existing.stall_offline_id,
|
|
2932
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2444
2933
|
data: { id }
|
|
2445
2934
|
});
|
|
2446
2935
|
await local_db.refunds.delete(id);
|
|
@@ -2504,14 +2993,12 @@ var create11 = async (props) => {
|
|
|
2504
2993
|
...data,
|
|
2505
2994
|
id: offline_id,
|
|
2506
2995
|
metadata: {
|
|
2507
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2508
2996
|
...data.metadata,
|
|
2509
|
-
stall_offline_id: offline_id
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
stall_offline_updated_at: now
|
|
2997
|
+
stall_offline_id: offline_id,
|
|
2998
|
+
stall_offline_created_at: now,
|
|
2999
|
+
stall_offline_updated_at: now,
|
|
3000
|
+
stall_offline_deleted_at: ""
|
|
3001
|
+
}
|
|
2515
3002
|
};
|
|
2516
3003
|
await local_db.payment_providers.add(local_payment_provider);
|
|
2517
3004
|
await add_to_sync_queue({
|
|
@@ -2538,17 +3025,21 @@ var update11 = async (props) => {
|
|
|
2538
3025
|
...existing,
|
|
2539
3026
|
...data,
|
|
2540
3027
|
id: existing.id,
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
3028
|
+
metadata: {
|
|
3029
|
+
...existing.metadata,
|
|
3030
|
+
...data.metadata,
|
|
3031
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3032
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3033
|
+
stall_offline_updated_at: now,
|
|
3034
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3035
|
+
}
|
|
2544
3036
|
};
|
|
2545
3037
|
await local_db.payment_providers.put(updated_payment_provider);
|
|
2546
3038
|
await add_to_sync_queue({
|
|
2547
3039
|
action: "update",
|
|
2548
3040
|
table: "payment_providers",
|
|
2549
3041
|
document_id: id,
|
|
2550
|
-
|
|
2551
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3042
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2552
3043
|
data: updated_payment_provider
|
|
2553
3044
|
});
|
|
2554
3045
|
return updated_payment_provider;
|
|
@@ -2567,8 +3058,7 @@ var _delete11 = async (props) => {
|
|
|
2567
3058
|
action: "delete",
|
|
2568
3059
|
table: "payment_providers",
|
|
2569
3060
|
document_id: id,
|
|
2570
|
-
|
|
2571
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3061
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2572
3062
|
data: { id }
|
|
2573
3063
|
});
|
|
2574
3064
|
await local_db.payment_providers.delete(id);
|
|
@@ -2588,14 +3078,12 @@ var bulk_create11 = async (props) => {
|
|
|
2588
3078
|
...payment_provider,
|
|
2589
3079
|
id: offline_id,
|
|
2590
3080
|
metadata: {
|
|
2591
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2592
3081
|
...payment_provider.metadata,
|
|
2593
|
-
stall_offline_id: offline_id
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
stall_offline_updated_at: now
|
|
3082
|
+
stall_offline_id: offline_id,
|
|
3083
|
+
stall_offline_created_at: now,
|
|
3084
|
+
stall_offline_updated_at: now,
|
|
3085
|
+
stall_offline_deleted_at: ""
|
|
3086
|
+
}
|
|
2599
3087
|
};
|
|
2600
3088
|
await local_db.payment_providers.add(local_payment_provider);
|
|
2601
3089
|
await add_to_sync_queue({
|
|
@@ -2629,17 +3117,21 @@ var bulk_update11 = async (props) => {
|
|
|
2629
3117
|
...existing,
|
|
2630
3118
|
...item.data,
|
|
2631
3119
|
id: existing.id,
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
3120
|
+
metadata: {
|
|
3121
|
+
...existing.metadata,
|
|
3122
|
+
...item.data.metadata,
|
|
3123
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3124
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3125
|
+
stall_offline_updated_at: now,
|
|
3126
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3127
|
+
}
|
|
2635
3128
|
};
|
|
2636
3129
|
await local_db.payment_providers.put(updated_payment_provider);
|
|
2637
3130
|
await add_to_sync_queue({
|
|
2638
3131
|
action: "update",
|
|
2639
3132
|
table: "payment_providers",
|
|
2640
3133
|
document_id: item.id,
|
|
2641
|
-
|
|
2642
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3134
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2643
3135
|
data: updated_payment_provider
|
|
2644
3136
|
});
|
|
2645
3137
|
updated_payment_providers.push(updated_payment_provider);
|
|
@@ -2664,8 +3156,7 @@ var bulk_delete11 = async (props) => {
|
|
|
2664
3156
|
action: "delete",
|
|
2665
3157
|
table: "payment_providers",
|
|
2666
3158
|
document_id: id,
|
|
2667
|
-
|
|
2668
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3159
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2669
3160
|
data: { id }
|
|
2670
3161
|
});
|
|
2671
3162
|
await local_db.payment_providers.delete(id);
|
|
@@ -2730,12 +3221,11 @@ var create12 = async (props) => {
|
|
|
2730
3221
|
id: offline_id,
|
|
2731
3222
|
metadata: {
|
|
2732
3223
|
...data.metadata,
|
|
2733
|
-
stall_offline_id: offline_id
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
stall_offline_updated_at: now
|
|
3224
|
+
stall_offline_id: offline_id,
|
|
3225
|
+
stall_offline_created_at: now,
|
|
3226
|
+
stall_offline_updated_at: now,
|
|
3227
|
+
stall_offline_deleted_at: ""
|
|
3228
|
+
}
|
|
2739
3229
|
};
|
|
2740
3230
|
await local_db.payments.add(local_payment);
|
|
2741
3231
|
await add_to_sync_queue({
|
|
@@ -2762,17 +3252,21 @@ var update12 = async (props) => {
|
|
|
2762
3252
|
...existing,
|
|
2763
3253
|
...data,
|
|
2764
3254
|
id: existing.id,
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
3255
|
+
metadata: {
|
|
3256
|
+
...existing.metadata,
|
|
3257
|
+
...data.metadata,
|
|
3258
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3259
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3260
|
+
stall_offline_updated_at: now,
|
|
3261
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3262
|
+
}
|
|
2768
3263
|
};
|
|
2769
3264
|
await local_db.payments.put(updated_payment);
|
|
2770
3265
|
await add_to_sync_queue({
|
|
2771
3266
|
action: "update",
|
|
2772
3267
|
table: "payments",
|
|
2773
3268
|
document_id: id,
|
|
2774
|
-
|
|
2775
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3269
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2776
3270
|
data: updated_payment
|
|
2777
3271
|
});
|
|
2778
3272
|
return updated_payment;
|
|
@@ -2791,8 +3285,7 @@ var _delete12 = async (props) => {
|
|
|
2791
3285
|
action: "delete",
|
|
2792
3286
|
table: "payments",
|
|
2793
3287
|
document_id: id,
|
|
2794
|
-
|
|
2795
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3288
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2796
3289
|
data: { id }
|
|
2797
3290
|
});
|
|
2798
3291
|
await local_db.payments.delete(id);
|
|
@@ -2813,12 +3306,11 @@ var bulk_create12 = async (props) => {
|
|
|
2813
3306
|
id: offline_id,
|
|
2814
3307
|
metadata: {
|
|
2815
3308
|
...payment.metadata,
|
|
2816
|
-
stall_offline_id: offline_id
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
stall_offline_updated_at: now
|
|
3309
|
+
stall_offline_id: offline_id,
|
|
3310
|
+
stall_offline_created_at: now,
|
|
3311
|
+
stall_offline_updated_at: now,
|
|
3312
|
+
stall_offline_deleted_at: ""
|
|
3313
|
+
}
|
|
2822
3314
|
};
|
|
2823
3315
|
await local_db.payments.add(local_payment);
|
|
2824
3316
|
await add_to_sync_queue({
|
|
@@ -2850,17 +3342,21 @@ var bulk_update12 = async (props) => {
|
|
|
2850
3342
|
...existing,
|
|
2851
3343
|
...item.data,
|
|
2852
3344
|
id: existing.id,
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
3345
|
+
metadata: {
|
|
3346
|
+
...existing.metadata,
|
|
3347
|
+
...item.data.metadata,
|
|
3348
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3349
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3350
|
+
stall_offline_updated_at: now,
|
|
3351
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3352
|
+
}
|
|
2856
3353
|
};
|
|
2857
3354
|
await local_db.payments.put(updated_payment);
|
|
2858
3355
|
await add_to_sync_queue({
|
|
2859
3356
|
action: "update",
|
|
2860
3357
|
table: "payments",
|
|
2861
3358
|
document_id: item.id,
|
|
2862
|
-
|
|
2863
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3359
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2864
3360
|
data: updated_payment
|
|
2865
3361
|
});
|
|
2866
3362
|
updated_payments.push(updated_payment);
|
|
@@ -2883,8 +3379,7 @@ var bulk_delete12 = async (props) => {
|
|
|
2883
3379
|
action: "delete",
|
|
2884
3380
|
table: "payments",
|
|
2885
3381
|
document_id: id,
|
|
2886
|
-
|
|
2887
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3382
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2888
3383
|
data: { id }
|
|
2889
3384
|
});
|
|
2890
3385
|
await local_db.payments.delete(id);
|
|
@@ -2949,11 +3444,11 @@ var create13 = async (props) => {
|
|
|
2949
3444
|
id: offline_id,
|
|
2950
3445
|
metadata: {
|
|
2951
3446
|
...data.metadata,
|
|
2952
|
-
stall_offline_id: offline_id
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
3447
|
+
stall_offline_id: offline_id,
|
|
3448
|
+
stall_offline_created_at: now,
|
|
3449
|
+
stall_offline_updated_at: now,
|
|
3450
|
+
stall_offline_deleted_at: ""
|
|
3451
|
+
}
|
|
2957
3452
|
};
|
|
2958
3453
|
await local_db.tax_regions.add(local_region);
|
|
2959
3454
|
await add_to_sync_queue({
|
|
@@ -2980,17 +3475,21 @@ var update13 = async (props) => {
|
|
|
2980
3475
|
...existing,
|
|
2981
3476
|
...data,
|
|
2982
3477
|
id: existing.id,
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
3478
|
+
metadata: {
|
|
3479
|
+
...existing.metadata,
|
|
3480
|
+
...data.metadata,
|
|
3481
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3482
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3483
|
+
stall_offline_updated_at: now,
|
|
3484
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3485
|
+
}
|
|
2986
3486
|
};
|
|
2987
3487
|
await local_db.tax_regions.put(updated_region);
|
|
2988
3488
|
await add_to_sync_queue({
|
|
2989
3489
|
action: "update",
|
|
2990
3490
|
table: "tax_regions",
|
|
2991
3491
|
document_id: id,
|
|
2992
|
-
|
|
2993
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3492
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
2994
3493
|
data: updated_region
|
|
2995
3494
|
});
|
|
2996
3495
|
return updated_region;
|
|
@@ -3009,8 +3508,7 @@ var _delete13 = async (props) => {
|
|
|
3009
3508
|
action: "delete",
|
|
3010
3509
|
table: "tax_regions",
|
|
3011
3510
|
document_id: id,
|
|
3012
|
-
|
|
3013
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3511
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3014
3512
|
data: { id }
|
|
3015
3513
|
});
|
|
3016
3514
|
await local_db.tax_regions.delete(id);
|
|
@@ -3031,11 +3529,11 @@ var bulk_create13 = async (props) => {
|
|
|
3031
3529
|
id: offline_id,
|
|
3032
3530
|
metadata: {
|
|
3033
3531
|
...region.metadata,
|
|
3034
|
-
stall_offline_id: offline_id
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3532
|
+
stall_offline_id: offline_id,
|
|
3533
|
+
stall_offline_created_at: now,
|
|
3534
|
+
stall_offline_updated_at: now,
|
|
3535
|
+
stall_offline_deleted_at: ""
|
|
3536
|
+
}
|
|
3039
3537
|
};
|
|
3040
3538
|
await local_db.tax_regions.add(local_region);
|
|
3041
3539
|
await add_to_sync_queue({
|
|
@@ -3069,17 +3567,21 @@ var bulk_update13 = async (props) => {
|
|
|
3069
3567
|
...existing,
|
|
3070
3568
|
...item.data,
|
|
3071
3569
|
id: existing.id,
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3570
|
+
metadata: {
|
|
3571
|
+
...existing.metadata,
|
|
3572
|
+
...item.data.metadata,
|
|
3573
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3574
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3575
|
+
stall_offline_updated_at: now,
|
|
3576
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3577
|
+
}
|
|
3075
3578
|
};
|
|
3076
3579
|
await local_db.tax_regions.put(updated_region);
|
|
3077
3580
|
await add_to_sync_queue({
|
|
3078
3581
|
action: "update",
|
|
3079
3582
|
table: "tax_regions",
|
|
3080
3583
|
document_id: item.id,
|
|
3081
|
-
|
|
3082
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3584
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3083
3585
|
data: updated_region
|
|
3084
3586
|
});
|
|
3085
3587
|
updated_regions.push(updated_region);
|
|
@@ -3102,8 +3604,7 @@ var bulk_delete13 = async (props) => {
|
|
|
3102
3604
|
action: "delete",
|
|
3103
3605
|
table: "tax_regions",
|
|
3104
3606
|
document_id: id,
|
|
3105
|
-
|
|
3106
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3607
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3107
3608
|
data: { id }
|
|
3108
3609
|
});
|
|
3109
3610
|
await local_db.tax_regions.delete(id);
|
|
@@ -3168,11 +3669,11 @@ var create14 = async (props) => {
|
|
|
3168
3669
|
id: offline_id,
|
|
3169
3670
|
metadata: {
|
|
3170
3671
|
...data.metadata,
|
|
3171
|
-
stall_offline_id: offline_id
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3672
|
+
stall_offline_id: offline_id,
|
|
3673
|
+
stall_offline_created_at: now,
|
|
3674
|
+
stall_offline_updated_at: now,
|
|
3675
|
+
stall_offline_deleted_at: ""
|
|
3676
|
+
}
|
|
3176
3677
|
};
|
|
3177
3678
|
await local_db.tax_rates.add(local_rate);
|
|
3178
3679
|
await add_to_sync_queue({
|
|
@@ -3199,17 +3700,21 @@ var update14 = async (props) => {
|
|
|
3199
3700
|
...existing,
|
|
3200
3701
|
...data,
|
|
3201
3702
|
id: existing.id,
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3703
|
+
metadata: {
|
|
3704
|
+
...existing.metadata,
|
|
3705
|
+
...data.metadata,
|
|
3706
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3707
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3708
|
+
stall_offline_updated_at: now,
|
|
3709
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3710
|
+
}
|
|
3205
3711
|
};
|
|
3206
3712
|
await local_db.tax_rates.put(updated_rate);
|
|
3207
3713
|
await add_to_sync_queue({
|
|
3208
3714
|
action: "update",
|
|
3209
3715
|
table: "tax_rates",
|
|
3210
3716
|
document_id: id,
|
|
3211
|
-
|
|
3212
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3717
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3213
3718
|
data: updated_rate
|
|
3214
3719
|
});
|
|
3215
3720
|
return updated_rate;
|
|
@@ -3228,8 +3733,7 @@ var _delete14 = async (props) => {
|
|
|
3228
3733
|
action: "delete",
|
|
3229
3734
|
table: "tax_rates",
|
|
3230
3735
|
document_id: id,
|
|
3231
|
-
|
|
3232
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3736
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3233
3737
|
data: { id }
|
|
3234
3738
|
});
|
|
3235
3739
|
await local_db.tax_rates.delete(id);
|
|
@@ -3250,11 +3754,11 @@ var bulk_create14 = async (props) => {
|
|
|
3250
3754
|
id: offline_id,
|
|
3251
3755
|
metadata: {
|
|
3252
3756
|
...rate.metadata,
|
|
3253
|
-
stall_offline_id: offline_id
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3757
|
+
stall_offline_id: offline_id,
|
|
3758
|
+
stall_offline_created_at: now,
|
|
3759
|
+
stall_offline_updated_at: now,
|
|
3760
|
+
stall_offline_deleted_at: ""
|
|
3761
|
+
}
|
|
3258
3762
|
};
|
|
3259
3763
|
await local_db.tax_rates.add(local_rate);
|
|
3260
3764
|
await add_to_sync_queue({
|
|
@@ -3286,17 +3790,21 @@ var bulk_update14 = async (props) => {
|
|
|
3286
3790
|
...existing,
|
|
3287
3791
|
...item.data,
|
|
3288
3792
|
id: existing.id,
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3793
|
+
metadata: {
|
|
3794
|
+
...existing.metadata,
|
|
3795
|
+
...item.data.metadata,
|
|
3796
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3797
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
3798
|
+
stall_offline_updated_at: now,
|
|
3799
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
3800
|
+
}
|
|
3292
3801
|
};
|
|
3293
3802
|
await local_db.tax_rates.put(updated_rate);
|
|
3294
3803
|
await add_to_sync_queue({
|
|
3295
3804
|
action: "update",
|
|
3296
3805
|
table: "tax_rates",
|
|
3297
3806
|
document_id: item.id,
|
|
3298
|
-
|
|
3299
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3807
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3300
3808
|
data: updated_rate
|
|
3301
3809
|
});
|
|
3302
3810
|
updated_rates.push(updated_rate);
|
|
@@ -3319,8 +3827,7 @@ var bulk_delete14 = async (props) => {
|
|
|
3319
3827
|
action: "delete",
|
|
3320
3828
|
table: "tax_rates",
|
|
3321
3829
|
document_id: id,
|
|
3322
|
-
|
|
3323
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3830
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
3324
3831
|
data: { id }
|
|
3325
3832
|
});
|
|
3326
3833
|
await local_db.tax_rates.delete(id);
|
|
@@ -3360,7 +3867,8 @@ var build_location = (data, offline_id, now) => {
|
|
|
3360
3867
|
...data.metadata,
|
|
3361
3868
|
stall_offline_id: offline_id,
|
|
3362
3869
|
stall_offline_created_at: now,
|
|
3363
|
-
stall_offline_updated_at: now
|
|
3870
|
+
stall_offline_updated_at: now,
|
|
3871
|
+
stall_offline_deleted_at: ""
|
|
3364
3872
|
}
|
|
3365
3873
|
};
|
|
3366
3874
|
};
|
|
@@ -3381,9 +3889,10 @@ var merge_location = (existing, updates, now) => {
|
|
|
3381
3889
|
metadata: {
|
|
3382
3890
|
...existing.metadata,
|
|
3383
3891
|
...updates.metadata,
|
|
3384
|
-
stall_offline_id: existing.metadata?.stall_offline_id,
|
|
3385
|
-
stall_offline_created_at: existing.metadata?.stall_offline_created_at,
|
|
3386
|
-
stall_offline_updated_at: now
|
|
3892
|
+
stall_offline_id: existing.metadata?.stall_offline_id || "",
|
|
3893
|
+
stall_offline_created_at: existing.metadata?.stall_offline_created_at || "",
|
|
3894
|
+
stall_offline_updated_at: now,
|
|
3895
|
+
stall_offline_deleted_at: existing.metadata?.stall_offline_deleted_at || ""
|
|
3387
3896
|
}
|
|
3388
3897
|
};
|
|
3389
3898
|
};
|
|
@@ -3537,657 +4046,257 @@ var bulk_delete15 = async (props) => {
|
|
|
3537
4046
|
for (const id of ids) {
|
|
3538
4047
|
const existing = await local_db.locations.get(id);
|
|
3539
4048
|
if (!existing) {
|
|
3540
|
-
console.warn(`Location with id ${id} not found locally, skipping`);
|
|
3541
|
-
continue;
|
|
3542
|
-
}
|
|
3543
|
-
await add_to_sync_queue({
|
|
3544
|
-
action: "delete",
|
|
3545
|
-
table: "locations",
|
|
3546
|
-
document_id: id,
|
|
3547
|
-
stall_offline_id: existing.metadata?.stall_offline_id || id,
|
|
3548
|
-
data: { id }
|
|
3549
|
-
});
|
|
3550
|
-
await local_db.locations.delete(id);
|
|
3551
|
-
}
|
|
3552
|
-
return;
|
|
3553
|
-
} catch (error) {
|
|
3554
|
-
throw error;
|
|
3555
|
-
}
|
|
3556
|
-
};
|
|
3557
|
-
var locations = {
|
|
3558
|
-
list: list15,
|
|
3559
|
-
retrieve: retrieve15,
|
|
3560
|
-
create: create15,
|
|
3561
|
-
update: update15,
|
|
3562
|
-
delete: _delete15,
|
|
3563
|
-
bulk_create: bulk_create15,
|
|
3564
|
-
bulk_update: bulk_update15,
|
|
3565
|
-
bulk_delete: bulk_delete15
|
|
3566
|
-
};
|
|
3567
|
-
|
|
3568
|
-
// src/services/fulfillments.service.ts
|
|
3569
|
-
var list16 = async (props) => {
|
|
3570
|
-
try {
|
|
3571
|
-
const { sdk, query } = props;
|
|
3572
|
-
const adapter = await sdk.adapter();
|
|
3573
|
-
if (!adapter) throw new Error("Adapter not found");
|
|
3574
|
-
const fulfillments2 = await adapter.fulfillments.list({
|
|
3575
|
-
connector_config: sdk.options.configuration,
|
|
3576
|
-
query
|
|
3577
|
-
});
|
|
3578
|
-
await save_bulk_data({
|
|
3579
|
-
table: "fulfillments",
|
|
3580
|
-
data: fulfillments2
|
|
3581
|
-
});
|
|
3582
|
-
return fulfillments2;
|
|
3583
|
-
} catch (error) {
|
|
3584
|
-
throw error;
|
|
3585
|
-
}
|
|
3586
|
-
};
|
|
3587
|
-
var retrieve16 = async (props) => {
|
|
3588
|
-
try {
|
|
3589
|
-
const { sdk, id } = props;
|
|
3590
|
-
const adapter = await sdk.adapter();
|
|
3591
|
-
if (!adapter) throw new Error("Adapter not found");
|
|
3592
|
-
const fulfillment = await adapter.fulfillments.retrieve({
|
|
3593
|
-
connector_config: sdk.options.configuration,
|
|
3594
|
-
id
|
|
3595
|
-
});
|
|
3596
|
-
await local_db.fulfillments.put(fulfillment);
|
|
3597
|
-
return fulfillment;
|
|
3598
|
-
} catch (error) {
|
|
3599
|
-
throw error;
|
|
3600
|
-
}
|
|
3601
|
-
};
|
|
3602
|
-
var create16 = async (props) => {
|
|
3603
|
-
try {
|
|
3604
|
-
const { sdk, data } = props;
|
|
3605
|
-
const offline_id = generate_offline_id("fulfillment");
|
|
3606
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3607
|
-
const local_fulfillment = {
|
|
3608
|
-
...data,
|
|
3609
|
-
id: offline_id,
|
|
3610
|
-
metadata: {
|
|
3611
|
-
...data.metadata,
|
|
3612
|
-
stall_offline_id: offline_id
|
|
3613
|
-
},
|
|
3614
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3615
|
-
stall_offline_id: offline_id,
|
|
3616
|
-
stall_offline_created_at: now,
|
|
3617
|
-
stall_offline_updated_at: now
|
|
3618
|
-
};
|
|
3619
|
-
await local_db.fulfillments.add(local_fulfillment);
|
|
3620
|
-
await add_to_sync_queue({
|
|
3621
|
-
action: "create",
|
|
3622
|
-
table: "fulfillments",
|
|
3623
|
-
document_id: offline_id,
|
|
3624
|
-
stall_offline_id: offline_id,
|
|
3625
|
-
data: local_fulfillment
|
|
3626
|
-
});
|
|
3627
|
-
return local_fulfillment;
|
|
3628
|
-
} catch (error) {
|
|
3629
|
-
throw error;
|
|
3630
|
-
}
|
|
3631
|
-
};
|
|
3632
|
-
var update16 = async (props) => {
|
|
3633
|
-
try {
|
|
3634
|
-
const { sdk, id, data } = props;
|
|
3635
|
-
const existing = await local_db.fulfillments.get(id);
|
|
3636
|
-
if (!existing) {
|
|
3637
|
-
throw new Error(`Fulfillment with id ${id} not found locally`);
|
|
3638
|
-
}
|
|
3639
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3640
|
-
const updated_fulfillment = {
|
|
3641
|
-
...existing,
|
|
3642
|
-
...data,
|
|
3643
|
-
id: existing.id,
|
|
3644
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3645
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3646
|
-
stall_offline_updated_at: now
|
|
3647
|
-
};
|
|
3648
|
-
await local_db.fulfillments.put(updated_fulfillment);
|
|
3649
|
-
await add_to_sync_queue({
|
|
3650
|
-
action: "update",
|
|
3651
|
-
table: "fulfillments",
|
|
3652
|
-
document_id: id,
|
|
3653
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3654
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3655
|
-
data: updated_fulfillment
|
|
3656
|
-
});
|
|
3657
|
-
return updated_fulfillment;
|
|
3658
|
-
} catch (error) {
|
|
3659
|
-
throw error;
|
|
3660
|
-
}
|
|
3661
|
-
};
|
|
3662
|
-
var _delete16 = async (props) => {
|
|
3663
|
-
try {
|
|
3664
|
-
const { sdk, id } = props;
|
|
3665
|
-
const existing = await local_db.fulfillments.get(id);
|
|
3666
|
-
if (!existing) {
|
|
3667
|
-
throw new Error(`Fulfillment with id ${id} not found locally`);
|
|
3668
|
-
}
|
|
3669
|
-
await add_to_sync_queue({
|
|
3670
|
-
action: "delete",
|
|
3671
|
-
table: "fulfillments",
|
|
3672
|
-
document_id: id,
|
|
3673
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3674
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3675
|
-
data: { id }
|
|
3676
|
-
});
|
|
3677
|
-
await local_db.fulfillments.delete(id);
|
|
3678
|
-
return;
|
|
3679
|
-
} catch (error) {
|
|
3680
|
-
throw error;
|
|
3681
|
-
}
|
|
3682
|
-
};
|
|
3683
|
-
var bulk_create16 = async (props) => {
|
|
3684
|
-
try {
|
|
3685
|
-
const { sdk, data } = props;
|
|
3686
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3687
|
-
const created_fulfillments = [];
|
|
3688
|
-
for (const fulfillment of data) {
|
|
3689
|
-
const offline_id = generate_offline_id("fulfillment");
|
|
3690
|
-
const local_fulfillment = {
|
|
3691
|
-
...fulfillment,
|
|
3692
|
-
id: offline_id,
|
|
3693
|
-
metadata: {
|
|
3694
|
-
...fulfillment.metadata,
|
|
3695
|
-
stall_offline_id: offline_id
|
|
3696
|
-
},
|
|
3697
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3698
|
-
stall_offline_id: offline_id,
|
|
3699
|
-
stall_offline_created_at: now,
|
|
3700
|
-
stall_offline_updated_at: now
|
|
3701
|
-
};
|
|
3702
|
-
await local_db.fulfillments.add(local_fulfillment);
|
|
3703
|
-
await add_to_sync_queue({
|
|
3704
|
-
action: "create",
|
|
3705
|
-
table: "fulfillments",
|
|
3706
|
-
document_id: offline_id,
|
|
3707
|
-
stall_offline_id: offline_id,
|
|
3708
|
-
data: local_fulfillment
|
|
3709
|
-
});
|
|
3710
|
-
created_fulfillments.push(local_fulfillment);
|
|
3711
|
-
}
|
|
3712
|
-
return created_fulfillments;
|
|
3713
|
-
} catch (error) {
|
|
3714
|
-
throw error;
|
|
3715
|
-
}
|
|
3716
|
-
};
|
|
3717
|
-
var bulk_update16 = async (props) => {
|
|
3718
|
-
try {
|
|
3719
|
-
const { sdk, data } = props;
|
|
3720
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3721
|
-
const updated_fulfillments = [];
|
|
3722
|
-
for (const item of data) {
|
|
3723
|
-
const existing = await local_db.fulfillments.get(item.id);
|
|
3724
|
-
if (!existing) {
|
|
3725
|
-
console.warn(
|
|
3726
|
-
`Fulfillment with id ${item.id} not found locally, skipping`
|
|
3727
|
-
);
|
|
3728
|
-
continue;
|
|
3729
|
-
}
|
|
3730
|
-
const updated_fulfillment = {
|
|
3731
|
-
...existing,
|
|
3732
|
-
...item.data,
|
|
3733
|
-
id: existing.id,
|
|
3734
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3735
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3736
|
-
stall_offline_updated_at: now
|
|
3737
|
-
};
|
|
3738
|
-
await local_db.fulfillments.put(updated_fulfillment);
|
|
3739
|
-
await add_to_sync_queue({
|
|
3740
|
-
action: "update",
|
|
3741
|
-
table: "fulfillments",
|
|
3742
|
-
document_id: item.id,
|
|
3743
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3744
|
-
stall_offline_id: existing.stall_offline_id,
|
|
3745
|
-
data: updated_fulfillment
|
|
3746
|
-
});
|
|
3747
|
-
updated_fulfillments.push(updated_fulfillment);
|
|
3748
|
-
}
|
|
3749
|
-
return updated_fulfillments;
|
|
3750
|
-
} catch (error) {
|
|
3751
|
-
throw error;
|
|
3752
|
-
}
|
|
3753
|
-
};
|
|
3754
|
-
var bulk_delete16 = async (props) => {
|
|
3755
|
-
try {
|
|
3756
|
-
const { sdk, ids } = props;
|
|
3757
|
-
for (const id of ids) {
|
|
3758
|
-
const existing = await local_db.fulfillments.get(id);
|
|
3759
|
-
if (!existing) {
|
|
3760
|
-
console.warn(`Fulfillment with id ${id} not found locally, skipping`);
|
|
4049
|
+
console.warn(`Location with id ${id} not found locally, skipping`);
|
|
3761
4050
|
continue;
|
|
3762
4051
|
}
|
|
3763
4052
|
await add_to_sync_queue({
|
|
3764
4053
|
action: "delete",
|
|
3765
|
-
table: "
|
|
4054
|
+
table: "locations",
|
|
3766
4055
|
document_id: id,
|
|
3767
|
-
|
|
3768
|
-
stall_offline_id: existing.stall_offline_id,
|
|
4056
|
+
stall_offline_id: existing.metadata?.stall_offline_id || id,
|
|
3769
4057
|
data: { id }
|
|
3770
4058
|
});
|
|
3771
|
-
await local_db.
|
|
4059
|
+
await local_db.locations.delete(id);
|
|
3772
4060
|
}
|
|
3773
4061
|
return;
|
|
3774
4062
|
} catch (error) {
|
|
3775
4063
|
throw error;
|
|
3776
4064
|
}
|
|
3777
4065
|
};
|
|
3778
|
-
var
|
|
3779
|
-
list:
|
|
3780
|
-
retrieve:
|
|
3781
|
-
create:
|
|
3782
|
-
update:
|
|
3783
|
-
delete:
|
|
3784
|
-
bulk_create:
|
|
3785
|
-
bulk_update:
|
|
3786
|
-
bulk_delete:
|
|
3787
|
-
};
|
|
3788
|
-
|
|
3789
|
-
// src/services/sync/sync-dependencies.ts
|
|
3790
|
-
var SYNC_DEPENDENCY_LAYERS = {
|
|
3791
|
-
1: [
|
|
3792
|
-
"tax_regions",
|
|
3793
|
-
"tax_rates",
|
|
3794
|
-
"categories",
|
|
3795
|
-
"collections",
|
|
3796
|
-
"locations",
|
|
3797
|
-
"payment_providers",
|
|
3798
|
-
"customers",
|
|
3799
|
-
"promotions"
|
|
3800
|
-
],
|
|
3801
|
-
2: ["products"],
|
|
3802
|
-
3: ["variants", "inventory_levels"],
|
|
3803
|
-
4: ["orders", "order_notes"],
|
|
3804
|
-
5: ["payments", "refunds", "fulfillments"]
|
|
3805
|
-
};
|
|
3806
|
-
var get_entity_dependencies = (table) => {
|
|
3807
|
-
const dependencies = {
|
|
3808
|
-
// Layer 1: Independent
|
|
3809
|
-
tax_regions: [],
|
|
3810
|
-
tax_rates: ["tax_regions"],
|
|
3811
|
-
categories: [],
|
|
3812
|
-
collections: [],
|
|
3813
|
-
locations: [],
|
|
3814
|
-
payment_providers: [],
|
|
3815
|
-
customers: [],
|
|
3816
|
-
promotions: [],
|
|
3817
|
-
// Layer 2: Product
|
|
3818
|
-
products: ["categories", "collections"],
|
|
3819
|
-
// Layer 3: Variants & Inventory
|
|
3820
|
-
variants: ["products"],
|
|
3821
|
-
inventory_levels: ["products", "variants"],
|
|
3822
|
-
inventory_history: ["products", "variants"],
|
|
3823
|
-
// Layer 4: Orders
|
|
3824
|
-
orders: ["customers", "products", "variants", "locations"],
|
|
3825
|
-
order_notes: ["orders"],
|
|
3826
|
-
// Layer 5: Order-related
|
|
3827
|
-
payments: ["orders", "payment_providers"],
|
|
3828
|
-
refunds: ["orders", "payments"],
|
|
3829
|
-
fulfillments: ["orders"],
|
|
3830
|
-
// Tags
|
|
3831
|
-
tags: ["products"],
|
|
3832
|
-
// Fulfillment config
|
|
3833
|
-
fulfillment_types: [],
|
|
3834
|
-
fulfillment_providers: []
|
|
3835
|
-
};
|
|
3836
|
-
return dependencies[table] || [];
|
|
3837
|
-
};
|
|
3838
|
-
var get_sync_layer = (table) => {
|
|
3839
|
-
for (const [layer, tables] of Object.entries(SYNC_DEPENDENCY_LAYERS)) {
|
|
3840
|
-
if (tables.includes(table)) {
|
|
3841
|
-
return parseInt(layer);
|
|
3842
|
-
}
|
|
3843
|
-
}
|
|
3844
|
-
return 99;
|
|
3845
|
-
};
|
|
3846
|
-
var sort_by_dependency_order = (items) => {
|
|
3847
|
-
return items.sort((a, b) => {
|
|
3848
|
-
const layer_a = get_sync_layer(a.table);
|
|
3849
|
-
const layer_b = get_sync_layer(b.table);
|
|
3850
|
-
if (layer_a !== layer_b) {
|
|
3851
|
-
return layer_a - layer_b;
|
|
3852
|
-
}
|
|
3853
|
-
return 0;
|
|
3854
|
-
});
|
|
3855
|
-
};
|
|
3856
|
-
var are_dependencies_satisfied = (table, synced_tables) => {
|
|
3857
|
-
const dependencies = get_entity_dependencies(table);
|
|
3858
|
-
return dependencies.every((dep) => synced_tables.has(dep));
|
|
4066
|
+
var locations = {
|
|
4067
|
+
list: list15,
|
|
4068
|
+
retrieve: retrieve15,
|
|
4069
|
+
create: create15,
|
|
4070
|
+
update: update15,
|
|
4071
|
+
delete: _delete15,
|
|
4072
|
+
bulk_create: bulk_create15,
|
|
4073
|
+
bulk_update: bulk_update15,
|
|
4074
|
+
bulk_delete: bulk_delete15
|
|
3859
4075
|
};
|
|
3860
4076
|
|
|
3861
|
-
// src/services/
|
|
3862
|
-
var
|
|
3863
|
-
var replace_temporary_ids = async (props) => {
|
|
3864
|
-
const { table, stall_offline_id, connector_id, local_data } = props;
|
|
4077
|
+
// src/services/fulfillments.service.ts
|
|
4078
|
+
var list16 = async (props) => {
|
|
3865
4079
|
try {
|
|
3866
|
-
const
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
}
|
|
3873
|
-
await
|
|
3874
|
-
table,
|
|
3875
|
-
|
|
3876
|
-
new_id: connector_id
|
|
4080
|
+
const { sdk, query } = props;
|
|
4081
|
+
const adapter = await sdk.adapter();
|
|
4082
|
+
if (!adapter) throw new Error("Adapter not found");
|
|
4083
|
+
const fulfillments2 = await adapter.fulfillments.list({
|
|
4084
|
+
connector_config: sdk.options.configuration,
|
|
4085
|
+
query
|
|
4086
|
+
});
|
|
4087
|
+
await save_bulk_data({
|
|
4088
|
+
table: "fulfillments",
|
|
4089
|
+
data: fulfillments2
|
|
3877
4090
|
});
|
|
4091
|
+
return fulfillments2;
|
|
3878
4092
|
} catch (error) {
|
|
3879
|
-
console.error(`Error replacing temporary IDs for ${table}:`, error);
|
|
3880
4093
|
throw error;
|
|
3881
4094
|
}
|
|
3882
4095
|
};
|
|
3883
|
-
var
|
|
3884
|
-
const { table, old_id, new_id } = props;
|
|
3885
|
-
try {
|
|
3886
|
-
const reference_map = {
|
|
3887
|
-
products: [
|
|
3888
|
-
{ table: "variants", field: "product_id" },
|
|
3889
|
-
{ table: "inventory_levels", field: "product_id" }
|
|
3890
|
-
],
|
|
3891
|
-
variants: [{ table: "inventory_levels", field: "variant_id" }],
|
|
3892
|
-
customers: [{ table: "orders", field: "customer_id" }],
|
|
3893
|
-
orders: [
|
|
3894
|
-
{ table: "payments", field: "order_id" },
|
|
3895
|
-
{ table: "refunds", field: "order_id" },
|
|
3896
|
-
{ table: "order_notes", field: "order_id" },
|
|
3897
|
-
{ table: "fulfillments", field: "order_id" }
|
|
3898
|
-
],
|
|
3899
|
-
payments: [{ table: "refunds", field: "payment_id" }],
|
|
3900
|
-
locations: [{ table: "orders", field: "location_id" }],
|
|
3901
|
-
categories: [{ table: "products", field: "category_id" }],
|
|
3902
|
-
collections: [{ table: "products", field: "collection_id" }],
|
|
3903
|
-
tax_regions: [{ table: "tax_rates", field: "region_id" }],
|
|
3904
|
-
tax_rates: [],
|
|
3905
|
-
tags: [],
|
|
3906
|
-
inventory_levels: [],
|
|
3907
|
-
inventory_history: [],
|
|
3908
|
-
promotions: [],
|
|
3909
|
-
order_notes: [],
|
|
3910
|
-
refunds: [],
|
|
3911
|
-
payment_providers: [],
|
|
3912
|
-
fulfillments: [],
|
|
3913
|
-
fulfillment_types: [],
|
|
3914
|
-
fulfillment_providers: []
|
|
3915
|
-
};
|
|
3916
|
-
const references = reference_map[table] || [];
|
|
3917
|
-
for (const ref of references) {
|
|
3918
|
-
const records = await local_db[ref.table].toArray();
|
|
3919
|
-
const updates = records.filter((record) => record[ref.field] === old_id).map((record) => ({
|
|
3920
|
-
...record,
|
|
3921
|
-
[ref.field]: new_id
|
|
3922
|
-
}));
|
|
3923
|
-
if (updates.length > 0) {
|
|
3924
|
-
await local_db[ref.table].bulkPut(updates);
|
|
3925
|
-
}
|
|
3926
|
-
}
|
|
3927
|
-
} catch (error) {
|
|
3928
|
-
console.error(`Error updating dependent references for ${table}:`, error);
|
|
3929
|
-
}
|
|
3930
|
-
};
|
|
3931
|
-
var sync_queue_item = async (props) => {
|
|
3932
|
-
const { sdk, item, sync_batch_id } = props;
|
|
3933
|
-
const start_time = Date.now();
|
|
4096
|
+
var retrieve16 = async (props) => {
|
|
3934
4097
|
try {
|
|
4098
|
+
const { sdk, id } = props;
|
|
3935
4099
|
const adapter = await sdk.adapter();
|
|
3936
|
-
if (!adapter)
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
const table_module = adapter[item.table];
|
|
3941
|
-
if (!table_module) {
|
|
3942
|
-
throw new Error(`Module ${item.table} not found in adapter`);
|
|
3943
|
-
}
|
|
3944
|
-
let connector_id;
|
|
3945
|
-
if (item.action === "create") {
|
|
3946
|
-
const result = await table_module.create({
|
|
3947
|
-
connector_config,
|
|
3948
|
-
data: item.data
|
|
3949
|
-
});
|
|
3950
|
-
connector_id = result?.id;
|
|
3951
|
-
if (connector_id) {
|
|
3952
|
-
await replace_temporary_ids({
|
|
3953
|
-
table: item.table,
|
|
3954
|
-
stall_offline_id: item.stall_offline_id,
|
|
3955
|
-
connector_id,
|
|
3956
|
-
local_data: result
|
|
3957
|
-
});
|
|
3958
|
-
}
|
|
3959
|
-
} else if (item.action === "update") {
|
|
3960
|
-
const result = await table_module.update({
|
|
3961
|
-
connector_config,
|
|
3962
|
-
id: item.document_id,
|
|
3963
|
-
data: item.data
|
|
3964
|
-
});
|
|
3965
|
-
connector_id = result?.id || item.document_id;
|
|
3966
|
-
} else if (item.action === "delete") {
|
|
3967
|
-
await table_module.delete({
|
|
3968
|
-
connector_config,
|
|
3969
|
-
id: item.document_id
|
|
3970
|
-
});
|
|
3971
|
-
connector_id = item.document_id;
|
|
3972
|
-
}
|
|
3973
|
-
const duration = Date.now() - start_time;
|
|
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
|
-
connector_id,
|
|
3981
|
-
status: "success",
|
|
3982
|
-
duration_ms: duration
|
|
3983
|
-
});
|
|
3984
|
-
await remove_from_sync_queue(item.id);
|
|
3985
|
-
return { success: true, connector_id };
|
|
3986
|
-
} catch (error) {
|
|
3987
|
-
const duration = Date.now() - start_time;
|
|
3988
|
-
console.error(`Error syncing item ${item.id}:`, error);
|
|
3989
|
-
const current_retries = item.retry_count || 0;
|
|
3990
|
-
if (current_retries < MAX_RETRIES) {
|
|
3991
|
-
await update_sync_queue_status({
|
|
3992
|
-
id: item.id,
|
|
3993
|
-
status: "pending",
|
|
3994
|
-
error: error.message,
|
|
3995
|
-
retry_count: current_retries + 1
|
|
3996
|
-
});
|
|
3997
|
-
} else {
|
|
3998
|
-
await update_sync_queue_status({
|
|
3999
|
-
id: item.id,
|
|
4000
|
-
status: "failed",
|
|
4001
|
-
error: `Max retries exceeded: ${error.message}`
|
|
4002
|
-
});
|
|
4003
|
-
}
|
|
4004
|
-
await add_sync_log({
|
|
4005
|
-
sync_batch_id,
|
|
4006
|
-
table: item.table,
|
|
4007
|
-
action: item.action,
|
|
4008
|
-
document_id: item.document_id,
|
|
4009
|
-
stall_offline_id: item.stall_offline_id,
|
|
4010
|
-
status: "failed",
|
|
4011
|
-
error: error.message,
|
|
4012
|
-
duration_ms: duration
|
|
4100
|
+
if (!adapter) throw new Error("Adapter not found");
|
|
4101
|
+
const fulfillment = await adapter.fulfillments.retrieve({
|
|
4102
|
+
connector_config: sdk.options.configuration,
|
|
4103
|
+
id
|
|
4013
4104
|
});
|
|
4014
|
-
|
|
4105
|
+
await local_db.fulfillments.put(fulfillment);
|
|
4106
|
+
return fulfillment;
|
|
4107
|
+
} catch (error) {
|
|
4108
|
+
throw error;
|
|
4015
4109
|
}
|
|
4016
4110
|
};
|
|
4017
|
-
var
|
|
4018
|
-
const { sdk } = props;
|
|
4019
|
-
const sync_batch_id = generate_uuid();
|
|
4111
|
+
var create16 = async (props) => {
|
|
4020
4112
|
try {
|
|
4021
|
-
const
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
const summary_data = [];
|
|
4034
|
-
const all_items = [];
|
|
4035
|
-
pending_items_by_table.forEach((items) => {
|
|
4036
|
-
items.forEach((item) => {
|
|
4037
|
-
all_items.push(item);
|
|
4038
|
-
});
|
|
4039
|
-
});
|
|
4040
|
-
const sorted_items = sort_by_dependency_order(
|
|
4041
|
-
all_items
|
|
4042
|
-
);
|
|
4043
|
-
const synced_tables = /* @__PURE__ */ new Set();
|
|
4044
|
-
const items_to_retry = [];
|
|
4045
|
-
for (const item of sorted_items) {
|
|
4046
|
-
if (!are_dependencies_satisfied(item.table, synced_tables)) {
|
|
4047
|
-
items_to_retry.push(item);
|
|
4048
|
-
continue;
|
|
4049
|
-
}
|
|
4050
|
-
await update_sync_queue_status({
|
|
4051
|
-
id: item.id,
|
|
4052
|
-
status: "syncing"
|
|
4053
|
-
});
|
|
4054
|
-
const result = await sync_queue_item({
|
|
4055
|
-
sdk,
|
|
4056
|
-
item,
|
|
4057
|
-
sync_batch_id
|
|
4058
|
-
});
|
|
4059
|
-
if (result.success) {
|
|
4060
|
-
total_synced++;
|
|
4061
|
-
if (!synced_tables.has(item.table)) {
|
|
4062
|
-
synced_tables.add(item.table);
|
|
4063
|
-
}
|
|
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
|
-
} else {
|
|
4075
|
-
summary_data.push({
|
|
4076
|
-
table: item.table,
|
|
4077
|
-
synced: result.success ? 1 : 0,
|
|
4078
|
-
failed: result.success ? 0 : 1
|
|
4079
|
-
});
|
|
4113
|
+
const { sdk, data } = props;
|
|
4114
|
+
const offline_id = generate_offline_id("fulfillment");
|
|
4115
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4116
|
+
const local_fulfillment = {
|
|
4117
|
+
...data,
|
|
4118
|
+
id: offline_id,
|
|
4119
|
+
metadata: {
|
|
4120
|
+
...data.metadata,
|
|
4121
|
+
stall_offline_id: offline_id,
|
|
4122
|
+
stall_offline_created_at: now,
|
|
4123
|
+
stall_offline_updated_at: now,
|
|
4124
|
+
stall_offline_deleted_at: ""
|
|
4080
4125
|
}
|
|
4126
|
+
};
|
|
4127
|
+
await local_db.fulfillments.add(local_fulfillment);
|
|
4128
|
+
await add_to_sync_queue({
|
|
4129
|
+
action: "create",
|
|
4130
|
+
table: "fulfillments",
|
|
4131
|
+
document_id: offline_id,
|
|
4132
|
+
stall_offline_id: offline_id,
|
|
4133
|
+
data: local_fulfillment
|
|
4134
|
+
});
|
|
4135
|
+
return local_fulfillment;
|
|
4136
|
+
} catch (error) {
|
|
4137
|
+
throw error;
|
|
4138
|
+
}
|
|
4139
|
+
};
|
|
4140
|
+
var update16 = async (props) => {
|
|
4141
|
+
try {
|
|
4142
|
+
const { sdk, id, data } = props;
|
|
4143
|
+
const existing = await local_db.fulfillments.get(id);
|
|
4144
|
+
if (!existing) {
|
|
4145
|
+
throw new Error(`Fulfillment with id ${id} not found locally`);
|
|
4081
4146
|
}
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
} else {
|
|
4095
|
-
total_failed++;
|
|
4096
|
-
}
|
|
4097
|
-
const table_summary = summary_data.find((s) => s.table === item.table);
|
|
4098
|
-
if (table_summary) {
|
|
4099
|
-
if (result.success) {
|
|
4100
|
-
table_summary.synced++;
|
|
4101
|
-
} else {
|
|
4102
|
-
table_summary.failed++;
|
|
4103
|
-
}
|
|
4147
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4148
|
+
const updated_fulfillment = {
|
|
4149
|
+
...existing,
|
|
4150
|
+
...data,
|
|
4151
|
+
id: existing.id,
|
|
4152
|
+
metadata: {
|
|
4153
|
+
...existing.metadata,
|
|
4154
|
+
...data.metadata,
|
|
4155
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
4156
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
4157
|
+
stall_offline_updated_at: now,
|
|
4158
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
4104
4159
|
}
|
|
4105
|
-
}
|
|
4106
|
-
return {
|
|
4107
|
-
sync_batch_id,
|
|
4108
|
-
total: all_items.length,
|
|
4109
|
-
synced: total_synced,
|
|
4110
|
-
failed: total_failed,
|
|
4111
|
-
summary: summary_data
|
|
4112
4160
|
};
|
|
4161
|
+
await local_db.fulfillments.put(updated_fulfillment);
|
|
4162
|
+
await add_to_sync_queue({
|
|
4163
|
+
action: "update",
|
|
4164
|
+
table: "fulfillments",
|
|
4165
|
+
document_id: id,
|
|
4166
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
4167
|
+
data: updated_fulfillment
|
|
4168
|
+
});
|
|
4169
|
+
return updated_fulfillment;
|
|
4113
4170
|
} catch (error) {
|
|
4114
|
-
|
|
4115
|
-
return {
|
|
4116
|
-
sync_batch_id,
|
|
4117
|
-
total: 0,
|
|
4118
|
-
synced: 0,
|
|
4119
|
-
failed: 0,
|
|
4120
|
-
summary: []
|
|
4121
|
-
};
|
|
4171
|
+
throw error;
|
|
4122
4172
|
}
|
|
4123
4173
|
};
|
|
4124
|
-
var
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4174
|
+
var _delete16 = async (props) => {
|
|
4175
|
+
try {
|
|
4176
|
+
const { sdk, id } = props;
|
|
4177
|
+
const existing = await local_db.fulfillments.get(id);
|
|
4178
|
+
if (!existing) {
|
|
4179
|
+
throw new Error(`Fulfillment with id ${id} not found locally`);
|
|
4180
|
+
}
|
|
4181
|
+
await add_to_sync_queue({
|
|
4182
|
+
action: "delete",
|
|
4183
|
+
table: "fulfillments",
|
|
4184
|
+
document_id: id,
|
|
4185
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
4186
|
+
data: { id }
|
|
4187
|
+
});
|
|
4188
|
+
await local_db.fulfillments.delete(id);
|
|
4129
4189
|
return;
|
|
4190
|
+
} catch (error) {
|
|
4191
|
+
throw error;
|
|
4130
4192
|
}
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
const
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
);
|
|
4139
|
-
|
|
4140
|
-
|
|
4193
|
+
};
|
|
4194
|
+
var bulk_create16 = async (props) => {
|
|
4195
|
+
try {
|
|
4196
|
+
const { sdk, data } = props;
|
|
4197
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4198
|
+
const created_fulfillments = [];
|
|
4199
|
+
for (const fulfillment of data) {
|
|
4200
|
+
const offline_id = generate_offline_id("fulfillment");
|
|
4201
|
+
const local_fulfillment = {
|
|
4202
|
+
...fulfillment,
|
|
4203
|
+
id: offline_id,
|
|
4204
|
+
metadata: {
|
|
4205
|
+
...fulfillment.metadata,
|
|
4206
|
+
stall_offline_id: offline_id,
|
|
4207
|
+
stall_offline_created_at: now,
|
|
4208
|
+
stall_offline_updated_at: now,
|
|
4209
|
+
stall_offline_deleted_at: ""
|
|
4210
|
+
}
|
|
4211
|
+
};
|
|
4212
|
+
await local_db.fulfillments.add(local_fulfillment);
|
|
4213
|
+
await add_to_sync_queue({
|
|
4214
|
+
action: "create",
|
|
4215
|
+
table: "fulfillments",
|
|
4216
|
+
document_id: offline_id,
|
|
4217
|
+
stall_offline_id: offline_id,
|
|
4218
|
+
data: local_fulfillment
|
|
4141
4219
|
});
|
|
4220
|
+
created_fulfillments.push(local_fulfillment);
|
|
4142
4221
|
}
|
|
4143
|
-
|
|
4144
|
-
}
|
|
4145
|
-
|
|
4146
|
-
if (sync_interval) {
|
|
4147
|
-
clearInterval(sync_interval);
|
|
4148
|
-
sync_interval = null;
|
|
4149
|
-
console.log("Offline sync service stopped");
|
|
4222
|
+
return created_fulfillments;
|
|
4223
|
+
} catch (error) {
|
|
4224
|
+
throw error;
|
|
4150
4225
|
}
|
|
4151
4226
|
};
|
|
4152
|
-
var
|
|
4227
|
+
var bulk_update16 = async (props) => {
|
|
4153
4228
|
try {
|
|
4154
|
-
const
|
|
4155
|
-
const
|
|
4156
|
-
const
|
|
4157
|
-
const
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4229
|
+
const { sdk, data } = props;
|
|
4230
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4231
|
+
const updated_fulfillments = [];
|
|
4232
|
+
for (const item of data) {
|
|
4233
|
+
const existing = await local_db.fulfillments.get(item.id);
|
|
4234
|
+
if (!existing) {
|
|
4235
|
+
console.warn(
|
|
4236
|
+
`Fulfillment with id ${item.id} not found locally, skipping`
|
|
4237
|
+
);
|
|
4238
|
+
continue;
|
|
4239
|
+
}
|
|
4240
|
+
const updated_fulfillment = {
|
|
4241
|
+
...existing,
|
|
4242
|
+
...item.data,
|
|
4243
|
+
id: existing.id,
|
|
4244
|
+
metadata: {
|
|
4245
|
+
...existing.metadata,
|
|
4246
|
+
...item.data.metadata,
|
|
4247
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
4248
|
+
stall_offline_created_at: existing.metadata.stall_offline_created_at,
|
|
4249
|
+
stall_offline_updated_at: now,
|
|
4250
|
+
stall_offline_deleted_at: existing.metadata.stall_offline_deleted_at
|
|
4251
|
+
}
|
|
4252
|
+
};
|
|
4253
|
+
await local_db.fulfillments.put(updated_fulfillment);
|
|
4254
|
+
await add_to_sync_queue({
|
|
4255
|
+
action: "update",
|
|
4256
|
+
table: "fulfillments",
|
|
4257
|
+
document_id: item.id,
|
|
4258
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
4259
|
+
data: updated_fulfillment
|
|
4260
|
+
});
|
|
4261
|
+
updated_fulfillments.push(updated_fulfillment);
|
|
4262
|
+
}
|
|
4263
|
+
return updated_fulfillments;
|
|
4164
4264
|
} catch (error) {
|
|
4165
|
-
|
|
4166
|
-
return { pending: 0, syncing: 0, failed: 0, total: 0 };
|
|
4265
|
+
throw error;
|
|
4167
4266
|
}
|
|
4168
4267
|
};
|
|
4169
|
-
var
|
|
4268
|
+
var bulk_delete16 = async (props) => {
|
|
4170
4269
|
try {
|
|
4171
|
-
const { sdk } = props;
|
|
4172
|
-
|
|
4270
|
+
const { sdk, ids } = props;
|
|
4271
|
+
for (const id of ids) {
|
|
4272
|
+
const existing = await local_db.fulfillments.get(id);
|
|
4273
|
+
if (!existing) {
|
|
4274
|
+
console.warn(`Fulfillment with id ${id} not found locally, skipping`);
|
|
4275
|
+
continue;
|
|
4276
|
+
}
|
|
4277
|
+
await add_to_sync_queue({
|
|
4278
|
+
action: "delete",
|
|
4279
|
+
table: "fulfillments",
|
|
4280
|
+
document_id: id,
|
|
4281
|
+
stall_offline_id: existing.metadata.stall_offline_id,
|
|
4282
|
+
data: { id }
|
|
4283
|
+
});
|
|
4284
|
+
await local_db.fulfillments.delete(id);
|
|
4285
|
+
}
|
|
4286
|
+
return;
|
|
4173
4287
|
} catch (error) {
|
|
4174
|
-
|
|
4175
|
-
return {
|
|
4176
|
-
sync_batch_id: generate_uuid(),
|
|
4177
|
-
total: 0,
|
|
4178
|
-
synced: 0,
|
|
4179
|
-
failed: 0,
|
|
4180
|
-
summary: []
|
|
4181
|
-
};
|
|
4288
|
+
throw error;
|
|
4182
4289
|
}
|
|
4183
4290
|
};
|
|
4184
|
-
var
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4291
|
+
var fulfillments = {
|
|
4292
|
+
list: list16,
|
|
4293
|
+
retrieve: retrieve16,
|
|
4294
|
+
create: create16,
|
|
4295
|
+
update: update16,
|
|
4296
|
+
delete: _delete16,
|
|
4297
|
+
bulk_create: bulk_create16,
|
|
4298
|
+
bulk_update: bulk_update16,
|
|
4299
|
+
bulk_delete: bulk_delete16
|
|
4191
4300
|
};
|
|
4192
4301
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4193
4302
|
0 && (module.exports = {
|
|
@@ -4204,6 +4313,8 @@ var sync_service = {
|
|
|
4204
4313
|
get_sync_logs_by_batch,
|
|
4205
4314
|
initializeStallCore,
|
|
4206
4315
|
inventory_levels,
|
|
4316
|
+
is_offline,
|
|
4317
|
+
is_online,
|
|
4207
4318
|
local_db,
|
|
4208
4319
|
locations,
|
|
4209
4320
|
order_notes,
|