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

Added Angler AI Destination #2051

Merged
merged 53 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0321bf9
initial commit
victor-ru Apr 9, 2024
6fe2c05
fix failing tests
victor-ru Apr 10, 2024
778b0ae
updated saveUser action
victor-ru Apr 16, 2024
dec2533
updated saveOrder action
victor-ru Apr 17, 2024
89ef69b
updated saveEvent action
victor-ru Apr 19, 2024
2775260
added action descriptions
victor-ru Apr 19, 2024
cb905a8
updated presets
victor-ru Apr 19, 2024
fd2088e
flattened saveEvent mapping
victor-ru Apr 24, 2024
0475238
fixed saveEvent.perform
victor-ru Apr 24, 2024
a0a090f
fixed saveEvent mapping
victor-ru Apr 24, 2024
6f76712
updated snapshots
victor-ru Apr 24, 2024
76c0952
updated snapshots
victor-ru Apr 24, 2024
605a367
fixed saveEvent payload structure
victor-ru Apr 25, 2024
78bbe94
don't include empty objects in payload
victor-ru Apr 26, 2024
4d83d95
Merge branch 'segmentio:main' into main
jonathansudhakar1 May 10, 2024
77f03d0
Merge branch 'segmentio:main' into main
jonathansudhakar1 May 21, 2024
afbaa51
updated
joe-ayoub-segment May 28, 2024
facea78
progress
joe-ayoub-segment May 30, 2024
673c854
restructure events
victor-ru Jun 11, 2024
97632ff
remove defaults for optional fields
victor-ru Jun 11, 2024
73b91b1
restore address field
victor-ru Jun 11, 2024
e679379
update untranslated title default values
victor-ru Jun 11, 2024
f32eae1
Merge pull request #1 from angler-ai/anglerai
victor-ru Jun 11, 2024
c06344b
updated snapshots
victor-ru Jun 11, 2024
cffd970
remove unused import
victor-ru Jun 12, 2024
1fbe462
Merge branch 'segmentio:main' into main
victor-ru Jun 12, 2024
9f61cf8
fixed default paths
victor-ru Jun 13, 2024
3ca25b7
reorganized saveUser fields
victor-ru Jun 25, 2024
fe1b642
updated saveBaseEvent fields
victor-ru Jun 26, 2024
ffb4cd0
fixed default_address default in saveUser
victor-ru Jun 26, 2024
b7035cd
moved custom event name to saveBaseEvent
victor-ru Jun 26, 2024
63a8b3c
updated tests
victor-ru Jun 26, 2024
91cd339
added defaults for customer field in saveEvent
victor-ru Jun 26, 2024
366f929
test commit
joe-ayoub-segment Jun 26, 2024
9774fe6
refactor fields
joe-ayoub-segment Jun 26, 2024
e1fade1
consistent naming for fields variables
victor-ru Jun 28, 2024
bdfab26
removed cartFields from saveCartEvent
victor-ru Jun 28, 2024
4852f78
removed less important saveOrder fields
victor-ru Jun 28, 2024
60d05fc
updated event names
victor-ru Jun 28, 2024
d94af9d
moved event name field from common fields
victor-ru Jul 2, 2024
55adbd5
fixed field name
victor-ru Jul 2, 2024
f8ce414
refactor event fields
victor-ru Jul 2, 2024
4d7208b
updated generated types
victor-ru Jul 2, 2024
39040d4
updated tests
victor-ru Jul 2, 2024
a34da47
fixed checkout fields
victor-ru Jul 3, 2024
33b27f3
updated payload transformation functions
victor-ru Jul 3, 2024
a0c21bd
removed custom event preset
victor-ru Jul 3, 2024
2f049a4
fixed identifiers transformation
victor-ru Jul 3, 2024
2295076
updated tests
victor-ru Jul 3, 2024
1ea48ca
wrapped cart and checkout fields into objects
victor-ru Jul 3, 2024
be0cb2f
Merge branch 'segmentio:main' into main
victor-ru Jul 8, 2024
64b5533
updated tests
victor-ru Jul 8, 2024
8fc109d
minor changes to presets
joe-ayoub-segment Jul 8, 2024
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import nock from 'nock'
import { createTestIntegration } from '@segment/actions-core'
import Definition from '../index'
import { baseURL } from '../routes'

const testDestination = createTestIntegration(Definition)

describe('Angler Ai', () => {
describe('testAuthentication', () => {
it('should validate authentication inputs', async () => {
const authResponse = {
sub: 'test_workspace_id',
scopes: 'DATA_ADMIN'
}

nock(baseURL).get('/v1/me').reply(200, authResponse)

const authData = {
accessToken: 'test_token',
workspaceId: 'test_workspace_id'
}

await expect(testDestination.testAuthentication(authData)).resolves.not.toThrowError()
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
import { generateTestData } from '../../../lib/test-data'
import destination from '../index'
import nock from 'nock'

const testDestination = createTestIntegration(destination)
const destinationSlug = 'actions-angler-ai'

describe(`Testing snapshot for ${destinationSlug} destination:`, () => {
for (const actionSlug in destination.actions) {
it(`${actionSlug} action - required fields`, async () => {
const seedName = `${destinationSlug}#${actionSlug}`
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, true)

nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
settings: settingsData,
auth: undefined
})

const request = responses[0].request
const rawBody = await request.text()

try {
const json = JSON.parse(rawBody)
expect(json).toMatchSnapshot()
return
} catch (err) {
expect(rawBody).toMatchSnapshot()
}

expect(request.headers).toMatchSnapshot()
})

it(`${actionSlug} action - all fields`, async () => {
const seedName = `${destinationSlug}#${actionSlug}`
const action = destination.actions[actionSlug]
const [eventData, settingsData] = generateTestData(seedName, destination, action, false)

nock(/.*/).persist().get(/.*/).reply(200)
nock(/.*/).persist().post(/.*/).reply(200)
nock(/.*/).persist().put(/.*/).reply(200)

const event = createTestEvent({
properties: eventData
})

const responses = await testDestination.testAction(actionSlug, {
event: event,
mapping: event.properties,
settings: settingsData,
auth: undefined
})

const request = responses[0].request
const rawBody = await request.text()

try {
const json = JSON.parse(rawBody)
expect(json).toMatchSnapshot()
return
} catch (err) {
expect(rawBody).toMatchSnapshot()
}
})
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { PathDirective, InputField } from '@segment/actions-core'

export const addressProperties: Record<string, InputField> = {
id: {
label: 'ID',
type: 'string',
description: 'A unique identifier for the address.'
},
address1: {
label: 'Address 1',
type: 'string',
description: "The customer's mailing address."
},
address2: {
label: 'Address 2',
type: 'string',
description: "An additional field for the customer's mailing address."
},
city: {
label: 'City',
type: 'string',
description: "The customer's city, town, or village."
},
company: {
label: 'Company',
type: 'string',
description: "The customer's company."
},
country: {
label: 'Country',
type: 'string',
description: "The customer's country."
},
country_code: {
label: 'Country Code',
type: 'string',
description: "The two-letter country code corresponding to the customer's country"
},
country_name: {
label: 'Country Name',
type: 'string',
description: "The customer's normalized country name."
},
customer_id: {
label: 'Customer ID',
type: 'string',
description: 'A unique identifier for the customer.'
},
default: {
label: 'Default',
type: 'boolean',
description: 'Whether this address is the default address for the customer.'
},
first_name: {
label: 'First Name',
type: 'string',
description: "The customer's first name."
},
last_name: {
label: 'Last Name',
type: 'string',
description: "The customer's last name."
},
name: {
label: 'Name',
type: 'string',
description: "The customer's first and last names."
},
phone: {
label: 'Phone',
type: 'string',
description: "The customer's phone number at this address."
},
province: {
label: 'Province',
type: 'string',
description: "The customer's region name. Typically a province, a state, or a prefecture"
},
province_code: {
label: 'Province Code',
type: 'string',
description:
'The code for the region of the address, such as the province, state, or district. For example QC for Quebec, Canada.'
},
zip: {
label: 'Zip',
type: 'string',
description: "The customer's postal code, also known as zip, postcode, Eircode, etc"
},
hashed_first_name: {
label: 'Hashed First Name',
type: 'string',
description: 'Hashed value of first name in SHA256 (lower case).'
},
hashed_last_name: {
label: 'Hashed Last Name',
type: 'string',
description: 'Hashed value of last name in SHA256 (lower case).'
},
hashed_phone: {
label: 'Hashed Phone',
type: 'string',
description: 'Hashed value of phone in SHA256 (lower case).'
},
hashed_address1: {
label: 'Hashed Address 1',
type: 'string',
description: 'Hashed value of address1 in SHA256 (lower case).'
},
hashed_address2: {
label: 'Hashed Address 2',
type: 'string',
description: 'Hashed value of address2 in SHA256 (lower case).'
},
hashed_city: {
label: 'Hashed City',
type: 'string',
description: 'Hashed value of city in SHA256 (lower case).'
},
hashed_zip: {
label: 'Hashed Zip',
type: 'string',
description: 'Hashed value of zip in SHA256 (lower case).'
},
hashed_country_code: {
label: 'Hashed Country Code',
type: 'string',
description: 'Hashed value of country code in SHA256 (lower case).'
}
}

export function addressDefaultFields(path = ''): Record<string, PathDirective> {
if (path && !path.endsWith('.')) {
path += '.'
}

return {
id: { '@path': `${path}id` },
address1: { '@path': `${path}address1` },
address2: { '@path': `${path}address2` },
city: { '@path': `${path}city` },
company: { '@path': `${path}company` },
country: { '@path': `${path}country` },
country_code: { '@path': `${path}country_code` },
country_name: { '@path': `${path}country_name` },
customer_id: { '@path': `${path}customer_id` },
default: { '@path': `${path}default` },
first_name: { '@path': `${path}first_name` },
last_name: { '@path': `${path}last_name` },
name: { '@path': `${path}name` },
phone: { '@path': `${path}phone` },
province: { '@path': `${path}province` },
province_code: { '@path': `${path}province_code` },
zip: { '@path': `${path}zip` },
hashed_first_name: { '@path': `${path}hashed_first_name` },
hashed_last_name: { '@path': `${path}hashed_last_name` },
hashed_phone: { '@path': `${path}hashed_phone` },
hashed_address1: { '@path': `${path}hashed_address1` },
hashed_address2: { '@path': `${path}hashed_address2` },
hashed_city: { '@path': `${path}hashed_city` },
hashed_zip: { '@path': `${path}hashed_zip` },
hashed_country_code: { '@path': `${path}hashed_country_code` }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { InputField } from '@segment/actions-core/index'
import { productsFields } from './productsFields'

export const cartFields: Record<string, InputField> = {
cart: {
label: 'Cart',
type: 'object',
description: 'Cart details',
properties: {
id: {
label: 'Cart ID',
type: 'string',
description: 'A globally unique identifier for the cart.'
},
totalAmount: {
label: 'Total Amount',
type: 'number',
description: 'Decimal money amount.'
},
currencyCode: {
label: 'Currency Code',
type: 'string',
description: 'The currency code of the money.'
}
}
},
cartLines: {
...productsFields,
label: 'Cart Line Items',
description: 'Cart Line Item details',
properties: {
...productsFields.properties,
quantity: {
label: 'Quantity',
type: 'number',
description: 'Quantity of the item'
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { InputField } from '@segment/actions-core/index'
import { productFields, productDefaultProperties } from './productFields'

export const cartLineFields: Record<string, InputField> = {
cartLine: {
...productFields,
label: 'Cart Line',
description: 'Cart Line details',
properties: {
...productFields.properties,
quantity: {
label: 'Quantity',
type: 'number',
description: 'Quantity of the item'
}
},
default: {
'@arrayPath': [
'$.properties.products',
{
...productDefaultProperties,
quantity: {
'@path': '$.quantity'
}
}
]
}
}
}
Loading
Loading