Skip to content

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

GS1 Barcode & Digital Link Decoder — TypeScript / JavaScript SDK

npm version License: MIT Stanza API

Decode GS1 DataMatrix, GS1-128, FNC1 barcodes, and GS1 Digital Link URIs into structured JSON in sub-5ms.

Official, zero-dependency Node.js and TypeScript client for GS1 Barcode & Digital Link Decoder, powered by the Stanza Micro-API Network. Delivers deterministic, sub-5ms V8 isolate execution directly to your application without 3rd-party proxies.


📦 Installation

npm install @stanzaapi/gs1-decoder
# or
pnpm add @stanzaapi/gs1-decoder
# or
yarn add @stanzaapi/gs1-decoder

🚀 Quickstart

import { Gs1DecoderClient } from '@stanzaapi/gs1-decoder';

// Initialize client (API key optional for sandbox tier evaluation)
const client = new Gs1DecoderClient({
  apiKey: process.env.STANZA_API_KEY,
});

async function main() {
  const result = await client.parse('(01)00123456789012(21)12345');

  if (result.success) {
    console.log('Verification Success:', result.data);
  } else {
    console.error('Validation Error:', result.error, result.code);
  }
}

main().catch(console.error);

📄 Example JSON Response

{
  "success": true,
  "data": {
    "gtin": "00123456789012",
    "serial_number": "12345",
    "ai_elements": [
      {
        "ai": "01",
        "label": "GTIN",
        "value": "00123456789012"
      },
      {
        "ai": "21",
        "label": "SERIAL",
        "value": "12345"
      }
    ]
  }
}

⚙️ Client Configuration Options

Option Type Default Description
apiKey string process.env.STANZA_API_KEY Your Stanza API Key. Required for high-throughput production tiers.
baseUrl string https://api.stanzaapi.com/gs1-decoder Public edge API base URL.
timeoutMs number 15000 Request timeout in milliseconds (uses native AbortSignal.timeout).

🛡️ Response Envelope & Error Handling

All responses return a typed envelope:

export interface ApiResponse<T> {
  success: boolean;
  data?: T;
  error?: string;
  code?: 'VALIDATION_ERROR' | 'UNAUTHORIZED' | 'PAYLOAD_TOO_LARGE' | 'RATE_LIMITED' | 'INTERNAL_ERROR';
}

🔗 Related Resources

📄 License

MIT © Stanza — Powered by Stanza.

Releases

Packages

Contributors

Languages