CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-graphql-scalars

A collection of scalar types not included in base GraphQL.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

financial.mddocs/

Financial Scalars

Financial data validation including currencies, bank account numbers, and routing information. These scalars provide validation for financial data commonly used in payment processing, banking, and e-commerce applications.

Capabilities

Currency Scalar

Validates ISO 4217 currency codes.

/**
 * GraphQL scalar for ISO 4217 currency code validation
 * Accepts 3-letter currency codes as defined by ISO 4217
 */
const GraphQLCurrency: GraphQLScalarType;

Example Values:

  • "USD" (US Dollar)
  • "EUR" (Euro)
  • "GBP" (British Pound)
  • "JPY" (Japanese Yen)
  • "CAD" (Canadian Dollar)
  • "AUD" (Australian Dollar)
  • "CHF" (Swiss Franc)

USCurrency Scalar

Validates US currency amounts and format.

/**
 * GraphQL scalar for US currency validation
 * Accepts US dollar amounts in various formats
 */
const GraphQLUSCurrency: GraphQLScalarType;

Example Values:

  • "$10.50"
  • "$1,234.56"
  • "$0.99"
  • "$1000000.00"

IBAN Scalar

Validates International Bank Account Number format.

/**
 * GraphQL scalar for IBAN validation
 * Accepts International Bank Account Number with country-specific formatting
 * Includes check digit validation
 */
const GraphQLIBAN: GraphQLScalarType;

Example Values:

  • "GB82 WEST 1234 5698 7654 32" (UK)
  • "DE89 3704 0044 0532 0130 00" (Germany)
  • "FR14 2004 1010 0505 0001 3M02 606" (France)
  • "IT60 X054 2811 1010 0000 0123 456" (Italy)

RoutingNumber Scalar

Validates US bank routing numbers (ABA routing transit numbers).

/**
 * GraphQL scalar for US bank routing number validation
 * Accepts 9-digit ABA routing transit numbers with check digit validation
 */
const GraphQLRoutingNumber: GraphQLScalarType;

Example Values:

  • "021000021" (Chase Bank)
  • "026009593" (Bank of America)
  • "111000025" (Wells Fargo)
  • "122000247" (Citibank)

AccountNumber Scalar

Validates bank account numbers.

/**
 * GraphQL scalar for bank account number validation
 * Accepts various bank account number formats
 */
const GraphQLAccountNumber: GraphQLScalarType;

Example Values:

  • "1234567890"
  • "0123456789"
  • "987654321012"

Usage Examples

import { 
  GraphQLCurrency,
  GraphQLUSCurrency,
  GraphQLIBAN,
  GraphQLRoutingNumber,
  GraphQLAccountNumber
} from "graphql-scalars";

// In a GraphQL schema
const PaymentMethodType = new GraphQLObjectType({
  name: "PaymentMethod",
  fields: {
    currency: { type: GraphQLCurrency },
    iban: { type: GraphQLIBAN },
    routingNumber: { type: GraphQLRoutingNumber },
    accountNumber: { type: GraphQLAccountNumber },
  },
});

const TransactionType = new GraphQLObjectType({
  name: "Transaction",
  fields: {
    amount: { type: GraphQLUSCurrency },
    currency: { type: GraphQLCurrency },
    fromAccount: { type: GraphQLAccountNumber },
    toAccount: { type: GraphQLAccountNumber },
  },
});

// Using with type definitions
const typeDefs = `
  scalar Currency
  scalar USCurrency
  scalar IBAN
  scalar RoutingNumber
  scalar AccountNumber
  
  type PaymentMethod {
    id: ID!
    type: PaymentMethodType
    currency: Currency
    iban: IBAN
    routingNumber: RoutingNumber
    accountNumber: AccountNumber
  }
  
  type Transaction {
    id: ID!
    amount: USCurrency
    currency: Currency
    fromAccount: AccountNumber
    toAccount: AccountNumber
    status: TransactionStatus
  }
  
  enum PaymentMethodType {
    BANK_ACCOUNT
    WIRE_TRANSFER
    ACH
  }
`;

GraphQL Operations:

query GetPaymentMethods($userId: ID!) {
  user(id: $userId) {
    paymentMethods {
      id
      type
      currency
      iban
      routingNumber
      accountNumber
    }
  }
}

mutation CreateBankTransfer($input: BankTransferInput!) {
  createBankTransfer(input: $input) {
    id
    amount
    currency
    fromAccount
    toAccount
    status
  }
}

Variables:

{
  "userId": "user-123",
  "input": {
    "amount": "$1,250.00",
    "currency": "USD",
    "fromAccount": "1234567890",
    "toAccount": "0987654321",
    "routingNumber": "021000021"
  }
}

Validation Behavior

Each financial scalar performs specific validation:

  • Currency: Validates against ISO 4217 standard currency codes
  • USCurrency: Validates dollar amounts, supports various formatting (commas, decimal places)
  • IBAN: Validates format and check digits according to ISO 13616 standard
  • RoutingNumber: Validates 9-digit format and check digit algorithm
  • AccountNumber: Validates basic account number format and length

Validation Examples:

// Valid financial data
const validPayment = {
  amount: "$1,234.56",           // Valid US currency format
  currency: "USD",               // Valid ISO 4217 code
  iban: "GB82 WEST 1234 5698 7654 32", // Valid IBAN with check digits
  routingNumber: "021000021",    // Valid routing number
  accountNumber: "1234567890"    // Valid account number
};

// Invalid financial data
const invalidPayment = {
  amount: "$1,234.567",          // Invalid: too many decimal places
  currency: "INVALID",           // Invalid: not ISO 4217 code
  iban: "GB99 WEST 1234 5698 7654 32", // Invalid: wrong check digits
  routingNumber: "123456789",    // Invalid: fails check digit validation
  accountNumber: "123"           // Invalid: too short
};

Security Considerations

When working with financial data, consider these security practices:

  • Data Encryption: Always encrypt sensitive financial data in transit and at rest
  • Access Control: Implement strict authorization for financial operations
  • Audit Logging: Log all financial transactions for compliance
  • Input Sanitization: Use these scalars to validate but never trust client data alone
  • PCI Compliance: Follow PCI DSS standards when handling payment card data

IBAN Country Support

The IBAN scalar supports validation for all countries that use IBAN:

European Countries:

  • Germany (DE), France (FR), United Kingdom (GB), Italy (IT)
  • Spain (ES), Netherlands (NL), Belgium (BE), Austria (AT)
  • Switzerland (CH), Poland (PL), Sweden (SE), Norway (NO)

Other Regions:

  • Middle East: UAE (AE), Saudi Arabia (SA), Qatar (QA)
  • Other: Tunisia (TN), Turkey (TR), Brazil (BR)

Common Use Cases

Currency Codes are used for:

  • Multi-currency e-commerce platforms
  • Foreign exchange applications
  • International payment processing
  • Financial reporting and analytics

Bank Account Information is used for:

  • ACH transfers and direct deposits
  • Wire transfer processing
  • Payment method storage
  • Banking integration APIs

IBAN is used for:

  • SEPA transfers in Europe
  • International wire transfers
  • Cross-border payment validation
  • Banking compliance systems

Type Definitions

// String constants for schema building
const Currency: string;        // "scalar Currency"
const USCurrency: string;      // "scalar USCurrency"
const IBAN: string;            // "scalar IBAN"
const RoutingNumber: string;   // "scalar RoutingNumber"
const AccountNumber: string;   // "scalar AccountNumber"

Mock Data

// Mock data generators for testing
const CurrencyMock: () => string;
const USCurrencyMock: () => string;
const IBANMock: () => string;
const RoutingNumberMock: () => string;
const AccountNumberMock: () => string;

Compliance Notes

  • IBAN: Fully compliant with ISO 13616 standard
  • Routing Numbers: Validates ABA routing transit number format and check digits
  • Currency Codes: Based on ISO 4217 standard, regularly updated
  • Data Protection: Consider GDPR, PCI DSS, and local financial data protection regulations

docs

colors.md

data-formats.md

date-time.md

financial.md

geographic.md

identifiers.md

index.md

network.md

numeric.md

specialized.md

string-text.md

utilities.md

tile.json