Skip to content

Commit

Permalink
refactor: refactor api type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
MoumitaM committed Sep 6, 2024
1 parent 1415ae5 commit 45d30f0
Show file tree
Hide file tree
Showing 2 changed files with 503 additions and 401 deletions.
136 changes: 65 additions & 71 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,65 @@ export interface constructorOptions {
export type apiCallback = () => void;
export type FlushCallback = (error?: Error, data?: any) => void;

export type IdentifyParams = {
userId?: string;
anonymousId?: string;
context?: apiObject;
traits?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
};

export type PageParams = {
name: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
};

export type TrackParams = {
event: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
};

export type GroupParams = {
groupId: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
traits?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
};

export type ScreenParams = {
name: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
};

export type AliasParams = {
previousId: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
};

declare class Analytics {
/**
* Initialize a new `Analytics` with your RudderStack project's `writeKey` and an
Expand Down Expand Up @@ -145,17 +204,7 @@ declare class Analytics {
* @param {Function=} callback (optional)
* @return {Analytics}
*/
identify(
message: {
userId?: string;
anonymousId?: string;
context?: apiObject;
traits?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
},
callback?: apiCallback,
): Analytics;
identify(message: IdentifyParams, callback?: apiCallback): Analytics;
/**
* Send a group `message`.
*
Expand All @@ -170,18 +219,7 @@ declare class Analytics {
* @param {Function=} callback (optional)
* @return {Analytics}
*/
group(
message: {
groupId: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
traits?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
},
callback?: apiCallback,
): Analytics;
group(message: GroupParams, callback?: apiCallback): Analytics;
/**
* Send a track `message`.
*
Expand All @@ -196,18 +234,7 @@ declare class Analytics {
* @param {Function=} callback (optional)
* @return {Analytics}
*/
track(
message: {
event: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
},
callback?: apiCallback,
): Analytics;
track(message: TrackParams, callback?: apiCallback): Analytics;

/**
* Send a page `message`.
Expand All @@ -223,18 +250,7 @@ declare class Analytics {
* @param {Function=} callback (optional)
* @return {Analytics}
*/
page(
message: {
name: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
},
callback?: apiCallback,
): Analytics;
page(message: PageParams, callback?: apiCallback): Analytics;

/**
* Send a screen `message`.
Expand All @@ -250,18 +266,7 @@ declare class Analytics {
* @param {Function=} callback (optional)
* @return {Analytics}
*/
screen(
message: {
name: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
},
callback?: apiCallback,
): Analytics;
screen(message: ScreenParams, callback?: apiCallback): Analytics;

/**
* Send an alias `message`.
Expand All @@ -277,18 +282,7 @@ declare class Analytics {
* @param {Function=} callback (optional)
* @return {Analytics}
*/
alias(
message: {
previousId: string;
userId?: string;
anonymousId?: string;
context?: apiObject;
properties?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
},
callback?: apiCallback,
): Analytics;
alias(message: AliasParams, callback?: apiCallback): Analytics;

/**
* Flush the current queue
Expand Down
Loading

0 comments on commit 45d30f0

Please sign in to comment.