ntk-cms-api 20.25.2 โ 20.25.4
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 +354 -34
- package/fesm2022/ntk-cms-api.mjs +963 -963
- package/fesm2022/ntk-cms-api.mjs.map +1 -1
- package/index.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,63 +1,383 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NTK CMS API Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**ntk-cms-api** - Complete API service layer and data models for CMS operations
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## ๐ Overview
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The NTK CMS API library provides a comprehensive set of services, models, and utilities for building Content Management System applications. It includes complete API integration, data models, and business logic for various CMS modules.
|
|
8
|
+
|
|
9
|
+
## ๐ Installation
|
|
8
10
|
|
|
9
11
|
```bash
|
|
10
|
-
|
|
12
|
+
npm install ntk-cms-api
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
## ๐ฆ Features
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
### Core Services
|
|
18
|
+
|
|
19
|
+
- **Main Service** - Core API operations and configuration
|
|
20
|
+
- **Log Service** - Logging and error handling
|
|
21
|
+
- **Token Service** - Authentication and authorization
|
|
22
|
+
- **File Service** - File management operations
|
|
23
|
+
- **Link Service** - Link management and routing
|
|
24
|
+
|
|
25
|
+
### Content Management
|
|
26
|
+
|
|
27
|
+
- **News Service** - News article management
|
|
28
|
+
- **Blog Service** - Blog post management
|
|
29
|
+
- **Catalog Service** - Product catalog management
|
|
30
|
+
- **Estate Service** - Real estate management
|
|
31
|
+
- **Member Service** - User and member management
|
|
32
|
+
|
|
33
|
+
### Additional Services
|
|
34
|
+
|
|
35
|
+
- **SMS Service** - SMS notifications
|
|
36
|
+
- **Payment Service** - Payment processing
|
|
37
|
+
- **Ticketing Service** - Support ticket system
|
|
38
|
+
- **Web Designer Service** - Website builder tools
|
|
39
|
+
|
|
40
|
+
## ๐ง Usage
|
|
41
|
+
|
|
42
|
+
### Basic Setup
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { NgModule } from "@angular/core";
|
|
46
|
+
import { HttpClientModule } from "@angular/common/http";
|
|
47
|
+
import { NtkCmsApiModule } from "ntk-cms-api";
|
|
48
|
+
|
|
49
|
+
@NgModule({
|
|
50
|
+
imports: [HttpClientModule, NtkCmsApiModule],
|
|
51
|
+
})
|
|
52
|
+
export class AppModule {}
|
|
17
53
|
```
|
|
18
54
|
|
|
19
|
-
|
|
55
|
+
### Configure API
|
|
20
56
|
|
|
21
|
-
|
|
57
|
+
```typescript
|
|
58
|
+
import { NtkCmsApiService } from "ntk-cms-api";
|
|
22
59
|
|
|
23
|
-
|
|
24
|
-
|
|
60
|
+
export class AppComponent {
|
|
61
|
+
constructor(private apiService: NtkCmsApiService) {
|
|
62
|
+
// Set API configuration
|
|
63
|
+
this.apiService.setApiUrl("https://api.example.com");
|
|
64
|
+
this.apiService.setToken("your-auth-token");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
25
67
|
```
|
|
26
68
|
|
|
27
|
-
|
|
69
|
+
### Using Services
|
|
28
70
|
|
|
29
|
-
|
|
71
|
+
```typescript
|
|
72
|
+
import { NewsService, NewsModel } from "ntk-cms-api";
|
|
30
73
|
|
|
31
|
-
|
|
74
|
+
export class NewsComponent {
|
|
75
|
+
constructor(private newsService: NewsService) {}
|
|
32
76
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
77
|
+
async getNews(): Promise<NewsModel[]> {
|
|
78
|
+
try {
|
|
79
|
+
const result = await this.newsService.ServiceGetAll().toPromise();
|
|
80
|
+
return result.listItems || [];
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("Error fetching news:", error);
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
37
86
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
87
|
+
async createNews(news: NewsModel): Promise<boolean> {
|
|
88
|
+
try {
|
|
89
|
+
const result = await this.newsService.ServiceAdd(news).toPromise();
|
|
90
|
+
return result.isSuccess;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("Error creating news:", error);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
42
98
|
|
|
43
|
-
##
|
|
99
|
+
## ๐ API Reference
|
|
44
100
|
|
|
45
|
-
|
|
101
|
+
### Core Models
|
|
46
102
|
|
|
47
|
-
|
|
48
|
-
|
|
103
|
+
#### NewsModel
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
interface NewsModel {
|
|
107
|
+
id?: string;
|
|
108
|
+
title: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
body?: string;
|
|
111
|
+
linkMainImageId?: number;
|
|
112
|
+
linkMainImageIdSrc?: string;
|
|
113
|
+
createdDate?: Date;
|
|
114
|
+
updatedDate?: Date;
|
|
115
|
+
// ... other properties
|
|
116
|
+
}
|
|
49
117
|
```
|
|
50
118
|
|
|
51
|
-
|
|
119
|
+
#### BlogModel
|
|
52
120
|
|
|
53
|
-
|
|
121
|
+
```typescript
|
|
122
|
+
interface BlogModel {
|
|
123
|
+
id?: string;
|
|
124
|
+
title: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
body?: string;
|
|
127
|
+
linkMainImageId?: number;
|
|
128
|
+
linkMainImageIdSrc?: string;
|
|
129
|
+
createdDate?: Date;
|
|
130
|
+
updatedDate?: Date;
|
|
131
|
+
// ... other properties
|
|
132
|
+
}
|
|
133
|
+
```
|
|
54
134
|
|
|
55
|
-
|
|
56
|
-
|
|
135
|
+
### Service Methods
|
|
136
|
+
|
|
137
|
+
#### NewsService
|
|
138
|
+
|
|
139
|
+
- `ServiceGetAll()` - Get all news articles
|
|
140
|
+
- `ServiceGetById(id: string)` - Get news by ID
|
|
141
|
+
- `ServiceAdd(model: NewsModel)` - Create new news
|
|
142
|
+
- `ServiceEdit(model: NewsModel)` - Update news
|
|
143
|
+
- `ServiceDelete(id: string)` - Delete news
|
|
144
|
+
|
|
145
|
+
#### BlogService
|
|
146
|
+
|
|
147
|
+
- `ServiceGetAll()` - Get all blog posts
|
|
148
|
+
- `ServiceGetById(id: string)` - Get blog by ID
|
|
149
|
+
- `ServiceAdd(model: BlogModel)` - Create new blog
|
|
150
|
+
- `ServiceEdit(model: BlogModel)` - Update blog
|
|
151
|
+
- `ServiceDelete(id: string)` - Delete blog
|
|
152
|
+
|
|
153
|
+
## ๐ Authentication
|
|
154
|
+
|
|
155
|
+
### Token Management
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { TokenService } from "ntk-cms-api";
|
|
159
|
+
|
|
160
|
+
export class AuthService {
|
|
161
|
+
constructor(private tokenService: TokenService) {}
|
|
162
|
+
|
|
163
|
+
async login(username: string, password: string): Promise<boolean> {
|
|
164
|
+
try {
|
|
165
|
+
const result = await this.tokenService.ServiceAccessToken(username, password).toPromise();
|
|
166
|
+
if (result.isSuccess) {
|
|
167
|
+
localStorage.setItem("token", result.token);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error("Login error:", error);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
logout(): void {
|
|
178
|
+
localStorage.removeItem("token");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
isAuthenticated(): boolean {
|
|
182
|
+
return !!localStorage.getItem("token");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## ๐ File Management
|
|
188
|
+
|
|
189
|
+
### File Operations
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { FileService, FileModel } from "ntk-cms-api";
|
|
193
|
+
|
|
194
|
+
export class FileComponent {
|
|
195
|
+
constructor(private fileService: FileService) {}
|
|
196
|
+
|
|
197
|
+
async uploadFile(file: File): Promise<FileModel | null> {
|
|
198
|
+
try {
|
|
199
|
+
const formData = new FormData();
|
|
200
|
+
formData.append("file", file);
|
|
201
|
+
|
|
202
|
+
const result = await this.fileService.ServiceUploadFile(formData).toPromise();
|
|
203
|
+
return result.isSuccess ? result.item : null;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
console.error("Upload error:", error);
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async getFiles(): Promise<FileModel[]> {
|
|
211
|
+
try {
|
|
212
|
+
const result = await this.fileService.ServiceGetAll().toPromise();
|
|
213
|
+
return result.listItems || [];
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.error("Error fetching files:", error);
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## ๐ Internationalization
|
|
223
|
+
|
|
224
|
+
The API library supports multiple languages through the translation service:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { TranslateService } from "ntk-cms-api";
|
|
228
|
+
|
|
229
|
+
export class AppComponent {
|
|
230
|
+
constructor(private translateService: TranslateService) {
|
|
231
|
+
// Set default language
|
|
232
|
+
this.translateService.setDefaultLang("en");
|
|
233
|
+
this.translateService.use("en");
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
changeLanguage(lang: string): void {
|
|
237
|
+
this.translateService.use(lang);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## ๐ง Configuration
|
|
243
|
+
|
|
244
|
+
### Environment Setup
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
// environment.ts
|
|
248
|
+
export const environment = {
|
|
249
|
+
production: false,
|
|
250
|
+
apiUrl: "https://api.example.com",
|
|
251
|
+
apiVersion: "v1",
|
|
252
|
+
timeout: 30000,
|
|
253
|
+
};
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Service Configuration
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { NtkCmsApiService } from "ntk-cms-api";
|
|
260
|
+
|
|
261
|
+
export class AppComponent {
|
|
262
|
+
constructor(private apiService: NtkCmsApiService) {
|
|
263
|
+
// Configure API service
|
|
264
|
+
this.apiService.setApiUrl(environment.apiUrl);
|
|
265
|
+
this.apiService.setTimeout(environment.timeout);
|
|
266
|
+
|
|
267
|
+
// Set default headers
|
|
268
|
+
this.apiService.setDefaultHeaders({
|
|
269
|
+
"Content-Type": "application/json",
|
|
270
|
+
Accept: "application/json",
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## ๐งช Testing
|
|
277
|
+
|
|
278
|
+
### Unit Tests
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { TestBed } from "@angular/core/testing";
|
|
282
|
+
import { HttpClientTestingModule } from "@angular/common/http/testing";
|
|
283
|
+
import { NewsService } from "ntk-cms-api";
|
|
284
|
+
|
|
285
|
+
describe("NewsService", () => {
|
|
286
|
+
let service: NewsService;
|
|
287
|
+
|
|
288
|
+
beforeEach(() => {
|
|
289
|
+
TestBed.configureTestingModule({
|
|
290
|
+
imports: [HttpClientTestingModule],
|
|
291
|
+
providers: [NewsService],
|
|
292
|
+
});
|
|
293
|
+
service = TestBed.inject(NewsService);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("should be created", () => {
|
|
297
|
+
expect(service).toBeTruthy();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should fetch news articles", async () => {
|
|
301
|
+
const result = await service.ServiceGetAll().toPromise();
|
|
302
|
+
expect(result).toBeDefined();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
57
305
|
```
|
|
58
306
|
|
|
59
|
-
|
|
307
|
+
## ๐ Error Handling
|
|
308
|
+
|
|
309
|
+
### Global Error Handler
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
import { Injectable } from "@angular/core";
|
|
313
|
+
import { HttpErrorResponse } from "@angular/common/http";
|
|
314
|
+
import { NtkCmsApiService } from "ntk-cms-api";
|
|
315
|
+
|
|
316
|
+
@Injectable()
|
|
317
|
+
export class GlobalErrorHandler {
|
|
318
|
+
constructor(private apiService: NtkCmsApiService) {}
|
|
319
|
+
|
|
320
|
+
handleError(error: HttpErrorResponse): void {
|
|
321
|
+
if (error.status === 401) {
|
|
322
|
+
// Handle unauthorized access
|
|
323
|
+
this.handleUnauthorized();
|
|
324
|
+
} else if (error.status === 403) {
|
|
325
|
+
// Handle forbidden access
|
|
326
|
+
this.handleForbidden();
|
|
327
|
+
} else {
|
|
328
|
+
// Handle other errors
|
|
329
|
+
console.error("API Error:", error);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private handleUnauthorized(): void {
|
|
334
|
+
// Redirect to login or refresh token
|
|
335
|
+
localStorage.removeItem("token");
|
|
336
|
+
// Redirect to login page
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private handleForbidden(): void {
|
|
340
|
+
// Handle forbidden access
|
|
341
|
+
console.error("Access forbidden");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## ๐ Version History
|
|
347
|
+
|
|
348
|
+
### v18.26.17
|
|
349
|
+
|
|
350
|
+
- Enhanced API services and models
|
|
351
|
+
- Improved error handling
|
|
352
|
+
- Added new content management features
|
|
353
|
+
- Updated TypeScript definitions
|
|
354
|
+
|
|
355
|
+
### v18.26.16
|
|
356
|
+
|
|
357
|
+
- Bug fixes and performance improvements
|
|
358
|
+
- Added new service methods
|
|
359
|
+
- Enhanced authentication system
|
|
360
|
+
|
|
361
|
+
## ๐ค Contributing
|
|
362
|
+
|
|
363
|
+
1. Fork the repository
|
|
364
|
+
2. Create a feature branch
|
|
365
|
+
3. Make your changes
|
|
366
|
+
4. Add tests for new features
|
|
367
|
+
5. Submit a pull request
|
|
368
|
+
|
|
369
|
+
## ๐ License
|
|
370
|
+
|
|
371
|
+
This library is licensed under the ISC License.
|
|
372
|
+
|
|
373
|
+
## ๐ Support
|
|
374
|
+
|
|
375
|
+
For support and questions:
|
|
376
|
+
|
|
377
|
+
- Create an issue on GitHub
|
|
378
|
+
- Contact: [ntk.ir](https://ntk.ir)
|
|
379
|
+
- Documentation: Check the main README.md
|
|
60
380
|
|
|
61
|
-
|
|
381
|
+
---
|
|
62
382
|
|
|
63
|
-
|
|
383
|
+
**Note**: This library is part of the NTK CMS Angular Libraries collection. For more information, see the main project README.
|