@use-stall/core 0.0.5 → 0.0.7

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
@@ -1,4 +1,5 @@
1
- import { ConnectorModuleKey, UnifiedProductType, UnifiedVariantsType, UnifiedCollectionType, UnifiedCategoryType, UnifiedInventoryLevelType, UnifiedPromotion, UnifiedOrderType, UnifiedOrderNote, UnifiedOrderRefundType, UnifiedPaymentProviderType, UnifiedPaymentCollectionType, UnifiedTaxRegionType, UnifiedTaxRateType, UnifiedCustomerType, UnifiedLocationType, UnifiedFulfillmentType } from '@use-stall/types';
1
+ import { ConnectorModuleKey, UnifiedProductType, UnifiedVariantsType, UnifiedCollectionType, UnifiedCategoryType, UnifiedTagProductTag, UnifiedInventoryLevelType, UnifiedPromotion, UnifiedOrderType, UnifiedOrderNote, UnifiedOrderRefundType, UnifiedPaymentProviderType, UnifiedPaymentCollectionType, UnifiedTaxRegionType, UnifiedTaxRateType, UnifiedCustomerType, UnifiedLocationType, UnifiedFulfillmentMethodType, UnifiedFulfillmentProviderConfigType, UnifiedFulfillmentType } from '@use-stall/types';
2
+ import Dexie, { EntityTable } from 'dexie';
2
3
 
3
4
  interface StallCoreConfigOptions {
4
5
  connector_url: string;
@@ -17,7 +18,7 @@ type ModuleTypeMap = {
17
18
  variants: UnifiedVariantsType;
18
19
  collections: UnifiedCollectionType;
19
20
  categories: UnifiedCategoryType;
20
- tags: string;
21
+ tags: UnifiedTagProductTag;
21
22
  inventory_levels: UnifiedInventoryLevelType;
22
23
  inventory_history: UnifiedInventoryLevelType;
23
24
  promotions: UnifiedPromotion;
@@ -30,8 +31,8 @@ type ModuleTypeMap = {
30
31
  tax_rates: UnifiedTaxRateType;
31
32
  customers: UnifiedCustomerType;
32
33
  locations: UnifiedLocationType;
33
- fulfillment_types: string;
34
- fulfillment_providers: string;
34
+ fulfillment_types: UnifiedFulfillmentMethodType;
35
+ fulfillment_providers: UnifiedFulfillmentProviderConfigType;
35
36
  fulfillments: UnifiedFulfillmentType;
36
37
  };
37
38
 
@@ -82,7 +83,7 @@ declare const initializeStallCore: (options: StallCoreConfigOptions) => CoreConf
82
83
  declare const products: {
83
84
  list: (props: {
84
85
  sdk: CoreConfig;
85
- query: string;
86
+ query?: string;
86
87
  }) => Promise<UnifiedProductType[]>;
87
88
  retrieve: (props: {
88
89
  sdk: CoreConfig;
@@ -160,7 +161,7 @@ declare const orders: {
160
161
  declare const customers: {
161
162
  list: (props: {
162
163
  sdk: CoreConfig;
163
- query: string;
164
+ query?: string;
164
165
  }) => Promise<UnifiedCustomerType[]>;
165
166
  retrieve: (props: {
166
167
  sdk: CoreConfig;
@@ -199,7 +200,7 @@ declare const customers: {
199
200
  declare const collections: {
200
201
  list: (props: {
201
202
  sdk: CoreConfig;
202
- query: string;
203
+ query?: string;
203
204
  }) => Promise<UnifiedCollectionType[]>;
204
205
  retrieve: (props: {
205
206
  sdk: CoreConfig;
@@ -238,7 +239,7 @@ declare const collections: {
238
239
  declare const categories: {
239
240
  list: (props: {
240
241
  sdk: CoreConfig;
241
- query: string;
242
+ query?: string;
242
243
  }) => Promise<UnifiedCategoryType[]>;
243
244
  retrieve: (props: {
244
245
  sdk: CoreConfig;
@@ -277,7 +278,7 @@ declare const categories: {
277
278
  declare const variants: {
278
279
  list: (props: {
279
280
  sdk: CoreConfig;
280
- query: string;
281
+ query?: string;
281
282
  }) => Promise<UnifiedVariantsType[]>;
282
283
  retrieve: (props: {
283
284
  sdk: CoreConfig;
@@ -316,7 +317,7 @@ declare const variants: {
316
317
  declare const inventory_levels: {
317
318
  list: (props: {
318
319
  sdk: CoreConfig;
319
- query: string;
320
+ query?: string;
320
321
  }) => Promise<UnifiedInventoryLevelType[]>;
321
322
  retrieve: (props: {
322
323
  sdk: CoreConfig;
@@ -355,7 +356,7 @@ declare const inventory_levels: {
355
356
  declare const promotions: {
356
357
  list: (props: {
357
358
  sdk: CoreConfig;
358
- query: string;
359
+ query?: string;
359
360
  }) => Promise<UnifiedPromotion[]>;
360
361
  retrieve: (props: {
361
362
  sdk: CoreConfig;
@@ -394,7 +395,7 @@ declare const promotions: {
394
395
  declare const order_notes: {
395
396
  list: (props: {
396
397
  sdk: CoreConfig;
397
- query: string;
398
+ query?: string;
398
399
  }) => Promise<UnifiedOrderNote[]>;
399
400
  retrieve: (props: {
400
401
  sdk: CoreConfig;
@@ -433,7 +434,7 @@ declare const order_notes: {
433
434
  declare const refunds: {
434
435
  list: (props: {
435
436
  sdk: CoreConfig;
436
- query: string;
437
+ query?: string;
437
438
  }) => Promise<UnifiedOrderRefundType[]>;
438
439
  retrieve: (props: {
439
440
  sdk: CoreConfig;
@@ -472,7 +473,7 @@ declare const refunds: {
472
473
  declare const payment_providers: {
473
474
  list: (props: {
474
475
  sdk: CoreConfig;
475
- query: string;
476
+ query?: string;
476
477
  }) => Promise<UnifiedPaymentProviderType[]>;
477
478
  retrieve: (props: {
478
479
  sdk: CoreConfig;
@@ -511,7 +512,7 @@ declare const payment_providers: {
511
512
  declare const payments: {
512
513
  list: (props: {
513
514
  sdk: CoreConfig;
514
- query: string;
515
+ query?: string;
515
516
  }) => Promise<UnifiedPaymentCollectionType[]>;
516
517
  retrieve: (props: {
517
518
  sdk: CoreConfig;
@@ -550,7 +551,7 @@ declare const payments: {
550
551
  declare const tax_regions: {
551
552
  list: (props: {
552
553
  sdk: CoreConfig;
553
- query: string;
554
+ query?: string;
554
555
  }) => Promise<UnifiedTaxRegionType[]>;
555
556
  retrieve: (props: {
556
557
  sdk: CoreConfig;
@@ -589,7 +590,7 @@ declare const tax_regions: {
589
590
  declare const tax_rates: {
590
591
  list: (props: {
591
592
  sdk: CoreConfig;
592
- query: string;
593
+ query?: string;
593
594
  }) => Promise<UnifiedTaxRateType[]>;
594
595
  retrieve: (props: {
595
596
  sdk: CoreConfig;
@@ -628,7 +629,7 @@ declare const tax_rates: {
628
629
  declare const locations: {
629
630
  list: (props: {
630
631
  sdk: CoreConfig;
631
- query: string;
632
+ query?: string;
632
633
  }) => Promise<UnifiedLocationType[]>;
633
634
  retrieve: (props: {
634
635
  sdk: CoreConfig;
@@ -667,7 +668,7 @@ declare const locations: {
667
668
  declare const fulfillments: {
668
669
  list: (props: {
669
670
  sdk: CoreConfig;
670
- query: string;
671
+ query?: string;
671
672
  }) => Promise<UnifiedFulfillmentType[]>;
672
673
  retrieve: (props: {
673
674
  sdk: CoreConfig;
@@ -703,4 +704,198 @@ declare const fulfillments: {
703
704
  }) => Promise<void>;
704
705
  };
705
706
 
706
- export { categories, collections, customers, fulfillments, initializeStallCore, inventory_levels, locations, order_notes, orders, payment_providers, payments, products, promotions, refunds, tax_rates, tax_regions, variants };
707
+ interface ConnectorCacheType {
708
+ id: string;
709
+ code: string;
710
+ timestamp: number;
711
+ }
712
+ interface SyncQueueType {
713
+ id: string;
714
+ action: "create" | "update" | "delete";
715
+ table: ConnectorModuleKey;
716
+ document_id: string;
717
+ stall_offline_id: string;
718
+ data: Record<string, any>;
719
+ timestamp: number;
720
+ status: "pending" | "syncing" | "completed" | "failed";
721
+ error?: string;
722
+ retry_count: number;
723
+ last_retry_at?: number;
724
+ }
725
+ interface SyncLogType {
726
+ id: string;
727
+ sync_batch_id: string;
728
+ table: ConnectorModuleKey;
729
+ action: "create" | "update" | "delete";
730
+ document_id: string;
731
+ stall_offline_id: string;
732
+ connector_id?: string;
733
+ status: "success" | "failed" | "pending";
734
+ error?: string;
735
+ timestamp: number;
736
+ duration_ms: number;
737
+ }
738
+ type ConnectorCacheTable = EntityTable<ConnectorCacheType, "id">;
739
+ type SyncQueueTable = EntityTable<SyncQueueType, "id">;
740
+ type SyncLogTable = EntityTable<SyncLogType, "id">;
741
+ type ProductsTable = EntityTable<UnifiedProductType, "id">;
742
+ type VariantsTable = EntityTable<UnifiedVariantsType, "id">;
743
+ type CollectionsTable = EntityTable<UnifiedCollectionType, "id">;
744
+ type CategoriesTable = EntityTable<UnifiedCategoryType, "id">;
745
+ type InventoryLevelsTable = EntityTable<UnifiedInventoryLevelType, "id">;
746
+ type InventoryHistoryTable = EntityTable<UnifiedInventoryLevelType, "id">;
747
+ type PromotionsTable = EntityTable<UnifiedPromotion, "id">;
748
+ type OrdersTable = EntityTable<UnifiedOrderType, "id">;
749
+ type OrderNotesTable = EntityTable<UnifiedOrderNote, "id">;
750
+ type RefundsTable = EntityTable<UnifiedOrderRefundType, "id">;
751
+ type PaymentProvidersTable = EntityTable<UnifiedPaymentProviderType, "id">;
752
+ type PaymentsTable = EntityTable<UnifiedPaymentCollectionType, "id">;
753
+ type TaxRegionsTable = EntityTable<UnifiedTaxRegionType, "id">;
754
+ type TaxRatesTable = EntityTable<UnifiedTaxRateType, "id">;
755
+ type CustomersTable = EntityTable<UnifiedCustomerType, "id">;
756
+ type LocationsTable = EntityTable<UnifiedLocationType, "id">;
757
+ type FulfillmentsTable = EntityTable<UnifiedFulfillmentType, "id">;
758
+
759
+ declare const sync_service: {
760
+ process_sync_queue: (props: {
761
+ sdk: CoreConfig;
762
+ }) => Promise<{
763
+ sync_batch_id: string;
764
+ total: number;
765
+ synced: number;
766
+ failed: number;
767
+ summary: {
768
+ table: ConnectorModuleKey;
769
+ synced: number;
770
+ failed: number;
771
+ }[];
772
+ }>;
773
+ sync_queue_item: (props: {
774
+ sdk: CoreConfig;
775
+ item: SyncQueueType;
776
+ sync_batch_id: string;
777
+ }) => Promise<{
778
+ success: boolean;
779
+ connector_id?: string;
780
+ error?: string;
781
+ }>;
782
+ start_sync_service: (props: {
783
+ sdk: CoreConfig;
784
+ interval?: number;
785
+ }) => Promise<void>;
786
+ stop_sync_service: () => void;
787
+ get_sync_stats: () => Promise<{
788
+ pending: number;
789
+ syncing: number;
790
+ failed: number;
791
+ total: number;
792
+ }>;
793
+ trigger_sync: (props: {
794
+ sdk: CoreConfig;
795
+ }) => Promise<{
796
+ sync_batch_id: string;
797
+ total: number;
798
+ synced: number;
799
+ failed: number;
800
+ summary: {
801
+ table: ConnectorModuleKey;
802
+ synced: number;
803
+ failed: number;
804
+ }[];
805
+ }>;
806
+ };
807
+
808
+ /**
809
+ * Generate a temporary offline ID
810
+ * Format: stall_{table}_{uuid}_{timestamp}
811
+ */
812
+ declare const generate_offline_id: (table: string) => string;
813
+ /**
814
+ * Save bulk data to local database, clearing existing data
815
+ */
816
+ declare const save_bulk_data: (props: {
817
+ table: string;
818
+ data: any[];
819
+ }) => Promise<void>;
820
+ /**
821
+ * Add a single item to the sync queue for later synchronization
822
+ */
823
+ declare const add_to_sync_queue: (props: {
824
+ action: "create" | "update" | "delete";
825
+ table: ConnectorModuleKey;
826
+ document_id: string;
827
+ stall_offline_id: string;
828
+ data: Record<string, any>;
829
+ }) => Promise<SyncQueueType>;
830
+ /**
831
+ * Get pending sync queue items grouped by table for dependency-aware syncing
832
+ */
833
+ declare const get_pending_sync_queue: () => Promise<Map<ConnectorModuleKey, SyncQueueType[]>>;
834
+ /**
835
+ * Update sync queue item status
836
+ */
837
+ declare const update_sync_queue_status: (props: {
838
+ id: string;
839
+ status: "pending" | "syncing" | "completed" | "failed";
840
+ error?: string;
841
+ retry_count?: number;
842
+ }) => Promise<void>;
843
+ /**
844
+ * Remove item from sync queue after successful sync
845
+ */
846
+ declare const remove_from_sync_queue: (id: string) => Promise<void>;
847
+ /**
848
+ * Add a sync log entry for tracking synchronization activities
849
+ */
850
+ declare const add_sync_log: (props: {
851
+ sync_batch_id: string;
852
+ table: ConnectorModuleKey;
853
+ action: "create" | "update" | "delete";
854
+ document_id: string;
855
+ stall_offline_id: string;
856
+ connector_id?: string;
857
+ status: "success" | "failed" | "pending";
858
+ error?: string;
859
+ duration_ms: number;
860
+ }) => Promise<SyncLogType>;
861
+ /**
862
+ * Get sync logs for a specific batch
863
+ */
864
+ declare const get_sync_logs_by_batch: (sync_batch_id: string) => Promise<SyncLogType[]>;
865
+ /**
866
+ * Get recent sync logs with optional filtering
867
+ */
868
+ declare const get_recent_sync_logs: (props?: {
869
+ limit?: number;
870
+ table?: ConnectorModuleKey;
871
+ status?: "success" | "failed" | "pending";
872
+ }) => Promise<SyncLogType[]>;
873
+ /**
874
+ * Clear old sync logs (keep last N days)
875
+ */
876
+ declare const cleanup_old_sync_logs: (days?: number) => Promise<void>;
877
+
878
+ declare const local_db: Dexie & {
879
+ connector_cache: ConnectorCacheTable;
880
+ sync_queue: SyncQueueTable;
881
+ sync_logs: SyncLogTable;
882
+ products: ProductsTable;
883
+ variants: VariantsTable;
884
+ collections: CollectionsTable;
885
+ categories: CategoriesTable;
886
+ inventory_levels: InventoryLevelsTable;
887
+ inventory_history: InventoryHistoryTable;
888
+ promotions: PromotionsTable;
889
+ orders: OrdersTable;
890
+ order_notes: OrderNotesTable;
891
+ refunds: RefundsTable;
892
+ payment_providers: PaymentProvidersTable;
893
+ payments: PaymentsTable;
894
+ tax_regions: TaxRegionsTable;
895
+ tax_rates: TaxRatesTable;
896
+ customers: CustomersTable;
897
+ locations: LocationsTable;
898
+ fulfillments: FulfillmentsTable;
899
+ };
900
+
901
+ 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, 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 };