# enterprise-basics

> A utility library for enterprise applications. It streamlines common business tasks by providing functions to process delimited and Excel files, generate professional PDFs, and handle email communications with attachments.

Latest version **3.0.2** (published 2026-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install enterprise-basics
pnpm add enterprise-basics
yarn add enterprise-basics
bun add enterprise-basics
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2026-04-14 |
| First published | 2025-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 23 |
| Unpacked size | 148.3 KB |
| Known vulnerabilities | 0 (+21 in 2 direct dependencies) |
| Install scripts | no |
| Author | joseph chustz |
| Maintainers | jchustz |
| Keywords | utilities, enterprise, business, pdf, excel, email, file-processing, typescript, nodejs |

## Links

- npm: https://www.npmjs.com/package/enterprise-basics
- npm.io page: https://npm.io/package/enterprise-basics

## Dependencies (23)

- [ai](https://npm.io/package/ai.md) ^6.0.49
- [add](https://npm.io/package/add.md) ^2.0.6
- [zod](https://npm.io/package/zod.md) ^4.3.6
- [mssql](https://npm.io/package/mssql.md) ^12.2.0
- [dotenv](https://npm.io/package/dotenv.md) ^17.2.3
- [openai](https://npm.io/package/openai.md) ^6.16.0
- [twilio](https://npm.io/package/twilio.md) ^5.12.0
- [exceljs](https://npm.io/package/exceljs.md) ^4.4.0
- [pdf-lib](https://npm.io/package/pdf-lib.md) ^1.17.1
- [csv-parse](https://npm.io/package/csv-parse.md) ^6.1.0
- [pdf-parse](https://npm.io/package/pdf-parse.md) ^2.4.5
- [puppeteer](https://npm.io/package/puppeteer.md) ^24.36.0
- [nodemailer](https://npm.io/package/nodemailer.md) ^7.0.12
- [@ai-sdk/azure](https://npm.io/package/@ai-sdk/azure.md) ^3.0.18
- [@azure/openai](https://npm.io/package/@azure/openai.md) ^2.0.0
- [@ai-sdk/openai](https://npm.io/package/@ai-sdk/openai.md) ^3.0.18
- [@langchain/core](https://npm.io/package/@langchain/core.md) ^1.1.17
- [@azure/core-auth](https://npm.io/package/@azure/core-auth.md) ^1.10.1
- [@langchain/openai](https://npm.io/package/@langchain/openai.md) ^1.2.3
- [@azure/storage-blob](https://npm.io/package/@azure/storage-blob.md) ^12.30.0
- [@langchain/community](https://npm.io/package/@langchain/community.md) ^1.1.7
- [@azure/search-documents](https://npm.io/package/@azure/search-documents.md) ^12.2.0
- [@azure/app-configuration](https://npm.io/package/@azure/app-configuration.md) ^1.10.0

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2026-04-14
- 3.0.1 — 2026-01-27
- 2.2.0 — 2025-12-01
- 2.1.3 — 2025-10-23
- 2.1.2 — 2025-08-26
- 2.1.1 — 2025-08-24
- 2.0.2 — 2025-08-05
- 2.0.1 — 2025-08-04
- 2.0.0 — 2025-08-04
- 1.6.8 — 2025-08-04
- 1.6.6 — 2025-08-04
- 1.6.5 — 2025-08-04
- 1.6.4 — 2025-08-04
- 1.6.3 — 2025-08-04
- 1.6.2 — 2025-08-04
- … 43 more at https://npm.io/package/enterprise-basics/versions

## README

# Enterprise Basics

A collection of utility functions for common enterprise operations in Azure and other services.

## Installation

```bash
npm install enterprise-basics
```

## Features

### Azure App Configuration

- `AzureAppConfig`: Class for interacting with Azure App Configuration. Provides methods to retrieve configuration values from Azure App Configuration. Supports environment-specific configuration through labels.

### Azure Storage

- `uploadBlob`: Uploads a file to Azure Blob Storage with metadata support
- `deleteBlob`: Deletes a blob from Azure Blob Storage
- `getBlob`: Downloads a blob from Azure Blob Storage as a Buffer

### Azure AI

- `generateCompletion`: Generates a single-turn completion using Azure-hosted OpenAI models.
  Designed for one-off completions and should not be used for maintaining chat history or conversational interactions.
- `transcribeAudio`: Transcribes audio using Azure OpenAI's Whisper model. The endpoint can be obtained from `getAppConfig('OPENAI_WHISPER_ENDPOINT', 'prod')`. Supports various audio formats including flac, m4a, mp3, mp4, mpeg, mpga, oga, ogg, wav, and webm.

### Database

- `executeSqlQuery`: Executes SQL queries against Microsoft SQL Server databases

### Delimited Files

- `createDelimitedFileBytes`: Creates a byte array from data in a delimited format
- `importDelimitedFile`: Imports data from a delimited file

### Excel

- `readExcelSheetData`: Reads data from Excel sheets
- `createExcelFileByteArray`: Creates an Excel file as a byte array
- Types:
  - `ExcelRow`: Type definition for Excel row data
  - `ExcelCellValue`: Type definition for Excel cell values

### File System

- `saveFileBytesToPath`: Saves byte array data to a file path
- `readTextFile`: Reads text content from a file
- `getEnvValue`: Retrieves environment variable values with validation

### MS Graph

- `graphUserSearchByEmail`: Searches for users in Microsoft Graph by email address

### Email

- `EmailClient`: Class for sending emails using SMTP. Provides methods to send emails with optional attachments. SMTP configuration is set during instantiation.

```typescript
// Create an instance with SMTP configuration
const emailClient = new EmailClient({
  host: 'smtp.example.com',
  port: 587,
  auth: { user: 'user', pass: 'pass' },
});

// Send an email
await emailClient.sendEmail({
  from: 'sender@example.com',
  to: ['recipient@example.com'],
  subject: 'Test Email',
  body: 'This is a test email with attachment',
  attachments: [
    {
      filename: 'test.pdf',
      fileBytes: new Uint8Array([255, 255]),
      contentType: 'application/pdf',
    },
  ],
});
```

### PDF

- `createPdfFromHtml`: Converts HTML content to a PDF file and returns it as a byte array. Supports custom page formats, orientation, and margins.
- `htmlToPdfBuffer`: Converts HTML content to a PDF buffer using puppeteer. Returns the PDF content as a `Uint8Array`.

## Usage Examples

### Azure Storage

```typescript
import { uploadBlob, deleteBlob, getBlob } from 'enterprise-basics';

// Upload a file
await uploadBlob(connectionString, 'my-container', 'path/to/file.txt', fileObject);

// Delete a blob
await deleteBlob(connectionString, 'my-container', 'path/to/file.txt');

// Download a blob
const buffer = await getBlob(connectionString, 'my-container', 'path/to/file.txt');
```

### Azure App Configuration

```typescript
import { getAzureConfigValue } from 'enterprise-basics';

const configValue = await getAzureConfigValue('myApp.setting', 'dev');
```

### Azure AI (Single-turn Completion)

```typescript
import { generateCompletion, transcribeAudio } from 'enterprise-basics';

// Note: This is for single-turn completions only, not for chat/conversations
const completion = await generateCompletion(
  'https://your-resource.openai.azure.com',
  'your-api-key',
  'your-deployment-name',
  [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'What is the capital of France?' },
  ],
  { temperature: 0.7 },
);

// Transcribe audio
const transcription = await transcribeAudio(
  'https://your-resource.openai.azure.com',
  'your-api-key',
  'your-whisper-deployment',
  audioFile,
  { language: 'en' },
);
```

### Excel Operations

```typescript
import { readExcelSheetData, createExcelFileByteArray } from 'enterprise-basics';

// Read Excel data
const data = await readExcelSheetData(filePath, sheetName);

// Create Excel file
const excelBytes = await createExcelFileByteArray(data);
```

### File System

```typescript
import { saveFileBytesToPath, readTextFile, getEnvValue } from 'enterprise-basics';

// Save file
await saveFileBytesToPath(filePath, fileBytes);

// Read text file
const content = await readTextFile(filePath);

// Get environment variable
const apiKey = await getEnvValue('API_KEY');
```

### MS Graph

```typescript
import { graphUserSearchByEmail } from 'enterprise-basics';

const user = await graphUserSearchByEmail('user@example.com');
```

### Email

```typescript
import { sendEmail } from 'enterprise-basics';

await sendEmail(
  {
    from: 'sender@example.com',
    to: ['recipient@example.com'],
    subject: 'Test Email',
    body: 'This is a test email with attachment',
    attachments: [
      {
        filename: 'test.pdf',
        fileBytes: new Uint8Array([255, 255]),
        contentType: 'application/pdf',
      },
    ],
  },
  {
    host: 'smtp.example.com',
    port: 587,
    auth: { user: 'user', pass: 'pass' },
  },
);
```

### PDF Generation

```typescript
import { htmlToPdfBuffer } from 'enterprise-basics';

const htmlContent = '<h1>Hello, PDF!</h1>';
try {
  const pdfBytes = await htmlToPdfBuffer(htmlContent);
  // Save or use the pdfBytes
  console.log('PDF generated successfully');
} catch (error) {
  console.error('Failed to generate PDF:', error);
}
```

## Error Handling

All functions include proper error handling and will throw descriptive errors when:

- Input validation fails
- Required parameters are missing
- Service operations fail
- Files are not found
- Network requests fail

## TypeScript Support

This package is written in TypeScript and includes type definitions for all functions and their parameters.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

MIT

---
_Source: https://npm.io/package/enterprise-basics · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
