Files
indee-demo/scripts/seed-profiles.ts
Dorian ab0560de00 Add WebSocket support and update dependencies
- Introduced WebSocket polyfill for Node.js in seed-activity.ts and seed-profiles.ts to support applesauce-relay and RxJS.
- Updated package.json and package-lock.json to include 'ws' version 8.19.0 and '@types/ws' version 8.18.1 as dependencies.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 13:25:58 +00:00

70 lines
2.0 KiB
TypeScript

// Polyfill WebSocket for Node.js (required by applesauce-relay / RxJS)
import WebSocket from 'ws'
if (!globalThis.WebSocket) {
;(globalThis as unknown as Record<string, unknown>).WebSocket = WebSocket
}
import { Relay } from 'applesauce-relay'
import { PrivateKeySigner } from 'applesauce-signers/signers/private-key-signer'
import {
TEST_PERSONAS,
TASTEMAKER_PERSONAS,
} from '../src/data/testPersonas.js'
const RELAY_URL = process.env.RELAY_URL || 'ws://localhost:7777'
type Persona = { name: string; nsec: string; pubkey: string }
function buildProfile(persona: Persona, role: 'test' | 'tastemaker') {
const about =
role === 'tastemaker'
? `${persona.name} — tastemaker for IndeeHub`
: `${persona.name} — test persona for IndeeHub`
return {
name: persona.name,
display_name: persona.name,
about,
picture: `https://robohash.org/${persona.pubkey}.png`,
bot: true,
}
}
async function seedProfiles() {
const relay = new Relay(RELAY_URL)
const allPersonas: { persona: Persona; role: 'test' | 'tastemaker' }[] = [
...TEST_PERSONAS.map((p) => ({ persona: p as Persona, role: 'test' as const })),
...TASTEMAKER_PERSONAS.map((p) => ({ persona: p as Persona, role: 'tastemaker' as const })),
]
const now = Math.floor(Date.now() / 1000)
for (const { persona, role } of allPersonas) {
const signer = PrivateKeySigner.fromKey(persona.nsec)
const profile = buildProfile(persona, role)
const signed = await signer.signEvent({
kind: 0,
created_at: now,
tags: [],
content: JSON.stringify(profile),
})
try {
const res = await relay.publish(signed, { timeout: 5000 })
console.log(`${persona.name} (${role}): ${res.ok ? 'OK' : res.message}`)
} catch (err) {
console.error(`${persona.name} (${role}):`, err)
}
}
// Give relay time to flush, then exit
setTimeout(() => process.exit(0), 1000)
}
seedProfiles().catch((err) => {
console.error('Fatal:', err)
process.exit(1)
})