{"id":16639012,"url":"https://github.com/cycloidio/auth0-rules-runtime","last_synced_at":"2025-11-02T18:30:34.026Z","repository":{"id":57187097,"uuid":"90394949","full_name":"cycloidio/auth0-rules-runtime","owner":"cycloidio","description":"Wrapper of webtask runtime for helping to write tests for Auth0 rules","archived":false,"fork":false,"pushed_at":"2017-07-17T10:50:20.000Z","size":82,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-18T12:47:01.579Z","etag":null,"topics":["auth0","auth0-rules","runtime","testing","webtask"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cycloidio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-05T16:16:37.000Z","updated_at":"2018-05-08T22:40:12.000Z","dependencies_parsed_at":"2022-08-28T13:00:16.527Z","dependency_job_id":null,"html_url":"https://github.com/cycloidio/auth0-rules-runtime","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fauth0-rules-runtime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fauth0-rules-runtime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fauth0-rules-runtime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycloidio%2Fauth0-rules-runtime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cycloidio","download_url":"https://codeload.github.com/cycloidio/auth0-rules-runtime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239399812,"owners_count":19632022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth0","auth0-rules","runtime","testing","webtask"],"created_at":"2024-10-12T07:04:48.854Z","updated_at":"2025-02-18T02:44:46.473Z","avatar_url":"https://github.com/cycloidio.png","language":"JavaScript","readme":"# Auth0 Rules Runtime\n\nIt's a wrapper of [webtask-runtime](https://github.com/auth0/webtask-runtime) for helping to write tests for [Auth0 rules](https://auth0.com/docs/rules).\n\n## Considerations\n\nThis tool has been developed with NodeJS v7 and we don't think to add support for previous versions.\n\n## Install\n\n`npm install auth0-rules-runtime --save-dev`\n\nNOTE _Yarn_ cannot be used because this tool run in NodeJS v7 (maybe in other previous version if it supports JS2015, but we haven't tried) and we use _auth0-authz-rules-api@^1.0.8_ NPM module for injecting the globals which the Auht0 rules can access, and through it we get a transient dependency (_tedious@~0.1.4_) which specifies that it doesn't support Node v7, so yarn rejects the installation.\n\nWe expect that this module won't affect in the rule testing, if you have a use case that it happens, please open an issue.\n\n## How to use\n\nThis module exports just the next function:\n\n```js\n/**\n * Executes the Auth0 rule contained in the script file with the provided\n * user and context object and optionally adding the configuration to the\n * global scope of the sandbox where the rule is actually executed.\n *\n * @param {string} ruleScriptPath - The path to the script which contains the\n *      Auth0 rule. The path can be absolute or relative. Relative paths are\n *      resolved from the Node process current working directory\n *      @see process.pwd()\n * @param {Object} user - The user data to pass to the rule.\n *      @see {@link https://auth0.com/docs/user-profile/user-profile-structure}\n *      and the specified JSON schema in json-schemas/rule-user-profile.json\n * @param {Object} context - The context data to pass to the rule.\n *      @see {@link https://auth0.com/docs/rules/context}\n *      and the specified JSON schema in json-schemas/rule-ctx.json\n * @param {Object} [configuration] - Key and values settings which are specified\n *      through the Rules UI. The value must be strings.\n * @returns {Promise} - Which rejects when there is any error out of the rule,\n *      for example, if you provided an invalid user or context or configuration\n *      object\n *      The promise resolve with an object with the data passed to the callback\n *      that the rule must call.\n *      The resolved object has an `error` property when the callback is called\n *      with an error. This object is the result of stringifying to JSON the\n *      original Error instance and parsed back to a JS Object. Otherwise the\n *      resolved object has an `user` an `\n *      - {Object} [error]: The property exists when the callback is called with\n *              an error. This object is the result of stringifying to JSON the\n *              original Error instance and parsed back to a JS Object.\n *      - {Object} [user]: The property exists when the callback is called\n *              without an error. It contains the value of the user object\n *              passed to the callback.\n *      - {Object} [context]: The property exists when the callback is called\n *              without an error. It contains the value of the context object\n *              passed to the callback.\n */\nfunction exec (ruleScriptPath, user, context, configuration = {})\n```\n\nExample\n\n```js\nconst ruleRt = require('auth0-rules-runtime')\nconst user = { /* Valid Auth0 user profile object */ }\nconst context = { /* Valid Auth0 context object */ }\n\nrun('rules/my-rule.js', user, context)\n.then((result) =\u003e {\n  if (result.error) {\n    console.log(`An error has been returned to the callback. ${result.error.message}`)\n    return\n  }\n\n  const userJSON = JSON.stringify(result.user)\n  const ctxJSON = JSON.stringify(result.context)\n  console.log(`Rule executed successfull. User: ${userJSON} | Ctx: ${ctxJSON}`)\n})\n.catch((e) =\u003e {\n  if (e instanceof SchemaValiationError) {\n    console.log(`There is an error in an entity object: ${e.message}`)\n    console.log(e.validationErrors)\n    return\n  }\n\n  console.log(`Oh no there is an Error: ${e.message}`)\n})\n\n```\n\n**NOTE** if your rules use external dependencies (`require(...)`), they have to be installed by you in your local.\n\nOn the other hand, Auht0 rules can require a specific module version with the syntax `require('module@x.x.x')`, where `module` is the name of the NPM module to require and the `x.x.x`, the version to install. Because, such syntax is specific of the Auth0 rules, this module rewrite those `require` calls in the rules to normal ones, before running them, hence it's you responsibility to install the correct version, of each module that your rules use.\n\n## Auth0 references\n\n* [Rules](https://auth0.com/docs/rules)\n* [Context Argument Properties in Rules](https://auth0.com/docs/rules/context)\n* [Structure of the User Profile](https://auth0.com/docs/user-profile/user-profile-structure)\n\n## Acknowledgements\n\nWe would like to give thanks to the creators and their contributors to the following projects\n\n* [tawawa/auth0-rules-testharness](https://github.com/tawawa/auth0-rules-testharness) because it helped us to find the [repository which has the modules required to run Auth0 rules](https://github.com/auth0/auth0-authz-rules-api)\n* [maxbeatty/auth0-rule-sandbox](https://github.com/maxbeatty/auth0-rule-sandbox) because brought to us the idea of running the rules in a sandbox using the [Node vm standard module](https://nodejs.org/api/vm.html)\n\n\n## License\n\nThe MIT License (MIT) Copyright (c) 2017 cycloid.io Read the LICENSE file for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycloidio%2Fauth0-rules-runtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcycloidio%2Fauth0-rules-runtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycloidio%2Fauth0-rules-runtime/lists"}