ec.fdk
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

ec.fdk

Lightweight SDK for entrecode APIs. Currently supports only most common PublicAPI functions.

Install

npm i ec.fdk

Publish

  1. cd packages/ec.fdk
  2. bump version in packages/ec.fdk/package.json
  3. run pnpm readme
  4. commit + push
  5. run pnpm publish

API

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:

api.Sdk

SDK

Kind: static class of api

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" });

sdk.deleteAsset(assetID) ⇒ Promise.<void>

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" })

sdk.deleteEntry(entryID) ⇒ void

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()

sdk.raw([options]) ⇒ Promise.<any>

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()

sdk.model(model) ⇒

Sets the given model to use

Kind: instance method of Sdk
Returns:

Sdk

Param Type Description
model string

name of the model

sdk.token(token) ⇒

Sets the token to use in requests

Kind: instance method of Sdk
Returns:

Sdk

Param Type
token string

sdk.dmShortID(dmShortID) ⇒

Sets the short ID of the datamanager to use

Kind: instance method of Sdk
Returns:

Sdk

Param Type
dmShortID string

sdk.dmID(dmID) ⇒

Sets the (long) ID of the datamanager to use

Kind: instance method of Sdk
Returns:

Sdk

Param Type
dmID string

sdk.dm(dmShortID) ⇒

Sets the short ID of the datamanager to use. Alias for dmShortID

Kind: instance method of Sdk
Returns:

Sdk

Param Type
dmShortID string

sdk.assetGroup(assetGroup) ⇒

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

sdk.assetgroup(assetGroup) ⇒

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

sdk.subdomain(subdomain) ⇒

Sets the subdomain to use.

Kind: instance method of Sdk
Returns:

Sdk

Param Type Description
subdomain string

subdomain

sdk.resource(resource) ⇒

Sets the name of the resource to use.

Kind: instance method of Sdk
Returns:

Sdk

Param Type Description
resource string

name of the resource

sdk.route(route) ⇒

Sets the route to use.

Kind: instance method of Sdk
Returns:

Sdk

Param Type Description
route string

route

sdk.publicApi() ⇒

Returns the public api root endpoint. Expects dmShortID to be set.

Kind: instance method of Sdk
Returns:

any


sdk.getDatamanager() ⇒

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()

Readme

Keywords

Package Sidebar

Install

npm i ec.fdk

Weekly Downloads

182

Version

0.4.0

License

ISC

Unpacked Size

80.2 kB

Total Files

23

Last publish

Collaborators

  • scherzinger
  • deyhle
  • ehlerskon
  • felixroos
  • ec.baesslerpa