Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raytha Functions: Embeddable functions / scripting #177

Closed
apexdodge opened this issue Dec 27, 2023 · 4 comments
Closed

Raytha Functions: Embeddable functions / scripting #177

apexdodge opened this issue Dec 27, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@apexdodge
Copy link
Contributor

The next big feature will be to permit running server side scripting code directly within the platform, without having to deploy. This will open up a huge amount of capability, but does require coding knowledge.

We will call this feature Raytha Functions.

New left side navigation menu item, only viewable and accessible to those with Manage System permission, will say Functions.

Functions page should:

  1. show a table of existing functions.
  2. show a Create function button

Create function
Form appears with the following fields:

  • Name
  • Developer Name (auto writes as person types Name)
  • Trigger (drop down options with Http Request as the only and default option). In the future we intend to have an Event Trigger and a Timer Trigger and possibly Template Trigger.
  • Code editor that populates with some default code:
/** The following classes are available:
 * API
 * CurrentOrganization
 * CurrentUser
 * Emailer
*/

/** 
 * Receives a get request at /raytha/functions/execute/{developerName}
 * @param {IQueryCollection} query Passed in from .NET's Request.Query
 * @returns {object} of type JsonResult, HtmlResult, or RedirectResult
 */
function get(query) {
    return new JsonResult({ success: true });
    //example 1: return new HtmlResult("<p>Hello World</p>");
    //example 2: return new RedirectResult("https://raytha.com");
}

/** 
 * Receives a post request at /raytha/functions/execute/{developerName}
 * @param {IFormCollection} payload Passed in from .NET's Request.Form
 * @param {IQueryCollection} query Passed in from .NET's Request.Query
 * @returns {object} of type JsonResult, HtmlResult, or RedirectResult
 */
function post(payload, query) {
    return new JsonResult({ success: true });
    //example 1: return new HtmlResult("<p>Hello World</p>");
    //example 2: return new RedirectResult("https://raytha.com");
}

We are going to use ClearScript for embedding javascript:
https://github.com/microsoft/ClearScript?tab=readme-ov-file
https://microsoft.github.io/ClearScript/Examples/Examples.html

Our ClearScript will attach some javascript classes that mimic IActionResult

class JsonResult {
  constructor(obj) {
    this.body = obj;
    this.contentType = "application/json";
  }
}

class HtmlResult {
  constructor(html) {
    this.body = html;
    this.contentType = "text/html";
  }
}

class RedirectResult {
  constructor(url) {
    this.body = url;
    this.contentType = "redirectToUrl";
  }
}

In order for Raytha Functions to be useful, we need to expose an interface that it can interact. The interface should represent functionality for:

  • API (Same functionality as REST API)
  • CurrentOrganization
  • CurrentUser
  • Emailer
  • HttpClient

New appsettings.json configuration:
RAYTHA_FUNCTIONS_TIMEOUT and default to 10000 ms.
RAYTHA_FUNCTIONS_MAX_ACTIVE and default to 5. If 0, disable the feature entirely.

Hitting the endpoints at /raytha/functions/execute/{developerName} will then trigger the correspondin ClearScript function for that DeveloperName if it exists. The running of the clearscript should crash out if it exceeds the timeout in appsettings for safety reasons.

We should be able to edit an existing function, disable / enable it, revert to previous revision, delete it.

@apexdodge apexdodge added the enhancement New feature or request label Dec 27, 2023
@apexdodge apexdodge self-assigned this Dec 27, 2023
@apexdodge apexdodge added this to the v1.2.0 milestone Dec 27, 2023
@bootleg224
Copy link

Functions should probably support current user context and admin context.

I can envision a function that should allow a user to update their own profile. Or an admin context that can list all users

@fasteddys
Copy link

@apexdodge has development stopped..
Was looking forward to adding custom modules or at least the way to add rapidly entities/crud with grid/tables from excel template

@apexdodge
Copy link
Contributor Author

@fasteddys this feature is in development and release is scheduled for April.

@apexdodge
Copy link
Contributor Author

This has been merged into dev and will now undergo testing and QA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants