Sandbox node.js code like a boss.
- Runs code on the public webtask.io cluster.
- Your code is totally sandboxed from everyone else's.
- Integrated with your wt-cli profiles.
- Supports returning Promises and/or invoking node-style callbacks.
npm install sandboxjs
# Optionally configure a default wt-cli profile
First, get a webtask token using wt-cli:
# Create a new wt-cli profile
npm install -g wt-cli
wt init
# Or, if you already use wt-cli:
wt profile ls
var Assert = require('assert');
var Sandbox = require('sandboxjs');
// You can get your webtask token using the steps above
var code = 'module.exports = function (ctx, cb) { cb(null, "hello world"); }';
var profile = Sandbox.fromToken(process.env.WEBTASK_TOKEN);
// This library lets you create a webtask and run it in one step as a shortcut:
profile.run(code, function (err, res, body) {
Assert.ifError(err);
Assert.equal(res.statusCode, 200, 'The webtask executed as expected');
Assert.equal(body, 'hello world', 'The webtask returned the expected string');
});
// Alternatively, your application might want to to create a webtask url
// with your (or your users') custom code and secrets.
profile.create(code, { secrets: { auth0: 'rocks' } }, function (err, webtask) {
Assert.ifError(err);
// Making requests to this url will run the specified custom code in a
// node.js sandbox and will give it access to your secrets in the first
// argument (`ctx`) of your exported webtask function.
// For more information on the different styles of webtask functions that
// are supported, see: https://webtask.io/docs/model
console.log(webtask.url);
});
Update the code of an existing named webtask
var Sandbox = require('sandboxjs');
var sandbox = Sandbox.init({ /* ... */ });
var webtaskName = 'my_webtask';
var webtaskCode = 'module.exports = ...';
sandbox.inspectWebtask({
name: webtaskName,
// We need to decrypt embedded secrets so that we can set them on the
// replacement named webtask
decrypt: true,
// No need to fetch code since we will be updating it anyway
fetch_code: false,
}).then(handleClaims);
function handleClaims(claims) {
// We will pull any claims from the existing webtask that are user-defined
// and set them on a new claims object. Note that some claims are *NOT*
// copied over because they are read-only claims generated by the platform.
// Common examples include: `ca`, `jti` and `iat`.
var newClaims = {
jtn: webtaskName,
dd: claims.dd,
mb: claims.mb,
pb: claims.pb,
// Instead of being an opaque, encrypted blob, this will be a javascript
// Object mapping secret key to value because we set the `decrypt`
// option on the call to `inspectWebtask`.
ectx: claims.ectx,
pctx: claims.pctx,
code: webtaskCode,
};
// Create a replacement webtask from raw claims. We use `createRaw` instead
// of `create` so that we can deal directly with the platform's claims
// instead of the more human-friendly aliases in `create`.
// This method will make a token issue request with the updated claims
// and resolve the Promise with a new `Webtask` instance based on that
// token.
return sandbox.createRaw(newClaims);
}
- sandboxjs
Sandbox node.js code.
Sandbox node.js code.
- sandboxjs
- static
- .fromToken(token, options) ⇒
Sandbox
- .init(options) ⇒
Sandbox
- .fromToken(token, options) ⇒
- inner
- ~Sandbox
- new Sandbox(options)
- .create([codeOrUrl], [options], [cb]) ⇒
Promise
- .createRaw(claims, [cb]) ⇒
Promise
- .createUrl(options, [cb]) ⇒
Promise
- .run([codeOrUrl], [options], [cb]) ⇒
Promise
- .createToken(options, [cb]) ⇒
Promise
- .createTokenRaw(claims, [cb]) ⇒
Promise
- .createLogStream(options) ⇒
Stream
- .getWebtask(options, [cb]) ⇒
Promise
- .removeWebtask(options, [cb]) ⇒
Promise
- .listWebtasks(options, [cb]) ⇒
Promise
- .createCronJob(options, [cb]) ⇒
Promise
- .removeCronJob(options, [cb]) ⇒
Promise
- .setCronJobState(options, [cb]) ⇒
Promise
- .listCronJobs([options], [cb]) ⇒
Promise
- .getCronJob(options, [cb]) ⇒
Promise
- .getCronJobHistory(options, [cb]) ⇒
Promise
- .inspectToken(options, [cb]) ⇒
Promise
- .inspectWebtask(options, [cb]) ⇒
Promise
- .revokeToken(token, [cb]) ⇒
Promise
- ~Sandbox
- static
Create a Sandbox instance from a webtask token
Kind: static method of sandboxjs
Returns: Sandbox
- A {@see Sandbox} instance whose url, token and container were derived from the given webtask token.
Param | Type | Description |
---|---|---|
token | String |
The webtask token from which the Sandbox profile will be derived. |
options | Object |
The options for creating the Sandbox instance that override the derived values from the token. |
[options.url] | String |
The url of the webtask cluster. Defaults to the public 'webtask.it.auth0.com' cluster. |
options.container | String |
The container with which this Sandbox instance should be associated. Note that your Webtask token must give you access to that container or all operations will fail. |
options.token | String |
The Webtask Token. See: https://webtask.io/docs/api_issue. |
Create a Sandbox instance
Kind: static method of sandboxjs
Returns: Sandbox
- A {@see Sandbox} instance.
Param | Type | Description |
---|---|---|
options | Object |
The options for creating the Sandbox instance. |
[options.url] | String |
The url of the webtask cluster. Defaults to the public 'webtask.it.auth0.com' cluster. |
options.container | String |
The container with which this Sandbox instance should be associated. Note that your Webtask token must give you access to that container or all operations will fail. |
options.token | String |
The Webtask Token. See: https://webtask.io/docs/api_issue. |
Kind: inner class of sandboxjs
- ~Sandbox
- new Sandbox(options)
- .create([codeOrUrl], [options], [cb]) ⇒
Promise
- .createRaw(claims, [cb]) ⇒
Promise
- .createUrl(options, [cb]) ⇒
Promise
- .run([codeOrUrl], [options], [cb]) ⇒
Promise
- .createToken(options, [cb]) ⇒
Promise
- .createTokenRaw(claims, [cb]) ⇒
Promise
- .createLogStream(options) ⇒
Stream
- .getWebtask(options, [cb]) ⇒
Promise
- .removeWebtask(options, [cb]) ⇒
Promise
- .listWebtasks(options, [cb]) ⇒
Promise
- .createCronJob(options, [cb]) ⇒
Promise
- .removeCronJob(options, [cb]) ⇒
Promise
- .setCronJobState(options, [cb]) ⇒
Promise
- .listCronJobs([options], [cb]) ⇒
Promise
- .getCronJob(options, [cb]) ⇒
Promise
- .getCronJobHistory(options, [cb]) ⇒
Promise
- .inspectToken(options, [cb]) ⇒
Promise
- .inspectWebtask(options, [cb]) ⇒
Promise
- .revokeToken(token, [cb]) ⇒
Promise
Creates an object representing a user's webtask.io credentials
Param | Type | Description |
---|---|---|
options | Object |
Options used to configure the profile |
options.url | String |
The url of the webtask cluster where code will run |
options.container | String |
The name of the container in which code will run |
options.token | String |
The JWT (see: http://jwt.io) issued by webtask.io that grants rights to run code in the indicated container |
Create a Webtask from the given options
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
[codeOrUrl] | String |
The code for the webtask or a url starting with http:// or https:// |
[options] | Object |
Options for creating the webtask |
[cb] | function |
Optional callback function for node-style callbacks |
Create a Webtask from the given claims
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
claims | Object |
Options for creating the webtask |
[cb] | function |
Optional callback function for node-style callbacks |
Shortcut to create a Webtask and get its url from the given options
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
options | Object |
Options for creating the webtask |
[cb] | function |
Optional callback function for node-style callbacks |
Shortcut to create and run a Webtask from the given options
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
[codeOrUrl] | String |
The code for the webtask or a url starting with http:// or https:// |
[options] | Object |
Options for creating the webtask |
[cb] | function |
Optional callback function for node-style callbacks |
Create a webtask token - A JWT (see: http://jwt.io) with the supplied options
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
options | Object |
Claims to make for this token (see: https://webtask.io/docs/api_issue) |
[cb] | function |
Optional callback function for node-style callbacks |
Create a webtask token - A JWT (see: http://jwt.io) with the supplied claims
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
claims | Object |
Claims to make for this token (see: https://webtask.io/docs/api_issue) |
[cb] | function |
Optional callback function for node-style callbacks |
Create a stream of logs from the webtask container
Note that the logs will include messages from our infrastructure.
Kind: instance method of Sandbox
Returns: Stream
- A stream that will emit 'data' events with container logs
Param | Type | Description |
---|---|---|
options | Object |
Streaming options overrides |
[options.container] | String |
The container for which you would like to stream logs. Defaults to the current profile's container. |
Read a named webtask
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with an array of Webtasks
Param | Type | Description |
---|---|---|
options | Object |
Options |
[options.container] | String |
Set the webtask container. Defaults to the profile's container. |
options.name | String |
The name of the webtask. |
[cb] | function |
Optional callback function for node-style callbacks. |
Remove a named webtask from the webtask container
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with an array of Webtasks
Param | Type | Description |
---|---|---|
options | Object |
Options |
[options.container] | String |
Set the webtask container. Defaults to the profile's container. |
options.name | String |
The name of the cron job. |
[cb] | function |
Optional callback function for node-style callbacks. |
List named webtasks from the webtask container
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with an array of Webtasks
Param | Type | Description |
---|---|---|
options | Object |
Options |
[options.container] | String |
Set the webtask container. Defaults to the profile's container. |
[cb] | function |
Optional callback function for node-style callbacks. |
Create a cron job from an already-existing webtask token
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with a {@see CronJob} instance.
Param | Type | Description |
---|---|---|
options | Object |
Options for creating a cron job |
[options.container] | String |
The container in which the job will run. Defaults to the current profile's container. |
options.name | String |
The name of the cron job. |
options.token | String |
The webtask token that will be used to run the job. |
options.schedule | String |
The cron schedule that will be used to determine when the job will be run. |
[cb] | function |
Optional callback function for node-style callbacks. |
Remove an existing cron job
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the response from removing the job.
Param | Type | Description |
---|---|---|
options | Object |
Options for removing the cron job |
[options.container] | String |
The container in which the job will run. Defaults to the current profile's container. |
options.name | String |
The name of the cron job. |
[cb] | function |
Optional callback function for node-style callbacks. |
Set an existing cron job's state
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the response from removing the job.
Param | Type | Description |
---|---|---|
options | Object |
Options for updating the cron job's state |
[options.container] | String |
The container in which the job will run. Defaults to the current profile's container. |
options.name | String |
The name of the cron job. |
options.state | String |
The new state of the cron job. |
[cb] | function |
Optional callback function for node-style callbacks. |
List cron jobs associated with this profile
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with an Array of {@see CronJob} instances.
Param | Type | Description |
---|---|---|
[options] | Object |
Options for listing cron jobs. |
[options.container] | String |
The container in which the job will run. Defaults to the current profile's container. |
[cb] | function |
Optional callback function for node-style callbacks. |
Get a CronJob instance associated with an existing cron job
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with a {@see CronJob} instance.
Param | Type | Description |
---|---|---|
options | Object |
Options for retrieving the cron job. |
[options.container] | String |
The container in which the job will run. Defaults to the current profile's container. |
options.name | String |
The name of the cron job. |
[cb] | function |
Optional callback function for node-style callbacks. |
Get the historical results of executions of an existing cron job.
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with an Array of cron job results.
Param | Type | Description |
---|---|---|
options | Object |
Options for retrieving the cron job. |
[options.container] | String |
The container in which the job will run. Defaults to the current profile's container. |
options.name | String |
The name of the cron job. |
[options.offset] | String |
The offset to use when paging through results. |
[options.limit] | String |
The limit to use when paging through results. |
[cb] | function |
Optional callback function for node-style callbacks. |
Inspect an existing webtask token to resolve code and/or secrets
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the resolved webtask data.
Param | Type | Description |
---|---|---|
options | Object |
Options for inspecting the webtask. |
options.token | Boolean |
The token that you would like to inspect. |
[options.decrypt] | Boolean |
Decrypt the webtask's secrets. |
[options.fetch_code] | Boolean |
Fetch the code associated with the webtask. |
[cb] | function |
Optional callback function for node-style callbacks. |
Inspect an existing named webtask to resolve code and/or secrets
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the resolved webtask data.
Param | Type | Description |
---|---|---|
options | Object |
Options for inspecting the webtask. |
options.name | Boolean |
The named webtask that you would like to inspect. |
[options.decrypt] | Boolean |
Decrypt the webtask's secrets. |
[options.fetch_code] | Boolean |
Fetch the code associated with the webtask. |
[cb] | function |
Optional callback function for node-style callbacks. |
Revoke a webtask token
Kind: instance method of Sandbox
Returns: Promise
- A Promise that will be fulfilled with the token
See: https://webtask.io/docs/api_revoke
Param | Type | Description |
---|---|---|
token | String |
The token that should be revoked |
[cb] | function |
Optional callback function for node-style callbacks |
Kind: global class
- CronJob
- new CronJob()
- .claims
- .sandbox
- .refresh([cb]) ⇒
Promise
- .remove([cb]) ⇒
Promise
- .getHistory(options, [cb]) ⇒
Promise
- .inspect(options, [cb]) ⇒
Promise
- .setJobState(options, [cb]) ⇒
Promise
Creates an object representing a CronJob
Kind: instance property of CronJob
Properties
Name | Description |
---|---|
claims | The claims embedded in the Webtask's token |
Kind: instance property of CronJob
Properties
Name | Description |
---|---|
sandbox | The {@see Sandbox} instance used to create this Webtask instance |
Refresh this job's metadata
Kind: instance method of CronJob
Returns: Promise
- A Promise that will be fulfilled with the this cron job instance
Param | Type | Description |
---|---|---|
[cb] | function |
Optional callback function for node-style callbacks |
Remove this cron job from the webtask cluster
Note that this will not revoke the underlying webtask token, so the underlying webtask will remain functional.
Kind: instance method of CronJob
Returns: Promise
- A Promise that will be fulfilled with the token
Param | Type | Description |
---|---|---|
[cb] | function |
Optional callback function for node-style callbacks |
Get the history of this cron job
Kind: instance method of CronJob
Returns: Promise
- A Promise that will be fulfilled with an Array of cron job results.
Param | Type | Description |
---|---|---|
options | Object |
Options for retrieving the cron job. |
[options.offset] | String |
The offset to use when paging through results. |
[options.limit] | String |
The limit to use when paging through results. |
[cb] | function |
Optional callback function for node-style callbacks. |
Inspect an existing webtask to optionally get code and/or secrets
Kind: instance method of CronJob
Returns: Promise
- A Promise that will be fulfilled with an Array of cron job results.
Param | Type | Description |
---|---|---|
options | Object |
Options for inspecting the webtask. |
[options.fetch_code] | Boolean |
Fetch the code associated with the webtask. |
[options.decrypt] | Boolean |
Decrypt the webtask's secrets. |
[cb] | function |
Optional callback function for node-style callbacks. |
Set the cron job's state
Kind: instance method of CronJob
Returns: Promise
- A Promise that will be fulfilled with an Array of cron job results.
Param | Type | Description |
---|---|---|
options | Object |
Options for updating the webtask. |
options.state | Boolean |
Set the cron job's state to this. |
[cb] | function |
Optional callback function for node-style callbacks. |
Kind: global class
- Webtask
- new Webtask()
- .claims
- .sandbox
- .token
- .createLogStream(options) ⇒
Stream
- .run(options, [cb]) ⇒
Promise
- .createCronJob(options, [cb]) ⇒
Promise
- .inspect(options, [cb]) ⇒
Promise
- .remove([cb]) ⇒
Promise
- .revoke([cb]) ⇒
Promise
Creates an object representing a Webtask
Kind: instance property of Webtask
Properties
Name | Description |
---|---|
claims | The claims embedded in the Webtask's token |
Kind: instance property of Webtask
Properties
Name | Description |
---|---|
sandbox | The {@see Sandbox} instance used to create this Webtask instance |
Kind: instance property of Webtask
Properties
Name | Description |
---|---|
token | The token associated with this webtask |
Create a stream of logs from the webtask container
Note that the logs will include messages from our infrastructure.
Kind: instance method of Webtask
Returns: Stream
- A stream that will emit 'data' events with container logs
Param | Type | Description |
---|---|---|
options | Object |
Streaming options overrides |
[options.container] | String |
The container for which you would like to stream logs. Defaults to the current profile's container. |
Run the webtask and return the result of execution
Kind: instance method of Webtask
Returns: Promise
- - A Promise that will be resolved with the response from the server.
Param | Type | Description |
---|---|---|
options | Object |
Options used to tweak how the webtask will be invoked |
[cb] | function |
Optional node-style callback that will be invoked upon completion |
Schedule the webtask to run periodically
Kind: instance method of Webtask
Returns: Promise
- - A Promise that will be resolved with a {@see CronJob} instance.
Param | Type | Description |
---|---|---|
options | Object |
Options for creating the webtask |
options.schedule | Object |
Cron-string-formatted schedule |
[options.name] | Object |
The name for the cron job |
[cb] | function |
Optional node-style callback that will be invoked upon completion |
Inspect an existing webtask to optionally get code and/or secrets
Kind: instance method of Webtask
Returns: Promise
- A Promise that will be fulfilled with the result of inspecting the token.
Param | Type | Description |
---|---|---|
options | Object |
Options for inspecting the webtask. |
[options.decrypt] | Boolean |
Decrypt the webtask's secrets. |
[options.fetch_code] | Boolean |
Fetch the code associated with the webtask. |
[cb] | function |
Optional callback function for node-style callbacks. |
Remove the named webtask
Kind: instance method of Webtask
Returns: Promise
- A Promise that will be fulfilled with the result of inspecting the token.
Param | Type | Description |
---|---|---|
[cb] | function |
Optional callback function for node-style callbacks. |
Revoke the webtask's token
Kind: instance method of Webtask
Returns: Promise
- A Promise that will be fulfilled with the result of revoking the token.
Param | Type | Description |
---|---|---|
[cb] | function |
Optional callback function for node-style callbacks. |
This library will be used in wt-cli.
Just clone the repo, run npm install
and then hack away.
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
MIT
Auth0 helps you to:
- Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
- Add authentication through more traditional username/password databases.
- Add support for linking different user accounts with the same user.
- Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
- Analytics of how, when and where users are logging in.
- Pull data from other sources and add it to the user profile, through JavaScript rules.
- Go to Auth0 and click Sign Up.
- Use Google, GitHub or Microsoft Account to login.