@tigrisdata/cli 1.6.3 → 2.1.0

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.
@@ -0,0 +1 @@
1
+ import g from"axios";import N from"open";function w(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var T="https://tigris";import{homedir as A}from"os";import{join as y}from"path";import{readFileSync as I,writeFileSync as O,existsSync as C,mkdirSync as S}from"fs";import{chmod as P}from"fs/promises";var p=y(A(),".tigris"),l=y(p,"config.json");function z(){C(p)||S(p,{recursive:!0,mode:448})}function c(){if(C(l))try{let n=I(l,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function f(n){z(),O(l,JSON.stringify(n,null,2),{mode:384});try{await P(l,384)}catch{}}async function u(n){let e=c();e.tokens=n,await f(e)}async function d(){return c().tokens||null}async function m(){let n=c();delete n.tokens,await f(n)}async function _(n){let e=c();e.organizations=n,await f(e)}function v(){return c().organizations||[]}async function x(n){let e=c();e.loginMethod=n,await f(e)}var k=class{config;baseUrl;constructor(){this.config=w(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await g.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(i.user_code,i.verification_uri),await this.sleep(2e3);try{await N(i.verification_uri_complete)}catch{}e?.onWaiting?.();let r=await this.pollForToken(i.device_code,i.interval||5);await u(r),x("oauth"),await this.extractAndStoreOrganizations(r.idToken)}async pollForToken(e,t){let r=0;for(;r<60;){r++;try{let s=(await g.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,a=Date.now()+(s.expires_in||3600)*1e3;return{accessToken:s.access_token,refreshToken:s.refresh_token,idToken:s.id_token,expiresAt:a}}catch(o){if(g.isAxiosError(o)&&o.response){let s=o.response.data?.error;if(s==="authorization_pending"){await this.sleep(t*1e3);continue}if(s==="slow_down"){t+=5,await this.sleep(t*1e3);continue}throw new Error(o.response.data?.error_description||"Authentication failed")}throw o}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await d();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let t=300*1e3;return Date.now()+t>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let t=null;if(e?.refreshToken?t=e:t=await d(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let r=(await g.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:t.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,o={accessToken:r.access_token,refreshToken:r.refresh_token||t.refreshToken,idToken:r.id_token||t.idToken,expiresAt:Date.now()+(r.expires_in||3600)*1e3};return await u(o),o}catch{throw await m(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await d();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let t=e.idToken.split(".")[1],i=Buffer.from(t,"base64").toString("utf8");return JSON.parse(i)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let t=e.split(".")[1],i=Buffer.from(t,"base64").toString("utf8"),o=JSON.parse(i)[T];if(!o)return;let s=o?.ns?.map(a=>typeof a=="object"&&a!==null?{id:a.id,name:a.name,displayName:a.name}:{id:a,name:a,displayName:a})||[];if(s.length===0)return;_(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),v()}async logout(){await m()}async isAuthenticated(){return await d()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},h=null;function H(){return h||(h=new k),h}export{k as TigrisAuthClient,H as getAuthClient};
@@ -0,0 +1 @@
1
+ function t(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var e="https://tigris";export{e as TIGRIS_CLAIMS_NAMESPACE,t as getAuth0Config};
@@ -0,0 +1 @@
1
+ import{S3Client as N}from"@aws-sdk/client-s3";import{homedir as E}from"os";import{join as v}from"path";import{readFileSync as M,writeFileSync as D,existsSync as _,mkdirSync as b}from"fs";import{chmod as K}from"fs/promises";var p=v(E(),".tigris"),g=v(p,"config.json");function R(){_(p)||b(p,{recursive:!0,mode:448})}function c(){if(_(g))try{let t=M(g,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function l(t){R(),D(g,JSON.stringify(t,null,2),{mode:384});try{await K(g,384)}catch{}}async function h(t){let e=c();e.tokens=t,await l(e)}async function d(){return c().tokens||null}async function m(){let t=c();delete t.tokens,await l(t)}async function I(t){let e=c();e.organizations=t,await l(e)}function A(){return c().organizations||[]}function f(){return c().selectedOrganization||null}function w(){let t=c();return t.temporaryCredentials||t.credentials||null}async function x(t){let e=c();e.loginMethod=t,await l(e)}function S(){return c().loginMethod||null}import u from"axios";import L from"open";function P(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var O="https://tigris";var T=class{config;baseUrl;constructor(){this.config=P(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await u.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(i.user_code,i.verification_uri),await this.sleep(2e3);try{await L(i.verification_uri_complete)}catch{}e?.onWaiting?.();let s=await this.pollForToken(i.device_code,i.interval||5);await h(s),x("oauth"),await this.extractAndStoreOrganizations(s.idToken)}async pollForToken(e,n){let s=0;for(;s<60;){s++;try{let a=(await u.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,r=Date.now()+(a.expires_in||3600)*1e3;return{accessToken:a.access_token,refreshToken:a.refresh_token,idToken:a.id_token,expiresAt:r}}catch(o){if(u.isAxiosError(o)&&o.response){let a=o.response.data?.error;if(a==="authorization_pending"){await this.sleep(n*1e3);continue}if(a==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(o.response.data?.error_description||"Authentication failed")}throw o}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await d();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let n=null;if(e?.refreshToken?n=e:n=await d(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let s=(await u.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,o={accessToken:s.access_token,refreshToken:s.refresh_token||n.refreshToken,idToken:s.id_token||n.idToken,expiresAt:Date.now()+(s.expires_in||3600)*1e3};return await h(o),o}catch{throw await m(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await d();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=e.idToken.split(".")[1],i=Buffer.from(n,"base64").toString("utf8");return JSON.parse(i)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let n=e.split(".")[1],i=Buffer.from(n,"base64").toString("utf8"),o=JSON.parse(i)[O];if(!o)return;let a=o?.ns?.map(r=>typeof r=="object"&&r!==null?{id:r.id,name:r.name,displayName:r.name}:{id:r,name:r,displayName:r})||[];if(a.length===0)return;I(a)}catch{}}async getOrganizations(){return await this.getAccessToken(),A()}async logout(){await m()}async isAuthenticated(){return await d()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},y=null;function k(){return y||(y=new T),y}async function C(){return S()}async function ee(){let t=await C();if(!t)throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.');if(t==="oauth"){let i=await k().getAccessToken();if(!f())throw new Error('No organization selected. Please run "tigris orgs select" first.');let o=process.env.TIGRIS_ENDPOINT??"https://t3.storage.dev",a=process.env.TIGRIS_STORAGE_IAM_ENDPOINT??"https://iam.storageapi.dev",r=process.env.AUTH0_DOMAIN??"https://auth.tigris.dev";return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:o,organizationId:f()??void 0,iamEndpoint:a,authDomain:r}}let e=w();if(!e)throw new Error('No credentials found. Please run "tigris configure" first.');return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint}}async function te(){let t=await C();if(!t)throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.');if(t==="oauth"){let n=await k().getAccessToken(),i=f();if(!i)throw new Error('No organization selected. Please run "tigris orgs select" first.');let s=process.env.TIGRIS_ENDPOINT??"https://t3.storage.dev",o=new N({region:"auto",endpoint:s,credentials:{sessionToken:n,accessKeyId:"",secretAccessKey:""}});return o.middlewareStack.add(a=>async r=>{let z=r.request;return z.headers["x-Tigris-Namespace"]=i,await a(r)},{name:"x-Tigris-Namespace-Middleware",step:"build",override:!0}),o}else{let e=w();if(!e)throw new Error('No credentials found. Please run "tigris configure" first.');return new N({region:"auto",endpoint:e.endpoint,credentials:{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey}})}}async function ne(){return await C()!==null}export{C as getLoginMethod,te as getS3Client,ee as getStorageConfig,ne as isAuthenticated};
@@ -0,0 +1 @@
1
+ import{homedir as c}from"os";import{join as s}from"path";import{readFileSync as g,writeFileSync as f,existsSync as a,mkdirSync as l}from"fs";import{chmod as d}from"fs/promises";var r=s(c(),".tigris"),t=s(r,"config.json");function u(){a(r)||l(r,{recursive:!0,mode:448})}function e(){if(a(t))try{let n=g(t,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function i(n){u(),f(t,JSON.stringify(n,null,2),{mode:384});try{await d(t,384)}catch{}}async function x(n){let o=e();o.tokens=n,await i(o)}async function O(){return e().tokens||null}async function v(){let n=e();delete n.tokens,await i(n)}async function z(n){let o=e();o.organizations=n,await i(o)}function w(){return e().organizations||[]}async function h(n){let o=e();o.selectedOrganization=n,await i(o)}function k(){return e().selectedOrganization||null}function P(){let n=e();return n.temporaryCredentials||n.credentials||null}async function S(n){let o=e();o.credentials=n,await i(o)}async function T(n){let o=e();o.temporaryCredentials=n,await i(o)}async function I(){let n=e();delete n.temporaryCredentials,await i(n)}async function F(){let n=e();delete n.credentials,await i(n)}async function M(n){let o=e();o.loginMethod=n,await i(o)}function N(){return e().loginMethod||null}async function j(){let o=e().credentials;await i({credentials:o})}export{j as clearAllData,F as clearCredentials,I as clearTemporaryCredentials,v as clearTokens,P as getCredentials,N as getLoginMethod,w as getOrganizations,k as getSelectedOrganization,O as getTokens,S as storeCredentials,M as storeLoginMethod,z as storeOrganizations,h as storeSelectedOrganization,T as storeTemporaryCredentials,x as storeTokens};
File without changes
package/dist/cli.js CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/cli.ts
4
- import { Command } from "commander";
5
- var program = new Command();
6
- program.name("tigris").description("Command line interface for Tigris object storage").version("0.0.1");
7
- program.parse();
8
- //# sourceMappingURL=cli.js.map
2
+ import{Command as v}from"commander";import{readFileSync as x}from"fs";import{join as E,dirname as k}from"path";import{fileURLToPath as j}from"url";import*as y from"yaml";var h="2.1.0";var q=j(import.meta.url),R=k(q),P=E(R,"specs.yaml"),D=x(P,"utf8"),a=y.parse(D);function w(e){let t;e.type==="noun"?t=` ${e.name}`:(t=` --${e.name}`,e.alias&&(t+=`, -${e.alias}`));let n=26,s=t.length>=n?t+" ":t.padEnd(n),i=e.description;return e.options&&(Array.isArray(e.options)&&typeof e.options[0]=="string"?i+=` (options: ${e.options.join(", ")})`:i+=` (options: ${e.options.map(o=>o.value).join(", ")})`),e.default&&(i+=` [default: ${e.default}]`),e.required&&(i+=" [required]"),e["required-when"]&&(i+=` [required when: ${e["required-when"]}]`),e.multiple&&(i+=" [multiple values: comma-separated]"),e.type==="noun"&&(i+=" [positional argument]"),e.examples&&e.examples.length>0&&(i+=` (examples: ${e.examples.join(", ")})`),`${s}${i}`}function $(e){console.log(`
3
+ ${a.name} ${e.name} - ${e.description}
4
+ `),e.operations&&e.operations.length>0&&(console.log("Operations:"),e.operations.forEach(t=>{let n=` ${t.name}`;if(t.alias){let i=Array.isArray(t.alias)?t.alias:[t.alias];n+=` (${i.join(", ")})`}let s=n.padEnd(24);console.log(`${s}${t.description}`)}),console.log()),e.arguments&&e.arguments.length>0&&(console.log("Arguments:"),e.arguments.forEach(t=>{console.log(w(t))}),console.log()),console.log(`Use "${a.name} ${e.name} <operation> help" for more information about an operation.`)}function M(e,t){console.log(`
5
+ ${a.name} ${e.name} ${t.name} - ${t.description}
6
+ `),t.arguments&&t.arguments.length>0&&(console.log("Arguments:"),t.arguments.forEach(n=>{console.log(w(n))}),console.log())}function A(){console.log(`Tigris CLI Version: ${h}
7
+ `),console.log(`Usage: tigris [command] [options]
8
+ `),console.log("Commands:"),a.commands.forEach(e=>{let t=` ${e.name}`;e.alias&&(t+=` (${e.alias})`);let n=t.padEnd(24);console.log(`${n}${e.description}`)}),console.log(`
9
+ Use "${a.name} <command> help" for more information about a command.`)}function m(e,t=[]){t.forEach(n=>{if(n.type==="noun"){let s=n.required?`<${n.name}>`:`[${n.name}]`;e.argument(s,n.description)}else{let s=`--${n.name}`;n.alias&&(s+=`, -${n.alias}`),n.options?s+=" <value>":s+=n.required||n["required-when"]?" <value>":" [value]",e.option(s,n.description,n.default)}})}function f(e,t){for(let n of e){if(n["required-when"]){let[s,i]=n["required-when"].split("="),o=d(t,s,e),r=d(t,n.name,e);if(o===i&&!r)return console.error(`--${n.name} is required when --${s} is ${i}`),!1}if(n.required&&!d(t,n.name,e))return console.error(`--${n.name} is required`),!1}return!0}function d(e,t,n){if(n){let i=n.find(o=>o.name===t);if(i&&i.alias){let o=i.alias.charAt(0).toUpperCase()+i.alias.slice(1);if(e[o]!==void 0)return e[o]}}let s=[t,t.replace(/-/g,""),t.replace(/-/g,"").toLowerCase(),t.charAt(0).toUpperCase(),U(t)];for(let i of s)if(e[i]!==void 0)return e[i]}function U(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}async function T(e,t){let n=t?[`./lib/${e}/${t}.js`,`./lib/${e}/${t}/index.js`]:[`./lib/${e}.js`,`./lib/${e}/index.js`];for(let i of n){let o=await import(i).catch(()=>null);if(o)return{module:o,error:null}}return{module:null,error:`Command not found: ${t?`${e} ${t}`:e}`}}async function g(e,t,n=[],s={},i){if(i){let C=i.replace(/\\n/g,`
10
+ `);console.log(C)}let{module:o,error:r}=await T(e,t);(r||!o)&&(console.error(r),process.exit(1));let l=t||e,p=o.default||o[l];typeof p!="function"&&(console.error(`Command not implemented: ${l}`),process.exit(1)),await p({...s,_positional:n})}var u=new v;u.name(a.name).description(a.description).version(a.version);function c(e,t,n){let s;"opts"in n&&typeof n.opts=="function"?s=n.opts():s=n;let i={...s};return e.filter(r=>r.type==="noun").forEach((r,l)=>{t[l]!==void 0&&(r.multiple?i[r.name]=t[l].split(",").map(p=>p.trim()):i[r.name]=t[l])}),e.forEach(r=>{r.multiple&&r.type!=="noun"&&i[r.name]&&typeof i[r.name]=="string"&&(i[r.name]=i[r.name].split(",").map(l=>l.trim()))}),i}a.commands.forEach(e=>{let t=u.command(e.name).description(e.description);if(e.alias&&t.alias(e.alias),e.operations&&e.operations.length>0)if(e.operations.forEach(n=>{let s=t.command(n.name).description(n.description);n.alias&&(Array.isArray(n.alias)?n.alias:[n.alias]).forEach(o=>s.alias(o)),m(s,n.arguments),s.action(async(...i)=>{let o=i.pop(),r=i;n.arguments&&!f(n.arguments,c(n.arguments,r,o))||await g(e.name,n.name,r,c(n.arguments||[],r,o),n.message)}),s.command("help").description("Show help for this operation").action(()=>{M(e,n)})}),e.default){let n=e.operations?.find(s=>s.name===e.default);n&&(m(t,n.arguments),t.action(async(...s)=>{let i=s.pop(),o=s;n.arguments&&!f(n.arguments,c(n.arguments,o,i))||await g(e.name,n.name,o,c(n.arguments||[],o,i),e.message||n.message)}))}else t.action(()=>{$(e)});else m(t,e.arguments),t.action(async(...n)=>{let s=n.pop(),i=n;e.arguments&&!f(e.arguments,c(e.arguments,i,s))||await g(e.name,void 0,i,c(e.arguments||[],i,s),e.message)});t.command("help").description("Show help for this command").action(()=>{$(e)})});u.command("help").description("Show general help").action(()=>{A()});u.action(()=>{A()});u.parse();
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import{Command as x}from"commander";import{readFileSync as v}from"fs";import{join as E,dirname as k}from"path";import{fileURLToPath as j}from"url";import*as y from"yaml";var h="2.1.0";var q=j(import.meta.url),R=k(q),P=E(R,"specs.yaml"),D=v(P,"utf8"),a=y.parse(D);function w(e){let t;e.type==="noun"?t=` ${e.name}`:(t=` --${e.name}`,e.alias&&(t+=`, -${e.alias}`));let n=26,s=t.length>=n?t+" ":t.padEnd(n),i=e.description;return e.options&&(Array.isArray(e.options)&&typeof e.options[0]=="string"?i+=` (options: ${e.options.join(", ")})`:i+=` (options: ${e.options.map(o=>o.value).join(", ")})`),e.default&&(i+=` [default: ${e.default}]`),e.required&&(i+=" [required]"),e["required-when"]&&(i+=` [required when: ${e["required-when"]}]`),e.multiple&&(i+=" [multiple values: comma-separated]"),e.type==="noun"&&(i+=" [positional argument]"),e.examples&&e.examples.length>0&&(i+=` (examples: ${e.examples.join(", ")})`),`${s}${i}`}function $(e){console.log(`
2
+ ${a.name} ${e.name} - ${e.description}
3
+ `),e.operations&&e.operations.length>0&&(console.log("Operations:"),e.operations.forEach(t=>{let n=` ${t.name}`;if(t.alias){let i=Array.isArray(t.alias)?t.alias:[t.alias];n+=` (${i.join(", ")})`}let s=n.padEnd(24);console.log(`${s}${t.description}`)}),console.log()),e.arguments&&e.arguments.length>0&&(console.log("Arguments:"),e.arguments.forEach(t=>{console.log(w(t))}),console.log()),console.log(`Use "${a.name} ${e.name} <operation> help" for more information about an operation.`)}function M(e,t){console.log(`
4
+ ${a.name} ${e.name} ${t.name} - ${t.description}
5
+ `),t.arguments&&t.arguments.length>0&&(console.log("Arguments:"),t.arguments.forEach(n=>{console.log(w(n))}),console.log())}function A(){console.log(`Tigris CLI Version: ${h}
6
+ `),console.log(`Usage: tigris [command] [options]
7
+ `),console.log("Commands:"),a.commands.forEach(e=>{let t=` ${e.name}`;e.alias&&(t+=` (${e.alias})`);let n=t.padEnd(24);console.log(`${n}${e.description}`)}),console.log(`
8
+ Use "${a.name} <command> help" for more information about a command.`)}function m(e,t=[]){t.forEach(n=>{if(n.type==="noun"){let s=n.required?`<${n.name}>`:`[${n.name}]`;e.argument(s,n.description)}else{let s=`--${n.name}`;n.alias&&(s+=`, -${n.alias}`),n.options?s+=" <value>":s+=n.required||n["required-when"]?" <value>":" [value]",e.option(s,n.description,n.default)}})}function f(e,t){for(let n of e){if(n["required-when"]){let[s,i]=n["required-when"].split("="),o=d(t,s,e),r=d(t,n.name,e);if(o===i&&!r)return console.error(`--${n.name} is required when --${s} is ${i}`),!1}if(n.required&&!d(t,n.name,e))return console.error(`--${n.name} is required`),!1}return!0}function d(e,t,n){if(n){let i=n.find(o=>o.name===t);if(i&&i.alias){let o=i.alias.charAt(0).toUpperCase()+i.alias.slice(1);if(e[o]!==void 0)return e[o]}}let s=[t,t.replace(/-/g,""),t.replace(/-/g,"").toLowerCase(),t.charAt(0).toUpperCase(),U(t)];for(let i of s)if(e[i]!==void 0)return e[i]}function U(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}async function T(e,t){let n=t?[`./lib/${e}/${t}.js`,`./lib/${e}/${t}/index.js`]:[`./lib/${e}.js`,`./lib/${e}/index.js`];for(let i of n){let o=await import(i).catch(()=>null);if(o)return{module:o,error:null}}return{module:null,error:`Command not found: ${t?`${e} ${t}`:e}`}}async function g(e,t,n=[],s={},i){if(i){let C=i.replace(/\\n/g,`
9
+ `);console.log(C)}let{module:o,error:r}=await T(e,t);(r||!o)&&(console.error(r),process.exit(1));let l=t||e,p=o.default||o[l];typeof p!="function"&&(console.error(`Command not implemented: ${l}`),process.exit(1)),await p({...s,_positional:n})}var u=new x;u.name(a.name).description(a.description).version(a.version);function c(e,t,n){let s;"opts"in n&&typeof n.opts=="function"?s=n.opts():s=n;let i={...s};return e.filter(r=>r.type==="noun").forEach((r,l)=>{t[l]!==void 0&&(r.multiple?i[r.name]=t[l].split(",").map(p=>p.trim()):i[r.name]=t[l])}),e.forEach(r=>{r.multiple&&r.type!=="noun"&&i[r.name]&&typeof i[r.name]=="string"&&(i[r.name]=i[r.name].split(",").map(l=>l.trim()))}),i}a.commands.forEach(e=>{let t=u.command(e.name).description(e.description);if(e.alias&&t.alias(e.alias),e.operations&&e.operations.length>0)if(e.operations.forEach(n=>{let s=t.command(n.name).description(n.description);n.alias&&(Array.isArray(n.alias)?n.alias:[n.alias]).forEach(o=>s.alias(o)),m(s,n.arguments),s.action(async(...i)=>{let o=i.pop(),r=i;n.arguments&&!f(n.arguments,c(n.arguments,r,o))||await g(e.name,n.name,r,c(n.arguments||[],r,o),n.message)}),s.command("help").description("Show help for this operation").action(()=>{M(e,n)})}),e.default){let n=e.operations?.find(s=>s.name===e.default);n&&(m(t,n.arguments),t.action(async(...s)=>{let i=s.pop(),o=s;n.arguments&&!f(n.arguments,c(n.arguments,o,i))||await g(e.name,n.name,o,c(n.arguments||[],o,i),e.message||n.message)}))}else t.action(()=>{$(e)});else m(t,e.arguments),t.action(async(...n)=>{let s=n.pop(),i=n;e.arguments&&!f(e.arguments,c(e.arguments,i,s))||await g(e.name,void 0,i,c(e.arguments||[],i,s),e.message)});t.command("help").description("Show help for this command").action(()=>{$(e)})});u.command("help").description("Show general help").action(()=>{A()});u.action(()=>{A()});u.parse();
@@ -0,0 +1,2 @@
1
+ function f(t,e,n){for(let i of e)if(t[i]!==void 0)return t[i];return n}import fe from"enquirer";import{readFileSync as Q,existsSync as X}from"fs";import{join as z,dirname as Z}from"path";import{fileURLToPath as ee}from"url";import*as D from"yaml";var te=ee(import.meta.url),ne=Z(te),x=null;function ie(){let t=ne;for(let e=0;e<5;e++){let n=z(t,"specs.yaml");if(X(n))return n;t=z(t,"..")}throw new Error("Could not find specs.yaml")}function se(){if(!x){let t=ie(),e=Q(t,"utf8");x=D.parse(e)}return x}function A(t,e){let i=se().commands.find(s=>s.name===t);return i?e&&i.operations?i.operations.find(s=>s.name===e)||null:i:null}function m(t,e,n){let i=A(t,n);return!i||!i.arguments?null:i.arguments.find(s=>s.name===e)||null}function h(t){return t.options?Array.isArray(t.options)&&typeof t.options[0]=="string"?t.options.map(e=>({name:e,message:e.charAt(0).toUpperCase()+e.slice(1),value:e})):Array.isArray(t.options)&&typeof t.options[0]=="object"?t.options.map(e=>({name:e.value,message:e.description?`${e.name} - ${e.description}`:e.name,value:e.value})):null:null}import{createBucket as pe}from"@tigrisdata/storage";import{S3Client as ze}from"@aws-sdk/client-s3";import{homedir as oe}from"os";import{join as R}from"path";import{readFileSync as re,writeFileSync as ae,existsSync as K,mkdirSync as ce}from"fs";import{chmod as de}from"fs/promises";var v=R(oe(),".tigris"),C=R(v,"config.json");function le(){K(v)||ce(v,{recursive:!0,mode:448})}function g(){if(K(C))try{let t=re(C,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function T(t){le(),ae(C,JSON.stringify(t,null,2),{mode:384});try{await de(C,384)}catch{}}async function I(t){let e=g();e.tokens=t,await T(e)}async function y(){return g().tokens||null}async function _(){let t=g();delete t.tokens,await T(t)}async function L(t){let e=g();e.organizations=t,await T(e)}function F(){return g().organizations||[]}function O(){return g().selectedOrganization||null}function $(){let t=g();return t.temporaryCredentials||t.credentials||null}async function U(t){let e=g();e.loginMethod=t,await T(e)}function q(){return g().loginMethod||null}import k from"axios";import ge from"open";function j(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var H="https://tigris";var b=class{config;baseUrl;constructor(){this.config=j(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await k.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(i.user_code,i.verification_uri),await this.sleep(2e3);try{await ge(i.verification_uri_complete)}catch{}e?.onWaiting?.();let s=await this.pollForToken(i.device_code,i.interval||5);await I(s),U("oauth"),await this.extractAndStoreOrganizations(s.idToken)}async pollForToken(e,n){let s=0;for(;s<60;){s++;try{let c=(await k.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,r=Date.now()+(c.expires_in||3600)*1e3;return{accessToken:c.access_token,refreshToken:c.refresh_token,idToken:c.id_token,expiresAt:r}}catch(o){if(k.isAxiosError(o)&&o.response){let c=o.response.data?.error;if(c==="authorization_pending"){await this.sleep(n*1e3);continue}if(c==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(o.response.data?.error_description||"Authentication failed")}throw o}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await y();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let n=null;if(e?.refreshToken?n=e:n=await y(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let s=(await k.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,o={accessToken:s.access_token,refreshToken:s.refresh_token||n.refreshToken,idToken:s.id_token||n.idToken,expiresAt:Date.now()+(s.expires_in||3600)*1e3};return await I(o),o}catch{throw await _(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await y();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=e.idToken.split(".")[1],i=Buffer.from(n,"base64").toString("utf8");return JSON.parse(i)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let n=e.split(".")[1],i=Buffer.from(n,"base64").toString("utf8"),o=JSON.parse(i)[H];if(!o)return;let c=o?.ns?.map(r=>typeof r=="object"&&r!==null?{id:r.id,name:r.name,displayName:r.name}:{id:r,name:r,displayName:r})||[];if(c.length===0)return;L(c)}catch{}}async getOrganizations(){return await this.getAccessToken(),F()}async logout(){await _()}async isAuthenticated(){return await y()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},P=null;function V(){return P||(P=new b),P}async function ue(){return q()}async function G(){let t=await ue();if(!t)throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.');if(t==="oauth"){let i=await V().getAccessToken();if(!O())throw new Error('No organization selected. Please run "tigris orgs select" first.');let o=process.env.TIGRIS_ENDPOINT??"https://t3.storage.dev",c=process.env.TIGRIS_STORAGE_IAM_ENDPOINT??"https://iam.storageapi.dev",r=process.env.AUTH0_DOMAIN??"https://auth.tigris.dev";return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:o,organizationId:O()??void 0,iamEndpoint:c,authDomain:r}}let e=$();if(!e)throw new Error('No credentials found. Please run "tigris configure" first.');return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint}}var B={success:"\u2714",failure:"\u2716",hint:"\u2192"};function M(t){let e=A(t.command,t.operation);if(e)return e.messages}function N(t,e){let n=t;return n=n.replace(/\\n/g,`
2
+ `),e&&(n=n.replace(/\{\{(\w+)\}\}/g,(i,s)=>{let o=e[s];return o!==void 0?String(o):`{{${s}}}`})),n}function J(t,e){let n=M(t);n?.onStart&&console.log(N(n.onStart,e))}function W(t,e){let n=M(t);n?.onSuccess&&console.log(`${B.success} ${N(n.onSuccess,e)}`)}function S(t,e,n){let i=M(t);i?.onFailure&&console.error(`${B.failure} ${N(i.onFailure,n)}`),e&&console.error(` ${e}`)}function Y(t,e){return{command:t,operation:e}}var{prompt:me}=fe,w=Y("buckets","create");async function he(t){J(w);let e=!f(t,["name"]),n=f(t,["name"]),i=e?void 0:f(t,["access","a","A"]),s=e?void 0:f(t,["enable-snapshots","s","S"]),o=e?void 0:f(t,["default-tier","t","T"]),c=e?void 0:f(t,["consistency","c","C"]),r=e?void 0:f(t,["region","r","R"]),u=[];if((!n||e)&&u.push({type:"input",name:"name",message:"Bucket name:",required:!0}),!i||e){let a=m("buckets","access","create"),l=h(a),d=l?.findIndex(p=>p.value===a?.default);u.push({type:"select",name:"access",message:"Access level:",choices:l||[],initial:d!==void 0&&d>=0?d:0})}if(!o||e){let a=m("buckets","default-tier","create"),l=h(a),d=l?.findIndex(p=>p.value===a?.default);u.push({type:"select",name:"defaultTier",message:"Default storage tier:",choices:l||[],initial:d!==void 0&&d>=0?d:0})}if(!c||e){let a=m("buckets","consistency","create"),l=h(a),d=l?.findIndex(p=>p.value===a?.default);u.push({type:"select",name:"consistency",message:"Consistency level:",choices:l||[],initial:d!==void 0&&d>=0?d:0})}if(!r||e){let a=m("buckets","region","create"),l=h(a),d=l?.findIndex(p=>p.value===a?.default);u.push({type:"select",name:"region",message:"Region:",choices:l||[],initial:d!==void 0&&d>=0?d:0})}if((s===void 0||e)&&u.push({type:"confirm",name:"enableSnapshots",message:"Enable snapshots?",initial:!0}),u.length>0)try{let a=await me(u);n=n||a.name,i=i||a.access,s=s!==void 0?s:a.enableSnapshots,o=o||a.defaultTier,c=c||a.consistency,r=r!==void 0?r:a.region}catch{S(w,"Operation cancelled"),process.exit(1)}n||(S(w,"Bucket name is required"),process.exit(1));let{error:E}=await pe(n,{defaultTier:o??"STANDARD",consistency:c==="strict"?"strict":"default",enableSnapshot:s===!0,region:r!=="global"&&r!==void 0?r.split(","):void 0,config:await G()});E&&(S(w,E.message),process.exit(1)),W(w,{name:n})}export{he as default};
@@ -0,0 +1,7 @@
1
+ function P(t,e,n){for(let o of e)if(t[o]!==void 0)return t[o];return n}function Q(t){return JSON.stringify(t,null,2)}function Z(t,e=" "){return Object.entries(t).map(([n,o])=>`${e}<${n}>${o}</${n}>`).join(`
2
+ `)}function ee(t,e,n){let o=[`<${e}>`];return t.forEach(r=>{o.push(` <${n}>`),o.push(Z(r," ")),o.push(` </${n}>`)}),o.push(`</${e}>`),o.join(`
3
+ `)}function M(t){if(t==null)return"";if(t instanceof Date)return b(t);if(typeof t=="string"){let e=new Date(t);if(!isNaN(e.getTime())&&t.includes("T"))return b(e)}return String(t)}function b(t){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(t)}function te(t,e){return e.map(n=>{if(n.width)return n.width;let o=n.header.length,r=t.reduce((i,s)=>{let a=M(s[n.key]);return Math.max(i,a.length)},0);return Math.max(o,r)})}function ne(t,e){let n=[],o=te(t,e),r="\u250C"+o.map(c=>"\u2500".repeat(c+2)).join("\u252C")+"\u2510",i="\u251C"+o.map(c=>"\u2500".repeat(c+2)).join("\u253C")+"\u2524",s="\u2514"+o.map(c=>"\u2500".repeat(c+2)).join("\u2534")+"\u2518";n.push(`
4
+ `+r);let a="\u2502 "+e.map((c,w)=>c.header.padEnd(o[w])).join(" \u2502 ")+" \u2502";return n.push(a),n.push(i),t.forEach(c=>{let w=e.map((_,I)=>{let O=M(c[_.key]);return _.align==="right"?O.padStart(o[I]):O.padEnd(o[I])});n.push("\u2502 "+w.join(" \u2502 ")+" \u2502")}),n.push(s+`
5
+ `),n.join(`
6
+ `)}function N(t,e,n,o,r){switch(e){case"json":return Q(t);case"xml":return ee(t,n,o);default:return ne(t,r)}}import{S3Client as ze}from"@aws-sdk/client-s3";import{homedir as oe}from"os";import{join as E}from"path";import{readFileSync as re,writeFileSync as ie,existsSync as D,mkdirSync as se}from"fs";import{chmod as ae}from"fs/promises";var T=E(oe(),".tigris"),l=E(T,"config.json");function ce(){D(T)||se(T,{recursive:!0,mode:448})}function d(){if(D(l))try{let t=re(l,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function p(t){ce(),ie(l,JSON.stringify(t,null,2),{mode:384});try{await ae(l,384)}catch{}}async function k(t){let e=d();e.tokens=t,await p(e)}async function g(){return d().tokens||null}async function C(){let t=d();delete t.tokens,await p(t)}async function z(t){let e=d();e.organizations=t,await p(e)}function R(){return d().organizations||[]}function x(){return d().selectedOrganization||null}function $(){let t=d();return t.temporaryCredentials||t.credentials||null}async function j(t){let e=d();e.loginMethod=t,await p(e)}function F(){return d().loginMethod||null}import f from"axios";import de from"open";function K(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var L="https://tigris";var A=class{config;baseUrl;constructor(){this.config=K(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await f.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await de(o.verification_uri_complete)}catch{}e?.onWaiting?.();let r=await this.pollForToken(o.device_code,o.interval||5);await k(r),j("oauth"),await this.extractAndStoreOrganizations(r.idToken)}async pollForToken(e,n){let r=0;for(;r<60;){r++;try{let s=(await f.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,a=Date.now()+(s.expires_in||3600)*1e3;return{accessToken:s.access_token,refreshToken:s.refresh_token,idToken:s.id_token,expiresAt:a}}catch(i){if(f.isAxiosError(i)&&i.response){let s=i.response.data?.error;if(s==="authorization_pending"){await this.sleep(n*1e3);continue}if(s==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(i.response.data?.error_description||"Authentication failed")}throw i}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await g();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let n=null;if(e?.refreshToken?n=e:n=await g(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let r=(await f.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,i={accessToken:r.access_token,refreshToken:r.refresh_token||n.refreshToken,idToken:r.id_token||n.idToken,expiresAt:Date.now()+(r.expires_in||3600)*1e3};return await k(i),i}catch{throw await C(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await g();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=e.idToken.split(".")[1],o=Buffer.from(n,"base64").toString("utf8");return JSON.parse(o)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let n=e.split(".")[1],o=Buffer.from(n,"base64").toString("utf8"),i=JSON.parse(o)[L];if(!i)return;let s=i?.ns?.map(a=>typeof a=="object"&&a!==null?{id:a.id,name:a.name,displayName:a.name}:{id:a,name:a,displayName:a})||[];if(s.length===0)return;z(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),R()}async logout(){await C()}async isAuthenticated(){return await g()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},S=null;function U(){return S||(S=new A),S}async function ue(){return F()}async function V(){let t=await ue();if(!t)throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.');if(t==="oauth"){let o=await U().getAccessToken();if(!x())throw new Error('No organization selected. Please run "tigris orgs select" first.');let i=process.env.TIGRIS_ENDPOINT??"https://t3.storage.dev",s=process.env.TIGRIS_STORAGE_IAM_ENDPOINT??"https://iam.storageapi.dev",a=process.env.AUTH0_DOMAIN??"https://auth.tigris.dev";return{sessionToken:o,accessKeyId:"",secretAccessKey:"",endpoint:i,organizationId:x()??void 0,iamEndpoint:s,authDomain:a}}let e=$();if(!e)throw new Error('No credentials found. Please run "tigris configure" first.');return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint}}import{listBuckets as Te}from"@tigrisdata/storage";import{readFileSync as ge,existsSync as le}from"fs";import{join as H,dirname as pe}from"path";import{fileURLToPath as fe}from"url";import*as J from"yaml";var me=fe(import.meta.url),he=pe(me),v=null;function ye(){let t=he;for(let e=0;e<5;e++){let n=H(t,"specs.yaml");if(le(n))return n;t=H(t,"..")}throw new Error("Could not find specs.yaml")}function we(){if(!v){let t=ye(),e=ge(t,"utf8");v=J.parse(e)}return v}function B(t,e){let o=we().commands.find(r=>r.name===t);return o?e&&o.operations?o.operations.find(r=>r.name===e)||null:o:null}var G={success:"\u2714",failure:"\u2716",hint:"\u2192"};function m(t){let e=B(t.command,t.operation);if(e)return e.messages}function h(t,e){let n=t;return n=n.replace(/\\n/g,`
7
+ `),e&&(n=n.replace(/\{\{(\w+)\}\}/g,(o,r)=>{let i=e[r];return i!==void 0?String(i):`{{${r}}}`})),n}function W(t,e){let n=m(t);n?.onStart&&console.log(h(n.onStart,e))}function q(t,e){let n=m(t);n?.onSuccess&&console.log(`${G.success} ${h(n.onSuccess,e)}`)}function y(t,e,n){let o=m(t);o?.onFailure&&console.error(`${G.failure} ${h(o.onFailure,n)}`),e&&console.error(` ${e}`)}function Y(t,e){let n=m(t);n?.onEmpty&&console.log(h(n.onEmpty,e))}function X(t,e){return{command:t,operation:e}}var u=X("buckets","list");async function ke(t){W(u);try{let e=P(t,["format","F"],"table"),{data:n,error:o}=await Te({config:await V()});if(o&&(y(u,o.message),process.exit(1)),!n.buckets||n.buckets.length===0){Y(u);return}let r=n.buckets.map(s=>({name:s.name,created:s.creationDate})),i=N(r,e,"buckets","bucket",[{key:"name",header:"Name"},{key:"created",header:"Created"}]);console.log(i),q(u,{count:r.length})}catch(e){e instanceof Error?y(u,e.message):y(u,"An unknown error occurred"),process.exit(1)}}export{ke as default};
@@ -0,0 +1,2 @@
1
+ import L from"enquirer";import{homedir as P}from"os";import{join as p}from"path";import{readFileSync as T,writeFileSync as k,existsSync as u,mkdirSync as I}from"fs";import{chmod as z}from"fs/promises";var g=p(P(),".tigris"),a=p(g,"config.json");function K(){u(g)||I(g,{recursive:!0,mode:448})}function m(){if(u(a))try{let e=T(a,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function y(e){K(),k(a,JSON.stringify(e,null,2),{mode:384});try{await z(a,384)}catch{}}async function C(e){let n=m();n.credentials=e,await y(n)}async function S(e){let n=m();n.loginMethod=e,await y(n)}import{readFileSync as b,existsSync as F}from"fs";import{join as x,dirname as $}from"path";import{fileURLToPath as D}from"url";import*as h from"yaml";var E=D(import.meta.url),V=$(E),l=null;function _(){let e=V;for(let n=0;n<5;n++){let t=x(e,"specs.yaml");if(F(t))return t;e=x(e,"..")}throw new Error("Could not find specs.yaml")}function j(){if(!l){let e=_(),n=b(e,"utf8");l=h.parse(n)}return l}function v(e,n){let s=j().commands.find(r=>r.name===e);return s?n&&s.operations?s.operations.find(r=>r.name===n)||null:s:null}var M={success:"\u2714",failure:"\u2716",hint:"\u2192"};function f(e){let n=v(e.command,e.operation);if(n)return n.messages}function d(e,n){let t=e;return t=t.replace(/\\n/g,`
2
+ `),n&&(t=t.replace(/\{\{(\w+)\}\}/g,(s,r)=>{let o=n[r];return o!==void 0?String(o):`{{${r}}}`})),t}function A(e,n){let t=f(e);t?.onStart&&console.log(d(t.onStart,n))}function O(e,n){let t=f(e);t?.onSuccess&&console.log(`${M.success} ${d(t.onSuccess,n)}`)}function c(e,n,t){let s=f(e);s?.onFailure&&console.error(`${M.failure} ${d(s.onFailure,t)}`),n&&console.error(` ${n}`)}function w(e,n){return{command:e,operation:n}}var{prompt:q}=L,i=w("configure");async function N(e){A(i);let n=e["access-key"]||e.accessKey||e.key||e.Key||e.accesskey,t=e["access-secret"]||e.accessSecret||e.secret||e.Secret||e.accesssecret,s=e.endpoint||e.e||e.E||e.Endpoint;if(!n||!t||!s)try{let r=[];n||r.push({type:"input",name:"accessKey",message:"Tigris Access Key ID:",required:!0}),t||r.push({type:"password",name:"accessSecret",message:"Tigris Secret Access Key:",required:!0}),s||r.push({type:"input",name:"endpoint",message:"Tigris Endpoint:",required:!0,initial:process.env.TIGRIS_ENDPOINT??"https://t3.storage.dev"});let o=await q(r);n=n||o.accessKey,t=t||o.accessSecret,s=s||o.endpoint}catch{c(i,"Configuration cancelled"),process.exit(1)}(!n||!t||!s)&&(c(i,"All credentials are required"),process.exit(1));try{await C({accessKeyId:n,secretAccessKey:t,endpoint:s}),await S("credentials"),O(i)}catch{c(i,"Failed to save credentials"),process.exit(1)}}export{N as default};
package/dist/lib/cp.js ADDED
@@ -0,0 +1 @@
1
+ async function t(e){let s=e.src||e._positional?.[0],r=e.dest||e._positional?.[1];(!s||!r)&&(console.error("both src and dest arguments are required"),process.exit(1)),console.error("cp command not yet implemented"),process.exit(1)}export{t as default};
@@ -0,0 +1,2 @@
1
+ import J from"enquirer";import{homedir as b}from"os";import{join as v}from"path";import{readFileSync as F,writeFileSync as $,existsSync as h,mkdirSync as D}from"fs";import{chmod as L}from"fs/promises";var f=v(b(),".tigris"),d=v(f,"config.json");function V(){h(f)||D(f,{recursive:!0,mode:448})}function u(){if(h(d))try{let e=F(d,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function M(e){V(),$(d,JSON.stringify(e,null,2),{mode:384});try{await L(d,384)}catch{}}function p(){let e=u();return e.temporaryCredentials||e.credentials||null}async function A(e){let n=u();n.temporaryCredentials=e,await M(n)}async function w(e){let n=u();n.loginMethod=e,await M(n)}import{readFileSync as j,existsSync as q}from"fs";import{join as P,dirname as _}from"path";import{fileURLToPath as E}from"url";import*as K from"yaml";var N=E(import.meta.url),R=_(N),m=null;function U(){let e=R;for(let n=0;n<5;n++){let s=P(e,"specs.yaml");if(q(s))return s;e=P(e,"..")}throw new Error("Could not find specs.yaml")}function G(){if(!m){let e=U(),n=j(e,"utf8");m=K.parse(n)}return m}function O(e,n){let t=G().commands.find(r=>r.name===e);return t?n&&t.operations?t.operations.find(r=>r.name===n)||null:t:null}var T={success:"\u2714",failure:"\u2716",hint:"\u2192"};function y(e){let n=O(e.command,e.operation);if(n)return n.messages}function C(e,n){let s=e;return s=s.replace(/\\n/g,`
2
+ `),n&&(s=s.replace(/\{\{(\w+)\}\}/g,(t,r)=>{let g=n[r];return g!==void 0?String(g):`{{${r}}}`})),s}function k(e,n){let s=y(e);s?.onStart&&console.log(C(s.onStart,n))}function I(e,n){let s=y(e);s?.onSuccess&&console.log(`${T.success} ${C(s.onSuccess,n)}`)}function l(e,n,s){let t=y(e);t?.onFailure&&console.error(`${T.failure} ${C(t.onFailure,s)}`),n&&console.error(` ${n}`)}function z(e,n){return{command:e,operation:n}}var{prompt:S}=J,c=z("login","credentials");async function Y(e){k(c);let n=e["access-key"]||e.accessKey||e.key||e.Key||e.accesskey,s=e["access-secret"]||e.accessSecret||e.secret||e.Secret||e.accesssecret,t=e.profile||e.Profile||e.p||e.P;if(!n||!s){let a=p();if(a)if(t)n=a.accessKeyId,s=a.secretAccessKey;else try{if((await S({type:"confirm",name:"useSaved",message:"Saved credentials found. Use them?",initial:!0})).useSaved)n=a.accessKeyId,s=a.secretAccessKey;else{let i=[];n||i.push({type:"input",name:"accessKey",message:"Tigris Access Key ID:",required:!0}),s||i.push({type:"password",name:"accessSecret",message:"Tigris Secret Access Key:",required:!0});let x=await S(i);n=n||x.accessKey,s=s||x.accessSecret}}catch{l(c,"Login cancelled"),process.exit(1)}else{t&&(l(c,'No saved credentials found. Please run "tigris configure" first.'),process.exit(1));try{let o=[];n||o.push({type:"input",name:"accessKey",message:"Tigris Access Key ID:",required:!0}),s||o.push({type:"password",name:"accessSecret",message:"Tigris Secret Access Key:",required:!0});let i=await S(o);n=n||i.accessKey,s=s||i.accessSecret}catch{l(c,"Login cancelled"),process.exit(1)}}}(!n||!s)&&(l(c,"Access key and secret are required"),process.exit(1));let g=p()?.endpoint||"https://t3.storage.dev";await A({accessKeyId:n,secretAccessKey:s,endpoint:g}),await w("credentials"),I(c)}export{Y as default};
@@ -0,0 +1,5 @@
1
+ import ge from"enquirer";import T from"axios";import te from"open";function N(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var E="https://tigris";import{homedir as G}from"os";import{join as F}from"path";import{readFileSync as Y,writeFileSync as Q,existsSync as $,mkdirSync as X}from"fs";import{chmod as Z}from"fs/promises";var v=F(G(),".tigris"),S=F(v,"config.json");function ee(){$(v)||X(v,{recursive:!0,mode:448})}function c(){if($(S))try{let e=Y(S,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function g(e){ee(),Q(S,JSON.stringify(e,null,2),{mode:384});try{await Z(S,384)}catch{}}async function A(e){let t=c();t.tokens=e,await g(t)}async function m(){return c().tokens||null}async function _(){let e=c();delete e.tokens,await g(e)}async function L(e){let t=c();t.organizations=e,await g(t)}function R(){return c().organizations||[]}async function U(e){let t=c();t.selectedOrganization=e,await g(t)}function O(){let e=c();return e.temporaryCredentials||e.credentials||null}async function j(e){let t=c();t.temporaryCredentials=e,await g(t)}async function k(e){let t=c();t.loginMethod=e,await g(t)}var I=class{config;baseUrl;constructor(){this.config=N(),this.baseUrl=`https://${this.config.domain}`}async login(t){let s=(await T.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;t?.onDeviceCode?.(s.user_code,s.verification_uri),await this.sleep(2e3);try{await te(s.verification_uri_complete)}catch{}t?.onWaiting?.();let r=await this.pollForToken(s.device_code,s.interval||5);await A(r),k("oauth"),await this.extractAndStoreOrganizations(r.idToken)}async pollForToken(t,n){let r=0;for(;r<60;){r++;try{let a=(await T.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:t,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,o=Date.now()+(a.expires_in||3600)*1e3;return{accessToken:a.access_token,refreshToken:a.refresh_token,idToken:a.id_token,expiresAt:o}}catch(i){if(T.isAxiosError(i)&&i.response){let a=i.response.data?.error;if(a==="authorization_pending"){await this.sleep(n*1e3);continue}if(a==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(i.response.data?.error_description||"Authentication failed")}throw i}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let t=await m();if(!t)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=t.expiresAt&&(t=await this.refreshAccessToken(t)),t.accessToken}async refreshAccessToken(t){let n=null;if(t?.refreshToken?n=t:n=await m(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let r=(await T.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,i={accessToken:r.access_token,refreshToken:r.refresh_token||n.refreshToken,idToken:r.id_token||n.idToken,expiresAt:Date.now()+(r.expires_in||3600)*1e3};return await A(i),i}catch{throw await _(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let t=await m();if(!t||!t.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=t.idToken.split(".")[1],s=Buffer.from(n,"base64").toString("utf8");return JSON.parse(s)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(t){if(t)try{let n=t.split(".")[1],s=Buffer.from(n,"base64").toString("utf8"),i=JSON.parse(s)[E];if(!i)return;let a=i?.ns?.map(o=>typeof o=="object"&&o!==null?{id:o.id,name:o.name,displayName:o.name}:{id:o,name:o,displayName:o})||[];if(a.length===0)return;L(a)}catch{}}async getOrganizations(){return await this.getAccessToken(),R()}async logout(){await _()}async isAuthenticated(){return await m()!==null}sleep(t){return new Promise(n=>setTimeout(n,t))}},P=null;function q(){return P||(P=new I),P}import{readFileSync as ne,existsSync as se}from"fs";import{join as V,dirname as re}from"path";import{fileURLToPath as ie}from"url";import*as H from"yaml";var oe=ie(import.meta.url),ae=re(oe),M=null;function ce(){let e=ae;for(let t=0;t<5;t++){let n=V(e,"specs.yaml");if(se(n))return n;e=V(e,"..")}throw new Error("Could not find specs.yaml")}function le(){if(!M){let e=ce(),t=ne(e,"utf8");M=H.parse(t)}return M}function J(e,t){let s=le().commands.find(r=>r.name===e);return s?t&&s.operations?s.operations.find(r=>r.name===t)||null:s:null}var b={success:"\u2714",failure:"\u2716",hint:"\u2192"};function y(e){let t=J(e.command,e.operation);if(t)return t.messages}function h(e,t){let n=e;return n=n.replace(/\\n/g,`
2
+ `),t&&(n=n.replace(/\{\{(\w+)\}\}/g,(s,r)=>{let i=t[r];return i!==void 0?String(i):`{{${r}}}`})),n}function x(e,t){let n=y(e);n?.onStart&&console.log(h(n.onStart,t))}function w(e,t){let n=y(e);n?.onSuccess&&console.log(`${b.success} ${h(n.onSuccess,t)}`)}function l(e,t,n){let s=y(e);s?.onFailure&&console.error(`${b.failure} ${h(s.onFailure,n)}`),t&&console.error(` ${t}`)}function W(e,t){let n=y(e);n?.onAlreadyDone&&console.log(h(n.onAlreadyDone,t))}function B(e,t){let n=y(e);n?.hint&&console.log(`${b.hint} ${h(n.hint,t)}`)}function u(e,t){return{command:e,operation:t}}var f=u("login","ui");async function z(){x(f);try{let e=q();if(await e.isAuthenticated()){W(f);return}await e.login({onDeviceCode:(s,r)=>{console.log(`
3
+ Your confirmation code: ${s}
4
+ `),console.log(`If browser doesn't open, visit: ${r}`)},onWaiting:()=>console.log(`
5
+ Waiting for authentication...`)});let n=await e.getOrganizations();if(n.length>0){let s=n[0];U(s.id),w(f,{org:s.displayName||s.name}),n.length>1&&B(f,{count:n.length})}else w(f,{org:"none"})}catch{l(f),process.exit(1)}}import de from"enquirer";var{prompt:K}=de,p=u("login","credentials");async function C(e){x(p);let t=e["access-key"]||e.accessKey||e.key||e.Key||e.accesskey,n=e["access-secret"]||e.accessSecret||e.secret||e.Secret||e.accesssecret,s=e.profile||e.Profile||e.p||e.P;if(!t||!n){let a=O();if(a)if(s)t=a.accessKeyId,n=a.secretAccessKey;else try{if((await K({type:"confirm",name:"useSaved",message:"Saved credentials found. Use them?",initial:!0})).useSaved)t=a.accessKeyId,n=a.secretAccessKey;else{let d=[];t||d.push({type:"input",name:"accessKey",message:"Tigris Access Key ID:",required:!0}),n||d.push({type:"password",name:"accessSecret",message:"Tigris Secret Access Key:",required:!0});let D=await K(d);t=t||D.accessKey,n=n||D.accessSecret}}catch{l(p,"Login cancelled"),process.exit(1)}else{s&&(l(p,'No saved credentials found. Please run "tigris configure" first.'),process.exit(1));try{let o=[];t||o.push({type:"input",name:"accessKey",message:"Tigris Access Key ID:",required:!0}),n||o.push({type:"password",name:"accessSecret",message:"Tigris Secret Access Key:",required:!0});let d=await K(o);t=t||d.accessKey,n=n||d.accessSecret}catch{l(p,"Login cancelled"),process.exit(1)}}}(!t||!n)&&(l(p,"Access key and secret are required"),process.exit(1));let i=O()?.endpoint||"https://t3.storage.dev";await j({accessKeyId:t,secretAccessKey:n,endpoint:i}),await k("credentials"),w(p)}var{prompt:ue}=ge,fe=u("login","select");async function pe(e){let t=e.profile||e.Profile||e.p||e.P,n=e["access-key"]||e.accessKey||e.key||e.Key||e.accesskey,s=e["access-secret"]||e.accessSecret||e.secret||e.Secret||e.accesssecret,r=e.oauth||e.OAuth||e.o||e.O;if(t){await C(e);return}if(n||s){await C(e);return}if(r){await z();return}try{(await ue({type:"select",name:"loginType",message:"How would you like to login?",choices:[{name:"user",message:"As a user (OAuth2 flow)",value:"user"},{name:"machine",message:"As a machine (Access Key & Secret)",value:"machine"}]})).loginType==="user"?await z():await C(e)}catch{l(fe,"Login cancelled"),process.exit(1)}}export{pe as default};
@@ -0,0 +1,5 @@
1
+ import m from"axios";import G from"open";function v(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var A="https://tigris";import{homedir as j}from"os";import{join as _}from"path";import{readFileSync as V,writeFileSync as H,existsSync as O,mkdirSync as J}from"fs";import{chmod as W}from"fs/promises";var h=_(j(),".tigris"),u=_(h,"config.json");function B(){O(h)||J(h,{recursive:!0,mode:448})}function c(){if(O(u))try{let t=V(u,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function g(t){B(),H(u,JSON.stringify(t,null,2),{mode:384});try{await W(u,384)}catch{}}async function y(t){let e=c();e.tokens=t,await g(e)}async function d(){return c().tokens||null}async function C(){let t=c();delete t.tokens,await g(t)}async function P(t){let e=c();e.organizations=t,await g(e)}function I(){return c().organizations||[]}async function M(t){let e=c();e.selectedOrganization=t,await g(e)}async function b(t){let e=c();e.loginMethod=t,await g(e)}var k=class{config;baseUrl;constructor(){this.config=v(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await m.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await G(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await y(i),b("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,n){let i=0;for(;i<60;){i++;try{let s=(await m.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,a=Date.now()+(s.expires_in||3600)*1e3;return{accessToken:s.access_token,refreshToken:s.refresh_token,idToken:s.id_token,expiresAt:a}}catch(r){if(m.isAxiosError(r)&&r.response){let s=r.response.data?.error;if(s==="authorization_pending"){await this.sleep(n*1e3);continue}if(s==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await d();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let n=null;if(e?.refreshToken?n=e:n=await d(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await m.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,r={accessToken:i.access_token,refreshToken:i.refresh_token||n.refreshToken,idToken:i.id_token||n.idToken,expiresAt:Date.now()+(i.expires_in||3600)*1e3};return await y(r),r}catch{throw await C(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await d();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=e.idToken.split(".")[1],o=Buffer.from(n,"base64").toString("utf8");return JSON.parse(o)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let n=e.split(".")[1],o=Buffer.from(n,"base64").toString("utf8"),r=JSON.parse(o)[A];if(!r)return;let s=r?.ns?.map(a=>typeof a=="object"&&a!==null?{id:a.id,name:a.name,displayName:a.name}:{id:a,name:a,displayName:a})||[];if(s.length===0)return;P(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),I()}async logout(){await C()}async isAuthenticated(){return await d()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},w=null;function z(){return w||(w=new k),w}import{readFileSync as Y,existsSync as K}from"fs";import{join as D,dirname as q}from"path";import{fileURLToPath as Q}from"url";import*as E from"yaml";var X=Q(import.meta.url),Z=q(X),T=null;function ee(){let t=Z;for(let e=0;e<5;e++){let n=D(t,"specs.yaml");if(K(n))return n;t=D(t,"..")}throw new Error("Could not find specs.yaml")}function ne(){if(!T){let t=ee(),e=Y(t,"utf8");T=E.parse(e)}return T}function N(t,e){let o=ne().commands.find(i=>i.name===t);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var x={success:"\u2714",failure:"\u2716",hint:"\u2192"};function p(t){let e=N(t.command,t.operation);if(e)return e.messages}function f(t,e){let n=t;return n=n.replace(/\\n/g,`
2
+ `),e&&(n=n.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=e[i];return r!==void 0?String(r):`{{${i}}}`})),n}function $(t,e){let n=p(t);n?.onStart&&console.log(f(n.onStart,e))}function S(t,e){let n=p(t);n?.onSuccess&&console.log(`${x.success} ${f(n.onSuccess,e)}`)}function F(t,e,n){let o=p(t);o?.onFailure&&console.error(`${x.failure} ${f(o.onFailure,n)}`),e&&console.error(` ${e}`)}function L(t,e){let n=p(t);n?.onAlreadyDone&&console.log(f(n.onAlreadyDone,e))}function R(t,e){let n=p(t);n?.hint&&console.log(`${x.hint} ${f(n.hint,e)}`)}function U(t,e){return{command:t,operation:e}}var l=U("login","ui");async function te(){$(l);try{let t=z();if(await t.isAuthenticated()){L(l);return}await t.login({onDeviceCode:(o,i)=>{console.log(`
3
+ Your confirmation code: ${o}
4
+ `),console.log(`If browser doesn't open, visit: ${i}`)},onWaiting:()=>console.log(`
5
+ Waiting for authentication...`)});let n=await t.getOrganizations();if(n.length>0){let o=n[0];M(o.id),S(l,{org:o.displayName||o.name}),n.length>1&&R(l,{count:n.length})}else S(l,{org:"none"})}catch{F(l),process.exit(1)}}var Se=te;export{Se as default,te as ui};
@@ -0,0 +1,2 @@
1
+ import{homedir as O}from"os";import{join as m}from"path";import{readFileSync as A,writeFileSync as P,existsSync as u,mkdirSync as w}from"fs";import{chmod as z}from"fs/promises";var a=m(O(),".tigris"),r=m(a,"config.json");function T(){u(a)||w(a,{recursive:!0,mode:448})}function b(){if(u(r))try{let e=A(r,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function k(e){T(),P(r,JSON.stringify(e,null,2),{mode:384});try{await z(r,384)}catch{}}async function d(){let n=b().credentials;await k({credentials:n})}import{readFileSync as F,existsSync as I}from"fs";import{join as C,dirname as $}from"path";import{fileURLToPath as D}from"url";import*as y from"yaml";var V=D(import.meta.url),j=$(V),c=null;function _(){let e=j;for(let n=0;n<5;n++){let t=C(e,"specs.yaml");if(I(t))return t;e=C(e,"..")}throw new Error("Could not find specs.yaml")}function E(){if(!c){let e=_(),n=F(e,"utf8");c=y.parse(n)}return c}function S(e,n){let o=E().commands.find(i=>i.name===e);return o?n&&o.operations?o.operations.find(i=>i.name===n)||null:o:null}var x={success:"\u2714",failure:"\u2716",hint:"\u2192"};function l(e){let n=S(e.command,e.operation);if(n)return n.messages}function g(e,n){let t=e;return t=t.replace(/\\n/g,`
2
+ `),n&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let p=n[i];return p!==void 0?String(p):`{{${i}}}`})),t}function M(e,n){let t=l(e);t?.onStart&&console.log(g(t.onStart,n))}function v(e,n){let t=l(e);t?.onSuccess&&console.log(`${x.success} ${g(t.onSuccess,n)}`)}function f(e,n,t){let o=l(e);o?.onFailure&&console.error(`${x.failure} ${g(o.onFailure,t)}`),n&&console.error(` ${n}`)}function h(e,n){return{command:e,operation:n}}var s=h("logout");async function L(){M(s);try{await d(),v(s)}catch(e){e instanceof Error?f(s,e.message):f(s),process.exit(1)}}export{L as default};
package/dist/lib/ls.js ADDED
@@ -0,0 +1 @@
1
+ async function e(t){t.path||t._positional?.[0]||(console.error("path argument is required"),process.exit(1)),console.error("ls command not yet implemented"),process.exit(1)}export{e as default};
package/dist/lib/mk.js ADDED
@@ -0,0 +1 @@
1
+ async function e(t){t.path||t._positional?.[0]||(console.error("path argument is required"),process.exit(1)),console.error("mk command not yet implemented"),process.exit(1)}export{e as default};
package/dist/lib/mv.js ADDED
@@ -0,0 +1 @@
1
+ async function t(e){let s=e.src||e._positional?.[0],r=e.dest||e._positional?.[1];(!s||!r)&&(console.error("both src and dest arguments are required"),process.exit(1)),console.error("mv command not yet implemented"),process.exit(1)}export{t as default};
@@ -0,0 +1,2 @@
1
+ import{createOrganization as se}from"@tigrisdata/storage";function _(t,e,n){for(let o of e)if(t[o]!==void 0)return t[o];return n}import{S3Client as ke}from"@aws-sdk/client-s3";import{homedir as V}from"os";import{join as I}from"path";import{readFileSync as G,writeFileSync as J,existsSync as O,mkdirSync as q}from"fs";import{chmod as B}from"fs/promises";var y=I(V(),".tigris"),l=I(y,"config.json");function W(){O(y)||q(y,{recursive:!0,mode:448})}function c(){if(O(l))try{let t=G(l,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function p(t){W(),J(l,JSON.stringify(t,null,2),{mode:384});try{await B(l,384)}catch{}}async function w(t){let e=c();e.tokens=t,await p(e)}async function d(){return c().tokens||null}async function C(){let t=c();delete t.tokens,await p(t)}async function P(t){let e=c();e.organizations=t,await p(e)}function M(){return c().organizations||[]}function T(){return c().selectedOrganization||null}function N(){let t=c();return t.temporaryCredentials||t.credentials||null}async function E(t){let e=c();e.loginMethod=t,await p(e)}function z(){return c().loginMethod||null}import u from"axios";import Y from"open";function b(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var D="https://tigris";var S=class{config;baseUrl;constructor(){this.config=b(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await u.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await Y(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await w(i),E("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,n){let i=0;for(;i<60;){i++;try{let s=(await u.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,a=Date.now()+(s.expires_in||3600)*1e3;return{accessToken:s.access_token,refreshToken:s.refresh_token,idToken:s.id_token,expiresAt:a}}catch(r){if(u.isAxiosError(r)&&r.response){let s=r.response.data?.error;if(s==="authorization_pending"){await this.sleep(n*1e3);continue}if(s==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await d();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let n=null;if(e?.refreshToken?n=e:n=await d(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await u.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,r={accessToken:i.access_token,refreshToken:i.refresh_token||n.refreshToken,idToken:i.id_token||n.idToken,expiresAt:Date.now()+(i.expires_in||3600)*1e3};return await w(r),r}catch{throw await C(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await d();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=e.idToken.split(".")[1],o=Buffer.from(n,"base64").toString("utf8");return JSON.parse(o)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let n=e.split(".")[1],o=Buffer.from(n,"base64").toString("utf8"),r=JSON.parse(o)[D];if(!r)return;let s=r?.ns?.map(a=>typeof a=="object"&&a!==null?{id:a.id,name:a.name,displayName:a.name}:{id:a,name:a,displayName:a})||[];if(s.length===0)return;P(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),M()}async logout(){await C()}async isAuthenticated(){return await d()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},k=null;function f(){return k||(k=new S),k}async function Q(){return z()}async function R(){let t=await Q();if(!t)throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.');if(t==="oauth"){let o=await f().getAccessToken();if(!T())throw new Error('No organization selected. Please run "tigris orgs select" first.');let r=process.env.TIGRIS_ENDPOINT??"https://t3.storage.dev",s=process.env.TIGRIS_STORAGE_IAM_ENDPOINT??"https://iam.storageapi.dev",a=process.env.AUTH0_DOMAIN??"https://auth.tigris.dev";return{sessionToken:o,accessKeyId:"",secretAccessKey:"",endpoint:r,organizationId:T()??void 0,iamEndpoint:s,authDomain:a}}let e=N();if(!e)throw new Error('No credentials found. Please run "tigris configure" first.');return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint}}import{readFileSync as X,existsSync as Z}from"fs";import{join as K,dirname as ee}from"path";import{fileURLToPath as te}from"url";import*as L from"yaml";var ne=te(import.meta.url),oe=ee(ne),x=null;function ie(){let t=oe;for(let e=0;e<5;e++){let n=K(t,"specs.yaml");if(Z(n))return n;t=K(t,"..")}throw new Error("Could not find specs.yaml")}function re(){if(!x){let t=ie(),e=X(t,"utf8");x=L.parse(e)}return x}function F(t,e){let o=re().commands.find(i=>i.name===t);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var A={success:"\u2714",failure:"\u2716",hint:"\u2192"};function m(t){let e=F(t.command,t.operation);if(e)return e.messages}function h(t,e){let n=t;return n=n.replace(/\\n/g,`
2
+ `),e&&(n=n.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=e[i];return r!==void 0?String(r):`{{${i}}}`})),n}function $(t,e){let n=m(t);n?.onStart&&console.log(h(n.onStart,e))}function U(t,e){let n=m(t);n?.onSuccess&&console.log(`${A.success} ${h(n.onSuccess,e)}`)}function v(t,e,n){let o=m(t);o?.onFailure&&console.error(`${A.failure} ${h(o.onFailure,n)}`),e&&console.error(` ${e}`)}function H(t,e){let n=m(t);n?.hint&&console.log(`${A.hint} ${h(n.hint,e)}`)}function j(t,e){return{command:t,operation:e}}var g=j("orgs","create");async function ae(t){$(g);let e=_(t,["name","N"]);e||(v(g,"Organization name is required"),process.exit(1));let n=await R(),{data:o,error:i}=await se(e,{config:n});i&&(v(g,i.message),process.exit(1));let r=f(),s=await r.refreshAccessToken();s.idToken&&await r.extractAndStoreOrganizations(s.idToken);let a=o.id;U(g,{name:e,id:a}),H(g,{name:e})}export{ae as default};
@@ -0,0 +1,7 @@
1
+ function M(n,e,t){for(let o of e)if(n[o]!==void 0)return n[o];return t}function X(n){return JSON.stringify(n,null,2)}function Q(n,e=" "){return Object.entries(n).map(([t,o])=>`${e}<${t}>${o}</${t}>`).join(`
2
+ `)}function Z(n,e,t){let o=[`<${e}>`];return n.forEach(i=>{o.push(` <${t}>`),o.push(Q(i," ")),o.push(` </${t}>`)}),o.push(`</${e}>`),o.join(`
3
+ `)}function z(n){if(n==null)return"";if(n instanceof Date)return P(n);if(typeof n=="string"){let e=new Date(n);if(!isNaN(e.getTime())&&n.includes("T"))return P(e)}return String(n)}function P(n){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(n)}function ee(n,e){return e.map(t=>{if(t.width)return t.width;let o=t.header.length,i=n.reduce((r,c)=>{let s=z(c[t.key]);return Math.max(r,s.length)},0);return Math.max(o,i)})}function ne(n,e){let t=[],o=ee(n,e),i="\u250C"+o.map(a=>"\u2500".repeat(a+2)).join("\u252C")+"\u2510",r="\u251C"+o.map(a=>"\u2500".repeat(a+2)).join("\u253C")+"\u2524",c="\u2514"+o.map(a=>"\u2500".repeat(a+2)).join("\u2534")+"\u2518";t.push(`
4
+ `+i);let s="\u2502 "+e.map((a,y)=>a.header.padEnd(o[y])).join(" \u2502 ")+" \u2502";return t.push(s),t.push(r),n.forEach(a=>{let y=e.map((u,p)=>{let g=z(a[u.key]);return u.align==="right"?g.padStart(o[p]):g.padEnd(o[p])});t.push("\u2502 "+y.join(" \u2502 ")+" \u2502")}),t.push(c+`
5
+ `),t.join(`
6
+ `)}function N(n,e,t,o,i){switch(e){case"json":return X(n);case"xml":return Z(n,t,o);default:return ne(n,i)}}import C from"axios";import ce from"open";function D(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var E="https://tigris";import{homedir as te}from"os";import{join as $}from"path";import{readFileSync as oe,writeFileSync as ie,existsSync as j,mkdirSync as re}from"fs";import{chmod as se}from"fs/promises";var S=$(te(),".tigris"),w=$(S,"config.json");function ae(){j(S)||re(S,{recursive:!0,mode:448})}function d(){if(j(w))try{let n=oe(w,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function m(n){ae(),ie(w,JSON.stringify(n,null,2),{mode:384});try{await se(w,384)}catch{}}async function A(n){let e=d();e.tokens=n,await m(e)}async function h(){return d().tokens||null}async function _(){let n=d();delete n.tokens,await m(n)}async function R(n){let e=d();e.organizations=n,await m(e)}function F(){return d().organizations||[]}async function L(n){let e=d();e.selectedOrganization=n,await m(e)}function U(){return d().selectedOrganization||null}async function V(n){let e=d();e.loginMethod=n,await m(e)}var O=class{config;baseUrl;constructor(){this.config=D(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await C.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await ce(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await A(i),V("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,t){let i=0;for(;i<60;){i++;try{let c=(await C.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,s=Date.now()+(c.expires_in||3600)*1e3;return{accessToken:c.access_token,refreshToken:c.refresh_token,idToken:c.id_token,expiresAt:s}}catch(r){if(C.isAxiosError(r)&&r.response){let c=r.response.data?.error;if(c==="authorization_pending"){await this.sleep(t*1e3);continue}if(c==="slow_down"){t+=5,await this.sleep(t*1e3);continue}throw new Error(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await h();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let t=300*1e3;return Date.now()+t>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let t=null;if(e?.refreshToken?t=e:t=await h(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await C.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:t.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,r={accessToken:i.access_token,refreshToken:i.refresh_token||t.refreshToken,idToken:i.id_token||t.idToken,expiresAt:Date.now()+(i.expires_in||3600)*1e3};return await A(r),r}catch{throw await _(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await h();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let t=e.idToken.split(".")[1],o=Buffer.from(t,"base64").toString("utf8");return JSON.parse(o)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let t=e.split(".")[1],o=Buffer.from(t,"base64").toString("utf8"),r=JSON.parse(o)[E];if(!r)return;let c=r?.ns?.map(s=>typeof s=="object"&&s!==null?{id:s.id,name:s.name,displayName:s.name}:{id:s,name:s,displayName:s})||[];if(c.length===0)return;R(c)}catch{}}async getOrganizations(){return await this.getAccessToken(),F()}async logout(){await _()}async isAuthenticated(){return await h()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},v=null;function J(){return v||(v=new O),v}import ye from"enquirer";import{readFileSync as de,existsSync as le}from"fs";import{join as B,dirname as ue}from"path";import{fileURLToPath as pe}from"url";import*as H from"yaml";var ge=pe(import.meta.url),fe=ue(ge),I=null;function me(){let n=fe;for(let e=0;e<5;e++){let t=B(n,"specs.yaml");if(le(t))return t;n=B(n,"..")}throw new Error("Could not find specs.yaml")}function he(){if(!I){let n=me(),e=de(n,"utf8");I=H.parse(e)}return I}function W(n,e){let o=he().commands.find(i=>i.name===n);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var G={success:"\u2714",failure:"\u2716",hint:"\u2192"};function T(n){let e=W(n.command,n.operation);if(e)return e.messages}function k(n,e){let t=n;return t=t.replace(/\\n/g,`
7
+ `),e&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=e[i];return r!==void 0?String(r):`{{${i}}}`})),t}function Y(n,e){let t=T(n);t?.onStart&&console.log(k(t.onStart,e))}function b(n,e){let t=T(n);t?.onSuccess&&console.log(`${G.success} ${k(t.onSuccess,e)}`)}function x(n,e,t){let o=T(n);o?.onFailure&&console.error(`${G.failure} ${k(o.onFailure,t)}`),e&&console.error(` ${e}`)}function q(n,e){let t=T(n);t?.onEmpty&&console.log(k(t.onEmpty,e))}function K(n,e){return{command:n,operation:e}}var l=K("orgs","list");async function we(n){Y(l);let e=M(n,["format","f","F"],"select");try{let t=J();await t.getAccessToken();let o=await t.getOrganizations();if(o.length===0){q(l);return}let i=U();if(e==="select"){let s=o.map(a=>({name:a.id,message:`${a.displayName||a.name} (${a.id})`,hint:a.id===i?"currently selected":void 0}));try{let u=(await ye.prompt({type:"select",name:"organization",message:"Select an organization:",choices:s.map(f=>f.message),initial:i?o.findIndex(f=>f.id===i):0})).organization.match(/\(([^)]+)\)$/),p=u?u[1]:o[0].id;L(p);let g=o.find(f=>f.id===p);b(l,{name:g?.displayName||g?.name});return}catch{x(l,"Selection cancelled"),process.exit(0)}}let r=o.map(s=>({id:s.id,name:s.name,displayName:s.displayName||s.name,selected:s.id===i?"*":""})),c=N(r,e,"organizations","organization",[{key:"selected",header:" ",width:1},{key:"id",header:"ID"},{key:"name",header:"Name"},{key:"displayName",header:"Display Name"}]);console.log(c),b(l,{count:r.length})}catch(t){t instanceof Error?x(l,t.message):x(l),process.exit(1)}}export{we as default};
@@ -0,0 +1,6 @@
1
+ function S(t,e,n){for(let o of e)if(t[o]!==void 0)return t[o];return n}import u from"axios";import G from"open";function v(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var A="https://tigris";import{homedir as U}from"os";import{join as _}from"path";import{readFileSync as j,writeFileSync as V,existsSync as O,mkdirSync as J}from"fs";import{chmod as H}from"fs/promises";var m=_(U(),".tigris"),f=_(m,"config.json");function B(){O(m)||J(m,{recursive:!0,mode:448})}function c(){if(O(f))try{let t=j(f,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function d(t){B(),V(f,JSON.stringify(t,null,2),{mode:384});try{await H(f,384)}catch{}}async function h(t){let e=c();e.tokens=t,await d(e)}async function g(){return c().tokens||null}async function y(){let t=c();delete t.tokens,await d(t)}async function I(t){let e=c();e.organizations=t,await d(e)}function P(){return c().organizations||[]}async function M(t){let e=c();e.selectedOrganization=t,await d(e)}async function b(t){let e=c();e.loginMethod=t,await d(e)}var w=class{config;baseUrl;constructor(){this.config=v(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await u.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await G(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await h(i),b("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,n){let i=0;for(;i<60;){i++;try{let s=(await u.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,a=Date.now()+(s.expires_in||3600)*1e3;return{accessToken:s.access_token,refreshToken:s.refresh_token,idToken:s.id_token,expiresAt:a}}catch(r){if(u.isAxiosError(r)&&r.response){let s=r.response.data?.error;if(s==="authorization_pending"){await this.sleep(n*1e3);continue}if(s==="slow_down"){n+=5,await this.sleep(n*1e3);continue}throw new Error(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await g();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let n=300*1e3;return Date.now()+n>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let n=null;if(e?.refreshToken?n=e:n=await g(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await u.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:n.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,r={accessToken:i.access_token,refreshToken:i.refresh_token||n.refreshToken,idToken:i.id_token||n.idToken,expiresAt:Date.now()+(i.expires_in||3600)*1e3};return await h(r),r}catch{throw await y(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await g();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=e.idToken.split(".")[1],o=Buffer.from(n,"base64").toString("utf8");return JSON.parse(o)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let n=e.split(".")[1],o=Buffer.from(n,"base64").toString("utf8"),r=JSON.parse(o)[A];if(!r)return;let s=r?.ns?.map(a=>typeof a=="object"&&a!==null?{id:a.id,name:a.name,displayName:a.name}:{id:a,name:a,displayName:a})||[];if(s.length===0)return;I(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),P()}async logout(){await y()}async isAuthenticated(){return await g()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},C=null;function z(){return C||(C=new w),C}import{readFileSync as W,existsSync as Y}from"fs";import{join as E,dirname as q}from"path";import{fileURLToPath as K}from"url";import*as N from"yaml";var Q=K(import.meta.url),X=q(Q),k=null;function Z(){let t=X;for(let e=0;e<5;e++){let n=E(t,"specs.yaml");if(Y(n))return n;t=E(t,"..")}throw new Error("Could not find specs.yaml")}function ee(){if(!k){let t=Z(),e=W(t,"utf8");k=N.parse(e)}return k}function D(t,e){let o=ee().commands.find(i=>i.name===t);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var $={success:"\u2714",failure:"\u2716",hint:"\u2192"};function T(t){let e=D(t.command,t.operation);if(e)return e.messages}function x(t,e){let n=t;return n=n.replace(/\\n/g,`
2
+ `),e&&(n=n.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=e[i];return r!==void 0?String(r):`{{${i}}}`})),n}function F(t,e){let n=T(t);n?.onStart&&console.log(x(n.onStart,e))}function R(t,e){let n=T(t);n?.onSuccess&&console.log(`${$.success} ${x(n.onSuccess,e)}`)}function p(t,e,n){let o=T(t);o?.onFailure&&console.error(`${$.failure} ${x(o.onFailure,n)}`),e&&console.error(` ${e}`)}function L(t,e){return{command:t,operation:e}}var l=L("orgs","select");async function ne(t){F(l);let e=S(t,["name","N"]);e||(p(l,"Organization name or ID is required"),process.exit(1));try{let n=z();await n.getAccessToken();let o=await n.getOrganizations(),i=o.find(r=>r.id===e||r.name===e);if(!i){let r=o.map(s=>` - ${s.name} (${s.id})`).join(`
3
+ `);p(l,`Organization "${e}" not found
4
+
5
+ Available organizations:
6
+ ${r}`),process.exit(1)}M(i.id),R(l,{name:i.name})}catch(n){n instanceof Error?p(l,n.message):p(l),process.exit(1)}}export{ne as default};
package/dist/lib/rm.js ADDED
@@ -0,0 +1 @@
1
+ async function e(t){t.path||t._positional?.[0]||(console.error("path argument is required"),process.exit(1)),console.error("rm command not yet implemented"),process.exit(1)}export{e as default};
@@ -0,0 +1 @@
1
+ async function e(t){t.path||t._positional?.[0]||(console.error("path argument is required"),process.exit(1)),console.error("stat command not yet implemented"),process.exit(1)}export{e as default};
@@ -0,0 +1,3 @@
1
+ import g from"axios";import H from"open";function T(){return{domain:process.env.AUTH0_DOMAIN||"auth-dev.tigris.dev",clientId:process.env.AUTH0_CLIENT_ID||"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF",audience:process.env.AUTH0_AUDIENCE||"https://tigris-api-dev"}}var x="https://tigris";import{homedir as U}from"os";import{join as S}from"path";import{readFileSync as L,writeFileSync as R,existsSync as v,mkdirSync as j}from"fs";import{chmod as V}from"fs/promises";var f=S(U(),".tigris"),d=S(f,"config.json");function J(){v(f)||j(f,{recursive:!0,mode:448})}function c(){if(v(d))try{let n=L(d,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function p(n){J(),R(d,JSON.stringify(n,null,2),{mode:384});try{await V(d,384)}catch{}}async function u(n){let e=c();e.tokens=n,await p(e)}async function l(){return c().tokens||null}async function m(){let n=c();delete n.tokens,await p(n)}async function A(n){let e=c();e.organizations=n,await p(e)}function _(){return c().organizations||[]}function O(){return c().selectedOrganization||null}async function I(n){let e=c();e.loginMethod=n,await p(e)}var y=class{config;baseUrl;constructor(){this.config=T(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await g.post(`${this.baseUrl}/oauth/device/code`,{client_id:this.config.clientId,audience:this.config.audience,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;e?.onDeviceCode?.(i.user_code,i.verification_uri),await this.sleep(2e3);try{await H(i.verification_uri_complete)}catch{}e?.onWaiting?.();let s=await this.pollForToken(i.device_code,i.interval||5);await u(s),I("oauth"),await this.extractAndStoreOrganizations(s.idToken)}async pollForToken(e,t){let s=0;for(;s<60;){s++;try{let r=(await g.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,a=Date.now()+(r.expires_in||3600)*1e3;return{accessToken:r.access_token,refreshToken:r.refresh_token,idToken:r.id_token,expiresAt:a}}catch(o){if(g.isAxiosError(o)&&o.response){let r=o.response.data?.error;if(r==="authorization_pending"){await this.sleep(t*1e3);continue}if(r==="slow_down"){t+=5,await this.sleep(t*1e3);continue}throw new Error(o.response.data?.error_description||"Authentication failed")}throw o}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await l();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let t=300*1e3;return Date.now()+t>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let t=null;if(e?.refreshToken?t=e:t=await l(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let s=(await g.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,grant_type:"refresh_token",refresh_token:t.refreshToken,scope:"openid profile email offline_access"},{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data,o={accessToken:s.access_token,refreshToken:s.refresh_token||t.refreshToken,idToken:s.id_token||t.idToken,expiresAt:Date.now()+(s.expires_in||3600)*1e3};return await u(o),o}catch{throw await m(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await l();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let t=e.idToken.split(".")[1],i=Buffer.from(t,"base64").toString("utf8");return JSON.parse(i)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let t=e.split(".")[1],i=Buffer.from(t,"base64").toString("utf8"),o=JSON.parse(i)[x];if(!o)return;let r=o?.ns?.map(a=>typeof a=="object"&&a!==null?{id:a.id,name:a.name,displayName:a.name}:{id:a,name:a,displayName:a})||[];if(r.length===0)return;A(r)}catch{}}async getOrganizations(){return await this.getAccessToken(),_()}async logout(){await m()}async isAuthenticated(){return await l()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},h=null;function P(){return h||(h=new y),h}import{readFileSync as B,existsSync as G}from"fs";import{join as M,dirname as W}from"path";import{fileURLToPath as Y}from"url";import*as z from"yaml";var K=Y(import.meta.url),q=W(K),C=null;function Q(){let n=q;for(let e=0;e<5;e++){let t=M(n,"specs.yaml");if(G(t))return t;n=M(n,"..")}throw new Error("Could not find specs.yaml")}function X(){if(!C){let n=Q(),e=B(n,"utf8");C=z.parse(e)}return C}function b(n,e){let i=X().commands.find(s=>s.name===n);return i?e&&i.operations?i.operations.find(s=>s.name===e)||null:i:null}var Z={success:"\u2714",failure:"\u2716",hint:"\u2192"};function E(n){let e=b(n.command,n.operation);if(e)return e.messages}function N(n,e){let t=n;return t=t.replace(/\\n/g,`
2
+ `),e&&(t=t.replace(/\{\{(\w+)\}\}/g,(i,s)=>{let o=e[s];return o!==void 0?String(o):`{{${s}}}`})),t}function w(n,e,t){let i=E(n);i?.onFailure&&console.error(`${Z.failure} ${N(i.onFailure,t)}`),e&&console.error(` ${e}`)}function $(n,e){let t=E(n);t?.onAlreadyDone&&console.log(N(t.onAlreadyDone,e))}function D(n,e){return{command:n,operation:e}}var k=D("whoami");async function ee(){try{let n=P();if(!await n.isAuthenticated()){$(k);return}let t=await n.getIdTokenClaims(),i=await n.getOrganizations(),s=O(),o=[];if(o.push(""),o.push("User Information:"),o.push(` Email: ${t.email||"N/A"}`),o.push(` User ID: ${t.sub}`),i.length>0){if(o.push(""),o.push(`Organizations (${i.length}):`),i.forEach(r=>{let F=r.id===s?">":" ";o.push(` ${F} ${r.name} (${r.id})`)}),s){let r=i.find(a=>a.id===s);r&&(o.push(""),o.push(`Active: ${r.name}`))}}else o.push(""),o.push("Organizations: None");o.push(""),console.log(o.join(`
3
+ `))}catch(n){n instanceof Error?w(k,n.message):w(k),process.exit(1)}}export{ee as default};
@@ -0,0 +1,627 @@
1
+ name: tigris
2
+ alias: t3
3
+ description: Command line interface for Tigris
4
+ version: 0.0.1
5
+
6
+ # Reusable option definitions
7
+ definitions:
8
+ tier_options: &tier_options
9
+ - name: Standard
10
+ value: STANDARD
11
+ description: The default storage class. It provides high durability, availability, and performance for frequently accessed data.
12
+ - name: Infrequent Access
13
+ value: STANDARD_IA
14
+ description: Lower-cost storage for data that is accessed less frequently but requires rapid access when needed.
15
+ - name: Archive
16
+ value: GLACIER
17
+ description: Low-cost storage for data archiving. Long-term data archiving with infrequent access.
18
+ - name: Instant Retrieval Archive
19
+ value: GLACIER_IR
20
+ description: Lowest-cost storage for long-lived data that is rarely accessed and requires retrieval in milliseconds.
21
+
22
+ consistency_options: &consistency_options
23
+ - name: Default
24
+ value: default
25
+ description: Strict read-after-write consistency in same region. Eventual consistency globally.
26
+ - name: Strict
27
+ value: strict
28
+ description: Strict read-after-write consistency globally. Latency will be higher than the default.
29
+
30
+ region_options: &region_options
31
+ - name: Global
32
+ value: 'global'
33
+ description: Global
34
+ - name: USA
35
+ value: usa
36
+ description: Restrict to USA
37
+ - name: Europe
38
+ value: eur
39
+ description: Restrict to Europe
40
+ - name: Amsterdam, Netherlands
41
+ value: ams
42
+ description: Amsterdam, Netherlands
43
+ - name: Frankfurt, Germany
44
+ value: fra
45
+ description: Frankfurt, Germany
46
+ - name: Sao Paulo, Brazil
47
+ value: gru
48
+ description: Sao Paulo, Brazil
49
+ - name: Ashburn, Virginia (US)
50
+ value: iad
51
+ description: Ashburn, Virginia (US)
52
+ - name: Johannesburg, South Africa
53
+ value: jnb
54
+ description: Johannesburg, South Africa
55
+ - name: London, United Kingdom
56
+ value: lhr
57
+ description: London, United Kingdom
58
+ - name: Tokyo, Japan
59
+ value: nrt
60
+ description: Tokyo, Japan
61
+ - name: Chicago, Illinois (US)
62
+ value: ord
63
+ description: Chicago, Illinois (US)
64
+ - name: Singapore, Singapore
65
+ value: sin
66
+ description: Singapore, Singapore
67
+ - name: San Jose, California (US)
68
+ value: sjc
69
+ description: San Jose, California (US)
70
+ - name: Sydney, Australia
71
+ value: syd
72
+ description: Sydney, Australia
73
+
74
+ access_options: &access_options
75
+ [public, private]
76
+
77
+ commands:
78
+ #########################
79
+ # Unix style commands
80
+ #########################
81
+
82
+ # ls
83
+ - name: ls
84
+ description: List buckets or objects in a bucket or path
85
+ alias: list
86
+ arguments:
87
+ - name: path
88
+ required: true
89
+ type: noun
90
+ description: a bucket or path in a bucket
91
+ examples:
92
+ - my-bucket
93
+ - my-bucket/my-path
94
+
95
+ # mk
96
+ - name: mk
97
+ description: Create a bucket or a folder in a bucket
98
+ alias: create
99
+ arguments:
100
+ - name: path
101
+ required: true
102
+ type: noun
103
+ description: a bucket or a folder in a bucket
104
+ examples:
105
+ - my-bucket
106
+ - my-bucket/my-path
107
+
108
+ # stat
109
+ - name: stat
110
+ description: Get the details of a bucket or a folder in a bucket or an object in a bucket or path
111
+ arguments:
112
+ - name: path
113
+ required: true
114
+ type: noun
115
+ description: a bucket or a folder in a bucket or an object in a bucket or path
116
+ examples:
117
+ - my-bucket
118
+ - my-bucket/my-path
119
+ - my-bucket/my-path/my-object.json
120
+
121
+ # cp
122
+ - name: cp
123
+ description: Copy a folder or an object
124
+ alias: copy
125
+ arguments:
126
+ - name: src
127
+ required: true
128
+ type: noun
129
+ description: a bucket, a folder in a bucket, an object in a bucket / path. Wildcard is supported.
130
+ examples:
131
+ - my-bucket
132
+ - my-bucket/my-path
133
+ - my-bucket/my-path/my-object.json
134
+ - name: dest
135
+ required: true
136
+ type: noun
137
+ description: path to copy to
138
+ examples:
139
+ - my-bucket
140
+ - my-bucket/my-path
141
+ - my-bucket/my-path/*
142
+ - my-bucket/my-path/my-object.json
143
+
144
+ # mv
145
+ - name: mv
146
+ description: Move a folder or an object
147
+ alias: move
148
+ arguments:
149
+ - name: src
150
+ type: noun
151
+ required: true
152
+ description: path to move from
153
+ examples:
154
+ - my-bucket
155
+ - my-bucket/my-path
156
+ - my-bucket/my-path/*
157
+ - my-bucket/my-path/my-object.json
158
+ - name: dest
159
+ type: noun
160
+ required: true
161
+ description: path to move to
162
+ examples:
163
+ - my-bucket
164
+ - my-bucket/new-path
165
+
166
+ # rm
167
+ - name: rm
168
+ description: Remove a bucket or a folder in a bucket or an object in a bucket or path
169
+ alias: remvoe
170
+ arguments:
171
+ - name: path
172
+ type: noun
173
+ required: true
174
+ description: a bucket, a folder in a bucket, an object in a bucket / path. Wildcard is supported.
175
+ examples:
176
+ - my-bucket
177
+ - my-bucket/my-path
178
+ - my-bucket/my-path/*
179
+ - my-bucket/my-path/my-object.json
180
+
181
+ #########################
182
+ # Authentication
183
+ #########################
184
+ # logout
185
+ - name: logout
186
+ description: Logout from Tigris
187
+ messages:
188
+ onStart: "Logging out..."
189
+ onSuccess: "Logged out successfully"
190
+ onFailure: "Failed to logout"
191
+
192
+ # whoami
193
+ - name: whoami
194
+ description: Show information about the current user
195
+ alias: w
196
+ messages:
197
+ onStart: ""
198
+ onSuccess: ""
199
+ onFailure: "Failed to get user information"
200
+ onAlreadyDone: "Not authenticated\nRun \"tigris login\" to authenticate"
201
+
202
+ # configure
203
+ - name: configure
204
+ description: Configure Tigris credentials interactively
205
+ alias: c
206
+ messages:
207
+ onStart: "Configuring credentials..."
208
+ onSuccess: "Configuration saved"
209
+ onFailure: "Failed to configure credentials"
210
+ arguments:
211
+ - name: access-key
212
+ description: Tigris Access key ID
213
+ alias: key
214
+ required: false
215
+ - name: access-secret
216
+ description: Tigris Access secret
217
+ alias: secret
218
+ required: false
219
+ - name: endpoint
220
+ description: Tigris Endpoint
221
+ alias: e
222
+ required: false
223
+
224
+ # login
225
+ - name: login
226
+ description: Login to Tigris (interactive selection between user and machine)
227
+ messages:
228
+ onStart: "Logging in..."
229
+ onSuccess: "Login successful"
230
+ onFailure: "Login failed"
231
+ alias: l
232
+ arguments:
233
+ - name: access-key
234
+ description: Access key (optional, will use credentials flow if provided)
235
+ alias: key
236
+ required: false
237
+ - name: access-secret
238
+ description: Access secret (optional, will use credentials flow if provided)
239
+ alias: secret
240
+ required: false
241
+ - name: profile
242
+ description: Use saved credentials profile (loads from ~/.tigris/credentials.json)
243
+ alias: p
244
+ required: false
245
+ type: flag
246
+ - name: oauth
247
+ description: Login as a user (OAuth2 flow)
248
+ alias: o
249
+ required: false
250
+ type: flag
251
+ operations:
252
+ # login (main interactive operation)
253
+ - name: select
254
+ description: Interactive selection between user and machine login
255
+ messages:
256
+ onStart: ""
257
+ onSuccess: "Login successful"
258
+ onFailure: "Login failed"
259
+ arguments:
260
+ - name: access-key
261
+ description: Access key (optional, will use credentials flow if provided)
262
+ alias: key
263
+ required: false
264
+ - name: access-secret
265
+ description: Access secret (optional, will use credentials flow if provided)
266
+ alias: secret
267
+ required: false
268
+ - name: profile
269
+ description: Use saved credentials profile (loads from ~/.tigris/credentials.json)
270
+ alias: p
271
+ required: false
272
+ type: flag
273
+ - name: oauth
274
+ description: Login as a user (OAuth2 flow)
275
+ alias: o
276
+ required: false
277
+ type: flag
278
+ # ui
279
+ - name: ui
280
+ description: Login as a user (OAuth2 flow)
281
+ alias: u
282
+ messages:
283
+ onStart: "Initiating authentication..."
284
+ onSuccess: "Authentication successful\nOrganization '{{org}}' selected"
285
+ onFailure: "Authentication failed"
286
+ onAlreadyDone: "You are already logged in.\nRun \"tigris logout\" first if you want to login with a different account."
287
+ hint: "You have {{count}} organizations available.\nRun \"tigris orgs list\" to see all and switch if needed."
288
+ # credentials
289
+ - name: credentials
290
+ description: Login as a machine (with access key and secret)
291
+ alias: c
292
+ messages:
293
+ onStart: "Authenticating with credentials..."
294
+ onSuccess: "Login successful"
295
+ onFailure: "Login failed"
296
+ arguments:
297
+ - name: access-key
298
+ description: Access key (optional, will prompt or use saved credentials if not provided)
299
+ alias: key
300
+ required: false
301
+ - name: access-secret
302
+ description: Access secret (optional, will prompt or use saved credentials if not provided)
303
+ alias: secret
304
+ required: false
305
+ default: select
306
+
307
+ #########################
308
+ # Manage organizations
309
+ #########################
310
+ - name: orgs
311
+ description: Manage organizations
312
+ operations:
313
+ # list
314
+ - name: list
315
+ description: List organizations
316
+ alias: l
317
+ messages:
318
+ onStart: "Listing organizations..."
319
+ onSuccess: "Organization '{{name}}' selected"
320
+ onFailure: "Failed to select organization"
321
+ onEmpty: "No organizations found. You may need to re-authenticate.\nRun: tigris login"
322
+ arguments:
323
+ - name: format
324
+ description: Format
325
+ alias: f
326
+ options: [json, table, xml, select]
327
+ default: select
328
+ - name: select
329
+ description: Interactive selection mode
330
+ alias: i
331
+ type: flag
332
+ - name: create
333
+ description: Create organization
334
+ alias: c
335
+ messages:
336
+ onStart: "Creating organization..."
337
+ onSuccess: "Organization '{{name}}' created successfully\nOrganization ID: {{id}}"
338
+ onFailure: "Failed to create organization"
339
+ hint: "Next steps:\n - Select this organization: tigris orgs select {{name}}"
340
+ arguments:
341
+ - name: name
342
+ type: noun
343
+ required: true
344
+ description: Name of the organization
345
+ - name: select
346
+ description: Select the organization to use
347
+ alias: s
348
+ messages:
349
+ onStart: ""
350
+ onSuccess: "Organization '{{name}}' selected"
351
+ onFailure: "Failed to select organization"
352
+ arguments:
353
+ - name: name
354
+ type: noun
355
+ required: true
356
+ description: Name of the organization
357
+
358
+ #########################
359
+ # Manage buckets
360
+ #########################
361
+ - name: buckets
362
+ description: Manage buckets
363
+ alias: b
364
+ operations:
365
+ # list
366
+ - name: list
367
+ description: List buckets
368
+ alias: l
369
+ messages:
370
+ onStart: "Listing buckets..."
371
+ onSuccess: "Found {{count}} bucket(s)"
372
+ onFailure: "Failed to list buckets"
373
+ onEmpty: "No buckets found"
374
+ arguments:
375
+ - name: format
376
+ description: Format
377
+ alias: f
378
+ options: [json, table, xml]
379
+ default: table
380
+ # create
381
+ - name: create
382
+ description: Create bucket
383
+ alias: [c]
384
+ messages:
385
+ onStart: "Creating bucket..."
386
+ onSuccess: "Bucket '{{name}}' created successfully"
387
+ onFailure: "Failed to create bucket"
388
+ arguments:
389
+ - name: name
390
+ description: Name of the bucket
391
+ type: noun
392
+ required: false
393
+ - name: access
394
+ description: Access level
395
+ alias: a
396
+ options: *access_options
397
+ default: private
398
+ - name: enable-snapshots
399
+ description: Enable snapshots for the bucket
400
+ alias: s
401
+ type: flag
402
+ default: false
403
+ - name: default-tier
404
+ description: Choose the default tier for the bucket
405
+ alias: t
406
+ options: *tier_options
407
+ default: STANDARD
408
+ - name: consistency
409
+ description: Choose the consistency level for the bucket
410
+ alias: c
411
+ options: *consistency_options
412
+ default: default
413
+ - name: region
414
+ description: Region
415
+ alias: r
416
+ options: *region_options
417
+ default: 'global'
418
+ # get
419
+ - name: get
420
+ description: Get bucket details
421
+ alias: g
422
+ messages:
423
+ onStart: "Getting bucket details..."
424
+ onSuccess: ""
425
+ onFailure: "Failed to get bucket details"
426
+ arguments:
427
+ - name: name
428
+ description: Name of the bucket
429
+ type: noun
430
+ required: true
431
+ # delete
432
+ - name: delete
433
+ description: Delete bucket
434
+ alias: d
435
+ messages:
436
+ onStart: "Deleting bucket..."
437
+ onSuccess: "Bucket '{{name}}' deleted successfully"
438
+ onFailure: "Failed to delete bucket '{{name}}'"
439
+ arguments:
440
+ - name: name
441
+ description: Name of the bucket or comma separated list of buckets
442
+ type: noun
443
+ required: true
444
+ multiple: true
445
+
446
+ #########################
447
+ # Manage forks
448
+ #########################
449
+ - name: forks
450
+ description: Manage forks
451
+ alias: f
452
+ operations:
453
+ # list
454
+ - name: list
455
+ description: List forks
456
+ alias: l
457
+ arguments:
458
+ - name: name
459
+ description: Name of the bucket
460
+ type: noun
461
+ required: true
462
+ # create
463
+ - name: create
464
+ description: Create fork
465
+ alias: c
466
+ arguments:
467
+ - name: name
468
+ description: Name of the bucket
469
+ type: noun
470
+ required: true
471
+ - name: fork-name
472
+ description: Name of the fork
473
+ type: noun
474
+ required: true
475
+
476
+ #########################
477
+ # Manage snapshots
478
+ #########################
479
+ - name: snapshots
480
+ description: Manage snapshots
481
+ alias: s
482
+ operations:
483
+ # list
484
+ - name: list
485
+ description: List snapshots
486
+ alias: l
487
+ arguments:
488
+ - name: name
489
+ description: Name of the bucket
490
+ type: noun
491
+ required: true
492
+ # create
493
+ - name: create
494
+ description: Create snapshot
495
+ alias: c
496
+ arguments:
497
+ - name: name
498
+ description: Name of the bucket
499
+ type: noun
500
+ required: true
501
+ - name: snapshot-name
502
+ description: Name of the snapshot
503
+ type: noun
504
+ required: true
505
+
506
+ #########################
507
+ # Manage objects
508
+ #########################
509
+ - name: objects
510
+ description: Manage objects
511
+ alias: o
512
+ operations:
513
+ # list
514
+ - name: list
515
+ description: List objects
516
+ alias: l
517
+ arguments:
518
+ - name: bucket
519
+ description: Name of the bucket
520
+ alias: b
521
+ required: true
522
+ - name: format
523
+ description: Format
524
+ alias: f
525
+ options: [json, table, xml]
526
+ default: table
527
+ # get
528
+ - name: get
529
+ description: Get object
530
+ alias: g
531
+ arguments:
532
+ - name: bucket
533
+ description: Name of the bucket
534
+ type: noun
535
+ required: true
536
+ - name: key
537
+ description: Name of the object
538
+ type: noun
539
+ required: true
540
+ - name: format
541
+ description: Format
542
+ alias: f
543
+ options: [string, file, stream]
544
+ default: string
545
+ # create
546
+ - name: create
547
+ description: Create object
548
+ alias: c
549
+ arguments:
550
+ - name: bucket
551
+ description: Name of the bucket
552
+ type: noun
553
+ required: true
554
+ - name: name
555
+ description: Name of the object
556
+ type: noun
557
+ required: true
558
+ - name: body
559
+ description: Body of the object
560
+ alias: d
561
+ required: true
562
+ - name: access
563
+ description: Access level
564
+ alias: a
565
+ options: *access_options
566
+ default: private
567
+ - name: content-type
568
+ description: Content type
569
+ alias: c
570
+ - name: content-disposition
571
+ description: Content disposition
572
+ alias: d
573
+ - name: tier
574
+ description: Tier
575
+ alias: t
576
+ options: *tier_options
577
+ default: STANDARD
578
+ # delete
579
+ - name: delete
580
+ description: Delete object
581
+ alias: d
582
+ arguments:
583
+ - name: bucket
584
+ description: Name of the bucket
585
+ type: noun
586
+ required: true
587
+ - name: key
588
+ description: Name of the object (comma separated names for multiple objects)
589
+ type: noun
590
+ required: true
591
+ multiple: true
592
+ # copy
593
+ - name: copy
594
+ description: Copy object
595
+ alias: c
596
+ arguments:
597
+ - name: bucket
598
+ description: Name of the bucket
599
+ type: noun
600
+ required: true
601
+ - name: name
602
+ description: Name of the object (comma separated names for multiple objects)
603
+ type: noun
604
+ required: true
605
+ multiple: true
606
+ - name: destination
607
+ description: Destination
608
+ type: noun
609
+ required: true
610
+ # move
611
+ - name: move
612
+ description: Move object
613
+ alias: m
614
+ arguments:
615
+ - name: bucket
616
+ description: Name of the bucket
617
+ type: noun
618
+ required: true
619
+ - name: source
620
+ description: Name of the object (comma separated names for multiple objects)
621
+ type: noun
622
+ required: true
623
+ multiple: true
624
+ - name: destination
625
+ description: Destination
626
+ type: noun
627
+ required: true
package/dist/types.js ADDED
File without changes
@@ -0,0 +1,6 @@
1
+ function m(n){return JSON.stringify(n,null,2)}function l(n,e=" "){return Object.entries(n).map(([t,r])=>`${e}<${t}>${r}</${t}>`).join(`
2
+ `)}function T(n,e,t){let r=[`<${e}>`];return n.forEach(o=>{r.push(` <${t}>`),r.push(l(o," ")),r.push(` </${t}>`)}),r.push(`</${e}>`),r.join(`
3
+ `)}function p(n){if(n==null)return"";if(n instanceof Date)return f(n);if(typeof n=="string"){let e=new Date(n);if(!isNaN(e.getTime())&&n.includes("T"))return f(e)}return String(n)}function f(n){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(n)}function w(n,e){return e.map(t=>{if(t.width)return t.width;let r=t.header.length,o=n.reduce((s,u)=>{let a=p(u[t.key]);return Math.max(s,a.length)},0);return Math.max(r,o)})}function x(n,e){let t=[],r=w(n,e),o="\u250C"+r.map(i=>"\u2500".repeat(i+2)).join("\u252C")+"\u2510",s="\u251C"+r.map(i=>"\u2500".repeat(i+2)).join("\u253C")+"\u2524",u="\u2514"+r.map(i=>"\u2500".repeat(i+2)).join("\u2534")+"\u2518";t.push(`
4
+ `+o);let a="\u2502 "+e.map((i,d)=>i.header.padEnd(r[d])).join(" \u2502 ")+" \u2502";return t.push(a),t.push(s),n.forEach(i=>{let d=e.map((c,g)=>{let h=p(i[c.key]);return c.align==="right"?h.padStart(r[g]):h.padEnd(r[g])});t.push("\u2502 "+d.join(" \u2502 ")+" \u2502")}),t.push(u+`
5
+ `),t.join(`
6
+ `)}function j(n,e,t,r,o){switch(e){case"json":return m(n);case"xml":return T(n,t,r);default:return x(n,o)}}export{m as formatJson,j as formatOutput,x as formatTable,T as formatXml,l as formatXmlObject};
@@ -0,0 +1,2 @@
1
+ import{readFileSync as g,existsSync as f}from"fs";import{join as m,dirname as d}from"path";import{fileURLToPath as S}from"url";import*as l from"yaml";var C=S(import.meta.url),M=d(C),a=null;function x(){let n=M;for(let e=0;e<5;e++){let s=m(n,"specs.yaml");if(f(s))return s;n=m(n,"..")}throw new Error("Could not find specs.yaml")}function y(){if(!a){let n=x(),e=g(n,"utf8");a=l.parse(e)}return a}function u(n,e){let t=y().commands.find(o=>o.name===n);return t?e&&t.operations?t.operations.find(o=>o.name===e)||null:t:null}var c={success:"\u2714",failure:"\u2716",hint:"\u2192"};function r(n){let e=u(n.command,n.operation);if(e)return e.messages}function i(n,e){let s=n;return s=s.replace(/\\n/g,`
2
+ `),e&&(s=s.replace(/\{\{(\w+)\}\}/g,(t,o)=>{let p=e[o];return p!==void 0?String(p):`{{${o}}}`})),s}function V(n,e){let s=r(n);s?.onStart&&console.log(i(s.onStart,e))}function O(n,e){let s=r(n);s?.onSuccess&&console.log(`${c.success} ${i(s.onSuccess,e)}`)}function P(n,e,s){let t=r(n);t?.onFailure&&console.error(`${c.failure} ${i(t.onFailure,s)}`),e&&console.error(` ${e}`)}function _(n,e){let s=r(n);s?.onEmpty&&console.log(i(s.onEmpty,e))}function j(n,e){let s=r(n);s?.onAlreadyDone&&console.log(i(s.onAlreadyDone,e))}function D(n,e){let s=r(n);s?.hint&&console.log(`${c.hint} ${i(s.hint,e)}`)}function E(n,e){return{command:n,operation:e}}export{E as msg,j as printAlreadyDone,_ as printEmpty,P as printFailure,D as printHint,V as printStart,O as printSuccess};
@@ -0,0 +1 @@
1
+ function f(n,r,t){for(let e of r)if(n[e]!==void 0)return n[e];return t}export{f as getOption};
@@ -0,0 +1 @@
1
+ function r(s){let t=s.split("/");return{bucket:t[0],path:t.slice(1).join("/")}}function e(s,t){return{source:r(s),destination:r(t)}}export{r as parsePath,e as parsePaths};
@@ -0,0 +1 @@
1
+ import{readFileSync as c,existsSync as m}from"fs";import{join as o,dirname as p}from"path";import{fileURLToPath as l}from"url";import*as a from"yaml";var u=l(import.meta.url),f=p(u),i=null;function d(){let e=f;for(let n=0;n<5;n++){let t=o(e,"specs.yaml");if(m(t))return t;e=o(e,"..")}throw new Error("Could not find specs.yaml")}function g(){if(!i){let e=d(),n=c(e,"utf8");i=a.parse(n)}return i}function S(e,n){let r=g().commands.find(s=>s.name===e);return r?n&&r.operations?r.operations.find(s=>s.name===n)||null:r:null}function h(e,n,t){let r=S(e,t);return!r||!r.arguments?null:r.arguments.find(s=>s.name===n)||null}function v(e){return e.options?Array.isArray(e.options)&&typeof e.options[0]=="string"?e.options.map(n=>({name:n,message:n.charAt(0).toUpperCase()+n.slice(1),value:n})):Array.isArray(e.options)&&typeof e.options[0]=="object"?e.options.map(n=>({name:n.value,message:n.description?`${n.name} - ${n.description}`:n.name,value:n.value})):null:null}export{v as buildPromptChoices,h as getArgumentSpec,S as getCommandSpec};
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@tigrisdata/cli",
3
- "version": "1.6.3",
3
+ "version": "2.1.0",
4
4
  "description": "Command line interface for Tigris object storage",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/cli.js",
9
- "require": "./dist/cli.cjs"
8
+ "import": "./dist/cli.js"
10
9
  }
11
10
  },
12
11
  "bin": {
13
- "tigris": "./dist/cli.js"
12
+ "tigris": "./dist/cli.js",
13
+ "t3": "./dist/cli.js"
14
14
  },
15
15
  "files": [
16
16
  "dist",
@@ -22,9 +22,15 @@
22
22
  "scripts": {
23
23
  "build": "tsup",
24
24
  "dev": "tsup --watch",
25
+ "lint": "eslint src --ext .ts",
26
+ "lint:fix": "eslint src --ext .ts --fix",
27
+ "format": "prettier --write \"src/**/*.ts\"",
28
+ "format:check": "prettier --check \"src/**/*.ts\"",
25
29
  "publint": "publint",
26
30
  "prepublishOnly": "npm run build",
27
- "clean": "rm -rf dist"
31
+ "clean": "rm -rf dist",
32
+ "semantic-release": "semantic-release",
33
+ "prepare": "husky install"
28
34
  },
29
35
  "keywords": [
30
36
  "cli",
@@ -36,12 +42,57 @@
36
42
  "author": "Tigris Data",
37
43
  "repository": {
38
44
  "type": "git",
39
- "url": "git+https://github.com/tigrisdata/storage.git",
40
- "directory": "packages/cli"
45
+ "url": "git+https://github.com/tigrisdata/cli.git"
41
46
  },
42
47
  "license": "MIT",
48
+ "config": {
49
+ "commitizen": {
50
+ "path": "cz-conventional-changelog"
51
+ }
52
+ },
53
+ "commitlint": {
54
+ "extends": [
55
+ "@commitlint/config-conventional"
56
+ ]
57
+ },
58
+ "release": {
59
+ "branches": [
60
+ "main",
61
+ {
62
+ "name": "next",
63
+ "prerelease": true
64
+ }
65
+ ],
66
+ "plugins": [
67
+ "@semantic-release/commit-analyzer",
68
+ "@semantic-release/release-notes-generator",
69
+ "@semantic-release/github",
70
+ "@semantic-release/npm"
71
+ ]
72
+ },
43
73
  "dependencies": {
44
- "@tigrisdata/storage": "*",
45
- "commander": "^11.0.0"
74
+ "@aws-sdk/client-s3": "^3.908.0",
75
+ "@tigrisdata/storage": "^2.10.0",
76
+ "axios": "^1.12.2",
77
+ "commander": "^11.0.0",
78
+ "enquirer": "^2.4.1",
79
+ "open": "^10.2.0",
80
+ "yaml": "^2.3.4"
81
+ },
82
+ "devDependencies": {
83
+ "@commitlint/cli": "^20.2.0",
84
+ "@commitlint/config-conventional": "^20.2.0",
85
+ "@semantic-release/changelog": "^6.0.3",
86
+ "@semantic-release/git": "^10.0.1",
87
+ "@types/node": "^20.0.0",
88
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
89
+ "@typescript-eslint/parser": "^6.0.0",
90
+ "eslint": "^8.0.0",
91
+ "husky": "^8.0.0",
92
+ "prettier": "^3.0.0",
93
+ "publint": "^0.2.0",
94
+ "semantic-release": "^25.0.2",
95
+ "tsup": "^8.0.0",
96
+ "typescript": "^5.0.0"
46
97
  }
47
98
  }
package/dist/cli.cjs DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- // src/cli.ts
5
- var import_commander = require("commander");
6
- var program = new import_commander.Command();
7
- program.name("tigris").description("Command line interface for Tigris object storage").version("0.0.1");
8
- program.parse();
9
- //# sourceMappingURL=cli.cjs.map
package/dist/cli.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from 'commander';\n\nconst program = new Command();\n\nprogram\n .name('tigris')\n .description('Command line interface for Tigris object storage')\n .version('0.0.1');\n\nprogram.parse();\n"],"mappings":";;;;AAEA,uBAAwB;AAExB,IAAM,UAAU,IAAI,yBAAQ;AAE5B,QACG,KAAK,QAAQ,EACb,YAAY,kDAAkD,EAC9D,QAAQ,OAAO;AAElB,QAAQ,MAAM;","names":[]}
package/dist/cli.d.cts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Command } from 'commander';\n\nconst program = new Command();\n\nprogram\n .name('tigris')\n .description('Command line interface for Tigris object storage')\n .version('0.0.1');\n\nprogram.parse();\n"],"mappings":";;;AAEA,SAAS,eAAe;AAExB,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,QAAQ,EACb,YAAY,kDAAkD,EAC9D,QAAQ,OAAO;AAElB,QAAQ,MAAM;","names":[]}