Skip to content

techdivision/appsheet

Repository files navigation

AppSheet TypeScript Library

A generic TypeScript library for AppSheet CRUD operations, designed for building MCP servers and internal tools.

Features

  • 🚀 Full CRUD operations for AppSheet tables
  • 📝 Runtime schema loading from YAML/JSON
  • 🔧 CLI tool for schema generation and management
  • 🔒 Type-safe API with TypeScript
  • 🌐 Multi-instance support (multiple AppSheet apps)
  • ✅ Schema-based validation
  • 🔄 Connection management with health checks

Installation

From GitHub (for internal projects)

Install directly from the GitHub repository:

npm install git+ssh://[email protected]:techdivision/appsheet.git

Or specify a specific branch or tag:

# Install from a specific branch
npm install git+ssh://[email protected]:techdivision/appsheet.git#main

# Install from a specific tag/version
npm install git+ssh://[email protected]:techdivision/appsheet.git#v0.1.0

Add to your package.json:

{
  "dependencies": {
    "@techdivision/appsheet": "git+ssh://[email protected]:techdivision/appsheet.git"
  }
}

From npm (when published)

npm install @techdivision/appsheet

Quick Start

1. Generate Schema

Use the CLI to automatically generate schema from your AppSheet app:

# Generate schema for specific tables
npx appsheet inspect \
  --app-id "your-app-id" \
  --access-key "your-access-key" \
  --tables "worklog,issues,employees"

# Or let it discover tables automatically
npx appsheet inspect \
  --app-id "your-app-id" \
  --access-key "your-access-key"

This creates config/appsheet-schema.yaml with your table definitions.

2. Use in Your Code

import { SchemaLoader, SchemaManager } from '@techdivision/appsheet';

// Load schema
const schema = SchemaLoader.fromYaml('./config/appsheet-schema.yaml');
const db = new SchemaManager(schema);

// Use type-safe table clients
interface Worklog {
  id: string;
  date: string;
  hours: number;
  description: string;
}

const worklogsTable = db.table<Worklog>('worklog', 'worklogs');

// CRUD operations
const worklogs = await worklogsTable.findAll();
const today = await worklogsTable.find('[date] = "2025-10-27"');

await worklogsTable.add([
  { id: '123', date: '2025-10-27', hours: 8, description: 'Work done' }
]);

await worklogsTable.update([{ id: '123', hours: 7 }]);
await worklogsTable.delete([{ id: '123' }]);

CLI Commands

# Initialize empty schema
npx appsheet init

# Inspect and generate schema
npx appsheet inspect --app-id <id> --access-key <key> --tables <tables>

# Add a table to existing schema
npx appsheet add-table <connection> <tableName>

# Validate schema
npx appsheet validate

Direct Client Usage

For simple use cases without schema files:

import { AppSheetClient } from '@techdivision/appsheet';

const client = new AppSheetClient({
  appId: process.env.APPSHEET_APP_ID!,
  applicationAccessKey: process.env.APPSHEET_ACCESS_KEY!,
  runAsUserEmail: '[email protected]',  // Optional: run operations as specific user
});

// CRUD operations
const rows = await client.findAll('Users');
const user = await client.findOne('Users', '[Email] = "[email protected]"');

await client.addOne('Users', { name: 'John', email: '[email protected]' });
await client.updateOne('Users', { id: '123', name: 'John Updated' });
await client.deleteOne('Users', { id: '123' });

// Override runAsUserEmail for specific operation
await client.add({
  tableName: 'Users',
  rows: [{ name: 'Jane' }],
  properties: { RunAsUserEmail: '[email protected]' }
});

Multi-Instance Support

Manage multiple AppSheet apps in one project:

# config/appsheet-schema.yaml
connections:
  worklog:
    appId: ${APPSHEET_WORKLOG_APP_ID}
    applicationAccessKey: ${APPSHEET_WORKLOG_ACCESS_KEY}
    tables:
      # ...

  hr:
    appId: ${APPSHEET_HR_APP_ID}
    applicationAccessKey: ${APPSHEET_HR_ACCESS_KEY}
    tables:
      # ...
const worklogTable = db.table('worklog', 'worklogs');
const employeeTable = db.table('hr', 'employees');

Examples

See the examples/ directory for complete examples:

  • basic-usage.ts - Direct client usage
  • schema-based-usage.ts - Schema-based usage
  • config/example-schema.yaml - Example schema file

Development

Setup

npm install

Build

npm run build

Test

npm test

Linting

npm run lint
npm run format

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published