/** * Test User Zero Configuration * * Based on TimeSafari crowd-master User Zero configuration * This provides the necessary credentials and settings for testing * the daily notification plugin with stars querying functionality. * * @author Matthew Raymer * @version 1.0.0 */ export const TEST_USER_ZERO_CONFIG = { // User Zero Identity (from crowd-master testUtils.ts) identity: { did: "did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F", name: "User Zero", seedPhrase: "rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage" }, // API Configuration api: { // Use staging API server for testing server: "https://api-staging.timesafari.com", // Stars querying endpoint (from crowd-master endorserServer.ts) starsEndpoint: "/api/v2/report/plansLastUpdatedBetween", // Authentication jwtExpirationMinutes: 1, // Short-lived tokens like crowd-master jwtAlgorithm: "HS256" }, // Test Starred Projects (mock data for testing) starredProjects: { // Sample starred project IDs for testing planIds: [ "test_project_1", "test_project_2", "test_project_3", "demo_project_alpha", "demo_project_beta" ], // Last acknowledged JWT ID (for pagination testing) lastAckedJwtId: "1704067200_abc123_def45678" }, // Notification Configuration notifications: { // Fetch timing: 5 minutes before notification (as requested) fetchLeadTimeMinutes: 5, // Schedule time for testing scheduleTime: "09:00", // Test notification content defaultTitle: "Daily Stars Update", defaultBody: "New changes detected in your starred projects!" }, // Testing Configuration testing: { // Enable mock responses for offline testing enableMockResponses: true, // Network timeouts timeoutMs: 30000, retryAttempts: 3, retryDelayMs: 1000, // Debug settings debugMode: true, logLevel: "INFO" } } as const; /** * Mock starred projects response for offline testing * Based on crowd-master test fixtures */ export const MOCK_STARRED_PROJECTS_RESPONSE = { data: [ { planSummary: { jwtId: "1704067200_abc123_def45678", handleId: "test_project_1", name: "Test Project 1", description: "First test project for User Zero", issuerDid: "did:key:test_issuer_1", agentDid: "did:key:test_agent_1", startTime: "2025-01-01T00:00:00Z", endTime: "2025-01-31T23:59:59Z", locLat: 40.7128, locLon: -74.0060, url: "https://test-project-1.com" }, previousClaim: { jwtId: "1703980800_xyz789_0badf00d", claimType: "project_update" } }, { planSummary: { jwtId: "1704153600_mno345_0badf00d", handleId: "test_project_2", name: "Test Project 2", description: "Second test project for User Zero", issuerDid: "did:key:test_issuer_2", agentDid: "did:key:test_agent_2", startTime: "2025-02-01T00:00:00Z", endTime: "2025-02-28T23:59:59Z", locLat: null, locLon: null }, previousClaim: { jwtId: "1704067200_stu901_1cafebad", claimType: "project_update" } } ], hitLimit: false, pagination: { hasMore: false, nextAfterId: null } } as const; /** * Generate test JWT token for User Zero * Mimics the crowd-master createEndorserJwtForDid function */ export function generateTestJWT(): string { const nowEpoch = Math.floor(Date.now() / 1000); const endEpoch = nowEpoch + TEST_USER_ZERO_CONFIG.api.jwtExpirationMinutes * 60; const header = { alg: TEST_USER_ZERO_CONFIG.api.jwtAlgorithm, typ: "JWT" }; const payload = { exp: endEpoch, iat: nowEpoch, iss: TEST_USER_ZERO_CONFIG.identity.did, sub: TEST_USER_ZERO_CONFIG.identity.did }; // Simple base64 encoding for testing (not cryptographically secure) const encodedHeader = btoa(JSON.stringify(header)); const encodedPayload = btoa(JSON.stringify(payload)); const signature = "test_signature_for_development_only"; return `${encodedHeader}.${encodedPayload}.${signature}`; } /** * Test User Zero API client for stars querying */ export class TestUserZeroAPI { private baseUrl: string; private jwt: string; constructor(baseUrl: string = TEST_USER_ZERO_CONFIG.api.server) { this.baseUrl = baseUrl; this.jwt = generateTestJWT(); } /** * Query starred projects for changes * Mimics crowd-master getStarredProjectsWithChanges function */ async getStarredProjectsWithChanges( starredPlanIds: string[], afterId?: string ): Promise { if (TEST_USER_ZERO_CONFIG.testing.enableMockResponses) { // Return mock data for offline testing console.log("๐Ÿงช Using mock starred projects response"); return MOCK_STARRED_PROJECTS_RESPONSE; } // Real API call (when mock is disabled) const url = `${this.baseUrl}${TEST_USER_ZERO_CONFIG.api.starsEndpoint}`; const headers = { 'Authorization': `Bearer ${this.jwt}`, 'Content-Type': 'application/json', 'User-Agent': 'TimeSafari-DailyNotificationPlugin/1.0.0' }; const requestBody = { planIds: starredPlanIds, afterId: afterId || TEST_USER_ZERO_CONFIG.starredProjects.lastAckedJwtId }; console.log("๐ŸŒ Making real API call to:", url); console.log("๐Ÿ“ฆ Request body:", requestBody); const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(requestBody) }); if (!response.ok) { throw new Error(`API call failed: ${response.status} ${response.statusText}`); } return await response.json(); } /** * Refresh JWT token */ refreshToken(): void { this.jwt = generateTestJWT(); console.log("๐Ÿ”„ JWT token refreshed"); } /** * Get current JWT token */ getJWT(): string { return this.jwt; } } export default TEST_USER_ZERO_CONFIG;