@t4h.framework/http 0.0.0-experimental-c0d4325
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/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/activities/AbstractHttpRequestActivity.d.ts +63 -0
- package/dist/activities/AbstractHttpRequestActivity.d.ts.map +1 -0
- package/dist/activities/AbstractHttpRequestActivity.js +101 -0
- package/dist/activities/AbstractHttpRequestActivity.js.map +1 -0
- package/dist/activities/HttpRequestActivity.d.ts +11 -0
- package/dist/activities/HttpRequestActivity.d.ts.map +1 -0
- package/dist/activities/HttpRequestActivity.js +17 -0
- package/dist/activities/HttpRequestActivity.js.map +1 -0
- package/dist/errors/HttpError.d.ts +318 -0
- package/dist/errors/HttpError.d.ts.map +1 -0
- package/dist/errors/HttpError.js +53 -0
- package/dist/errors/HttpError.js.map +1 -0
- package/dist/http.d.ts +11 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +11 -0
- package/dist/http.js.map +1 -0
- package/dist/models/Body.d.ts +15 -0
- package/dist/models/Body.d.ts.map +1 -0
- package/dist/models/Body.js +37 -0
- package/dist/models/Body.js.map +1 -0
- package/dist/models/HttpAuth.d.ts +12 -0
- package/dist/models/HttpAuth.d.ts.map +1 -0
- package/dist/models/HttpAuth.js +10 -0
- package/dist/models/HttpAuth.js.map +1 -0
- package/dist/models/HttpClient.d.ts +25 -0
- package/dist/models/HttpClient.d.ts.map +1 -0
- package/dist/models/HttpClient.js +39 -0
- package/dist/models/HttpClient.js.map +1 -0
- package/dist/models/HttpClientRequestClaim.d.ts +20 -0
- package/dist/models/HttpClientRequestClaim.d.ts.map +1 -0
- package/dist/models/HttpClientRequestClaim.js +3 -0
- package/dist/models/HttpClientRequestClaim.js.map +1 -0
- package/dist/models/OAuth2.d.ts +44 -0
- package/dist/models/OAuth2.d.ts.map +1 -0
- package/dist/models/OAuth2.js +86 -0
- package/dist/models/OAuth2.js.map +1 -0
- package/dist/models/OAuth2GrantClientCredentials.d.ts +13 -0
- package/dist/models/OAuth2GrantClientCredentials.d.ts.map +1 -0
- package/dist/models/OAuth2GrantClientCredentials.js +11 -0
- package/dist/models/OAuth2GrantClientCredentials.js.map +1 -0
- package/dist/models/OAuth2GrantResourceOwnerPassword.d.ts +17 -0
- package/dist/models/OAuth2GrantResourceOwnerPassword.d.ts.map +1 -0
- package/dist/models/OAuth2GrantResourceOwnerPassword.js +13 -0
- package/dist/models/OAuth2GrantResourceOwnerPassword.js.map +1 -0
- package/dist/models/Response.d.ts +9 -0
- package/dist/models/Response.d.ts.map +1 -0
- package/dist/models/Response.js +11 -0
- package/dist/models/Response.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tech four 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @t4h.framework/http
|
|
2
|
+
|
|
3
|
+
HTTP activities, claims, and a high-level client for making HTTP requests within workflows.
|
|
4
|
+
|
|
5
|
+
## Claim
|
|
6
|
+
|
|
7
|
+
### HttpClientRequestClaim
|
|
8
|
+
|
|
9
|
+
Abstract dependency for performing raw HTTP requests. The runtime must provide a concrete implementation.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { HttpClientRequestClaim } from '@t4h.framework/http'
|
|
13
|
+
|
|
14
|
+
// the runtime provides this:
|
|
15
|
+
// { provide: HttpClientRequestClaim, value: new MyHttpClientRequestClaimImpl() }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Activities
|
|
19
|
+
|
|
20
|
+
### HttpRequestActivity
|
|
21
|
+
|
|
22
|
+
A `SyncActivity` that performs an HTTP request and returns a `Response`. Internally it uses `HttpClientRequestClaim` and `FileSystemClaim` to execute the request and persist the response body.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { HttpRequestActivity } from '@t4h.framework/http'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### AbstractHttpRequestActivity
|
|
29
|
+
|
|
30
|
+
Base class for building custom HTTP activities. Extend it and implement `toHttpInput` and `toHttpOutput`:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { AbstractHttpRequestActivity } from '@t4h.framework/http'
|
|
34
|
+
import type { HttpRequestActivityInput, HttpRequestActivityOutput } from '@t4h.framework/http'
|
|
35
|
+
import type { Serializable } from '@t4h.framework/core'
|
|
36
|
+
|
|
37
|
+
class MyCustomHttpActivity extends AbstractHttpRequestActivity<
|
|
38
|
+
[url: string],
|
|
39
|
+
{ url: string }
|
|
40
|
+
> {
|
|
41
|
+
public async toInput(url: string) {
|
|
42
|
+
return { url }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected async toHttpInput(input: { url: string }): Promise<HttpRequestActivityInput> {
|
|
46
|
+
return { url: input.url, method: 'GET' }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected async toHttpOutput(output: HttpRequestActivityOutput): Promise<Serializable> {
|
|
50
|
+
return { status: output.status }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public toOutput(output: { status: number }) {
|
|
54
|
+
return output
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## HttpClient
|
|
60
|
+
|
|
61
|
+
High-level HTTP client that wraps `HttpRequestActivity` behind a simple API. Available as a singleton `http` or instantiated with custom config.
|
|
62
|
+
|
|
63
|
+
### Basic usage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { http } from '@t4h.framework/http'
|
|
67
|
+
|
|
68
|
+
const response = await http.get('https://api.example.com/users')
|
|
69
|
+
const data = await response.body.json()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### POST with JSON body
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const response = await http.post('https://api.example.com/users', {
|
|
76
|
+
json: { name: 'John', email: 'john@example.com' },
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Custom client with base URL
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { http } from '@t4h.framework/http'
|
|
84
|
+
|
|
85
|
+
const api = http.extend({ baseUrl: 'https://api.example.com' })
|
|
86
|
+
|
|
87
|
+
const response = await api.get('/users')
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Available methods
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
http.request(url, config?)
|
|
94
|
+
http.get(url, config?)
|
|
95
|
+
http.post(url, body, config?)
|
|
96
|
+
http.put(url, body, config?)
|
|
97
|
+
http.patch(url, body, config?)
|
|
98
|
+
http.delete(url, config?)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Authentication
|
|
102
|
+
|
|
103
|
+
### OAuth2 Client Credentials
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { http, OAuth2ClientCredentials } from '@t4h.framework/http'
|
|
107
|
+
|
|
108
|
+
const auth = new OAuth2ClientCredentials({
|
|
109
|
+
tokenUrl: 'https://auth.example.com/token',
|
|
110
|
+
clientId: 'my-client-id',
|
|
111
|
+
clientSecret: 'my-client-secret',
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const response = await http.get('https://api.example.com/data', { auth })
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### OAuth2 Resource Owner Password
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { OAuth2GrantResourceOwnerPassword } from '@t4h.framework/http'
|
|
121
|
+
|
|
122
|
+
const auth = new OAuth2GrantResourceOwnerPassword({
|
|
123
|
+
tokenUrl: 'https://auth.example.com/token',
|
|
124
|
+
clientId: 'my-client-id',
|
|
125
|
+
clientSecret: 'my-client-secret',
|
|
126
|
+
username: 'user',
|
|
127
|
+
password: 'pass',
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Basic Auth
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
const response = await http.get('https://api.example.com/data', {
|
|
135
|
+
auth: { username: 'user', password: 'pass' },
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Response
|
|
140
|
+
|
|
141
|
+
The `Response` object provides access to status, headers, and body:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
const response = await http.get('https://api.example.com/data')
|
|
145
|
+
|
|
146
|
+
response.status // number
|
|
147
|
+
response.headers // Record<string, string | string[] | undefined>
|
|
148
|
+
|
|
149
|
+
await response.body.text() // string
|
|
150
|
+
await response.body.json() // parsed JSON
|
|
151
|
+
response.body.contentType // string
|
|
152
|
+
response.body.contentLength // number
|
|
153
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SyncActivity, Binary, type Serializable } from '@t4h.framework/core';
|
|
2
|
+
import { Body } from '../models/Body.js';
|
|
3
|
+
import { HttpAuth } from '../models/HttpAuth.js';
|
|
4
|
+
export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
|
5
|
+
export type HttpRequestActivityInputRetryOptions = {
|
|
6
|
+
limit?: number;
|
|
7
|
+
methods?: HttpMethod[];
|
|
8
|
+
status?: number[];
|
|
9
|
+
maxRetryAfter?: undefined;
|
|
10
|
+
backoffLimit?: number;
|
|
11
|
+
jitter?: number;
|
|
12
|
+
};
|
|
13
|
+
export type HttpRequestActivityInputBodyFormData = {
|
|
14
|
+
[key: string]: string | number | boolean | null | undefined | Binary | readonly HttpRequestActivityInputBodyFormData[] | HttpRequestActivityInputBodyFormData;
|
|
15
|
+
};
|
|
16
|
+
export type HttpRequestActivityInput = {
|
|
17
|
+
url: string;
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
method?: HttpMethod;
|
|
20
|
+
body?: {
|
|
21
|
+
json: Serializable;
|
|
22
|
+
} | {
|
|
23
|
+
text: string;
|
|
24
|
+
} | {
|
|
25
|
+
form: HttpRequestActivityInputBodyFormData;
|
|
26
|
+
};
|
|
27
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
28
|
+
retry?: boolean | HttpRequestActivityInputRetryOptions;
|
|
29
|
+
auth?: HttpAuth | {
|
|
30
|
+
username: string;
|
|
31
|
+
password: string;
|
|
32
|
+
};
|
|
33
|
+
redirect?: 'follow' | 'manual' | number;
|
|
34
|
+
};
|
|
35
|
+
export type HttpRequestActivityOutput = {
|
|
36
|
+
status: number;
|
|
37
|
+
headers: Record<string, string | string[] | undefined>;
|
|
38
|
+
body: Body;
|
|
39
|
+
};
|
|
40
|
+
declare const CLAIMS_KEY: unique symbol;
|
|
41
|
+
export declare abstract class AbstractHttpRequestActivity<TArgs extends readonly any[], TInput extends Serializable, TSerializableOutput extends Serializable | void, TOutput> extends SyncActivity<TArgs, TInput, TSerializableOutput, TOutput> {
|
|
42
|
+
private readonly [CLAIMS_KEY];
|
|
43
|
+
protected abstract toHttpInput(input: TInput): HttpRequestActivityInput | Promise<HttpRequestActivityInput>;
|
|
44
|
+
protected abstract toHttpOutput(output: HttpRequestActivityOutput): TSerializableOutput | Promise<TSerializableOutput>;
|
|
45
|
+
static append(form: FormData, input: HttpRequestActivityInputBodyFormData, currentKey?: string): Promise<FormData>;
|
|
46
|
+
protected static getFormData(input: HttpRequestActivityInputBodyFormData): Promise<FormData>;
|
|
47
|
+
protected static getContent(body: HttpRequestActivityInput['body']): Promise<{
|
|
48
|
+
body: undefined;
|
|
49
|
+
headers: undefined;
|
|
50
|
+
} | {
|
|
51
|
+
body: Buffer<ArrayBuffer>;
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': string;
|
|
54
|
+
'Content-Length': string;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
body: FormData;
|
|
58
|
+
headers?: undefined;
|
|
59
|
+
}>;
|
|
60
|
+
run(input: TInput): Promise<TSerializableOutput>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=AbstractHttpRequestActivity.d.ts.map
|
|
@@ -0,0 +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;AAGhD,MAAM,MAAM,UAAU,GAClB,KAAK,GACL,MAAM,GACN,MAA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AM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,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"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import { SyncActivity, Binary, Claim, } from '@t4h.framework/core';
|
|
3
|
+
import { FileSystemClaim } from '@t4h.framework/fs';
|
|
4
|
+
import mime from 'mime';
|
|
5
|
+
import { uuidv7 } from 'uuidv7';
|
|
6
|
+
import { Body } from '../models/Body.js';
|
|
7
|
+
import { HttpAuth } from '../models/HttpAuth.js';
|
|
8
|
+
import { HttpClientRequestClaim } from '../models/HttpClientRequestClaim.js';
|
|
9
|
+
const CLAIMS_KEY = Symbol('http-request-activity-claims');
|
|
10
|
+
export class AbstractHttpRequestActivity extends SyncActivity {
|
|
11
|
+
[CLAIMS_KEY] = new Claim({
|
|
12
|
+
http: HttpClientRequestClaim,
|
|
13
|
+
fs: FileSystemClaim,
|
|
14
|
+
});
|
|
15
|
+
static async append(form, input, currentKey) {
|
|
16
|
+
for (const [key, value] of Object.entries(input)) {
|
|
17
|
+
if (typeof value === 'undefined')
|
|
18
|
+
continue;
|
|
19
|
+
if (value === null)
|
|
20
|
+
continue;
|
|
21
|
+
const formKey = currentKey ? `${currentKey}[${key}]` : key;
|
|
22
|
+
if (typeof value === 'object')
|
|
23
|
+
if (value instanceof Binary)
|
|
24
|
+
form.append(formKey, await value.stream(), `${uuidv7()}.${mime.getExtension(value.contentType)}`);
|
|
25
|
+
else
|
|
26
|
+
await this.append(form, value, formKey);
|
|
27
|
+
else
|
|
28
|
+
form.append(formKey, String(value));
|
|
29
|
+
}
|
|
30
|
+
return form;
|
|
31
|
+
}
|
|
32
|
+
static async getFormData(input) {
|
|
33
|
+
const formData = new FormData();
|
|
34
|
+
await this.append(formData, input);
|
|
35
|
+
return formData;
|
|
36
|
+
}
|
|
37
|
+
static async getContent(body) {
|
|
38
|
+
if (typeof body !== 'object')
|
|
39
|
+
return {
|
|
40
|
+
body: undefined,
|
|
41
|
+
headers: undefined,
|
|
42
|
+
};
|
|
43
|
+
if ('json' in body) {
|
|
44
|
+
const json = JSON.stringify(body.json);
|
|
45
|
+
const buffer = Buffer.from(json);
|
|
46
|
+
return {
|
|
47
|
+
body: buffer,
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'Content-Length': buffer.byteLength.toString(),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if ('text' in body) {
|
|
55
|
+
const buffer = Buffer.from(body.text);
|
|
56
|
+
return {
|
|
57
|
+
body: buffer,
|
|
58
|
+
headers: {
|
|
59
|
+
'Content-Type': 'text/plain',
|
|
60
|
+
'Content-Length': buffer.byteLength.toString(),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if ('form' in body) {
|
|
65
|
+
const form = await this.getFormData(body.form);
|
|
66
|
+
return { body: form };
|
|
67
|
+
}
|
|
68
|
+
throw new Error('Invalid body');
|
|
69
|
+
}
|
|
70
|
+
async run(input) {
|
|
71
|
+
const httpInput = await this.toHttpInput(input);
|
|
72
|
+
const headers = {};
|
|
73
|
+
if (httpInput.auth)
|
|
74
|
+
if (httpInput.auth instanceof HttpAuth)
|
|
75
|
+
headers.Authorization = await httpInput.auth.getAuthorizationHeader();
|
|
76
|
+
else
|
|
77
|
+
headers.Authorization = `Basic ${Buffer.from(`${httpInput.auth.username}:${httpInput.auth.password}`).toString('base64')}`;
|
|
78
|
+
const content = await AbstractHttpRequestActivity.getContent(httpInput.body);
|
|
79
|
+
const response = await this[CLAIMS_KEY].http.request({
|
|
80
|
+
url: new URL(httpInput.url, httpInput.baseUrl),
|
|
81
|
+
method: httpInput.method ?? 'GET',
|
|
82
|
+
body: content?.body,
|
|
83
|
+
redirect: httpInput.redirect ?? 'follow',
|
|
84
|
+
retry: httpInput.retry ?? true,
|
|
85
|
+
headers: {
|
|
86
|
+
...httpInput.headers,
|
|
87
|
+
...content.headers,
|
|
88
|
+
...headers,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const contentType = response.headers['content-type'];
|
|
92
|
+
const ext = typeof contentType === 'string' ? mime.getExtension(contentType) : 'bin';
|
|
93
|
+
const binary = await this[CLAIMS_KEY].fs.write(`${uuidv7()}-http-request-activity-response-body.${ext}`, response.body);
|
|
94
|
+
return this.toHttpOutput({
|
|
95
|
+
status: response.status,
|
|
96
|
+
headers: response.headers,
|
|
97
|
+
body: new Body(binary),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=AbstractHttpRequestActivity.js.map
|
|
@@ -0,0 +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;AAsD5E,MAAM,UAAU,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAA;AAEzD,MAAM,OAAgB,2BAKpB,SAAQ,YAAyD;IAChD,CAAC,UAAU,CAAC,GAAG,IAAI,KAAK,CAAC;QACxC,IAAI,EAAE,sBAAsB;QAC5B,EAAE,EAAE,eAAe;KACpB,CAAC,CAAA;IAUK,MAAM,CAAC,KAAK,CAAC,MAAM,CACxB,IAAc,EACd,KAA2C,EAC3C,UAAmB;QAEnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,OAAO,KAAK,KAAK,WAAW;gBAAE,SAAQ;YAC1C,IAAI,KAAK,KAAK,IAAI;gBAAE,SAAQ;YAE5B,MAAM,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;YAE1D,IAAI,OAAO,KAAK,KAA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M,IAAI,KAAK;YACjC,IAAI,EAAE,OAAO,EAAE,IAAI;YACnB,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,QAAQ;YACxC,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,IAAI;YAC9B,OAAO,EAAE;gBACP,GAAG,SAAS,CAAC,OAAO;gBACpB,GAAG,OAAO,CAAC,OAAO;gBAClB,GAAG,OAAO;aACX;SACF,CAAC,CAAA;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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbstractHttpRequestActivity, type HttpRequestActivityInput, type HttpRequestActivityOutput } from './AbstractHttpRequestActivity.js';
|
|
2
|
+
import { Response } from '../models/Response.js';
|
|
3
|
+
export declare class HttpRequestActivity extends AbstractHttpRequestActivity<[
|
|
4
|
+
config: HttpRequestActivityInput
|
|
5
|
+
], HttpRequestActivityInput, HttpRequestActivityOutput, Response> {
|
|
6
|
+
toInput(input: HttpRequestActivityInput): HttpRequestActivityInput;
|
|
7
|
+
toOutput(output: any): Response;
|
|
8
|
+
protected toHttpInput(input: HttpRequestActivityInput): HttpRequestActivityInput;
|
|
9
|
+
protected toHttpOutput(output: HttpRequestActivityOutput): HttpRequestActivityOutput;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=HttpRequestActivity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRequestActivity.d.ts","sourceRoot":"","sources":["../../src/activities/HttpRequestActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC/B,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,qBAAa,mBAAoB,SAAQ,2BAA2B,CAClE;IAAC,MAAM,EAAE,wBAAwB;CAAC,EAClC,wBAAwB,EACxB,yBAAyB,EACzB,QAAQ,CACT;IACQ,OAAO,CAAC,KAAK,EAAE,wBAAwB,GAAG,wBAAwB;IAIlE,QAAQ,CAAC,MAAM,EAAE,GAAG,GAAG,QAAQ;IAItC,SAAS,CAAC,WAAW,CACnB,KAAK,EAAE,wBAAwB,GAC9B,wBAAwB;IAI3B,SAAS,CAAC,YAAY,CACpB,MAAM,EAAE,yBAAyB,GAChC,yBAAyB;CAG7B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AbstractHttpRequestActivity, } from './AbstractHttpRequestActivity.js';
|
|
2
|
+
import { Response } from '../models/Response.js';
|
|
3
|
+
export class HttpRequestActivity extends AbstractHttpRequestActivity {
|
|
4
|
+
toInput(input) {
|
|
5
|
+
return input;
|
|
6
|
+
}
|
|
7
|
+
toOutput(output) {
|
|
8
|
+
return new Response(output);
|
|
9
|
+
}
|
|
10
|
+
toHttpInput(input) {
|
|
11
|
+
return input;
|
|
12
|
+
}
|
|
13
|
+
toHttpOutput(output) {
|
|
14
|
+
return output;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=HttpRequestActivity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRequestActivity.js","sourceRoot":"","sources":["../../src/activities/HttpRequestActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,GAG5B,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,OAAO,mBAAoB,SAAQ,2BAKxC;IACQ,OAAO,CAAC,KAA+B;QAC5C,OAAO,KAAK,CAAA;IACd,CAAC;IAEM,QAAQ,CAAC,MAAW;QACzB,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC;IAES,WAAW,CACnB,KAA+B;QAE/B,OAAO,KAAK,CAAA;IACd,CAAC;IAES,YAAY,CACpB,MAAiC;QAEjC,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|