ec.fdk 0.8.3 → 0.8.5

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/README.md CHANGED
@@ -26,11 +26,11 @@ There are 2 ways to use ec.fdk:
26
26
  Start by calling `fdk` with your environment (`stage` | `live`), then method chain your way to success:
27
27
 
28
28
  ```js
29
- import { fdk } from "ec.fdk";
29
+ import { fdk } from 'ec.fdk';
30
30
 
31
- fdk("stage") // choose stage environment
32
- .dm("83cc6374") // select datamanager via short id
33
- .model("muffin") // select model muffin
31
+ fdk('stage') // choose stage environment
32
+ .dm('83cc6374') // select datamanager via short id
33
+ .model('muffin') // select model muffin
34
34
  .entryList() // load entry list
35
35
  .then((list) => {
36
36
  console.log(list);
@@ -45,10 +45,10 @@ The act function converts a single object param into a fetch request:
45
45
 
46
46
  ```js
47
47
  const muffins = await act({
48
- action: "entryList",
49
- env: "stage",
50
- dmShortID: "83cc6374",
51
- model: "muffin",
48
+ action: 'entryList',
49
+ env: 'stage',
50
+ dmShortID: '83cc6374',
51
+ model: 'muffin',
52
52
  });
53
53
  ```
54
54
 
@@ -59,8 +59,8 @@ More in the [act reference](https://entrecode.github.io/ec.fdk/functions/act.htm
59
59
  The act function is good to be used with swr or react-query:
60
60
 
61
61
  ```js
62
- import { act } from "ec.fdk";
63
- import useSWR from "swr";
62
+ import { act } from 'ec.fdk';
63
+ import useSWR from 'swr';
64
64
 
65
65
  export function useFdk(config) {
66
66
  const key = config ? JSON.stringify(config) : null;
@@ -72,20 +72,100 @@ Then use the hook:
72
72
 
73
73
  ```js
74
74
  const config = {
75
- env: "stage",
76
- dmShortID: "83cc6374",
75
+ env: 'stage',
76
+ dmShortID: '83cc6374',
77
77
  };
78
78
 
79
79
  function App() {
80
80
  const { data: entryList } = useFdk({
81
81
  ...config,
82
- action: "entryList",
83
- model: "muffin",
82
+ action: 'entryList',
83
+ model: 'muffin',
84
84
  });
85
85
  /* more stuff */
86
86
  }
87
87
  ```
88
88
 
89
+ ## CLI
90
+
91
+ ec.fdk also ships a CLI for quick shell-based interaction with entrecode APIs. Output is JSON, so you can pipe it into `jq` and friends.
92
+
93
+ ### Usage
94
+
95
+ ```sh
96
+ npx ec.fdk <command> [options]
97
+ ```
98
+
99
+ Or install globally:
100
+
101
+ ```sh
102
+ npm i -g ec.fdk
103
+ ec.fdk <command> [options]
104
+ ```
105
+
106
+ ### Commands
107
+
108
+ | Command | Description |
109
+ | ------------- | ---------------------------------------------- |
110
+ | `login` | Login with ec credentials (interactive prompt) |
111
+ | `entryList` | List entries |
112
+ | `getEntry` | Get a single entry |
113
+ | `createEntry` | Create an entry |
114
+ | `editEntry` | Edit an entry |
115
+ | `deleteEntry` | Delete an entry |
116
+ | `getSchema` | Get model schema |
117
+
118
+ ### Options
119
+
120
+ | Option | Description |
121
+ | -------------------- | ------------------------------------------------- |
122
+ | `-e, --env <env>` | Environment: `stage` \| `live` (default: `stage`) |
123
+ | `-d, --dm <shortID>` | DataManager short ID |
124
+ | `-m, --model <name>` | Model name |
125
+ | `-i, --id <id>` | Entry ID (for get/edit/delete) |
126
+ | `--data <json>` | JSON data (for create/edit) |
127
+ | `-s, --size <n>` | Page size for list |
128
+ | `-p, --page <n>` | Page number for list |
129
+ | `--sort <field>` | Sort field for list |
130
+ | `--raw` | Include `_links` and `_embedded` in output |
131
+ | `-h, --help` | Show help |
132
+
133
+ ### Examples
134
+
135
+ ```sh
136
+ # Login to stage (stores token in ~/.ec-fdk/auth.json)
137
+ ec.fdk login -e stage
138
+
139
+ # List entries
140
+ ec.fdk entryList -d 83cc6374 -m muffin
141
+
142
+ # List with pagination
143
+ ec.fdk entryList -d 83cc6374 -m muffin -s 10 -p 2
144
+
145
+ # Get a single entry
146
+ ec.fdk getEntry -d 83cc6374 -m muffin -i fZctZXIeRJ
147
+
148
+ # Create an entry
149
+ ec.fdk createEntry -d 83cc6374 -m muffin --data '{"name":"new muffin","amazement_factor":10}'
150
+
151
+ # Create via stdin pipe
152
+ echo '{"name":"piped muffin","amazement_factor":10}' | ec.fdk createEntry -d 83cc6374 -m muffin
153
+
154
+ # Edit an entry
155
+ ec.fdk editEntry -d 83cc6374 -m muffin -i fZctZXIeRJ --data '{"name":"edited"}'
156
+
157
+ # Delete an entry
158
+ ec.fdk deleteEntry -d 83cc6374 -m muffin -i fZctZXIeRJ
159
+
160
+ # Get model schema
161
+ ec.fdk getSchema -d 83cc6374 -m muffin
162
+
163
+ # Pipe into jq
164
+ ec.fdk entryList -d 83cc6374 -m muffin | jq '.items | length'
165
+ ```
166
+
167
+ Status/error messages go to stderr, data goes to stdout — so piping always works cleanly.
168
+
89
169
  ## migration from ec.sdk
90
170
 
91
171
  ec.fdk won't change / decorate data returned from ec APIs. For example, an entry returned from the datamanager will be returned as is.
@@ -107,7 +187,7 @@ await editEntryObject(entry, value); // <- DO
107
187
  // alternatively:
108
188
  await fdk.env(env).dm(dmShortID).model(model).updateEntry(entryID, value);
109
189
  // or:
110
- await act({ action: "editEntry", env, dmShortID, model, entryID, value });
190
+ await act({ action: 'editEntry', env, dmShortID, model, entryID, value });
111
191
  ```
112
192
 
113
193
  ### Entry delete
@@ -120,9 +200,9 @@ await entry.del(); // <- DONT
120
200
  // use this to delete an entry:
121
201
  await deleteEntryObject(entry); // <- DO
122
202
  // alternatively:
123
- await fdk.dm("shortID").model("model").deleteEntry("entryID");
203
+ await fdk.dm('shortID').model('model').deleteEntry('entryID');
124
204
  // or:
125
- await act({ action: "deleteEntry", env, dmShortID, model, entryID });
205
+ await act({ action: 'deleteEntry', env, dmShortID, model, entryID });
126
206
  ```
127
207
 
128
208
  ### Entry Asset Fields
@@ -133,7 +213,7 @@ In ec.fdk, entry asset fields are plain ids:
133
213
  // assuming "photo" is an asset field:
134
214
  entry.photo; // <-- this used to be an AssetResource. Now it's a plain id string.
135
215
  // use this to get the embedded AssetResource:
136
- getEntryAsset("photo", entry); // (no request goes out)
216
+ getEntryAsset('photo', entry); // (no request goes out)
137
217
  ```
138
218
 
139
219
  ### Entry Date Fields
@@ -167,9 +247,7 @@ const entryList = await fdk(env).dm(shortID).entryList(model);
167
247
  By default, the second param of ec.fdk `entryList` will just convert the object to url params:
168
248
 
169
249
  ```js
170
- const entryList = await fdk("stage")
171
- .dm("83cc6374")
172
- .entryList({ createdTo: "2021-01-18T09:13:47.605Z" });
250
+ const entryList = await fdk('stage').dm('83cc6374').entryList({ createdTo: '2021-01-18T09:13:47.605Z' });
173
251
  /*
174
252
  https://datamanager.cachena.entrecode.de/api/83cc6374/muffin?
175
253
  _list=true&
@@ -184,9 +262,9 @@ Read more in the [entrecode filtering doc](https://doc.entrecode.de/api-basics/#
184
262
  There is some syntax sugar you can use to get the same behavior as [ec.sdk filterOptions](https://entrecode.github.io/ec.sdk/#filteroptions):
185
263
 
186
264
  ```js
187
- const entryList = await fdk("stage")
188
- .dm("83cc6374")
189
- .entryList(filterOptions({ created: { to: "2021-01-18T09:13:47.605Z" } }));
265
+ const entryList = await fdk('stage')
266
+ .dm('83cc6374')
267
+ .entryList(filterOptions({ created: { to: '2021-01-18T09:13:47.605Z' } }));
190
268
  ```
191
269
 
192
270
  ### Asset List
package/dist/cli.cjs ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";const M=require("node:util"),w=require("node:fs"),q=require("node:path"),R=require("node:os"),U=require("node:readline");async function h(n,t={},e={}){const{token:s,rawRes:r}=t;s&&(e.headers={...e.headers||{},Authorization:`Bearer ${s}`});const i=await fetch(n,e);if(!i.ok){if(i.headers.get("content-type")?.includes("application/json")){const o=await i.json(),a=`${o.title}
3
+ ${o.detail}
4
+ ${o.verbose}`;throw new Error(a)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return r?i:await i.json()}const E={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 g(n,t="stage",e="datamanager"){const s=E[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(E).join(", ")}`);const r=s[t];if(!r)throw new Error(`env "${t}" not found. Try one of ${Object.keys(s[t]).join(", ")}`);return r+n}function m(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function l(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const B={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};async function K(n){let{env:t,dmShortID:e,email:s,password:r}=n;l({env:t,dmShortID:e,email:s,password:r});const i=g(`api/${e}/_auth/login?clientID=rest`,t);return await h(i,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})}async function V(n){let{env:t,email:e,password:s}=n;l({env:t,email:e,password:s});const r=`${B[t]}auth/login?clientID=rest`;return await h(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})}async function G(n){let{dmShortID:t,env:e,token:s}=n;l({dmShortID:t,env:e,token:s});const r=g(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return await h(r,{rawRes:!0},{method:"POST"})}async function H(n){let{env:t,token:e}=n;l({env:t,token:e});const s=`${B[t]}auth/logout?clientID=rest`;return await h(s,{rawRes:!0,token:e},{method:"POST"})}function Y({dmShortID:n}){return l({dmShortID:n}),n}function Q({env:n}){return l({env:n}),n}let W=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function N(n){let t={};for(let e in n)W.includes(e)||(t[e]=n[e]);return t}function X(n){return JSON.parse(JSON.stringify(n))}async function Z(n){let{env:t,dmShortID:e}=n;l({env:t,dmShortID:e});const s=g(`api/${e}`,t);return h(s,n)}async function J(n){let{env:t,dmShortID:e,model:s,options:r={}}=n;l({env:t,dmShortID:e,model:s}),r={size:50,page:1,_list:!0,...r};const i=m(r),o=g(`api/${e}/${s}?${i}`,t),{count:a,total:c,_embedded:u}=await h(o,n);let d=u?u[`${e}:${s}`]:[];return d=Array.isArray(d)?d:[d],{count:a,total:c,items:d}}function tt({env:n,dmShortID:t,model:e,entryID:s,token:r}){l({env:n,dmShortID:t,model:e,entryID:s});const i=m({_id:s}),o=g(`api/${t}/${e}?${i}`,n);return h(o,{token:r})}async function et({env:n,dmShortID:t,model:e,value:s,token:r}){l({env:n,dmShortID:t,model:e,value:s});const i=g(`api/${t}/${e}`,n);return await h(i,{token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})}async function x({env:n,dmShortID:t,model:e,entryID:s,value:r,token:i,safePut:o=!1}){l({env:n,dmShortID:t,model:e,entryID:s,value:r});const a={"Content-Type":"application/json"};if(o){if(!("_modified"in r))throw new Error("expected _modified to be set!");a["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const c=g(`api/${t}/${e}?_id=${s}`,n);return r=X(r),r=N(r),await h(c,{token:i},{method:"PUT",headers:a,body:JSON.stringify(r)})}function C({env:n,dmShortID:t,model:e,entryID:s,token:r}){l({env:n,dmShortID:t,model:e,entryID:s});const i=g(`api/${t}/${e}?_id=${s}`,n);return h(i,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}async function nt(n,t){let{env:e,dmShortID:s,model:r,options:i={}}=n;l({env:e,dmShortID:s,model:r}),n.options={size:50,page:1,_list:!0,...i};let o=0,a,c=[];for(;a===void 0||o<a;){const u=await J(n);for(let d of u.items)c.push(await t(d));o+=u.items.length,a=u.total,n.options.page++}return c}async function st({env:n,dmShortID:t,model:e,withMetadata:s}){l({env:n,dmShortID:t,model:e});const r=g(`api/schema/${t}/${e}`,n),i=await h(r),o=i?.allOf?.[1];if(typeof o.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(i)}`);const{properties:a}=o,c=N(a);for(let u in c){let d=c[u];if(d.required=o.required.includes(u),c[u]?.oneOf&&delete c[u]?.oneOf,d.title?.includes("<")&&d.title?.includes(">")){const f=d.title.split("<")[1].slice(0,-1),y=d.title.split("<")[0];d.type=y,f.includes(":")?d.resource=f.split(":")[1]:d.resource=f}else["asset","entry","assets","entries"].includes(d.title)?(d.type=d.title,d.resource=null):d.type=d.title;delete c[u].title}if(s){const u=a._modelTitle.title,d=a._modelTitleField.title;return{properties:c,meta:{modelTitleField:d,modelTitle:u}}}return c}function I(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:{...e.sort&&{sort:Array.isArray(e)?e.join(","):e},...e.search&&{[t+"~"]:e.search},...e.notNull&&{[t+"!"]:""},...e.null&&{[t]:""},...e.any&&{[t]:e.any.join(",")},...e.from&&{[t+"From"]:e.from},...e.to&&{[t+"To"]:e.to}}).reduce((t,e)=>({...t,...e}),{})}const rt=I;function S(n){return n._links.collection.href.split("/").slice(-2)[0]}function z(n){const t=n._links.collection.href.split("api/")[0];return Object.keys(E.datamanager).find(s=>E.datamanager[s]===t)}const F=n=>{const t=S(n),e=z(n),s=n._modelTitle,r=n.id;return{dmShortID:t,env:e,model:s,entryID:r}},it=n=>C(F(n)),ot=(n,t)=>x({...F(n),value:t});function at(n,t){const e=S(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}async function ct({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){l({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=m({assetID:s}),o=g(`a/${t}/${e}?${i}`,n),{_embedded:a}=await h(o,{token:r});return a?a["ec:dm-asset"]:void 0}async function dt(n){let{env:t,dmShortID:e,assetGroup:s,token:r,options:i={}}=n;l({env:t,dmShortID:e,assetGroup:s}),i={size:50,page:1,_list:!0,...i};const o=m(i),a=g(`a/${e}/${s}?${o}`,t),{count:c,total:u,_embedded:d}=await h(a,{token:r});let f=d?d["ec:dm-asset"]:[];return f=Array.isArray(f)?f:[f],{count:c,total:u,items:f}}async function ut({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:i,options:o}){l({env:n,dmShortID:t,assetGroup:e,file:r});const a=g(`a/${t}/${e}`,n),c=new FormData;return c.append("file",r,i),o&&Object.keys(o).forEach(d=>{c.append(d,o[d])}),(await h(a,{token:s},{method:"POST",body:c}))._embedded["ec:dm-asset"]}async function lt({env:n,dmShortID:t,assetGroup:e,files:s,options:r}){l({env:n,dmShortID:t,assetGroup:e,files:s});const i=g(`a/${t}/${e}`,n),o=new FormData;s.forEach(c=>{o.append("file",c)}),r&&Object.keys(r).forEach(c=>{o.append(c,r[c])});const a=await h(i,{},{method:"POST",body:o});return Array.isArray(a._embedded["ec:dm-asset"])?a._embedded["ec:dm-asset"]:[a._embedded["ec:dm-asset"]]}async function ht({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){l({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=g(`a/${t}/${e}/${s}`,n);await h(i,{token:r,rawRes:!0},{method:"DELETE"})}function gt(n,t,e=!1){let s,r;return(e?n?.thumbnails:n?.fileVariants)?.forEach(o=>{const{resolution:{width:a,height:c}}=o,u=Math.abs(Math.max(a,c)-t);(!r||u<r)&&(r=u,s=o)}),s?.url??n?.file?.url??null}function ft(n="stage",t,e,s,r=!1){const i=Math.max(s.file.resolution.width,s.file.resolution.height),o=e.filter(c=>c<i),a=`https://datamanager${n==="stage"?".cachena":""}.entrecode.de`;return r?o.map(c=>{const u=s.thumbnails.find(y=>c===y.dimension),d=`${a}/t/${t}/${s.assetID}/${c}`,f=u?u.url:d;return{size:c,url:f,generated:u}}):o.map(c=>{const u=s.fileVariants.find(y=>c===Math.max(y.resolution.width,y.resolution.height)),d=`${a}/f/${t}/${s.assetID}/${c}`,f=u?u.url:d;return{size:c,url:f,generated:u}})}async function pt(n){let{env:t,dmID:e,token:s}=n;l({env:t,dmID:e});const r=g(`?dataManagerID=${e}`,t);return h(r,{token:s})}async function mt(n){let{env:t,options:e={}}=n;l({env:t}),e={size:25,page:1,_list:!0,...e};const s=m(e),r=g(`?${s}`,t),{count:i,total:o,_embedded:a}=await h(r,n);let c=a?a["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:i,total:o,items:c}}async function yt(n){let{env:t,dmID:e,options:s={}}=n;l({env:t,dmID:e}),s={size:25,dataManagerID:e,page:1,_list:!0,...s};const r=m(s),i=g(`model?${r}`,t),{count:o,total:a,_embedded:c}=await h(i,n);let u=c?c["ec:model"]:[];return u=Array.isArray(u)?u:[u],{count:o,total:a,items:u}}async function wt(n){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;l({env:t,subdomain:r,resource:e}),s={size:25,page:1,_list:!0,...s};const i=m(s),o=g(`${e}?${i}`,t,r),{count:a,total:c,_embedded:u}=await h(o,n);let d=u?u[Object.keys(u)[0]]:[];return d=Array.isArray(d)?d:[d],{count:a,total:c,items:d}}async function $t(n,t={}){let{env:e,route:s,options:r={},subdomain:i="datamanager"}=n;l({env:e,subdomain:i,route:s}),r={...r};const o=m(r),a=g(`${s}?${o}`,e,i);return h(a,n,t)}const bt=Object.freeze(Object.defineProperty({__proto__:null,assetList:dt,createAsset:ut,createAssets:lt,createEntry:et,deleteAsset:ht,deleteEntry:C,deleteEntryObject:it,dmList:mt,editEntry:x,editEntryObject:ot,entryList:J,fileVariant:gt,filterOptions:rt,getAsset:ct,getDatamanager:pt,getEcAuthKey:Q,getEntry:tt,getEntryAsset:at,getEntryEnv:z,getEntryShortID:S,getFileVariants:ft,getPublicAuthKey:Y,getSchema:st,loginEc:V,loginPublic:K,logoutEc:H,logoutPublic:G,mapEntries:nt,modelList:yt,publicApi:Z,raw:$t,resourceList:wt,sdkOptions:I},Symbol.toStringTag,{value:"Module"})),{entryList:v,mapEntries:Et,getEntry:kt,getAsset:Tt,assetList:O,createAsset:At,createAssets:St,deleteAsset:_t,createEntry:vt,editEntry:P,deleteEntry:Ot,getSchema:Pt,loginPublic:jt,loginEc:Lt,logoutEc:Dt,logoutPublic:qt,getEcAuthKey:$,getPublicAuthKey:b,dmList:Bt,modelList:Nt,publicApi:Jt,getDatamanager:xt,resourceList:Ct,raw:It}=bt;function j(n){if(!n||typeof n!="object")return n;const{_links:t,_embedded:e,...s}=n;return s}function zt(n){return!n||typeof n!="object"?n:Array.isArray(n.items)?{...n,items:n.items.map(j)}:j(n)}class _{constructor(t={}){if(!t.storageAdapter){let e=new Map;t.storageAdapter={get:s=>e.get(s),set:(s,r)=>e.set(s,r),remove:s=>e.delete(s)}}this.config=t}set(t){return new _({...this.config,...t})}async entries(t={}){const e=await this.getBestToken();return v({...this.config,options:t,token:e})}async entryList(t){const e=await this.getBestToken();return v({...this.config,options:t,token:e}).then(s=>this.maybeClean(s))}async mapEntries(t,e={}){const s=await this.getBestToken();return Et({...this.config,options:e,token:s},t)}async getEntry(t){const e=await this.getBestToken();return kt({...this.config,entryID:t,token:e}).then(s=>this.maybeClean(s))}async editEntrySafe(t,e){const s=await this.getBestToken();return P({...this.config,entryID:t,token:s,value:e,safePut:!0}).then(r=>this.maybeClean(r))}async getSchema(){return Pt(this.config)}async assets(t){const e=await this.getBestToken();return O({...this.config,options:t,token:e})}async assetList(t){const e=await this.getBestToken();return O({...this.config,options:t,token:e})}async createAsset(t){const{file:e,name:s,options:r}=t,i=await this.getBestToken();return At({...this.config,file:e,name:s,options:r,token:i})}async createAssets(t){const{files:e,options:s}=t,r=await this.getBestToken();return St({...this.config,files:e,options:s,token:r})}async deleteAsset(t){const e=await this.getBestToken();return _t({...this.config,token:e,assetID:t})}async getAsset(t){const e=await this.getBestToken();return Tt({...this.config,assetID:t,token:e})}async createEntry(t){const e=await this.getBestToken();return vt({...this.config,token:e,value:t}).then(s=>this.maybeClean(s))}async editEntry(t,e){const s=await this.getBestToken();return P({...this.config,entryID:t,token:s,value:e}).then(r=>this.maybeClean(r))}async deleteEntry(t){const e=await this.getBestToken();return Ot({...this.config,token:e,entryID:t})}async resourceList(t){const e=await this.getBestToken();return Ct({...this.config,options:t,token:e})}async raw(t,e){const s=await this.getBestToken();return It({...this.config,options:t,token:s},e)}storageAdapter(t){return this.set({storageAdapter:t})}removeToken(t){if(!this.config.storageAdapter)throw new Error("cannot removeToken: no storageAdapter defined!");const{remove:e}=this.config.storageAdapter;e(t)}getToken(t){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:e}=this.config.storageAdapter;return e(t)}getPublicToken(){return this.config.token||this.getToken(b(this.config))}getEcToken(){return this.config.token||this.getToken($(this.config))}setToken(t,e){if(!this.config.storageAdapter)throw new Error("cannot setEcToken: no storageAdapter defined!");return this.config.storageAdapter.set(t,e)}setEcToken(t){this.setToken($(this.config),t)}setPublicToken(t){this.setToken(b(this.config),t)}loginEc(t){return Lt({...this.config,...t}).then(e=>this.setToken($(this.config),e.token))}loginPublic(t){return jt({...this.config,...t}).then(e=>this.setToken(b(this.config),e.token))}logoutPublic(){const t=this.getPublicToken();return qt({...this.config,token:t}).then(()=>this.removeToken(b(this.config)))}logoutEc(){const t=this.getEcToken();return Dt({...this.config,token:t}).then(()=>this.removeToken($(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(t=!0){return this.set({_clean:t})}maybeClean(t){return this.config._clean?zt(t):t}model(t){return this.set({model:t})}token(t){return this.set({token:t})}dmShortID(t){return this.set({dmShortID:t})}dm(t){return this.dmShortID(t)}dmID(t){return this.set({dmID:t})}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}subdomain(t){return this.set({subdomain:t})}resource(t){return this.set({resource:t})}route(t){return this.set({route:t})}publicApi(){return Jt(this.config)}async getDatamanager(t){const e=await this.getBestToken();return xt({...this.config,dmID:t,token:e})}async dmList(t={}){const e=await this.getBestToken();return Bt({...this.config,options:t,token:e})}async modelList(t={}){const e=await this.getBestToken();return Nt({...this.config,options:t,token:e})}}const T=q.join(R.homedir(),".ec-fdk"),A=q.join(T,"auth.json");function k(){try{return w.existsSync(A)?JSON.parse(w.readFileSync(A,"utf-8")):{}}catch{return{}}}function L(n){w.existsSync(T)||w.mkdirSync(T,{recursive:!0,mode:448}),w.writeFileSync(A,JSON.stringify(n,null,2),{mode:384})}const Ft={get(n){return k()[n]},set(n,t){const e=k();e[n]=t,L(e)},remove(n){const t=k();delete t[n],L(t)}};function Mt(n){const t=U.createInterface({input:process.stdin,output:process.stderr});return new Promise(e=>{t.question(n,s=>{t.close(),e(s)})})}function Rt(n){return new Promise(t=>{process.stderr.write(n);const e=process.stdin;e.setRawMode(!0),e.resume(),e.setEncoding("utf-8");let s="";const r=i=>{if(i===""&&(process.stderr.write(`
5
+ `),process.exit(130)),i==="\r"||i===`
6
+ `){e.setRawMode(!1),e.pause(),e.removeListener("data",r),process.stderr.write(`
7
+ `),t(s);return}if(i===""||i==="\b"){s.length>0&&(s=s.slice(0,-1),process.stderr.write("\b \b"));return}s+=i,process.stderr.write("*")};e.on("data",r)})}const Ut=`ec.fdk <command> [options]
8
+
9
+ Commands:
10
+ login Login with ec credentials (interactive prompt)
11
+ entryList List entries
12
+ getEntry Get a single entry
13
+ createEntry Create an entry
14
+ editEntry Edit an entry
15
+ deleteEntry Delete an entry
16
+ getSchema Get model schema
17
+
18
+ Options:
19
+ -e, --env <env> Environment: stage|live (default: stage)
20
+ -d, --dm <shortID> DataManager short ID
21
+ -m, --model <name> Model name
22
+ -i, --id <entryID> Entry ID (for get/edit/delete)
23
+ --data <json> JSON data (for create/edit, or pipe via stdin)
24
+ -s, --size <n> Page size for list
25
+ -p, --page <n> Page number for list
26
+ --sort <field> Sort field for list
27
+ --raw Include _links and _embedded in output
28
+ -h, --help Show help`;function p(n){process.stderr.write(`Error: ${n}
29
+ `),process.exit(2)}function Kt(){return new Promise(n=>{let t="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",e=>t+=e),process.stdin.on("end",()=>n(t))})}async function D(n){if(n)try{return JSON.parse(n)}catch{p("--data must be valid JSON")}if(!process.stdin.isTTY){const t=await Kt();t.trim()||p("No data provided via stdin");try{return JSON.parse(t)}catch{p("Stdin must be valid JSON")}}p("Provide --data or pipe JSON via stdin")}async function Vt(){const{values:n,positionals:t}=M.parseArgs({allowPositionals:!0,options:{env:{type:"string",short:"e",default:"stage"},dm:{type:"string",short:"d"},model:{type:"string",short:"m"},id:{type:"string",short:"i"},data:{type:"string"},size:{type:"string",short:"s"},page:{type:"string",short:"p"},sort:{type:"string"},raw:{type:"boolean",default:!1},help:{type:"boolean",short:"h"}}});(n.help||t.length===0)&&(console.log(Ut),process.exit(0));const e=t[0],s=n.env;s!=="stage"&&s!=="live"&&p('--env must be "stage" or "live"');const r=new _({env:s,storageAdapter:Ft});if(e==="login"){const o=await Mt("Email: "),a=await Rt("Password: ");try{await r.loginEc({email:o,password:a}),process.stderr.write(`Logged in to ${s} successfully.
30
+ `)}catch(c){process.stderr.write(`Login failed: ${c.message}
31
+ `),process.exit(1)}return}n.dm||p("--dm is required"),n.model,n.model||p("--model is required");const i=r.dm(n.dm).model(n.model).clean(!n.raw);try{let o;switch(e){case"entryList":{const a={};n.size&&(a.size=Number(n.size)),n.page&&(a.page=Number(n.page)),n.sort&&(a.sort=[n.sort]),o=await i.entryList(a);break}case"getEntry":{n.id||p("--id is required for getEntry"),o=await i.getEntry(n.id);break}case"createEntry":{const a=await D(n.data);o=await i.createEntry(a);break}case"editEntry":{n.id||p("--id is required for editEntry");const a=await D(n.data);o=await i.editEntry(n.id,a);break}case"deleteEntry":{n.id||p("--id is required for deleteEntry"),await i.deleteEntry(n.id),process.stderr.write(`Entry deleted.
32
+ `);return}case"getSchema":{o=await i.getSchema();break}default:p(`Unknown command: ${e}`)}process.stdout.write(JSON.stringify(o,null,2)+`
33
+ `)}catch(o){process.stderr.write(`${o.message}
34
+ `),process.exit(1)}}Vt();
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var mt=Object.defineProperty,kt=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var wt=Object.prototype.hasOwnProperty,Et=Object.prototype.propertyIsEnumerable;var z=(n,t,e)=>t in n?mt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,a=(n,t)=>{for(var e in t||(t={}))wt.call(t,e)&&z(n,e,t[e]);if(F)for(var e of F(t))Et.call(t,e)&&z(n,e,t[e]);return n},g=(n,t)=>kt(n,$t(t));var l=(n,t,e)=>new Promise((s,r)=>{var u=o=>{try{d(e.next(o))}catch(c){r(c)}},i=o=>{try{d(e.throw(o))}catch(c){r(c)}},d=o=>o.done?s(o.value):Promise.resolve(o.value).then(u,i);d((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(s){return l(this,arguments,function*(n,t={},e={}){var d;const{token:r,rawRes:u}=t;r&&(e.headers=g(a({},e.headers||{}),{Authorization:`Bearer ${r}`}));const i=yield fetch(n,e);if(!i.ok){if((d=i.headers.get("content-type"))!=null&&d.includes("application/json")){const o=yield i.json(),c=`${o.title}
1
+ "use strict";var Et=Object.defineProperty,Tt=Object.defineProperties;var At=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var F=(n,t,e)=>t in n?Et(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,c=(n,t)=>{for(var e in t||(t={}))U.call(t,e)&&F(n,e,t[e]);if(A)for(var e of A(t))I.call(t,e)&&F(n,e,t[e]);return n},f=(n,t)=>Tt(n,At(t));var M=(n,t)=>{var e={};for(var s in n)U.call(n,s)&&t.indexOf(s)<0&&(e[s]=n[s]);if(n!=null&&A)for(var s of A(n))t.indexOf(s)<0&&I.call(n,s)&&(e[s]=n[s]);return e};var l=(n,t,e)=>new Promise((s,r)=>{var u=o=>{try{d(e.next(o))}catch(i){r(i)}},a=o=>{try{d(e.throw(o))}catch(i){r(i)}},d=o=>o.done?s(o.value):Promise.resolve(o.value).then(u,a);d((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(s){return l(this,arguments,function*(n,t={},e={}){var d;const{token:r,rawRes:u}=t;r&&(e.headers=f(c({},e.headers||{}),{Authorization:`Bearer ${r}`}));const a=yield fetch(n,e);if(!a.ok){if((d=a.headers.get("content-type"))!=null&&d.includes("application/json")){const o=yield a.json(),i=`${o.title}
2
2
  ${o.detail}
3
- ${o.verbose}`;throw new Error(c)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return u?i:yield i.json()})}const T={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 y(n,t="stage",e="datamanager"){const s=T[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(T).join(", ")}`);const r=s[t];if(!r)throw new Error(`env "${t}" not found. Try one of ${Object.keys(s[t]).join(", ")}`);return r+n}function $(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const N={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function J(n){return l(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const u=y(`api/${e}/_auth/login?clientID=rest`,t);return yield p(u,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function M(n){return l(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const r=`${N[t]}auth/login?clientID=rest`;return yield p(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function R(n){return l(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield p(r,{rawRes:!0},{method:"POST"})})}function U(n){return l(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${N[t]}auth/logout?clientID=rest`;return yield p(s,{rawRes:!0,token:e},{method:"POST"})})}function V({dmShortID:n}){return h({dmShortID:n}),n}function H({env:n}){return h({env:n}),n}let Tt=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function Q(n){let t={};for(let e in n)Tt.includes(e)||(t[e]=n[e]);return t}function bt(n){return JSON.parse(JSON.stringify(n))}function W(n){return l(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=y(`api/${e}`,t);return p(s,n)})}function S(n){return l(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;h({env:t,dmShortID:e,model:s}),r=a({size:50,page:1,_list:!0},r);const u=$(r),i=y(`api/${e}/${s}?${u}`,t),{count:d,total:o,_embedded:c}=yield p(i,n);let f=c?c[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:d,total:o,items:f}})}function X({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=$({_id:s}),i=y(`api/${t}/${e}?${u}`,n);return p(i,{token:r})}function Y(u){return l(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=y(`api/${t}/${e}`,n);return yield p(i,{token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function L(d){return l(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:u,safePut:i=!1}){h({env:n,dmShortID:t,model:e,entryID:s,value:r});const o={"Content-Type":"application/json"};if(i){if(!("_modified"in r))throw new Error("expected _modified to be set!");o["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const c=y(`api/${t}/${e}?_id=${s}`,n);return r=bt(r),r=Q(r),yield p(c,{token:u},{method:"PUT",headers:o,body:JSON.stringify(r)})})}function B({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=y(`api/${t}/${e}?_id=${s}`,n);return p(u,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}function Z(n,t){return l(this,null,function*(){let{env:e,dmShortID:s,model:r,options:u={}}=n;h({env:e,dmShortID:s,model:r}),n.options=a({size:50,page:1,_list:!0},u);let i=0,d,o=[];for(;d===void 0||i<d;){const c=yield S(n);for(let f of c.items)o.push(yield t(f));i+=c.items.length,d=c.total,n.options.page++}return o})}function G(r){return l(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var f,k,E,q,x;h({env:n,dmShortID:t,model:e});const u=y(`api/schema/${t}/${e}`,n),i=yield p(u),d=(f=i==null?void 0:i.allOf)==null?void 0:f[1];if(typeof d.properties!="object")throw new Error(`getSchema: ${u} returned unexpected format: ${JSON.stringify(i)}`);const{properties:o}=d,c=Q(o);for(let w in c){let m=c[w];if(m.required=d.required.includes(w),(k=c[w])!=null&&k.oneOf&&((E=c[w])==null||delete E.oneOf),(q=m.title)!=null&&q.includes("<")&&((x=m.title)!=null&&x.includes(">"))){const P=m.title.split("<")[1].slice(0,-1),yt=m.title.split("<")[0];m.type=yt,P.includes(":")?m.resource=P.split(":")[1]:m.resource=P}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete c[w].title}if(s){const w=o._modelTitle.title,m=o._modelTitleField.title;return{properties:c,meta:{modelTitleField:m,modelTitle:w}}}return c})}function v(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:a(a(a(a(a(a(a({},e.sort&&{sort:Array.isArray(e)?e.join(","):e}),e.search&&{[t+"~"]:e.search}),e.notNull&&{[t+"!"]:""}),e.null&&{[t]:""}),e.any&&{[t]:e.any.join(",")}),e.from&&{[t+"From"]:e.from}),e.to&&{[t+"To"]:e.to})).reduce((t,e)=>a(a({},t),e),{})}const tt=v;function j(n){return n._links.collection.href.split("/").slice(-2)[0]}function D(n){const t=n._links.collection.href.split("api/")[0];return Object.keys(T.datamanager).find(s=>T.datamanager[s]===t)}const et=n=>{const t=j(n),e=D(n),s=n._modelTitle,r=n.id;return{dmShortID:t,env:e,model:s,entryID:r}},nt=n=>B(et(n)),st=(n,t)=>L(g(a({},et(n)),{value:t}));function rt(n,t){const e=j(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}function ot(u){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=$({assetID:s}),d=y(`a/${t}/${e}?${i}`,n),{_embedded:o}=yield p(d,{token:r});return o?o["ec:dm-asset"]:void 0})}function it(n){return l(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:u={}}=n;h({env:t,dmShortID:e,assetGroup:s}),u=a({size:50,page:1,_list:!0},u);const i=$(u),d=y(`a/${e}/${s}?${i}`,t),{count:o,total:c,_embedded:f}=yield p(d,{token:r});let k=f?f["ec:dm-asset"]:[];return k=Array.isArray(k)?k:[k],{count:o,total:c,items:k}})}function ct(d){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:u,options:i}){h({env:n,dmShortID:t,assetGroup:e,file:r});const o=y(`a/${t}/${e}`,n),c=new FormData;return c.append("file",r,u),i&&Object.keys(i).forEach(k=>{c.append(k,i[k])}),(yield p(o,{token:s},{method:"POST",body:c}))._embedded["ec:dm-asset"]})}function at(u){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,files:s,options:r}){h({env:n,dmShortID:t,assetGroup:e,files:s});const i=y(`a/${t}/${e}`,n),d=new FormData;s.forEach(c=>{d.append("file",c)}),r&&Object.keys(r).forEach(c=>{d.append(c,r[c])});const o=yield p(i,{},{method:"POST",body:d});return Array.isArray(o._embedded["ec:dm-asset"])?o._embedded["ec:dm-asset"]:[o._embedded["ec:dm-asset"]]})}function ut(u){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=y(`a/${t}/${e}/${s}`,n);yield p(i,{token:r,rawRes:!0},{method:"DELETE"})})}function lt(n,t,e=!1){var i,d,o;let s,r;const u=e?n==null?void 0:n.thumbnails:n==null?void 0:n.fileVariants;return u==null||u.forEach(c=>{const{resolution:{width:f,height:k}}=c,E=Math.abs(Math.max(f,k)-t);(!r||E<r)&&(r=E,s=c)}),(o=(d=s==null?void 0:s.url)!=null?d:(i=n==null?void 0:n.file)==null?void 0:i.url)!=null?o:null}function dt(n){return l(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return p(r,{token:s})})}function ht(n){return l(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=a({size:25,page:1,_list:!0},e);const s=$(e),r=y(`?${s}`,t),{count:u,total:i,_embedded:d}=yield p(r,n);let o=d?d["ec:datamanager"]:[];return o=Array.isArray(o)?o:[o],{count:u,total:i,items:o}})}function gt(n){return l(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;h({env:t,dmID:e}),s=a({size:25,dataManagerID:e,page:1,_list:!0},s);const r=$(s),u=y(`model?${r}`,t),{count:i,total:d,_embedded:o}=yield p(u,n);let c=o?o["ec:model"]:[];return c=Array.isArray(c)?c:[c],{count:i,total:d,items:c}})}function ft(n){return l(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;h({env:t,subdomain:r,resource:e}),s=a({size:25,page:1,_list:!0},s);const u=$(s),i=y(`${e}?${u}`,t,r),{count:d,total:o,_embedded:c}=yield p(i,n);let f=c?c[Object.keys(c)[0]]:[];return f=Array.isArray(f)?f:[f],{count:d,total:o,items:f}})}function pt(e){return l(this,arguments,function*(n,t={}){let{env:s,route:r,options:u={},subdomain:i="datamanager"}=n;h({env:s,subdomain:i,route:r}),u=a({},u);const d=$(u),o=y(`${r}?${d}`,s,i);return p(o,n,t)})}const O=Object.freeze(Object.defineProperty({__proto__:null,assetList:it,createAsset:ct,createAssets:at,createEntry:Y,deleteAsset:ut,deleteEntry:B,deleteEntryObject:nt,dmList:ht,editEntry:L,editEntryObject:st,entryList:S,fileVariant:lt,filterOptions:tt,getAsset:ot,getDatamanager:dt,getEcAuthKey:H,getEntry:X,getEntryAsset:rt,getEntryEnv:D,getEntryShortID:j,getPublicAuthKey:V,getSchema:G,loginEc:M,loginPublic:J,logoutEc:U,logoutPublic:R,mapEntries:Z,modelList:gt,publicApi:W,raw:pt,resourceList:ft,sdkOptions:v},Symbol.toStringTag,{value:"Module"})),{entryList:C,mapEntries:At,getEntry:_t,getAsset:Ot,assetList:I,createAsset:jt,createAssets:Pt,deleteAsset:St,createEntry:Lt,editEntry:K,deleteEntry:Bt,getSchema:vt,loginPublic:Dt,loginEc:qt,logoutEc:xt,logoutPublic:Ft,getEcAuthKey:A,getPublicAuthKey:_,dmList:zt,modelList:Ct,publicApi:It,getDatamanager:Kt,resourceList:Nt,raw:Jt}=O;function Mt(n){const{action:t}=n;if(h({action:t}),!O[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(O).join(", ")}`);return O[t](n)}class b{constructor(t={}){if(!t.storageAdapter){let e=new Map;t.storageAdapter={get:s=>e.get(s),set:(s,r)=>e.set(s,r),remove:s=>e.delete(s)}}this.config=t}set(t){return new b(a(a({},this.config),t))}entries(){return l(this,arguments,function*(t={}){const e=yield this.getBestToken();return C(g(a({},this.config),{options:t,token:e}))})}entryList(t){return l(this,null,function*(){const e=yield this.getBestToken();return C(g(a({},this.config),{options:t,token:e}))})}mapEntries(s){return l(this,arguments,function*(t,e={}){const r=yield this.getBestToken();return At(g(a({},this.config),{options:e,token:r}),t)})}getEntry(t){return l(this,null,function*(){const e=yield this.getBestToken();return _t(g(a({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return l(this,null,function*(){const s=yield this.getBestToken();return K(g(a({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return l(this,null,function*(){return vt(this.config)})}assets(t){return l(this,null,function*(){const e=yield this.getBestToken();return I(g(a({},this.config),{options:t,token:e}))})}assetList(t){return l(this,null,function*(){const e=yield this.getBestToken();return I(g(a({},this.config),{options:t,token:e}))})}createAsset(t){return l(this,null,function*(){const{file:e,name:s,options:r}=t,u=yield this.getBestToken();return jt(g(a({},this.config),{file:e,name:s,options:r,token:u}))})}createAssets(t){return l(this,null,function*(){const{files:e,options:s}=t,r=yield this.getBestToken();return Pt(g(a({},this.config),{files:e,options:s,token:r}))})}deleteAsset(t){return l(this,null,function*(){const e=yield this.getBestToken();return St(g(a({},this.config),{token:e,assetID:t}))})}getAsset(t){return l(this,null,function*(){const e=yield this.getBestToken();return Ot(g(a({},this.config),{assetID:t,token:e}))})}createEntry(t){return l(this,null,function*(){const e=yield this.getBestToken();return Lt(g(a({},this.config),{token:e,value:t}))})}editEntry(t,e){return l(this,null,function*(){const s=yield this.getBestToken();return K(g(a({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return l(this,null,function*(){const e=yield this.getBestToken();return Bt(g(a({},this.config),{token:e,entryID:t}))})}resourceList(t){return l(this,null,function*(){const e=yield this.getBestToken();return Nt(g(a({},this.config),{options:t,token:e}))})}raw(t,e){return l(this,null,function*(){const s=yield this.getBestToken();return Jt(g(a({},this.config),{options:t,token:s}),e)})}storageAdapter(t){return this.set({storageAdapter:t})}removeToken(t){if(!this.config.storageAdapter)throw new Error("cannot removeToken: no storageAdapter defined!");const{remove:e}=this.config.storageAdapter;e(t)}getToken(t){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:e}=this.config.storageAdapter;return e(t)}getPublicToken(){return this.config.token||this.getToken(_(this.config))}getEcToken(){return this.config.token||this.getToken(A(this.config))}setToken(t,e){if(!this.config.storageAdapter)throw new Error("cannot setEcToken: no storageAdapter defined!");return this.config.storageAdapter.set(t,e)}setEcToken(t){this.setToken(A(this.config),t)}setPublicToken(t){this.setToken(_(this.config),t)}loginEc(t){return qt(a(a({},this.config),t)).then(e=>this.setToken(A(this.config),e.token))}loginPublic(t){return Dt(a(a({},this.config),t)).then(e=>this.setToken(_(this.config),e.token))}logoutPublic(){const t=this.getPublicToken();return Ft(g(a({},this.config),{token:t})).then(()=>this.removeToken(_(this.config)))}logoutEc(){const t=this.getEcToken();return xt(g(a({},this.config),{token:t})).then(()=>this.removeToken(A(this.config)))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch(t){return}}model(t){return this.set({model:t})}token(t){return this.set({token:t})}dmShortID(t){return this.set({dmShortID:t})}dm(t){return this.dmShortID(t)}dmID(t){return this.set({dmID:t})}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}subdomain(t){return this.set({subdomain:t})}resource(t){return this.set({resource:t})}route(t){return this.set({route:t})}publicApi(){return It(this.config)}getDatamanager(t){return l(this,null,function*(){const e=yield this.getBestToken();return Kt(g(a({},this.config),{dmID:t,token:e}))})}dmList(){return l(this,arguments,function*(t={}){const e=yield this.getBestToken();return zt(g(a({},this.config),{options:t,token:e}))})}modelList(){return l(this,arguments,function*(t={}){const e=yield this.getBestToken();return Ct(g(a({},this.config),{options:t,token:e}))})}}const Rt=n=>new b({env:n}),Ut=n=>new b({env:n});exports.Fdk=b;exports.act=Mt;exports.apiURL=y;exports.apis=T;exports.assetList=it;exports.createAsset=ct;exports.createAssets=at;exports.createEntry=Y;exports.deleteAsset=ut;exports.deleteEntry=B;exports.deleteEntryObject=nt;exports.dmList=ht;exports.editEntry=L;exports.editEntryObject=st;exports.entryList=S;exports.expect=h;exports.fdk=Rt;exports.fetcher=p;exports.fileVariant=lt;exports.filterOptions=tt;exports.getAsset=ot;exports.getDatamanager=dt;exports.getEcAuthKey=H;exports.getEntry=X;exports.getEntryAsset=rt;exports.getEntryEnv=D;exports.getEntryShortID=j;exports.getPublicAuthKey=V;exports.getSchema=G;exports.loginEc=M;exports.loginPublic=J;exports.logoutEc=U;exports.logoutPublic=R;exports.mapEntries=Z;exports.modelList=gt;exports.publicApi=W;exports.query=$;exports.raw=pt;exports.resourceList=ft;exports.sdk=Ut;exports.sdkOptions=v;
3
+ ${o.verbose}`;throw new Error(i)}throw new Error(`unexpected fetch error: ${a.statusText}`)}return u?a:yield a.json()})}const E={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 y(n,t="stage",e="datamanager"){const s=E[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(E).join(", ")}`);const r=s[t];if(!r)throw new Error(`env "${t}" not found. Try one of ${Object.keys(s[t]).join(", ")}`);return r+n}function w(n,t=!0){return Object.entries(n).sort((e,s)=>e[0].localeCompare(s[0])).map(([e,s])=>`${e}=${s}`).join("&")}function g(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const V={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function z(n){return l(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;g({env:t,dmShortID:e,email:s,password:r});const u=y(`api/${e}/_auth/login?clientID=rest`,t);return yield p(u,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function H(n){return l(this,null,function*(){let{env:t,email:e,password:s}=n;g({env:t,email:e,password:s});const r=`${V[t]}auth/login?clientID=rest`;return yield p(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function Q(n){return l(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;g({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield p(r,{rawRes:!0},{method:"POST"})})}function W(n){return l(this,null,function*(){let{env:t,token:e}=n;g({env:t,token:e});const s=`${V[t]}auth/logout?clientID=rest`;return yield p(s,{rawRes:!0,token:e},{method:"POST"})})}function X({dmShortID:n}){return g({dmShortID:n}),n}function Y({env:n}){return g({env:n}),n}let _t=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function Z(n){let t={};for(let e in n)_t.includes(e)||(t[e]=n[e]);return t}function Ot(n){return JSON.parse(JSON.stringify(n))}function G(n){return l(this,null,function*(){let{env:t,dmShortID:e}=n;g({env:t,dmShortID:e});const s=y(`api/${e}`,t);return p(s,n)})}function L(n){return l(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;g({env:t,dmShortID:e,model:s}),r=c({size:50,page:1,_list:!0},r);const u=w(r),a=y(`api/${e}/${s}?${u}`,t),{count:d,total:o,_embedded:i}=yield p(a,n);let h=i?i[`${e}:${s}`]:[];return h=Array.isArray(h)?h:[h],{count:d,total:o,items:h}})}function tt({env:n,dmShortID:t,model:e,entryID:s,token:r}){g({env:n,dmShortID:t,model:e,entryID:s});const u=w({_id:s}),a=y(`api/${t}/${e}?${u}`,n);return p(a,{token:r})}function et(u){return l(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){g({env:n,dmShortID:t,model:e,value:s});const a=y(`api/${t}/${e}`,n);return yield p(a,{token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function B(d){return l(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:u,safePut:a=!1}){g({env:n,dmShortID:t,model:e,entryID:s,value:r});const o={"Content-Type":"application/json"};if(a){if(!("_modified"in r))throw new Error("expected _modified to be set!");o["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const i=y(`api/${t}/${e}?_id=${s}`,n);return r=Ot(r),r=Z(r),yield p(i,{token:u},{method:"PUT",headers:o,body:JSON.stringify(r)})})}function D({env:n,dmShortID:t,model:e,entryID:s,token:r}){g({env:n,dmShortID:t,model:e,entryID:s});const u=y(`api/${t}/${e}?_id=${s}`,n);return p(u,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}function nt(n,t){return l(this,null,function*(){let{env:e,dmShortID:s,model:r,options:u={}}=n;g({env:e,dmShortID:s,model:r}),n.options=c({size:50,page:1,_list:!0},u);let a=0,d,o=[];for(;d===void 0||a<d;){const i=yield L(n);for(let h of i.items)o.push(yield t(h));a+=i.items.length,d=i.total,n.options.page++}return o})}function st(r){return l(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var h,m,k,q,x;g({env:n,dmShortID:t,model:e});const u=y(`api/schema/${t}/${e}`,n),a=yield p(u),d=(h=a==null?void 0:a.allOf)==null?void 0:h[1];if(typeof d.properties!="object")throw new Error(`getSchema: ${u} returned unexpected format: ${JSON.stringify(a)}`);const{properties:o}=d,i=Z(o);for(let b in i){let $=i[b];if($.required=d.required.includes(b),(m=i[b])!=null&&m.oneOf&&((k=i[b])==null||delete k.oneOf),(q=$.title)!=null&&q.includes("<")&&((x=$.title)!=null&&x.includes(">"))){const P=$.title.split("<")[1].slice(0,-1),bt=$.title.split("<")[0];$.type=bt,P.includes(":")?$.resource=P.split(":")[1]:$.resource=P}else["asset","entry","assets","entries"].includes($.title)?($.type=$.title,$.resource=null):$.type=$.title;delete i[b].title}if(s){const b=o._modelTitle.title,$=o._modelTitleField.title;return{properties:i,meta:{modelTitleField:$,modelTitle:b}}}return i})}function v(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:c(c(c(c(c(c(c({},e.sort&&{sort:Array.isArray(e)?e.join(","):e}),e.search&&{[t+"~"]:e.search}),e.notNull&&{[t+"!"]:""}),e.null&&{[t]:""}),e.any&&{[t]:e.any.join(",")}),e.from&&{[t+"From"]:e.from}),e.to&&{[t+"To"]:e.to})).reduce((t,e)=>c(c({},t),e),{})}const rt=v;function S(n){return n._links.collection.href.split("/").slice(-2)[0]}function C(n){const t=n._links.collection.href.split("api/")[0];return Object.keys(E.datamanager).find(s=>E.datamanager[s]===t)}const ot=n=>{const t=S(n),e=C(n),s=n._modelTitle,r=n.id;return{dmShortID:t,env:e,model:s,entryID:r}},it=n=>D(ot(n)),at=(n,t)=>B(f(c({},ot(n)),{value:t}));function ct(n,t){const e=S(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}function ut(u){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){g({env:n,dmShortID:t,assetGroup:e,assetID:s});const a=w({assetID:s}),d=y(`a/${t}/${e}?${a}`,n),{_embedded:o}=yield p(d,{token:r});return o?o["ec:dm-asset"]:void 0})}function lt(n){return l(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:u={}}=n;g({env:t,dmShortID:e,assetGroup:s}),u=c({size:50,page:1,_list:!0},u);const a=w(u),d=y(`a/${e}/${s}?${a}`,t),{count:o,total:i,_embedded:h}=yield p(d,{token:r});let m=h?h["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:o,total:i,items:m}})}function dt(d){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:u,options:a}){g({env:n,dmShortID:t,assetGroup:e,file:r});const o=y(`a/${t}/${e}`,n),i=new FormData;return i.append("file",r,u),a&&Object.keys(a).forEach(m=>{i.append(m,a[m])}),(yield p(o,{token:s},{method:"POST",body:i}))._embedded["ec:dm-asset"]})}function ht(u){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,files:s,options:r}){g({env:n,dmShortID:t,assetGroup:e,files:s});const a=y(`a/${t}/${e}`,n),d=new FormData;s.forEach(i=>{d.append("file",i)}),r&&Object.keys(r).forEach(i=>{d.append(i,r[i])});const o=yield p(a,{},{method:"POST",body:d});return Array.isArray(o._embedded["ec:dm-asset"])?o._embedded["ec:dm-asset"]:[o._embedded["ec:dm-asset"]]})}function gt(u){return l(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){g({env:n,dmShortID:t,assetGroup:e,assetID:s});const a=y(`a/${t}/${e}/${s}`,n);yield p(a,{token:r,rawRes:!0},{method:"DELETE"})})}function ft(n,t,e=!1){var a,d,o;let s,r;const u=e?n==null?void 0:n.thumbnails:n==null?void 0:n.fileVariants;return u==null||u.forEach(i=>{const{resolution:{width:h,height:m}}=i,k=Math.abs(Math.max(h,m)-t);(!r||k<r)&&(r=k,s=i)}),(o=(d=s==null?void 0:s.url)!=null?d:(a=n==null?void 0:n.file)==null?void 0:a.url)!=null?o:null}function pt(n="stage",t,e,s,r=!1){const u=Math.max(s.file.resolution.width,s.file.resolution.height),a=e.filter(o=>o<u),d=`https://datamanager${n==="stage"?".cachena":""}.entrecode.de`;return r?a.map(o=>{const i=s.thumbnails.find(k=>o===k.dimension),h=`${d}/t/${t}/${s.assetID}/${o}`,m=i?i.url:h;return{size:o,url:m,generated:i}}):a.map(o=>{const i=s.fileVariants.find(k=>o===Math.max(k.resolution.width,k.resolution.height)),h=`${d}/f/${t}/${s.assetID}/${o}`,m=i?i.url:h;return{size:o,url:m,generated:i}})}function yt(n){return l(this,null,function*(){let{env:t,dmID:e,token:s}=n;g({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return p(r,{token:s})})}function mt(n){return l(this,null,function*(){let{env:t,options:e={}}=n;g({env:t}),e=c({size:25,page:1,_list:!0},e);const s=w(e),r=y(`?${s}`,t),{count:u,total:a,_embedded:d}=yield p(r,n);let o=d?d["ec:datamanager"]:[];return o=Array.isArray(o)?o:[o],{count:u,total:a,items:o}})}function $t(n){return l(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;g({env:t,dmID:e}),s=c({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),u=y(`model?${r}`,t),{count:a,total:d,_embedded:o}=yield p(u,n);let i=o?o["ec:model"]:[];return i=Array.isArray(i)?i:[i],{count:a,total:d,items:i}})}function kt(n){return l(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;g({env:t,subdomain:r,resource:e}),s=c({size:25,page:1,_list:!0},s);const u=w(s),a=y(`${e}?${u}`,t,r),{count:d,total:o,_embedded:i}=yield p(a,n);let h=i?i[Object.keys(i)[0]]:[];return h=Array.isArray(h)?h:[h],{count:d,total:o,items:h}})}function wt(e){return l(this,arguments,function*(n,t={}){let{env:s,route:r,options:u={},subdomain:a="datamanager"}=n;g({env:s,subdomain:a,route:r}),u=c({},u);const d=w(u),o=y(`${r}?${d}`,s,a);return p(o,n,t)})}const j=Object.freeze(Object.defineProperty({__proto__:null,assetList:lt,createAsset:dt,createAssets:ht,createEntry:et,deleteAsset:gt,deleteEntry:D,deleteEntryObject:it,dmList:mt,editEntry:B,editEntryObject:at,entryList:L,fileVariant:ft,filterOptions:rt,getAsset:ut,getDatamanager:yt,getEcAuthKey:Y,getEntry:tt,getEntryAsset:ct,getEntryEnv:C,getEntryShortID:S,getFileVariants:pt,getPublicAuthKey:X,getSchema:st,loginEc:H,loginPublic:z,logoutEc:W,logoutPublic:Q,mapEntries:nt,modelList:$t,publicApi:G,raw:wt,resourceList:kt,sdkOptions:v},Symbol.toStringTag,{value:"Module"})),{entryList:K,mapEntries:jt,getEntry:St,getAsset:Pt,assetList:N,createAsset:Lt,createAssets:Bt,deleteAsset:Dt,createEntry:vt,editEntry:R,deleteEntry:Ct,getSchema:qt,loginPublic:xt,loginEc:Ft,logoutEc:Ut,logoutPublic:It,getEcAuthKey:_,getPublicAuthKey:O,dmList:Mt,modelList:Kt,publicApi:Nt,getDatamanager:Rt,resourceList:Jt,raw:Vt}=j;function zt(n){const{action:t}=n;if(g({action:t}),!j[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(j).join(", ")}`);return j[t](n)}function J(n){if(!n||typeof n!="object")return n;const r=n,{_links:t,_embedded:e}=r;return M(r,["_links","_embedded"])}function Ht(n){return!n||typeof n!="object"?n:Array.isArray(n.items)?f(c({},n),{items:n.items.map(J)}):J(n)}class T{constructor(t={}){if(!t.storageAdapter){let e=new Map;t.storageAdapter={get:s=>e.get(s),set:(s,r)=>e.set(s,r),remove:s=>e.delete(s)}}this.config=t}set(t){return new T(c(c({},this.config),t))}entries(){return l(this,arguments,function*(t={}){const e=yield this.getBestToken();return K(f(c({},this.config),{options:t,token:e}))})}entryList(t){return l(this,null,function*(){const e=yield this.getBestToken();return K(f(c({},this.config),{options:t,token:e})).then(s=>this.maybeClean(s))})}mapEntries(s){return l(this,arguments,function*(t,e={}){const r=yield this.getBestToken();return jt(f(c({},this.config),{options:e,token:r}),t)})}getEntry(t){return l(this,null,function*(){const e=yield this.getBestToken();return St(f(c({},this.config),{entryID:t,token:e})).then(s=>this.maybeClean(s))})}editEntrySafe(t,e){return l(this,null,function*(){const s=yield this.getBestToken();return R(f(c({},this.config),{entryID:t,token:s,value:e,safePut:!0})).then(r=>this.maybeClean(r))})}getSchema(){return l(this,null,function*(){return qt(this.config)})}assets(t){return l(this,null,function*(){const e=yield this.getBestToken();return N(f(c({},this.config),{options:t,token:e}))})}assetList(t){return l(this,null,function*(){const e=yield this.getBestToken();return N(f(c({},this.config),{options:t,token:e}))})}createAsset(t){return l(this,null,function*(){const{file:e,name:s,options:r}=t,u=yield this.getBestToken();return Lt(f(c({},this.config),{file:e,name:s,options:r,token:u}))})}createAssets(t){return l(this,null,function*(){const{files:e,options:s}=t,r=yield this.getBestToken();return Bt(f(c({},this.config),{files:e,options:s,token:r}))})}deleteAsset(t){return l(this,null,function*(){const e=yield this.getBestToken();return Dt(f(c({},this.config),{token:e,assetID:t}))})}getAsset(t){return l(this,null,function*(){const e=yield this.getBestToken();return Pt(f(c({},this.config),{assetID:t,token:e}))})}createEntry(t){return l(this,null,function*(){const e=yield this.getBestToken();return vt(f(c({},this.config),{token:e,value:t})).then(s=>this.maybeClean(s))})}editEntry(t,e){return l(this,null,function*(){const s=yield this.getBestToken();return R(f(c({},this.config),{entryID:t,token:s,value:e})).then(r=>this.maybeClean(r))})}deleteEntry(t){return l(this,null,function*(){const e=yield this.getBestToken();return Ct(f(c({},this.config),{token:e,entryID:t}))})}resourceList(t){return l(this,null,function*(){const e=yield this.getBestToken();return Jt(f(c({},this.config),{options:t,token:e}))})}raw(t,e){return l(this,null,function*(){const s=yield this.getBestToken();return Vt(f(c({},this.config),{options:t,token:s}),e)})}storageAdapter(t){return this.set({storageAdapter:t})}removeToken(t){if(!this.config.storageAdapter)throw new Error("cannot removeToken: no storageAdapter defined!");const{remove:e}=this.config.storageAdapter;e(t)}getToken(t){if(!this.config.storageAdapter)throw new Error("cannot getAuth: no storageAdapter defined!");const{get:e}=this.config.storageAdapter;return e(t)}getPublicToken(){return this.config.token||this.getToken(O(this.config))}getEcToken(){return this.config.token||this.getToken(_(this.config))}setToken(t,e){if(!this.config.storageAdapter)throw new Error("cannot setEcToken: no storageAdapter defined!");return this.config.storageAdapter.set(t,e)}setEcToken(t){this.setToken(_(this.config),t)}setPublicToken(t){this.setToken(O(this.config),t)}loginEc(t){return Ft(c(c({},this.config),t)).then(e=>this.setToken(_(this.config),e.token))}loginPublic(t){return xt(c(c({},this.config),t)).then(e=>this.setToken(O(this.config),e.token))}logoutPublic(){const t=this.getPublicToken();return It(f(c({},this.config),{token:t})).then(()=>this.removeToken(O(this.config)))}logoutEc(){const t=this.getEcToken();return Ut(f(c({},this.config),{token:t})).then(()=>this.removeToken(_(this.config)))}hasPublicToken(){return!!this.getPublicToken()}hasEcToken(){return!!this.getEcToken()}hasAnyToken(){return!!this.getEcToken()||!!this.getPublicToken()}getBestToken(){try{return this.getEcToken()||this.getPublicToken()}catch(t){return}}clean(t=!0){return this.set({_clean:t})}maybeClean(t){return this.config._clean?Ht(t):t}model(t){return this.set({model:t})}token(t){return this.set({token:t})}dmShortID(t){return this.set({dmShortID:t})}dm(t){return this.dmShortID(t)}dmID(t){return this.set({dmID:t})}assetGroup(t){return this.set({assetGroup:t})}assetgroup(t){return this.assetGroup(t)}subdomain(t){return this.set({subdomain:t})}resource(t){return this.set({resource:t})}route(t){return this.set({route:t})}publicApi(){return Nt(this.config)}getDatamanager(t){return l(this,null,function*(){const e=yield this.getBestToken();return Rt(f(c({},this.config),{dmID:t,token:e}))})}dmList(){return l(this,arguments,function*(t={}){const e=yield this.getBestToken();return Mt(f(c({},this.config),{options:t,token:e}))})}modelList(){return l(this,arguments,function*(t={}){const e=yield this.getBestToken();return Kt(f(c({},this.config),{options:t,token:e}))})}}const Qt=n=>new T({env:n}),Wt=n=>new T({env:n});exports.Fdk=T;exports.act=zt;exports.apiURL=y;exports.apis=E;exports.assetList=lt;exports.createAsset=dt;exports.createAssets=ht;exports.createEntry=et;exports.deleteAsset=gt;exports.deleteEntry=D;exports.deleteEntryObject=it;exports.dmList=mt;exports.editEntry=B;exports.editEntryObject=at;exports.entryList=L;exports.expect=g;exports.fdk=Qt;exports.fetcher=p;exports.fileVariant=ft;exports.filterOptions=rt;exports.getAsset=ut;exports.getDatamanager=yt;exports.getEcAuthKey=Y;exports.getEntry=tt;exports.getEntryAsset=ct;exports.getEntryEnv=C;exports.getEntryShortID=S;exports.getFileVariants=pt;exports.getPublicAuthKey=X;exports.getSchema=st;exports.loginEc=H;exports.loginPublic=z;exports.logoutEc=W;exports.logoutPublic=Q;exports.mapEntries=nt;exports.modelList=$t;exports.publicApi=G;exports.query=w;exports.raw=wt;exports.resourceList=kt;exports.sdk=Wt;exports.sdkOptions=v;