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

@hidayetcanozcan/nucleus-generic-api-caller

v1.0.1

Published

Type-safe generic API caller for Next.js Server Actions with automatic CRUD generation, React hooks, and CustomFetch integration.

Readme

🔌 Nucleus Generic API Caller

Internal package for Nucleus project. This package is published for internal use and is not accepting external contributions.

Type-safe API caller for Next.js Server Actions with automatic CRUD endpoint generation from database schemas.

Overview

  • Server-side API factory with automatic token refresh and cookie handling
  • Generic CRUD endpoints generated from schema definitions
  • Type-safe React hooks for API calls
  • Built on @hidayetcanozcan/custom-fetch

Installation

bun add @hidayetcanozcan/nucleus-generic-api-caller @hidayetcanozcan/custom-fetch

Nucleus Project Setup

1. Create Config File

// lib/api/config.ts
import type { NucleusApiConfig } from "@hidayetcanozcan/nucleus-generic-api-caller";
import { generateGenericEndpoints } from "@hidayetcanozcan/nucleus-generic-api-caller";
import * as AllSchemas from "@monorepo/db-entities/schemas";
import { customSettings } from "./custom-settings";
import { vorionSettings } from "./vorion";

const { endpoints: genericEndpoints, settings: genericSettings } = generateGenericEndpoints(AllSchemas);

export const Endpoints = {
  ...genericEndpoints,
  ...CustomEndpoints,
  ...VorionEndpoints,
};

export const apiConfig: NucleusApiConfig = {
  baseUrl: process.env.AUTH_API_URL!,
  alternateBaseUrl: process.env.VORION_API_URL,
  shouldUseAlternateUrl: (endpoint) => endpoint.startsWith("Vorion: "),
  settings: {
    ...genericSettings,
    ...customSettings,
    ...vorionSettings,
  },
  authCookieName: "nucleus_access_token",
  refreshCookieName: "nucleus_refresh_token",
  refreshEndpoint: "/v2/auth/refresh",
  refreshExcludedEndpoints: ["Login", "Login V2", "Register V2", "Refresh V2", "Logout V2"],
  authCreationEndpoints: ["Login", "Login V2", "Register V2"],
  cookieSettingEndpoints: ["Login", "Login V2", "Register V2"],
  logoutEndpoint: "Logout",
  enableBypassHeader: process.env.BYPASS_IDENTITY_MIDDLEWARE === "true",
  debug: process.env.NODE_ENV === "development",
};

2. Create Factory (Server Action)

// lib/api/factory.ts
"use server";

import { cookies, headers } from "next/headers";
import { CustomFetch } from "@hidayetcanozcan/custom-fetch";
import { createNucleusApiFactory } from "@hidayetcanozcan/nucleus-generic-api-caller/server";
import { apiConfig, Endpoints } from "./config";

const NucleusApi = createNucleusApiFactory(apiConfig);

export async function FactoryFunction<Payload, Success, Error>(
  payload: Payload,
  endpoint: string,
) {
  const cookieStore = await cookies();
  const headersList = await headers();

  return NucleusApi<Payload, Success, Error>(payload, endpoint, {
    cookies: {
      get: (name) => cookieStore.get(name),
      set: (name, value, opts) => cookieStore.set(name, value, opts),
      delete: (name) => cookieStore.delete(name),
    },
    headers: {
      get: (name) => headersList.get(name),
      forEach: (cb) => headersList.forEach(cb),
    },
  });
}

export async function Factory({ endpoint }: { endpoint: string }) {
  return (payload: unknown, ep: string) => FactoryFunction(payload, ep);
}

export { Endpoints };

3. Create Hook (Client)

// lib/api/hook.ts
"use client";

import { createNucleusApiHook } from "@hidayetcanozcan/nucleus-generic-api-caller/client";
import * as AllSchemas from "@monorepo/db-entities/schemas";
import { Endpoints, Factory } from "./factory";
import { CustomEndpoints } from "./custom-endpoints";
import type { ActionTypes } from "./types";

export const useGenericApiActions = createNucleusApiHook<typeof Endpoints, ActionTypes>({
  endpoints: Endpoints,
  customEndpoints: CustomEndpoints,
  schemas: AllSchemas,
  factory: async (endpoint) => Factory({ endpoint }),
  routerPush: (path) => {
    if (typeof window !== "undefined") window.location.href = path;
  },
});

4. Usage in Components

"use client";

import { useGenericApiActions } from "@/lib/api/hook";

export function UserList() {
  const actions = useGenericApiActions();

  const loadUsers = () => {
    actions.GET_USERS?.start({
      payload: { page: 1, limit: 10 },
      onAfterHandle: (data) => console.log("Users:", data),
      onErrorHandle: (error) => console.error("Error:", error),
    });
  };

  return (
    <div>
      <button onClick={loadUsers} disabled={actions.GET_USERS?.state?.isPending}>
        {actions.GET_USERS?.state?.isPending ? "Loading..." : "Load Users"}
      </button>
    </div>
  );
}

API Reference

| Export | Description | |--------|-------------| | createNucleusApiFactory | Server-side API factory | | createNucleusApiHook | Client-side React hook | | generateGenericEndpoints | CRUD generator from schemas | | GenericMethods | Enum: GET, CREATE, UPDATE, DELETE, TOGGLE, VERIFICATION |

License

MIT - Internal use only.