diff --git a/docs/development/deployment-key.md b/docs/development/access-key.md similarity index 70% rename from docs/development/deployment-key.md rename to docs/development/access-key.md index 1d64549..4859b03 100644 --- a/docs/development/deployment-key.md +++ b/docs/development/access-key.md @@ -1,11 +1,11 @@ --- -title: Development - Deployment key +title: Development - Access key --- -Each time when a new project is created the framework will assign a **deployment key** , +Each time when a new project is created the framework will assign a **access key** , which will be used later to compile, test & deploy only functions where code changed from the previous deployment , making blazing fast cloud deployments . -**Generate a Squeezer deployment key** +**Generate a Squeezer access key** `sqz genkey` \ No newline at end of file diff --git a/docs/doc-links.yaml b/docs/doc-links.yaml index 08e6f5c..401a83a 100644 --- a/docs/doc-links.yaml +++ b/docs/doc-links.yaml @@ -6,7 +6,7 @@ Function: /docs/development/function/ Variables: /docs/development/variables/ Yaml: /docs/development/yaml/ - Deployment key: /docs/development/deployment-key/ + Access key: /docs/development/access-key/ Runtime: /docs/development/runtime/ Testing: /docs/development/testing/ Packaging: /docs/development/packaging/ diff --git a/docs/events/http/nodejs.md b/docs/events/http/nodejs.md index 180be73..28280dd 100644 --- a/docs/events/http/nodejs.md +++ b/docs/events/http/nodejs.md @@ -14,9 +14,11 @@ title: Events - Http - Nodejs import event from 'squeezer-event-node'; import vars from './.vars'; -exports.handler = (...args) => event(vars, (req, res) => { - res.send(200, 'hello!'); -}, ...args); +export function handler(...args) { + event(vars, (req, res) => { + res.send(200, 'hello!'); + }, ...args); +} ``` #### req : Object diff --git a/docs/events/schedule/nodejs.md b/docs/events/schedule/nodejs.md index dccbb68..077b7b0 100644 --- a/docs/events/schedule/nodejs.md +++ b/docs/events/schedule/nodejs.md @@ -14,8 +14,10 @@ title: Events - Http - Nodejs import event from 'squeezer-event-node'; import vars from './.vars'; -exports.handler = (...args) => event(vars, (req, res) => { - console.log('triggered by schedule event'); - res.done(); -}, ...args); +export function handler(...args) { + event(vars, (req, res) => { + console.log('triggered by schedule event'); + res.done(); + }, ...args); +} ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index d056e3d..0db8617 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -53,240 +53,312 @@ Configure provider & setup credentials ## Blockchain Connector +Agnostic blockchain connector - +The main scope for adding the connector is to unify all the current blockchains data assets into a single normalized API interface , therefore you can build blockchain apps easily without digging into all blockchain infrastructures -**https://github.com/SqueezerIO/squeezer-blockchain-connector** +Basically the connector is only a client for the Squeezer Blockchain Gateway where actually all the magic happens. -
-
+Check the Squeezer Blockchain Gateway API Documentation: -### Initialize +[Squeezer Blockchain Gateway - Test](https://squeezerblockchaingatewa-squeezerdeploymentbucket-1rzodet1yc0k1.s3.amazonaws.com/swagger-ui/index.html) -``` -const blockchainConnector = require('squeezer-blockchain-connector').init({ - key : 'squeezer-key', - type: 'ETH', - environment: 'test' -}); -``` -Created api-key is used when generate new wallet +[Squeezer Blockchain Gateway - Production (in development)]() -## Using connector + -### Create new Wallet +Table of contents +================= -``` -POST /v1/wallets/CreateWallet -``` +* [Install](#install) +* [ITN ( Instant Transaction Notification )](#itn) +* [Initialize](#init) +* [Wallet types](#walletTypes) +* [Create Wallet](#createWallet) +* [Send transaction](#sendTransaction) +* [Transactions](#transactions) +* [Get balance](#getBalance) +* [Smart contract](#smartContract) -#### Description -Create new wallet address using api-key + +### Install -#### Parameter +`npm install squeezer-blockchain-connector --save` -* accessKey - api-key generated at connector initialization -* currencyType - what type of wallet want +[back to top](#table) -#### Return format + -A JSON object with keystore and address of wallet - -#### Example +### Initialize -Request +You will need a Squeezer access key in order to use the blockchain connector. You can get one [here](https://squeezer.io/docs/development/deployment-key/) +```javascript +const BlockchainConnector = require('squeezer-blockchain-connector'); +const blockchainConnector = new BlockchainConnector(options); ``` -POST /v1/wallets/CreateWallet -``` +- ``options`` ***required*** +- ``options.accessKey`` - ***required*** Squeezer access key +- ``options.environment`` - ***required*** use ``test`` for sandbox or ``live`` for production -Body + -``` -{ - "accessKey": "3fb1cd2cd96c6d5c0b5eb3322d807b34482481d4" -} -``` +## ITN ( Instant Transaction Notification ) +---- +The ITN system will notify your server when you receive a transaction and when a transaction status changes. This is a quick and useful way to integrate blockchain transactions processing. -Response -``` +Please check the ``Squeezer Blockchain Gateway API Documentation``->`` +Configure ITN callback url`` + +ITN JSON object: + +```JSON { - "version": 3, - "id": "f0efc549-88c0-45cf-9991-6ec53ba7ba13", - "address": "7c110b7761b695d4343f6dfe786a49cd5c03e31e", - "crypto": { - "ciphertext": "6ec3946b5ed85d1acd5c2b67289ea05bee0b3095cdf3661469a6d8acc6cf85f5", - "cipherparams": { - "iv": "ea54225d082c7a010467d73b3a309eda" - }, - "cipher": "aes-128-ctr", - "kdf": "scrypt", - "kdfparams": { - "dklen": 32, - "salt": "dfc9c26cda4253852b93c60f7d7099a5b3f127031faf19e2dbf0593a0d3190f8", - "n": 262144, - "r": 8, - "p": 1 - }, - "mac": "ce5c87d1b0d0b2df0fbe4f389806594203fa091be4beaa6bfa6e1a10856d369e" - } + "from": "0xc03f7B9bddF8aeeBCbA2f818E5f873f71b85EB5c", + "to": "0x903f7B9bddF8aeeBCbA2f818E5f873f71b85EB5c", + "amount": "0.99999999", + "type": "in", + "accessKeyHash": "accessKeyHash", + "hash": "0xcf387e8d1a95bd3a5b54269aa0a228...", + "block": "891093", + "status": 1, + "itnStatus": 1, + "createdAt": "2018-05-13 18:09:18", + "updateAt": "2018-05-13 18:09:18" } ``` -### Get balance +NOTE: As a security measure please make sure that you validate `accessKeyHash` is the same at with your default `access key` -``` -POST /v1/wallets/GetBalance -``` +Validate `accessKeyHash` example: -#### Description +```javascript +if (accessKeyHash === crypto.createHmac('SHA256', accessKey).update(accessKey).digest('base64')) { + console.log('valid access key hash') +} else { + console.log('invalid access key hash') +} +``` -Get balance of specified address +[back to top](#table) -#### Parameters + -* walletAddress - wallet's address -* network - if use test environment should be passed network (rinkeby, ropsten, kovan - ETH, bitcoin-testnet -BTC) +## Wallet types -#### Return format -A string with amount of wallet +Get current available blockchain wallet types -#### Example -Request +```javascript +blockchainConnector.walletTypes(callback) ``` -POST /v1/wallets/GetBalance -``` -Body +- ``callback`` - ***required*** callback function, accepts 2 values (``error``,``result``) + +Example request +```javascript +blockchainConnector.walletTypes((err, response) => { + console.log(response) +}); ``` + +Example response from server +```json { - "walletAddress": "0xc1f9e93081e7797ec3ef2134e0e656b2c8d542f1" + "message":"success", + "data":[ + { + "type":"ETH", + "info":"Ethereum wallet." + }, + { + "type":"BTC", + "info":"Bitcoin wallet." + } + ] } ``` -Response -``` -"1.895178899999999998" -``` -### Send transaction +[back to top](#table) + + + +## Create wallet + +Create a new blockchain wallet. + +```javascript +blockchainConnector.createWallet(options, callback) ``` -POST /v1/blockchainlink/SendTransaction +- ``options`` - ***required***. +- ``options.type`` - ***required***. Wallet type (``ETH``). +- ``callback`` - ***required*** callback function, accepts 2 values (``error``,``result``) + +Example request +```javascript +blockchainConnector.createWallet({ + type: 'ETH' +}, (err, response) => { + console.log(response) +}); ``` -#### Description +Example response from server +```json +{ + "walletID": "8193d025-6430-496e-abf3-88f06b51889c", + "address": "0xbd61ef790C3eaf4D0c4D4bE3558F8a501863525f", + "token": "41dbecfb0454183a4c7a9be8b874e1785b5..." +} +``` -Send coins from one wallet to another +NOTE: Squeezer will not store any sensitive data similar to `token`. For later usage please store the wallet details on a secure & safe environment. -#### Parameters -* toWallet - wallet's address -* currencyType - what type of wallet want -* amount - amount of coins -* keyStore - fromWallet's keystore -* accessKey - api-key used to generate wallet -* network - if use test environment should be passed network (rinkeby, ropsten, kovan - ETH and bitcoin-testnet -BTC) +[back to top](#table) -#### Return format + -A JSON object that contain informations about that transaction +## Send transaction -#### Example +Initiate a new blockchain transaction. -Request -``` -POST /v1/wallets/SendTransaction -``` -Body -``` -{ - "toWallet": "0x8a5cf6d5e86ebfe3e1ab573d1eafc299c04c8cf9", - "amount": 0.001, - "keyStore": { - "version": 3, - "id": "0af46c1e-4d02-4f9b-af62-ec358612a3c2", - "address": "c1f9e93081e7797ec3ef2134e0e656b2c8d542f1", - "crypto": { - "ciphertext": "cc3bb088bd53ea45172b0ab5f01c9e28e6b7b3743a589a4437844b9fce922888", - "cipherparams": { - "iv": "55b1aeeffa8ce3ffe24a488e58174c0f" - }, - "cipher": "aes-128-ctr", - "kdf": "scrypt", - "kdfparams": { - "dklen": 32, - "salt": "0c990d41edcf0d8f5541713ef0e2f0629366ffadb8190b0d3a32755488de6877", - "n": 262144, - "r": 8, - "p": 1 - }, - "mac": "4ea78c87318dbe87ac4e109845301d248d4caf25f82882dff1fbaa1fe4b3d70c" - } - }, - "accessKey": "3fb1cd2cd96c6d5c0b5eb3322d807b34482481d4", - "network" : "rinkeby" -} +```javascript +blockchainConnector.sendTransaction(options, callback) ``` -Response +- ``options`` - ***required***. +- ``options.amount`` - ***required***. Amount to send, 8 decimal max. (``0.01``). +- ``options.type`` - ***required***. Transaction type. (``ETH``). +- ``options.to`` - ***required***. Receiver's address +- ``options.token`` - ***required***. Wallet token +- ``callback`` - ***required*** callback function, accepts 2 values (``error``,``result``) + +Example request +```javascript +blockchainConnector.sendTransaction({ + amount: 0.01, + type: 'ETH', + to: '0x207E1a4F3Ab910D2164bC3646CFD0aF697f86713', + token: "41dbecfb04541........" +}, (err, response) => { + console.log(response) +}); ``` + +Example response from server +```json { - "transaction": { - "transaction": "0xad63f8fc7db990058ef3ec6433190cbc5b0e0af670be79c49a70d8e1daacfb29", - "transactionStatus": 0, - "_id": "5ab2b1fd6e578b3ae275e351", - "__v": 0 - } + "hash" : "0x4b9c1358fcbeb5434457355e3e8e44e10ebc6bec02d40c7a28046b1cfef99476" } ``` -### Get transaction -``` -POST /v1/blockchainlink/GetTransaction -``` +[back to top](#table) -#### Description +## Get transactions -Get info about one transaction +Get transactions for a specific wallet + +```javascript +blockchainConnector.getTransactions(options, callback) +``` +- ``options`` - ***required***. +- ``options.walletId`` - ***required***. Wallet ID +- ``callback`` - ***required*** callback function, accepts 2 values (``error``,``result``) + +Example request +```javascript +blockchainConnector.getTransactions({ + walletId: "0dbeb851-b9e7-42e4-a448-71f8520f1ea3", +}, (err, response) => { + console.log(response) +}); +``` -#### Parameters +Example response from server +```json +{ + "message": "success", + "data": [ + { + "from": "0xc03f7B9bddF8aeeBCbA2f818E5f873f71b85EB5c", + "to": "0x903f7B9bddF8aeeBCbA2f818E5f873f71b85EB5c", + "amount": 0.99999999, + "type": "in", + "hash": "0xcf387e8d1a95bd3a5b54269aa0a228f159d3cd33fa9e946617c532c5cb8c77bb", + "block": 891093, + "status": 0, + "itnStatus": 0, + "createdAt": "2018-05-13 18:09:18", + "updateAt": "2018-05-13 18:09:18" + } + ] +} +``` -* transactionHash - transaction hash returned by SendTransaction -* network - if use test environment should be passed network (rinkeby, ropsten, kovan - ETH and bitcoin-testnet -BTC) +[back to top](#table) -#### Return format + -A JSON object that contain informations about transaction +## Get balance -#### Example +Get balance for a specific wallet -Request -``` -POST /v1/wallets/GetTransaction +```javascript +blockchainConnector.getBalance(options, callback) ``` -Body +- ``options`` - ***required***. +- ``options.walletId`` - ***required***. Wallet ID +- ``callback`` - ***required*** callback function, accepts 2 values (``error``,``result``) + +Example request +```javascript +blockchainConnector.getBalance({ + walletId: "0dbeb851-b9e7-42e4-a448-71f8520f1ea3", +}, (err, response) => { + console.log(response) +}); ``` + +Example response from server +```json { - "transactionHash": "0xad63f8fc7db990058ef3ec6433190cbc5b0e0af670be79c49a70d8e1daacfb29", - "currencyType" : "ETH", - "network" : "rinkeby" - new + "message":"success", + "data": { + "balance":0 + } } ``` -Response + +[back to top](#table) + +## Smart contract ( In development feature ) + +Access a smart contract + +```javascript +blockchainConnector.smartContract(options, callback) +``` +- ``options`` - ***required***. +- ``options.address`` - ***required***. Smart contract address. +- ``options.type`` - ***required***. Smart contract type. (``ETH``) +- ``options.abi`` - ***required***. Abi code. +- ``options.methods`` - ***required***. Smart contract methods. +- ``options.token`` - ***required***. Wallet token +- ``callback`` - ***required*** callback function, accepts 2 values (``error``,``result``) + +Example request +```javascript +blockchainConnector.smartContract({ + type: 'ETH', + abi : '', + address: '0x207E1a4F3Ab910D2164bC3646CFD0aF697f86713', + token: '348nagfgf45tgtg....', + methods: [{ + listVotes: ['arg1', 'arg2'], + votesType: ['positive'] + }] +}, (err, response) => { + console.log(response) +}); ``` -{ - "blockHash": "0xb589d75b759436e43381dc30f89a792f6f7bace421bf04f5eb1f2cca7c8e0628", - "blockNumber": 1972693, - "from": "0xc1f9e93081e7797ec3ef2134e0e656b2c8d542f1", - "gas": 21000, - "gasPrice": "1000000000", - "hash": "0xad63f8fc7db990058ef3ec6433190cbc5b0e0af670be79c49a70d8e1daacfb29", - "input": "0x", - "nonce": 11, - "to": "0x8a5cf6d5e86ebfe3e1ab573d1eafc299c04c8cf9", - "transactionIndex": 9, - "value": "1000000000000000", - "v": "0x1b", - "r": "0xf62198309971d6c3725f2f0cddc7eb60da5715fed89b597d4a273322313aebe4", - "s": "0x5b86ac969b259c73d7fccc3dec9f28fdbdc024a8f72c842939baeb198eb9b6b1" -} -``` \ No newline at end of file + +[back to top](#table) \ No newline at end of file diff --git a/lib/common/archiver/index.js b/lib/common/archiver/index.js index f1530ce..f809bab 100644 --- a/lib/common/archiver/index.js +++ b/lib/common/archiver/index.js @@ -17,7 +17,7 @@ class Archiver { * Zips a directory * * @param {string} source - source directory path "/tmp/my-files" - * @param {string} dest - destionation path "/tmp/myfiles.zip" + * @param {string} dest - destination path "/tmp/myfiles.zip" * * @name this.sqz.archive */ diff --git a/lib/common/checksums/lib/data.js b/lib/common/checksums/lib/data.js index 6d04d44..13fa1b2 100644 --- a/lib/common/checksums/lib/data.js +++ b/lib/common/checksums/lib/data.js @@ -35,11 +35,11 @@ class Data { resolve(checksums); } else if (compileType === 'cloud') { - const accessKey = this.getKey(); + const key = this.getKey(); const apiBaseUrl = this.sqz.vars.apiBaseUrl; const endpoint = `${apiBaseUrl}/rest/v1/deployment/${key}`; - if (accessKey) { + if (key) { request.get(endpoint, { json: true }, (error, response, body) => { const statusCode = response.statusCode; diff --git a/lib/plugins/compile/lib/compile.js b/lib/plugins/compile/lib/compile.js index cbb2d70..48554d3 100644 --- a/lib/plugins/compile/lib/compile.js +++ b/lib/plugins/compile/lib/compile.js @@ -57,7 +57,7 @@ class Compile { const projectVars = this.sqz.vars.project.vars; const config = this.sqz.config.data; const projectPath = this.sqz.vars.project.path; - const mainVarsPath = path.join(projectPath, '.build', compileType, '.vars.json'); + const mainVarsPath = path.join(projectPath, '.build', '.vars.json'); let vars = { name: this.sqz.vars.project.name, diff --git a/lib/plugins/deploy/lib/index.js b/lib/plugins/deploy/lib/index.js index 51537f4..6091f40 100644 --- a/lib/plugins/deploy/lib/index.js +++ b/lib/plugins/deploy/lib/index.js @@ -20,7 +20,7 @@ class Deploy { return new Promise((resolve) => { const projectBuildPath = this.sqz.vars.project.buildPath; const projectPath = this.sqz.vars.project.path; - const mainVarsPath = path.join(projectPath, '.build', 'cloud', '.vars.json'); + const mainVarsPath = path.join(projectPath, '.build', '.vars.json'); const vars = JSON.parse(fs.readFileSync(mainVarsPath, 'utf8')); fsExtra.ensureDirSync(path.join(projectBuildPath, 'deploy', 'functions')); diff --git a/lib/plugins/functions/lib/compile/lib/index.js b/lib/plugins/functions/lib/compile/lib/index.js index a849ba5..6e46289 100644 --- a/lib/plugins/functions/lib/compile/lib/index.js +++ b/lib/plugins/functions/lib/compile/lib/index.js @@ -92,7 +92,9 @@ class Compile { if (projectRuntime === 'nodejs') { const packagesData = { license : 'UNLICENSED', - dependencies : {} + dependencies : { + 'source-map-support': '^0.4.18' + } }; _.forEach(treeData.functions[functionObject.name].packages, (obj) => { diff --git a/lib/plugins/key/index.js b/lib/plugins/key/index.js index e6de2bd..5055baa 100644 --- a/lib/plugins/key/index.js +++ b/lib/plugins/key/index.js @@ -7,7 +7,7 @@ class KeyCmd { this.commands = [ { arg : ['genkey'], - summary : 'Will generate a deployment key', + summary : 'Will generate an access key', description : null, lifecycle : [ 'key:get' diff --git a/lib/plugins/key/lib/index.js b/lib/plugins/key/lib/index.js index 458dc46..f1c62d9 100644 --- a/lib/plugins/key/lib/index.js +++ b/lib/plugins/key/lib/index.js @@ -13,7 +13,7 @@ class Key { const apiBaseUrl = this.sqz.vars.apiBaseUrl; const endpoint = `${apiBaseUrl}/rest/v1/deployment/generate/key`; - this.sqz.cli.log.info('Generating a new deployment key'); + this.sqz.cli.log.info('Generating a new deployment access key'); return new Promise((resolve, reject) => { request.get(endpoint, { json: true }, (error, response, body) => { if (!error && response.statusCode === 200 && body.message === 'success') { diff --git a/lib/plugins/templates/lib/samples/api-nodejs/data/services/my-service/hello/src/handler.js b/lib/plugins/templates/lib/samples/api-nodejs/data/services/my-service/hello/src/handler.js index 0cdc3c2..4eb85a7 100644 --- a/lib/plugins/templates/lib/samples/api-nodejs/data/services/my-service/hello/src/handler.js +++ b/lib/plugins/templates/lib/samples/api-nodejs/data/services/my-service/hello/src/handler.js @@ -5,9 +5,11 @@ import fs from 'fs'; const vars = JSON.parse(fs.readFileSync('.vars.json', 'utf8')); -export const handler = (...args) => event(vars, (req, res) => { - res.json(200, { - name : `Your name : ${req.query.name}`, - message: req.body.message || 'hello world !!!' - }); -}, ...args); +export function handler(...args) { + event(vars, (req, res) => { + res.json(200, { + name: `Your name : ${req.query.name}`, + message: req.body.message || 'hello world !!!' + }); + }, ...args); +} diff --git a/lib/plugins/templates/lib/shared/nodejs/package.json b/lib/plugins/templates/lib/shared/nodejs/package.json index c1407d4..fe06e45 100644 --- a/lib/plugins/templates/lib/shared/nodejs/package.json +++ b/lib/plugins/templates/lib/shared/nodejs/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "squeezer-event-node" : "~0.0.4", - "squeezer-serve" : "~0.0.6", + "squeezer-serve" : "~0.0.7", "squeezer-swagger": "~0.0.7" }, "devDependencies": { diff --git a/lib/plugins/templates/lib/shared/nodejs/watcher.yml b/lib/plugins/templates/lib/shared/nodejs/watcher.yml index b573b79..016aada 100644 --- a/lib/plugins/templates/lib/shared/nodejs/watcher.yml +++ b/lib/plugins/templates/lib/shared/nodejs/watcher.yml @@ -3,10 +3,12 @@ globs: include: - - '${projectPath}/services/**' - - '${projectPath}/lib/**' - '${projectPath}/**/*.yml' + - '${projectPath}/**/*.js' + - '${projectPath}/**/*.json' ignore: - '**/node_modules/**' + - '**/.build/**' - '**/.vars.json' - - '**/event.input.json' + - '**/.event.input.json' + - '**/.event.output.json' diff --git a/lib/plugins/test/lib/index.js b/lib/plugins/test/lib/index.js index 87ea098..1340e06 100644 --- a/lib/plugins/test/lib/index.js +++ b/lib/plugins/test/lib/index.js @@ -34,7 +34,7 @@ class Test { return new Promise((resolve) => { if (_.has(options, 'smart')) { - const mainVarsPath = path.join(projectPath, '.build', 'cloud', '.vars.json'); + const mainVarsPath = path.join(projectPath, '.build', '.vars.json'); if (!fs.existsSync(mainVarsPath)) { this.sqz.cli.log.error( diff --git a/package.json b/package.json index 1a6a207..935fcb9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "squeezer-cli", - "version": "1.2.1", + "version": "1.2.5", "preferGlobal": true, "description": "Event-driven APIs & Web apps on functions, serverless ! Squeezer is a framework designed to help developers to get a better architecture on serverless zero-administration compute platforms with code that runs into cloud functions like [AWS Lambda](https://aws.amazon.com/documentation/lambda/) , [Azure Functions](https://azure.microsoft.com/en-us/services/functions/) , [Google Cloud Functions](https://cloud.google.com/functions/docs/) and [IBM OpenWhisk](https://developer.ibm.com/openwhisk/) .", "homepage": "https://squeezer.io/",