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

@codeswayam/api-client

v1.3.1

Published

CodeSwayam Professional SaaS SDK

Readme

@codeswayam/api-client

Low-level HTTP client and typed API functions for the Codeswayam platform. Used internally by @codeswayam/auth — most apps should use that package instead.

Installation

npm install @codeswayam/api-client

When to use this directly

Use @codeswayam/api-client directly when:

  • Writing server-side code (NestJS services, Next.js server actions)
  • Building admin tools that need raw API access
  • You need functions not exposed by @codeswayam/auth

For everything else, use @codeswayam/auth.


SDK Class

import { CodeSwayamSDK } from '@codeswayam/api-client';

const sdk = new CodeSwayamSDK({
  baseUrl: process.env.NEXT_PUBLIC_API_URL,
  onUnauthorized: () => redirectToLogin(),
});

// Auth
const profile = await sdk.auth.getProfile();

// Billing
const subs = await sdk.billing.getSubscriptions();

// Credits
const wallet = await sdk.credits.getWallet();

// Entitlements
const canUse = sdk.entitlements.canAccess('smart_ai', activeSubs);
const remaining = sdk.entitlements.getRemainingLimit('max_automations', 5, activeSubs);

// Full profile in one call
const { profile, subscriptions, wallet } = await sdk.getFullProfile();

Auth Functions

import { getSession, fetchProfile, updateProfile, logout } from '@codeswayam/api-client';

const user = await getSession();           // { id, email, name, access_scopes }
const profile = await fetchProfile();
await updateProfile({ name: 'New Name' });
await logout();

Subscription Functions

import {
  fetchPublicPlans,
  fetchUserSubscriptions,
  fetchSubscriptionById,
  createRazorpayOrder,
  verifyRazorpayPayment,
  changeSubscriptionPlan,
  cancelUserSubscription,
} from '@codeswayam/api-client';

// Public plans (no auth needed)
const { products, bundles } = await fetchPublicPlans();

// User's subscriptions
const subs = await fetchUserSubscriptions();
const sub = await fetchSubscriptionById(123);

// Payment — pass returnUrl for cross-domain redirect, and optional upgradeFromSubscriptionId
const order = await createRazorpayOrder({
  saasProductId: 1,
  billingCycle: 'monthly',
  currency: 'INR',
  returnUrl: `${window.location.origin}/dashboard`,
  upgradeFromSubscriptionId: 123, // Optional: old subscription ID to upgrade from (prorates cost)
});

await verifyRazorpayPayment({
  razorpay_order_id: order.orderId,
  razorpay_payment_id: paymentId,
  razorpay_signature: signature,
  saasProductId: 1,
  billingCycle: 'monthly',
  currency: 'INR',
  amount: order.amount,
  upgradeFromSubscriptionId: 123, // Pass old subscription ID to automatically cancel it upon payment success
});

// Upgrade/downgrade
await changeSubscriptionPlan(subId, {
  saasProductId: 2,
  billingCycle: 'yearly',
  currency: 'INR',
});

await cancelUserSubscription(subId);

Credits Functions

import {
  fetchMyWallet,
  fetchCreditPacks,
  fetchFeatureCosts,
  createCreditPurchaseOrder,
  verifyCreditPurchase,
  useCredits,
} from '@codeswayam/api-client';

const { wallet, transactions } = await fetchMyWallet();
const packs = await fetchCreditPacks();
const costs = await fetchFeatureCosts('auraflow');

// Deduct credits (server-side)
await useCredits({ saasId: 'auraflow', featureKey: 'ai_chat', quantity: 1 });

Cross-Domain Auth

All functions automatically inject the Bearer token from localStorage for cross-domain compatibility:

import { getAuthHeaders } from '@codeswayam/api-client';

// Use in any custom fetch call
const headers = getAuthHeaders();
fetch(`${apiUrl}/my-endpoint`, { headers });

Referrals & Coupons

import { fetchReferralStats, redeemReferralCode, redeemCouponCode } from '@codeswayam/api-client';

const stats = await fetchReferralStats();
await redeemReferralCode('FRIEND123');
await redeemCouponCode('LAUNCH50');

Push Notifications

import { registerPushSubscription, fetchVapidPublicKey } from '@codeswayam/api-client';

const { publicKey } = await fetchVapidPublicKey();
const sub = await navigator.serviceWorker.ready.then(sw =>
  sw.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: publicKey })
);
await registerPushSubscription(sub.toJSON(), 'auraflow');