{"id":22712021,"url":"https://github.com/buildit/twig-api-wrapper","last_synced_at":"2025-03-29T22:21:24.323Z","repository":{"id":78235779,"uuid":"97014492","full_name":"buildit/twig-api-wrapper","owner":"buildit","description":"wrapper functions for accessing twig-api","archived":false,"fork":false,"pushed_at":"2017-07-20T18:45:12.000Z","size":300,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-17T20:56:50.341Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buildit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-12T14:00:49.000Z","updated_at":"2017-07-13T19:32:38.000Z","dependencies_parsed_at":"2023-06-11T19:15:10.768Z","dependency_job_id":null,"html_url":"https://github.com/buildit/twig-api-wrapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildit%2Ftwig-api-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildit%2Ftwig-api-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildit%2Ftwig-api-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildit%2Ftwig-api-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buildit","download_url":"https://codeload.github.com/buildit/twig-api-wrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246250082,"owners_count":20747292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-10T13:09:07.049Z","updated_at":"2025-03-29T22:21:24.316Z","avatar_url":"https://github.com/buildit.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @buildit/twig-api-wrapper\n\n## PURPOSE\n\nThis project is a nodejs helper library for getting data into [Twig](http://github.com/buildit/twig). It is designed to abstract out all of the HTTP calls necessary so you can get right into the data entry. This project is written in typescript and published with definition files allowing you to take advantage of editors with proper code completion such as [vscode](https://code.visualstudio.com/). If your editor supports it, it will also help with paremeters for each method.\n![intellisense demo](images/intellisense.png)\n\nThe entire library is promise based and in these examples we will be taking advantage of IIFEs and the async/await spec included by default in node \u003e= v7.6\n\n## Table of Contents\n\n* [Installation and Setup](#installation-and-setup)\n* [Model Manipulation](#model-manipulation)\n* [Twiglet Maniupation](#twiglet-manipulation)\n* [Events and Sequences](#events-and-sequences)\n* [Other Methods](#other-methods)\n\n## Installation and Setup\n\n```Shell\nnpm install -S @buildit/twig-api-wrapper\n```\n\nThen in your project\n\n```JavaScript\nconst { config, login, Twiglet, Model } = require('@buildit/twig-api-wrapper');\n\n(async function main() {\n  try {\n    config.useLocal(); // also .useStaging() and .useProduction()\n    await login(\"ben.hernandez@corp.riglet.io\", \"my super secure password\")\n  } catch (error) {\n    console.err(error);\n  }\n})()\n```\n\n## Model Manipulation\n\n```JavaScript\n(async function main() {\n  try {\n    // setup\n    config.useLocal();\n    await login(\"ben.hernandez@corp.riglet.io\", \"my super secure password\")\n    // create a model.\n    const newModel = await Model.create({\n      name: 'a new model',\n      commitMessage: 'initial commit',\n      entities: {\n        users: { class: 'user-circle-o', image: 'A', attributes: [] },\n        bugs: { class: 'bug', image: 'B', attributes: [] }\n      }\n    });\n\n    // update a model, could also update entities here, works like a patch\n    await newModel.update({ name: 'this name is better', commitMessage: 'did not like old name'})\n\n    // model information\n    console.log('the entitites', newModel.entities);\n    console.log('the name', newModel.name);\n    console.log('latest commit message', newModel.latestCommit)\n    console.log('older changelog entries', await newModel.changelog.getList());\n\n    // delete a model.\n    await newModel.remove()\n\n    // Get a list of all of the models\n    const list = await Model.getList();\n    console.log(list);\n\n    // load the bsc model\n    const bscUrl = list.filter(m =\u003e m.name === 'bsc')[0].url;\n    const bsc = await Model.instance(bscUrl);\n    console.log(bsc.entities);\n  } catch (error) {\n    console.error(error);\n  }\n})()\n```\n\n## Twiglet Manipulation\n\n```JavaScript\n(async function main() {\n  try {\n    // setup\n    config.useLocal();\n    await login(\"ben.hernandez@corp.riglet.io\", \"my super secure password\")\n\n    // Twiglet creation\n    const newTwiglet = await Twiglet.create({\n      name: 'a new twiglet',\n      commitMessage: 'initial creation',\n      description: 'this is a demo twiglet',\n      model: 'bsc',\n    });\n\n    // Twiglet updating (could also update name and description, works like a patch)\n    await newTwiglet.update({\n      commitMessage: 'adding some nodes and links',\n      links: [\n        { id: 'one-to-two', source: '2', target: '1' }\n      ],\n      nodes: [\n        { id: '1', name: 'one', type: 'person' },\n        { id: '2', name: 'two', type: 'tribe' }\n      ],\n    });\n\n    // Twiglet information\n    console.log('Name', newTwiglet.name);\n    console.log('Description', newTwiglet.description);\n    console.log('Nodes', newTwiglet.nodes);\n    console.log('Links', newTwiglet.links);\n    console.log('Latest Commit', newTwiglet.latestCommit);\n    console.log('Entire changelog', await newTwiglet.changelog.getList());\n\n    // Delete a Twiglet\n    await newTwiglet.remove();\n\n    // Get a list of all the twiglets\n    const list = await Twiglet.getList();\n    console.log(list);\n\n    // Loading a specific twiglet\n    const slackUrl = list.filter(t =\u003e t.name === 'slack-analysis')[0].url;\n    const slack = await Twiglet.instance(slackUrl);\n    console.log(slack.name);\n  } catch (error) {\n    console.error(error);\n  }\n})()\n```\n\n## Events and Sequences\n\n```Javascript\n(async function main() {\n  try {\n    // setup\n    config.useLocal();\n    await login(\"ben.hernandez@corp.riglet.io\", \"my super secure password\")\n    // Note, since I am bypassing any lists with this instance and just providing a direct url, it does not matter what I set my config to, this will use localhost no matter what. Better make sure you are authenticated against that server before going direct to urls.\n    const emails = await Twiglet.instance('http://localhost:3000/v2/twiglets/Emails');\n\n    // Create an event\n    await emails.events.create({ name: 'event 1', description: 'the first event'});\n\n    // Getting a list of events\n    const eventsList = await emails.events.getList();\n    console.log(eventsList);\n    /**\n     * ...\n     * { id: '46a15ed5-6a0d-4bbf-8fde-5696a5f0147b',\n     *   name: 'event 1',\n     *   description: 'the first event',\n     *   url: 'http://localhost:3000/v2/twiglets/Emails/events/46a15ed5-6a0d-4bbf-8fde-5696a5f0147b' } ]\n     */\n\n    // deleting an event\n    await emails.events.deleteOne('http://localhost:3000/v2/twiglets/Emails/events/46a15ed5-6a0d-4bbf-8fde-5696a5f0147b');\n\n    // Create a sequence\n    // Note, a sequence is just an array of event IDs so we are going to use ids from the list above\n    await emails.sequences.create({\n      description: 'a series of unfortunate events',\n      name: 'sequence 1',\n      events: [eventsList[0].id, eventsList[4].id, eventsList[10].id],\n    })\n\n    // Getting a list of sequences\n    const sequenceList = await emails.sequences.getList();\n    console.log(sequenceList);\n    /**\n     * ...\n     * { description: 'a series of unfortunate events',\n     *   events:\n     *     [ 'eafd9c10-f622-4050-b18c-29764ce0c375',\n     *       'cbfced59-08c6-406b-b457-d4ca04ff3efc',\n     *       'b750855b-c590-4cb2-9dea-eff96269c3e3' ],\n     *   id: 'e6c5f16e-ad24-443b-a825-2cbc0ea869d3',\n     *   name: 'sequence 1',\n     *   url: 'http://localhost:3000/v2/twiglets/Emails/sequences/e6c5f16e-ad24-443b-a825-2cbc0ea869d3' } ]\n     */\n\n    // deleting a sequence\n    await emails.sequences.deleteOne('http://localhost:3000/v2/twiglets/Emails/sequences/e6c5f16e-ad24-443b-a825-2cbc0ea869d3')\n  } catch (error) {\n    console.error(error);\n  }\n})()\n```\n\n## Other Methods\n\nThere are a lot of other methods inside this wrapper. At the time of this writing, every method on the API has a corresponding method here. To get a good feel for how to use them, check out the e2e tests accompanying Models and Twiglets.\n\n## Contributing\n\nFeel free to update/add methods as needed. This package is published on npm under the @buildit organization. Write unit/e2e tests as appropriate then version and publish. Since these are mostly just wrappers around API calls, I found it was more useful to write e2e tests for most methods.\n\n```Shell\nnpm version major | minor | patch\nnpm publish --access=public\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildit%2Ftwig-api-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuildit%2Ftwig-api-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildit%2Ftwig-api-wrapper/lists"}