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

stripe-search-ql

v0.1.1

Published

TypeScript query builder for Stripe Search API

Readme

stripe-search-ql

A TypeScript query builder library for easily constructing queries for the Stripe Search API.

Installation

npm install stripe-search-ql

Usage

Basic Examples

import { stripeQuery } from "stripe-search-ql";

// Exact match search
const query = stripeQuery()
  .field("email")
  .equals("[email protected]")
  .build();
// => 'email:"[email protected]"'

// Numeric comparison
const amountQuery = stripeQuery()
  .field("amount")
  .greaterThan(1000)
  .build();
// => 'amount>1000'

// Substring match
const substringQuery = stripeQuery()
  .field("email")
  .contains("amy")
  .build();
// => 'email~"amy"'

Combining Multiple Conditions

// AND operator
const andQuery = stripeQuery()
  .field("email")
  .equals("[email protected]")
  .and()
  .field("currency")
  .equals("usd")
  .build();
// => 'email:"[email protected]" AND currency:"usd"'

// OR operator
const orQuery = stripeQuery()
  .field("currency")
  .equals("usd")
  .or()
  .field("currency")
  .equals("eur")
  .build();
// => 'currency:"usd" OR currency:"eur"'

Metadata Search

// Exact match for metadata
const metadataQuery = stripeQuery()
  .metadata("donation-id")
  .equals("asdf-jkl")
  .build();
// => 'metadata["donation-id"]:"asdf-jkl"'

// Substring match for metadata
const metadataSubstringQuery = stripeQuery()
  .metadata("key")
  .contains("value")
  .build();
// => 'metadata["key"]~"value"'

Negation Search

// Field negation
const negatedQuery = stripeQuery()
  .not("currency")
  .equals("jpy")
  .build();
// => '-currency:"jpy"'

// Metadata negation
const negatedMetadataQuery = stripeQuery()
  .notMetadata("donation-id")
  .equals("asdf-jkl")
  .build();
// => '-metadata["donation-id"]:"asdf-jkl"'

NULL Value Checks

// Check if field is NULL
const nullCheckQuery = stripeQuery()
  .field("url")
  .isNull()
  .build();
// => 'url:null'

// Check if metadata key does not exist
const metadataNullQuery = stripeQuery()
  .notMetadata("donation-id")
  .isNull()
  .build();
// => '-metadata["donation-id"]:null'

Numeric Comparison Operators

// Greater than
stripeQuery().field("amount").greaterThan(1000).build();
// => 'amount>1000'

// Less than
stripeQuery().field("amount").lessThan(1000).build();
// => 'amount<1000'

// Greater than or equal
stripeQuery().field("amount").greaterThanOrEqual(1000).build();
// => 'amount>=1000'

// Less than or equal
stripeQuery().field("amount").lessThanOrEqual(1000).build();
// => 'amount<=1000'

Complex Query Examples

// Combining multiple conditions
const complexQuery = stripeQuery()
  .field("email")
  .equals("[email protected]")
  .and()
  .metadata("donation-id")
  .equals("asdf-jkl")
  .and()
  .field("amount")
  .greaterThan(1000)
  .build();
// => 'email:"[email protected]" AND metadata["donation-id"]:"asdf-jkl" AND amount>1000'

API Reference

stripeQuery()

Creates a new query builder instance.

Returns: SearchQueryBuilder instance

SearchQueryBuilder

Field Search

  • field(field: string): FieldBuilder - Specify a field to build search conditions
  • not(field: string): FieldBuilder - Specify a negated field to build search conditions

Metadata Search

  • metadata(key: string): MetadataFieldBuilder - Specify a metadata field to build search conditions
  • notMetadata(key: string): MetadataFieldBuilder - Specify a negated metadata field to build search conditions

Logical Operators

  • and(): SearchQueryBuilder - Add AND operator
  • or(): SearchQueryBuilder - Add OR operator

Others

  • build(): string - Returns the constructed query as a string
  • reset(): SearchQueryBuilder - Reset the query

FieldBuilder

  • equals(value: string | number | null): SearchQueryBuilder - Exact match (:)
  • contains(value: string): SearchQueryBuilder - Substring match (~, minimum 3 characters)
  • greaterThan(value: number): SearchQueryBuilder - Greater than (>)
  • lessThan(value: number): SearchQueryBuilder - Less than (<)
  • greaterThanOrEqual(value: number): SearchQueryBuilder - Greater than or equal (>=)
  • lessThanOrEqual(value: number): SearchQueryBuilder - Less than or equal (<=)
  • isNull(): SearchQueryBuilder - NULL value check

MetadataFieldBuilder

  • equals(value: string | number | null): SearchQueryBuilder - Exact match (:)
  • contains(value: string): SearchQueryBuilder - Substring match (~, minimum 3 characters)
  • isNull(): SearchQueryBuilder - NULL value check (when metadata key does not exist)

Integration with Stripe Search API

The constructed query can be used with the Stripe SDK or API client.

import { stripeQuery } from "stripe-search-ql";
import Stripe from "stripe";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

// Build query
const query = stripeQuery()
  .field("email")
  .equals("[email protected]")
  .build();

// Search with Stripe API
const customers = await stripe.customers.search({
  query: query,
});

Limitations

  • Substring match (~) requires a minimum of 3 characters
  • You cannot mix AND and OR in the same query (Stripe Search API limitation)
  • Parentheses for specifying precedence are not supported (Stripe Search API limitation)

Development

# Install dependencies
npm install

# Build
npm run build

# Test
npm test

# Test (watch mode)
npm run test:watch

# Linter
npm run lint

# Formatter
npm run format

# Type check
npm run typecheck

License

MIT