@strimz/shared-types

v0.15.0

Published

Zod schemas and inferred TypeScript types for every Strimz platform entity, API input, and webhook event.

Readme

@strimz/shared-types

Zod schemas and inferred TypeScript types for every Strimz entity, API input, and webhook event.

npm version npm downloads bundle size types License: MIT

The Zod schema is the source of truth. TypeScript types are inferred from it, so the wire format and the compile-time shape can never drift apart. Each request schema xInputSchema has two types: XInput (z.input<>) is the body a caller sends, where a field with a default is optional; XParsed (z.output<>) is the value after xInputSchema.parse, with every default filled in. The Strimz SDK consumes this package internally, but you can use the schemas and types directly if you prefer to validate the wire format in your own code.

Install

pnpm add @strimz/shared-types
# npm install @strimz/shared-types
# yarn add @strimz/shared-types

Quick start

import {
  createPaymentSessionInputSchema,
  type CreatePaymentSessionParsed,
} from '@strimz/shared-types'

const parsed: CreatePaymentSessionParsed = createPaymentSessionInputSchema.parse(req.body)

Exhaustive webhook handling

import { webhookEventSchema, type StrimzWebhookEvent } from '@strimz/shared-types/events'

function handle(event: StrimzWebhookEvent) {
  switch (event.type) {
    case 'payment.completed':
      // event.data is typed as { session, transaction }
      break
    case 'subscription.charge_failed':
      // event.data is typed as { subscription, charge }
      break
    // TypeScript enforces exhaustiveness over the discriminated union.
  }
}

Modules

Every group is also available as a subpath import for tree-shaking.

| Subpath | Contains | | ------------------- | ------------------------------------------------------------------------------------------------------- | | /common | Primitives: ids, EVM address, tx hash, email, URL, money, pagination, metadata, mode, tier, environment | | /merchants | Merchant entity, login, member invites, tier changes | | /api-keys | Secret and publishable keys, scopes, rotation | | /customers | Payer identity | | /payment-sessions | One-shot session entity, state machine, createPaymentSessionInputSchema | | /transactions | Confirmed on-chain payment records | | /subscriptions | Plans, active subscriptions, per-period charges (with chargeAttemptId) | | /refunds | Merchant-initiated refund entity + signature flow | | /webhooks | Endpoints, deliveries, replay | | /compliance | Screening log schema (wallet screening isn't part of checkout today) | | /agents | Identity, merchant config, activity log, ERC-8183 jobs | | /storefronts | Storefront + product | | /invoices | Invoice + line items | | /events | Discriminated StrimzWebhookEvent union covering every webhook payload shape | | /analytics | Stats queries and responses: summary, volume, MRR, LTV, forecast |

The package root re-exports every subpath, plus the token, contact and notification schemas, which have no subpath of their own.

Runtime support

Pure TypeScript. Runtime dependencies are zod and @strimz/shared-config (which brings in viem). Works in Node 22+, every modern browser, Vercel Edge, Cloudflare Workers, Deno, and Bun.

Design notes

  • Schemas describe wire format. No business logic, no persistence, no side effects.
  • Amounts are decimal strings of the token's smallest unit (USDC has 6 decimals, so "1000000" is 1 USDC). This preserves precision beyond Number.MAX_SAFE_INTEGER.
  • EVM addresses are normalised to lowercase on parse. Transaction hashes are preserved verbatim.
  • Optional vs nullable is a real distinction. Fields marked .optional() accept omission. Fields marked .nullable() accept explicit null. The two are not interchangeable on the wire.

Links

License

MIT © Strimz