Skip to content

Commit

Permalink
Merge branch 'segmentio:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
askkaz authored Sep 29, 2023
2 parents 63866be + 17bd01f commit dfd8614
Show file tree
Hide file tree
Showing 1,268 changed files with 49,996 additions and 7,620 deletions.
100 changes: 51 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test-and-build:
runs-on: ubuntu-20.04

timeout-minutes: 20
timeout-minutes: 30

strategy:
matrix:
Expand Down Expand Up @@ -51,6 +51,8 @@ jobs:
run: NODE_ENV=production yarn build

- name: Lint
env:
NODE_OPTIONS: '--max-old-space-size=4096'
run: yarn lint

- name: Validate
Expand All @@ -65,54 +67,54 @@ jobs:
yarn subscriptions size
fi
browser-tests-destination:
env:
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}

runs-on: ubuntu-20.04

timeout-minutes: 20

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@master

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Dependencies
run: yarn install --frozen-lockfile
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Build
run: NODE_ENV=production yarn lerna run build --scope=@segment/browser-destinations --include-dependencies --stream

- name: Run Saucelabs Tests
working-directory: packages/browser-destinations-integration-tests
shell: bash
run: |
yarn start-destination-server &
yarn test:sauce
# browser-tests-destination:
# # env: # Disable saucelabs - we blew through our quota.
# # SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}
# # SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}

# runs-on: ubuntu-20.04

# timeout-minutes: 20

# strategy:
# matrix:
# node-version: [18.x]

# steps:
# - uses: actions/checkout@master

# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v2
# with:
# node-version: ${{ matrix.node-version }}
# registry-url: 'https://registry.npmjs.org'

# - name: Get yarn cache directory path
# id: yarn-cache-dir-path
# run: echo "::set-output name=dir::$(yarn cache dir)"

# - uses: actions/cache@v2
# id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
# with:
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-yarn-

# - name: Install Dependencies
# run: yarn install --frozen-lockfile
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# - name: Build
# run: NODE_ENV=production yarn build:browser-destinations && yarn browser build-web

# - name: Run Saucelabs Tests
# working-directory: packages/browser-destinations-integration-tests
# shell: bash
# run: |
# yarn start-destination-server &
# yarn test:sauce

browser-tests-core:
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
- name: Publish
run: |
yarn lerna publish from-git --yes --allowBranch=main
yarn lerna publish from-git --yes --allowBranch=main --loglevel=verbose --dist-tag latest
96 changes: 94 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<p align="center"><a href="https://segment.com"><img src="https://library.twilio.com/m/75a81eb2857bfd02/webimage-logo-segment-icon-clearspace-rgb.png" width="100"/></a></p>
<p align="center"><a href="https://segment.com"><img src="https://github-production-user-asset-6210df.s3.amazonaws.com/316711/254403783-df7b9cdd-1e45-48a8-a255-e1cc087e2196.svg" width="100"/></a></p>

# Action Destinations

Action Destinations are the new way to build streaming destinations on Segment.

Action Destinations were [launched in December 2021](https://segment.com/blog/introducing-destination-actions/) to enable customers with a customizable framework to map Segment event sources to their favorite 3rd party tools like Google Analytics.
Expand All @@ -28,6 +27,7 @@ For more detailed instruction, see the following READMEs:
- [Example Destination](#example-destination)
- [Input Fields](#input-fields)
- [Default Values](#default-values)
- [Presets](#presets)
- [perform function](#the-perform-function)
- [Batching Requests](#batching-requests)
- [HTTP Requests](#http-requests)
Expand Down Expand Up @@ -383,6 +383,40 @@ const destination = {
}
```
## Presets
Presets are pre-built use cases to enable customers to get started quickly with an action destination. They include everything needed to generate a valid subscription.
There are two types of Presets: `automatic` and `specificEvent`.
Automatic presets generate subscriptions automatically when an action destination is connected to a _non-Engage_ source. Automatic presets are also available for the customer to choose to generate a subscription at any point in the destination's lifecycle. If you are not sure which type of preset to choose, this is probably the right type.
[Experimental] SpecificEvent presets are meant to be used with destinations connected to Segment Engage Sources. A subscription will be created from the preset when a _specific action_ is taken by the customer, as specified by the `eventSlug`. If you think your destination should include a specific event preset, please reach out to us.
```js
const destination = {
// ...other properties
presets: [
// automatic preset
{
name: 'Track Event',
subscribe: 'type = "track"',
partnerAction: 'track',
mapping: defaultValues(track.fields),
type: 'automatic'
},
// specific event preset
{
name: 'Associated Entity Added',
partnerAction: 'track',
mapping: defaultValues(track.fields),
type: 'specificEvent'
slug: 'warehouse_entity_added_track'
},
],
}
```
## The `perform` function
The `perform` function defines what the action actually does. All logic and request handling happens here. Every action MUST have a `perform` function defined.
Expand Down Expand Up @@ -477,6 +511,64 @@ Keep in mind a few important things about how batching works:
Additionally, you’ll need to coordinate with Segment’s R&D team for the time being. Please reach out to us in your dedicated Slack channel!
## Audience Support (Pilot)
In order to support audience destinations, we've introduced a type that extends regular destinations:
```js
const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
// ...other properties
audienceFields: {
audienceId: {
label: 'An audience id required by the destination',
description: 'An audience id required by the destination',
type: 'string',
required: true
}
},
audienceConfig: {
mode: {
type: 'synced', // Indicates that the audience is synced on some schedule
full_audience_sync: true // If true, we send the entire audience. If false, we just send the delta.
}
},
// These are optional and only needed if you need to create an audience before sending events/users.
// Create an audience on the destination side
async createAudience(request, { settings, audienceSettings, audienceName }) {
const response = await request(YOUR_URL, {
method: 'POST',
json: {
new_audience_name: audienceName,
some_audience_specific_id: audienceSettings.audienceId // As defined in audienceFields
}
})
const jsonOutput = await response.json()
// Segment will save this externalId for subsequent calls
return {
externalId: jsonOutput['my_audience_id']
}
},
// Right now, this serves mostly as a check to ensure the audience still exists in the destination
async getAudience(request, { settings, audienceSettings, externalId }) {
const response = await request(YOUR_URL, {
method: 'POST',
json: {
my_audience_id: externalId
}
})
const jsonOutput = await response.json()
return {
externalId: jsonOutput['my_audience_id']
}
}
}
```
**Other considerations for audience support:**
- It is highly recommended to implement a `performBatch` function in your actions implementation.
- You should implement actions specific to audiences such as adding and removing a user
## HTTP Requests
Today, there is only one way to make HTTP requests in a destination: **Manual HTTP Requests**.
Expand Down
8 changes: 8 additions & 0 deletions docs/actions_tester.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ Actions tester allows for a simulated test of the action environment. Clicking t
Currently the output panel behaves in two 'modes'. The first is `immediate` failures. If your api call could not be completed due to invalid url, credentials, etc, the pane will display whatever debugging information we have in the client.

Once you have made a successful api call, we show both the request and response objects that the actions runtime uses internally to track your event. At the time of this writing, these are PERSISTED across individual calls, so if multiple calls appear and this is not desired behavior, you may want to reload the browser instance.

#### Testing Refresh Token

For OAuth2 destination, you can test refreshAccessToken handler from the `Test Refresh Token` pane. You can fill in the fields in the section, click on `Test Refresh Token` and results will be displayed in the output panel.

#### Testing Authentication

For validating `testAuthentication` handler from actions tester, navigate to the `Settings` pane and fill in all the required settings. You should see `Test Authentication` button below the output panel on the right. On clicking the button, results will be displayed in the output panel.
2 changes: 1 addition & 1 deletion docs/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ With this minimal configuration, the destination can connect to the Segment App'

```js
import type { Settings } from './generated-types'
import type { BrowserDestinationDefinition } from '../../lib/browser-destinations'
import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types'
import { browserDestination } from '../../runtime/shim'

// Declare global to access your client
Expand Down
37 changes: 37 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,43 @@ curl --location --request POST 'http://localhost:3000/authentication' \
}'
```

### Example request to test createAudience() and getAudience()

You can test the createAudience and getAudience methods as well. Use the commands below as an example and populate the
settings according to the needs of your destination.

**createAudience**

```sh
curl --location 'http://localhost:3000/createAudience' \
--header 'Content-Type: application/json' \
--data '{
"settings": {
"createAudienceUrl": "http://localhost:4242"
},
"audienceSettings": {
"advertiser_id": "abcxyz123"
},
"audienceName": "The Super Mario Brothers Super Audience"
}'
```

**getAudience**

```sh
curl --location 'http://localhost:3000/getAudience' \
--header 'Content-Type: application/json' \
--data '{
"settings": {
"getAudienceUrl": "http://localhost:4242/getAudience"
},
"audienceSettings": {
"advertiser_id": "abcxyz123"
},
"externalId": 21
}'
```

## Unit Testing

When building a destination action, you should write unit and end-to-end tests to ensure your action is working as intended. Tests are automatically run on every commit in Github Actions. Pull requests that do not include relevant tests will not be approved.
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"packages": ["packages/*", "packages/browser-destinations/destinations/*"],
"npmClient": "yarn",
"version": "independent",
"useWorkspaces": true,
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MIT",
"workspaces": {
"packages": [
"packages/*"
"packages/*",
"packages/browser-destinations/destinations/*"
]
},
"engines": {
Expand All @@ -17,10 +18,11 @@
"cli-internal": "yarn workspace @segment/actions-cli-internal",
"core": "yarn workspace @segment/actions-core",
"bootstrap": "lerna bootstrap",
"build": "./bin/run generate:types && lerna run build --stream --ignore @segment/actions-cli-internal",
"build": "./bin/run generate:types && lerna run build --concurrency 1 --stream --ignore @segment/actions-cli-internal && yarn browser build-web",
"build:browser-destinations": "yarn lerna run build --concurrency 1 --scope=@segment/destinations-manifest --include-dependencies --stream && yarn browser build-web",
"types": "./bin/run generate:types",
"validate": "./bin/run validate",
"lint": "eslint '**/*.ts' --cache",
"lint": "ls -d ./packages/* | xargs -I {} eslint '{}/**/*.ts' --cache",
"subscriptions": "yarn workspace @segment/destination-subscriptions",
"test": "lerna run test --stream",
"test-partners": "lerna run test --stream --ignore @segment/actions-core --ignore @segment/actions-cli --ignore @segment/ajv-human-errors",
Expand Down Expand Up @@ -56,7 +58,7 @@
"karma-jasmine": "^5.1.0",
"karma-webkit-launcher": "^2.0.0",
"karma-webpack": "^5.0.0",
"lerna": "^6.0.3",
"lerna": "^6.5.0",
"lint-staged": "^10.5.3",
"open": "^8.4.0",
"os-browserify": "^0.3.0",
Expand All @@ -68,7 +70,7 @@
"timers-browserify": "^2.0.12",
"ts-jest": "^27.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"typescript": "4.3.5",
"ws": "^8.5.0"
},
"resolutions": {
Expand Down
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.50.0",
"version": "1.65.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.68.0",
"@segment/actions-core": "^3.83.0",
"cheerio": "^1.0.0-rc.10",
"dayjs": "^1.10.7",
"escape-goat": "^3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ajv-human-errors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@segment/ajv-human-errors",
"version": "2.7.0",
"version": "2.11.3",
"description": "Human-readable error messages for Ajv (Another JSON Schema Validator).",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit dfd8614

Please sign in to comment.