@corva/create-app 0.12.0-1 → 0.12.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +32 -7
- package/constants/manifest.js +60 -14
- package/helpers/manifest.js +18 -15
- package/index.js +92 -75
- package/package.json +2 -2
- package/scripts/ui/zipAppSource.js +4 -4
- package/template/scheduler/node/__test__/processor.test.js +3 -3
- package/template/scheduler/node/gitignore +21 -0
- package/template/scheduler/node/package.json +3 -3
- package/template/scheduler/node-ts/README.md +25 -0
- package/template/scheduler/node-ts/__test__/processor.spec.ts +20 -0
- package/template/scheduler/node-ts/gitignore +25 -0
- package/template/scheduler/node-ts/index.ts +8 -0
- package/template/scheduler/node-ts/lib/processor.ts +13 -0
- package/template/scheduler/node-ts/package.json +37 -0
- package/template/scheduler/node-ts/tsconfig.build.json +11 -0
- package/template/scheduler/node-ts/tsconfig.json +33 -0
- package/template/stream/node/__test__/processor.test.js +6 -9
- package/template/stream/node/gitignore +21 -0
- package/template/stream/node/package.json +3 -3
- package/template/stream/node-ts/README.md +25 -0
- package/template/stream/node-ts/__test__/processor.spec.ts +43 -0
- package/template/stream/node-ts/gitignore +25 -0
- package/template/stream/node-ts/index.ts +8 -0
- package/template/stream/node-ts/lib/processor.ts +16 -0
- package/template/stream/node-ts/package.json +37 -0
- package/template/stream/node-ts/tsconfig.build.json +11 -0
- package/template/stream/node-ts/tsconfig.json +33 -0
- package/template/task/node/__test__/processor.test.js +18 -0
- package/template/task/node/gitignore +21 -0
- package/template/task/node/index.js +1 -1
- package/template/task/node/package.json +3 -3
- package/template/task/node/src/processor.js +0 -1
- package/template/task/node-ts/README.md +25 -0
- package/template/task/node-ts/__test__/processor.spec.ts +27 -0
- package/template/task/node-ts/gitignore +25 -0
- package/template/task/node-ts/index.ts +8 -0
- package/template/task/node-ts/package.json +37 -0
- package/template/task/node-ts/src/processor.ts +13 -0
- package/template/task/node-ts/tsconfig.build.json +11 -0
- package/template/task/node-ts/tsconfig.json +33 -0
- package/helpers/metadata.js +0 -29
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# testing
|
|
7
|
+
/coverage
|
|
8
|
+
|
|
9
|
+
# misc
|
|
10
|
+
.env
|
|
11
|
+
.DS_Store
|
|
12
|
+
.env.local
|
|
13
|
+
.env.development.local
|
|
14
|
+
.env.test.local
|
|
15
|
+
.env.production.local
|
|
16
|
+
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
|
|
21
|
+
**/*.js
|
|
22
|
+
**/*.js.map
|
|
23
|
+
**/.d.ts
|
|
24
|
+
|
|
25
|
+
*.zip
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Corva } from '@corva/node-sdk';
|
|
2
|
+
import { Processor } from './lib/processor';
|
|
3
|
+
|
|
4
|
+
export const handler = new Corva().scheduled<{ some: string }, void>(async (event, context) => {
|
|
5
|
+
const processor = new Processor(context.api, context.logger);
|
|
6
|
+
|
|
7
|
+
await processor.process(event);
|
|
8
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HandlerContext, ScheduledLambdaEvent } from '@corva/node-sdk';
|
|
2
|
+
|
|
3
|
+
export class Processor {
|
|
4
|
+
constructor(private apiClient: HandlerContext['api'], private logger: HandlerContext['logger']) {}
|
|
5
|
+
|
|
6
|
+
async process(event: ScheduledLambdaEvent<{ some: string }>) {
|
|
7
|
+
this.logger.debug({ event }, 'Event');
|
|
8
|
+
|
|
9
|
+
const { asset_id: assetId, schedule_start: scheduleStart, interval } = event;
|
|
10
|
+
|
|
11
|
+
this.logger.info(`Processing event. Asset: ${assetId}. Schedule start: ${scheduleStart}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-dev-center-polling-scheduler-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "My Dev Center Polling Scheduler Data App",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json $LOCKFILE manifest.json index.js lib -x '*.ts'",
|
|
8
|
+
"test": "npm audit --production && npm run unit",
|
|
9
|
+
"build": "tsc -p tsconfig.build.json",
|
|
10
|
+
"unit": "jest"
|
|
11
|
+
},
|
|
12
|
+
"jest": {
|
|
13
|
+
"moduleFileExtensions": [
|
|
14
|
+
"js",
|
|
15
|
+
"json",
|
|
16
|
+
"ts"
|
|
17
|
+
],
|
|
18
|
+
"rootDir": ".",
|
|
19
|
+
"testEnvironment": "node",
|
|
20
|
+
"testMatch": [
|
|
21
|
+
"**/*.spec.ts"
|
|
22
|
+
],
|
|
23
|
+
"transform": {
|
|
24
|
+
"^.+\\.ts$": "ts-jest"
|
|
25
|
+
},
|
|
26
|
+
"verbose": true
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@corva/node-sdk": "^5.3.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^27.0.1",
|
|
33
|
+
"jest": "^27.2.1",
|
|
34
|
+
"ts-jest": "^27.0.5",
|
|
35
|
+
"typescript": "^4.4.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": [
|
|
3
|
+
"lib/**/*.ts",
|
|
4
|
+
"__tests__"
|
|
5
|
+
],
|
|
6
|
+
"exclude": [
|
|
7
|
+
"node_modules"
|
|
8
|
+
],
|
|
9
|
+
"compilerOptions": {
|
|
10
|
+
"target": "es2019",
|
|
11
|
+
"skipLibCheck": false,
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"checkJs": false,
|
|
17
|
+
"module": "commonjs",
|
|
18
|
+
"alwaysStrict": true,
|
|
19
|
+
"noImplicitAny": true,
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"declaration": false,
|
|
22
|
+
"sourceMap": true,
|
|
23
|
+
"types": [
|
|
24
|
+
"jest"
|
|
25
|
+
],
|
|
26
|
+
"typeRoots": [
|
|
27
|
+
"./node_modules/@types",
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"typeAcquisition": {
|
|
31
|
+
"enable": true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
jest.mock('@corva/node-api-client');
|
|
2
2
|
|
|
3
|
-
const loggerFactory = require('@corva/node-logger');
|
|
4
|
-
const { ApiClient } = require('@corva/node-api-client');
|
|
5
3
|
const Processor = require('../src/processor');
|
|
6
4
|
|
|
7
5
|
test('process event', async () => {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
6
|
+
const fakeLogger = console;
|
|
7
|
+
const fakeApiClient = {};
|
|
10
8
|
|
|
11
9
|
const processor = new Processor({
|
|
12
|
-
apiClient,
|
|
13
|
-
logger,
|
|
10
|
+
apiClient: fakeApiClient,
|
|
11
|
+
logger: fakeLogger,
|
|
14
12
|
});
|
|
15
13
|
|
|
16
14
|
const event = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
appConnectionId: 3456,
|
|
15
|
+
asset_id: 1234,
|
|
16
|
+
app_stream_id: 2345,
|
|
20
17
|
records: [
|
|
21
18
|
{
|
|
22
19
|
company_id: 1,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# testing
|
|
7
|
+
/coverage
|
|
8
|
+
|
|
9
|
+
# misc
|
|
10
|
+
.env
|
|
11
|
+
.DS_Store
|
|
12
|
+
.env.local
|
|
13
|
+
.env.development.local
|
|
14
|
+
.env.test.local
|
|
15
|
+
.env.production.local
|
|
16
|
+
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
|
|
21
|
+
*.zip
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
"description": "My Dev Center Real-Time Stream Data App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json
|
|
7
|
+
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json $LOCKFILE manifest.json index.js src",
|
|
8
8
|
"test": "npm audit --production && npm run unit",
|
|
9
9
|
"unit": "jest"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@corva/node-sdk": "^
|
|
12
|
+
"@corva/node-sdk": "^5.3.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"jest": "^
|
|
15
|
+
"jest": "^27.2.0"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Dev Center Node.js TypeScript Real-Time Stream Data App
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
### 1. Install Dependencies
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### 2. Run Tests
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm test
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 3. Build
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 4. Deploy
|
|
24
|
+
|
|
25
|
+
Run `npm run bundle` to create a zip package that can be uploaded to Dev Center
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Processor } from '../lib/processor';
|
|
2
|
+
import type { HandlerContext } from '@corva/node-sdk';
|
|
3
|
+
import { NormalizedStreamLambdaEvent } from '@corva/node-sdk/lib/lambdas/interfaces';
|
|
4
|
+
|
|
5
|
+
test('process event', async () => {
|
|
6
|
+
const fakeLogger = console as unknown as HandlerContext['logger'];
|
|
7
|
+
const fakeApiClient = {} as unknown as HandlerContext['api'];
|
|
8
|
+
|
|
9
|
+
const processor = new Processor(fakeApiClient, fakeLogger);
|
|
10
|
+
|
|
11
|
+
const event = {
|
|
12
|
+
asset_id: 1234,
|
|
13
|
+
app_stream_id: 2345,
|
|
14
|
+
records: [
|
|
15
|
+
{
|
|
16
|
+
company_id: 1,
|
|
17
|
+
asset_id: 1234,
|
|
18
|
+
timestamp: 157829400,
|
|
19
|
+
data: { hole_depth: 1000 },
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
company_id: 1,
|
|
23
|
+
asset_id: 1234,
|
|
24
|
+
timestamp: 157829401,
|
|
25
|
+
data: { hole_depth: 1001 },
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
company_id: 1,
|
|
29
|
+
asset_id: 1234,
|
|
30
|
+
timestamp: 157829402,
|
|
31
|
+
data: { hole_depth: 1001 },
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
company_id: 1,
|
|
35
|
+
asset_id: 1234,
|
|
36
|
+
timestamp: 157829403,
|
|
37
|
+
data: { hole_depth: 1001.5 },
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
} as unknown as NormalizedStreamLambdaEvent<unknown>;
|
|
41
|
+
|
|
42
|
+
await processor.process(event);
|
|
43
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# testing
|
|
7
|
+
/coverage
|
|
8
|
+
|
|
9
|
+
# misc
|
|
10
|
+
.env
|
|
11
|
+
.DS_Store
|
|
12
|
+
.env.local
|
|
13
|
+
.env.development.local
|
|
14
|
+
.env.test.local
|
|
15
|
+
.env.production.local
|
|
16
|
+
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
|
|
21
|
+
**/*.js
|
|
22
|
+
**/*.js.map
|
|
23
|
+
**/.d.ts
|
|
24
|
+
|
|
25
|
+
*.zip
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Corva } from '@corva/node-sdk';
|
|
2
|
+
import { Processor } from './lib/processor';
|
|
3
|
+
|
|
4
|
+
export const handler = new Corva().stream(async (event, context) => {
|
|
5
|
+
const processor = new Processor(context.api, context.logger);
|
|
6
|
+
|
|
7
|
+
await processor.process(event);
|
|
8
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HandlerContext } from '@corva/node-sdk';
|
|
2
|
+
import { NormalizedStreamLambdaEvent } from '@corva/node-sdk/lib/lambdas/interfaces';
|
|
3
|
+
|
|
4
|
+
export class Processor {
|
|
5
|
+
constructor(private apiClient: HandlerContext['api'], private logger: HandlerContext['logger']) {}
|
|
6
|
+
|
|
7
|
+
async process(event: NormalizedStreamLambdaEvent<unknown>) {
|
|
8
|
+
const { asset_id, records } = event;
|
|
9
|
+
|
|
10
|
+
if (!records.length) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this.logger.info(`Processing event. Asset: ${asset_id}. Received ${records.length} records.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-dev-center-real-time-stream-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "My Dev Center Real-Time Stream Data App",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json $LOCKFILE manifest.json index.js lib -x '*.ts'",
|
|
8
|
+
"test": "npm audit --production && npm run unit",
|
|
9
|
+
"build": "tsc -p tsconfig.build.json",
|
|
10
|
+
"unit": "jest"
|
|
11
|
+
},
|
|
12
|
+
"jest": {
|
|
13
|
+
"moduleFileExtensions": [
|
|
14
|
+
"js",
|
|
15
|
+
"json",
|
|
16
|
+
"ts"
|
|
17
|
+
],
|
|
18
|
+
"rootDir": ".",
|
|
19
|
+
"testEnvironment": "node",
|
|
20
|
+
"testMatch": [
|
|
21
|
+
"**/*.spec.ts"
|
|
22
|
+
],
|
|
23
|
+
"transform": {
|
|
24
|
+
"^.+\\.ts$": "ts-jest"
|
|
25
|
+
},
|
|
26
|
+
"verbose": true
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@corva/node-sdk": "^5.3.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^27.0.1",
|
|
33
|
+
"jest": "^27.2.1",
|
|
34
|
+
"ts-jest": "^27.0.5",
|
|
35
|
+
"typescript": "^4.4.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": [
|
|
3
|
+
"lib/**/*.ts",
|
|
4
|
+
"__tests__"
|
|
5
|
+
],
|
|
6
|
+
"exclude": [
|
|
7
|
+
"node_modules"
|
|
8
|
+
],
|
|
9
|
+
"compilerOptions": {
|
|
10
|
+
"target": "es2019",
|
|
11
|
+
"skipLibCheck": false,
|
|
12
|
+
"baseUrl": "./",
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"checkJs": false,
|
|
17
|
+
"module": "commonjs",
|
|
18
|
+
"alwaysStrict": true,
|
|
19
|
+
"noImplicitAny": true,
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"declaration": false,
|
|
22
|
+
"sourceMap": true,
|
|
23
|
+
"types": [
|
|
24
|
+
"jest"
|
|
25
|
+
],
|
|
26
|
+
"typeRoots": [
|
|
27
|
+
"./node_modules/@types",
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"typeAcquisition": {
|
|
31
|
+
"enable": true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Processor = require('../src/processor');
|
|
2
|
+
|
|
3
|
+
test('process event', async () => {
|
|
4
|
+
const fakeLogger = console;
|
|
5
|
+
const fakeApiClient = {};
|
|
6
|
+
|
|
7
|
+
const event = {
|
|
8
|
+
asset_id: 123,
|
|
9
|
+
company_id: 1234,
|
|
10
|
+
properties: {
|
|
11
|
+
foo: 'bar',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const processor = new Processor({ logger: fakeLogger, apiClient: fakeApiClient });
|
|
16
|
+
|
|
17
|
+
await processor.process({ event });
|
|
18
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# testing
|
|
7
|
+
/coverage
|
|
8
|
+
|
|
9
|
+
# misc
|
|
10
|
+
.env
|
|
11
|
+
.DS_Store
|
|
12
|
+
.env.local
|
|
13
|
+
.env.development.local
|
|
14
|
+
.env.test.local
|
|
15
|
+
.env.production.local
|
|
16
|
+
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
|
|
21
|
+
*.zip
|
|
@@ -2,7 +2,7 @@ const { Corva } = require('@corva/node-sdk');
|
|
|
2
2
|
const Processor = require('./src/processor');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @param {import('@corva/node-sdk').
|
|
5
|
+
* @param {import('@corva/node-sdk').Task} event
|
|
6
6
|
* @param {import('@corva/node-sdk').HandlerContext} context
|
|
7
7
|
*/
|
|
8
8
|
exports.handler = new Corva().task((event, context) => {
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
"description": "My Dev Center Task Data App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json
|
|
7
|
+
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json $LOCKFILE manifest.json index.js src",
|
|
8
8
|
"test": "npm audit --production && npm run unit",
|
|
9
9
|
"unit": "jest"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@corva/node-sdk": "^
|
|
12
|
+
"@corva/node-sdk": "^5.3.1"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"jest": "^
|
|
15
|
+
"jest": "^27.2.0"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Dev Center Node.js Task Data App
|
|
2
|
+
|
|
3
|
+
## Getting started
|
|
4
|
+
|
|
5
|
+
### 1. Install Dependencies
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### 2. Run Tests
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm test
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 3. Build
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 4. Deploy
|
|
24
|
+
|
|
25
|
+
Run `npm run bundle` to create a zip package that can be uploaded to Dev Center
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HandlerContext, Task, TaskState } from '@corva/node-sdk';
|
|
2
|
+
import { Processor } from '../src/processor';
|
|
3
|
+
|
|
4
|
+
test('process event', async () => {
|
|
5
|
+
const fakeLogger = console as unknown as HandlerContext['logger'];
|
|
6
|
+
const fakeApiClient = {} as unknown as HandlerContext['api'];
|
|
7
|
+
|
|
8
|
+
const event: Task<{
|
|
9
|
+
foo: string;
|
|
10
|
+
}> = {
|
|
11
|
+
id: 'id',
|
|
12
|
+
state: TaskState.Running,
|
|
13
|
+
fail_reason: null,
|
|
14
|
+
asset_id: 123,
|
|
15
|
+
company_id: 1234,
|
|
16
|
+
properties: {
|
|
17
|
+
foo: 'bar',
|
|
18
|
+
},
|
|
19
|
+
document_bucket: 'test',
|
|
20
|
+
payload: null,
|
|
21
|
+
app_id: 42,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const processor = new Processor(fakeApiClient, fakeLogger);
|
|
25
|
+
|
|
26
|
+
await processor.process(event);
|
|
27
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# testing
|
|
7
|
+
/coverage
|
|
8
|
+
|
|
9
|
+
# misc
|
|
10
|
+
.env
|
|
11
|
+
.DS_Store
|
|
12
|
+
.env.local
|
|
13
|
+
.env.development.local
|
|
14
|
+
.env.test.local
|
|
15
|
+
.env.production.local
|
|
16
|
+
|
|
17
|
+
npm-debug.log*
|
|
18
|
+
yarn-debug.log*
|
|
19
|
+
yarn-error.log*
|
|
20
|
+
|
|
21
|
+
**/*.js
|
|
22
|
+
**/*.js.map
|
|
23
|
+
**/.d.ts
|
|
24
|
+
|
|
25
|
+
*.zip
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-dev-center-task-app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "My Dev Center Task Data App",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"bundle": "zip -r $npm_package_name-$npm_package_version.zip package.json $LOCKFILE manifest.json index.js lib -x '*.ts'",
|
|
8
|
+
"test": "npm audit --production && npm run unit",
|
|
9
|
+
"build": "tsc -p tsconfig.build.json",
|
|
10
|
+
"unit": "jest"
|
|
11
|
+
},
|
|
12
|
+
"jest": {
|
|
13
|
+
"moduleFileExtensions": [
|
|
14
|
+
"js",
|
|
15
|
+
"json",
|
|
16
|
+
"ts"
|
|
17
|
+
],
|
|
18
|
+
"rootDir": ".",
|
|
19
|
+
"testEnvironment": "node",
|
|
20
|
+
"testMatch": [
|
|
21
|
+
"**/*.spec.ts"
|
|
22
|
+
],
|
|
23
|
+
"transform": {
|
|
24
|
+
"^.+\\.ts$": "ts-jest"
|
|
25
|
+
},
|
|
26
|
+
"verbose": true
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@corva/node-sdk": "^5.3.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^27.0.1",
|
|
33
|
+
"jest": "^27.2.1",
|
|
34
|
+
"ts-jest": "^27.0.5",
|
|
35
|
+
"typescript": "^4.4.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HandlerContext, Task } from '@corva/node-sdk';
|
|
2
|
+
|
|
3
|
+
export class Processor {
|
|
4
|
+
constructor(private apiClient: HandlerContext['api'], private logger: HandlerContext['logger']) {}
|
|
5
|
+
|
|
6
|
+
async process(event: Task) {
|
|
7
|
+
this.logger.debug({ event }, 'Event');
|
|
8
|
+
|
|
9
|
+
const { asset_id: assetId, company_id: companyId } = event;
|
|
10
|
+
|
|
11
|
+
this.logger.info(`Processing event. Asset: ${assetId}`);
|
|
12
|
+
}
|
|
13
|
+
}
|