Core SDK Methods
initialize(options)
Promise<void> initialize(options: { apiKey: string, endpoint?: string })
Initializes the SDK with your API key and optional endpoint configuration. This method must be called before any other SDK operations.
Parameters
- options (Object): Configuration object.
- apiKey (string, required): Your unique API key.
- endpoint (string, optional): The custom API endpoint URL if you are not using the default.
Returns
A Promise
that resolves when the SDK has been successfully initialized.
Example Usage
import { initialize } from '@your-company/sdk';
async function setupSDK() {
try {
await initialize({
apiKey: 'YOUR_API_KEY_HERE',
endpoint: 'https://api.your-company.com/v1'
});
console.log('SDK initialized successfully!');
} catch (error) {
console.error('Failed to initialize SDK:', error);
}
}
setupSDK();
getUser(userId)
Promise<User> getUser(userId: string)
Fetches detailed information for a specific user.
Parameters
- userId (string, required): The unique identifier of the user to retrieve.
Returns
A Promise
that resolves with a User
object containing user details.
The User
object has the following structure:
{
id: string;
name: string;
email: string;
createdAt: string; // ISO 8601 date string
// ... other user properties
}
Example Usage
import { getUser } from '@your-company/sdk';
async function fetchUser() {
try {
const user = await getUser('user-12345');
console.log('User Data:', user);
} catch (error) {
console.error('Failed to fetch user:', error);
}
}
fetchUser();
createItem(itemData)
Promise<Item> createItem(itemData: ItemInput)
Creates a new item in the system.
Parameters
- itemData (Object, required): The data for the new item.
- name (string, required): The name of the item.
- description (string, optional): A brief description of the item.
- price (number, required): The price of the item.
Returns
A Promise
that resolves with the newly created Item
object.
The Item
object has the following structure:
{
id: string;
name: string;
description: string | null;
price: number;
createdAt: string; // ISO 8601 date string
}
Example Usage
import { createItem } from '@your-company/sdk';
async function addItem() {
try {
const newItem = await createItem({
name: 'Awesome Gadget',
description: 'A truly remarkable piece of technology.',
price: 99.99
});
console.log('Item created:', newItem);
} catch (error) {
console.error('Failed to create item:', error);
}
}
addItem();
Data Structures
User
Object
Represents a user in the system.
Properties
- id (string): Unique identifier for the user.
- name (string): The full name of the user.
- email (string): The email address of the user.
- createdAt (string): The date and time the user was created (ISO 8601 format).
- updatedAt (string): The date and time the user was last updated (ISO 8601 format).
- isActive (boolean): Indicates if the user account is currently active.
Item
Object
Represents an item in the system.
Properties
- id (string): Unique identifier for the item.
- name (string): The name of the item.
- description (string | null): An optional description of the item.
- price (number): The price of the item.
- createdAt (string): The date and time the item was created (ISO 8601 format).
- updatedAt (string): The date and time the item was last updated (ISO 8601 format).