ti2 1.0.115 → 1.0.118
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.
- package/README.md +1 -0
- package/__tests__/cache.js +64 -0
- package/api.yml +112 -0
- package/cache.js +74 -30
- package/controllers/__tests__/bookings-searchProducts.js +483 -8
- package/controllers/__tests__/bookings.js +53 -0
- package/controllers/bookings.js +352 -48
- package/index.js +3 -0
- package/package.json +1 -1
- package/test/plugin.js +41 -0
- package/tutorials/plugin-development.md +2 -0
- package/.windsurfrules +0 -9
- package/CLAUDE.md +0 -159
package/CLAUDE.md
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
Ti2 (Tourism Information Interchange) is an open-source integration framework for the tourism industry. It provides standardized functions for bookings, content, and rates management through a plugin-based architecture.
|
|
8
|
-
|
|
9
|
-
## Critical Development Rules
|
|
10
|
-
|
|
11
|
-
1. **Docker Container Execution**: ALL commands must be run inside the `ti2` Docker container
|
|
12
|
-
- The codebase is located at `/ti2` path inside the container
|
|
13
|
-
- This project is part of `node_modules/ti2` in the container environment
|
|
14
|
-
- **NEVER run npm, node, or npx commands on the host machine**
|
|
15
|
-
- Always use: `docker exec ti2 bash -c "cd /ti2 && <command>"`
|
|
16
|
-
- Example for npm install: `docker exec ti2 bash -c "cd /ti2 && npm install <package>"`
|
|
17
|
-
|
|
18
|
-
2. **Testing Rules**:
|
|
19
|
-
- Tests MUST be run inside the Docker container
|
|
20
|
-
- Example: `docker exec ti2 bash -c "cd /ti2 && npx jest lib/__tests__/callback.js --forceExit"`
|
|
21
|
-
- Use `test/utils.js` for mocking the environment
|
|
22
|
-
- Review test utility implementations before writing/editing tests
|
|
23
|
-
|
|
24
|
-
3. **Background Jobs**:
|
|
25
|
-
- Jobs sent to the queue run on a separate worker thread/instance
|
|
26
|
-
- Use `worker/queue.js` `listJobs` function to check job status
|
|
27
|
-
- Workers are always assumed to be running
|
|
28
|
-
|
|
29
|
-
4. **Code Confidence**: Do not make changes until 95% confident. Ask follow-up questions if uncertain.
|
|
30
|
-
|
|
31
|
-
## Common Development Commands
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
# Run tests (inside Docker container)
|
|
35
|
-
docker exec ti2 bash -c "cd /ti2 && npm test"
|
|
36
|
-
docker exec ti2 bash -c "cd /ti2 && npx jest [test-file] --forceExit"
|
|
37
|
-
|
|
38
|
-
# Run specific test file
|
|
39
|
-
docker exec ti2 bash -c "cd /ti2 && npx jest controllers/__tests__/bookings.js --forceExit"
|
|
40
|
-
|
|
41
|
-
# Database migrations
|
|
42
|
-
docker exec ti2 bash -c "cd /ti2 && npm run sequelize db:migrate"
|
|
43
|
-
|
|
44
|
-
# Generate documentation
|
|
45
|
-
docker exec ti2 bash -c "cd /ti2 && npm run doc"
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Architecture
|
|
49
|
-
|
|
50
|
-
### Core Components
|
|
51
|
-
|
|
52
|
-
1. **Main Entry Point** (`index.js`):
|
|
53
|
-
- Initializes Express server on port 10010 (default)
|
|
54
|
-
- Sets up Swagger documentation at `/api-docs`
|
|
55
|
-
- Handles plugin instantiation and middleware
|
|
56
|
-
- Implements caching mechanism
|
|
57
|
-
- Manages background job processing via `worker/queue.js`
|
|
58
|
-
|
|
59
|
-
2. **API Definition** (`api.yml`):
|
|
60
|
-
- OpenAPI 3.0.0 specification
|
|
61
|
-
- Defines all endpoints and schemas
|
|
62
|
-
- JWT Bearer authentication
|
|
63
|
-
|
|
64
|
-
3. **Plugin System**:
|
|
65
|
-
- Two types: Integration Plugins (connect systems) and App Plugins (value-added tools)
|
|
66
|
-
- Plugins are instantiated with cache, axios, events, and configuration
|
|
67
|
-
- Plugin schemas are merged with main API schema
|
|
68
|
-
- Each plugin gets its own routes under `/apps/{pluginName}`
|
|
69
|
-
|
|
70
|
-
4. **Controllers** (`controllers/`):
|
|
71
|
-
- `app.js`: Core application controller
|
|
72
|
-
- `bookings.js`: Booking operations (searchProducts, createBooking, etc.)
|
|
73
|
-
- `admin.js`: Administrative functions
|
|
74
|
-
- `user.js`: User management
|
|
75
|
-
- `ping.js`: Health check endpoints
|
|
76
|
-
- `allotment.js`: Allotment management
|
|
77
|
-
|
|
78
|
-
5. **Database Models** (`models/`):
|
|
79
|
-
- Sequelize ORM with MySQL
|
|
80
|
-
- Key models: Integration, User, UserAppKey, CronJobs, ApiCronJobs
|
|
81
|
-
- Migrations in `migrations/` directory
|
|
82
|
-
|
|
83
|
-
6. **Worker System** (`worker/`):
|
|
84
|
-
- Bull queue for background job processing
|
|
85
|
-
- Redis-backed job queue
|
|
86
|
-
- Supports plugin jobs, API jobs, and callback jobs
|
|
87
|
-
- Multi-worker support with throng
|
|
88
|
-
|
|
89
|
-
7. **Authentication** (`auth/authHandler.js`):
|
|
90
|
-
- JWT-based authentication
|
|
91
|
-
- Bearer token scheme
|
|
92
|
-
|
|
93
|
-
### Key Features
|
|
94
|
-
|
|
95
|
-
- **Caching**: Redis-based caching with configurable TTL
|
|
96
|
-
- **Event System**: EventEmitter2 for plugin communication
|
|
97
|
-
- **Background Jobs**: Async job processing with Bull/Redis
|
|
98
|
-
- **Cron Jobs**: Scheduled task execution
|
|
99
|
-
- **Multi-tenancy**: Support for multiple integrations/plugins
|
|
100
|
-
|
|
101
|
-
### Plugin Development
|
|
102
|
-
|
|
103
|
-
Plugins must implement standard methods:
|
|
104
|
-
- `validateToken`: Token validation
|
|
105
|
-
- `tokenTemplate`: Token configuration template
|
|
106
|
-
- Booking methods: `searchProducts`, `searchAvailability`, `createBooking`, `cancelBooking`
|
|
107
|
-
- Content methods: `getProducts`, `getProduct`, `createProduct`, `updateProduct`
|
|
108
|
-
|
|
109
|
-
### Testing Strategy
|
|
110
|
-
|
|
111
|
-
- Jest testing framework
|
|
112
|
-
- Test fixtures in `__fixtures__/`
|
|
113
|
-
- Mock plugins in `__mocks__/`
|
|
114
|
-
- Use `test/utils.js` for creating test environments
|
|
115
|
-
- Tests organized by controller in `controllers/__tests__/`
|
|
116
|
-
|
|
117
|
-
## Database
|
|
118
|
-
|
|
119
|
-
- Sequelize ORM with MySQL/MariaDB
|
|
120
|
-
- Connection managed through `models/db.js`
|
|
121
|
-
- Migrations handled via sequelize-cli
|
|
122
|
-
- Models auto-loaded from `models/` directory
|
|
123
|
-
|
|
124
|
-
## Environment Variables
|
|
125
|
-
|
|
126
|
-
Key variables:
|
|
127
|
-
- `PORT`: Server port (default: 10010)
|
|
128
|
-
- `REDIS_URL`: Redis connection (default: redis://redis:6379)
|
|
129
|
-
- `jwtSecret`: JWT signing secret
|
|
130
|
-
- `adminKey`: Admin authentication key
|
|
131
|
-
- `WEB_CONCURRENCY`: Number of workers
|
|
132
|
-
- `MAX_JOBS_PER_WORKER`: Job concurrency per worker
|
|
133
|
-
- `SSL_INSECURE_ALLOWED_DOMAINS`: Pipe-separated list of domains where SSL certificate verification is skipped (e.g., `localhost|staging.example.com|192.168.1.100`)
|
|
134
|
-
|
|
135
|
-
Plugin-specific variables follow pattern: `ti2_{pluginName}_{setting}`
|
|
136
|
-
|
|
137
|
-
### SSL Configuration
|
|
138
|
-
|
|
139
|
-
The `SSL_INSECURE_ALLOWED_DOMAINS` environment variable allows you to specify domains where SSL certificate verification should be skipped. This is useful for:
|
|
140
|
-
- Development environments with self-signed certificates
|
|
141
|
-
- Testing against staging servers with invalid certificates
|
|
142
|
-
- Local development with HTTPS
|
|
143
|
-
|
|
144
|
-
Example usage:
|
|
145
|
-
```bash
|
|
146
|
-
# Skip SSL verification for specific domains
|
|
147
|
-
export SSL_INSECURE_ALLOWED_DOMAINS="localhost|staging.api.com|192.168.1.100"
|
|
148
|
-
|
|
149
|
-
# Multiple domains separated by pipe
|
|
150
|
-
export SSL_INSECURE_ALLOWED_DOMAINS="dev.example.com|test.example.com"
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
**Important Implementation Notes**:
|
|
154
|
-
- SSL configuration is ONLY applied to plugin axios instances (for external API calls) and worker axios instances
|
|
155
|
-
- Internal communication (callbacks, per-request axios) do NOT use SSL configuration
|
|
156
|
-
- SSL configuration uses a per-request interceptor approach for better isolation
|
|
157
|
-
- The configuration checks domains dynamically on each request
|
|
158
|
-
|
|
159
|
-
**Warning**: Only use this in development/testing environments. Never skip SSL verification in production for security reasons.
|