Skip to content

Commit 1eca4d7

Browse files
Increase body limits & fix dependencies (#62)
1 parent 85fa65a commit 1eca4d7

File tree

87 files changed

+6116
-5039
lines changed

Some content is hidden

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

87 files changed

+6116
-5039
lines changed

circle.yml renamed to .circleci/circle.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ version: 2
22
jobs:
33
test:
44
docker:
5-
- image: circleci/node:12-stretch
5+
- image: circleci/node:14-stretch
66
steps:
77
- checkout
88
- restore_cache:
99
key: dependency-cache-{{ checksum "package.json" }}
10+
- run:
11+
name: Audit Dependencies
12+
command: npm audit --audit-level=high
1013
- run:
1114
name: Installing Dependencies
1215
command: npm install

.eslintrc.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module.exports = {
2+
env: {
3+
es6: true,
4+
node: true,
5+
mocha: true,
6+
},
7+
extends: [
8+
'airbnb-base',
9+
],
10+
globals: {
11+
Atomics: 'readonly',
12+
SharedArrayBuffer: 'readonly',
13+
},
14+
parser: '@typescript-eslint/parser',
15+
parserOptions: {
16+
ecmaVersion: 2018,
17+
sourceType: 'module',
18+
},
19+
plugins: [
20+
'@typescript-eslint',
21+
],
22+
rules: {
23+
'import/no-extraneous-dependencies': ['error', { devDependencies: ['spec/**/*', 'spec-integration/**/*'] }],
24+
'no-plusplus': 0,
25+
'no-unused-vars': 0,
26+
'no-await-in-loop': 0,
27+
'prefer-default-export': 0,
28+
'import/prefer-default-export': 0,
29+
'class-methods-use-this': 1,
30+
'max-len': ['error', { code: 180 }],
31+
'no-param-reassign': 1,
32+
'no-return-assign': 1,
33+
'no-use-before-define': 0,
34+
'comma-dangle': 0,
35+
'object-curly-newline': 0,
36+
camelcase: 0,
37+
'import/extensions': [
38+
'error',
39+
'ignorePackages',
40+
{
41+
js: 'never',
42+
jsx: 'never',
43+
ts: 'never',
44+
tsx: 'never',
45+
},
46+
],
47+
},
48+
settings: {
49+
'import/parsers': {
50+
'@typescript-eslint/parser': ['.ts', '.tsx'],
51+
},
52+
'import/resolver': {
53+
node: {
54+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
55+
},
56+
},
57+
},
58+
};

.gitignore

+46-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
*.js
2-
*.map
3-
*.d.ts
4-
!*.json
51
# Logs
62
logs
73
*.log
84
npm-debug.log*
95
yarn-debug.log*
106
yarn-error.log*
7+
lerna-debug.log*
118

12-
# IDEA files
13-
.idea
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
1411

1512
# Runtime data
1613
pids
@@ -23,11 +20,12 @@ lib-cov
2320

2421
# Coverage directory used by tools like istanbul
2522
coverage
23+
*.lcov
2624

2725
# nyc test coverage
2826
.nyc_output
2927

30-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
3129
.grunt
3230

3331
# Bower dependency directory (https://bower.io/)
@@ -46,12 +44,21 @@ jspm_packages/
4644
# TypeScript v1 declaration files
4745
typings/
4846

47+
# TypeScript cache
48+
*.tsbuildinfo
49+
4950
# Optional npm cache directory
5051
.npm
5152

5253
# Optional eslint cache
5354
.eslintcache
5455

56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
5562
# Optional REPL history
5663
.node_repl_history
5764

@@ -63,9 +70,38 @@ typings/
6370

6471
# dotenv environment variables file
6572
.env
73+
.env.test
6674

67-
# next.js build output
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
6879
.next
6980

70-
# TypeScript output directory
71-
out
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
84+
# Gatsby files
85+
.cache/
86+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
87+
# https://nextjs.org/blog/next-9-1#public-directory-support
88+
# public
89+
90+
# vuepress build output
91+
.vuepress/dist
92+
93+
# Serverless directories
94+
.serverless/
95+
96+
# FuseBox cache
97+
.fusebox/
98+
99+
# DynamoDB Local files
100+
.dynamodb/
101+
102+
# TernJS port file
103+
.tern-port
104+
.vscode
105+
.idea
106+
!.eslintrc.js
107+
*.d.ts

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.2 (April 13, 2022)
2+
* Fix dependencies
3+
4+
## 2.0.1 (March 29, 2022)
5+
- Increase `REQUEST_MAX_BODY_LENGTH` to 100MB
6+
17
## 2.0.0 (January 14, 2022)
28
* Now method `uploadAttachment` from `AttachmentProcessor` saves attachments directly to `Maester`
39
* Now method `uploadAttachment` from `AttachmentProcessor` accepts additional argument `contentType`

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ A number of REST Client classes are available to use and extend to create Client
3636
Each of the REST Clients extends from the `NoAuthRestClient`, overriding the relevant methods. Exception is PlatformApiRestClient and PlatformApiLogicClient.
3737

3838
### NoAuthRestClient
39-
[NoAuthRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/NoAuthRestClient.ts) class to make rest requests no no auth APIs by provided options.
39+
[NoAuthRestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/NoAuthRestClient.ts) class to make rest requests no no auth APIs by provided options.
4040

4141
#### constructor(emitter, cfg)
4242
- emitter - EIO emitting context.
@@ -80,7 +80,7 @@ class MyClient extends NoAuthRestClient {
8080
```
8181

8282
### BasicAuthRestClient
83-
[BasicAuthRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/BasicAuthRestClient.ts)
83+
[BasicAuthRestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/BasicAuthRestClient.ts)
8484
class extends [NoAuthRestClient](#NoAuthRestClient) class.
8585
Makes requests to resource with basic auth.
8686

@@ -94,7 +94,7 @@ const Client = new BasicAuthRestClient(emitter, cfg, user, pass);
9494

9595

9696
### ApiKeyRestClient
97-
[ApiKeyRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/ApiKeyRestClient.ts)
97+
[ApiKeyRestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/ApiKeyRestClient.ts)
9898
class extends [NoAuthRestClient](#NoAuthRestClient) class.
9999
Makes requests to resource with api key (custom header) auth.
100100

@@ -107,13 +107,13 @@ const Client = new BasicAuthRestClient(emitter, cfg, user, pass);
107107
```
108108

109109
### CookieRestClient
110-
[CookieRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/CookieRestClient.ts)
110+
[CookieRestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/CookieRestClient.ts)
111111
class extends [NoAuthRestClient](#NoAuthRestClient) class.
112112

113113
TBD
114114

115115
### OAuth2AuthorizationCodeRestClient
116-
[OAuth2RestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/OAuth2AuthorizationCodeRestClient.ts)
116+
[OAuth2RestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/OAuth2AuthorizationCodeRestClient.ts)
117117
class extends [NoAuthRestClient](#NoAuthRestClient) class.
118118
Makes requests to resource with oauth2 access token auth.
119119

@@ -125,7 +125,7 @@ const Client = new OAuth2AuthorizationCodeRestClient(emitter, cfg);
125125
This class can handle, refresh and emit oauth2 EIO configuration.
126126

127127
### NtlmRestClient
128-
[NtlmRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/NtlmRestClient.ts)
128+
[NtlmRestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/NtlmRestClient.ts)
129129
class extends [NoAuthRestClient](#NoAuthRestClient) class.
130130
Makes requests to resource with [NTLM authentication](https://en.wikipedia.org/wiki/NT_LAN_Manager).
131131
Falls back to basic authentication if NTLM authentication fails.
@@ -143,7 +143,7 @@ const Client = new NtlmRestClient(emitter, cfg);
143143
A number of Platform API Client classes are available to use and extend them to create Clients for Platform API.
144144

145145
### PlatformApiRestClient
146-
[PlatformApiRestClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/PlatformApiRestClient.ts)
146+
[PlatformApiRestClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/PlatformApiRestClient.ts)
147147
class extends [BasicAuthRestClient](#BasicAuthRestClient) class.
148148
The method inside this class checks for the status code 200, if not, then throws an error. And also checks that the response came with the correct data in the JSON format and the other expected response headers.
149149

@@ -156,7 +156,7 @@ const Client = new PlatformApiRestClient(emitter, cfg);
156156
```
157157

158158
### PlatformApiLogicClient
159-
[PlatformApiLogicClient](https://github.com/elasticio/component-commons-library/blob/master/lib/authentication/PlatformApiLogicClient.ts)
159+
[PlatformApiLogicClient](https://github.com/elasticio/component-commons-library/blob/master/src/authentication/PlatformApiLogicClient.ts)
160160
class extends [PlatformApiRestClient](#PlatformApiRestClient) class.
161161
Contains useful methods to manipulate flow's state to set it either to active running or to inactive stopped, searching flows, workspaces, credentials and more.
162162

@@ -225,7 +225,7 @@ const result = await new AttachmentProcessor().getAttachment('http://example.com
225225
```
226226

227227
## Logger
228-
The built in logger uses Bunyan Logger as its base implementation. The available logger methods can be found [here](https://github.com/elasticio/component-commons-library/blob/master/lib/logger/logger.ts#L19).
228+
The built in logger uses Bunyan Logger as its base implementation. The available logger methods can be found [here](https://github.com/elasticio/component-commons-library/blob/master/src/logger/logger.ts#L19).
229229

230230
Example:
231231

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const fs_1 = __importDefault(require("fs"));
7+
const path_1 = __importDefault(require("path"));
8+
const chai_1 = require("chai");
9+
const common_1 = require("./common");
10+
const AttachmentProcessor_1 = require("../src/attachment/AttachmentProcessor");
11+
(0, common_1.setEnvs)();
12+
describe('AttachmentProcessor', () => {
13+
describe('uploadAttachment', () => {
14+
it('uploadAttachment (/samples/sample.json)', async () => {
15+
const file = fs_1.default.createReadStream(path_1.default.join(__dirname, './samples/sample.json'));
16+
const res = await new AttachmentProcessor_1.AttachmentProcessor().uploadAttachment(file, 'application/octet-stream');
17+
(0, chai_1.expect)(res.data.contentType).to.be.equal('application/octet-stream');
18+
});
19+
it('uploadAttachment (/samples/image.png)', async () => {
20+
const file = fs_1.default.createReadStream(path_1.default.join(__dirname, './samples/image.png'));
21+
const res = await new AttachmentProcessor_1.AttachmentProcessor().uploadAttachment(file, 'image/png');
22+
(0, chai_1.expect)(res.data.contentType).to.be.equal('image/png');
23+
});
24+
});
25+
});

dist/spec-integration/common.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.setEnvs = void 0;
4+
const fs_1 = require("fs");
5+
const dotenv_1 = require("dotenv");
6+
const setEnvs = () => {
7+
if ((0, fs_1.existsSync)('.env')) {
8+
(0, dotenv_1.config)();
9+
}
10+
};
11+
exports.setEnvs = setEnvs;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
/* eslint-disable no-buffer-constructor */
7+
const chai_1 = __importDefault(require("chai"));
8+
const fs_1 = __importDefault(require("fs"));
9+
const stream_1 = require("stream");
10+
const sinon_1 = __importDefault(require("sinon"));
11+
const dist_1 = require("@elastic.io/maester-client/dist");
12+
const AttachmentProcessor_1 = require("../../src/attachment/AttachmentProcessor");
13+
const { expect } = chai_1.default;
14+
const maesterUri = 'https://ma.estr';
15+
process.env.ELASTICIO_OBJECT_STORAGE_TOKEN = 'token';
16+
process.env.ELASTICIO_OBJECT_STORAGE_URI = maesterUri;
17+
const formStream = (dataString) => {
18+
const stream = new stream_1.Readable();
19+
stream.push(dataString);
20+
stream.push(null);
21+
return stream;
22+
};
23+
describe('AttachmentProcessor', () => {
24+
const attachmentProcessor = new AttachmentProcessor_1.AttachmentProcessor();
25+
describe('Steward', () => {
26+
it('Should successfully retrieve csv', async () => {
27+
const attachmentOptions = {
28+
'content-type': 'arraybuffer',
29+
url: 'http://insight.dev.schoolwires.com/HelpAssets/C2Assets/C2Files/C2ImportCalEventSample.csv',
30+
};
31+
const result = await attachmentProcessor.getAttachment(attachmentOptions.url, attachmentOptions['content-type']);
32+
const encodedResult = new Buffer(result.data, 'binary').toString('base64');
33+
const expectedResult = fs_1.default.readFileSync('spec/attachment/resources/base64csv.txt').toString();
34+
expect(encodedResult).to.be.equal(expectedResult);
35+
});
36+
it('Should successfully retrieve png image', async () => {
37+
const attachmentOptions = {
38+
'content-type': 'arraybuffer',
39+
url: `https://httpbin.org/image/png?${AttachmentProcessor_1.STORAGE_TYPE_PARAMETER}=steward`,
40+
};
41+
const result = await attachmentProcessor.getAttachment(attachmentOptions.url, 'arraybuffer');
42+
const encodedResult = new Buffer(result.data, 'binary').toString('base64');
43+
const expectedResult = fs_1.default.readFileSync('spec/attachment/resources/base64Png.txt').toString();
44+
expect(encodedResult).to.be.equal(expectedResult);
45+
});
46+
});
47+
describe('maester', () => {
48+
let getById;
49+
beforeEach(() => {
50+
getById = sinon_1.default.stub(dist_1.ObjectStorage.prototype, 'getById').callsFake(async () => ({ data: formStream('i`m a stream') }));
51+
});
52+
afterEach(() => {
53+
sinon_1.default.restore();
54+
});
55+
it('Should successfully retrieve response (stream)', async () => {
56+
const attachmentOptions = {
57+
'content-type': 'stream',
58+
url: `${maesterUri}${AttachmentProcessor_1.MAESTER_OBJECT_ID_ENDPOINT}object_id?${AttachmentProcessor_1.STORAGE_TYPE_PARAMETER}=maester`,
59+
};
60+
const result = await attachmentProcessor.getAttachment(attachmentOptions.url, attachmentOptions['content-type']);
61+
expect(result.toString('base64')).to.be.equal({ data: formStream('i`m a stream') }.toString());
62+
expect(getById.getCall(0).args[0]).to.be.equal('object_id');
63+
expect(getById.getCall(0).args[1]).to.be.equal('stream');
64+
});
65+
});
66+
});

0 commit comments

Comments
 (0)