@corva/create-app 0.40.0-1 → 0.41.0-1
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/README.md +18 -19
- package/bin/cca.js +5 -0
- package/bin/create-corva-app.cjs +14 -0
- package/lib/bump-version.option.js +17 -8
- package/lib/constants/cli.js +5 -11
- package/lib/constants/manifest.js +10 -22
- package/lib/constants/messages.js +4 -10
- package/lib/constants/package.js +6 -8
- package/lib/flow.js +12 -10
- package/lib/flows/lib/api.js +153 -84
- package/lib/flows/lib/create-zip-archive.js +7 -7
- package/lib/flows/lib/json.js +8 -8
- package/lib/flows/lib/manifest.js +5 -7
- package/lib/flows/lib/step-error.js +1 -3
- package/lib/flows/prepare.js +2 -4
- package/lib/flows/release.js +18 -10
- package/lib/flows/rerun.js +5 -7
- package/lib/flows/steps/prepare-load-app-files.js +3 -7
- package/lib/flows/steps/release/add-label.js +11 -0
- package/lib/flows/steps/release/add-notes.js +10 -0
- package/lib/flows/steps/release/get-config.js +37 -0
- package/lib/flows/steps/release/prepare-data.js +10 -0
- package/lib/flows/steps/release/publish.js +9 -0
- package/lib/flows/steps/release/remove-failed-upload.js +20 -0
- package/lib/flows/steps/release/upload-zip-to-corva.js +25 -0
- package/lib/flows/steps/release/wait-for-build.js +29 -0
- package/lib/flows/steps/rerun-create-task.js +22 -15
- package/lib/flows/steps/rerun-prepare-data.js +150 -127
- package/lib/flows/steps/rerun.js +3 -7
- package/lib/flows/steps/zip-cleanup.js +6 -6
- package/lib/flows/steps/zip-create-archive.js +5 -5
- package/lib/flows/steps/zip-file-list-resolve.js +34 -29
- package/lib/flows/steps/zip-prepare.js +6 -8
- package/lib/flows/steps/zip.js +5 -9
- package/lib/flows/zip-simple.js +2 -4
- package/lib/flows/zip.js +3 -5
- package/lib/helpers/logger.js +13 -5
- package/lib/helpers/manifest.js +6 -10
- package/lib/helpers/resolve-app-runtime.js +47 -45
- package/lib/helpers/utils.js +4 -9
- package/lib/helpers/versioning.js +6 -12
- package/lib/{index.js → main.js} +80 -89
- package/lib/scripts/utils/version.js +10 -12
- package/package.json +5 -3
- package/bin/create-corva-app.js +0 -5
- package/lib/app.js +0 -9
- package/lib/flows/steps/release-get-app-key.js +0 -16
- package/lib/flows/steps/release-get-config.js +0 -37
- package/lib/flows/steps/release-upload-zip-to-corva.js +0 -25
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Apps generator for [corva.ai](https://corva.ai).
|
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
7
|
-
- NodeJs
|
|
7
|
+
- NodeJs >= 16.14.0 (https://nodejs.org/en/download/)
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -46,26 +46,20 @@ Options:
|
|
|
46
46
|
--appKey [string] Enter the App Key (default: "app.key-goes-here")
|
|
47
47
|
--appName [string] Enter the App Name
|
|
48
48
|
--appType [string] Choose the App Type (choices: "ui", "scheduler", "stream", "task", default: "ui")
|
|
49
|
-
--bump-version <string> DEPRECATED Use with zip or release command instead (choices: "major", "minor", "patch", "skip")
|
|
50
49
|
--category [string] Enter category (default: "")
|
|
51
50
|
--cronString [string] Provide CRON string for the scheduler (default: "*/5 * * * *")
|
|
52
51
|
--depthMilestone [number] Provide depth milestone for the scheduler (default: 1)
|
|
53
52
|
--description [string] Enter description (default: "This is the description of my app. You can do great things with it!")
|
|
54
53
|
--developerIdentifier [string] Enter the Developer Identifier (default: "oandgc")
|
|
55
54
|
--developerName [string] Enter the Developer Name (default: "O&G Company")
|
|
56
|
-
--
|
|
57
|
-
--release DEPRECATED Use release command instead
|
|
58
|
-
--runtime [string] Choose runtime (choices: "ui", "nodejs12.x", "nodejs14.x", "python3.8")
|
|
55
|
+
--runtime [string] Choose runtime (choices: "ui", "nodejs16.x", "python3.8")
|
|
59
56
|
--schedulerType [number] Choose the scheduler type (choices: "1", "2", "4", default: 1)
|
|
60
57
|
--segments [string] Choose segments (choices: "drilling", "completion")
|
|
61
58
|
--summary [string] Enter summary (default: "More information about this app goes here")
|
|
62
59
|
--website [string] Enter website (default: "https://www.oandgexample.com/my-app/")
|
|
63
|
-
--silent [boolean] Only log result of the operation
|
|
64
|
-
-V, --version output the version number
|
|
65
|
-
-h, --help display help for command
|
|
66
60
|
-p, --packageManager [string] Please select the desired package manager (choices: "yarn", "npm", default: "yarn")
|
|
67
61
|
-t, --useTypescript [boolean] Would you like to use TypesScript? (default: false)
|
|
68
|
-
|
|
62
|
+
--silent [boolean] Only log result of the operation (default: false)
|
|
69
63
|
```
|
|
70
64
|
|
|
71
65
|
### Examples
|
|
@@ -98,13 +92,13 @@ Usage: create-corva-app zip [options] <project-directory> [patterns...]
|
|
|
98
92
|
Bundle app
|
|
99
93
|
|
|
100
94
|
Arguments:
|
|
101
|
-
project-directory
|
|
102
|
-
patterns
|
|
95
|
+
project-directory Project directory to work with
|
|
96
|
+
patterns Additional patterns to zip (default: [])
|
|
103
97
|
|
|
104
98
|
Options:
|
|
105
|
-
--bump-version <string>
|
|
106
|
-
--
|
|
107
|
-
|
|
99
|
+
--bump-version <string> Bump version (choices: "major", "minor", "patch", "skip")
|
|
100
|
+
--ignored-files [ignoredFiles...] Patterns to skip zip
|
|
101
|
+
--silent [boolean] Only log result of the operation (default: false)
|
|
108
102
|
```
|
|
109
103
|
|
|
110
104
|
### What is getting zipped?
|
|
@@ -170,13 +164,18 @@ Usage: create-corva-app release [options] <project-directory> [patterns...]
|
|
|
170
164
|
Release app
|
|
171
165
|
|
|
172
166
|
Arguments:
|
|
173
|
-
project-directory
|
|
174
|
-
patterns
|
|
167
|
+
project-directory Project directory to work with
|
|
168
|
+
patterns Additional patterns to zip (default: [])
|
|
175
169
|
|
|
176
170
|
Options:
|
|
177
|
-
--bump-version <string>
|
|
178
|
-
--
|
|
179
|
-
|
|
171
|
+
--bump-version <string> Bump version (choices: "major", "minor", "patch", "skip")
|
|
172
|
+
--ignored-files [string...] Patterns to skip zip (default: [])
|
|
173
|
+
--env [string] Environment to use (choices: "qa", "staging", "production", default: "qa")
|
|
174
|
+
--api-key [string] Pre generated API key for authorization during app upload
|
|
175
|
+
--notes [string] Add custom notes to published app
|
|
176
|
+
--label [string] Put a label on the release (choices: "BETA", "STABLE")
|
|
177
|
+
--remove-on-fail [boolean] Remove release if it fails during deployment (default: false)
|
|
178
|
+
--silent [boolean] Only log result of the operation (default: false)
|
|
180
179
|
```
|
|
181
180
|
|
|
182
181
|
### Examples
|
package/bin/cca.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
const { resolve } = require('path');
|
|
5
|
+
|
|
6
|
+
const cmd = [
|
|
7
|
+
'node',
|
|
8
|
+
'--no-warnings',
|
|
9
|
+
'--experimental-json-modules',
|
|
10
|
+
resolve(__dirname, 'cca.js'),
|
|
11
|
+
...process.argv.slice(2),
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
spawnSync(cmd.join(' '), { stdio: 'inherit', shell: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Option, InvalidArgumentError } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import semver from 'semver';
|
|
4
4
|
|
|
5
5
|
const flags = '--bump-version <string>';
|
|
6
6
|
const description = 'Bump version';
|
|
@@ -17,14 +17,23 @@ function argParser(value, previous) {
|
|
|
17
17
|
.join(', ')} or a valid semver version.`
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
|
-
const bumpVersionOption = new Option(flags, description)
|
|
20
|
+
export const bumpVersionOption = new Option(flags, description)
|
|
21
|
+
.choices(choices)
|
|
22
|
+
.argParser(argParser);
|
|
23
|
+
|
|
24
|
+
export const apiKeyOption = new Option('--api-key [string]',
|
|
25
|
+
'Pre generated API key for authorization during app upload')
|
|
21
26
|
|
|
22
|
-
const
|
|
27
|
+
export const envOption = new Option('--env [string]', 'Environment to use')
|
|
28
|
+
.choices(['qa', 'staging', 'production'])
|
|
29
|
+
.default('qa')
|
|
30
|
+
|
|
31
|
+
export const silentOption = new Option('--silent [boolean]', 'Only log result of the operation').default(false)
|
|
32
|
+
|
|
33
|
+
export const bumpVersionOptionDeprecated = new Option(
|
|
23
34
|
flags,
|
|
24
35
|
chalk.bgYellow`DEPRECATED` +
|
|
25
|
-
|
|
36
|
+
` Use with ${chalk.cyan`zip`} or ${chalk.cyan`release`} command instead`
|
|
26
37
|
)
|
|
27
38
|
.choices(choices)
|
|
28
39
|
.argParser(argParser);
|
|
29
|
-
|
|
30
|
-
module.exports = { bumpVersionOption, bumpVersionOptionDeprecated };
|
package/lib/constants/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const APP_RUNTIMES = {
|
|
1
|
+
export const APP_RUNTIMES = {
|
|
2
2
|
UI: 'ui',
|
|
3
|
-
NODE12: 'nodejs12.x',
|
|
4
|
-
NODE14: 'nodejs14.x',
|
|
3
|
+
// NODE12: 'nodejs12.x',
|
|
4
|
+
// NODE14: 'nodejs14.x',
|
|
5
5
|
NODE16: 'nodejs16.x',
|
|
6
6
|
PYTHON3: 'python3.8',
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const TEMPLATE_TYPES = {
|
|
9
|
+
export const TEMPLATE_TYPES = {
|
|
10
10
|
UI: 'js',
|
|
11
11
|
UI_TS: 'ts',
|
|
12
12
|
NODE: 'node',
|
|
@@ -14,15 +14,9 @@ const TEMPLATE_TYPES = {
|
|
|
14
14
|
PYTHON: 'python',
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const APP_TYPES = {
|
|
17
|
+
export const APP_TYPES = {
|
|
18
18
|
UI: 'ui',
|
|
19
19
|
SCHEDULER: 'scheduler',
|
|
20
20
|
STREAM: 'stream',
|
|
21
21
|
TASK: 'task',
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
module.exports = {
|
|
25
|
-
TEMPLATE_TYPES,
|
|
26
|
-
APP_RUNTIMES,
|
|
27
|
-
APP_TYPES,
|
|
28
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { APP_RUNTIMES, APP_TYPES, TEMPLATE_TYPES } from './cli.js';
|
|
2
2
|
|
|
3
|
-
const defaultManifest = {
|
|
3
|
+
export const defaultManifest = {
|
|
4
4
|
format: 1,
|
|
5
5
|
license: {
|
|
6
6
|
type: 'MIT',
|
|
@@ -32,7 +32,7 @@ const defaultManifest = {
|
|
|
32
32
|
datasets: {},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
const defaultUIAppManifest = {
|
|
35
|
+
export const defaultUIAppManifest = {
|
|
36
36
|
application: {
|
|
37
37
|
ui: { initial_size: { w: 4, h: 10 } },
|
|
38
38
|
},
|
|
@@ -45,7 +45,7 @@ const defaultUIAppManifest = {
|
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
const defaultDataAppNodeManifest = {
|
|
48
|
+
export const defaultDataAppNodeManifest = {
|
|
49
49
|
settings: {
|
|
50
50
|
entrypoint: {
|
|
51
51
|
file: 'index.js',
|
|
@@ -57,7 +57,7 @@ const defaultDataAppNodeManifest = {
|
|
|
57
57
|
},
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const defaultDataAppPythonManifest = {
|
|
60
|
+
export const defaultDataAppPythonManifest = {
|
|
61
61
|
settings: {
|
|
62
62
|
entrypoint: {
|
|
63
63
|
file: 'lambda_function',
|
|
@@ -69,7 +69,7 @@ const defaultDataAppPythonManifest = {
|
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
const getManifestMandatoryKeys = (opts) => {
|
|
72
|
+
export const getManifestMandatoryKeys = (opts) => {
|
|
73
73
|
const keys = manifestOptions(opts.projectName).reduce((acc, option) => {
|
|
74
74
|
if (option.required) {
|
|
75
75
|
acc.push(option.name);
|
|
@@ -99,11 +99,11 @@ const getManifestMandatoryKeys = (opts) => {
|
|
|
99
99
|
return keys;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
const SCHEDULER_TYPE_NATURAL_TIME = { name: 'Natural Time', value: 1 };
|
|
103
|
-
const SCHEDULER_TYPE_DATA_TIME = { name: 'Data Time', value: 2 };
|
|
104
|
-
const SCHEDULER_TYPE_DEPTH = { name: 'Date Depth', value: 4 };
|
|
102
|
+
export const SCHEDULER_TYPE_NATURAL_TIME = { name: 'Natural Time', value: 1 };
|
|
103
|
+
export const SCHEDULER_TYPE_DATA_TIME = { name: 'Data Time', value: 2 };
|
|
104
|
+
export const SCHEDULER_TYPE_DEPTH = { name: 'Date Depth', value: 4 };
|
|
105
105
|
|
|
106
|
-
const manifestOptions = (projectName = 'Corva Dev Center App') => [
|
|
106
|
+
export const manifestOptions = (projectName = 'Corva Dev Center App') => [
|
|
107
107
|
{ name: 'developerName', message: 'Enter the Developer Name', default: 'O&G Company' },
|
|
108
108
|
{ name: 'developerIdentifier', message: 'Enter the Developer Identifier', default: 'oandgc' },
|
|
109
109
|
{
|
|
@@ -210,15 +210,3 @@ const manifestOptions = (projectName = 'Corva Dev Center App') => [
|
|
|
210
210
|
default: false,
|
|
211
211
|
},
|
|
212
212
|
];
|
|
213
|
-
|
|
214
|
-
module.exports = {
|
|
215
|
-
defaultManifest,
|
|
216
|
-
defaultUIAppManifest,
|
|
217
|
-
defaultDataAppNodeManifest,
|
|
218
|
-
defaultDataAppPythonManifest,
|
|
219
|
-
manifestOptions,
|
|
220
|
-
getManifestMandatoryKeys,
|
|
221
|
-
SCHEDULER_TYPE_NATURAL_TIME,
|
|
222
|
-
SCHEDULER_TYPE_DATA_TIME,
|
|
223
|
-
SCHEDULER_TYPE_DEPTH,
|
|
224
|
-
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
2
|
|
|
3
|
-
const SUCCESS_ICON = ' ✅ \n';
|
|
4
|
-
const ERROR_ICON = ' ❌ \n';
|
|
3
|
+
export const SUCCESS_ICON = ' ✅ \n';
|
|
4
|
+
export const ERROR_ICON = ' ❌ \n';
|
|
5
5
|
|
|
6
|
-
const RELEASE = {
|
|
6
|
+
export const RELEASE = {
|
|
7
7
|
createZip: 'Creating zip archive...\n',
|
|
8
8
|
createZipError: 'Could not create zip archive.',
|
|
9
9
|
createZipSuccess: `Zip archive has been created ${SUCCESS_ICON}`,
|
|
@@ -13,9 +13,3 @@ const RELEASE = {
|
|
|
13
13
|
getAppKeyError: "Could not find app key. Please make sure it's defined in manifest.json",
|
|
14
14
|
uploadApp: 'Uploading app...',
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
RELEASE,
|
|
19
|
-
SUCCESS_ICON,
|
|
20
|
-
ERROR_ICON,
|
|
21
|
-
};
|
package/lib/constants/package.js
CHANGED
|
@@ -129,13 +129,13 @@ const nodeTsYarnPackage = {
|
|
|
129
129
|
scripts: nodeTsYarnScripts,
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
const extendWithTsConfig = (
|
|
133
|
-
|
|
132
|
+
const extendWithTsConfig = (packageJson, version) => {
|
|
133
|
+
packageJson.devDependencies = {
|
|
134
134
|
[`@tsconfig/node${version}`]: `^${version === '12' ? '1.0.9' : '1.0.1'}`,
|
|
135
|
-
...
|
|
135
|
+
...packageJson.devDependencies,
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
return
|
|
138
|
+
return packageJson;
|
|
139
139
|
};
|
|
140
140
|
|
|
141
141
|
const defaults = {
|
|
@@ -169,8 +169,6 @@ const defaults = {
|
|
|
169
169
|
},
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return defaults[runtime.language][runtime.packageManager][manifest.type](runtime);
|
|
175
|
-
},
|
|
172
|
+
export const getDefaultsForPackageJson = (manifest, runtime) => {
|
|
173
|
+
return defaults[runtime.language][runtime.packageManager][manifest.type](runtime);
|
|
176
174
|
};
|
package/lib/flow.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { SUCCESS_ICON } from './constants/messages.js';
|
|
3
|
+
import { resolve, sep } from 'node:path';
|
|
4
|
+
import { logger } from './helpers/logger.js';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const { SUCCESS_ICON } = require('./constants/messages');
|
|
5
|
-
const { resolve, sep } = require('path');
|
|
6
|
-
const logger = require('./helpers/logger');
|
|
6
|
+
import Debug from 'debug';
|
|
7
7
|
|
|
8
|
-
const debug =
|
|
8
|
+
const debug = Debug('cca:flow');
|
|
9
9
|
|
|
10
|
-
const runFlow = async (flow, context, indent = '') => {
|
|
10
|
+
export const runFlow = async (flow, context, indent = '') => {
|
|
11
11
|
logger.write(
|
|
12
|
-
`${indent}Running ${chalk.cyan(flow.name)} in ${chalk.cyan(
|
|
12
|
+
`${indent}Running ${chalk.cyan(flow.name)} in ${chalk.cyan(
|
|
13
|
+
resolve(context.dirName).split(sep).pop()
|
|
14
|
+
)}\n`
|
|
13
15
|
);
|
|
14
16
|
|
|
17
|
+
context.progress = () => logger.write('.')
|
|
18
|
+
|
|
15
19
|
const result = await runSteps(flow.steps, context, indent + ' ');
|
|
16
20
|
|
|
17
21
|
logger.write(`${indent}Done!` + SUCCESS_ICON);
|
|
@@ -43,5 +47,3 @@ const runSteps = async (steps = [], context = {}, indent = '') => {
|
|
|
43
47
|
|
|
44
48
|
return context;
|
|
45
49
|
};
|
|
46
|
-
|
|
47
|
-
module.exports = { runFlow };
|
package/lib/flows/lib/api.js
CHANGED
|
@@ -1,50 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import got from 'got';
|
|
2
|
+
import Debug from 'debug';
|
|
3
|
+
import { StepError } from './step-error.js';
|
|
4
|
+
import _ from 'lodash/fp.js';
|
|
5
|
+
|
|
6
|
+
const debug = Debug('cca:api');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Connect to Corva API
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export class Api {
|
|
13
|
+
/**
|
|
14
|
+
* @type {import('got').Got}
|
|
15
|
+
*/
|
|
16
|
+
#api;
|
|
2
17
|
|
|
3
|
-
/**
|
|
4
|
-
* Connect to Corva API
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
class Api {
|
|
8
18
|
constructor(envName, apiKey, authToken = null) {
|
|
9
|
-
|
|
10
|
-
envName === 'production' ? '' : `.${envName}`
|
|
11
|
-
}.corva.ai`;
|
|
19
|
+
const prefixUrl = `https://api${envName === 'production' ? '' : `.${envName}`}.corva.ai`;
|
|
12
20
|
|
|
13
|
-
this
|
|
21
|
+
this.#api = got.extend({
|
|
22
|
+
prefixUrl,
|
|
23
|
+
retry: { limit: 0 },
|
|
14
24
|
headers: {
|
|
15
|
-
'Authorization': authToken ? `Bearer ${authToken}`
|
|
25
|
+
'Authorization': authToken ? `Bearer ${authToken}` : `API ${apiKey}`,
|
|
16
26
|
'Content-Type': 'application/json',
|
|
17
27
|
'Accept': 'application/json',
|
|
18
28
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Get api url
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
26
|
-
*
|
|
27
|
-
* @param {string} path
|
|
28
|
-
*
|
|
29
|
-
* @returns {string}
|
|
30
|
-
*/
|
|
31
|
-
getUrl(path) {
|
|
32
|
-
return `${this.baseURL}${path}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Send api request
|
|
37
|
-
*
|
|
38
|
-
* @private
|
|
39
|
-
*
|
|
40
|
-
* @param {string} path
|
|
41
|
-
* @param {string} method
|
|
42
|
-
* @param {object} data
|
|
43
|
-
*
|
|
44
|
-
* @returns {object}
|
|
45
|
-
*/
|
|
46
|
-
sendRequest(method, url, data = null) {
|
|
47
|
-
return data ? axios[method](url, data, this.config) : axios[method](url, this.config);
|
|
29
|
+
hooks: {
|
|
30
|
+
beforeRequest: [debug]
|
|
31
|
+
}
|
|
32
|
+
})
|
|
48
33
|
}
|
|
49
34
|
|
|
50
35
|
/**
|
|
@@ -57,10 +42,10 @@ class Api {
|
|
|
57
42
|
* @returns {object}
|
|
58
43
|
*/
|
|
59
44
|
async getAppByKey(appKey) {
|
|
60
|
-
const
|
|
61
|
-
|
|
45
|
+
const { data: [app] } = await this.#api.get('v2/apps', {
|
|
46
|
+
searchParams: { per_page: 2, search: appKey }
|
|
47
|
+
}).json();
|
|
62
48
|
|
|
63
|
-
const app = response.data.data[0];
|
|
64
49
|
if (!app || app.attributes.app_key != appKey) {
|
|
65
50
|
throw new Error(`App with key - ${appKey}, not exist`);
|
|
66
51
|
}
|
|
@@ -78,16 +63,13 @@ class Api {
|
|
|
78
63
|
* @returns {object}
|
|
79
64
|
*/
|
|
80
65
|
async getAppDatasetsOperationWrite(appId) {
|
|
81
|
-
const
|
|
82
|
-
`/v2/apps/${appId}/app_datasets?dataset_operation=write&fields[]=app_dataset.dataset_name`
|
|
83
|
-
);
|
|
84
|
-
const response = await this.sendRequest('get', url);
|
|
66
|
+
const { data } = await this.#api.get(`v2/apps/${appId}/app_datasets?dataset_operation=write&fields[]=app_dataset.dataset_name`).json();
|
|
85
67
|
|
|
86
|
-
if (!
|
|
87
|
-
throw new Error(`App with ID - ${appId}, has
|
|
68
|
+
if (!data.length) {
|
|
69
|
+
throw new Error(`App with ID - ${appId}, has no datasets`);
|
|
88
70
|
}
|
|
89
71
|
|
|
90
|
-
return
|
|
72
|
+
return data;
|
|
91
73
|
}
|
|
92
74
|
|
|
93
75
|
/**
|
|
@@ -97,16 +79,14 @@ class Api {
|
|
|
97
79
|
*
|
|
98
80
|
* @param {string} assetId
|
|
99
81
|
*
|
|
100
|
-
* @returns {object[]}
|
|
82
|
+
* @returns {Promise<object[]>}
|
|
101
83
|
*/
|
|
102
84
|
async getAssetById(assetId) {
|
|
103
|
-
const
|
|
104
|
-
const response = await this.sendRequest('get', url);
|
|
85
|
+
const { data } = await this.#api.get(`v2/assets/${assetId}`).json();
|
|
105
86
|
|
|
106
|
-
return
|
|
87
|
+
return data;
|
|
107
88
|
}
|
|
108
89
|
|
|
109
|
-
|
|
110
90
|
/**
|
|
111
91
|
* Get asset streams
|
|
112
92
|
*
|
|
@@ -116,15 +96,20 @@ class Api {
|
|
|
116
96
|
*
|
|
117
97
|
* @returns {object[]}
|
|
118
98
|
*/
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
99
|
+
async getStreamByAssetId(assetId) {
|
|
100
|
+
const data = await this.#api.get(`v1/app_streams`, {
|
|
101
|
+
searchParams: {
|
|
102
|
+
asset_id: assetId,
|
|
103
|
+
segment: 'drilling',
|
|
104
|
+
status: 'complete'
|
|
105
|
+
}
|
|
106
|
+
}).json();
|
|
122
107
|
|
|
123
|
-
if (!
|
|
108
|
+
if (!data[0]) {
|
|
124
109
|
throw new Error(`Could not found streams for asset ID - ${assetId}`);
|
|
125
110
|
}
|
|
126
111
|
|
|
127
|
-
return
|
|
112
|
+
return data;
|
|
128
113
|
}
|
|
129
114
|
|
|
130
115
|
/**
|
|
@@ -137,18 +122,13 @@ class Api {
|
|
|
137
122
|
* @returns {object[]}
|
|
138
123
|
*/
|
|
139
124
|
async getWellByAssetId(assetId) {
|
|
140
|
-
const
|
|
141
|
-
assets: [assetId],
|
|
142
|
-
};
|
|
125
|
+
const { wells } = await this.#api.post('v2/assets/resolve', { json: { assets: [assetId], } }).json();
|
|
143
126
|
|
|
144
|
-
|
|
145
|
-
const response = await this.sendRequest('post', url, data);
|
|
146
|
-
|
|
147
|
-
if (!response.data.wells.length) {
|
|
127
|
+
if (!wells.length) {
|
|
148
128
|
throw new Error(`Could not found wells by asset ID - ${assetId}`);
|
|
149
129
|
}
|
|
150
130
|
|
|
151
|
-
return
|
|
131
|
+
return wells;
|
|
152
132
|
}
|
|
153
133
|
|
|
154
134
|
/**
|
|
@@ -165,7 +145,7 @@ class Api {
|
|
|
165
145
|
* @returns {object}
|
|
166
146
|
*/
|
|
167
147
|
async queueAppRun(appId, version, wellId, appDatasetsNames, streamId) {
|
|
168
|
-
const
|
|
148
|
+
const json = {
|
|
169
149
|
app_run: {
|
|
170
150
|
app_stream_id: streamId,
|
|
171
151
|
well_id: wellId,
|
|
@@ -181,9 +161,9 @@ class Api {
|
|
|
181
161
|
},
|
|
182
162
|
};
|
|
183
163
|
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
return
|
|
164
|
+
const { data } = await this.#api.post(`v2/apps/${appId}/app_runs`, { json }).json();
|
|
165
|
+
|
|
166
|
+
return data;
|
|
187
167
|
}
|
|
188
168
|
|
|
189
169
|
/**
|
|
@@ -195,11 +175,10 @@ class Api {
|
|
|
195
175
|
*
|
|
196
176
|
* @returns {object[]}
|
|
197
177
|
*/
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
const response = await this.sendRequest('get', url);
|
|
178
|
+
async getAppRuns(appId) {
|
|
179
|
+
const { data } = await this.#api.get(`v2/apps/${appId}/app_runs?page=1&per_page=500&status[]=pending&status[]=in_progress&status[]=running`).json();
|
|
201
180
|
|
|
202
|
-
return
|
|
181
|
+
return data;
|
|
203
182
|
}
|
|
204
183
|
|
|
205
184
|
/**
|
|
@@ -212,14 +191,104 @@ class Api {
|
|
|
212
191
|
*
|
|
213
192
|
* @returns
|
|
214
193
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
194
|
+
async uploadPackages(appKey, formData) {
|
|
195
|
+
const uploadURL = `v2/apps/${appKey}/packages/upload`;
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
const { data } = await this.#api.post(uploadURL, {
|
|
199
|
+
headers: formData.getHeaders(),
|
|
200
|
+
body: formData,
|
|
201
|
+
}).json();
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
id: data.id,
|
|
205
|
+
status: data.attributes.status,
|
|
220
206
|
};
|
|
221
|
-
|
|
207
|
+
} catch (e) {
|
|
208
|
+
throw new StepError(
|
|
209
|
+
`${JSON.parse(e.response.body).message || ''} \nPOST: ${uploadURL} failed.`,
|
|
210
|
+
{ cause: e }
|
|
211
|
+
);
|
|
212
|
+
|
|
222
213
|
}
|
|
223
|
-
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @param {string} appId
|
|
219
|
+
* @param {string} id
|
|
220
|
+
* @param {string} notes
|
|
221
|
+
*
|
|
222
|
+
* @returns { Promise<{id: number, status: string}>}
|
|
223
|
+
*/
|
|
224
|
+
async addNotes(appId, id, notes) {
|
|
225
|
+
const { data } = await this.#api.patch(`v2/apps/${appId}/packages/${id}`, {
|
|
226
|
+
json: { package: { notes } },
|
|
227
|
+
}).json();
|
|
224
228
|
|
|
225
|
-
|
|
229
|
+
return {
|
|
230
|
+
id: data.id,
|
|
231
|
+
status: data.attributes.status,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @param {string} appId
|
|
237
|
+
* @param {string} uploadId
|
|
238
|
+
*
|
|
239
|
+
* @returns { Promise<{id: number, status: string}>}
|
|
240
|
+
*/
|
|
241
|
+
async checkApp(appId, uploadId) {
|
|
242
|
+
const { data } = await this.#api.get(`v2/apps/${appId}/packages/${uploadId}`).json();
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
id: data.id,
|
|
246
|
+
status: data.attributes.status,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @param {string} appId
|
|
252
|
+
* @param {string} uploadId
|
|
253
|
+
*
|
|
254
|
+
* @returns { Promise<void>}
|
|
255
|
+
*/
|
|
256
|
+
deleteAppUpload(appId, uploadId) {
|
|
257
|
+
return this.#api.del(`v2/apps/${appId}/packages/${uploadId}`).json();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @param {string} appId
|
|
262
|
+
* @param {string} id
|
|
263
|
+
*
|
|
264
|
+
* @returns { Promise<{id: number, status: string}>}
|
|
265
|
+
*/
|
|
266
|
+
async publishApp(appId, id) {
|
|
267
|
+
console.log(`v2/apps/${appId}/packages/${id}`, {
|
|
268
|
+
json: { package: { status: 'published' } },
|
|
269
|
+
})
|
|
270
|
+
const { data } = await this.#api.patch(`v2/apps/${appId}/packages/${id}`, {
|
|
271
|
+
json: { package: { status: 'published' } },
|
|
272
|
+
}).json();
|
|
273
|
+
|
|
274
|
+
console.log('done')
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
id: data.id,
|
|
278
|
+
status: data.attributes.status,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @param {string} appId
|
|
284
|
+
* @param {string} id
|
|
285
|
+
* @param {'BETA' | 'PROD'} label
|
|
286
|
+
*
|
|
287
|
+
* @returns { Promise<{id: number, status: string}>}
|
|
288
|
+
*/
|
|
289
|
+
async putLabel(appId, id, label) {
|
|
290
|
+
await this.#api.patch(`v2/apps/${appId}/packages/${id}`, {
|
|
291
|
+
json: { package: { label } },
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|