Skip to content

Commit

Permalink
feat: add support for both v0,v1 in handler for old server support
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Nov 23, 2023
1 parent 35a9210 commit 38d73b4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 41 deletions.
18 changes: 15 additions & 3 deletions src/adapters/networkHandlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { getIntegrations } = require('../routes/utils');

const handlers = {
generic: GenericNetworkHandler,
v0: {},
v1: {},
};

// Dynamically import the network handlers for all
Expand All @@ -16,16 +18,26 @@ SUPPORTED_VERSIONS.forEach((version) => {
const destinations = getIntegrations(path.resolve(__dirname, `../${version}/destinations`));
destinations.forEach((dest) => {
try {
handlers[dest] = require(`../${version}/destinations/${dest}/networkHandler`).networkHandler;
// handles = {
// v0: {
// dest: handler
// },
// v1: {
// dest: handler
// },
// generic: GenericNetworkHandler,
// }
handlers[version][dest] =
require(`../${version}/destinations/${dest}/networkHandler`).networkHandler;
} catch {
// Do nothing as exception indicates
// network handler is not defined for that destination
}
});
});

const getNetworkHandler = (type) => {
const NetworkHandler = handlers[type] || handlers.generic;
const getNetworkHandler = (type, version) => {
const NetworkHandler = handlers[version][type] || handlers.generic;
return new NetworkHandler();
};

Expand Down
8 changes: 7 additions & 1 deletion src/controllers/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ export class DeliveryController {
const requestMetadata = MiscService.getRequestMetadata(ctx);
const event = ctx.request.body as ProcessorTransformationOutput;
const { destination }: { destination: string } = ctx.params;
const { version }: { version: string } = ctx.params;
const integrationService = ServiceSelector.getNativeDestinationService();
try {
deliveryResponse = await integrationService.deliver(event, destination, requestMetadata);
deliveryResponse = await integrationService.deliver(
event,
destination,
requestMetadata,
version,
);
} catch (error: any) {
const metaTO = integrationService.getTags(
destination,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/DestinationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface DestinationService {
event: ProcessorTransformationOutput,
destinationType: string,
requestMetadata: NonNullable<unknown>,
version: string,
): Promise<DeliveryResponse>;

processUserDeletion(
Expand Down
2 changes: 2 additions & 0 deletions src/services/comparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@ export class ComparatorService implements DestinationService {
event: ProcessorTransformationOutput,
destinationType: string,
requestMetadata: NonNullable<unknown>,
version: string,

Check warning on line 371 in src/services/comparator.ts

View check run for this annotation

Codecov / codecov/patch

src/services/comparator.ts#L371

Added line #L371 was not covered by tests
): Promise<DeliveryResponse> {
const primaryResplist = await this.primaryService.deliver(
event,
destinationType,
requestMetadata,
version,
);
logger.error('[LIVE_COMPARE_TEST] not implemented for delivery routine');

Expand Down
3 changes: 2 additions & 1 deletion src/services/destination/nativeIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ export class NativeIntegrationDestinationService implements DestinationService {
destinationRequest: ProcessorTransformationOutput,
destinationType: string,
_requestMetadata: NonNullable<unknown>,
version: string,
): Promise<DeliveryResponse> {
try {
const networkHandler = networkHandlerFactory.getNetworkHandler(destinationType);
const networkHandler = networkHandlerFactory.getNetworkHandler(destinationType, version);
const rawProxyResponse = await networkHandler.proxy(destinationRequest, destinationType);
const processedProxyResponse = networkHandler.processAxiosResponse(rawProxyResponse);
return networkHandler.responseHandler(
Expand Down
36 changes: 0 additions & 36 deletions src/v1/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,6 @@ const {
// const { TransformerProxyError } = require('../../util/errorTypes');
const tags = require('../../../v0/util/tags');

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function checkIfFailuresAreRetryable(response, proxyOutputObj) {
const { status } = response;
try {
if (Array.isArray(status)) {
// iterate over each status, and if found retryable in conversations ..retry else discard
/* status : [{
"conversion": {
object (Conversion)
},
"errors": [
{
object (ConversionError)
}
],
"kind": string
}] */
for (const st of status) {
for (const err of st.errors) {
// if code is any of these, event is not retryable
if (
err.code === 'PERMISSION_DENIED' ||
err.code === 'INVALID_ARGUMENT' ||
err.code === 'NOT_FOUND'
) {
return false;
}
}
}
}
return true;
} catch (e) {
return false;
}
}

function isEventRetryable(element, proxyOutputObj) {
let flag = false;
let errorMsg = '';

Check warning on line 16 in src/v1/destinations/campaign_manager/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v1/destinations/campaign_manager/networkHandler.js#L14-L16

Added lines #L14 - L16 were not covered by tests
Expand Down

0 comments on commit 38d73b4

Please sign in to comment.