npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ntk-cms-api

v20.25.52

Published

Ntk Cms Api And Model For Typscript

Readme

NTK CMS API Library

ntk-cms-api - Complete API service layer and data models for CMS operations

📋 Overview

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.

🚀 Installation

npm install ntk-cms-api

📦 Features

Core Services

  • Main Service - Core API operations and configuration
  • Log Service - Logging and error handling
  • Token Service - Authentication and authorization
  • File Service - File management operations
  • Link Service - Link management and routing

Content Management

  • News Service - News article management
  • Blog Service - Blog post management
  • Catalog Service - Product catalog management
  • Estate Service - Real estate management
  • Member Service - User and member management

Additional Services

  • SMS Service - SMS notifications
  • Payment Service - Payment processing
  • Ticketing Service - Support ticket system
  • Web Designer Service - Website builder tools

🔧 Usage

Basic Setup

import { NgModule } from "@angular/core";
import { HttpClientModule } from "@angular/common/http";
import { NtkCmsApiModule } from "ntk-cms-api";

@NgModule({
  imports: [HttpClientModule, NtkCmsApiModule],
})
export class AppModule {}

Configure API

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");
  }
}

Using Services

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;
    }
  }
}

📚 API Reference

Core Models

NewsModel

interface NewsModel {
  id?: string;
  title: string;
  description?: string;
  body?: string;
  linkMainImageId?: number;
  linkMainImageIdSrc?: string;
  createdDate?: Date;
  updatedDate?: Date;
  // ... other properties
}

BlogModel

interface BlogModel {
  id?: string;
  title: string;
  description?: string;
  body?: string;
  linkMainImageId?: number;
  linkMainImageIdSrc?: string;
  createdDate?: Date;
  updatedDate?: Date;
  // ... other properties
}

Service Methods

NewsService

  • ServiceGetAll() - Get all news articles
  • ServiceGetById(id: string) - Get news by ID
  • ServiceAdd(model: NewsModel) - Create new news
  • ServiceEdit(model: NewsModel) - Update news
  • ServiceDelete(id: string) - Delete news

BlogService

  • ServiceGetAll() - Get all blog posts
  • ServiceGetById(id: string) - Get blog by ID
  • ServiceAdd(model: BlogModel) - Create new blog
  • ServiceEdit(model: BlogModel) - Update blog
  • ServiceDelete(id: string) - Delete blog

🔐 Authentication

Token Management

📁 File Management

File Operations

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 [];
    }
  }
}

🌐 Internationalization

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);
  }
}

🔧 Configuration

Environment Setup

// environment.ts
export const environment = {
  production: false,
  apiUrl: "https://api.example.com",
  apiVersion: "v1",
  timeout: 30000,
};

Service Configuration

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",
    });
  }
}

🧪 Testing

Unit Tests

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();
  });
});

📊 Error Handling

Global Error Handler

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 handleForbidden(): void {
    // Handle forbidden access
    console.error("Access forbidden");
  }
}

🔄 Version History

v18.26.17

  • Enhanced API services and models
  • Improved error handling
  • Added new content management features
  • Updated TypeScript definitions

v18.26.16

  • Bug fixes and performance improvements
  • Added new service methods
  • Enhanced authentication system

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new features
  5. Submit a pull request

📄 License

This library is licensed under the ISC License.

🆘 Support

For support and questions:

  • Create an issue on GitHub
  • Contact: ntk.ir
  • Documentation: Check the main README.md

Note: This library is part of the NTK CMS Angular Libraries collection. For more information, see the main project README.