@sentinel-unturned/integration-sdk
v1.0.0
Published
SDK for building Sentinel integrations with full TypeScript support
Downloads
32
Maintainers
Readme
@sentinel-unturned/integration-sdk
Build type-safe integrations for Sentinel with full TypeScript support.
Installation
npm install @sentinel-unturned/integration-sdk zodQuick Start
1. Create Your Manifest
{
"name": "my-integration",
"slug": "my-integration",
"displayName": "My Integration",
"description": "Does something cool",
"version": "1.0.0",
"author": "Your Name",
"license": "MIT",
"scope": "organization",
"events": {
"subscribes": ["player.created", "moderation.ban.*"]
},
"config": {
"webhookUrl": {
"type": "string",
"required": true,
"description": "Where to send events"
}
}
}2. Validate Your Manifest
import { validateManifest } from '@sentinel-unturned/integration-sdk';
const result = validateManifest(manifest);
if (!result.success) {
console.error('Invalid manifest:', result.errors);
}3. Handle Webhooks
import {
createWebhookRouter,
successResponse,
EVENTS,
} from '@sentinel-unturned/integration-sdk';
const router = createWebhookRouter({
[EVENTS.PLAYER.CREATED]: async (payload) => {
console.log('New player:', payload.data.name);
return successResponse('Processed');
},
[EVENTS.MODERATION.BAN_CREATED]: async (payload) => {
const { player, reason, duration } = payload.data;
console.log(`${player.name} banned for: ${reason}`);
return successResponse();
},
});
// Express example
app.post('/webhook', async (req, res) => {
const result = await router(req.body);
res.json(result);
});4. Verify Webhook Signatures
import { verifyWebhookSignature } from '@sentinel-unturned/integration-sdk';
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-sentinel-signature'];
const isValid = verifyWebhookSignature(
req.body.toString(),
signature,
process.env.WEBHOOK_SECRET
);
if (!isValid) {
return res.status(401).send('Invalid signature');
}
// Process webhook...
});API Reference
Types
IntegrationManifest- Complete manifest structureWebhookPayload<T>- Typed webhook payloadEventType- All event type stringsEventPayload<T>- Payload for specific event type
Validators
validateManifest(manifest)- Validate manifest objectparseManifest(manifest)- Parse and validate (throws on error)manifestSchema- Zod schema for manifest
Helpers
createWebhookRouter(handlers)- Create typed event routerverifyWebhookSignature(payload, signature, secret)- Verify HMAC signaturesuccessResponse(message?, data?)- Create success responseerrorResponse(message)- Create error response
Constants
EVENTS- All event name constantsEVENT_PATTERNS- Wildcard patterns for subscriptions
Event Types
Player Events
player.created- New player registeredplayer.updated- Player data updatedplayer.connected- Player joined serverplayer.disconnected- Player left server
Moderation Events
moderation.ban.created- Player bannedmoderation.ban.removed- Ban liftedmoderation.kick.created- Player kickedmoderation.warn.created- Player warnedmoderation.mute.created- Player mutedmoderation.mute.removed- Mute lifted
Server Events
gameserver.connected- Server came onlinegameserver.disconnected- Server went offline
Organization Events
organization.created- Organization createdorganization.updated- Organization updatedorganization.deleted- Organization deletedorganization.member.added- Member addedorganization.member.removed- Member removed
Integration Events
integration.installed- Integration installedintegration.uninstalled- Integration removedintegration.enabled- Integration enabledintegration.disabled- Integration disabledintegration.configured- Configuration updated
Wildcard Patterns
Subscribe to multiple events using patterns:
{
"events": {
"subscribes": [
"player.*",
"moderation.ban.*",
"*"
]
}
}Available patterns:
*- All eventsplayer.*- All player eventsmoderation.*- All moderation eventsmoderation.ban.*- Ban created/removedmoderation.mute.*- Mute created/removedgameserver.*- Server connect/disconnectorganization.*- All organization eventsintegration.*- All integration events
Examples
See the examples/ directory for complete integration examples:
discord-notifier- Send events to Discord
License
MIT
