@molecule/app-http-inspector-angular 0.0.1-stage → 1.1.0

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/README.md +461 -4
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,11 +1,468 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-21T12:46:36.971Z
7
+ -->
8
+
1
9
  # @molecule/app-http-inspector-angular
2
10
 
3
- HTTP method + URL builder + headers/params/body tabs + response status/timing display
11
+ Angular HTTP request builder + response inspector — the counterpart of
12
+ `@molecule/app-http-inspector-react`: the same props and the same DOM for the
13
+ same input.
14
+
15
+ Exports `<HttpInspector>`, `HttpMethod`, `HttpHeader`, `HttpResponse` types.
16
+
17
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
18
+ > It is written to be read by coding agents as much as by people, and is generated from this
19
+ > package's source — edit `src/index.ts` JSDoc, not this file.
20
+
21
+ ## Quick Start
22
+
23
+ ```ts
24
+ import { Component, signal } from '@angular/core'
25
+ import { HttpInspector } from '@molecule/app-http-inspector-angular'
26
+ import type { HttpHeader, HttpMethod, HttpResponse } from '@molecule/app-http-inspector-angular'
27
+
28
+ @Component({
29
+ selector: 'app-inspector',
30
+ standalone: true,
31
+ imports: [HttpInspector],
32
+ template: `
33
+ <div
34
+ mol-http-inspector
35
+ [method]="method()"
36
+ (onMethodChange)="method.set($event)"
37
+ [url]="url()"
38
+ (onUrlChange)="url.set($event)"
39
+ [headers]="headers()"
40
+ (onHeadersChange)="headers.set($event)"
41
+ [body]="body()"
42
+ (onBodyChange)="body.set($event)"
43
+ [onSend]="send"
44
+ [sending]="sending()"
45
+ [response]="response()"
46
+ ></div>
47
+ `,
48
+ })
49
+ export class Inspector {
50
+ readonly method = signal<HttpMethod>('GET')
51
+ readonly url = signal('https://api.example.com/v1/users')
52
+ readonly headers = signal<HttpHeader[]>([])
53
+ readonly body = signal('')
54
+ readonly sending = signal(false)
55
+ readonly response = signal<HttpResponse | null>(null)
56
+
57
+ async send() {
58
+ this.sending.set(true)
59
+ try {
60
+ // YOUR fetch here; then this.response.set(...)
61
+ } finally {
62
+ this.sending.set(false)
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## Type
69
+
70
+ `feature`
4
71
 
72
+ ## Installation
73
+
74
+ ```bash
75
+ npm install @molecule/app-http-inspector-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
76
+ ```
77
+
78
+ ## API
79
+
80
+ ### Interfaces
81
+
82
+ #### `HttpHeader`
83
+
84
+ A single HTTP request or response header key/value pair.
85
+
86
+ ```typescript
87
+ interface HttpHeader {
88
+ key: string
89
+ value: string
90
+ }
5
91
  ```
6
- npm install @molecule/app-http-inspector-angular
92
+
93
+ #### `HttpResponse`
94
+
95
+ Parsed HTTP response returned after a request completes.
96
+
97
+ ```typescript
98
+ interface HttpResponse {
99
+ statusCode: number
100
+ statusText?: string
101
+ durationMs?: number
102
+ body: string
103
+ headers?: HttpHeader[]
104
+ }
7
105
  ```
8
106
 
9
- Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
107
+ #### `HttpInspectorProps`
108
+
109
+ Inputs accepted by {@link HttpInspector} — the same props `@molecule/app-http-inspector-react` accepts.
110
+
111
+ ```typescript
112
+ interface HttpInspectorProps {
113
+ /** The request's HTTP method. */
114
+ method: HttpMethod
115
+ /** Called with the new method when the user picks one. */
116
+ onMethodChange: (method: HttpMethod) => void
117
+ /** The request URL. */
118
+ url: string
119
+ /** Called with the new URL as the user types. */
120
+ onUrlChange: (url: string) => void
121
+ /** The request headers, in render order. */
122
+ headers: HttpHeader[]
123
+ /** Called with the next header list on any header edit. */
124
+ onHeadersChange: (headers: HttpHeader[]) => void
125
+ /** The request body. */
126
+ body: string
127
+ /** Called with the new body as the user types. */
128
+ onBodyChange: (body: string) => void
129
+ /** Sends the request; the app owns the fetch and the response state. */
130
+ onSend: () => void | Promise<void>
131
+ /** Whether a send is in flight (disables the Send button, shows `Sending…`). */
132
+ sending?: boolean
133
+ /** The last response to show, or `null`/absent for none. */
134
+ response?: HttpResponse | null
135
+ /** Extra classes on the outer wrapper. */
136
+ className?: string
137
+ }
138
+ ```
139
+
140
+ ### Types
141
+
142
+ #### `HttpMethod`
143
+
144
+ HTTP method verb for a request.
145
+
146
+ ```typescript
147
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'
148
+ ```
149
+
150
+ ### Classes
151
+
152
+ #### `HttpInspector`
153
+
154
+ HttpInspector component.
155
+
156
+ Controlled HTTP request builder + response panel. The host IS the outer
157
+ `<div>` React renders (`div[mol-http-inspector]`), with the same classes.
158
+ App owns request state + the actual `fetch`; this component renders the UI:
159
+ method + URL row, headers key/value editor, body textarea (methods that
160
+ allow a body), Send button, then a response panel showing status + timing +
161
+ body.
162
+
163
+ ```typescript
164
+ @Component({
165
+ selector: 'div[mol-http-inspector]',
166
+ standalone: true,
167
+ imports: [Button, Input, Select, Textarea],
168
+ inputs: [
169
+ 'method',
170
+ 'onMethodChange',
171
+ 'url',
172
+ 'onUrlChange',
173
+ 'headers',
174
+ 'onHeadersChange',
175
+ 'body',
176
+ 'onBodyChange',
177
+ 'onSend',
178
+ 'sending',
179
+ 'response',
180
+ 'className',
181
+ ],
182
+ host: {
183
+ '[class]': 'classes()',
184
+ },
185
+ // prettier-ignore
186
+ template: `<div [class]="rowClasses()"
187
+ ><!-- The options are protocol tokens (GET, POST, …): never translated, so the element carries HTML's own translate="no" attribute. --><div
188
+ mol-select
189
+ [id]="'http-inspector-method'"
190
+ [options]="methodOptions"
191
+ [value]="method"
192
+ (valueChange)="handleMethodChange($event)"
193
+ translate="no"
194
+ [attr.aria-label]="methodLabel()"
195
+ ></div
196
+ ><!-- The placeholder is an example URL — input, not prose: never translated. --><div
197
+ mol-input
198
+ [id]="'http-inspector-url'"
199
+ [type]="'text'"
200
+ [value]="url"
201
+ (change)="handleUrlChange($event)"
202
+ placeholder="https://api.example.com/v1/resources"
203
+ translate="no"
204
+ [className]="flexClasses()"
205
+ [attr.aria-label]="urlLabel()"
206
+ ></div
207
+ ><button
208
+ mol-button
209
+ [variant]="'solid'"
210
+ [color]="'primary'"
211
+ (click)="send()"
212
+ [disabled]="!!sending"
213
+ >{{ sending ? sendingText() : sendText() }}</button
214
+ ></div>
215
+ <div [class]="stack1Classes()"><span [class]="labelClasses()">{{ headersLabel() }}</span>
216
+ @for (header of headers; track $index) {
217
+ <div [class]="headerRowClasses()"
218
+ ><div
219
+ mol-input
220
+ [id]="'http-inspector-header-' + $index + '-key'"
221
+ [type]="'text'"
222
+ [value]="header.key"
223
+ (change)="handleHeaderKey($index, $event)"
224
+ [placeholder]="headerPlaceholder()"
225
+ ></div
226
+ ><div
227
+ mol-input
228
+ [id]="'http-inspector-header-' + $index + '-value'"
229
+ [type]="'text'"
230
+ [value]="header.value"
231
+ (change)="handleHeaderValue($index, $event)"
232
+ [placeholder]="valuePlaceholder()"
233
+ [className]="flexClasses()"
234
+ ></div
235
+ ><button mol-button [variant]="'ghost'" [size]="'sm'" (click)="removeHeader($index)">×</button
236
+ ></div>
237
+ }
238
+ <button mol-button [variant]="'ghost'" [size]="'sm'" (click)="addHeader()">+ {{ addHeaderLabel() }}</button>
239
+ </div>
240
+ @if (showBody()) {
241
+ <div [class]="stack1Classes()"><span [class]="labelClasses()">{{ bodyLabel() }}</span><!-- The placeholder is a JSON example — input, not prose: never translated. --><div
242
+ mol-textarea
243
+ [id]="'http-inspector-body'"
244
+ [value]="body"
245
+ (change)="handleBodyChange($event)"
246
+ [rows]="6"
247
+ [placeholder]="bodyPlaceholder"
248
+ translate="no"
249
+ ></div></div>
250
+ }
251
+ @if (response; as resp) {
252
+ <div [class]="stack2Classes()">
253
+ <div [class]="rowClasses()"
254
+ ><span [class]="statusClasses(resp.statusCode)" [style]="statusStyle()">{{ resp.statusCode }} {{ resp.statusText ?? '' }}</span
255
+ >@if (resp.durationMs !== undefined) {<span [class]="textXsClasses()">{{ resp.durationMs }}ms</span>}</div
256
+ ><pre [class]="preClasses()" [style]="preStyle()">@if (resp.body !== '') {<ng-container>{{ resp.body }}</ng-container>}</pre>
257
+ </div>
258
+ }`,
259
+ })
260
+ export class HttpInspector {
261
+ /** The request's HTTP method. */
262
+ method: HttpMethod = 'GET'
263
+ onMethodChange?: (method: HttpMethod) => void
264
+ /** The request URL. */
265
+ url = ''
266
+ onUrlChange?: (url: string) => void
267
+ /** The request headers, in render order. */
268
+ headers: HttpHeader[] = []
269
+ onHeadersChange?: (headers: HttpHeader[]) => void
270
+ /** The request body. */
271
+ body = ''
272
+ onBodyChange?: (body: string) => void
273
+ /** Sends the request (React's `onSend`). */
274
+ onSend?: () => void | Promise<void>
275
+ /** Whether a send is in flight (React's `sending`). */
276
+ sending?: boolean
277
+ /** The last response to show (React's `response`). */
278
+ response?: HttpResponse | null
279
+ className?: string
280
+
281
+ /** The method options, in React's order. */
282
+ readonly methodOptions = METHODS.map((method) => ({ value: method, label: method }))
283
+
284
+ /** The body textarea's placeholder (React's literal). */
285
+ readonly bodyPlaceholder = '{"key": "value"}'
286
+
287
+ /** Reactive translation, read in the injection context. */
288
+ private readonly i18n = useTranslation()
289
+
290
+ /** The current class map. */
291
+ cm(): UIClassMap {
292
+ return getClassMap()
293
+ }
294
+
295
+ classes(): string {
296
+ return this.cm().cn(this.cm().stack(3), this.className)
297
+ }
298
+
299
+ rowClasses(): string {
300
+ return this.cm().flex({ align: 'center', gap: 'sm' })
301
+ }
302
+
303
+ headerRowClasses(): string {
304
+ return this.cm().flex({ align: 'center', gap: 'xs' })
305
+ }
306
+
307
+ stack1Classes(): string {
308
+ return this.cm().stack(1)
309
+ }
310
+
311
+ /** The response section's class (React's `cm.stack(2)`). */
312
+ stack2Classes(): string {
313
+ return this.cm().stack(2)
314
+ }
315
+
316
+ labelClasses(): string {
317
+ return this.cm().cn(this.cm().textSize('xs'), this.cm().fontWeight('semibold'))
318
+ }
319
+
320
+ textXsClasses(): string {
321
+ return this.cm().textSize('xs')
322
+ }
323
+
324
+ preClasses(): string {
325
+ return this.cm().cn(this.cm().sp('p', 3), this.cm().textSize('xs'))
326
+ }
327
+
328
+ /** The URL input's extra class (React's `cm.flex1`). */
329
+ flexClasses(): string {
330
+ return this.cm().flex1
331
+ }
332
+
333
+ statusClasses(code: number): string {
334
+ return this.cm().cn(this.cm().bgTone(statusTone(code)), this.cm().textOnTone)
335
+ }
336
+
337
+ statusStyle(): Record<string, string> {
338
+ return {
339
+ padding: '2px 8px',
340
+ 'border-radius': '4px',
341
+ 'font-weight': '700',
342
+ }
343
+ }
344
+
345
+ preStyle(): Record<string, string> {
346
+ return { 'overflow-x': 'auto' }
347
+ }
348
+
349
+ showBody(): boolean {
350
+ return this.method !== 'GET' && this.method !== 'HEAD'
351
+ }
352
+
353
+ sendingText(): string {
354
+ return this.i18n.t('httpInspector.sending', {}, { defaultValue: 'Sending…' })
355
+ }
356
+
357
+ sendText(): string {
358
+ return this.i18n.t('httpInspector.send', {}, { defaultValue: 'Send' })
359
+ }
360
+
361
+ headersLabel(): string {
362
+ return this.i18n.t('httpInspector.headers', {}, { defaultValue: 'Headers' })
363
+ }
364
+
365
+ bodyLabel(): string {
366
+ return this.i18n.t('httpInspector.body', {}, { defaultValue: 'Body' })
367
+ }
368
+
369
+ addHeaderLabel(): string {
370
+ return this.i18n.t('httpInspector.addHeader', {}, { defaultValue: 'Add header' })
371
+ }
372
+
373
+ methodLabel(): string {
374
+ return this.i18n.t('httpInspector.methodLabel', {}, { defaultValue: 'HTTP method' })
375
+ }
376
+
377
+ urlLabel(): string {
378
+ return this.i18n.t('httpInspector.urlLabel', {}, { defaultValue: 'URL' })
379
+ }
380
+
381
+ headerPlaceholder(): string {
382
+ return this.i18n.t('httpInspector.headerPlaceholder', {}, { defaultValue: 'Header' })
383
+ }
384
+
385
+ valuePlaceholder(): string {
386
+ return this.i18n.t('httpInspector.valuePlaceholder', {}, { defaultValue: 'Value' })
387
+ }
388
+
389
+ /** Reports a picked method (React's `onMethodChange`). */
390
+ handleMethodChange(method: string): void {
391
+ this.onMethodChange?.(method as HttpMethod)
392
+ }
393
+
394
+ /** Adopts the typed URL (React's `onUrlChange`). */
395
+ handleUrlChange(event: Event): void {
396
+ this.onUrlChange?.((event.target as HTMLInputElement).value)
397
+ }
398
+
399
+ handleHeaderKey(i: number, event: Event): void {
400
+ const next = [...this.headers]
401
+ next[i] = { key: (event.target as HTMLInputElement).value, value: next[i].value }
402
+ this.onHeadersChange?.(next)
403
+ }
404
+
405
+ handleHeaderValue(i: number, event: Event): void {
406
+ const next = [...this.headers]
407
+ next[i] = { key: next[i].key, value: (event.target as HTMLInputElement).value }
408
+ this.onHeadersChange?.(next)
409
+ }
410
+
411
+ removeHeader(i: number): void {
412
+ this.onHeadersChange?.(this.headers.filter((_, j) => j !== i))
413
+ }
414
+
415
+ addHeader(): void {
416
+ this.onHeadersChange?.([...this.headers, { key: '', value: '' }])
417
+ }
418
+
419
+ /** Adopts the typed body (React's `onBodyChange`). */
420
+ handleBodyChange(event: Event): void {
421
+ this.onBodyChange?.((event.target as HTMLTextAreaElement).value)
422
+ }
423
+
424
+ send(): void {
425
+ void this.onSend?.()
426
+ }
427
+ }
428
+ ```
429
+
430
+ _(Member comments are shortened to their first sentence, and the 30 longest are left out to fit; the full declaration is in `node_modules/@molecule/app-http-inspector-angular/dist/http-inspector.component.d.ts`.)_
431
+
432
+ ## Injection Notes
433
+
434
+ ### Requirements
435
+
436
+ Peer dependencies:
437
+
438
+ - `@angular/common` ^22.0.0
439
+ - `@angular/core` ^22.0.0
440
+ - `@angular/platform-browser` ^22.0.0
441
+ - `@molecule/app-angular` ^3.5.0
442
+ - `@molecule/app-ui` ^1.4.0
443
+ - `@molecule/app-ui-angular` ^1.1.0
444
+
445
+ ### Runtime Dependencies
446
+
447
+ - `@angular/common`
448
+ - `@angular/core`
449
+ - `@angular/platform-browser`
450
+ - `@molecule/app-angular`
451
+ - `@molecule/app-ui`
452
+ - `@molecule/app-ui-angular`
453
+
454
+ - Fully controlled and transport-agnostic: the component renders the
455
+ builder UI only — YOUR `onSend` performs the fetch and sets `response`
456
+ (`HttpResponse` with statusCode/durationMs/body). `sending` disables the
457
+ Send button.
458
+ - Requires the Angular binding's i18n provider (`useTranslation()` THROWS
459
+ without it) and a bonded ClassMap; button/tab labels come from the
460
+ `@molecule/app-locales-http-inspector` companion bond.
461
+ - The body editor renders only for methods with bodies (hidden for GET and
462
+ HEAD).
463
+ - The response status chip uses fixed severity colors (green/blue/
464
+ yellow/red) rendered inline — they do not follow the app theme.
465
+
466
+ ## Translations
10
467
 
11
- License: Apache-2.0
468
+ Translation strings are provided by `@molecule/app-locales-http-inspector`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-http-inspector-angular",
3
- "version": "0.0.1-stage",
3
+ "version": "1.1.0",
4
4
  "description": "HTTP method + URL builder + headers/params/body tabs + response status/timing display",
5
5
  "homepage": "https://www.molecule.dev/packages/app-http-inspector-angular",
6
6
  "type": "module",
@@ -55,12 +55,12 @@
55
55
  "@angular/compiler-cli": "22.2.3",
56
56
  "@angular/core": "22.2.3",
57
57
  "@angular/platform-browser": "22.2.3",
58
- "@molecule/app-angular": "3.7.2",
58
+ "@molecule/app-angular": "3.9.0",
59
59
  "@molecule/app-framework-conformance": "0.0.0",
60
60
  "@molecule/app-i18n": "1.2.2",
61
61
  "@molecule/app-icons": "1.0.4",
62
- "@molecule/app-ui": "1.4.0",
63
- "@molecule/app-ui-angular": "1.2.1",
62
+ "@molecule/app-ui": "1.5.0",
63
+ "@molecule/app-ui-angular": "1.3.1",
64
64
  "@types/node": "26.6.5",
65
65
  "jsdom": "30.1.3",
66
66
  "rxjs": "7.8.2",