@truebit/cli 1.120.0-beta.254 → 1.120.0-beta.255
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/build/index.mjs +1 -1
- package/package.json +2 -2
package/build/index.mjs
CHANGED
|
@@ -239,7 +239,7 @@ ${n.data.payload.instrumentedTaskId}`);else throw"Malformed instrumentation serv
|
|
|
239
239
|
`),console.log(Zn.white("Wallet Address: ")+Zn.yellow(e)),console.log(Zn.white("Subscription Tier: ")+Zn.green(a.userSubscription.toUpperCase())),a.maxSolutions!==void 0&&console.log(Zn.white("Max Solutions: ")+Zn.green(`${a.maxSolutions}`)),a.quotaMax===0)console.log(Zn.white("Monthly Quota: ")+Zn.green("UNLIMITED")),a.currentUsage!==void 0&&console.log(Zn.white("Current Usage: ")+Zn.yellow(`${a.currentUsage} executions`));else{if(console.log(Zn.white("Monthly Quota: ")+Zn.green(`${a.quotaMax} executions`)),a.currentUsage!==void 0&&(console.log(Zn.white("Current Usage: ")+Zn.yellow(`${a.currentUsage} executions`)),a.remaining!==void 0)){let c=a.remaining===0?Zn.red:a.remaining<a.quotaMax*.2?Zn.yellow:Zn.green;console.log(Zn.white("Remaining: ")+c(`${a.remaining} executions`))}console.log(Zn.white("Quota Resets On: ")+Zn.yellow(u))}console.log(`
|
|
240
240
|
`+Zn.cyan("=".repeat(60))+`
|
|
241
241
|
`)}catch(t){throw t instanceof Error?console.error(Zn.red("Error fetching quota status: ")+t.message):console.error(Zn.red("Error fetching quota status: ")+String(t)),t}}_X();wo();async function UDe(t){try{console.log("Fetching execution status...");let n=await(await Ec()).get(`api/execution/${t}`).catch(o0);if(n.data.message)throw n.data.message;console.log("Task execution status: ",n.data.status),n.data.output&&console.log("Task execution output: ",n.data.output)}catch(e){console.error(`Couldn't fetch execution status for executionId ${t}: ${e}`)}}var jDe=gt(PS(),1),S7=class{tokens=[];authInputs;parse(e,n){let r=this.parseKeyValuePairs(n);if(e.length==0){this.authInputs=r;return}let i=Object.keys(r);if(e.every(s=>i.includes(s))){let s={};for(let a of e)s[a]=r[a];this.authInputs=s}else throw new Error(`Invalid authString: ${e} are required`)}parseKeyValuePairs(e){try{let n=e.split(","),r={};for(let i of n){let[s,a]=i.split(":");r[s.trim()]=a.trim()}return r}catch{throw new Error("Invalid auth string")}}},AI=class extends S7{tokens=["accessKey","secretKey"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return jDe.default.sign(e,{accessKeyId:this.authInputs.accessKey,secretAccessKey:this.authInputs.secretKey}).headers||{}}},wI=class extends S7{tokens=["username","password"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return{Authorization:`Basic ${btoa(`${this.authInputs.username}:${this.authInputs.password}`)}`}}},EI=class extends S7{tokens=[];constructor(e){super(),this.parse([],e)}authHeaders(e){return{...this.authInputs}}};var Ou;(function(t){t.AWS_SIGNATURE="aws-signature",t.BASIC_AUTH="basic-auth",t.CUSTOM_HEADER="custom-header"})(Ou||(Ou={}));var vX=(t,e)=>{switch(t){case Ou.AWS_SIGNATURE:return new AI(e);case Ou.BASIC_AUTH:return new wI(e);case Ou.CUSTOM_HEADER:return new EI(e);default:throw new Error(`Invalid authentication method specified. Should be one of <${Object.values(Ou)}>`)}};import Ljt from"chalk";import{ethers as qjt}from"ethers";wo();import*as SI from"crypto";async function Bjt(t){try{return(await t.get("/getkey")).data}catch(e){throw new Error(`Failed to get encryption key: ${e}`)}}function Fjt(t,e){try{let n=Buffer.from(e,"base64"),r=SI.randomBytes(16),i=SI.createCipheriv("aes-256-cbc",n,r),s=Buffer.concat([i.update(t,"utf8"),i.final()]);return n.fill(0),{encrypted_authString:s.toString("base64"),iv:r.toString("base64")}}catch(n){throw n instanceof Error?new Error(`Failed to encrypt credentials: ${n.message}`):new Error(`Failed to encrypt credentials: ${n}`)}}async function VDe(t,e){let n=await Bjt(t),r=Fjt(e,n.plaintext_key);return{encrypted_authString:r.encrypted_authString,encrypted_data_key:n.encrypted_key,iv:r.iv}}async function HDe(t,e,n,r,i,s,a){console.log("Deploying the API Authentication Credentials");try{if(!SDe(s))throw"Invalid private key provided";if(!qjt.isAddress(a))throw"Invalid address provided";if(vX(r,i),!Oy(t))throw"Invalid taskId";let o=await KPe();console.log("Encrypting credentials...");let f=await VDe(o,i);await o.post("credentials",{taskId:t,namespace:e,taskName:n,method:r,encrypted_authString:f.encrypted_authString,encrypted_data_key:f.encrypted_data_key,iv:f.iv}).catch(o0),console.log("The encrypted credentials were deployed "+Ljt.green("Successfully"))}catch(o){throw console.log(o),`There was an Error deploying credentials:
|
|
242
|
-
Couldn't push api credentials to remote server: ${o}`}}import{inspect as SHt}from"util";import Cs from"ora";import{v4 as xHt}from"uuid";import{ethers as FI}from"ethers";var zDe={name:"@truebit/cli",version:"1.120.0-beta.
|
|
242
|
+
Couldn't push api credentials to remote server: ${o}`}}import{inspect as SHt}from"util";import Cs from"ora";import{v4 as xHt}from"uuid";import{ethers as FI}from"ethers";var zDe={name:"@truebit/cli",version:"1.120.0-beta.255",private:!1,description:"truebit-cli is a basic command line that allows interaction between users and truebit nextgen node.",author:{name:"Truebit Co.",url:"https://truebit.io/"},license:"https://truebit.io/terms/",repository:{type:"git",url:"https://github.com/TruebitProtocol"},homepage:"https://truebit.io/",main:"build/index.mjs",module:"build/index.mjs",types:"build/types/index.d.ts",type:"module",scripts:{prebuild:"rimraf build logs","prebuild:dev":"rimraf build logs","build:dev":"tsc && chmod +x build/index.mjs",build:"NODE_ENV=production node esbuild.config.mjs && chmod +x build/index.mjs",dev:"export NODE_ENV=development && npx nodemon",test:"vitest run --passWithNoTests tests/"},dependencies:{axios:"1.13.2",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.2",ethers:"6.16.0",figlet:"1.9.4","form-data":"4.0.5","openapi-enforcer":"1.23.0",ora:"9.0.0","public-ip":"8.0.0","ts-retry":"6.0.0",uuid:"13.0.0"},bin:{truebit:"build/index.mjs"},files:["build"],devDependencies:{"@types/figlet":"1.7.0","@vitest/coverage-v8":"4.0.17",esbuild:"0.27.2",typescript:"5.9.3",vitest:"4.0.17"},engines:{node:">=22.13.0"}};qa();wo();h1();qa();import{createInterface as Gjt}from"node:readline/promises";import kd from"chalk";wo();import x7 from"axios";import{ethers as AX}from"ethers";import{randomBytes as jjt}from"crypto";import{v4 as Vjt}from"uuid";qa();import{ethers as xI}from"ethers";async function WDe(t){E7(t);let e=Yn(ea(),nt.AVAX),n=xI.keccak256(xI.toUtf8Bytes(t));return await e.authorization.registerAuthorization(n),n}async function TI(t,e,n=Tn("address")){E7(t);let r=Yn(ea(),nt.AVAX),i=await r.authorization.getEIP712Domain(),s=await r.authorization.nonces(n),a=Math.floor(Date.now()/1e3)+3600,o={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},f=xI.keccak256(xI.toUtf8Bytes(t)),u={user:n,apiKeyHash:f,nonce:Number(s),deadline:a},c=await r.utils.signMeta(i,o,u);return(await TDe(n,f,a,c,e)).status==201?f:null}h1();import{isTooManyTries as GDe,retryAsync as KDe}from"ts-retry";var YDe="0x0000000000000000000000000000000000000000";async function ZDe(t){let e=!0;return t===""?(e=!1,console.log("An email address is required. Please provide your email address to proceed.")):new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(t)?await Hjt(t)&&(e=!1,console.log("The provided email address is already in use. Please enter a different email address.")):(e=!1,console.log("The email address provided is not valid. Please try again.")),e}function $h(t){return t==="Y"||t==="N"}function XDe(t){return!AX.isAddress(t)||t.length!==42||!t.startsWith("0x")}async function JDe(){let t=await zjt();try{if(!await TI(t,!0))throw Error("The API key could not been registered.")}catch(e){let n=e.message;if(n)throw Error(`There was an error registering the API key -> ${n}`)}return t}async function QDe(){let t=await Wjt();try{if(!await gI(t,!0))throw Error("The namespace could not been registered.")}catch(e){let n=e.message,r=n?n.match(/execution reverted: "(.*?)" /)?.[1]:null;if(r)throw Error(`There was an error registering the namespace -> ${r}`);if(n)throw Error(`There was an error registering the namespace -> ${n}`)}return t}async function Hjt(t){let e=await La();try{return(await e.get(`userexistence/${t}`)).data===!0}catch(n){if(x7.isAxiosError(n)&&n.response?.status===404&&typeof n.response?.data?.message=="string"&&n.response.data.message.includes("User not found"))return!1;throw n}}async function CI(t,e){try{let n={message:"I am a Truebit User"};if(!e)throw Error("Secret.json does not exists");let r=e.privateKey,i=e.address,s=no.createSignedBody(n,r,i);return(await(await La()).get(`user/${t}`,{headers:{"truebit-auth":JSON.stringify(s)}})).data}catch(n){if(x7.isAxiosError(n)&&n.response?.status===401&&n.response?.data.message.includes("Entitlement Validation Error")||x7.isAxiosError(n)&&n.response?.status==404&&n.response?.data.message&&n.response?.data.message.includes("User not found"))return null;throw x7.isAxiosError(n)?n.response?Error(`The server responding with an error -> ${n.response.data.message||n.response.status+" - "+n.response.statusText}`):n.request?Error(`The server is not responding -> ${n.message}`):Error(`There was an error in the communication with the server -> ${n.message}`):Error(typeof n=="string"?`There was an error in the communication with the server -> ${n}`:"There was an error in the communication with the server.")}}async function eNe(t){try{return await(await La()).post("user/register",t)}catch(e){throw x7.isAxiosError(e)?e.response?Error(`The server responding with an error -> ${e.response.data.message||e.response.status+" - "+e.response.statusText}`):e.request?Error(`The server is not responding -> ${e.message}`):Error(`There was an error in the communication with the server -> ${e.message}`):Error(typeof e=="string"?`There was an error in the communication with the server -> ${e}`:"There was an error in the communication with the server.")}}async function zjt(){let t=ea(),e=Yn(t,nt.AVAX),n="";try{await KDe(async()=>{n=Vjt();let r=AX.keccak256(AX.toUtf8Bytes(n));return await e.authorization.getPayerAddress(r)===YDe},{delay:500,maxTry:5,until:r=>r===!0})}catch(r){throw GDe(r)?Error("Attempts to generate unique Api Key for the user exhausted."):r}return n}async function Wjt(){let t=ea(),e=Yn(t,nt.AVAX),n="";try{await KDe(async()=>(n=jjt(4).toString("hex"),await e.taskRegistry.getNamespaceOwner(n)===YDe),{delay:500,maxTry:5,until:r=>r===!0})}catch(r){throw GDe(r)?Error("Attempts to generate unique namespace for the user exhausted."):r}return n}function tNe(t){t.fullNameAnswer="",t.emailAddressAnswer="",t.companyNameAnswer="",t.jobPositionAnswer="",t.eulaAnswer="",t.confirmRegistration=""}h1();ap();import Kjt from"ora";import*as OI from"os";async function nNe(t,e,n){let r=Js(),i=r!==null,s=0,a,o=Gjt({input:process.stdin,output:process.stdout,terminal:!0});switch(i&&(XDe(r.address)?s=1:(a=await CI(r.address,r),a?s=2:s=3)),s){case 1:console.log("The wallet set in the configuration must be a valid ethereum address. (ENS not supported yet)");break;case 2:console.log(Kn.SETUP_STEP1_SCENARIO1_P2(a));break;case 3:{console.log(Kn.SETUP_STEP2_SCENARIO3_P1),console.log();let f={user_ip:t,date_time:Yr(),os_version:OI.type+"_"+OI.release,node_version:process.version,cli_version:e};await n.sendEventToMixpanel("user_registration_begin",f);let u={confirmRegistration:"",fullNameAnswer:"",emailAddressAnswer:"",companyNameAnswer:"",jobPositionAnswer:"",eulaAnswer:""};try{for(;u.confirmRegistration!="Y";){for(u.fullNameAnswer=(await o.question(kd.bold(" 1. Full Name: "))).trim();u.fullNameAnswer==="";)console.log("Your full name is required. Please provide your first and last name to proceed."),u.fullNameAnswer=(await o.question(kd.bold(" 1. Full Name: "))).trim();for(u.emailAddressAnswer=(await o.question(kd.bold(" 2. Email Address: "))).trim();!await ZDe(u.emailAddressAnswer);)u.emailAddressAnswer=(await o.question(kd.bold(" 2. Email Address: "))).trim();for(u.companyNameAnswer=(await o.question(kd.bold(" 3. Company Name: "))).trim(),u.jobPositionAnswer=(await o.question(kd.bold(" 4. Job Position: "))).trim();!$h(u.eulaAnswer);)u.eulaAnswer=(await o.question(kd.bold(` 5. Accept EULA? [Y|N] (${Kn.EULA_TERMS_LINK}): `))).toUpperCase();if(u.eulaAnswer=="N"){console.log(Kn.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!$h(u.confirmRegistration);)console.log(`
|
|
243
243
|
Is the information provided above correct?`),u.confirmRegistration=(await o.question(kd.bold("Press [Y] to confirm or [N] to edit: "))).toUpperCase();u.confirmRegistration=="N"&&(console.log(`
|
|
244
244
|
Please provide the following information:`),tNe(u))}}catch(l){if(l.name==="AbortError"||l.message.includes("Ctrl+C")){let p=l.message,h=f;h.error_details=p,h.date_time=Yr();let g={fullname:u.fullNameAnswer,email:u.emailAddressAnswer,company:u.companyNameAnswer,role:u.jobPositionAnswer};h.user_info=JSON.stringify(g),await n.sendEventToMixpanel("user_registration_failed",h),process.exit(0)}}if(u.eulaAnswer=="N")break;let c=f;console.log(),console.log("By completing registration, you'll be automatically subscribed to our newsletter."),console.log("To opt-out, please follow the steps described in our documentation portal."),console.log();let d=Kjt({text:kd.bold("... registering your account."),stream:process.stdout}).start();try{let l=await QDe(),p=await JDe(),h={name:u.fullNameAnswer,email:u.emailAddressAnswer,walletAddress:r?.address,company:u.companyNameAnswer,jobDescription:u.jobPositionAnswer,EULA:no.createSignedBody({ip:await sI(),date:new Date().toISOString()},r.privateKey),defaultNamespace:l,defaultApiKey:p};await eNe(h),d.stop(),console.log(Kn.SETUP_STEP2_SCENARIO3_P2(u,r.address,l,p)),c.distinct_id=h.walletAddress,c.date_time=Yr(),c.fullname=h.name,c.email=h.email,c.company=h.company,c.role=h.jobDescription,c.namespace=h.defaultNamespace,c.api_key=p,c.wallet_address=h.walletAddress,await n.sendEventToMixpanel("user_registration_success",c),await n.registerUserMixpanel(c.wallet_address,Yjt(c))}catch(l){d.stop();let p=l.message,h=f;h.error_details=p,h.date_time=Yr();let g={fullname:u.fullNameAnswer,email:u.emailAddressAnswer,company:u.companyNameAnswer,role:u.jobPositionAnswer};h.user_info=JSON.stringify(g),await n.sendEventToMixpanel("user_registration_failed",h);let _=p?p.match(/CreateUserValidation - (.*?.*)/)?.[1]:null;if(_)throw Error(_);if(p.includes("Sender doesn't have enough funds to send tx"))throw Error("We are currently experiencing technical difficulties. Please try again later.");console.error(Kn.SETUP_STEP2_UNHANDLED_ERROR),process.exit(1)}finally{d.clear()}break}default:throw Error("An unexpected error occurred.")}o.close()}function Yjt(t){return{apiKey:t.api_key,name:t.fullname,email:t.email,ip:t.user_ip,company:t.company,role:t.role,namespace:t.namespace,walletAddress:t.wallet_address}}import{setDefaultAutoSelectFamily as THt}from"node:net";import Zjt from"chalk";qa();ap();import{createInterface as Xjt}from"node:readline/promises";import*as II from"os";async function rNe(t,e,n){let r=Js(),i=r!==null,s=0;switch(i?i&&!r.eula?s=2:s=3:s=1,s){case 1:case 2:{let a=Xjt({input:process.stdin,output:process.stdout,terminal:!0}),o="",f={user_ip:t,date_time:Yr(),os_version:II.type+"_"+II.release,node_version:process.version,cli_version:e};for(console.log(Kn.EULA_INSTALLATION);!$h(o);)o=(await a.question(Zjt.bold(`
|
|
245
245
|
Have you read, and do you accept the Terms of Use? [Y|N]: `))).toUpperCase(),await n.sendEventToMixpanel("TOS_shown",f);if(o=="N")throw f.date_time=Yr(),await n.sendEventToMixpanel("TOS_rejected",f),Kn.EULA_INSTALLATION_NO_ACCEPTED;f.date_time=Yr(),await n.sendEventToMixpanel("TOS_accepted",f);let u=Math.round(new Date().getTime()).toString();if(s===1){let c={...FZ(),eula:u};JPe(c)}else s===2&&d7({eula:u});a.close()}break;default:break}}qa();ap();async function u0(t=!1){let e=Js(),n=e!==null,r=null,i=0;switch(n?n&&(!e.privateKey||!e.address)?i=2:(r=await CI(e.address,e),r?i=4:i=3):i=1,i){case 1:case 2:case 3:console.log(Kn.USER_NO_REGISTERED),process.exit(1);break;case 4:t&&console.log(`You are logged in as: ${r?.name} - ${r?.email}`);break}}import{createInterface as Jjt}from"node:readline/promises";ap();qa();import Qjt from"chalk";async function iNe(){console.log(Qjt.bold(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truebit/cli",
|
|
3
|
-
"version": "1.120.0-beta.
|
|
3
|
+
"version": "1.120.0-beta.255",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "truebit-cli is a basic command line that allows interaction between users and truebit nextgen node.",
|
|
6
6
|
"author": {
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=22.13.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "4956f023e1e490ffc58c5cca8e6ad212c1deac0a"
|
|
59
59
|
}
|