Skip to content

Commit

Permalink
Open source release
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel P Samson committed Jul 6, 2021
0 parents commit 492c310
Show file tree
Hide file tree
Showing 204 changed files with 30,211 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
72 changes: 72 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module.exports = {
root: true,
ignorePatterns: ['node_modules', 'dist', 'templates'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2019,
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
tsconfigRootDir: __dirname
},
env: {
node: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier/@typescript-eslint',
'prettier'
],
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': true,
'ts-check': false
}
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_', ignoreRestSiblings: true }
],
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off'
},
overrides: [
{
files: ['*.test.ts', '**/test/**/*.ts'],
env: {
jest: true
},
plugins: ['jest'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-explicit-any': 'off'
}
},
{
files: ['**/benchmarks/**/*.js'],
env: {
node: true
},
rules: {
'@typescript-eslint/no-var-requires': 'off'
}
}
]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*/generated-types.ts linguist-generated=true
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on: [push]

jobs:
test-and-build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x]

steps:
- uses: actions/checkout@v2
with:
persist-credentials: false

- 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: Install Dependencies
run: yarn install --frozen-lockfile --ignore-optional
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --fail-on=upgradable --all-projects

- name: Build
run: NODE_ENV=production yarn build

- name: Lint
run: yarn lint

- name: Test
run: yarn test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.DS_Store
*.log
*.tsbuildinfo
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
>=12.x
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["eamodio.gitlens", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
46 changes: 46 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to running server",
"restart": true,
"address": "localhost",
"port": 47082,
"skipFiles": ["<node_internals>/**"]
},
// Launches Jest tests in debug mode
// Simply drop a breakpoint and wait for the debugger to pick it up
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${relativeFile}", "--coverage=false"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
// skip annoying `async_hooks` file for promises
"<node_internals>/**"
]
},
{
"type": "node",
"name": "Jest All",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"skipFiles": [
// skip annoying `async_hooks` file for promises
"<node_internals>/**"
]
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.formatOnSave": true,
"eslint.validate": ["javascript", "typescript"],
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Action Destinations

Action Destinations are a way to build streaming destinations on Segment.

## Local Development

This project is a monorepo with multiple packages using Yarn Workspaces:

- `packages/cli` - a set of command line tools for interacting with the repo
- `packages/core` - the core runtime engine for actions, including mapping-kit transforms
- `packages/destinations-actions` - an npm package for use in `integrations`

```
$ yarn install
```

## Test Actions Locally

To test actions locally, you send a curl request. For example:

```sh
curl --request POST \
--url http://localhost:3000/actions/5f7dd8e302173ff732db5cc4 \
--header 'content-type: application/cloudevents-batch+json' \
--data '[
{
"id": "dkjfksldfjiuhfenjk",
"source": "some-source",
"destination": "slack",
"data": {
"channel": "server",
"context": {
"library": {
"name": "unknown",
"version": "unknown"
}
},
"event": "Example Event",
"integrations": {},
"messageId": "api-1iI59hvBEtckNicjbfqG7VdjRw2",
"projectId": "29qHxXL9muph5R19vwAnDP",
"properties": {
"text": "Hello, from dev :blobcatwave:!"
},
"receivedAt": "2020-10-01T19:55:15.068Z",
"timestamp": "2020-10-01T19:55:15.068Z",
"type": "track",
"userId": "sloth@segment.com",
"version": 2
},
"settings": {
"subscription": {
"mapping": {
"channel": "test-channel",
"url": "https://hooks.slack.com/services/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",
"text": {
"@template": "Event = {{event}}, properties.text = {{properties.text}}"
}
},
"partnerAction": "postToChannel",
"subscribe": "type = \"track\""
}
}
}
]'
```

## Configuring

Action destinations are configured using a single Destination setting (`subscriptions`) that should contain a JSON blob of all subscriptions for the destination. The format should look like this:

```js
[
{
"subscribe": "<fql query>",
"partnerAction": "<actionSlug>",

// See ./packages/core/src/mapping-kit/README.md for documentation. The keys in this object should match the `action.fields`
"mapping": { ... }
}
]
```

Here's a full example:

```json
[
{
"subscribe": "type = 'track'",
"partnerAction": "postToChannel",
"mapping": {
"text": {
"@template": "Tracked! event={{event}}, {{properties.text}}"
},
"url": "https://hooks.slack.com/services/0HL7TC62R/0T276CRHL/8WvI6gEiE9ZqD47kWqYbfIhZ",
"channel": "test-channel"
}
},
{
"subscribe": "type = 'identify'",
"partnerAction": "postToChannel",
"mapping": {
"text": {
"@template": "User identified! email={{email}}"
},
"url": "https://hooks.slack.com/services/0HL7TC62R/0T276CRHL/8WvI6gEiE9ZqD47kWqYbfIhZ",
"channel": "test-channel"
}
}
]
```
1 change: 1 addition & 0 deletions bin
6 changes: 6 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent"
}
71 changes: 71 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "action-destinations",
"private": true,
"license": "UNLICENSED",
"workspaces": {
"packages": [
"packages/*"
]
},
"engines": {
"node": ">=12"
},
"scripts": {
"cloud": "yarn workspace @segment/destination-actions",
"cli": "yarn workspace @segment/actions-cli",
"core": "yarn workspace @segment/actions-core",
"bootstrap": "lerna bootstrap",
"build": "npx segment generate:types && lerna run build --stream",
"types": "npx segment generate:types",
"lint": "eslint '**/*.ts' --max-warnings=10",
"test": "lerna run test --stream",
"typecheck": "lerna run typecheck --stream"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-jest": "^24.3.6",
"husky": "^4.3.8",
"jest": "^26.6.3",
"lerna": "^4.0.0",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"ts-jest": "^26.5.5",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/src/destinations/**/index.ts": [
"npx segment generate:types"
],
"!(templates)/**/*.ts": [
"eslint --fix",
"prettier --write"
],
"*.{yml,md,json}": [
"prettier --write"
]
},
"prettier": {
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 120
},
"jest": {
"preset": "ts-jest",
"globals": {
"ts-jest": {
"isolatedModules": true
}
}
}
}
Loading

0 comments on commit 492c310

Please sign in to comment.