@tulipnpm/timekit_project_selector 2.1.2 → 2.1.3-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ {
2
+ "context": {
3
+ "fileName": "AGENTS.md"
4
+ }
5
+ }
package/AGENTS.md ADDED
@@ -0,0 +1,47 @@
1
+ # Project Context: Tulip Appointments Web Widget
2
+
3
+ ## Overview
4
+ The Tulip Appointments Web Widget (`@tulipnpm/timekit_project_selector`) is a JavaScript library that extends the functionality of [TimeKit's Booking Widget](https://developers.timekit.io/docs/booking-widget-v2). It allows users to set up selectors based on project metadata to filter TimeKit projects for customer bookings. It supports a default UI (Popup or Page mode) and a Custom UI mode.
5
+
6
+ ## Tech Stack
7
+ - **Language:** JavaScript (ES6+)
8
+ - **Build Tool:** Webpack (^5.14.0)
9
+ - **Testing Framework:** Jest (^26.6.3)
10
+ - **Transpilation:** Babel
11
+ - **Key Dependencies:** `axios` (^0.21.1), `lodash` (^4.17.20), `@babel/runtime` (^7.12.5)
12
+ - **Key DevDependencies:** `webpack` (^5.14.0), `jest` (^26.6.3), `babel-loader` (^8.2.2)
13
+
14
+ ## Project Structure
15
+ - **`src/`**: Core source code.
16
+ - **`ConfigurationManager.js`**: Manages widget configurations.
17
+ - **`TimekitApiClient.js`**: Client for interacting with TimeKit API.
18
+ - **`Strategy/`**: Contains strategies for project selection (e.g., `DefaultProjectStrategy`, `LocationsStrategy`).
19
+ - **`Steps/`**: Logic for widget steps (`Step.js`, `StepsFactory.js`).
20
+ - **`ui/`**: UI components (`widget.js`, `searchbar.js`, `embed.js`, etc.).
21
+ - **`styles/`**: CSS files for the widget.
22
+ - **`callbacks/`**: Logic for specific callbacks (e.g., auto-assigning associates).
23
+ - **`test/`**: Test files.
24
+ - **`unittests/`**: Jest unit tests corresponding to source files.
25
+ - **`data/`**: Mock data for tests.
26
+ - HTML files (`custom.html`, `embed.html`, `index.html`) for testing different modes.
27
+ - **`dist/`**: Distribution files (built artifacts).
28
+
29
+ ## Key Scripts
30
+ - **Build:** `npm run build` (runs `webpack`)
31
+ - **Development Server:** `npm run start-dev` (runs `webpack serve --mode development`)
32
+ - **Test:** `npm test` (runs `jest`)
33
+ - **CI Test:** `npm run test:ci` (runs jest with coverage and CI reporters)
34
+ - **Watch:** `npm run watch` (runs `webpack --watch`)
35
+
36
+ ## Development Conventions
37
+ - **Code Style:** Follows standard JavaScript conventions.
38
+ - **Testing:** Unit tests are located in `test/unittests` and mirror the structure of `src`.
39
+ - **Building:** The project uses Webpack to bundle the library for distribution.
40
+ - **Configuration:** Project configurations are managed via `ConfigurationManager`.
41
+
42
+ ## Gotchas & Implementation Details
43
+ - **External Dependencies:** The library relies on `TimekitBooking` being available in the global scope (provided by TimeKit's `booking.min.js`). It is not imported via `npm`.
44
+ - **Symbol Typos:** Note that "Strategy" is misspelled as "Statergy" in several key symbols, including the file `src/Strategy/ServiceProjectsStatergy.js` and its corresponding class name.
45
+ - **Template Resolution:** Card rendering uses a custom template parser in `src/ui/helpers.js` that resolves placeholders like `{{[meta]key}}` or `{{[project]key}}`.
46
+ - **State Management:** The application uses a custom singleton store (`src/ProjectsStore.js`) to manage the state of fetched projects and active filters.
47
+ - **CSS Injection:** Styles are imported in `src/index.js` and injected into the DOM at runtime, typically using Webpack's `style-loader`.
package/README.md CHANGED
@@ -2,14 +2,55 @@
2
2
 
3
3
  The Tulip Appointments Web Widget is a library that extends the functionality of [TimeKit's Booking Widget](https://developers.timekit.io/docs/booking-widget-v2). This library allows users to set up selectors based on project metadata, which will filter down a list of TimeKit projects for a customer to book with. The library has a default UI that embeds on an e-commerce site that can either be customized or overwritten.
4
4
 
5
- ## Installation
5
+ ## Integrator Installation
6
+
7
+ If you are looking to add the Tulip Appointments Web Widget to your website, follow these steps:
6
8
 
7
9
  ```html
10
+ <!-- 1. Required: Timekit's base booking styles -->
8
11
  <link rel="stylesheet" href="https://cdn.timekit.io/booking-js/v3/booking.min.css" />
12
+
13
+ <!-- 2. Required: Timekit's base booking library (Provides the global TimekitBooking constructor) -->
9
14
  <script type="text/javascript" src="//cdn.timekit.io/booking-js/v3/booking.min.js" defer></script>
15
+
16
+ <!-- 3. Required: This library (Tulip Project Selector) -->
10
17
  <script src="https://cdn.jsdelivr.net/npm/@tulipnpm/timekit_project_selector@latest/dist/timekit_project_selector.min.js"></script>
11
18
  ```
12
19
 
20
+ Alternatively, if you are using a module bundler, you can install both via npm:
21
+ `npm install @timekit/booking-js @tulipnpm/timekit_project_selector`
22
+
23
+ ---
24
+
25
+ ## Developer Setup
26
+
27
+ If you are a developer working on the `timekit-ecomm-widget` repository itself, follow these steps to get started:
28
+
29
+ 1. **Clone the repository:**
30
+ ```bash
31
+ git clone git@git.internal.tulip.io:teams/apps/connect/timekit-ecomm-widget.git
32
+ cd timekit-ecomm-widget
33
+ ```
34
+ 2. **Install dependencies:**
35
+ ```bash
36
+ npm install
37
+ ```
38
+ 3. **Local Development:**
39
+ To run the development server with hot-reloading:
40
+ ```bash
41
+ npm run start-dev
42
+ ```
43
+ 4. **Testing:**
44
+ ```bash
45
+ npm test
46
+ ```
47
+ 5. **Build for Production:**
48
+ ```bash
49
+ npm run build
50
+ ```
51
+
52
+ ---
53
+
13
54
  ## Initialization
14
55
 
15
56
  To initialize the Tulip Appointments Web Widget on your site, you first need to import all required libraries onto your webpage (see above). After the library is installed, set up is as easy as running a single function:
@@ -25,6 +66,16 @@ timekit_project_selector.init({
25
66
 
26
67
  This will connect to TimeKit's API and load in all the required data. Once the initialization is completed, the exposed methods will be able to be used. If enabled, it will also render the default UI.
27
68
 
69
+ ### TimekitBooking Dependency
70
+
71
+ This library does not bundle the core Timekit booking logic. It relies on the global `TimekitBooking` constructor, which is provided by the **Timekit Booking JS library** mentioned in the [Installation](#installation) section.
72
+
73
+ You can provide this dependency in two ways:
74
+ 1. **CDN (Recommended for simple integration):** Include the `booking.min.js` script tag.
75
+ 2. **NPM:** Install `@timekit/booking-js`. If using NPM, ensure that `TimekitBooking` is available on the `window` object, as this library looks for the global variable when a project is selected.
76
+
77
+ The `selectProject` method internally initializes a new `TimekitBooking` instance to render the final calendar view. Without this dependency, the widget will fail at the final step.
78
+
28
79
  ---
29
80
 
30
81
  ## Configurations
@@ -283,7 +334,7 @@ timekit_project_selector.init({
283
334
 
284
335
  ### Automatically Assign Associates To Bookings (Optional)
285
336
 
286
- Once bokings are created associates must be manually assigned to those bookings. This automatically assigns assigns associates when bookings are created. To automatically assign associates to bookings the `shouldAutomaticallyBookAssociates` configuration option can be set to `true`.
337
+ Once bookings are created associates must be manually assigned to those bookings. This automatically assigns associates when bookings are created. To automatically assign associates to bookings the `shouldAutomaticallyBookAssociates` configuration option can be set to `true`.
287
338
 
288
339
  ```js
289
340
  timekit_project_selector.init({
@@ -340,9 +391,7 @@ timekit_project_selector.getStrategy('store_project');
340
391
  ```
341
392
  #### getProjects()
342
393
 
343
- Returns a list of TimeKit projects
344
- Optionally takes project type for return projects by project type only.(Filters not using if null)
345
- Optionally takes filters for return filtered projects
394
+ Returns a list of TimeKit projects. Accepts an optional `filters` object to filter the results.
346
395
 
347
396
  ```js
348
397
  await timekit_project_selector.getStrategy('store_project').getProjects({ id: 'ef0cee8a-6096-453f-a634-1597b359cdfa'});
@@ -381,6 +430,20 @@ Opens the BookingJS widget for the selected project. Takes a TimeKit Project as
381
430
  timekit_project_selector.selectProject(timekitProject);
382
431
  ```
383
432
 
433
+ ### getStepsFactory
434
+
435
+ Returns the steps factory instance which helps track the state of selection steps.
436
+
437
+ ```js
438
+ timekit_project_selector.getStepsFactory();
439
+ ```
440
+
441
+ ---
442
+
443
+ ## Architecture
444
+
445
+ For a detailed breakdown of how the widget manages project selection logic and wizard steps, see the [Strategies and Steps Architecture](docs/STRATEGIES_AND_STEPS.md) documentation.
446
+
384
447
  ## Supported Use Cases (Default UI)
385
448
  ### Global Appointment Type -> Store -> Booking.js
386
449
  ```js
@@ -499,10 +562,6 @@ timekit_project_selector.selectProject(timekitProject);
499
562
  let serviceHtml = '';
500
563
  let locationHtml = '';
501
564
 
502
- // You could use simple array instead of using the steps factor.
503
- // This factory makes it simple to track which TK project uuids were selected
504
- let stepsFactory = tps.getStepsFactory();
505
-
506
565
  // Fetch the service_project
507
566
  let globalProjects = await tps.getStrategy('service_project').getProjects({ t_private: 0, t_disabled: 0 });
508
567