Coding Guidelines

All apps that are to be published in Marketplace go through a code review where they are vetted for code quality, correctness, and security. Here are a broad set of guidelines to be followed while developing apps.

Security

The following security-related guidelines are mandatory. We recommend that you follow them even for custom apps.

  • Use secure iparams for sensitive information: Non-secure iparams should not be used to obtain sensitive information, such as API keys, usernames, passwords, during app installation as agents will be able to inspect these values in the browser and access them.
  • Do not log sensitive information: Sensitive information (especially privileged customer/user information) should not be stored in console logs as they are easily accessible.
  • External services must be protected: If an app requires working with an external custom web service (e.g., Heroku), the web service must require authentication for any access so that privileged information is secure and only accessible through the app.
  • Use the Request method for API calls: Wherever requests to external services are to be made from the front end of an app, the Request method must be used. Direct Ajax calls must be eschewed under all circumstances so that the app is compliant with popular security standards.
  • Pack all Freshworks SDK interactions within the app package: All source code that interacts with the Freshworks SDK (for references, see client) must be packed within the app package submitted for review so app users can tell what data from their accounts is used by the apps. Business logic that uses this data can remain outside of the app package, if required. If a large part of the app source code is hosted outside the app, reviewers are likely to seek further information on the overall app architecture and how the business logic makes use of any personal information sourced by the app from a user’s account.
General
  • Test your app : You can test your app by running the following command in your terminal. $ fdk run

    Once you exit testing, the CLI prints the code coverage summary of how extensive your testing was and you can access the coverage report via the link as shown in the image. Each component in the coverage summary should be at least 80% for apps to be submitted in Freshworks Marketplace. To improve code coverage, you would need to test each and every functionality in your app for both success and failure cases, thereby detecting hidden bugs and improving the quality of the app. Here is a coverage report for a JavaScript file.

    The main components of the coverage summary that we deal with are:

    1. Statement coverage: Checks if each statement in the code has been executed at least once.
    2. Branch coverage: Checks if each branch of each control structure has been executed. For example, in an IF statement, both the true and false branches need to be tested.
    3. Function coverage: Checks if each function (or subroutine) has been called in the code.
    4. Line coverage: Checks if each line of code has been executed (excluding comments/ conditionals).
  • Handle failures: All failure cases must be handled in both the front end and back end of your apps. A proper error response must be returned from the serverless component of the app to the front end. This ensures business continuity for users in the face of unexpected errors and avoids negative experiences.
  • Clean up: If any setup actions were performed during the app install (e.g., registering an external webhook), the same must be undone and cleaned up during app uninstall.
  • Use reliable external services: Any external web services used must be capable of supporting considerable load and must have reliable uptime.
  • Readable and maintainable code: All submitted code must be readable and maintainable to ensure faster code review feedback and certification.
  • Do not minify code: Any code submitted with an app (with libraries included as assets) must be provided in an unminified/untranspiled form so that code reviews and app certification processes are faster.