UNPKG

thrivestack-node-sdk

Version:

Official ThriveStack Analytics SDK for Node.js and Next.js server-side applications

87 lines 3.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ThriveStack_1 = require("./ThriveStack"); async function testThriveStack() { console.log('Testing ThriveStack TypeScript SDK...\n'); // Test 1: Basic initialization console.log('1. Testing basic initialization...'); const thriveStack = new ThriveStack_1.ThriveStack({ apiKey: "/0h1H3frdqN8u1C99q03MMu+VO8YbQeXbNa1VQPXf3A=", source: "marketing,product", batchSize: 1, // Small batch size for testing batchInterval: 1000 }); console.log('✓ ThriveStack instance created successfully'); console.log('Device ID:', thriveStack.getDeviceId()); console.log('Session ID:', thriveStack.getSessionId()); // Test 2: Configuration console.log('\n2. Testing configuration...'); const config = thriveStack.getConfig(); console.log('✓ Configuration retrieved:', { apiEndpoint: config.apiEndpoint, batchSize: config.batchSize, source: config.source }); // Test 3: Consent management console.log('\n3. Testing consent management...'); thriveStack.setConsent('functional', true); thriveStack.setConsent('analytics', true); thriveStack.setConsent('marketing', false); console.log('✓ Consent settings applied'); // Test 4: Tracking permissions console.log('\n4. Testing tracking permissions...'); console.log('Should track:', thriveStack.shouldTrack()); console.log('Analytics allowed:', thriveStack.isTrackingAllowed('analytics')); console.log('Marketing allowed:', thriveStack.isTrackingAllowed('marketing')); // Test 5: Event capture (without actually sending to API) console.log('\n5. Testing event capture...'); try { await thriveStack.capturePageVisit({ title: 'Test Page', url: 'https://test.com/page', path: '/test' }); console.log('✓ Page visit event captured'); await thriveStack.captureEvent('test_event', { test_property: 'test_value', timestamp: Date.now() }); console.log('✓ Custom event captured'); } catch (error) { console.log('⚠ Event capture failed (expected without valid API key):', error.message); } // Test 6: Interaction history console.log('\n6. Testing interaction history...'); const history = thriveStack.getInteractionHistory(); console.log('✓ Interaction history length:', history.length); // Test 7: User and group management console.log('\n7. Testing user and group management...'); try { await thriveStack.setUser('test-user-123', 'test@example.com', { name: 'Test User', role: 'tester' }); console.log('✓ User set successfully'); await thriveStack.setGroup('test-group-456', 'test.com', 'Test Group', { type: 'test' }); console.log('✓ Group set successfully'); } catch (error) { console.log('⚠ User/Group API calls failed (expected without valid API key):', error.message); } // Test 8: Debug mode console.log('\n8. Testing debug mode...'); thriveStack.enableDebugMode(); console.log('✓ Debug mode enabled'); console.log('\n🎉 All tests completed successfully!'); console.log('\nThe ThriveStack TypeScript SDK is working correctly.'); console.log('Note: API calls will fail without a valid API key, which is expected behavior.'); } // Run the test testThriveStack().catch(error => { console.error('Test failed:', error); process.exit(1); }); //# sourceMappingURL=test.js.map