@sentio/cli 1.1.9-rc.1 → 1.1.9-rc.3
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/cli.js +2 -68
- package/lib/cli.js.map +1 -1
- package/lib/commands/login-server.js +13 -7
- package/lib/commands/login-server.js.map +1 -1
- package/lib/commands/run-upload.d.ts +3 -0
- package/lib/{upload.js → commands/run-upload.js} +83 -11
- package/lib/commands/run-upload.js.map +1 -0
- package/package.json +1 -1
- package/src/cli.ts +3 -68
- package/src/commands/login-server.ts +15 -7
- package/src/{upload.ts → commands/run-upload.ts} +81 -10
- package/lib/upload.d.ts +0 -2
- package/lib/upload.js.map +0 -1
package/lib/cli.js
CHANGED
|
@@ -9,13 +9,12 @@ const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
12
|
-
const config_1 = require("./config");
|
|
13
|
-
const upload_1 = require("./upload");
|
|
14
12
|
const chalk_1 = __importDefault(require("chalk"));
|
|
15
13
|
const build_1 = require("./build");
|
|
16
14
|
const run_create_1 = require("./commands/run-create");
|
|
17
15
|
const run_version_1 = require("./commands/run-version");
|
|
18
16
|
const run_login_1 = require("./commands/run-login");
|
|
17
|
+
const run_upload_1 = require("./commands/run-upload");
|
|
19
18
|
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
20
19
|
const mainOptions = (0, command_line_args_1.default)(mainDefinitions, {
|
|
21
20
|
stopAtFirstUnknown: true,
|
|
@@ -84,72 +83,7 @@ else {
|
|
|
84
83
|
process.exit(1);
|
|
85
84
|
}
|
|
86
85
|
if (mainOptions.command === 'upload') {
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
name: 'help',
|
|
90
|
-
alias: 'h',
|
|
91
|
-
type: Boolean,
|
|
92
|
-
description: 'Display this usage guide.',
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
name: 'api-key',
|
|
96
|
-
type: String,
|
|
97
|
-
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: 'host',
|
|
101
|
-
description: '(Optional) Override Sentio Host name',
|
|
102
|
-
type: String,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: 'owner',
|
|
106
|
-
description: '(Optional) Override Project owner',
|
|
107
|
-
type: String,
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'nobuild',
|
|
111
|
-
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
112
|
-
type: Boolean,
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
name: 'debug',
|
|
116
|
-
description: '(Optional) Set driver logging level to debug',
|
|
117
|
-
type: Boolean,
|
|
118
|
-
},
|
|
119
|
-
];
|
|
120
|
-
const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
|
|
121
|
-
if (options.help) {
|
|
122
|
-
const usage = (0, command_line_usage_1.default)([
|
|
123
|
-
{
|
|
124
|
-
header: 'Sentio upload',
|
|
125
|
-
content: 'sentio upload',
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
header: 'Options',
|
|
129
|
-
optionList: optionDefinitions,
|
|
130
|
-
},
|
|
131
|
-
]);
|
|
132
|
-
console.log(usage);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
if (options.host) {
|
|
136
|
-
processorConfig.host = options.host;
|
|
137
|
-
}
|
|
138
|
-
if (options.nobuild) {
|
|
139
|
-
processorConfig.build = false;
|
|
140
|
-
}
|
|
141
|
-
if (options.debug) {
|
|
142
|
-
processorConfig.debug = true;
|
|
143
|
-
}
|
|
144
|
-
(0, config_1.finalizeHost)(processorConfig);
|
|
145
|
-
(0, config_1.FinalizeProjectName)(processorConfig, options.owner);
|
|
146
|
-
console.log(processorConfig);
|
|
147
|
-
let apiOverride = undefined;
|
|
148
|
-
if (options['api-key']) {
|
|
149
|
-
apiOverride = options['api-key'];
|
|
150
|
-
}
|
|
151
|
-
(0, upload_1.uploadFile)(processorConfig, apiOverride);
|
|
152
|
-
}
|
|
86
|
+
(0, run_upload_1.runUpload)(processorConfig, argv);
|
|
153
87
|
}
|
|
154
88
|
else if (mainOptions.command === 'build') {
|
|
155
89
|
(0, build_1.buildProcessor)(false);
|
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,gDAAuB;AAEvB,sDAA0B;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,gDAAuB;AAEvB,sDAA0B;AAE1B,kDAAyB;AACzB,mCAAwC;AACxC,sDAAiD;AACjD,wDAAmD;AACnD,oDAA+C;AAC/C,sDAAiD;AAEjD,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;AAClE,MAAM,WAAW,GAAG,IAAA,2BAAe,EAAC,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,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;CACf;KAAM,IAAI,WAAW,CAAC,OAAO,KAAK,QAAQ,EAAE;IAC3C,IAAA,sBAAS,EAAC,IAAI,CAAC,CAAA;CAChB;KAAM,IAAI,WA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;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'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport { runCreate } from './commands/run-create'\nimport { runVersion } from './commands/run-version'\nimport { runLogin } from './commands/run-login'\nimport { runUpload } from './commands/run-upload'\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 runCreate(argv)\n} else if (mainOptions.command === 'version') {\n runVersion(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 runUpload(processorConfig, argv)\n } else if (mainOptions.command === 'build') {\n buildProcessor(false)\n } else if (mainOptions.command === 'gen') {\n 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 version\\t\\t\\tcurrent cli version',\n ],\n },\n ])\n console.log(usage)\n process.exit(1)\n}\n"]}
|
|
@@ -45,16 +45,21 @@ function startServer(params) {
|
|
|
45
45
|
}
|
|
46
46
|
exports.startServer = startServer;
|
|
47
47
|
app.get('/callback', async (req, res) => {
|
|
48
|
-
|
|
48
|
+
const fail = function (...args) {
|
|
49
|
+
console.error(chalk_1.default.red(args));
|
|
50
|
+
res.end(args.toString());
|
|
51
|
+
server.close();
|
|
52
|
+
};
|
|
49
53
|
const host = (0, config_1.getFinalizedHost)(authParams.sentioHost);
|
|
50
54
|
const code = req.query.code;
|
|
51
55
|
if (!code || code.length == 0) {
|
|
56
|
+
fail('Failed to get authorization code');
|
|
52
57
|
return;
|
|
53
58
|
}
|
|
54
59
|
// exchange token
|
|
55
60
|
const tokenResRaw = await getToken(host, code);
|
|
56
61
|
if (!tokenResRaw.ok) {
|
|
57
|
-
|
|
62
|
+
fail(`Failed to get access token: ${tokenResRaw.status} ${tokenResRaw.statusText}`);
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
60
65
|
const tokenRes = await tokenResRaw.json();
|
|
@@ -63,29 +68,30 @@ app.get('/callback', async (req, res) => {
|
|
|
63
68
|
const userResRaw = await getUser(host, accessToken);
|
|
64
69
|
if (!userResRaw.ok) {
|
|
65
70
|
if (userResRaw.status == 401) {
|
|
66
|
-
|
|
71
|
+
fail('The account does not exist, please sign up on sentio first');
|
|
67
72
|
}
|
|
68
73
|
else {
|
|
69
|
-
|
|
74
|
+
fail(`Failed to get user info: ${userResRaw.status} ${userResRaw.statusText}`);
|
|
70
75
|
}
|
|
71
76
|
return;
|
|
72
77
|
}
|
|
73
78
|
const userRes = await userResRaw.json();
|
|
74
79
|
if (!userRes.emailVerified) {
|
|
75
|
-
|
|
80
|
+
fail('Your account is not verified, please verify your email first');
|
|
76
81
|
return;
|
|
77
82
|
}
|
|
78
83
|
// create API key
|
|
79
84
|
const apiKeyName = `${os_1.default.hostname()}-${crypto.randomBytes(4).toString('hex')}`;
|
|
80
85
|
const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken);
|
|
81
86
|
if (!createApiKeyResRaw.ok) {
|
|
82
|
-
|
|
87
|
+
fail(`Failed to create API key: ${createApiKeyResRaw.status} ${createApiKeyResRaw.statusText}`);
|
|
83
88
|
return;
|
|
84
89
|
}
|
|
85
90
|
const createApiKeyRes = await createApiKeyResRaw.json();
|
|
86
91
|
const apiKey = createApiKeyRes['key'];
|
|
87
92
|
(0, key_1.WriteKey)(host, apiKey);
|
|
88
|
-
|
|
93
|
+
res.end("Login success, please go back to CLI to continue");
|
|
94
|
+
console.log(chalk_1.default.green('Login success, new API key: ' + apiKey));
|
|
89
95
|
server.close();
|
|
90
96
|
});
|
|
91
97
|
async function getToken(host, code) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-server.js","sourceRoot":"","sources":["../../src/commands/login-server.ts"],"names":[],"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Ac,EAAE;QAC7C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,mCAAmC;SACpD;QACD,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE;KACxB,CAAC,CAAA;AACJ,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,IAAY,EAAE,IAAY,EAAE,MAAc,EAAE,WAAmB;IACzF,MAAM,eAAe,GAAG,IAAI,SAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;IACrD,OAAO,IAAA,oBAAK,EAAC,eAAe,EAAE;QAC5B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,GAAG,WAAW;YACtC,OAAO,EAAE,IAAA,qBAAa,GAAE;SACzB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,CAAC,eAAe,CAAC;YACzB,MAAM,EAAE,MAAM;SACf,CAAC;KACH,CAAC,CAAA;AACJ,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,IAAY,EAAE,WAAmB;IACtD,MAAM,UAAU,GAAG,IAAI,SAAG,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;IACjD,OAAO,IAAA,oBAAK,EAAC,UAAU,EAAE;QACvB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,aAAa,EAAE,SAAS,GAAG,WAAW;YACtC,OAAO,EAAE,IAAA,qBAAa,GAAE;SACzB;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import express from 'express'\nimport { getAuthConfig, getFinalizedHost } from '../config'\nimport url, { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { getCliVersion } from '../utils'\nimport { WriteKey } from '../key'\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()\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()\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()\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, {\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, {\n method: 'GET',\n headers: {\n Authorization: 'Bearer ' + accessToken,\n version: getCliVersion(),\n },\n })\n}\n"]}
|
|
@@ -3,18 +3,90 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.uploadFile = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
exports.uploadFile = exports.runUpload = void 0;
|
|
7
|
+
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
8
|
+
const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const url_1 = require("url");
|
|
11
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
+
const build_1 = require("../build");
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const key_1 = require("../key");
|
|
9
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const crypto_1 = require("crypto");
|
|
18
|
+
const child_process_1 = require("child_process");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
10
20
|
const readline_1 = __importDefault(require("readline"));
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
async function runUpload(processorConfig, argv) {
|
|
22
|
+
const optionDefinitions = [
|
|
23
|
+
{
|
|
24
|
+
name: 'help',
|
|
25
|
+
alias: 'h',
|
|
26
|
+
type: Boolean,
|
|
27
|
+
description: 'Display this usage guide.',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'api-key',
|
|
31
|
+
type: String,
|
|
32
|
+
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'host',
|
|
36
|
+
description: '(Optional) Override Sentio Host name',
|
|
37
|
+
type: String,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'owner',
|
|
41
|
+
description: '(Optional) Override Project owner',
|
|
42
|
+
type: String,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'nobuild',
|
|
46
|
+
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
47
|
+
type: Boolean,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'debug',
|
|
51
|
+
description: '(Optional) Run driver in debug mode, default false',
|
|
52
|
+
type: Boolean,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
const options = (0, command_line_args_1.default)(optionDefinitions, { argv });
|
|
56
|
+
if (options.help) {
|
|
57
|
+
const usage = (0, command_line_usage_1.default)([
|
|
58
|
+
{
|
|
59
|
+
header: 'Sentio upload',
|
|
60
|
+
content: 'sentio upload',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
header: 'Options',
|
|
64
|
+
optionList: optionDefinitions,
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
console.log(usage);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (options.host) {
|
|
71
|
+
processorConfig.host = options.host;
|
|
72
|
+
}
|
|
73
|
+
if (options.nobuild) {
|
|
74
|
+
processorConfig.build = false;
|
|
75
|
+
}
|
|
76
|
+
if (options.debug) {
|
|
77
|
+
processorConfig.debug = true;
|
|
78
|
+
}
|
|
79
|
+
(0, config_1.finalizeHost)(processorConfig);
|
|
80
|
+
(0, config_1.FinalizeProjectName)(processorConfig, options.owner);
|
|
81
|
+
console.log(processorConfig);
|
|
82
|
+
let apiOverride = undefined;
|
|
83
|
+
if (options['api-key']) {
|
|
84
|
+
apiOverride = options['api-key'];
|
|
85
|
+
}
|
|
86
|
+
return uploadFile(processorConfig, apiOverride);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.runUpload = runUpload;
|
|
18
90
|
async function createProject(options, apiKey) {
|
|
19
91
|
const url = new url_1.URL('/api/v1/projects', options.host);
|
|
20
92
|
const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project];
|
|
@@ -187,4 +259,4 @@ async function finishUpload(host, apiKey, projectSlug, sdkVersion, sha256, commi
|
|
|
187
259
|
}),
|
|
188
260
|
});
|
|
189
261
|
}
|
|
190
|
-
//# sourceMappingURL=upload.js.map
|
|
262
|
+
//# sourceMappingURL=run-upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-upload.js","sourceRoot":"","sources":["../../src/commands/run-upload.ts"],"names":[],"mappings":";;;;;;AAAA,0EAA+C;AAC/C,4EAAiD;AACjD,sCAAkF;AAClF,6BAAyB;AACzB,4DAA8B;AAC9B,oCAAyC;AACzC,kDAAyB;AACzB,gDAAuB;AACvB,gCAAgC;AAChC,4CAAmB;AACnB,mCAAmC;AACnC,iDAAwC;AACxC,oCAAwC;AACxC,wDAA+B;AAExB,KAAK,UAAU,SAAS,CAAC,eAAoC,EAAE,IAAc;IAClF,MAAM,iBAAiB,GAAG;QACxB;YACE,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,2BAA2B;SACzC;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sEAAsE;SACpF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YAC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d,SAAiB,EACjB,MAAc,EACd,KAAc;IAEd,MAAM,eAAe,GAAG,IAAI,SAAG,CAAC,kCAAkC,EAAE,IAAI,CAAC,CAAA;IACzE,OAAO,IAAA,oBAAK,EAAC,eAAe,EAAE;QAC5B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,UAAU;YACvB,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,MAAM;YACf,KAAK,EAAE,KAAK;SACb,CAAC;KACH,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import commandLineArgs from 'command-line-args'\nimport commandLineUsage from 'command-line-usage'\nimport { finalizeHost, FinalizeProjectName, SentioProjectConfig } from '../config'\nimport { URL } from 'url'\nimport fetch from 'node-fetch'\nimport { buildProcessor } from '../build'\nimport chalk from 'chalk'\nimport path from 'path'\nimport { ReadKey } from '../key'\nimport fs from 'fs'\nimport { createHash } from 'crypto'\nimport { execSync } from 'child_process'\nimport { getSdkVersion } from '../utils'\nimport readline from 'readline'\n\nexport async function runUpload(processorConfig: SentioProjectConfig, argv: string[]) {\n const optionDefinitions = [\n {\n name: 'help',\n alias: 'h',\n type: Boolean,\n description: 'Display this usage guide.',\n },\n {\n name: 'api-key',\n type: String,\n description: '(Optional) Manually provide API key rather than use saved credential',\n },\n {\n name: 'host',\n description: '(Optional) Override Sentio Host name',\n type: String,\n },\n {\n name: 'owner',\n description: '(Optional) Override Project owner',\n type: String,\n },\n {\n name: 'nobuild',\n description: '(Optional) Skip build & pack file before uploading, default false',\n type: Boolean,\n },\n {\n name: 'debug',\n description: '(Optional) Run driver in debug mode, default false',\n type: Boolean,\n },\n ]\n const options = commandLineArgs(optionDefinitions, { argv })\n if (options.help) {\n const usage = commandLineUsage([\n {\n header: 'Sentio upload',\n content: 'sentio upload',\n },\n {\n header: 'Options',\n optionList: optionDefinitions,\n },\n ])\n console.log(usage)\n } else {\n if (options.host) {\n processorConfig.host = options.host\n }\n if (options.nobuild) {\n processorConfig.build = false\n }\n if (options.debug) {\n processorConfig.debug = true\n }\n finalizeHost(processorConfig)\n FinalizeProjectName(processorConfig, options.owner)\n console.log(processorConfig)\n\n let apiOverride = undefined\n if (options['api-key']) {\n apiOverride = options['api-key']\n }\n return uploadFile(processorConfig, apiOverride)\n }\n}\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]\n return fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n let triedCount = 0\n const upload = async () => {\n let commitSha = ''\n let gitUrl = ''\n const sha256 = digest\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n } catch (e) {\n chalk.yellow(e)\n }\n try {\n gitUrl = execSync('git remote get-url origin').toString().trim()\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n\n // get gcs upload url\n const initUploadResRaw = await initUpload(options.host, apiKey, options.project, getSdkVersion())\n if (!initUploadResRaw.ok) {\n console.error(chalk.red('Failed to get upload url'))\n console.error(chalk.red((await initUploadResRaw.json()).message))\n\n if (initUploadResRaw.status === 404) {\n // create project if not exist\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red((await res.json()).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n return\n }\n const initUploadRes = await initUploadResRaw.json()\n const uploadUrl = initUploadRes['url'] as string\n\n // do actual uploading\n const file = fs.createReadStream(PROCESSOR_FILE)\n const uploadResRaw = await fetch(uploadUrl, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/octet-stream',\n },\n body: file,\n })\n if (!uploadResRaw.ok) {\n console.error(chalk.red('Failed to upload'))\n console.error(chalk.red(await uploadResRaw.text()))\n return\n }\n\n // finish uploading\n const finishUploadResRaw = await finishUpload(\n options.host,\n apiKey,\n options.project,\n getSdkVersion(),\n sha256,\n commitSha,\n gitUrl,\n options.debug\n )\n if (!finishUploadResRaw.ok) {\n console.error(chalk.red('Failed to finish uploading'))\n console.error(chalk.red(await finishUploadResRaw.text()))\n return\n }\n\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { projectFullSlug, version } = await finishUploadResRaw.json()\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${projectFullSlug}/datasource`)\n console.log('\\t', chalk.blue('Version:'), version)\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n\nasync function initUpload(host: string, apiKey: string, projectSlug: string, sdkVersion: string) {\n const initUploadUrl = new URL(`/api/v1/processors/init_upload`, host)\n return fetch(initUploadUrl, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n }),\n })\n}\n\nasync function finishUpload(\n host: string,\n apiKey: string,\n projectSlug: string,\n sdkVersion: string,\n sha256: string,\n commitSha: string,\n gitUrl: string,\n debug: boolean\n) {\n const finishUploadUrl = new URL(`/api/v1/processors/finish_upload`, host)\n return fetch(finishUploadUrl, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n sha256: sha256,\n commit_sha: commitSha,\n git_url: gitUrl,\n debug: debug,\n }),\n })\n}\n"]}
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -6,13 +6,13 @@ import fs from 'fs'
|
|
|
6
6
|
import path from 'path'
|
|
7
7
|
|
|
8
8
|
import yaml from 'js-yaml'
|
|
9
|
-
import {
|
|
10
|
-
import { uploadFile } from './upload'
|
|
9
|
+
import { SentioProjectConfig } from './config'
|
|
11
10
|
import chalk from 'chalk'
|
|
12
11
|
import { buildProcessor } from './build'
|
|
13
12
|
import { runCreate } from './commands/run-create'
|
|
14
13
|
import { runVersion } from './commands/run-version'
|
|
15
14
|
import { runLogin } from './commands/run-login'
|
|
15
|
+
import { runUpload } from './commands/run-upload'
|
|
16
16
|
|
|
17
17
|
const mainDefinitions = [{ name: 'command', defaultOption: true }]
|
|
18
18
|
const mainOptions = commandLineArgs(mainDefinitions, {
|
|
@@ -85,72 +85,7 @@ if (mainOptions.command === 'login') {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (mainOptions.command === 'upload') {
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
name: 'help',
|
|
91
|
-
alias: 'h',
|
|
92
|
-
type: Boolean,
|
|
93
|
-
description: 'Display this usage guide.',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'api-key',
|
|
97
|
-
type: String,
|
|
98
|
-
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: 'host',
|
|
102
|
-
description: '(Optional) Override Sentio Host name',
|
|
103
|
-
type: String,
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: 'owner',
|
|
107
|
-
description: '(Optional) Override Project owner',
|
|
108
|
-
type: String,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: 'nobuild',
|
|
112
|
-
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
113
|
-
type: Boolean,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
name: 'debug',
|
|
117
|
-
description: '(Optional) Set driver logging level to debug',
|
|
118
|
-
type: Boolean,
|
|
119
|
-
},
|
|
120
|
-
]
|
|
121
|
-
const options = commandLineArgs(optionDefinitions, { argv })
|
|
122
|
-
if (options.help) {
|
|
123
|
-
const usage = commandLineUsage([
|
|
124
|
-
{
|
|
125
|
-
header: 'Sentio upload',
|
|
126
|
-
content: 'sentio upload',
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
header: 'Options',
|
|
130
|
-
optionList: optionDefinitions,
|
|
131
|
-
},
|
|
132
|
-
])
|
|
133
|
-
console.log(usage)
|
|
134
|
-
} else {
|
|
135
|
-
if (options.host) {
|
|
136
|
-
processorConfig.host = options.host
|
|
137
|
-
}
|
|
138
|
-
if (options.nobuild) {
|
|
139
|
-
processorConfig.build = false
|
|
140
|
-
}
|
|
141
|
-
if (options.debug) {
|
|
142
|
-
processorConfig.debug = true
|
|
143
|
-
}
|
|
144
|
-
finalizeHost(processorConfig)
|
|
145
|
-
FinalizeProjectName(processorConfig, options.owner)
|
|
146
|
-
console.log(processorConfig)
|
|
147
|
-
|
|
148
|
-
let apiOverride = undefined
|
|
149
|
-
if (options['api-key']) {
|
|
150
|
-
apiOverride = options['api-key']
|
|
151
|
-
}
|
|
152
|
-
uploadFile(processorConfig, apiOverride)
|
|
153
|
-
}
|
|
88
|
+
runUpload(processorConfig, argv)
|
|
154
89
|
} else if (mainOptions.command === 'build') {
|
|
155
90
|
buildProcessor(false)
|
|
156
91
|
} else if (mainOptions.command === 'gen') {
|
|
@@ -26,17 +26,23 @@ export function startServer(params: AuthParams) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
app.get('/callback', async (req, res) => {
|
|
29
|
-
|
|
29
|
+
const fail = function(...args: any[]) {
|
|
30
|
+
console.error(chalk.red(args))
|
|
31
|
+
res.end(args.toString())
|
|
32
|
+
server.close()
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
const host = getFinalizedHost(authParams.sentioHost)
|
|
31
36
|
const code = req.query.code
|
|
32
37
|
if (!code || (code as string).length == 0) {
|
|
38
|
+
fail('Failed to get authorization code')
|
|
33
39
|
return
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
// exchange token
|
|
37
43
|
const tokenResRaw = await getToken(host, code as string)
|
|
38
44
|
if (!tokenResRaw.ok) {
|
|
39
|
-
|
|
45
|
+
fail(`Failed to get access token: ${tokenResRaw.status} ${tokenResRaw.statusText}`)
|
|
40
46
|
return
|
|
41
47
|
}
|
|
42
48
|
const tokenRes = await tokenResRaw.json()
|
|
@@ -46,15 +52,15 @@ app.get('/callback', async (req, res) => {
|
|
|
46
52
|
const userResRaw = await getUser(host, accessToken)
|
|
47
53
|
if (!userResRaw.ok) {
|
|
48
54
|
if (userResRaw.status == 401) {
|
|
49
|
-
|
|
55
|
+
fail('The account does not exist, please sign up on sentio first')
|
|
50
56
|
} else {
|
|
51
|
-
|
|
57
|
+
fail(`Failed to get user info: ${userResRaw.status} ${userResRaw.statusText}`)
|
|
52
58
|
}
|
|
53
59
|
return
|
|
54
60
|
}
|
|
55
61
|
const userRes = await userResRaw.json()
|
|
56
62
|
if (!userRes.emailVerified) {
|
|
57
|
-
|
|
63
|
+
fail('Your account is not verified, please verify your email first')
|
|
58
64
|
return
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -62,13 +68,15 @@ app.get('/callback', async (req, res) => {
|
|
|
62
68
|
const apiKeyName = `${os.hostname()}-${crypto.randomBytes(4).toString('hex')}`
|
|
63
69
|
const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken)
|
|
64
70
|
if (!createApiKeyResRaw.ok) {
|
|
65
|
-
|
|
71
|
+
fail(`Failed to create API key: ${createApiKeyResRaw.status} ${createApiKeyResRaw.statusText}`)
|
|
66
72
|
return
|
|
67
73
|
}
|
|
68
74
|
const createApiKeyRes = await createApiKeyResRaw.json()
|
|
69
75
|
const apiKey = createApiKeyRes['key']
|
|
70
76
|
WriteKey(host, apiKey)
|
|
71
|
-
|
|
77
|
+
|
|
78
|
+
res.end("Login success, please go back to CLI to continue")
|
|
79
|
+
console.log(chalk.green('Login success, new API key: ' + apiKey))
|
|
72
80
|
|
|
73
81
|
server.close()
|
|
74
82
|
})
|
|
@@ -1,15 +1,86 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import commandLineArgs from 'command-line-args'
|
|
2
|
+
import commandLineUsage from 'command-line-usage'
|
|
3
|
+
import { finalizeHost, FinalizeProjectName, SentioProjectConfig } from '../config'
|
|
4
|
+
import { URL } from 'url'
|
|
5
|
+
import fetch from 'node-fetch'
|
|
6
|
+
import { buildProcessor } from '../build'
|
|
7
|
+
import chalk from 'chalk'
|
|
8
|
+
import path from 'path'
|
|
9
|
+
import { ReadKey } from '../key'
|
|
3
10
|
import fs from 'fs'
|
|
11
|
+
import { createHash } from 'crypto'
|
|
12
|
+
import { execSync } from 'child_process'
|
|
13
|
+
import { getSdkVersion } from '../utils'
|
|
4
14
|
import readline from 'readline'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
export async function runUpload(processorConfig: SentioProjectConfig, argv: string[]) {
|
|
17
|
+
const optionDefinitions = [
|
|
18
|
+
{
|
|
19
|
+
name: 'help',
|
|
20
|
+
alias: 'h',
|
|
21
|
+
type: Boolean,
|
|
22
|
+
description: 'Display this usage guide.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'api-key',
|
|
26
|
+
type: String,
|
|
27
|
+
description: '(Optional) Manually provide API key rather than use saved credential',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'host',
|
|
31
|
+
description: '(Optional) Override Sentio Host name',
|
|
32
|
+
type: String,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'owner',
|
|
36
|
+
description: '(Optional) Override Project owner',
|
|
37
|
+
type: String,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'nobuild',
|
|
41
|
+
description: '(Optional) Skip build & pack file before uploading, default false',
|
|
42
|
+
type: Boolean,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'debug',
|
|
46
|
+
description: '(Optional) Run driver in debug mode, default false',
|
|
47
|
+
type: Boolean,
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
const options = commandLineArgs(optionDefinitions, { argv })
|
|
51
|
+
if (options.help) {
|
|
52
|
+
const usage = commandLineUsage([
|
|
53
|
+
{
|
|
54
|
+
header: 'Sentio upload',
|
|
55
|
+
content: 'sentio upload',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
header: 'Options',
|
|
59
|
+
optionList: optionDefinitions,
|
|
60
|
+
},
|
|
61
|
+
])
|
|
62
|
+
console.log(usage)
|
|
63
|
+
} else {
|
|
64
|
+
if (options.host) {
|
|
65
|
+
processorConfig.host = options.host
|
|
66
|
+
}
|
|
67
|
+
if (options.nobuild) {
|
|
68
|
+
processorConfig.build = false
|
|
69
|
+
}
|
|
70
|
+
if (options.debug) {
|
|
71
|
+
processorConfig.debug = true
|
|
72
|
+
}
|
|
73
|
+
finalizeHost(processorConfig)
|
|
74
|
+
FinalizeProjectName(processorConfig, options.owner)
|
|
75
|
+
console.log(processorConfig)
|
|
76
|
+
|
|
77
|
+
let apiOverride = undefined
|
|
78
|
+
if (options['api-key']) {
|
|
79
|
+
apiOverride = options['api-key']
|
|
80
|
+
}
|
|
81
|
+
return uploadFile(processorConfig, apiOverride)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
13
84
|
|
|
14
85
|
async function createProject(options: SentioProjectConfig, apiKey: string) {
|
|
15
86
|
const url = new URL('/api/v1/projects', options.host)
|
package/lib/upload.d.ts
DELETED
package/lib/upload.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAwC;AACxC,mCAAmC;AACnC,4CAAmB;AACnB,wDAA+B;AAE/B,+BAA+B;AAC/B,gDAAuB;AACvB,kDAAyB;AACzB,mCAAwC;AACxC,4DAA8B;AAC9B,mCAAuC;AACvC,6BAAyB;AAEzB,KAAK,UAAU,aAAa,CAAC,OAA4B,EAAE,MAAc;IACvE,MAAM,GAAG,GAAG,IAAI,SAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACrD,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,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nB,YAAY,EAAE,WAAW;YACzB,WAAW,EAAE,UAAU;YACvB,MAAM,EAAE,MAAM;YACd,UAAU,EAAE,SAAS;YACrB,OAAO,EAAE,MAAM;YACf,KAAK,EAAE,KAAK;SACb,CAAC;KACH,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport fs from 'fs'\nimport readline from 'readline'\nimport { SentioProjectConfig } from './config'\nimport { ReadKey } from './key'\nimport path from 'path'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport fetch from 'node-fetch'\nimport { getSdkVersion } from './utils'\nimport { URL } from 'url'\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n const [ownerName, slug] = options.project.includes('/') ? options.project.split('/') : [undefined, options.project]\n return fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug, ownerName, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n let triedCount = 0\n const upload = async () => {\n let commitSha = ''\n let gitUrl = ''\n const sha256 = digest\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n } catch (e) {\n chalk.yellow(e)\n }\n try {\n gitUrl = execSync('git remote get-url origin').toString().trim()\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n\n // get gcs upload url\n const initUploadResRaw = await initUpload(options.host, apiKey, options.project, getSdkVersion())\n if (!initUploadResRaw.ok) {\n console.error(chalk.red('Failed to get upload url'))\n console.error(chalk.red((await initUploadResRaw.json()).message))\n\n if (initUploadResRaw.status === 404) {\n // create project if not exist\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red((await res.json()).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n return\n }\n const initUploadRes = await initUploadResRaw.json()\n const uploadUrl = initUploadRes['url'] as string\n\n // do actual uploading\n const file = fs.createReadStream(PROCESSOR_FILE)\n const uploadResRaw = await fetch(uploadUrl, {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/octet-stream',\n },\n body: file,\n })\n if (!uploadResRaw.ok) {\n console.error(chalk.red('Failed to upload'))\n console.error(chalk.red(await uploadResRaw.text()))\n return\n }\n\n // finish uploading\n const finishUploadResRaw = await finishUpload(\n options.host,\n apiKey,\n options.project,\n getSdkVersion(),\n sha256,\n commitSha,\n gitUrl,\n options.debug\n )\n if (!finishUploadResRaw.ok) {\n console.error(chalk.red('Failed to finish uploading'))\n console.error(chalk.red(await finishUploadResRaw.text()))\n return\n }\n\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { projectFullSlug, version } = await finishUploadResRaw.json()\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${projectFullSlug}/datasource`)\n console.log('\\t', chalk.blue('Version:'), version)\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n\nasync function initUpload(host: string, apiKey: string, projectSlug: string, sdkVersion: string) {\n const initUploadUrl = new URL(`/api/v1/processors/init_upload`, host)\n return fetch(initUploadUrl, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n }),\n })\n}\n\nasync function finishUpload(\n host: string,\n apiKey: string,\n projectSlug: string,\n sdkVersion: string,\n sha256: string,\n commitSha: string,\n gitUrl: string,\n debug: boolean\n) {\n const finishUploadUrl = new URL(`/api/v1/processors/finish_upload`, host)\n return fetch(finishUploadUrl, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({\n project_slug: projectSlug,\n sdk_version: sdkVersion,\n sha256: sha256,\n commit_sha: commitSha,\n git_url: gitUrl,\n debug: debug,\n }),\n })\n}\n"]}
|