
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socketโs new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
ntk-cms-api
Advanced tools
ntk-cms-api - Complete API service layer and data models for CMS operations
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.
npm install ntk-cms-api
import { NgModule } from "@angular/core";
import { HttpClientModule } from "@angular/common/http";
import { NtkCmsApiModule } from "ntk-cms-api";
@NgModule({
imports: [HttpClientModule, NtkCmsApiModule],
})
export class AppModule {}
import { NtkCmsApiService } from "ntk-cms-api";
export class AppComponent {
constructor(private apiService: NtkCmsApiService) {
// Set API configuration
this.apiService.setApiUrl("https://api.example.com");
this.apiService.setToken("your-auth-token");
}
}
import { NewsService, NewsModel } from "ntk-cms-api";
export class NewsComponent {
constructor(private newsService: NewsService) {}
async getNews(): Promise<NewsModel[]> {
try {
const result = await this.newsService.ServiceGetAll().toPromise();
return result.listItems || [];
} catch (error) {
console.error("Error fetching news:", error);
return [];
}
}
async createNews(news: NewsModel): Promise<boolean> {
try {
const result = await this.newsService.ServiceAdd(news).toPromise();
return result.isSuccess;
} catch (error) {
console.error("Error creating news:", error);
return false;
}
}
}
interface NewsModel {
id?: string;
title: string;
description?: string;
body?: string;
linkMainImageId?: number;
linkMainImageIdSrc?: string;
createdDate?: Date;
updatedDate?: Date;
// ... other properties
}
interface BlogModel {
id?: string;
title: string;
description?: string;
body?: string;
linkMainImageId?: number;
linkMainImageIdSrc?: string;
createdDate?: Date;
updatedDate?: Date;
// ... other properties
}
ServiceGetAll()
- Get all news articlesServiceGetById(id: string)
- Get news by IDServiceAdd(model: NewsModel)
- Create new newsServiceEdit(model: NewsModel)
- Update newsServiceDelete(id: string)
- Delete newsServiceGetAll()
- Get all blog postsServiceGetById(id: string)
- Get blog by IDServiceAdd(model: BlogModel)
- Create new blogServiceEdit(model: BlogModel)
- Update blogServiceDelete(id: string)
- Delete blogimport { TokenService } from "ntk-cms-api";
export class AuthService {
constructor(private tokenService: TokenService) {}
async login(username: string, password: string): Promise<boolean> {
try {
const result = await this.tokenService.ServiceAccessToken(username, password).toPromise();
if (result.isSuccess) {
localStorage.setItem("token", result.token);
return true;
}
return false;
} catch (error) {
console.error("Login error:", error);
return false;
}
}
logout(): void {
localStorage.removeItem("token");
}
isAuthenticated(): boolean {
return !!localStorage.getItem("token");
}
}
import { FileService, FileModel } from "ntk-cms-api";
export class FileComponent {
constructor(private fileService: FileService) {}
async uploadFile(file: File): Promise<FileModel | null> {
try {
const formData = new FormData();
formData.append("file", file);
const result = await this.fileService.ServiceUploadFile(formData).toPromise();
return result.isSuccess ? result.item : null;
} catch (error) {
console.error("Upload error:", error);
return null;
}
}
async getFiles(): Promise<FileModel[]> {
try {
const result = await this.fileService.ServiceGetAll().toPromise();
return result.listItems || [];
} catch (error) {
console.error("Error fetching files:", error);
return [];
}
}
}
The API library supports multiple languages through the translation service:
import { TranslateService } from "ntk-cms-api";
export class AppComponent {
constructor(private translateService: TranslateService) {
// Set default language
this.translateService.setDefaultLang("en");
this.translateService.use("en");
}
changeLanguage(lang: string): void {
this.translateService.use(lang);
}
}
// environment.ts
export const environment = {
production: false,
apiUrl: "https://api.example.com",
apiVersion: "v1",
timeout: 30000,
};
import { NtkCmsApiService } from "ntk-cms-api";
export class AppComponent {
constructor(private apiService: NtkCmsApiService) {
// Configure API service
this.apiService.setApiUrl(environment.apiUrl);
this.apiService.setTimeout(environment.timeout);
// Set default headers
this.apiService.setDefaultHeaders({
"Content-Type": "application/json",
Accept: "application/json",
});
}
}
import { TestBed } from "@angular/core/testing";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { NewsService } from "ntk-cms-api";
describe("NewsService", () => {
let service: NewsService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [NewsService],
});
service = TestBed.inject(NewsService);
});
it("should be created", () => {
expect(service).toBeTruthy();
});
it("should fetch news articles", async () => {
const result = await service.ServiceGetAll().toPromise();
expect(result).toBeDefined();
});
});
import { Injectable } from "@angular/core";
import { HttpErrorResponse } from "@angular/common/http";
import { NtkCmsApiService } from "ntk-cms-api";
@Injectable()
export class GlobalErrorHandler {
constructor(private apiService: NtkCmsApiService) {}
handleError(error: HttpErrorResponse): void {
if (error.status === 401) {
// Handle unauthorized access
this.handleUnauthorized();
} else if (error.status === 403) {
// Handle forbidden access
this.handleForbidden();
} else {
// Handle other errors
console.error("API Error:", error);
}
}
private handleUnauthorized(): void {
// Redirect to login or refresh token
localStorage.removeItem("token");
// Redirect to login page
}
private handleForbidden(): void {
// Handle forbidden access
console.error("Access forbidden");
}
}
This library is licensed under the ISC License.
For support and questions:
Note: This library is part of the NTK CMS Angular Libraries collection. For more information, see the main project README.
FAQs
Ntk Cms Api And Model For Typscript
The npm package ntk-cms-api receives a total of 134 weekly downloads. As such, ntk-cms-api popularity was classified as not popular.
We found that ntk-cms-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socketโs new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.