0.1.6 • Published 5 years ago

kauri-api-client v0.1.6

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

kauri-scripts

Getting started

  1. Init a npm project
npn init
  1. Load the dependency
npm install -s kauri-api-client
  1. Create a js file like this
(async () => {
    // Import kauri-client
    const KauriClient   = require('kauri-api-client');

    // Init the client (that's for dev, for production, just change api.dev.kauri.io to api.kauri.io)
    const kauriClient = await KauriClient.init({
        "MNEMONIC": "word1 word2 ... word12",
        "HOST": "api.dev2.kauri.io",
    });

    // Example 1: Get user details
    var user = await kauriClient.getUser("F0f15Cedc719B5A55470877B0710d5c7816916b1");
    console.log(user)

    // Example 2: Search latest articles
    var articles = await kauriClient.searchArticles();
    console.log(articles)

    // Example 3: Submit and Publish an article
    var article = await kauriClient.submitAndSelfPublishArticle({
            "content": "blabla",
            "title": "title",
            "attributes": {},
            "tags": ["tag1", "tag2"]
        });
    console.log(article)

    process.exit();
})();
  1. Run the script
node myscript.js

Documentation

/**
 * getUser
 * @description: Retrieve public user profile
 * @args: userId User Account Address (withtout 0x)
 */
KauriClient.prototype.getUser = async function(userId)

/**
 * saveUser
 * @description: Save (create/edit) a user profile
 * @args: userInput User Data
 *        { "name": name, "username": username, "email": email, "title": title, "website": website, "avatar": avatar, "social": {"twitter": "username"}, "subscriptions": {"newletters": true} }
 */
KauriClient.prototype.saveUser = async function(userInput)

/**
 * countVote
 * @description: Get vote result for a resource
 * @args: parent Resource Identifier
 *        { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.countVote = async function(parent)

/**
 * addVote
 * @description: Record a vote
 * @args: parent
 *       {"parent": { "type": "ARTICLE", "id": "123123" } }
 */
KauriClient.prototype.addVote = async function(voteInput)

/**
 * getComments
 * @description: Get Comments for a resource
 * @args: parent Resource Identifier
 *        { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.getComments = async function(parent)

/**
 * addComment
 * @description: Record comment
 * @args: parent
 *       {"body": "my comment", "parent": { "type": "ARTICLE", "id": "123123" } }
 */
KauriClient.prototype.addComment = async function(commentInput)

/**
 * getCollection
 * @description: Get collection
 * @args: collectionId Collection ID
 */
KauriClient.prototype.getCollection = async function(collectionId)

/**
 * createCollection
 * @description: Create a collection
 * @args: collectionInput
 *       {"name": collectionName, "description": collectionDescription, "attributes": {}, "sections": [{ "name": "section name", "description": "section desc", "resourcesId": [{ "type": "ARTICLE", "id": "123123" }] }], "tags": ["tag1"]}
 */
KauriClient.prototype.createCollection = async function(collectionInput)

/**
 * editCollection
 * @description: Edit a collection
 * @args: collectionInput
 *       { "id": id, "name": collectionName, "description": collectionDescription, "attributes": {}, "sections": [{ "name": "section name", "description": "section desc", "resourcesId": [{ "type": "ARTICLE", "id": "123123" }] }], "tags": ["tag1"]}
 */
KauriClient.prototype.editCollection = async function(collectionInput)

/**
 * addCollectionSection
 * @description: Add a section to a collection
 * @args: id Collection ID
 * @args: section Section
 *      { "name": "section name", "description": "section desc", "resourcesId": [{ "type": "ARTICLE", "id": "123123" }] }
 * @args: position Position of the section (default: last)
 */
KauriClient.prototype.addCollectionSection = async function(id, section, position)

/**
 * removeCollectionSection
 * @description: Remove a section from a collection
 * @args: id Collection ID
 * @args: sectionId Section ID
 */
KauriClient.prototype.removeCollectionSection = async function(id, sectionId)

/**
 * moveCollectionSection
 * @description: Move a section within a collection
 * @args: id Collection ID
 * @args: sectionId Section ID
 * @args: position Position of the section (default: last)
 */
KauriClient.prototype.moveCollectionSection = async function(id, sectionId, position)

/**
 * addCollectionResource
 * @description: Add a resource to a collection section
 * @args: id Collection ID
 * @args: sectionId Section ID
 * @args: resource Resource Identifier
 *      { "type": "ARTICLE", "id": "123123" }
 * @args: position Position of the section (default: last)
 */
KauriClient.prototype.addCollectionResource = async function(id, sectionId, resource, position)

/**
 * removeCollectionResource
 * @description: Remove a resource from a collection section
 * @args: id Collection ID
 * @args: sectionId Section ID
 * @args: resource Resource Identifier
 *      { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.removeCollectionResource = async function(id, sectionId, resource)

/**
 * moveCollectionResource
 * @description: Move a resource within a collection section
 * @args: id Collection ID
 * @args: sectionId Section ID
 * @args: resource Resource Identifier
 *      { "type": "ARTICLE", "id": "123123" }
 * @args: position Position of the section (default: last)
 */
KauriClient.prototype.moveCollectionResource = async function(id, sectionId, resource, position)


/**
 * getCuratedList
 * @description: Get a curated List
 * @args: curatedListId CuratedList ID
 */
KauriClient.prototype.getCuratedList = async function(curatedListId)

/**
 * createCuratedList
 * @description: Creat a curated List
 * @args: curatedListInput
 *        { "name": curatedListName, "description": curatedListDescription, "header": { "type": "ARTICLE", "id": "123123" }, "resources": [{ "type": "ARTICLE", "id": "123123" }], "links": links }
 */
KauriClient.prototype.createCuratedList = async function(curatedListInput)

/**
 * editCuratedList
 * @description: Edit a curated List
 * @args: curatedListInput
 *        { "id": id, "name": curatedListName, "description": curatedListDescription, "header": { "type": "ARTICLE", "id": "123123" }, "resources": [{ "type": "ARTICLE", "id": "123123" }], "links": links }
 */
KauriClient.prototype.editCuratedList = async function(curatedListInput)

/**
 * removeCuratedList
 * @description: Remove a curated List
 * @args: curatedListId CuratedList ID
 */
KauriClient.prototype.removeCuratedList = async function(curatedListId)

/**
 * getCommunity
 * @description: Get community details
 * @args: communityId Community ID
 */
KauriClient.prototype.getCommunity = async function(communityId)

/**
 * createCommunity
 * @description: Create a community
 * @args: communityInput
 *        { "name": name,  "description": desc, "website": website, "social": {"twitter": twitter}, "tags": ["tag1"] }
 */
KauriClient.prototype.createCommunity = async function(communityInput)

/**
 * editCommunity
 * @description: Edit a community
 * @args: communityInput
 *        { "id": id,  "name": name,  "description": desc, "website": website, "social": {"twitter": twitter}, "tags": ["tag1"] }
 */
KauriClient.prototype.editCommunity = async function(communityInput)

/**
 * submitResourceToCommunity
 * @description: Submit a resource to a community (curation)
 * @args: communityId Community ID
 * @args: resourceId Resource Identifier
 *        { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.submitResourceToCommunity = async function(communityId, resourceId)

/**
 * approveResourceToCommunity
 * @description: Approve a resource to a community (curation)
 * @args: communityId Community ID
 * @args: resourceId Resource Identifier
 *        { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.approveResourceToCommunity = async function(communityId, resourceId)

/**
 * removeResourceFromCommunity
 * @description: Remove a resource from a community (curation)
 * @args: communityId Community ID
 * @args: resourceId Resource Identifier
 *        { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.removeResourceFromCommunity = async function(communityId, resourceId)

/**
 * addMember
 * @description: Add member to a community
 * @args: communityId Community ID
 * @args: member Member address
 * @args: role Role (1: ADMIN, 2: CURATOR)
 */
KauriClient.prototype.addMember = async function(communityId, member, role)

/**
 * removeMember
 * @description: Remove member from a community
 * @args: communityId Community ID
 * @args: member Member address
 * @args: role Role (1: ADMIN, 2: CURATOR)
 */
KauriClient.prototype.removeMember = async function(communityId, member, role)

/**
 * getArticle
 * @description: Get Article details
 * @args: id Article ID
 * @args: version Article version (optional)
 * @args: published Last published article (optional) (true|false)
 */
KauriClient.prototype.getArticle = async function(id, version, published)

/**
 * searchArticles
 * @description: Search Article
 * @args: filter Article Filter
 *        {"dateCreatedLessThan": "2019-03-21T10:42:04.612Z", "dateCreatedGreaterThan": "2019-03-21T10:42:04.612Z", "idEquals": "c253adf5afb34548b14c4725ebba87e5", "authorIdEquals": "f0f15cedc719b5a55470877b0710d5c7816916b1", "ownerIdEquals": "f0f15cedc719b5a55470877b0710d5c7816916b1", "checkpointEquals": "", "statusIn": ["PUBLISHED", "DRAFT"], "latestVersion": true, "versionIn": [1, 2]}
 * @args: page Page No (default 0)
 * @args: size Page Size (default 20)
 * @args: sort Sorting attribute (default dateCreate)
 * @args: dir Sorting direction (default DESC)
 */
KauriClient.prototype.searchArticles = async function(filter, page, size, sort, dir)

/**
 * submitArticle
 * @description: Submit an article as a DRAFT
 * @args: articleInput
 *        { "content": "the content", "title": "the title", "attributes": {"origin_source": "canonical url", "original_name": "medium"},  "tags": ["tag1"] }
 */
KauriClient.prototype.submitArticle = async function(articleInput)

/**
 * publishArticle
 * @description: Publish a DRAFT
 * @args: id Article ID
 * @args: version Article version
 * @args: signature (see generateArticleSignature)
 * @args: owner Article Owner (individual or community)
 * @args: updateComment Revision message
 */
KauriClient.prototype.publishArticle = async function(id, version, signature, owner, updateComment)

/**
 * submitAndSelfPublishArticle
 * @description: Submit and Publish an article
 * @args: articleInput
 *        { "content": "the content", "title": "the title", "attributes": {"origin_source": "canonical url", "original_name": "medium"},  "tags": ["tag1"] }
 */
KauriClient.prototype.submitAndSelfPublishArticle = async function(articleInput)

/**
 * approveArticle
 * @description: Approve a pending article version
 * @args: id Article ID
 * @args: version Article version
 * @args: signature (see generateArticleSignature)
 */
KauriClient.prototype.approveArticle = async function(id, version, signature)

/**
 * rejectArticle
 * @description: Approve a pending article version
 * @args: id Article ID
 * @args: version Article version
 * @args: cause Cause of the rejection
 */
KauriClient.prototype.rejectArticle = async function(id, version, cause)

/**
 * cancelArticle
 * @description: Delete a DRAFT
 * @args: id Article ID
 * @args: version Article version
 */
KauriClient.prototype.cancelArticle = async function(id, version)

/**
 * generateArticleSignature
 * @description: Generate a cryptoggraphic signature of the article
 * @args: id Article ID
 * @args: version Article version
 * @args: author Articl Author address
 * @args: contentHash Article  IPFS content hash
 * @args: dateCreated Article date Created
 */
KauriClient.prototype.generateArticleSignature = async function(id, version, author, contentHash, dateCreated)

/**
 * searchAutocomplete
 * @description: Make a global search across kauri resources (any type)
 * @args: query Query search
 */
KauriClient.prototype.searchAutocomplete = async function(query)

/**
 * searchTags
 * @description: Suggest tags
 * @args: query Query search
 */
KauriClient.prototype.searchTags = async function(query)

/**
 * searchMoreLikeThis
 * @description: Find related content
 * @args: resourceId Resource Identifier
 *        { "type": "ARTICLE", "id": "123123" }
 */
KauriClient.prototype.searchMoreLikeThis = async function(resourceId)

/**
 * checkpointArticles
 * @description: Initiate the checkpointer to pick-up no-checkpointed articles and checkpoint them
 */
KauriClient.prototype.checkpointArticles = async function()

/**
 * submitCheckpoint
 * @description: Submit a checkpoint to the chain
 * @args: checkpoint Checkpoint hash
 */
KauriClient.prototype.submitCheckpoint = async function(checkpoint)

/**
 * getArticleProof
 * @description: Retrieve an article proof
 * @args: id Article ID
 * @args: version Article version
 */
KauriClient.prototype.getArticleProof = async function(id, version)

/**
 * validateArticleProof
 * @description: Validate a proof
 * @args: id Article ID
 * @args: version Article version
 * @args: contentHash Article IPFS content hash
 * @args: creator Article Author account address
 * @args: timestamp Article date created
 * @args: checkpointRoot Article Checkpoint hash
 * @args: proof Article proof to validate
 */
KauriClient.prototype.validateArticleProof = async function(id, version, contentHash, creator, timestamp, checkpointRoot, proof)

/**
 * upload
 * @description: Upload a file on IPFS
 * @args: filePath file to upload
 */
KauriClient.prototype.upload = async function(filePath)

/**
 * download
 * @description: Download a file from IPFS
 * @args: filePath file to store the result
 */
KauriClient.prototype.download = async function(filePath) {

/**
 * addTemplate
 * @description: Add a template
 * @args: name
 * @args: content
 * @args: criteria
 */
KauriClient.prototype.addTemplate = async function(name, content, criteria)

/**
 * getTemplates
 * @description: Find templates
 * @args: articleContext
 */
KauriClient.prototype.getTemplates = async function(articleContext)

/**
 * getSitemap
 * @description: Get latest sitemap
 */
KauriClient.prototype.getSitemap = async function()

/**
 * generateSitemap
 * @description: Trigger the generation of the sitemap
 */
KauriClient.prototype.generateSitemap = async function()