@sentio/cli 2.0.0-rc.1 → 2.0.0-rc.11
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/lib/build.d.ts +0 -1
- package/lib/build.js +62 -50
- package/lib/build.js.map +1 -1
- package/lib/cli.js +30 -28
- package/lib/cli.js.map +1 -1
- package/lib/commands/login-server.js +31 -36
- package/lib/commands/login-server.js.map +1 -1
- package/lib/commands/run-create.js +23 -39
- package/lib/commands/run-create.js.map +1 -1
- package/lib/commands/run-login.js +28 -33
- package/lib/commands/run-login.js.map +1 -1
- package/lib/commands/run-test.d.ts +1 -0
- package/lib/commands/run-test.js +10 -0
- package/lib/commands/run-test.js.map +1 -0
- package/lib/commands/run-upload.d.ts +1 -1
- package/lib/commands/run-upload.js +62 -68
- package/lib/commands/run-upload.js.map +1 -1
- package/lib/commands/run-version.js +9 -14
- package/lib/commands/run-version.js.map +1 -1
- package/lib/config.js +4 -11
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/key.js +18 -24
- package/lib/key.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +20 -14
- package/lib/utils.js.map +1 -1
- package/package.json +18 -13
- package/src/build.ts +56 -45
- package/src/cli.ts +14 -10
- package/src/commands/login-server.ts +12 -12
- package/src/commands/run-create.ts +0 -12
- package/src/commands/run-login.ts +4 -4
- package/src/commands/run-test.ts +10 -0
- package/src/commands/run-upload.ts +16 -13
- package/src/commands/run-version.ts +1 -1
- package/src/index.ts +1 -0
- package/src/utils.ts +18 -3
- package/templates/aptos/jest.config.ts +8 -0
- package/templates/aptos/package.json +3 -6
- package/templates/aptos/src/processor.ts +3 -3
- package/templates/aptos/tsconfig.json +4 -3
- package/templates/evm/jest.config.ts +8 -0
- package/templates/evm/package.json +2 -4
- package/templates/evm/src/processor.ts +4 -5
- package/templates/evm/tsconfig.json +4 -3
- package/templates/raw/jest.config.ts +8 -0
- package/templates/raw/package.json +2 -4
- package/templates/raw/tsconfig.json +4 -3
- package/templates/solana/jest.config.ts +8 -0
- package/templates/solana/package.json +3 -6
- package/templates/solana/src/processor.ts +3 -3
- package/templates/solana/tsconfig.json +4 -3
- package/lib/webpack.config.js +0 -50
- package/src/webpack.config.js +0 -50
- package/templates/aptos/jest.config.js +0 -7
- package/templates/evm/jest.config.js +0 -7
- package/templates/raw/jest.config.js +0 -7
- package/templates/raw/yarn.lock +0 -4095
- package/templates/solana/jest.config.js +0 -7
- package/templates/solana/yarn.lock +0 -4918
package/lib/build.d.ts
CHANGED
package/lib/build.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const child_process_1 = require("child_process");
|
|
9
|
-
async function buildProcessor(onlyGen) {
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { exec } from 'child_process';
|
|
5
|
+
import * as process from 'process';
|
|
6
|
+
import { getPackageRoot } from './utils.js';
|
|
7
|
+
export async function buildProcessor(onlyGen) {
|
|
10
8
|
if (!onlyGen) {
|
|
11
9
|
await installDeps();
|
|
12
10
|
}
|
|
@@ -15,33 +13,67 @@ async function buildProcessor(onlyGen) {
|
|
|
15
13
|
await buildProcessorForTarget(onlyGen);
|
|
16
14
|
// }
|
|
17
15
|
if (!onlyGen) {
|
|
18
|
-
let
|
|
16
|
+
let tsupConfig;
|
|
19
17
|
try {
|
|
20
|
-
|
|
18
|
+
tsupConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts');
|
|
21
19
|
}
|
|
22
20
|
catch (e) {
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
console.error(chalk.red("Wrong CLI version for sdk, can't find tsup.config.ts"));
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js');
|
|
25
|
+
// await execStep('yarn tsc -p .', 'Compile')
|
|
26
|
+
await execStep(`node ${tsup} --config=${tsupConfig}`, 'Packaging');
|
|
27
|
+
const dir = fs.readdirSync(path.join(process.cwd(), 'dist'));
|
|
28
|
+
const generated = dir.filter((d) => d.endsWith('.js')).length;
|
|
29
|
+
if (generated < 0) {
|
|
30
|
+
console.error(chalk.red('No filed generated, please check if your processor.ts file'));
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
if (generated > 1) {
|
|
34
|
+
console.error(chalk.red('Packing failed: '), `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:
|
|
35
|
+
import('mine.js')
|
|
36
|
+
to
|
|
37
|
+
import 'mine.js'
|
|
38
|
+
`);
|
|
25
39
|
}
|
|
26
|
-
await execStep('yarn tsc -p .', 'Compile');
|
|
27
|
-
await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging');
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
|
-
exports.buildProcessor = buildProcessor;
|
|
31
42
|
async function buildProcessorForTarget(onlyGen) {
|
|
32
|
-
|
|
43
|
+
const outputBase = path.resolve('src', 'types');
|
|
44
|
+
try {
|
|
45
|
+
// @ts-ignore dynamic import
|
|
46
|
+
const codegen = await import('@sentio/sdk/eth/codegen');
|
|
47
|
+
let input = path.resolve('abis', 'eth');
|
|
48
|
+
let output = path.resolve(outputBase);
|
|
49
|
+
if (!fs.existsSync(input)) {
|
|
50
|
+
input = path.resolve('abis', 'evm');
|
|
51
|
+
output = path.resolve(outputBase);
|
|
52
|
+
}
|
|
53
|
+
// @ts-ignore dynamic import
|
|
54
|
+
await codegen.codegen(input, output);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error('code gen error', e);
|
|
58
|
+
}
|
|
33
59
|
try {
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
60
|
+
// @ts-ignore dynamic import
|
|
61
|
+
const codegen = await import('@sentio/sdk/solana/codegen');
|
|
62
|
+
// @ts-ignore dynamic import
|
|
63
|
+
await codegen.codegen(path.resolve('abis', 'solana'), path.resolve(outputBase, 'solana'));
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error('code gen error', e);
|
|
37
67
|
}
|
|
38
|
-
catch (e) { }
|
|
39
68
|
try {
|
|
40
|
-
//
|
|
41
|
-
const
|
|
42
|
-
|
|
69
|
+
// @ts-ignore dynamic import
|
|
70
|
+
const codegen = await import('@sentio/sdk/aptos/codegen');
|
|
71
|
+
// @ts-ignore dynamic import
|
|
72
|
+
await codegen.codegen(path.resolve('abis', 'aptos'), path.resolve(outputBase, 'aptos'));
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error('code gen error', e);
|
|
43
76
|
}
|
|
44
|
-
catch (e) { }
|
|
45
77
|
if (onlyGen) {
|
|
46
78
|
return;
|
|
47
79
|
}
|
|
@@ -49,31 +81,11 @@ async function buildProcessorForTarget(onlyGen) {
|
|
|
49
81
|
async function installDeps() {
|
|
50
82
|
await execStep('yarn install --ignore-scripts', 'Yarn Install');
|
|
51
83
|
}
|
|
52
|
-
async function codeGenEthersProcessor(abisDir, ETHERS_TARGET = path_1.default.dirname(require.resolve('@sentio/sdk/lib/target-ethers-sentio')), outDir = 'src/types/internal') {
|
|
53
|
-
if (!fs_1.default.existsSync(abisDir)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let haveJson = false;
|
|
57
|
-
const files = fs_1.default.readdirSync(abisDir);
|
|
58
|
-
for (const file of files) {
|
|
59
|
-
if (file.toLowerCase().endsWith('.json')) {
|
|
60
|
-
haveJson = true;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!haveJson) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
console.log(chalk_1.default.green('Generated Types for EVM'));
|
|
68
|
-
// TODO this will fail during postinstall, need to locate real typechain path
|
|
69
|
-
await execStep('yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path_1.default.join(abisDir, '*.json')}`, 'Type definitions gen');
|
|
70
|
-
}
|
|
71
|
-
exports.codeGenEthersProcessor = codeGenEthersProcessor;
|
|
72
84
|
async function execStep(cmd, stepName) {
|
|
73
|
-
const child =
|
|
74
|
-
console.log(
|
|
85
|
+
const child = exec(cmd);
|
|
86
|
+
console.log(chalk.blue(stepName + ' begin'));
|
|
75
87
|
if (!child.stdout || !child.stderr) {
|
|
76
|
-
console.error(
|
|
88
|
+
console.error(chalk.red(stepName + ' failed'));
|
|
77
89
|
process.exit(1);
|
|
78
90
|
}
|
|
79
91
|
child.stdout.pipe(process.stdout);
|
|
@@ -82,10 +94,10 @@ async function execStep(cmd, stepName) {
|
|
|
82
94
|
child.on('close', resolve);
|
|
83
95
|
});
|
|
84
96
|
if (child.exitCode) {
|
|
85
|
-
console.error(
|
|
97
|
+
console.error(chalk.red(stepName + ' failed'));
|
|
86
98
|
process.exit(child.exitCode);
|
|
87
99
|
}
|
|
88
|
-
console.log(
|
|
100
|
+
console.log(chalk.blue(stepName + ' success'));
|
|
89
101
|
console.log();
|
|
90
102
|
}
|
|
91
103
|
//# sourceMappingURL=build.js.map
|
package/lib/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,cAAc,E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,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC","sourcesContent":["import chalk from 'chalk'\nimport path from 'path'\nimport fs from 'fs'\nimport { exec } from 'child_process'\nimport * as process from 'process'\nimport { getPackageRoot } from './utils.js'\n\nexport async function buildProcessor(onlyGen: boolean) {\n if (!onlyGen) {\n await installDeps()\n }\n\n // targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))\n // for (const target) {\n await buildProcessorForTarget(onlyGen)\n // }\n\n if (!onlyGen) {\n let tsupConfig: string\n try {\n tsupConfig = path.resolve(getPackageRoot('@sentio/sdk'), 'lib/tsup.config.ts')\n } catch (e) {\n console.error(chalk.red(\"Wrong CLI version for sdk, can't find tsup.config.ts\"))\n process.exit(1)\n }\n\n const tsup = path.resolve(getPackageRoot('tsup'), 'dist', 'cli-default.js')\n // await execStep('yarn tsc -p .', 'Compile')\n await execStep(`node ${tsup} --config=${tsupConfig}`, 'Packaging')\n\n const dir = fs.readdirSync(path.join(process.cwd(), 'dist'))\n const generated = dir.filter((d) => d.endsWith('.js')).length\n if (generated < 0) {\n console.error(chalk.red('No filed generated, please check if your processor.ts file'))\n process.exit(1)\n }\n if (generated > 1) {\n console.error(\n chalk.red('Packing failed: '),\n `Multiple entry point is not allowed. If your processor.ts have multiple file imported, please change:\nimport('mine.js')\nto\nimport 'mine.js'\n`\n )\n }\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n const outputBase = path.resolve('src', 'types')\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/eth/codegen')\n let input = path.resolve('abis', 'eth')\n let output = path.resolve(outputBase)\n if (!fs.existsSync(input)) {\n input = path.resolve('abis', 'evm')\n output = path.resolve(outputBase)\n }\n // @ts-ignore dynamic import\n await codegen.codegen(input, output)\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/solana/codegen')\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'solana'), path.resolve(outputBase, 'solana'))\n } catch (e) {\n console.error('code gen error', e)\n }\n\n try {\n // @ts-ignore dynamic import\n const codegen = await import('@sentio/sdk/aptos/codegen')\n // @ts-ignore dynamic import\n await codegen.codegen(path.resolve('abis', 'aptos'), path.resolve(outputBase, 'aptos'))\n } catch (e) {\n console.error('code gen error', e)\n }\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nasync function execStep(cmd: string, stepName: string) {\n const child = exec(cmd)\n console.log(chalk.blue(stepName + ' begin'))\n\n if (!child.stdout || !child.stderr) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(1)\n }\n\n child.stdout.pipe(process.stdout)\n child.stderr.pipe(process.stderr)\n\n await new Promise((resolve) => {\n child.on('close', resolve)\n })\n\n if (child.exitCode) {\n console.error(chalk.red(stepName + ' failed'))\n process.exit(child.exitCode)\n }\n console.log(chalk.blue(stepName + ' success'))\n console.log()\n}\n"]}
|
package/lib/cli.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const run_login_1 = require("./commands/run-login");
|
|
15
|
-
const run_upload_1 = require("./commands/run-upload");
|
|
2
|
+
import commandLineArgs from 'command-line-args';
|
|
3
|
+
import commandLineUsage from 'command-line-usage';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import yaml from 'js-yaml';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import { buildProcessor } from './build.js';
|
|
9
|
+
import { runCreate } from './commands/run-create.js';
|
|
10
|
+
import { runVersion } from './commands/run-version.js';
|
|
11
|
+
import { runLogin } from './commands/run-login.js';
|
|
12
|
+
import { runUpload } from './commands/run-upload.js';
|
|
13
|
+
import { runTest } from './commands/run-test.js';
|
|
16
14
|
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
17
|
-
const mainOptions = (
|
|
15
|
+
const mainOptions = commandLineArgs(mainDefinitions, {
|
|
18
16
|
stopAtFirstUnknown: true,
|
|
19
17
|
});
|
|
20
18
|
const argv = mainOptions._unknown || [];
|
|
@@ -22,13 +20,16 @@ if (!mainOptions.command) {
|
|
|
22
20
|
usage();
|
|
23
21
|
}
|
|
24
22
|
if (mainOptions.command === 'login') {
|
|
25
|
-
|
|
23
|
+
runLogin(argv);
|
|
26
24
|
}
|
|
27
25
|
else if (mainOptions.command === 'create') {
|
|
28
|
-
|
|
26
|
+
await runCreate(argv);
|
|
29
27
|
}
|
|
30
28
|
else if (mainOptions.command === 'version') {
|
|
31
|
-
|
|
29
|
+
runVersion(argv);
|
|
30
|
+
}
|
|
31
|
+
else if (mainOptions.command === 'test') {
|
|
32
|
+
runTest(argv);
|
|
32
33
|
}
|
|
33
34
|
else {
|
|
34
35
|
// For all the commands that need read project configs
|
|
@@ -37,20 +38,20 @@ else {
|
|
|
37
38
|
let processorConfig = { host: '', project: '', build: true, debug: false };
|
|
38
39
|
// Fist step, read from project yaml file
|
|
39
40
|
try {
|
|
40
|
-
console.log(
|
|
41
|
+
console.log(chalk.blue('Loading Process config'));
|
|
41
42
|
// TODO correctly located sentio.yaml
|
|
42
43
|
const pwd = process.cwd();
|
|
43
|
-
const packageJson =
|
|
44
|
-
if (!
|
|
44
|
+
const packageJson = path.join(pwd, 'package.json');
|
|
45
|
+
if (!fs.existsSync(packageJson)) {
|
|
45
46
|
console.error('package.json not found, please run this command in the root of your project');
|
|
46
47
|
process.exit(1);
|
|
47
48
|
}
|
|
48
|
-
const yamlPath =
|
|
49
|
-
if (!
|
|
49
|
+
const yamlPath = path.join(pwd, 'sentio.yaml');
|
|
50
|
+
if (!fs.existsSync(yamlPath)) {
|
|
50
51
|
console.error('sentio.yaml not found, please create one according to: TODO docs');
|
|
51
52
|
process.exit(1);
|
|
52
53
|
}
|
|
53
|
-
processorConfig =
|
|
54
|
+
processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8'));
|
|
54
55
|
if (!processorConfig.project === undefined) {
|
|
55
56
|
console.error('Config yaml must have contain a valid project identifier');
|
|
56
57
|
process.exit(1);
|
|
@@ -81,20 +82,20 @@ else {
|
|
|
81
82
|
process.exit(1);
|
|
82
83
|
}
|
|
83
84
|
if (mainOptions.command === 'upload') {
|
|
84
|
-
|
|
85
|
+
await runUpload(processorConfig, argv);
|
|
85
86
|
}
|
|
86
87
|
else if (mainOptions.command === 'build') {
|
|
87
|
-
|
|
88
|
+
await buildProcessor(false);
|
|
88
89
|
}
|
|
89
90
|
else if (mainOptions.command === 'gen') {
|
|
90
|
-
|
|
91
|
+
await buildProcessor(true);
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
93
94
|
usage();
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
function usage() {
|
|
97
|
-
const usage = (
|
|
98
|
+
const usage = commandLineUsage([
|
|
98
99
|
{
|
|
99
100
|
header: 'Sentio',
|
|
100
101
|
content: 'Login & Manage your project files to Sentio.',
|
|
@@ -108,6 +109,7 @@ function usage() {
|
|
|
108
109
|
'sentio upload\t\t\t\tbuild and upload processor to sentio',
|
|
109
110
|
'sentio gen\t\t\t\tgenerate abi',
|
|
110
111
|
'sentio build\t\t\t\tgenerate abi and build',
|
|
112
|
+
'sentio test\t\t\t\trun tests',
|
|
111
113
|
'sentio version\t\t\tcurrent cli version',
|
|
112
114
|
],
|
|
113
115
|
},
|
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,OAAO,IAAI,MAAM,SAAS,CAAA;AAE1B,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAClE,MAAM,WAAW,GAAG,eAAe,CAAC,eAAe,EAAE;IACnD,kBAAkB,EAAE,IAAI;CACzB,CAAC,CAAA;AACF,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,IAAI,EAAE,CAAA;AAEvC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;IACxB,KAAK,EAAE,CAAA;CACR;AAED,IAAI,WAAW,CAAC,OAAO,KAAK,OAAO,EAAE;IACnC,QAAQ,CAAC,IAAI,CAAC,CAAA;CACf;KAAM,IAAI,WAAW,CAAC,OAAO,KAAK,QAAQ,EAAE;IAC3C,MAAM,SAAS,CAAC,IAAI,CAAC,CAAA;CACtB;KAAM,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BAA8B;gBAC9B,yCAAyC;aAC1C;SACF;KACF,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport fs from 'fs'\nimport path from 'path'\n\nimport yaml from 'js-yaml'\nimport { SentioProjectConfig } from './config.js'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build.js'\nimport { runCreate } from './commands/run-create.js'\nimport { runVersion } from './commands/run-version.js'\nimport { runLogin } from './commands/run-login.js'\nimport { runUpload } from './commands/run-upload.js'\nimport { runTest } from './commands/run-test.js'\n\nconst mainDefinitions = [{ name: 'command', defaultOption: true }]\nconst mainOptions = commandLineArgs(mainDefinitions, {\n stopAtFirstUnknown: true,\n})\nconst argv = mainOptions._unknown || []\n\nif (!mainOptions.command) {\n usage()\n}\n\nif (mainOptions.command === 'login') {\n runLogin(argv)\n} else if (mainOptions.command === 'create') {\n await runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(argv)\n} else if (mainOptions.command === 'test') {\n runTest(argv)\n} else {\n // For all the commands that need read project configs\n // TODO move them to their own modules\n\n // Process configs\n let processorConfig: SentioProjectConfig = { host: '', project: '', build: true, debug: false }\n // Fist step, read from project yaml file\n try {\n console.log(chalk.blue('Loading Process config'))\n // TODO correctly located sentio.yaml\n const pwd = process.cwd()\n const packageJson = path.join(pwd, 'package.json')\n if (!fs.existsSync(packageJson)) {\n console.error('package.json not found, please run this command in the root of your project')\n process.exit(1)\n }\n\n const yamlPath = path.join(pwd, 'sentio.yaml')\n if (!fs.existsSync(yamlPath)) {\n console.error('sentio.yaml not found, please create one according to: TODO docs')\n process.exit(1)\n }\n\n processorConfig = yaml.load(fs.readFileSync('sentio.yaml', 'utf8')) as SentioProjectConfig\n if (!processorConfig.project === undefined) {\n console.error('Config yaml must have contain a valid project identifier')\n process.exit(1)\n }\n if (processorConfig.build === undefined) {\n processorConfig.build = true\n }\n if (!processorConfig.host) {\n processorConfig.host = 'prod'\n }\n if (processorConfig.debug === undefined) {\n processorConfig.debug = false\n }\n\n // if (!processorConfig.source) {\n // processorConfig.source = 'src/processor.ts'\n // }\n // if (!processorConfig.targets) {\n // console.warn('targets is not defined, use EVM as the default target')\n // processorConfig.targets = []\n // }\n // if (processorConfig.targets.length === 0) {\n // // By default evm\n // processorConfig.targets.push({ chain: EVM })\n // }\n } catch (e) {\n console.error(e)\n process.exit(1)\n }\n\n if (mainOptions.command === 'upload') {\n await runUpload(processorConfig, argv)\n } else if (mainOptions.command === 'build') {\n await buildProcessor(false)\n } else if (mainOptions.command === 'gen') {\n await buildProcessor(true)\n } else {\n usage()\n }\n}\n\nfunction usage() {\n const usage = commandLineUsage([\n {\n header: 'Sentio',\n content: 'Login & Manage your project files to Sentio.',\n },\n {\n header: 'Usage',\n content: [\n 'sentio <command> --help\\t\\tshow detail usage of specific command',\n 'sentio login\\t\\t\\t\\tlogin to sentio',\n 'sentio create\\t\\t\\t\\tcreate a template project',\n 'sentio upload\\t\\t\\t\\tbuild and upload processor to sentio',\n 'sentio gen\\t\\t\\t\\tgenerate abi',\n 'sentio build\\t\\t\\t\\tgenerate abi and build',\n 'sentio test\\t\\t\\t\\trun tests',\n 'sentio version\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
|
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
12
|
-
const os_1 = tslib_1.__importDefault(require("os"));
|
|
13
|
-
const crypto = tslib_1.__importStar(require("crypto"));
|
|
14
|
-
const app = (0, express_1.default)();
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { getAuthConfig, getFinalizedHost } from '../config.js';
|
|
3
|
+
import url, { URL } from 'url';
|
|
4
|
+
import fetch from 'node-fetch';
|
|
5
|
+
import { getCliVersion } from '../utils.js';
|
|
6
|
+
import { WriteKey } from '../key.js';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import os from 'os';
|
|
9
|
+
import * as crypto from 'crypto';
|
|
10
|
+
const app = express();
|
|
15
11
|
let server;
|
|
16
12
|
let authParams;
|
|
17
|
-
function startServer(params) {
|
|
13
|
+
export function startServer(params) {
|
|
18
14
|
authParams = params;
|
|
19
15
|
server = app.listen(params.serverPort);
|
|
20
16
|
}
|
|
21
|
-
exports.startServer = startServer;
|
|
22
17
|
app.get('/callback', async (req, res) => {
|
|
23
18
|
const fail = function (...args) {
|
|
24
|
-
console.error(
|
|
19
|
+
console.error(chalk.red(args));
|
|
25
20
|
res.end(args.toString());
|
|
26
21
|
server.close();
|
|
27
22
|
};
|
|
28
|
-
const host =
|
|
23
|
+
const host = getFinalizedHost(authParams.sentioHost);
|
|
29
24
|
const code = req.query.code;
|
|
30
25
|
if (!code || code.length == 0) {
|
|
31
26
|
fail('Failed to get authorization code');
|
|
@@ -37,8 +32,8 @@ app.get('/callback', async (req, res) => {
|
|
|
37
32
|
fail(`Failed to get access token: ${tokenResRaw.status} ${tokenResRaw.statusText}`);
|
|
38
33
|
return;
|
|
39
34
|
}
|
|
40
|
-
const tokenRes = await tokenResRaw.json();
|
|
41
|
-
const accessToken = tokenRes
|
|
35
|
+
const tokenRes = (await tokenResRaw.json());
|
|
36
|
+
const accessToken = tokenRes.access_token;
|
|
42
37
|
// check if the account is ready
|
|
43
38
|
const userResRaw = await getUser(host, accessToken);
|
|
44
39
|
if (!userResRaw.ok) {
|
|
@@ -50,35 +45,35 @@ app.get('/callback', async (req, res) => {
|
|
|
50
45
|
}
|
|
51
46
|
return;
|
|
52
47
|
}
|
|
53
|
-
const userRes = await userResRaw.json();
|
|
48
|
+
const userRes = (await userResRaw.json());
|
|
54
49
|
if (!userRes.emailVerified) {
|
|
55
50
|
fail('Your account is not verified, please verify your email first');
|
|
56
51
|
return;
|
|
57
52
|
}
|
|
58
53
|
// create API key
|
|
59
|
-
const apiKeyName = `${
|
|
54
|
+
const apiKeyName = `${os.hostname()}-${crypto.randomBytes(4).toString('hex')}`;
|
|
60
55
|
const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken);
|
|
61
56
|
if (!createApiKeyResRaw.ok) {
|
|
62
57
|
fail(`Failed to create API key: ${createApiKeyResRaw.status} ${createApiKeyResRaw.statusText}`);
|
|
63
58
|
return;
|
|
64
59
|
}
|
|
65
|
-
const createApiKeyRes = await createApiKeyResRaw.json();
|
|
66
|
-
const apiKey = createApiKeyRes
|
|
67
|
-
|
|
68
|
-
res.end(
|
|
69
|
-
console.log(
|
|
60
|
+
const createApiKeyRes = (await createApiKeyResRaw.json());
|
|
61
|
+
const apiKey = createApiKeyRes.key;
|
|
62
|
+
WriteKey(host, apiKey);
|
|
63
|
+
res.end('Login success, please go back to CLI to continue');
|
|
64
|
+
console.log(chalk.green('Login success, new API key: ' + apiKey));
|
|
70
65
|
server.close();
|
|
71
66
|
});
|
|
72
67
|
async function getToken(host, code) {
|
|
73
|
-
const authConf =
|
|
74
|
-
const params = new
|
|
68
|
+
const authConf = getAuthConfig(host);
|
|
69
|
+
const params = new url.URLSearchParams({
|
|
75
70
|
grant_type: 'authorization_code',
|
|
76
71
|
client_id: authConf.clientId,
|
|
77
72
|
code_verifier: authParams.codeVerifier,
|
|
78
73
|
code: code,
|
|
79
74
|
redirect_uri: `http://localhost:${authParams.serverPort}/callback`,
|
|
80
75
|
});
|
|
81
|
-
return (
|
|
76
|
+
return fetch(`${authConf.domain}/oauth/token`, {
|
|
82
77
|
method: 'POST',
|
|
83
78
|
headers: {
|
|
84
79
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
@@ -87,12 +82,12 @@ async function getToken(host, code) {
|
|
|
87
82
|
});
|
|
88
83
|
}
|
|
89
84
|
async function createApiKey(host, name, source, accessToken) {
|
|
90
|
-
const createApiKeyUrl = new
|
|
91
|
-
return (
|
|
85
|
+
const createApiKeyUrl = new URL('/api/v1/keys', host);
|
|
86
|
+
return fetch(createApiKeyUrl.href, {
|
|
92
87
|
method: 'POST',
|
|
93
88
|
headers: {
|
|
94
89
|
Authorization: 'Bearer ' + accessToken,
|
|
95
|
-
version:
|
|
90
|
+
version: getCliVersion(),
|
|
96
91
|
},
|
|
97
92
|
body: JSON.stringify({
|
|
98
93
|
name: name,
|
|
@@ -102,12 +97,12 @@ async function createApiKey(host, name, source, accessToken) {
|
|
|
102
97
|
});
|
|
103
98
|
}
|
|
104
99
|
async function getUser(host, accessToken) {
|
|
105
|
-
const getUserUrl = new
|
|
106
|
-
return (
|
|
100
|
+
const getUserUrl = new URL('/api/v1/users', host);
|
|
101
|
+
return fetch(getUserUrl.href, {
|
|
107
102
|
method: 'GET',
|
|
108
103
|
headers: {
|
|
109
104
|
Authorization: 'Bearer ' + accessToken,
|
|
110
|
-
version:
|
|
105
|
+
version: getCliVersion(),
|
|
111
106
|
},
|
|
112
107
|
});
|
|
113
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-server.js","sourceRoot":"","sources":["../../src/commands/login-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login-server.js","sourceRoot":"","sources":["../../src/commands/login-server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC9B,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OA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,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;IACjD,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE;QAC5B,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,GAAG,WAAW;YACtC,OAAO,EAAE,aAAa,EAAE;SACzB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import express from 'express'\nimport { getAuthConfig, getFinalizedHost } from '../config.js'\nimport url, { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { getCliVersion } from '../utils.js'\nimport { WriteKey } from '../key.js'\nimport chalk from 'chalk'\nimport http from 'http'\nimport os from 'os'\nimport * as crypto from 'crypto'\n\ninterface AuthParams {\n serverPort: number\n sentioHost: string\n codeVerifier: string\n}\n\nconst app = express()\n\nlet server: http.Server\nlet authParams: AuthParams\n\nexport function startServer(params: AuthParams) {\n authParams = params\n server = app.listen(params.serverPort)\n}\n\napp.get('/callback', async (req, res) => {\n const fail = function (...args: any[]) {\n console.error(chalk.red(args))\n res.end(args.toString())\n server.close()\n }\n\n const host = getFinalizedHost(authParams.sentioHost)\n const code = req.query.code\n if (!code || (code as string).length == 0) {\n fail('Failed to get authorization code')\n return\n }\n\n // exchange token\n const tokenResRaw = await getToken(host, code as string)\n if (!tokenResRaw.ok) {\n fail(`Failed to get access token: ${tokenResRaw.status} ${tokenResRaw.statusText}`)\n return\n }\n const tokenRes = (await tokenResRaw.json()) as { access_token: string }\n const accessToken = tokenRes.access_token\n\n // check if the account is ready\n const userResRaw = await getUser(host, accessToken)\n if (!userResRaw.ok) {\n if (userResRaw.status == 401) {\n fail('The account does not exist, please sign up on sentio first')\n } else {\n fail(`Failed to get user info: ${userResRaw.status} ${userResRaw.statusText}`)\n }\n return\n }\n const userRes = (await userResRaw.json()) as { emailVerified: boolean }\n if (!userRes.emailVerified) {\n fail('Your account is not verified, please verify your email first')\n return\n }\n\n // create API key\n const apiKeyName = `${os.hostname()}-${crypto.randomBytes(4).toString('hex')}`\n const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken)\n if (!createApiKeyResRaw.ok) {\n fail(`Failed to create API key: ${createApiKeyResRaw.status} ${createApiKeyResRaw.statusText}`)\n return\n }\n const createApiKeyRes = (await createApiKeyResRaw.json()) as { key: string }\n const apiKey = createApiKeyRes.key\n WriteKey(host, apiKey)\n\n res.end('Login success, please go back to CLI to continue')\n console.log(chalk.green('Login success, new API key: ' + apiKey))\n\n server.close()\n})\n\nasync function getToken(host: string, code: string) {\n const authConf = getAuthConfig(host)\n const params = new url.URLSearchParams({\n grant_type: 'authorization_code',\n client_id: authConf.clientId,\n code_verifier: authParams.codeVerifier,\n code: code,\n redirect_uri: `http://localhost:${authParams.serverPort}/callback`,\n })\n return fetch(`${authConf.domain}/oauth/token`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: params.toString(),\n })\n}\n\nasync function createApiKey(host: string, name: string, source: string, accessToken: string) {\n const createApiKeyUrl = new URL('/api/v1/keys', host)\n return fetch(createApiKeyUrl.href, {\n method: 'POST',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n body: JSON.stringify({\n name: name,\n scopes: ['write:project'],\n source: source,\n }),\n })\n}\n\nasync function getUser(host: string, accessToken: string) {\n const getUserUrl = new URL('/api/v1/users', host)\n return fetch(getUserUrl.href, {\n method: 'GET',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n })\n}\n"]}
|