Giter Club home page Giter Club logo

openwhisk-client-js's Issues

Feature request: Result only flag for action invoke

Is there an option similar to the -r in the wsk cli that returns only the result of the invocation (used together with -b or blocking = true)? I'd use it all the time :)

On a related note, I don't think I understand how this example in the readme works:

const blocking = true
const params = {msg: 'this is some words to reverse'}

ow.actions.invoke({actionName, blocking, params}).then(result => {
  console.log('here's the reversed string', result.reversed)
}).catch(err => {
  console.error(failed to invoke actions', err)
})

IIUC the result of the invocation will contain not only the "result", but all the other meta data (e.g., duration, name, annotations, etc.) and I would expect result.reversed to be undefined. New to js, what am I missing?

odd SSL error when passing large payloads

try calling ow.packges.get({name:"foo", junk: "SOME VERY LARGE PAYLOAD"})

if the payload is too big (in my case, 330k), you will get back an odd SSL error:

Error encountered calling OpenWhisk: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line"

allow default parameters when creating and updating actions

action.js does not allow to set {"parameters"}

wsk -v action create --kind nodejs:6 -p param pval helloAction7 helloAction.js
...
Body sent:
{"parameters": [{"value": "pval", "key": "param"}], "exec": {"kind": "nodejs:6", "code": "function main() {\n    return {payload: 'Hello world'};\n}\n"}}

Add debugging flags

Use environment variable to turn on help debugging by dumping more information about API requests to the console.

3.13.0 release

Minor release, rather than patch, as #99 is a new feature.

release notes

3.13.0 (2018.03.14)

  • Adds an optional query parameter for action fetches that determines if action code will be retrieved or not (#99)

process

  • npm version minor to bump package.json to 3.13.0
  • Push version commit and git tags to Github
  • Travis CI will auto-publish new version to NPM
  • Draft Github release from tags with notes above.

Need to write up these instructions in the repository.

Updated README with more examples.

The README is light on examples of using the library for common tasks, focusing more the API documentation.

We should re-work the file to add more of these common usecases to help developers.

People have recently been asking about retrieving package details, including credentials, invoking actions and triggers amongst others.

3.13.1 release

Patch release to resolve bug in 3.13.0

release notes

3.13.1 (2018.03.15)

  • Fix support for string parameter in action.get API (#105)

process

  • npm version patch to bump package.json to 3.13.1
  • Push version commit and git tags to Github
  • Travis CI will auto-publish new version to NPM
  • Draft Github release from tags with notes above.

support running against a local deployment of openwhisk

A local deployment of openwhisk generally uses a self signed certificate. The base request operations should permit an additional configuration parameter to disable rejecting unauthorized TLS. This is particularly helpful for integration testing against a local deployment.

Create Trigger Feed failing with Check syntax errors message

Hi I'm trying the sample code:

create trigger feed from alarm package

// for example...
const params = {cron: '*/8 * * * * *', trigger_payload: {name: 'James'}}
const name = '/whisk.system/alarms/alarm'
const trigger = 'alarmTrigger'
ow.feeds.create({name, trigger, params}).then(package => {
console.log('alarm trigger feed created')
}).catch(err => {
console.error('failed to create alarm trigger', err)
})

This is giving me a failure:
failed to create alarm trigger { BaseOperationError: Action invocation failed, API returned error code. Check syntax errors? Missing error message.
at Client.handle_errors (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/openwhisk/lib/client.js:102:13)
at rp.catch.err (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/openwhisk/lib/client.js:43:38)
at tryCatcher (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/promise.js:510:31)
at Promise._settlePromiseAt (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/promise.js:584:18)
at Promise._settlePromises (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/promise.js:700:14)
at Async._drainQueue (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (/home/lzhao/openwhisk/code/openwhisk-package-ecs/node_modules/bluebird/js/main/async.js:15:14)
at runCallback (timers.js:666:20)
at tryOnImmediate (timers.js:639:5)
at processImmediate [as _immediateCallback] (timers.js:611:5)
name: 'BaseOperationError',
message: 'Action invocation failed, API returned error code. Check syntax errors? Missing error message.',
error:
{ duration: 109,
name: 'alarm',
subject: 'whisk.system',
activationId: '20ae80ca53c24fa3886fb9a23e2ba16c',
publish: false,
annotations: [ [Object], [Object] ],
version: '0.0.5',
response: { result: [Object], success: false, status: 'application error' },
end: 1492115313980,
logs: [],
start: 1492115313871,
namespace: 'whisk.system' } }

Can you let me know why this is not working? I am able to use the sample snippets to create an action without any problems but I'm not able to do it for an alarm

please add ignore_certs env var

When running test code for openwhisk actions it is often necessary to ignore certificates since it is running openwhisk in travis. It looks like the other constructor parameters are already handled this way.

feature request: support "name" for get, invoke operations

right now, i find that my code is littered with things like:

Promise.all(triggers.map(trigger => ow.triggers.invoke({ triggerName: trigger.name })))

it seems preferable to me to write:

Promise.all(triggers.map(ow.triggers.invoke))

but i can't, because the get and invoke operations require triggerName, or actionName or packageName or ruleName rather than just name.

on top of this, having an invokeAll or getAll command would be nice, so that i could write

ow.packages.get('foo').then(package=>package.actions).then(ow.actions.getAll)

and having a simple projection mechanism would then simplify this to:

ow.packages.getActions('foo').then(ow.actions.getAll)

compare this to what we have now:

ow.packages.get('foo').then(package=>package.actions)
    .then(Promise.all(triggers.map(trigger=>ow.triggers.invoke({triggerName:trigger.name})))

consider switching from request-promise to needle

request-promise depends on request, which is very slow to load: request/request#2261

that issue aligns with my experience. namely, that request-promise, due to request, can take anywhere from 120-250ms to require on mac and linux.

on windows 10, apparently due to windows defender, it can take 10 times as long! sometimes multiple seconds!

an alternative is needle: https://www.npmjs.com/package/needle

quick experiments show that needle indeed loads in about 1/4th the time. these numbers from macos 10.12.6, node 8.5.0: fairly stably needle loads in 30-32ms, and request-promise in 110-120ms.

in more realistic scenarios, i've seen request-promise routinely take close to 300ms on macos, and 1-3 seconds on windows 10. the fall creators update of windows 10 seems to have made this much worse.

the patch for this is straightforward, as needle mostly obeys the same schema as rp.

allow initialization for host:port and determine protocol automatically

rather than init the api like this:

var ow = openwhisk({api: 'https://openwhisk.ng.bluemix.net/api/v1/', api_key: '...', namespace: 'default_namespace'});

I'd like to suggest a little bit of convenience:

var ow = openwhisk({apihost: 'openwhisk.ng.bluemix.net', api_key: '...', namespace: 'default_namespace'});

where apihost allows one to just provide either the host or host:port.
this can be split to determine protocol as in

var edgeHostParts = apihost.split(':');
var protocol = (edgeHostParts.length >= 2  &&  edgeHostParts[1] == '443') ? 'https' : 'http';
api = protocol + '://' + apihost + '/api/v1/';

Improve Developer Experience when errors occur

If the platform returns an API error, the library parses any error text and wraps it in a generic error response.

Here's an example of creating an action for an invalid namespace.

{
  "error": {
    "name": "BaseOperationError",
    "message": "OpenWhisk authentication failed, check API key? The supplied authentication is not authorized to access this resource.",
    "error": {
      "error": "The supplied authentication is not authorized to access this resource.",
      "code": 5170570
    }
  }
}

This does not give the developer much help to understand where the error occurred and why.

Ideas for improving this from @starpit

  • Provide more descriptive names in error message, rather than BaseOperationError.
  • Add HTTP path for failing response into the error message.
  • Stack trace should match error site.

integration tests require manual setup and cleanup

In order for a dev to run the integration tests, one has to create seed artifacts manually. Further, if a test fails, its transient artifacts are not reclaimed. The integration tests should perform all required setup and cleanup on termination.

Actions test uses payload instead of params when sending JSON string

In the test for invoking an action using a JSON string (actions.test.js, line 413 ff) the JSON string is defined in a payload field, rather than in the params field. Furthermore, it is an empty object, which is equal to the default when no params are provided - so the test will always succeed.

actions.invoke returning a 405 (method POST not supported)

I was getting errors trying actions.invoke but not getting any error stack back (using .then().catch(err)). actions.list works fine which means my base setup of API key etc was fine. I added a line of instrumentation into base_operation.js handle_errors() which showed that OW was returning a 405 method not allowed.
ow_error

Build via react-scripts fails due to ES5 incompatibility

Using 'openwhisk' in context of a React app (created with create-react-app) is causing react-scripts build to fail due to ES5 incompatibility.

$ npm run build

> [email protected] build /Users/guest/Downloads/my-app
> react-scripts build

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file:

 	./node_modules/openwhisk/lib/names.js:6

Read more here: http://bit.ly/2tRViJ9

[Error][minikube] ENOTFOUND nginx.openwhisk nginx.openwhisk:443

Hi folks!

I deploy OpenWhisk locally on minikube and it's my action:

const openwhisk = require('openwhisk');

function main(params){
  return new Promise((resolve, reject) => {
    ow.actions.list().then(resolve);
  });
}

Result of invoke it is error:

Unhandled rejection Error: Error encountered calling OpenWhisk: Error: getaddrinfo ENOTFOUND nginx.openwhisk nginx.openwhisk:443

Maybe someone experienced similar issue and can help?

Cheers ๐Ÿฅ‚

3.10.0 release

Once the following PRs have merged, the next release can drafted and made available on this repo. npmbot should automatically publish to NPM.

outstanding PRs

notes for release page

  • Added new features to routes() methods. API name parameter and swagger route definition now supported. Route retrieval method included. (#69, #70, #71)
  • Swapped HTTP client library from request to needle. Significant reduction in dependencies installed and loading time. (#77)
  • Retrieving status and configuration for feed triggers now included (#80)
  • FQN names now handles missing leading forward-slash character (#75)
  • Updated TypeScript definitions (#76)

^^ @csantanapr

action.get does not return parameters bound to an action

Whisk's CLI returns parameters bound to an action when using "wsk action get" (in an array called "parameters" that has objects storing each parameter's name and value).

But the parameter information is gone in the nodeJS library when using actions.get - the parameters array is always empty (or only has an "_actions" object for a sequence action).

Many Action Invocations: EPIPE / PROTOCOL_CONNECTION_LOST

Hi, I'm invoking many actions from inside a parent action over a long (3-5 mins) period of time. We're running against an on-premises OpenWhisk cluster. The code invoking the actions is along the lines of:

const invokeAction = (openwhisk, v) => {
    return openwhisk.actions.invoke({
        name: "my-action",
        params: { param: "val" },
        insecure: true,
        blocking: true  //different error depending on whether true or false
    });
};
const ow = openwhisk({ ignore_certs: true });
rxObservableEmittingMySqlData
    .bufferCount(1000) //buffer to accomodate 1MB max message size
    .zip(Observable.timer(0, 800) x => x) //this will add a .8s delay before each action invocation - without this, I get "too many actions for namespace"
    .flatMap(v => Observable.fromPromise(invokeAction(ow, v)), 30)  //where 30 is maximum concurrent in-flight requests - these problems occur regardless of this value
    .subscribe(console.log, reject, resolve);

Error If blocking = true:

"response": {
        "status": "application error",
        "statusCode": 0,
        "success": false,
        "result": {
            "error": {
                "error": {
                    "code": "EPIPE",
                    "errno": "EPIPE",
                    "syscall": "write"
                },
                "message": "Unknown Error From API: Error: write EPIPE",
                "name": "OpenWhiskError"
            }
        }
    }

Error If blocking = false:

{"fatal":true, "code": "PROTOCOL_CONNECTION_LOST"}

Even though more OW instances were added to our cluster, it also doesn't seem like the actions aren't completing quickly enough (even when I remove/reduce my throttling), and even if not for these errors I'd be hitting the 5 minute timeout.

Is this the wrong approach for handling millions of MySQL records with OpenWhisk? Is OW even the right tool for the job?

socket hangup issues due to slow connection open

we inherit needle's default connection-open timeout of 10 seconds. this seems to result in socket hangup errors. i'm not sure what the right solution is here, but wanted to raise awareness of it.

  • option 1: the user of this library has to retry
  • option 2: we update the openwhisk npm to retry, according to a policy established by the caller (e.g. maxRetries)
  • option 3: we increase the connection open timeout a bit, in tandem with either opt1 or opt2

this seems to happen often enough to be of note, when talking to ibm cloud functions

Are multiple openwhisk() objects supported ?

Greetings

I am looking into the JS api and have a question.

var options = {apihost: 'openwhisk.ng.bluemix.net', api_key: '...'};
var ow = openwhisk(options);

Is it possible to have multiple 'ow' objects , with different API key/Namespace combos in the same Node.js application?

Does the library have any global/singleton properties that preclude that kind of usage?

Thanks
pj

Add support for error response coming out of OpenWhisk action invocation

action being invoked:

function main(args) {
    return new Promise((resolve, reject) => { reject({ statusCode: 404 }) };
}

The invocation of this action through the REST API produces this response:

{
"error": {
"statusCode": 404
}
}

However OpenWhisk Client expect the statusCode to be at the top-level, and I think we should change this behavior to also support OpenWhisk error response.

rule creation fails due to openwhisk api change

recently, the openwhisk backend introduced a (non-semver!) breaking change to the rule creation API. now, the action and trigger fields must be fully qualified, as in they must include a namespace.

suggestion: if the action or trigger do not have a slash in them, then prepend '/_/'?

regression: global namespace no longer matters

at some point a change was made that breaks code that relies on the global namespace field, i.e. the one provided with the openwhisk constructor.

now, the namespace is either the per-request options.namespace or names.default_namespace(), the latter of which does not pay attention to the global option:

const default_namespace = () => {
  return process.env['__OW_NAMESPACE'] || '_'
}

this breaks our code. luckily we are still pre-production, or this would've been a nightmare.

perhaps this: 9269e96

Travis Test Breakage

Travis is currently failing for this repo due to a trigger test failure.

Test output:

  โœ– triggers โ€บ fire a trigger   
  t.true(update_result.hasOwnProperty('activationId'))
                       |                              
                       false                          
  1. triggers โ€บ fire a trigger
  AssertionError: false === true
    triggers.test.js:112:7
    process._tickCallback (internal/process/next_tick.js:109:7)

3.11.0 release

Minor release, rather than patch, as #88 is a new feature.

release notes

3.11.0 (2017.12.07)

  • Added client library support for updating trigger feeds (#88)
  • Updated version of needle to 2.1.0 to resolve timeout issues with HTTP library (#90)

process

  • npm version minor to bump package.json to 3.11.0
  • Push version commit and git tags to Github
  • Travis CI will auto-publish new version to NPM
  • Draft Github release from tags with notes above.

Need to write up these instructions in the repository.

Add tests to improve coverage of error handling

Is it possible that the current test suite has no coverage of error handling? Because

  1. earlier versions of PR #78 didn't do proper error handling, but all of the integration and functional tests passed

  2. with proper error handling, the PR still fails, because the codecov tool complains that the lines having to do with error handling (in my update) are not covered by tests!

Working with Feeds should manage related Trigger annotations

The CLI and OW web UIs add an annotation to triggers to associate them with feeds when creating new trigger feeds.

This means that when that trigger is deleted, the feed can be notified.

The SDK does not implement this behaviour. This means that if someone creates a new trigger feed, deletes it and tries to re-create it, it may fail based on the implementation of the feed provider.

The behaviour of the SDK should mirror the other OW tools. It should be possible to disable this behaviour using a parameter option, although it defaults to on.

CI with travis

Setup a Travis build to periodically run integration test against an openwhisk deployment (or the publicly hosted service).

Deprecate "experimental" API Gateway

OpenWhisk's API Gateway service has moved from "experimental" to "release". The API path has changed between the versions.

The library has been updated to support both API endpoints recently, using a configuration parameter to control which one to use.

We need to remove the old API from the library. This will be a breaking change and need to be a major release.

3.14.0 release

release notes

3.14.0 (2018.03.26)

  • Add support to count entities with list (#109 )

process

  • npm version patch to bump package.json to 3.14.0
  • Push version commit and git tags to Github
  • Travis CI will auto-publish new version to NPM
  • Draft Github release from tags with notes above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.