-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
909cad0
commit 2337c7b
Showing
7 changed files
with
153 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { prepareProxyRequest, proxyRequest } from '../../../adapters/network'; | ||
import { processAxiosResponse } from '../../../adapters/utils/networkUtils'; | ||
import { BULK_ENDPOINTS } from '../../../v0/destinations/iterable/config'; | ||
import { CommonStrategy } from './commonStrategy'; | ||
import { TrackIdentifyStrategy } from './trackIdentifyStrategy'; | ||
|
||
interface ResponseParams { | ||
destinationRequest: { | ||
endpoint: string; | ||
}; | ||
} | ||
|
||
const strategyRegistry: { [key: string]: any } = { | ||
[TrackIdentifyStrategy.name]: new TrackIdentifyStrategy(), | ||
[CommonStrategy.name]: new CommonStrategy(), | ||
}; | ||
|
||
const getResponseStrategy = (endpoint: string) => { | ||
if (BULK_ENDPOINTS.some((path) => endpoint.includes(path))) { | ||
return strategyRegistry[TrackIdentifyStrategy.name]; | ||
} | ||
return strategyRegistry[CommonStrategy.name]; | ||
}; | ||
|
||
const responseHandler = (responseParams: ResponseParams) => { | ||
const { destinationRequest } = responseParams; | ||
const strategy = getResponseStrategy(destinationRequest.endpoint); | ||
return strategy.handleResponse(responseParams); | ||
}; | ||
|
||
function networkHandler(this: any) { | ||
this.prepareProxy = prepareProxyRequest; | ||
this.proxy = proxyRequest; | ||
this.processAxiosResponse = processAxiosResponse; | ||
this.responseHandler = responseHandler; | ||
} | ||
|
||
export { networkHandler }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ResponseStrategy } from './responseStrategy'; | ||
import { checkIfEventIsAbortableAndExtractErrorMessage } from '../../../v0/destinations/iterable/util'; | ||
import { CommonResponse } from './type'; | ||
|
||
interface ResponseParams { | ||
destinationResponse: { status: number; response: CommonResponse }; | ||
rudderJobMetadata: any[]; | ||
destinationRequest: { | ||
body: { | ||
JSON: { | ||
events?: any[]; | ||
users?: any[]; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
class TrackIdentifyStrategy extends ResponseStrategy { | ||
handleSuccess(responseParams: ResponseParams): { | ||
status: number; | ||
message: string; | ||
destinationResponse: { status: number; response: CommonResponse }; | ||
response: Array<{ statusCode: number; metadata: any; error: string }>; | ||
} { | ||
const { destinationResponse, rudderJobMetadata, destinationRequest } = responseParams; | ||
const { status } = destinationResponse; | ||
const responseWithIndividualEvents: Array<{ | ||
statusCode: number; | ||
metadata: any; | ||
error: string; | ||
}> = []; | ||
|
||
const { events, users } = destinationRequest.body.JSON; | ||
const finalData = events || users; | ||
|
||
if (finalData) { | ||
finalData.forEach((event, idx) => { | ||
const proxyOutput = { | ||
statusCode: 200, | ||
metadata: rudderJobMetadata[idx], | ||
error: 'success', | ||
}; | ||
|
||
const { isAbortable, errorMsg } = checkIfEventIsAbortableAndExtractErrorMessage( | ||
event, | ||
destinationResponse, | ||
); | ||
if (isAbortable) { | ||
proxyOutput.statusCode = 400; | ||
proxyOutput.error = errorMsg; | ||
} | ||
responseWithIndividualEvents.push(proxyOutput); | ||
}); | ||
} | ||
|
||
return { | ||
status, | ||
message: '[ITERABLE Response Handler] - Request Processed Successfully', | ||
destinationResponse, | ||
response: responseWithIndividualEvents, | ||
}; | ||
} | ||
} | ||
|
||
export { TrackIdentifyStrategy }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
interface FailedUpdates { | ||
invalidEmails?: string[]; | ||
invalidUserIds?: string[]; | ||
notFoundEmails?: string[]; | ||
notFoundUserIds?: string[]; | ||
invalidDataEmails?: string[]; | ||
invalidDataUserIds?: string[]; | ||
conflictEmails?: string[]; | ||
conflictUserIds?: string[]; | ||
forgottenEmails?: string[]; | ||
forgottenUserIds?: string[]; | ||
} | ||
|
||
export interface CommonResponse { | ||
msg?: string; // Optional since it's only in Response 1 | ||
code?: string; // Optional since it's only in Response 1 | ||
params?: Record<string, unknown>; // Optional, specific to Response 1 | ||
successCount?: number; // Shared by Response 2 and 3 | ||
failCount?: number; // Shared by Response 2 and 3 | ||
invalidEmails?: string[]; // Shared by Response 2 and 3 | ||
invalidUserIds?: string[]; // Shared by Response 2 and 3 | ||
filteredOutFields?: string[]; // Shared by Response 2 and 3 | ||
createdFields?: string[]; // Shared by Response 2 and 3 | ||
disallowedEventNames?: string[]; // Specific to Response 3 | ||
failedUpdates?: FailedUpdates; // Nested object for failed updates | ||
} |