Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'segmentio:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
esezerguven authored Dec 5, 2023
2 parents e12bf4a + 1daca21 commit 063fd54
Show file tree
Hide file tree
Showing 232 changed files with 6,920 additions and 2,014 deletions.
4 changes: 2 additions & 2 deletions packages/actions-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/actions-shared",
"description": "Shared destination action methods and definitions.",
"version": "1.70.0",
"version": "1.71.0",
"repository": {
"type": "git",
"url": "https://github.com/segmentio/action-destinations",
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@amplitude/ua-parser-js": "^0.7.25",
"@segment/actions-core": "^3.88.0",
"@segment/actions-core": "^3.90.0",
"cheerio": "^1.0.0-rc.10",
"dayjs": "^1.10.7",
"escape-goat": "^3",
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-destination-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@segment/browser-destination-runtime",
"version": "1.19.0",
"version": "1.20.0",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down Expand Up @@ -62,7 +62,7 @@
}
},
"dependencies": {
"@segment/actions-core": "^3.88.0"
"@segment/actions-core": "^3.90.0"
},
"devDependencies": {
"@segment/analytics-next": "*"
Expand Down
31 changes: 31 additions & 0 deletions packages/browser-destinations/destinations/1flow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# @segment/analytics-browser-actions-1flow

The 1Flow browser action destination for use with @segment/analytics-next.

## License

MIT License

Copyright (c) 2023 Segment

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

## Contributing

All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under.
23 changes: 23 additions & 0 deletions packages/browser-destinations/destinations/1flow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@segment/analytics-browser-actions-1flow",
"version": "1.2.0",
"license": "MIT",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"main": "./dist/cjs",
"module": "./dist/esm",
"scripts": {
"build": "yarn build:esm && yarn build:cjs",
"build:cjs": "tsc --module commonjs --outDir ./dist/cjs",
"build:esm": "tsc --outDir ./dist/esm"
},
"typings": "./dist/esm",
"dependencies": {
"@segment/browser-destination-runtime": "^1.20.0"
},
"peerDependencies": {
"@segment/analytics-next": ">=1.55.0"
}
}
22 changes: 22 additions & 0 deletions packages/browser-destinations/destinations/1flow/src/1flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
// @ts-nocheck

export function initScript({ projectApiKey }) {
//Set your APP_ID
const apiKey = projectApiKey

const autoURLTracking = false
;(function (w, o, s, t, k, a, r) {
;(w._1flow = function (e, d, v) {
s(function () {
w._1flow(e, d, !v ? {} : v)
}, 5)
}),
(a = o.getElementsByTagName('head')[0])
r = o.createElement('script')
r.async = 1
r.setAttribute('data-api-key', k)
r.src = t
a.appendChild(r)
})(window, document, setTimeout, 'https://cdn-development.1flow.ai/js-sdk/1flow.js', apiKey)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import _1FlowDestination from '../index'
import { _1Flow } from '../api'

describe('_1Flow', () => {
beforeAll(() => {
jest.mock('@segment/browser-destination-runtime/load-script', () => ({
loadScript: (_src: any, _attributes: any) => {}
}))
jest.mock('@segment/browser-destination-runtime/resolve-when', () => ({
resolveWhen: (_fn: any, _timeout: any) => {}
}))
})
test('it maps event parameters correctly to identify function ', async () => {})
})
11 changes: 11 additions & 0 deletions packages/browser-destinations/destinations/1flow/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type method = 'track' | 'identify'

type _1FlowApi = {
richLinkProperties: string[] | undefined
activator: string | undefined
projectApiKey: string
}

type _1FlowFunction = (method: method, ...args: unknown[]) => void

export type _1Flow = _1FlowFunction & _1FlowApi

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
@@ -0,0 +1,14 @@
import _1FlowDestination from '../../index'

describe('identify', () => {
beforeAll(() => {
jest.mock('@segment/browser-destination-runtime/load-script', () => ({
loadScript: (_src: any, _attributes: any) => {}
}))
jest.mock('@segment/browser-destination-runtime/resolve-when', () => ({
resolveWhen: (_fn: any, _timeout: any) => {}
}))
})

test('it maps event parameters correctly to identify function ', async () => {})
})

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
@@ -0,0 +1,90 @@
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
import { _1Flow } from '../api'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'

const action: BrowserActionDefinition<Settings, _1Flow, Payload> = {
title: 'Identify User',
description: 'Create or update a user in 1Flow.',
defaultSubscription: 'type = "identify"',
platform: 'web',
fields: {
userId: {
description: 'A unique identifier for the user.',
label: 'User ID',
type: 'string',
required: false,
default: {
'@path': '$.userId'
}
},
anonymousId: {
description: 'An anonymous identifier for the user.',
label: 'Anonymous ID',
type: 'string',
required: false,
default: {
'@path': '$.anonymousId'
}
},
traits: {
description: "The user's custom attributes.",
label: 'Custom Attributes',
type: 'object',
required: false,
defaultObjectUI: 'keyvalue',
default: {
'@path': '$.traits'
}
},
first_name: {
description: "The user's first name.",
label: 'First Name',
type: 'string',
required: false,
default: {
'@path': '$.traits.first_name'
}
},
last_name: {
description: "The user's last name.",
label: 'First Name',
type: 'string',
required: false,
default: {
'@path': '$.traits.last_name'
}
},
phone: {
description: "The user's phone number.",
label: 'Phone Number',
type: 'string',
required: false,
default: {
'@path': '$.traits.phone'
}
},

email: {
description: "The user's email address.",
label: 'Email Address',
type: 'string',
required: false,
default: {
'@path': '$.traits.email'
}
}
},
perform: (_1Flow, event) => {
const { userId, anonymousId, traits, first_name, last_name, phone, email } = event.payload
_1Flow('identify', userId, anonymousId, {
...traits,
first_name: first_name,
last_name: last_name,
phone: phone,
email: email
})
}
}

export default action
58 changes: 58 additions & 0 deletions packages/browser-destinations/destinations/1flow/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import type { Settings } from './generated-types'
import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types'
import { browserDestination } from '@segment/browser-destination-runtime/shim'
import trackEvent from './trackEvent'
import { initScript } from './1flow'
import { _1Flow } from './api'
import identifyUser from './identifyUser'
import { defaultValues } from '@segment/actions-core'
declare global {
interface Window {
_1Flow: _1Flow
}
}

export const destination: BrowserDestinationDefinition<Settings, _1Flow> = {
name: '1Flow Web (Actions)',
slug: 'actions-1flow',
mode: 'device',
description: 'Send analytics from Segment to 1Flow',
settings: {
projectApiKey: {
description:
'This is the unique app_id for your 1Flow application, serving as the identifier for data storage and retrieval. This field is mandatory.',
label: 'Project API Key',
type: 'string',
required: true
}
},
presets: [
{
name: 'Track Event',
subscribe: 'type = "track"',
partnerAction: 'trackEvent',
mapping: defaultValues(trackEvent.fields),
type: 'automatic'
},
{
name: 'Identify User',
subscribe: 'type = "identify"',
partnerAction: 'identifyUser',
mapping: defaultValues(identifyUser.fields),
type: 'automatic'
}
],

initialize: async ({ settings }, deps) => {
const projectApiKey = settings.projectApiKey
initScript({ projectApiKey })
await deps.resolveWhen(() => Object.prototype.hasOwnProperty.call(window, '_1Flow'), 100)
return window._1Flow
},
actions: {
trackEvent,
identifyUser
}
}

export default browserDestination(destination)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import _1flowDestination from '../../index'

describe('track', () => {
beforeAll(() => {
jest.mock('@segment/browser-destination-runtime/load-script', () => ({
loadScript: (_src: any, _attributes: any) => {}
}))
jest.mock('@segment/browser-destination-runtime/resolve-when', () => ({
resolveWhen: (_fn: any, _timeout: any) => {}
}))
})

test('it maps event parameters correctly to track function', async () => {})
})

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

Loading

0 comments on commit 063fd54

Please sign in to comment.