This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'segmentio:main' into main
- Loading branch information
Showing
232 changed files
with
6,920 additions
and
2,014 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/browser-destinations/destinations/1flow/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
packages/browser-destinations/destinations/1flow/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
packages/browser-destinations/destinations/1flow/src/1flow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/browser-destinations/destinations/1flow/src/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
packages/browser-destinations/destinations/1flow/src/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
packages/browser-destinations/destinations/1flow/src/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
packages/browser-destinations/destinations/1flow/src/identifyUser/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => {}) | ||
}) |
34 changes: 34 additions & 0 deletions
34
packages/browser-destinations/destinations/1flow/src/identifyUser/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
packages/browser-destinations/destinations/1flow/src/identifyUser/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
packages/browser-destinations/destinations/1flow/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
14 changes: 14 additions & 0 deletions
14
packages/browser-destinations/destinations/1flow/src/trackEvent/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => {}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
packages/browser-destinations/destinations/1flow/src/trackEvent/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.