@tigrisdata/cli 2.6.0 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +22 -13
  2. package/dist/auth/client.js +1 -1
  3. package/dist/auth/config.js +1 -1
  4. package/dist/auth/s3-client.js +1 -1
  5. package/dist/auth/storage.js +1 -1
  6. package/dist/chunk-4LGKN5DA.js +1 -0
  7. package/dist/chunk-6U4U4JM6.js +1 -0
  8. package/dist/chunk-A3TXP5Y2.js +2 -0
  9. package/dist/chunk-D63SZLT5.js +1 -0
  10. package/dist/chunk-DJIPPZGR.js +4 -0
  11. package/dist/chunk-ESJWTUFN.js +1 -0
  12. package/dist/chunk-HE7E7ZMA.js +1 -0
  13. package/dist/chunk-HGIJOGCZ.js +6 -0
  14. package/dist/chunk-JRALYIRA.js +1 -0
  15. package/dist/chunk-JVB3Y42V.js +1 -0
  16. package/dist/chunk-LCWHZUZZ.js +1 -0
  17. package/dist/chunk-QZXBLNMQ.js +1 -0
  18. package/dist/chunk-TPUZYSCZ.js +12 -0
  19. package/dist/chunk-TUJTXB5G.js +8 -0
  20. package/dist/cli.js +1 -12
  21. package/dist/constants.js +1 -1
  22. package/dist/index.js +1 -12
  23. package/dist/lib/_stat.js +1 -1
  24. package/dist/lib/access-keys/assign.js +2 -3
  25. package/dist/lib/access-keys/create.js +2 -3
  26. package/dist/lib/access-keys/delete.js +2 -3
  27. package/dist/lib/access-keys/get.js +2 -3
  28. package/dist/lib/access-keys/list.js +2 -8
  29. package/dist/lib/buckets/create.js +1 -2
  30. package/dist/lib/buckets/delete.js +1 -2
  31. package/dist/lib/buckets/get.js +1 -7
  32. package/dist/lib/buckets/list.js +1 -7
  33. package/dist/lib/buckets/set.js +1 -2
  34. package/dist/lib/configure/index.js +1 -2
  35. package/dist/lib/cp.js +1 -1
  36. package/dist/lib/credentials/test.js +1 -2
  37. package/dist/lib/forks/create.js +1 -2
  38. package/dist/lib/forks/list.js +1 -7
  39. package/dist/lib/login/credentials.js +1 -2
  40. package/dist/lib/login/oauth.js +1 -5
  41. package/dist/lib/login/select.js +1 -5
  42. package/dist/lib/logout.js +1 -2
  43. package/dist/lib/ls.js +1 -6
  44. package/dist/lib/mk.js +1 -1
  45. package/dist/lib/mv.js +1 -1
  46. package/dist/lib/objects/delete.js +1 -2
  47. package/dist/lib/objects/get.js +1 -2
  48. package/dist/lib/objects/list.js +1 -7
  49. package/dist/lib/objects/put.js +1 -7
  50. package/dist/lib/organizations/create.js +2 -3
  51. package/dist/lib/organizations/list.js +2 -8
  52. package/dist/lib/organizations/select.js +4 -5
  53. package/dist/lib/rm.js +1 -1
  54. package/dist/lib/snapshots/list.js +1 -7
  55. package/dist/lib/snapshots/take.js +1 -2
  56. package/dist/lib/touch.js +1 -1
  57. package/dist/lib/whoami.js +2 -3
  58. package/dist/specs.yaml +49 -28
  59. package/dist/utils/format.js +1 -6
  60. package/dist/utils/messages.js +1 -2
  61. package/dist/utils/options.js +1 -1
  62. package/dist/utils/path.js +1 -1
  63. package/dist/utils/specs.js +1 -1
  64. package/dist/utils/update-check.js +1 -0
  65. package/package.json +3 -2
package/dist/lib/mk.js CHANGED
@@ -1 +1 @@
1
- import{list as ee}from"@tigrisdata/storage";function k(n){let e=n.split("/");return{bucket:e[0],path:e.slice(1).join("/")}}function P(n,e,t){for(let i of e)if(n[i]!==void 0)return n[i];return t}import{S3Client as Ce}from"@aws-sdk/client-s3";import{fromIni as H}from"@aws-sdk/credential-providers";import{homedir as v}from"os";import{join as g}from"path";import{readFileSync as F,writeFileSync as U,existsSync as f,mkdirSync as W}from"fs";import{loadSharedConfigFiles as j}from"@smithy/shared-ini-file-loader";import{chmod as $}from"fs/promises";var d="https://t3.storage.dev",y="https://iam.storageapi.dev";var C=g(v(),".tigris"),p=g(C,"config.json");function q(){f(C)||W(C,{recursive:!0,mode:448})}function c(){if(f(p))try{let n=F(p,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function u(n){q(),U(p,JSON.stringify(n,null,2),{mode:384});try{await $(p,384)}catch{}}async function _(n){let e=c();e.tokens=n,await u(e)}async function l(){return c().tokens||null}async function I(){let n=c();delete n.tokens,await u(n)}async function x(n){let e=c();e.organizations=n,await u(e)}function O(){return c().organizations||[]}function w(){return c().selectedOrganization||null}function N(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let i=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,r=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!i||!r)return null;let o=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:i,secretAccessKey:r,endpoint:o}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let t=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:n,secretAccessKey:e,endpoint:t}}function K(){if(!process.env.AWS_PROFILE)return!1;let n=g(v(),".aws");return f(g(n,"credentials"))||f(g(n,"config"))}async function D(n){try{let{configFile:e}=await j(),t=e[n];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function A(){let n=c();return n.temporaryCredentials||n.credentials||null}async function R(n){let e=c();e.loginMethod=n,await u(e)}function M(){return c().loginMethod||null}import h from"axios";import B from"open";function m(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",i=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:t,audience:i}}var z=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function L(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||y}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||y}}var E=class{config;baseUrl;constructor(){this.config=m(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await h.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 B(i.verification_uri_complete)}catch{}e?.onWaiting?.();let r=await this.pollForToken(i.device_code,i.interval||5);await _(r),R("oauth"),await this.extractAndStoreOrganizations(r.idToken)}async pollForToken(e,t){let r=0;for(;r<60;){r++;try{let s=(await h.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(h.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 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 r=(await h.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 _(o),o}catch{throw await I(),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)[z];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;x(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),O()}async logout(){await I()}async isAuthenticated(){return await l()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},S=null;function b(){return S||(S=new E),S}var T=L(),J=m();async function Y(){return M()}async function G(){if(K()){let i=process.env.AWS_PROFILE||"default",r=await D(i),o=await H({profile:i})();return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:r.endpoint||T.endpoint||d,iamEndpoint:r.iamEndpoint||T.iamEndpoint}}let n=await Y();if(n==="oauth"){let r=await b().getAccessToken();if(!w())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:r,accessKeyId:"",secretAccessKey:"",endpoint:T.endpoint,organizationId:w()??void 0,iamEndpoint:T.iamEndpoint,authDomain:J.domain}}if(n==="credentials"){let i=A();if(i)return{accessKeyId:i.accessKeyId,secretAccessKey:i.secretAccessKey,endpoint:i.endpoint}}let e=N();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let t=A();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{createBucket as V,put as Q}from"@tigrisdata/storage";async function X(n){let e=P(n,["path"]);e||(console.error("path argument is required"),process.exit(1));let{bucket:t,path:i}=k(e);t||(console.error("Invalid path"),process.exit(1));let r=await G();if(i){let o=i.endsWith("/")?i:`${i}/`,{error:s}=await Q(o,"",{config:{...r,bucket:t}});s&&(console.error(s.message),process.exit(1)),console.log(`Folder '${t}/${o}' created`),process.exit(0)}else{let{error:o}=await V(t,{config:r});o&&(console.error(o.message),process.exit(1)),console.log(`Bucket '${t}' created`),process.exit(0)}}export{X as default};
1
+ import{a as n}from"../chunk-JRALYIRA.js";import{b as a}from"../chunk-ESJWTUFN.js";import"../chunk-QZXBLNMQ.js";import"../chunk-6U4U4JM6.js";import{f as c}from"../chunk-LCWHZUZZ.js";import"../chunk-JVB3Y42V.js";import"../chunk-D63SZLT5.js";import{createBucket as f,put as g}from"@tigrisdata/storage";async function l(p){let t=n(p,["path"]);t||(console.error("path argument is required"),process.exit(1));let{bucket:e,path:r}=c(t);e||(console.error("Invalid path"),process.exit(1));let s=await a();if(r){let o=r.endsWith("/")?r:`${r}/`,{error:i}=await g(o,"",{config:{...s,bucket:e}});i&&(console.error(i.message),process.exit(1)),console.log(`Folder '${e}/${o}' created`),process.exit(0)}else{let{error:o}=await f(e,{config:s});o&&(console.error(o.message),process.exit(1)),console.log(`Bucket '${e}' created`),process.exit(0)}}export{l as default};
package/dist/lib/mv.js CHANGED
@@ -1 +1 @@
1
- import*as se from"readline";import{list as j}from"@tigrisdata/storage";function b(t){let e=t.split("/");return{bucket:e[0],path:e.slice(1).join("/")}}async function O(t,e,n){let{data:i}=await j({prefix:`${e}/`,limit:1,config:{...n,bucket:t}});return!!(i?.items&&i.items.length>0)}async function q(t,e,n){let i=[],o;do{let{data:r,error:s}=await j({prefix:e,paginationToken:o,config:{...n,bucket:t}});if(s)return{items:i,error:s};r?.items&&i.push(...r.items),o=r?.hasMore?r.paginationToken:void 0}while(o);return{items:i}}function C(t,e,n){for(let i of e)if(t[i]!==void 0)return t[i];return n}import{S3Client as Ge}from"@aws-sdk/client-s3";import{fromIni as he}from"@aws-sdk/credential-providers";import{homedir as H}from"os";import{join as m}from"path";import{readFileSync as de,writeFileSync as le,existsSync as k,mkdirSync as fe}from"fs";import{loadSharedConfigFiles as ge}from"@smithy/shared-ini-file-loader";import{chmod as pe}from"fs/promises";var g="https://t3.storage.dev",N="https://iam.storageapi.dev";var R=m(H(),".tigris"),I=m(R,"config.json");function ue(){k(R)||fe(R,{recursive:!0,mode:448})}function f(){if(k(I))try{let t=de(I,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function A(t){ue(),le(I,JSON.stringify(t,null,2),{mode:384});try{await pe(I,384)}catch{}}async function D(t){let e=f();e.tokens=t,await A(e)}async function h(){return f().tokens||null}async function K(){let t=f();delete t.tokens,await A(t)}async function J(t){let e=f();e.organizations=t,await A(e)}function Y(){return f().organizations||[]}function M(){return f().selectedOrganization||null}function B(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let i=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,o=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!i||!o)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||g;return{accessKeyId:i,secretAccessKey:o,endpoint:r}}let t=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!t||!e)return null;let n=process.env.AWS_ENDPOINT_URL_S3||g;return{accessKeyId:t,secretAccessKey:e,endpoint:n}}function V(){if(!process.env.AWS_PROFILE)return!1;let t=m(H(),".aws");return k(m(t,"credentials"))||k(m(t,"config"))}async function Q(t){try{let{configFile:e}=await ge(),n=e[t];return n?{endpoint:n.endpoint_url_s3||n.endpoint_url,iamEndpoint:n.endpoint_url_iam,region:n.region}:{}}catch{return{}}}function $(){let t=f();return t.temporaryCredentials||t.credentials||null}async function X(t){let e=f();e.loginMethod=t,await A(e)}function Z(){return f().loginMethod||null}import S from"axios";import me from"open";function _(){let t=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||t?"auth-dev.tigris.dev":"auth.tigris.dev",n=process.env.AUTH0_CLIENT_ID||t?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",i=process.env.AUTH0_AUDIENCE||t?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:n,audience:i}}var ee=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function te(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||g,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||N}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||g,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||N}}var L=class{config;baseUrl;constructor(){this.config=_(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await S.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 me(i.verification_uri_complete)}catch{}e?.onWaiting?.();let o=await this.pollForToken(i.device_code,i.interval||5);await D(o),X("oauth"),await this.extractAndStoreOrganizations(o.idToken)}async pollForToken(e,n){let o=0;for(;o<60;){o++;try{let s=(await S.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(S.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 h();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 h(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let o=(await S.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:o.access_token,refreshToken:o.refresh_token||n.refreshToken,idToken:o.id_token||n.idToken,expiresAt:Date.now()+(o.expires_in||3600)*1e3};return await D(r),r}catch{throw await K(),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 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"),r=JSON.parse(i)[ee];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;J(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),Y()}async logout(){await K()}async isAuthenticated(){return await h()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},F=null;function ne(){return F||(F=new L),F}var v=te(),Te=_();async function ye(){return Z()}async function oe(){if(V()){let i=process.env.AWS_PROFILE||"default",o=await Q(i),r=await he({profile:i})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:o.endpoint||v.endpoint||g,iamEndpoint:o.iamEndpoint||v.iamEndpoint}}let t=await ye();if(t==="oauth"){let o=await ne().getAccessToken();if(!M())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:o,accessKeyId:"",secretAccessKey:"",endpoint:v.endpoint,organizationId:M()??void 0,iamEndpoint:v.iamEndpoint,authDomain:Te.domain}}if(t==="credentials"){let i=$();if(i)return{accessKeyId:i.accessKeyId,secretAccessKey:i.secretAccessKey,endpoint:i.endpoint}}let e=B();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let n=$();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{get as we,put as re,remove as G,list as Ce}from"@tigrisdata/storage";async function ie(t){let e=se.createInterface({input:process.stdin,output:process.stdout});return new Promise(n=>{e.question(`${t} (y/N): `,i=>{e.close(),n(i.toLowerCase()==="y")})})}async function ke(t){let e=C(t,["src"]),n=C(t,["dest"]),i=C(t,["force","f","F"]);(!e||!n)&&(console.error("both src and dest arguments are required"),process.exit(1));let o=b(e),r=b(n);o.bucket||(console.error("Invalid source path"),process.exit(1)),r.bucket||(console.error("Invalid destination path"),process.exit(1)),o.path||(console.error("Cannot move a bucket. Provide a path within the bucket."),process.exit(1));let s=await oe(),a=e.includes("*"),p=e.endsWith("/");if(!a&&!p&&o.path&&(p=await O(o.bucket,o.path,s)),a||p){let c=a?o.path.replace("*",""):o.path.endsWith("/")?o.path:`${o.path}/`,l=r.path?`${r.path.replace(/\/$/,"")}/`:"";o.bucket===r.bucket&&c===l&&(console.error("Source and destination are the same"),process.exit(1));let{items:T,error:y}=await q(o.bucket,c||void 0,s);y&&(console.error(y.message),process.exit(1));let E=T.filter(d=>d.name!==c),{data:ae}=await Ce({prefix:c,limit:1,config:{...s,bucket:o.bucket}}),P=c?ae?.items?.some(d=>d.name===c):!1;if(E.length===0&&!P){console.log("No objects to move");return}let ce=E.length+(P?1:0);if(!i&&!await ie(`Are you sure you want to move ${ce} object(s)?`)){console.log("Aborted");return}let w=0;for(let d of E){let u=c?d.name.slice(c.length):d.name,U=r.path?`${r.path.replace(/\/$/,"")}/${u}`:u,W=await z(s,o.bucket,d.name,r.bucket,U);W.error?console.error(`Failed to move ${d.name}: ${W.error}`):(console.log(`Moved ${d.name} -> ${r.bucket}/${U}`),w++)}let x=!1;if(P)if(r.path){let d=`${r.path.replace(/\/$/,"")}/`,u=await z(s,o.bucket,c,r.bucket,d);u.error?console.error(`Failed to move folder marker: ${u.error}`):x=!0}else{let{error:d}=await G(c,{config:{...s,bucket:o.bucket}});d?console.error(`Failed to remove source folder marker: ${d.message}`):x=!0}w===0&&x&&(w=1),console.log(`Moved ${w} object(s)`)}else{o.path||(console.error("Source object key is required"),process.exit(1));let c=o.path.split("/").pop(),l;if(r.path?n.endsWith("/")?l=`${r.path}${c}`:await O(r.bucket,r.path,s)?l=`${r.path}/${c}`:l=r.path:l=c,o.bucket===r.bucket&&o.path===l&&(console.error("Source and destination are the same"),process.exit(1)),!i&&!await ie(`Are you sure you want to move '${o.bucket}/${o.path}'?`)){console.log("Aborted");return}let T=await z(s,o.bucket,o.path,r.bucket,l);T.error&&(console.error(T.error),process.exit(1)),console.log(`Moved ${e} -> ${r.bucket}/${l}`)}process.exit(0)}async function z(t,e,n,i,o){if(n.endsWith("/")){let{error:c}=await re(o,"",{config:{...t,bucket:i}});if(c)return{error:c.message};let{error:l}=await G(n,{config:{...t,bucket:e}});return l?{error:`Copied but failed to delete source: ${l.message}`}:{}}let{data:r,error:s}=await we(n,"stream",{config:{...t,bucket:e}});if(s)return{error:s.message};let{error:a}=await re(o,r,{config:{...t,bucket:i}});if(a)return{error:a.message};let{error:p}=await G(n,{config:{...t,bucket:e}});return p?{error:`Copied but failed to delete source: ${p.message}`}:{}}export{ke as default};
1
+ import{a as x}from"../chunk-HGIJOGCZ.js";import{a as v}from"../chunk-JRALYIRA.js";import{b as j}from"../chunk-ESJWTUFN.js";import"../chunk-QZXBLNMQ.js";import"../chunk-6U4U4JM6.js";import{a as F,b as y,d as S,g as A,h as C,i as I}from"../chunk-LCWHZUZZ.js";import"../chunk-JVB3Y42V.js";import"../chunk-D63SZLT5.js";import*as N from"readline";import{get as B,put as T,remove as E,list as L,head as G}from"@tigrisdata/storage";async function D(i){let n=N.createInterface({input:process.stdin,output:process.stdout});return new Promise(a=>{n.question(`${i} (y/N): `,d=>{n.close(),a(d.toLowerCase()==="y")})})}async function H(i){let n=v(i,["src"]),a=v(i,["dest"]),d=v(i,["force","f","F"]),h=!!v(i,["recursive","r"]);(!n||!a)&&(console.error("both src and dest arguments are required"),process.exit(1)),(!F(n)||!F(a))&&(console.error("Both src and dest must be remote Tigris paths (t3:// or tigris://)"),process.exit(1));let e=y(n),t=y(a);e.bucket||(console.error("Invalid source path"),process.exit(1)),t.bucket||(console.error("Invalid destination path"),process.exit(1));let $=n.endsWith("/");!e.path&&!$&&(console.error("Cannot move a bucket. Provide a path within the bucket."),process.exit(1));let c=await j(),l=e.path.includes("*"),p=e.path.endsWith("/")||!e.path&&$;if(!l&&!p&&e.path&&(p=await S(e.bucket,e.path,c)),p&&!l&&!h&&(console.error("Source is a remote folder (not moved). Use -r to move recursively."),process.exit(1)),l||p){let r=l?C(e.path):e.path?e.path.endsWith("/")?e.path:`${e.path}/`:"",o=!l&&e.path&&!e.path.endsWith("/")?e.path.split("/").filter(Boolean).pop()??"":"",f=[t.path?.replace(/\/$/,"")||"",o].filter(Boolean).join("/"),z=f?`${f}/`:"";e.bucket===t.bucket&&r===z&&(console.error("Source and destination are the same"),process.exit(1));let{items:q,error:R}=await I(e.bucket,r||void 0,c);R&&(console.error(R.message),process.exit(1));let b=q.filter(s=>s.name!==r);if(l){let s=e.path.split("/").pop(),m=A(s);b=b.filter(g=>{let k=r?g.name.slice(r.length):g.name;return!h&&k.includes("/")?!1:m.test(k.split("/").pop())})}let{data:O}=await L({prefix:r,limit:1,config:{...c,bucket:e.bucket}}),P=r?O?.items?.some(s=>s.name===r):!1;if(b.length===0&&!P){console.log("No objects to move");return}let U=b.length+(P?1:0);if(!d&&!await D(`Are you sure you want to move ${U} object(s)?`)){console.log("Aborted");return}let w=0;for(let s of b){let m=r?s.name.slice(r.length):s.name,g=f?`${f}/${m}`:m,k=await W(c,e.bucket,s.name,t.bucket,g);k.error?console.error(`Failed to move ${s.name}: ${k.error}`):(console.log(`Moved t3://${e.bucket}/${s.name} -> t3://${t.bucket}/${g}`),w++)}let M=!1;if(P)if(f){let s=`${f}/`,m=await W(c,e.bucket,r,t.bucket,s);m.error?console.error(`Failed to move folder marker: ${m.error}`):M=!0}else{let{error:s}=await E(r,{config:{...c,bucket:e.bucket}});s?console.error(`Failed to remove source folder marker: ${s.message}`):M=!0}w===0&&M&&(w=1),console.log(`Moved ${w} object(s)`)}else{let r=e.path.split("/").pop(),o;if(t.path?t.path.endsWith("/")?o=`${t.path}${r}`:await S(t.bucket,t.path,c)?o=`${t.path}/${r}`:o=t.path:o=r,e.bucket===t.bucket&&e.path===o&&(console.error("Source and destination are the same"),process.exit(1)),!d&&!await D(`Are you sure you want to move 't3://${e.bucket}/${e.path}'?`)){console.log("Aborted");return}let u=await W(c,e.bucket,e.path,t.bucket,o,!0);u.error&&(console.error(u.error),process.exit(1)),console.log(`Moved t3://${e.bucket}/${e.path} -> t3://${t.bucket}/${o}`)}process.exit(0)}async function W(i,n,a,d,h,e=!1){if(a.endsWith("/")){let{error:o}=await T(h,"",{config:{...i,bucket:d}});if(o)return{error:o.message};let{error:u}=await E(a,{config:{...i,bucket:n}});return u?{error:`Copied but failed to delete source: ${u.message}`}:{}}let t;if(e){let{data:o}=await G(a,{config:{...i,bucket:n}});t=o?.size}let{data:$,error:c}=await B(a,"stream",{config:{...i,bucket:n}});if(c)return{error:c.message};let l=t!==void 0&&t>100*1024*1024,{error:p}=await T(h,$,{multipart:l,onUploadProgress:e?({loaded:o})=>{if(t!==void 0&&t>0){let u=Math.round(o/t*100);process.stdout.write(`\rMoving: ${x(o)} / ${x(t)} (${u}%)`)}else process.stdout.write(`\rMoving: ${x(o)}`)}:void 0,config:{...i,bucket:d}});if(e&&process.stdout.write("\r"+" ".repeat(60)+"\r"),p)return{error:p.message};let{error:r}=await E(a,{config:{...i,bucket:n}});return r?{error:`Copied but failed to delete source: ${r.message}`}:{}}export{H as default};
@@ -1,2 +1 @@
1
- function S(n,e,t){for(let o of e)if(n[o]!==void 0)return n[o];return t}import{S3Client as Re}from"@aws-sdk/client-s3";import{fromIni as re}from"@aws-sdk/credential-providers";import{homedir as M}from"os";import{join as l}from"path";import{readFileSync as X,writeFileSync as Z,existsSync as f,mkdirSync as ee}from"fs";import{loadSharedConfigFiles as ne}from"@smithy/shared-ini-file-loader";import{chmod as te}from"fs/promises";var d="https://t3.storage.dev",A="https://iam.storageapi.dev";var _=l(M(),".tigris"),u=l(_,"config.json");function oe(){f(_)||ee(_,{recursive:!0,mode:448})}function c(){if(f(u))try{let n=X(u,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function m(n){oe(),Z(u,JSON.stringify(n,null,2),{mode:384});try{await te(u,384)}catch{}}async function w(n){let e=c();e.tokens=n,await m(e)}async function g(){return c().tokens||null}async function I(){let n=c();delete n.tokens,await m(n)}async function D(n){let e=c();e.organizations=n,await m(e)}function K(){return c().organizations||[]}function E(){return c().selectedOrganization||null}function R(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:o,secretAccessKey:i,endpoint:r}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let t=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:n,secretAccessKey:e,endpoint:t}}function b(){if(!process.env.AWS_PROFILE)return!1;let n=l(M(),".aws");return f(l(n,"credentials"))||f(l(n,"config"))}async function L(n){try{let{configFile:e}=await ne(),t=e[n];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function k(){let n=c();return n.temporaryCredentials||n.credentials||null}async function z(n){let e=c();e.loginMethod=n,await m(e)}function G(){return c().loginMethod||null}import C from"axios";import ie from"open";function y(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:t,audience:o}}var F=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function U(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||A}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||A}}var x=class{config;baseUrl;constructor(){this.config=y(),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 ie(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await w(i),z("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,t){let i=0;for(;i<60;){i++;try{let s=(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,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(C.isAxiosError(r)&&r.response){let s=r.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(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 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 g(),!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 w(r),r}catch{throw await I(),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 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)[F];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;D(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),K()}async logout(){await I()}async isAuthenticated(){return await g()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},v=null;function j(){return v||(v=new x),v}var h=U(),se=y();async function ae(){return G()}async function $(){if(b()){let o=process.env.AWS_PROFILE||"default",i=await L(o),r=await re({profile:o})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||h.endpoint||d,iamEndpoint:i.iamEndpoint||h.iamEndpoint}}let n=await ae();if(n==="oauth"){let i=await j().getAccessToken();if(!E())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:h.endpoint,organizationId:E()??void 0,iamEndpoint:h.iamEndpoint,authDomain:se.domain}}if(n==="credentials"){let o=k();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let e=R();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let t=k();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{remove as ye}from"@tigrisdata/storage";import{readFileSync as ce,existsSync as de}from"fs";import{join as W,dirname as le}from"path";import{fileURLToPath as ge}from"url";import*as Y from"yaml";var pe=ge(import.meta.url),fe=le(pe),O=null;function ue(){let n=fe;for(let e=0;e<5;e++){let t=W(n,"specs.yaml");if(de(t))return t;n=W(n,"..")}throw new Error("Could not find specs.yaml")}function me(){if(!O){let n=ue(),e=ce(n,"utf8");O=Y.parse(e)}return O}function V(n,e){let o=me().commands.find(i=>i.name===n);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var q={success:"\u2714",failure:"\u2716",hint:"\u2192"};function H(){return process.stdout.isTTY===!0}function P(n){let e=V(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,(o,i)=>{let r=e[i];return r!==void 0?String(r):`{{${i}}}`})),t}function J(n,e){if(!H())return;let t=P(n);t?.onStart&&console.log(N(t.onStart,e))}function B(n,e){if(!H())return;let t=P(n);t?.onSuccess&&console.log(`${q.success} ${N(t.onSuccess,e)}`)}function T(n,e,t){let o=P(n);o?.onFailure&&console.error(`${q.failure} ${N(o.onFailure,t)}`),e&&console.error(` ${e}`)}function Q(n,e){return{command:n,operation:e}}var p=Q("objects","delete");async function Ce(n){J(p);let e=S(n,["bucket"]),t=S(n,["key"]);e||(T(p,"Bucket name is required"),process.exit(1)),t||(T(p,"Object key is required"),process.exit(1));let o=await $(),i=Array.isArray(t)?t:[t];for(let r of i){let{error:s}=await ye(r,{config:{...o,bucket:e}});s&&(T(p,s.message,{key:r}),process.exit(1)),B(p,{key:r})}}export{Ce as default};
1
+ import{a,b as g,c as r,g as m}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as i}from"../../chunk-JRALYIRA.js";import{b as f}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{remove as k}from"@tigrisdata/storage";var e=m("objects","delete");async function y(s){a(e);let n=i(s,["bucket"]),t=i(s,["key"]);n||(r(e,"Bucket name is required"),process.exit(1)),t||(r(e,"Object key is required"),process.exit(1));let p=await f(),u=Array.isArray(t)?t:[t];for(let o of u){let{error:c}=await k(o,{config:{...p,bucket:n}});c&&(r(e,c.message,{key:o}),process.exit(1)),g(e,{key:o})}}export{y as default};
@@ -1,2 +1 @@
1
- import{createWriteStream as Ae,writeFileSync as we}from"fs";import{Readable as Z}from"stream";import{pipeline as ee}from"stream/promises";import{extname as _e}from"path";function p(t,e,n){for(let o of e)if(t[o]!==void 0)return t[o];return n}import{S3Client as $e}from"@aws-sdk/client-s3";import{fromIni as le}from"@aws-sdk/credential-providers";import{homedir as b}from"os";import{join as f}from"path";import{readFileSync as oe,writeFileSync as ie,existsSync as y,mkdirSync as se}from"fs";import{loadSharedConfigFiles as re}from"@smithy/shared-ini-file-loader";import{chmod as ae}from"fs/promises";var l="https://t3.storage.dev",_="https://iam.storageapi.dev";var I=f(b(),".tigris"),C=f(I,"config.json");function ce(){y(I)||se(I,{recursive:!0,mode:448})}function c(){if(y(C))try{let t=oe(C,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function T(t){ce(),ie(C,JSON.stringify(t,null,2),{mode:384});try{await ae(C,384)}catch{}}async function E(t){let e=c();e.tokens=t,await T(e)}async function u(){return c().tokens||null}async function x(){let t=c();delete t.tokens,await T(t)}async function D(t){let e=c();e.organizations=t,await T(e)}function K(){return c().organizations||[]}function k(){return c().selectedOrganization||null}function L(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let s=process.env.TIGRIS_STORAGE_ENDPOINT||l;return{accessKeyId:o,secretAccessKey:i,endpoint:s}}let t=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!t||!e)return null;let n=process.env.AWS_ENDPOINT_URL_S3||l;return{accessKeyId:t,secretAccessKey:e,endpoint:n}}function z(){if(!process.env.AWS_PROFILE)return!1;let t=f(b(),".aws");return y(f(t,"credentials"))||y(f(t,"config"))}async function F(t){try{let{configFile:e}=await re(),n=e[t];return n?{endpoint:n.endpoint_url_s3||n.endpoint_url,iamEndpoint:n.endpoint_url_iam,region:n.region}:{}}catch{return{}}}function v(){let t=c();return t.temporaryCredentials||t.credentials||null}async function G(t){let e=c();e.loginMethod=t,await T(e)}function j(){return c().loginMethod||null}import A from"axios";import de from"open";function S(){let t=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||t?"auth-dev.tigris.dev":"auth.tigris.dev",n=process.env.AUTH0_CLIENT_ID||t?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||t?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:n,audience:o}}var U=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function W(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||l,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||_}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||l,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||_}}var P=class{config;baseUrl;constructor(){this.config=S(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await A.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 i=await this.pollForToken(o.device_code,o.interval||5);await E(i),G("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,n){let i=0;for(;i<60;){i++;try{let a=(await A.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(s){if(A.isAxiosError(s)&&s.response){let a=s.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(s.response.data?.error_description||"Authentication failed")}throw s}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await u();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 u(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await A.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,s={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 E(s),s}catch{throw await x(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await u();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"),s=JSON.parse(o)[U];if(!s)return;let a=s?.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;D(a)}catch{}}async getOrganizations(){return await this.getAccessToken(),K()}async logout(){await x()}async isAuthenticated(){return await u()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},O=null;function $(){return O||(O=new P),O}var w=W(),ge=S();async function pe(){return j()}async function q(){if(z()){let o=process.env.AWS_PROFILE||"default",i=await F(o),s=await le({profile:o})();return{accessKeyId:s.accessKeyId,secretAccessKey:s.secretAccessKey,endpoint:i.endpoint||w.endpoint||l,iamEndpoint:i.iamEndpoint||w.iamEndpoint}}let t=await pe();if(t==="oauth"){let i=await $().getAccessToken();if(!k())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:w.endpoint,organizationId:k()??void 0,iamEndpoint:w.iamEndpoint,authDomain:ge.domain}}if(t==="credentials"){let o=v();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let e=L();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let n=v();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{get as te}from"@tigrisdata/storage";import{readFileSync as fe,existsSync as ue}from"fs";import{join as Y,dirname as me}from"path";import{fileURLToPath as he}from"url";import*as V from"yaml";var ye=he(import.meta.url),Ce=me(ye),N=null;function Te(){let t=Ce;for(let e=0;e<5;e++){let n=Y(t,"specs.yaml");if(ue(n))return n;t=Y(t,"..")}throw new Error("Could not find specs.yaml")}function Se(){if(!N){let t=Te(),e=fe(t,"utf8");N=V.parse(e)}return N}function H(t,e){let o=Se().commands.find(i=>i.name===t);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var J={success:"\u2714",failure:"\u2716",hint:"\u2192"};function B(){return process.stdout.isTTY===!0}function M(t){let e=H(t.command,t.operation);if(e)return e.messages}function R(t,e){let n=t;return n=n.replace(/\\n/g,`
2
- `),e&&(n=n.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let s=e[i];return s!==void 0?String(s):`{{${i}}}`})),n}function X(t,e){if(!B())return;let n=M(t);n?.onStart&&console.log(R(n.onStart,e))}function m(t,e){if(!B())return;let n=M(t);n?.onSuccess&&console.log(`${J.success} ${R(n.onSuccess,e)}`)}function h(t,e,n){let o=M(t);o?.onFailure&&console.error(`${J.failure} ${R(o.onFailure,n)}`),e&&console.error(` ${e}`)}function Q(t,e){return{command:t,operation:e}}var d=Q("objects","get"),Ie=new Set([".js",".ts",".jsx",".tsx",".mjs",".cjs",".py",".rb",".php",".java",".go",".rs",".c",".cpp",".h",".hpp",".cs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".sql",".graphql",".gql",".json",".yaml",".yml",".toml",".ini",".cfg",".conf",".xml",".plist",".env",".properties",".html",".htm",".css",".scss",".sass",".less",".styl",".md",".markdown",".mdx",".rst",".txt",".text",".csv",".tsv",".log",".ejs",".hbs",".pug",".jade",".njk",".twig",".liquid",".svg",".gitignore",".dockerignore",".editorconfig"]);function Ee(t,e){let o=_e(e||t).toLowerCase();return Ie.has(o)?"string":"stream"}async function xe(t){X(d);let e=p(t,["bucket"]),n=p(t,["key"]),o=p(t,["output","o","O"]),i=p(t,["mode","m","M"]);e||(h(d,"Bucket name is required"),process.exit(1)),n||(h(d,"Object key is required"),process.exit(1));let s=await q();if((i||Ee(n,o))==="stream"){let{data:r,error:g}=await te(n,"stream",{config:{...s,bucket:e}});if(g&&(h(d,g.message),process.exit(1)),o){let ne=Ae(o);await ee(Z.fromWeb(r),ne),m(d,{key:n,output:o})}else await ee(Z.fromWeb(r),process.stdout),m(d)}else{let{data:r,error:g}=await te(n,"string",{config:{...s,bucket:e}});g&&(h(d,g.message),process.exit(1)),o?(we(o,r),m(d,{key:n,output:o})):(console.log(r),m(d))}}export{xe as default};
1
+ import{a as f,b as c,c as m,g as l}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as n}from"../../chunk-JRALYIRA.js";import{b as p}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{createWriteStream as j,writeFileSync as k}from"fs";import{Readable as d}from"stream";import{pipeline as u}from"stream/promises";import{extname as w}from"path";import{get as h}from"@tigrisdata/storage";var e=l("objects","get"),S=new Set([".js",".ts",".jsx",".tsx",".mjs",".cjs",".py",".rb",".php",".java",".go",".rs",".c",".cpp",".h",".hpp",".cs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".sql",".graphql",".gql",".json",".yaml",".yml",".toml",".ini",".cfg",".conf",".xml",".plist",".env",".properties",".html",".htm",".css",".scss",".sass",".less",".styl",".md",".markdown",".mdx",".rst",".txt",".text",".csv",".tsv",".log",".ejs",".hbs",".pug",".jade",".njk",".twig",".liquid",".svg",".gitignore",".dockerignore",".editorconfig"]);function y(r,o){let t=w(o||r).toLowerCase();return S.has(t)?"string":"stream"}async function q(r){f(e);let o=n(r,["bucket"]),s=n(r,["key"]),t=n(r,["output","o","O"]),x=n(r,["mode","m","M"]);o||(m(e,"Bucket name is required"),process.exit(1)),s||(m(e,"Object key is required"),process.exit(1));let g=await p();if((x||y(s,t))==="stream"){let{data:i,error:a}=await h(s,"stream",{config:{...g,bucket:o}});if(a&&(m(e,a.message),process.exit(1)),t){let b=j(t);await u(d.fromWeb(i),b),c(e,{key:s,output:t})}else await u(d.fromWeb(i),process.stdout),c(e)}else{let{data:i,error:a}=await h(s,"string",{config:{...g,bucket:o}});a&&(m(e,a.message),process.exit(1)),t?(k(t,i),c(e,{key:s,output:t})):(console.log(i),c(e))}}export{q as default};
@@ -1,7 +1 @@
1
- function m(e,n,t){for(let o of n)if(e[o]!==void 0)return e[o];return t}function ae(e){return JSON.stringify(e,null,2)}function ce(e,n=" "){return Object.entries(e).map(([t,o])=>`${n}<${t}>${o}</${t}>`).join(`
2
- `)}function de(e,n,t){let o=[`<${n}>`];return e.forEach(i=>{o.push(` <${t}>`),o.push(ce(i," ")),o.push(` </${t}>`)}),o.push(`</${n}>`),o.join(`
3
- `)}function F(e){if(e==null)return"";if(e instanceof Date)return L(e);if(typeof e=="string"){let n=new Date(e);if(!isNaN(n.getTime())&&e.includes("T"))return L(n)}return String(e)}function L(e){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(e)}function ue(e,n){return n.map(t=>{if(t.width)return t.width;let o=t.header.length,i=e.reduce((r,s)=>{let a=F(s[t.key]);return Math.max(r,a.length)},0);return Math.max(o,i)})}function pe(e,n){let t=[],o=ue(e,n),i="\u250C"+o.map(c=>"\u2500".repeat(c+2)).join("\u252C")+"\u2510",r="\u251C"+o.map(c=>"\u2500".repeat(c+2)).join("\u253C")+"\u2524",s="\u2514"+o.map(c=>"\u2500".repeat(c+2)).join("\u2534")+"\u2518";t.push(`
4
- `+i);let a="\u2502 "+n.map((c,p)=>c.header.padEnd(o[p])).join(" \u2502 ")+" \u2502";return t.push(a),t.push(r),e.forEach(c=>{let p=n.map((b,K)=>{let z=F(c[b.key]);return b.align==="right"?z.padStart(o[K]):z.padEnd(o[K])});t.push("\u2502 "+p.join(" \u2502 ")+" \u2502")}),t.push(s+`
5
- `),t.join(`
6
- `)}function j(e,n,t,o,i){switch(n){case"json":return ae(e);case"xml":return de(e,t,o);default:return pe(e,i)}}import{S3Client as Xe}from"@aws-sdk/client-s3";import{fromIni as Ce}from"@aws-sdk/credential-providers";import{homedir as G}from"os";import{join as g}from"path";import{readFileSync as ge,writeFileSync as le,existsSync as h,mkdirSync as fe}from"fs";import{loadSharedConfigFiles as me}from"@smithy/shared-ini-file-loader";import{chmod as he}from"fs/promises";var u="https://t3.storage.dev",I="https://iam.storageapi.dev";var x=g(G(),".tigris"),T=g(x,"config.json");function Te(){h(x)||fe(x,{recursive:!0,mode:448})}function d(){if(h(T))try{let e=ge(T,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function y(e){Te(),le(T,JSON.stringify(e,null,2),{mode:384});try{await he(T,384)}catch{}}async function k(e){let n=d();n.tokens=e,await y(n)}async function l(){return d().tokens||null}async function E(){let e=d();delete e.tokens,await y(e)}async function $(e){let n=d();n.organizations=e,await y(n)}function U(){return d().organizations||[]}function v(){return d().selectedOrganization||null}function B(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||u;return{accessKeyId:o,secretAccessKey:i,endpoint:r}}let e=process.env.AWS_ACCESS_KEY_ID,n=process.env.AWS_SECRET_ACCESS_KEY;if(!e||!n)return null;let t=process.env.AWS_ENDPOINT_URL_S3||u;return{accessKeyId:e,secretAccessKey:n,endpoint:t}}function W(){if(!process.env.AWS_PROFILE)return!1;let e=g(G(),".aws");return h(g(e,"credentials"))||h(g(e,"config"))}async function V(e){try{let{configFile:n}=await me(),t=n[e];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function O(){let e=d();return e.temporaryCredentials||e.credentials||null}async function Y(e){let n=d();n.loginMethod=e,await y(n)}function J(){return d().loginMethod||null}import S from"axios";import ye from"open";function C(){let e=process.env.TIGRIS_ENV==="development",n=process.env.AUTH0_DOMAIN||e?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||e?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||e?"https://tigris-api-dev":"https://tigris-os-api";return{domain:n,clientId:t,audience:o}}var q=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function H(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||u,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||I}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||u,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||I}}var M=class{config;baseUrl;constructor(){this.config=C(),this.baseUrl=`https://${this.config.domain}`}async login(n){let o=(await S.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;n?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await ye(o.verification_uri_complete)}catch{}n?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await k(i),Y("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(n,t){let i=0;for(;i<60;){i++;try{let s=(await S.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:n,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(S.isAxiosError(r)&&r.response){let s=r.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(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let n=await l();if(!n)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let t=300*1e3;return Date.now()+t>=n.expiresAt&&(n=await this.refreshAccessToken(n)),n.accessToken}async refreshAccessToken(n){let t=null;if(n?.refreshToken?t=n:t=await l(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await S.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 k(r),r}catch{throw await E(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let n=await l();if(!n||!n.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let t=n.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(n){if(n)try{let t=n.split(".")[1],o=Buffer.from(t,"base64").toString("utf8"),r=JSON.parse(o)[q];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;$(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),U()}async logout(){await E()}async isAuthenticated(){return await l()!==null}sleep(n){return new Promise(t=>setTimeout(t,n))}},P=null;function X(){return P||(P=new M),P}var w=H(),Se=C();async function we(){return J()}async function Q(){if(W()){let o=process.env.AWS_PROFILE||"default",i=await V(o),r=await Ce({profile:o})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||w.endpoint||u,iamEndpoint:i.iamEndpoint||w.iamEndpoint}}let e=await we();if(e==="oauth"){let i=await X().getAccessToken();if(!v())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:w.endpoint,organizationId:v()??void 0,iamEndpoint:w.iamEndpoint,authDomain:Se.domain}}if(e==="credentials"){let o=O();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let n=B();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};let t=O();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{list as Pe}from"@tigrisdata/storage";import{readFileSync as Ae,existsSync as _e}from"fs";import{join as Z,dirname as Ie}from"path";import{fileURLToPath as xe}from"url";import*as ee from"yaml";var ke=xe(import.meta.url),Ee=Ie(ke),N=null;function ve(){let e=Ee;for(let n=0;n<5;n++){let t=Z(e,"specs.yaml");if(_e(t))return t;e=Z(e,"..")}throw new Error("Could not find specs.yaml")}function Oe(){if(!N){let e=ve(),n=Ae(e,"utf8");N=ee.parse(n)}return N}function ne(e,n){let o=Oe().commands.find(i=>i.name===e);return o?n&&o.operations?o.operations.find(i=>i.name===n)||null:o:null}var te={success:"\u2714",failure:"\u2716",hint:"\u2192"};function D(){return process.stdout.isTTY===!0}function A(e){let n=ne(e.command,e.operation);if(n)return n.messages}function _(e,n){let t=e;return t=t.replace(/\\n/g,`
7
- `),n&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=n[i];return r!==void 0?String(r):`{{${i}}}`})),t}function oe(e,n){if(!D())return;let t=A(e);t?.onStart&&console.log(_(t.onStart,n))}function ie(e,n){if(!D())return;let t=A(e);t?.onSuccess&&console.log(`${te.success} ${_(t.onSuccess,n)}`)}function R(e,n,t){let o=A(e);o?.onFailure&&console.error(`${te.failure} ${_(o.onFailure,t)}`),n&&console.error(` ${n}`)}function re(e,n){if(!D())return;let t=A(e);t?.onEmpty&&console.log(_(t.onEmpty,n))}function se(e,n){return{command:e,operation:n}}var f=se("objects","list");async function Me(e){oe(f);let n=m(e,["bucket"]),t=m(e,["prefix","p","P"]),o=m(e,["format","f","F"],"table");n||(R(f,"Bucket name is required"),process.exit(1));let i=await Q(),{data:r,error:s}=await Pe({prefix:t||void 0,config:{...i,bucket:n}});if(s&&(R(f,s.message),process.exit(1)),!r.items||r.items.length===0){re(f);return}let a=r.items.map(p=>({key:p.name,size:Ne(p.size),modified:p.lastModified})),c=j(a,o,"objects","object",[{key:"key",header:"Key"},{key:"size",header:"Size"},{key:"modified",header:"Modified"}]);console.log(c),ie(f,{count:a.length})}function Ne(e){if(e===0)return"0 B";let n=["B","KB","MB","GB","TB"],t=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,t)).toFixed(t>0?1:0)} ${n[t]}`}export{Me as default};
1
+ import{a as d,b as u,c as s,d as g,g as l}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as m,f as p}from"../../chunk-HGIJOGCZ.js";import{a as e}from"../../chunk-JRALYIRA.js";import{b as a}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{list as h}from"@tigrisdata/storage";var t=l("objects","list");async function j(i){d(t);let n=e(i,["bucket"]),k=e(i,["prefix","p","P"]),b=e(i,["format","f","F"],"table");n||(s(t,"Bucket name is required"),process.exit(1));let y=await a(),{data:o,error:c}=await h({prefix:k||void 0,config:{...y,bucket:n}});if(c&&(s(t,c.message),process.exit(1)),!o.items||o.items.length===0){g(t);return}let f=o.items.map(r=>({key:r.name,size:m(r.size),modified:r.lastModified})),x=p(f,b,"objects","object",[{key:"key",header:"Key"},{key:"size",header:"Size"},{key:"modified",header:"Modified"}]);console.log(x),u(t,{count:f.length})}export{j as default};
@@ -1,7 +1 @@
1
- import{createReadStream as Ke,statSync as ze}from"fs";import{Readable as pe}from"stream";function f(e,t,n){for(let o of t)if(e[o]!==void 0)return e[o];return n}function fe(e){return JSON.stringify(e,null,2)}function ge(e,t=" "){return Object.entries(e).map(([n,o])=>`${t}<${n}>${o}</${n}>`).join(`
2
- `)}function me(e,t,n){let o=[`<${t}>`];return e.forEach(i=>{o.push(` <${n}>`),o.push(ge(i," ")),o.push(` </${n}>`)}),o.push(`</${t}>`),o.join(`
3
- `)}function G(e){if(e==null)return"";if(e instanceof Date)return j(e);if(typeof e=="string"){let t=new Date(e);if(!isNaN(t.getTime())&&e.includes("T"))return j(t)}return String(e)}function j(e){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(e)}function he(e,t){return t.map(n=>{if(n.width)return n.width;let o=n.header.length,i=e.reduce((r,s)=>{let a=G(s[n.key]);return Math.max(r,a.length)},0);return Math.max(o,i)})}function Te(e,t){let n=[],o=he(e,t),i="\u250C"+o.map(c=>"\u2500".repeat(c+2)).join("\u252C")+"\u2510",r="\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
- `+i);let a="\u2502 "+t.map((c,d)=>c.header.padEnd(o[d])).join(" \u2502 ")+" \u2502";return n.push(a),n.push(r),e.forEach(c=>{let d=t.map((y,C)=>{let l=G(c[y.key]);return y.align==="right"?l.padStart(o[C]):l.padEnd(o[C])});n.push("\u2502 "+d.join(" \u2502 ")+" \u2502")}),n.push(s+`
5
- `),n.join(`
6
- `)}function U(e,t,n,o,i){switch(t){case"json":return fe(e);case"xml":return me(e,n,o);default:return Te(e,i)}}import{S3Client as it}from"@aws-sdk/client-s3";import{fromIni as xe}from"@aws-sdk/credential-providers";import{homedir as W}from"os";import{join as h}from"path";import{readFileSync as ye,writeFileSync as Ce,existsSync as w,mkdirSync as Se}from"fs";import{loadSharedConfigFiles as we}from"@smithy/shared-ini-file-loader";import{chmod as Ae}from"fs/promises";var u="https://t3.storage.dev",v="https://iam.storageapi.dev";var O=h(W(),".tigris"),A=h(O,"config.json");function _e(){w(O)||Se(O,{recursive:!0,mode:448})}function p(){if(w(A))try{let e=ye(A,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function _(e){_e(),Ce(A,JSON.stringify(e,null,2),{mode:384});try{await Ae(A,384)}catch{}}async function P(e){let t=p();t.tokens=e,await _(t)}async function T(){return p().tokens||null}async function b(){let e=p();delete e.tokens,await _(e)}async function B(e){let t=p();t.organizations=e,await _(t)}function V(){return p().organizations||[]}function M(){return p().selectedOrganization||null}function Y(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||u;return{accessKeyId:o,secretAccessKey:i,endpoint:r}}let e=process.env.AWS_ACCESS_KEY_ID,t=process.env.AWS_SECRET_ACCESS_KEY;if(!e||!t)return null;let n=process.env.AWS_ENDPOINT_URL_S3||u;return{accessKeyId:e,secretAccessKey:t,endpoint:n}}function q(){if(!process.env.AWS_PROFILE)return!1;let e=h(W(),".aws");return w(h(e,"credentials"))||w(h(e,"config"))}async function J(e){try{let{configFile:t}=await we(),n=t[e];return n?{endpoint:n.endpoint_url_s3||n.endpoint_url,iamEndpoint:n.endpoint_url_iam,region:n.region}:{}}catch{return{}}}function N(){let e=p();return e.temporaryCredentials||e.credentials||null}async function H(e){let t=p();t.loginMethod=e,await _(t)}function X(){return p().loginMethod||null}import x from"axios";import Ie from"open";function I(){let e=process.env.TIGRIS_ENV==="development",t=process.env.AUTH0_DOMAIN||e?"auth-dev.tigris.dev":"auth.tigris.dev",n=process.env.AUTH0_CLIENT_ID||e?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||e?"https://tigris-api-dev":"https://tigris-os-api";return{domain:t,clientId:n,audience:o}}var Q=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function Z(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||u,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||v}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||u,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||v}}var D=class{config;baseUrl;constructor(){this.config=I(),this.baseUrl=`https://${this.config.domain}`}async login(t){let o=(await x.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?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await Ie(o.verification_uri_complete)}catch{}t?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await P(i),H("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(t,n){let i=0;for(;i<60;){i++;try{let s=(await x.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,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(x.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 t=await T();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 T(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await x.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 P(r),r}catch{throw await b(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let t=await T();if(!t||!t.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let n=t.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(t){if(t)try{let n=t.split(".")[1],o=Buffer.from(n,"base64").toString("utf8"),r=JSON.parse(o)[Q];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;B(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),V()}async logout(){await b()}async isAuthenticated(){return await T()!==null}sleep(t){return new Promise(n=>setTimeout(n,t))}},R=null;function ee(){return R||(R=new D),R}var k=Z(),ke=I();async function Ee(){return X()}async function te(){if(q()){let o=process.env.AWS_PROFILE||"default",i=await J(o),r=await xe({profile:o})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||k.endpoint||u,iamEndpoint:i.iamEndpoint||k.iamEndpoint}}let e=await Ee();if(e==="oauth"){let i=await ee().getAccessToken();if(!M())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:k.endpoint,organizationId:M()??void 0,iamEndpoint:k.iamEndpoint,authDomain:ke.domain}}if(e==="credentials"){let o=N();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let t=Y();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};let n=N();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{put as Fe}from"@tigrisdata/storage";import{readFileSync as ve,existsSync as Oe}from"fs";import{join as ne,dirname as Pe}from"path";import{fileURLToPath as be}from"url";import*as oe from"yaml";var Me=be(import.meta.url),Ne=Pe(Me),K=null;function Re(){let e=Ne;for(let t=0;t<5;t++){let n=ne(e,"specs.yaml");if(Oe(n))return n;e=ne(e,"..")}throw new Error("Could not find specs.yaml")}function De(){if(!K){let e=Re(),t=ve(e,"utf8");K=oe.parse(t)}return K}function ie(e,t){let o=De().commands.find(i=>i.name===e);return o?t&&o.operations?o.operations.find(i=>i.name===t)||null:o:null}var re={success:"\u2714",failure:"\u2716",hint:"\u2192"};function se(){return process.stdout.isTTY===!0}function z(e){let t=ie(e.command,e.operation);if(t)return t.messages}function F(e,t){let n=e;return n=n.replace(/\\n/g,`
7
- `),t&&(n=n.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=t[i];return r!==void 0?String(r):`{{${i}}}`})),n}function ae(e,t){if(!se())return;let n=z(e);n?.onStart&&console.log(F(n.onStart,t))}function ce(e,t){if(!se())return;let n=z(e);n?.onSuccess&&console.log(`${re.success} ${F(n.onSuccess,t)}`)}function m(e,t,n){let o=z(e);o?.onFailure&&console.error(`${re.failure} ${F(o.onFailure,n)}`),t&&console.error(` ${t}`)}function de(e,t){return{command:e,operation:t}}var g=de("objects","put");async function Le(e){ae(g);let t=f(e,["bucket"]),n=f(e,["key"]),o=f(e,["file"]),i=f(e,["access","a","A"],"private"),r=f(e,["content-type","contentType","t","T"]),s=f(e,["format","f","F"],"table");t||(m(g,"Bucket name is required"),process.exit(1)),n||(m(g,"Object key is required"),process.exit(1));let a=!process.stdin.isTTY;!o&&!a&&(m(g,"File path is required (or pipe data via stdin)"),process.exit(1));let c,d;if(o){try{d=ze(o).size}catch{m(g,`File not found: ${o}`),process.exit(1)}let S=Ke(o);c=pe.toWeb(S)}else c=pe.toWeb(process.stdin);let y=await te(),C=!o||d!==void 0&&d>100*1024*1024,{data:l,error:L}=await Fe(n,c,{access:i==="public"?"public":"private",contentType:r,multipart:C,onUploadProgress:({loaded:S,percentage:$})=>{d!==void 0&&d>0?process.stdout.write(`\rUploading: ${E(S)} / ${E(d)} (${$}%)`):process.stdout.write(`\rUploading: ${E(S)}`)},config:{...y,bucket:t}});process.stdout.write("\r"+" ".repeat(60)+"\r"),L&&(m(g,L.message),process.exit(1));let ue=[{path:l.path,size:E(l.size??d??0),contentType:l.contentType||"-",modified:l.modified}],le=U(ue,s,"objects","object",[{key:"path",header:"Path"},{key:"size",header:"Size"},{key:"contentType",header:"Content-Type"},{key:"modified",header:"Modified"}]);console.log(le),ce(g,{key:n,bucket:t})}function E(e){if(e===0)return"0 B";let t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n>0?1:0)} ${t[n]}`}export{Le as default};
1
+ import{a as b,b as y,c as o,g as S}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as n,f as g}from"../../chunk-HGIJOGCZ.js";import{a as t}from"../../chunk-JRALYIRA.js";import{b as l}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{createReadStream as F,statSync as O}from"fs";import{Readable as h}from"stream";import{put as q}from"@tigrisdata/storage";var r=S("objects","put");async function v(s){b(r);let p=t(s,["bucket"]),d=t(s,["key"]),i=t(s,["file"]),k=t(s,["access","a","A"],"private"),T=t(s,["content-type","contentType","t","T"]),x=t(s,["format","f","F"],"table");p||(o(r,"Bucket name is required"),process.exit(1)),d||(o(r,"Object key is required"),process.exit(1));let z=!process.stdin.isTTY;!i&&!z&&(o(r,"File path is required (or pipe data via stdin)"),process.exit(1));let f,e;if(i){try{e=O(i).size}catch{o(r,`File not found: ${i}`),process.exit(1)}let c=F(i);f=h.toWeb(c)}else f=h.toWeb(process.stdin);let w=await l(),R=!i||e!==void 0&&e>100*1024*1024,{data:a,error:u}=await q(d,f,{access:k==="public"?"public":"private",contentType:T,multipart:R,onUploadProgress:({loaded:c,percentage:m})=>{e!==void 0&&e>0?process.stdout.write(`\rUploading: ${n(c)} / ${n(e)} (${m}%)`):process.stdout.write(`\rUploading: ${n(c)}`)},config:{...w,bucket:p}});process.stdout.write("\r"+" ".repeat(60)+"\r"),u&&(o(r,u.message),process.exit(1));let j=[{path:a.path,size:n(a.size??e??0),contentType:a.contentType||"-",modified:a.modified}],$=g(j,x,"objects","object",[{key:"path",header:"Path"},{key:"size",header:"Size"},{key:"contentType",header:"Content-Type"},{key:"modified",header:"Modified"}]);console.log($),y(r,{key:d,bucket:p})}export{v as default};
@@ -1,5 +1,4 @@
1
- import{createOrganization as ye}from"@tigrisdata/iam";function K(n,e,t){for(let o of e)if(n[o]!==void 0)return n[o];return t}import{S3Client as ze}from"@aws-sdk/client-s3";import{fromIni as ae}from"@aws-sdk/credential-providers";import{homedir as b}from"os";import{join as l}from"path";import{readFileSync as ee,writeFileSync as ne,existsSync as f,mkdirSync as te}from"fs";import{loadSharedConfigFiles as oe}from"@smithy/shared-ini-file-loader";import{chmod as ie}from"fs/promises";var d="https://t3.storage.dev",_="https://iam.storageapi.dev";var w=l(b(),".tigris"),u=l(w,"config.json");function re(){f(w)||te(w,{recursive:!0,mode:448})}function c(){if(f(u))try{let n=ee(u,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function m(n){re(),ne(u,JSON.stringify(n,null,2),{mode:384});try{await ie(u,384)}catch{}}async function I(n){let e=c();e.tokens=n,await m(e)}async function g(){return c().tokens||null}async function E(){let n=c();delete n.tokens,await m(n)}async function z(n){let e=c();e.organizations=n,await m(e)}function L(){return c().organizations||[]}function v(){return c().selectedOrganization||null}function x(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:o,secretAccessKey:i,endpoint:r}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let t=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:n,secretAccessKey:e,endpoint:t}}function G(){if(!process.env.AWS_PROFILE)return!1;let n=l(b(),".aws");return f(l(n,"credentials"))||f(l(n,"config"))}async function F(n){try{let{configFile:e}=await oe(),t=e[n];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function U(){let n=c();return x()||n.temporaryCredentials||n.credentials||null}function k(){let n=c();return n.temporaryCredentials||n.credentials||null}async function $(n){let e=c();e.loginMethod=n,await m(e)}function h(){return c().loginMethod||null}import y from"axios";import se from"open";function C(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:t,audience:o}}var Y=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function j(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||_}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||_}}var P=class{config;baseUrl;constructor(){this.config=C(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await y.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 se(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await I(i),$("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,t){let i=0;for(;i<60;){i++;try{let s=(await y.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(y.isAxiosError(r)&&r.response){let s=r.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(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 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 g(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await y.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 I(r),r}catch{throw await E(),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 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)[Y];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;z(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),L()}async logout(){await E()}async isAuthenticated(){return await g()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},O=null;function W(){return O||(O=new P),O}var T=j(),ce=C();async function de(){return h()}async function V(){if(G()){let o=process.env.AWS_PROFILE||"default",i=await F(o),r=await ae({profile:o})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||T.endpoint||d,iamEndpoint:i.iamEndpoint||T.iamEndpoint}}let n=await de();if(n==="oauth"){let i=await W().getAccessToken();if(!v())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:T.endpoint,organizationId:v()??void 0,iamEndpoint:T.iamEndpoint,authDomain:ce.domain}}if(n==="credentials"){let o=k();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let e=x();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let t=k();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{readFileSync as le,existsSync as ge}from"fs";import{join as H,dirname as pe}from"path";import{fileURLToPath as fe}from"url";import*as q from"yaml";var ue=fe(import.meta.url),me=pe(ue),N=null;function he(){let n=me;for(let e=0;e<5;e++){let t=H(n,"specs.yaml");if(ge(t))return t;n=H(n,"..")}throw new Error("Could not find specs.yaml")}function Ce(){if(!N){let n=he(),e=le(n,"utf8");N=q.parse(e)}return N}function J(n,e){let o=Ce().commands.find(i=>i.name===n);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var M={success:"\u2714",failure:"\u2716",hint:"\u2192"};function D(){return process.stdout.isTTY===!0}function S(n){let e=J(n.command,n.operation);if(e)return e.messages}function A(n,e){let t=n;return t=t.replace(/\\n/g,`
2
- `),e&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=e[i];return r!==void 0?String(r):`{{${i}}}`})),t}function B(n,e){if(!D())return;let t=S(n);t?.onStart&&console.log(A(t.onStart,e))}function Q(n,e){if(!D())return;let t=S(n);t?.onSuccess&&console.log(`${M.success} ${A(t.onSuccess,e)}`)}function R(n,e,t){let o=S(n);o?.onFailure&&console.error(`${M.failure} ${A(o.onFailure,t)}`),e&&console.error(` ${e}`)}function X(n,e){if(!D())return;let t=S(n);t?.hint&&console.log(`${M.hint} ${A(t.hint,e)}`)}function Z(n,e){return{command:n,operation:e}}var p=Z("organizations","create");async function Te(n){if(B(p),h()!=="oauth"){U()?console.log(`You are using access key credentials, which belong to a single organization.
1
+ import{a as g,b as c,c as o,f as l,g as u}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as e}from"../../chunk-JRALYIRA.js";import{b as s}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import{k as r,s as a}from"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{createOrganization as h}from"@tigrisdata/iam";var i=u("organizations","create");async function w(m){if(g(i),a()!=="oauth"){r()?console.log(`You are using access key credentials, which belong to a single organization.
3
2
  Organization creation is only available with OAuth login.
4
3
 
5
- Run "tigris login" to login with your Tigris account.`):console.log('Not authenticated. Please run "tigris login" to login with your Tigris account.');return}let t=K(n,["name","N"]);t||(R(p,"Organization name is required"),process.exit(1));let o=await V(),{data:i,error:r}=await ye(t,{config:o});r&&(R(p,r.message),process.exit(1));let s=i.id;Q(p,{name:t,id:s}),X(p,{name:t})}export{Te as default};
4
+ Run "tigris login" to login with your Tigris account.`):console.log('Not authenticated. Please run "tigris login" to login with your Tigris account.');return}let t=e(m,["name","N"]);t||(o(i,"Organization name is required"),process.exit(1));let f=await s(),{data:p,error:n}=await h(t,{config:f});n&&(o(i,n.message),process.exit(1));let d=p.id;c(i,{name:t,id:d}),l(i,{name:t})}export{w as default};
@@ -1,10 +1,4 @@
1
- import{listOrganizations as Ke}from"@tigrisdata/iam";function j(e,n,t){for(let i of n)if(e[i]!==void 0)return e[i];return t}function pe(e){return JSON.stringify(e,null,2)}function fe(e,n=" "){return Object.entries(e).map(([t,i])=>`${n}<${t}>${i}</${t}>`).join(`
2
- `)}function me(e,n,t){let i=[`<${n}>`];return e.forEach(o=>{i.push(` <${t}>`),i.push(fe(o," ")),i.push(` </${t}>`)}),i.push(`</${n}>`),i.join(`
3
- `)}function W(e){if(e==null)return"";if(e instanceof Date)return U(e);if(typeof e=="string"){let n=new Date(e);if(!isNaN(n.getTime())&&e.includes("T"))return U(n)}return String(e)}function U(e){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(e)}function he(e,n){return n.map(t=>{if(t.width)return t.width;let i=t.header.length,o=e.reduce((r,s)=>{let a=W(s[t.key]);return Math.max(r,a.length)},0);return Math.max(i,o)})}function ye(e,n){let t=[],i=he(e,n),o="\u250C"+i.map(c=>"\u2500".repeat(c+2)).join("\u252C")+"\u2510",r="\u251C"+i.map(c=>"\u2500".repeat(c+2)).join("\u253C")+"\u2524",s="\u2514"+i.map(c=>"\u2500".repeat(c+2)).join("\u2534")+"\u2518";t.push(`
4
- `+o);let a="\u2502 "+n.map((c,p)=>c.header.padEnd(i[p])).join(" \u2502 ")+" \u2502";return t.push(a),t.push(r),e.forEach(c=>{let p=n.map((l,k)=>{let O=W(c[l.key]);return l.align==="right"?O.padStart(i[k]):O.padEnd(i[k])});t.push("\u2502 "+p.join(" \u2502 ")+" \u2502")}),t.push(s+`
5
- `),t.join(`
6
- `)}function V(e,n,t,i,o){switch(n){case"json":return pe(e);case"xml":return me(e,t,i);default:return ye(e,o)}}import{S3Client as on}from"@aws-sdk/client-s3";import{fromIni as xe}from"@aws-sdk/credential-providers";import{homedir as Y}from"os";import{join as f}from"path";import{readFileSync as Te,writeFileSync as Ce,existsSync as C,mkdirSync as we}from"fs";import{loadSharedConfigFiles as Se}from"@smithy/shared-ini-file-loader";import{chmod as Ae}from"fs/promises";var u="https://t3.storage.dev",v="https://iam.storageapi.dev";var P=f(Y(),".tigris"),w=f(P,"config.json");function _e(){C(P)||we(P,{recursive:!0,mode:448})}function d(){if(C(w))try{let e=Te(w,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function m(e){_e(),Ce(w,JSON.stringify(e,null,2),{mode:384});try{await Ae(w,384)}catch{}}async function N(e){let n=d();n.tokens=e,await m(n)}async function h(){return d().tokens||null}async function M(){let e=d();delete e.tokens,await m(e)}async function J(e){let n=d();n.organizations=e,await m(n)}function q(){return d().organizations||[]}async function B(e){let n=d();n.selectedOrganization=e,await m(n)}function y(){return d().selectedOrganization||null}function D(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let i=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,o=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!i||!o)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||u;return{accessKeyId:i,secretAccessKey:o,endpoint:r}}let e=process.env.AWS_ACCESS_KEY_ID,n=process.env.AWS_SECRET_ACCESS_KEY;if(!e||!n)return null;let t=process.env.AWS_ENDPOINT_URL_S3||u;return{accessKeyId:e,secretAccessKey:n,endpoint:t}}function H(){if(!process.env.AWS_PROFILE)return!1;let e=f(Y(),".aws");return C(f(e,"credentials"))||C(f(e,"config"))}async function X(e){try{let{configFile:n}=await Se(),t=n[e];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function Q(){let e=d();return D()||e.temporaryCredentials||e.credentials||null}function R(){let e=d();return e.temporaryCredentials||e.credentials||null}async function Z(e){let n=d();n.loginMethod=e,await m(n)}function S(){return d().loginMethod||null}import _ from"axios";import Ie from"open";function A(){let e=process.env.TIGRIS_ENV==="development",n=process.env.AUTH0_DOMAIN||e?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||e?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",i=process.env.AUTH0_AUDIENCE||e?"https://tigris-api-dev":"https://tigris-os-api";return{domain:n,clientId:t,audience:i}}var ee=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function ne(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||u,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||v}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||u,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||v}}var K=class{config;baseUrl;constructor(){this.config=A(),this.baseUrl=`https://${this.config.domain}`}async login(n){let i=(await _.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;n?.onDeviceCode?.(i.user_code,i.verification_uri),await this.sleep(2e3);try{await Ie(i.verification_uri_complete)}catch{}n?.onWaiting?.();let o=await this.pollForToken(i.device_code,i.interval||5);await N(o),Z("oauth"),await this.extractAndStoreOrganizations(o.idToken)}async pollForToken(n,t){let o=0;for(;o<60;){o++;try{let s=(await _.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:n,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(_.isAxiosError(r)&&r.response){let s=r.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(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let n=await h();if(!n)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let t=300*1e3;return Date.now()+t>=n.expiresAt&&(n=await this.refreshAccessToken(n)),n.accessToken}async refreshAccessToken(n){let t=null;if(n?.refreshToken?t=n:t=await h(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let o=(await _.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:o.access_token,refreshToken:o.refresh_token||t.refreshToken,idToken:o.id_token||t.idToken,expiresAt:Date.now()+(o.expires_in||3600)*1e3};return await N(r),r}catch{throw await M(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let n=await h();if(!n||!n.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let t=n.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(n){if(n)try{let t=n.split(".")[1],i=Buffer.from(t,"base64").toString("utf8"),r=JSON.parse(i)[ee];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;J(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),q()}async logout(){await M()}async isAuthenticated(){return await h()!==null}sleep(n){return new Promise(t=>setTimeout(t,n))}},b=null;function te(){return b||(b=new K),b}var I=ne(),Ee=A();async function ke(){return S()}async function ie(){if(H()){let i=process.env.AWS_PROFILE||"default",o=await X(i),r=await xe({profile:i})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:o.endpoint||I.endpoint||u,iamEndpoint:o.iamEndpoint||I.iamEndpoint}}let e=await ke();if(e==="oauth"){let o=await te().getAccessToken();if(!y())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:o,accessKeyId:"",secretAccessKey:"",endpoint:I.endpoint,organizationId:y()??void 0,iamEndpoint:I.iamEndpoint,authDomain:Ee.domain}}if(e==="credentials"){let i=R();if(i)return{accessKeyId:i.accessKeyId,secretAccessKey:i.secretAccessKey,endpoint:i.endpoint}}let n=D();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};let t=R();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import ze from"enquirer";import{readFileSync as Oe,existsSync as ve}from"fs";import{join as oe,dirname as Pe}from"path";import{fileURLToPath as Ne}from"url";import*as re from"yaml";var Me=Ne(import.meta.url),De=Pe(Me),z=null;function Re(){let e=De;for(let n=0;n<5;n++){let t=oe(e,"specs.yaml");if(ve(t))return t;e=oe(e,"..")}throw new Error("Could not find specs.yaml")}function be(){if(!z){let e=Re(),n=Oe(e,"utf8");z=re.parse(n)}return z}function se(e,n){let i=be().commands.find(o=>o.name===e);return i?n&&i.operations?i.operations.find(o=>o.name===n)||null:i:null}var ae={success:"\u2714",failure:"\u2716",hint:"\u2192"};function L(){return process.stdout.isTTY===!0}function x(e){let n=se(e.command,e.operation);if(n)return n.messages}function E(e,n){let t=e;return t=t.replace(/\\n/g,`
7
- `),n&&(t=t.replace(/\{\{(\w+)\}\}/g,(i,o)=>{let r=n[o];return r!==void 0?String(r):`{{${o}}}`})),t}function ce(e,n){if(!L())return;let t=x(e);t?.onStart&&console.log(E(t.onStart,n))}function F(e,n){if(!L())return;let t=x(e);t?.onSuccess&&console.log(`${ae.success} ${E(t.onSuccess,n)}`)}function de(e,n,t){let i=x(e);i?.onFailure&&console.error(`${ae.failure} ${E(i.onFailure,t)}`),n&&console.error(` ${n}`)}function ge(e,n){if(!L())return;let t=x(e);t?.onEmpty&&console.log(E(t.onEmpty,n))}function le(e,n){return{command:e,operation:n}}var T=le("organizations","list");async function Le(e){if(ce(T),S()!=="oauth"){Q()?console.log(`You are using access key credentials, which belong to a single organization.
1
+ import{a as w,b as a,c as y,d as O,g as S}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{f as z}from"../../chunk-HGIJOGCZ.js";import{a as d}from"../../chunk-JRALYIRA.js";import{b as h}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import{f as m,g as u,k as p,s as f}from"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{listOrganizations as b}from"@tigrisdata/iam";import C from"enquirer";var i=S("organizations","list");async function E(k){if(w(i),f()!=="oauth"){p()?console.log(`You are using access key credentials, which belong to a single organization.
8
2
  Organization listing and selection is only available with OAuth login.
9
3
 
10
- Run "tigris login" to login with your Tigris account.`):console.log('Not authenticated. Please run "tigris login" to login with your Tigris account.');return}let t=j(e,["format","f","F"],"select"),i=await ie(),{data:o,error:r}=await Ke({config:i});r&&(de(T,r.message),process.exit(1));let s=o?.organizations??[];if(s.length===0){ge(T);return}let a=y();if(t==="select"){let l=s.map(g=>({name:g.id,message:`${g.name} (${g.id})`,hint:g.id===a?"currently selected":void 0})),G=(await ze.prompt({type:"select",name:"organization",message:"Select an organization:",choices:l.map(g=>g.message),initial:a?s.findIndex(g=>g.id===a):0})).organization.match(/\(([^)]+)\)$/),$=G?G[1]:s[0].id;await B($);let ue=s.find(g=>g.id===$);F(T,{name:ue?.name});return}let c=s.map(l=>({id:l.id,name:l.name,slug:l.slug,selected:l.id===a?"*":""})),p=V(c,t,"organizations","organization",[{key:"selected",header:" ",width:1},{key:"id",header:"ID"},{key:"name",header:"Name"},{key:"slug",header:"Slug"}]);console.log(p),F(T,{count:c.length})}export{Le as default};
4
+ Run "tigris login" to login with your Tigris account.`):console.log('Not authenticated. Please run "tigris login" to login with your Tigris account.');return}let s=d(k,["format","f","F"],"select"),x=await h(),{data:I,error:r}=await b({config:x});r&&(y(i,r.message),process.exit(1));let e=I?.organizations??[];if(e.length===0){O(i);return}let o=u();if(s==="select"){let n=e.map(t=>({name:t.id,message:`${t.name} (${t.id})`,hint:t.id===o?"currently selected":void 0})),g=(await C.prompt({type:"select",name:"organization",message:"Select an organization:",choices:n.map(t=>t.message),initial:o?e.findIndex(t=>t.id===o):0})).organization.match(/\(([^)]+)\)$/),l=g?g[1]:e[0].id;await m(l);let $=e.find(t=>t.id===l);a(i,{name:$?.name});return}let c=e.map(n=>({id:n.id,name:n.name,slug:n.slug,selected:n.id===o?"*":""})),M=z(c,s,"organizations","organization",[{key:"selected",header:" ",width:1},{key:"id",header:"ID"},{key:"name",header:"Name"},{key:"slug",header:"Slug"}]);console.log(M),a(i,{count:c.length})}export{E as default};
@@ -1,9 +1,8 @@
1
- import{listOrganizations as Se}from"@tigrisdata/iam";function K(n,e,t){for(let o of e)if(n[o]!==void 0)return n[o];return t}import{S3Client as Ge}from"@aws-sdk/client-s3";import{fromIni as de}from"@aws-sdk/credential-providers";import{homedir as b}from"os";import{join as l}from"path";import{readFileSync as te,writeFileSync as oe,existsSync as m,mkdirSync as ie}from"fs";import{loadSharedConfigFiles as se}from"@smithy/shared-ini-file-loader";import{chmod as re}from"fs/promises";var d="https://t3.storage.dev",_="https://iam.storageapi.dev";var w=l(b(),".tigris"),h=l(w,"config.json");function ae(){m(w)||ie(w,{recursive:!0,mode:448})}function c(){if(m(h))try{let n=te(h,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function g(n){ae(),oe(h,JSON.stringify(n,null,2),{mode:384});try{await re(h,384)}catch{}}async function I(n){let e=c();e.tokens=n,await g(e)}async function p(){return c().tokens||null}async function E(){let n=c();delete n.tokens,await g(n)}async function z(n){let e=c();e.organizations=n,await g(e)}function L(){return c().organizations||[]}async function G(n){let e=c();e.selectedOrganization=n,await g(e)}function v(){return c().selectedOrganization||null}function x(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let s=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:o,secretAccessKey:i,endpoint:s}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let t=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:n,secretAccessKey:e,endpoint:t}}function F(){if(!process.env.AWS_PROFILE)return!1;let n=l(b(),".aws");return m(l(n,"credentials"))||m(l(n,"config"))}async function U(n){try{let{configFile:e}=await se(),t=e[n];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function $(){let n=c();return x()||n.temporaryCredentials||n.credentials||null}function k(){let n=c();return n.temporaryCredentials||n.credentials||null}async function j(n){let e=c();e.loginMethod=n,await g(e)}function C(){return c().loginMethod||null}import T from"axios";import ce from"open";function y(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:t,audience:o}}var Y=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function W(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||_}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||_}}var P=class{config;baseUrl;constructor(){this.config=y(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(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;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 I(i),j("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,t){let i=0;for(;i<60;){i++;try{let a=(await T.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(s){if(T.isAxiosError(s)&&s.response){let a=s.response.data?.error;if(a==="authorization_pending"){await this.sleep(t*1e3);continue}if(a==="slow_down"){t+=5,await this.sleep(t*1e3);continue}throw new Error(s.response.data?.error_description||"Authentication failed")}throw s}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await p();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 p(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await T.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,s={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 I(s),s}catch{throw await E(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await p();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"),s=JSON.parse(o)[Y];if(!s)return;let a=s?.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;z(a)}catch{}}async getOrganizations(){return await this.getAccessToken(),L()}async logout(){await E()}async isAuthenticated(){return await p()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},O=null;function V(){return O||(O=new P),O}var S=W(),le=y();async function ge(){return C()}async function q(){if(F()){let o=process.env.AWS_PROFILE||"default",i=await U(o),s=await de({profile:o})();return{accessKeyId:s.accessKeyId,secretAccessKey:s.secretAccessKey,endpoint:i.endpoint||S.endpoint||d,iamEndpoint:i.iamEndpoint||S.iamEndpoint}}let n=await ge();if(n==="oauth"){let i=await V().getAccessToken();if(!v())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:S.endpoint,organizationId:v()??void 0,iamEndpoint:S.iamEndpoint,authDomain:le.domain}}if(n==="credentials"){let o=k();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let e=x();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let t=k();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{readFileSync as pe,existsSync as fe}from"fs";import{join as H,dirname as ue}from"path";import{fileURLToPath as me}from"url";import*as J from"yaml";var he=me(import.meta.url),Ce=ue(he),N=null;function ye(){let n=Ce;for(let e=0;e<5;e++){let t=H(n,"specs.yaml");if(fe(t))return t;n=H(n,"..")}throw new Error("Could not find specs.yaml")}function Te(){if(!N){let n=ye(),e=pe(n,"utf8");N=J.parse(e)}return N}function B(n,e){let o=Te().commands.find(i=>i.name===n);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var Q={success:"\u2714",failure:"\u2716",hint:"\u2192"};function X(){return process.stdout.isTTY===!0}function M(n){let e=B(n.command,n.operation);if(e)return e.messages}function D(n,e){let t=n;return t=t.replace(/\\n/g,`
2
- `),e&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let s=e[i];return s!==void 0?String(s):`{{${i}}}`})),t}function Z(n,e){if(!X())return;let t=M(n);t?.onStart&&console.log(D(t.onStart,e))}function ee(n,e){if(!X())return;let t=M(n);t?.onSuccess&&console.log(`${Q.success} ${D(t.onSuccess,e)}`)}function A(n,e,t){let o=M(n);o?.onFailure&&console.error(`${Q.failure} ${D(o.onFailure,t)}`),e&&console.error(` ${e}`)}function ne(n,e){return{command:n,operation:e}}var f=ne("organizations","select");async function Ae(n){if(Z(f),C()!=="oauth"){$()?console.log(`You are using access key credentials, which belong to a single organization.
1
+ import{a as d,b as f,c as t,g as p}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as g}from"../../chunk-JRALYIRA.js";import{b as u}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import{f as c,k as l,s as m}from"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{listOrganizations as O}from"@tigrisdata/iam";var i=p("organizations","select");async function x(h){if(d(i),m()!=="oauth"){l()?console.log(`You are using access key credentials, which belong to a single organization.
3
2
  Organization selection is only available with OAuth login.
4
3
 
5
- Run "tigris login" to login with your Tigris account.`):console.log('Not authenticated. Please run "tigris login" to login with your Tigris account.');return}let t=K(n,["name","N"]);t||(A(f,"Organization name or ID is required"),process.exit(1));let o=await q(),{data:i,error:s}=await Se({config:o});s&&(A(f,s.message),process.exit(1));let a=i?.organizations??[],r=a.find(u=>u.id===t||u.name===t);if(!r){let u=a.map(R=>` - ${R.name} (${R.id})`).join(`
6
- `);A(f,`Organization "${t}" not found
4
+ Run "tigris login" to login with your Tigris account.`):console.log('Not authenticated. Please run "tigris login" to login with your Tigris account.');return}let n=g(h,["name","N"]);n||(t(i,"Organization name or ID is required"),process.exit(1));let z=await u(),{data:w,error:a}=await O({config:z});a&&(t(i,a.message),process.exit(1));let r=w?.organizations??[],e=r.find(o=>o.id===n||o.name===n);if(!e){let o=r.map(s=>` - ${s.name} (${s.id})`).join(`
5
+ `);t(i,`Organization "${n}" not found
7
6
 
8
7
  Available organizations:
9
- ${u}`),process.exit(1)}await G(r.id),ee(f,{name:r.name})}export{Ae as default};
8
+ ${o}`),process.exit(1)}await c(e.id),f(i,{name:e.name})}export{x as default};
package/dist/lib/rm.js CHANGED
@@ -1 +1 @@
1
- import*as te from"readline";import{list as F}from"@tigrisdata/storage";function G(n){let e=n.split("/");return{bucket:e[0],path:e.slice(1).join("/")}}async function $(n,e,o){let{data:t}=await F({prefix:`${e}/`,limit:1,config:{...o,bucket:n}});return!!(t?.items&&t.items.length>0)}async function U(n,e,o){let t=[],i;do{let{data:r,error:s}=await F({prefix:e,paginationToken:i,config:{...o,bucket:n}});if(s)return{items:t,error:s};r?.items&&t.push(...r.items),i=r?.hasMore?r.paginationToken:void 0}while(i);return{items:t}}function E(n,e,o){for(let t of e)if(n[t]!==void 0)return n[t];return o}import{S3Client as be}from"@aws-sdk/client-s3";import{fromIni as le}from"@aws-sdk/credential-providers";import{homedir as W}from"os";import{join as p}from"path";import{readFileSync as oe,writeFileSync as ie,existsSync as h,mkdirSync as re}from"fs";import{loadSharedConfigFiles as se}from"@smithy/shared-ini-file-loader";import{chmod as ae}from"fs/promises";var f="https://t3.storage.dev",v="https://iam.storageapi.dev";var P=p(W(),".tigris"),T=p(P,"config.json");function ce(){h(P)||re(P,{recursive:!0,mode:448})}function d(){if(h(T))try{let n=oe(T,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function y(n){ce(),ie(T,JSON.stringify(n,null,2),{mode:384});try{await ae(T,384)}catch{}}async function x(n){let e=d();e.tokens=n,await y(e)}async function u(){return d().tokens||null}async function O(){let n=d();delete n.tokens,await y(n)}async function j(n){let e=d();e.organizations=n,await y(e)}function q(){return d().organizations||[]}function N(){return d().selectedOrganization||null}function H(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let t=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!t||!i)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||f;return{accessKeyId:t,secretAccessKey:i,endpoint:r}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let o=process.env.AWS_ENDPOINT_URL_S3||f;return{accessKeyId:n,secretAccessKey:e,endpoint:o}}function J(){if(!process.env.AWS_PROFILE)return!1;let n=p(W(),".aws");return h(p(n,"credentials"))||h(p(n,"config"))}async function Y(n){try{let{configFile:e}=await se(),o=e[n];return o?{endpoint:o.endpoint_url_s3||o.endpoint_url,iamEndpoint:o.endpoint_url_iam,region:o.region}:{}}catch{return{}}}function R(){let n=d();return n.temporaryCredentials||n.credentials||null}async function B(n){let e=d();e.loginMethod=n,await y(e)}function V(){return d().loginMethod||null}import C from"axios";import de from"open";function w(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",o=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",t=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:o,audience:t}}var Q=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function X(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||f,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||v}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||f,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||v}}var D=class{config;baseUrl;constructor(){this.config=w(),this.baseUrl=`https://${this.config.domain}`}async login(e){let t=(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?.(t.user_code,t.verification_uri),await this.sleep(2e3);try{await de(t.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(t.device_code,t.interval||5);await x(i),B("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,o){let i=0;for(;i<60;){i++;try{let s=(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,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(C.isAxiosError(r)&&r.response){let s=r.response.data?.error;if(s==="authorization_pending"){await this.sleep(o*1e3);continue}if(s==="slow_down"){o+=5,await this.sleep(o*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 u();if(!e)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let o=300*1e3;return Date.now()+o>=e.expiresAt&&(e=await this.refreshAccessToken(e)),e.accessToken}async refreshAccessToken(e){let o=null;if(e?.refreshToken?o=e:o=await u(),!o)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:o.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||o.refreshToken,idToken:i.id_token||o.idToken,expiresAt:Date.now()+(i.expires_in||3600)*1e3};return await x(r),r}catch{throw await O(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await u();if(!e||!e.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let o=e.idToken.split(".")[1],t=Buffer.from(o,"base64").toString("utf8");return JSON.parse(t)}catch{throw new Error("Failed to decode ID token")}}async extractAndStoreOrganizations(e){if(e)try{let o=e.split(".")[1],t=Buffer.from(o,"base64").toString("utf8"),r=JSON.parse(t)[Q];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;j(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),q()}async logout(){await O()}async isAuthenticated(){return await u()!==null}sleep(e){return new Promise(o=>setTimeout(o,e))}},K=null;function Z(){return K||(K=new D),K}var I=X(),fe=w();async function ge(){return V()}async function ee(){if(J()){let t=process.env.AWS_PROFILE||"default",i=await Y(t),r=await le({profile:t})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||I.endpoint||f,iamEndpoint:i.iamEndpoint||I.iamEndpoint}}let n=await ge();if(n==="oauth"){let i=await Z().getAccessToken();if(!N())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:I.endpoint,organizationId:N()??void 0,iamEndpoint:I.iamEndpoint,authDomain:fe.domain}}if(n==="credentials"){let t=R();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint}}let e=H();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let o=R();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{remove as b,removeBucket as pe,list as ue}from"@tigrisdata/storage";async function M(n){let e=te.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(`${n} (y/N): `,t=>{e.close(),o(t.toLowerCase()==="y")})})}async function me(n){let e=E(n,["path"]),o=E(n,["force","f","F"]);e||(console.error("path argument is required"),process.exit(1));let{bucket:t,path:i}=G(e);t||(console.error("Invalid path"),process.exit(1));let r=await ee();if(!i){if(!o&&!await M(`Are you sure you want to delete bucket '${t}'?`)){console.log("Aborted");return}let{error:l}=await pe(t,{config:r});l&&(console.error(l.message),process.exit(1)),console.log(`Removed bucket '${t}'`);return}let s=e.includes("*"),a=i.endsWith("/");if(!s&&!a&&(a=await $(t,i,r)),s||a){let l=s?i.replace("*",""):i.endsWith("/")?i:`${i}/`,{items:A,error:L}=await U(t,l||void 0,r);L&&(console.error(L.message),process.exit(1));let _=A,g=l,ne=_.some(c=>c.name===g),S=!1;if(!ne){let{data:c}=await ue({prefix:g,limit:1,config:{...r,bucket:t}});S=c?.items?.some(m=>m.name===g)||!1}let z=_.length+(S?1:0);if(z===0){console.log("No objects to remove");return}if(!o&&!await M(`Are you sure you want to delete ${z} object(s)?`)){console.log("Aborted");return}let k=0;for(let c of _){let{error:m}=await b(c.name,{config:{...r,bucket:t}});m?console.error(`Failed to remove ${c.name}: ${m.message}`):(console.log(`Removed ${t}/${c.name}`),k++)}if(S){let{error:c}=await b(g,{config:{...r,bucket:t}});c?console.error(`Failed to remove ${g}: ${c.message}`):(console.log(`Removed ${t}/${g}`),k++)}console.log(`Removed ${k} object(s)`)}else{if(!o&&!await M(`Are you sure you want to delete '${t}/${i}'?`)){console.log("Aborted");return}let{error:l}=await b(i,{config:{...r,bucket:t}});l&&(console.error(l.message),process.exit(1)),console.log(`Removed ${t}/${i}`)}process.exit(0)}export{me as default};
1
+ import{a as g}from"../chunk-JRALYIRA.js";import{b as j}from"../chunk-ESJWTUFN.js";import"../chunk-QZXBLNMQ.js";import"../chunk-6U4U4JM6.js";import{a as P,b as A,d as F,g as I,h as S,i as W}from"../chunk-LCWHZUZZ.js";import"../chunk-JVB3Y42V.js";import"../chunk-D63SZLT5.js";import*as E from"readline";import{remove as w,removeBucket as T,list as q}from"@tigrisdata/storage";async function $(l){let s=E.createInterface({input:process.stdin,output:process.stdout});return new Promise(m=>{s.question(`${l} (y/N): `,d=>{s.close(),m(d.toLowerCase()==="y")})})}async function C(l){let s=g(l,["path"]),m=g(l,["force","f","F"]),d=!!g(l,["recursive","r"]);s||(console.error("path argument is required"),process.exit(1)),P(s)||(console.error("Path must be a remote Tigris path (t3:// or tigris://)"),process.exit(1));let{bucket:e,path:o}=A(s);e||(console.error("Invalid path"),process.exit(1));let i=await j(),b=s.endsWith("/");if(!o&&!b){if(!m&&!await $(`Are you sure you want to delete bucket '${e}'?`)){console.log("Aborted");return}let{error:t}=await T(e,{config:i});t&&(console.error(t.message),process.exit(1)),console.log(`Removed bucket '${e}'`);return}let n=o.includes("*"),u=o.endsWith("/")||!o&&b;if(!n&&!u&&(u=await F(e,o,i)),u&&!n&&!d&&(console.error("Source is a remote folder (not removed). Use -r to remove recursively."),process.exit(1)),n||u){let t=n?S(o):o?o.endsWith("/")?o:`${o}/`:"",{items:p,error:x}=await W(e,t||void 0,i);x&&(console.error(x.message),process.exit(1));let f=p;if(n){let r=o.split("/").pop(),a=I(r);f=f.filter(R=>{let k=t?R.name.slice(t.length):R.name;return!d&&k.includes("/")?!1:a.test(k.split("/").pop())})}let c=t,M=f.some(r=>r.name===c),v=!1;if(!M&&!n){let{data:r}=await q({prefix:c,limit:1,config:{...i,bucket:e}});v=r?.items?.some(a=>a.name===c)||!1}let y=f.length+(v?1:0);if(y===0){console.log("No objects to remove");return}if(!m&&!await $(`Are you sure you want to delete ${y} object(s)?`)){console.log("Aborted");return}let h=0;for(let r of f){let{error:a}=await w(r.name,{config:{...i,bucket:e}});a?console.error(`Failed to remove ${r.name}: ${a.message}`):(console.log(`Removed t3://${e}/${r.name}`),h++)}if(v){let{error:r}=await w(c,{config:{...i,bucket:e}});r?console.error(`Failed to remove ${c}: ${r.message}`):(console.log(`Removed t3://${e}/${c}`),h++)}console.log(`Removed ${h} object(s)`)}else{if(!m&&!await $(`Are you sure you want to delete 't3://${e}/${o}'?`)){console.log("Aborted");return}let{error:t}=await w(o,{config:{...i,bucket:e}});t&&(console.error(t.message),process.exit(1)),console.log(`Removed t3://${e}/${o}`)}process.exit(0)}export{C as default};
@@ -1,7 +1 @@
1
- function _(e,n,t){for(let o of n)if(e[o]!==void 0)return e[o];return t}function ae(e){return JSON.stringify(e,null,2)}function ce(e,n=" "){return Object.entries(e).map(([t,o])=>`${n}<${t}>${o}</${t}>`).join(`
2
- `)}function de(e,n,t){let o=[`<${n}>`];return e.forEach(i=>{o.push(` <${t}>`),o.push(ce(i," ")),o.push(` </${t}>`)}),o.push(`</${n}>`),o.join(`
3
- `)}function F(e){if(e==null)return"";if(e instanceof Date)return z(e);if(typeof e=="string"){let n=new Date(e);if(!isNaN(n.getTime())&&e.includes("T"))return z(n)}return String(e)}function z(e){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(e)}function pe(e,n){return n.map(t=>{if(t.width)return t.width;let o=t.header.length,i=e.reduce((r,s)=>{let a=F(s[t.key]);return Math.max(r,a.length)},0);return Math.max(o,i)})}function ue(e,n){let t=[],o=pe(e,n),i="\u250C"+o.map(c=>"\u2500".repeat(c+2)).join("\u252C")+"\u2510",r="\u251C"+o.map(c=>"\u2500".repeat(c+2)).join("\u253C")+"\u2524",s="\u2514"+o.map(c=>"\u2500".repeat(c+2)).join("\u2534")+"\u2518";t.push(`
4
- `+i);let a="\u2502 "+n.map((c,A)=>c.header.padEnd(o[A])).join(" \u2502 ")+" \u2502";return t.push(a),t.push(r),e.forEach(c=>{let A=n.map((K,b)=>{let L=F(c[K.key]);return K.align==="right"?L.padStart(o[b]):L.padEnd(o[b])});t.push("\u2502 "+A.join(" \u2502 ")+" \u2502")}),t.push(s+`
5
- `),t.join(`
6
- `)}function G(e,n,t,o,i){switch(n){case"json":return ae(e);case"xml":return de(e,t,o);default:return ue(e,i)}}import{S3Client as He}from"@aws-sdk/client-s3";import{fromIni as ye}from"@aws-sdk/credential-providers";import{homedir as j}from"os";import{join as u}from"path";import{readFileSync as ge,writeFileSync as le,existsSync as f,mkdirSync as fe}from"fs";import{loadSharedConfigFiles as me}from"@smithy/shared-ini-file-loader";import{chmod as he}from"fs/promises";var p="https://t3.storage.dev",I="https://iam.storageapi.dev";var x=u(j(),".tigris"),m=u(x,"config.json");function Te(){f(x)||fe(x,{recursive:!0,mode:448})}function d(){if(f(m))try{let e=ge(m,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function h(e){Te(),le(m,JSON.stringify(e,null,2),{mode:384});try{await he(m,384)}catch{}}async function E(e){let n=d();n.tokens=e,await h(n)}async function g(){return d().tokens||null}async function k(){let e=d();delete e.tokens,await h(e)}async function $(e){let n=d();n.organizations=e,await h(n)}function U(){return d().organizations||[]}function v(){return d().selectedOrganization||null}function W(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||p;return{accessKeyId:o,secretAccessKey:i,endpoint:r}}let e=process.env.AWS_ACCESS_KEY_ID,n=process.env.AWS_SECRET_ACCESS_KEY;if(!e||!n)return null;let t=process.env.AWS_ENDPOINT_URL_S3||p;return{accessKeyId:e,secretAccessKey:n,endpoint:t}}function V(){if(!process.env.AWS_PROFILE)return!1;let e=u(j(),".aws");return f(u(e,"credentials"))||f(u(e,"config"))}async function Y(e){try{let{configFile:n}=await me(),t=n[e];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function O(){let e=d();return e.temporaryCredentials||e.credentials||null}async function B(e){let n=d();n.loginMethod=e,await h(n)}function J(){return d().loginMethod||null}import C from"axios";import Ce from"open";function T(){let e=process.env.TIGRIS_ENV==="development",n=process.env.AUTH0_DOMAIN||e?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||e?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||e?"https://tigris-api-dev":"https://tigris-os-api";return{domain:n,clientId:t,audience:o}}var q=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function H(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||p,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||I}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||p,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||I}}var N=class{config;baseUrl;constructor(){this.config=T(),this.baseUrl=`https://${this.config.domain}`}async login(n){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;n?.onDeviceCode?.(o.user_code,o.verification_uri),await this.sleep(2e3);try{await Ce(o.verification_uri_complete)}catch{}n?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await E(i),B("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(n,t){let i=0;for(;i<60;){i++;try{let s=(await C.post(`${this.baseUrl}/oauth/token`,{client_id:this.config.clientId,device_code:n,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(C.isAxiosError(r)&&r.response){let s=r.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(r.response.data?.error_description||"Authentication failed")}throw r}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let n=await g();if(!n)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');let t=300*1e3;return Date.now()+t>=n.expiresAt&&(n=await this.refreshAccessToken(n)),n.accessToken}async refreshAccessToken(n){let t=null;if(n?.refreshToken?t=n:t=await g(),!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 E(r),r}catch{throw await k(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let n=await g();if(!n||!n.idToken)throw new Error('Not authenticated. Please run "tigris login" to authenticate.');try{let t=n.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(n){if(n)try{let t=n.split(".")[1],o=Buffer.from(t,"base64").toString("utf8"),r=JSON.parse(o)[q];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;$(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),U()}async logout(){await k()}async isAuthenticated(){return await g()!==null}sleep(n){return new Promise(t=>setTimeout(t,n))}},P=null;function X(){return P||(P=new N),P}var y=H(),Se=T();async function we(){return J()}async function Q(){if(V()){let o=process.env.AWS_PROFILE||"default",i=await Y(o),r=await ye({profile:o})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||y.endpoint||p,iamEndpoint:i.iamEndpoint||y.iamEndpoint}}let e=await we();if(e==="oauth"){let i=await X().getAccessToken();if(!v())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:y.endpoint,organizationId:v()??void 0,iamEndpoint:y.iamEndpoint,authDomain:Se.domain}}if(e==="credentials"){let o=O();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let n=W();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};let t=O();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{listBucketSnapshots as Pe}from"@tigrisdata/storage";import{readFileSync as Ae,existsSync as _e}from"fs";import{join as Z,dirname as Ie}from"path";import{fileURLToPath as xe}from"url";import*as ee from"yaml";var Ee=xe(import.meta.url),ke=Ie(Ee),D=null;function ve(){let e=ke;for(let n=0;n<5;n++){let t=Z(e,"specs.yaml");if(_e(t))return t;e=Z(e,"..")}throw new Error("Could not find specs.yaml")}function Oe(){if(!D){let e=ve(),n=Ae(e,"utf8");D=ee.parse(n)}return D}function ne(e,n){let o=Oe().commands.find(i=>i.name===e);return o?n&&o.operations?o.operations.find(i=>i.name===n)||null:o:null}var te={success:"\u2714",failure:"\u2716",hint:"\u2192"};function M(){return process.stdout.isTTY===!0}function S(e){let n=ne(e.command,e.operation);if(n)return n.messages}function w(e,n){let t=e;return t=t.replace(/\\n/g,`
7
- `),n&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let r=n[i];return r!==void 0?String(r):`{{${i}}}`})),t}function oe(e,n){if(!M())return;let t=S(e);t?.onStart&&console.log(w(t.onStart,n))}function ie(e,n){if(!M())return;let t=S(e);t?.onSuccess&&console.log(`${te.success} ${w(t.onSuccess,n)}`)}function R(e,n,t){let o=S(e);o?.onFailure&&console.error(`${te.failure} ${w(o.onFailure,t)}`),n&&console.error(` ${n}`)}function re(e,n){if(!M())return;let t=S(e);t?.onEmpty&&console.log(w(t.onEmpty,n))}function se(e,n){return{command:e,operation:n}}var l=se("snapshots","list");async function Ne(e){oe(l);let n=_(e,["name"]),t=_(e,["format","f","F"],"table");n||(R(l,"Bucket name is required"),process.exit(1));let o=await Q(),{data:i,error:r}=await Pe(n,{config:o});if(r&&(R(l,r.message),process.exit(1)),!i||i.length===0){re(l);return}let s=i.map(c=>({name:c.name||"",version:c.version||"",created:c.creationDate})),a=G(s,t,"snapshots","snapshot",[{key:"name",header:"Name"},{key:"version",header:"Version"},{key:"created",header:"Created"}]);console.log(a),ie(l,{count:s.length})}export{Ne as default};
1
+ import{a as f,b as u,c as n,d as g,g as d}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{f as p}from"../../chunk-HGIJOGCZ.js";import{a as o}from"../../chunk-JRALYIRA.js";import{b as c}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{listBucketSnapshots as y}from"@tigrisdata/storage";var t=d("snapshots","list");async function x(s){f(t);let a=o(s,["name"]),l=o(s,["format","f","F"],"table");a||(n(t,"Bucket name is required"),process.exit(1));let h=await c(),{data:e,error:i}=await y(a,{config:h});if(i&&(n(t,i.message),process.exit(1)),!e||e.length===0){g(t);return}let m=e.map(r=>({name:r.name||"",version:r.version||"",created:r.creationDate})),k=p(m,l,"snapshots","snapshot",[{key:"name",header:"Name"},{key:"version",header:"Version"},{key:"created",header:"Created"}]);console.log(k),u(t,{count:m.length})}export{x as default};
@@ -1,2 +1 @@
1
- function T(n,e,t){for(let o of e)if(n[o]!==void 0)return n[o];return t}import{S3Client as Re}from"@aws-sdk/client-s3";import{fromIni as se}from"@aws-sdk/credential-providers";import{homedir as M}from"os";import{join as p}from"path";import{readFileSync as X,writeFileSync as Z,existsSync as g,mkdirSync as ee}from"fs";import{loadSharedConfigFiles as ne}from"@smithy/shared-ini-file-loader";import{chmod as te}from"fs/promises";var d="https://t3.storage.dev",S="https://iam.storageapi.dev";var A=p(M(),".tigris"),f=p(A,"config.json");function oe(){g(A)||ee(A,{recursive:!0,mode:448})}function c(){if(g(f))try{let n=X(f,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function u(n){oe(),Z(f,JSON.stringify(n,null,2),{mode:384});try{await te(f,384)}catch{}}async function _(n){let e=c();e.tokens=n,await u(e)}async function l(){return c().tokens||null}async function w(){let n=c();delete n.tokens,await u(n)}async function D(n){let e=c();e.organizations=n,await u(e)}function K(){return c().organizations||[]}function I(){return c().selectedOrganization||null}function R(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let s=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:o,secretAccessKey:i,endpoint:s}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let t=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:n,secretAccessKey:e,endpoint:t}}function b(){if(!process.env.AWS_PROFILE)return!1;let n=p(M(),".aws");return g(p(n,"credentials"))||g(p(n,"config"))}async function L(n){try{let{configFile:e}=await ne(),t=e[n];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function E(){let n=c();return n.temporaryCredentials||n.credentials||null}async function z(n){let e=c();e.loginMethod=n,await u(e)}function G(){return c().loginMethod||null}import h from"axios";import ie from"open";function m(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:t,audience:o}}var F=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function U(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||S}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||S}}var v=class{config;baseUrl;constructor(){this.config=m(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await h.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 ie(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await _(i),z("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,t){let i=0;for(;i<60;){i++;try{let r=(await h.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(s){if(h.isAxiosError(s)&&s.response){let r=s.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(s.response.data?.error_description||"Authentication failed")}throw s}}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 i=(await h.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,s={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 _(s),s}catch{throw await w(),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],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"),s=JSON.parse(o)[F];if(!s)return;let r=s?.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;D(r)}catch{}}async getOrganizations(){return await this.getAccessToken(),K()}async logout(){await w()}async isAuthenticated(){return await l()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},k=null;function $(){return k||(k=new v),k}var C=U(),re=m();async function ae(){return G()}async function V(){if(b()){let o=process.env.AWS_PROFILE||"default",i=await L(o),s=await se({profile:o})();return{accessKeyId:s.accessKeyId,secretAccessKey:s.secretAccessKey,endpoint:i.endpoint||C.endpoint||d,iamEndpoint:i.iamEndpoint||C.iamEndpoint}}let n=await ae();if(n==="oauth"){let i=await $().getAccessToken();if(!I())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:C.endpoint,organizationId:I()??void 0,iamEndpoint:C.iamEndpoint,authDomain:re.domain}}if(n==="credentials"){let o=E();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let e=R();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let t=E();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{createBucketSnapshot as he}from"@tigrisdata/storage";import{readFileSync as ce,existsSync as de}from"fs";import{join as j,dirname as pe}from"path";import{fileURLToPath as le}from"url";import*as W from"yaml";var ge=le(import.meta.url),fe=pe(ge),x=null;function ue(){let n=fe;for(let e=0;e<5;e++){let t=j(n,"specs.yaml");if(de(t))return t;n=j(n,"..")}throw new Error("Could not find specs.yaml")}function me(){if(!x){let n=ue(),e=ce(n,"utf8");x=W.parse(e)}return x}function Y(n,e){let o=me().commands.find(i=>i.name===n);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var q={success:"\u2714",failure:"\u2716",hint:"\u2192"};function H(){return process.stdout.isTTY===!0}function O(n){let e=Y(n.command,n.operation);if(e)return e.messages}function P(n,e){let t=n;return t=t.replace(/\\n/g,`
2
- `),e&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let s=e[i];return s!==void 0?String(s):`{{${i}}}`})),t}function B(n,e){if(!H())return;let t=O(n);t?.onStart&&console.log(P(t.onStart,e))}function J(n,e){if(!H())return;let t=O(n);t?.onSuccess&&console.log(`${q.success} ${P(t.onSuccess,e)}`)}function N(n,e,t){let o=O(n);o?.onFailure&&console.error(`${q.failure} ${P(o.onFailure,t)}`),e&&console.error(` ${e}`)}function Q(n,e){return{command:n,operation:e}}var y=Q("snapshots","take");async function Ce(n){B(y);let e=T(n,["name"]),t=T(n,["snapshot-name","snapshotName"]);e||(N(y,"Bucket name is required"),process.exit(1));let o=await V(),{data:i,error:s}=await he(e,{name:t,config:o});s&&(N(y,s.message),process.exit(1)),J(y,{name:e,snapshotName:t||i?.snapshotVersion,version:i?.snapshotVersion})}export{Ce as default};
1
+ import{a as p,b as c,c as e,g as f}from"../../chunk-A3TXP5Y2.js";import"../../chunk-4LGKN5DA.js";import{a as n}from"../../chunk-JRALYIRA.js";import{b as m}from"../../chunk-ESJWTUFN.js";import"../../chunk-QZXBLNMQ.js";import"../../chunk-6U4U4JM6.js";import"../../chunk-JVB3Y42V.js";import"../../chunk-D63SZLT5.js";import{createBucketSnapshot as h}from"@tigrisdata/storage";var t=f("snapshots","take");async function u(o){p(t);let s=n(o,["name"]),a=n(o,["snapshot-name","snapshotName"]);s||(e(t,"Bucket name is required"),process.exit(1));let g=await m(),{data:r,error:i}=await h(s,{name:a,config:g});i&&(e(t,i.message),process.exit(1)),c(t,{name:s,snapshotName:a||r?.snapshotVersion,version:r?.snapshotVersion})}export{u as default};
package/dist/lib/touch.js CHANGED
@@ -1 +1 @@
1
- import{list as Z}from"@tigrisdata/storage";function k(t){let e=t.split("/");return{bucket:e[0],path:e.slice(1).join("/")}}function P(t,e,n){for(let i of e)if(t[i]!==void 0)return t[i];return n}import{S3Client as ye}from"@aws-sdk/client-s3";import{fromIni as Y}from"@aws-sdk/credential-providers";import{homedir as v}from"os";import{join as g}from"path";import{readFileSync as F,writeFileSync as U,existsSync as f,mkdirSync as j}from"fs";import{loadSharedConfigFiles as W}from"@smithy/shared-ini-file-loader";import{chmod as q}from"fs/promises";var d="https://t3.storage.dev",y="https://iam.storageapi.dev";var C=g(v(),".tigris"),p=g(C,"config.json");function H(){f(C)||j(C,{recursive:!0,mode:448})}function c(){if(f(p))try{let t=F(p,"utf8");return JSON.parse(t)}catch{return{}}return{}}async function u(t){H(),U(p,JSON.stringify(t,null,2),{mode:384});try{await q(p,384)}catch{}}async function _(t){let e=c();e.tokens=t,await u(e)}async function l(){return c().tokens||null}async function I(){let t=c();delete t.tokens,await u(t)}async function x(t){let e=c();e.organizations=t,await u(e)}function O(){return c().organizations||[]}function w(){return c().selectedOrganization||null}function N(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let i=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,o=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!i||!o)return null;let r=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:i,secretAccessKey:o,endpoint:r}}let t=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!t||!e)return null;let n=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:t,secretAccessKey:e,endpoint:n}}function K(){if(!process.env.AWS_PROFILE)return!1;let t=g(v(),".aws");return f(g(t,"credentials"))||f(g(t,"config"))}async function D(t){try{let{configFile:e}=await W(),n=e[t];return n?{endpoint:n.endpoint_url_s3||n.endpoint_url,iamEndpoint:n.endpoint_url_iam,region:n.region}:{}}catch{return{}}}function A(){let t=c();return t.temporaryCredentials||t.credentials||null}async function R(t){let e=c();e.loginMethod=t,await u(e)}function M(){return c().loginMethod||null}import h from"axios";import J from"open";function m(){let t=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||t?"auth-dev.tigris.dev":"auth.tigris.dev",n=process.env.AUTH0_CLIENT_ID||t?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",i=process.env.AUTH0_AUDIENCE||t?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:n,audience:i}}var z=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function L(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||y}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||y}}var E=class{config;baseUrl;constructor(){this.config=m(),this.baseUrl=`https://${this.config.domain}`}async login(e){let i=(await h.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 J(i.verification_uri_complete)}catch{}e?.onWaiting?.();let o=await this.pollForToken(i.device_code,i.interval||5);await _(o),R("oauth"),await this.extractAndStoreOrganizations(o.idToken)}async pollForToken(e,n){let o=0;for(;o<60;){o++;try{let s=(await h.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(h.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 l();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 l(),!n)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let o=(await h.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:o.access_token,refreshToken:o.refresh_token||n.refreshToken,idToken:o.id_token||n.idToken,expiresAt:Date.now()+(o.expires_in||3600)*1e3};return await _(r),r}catch{throw await I(),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 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"),r=JSON.parse(i)[z];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;x(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),O()}async logout(){await I()}async isAuthenticated(){return await l()!==null}sleep(e){return new Promise(n=>setTimeout(n,e))}},S=null;function b(){return S||(S=new E),S}var T=L(),$=m();async function B(){return M()}async function G(){if(K()){let i=process.env.AWS_PROFILE||"default",o=await D(i),r=await Y({profile:i})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:o.endpoint||T.endpoint||d,iamEndpoint:o.iamEndpoint||T.iamEndpoint}}let t=await B();if(t==="oauth"){let o=await b().getAccessToken();if(!w())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:o,accessKeyId:"",secretAccessKey:"",endpoint:T.endpoint,organizationId:w()??void 0,iamEndpoint:T.iamEndpoint,authDomain:$.domain}}if(t==="credentials"){let i=A();if(i)return{accessKeyId:i.accessKeyId,secretAccessKey:i.secretAccessKey,endpoint:i.endpoint}}let e=N();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let n=A();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{put as V}from"@tigrisdata/storage";async function Q(t){let e=P(t,["path"]);e||(console.error("path argument is required"),process.exit(1));let{bucket:n,path:i}=k(e);n||(console.error("Invalid path"),process.exit(1)),i||(console.error("Object key is required (use mk to create buckets)"),process.exit(1));let o=await G(),{error:r}=await V(i,"",{config:{...o,bucket:n}});r&&(console.error(r.message),process.exit(1)),console.log(`Created '${n}/${i}'`),process.exit(0)}export{Q as default};
1
+ import{a as i}from"../chunk-JRALYIRA.js";import{b as n}from"../chunk-ESJWTUFN.js";import"../chunk-QZXBLNMQ.js";import"../chunk-6U4U4JM6.js";import{f as s}from"../chunk-LCWHZUZZ.js";import"../chunk-JVB3Y42V.js";import"../chunk-D63SZLT5.js";import{put as p}from"@tigrisdata/storage";async function f(c){let r=i(c,["path"]);r||(console.error("path argument is required"),process.exit(1));let{bucket:o,path:e}=s(r);o||(console.error("Invalid path"),process.exit(1)),e||(console.error("Object key is required (use mk to create buckets)"),process.exit(1));let a=await n(),{error:t}=await p(e,"",{config:{...a,bucket:o}});t&&(console.error(t.message),process.exit(1)),console.log(`Created '${o}/${e}'`),process.exit(0)}export{f as default};
@@ -1,3 +1,2 @@
1
- import{listOrganizations as Ae}from"@tigrisdata/iam";import S from"axios";import re from"open";var d="https://t3.storage.dev",E="https://iam.storageapi.dev";function h(){let n=process.env.TIGRIS_ENV==="development",e=process.env.AUTH0_DOMAIN||n?"auth-dev.tigris.dev":"auth.tigris.dev",t=process.env.AUTH0_CLIENT_ID||n?"JdJVYIyw0O1uHi5L5OJH903qaWBgd3gF":"DMejqeM3CQ4IqTjEcd3oA9eEiT40hn8D",o=process.env.AUTH0_AUDIENCE||n?"https://tigris-api-dev":"https://tigris-os-api";return{domain:e,clientId:t,audience:o}}var b=process.env.TIGRIS_CLAIMS_NAMESPACE||"https://tigris";function L(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||d,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||E}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||d,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||E}}import{homedir as G}from"os";import{join as g}from"path";import{readFileSync as ee,writeFileSync as ne,existsSync as C,mkdirSync as te}from"fs";import{loadSharedConfigFiles as ie}from"@smithy/shared-ini-file-loader";import{chmod as oe}from"fs/promises";var v=g(G(),".tigris"),y=g(v,"config.json");function se(){C(v)||te(v,{recursive:!0,mode:448})}function c(){if(C(y))try{let n=ee(y,"utf8");return JSON.parse(n)}catch{return{}}return{}}async function T(n){se(),ne(y,JSON.stringify(n,null,2),{mode:384});try{await oe(y,384)}catch{}}async function x(n){let e=c();e.tokens=n,await T(e)}async function p(){return c().tokens||null}async function k(){let n=c();delete n.tokens,await T(n)}async function F(n){let e=c();e.organizations=n,await T(e)}function U(){return c().organizations||[]}function u(){return c().selectedOrganization||null}function O(){if(process.env.TIGRIS_STORAGE_ACCESS_KEY_ID||process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY){let o=process.env.TIGRIS_STORAGE_ACCESS_KEY_ID,i=process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;if(!o||!i)return null;let s=process.env.TIGRIS_STORAGE_ENDPOINT||d;return{accessKeyId:o,secretAccessKey:i,endpoint:s}}let n=process.env.AWS_ACCESS_KEY_ID,e=process.env.AWS_SECRET_ACCESS_KEY;if(!n||!e)return null;let t=process.env.AWS_ENDPOINT_URL_S3||d;return{accessKeyId:n,secretAccessKey:e,endpoint:t}}function $(){if(!process.env.AWS_PROFILE)return!1;let n=g(G(),".aws");return C(g(n,"credentials"))||C(g(n,"config"))}async function j(n){try{let{configFile:e}=await ie(),t=e[n];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function W(){let n=c();return O()||n.temporaryCredentials||n.credentials||null}function P(){let n=c();return n.temporaryCredentials||n.credentials||null}async function Y(n){let e=c();e.loginMethod=n,await T(e)}function A(){return c().loginMethod||null}var M=class{config;baseUrl;constructor(){this.config=h(),this.baseUrl=`https://${this.config.domain}`}async login(e){let o=(await S.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 re(o.verification_uri_complete)}catch{}e?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await x(i),Y("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(e,t){let i=0;for(;i<60;){i++;try{let r=(await S.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(s){if(S.isAxiosError(s)&&s.response){let r=s.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(s.response.data?.error_description||"Authentication failed")}throw s}}throw new Error("Authentication timed out. Please try again.")}async getAccessToken(){let e=await p();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 p(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await S.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,s={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 x(s),s}catch{throw await k(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let e=await p();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"),s=JSON.parse(o)[b];if(!s)return;let r=s?.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;F(r)}catch{}}async getOrganizations(){return await this.getAccessToken(),U()}async logout(){await k()}async isAuthenticated(){return await p()!==null}sleep(e){return new Promise(t=>setTimeout(t,e))}},N=null;function _(){return N||(N=new M),N}import{S3Client as Le}from"@aws-sdk/client-s3";import{fromIni as ae}from"@aws-sdk/credential-providers";var w=L(),ce=h();async function de(){return A()}async function V(){if($()){let o=process.env.AWS_PROFILE||"default",i=await j(o),s=await ae({profile:o})();return{accessKeyId:s.accessKeyId,secretAccessKey:s.secretAccessKey,endpoint:i.endpoint||w.endpoint||d,iamEndpoint:i.iamEndpoint||w.iamEndpoint}}let n=await de();if(n==="oauth"){let i=await _().getAccessToken();if(!u())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:w.endpoint,organizationId:u()??void 0,iamEndpoint:w.iamEndpoint,authDomain:ce.domain}}if(n==="credentials"){let o=P();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let e=O();if(e)return{accessKeyId:e.accessKeyId,secretAccessKey:e.secretAccessKey,endpoint:e.endpoint};let t=P();if(t)return{accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint};throw new Error('Not authenticated. Please run "tigris login" or "tigris configure" first.')}import{readFileSync as le,existsSync as ge}from"fs";import{join as q,dirname as pe}from"path";import{fileURLToPath as ue}from"url";import*as H from"yaml";var fe=ue(import.meta.url),me=pe(fe),D=null;function he(){let n=me;for(let e=0;e<5;e++){let t=q(n,"specs.yaml");if(ge(t))return t;n=q(n,"..")}throw new Error("Could not find specs.yaml")}function Ce(){if(!D){let n=he(),e=le(n,"utf8");D=H.parse(e)}return D}function J(n,e){let o=Ce().commands.find(i=>i.name===n);return o?e&&o.operations?o.operations.find(i=>i.name===e)||null:o:null}var ye={success:"\u2714",failure:"\u2716",hint:"\u2192"};function Te(){return process.stdout.isTTY===!0}function B(n){let e=J(n.command,n.operation);if(e)return e.messages}function Q(n,e){let t=n;return t=t.replace(/\\n/g,`
2
- `),e&&(t=t.replace(/\{\{(\w+)\}\}/g,(o,i)=>{let s=e[i];return s!==void 0?String(s):`{{${i}}}`})),t}function I(n,e,t){let o=B(n);o?.onFailure&&console.error(`${ye.failure} ${Q(o.onFailure,t)}`),e&&console.error(` ${e}`)}function K(n,e){if(!Te())return;let t=B(n);t?.onAlreadyDone&&console.log(Q(t.onAlreadyDone,e))}function X(n,e){return{command:n,operation:e}}var f=X("whoami");async function Se(){try{let n=A(),e=W(),t,o;if(n==="oauth"){let s=_();if(!await s.isAuthenticated()){K(f);return}let a=await s.getIdTokenClaims();t=a.email,o=a.sub}else if(e)t=void 0,o=e.accessKeyId;else{K(f);return}let i=[];if(i.push(""),i.push("User Information:"),i.push(` Email: ${t||"N/A"}`),i.push(` User ID: ${o||"N/A"}`),n==="oauth"){let s=await V(),r=u(),{data:a,error:R}=await Ae({config:s});R&&(I(f,R.message),process.exit(1));let m=a?.organizations??[];if(m.length>0){if(i.push(""),i.push(`Organizations (${m.length}):`),m.forEach(l=>{let Z=l.id===r?">":" ";i.push(` ${Z} ${l.name} (${l.id})`)}),r){let l=m.find(z=>z.id===r);l&&(i.push(""),i.push(`Active: ${l.name}`))}}else i.push(""),i.push("Organizations: None")}else i.push(""),i.push("Login method: Access Key Credentials"),i.push(" (Organization listing requires OAuth login: tigris login)");i.push(""),console.log(i.join(`
3
- `))}catch(n){n instanceof Error?I(f,n.message):I(f),process.exit(1)}}export{Se as default};
1
+ import{c,e as h,g as $}from"../chunk-A3TXP5Y2.js";import"../chunk-4LGKN5DA.js";import{b as O}from"../chunk-ESJWTUFN.js";import{b as z}from"../chunk-QZXBLNMQ.js";import"../chunk-6U4U4JM6.js";import{g as f,k as p,s as A}from"../chunk-JVB3Y42V.js";import"../chunk-D63SZLT5.js";import{listOrganizations as C}from"@tigrisdata/iam";var s=$("whoami");async function y(){try{let i=A(),d=p(),l,u;if(i==="oauth"){let n=z();if(!await n.isAuthenticated()){h(s);return}let a=await n.getIdTokenClaims();l=a.email,u=a.sub}else if(d)l=void 0,u=d.accessKeyId;else{h(s);return}let e=[];if(e.push(""),e.push("User Information:"),e.push(` Email: ${l||"N/A"}`),e.push(` User ID: ${u||"N/A"}`),i==="oauth"){let n=await O(),o=f(),{data:a,error:g}=await C({config:n});g&&(c(s,g.message),process.exit(1));let r=a?.organizations??[];if(r.length>0){if(e.push(""),e.push(`Organizations (${r.length}):`),r.forEach(t=>{let w=t.id===o?">":" ";e.push(` ${w} ${t.name} (${t.id})`)}),o){let t=r.find(m=>m.id===o);t&&(e.push(""),e.push(`Active: ${t.name}`))}}else e.push(""),e.push("Organizations: None")}else e.push(""),e.push("Login method: Access Key Credentials"),e.push(" (Organization listing requires OAuth login: tigris login)");e.push(""),console.log(e.join(`
2
+ `))}catch(i){i instanceof Error?c(s,i.message):c(s),process.exit(1)}}export{y as default};