-
Notifications
You must be signed in to change notification settings - Fork 121
fix: adding transformer proxy for iterable #3878
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
096d008
fix: adding transformer proxy for iterable
shrouti1507 2a10f70
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 2b34182
fix: adding component test cases
shrouti1507 8742244
fix: adding factory pattern
shrouti1507 25a5ced
fix: code redesigning
shrouti1507 c87c5ce
fix: decoupling networkHandler and specific strategy
shrouti1507 1058ec1
fix: simplifying logic
shrouti1507 f11d7eb
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 909cad0
fix: convert to registry pattern
shrouti1507 2337c7b
fix: converting to typescript
shrouti1507 9eb31bf
fix: removing unnecessary comments
shrouti1507 97d531f
fix: adding data delivery test cases for all endpoints
shrouti1507 3789652
chore: improve iterable network handler (#3918)
aae7b3d
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 9ee2847
fix: review comments addressed
shrouti1507 a5ba58c
fix: small refactoring
shrouti1507 d00f31f
fix: update for supporting disallowed events
shrouti1507 707dfe8
fix: code review suggestion
shrouti1507 8e5d6ab
fix: fixing test cases
shrouti1507 9ce4575
fix: review comment addressed
shrouti1507 de1bb5c
fix: adding type definitions
shrouti1507 85b1166
fix: separating handle error functions
shrouti1507 933473a
Merge branch 'develop' into fix.iterable-networkhandler
shrouti1507 ebfeffc
fix: migrating processor and router test cases
shrouti1507 4cc52d2
fix: review comment addressed
shrouti1507 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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,33 @@ | ||
import { prepareProxyRequest, proxyRequest } from '../../../adapters/network'; | ||
import { processAxiosResponse } from '../../../adapters/utils/networkUtils'; | ||
import { BULK_ENDPOINTS } from '../../../v0/destinations/iterable/config'; | ||
import { GenericStrategy } from './strategies/generic'; | ||
import { TrackIdentifyStrategy } from './strategies/track-identify'; | ||
import { GenericProxyHandlerInput } from './types'; | ||
|
||
const strategyRegistry: { [key: string]: any } = { | ||
[TrackIdentifyStrategy.name]: new TrackIdentifyStrategy(), | ||
[GenericStrategy.name]: new GenericStrategy(), | ||
}; | ||
|
||
const getResponseStrategy = (endpoint: string) => { | ||
if (BULK_ENDPOINTS.some((path) => endpoint.includes(path))) { | ||
return strategyRegistry[TrackIdentifyStrategy.name]; | ||
} | ||
return strategyRegistry[GenericStrategy.name]; | ||
}; | ||
|
||
const responseHandler = (responseParams: GenericProxyHandlerInput) => { | ||
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 hidden or 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,22 @@ | ||
import { isHttpStatusSuccess } from '../../../../v0/util'; | ||
import { GenericProxyHandlerInput } from '../types'; | ||
|
||
// Base strategy is the base class for all strategies in Iterable destination | ||
abstract class BaseStrategy { | ||
handleResponse(responseParams: GenericProxyHandlerInput): void { | ||
const { destinationResponse } = responseParams; | ||
const { status } = destinationResponse; | ||
|
||
if (!isHttpStatusSuccess(status)) { | ||
return this.handleError(responseParams); | ||
} | ||
|
||
return this.handleSuccess(responseParams); | ||
} | ||
|
||
abstract handleError(responseParams: GenericProxyHandlerInput): void; | ||
|
||
abstract handleSuccess(responseParams: any): void; | ||
} | ||
|
||
export { BaseStrategy }; |
This file contains hidden or 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,57 @@ | ||
import { BaseStrategy } from './base'; | ||
import { | ||
GenericProxyHandlerInput, | ||
IterableBulkApiResponse, | ||
IterableSuccessResponse, | ||
} from '../types'; | ||
import { ProxyMetdata } from '../../../../types'; | ||
import { TransformerProxyError } from '../../../../v0/util/errorTypes'; | ||
import { TAG_NAMES } from '../../../../v0/util/tags'; | ||
import { getDynamicErrorType } from '../../../../adapters/utils/networkUtils'; | ||
|
||
class GenericStrategy extends BaseStrategy { | ||
handleSuccess(responseParams: { | ||
destinationResponse: IterableBulkApiResponse; | ||
rudderJobMetadata: ProxyMetdata[]; | ||
}): IterableSuccessResponse { | ||
const { destinationResponse, rudderJobMetadata } = responseParams; | ||
const { status } = destinationResponse; | ||
|
||
const responseWithIndividualEvents = rudderJobMetadata.map((metadata) => ({ | ||
statusCode: status, | ||
metadata, | ||
error: 'success', | ||
})); | ||
|
||
return { | ||
status, | ||
message: '[ITERABLE Response Handler] - Request Processed Successfully', | ||
destinationResponse, | ||
response: responseWithIndividualEvents, | ||
}; | ||
} | ||
|
||
handleError(responseParams: GenericProxyHandlerInput): void { | ||
const { destinationResponse, rudderJobMetadata } = responseParams; | ||
const { response, status } = destinationResponse; | ||
const responseMessage = response.params || response.msg || response.message; | ||
const errorMessage = JSON.stringify(responseMessage) || 'unknown error format'; | ||
|
||
const responseWithIndividualEvents = rudderJobMetadata.map((metadata) => ({ | ||
statusCode: status, | ||
metadata, | ||
error: errorMessage, | ||
})); | ||
|
||
throw new TransformerProxyError( | ||
`ITERABLE: Error transformer proxy during ITERABLE response transformation. ${errorMessage}`, | ||
status, | ||
{ [TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status) }, | ||
destinationResponse, | ||
'', | ||
responseWithIndividualEvents, | ||
); | ||
} | ||
} | ||
|
||
export { GenericStrategy }; |
This file contains hidden or 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,69 @@ | ||
import { BaseStrategy } from './base'; | ||
import { GenericProxyHandlerInput, IterableBulkProxyInput } from '../types'; | ||
import { checkIfEventIsAbortableAndExtractErrorMessage } from '../utils'; | ||
import { DeliveryJobState, DeliveryV1Response } from '../../../../types'; | ||
import { TransformerProxyError } from '../../../../v0/util/errorTypes'; | ||
import { getDynamicErrorType } from '../../../../adapters/utils/networkUtils'; | ||
import { TAG_NAMES } from '../../../../v0/util/tags'; | ||
|
||
class TrackIdentifyStrategy extends BaseStrategy { | ||
handleSuccess(responseParams: IterableBulkProxyInput): DeliveryV1Response { | ||
const { destinationResponse, rudderJobMetadata, destinationRequest } = responseParams; | ||
const { status } = destinationResponse; | ||
const responseWithIndividualEvents: DeliveryJobState[] = []; | ||
|
||
const { events, users } = destinationRequest?.body.JSON || {}; | ||
const finalData = events || users; | ||
|
||
if (finalData) { | ||
finalData.forEach((event, idx) => { | ||
shrouti1507 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const parsedOutput = { | ||
statusCode: 200, | ||
metadata: rudderJobMetadata[idx], | ||
error: 'success', | ||
}; | ||
|
||
const { isAbortable, errorMsg } = checkIfEventIsAbortableAndExtractErrorMessage( | ||
event, | ||
destinationResponse, | ||
); | ||
if (isAbortable) { | ||
parsedOutput.statusCode = 400; | ||
parsedOutput.error = errorMsg; | ||
} | ||
responseWithIndividualEvents.push(parsedOutput); | ||
}); | ||
} | ||
|
||
return { | ||
status, | ||
message: '[ITERABLE Response Handler] - Request Processed Successfully', | ||
destinationResponse, | ||
response: responseWithIndividualEvents, | ||
}; | ||
} | ||
|
||
handleError(responseParams: GenericProxyHandlerInput): void { | ||
const { destinationResponse, rudderJobMetadata } = responseParams; | ||
const { response, status } = destinationResponse; | ||
const responseMessage = response.params || response.msg || response.message; | ||
const errorMessage = JSON.stringify(responseMessage) || 'unknown error format'; | ||
|
||
const responseWithIndividualEvents = rudderJobMetadata.map((metadata) => ({ | ||
statusCode: status, | ||
metadata, | ||
error: errorMessage, | ||
})); | ||
|
||
throw new TransformerProxyError( | ||
`ITERABLE: Error transformer proxy during ITERABLE response transformation. ${errorMessage}`, | ||
status, | ||
{ [TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status) }, | ||
destinationResponse, | ||
'', | ||
responseWithIndividualEvents, | ||
); | ||
} | ||
} | ||
|
||
export { TrackIdentifyStrategy }; |
This file contains hidden or 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,69 @@ | ||
import { ProxyMetdata, ProxyV1Request } from '../../../types'; | ||
|
||
type FailedUpdates = { | ||
invalidEmails?: string[]; | ||
invalidUserIds?: string[]; | ||
notFoundEmails?: string[]; | ||
notFoundUserIds?: string[]; | ||
invalidDataEmails?: string[]; | ||
invalidDataUserIds?: string[]; | ||
conflictEmails?: string[]; | ||
conflictUserIds?: string[]; | ||
forgottenEmails?: string[]; | ||
forgottenUserIds?: string[]; | ||
}; | ||
|
||
export type GeneralApiResponse = { | ||
msg?: string; | ||
code?: string; | ||
params?: Record<string, unknown>; | ||
successCount?: number; | ||
failCount?: number; | ||
invalidEmails?: string[]; | ||
invalidUserIds?: string[]; | ||
filteredOutFields?: string[]; | ||
createdFields?: string[]; | ||
disallowedEventNames?: string[]; | ||
failedUpdates?: FailedUpdates; | ||
}; | ||
|
||
export type IterableBulkApiResponse = { | ||
status: number; | ||
response: GeneralApiResponse; | ||
}; | ||
|
||
type IterableBulkRequestBody = { | ||
events?: any[]; | ||
users?: any[]; | ||
}; | ||
|
||
export type IterableBulkProxyInput = { | ||
destinationResponse: IterableBulkApiResponse; | ||
rudderJobMetadata: ProxyMetdata[]; | ||
destType: string; | ||
destinationRequest?: { | ||
body: { | ||
JSON: IterableBulkRequestBody; | ||
}; | ||
}; | ||
}; | ||
|
||
export type GenericProxyHandlerInput = { | ||
destinationResponse: any; | ||
rudderJobMetadata: ProxyMetdata[]; | ||
destType: string; | ||
destinationRequest: ProxyV1Request; | ||
}; | ||
|
||
export type Response = { | ||
statusCode: number; | ||
metadata: any; | ||
error: string; | ||
}; | ||
|
||
export type IterableSuccessResponse = { | ||
status: number; | ||
message: string; | ||
destinationResponse: IterableBulkApiResponse; | ||
response: Response[]; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.