Multi-format client SDK for Elfsensoz API
npm install @elfsensoz/client-sdkbash
npm install @elfsensoz/client-sdk
`
$3
`html
`
Usage
$3
`typescript
import { SDKClient } from '@elfsensoz/client-sdk';
const client = new SDKClient({
baseUrl: 'https://api.example.com',
apiKey: 'your-api-key',
timeout: 30000
});
// Hello World
const greeting = client.hello();
console.log(greeting); // "Hello World"
// Get token
const tokenResponse = await client.getToken();
console.log(tokenResponse);
// Make API request
const data = await client.request('/api/endpoint', {
method: 'GET'
});
`
$3
`html
`
$3
`html
`
$3
`javascript
const { SDKClient } = require('@elfsensoz/client-sdk');
const client = new SDKClient({
baseUrl: 'https://api.example.com'
});
const greeting = client.hello();
console.log(greeting);
`
$3
`javascript
import { SDKClient } from '@elfsensoz/client-sdk';
const client = new SDKClient({
baseUrl: 'https://api.example.com'
});
const greeting = client.hello();
console.log(greeting);
`
API Reference
$3
Main client class for interacting with the API.
#### Constructor
`typescript
new SDKClient(config?: SDKClientConfig)
`
Config Options:
- baseUrl?: string - Base URL for API requests (default: 'https://api.example.com')
- apiKey?: string - API key for authentication
- timeout?: number - Request timeout in milliseconds (default: 30000)
#### Methods
##### hello(): string
Returns a greeting message.
`typescript
const greeting = client.hello();
// Returns: "Hello World"
`
##### getToken(): Promise
Retrieves an authentication token.
`typescript
const tokenResponse = await client.getToken();
// Returns: { token: string, expiresIn?: number }
`
##### request
Makes a generic API request.
`typescript
const data = await client.request('/api/users', {
method: 'GET',
headers: { 'Custom-Header': 'value' },
body: { key: 'value' }
});
`
Development
$3
`bash
Build all formats
npm run build
Build TypeScript definitions only
npm run build:types
Build bundles only
npm run build:bundles
Production build (minified)
npm run build:prod
`
$3
`
client-sdk/
├── src/
│ ├── index.ts # Main entry point
│ ├── Client.ts # SDK Client class
│ ├── types.ts # TypeScript type definitions
│ └── utils.ts # Utility functions
├── dist/ # Build output
│ ├── browser/
│ │ ├── sdk.umd.js # UMD format (CDN)
│ │ ├── sdk.esm.js # ES Module format
│ │ └── sdk.cjs.js # CommonJS format
│ ├── node/
│ │ ├── index.js # Node.js CJS build
│ │ └── index.esm.js # Node.js ESM build
│ └── types/ # TypeScript definitions
│ └── index.d.ts
├── examples/
│ ├── browser/
│ │ ├── vanilla.html # Vanilla JS example
│ │ └── es-module.html # ES Module example
│ └── node/
│ ├── commonjs.js # CommonJS example
│ └── es-module.mjs # ES Module example
├── package.json
├── tsconfig.json
├── rollup.config.js
└── README.md
`
Publishing
$3
#### First Time Publish
`bash
1. Build
npm run build
2. Login to npm
npm login
3. Publish (scoped packages require --access public)
npm publish --access public
`
#### Subsequent Publishes
`bash
Version bump and publish
npm run publish:patch # 1.0.0 → 1.0.1
npm run publish:minor # 1.0.1 → 1.1.0
npm run publish:major # 1.1.0 → 2.0.0
`
$3
`bash
Manual version
npm version 1.0.0
Semantic versioning
npm version patch # Bug fixes
npm version minor # New features
npm version major # Breaking changes
`
$3
After publishing to NPM, the package is automatically available via CDN:
- unpkg: https://unpkg.com/@elfsensoz/client-sdk@latest/dist/browser/sdk.umd.js
- jsDelivr: https://cdn.jsdelivr.net/npm/@elfsensoz/client-sdk@latest/dist/browser/sdk.umd.js
Examples
See the examples/ directory for complete working examples:
- examples/browser/vanilla.html - Browser UMD example
- examples/browser/es-module.html - Browser ES Module example
- examples/node/commonjs.js - Node.js CommonJS example
- examples/node/es-module.mjs` - Node.js ES Module example