snow-flow 3.0.15 → 3.0.16

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.
@@ -637,7 +637,9 @@ Your widget is deployed and ready for testing in Service Portal.`
637
637
  this.logger.info('✅ Direct deployment successful');
638
638
  }
639
639
  else {
640
- throw new Error(`Widget creation failed: ${result?.error || 'Unknown error'}`);
640
+ // Include detailed error information
641
+ const errorDetails = result?.details ? JSON.stringify(result.details, null, 2) : '';
642
+ throw new Error(`Widget creation failed: ${result?.error || 'Unknown error'}${errorDetails ? '\nDetails: ' + errorDetails : ''}`);
641
643
  }
642
644
  }
643
645
  catch (error) {
@@ -46,6 +46,7 @@ export interface ServiceNowAPIResponse<T> {
46
46
  data?: T;
47
47
  error?: string;
48
48
  result?: T[];
49
+ details?: any;
49
50
  }
50
51
  export declare class ServiceNowClient {
51
52
  private client;
@@ -668,39 +668,91 @@ class ServiceNowClient {
668
668
  }
669
669
  // Ensure we have credentials before making the API call
670
670
  await this.ensureAuthenticated();
671
- const response = await this.client.post(`${this.getBaseUrl()}/api/now/table/sp_widget`, {
671
+ // Log the request details for debugging
672
+ const widgetData = {
672
673
  name: widget.name,
673
- id: widget.id,
674
+ id: widget.id || widget.name, // Ensure id is set
674
675
  title: widget.title,
675
- description: widget.description,
676
+ description: widget.description || '',
676
677
  template: widget.template,
677
- css: widget.css,
678
- client_script: widget.client_script,
679
- script: widget.server_script, // Service Portal uses 'script' not 'server_script'
678
+ css: widget.css || '',
679
+ client_script: widget.client_script || '',
680
+ script: widget.server_script || '', // Service Portal uses 'script' not 'server_script'
680
681
  option_schema: widget.option_schema || '[]',
681
682
  demo_data: widget.demo_data || '{}',
682
- has_preview: widget.has_preview || false,
683
- category: widget.category || 'custom'
684
- }, {
683
+ has_preview: widget.has_preview !== false, // Default to true
684
+ category: widget.category || 'custom',
685
+ active: true // Ensure widget is active
686
+ };
687
+ this.logger.info('Widget data to be sent:', widgetData);
688
+ const response = await this.client.post(`${this.getBaseUrl()}/api/now/table/sp_widget`, widgetData, {
685
689
  timeout: this.deploymentTimeout, // Use deployment-specific timeout
686
690
  headers: {
687
691
  'X-Operation-Type': 'deployment' // Mark as deployment operation
688
692
  }
689
693
  });
690
694
  this.logger.info('✅ Widget created successfully!');
691
- this.logger.info(`🆔 Widget ID: ${response.data.result.sys_id}`);
695
+ // Handle different response structures from ServiceNow
696
+ const widgetResult = response.data.result || response.data;
697
+ const sysId = widgetResult.sys_id;
698
+ if (!sysId) {
699
+ this.logger.warn('⚠️ Widget created but no sys_id returned. Response:', response.data);
700
+ throw new Error('Widget creation succeeded but no sys_id was returned');
701
+ }
702
+ this.logger.info(`🆔 Widget ID: ${sysId}`);
692
703
  // Add post-deployment verification
693
- await this.verifyDeployment(response.data.result.sys_id, 'widget');
704
+ await this.verifyDeployment(sysId, 'widget');
694
705
  return {
695
706
  success: true,
696
- data: response.data.result
707
+ data: widgetResult
697
708
  };
698
709
  }
699
710
  catch (error) {
700
711
  console.error('❌ Failed to create widget:', error);
712
+ // Better error handling for axios errors
713
+ let errorMessage = 'Unknown error';
714
+ let errorDetails = {};
715
+ if (error.response) {
716
+ // The request was made and the server responded with a status code
717
+ // that falls out of the range of 2xx
718
+ errorMessage = `HTTP ${error.response.status}: ${error.response.statusText || 'Request failed'}`;
719
+ errorDetails = {
720
+ status: error.response.status,
721
+ statusText: error.response.statusText,
722
+ data: error.response.data,
723
+ headers: error.response.headers
724
+ };
725
+ // Extract ServiceNow specific error message if available
726
+ if (error.response.data?.error?.message) {
727
+ errorMessage = `ServiceNow Error: ${error.response.data.error.message}`;
728
+ }
729
+ else if (error.response.data?.error) {
730
+ errorMessage = `ServiceNow Error: ${JSON.stringify(error.response.data.error)}`;
731
+ }
732
+ else if (error.response.status === 401) {
733
+ errorMessage = 'Authentication failed: Invalid or expired token. Run: snow-flow auth login';
734
+ }
735
+ else if (error.response.status === 403) {
736
+ errorMessage = 'Permission denied: User lacks sp_admin role or widget creation permissions';
737
+ }
738
+ else if (error.response.status === 404) {
739
+ errorMessage = 'API endpoint not found: ServiceNow instance may not have Service Portal installed';
740
+ }
741
+ }
742
+ else if (error.request) {
743
+ // The request was made but no response was received
744
+ errorMessage = 'No response from ServiceNow - check network connection and instance URL';
745
+ errorDetails = { request: error.config?.url };
746
+ }
747
+ else {
748
+ // Something happened in setting up the request that triggered an Error
749
+ errorMessage = error.message || String(error);
750
+ }
751
+ this.logger.error('Widget creation error details:', errorDetails);
701
752
  return {
702
753
  success: false,
703
- error: error instanceof Error ? error.message : String(error)
754
+ error: errorMessage,
755
+ details: errorDetails
704
756
  };
705
757
  }
706
758
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "3.0.15",
4
- "description": "Snow-Flow v3.0.15: FLOW/WORKFLOW DEPRECATION 🚫 Flows, workflows, and subflows have been officially deprecated and are no longer supported. Focus is now entirely on widgets, applications, and direct ServiceNow development. All flow-related features have been marked as deprecated. Use widgets and applications for UI development instead.",
3
+ "version": "3.0.16",
4
+ "description": "Snow-Flow v3.0.16: WIDGET DEPLOYMENT ERROR FIX! 🔧 Fixed 'error: null' issue in widget deployment. Enhanced error reporting for failed POST requests to /api/now/table/sp_widget. Now provides detailed HTTP status codes, ServiceNow-specific error messages, and better debugging information. Widget deployment failures now show exact cause (401 auth, 403 permissions, 404 endpoint, etc).",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
7
7
  "bin": {