Comparing version 3.9.0 to 3.10.0
@@ -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)) { |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
553
5
73052
21
1003
3
+ Addedneedle@^2.0.1
+ Addeddebug@3.2.7(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedms@2.1.3(transitive)
+ Addedneedle@2.9.1(transitive)
+ Addedsax@1.4.1(transitive)
- Removedrequest-promise@^2.0.1
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.10.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise@2.0.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)