@north7/entraaware 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/index.js +45 -8
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -30,15 +30,22 @@ function getCredentials() {
30
30
  function getAzureCredential() {
31
31
  if (!azureCredential) {
32
32
  try {
33
- // First try to create a DefaultAzureCredential that can use Azure CLI or other authentication methods
33
+ // Try DefaultAzureCredential which includes CLI credentials
34
+ console.error("Attempting to use DefaultAzureCredential (will try Azure CLI if environment variables not set)");
34
35
  azureCredential = new DefaultAzureCredential();
35
- console.error("Using DefaultAzureCredential - will try Azure CLI if environment variables not set");
36
36
  }
37
37
  catch (error) {
38
- // Fall back to ClientSecretCredential if DefaultAzureCredential fails
39
- console.error("DefaultAzureCredential failed, falling back to ClientSecretCredential");
40
- const { tenantId, clientId, clientSecret } = getCredentials();
41
- azureCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
38
+ // Fall back to ClientSecretCredential
39
+ console.error(`DefaultAzureCredential failed: ${error instanceof Error ? error.message : String(error)}`);
40
+ console.error("Falling back to ClientSecretCredential");
41
+ try {
42
+ const { tenantId, clientId, clientSecret } = getCredentials();
43
+ azureCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
44
+ }
45
+ catch (secretError) {
46
+ console.error(`ClientSecretCredential failed: ${secretError instanceof Error ? secretError.message : String(secretError)}`);
47
+ throw new Error("Failed to initialize any Azure credential. Please ensure you are logged in with 'az login' or have set environment variables.");
48
+ }
42
49
  }
43
50
  }
44
51
  return azureCredential;
@@ -90,6 +97,7 @@ server.tool("askEntra", "Direct access to Microsoft Graph API for accurate Entra
90
97
  top: z.number().optional().describe("Shorthand for $top query parameter"),
91
98
  count: z.boolean().optional().describe("Shorthand for $count=true to include count of items"),
92
99
  }, async ({ path, method, queryParams = {}, body, apiVersion, fetchAllPages, consistencyLevel, select, filter, expand, orderBy, top, count }) => {
100
+ console.error(`[askEntra] Processing request: ${method} ${path}`);
93
101
  try {
94
102
  // Process shorthand query parameters
95
103
  const processedParams = { ...queryParams };
@@ -105,27 +113,35 @@ server.tool("askEntra", "Direct access to Microsoft Graph API for accurate Entra
105
113
  processedParams['$top'] = top.toString();
106
114
  if (count)
107
115
  processedParams['$count'] = 'true';
108
- // Initialize or get Graph client
116
+ console.error(`[askEntra] Getting Azure credential`);
117
+ // Initialize or get Azure credential
118
+ const credential = getAzureCredential();
119
+ console.error(`[askEntra] Initializing Graph client`);
120
+ // Initialize Graph client if not already done
109
121
  if (!graphClient) {
110
- const credential = getAzureCredential();
111
122
  const authProvider = new TokenCredentialAuthenticationProvider(credential, {
112
123
  scopes: ["https://graph.microsoft.com/.default"],
113
124
  });
114
125
  graphClient = Client.initWithMiddleware({ authProvider });
126
+ console.error(`[askEntra] Graph client initialized`);
115
127
  }
116
128
  // Build request with API path and version
129
+ console.error(`[askEntra] Creating request for ${path} with version ${apiVersion}`);
117
130
  let request = graphClient.api(path).version(apiVersion);
118
131
  // Add query parameters
119
132
  if (Object.keys(processedParams).length > 0) {
133
+ console.error(`[askEntra] Adding query parameters: ${JSON.stringify(processedParams)}`);
120
134
  request = request.query(processedParams);
121
135
  }
122
136
  // Add consistency level header if provided
123
137
  if (consistencyLevel) {
138
+ console.error(`[askEntra] Adding consistency level: ${consistencyLevel}`);
124
139
  request = request.header('ConsistencyLevel', consistencyLevel);
125
140
  }
126
141
  // Handle pagination for GET requests
127
142
  let result;
128
143
  if (method === 'get' && fetchAllPages) {
144
+ console.error(`[askEntra] Executing GET with pagination`);
129
145
  const firstPage = await request.get();
130
146
  // If no pagination needed, return first page
131
147
  if (!firstPage["@odata.nextLink"]) {
@@ -136,6 +152,7 @@ server.tool("askEntra", "Direct access to Microsoft Graph API for accurate Entra
136
152
  const allItems = [...(firstPage.value || [])];
137
153
  let nextLink = firstPage["@odata.nextLink"];
138
154
  while (nextLink) {
155
+ console.error(`[askEntra] Fetching next page: ${nextLink}`);
139
156
  const nextPage = await graphClient.api(nextLink).get();
140
157
  if (nextPage.value)
141
158
  allItems.push(...nextPage.value);
@@ -151,6 +168,7 @@ server.tool("askEntra", "Direct access to Microsoft Graph API for accurate Entra
151
168
  }
152
169
  else {
153
170
  // Execute appropriate method
171
+ console.error(`[askEntra] Executing ${method} request`);
154
172
  switch (method) {
155
173
  case 'get':
156
174
  result = await request.get();
@@ -170,9 +188,14 @@ server.tool("askEntra", "Direct access to Microsoft Graph API for accurate Entra
170
188
  break;
171
189
  }
172
190
  }
191
+ console.error(`[askEntra] Successfully executed request`);
173
192
  return formatApiResponse('Entra', method, path, result);
174
193
  }
175
194
  catch (err) {
195
+ console.error(`[askEntra] ERROR: ${err instanceof Error ? err.message : String(err)}`);
196
+ if (err instanceof Error && err.stack) {
197
+ console.error(`[askEntra] Stack trace: ${err.stack}`);
198
+ }
176
199
  return formatErrorResponse(err, 'Entra');
177
200
  }
178
201
  });
@@ -197,6 +220,7 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
197
220
  resourceGroupName: z.string().optional().describe("Resource group name for resource operations"),
198
221
  resourceName: z.string().optional().describe("Resource name for resource operations"),
199
222
  }, async ({ path, method, apiVersion, subscriptionId, body, queryParams = {}, fetchAllPages, operation = "custom", providerNamespace, resourceType, resourceGroupName, resourceName }) => {
223
+ console.error(`[askAzure] Processing request: ${operation} - ${method} ${path}`);
200
224
  try {
201
225
  // Default API versions for common resource types
202
226
  const defaultApiVersions = {
@@ -286,6 +310,7 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
286
310
  throw new Error("Azure Resource Management API requires an 'apiVersion' parameter");
287
311
  }
288
312
  // Get Azure credential
313
+ console.error(`[askAzure] Getting Azure credential`);
289
314
  const credential = getAzureCredential();
290
315
  // Construct the base URL and path
291
316
  const baseUrl = "https://management.azure.com";
@@ -297,10 +322,12 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
297
322
  const params = new URLSearchParams(queryParams);
298
323
  if (apiVersion)
299
324
  params.set('api-version', apiVersion);
325
+ console.error(`[askAzure] Requesting token for Azure Resource Management API`);
300
326
  // Get access token
301
327
  const tokenResponse = await credential.getToken("https://management.azure.com/.default");
302
328
  if (!tokenResponse?.token)
303
329
  throw new Error("Failed to acquire Azure access token");
330
+ console.error(`[askAzure] Successfully acquired token`);
304
331
  // Prepare request options
305
332
  const headers = {
306
333
  'Authorization': `Bearer ${tokenResponse.token}`,
@@ -315,10 +342,12 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
315
342
  }
316
343
  // Construct URL
317
344
  const url = `${baseUrl}${fullPath}?${params.toString()}`;
345
+ console.error(`[askAzure] Making request to ${url}`);
318
346
  // Execute request with pagination if needed
319
347
  let result;
320
348
  if (method === 'get' && fetchAllPages) {
321
349
  // Fetch first page
350
+ console.error(`[askAzure] Executing GET with pagination`);
322
351
  const response = await fetch(url, options);
323
352
  if (!response.ok) {
324
353
  const errorText = await response.text();
@@ -334,6 +363,7 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
334
363
  const allItems = [...(firstPage.value || [])];
335
364
  let nextLink = firstPage.nextLink;
336
365
  while (nextLink) {
366
+ console.error(`[askAzure] Fetching next page: ${nextLink}`);
337
367
  const pageResponse = await fetch(nextLink, options);
338
368
  if (!pageResponse.ok)
339
369
  throw new Error(`Azure API pagination error: ${pageResponse.status}`);
@@ -350,9 +380,11 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
350
380
  }
351
381
  else {
352
382
  // Single page request
383
+ console.error(`[askAzure] Executing ${method} request`);
353
384
  const response = await fetch(url, options);
354
385
  if (!response.ok) {
355
386
  const errorText = await response.text();
387
+ console.error(`[askAzure] Request failed with status ${response.status}: ${errorText}`);
356
388
  let errorDetail;
357
389
  try {
358
390
  errorDetail = JSON.parse(errorText);
@@ -368,9 +400,14 @@ server.tool("askAzure", "Direct access to Azure Resource Management API for mana
368
400
  const text = await response.text();
369
401
  result = text ? JSON.parse(text) : { status: "Success" };
370
402
  }
403
+ console.error(`[askAzure] Successfully executed request`);
371
404
  return formatApiResponse('Azure', method, path, result);
372
405
  }
373
406
  catch (err) {
407
+ console.error(`[askAzure] ERROR: ${err instanceof Error ? err.message : String(err)}`);
408
+ if (err instanceof Error && err.stack) {
409
+ console.error(`[askAzure] Stack trace: ${err.stack}`);
410
+ }
374
411
  return formatErrorResponse(err, 'Azure');
375
412
  }
376
413
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north7/entraaware",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "build/index.js",
6
6
  "bin": {