Code Monkey home page Code Monkey logo

fh-js-sdk's Introduction

FeedHenry JavaScript SDK

Build Status

The JavaScript SDK allows developers to integrate the FeedHenry Cloud into any web-based solution - desktop websites, mobile websites or a stand-alone JavaScript client.

The API is provided in the $fh namespace and uses a common convention for most functions, which takes the format:

$fh.doSomething(parameterObject, successFunction, failureFunction)

Where parameterObject is an ordinary JavaScript object. The successFunction callback is called if the operation was successful and the failureFunction callback is called if the operation fails. All of these arguments are optional. If there is only one function, it is taken as the success function.

The successFunction callback is called with one argument, a result object, which is again an ordinary JavaScript object. The failureFunction callback is called with two arguments: an error code string, and an object containing additional error properties (if any).

Detailed documentation for the JavaScript SDK's API can be found here: http://docs.feedhenry.com/v3/api/app_api

Building

The JS SDK is now built using Browserify.

Development

Because of Browserify, you can write any new functions as normal node modules, and use node's "require" to load any other modules, or to be consumed by other modules.

Testing

Write your tests in test/tests directory. Add the tests to test/browser/suite.js file and run

grunt test

This will use mocha and phatomjs to run the tests.

In fact, if your module and test don't require a browser environment, you can just run them purely in node. (You may need to add a new grunt task to run them).

To help debugging, you can run

grunt local

This will start mock servers locally and you can go to http://localhost:8200/example/index.html page to debug. You may want to run

grunt watch

In another terminal window to auto generate the combined js sdk file.

Testling

For browser compatibility testing, we use Testling. The project page is here: https://ci.testling.com/feedhenry/fh-js-sdk.

You can also run testling locally:

npm install -g testling
testling

If testling can not find any browser locally, you either need to add browser paths to your PATH environment variable, or use

testling -u

and copy the url to a browser.

Build

When finish developing and testing, run

grunt

To generate the release builds.

Updating the AppForms Template App

This process should be changed, however, documenting it here.

Build the js-sdk as above. clone the AppForms-Template repo

git clone [email protected]:feedhenry/AppForms-Template.git

switch to the feedhenry3 branch

git checkout feedhenry3

copy the appForms-backbone file generated in the js-sdk to the AppForms-Template

cp fh-js-sdk/dist/appForms-backbone.js AppForms-Template/client/default/lib/appform-backbone.js

install the node modules in the AppForms-Template

cd AppForms-Template
npm install

and run grunt

grunt

clone the app forms-project-client template app

git clone git://github.com/feedhenry/appforms-project-client.git

copy the resulting lib.min.js to the appforms template

cp AppForms-Template/dist/client/default/lib.min.js appforms-project-client/www/lib.min.js

push the updated changes

git push origin master

Releasing

Our SDK is release on npmjs. To do a release follow those steps:

Prepare release

  • Update package.json, npm-shrinkwrap.json, bower.json file with the new version number.
  • Update CHANGELOG.md with some JIRA link
  • Do a PR, make sure Travis build passed. Merge.
  • Tag the repository with the new version number:
git tag -s -a {VERSION} -m 'version {VERSION}'   // e.g. {VERSION} format is  '2.17.0'
  • Push the new release tag on GitHub:
git push origin {TAG}
  • Travis build will generate a relase for you in release tab.

Publish to npmjs

  • Login to npm as feedhenry or make sure your own login is part of the collaborator list in fh-js-sdk in npmjs.org
npm login
  • Publish:
npm publish

Generate API doc

The documentation is generated from fh-js-sdk.d.ts. The generated doc is comitted in doc/ folder and deployed to gh-pages so that feedhenry.org and portal documentation can pick it up from a published location.

To publish doc, run the command:

npm run doc

Go to gh-pages and see recent commit for the publication.

Sync client development

Sync client development should be done in [fh-sync-js repository] (https://github.com/feedhenry/fh-sync-js)

fh-js-sdk's People

Contributors

aidenkeating avatar alanmoran avatar bleathem avatar camilamacedo86 avatar cianclarke avatar corinnekrych avatar danbev avatar danielpassos avatar danseethaler avatar david-martin avatar davidffrench avatar dberesford avatar deewhyweb avatar edewit avatar evanshortiss avatar grdryn avatar jasonmadigan avatar jcesarmobile avatar jhellar avatar johnfriz avatar keyang avatar lfryc avatar lgriffin avatar lholmquist avatar mmurphy avatar nialldonnellyfh avatar rachael-oregan avatar sedroche avatar witmicko avatar wtrocki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fh-js-sdk's Issues

$fh.sec - Cannot supply a custom Secret

Currently $fh.sec's keygen operation generates a random secret for the key. If I added a backwards compatible patch to allow for a custom secret would it be of use? We need it in an application we're working on.

The tests for the fh.sync.manage are not covering the example scenario with query_param filter

Following the example in the docs:

var dataset_id = 'tasks';

// Configuration options object.
// These override the options passed to init.
var options = {
"sync_frequency": 30 // Sync every 30 seconds for the 'tasks' dataset
};

// Parameters object to be passed to the cloud sync service.
// It will be passed to the dataHandler when listing dataset on the back end.
// If the default MBaaS cloud implementation is used (which uses $fh.db for data handlers), all the valid list options can be used here.
// For example, to list the tasks that are assigned to a user called "Tom", the query params should be
var query_params = {
"eq": {
"assigned": "Tom"
}
};

// Extra params that will be sent to the back-end data handlers.
var meta_data = {};
$fh.sync.manage(dataset_id, options, query_params, meta_data, function(){
console.log('dataset ' + dataset_id + ' is now managed by sync');
});

Ref: https://access.redhat.com/documentation/en-us/red_hat_mobile_application_platform_hosted/3/html-single/client_api/#fh-sync

Code implementation:

syncClient.manage(dataSetId, {"sync_active": false, "has_custom_sync": false}, {}, {}, done);

Remove FeedHenry Params in Query/Body

Hey,

Currently when making a FH.Cloud call the result of FH.getCloudParams is injected to the body/query. This is a highly intrusive behaviour that would be unwanted by people building an API in express since they have to deal with removing these from a query/body.

Placing these in the headers would be much cleaner and it appears we do that. I'll take a look to see why this is not being added to my FH.Cloud call headers, but would we be open to removing or adding a config option to prevent the FH.getCloudParams from being injected into user queries/bodies?

@wei-lee

Error installing via npm and bundling

I installed this module via npm into a project and then I tried to create my vendor bundle like so:

browserify -o www/dist/vendor.js -r fh-js-sdk -r react -r react-redux -r redux

Doing so results in an error like so being generated when browserify tries to package in fh-js-sdk due to the transforms required:

Error: Cannot find module 'browserify-shim' from '/workspaces/fh/my-app/node_modules/fh-js-sdk'

Currently I've found two solutions:

  1. Install browserify-shim in my project
  2. Install browserify-shim inside the node_modules of fh-js-sdk

I would suggest fixing by setting browserify-shim as a dependency or peerDependency of fh-js-sdk. Thoughts?

Client gets null pointer exception when connection tag is disabled

This is related to this PR: #213

When the connection tag is disabled, all the parameters passed to the error callback, including req, are apparently undefined. That PR assumes that req is defined, even though there's an explicit check for req not being there a couple lines above it. Line 86 in initializer.js thus throws a null pointer instead of calling the callback with the appropriate error.

https://github.com/feedhenry/fh-js-sdk/blob/2.23.0/src/modules/initializer.js#L86

$fh.cloud (and $fh.act?) Parsing of Error Responses

I'd like to know if it would be ok to change the way handleError works when called in the event of an AJAX error.

Currently my express application returns a specific response format for all requests, even when I return a 500 error for example. When I return this 500 the SDK smarts kick in and parse it. As I don't conform to the format it expects, the errraw returned to the failure callback is undefined, but I need the errraw to present a useful error message to users.

I'd like to propose changing this line to something like:

errraw = res.error || res.msg || res;

This would mean that if a request doesn't have an error or msg result, such as in my case, it will still be returned to the error callback as a user would expect. I believe this would retain compatibility with previous applications too so it's safe.

Is there a way to use different config files?

For example, we are building an admin app for our services hosted in Feed Henry, and we want to enable the users to toggle between the different environments we have set up on the Feed Henry side of things. So, we have fhconfig-dev.json, fhconfig-stage.json and fhconfig-production.json. Is there any way we can init the fh library using one of those files? And then maybe also have a way to re-init with a different file at runtime? That way the user can pick their environment from a drop down and then view the data from that environment, all dynamically within the same page. Is this possible? If not, can it be added in as a feature?

Add fh cloud is ready event

Hello is it possible to emit 'fhcloudready' event like so:
....
module.exports = {
"boxprefix": "/box/srv/1.1/",
"sdk_version": "2.0.3-alpha",
"config_js": "fhconfig.json",
"INIT_EVENT": "fhinit",
"FH_READY_EVENT":"fhready"
};
....
events.emit(constants.FH_READY_EVENT);
logger.info("fh cloud is ready");
...
That way on you can listen to this like so:
$fh.on('fhready',function(){
console.log('CLOUD IS READY EVENT EMITED');
});

Thanks a lot.

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.