https://github.com/holidaycheck/auth0-bundler
Bundle rules, scripts and hooks to deploy them to Auth0.
https://github.com/holidaycheck/auth0-bundler
auth0
Last synced: 3 months ago
JSON representation
Bundle rules, scripts and hooks to deploy them to Auth0.
- Host: GitHub
- URL: https://github.com/holidaycheck/auth0-bundler
- Owner: holidaycheck
- License: mit
- Archived: true
- Created: 2017-04-10T15:54:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-13T12:02:28.000Z (about 2 years ago)
- Last Synced: 2025-01-10T20:12:07.080Z (3 months ago)
- Topics: auth0
- Language: JavaScript
- Size: 243 KB
- Stars: 8
- Watchers: 5
- Forks: 4
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# auth0-bundler
The project was not updated for two years and does not even support Node 16, which is required by Auth0 now. We decided to archive this project to make it clear, that no updates for this library can be expected any more.
[![NPM version][npm-image]][npm-url]
[![Build status][travis-ci-image]][travis-ci-url]
[![License][license-image]][license-url]Bundle [rules](https://auth0.com/docs/rules), [scripts](https://auth0.com/docs/connections/database/mysql#3-provide-action-scripts) and [hooks](https://auth0.com/docs/hooks) to deploy them to Auth0.
This allows you to
- test rules, scripts and hooks dedicated to be deployed to Auth0, as they can be required in node as well.
- import other modules by using `require` statements with relative file paths. This way common functionality can be shared between rules.
- write your rules using the whole ES2015 feature set, as the rules will be transpiled at bundle time.
- pass in configuration at bundling time which can be used in your rule when it is executed.## API
### `createBundler`
```
const createBundler = require('auth0-bundler');const bundler = createBundler(options);
```#### Options
* `nodeVersion`: the node version that should be targeted (used for `@babel/preset-env`), the default is `4`
### bundler.bundleScript(injectedConfig, scriptFilename) -> Promise\
### bundler.bundleRule(injectedConfig, ruleFilename) -> Promise\
### bundler.bundleHook(injectedConfig, hookFilename) -> Promise\Bundles a single script, rule or hook so it can be deployed to Auth0. The rule needs to be written as a commonjs
module that exports a single function. This function takes an additional first parameter compared to being defined in Auth0: The `injectedConfig` that can be specified at bundle time. Modules required from the `node_modules` folder will not be bundled and will be required in the Auth0 environment as well. Auth0 provides a number of modules inside the Auth0 environment, to check whether a module can be required check [webtaskio-canirequire](https://tehsis.github.io/webtaskio-canirequire/).__Example__:
Rule:
```js
// my-rule.js
// Example rule to be deployed to auth0// This dependency will be automatically bundled into the rule
const doRequest = require('../common/function');
// This dependency will be loaded using require
const R = require('ramda');module.exports = function myRule(config, user, context, callback) {
return doRequest(`${config.baseUrl}/some/endpoint`, user).then(function (result) {
callback(null, R.merge({ some: 'result' }, result), context);
});
};
```Bundle dependencies:
```js
const createBundler = require('auth0-bundler');
const bundler = createBundler();
const config = { baseUrl: 'https://www.example.com' };bundler
.bundleRule(config, `${__dirname}/my-rule.js`)
.then(console.log);
```## Using auth0-bundler during deployment
This is an example on how to use auth0-bundler and the Auth0 Management API client to automatically
deploy a rule using auth0-bundler. Like this you can automatically deploy rules e.g. during a
CI run.```js
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
token: '{YOUR_API_V2_TOKEN}',
domain: '{YOUR_ACCOUNT}.auth0.com'
});
const createBundler = require('auth0-bundler');
const bundler = createBundler();
const config = { baseUrl: 'https://www.example.com' };bundler.bundleRule(config, `${__dirname}/my-rule.js`).then((bundledRule) => {
return management.createRule({
enabled: true,
name: 'my-rule',
order: 1,
stage: 'login_success',
script: bundledRule
});
});
```## License
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
[npm-image]: https://img.shields.io/npm/v/auth0-bundler.svg
[npm-url]: https://npmjs.org/package/auth0-bundler
[travis-ci-image]: https://img.shields.io/travis/holidaycheck/auth0-bundler/master.svg
[travis-ci-url]: https://travis-ci.org/holidaycheck/auth0-bundler
[license-image]: http://img.shields.io/npm/l/auth0-lock.svg
[license-url]: #license