@interdead/identity-core
v0.1.7
Published
Headless identity kernel that wires Discord OAuth with portable storage adapters using a hexagonal/ports-and-adapters layout.
Maintainers
Readme
╭────────────────────────╮ ╭────────╮ ╭──────────╮ │ Proto │ │ Core │ │ IT │ ╰────────────────────────╯ ╰════════╯ ╰──────────╯
Introduction
@interdead/identity-core is a headless identity kernel that wires Discord OAuth with portable storage adapters using a hexagonal/ports-and-adapters layout. The package keeps presentation concerns out of the core while exposing services and factories that host applications can register in their own containers.
Installation
npm install @interdead/identity-coreUsage Examples
import { createIdentityCore, ProfileMetadata } from '@interdead/identity-core';
const identity = createIdentityCore({
discord: {
clientId: process.env.IDENTITY_DISCORD_CLIENT_ID!,
clientSecret: process.env.IDENTITY_DISCORD_CLIENT_SECRET!,
redirectUri: process.env.IDENTITY_DISCORD_REDIRECT_URI!
},
cloudflare: bindings,
sessionStore,
eventBus,
logger
});
const profile = new ProfileMetadata({ profileId: 'player-123', displayName: 'Visitor' });
await identity.linkService.beginDiscordLogin('discord_state', 'nonce');
const aggregate = await identity.linkService.completeDiscordLogin('player-123', 'code-from-callback', profile);Additional Notes
- Features: Discord login with optional Cloudflare persistence or local-only storage; domain-driven aggregate tracking; ports for prompts, events, and EFBD scale sync; factory helper
createIdentityCoreto wire services quickly. - Configuration:
- Discord: provide OAuth client credentials and redirect URI via
IDENTITY_DISCORD_CLIENT_ID,IDENTITY_DISCORD_CLIENT_SECRET, andIDENTITY_DISCORD_REDIRECT_URI. Custom endpoints are supported for staging. - Cloudflare: D1 database name
interdead_corewith shared Worker bindingINTERDEAD_CORE; pass D1/KV bindings to enable persistence. Omit to rely on in-memory local storage. - Feature flags: skip Discord or scale synchronization by omitting those adapters when calling
createIdentityCore.
- Discord: provide OAuth client credentials and redirect URI via
- Cloudflare schema:
CREATE TABLE profiles (
profile_id TEXT PRIMARY KEY,
data TEXT NOT NULL
);- Testing:
npm test. - Errors are wrapped in
IdentityCoreErrorto avoid leaking raw fetch/D1 exceptions. Consumers can catch and map these errors to UI states.
