@truebit/cli 1.120.0-beta.231 → 1.120.0-beta.232
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
|
@@ -244,7 +244,7 @@ ${n.data.payload.instrumentedTaskId}`);else throw"Malformed instrumentation serv
|
|
|
244
244
|
`),console.log(Dr.white("Wallet Address: ")+Dr.yellow(e)),console.log(Dr.white("Subscription Tier: ")+Dr.green(s.userSubscription.toUpperCase())),s.maxSolutions!==void 0&&console.log(Dr.white("Max Solutions: ")+Dr.green(`${s.maxSolutions}`)),s.quotaMax===0)console.log(Dr.white("Monthly Quota: ")+Dr.green("UNLIMITED")),s.currentUsage!==void 0&&console.log(Dr.white("Current Usage: ")+Dr.yellow(`${s.currentUsage} executions`));else{if(console.log(Dr.white("Monthly Quota: ")+Dr.green(`${s.quotaMax} executions`)),s.currentUsage!==void 0&&(console.log(Dr.white("Current Usage: ")+Dr.yellow(`${s.currentUsage} executions`)),s.remaining!==void 0)){let c=s.remaining===0?Dr.red:s.remaining<s.quotaMax*.2?Dr.yellow:Dr.green;console.log(Dr.white("Remaining: ")+c(`${s.remaining} executions`))}console.log(Dr.white("Quota Resets On: ")+Dr.yellow(u))}console.log(`
|
|
245
245
|
`+Dr.cyan("=".repeat(60))+`
|
|
246
246
|
`)}catch(t){throw t instanceof Error?console.error(Dr.red("Error fetching quota status: ")+t.message):console.error(Dr.red("Error fetching quota status: ")+String(t)),t}}cJ();m0();async function HDe(t){try{console.log("Fetching execution status...");let n=await(await Bl()).get(`api/execution/${t}`).catch(cf);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 WDe=Rt(VS(),1),Pv=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(a=>i.includes(a))){let a={};for(let s of e)a[s]=r[s];this.authInputs=a}else throw new Error(`Invalid authString: ${e} are required`)}parseKeyValuePairs(e){try{let n=e.split(","),r={};for(let i of n){let[a,s]=i.split(":");r[a.trim()]=s.trim()}return r}catch{throw new Error("Invalid auth string")}}},RM=class extends Pv{tokens=["accessKey","secretKey"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return WDe.default.sign(e,{accessKeyId:this.authInputs.accessKey,secretAccessKey:this.authInputs.secretKey}).headers||{}}},kM=class extends Pv{tokens=["username","password"];constructor(e){super(),this.parse(this.tokens,e)}authHeaders(e){return{Authorization:`Basic ${btoa(`${this.authInputs.username}:${this.authInputs.password}`)}`}}},DM=class extends Pv{tokens=[];constructor(e){super(),this.parse([],e)}authHeaders(e){return{...this.authInputs}}};var Pc;(function(t){t.AWS_SIGNATURE="aws-signature",t.BASIC_AUTH="basic-auth",t.CUSTOM_HEADER="custom-header"})(Pc||(Pc={}));var lJ=(t,e)=>{switch(t){case Pc.AWS_SIGNATURE:return new RM(e);case Pc.BASIC_AUTH:return new kM(e);case Pc.CUSTOM_HEADER:return new DM(e);default:throw new Error(`Invalid authentication method specified. Should be one of <${Object.values(Pc)}>`)}};import xHt from"chalk";import{ethers as THt}from"ethers";m0();import*as NM from"crypto";async function EHt(t){try{return(await t.get("/getkey")).data}catch(e){throw new Error(`Failed to get encryption key: ${e}`)}}function SHt(t,e){try{let n=Buffer.from(e,"base64"),r=NM.randomBytes(16),i=NM.createCipheriv("aes-256-cbc",n,r),a=Buffer.concat([i.update(t,"utf8"),i.final()]);return n.fill(0),{encrypted_authString:a.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 GDe(t,e){let n=await EHt(t),r=SHt(e,n.plaintext_key);return{encrypted_authString:r.encrypted_authString,encrypted_data_key:n.encrypted_key,iv:r.iv}}async function KDe(t,e,n,r,i,a,s){console.log("Deploying the API Authentication Credentials");try{if(!ODe(a))throw"Invalid private key provided";if(!THt.isAddress(s))throw"Invalid address provided";if(lJ(r,i),!Fb(t))throw"Invalid taskId";let o=await qke();console.log("Encrypting credentials...");let f=await GDe(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(cf),console.log("The encrypted credentials were deployed "+xHt.green("Successfully"))}catch(o){throw console.log(o),`There was an Error deploying credentials:
|
|
247
|
-
Couldn't push api credentials to remote server: ${o}`}}import{inspect as CWt}from"util";import hs from"ora";import{v4 as OWt}from"uuid";import{ethers as HM}from"ethers";var YDe={name:"@truebit/cli",version:"1.120.0-beta.
|
|
247
|
+
Couldn't push api credentials to remote server: ${o}`}}import{inspect as CWt}from"util";import hs from"ora";import{v4 as OWt}from"uuid";import{ethers as HM}from"ethers";var YDe={name:"@truebit/cli",version:"1.120.0-beta.232",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.1",chalk:"5.6.2",colors:"1.4.0",commander:"14.0.2",ethers:"6.15.0",figlet:"1.9.3","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":"3.2.4",esbuild:"^0.25.11",typescript:"5.9.3",vitest:"3.2.4"},engines:{node:">=22.13.0"}};Ua();m0();Ep();Ua();import{createInterface as kHt}from"node:readline/promises";import V1 from"chalk";m0();import Rv from"axios";import{ethers as dJ}from"ethers";import{randomBytes as OHt}from"crypto";import{v4 as IHt}from"uuid";Ua();import{ethers as $M}from"ethers";async function ZDe(t,e=jt("blockchainEnv")){Mv(t);let n=kr(e,Mt.AVAX),r=$M.keccak256($M.toUtf8Bytes(t));return await n.authorization.registerAuthorization(r),r}async function BM(t,e,n=jt("blockchainEnv"),r=jt("address")){Mv(t);let i=kr(n,Mt.AVAX),a=await i.authorization.getEIP712Domain(),s=await i.authorization.nonces(r),o=Math.floor(Date.now()/1e3)+3600,f={RegisterMeta:[{name:"user",type:"address"},{name:"apiKeyHash",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},u=$M.keccak256($M.toUtf8Bytes(t)),c={user:r,apiKeyHash:u,nonce:Number(s),deadline:o},d=await i.utils.signMeta(a,f,c);return(await MDe(r,u,o,d,e)).status==201?u:null}Ua();Ep();import{isTooManyTries as XDe,retryAsync as JDe}from"ts-retry";var QDe="0x0000000000000000000000000000000000000000";async function eNe(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 MHt(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 Bm(t){return t==="Y"||t==="N"}function tNe(t){return!dJ.isAddress(t)||t.length!==42||!t.startsWith("0x")}async function nNe(){let t=await PHt();try{if(!await BM(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 rNe(){let t=await RHt();try{if(!await IM(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 MHt(t){let e=await No();try{return(await e.get(`userexistence/${t}`)).data===!0}catch(n){if(Rv.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 FM(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,a=Xa.createSignedBody(n,r,i);return(await(await No()).get(`user/${t}`,{headers:{"truebit-auth":JSON.stringify(a)}})).data}catch(n){if(Rv.isAxiosError(n)&&n.response?.status===401&&n.response?.data.message.includes("Entitlement Validation Error")||Rv.isAxiosError(n)&&n.response?.status==404&&n.response?.data.message&&n.response?.data.message.includes("User not found"))return null;throw Rv.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 iNe(t){try{return await(await No()).post("user/register",t)}catch(e){throw Rv.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 PHt(){let t=jt("blockchainEnv"),e=kr(t,Mt.AVAX),n="";try{await JDe(async()=>{n=IHt();let r=dJ.keccak256(dJ.toUtf8Bytes(n));return await e.authorization.getPayerAddress(r)===QDe},{delay:500,maxTry:5,until:r=>r===!0})}catch(r){throw XDe(r)?Error("Attempts to generate unique Api Key for the user exhausted."):r}return n}async function RHt(){let t=jt("blockchainEnv"),e=kr(t,Mt.AVAX),n="";try{await JDe(async()=>(n=OHt(4).toString("hex"),await e.taskRegistry.getNamespaceOwner(n)===QDe),{delay:500,maxTry:5,until:r=>r===!0})}catch(r){throw XDe(r)?Error("Attempts to generate unique namespace for the user exhausted."):r}return n}function aNe(t){t.fullNameAnswer="",t.emailAddressAnswer="",t.companyNameAnswer="",t.jobPositionAnswer="",t.eulaAnswer="",t.confirmRegistration=""}Ep();L1();import DHt from"ora";import*as LM from"os";async function sNe(t,e,n){let r=qs(),i=r!==null,a=0,s,o=kHt({input:process.stdin,output:process.stdout,terminal:!0});switch(i&&(tNe(r.address)?a=1:(s=await FM(r.address,r),s?a=2:a=3)),a){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(rr.SETUP_STEP1_SCENARIO1_P2(s));break;case 3:{console.log(rr.SETUP_STEP2_SCENARIO3_P1),console.log();let f={user_ip:t,date_time:Ri(),os_version:LM.type+"_"+LM.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(V1.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(V1.bold(" 1. Full Name: "))).trim();for(u.emailAddressAnswer=(await o.question(V1.bold(" 2. Email Address: "))).trim();!await eNe(u.emailAddressAnswer);)u.emailAddressAnswer=(await o.question(V1.bold(" 2. Email Address: "))).trim();for(u.companyNameAnswer=(await o.question(V1.bold(" 3. Company Name: "))).trim(),u.jobPositionAnswer=(await o.question(V1.bold(" 4. Job Position: "))).trim();!Bm(u.eulaAnswer);)u.eulaAnswer=(await o.question(V1.bold(` 5. Accept EULA? [Y|N] (${rr.EULA_TERMS_LINK}): `))).toUpperCase();if(u.eulaAnswer=="N"){console.log(rr.EULA_REGISTRATION_NO_ACCEPTED);break}for(;!Bm(u.confirmRegistration);)console.log(`
|
|
248
248
|
Is the information provided above correct?`),u.confirmRegistration=(await o.question(V1.bold("Press [Y] to confirm or [N] to edit: "))).toUpperCase();u.confirmRegistration=="N"&&(console.log(`
|
|
249
249
|
Please provide the following information:`),aNe(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=Ri();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=DHt({text:V1.bold("... registering your account."),stream:process.stdout}).start();try{let l=await rNe(),p=await nNe(),h={name:u.fullNameAnswer,email:u.emailAddressAnswer,walletAddress:r?.address,company:u.companyNameAnswer,jobDescription:u.jobPositionAnswer,EULA:Xa.createSignedBody({ip:await _M(),date:new Date().toISOString()},r.privateKey),defaultNamespace:l,defaultApiKey:p};await iNe(h),d.stop(),console.log(rr.SETUP_STEP2_SCENARIO3_P2(u,r.address,l,p)),c.distinct_id=h.walletAddress,c.date_time=Ri(),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,NHt(c))}catch(l){d.stop();let p=l.message,h=f;h.error_details=p,h.date_time=Ri();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 E=p?p.match(/CreateUserValidation - (.*?.*)/)?.[1]:null;if(E)throw Error(E);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(rr.SETUP_STEP2_UNHANDLED_ERROR),process.exit(1)}finally{d.clear()}break}default:throw Error("An unexpected error occurred.")}o.close()}function NHt(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 IWt}from"node:net";import $Ht from"chalk";Ua();L1();import{createInterface as BHt}from"node:readline/promises";import*as qM from"os";async function oNe(t,e,n){let r=qs(),i=r!==null,a=0;switch(i?i&&!r.eula?a=2:a=3:a=1,a){case 1:case 2:{let s=BHt({input:process.stdin,output:process.stdout,terminal:!0}),o="",f={user_ip:t,date_time:Ri(),os_version:qM.type+"_"+qM.release,node_version:process.version,cli_version:e};for(console.log(rr.EULA_INSTALLATION);!Bm(o);)o=(await s.question($Ht.bold(`
|
|
250
250
|
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=Ri(),await n.sendEventToMixpanel("TOS_rejected",f),rr.EULA_INSTALLATION_NO_ACCEPTED;f.date_time=Ri(),await n.sendEventToMixpanel("TOS_accepted",f);let u=Math.round(new Date().getTime()).toString();if(a===1){let c={...Cb(),eula:u};Fke(c)}else a===2&&Ev({eula:u});s.close()}break;case 3:default:break}}Ua();L1();async function df(t=!1){let e=qs(),n=e!==null,r=null,i=0;switch(n?n&&(!e.privateKey||!e.address)?i=2:(r=await FM(e.address,e),r?i=4:i=3):i=1,i){case 1:case 2:case 3:console.log(rr.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 FHt}from"node:readline/promises";L1();Ua();import LHt from"chalk";async function fNe(){console.log(LHt.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.232",
|
|
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": {
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=22.13.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "cb66fb16561b855010e0f09a32365884b1c540e5"
|
|
58
58
|
}
|