@cbnsndwch/ghl-sdk-storage-memory
v0.5.1
Published
In-memory storage adapter for GHL SDK
Readme
@cbnsndwch/ghl-sdk-storage-memory
In-memory storage adapter for GHL SDK.
Installation
pnpm add @cbnsndwch/ghl-sdk-storage-memoryUsage
import { HighLevel } from '@cbnsndwch/ghl-sdk-core';
import { MemorySessionStorage } from '@cbnsndwch/ghl-sdk-storage-memory';
// Create memory storage
const storage = new MemorySessionStorage();
await storage.init();
storage.setClientId(process.env.GHL_CLIENT_ID);
// Use with HighLevel SDK
const ghl = new HighLevel({
clientId: process.env.GHL_CLIENT_ID,
clientSecret: process.env.GHL_CLIENT_SECRET,
tokenProvider: storage,
});
// Make API calls - tokens will be stored in memory
const contacts = await ghl.contacts.searchContactsAdvanced({
locationId: 'location-id',
// ... search params
});Features
- ✅ Fast in-memory storage
- ✅ Zero external dependencies (only
@cbnsndwch/ghl-sdk-storage) - ✅ Perfect for development and testing
- ✅ ESM-only
- ✅ Full TypeScript support
API
MemorySessionStorage
Extends BaseSessionStorage from @cbnsndwch/ghl-sdk-storage.
Methods
init()- Initialize the storage (no-op for memory)disconnect()- Clear all sessionssetClientId(clientId)- Set the client IDsetSession(resourceId, data)- Store a sessiongetSession(resourceId)- Retrieve a sessiondeleteSession(resourceId)- Delete a sessionhasSession(resourceId)- Check if session existsgetToken(type, id)- Get access token (implements ITokenProvider)setToken(type, id, token, expiresAt)- Store access tokendeleteToken(type, id)- Delete access token
Utility Methods
isStorageActive()- Check if storage is initializedgetSessionCount()- Get number of stored sessionsgetAllSessionKeys()- Get all session keys (debugging)clearAllSessions()- Clear all sessions
Notes
⚠️ Important: Data is stored in memory and will be lost when the application restarts. For production use, consider using @cbnsndwch/ghl-sdk-storage-mongodb or implementing a custom persistent storage adapter.
License
MIT
