-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-component.ts
More file actions
73 lines (61 loc) · 2.63 KB
/
test-component.ts
File metadata and controls
73 lines (61 loc) · 2.63 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Configuration, ComponentsApi } from "@systeminit/api-client";
// Test script to verify component API calls work using SDK
const WORKSPACE_API_TOKEN = Deno.env.get('WORKSPACE_API_TOKEN');
const SI_WORKSPACE_ID = Deno.env.get('SI_WORKSPACE_ID');
const COMPONENT_ID = '01K9DFX28X8WGZ08MAG3GY8MJQ'; // Use your actual component ID
const CHANGESET_ID = 'head'; // or your actual changeset ID
if (!WORKSPACE_API_TOKEN || !SI_WORKSPACE_ID) {
console.error('❌ Missing required environment variables');
console.error('Please set WORKSPACE_API_TOKEN and SI_WORKSPACE_ID');
Deno.exit(1);
}
console.log('🔧 Configuration:');
console.log(` Workspace ID: ${SI_WORKSPACE_ID}`);
console.log(` Component ID: ${COMPONENT_ID}`);
console.log(` API Token Length: ${WORKSPACE_API_TOKEN.length} characters`);
console.log('\n🚀 Fetching component using SDK...');
try {
const config = new Configuration({
basePath: 'https://api.systeminit.com',
accessToken: WORKSPACE_API_TOKEN,
baseOptions: {
headers: {
'Authorization': `Bearer ${WORKSPACE_API_TOKEN}`,
'Content-Type': 'application/json'
}
}
});
const componentsApi = new ComponentsApi(config);
const response = await componentsApi.getComponent({
workspaceId: SI_WORKSPACE_ID,
changeSetId: CHANGESET_ID,
componentId: COMPONENT_ID
});
console.log('\n✅ SDK Response received!');
console.log('📊 Full Response:');
console.log(JSON.stringify(response.data, null, 2));
const component = response.data.component;
if (component) {
console.log(`\n🔍 Component Details:`);
console.log(` Name: ${component.name}`);
console.log(` Resource ID: ${component.resourceId}`);
// Check for token in resource payload
const resourcePayload = (component as any).attributes?.['/resource/payload'];
if (resourcePayload?.initialApiToken?.token) {
console.log('\n🎯 Found initialApiToken in resource payload!');
console.log(` Token: ${resourcePayload.initialApiToken.token.substring(0, 50)}...`);
console.log(` Expires: ${resourcePayload.initialApiToken.expiresAt}`);
console.log(` Workspace ID: ${resourcePayload.id}`);
}
// Check resourceProps
console.log(`\n📝 Resource Props:`);
(component as any).resourceProps?.forEach((prop: any, index: number) => {
console.log(` ${index + 1}. ${prop.path} = ${typeof prop.value === 'object' ? JSON.stringify(prop.value) : prop.value}`);
});
}
console.log('\n✅ Script completed successfully!');
} catch (error: any) {
console.error('\n❌ Error:', error.message);
console.error('❌ Error details:', error);
Deno.exit(1);
}