@sentio/sdk 1.35.1-rc.1 → 1.36.0-rc.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/lib/aptos-codegen/codegen.d.ts +1 -0
- package/lib/aptos-codegen/codegen.js +9 -1
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +8 -1
- package/lib/core/base-processor-template.js +13 -4
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/service.d.ts +1 -3
- package/lib/service.js +9 -41
- package/lib/service.js.map +1 -1
- package/lib/solana-codegen/codegen.d.ts +1 -0
- package/lib/{cli/build.js → solana-codegen/codegen.js} +3 -92
- package/lib/solana-codegen/codegen.js.map +1 -0
- package/lib/state/processor-state.d.ts +0 -5
- package/lib/state/processor-state.js +0 -5
- package/lib/state/processor-state.js.map +1 -1
- package/lib/test-abi-code-gen.js +4 -3
- package/lib/test-abi-code-gen.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +0 -2
- package/lib/testing/test-processor-server.js +7 -17
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +3 -11
- package/src/aptos-codegen/codegen.ts +8 -0
- package/src/core/base-processor-template.ts +14 -4
- package/src/service.ts +9 -57
- package/src/{cli/build.ts → solana-codegen/codegen.ts} +1 -113
- package/src/state/processor-state.ts +0 -11
- package/src/test-abi-code-gen.ts +2 -1
- package/src/testing/test-processor-server.ts +7 -19
- package/lib/cli/build.d.ts +0 -4
- package/lib/cli/build.js.map +0 -1
- package/lib/cli/cli.d.ts +0 -2
- package/lib/cli/cli.js +0 -186
- package/lib/cli/cli.js.map +0 -1
- package/lib/cli/commands/login-server.d.ts +0 -7
- package/lib/cli/commands/login-server.js +0 -133
- package/lib/cli/commands/login-server.js.map +0 -1
- package/lib/cli/commands/run-create.d.ts +0 -1
- package/lib/cli/commands/run-create.js +0 -111
- package/lib/cli/commands/run-create.js.map +0 -1
- package/lib/cli/commands/run-login.d.ts +0 -1
- package/lib/cli/commands/run-login.js +0 -136
- package/lib/cli/commands/run-login.js.map +0 -1
- package/lib/cli/commands/run-version.d.ts +0 -1
- package/lib/cli/commands/run-version.js +0 -39
- package/lib/cli/commands/run-version.js.map +0 -1
- package/lib/cli/config.d.ts +0 -14
- package/lib/cli/config.js +0 -64
- package/lib/cli/config.js.map +0 -1
- package/lib/cli/key.d.ts +0 -2
- package/lib/cli/key.js +0 -44
- package/lib/cli/key.js.map +0 -1
- package/lib/cli/upload.d.ts +0 -2
- package/lib/cli/upload.js +0 -189
- package/lib/cli/upload.js.map +0 -1
- package/lib/cli/utils.d.ts +0 -1
- package/lib/cli/utils.js +0 -16
- package/lib/cli/utils.js.map +0 -1
- package/lib/cli/webpack.config.js +0 -47
- package/src/cli/cli.ts +0 -184
- package/src/cli/commands/login-server.ts +0 -119
- package/src/cli/commands/run-create.ts +0 -115
- package/src/cli/commands/run-login.ts +0 -111
- package/src/cli/commands/run-version.ts +0 -32
- package/src/cli/config.ts +0 -72
- package/src/cli/key.ts +0 -43
- package/src/cli/upload.ts +0 -214
- package/src/cli/utils.ts +0 -10
- package/src/cli/webpack.config.js +0 -47
- package/templates/aptos/abis/aptos/souffle.json +0 -389
- package/templates/aptos/jest.config.js +0 -7
- package/templates/aptos/package.json +0 -20
- package/templates/aptos/sentio.yaml +0 -1
- package/templates/aptos/src/processor.ts +0 -13
- package/templates/aptos/tsconfig.json +0 -20
- package/templates/evm/abis/evm/x2y2.json +0 -296
- package/templates/evm/jest.config.js +0 -7
- package/templates/evm/package.json +0 -20
- package/templates/evm/sentio.yaml +0 -3
- package/templates/evm/src/processor.ts +0 -29
- package/templates/evm/tsconfig.json +0 -20
- package/templates/raw/jest.config.js +0 -7
- package/templates/raw/package.json +0 -20
- package/templates/raw/sentio.yaml +0 -3
- package/templates/raw/src/processor.ts +0 -0
- package/templates/raw/tsconfig.json +0 -20
- package/templates/raw/yarn.lock +0 -4095
|
@@ -1,94 +1,6 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
1
|
import path from 'path'
|
|
3
2
|
import fs from 'fs'
|
|
4
|
-
import
|
|
5
|
-
import { generate } from '../aptos-codegen/codegen'
|
|
6
|
-
// import { EVM, SOLANA, Target } from './config'
|
|
7
|
-
|
|
8
|
-
export async function buildProcessor(onlyGen: boolean) {
|
|
9
|
-
if (!onlyGen) {
|
|
10
|
-
await installDeps()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// targets.forEach(async (target) => await buildProcessorForTarget(onlyGen, target))
|
|
14
|
-
// for (const target) {
|
|
15
|
-
await buildProcessorForTarget(onlyGen)
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
if (!onlyGen) {
|
|
19
|
-
const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')
|
|
20
|
-
await execStep('yarn tsc -p .', 'Compile')
|
|
21
|
-
await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function buildProcessorForTarget(onlyGen: boolean) {
|
|
26
|
-
await codeGenEthersProcessor(path.join('abis', 'evm'))
|
|
27
|
-
codeGenSolanaProcessor(path.join('abis', 'solana'))
|
|
28
|
-
codeGenAptosProcessor(path.join('abis', 'aptos'))
|
|
29
|
-
|
|
30
|
-
if (onlyGen) {
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function installDeps() {
|
|
36
|
-
await execStep('yarn install --ignore-scripts', 'Yarn Install')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {
|
|
40
|
-
if (!fs.existsSync(abisDir)) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// const files = fs.readdirSync(abisDir)
|
|
45
|
-
|
|
46
|
-
console.log(chalk.green('Generated Types for Aptos'))
|
|
47
|
-
|
|
48
|
-
generate(abisDir, outDir)
|
|
49
|
-
// for (const file of files) {
|
|
50
|
-
// if (path.extname(file) === '.json') {
|
|
51
|
-
// if (!fs.existsSync(outDir)) {
|
|
52
|
-
// fs.mkdirSync(outDir, { recursive: true })
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
55
|
-
// const codegen = new AptosAccountCodegen({
|
|
56
|
-
// srcFile: path.join(abisDir, file),
|
|
57
|
-
// outputDir: outDir,
|
|
58
|
-
// })
|
|
59
|
-
// codegen.generate()
|
|
60
|
-
// }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function codeGenEthersProcessor(
|
|
64
|
-
abisDir: string,
|
|
65
|
-
ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),
|
|
66
|
-
outDir = 'src/types/internal'
|
|
67
|
-
) {
|
|
68
|
-
if (!fs.existsSync(abisDir)) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let haveJson = false
|
|
73
|
-
const files = fs.readdirSync(abisDir)
|
|
74
|
-
for (const file of files) {
|
|
75
|
-
if (file.toLowerCase().endsWith('.json')) {
|
|
76
|
-
haveJson = true
|
|
77
|
-
break
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (!haveJson) {
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
console.log(chalk.green('Generated Types for EVM'))
|
|
85
|
-
|
|
86
|
-
// TODO this will fail during postinstall, need to locate real typechain path
|
|
87
|
-
await execStep(
|
|
88
|
-
'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,
|
|
89
|
-
'Type definitions gen'
|
|
90
|
-
)
|
|
91
|
-
}
|
|
3
|
+
import chalk from 'chalk'
|
|
92
4
|
|
|
93
5
|
export function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {
|
|
94
6
|
if (!fs.existsSync(abisDir)) {
|
|
@@ -202,27 +114,3 @@ function toPascalCase(str: string) {
|
|
|
202
114
|
.replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
|
|
203
115
|
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
|
|
204
116
|
}
|
|
205
|
-
|
|
206
|
-
async function execStep(cmd: string, stepName: string) {
|
|
207
|
-
const child = exec(cmd)
|
|
208
|
-
console.log(chalk.blue(stepName + ' begin'))
|
|
209
|
-
|
|
210
|
-
if (!child.stdout || !child.stderr) {
|
|
211
|
-
console.error(chalk.red(stepName + ' failed'))
|
|
212
|
-
process.exit(1)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
child.stdout.pipe(process.stdout)
|
|
216
|
-
child.stderr.pipe(process.stderr)
|
|
217
|
-
|
|
218
|
-
await new Promise((resolve) => {
|
|
219
|
-
child.on('close', resolve)
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
if (child.exitCode) {
|
|
223
|
-
console.error(chalk.red(stepName + ' failed'))
|
|
224
|
-
process.exit(child.exitCode)
|
|
225
|
-
}
|
|
226
|
-
console.log(chalk.blue(stepName + ' success'))
|
|
227
|
-
console.log()
|
|
228
|
-
}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import { BoundContractView, BaseProcessorTemplate } from '../core'
|
|
2
|
-
|
|
3
|
-
import { BaseContract } from 'ethers'
|
|
4
|
-
import { TemplateInstance } from '../gen'
|
|
5
|
-
|
|
6
1
|
export class ProcessorState {
|
|
7
|
-
// all evm processors
|
|
8
|
-
templates: BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>[] = []
|
|
9
|
-
// evm processor template instances spec
|
|
10
|
-
templatesInstances: TemplateInstance[] = []
|
|
11
|
-
|
|
12
|
-
// TODO move above to state map
|
|
13
2
|
stateMap = new Map<string, any>()
|
|
14
3
|
}
|
package/src/test-abi-code-gen.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { codeGenAptosProcessor, codeGenSolanaProcessor } from './cli/build'
|
|
4
3
|
import path from 'path'
|
|
4
|
+
import { codeGenSolanaProcessor } from './solana-codegen/codegen'
|
|
5
|
+
import { codeGenAptosProcessor } from './aptos-codegen/codegen'
|
|
5
6
|
|
|
6
7
|
if (process.argv.length > 3) {
|
|
7
8
|
const abisDir = process.argv[2]
|
|
@@ -71,24 +71,12 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
71
71
|
return this.service.getConfig(request, context)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
//
|
|
75
|
-
// return this.service.
|
|
74
|
+
// processLogs(request: ProcessBindingsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
75
|
+
// return this.service.processLogs(request, context)
|
|
76
76
|
// }
|
|
77
77
|
//
|
|
78
|
-
//
|
|
79
|
-
// return this.service.
|
|
80
|
-
// }
|
|
81
|
-
|
|
82
|
-
processLogs(request: ProcessBindingsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
83
|
-
return this.service.processLogs(request, context)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
processTraces(request: ProcessBindingsRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
87
|
-
return this.service.processTraces(request, context)
|
|
88
|
-
}
|
|
89
|
-
//
|
|
90
|
-
// processTransactions(request: ProcessTransactionsRequest, context = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
91
|
-
// return this.service.processTransactions(request, context)
|
|
78
|
+
// processTraces(request: ProcessBindingsRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessBindingResponse> {
|
|
79
|
+
// return this.service.processTraces(request, context)
|
|
92
80
|
// }
|
|
93
81
|
|
|
94
82
|
testTrace(trace: Trace, network: Networkish = 1): Promise<ProcessBindingResponse> {
|
|
@@ -104,7 +92,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
104
92
|
}
|
|
105
93
|
bindings.push(binding)
|
|
106
94
|
}
|
|
107
|
-
return this.
|
|
95
|
+
return this.processBindings({
|
|
108
96
|
bindings: bindings,
|
|
109
97
|
})
|
|
110
98
|
}
|
|
@@ -151,7 +139,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
151
139
|
}
|
|
152
140
|
bindings.push(binding)
|
|
153
141
|
}
|
|
154
|
-
return this.
|
|
142
|
+
return this.processBindings({
|
|
155
143
|
bindings: bindings,
|
|
156
144
|
})
|
|
157
145
|
}
|
|
@@ -213,7 +201,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
213
201
|
}
|
|
214
202
|
bindings.push(binding)
|
|
215
203
|
}
|
|
216
|
-
return this.
|
|
204
|
+
return this.processBindings({
|
|
217
205
|
bindings: bindings,
|
|
218
206
|
})
|
|
219
207
|
}
|
package/lib/cli/build.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function buildProcessor(onlyGen: boolean): Promise<void>;
|
|
2
|
-
export declare function codeGenAptosProcessor(abisDir: string, outDir?: string): void;
|
|
3
|
-
export declare function codeGenEthersProcessor(abisDir: string, ETHERS_TARGET?: string, outDir?: string): Promise<void>;
|
|
4
|
-
export declare function codeGenSolanaProcessor(abisDir: string, targetPath?: string): void;
|
package/lib/cli/build.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,gDAAuB;AACvB,4CAAmB;AACnB,iDAAoC;AACpC,sDAAmD;AACnD,iDAAiD;AAE1C,KAAK,UAAU,cAAc,CAAC,OAAgB;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,WAAW,EAAE,CAAA;KACpB;IAED,oFAAoF;IACpF,uBAAuB;IACvB,MAAM,uBAAuB,CAAC,OAAO,CAAC,CAAA;IACtC,IAAI;IAEJ,IAAI,CAAC,OAAO,EAA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C,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;KAC7B;IACD,OAAO,CAAC,GAAG,CAAC,eAAK,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 { generate } from '../aptos-codegen/codegen'\n// import { EVM, SOLANA, Target } from './config'\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 const WEBPACK_CONFIG = path.join(__dirname, 'webpack.config.js')\n await execStep('yarn tsc -p .', 'Compile')\n await execStep('yarn webpack --config=' + WEBPACK_CONFIG, 'Packaging')\n }\n}\n\nasync function buildProcessorForTarget(onlyGen: boolean) {\n await codeGenEthersProcessor(path.join('abis', 'evm'))\n codeGenSolanaProcessor(path.join('abis', 'solana'))\n codeGenAptosProcessor(path.join('abis', 'aptos'))\n\n if (onlyGen) {\n return\n }\n}\n\nasync function installDeps() {\n await execStep('yarn install --ignore-scripts', 'Yarn Install')\n}\n\nexport function codeGenAptosProcessor(abisDir: string, outDir = 'src/types/aptos') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n // const files = fs.readdirSync(abisDir)\n\n console.log(chalk.green('Generated Types for Aptos'))\n\n generate(abisDir, outDir)\n // for (const file of files) {\n // if (path.extname(file) === '.json') {\n // if (!fs.existsSync(outDir)) {\n // fs.mkdirSync(outDir, { recursive: true })\n // }\n // }\n // const codegen = new AptosAccountCodegen({\n // srcFile: path.join(abisDir, file),\n // outputDir: outDir,\n // })\n // codegen.generate()\n // }\n}\n\nexport async function codeGenEthersProcessor(\n abisDir: string,\n ETHERS_TARGET = path.join(__dirname, '../target-ethers-sentio'),\n outDir = 'src/types/internal'\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n let haveJson = false\n const files = fs.readdirSync(abisDir)\n for (const file of files) {\n if (file.toLowerCase().endsWith('.json')) {\n haveJson = true\n break\n }\n }\n if (!haveJson) {\n return\n }\n\n console.log(chalk.green('Generated Types for EVM'))\n\n // TODO this will fail during postinstall, need to locate real typechain path\n await execStep(\n 'yarn typechain --target ' + ETHERS_TARGET + ` --out-dir ${outDir} ${path.join(abisDir, '*.json')}`,\n 'Type definitions gen'\n )\n}\n\nexport function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n\n const abisFiles = fs.readdirSync(abisDir)\n\n if (abisFiles.length > 0) {\n console.log(chalk.green('Generated Types for Solana'))\n }\n\n for (const file of abisFiles) {\n if (path.extname(file) === '.json') {\n if (!fs.existsSync(targetPath)) {\n fs.mkdirSync(targetPath, { recursive: true })\n }\n const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')\n const idlObj = JSON.parse(idlContent)\n const idlName = idlObj.name\n const idlFile = path.join(targetPath, idlName + '.ts')\n fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)\n fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))\n }\n }\n}\n\nfunction codeGenSolanaIdlProcessor(idlObj: any): string {\n const idlName = idlObj.name\n const idlNamePascalCase = toPascalCase(idlName)\n const instructions: any[] = idlObj.instructions\n return `import { BorshInstructionCoder, Instruction, Idl, BN } from '@project-serum/anchor'\nimport { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from \"@sentio/sdk\"\nimport { ${idlName}_idl } from \"./${idlName}\"\nimport bs58 from 'bs58'\nimport { PublicKey } from '@solana/web3.js'\n\nexport class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {\n static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {\n if (options && !options.name) {\n options.name = '${idlNamePascalCase}'\n }\n return new ${idlNamePascalCase}Processor(options)\n }\n\n decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {\n const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)\n const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))\n return decodedIns\n }\n\n ${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}\n}\n `\n}\n\nfunction codeGenSolanaInstruction(idlName: string, ins: any): string {\n const instructionName = ins.name\n const argsTypeString = codeGenInstructionArgs(ins.args)\n return `\n on${\n instructionName.charAt(0).toUpperCase() + instructionName.slice(1)\n }(handler: (args: ${argsTypeString}, accounts: string[], ctx: SolanaContext) => void): ${idlName}Processor {\n this.onInstruction('${instructionName}', (ins: Instruction, ctx, accounts: string[]) => {\n if (ins) {\n handler(ins.data as ${argsTypeString}, accounts, ctx)\n }\n })\n return this\n }\n `\n}\n\nfunction codeGenInstructionArgs(args: { name: string; type: string }[]): string {\n return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`\n}\n\n// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104\nfunction mapType(tpe: string): string {\n switch (tpe) {\n case 'publicKey':\n return 'PublicKey'\n case 'bool':\n return 'boolean'\n case 'string':\n return 'string'\n case 'u8':\n case 'i8':\n case 'u16':\n case 'i16':\n case 'u32':\n case 'i32':\n case 'f32':\n case 'f64':\n return 'number'\n case 'u64':\n case 'i64':\n case 'u128':\n case 'i128':\n return 'BN'\n default:\n return 'any'\n }\n}\n\nfunction toPascalCase(str: string) {\n return `${str}`\n .toLowerCase()\n .replace(new RegExp(/[-_]+/, 'g'), ' ')\n .replace(new RegExp(/[^\\w\\s]/, 'g'), '')\n .replace(new RegExp(/\\s+(.)(\\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)\n .replace(new RegExp(/\\w/), (s) => s.toUpperCase())\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/cli.d.ts
DELETED
package/lib/cli/cli.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const command_line_args_1 = __importDefault(require("command-line-args"));
|
|
8
|
-
const command_line_usage_1 = __importDefault(require("command-line-usage"));
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
12
|
-
const config_1 = require("./config");
|
|
13
|
-
const upload_1 = require("./upload");
|
|
14
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
15
|
-
const build_1 = require("./build");
|
|
16
|
-
const run_create_1 = require("./commands/run-create");
|
|
17
|
-
const run_version_1 = require("./commands/run-version");
|
|
18
|
-
const run_login_1 = require("./commands/run-login");
|
|
19
|
-
const mainDefinitions = [{ name: 'command', defaultOption: true }];
|
|
20
|
-
const mainOptions = (0, command_line_args_1.default)(mainDefinitions, {
|
|
21
|
-
stopAtFirstUnknown: true,
|
|
22
|
-
});
|
|
23
|
-
const argv = mainOptions._unknown || [];
|
|
24
|
-
if (!mainOptions.command) {
|
|
25
|
-
usage();
|
|
26
|
-
}
|
|
27
|
-
if (mainOptions.command === 'login') {
|
|
28
|
-
(0, run_login_1.runLogin)(argv);
|
|
29
|
-
}
|
|
30
|
-
else if (mainOptions.command === 'create') {
|
|
31
|
-
(0, run_create_1.runCreate)(argv);
|
|
32
|
-
}
|
|
33
|
-
else if (mainOptions.command === 'version') {
|
|
34
|
-
(0, run_version_1.runVersion)(argv);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// For all the commands that need read project configs
|
|
38
|
-
// TODO move them to their own modules
|
|
39
|
-
// Process configs
|
|
40
|
-
let processorConfig = { host: '', project: '', build: true, debug: false };
|
|
41
|
-
// Fist step, read from project yaml file
|
|
42
|
-
try {
|
|
43
|
-
console.log(chalk_1.default.blue('Loading Process config'));
|
|
44
|
-
// TODO correctly located sentio.yaml
|
|
45
|
-
const pwd = process.cwd();
|
|
46
|
-
const packageJson = path_1.default.join(pwd, 'package.json');
|
|
47
|
-
if (!fs_1.default.existsSync(packageJson)) {
|
|
48
|
-
console.error('package.json not found, please run this command in the root of your project');
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
const yamlPath = path_1.default.join(pwd, 'sentio.yaml');
|
|
52
|
-
if (!fs_1.default.existsSync(yamlPath)) {
|
|
53
|
-
console.error('sentio.yaml not found, please create one according to: TODO docs');
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
56
|
-
processorConfig = js_yaml_1.default.load(fs_1.default.readFileSync('sentio.yaml', 'utf8'));
|
|
57
|
-
if (!processorConfig.project === undefined) {
|
|
58
|
-
console.error('Config yaml must have contain a valid project identifier');
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
if (processorConfig.build === undefined) {
|
|
62
|
-
processorConfig.build = true;
|
|
63
|
-
}
|
|
64
|
-
if (!processorConfig.host) {
|
|
65
|
-
processorConfig.host = 'prod';
|
|
66
|
-
}
|
|
67
|
-
if (processorConfig.debug === undefined) {
|
|
68
|
-
processorConfig.debug = false;
|
|
69
|
-
}
|
|
70
|
-
// if (!processorConfig.source) {
|
|
71
|
-
// processorConfig.source = 'src/processor.ts'
|
|
72
|
-
// }
|
|
73
|
-
// if (!processorConfig.targets) {
|
|
74
|
-
// console.warn('targets is not defined, use EVM as the default target')
|
|
75
|
-
// processorConfig.targets = []
|
|
76
|
-
// }
|
|
77
|
-
// if (processorConfig.targets.length === 0) {
|
|
78
|
-
// // By default evm
|
|
79
|
-
// processorConfig.targets.push({ chain: EVM })
|
|
80
|
-
// }
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
console.error(e);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
}
|
|
86
|
-
if (mainOptions.command === 'upload') {
|
|
87
|
-
const optionDefinitions = [
|
|
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
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (mainOptions.command === 'build') {
|
|
155
|
-
(0, build_1.buildProcessor)(false);
|
|
156
|
-
}
|
|
157
|
-
else if (mainOptions.command === 'gen') {
|
|
158
|
-
(0, build_1.buildProcessor)(true);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
usage();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function usage() {
|
|
165
|
-
const usage = (0, command_line_usage_1.default)([
|
|
166
|
-
{
|
|
167
|
-
header: 'Sentio',
|
|
168
|
-
content: 'Login & Manage your project files to Sentio.',
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
header: 'Usage',
|
|
172
|
-
content: [
|
|
173
|
-
'sentio <command> --help\t\tshow detail usage of specific command',
|
|
174
|
-
'sentio login\t\t\t\tlogin to sentio',
|
|
175
|
-
'sentio create\t\t\t\tcreate a template project',
|
|
176
|
-
'sentio upload\t\t\t\tbuild and upload processor to sentio',
|
|
177
|
-
'sentio gen\t\t\t\tgenerate abi',
|
|
178
|
-
'sentio build\t\t\t\tgenerate abi and build',
|
|
179
|
-
'sentio version\t\t\tcurrent cli version',
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
]);
|
|
183
|
-
console.log(usage);
|
|
184
|
-
process.exit(1);
|
|
185
|
-
}
|
|
186
|
-
//# sourceMappingURL=cli.js.map
|
package/lib/cli/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;;;;AAEA,0EAA+C;AAC/C,4EAAiD;AACjD,4CAAmB;AACnB,gDAAuB;AAEvB,sDAA0B;AAC1B,qCAAiF;AACjF,qCAAqC;AACrC,kDAAyB;AACzB,mCAAwC;AACxC,sDAAiD;AACjD,wDAAmD;AACnD,oDAA+C;AAE/C,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,IA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C;QAC7B;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE,8CAA8C;SACxD;QACD;YACE,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,kEAAkE;gBAClE,qCAAqC;gBACrC,gDAAgD;gBAChD,2DAA2D;gBAC3D,gCAAgC;gBAChC,4CAA4C;gBAC5C,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 { finalizeHost, FinalizeProjectName, SentioProjectConfig } from './config'\nimport { uploadFile } from './upload'\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'\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 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) Set driver logging level to debug',\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 uploadFile(processorConfig, apiOverride)\n }\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"]}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.startServer = void 0;
|
|
30
|
-
const express_1 = __importDefault(require("express"));
|
|
31
|
-
const config_1 = require("../config");
|
|
32
|
-
const url_1 = __importStar(require("url"));
|
|
33
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
34
|
-
const utils_1 = require("../utils");
|
|
35
|
-
const key_1 = require("../key");
|
|
36
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
37
|
-
const os_1 = __importDefault(require("os"));
|
|
38
|
-
const crypto = __importStar(require("crypto"));
|
|
39
|
-
const app = (0, express_1.default)();
|
|
40
|
-
let server;
|
|
41
|
-
let authParams;
|
|
42
|
-
function startServer(params) {
|
|
43
|
-
authParams = params;
|
|
44
|
-
server = app.listen(params.serverPort);
|
|
45
|
-
}
|
|
46
|
-
exports.startServer = startServer;
|
|
47
|
-
app.get('/callback', async (req, res) => {
|
|
48
|
-
res.end('login success, please go back to CLI to continue');
|
|
49
|
-
const host = (0, config_1.getFinalizedHost)(authParams.sentioHost);
|
|
50
|
-
const code = req.query.code;
|
|
51
|
-
if (!code || code.length == 0) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// exchange token
|
|
55
|
-
const tokenResRaw = await getToken(host, code);
|
|
56
|
-
if (!tokenResRaw.ok) {
|
|
57
|
-
console.error(chalk_1.default.red('request token error, code:', tokenResRaw.status, tokenResRaw.statusText));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const tokenRes = await tokenResRaw.json();
|
|
61
|
-
const accessToken = tokenRes['access_token'];
|
|
62
|
-
// check if the account is ready
|
|
63
|
-
const userResRaw = await getUser(host, accessToken);
|
|
64
|
-
if (!userResRaw.ok) {
|
|
65
|
-
if (userResRaw.status == 401) {
|
|
66
|
-
console.error(chalk_1.default.red('please sign up on sentio first'));
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
console.error(chalk_1.default.red('get user error, code:', userResRaw.status, userResRaw.statusText));
|
|
70
|
-
}
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const userRes = await userResRaw.json();
|
|
74
|
-
if (!userRes.emailVerified) {
|
|
75
|
-
console.error(chalk_1.default.red('please verify your email first'));
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// create API key
|
|
79
|
-
const apiKeyName = `${os_1.default.hostname()}-${crypto.randomBytes(4).toString('hex')}`;
|
|
80
|
-
const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken);
|
|
81
|
-
if (!createApiKeyResRaw.ok) {
|
|
82
|
-
console.error(chalk_1.default.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const createApiKeyRes = await createApiKeyResRaw.json();
|
|
86
|
-
const apiKey = createApiKeyRes['key'];
|
|
87
|
-
(0, key_1.WriteKey)(host, apiKey);
|
|
88
|
-
console.log(chalk_1.default.green('login success, new API key: ' + apiKey));
|
|
89
|
-
server.close();
|
|
90
|
-
});
|
|
91
|
-
async function getToken(host, code) {
|
|
92
|
-
const authConf = (0, config_1.getAuthConfig)(host);
|
|
93
|
-
const params = new url_1.default.URLSearchParams({
|
|
94
|
-
grant_type: 'authorization_code',
|
|
95
|
-
client_id: authConf.clientId,
|
|
96
|
-
code_verifier: authParams.codeVerifier,
|
|
97
|
-
code: code,
|
|
98
|
-
redirect_uri: `http://localhost:${authParams.serverPort}/callback`,
|
|
99
|
-
});
|
|
100
|
-
return (0, node_fetch_1.default)(`${authConf.domain}/oauth/token`, {
|
|
101
|
-
method: 'POST',
|
|
102
|
-
headers: {
|
|
103
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
104
|
-
},
|
|
105
|
-
body: params.toString(),
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async function createApiKey(host, name, source, accessToken) {
|
|
109
|
-
const createApiKeyUrl = new url_1.URL('/api/v1/keys', host);
|
|
110
|
-
return (0, node_fetch_1.default)(createApiKeyUrl, {
|
|
111
|
-
method: 'POST',
|
|
112
|
-
headers: {
|
|
113
|
-
Authorization: 'Bearer ' + accessToken,
|
|
114
|
-
version: (0, utils_1.getCliVersion)(),
|
|
115
|
-
},
|
|
116
|
-
body: JSON.stringify({
|
|
117
|
-
name: name,
|
|
118
|
-
scopes: ['write:project'],
|
|
119
|
-
source: source,
|
|
120
|
-
}),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
async function getUser(host, accessToken) {
|
|
124
|
-
const getUserUrl = new url_1.URL('/api/v1/users', host);
|
|
125
|
-
return (0, node_fetch_1.default)(getUserUrl, {
|
|
126
|
-
method: 'GET',
|
|
127
|
-
headers: {
|
|
128
|
-
Authorization: 'Bearer ' + accessToken,
|
|
129
|
-
version: (0, utils_1.getCliVersion)(),
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=login-server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"login-server.js","sourceRoot":"","sources":["../../../src/cli/commands/login-server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA6B;AAC7B,sCAA2D;AAC3D,2CAA8B;AAC9B,4DAA8B;AAC9B,oCAAwC;AACxC,gCAAiC;AACjC,kDAAyB;AAEzB,4CAAmB;AACnB,+CAAgC;AAQhC,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAA;AAErB,IAAI,MAAmB,CAAA;AACvB,IAAI,UAAsB,CAAA;AAE1B,SAAgB,WAAW,CAAC,MAAkB;I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QAChC,SAAS,EAAE,QAAQ,CAAC,QAAQ;QAC5B,aAAa,EAAE,UAAU,CAAC,YAAY;QACtC,IAAI,EAAE,IAAI;QACV,YAAY,EAAE,oBAAoB,UAAU,CAAC,UAAU,WAAW;KACnE,CAAC,CAAA;IACF,OAAO,IAAA,oBAAK,EAAC,GAAG,QAAQ,CAAC,MAAM,cAAc,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 res.end('login success, please go back to CLI to continue')\n const host = getFinalizedHost(authParams.sentioHost)\n const code = req.query.code\n if (!code || (code as string).length == 0) {\n return\n }\n\n // exchange token\n const tokenResRaw = await getToken(host, code as string)\n if (!tokenResRaw.ok) {\n console.error(chalk.red('request token error, code:', 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 console.error(chalk.red('please sign up on sentio first'))\n } else {\n console.error(chalk.red('get user error, code:', userResRaw.status, userResRaw.statusText))\n }\n return\n }\n const userRes = await userResRaw.json()\n if (!userRes.emailVerified) {\n console.error(chalk.red('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 console.error(chalk.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText))\n return\n }\n const createApiKeyRes = await createApiKeyResRaw.json()\n const apiKey = createApiKeyRes['key']\n WriteKey(host, apiKey)\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function runCreate(argv: string[]): void;
|