Skip to main content

Overview

The S4Kit CLI provides utilities for type generation, project initialization, and more.
npx s4kit <command> [options]
Or install globally:
npm install -g s4kit
s4kit <command> [options]

Commands

generate-types

Generate TypeScript type definitions from SAP OData metadata:
npx s4kit generate-types --api-key sk_live_... --output ./types

Options

OptionAliasDescriptionRequired
--api-key-kYour S4Kit API keyYes
--base-url-bAPI proxy URLNo
--output-oOutput directory pathYes

Examples

# Generate types (minimal)
npx s4kit generate-types --api-key sk_live_abc123 --output ./types

# With custom base URL
npx s4kit generate-types --api-key sk_live_abc123 --base-url https://api.s4kit.com/api/proxy --output ./types

Generated Types

The CLI generates comprehensive TypeScript types:
// ./types/sap.d.ts (generated)

export interface A_BusinessPartner {
  BusinessPartner: string;
  Customer?: string;
  Supplier?: string;
  AcademicTitle?: string;
  AuthorizationGroup?: string;
  BusinessPartnerCategory?: string;
  BusinessPartnerFullName?: string;
  // ... all fields with correct types
}

export interface A_BusinessPartnerAddress {
  BusinessPartner: string;
  AddressID: string;
  CityName?: string;
  Country?: string;
  // ...
}

// Navigation properties
export interface A_BusinessPartner_Navigations {
  to_BusinessPartnerAddress: A_BusinessPartnerAddress[];
  to_BusinessPartnerBank: A_BusinessPartnerBank[];
  // ...
}

Using Generated Types

import type { A_BusinessPartner } from './types/sap';
import { S4Kit } from 's4kit';

const client = new S4Kit({ apiKey: '...' });

// Fully typed response
const partners: A_BusinessPartner[] = await client.A_BusinessPartner.list();

// Autocomplete for fields
partners.forEach(p => {
  console.log(p.BusinessPartnerFullName); // TypeScript knows this field
});

init

Initialize a new S4Kit project:
npx s4kit init
This creates:
  • .env.example with configuration template
  • s4kit.config.ts with default settings
  • TypeScript configuration if not present

version

Display the CLI version:
npx s4kit version
# s4kit v1.2.3

help

Show help information:
npx s4kit help
npx s4kit help generate-types

Environment Variables

The CLI respects these environment variables:
VariableDescription
S4KIT_API_KEYDefault API key
S4KIT_BASE_URLCustom API base URL
# .env
S4KIT_API_KEY=sk_live_abc123
S4KIT_BASE_URL=https://api.s4kit.com/api/proxy

CI/CD Integration

GitHub Actions

# .github/workflows/generate-types.yml
name: Generate SAP Types

on:
  schedule:
    - cron: '0 0 * * 0'  # Weekly
  workflow_dispatch:

jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '20'

      - run: npm install

      - run: npx s4kit generate-types --api-key $S4KIT_API_KEY --output ./types
        env:
          S4KIT_API_KEY: ${{ secrets.S4KIT_API_KEY }}

      - name: Commit changes
        run: |
          git config user.name "GitHub Actions"
          git config user.email "actions@github.com"
          git add types/
          git diff --staged --quiet || git commit -m "chore: update SAP types"
          git push

GitLab CI

# .gitlab-ci.yml
generate-types:
  image: node:20
  script:
    - npm install
    - npx s4kit generate-types --api-key $S4KIT_API_KEY --output ./types
  variables:
    S4KIT_API_KEY: $S4KIT_API_KEY
  artifacts:
    paths:
      - types/

Troubleshooting

Authentication Failed

Error: Authentication failed. Check your API key.
Verify your API key:
  • Check the API key is correct
  • Ensure the --api-key flag is provided
  • Try using environment variable S4KIT_API_KEY

Invalid Base URL

Error: Cannot connect to API.
Verify the base URL:
  • Check the --base-url flag points to your S4Kit proxy
  • Ensure the URL is reachable from your network