npm package: @initiative-ui/initiative-trial-web-js
Description: This project handles all the interactions and technical aspects necessary for the system designed with Webflow for creating the Initiative Trial System. It has been written with Vite Js, and the final distribution is a module that binds several page handl
Latest version: 0.14.0

# Trial Web Js
This project handles all the interactions and technical aspects necessary for the system designed with Webflow for creating the Initiative Trial System. It has been written with Vite Js, and the final distribution is a module that binds several page handlers to the window object, which are then used in Webflow for binding the interaction to the page.

# Installation
After cloning the repository, install all required dependencies using `npm ci` command.

# Development mode
Use `npm run dev` to start the development mode. In the Webflow project, you need to pass the `dev` query string to each page to read the JS module from your dev environment. Please verify the Custom Codes section of Webflow project settings to make sure it reads the JS module from the proper URL (currently set to http://localhost:5173/) and modify it if necessary. For example, to load the `/sign-up` page in dev mode, you need to open `/sign-up?dev` in your browser.

# How to collaborate
Create your branch from the main branch with a name starting with either `feature/` or `bugfix/`. After you push, the GitHub workflow will be triggered and will build and push the beta version to the npm repository. The Webflow project checks the URL and loads the beta version for the staging environment.

# Page handlers
Page handlers are the main entry point of Webflow project. If you look at the script section of each Webflow page, you will find out a call to a page handler like `Signup.handle()`. In order to add a new page handler for a new Webflow page, you need to:
- Create a new class extending `PageHandler` and put it in `handlers` directory.
- Switch to `index.js` root file and import your class.
- Create a new instance of your class and add it to `window` object with a proper name.
- Call your handler in Webflow page script section.

# Api
You can find all the back-end services provided by Initiative Trial Api projecrt in `api` directory.

# Third party services
All third party services like `intercom` and `segment` are added into `services` directory and wrapped in a proper js class. To add a new service, follow these steps:
- Create a new class and put it in `services` directory.
- Switch to `PageHandler` root class and add a new function for your service in `addThirdPartyServices` function.
- Call `addScript` and pass the script of your service using the necessary environment variables.
- Add your new env variables, both in `.env.example` file and github workflows under `.github` directory.

# Utils
This directory includes some utility classes for handling validation and data transfer between Webflow pages.

## Store
This class is responsible for saving/retrieval of input values used for transferring data between Webflow pages.

## Validation
This class provides proper validation errors for input elements of the Webflow project. It handles generic and custom validation errors.