import type { Persistor } from '@segment/sovran-react-native'; import type { Rule } from '@segment/tsub/dist/store'; import type { SegmentError } from './errors'; import type { FlushPolicy } from './flushPolicies'; import type { NativeModule } from 'react-native'; export type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined; export interface JsonMap { [key: string]: JsonValue; [index: number]: JsonValue; } export type JsonList = Array; export type SegmentEvent = TrackEventType | ScreenEventType | IdentifyEventType | GroupEventType | AliasEventType; interface BaseEventType { anonymousId?: string; messageId?: string; userId?: string; timestamp?: string; context?: PartialContext; integrations?: SegmentAPIIntegrations; _metadata?: DestinationMetadata; enrichment?: EnrichmentClosure; /** Internal: timestamp (ms) when event was added to queue. Stripped before upload. */ _queuedAt?: number; } export interface TrackEventType extends BaseEventType { type: EventType.TrackEvent; event: string; properties?: JsonMap; } export interface ScreenEventType extends BaseEventType { type: EventType.ScreenEvent; name: string; properties: JsonMap; } export interface IdentifyEventType extends BaseEventType { type: EventType.IdentifyEvent; traits?: UserTraits; } export interface GroupEventType extends BaseEventType { type: EventType.GroupEvent; groupId: string; traits?: GroupTraits; } export interface AliasEventType extends BaseEventType { type: EventType.AliasEvent; userId?: string; previousId: string; } export type UserTraits = JsonMap & { address?: { city?: string; country?: string; postalCode?: string; state?: string; street?: string; }; age?: number; avatar?: string; birthday?: string; company?: { name?: string; id?: string | number; industry?: string; employee_count?: number; plan?: string; }; createdAt?: string; description?: string; email?: string; firstName?: string; gender?: string; id?: string; lastName?: string; name?: string; phone?: string; title?: string; username?: string; website?: string; }; export type GroupTraits = JsonMap & { address?: { city?: string; country?: string; postalCode?: string; state?: string; street?: string; }; avatar?: string; createdAt?: string; description?: string; email?: string; employees?: string; id?: string; industry?: string; name?: string; phone?: string; website?: string; plan?: string; }; export interface LoggerType { info(message?: unknown, ...optionalParams: unknown[]): void; warn(message?: unknown, ...optionalParams: unknown[]): void; error(message?: unknown, ...optionalParams: unknown[]): void; } export interface DeactivableLoggerType extends LoggerType { enable(): void; disable(): void; } export type Config = { writeKey: string; debug?: boolean; logger?: DeactivableLoggerType; flushAt?: number; flushInterval?: number; flushPolicies?: FlushPolicy[]; trackAppLifecycleEvents?: boolean; maxBatchSize?: number; trackDeepLinks?: boolean; defaultSettings?: SegmentAPISettings; autoAddSegmentDestination?: boolean; collectDeviceId?: boolean; storePersistor?: Persistor; storePersistorSaveDelay?: number; proxy?: string; cdnProxy?: string; useSegmentEndpoints?: boolean; errorHandler?: (error: SegmentError) => void; /** Client-side httpConfig overrides (highest precedence over defaults and CDN). */ httpConfig?: DeepPartial; }; export type ClientMethods = { screen: (name: string, properties?: JsonMap, enrichment?: EnrichmentClosure) => Promise; track: (event: string, properties?: JsonMap, enrichment?: EnrichmentClosure) => Promise; identify: (userId?: string, userTraits?: UserTraits, enrichment?: EnrichmentClosure) => Promise; flush: () => Promise; group: (groupId: string, groupTraits?: GroupTraits, enrichment?: EnrichmentClosure) => Promise; alias: (newUserId: string, enrichment?: EnrichmentClosure) => Promise; reset: (resetAnonymousId?: boolean) => Promise; }; type ContextApp = { build: string; name: string; namespace: string; version: string; }; export type ContextDevice = { id?: string; manufacturer: string; model: string; name: string; type: string; adTrackingEnabled?: boolean; advertisingId?: string; trackingStatus?: string; token?: string; }; type ContextLibrary = { name: string; version: string; }; type ContextNetwork = { cellular: boolean; wifi: boolean; }; type ContextOS = { name: string; version: string; }; type ContextScreen = { height: number; width: number; density?: number; }; export type Context = { app: ContextApp; device: ContextDevice; library: ContextLibrary; locale: string; network: ContextNetwork; os: ContextOS; screen: ContextScreen; timezone: string; traits: UserTraits; instanceId: string; consent?: { categoryPreferences: Record; }; __eventOrigin?: { type: string; version?: string; }; }; /** * Makes all the properties in an object optional */ export type DeepPartial = { [Property in keyof T]?: Property extends object ? DeepPartial : Partial; }; export type PartialContext = DeepPartial; export type NativeContextInfo = { appName: string; appVersion: string; buildNumber: string; bundleId: string; locale: string; networkType: string; osName: string; osVersion: string; screenHeight: number; screenWidth: number; screenDensity?: number; timezone: string; manufacturer: string; model: string; deviceName: string; deviceId?: string; deviceType: string; adTrackingEnabled?: boolean; advertisingId?: string; }; export type SegmentAPIIntegration = { apiKey: string; apiHost: string; consentSettings?: { categories: string[]; }; } & T; type SegmentAmplitudeIntegration = { session_id: number; }; export type SegmentAdjustSettings = { appToken: string; setEnvironmentProduction?: boolean; trackAttributionData?: boolean; customEvents?: { [key: string]: string; }; }; export type SegmentBrazeSettings = { logPurchaseWhenRevenuePresent: boolean; }; export type IntegrationSettings = SegmentAPIIntegration | SegmentAPIIntegration | Record | boolean; export type SegmentAPIIntegrations = { [key: string]: IntegrationSettings; }; export type SegmentAPIConsentSettings = { allCategories: string[]; hasUnmappedDestinations: boolean; }; export type RoutingRule = Rule; export interface MetricsOptions { host?: string; sampleRate?: number; flushTimer?: number; maxQueueSize?: number; } export interface DestinationFilters { [key: string]: RoutingRule; } export interface EdgeFunctionSettings { downloadURL: string; version: string; } export type RateLimitConfig = { enabled: boolean; maxRetryCount: number; maxRetryInterval: number; maxRateLimitDuration: number; }; export type BackoffConfig = { enabled: boolean; maxRetryCount: number; baseBackoffInterval: number; maxBackoffInterval: number; maxTotalBackoffDuration: number; jitterPercent: number; default4xxBehavior: 'drop' | 'retry'; default5xxBehavior: 'drop' | 'retry'; statusCodeOverrides: Record; }; export type HttpConfig = { rateLimitConfig?: RateLimitConfig; backoffConfig?: BackoffConfig; }; export declare class ErrorClassification { readonly errorType: 'rate_limit' | 'transient' | 'permanent'; readonly retryAfterSeconds?: number; constructor(errorType: 'rate_limit' | 'transient' | 'permanent', retryAfterSeconds?: number); get isRetryable(): boolean; } export type SegmentAPISettings = { integrations: SegmentAPIIntegrations; edgeFunction?: EdgeFunctionSettings; middlewareSettings?: { routingRules: RoutingRule[]; }; metrics?: MetricsOptions; consentSettings?: SegmentAPIConsentSettings; httpConfig?: HttpConfig; }; export type DestinationMetadata = { bundled: string[]; unbundled: string[]; bundledIds: string[]; }; export declare enum PluginType { 'before' = "before", 'enrichment' = "enrichment", 'destination' = "destination", 'after' = "after", 'utility' = "utility" } export declare enum UpdateType { 'initial' = "initial", 'refresh' = "refresh" } export declare enum EventType { 'TrackEvent' = "track", 'IdentifyEvent' = "identify", 'ScreenEvent' = "screen", 'GroupEvent' = "group", 'AliasEvent' = "alias" } export type UserInfoState = { anonymousId: string; userId?: string; traits?: UserTraits | GroupTraits; }; export interface GetContextConfig { collectDeviceId: boolean; } export type AnalyticsReactNativeModule = NativeModule & { getContextInfo: (config: GetContextConfig) => Promise; }; export type EnrichmentClosure = (event: SegmentEvent) => SegmentEvent; export {}; //# sourceMappingURL=types.d.ts.map