ec.fdk v0.4.0
ec.fdk
Lightweight SDK for entrecode APIs. Currently supports only most common PublicAPI functions.
Install
npm i ec.fdk
Publish
cd packages/ec.fdk
- bump version in
packages/ec.fdk/package.json
- run
pnpm readme
- commit + push
- 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
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>
sdk.entries(options) ⇒ Promise.<EntryList>
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>
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>
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>
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>
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>
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>
Kind: instance method of Sdk
Param | Type |
---|---|
assetID | string |
Example
await ecadmin.assetgroup("test").deleteAsset('xxxx');
sdk.getAsset(assetID) ⇒ Promise.<AssetResource>
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>
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>
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
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>
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>
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) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type | Description |
---|---|---|
model | string | name of the model |
sdk.token(token) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type |
---|---|
token | string |
sdk.dmShortID(dmShortID) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type |
---|---|
dmShortID | string |
sdk.dmID(dmID) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type |
---|---|
dmID | string |
sdk.dm(dmShortID) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type |
---|---|
dmShortID | string |
sdk.assetGroup(assetGroup) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type | Description |
---|---|---|
assetGroup | string | name of the asset group |
sdk.assetgroup(assetGroup) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type | Description |
---|---|---|
assetGroup | string | name of the asset group |
sdk.subdomain(subdomain) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type | Description |
---|---|---|
subdomain | string | subdomain |
sdk.resource(resource) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type | Description |
---|---|---|
resource | string | name of the resource |
sdk.route(route) ⇒
Kind: instance method of Sdk
Returns: Sdk
Param | Type | Description |
---|---|---|
route | string | route |
sdk.publicApi() ⇒
Kind: instance method of Sdk
Returns: any
sdk.getDatamanager() ⇒
Kind: instance method of Sdk
Returns: any
sdk.dmList(options) ⇒ Promise.<DatamanagerList>
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>
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()
18 days ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
9 months ago
9 months ago
9 months ago