-
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.
Merge branch 'develop' into fix.iterable-networkhandler
- Loading branch information
Showing
33 changed files
with
1,210 additions
and
106 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 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 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,5 @@ | ||
import { SourceInputConversionResult } from '../../../types'; | ||
|
||
export abstract class VersionConversionStrategy<I, O> { | ||
abstract convert(sourceEvents: I[]): SourceInputConversionResult<O>[]; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/controllers/util/conversionStrategies/strategyDefault.ts
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,15 @@ | ||
import { SourceInputConversionResult } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyDefault extends VersionConversionStrategy< | ||
NonNullable<unknown>, | ||
NonNullable<unknown> | ||
> { | ||
convert( | ||
sourceEvents: NonNullable<unknown>[], | ||
): SourceInputConversionResult<NonNullable<unknown>>[] { | ||
return sourceEvents.map((sourceEvent) => ({ | ||
output: sourceEvent, | ||
})); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/controllers/util/conversionStrategies/strategyV0ToV1.ts
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,11 @@ | ||
import { SourceInput, SourceInputConversionResult } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyV0ToV1 extends VersionConversionStrategy<NonNullable<unknown>, SourceInput> { | ||
convert(sourceEvents: NonNullable<unknown>[]): SourceInputConversionResult<SourceInput>[] { | ||
// This should be deprecated along with v0-webhook-rudder-server deprecation | ||
return sourceEvents.map((sourceEvent) => ({ | ||
output: { event: sourceEvent, source: undefined } as SourceInput, | ||
})); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/controllers/util/conversionStrategies/strategyV1ToV0.ts
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,10 @@ | ||
import { SourceInput, SourceInputConversionResult } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyV1ToV0 extends VersionConversionStrategy<SourceInput, NonNullable<unknown>> { | ||
convert(sourceEvents: SourceInput[]): SourceInputConversionResult<NonNullable<unknown>>[] { | ||
return sourceEvents.map((sourceEvent) => ({ | ||
output: sourceEvent.event as NonNullable<unknown>, | ||
})); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/controllers/util/conversionStrategies/strategyV1ToV2.ts
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,42 @@ | ||
import { | ||
SourceInput, | ||
SourceInputConversionResult, | ||
SourceInputV2, | ||
SourceRequestV2, | ||
} from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyV1ToV2 extends VersionConversionStrategy<SourceInput, SourceInputV2> { | ||
convert(sourceEvents: SourceInput[]): SourceInputConversionResult<SourceInputV2>[] { | ||
return sourceEvents.map((sourceEvent) => { | ||
try { | ||
const sourceEventParam = { ...sourceEvent }; | ||
|
||
let queryParameters: Record<string, unknown> | undefined; | ||
if (sourceEventParam.event && sourceEventParam.event.query_parameters) { | ||
queryParameters = sourceEventParam.event.query_parameters; | ||
delete sourceEventParam.event.query_parameters; | ||
} | ||
|
||
const sourceRequest: SourceRequestV2 = { | ||
body: JSON.stringify(sourceEventParam.event), | ||
}; | ||
if (queryParameters) { | ||
sourceRequest.query_parameters = queryParameters; | ||
} | ||
|
||
const sourceInputV2: SourceInputV2 = { | ||
request: sourceRequest, | ||
source: sourceEventParam.source, | ||
}; | ||
return { | ||
output: sourceInputV2, | ||
}; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof Error ? err : new Error('error converting v1 to v2 spec'); | ||
return { conversionError }; | ||
} | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/controllers/util/conversionStrategies/strategyV2ToV0.ts
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,17 @@ | ||
import { SourceInputConversionResult, SourceInputV2 } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyV2ToV0 extends VersionConversionStrategy<SourceInputV2, NonNullable<unknown>> { | ||
convert(sourceEvents: SourceInputV2[]): SourceInputConversionResult<NonNullable<unknown>>[] { | ||
return sourceEvents.map((sourceEvent) => { | ||
try { | ||
const v0Event = JSON.parse(sourceEvent.request.body); | ||
return { output: v0Event }; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof Error ? err : new Error('error converting v2 to v0 spec'); | ||
return { conversionError }; | ||
} | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/controllers/util/conversionStrategies/strategyV2ToV1.ts
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,17 @@ | ||
import { SourceInput, SourceInputConversionResult, SourceInputV2 } from '../../../types'; | ||
import { VersionConversionStrategy } from './abstractions'; | ||
|
||
export class StrategyV2ToV1 extends VersionConversionStrategy<SourceInputV2, SourceInput> { | ||
convert(sourceEvents: SourceInputV2[]): SourceInputConversionResult<SourceInput>[] { | ||
return sourceEvents.map((sourceEvent) => { | ||
try { | ||
const v1Event = { event: JSON.parse(sourceEvent.request.body), source: sourceEvent.source }; | ||
return { output: v1Event }; | ||
} catch (err) { | ||
const conversionError = | ||
err instanceof Error ? err : new Error('error converting v2 to v1 spec'); | ||
return { conversionError }; | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.