Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Object {
upsertProfileMapping(
input: {
advertiserId: 84GW[vK%wv2xv@UF5iy,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",type:STRING,isPii:false,label:\\"External Profile ID\\"}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand All @@ -29,7 +29,7 @@ Object {
upsertExternalAudienceMapping(
input: {
advertiserId: 84GW[vK%wv2xv@UF5iy,
mappingSchema: [{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\",\\\\\\"isPii\\\\\\":false}],
mappingSchema: [{incomingKey:\\"audienceId\\",destinationKey:\\"external_id\\",type:STRING,label:\\"External Audience ID\\",isPii:false},{incomingKey:\\"audienceName\\",destinationKey:\\"name\\",type:STRING,label:\\"External Audience Name\\",isPii:false}],
mappableType: \\"segment_io\\"
}
) {
Expand Down Expand Up @@ -59,8 +59,8 @@ Object {
upsertProfileMapping(
input: {
advertiserId: 84GW[vK%wv2xv@UF5iy,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",type:STRING,isPii:false,label:\\"External Profile ID\\"}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand All @@ -70,7 +70,7 @@ Object {
upsertExternalAudienceMapping(
input: {
advertiserId: 84GW[vK%wv2xv@UF5iy,
mappingSchema: [{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\",\\\\\\"isPii\\\\\\":false}],
mappingSchema: [{incomingKey:\\"audienceId\\",destinationKey:\\"external_id\\",type:STRING,label:\\"External Audience ID\\",isPii:false},{incomingKey:\\"audienceName\\",destinationKey:\\"name\\",type:STRING,label:\\"External Audience Name\\",isPii:false}],
mappableType: \\"segment_io\\"
}
) {
Expand Down Expand Up @@ -100,8 +100,8 @@ Object {
upsertProfileMapping(
input: {
advertiserId: PsAwlRv%,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",label:\\"User Id\\",type:STRING,isPii:false}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand Down Expand Up @@ -130,8 +130,8 @@ Object {
upsertProfileMapping(
input: {
advertiserId: PsAwlRv%,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",label:\\"User Id\\",type:STRING,isPii:false}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringifyJsonWithEscapedQuotes } from '../functions'
import { stringifyJsonWithEscapedQuotes, stringifyMappingSchemaForGraphQL } from '../functions'

describe('stringifyJsonWithEscapedQuotes', () => {
it('should escape quotes in a simple object', () => {
Expand Down Expand Up @@ -38,35 +38,96 @@ describe('stringifyJsonWithEscapedQuotes', () => {
expect(stringifyJsonWithEscapedQuotes(null)).toBe('null')
})

describe('type field transformation', () => {
it('should transform type field to uppercase without quotes', () => {
const input = { type: 'string' }
const expected = '{\\"type\\":STRING}'
expect(stringifyJsonWithEscapedQuotes(input)).toBe(expected)
})
})

it('should transform type field when it\'s already uppercase', () => {
const input = { type: 'STRING' }
const expected = '{\\"type\\":STRING}'
expect(stringifyJsonWithEscapedQuotes(input)).toBe(expected)
})
describe('stringifyMappingSchemaForGraphQL', () => {
it('should transform simple mapping object for GraphQL', () => {
const input = {
incomingKey: 'userId',
destinationKey: 'external_id',
label: 'User Id',
type: 'STRING',
isPii: false
}
const expected = '{incomingKey:"userId",destinationKey:"external_id",label:"User Id",type:STRING,isPii:false}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should transform type field to uppercase and unquoted', () => {
const input = { type: 'string' }
const expected = '{type:STRING}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should transform type field in nested objects', () => {
const input = { data: { type: 'string' } }
const expected = '{\\"data\\":{\\"type\\":STRING}}'
expect(stringifyJsonWithEscapedQuotes(input)).toBe(expected)
})
it('should transform type field when it\'s already uppercase', () => {
const input = { type: 'STRING' }
const expected = '{type:STRING}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should transform type fields in an array of objects', () => {
const input = {
mappings: [
{ type: 'string', field: 'name' },
{ type: 'number', field: 'age' },
{ type: 'boolean', field: 'active' }
]
it('should handle array of mapping objects', () => {
const input = [
{
incomingKey: 'userId',
destinationKey: 'external_id',
type: 'STRING',
isPii: false,
label: 'External Profile ID'
},
{
incomingKey: 'email',
destinationKey: 'email',
type: 'string',
isPii: true,
label: 'Email Address'
}
const expected = '{\\"mappings\\":[{\\"type\\":STRING,\\"field\\":\\"name\\"},{\\"type\\":NUMBER,\\"field\\":\\"age\\"},{\\"type\\":BOOLEAN,\\"field\\":\\"active\\"}]}'
expect(stringifyJsonWithEscapedQuotes(input)).toBe(expected)
})
]
const expected = '[{incomingKey:"userId",destinationKey:"external_id",type:STRING,isPii:false,label:"External Profile ID"},{incomingKey:"email",destinationKey:"email",type:STRING,isPii:true,label:"Email Address"}]'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should handle different type values', () => {
const input = {
mappings: [
{ type: 'string', field: 'name' },
{ type: 'number', field: 'age' },
{ type: 'boolean', field: 'active' }
]
}
const expected = '{mappings:[{type:STRING,field:"name"},{type:NUMBER,field:"age"},{type:BOOLEAN,field:"active"}]}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should unquote all object keys for GraphQL syntax', () => {
const input = {
incomingKey: 'test',
destinationKey: 'test_field',
customProperty: 'value',
type: 'string'
}
const expected = '{incomingKey:"test",destinationKey:"test_field",customProperty:"value",type:STRING}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should preserve string values with quotes', () => {
const input = {
label: 'User Name with "quotes"',
description: 'Field description',
type: 'string'
}
const expected = '{label:"User Name with \\"quotes\\"",description:"Field description",type:STRING}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})

it('should handle nested objects', () => {
const input = {
field: {
incomingKey: 'nested',
type: 'string'
},
type: 'object'
}
const expected = '{field:{incomingKey:"nested",type:STRING},type:OBJECT}'
expect(stringifyMappingSchemaForGraphQL(input)).toBe(expected)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ describe('forwardAudienceEvent', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",type:STRING,isPii:false,label:\\"External Profile ID\\"}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand All @@ -106,7 +106,7 @@ describe('forwardAudienceEvent', () => {
upsertExternalAudienceMapping(
input: {
advertiserId: 23,
mappingSchema: [{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\",\\\\\\"isPii\\\\\\":false}],
mappingSchema: [{incomingKey:\\"audienceId\\",destinationKey:\\"external_id\\",type:STRING,label:\\"External Audience ID\\",isPii:false},{incomingKey:\\"audienceName\\",destinationKey:\\"name\\",type:STRING,label:\\"External Audience Name\\",isPii:false}],
mappableType: \\"segment_io\\"
}
) {
Expand Down Expand Up @@ -169,8 +169,8 @@ describe('forwardAudienceEvent', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",type:STRING,isPii:false,label:\\"External Profile ID\\"}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand All @@ -180,7 +180,7 @@ describe('forwardAudienceEvent', () => {
upsertExternalAudienceMapping(
input: {
advertiserId: 23,
mappingSchema: [{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\",\\\\\\"isPii\\\\\\":false}],
mappingSchema: [{incomingKey:\\"audienceId\\",destinationKey:\\"external_id\\",type:STRING,label:\\"External Audience ID\\",isPii:false},{incomingKey:\\"audienceName\\",destinationKey:\\"name\\",type:STRING,label:\\"External Audience Name\\",isPii:false}],
mappableType: \\"segment_io\\"
}
) {
Expand Down Expand Up @@ -228,8 +228,8 @@ describe('forwardAudienceEvent', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false,\\\\\\"label\\\\\\":\\\\\\"External Profile ID\\\\\\"}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",type:STRING,isPii:false,label:\\"External Profile ID\\"}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand All @@ -239,7 +239,7 @@ describe('forwardAudienceEvent', () => {
upsertExternalAudienceMapping(
input: {
advertiserId: 23,
mappingSchema: [{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience ID\\\\\\",\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"audienceName\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"name\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"label\\\\\\":\\\\\\"External Audience Name\\\\\\",\\\\\\"isPii\\\\\\":false}],
mappingSchema: [{incomingKey:\\"audienceId\\",destinationKey:\\"external_id\\",type:STRING,label:\\"External Audience ID\\",isPii:false},{incomingKey:\\"audienceName\\",destinationKey:\\"name\\",type:STRING,label:\\"External Audience Name\\",isPii:false}],
mappableType: \\"segment_io\\"
}
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RequestClient } from '@segment/actions-core'
import { Payload } from './generated-types'
import { GQL_ENDPOINT, EXTERNAL_PROVIDER, sha256hash, stringifyJsonWithEscapedQuotes } from '../functions'
import { GQL_ENDPOINT, EXTERNAL_PROVIDER, sha256hash, stringifyJsonWithEscapedQuotes, stringifyMappingSchemaForGraphQL } from '../functions'

const audienceMapping = stringifyJsonWithEscapedQuotes([
const audienceMapping = stringifyMappingSchemaForGraphQL([
{
incomingKey: 'audienceId',
destinationKey: 'external_id',
Expand All @@ -20,7 +20,7 @@ const audienceMapping = stringifyJsonWithEscapedQuotes([
}
])

const profileMapping = stringifyJsonWithEscapedQuotes([
const profileMapping = stringifyMappingSchemaForGraphQL([
{
incomingKey: 'userId',
destinationKey: 'external_id',
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function performForwardAudienceEvents(request: RequestClient, event
input: {
advertiserId: ${advertiserId},
mappingSchemaV2: ${profileMapping},
mappableType: "${EXTERNAL_PROVIDER}",
mappableType: "${EXTERNAL_PROVIDER}"
}
) {
userErrors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ describe('forwardProfile', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",label:\\"User Id\\",type:STRING,isPii:false}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand Down Expand Up @@ -194,8 +194,8 @@ describe('forwardProfile', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",label:\\"User Id\\",type:STRING,isPii:false}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand Down Expand Up @@ -242,8 +242,8 @@ describe('forwardProfile', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"customField\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"customField\\\\\\",\\\\\\"label\\\\\\":\\\\\\"Custom Field\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false},{\\\\\\"incomingKey\\\\\\":\\\\\\"numberCustomField\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"numberCustomField\\\\\\",\\\\\\"label\\\\\\":\\\\\\"Number Custom Field\\\\\\",\\\\\\"type\\\\\\":NUMBER,\\\\\\"isPii\\\\\\":false}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",label:\\"User Id\\",type:STRING,isPii:false},{incomingKey:\\"customField\\",destinationKey:\\"customField\\",label:\\"Custom Field\\",type:STRING,isPii:false},{incomingKey:\\"numberCustomField\\",destinationKey:\\"numberCustomField\\",label:\\"Number Custom Field\\",type:NUMBER,isPii:false}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand Down Expand Up @@ -290,8 +290,8 @@ describe('forwardProfile', () => {
upsertProfileMapping(
input: {
advertiserId: 23,
mappingSchemaV2: [{\\\\\\"incomingKey\\\\\\":\\\\\\"userId\\\\\\",\\\\\\"destinationKey\\\\\\":\\\\\\"external_id\\\\\\",\\\\\\"label\\\\\\":\\\\\\"User Id\\\\\\",\\\\\\"type\\\\\\":STRING,\\\\\\"isPii\\\\\\":false}],
mappableType: \\"segment_io\\",
mappingSchemaV2: [{incomingKey:\\"userId\\",destinationKey:\\"external_id\\",label:\\"User Id\\",type:STRING,isPii:false}],
mappableType: \\"segment_io\\"
}
) {
userErrors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RequestClient } from '@segment/actions-core'
import camelCase from 'lodash/camelCase'
import isEmpty from 'lodash/isEmpty'
import { Payload } from './generated-types'
import { GQL_ENDPOINT, EXTERNAL_PROVIDER, sha256hash, stringifyJsonWithEscapedQuotes } from '../functions'
import { GQL_ENDPOINT, EXTERNAL_PROVIDER, sha256hash, stringifyJsonWithEscapedQuotes, stringifyMappingSchemaForGraphQL } from '../functions'

const standardFields = new Set([
'email',
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function performForwardProfiles(request: RequestClient, events: Pay
input: {
advertiserId: ${advertiserId},
mappingSchemaV2: ${getProfileMappings(Array.from(fieldsToMap), fieldTypes)},
mappableType: "${EXTERNAL_PROVIDER}",
mappableType: "${EXTERNAL_PROVIDER}"
}
) {
userErrors {
Expand Down Expand Up @@ -119,7 +119,7 @@ function getProfileMappings(customFields: string[], fieldTypes: Record<string, s
isPii: false
})
}
return stringifyJsonWithEscapedQuotes(mappingSchema)
return stringifyMappingSchemaForGraphQL(mappingSchema)
}

function generateLabel(field: string) {
Expand Down
Loading
Loading