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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sx-community-data

v1.0.5

Published

sx-community data

Downloads

13

Readme

sx-community-api

Setup API

  1. Setup env
SPREADSHEET_ID=
EMPLOYEE_SHEET_RANGE=
MASTER_DATA_SHEET_RANGE=
EMPLOYEE_PHOTO_FOLDER=
CATEGORY_PHOTO_FOLDER=
NEXT_PUBLIC_API_SECRET_KEY=
DRIVE_PHOTO_HOST=
GOOGLE_PROJECT_ID=
GOOGLE_CREDENTIAL_PRIVATE_KEY_ID=
GOOGLE_CREDENTIAL_PRIVATE_KEY=""
GOOGLE_CREDENTIAL_CLIENT_EMAIL=
GOOGLE_CREDENTIAL_CLIENT_ID=
  1. Create new file route.ts inside folder app/api/employee/route.ts and update the code like this
import { type NextRequest, NextResponse } from 'next/server'
import { getAllEmployees } from 'sx-community-data';
 
export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const secretKey = request.headers.get('x-secret-key') ?? searchParams.get('x-secret-key');
    if (secretKey !== process.env.NEXT_PUBLIC_API_SECRET_KEY) {
      return NextResponse.json({
        error_code: 'unauthorized',
        error_message: 'Invalid secret key',
      }, {
        status: 401
      });
    }
    const employees = await getAllEmployees({
      spreadsheetId: process.env.SPREADSHEET_ID!,
      sheetRange: process.env.EMPLOYEE_SHEET_RANGE!,
      photoFolder: process.env.EMPLOYEE_PHOTO_FOLDER!,
    });
   
    return NextResponse.json(employees, {
      status: 200
    });
  } catch (error) {
    console.log(error);
    return NextResponse.json({
      error_code: '00001',
      error_message: 'Internal Server Error',
    }, {
      status: 500
    });
  }
}
  1. Create new file route.ts inside folder pages/api/master-data/route.ts and update the code like this
export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const secretKey = request.headers.get('x-secret-key') ?? searchParams.get('x-secret-key');
    if (secretKey !== process.env.NEXT_PUBLIC_API_SECRET_KEY) {
      return NextResponse.json({
        error_code: 'unauthorized',
        error_message: 'Invalid secret key',
      }, {
        status: 401
      });
    }
    const result = await getMasterDataSource({
      spreadsheetId: process.env.SPREADSHEET_ID!,
      sheetRange: process.env.MASTER_DATA_SHEET_RANGE!,
      photoFolder: process.env.MASTER_SOURCE_PHOTO_FOLDER!,
    });
   
    return NextResponse.json(result, {
      status: 200
    });
  } catch (error) {
    console.log(error);
    return NextResponse.json({
      error_code: '00002',
      error_message: 'Internal Server Error',
    }, {
      status: 500
    });
  }
}

Use API

TODO: fetch/parse response/ handle error

Common function

Filter employee by sub category

const employees = filterEmployee(categoryKey, value, apiResponse);

Model

ApiParam
Employee
MasterData
Category
SubCategory