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

@peakgateway/sdk

v0.4.12

Published

TypeScript SDK for the Peak Gateway merchant and partner API: hosted checkout, customers, subscriptions, catalog, reporting and webhooks.

Readme

@peakgateway/sdk

TypeScript SDK for the full public Peak Gateway merchant and partner API. Its API classes and models are generated from the public OpenAPI specification, including checkout, transactions, customers, saved payment methods, subscriptions, catalog, reporting and webhooks.

Install

npm install @peakgateway/sdk

Pin an exact version in production and use the release that matches your Gateway environment.

Quick start

Server side, with an API key (keep the key on your server):

import { GatewayPayClient } from '@peakgateway/sdk'

const pay = new GatewayPayClient({
  environment: 'staging', // or 'production'
  apiKey: process.env.GATEWAY_API_KEY!,
})

// Persist this key and the original request before dispatch; reuse on recovery.
const checkoutCreateKey = process.env.CHECKOUT_CREATE_KEY!
const session = await pay.checkoutSessions.create({
  amount: 2500,
  currency: 'USD',
  locationId: process.env.GATEWAY_LOCATION_ID!,
  successUrl: 'https://example.com/checkout/success',
  cancelUrl: 'https://example.com/checkout/cancel',
}, checkoutCreateKey)

console.log(`Send the shopper to ${session.checkoutUrl}`)

Checkout creation requires a nonblank key of at most 64 characters. Recover a lost response with authenticated pay.checkoutSessions.getByKey(checkoutCreateKey, locationId) rather than minting another identity. Changed input under the same key returns HTTP 409; even a lookup 404 does not exclude a delayed original create, so any recovery retry must reuse the original key and body.

Management APIs (customers, subscriptions, catalog, reports, webhooks, API keys):

import { GatewayAdminClient } from '@peakgateway/sdk'

const gateway = new GatewayAdminClient({
  environment: 'production',
  clientId: process.env.GATEWAY_CLIENT_ID,
  clientSecret: process.env.GATEWAY_CLIENT_SECRET,
})

const customers = await gateway.customers.list()

Clients

  • GatewayAdminClient exposes every API class in the public specification. Each operation automatically uses its declared API, payment, authentication or card-present host, even when operations on one API class use different hosts.
  • GatewayPayClient exposes the checkout and shopper-facing API subset used by @peakgateway/web-sdk. Call setSessionToken(token) to authenticate shopper requests on its payment client. Its checkoutSessions API always uses the session-aware payment-host alternative, including session reads and cancellation; management proxies require bearer auth.

Both accept apiKey, clientId + clientSecret, or a tokenProvider that returns a bearer token. API keys are exchanged for short-lived tokens and cached until 60 seconds before expiry. Concurrent requests share the exchange. A supplied tokenProvider takes precedence over apiKey. Use API keys and OAuth secrets only on your server; browser integrations must use a scoped checkout-session token or a suitable user token instead. Reuse one client instance and call close() when finished.

Routing follows the operation's host when an API class spans services: admin.customers.updateCustomer(...) (hosted PUT) uses payUrl, while customer update(...) (PATCH), reads and management operations use gatewayUrl. Checkout shipping configuration (getShippingConfig, upsertShippingConfig, deleteShippingConfig) is exposed on admin.checkoutSessions; the same methods on pay.checkoutSessions also use gatewayUrl. Payment/session calls remain on the pay host.

Public SDK release artifacts include peak-gateway.openapi.json, the merchant-facing document with public server URLs and authentication requirements. The separate gateway-public.openapi.json is the raw generation inventory retained for package verification, not the documentation download.

Public coverage does not imply every operation accepts client credentials. In the public OpenAPI document, OAuth2 requirements name integration-grantable scopes; UserSession requires the access token of a signed-in Peak Gateway dashboard user and cannot be satisfied by API keys or client credentials. Supply that user's token through tokenProvider for human-only operations such as customer OAuth-client management.

CustomerSession is separate from dashboard UserSession and integration OAuth2: supply the signed-in customer's CUSTOMER-principal bearer through tokenProvider for the customer portal, checkout identity and account-credential operations. Dashboard tokens and client credentials do not satisfy customer identity.

Checkout account credentials require three independent proofs: the signed-in CUSTOMER token, the checkout session token and the caller-supplied App Check token. Set the checkout proof with pay.setSessionToken(checkoutSessionToken), then call pay.checkoutSessions.issueCredential(sessionId, appCheckToken). The transport sends X-Session-Token, X-Firebase-AppCheck and the customer bearer. The SDK does not mint proofs or bypass verification.

Customer portal and checkoutAuth.me calls use a customer-tenant Firebase ID token from tokenProvider, not an integration OAuth token or a dashboard-user token. Pass the caller-generated App Check proof through the operation's optional appCheckToken header argument, for example pay.portal.getBalance(undefined, appCheckToken). The published CustomerSession + FirebaseAppCheck security requirement is conjunctive even though the header argument is optional to support other authentication paths. Every portal operation exposes that header, including subscription item quantity, available plans, credit notes, balance, balance transactions and usage records.

Where advertised, account handoff is a separate alternative requiring both X-Checkout-Account-Credential and X-Session-Token, bound to the same checkout and merchant; it is not a bearer-token alternative and does not require a Firebase/App Check pair. Invitation acceptance accepts only the customer Firebase/App Check path, never handoff. The SDK's existing session-token transport remains unchanged; it does not mint account handoff credentials or provide a general custom-header hook.

Transaction export downloads require both reports:export and transactions:read. The authenticated export-access probe requires reports:export to call and returns allowed: false when transactions:read or access to the requested scope is missing, rather than rejecting that decision with a 403. Public permission requirements come from the exposed handler rather than a downstream service's SDK annotations; dunning case reads require billing:read. When a route has multiple public header-conditioned handlers or server alternatives, documented permissions conservatively satisfy all of them. Different any-of groups are not flattened into a weaker OR.

admin.portalSignIn.issue(), .exchange(...) and .revoke() are trusted-browser operations. Run them in a browser on a Gateway-approved, same-site HTTPS origin: the secure HttpOnly trust and CSRF cookies use SameSite=Strict and are not a server-side cookie jar. The SDK uses the /management/api/v1/portal-sign-in/device-trust exposure path to match the cookies' path, includes browser credentials only for this flow, and obtains a fresh CSRF token before each mutation. Issue/revoke require the signed-in user's token; exchange sends the sign-in proof and browser cookie without resolving an OAuth token. These mutations are not automatically replayed or redirected. Other SDK requests continue to omit ambient browser cookies.

Card-present calls through pay.bolt, pay.cloudTerminals and pay.cardPresentTransactionSync retain the pay router's /card-present exposure prefix.

Webhooks

Verify the raw request body before acting on a delivery:

import { WebhookVerifier, isKnownWebhookEvent } from '@peakgateway/sdk'

const verifier = new WebhookVerifier(process.env.GATEWAY_WEBHOOK_SECRET!)
const delivery = await verifier.verifyDelivery(rawBody, signature, timestamp, headers)

const event = delivery.event
if (isKnownWebhookEvent(event) && event.eventType === 'payment.completed') {
  console.log(event.eventId)
}

WebhookEvent has one <Name>Event member per public event type plus UnknownWebhookEvent for an event type newer than your SDK version.

Errors and retries

Handle GatewayError, AuthenticationError, RateLimitError, NetworkError, ServerError, ValidationError and NotFoundError without logging credentials or raw payment payloads. Automatic transient retries apply only to GET/HEAD or requests carrying a nonblank Idempotency-Key (header names are case-insensitive), within the configured maxRetries. Only fetch failures before a response and HTTP 5xx responses are eligible; response-body failures and INTERNAL_STATE_ERROR / PAYMENT_IN_DOUBT outcomes are never replayed. HTTP 4xx responses are not retried, except for the existing one-time authorization refresh where the operation permits it. Other 4xx statuses, including 409, surface as GatewayError, not ServerError. A timeout or unknown outcome may have committed remotely: reconcile it, never repeat the payment with a new idempotency key.

pay.installmentPlans.chargeInstallment(...) makes one wire attempt and does not refresh and resend after a 401, retry a server or transport failure, or follow a redirect. Use the plan's attempt inquiry to reconcile an unknown result before deciding what to do next.

Versioning and support

The package follows semantic versioning; additions are minor releases. Release notes are in CHANGELOG.md. Report security issues to [email protected].

License

MIT: see LICENSE.