Skip to content

Commit 7bf48d6

Browse files
authored
Merge pull request #56 from KnorpelSenf/linting
Linting
2 parents 397cf29 + 70f4864 commit 7bf48d6

34 files changed

Lines changed: 1775 additions & 900 deletions

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.idea
3+
node_modules/
4+
built/
5+
package-lock.json

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true,
5+
es6: true
6+
},
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:@typescript-eslint/recommended',
10+
'prettier/@typescript-eslint',
11+
'plugin:prettier/recommended'
12+
],
13+
rules: {
14+
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
15+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
16+
'@typescript-eslint/no-unused-vars': 'error',
17+
'@typescript-eslint/no-explicit-any': 0,
18+
'@typescript-eslint/explicit-function-return-type': [
19+
'error',
20+
{
21+
allowExpressions: true
22+
}
23+
],
24+
'object-shorthand': ['error', 'always', { avoidQuotes: true }]
25+
},
26+
parserOptions: {
27+
parser: '@typescript-eslint/parser'
28+
}
29+
};

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.DS_Store
22
.idea
33
node_modules/
4-
built
4+
built/

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "none",
4+
"htmlWhitespaceSensitivity": "ignore",
5+
"tabWidth": 4,
6+
"semi": true,
7+
"arrowParens": "avoid"
8+
}

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dbaeumer.vscode-eslint"]
3+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll": true
5+
}
6+
}

README.md

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# cloudconvert-node
22

3-
4-
> This is the official Node.js SDK v2 for the [CloudConvert](https://cloudconvert.com/api/v2) _API v2_.
3+
> This is the official Node.js SDK v2 for the [CloudConvert](https://cloudconvert.com/api/v2) _API v2_.
54
> For API v1, please use [v1 branch](https://github.com/cloudconvert/cloudconvert-node/tree/v1) of this repository.
65
76
[![Build Status](https://travis-ci.org/cloudconvert/cloudconvert-node.svg?branch=master)](https://travis-ci.org/cloudconvert/cloudconvert-node)
@@ -10,21 +9,20 @@
109

1110
## Installation
1211

13-
1412
npm install --save cloudconvert
15-
13+
1614
Load as ESM module:
1715

1816
```js
1917
import CloudConvert from 'cloudconvert';
2018
```
2119

2220
... or via require:
21+
2322
```js
2423
const CloudConvert = require('cloudconvert');
2524
```
2625

27-
2826
## Creating Jobs
2927

3028
```js
@@ -33,24 +31,25 @@ import CloudConvert from 'cloudconvert';
3331
const cloudConvert = new CloudConvert('api_key');
3432

3533
let job = await cloudConvert.jobs.create({
36-
'tasks': {
34+
tasks: {
3735
'import-my-file': {
38-
'operation': 'import/url',
39-
'url': 'https://my-url'
36+
operation: 'import/url',
37+
url: 'https://my-url'
4038
},
4139
'convert-my-file': {
42-
'operation': 'convert',
43-
'input': 'import-my-file',
44-
'output_format': 'pdf',
45-
'some_other_option': 'value'
40+
operation: 'convert',
41+
input: 'import-my-file',
42+
output_format: 'pdf',
43+
some_other_option: 'value'
4644
},
4745
'export-my-file': {
48-
'operation': 'export/url',
49-
'input': 'convert-my-file'
46+
operation: 'export/url',
47+
input: 'convert-my-file'
5048
}
5149
}
5250
});
5351
```
52+
5453
You can use the [CloudConvert Job Builder](https://cloudconvert.com/api/v2/jobs/builder) to see the available options for the various task types.
5554

5655
## Downloading Files
@@ -60,13 +59,15 @@ CloudConvert can generate public URLs for using `export/url` tasks. You can use
6059
```js
6160
job = await cloudConvert.jobs.wait(job.id); // Wait for job completion
6261

63-
const exportTask = job.tasks.filter(task => task.operation === 'export/url' && task.status === 'finished')[0];
62+
const exportTask = job.tasks.filter(
63+
task => task.operation === 'export/url' && task.status === 'finished'
64+
)[0];
6465
const file = exportTask.result.files[0];
6566

6667
const writeStream = fs.createWriteStream('./out/' + file.filename);
6768

68-
https.get(file.url, function(response) {
69-
response.pipe(writeStream);
69+
https.get(file.url, function (response) {
70+
response.pipe(writeStream);
7071
});
7172

7273
await new Promise((resolve, reject) => {
@@ -81,10 +82,10 @@ Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https
8182

8283
```js
8384
const job = await cloudConvert.jobs.create({
84-
'tasks': {
85+
tasks: {
8586
'upload-my-file': {
86-
'operation': 'import/upload'
87-
},
87+
operation: 'import/upload'
88+
}
8889
// ...
8990
}
9091
});
@@ -96,12 +97,10 @@ const inputFile = fs.createReadStream('./file.pdf');
9697
await cloudConvert.tasks.upload(uploadTask, inputFile, 'file.pdf');
9798
```
9899

99-
100100
## Websocket Events
101101

102102
The node SDK can subscribe to events of the [CloudConvert socket.io API](https://cloudconvert.com/api/v2/socket#socket).
103103

104-
105104
```js
106105
const job = await cloudConvert.jobs.create({ ... });
107106

@@ -121,6 +120,7 @@ cloudConvert.jobs.subscribeTaskEvent(job.id, 'finished', event => {
121120
```
122121

123122
When you don't want to receive any events any more you should close the socket:
123+
124124
```js
125125
cloudConvert.socket.close();
126126
```
@@ -134,7 +134,11 @@ const payloadString = '...'; // The JSON string from the raw request body.
134134
const signature = '...'; // The value of the "CloudConvert-Signature" header.
135135
const signingSecret = '...'; // You can find it in your webhook settings.
136136

137-
const isValid = cloudConvert.webhooks.verify(payloadString, signature, signingSecret); // returns true or false
137+
const isValid = cloudConvert.webhooks.verify(
138+
payloadString,
139+
signature,
140+
signingSecret
141+
); // returns true or false
138142
```
139143

140144
## Contributing
@@ -172,7 +176,20 @@ By default, this runs the integration tests against the Sandbox API with an offi
172176
53d6fe6b688c31c565907c81de625046 input.pdf
173177
99d4c165f77af02015aa647770286cf9 input.png
174178

179+
### Linting
180+
181+
The project is linted by ESLint+Prettier.
182+
183+
If you're using VSCode, all files will be linted automatically upon saving.
184+
Otherwise, you can lint the project by running
185+
186+
npm run lint
187+
188+
and even auto-fix as many things as possible by running
189+
190+
npm run lint -- --fix
191+
175192
## Resources
176193

177-
* [API v2 Documentation](https://cloudconvert.com/api/v2)
178-
* [CloudConvert Blog](https://cloudconvert.com/blog)
194+
- [API v2 Documentation](https://cloudconvert.com/api/v2)
195+
- [CloudConvert Blog](https://cloudconvert.com/blog)

lib/CloudConvert.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import axios, { AxiosInstance } from "axios";
1+
import axios, { AxiosInstance } from 'axios';
22
import io from 'socket.io-client';
3-
import JobsResource, { JobEventData } from "./JobsResource";
4-
import TasksResource, { TaskEventData } from "./TasksResource";
5-
import UsersResource from "./UsersResource";
6-
import WebhooksResource from "./WebhooksResource";
3+
import JobsResource, { JobEventData } from './JobsResource';
4+
import TasksResource, { TaskEventData } from './TasksResource';
5+
import UsersResource from './UsersResource';
6+
import WebhooksResource from './WebhooksResource';
77

88
export default class CloudConvert {
99
private socket: SocketIOClient.Socket | undefined;
1010
private subscribedChannels: Map<string, boolean> | undefined;
11-
11+
1212
public readonly apiKey: string;
1313
public readonly useSandbox: boolean;
14-
14+
1515
public axios!: AxiosInstance;
1616
public tasks!: TasksResource;
1717
public jobs!: JobsResource;
1818
public users!: UsersResource;
1919
public webhooks!: WebhooksResource;
2020

2121
constructor(apiKey: string, useSandbox = false) {
22-
2322
this.apiKey = apiKey;
2423
this.useSandbox = useSandbox;
2524

2625
this.createAxiosInstance();
2726
this.createResources();
28-
2927
}
3028

31-
3229
createAxiosInstance(): void {
3330
this.axios = axios.create({
34-
baseURL: this.useSandbox ? 'https://api.sandbox.cloudconvert.com/v2/' : 'https://api.cloudconvert.com/v2/',
31+
baseURL: this.useSandbox
32+
? 'https://api.sandbox.cloudconvert.com/v2/'
33+
: 'https://api.cloudconvert.com/v2/',
3534
headers: {
36-
'Authorization': 'Bearer ' + this.apiKey,
37-
'User-Agent': 'cloudconvert-node/v2 (https://github.com/cloudconvert/cloudconvert-node)'
35+
Authorization: 'Bearer ' + this.apiKey,
36+
'User-Agent':
37+
'cloudconvert-node/v2 (https://github.com/cloudconvert/cloudconvert-node)'
3838
}
3939
});
4040
}
@@ -46,13 +46,22 @@ export default class CloudConvert {
4646
this.webhooks = new WebhooksResource(this);
4747
}
4848

49-
50-
subscribe(channel: string, event: string, callback: ((event: JobEventData) => void) | ((event: TaskEventData) => void)): void {
51-
49+
subscribe(
50+
channel: string,
51+
event: string,
52+
callback:
53+
| ((event: JobEventData) => void)
54+
| ((event: TaskEventData) => void)
55+
): void {
5256
if (!this.socket) {
53-
this.socket = io.connect(this.useSandbox ? 'https://socketio.sandbox.cloudconvert.com' : 'https://socketio.cloudconvert.com', {
54-
transports: ['websocket']
55-
});
57+
this.socket = io.connect(
58+
this.useSandbox
59+
? 'https://socketio.sandbox.cloudconvert.com'
60+
: 'https://socketio.cloudconvert.com',
61+
{
62+
transports: ['websocket']
63+
}
64+
);
5665
this.subscribedChannels = new Map<string, boolean>();
5766
}
5867

@@ -61,23 +70,21 @@ export default class CloudConvert {
6170
channel,
6271
auth: {
6372
headers: {
64-
'Authorization': 'Bearer ' + this.apiKey
73+
Authorization: 'Bearer ' + this.apiKey
6574
}
66-
},
75+
}
6776
});
6877
this.subscribedChannels?.set(channel, true);
6978
}
7079

71-
this.socket.on(event, function (eventChannel: string, eventData: any): void {
80+
this.socket.on(event, function (
81+
eventChannel: string,
82+
eventData: any
83+
): void {
7284
if (channel !== eventChannel) {
7385
return;
7486
}
7587
callback(eventData);
7688
});
77-
7889
}
79-
80-
8190
}
82-
83-

0 commit comments

Comments
 (0)