@sentio/cli 1.37.5-rc.7 → 2.0.0-development

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.
Files changed (68) hide show
  1. package/lib/index.js +125 -0
  2. package/package.json +42 -41
  3. package/lib/build.d.ts +0 -2
  4. package/lib/build.js +0 -86
  5. package/lib/build.js.map +0 -1
  6. package/lib/cli.d.ts +0 -2
  7. package/lib/cli.js +0 -186
  8. package/lib/cli.js.map +0 -1
  9. package/lib/commands/login-server.d.ts +0 -7
  10. package/lib/commands/login-server.js +0 -133
  11. package/lib/commands/login-server.js.map +0 -1
  12. package/lib/commands/run-create.d.ts +0 -1
  13. package/lib/commands/run-create.js +0 -121
  14. package/lib/commands/run-create.js.map +0 -1
  15. package/lib/commands/run-login.d.ts +0 -1
  16. package/lib/commands/run-login.js +0 -136
  17. package/lib/commands/run-login.js.map +0 -1
  18. package/lib/commands/run-version.d.ts +0 -1
  19. package/lib/commands/run-version.js +0 -69
  20. package/lib/commands/run-version.js.map +0 -1
  21. package/lib/config.d.ts +0 -14
  22. package/lib/config.js +0 -64
  23. package/lib/config.js.map +0 -1
  24. package/lib/key.d.ts +0 -2
  25. package/lib/key.js +0 -44
  26. package/lib/key.js.map +0 -1
  27. package/lib/upload.d.ts +0 -2
  28. package/lib/upload.js +0 -189
  29. package/lib/upload.js.map +0 -1
  30. package/lib/utils.d.ts +0 -2
  31. package/lib/utils.js +0 -28
  32. package/lib/utils.js.map +0 -1
  33. package/lib/webpack.config.js +0 -50
  34. package/src/build.ts +0 -99
  35. package/src/cli.ts +0 -184
  36. package/src/commands/login-server.ts +0 -119
  37. package/src/commands/run-create.ts +0 -126
  38. package/src/commands/run-login.ts +0 -111
  39. package/src/commands/run-version.ts +0 -38
  40. package/src/config.ts +0 -72
  41. package/src/key.ts +0 -43
  42. package/src/upload.ts +0 -214
  43. package/src/utils.ts +0 -21
  44. package/src/webpack.config.js +0 -50
  45. package/templates/aptos/abis/aptos/souffle.json +0 -389
  46. package/templates/aptos/jest.config.js +0 -7
  47. package/templates/aptos/package.json +0 -21
  48. package/templates/aptos/sentio.yaml +0 -1
  49. package/templates/aptos/src/processor.ts +0 -13
  50. package/templates/aptos/tsconfig.json +0 -20
  51. package/templates/evm/abis/evm/x2y2.json +0 -296
  52. package/templates/evm/jest.config.js +0 -7
  53. package/templates/evm/package.json +0 -20
  54. package/templates/evm/sentio.yaml +0 -3
  55. package/templates/evm/src/processor.ts +0 -29
  56. package/templates/evm/tsconfig.json +0 -20
  57. package/templates/raw/jest.config.js +0 -7
  58. package/templates/raw/package.json +0 -20
  59. package/templates/raw/sentio.yaml +0 -3
  60. package/templates/raw/src/processor.ts +0 -0
  61. package/templates/raw/tsconfig.json +0 -20
  62. package/templates/raw/yarn.lock +0 -4095
  63. package/templates/solana/jest.config.js +0 -7
  64. package/templates/solana/package.json +0 -21
  65. package/templates/solana/sentio.yaml +0 -3
  66. package/templates/solana/src/processor.ts +0 -16
  67. package/templates/solana/tsconfig.json +0 -20
  68. package/templates/solana/yarn.lock +0 -4918
@@ -1,119 +0,0 @@
1
- import express from 'express'
2
- import { getAuthConfig, getFinalizedHost } from '../config'
3
- import url, { URL } from 'url'
4
- import fetch from 'node-fetch'
5
- import { getCliVersion } from '../utils'
6
- import { WriteKey } from '../key'
7
- import chalk from 'chalk'
8
- import http from 'http'
9
- import os from 'os'
10
- import * as crypto from 'crypto'
11
-
12
- interface AuthParams {
13
- serverPort: number
14
- sentioHost: string
15
- codeVerifier: string
16
- }
17
-
18
- const app = express()
19
-
20
- let server: http.Server
21
- let authParams: AuthParams
22
-
23
- export function startServer(params: AuthParams) {
24
- authParams = params
25
- server = app.listen(params.serverPort)
26
- }
27
-
28
- app.get('/callback', async (req, res) => {
29
- res.end('login success, please go back to CLI to continue')
30
- const host = getFinalizedHost(authParams.sentioHost)
31
- const code = req.query.code
32
- if (!code || (code as string).length == 0) {
33
- return
34
- }
35
-
36
- // exchange token
37
- const tokenResRaw = await getToken(host, code as string)
38
- if (!tokenResRaw.ok) {
39
- console.error(chalk.red('request token error, code:', tokenResRaw.status, tokenResRaw.statusText))
40
- return
41
- }
42
- const tokenRes = await tokenResRaw.json()
43
- const accessToken = tokenRes['access_token']
44
-
45
- // check if the account is ready
46
- const userResRaw = await getUser(host, accessToken)
47
- if (!userResRaw.ok) {
48
- if (userResRaw.status == 401) {
49
- console.error(chalk.red('please sign up on sentio first'))
50
- } else {
51
- console.error(chalk.red('get user error, code:', userResRaw.status, userResRaw.statusText))
52
- }
53
- return
54
- }
55
- const userRes = await userResRaw.json()
56
- if (!userRes.emailVerified) {
57
- console.error(chalk.red('please verify your email first'))
58
- return
59
- }
60
-
61
- // create API key
62
- const apiKeyName = `${os.hostname()}-${crypto.randomBytes(4).toString('hex')}`
63
- const createApiKeyResRaw = await createApiKey(host, apiKeyName, 'sdk_generated', accessToken)
64
- if (!createApiKeyResRaw.ok) {
65
- console.error(chalk.red('create api key error, code:', createApiKeyResRaw.status, createApiKeyResRaw.statusText))
66
- return
67
- }
68
- const createApiKeyRes = await createApiKeyResRaw.json()
69
- const apiKey = createApiKeyRes['key']
70
- WriteKey(host, apiKey)
71
- console.log(chalk.green('login success, new API key: ' + apiKey))
72
-
73
- server.close()
74
- })
75
-
76
- async function getToken(host: string, code: string) {
77
- const authConf = getAuthConfig(host)
78
- const params = new url.URLSearchParams({
79
- grant_type: 'authorization_code',
80
- client_id: authConf.clientId,
81
- code_verifier: authParams.codeVerifier,
82
- code: code,
83
- redirect_uri: `http://localhost:${authParams.serverPort}/callback`,
84
- })
85
- return fetch(`${authConf.domain}/oauth/token`, {
86
- method: 'POST',
87
- headers: {
88
- 'Content-Type': 'application/x-www-form-urlencoded',
89
- },
90
- body: params.toString(),
91
- })
92
- }
93
-
94
- async function createApiKey(host: string, name: string, source: string, accessToken: string) {
95
- const createApiKeyUrl = new URL('/api/v1/keys', host)
96
- return fetch(createApiKeyUrl, {
97
- method: 'POST',
98
- headers: {
99
- Authorization: 'Bearer ' + accessToken,
100
- version: getCliVersion(),
101
- },
102
- body: JSON.stringify({
103
- name: name,
104
- scopes: ['write:project'],
105
- source: source,
106
- }),
107
- })
108
- }
109
-
110
- async function getUser(host: string, accessToken: string) {
111
- const getUserUrl = new URL('/api/v1/users', host)
112
- return fetch(getUserUrl, {
113
- method: 'GET',
114
- headers: {
115
- Authorization: 'Bearer ' + accessToken,
116
- version: getCliVersion(),
117
- },
118
- })
119
- }
@@ -1,126 +0,0 @@
1
- import commandLineArgs from 'command-line-args'
2
- import commandLineUsage from 'command-line-usage'
3
- import path from 'path'
4
- import fs from 'fs-extra'
5
- import chalk from 'chalk'
6
- import latestVersion from 'latest-version'
7
-
8
- export async function runCreate(argv: string[]) {
9
- const optionDefinitions = [
10
- {
11
- name: 'help',
12
- alias: 'h',
13
- type: Boolean,
14
- description: 'Display this usage guide.',
15
- },
16
- {
17
- name: 'name',
18
- alias: 'n',
19
- defaultOption: true,
20
- type: String,
21
- description: 'Project name',
22
- },
23
- {
24
- name: 'directory',
25
- alias: 'd',
26
- description: '(Optional) The root direct new project will be created, default current working dir',
27
- type: String,
28
- },
29
- {
30
- name: 'chain-type',
31
- alias: 'c',
32
- description:
33
- 'The type of project you want to create, can be evm, aptos, solana, raw (if you want to start from scratch and support multiple types of chains)',
34
- type: String,
35
- defaultValue: 'evm',
36
- },
37
- ]
38
-
39
- const options = commandLineArgs(optionDefinitions, { argv })
40
- const usage = commandLineUsage([
41
- {
42
- header: 'Create a template project',
43
- content: 'sentio create <name>',
44
- },
45
- {
46
- header: 'Options',
47
- optionList: optionDefinitions,
48
- },
49
- ])
50
-
51
- if (options.help || !options.name) {
52
- console.log(usage)
53
- } else {
54
- const chainType: string = options['chain-type'].toLowerCase()
55
- switch (chainType) {
56
- case 'evm':
57
- break
58
- case 'aptos':
59
- break
60
- case 'raw':
61
- break
62
- case 'solana':
63
- break
64
- default:
65
- console.error(chalk.red('non supported chain-type for template creation, use --help for more information.'))
66
- console.log(usage)
67
- process.exit(1)
68
- }
69
- const templateFolder = path.resolve(__dirname, '../../templates', chainType)
70
- const projectName = options.name || 'default'
71
-
72
- const rootDir = options.directory || process.cwd()
73
- const dstFolder = path.resolve(rootDir, projectName)
74
- if (fs.existsSync(dstFolder)) {
75
- console.error(chalk.red("can't create project '" + projectName + "', directory already existed"))
76
- process.exit(1)
77
- }
78
-
79
- fs.copySync(templateFolder, dstFolder, {
80
- filter: (src, _) => {
81
- // TODO read from .gitignore to be more reliable
82
- if (
83
- src.endsWith('types') ||
84
- src.endsWith('dist') ||
85
- src.endsWith('node_modules') ||
86
- src.endsWith('.lock') ||
87
- src.endsWith('dist')
88
- ) {
89
- return false
90
- }
91
- return true
92
- },
93
- overwrite: false,
94
- })
95
- if (options.name) {
96
- const sentioYamlPath = path.resolve(dstFolder, 'sentio.yaml')
97
- fs.writeFileSync(sentioYamlPath, 'project: ' + projectName + '\n', { flag: 'w+' })
98
-
99
- const packageJsonPath = path.resolve(dstFolder, 'package.json')
100
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
101
-
102
- const sdkVersion = '^' + (await latestVersion('@sentio/sdk'))
103
- packageJson.dependencies['@sentio/sdk'] = sdkVersion
104
-
105
- switch (chainType) {
106
- case 'aptos':
107
- packageJson.dependencies['@sentio/sdk-aptos'] = sdkVersion
108
- break
109
- case 'solana':
110
- packageJson.dependencies['@sentio/sdk-solana'] = sdkVersion
111
- break
112
- default:
113
- }
114
-
115
- const cliVersion = '^' + (await latestVersion('@sentio/cli'))
116
- packageJson.devDependencies['@sentio/cli'] = cliVersion
117
- packageJson.name = projectName
118
-
119
- // Don't add directly to avoid deps issue
120
- packageJson.scripts.postinstall = 'sentio gen'
121
-
122
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
123
- }
124
- console.log(chalk.green("successfully create project '" + projectName + "'"))
125
- }
126
- }
@@ -1,111 +0,0 @@
1
- import commandLineArgs from 'command-line-args'
2
- import commandLineUsage from 'command-line-usage'
3
- import { getAuthConfig, getFinalizedHost } from '../config'
4
- import { startServer } from './login-server'
5
- import url, { URL } from 'url'
6
- import * as crypto from 'crypto'
7
- import chalk from 'chalk'
8
- import { WriteKey } from '../key'
9
- import fetch from 'node-fetch'
10
- import open from 'open'
11
-
12
- const port = 20000
13
-
14
- export function runLogin(argv: string[]) {
15
- const optionDefinitions = [
16
- {
17
- name: 'help',
18
- alias: 'h',
19
- type: Boolean,
20
- description: 'Display this usage guide.',
21
- },
22
- {
23
- name: 'host',
24
- description: '(Optional) Override Sentio Host name',
25
- type: String,
26
- },
27
- {
28
- name: 'api-key',
29
- type: String,
30
- description: '(Optional) Your API key',
31
- },
32
- ]
33
- const options = commandLineArgs(optionDefinitions, { argv })
34
-
35
- const host = getFinalizedHost(options.host)
36
- if (options.help) {
37
- const usage = commandLineUsage([
38
- {
39
- header: 'Login to Sentio',
40
- content: 'sentio login',
41
- },
42
- {
43
- header: 'Options',
44
- optionList: optionDefinitions,
45
- },
46
- ])
47
- console.log(usage)
48
- } else if (options['api-key']) {
49
- console.log(chalk.blue('login to ' + host))
50
- const apiKey = options['api-key']
51
- checkKey(host, apiKey).then((res) => {
52
- if (res.status == 200) {
53
- WriteKey(host, apiKey)
54
- console.log(chalk.green('login success'))
55
- } else {
56
- console.error(chalk.red('login failed, code:', res.status, res.statusText))
57
- }
58
- })
59
- } else {
60
- // https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce
61
- const verifier = base64URLEncode(crypto.randomBytes(32))
62
- const challenge = base64URLEncode(sha256(verifier))
63
-
64
- const conf = getAuthConfig(host)
65
- if (conf.domain === '') {
66
- console.error(chalk.red('invalid host, try login with an API key if it is a dev env'))
67
- return
68
- }
69
- const authURL = new URL(conf.domain + `/authorize?`)
70
- const params = new url.URLSearchParams({
71
- response_type: 'code',
72
- code_challenge: challenge,
73
- code_challenge_method: 'S256',
74
- client_id: conf.clientId,
75
- redirect_uri: `http://localhost:${port}/callback`,
76
- audience: conf.audience,
77
- prompt: 'login',
78
- })
79
- authURL.search = params.toString()
80
-
81
- console.log('Continue your authorization in the browser')
82
- open(authURL.toString()).catch((reason) => {
83
- console.error(chalk.red('Unable to open browser: ' + reason))
84
- console.error(chalk.red('Open this url in your browser: ' + authURL.toString()))
85
- })
86
-
87
- startServer({
88
- serverPort: port,
89
- sentioHost: options.host,
90
- codeVerifier: verifier,
91
- })
92
- }
93
- }
94
-
95
- function base64URLEncode(str: Buffer) {
96
- return str.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
97
- }
98
-
99
- function sha256(str: string) {
100
- return crypto.createHash('sha256').update(str).digest()
101
- }
102
-
103
- async function checkKey(host: string, apiKey: string) {
104
- const checkApiKeyUrl = new URL('/api/v1/processors/check_key', host)
105
- return fetch(checkApiKeyUrl, {
106
- method: 'GET',
107
- headers: {
108
- 'api-key': apiKey,
109
- },
110
- })
111
- }
@@ -1,38 +0,0 @@
1
- import commandLineArgs from 'command-line-args'
2
- import commandLineUsage from 'command-line-usage'
3
- import { getCliVersion, getSdkVersion } from '../utils'
4
- import * as console from 'console'
5
-
6
- export function runVersion(argv: string[]) {
7
- const optionDefinitions = [
8
- {
9
- name: 'help',
10
- alias: 'h',
11
- type: Boolean,
12
- description: 'Display this usage guide.',
13
- },
14
- ]
15
- const options = commandLineArgs(optionDefinitions, { argv })
16
-
17
- if (options.help) {
18
- const usage = commandLineUsage([
19
- {
20
- header: 'Show current version',
21
- content: 'sentio version',
22
- },
23
- {
24
- header: 'Options',
25
- optionList: optionDefinitions,
26
- },
27
- ])
28
- console.log(usage)
29
- } else {
30
- console.log('CLI Version: ', getCliVersion())
31
- const sdkVersion = getSdkVersion()
32
- if (sdkVersion) {
33
- console.log('SDK Version: ', sdkVersion)
34
- } else {
35
- console.log('SDK Not installed for this project')
36
- }
37
- }
38
- }
package/src/config.ts DELETED
@@ -1,72 +0,0 @@
1
- const HostMap: { [host: string]: string } = {
2
- local: 'http://localhost:10000',
3
- test: 'https://test.sentio.xyz',
4
- staging: 'https://staging.sentio.xyz',
5
- prod: 'https://app.sentio.xyz',
6
- }
7
-
8
- export interface SentioProjectConfig {
9
- project: string
10
- host: string
11
- // source: string
12
- build: boolean
13
- // targets: Target[]
14
- debug: boolean
15
- }
16
-
17
- export function getFinalizedHost(host: string): string {
18
- if (host === undefined || host === '') {
19
- host = 'prod'
20
- }
21
- return HostMap[host] ?? host
22
- }
23
-
24
- export function getAuthConfig(host: string): { domain: string; clientId: string; audience: string } {
25
- let domain = '',
26
- clientId = '',
27
- audience = ''
28
- switch (host) {
29
- case HostMap['local']:
30
- domain = 'https://sentio-dev.us.auth0.com'
31
- clientId = 'qGDisObqQbcPeRA8k02POPZ2Df4KVCna'
32
- audience = 'http://localhost:8080/v1'
33
- break
34
- case HostMap['prod']:
35
- domain = 'https://auth.sentio.xyz'
36
- clientId = 'xd80PeuvuZVHpBFh7yEdlSZdtE5mTpGe'
37
- audience = 'https://app.sentio.xyz/api/v1'
38
- break
39
- case HostMap['test']:
40
- case HostMap['staging']:
41
- domain = 'https://auth.test.sentio.xyz'
42
- clientId = 'qXVvovHaOE37SndxTZJxCKgZjw1axPax'
43
- audience = 'https://test.sentio.xyz/api/v1'
44
- break
45
- default:
46
- break
47
- }
48
- return { domain, clientId, audience }
49
- }
50
-
51
- export function finalizeHost(config: SentioProjectConfig) {
52
- config.host = getFinalizedHost(config.host)
53
- }
54
-
55
- export function FinalizeProjectName(config: SentioProjectConfig, owner: string | undefined) {
56
- if (owner) {
57
- let name = config.project
58
- if (name.includes('/')) {
59
- name = config.project.split('/')[1]
60
- }
61
- config.project = [owner, name].join('/')
62
- }
63
- }
64
-
65
- // export interface Target {
66
- // chain: string
67
- // abisDir?: string
68
- // }
69
- //
70
- // // Supported target chain, lower case
71
- // export const EVM = 'evm'
72
- // export const SOLANA = 'solana'
package/src/key.ts DELETED
@@ -1,43 +0,0 @@
1
- import path from 'path'
2
- import fs from 'fs'
3
- import os from 'os'
4
-
5
- const homeDir = os.homedir()
6
- const sentioDir = path.join(homeDir, '.sentio')
7
- const configFile = path.join(sentioDir, 'config.json')
8
-
9
- interface SentioKeyConfig {
10
- [key: string]: {
11
- api_keys: string
12
- }
13
- }
14
-
15
- export function WriteKey(host: string, api_key: string) {
16
- const sentioDir = path.join(homeDir, '.sentio')
17
- if (!fs.existsSync(sentioDir)) {
18
- fs.mkdirSync(sentioDir, { recursive: true })
19
- }
20
- let config: SentioKeyConfig = {}
21
- if (fs.existsSync(configFile)) {
22
- const content = fs.readFileSync(configFile, 'utf8')
23
- config = JSON.parse(content)
24
- }
25
- const hostConfig = config[host] || { api_keys: {} }
26
- hostConfig.api_keys = api_key
27
- config[host] = hostConfig
28
- fs.writeFileSync(configFile, JSON.stringify(config, null, 2))
29
- }
30
-
31
- export function ReadKey(host: string): string | undefined {
32
- if (!fs.existsSync(sentioDir)) {
33
- return undefined
34
- }
35
- const configFile = path.join(sentioDir, 'config.json')
36
- if (fs.existsSync(configFile)) {
37
- const content = fs.readFileSync(configFile, 'utf8')
38
- const config = JSON.parse(content)
39
- return config[host]?.api_keys
40
- } else {
41
- return undefined
42
- }
43
- }