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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tatil/server-api

v0.0.3

Published

Tatilsepeti Server Api for Next.js server-side operations

Readme

@tatil/server-api

Tatilsepeti server-side API package. Next.js server components, route handlers ve middleware için token yönetimli API çağrıları sağlar.

Kurulum

yarn add @tatil/server-api

Kullanım

Tatilsepeti API

GET İsteği

import { Tatilsepeti } from '@tatil/server-api';

const data = await Tatilsepeti.get('/tour/list', {
  page: 1,
  pageSize: 20,
});

POST İsteği

import { Tatilsepeti } from '@tatil/server-api';

const result = await Tatilsepeti.post('/hotel/list', {
  checkinDate: '2026-01-17',
  checkoutDate: '2026-01-21',
  pageNumber: 1,
  pageSize: 20,
});

TokenManager

Token expire kontrolü ve refresh işlemleri için:

import { TokenManager } from '@tatil/server-api';

// Token expire kontrolü
const isExpired = TokenManager.isTokenExpired(tokenValue, tokenExpireValue);

// Token yenileme (gerekirse)
const { token, tokenExpire, refreshed } = await TokenManager.refreshTokenIfNeeded(
  tokenValue,
  tokenExpireValue
);

Response Helper

Server response oluşturma:

import { Tatilsepeti, createResponse, createErrorResponse } from '@tatil/server-api';

// Başarılı response
return createResponse('success', data, 200);

// Hata response
return createErrorResponse('Bir hata oluştu', 400);

Veya Tatilsepeti instance üzerinden:

import { Tatilsepeti } from '@tatil/server-api';

// Başarılı response
return Tatilsepeti.createResponse(data, 200);

// Hata response
return Tatilsepeti.createErrorResponse('Bir hata oluştu', 500);

Environment Variables

Bu paket aşağıdaki environment değişkenlerini gerektirir:

API_URL=https://api.example.com
API_USERNAME=your_username
API_PASSWORD=your_password
REKLOG_KEY=your_reklog_key
NODE_ENV=production

Özellikler

  • Otomatik token yönetimi ve refresh
  • Request logging ile Reklog entegrasyonu
  • /api/v1 prefix otomatik eklenir
  • Cookie-based token storage
  • Next.js server components ile tam uyumlu

Örnek Kullanım (Next.js)

Server Component

import { Tatilsepeti } from '@tatil/server-api';

export default async function Page() {
  const tours = await Tatilsepeti.get('/tour/list', { page: 1 });

  return <div>{/* ... */}</div>;
}

Route Handler

import { Tatilsepeti } from '@tatil/server-api';

export async function GET(request) {
  const data = await Tatilsepeti.get('/tour/list');

  if (!data) {
    return Tatilsepeti.createErrorResponse('Failed to fetch', 500);
  }

  return Tatilsepeti.createResponse(data);
}

Middleware

import { TokenManager } from '@tatil/server-api';
import { NextResponse } from 'next/server';

export async function middleware(request) {
  const token = request.cookies.get('token');
  const tokenExpire = request.cookies.get('token_expire');

  const isExpired = TokenManager.isTokenExpired(
    token?.value,
    tokenExpire?.value
  );

  if (isExpired) {
    const { token: newToken } = await TokenManager.refreshTokenIfNeeded(
      token?.value,
      tokenExpire?.value
    );

    const response = NextResponse.next();
    response.cookies.set('token', newToken);
    return response;
  }

  return NextResponse.next();
}

API Metotları

| Metot | Parametreler | Açıklama | |-------|--------------|----------| | get(endpoint, params) | endpoint: string/array, params: object | GET isteği | | post(endpoint, body) | endpoint: string/array, body: object | POST isteği | | createResponse(data, status) | data: any, status: number | Response objesi oluşturur | | createErrorResponse(message, status) | message: string, status: number | Hata response'u oluşturur |

TokenManager Metotları

| Metot | Parametreler | Açıklama | |-------|--------------|----------| | isTokenExpired(token, tokenExpire) | token: string, tokenExpire: string | Token expire kontrolü | | refreshTokenIfNeeded(token, tokenExpire) | token: string, tokenExpire: string | Token yeniler (gerekirse) |

Lisans

MIT