@warriorteam/redai-zalo-sdk 1.11.1 → 1.12.0
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/CHANGELOG.md +41 -0
- package/README.md +33 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/services/user.service.js +1 -1
- package/dist/services/user.service.js.map +1 -1
- package/dist/types/webhook.d.ts +24 -0
- package/dist/types/webhook.d.ts.map +1 -1
- package/dist/types/webhook.js +110 -0
- package/dist/types/webhook.js.map +1 -1
- package/docs/WEBHOOK_MESSAGE_HELPERS.md +230 -0
- package/examples/webhook-message-classification.ts +285 -0
- package/package.json +1 -1
- package/ARCHITECTURE.md +0 -265
- package/SERVICES_ADDED.md +0 -540
- package/UPDATE_ARTICLE_STATUS.md +0 -152
package/ARCHITECTURE.md
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
# RedAI Zalo SDK Architecture
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
RedAI Zalo SDK là một TypeScript SDK hoàn chỉnh cho các API của Zalo, được thiết kế với kiến trúc modular và type-safe.
|
|
6
|
-
|
|
7
|
-
## Cấu trúc thư mục
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
redai-zalo-sdk/
|
|
11
|
-
├── src/
|
|
12
|
-
│ ├── types/ # Type definitions
|
|
13
|
-
│ │ ├── common.ts # Common types và interfaces
|
|
14
|
-
│ │ ├── auth.ts # Authentication types
|
|
15
|
-
│ │ ├── oa.ts # Official Account types
|
|
16
|
-
│ │ ├── message.ts # Message types
|
|
17
|
-
│ │ └── webhook.ts # Webhook types
|
|
18
|
-
│ ├── clients/ # HTTP clients
|
|
19
|
-
│ │ ├── base-client.ts # Base HTTP client
|
|
20
|
-
│ │ └── zalo-client.ts # Zalo-specific client
|
|
21
|
-
│ ├── services/ # Business logic services
|
|
22
|
-
│ │ ├── auth.service.ts # Authentication service
|
|
23
|
-
│ │ ├── oa.service.ts # Official Account service
|
|
24
|
-
│ │ └── message.service.ts # Message service
|
|
25
|
-
│ ├── utils/ # Utility functions
|
|
26
|
-
│ ├── index.ts # Main export file
|
|
27
|
-
│ └── zalo-sdk.ts # Main SDK class
|
|
28
|
-
├── examples/ # Usage examples
|
|
29
|
-
├── dist/ # Build output
|
|
30
|
-
├── package.json
|
|
31
|
-
├── tsconfig.json
|
|
32
|
-
└── README.md
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Kiến trúc chính
|
|
36
|
-
|
|
37
|
-
### 1. Layered Architecture
|
|
38
|
-
|
|
39
|
-
SDK được thiết kế theo kiến trúc phân lớp:
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
┌─────────────────┐
|
|
43
|
-
│ Main SDK │ ← ZaloSDK class (public API)
|
|
44
|
-
├─────────────────┤
|
|
45
|
-
│ Services │ ← Business logic (AuthService, OAService, MessageService)
|
|
46
|
-
├─────────────────┤
|
|
47
|
-
│ Clients │ ← HTTP communication (BaseClient, ZaloClient)
|
|
48
|
-
├─────────────────┤
|
|
49
|
-
│ Types │ ← Type definitions và interfaces
|
|
50
|
-
└─────────────────┘
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 2. Core Components
|
|
54
|
-
|
|
55
|
-
#### ZaloSDK (Main Class)
|
|
56
|
-
- Entry point cho tất cả các chức năng
|
|
57
|
-
- Khởi tạo và quản lý các services
|
|
58
|
-
- Cung cấp quick methods cho các tác vụ phổ biến
|
|
59
|
-
- Quản lý configuration và lifecycle
|
|
60
|
-
|
|
61
|
-
#### BaseClient
|
|
62
|
-
- HTTP client cơ bản với axios
|
|
63
|
-
- Retry mechanism
|
|
64
|
-
- Error handling
|
|
65
|
-
- Request/response logging
|
|
66
|
-
- File upload support
|
|
67
|
-
|
|
68
|
-
#### ZaloClient
|
|
69
|
-
- Extends BaseClient
|
|
70
|
-
- Zalo-specific endpoints
|
|
71
|
-
- API versioning support
|
|
72
|
-
- OAuth và ZNS endpoint handling
|
|
73
|
-
|
|
74
|
-
#### Services
|
|
75
|
-
- **AuthService**: OAuth flows, token management
|
|
76
|
-
- **OAService**: Official Account operations
|
|
77
|
-
- **MessageService**: Message sending và file upload
|
|
78
|
-
|
|
79
|
-
### 3. Type System
|
|
80
|
-
|
|
81
|
-
#### Comprehensive Types
|
|
82
|
-
- Tất cả API responses được type-safe
|
|
83
|
-
- Union types cho message types
|
|
84
|
-
- Enum cho constants
|
|
85
|
-
- Generic types cho reusability
|
|
86
|
-
|
|
87
|
-
#### Error Handling
|
|
88
|
-
- Custom `ZaloSDKError` class
|
|
89
|
-
- Structured error information
|
|
90
|
-
- Error code mapping
|
|
91
|
-
|
|
92
|
-
### 4. Configuration
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
interface ZaloSDKConfig {
|
|
96
|
-
appId: string;
|
|
97
|
-
appSecret: string;
|
|
98
|
-
timeout?: number;
|
|
99
|
-
debug?: boolean;
|
|
100
|
-
apiBaseUrl?: string;
|
|
101
|
-
retry?: {
|
|
102
|
-
attempts?: number;
|
|
103
|
-
delay?: number;
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Design Patterns
|
|
109
|
-
|
|
110
|
-
### 1. Builder Pattern
|
|
111
|
-
SDK configuration với default values và validation.
|
|
112
|
-
|
|
113
|
-
### 2. Service Pattern
|
|
114
|
-
Mỗi service chịu trách nhiệm cho một domain cụ thể.
|
|
115
|
-
|
|
116
|
-
### 3. Factory Pattern
|
|
117
|
-
Client creation và service initialization.
|
|
118
|
-
|
|
119
|
-
### 4. Strategy Pattern
|
|
120
|
-
Different authentication flows (OA vs Social).
|
|
121
|
-
|
|
122
|
-
### 5. Observer Pattern
|
|
123
|
-
Webhook event handling (planned).
|
|
124
|
-
|
|
125
|
-
## Key Features
|
|
126
|
-
|
|
127
|
-
### 1. Type Safety
|
|
128
|
-
- Full TypeScript support
|
|
129
|
-
- Comprehensive type definitions
|
|
130
|
-
- Generic types cho flexibility
|
|
131
|
-
- Union types cho message variants
|
|
132
|
-
|
|
133
|
-
### 2. Error Handling
|
|
134
|
-
- Structured error responses
|
|
135
|
-
- Retry mechanism
|
|
136
|
-
- Detailed error information
|
|
137
|
-
- Error code mapping
|
|
138
|
-
|
|
139
|
-
### 3. Authentication
|
|
140
|
-
- OAuth 2.0 flows
|
|
141
|
-
- PKCE support
|
|
142
|
-
- Token refresh
|
|
143
|
-
- Multiple auth scopes
|
|
144
|
-
|
|
145
|
-
### 4. Extensibility
|
|
146
|
-
- Modular architecture
|
|
147
|
-
- Easy to add new services
|
|
148
|
-
- Plugin-ready design
|
|
149
|
-
- Custom request support
|
|
150
|
-
|
|
151
|
-
### 5. Developer Experience
|
|
152
|
-
- IntelliSense support
|
|
153
|
-
- Comprehensive documentation
|
|
154
|
-
- Usage examples
|
|
155
|
-
- Debug logging
|
|
156
|
-
|
|
157
|
-
## API Design Principles
|
|
158
|
-
|
|
159
|
-
### 1. Consistency
|
|
160
|
-
- Consistent naming conventions
|
|
161
|
-
- Uniform error handling
|
|
162
|
-
- Standard response formats
|
|
163
|
-
|
|
164
|
-
### 2. Simplicity
|
|
165
|
-
- Easy-to-use public API
|
|
166
|
-
- Quick methods cho common tasks
|
|
167
|
-
- Sensible defaults
|
|
168
|
-
|
|
169
|
-
### 3. Flexibility
|
|
170
|
-
- Low-level access khi cần
|
|
171
|
-
- Custom request support
|
|
172
|
-
- Configurable behavior
|
|
173
|
-
|
|
174
|
-
### 4. Reliability
|
|
175
|
-
- Retry mechanisms
|
|
176
|
-
- Error recovery
|
|
177
|
-
- Connection testing
|
|
178
|
-
|
|
179
|
-
## Future Enhancements
|
|
180
|
-
|
|
181
|
-
### 1. Additional Services
|
|
182
|
-
- ZNS Service (Zalo Notification Service)
|
|
183
|
-
- User Management Service
|
|
184
|
-
- Group Management Service
|
|
185
|
-
- Webhook Service
|
|
186
|
-
|
|
187
|
-
### 2. Advanced Features
|
|
188
|
-
- Rate limiting
|
|
189
|
-
- Caching
|
|
190
|
-
- Batch operations
|
|
191
|
-
- Real-time subscriptions
|
|
192
|
-
|
|
193
|
-
### 3. Developer Tools
|
|
194
|
-
- CLI tools
|
|
195
|
-
- Testing utilities
|
|
196
|
-
- Mock server
|
|
197
|
-
- Documentation generator
|
|
198
|
-
|
|
199
|
-
## Testing Strategy
|
|
200
|
-
|
|
201
|
-
### 1. Unit Tests
|
|
202
|
-
- Service logic testing
|
|
203
|
-
- Type validation
|
|
204
|
-
- Error handling
|
|
205
|
-
|
|
206
|
-
### 2. Integration Tests
|
|
207
|
-
- API endpoint testing
|
|
208
|
-
- Authentication flows
|
|
209
|
-
- File upload/download
|
|
210
|
-
|
|
211
|
-
### 3. E2E Tests
|
|
212
|
-
- Complete workflows
|
|
213
|
-
- Real API interactions
|
|
214
|
-
- Error scenarios
|
|
215
|
-
|
|
216
|
-
## Performance Considerations
|
|
217
|
-
|
|
218
|
-
### 1. HTTP Optimization
|
|
219
|
-
- Connection pooling
|
|
220
|
-
- Request compression
|
|
221
|
-
- Timeout management
|
|
222
|
-
|
|
223
|
-
### 2. Memory Management
|
|
224
|
-
- Efficient data structures
|
|
225
|
-
- Stream processing cho large files
|
|
226
|
-
- Garbage collection friendly
|
|
227
|
-
|
|
228
|
-
### 3. Network Efficiency
|
|
229
|
-
- Batch requests
|
|
230
|
-
- Caching strategies
|
|
231
|
-
- Retry with backoff
|
|
232
|
-
|
|
233
|
-
## Security
|
|
234
|
-
|
|
235
|
-
### 1. Token Management
|
|
236
|
-
- Secure token storage
|
|
237
|
-
- Automatic refresh
|
|
238
|
-
- Token validation
|
|
239
|
-
|
|
240
|
-
### 2. Request Security
|
|
241
|
-
- HTTPS only
|
|
242
|
-
- Request signing
|
|
243
|
-
- Parameter validation
|
|
244
|
-
|
|
245
|
-
### 3. Error Information
|
|
246
|
-
- Sanitized error messages
|
|
247
|
-
- No sensitive data in logs
|
|
248
|
-
- Secure debugging
|
|
249
|
-
|
|
250
|
-
## Deployment
|
|
251
|
-
|
|
252
|
-
### 1. Package Distribution
|
|
253
|
-
- NPM package
|
|
254
|
-
- TypeScript declarations
|
|
255
|
-
- Source maps
|
|
256
|
-
|
|
257
|
-
### 2. Versioning
|
|
258
|
-
- Semantic versioning
|
|
259
|
-
- Backward compatibility
|
|
260
|
-
- Migration guides
|
|
261
|
-
|
|
262
|
-
### 3. Documentation
|
|
263
|
-
- API documentation
|
|
264
|
-
- Usage examples
|
|
265
|
-
- Migration guides
|