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

[Hyperengage] Resolved issue with Timezone Offset and Added Missing user_id field in group call #1733

Merged
merged 18 commits into from
Nov 29, 2023
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 @@ -41,6 +41,7 @@ const fakeGroupData = {
required: 'false'
},
timestamp: '2023-09-11T08:06:11.192Z',
timezone: 'Europe/Amsterdam',
user_id: 'test',
account_id: 'testAccount'
}
Expand Down Expand Up @@ -75,10 +76,12 @@ describe('validateInput', () => {
it('should return converted payload', async () => {
const payload = validateInput(settings, fakeGroupData, 'account_identify')
expect(payload.account_id).toEqual(fakeGroupData.account_id)
expect(payload.user_id).toEqual(fakeGroupData.user_id)
expect(payload.traits.plan_name).toEqual(fakeGroupData.plan)
expect(payload.traits.industry).toEqual(fakeGroupData.industry)
expect(payload.traits.website).toEqual(fakeGroupData.website)
expect(payload.traits).toHaveProperty('required')
expect(payload.local_tz_offset).toEqual(60)
})
})

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const action: ActionDefinition<Settings, Payload> = {
}
}
},
user_id: {
type: 'string',
description: 'The ID associated with the user',
label: 'User ID',
default: { '@path': '$.userId' }
},
name: {
type: 'string',
required: true,
Expand All @@ -41,7 +47,13 @@ const action: ActionDefinition<Settings, Payload> = {
description:
'The timestamp when the account was created, represented in the ISO-8601 date format. For instance, "2023-09-26T15:30:00Z".',
label: 'Account created at',
default: { '@path': '$.traits.created_at' }
default: {
'@if': {
exists: { '@path': '$.traits.created_at' },
then: { '@path': '$.traits.created_at' },
else: { '@path': '$.traits.createdAt' }
}
}
},
traits: {
type: 'object',
Expand All @@ -55,7 +67,13 @@ const action: ActionDefinition<Settings, Payload> = {
required: false,
description: 'Subscription plan the account is associated with',
label: 'Account subscription plan',
default: { '@path': '$.traits.plan' }
default: {
'@if': {
exists: { '@path': '$.traits.plan' },
then: { '@path': '$.traits.plan' },
else: { '@path': '$.traits.plan_name' }
}
}
},
industry: {
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ const action: ActionDefinition<Settings, Payload> = {
description:
'The timestamp when the user was created, represented in the ISO-8601 date format. For instance, "2023-09-26T15:30:00Z".',
label: 'Created at',
default: { '@path': '$.traits.created_at' }
default: {
'@if': {
exists: { '@path': '$.traits.created_at' },
then: { '@path': '$.traits.created_at' },
else: { '@path': '$.traits.createdAt' }
}
}
},
traits: {
type: 'object',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ const action: ActionDefinition<Settings, Payload> = {
label: 'User id',
default: { '@path': '$.userId' }
},
properties: {
type: 'object',
required: false,
description: 'The properties of the track call',
label: 'Event properties',
default: { '@path': '$.properties' }
},
account_id: {
type: 'string',
required: false,
description: 'The account id, to uniquely identify the account associated with the user',
label: 'Account id',
default: {
'@if': {
exists: { '@path': '$.context.group_id' },
then: { '@path': '$.context.group_id' },
exists: { '@path': '$.context.groupId' },
then: { '@path': '$.context.groupId' },
else: { '@path': '$.groupId' }
}
}
},
properties: {
type: 'object',
required: false,
description: 'The properties of the track call',
label: 'Event properties',
default: { '@path': '$.properties' }
},
...commonFields
},
perform: (request, data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export const validateInput = (

// Resolve local_tz_offset property, we can get local_tz_offset from the input context.timezone
if (input?.timezone) {
const offset = new Date().toLocaleString('en-US', { timeZone: input.timezone, timeZoneName: 'short' }).split(' ')[2]
properties.local_tz_offset = offset
const offset = new Date()
.toLocaleString('en-US', { timeZone: input.timezone, timeZoneName: 'short' })
.split(' ')[3]
.slice(3)
properties.local_tz_offset = parseInt(offset) * 60
delete properties.timezone
}

Expand Down