Skip to content

Commit

Permalink
feat: add hygen script for bootstrapping new templates
Browse files Browse the repository at this point in the history
  • Loading branch information
johneke-auth0 committed Jan 29, 2024
1 parent 6983a66 commit 1e87ee7
Show file tree
Hide file tree
Showing 19 changed files with 1,380 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
### Actions Templates

For best practices, please review [our documentaton](https://auth0.com/docs/customize/actions/actions-templates#best-practices) and accompanying coding guidelines

To create a new actions template, follow the steps below:

1. Make sure you have all npm modules installed: `npm i` (from the root of this repo)
2. Generate a new actions template and follow all prompts: `npm run add:template` (from the root of this repo)
3. Open the newly generated `manifest.yaml` file and make sure to update it and fill in any other extra details such as secrets, and notes.
4. Open the newly generated `code.js` file and make sure to add your code implementation within the relevant generated exported functions
5. Make sure to test your `code.js` in a live tenant of your own to make sure it works as expected.
6. Once ready, create a pull request with your new actions template.
14 changes: 14 additions & 0 deletions _templates/generator/template/code.js.CREDENTIALS_EXCHANGE.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: "<%= trigger == 'CREDENTIALS_EXCHANGE' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a Client Credentials exchange.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about client credentials grant request.
* @param {CredentialsExchangeAPI} api - Interface whose methods can be used to change the behavior of client credentials grant.
*/
exports.onExecuteCredentialsExchange = async (event, api) => {
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
to: "<%= trigger == 'PASSWORD_RESET_POST_CHALLENGE' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a Password Reset / Post Challenge Flow.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about the post challenge request.
* @param {PasswordResetPostChallengeAPI} api - Interface whose methods can be used to change the behavior of the post challenge flow.
*/
exports.onExecutePostChallenge = async (event, api) => {
};


/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostChallenge function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PasswordResetPostChallengeAPI} api - Interface whose methods can be used to change the behavior of the post challenge flow.
*/
// exports.onContinuePostChallenge = async (event, api) => {
// };
14 changes: 14 additions & 0 deletions _templates/generator/template/code.js.POST_CHANGE_PASSWORD.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: "<%= trigger == 'POST_CHANGE_PASSWORD' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a PostChangePassword flow.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about the user and the context in which the change password is happening.
* @param {PostChangePasswordAPI} api - Methods and utilities to help change the behavior after a user changes their password.
*/
exports.onExecutePostChangePassword = async (event, api) => {
};
24 changes: 24 additions & 0 deletions _templates/generator/template/code.js.POST_LOGIN.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
to: "<%= trigger == 'POST_LOGIN' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a PostLogin flow.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
};

/**
* Handler that will be invoked when this action is resuming after an external redirect. If your
* onExecutePostLogin function does not perform a redirect, this function can be safely ignored.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
// exports.onContinuePostLogin = async (event, api) => {
// };
14 changes: 14 additions & 0 deletions _templates/generator/template/code.js.POST_USER_REGISTRATION.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: "<%= trigger == 'POST_USER_REGISTRATION' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about the context and user that has registered.
* @param {PostUserRegistrationAPI} api - Methods and utilities to help change the behavior after a signup.
*/
exports.onExecutePostUserRegistration = async (event, api) => {
};
14 changes: 14 additions & 0 deletions _templates/generator/template/code.js.PRE_USER_REGISTRATION.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: "<%= trigger == 'PRE_USER_REGISTRATION' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a PreUserRegistration flow.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
exports.onExecutePreUserRegistration = async (event, api) => {
};
14 changes: 14 additions & 0 deletions _templates/generator/template/code.js.SEND_PHONE_MESSAGE.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
to: "<%= trigger == 'SEND_PHONE_MESSAGE' ? `templates/${fileName}-${trigger}/code.js` : null %>"
---

/**
* Handler that will be called during the execution of a SendPhoneMessage flow.
*
* --- AUTH0 ACTIONS TEMPLATE https://github.com/auth0/opensource-marketplace/blob/main/templates/<%= fileName %>-<%= trigger %> ---
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {SendPhoneMessageAPI} api - Methods and utilities to help change the behavior of sending a phone message.
*/
exports.onExecuteSendPhoneMessage = async (event, api) => {
};
20 changes: 20 additions & 0 deletions _templates/generator/template/manifest.yaml.CREDENTIALS_EXCHANGE.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'CREDENTIALS_EXCHANGE' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "CREDENTIALS_EXCHANGE"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'PASSWORD_RESET_POST_CHALLENGE' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "PASSWORD_RESET_POST_CHALLENGE"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
20 changes: 20 additions & 0 deletions _templates/generator/template/manifest.yaml.POST_CHANGE_PASSWORD.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'POST_CHANGE_PASSWORD' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "POST_CHANGE_PASSWORD"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
20 changes: 20 additions & 0 deletions _templates/generator/template/manifest.yaml.POST_LOGIN.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'POST_LOGIN' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "POST_LOGIN"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'POST_USER_REGISTRATION' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "POST_USER_REGISTRATION"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'PRE_USER_REGISTRATION' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "PRE_USER_REGISTRATION"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
20 changes: 20 additions & 0 deletions _templates/generator/template/manifest.yaml.SEND_PHONE_MESSAGE.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
to: "<%= trigger == 'SEND_PHONE_MESSAGE' ? `templates/${fileName}-${trigger}/manifest.yaml` : null %>"
---
name: "<%= name %>"
triggers:
- "SEND_PHONE_MESSAGE"
useCases:
-
public: true
description: "<%= description %>"
version: "1.0.0"
runtime: "node18"
secrets:
-
config:
-
sourceUrl: "https://github.com/auth0/opensource-marketplace/tree/main/templates/<%= fileName %>-<%= trigger %>/manifest.yaml"
modules:
-
notes: ""
72 changes: 72 additions & 0 deletions _templates/generator/template/prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { kebabCase } = require('lodash');

const TRIGGERS = [
'POST_LOGIN',
'CREDENTIALS_EXCHANGE',
'PRE_USER_REGISTRATION',
'POST_USER_REGISTRATION',
'POST_CHANGE_PASSWORD',
'SEND_PHONE_MESSAGE',
'PASSWORD_RESET_POST_CHALLENGE',
];

module.exports = {
prompt: ({ inquirer }) => {
const questions = [
{
type: 'input',
name: 'name',
message:
"Please provide a concise title for the actions template you'd like to create. For example: 'Quadruple Factor Authentication'",
},
{
type: 'input',
name: 'description',
message:
"Please provide a short description of this actions template. For example: 'Enforces quadruple factor authentication when John Doe logs in on a Tuesday'",
},
{
type: 'input',
name: 'trigger',
message: `What trigger is this actions template for? Your options are: ${TRIGGERS.map((t) => `\n ${t}`).join('')}`,
},
];

return inquirer.prompt(questions).then((answers) => {
const { name, description, trigger } = answers;

let error = false;

if (!name) {
console.log('Must specify a name for your actions template');
error = true;
}

if (!description) {
console.log('Must specify a name for your actions template');
error = true;
}

if (TRIGGERS.indexOf(trigger) === -1) {
console.log(
'Must specify a valid trigger for your actions template'
);
error = true;
}

if (error) {
throw new Error('inout validation failed');
}

const fileName = kebabCase(name);

return {
...answers,
name,
description,
trigger,
fileName,
};
});
},
};
Loading

0 comments on commit 1e87ee7

Please sign in to comment.