Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openwhisk

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openwhisk - npm Package Compare versions

Comparing version 3.3.5 to 3.4.0

16

lib/actions.js

@@ -11,2 +11,3 @@ 'use strict'

this.identifiers.push('actionName')
this.qs_options.invoke = ['blocking']
}

@@ -23,4 +24,5 @@

options = options || {}
options.qs = this.qs(options, ['blocking'])
options.body = this.payload(options)
if (options.blocking && options.result) {
return super.invoke(options).then(result => result.response.result)
}

@@ -42,4 +44,6 @@ return super.invoke(options)

const body = { exec: { kind: 'nodejs:default', code: options.action } }
if (options.action instanceof Buffer) {
options.action = options.action.toString('base64')
body.exec.code = options.action.toString('base64')
} else if (typeof options.action === 'object') {

@@ -49,3 +53,7 @@ return options.action

return { exec: { kind: 'nodejs:default', code: options.action } }
if (typeof options.params === 'object') {
body.parameters = Object.keys(options.params).map(key => ({ key, value: options.params[key] }))
}
return body
}

@@ -52,0 +60,0 @@ }

@@ -113,4 +113,9 @@ 'use strict'

return error.error
} else if (error.response && error.response.result && typeof error.response.result.error === 'string') {
return error.response.result.error
} else if (error.response && error.response.result) {
const result = error.response.result
if (typeof result.error === 'string') {
return result.error
} else if (typeof result.statusCode === 'number') {
return `application error, status code: ${result.statusCode}`
}
}

@@ -117,0 +122,0 @@

@@ -10,2 +10,3 @@ 'use strict'

this.identifiers = ['name']
this.qs_options = {}
}

@@ -22,2 +23,7 @@

invoke (options) {
options = options || {}
if (typeof options === 'object' && !Array.isArray(options)) {
options.qs = this.qs(options, this.qs_options.invoke || [])
options.body = this.payload(options)
}
return this.operation_with_id('POST', options)

@@ -24,0 +30,0 @@ }

@@ -48,3 +48,3 @@ 'use strict'

options = options || {}
options.body = { status: 'active' }
options.params = { status: 'active' }
return super.invoke(options)

@@ -55,3 +55,3 @@ }

options = options || {}
options.body = { status: 'inactive' }
options.params = { status: 'inactive' }
return super.invoke(options)

@@ -58,0 +58,0 @@ }

@@ -19,9 +19,2 @@ 'use strict'

invoke (options) {
options = options || {}
options.body = this.payload(options)
return super.invoke(options)
}
create (options) {

@@ -28,0 +21,0 @@ options.qs = this.qs(options, ['overwrite'])

{
"name": "openwhisk",
"version": "3.3.5",
"version": "3.4.0",
"description": "JavaScript client library for the OpenWhisk platform",

@@ -5,0 +5,0 @@ "main": "lib/main.js",

@@ -90,6 +90,6 @@ # openwhisk-client-js

const name = 'reverseWords'
const blocking = true
const blocking = true, result = true
const params = {msg: 'this is some words to reverse'}
ow.actions.invoke({name, blocking, params}).then(result => {
ow.actions.invoke({name, blocking, result, params}).then(result => {
console.log('here's the reversed string', result.reversed)

@@ -211,4 +211,4 @@ }).catch(err => {

- `namespace` from method parameter options OR
- `namespace` from options passed into client constructor OR
- `namespace` from environment variable (`__OW_NAMESPACE`) OR
- `namespace` from options passed into client constructor OR
- `namespace` from environment variable (`__OW_NAMESPACE`) OR
- default namespace: `_`

@@ -300,2 +300,3 @@

- `blocking` - delay returning until action has finished executing (default: `false`)
- `result` - return function result (`obj.response.result`) rather than entire API result (default: `false`)
- `params` - JSON object containing parameters for the action being invoked (default: `{}`)

@@ -330,10 +331,4 @@ - `namespace` - set custom namespace for endpoint

- `namespace` - set custom namespace for endpoint
- `params` - object containing default parameters for the action (default: `{}`)
This method also supports passing the `name` property directly without wrapping within an object.
```
const name = "actionName"
ow.actions.create(name)
```
If you pass in an array for the first parameter, the `create` call will be executed for each array item. The function returns a Promise which resolves with the results when all operations have finished.

@@ -463,1 +458,19 @@

- `basepath` - base URI path for endpoints (default: `/`)
## Development
### unit tests
```
npm test
```
### integration tests
*Please [see the instructions](https://github.com/openwhisk/openwhisk-client-js/tree/master/test/integration) for setting up the integration test environment prior to running these tests.*
```
npm run-script test-integration
```

@@ -101,2 +101,27 @@ 'use strict'

test('create, get and delete with parameters an action', t => {
const params = {api: API_URL, api_key: API_KEY, namespace: NAMESPACE}
const errors = err => {
console.log(err)
t.fail()
}
const actions = new Actions(new Client(params))
return actions.create({name: 'random_action_params_test', params: { hello: 'world' }, action: 'function main() {return {payload:"testing"}}'}).then(result => {
t.is(result.name, 'random_action_params_test')
t.is(result.namespace, NAMESPACE)
t.deepEqual(result.parameters, [{key: 'hello', value: 'world'}])
t.is(result.exec.kind, 'nodejs:6')
t.is(result.exec.code, 'function main() {return {payload:"testing"}}')
return actions.update({actionName: 'random_action_params_test', params: { foo: 'bar' }, action: 'update test'}).then(update_result => {
t.is(update_result.name, 'random_action_params_test')
t.is(update_result.namespace, NAMESPACE)
t.deepEqual(update_result.parameters, [{key: 'foo', value: 'bar'}])
t.pass()
return actions.delete({name: 'random_action_params_test'}).catch(errors)
}).catch(errors)
}).catch(errors)
})
test('invoke action with fully-qualified name', t => {

@@ -103,0 +128,0 @@ const params = {api: API_URL, api_key: API_KEY, namespace: NAMESPACE}

@@ -23,3 +23,2 @@ 'use strict'

t.plan(3)
const ns = '_'
const client = {}

@@ -51,2 +50,16 @@ const actions = new Actions(client)

test('should retrieve action from string identifier', t => {
t.plan(2)
const ns = '_'
const client = {}
const actions = new Actions(client)
client.request = (method, path, options) => {
t.is(method, 'GET')
t.is(path, `namespaces/${ns}/actions/12345`)
}
return actions.get('12345')
})
test('should delete action from identifier', t => {

@@ -80,2 +93,16 @@ t.plan(2)

test('should delete action from string identifier', t => {
t.plan(2)
const ns = '_'
const client = {}
const actions = new Actions(client)
client.request = (method, path, options) => {
t.is(method, 'DELETE')
t.is(path, `namespaces/${ns}/actions/12345`)
}
return actions.delete('12345')
})
test('should invoke action', t => {

@@ -97,5 +124,18 @@ t.plan(4)

test('should invoke action from string identifier', t => {
t.plan(2)
const ns = '_'
const client = {}
const actions = new Actions(client)
client.request = (method, path, options) => {
t.is(method, 'POST')
t.is(path, `namespaces/${ns}/actions/12345`)
}
return actions.invoke('12345')
})
test('should invoke fully qualified action', t => {
t.plan(4)
const ns = '_'
const client = {}

@@ -116,3 +156,2 @@ const actions = new Actions(client)

t.plan(4)
const ns = '_'
const client = {}

@@ -147,2 +186,40 @@ const actions = new Actions(client)

test('should invoke action to retrieve result', t => {
t.plan(4)
const ns = '_'
const client = {}
const actions = new Actions(client)
const result = { hello: 'world' }
client.request = (method, path, options) => {
t.is(method, 'POST')
t.is(path, `namespaces/${ns}/actions/12345`)
t.deepEqual(options.qs, {blocking: true})
return Promise.resolve({response: { result }})
}
return actions.invoke({name: '12345', result: true, blocking: true}).then(_result => {
t.deepEqual(_result, result)
})
})
test('should invoke action to retrieve result without blocking', t => {
t.plan(4)
const ns = '_'
const client = {}
const actions = new Actions(client)
const result = { hello: 'world' }
client.request = (method, path, options) => {
t.is(method, 'POST')
t.is(path, `namespaces/${ns}/actions/12345`)
t.deepEqual(options.qs, {})
return Promise.resolve({response: { result }})
}
return actions.invoke({name: '12345', result: true}).then(_result => {
t.deepEqual(_result, {response: { result } })
})
})
test('should invoke blocking action using actionName', t => {

@@ -216,2 +293,24 @@ t.plan(4)

test('create a new action with default parameters', t => {
t.plan(4)
const ns = '_'
const client = {}
const action = 'function main() { // main function body};'
const params = {
foo: 'bar'
}
const actions = new Actions(client)
client.request = (method, path, options) => {
t.is(method, 'PUT')
t.is(path, `namespaces/${ns}/actions/12345`)
t.deepEqual(options.qs, {})
t.deepEqual(options.body, {exec: {kind: 'nodejs:default', code: action}, parameters: [
{ key: 'foo', value: 'bar' }
]})
}
return actions.create({name: '12345', action, params})
})
test('create an action without providing an action body', t => {

@@ -218,0 +317,0 @@ const actions = new Actions()

@@ -112,4 +112,6 @@ 'use strict'

t.throws(() => client.handle_errors({statusCode: 500, error: {response: {result: {error: 'custom'}}}}), /custom/)
t.throws(() => client.handle_errors({statusCode: 500, error: {response: {result: {statusCode: 404}}}}), /404/)
t.throws(() => client.handle_errors({statusCode: 502, error: {}}), /Action invocation failed/)
t.throws(() => client.handle_errors({statusCode: 500, error: {response: {result: {error: 'custom'}}}}), /custom/)
t.throws(() => client.handle_errors({statusCode: 502, error: {response: {result: {error: 'custom'}}}}), /custom/)
t.throws(() => client.handle_errors({statusCode: 502, error: {response: {result: {statusCode: 404}}}}), /404/)
})

@@ -116,0 +118,0 @@

@@ -120,7 +120,7 @@ 'use strict'

apidoc: {
namespace: 'global_ns',
namespace: '_',
gatewayBasePath: '/',
gatewayPath: '/hello',
gatewayMethod: 'GET',
id: 'API:global_ns:/',
id: 'API:_:/',
action: {

@@ -261,7 +261,7 @@ name: 'helloAction',

apidoc: {
namespace: 'global',
namespace: '_',
gatewayBasePath: '/',
gatewayPath: '/hello',
gatewayMethod: 'GET',
id: 'API:global:/',
id: 'API:_:/',
action: {

@@ -268,0 +268,0 @@ name: 'helloAction',

@@ -63,2 +63,16 @@ 'use strict'

test('should retrieve rule from string identifier', t => {
t.plan(2)
const ns = '_'
const client = { options: {} }
const rules = new Rules(client)
client.request = (method, path, options) => {
t.is(method, 'GET')
t.is(path, `namespaces/${ns}/rules/12345`)
}
return rules.get('12345')
})
test('should delete rule from identifier', t => {

@@ -78,2 +92,16 @@ t.plan(2)

test('should delete rule from string identifier', t => {
t.plan(2)
const ns = '_'
const client = { options: {} }
const rules = new Rules(client)
client.request = (method, path, options) => {
t.is(method, 'DELETE')
t.is(path, `namespaces/${ns}/rules/12345`)
}
return rules.delete('12345')
})
test('should throw error trying to invoke rule', t => {

@@ -80,0 +108,0 @@ const rules = new Rules()

@@ -50,2 +50,16 @@ 'use strict'

test('should retrieve trigger from string identifier', t => {
t.plan(2)
const ns = '_'
const client = {}
const triggers = new Triggers(client)
client.request = (method, path, options) => {
t.is(method, 'GET')
t.is(path, `namespaces/${ns}/triggers/12345`)
}
return triggers.get('12345')
})
test('should delete trigger from identifier', t => {

@@ -65,2 +79,16 @@ t.plan(2)

test('should delete trigger from string identifier', t => {
t.plan(2)
const ns = '_'
const client = {}
const triggers = new Triggers(client)
client.request = (method, path, options) => {
t.is(method, 'DELETE')
t.is(path, `namespaces/${ns}/triggers/12345`)
}
return triggers.delete('12345')
})
test('should retrieve triggerName from identifier', t => {

@@ -95,2 +123,16 @@ t.plan(2)

test('should invoke trigger from string identifier', t => {
t.plan(2)
const ns = '_'
const client = {}
const triggers = new Triggers(client)
client.request = (method, path, options) => {
t.is(method, 'POST')
t.is(path, `namespaces/${ns}/triggers/12345`)
}
return triggers.invoke('12345')
})
test('should invoke fully qualified trigger', t => {

@@ -97,0 +139,0 @@ t.plan(3)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc