diff --git a/packages/koa/contracts/public-contract.json b/packages/koa/contracts/public-contract.json new file mode 100644 index 0000000000000000000000000000000000000000..08cb6fad7c0bda4692d3106a70344581c0e25438 --- /dev/null +++ b/packages/koa/contracts/public-contract.json @@ -0,0 +1,192 @@ +{ + "query": { + "helloWorld": { + "params": [], + "returns": [ + { + "type": "string", + "description": "stock message" + } + ] + }, + "causeError": { + "params": [ + { + "type": [ + "any" + ], + "name": "x", + "description": "param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "unknown" + } + ] + }, + "getUser": { + "params": [ + { + "type": [ + "string" + ], + "name": "args", + "variable": true, + "description": "passing unknown number of param" + } + ], + "returns": [ + { + "type": [ + "any" + ], + "description": "extract from last of the args" + } + ] + }, + "getSecretMsg": { + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a secret message" + } + ] + }, + "alwaysAvailable": { + "public": true, + "params": [], + "returns": [ + { + "type": [ + "string" + ], + "description": "a message" + } + ] + }, + "testList": { + "params": [ + { + "type": [ + "number" + ], + "name": "num", + "description": "a number" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "@TODO need to figure out how to give keys to the returns" + } + ] + } + }, + "mutation": { + "updateList": { + "params": [ + { + "type": [ + "object" + ], + "name": "payload", + "keys": [ + { + "type": [ + "number" + ], + "name": "user", + "parent": "payload" + } + ] + }, + { + "type": [ + "object" + ], + "name": "condition" + } + ], + "returns": [ + { + "type": [ + "object" + ], + "description": "with user as key" + } + ] + } + }, + "auth": { + "login": { + "params": [ + { + "type": [ + "string" + ], + "name": "username", + "description": "user name" + }, + { + "type": [ + "string" + ], + "name": "password", + "description": "password" + } + ], + "returns": [ + { + "type": [ + "string", + "boolean" + ], + "description": "token on success, false on fail" + } + ] + }, + "logout": { + "params": [], + "returns": [ + { + "type": [ + "boolean" + ], + "description": "just return something" + } + ] + } + }, + "timestamp": 1573116438, + "socket": { + "callSub": { + "namespace": "jsonql/private", + "params": [ + { + "type": [ + "string" + ], + "name": "msg", + "description": "a message" + } + ], + "returns": [ + { + "type": [ + "string" + ], + "description": "a reply from the sub" + } + ] + } + } +} diff --git a/packages/koa/package.json b/packages/koa/package.json index f396fd2f2b2a735b703c1382696940183674a5ec..2acf5c68293c1522fd9ebe3a5ce7856ef04baf73 100644 --- a/packages/koa/package.json +++ b/packages/koa/package.json @@ -57,7 +57,7 @@ "tests/*.test.js", "!tests/helpers/*.*", "!tests/fixtures/*.*", - "!tests/node-client.test.js" + "!tests/node-client.test.xyz.js" ], "require": [ "esm" @@ -77,7 +77,7 @@ "jsonql-contract": "^1.8.4", "jsonql-errors": "^1.1.5", "jsonql-jwt": "^1.3.3", - "jsonql-node-client": "^1.2.0", + "jsonql-node-client": "^1.2.1", "jsonql-params-validator": "^1.4.11", "jsonql-resolver": "^0.9.4", "jsonql-utils": "^0.8.3", diff --git a/packages/koa/tests/jwt-auth.test.js b/packages/koa/tests/jwt-auth.test.js index 82919bd1269b6ce21a8c7e131ae7ad8a413ad953..1525cc8b5406bd00212bf15d6585b01f4f0ed051 100644 --- a/packages/koa/tests/jwt-auth.test.js +++ b/packages/koa/tests/jwt-auth.test.js @@ -13,7 +13,7 @@ const debug = require('debug')('jsonql-koa:test:jwt'); const { type, headers, dirs, dummy } = require('./fixtures/options'); const createServer = require('./helpers/server') -const dir = 'jwt'; +const dir = 'jwt-auth'; const keysDir = join(__dirname, 'fixtures', 'keys') const { createTokenValidator, loginResultToJwt } = require('jsonql-jwt') @@ -38,7 +38,7 @@ test.before( t => { test.after(t => { - fsx.removeSync(join(__dirname, 'fixtures', 'tmp', 'jwt')) + fsx.removeSync(join(__dirname, 'fixtures', 'tmp', dir)) // fsx.removeSync(join(__dirname, 'fixtures', 'tmp', '')) }) diff --git a/packages/node-client/package.json b/packages/node-client/package.json index 2cc0f046c900a9e5fb8167c89a9f32b381209056..1a049a72d612a8bad01cd6f6ae5080e9b017929d 100755 --- a/packages/node-client/package.json +++ b/packages/node-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-node-client", - "version": "1.2.1", + "version": "1.2.2", "description": "jsonql node.js client", "main": "index.js", "scripts": { diff --git a/packages/node-client/src/generator.js b/packages/node-client/src/generator.js index 596c362ac069c67e9909722a6259c76e88610097..516b7aba0e2fa659b397b46a7d94e2432ec6eb9e 100755 --- a/packages/node-client/src/generator.js +++ b/packages/node-client/src/generator.js @@ -108,15 +108,15 @@ function generator(jsonqlInstance, config, contract) { jsonqlInstance.logoutCallback() } } - // the eventEmitter getter - obj.eventEmitter = () => jsonqlInstance.eventEmitter // we have to make this into a function if I want to // need to create a getter method for it otherwise // it's straight through pass to the instance property obj.userdata = () => jsonqlInstance.userdata; } + // the eventEmitter getter - it should not be inside the auth! + obj.eventEmitter = () => jsonqlInstance.eventEmitter // store this once again and export it - obj.jsonqlClientInstance = jsonqlInstance; + obj.getJsonqlInstance = () => jsonqlInstance; // output return obj; }