File size: 1,428 Bytes
34367da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { config } from 'dotenv';
import { resolve } from 'path';

const __dirname = new URL('.', import.meta.url).pathname.replace(/^\/([A-Z]:)/, '$1');
config({ path: resolve(__dirname, '../.env') });

import { createShowpadAuthFromEnv } from '../src/services/showpad/showpad-auth.js';

async function main() {
  console.log('Testing Showpad with existing auth service...\n');
  console.log('Subdomain:', process.env.SHOWPAD_SUBDOMAIN);
  console.log('Username:', process.env.SHOWPAD_USERNAME);
  console.log('Password:', process.env.SHOWPAD_PASSWORD ? '***' : '(missing)');
  console.log('');

  try {
    const auth = createShowpadAuthFromEnv();
    console.log('Attempting authentication...');
    await auth.authenticate();

    const state = auth.getState();
    console.log('✅ Authentication successful!');
    console.log('   Token expires:', new Date(state.expiresAt!).toISOString());
    console.log('   Scopes:', state.scope.join(', '));

    // Try to fetch some assets
    console.log('\nFetching assets...');
    const assets = await auth.request<{items: any[]}>('/assets?limit=5');
    console.log('✅ Fetched ' + assets.items.length + ' assets');

    for (const asset of assets.items) {
      console.log('   - ' + asset.name + ' (' + (asset.mimeType || 'unknown') + ')');
    }

  } catch (error: any) {
    console.error('❌ Error:', error.message);
  }
}

main();