@tigrisdata/cli 2.5.0 → 2.6.1

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 (61) hide show
  1. package/dist/auth/client.js +1 -1
  2. package/dist/auth/config.js +1 -1
  3. package/dist/auth/s3-client.js +1 -1
  4. package/dist/auth/storage.js +1 -1
  5. package/dist/chunk-4BZ377KV.js +1 -0
  6. package/dist/chunk-4LGKN5DA.js +1 -0
  7. package/dist/chunk-A3TXP5Y2.js +2 -0
  8. package/dist/chunk-DYTBLGO7.js +1 -0
  9. package/dist/chunk-HGIJOGCZ.js +6 -0
  10. package/dist/chunk-I3FOSZPG.js +1 -0
  11. package/dist/chunk-IACJQZUD.js +4 -0
  12. package/dist/chunk-IY46B353.js +12 -0
  13. package/dist/chunk-JRALYIRA.js +1 -0
  14. package/dist/chunk-NYAHHQ3A.js +1 -0
  15. package/dist/chunk-PKWQDQLT.js +1 -0
  16. package/dist/chunk-TQWT7ROJ.js +1 -0
  17. package/dist/chunk-WE6NZ2ZK.js +1 -0
  18. package/dist/cli.js +1 -12
  19. package/dist/constants.js +1 -1
  20. package/dist/index.js +1 -12
  21. package/dist/lib/access-keys/assign.js +2 -3
  22. package/dist/lib/access-keys/create.js +2 -3
  23. package/dist/lib/access-keys/delete.js +2 -3
  24. package/dist/lib/access-keys/get.js +2 -3
  25. package/dist/lib/access-keys/list.js +2 -8
  26. package/dist/lib/buckets/create.js +1 -2
  27. package/dist/lib/buckets/delete.js +1 -2
  28. package/dist/lib/buckets/get.js +1 -7
  29. package/dist/lib/buckets/list.js +1 -7
  30. package/dist/lib/buckets/set.js +1 -2
  31. package/dist/lib/configure/index.js +1 -2
  32. package/dist/lib/cp.js +1 -1
  33. package/dist/lib/credentials/test.js +1 -2
  34. package/dist/lib/forks/create.js +1 -2
  35. package/dist/lib/forks/list.js +1 -7
  36. package/dist/lib/login/credentials.js +1 -2
  37. package/dist/lib/login/oauth.js +1 -5
  38. package/dist/lib/login/select.js +1 -5
  39. package/dist/lib/logout.js +1 -2
  40. package/dist/lib/ls.js +1 -6
  41. package/dist/lib/mk.js +1 -1
  42. package/dist/lib/mv.js +1 -1
  43. package/dist/lib/objects/delete.js +1 -2
  44. package/dist/lib/objects/get.js +1 -2
  45. package/dist/lib/objects/list.js +1 -7
  46. package/dist/lib/objects/put.js +1 -7
  47. package/dist/lib/organizations/create.js +2 -3
  48. package/dist/lib/organizations/list.js +2 -8
  49. package/dist/lib/organizations/select.js +4 -5
  50. package/dist/lib/rm.js +1 -1
  51. package/dist/lib/snapshots/list.js +1 -7
  52. package/dist/lib/snapshots/take.js +1 -2
  53. package/dist/lib/touch.js +1 -1
  54. package/dist/lib/whoami.js +2 -3
  55. package/dist/specs.yaml +0 -1
  56. package/dist/utils/format.js +1 -6
  57. package/dist/utils/messages.js +1 -2
  58. package/dist/utils/options.js +1 -1
  59. package/dist/utils/path.js +1 -1
  60. package/dist/utils/specs.js +1 -1
  61. package/package.json +4 -3
@@ -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{b as a}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{a as m,f as p}from"../../chunk-HGIJOGCZ.js";import{a as e}from"../../chunk-JRALYIRA.js";import"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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{readFileSync as Oe,statSync as Pe}from"fs";function g(e,n,t){for(let o of n)if(e[o]!==void 0)return e[o];return t}function se(e){return JSON.stringify(e,null,2)}function ae(e,n=" "){return Object.entries(e).map(([t,o])=>`${n}<${t}>${o}</${t}>`).join(`
2
- `)}function ce(e,n,t){let o=[`<${n}>`];return e.forEach(i=>{o.push(` <${t}>`),o.push(ae(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 de(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=de(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((m,y)=>{let C=F(c[m.key]);return m.align==="right"?C.padStart(o[y]):C.padEnd(o[y])});t.push("\u2502 "+p.join(" \u2502 ")+" \u2502")}),t.push(s+`
5
- `),t.join(`
6
- `)}function L(e,n,t,o,i){switch(n){case"json":return se(e);case"xml":return ce(e,t,o);default:return pe(e,i)}}import{S3Client as Qe}from"@aws-sdk/client-s3";import{fromIni as ye}from"@aws-sdk/credential-providers";import{homedir as j}from"os";import{join as h}from"path";import{readFileSync as ue,writeFileSync as ge,existsSync as S,mkdirSync as le}from"fs";import{loadSharedConfigFiles as fe}from"@smithy/shared-ini-file-loader";import{chmod as me}from"fs/promises";var u="https://t3.storage.dev",k="https://iam.storageapi.dev";var E=h(j(),".tigris"),w=h(E,"config.json");function he(){S(E)||le(E,{recursive:!0,mode:448})}function d(){if(S(w))try{let e=ue(w,"utf8");return JSON.parse(e)}catch{return{}}return{}}async function A(e){he(),ge(w,JSON.stringify(e,null,2),{mode:384});try{await me(w,384)}catch{}}async function v(e){let n=d();n.tokens=e,await A(n)}async function T(){return d().tokens||null}async function O(){let e=d();delete e.tokens,await A(e)}async function G(e){let n=d();n.organizations=e,await A(n)}function $(){return d().organizations||[]}function P(){return d().selectedOrganization||null}function U(){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 B(){if(!process.env.AWS_PROFILE)return!1;let e=h(j(),".aws");return S(h(e,"credentials"))||S(h(e,"config"))}async function W(e){try{let{configFile:n}=await fe(),t=n[e];return t?{endpoint:t.endpoint_url_s3||t.endpoint_url,iamEndpoint:t.endpoint_url_iam,region:t.region}:{}}catch{return{}}}function M(){let e=d();return e.temporaryCredentials||e.credentials||null}async function V(e){let n=d();n.loginMethod=e,await A(n)}function Y(){return d().loginMethod||null}import I from"axios";import Te from"open";function _(){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 J(){return process.env.TIGRIS_STORAGE_ENDPOINT||process.env.TIGRIS_IAM_ENDPOINT?{endpoint:process.env.TIGRIS_STORAGE_ENDPOINT||u,iamEndpoint:process.env.TIGRIS_IAM_ENDPOINT||k}:{endpoint:process.env.AWS_ENDPOINT_URL_S3||u,iamEndpoint:process.env.AWS_ENDPOINT_URL_IAM||k}}var b=class{config;baseUrl;constructor(){this.config=_(),this.baseUrl=`https://${this.config.domain}`}async login(n){let o=(await I.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 Te(o.verification_uri_complete)}catch{}n?.onWaiting?.();let i=await this.pollForToken(o.device_code,o.interval||5);await v(i),V("oauth"),await this.extractAndStoreOrganizations(i.idToken)}async pollForToken(n,t){let i=0;for(;i<60;){i++;try{let s=(await I.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(I.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 T();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 T(),!t)throw new Error('No refresh token available. Please run "tigris login" to re-authenticate.');try{let i=(await I.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 v(r),r}catch{throw await O(),new Error('Token refresh failed. Please run "tigris login" to re-authenticate.')}}async getIdTokenClaims(){let n=await T();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;G(s)}catch{}}async getOrganizations(){return await this.getAccessToken(),$()}async logout(){await O()}async isAuthenticated(){return await T()!==null}sleep(n){return new Promise(t=>setTimeout(t,n))}},N=null;function H(){return N||(N=new b),N}var x=J(),Ce=_();async function Se(){return Y()}async function X(){if(B()){let o=process.env.AWS_PROFILE||"default",i=await W(o),r=await ye({profile:o})();return{accessKeyId:r.accessKeyId,secretAccessKey:r.secretAccessKey,endpoint:i.endpoint||x.endpoint||u,iamEndpoint:i.iamEndpoint||x.iamEndpoint}}let e=await Se();if(e==="oauth"){let i=await H().getAccessToken();if(!P())throw new Error('No organization selected. Please run "tigris orgs select" first.');return{sessionToken:i,accessKeyId:"",secretAccessKey:"",endpoint:x.endpoint,organizationId:P()??void 0,iamEndpoint:x.iamEndpoint,authDomain:Ce.domain}}if(e==="credentials"){let o=M();if(o)return{accessKeyId:o.accessKeyId,secretAccessKey:o.secretAccessKey,endpoint:o.endpoint}}let n=U();if(n)return{accessKeyId:n.accessKeyId,secretAccessKey:n.secretAccessKey,endpoint:n.endpoint};let t=M();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{put as Me}from"@tigrisdata/storage";import{readFileSync as we,existsSync as Ae}from"fs";import{join as Q,dirname as _e}from"path";import{fileURLToPath as Ie}from"url";import*as Z from"yaml";var xe=Ie(import.meta.url),ke=_e(xe),D=null;function Ee(){let e=ke;for(let n=0;n<5;n++){let t=Q(e,"specs.yaml");if(Ae(t))return t;e=Q(e,"..")}throw new Error("Could not find specs.yaml")}function ve(){if(!D){let e=Ee(),n=we(e,"utf8");D=Z.parse(n)}return D}function ee(e,n){let o=ve().commands.find(i=>i.name===e);return o?n&&o.operations?o.operations.find(i=>i.name===n)||null:o:null}var ne={success:"\u2714",failure:"\u2716",hint:"\u2192"};function te(){return process.stdout.isTTY===!0}function R(e){let n=ee(e.command,e.operation);if(n)return n.messages}function K(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(!te())return;let t=R(e);t?.onStart&&console.log(K(t.onStart,n))}function ie(e,n){if(!te())return;let t=R(e);t?.onSuccess&&console.log(`${ne.success} ${K(t.onSuccess,n)}`)}function f(e,n,t){let o=R(e);o?.onFailure&&console.error(`${ne.failure} ${K(o.onFailure,t)}`),n&&console.error(` ${n}`)}function re(e,n){return{command:e,operation:n}}var l=re("objects","put");async function Ne(e){oe(l);let n=g(e,["bucket"]),t=g(e,["key"]),o=g(e,["file"]),i=g(e,["access","a","A"],"private"),r=g(e,["content-type","contentType","t","T"]),s=g(e,["format","f","F"],"table");n||(f(l,"Bucket name is required"),process.exit(1)),t||(f(l,"Object key is required"),process.exit(1)),o||(f(l,"File path is required"),process.exit(1));try{Pe(o)}catch{f(l,`File not found: ${o}`),process.exit(1)}let a=await X(),c=Oe(o),{data:p,error:m}=await Me(t,c,{access:i==="public"?"public":"private",contentType:r,config:{...a,bucket:n}});m&&(f(l,m.message),process.exit(1));let y=[{path:p.path,size:be(p.size),contentType:p.contentType||"-",modified:p.modified}],C=L(y,s,"objects","object",[{key:"path",header:"Path"},{key:"size",header:"Size"},{key:"contentType",header:"Content-Type"},{key:"modified",header:"Modified"}]);console.log(C),ie(l,{key:t,bucket:n})}function be(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{Ne 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{b as l}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{a as n,f as g}from"../../chunk-HGIJOGCZ.js";import{a as t}from"../../chunk-JRALYIRA.js";import"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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{b as s}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{a as e}from"../../chunk-JRALYIRA.js";import{k as r,s as a}from"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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{b as h}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{f as z}from"../../chunk-HGIJOGCZ.js";import{a as d}from"../../chunk-JRALYIRA.js";import{f as m,g as u,k as p,s as f}from"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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{b as u}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{a as g}from"../../chunk-JRALYIRA.js";import{f as c,k as l,s as m}from"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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 y,b as k,d as x}from"../chunk-I3FOSZPG.js";import{b as A}from"../chunk-TQWT7ROJ.js";import"../chunk-WE6NZ2ZK.js";import"../chunk-NYAHHQ3A.js";import{a as $}from"../chunk-JRALYIRA.js";import"../chunk-PKWQDQLT.js";import"../chunk-4BZ377KV.js";import*as F from"readline";import{remove as w,removeBucket as I,list as P}from"@tigrisdata/storage";async function v(a){let n=F.createInterface({input:process.stdin,output:process.stdout});return new Promise(c=>{n.question(`${a} (y/N): `,e=>{n.close(),c(e.toLowerCase()==="y")})})}async function j(a){let n=$(a,["path"]),c=$(a,["force","f","F"]);n||(console.error("path argument is required"),process.exit(1));let{bucket:e,path:r}=y(n);e||(console.error("Invalid path"),process.exit(1));let s=await A();if(!r){if(!c&&!await v(`Are you sure you want to delete bucket '${e}'?`)){console.log("Aborted");return}let{error:t}=await I(e,{config:s});t&&(console.error(t.message),process.exit(1)),console.log(`Removed bucket '${e}'`);return}let m=n.includes("*"),f=r.endsWith("/");if(!m&&!f&&(f=await k(e,r,s)),m||f){let t=m?r.replace("*",""):r.endsWith("/")?r:`${r}/`,{items:d,error:h}=await x(e,t||void 0,s);h&&(console.error(h.message),process.exit(1));let u=d,i=t,R=u.some(o=>o.name===i),g=!1;if(!R){let{data:o}=await P({prefix:i,limit:1,config:{...s,bucket:e}});g=o?.items?.some(l=>l.name===i)||!1}let b=u.length+(g?1:0);if(b===0){console.log("No objects to remove");return}if(!c&&!await v(`Are you sure you want to delete ${b} object(s)?`)){console.log("Aborted");return}let p=0;for(let o of u){let{error:l}=await w(o.name,{config:{...s,bucket:e}});l?console.error(`Failed to remove ${o.name}: ${l.message}`):(console.log(`Removed ${e}/${o.name}`),p++)}if(g){let{error:o}=await w(i,{config:{...s,bucket:e}});o?console.error(`Failed to remove ${i}: ${o.message}`):(console.log(`Removed ${e}/${i}`),p++)}console.log(`Removed ${p} object(s)`)}else{if(!c&&!await v(`Are you sure you want to delete '${e}/${r}'?`)){console.log("Aborted");return}let{error:t}=await w(r,{config:{...s,bucket:e}});t&&(console.error(t.message),process.exit(1)),console.log(`Removed ${e}/${r}`)}process.exit(0)}export{j 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{b as c}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{f as p}from"../../chunk-HGIJOGCZ.js";import{a as o}from"../../chunk-JRALYIRA.js";import"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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{b as m}from"../../chunk-TQWT7ROJ.js";import"../../chunk-WE6NZ2ZK.js";import"../../chunk-NYAHHQ3A.js";import{a as n}from"../../chunk-JRALYIRA.js";import"../../chunk-PKWQDQLT.js";import"../../chunk-4BZ377KV.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 s}from"../chunk-I3FOSZPG.js";import{b as c}from"../chunk-TQWT7ROJ.js";import"../chunk-WE6NZ2ZK.js";import"../chunk-NYAHHQ3A.js";import{a as i}from"../chunk-JRALYIRA.js";import"../chunk-PKWQDQLT.js";import"../chunk-4BZ377KV.js";import{put as p}from"@tigrisdata/storage";async function f(n){let r=i(n,["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 c(),{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-TQWT7ROJ.js";import{b as z}from"../chunk-WE6NZ2ZK.js";import"../chunk-NYAHHQ3A.js";import{g as f,k as p,s as A}from"../chunk-PKWQDQLT.js";import"../chunk-4BZ377KV.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};
package/dist/specs.yaml CHANGED
@@ -680,7 +680,6 @@ commands:
680
680
  - name: file
681
681
  description: Path to the file to upload
682
682
  type: positional
683
- required: true
684
683
  examples:
685
684
  - ./my-file.txt
686
685
  - name: access
@@ -1,6 +1 @@
1
- function m(n){return JSON.stringify(n,null,2)}function l(n,e=" "){return Object.entries(n).map(([t,r])=>`${e}<${t}>${r}</${t}>`).join(`
2
- `)}function T(n,e,t){let r=[`<${e}>`];return n.forEach(o=>{r.push(` <${t}>`),r.push(l(o," ")),r.push(` </${t}>`)}),r.push(`</${e}>`),r.join(`
3
- `)}function p(n){if(n==null)return"";if(n instanceof Date)return f(n);if(typeof n=="string"){let e=new Date(n);if(!isNaN(e.getTime())&&n.includes("T"))return f(e)}return String(n)}function f(n){return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(n)}function w(n,e){return e.map(t=>{if(t.width)return t.width;let r=t.header.length,o=n.reduce((s,u)=>{let a=p(u[t.key]);return Math.max(s,a.length)},0);return Math.max(r,o)})}function x(n,e){let t=[],r=w(n,e),o="\u250C"+r.map(i=>"\u2500".repeat(i+2)).join("\u252C")+"\u2510",s="\u251C"+r.map(i=>"\u2500".repeat(i+2)).join("\u253C")+"\u2524",u="\u2514"+r.map(i=>"\u2500".repeat(i+2)).join("\u2534")+"\u2518";t.push(`
4
- `+o);let a="\u2502 "+e.map((i,d)=>i.header.padEnd(r[d])).join(" \u2502 ")+" \u2502";return t.push(a),t.push(s),n.forEach(i=>{let d=e.map((c,g)=>{let h=p(i[c.key]);return c.align==="right"?h.padStart(r[g]):h.padEnd(r[g])});t.push("\u2502 "+d.join(" \u2502 ")+" \u2502")}),t.push(u+`
5
- `),t.join(`
6
- `)}function j(n,e,t,r,o){switch(e){case"json":return m(n);case"xml":return T(n,t,r);default:return x(n,o)}}export{m as formatJson,j as formatOutput,x as formatTable,T as formatXml,l as formatXmlObject};
1
+ import{a,b,c,d,e,f}from"../chunk-HGIJOGCZ.js";export{b as formatJson,f as formatOutput,a as formatSize,e as formatTable,d as formatXml,c as formatXmlObject};
@@ -1,2 +1 @@
1
- import{readFileSync as f,existsSync as d}from"fs";import{join as m,dirname as S}from"path";import{fileURLToPath as C}from"url";import*as l from"yaml";var M=C(import.meta.url),x=S(M),c=null;function y(){let n=x;for(let e=0;e<5;e++){let s=m(n,"specs.yaml");if(d(s))return s;n=m(n,"..")}throw new Error("Could not find specs.yaml")}function A(){if(!c){let n=y(),e=f(n,"utf8");c=l.parse(e)}return c}function g(n,e){let t=A().commands.find(r=>r.name===n);return t?e&&t.operations?t.operations.find(r=>r.name===e)||null:t:null}var p={success:"\u2714",failure:"\u2716",hint:"\u2192"};function a(){return process.stdout.isTTY===!0}function o(n){let e=g(n.command,n.operation);if(e)return e.messages}function i(n,e){let s=n;return s=s.replace(/\\n/g,`
2
- `),e&&(s=s.replace(/\{\{(\w+)\}\}/g,(t,r)=>{let u=e[r];return u!==void 0?String(u):`{{${r}}}`})),s}function O(n,e){if(!a())return;let s=o(n);s?.onStart&&console.log(i(s.onStart,e))}function P(n,e){if(!a())return;let s=o(n);s?.onSuccess&&console.log(`${p.success} ${i(s.onSuccess,e)}`)}function T(n,e,s){let t=o(n);t?.onFailure&&console.error(`${p.failure} ${i(t.onFailure,s)}`),e&&console.error(` ${e}`)}function _(n,e){if(!a())return;let s=o(n);s?.onEmpty&&console.log(i(s.onEmpty,e))}function j(n,e){if(!a())return;let s=o(n);s?.onAlreadyDone&&console.log(i(s.onAlreadyDone,e))}function D(n,e){if(!a())return;let s=o(n);s?.hint&&console.log(`${p.hint} ${i(s.hint,e)}`)}function E(n,e){return{command:n,operation:e}}export{E as msg,j as printAlreadyDone,_ as printEmpty,T as printFailure,D as printHint,O as printStart,P as printSuccess};
1
+ import{a,b,c,d,e,f,g}from"../chunk-A3TXP5Y2.js";import"../chunk-4LGKN5DA.js";export{g as msg,e as printAlreadyDone,d as printEmpty,c as printFailure,f as printHint,a as printStart,b as printSuccess};
@@ -1 +1 @@
1
- function t(n,r,o){for(let e of r)if(n[e]!==void 0)return n[e];return o}function f(n){if(n!==void 0)return typeof n=="boolean"?n:n==="true"}export{t as getOption,f as parseBoolean};
1
+ import{a,b}from"../chunk-JRALYIRA.js";export{a as getOption,b as parseBoolean};
@@ -1 +1 @@
1
- import{list as g}from"@tigrisdata/storage";function a(i){let t=i.split("/");return{bucket:t[0],path:t.slice(1).join("/")}}async function p(i,t,s){let{data:e}=await g({prefix:`${t}/`,limit:1,config:{...s,bucket:i}});return!!(e?.items&&e.items.length>0)}function f(i,t){return{source:a(i),destination:a(t)}}async function d(i,t,s){let e=[],n;do{let{data:r,error:o}=await g({prefix:t,paginationToken:n,config:{...s,bucket:i}});if(o)return{items:e,error:o};r?.items&&e.push(...r.items),n=r?.hasMore?r.paginationToken:void 0}while(n);return{items:e}}export{p as isPathFolder,d as listAllItems,a as parsePath,f as parsePaths};
1
+ import{a,b,c,d}from"../chunk-I3FOSZPG.js";export{b as isPathFolder,d as listAllItems,a as parsePath,c as parsePaths};
@@ -1 +1 @@
1
- import{readFileSync as c,existsSync as m}from"fs";import{join as o,dirname as p}from"path";import{fileURLToPath as l}from"url";import*as a from"yaml";var u=l(import.meta.url),f=p(u),i=null;function d(){let e=f;for(let n=0;n<5;n++){let t=o(e,"specs.yaml");if(m(t))return t;e=o(e,"..")}throw new Error("Could not find specs.yaml")}function g(){if(!i){let e=d(),n=c(e,"utf8");i=a.parse(n)}return i}function S(e,n){let r=g().commands.find(s=>s.name===e);return r?n&&r.operations?r.operations.find(s=>s.name===n)||null:r:null}function h(e,n,t){let r=S(e,t);return!r||!r.arguments?null:r.arguments.find(s=>s.name===n)||null}function v(e){return e.options?Array.isArray(e.options)&&typeof e.options[0]=="string"?e.options.map(n=>({name:n,message:n.charAt(0).toUpperCase()+n.slice(1),value:n})):Array.isArray(e.options)&&typeof e.options[0]=="object"?e.options.map(n=>({name:n.value,message:n.description?`${n.name} - ${n.description}`:n.name,value:n.value})):null:null}export{v as buildPromptChoices,h as getArgumentSpec,S as getCommandSpec};
1
+ import{a,b,c,d}from"../chunk-4LGKN5DA.js";export{d as buildPromptChoices,c as getArgumentSpec,b as getCommandSpec,a as loadSpecs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tigrisdata/cli",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "Command line interface for Tigris object storage",
5
5
  "type": "module",
6
6
  "exports": {
@@ -81,10 +81,11 @@
81
81
  "@aws-sdk/credential-providers": "^3.981.0",
82
82
  "@smithy/shared-ini-file-loader": "^4.4.3",
83
83
  "@tigrisdata/iam": "^1.1.0",
84
- "@tigrisdata/storage": "^2.12.0",
84
+ "@tigrisdata/storage": "^2.12.2",
85
85
  "axios": "^1.12.2",
86
86
  "commander": "^11.0.0",
87
87
  "enquirer": "^2.4.1",
88
+ "jose": "^6.1.3",
88
89
  "open": "^10.2.0",
89
90
  "yaml": "^2.3.4"
90
91
  },
@@ -101,7 +102,7 @@
101
102
  "husky": "^8.0.0",
102
103
  "prettier": "^3.0.0",
103
104
  "publint": "^0.2.0",
104
- "semantic-release": "^25.0.2",
105
+ "semantic-release": "^25.0.3",
105
106
  "tsup": "^8.0.0",
106
107
  "tsx": "^4.21.0",
107
108
  "typescript": "^5.0.0",