-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rupt integration (prev. Sabil) (#1527)
* Add Rupt integration (prev. Sabil) * Update browser destination runtime package as requested. Co-authored-by: Joe Ayoub <[email protected]> * PR Review changes & improvements --------- Co-authored-by: Joe Ayoub <[email protected]>
- Loading branch information
1 parent
35b0b5e
commit 991c501
Showing
11 changed files
with
477 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# @segment/analytics-browser-actions-rupt | ||
|
||
The Rupt 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. |
24 changes: 24 additions & 0 deletions
24
packages/browser-destinations/destinations/rupt/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,24 @@ | ||
{ | ||
"name": "@segment/analytics-browser-actions-rupt", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/segmentio/action-destinations", | ||
"directory": "packages/browser-destinations/destinations/rupt" | ||
}, | ||
"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.12.2" | ||
}, | ||
"peerDependencies": { | ||
"@segment/analytics-next": "*" | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/browser-destinations/destinations/rupt/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,28 @@ | ||
import { Analytics, Context } from '@segment/analytics-next' | ||
import plugins, { destination } from '../index' | ||
|
||
describe('Rupt', () => { | ||
it('should load Rupt script', async () => { | ||
const [event] = await plugins({ | ||
client_id: '123', | ||
|
||
subscriptions: [ | ||
{ | ||
enabled: true, | ||
name: 'Attach Device', | ||
subscribe: 'type = "page"', | ||
partnerAction: 'attach', | ||
mapping: { | ||
metadata: { unitTest: 'true' } | ||
} | ||
} | ||
] | ||
}) | ||
|
||
jest.spyOn(destination, 'initialize') | ||
|
||
await event.load(Context.system(), {} as Analytics) | ||
expect(destination.initialize).toHaveBeenCalled() | ||
expect(window).toHaveProperty('Rupt') | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
packages/browser-destinations/destinations/rupt/src/attach.types.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,26 @@ | ||
// Generated file. DO NOT MODIFY IT BY HAND. | ||
|
||
export interface Payload { | ||
/** | ||
* The account to attach the device to. | ||
*/ | ||
account: string | ||
/** | ||
* The email of the user to attach the device to. | ||
*/ | ||
email?: string | ||
/** | ||
* The phone number of the user to attach the device to. | ||
*/ | ||
phone?: string | ||
/** | ||
* Metadata to attach to the device. | ||
*/ | ||
metadata?: { | ||
[k: string]: unknown | ||
} | ||
/** | ||
* Whether to include the page in the metadata. | ||
*/ | ||
include_page?: boolean | ||
} |
77 changes: 77 additions & 0 deletions
77
packages/browser-destinations/destinations/rupt/src/attach/__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,77 @@ | ||
import { Analytics, Context } from '@segment/analytics-next' | ||
import rupt from '../../index' | ||
|
||
describe('Rupt', () => { | ||
it('should attach a device', async () => { | ||
const TEST_USER_ID = 'segment-unit-test-user-id' | ||
const TEST_USER_EMAIL = '[email protected]' | ||
const TEST_USER_PHONE = '555-555-5555' | ||
const TEST_METADATA = { url: 'https://segment.com', source: 'segment' } | ||
|
||
const [event] = await rupt({ | ||
client_id: 'bf9ce83b-d44b-4da2-97df-1094decbdd56', | ||
|
||
subscriptions: [ | ||
{ | ||
enabled: true, | ||
name: 'Attach Device', | ||
subscribe: 'type = "page"', | ||
partnerAction: 'attach', | ||
mapping: { | ||
account: { | ||
'@path': '$.userId' | ||
}, | ||
email: { | ||
'@if': { | ||
exists: { '@path': '$.traits.email' }, | ||
then: { '@path': '$.traits.email' }, | ||
else: { '@path': '$.email' } | ||
} | ||
}, | ||
phone: { | ||
'@if': { | ||
exists: { '@path': '$.traits.phone' }, | ||
then: { '@path': '$.traits.phone' }, | ||
else: { '@path': '$.properties.phone' } | ||
} | ||
}, | ||
metadata: { | ||
'@path': '$.properties.metadata' | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
|
||
await event.load(Context.system(), {} as Analytics) | ||
const attach = jest.spyOn(window.Rupt, 'attach') | ||
await event.page?.( | ||
new Context({ | ||
type: 'page', | ||
event: 'Page Viewed - test', | ||
userId: TEST_USER_ID, | ||
traits: { | ||
email: TEST_USER_EMAIL | ||
}, | ||
properties: { | ||
phone: TEST_USER_PHONE, | ||
metadata: TEST_METADATA | ||
} | ||
}) | ||
) | ||
expect(attach).toHaveBeenCalledWith({ | ||
client_id: 'bf9ce83b-d44b-4da2-97df-1094decbdd56', | ||
account: TEST_USER_ID, | ||
email: TEST_USER_EMAIL, | ||
phone: TEST_USER_PHONE, | ||
metadata: TEST_METADATA, | ||
include_page: undefined, | ||
redirect_urls: { | ||
logout_url: undefined, | ||
new_account_url: undefined, | ||
success_url: undefined, | ||
suspended_url: undefined | ||
} | ||
}) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
packages/browser-destinations/destinations/rupt/src/attach/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
packages/browser-destinations/destinations/rupt/src/attach/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,79 @@ | ||
import { BrowserActionDefinition } from '@segment/browser-destination-runtime/types' | ||
import { Payload } from 'src/attach.types' | ||
import { Settings } from 'src/generated-types' | ||
import Rupt from 'src/types' | ||
|
||
const attach: BrowserActionDefinition<Settings, Rupt, Payload> = { | ||
title: 'Attach Device', | ||
description: 'Attach a device to an account.', | ||
defaultSubscription: 'type = "page"', | ||
platform: 'web', | ||
fields: { | ||
account: { | ||
description: 'The account to attach the device to.', | ||
label: 'Account', | ||
type: 'string', | ||
required: true, | ||
default: { | ||
'@path': '$.userId' | ||
} | ||
}, | ||
email: { | ||
description: 'The email of the user to attach the device to.', | ||
label: 'Email', | ||
type: 'string', | ||
required: false, | ||
default: { | ||
'@if': { | ||
exists: { '@path': '$.context.traits.email' }, | ||
then: { '@path': '$.context.traits.email' }, | ||
else: { '@path': '$.properties.email' } | ||
} | ||
} | ||
}, | ||
phone: { | ||
description: 'The phone number of the user to attach the device to.', | ||
label: 'Phone', | ||
type: 'string', | ||
required: false, | ||
default: { | ||
'@if': { | ||
exists: { '@path': '$.context.traits.phone' }, | ||
then: { '@path': '$.context.traits.phone' }, | ||
else: { '@path': '$.properties.phone' } | ||
} | ||
} | ||
}, | ||
metadata: { | ||
description: 'Metadata to attach to the device.', | ||
label: 'Metadata', | ||
type: 'object', | ||
required: false, | ||
defaultObjectUI: 'keyvalue' | ||
}, | ||
include_page: { | ||
description: 'Whether to include the page (url) in the attach request', | ||
label: 'Include Page', | ||
type: 'boolean', | ||
required: false | ||
} | ||
}, | ||
perform(rupt, data) { | ||
rupt.attach({ | ||
client_id: data.settings.client_id, | ||
account: data.payload.account, | ||
email: data.payload.email, | ||
phone: data.payload.phone, | ||
metadata: data.payload.metadata, | ||
include_page: data.payload.include_page, | ||
redirect_urls: { | ||
new_account_url: data.settings.new_account_url, | ||
success_url: data.settings.success_url, | ||
suspended_url: data.settings.suspended_url, | ||
logout_url: data.settings.logout_url | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export default attach |
24 changes: 24 additions & 0 deletions
24
packages/browser-destinations/destinations/rupt/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.
Oops, something went wrong.