ec.fdk 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.hbs CHANGED
@@ -46,6 +46,8 @@ await muffin.editEntry(items[0].id, { name: "edit!" });
46
46
  await muffin.deleteEntry(items[1].id);
47
47
  // create a new muffin
48
48
  await muffin.createEntry({ name: "new muffin" });
49
+ // edit third entry with safePut
50
+ await muffin.editEntrySafe(items[2].id, { _modified: items[2]._modified, name: "safePut!" });
49
51
  ```
50
52
 
51
53
  Now what follows is the autogenerated doc from source:
package/README.md CHANGED
@@ -46,6 +46,8 @@ await muffin.editEntry(items[0].id, { name: "edit!" });
46
46
  await muffin.deleteEntry(items[1].id);
47
47
  // create a new muffin
48
48
  await muffin.createEntry({ name: "new muffin" });
49
+ // edit third entry with safePut
50
+ await muffin.editEntrySafe(items[2].id, { _modified: items[2]._modified, name: "safePut!" });
49
51
  ```
50
52
 
51
53
  Now what follows is the autogenerated doc from source:
@@ -60,6 +62,8 @@ Now what follows is the autogenerated doc from source:
60
62
  * [.Sdk](#module_api.Sdk)
61
63
  * [.entries([options])](#module_api.Sdk+entries) ⇒ [<code>Promise.&lt;EntryList&gt;</code>](#EntryList)
62
64
  * [.getEntry(entryID)](#module_api.Sdk+getEntry) ⇒ [<code>Promise.&lt;EntryResource&gt;</code>](#EntryResource)
65
+ * [.editEntrySafe(entryID, value)](#module_api.Sdk+editEntrySafe) ⇒ [<code>Promise.&lt;EntryResource&gt;</code>](#EntryResource)
66
+ * [.getSchema(entryID)](#module_api.Sdk+getSchema) ⇒ [<code>Promise.&lt;EntrySchema&gt;</code>](#EntrySchema)
63
67
  * [.assets([options])](#module_api.Sdk+assets) ⇒ [<code>Promise.&lt;AssetList&gt;</code>](#AssetList)
64
68
  * [.createAsset(options)](#module_api.Sdk+createAsset) ⇒ [<code>Promise.&lt;AssetResource&gt;</code>](#AssetResource)
65
69
  * [.deleteAsset(assetID)](#module_api.Sdk+deleteAsset) ⇒ <code>Promise.&lt;void&gt;</code>
@@ -67,13 +71,22 @@ Now what follows is the autogenerated doc from source:
67
71
  * [.createEntry(value)](#module_api.Sdk+createEntry) ⇒ [<code>Promise.&lt;EntryResource&gt;</code>](#EntryResource)
68
72
  * [.editEntry(entryID, value)](#module_api.Sdk+editEntry) ⇒ [<code>Promise.&lt;EntryResource&gt;</code>](#EntryResource)
69
73
  * [.deleteEntry(entryID)](#module_api.Sdk+deleteEntry) ⇒ <code>void</code>
74
+ * [.resourceList([options])](#module_api.Sdk+resourceList) ⇒ [<code>Promise.&lt;ResourceList&gt;</code>](#ResourceList)
75
+ * [.raw([options])](#module_api.Sdk+raw) ⇒ <code>Promise.&lt;any&gt;</code>
70
76
  * [.model(model)](#module_api.Sdk+model) ⇒
71
77
  * [.token(token)](#module_api.Sdk+token) ⇒
72
78
  * [.dmShortID(dmShortID)](#module_api.Sdk+dmShortID) ⇒
79
+ * [.dmID(dmID)](#module_api.Sdk+dmID) ⇒
73
80
  * [.dm(dmShortID)](#module_api.Sdk+dm) ⇒
74
81
  * [.assetGroup(assetGroup)](#module_api.Sdk+assetGroup) ⇒
75
82
  * [.assetgroup(assetGroup)](#module_api.Sdk+assetgroup) ⇒
83
+ * [.subdomain(subdomain)](#module_api.Sdk+subdomain) ⇒
84
+ * [.resource(resource)](#module_api.Sdk+resource) ⇒
85
+ * [.route(route)](#module_api.Sdk+route) ⇒
86
+ * [.publicApi()](#module_api.Sdk+publicApi) ⇒
87
+ * [.getDatamanager()](#module_api.Sdk+getDatamanager) ⇒
76
88
  * [.dmList([options])](#module_api.Sdk+dmList) ⇒ [<code>Promise.&lt;DatamanagerList&gt;</code>](#DatamanagerList)
89
+ * [.modelList([options])](#module_api.Sdk+modelList) ⇒ [<code>Promise.&lt;ModelList&gt;</code>](#ModelList)
77
90
 
78
91
  <a name="module_api.Sdk+entries"></a>
79
92
 
@@ -113,6 +126,42 @@ If the model is not public, you also need to provide a <code>token</code>.</p>
113
126
  ```js
114
127
  const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
115
128
  ```
129
+ <a name="module_api.Sdk+editEntrySafe"></a>
130
+
131
+ #### sdk.editEntrySafe(entryID, value) ⇒ [<code>Promise.&lt;EntryResource&gt;</code>](#EntryResource)
132
+ <p>Edits an entry with safe put. Expects <code>dmShortID</code> / <code>model</code> to be set.
133
+ Expects a <code>_modified</code> field in the value. Will only update if the entry has not been changed since.
134
+ If model PUT is not public, you also need to provide a <code>token</code>.</p>
135
+
136
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
137
+
138
+ | Param | Type | Description |
139
+ | --- | --- | --- |
140
+ | entryID | <code>string</code> | <p>id of entry to edit</p> |
141
+ | value | <code>object</code> | <p>values to set. undefined fields are ignored</p> |
142
+
143
+ **Example**
144
+ ```js
145
+ const entry = await sdk("stage")
146
+ .dm("83cc6374")
147
+ .model("muffin")
148
+ .editEntrySafe("1gOtzWvrdq", { name: "test", _modified: "2020-01-01T00:00:00.000Z"})
149
+ ```
150
+ <a name="module_api.Sdk+getSchema"></a>
151
+
152
+ #### sdk.getSchema(entryID) ⇒ [<code>Promise.&lt;EntrySchema&gt;</code>](#EntrySchema)
153
+ <p>Loads the schema of a model. Expects <code>dmShortID</code> / <code>model</code> to be set.</p>
154
+
155
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
156
+
157
+ | Param | Type |
158
+ | --- | --- |
159
+ | entryID | <code>string</code> |
160
+
161
+ **Example**
162
+ ```js
163
+ const muffin = await sdk("stage").dm("83cc6374").model("muffin").getSchema()
164
+ ```
116
165
  <a name="module_api.Sdk+assets"></a>
117
166
 
118
167
  #### sdk.assets([options]) ⇒ [<code>Promise.&lt;AssetList&gt;</code>](#AssetList)
@@ -246,6 +295,39 @@ If model DELETE is not public, you also need to provide a <code>token</code>.</p
246
295
  ```js
247
296
  await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
248
297
  ```
298
+ <a name="module_api.Sdk+resourceList"></a>
299
+
300
+ #### sdk.resourceList([options]) ⇒ [<code>Promise.&lt;ResourceList&gt;</code>](#ResourceList)
301
+ <p>Fetches resource list. Expects <code>resource</code> to be set. <code>subdomain</code> defaults to &quot;datamanager&quot;.
302
+ Fetches <code>https://&lt;subdomain&gt;.entrecode.de/&lt;resource&gt;?_list=true&amp;size=&lt;options.size ?? 25&gt;</code></p>
303
+
304
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
305
+
306
+ | Param | Type | Description |
307
+ | --- | --- | --- |
308
+ | [options] | <code>object</code> | <p>options for list request.</p> |
309
+
310
+ **Example**
311
+ ```js
312
+ const res = await sdk("stage").resource("template").resourceList()
313
+ ```
314
+ <a name="module_api.Sdk+raw"></a>
315
+
316
+ #### sdk.raw([options]) ⇒ <code>Promise.&lt;any&gt;</code>
317
+ <p>Fetches raw route. Expects <code>route</code> to be set. <code>subdomain</code> defaults to &quot;datamanager&quot;.
318
+ Fetches <code>https://&lt;subdomain&gt;.entrecode.de/&lt;route&gt;?&lt;options&gt;</code>
319
+ Use this when no other fdk method can give you your request.</p>
320
+
321
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
322
+
323
+ | Param | Type | Description |
324
+ | --- | --- | --- |
325
+ | [options] | <code>object</code> | <p>options for list request.</p> |
326
+
327
+ **Example**
328
+ ```js
329
+ const res = await sdk("stage").route("stats").raw()
330
+ ```
249
331
  <a name="module_api.Sdk+model"></a>
250
332
 
251
333
  #### sdk.model(model) ⇒
@@ -282,6 +364,18 @@ await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
282
364
  | --- | --- |
283
365
  | dmShortID | <code>string</code> |
284
366
 
367
+ <a name="module_api.Sdk+dmID"></a>
368
+
369
+ #### sdk.dmID(dmID) ⇒
370
+ <p>Sets the (long) ID of the datamanager to use</p>
371
+
372
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
373
+ **Returns**: <p>Sdk</p>
374
+
375
+ | Param | Type |
376
+ | --- | --- |
377
+ | dmID | <code>string</code> |
378
+
285
379
  <a name="module_api.Sdk+dm"></a>
286
380
 
287
381
  #### sdk.dm(dmShortID) ⇒
@@ -318,6 +412,56 @@ await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
318
412
  | --- | --- | --- |
319
413
  | assetGroup | <code>string</code> | <p>name of the asset group</p> |
320
414
 
415
+ <a name="module_api.Sdk+subdomain"></a>
416
+
417
+ #### sdk.subdomain(subdomain) ⇒
418
+ <p>Sets the subdomain to use.</p>
419
+
420
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
421
+ **Returns**: <p>Sdk</p>
422
+
423
+ | Param | Type | Description |
424
+ | --- | --- | --- |
425
+ | subdomain | <code>string</code> | <p>subdomain</p> |
426
+
427
+ <a name="module_api.Sdk+resource"></a>
428
+
429
+ #### sdk.resource(resource) ⇒
430
+ <p>Sets the name of the resource to use.</p>
431
+
432
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
433
+ **Returns**: <p>Sdk</p>
434
+
435
+ | Param | Type | Description |
436
+ | --- | --- | --- |
437
+ | resource | <code>string</code> | <p>name of the resource</p> |
438
+
439
+ <a name="module_api.Sdk+route"></a>
440
+
441
+ #### sdk.route(route) ⇒
442
+ <p>Sets the route to use.</p>
443
+
444
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
445
+ **Returns**: <p>Sdk</p>
446
+
447
+ | Param | Type | Description |
448
+ | --- | --- | --- |
449
+ | route | <code>string</code> | <p>route</p> |
450
+
451
+ <a name="module_api.Sdk+publicApi"></a>
452
+
453
+ #### sdk.publicApi() ⇒
454
+ <p>Returns the public api root endpoint. Expects dmShortID to be set.</p>
455
+
456
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
457
+ **Returns**: <p>any</p>
458
+ <a name="module_api.Sdk+getDatamanager"></a>
459
+
460
+ #### sdk.getDatamanager() ⇒
461
+ <p>Loads a DatamanagerResource by its long id. Requires token.</p>
462
+
463
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
464
+ **Returns**: <p>any</p>
321
465
  <a name="module_api.Sdk+dmList"></a>
322
466
 
323
467
  #### sdk.dmList([options]) ⇒ [<code>Promise.&lt;DatamanagerList&gt;</code>](#DatamanagerList)
@@ -331,11 +475,20 @@ await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
331
475
 
332
476
  **Example**
333
477
  ```js
334
- // public model
335
- const muffins = await sdk("stage").dm("83cc6374").model("muffin").entries()
478
+ const dms = await sdk("stage").dmList()
336
479
  ```
480
+ <a name="module_api.Sdk+modelList"></a>
481
+
482
+ #### sdk.modelList([options]) ⇒ [<code>Promise.&lt;ModelList&gt;</code>](#ModelList)
483
+ <p>Loads model list. Expects dmID to be set. Make sure to provide an ec.admin <code>token</code> intercept one.</p>
484
+
485
+ **Kind**: instance method of [<code>Sdk</code>](#module_api.Sdk)
486
+
487
+ | Param | Type | Description |
488
+ | --- | --- | --- |
489
+ | [options] | <code>object</code> | <p>options for entry list request.</p> |
490
+
337
491
  **Example**
338
492
  ```js
339
- // non-public model
340
- const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
493
+ const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
341
494
  ```
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var nt=Object.defineProperty,st=Object.defineProperties;var rt=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var ot=Object.prototype.hasOwnProperty,it=Object.prototype.propertyIsEnumerable;var j=(n,t,e)=>t in n?nt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))ot.call(t,e)&&j(n,e,t[e]);if(O)for(var e of O(t))it.call(t,e)&&j(n,e,t[e]);return n},p=(n,t)=>st(n,rt(t));var c=(n,t,e)=>new Promise((s,r)=>{var a=i=>{try{h(e.next(i))}catch(l){r(l)}},o=i=>{try{h(e.throw(i))}catch(l){r(l)}},h=i=>i.done?s(i.value):Promise.resolve(i.value).then(a,o);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return c(this,arguments,function*(n,t={},e={}){var h;const{token:r,rawRes:a}=t;r&&(e.headers=p(u({},e.headers||{}),{Authorization:`Bearer ${r}`}));const o=yield fetch(n,e);if(!o.ok){if((h=o.headers.get("content-type"))!=null&&h.includes("application/json")){const i=yield o.json(),l=`${i.title}
1
+ "use strict";var st=Object.defineProperty,rt=Object.defineProperties;var ot=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var it=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?st(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))it.call(t,e)&&S(n,e,t[e]);if(O)for(var e of O(t))ct.call(t,e)&&S(n,e,t[e]);return n},y=(n,t)=>rt(n,ot(t));var c=(n,t,e)=>new Promise((s,r)=>{var a=i=>{try{h(e.next(i))}catch(l){r(l)}},o=i=>{try{h(e.throw(i))}catch(l){r(l)}},h=i=>i.done?s(i.value):Promise.resolve(i.value).then(a,o);h((e=e.apply(n,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function g(s){return c(this,arguments,function*(n,t={},e={}){var h;const{token:r,rawRes:a}=t;r&&(e.headers=y(u({},e.headers||{}),{Authorization:`Bearer ${r}`}));const o=yield fetch(n,e);if(!o.ok){if((h=o.headers.get("content-type"))!=null&&h.includes("application/json")){const i=yield o.json(),l=`${i.title}
2
2
  ${i.detail}
3
- ${i.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${o.statusText}`)}return a?o:yield o.json()})}const S={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 y(n,t="stage",e="datamanager"){const s=S[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(S).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 d(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/"};function q(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;d({env:t,dmShortID:e,email:s,password:r});const a=y(`api/${e}/_auth/login?clientID=rest`,t);return yield g(a,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function D(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${B[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function v(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;d({dmShortID:t,env:e,token:s});const r=y(`api/${t}/_auth/logout?clientID=rest&token=${s}`,e);return yield g(r,{dmShortID:t,rawRes:!0},{method:"POST"})})}function K(n){return c(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${B[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function x({dmShortID:n}){return d({dmShortID:n}),n}function z({env:n}){return d({env:n}),n}let ct=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function J(n){let t={};for(let e in n)ct.includes(e)||(t[e]=n[e]);return t}function at(n){return JSON.parse(JSON.stringify(n))}function N(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=y(`api/${e}`,t);return g(s,n)})}function R(n){return c(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;d({env:t,dmShortID:e,model:s}),r=u({size:50,page:1,_list:!0},r);const a=w(r),o=y(`api/${e}/${s}?${a}`,t),{count:h,total:i,_embedded:l}=yield g(o,n);let f=l?l[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:h,total:i,items:f}})}function C({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=w({_id:s}),o=y(`api/${t}/${e}?${a}`,n);return g(o,{dmShortID:t,token:r})}function F(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){d({env:n,dmShortID:t,model:e,value:s});const o=y(`api/${t}/${e}`,n);return yield g(o,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function M(o){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const h=y(`api/${t}/${e}?_id=${s}`,n);return r=at(r),r=J(r),yield g(h,{token:a},{method:"PUT",body:JSON.stringify(r),headers:{"Content-Type":"application/json"}})})}function U(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const o=y(`api/${t}/${e}?_id=${s}`,n);yield g(o,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function V(s){return c(this,arguments,function*({env:n,dmShortID:t,model:e}){var l,f,m,_,L;d({env:n,dmShortID:t,model:e});const r=y(`api/schema/${t}/${e}`,n),a=yield g(r),o=(l=a==null?void 0:a.allOf)==null?void 0:l[1];if(typeof o.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:h}=o,i=J(h);for(let k in i){let $=i[k];if($.required=o.required.includes(k),(f=i[k])!=null&&f.oneOf&&((m=i[k])==null||delete m.oneOf),(_=$.title)!=null&&_.includes("<")&&((L=$.title)!=null&&L.includes(">"))){const b=$.title.split("<")[1].slice(0,-1),et=$.title.split("<")[0];$.type=et,b.includes(":")?$.resource=b.split(":")[1]:$.resource=b}else["asset","entry","assets","entries"].includes($.title)?($.type=$.title,$.resource=null):$.type=$.title;delete i[k].title}return i})}function G(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const o=w({assetID:s}),h=y(`a/${t}/${e}?${o}`,n);return(yield g(h,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function H(n){return c(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:a={}}=n;d({env:t,dmShortID:e,assetGroup:s}),a=u({size:50,page:1,_list:!0},a);const o=w(a),h=y(`a/${e}/${s}?${o}`,t),{count:i,total:l,_embedded:f}=yield g(h,{dmShortID:e,token:r});let m=f?f["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:i,total:l,items:m}})}function I(h){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:o}){d({env:n,dmShortID:t,assetGroup:e,file:r});const i=y(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,a),o&&Object.keys(o).forEach(m=>{l.append(m,o[m])}),(yield g(i,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function Q(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const o=y(`a/${t}/${e}/${s}`,n);yield g(o,{token:r,rawRes:!0},{method:"DELETE"})})}function W(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=y(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function X(n){return c(this,null,function*(){let{env:t,options:e={}}=n;d({env:t}),e=u({size:25,page:1,_list:!0},e);const s=w(e),r=y(`?${s}`,t),{count:a,total:o,_embedded:h}=yield g(r,n);let i=h?h["ec:datamanager"]:[];return i=Array.isArray(i)?i:[i],{count:a,total:o,items:i}})}function Y(n){return c(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;d({env:t,dmID:e}),s=u({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),a=y(`model?${r}`,t),{count:o,total:h,_embedded:i}=yield g(a,n);let l=i?i["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:o,total:h,items:l}})}function Z(n){return c(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;d({env:t,subdomain:r,resource:e}),s=u({size:25,page:1,_list:!0},s);const a=w(s),o=y(`${e}?${a}`,t,r),{count:h,total:i,_embedded:l}=yield g(o,n);let f=l?l[Object.keys(l)[0]]:[];return f=Array.isArray(f)?f:[f],{count:h,total:i,items:f}})}function tt(e){return c(this,arguments,function*(n,t={}){let{env:s,route:r,options:a={},subdomain:o="datamanager"}=n;d({env:s,subdomain:o,route:r}),a=u({},a);const h=w(a),i=y(`${r}?${h}`,s,o);return g(i,n,t)})}const A=Object.freeze(Object.defineProperty({__proto__:null,assetList:H,createAsset:I,createEntry:F,deleteAsset:Q,deleteEntry:U,dmList:X,editEntry:M,entryList:R,getAsset:G,getDatamanager:W,getEcAuthKey:z,getEntry:C,getPublicAuthKey:x,getSchema:V,loginEc:D,loginPublic:q,logoutEc:K,logoutPublic:v,modelList:Y,publicApi:N,raw:tt,resourceList:Z},Symbol.toStringTag,{value:"Module"})),{entryList:ut,getEntry:lt,getAsset:ht,assetList:dt,createAsset:gt,deleteAsset:yt,createEntry:ft,editEntry:pt,deleteEntry:$t,getSchema:mt,loginPublic:wt,loginEc:kt,logoutEc:At,logoutPublic:Et,getEcAuthKey:T,getPublicAuthKey:P,dmList:bt,modelList:Tt,publicApi:Pt,getDatamanager:_t,resourceList:Lt,raw:Ot}=A;function jt(n){const{action:t}=n;if(d({action:t}),!A[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(A).join(", ")}`);return A[t](n)}class E{constructor(t){this.config=t}set(t){return new E(u(u({},this.config),t))}entries(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return ut(p(u({},this.config),{options:t,token:e}))})}entryList(t){return c(this,null,function*(){return this.entries(t)})}getEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return lt(p(u({},this.config),{entryID:t,token:e}))})}getSchema(){return c(this,null,function*(){return mt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return dt(p(u({},this.config),{options:t,token:e}))})}assetList(t){return c(this,null,function*(){return this.assets(t)})}createAsset(){return c(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return gt(p(u({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return yt(p(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return ht(p(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return ft(p(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return pt(p(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return $t(p(u({},this.config),{token:e,entryID:t}))})}resourceList(t){return c(this,null,function*(){const e=yield this.getBestToken();return Lt(p(u({},this.config),{options:t,token:e}))})}raw(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return Ot(p(u({},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 kt(u(u({},this.config),t)).then(this.setAuth(T(this.config)))}loginPublic(t){return wt(u(u({},this.config),t)).then(this.setAuth(P(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),Et(p(u({},this.config),{token:t})).then(this.unsetAuth(P(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),At(p(u({},this.config),{token:t})).then(this.unsetAuth(T(this.config)))}getPublicToken(){return this.config.token||this.getAuth(P(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 Pt(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return _t(p(u({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return bt(p(u({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Tt(p(u({},this.config),{options:t,token:e}))})}}const St=n=>new E({env:n});exports.Sdk=E;exports.act=jt;exports.apiURL=y;exports.assetList=H;exports.createAsset=I;exports.createEntry=F;exports.deleteAsset=Q;exports.deleteEntry=U;exports.dmList=X;exports.editEntry=M;exports.entryList=R;exports.expect=d;exports.fetcher=g;exports.getAsset=G;exports.getDatamanager=W;exports.getEcAuthKey=z;exports.getEntry=C;exports.getPublicAuthKey=x;exports.getSchema=V;exports.loginEc=D;exports.loginPublic=q;exports.logoutEc=K;exports.logoutPublic=v;exports.modelList=Y;exports.publicApi=N;exports.query=w;exports.raw=tt;exports.resourceList=Z;exports.sdk=St;
3
+ ${i.verbose}`;throw new Error(l)}throw new Error(`unexpected fetch error: ${o.statusText}`)}return a?o:yield o.json()})}const j={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=j[e];if(!s)throw new Error(`subdomain "${e}" not found. Try one of ${Object.keys(j).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 d(n){Object.entries(n).forEach(([t,e])=>{if(e===void 0)throw new Error(`expected ${t} to be set!`)})}const q={stage:"https://accounts.cachena.entrecode.de/",live:"https://accounts.entrecode.de/"};function D(n){return c(this,null,function*(){let{env:t,dmShortID:e,email:s,password:r}=n;d({env:t,dmShortID:e,email:s,password:r});const a=p(`api/${e}/_auth/login?clientID=rest`,t);return yield g(a,{},{method:"POST",body:JSON.stringify({email:s,password:r}),headers:{"Content-Type":"application/json"}})})}function x(n){return c(this,null,function*(){let{env:t,email:e,password:s}=n;d({env:t,email:e,password:s});const r=`${q[t]}auth/login?clientID=rest`;return yield g(r,{},{method:"POST",body:JSON.stringify({email:e,password:s}),headers:{"Content-Type":"application/json"}})})}function K(n){return c(this,null,function*(){let{dmShortID:t,env:e,token:s}=n;d({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 z(n){return c(this,null,function*(){let{env:t,token:e}=n;d({env:t,token:e});const s=`${q[t]}auth/logout?clientID=rest`;return yield g(s,{rawRes:!0,token:e},{method:"POST"})})}function C({dmShortID:n}){return d({dmShortID:n}),n}function J({env:n}){return d({env:n}),n}let at=["created","creator","id","modified","private","_created","_creator","_embedded","_entryTitle","_id","_links","_modelTitle","_modelTitleField","_modified"];function N(n){let t={};for(let e in n)at.includes(e)||(t[e]=n[e]);return t}function ut(n){return JSON.parse(JSON.stringify(n))}function R(n){return c(this,null,function*(){let{env:t,dmShortID:e}=n;d({env:t,dmShortID:e});const s=p(`api/${e}`,t);return g(s,n)})}function v(n){return c(this,null,function*(){let{env:t,dmShortID:e,model:s,options:r={}}=n;d({env:t,dmShortID:e,model:s}),r=u({size:50,page:1,_list:!0},r);const a=w(r),o=p(`api/${e}/${s}?${a}`,t),{count:h,total:i,_embedded:l}=yield g(o,n);let f=l?l[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:h,total:i,items:f}})}function U({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const a=w({_id:s}),o=p(`api/${t}/${e}?${a}`,n);return g(o,{dmShortID:t,token:r})}function F(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,value:s,token:r}){d({env:n,dmShortID:t,model:e,value:s});const o=p(`api/${t}/${e}`,n);return yield g(o,{env:n,dmShortID:t,token:r},{method:"POST",body:JSON.stringify(s),headers:{"Content-Type":"application/json"}})})}function M(h){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,value:r,token:a,safePut:o=!1}){d({env:n,dmShortID:t,model:e,entryID:s,value:r});const i={"Content-Type":"application/json"};if(o){if(!("_modified"in r))throw new Error("expected _modified to be set!");i["If-Unmodified-Since"]=new Date(r._modified).toUTCString()}const l=p(`api/${t}/${e}?_id=${s}`,n);return r=ut(r),r=N(r),yield g(l,{token:a},{method:"PUT",headers:i,body:JSON.stringify(r)})})}function I(a){return c(this,arguments,function*({env:n,dmShortID:t,model:e,entryID:s,token:r}){d({env:n,dmShortID:t,model:e,entryID:s});const o=p(`api/${t}/${e}?_id=${s}`,n);yield g(o,{token:r,rawRes:!0},{method:"DELETE",headers:{"Content-Type":"application/json"}})})}function V(s){return c(this,arguments,function*({env:n,dmShortID:t,model:e}){var l,f,m,P,L;d({env:n,dmShortID:t,model:e});const r=p(`api/schema/${t}/${e}`,n),a=yield g(r),o=(l=a==null?void 0:a.allOf)==null?void 0:l[1];if(typeof o.properties!="object")throw new Error(`getSchema: ${r} returned unexpected format: ${JSON.stringify(a)}`);const{properties:h}=o,i=N(h);for(let k in i){let $=i[k];if($.required=o.required.includes(k),(f=i[k])!=null&&f.oneOf&&((m=i[k])==null||delete m.oneOf),(P=$.title)!=null&&P.includes("<")&&((L=$.title)!=null&&L.includes(">"))){const b=$.title.split("<")[1].slice(0,-1),nt=$.title.split("<")[0];$.type=nt,b.includes(":")?$.resource=b.split(":")[1]:$.resource=b}else["asset","entry","assets","entries"].includes($.title)?($.type=$.title,$.resource=null):$.type=$.title;delete i[k].title}return i})}function G(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const o=w({assetID:s}),h=p(`a/${t}/${e}?${o}`,n);return(yield g(h,{dmShortID:t,token:r}))._embedded["ec:dm-asset"]})}function H(n){return c(this,null,function*(){let{env:t,dmShortID:e,assetGroup:s,token:r,options:a={}}=n;d({env:t,dmShortID:e,assetGroup:s}),a=u({size:50,page:1,_list:!0},a);const o=w(a),h=p(`a/${e}/${s}?${o}`,t),{count:i,total:l,_embedded:f}=yield g(h,{dmShortID:e,token:r});let m=f?f["ec:dm-asset"]:[];return m=Array.isArray(m)?m:[m],{count:i,total:l,items:m}})}function Q(h){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,token:s,file:r,name:a,options:o}){d({env:n,dmShortID:t,assetGroup:e,file:r});const i=p(`a/${t}/${e}`,n),l=new FormData;return l.append("file",r,a),o&&Object.keys(o).forEach(m=>{l.append(m,o[m])}),(yield g(i,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function W(a){return c(this,arguments,function*({env:n,dmShortID:t,assetGroup:e,assetID:s,token:r}){d({env:n,dmShortID:t,assetGroup:e,assetID:s});const o=p(`a/${t}/${e}/${s}`,n);yield g(o,{token:r,rawRes:!0},{method:"DELETE"})})}function X(n){return c(this,null,function*(){let{env:t,dmID:e,token:s}=n;d({env:t,dmID:e});const r=p(`?dataManagerID=${e}`,t);return g(r,{token:s})})}function Y(n){return c(this,null,function*(){let{env:t,options:e={}}=n;d({env:t}),e=u({size:25,page:1,_list:!0},e);const s=w(e),r=p(`?${s}`,t),{count:a,total:o,_embedded:h}=yield g(r,n);let i=h?h["ec:datamanager"]:[];return i=Array.isArray(i)?i:[i],{count:a,total:o,items:i}})}function Z(n){return c(this,null,function*(){let{env:t,dmID:e,options:s={}}=n;d({env:t,dmID:e}),s=u({size:25,dataManagerID:e,page:1,_list:!0},s);const r=w(s),a=p(`model?${r}`,t),{count:o,total:h,_embedded:i}=yield g(a,n);let l=i?i["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:o,total:h,items:l}})}function tt(n){return c(this,null,function*(){let{env:t,resource:e,options:s={},subdomain:r="datamanager"}=n;d({env:t,subdomain:r,resource:e}),s=u({size:25,page:1,_list:!0},s);const a=w(s),o=p(`${e}?${a}`,t,r),{count:h,total:i,_embedded:l}=yield g(o,n);let f=l?l[Object.keys(l)[0]]:[];return f=Array.isArray(f)?f:[f],{count:h,total:i,items:f}})}function et(n){return c(this,null,function*(){let{env:t,route:e,options:s={},subdomain:r="datamanager"}=n;d({env:t,subdomain:r,route:e}),s=u({},s);const a=w(s),o=p(`${e}?${a}`,t,r);return g(o,n)})}const A=Object.freeze(Object.defineProperty({__proto__:null,assetList:H,createAsset:Q,createEntry:F,deleteAsset:W,deleteEntry:I,dmList:Y,editEntry:M,entryList:v,getAsset:G,getDatamanager:X,getEcAuthKey:J,getEntry:U,getPublicAuthKey:C,getSchema:V,loginEc:x,loginPublic:D,logoutEc:z,logoutPublic:K,modelList:Z,publicApi:R,raw:et,resourceList:tt},Symbol.toStringTag,{value:"Module"})),{entryList:lt,getEntry:dt,getAsset:ht,assetList:gt,createAsset:ft,deleteAsset:yt,createEntry:pt,editEntry:B,deleteEntry:$t,getSchema:mt,loginPublic:wt,loginEc:kt,logoutEc:At,logoutPublic:Et,getEcAuthKey:T,getPublicAuthKey:_,dmList:bt,modelList:Tt,publicApi:_t,getDatamanager:Pt,resourceList:Lt,raw:Ot}=A;function St(n){const{action:t}=n;if(d({action:t}),!A[t])throw new Error(`"${t}" does not exist! try one of ${Object.keys(A).join(", ")}`);return A[t](n)}class E{constructor(t){this.config=t}set(t){return new E(u(u({},this.config),t))}entries(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return lt(y(u({},this.config),{options:t,token:e}))})}entryList(t){return c(this,null,function*(){return this.entries(t)})}getEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return dt(y(u({},this.config),{entryID:t,token:e}))})}editEntrySafe(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return B(y(u({},this.config),{entryID:t,token:s,value:e,safePut:!0}))})}getSchema(){return c(this,null,function*(){return mt(this.config)})}assets(t){return c(this,null,function*(){const e=yield this.getBestToken();return gt(y(u({},this.config),{options:t,token:e}))})}assetList(t){return c(this,null,function*(){return this.assets(t)})}createAsset(){return c(this,arguments,function*({file:t,name:e,options:s}={}){const r=yield this.getBestToken();return ft(y(u({},this.config),{file:t,name:e,options:s,token:r}))})}deleteAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return yt(y(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return c(this,null,function*(){const e=yield this.getBestToken();return ht(y(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return pt(y(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return c(this,null,function*(){const s=yield this.getBestToken();return B(y(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return c(this,null,function*(){const e=yield this.getBestToken();return $t(y(u({},this.config),{token:e,entryID:t}))})}resourceList(t){return c(this,null,function*(){const e=yield this.getBestToken();return Lt(y(u({},this.config),{options:t,token:e}))})}raw(t){return c(this,null,function*(){const e=yield this.getBestToken();return Ot(y(u({},this.config),{options:t,token: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 kt(u(u({},this.config),t)).then(this.setAuth(T(this.config)))}loginPublic(t){return wt(u(u({},this.config),t)).then(this.setAuth(_(this.config)))}logoutPublic(){const t=this.getPublicToken();return console.log("token",t),Et(y(u({},this.config),{token:t})).then(this.unsetAuth(_(this.config)))}logoutEc(){const t=this.getEcToken();return console.log("token",t),At(y(u({},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 _t(this.config)}getDatamanager(t){return c(this,null,function*(){const e=yield this.getBestToken();return Pt(y(u({},this.config),{dmID:t,token:e}))})}dmList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return bt(y(u({},this.config),{options:t,token:e}))})}modelList(){return c(this,arguments,function*(t={}){const e=yield this.getBestToken();return Tt(y(u({},this.config),{options:t,token:e}))})}}const jt=n=>new E({env:n});exports.Sdk=E;exports.act=St;exports.apiURL=p;exports.assetList=H;exports.createAsset=Q;exports.createEntry=F;exports.deleteAsset=W;exports.deleteEntry=I;exports.dmList=Y;exports.editEntry=M;exports.entryList=v;exports.expect=d;exports.fetcher=g;exports.getAsset=G;exports.getDatamanager=X;exports.getEcAuthKey=J;exports.getEntry=U;exports.getPublicAuthKey=C;exports.getSchema=V;exports.loginEc=x;exports.loginPublic=D;exports.logoutEc=z;exports.logoutPublic=K;exports.modelList=Z;exports.publicApi=R;exports.query=w;exports.raw=et;exports.resourceList=tt;exports.sdk=jt;
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
- var K = Object.defineProperty, v = Object.defineProperties;
2
- var x = Object.getOwnPropertyDescriptors;
1
+ var K = Object.defineProperty, z = Object.defineProperties;
2
+ var C = Object.getOwnPropertyDescriptors;
3
3
  var O = Object.getOwnPropertySymbols;
4
- var z = Object.prototype.hasOwnProperty, J = Object.prototype.propertyIsEnumerable;
4
+ var J = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
5
  var j = (n, t, e) => t in n ? K(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, u = (n, t) => {
6
6
  for (var e in t || (t = {}))
7
- z.call(t, e) && j(n, e, t[e]);
7
+ J.call(t, e) && j(n, e, t[e]);
8
8
  if (O)
9
9
  for (var e of O(t))
10
- J.call(t, e) && j(n, e, t[e]);
10
+ N.call(t, e) && j(n, e, t[e]);
11
11
  return n;
12
- }, f = (n, t) => v(n, x(t));
12
+ }, y = (n, t) => z(n, C(t));
13
13
  var a = (n, t, e) => new Promise((s, r) => {
14
14
  var c = (i) => {
15
15
  try {
@@ -30,7 +30,7 @@ function g(s) {
30
30
  return a(this, arguments, function* (n, t = {}, e = {}) {
31
31
  var h;
32
32
  const { token: r, rawRes: c } = t;
33
- r && (e.headers = f(u({}, e.headers || {}), {
33
+ r && (e.headers = y(u({}, e.headers || {}), {
34
34
  Authorization: `Bearer ${r}`
35
35
  }));
36
36
  const o = yield fetch(n, e);
@@ -82,11 +82,11 @@ function d(n) {
82
82
  throw new Error(`expected ${t} to be set!`);
83
83
  });
84
84
  }
85
- const B = {
85
+ const q = {
86
86
  stage: "https://accounts.cachena.entrecode.de/",
87
87
  live: "https://accounts.entrecode.de/"
88
88
  };
89
- function N(n) {
89
+ function R(n) {
90
90
  return a(this, null, function* () {
91
91
  let { env: t, dmShortID: e, email: s, password: r } = n;
92
92
  d({ env: t, dmShortID: e, email: s, password: r });
@@ -104,11 +104,11 @@ function N(n) {
104
104
  );
105
105
  });
106
106
  }
107
- function C(n) {
107
+ function v(n) {
108
108
  return a(this, null, function* () {
109
109
  let { env: t, email: e, password: s } = n;
110
110
  d({ env: t, email: e, password: s });
111
- const r = `${B[t]}auth/login?clientID=rest`;
111
+ const r = `${q[t]}auth/login?clientID=rest`;
112
112
  return yield g(
113
113
  r,
114
114
  {},
@@ -122,7 +122,7 @@ function C(n) {
122
122
  );
123
123
  });
124
124
  }
125
- function R(n) {
125
+ function U(n) {
126
126
  return a(this, null, function* () {
127
127
  let { dmShortID: t, env: e, token: s } = n;
128
128
  d({ dmShortID: t, env: e, token: s });
@@ -143,7 +143,7 @@ function F(n) {
143
143
  return a(this, null, function* () {
144
144
  let { env: t, token: e } = n;
145
145
  d({ env: t, token: e });
146
- const s = `${B[t]}auth/logout?clientID=rest`;
146
+ const s = `${q[t]}auth/logout?clientID=rest`;
147
147
  return yield g(
148
148
  s,
149
149
  {
@@ -159,7 +159,7 @@ function F(n) {
159
159
  function M({ dmShortID: n }) {
160
160
  return d({ dmShortID: n }), n;
161
161
  }
162
- function U({ env: n }) {
162
+ function I({ env: n }) {
163
163
  return d({ env: n }), n;
164
164
  }
165
165
  let V = [
@@ -178,7 +178,7 @@ let V = [
178
178
  "_modelTitleField",
179
179
  "_modified"
180
180
  ];
181
- function q(n) {
181
+ function D(n) {
182
182
  let t = {};
183
183
  for (let e in n)
184
184
  V.includes(e) || (t[e] = n[e]);
@@ -195,21 +195,21 @@ function H(n) {
195
195
  return g(s, n);
196
196
  });
197
197
  }
198
- function I(n) {
198
+ function Q(n) {
199
199
  return a(this, null, function* () {
200
200
  let { env: t, dmShortID: e, model: s, options: r = {} } = n;
201
201
  d({ env: t, dmShortID: e, model: s }), r = u({ size: 50, page: 1, _list: !0 }, r);
202
202
  const c = w(r), o = p(`api/${e}/${s}?${c}`, t), { count: h, total: i, _embedded: l } = yield g(o, n);
203
- let y = l ? l[`${e}:${s}`] : [];
204
- return y = Array.isArray(y) ? y : [y], { count: h, total: i, items: y };
203
+ let f = l ? l[`${e}:${s}`] : [];
204
+ return f = Array.isArray(f) ? f : [f], { count: h, total: i, items: f };
205
205
  });
206
206
  }
207
- function Q({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
207
+ function W({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
208
208
  d({ env: n, dmShortID: t, model: e, entryID: s });
209
209
  const c = w({ _id: s }), o = p(`api/${t}/${e}?${c}`, n);
210
210
  return g(o, { dmShortID: t, token: r });
211
211
  }
212
- function W(c) {
212
+ function X(c) {
213
213
  return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, value: s, token: r }) {
214
214
  d({ env: n, dmShortID: t, model: e, value: s });
215
215
  const o = p(`api/${t}/${e}`, n);
@@ -226,31 +226,38 @@ function W(c) {
226
226
  );
227
227
  });
228
228
  }
229
- function X(o) {
229
+ function Y(h) {
230
230
  return a(this, arguments, function* ({
231
231
  env: n,
232
232
  dmShortID: t,
233
233
  model: e,
234
234
  entryID: s,
235
235
  value: r,
236
- token: c
236
+ token: c,
237
+ safePut: o = !1
237
238
  }) {
238
239
  d({ env: n, dmShortID: t, model: e, entryID: s, value: r });
239
- const h = p(`api/${t}/${e}?_id=${s}`, n);
240
- return r = G(r), r = q(r), yield g(
241
- h,
240
+ const i = {
241
+ "Content-Type": "application/json"
242
+ };
243
+ if (o) {
244
+ if (!("_modified" in r))
245
+ throw new Error("expected _modified to be set!");
246
+ i["If-Unmodified-Since"] = new Date(r._modified).toUTCString();
247
+ }
248
+ const l = p(`api/${t}/${e}?_id=${s}`, n);
249
+ return r = G(r), r = D(r), yield g(
250
+ l,
242
251
  { token: c },
243
252
  {
244
253
  method: "PUT",
245
- body: JSON.stringify(r),
246
- headers: {
247
- "Content-Type": "application/json"
248
- }
254
+ headers: i,
255
+ body: JSON.stringify(r)
249
256
  }
250
257
  );
251
258
  });
252
259
  }
253
- function Y(c) {
260
+ function Z(c) {
254
261
  return a(this, arguments, function* ({ env: n, dmShortID: t, model: e, entryID: s, token: r }) {
255
262
  d({ env: n, dmShortID: t, model: e, entryID: s });
256
263
  const o = p(`api/${t}/${e}?_id=${s}`, n);
@@ -266,21 +273,21 @@ function Y(c) {
266
273
  );
267
274
  });
268
275
  }
269
- function Z(s) {
276
+ function tt(s) {
270
277
  return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
271
- var l, y, m, P, L;
278
+ var l, f, m, P, L;
272
279
  d({ env: n, dmShortID: t, model: e });
273
280
  const r = p(`api/schema/${t}/${e}`, n), c = yield g(r), o = (l = c == null ? void 0 : c.allOf) == null ? void 0 : l[1];
274
281
  if (typeof o.properties != "object")
275
282
  throw new Error(
276
283
  `getSchema: ${r} returned unexpected format: ${JSON.stringify(c)}`
277
284
  );
278
- const { properties: h } = o, i = q(h);
285
+ const { properties: h } = o, i = D(h);
279
286
  for (let k in i) {
280
287
  let $ = i[k];
281
- if ($.required = o.required.includes(k), (y = i[k]) != null && y.oneOf && ((m = i[k]) == null || delete m.oneOf), (P = $.title) != null && P.includes("<") && ((L = $.title) != null && L.includes(">"))) {
282
- const E = $.title.split("<")[1].slice(0, -1), D = $.title.split("<")[0];
283
- $.type = D, E.includes(":") ? $.resource = E.split(":")[1] : $.resource = E;
288
+ if ($.required = o.required.includes(k), (f = i[k]) != null && f.oneOf && ((m = i[k]) == null || delete m.oneOf), (P = $.title) != null && P.includes("<") && ((L = $.title) != null && L.includes(">"))) {
289
+ const E = $.title.split("<")[1].slice(0, -1), x = $.title.split("<")[0];
290
+ $.type = x, E.includes(":") ? $.resource = E.split(":")[1] : $.resource = E;
284
291
  } else
285
292
  ["asset", "entry", "assets", "entries"].includes($.title) ? ($.type = $.title, $.resource = null) : $.type = $.title;
286
293
  delete i[k].title;
@@ -288,23 +295,23 @@ function Z(s) {
288
295
  return i;
289
296
  });
290
297
  }
291
- function tt(c) {
298
+ function et(c) {
292
299
  return a(this, arguments, function* ({ env: n, dmShortID: t, assetGroup: e, assetID: s, token: r }) {
293
300
  d({ env: n, dmShortID: t, assetGroup: e, assetID: s });
294
301
  const o = w({ assetID: s }), h = p(`a/${t}/${e}?${o}`, n);
295
302
  return (yield g(h, { dmShortID: t, token: r }))._embedded["ec:dm-asset"];
296
303
  });
297
304
  }
298
- function et(n) {
305
+ function nt(n) {
299
306
  return a(this, null, function* () {
300
307
  let { env: t, dmShortID: e, assetGroup: s, token: r, options: c = {} } = n;
301
308
  d({ env: t, dmShortID: e, assetGroup: s }), c = u({ size: 50, page: 1, _list: !0 }, c);
302
- const o = w(c), h = p(`a/${e}/${s}?${o}`, t), { count: i, total: l, _embedded: y } = yield g(h, { dmShortID: e, token: r });
303
- let m = y ? y["ec:dm-asset"] : [];
309
+ const o = w(c), h = p(`a/${e}/${s}?${o}`, t), { count: i, total: l, _embedded: f } = yield g(h, { dmShortID: e, token: r });
310
+ let m = f ? f["ec:dm-asset"] : [];
304
311
  return m = Array.isArray(m) ? m : [m], { count: i, total: l, items: m };
305
312
  });
306
313
  }
307
- function nt(h) {
314
+ function st(h) {
308
315
  return a(this, arguments, function* ({
309
316
  env: n,
310
317
  dmShortID: t,
@@ -328,7 +335,7 @@ function nt(h) {
328
335
  ))._embedded["ec:dm-asset"];
329
336
  });
330
337
  }
331
- function st(c) {
338
+ function rt(c) {
332
339
  return a(this, arguments, function* ({
333
340
  env: n,
334
341
  dmShortID: t,
@@ -347,7 +354,7 @@ function st(c) {
347
354
  );
348
355
  });
349
356
  }
350
- function rt(n) {
357
+ function ot(n) {
351
358
  return a(this, null, function* () {
352
359
  let { env: t, dmID: e, token: s } = n;
353
360
  d({ env: t, dmID: e });
@@ -355,7 +362,7 @@ function rt(n) {
355
362
  return g(r, { token: s });
356
363
  });
357
364
  }
358
- function ot(n) {
365
+ function it(n) {
359
366
  return a(this, null, function* () {
360
367
  let { env: t, options: e = {} } = n;
361
368
  d({ env: t }), e = u({ size: 25, page: 1, _list: !0 }, e);
@@ -364,7 +371,7 @@ function ot(n) {
364
371
  return i = Array.isArray(i) ? i : [i], { count: c, total: o, items: i };
365
372
  });
366
373
  }
367
- function it(n) {
374
+ function at(n) {
368
375
  return a(this, null, function* () {
369
376
  let { env: t, dmID: e, options: s = {} } = n;
370
377
  d({ env: t, dmID: e }), s = u({ size: 25, dataManagerID: e, page: 1, _list: !0 }, s);
@@ -373,56 +380,56 @@ function it(n) {
373
380
  return l = Array.isArray(l) ? l : [l], { count: o, total: h, items: l };
374
381
  });
375
382
  }
376
- function at(n) {
383
+ function ct(n) {
377
384
  return a(this, null, function* () {
378
385
  let { env: t, resource: e, options: s = {}, subdomain: r = "datamanager" } = n;
379
386
  d({ env: t, subdomain: r, resource: e }), s = u({ size: 25, page: 1, _list: !0 }, s);
380
387
  const c = w(s), o = p(`${e}?${c}`, t, r), { count: h, total: i, _embedded: l } = yield g(o, n);
381
- let y = l ? l[Object.keys(l)[0]] : [];
382
- return y = Array.isArray(y) ? y : [y], { count: h, total: i, items: y };
388
+ let f = l ? l[Object.keys(l)[0]] : [];
389
+ return f = Array.isArray(f) ? f : [f], { count: h, total: i, items: f };
383
390
  });
384
391
  }
385
- function ct(e) {
386
- return a(this, arguments, function* (n, t = {}) {
387
- let { env: s, route: r, options: c = {}, subdomain: o = "datamanager" } = n;
388
- d({ env: s, subdomain: o, route: r }), c = u({}, c);
389
- const h = w(c), i = p(`${r}?${h}`, s, o);
390
- return g(i, n, t);
392
+ function ut(n) {
393
+ return a(this, null, function* () {
394
+ let { env: t, route: e, options: s = {}, subdomain: r = "datamanager" } = n;
395
+ d({ env: t, subdomain: r, route: e }), s = u({}, s);
396
+ const c = w(s), o = p(`${e}?${c}`, t, r);
397
+ return g(o, n);
391
398
  });
392
399
  }
393
400
  const A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
394
401
  __proto__: null,
395
- assetList: et,
396
- createAsset: nt,
397
- createEntry: W,
398
- deleteAsset: st,
399
- deleteEntry: Y,
400
- dmList: ot,
401
- editEntry: X,
402
- entryList: I,
403
- getAsset: tt,
404
- getDatamanager: rt,
405
- getEcAuthKey: U,
406
- getEntry: Q,
402
+ assetList: nt,
403
+ createAsset: st,
404
+ createEntry: X,
405
+ deleteAsset: rt,
406
+ deleteEntry: Z,
407
+ dmList: it,
408
+ editEntry: Y,
409
+ entryList: Q,
410
+ getAsset: et,
411
+ getDatamanager: ot,
412
+ getEcAuthKey: I,
413
+ getEntry: W,
407
414
  getPublicAuthKey: M,
408
- getSchema: Z,
409
- loginEc: C,
410
- loginPublic: N,
415
+ getSchema: tt,
416
+ loginEc: v,
417
+ loginPublic: R,
411
418
  logoutEc: F,
412
- logoutPublic: R,
413
- modelList: it,
419
+ logoutPublic: U,
420
+ modelList: at,
414
421
  publicApi: H,
415
- raw: ct,
416
- resourceList: at
422
+ raw: ut,
423
+ resourceList: ct
417
424
  }, Symbol.toStringTag, { value: "Module" })), {
418
- entryList: ut,
419
- getEntry: lt,
425
+ entryList: lt,
426
+ getEntry: dt,
420
427
  getAsset: ht,
421
- assetList: dt,
422
- createAsset: gt,
428
+ assetList: gt,
429
+ createAsset: ft,
423
430
  deleteAsset: yt,
424
- createEntry: ft,
425
- editEntry: pt,
431
+ createEntry: pt,
432
+ editEntry: B,
426
433
  deleteEntry: $t,
427
434
  getSchema: mt,
428
435
  loginPublic: wt,
@@ -471,7 +478,7 @@ class _ {
471
478
  entries() {
472
479
  return a(this, arguments, function* (t = {}) {
473
480
  const e = yield this.getBestToken();
474
- return ut(f(u({}, this.config), { options: t, token: e }));
481
+ return lt(y(u({}, this.config), { options: t, token: e }));
475
482
  });
476
483
  }
477
484
  entryList(t) {
@@ -484,14 +491,34 @@ class _ {
484
491
  * If the model is not public, you also need to provide a `token`.
485
492
  *
486
493
  * @param {string} entryID
487
- * @returns {Promise<EntryResource & Record<string, any>>}
494
+ * @returns {Promise<EntryResource>}
488
495
  * @example
489
496
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
490
497
  */
491
498
  getEntry(t) {
492
499
  return a(this, null, function* () {
493
500
  const e = yield this.getBestToken();
494
- return lt(f(u({}, this.config), { entryID: t, token: e }));
501
+ return dt(y(u({}, this.config), { entryID: t, token: e }));
502
+ });
503
+ }
504
+ /**
505
+ * Edits an entry with safe put. Expects `dmShortID` / `model` to be set.
506
+ * Expects a `_modified` field in the value. Will only update if the entry has not been changed since.
507
+ * If model PUT is not public, you also need to provide a `token`.
508
+ *
509
+ * @param {string} entryID id of entry to edit
510
+ * @param {object} value values to set. undefined fields are ignored
511
+ * @returns {Promise<EntryResource>}
512
+ * @example
513
+ * const entry = await sdk("stage")
514
+ * .dm("83cc6374")
515
+ * .model("muffin")
516
+ * .editEntrySafe("1gOtzWvrdq", { name: "test", _modified: "2020-01-01T00:00:00.000Z"})
517
+ */
518
+ editEntrySafe(t, e) {
519
+ return a(this, null, function* () {
520
+ const s = yield this.getBestToken();
521
+ return B(y(u({}, this.config), { entryID: t, token: s, value: e, safePut: !0 }));
495
522
  });
496
523
  }
497
524
  /**
@@ -523,7 +550,7 @@ class _ {
523
550
  assets(t) {
524
551
  return a(this, null, function* () {
525
552
  const e = yield this.getBestToken();
526
- return dt(f(u({}, this.config), { options: t, token: e }));
553
+ return gt(y(u({}, this.config), { options: t, token: e }));
527
554
  });
528
555
  }
529
556
  assetList(t) {
@@ -555,7 +582,7 @@ class _ {
555
582
  createAsset() {
556
583
  return a(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
557
584
  const r = yield this.getBestToken();
558
- return gt(f(u({}, this.config), { file: t, name: e, options: s, token: r }));
585
+ return ft(y(u({}, this.config), { file: t, name: e, options: s, token: r }));
559
586
  });
560
587
  }
561
588
  /**
@@ -570,7 +597,7 @@ class _ {
570
597
  deleteAsset(t) {
571
598
  return a(this, null, function* () {
572
599
  const e = yield this.getBestToken();
573
- return yt(f(u({}, this.config), { token: e, assetID: t }));
600
+ return yt(y(u({}, this.config), { token: e, assetID: t }));
574
601
  });
575
602
  }
576
603
  /**
@@ -585,7 +612,7 @@ class _ {
585
612
  getAsset(t) {
586
613
  return a(this, null, function* () {
587
614
  const e = yield this.getBestToken();
588
- return ht(f(u({}, this.config), { assetID: t, token: e }));
615
+ return ht(y(u({}, this.config), { assetID: t, token: e }));
589
616
  });
590
617
  }
591
618
  /**
@@ -600,7 +627,7 @@ class _ {
600
627
  createEntry(t) {
601
628
  return a(this, null, function* () {
602
629
  const e = yield this.getBestToken();
603
- return ft(f(u({}, this.config), { token: e, value: t }));
630
+ return pt(y(u({}, this.config), { token: e, value: t }));
604
631
  });
605
632
  }
606
633
  /**
@@ -616,7 +643,7 @@ class _ {
616
643
  editEntry(t, e) {
617
644
  return a(this, null, function* () {
618
645
  const s = yield this.getBestToken();
619
- return pt(f(u({}, this.config), { entryID: t, token: s, value: e }));
646
+ return B(y(u({}, this.config), { entryID: t, token: s, value: e }));
620
647
  });
621
648
  }
622
649
  /**
@@ -631,7 +658,7 @@ class _ {
631
658
  deleteEntry(t) {
632
659
  return a(this, null, function* () {
633
660
  const e = yield this.getBestToken();
634
- return $t(f(u({}, this.config), { token: e, entryID: t }));
661
+ return $t(y(u({}, this.config), { token: e, entryID: t }));
635
662
  });
636
663
  }
637
664
  /**
@@ -646,7 +673,7 @@ class _ {
646
673
  resourceList(t) {
647
674
  return a(this, null, function* () {
648
675
  const e = yield this.getBestToken();
649
- return Lt(f(u({}, this.config), { options: t, token: e }));
676
+ return Lt(y(u({}, this.config), { options: t, token: e }));
650
677
  });
651
678
  }
652
679
  /**
@@ -655,15 +682,14 @@ class _ {
655
682
  * Use this when no other fdk method can give you your request.
656
683
  *
657
684
  * @param {object=} options options for list request.
658
- * @param {object=} fetchOptions (optional) options passed to fetch.
659
685
  * @returns {Promise<any>}
660
686
  * @example
661
687
  * const res = await sdk("stage").route("stats").raw()
662
688
  */
663
- raw(t, e) {
689
+ raw(t) {
664
690
  return a(this, null, function* () {
665
- const s = yield this.getBestToken();
666
- return Ot(f(u({}, this.config), { options: t, token: s }), e);
691
+ const e = yield this.getBestToken();
692
+ return Ot(y(u({}, this.config), { options: t, token: e }));
667
693
  });
668
694
  }
669
695
  // TODO: rename authAdapter -> storageAdapter
@@ -704,13 +730,13 @@ class _ {
704
730
  }
705
731
  logoutPublic() {
706
732
  const t = this.getPublicToken();
707
- return console.log("token", t), Et(f(u({}, this.config), { token: t })).then(
733
+ return console.log("token", t), Et(y(u({}, this.config), { token: t })).then(
708
734
  this.unsetAuth(T(this.config))
709
735
  );
710
736
  }
711
737
  logoutEc() {
712
738
  const t = this.getEcToken();
713
- return console.log("token", t), At(f(u({}, this.config), { token: t })).then(
739
+ return console.log("token", t), At(y(u({}, this.config), { token: t })).then(
714
740
  this.unsetAuth(b(this.config))
715
741
  );
716
742
  }
@@ -830,7 +856,7 @@ class _ {
830
856
  getDatamanager(t) {
831
857
  return a(this, null, function* () {
832
858
  const e = yield this.getBestToken();
833
- return Pt(f(u({}, this.config), { dmID: t, token: e }));
859
+ return Pt(y(u({}, this.config), { dmID: t, token: e }));
834
860
  });
835
861
  }
836
862
  /**
@@ -844,7 +870,7 @@ class _ {
844
870
  dmList() {
845
871
  return a(this, arguments, function* (t = {}) {
846
872
  const e = yield this.getBestToken();
847
- return bt(f(u({}, this.config), { options: t, token: e }));
873
+ return bt(y(u({}, this.config), { options: t, token: e }));
848
874
  });
849
875
  }
850
876
  /**
@@ -858,7 +884,7 @@ class _ {
858
884
  modelList() {
859
885
  return a(this, arguments, function* (t = {}) {
860
886
  const e = yield this.getBestToken();
861
- return Tt(f(u({}, this.config), { options: t, token: e }));
887
+ return Tt(y(u({}, this.config), { options: t, token: e }));
862
888
  });
863
889
  }
864
890
  }
@@ -867,30 +893,30 @@ export {
867
893
  _ as Sdk,
868
894
  St as act,
869
895
  p as apiURL,
870
- et as assetList,
871
- nt as createAsset,
872
- W as createEntry,
873
- st as deleteAsset,
874
- Y as deleteEntry,
875
- ot as dmList,
876
- X as editEntry,
877
- I as entryList,
896
+ nt as assetList,
897
+ st as createAsset,
898
+ X as createEntry,
899
+ rt as deleteAsset,
900
+ Z as deleteEntry,
901
+ it as dmList,
902
+ Y as editEntry,
903
+ Q as entryList,
878
904
  d as expect,
879
905
  g as fetcher,
880
- tt as getAsset,
881
- rt as getDatamanager,
882
- U as getEcAuthKey,
883
- Q as getEntry,
906
+ et as getAsset,
907
+ ot as getDatamanager,
908
+ I as getEcAuthKey,
909
+ W as getEntry,
884
910
  M as getPublicAuthKey,
885
- Z as getSchema,
886
- C as loginEc,
887
- N as loginPublic,
911
+ tt as getSchema,
912
+ v as loginEc,
913
+ R as loginPublic,
888
914
  F as logoutEc,
889
- R as logoutPublic,
890
- it as modelList,
915
+ U as logoutPublic,
916
+ at as modelList,
891
917
  H as publicApi,
892
918
  w as query,
893
- ct as raw,
894
- at as resourceList,
919
+ ut as raw,
920
+ ct as resourceList,
895
921
  Bt as sdk
896
922
  };
@@ -14,5 +14,5 @@ export function resourceList(config: any): Promise<{
14
14
  total: any;
15
15
  items: any;
16
16
  }>;
17
- export function raw(config: any, fetchOptions?: {}): Promise<any>;
17
+ export function raw(config: any): Promise<any>;
18
18
  //# sourceMappingURL=admin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.mts","sourceRoot":"","sources":["../../src/lib/admin.mjs"],"names":[],"mappings":"AAEA,0DAMC;AAED;;;;GAYC;AAED;;;;GAWC;AAED;;;;GAWC;AAED,kEAQC"}
1
+ {"version":3,"file":"admin.d.mts","sourceRoot":"","sources":["../../src/lib/admin.mjs"],"names":[],"mappings":"AAEA,0DAMC;AAED;;;;GAYC;AAED;;;;GAWC;AAED;;;;GAWC;AAED,+CAQC"}
@@ -27,11 +27,26 @@ export class Sdk {
27
27
  * If the model is not public, you also need to provide a `token`.
28
28
  *
29
29
  * @param {string} entryID
30
- * @returns {Promise<EntryResource & Record<string, any>>}
30
+ * @returns {Promise<EntryResource>}
31
31
  * @example
32
32
  * const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
33
33
  */
34
- getEntry(entryID: string): Promise<EntryResource & Record<string, any>>;
34
+ getEntry(entryID: string): Promise<EntryResource>;
35
+ /**
36
+ * Edits an entry with safe put. Expects `dmShortID` / `model` to be set.
37
+ * Expects a `_modified` field in the value. Will only update if the entry has not been changed since.
38
+ * If model PUT is not public, you also need to provide a `token`.
39
+ *
40
+ * @param {string} entryID id of entry to edit
41
+ * @param {object} value values to set. undefined fields are ignored
42
+ * @returns {Promise<EntryResource>}
43
+ * @example
44
+ * const entry = await sdk("stage")
45
+ * .dm("83cc6374")
46
+ * .model("muffin")
47
+ * .editEntrySafe("1gOtzWvrdq", { name: "test", _modified: "2020-01-01T00:00:00.000Z"})
48
+ */
49
+ editEntrySafe(entryID: string, value: object): Promise<EntryResource>;
35
50
  /**
36
51
  * Loads the schema of a model. Expects `dmShortID` / `model` to be set.
37
52
  *
@@ -149,12 +164,11 @@ export class Sdk {
149
164
  * Use this when no other fdk method can give you your request.
150
165
  *
151
166
  * @param {object=} options options for list request.
152
- * @param {object=} fetchOptions (optional) options passed to fetch.
153
167
  * @returns {Promise<any>}
154
168
  * @example
155
169
  * const res = await sdk("stage").route("stats").raw()
156
170
  */
157
- raw(options?: object | undefined, fetchOptions?: object | undefined): Promise<any>;
171
+ raw(options?: object | undefined): Promise<any>;
158
172
  authAdapter(authAdapter: any): Sdk;
159
173
  setAuth(key: any): (auth: any) => any;
160
174
  unsetAuth(key: any): (auth: any) => any;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"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"}
@@ -18,13 +18,14 @@ export function createEntry({ env, dmShortID, model, value, token }: {
18
18
  value: any;
19
19
  token: any;
20
20
  }): Promise<any>;
21
- export function editEntry({ env, dmShortID, model, entryID, value, token, }: {
21
+ export function editEntry({ env, dmShortID, model, entryID, value, token, safePut, }: {
22
22
  env: any;
23
23
  dmShortID: any;
24
24
  model: any;
25
25
  entryID: any;
26
26
  value: any;
27
27
  token: any;
28
+ safePut?: boolean;
28
29
  }): Promise<any>;
29
30
  export function deleteEntry({ env, dmShortID, model, entryID, token }: {
30
31
  env: any;
@@ -1 +1 @@
1
- {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAiCA,qDAMC;AAED;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;iBA0BC;AAED;;;;;;kBAcC;AAED;;;;gBAsCC"}
1
+ {"version":3,"file":"entries.d.mts","sourceRoot":"","sources":["../../src/lib/entries.mjs"],"names":[],"mappings":"AAiCA,qDAMC;AAED;;;;GAYC;AAED;;;;;;iBAKC;AAED;;;;;;iBAeC;AAED;;;;;;;;iBAkCC;AAED;;;;;;kBAcC;AAED;;;;gBAsCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ec.fdk",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "ec frontend sdk",
5
5
  "main": "dist/index.cjs",
6
6
  "directories": {