Skip to content

Commit 8c2d44b

Browse files
authored
Update template in snap-in-examples (#30)
1 parent ebd0122 commit 8c2d44b

File tree

63 files changed

+4491
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4491
-63
lines changed

1-starter/code/.npmrc

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

1-starter/code/package.json

+18-8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"build": "rimraf ./dist && tsc",
1010
"build:watch": "tsc --watch",
1111
"prepackage": "npm run build",
12-
"package": "tar -cvzf build.tar.gz dist package.json package-lock.json",
13-
"start": "ts-node ./src/main.ts",
14-
"start:watch": "nodemon ./src/main.ts",
12+
"package": "tar -cvzf build.tar.gz dist package.json package-lock.json .npmrc",
13+
"start": "ts-node src/main.ts",
14+
"start:watch": "nodemon src/main.ts",
1515
"start:production": "node dist/main.js",
16+
"test:server": "nodemon --watch src --watch test test/main.ts",
1617
"test": "jest",
1718
"test:watch": "jest --watch"
1819
},
@@ -23,6 +24,8 @@
2324
"@babel/core": "^7.20.12",
2425
"@babel/preset-env": "^7.20.2",
2526
"@babel/preset-typescript": "^7.18.6",
27+
"@types/body-parser": "1.19.5",
28+
"@types/express": "4.17.21",
2629
"@types/jest": "^29.4.0",
2730
"@types/node": "^18.13.0",
2831
"@types/yargs": "^17.0.24",
@@ -31,19 +34,26 @@
3134
"eslint": "^8.33.0",
3235
"eslint-config-airbnb-base": "^15.0.0",
3336
"eslint-config-airbnb-typescript": "^17.0.0",
34-
"eslint-plugin-import": "^2.27.5",
35-
"eslint-plugin-prettier": "^4.2.1",
37+
"eslint-config-prettier": "8.5.0",
38+
"eslint-plugin-import": "2.25.4",
39+
"eslint-plugin-prettier": "4.0.0",
40+
"eslint-plugin-simple-import-sort": "7.0.0",
41+
"eslint-plugin-sort-keys-fix": "1.1.2",
42+
"eslint-plugin-unused-imports": "2.0.0",
3643
"jest": "^29.4.2",
3744
"nodemon": "^2.0.20",
3845
"prettier": "^2.8.3",
3946
"prettier-plugin-organize-imports": "^3.2.2",
4047
"rimraf": "^4.1.2",
4148
"ts-jest": "^29.0.5",
4249
"ts-node": "^10.9.1",
43-
"typescript": "^4.9.5"
44-
},
45-
"dependencies": {
50+
"typescript": "^4.9.5",
51+
"body-parser": "1.20.2",
4652
"dotenv": "^16.0.3",
53+
"express": "4.19.2",
4754
"yargs": "^17.6.2"
55+
},
56+
"dependencies": {
57+
"@devrev/typescript-sdk": "^1.1.17"
4858
}
4959
}

1-starter/code/test/http_client.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2024 DevRev Inc. All rights reserved.
3+
4+
Disclaimer:
5+
The code provided herein is intended solely for testing purposes.
6+
Under no circumstances should it be utilized in a production environment. Use of
7+
this code in live systems, production environments, or any situation where
8+
reliability and stability are critical is strongly discouraged. The code is
9+
provided as-is, without any warranties or guarantees of any kind, and the user
10+
assumes all risks associated with its use. It is the responsibility of the user
11+
to ensure that proper testing and validation procedures are carried out before
12+
deploying any code into production environments.
13+
*/
14+
15+
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
16+
17+
interface SetupOptions {
18+
endpoint: string;
19+
token?: string;
20+
}
21+
22+
export interface HttpRequest {
23+
headers?: any;
24+
path: string;
25+
body: unknown;
26+
}
27+
28+
export class HTTPClient {
29+
public instance: AxiosInstance;
30+
31+
constructor({ endpoint, token }: SetupOptions) {
32+
const axiosConfig: AxiosRequestConfig = {
33+
baseURL: endpoint,
34+
headers: {
35+
Authorization: token,
36+
},
37+
};
38+
39+
this.instance = axios.create({
40+
...axiosConfig,
41+
});
42+
}
43+
44+
async post<T>({ headers, path, body }: HttpRequest): Promise<AxiosResponse<T>> {
45+
return this.instance.request({
46+
method: 'POST',
47+
headers: headers,
48+
data: body,
49+
url: path,
50+
});
51+
}
52+
}

1-starter/code/test/main.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2024 DevRev Inc. All rights reserved.
3+
4+
Disclaimer:
5+
The code provided herein is intended solely for testing purposes.
6+
Under no circumstances should it be utilized in a production environment. Use of
7+
this code in live systems, production environments, or any situation where
8+
reliability and stability are critical is strongly discouraged. The code is
9+
provided as-is, without any warranties or guarantees of any kind, and the user
10+
assumes all risks associated with its use. It is the responsibility of the user
11+
to ensure that proper testing and validation procedures are carried out before
12+
deploying any code into production environments.
13+
*/
14+
15+
import yargs from 'yargs';
16+
import { hideBin } from 'yargs/helpers';
17+
import { startServer } from './runner';
18+
19+
(async () => {
20+
const argv = await yargs(hideBin(process.argv)).options({
21+
port: {
22+
require: false,
23+
type: 'number',
24+
},
25+
}).argv;
26+
27+
const port = argv.port || 8000;
28+
startServer(port);
29+
})();

0 commit comments

Comments
 (0)