kinvey-backend-sdk
Advanced tools
Comparing version 0.0.0 to 0.1.0
## Changelog | ||
### 0.1.0 | ||
* Initial Release |
{ | ||
"name": "kinvey-backend-sdk", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "Backend SDK", | ||
@@ -10,6 +10,6 @@ "engines": { | ||
"coffee-script": "1.7.1", | ||
"request": "2.55.0", | ||
"moment": "*", | ||
"bson":"*", | ||
"code-task-runner": "git+ssh://git@github.com:Kinvey/kinvey-task-receiver.git" | ||
"request": "2.44.0", | ||
"moment": "2.10.6", | ||
"bson":"0.4.11", | ||
"kinvey-code-task-runner": "0.0.5" | ||
}, | ||
@@ -19,8 +19,25 @@ "devDependencies": { | ||
"should": "3.3.2", | ||
"coffeelint": "1.8.1" | ||
"coffeelint": "1.8.1", | ||
"proxyquire": "1.0.1", | ||
"sinon": "1.10.3" | ||
}, | ||
"scripts": { | ||
"pretest": "./node_modules/.bin/coffeelint --file ./coffeelint.json lib test", | ||
"test": "mocha test/lib/*" | ||
"test": "mocha test/lib/modules/* test/lib/*", | ||
"test-core": "mocha test/lib/*", | ||
"test-sdk": "mocha test/lib/sdk.test.coffee", | ||
"test-datalink": "mocha test/lib/dataLink.test.coffee", | ||
"test-businesslogic": "mocha test/lib/businessLogic.test.coffee", | ||
"test-moduleGenerator": "mocha test/lib/moduleGenerator.test.coffee", | ||
"test-modules": "mocha test/lib/modules/*", | ||
"test-backendcontext": "mocha test/lib/modules/backendContext.test.coffee", | ||
"test-email": "mocha test/lib/modules/email.test.coffee", | ||
"test-entity": "mocha test/lib/modules/entity.test.coffee", | ||
"test-kinveydate": "mocha test/lib/modules/kinveyDate.test.coffee", | ||
"test-logger": "mocha test/lib/modules/logger.test.coffee", | ||
"test-push": "mocha test/lib/modules/push.test.coffee", | ||
"test-requestcontext": "mocha test/lib/modules/requestContext.test.coffee", | ||
"test-tempobjectstore": "mocha test/lib/modules/tempObjectStore.test.coffee", | ||
"test-validation": "mocha test/lib/modules/validation.test.coffee" | ||
} | ||
} |
198
README.md
@@ -1,3 +0,197 @@ | ||
# Kinvey Backend SDK | ||
# Kinvey Backend SDK (beta) | ||
This is the SDK for Backend code execution for hosted DLCs and Logic tasks. | ||
This is the SDK for Backend code execution for kinvey-hosted Data Link Connectors and Logic tasks. The module provides a framework for building kinvey-backed Data Link Connectors easily. | ||
This module provides an easy way to connect to a Kinvey Business Logic (BL) instance running on docker. It is up to the user to download, configure and start the docker image itself before running code using this module. Two [utility](#Utilities) functions are provided to automate setting up the docker image. | ||
## Installation | ||
To install this project, add it to your `package.json` file and install it via `npm` | ||
``` | ||
npm install kinvey-backend-sdk | ||
``` | ||
To use this module, require it in your project and | ||
``` | ||
var sdk = require('kinvey-backend-sdk'); | ||
``` | ||
## DataLink framework | ||
The DataLink framework can be accessed via the sdk's `dataLink` property. | ||
``` | ||
var dataLink = sdk.dataLink; | ||
``` | ||
## Registering collections | ||
The backend SDK works by defining collections, and then wiring up data access event handlers to those collections. To register a collection, use the `collection` method of the `dataLink` framework: | ||
``` | ||
// To register the 'widgets' collection: | ||
var widgets = sdk.dataLink.collection('widgets'); | ||
``` | ||
## Data Events | ||
Each collection object exposes data events that are invoked when the corresponding Kinvey collection endpoing is invoked. The data event takes a single handler function to be executed. | ||
| event | description | | ||
| --------- | ----------- | | ||
| onInsert | executed on collection inserts (or POST to REST API) | | ||
| onUpdate | executed on collection updates (or PUT to the REST API) | | ||
| onDeleteById | executed when a single entity is to be deleted | | ||
| onDeleteByQuery | executed when a query is included as part of a DELETE | | ||
| onDeleteAll | executed when the DELETE command is invoked on a collection | | ||
| onGetById | get a single entity by Id | | ||
| onGetByQuery | retrieve results based on a query | | ||
| onGetAll | get all entities in a given collection | | ||
| onGetCount | get the count of the entities in a collection | | ||
| onGetCountByQuery | get the count of the entities in a query result | | ||
For example, to get all entities in the `widgets` collection: | ||
``` | ||
widgets.onGetAll(callbackFunction); | ||
``` | ||
## Data Handler Functions | ||
The data events take a handler funciton, which takes two arguments: `request` and `complete`. `request` represents the request made to Kinvey, and `complete` is a completion handler for ending BL. | ||
### request object | ||
The request object contains the following properties | ||
| property | description | | ||
| --------- | ----------- | | ||
| method | the HTTP method (GET, POST, PUT, DELETE) | | ||
| headers | the HTTP request headers | | ||
| entityId | executed when the DELETE command is invoked on a collection | | ||
| collectionName | the name of the collection | | ||
| body | the HTTP body | | ||
| query | the query object | | ||
### Completion Handler | ||
The completion handlers object follows a builder pattern for creating the datalink's response. The pattern for the completion handler is `complete(<entity>).<status>.<done|next>` | ||
For example, a sample completion handler is: | ||
``` | ||
complete(myEntity).ok.next() | ||
``` | ||
#### complete | ||
The `complete` handler takes either an entity, an array of entities, or an error description. The result of the `complete` handler is an object of status functions. | ||
``` | ||
// Sets the response to include an entity. | ||
complete({"foo", "bar"}); | ||
// Sets the response to include an array of entities | ||
complete([{"foo":"bar"}, {"abc":"123}]); | ||
// Sets the response to an error string, to be used with error status codes | ||
complete("Record 123 was not found"); | ||
``` | ||
### status functions | ||
Status functions set the valid status codes for a Data Link Connector. The status function also sets the body to a Kinvey-formatted error, and uses the value passed into the `complete` function as the debug property, if it is present. | ||
The available status functions are: | ||
| Function | Status Code | Description | | ||
| --------- | ----------- |------------| | ||
| ok | 200 | Used for a normal success response | | ||
| created | 201 | Used for creating new records | | ||
| accepted | 202 | Used when the request has been submitted for processing, but will be processed asynchronously | | ||
| notFound | 404 | Used when the entity or entities could not be found | | ||
| badRequest | 400 | Used when the request is invalid | | ||
| unauthorized | 401 | Used when the request has not been authorized for the given user context | | ||
| forbidden | 403 | Used when the specific request is forbidden for some reason | | ||
| notAllowed | 405 | Used when the specific request or request method is not allowed | | ||
| notImplemented | 501 | Used when the specific handler has no implementation | | ||
| runtimeError | 550 | Used for custom runtime errors | | ||
For example: | ||
``` | ||
// Return that the record has been created | ||
complete(myRecord).created(); | ||
// Entity wasn't found | ||
complete("The given entity wasn't found").notFound(); | ||
``` | ||
### End processing | ||
Once the status is set, you can end the processing of the dataLink request with either `done` or `next`. Most requests should normally end with `next`, which will continue the Kinvey request pipeline with Business Logic. `done` will return the response that was set in the DataLink, and end request processing without executing any further business logic. | ||
``` | ||
// This will continue the request chain | ||
complete(myEntity).ok().next(); | ||
// This will end the request chain with no further processing | ||
complete(myEntity).ok().done(); | ||
``` | ||
## Example | ||
The following is an examp | ||
``` | ||
var sdk = require('kinvey-backend-sdk'); | ||
var dataLink = sdk.dataLink; // gets the datalink object from the SDK | ||
var notImplementedHandler = function(request, complete) { | ||
complete("These methods are not implemented").notImplemented().done(); | ||
}; | ||
var getRecordById = function(request, complete) { | ||
var entityId = request.entityId; | ||
var entity; | ||
// Do some logic to get the entity id from the remote data store | ||
// Assume that data is retrieved and stored in "entity" variable | ||
// After entity is retrieved, check to see if it exists | ||
if (typeof entity === 'undefined' or entity === null or entity = {}) { | ||
return complete("The entity could not be found").notFound().next(); | ||
} else { | ||
// return the entity | ||
return complete(entity).ok().next(); | ||
} | ||
} | ||
// set the collection | ||
var widgets = dataLink.collection('widgets'); | ||
// wire up the event that we want to process | ||
widgets.onGetById(getRecordById); | ||
// wire up the events that we are not implementing | ||
widgets.onGetByQuery(notImplementedHandler); | ||
widgets.onGetAll(notImplementedHandler); | ||
widgets.onGetCount(notImplementedHandler); | ||
widgets.onInsert(notImplementedHandler); | ||
widgets.onUpdate(notImplementedHandler); | ||
widgets.onDeleteAll(notImplementedHandler); | ||
widgets.onDeleteByQuery(notImplementedHandler); | ||
widgets.onDeleteById(notImplementedHandler); | ||
``` | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
197287
35
1
198
0
5
+ Addedasync@0.9.0(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedcaseless@0.6.0(transitive)
+ Addedconfig@0.4.36(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.1.1(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedkinvey-code-task-runner@0.0.5(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmime-types@1.0.2(transitive)
+ Addedmoment@2.10.6(transitive)
+ Addedoauth-sign@0.4.0(transitive)
+ Addedqs@1.2.2(transitive)
+ Addedrequest@2.44.0(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedtldts@6.1.74(transitive)
+ Addedtldts-core@6.1.74(transitive)
- Removedcode-task-runner@git+ssh://git@github.com:Kinvey/kinvey-task-receiver.git
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedasync@0.9.2(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedboom@2.10.1(transitive)
- Removedbson@6.10.1(transitive)
- Removedcaseless@0.9.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@0.2.0(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedhar-validator@1.8.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhawk@2.3.1(transitive)
- Removedhoek@2.16.3(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
- Removedmoment@2.30.1(transitive)
- Removedoauth-sign@0.6.0(transitive)
- Removedqs@2.4.2(transitive)
- Removedrequest@2.55.0(transitive)
- Removedsntp@1.0.9(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtldts@6.1.73(transitive)
- Removedtldts-core@6.1.73(transitive)
- Removedxtend@4.0.2(transitive)
Updatedbson@0.4.11
Updatedmoment@2.10.6
Updatedrequest@2.44.0