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

feat: added path param tab hhtp #3894

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/cdk/v2/destinations/http/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ steps:

- name: deduceEndPoint
template: |
$.context.endpoint = $.addPathParams(.message, .destination.Config.apiUrl);
$.context.endpoint = $.addPathParams(.message, .destination.Config);

- name: prepareBody
template: |
Expand Down
20 changes: 18 additions & 2 deletions src/cdk/v2/destinations/http/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,25 @@ const getCustomMappings = (message, mapping) => {
}
};

const addPathParams = (message, apiUrl) => {
const addPathParams = (message, config) => {
try {
return applyJSONStringTemplate(message, `\`${apiUrl}\``);
if (!config || !config.pathParams) {
return applyJSONStringTemplate(message, `\`${config.apiUrl}\``);
}
const baseUrl = config.apiUrl.replace(/\/+$/, '') || '';
const pathSegments = config.pathParams
.map((p) => {
const path = p?.path || '';
// Clean multiple slashes and trim
const cleanPath = path.replace(/\/+/g, '/').replace(/^\/|\/$/g, '');
return cleanPath.startsWith('$.') ? `{{${cleanPath}}}` : cleanPath;
})
.filter(Boolean)
.join('/');
const url = pathSegments ? `${baseUrl}/${pathSegments}` : baseUrl;

const a = applyJSONStringTemplate(message, `\`${url}\``);
return a;
} catch (e) {
throw new ConfigurationError(`Error in api url template: ${e.message}`);
}
Expand Down
6 changes: 6 additions & 0 deletions test/integrations/destinations/http/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ const destinations: Destination[] = [
from: '$.traits.email',
},
],
pathParams: [
{ path: 'users' },
{ path: '$.userId' },
{ path: 'update//' },
{ path: '$.type' },
],
},
DestinationDefinition: {
DisplayName: displayName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProcessorTestData } from '../../../testTypes';
import { generateMetadata, transformResultBuilder } from '../../../testUtils';
import { destType, destinations, properties, traits } from '../common';
import { destinations, destType, properties, traits } from '../common';

export const configuration: ProcessorTestData[] = [
{
Expand Down Expand Up @@ -132,7 +132,7 @@ export const configuration: ProcessorTestData[] = [
output: transformResultBuilder({
method: 'GET',
userId: '',
endpoint: destinations[1].Config.apiUrl,
endpoint: 'http://abc.com/contacts/users/userId123/update/track',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
h1: 'val1',
Expand Down
8 changes: 4 additions & 4 deletions test/integrations/destinations/http/router/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateMetadata } from '../../../testUtils';
import { destType, destinations, traits, properties } from '../common';
import { destinations, destType, properties, traits } from '../common';

const routerRequest1 = {
input: [
Expand Down Expand Up @@ -231,7 +231,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contacts',
endpoint: 'http://abc.com/contacts/users/userId1/update/identify',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
'content-type': 'application/json',
Expand Down Expand Up @@ -263,7 +263,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contacts',
endpoint: 'http://abc.com/contacts/users/userId1/update/identify',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
'content-type': 'application/json',
Expand Down Expand Up @@ -295,7 +295,7 @@ export const data = [
version: '1',
type: 'REST',
method: 'GET',
endpoint: 'http://abc.com/contacts',
endpoint: 'http://abc.com/contacts/users/userId2/update/identify',
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
'content-type': 'application/json',
Expand Down
Loading