ec.fdk 0.8.9 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +3 -3
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";const Y=require("node:util"),Q=require("node:module"),D=require("node:fs"),j=require("node:path"),Z=require("node:os"),ee=require("node:readline");async function u(t,e={},n={}){const{token:r,rawRes:a}=e;r&&(n.headers={...n.headers||{},Authorization:`Bearer ${r}`});const i=await fetch(t,n);if(!i.ok){if(i.headers.get("content-type")?.includes("application/json")){const s=await i.json(),c=`${s.title}
|
|
3
3
|
${s.detail}
|
|
4
|
-
${s.verbose}`;throw new Error(c)}throw new Error(`unexpected fetch error: ${i.statusText}`)}if(a)return i;if(i.status===204)return;const o=await i.text();return o?JSON.parse(o):void 0}const v={datamanager:{live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"},accounts:{live:"https://accounts.entrecode.de/",stage:"https://accounts.cachena.entrecode.de/"},appserver:{live:"https://appserver.entrecode.de/",stage:"https://appserver.cachena.entrecode.de/"},"dm-history":{live:"https://dm-history.entrecode.de/",stage:"https://dm-history.cachena.entrecode.de/"}};function f(t,e="stage",n="datamanager"){const r=v[n];if(!r)throw new Error(`subdomain "${n}" not found. Try one of ${Object.keys(v).join(", ")}`);const a=r[e];if(!a)throw new Error(`env "${e}" not found. Try one of ${Object.keys(r[e]).join(", ")}`);return a+t}function h(t,e=!0){return Object.entries(t).sort((n,r)=>n[0].localeCompare(r[0])).map(([n,r])=>`${n}=${r}`).join("&")}function d(t){Object.entries(t).forEach(([e,n])=>{if(n===void 0)throw new Error(`expected ${e} to be set!`)})}const N={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};async function te(t){let{env:e,dmShortID:n,email:r,password:a}=t;d({env:e,dmShortID:n,email:r,password:a});const i=f(`api/${n}/_auth/login?clientID=rest`,e);return await u(i,{},{method:"POST",body:JSON.stringify({email:r,password:a}),headers:{"Content-Type":"application/json"}})}async function ne(t){let{env:e,email:n,password:r}=t;d({env:e,email:n,password:r});const a=`${N[e]}auth/login?clientID=rest`;return await u(a,{},{method:"POST",body:JSON.stringify({email:n,password:r}),headers:{"Content-Type":"application/json"}})}async function re(t){let{dmShortID:e,env:n,token:r}=t;d({dmShortID:e,env:n,token:r});const a=f(`api/${e}/_auth/logout?clientID=rest&token=${r}`,n);return await u(a,{rawRes:!0},{method:"POST"})}async function ae(t){let{env:e,token:n}=t;d({env:e,token:n});const r=`${N[e]}auth/logout?clientID=rest`;return await u(r,{rawRes:!0,token:n},{method:"POST"})}function ie({dmShortID:t}){return d({dmShortID:t}),t}function se({env:t}){return d({env:t}),t}let oe=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function J(t){let e={};for(let n in t)oe.includes(n)||(e[n]=t[n]);return e}function ce(t){return JSON.parse(JSON.stringify(t))}async function de(t){let{env:e,dmShortID:n}=t;d({env:e,dmShortID:n});const r=f(`api/${n}`,e);return u(r,t)}async function x(t){let{env:e,dmShortID:n,model:r,options:a={}}=t;d({env:e,dmShortID:n,model:r}),a={size:50,page:1,_list:!0,...a};const i=h(a),o=f(`api/${n}/${r}?${i}`,e),{count:s,total:c,_embedded:g}=await u(o,t);let m=g?g[`${n}:${r}`]:[];return m=Array.isArray(m)?m:[m],{count:s,total:c,items:m}}function ue({env:t,dmShortID:e,model:n,entryID:r,token:a}){d({env:t,dmShortID:e,model:n,entryID:r});const i=h({_id:r}),o=f(`api/${e}/${n}?${i}`,t);return u(o,{token:a})}async function le({env:t,dmShortID:e,model:n,value:r,token:a}){d({env:t,dmShortID:e,model:n,value:r});const i=f(`api/${e}/${n}`,t);return await u(i,{token:a},{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}async function F({env:t,dmShortID:e,model:n,entryID:r,value:a,token:i,safePut:o=!1}){d({env:t,dmShortID:e,model:n,entryID:r,value:a});const s={"Content-Type":"application/json"};if(o){if(!("_modified"in a))throw new Error("expected _modified to be set!");s["If-Unmodified-Since"]=new Date(a._modified).toUTCString()}const c=f(`api/${e}/${n}?_id=${r}`,t);return a=ce(a),a=J(a),await u(c,{token:i},{method:"PUT",headers:s,body:JSON.stringify(a)})}function z({env:t,dmShortID:e,model:n,entryID:r,token:a}){d({env:t,dmShortID:e,model:n,entryID:r});const i=f(`api/${e}/${n}?_id=${r}`,t);return u(i,{token:a,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}async function fe(t,e){let{env:n,dmShortID:r,model:a,options:i={}}=t;d({env:n,dmShortID:r,model:a}),t.options={size:50,page:1,_list:!0,...i};let o=0,s,c=[];for(;s===void 0||o<s;){const g=await x(t);for(let m of g.items)c.push(await e(m));o+=g.items.length,s=g.total,t.options.page++}return c}async function ge({env:t,dmShortID:e,model:n,withMetadata:r}){d({env:t,dmShortID:e,model:n});const a=f(`api/schema/${e}/${n}`,t),i=await u(a),o=i?.allOf?.[1];if(typeof o.properties!="object")throw new Error(`getSchema: ${a} returned unexpected format: ${JSON.stringify(i)}`);const{properties:s}=o,c=J(s);for(let g in c){let m=c[g];if(m.required=o.required.includes(g),c[g]?.oneOf&&delete c[g]?.oneOf,m.title?.includes("<")&&m.title?.includes(">")){const k=m.title.split("<")[1].slice(0,-1),w=m.title.split("<")[0];m.type=w,k.includes(":")?m.resource=k.split(":")[1]:m.resource=k}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete c[g].title}if(r){const g=s._modelTitle.title,m=s._modelTitleField.title;return{properties:c,meta:{modelTitleField:m,modelTitle:g}}}return c}function H(t){return Object.entries(t).map(([e,n])=>typeof n!="object"?{[e]:String(n)}:{...n.sort&&{sort:Array.isArray(n)?n.join(","):n},...n.search&&{[e+"~"]:n.search},...n.notNull&&{[e+"!"]:""},...n.null&&{[e]:""},...n.any&&{[e]:n.any.join(",")},...n.from&&{[e+"From"]:n.from},...n.to&&{[e+"To"]:n.to}}).reduce((e,n)=>({...e,...n}),{})}const me=H;function U(t){return t._links.collection.href.split("/").slice(-2)[0]}function K(t){const e=t._links.collection.href.split("api/")[0];return Object.keys(v.datamanager).find(r=>v.datamanager[r]===e)}const V=t=>{const e=U(t),n=K(t),r=t._modelTitle,a=t.id;return{dmShortID:e,env:n,model:r,entryID:a}},he=t=>z(V(t)),pe=(t,e)=>F({...V(t),value:e});function ye(t,e){const n=U(e);return e._embedded[`${n}:${e._modelTitle}/${t}/asset`]}async function ke({env:t,dmShortID:e,assetGroup:n,assetID:r,token:a}){d({env:t,dmShortID:e,assetGroup:n,assetID:r});const i=h({assetID:r}),o=f(`a/${e}/${n}?${i}`,t),{_embedded:s}=await u(o,{token:a});return s?s["ec:dm-asset"]:void 0}async function we(t){let{env:e,dmShortID:n,assetGroup:r,token:a,options:i={}}=t;d({env:e,dmShortID:n,assetGroup:r}),i={size:50,page:1,_list:!0,...i};const o=h(i),s=f(`a/${n}/${r}?${o}`,e),{count:c,total:g,_embedded:m}=await u(s,{token:a});let k=m?m["ec:dm-asset"]:[];return k=Array.isArray(k)?k:[k],{count:c,total:g,items:k}}async function De({env:t,dmShortID:e,assetGroup:n,token:r,file:a,name:i,options:o}){d({env:t,dmShortID:e,assetGroup:n,file:a});const s=f(`a/${e}/${n}`,t),c=new FormData;return c.append("file",a,i),o&&Object.keys(o).forEach(m=>{c.append(m,o[m])}),(await u(s,{token:r},{method:"POST",body:c}))._embedded["ec:dm-asset"]}async function Te({env:t,dmShortID:e,assetGroup:n,files:r,options:a}){d({env:t,dmShortID:e,assetGroup:n,files:r});const i=f(`a/${e}/${n}`,t),o=new FormData;r.forEach(c=>{o.append("file",c)}),a&&Object.keys(a).forEach(c=>{o.append(c,a[c])});const s=await u(i,{},{method:"POST",body:o});return Array.isArray(s._embedded["ec:dm-asset"])?s._embedded["ec:dm-asset"]:[s._embedded["ec:dm-asset"]]}async function be({env:t,dmShortID:e,assetGroup:n,assetID:r,token:a}){d({env:t,dmShortID:e,assetGroup:n,assetID:r});const i=f(`a/${e}/${n}/${r}`,t);await u(i,{token:a,rawRes:!0},{method:"DELETE"})}function $e(t,e,n=!1){let r,a;return(n?t?.thumbnails:t?.fileVariants)?.forEach(o=>{const{resolution:{width:s,height:c}}=o,g=Math.abs(Math.max(s,c)-e);(!a||g<a)&&(a=g,r=o)}),r?.url??t?.file?.url??null}function Ae(t="stage",e,n,r,a=!1){const i=Math.max(r.file.resolution.width,r.file.resolution.height),o=n.filter(c=>c<i),s=`https://datamanager${t==="stage"?".cachena":""}.entrecode.de`;return a?o.map(c=>{const g=r.thumbnails.find(w=>c===w.dimension),m=`${s}/t/${e}/${r.assetID}/${c}`,k=g?g.url:m;return{size:c,url:k,generated:g}}):o.map(c=>{const g=r.fileVariants.find(w=>c===Math.max(w.resolution.width,w.resolution.height)),m=`${s}/f/${e}/${r.assetID}/${c}`,k=g?g.url:m;return{size:c,url:k,generated:g}})}const p={"Content-Type":"application/json"};async function Ee(t){let{env:e,dmID:n,token:r}=t;d({env:e,dmID:n});const a=f(`?dataManagerID=${n}`,e);return u(a,{token:r})}async function ve(t){let{env:e,options:n={}}=t;d({env:e}),n={size:25,page:1,_list:!0,...n};const r=h(n),a=f(`?${r}`,e),{count:i,total:o,_embedded:s}=await u(a,t);let c=s?s["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:i,total:o,items:c}}async function Ie(t){let{env:e,dmID:n,options:r={}}=t;d({env:e,dmID:n}),r={size:25,dataManagerID:n,page:1,_list:!0,...r};const a=h(r),i=f(`model?${a}`,e),{count:o,total:s,_embedded:c}=await u(i,t);let g=c?c["ec:model"]:[];return g=Array.isArray(g)?g:[g],{count:o,total:s,items:g}}async function Se(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager"}=t;d({env:e,subdomain:a,resource:n}),r={size:25,page:1,_list:!0,...r};const i=h(r),o=f(`${n}?${i}`,e,a),{count:s,total:c,_embedded:g}=await u(o,t);let m=g?g[Object.keys(g)[0]]:[];return m=Array.isArray(m)?m:[m],{count:s,total:c,items:m}}async function qe(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager"}=t;d({env:e,subdomain:a,resource:n});const i=h(r),o=f(`${n}?${i}`,e,a);return u(o,t)}async function Oe(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager",value:i}=t;d({env:e,subdomain:a,resource:n,value:i});const o=h(r),s=f(`${n}?${o}`,e,a);return u(s,t,{method:"PUT",body:JSON.stringify(i),headers:p})}async function Ue(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager"}=t;d({env:e,subdomain:a,resource:n});const i=h(r),o=f(`${n}?${i}`,e,a);return u(o,{...t,rawRes:!0},{method:"DELETE",headers:p})}async function Me(t,e={}){let{env:n,route:r,options:a={},subdomain:i="datamanager"}=t;d({env:n,subdomain:i,route:r}),a={...a};const o=h(a),s=f(`${r}?${o}`,n,i);return u(s,t,e)}async function Ce(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("",e);return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function Le(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`?${i}`,e);return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function _e(t){let{env:e,token:n,dmID:r}=t;d({env:e,dmID:r});const a=h({dataManagerID:r}),i=f(`?${a}`,e);return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function Re(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`model?${i}`,e);return u(o,{token:n},{method:"POST",body:JSON.stringify(a),headers:p})}async function Ge(t){let{env:e,token:n,dmID:r,modelID:a,value:i}=t;d({env:e,dmID:r,modelID:a,value:i});const o=h({dataManagerID:r,modelID:a}),s=f(`model?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Pe(t){let{env:e,token:n,dmID:r,modelID:a}=t;d({env:e,dmID:r,modelID:a});const i=h({dataManagerID:r,modelID:a}),o=f(`model?${i}`,e);return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function Be(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("template",e);return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function je(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`assetgroup?${i}`,e);return u(o,{token:n},{method:"POST",body:JSON.stringify(a),headers:p})}async function Ne(t){let{env:e,token:n,dmID:r,assetGroupID:a,value:i}=t;d({env:e,dmID:r,assetGroupID:a,value:i});const o=h({dataManagerID:r,assetGroupID:a}),s=f(`assetgroup?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Je(t){let{env:e,token:n,dmShortID:r,assetGroup:a,assetID:i,value:o}=t;d({env:e,dmShortID:r,assetGroup:a,assetID:i,value:o});const s=f(`a/${r}/${a}/${i}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(o),headers:p})}async function xe(t){let{env:e,token:n,dmID:r,clientID:a,value:i}=t;d({env:e,dmID:r,clientID:a,value:i});const o=h({dataManagerID:r,clientID:a}),s=f(`client?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Fe(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`role?${i}`,e);return u(o,{token:n},{method:"POST",body:JSON.stringify(a),headers:p})}async function ze(t){let{env:e,token:n,dmID:r,roleID:a,value:i}=t;d({env:e,dmID:r,roleID:a,value:i});const o=h({dataManagerID:r,roleID:a}),s=f(`role?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function He(t){let{env:e,token:n,dmID:r,roleID:a}=t;d({env:e,dmID:r,roleID:a});const i=h({dataManagerID:r,roleID:a}),o=f(`role?${i}`,e);return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function Ke(t){let{env:e,token:n,dmID:r,accountID:a,value:i}=t;d({env:e,dmID:r,accountID:a,value:i});const o=h({dataManagerID:r,accountID:a}),s=f(`account?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Ve(t){let{env:e,token:n,dmID:r,accountID:a}=t;d({env:e,dmID:r,accountID:a});const i=h({dataManagerID:r,accountID:a}),o=f(`account?${i}`,e);return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function We(t){let{env:e,token:n,options:r={}}=t;d({env:e});const a=h(r),i=f(`stats?${a}`,e);return u(i,{token:n})}async function Xe(t){let{env:e,token:n,options:r={}}=t;d({env:e});const a=h(r),i=f(`entries?${a}`,e,"dm-history");return u(i,{token:n})}async function Ye(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("client",e,"accounts");return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function Qe(t){let{env:e,token:n,clientID:r,value:a}=t;d({env:e,clientID:r,value:a});const i=h({clientID:r}),o=f(`client?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function Ze(t){let{env:e,token:n,clientID:r}=t;d({env:e,clientID:r});const a=h({clientID:r}),i=f(`client?${a}`,e,"accounts");return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function et(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("group",e,"accounts");return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function tt(t){let{env:e,token:n,groupID:r,value:a}=t;d({env:e,groupID:r,value:a});const i=h({groupID:r}),o=f(`group?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function nt(t){let{env:e,token:n,groupID:r}=t;d({env:e,groupID:r});const a=h({groupID:r}),i=f(`group?${a}`,e,"accounts");return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function rt(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("invite",e,"accounts"),i=await u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p});return i?._embedded?.["ec:invite"]??i}async function at(t){let{env:e,token:n,inviteID:r,value:a}=t;d({env:e,inviteID:r,value:a});const i=h({invite:r}),o=f(`invite?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function it(t){let{env:e,token:n,inviteID:r}=t;d({env:e,inviteID:r});const a=h({invite:r}),i=f(`invite?${a}`,e,"accounts");return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function st(t){let{env:e,token:n,accountID:r,value:a}=t;d({env:e,accountID:r,value:a});const i=h({accountID:r}),o=f(`account?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function ot(t){let{env:e,token:n,accountID:r}=t;d({env:e,accountID:r});const a=h({accountID:r}),i=f(`account/tokens?${a}`,e,"accounts");let s=(await u(i,{token:n}))?._embedded?.["ec:account/token"]??[];return Array.isArray(s)?s:[s]}async function ct(t){let{env:e,token:n,accountID:r}=t;d({env:e,accountID:r});const a=h({accountID:r}),i=f(`account/tokens?${a}`,e,"accounts");return u(i,{token:n},{method:"POST",headers:p})}async function dt(t){let{env:e,token:n,accountID:r,accessTokenID:a}=t;d({env:e,accountID:r,accessTokenID:a});const i=h({accessTokenID:a,accountID:r}),o=f(`account/tokens?${i}`,e,"accounts");return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}const ut=Object.freeze(Object.defineProperty({__proto__:null,assetList:we,createAccountClient:Ye,createAsset:De,createAssetGroup:je,createAssets:Te,createDatamanager:Ce,createEntry:le,createGroup:et,createInvite:rt,createModel:Re,createRole:Fe,createTemplate:Be,createToken:ct,deleteAccountClient:Ze,deleteAsset:be,deleteDatamanager:_e,deleteDmAccount:Ve,deleteEntry:z,deleteEntryObject:he,deleteGroup:nt,deleteInvite:it,deleteModel:Pe,deleteRole:He,deleteToken:dt,dmList:ve,editAccount:st,editAccountClient:Qe,editAsset:Je,editAssetGroup:Ne,editDatamanager:Le,editDmAccount:Ke,editDmClient:xe,editEntry:F,editEntryObject:pe,editGroup:tt,editInvite:at,editModel:Ge,editRole:ze,entryList:x,fileVariant:$e,filterOptions:me,getAsset:ke,getDatamanager:Ee,getEcAuthKey:se,getEntry:ue,getEntryAsset:ye,getEntryEnv:K,getEntryShortID:U,getFileVariants:Ae,getHistory:Xe,getPublicAuthKey:ie,getSchema:ge,getStats:We,listTokens:ot,loginEc:ne,loginPublic:te,logoutEc:ae,logoutPublic:re,mapEntries:fe,modelList:Ie,publicApi:de,raw:Me,resourceDelete:Ue,resourceEdit:Oe,resourceGet:qe,resourceList:Se,sdkOptions:H},Symbol.toStringTag,{value:"Module"})),{entryList:C,mapEntries:lt,getEntry:ft,getAsset:gt,assetList:L,createAsset:mt,createAssets:ht,deleteAsset:pt,createEntry:yt,editEntry:_,deleteEntry:kt,getSchema:wt,loginPublic:Dt,loginEc:Tt,logoutEc:bt,logoutPublic:$t,getEcAuthKey:b,getPublicAuthKey:$,dmList:At,modelList:Et,publicApi:vt,getDatamanager:It,resourceList:St,resourceGet:qt,resourceEdit:Ot,resourceDelete:Ut,raw:Mt,createDatamanager:Ct,editDatamanager:Lt,deleteDatamanager:_t,createModel:Rt,editModel:Gt,deleteModel:Pt,createTemplate:Bt,createAssetGroup:jt,editAssetGroup:Nt,editAsset:Jt,editDmClient:xt,createRole:Ft,editRole:zt,deleteRole:Ht,editDmAccount:Kt,deleteDmAccount:Vt,getStats:Wt,getHistory:Xt,createAccountClient:Yt,editAccountClient:Qt,deleteAccountClient:Zt,createGroup:en,editGroup:tn,deleteGroup:nn,createInvite:rn,editInvite:an,deleteInvite:sn,editAccount:on,listTokens:cn,createToken:dn,deleteToken:un}=ut;function R(t){if(!t||typeof t!="object")return t;const{_links:e,_embedded:n,...r}=t;return r}function ln(t){return!t||typeof t!="object"?t:Array.isArray(t.items)?{...t,items:t.items.map(R)}:R(t)}class M{constructor(e={}){if(!e.storageAdapter){let n=new Map;e.storageAdapter={get:r=>n.get(r),set:(r,a)=>n.set(r,a),remove:r=>n.delete(r)}}this.config=e}set(e){return new M({...this.config,...e})}async entries(e={}){const n=await this.getBestToken();return C({...this.config,options:e,token:n})}async entryList(e){const n=await this.getBestToken();return C({...this.config,options:e,token:n}).then(r=>this.maybeClean(r))}async mapEntries(e,n={}){const r=await this.getBestToken();return lt({...this.config,options:n,token:r},e)}async getEntry(e){const n=await this.getBestToken();return ft({...this.config,entryID:e,token:n}).then(r=>this.maybeClean(r))}async editEntrySafe(e,n){const r=await this.getBestToken();return _({...this.config,entryID:e,token:r,value:n,safePut:!0}).then(a=>this.maybeClean(a))}async getSchema(){return wt(this.config)}async assets(e){const n=await this.getBestToken();return L({...this.config,options:e,token:n})}async assetList(e){const n=await this.getBestToken();return L({...this.config,options:e,token:n})}async createAsset(e){const{file:n,name:r,options:a}=e,i=await this.getBestToken();return mt({...this.config,file:n,name:r,options:a,token:i})}async createAssets(e){const{files:n,options:r}=e,a=await this.getBestToken();return ht({...this.config,files:n,options:r,token:a})}async deleteAsset(e){const n=await this.getBestToken();return pt({...this.config,token:n,assetID:e})}async getAsset(e){const n=await this.getBestToken();return gt({...this.config,assetID:e,token:n})}async createEntry(e){const n=await this.getBestToken();return yt({...this.config,token:n,value:e}).then(r=>this.maybeClean(r))}async editEntry(e,n){const r=await this.getBestToken();return _({...this.config,entryID:e,token:r,value:n}).then(a=>this.maybeClean(a))}async deleteEntry(e){const n=await this.getBestToken();return kt({...this.config,token:n,entryID:e})}async resourceList(e){const n=await this.getBestToken();return St({...this.config,options:e,token:n})}async resourceGet(e){const n=await this.getBestToken();return qt({...this.config,options:e,token:n})}async resourceEdit(e,n){const r=await this.getBestToken();return Ot({...this.config,options:e,token:r,value:n})}async resourceDelete(e){const n=await this.getBestToken();return Ut({...this.config,options:e,token:n})}async raw(e,n){const r=await this.getBestToken();return Mt({...this.config,options:e,token:r},n)}async createDatamanager(e){const n=await this.getBestToken();return Ct({...this.config,token:n,value:e})}async editDatamanager(e,n){const r=await this.getBestToken();return Lt({...this.config,token:r,dmID:e,value:n})}async deleteDatamanager(e){const n=await this.getBestToken();return _t({...this.config,token:n,dmID:e})}async createModel(e){const n=await this.getBestToken();return Rt({...this.config,token:n,value:e})}async editModel(e,n){const r=await this.getBestToken();return Gt({...this.config,token:r,modelID:e,value:n})}async deleteModel(e){const n=await this.getBestToken();return Pt({...this.config,token:n,modelID:e})}async createTemplate(e){const n=await this.getBestToken();return Bt({...this.config,token:n,value:e})}async createAssetGroup(e){const n=await this.getBestToken();return jt({...this.config,token:n,value:e})}async editAssetGroup(e,n){const r=await this.getBestToken();return Nt({...this.config,token:r,assetGroupID:e,value:n})}async editAsset(e,n){const r=await this.getBestToken();return Jt({...this.config,token:r,assetID:e,value:n})}async editDmClient(e,n){const r=await this.getBestToken();return xt({...this.config,token:r,clientID:e,value:n})}async createRole(e){const n=await this.getBestToken();return Ft({...this.config,token:n,value:e})}async editRole(e,n){const r=await this.getBestToken();return zt({...this.config,token:r,roleID:e,value:n})}async deleteRole(e){const n=await this.getBestToken();return Ht({...this.config,token:n,roleID:e})}async editDmAccount(e,n){const r=await this.getBestToken();return Kt({...this.config,token:r,accountID:e,value:n})}async deleteDmAccount(e){const n=await this.getBestToken();return Vt({...this.config,token:n,accountID:e})}async getStats(e={}){const n=await this.getBestToken();return Wt({...this.config,token:n,options:e})}async getHistory(e={}){const n=await this.getBestToken();return Xt({...this.config,token:n,options:e})}async createAccountClient(e){const n=await this.getBestToken();return Yt({...this.config,token:n,value:e})}async editAccountClient(e,n){const r=await this.getBestToken();return Qt({...this.config,token:r,clientID:e,value:n})}async deleteAccountClient(e){const n=await this.getBestToken();return Zt({...this.config,token:n,clientID:e})}async createGroup(e){const n=await this.getBestToken();return en({...this.config,token:n,value:e})}async editGroup(e,n){const r=await this.getBestToken();return tn({...this.config,token:r,groupID:e,value:n})}async deleteGroup(e){const n=await this.getBestToken();return nn({...this.config,token:n,groupID:e})}async createInvite(e){const n=await this.getBestToken();return rn({...this.config,token:n,value:e})}async editInvite(e,n){const r=await this.getBestToken();return an({...this.config,token:r,inviteID:e,value:n})}async deleteInvite(e){const n=await this.getBestToken();return sn({...this.config,token:n,inviteID:e})}async editAccount(e,n){const r=await this.getBestToken();return on({...this.config,token:r,accountID:e,value:n})}async listTokens(e){const n=await this.getBestToken();return cn({...this.config,token:n,accountID:e})}async createToken(e){const n=await this.getBestToken();return dn({...this.config,token:n,accountID:e})}async deleteToken(e,n){const r=await this.getBestToken();return un({...this.config,token:r,accountID:e,accessTokenID:n})}storageAdapter(e){return this.set({storageAdapter:e})}removeToken(e){if(!this.config.storageAdapter)throw new Error("cannot removeToken: no storageAdapter defined!");const{remove:n}=this.config.storageAdapter;n(e)}getToken(e){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:n}=this.config.storageAdapter;return n(e)}getPublicToken(){return this.config.token||this.getToken($(this.config))}getEcToken(){return this.config.token||this.getToken(b(this.config))}setToken(e,n){if(!this.config.storageAdapter)throw new Error("cannot setEcToken: no storageAdapter defined!");return this.config.storageAdapter.set(e,n)}setEcToken(e){this.setToken(b(this.config),e)}setPublicToken(e){this.setToken($(this.config),e)}loginEc(e){return Tt({...this.config,...e}).then(n=>this.setToken(b(this.config),n.token))}loginPublic(e){return Dt({...this.config,...e}).then(n=>this.setToken($(this.config),n.token))}logoutPublic(){const e=this.getPublicToken();return $t({...this.config,token:e}).then(()=>this.removeToken($(this.config)))}logoutEc(){const e=this.getEcToken();return bt({...this.config,token:e}).then(()=>this.removeToken(b(this.config)))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch{return}}clean(e=!0){return this.set({_clean:e})}maybeClean(e){return this.config._clean?ln(e):e}model(e){return this.set({model:e})}token(e){return this.set({token:e})}dmShortID(e){return this.set({dmShortID:e})}dm(e){return this.dmShortID(e)}dmID(e){return this.set({dmID:e})}assetGroup(e){return this.set({assetGroup:e})}assetgroup(e){return this.assetGroup(e)}subdomain(e){return this.set({subdomain:e})}resource(e){return this.set({resource:e})}route(e){return this.set({route:e})}publicApi(){return vt(this.config)}async getDatamanager(e){const n=await this.getBestToken();return It({...this.config,dmID:e,token:n})}async dmList(e={}){const n=await this.getBestToken();return At({...this.config,options:e,token:n})}async modelList(e={}){const n=await this.getBestToken();return Et({...this.config,options:e,token:n})}}const q=j.join(Z.homedir(),".ec-fdk"),O=j.join(q,"auth.json");function S(){try{return D.existsSync(O)?JSON.parse(D.readFileSync(O,"utf-8")):{}}catch{return{}}}function G(t){D.existsSync(q)||D.mkdirSync(q,{recursive:!0,mode:448}),D.writeFileSync(O,JSON.stringify(t,null,2),{mode:384})}const fn={get(t){return S()[t]},set(t,e){const n=S();n[t]=e,G(n)},remove(t){const e=S();delete e[t],G(e)}};function gn(t){const e=ee.createInterface({input:process.stdin,output:process.stderr});return new Promise(n=>{e.question(t,r=>{e.close(),n(r)})})}function mn(t){return new Promise(e=>{process.stderr.write(t);const n=process.stdin;n.setRawMode(!0),n.resume(),n.setEncoding("utf-8");let r="";const a=i=>{if(i===""&&(process.stderr.write(`
|
|
5
|
-
`),process.exit(130)),
|
|
4
|
+
${s.verbose}`;throw new Error(c)}throw new Error(`unexpected fetch error: ${i.statusText}`)}if(a)return i;if(i.status===204)return;const o=await i.text();return o?JSON.parse(o):void 0}const v={datamanager:{live:"https://datamanager.entrecode.de/",stage:"https://datamanager.cachena.entrecode.de/"},accounts:{live:"https://accounts.entrecode.de/",stage:"https://accounts.cachena.entrecode.de/"},appserver:{live:"https://appserver.entrecode.de/",stage:"https://appserver.cachena.entrecode.de/"},"dm-history":{live:"https://dm-history.entrecode.de/",stage:"https://dm-history.cachena.entrecode.de/"}};function f(t,e="stage",n="datamanager"){const r=v[n];if(!r)throw new Error(`subdomain "${n}" not found. Try one of ${Object.keys(v).join(", ")}`);const a=r[e];if(!a)throw new Error(`env "${e}" not found. Try one of ${Object.keys(r[e]).join(", ")}`);return a+t}function h(t,e=!0){return Object.entries(t).sort((n,r)=>n[0].localeCompare(r[0])).map(([n,r])=>`${n}=${r}`).join("&")}function d(t){Object.entries(t).forEach(([e,n])=>{if(n===void 0)throw new Error(`expected ${e} to be set!`)})}const N={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};async function te(t){let{env:e,dmShortID:n,email:r,password:a}=t;d({env:e,dmShortID:n,email:r,password:a});const i=f(`api/${n}/_auth/login?clientID=rest`,e);return await u(i,{},{method:"POST",body:JSON.stringify({email:r,password:a}),headers:{"Content-Type":"application/json"}})}async function ne(t){let{env:e,email:n,password:r}=t;d({env:e,email:n,password:r});const a=`${N[e]}auth/login?clientID=rest`;return await u(a,{},{method:"POST",body:JSON.stringify({email:n,password:r}),headers:{"Content-Type":"application/json"}})}async function re(t){let{dmShortID:e,env:n,token:r}=t;d({dmShortID:e,env:n,token:r});const a=f(`api/${e}/_auth/logout?clientID=rest&token=${r}`,n);return await u(a,{rawRes:!0},{method:"POST"})}async function ae(t){let{env:e,token:n}=t;d({env:e,token:n});const r=`${N[e]}auth/logout?clientID=rest`;return await u(r,{rawRes:!0,token:n},{method:"POST"})}function ie({dmShortID:t}){return d({dmShortID:t}),t}function se({env:t}){return d({env:t}),t}let oe=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function J(t){let e={};for(let n in t)oe.includes(n)||(e[n]=t[n]);return e}function ce(t){return JSON.parse(JSON.stringify(t))}async function de(t){let{env:e,dmShortID:n}=t;d({env:e,dmShortID:n});const r=f(`api/${n}`,e);return u(r,t)}async function x(t){let{env:e,dmShortID:n,model:r,options:a={}}=t;d({env:e,dmShortID:n,model:r}),a={size:50,page:1,_list:!0,...a};const i=h(a),o=f(`api/${n}/${r}?${i}`,e),{count:s,total:c,_embedded:g}=await u(o,t);let m=g?g[`${n}:${r}`]:[];return m=Array.isArray(m)?m:[m],{count:s,total:c,items:m}}function ue({env:t,dmShortID:e,model:n,entryID:r,token:a}){d({env:t,dmShortID:e,model:n,entryID:r});const i=h({_id:r}),o=f(`api/${e}/${n}?${i}`,t);return u(o,{token:a})}async function le({env:t,dmShortID:e,model:n,value:r,token:a}){d({env:t,dmShortID:e,model:n,value:r});const i=f(`api/${e}/${n}`,t);return await u(i,{token:a},{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})}async function F({env:t,dmShortID:e,model:n,entryID:r,value:a,token:i,safePut:o=!1}){d({env:t,dmShortID:e,model:n,entryID:r,value:a});const s={"Content-Type":"application/json"};if(o){if(!("_modified"in a))throw new Error("expected _modified to be set!");s["If-Unmodified-Since"]=new Date(a._modified).toUTCString()}const c=f(`api/${e}/${n}?_id=${r}`,t);return a=ce(a),a=J(a),await u(c,{token:i},{method:"PUT",headers:s,body:JSON.stringify(a)})}function z({env:t,dmShortID:e,model:n,entryID:r,token:a}){d({env:t,dmShortID:e,model:n,entryID:r});const i=f(`api/${e}/${n}?_id=${r}`,t);return u(i,{token:a,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}async function fe(t,e){let{env:n,dmShortID:r,model:a,options:i={}}=t;d({env:n,dmShortID:r,model:a}),t.options={size:50,page:1,_list:!0,...i};let o=0,s,c=[];for(;s===void 0||o<s;){const g=await x(t);for(let m of g.items)c.push(await e(m));o+=g.items.length,s=g.total,t.options.page++}return c}async function ge({env:t,dmShortID:e,model:n,withMetadata:r}){d({env:t,dmShortID:e,model:n});const a=f(`api/schema/${e}/${n}`,t),i=await u(a),o=i?.allOf?.[1];if(typeof o.properties!="object")throw new Error(`getSchema: ${a} returned unexpected format: ${JSON.stringify(i)}`);const{properties:s}=o,c=J(s);for(let g in c){let m=c[g];if(m.required=o.required.includes(g),c[g]?.oneOf&&delete c[g]?.oneOf,m.title?.includes("<")&&m.title?.includes(">")){const k=m.title.split("<")[1].slice(0,-1),w=m.title.split("<")[0];m.type=w,k.includes(":")?m.resource=k.split(":")[1]:m.resource=k}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete c[g].title}if(r){const g=s._modelTitle.title,m=s._modelTitleField.title;return{properties:c,meta:{modelTitleField:m,modelTitle:g}}}return c}function H(t){return Object.entries(t).map(([e,n])=>typeof n!="object"?{[e]:String(n)}:{...n.sort&&{sort:Array.isArray(n)?n.join(","):n},...n.search&&{[e+"~"]:n.search},...n.notNull&&{[e+"!"]:""},...n.null&&{[e]:""},...n.any&&{[e]:n.any.join(",")},...n.from&&{[e+"From"]:n.from},...n.to&&{[e+"To"]:n.to}}).reduce((e,n)=>({...e,...n}),{})}const me=H;function U(t){return t._links.collection.href.split("/").slice(-2)[0]}function K(t){const e=t._links.collection.href.split("api/")[0];return Object.keys(v.datamanager).find(r=>v.datamanager[r]===e)}const V=t=>{const e=U(t),n=K(t),r=t._modelTitle,a=t.id;return{dmShortID:e,env:n,model:r,entryID:a}},he=t=>z(V(t)),pe=(t,e)=>F({...V(t),value:e});function ye(t,e){const n=U(e);return e._embedded[`${n}:${e._modelTitle}/${t}/asset`]}async function ke({env:t,dmShortID:e,assetGroup:n,assetID:r,token:a}){d({env:t,dmShortID:e,assetGroup:n,assetID:r});const i=h({assetID:r}),o=f(`a/${e}/${n}?${i}`,t),{_embedded:s}=await u(o,{token:a});return s?s["ec:dm-asset"]:void 0}async function we(t){let{env:e,dmShortID:n,assetGroup:r,token:a,options:i={}}=t;d({env:e,dmShortID:n,assetGroup:r}),i={size:50,page:1,_list:!0,...i};const o=h(i),s=f(`a/${n}/${r}?${o}`,e),{count:c,total:g,_embedded:m}=await u(s,{token:a});let k=m?m["ec:dm-asset"]:[];return k=Array.isArray(k)?k:[k],{count:c,total:g,items:k}}async function De({env:t,dmShortID:e,assetGroup:n,token:r,file:a,name:i,options:o}){d({env:t,dmShortID:e,assetGroup:n,file:a});const s=f(`a/${e}/${n}`,t),c=new FormData;return c.append("file",a,i),o&&Object.keys(o).forEach(m=>{c.append(m,o[m])}),(await u(s,{token:r},{method:"POST",body:c}))._embedded["ec:dm-asset"]}async function Te({env:t,dmShortID:e,assetGroup:n,files:r,options:a}){d({env:t,dmShortID:e,assetGroup:n,files:r});const i=f(`a/${e}/${n}`,t),o=new FormData;r.forEach(c=>{o.append("file",c)}),a&&Object.keys(a).forEach(c=>{o.append(c,a[c])});const s=await u(i,{},{method:"POST",body:o});return Array.isArray(s._embedded["ec:dm-asset"])?s._embedded["ec:dm-asset"]:[s._embedded["ec:dm-asset"]]}async function be({env:t,dmShortID:e,assetGroup:n,assetID:r,token:a}){d({env:t,dmShortID:e,assetGroup:n,assetID:r});const i=f(`a/${e}/${n}/${r}`,t);await u(i,{token:a,rawRes:!0},{method:"DELETE"})}function $e(t,e,n=!1){let r,a;return(n?t?.thumbnails:t?.fileVariants)?.forEach(o=>{const{resolution:{width:s,height:c}}=o,g=Math.abs(Math.max(s,c)-e);(!a||g<a)&&(a=g,r=o)}),r?.url??t?.file?.url??null}function Ae(t="stage",e,n,r,a=!1){const i=Math.max(r.file.resolution.width,r.file.resolution.height),o=n.filter(c=>c<i),s=`https://datamanager${t==="stage"?".cachena":""}.entrecode.de`;return a?o.map(c=>{const g=r.thumbnails.find(w=>c===w.dimension),m=`${s}/t/${e}/${r.assetID}/${c}`,k=g?g.url:m;return{size:c,url:k,generated:g}}):o.map(c=>{const g=r.fileVariants.find(w=>c===Math.max(w.resolution.width,w.resolution.height)),m=`${s}/f/${e}/${r.assetID}/${c}`,k=g?g.url:m;return{size:c,url:k,generated:g}})}const p={"Content-Type":"application/json"};async function Ee(t){let{env:e,dmID:n,token:r}=t;d({env:e,dmID:n});const a=f(`?dataManagerID=${n}`,e);return u(a,{token:r})}async function ve(t){let{env:e,options:n={}}=t;d({env:e}),n={size:25,page:1,_list:!0,...n};const r=h(n),a=f(`?${r}`,e),{count:i,total:o,_embedded:s}=await u(a,t);let c=s?s["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:i,total:o,items:c}}async function Ie(t){let{env:e,dmID:n,options:r={}}=t;d({env:e,dmID:n}),r={size:25,dataManagerID:n,page:1,_list:!0,...r};const a=h(r),i=f(`model?${a}`,e),{count:o,total:s,_embedded:c}=await u(i,t);let g=c?c["ec:model"]:[];return g=Array.isArray(g)?g:[g],{count:o,total:s,items:g}}async function Se(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager"}=t;d({env:e,subdomain:a,resource:n}),r={size:25,page:1,_list:!0,...r};const i=h(r),o=f(`${n}?${i}`,e,a),{count:s,total:c,_embedded:g}=await u(o,t);let m=g?g[Object.keys(g)[0]]:[];return m=Array.isArray(m)?m:[m],{count:s,total:c,items:m}}async function qe(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager"}=t;d({env:e,subdomain:a,resource:n});const i=h(r),o=f(`${n}?${i}`,e,a);return u(o,t)}async function Oe(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager",value:i}=t;d({env:e,subdomain:a,resource:n,value:i});const o=h(r),s=f(`${n}?${o}`,e,a);return u(s,t,{method:"PUT",body:JSON.stringify(i),headers:p})}async function Ue(t){let{env:e,resource:n,options:r={},subdomain:a="datamanager"}=t;d({env:e,subdomain:a,resource:n});const i=h(r),o=f(`${n}?${i}`,e,a);return u(o,{...t,rawRes:!0},{method:"DELETE",headers:p})}async function Me(t,e={}){let{env:n,route:r,options:a={},subdomain:i="datamanager"}=t;d({env:n,subdomain:i,route:r}),a={...a};const o=h(a),s=f(`${r}?${o}`,n,i);return u(s,t,e)}async function Ce(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("",e);return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function Le(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`?${i}`,e);return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function _e(t){let{env:e,token:n,dmID:r}=t;d({env:e,dmID:r});const a=h({dataManagerID:r}),i=f(`?${a}`,e);return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function Re(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`model?${i}`,e);return u(o,{token:n},{method:"POST",body:JSON.stringify(a),headers:p})}async function Ge(t){let{env:e,token:n,dmID:r,modelID:a,value:i}=t;d({env:e,dmID:r,modelID:a,value:i});const o=h({dataManagerID:r,modelID:a}),s=f(`model?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Pe(t){let{env:e,token:n,dmID:r,modelID:a}=t;d({env:e,dmID:r,modelID:a});const i=h({dataManagerID:r,modelID:a}),o=f(`model?${i}`,e);return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function Be(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("template",e);return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function je(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`assetgroup?${i}`,e);return u(o,{token:n},{method:"POST",body:JSON.stringify(a),headers:p})}async function Ne(t){let{env:e,token:n,dmID:r,assetGroupID:a,value:i}=t;d({env:e,dmID:r,assetGroupID:a,value:i});const o=h({dataManagerID:r,assetGroupID:a}),s=f(`assetgroup?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Je(t){let{env:e,token:n,dmShortID:r,assetGroup:a,assetID:i,value:o}=t;d({env:e,dmShortID:r,assetGroup:a,assetID:i,value:o});const s=f(`a/${r}/${a}/${i}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(o),headers:p})}async function xe(t){let{env:e,token:n,dmID:r,clientID:a,value:i}=t;d({env:e,dmID:r,clientID:a,value:i});const o=h({dataManagerID:r,clientID:a}),s=f(`client?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Fe(t){let{env:e,token:n,dmID:r,value:a}=t;d({env:e,dmID:r,value:a});const i=h({dataManagerID:r}),o=f(`role?${i}`,e);return u(o,{token:n},{method:"POST",body:JSON.stringify(a),headers:p})}async function ze(t){let{env:e,token:n,dmID:r,roleID:a,value:i}=t;d({env:e,dmID:r,roleID:a,value:i});const o=h({dataManagerID:r,roleID:a}),s=f(`role?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function He(t){let{env:e,token:n,dmID:r,roleID:a}=t;d({env:e,dmID:r,roleID:a});const i=h({dataManagerID:r,roleID:a}),o=f(`role?${i}`,e);return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function Ke(t){let{env:e,token:n,dmID:r,accountID:a,value:i}=t;d({env:e,dmID:r,accountID:a,value:i});const o=h({dataManagerID:r,accountID:a}),s=f(`account?${o}`,e);return u(s,{token:n},{method:"PUT",body:JSON.stringify(i),headers:p})}async function Ve(t){let{env:e,token:n,dmID:r,accountID:a}=t;d({env:e,dmID:r,accountID:a});const i=h({dataManagerID:r,accountID:a}),o=f(`account?${i}`,e);return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function We(t){let{env:e,token:n,options:r={}}=t;d({env:e});const a=h(r),i=f(`stats?${a}`,e);return u(i,{token:n})}async function Xe(t){let{env:e,token:n,options:r={}}=t;d({env:e});const a=h(r),i=f(`entries?${a}`,e,"dm-history");return u(i,{token:n})}async function Ye(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("client",e,"accounts");return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function Qe(t){let{env:e,token:n,clientID:r,value:a}=t;d({env:e,clientID:r,value:a});const i=h({clientID:r}),o=f(`client?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function Ze(t){let{env:e,token:n,clientID:r}=t;d({env:e,clientID:r});const a=h({clientID:r}),i=f(`client?${a}`,e,"accounts");return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function et(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("group",e,"accounts");return u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p})}async function tt(t){let{env:e,token:n,groupID:r,value:a}=t;d({env:e,groupID:r,value:a});const i=h({groupID:r}),o=f(`group?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function nt(t){let{env:e,token:n,groupID:r}=t;d({env:e,groupID:r});const a=h({groupID:r}),i=f(`group?${a}`,e,"accounts");return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function rt(t){let{env:e,token:n,value:r}=t;d({env:e,value:r});const a=f("invite",e,"accounts"),i=await u(a,{token:n},{method:"POST",body:JSON.stringify(r),headers:p});return i?._embedded?.["ec:invite"]??i}async function at(t){let{env:e,token:n,inviteID:r,value:a}=t;d({env:e,inviteID:r,value:a});const i=h({invite:r}),o=f(`invite?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function it(t){let{env:e,token:n,inviteID:r}=t;d({env:e,inviteID:r});const a=h({invite:r}),i=f(`invite?${a}`,e,"accounts");return u(i,{token:n,rawRes:!0},{method:"DELETE",headers:p})}async function st(t){let{env:e,token:n,accountID:r,value:a}=t;d({env:e,accountID:r,value:a});const i=h({accountID:r}),o=f(`account?${i}`,e,"accounts");return u(o,{token:n},{method:"PUT",body:JSON.stringify(a),headers:p})}async function ot(t){let{env:e,token:n,accountID:r}=t;d({env:e,accountID:r});const a=h({accountID:r}),i=f(`account/tokens?${a}`,e,"accounts");let s=(await u(i,{token:n}))?._embedded?.["ec:account/token"]??[];return Array.isArray(s)?s:[s]}async function ct(t){let{env:e,token:n,accountID:r}=t;d({env:e,accountID:r});const a=h({accountID:r}),i=f(`account/tokens?${a}`,e,"accounts");return u(i,{token:n},{method:"POST",headers:p})}async function dt(t){let{env:e,token:n,accountID:r,accessTokenID:a}=t;d({env:e,accountID:r,accessTokenID:a});const i=h({accessTokenID:a,accountID:r}),o=f(`account/tokens?${i}`,e,"accounts");return u(o,{token:n,rawRes:!0},{method:"DELETE",headers:p})}const ut=Object.freeze(Object.defineProperty({__proto__:null,assetList:we,createAccountClient:Ye,createAsset:De,createAssetGroup:je,createAssets:Te,createDatamanager:Ce,createEntry:le,createGroup:et,createInvite:rt,createModel:Re,createRole:Fe,createTemplate:Be,createToken:ct,deleteAccountClient:Ze,deleteAsset:be,deleteDatamanager:_e,deleteDmAccount:Ve,deleteEntry:z,deleteEntryObject:he,deleteGroup:nt,deleteInvite:it,deleteModel:Pe,deleteRole:He,deleteToken:dt,dmList:ve,editAccount:st,editAccountClient:Qe,editAsset:Je,editAssetGroup:Ne,editDatamanager:Le,editDmAccount:Ke,editDmClient:xe,editEntry:F,editEntryObject:pe,editGroup:tt,editInvite:at,editModel:Ge,editRole:ze,entryList:x,fileVariant:$e,filterOptions:me,getAsset:ke,getDatamanager:Ee,getEcAuthKey:se,getEntry:ue,getEntryAsset:ye,getEntryEnv:K,getEntryShortID:U,getFileVariants:Ae,getHistory:Xe,getPublicAuthKey:ie,getSchema:ge,getStats:We,listTokens:ot,loginEc:ne,loginPublic:te,logoutEc:ae,logoutPublic:re,mapEntries:fe,modelList:Ie,publicApi:de,raw:Me,resourceDelete:Ue,resourceEdit:Oe,resourceGet:qe,resourceList:Se,sdkOptions:H},Symbol.toStringTag,{value:"Module"})),{entryList:C,mapEntries:lt,getEntry:ft,getAsset:gt,assetList:L,createAsset:mt,createAssets:ht,deleteAsset:pt,createEntry:yt,editEntry:_,deleteEntry:kt,getSchema:wt,loginPublic:Dt,loginEc:Tt,logoutEc:bt,logoutPublic:$t,getEcAuthKey:b,getPublicAuthKey:$,dmList:At,modelList:Et,publicApi:vt,getDatamanager:It,resourceList:St,resourceGet:qt,resourceEdit:Ot,resourceDelete:Ut,raw:Mt,createDatamanager:Ct,editDatamanager:Lt,deleteDatamanager:_t,createModel:Rt,editModel:Gt,deleteModel:Pt,createTemplate:Bt,createAssetGroup:jt,editAssetGroup:Nt,editAsset:Jt,editDmClient:xt,createRole:Ft,editRole:zt,deleteRole:Ht,editDmAccount:Kt,deleteDmAccount:Vt,getStats:Wt,getHistory:Xt,createAccountClient:Yt,editAccountClient:Qt,deleteAccountClient:Zt,createGroup:en,editGroup:tn,deleteGroup:nn,createInvite:rn,editInvite:an,deleteInvite:sn,editAccount:on,listTokens:cn,createToken:dn,deleteToken:un}=ut;function R(t){if(!t||typeof t!="object")return t;const{_links:e,_embedded:n,...r}=t;return r}function ln(t){return!t||typeof t!="object"?t:Array.isArray(t.items)?{...t,items:t.items.map(R)}:R(t)}class M{constructor(e={}){if(!e.storageAdapter){let n=new Map;e.storageAdapter={get:r=>n.get(r),set:(r,a)=>n.set(r,a),remove:r=>n.delete(r)}}this.config=e}set(e){return new M({...this.config,...e})}async entries(e={}){const n=await this.getBestToken();return C({...this.config,options:e,token:n})}async entryList(e){const n=await this.getBestToken();return C({...this.config,options:e,token:n}).then(r=>this.maybeClean(r))}async mapEntries(e,n={}){const r=await this.getBestToken();return lt({...this.config,options:n,token:r},e)}async getEntry(e){const n=await this.getBestToken();return ft({...this.config,entryID:e,token:n}).then(r=>this.maybeClean(r))}async editEntrySafe(e,n){const r=await this.getBestToken();return _({...this.config,entryID:e,token:r,value:n,safePut:!0}).then(a=>this.maybeClean(a))}async getSchema(){return wt(this.config)}async assets(e){const n=await this.getBestToken();return L({...this.config,options:e,token:n})}async assetList(e){const n=await this.getBestToken();return L({...this.config,options:e,token:n})}async createAsset(e){const{file:n,name:r,options:a}=e,i=await this.getBestToken();return mt({...this.config,file:n,name:r,options:a,token:i})}async createAssets(e){const{files:n,options:r}=e,a=await this.getBestToken();return ht({...this.config,files:n,options:r,token:a})}async deleteAsset(e){const n=await this.getBestToken();return pt({...this.config,token:n,assetID:e})}async getAsset(e){const n=await this.getBestToken();return gt({...this.config,assetID:e,token:n})}async createEntry(e){const n=await this.getBestToken();return yt({...this.config,token:n,value:e}).then(r=>this.maybeClean(r))}async editEntry(e,n){const r=await this.getBestToken();return _({...this.config,entryID:e,token:r,value:n}).then(a=>this.maybeClean(a))}async deleteEntry(e){const n=await this.getBestToken();return kt({...this.config,token:n,entryID:e})}async resourceList(e){const n=await this.getBestToken();return St({...this.config,options:e,token:n})}async resourceGet(e){const n=await this.getBestToken();return qt({...this.config,options:e,token:n})}async resourceEdit(e,n){const r=await this.getBestToken();return Ot({...this.config,options:e,token:r,value:n})}async resourceDelete(e){const n=await this.getBestToken();return Ut({...this.config,options:e,token:n})}async raw(e,n){const r=await this.getBestToken();return Mt({...this.config,options:e,token:r},n)}async createDatamanager(e){const n=await this.getBestToken();return Ct({...this.config,token:n,value:e})}async editDatamanager(e,n){const r=await this.getBestToken();return Lt({...this.config,token:r,dmID:e,value:n})}async deleteDatamanager(e){const n=await this.getBestToken();return _t({...this.config,token:n,dmID:e})}async createModel(e){const n=await this.getBestToken();return Rt({...this.config,token:n,value:e})}async editModel(e,n){const r=await this.getBestToken();return Gt({...this.config,token:r,modelID:e,value:n})}async deleteModel(e){const n=await this.getBestToken();return Pt({...this.config,token:n,modelID:e})}async createTemplate(e){const n=await this.getBestToken();return Bt({...this.config,token:n,value:e})}async createAssetGroup(e){const n=await this.getBestToken();return jt({...this.config,token:n,value:e})}async editAssetGroup(e,n){const r=await this.getBestToken();return Nt({...this.config,token:r,assetGroupID:e,value:n})}async editAsset(e,n){const r=await this.getBestToken();return Jt({...this.config,token:r,assetID:e,value:n})}async editDmClient(e,n){const r=await this.getBestToken();return xt({...this.config,token:r,clientID:e,value:n})}async createRole(e){const n=await this.getBestToken();return Ft({...this.config,token:n,value:e})}async editRole(e,n){const r=await this.getBestToken();return zt({...this.config,token:r,roleID:e,value:n})}async deleteRole(e){const n=await this.getBestToken();return Ht({...this.config,token:n,roleID:e})}async editDmAccount(e,n){const r=await this.getBestToken();return Kt({...this.config,token:r,accountID:e,value:n})}async deleteDmAccount(e){const n=await this.getBestToken();return Vt({...this.config,token:n,accountID:e})}async getStats(e={}){const n=await this.getBestToken();return Wt({...this.config,token:n,options:e})}async getHistory(e={}){const n=await this.getBestToken();return Xt({...this.config,token:n,options:e})}async createAccountClient(e){const n=await this.getBestToken();return Yt({...this.config,token:n,value:e})}async editAccountClient(e,n){const r=await this.getBestToken();return Qt({...this.config,token:r,clientID:e,value:n})}async deleteAccountClient(e){const n=await this.getBestToken();return Zt({...this.config,token:n,clientID:e})}async createGroup(e){const n=await this.getBestToken();return en({...this.config,token:n,value:e})}async editGroup(e,n){const r=await this.getBestToken();return tn({...this.config,token:r,groupID:e,value:n})}async deleteGroup(e){const n=await this.getBestToken();return nn({...this.config,token:n,groupID:e})}async createInvite(e){const n=await this.getBestToken();return rn({...this.config,token:n,value:e})}async editInvite(e,n){const r=await this.getBestToken();return an({...this.config,token:r,inviteID:e,value:n})}async deleteInvite(e){const n=await this.getBestToken();return sn({...this.config,token:n,inviteID:e})}async editAccount(e,n){const r=await this.getBestToken();return on({...this.config,token:r,accountID:e,value:n})}async listTokens(e){const n=await this.getBestToken();return cn({...this.config,token:n,accountID:e})}async createToken(e){const n=await this.getBestToken();return dn({...this.config,token:n,accountID:e})}async deleteToken(e,n){const r=await this.getBestToken();return un({...this.config,token:r,accountID:e,accessTokenID:n})}storageAdapter(e){return this.set({storageAdapter:e})}removeToken(e){if(!this.config.storageAdapter)throw new Error("cannot removeToken: no storageAdapter defined!");const{remove:n}=this.config.storageAdapter;n(e)}getToken(e){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:n}=this.config.storageAdapter;return n(e)}getPublicToken(){return this.config.token||this.getToken($(this.config))}getEcToken(){return this.config.token||this.getToken(b(this.config))}setToken(e,n){if(!this.config.storageAdapter)throw new Error("cannot setEcToken: no storageAdapter defined!");return this.config.storageAdapter.set(e,n)}setEcToken(e){this.setToken(b(this.config),e)}setPublicToken(e){this.setToken($(this.config),e)}loginEc(e){return Tt({...this.config,...e}).then(n=>this.setToken(b(this.config),n.token))}loginPublic(e){return Dt({...this.config,...e}).then(n=>this.setToken($(this.config),n.token))}logoutPublic(){const e=this.getPublicToken();return $t({...this.config,token:e}).then(()=>this.removeToken($(this.config)))}logoutEc(){const e=this.getEcToken();return bt({...this.config,token:e}).then(()=>this.removeToken(b(this.config)))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch{return}}clean(e=!0){return this.set({_clean:e})}maybeClean(e){return this.config._clean?ln(e):e}model(e){return this.set({model:e})}token(e){return this.set({token:e})}dmShortID(e){return this.set({dmShortID:e})}dm(e){return this.dmShortID(e)}dmID(e){return this.set({dmID:e})}assetGroup(e){return this.set({assetGroup:e})}assetgroup(e){return this.assetGroup(e)}subdomain(e){return this.set({subdomain:e})}resource(e){return this.set({resource:e})}route(e){return this.set({route:e})}publicApi(){return vt(this.config)}async getDatamanager(e){const n=await this.getBestToken();return It({...this.config,dmID:e,token:n})}async dmList(e={}){const n=await this.getBestToken();return At({...this.config,options:e,token:n})}async modelList(e={}){const n=await this.getBestToken();return Et({...this.config,options:e,token:n})}}const q=j.join(Z.homedir(),".ec-fdk"),O=j.join(q,"auth.json");function S(){try{return D.existsSync(O)?JSON.parse(D.readFileSync(O,"utf-8")):{}}catch{return{}}}function G(t){D.existsSync(q)||D.mkdirSync(q,{recursive:!0,mode:448}),D.writeFileSync(O,JSON.stringify(t,null,2),{mode:384})}const fn={get(t){return S()[t]},set(t,e){const n=S();n[t]=e,G(n)},remove(t){const e=S();delete e[t],G(e)}};function gn(t){const e=ee.createInterface({input:process.stdin,output:process.stderr});return new Promise(n=>{e.question(t,r=>{e.close(),n(r)})})}function mn(t){return new Promise(e=>{process.stderr.write(t);const n=process.stdin;n.setRawMode(!0),n.resume(),n.setEncoding("utf-8");let r="";const a=i=>{for(const o of i){if(o===""&&(process.stderr.write(`
|
|
5
|
+
`),process.exit(130)),o==="\r"||o===`
|
|
6
6
|
`){n.setRawMode(!1),n.pause(),n.removeListener("data",a),process.stderr.write(`
|
|
7
|
-
`),e(r);return}if(
|
|
7
|
+
`),e(r);return}if(o===""||o==="\b"){r.length>0&&(r=r.slice(0,-1),process.stderr.write("\b \b"));continue}r+=o,process.stderr.write("*")}};n.on("data",a)})}const hn=Q.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:document.currentScript&&document.currentScript.src||new URL("cli.cjs",document.baseURI).href),{version:pn}=hn("../package.json"),yn=`ec.fdk <command> [options]
|
|
8
8
|
|
|
9
9
|
Commands:
|
|
10
10
|
login Login with ec credentials (interactive prompt)
|