sim
sim copied to clipboard
feat(service-now): added service now block
Summary
Brief description of what this PR does and why.
Fixes #(issue)
Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation
- [ ] Other: ___________
Testing
How has this been tested? What should reviewers focus on?
Checklist
- [ ] Code follows project style guidelines
- [ ] Self-reviewed my changes
- [ ] Tests added/updated and passing
- [ ] No new warnings introduced
- [ ] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Screenshots/Videos
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Review | Updated (UTC) |
|---|---|---|---|
| docs | Preview, Comment | Dec 17, 2025 4:35am |
Greptile Overview
Greptile Summary
added comprehensive ServiceNow integration with CRUD operations (create, read, update, delete) and import set functionality. Implementation includes OAuth 2.0 and Basic Auth support, instance-specific OAuth flow with user-provided instance URLs, and proper token management with refresh capability.
Key Changes:
- ServiceNow block with conditional UI fields based on operation and auth method
- Five tool implementations with dual auth support and proper error handling
- OAuth flow with embedded HTML form for instance URL collection, state validation, and secure token storage
- Instance-specific token refresh logic in
oauth.ts - Environment variables for ServiceNow OAuth credentials
- Comprehensive documentation with API reference
Critical Issue Found:
-
apps/sim/blocks/registry.tsaccidentally removed 4 existing blocks (schedule,search,sendgrid,sentry) and their imports - these must be restored immediately to prevent breaking existing workflows
Style Issues:
- Username and password parameters in create and read tools use
'hidden'visibility but should use'user-only'per custom rule 2851870a (only framework-injected tokens should be hidden)
Confidence Score: 1/5
- This PR cannot be merged safely - it will break existing functionality by removing 4 blocks
- Score reflects a critical bug where 4 existing blocks (schedule, search, sendgrid, sentry) were accidentally removed from the registry. While the ServiceNow implementation itself is well-structured with proper OAuth flow, dual auth support, and comprehensive error handling, the accidental deletion of unrelated blocks makes this PR unsafe to merge. The style issues with credential visibility are minor and can be addressed, but the registry bug must be fixed first.
- Pay immediate attention to
apps/sim/blocks/registry.ts- the removed imports and registry entries for schedule, search, sendgrid, and sentry blocks must be restored before merge
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/blocks/registry.ts | 0/5 | accidentally removed 4 existing blocks (schedule, search, sendgrid, sentry) along with their imports |
| apps/sim/tools/servicenow/create.ts | 4/5 | create tool implementation with dual auth support; username/password visibility should be user-only per custom rule |
| apps/sim/tools/servicenow/read.ts | 4/5 | read tool with flexible query options; username/password visibility should be user-only per custom rule |
| apps/sim/app/api/auth/servicenow/authorize/route.ts | 5/5 | OAuth authorization with embedded HTML form for instance URL input, proper URL validation, and state management |
| apps/sim/app/api/auth/oauth2/callback/servicenow/route.ts | 5/5 | OAuth callback with proper state validation, token exchange, and secure cookie handling |
| apps/sim/app/api/auth/oauth2/servicenow/store/route.ts | 4/5 | stores OAuth tokens in database with user info retrieval; includes unused userResponse fetch on line 37 |
Sequence Diagram
sequenceDiagram
participant User
participant SimApp as Sim App
participant AuthRoute as /api/auth/servicenow/authorize
participant SNInstance as ServiceNow Instance
participant CallbackRoute as /api/auth/oauth2/callback/servicenow
participant StoreRoute as /api/auth/oauth2/servicenow/store
participant Database as Database
participant BlockExec as Block Execution
participant SNApi as ServiceNow API
Note over User,SNApi: OAuth Flow
User->>SimApp: Click "Connect ServiceNow"
SimApp->>AuthRoute: GET with returnUrl
AuthRoute->>User: Show instance URL form
User->>AuthRoute: Submit instance URL
AuthRoute->>SNInstance: Redirect to OAuth authorize
SNInstance->>User: Show login & consent
User->>SNInstance: Approve
SNInstance->>CallbackRoute: Redirect with code & state
CallbackRoute->>CallbackRoute: Validate state
CallbackRoute->>SNInstance: POST /oauth_token.do (exchange code)
SNInstance->>CallbackRoute: Return access_token & refresh_token
CallbackRoute->>StoreRoute: Redirect with tokens in cookies
StoreRoute->>SNInstance: GET /api/now/ui/user/current_user
SNInstance->>StoreRoute: Return user info
StoreRoute->>Database: Insert/update account record
StoreRoute->>User: Redirect to workspace with success
Note over User,SNApi: Block Execution Flow
User->>BlockExec: Execute ServiceNow block
BlockExec->>BlockExec: Parse operation & auth method
BlockExec->>Database: Fetch access_token (if OAuth)
Database->>BlockExec: Return credentials
BlockExec->>SNApi: HTTP request with Bearer/Basic auth
SNApi->>BlockExec: Return response
BlockExec->>User: Return formatted output