@t4h.framework/http 0.3.1 → 0.4.1
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.
- package/.ai/skills/framework-http/SKILL.md +73 -138
- package/CHANGELOG.md +52 -0
- package/LICENSE +21 -0
- package/dist/activities/AbstractHttpRequestActivity.d.ts.map +1 -1
- package/dist/activities/AbstractHttpRequestActivity.js +3 -2
- package/dist/activities/AbstractHttpRequestActivity.js.map +1 -1
- package/dist/models/OAuth2.d.ts +2 -0
- package/dist/models/OAuth2.d.ts.map +1 -1
- package/dist/models/OAuth2.js +29 -21
- package/dist/models/OAuth2.js.map +1 -1
- package/dist/tools/with-default-user-agent.d.ts +3 -0
- package/dist/tools/with-default-user-agent.d.ts.map +1 -0
- package/dist/tools/with-default-user-agent.js +8 -0
- package/dist/tools/with-default-user-agent.js.map +1 -0
- package/package.json +7 -7
- package/dist/testing/index.d.ts +0 -3
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/index.js +0 -15
- package/dist/testing/index.js.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: framework-http
|
|
3
3
|
description: >-
|
|
4
|
-
Guides correct use of @t4h.framework/http in T4H Framework workflows:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
activities, OAuth2/Basic auth, or working in packages/http.
|
|
4
|
+
Guides correct use of @t4h.framework/http in T4H Framework workflows: the
|
|
5
|
+
`http` / `HttpClient` client, claims (HttpClientRequestClaim, FileSystemClaim,
|
|
6
|
+
CacheClaim for OAuth), request/response bodies, and auth. Use when making or
|
|
7
|
+
testing HTTP calls in workflows, wiring HTTP claim providers, OAuth2/Basic
|
|
8
|
+
auth, or working in packages/http.
|
|
10
9
|
---
|
|
11
10
|
|
|
12
11
|
# @t4h.framework/http
|
|
@@ -19,8 +18,6 @@ Import surface (from `src/http.ts` only — do not reference unexported modules
|
|
|
19
18
|
import {
|
|
20
19
|
http,
|
|
21
20
|
HttpClient,
|
|
22
|
-
HttpRequestActivity,
|
|
23
|
-
AbstractHttpRequestActivity,
|
|
24
21
|
HttpClientRequestClaim,
|
|
25
22
|
HttpAuth,
|
|
26
23
|
OAuth2,
|
|
@@ -28,13 +25,15 @@ import {
|
|
|
28
25
|
OAuth2GrantResourceOwnerPassword,
|
|
29
26
|
Body,
|
|
30
27
|
Response,
|
|
31
|
-
type HttpRequestActivityInput,
|
|
32
|
-
type HttpRequestActivityOutput,
|
|
33
28
|
type HttpClientRequestClaimInput,
|
|
34
29
|
type HttpClientRequestClaimOutput,
|
|
35
30
|
} from '@t4h.framework/http'
|
|
36
31
|
```
|
|
37
32
|
|
|
33
|
+
> Workflows use the **`http` / `HttpClient`** client. The package also exports
|
|
34
|
+
> the underlying `HttpRequestActivity` / `AbstractHttpRequestActivity`, but
|
|
35
|
+
> workflow code never imports, instantiates, or extends them.
|
|
36
|
+
|
|
38
37
|
## Architecture
|
|
39
38
|
|
|
40
39
|
`Workflow` → `http`/`HttpClient` (`History.bind(HttpRequestActivity)`) → `AbstractHttpRequestActivity.run` → `HttpClientRequestClaim.request` + `FileSystemClaim.write` (response → `Body`/`Response`).
|
|
@@ -78,11 +77,11 @@ abstract class HttpClientRequestClaim {
|
|
|
78
77
|
}
|
|
79
78
|
```
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
The runtime provides a concrete implementation; workflow tests mock it (see **Testing** below).
|
|
82
81
|
|
|
83
|
-
### FileSystemClaim (required by
|
|
82
|
+
### FileSystemClaim (required by the HTTP activity)
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
The HTTP activity persists the response body to `fs` (path `\`${uuid}-http-request-activity-response-body.${ext}\``, extension from `content-type` via `mime`, or `.bin`) and returns it wrapped in a `Body`. So any workflow that makes an HTTP call also needs a `FileSystemClaim` provider; tests mock its `write` to return a `Binary`.
|
|
86
85
|
|
|
87
86
|
### CacheClaim (OAuth only)
|
|
88
87
|
|
|
@@ -100,7 +99,7 @@ Shared by activities and `HttpClient` config (minus `url` / `baseUrl` on client
|
|
|
100
99
|
| `baseUrl` | `string?` | Optional base for relative paths |
|
|
101
100
|
| `method` | `HttpMethod?` | `'GET'` |
|
|
102
101
|
| `body` | `{ json }` \| `{ text }` \| `{ form }` | See below |
|
|
103
|
-
| `headers` | `Record<...>?` | Merged with body-derived headers; `auth` sets `Authorization` and overrides a custom `Authorization` header |
|
|
102
|
+
| `headers` | `Record<...>?` | Merged with body-derived headers; `auth` sets `Authorization` and overrides a custom `Authorization` header. A default `User-Agent` is added when none is given (any casing) |
|
|
104
103
|
| `auth` | `HttpAuth` \| `{ username, password }` | Basic auth object or subclass with `getAuthorizationHeader()` |
|
|
105
104
|
| `retry` | `boolean` \| retry options | `true` |
|
|
106
105
|
| `redirect` | `'follow' \| 'manual' \| number` | `'follow'` |
|
|
@@ -117,74 +116,21 @@ Invalid body shape throws `Invalid body`.
|
|
|
117
116
|
|
|
118
117
|
---
|
|
119
118
|
|
|
120
|
-
##
|
|
119
|
+
## Making HTTP calls in a workflow
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
Always use the ready **`http` / `HttpClient`** helper — it is what the package
|
|
122
|
+
exports for workflows and it drives the underlying HTTP activity through the
|
|
123
|
+
reconciler for you (replay-safe). Never define, extend, or hand-instantiate an
|
|
124
|
+
activity in workflow code.
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
For a typed result, read the response and map with plain TypeScript:
|
|
125
127
|
|
|
126
128
|
```typescript
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// Inside Claim.run or reconciler context:
|
|
130
|
-
const activity = new HttpRequestActivity()
|
|
131
|
-
const output = await activity.run({
|
|
132
|
-
url: 'https://api.example.com/data',
|
|
133
|
-
method: 'GET',
|
|
134
|
-
})
|
|
135
|
-
// Serializable output is HttpRequestActivityOutput; toOutput wraps Response
|
|
129
|
+
const res = await http.get(`${environments.SERVICE_URL}/data`)
|
|
130
|
+
const data = await res.body.json<MyType>()
|
|
136
131
|
```
|
|
137
132
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
### AbstractHttpRequestActivity (custom activities)
|
|
141
|
-
|
|
142
|
-
Extend with **four** type parameters: `TArgs`, `TInput`, `TSerializableOutput`, `TOutput`.
|
|
143
|
-
|
|
144
|
-
Implement:
|
|
145
|
-
|
|
146
|
-
- `toInput(...args)` — map workflow args → activity input
|
|
147
|
-
- `toOutput(serializable, ...args)` — map serializable result → workflow return type
|
|
148
|
-
- `protected toHttpInput(input)` — map to `HttpRequestActivityInput`
|
|
149
|
-
- `protected toHttpOutput(output)` — map `HttpRequestActivityOutput` → serializable stored in history
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
import {
|
|
153
|
-
AbstractHttpRequestActivity,
|
|
154
|
-
type HttpRequestActivityInput,
|
|
155
|
-
type HttpRequestActivityOutput,
|
|
156
|
-
} from '@t4h.framework/http'
|
|
157
|
-
import type { Serializable } from '@t4h.framework/core'
|
|
158
|
-
|
|
159
|
-
class FetchStatusActivity extends AbstractHttpRequestActivity<
|
|
160
|
-
[endpoint: string],
|
|
161
|
-
{ endpoint: string },
|
|
162
|
-
{ status: number },
|
|
163
|
-
{ status: number }
|
|
164
|
-
> {
|
|
165
|
-
public async toInput(endpoint: string) {
|
|
166
|
-
return { endpoint }
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
protected async toHttpInput(input: { endpoint: string }): Promise<HttpRequestActivityInput> {
|
|
170
|
-
return { url: input.endpoint, method: 'GET' }
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
protected async toHttpOutput(output: HttpRequestActivityOutput): Promise<{ status: number }> {
|
|
174
|
-
return { status: output.status }
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public toOutput(output: { status: number }) {
|
|
178
|
-
return output
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
Static helpers (for tests or advanced form building):
|
|
184
|
-
|
|
185
|
-
- `AbstractHttpRequestActivity.getContent(body)`
|
|
186
|
-
- `AbstractHttpRequestActivity.append(form, input, currentKey?)`
|
|
187
|
-
- `AbstractHttpRequestActivity.getFormData(input)`
|
|
133
|
+
See **HttpClient and `http`** and **Response and Body** below.
|
|
188
134
|
|
|
189
135
|
---
|
|
190
136
|
|
|
@@ -217,7 +163,7 @@ const client = new HttpClient({
|
|
|
217
163
|
|
|
218
164
|
Methods: `request(url, config?)`, `get`, `post(url, body, config?)`, `put`, `patch`, `delete`. Per-request `auth` in config merges over client `config.auth`.
|
|
219
165
|
|
|
220
|
-
Workflow example
|
|
166
|
+
Workflow example:
|
|
221
167
|
|
|
222
168
|
```typescript
|
|
223
169
|
import { Workflow } from '@t4h.framework/core'
|
|
@@ -254,6 +200,13 @@ await response.body.stream()
|
|
|
254
200
|
|
|
255
201
|
`body.json()` throws `Invalid content type` for non-JSON types (e.g. `text/plain`, `text/html`).
|
|
256
202
|
|
|
203
|
+
`Body` extends `SerializableClass` (`packages/http/src/models/Body.ts`) and is
|
|
204
|
+
persisted through `FileSystemClaim`, so the `Response`/`Body` returned by the
|
|
205
|
+
`http` client **is replay-safe** — it is serialized between reconciler steps and
|
|
206
|
+
rebuilt on replay. You do **not** need a custom activity to "flatten" the body
|
|
207
|
+
into history; read it with `await res.body.json<T>()` in the workflow and
|
|
208
|
+
transform with plain TypeScript.
|
|
209
|
+
|
|
257
210
|
Serializable shape: `{ binary: ... }` via `toSerializable` / `fromSerializable`.
|
|
258
211
|
|
|
259
212
|
---
|
|
@@ -302,101 +255,83 @@ const auth = new OAuth2GrantResourceOwnerPassword({
|
|
|
302
255
|
|
|
303
256
|
OAuth2 flow: POST `application/x-www-form-urlencoded` to `tokenUrl` via `HttpClientRequestClaim`; cache token; refresh with `grant_type=refresh_token` when expired if `refresh_token` present; header format `${token_type} ${access_token}`.
|
|
304
257
|
|
|
258
|
+
The token request throws when the response is non-2xx, is not valid JSON, or lacks `access_token`/`token_type`, so a broken token endpoint surfaces at the token step instead of producing an `undefined undefined` `Authorization` header on the next call.
|
|
259
|
+
|
|
305
260
|
Requires `CacheClaim` + `HttpClientRequestClaim` in the runtime.
|
|
306
261
|
|
|
307
262
|
---
|
|
308
263
|
|
|
309
264
|
## Testing
|
|
310
265
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
266
|
+
Test the **workflow** with `TestWorkflowEnvironment` from
|
|
267
|
+
`@t4h.framework/core/testing`, mocking the two claims the HTTP activity uses:
|
|
268
|
+
`HttpClientRequestClaim` (the network request) and `FileSystemClaim` (where the
|
|
269
|
+
activity persists the response body). See the **framework-workflow-testing** skill
|
|
270
|
+
for the full harness API.
|
|
316
271
|
|
|
317
272
|
```typescript
|
|
318
|
-
import { Claim } from '@t4h.framework/core'
|
|
319
|
-
import { FileSystemClaim } from '@t4h.framework/fs'
|
|
320
273
|
import { Readable } from 'node:stream'
|
|
274
|
+
import { Binary } from '@t4h.framework/core'
|
|
275
|
+
import { TestWorkflowEnvironment, mockClaim } from '@t4h.framework/core/testing'
|
|
321
276
|
import { HttpClientRequestClaim } from '@t4h.framework/http'
|
|
277
|
+
import { FileSystemClaim } from '@t4h.framework/fs'
|
|
322
278
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
})
|
|
328
|
-
|
|
329
|
-
const mockWrite = vi.fn().mockImplementation(async (_path, readable) => {
|
|
330
|
-
const chunks = await readable.toArray()
|
|
331
|
-
return new MockBinary(Buffer.concat(chunks), 'application/json')
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
const result = await Claim.run(
|
|
335
|
-
[
|
|
336
|
-
{ provide: HttpClientRequestClaim, value: { request: mockRequest } },
|
|
337
|
-
{ provide: FileSystemClaim, value: { write: mockWrite, read: vi.fn() } },
|
|
338
|
-
],
|
|
339
|
-
() => new MyActivity().run(input),
|
|
340
|
-
)
|
|
341
|
-
|
|
342
|
-
await expect(result.body.json()).resolves.toEqual({ ok: true })
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
Assert `mockRequest` received `url`, `method`, merged headers, and JSON buffer for `{ json: ... }` bodies.
|
|
346
|
-
|
|
347
|
-
### 2. Assert HttpClient schedules HttpRequestActivity
|
|
279
|
+
// Minimal Binary the FileSystemClaim mock returns from write().
|
|
280
|
+
class MockBinary extends Binary {
|
|
281
|
+
public readonly contentType = 'application/json'
|
|
282
|
+
public readonly contentLength: number
|
|
348
283
|
|
|
349
|
-
|
|
284
|
+
constructor(private readonly data: Buffer) {
|
|
285
|
+
super()
|
|
286
|
+
this.contentLength = data.byteLength
|
|
287
|
+
}
|
|
350
288
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
import { HttpRequestActivity } from '@t4h.framework/http'
|
|
354
|
-
|
|
355
|
-
async function captureTrigger(fn: () => unknown) {
|
|
356
|
-
try {
|
|
357
|
-
await History.run([], fn)
|
|
358
|
-
} catch (error) {
|
|
359
|
-
if (error instanceof PushActivity) return error
|
|
360
|
-
throw error
|
|
289
|
+
public stream() {
|
|
290
|
+
return Readable.from(this.data)
|
|
361
291
|
}
|
|
362
292
|
}
|
|
363
293
|
|
|
364
|
-
const
|
|
365
|
-
expect(trigger.activity.constructor).toBe(HttpRequestActivity)
|
|
366
|
-
expect(trigger.input).toMatchObject({ method: 'POST', body: { json: { name: 'Tony' } } })
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### 3. Integration-test workflows with mocked claims
|
|
294
|
+
const body = Buffer.from(JSON.stringify({ ok: true }))
|
|
370
295
|
|
|
371
|
-
|
|
296
|
+
// mockImplementation (not mockResolvedValue): replay runs the workflow twice, so
|
|
297
|
+
// each call must hand back a fresh, unconsumed stream.
|
|
298
|
+
const mockRequest = vi.fn().mockImplementation(async () => ({
|
|
299
|
+
status: 200,
|
|
300
|
+
headers: { 'content-type': 'application/json' },
|
|
301
|
+
body: Readable.from(body),
|
|
302
|
+
}))
|
|
372
303
|
|
|
373
|
-
|
|
374
|
-
import { WorkflowTesting } from '@t4h.framework/core/testing'
|
|
375
|
-
import { HttpClientRequestClaim, type HttpClientRequestClaimInput } from '@t4h.framework/http'
|
|
304
|
+
const mockWrite = vi.fn().mockImplementation(async () => new MockBinary(body))
|
|
376
305
|
|
|
377
|
-
const
|
|
306
|
+
const env = TestWorkflowEnvironment.create({ now: 0 })
|
|
378
307
|
|
|
379
|
-
await
|
|
308
|
+
const output = await env.execute(workflow, input, {
|
|
380
309
|
claims: [
|
|
381
|
-
|
|
382
|
-
{
|
|
310
|
+
mockClaim(HttpClientRequestClaim, { request: mockRequest }),
|
|
311
|
+
mockClaim(FileSystemClaim, { write: mockWrite, read: vi.fn() }),
|
|
383
312
|
],
|
|
313
|
+
env: { SERVICE_URL: 'https://api.example.com' },
|
|
384
314
|
})
|
|
315
|
+
|
|
316
|
+
// request input carries a URL object
|
|
317
|
+
expect(mockRequest.mock.calls[0][0].url).toEqual(
|
|
318
|
+
new URL('https://api.example.com/data'),
|
|
319
|
+
)
|
|
385
320
|
```
|
|
386
321
|
|
|
387
|
-
Inspect `mockRequest.mock.calls` for URLs, methods, and bodies.
|
|
322
|
+
Inspect `mockRequest.mock.calls` for URLs, methods, and bodies.
|
|
388
323
|
|
|
389
324
|
---
|
|
390
325
|
|
|
391
326
|
## Checklist for agents
|
|
392
327
|
|
|
393
|
-
1.
|
|
328
|
+
1. In workflows, **always** use **`http` / `HttpClient`** — never define or extend an activity. Get typed, replay-safe results with `await res.body.json<T>()` plus plain TypeScript.
|
|
394
329
|
2. Never call `fetch` directly in workflow code if the step must be replayable — use the package APIs.
|
|
395
330
|
3. Ensure runtime provides **`HttpClientRequestClaim`** and **`FileSystemClaim`** (or pass mocks in tests).
|
|
396
331
|
4. Use **`{ json: ... }`**, **`{ text: ... }`**, or **`{ form: ... }`** for bodies — not raw `Buffer` on activity input.
|
|
397
332
|
5. Read responses with **`await response.body.json()`** or **`text()`**; check `status` explicitly (no automatic throw on 4xx/5xx).
|
|
398
333
|
6. For OAuth, wire **`CacheClaim`** and use exported grant classes only.
|
|
399
|
-
7.
|
|
334
|
+
7. Test workflows with **`TestWorkflowEnvironment`** + **`mockClaim`**, mocking **`HttpClientRequestClaim`** and **`FileSystemClaim`**; assert on `mockRequest.mock.calls`.
|
|
400
335
|
8. Do not document or import APIs not exported from `@t4h.framework/http`.
|
|
401
336
|
|
|
402
|
-
See also: `packages/http/README.md
|
|
337
|
+
See also: `packages/http/README.md`; **framework-workflow-testing** for the test harness.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @t4h.framework/http
|
|
2
|
+
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#130](https://github.com/tech4humans-brasil/framework/pull/130) [`587b9a2`](https://github.com/tech4humans-brasil/framework/commit/587b9a2a847810f72e82f33a77c0ec2d3767dd2e) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Adds default user-agent header on http requests
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Update skills ([`6d7e7bc`](https://github.com/tech4humans-brasil/framework/commit/6d7e7bca0c780a9c53a0c9e5aa0a865c5af67959))
|
|
14
|
+
|
|
15
|
+
## 0.3.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Import serializable class from correct package ([#101](https://github.com/tech4humans-brasil/framework/pull/101))
|
|
20
|
+
|
|
21
|
+
## 0.3.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- Adds fs package ([`538c9bd`](https://github.com/tech4humans-brasil/framework/commit/538c9bd5c49031ceb94ef8d6c513f6ffc9c848c5))
|
|
26
|
+
- Adds http auth ([`dd58d6e`](https://github.com/tech4humans-brasil/framework/commit/dd58d6e10b9440379f478ed3e961d150e205a2eb))
|
|
27
|
+
- Adds support to serializable class ([`ed0ddbb`](https://github.com/tech4humans-brasil/framework/commit/ed0ddbb7c07e2d1d8810e3079c9aa6dd10f4479f))
|
|
28
|
+
- Adds async support for serialization ([#10](https://github.com/tech4humans-brasil/framework/pull/10))
|
|
29
|
+
- Introduce async activity advance and bootstrap ([#19](https://github.com/tech4humans-brasil/framework/pull/19))
|
|
30
|
+
- Adds support to retry and redirect ([`5c97588`](https://github.com/tech4humans-brasil/framework/commit/5c97588262d5f9817ad876d9c682e402c3f6cd94))
|
|
31
|
+
- Adds .ai/skills in packages ([#88](https://github.com/tech4humans-brasil/framework/pull/88))
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Http package ([`a84844f`](https://github.com/tech4humans-brasil/framework/commit/a84844fbdf6de443f7de748c5632710662faff7f))
|
|
36
|
+
- Remove activity claim context dependency ([`c7c1ac1`](https://github.com/tech4humans-brasil/framework/commit/c7c1ac1fbe4d3eb0d87a7909408c75ebd26b139f))
|
|
37
|
+
- Await multipart form build and include http headers ([#12](https://github.com/tech4humans-brasil/framework/pull/12))
|
|
38
|
+
- Rename activity claim to claim ([`281d700`](https://github.com/tech4humans-brasil/framework/commit/281d7008bd5539ab0b701e755f053d031b332aa8))
|
|
39
|
+
- Rename activity history to history ([`4eaad08`](https://github.com/tech4humans-brasil/framework/commit/4eaad08468815bcdea14c36468c7904655715406))
|
|
40
|
+
- Remove activity prefix from file system claim class name ([`d257bd1`](https://github.com/tech4humans-brasil/framework/commit/d257bd177d477a56a897ba862a0be1f50531c633))
|
|
41
|
+
- Remove activity prefix from http client request claim class name ([`5d37e31`](https://github.com/tech4humans-brasil/framework/commit/5d37e315bafecf949e4c69651c22a4ba4232fe16))
|
|
42
|
+
- Remove activity prefix from cache claim class name ([`4fa4ec9`](https://github.com/tech4humans-brasil/framework/commit/4fa4ec9e319fffeae0b5c96e0ec0e9cfa4e22c22))
|
|
43
|
+
- Fix all tests ([`0270832`](https://github.com/tech4humans-brasil/framework/commit/02708320bd39ffef87f6b46c2e57a1ccccb4ceb0))
|
|
44
|
+
- Fix eslint warnings and errors ([`9a7eeb5`](https://github.com/tech4humans-brasil/framework/commit/9a7eeb52d81a5e99c44819e8271db7f35b6c5195))
|
|
45
|
+
- Adds github workflow to run, build, tests and lint ([#18](https://github.com/tech4humans-brasil/framework/pull/18))
|
|
46
|
+
- Adds readme ([`630c818`](https://github.com/tech4humans-brasil/framework/commit/630c8188df2623019348aa1674315ac0ddcb467f))
|
|
47
|
+
- Update package metadata and author information across multiple packages ([`2ca73df`](https://github.com/tech4humans-brasil/framework/commit/2ca73df42dc63c86ed44717b50d5402fca45b4e7))
|
|
48
|
+
- Improve repository info ([`1fad92d`](https://github.com/tech4humans-brasil/framework/commit/1fad92d959b804189fd1486d047115995ac81eb0))
|
|
49
|
+
- Check types ([`a975a38`](https://github.com/tech4humans-brasil/framework/commit/a975a38a09b81c35205e55170efbed12b54f683a))
|
|
50
|
+
- Up repo coverage ([`24c057c`](https://github.com/tech4humans-brasil/framework/commit/24c057c470d0829ea9a1e1f71011b6eff408180c))
|
|
51
|
+
- Fix check types and lint errors ([`00ca0df`](https://github.com/tech4humans-brasil/framework/commit/00ca0dfe6c2fddbc4e0dbeefb1556d172c752c55))
|
|
52
|
+
- Update package dependencies across multiple packages ([`8b4fc1d`](https://github.com/tech4humans-brasil/framework/commit/8b4fc1d0e92d6bd880ddf4c8119fb68c49c53760))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tech for humans
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractHttpRequestActivity.d.ts","sourceRoot":"","sources":["../../src/activities/AbstractHttpRequestActivity.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,MAAM,EACN,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAK5B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"AbstractHttpRequestActivity.d.ts","sourceRoot":"","sources":["../../src/activities/AbstractHttpRequestActivity.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,MAAM,EACN,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAA;AAK5B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAIhD,MAAM,MAAM,UAAU,GAClB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,QAAQ,GACR,SAAS,G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M,EAAE,GAAG,SAAS,CAAC,CAAA;IACtD,IAAI,EAAE,IAAI,CAAA;CACX,CAAA;AAED,QAAA,MAAM,UAAU,eAAyC,CAAA;AAEzD,8BAAsB,2BAA2B,CAC/C,KAAK,SAAS,SAAS,GAAG,EAAE,EAC5B,MAAM,SAAS,YAAY,EAC3B,mBAAmB,SAAS,YAAY,GAAG,IAAI,EAC/C,OAAO,CACP,SAAQ,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,CAAC;IACjE,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,CAG3B;IAEF,SAAS,CAAC,QAAQ,CAAC,WAAW,CAC5B,KAAK,EAAE,MAAM,GACZ,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAE/D,SAAS,CAAC,QAAQ,CAAC,YAAY,CAC7B,MAAM,EAAE,yBAAyB,GAChC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;WAEjC,MAAM,CACxB,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,oCAAoC,EAC3C,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;qBA0BG,WAAW,CAChC,KAAK,EAAE,oCAAoC,GAC1C,OAAO,CAAC,QAAQ,CAAC;qBAMG,UAAU,CAAC,IAAI,EAAE,wBAAwB,CAAC,MAAM,CAAC;;;;;;;;;;;;;IAyC3D,GAAG,CAAC,KAAK,EAAE,MAAM;CA0C/B"}
|
|
@@ -6,6 +6,7 @@ import { uuidv7 } from 'uuidv7';
|
|
|
6
6
|
import { Body } from '../models/Body.js';
|
|
7
7
|
import { HttpAuth } from '../models/HttpAuth.js';
|
|
8
8
|
import { HttpClientRequestClaim } from '../models/HttpClientRequestClaim.js';
|
|
9
|
+
import { withDefaultUserAgent } from '../tools/with-default-user-agent.js';
|
|
9
10
|
const CLAIMS_KEY = Symbol('http-request-activity-claims');
|
|
10
11
|
export class AbstractHttpRequestActivity extends SyncActivity {
|
|
11
12
|
[CLAIMS_KEY] = new Claim({
|
|
@@ -82,11 +83,11 @@ export class AbstractHttpRequestActivity extends SyncActivity {
|
|
|
82
83
|
body: content?.body,
|
|
83
84
|
redirect: httpInput.redirect ?? 'follow',
|
|
84
85
|
retry: httpInput.retry ?? true,
|
|
85
|
-
headers: {
|
|
86
|
+
headers: withDefaultUserAgent({
|
|
86
87
|
...httpInput.headers,
|
|
87
88
|
...content.headers,
|
|
88
89
|
...headers,
|
|
89
|
-
},
|
|
90
|
+
}),
|
|
90
91
|
});
|
|
91
92
|
const contentType = response.headers['content-type'];
|
|
92
93
|
const ext = typeof contentType === 'string' ? mime.getExtension(contentType) : 'bin';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractHttpRequestActivity.js","sourceRoot":"","sources":["../../src/activities/AbstractHttpRequestActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,OAAO,EACL,YAAY,EACZ,MAAM,EAEN,KAAK,GACN,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAA;
|
|
1
|
+
{"version":3,"file":"AbstractHttpRequestActivity.js","sourceRoot":"","sources":["../../src/activities/AbstractHttpRequestActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,OAAO,EACL,YAAY,EACZ,MAAM,EAEN,KAAK,GACN,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,mBA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A;QAEF,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAEpD,MAAM,GAAG,GACP,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAE1E,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,CAC5C,GAAG,MAAM,EAAE,wCAAwC,GAAG,EAAE,EACxD,QAAQ,CAAC,IAAI,CACd,CAAA;QAED,OAAO,IAAI,CAAC,YAAY,CAAC;YACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC;SACvB,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/models/OAuth2.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare abstract class OAuth2<TConfig extends OAuth2Config> extends HttpA
|
|
|
23
23
|
protected fromSerializable(serializable: PromiseLikeType<TConfig>): void;
|
|
24
24
|
constructor(config: TConfig);
|
|
25
25
|
protected abstract toTokenBody(): Record<string, string>;
|
|
26
|
+
private toTokenError;
|
|
27
|
+
private requestToken;
|
|
26
28
|
protected toToken(): Promise<OAuth2Token>;
|
|
27
29
|
protected refresh(refreshToken: string): Promise<{
|
|
28
30
|
expiresAt: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OAuth2.d.ts","sourceRoot":"","sources":["../../src/models/OAuth2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,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CAAC,WAAW,CAAC;IAcnC,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;CAKvD"}
|
package/dist/models/OAuth2.js
CHANGED
|
@@ -2,6 +2,8 @@ import { CacheClaim } from '@t4h.framework/cache';
|
|
|
2
2
|
import { Claim } from '@t4h.framework/core';
|
|
3
3
|
import { HttpAuth } from './HttpAuth.js';
|
|
4
4
|
import { HttpClientRequestClaim } from './HttpClientRequestClaim.js';
|
|
5
|
+
import { withDefaultUserAgent } from '../tools/with-default-user-agent.js';
|
|
6
|
+
const TOKEN_ERROR_BODY_LIMIT = 512;
|
|
5
7
|
export class OAuth2 extends HttpAuth {
|
|
6
8
|
config;
|
|
7
9
|
claims = new Claim({
|
|
@@ -24,39 +26,45 @@ export class OAuth2 extends HttpAuth {
|
|
|
24
26
|
super();
|
|
25
27
|
this.config = config;
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
toTokenError(reason, body, options) {
|
|
30
|
+
return new Error(`OAuth2 token request to ${this.config.tokenUrl} ${reason}: ${body.slice(0, TOKEN_ERROR_BODY_LIMIT)}`, options);
|
|
31
|
+
}
|
|
32
|
+
async requestToken(body) {
|
|
28
33
|
const response = await this.claims.http.request({
|
|
29
34
|
url: new URL(this.config.tokenUrl),
|
|
30
35
|
method: 'POST',
|
|
31
|
-
body: new URLSearchParams(
|
|
36
|
+
body: new URLSearchParams(body),
|
|
32
37
|
redirect: 'follow',
|
|
33
38
|
retry: true,
|
|
34
|
-
headers: {
|
|
39
|
+
headers: withDefaultUserAgent({
|
|
35
40
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
36
|
-
},
|
|
41
|
+
}),
|
|
37
42
|
});
|
|
38
43
|
const chunks = await response.body.toArray();
|
|
39
|
-
const
|
|
40
|
-
|
|
44
|
+
const text = Buffer.concat(chunks).toString('utf-8');
|
|
45
|
+
if (response.status < 200 || response.status >= 300)
|
|
46
|
+
throw this.toTokenError(`failed with status ${response.status}`, text);
|
|
47
|
+
let token;
|
|
48
|
+
try {
|
|
49
|
+
token = JSON.parse(text);
|
|
50
|
+
}
|
|
51
|
+
catch (cause) {
|
|
52
|
+
throw this.toTokenError('returned a body that is not valid JSON', text, {
|
|
53
|
+
cause,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (!token.access_token || !token.token_type)
|
|
57
|
+
throw this.toTokenError('returned a body without access_token or token_type', text);
|
|
41
58
|
return token;
|
|
42
59
|
}
|
|
60
|
+
async toToken() {
|
|
61
|
+
return await this.requestToken(this.toTokenBody());
|
|
62
|
+
}
|
|
43
63
|
async refresh(refreshToken) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
body: new URLSearchParams({
|
|
48
|
-
grant_type: 'refresh_token',
|
|
49
|
-
refresh_token: refreshToken,
|
|
50
|
-
}),
|
|
51
|
-
redirect: 'follow',
|
|
52
|
-
retry: true,
|
|
53
|
-
headers: {
|
|
54
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
55
|
-
},
|
|
64
|
+
const token = await this.requestToken({
|
|
65
|
+
grant_type: 'refresh_token',
|
|
66
|
+
refresh_token: refreshToken,
|
|
56
67
|
});
|
|
57
|
-
const chunks = await response.body.toArray();
|
|
58
|
-
const buffer = Buffer.concat(chunks);
|
|
59
|
-
const token = JSON.parse(buffer.toString('utf-8'));
|
|
60
68
|
return await this.setToken(token);
|
|
61
69
|
}
|
|
62
70
|
async setToken(token) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OAuth2.js","sourceRoot":"","sources":["../../src/models/OAuth2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAwB,MAAM,qBAAqB,CAAA;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"OAuth2.js","sourceR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AQ,EAAE,CAAA;QAEnC,OAAO,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,YAAY,EAAE,CAAA;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-default-user-agent.d.ts","sourceRoot":"","sources":["../../src/tools/with-default-user-agent.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,wBAAwB,CAAA;AAEvD,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAM,GAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAQ/C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const DEFAULT_USER_AGENT = '@t4h.framework/http';
|
|
2
|
+
export function withDefaultUserAgent(headers = {}) {
|
|
3
|
+
const hasUserAgent = Object.keys(headers).some(header => header.toLowerCase() === 'user-agent');
|
|
4
|
+
if (hasUserAgent)
|
|
5
|
+
return headers;
|
|
6
|
+
return { 'User-Agent': DEFAULT_USER_AGENT, ...headers };
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=with-default-user-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-default-user-agent.js","sourceRoot":"","sources":["../../src/tools/with-default-user-agent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAEvD,MAAM,UAAU,oBAAoB,CAClC,UAAyD,EAAE;IAE3D,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAC5C,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,YAAY,CAChD,CAAA;IAED,IAAI,YAAY;QAAE,OAAO,OAAO,CAAA;IAEhC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,OAAO,EAAE,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t4h.framework/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "HTTP module for the T4H Framework",
|
|
5
5
|
"homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/http",
|
|
6
6
|
"bugs": "https://github.com/tech4humans-brasil/framework/issues",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
"uuidv7": "^1.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@t4h.framework/cache": "^0.
|
|
42
|
-
"@t4h.framework/core": "^0.
|
|
43
|
-
"@t4h.framework/fs": "^0.
|
|
41
|
+
"@t4h.framework/cache": "^0.5.0",
|
|
42
|
+
"@t4h.framework/core": "^0.9.0",
|
|
43
|
+
"@t4h.framework/fs": "^0.7.0",
|
|
44
44
|
"@types/type-is": "^1.6.7",
|
|
45
45
|
"@vitest/coverage-v8": "^4.0.18",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
47
|
"vitest": "^4.0.18"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@t4h.framework/cache": "^0.
|
|
51
|
-
"@t4h.framework/core": "^0.
|
|
52
|
-
"@t4h.framework/fs": "^0.
|
|
50
|
+
"@t4h.framework/cache": "^0.5.0",
|
|
51
|
+
"@t4h.framework/core": "^0.9.0",
|
|
52
|
+
"@t4h.framework/fs": "^0.7.0"
|
|
53
53
|
},
|
|
54
54
|
"packageManager": "yarn@4.12.0",
|
|
55
55
|
"engines": {
|
package/dist/testing/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,sBAAsB,EAEvB,MAAM,qCAAqC,CAAA;AAE5C,wBAAgB,aAAa,CAC3B,cAAc,GAAE,OAAO,CAAC,sBAAsB,CAAM,uEAYrD"}
|
package/dist/testing/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
|
-
import { mockClaim } from '@t4h.framework/core/testing';
|
|
3
|
-
import { HttpClientRequestClaim, } from '../models/HttpClientRequestClaim.js';
|
|
4
|
-
export function mockHttpClaim(implementation = {}) {
|
|
5
|
-
const defaultResponse = {
|
|
6
|
-
status: 200,
|
|
7
|
-
headers: { 'content-type': 'application/json' },
|
|
8
|
-
body: Readable.from(Buffer.from('{}')),
|
|
9
|
-
};
|
|
10
|
-
return mockClaim(HttpClientRequestClaim, {
|
|
11
|
-
request: async () => defaultResponse,
|
|
12
|
-
...implementation,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAEvD,OAAO,EACL,sBAAsB,GAEvB,MAAM,qCAAqC,CAAA;AAE5C,MAAM,UAAU,aAAa,CAC3B,iBAAkD,EAAE;IAEpD,MAAM,eAAe,GAAiC;QACpD,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACvC,CAAA;IAED,OAAO,SAAS,CAAC,sBAAsB,EAAE;QACvC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,eAAe;QACpC,GAAG,cAAc;KAClB,CAAC,CAAA;AACJ,CAAC"}
|