Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor api type declarations #150

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 57 additions & 71 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,57 @@ export interface constructorOptions {
export type apiCallback = () => void;
export type FlushCallback = (error?: Error, data?: any) => void;

type IdentityOptions =
| { userId: string; anonymousId?: string }
| { userId?: string; anonymousId: string };

export type IdentifyParams = {
context?: apiObject;
traits?: apiObject;
integrations?: integrationOptions;
timestamp?: Date;
} & IdentityOptions;

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

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

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

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

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

declare class Analytics {
/**
* Initialize a new `Analytics` with your RudderStack project's `writeKey` and an
Expand Down Expand Up @@ -145,17 +196,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 +211,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 +226,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 +242,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 +258,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 +274,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
Loading