{"version":3,"file":"types.mjs","sources":["../../../../src/clients/guide/types.ts"],"sourcesContent":["import { GenericData } from \"@knocklabs/types\";\n\n// i.e. useGuide vs useGuides\nexport type SelectQueryLimit = \"one\" | \"all\";\n\ntype SelectionResultMetadata = {\n  guideGroup: GuideGroupData;\n  // Additional info about the underlying select query behind the result.\n  filters: SelectFilterParams;\n  limit: SelectQueryLimit;\n  opts: SelectGuideOpts;\n};\n\n// Extends the map class to allow having metadata on it, which is used to record\n// the guide group context for the selection result (though currently only a\n// default global group is supported).\nexport class SelectionResult<K = number, V = KnockGuide> extends Map<K, V> {\n  metadata: SelectionResultMetadata | undefined;\n\n  constructor() {\n    super();\n  }\n}\n\n//\n// Fetch guides API\n//\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Any = any;\n\nexport interface StepMessageState {\n  seen_at: string | null;\n  read_at: string | null;\n  interacted_at: string | null;\n  archived_at: string | null;\n  link_clicked_at: string | null;\n}\n\nexport interface GuideStepData<TContent = Any> {\n  ref: string;\n  schema_key: string;\n  schema_semver: string;\n  schema_variant_key: string;\n  message: StepMessageState;\n  content: TContent;\n}\n\nexport interface GuideActivationUrlRuleData {\n  directive: \"allow\" | \"block\";\n  variable: \"pathname\";\n  operator: \"equal_to\" | \"contains\";\n  argument: string;\n}\n\ninterface GuideActivationUrlPatternData {\n  directive: \"allow\" | \"block\";\n  // At least one part should be present.\n  pathname?: string;\n  search?: string;\n}\n\nexport interface GuideData<TContent = Any> {\n  __typename: \"Guide\";\n  channel_id: string;\n  id: string;\n  key: string;\n  type: string;\n  semver: string;\n  active: boolean;\n  steps: GuideStepData<TContent>[];\n  activation_url_rules: GuideActivationUrlRuleData[];\n  activation_url_patterns: GuideActivationUrlPatternData[];\n  bypass_global_group_limit: boolean;\n  dashboard_url: string | null;\n  inserted_at: string;\n  updated_at: string;\n}\n\nexport interface GuideGroupData {\n  __typename: \"GuideGroup\";\n  key: string;\n  display_sequence: Array<GuideData[\"key\"]>;\n  display_sequence_unthrottled: Array<GuideData[\"key\"]> | null;\n  display_sequence_throttled: Array<GuideData[\"key\"]> | null;\n  display_interval: number | null;\n  inserted_at: string;\n  updated_at: string;\n}\n\ntype GuideIneligibilityReason =\n  | \"guide_not_active\"\n  | \"marked_as_archived\"\n  | \"target_conditions_not_met\"\n  | \"not_in_target_audience\";\n\nexport type GuideIneligibilityMarker = {\n  __typename: \"GuideIneligibilityMarker\";\n  key: KnockGuide[\"key\"];\n  reason: GuideIneligibilityReason;\n  message: string;\n};\n\nexport type GetGuidesQueryParams = {\n  data?: string;\n  tenant?: string;\n  type?: string;\n  force_all_guides?: boolean;\n};\n\nexport type GetGuidesResponse = {\n  entries: GuideData[];\n  guide_groups: GuideGroupData[];\n  guide_group_display_logs: Record<GuideGroupData[\"key\"], string>;\n  ineligible_guides: GuideIneligibilityMarker[];\n};\n\n//\n// Engagement actions API\n//\n\nexport type GuideEngagementEventBaseParams = {\n  // Base params required for all engagement update events\n  channel_id: string;\n  guide_key: string;\n  guide_id: string;\n  guide_step_ref: string;\n};\n\nexport type MarkAsSeenParams = GuideEngagementEventBaseParams & {\n  // Rendered step content seen by the recipient\n  content: GenericData;\n  // Target params\n  data?: GenericData;\n  tenant?: string;\n};\nexport type MarkAsInteractedParams = GuideEngagementEventBaseParams;\nexport type MarkAsArchivedParams = GuideEngagementEventBaseParams & {\n  unthrottled?: boolean;\n};\n\nexport type MarkGuideAsResponse = {\n  status: \"ok\";\n};\n\nexport type ResetGuideEngagementParams = {\n  guide_key: string;\n  tenant?: string;\n};\n\nexport type ResetGuideEngagementResponse = {\n  status: \"ok\";\n};\n\n//\n// Socket events\n//\n\ntype SocketEventType =\n  | \"guide.added\"\n  | \"guide.updated\"\n  | \"guide.removed\"\n  | \"guide_group.added\"\n  | \"guide_group.updated\"\n  | \"guide.live_preview_updated\";\n\ntype SocketEventPayload<E extends SocketEventType, D> = {\n  topic: string;\n  event: E;\n  data: D;\n};\n\nexport type GuideAddedEvent = SocketEventPayload<\n  \"guide.added\",\n  { guide: GuideData; eligible: true }\n>;\n\nexport type GuideUpdatedEvent = SocketEventPayload<\n  \"guide.updated\",\n  { guide: GuideData; eligible: boolean }\n>;\n\nexport type GuideRemovedEvent = SocketEventPayload<\n  \"guide.removed\",\n  { guide: Pick<GuideData, \"key\"> }\n>;\n\nexport type GuideGroupAddedEvent = SocketEventPayload<\n  \"guide_group.added\",\n  { guide_group: GuideGroupData }\n>;\n\nexport type GuideGroupUpdatedEvent = SocketEventPayload<\n  \"guide_group.updated\",\n  { guide_group: GuideGroupData }\n>;\n\nexport type GuideLivePreviewUpdatedEvent = SocketEventPayload<\n  \"guide.live_preview_updated\",\n  { guide: GuideData; eligible: boolean }\n>;\n\nexport type GuideSocketEvent =\n  | GuideAddedEvent\n  | GuideUpdatedEvent\n  | GuideRemovedEvent\n  | GuideGroupAddedEvent\n  | GuideGroupUpdatedEvent\n  | GuideLivePreviewUpdatedEvent;\n\n//\n// Guide client\n//\n\nexport interface KnockGuideStep<TContent = Any>\n  extends GuideStepData<TContent> {\n  markAsSeen: () => Promise<KnockGuideStep<TContent> | undefined>;\n  markAsInteracted: (params?: {\n    metadata?: GenericData;\n  }) => Promise<KnockGuideStep<TContent> | undefined>;\n  markAsArchived: () => Promise<KnockGuideStep<TContent> | undefined>;\n}\n\nexport interface KnockGuideActivationUrlPattern\n  extends GuideActivationUrlPatternData {\n  pattern: URLPattern;\n}\n\nexport interface KnockGuide<TContent = Any> extends GuideData<TContent> {\n  steps: KnockGuideStep<TContent>[];\n  activation_url_patterns: KnockGuideActivationUrlPattern[];\n  getStep: () => KnockGuideStep<TContent> | undefined;\n  hasEngagement: () => boolean;\n}\n\ntype QueryKey = string;\n\nexport type QueryStatus = {\n  status: \"loading\" | \"ok\" | \"error\";\n  error?: Error;\n};\n\nexport type DebugState = {\n  debugging?: boolean;\n  forcedGuideKey?: string | null;\n  focusedGuideKeys?: Record<KnockGuide[\"key\"], true>;\n  previewSessionId?: string | null;\n  skipEngagementTracking?: boolean;\n  ignoreDisplayInterval?: boolean;\n};\n\nexport type StoreState = {\n  guideGroups: GuideGroupData[];\n  guideGroupDisplayLogs: Record<GuideGroupData[\"key\"], string>;\n  guides: Record<KnockGuide[\"key\"], KnockGuide>;\n  ineligibleGuides: Record<\n    GuideIneligibilityMarker[\"key\"],\n    GuideIneligibilityMarker\n  >;\n  previewGuides: Record<KnockGuide[\"key\"], KnockGuide>;\n  queries: Record<QueryKey, QueryStatus>;\n  location: string | undefined;\n  counter: number;\n  debug?: DebugState;\n};\n\nexport type QueryFilterParams = Pick<GetGuidesQueryParams, \"type\">;\n\nexport type SelectFilterParams = {\n  key?: string;\n  type?: string;\n};\n\nexport type SelectGuideOpts = {\n  includeThrottled?: boolean;\n  recordSelectQuery?: boolean;\n};\n\nexport type SelectGuidesOpts = SelectGuideOpts;\n\nexport type TargetParams = {\n  data?: GenericData | undefined;\n  tenant?: string | undefined;\n};\n\nexport type ConstructorOpts = {\n  trackLocationFromWindow?: boolean;\n  trackDebugParams?: boolean;\n  orderResolutionDuration?: number;\n  throttleCheckInterval?: number;\n};\n\ntype SelectionResultByLimit = {\n  one?: SelectionResult;\n  all?: SelectionResult;\n};\n\ntype RecordedSelectionResults = {\n  key?: Record<KnockGuide[\"key\"], SelectionResultByLimit>;\n  type?: Record<KnockGuide[\"type\"], SelectionResultByLimit>;\n};\n\nexport type GroupStage = {\n  status: \"open\" | \"closed\" | \"patch\";\n  ordered: Array<KnockGuide[\"key\"]>;\n  resolved?: KnockGuide[\"key\"];\n  timeoutId: ReturnType<typeof setTimeout> | null;\n  results: RecordedSelectionResults;\n};\n"],"names":["SelectionResult","__publicField"],"mappings":";;;AAgBO,MAAMA,UAAoD,IAAU;AAAA,EAGzE,cAAc;AACN,UAAA;AAHR,IAAAC,EAAA;AAAA,EAGQ;AAEV;"}