Skip to content

Commit

Permalink
fix: add user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Bodin committed Sep 27, 2021
1 parent 0dc8303 commit 36addeb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.17.6
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Contributing

##  Commands

```sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ We highly recommend not to define sensitive information such as Algolia and/or C

## Troubleshooting

- Need help? We have you covered in our [Discourse forum](https://discourse.algolia.com/c/netlify/28)
- Need help? We have you covered in our [Discourse forum](https://discourse.algolia.com/)
- Found a bug in the plugin? Please read our [contributing guide](/CONTRIBUTING.md) and either open an [issue](https://github.com/algolia/algoliasearch-crawler-github-actions/issues) or a [pull request](https://github.com/algolia/algoliasearch-crawler-github-actions/pulls)
- Can't find the answer to your issue? Please reach out to [support@algolia.com](support@algolia.com)

Expand Down
15 changes: 15 additions & 0 deletions src/crawler-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import fetch from 'node-fetch';
import type { Response } from 'node-fetch';

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
import { version } from '../package.json';

import type { ConfigJson } from './types/configJson';
import type {
GetCrawlersResponseBody,
Expand Down Expand Up @@ -42,6 +46,8 @@ export interface TestUrlParams {
config?: JSON;
}

const USER_AGENT = `algolia_crawler_github_actions/${version}`;

/**
* Example of class that can be used to hit the Crawler API.
*
Expand Down Expand Up @@ -109,6 +115,7 @@ class CrawlerApiClient {
headers: {
Authorization: this.basicAuthToken,
'Content-Type': 'application/json',
'User-Agent': USER_AGENT,
},
body: JSON.stringify(body),
});
Expand Down Expand Up @@ -140,6 +147,7 @@ class CrawlerApiClient {
headers: {
Authorization: this.basicAuthToken,
'Content-Type': 'application/json',
'User-Agent': USER_AGENT,
},
body: JSON.stringify(body),
});
Expand Down Expand Up @@ -189,6 +197,7 @@ class CrawlerApiClient {
{
headers: {
Authorization: this.basicAuthToken,
'User-Agent': USER_AGENT,
},
}
);
Expand Down Expand Up @@ -217,6 +226,7 @@ class CrawlerApiClient {
headers: {
Authorization: this.basicAuthToken,
'Content-Type': 'application/json',
'User-Agent': USER_AGENT,
},
body: JSON.stringify(partialJsonConfig),
});
Expand Down Expand Up @@ -253,6 +263,7 @@ class CrawlerApiClient {
const res = await fetch(`${this.crawlerApiBaseUrl}/crawlers/${id}`, {
headers: {
Authorization: this.basicAuthToken,
'User-Agent': USER_AGENT,
},
});
return CrawlerApiClient.__handleResponse<CrawlerStatusResponseBody>(res);
Expand All @@ -270,6 +281,7 @@ class CrawlerApiClient {
{
headers: {
Authorization: this.basicAuthToken,
'User-Agent': USER_AGENT,
},
}
);
Expand Down Expand Up @@ -315,6 +327,7 @@ class CrawlerApiClient {
headers: {
Authorization: this.basicAuthToken,
'Content-Type': 'application/json',
'User-Agent': USER_AGENT,
},
}
);
Expand All @@ -339,6 +352,7 @@ class CrawlerApiClient {
{
headers: {
Authorization: this.basicAuthToken,
'User-Agent': USER_AGENT,
},
}
);
Expand Down Expand Up @@ -375,6 +389,7 @@ class CrawlerApiClient {
headers: {
Authorization: this.basicAuthToken,
'Content-Type': 'application/json',
'User-Agent': USER_AGENT,
},
body: JSON.stringify({ url, config }),
}
Expand Down
16 changes: 12 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"types": ["node", "jest"],
"types": [
"node",
"jest"
],
},
"exclude": ["node_modules","**/*.test.ts"],
"exclude": [
"node_modules",
"**/*.test.ts"
],
"include": [
"src/**/*",
"package.json"
],
"typeRoots": ["node_modules/@types"]
"typeRoots": [
"node_modules/@types"
]
}

0 comments on commit 36addeb

Please sign in to comment.