Class Fdk<TModel, TResource>

Type Parameters

  • TModel extends string = string
  • TResource extends string = string

Methods - Entries

  • Loads entry list. Expects dmShortID / model to be set. If the model is not public, you also need to provide a token.

    Parameters

    Returns Promise<TypedEntryList<TModel>>

    // public model
    const muffins = await fdk("stage").dm("83cc6374").model("muffin").entryList()
    // non-public model
    const secrets = await fdk("stage").token(token).dm("83cc6374").model("secret").entryList()
  • Maps over entry list.

    Parameters

    Returns Promise<EntryResource[]>

    // public model
    const muffins = fdk("stage").dm("83cc6374").model("muffin")
    const res = await muffin.mapEntries((entry) => muffin.editEntry(entry.id, { name: entry.name + "!" }));
    console.log("res", res);
  • Loads a single entry. Expects dmShortID / model to be set. If the model is not public, you also need to provide a token.

    Parameters

    • entryID: string

    Returns Promise<TypedEntry<TModel>>

    const muffin = await fdk("stage").dm("83cc6374").model("muffin").getEntry("1gOtzWvrdq")
    
  • 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.

    Parameters

    • entryID: string

      id of entry to edit

    • value: Partial<EntryInput<TModel>> & { _modified: string | Date }

      values to set. undefined fields are ignored

    Returns Promise<TypedEntry<TModel>>

    const entry = await fdk("stage")
    .dm("83cc6374")
    .model("muffin")
    .editEntrySafe("1gOtzWvrdq", { name: "test", _modified: "2020-01-01T00:00:00.000Z"})
  • Loads the schema of a model. Expects dmShortID / model to be set.

    Returns Promise<EntrySchema>

    const muffin = await fdk("stage").dm("83cc6374").model("muffin").getSchema()
    
  • Creates a new entry. Expects dmShortID / model to be set. If model POST is not public, you also need to provide a token.

    Parameters

    Returns Promise<TypedEntry<TModel>>

    const entry = await fdk("stage").dm("83cc6374").model("muffin").createEntry({ name: 'test' })
    
  • Edits an entry. Expects dmShortID / model to be set. If model PUT is not public, you also need to provide a token.

    Parameters

    • entryID: string

      id of entry to edit

    • value: Partial<EntryInput<TModel>>

      values to set. undefined fields are ignored

    Returns Promise<TypedEntry<TModel>>

    const entry = await fdk("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.

    Parameters

    • entryID: string

      id of entry to delete

    Returns Promise<void>

    await fdk("stage").dm("83cc6374").model("muffin").deleteEntry("1gOtzWvrdq")
    
  • If true, removes _links and _embedded from returned entries. Default: false.

    Parameters

    • shouldClean: boolean = true

      whether to clean entries (default: true)

    Returns Fdk<TModel, TResource>

    const { items } = await fdk("stage").dm("83cc6374").model("muffin").clean().entryList()
    // items won't have _links or _embedded

Methods - Assets

  • Loads asset list. Expects dmShortID / assetGroup to be set. If the assetGroup is not public, you also need to provide a token.

    Parameters

    Returns Promise<AssetList>

    // public assetGroup
    const files = await fdk("stage").dm("83cc6374").assetGroup("avatars").assetList()
    // non-public assetGroup
    const files = await fdk("stage").token(token).dm("83cc6374").assetGroup("avatars").assetList()
  • Uploads an asset. Expects dmShortID / assetGroup / file to be set. If the assetGroup is not public, you also need to provide a token.

    Parameters

    Returns Promise<AssetResource>

    // browser example
    document.getElementById("file").addEventListener("input", async (e) => {
    const [file] = e.target.files;
    const asset = await ecadmin.assetgroup("test").createAsset({ file })
    });
    // node example
    const buf = fs.readFileSync("venndiagram.png");
    const file = new Blob([buf]);
    const upload = await fdk("stage")
    .dm("83cc6374")
    .assetgroup("test")
    .createAsset({ file, name: "venndiagram.png" });
  • Uploads multiple assets. Expects dmShortID / assetGroup / files to be set. If the assetGroup is not public, you also need to provide a token.

    Parameters

    Returns Promise<AssetResource[]>

    // browser example
    document.getElementById("file").addEventListener("input", async (e) => {
    const files = e.target.files;
    const asset = await ecadmin.assetgroup("test").createAssets({ files })
    });
    // node example
    const buf = fs.readFileSync("venndiagram.png");
    const files = [new Blob([buf])];
    const upload = await fdk("stage")
    .dm("83cc6374")
    .assetgroup("test")
    .createAsset({ files });
  • Deletes an asset. Expects dmShortID / assetGroup / assetID to be set. You probably also need to provide a token.

    Parameters

    • assetID: string

    Returns Promise<void>

    await ecadmin.assetgroup("test").deleteAsset('xxxx');
    
  • Loads a single asset. Expects dmShortID / assetGroup to be set. If the asset group is not public, you also need to provide a token.

    Parameters

    • assetID: string

    Returns Promise<AssetResource>

    const asset = await fdk("stage").dm("83cc6374").assetgroup("test").getAsset("tP-ZxpZZTGmbPnET-wArAQ")
    
  • Edits asset metadata. Expects dmShortID and assetGroup to be set.

    Parameters

    • assetID: string
    • value: object

    Returns Promise<AssetResource>

Methods - Admin

  • Edits a single resource via PUT. Expects resource to be set. subdomain defaults to "datamanager". Pass identifying query params as options.

    Parameters

    • options: Record<string, any>

      query params to identify the resource.

    • value: object

      the resource body to PUT.

    Returns Promise<any>

    const model = await fdk("stage").resource("model").resourceEdit({ dataManagerID: 'x', modelID: 'y' }, { title: 'new' })
    
  • Deletes a single resource. Expects resource to be set. subdomain defaults to "datamanager". Pass identifying query params as options.

    Parameters

    • options: Record<string, any>

      query params to identify the resource.

    Returns Promise<Response>

    await fdk("stage").resource("model").resourceDelete({ dataManagerID: 'x', modelID: 'y' })
    
  • 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.

    Type Parameters

    • T = any

    Parameters

    • options: object

      options that are converted to query params.

    • OptionalfetchOptions: object

      (optional) options passed to fetch.

    Returns Promise<T>

    const res = await fdk("stage").route("stats").raw()
    
  • Deletes a datamanager. Expects dmID to be set.

    Parameters

    • dmID: string

    Returns Promise<Response>

  • Deletes a model. Expects dmID to be set.

    Parameters

    • modelID: string

    Returns Promise<Response>

  • Edits a role. Expects dmID to be set.

    Parameters

    • roleID: string
    • value: object

    Returns Promise<RoleResource>

  • Deletes a role. Expects dmID to be set.

    Parameters

    • roleID: string

    Returns Promise<Response>

  • Deletes a DM account. Expects dmID to be set.

    Parameters

    • accountID: string

    Returns Promise<Response>

  • Loads datamanager stats.

    Parameters

    • options: object = {}

    Returns Promise<any>

  • Deletes an account client.

    Parameters

    • clientID: string

    Returns Promise<Response>

  • Deletes a group.

    Parameters

    • groupID: string

    Returns Promise<Response>

  • Deletes an invite.

    Parameters

    • inviteID: string

    Returns Promise<Response>

  • Deletes a token for an account.

    Parameters

    • accountID: string
    • accessTokenID: string

    Returns Promise<Response>

  • Sets the name of the resource to use.

    Type Parameters

    • R extends string

    Parameters

    • resource: R

      name of the resource

    Returns Fdk<TModel, R>

  • Loads model list. Expects dmID to be set. Requires auth.

    Parameters

    Returns Promise<ModelList>

    const models = await fdk("stage").dmID("254a03f1-cb76-4f1e-a52a-bbd4180ca10c").modelList()
    

Methods - Auth

  • Defines a custom storage to use for auth data. In most cases, this should not be needed. By default, auth will be stored in-memory, using a JS Map. This should be fine for NodeJS. In the Browser, it's better to use oidc-client and ignore all Auth methods here.

    Parameters

    Returns Fdk<TModel, TResource>

    // using Cookies
    import Cookies from "js-cookie";
    let fdk = fdk("stage").storageAdapter(Cookies);
    await fdk.dm("83cc6374").model("my-protected-model").entryList();
  • Login with the given ec user. Only needed when using manual auth.

    Parameters

    • config: { email: string; password: string }

    Returns Promise<any>

  • Login with the given public user. Only needed when using manual auth.

    Parameters

    • config: any

    Returns Promise<any>

  • Logs out the current public user. Only needed when using manual auth.

    Returns Promise<void>

  • Logs out the current ec user. Only needed when using manual auth.

    Returns Promise<void>