JSPM

@templatefox/sdk

1.7.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 135
  • Score
    100M100P100Q35318F
  • License MIT

Official TemplateFox TypeScript SDK - Generate PDFs from HTML templates

Package Exports

  • @templatefox/sdk
  • @templatefox/sdk/dist/esm/index.js
  • @templatefox/sdk/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@templatefox/sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

TemplateFox TypeScript SDK

Official TypeScript/Node.js SDK for TemplateFox - Generate PDFs from HTML templates via API.

npm version License: MIT

Installation

npm install @templatefox/sdk

Or with yarn:

yarn add @templatefox/sdk

Quick Start

import { Configuration, PDFApi, CreatePdfRequest } from '@templatefox/sdk';

// Initialize the client
const config = new Configuration({
  apiKey: 'your-api-key',
});

const api = new PDFApi(config);

// Generate a PDF
async function generatePdf() {
  const response = await api.createPdf({
    templateId: 'YOUR_TEMPLATE_ID',
    data: {
      name: 'John Doe',
      invoiceNumber: 'INV-001',
      totalAmount: 150.00,
    },
  });

  console.log('PDF URL:', response.url);
  console.log('Credits remaining:', response.creditsRemaining);
}

generatePdf();

Features

  • Template-based PDF generation - Create templates with dynamic variables, generate PDFs with your data
  • Multiple export options - Get a signed URL (default) or raw binary PDF
  • S3 integration - Upload generated PDFs directly to your own S3-compatible storage
  • TypeScript support - Full type definitions included

API Methods

PDF Generation

// Generate PDF and get URL
const response = await api.createPdf({
  templateId: 'TEMPLATE_ID',
  data: { name: 'John Doe' },
  exportType: 'url',        // 'url' or 'binary'
  expiration: 86400,        // URL expiration in seconds (default: 24h)
  filename: 'invoice-001',  // Custom filename
});

Templates

import { TemplatesApi } from '@templatefox/sdk';

const templatesApi = new TemplatesApi(config);

// List all templates
const templates = await templatesApi.listTemplates();

// Get template fields
const fields = await templatesApi.getTemplateFields({ templateId: 'TEMPLATE_ID' });

Account

import { AccountApi } from '@templatefox/sdk';

const accountApi = new AccountApi(config);

// Get account info
const account = await accountApi.getAccount();
console.log('Credits:', account.credits);

// List transactions
const transactions = await accountApi.listTransactions({ limit: 100, offset: 0 });

S3 Integration

import { IntegrationsApi } from '@templatefox/sdk';

const integrationsApi = new IntegrationsApi(config);

// Save S3 configuration
await integrationsApi.saveS3Config({
  s3ConfigRequest: {
    endpointUrl: 'https://s3.amazonaws.com',
    accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
    secretAccessKey: 'your-secret-key',
    bucketName: 'my-pdf-bucket',
    defaultPrefix: 'generated/pdfs/',
  }
});

// Test connection
const test = await integrationsApi.testS3Connection();
console.log('Connection:', test.success ? 'OK' : 'Failed');

Configuration Options

const config = new Configuration({
  basePath: 'https://api.pdftemplateapi.com', // Default API URL
  apiKey: 'your-api-key',
});

// Or use environment variable
const config = new Configuration({
  apiKey: process.env.TEMPLATEFOX_API_KEY,
});

Error Handling

try {
  const response = await api.createPdf({ /* ... */ });
} catch (error) {
  if (error.status === 402) {
    console.error('Insufficient credits');
  } else if (error.status === 403) {
    console.error('Access denied - check your API key');
  } else if (error.status === 404) {
    console.error('Template not found');
  } else {
    console.error('Error:', error.message);
  }
}

Documentation

Support

License

MIT License - see LICENSE for details.