Skip to content

Commit 0107fb2

Browse files
committed
chore: add 3P workflow operations
1 parent 8c2d44b commit 0107fb2

29 files changed

+11690
-0
lines changed

14-operations/README.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
## DevRev Snaps TypeScript Template
2+
3+
This repository contains a template for the functions that can be deployed as
4+
part of Snap-Ins.
5+
6+
For reference on snap-ins, refer to the [documentation](https://github.com/devrev/snap-in-docs).
7+
8+
### Getting started with the template
9+
10+
1. Create a new repository using this template.
11+
2. In the new repository, you can add functions at the path `src/functions` where the folder name corresponds to the function name in your manifest file.
12+
3. Ensure to include each new function in the file named "src/function-factory.ts".
13+
14+
### Testing locally
15+
16+
To test your code locally, add test events under 'src/fixtures' following the example event provided. Additionally, you can include keyring values in the event payload to test API calls.```
17+
18+
After adding the event, execute the following commands to test your code:
19+
20+
```
21+
npm install
22+
npm run start -- --functionName=on_work_creation --fixturePath=on_work_created_event.json
23+
```
24+
25+
### Adding external dependencies
26+
27+
You can also add dependencies on external packages to package.json under the “dependencies” key. These dependencies will be made available to your function at runtime and during testing.
28+
29+
### Linting
30+
31+
To check for lint errors, run the following command:
32+
33+
```bash
34+
npm run lint
35+
```
36+
37+
To automatically fix fixable lint errors, run:
38+
39+
```bash
40+
npm run lint:fix
41+
```
42+
43+
### Deploying Snap-ins
44+
45+
Once you are done with the testing, run the following commands to deploy your snap-in:
46+
47+
1. Authenticate to devrev CLI, run the following command:
48+
49+
```
50+
devrev profiles authenticate --org <devorg name> --usr <user email>
51+
```
52+
53+
2. To create a snap_in_version, run the following command:
54+
55+
```
56+
devrev snap_in_version create-one --path <template path> --create-package
57+
```
58+
59+
3. Draft the snap_in, run the following command:
60+
61+
```
62+
devrev snap_in draft
63+
```
64+
65+
4. To update the snap-in, run the following command:
66+
67+
```
68+
devrev snap_in update
69+
```
70+
71+
5. Activate the snap_in
72+
73+
```
74+
devrev snap_in activate
75+
```
76+
77+
### Testing Snap-in changes locally
78+
79+
### Setting up the server
80+
81+
To test out changes in snap-in locally, developers can create a snap-in version in test mode.
82+
A snap-in version created in test mode enables developers to specify a public HTTP URL to receive events from DevRev. This makes for
83+
quick code changes on the local machine without needing to repeatedly deploy the snap-in again for testing the changes.
84+
85+
To test out a snap-in version locally, follow the below steps:
86+
87+
1. Run a server locally to ingest events from DevRev. The `port` parameter is optional. If not set, the server starts default on `8000`.
88+
89+
```
90+
npm run test:server -- --port=<PORT>
91+
```
92+
93+
2. Expose the local port as a publicly available URL. We recommend using [`ngrok`](https://ngrok.com/download) since it is free and easy to set up. The command for running ngrok tunnelling on port `8000`:
94+
95+
```
96+
ngrok http 8000
97+
```
98+
99+
This returns a public HTTP URL.
100+
101+
3. Create a snap-in version with the `testing_url` flag set
102+
103+
```
104+
devrev snap_in_version create-one --path <template path> --create-package --testing_url <HTTP_URL>
105+
```
106+
107+
Here, `HTTP_URL` is the publicly available URL from Step 2. The URL should start with `http` or `https`
108+
109+
4. Once the snap-in version is ready, create a snap-in, update and activate it.
110+
111+
```
112+
devrev snap_in draft
113+
```
114+
115+
Update the snap-in through UI or using the CLI:
116+
117+
```
118+
devrev snap_in update
119+
```
120+
121+
Activate the snap-in through UI or through the CLI command:
122+
123+
```
124+
devrev snap_in activate
125+
```
126+
127+
### Receiving events locally
128+
129+
After the snap-in has been activated, it can receive events locally from DevRev as a
130+
snap-in would. If the snap-in was listening to `work_created` event type, then creating a
131+
new work-item would send the event to the local server.
132+
133+
If utilizing ngrok, accessing the ngrok UI is possible by opening http://127.0.0.1:4040/ in the browser. This interface offers a neat way to review the list of requests and replay them if necessary.
134+
135+
The service account token included with the request is valid for only 30 minutes. Therefore, attempting to call the DevRev API with that token for events older than this timeframe will result in a '401 Unauthorized' error.
136+
137+
### Updating manifest or the URL
138+
139+
The code can be changed without the need to create a snap-in version or redeploy the snap-in. On any change to the
140+
`src` folder, the server restarts with the updated changes. However, on [patch compatible](https://developer.devrev.ai/snap-in-development/upgrade-snap-ins#version-compatibility) updates to the manifest or the testing URL, we can `upgrade` the snap-in version.
141+
142+
```
143+
devrev snap_in_version upgrade --manifest <PATH_TO_MANIFEST> --testing-url <UPDATED_URL>
144+
```
145+
146+
In case of non-patch compatible updates, the `force` flag can be used to upgrade the version. However this will delete any
147+
existing snap-ins that have been created from this version.
148+
149+
```
150+
devrev snap_in_version upgrade --force --manifest <PATH_TO_MANIFEST> --testing-url <UPDATED_URL>
151+
```
152+
153+
Do note that manifest must always be provided when upgrading a snap-in version.

14-operations/code/.eslintrc.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = {
2+
extends: 'airbnb-typescript/base',
3+
extends: [
4+
'plugin:@typescript-eslint/recommended',
5+
'plugin:prettier/recommended', // Makes ESLint and Prettier play nicely together
6+
'plugin:import/recommended',
7+
'plugin:import/typescript',
8+
],
9+
ignorePatterns: ['**/dist/*'],
10+
parser: '@typescript-eslint/parser',
11+
parserOptions: {
12+
project: './tsconfig.eslint.json',
13+
},
14+
plugins: ['prettier', 'unused-imports', 'import', 'simple-import-sort', 'sort-keys-fix'],
15+
root: true,
16+
rules: {
17+
'import/first': 'error', // Ensures all imports are at the top of the file
18+
'import/newline-after-import': 'error', // Ensures there’s a newline after the imports
19+
'import/no-duplicates': 'error', // Merges import statements from the same file
20+
'import/order': 'off', // Not compatible with simple-import-sort
21+
'no-unused-vars': 'off', // Handled by @typescript-eslint/no-unused-vars
22+
'simple-import-sort/exports': 'error', // Auto-formats exports
23+
'simple-import-sort/imports': 'error', // Auto-formats imports
24+
'sort-imports': 'off', // Not compatible with simple-import-sort
25+
'sort-keys-fix/sort-keys-fix': ['error', 'asc', { natural: true }], // Sorts long object key lists alphabetically
26+
'unused-imports/no-unused-imports': 'error', // Removes unused imports automatically,
27+
'@typescript-eslint/no-explicit-any': 'warn', // Allows any type with a warning
28+
},
29+
overrides:[{
30+
"files": ["**/*.test.ts"],
31+
"rules": {
32+
'simple-import-sort/imports': 'off', // for test files we would want to load the mocked up modules later so on sorting the mocking mechanism will not work
33+
}
34+
}]
35+
};

14-operations/code/.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# Testing
9+
coverage/
10+
11+
# dependencies
12+
/node_modules
13+
14+
# IDEs and editors
15+
/.idea
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
*.sublime-workspace
22+
23+
# IDE - VSCode
24+
.vscode/*
25+
!.vscode/settings.json
26+
!.vscode/tasks.json
27+
!.vscode/launch.json
28+
!.vscode/extensions.json
29+
30+
# System Files
31+
.DS_Store
32+
Thumbs.db
33+
34+
deps.json
35+
results.json
36+
before-run-data.json
37+
38+
# packaged app
39+
*.tar.gz

14-operations/code/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

14-operations/code/.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Add files here to ignore them from prettier formatting
2+
3+
/dist
4+

14-operations/code/.prettierrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "es5",
8+
"bracketSpacing": true,
9+
"jsxSingleQuote": false,
10+
"arrowParens": "always",
11+
"proseWrap": "never",
12+
"htmlWhitespaceSensitivity": "strict",
13+
"endOfLine": "lf",
14+
"organizeImportsSkipDestructiveCodeActions": true
15+
}

14-operations/code/babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
3+
};

14-operations/code/jest.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
coverageDirectory: 'coverage',
4+
coverageThreshold: {
5+
"**/*": {
6+
branches: 60
7+
}
8+
},
9+
coverageReporters: ['text'],
10+
preset: 'ts-jest',
11+
testEnvironment: 'node'
12+
};

14-operations/code/nodemon.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"execMap": {
3+
"ts": "ts-node"
4+
}
5+
}

0 commit comments

Comments
 (0)