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

document-extraction-service

v1.0.3

Published

A service for handling document extraction and processing

Readme

Document Extraction Service

document-extraction-service is a Node.js library for seamless integration with document processing APIs. It provides request preparation, response validation, and callback handling functionalities, making document extraction workflows efficient and robust.


Installation

To install the package, run:

npm install document-extraction-service

Quick Start

Configure the Request Validator

const { createRequestValidator } = require('document-extraction-service');

const config = {
  endpoint: 'https://your-extraction-api.com',
  headers: {
    'Content-Type': 'multipart/form-data',
    'callback_url_pattern': 'https://your-service.com/callback/{{streamId}}/{{extractionStrategyId}}',
    'trace_id': '{{traceId}}'
  },
  requestBody: {
    'strategies_batch_id': '{{strategiesBatchId}}',
    'doc_id': '{{docId}}',
    'url': '{{file_url}}',
    'document_meta': '{{content}}',
  },
  timeout_days: 2, 
  max_retries: 3  
};

const requestValidator = createRequestValidator(config);

Create the Callback Validator

const { createCallbackValidator } = require('document-extraction-service');

const callbackValidator = createCallbackValidator();

Processing a Document

const processDocument = async () => {
  const docId = 'doc123';
  const content = { text: 'Your document content' };
  const streamId = 'stream456';

  try {
    // Prepare request parameters
    const requestParams = requestValidator.prepareRequest(docId, content, streamId);

    // Make API call (using your preferred HTTP client, e.g., axios)
    const response = await axios(requestParams);

    // Handle response
    const result = requestValidator.handleResponse(response, requestParams.headers['X-Trace-ID']);
    console.log('Document processing initiated:', result);
  } catch (error) {
    console.error('Error processing document:', error);
  }
};

Handling Callback

const handleCallback = async (callbackData) => {
  try {
    const result = await callbackValidator.handleCallback(callbackData);
    if (!result.success) {
      console.error(result.error);
    } else {
      console.log('Callback processed:', result);
    }
  } catch (error) {
    console.error('Error processing callback:', error);
  }
};

API Documentation

Configuration Object

const config = {
  endpoint: 'https://api.example.com', // Required - API endpoint
  headers: {
    'Authorization': 'Bearer token',
    'callback_url_pattern': 'https://callback.com/{{docId}}/{{streamId}}' // Required
  },
  timeout_days: 2, // Optional - default: 2
  max_retries: 3 // Optional - default: 3
};

Request Preparation

const params = requestValidator.prepareRequest(docId, content, streamId);

Returns:

{
  url: string,    'callback_url_pattern': 'https://your-service.com/callback/{{docId}}/{{streamId}}'

  method: 'POST',
  headers: {
    'X-Document-ID': string,
    'X-Trace-ID': string,
    'X-Callback-URL': string,
    ...other headers
  },
  data: {
    content: any,
    streamId: string
  }
}

Response Handling

const result = requestValidator.handleResponse(response, traceId);

Returns:

{
  success: boolean,
  docId: string,
  traceId: string,
  message?: string,
  error?: string
}

Callback Handling

const result = await callbackValidator.handleCallback(callbackData);

Input Format:

{
  doc_id: string,
  trace_id: string,
  chunk_data: Array<{
    content: string,
    index: number,
    chunkId: string,
    chunkText: string
  }>,
  last_batch: boolean
}

Returns:

{
  success: boolean,
  docId: string,
  traceId: string,
  isLastBatch: boolean,
  chunks: Array<ProcessedChunk>,
  metadata: {
    processedAt: string,
    chunksCount: number
  }
}

Additional Utilities

Chunk Validation

const {
  ChunkData,
  ExtractionConfig,
  CustomExtractorFactory
} = require('document-extraction-service');

// Validate chunks
ChunkData.validateResponse(chunksData);
ChunkData.validateChunk(chunk);

Custom Configurations

const config = new ExtractionConfig({...});
const factory = new CustomExtractorFactory();

const customRequestValidator = factory.createRequestValidator(config);
const customCallbackValidator = factory.createCallbackValidator();

Error Handling

Validating Input

try {
  const result = await requestValidator.prepareRequest(docId, content, streamId);
} catch (error) {
  if (error.message.includes('Missing required field')) {
    // Handle validation error
  } else {
    // Handle other errors
  }
}

Handling Callback Validation Errors

try {
  const result = await callbackValidator.handleCallback(callbackData);
  if (!result.success) {
    // Handle validation failure
    console.error(result.error);
  }
} catch (error) {
  // Handle unexpected errors
  console.error(error);
}

Testing

Run the provided test suite:

npm test

Features

  • Request Preparation: Simplifies constructing API requests with headers and parameters.
  • Response Validation: Ensures API responses are correctly formatted.
  • Callback Processing: Validates and processes callback data efficiently.
  • Customizable Configuration: Supports flexible timeout, retry logic, and callback URL patterns.

License

This project is licensed under the MIT License. Contributions are welcome!