ec.fdk 0.4.4 → 0.4.6

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.hbs CHANGED
@@ -1,7 +1,6 @@
1
1
  # ec.fdk
2
2
 
3
- Lightweight SDK for entrecode APIs.
4
- Currently supports only most common PublicAPI functions.
3
+ *F*eatherweight *D*evelopment *K*it for entrecode APIs.
5
4
 
6
5
  ## Install
7
6
 
@@ -9,22 +8,21 @@ Currently supports only most common PublicAPI functions.
9
8
  npm i ec.fdk
10
9
  ```
11
10
 
12
- ## Publish
11
+ ## Getting Started
13
12
 
14
- 0. `cd packages/ec.fdk`
15
- 1. bump version in `packages/ec.fdk/package.json`
16
- 2. run `pnpm readme`
17
- 3. commit + push
18
- 4. run `pnpm publish`
13
+ There are 2 ways to use ec.fdk:
14
+
15
+ - method chaining
16
+ - act
19
17
 
20
- # API
18
+ ### Method Chaining
21
19
 
22
- Start by calling `sdk` with your environment (`stage` | `live`), then method chain your way to success:
20
+ Start by calling `fdk` with your environment (`stage` | `live`), then method chain your way to success:
23
21
 
24
22
  ```js
25
- import { sdk } from "ec.fdk";
23
+ import { fdk } from "ec.fdk";
26
24
 
27
- sdk("stage") // choose stage environment
25
+ fdk("stage") // choose stage environment
28
26
  .dm("83cc6374") // select datamanager via short id
29
27
  .model("muffin") // select model muffin
30
28
  .entries() // load entry list
@@ -37,7 +35,7 @@ You can also reuse parts of the chain with variables:
37
35
 
38
36
  ```js
39
37
  // we want to do stuff with model muffin here
40
- const muffin = sdk("stage").dm("83cc6374").model("muffin");
38
+ const muffin = fdk("stage").dm("83cc6374").model("muffin");
41
39
  // load entry list
42
40
  const { items } = await muffin.entries();
43
41
  // edit first entry
@@ -50,6 +48,177 @@ await muffin.createEntry({ name: "new muffin" });
50
48
  await muffin.editEntrySafe(items[2].id, { _modified: items[2]._modified, name: "safePut!" });
51
49
  ```
52
50
 
51
+ ### act
52
+
53
+ The act function converts a single object param into a fetch request:
54
+
55
+ ```js
56
+ const muffins = await act({
57
+ action: "entryList",
58
+ env: "stage",
59
+ dmShortID: "83cc6374",
60
+ model: "muffin",
61
+ })
62
+ ```
63
+
64
+ The object passed to `act` expects an `action` ([available actions](https://github.com/entrecode/ec.fdk/blob/main/packages/ec.fdk/src/lib/api.mjs))
65
+ + additional keys that are required to perform the action.
66
+ If you don't know the required keys for an action, either call `act` without additional keys or look it up in the source.
67
+ For example, this is how the `entryList` function looks:
68
+
69
+ ```js
70
+ export async function entryList(config) {
71
+ let { env, dmShortID, model, options = {} } = config;
72
+ expect({ env, dmShortID, model });
73
+ /* more stuff */
74
+ }
75
+ ```
76
+
77
+ here you can clearly see the available params.
78
+
79
+ ### Using act with swr / react-query
80
+
81
+ The act function is good to be used with swr or react-query:
82
+
83
+ ```js
84
+ import { act } from "ec.fdk";
85
+ import useSWR from "swr";
86
+
87
+ export function useFdk(config) {
88
+ const key = config ? JSON.stringify(config) : null;
89
+ return useSWR([key], () => act(config));
90
+ }
91
+ ```
92
+
93
+ Then use the hook:
94
+
95
+ ```js
96
+ const config = {
97
+ env: "stage",
98
+ dmShortID: "83cc6374",
99
+ };
100
+
101
+ function App() {
102
+ const { data: entryList } = useFdk({
103
+ ...config,
104
+ action: "entryList",
105
+ model: "muffin",
106
+ });
107
+ /* more stuff */
108
+ }
109
+ ```
110
+
111
+ ## migration from ec.sdk
112
+
113
+ ec.fdk won't change / decorate data returned from ec APIs. For example, an entry returned from the datamanager will be returned as is.
114
+ Advantages:
115
+
116
+ - The network tab shows what goes into the frontend
117
+ - Resources have the same shape everywhere
118
+ - Resources are serializable
119
+
120
+ ### Entry save
121
+
122
+ Instead of mutating an EntryResource and calling `.save()`, we now pass the new `value` directly:
123
+
124
+ ```js
125
+ // this does not exist anymore:
126
+ await entry.save(); // <- DONT
127
+ // use this to update an entry:
128
+ await editEntryObject(entry, value); // <- DO
129
+ // alternatively:
130
+ await fdk.env(env).dm(dmShortID).model(model).updateEntry(entryID, value);
131
+ // or:
132
+ await editEntry({ env, dmShortID, model, entryID, value });
133
+ ```
134
+
135
+ ### Entry delete
136
+
137
+ Similar to save:
138
+
139
+ ```js
140
+ // this does not exist anymore:
141
+ await entry.del(); // <- DONT
142
+ // use this to delete an entry:
143
+ await deleteEntryObject(entry); // <- DO
144
+ // alternatively:
145
+ await fdk.dm("shortID").model("model").deleteEntry("entryID");
146
+ ```
147
+
148
+ ### Entry Asset Fields
149
+
150
+ In ec.fdk, entry asset fields are plain ids:
151
+
152
+ ```js
153
+ // assuming "photo" is an asset field:
154
+ entry.photo; // <-- this used to be an AssetResource. Now it's a plain id string.
155
+ // use this to get the embedded AssetResource:
156
+ getEntryAsset("photo", entry); // (no request goes out)
157
+ ```
158
+
159
+ ### Entry Date Fields
160
+
161
+ ```js
162
+ // assuming "lastSeen" is a datetime field:
163
+ entry.lastSeen; // <-- this used to be an instance of Date. Now it's a date ISO string
164
+ // use this to get a Date instance:
165
+ new Date(entry.lastSeen);
166
+ ```
167
+
168
+ ### Entry List
169
+
170
+ ```js
171
+ // ec.sdk
172
+ const api = new PublicAPI(shortID, env, true);
173
+ const entryList = await api.entryList(model);
174
+ const items = entryList.getAllItems();
175
+ const first = entryList.getFirstItem();
176
+ // ec.fdk
177
+ const api = fdk(env).dm(shortID);
178
+ const entryList = await api.entryList(model);
179
+ const items = entryList.items; // <------- change
180
+ const first = entryList.items[0]; // <------- change
181
+ // or in one line:
182
+ const entryList = await fdk(env).dm(shortID).entryList(model);
183
+ ```
184
+
185
+ ### Entry List Filter Options
186
+
187
+ By default, the second param of ec.fdk `entryList` will just convert the object to url params:
188
+
189
+ ```js
190
+ const entryList = await fdk("stage")
191
+ .dm("83cc6374")
192
+ .entryList({ createdTo: "2021-01-18T09:13:47.605Z" });
193
+ /*
194
+ https://datamanager.cachena.entrecode.de/api/83cc6374/muffin?
195
+ _list=true&
196
+ createdTo=2021-01-18T09:13:47.605Z&
197
+ page=1&
198
+ size=50
199
+ */
200
+ ```
201
+
202
+ Read more in the [entrecode filtering doc](https://doc.entrecode.de/api-basics/#filtering)
203
+
204
+ There is some syntax sugar you can use to get the same behavior as [ec.sdk filterOptions](https://entrecode.github.io/ec.sdk/#filteroptions):
205
+
206
+ ```js
207
+ const entryList = await fdk("stage")
208
+ .dm("83cc6374")
209
+ .entryList(filterOptions({ created: { to: "2021-01-18T09:13:47.605Z" } }));
210
+ ```
211
+
212
+ ## Publish
213
+
214
+ 0. `cd packages/ec.fdk`
215
+ 1. bump version in `packages/ec.fdk/package.json`
216
+ 2. run `pnpm readme`
217
+ 3. commit + push
218
+ 4. run `pnpm publish`
219
+
220
+ ## API Reference
221
+
53
222
  Now what follows is the autogenerated doc from source:
54
223
 
55
224
  {{#module name="api"}}
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # ec.fdk
2
2
 
3
- Lightweight SDK for entrecode APIs.
4
- Currently supports only most common PublicAPI functions.
3
+ *F*eatherweight *D*evelopment *K*it for entrecode APIs.
5
4
 
6
5
  ## Install
7
6
 
@@ -9,22 +8,21 @@ Currently supports only most common PublicAPI functions.
9
8
  npm i ec.fdk
10
9
  ```
11
10
 
12
- ## Publish
11
+ ## Getting Started
13
12
 
14
- 0. `cd packages/ec.fdk`
15
- 1. bump version in `packages/ec.fdk/package.json`
16
- 2. run `pnpm readme`
17
- 3. commit + push
18
- 4. run `pnpm publish`
13
+ There are 2 ways to use ec.fdk:
14
+
15
+ - method chaining
16
+ - act
19
17
 
20
- # API
18
+ ### Method Chaining
21
19
 
22
- Start by calling `sdk` with your environment (`stage` | `live`), then method chain your way to success:
20
+ Start by calling `fdk` with your environment (`stage` | `live`), then method chain your way to success:
23
21
 
24
22
  ```js
25
- import { sdk } from "ec.fdk";
23
+ import { fdk } from "ec.fdk";
26
24
 
27
- sdk("stage") // choose stage environment
25
+ fdk("stage") // choose stage environment
28
26
  .dm("83cc6374") // select datamanager via short id
29
27
  .model("muffin") // select model muffin
30
28
  .entries() // load entry list
@@ -37,7 +35,7 @@ You can also reuse parts of the chain with variables:
37
35
 
38
36
  ```js
39
37
  // we want to do stuff with model muffin here
40
- const muffin = sdk("stage").dm("83cc6374").model("muffin");
38
+ const muffin = fdk("stage").dm("83cc6374").model("muffin");
41
39
  // load entry list
42
40
  const { items } = await muffin.entries();
43
41
  // edit first entry
@@ -50,6 +48,177 @@ await muffin.createEntry({ name: "new muffin" });
50
48
  await muffin.editEntrySafe(items[2].id, { _modified: items[2]._modified, name: "safePut!" });
51
49
  ```
52
50
 
51
+ ### act
52
+
53
+ The act function converts a single object param into a fetch request:
54
+
55
+ ```js
56
+ const muffins = await act({
57
+ action: "entryList",
58
+ env: "stage",
59
+ dmShortID: "83cc6374",
60
+ model: "muffin",
61
+ })
62
+ ```
63
+
64
+ The object passed to `act` expects an `action` ([available actions](https://github.com/entrecode/ec.fdk/blob/main/packages/ec.fdk/src/lib/api.mjs))
65
+ + additional keys that are required to perform the action.
66
+ If you don't know the required keys for an action, either call `act` without additional keys or look it up in the source.
67
+ For example, this is how the `entryList` function looks:
68
+
69
+ ```js
70
+ export async function entryList(config) {
71
+ let { env, dmShortID, model, options = {} } = config;
72
+ expect({ env, dmShortID, model });
73
+ /* more stuff */
74
+ }
75
+ ```
76
+
77
+ here you can clearly see the available params.
78
+
79
+ ### Using act with swr / react-query
80
+
81
+ The act function is good to be used with swr or react-query:
82
+
83
+ ```js
84
+ import { act } from "ec.fdk";
85
+ import useSWR from "swr";
86
+
87
+ export function useFdk(config) {
88
+ const key = config ? JSON.stringify(config) : null;
89
+ return useSWR([key], () => act(config));
90
+ }
91
+ ```
92
+
93
+ Then use the hook:
94
+
95
+ ```js
96
+ const config = {
97
+ env: "stage",
98
+ dmShortID: "83cc6374",
99
+ };
100
+
101
+ function App() {
102
+ const { data: entryList } = useFdk({
103
+ ...config,
104
+ action: "entryList",
105
+ model: "muffin",
106
+ });
107
+ /* more stuff */
108
+ }
109
+ ```
110
+
111
+ ## migration from ec.sdk
112
+
113
+ ec.fdk won't change / decorate data returned from ec APIs. For example, an entry returned from the datamanager will be returned as is.
114
+ Advantages:
115
+
116
+ - The network tab shows what goes into the frontend
117
+ - Resources have the same shape everywhere
118
+ - Resources are serializable
119
+
120
+ ### Entry save
121
+
122
+ Instead of mutating an EntryResource and calling `.save()`, we now pass the new `value` directly:
123
+
124
+ ```js
125
+ // this does not exist anymore:
126
+ await entry.save(); // <- DONT
127
+ // use this to update an entry:
128
+ await editEntryObject(entry, value); // <- DO
129
+ // alternatively:
130
+ await fdk.env(env).dm(dmShortID).model(model).updateEntry(entryID, value);
131
+ // or:
132
+ await editEntry({ env, dmShortID, model, entryID, value });
133
+ ```
134
+
135
+ ### Entry delete
136
+
137
+ Similar to save:
138
+
139
+ ```js
140
+ // this does not exist anymore:
141
+ await entry.del(); // <- DONT
142
+ // use this to delete an entry:
143
+ await deleteEntryObject(entry); // <- DO
144
+ // alternatively:
145
+ await fdk.dm("shortID").model("model").deleteEntry("entryID");
146
+ ```
147
+
148
+ ### Entry Asset Fields
149
+
150
+ In ec.fdk, entry asset fields are plain ids:
151
+
152
+ ```js
153
+ // assuming "photo" is an asset field:
154
+ entry.photo; // <-- this used to be an AssetResource. Now it's a plain id string.
155
+ // use this to get the embedded AssetResource:
156
+ getEntryAsset("photo", entry); // (no request goes out)
157
+ ```
158
+
159
+ ### Entry Date Fields
160
+
161
+ ```js
162
+ // assuming "lastSeen" is a datetime field:
163
+ entry.lastSeen; // <-- this used to be an instance of Date. Now it's a date ISO string
164
+ // use this to get a Date instance:
165
+ new Date(entry.lastSeen);
166
+ ```
167
+
168
+ ### Entry List
169
+
170
+ ```js
171
+ // ec.sdk
172
+ const api = new PublicAPI(shortID, env, true);
173
+ const entryList = await api.entryList(model);
174
+ const items = entryList.getAllItems();
175
+ const first = entryList.getFirstItem();
176
+ // ec.fdk
177
+ const api = fdk(env).dm(shortID);
178
+ const entryList = await api.entryList(model);
179
+ const items = entryList.items; // <------- change
180
+ const first = entryList.items[0]; // <------- change
181
+ // or in one line:
182
+ const entryList = await fdk(env).dm(shortID).entryList(model);
183
+ ```
184
+
185
+ ### Entry List Filter Options
186
+
187
+ By default, the second param of ec.fdk `entryList` will just convert the object to url params:
188
+
189
+ ```js
190
+ const entryList = await fdk("stage")
191
+ .dm("83cc6374")
192
+ .entryList({ createdTo: "2021-01-18T09:13:47.605Z" });
193
+ /*
194
+ https://datamanager.cachena.entrecode.de/api/83cc6374/muffin?
195
+ _list=true&
196
+ createdTo=2021-01-18T09:13:47.605Z&
197
+ page=1&
198
+ size=50
199
+ */
200
+ ```
201
+
202
+ Read more in the [entrecode filtering doc](https://doc.entrecode.de/api-basics/#filtering)
203
+
204
+ There is some syntax sugar you can use to get the same behavior as [ec.sdk filterOptions](https://entrecode.github.io/ec.sdk/#filteroptions):
205
+
206
+ ```js
207
+ const entryList = await fdk("stage")
208
+ .dm("83cc6374")
209
+ .entryList(filterOptions({ created: { to: "2021-01-18T09:13:47.605Z" } }));
210
+ ```
211
+
212
+ ## Publish
213
+
214
+ 0. `cd packages/ec.fdk`
215
+ 1. bump version in `packages/ec.fdk/package.json`
216
+ 2. run `pnpm readme`
217
+ 3. commit + push
218
+ 4. run `pnpm publish`
219
+
220
+ ## API Reference
221
+
53
222
  Now what follows is the autogenerated doc from source:
54
223
 
55
224
  <a name="module_api.Sdk"></a>
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var ct=Object.defineProperty,at=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var B=(n,t,e)=>t in n?ct(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,o=(n,t)=>{for(var e in t||(t={}))lt.call(t,e)&&B(n,e,t[e]);if(S)for(var e of S(t))dt.call(t,e)&&B(n,e,t[e]);return n},y=(n,t)=>at(n,ut(t));var a=(n,t,e)=>new Promise((s,r)=>{var u=c=>{try{d(e.next(c))}catch(l){r(l)}},i=c=>{try{d(e.throw(c))}catch(l){r(l)}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(u,i);d((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return a(this,arguments,function*(n,t={},e={}){var d;const{token:r,rawRes:u}=t;r&&(e.headers=y(o({},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 c=yield i.json(),l=`${c.title}
1
+ "use strict";var gt=Object.defineProperty,ft=Object.defineProperties;var yt=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,mt=Object.prototype.propertyIsEnumerable;var C=(n,t,e)=>t in n?gt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,o=(n,t)=>{for(var e in t||(t={}))pt.call(t,e)&&C(n,e,t[e]);if(x)for(var e of x(t))mt.call(t,e)&&C(n,e,t[e]);return n},f=(n,t)=>ft(n,yt(t));var a=(n,t,e)=>new Promise((s,r)=>{var u=c=>{try{d(e.next(c))}catch(l){r(l)}},i=c=>{try{d(e.throw(c))}catch(l){r(l)}},d=c=>c.done?s(c.value):Promise.resolve(c.value).then(u,i);d((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return a(this,arguments,function*(n,t={},e={}){var d;const{token:r,rawRes:u}=t;r&&(e.headers=f(o({},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 c=yield i.json(),l=`${c.title}
2
2
  ${c.detail}
3
- ${c.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return u?i:yield i.json()})}const D={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/"}};function p(n,t="stage",e="datamanager"){const s=D[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(D).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 h(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const x={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function K(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const u=p(`api/${e}/_auth/login?clientID=rest`,t);return yield g(u,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function N(n){return a(this,null,function*(){let{env:t,email:e,password:s}=n;h({env:t,email:e,password:s});const r=`${x[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function z(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=p(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function C(n){return a(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${x[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function F({dmShortID:n}){return h({dmShortID:n}),n}function J({env:n}){return h({env:n}),n}let ht=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function R(n){let t={};for(let e in n)ht.includes(e)||(t[e]=n[e]);return t}function gt(n){return JSON.parse(JSON.stringify(n))}function v(n){return a(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=p(`api/${e}`,t);return g(s,n)})}function U(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;h({env:t,dmShortID:e,model:s}),r=o({size:50,page:1,_list:!0},r);const u=w(r),i=p(`api/${e}/${s}?${u}`,t),{count:d,total:c,_embedded:l}=yield g(i,n);let f=l?l[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:d,total:c,items:f}})}function I({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=w({_id:s}),i=p(`api/${t}/${e}?${u}`,n);return g(i,{dmShortID:t,token:r})}function M(u){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=p(`api/${t}/${e}`,n);return yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function V(d){return a(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 c={"Content-Type":"application/json"};if(i){if(!("_modified"in r))throw new Error("expected _modified to be set!");c["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const l=p(`api/${t}/${e}?_id=${s}`,n);return r=gt(r),r=R(r),yield g(l,{token:u},{method:"PUT",headers:c,body:JSON.stringify(r)})})}function G({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=p(`api/${t}/${e}?_id=${s}`,n);return g(u,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}function H(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var f,$,O,L,j;h({env:n,dmShortID:t,model:e});const u=p(`api/schema/${t}/${e}`,n),i=yield g(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:c}=d,l=R(c);for(let A in l){let m=l[A];if(m.required=d.required.includes(A),($=l[A])!=null&&$.oneOf&&((O=l[A])==null||delete O.oneOf),(L=m.title)!=null&&L.includes("<")&&((j=m.title)!=null&&j.includes(">"))){const b=m.title.split("<")[1].slice(0,-1),ot=m.title.split("<")[0];m.type=ot,b.includes(":")?m.resource=b.split(":")[1]:m.resource=b}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete l[A].title}if(s){const A=c._modelTitle.title,m=c._modelTitleField.title;return{properties:l,meta:{modelTitleField:m,modelTitle:A}}}return l})}function Q(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:o(o(o(o(o(o(o({},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)=>o(o({},t),e),{})}function P(n){return n._links.collection.href.split("/").slice(-2)[0]}function W(n,t){const e=P(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}function X(u){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=w({assetID:s}),d=p(`a/${t}/${e}?${i}`,n);return(yield g(d,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function Y(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:u={}}=n;h({env:t,dmShortID:e,assetGroup:s}),u=o({size:50,page:1,_list:!0},u);const i=w(u),d=p(`a/${e}/${s}?${i}`,t),{count:c,total:l,_embedded:f}=yield g(d,{dmShortID:e,token:r});let $=f?f["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:c,total:l,items:$}})}function Z(d){return a(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 c=p(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,u),i&&Object.keys(i).forEach($=>{l.append($,i[$])}),(yield g(c,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function tt(u){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=p(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function et(n){return a(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=p(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function nt(n){return a(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=o({size:25,page:1,_list:!0},e);const s=w(e),r=p(`?${s}`,t),{count:u,total:i,_embedded:d}=yield g(r,n);let c=d?d["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:u,total:i,items:c}})}function st(n){return a(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;h({env:t,dmID:e}),s=o({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),u=p(`model?${r}`,t),{count:i,total:d,_embedded:c}=yield g(u,n);let l=c?c["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:i,total:d,items:l}})}function rt(n){return a(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;h({env:t,subdomain:r,resource:e}),s=o({size:25,page:1,_list:!0},s);const u=w(s),i=p(`${e}?${u}`,t,r),{count:d,total:c,_embedded:l}=yield g(i,n);let f=l?l[Object.keys(l)[0]]:[];return f=Array.isArray(f)?f:[f],{count:d,total:c,items:f}})}function it(e){return a(this,arguments,function*(n,t={}){let{env:s,route:r,options:u={},subdomain:i="datamanager"}=n;h({env:s,subdomain:i,route:r}),u=o({},u);const d=w(u),c=p(`${r}?${d}`,s,i);return g(c,n,t)})}const E=Object.freeze(Object.defineProperty({__proto__:null,assetList:Y,createAsset:Z,createEntry:M,deleteAsset:tt,deleteEntry:G,dmList:nt,editEntry:V,entryList:U,getAsset:X,getDatamanager:et,getEcAuthKey:J,getEntry:I,getEntryAsset:W,getEntryShortID:P,getPublicAuthKey:F,getSchema:H,loginEc:N,loginPublic:K,logoutEc:C,logoutPublic:z,modelList:st,publicApi:v,raw:it,resourceList:rt,sdkOptions:Q},Symbol.toStringTag,{value:"Module"})),{entryList:ft,getEntry:yt,getAsset:pt,assetList:mt,createAsset:$t,deleteAsset:wt,createEntry:At,editEntry:q,deleteEntry:Et,getSchema:kt,loginPublic:bt,loginEc:Tt,logoutEc:_t,logoutPublic:Pt,getEcAuthKey:T,getPublicAuthKey:_,dmList:Ot,modelList:Lt,publicApi:jt,getDatamanager:St,resourceList:Bt,raw:Dt}=E;function qt(n){const{action:t}=n;if(h({action:t}),!E[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(E).join(", ")}`);return E[t](n)}class k{constructor(t){this.config=t}set(t){return new k(o(o({},this.config),t))}entries(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return ft(y(o({},this.config),{options:t,token:e}))})}entryList(t){return a(this,null,function*(){return this.entries(t)})}getEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return yt(y(o({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return q(y(o({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return a(this,null,function*(){return kt(this.config)})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return mt(y(o({},this.config),{options:t,token:e}))})}assetList(t){return a(this,null,function*(){return this.assets(t)})}createAsset(){return a(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return $t(y(o({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return wt(y(o({},this.config),{token:e,assetID:t}))})}getAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return pt(y(o({},this.config),{assetID:t,token:e}))})}createEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return At(y(o({},this.config),{token:e,value:t}))})}editEntry(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return q(y(o({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return Et(y(o({},this.config),{token:e,entryID:t}))})}resourceList(t){return a(this,null,function*(){const e=yield this.getBestToken();return Bt(y(o({},this.config),{options:t,token:e}))})}raw(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return Dt(y(o({},this.config),{options:t,token:s}),e)})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:s}=this.config.authAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:s}=this.config.authAdapter;return s(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return Tt(o(o({},this.config),t)).then(this.setAuth(T(this.config)))}loginPublic(t){return bt(o(o({},this.config),t)).then(this.setAuth(_(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),Pt(y(o({},this.config),{token:t})).then(this.unsetAuth(_(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),_t(y(o({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}getPublicToken(){return this.config.token||this.getAuth(_(this.config))}getEcToken(){return this.config.token||this.getAuth(T(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})}dmID(t){return this.set({dmID:t})}dm(t){return this.dmShortID(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)}getDatamanager(t){return a(this,null,function*(){const e=yield this.getBestToken();return St(y(o({},this.config),{dmID:t,token:e}))})}dmList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return Ot(y(o({},this.config),{options:t,token:e}))})}modelList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return Lt(y(o({},this.config),{options:t,token:e}))})}}const xt=n=>new k({env:n});exports.Sdk=k;exports.act=qt;exports.apiURL=p;exports.assetList=Y;exports.createAsset=Z;exports.createEntry=M;exports.deleteAsset=tt;exports.deleteEntry=G;exports.dmList=nt;exports.editEntry=V;exports.entryList=U;exports.expect=h;exports.fetcher=g;exports.getAsset=X;exports.getDatamanager=et;exports.getEcAuthKey=J;exports.getEntry=I;exports.getEntryAsset=W;exports.getEntryShortID=P;exports.getPublicAuthKey=F;exports.getSchema=H;exports.loginEc=N;exports.loginPublic=K;exports.logoutEc=C;exports.logoutPublic=z;exports.modelList=st;exports.publicApi=v;exports.query=w;exports.raw=it;exports.resourceList=rt;exports.sdk=xt;exports.sdkOptions=Q;
3
+ ${c.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${i.statusText}`)}return u?i:yield i.json()})}const b={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/"}};function p(n,t="stage",e="datamanager"){const s=b[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(b).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 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 z(n){return a(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;h({env:t,dmShortID:e,email:s,password:r});const u=p(`api/${e}/_auth/login?clientID=rest`,t);return yield g(u,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function F(n){return a(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 g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function J(n){return a(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;h({dmShortID:t,env:e,token:s});const r=p(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function R(n){return a(this,null,function*(){let{env:t,token:e}=n;h({env:t,token:e});const s=`${N[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function U({dmShortID:n}){return h({dmShortID:n}),n}function I({env:n}){return h({env:n}),n}let $t=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function M(n){let t={};for(let e in n)$t.includes(e)||(t[e]=n[e]);return t}function wt(n){return JSON.parse(JSON.stringify(n))}function V(n){return a(this,null,function*(){let{env:t,dmShortID:e}=n;h({env:t,dmShortID:e});const s=p(`api/${e}`,t);return g(s,n)})}function G(n){return a(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;h({env:t,dmShortID:e,model:s}),r=o({size:50,page:1,_list:!0},r);const u=w(r),i=p(`api/${e}/${s}?${u}`,t),{count:d,total:c,_embedded:l}=yield g(i,n);let y=l?l[`${e}:${s}`]:[];return y=Array.isArray(y)?y:[y],{count:d,total:c,items:y}})}function H({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=w({_id:s}),i=p(`api/${t}/${e}?${u}`,n);return g(i,{dmShortID:t,token:r})}function Q(u){return a(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){h({env:n,dmShortID:t,model:e,value:s});const i=p(`api/${t}/${e}`,n);return yield g(i,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function P(d){return a(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 c={"Content-Type":"application/json"};if(i){if(!("_modified"in r))throw new Error("expected _modified to be set!");c["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const l=p(`api/${t}/${e}?_id=${s}`,n);return r=wt(r),r=M(r),yield g(l,{token:u},{method:"PUT",headers:c,body:JSON.stringify(r)})})}function L({env:n,dmShortID:t,model:e,entryID:s,token:r}){h({env:n,dmShortID:t,model:e,entryID:s});const u=p(`api/${t}/${e}?_id=${s}`,n);return g(u,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})}function W(r){return a(this,arguments,function*({env:n,dmShortID:t,model:e,withMetadata:s}){var y,$,D,q,v;h({env:n,dmShortID:t,model:e});const u=p(`api/schema/${t}/${e}`,n),i=yield g(u),d=(y=i==null?void 0:i.allOf)==null?void 0:y[1];if(typeof d.properties!="object")throw new Error(`getSchema: ${u} returned unexpected format: ${JSON.stringify(i)}`);const{properties:c}=d,l=M(c);for(let E in l){let m=l[E];if(m.required=d.required.includes(E),($=l[E])!=null&&$.oneOf&&((D=l[E])==null||delete D.oneOf),(q=m.title)!=null&&q.includes("<")&&((v=m.title)!=null&&v.includes(">"))){const _=m.title.split("<")[1].slice(0,-1),ht=m.title.split("<")[0];m.type=ht,_.includes(":")?m.resource=_.split(":")[1]:m.resource=_}else["asset","entry","assets","entries"].includes(m.title)?(m.type=m.title,m.resource=null):m.type=m.title;delete l[E].title}if(s){const E=c._modelTitle.title,m=c._modelTitleField.title;return{properties:l,meta:{modelTitleField:m,modelTitle:E}}}return l})}function S(n){return Object.entries(n).map(([t,e])=>typeof e!="object"?{[t]:String(e)}:o(o(o(o(o(o(o({},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)=>o(o({},t),e),{})}const X=S;function A(n){return n._links.collection.href.split("/").slice(-2)[0]}function B(n){const t=n._links.collection.href.split("api/")[0];return Object.keys(b.datamanager).find(s=>b.datamanager[s]===t)}const Y=n=>{const t=A(n),e=B(n),s=n._modelTitle,r=n.id;return{dmShortID:t,env:e,model:s,entryID:r}},Z=n=>L(Y(n)),tt=(n,t)=>P(f(o({},Y(n)),{value:t}));function et(n,t){const e=A(t);return t._embedded[`${e}:${t._modelTitle}/${n}/asset`]}function nt(u){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=w({assetID:s}),d=p(`a/${t}/${e}?${i}`,n);return(yield g(d,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function st(n){return a(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:u={}}=n;h({env:t,dmShortID:e,assetGroup:s}),u=o({size:50,page:1,_list:!0},u);const i=w(u),d=p(`a/${e}/${s}?${i}`,t),{count:c,total:l,_embedded:y}=yield g(d,{dmShortID:e,token:r});let $=y?y["ec:dm-asset"]:[];return $=Array.isArray($)?$:[$],{count:c,total:l,items:$}})}function rt(d){return a(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 c=p(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,u),i&&Object.keys(i).forEach($=>{l.append($,i[$])}),(yield g(c,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function it(u){return a(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){h({env:n,dmShortID:t,assetGroup:e,assetID:s});const i=p(`a/${t}/${e}/${s}`,n);yield g(i,{token:r,rawRes:!0},{method:"DELETE"})})}function ot(n){return a(this,null,function*(){let{env:t,dmID:e,token:s}=n;h({env:t,dmID:e});const r=p(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function ct(n){return a(this,null,function*(){let{env:t,options:e={}}=n;h({env:t}),e=o({size:25,page:1,_list:!0},e);const s=w(e),r=p(`?${s}`,t),{count:u,total:i,_embedded:d}=yield g(r,n);let c=d?d["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:u,total:i,items:c}})}function at(n){return a(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;h({env:t,dmID:e}),s=o({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),u=p(`model?${r}`,t),{count:i,total:d,_embedded:c}=yield g(u,n);let l=c?c["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:i,total:d,items:l}})}function ut(n){return a(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;h({env:t,subdomain:r,resource:e}),s=o({size:25,page:1,_list:!0},s);const u=w(s),i=p(`${e}?${u}`,t,r),{count:d,total:c,_embedded:l}=yield g(i,n);let y=l?l[Object.keys(l)[0]]:[];return y=Array.isArray(y)?y:[y],{count:d,total:c,items:y}})}function lt(e){return a(this,arguments,function*(n,t={}){let{env:s,route:r,options:u={},subdomain:i="datamanager"}=n;h({env:s,subdomain:i,route:r}),u=o({},u);const d=w(u),c=p(`${r}?${d}`,s,i);return g(c,n,t)})}const k=Object.freeze(Object.defineProperty({__proto__:null,assetList:st,createAsset:rt,createEntry:Q,deleteAsset:it,deleteEntry:L,deleteEntryObject:Z,dmList:ct,editEntry:P,editEntryObject:tt,entryList:G,filterOptions:X,getAsset:nt,getDatamanager:ot,getEcAuthKey:I,getEntry:H,getEntryAsset:et,getEntryEnv:B,getEntryShortID:A,getPublicAuthKey:U,getSchema:W,loginEc:F,loginPublic:z,logoutEc:R,logoutPublic:J,modelList:at,publicApi:V,raw:lt,resourceList:ut,sdkOptions:S},Symbol.toStringTag,{value:"Module"})),{entryList:Et,getEntry:bt,getAsset:kt,assetList:At,createAsset:Tt,deleteAsset:_t,createEntry:Ot,editEntry:K,deleteEntry:jt,getSchema:Pt,loginPublic:Lt,loginEc:St,logoutEc:Bt,logoutPublic:Dt,getEcAuthKey:O,getPublicAuthKey:j,dmList:qt,modelList:vt,publicApi:xt,getDatamanager:Ct,resourceList:Kt,raw:Nt}=k;function zt(n){const{action:t}=n;if(h({action:t}),!k[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(k).join(", ")}`);return k[t](n)}class T{constructor(t){this.config=t}set(t){return new T(o(o({},this.config),t))}entries(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return Et(f(o({},this.config),{options:t,token:e}))})}entryList(t){return a(this,null,function*(){return this.entries(t)})}getEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return bt(f(o({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return K(f(o({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return a(this,null,function*(){return Pt(this.config)})}assets(t){return a(this,null,function*(){const e=yield this.getBestToken();return At(f(o({},this.config),{options:t,token:e}))})}assetList(t){return a(this,null,function*(){return this.assets(t)})}createAsset(){return a(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return Tt(f(o({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return _t(f(o({},this.config),{token:e,assetID:t}))})}getAsset(t){return a(this,null,function*(){const e=yield this.getBestToken();return kt(f(o({},this.config),{assetID:t,token:e}))})}createEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return Ot(f(o({},this.config),{token:e,value:t}))})}editEntry(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return K(f(o({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return a(this,null,function*(){const e=yield this.getBestToken();return jt(f(o({},this.config),{token:e,entryID:t}))})}resourceList(t){return a(this,null,function*(){const e=yield this.getBestToken();return Kt(f(o({},this.config),{options:t,token:e}))})}raw(t,e){return a(this,null,function*(){const s=yield this.getBestToken();return Nt(f(o({},this.config),{options:t,token:s}),e)})}authAdapter(t){return this.set({authAdapter:t})}setAuth(t){return e=>{if(!this.config.authAdapter)throw new Error("cannot setAuth: no authAdapter defined!");const{set:s}=this.config.authAdapter;return s(t,e.token),e}}unsetAuth(t){return e=>{if(console.log("unset auth",e),!this.config.authAdapter)throw new Error("cannot unsetAuth: no authAdapter defined!");const{remove:s}=this.config.authAdapter;return s(t),e}}getAuth(t){if(!this.config.authAdapter)throw new Error("cannot getAuth: no authAdapter defined!");const{get:e}=this.config.authAdapter;return e(t)}loginEc(t){return St(o(o({},this.config),t)).then(this.setAuth(O(this.config)))}loginPublic(t){return Lt(o(o({},this.config),t)).then(this.setAuth(j(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),Dt(f(o({},this.config),{token:t})).then(this.unsetAuth(j(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),Bt(f(o({},this.config),{token:t})).then(this.unsetAuth(O(this.config)))}getPublicToken(){return this.config.token||this.getAuth(j(this.config))}getEcToken(){return this.config.token||this.getAuth(O(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})}dmID(t){return this.set({dmID:t})}dm(t){return this.dmShortID(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 xt(this.config)}getDatamanager(t){return a(this,null,function*(){const e=yield this.getBestToken();return Ct(f(o({},this.config),{dmID:t,token:e}))})}dmList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return qt(f(o({},this.config),{options:t,token:e}))})}modelList(){return a(this,arguments,function*(t={}){const e=yield this.getBestToken();return vt(f(o({},this.config),{options:t,token:e}))})}}const dt=n=>new T({env:n}),Ft=dt;exports.Sdk=T;exports.act=zt;exports.apiURL=p;exports.apis=b;exports.assetList=st;exports.createAsset=rt;exports.createEntry=Q;exports.deleteAsset=it;exports.deleteEntry=L;exports.deleteEntryObject=Z;exports.dmList=ct;exports.editEntry=P;exports.editEntryObject=tt;exports.entryList=G;exports.expect=h;exports.fdk=Ft;exports.fetcher=g;exports.filterOptions=X;exports.getAsset=nt;exports.getDatamanager=ot;exports.getEcAuthKey=I;exports.getEntry=H;exports.getEntryAsset=et;exports.getEntryEnv=B;exports.getEntryShortID=A;exports.getPublicAuthKey=U;exports.getSchema=W;exports.loginEc=F;exports.loginPublic=z;exports.logoutEc=R;exports.logoutPublic=J;exports.modelList=at;exports.publicApi=V;exports.query=w;exports.raw=lt;exports.resourceList=ut;exports.sdk=dt;exports.sdkOptions=S;