Skip to content

Commit

Permalink
move type
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Mar 22, 2023
1 parent c2104d5 commit f2cac54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,21 @@ import {

import type {
InsightsClient,
InsightsEvent as _InsightsEvent,
InsightsMethod,
InsightsMethodMap,
InternalMiddleware,
Hit,
} from '../types';
import type {
AlgoliaSearchHelper,
PlainSearchParameters,
} from 'algoliasearch-helper';

// not every method is actually allowed to be called with the insights middleware
export type InsightsMethod =
| 'clickedObjectIDsAfterSearch'
| 'clickedObjectIDs'
| 'clickedFilters'
| 'convertedObjectIDsAfterSearch'
| 'convertedObjectIDs'
| 'convertedFilters'
| 'viewedObjectIDs'
| 'viewedFilters';

export type InsightsEvent<TMethod extends InsightsMethod = InsightsMethod> = {
insightsMethod?: TMethod;
payload: InsightsMethodMap[TMethod][0];
widgetType: string;
eventType: string; // 'view' | 'click' | 'conversion', but we're not restricting.
hits?: Hit[];
attribute?: string;
};

type ProvidedInsightsClient = InsightsClient | null | undefined;

export type InsightsEvent<TMethod extends InsightsMethod = InsightsMethod> =
_InsightsEvent<TMethod>;

export type InsightsProps<
TInsightsClient extends ProvidedInsightsClient = ProvidedInsightsClient
> = {
Expand Down
26 changes: 26 additions & 0 deletions packages/instantsearch.js/src/types/insights.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Hit } from './results';
import type {
InsightsMethodMap as _InsightsMethodMap,
InsightsClient as _InsightsClient,
Expand All @@ -14,6 +15,31 @@ export type {
export type InsightsMethodMap = _InsightsMethodMap;
export type InsightsClientMethod = keyof InsightsMethodMap;

/**
* Method allowed by the insights middleware.
*/
export type InsightsMethod =
| 'clickedObjectIDsAfterSearch'
| 'clickedObjectIDs'
| 'clickedFilters'
| 'convertedObjectIDsAfterSearch'
| 'convertedObjectIDs'
| 'convertedFilters'
| 'viewedObjectIDs'
| 'viewedFilters';

/**
* The event sent to the insights middleware.
*/
export type InsightsEvent<TMethod extends InsightsMethod = InsightsMethod> = {
insightsMethod?: TMethod;
payload: InsightsMethodMap[TMethod][0];
widgetType: string;
eventType: string; // 'view' | 'click' | 'conversion', but we're not restricting.
hits?: Hit[];
attribute?: string;
};

export type InsightsClientPayload = {
eventName: string;
queryID: string;
Expand Down

0 comments on commit f2cac54

Please sign in to comment.