Lightweight SDK for entrecode APIs. Currently supports only most common PublicAPI functions.
npm i ec.fdk
cd packages/ec.fdk
- bump version in
packages/ec.fdk/package.json
- run
pnpm readme
- commit + push
- run
pnpm publish
Start by calling sdk
with your environment (stage
| live
), then method chain your way to success:
import { sdk } from "ec.fdk";
sdk("stage") // choose stage environment
.dm("83cc6374") // select datamanager via short id
.model("muffin") // select model muffin
.entries() // load entry list
.then(list => {
console.log(list);
})
You can also reuse parts of the chain with variables:
// we want to do stuff with model muffin here
const muffin = sdk("stage").dm("83cc6374").model("muffin");
// load entry list
const { items } = await muffin.entries();
// edit first entry
await muffin.editEntry(items[0].id, { name: "edit!" });
// delete second entry
await muffin.deleteEntry(items[1].id);
// create a new muffin
await muffin.createEntry({ name: "new muffin" });
// edit third entry with safePut
await muffin.editEntrySafe(items[2].id, { _modified: items[2]._modified, name: "safePut!" });
Now what follows is the autogenerated doc from source:
SDK
Kind: static class of api
-
.Sdk
-
.entries([options]) ⇒
Promise.<EntryList>
-
.getEntry(entryID) ⇒
Promise.<EntryResource>
-
.editEntrySafe(entryID, value) ⇒
Promise.<EntryResource>
-
.getSchema(entryID) ⇒
Promise.<EntrySchema>
-
.assets([options]) ⇒
Promise.<AssetList>
-
.createAsset(options) ⇒
Promise.<AssetResource>
-
.deleteAsset(assetID) ⇒
Promise.<void>
-
.getAsset(assetID) ⇒
Promise.<AssetResource>
-
.createEntry(value) ⇒
Promise.<EntryResource>
-
.editEntry(entryID, value) ⇒
Promise.<EntryResource>
-
.deleteEntry(entryID) ⇒
void
-
.resourceList([options]) ⇒
Promise.<ResourceList>
-
.raw([options]) ⇒
Promise.<any>
- .model(model) ⇒
- .token(token) ⇒
- .dmShortID(dmShortID) ⇒
- .dmID(dmID) ⇒
- .dm(dmShortID) ⇒
- .assetGroup(assetGroup) ⇒
- .assetgroup(assetGroup) ⇒
- .subdomain(subdomain) ⇒
- .resource(resource) ⇒
- .route(route) ⇒
- .publicApi() ⇒
- .getDatamanager() ⇒
-
.dmList([options]) ⇒
Promise.<DatamanagerList>
-
.modelList([options]) ⇒
Promise.<ModelList>
-
.entries([options]) ⇒
sdk.entries([options]) ⇒ Promise.<EntryList>
Loads entry list. Expects dmShortID
/ model
to be set.
If the model is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
[options] | object |
options for entry list request. |
Example
// public model
const muffins = await sdk("stage").dm("83cc6374").model("muffin").entries()
Example
// non-public model
const secrets = await sdk("stage").token(token).dm("83cc6374").model("secret").entries()
sdk.getEntry(entryID) ⇒ Promise.<EntryResource>
Loads a single entry. Expects dmShortID
/ model
to be set.
If the model is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type |
---|---|
entryID | string |
Example
const muffin = await sdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
sdk.editEntrySafe(entryID, value) ⇒ Promise.<EntryResource>
Edits an entry with safe put. Expects dmShortID
/ model
to be set.
Expects a _modified
field in the value. Will only update if the entry has not been changed since.
If model PUT is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
entryID | string |
id of entry to edit |
value | object |
values to set. undefined fields are ignored |
Example
const entry = await sdk("stage")
.dm("83cc6374")
.model("muffin")
.editEntrySafe("1gOtzWvrdq", { name: "test", _modified: "2020-01-01T00:00:00.000Z"})
sdk.getSchema(entryID) ⇒ Promise.<EntrySchema>
Loads the schema of a model. Expects dmShortID
/ model
to be set.
Kind: instance method of Sdk
Param | Type |
---|---|
entryID | string |
Example
const muffin = await sdk("stage").dm("83cc6374").model("muffin").getSchema()
sdk.assets([options]) ⇒ Promise.<AssetList>
Loads asset list. Expects dmShortID
/ assetGroup
to be set.
If the assetGroup is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
[options] | object |
options for entry list request. |
Example
// public assetGroup
const files = await sdk("stage").dm("83cc6374").assetGroup("avatars").assets()
Example
// non-public assetGroup
const files = await sdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assets()
sdk.createAsset(options) ⇒ Promise.<AssetResource>
Uploads an asset. Expects dmShortID
/ assetGroup
/ file
to be set.
If the assetGroup is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
options | Object |
options for entry list request. |
Example
// browser example
document.getElementById("file").addEventListener("input", async (e) => {
const [file] = e.target.files;
const asset = await ecadmin.assetgroup("test").createAsset({ file })
});
Example
// node example
const buf = fs.readFileSync("venndiagram.png");
const file = new Blob([buf]);
const upload = await sdk("stage")
.dm("83cc6374")
.assetgroup("test")
.createAsset({ file, name: "venndiagram.png" });
Deletes an asset. Expects dmShortID
/ assetGroup
/ assetID
to be set.
You probably also need to provide a token
.
Kind: instance method of Sdk
Param | Type |
---|---|
assetID | string |
Example
await ecadmin.assetgroup("test").deleteAsset('xxxx');
sdk.getAsset(assetID) ⇒ Promise.<AssetResource>
Loads a single asset. Expects dmShortID
/ assetGroup
to be set.
If the asset group is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type |
---|---|
assetID | string |
Example
const asset = await sdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
sdk.createEntry(value) ⇒ Promise.<EntryResource>
Creates a new entry. Expects dmShortID
/ model
to be set.
If model POST is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
value | object |
values to set. |
Example
const entry = await sdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
sdk.editEntry(entryID, value) ⇒ Promise.<EntryResource>
Edits an entry. Expects dmShortID
/ model
to be set.
If model PUT is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
entryID | string |
id of entry to edit |
value | object |
values to set. undefined fields are ignored |
Example
const entry = await sdk("stage").dm("83cc6374").model("muffin").editEntry("1gOtzWvrdq", { name: "test" })
Deletes an entry. Expects dmShortID
/ model
to be set.
If model DELETE is not public, you also need to provide a token
.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
entryID | string |
id of entry to delete |
Example
await sdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
sdk.resourceList([options]) ⇒ Promise.<ResourceList>
Fetches resource list. Expects resource
to be set. subdomain
defaults to "datamanager".
Fetches https://<subdomain>.entrecode.de/<resource>?_list=true&size=<options.size ?? 25>
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
[options] | object |
options for list request. |
Example
const res = await sdk("stage").resource("template").resourceList()
Fetches raw route. Expects route
to be set. subdomain
defaults to "datamanager".
Fetches https://<subdomain>.entrecode.de/<route>?<options>
Use this when no other fdk method can give you your request.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
[options] | object |
options for list request. |
Example
const res = await sdk("stage").route("stats").raw()
Sets the given model to use
Kind: instance method of Sdk
Returns:
Sdk
Param | Type | Description |
---|---|---|
model | string |
name of the model |
Sets the token to use in requests
Kind: instance method of Sdk
Returns:
Sdk
Param | Type |
---|---|
token | string |
Sets the short ID of the datamanager to use
Kind: instance method of Sdk
Returns:
Sdk
Param | Type |
---|---|
dmShortID | string |
Sets the (long) ID of the datamanager to use
Kind: instance method of Sdk
Returns:
Sdk
Param | Type |
---|---|
dmID | string |
Sets the short ID of the datamanager to use. Alias for dmShortID
Kind: instance method of Sdk
Returns:
Sdk
Param | Type |
---|---|
dmShortID | string |
Sets the name of the asset group to use.
Kind: instance method of Sdk
Returns:
Sdk
Param | Type | Description |
---|---|---|
assetGroup | string |
name of the asset group |
Sets the name of the asset group to use. Alias for assetGroup
Kind: instance method of Sdk
Returns:
Sdk
Param | Type | Description |
---|---|---|
assetGroup | string |
name of the asset group |
Sets the subdomain to use.
Kind: instance method of Sdk
Returns:
Sdk
Param | Type | Description |
---|---|---|
subdomain | string |
subdomain |
Sets the name of the resource to use.
Kind: instance method of Sdk
Returns:
Sdk
Param | Type | Description |
---|---|---|
resource | string |
name of the resource |
Sets the route to use.
Kind: instance method of Sdk
Returns:
Sdk
Param | Type | Description |
---|---|---|
route | string |
route |
Returns the public api root endpoint. Expects dmShortID to be set.
Kind: instance method of Sdk
Returns:
any
Loads a DatamanagerResource by its long id. Requires token.
Kind: instance method of Sdk
Returns:
any
sdk.dmList([options]) ⇒ Promise.<DatamanagerList>
Loads datamanager list. Make sure to provide an ec.admin token
intercept one.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
[options] | object |
options for entry list request. |
Example
const dms = await sdk("stage").dmList()
sdk.modelList([options]) ⇒ Promise.<ModelList>
Loads model list. Expects dmID to be set. Make sure to provide an ec.admin token
intercept one.
Kind: instance method of Sdk
Param | Type | Description |
---|---|---|
[options] | object |
options for entry list request. |
Example
const models = await sdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()