Spaces:
Running
Running
File size: 19,905 Bytes
cf4f53c c5cff03 e71d582 05b6e5e e71d582 05b6e5e e71d582 cf4f53c 05b6e5e cf4f53c b532a8f 2678346 b532a8f 2678346 b532a8f 2678346 b532a8f cf4f53c b532a8f cf4f53c b532a8f cf4f53c b532a8f 05b6e5e b532a8f cf4f53c f761966 b532a8f cf4f53c 9b053d5 cf4f53c b532a8f cf4f53c e2b0645 cf4f53c e2b0645 cf4f53c e2b0645 cf4f53c b532a8f cf4f53c |
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
<h2 mat-dialog-title>
{{ data.mode === 'create' ? 'Create New API' : data.mode === 'duplicate' ? 'Duplicate API' : 'Edit API' }}
</h2>
<mat-dialog-content>
<form [formGroup]="form">
<mat-tab-group>
<!-- General Tab -->
<mat-tab label="General">
<div class="tab-content">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Name*</mat-label>
<input matInput formControlName="name"
placeholder="e.g., book_flight_api"
[readonly]="data.mode === 'edit'">
<mat-hint>Use only letters, numbers, and underscores</mat-hint>
<mat-error *ngIf="form.get('name')?.hasError('required')">Name is required</mat-error>
<mat-error *ngIf="form.get('name')?.hasError('pattern')">Invalid characters in name</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" class="full-width">
<mat-label>URL*</mat-label>
<input matInput formControlName="url"
placeholder="https://api.example.com/endpoint">
<mat-error *ngIf="form.get('url')?.hasError('required')">URL is required</mat-error>
<mat-error *ngIf="form.get('url')?.hasError('pattern')">Invalid URL format</mat-error>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Method*</mat-label>
<mat-select formControlName="method">
<mat-option *ngFor="let method of httpMethods" [value]="method">
{{ method }}
</mat-option>
</mat-select>
</mat-form-field>
<div class="form-section">
<label class="section-label">Body Template:</label>
<div class="json-editor">
<textarea formControlName="body_template"
placeholder='{"key": "value"}'
rows="8"
class="json-textarea"
(click)="saveCursorPosition('body_template', $event)"
(keyup)="saveCursorPosition('body_template', $event)"></textarea>
<button mat-button type="button"
(click)="validateJSON('body_template')"
[color]="validateJSON('body_template') ? 'primary' : 'warn'">
<mat-icon>check_circle</mat-icon>
Validate JSON
</button>
</div>
<div class="template-helpers">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<mat-icon>help_outline</mat-icon>
Template Variables
</mat-panel-title>
</mat-expansion-panel-header>
<div class="hint-text" style="margin-bottom: 16px; padding: 16px; background-color: #e3f2fd; border-radius: 4px;">
<mat-icon style="vertical-align: middle; color: #1976d2;">info</mat-icon>
<strong style="color: #1976d2;">Important:</strong><br>
Write all variables <strong>without quotes</strong>: <code>{{ '{' }}{{ '{' }}variables.pnr{{ '}' }}{{ '}' }}</code><br>
The system will automatically add quotes for string values during execution.<br><br>
<strong>Examples:</strong><br>
• <code>{{ '{' }} "pnr": {{ '{' }}{{ '{' }}variables.pnr{{ '}' }}{{ '}' }} {{ '}' }}</code> → <code>{{ '{' }} "pnr": "ABC123" {{ '}' }}</code><br>
• <code>{{ '{' }} "count": {{ '{' }}{{ '{' }}variables.passenger_count{{ '}' }}{{ '}' }} {{ '}' }}</code> → <code>{{ '{' }} "count": 2 {{ '}' }}</code><br>
• <code>{{ '{' }} "active": {{ '{' }}{{ '{' }}variables.enabled{{ '}' }}{{ '}' }} {{ '}' }}</code> → <code>{{ '{' }} "active": true {{ '}' }}</code>
</div>
<div class="template-list">
<mat-chip *ngFor="let templateVar of getTemplateVariables()"
(click)="insertTemplateVariable('body_template', templateVar)"
class="template-chip">
{{ templateVar }}
</mat-chip>
</div>
</mat-expansion-panel>
</div>
</div>
<mat-form-field appearance="outline">
<mat-label>Timeout (seconds)*</mat-label>
<input matInput type="number" formControlName="timeout_seconds">
<mat-error *ngIf="form.get('timeout_seconds')?.hasError('required')">Timeout is required</mat-error>
<mat-error *ngIf="form.get('timeout_seconds')?.hasError('min')">Minimum 1 second</mat-error>
<mat-error *ngIf="form.get('timeout_seconds')?.hasError('max')">Maximum 300 seconds</mat-error>
</mat-form-field>
<div class="form-section">
<h4>Retry Settings</h4>
<div formGroupName="retry" class="retry-settings">
<mat-form-field appearance="outline">
<mat-label>Retry Count*</mat-label>
<input matInput type="number" formControlName="retry_count">
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Backoff (seconds)*</mat-label>
<input matInput type="number" formControlName="backoff_seconds">
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Strategy*</mat-label>
<mat-select formControlName="strategy">
<mat-option value="static">Static</mat-option>
<mat-option value="exponential">Exponential</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<mat-form-field appearance="outline" class="full-width">
<mat-label>Response Prompt</mat-label>
<textarea matInput formControlName="response_prompt"
rows="4"
placeholder="Convert the API response to human-friendly text..."></textarea>
<mat-hint>Use {{ '{' }}{{ '{' }}api_response{{ '}' }}{{ '}' }} to reference the API response</mat-hint>
</mat-form-field>
<div class="form-section">
<div class="section-header">
<h4>Response Mappings</h4>
<button mat-raised-button color="primary" type="button" (click)="addResponseMapping()">
<mat-icon>add</mat-icon>
Add Mapping
</button>
</div>
<div formArrayName="response_mappings" class="response-mappings-list">
<div *ngFor="let mapping of responseMappings.controls; let i = index"
[formGroupName]="i"
class="mapping-row">
<mat-form-field appearance="outline">
<mat-label>Variable Name</mat-label>
<input matInput formControlName="variable_name" placeholder="departure_time">
<mat-hint>snake_case only</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Type</mat-label>
<mat-select formControlName="type">
<mat-option *ngFor="let type of variableTypes" [value]="type">
{{ type }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" class="json-path-field">
<mat-label>JSON Path</mat-label>
<input matInput formControlName="json_path" placeholder="FlightInfo.Details.DepartureTime">
<mat-hint>Use dot notation for nested values</mat-hint>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Caption</mat-label>
<input matInput formControlName="caption" placeholder="Kalkış Saati">
<mat-hint>Human-readable label</mat-hint>
</mat-form-field>
<button mat-icon-button color="warn" type="button" (click)="removeResponseMapping(i)">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
<div *ngIf="responseMappings.length === 0" class="empty-state-small">
<mat-icon>info</mat-icon>
<p>No response mappings defined. Use this to extract values from API responses into session variables.</p>
</div>
</div>
<mat-form-field appearance="outline" class="full-width">
<mat-label>Proxy URL (Optional)</mat-label>
<input matInput formControlName="proxy"
placeholder="http://proxy.example.com:8080">
</mat-form-field>
</div>
</mat-tab>
<!-- Headers Tab -->
<mat-tab label="Headers">
<div class="tab-content">
<div class="headers-section">
<div class="section-header">
<h4>Request Headers</h4>
<button mat-raised-button color="primary" type="button" (click)="addHeader()">
<mat-icon>add</mat-icon>
Add Header
</button>
</div>
<div formArrayName="headers" class="headers-list">
<div *ngFor="let header of headers.controls; let i = index"
[formGroupName]="i"
class="header-row">
<mat-form-field appearance="outline">
<mat-label>Key</mat-label>
<input matInput formControlName="key" placeholder="Content-Type">
</mat-form-field>
<mat-form-field appearance="outline" class="header-value">
<mat-label>Value</mat-label>
<input matInput formControlName="value" placeholder="application/json">
</mat-form-field>
<button mat-icon-button color="warn" type="button" (click)="removeHeader(i)">
<mat-icon>delete</mat-icon>
</button>
</div>
</div>
<div *ngIf="headers.length === 0" class="empty-state">
<mat-icon>info</mat-icon>
<p>No headers defined. Click "Add Header" to create one.</p>
</div>
<div class="template-helpers">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<mat-icon>help_outline</mat-icon>
Template Variables for Headers
</mat-panel-title>
</mat-expansion-panel-header>
<div class="template-list">
<mat-chip *ngFor="let templateVar of getTemplateVariables()"
class="template-chip">
<span (click)="headers.length > 0 ? insertHeaderValue(headers.length - 1, templateVar) : null">
{{ templateVar }}
</span>
</mat-chip>
</div>
<p class="hint-text">
Common headers:<br>
<strong>Authorization:</strong> Bearer {{ '{' }}{{ '{' }}auth_tokens.api_name.token{{ '}' }}{{ '}' }}<br>
<strong>Content-Type:</strong> application/json
</p>
</mat-expansion-panel>
</div>
</div>
</div>
</mat-tab>
<!-- Auth Tab -->
<mat-tab label="Auth">
<div class="tab-content">
<div formGroupName="auth">
<mat-checkbox formControlName="enabled">
Enable Authentication
</mat-checkbox>
<div *ngIf="form.get('auth.enabled')?.value" class="auth-settings">
<mat-form-field appearance="outline" class="full-width">
<mat-label>Token Endpoint*</mat-label>
<input matInput formControlName="token_endpoint"
placeholder="https://api.example.com/auth">
<mat-error *ngIf="form.get('auth.token_endpoint')?.hasError('required')">
Token endpoint is required when auth is enabled
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" class="full-width">
<mat-label>Response Token Path*</mat-label>
<input matInput formControlName="response_token_path"
placeholder="access_token or data.token">
<mat-hint>JSON path to extract token from response (e.g., data.token)</mat-hint>
<mat-error *ngIf="form.get('auth.response_token_path')?.hasError('required')">
Token path is required when auth is enabled
</mat-error>
</mat-form-field>
<div class="form-section">
<label class="section-label">Token Request Body:</label>
<div class="json-editor">
<textarea formControlName="token_request_body"
placeholder='{"grant_type": "client_credentials"}'
rows="4"
class="json-textarea"
(click)="saveCursorPosition('auth.token_request_body', $event)"
(keyup)="saveCursorPosition('auth.token_request_body', $event)"></textarea>
<div class="template-helpers">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<mat-icon>help_outline</mat-icon>
Template Variables
</mat-panel-title>
</mat-expansion-panel-header>
<div class="template-list">
<mat-chip *ngFor="let templateVar of getTemplateVariables(false)"
(click)="insertTemplateVariable('auth.token_request_body', templateVar)"
class="template-chip">
{{ templateVar }}
</mat-chip>
</div>
</mat-expansion-panel>
</div>
<button mat-button type="button"
(click)="validateJSON('auth.token_request_body')"
[color]="validateJSON('auth.token_request_body') ? 'primary' : 'warn'">
<mat-icon>check_circle</mat-icon>
Validate JSON
</button>
</div>
</div>
<mat-divider></mat-divider>
<h4>Token Refresh (Optional)</h4>
<mat-form-field appearance="outline" class="full-width">
<mat-label>Token Refresh Endpoint</mat-label>
<input matInput formControlName="token_refresh_endpoint"
placeholder="https://api.example.com/refresh">
</mat-form-field>
<div class="form-section" *ngIf="form.get('auth.token_refresh_endpoint')?.value">
<label class="section-label">Token Refresh Body:</label>
<div class="json-editor">
<textarea formControlName="token_refresh_body"
placeholder='{"refresh_token": "value"}'
rows="4"
class="json-textarea"></textarea>
<button mat-button type="button"
(click)="validateJSON('auth.token_refresh_body')"
[color]="validateJSON('auth.token_refresh_body') ? 'primary' : 'warn'">
<mat-icon>check_circle</mat-icon>
Validate JSON
</button>
</div>
</div>
</div>
</div>
</div>
</mat-tab>
<!-- Test Tab -->
<mat-tab label="Test">
<div class="tab-content">
<div class="test-section">
<h4>Test API Configuration</h4>
<p>Test your API with sample data before saving.</p>
<div class="test-info">
<mat-chip-listbox>
<mat-chip-option selected>{{ form.get('method')?.value || 'POST' }}</mat-chip-option>
<mat-chip-option>{{ form.get('url')?.value || 'No URL set' }}</mat-chip-option>
</mat-chip-listbox>
</div>
<div class="form-section">
<label class="section-label">Test Request JSON:</label>
<div class="json-editor">
<textarea [(ngModel)]="testRequestJson"
[ngModelOptions]="{standalone: true}"
rows="8"
class="json-textarea"
placeholder='{"key": "value"}'></textarea>
<button mat-button type="button"
(click)="updateTestRequestJson()">
<mat-icon>refresh</mat-icon>
Reset to Template
</button>
</div>
<p class="hint-text">
Edit the JSON above to customize test values. Template variables are replaced with placeholder values.
</p>
</div>
<button mat-raised-button color="accent"
(click)="testAPI()"
[disabled]="testing || !form.get('url')?.valid">
<mat-icon>play_arrow</mat-icon>
{{ testing ? 'Testing...' : 'Send Test Request' }}
</button>
<div *ngIf="testResult" class="test-result">
<h4>Test Result:</h4>
<div class="result-status" [class.success]="testResult.success" [class.error]="!testResult.success">
<mat-icon>{{ testResult.success ? 'check_circle' : 'error' }}</mat-icon>
<span>{{ testResult.success ? 'Success' : 'Failed' }}</span>
<span *ngIf="testResult.status_code" class="status-code">
Status: {{ testResult.status_code }}
</span>
<span *ngIf="testResult.response_time_ms" class="response-time">
Time: {{ testResult.response_time_ms }}ms
</span>
</div>
<div *ngIf="testResult.error" class="error-message">
<mat-icon>error_outline</mat-icon>
{{ testResult.error }}
</div>
<div *ngIf="testResult.headers" class="response-section">
<h5>Response Headers:</h5>
<pre>{{ testResult.headers | json }}</pre>
</div>
<div *ngIf="testResult.body !== undefined" class="response-section">
<h5>Response Body:</h5>
<pre>{{ testResult.body }}</pre>
</div>
</div>
<div class="test-note">
<mat-icon>info</mat-icon>
<p>Note: Test requests use the JSON content from the text area above.</p>
</div>
</div>
</div>
</mat-tab>
</mat-tab-group>
</form>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button (click)="cancel()">Cancel</button>
<button mat-raised-button color="primary"
(click)="save()"
[disabled]="form.invalid || saving">
{{ saving ? 'Saving...' : 'Save' }}
</button>
</mat-dialog-actions> |