@use-stall/core 0.0.13 → 0.0.15

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 CHANGED
@@ -855,6 +855,10 @@ declare const get_recent_sync_logs: (props?: {
855
855
  table?: ConnectorModuleKey;
856
856
  status?: "success" | "failed" | "pending";
857
857
  }) => Promise<SyncLogType[]>;
858
+ /**
859
+ * Check if sync queue is empty (all pending items synced)
860
+ */
861
+ declare const is_sync_queue_empty: () => Promise<boolean>;
858
862
  /**
859
863
  * Clear old sync logs (keep last N days)
860
864
  */
@@ -893,4 +897,4 @@ declare const is_online: () => boolean;
893
897
  */
894
898
  declare const is_offline: () => boolean;
895
899
 
896
- export { add_sync_log, add_to_sync_queue, categories, cleanup_old_sync_logs, collections, customers, fulfillments, generate_offline_id, get_pending_sync_queue, get_recent_sync_logs, get_sync_logs_by_batch, initializeStallCore, inventory_levels, is_offline, is_online, local_db, locations, order_notes, orders, payment_providers, payments, products, promotions, refunds, remove_from_sync_queue, save_bulk_data, sync_service, tax_rates, tax_regions, update_sync_queue_status, variants };
900
+ export { add_sync_log, add_to_sync_queue, categories, cleanup_old_sync_logs, collections, customers, fulfillments, generate_offline_id, get_pending_sync_queue, get_recent_sync_logs, get_sync_logs_by_batch, initializeStallCore, inventory_levels, is_offline, is_online, is_sync_queue_empty, local_db, locations, order_notes, orders, payment_providers, payments, products, promotions, refunds, remove_from_sync_queue, save_bulk_data, sync_service, tax_rates, tax_regions, update_sync_queue_status, variants };
package/dist/index.d.ts CHANGED
@@ -855,6 +855,10 @@ declare const get_recent_sync_logs: (props?: {
855
855
  table?: ConnectorModuleKey;
856
856
  status?: "success" | "failed" | "pending";
857
857
  }) => Promise<SyncLogType[]>;
858
+ /**
859
+ * Check if sync queue is empty (all pending items synced)
860
+ */
861
+ declare const is_sync_queue_empty: () => Promise<boolean>;
858
862
  /**
859
863
  * Clear old sync logs (keep last N days)
860
864
  */
@@ -893,4 +897,4 @@ declare const is_online: () => boolean;
893
897
  */
894
898
  declare const is_offline: () => boolean;
895
899
 
896
- export { add_sync_log, add_to_sync_queue, categories, cleanup_old_sync_logs, collections, customers, fulfillments, generate_offline_id, get_pending_sync_queue, get_recent_sync_logs, get_sync_logs_by_batch, initializeStallCore, inventory_levels, is_offline, is_online, local_db, locations, order_notes, orders, payment_providers, payments, products, promotions, refunds, remove_from_sync_queue, save_bulk_data, sync_service, tax_rates, tax_regions, update_sync_queue_status, variants };
900
+ export { add_sync_log, add_to_sync_queue, categories, cleanup_old_sync_logs, collections, customers, fulfillments, generate_offline_id, get_pending_sync_queue, get_recent_sync_logs, get_sync_logs_by_batch, initializeStallCore, inventory_levels, is_offline, is_online, is_sync_queue_empty, local_db, locations, order_notes, orders, payment_providers, payments, products, promotions, refunds, remove_from_sync_queue, save_bulk_data, sync_service, tax_rates, tax_regions, update_sync_queue_status, variants };
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ __export(index_exports, {
45
45
  inventory_levels: () => inventory_levels,
46
46
  is_offline: () => is_offline,
47
47
  is_online: () => is_online,
48
+ is_sync_queue_empty: () => is_sync_queue_empty,
48
49
  local_db: () => local_db,
49
50
  locations: () => locations,
50
51
  order_notes: () => order_notes,
@@ -224,6 +225,15 @@ var get_recent_sync_logs = async (props) => {
224
225
  }
225
226
  return logs;
226
227
  };
228
+ var is_sync_queue_empty = async () => {
229
+ try {
230
+ const pending_items = await local_db.sync_queue.count();
231
+ return pending_items === 0;
232
+ } catch (error) {
233
+ console.error("Error checking sync queue status:", error);
234
+ return false;
235
+ }
236
+ };
227
237
  var cleanup_old_sync_logs = async (days = 30) => {
228
238
  const cutoff_time = Date.now() - days * 24 * 60 * 60 * 1e3;
229
239
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
@@ -698,6 +708,12 @@ var getAdapter = async (sdk, force) => {
698
708
  var list = async (props) => {
699
709
  try {
700
710
  const { sdk, query } = props;
711
+ const queue_is_empty = await is_sync_queue_empty();
712
+ if (!queue_is_empty) {
713
+ throw new Error(
714
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
715
+ );
716
+ }
701
717
  const adapter = await sdk.adapter();
702
718
  if (!adapter) throw new Error("Adapter not found");
703
719
  const products2 = await adapter.products.list({
@@ -716,6 +732,12 @@ var list = async (props) => {
716
732
  var retrieve = async (props) => {
717
733
  try {
718
734
  const { sdk, id } = props;
735
+ const queue_is_empty = await is_sync_queue_empty();
736
+ if (!queue_is_empty) {
737
+ throw new Error(
738
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
739
+ );
740
+ }
719
741
  const adapter = await sdk.adapter();
720
742
  if (!adapter) throw new Error("Adapter not found");
721
743
  const product = await adapter.products.retrieve({
@@ -921,6 +943,12 @@ var products = {
921
943
  var list2 = async (props) => {
922
944
  try {
923
945
  const { sdk, query } = props;
946
+ const queue_is_empty = await is_sync_queue_empty();
947
+ if (!queue_is_empty) {
948
+ throw new Error(
949
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
950
+ );
951
+ }
924
952
  const adapter = await sdk.adapter();
925
953
  if (!adapter) throw new Error("Adapter not found");
926
954
  const orders2 = await adapter.orders.list({
@@ -941,6 +969,12 @@ var list2 = async (props) => {
941
969
  var retrieve2 = async (props) => {
942
970
  try {
943
971
  const { sdk, id } = props;
972
+ const queue_is_empty = await is_sync_queue_empty();
973
+ if (!queue_is_empty) {
974
+ throw new Error(
975
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
976
+ );
977
+ }
944
978
  const adapter = await sdk.adapter();
945
979
  if (!adapter) throw new Error("Adapter not found");
946
980
  const order = await adapter.orders.retrieve({
@@ -1160,6 +1194,12 @@ var orders = {
1160
1194
  var list3 = async (props) => {
1161
1195
  try {
1162
1196
  const { sdk, query } = props;
1197
+ const queue_is_empty = await is_sync_queue_empty();
1198
+ if (!queue_is_empty) {
1199
+ throw new Error(
1200
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1201
+ );
1202
+ }
1163
1203
  const adapter = await sdk.adapter();
1164
1204
  if (!adapter) throw new Error("Adapter not found");
1165
1205
  const customers2 = await adapter.customers.list({
@@ -1178,6 +1218,12 @@ var list3 = async (props) => {
1178
1218
  var retrieve3 = async (props) => {
1179
1219
  try {
1180
1220
  const { sdk, id } = props;
1221
+ const queue_is_empty = await is_sync_queue_empty();
1222
+ if (!queue_is_empty) {
1223
+ throw new Error(
1224
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1225
+ );
1226
+ }
1181
1227
  const adapter = await sdk.adapter();
1182
1228
  if (!adapter) throw new Error("Adapter not found");
1183
1229
  const customer = await adapter.customers.retrieve({
@@ -1383,6 +1429,12 @@ var customers = {
1383
1429
  var list4 = async (props) => {
1384
1430
  try {
1385
1431
  const { sdk, query } = props;
1432
+ const queue_is_empty = await is_sync_queue_empty();
1433
+ if (!queue_is_empty) {
1434
+ throw new Error(
1435
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1436
+ );
1437
+ }
1386
1438
  const adapter = await sdk.adapter();
1387
1439
  if (!adapter) throw new Error("Adapter not found");
1388
1440
  const collections2 = await adapter.collections.list({
@@ -1401,6 +1453,12 @@ var list4 = async (props) => {
1401
1453
  var retrieve4 = async (props) => {
1402
1454
  try {
1403
1455
  const { sdk, id } = props;
1456
+ const queue_is_empty = await is_sync_queue_empty();
1457
+ if (!queue_is_empty) {
1458
+ throw new Error(
1459
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1460
+ );
1461
+ }
1404
1462
  const adapter = await sdk.adapter();
1405
1463
  if (!adapter) throw new Error("Adapter not found");
1406
1464
  const collection = await adapter.collections.retrieve({
@@ -1608,6 +1666,12 @@ var collections = {
1608
1666
  var list5 = async (props) => {
1609
1667
  try {
1610
1668
  const { sdk, query } = props;
1669
+ const queue_is_empty = await is_sync_queue_empty();
1670
+ if (!queue_is_empty) {
1671
+ throw new Error(
1672
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1673
+ );
1674
+ }
1611
1675
  const adapter = await sdk.adapter();
1612
1676
  if (!adapter) throw new Error("Adapter not found");
1613
1677
  const categories2 = await adapter.categories.list({
@@ -1626,6 +1690,12 @@ var list5 = async (props) => {
1626
1690
  var retrieve5 = async (props) => {
1627
1691
  try {
1628
1692
  const { sdk, id } = props;
1693
+ const queue_is_empty = await is_sync_queue_empty();
1694
+ if (!queue_is_empty) {
1695
+ throw new Error(
1696
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1697
+ );
1698
+ }
1629
1699
  const adapter = await sdk.adapter();
1630
1700
  if (!adapter) throw new Error("Adapter not found");
1631
1701
  const category = await adapter.categories.retrieve({
@@ -1831,6 +1901,12 @@ var categories = {
1831
1901
  var list6 = async (props) => {
1832
1902
  try {
1833
1903
  const { sdk, query } = props;
1904
+ const queue_is_empty = await is_sync_queue_empty();
1905
+ if (!queue_is_empty) {
1906
+ throw new Error(
1907
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1908
+ );
1909
+ }
1834
1910
  const adapter = await sdk.adapter();
1835
1911
  if (!adapter) throw new Error("Adapter not found");
1836
1912
  const variants2 = await adapter.variants.list({
@@ -1849,6 +1925,12 @@ var list6 = async (props) => {
1849
1925
  var retrieve6 = async (props) => {
1850
1926
  try {
1851
1927
  const { sdk, id } = props;
1928
+ const queue_is_empty = await is_sync_queue_empty();
1929
+ if (!queue_is_empty) {
1930
+ throw new Error(
1931
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1932
+ );
1933
+ }
1852
1934
  const adapter = await sdk.adapter();
1853
1935
  if (!adapter) throw new Error("Adapter not found");
1854
1936
  const variant = await adapter.variants.retrieve({
@@ -2054,6 +2136,12 @@ var variants = {
2054
2136
  var list7 = async (props) => {
2055
2137
  try {
2056
2138
  const { sdk, query } = props;
2139
+ const queue_is_empty = await is_sync_queue_empty();
2140
+ if (!queue_is_empty) {
2141
+ throw new Error(
2142
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2143
+ );
2144
+ }
2057
2145
  const adapter = await sdk.adapter();
2058
2146
  if (!adapter) throw new Error("Adapter not found");
2059
2147
  const inventory_levels2 = await adapter.inventory_levels.list({
@@ -2072,6 +2160,12 @@ var list7 = async (props) => {
2072
2160
  var retrieve7 = async (props) => {
2073
2161
  try {
2074
2162
  const { sdk, id } = props;
2163
+ const queue_is_empty = await is_sync_queue_empty();
2164
+ if (!queue_is_empty) {
2165
+ throw new Error(
2166
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2167
+ );
2168
+ }
2075
2169
  const adapter = await sdk.adapter();
2076
2170
  if (!adapter) throw new Error("Adapter not found");
2077
2171
  const inventory_level = await adapter.inventory_levels.retrieve({
@@ -2281,6 +2375,12 @@ var inventory_levels = {
2281
2375
  var list8 = async (props) => {
2282
2376
  try {
2283
2377
  const { sdk, query } = props;
2378
+ const queue_is_empty = await is_sync_queue_empty();
2379
+ if (!queue_is_empty) {
2380
+ throw new Error(
2381
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2382
+ );
2383
+ }
2284
2384
  const adapter = await sdk.adapter();
2285
2385
  if (!adapter) throw new Error("Adapter not found");
2286
2386
  const promotions2 = await adapter.promotions.list({
@@ -2299,6 +2399,12 @@ var list8 = async (props) => {
2299
2399
  var retrieve8 = async (props) => {
2300
2400
  try {
2301
2401
  const { sdk, id } = props;
2402
+ const queue_is_empty = await is_sync_queue_empty();
2403
+ if (!queue_is_empty) {
2404
+ throw new Error(
2405
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2406
+ );
2407
+ }
2302
2408
  const adapter = await sdk.adapter();
2303
2409
  if (!adapter) throw new Error("Adapter not found");
2304
2410
  const promotion = await adapter.promotions.retrieve({
@@ -2506,6 +2612,12 @@ var promotions = {
2506
2612
  var list9 = async (props) => {
2507
2613
  try {
2508
2614
  const { sdk, query } = props;
2615
+ const queue_is_empty = await is_sync_queue_empty();
2616
+ if (!queue_is_empty) {
2617
+ throw new Error(
2618
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2619
+ );
2620
+ }
2509
2621
  const adapter = await sdk.adapter();
2510
2622
  if (!adapter) throw new Error("Adapter not found");
2511
2623
  const order_notes2 = await adapter.order_notes.list({
@@ -2524,6 +2636,12 @@ var list9 = async (props) => {
2524
2636
  var retrieve9 = async (props) => {
2525
2637
  try {
2526
2638
  const { sdk, id } = props;
2639
+ const queue_is_empty = await is_sync_queue_empty();
2640
+ if (!queue_is_empty) {
2641
+ throw new Error(
2642
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2643
+ );
2644
+ }
2527
2645
  const adapter = await sdk.adapter();
2528
2646
  if (!adapter) throw new Error("Adapter not found");
2529
2647
  const order_note = await adapter.order_notes.retrieve({
@@ -2731,6 +2849,12 @@ var order_notes = {
2731
2849
  var list10 = async (props) => {
2732
2850
  try {
2733
2851
  const { sdk, query } = props;
2852
+ const queue_is_empty = await is_sync_queue_empty();
2853
+ if (!queue_is_empty) {
2854
+ throw new Error(
2855
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2856
+ );
2857
+ }
2734
2858
  const adapter = await sdk.adapter();
2735
2859
  if (!adapter) throw new Error("Adapter not found");
2736
2860
  const refunds2 = await adapter.refunds.list({
@@ -2749,6 +2873,12 @@ var list10 = async (props) => {
2749
2873
  var retrieve10 = async (props) => {
2750
2874
  try {
2751
2875
  const { sdk, id } = props;
2876
+ const queue_is_empty = await is_sync_queue_empty();
2877
+ if (!queue_is_empty) {
2878
+ throw new Error(
2879
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2880
+ );
2881
+ }
2752
2882
  const adapter = await sdk.adapter();
2753
2883
  if (!adapter) throw new Error("Adapter not found");
2754
2884
  const refund = await adapter.refunds.retrieve({
@@ -2954,6 +3084,12 @@ var refunds = {
2954
3084
  var list11 = async (props) => {
2955
3085
  try {
2956
3086
  const { sdk, query } = props;
3087
+ const queue_is_empty = await is_sync_queue_empty();
3088
+ if (!queue_is_empty) {
3089
+ throw new Error(
3090
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3091
+ );
3092
+ }
2957
3093
  const adapter = await sdk.adapter();
2958
3094
  if (!adapter) throw new Error("Adapter not found");
2959
3095
  const payment_providers2 = await adapter.payment_providers.list({
@@ -2972,6 +3108,12 @@ var list11 = async (props) => {
2972
3108
  var retrieve11 = async (props) => {
2973
3109
  try {
2974
3110
  const { sdk, id } = props;
3111
+ const queue_is_empty = await is_sync_queue_empty();
3112
+ if (!queue_is_empty) {
3113
+ throw new Error(
3114
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3115
+ );
3116
+ }
2975
3117
  const adapter = await sdk.adapter();
2976
3118
  if (!adapter) throw new Error("Adapter not found");
2977
3119
  const payment_provider = await adapter.payment_providers.retrieve({
@@ -3181,6 +3323,12 @@ var payment_providers = {
3181
3323
  var list12 = async (props) => {
3182
3324
  try {
3183
3325
  const { sdk, query } = props;
3326
+ const queue_is_empty = await is_sync_queue_empty();
3327
+ if (!queue_is_empty) {
3328
+ throw new Error(
3329
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3330
+ );
3331
+ }
3184
3332
  const adapter = await sdk.adapter();
3185
3333
  if (!adapter) throw new Error("Adapter not found");
3186
3334
  const payments2 = await adapter.payments.list({
@@ -3199,6 +3347,12 @@ var list12 = async (props) => {
3199
3347
  var retrieve12 = async (props) => {
3200
3348
  try {
3201
3349
  const { sdk, id } = props;
3350
+ const queue_is_empty = await is_sync_queue_empty();
3351
+ if (!queue_is_empty) {
3352
+ throw new Error(
3353
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3354
+ );
3355
+ }
3202
3356
  const adapter = await sdk.adapter();
3203
3357
  if (!adapter) throw new Error("Adapter not found");
3204
3358
  const payment = await adapter.payments.retrieve({
@@ -3404,6 +3558,12 @@ var payments = {
3404
3558
  var list13 = async (props) => {
3405
3559
  try {
3406
3560
  const { sdk, query } = props;
3561
+ const queue_is_empty = await is_sync_queue_empty();
3562
+ if (!queue_is_empty) {
3563
+ throw new Error(
3564
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3565
+ );
3566
+ }
3407
3567
  const adapter = await sdk.adapter();
3408
3568
  if (!adapter) throw new Error("Adapter not found");
3409
3569
  const regions = await adapter.tax_regions.list({
@@ -3422,6 +3582,12 @@ var list13 = async (props) => {
3422
3582
  var retrieve13 = async (props) => {
3423
3583
  try {
3424
3584
  const { sdk, id } = props;
3585
+ const queue_is_empty = await is_sync_queue_empty();
3586
+ if (!queue_is_empty) {
3587
+ throw new Error(
3588
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3589
+ );
3590
+ }
3425
3591
  const adapter = await sdk.adapter();
3426
3592
  if (!adapter) throw new Error("Adapter not found");
3427
3593
  const region = await adapter.tax_regions.retrieve({
@@ -3629,6 +3795,12 @@ var tax_regions = {
3629
3795
  var list14 = async (props) => {
3630
3796
  try {
3631
3797
  const { sdk, query } = props;
3798
+ const queue_is_empty = await is_sync_queue_empty();
3799
+ if (!queue_is_empty) {
3800
+ throw new Error(
3801
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3802
+ );
3803
+ }
3632
3804
  const adapter = await sdk.adapter();
3633
3805
  if (!adapter) throw new Error("Adapter not found");
3634
3806
  const rates = await adapter.tax_rates.list({
@@ -3647,6 +3819,12 @@ var list14 = async (props) => {
3647
3819
  var retrieve14 = async (props) => {
3648
3820
  try {
3649
3821
  const { sdk, id } = props;
3822
+ const queue_is_empty = await is_sync_queue_empty();
3823
+ if (!queue_is_empty) {
3824
+ throw new Error(
3825
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3826
+ );
3827
+ }
3650
3828
  const adapter = await sdk.adapter();
3651
3829
  if (!adapter) throw new Error("Adapter not found");
3652
3830
  const rate = await adapter.tax_rates.retrieve({
@@ -3899,6 +4077,12 @@ var merge_location = (existing, updates, now) => {
3899
4077
  var list15 = async (props) => {
3900
4078
  try {
3901
4079
  const { sdk, query } = props;
4080
+ const queue_is_empty = await is_sync_queue_empty();
4081
+ if (!queue_is_empty) {
4082
+ throw new Error(
4083
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4084
+ );
4085
+ }
3902
4086
  const adapter = await sdk.adapter();
3903
4087
  if (!adapter) throw new Error("Adapter not found");
3904
4088
  const locations2 = await adapter.locations.list({
@@ -3917,6 +4101,12 @@ var list15 = async (props) => {
3917
4101
  var retrieve15 = async (props) => {
3918
4102
  try {
3919
4103
  const { sdk, id } = props;
4104
+ const queue_is_empty = await is_sync_queue_empty();
4105
+ if (!queue_is_empty) {
4106
+ throw new Error(
4107
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4108
+ );
4109
+ }
3920
4110
  const adapter = await sdk.adapter();
3921
4111
  if (!adapter) throw new Error("Adapter not found");
3922
4112
  const location = await adapter.locations.retrieve({
@@ -4078,6 +4268,12 @@ var locations = {
4078
4268
  var list16 = async (props) => {
4079
4269
  try {
4080
4270
  const { sdk, query } = props;
4271
+ const queue_is_empty = await is_sync_queue_empty();
4272
+ if (!queue_is_empty) {
4273
+ throw new Error(
4274
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4275
+ );
4276
+ }
4081
4277
  const adapter = await sdk.adapter();
4082
4278
  if (!adapter) throw new Error("Adapter not found");
4083
4279
  const fulfillments2 = await adapter.fulfillments.list({
@@ -4096,6 +4292,12 @@ var list16 = async (props) => {
4096
4292
  var retrieve16 = async (props) => {
4097
4293
  try {
4098
4294
  const { sdk, id } = props;
4295
+ const queue_is_empty = await is_sync_queue_empty();
4296
+ if (!queue_is_empty) {
4297
+ throw new Error(
4298
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4299
+ );
4300
+ }
4099
4301
  const adapter = await sdk.adapter();
4100
4302
  if (!adapter) throw new Error("Adapter not found");
4101
4303
  const fulfillment = await adapter.fulfillments.retrieve({
@@ -4315,6 +4517,7 @@ var fulfillments = {
4315
4517
  inventory_levels,
4316
4518
  is_offline,
4317
4519
  is_online,
4520
+ is_sync_queue_empty,
4318
4521
  local_db,
4319
4522
  locations,
4320
4523
  order_notes,
package/dist/index.mjs CHANGED
@@ -158,6 +158,15 @@ var get_recent_sync_logs = async (props) => {
158
158
  }
159
159
  return logs;
160
160
  };
161
+ var is_sync_queue_empty = async () => {
162
+ try {
163
+ const pending_items = await local_db.sync_queue.count();
164
+ return pending_items === 0;
165
+ } catch (error) {
166
+ console.error("Error checking sync queue status:", error);
167
+ return false;
168
+ }
169
+ };
161
170
  var cleanup_old_sync_logs = async (days = 30) => {
162
171
  const cutoff_time = Date.now() - days * 24 * 60 * 60 * 1e3;
163
172
  await local_db.sync_logs.where("timestamp").below(cutoff_time).delete();
@@ -632,6 +641,12 @@ var getAdapter = async (sdk, force) => {
632
641
  var list = async (props) => {
633
642
  try {
634
643
  const { sdk, query } = props;
644
+ const queue_is_empty = await is_sync_queue_empty();
645
+ if (!queue_is_empty) {
646
+ throw new Error(
647
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
648
+ );
649
+ }
635
650
  const adapter = await sdk.adapter();
636
651
  if (!adapter) throw new Error("Adapter not found");
637
652
  const products2 = await adapter.products.list({
@@ -650,6 +665,12 @@ var list = async (props) => {
650
665
  var retrieve = async (props) => {
651
666
  try {
652
667
  const { sdk, id } = props;
668
+ const queue_is_empty = await is_sync_queue_empty();
669
+ if (!queue_is_empty) {
670
+ throw new Error(
671
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
672
+ );
673
+ }
653
674
  const adapter = await sdk.adapter();
654
675
  if (!adapter) throw new Error("Adapter not found");
655
676
  const product = await adapter.products.retrieve({
@@ -855,6 +876,12 @@ var products = {
855
876
  var list2 = async (props) => {
856
877
  try {
857
878
  const { sdk, query } = props;
879
+ const queue_is_empty = await is_sync_queue_empty();
880
+ if (!queue_is_empty) {
881
+ throw new Error(
882
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
883
+ );
884
+ }
858
885
  const adapter = await sdk.adapter();
859
886
  if (!adapter) throw new Error("Adapter not found");
860
887
  const orders2 = await adapter.orders.list({
@@ -875,6 +902,12 @@ var list2 = async (props) => {
875
902
  var retrieve2 = async (props) => {
876
903
  try {
877
904
  const { sdk, id } = props;
905
+ const queue_is_empty = await is_sync_queue_empty();
906
+ if (!queue_is_empty) {
907
+ throw new Error(
908
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
909
+ );
910
+ }
878
911
  const adapter = await sdk.adapter();
879
912
  if (!adapter) throw new Error("Adapter not found");
880
913
  const order = await adapter.orders.retrieve({
@@ -1094,6 +1127,12 @@ var orders = {
1094
1127
  var list3 = async (props) => {
1095
1128
  try {
1096
1129
  const { sdk, query } = props;
1130
+ const queue_is_empty = await is_sync_queue_empty();
1131
+ if (!queue_is_empty) {
1132
+ throw new Error(
1133
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1134
+ );
1135
+ }
1097
1136
  const adapter = await sdk.adapter();
1098
1137
  if (!adapter) throw new Error("Adapter not found");
1099
1138
  const customers2 = await adapter.customers.list({
@@ -1112,6 +1151,12 @@ var list3 = async (props) => {
1112
1151
  var retrieve3 = async (props) => {
1113
1152
  try {
1114
1153
  const { sdk, id } = props;
1154
+ const queue_is_empty = await is_sync_queue_empty();
1155
+ if (!queue_is_empty) {
1156
+ throw new Error(
1157
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1158
+ );
1159
+ }
1115
1160
  const adapter = await sdk.adapter();
1116
1161
  if (!adapter) throw new Error("Adapter not found");
1117
1162
  const customer = await adapter.customers.retrieve({
@@ -1317,6 +1362,12 @@ var customers = {
1317
1362
  var list4 = async (props) => {
1318
1363
  try {
1319
1364
  const { sdk, query } = props;
1365
+ const queue_is_empty = await is_sync_queue_empty();
1366
+ if (!queue_is_empty) {
1367
+ throw new Error(
1368
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1369
+ );
1370
+ }
1320
1371
  const adapter = await sdk.adapter();
1321
1372
  if (!adapter) throw new Error("Adapter not found");
1322
1373
  const collections2 = await adapter.collections.list({
@@ -1335,6 +1386,12 @@ var list4 = async (props) => {
1335
1386
  var retrieve4 = async (props) => {
1336
1387
  try {
1337
1388
  const { sdk, id } = props;
1389
+ const queue_is_empty = await is_sync_queue_empty();
1390
+ if (!queue_is_empty) {
1391
+ throw new Error(
1392
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1393
+ );
1394
+ }
1338
1395
  const adapter = await sdk.adapter();
1339
1396
  if (!adapter) throw new Error("Adapter not found");
1340
1397
  const collection = await adapter.collections.retrieve({
@@ -1542,6 +1599,12 @@ var collections = {
1542
1599
  var list5 = async (props) => {
1543
1600
  try {
1544
1601
  const { sdk, query } = props;
1602
+ const queue_is_empty = await is_sync_queue_empty();
1603
+ if (!queue_is_empty) {
1604
+ throw new Error(
1605
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1606
+ );
1607
+ }
1545
1608
  const adapter = await sdk.adapter();
1546
1609
  if (!adapter) throw new Error("Adapter not found");
1547
1610
  const categories2 = await adapter.categories.list({
@@ -1560,6 +1623,12 @@ var list5 = async (props) => {
1560
1623
  var retrieve5 = async (props) => {
1561
1624
  try {
1562
1625
  const { sdk, id } = props;
1626
+ const queue_is_empty = await is_sync_queue_empty();
1627
+ if (!queue_is_empty) {
1628
+ throw new Error(
1629
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1630
+ );
1631
+ }
1563
1632
  const adapter = await sdk.adapter();
1564
1633
  if (!adapter) throw new Error("Adapter not found");
1565
1634
  const category = await adapter.categories.retrieve({
@@ -1765,6 +1834,12 @@ var categories = {
1765
1834
  var list6 = async (props) => {
1766
1835
  try {
1767
1836
  const { sdk, query } = props;
1837
+ const queue_is_empty = await is_sync_queue_empty();
1838
+ if (!queue_is_empty) {
1839
+ throw new Error(
1840
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1841
+ );
1842
+ }
1768
1843
  const adapter = await sdk.adapter();
1769
1844
  if (!adapter) throw new Error("Adapter not found");
1770
1845
  const variants2 = await adapter.variants.list({
@@ -1783,6 +1858,12 @@ var list6 = async (props) => {
1783
1858
  var retrieve6 = async (props) => {
1784
1859
  try {
1785
1860
  const { sdk, id } = props;
1861
+ const queue_is_empty = await is_sync_queue_empty();
1862
+ if (!queue_is_empty) {
1863
+ throw new Error(
1864
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
1865
+ );
1866
+ }
1786
1867
  const adapter = await sdk.adapter();
1787
1868
  if (!adapter) throw new Error("Adapter not found");
1788
1869
  const variant = await adapter.variants.retrieve({
@@ -1988,6 +2069,12 @@ var variants = {
1988
2069
  var list7 = async (props) => {
1989
2070
  try {
1990
2071
  const { sdk, query } = props;
2072
+ const queue_is_empty = await is_sync_queue_empty();
2073
+ if (!queue_is_empty) {
2074
+ throw new Error(
2075
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2076
+ );
2077
+ }
1991
2078
  const adapter = await sdk.adapter();
1992
2079
  if (!adapter) throw new Error("Adapter not found");
1993
2080
  const inventory_levels2 = await adapter.inventory_levels.list({
@@ -2006,6 +2093,12 @@ var list7 = async (props) => {
2006
2093
  var retrieve7 = async (props) => {
2007
2094
  try {
2008
2095
  const { sdk, id } = props;
2096
+ const queue_is_empty = await is_sync_queue_empty();
2097
+ if (!queue_is_empty) {
2098
+ throw new Error(
2099
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2100
+ );
2101
+ }
2009
2102
  const adapter = await sdk.adapter();
2010
2103
  if (!adapter) throw new Error("Adapter not found");
2011
2104
  const inventory_level = await adapter.inventory_levels.retrieve({
@@ -2215,6 +2308,12 @@ var inventory_levels = {
2215
2308
  var list8 = async (props) => {
2216
2309
  try {
2217
2310
  const { sdk, query } = props;
2311
+ const queue_is_empty = await is_sync_queue_empty();
2312
+ if (!queue_is_empty) {
2313
+ throw new Error(
2314
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2315
+ );
2316
+ }
2218
2317
  const adapter = await sdk.adapter();
2219
2318
  if (!adapter) throw new Error("Adapter not found");
2220
2319
  const promotions2 = await adapter.promotions.list({
@@ -2233,6 +2332,12 @@ var list8 = async (props) => {
2233
2332
  var retrieve8 = async (props) => {
2234
2333
  try {
2235
2334
  const { sdk, id } = props;
2335
+ const queue_is_empty = await is_sync_queue_empty();
2336
+ if (!queue_is_empty) {
2337
+ throw new Error(
2338
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2339
+ );
2340
+ }
2236
2341
  const adapter = await sdk.adapter();
2237
2342
  if (!adapter) throw new Error("Adapter not found");
2238
2343
  const promotion = await adapter.promotions.retrieve({
@@ -2440,6 +2545,12 @@ var promotions = {
2440
2545
  var list9 = async (props) => {
2441
2546
  try {
2442
2547
  const { sdk, query } = props;
2548
+ const queue_is_empty = await is_sync_queue_empty();
2549
+ if (!queue_is_empty) {
2550
+ throw new Error(
2551
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2552
+ );
2553
+ }
2443
2554
  const adapter = await sdk.adapter();
2444
2555
  if (!adapter) throw new Error("Adapter not found");
2445
2556
  const order_notes2 = await adapter.order_notes.list({
@@ -2458,6 +2569,12 @@ var list9 = async (props) => {
2458
2569
  var retrieve9 = async (props) => {
2459
2570
  try {
2460
2571
  const { sdk, id } = props;
2572
+ const queue_is_empty = await is_sync_queue_empty();
2573
+ if (!queue_is_empty) {
2574
+ throw new Error(
2575
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2576
+ );
2577
+ }
2461
2578
  const adapter = await sdk.adapter();
2462
2579
  if (!adapter) throw new Error("Adapter not found");
2463
2580
  const order_note = await adapter.order_notes.retrieve({
@@ -2665,6 +2782,12 @@ var order_notes = {
2665
2782
  var list10 = async (props) => {
2666
2783
  try {
2667
2784
  const { sdk, query } = props;
2785
+ const queue_is_empty = await is_sync_queue_empty();
2786
+ if (!queue_is_empty) {
2787
+ throw new Error(
2788
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2789
+ );
2790
+ }
2668
2791
  const adapter = await sdk.adapter();
2669
2792
  if (!adapter) throw new Error("Adapter not found");
2670
2793
  const refunds2 = await adapter.refunds.list({
@@ -2683,6 +2806,12 @@ var list10 = async (props) => {
2683
2806
  var retrieve10 = async (props) => {
2684
2807
  try {
2685
2808
  const { sdk, id } = props;
2809
+ const queue_is_empty = await is_sync_queue_empty();
2810
+ if (!queue_is_empty) {
2811
+ throw new Error(
2812
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
2813
+ );
2814
+ }
2686
2815
  const adapter = await sdk.adapter();
2687
2816
  if (!adapter) throw new Error("Adapter not found");
2688
2817
  const refund = await adapter.refunds.retrieve({
@@ -2888,6 +3017,12 @@ var refunds = {
2888
3017
  var list11 = async (props) => {
2889
3018
  try {
2890
3019
  const { sdk, query } = props;
3020
+ const queue_is_empty = await is_sync_queue_empty();
3021
+ if (!queue_is_empty) {
3022
+ throw new Error(
3023
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3024
+ );
3025
+ }
2891
3026
  const adapter = await sdk.adapter();
2892
3027
  if (!adapter) throw new Error("Adapter not found");
2893
3028
  const payment_providers2 = await adapter.payment_providers.list({
@@ -2906,6 +3041,12 @@ var list11 = async (props) => {
2906
3041
  var retrieve11 = async (props) => {
2907
3042
  try {
2908
3043
  const { sdk, id } = props;
3044
+ const queue_is_empty = await is_sync_queue_empty();
3045
+ if (!queue_is_empty) {
3046
+ throw new Error(
3047
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3048
+ );
3049
+ }
2909
3050
  const adapter = await sdk.adapter();
2910
3051
  if (!adapter) throw new Error("Adapter not found");
2911
3052
  const payment_provider = await adapter.payment_providers.retrieve({
@@ -3115,6 +3256,12 @@ var payment_providers = {
3115
3256
  var list12 = async (props) => {
3116
3257
  try {
3117
3258
  const { sdk, query } = props;
3259
+ const queue_is_empty = await is_sync_queue_empty();
3260
+ if (!queue_is_empty) {
3261
+ throw new Error(
3262
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3263
+ );
3264
+ }
3118
3265
  const adapter = await sdk.adapter();
3119
3266
  if (!adapter) throw new Error("Adapter not found");
3120
3267
  const payments2 = await adapter.payments.list({
@@ -3133,6 +3280,12 @@ var list12 = async (props) => {
3133
3280
  var retrieve12 = async (props) => {
3134
3281
  try {
3135
3282
  const { sdk, id } = props;
3283
+ const queue_is_empty = await is_sync_queue_empty();
3284
+ if (!queue_is_empty) {
3285
+ throw new Error(
3286
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3287
+ );
3288
+ }
3136
3289
  const adapter = await sdk.adapter();
3137
3290
  if (!adapter) throw new Error("Adapter not found");
3138
3291
  const payment = await adapter.payments.retrieve({
@@ -3338,6 +3491,12 @@ var payments = {
3338
3491
  var list13 = async (props) => {
3339
3492
  try {
3340
3493
  const { sdk, query } = props;
3494
+ const queue_is_empty = await is_sync_queue_empty();
3495
+ if (!queue_is_empty) {
3496
+ throw new Error(
3497
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3498
+ );
3499
+ }
3341
3500
  const adapter = await sdk.adapter();
3342
3501
  if (!adapter) throw new Error("Adapter not found");
3343
3502
  const regions = await adapter.tax_regions.list({
@@ -3356,6 +3515,12 @@ var list13 = async (props) => {
3356
3515
  var retrieve13 = async (props) => {
3357
3516
  try {
3358
3517
  const { sdk, id } = props;
3518
+ const queue_is_empty = await is_sync_queue_empty();
3519
+ if (!queue_is_empty) {
3520
+ throw new Error(
3521
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3522
+ );
3523
+ }
3359
3524
  const adapter = await sdk.adapter();
3360
3525
  if (!adapter) throw new Error("Adapter not found");
3361
3526
  const region = await adapter.tax_regions.retrieve({
@@ -3563,6 +3728,12 @@ var tax_regions = {
3563
3728
  var list14 = async (props) => {
3564
3729
  try {
3565
3730
  const { sdk, query } = props;
3731
+ const queue_is_empty = await is_sync_queue_empty();
3732
+ if (!queue_is_empty) {
3733
+ throw new Error(
3734
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3735
+ );
3736
+ }
3566
3737
  const adapter = await sdk.adapter();
3567
3738
  if (!adapter) throw new Error("Adapter not found");
3568
3739
  const rates = await adapter.tax_rates.list({
@@ -3581,6 +3752,12 @@ var list14 = async (props) => {
3581
3752
  var retrieve14 = async (props) => {
3582
3753
  try {
3583
3754
  const { sdk, id } = props;
3755
+ const queue_is_empty = await is_sync_queue_empty();
3756
+ if (!queue_is_empty) {
3757
+ throw new Error(
3758
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
3759
+ );
3760
+ }
3584
3761
  const adapter = await sdk.adapter();
3585
3762
  if (!adapter) throw new Error("Adapter not found");
3586
3763
  const rate = await adapter.tax_rates.retrieve({
@@ -3833,6 +4010,12 @@ var merge_location = (existing, updates, now) => {
3833
4010
  var list15 = async (props) => {
3834
4011
  try {
3835
4012
  const { sdk, query } = props;
4013
+ const queue_is_empty = await is_sync_queue_empty();
4014
+ if (!queue_is_empty) {
4015
+ throw new Error(
4016
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4017
+ );
4018
+ }
3836
4019
  const adapter = await sdk.adapter();
3837
4020
  if (!adapter) throw new Error("Adapter not found");
3838
4021
  const locations2 = await adapter.locations.list({
@@ -3851,6 +4034,12 @@ var list15 = async (props) => {
3851
4034
  var retrieve15 = async (props) => {
3852
4035
  try {
3853
4036
  const { sdk, id } = props;
4037
+ const queue_is_empty = await is_sync_queue_empty();
4038
+ if (!queue_is_empty) {
4039
+ throw new Error(
4040
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4041
+ );
4042
+ }
3854
4043
  const adapter = await sdk.adapter();
3855
4044
  if (!adapter) throw new Error("Adapter not found");
3856
4045
  const location = await adapter.locations.retrieve({
@@ -4012,6 +4201,12 @@ var locations = {
4012
4201
  var list16 = async (props) => {
4013
4202
  try {
4014
4203
  const { sdk, query } = props;
4204
+ const queue_is_empty = await is_sync_queue_empty();
4205
+ if (!queue_is_empty) {
4206
+ throw new Error(
4207
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4208
+ );
4209
+ }
4015
4210
  const adapter = await sdk.adapter();
4016
4211
  if (!adapter) throw new Error("Adapter not found");
4017
4212
  const fulfillments2 = await adapter.fulfillments.list({
@@ -4030,6 +4225,12 @@ var list16 = async (props) => {
4030
4225
  var retrieve16 = async (props) => {
4031
4226
  try {
4032
4227
  const { sdk, id } = props;
4228
+ const queue_is_empty = await is_sync_queue_empty();
4229
+ if (!queue_is_empty) {
4230
+ throw new Error(
4231
+ "Cannot fetch data while pending syncs exist. Please wait for all pending changes to sync."
4232
+ );
4233
+ }
4033
4234
  const adapter = await sdk.adapter();
4034
4235
  if (!adapter) throw new Error("Adapter not found");
4035
4236
  const fulfillment = await adapter.fulfillments.retrieve({
@@ -4248,6 +4449,7 @@ export {
4248
4449
  inventory_levels,
4249
4450
  is_offline,
4250
4451
  is_online,
4452
+ is_sync_queue_empty,
4251
4453
  local_db,
4252
4454
  locations,
4253
4455
  order_notes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-stall/core",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "author": "Stall",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",