Skip to content

Commit f51b277

Browse files
committed
feat(Flows): add flows.webInputs methods
- add methods for `getAll` and `respond` to web inputs
1 parent c672889 commit f51b277

5 files changed

Lines changed: 239 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`flows.webInputs get 1`] = `
4+
{
5+
"headers": {
6+
"accept": "*/*",
7+
"accept-encoding": "gzip,deflate",
8+
"connection": "close",
9+
"host": "flows.globus.org",
10+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
11+
},
12+
"method": "GET",
13+
"url": "https://flows.globus.org/web_inputs/web-input-id",
14+
}
15+
`;
16+
17+
exports[`flows.webInputs getAll 1`] = `
18+
{
19+
"headers": {
20+
"accept": "*/*",
21+
"accept-encoding": "gzip,deflate",
22+
"connection": "close",
23+
"host": "flows.globus.org",
24+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
25+
},
26+
"method": "GET",
27+
"url": "https://flows.globus.org/web_inputs",
28+
}
29+
`;
30+
31+
exports[`flows.webInputs respond 1`] = `
32+
{
33+
"headers": {
34+
"accept": "*/*",
35+
"accept-encoding": "gzip,deflate",
36+
"connection": "close",
37+
"content-length": "15",
38+
"content-type": "application/json",
39+
"host": "flows.globus.org",
40+
"user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)",
41+
},
42+
"method": "POST",
43+
"url": "https://flows.globus.org/web_inputs/web-input-id/response",
44+
}
45+
`;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { mirror } from '../../../__mocks__/handlers';
2+
import { webInputs } from '..';
3+
4+
const WEB_INPUT_ID = 'web-input-id';
5+
6+
describe('flows.webInputs', () => {
7+
test('get', async () => {
8+
const {
9+
req: { url, method, headers },
10+
} = await mirror(await webInputs.get(WEB_INPUT_ID));
11+
expect({
12+
url,
13+
method,
14+
headers,
15+
}).toMatchSnapshot();
16+
});
17+
18+
test('getAll', async () => {
19+
const {
20+
req: { url, method, headers },
21+
} = await mirror(await webInputs.getAll());
22+
expect({
23+
url,
24+
method,
25+
headers,
26+
}).toMatchSnapshot();
27+
});
28+
29+
test('respond', async () => {
30+
const {
31+
req: { url, method, headers },
32+
} = await mirror(
33+
await webInputs.respond(WEB_INPUT_ID, {
34+
body: {
35+
response: { value: 'response' },
36+
},
37+
}),
38+
);
39+
expect({
40+
url,
41+
method,
42+
headers,
43+
}).toMatchSnapshot();
44+
});
45+
});

src/services/flows/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ export const SCOPES = {
1919
RUN: 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/run',
2020
RUN_STATUS: 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/run_status',
2121
RUN_MANAGE: 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/run_manage',
22+
WEB_INPUT_VIEW:
23+
'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/web_input_view',
24+
WEB_INPUT_RESPOND:
25+
'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/web_input_respond',
2226
};

src/services/flows/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export const CONFIG = FLOWS;
1616

1717
export * as flows from './service/flows.js';
1818
export * as runs from './service/runs.js';
19+
export * as webInputs from './service/web-inputs.js';
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { ID, SCOPES } from '../config.js';
2+
import { HTTP_METHODS, serviceRequest } from '../../shared.js';
3+
import { createServiceMethodFactory } from '../../factory.js';
4+
import { RESOURCE_SERVERS } from '../../auth/config.js';
5+
6+
import type { OpenAPI } from '../index.js';
7+
import type {
8+
JSONFetchResponse,
9+
ServiceMethod,
10+
ServiceMethodDynamicSegments,
11+
} from '../../types.js';
12+
13+
export const get = function (
14+
web_input_id: string,
15+
options?,
16+
sdkOptions?,
17+
): Promise<
18+
JSONFetchResponse<
19+
OpenAPI.paths['/web_inputs/{web_input_id}']['get']['responses']['200']['content']['application/json']
20+
>
21+
> {
22+
return serviceRequest(
23+
{
24+
service: ID,
25+
scope: SCOPES.WEB_INPUT_VIEW,
26+
path: `/web_inputs/${web_input_id}`,
27+
},
28+
options,
29+
sdkOptions,
30+
);
31+
} satisfies ServiceMethodDynamicSegments<
32+
string,
33+
{
34+
query?: OpenAPI.paths['/web_inputs/{web_input_id}']['get']['parameters']['query'];
35+
},
36+
JSONFetchResponse<
37+
OpenAPI.paths['/web_inputs/{web_input_id}']['get']['responses']['200']['content']['application/json']
38+
>
39+
>;
40+
41+
/**
42+
* @see https://flows.globus.org/redoc#tag/Web-Inputs/paths/~1web_inputs/get
43+
*/
44+
export const getAll = function (
45+
options?,
46+
sdkOptions?,
47+
): Promise<
48+
JSONFetchResponse<
49+
OpenAPI.paths['/web_inputs']['get']['responses']['200']['content']['application/json']
50+
>
51+
> {
52+
return serviceRequest(
53+
{
54+
service: ID,
55+
scope: SCOPES.WEB_INPUT_VIEW,
56+
path: `/web_inputs`,
57+
},
58+
options,
59+
sdkOptions,
60+
);
61+
} satisfies ServiceMethod<{
62+
query?: OpenAPI.paths['/web_inputs']['get']['parameters']['query'];
63+
}>;
64+
65+
/**
66+
* @see https://flows.globus.org/redoc#tag/Web-Inputs/paths/~1web_inputs~1%7Bweb_input_id%7D~1response/post
67+
*/
68+
export const respond = function (
69+
web_input_id: string,
70+
options?,
71+
sdkOptions?,
72+
): Promise<
73+
JSONFetchResponse<
74+
OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['responses']['200']['content']['application/json']
75+
>
76+
> {
77+
return serviceRequest(
78+
{
79+
service: ID,
80+
scope: SCOPES.WEB_INPUT_RESPOND,
81+
path: `/web_inputs/${web_input_id}/response`,
82+
method: HTTP_METHODS.POST,
83+
},
84+
options,
85+
sdkOptions,
86+
);
87+
} satisfies ServiceMethodDynamicSegments<
88+
string,
89+
{
90+
body: OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['requestBody']['content']['application/json'];
91+
},
92+
JSONFetchResponse<
93+
OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['responses']['200']['content']['application/json']
94+
>
95+
>;
96+
97+
/**
98+
* @private
99+
*/
100+
export const next = {
101+
get: createServiceMethodFactory({
102+
service: ID,
103+
resource_server: RESOURCE_SERVERS.FLOWS,
104+
path: `/web_inputs/{web_input_id}`,
105+
}).generate<
106+
{
107+
request?: {
108+
query?: OpenAPI.paths['/web_inputs/{web_input_id}']['get']['parameters']['query'];
109+
};
110+
},
111+
JSONFetchResponse<
112+
OpenAPI.paths['/web_inputs/{web_input_id}']['get']['responses']['200']['content']['application/json']
113+
>
114+
>(),
115+
getAll: createServiceMethodFactory({
116+
service: ID,
117+
resource_server: RESOURCE_SERVERS.FLOWS,
118+
path: `/web_inputs`,
119+
}).generate<
120+
{
121+
request?: {
122+
query?: OpenAPI.paths['/web_inputs']['get']['parameters']['query'];
123+
};
124+
},
125+
JSONFetchResponse<
126+
OpenAPI.paths['/web_inputs']['get']['responses']['200']['content']['application/json']
127+
>
128+
>(),
129+
respond: createServiceMethodFactory({
130+
service: ID,
131+
resource_server: RESOURCE_SERVERS.FLOWS,
132+
path: `/web_inputs/{web_input_id}/response`,
133+
}).generate<
134+
{
135+
request?: {
136+
query?: OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['parameters']['query'];
137+
data?: OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['requestBody']['content']['application/json'];
138+
};
139+
},
140+
JSONFetchResponse<
141+
OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['responses']['200']['content']['application/json']
142+
>
143+
>(),
144+
};

0 commit comments

Comments
 (0)