Git Product home page Git Product logo

kido-custom-script's Introduction

#KidoZen Custom Script These set of utilities are designed to help customers to develop custom scripts which will run on Kidozen's platform.

##Requirements You will need version 0.10.33 or greater of Node.js installed in your system. You can download it here.

##Installation You can install this module dependencies from npm (by executing npm install in your terminal)

##Files Description Each file has a specific purpose:

  • api.js: This is the exposed API for invoking Kidozen Services from inside the custom script. This file is not intended to be edited.
  • run.js: This is another sample file which will run your custom script and will print the result on stdout. You can run it with node run.js. This file is not intended to be edited.
  • config.json.sample: This is the config file sample. Copy this file with the name 'config.json' and complete it with the Tenant, application and security's configuration details.
  • user.js: User Profile Mock. An array of user claims which will be passed to the custom scripts. This mock represents the user which is invoking the custom script.
  • script.js: Here you can write your custom script.
  • test.js: This is a sample file with mocha unit tests. The code here can be executed with the mocha test runner

##Setting up Create a file named config.json (you can use the config.json.sample as a template).

{
    "tenant": <TENANT NAME>,
    "clientID": <APPLICATION CLIENT ID>,
    "clientSecret": <APPLICATION CLIENT SECRET>,
    "app": <APPLICATION NAME>,
    "url": <APPLICATION URL>
}

For example a config file for the tenant "kidodemo" and the application "tasks" is as follows:

{
    "tenant": "kidodemo",
    "clientID": "a41468c9-3e6d-4c6f-baef-b040cc024f98",
    "clientSecret": "86BE9511AhJzCGM7w1J6m+cBeq8jH7oA2SvyWqQqFE7=",
    "app": "tasks",
    "url": "https://tasks-kidodemo.kidocloud.com"
}

##Sample Scripts

Validation Sample:

function userCustomFunction (api, params, user) {
    if (!params)
        return api.reject("missing required params");
    if (!params.name)
        return api.reject("missing required name parameter");
    if (params.name.length > 25)
        return api.reject("name is too long");

    api.resolve("The name param is: " + params.name);
}

Agregating from two Data Access APIs (datasources)

function userCustomFunction (api, params, user) {
    return api.invoke({path: "/api/v2/datasources/GetCityForecastByZIP-33431-Cloud"})
    .then(function (data1) {
        return return api.invoke({path: "/api/v2/datasources/GetCityForecastByZIP-33033-Cloud"})
        .then(function (data2) {
            return { data1: data1, data2: data2 };
        });
    });
}

Invoking an Operation Data Access API with parameters

function userCustomFunction (api, params, user) {
    return api.invoke({path: "/api/v2/datasources/GetCityForecastByZIP-Cloud",
        method: "POST", data: {zip: params.zip}})
    .then(function (data) {
        return { data: data };
    });
}

Invoking a query Data Access API passing a parameter

function userCustomFunction (api, params, user) {
    return api.invoke({path: "/api/v2/datasources/GetCityForecastByZIP-Cloud?zip=" + params.zip})
    .then(function (data) {
        return { data: data };
    });
}

Invoking a Storage Core API

function userCustomFunction (api, params, user) {
    return api.invoke({path: "/storage/local"}).then(function (data) {
        return { data: data };
    });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.