@qhr123/sa2kit 0.3.1 → 0.4.0

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.
@@ -727,15 +727,209 @@ declare function useAutoTracking(analytics: Analytics | null, options?: {
727
727
  trackErrors?: boolean;
728
728
  }): void;
729
729
 
730
+ /**
731
+ * Web 平台适配器
732
+ * Browser/Next.js Platform Adapters
733
+ */
734
+
735
+ /**
736
+ * Web 存储适配器(使用 localStorage)
737
+ */
738
+ declare class WebStorageAdapter implements AnalyticsStorageAdapter {
739
+ private EVENTS_KEY;
740
+ private DEVICE_INFO_KEY;
741
+ private SESSION_ID_KEY;
742
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
743
+ getEvents(): Promise<AnalyticsEvent[]>;
744
+ clearEvents(): Promise<void>;
745
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
746
+ getDeviceInfo(): Promise<DeviceInfo | null>;
747
+ saveSessionId(sessionId: string): Promise<void>;
748
+ getSessionId(): Promise<string | null>;
749
+ }
750
+ /**
751
+ * Web 网络适配器
752
+ */
753
+ declare class WebNetworkAdapter implements AnalyticsNetworkAdapter {
754
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
755
+ isOnline(): Promise<boolean>;
756
+ }
757
+ /**
758
+ * Web 设备信息适配器
759
+ */
760
+ declare class WebDeviceAdapter implements AnalyticsDeviceAdapter {
761
+ getDeviceInfo(): Promise<DeviceInfo>;
762
+ generateDeviceId(): Promise<string>;
763
+ private getOSName;
764
+ private getOSVersion;
765
+ private getBrowserName;
766
+ private getBrowserVersion;
767
+ }
768
+ /**
769
+ * 统一的 Web 适配器对象
770
+ */
771
+ declare const webAdapter: {
772
+ storage: WebStorageAdapter;
773
+ network: WebNetworkAdapter;
774
+ device: WebDeviceAdapter;
775
+ };
776
+
777
+ /**
778
+ * Mobile 平台适配器
779
+ * React Native Platform Adapters
780
+ */
781
+
782
+ /**
783
+ * Mobile 存储适配器
784
+ * 需要在 mobile 项目中实现具体的 AsyncStorage 逻辑
785
+ */
786
+ declare class MobileStorageAdapter implements AnalyticsStorageAdapter {
787
+ private storage;
788
+ private EVENTS_KEY;
789
+ private DEVICE_INFO_KEY;
790
+ private SESSION_ID_KEY;
791
+ constructor(storage: {
792
+ getItem: (key: string) => Promise<string | null>;
793
+ setItem: (key: string, value: string) => Promise<void>;
794
+ removeItem: (key: string) => Promise<void>;
795
+ });
796
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
797
+ getEvents(): Promise<AnalyticsEvent[]>;
798
+ clearEvents(): Promise<void>;
799
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
800
+ getDeviceInfo(): Promise<DeviceInfo | null>;
801
+ saveSessionId(sessionId: string): Promise<void>;
802
+ getSessionId(): Promise<string | null>;
803
+ }
804
+ /**
805
+ * Mobile 网络适配器
806
+ */
807
+ declare class MobileNetworkAdapter implements AnalyticsNetworkAdapter {
808
+ private netInfo?;
809
+ constructor(netInfo?: {
810
+ fetch: () => Promise<{
811
+ isConnected: boolean | null;
812
+ }>;
813
+ } | undefined);
814
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
815
+ isOnline(): Promise<boolean>;
816
+ }
817
+ /**
818
+ * Mobile 设备信息适配器
819
+ */
820
+ declare class MobileDeviceAdapter implements AnalyticsDeviceAdapter {
821
+ private deviceInfoModule?;
822
+ constructor(deviceInfoModule?: {
823
+ getSystemName: () => Promise<string>;
824
+ getSystemVersion: () => Promise<string>;
825
+ getModel: () => Promise<string>;
826
+ getBrand: () => Promise<string>;
827
+ getUniqueId: () => Promise<string>;
828
+ } | undefined);
829
+ getDeviceInfo(): Promise<DeviceInfo>;
830
+ generateDeviceId(): Promise<string>;
831
+ private getDefaultDeviceInfo;
832
+ }
833
+
834
+ /**
835
+ * 小程序平台适配器
836
+ * WeChat MiniProgram Platform Adapters
837
+ */
838
+
839
+ /**
840
+ * 小程序存储适配器
841
+ */
842
+ declare class MiniappStorageAdapter implements AnalyticsStorageAdapter {
843
+ private storage?;
844
+ private EVENTS_KEY;
845
+ private DEVICE_INFO_KEY;
846
+ private SESSION_ID_KEY;
847
+ constructor(storage?: {
848
+ getStorageSync: (key: string) => any;
849
+ setStorageSync: (key: string, data: any) => void;
850
+ removeStorageSync: (key: string) => void;
851
+ } | undefined);
852
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
853
+ getEvents(): Promise<AnalyticsEvent[]>;
854
+ clearEvents(): Promise<void>;
855
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
856
+ getDeviceInfo(): Promise<DeviceInfo | null>;
857
+ saveSessionId(sessionId: string): Promise<void>;
858
+ getSessionId(): Promise<string | null>;
859
+ }
860
+ /**
861
+ * 小程序网络适配器
862
+ */
863
+ declare class MiniappNetworkAdapter implements AnalyticsNetworkAdapter {
864
+ private request?;
865
+ private netInfo?;
866
+ constructor(request?: {
867
+ request: (options: any) => Promise<any>;
868
+ } | undefined, netInfo?: {
869
+ getNetworkType: () => Promise<{
870
+ networkType: string;
871
+ }>;
872
+ } | undefined);
873
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
874
+ isOnline(): Promise<boolean>;
875
+ }
876
+ /**
877
+ * 小程序设备信息适配器
878
+ */
879
+ declare class MiniappDeviceAdapter implements AnalyticsDeviceAdapter {
880
+ private systemInfo?;
881
+ constructor(systemInfo?: {
882
+ getSystemInfoSync: () => any;
883
+ } | undefined);
884
+ getDeviceInfo(): Promise<DeviceInfo>;
885
+ generateDeviceId(): Promise<string>;
886
+ private getDefaultDeviceInfo;
887
+ }
888
+
889
+ /**
890
+ * Desktop 平台适配器
891
+ * Electron Platform Adapters
892
+ */
893
+
894
+ /**
895
+ * Desktop 存储适配器(使用 localStorage)
896
+ */
897
+ declare class DesktopStorageAdapter implements AnalyticsStorageAdapter {
898
+ private EVENTS_KEY;
899
+ private DEVICE_INFO_KEY;
900
+ private SESSION_ID_KEY;
901
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
902
+ getEvents(): Promise<AnalyticsEvent[]>;
903
+ clearEvents(): Promise<void>;
904
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
905
+ getDeviceInfo(): Promise<DeviceInfo | null>;
906
+ saveSessionId(sessionId: string): Promise<void>;
907
+ getSessionId(): Promise<string | null>;
908
+ }
909
+ /**
910
+ * Desktop 网络适配器
911
+ */
912
+ declare class DesktopNetworkAdapter implements AnalyticsNetworkAdapter {
913
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
914
+ isOnline(): Promise<boolean>;
915
+ }
916
+ /**
917
+ * Desktop 设备信息适配器
918
+ */
919
+ declare class DesktopDeviceAdapter implements AnalyticsDeviceAdapter {
920
+ getDeviceInfo(): Promise<DeviceInfo>;
921
+ generateDeviceId(): Promise<string>;
922
+ private getOSName;
923
+ private getOSVersion;
924
+ }
925
+
730
926
  /**
731
927
  * Analytics 埋点分析模块
732
928
  *
733
929
  * 提供完整的事件追踪、用户行为分析、数据上报等功能
734
- *
735
- * 注意:此模块不包含平台特定的适配器(web/mobile/desktop/miniapp)
736
- * 如需使用平台适配器,请在项目中自行实现
930
+ * 包含多平台适配器(web/mobile/desktop/miniapp)
737
931
  */
738
932
 
739
933
  declare const ANALYTICS_VERSION = "1.0.0";
740
934
 
741
- export { ANALYTICS_VERSION, Analytics, type AnalyticsConfig, type AnalyticsDeviceAdapter, type AnalyticsEvent, type AnalyticsNetworkAdapter, type AnalyticsStorageAdapter, type ApiCallEvent, type BaseEvent, CatchError, type ClickEvent, type DeviceInfo, type ErrorEvent, EventPriority, EventQueue, EventType, type PageViewEvent, type PerformanceEvent, Track, TrackClick, TrackPerformance, type UploadResponse, Uploader, createAnalytics, createDesktopConfig, createMiniappConfig, createMobileConfig, createWebConfig, debounce, deepClone, formatEvent, formatTimestamp, generateUniqueId, getAllInstanceKeys, getAnalyticsInstance, getBatchSize, getCurrentPageTitle, getCurrentPageUrl, getEventSize, getGlobalAnalytics, getPageDuration, getReferrer, isAnalyticsInitialized, isDevelopment, isMobile, mergeEventProperties, resetAllAnalytics, resetAnalytics, safeParse, safeStringify, sanitizeEvent, setGlobalAnalytics, throttle, useAnalytics, useAutoTracking, useErrorTracking, usePageDuration, usePageView, usePerformanceTracking, useTrackClick, useTrackEvent, validateEvent, validateEvents };
935
+ export { ANALYTICS_VERSION, Analytics, type AnalyticsConfig, type AnalyticsDeviceAdapter, type AnalyticsEvent, type AnalyticsNetworkAdapter, type AnalyticsStorageAdapter, type ApiCallEvent, type BaseEvent, CatchError, type ClickEvent, DesktopDeviceAdapter, DesktopNetworkAdapter, DesktopStorageAdapter, type DeviceInfo, type ErrorEvent, EventPriority, EventQueue, EventType, MiniappDeviceAdapter, MiniappNetworkAdapter, MiniappStorageAdapter, MobileDeviceAdapter, MobileNetworkAdapter, MobileStorageAdapter, type PageViewEvent, type PerformanceEvent, Track, TrackClick, TrackPerformance, type UploadResponse, Uploader, WebDeviceAdapter, WebNetworkAdapter, WebStorageAdapter, createAnalytics, createDesktopConfig, createMiniappConfig, createMobileConfig, createWebConfig, debounce, deepClone, formatEvent, formatTimestamp, generateUniqueId, getAllInstanceKeys, getAnalyticsInstance, getBatchSize, getCurrentPageTitle, getCurrentPageUrl, getEventSize, getGlobalAnalytics, getPageDuration, getReferrer, isAnalyticsInitialized, isDevelopment, isMobile, mergeEventProperties, resetAllAnalytics, resetAnalytics, safeParse, safeStringify, sanitizeEvent, setGlobalAnalytics, throttle, useAnalytics, useAutoTracking, useErrorTracking, usePageDuration, usePageView, usePerformanceTracking, useTrackClick, useTrackEvent, validateEvent, validateEvents, webAdapter };
@@ -727,15 +727,209 @@ declare function useAutoTracking(analytics: Analytics | null, options?: {
727
727
  trackErrors?: boolean;
728
728
  }): void;
729
729
 
730
+ /**
731
+ * Web 平台适配器
732
+ * Browser/Next.js Platform Adapters
733
+ */
734
+
735
+ /**
736
+ * Web 存储适配器(使用 localStorage)
737
+ */
738
+ declare class WebStorageAdapter implements AnalyticsStorageAdapter {
739
+ private EVENTS_KEY;
740
+ private DEVICE_INFO_KEY;
741
+ private SESSION_ID_KEY;
742
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
743
+ getEvents(): Promise<AnalyticsEvent[]>;
744
+ clearEvents(): Promise<void>;
745
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
746
+ getDeviceInfo(): Promise<DeviceInfo | null>;
747
+ saveSessionId(sessionId: string): Promise<void>;
748
+ getSessionId(): Promise<string | null>;
749
+ }
750
+ /**
751
+ * Web 网络适配器
752
+ */
753
+ declare class WebNetworkAdapter implements AnalyticsNetworkAdapter {
754
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
755
+ isOnline(): Promise<boolean>;
756
+ }
757
+ /**
758
+ * Web 设备信息适配器
759
+ */
760
+ declare class WebDeviceAdapter implements AnalyticsDeviceAdapter {
761
+ getDeviceInfo(): Promise<DeviceInfo>;
762
+ generateDeviceId(): Promise<string>;
763
+ private getOSName;
764
+ private getOSVersion;
765
+ private getBrowserName;
766
+ private getBrowserVersion;
767
+ }
768
+ /**
769
+ * 统一的 Web 适配器对象
770
+ */
771
+ declare const webAdapter: {
772
+ storage: WebStorageAdapter;
773
+ network: WebNetworkAdapter;
774
+ device: WebDeviceAdapter;
775
+ };
776
+
777
+ /**
778
+ * Mobile 平台适配器
779
+ * React Native Platform Adapters
780
+ */
781
+
782
+ /**
783
+ * Mobile 存储适配器
784
+ * 需要在 mobile 项目中实现具体的 AsyncStorage 逻辑
785
+ */
786
+ declare class MobileStorageAdapter implements AnalyticsStorageAdapter {
787
+ private storage;
788
+ private EVENTS_KEY;
789
+ private DEVICE_INFO_KEY;
790
+ private SESSION_ID_KEY;
791
+ constructor(storage: {
792
+ getItem: (key: string) => Promise<string | null>;
793
+ setItem: (key: string, value: string) => Promise<void>;
794
+ removeItem: (key: string) => Promise<void>;
795
+ });
796
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
797
+ getEvents(): Promise<AnalyticsEvent[]>;
798
+ clearEvents(): Promise<void>;
799
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
800
+ getDeviceInfo(): Promise<DeviceInfo | null>;
801
+ saveSessionId(sessionId: string): Promise<void>;
802
+ getSessionId(): Promise<string | null>;
803
+ }
804
+ /**
805
+ * Mobile 网络适配器
806
+ */
807
+ declare class MobileNetworkAdapter implements AnalyticsNetworkAdapter {
808
+ private netInfo?;
809
+ constructor(netInfo?: {
810
+ fetch: () => Promise<{
811
+ isConnected: boolean | null;
812
+ }>;
813
+ } | undefined);
814
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
815
+ isOnline(): Promise<boolean>;
816
+ }
817
+ /**
818
+ * Mobile 设备信息适配器
819
+ */
820
+ declare class MobileDeviceAdapter implements AnalyticsDeviceAdapter {
821
+ private deviceInfoModule?;
822
+ constructor(deviceInfoModule?: {
823
+ getSystemName: () => Promise<string>;
824
+ getSystemVersion: () => Promise<string>;
825
+ getModel: () => Promise<string>;
826
+ getBrand: () => Promise<string>;
827
+ getUniqueId: () => Promise<string>;
828
+ } | undefined);
829
+ getDeviceInfo(): Promise<DeviceInfo>;
830
+ generateDeviceId(): Promise<string>;
831
+ private getDefaultDeviceInfo;
832
+ }
833
+
834
+ /**
835
+ * 小程序平台适配器
836
+ * WeChat MiniProgram Platform Adapters
837
+ */
838
+
839
+ /**
840
+ * 小程序存储适配器
841
+ */
842
+ declare class MiniappStorageAdapter implements AnalyticsStorageAdapter {
843
+ private storage?;
844
+ private EVENTS_KEY;
845
+ private DEVICE_INFO_KEY;
846
+ private SESSION_ID_KEY;
847
+ constructor(storage?: {
848
+ getStorageSync: (key: string) => any;
849
+ setStorageSync: (key: string, data: any) => void;
850
+ removeStorageSync: (key: string) => void;
851
+ } | undefined);
852
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
853
+ getEvents(): Promise<AnalyticsEvent[]>;
854
+ clearEvents(): Promise<void>;
855
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
856
+ getDeviceInfo(): Promise<DeviceInfo | null>;
857
+ saveSessionId(sessionId: string): Promise<void>;
858
+ getSessionId(): Promise<string | null>;
859
+ }
860
+ /**
861
+ * 小程序网络适配器
862
+ */
863
+ declare class MiniappNetworkAdapter implements AnalyticsNetworkAdapter {
864
+ private request?;
865
+ private netInfo?;
866
+ constructor(request?: {
867
+ request: (options: any) => Promise<any>;
868
+ } | undefined, netInfo?: {
869
+ getNetworkType: () => Promise<{
870
+ networkType: string;
871
+ }>;
872
+ } | undefined);
873
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
874
+ isOnline(): Promise<boolean>;
875
+ }
876
+ /**
877
+ * 小程序设备信息适配器
878
+ */
879
+ declare class MiniappDeviceAdapter implements AnalyticsDeviceAdapter {
880
+ private systemInfo?;
881
+ constructor(systemInfo?: {
882
+ getSystemInfoSync: () => any;
883
+ } | undefined);
884
+ getDeviceInfo(): Promise<DeviceInfo>;
885
+ generateDeviceId(): Promise<string>;
886
+ private getDefaultDeviceInfo;
887
+ }
888
+
889
+ /**
890
+ * Desktop 平台适配器
891
+ * Electron Platform Adapters
892
+ */
893
+
894
+ /**
895
+ * Desktop 存储适配器(使用 localStorage)
896
+ */
897
+ declare class DesktopStorageAdapter implements AnalyticsStorageAdapter {
898
+ private EVENTS_KEY;
899
+ private DEVICE_INFO_KEY;
900
+ private SESSION_ID_KEY;
901
+ saveEvents(events: AnalyticsEvent[]): Promise<void>;
902
+ getEvents(): Promise<AnalyticsEvent[]>;
903
+ clearEvents(): Promise<void>;
904
+ saveDeviceInfo(info: DeviceInfo): Promise<void>;
905
+ getDeviceInfo(): Promise<DeviceInfo | null>;
906
+ saveSessionId(sessionId: string): Promise<void>;
907
+ getSessionId(): Promise<string | null>;
908
+ }
909
+ /**
910
+ * Desktop 网络适配器
911
+ */
912
+ declare class DesktopNetworkAdapter implements AnalyticsNetworkAdapter {
913
+ upload(url: string, events: AnalyticsEvent[]): Promise<UploadResponse>;
914
+ isOnline(): Promise<boolean>;
915
+ }
916
+ /**
917
+ * Desktop 设备信息适配器
918
+ */
919
+ declare class DesktopDeviceAdapter implements AnalyticsDeviceAdapter {
920
+ getDeviceInfo(): Promise<DeviceInfo>;
921
+ generateDeviceId(): Promise<string>;
922
+ private getOSName;
923
+ private getOSVersion;
924
+ }
925
+
730
926
  /**
731
927
  * Analytics 埋点分析模块
732
928
  *
733
929
  * 提供完整的事件追踪、用户行为分析、数据上报等功能
734
- *
735
- * 注意:此模块不包含平台特定的适配器(web/mobile/desktop/miniapp)
736
- * 如需使用平台适配器,请在项目中自行实现
930
+ * 包含多平台适配器(web/mobile/desktop/miniapp)
737
931
  */
738
932
 
739
933
  declare const ANALYTICS_VERSION = "1.0.0";
740
934
 
741
- export { ANALYTICS_VERSION, Analytics, type AnalyticsConfig, type AnalyticsDeviceAdapter, type AnalyticsEvent, type AnalyticsNetworkAdapter, type AnalyticsStorageAdapter, type ApiCallEvent, type BaseEvent, CatchError, type ClickEvent, type DeviceInfo, type ErrorEvent, EventPriority, EventQueue, EventType, type PageViewEvent, type PerformanceEvent, Track, TrackClick, TrackPerformance, type UploadResponse, Uploader, createAnalytics, createDesktopConfig, createMiniappConfig, createMobileConfig, createWebConfig, debounce, deepClone, formatEvent, formatTimestamp, generateUniqueId, getAllInstanceKeys, getAnalyticsInstance, getBatchSize, getCurrentPageTitle, getCurrentPageUrl, getEventSize, getGlobalAnalytics, getPageDuration, getReferrer, isAnalyticsInitialized, isDevelopment, isMobile, mergeEventProperties, resetAllAnalytics, resetAnalytics, safeParse, safeStringify, sanitizeEvent, setGlobalAnalytics, throttle, useAnalytics, useAutoTracking, useErrorTracking, usePageDuration, usePageView, usePerformanceTracking, useTrackClick, useTrackEvent, validateEvent, validateEvents };
935
+ export { ANALYTICS_VERSION, Analytics, type AnalyticsConfig, type AnalyticsDeviceAdapter, type AnalyticsEvent, type AnalyticsNetworkAdapter, type AnalyticsStorageAdapter, type ApiCallEvent, type BaseEvent, CatchError, type ClickEvent, DesktopDeviceAdapter, DesktopNetworkAdapter, DesktopStorageAdapter, type DeviceInfo, type ErrorEvent, EventPriority, EventQueue, EventType, MiniappDeviceAdapter, MiniappNetworkAdapter, MiniappStorageAdapter, MobileDeviceAdapter, MobileNetworkAdapter, MobileStorageAdapter, type PageViewEvent, type PerformanceEvent, Track, TrackClick, TrackPerformance, type UploadResponse, Uploader, WebDeviceAdapter, WebNetworkAdapter, WebStorageAdapter, createAnalytics, createDesktopConfig, createMiniappConfig, createMobileConfig, createWebConfig, debounce, deepClone, formatEvent, formatTimestamp, generateUniqueId, getAllInstanceKeys, getAnalyticsInstance, getBatchSize, getCurrentPageTitle, getCurrentPageUrl, getEventSize, getGlobalAnalytics, getPageDuration, getReferrer, isAnalyticsInitialized, isDevelopment, isMobile, mergeEventProperties, resetAllAnalytics, resetAnalytics, safeParse, safeStringify, sanitizeEvent, setGlobalAnalytics, throttle, useAnalytics, useAutoTracking, useErrorTracking, usePageDuration, usePageView, usePerformanceTracking, useTrackClick, useTrackEvent, validateEvent, validateEvents, webAdapter };