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

openwhisk

Package Overview
Dependencies
Maintainers
3
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.9.0 to 3.10.0

48

lib/client.js

@@ -8,6 +8,52 @@ // Licensed to the Apache Software Foundation (ASF) under one or more contributor

const OpenWhiskError = require('./openwhisk_error')
const rp = require('request-promise')
const needle = require('needle')
const url = require('url')
const http = require('http')
/**
* This implements a request-promise-like facade over the needle
* library. There are two gaps between needle and rp that need to be
* bridged: 1) convert `qs` into a query string; and 2) convert
* needle's non-excepting >=400 statusCode responses into exceptions
*
*/
const rp = opts => {
if (opts.qs) {
// we turn the qs struct into a query string over the url
let first = true
for (let key in opts.qs) {
const str = `${encodeURIComponent(key)}=${encodeURIComponent(opts.qs[key])}`
if (first) {
opts.url += `?${str}`
first = false
} else {
opts.url += `&${str}`
}
}
}
// it appears that certain call paths from our code do not set the
// opts.json field to true; rp is apparently more resilient to
// this situation than needle
opts.json = true
return needle(opts.method.toLowerCase(), // needle takes e.g. 'put' not 'PUT'
opts.url,
opts.body || opts.params,
opts)
.then(resp => {
if (resp.statusCode >= 400) {
// we turn >=400 statusCode responses into exceptions
const error = new Error(resp.body.error || resp.statusMessage)
error.statusCode = resp.statusCode // the http status code
error.options = opts // the code below requires access to the input opts
error.error = resp.body // the error body
throw error
} else {
// otherwise, the response body is the expected return value
return resp.body
}
})
}
class Client {

@@ -14,0 +60,0 @@ constructor (options) {

@@ -24,2 +24,6 @@ // Licensed to the Apache Software Foundation (ASF) under one or more contributor

get (options) {
return this.feed('READ', options)
}
feed (event, options) {

@@ -26,0 +30,0 @@ if (!this.feed_name(options)) {

10

lib/main.d.ts

@@ -49,5 +49,5 @@ // Licensed to the Apache Software Foundation (ASF) under one or more contributor

invoke<In extends Dict, Out extends Dict>(options: { name: string; namespace?: string; blocking?: false; params?: In; result?: boolean; }): Promise<{ activationId: string }>;
create(options: { name: string; namespace?: string; action: (string | Buffer | Action); kind?: Kind; overwrite?: boolean; params?: Dict; version?: string; }): Promise<Action>;
create(options: { name: string; namespace?: string; action: (string | Buffer | Action); kind?: Kind; overwrite?: boolean; params?: Dict; annotations?: Dict; limits?: Limits; version?: string; }): Promise<Action>;
//create(options: { name: string; namespace?: string; action: (string | Buffer | Action); kind?: Kind; overwrite?: boolean; params?: Dict; version?: string; }[]): Promise<Action[]>;
update(options: { name: string; namespace?: string; action: (string | Buffer | Action); kind?: Kind; params?: Dict; version?: string; }): Promise<Action>;
update(options: { name: string; namespace?: string; action: (string | Buffer | Action); kind?: Kind; params?: Dict; annotations?: Dict; limits?: Limits; version?: string; }): Promise<Action>;
//update(options: ({ name: string; namespace?: string; action: (string | Buffer | Action); kind?: Kind; params?: Dict; version?: string; })[]): Promise<Action[]>;

@@ -243,5 +243,5 @@ delete(options: string): Promise<Action>;

interface Limits {
timeout: number;
memory: number;
logs: number;
timeout?: number;
memory?: number;
logs?: number;
}

@@ -248,0 +248,0 @@

@@ -21,3 +21,4 @@ // Licensed to the Apache Software Foundation (ASF) under one or more contributor

INVALID_OPTIONS_ERROR: 'Invalid constructor options.',
MISSING_BASEPATH_ERROR: 'Missing mandatory basepath parameter from options.'
MISSING_BASEPATH_ERROR: 'Missing mandatory parameters: basepath or name.',
INVALID_BASEPATH_ERROR: 'Invalid parameters: use basepath or name, not both.'
}

@@ -15,17 +15,28 @@ // Licensed to the Apache Software Foundation (ASF) under one or more contributor

// - /namespace/package/resource_name
// - namespace/package/resource_name
const parse_id_and_ns = resource => {
if (!resource.startsWith('/')) {
const parts = (resource.match(/\//g) || []).length
const names = resource.split('/')
// checking for `resource_name` and `package/resource_name`
if (parts === 0 ||
(parts === 1 && !resource.startsWith('/'))) {
return { namespace: default_namespace(), id: resource }
}
const paths = resource.split('/')
// checking for `/namespace/resource_name` and `namespace/package/resource_name`
if (parts === 2) {
if (resource.startsWith('/')) {
return { namespace: names[1], id: names[2] }
} else {
return { namespace: names[0], id: `${names[1]}/${names[2]}` }
}
}
if (paths.length !== 3 && paths.length !== 4) {
throw new Error(messages.INVALID_RESOURCE_ERROR)
// checking for `/namespace/package/resource_name`
if (parts === 3 && resource.startsWith('/')) {
return { namespace: names[1], id: `${names[2]}/${names[3]}` }
}
const id = paths.slice(2).join('/')
const namespace = paths[1]
return { id, namespace }
throw new Error(messages.INVALID_RESOURCE_ERROR)
}

@@ -32,0 +43,0 @@

@@ -16,4 +16,15 @@ // Licensed to the Apache Software Foundation (ASF) under one or more contributor

get (options) {
options = options || {}
options.basepath = this.basepath(options)
return this.list(this.qs(options, ['basepath']))
}
list (options) {
options = options || {}
if (this.has_basepath(options)) {
options.basepath = this.calculate_basepath(options)
}
const qs = this.qs(options, ['relpath', 'basepath', 'operation', 'limit', 'skip'])

@@ -34,7 +45,30 @@ return this.client.request('GET', this.routeMgmtApiPath('getApi'), { qs })

delete (options) {
if (!options || !options.hasOwnProperty('basepath')) {
has_basepath (options) {
return !!(options.name || options.basepath)
}
basepath (options) {
if (!this.has_basepath(options)) {
throw new Error(messages.MISSING_BASEPATH_ERROR)
}
return this.calculate_basepath(options)
}
calculate_basepath (options) {
if (options.name && options.basepath) {
throw new Error(messages.INVALID_BASEPATH_ERROR)
}
return options.basepath || options.name
}
missing_basepath (options) {
return !(options.name || options.basepath)
}
delete (options) {
options = options || {}
options.basepath = this.basepath(options)
const qs = this.qs(options, ['relpath', 'basepath', 'operation'])

@@ -46,2 +80,12 @@ qs.force = true

create (options) {
const body = this.create_body(options || {})
const qs = this.qs(options, ['responsetype'])
return this.client.request('POST', this.routeMgmtApiPath('createApi'), { body, qs })
}
create_body (options) {
if (options.swagger) {
return { apidoc: { namespace: '_', swagger: options.swagger } }
}
const missing = CREATE_PARAMS.filter(param => !(options || {}).hasOwnProperty(param))

@@ -53,5 +97,3 @@

const body = this.route_swagger_definition(options)
const qs = this.qs(options, ['responsetype'])
return this.client.request('POST', this.routeMgmtApiPath('createApi'), { body, qs })
return this.route_swagger_definition(options)
}

@@ -67,4 +109,8 @@

action: this.route_swagger_action(params)
}
}
if (params.name) {
apidoc.apiName = params.name
}
return { apidoc }

@@ -71,0 +117,0 @@ }

{
"name": "openwhisk",
"version": "3.9.0",
"version": "3.10.0",
"description": "JavaScript client library for the OpenWhisk platform",

@@ -45,3 +45,3 @@ "main": "lib/main.js",

"dependencies": {
"request-promise": "^2.0.1",
"needle": "^2.0.1",
"@types/node": "^8.0.26",

@@ -48,0 +48,0 @@ "@types/swagger-schema-official": "^2.0.6"

@@ -250,2 +250,3 @@ # OpenWhisk Client for JavaScript

ow.packages.get({name: '...'})
ow.feeds.get({name: '...'})
```

@@ -276,2 +277,3 @@

ow.packages.delete({name: '...'})
ow.feeds.delete({name: '...', trigger: '...'})
```

@@ -418,7 +420,6 @@

### create & delete feeds
### create feeds
```javascript
ow.feeds.create({feedName: '...', trigger: '...'})
ow.feeds.delete({feedName: '...', trigger: '...'})
```

@@ -438,2 +439,11 @@

### retrieve route
```javascript
ow.routes.get({basepath: '...'})
ow.routes.get({name: '...'})
```
*This method is a wrapper for the list method. It throws an error if the base path or name parameter is missing.*
### list routes

@@ -448,2 +458,3 @@

- `basepath` - base URI path for endpoints
- `name` - identifier for API
- `operation` - HTTP methods

@@ -453,3 +464,3 @@ - `limit` - limit result set size

*`relpath` is only valid when `basepath` is also specified.*
*`relpath` is only valid when `basepath` is also specified. `name` and `basepath` cannot be used together.*

@@ -460,2 +471,3 @@ ### delete routes

ow.routes.delete({basepath: '...'})
ow.routes.delete({name: '...'})
```

@@ -477,3 +489,14 @@

- `basepath` - base URI path for endpoints (default: `/`)
- `name` - identifier for API (default: `basepath`)
### add route (swagger)
```javascript
ow.routes.create({swagger: '{...}'})
```
Swagger parameter must be a well-formed JSON string, containing a valid Swagger API definition, which follows the [OpenWhisk API Gateway route schema](https://github.com/apache/incubator-openwhisk-apigateway/blob/master/doc/v2/management_interface_v2.md#post-v2tenant_idapis).
*No other parameters are supported when creating the route from a JSON Swagger document.*
## Debugging

@@ -521,3 +544,3 @@

$ ./test/integration/prepIntegrationTests.sh <your key in the form of ABCD:EFGH> <openwhisk instance hostname> <openwhisk namespace> <api gatewaytoken>
```
```
The `prepIntegrationTests.sh` script is designed to give you feedback if it detects a setting that is not correct on your machine. ex: `node 6 or above is not detected`

@@ -524,0 +547,0 @@

Sorry, the diff of this file is not supported yet

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