#!/usr/bin/env node const fetch = require('node-fetch'); const { SDKSignerClient } = require('sdk-signer-client'); // Quick test configuration const BASE_URL = 'http://localhost:8080'; const ENDPOINT = '/api/v1/idnot/user/rattachements'; // Base endpoint, idnot will be added as path parameter const signerConfig = { url: process.env.SIGNER_WS_URL || 'ws://localhost:9090', apiKey: process.env.SIGNER_API_KEY || 'your-api-key-change-this', timeout: 30000, reconnectInterval: 5000, maxReconnectAttempts: 3 }; // Test with a specific IDNot async function testWithIdNot(idNot) { if (!idNot) { console.log('šŸ’” Usage: node quick-test-rattachements.js [idNot]'); console.log(' Example: node quick-test-rattachements.js 12345'); console.log(' Example: node quick-test-rattachements.js (no parameter to test without idNot)'); console.log(' URL format: /api/v1/idnot/user/{idnot}/rattachements'); return; } console.log(`šŸ†” Testing with IDNot: ${idNot}`); // Build URL with path parameter let url = `${BASE_URL}${ENDPOINT}`; url += `?idNot=${encodeURIComponent(idNot)}`; console.log(`šŸ“ URL: ${url}`); console.log('=' .repeat(60)); try { const response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json' } }); console.log(`šŸ“Š Status: ${response.status} ${response.statusText}`); const responseText = await response.text(); console.log(`šŸ“„ Response length: ${responseText.length} characters`); let data; try { data = JSON.parse(responseText); console.log('šŸ“‹ Parsed JSON response:'); console.log(JSON.stringify(data, null, 2)); } catch (e) { console.log('šŸ“‹ Raw response (not JSON):'); console.log(responseText); return; } for (const office of data) { let officeRattachementsData = []; // Now test the office rattachements const officeRattachements = await fetch(`${BASE_URL}/api/v1/idnot/office/rattachements?idNot=${office.ou}`, { method: 'GET', headers: { 'Accept': 'application/json' } }); console.log(`šŸ“Š Status: ${officeRattachements.status} ${officeRattachements.statusText}`); const officeRattachementsText = await officeRattachements.text(); console.log(`šŸ“„ Response length: ${officeRattachementsText.length} characters`); try { officeRattachementsData = JSON.parse(officeRattachementsText); console.log('šŸ“‹ Parsed JSON response:'); console.log(JSON.stringify(officeRattachementsData, null, 2)); } catch (e) { console.log('šŸ“‹ Raw response (not JSON):'); console.log(officeRattachementsText); return; } // Now try to create a new process with all the users that have `activite` set to `En exercice` const usersToAdd = officeRattachementsData.result.filter(user => user.activite === 'En exercice'); console.log(`šŸ“‹ Users to add: ${usersToAdd.length}`); console.log(JSON.stringify(usersToAdd, null, 2)); // Probably the idnot number should be public so that caller can easily find the processId? // Caller can now create the office process with the following data const processData = { name: 'New Process', description: 'New Process Description', timestamp: new Date().toISOString(), office: office.ou, }; const privateFields = Object.keys(processData); privateFields.splice(privateFields.indexOf('office'), 1); // Make office public data const roles = { owner: { members: usersToAdd.map(user => user.uid), validation_rules: [ { quorum: 0.1, fields: [...privateFields, 'roles', 'office'], min_sig_member: 1, }, ], storages: ["https://dev3.4nkweb.com/storage"] }, apophis: { members: usersToAdd.map(user => user.uid), validation_rules: [], storages: [] } }; } } catch (error) { console.log(`šŸ’„ Error: ${error.message}`); } } // Main execution async function main() { const idNot = process.argv[2]; // Get IDNot from command line argument console.log('šŸš€ Quick Rattachements Endpoint Test'); console.log('=' .repeat(60)); // Check if server is running try { const healthCheck = await fetch(`${BASE_URL}/api/v1/health`); if (healthCheck.ok) { console.log('āœ… Server is running'); } else { console.log(`āš ļø Server responded but health check failed with status: ${healthCheck.status}`); } } catch (error) { console.log('āŒ Server is not responding'); console.log('šŸ’” Make sure to start your server first with: npm run dev'); return; } console.log(''); await testWithIdNot(idNot); console.log('\nšŸ’” Usage: node quick-test-rattachements.js [idNot]'); console.log(' Example: node quick-test-rattachements.js 12345'); console.log(' Example: node quick-test-rattachements.js (no parameter to test without idNot)'); console.log(' URL format: /api/v1/idnot/user/{idnot}/rattachements'); } main().catch(console.error);