ec.fdk 0.3.0 → 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 +2 -0
- package/README.md +157 -4
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +196 -169
- package/dist/lib/api.d.mts +17 -2
- package/dist/lib/api.d.mts.map +1 -1
- package/dist/lib/entries.d.mts +2 -1
- package/dist/lib/entries.d.mts.map +1 -1
- package/package.json +1 -1
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.<EntryList></code>](#EntryList)
|
|
62
64
|
* [.getEntry(entryID)](#module_api.Sdk+getEntry) ⇒ [<code>Promise.<EntryResource></code>](#EntryResource)
|
|
65
|
+
* [.editEntrySafe(entryID, value)](#module_api.Sdk+editEntrySafe) ⇒ [<code>Promise.<EntryResource></code>](#EntryResource)
|
|
66
|
+
* [.getSchema(entryID)](#module_api.Sdk+getSchema) ⇒ [<code>Promise.<EntrySchema></code>](#EntrySchema)
|
|
63
67
|
* [.assets([options])](#module_api.Sdk+assets) ⇒ [<code>Promise.<AssetList></code>](#AssetList)
|
|
64
68
|
* [.createAsset(options)](#module_api.Sdk+createAsset) ⇒ [<code>Promise.<AssetResource></code>](#AssetResource)
|
|
65
69
|
* [.deleteAsset(assetID)](#module_api.Sdk+deleteAsset) ⇒ <code>Promise.<void></code>
|
|
@@ -67,13 +71,22 @@ Now what follows is the autogenerated doc from source:
|
|
|
67
71
|
* [.createEntry(value)](#module_api.Sdk+createEntry) ⇒ [<code>Promise.<EntryResource></code>](#EntryResource)
|
|
68
72
|
* [.editEntry(entryID, value)](#module_api.Sdk+editEntry) ⇒ [<code>Promise.<EntryResource></code>](#EntryResource)
|
|
69
73
|
* [.deleteEntry(entryID)](#module_api.Sdk+deleteEntry) ⇒ <code>void</code>
|
|
74
|
+
* [.resourceList([options])](#module_api.Sdk+resourceList) ⇒ [<code>Promise.<ResourceList></code>](#ResourceList)
|
|
75
|
+
* [.raw([options])](#module_api.Sdk+raw) ⇒ <code>Promise.<any></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.<DatamanagerList></code>](#DatamanagerList)
|
|
89
|
+
* [.modelList([options])](#module_api.Sdk+modelList) ⇒ [<code>Promise.<ModelList></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.<EntryResource></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.<EntrySchema></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.<AssetList></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.<ResourceList></code>](#ResourceList)
|
|
301
|
+
<p>Fetches resource list. Expects <code>resource</code> to be set. <code>subdomain</code> defaults to "datamanager".
|
|
302
|
+
Fetches <code>https://<subdomain>.entrecode.de/<resource>?_list=true&size=<options.size ?? 25></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.<any></code>
|
|
317
|
+
<p>Fetches raw route. Expects <code>route</code> to be set. <code>subdomain</code> defaults to "datamanager".
|
|
318
|
+
Fetches <code>https://<subdomain>.entrecode.de/<route>?<options></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.<DatamanagerList></code>](#DatamanagerList)
|
|
@@ -331,11 +475,20 @@ await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
|
|
|
331
475
|
|
|
332
476
|
**Example**
|
|
333
477
|
```js
|
|
334
|
-
|
|
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.<ModelList></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
|
-
|
|
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
|
|
2
|
-
${
|
|
3
|
-
${c.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 i(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 i(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 i(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 i(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 i(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 i(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:c,_embedded:l}=yield g(o,n);let f=l?l[`${e}:${s}`]:[];return f=Array.isArray(f)?f:[f],{count:h,total:c,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 i(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 i(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 i(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 i(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,c=J(h);for(let k in c){let $=c[k];if($.required=o.required.includes(k),(f=c[k])!=null&&f.oneOf&&((m=c[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 c[k].title}return c})}function G(a){return i(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 i(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:c,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:c,total:l,items:m}})}function I(h){return i(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 c=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(c,{token:s},{method:"POST",body:l}))._embedded["ec:dm-asset"]})}function Q(a){return i(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 i(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 i(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 c=h?h["ec:datamanager"]:[];return c=Array.isArray(c)?c:[c],{count:a,total:o,items:c}})}function Y(n){return i(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:c}=yield g(a,n);let l=c?c["ec:model"]:[];return l=Array.isArray(l)?l:[l],{count:o,total:h,items:l}})}function Z(n){return i(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:c,_embedded:l}=yield g(o,n);let f=l?l[Object.keys(l)[0]]:[];return f=Array.isArray(f)?f:[f],{count:h,total:c,items:f}})}function tt(n){return i(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=y(`${e}?${a}`,t,r);return g(o,n)})}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 i(this,arguments,function*(t={}){const e=yield this.getBestToken();return ut(p(u({},this.config),{options:t,token:e}))})}entryList(t){return i(this,null,function*(){return this.entries(t)})}getEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return lt(p(u({},this.config),{entryID:t,token:e}))})}getSchema(){return i(this,null,function*(){return mt(this.config)})}assets(t){return i(this,null,function*(){const e=yield this.getBestToken();return dt(p(u({},this.config),{options:t,token:e}))})}assetList(t){return i(this,null,function*(){return this.assets(t)})}createAsset(){return i(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 i(this,null,function*(){const e=yield this.getBestToken();return yt(p(u({},this.config),{token:e,assetID:t}))})}getAsset(t){return i(this,null,function*(){const e=yield this.getBestToken();return ht(p(u({},this.config),{assetID:t,token:e}))})}createEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return ft(p(u({},this.config),{token:e,value:t}))})}editEntry(t,e){return i(this,null,function*(){const s=yield this.getBestToken();return pt(p(u({},this.config),{entryID:t,token:s,value:e}))})}deleteEntry(t){return i(this,null,function*(){const e=yield this.getBestToken();return $t(p(u({},this.config),{token:e,entryID:t}))})}resourceList(t){return i(this,null,function*(){const e=yield this.getBestToken();return Lt(p(u({},this.config),{options:t,token:e}))})}raw(t){return i(this,null,function*(){const e=yield this.getBestToken();return Ot(p(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(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 i(this,null,function*(){const e=yield this.getBestToken();return _t(p(u({},this.config),{dmID:t,token:e}))})}dmList(){return i(this,arguments,function*(t={}){const e=yield this.getBestToken();return bt(p(u({},this.config),{options:t,token:e}))})}modelList(){return i(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;
|
|
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
|
+
${i.detail}
|
|
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,44 +1,44 @@
|
|
|
1
|
-
var K = Object.defineProperty,
|
|
2
|
-
var
|
|
1
|
+
var K = Object.defineProperty, z = Object.defineProperties;
|
|
2
|
+
var C = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var O = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
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
|
-
|
|
7
|
+
J.call(t, e) && j(n, e, t[e]);
|
|
8
8
|
if (O)
|
|
9
9
|
for (var e of O(t))
|
|
10
|
-
|
|
10
|
+
N.call(t, e) && j(n, e, t[e]);
|
|
11
11
|
return n;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var c = (
|
|
12
|
+
}, y = (n, t) => z(n, C(t));
|
|
13
|
+
var a = (n, t, e) => new Promise((s, r) => {
|
|
14
|
+
var c = (i) => {
|
|
15
15
|
try {
|
|
16
|
-
h(e.next(
|
|
16
|
+
h(e.next(i));
|
|
17
17
|
} catch (l) {
|
|
18
18
|
r(l);
|
|
19
19
|
}
|
|
20
|
-
}, o = (
|
|
20
|
+
}, o = (i) => {
|
|
21
21
|
try {
|
|
22
|
-
h(e.throw(
|
|
22
|
+
h(e.throw(i));
|
|
23
23
|
} catch (l) {
|
|
24
24
|
r(l);
|
|
25
25
|
}
|
|
26
|
-
}, h = (
|
|
26
|
+
}, h = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(c, o);
|
|
27
27
|
h((e = e.apply(n, t)).next());
|
|
28
28
|
});
|
|
29
29
|
function g(s) {
|
|
30
|
-
return
|
|
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 =
|
|
33
|
+
r && (e.headers = y(u({}, e.headers || {}), {
|
|
34
34
|
Authorization: `Bearer ${r}`
|
|
35
35
|
}));
|
|
36
36
|
const o = yield fetch(n, e);
|
|
37
37
|
if (!o.ok) {
|
|
38
38
|
if ((h = o.headers.get("content-type")) != null && h.includes("application/json")) {
|
|
39
|
-
const
|
|
40
|
-
${
|
|
41
|
-
${
|
|
39
|
+
const i = yield o.json(), l = `${i.title}
|
|
40
|
+
${i.detail}
|
|
41
|
+
${i.verbose}`;
|
|
42
42
|
throw new Error(l);
|
|
43
43
|
}
|
|
44
44
|
throw new Error(`unexpected fetch error: ${o.statusText}`);
|
|
@@ -82,12 +82,12 @@ function d(n) {
|
|
|
82
82
|
throw new Error(`expected ${t} to be set!`);
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
const
|
|
85
|
+
const q = {
|
|
86
86
|
stage: "https://accounts.cachena.entrecode.de/",
|
|
87
87
|
live: "https://accounts.entrecode.de/"
|
|
88
88
|
};
|
|
89
|
-
function
|
|
90
|
-
return
|
|
89
|
+
function R(n) {
|
|
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 });
|
|
93
93
|
const c = p(`api/${e}/_auth/login?clientID=rest`, t);
|
|
@@ -104,11 +104,11 @@ function N(n) {
|
|
|
104
104
|
);
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
return
|
|
107
|
+
function v(n) {
|
|
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 = `${
|
|
111
|
+
const r = `${q[t]}auth/login?clientID=rest`;
|
|
112
112
|
return yield g(
|
|
113
113
|
r,
|
|
114
114
|
{},
|
|
@@ -122,8 +122,8 @@ function C(n) {
|
|
|
122
122
|
);
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
return
|
|
125
|
+
function U(n) {
|
|
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 });
|
|
129
129
|
const r = p(
|
|
@@ -140,10 +140,10 @@ function R(n) {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
function F(n) {
|
|
143
|
-
return
|
|
143
|
+
return a(this, null, function* () {
|
|
144
144
|
let { env: t, token: e } = n;
|
|
145
145
|
d({ env: t, token: e });
|
|
146
|
-
const s = `${
|
|
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
|
|
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
|
|
181
|
+
function D(n) {
|
|
182
182
|
let t = {};
|
|
183
183
|
for (let e in n)
|
|
184
184
|
V.includes(e) || (t[e] = n[e]);
|
|
@@ -188,29 +188,29 @@ function G(n) {
|
|
|
188
188
|
return JSON.parse(JSON.stringify(n));
|
|
189
189
|
}
|
|
190
190
|
function H(n) {
|
|
191
|
-
return
|
|
191
|
+
return a(this, null, function* () {
|
|
192
192
|
let { env: t, dmShortID: e } = n;
|
|
193
193
|
d({ env: t, dmShortID: e });
|
|
194
194
|
const s = p(`api/${e}`, t);
|
|
195
195
|
return g(s, n);
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return
|
|
198
|
+
function Q(n) {
|
|
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
|
-
const c = w(r), o = p(`api/${e}/${s}?${c}`, t), { count: h, total:
|
|
203
|
-
let
|
|
204
|
-
return
|
|
202
|
+
const c = w(r), o = p(`api/${e}/${s}?${c}`, t), { count: h, total: i, _embedded: l } = yield g(o, n);
|
|
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
|
|
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
|
|
213
|
-
return
|
|
212
|
+
function X(c) {
|
|
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);
|
|
216
216
|
return yield g(
|
|
@@ -226,32 +226,39 @@ function W(c) {
|
|
|
226
226
|
);
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
-
function
|
|
230
|
-
return
|
|
229
|
+
function Y(h) {
|
|
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
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
"Content-Type": "application/json"
|
|
248
|
-
}
|
|
254
|
+
headers: i,
|
|
255
|
+
body: JSON.stringify(r)
|
|
249
256
|
}
|
|
250
257
|
);
|
|
251
258
|
});
|
|
252
259
|
}
|
|
253
|
-
function
|
|
254
|
-
return
|
|
260
|
+
function Z(c) {
|
|
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);
|
|
257
264
|
yield g(
|
|
@@ -266,46 +273,46 @@ function Y(c) {
|
|
|
266
273
|
);
|
|
267
274
|
});
|
|
268
275
|
}
|
|
269
|
-
function
|
|
270
|
-
return
|
|
271
|
-
var l,
|
|
276
|
+
function tt(s) {
|
|
277
|
+
return a(this, arguments, function* ({ env: n, dmShortID: t, model: e }) {
|
|
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,
|
|
279
|
-
for (let k in
|
|
280
|
-
let $ =
|
|
281
|
-
if ($.required = o.required.includes(k), (
|
|
282
|
-
const E = $.title.split("<")[1].slice(0, -1),
|
|
283
|
-
$.type =
|
|
285
|
+
const { properties: h } = o, i = D(h);
|
|
286
|
+
for (let k in i) {
|
|
287
|
+
let $ = i[k];
|
|
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
|
-
delete
|
|
293
|
+
delete i[k].title;
|
|
287
294
|
}
|
|
288
|
-
return
|
|
295
|
+
return i;
|
|
289
296
|
});
|
|
290
297
|
}
|
|
291
|
-
function
|
|
292
|
-
return
|
|
298
|
+
function et(c) {
|
|
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
|
|
299
|
-
return
|
|
305
|
+
function nt(n) {
|
|
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:
|
|
303
|
-
let m =
|
|
304
|
-
return m = Array.isArray(m) ? m : [m], { count:
|
|
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"] : [];
|
|
311
|
+
return m = Array.isArray(m) ? m : [m], { count: i, total: l, items: m };
|
|
305
312
|
});
|
|
306
313
|
}
|
|
307
|
-
function
|
|
308
|
-
return
|
|
314
|
+
function st(h) {
|
|
315
|
+
return a(this, arguments, function* ({
|
|
309
316
|
env: n,
|
|
310
317
|
dmShortID: t,
|
|
311
318
|
assetGroup: e,
|
|
@@ -315,11 +322,11 @@ function nt(h) {
|
|
|
315
322
|
options: o
|
|
316
323
|
}) {
|
|
317
324
|
d({ env: n, dmShortID: t, assetGroup: e, file: r });
|
|
318
|
-
const
|
|
325
|
+
const i = p(`a/${t}/${e}`, n), l = new FormData();
|
|
319
326
|
return l.append("file", r, c), o && Object.keys(o).forEach((m) => {
|
|
320
327
|
l.append(m, o[m]);
|
|
321
328
|
}), (yield g(
|
|
322
|
-
|
|
329
|
+
i,
|
|
323
330
|
{ token: s },
|
|
324
331
|
{
|
|
325
332
|
method: "POST",
|
|
@@ -328,8 +335,8 @@ function nt(h) {
|
|
|
328
335
|
))._embedded["ec:dm-asset"];
|
|
329
336
|
});
|
|
330
337
|
}
|
|
331
|
-
function
|
|
332
|
-
return
|
|
338
|
+
function rt(c) {
|
|
339
|
+
return a(this, arguments, function* ({
|
|
333
340
|
env: n,
|
|
334
341
|
dmShortID: t,
|
|
335
342
|
assetGroup: e,
|
|
@@ -347,43 +354,43 @@ function st(c) {
|
|
|
347
354
|
);
|
|
348
355
|
});
|
|
349
356
|
}
|
|
350
|
-
function
|
|
351
|
-
return
|
|
357
|
+
function ot(n) {
|
|
358
|
+
return a(this, null, function* () {
|
|
352
359
|
let { env: t, dmID: e, token: s } = n;
|
|
353
360
|
d({ env: t, dmID: e });
|
|
354
361
|
const r = p(`?dataManagerID=${e}`, t);
|
|
355
362
|
return g(r, { token: s });
|
|
356
363
|
});
|
|
357
364
|
}
|
|
358
|
-
function
|
|
359
|
-
return
|
|
365
|
+
function it(n) {
|
|
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);
|
|
362
369
|
const s = w(e), r = p(`?${s}`, t), { count: c, total: o, _embedded: h } = yield g(r, n);
|
|
363
|
-
let
|
|
364
|
-
return
|
|
370
|
+
let i = h ? h["ec:datamanager"] : [];
|
|
371
|
+
return i = Array.isArray(i) ? i : [i], { count: c, total: o, items: i };
|
|
365
372
|
});
|
|
366
373
|
}
|
|
367
|
-
function
|
|
368
|
-
return
|
|
374
|
+
function at(n) {
|
|
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);
|
|
371
|
-
const r = w(s), c = p(`model?${r}`, t), { count: o, total: h, _embedded:
|
|
372
|
-
let l =
|
|
378
|
+
const r = w(s), c = p(`model?${r}`, t), { count: o, total: h, _embedded: i } = yield g(c, n);
|
|
379
|
+
let l = i ? i["ec:model"] : [];
|
|
373
380
|
return l = Array.isArray(l) ? l : [l], { count: o, total: h, items: l };
|
|
374
381
|
});
|
|
375
382
|
}
|
|
376
|
-
function
|
|
377
|
-
return
|
|
383
|
+
function ct(n) {
|
|
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
|
-
const c = w(s), o = p(`${e}?${c}`, t, r), { count: h, total:
|
|
381
|
-
let
|
|
382
|
-
return
|
|
387
|
+
const c = w(s), o = p(`${e}?${c}`, t, r), { count: h, total: i, _embedded: l } = yield g(o, n);
|
|
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
|
|
386
|
-
return
|
|
392
|
+
function ut(n) {
|
|
393
|
+
return a(this, null, function* () {
|
|
387
394
|
let { env: t, route: e, options: s = {}, subdomain: r = "datamanager" } = n;
|
|
388
395
|
d({ env: t, subdomain: r, route: e }), s = u({}, s);
|
|
389
396
|
const c = w(s), o = p(`${e}?${c}`, t, r);
|
|
@@ -392,37 +399,37 @@ function ct(n) {
|
|
|
392
399
|
}
|
|
393
400
|
const A = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
394
401
|
__proto__: null,
|
|
395
|
-
assetList:
|
|
396
|
-
createAsset:
|
|
397
|
-
createEntry:
|
|
398
|
-
deleteAsset:
|
|
399
|
-
deleteEntry:
|
|
400
|
-
dmList:
|
|
401
|
-
editEntry:
|
|
402
|
-
entryList:
|
|
403
|
-
getAsset:
|
|
404
|
-
getDatamanager:
|
|
405
|
-
getEcAuthKey:
|
|
406
|
-
getEntry:
|
|
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:
|
|
409
|
-
loginEc:
|
|
410
|
-
loginPublic:
|
|
415
|
+
getSchema: tt,
|
|
416
|
+
loginEc: v,
|
|
417
|
+
loginPublic: R,
|
|
411
418
|
logoutEc: F,
|
|
412
|
-
logoutPublic:
|
|
413
|
-
modelList:
|
|
419
|
+
logoutPublic: U,
|
|
420
|
+
modelList: at,
|
|
414
421
|
publicApi: H,
|
|
415
|
-
raw:
|
|
416
|
-
resourceList:
|
|
422
|
+
raw: ut,
|
|
423
|
+
resourceList: ct
|
|
417
424
|
}, Symbol.toStringTag, { value: "Module" })), {
|
|
418
|
-
entryList:
|
|
419
|
-
getEntry:
|
|
425
|
+
entryList: lt,
|
|
426
|
+
getEntry: dt,
|
|
420
427
|
getAsset: ht,
|
|
421
|
-
assetList:
|
|
422
|
-
createAsset:
|
|
428
|
+
assetList: gt,
|
|
429
|
+
createAsset: ft,
|
|
423
430
|
deleteAsset: yt,
|
|
424
|
-
createEntry:
|
|
425
|
-
editEntry:
|
|
431
|
+
createEntry: pt,
|
|
432
|
+
editEntry: B,
|
|
426
433
|
deleteEntry: $t,
|
|
427
434
|
getSchema: mt,
|
|
428
435
|
loginPublic: wt,
|
|
@@ -469,13 +476,13 @@ class _ {
|
|
|
469
476
|
* const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
|
|
470
477
|
*/
|
|
471
478
|
entries() {
|
|
472
|
-
return
|
|
479
|
+
return a(this, arguments, function* (t = {}) {
|
|
473
480
|
const e = yield this.getBestToken();
|
|
474
|
-
return
|
|
481
|
+
return lt(y(u({}, this.config), { options: t, token: e }));
|
|
475
482
|
});
|
|
476
483
|
}
|
|
477
484
|
entryList(t) {
|
|
478
|
-
return
|
|
485
|
+
return a(this, null, function* () {
|
|
479
486
|
return this.entries(t);
|
|
480
487
|
});
|
|
481
488
|
}
|
|
@@ -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
|
|
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
|
-
return
|
|
499
|
+
return a(this, null, function* () {
|
|
493
500
|
const e = yield this.getBestToken();
|
|
494
|
-
return
|
|
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
|
/**
|
|
@@ -503,7 +530,7 @@ class _ {
|
|
|
503
530
|
* const muffin = await sdk("stage").dm("83cc6374").model("muffin").getSchema()
|
|
504
531
|
*/
|
|
505
532
|
getSchema() {
|
|
506
|
-
return
|
|
533
|
+
return a(this, null, function* () {
|
|
507
534
|
return mt(this.config);
|
|
508
535
|
});
|
|
509
536
|
}
|
|
@@ -521,13 +548,13 @@ class _ {
|
|
|
521
548
|
* const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
|
|
522
549
|
*/
|
|
523
550
|
assets(t) {
|
|
524
|
-
return
|
|
551
|
+
return a(this, null, function* () {
|
|
525
552
|
const e = yield this.getBestToken();
|
|
526
|
-
return
|
|
553
|
+
return gt(y(u({}, this.config), { options: t, token: e }));
|
|
527
554
|
});
|
|
528
555
|
}
|
|
529
556
|
assetList(t) {
|
|
530
|
-
return
|
|
557
|
+
return a(this, null, function* () {
|
|
531
558
|
return this.assets(t);
|
|
532
559
|
});
|
|
533
560
|
}
|
|
@@ -553,9 +580,9 @@ class _ {
|
|
|
553
580
|
* .createAsset({ file, name: "venndiagram.png" });
|
|
554
581
|
*/
|
|
555
582
|
createAsset() {
|
|
556
|
-
return
|
|
583
|
+
return a(this, arguments, function* ({ file: t, name: e, options: s } = {}) {
|
|
557
584
|
const r = yield this.getBestToken();
|
|
558
|
-
return
|
|
585
|
+
return ft(y(u({}, this.config), { file: t, name: e, options: s, token: r }));
|
|
559
586
|
});
|
|
560
587
|
}
|
|
561
588
|
/**
|
|
@@ -568,9 +595,9 @@ class _ {
|
|
|
568
595
|
* await ecadmin.assetgroup("test").deleteAsset('xxxx');
|
|
569
596
|
*/
|
|
570
597
|
deleteAsset(t) {
|
|
571
|
-
return
|
|
598
|
+
return a(this, null, function* () {
|
|
572
599
|
const e = yield this.getBestToken();
|
|
573
|
-
return yt(
|
|
600
|
+
return yt(y(u({}, this.config), { token: e, assetID: t }));
|
|
574
601
|
});
|
|
575
602
|
}
|
|
576
603
|
/**
|
|
@@ -583,9 +610,9 @@ class _ {
|
|
|
583
610
|
* const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
|
|
584
611
|
*/
|
|
585
612
|
getAsset(t) {
|
|
586
|
-
return
|
|
613
|
+
return a(this, null, function* () {
|
|
587
614
|
const e = yield this.getBestToken();
|
|
588
|
-
return ht(
|
|
615
|
+
return ht(y(u({}, this.config), { assetID: t, token: e }));
|
|
589
616
|
});
|
|
590
617
|
}
|
|
591
618
|
/**
|
|
@@ -598,9 +625,9 @@ class _ {
|
|
|
598
625
|
* const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
|
|
599
626
|
*/
|
|
600
627
|
createEntry(t) {
|
|
601
|
-
return
|
|
628
|
+
return a(this, null, function* () {
|
|
602
629
|
const e = yield this.getBestToken();
|
|
603
|
-
return
|
|
630
|
+
return pt(y(u({}, this.config), { token: e, value: t }));
|
|
604
631
|
});
|
|
605
632
|
}
|
|
606
633
|
/**
|
|
@@ -614,9 +641,9 @@ class _ {
|
|
|
614
641
|
* const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
|
|
615
642
|
*/
|
|
616
643
|
editEntry(t, e) {
|
|
617
|
-
return
|
|
644
|
+
return a(this, null, function* () {
|
|
618
645
|
const s = yield this.getBestToken();
|
|
619
|
-
return
|
|
646
|
+
return B(y(u({}, this.config), { entryID: t, token: s, value: e }));
|
|
620
647
|
});
|
|
621
648
|
}
|
|
622
649
|
/**
|
|
@@ -629,9 +656,9 @@ class _ {
|
|
|
629
656
|
* await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
|
|
630
657
|
*/
|
|
631
658
|
deleteEntry(t) {
|
|
632
|
-
return
|
|
659
|
+
return a(this, null, function* () {
|
|
633
660
|
const e = yield this.getBestToken();
|
|
634
|
-
return $t(
|
|
661
|
+
return $t(y(u({}, this.config), { token: e, entryID: t }));
|
|
635
662
|
});
|
|
636
663
|
}
|
|
637
664
|
/**
|
|
@@ -644,9 +671,9 @@ class _ {
|
|
|
644
671
|
* const res = await sdk("stage").resource("template").resourceList()
|
|
645
672
|
*/
|
|
646
673
|
resourceList(t) {
|
|
647
|
-
return
|
|
674
|
+
return a(this, null, function* () {
|
|
648
675
|
const e = yield this.getBestToken();
|
|
649
|
-
return Lt(
|
|
676
|
+
return Lt(y(u({}, this.config), { options: t, token: e }));
|
|
650
677
|
});
|
|
651
678
|
}
|
|
652
679
|
/**
|
|
@@ -660,9 +687,9 @@ class _ {
|
|
|
660
687
|
* const res = await sdk("stage").route("stats").raw()
|
|
661
688
|
*/
|
|
662
689
|
raw(t) {
|
|
663
|
-
return
|
|
690
|
+
return a(this, null, function* () {
|
|
664
691
|
const e = yield this.getBestToken();
|
|
665
|
-
return Ot(
|
|
692
|
+
return Ot(y(u({}, this.config), { options: t, token: e }));
|
|
666
693
|
});
|
|
667
694
|
}
|
|
668
695
|
// TODO: rename authAdapter -> storageAdapter
|
|
@@ -703,13 +730,13 @@ class _ {
|
|
|
703
730
|
}
|
|
704
731
|
logoutPublic() {
|
|
705
732
|
const t = this.getPublicToken();
|
|
706
|
-
return console.log("token", t), Et(
|
|
733
|
+
return console.log("token", t), Et(y(u({}, this.config), { token: t })).then(
|
|
707
734
|
this.unsetAuth(T(this.config))
|
|
708
735
|
);
|
|
709
736
|
}
|
|
710
737
|
logoutEc() {
|
|
711
738
|
const t = this.getEcToken();
|
|
712
|
-
return console.log("token", t), At(
|
|
739
|
+
return console.log("token", t), At(y(u({}, this.config), { token: t })).then(
|
|
713
740
|
this.unsetAuth(b(this.config))
|
|
714
741
|
);
|
|
715
742
|
}
|
|
@@ -827,9 +854,9 @@ class _ {
|
|
|
827
854
|
* @returns any
|
|
828
855
|
*/
|
|
829
856
|
getDatamanager(t) {
|
|
830
|
-
return
|
|
857
|
+
return a(this, null, function* () {
|
|
831
858
|
const e = yield this.getBestToken();
|
|
832
|
-
return Pt(
|
|
859
|
+
return Pt(y(u({}, this.config), { dmID: t, token: e }));
|
|
833
860
|
});
|
|
834
861
|
}
|
|
835
862
|
/**
|
|
@@ -841,9 +868,9 @@ class _ {
|
|
|
841
868
|
* const dms = await sdk("stage").dmList()
|
|
842
869
|
*/
|
|
843
870
|
dmList() {
|
|
844
|
-
return
|
|
871
|
+
return a(this, arguments, function* (t = {}) {
|
|
845
872
|
const e = yield this.getBestToken();
|
|
846
|
-
return bt(
|
|
873
|
+
return bt(y(u({}, this.config), { options: t, token: e }));
|
|
847
874
|
});
|
|
848
875
|
}
|
|
849
876
|
/**
|
|
@@ -855,9 +882,9 @@ class _ {
|
|
|
855
882
|
* const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
|
|
856
883
|
*/
|
|
857
884
|
modelList() {
|
|
858
|
-
return
|
|
885
|
+
return a(this, arguments, function* (t = {}) {
|
|
859
886
|
const e = yield this.getBestToken();
|
|
860
|
-
return Tt(
|
|
887
|
+
return Tt(y(u({}, this.config), { options: t, token: e }));
|
|
861
888
|
});
|
|
862
889
|
}
|
|
863
890
|
}
|
|
@@ -866,30 +893,30 @@ export {
|
|
|
866
893
|
_ as Sdk,
|
|
867
894
|
St as act,
|
|
868
895
|
p as apiURL,
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
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,
|
|
877
904
|
d as expect,
|
|
878
905
|
g as fetcher,
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
906
|
+
et as getAsset,
|
|
907
|
+
ot as getDatamanager,
|
|
908
|
+
I as getEcAuthKey,
|
|
909
|
+
W as getEntry,
|
|
883
910
|
M as getPublicAuthKey,
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
911
|
+
tt as getSchema,
|
|
912
|
+
v as loginEc,
|
|
913
|
+
R as loginPublic,
|
|
887
914
|
F as logoutEc,
|
|
888
|
-
|
|
889
|
-
|
|
915
|
+
U as logoutPublic,
|
|
916
|
+
at as modelList,
|
|
890
917
|
H as publicApi,
|
|
891
918
|
w as query,
|
|
892
|
-
|
|
893
|
-
|
|
919
|
+
ut as raw,
|
|
920
|
+
ct as resourceList,
|
|
894
921
|
Bt as sdk
|
|
895
922
|
};
|
package/dist/lib/api.d.mts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
*
|
package/dist/lib/api.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AAgCA,sCAWC;;AAED;;GAEG;AACH;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,
|
|
1
|
+
{"version":3,"file":"api.d.mts","sourceRoot":"","sources":["../../src/lib/api.mjs"],"names":[],"mappings":"AAgCA,sCAWC;;AAED;;GAEG;AACH;IACE,yBAEC;IADC,YAAoB;IAGtB,mBAGC;IAED;;;;;;;;;;;;OAYG;IACH,kBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;;;;;OAaG;IACH,uBATW,MAAM,SACN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAUlC;IACD;;;;;;;OAOG;IACH,aAJa,QAAQ,WAAW,CAAC,CAMhC;IACD;;;;;;;;;;;;OAYG;IACH,iBATW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAW9B;IACD,4CAEC;IACD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,sCAjBW;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,MAAM,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAClD,QAAQ,aAAa,CAAC,CAmBlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,QAAQ,IAAI,CAAC,CAOzB;IACD;;;;;;;;OAQG;IACH,kBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IAED;;;;;;;;OAQG;IACH,mBALW,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;;OASG;IACH,mBANW,MAAM,SACN,MAAM,GACJ,QAAQ,aAAa,CAAC,CAOlC;IACD;;;;;;;;OAQG;IACH,qBALW,MAAM,GACJ,IAAI,CAOhB;IAED;;;;;;;;OAQG;IACH,uBALW,MAAM,eACJ,QAAQ,YAAY,CAAC,CAOjC;IAED;;;;;;;;;OASG;IACH,cALW,MAAM,eACJ,QAAQ,GAAG,CAAC,CAOxB;IAID,mCAGC;IAED,sCASC;IACD,wCAUC;IACD,uBAMC;IAED,mCAIC;IACD,uCAKC;IAED,6BAMC;IAED,yBAMC;IAED,sBAEC;IACD,kBAEC;IACD,0BAEC;IACD,sBAEC;IACD,uBAEC;IACD,oBAMC;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,qBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,WAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,cAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,uBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,qBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,mBAHW,MAAM,OAKhB;IACD;;;;OAIG;IACH,aAHW,MAAM,OAKhB;IAED;;;OAGG;IACH,0BAEC;IAED;;;OAGG;IACH,wCAGC;IAED;;;;;;;OAOG;IACH,iBALW,MAAM,eACJ,QAAQ,eAAe,CAAC,CAOpC;IACD;;;;;;;OAOG;IACH,oBALW,MAAM,eACJ,QAAQ,SAAS,CAAC,CAO9B;CACF;AAEM,mCAAqC;;SAI9B,MAAM;UACN,MAAM;;;;aAMN,MAAM;aACN,IAAI;WACJ,MAAM,GAAG,CAAC;UACV,MAAM,MAAM,GAAG,GAAG,CAAC;WACnB,MAAM;UACN,MAAM;UACN,SAAS;;;;;;QAKT,MAAM;;;;cACN,IAAI;;;;cACJ,MAAM;;;;eACN,GAAG;;;;YACH,GAAG;;;;iBACH,MAAM;;;;sBACN,MAAM;;;;eACN,IAAI;;;;aACJ,IAAI;;;;cACJ,IAAI;;;;UACJ,GAAG;;;;;;aAOH,GAAG;;;;iBACH,MAAM;;;;cACN,OAAO;;;;cACP,OAAO;;;;UACP,MAAM;;;;cACN,MAAM;;;QAIC,MAAM,GAAE,gBAAgB;;;WAK/B,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;aAKf,MAAM;mBACN,MAAM;mBACN,MAAM;iBACN,MAAM;YACN,GAAG;cACH,MAAM;aACN,MAAM,EAAE;YACR,MAAM,EAAE;uBACR,MAAM,EAAE;aACR,MAAM;WACN,MAAM;;;;YACN,GAAG;;;WAKH,MAAM;WACN,MAAM;WACN,mBAAmB,EAAE;;;WAKrB,MAAM;WACN,MAAM;WACN,aAAa,EAAE;;;WAKf,MAAM;WACN,MAAM;WACN,GAAG,EAAE;;;;;;aAML,GAAG;iBACH,MAAM;iBACN,OAAO;aACP,OAAO;cACP,OAAO;cACP,OAAO;YACP,OAAO;WACP,MAAM;UACN,MAAM;gBACN,MAAM,GAAG,IAAI;;;YAKb,GAAG;aACH,MAAM;iBACN,MAAM;YACN,gBAAgB,EAAE;gBAClB,OAAO;cACP,MAAM;WACN,GAAG,EAAE;eACL,GAAG,EAAE;aACL,MAAM,EAAE;aACR,MAAM;cACN,MAAM;cACN,GAAG,EAAE;UACL,GAAG;WACH,MAAM;gBACN,MAAM;YACN,GAAG;;;WAMH,MAAM;WACN,MAAM;WACN,aAAa,EAAE"}
|
package/dist/lib/entries.d.mts
CHANGED
|
@@ -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
|
|
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"}
|