From f51b277451cdd243106af512114f31de89714922 Mon Sep 17 00:00:00 2001 From: Jake Lewis Date: Tue, 23 Jun 2026 10:35:39 -0500 Subject: [PATCH] feat(Flows): add `flows.webInputs` methods - add methods for `getAll` and `respond` to web inputs --- .../__snapshots__/web-inputs.spec.ts.snap | 45 ++++++ .../flows/__tests__/web-inputs.spec.ts | 45 ++++++ src/services/flows/config.ts | 4 + src/services/flows/index.ts | 1 + src/services/flows/service/web-inputs.ts | 144 ++++++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 src/services/flows/__tests__/__snapshots__/web-inputs.spec.ts.snap create mode 100644 src/services/flows/__tests__/web-inputs.spec.ts create mode 100644 src/services/flows/service/web-inputs.ts diff --git a/src/services/flows/__tests__/__snapshots__/web-inputs.spec.ts.snap b/src/services/flows/__tests__/__snapshots__/web-inputs.spec.ts.snap new file mode 100644 index 00000000..76bb0ccc --- /dev/null +++ b/src/services/flows/__tests__/__snapshots__/web-inputs.spec.ts.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`flows.webInputs get 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "host": "flows.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "GET", + "url": "https://flows.globus.org/web_inputs/web-input-id", +} +`; + +exports[`flows.webInputs getAll 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "host": "flows.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "GET", + "url": "https://flows.globus.org/web_inputs", +} +`; + +exports[`flows.webInputs respond 1`] = ` +{ + "headers": { + "accept": "*/*", + "accept-encoding": "gzip,deflate", + "connection": "close", + "content-length": "15", + "content-type": "application/json", + "host": "flows.globus.org", + "user-agent": "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)", + }, + "method": "POST", + "url": "https://flows.globus.org/web_inputs/web-input-id/response", +} +`; diff --git a/src/services/flows/__tests__/web-inputs.spec.ts b/src/services/flows/__tests__/web-inputs.spec.ts new file mode 100644 index 00000000..29fe81bf --- /dev/null +++ b/src/services/flows/__tests__/web-inputs.spec.ts @@ -0,0 +1,45 @@ +import { mirror } from '../../../__mocks__/handlers'; +import { webInputs } from '..'; + +const WEB_INPUT_ID = 'web-input-id'; + +describe('flows.webInputs', () => { + test('get', async () => { + const { + req: { url, method, headers }, + } = await mirror(await webInputs.get(WEB_INPUT_ID)); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); + + test('getAll', async () => { + const { + req: { url, method, headers }, + } = await mirror(await webInputs.getAll()); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); + + test('respond', async () => { + const { + req: { url, method, headers }, + } = await mirror( + await webInputs.respond(WEB_INPUT_ID, { + body: { + response: { value: 'response' }, + }, + }), + ); + expect({ + url, + method, + headers, + }).toMatchSnapshot(); + }); +}); diff --git a/src/services/flows/config.ts b/src/services/flows/config.ts index c529e068..0dc69d42 100644 --- a/src/services/flows/config.ts +++ b/src/services/flows/config.ts @@ -19,4 +19,8 @@ export const SCOPES = { RUN: 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/run', RUN_STATUS: 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/run_status', RUN_MANAGE: 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/run_manage', + WEB_INPUT_VIEW: + 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/web_input_view', + WEB_INPUT_RESPOND: + 'https://auth.globus.org/scopes/eec9b274-0c81-4334-bdc2-54e90e689b9a/web_input_respond', }; diff --git a/src/services/flows/index.ts b/src/services/flows/index.ts index 0ce87a1d..3f878b6c 100644 --- a/src/services/flows/index.ts +++ b/src/services/flows/index.ts @@ -16,3 +16,4 @@ export const CONFIG = FLOWS; export * as flows from './service/flows.js'; export * as runs from './service/runs.js'; +export * as webInputs from './service/web-inputs.js'; diff --git a/src/services/flows/service/web-inputs.ts b/src/services/flows/service/web-inputs.ts new file mode 100644 index 00000000..f2ab7d5e --- /dev/null +++ b/src/services/flows/service/web-inputs.ts @@ -0,0 +1,144 @@ +import { ID, SCOPES } from '../config.js'; +import { HTTP_METHODS, serviceRequest } from '../../shared.js'; +import { createServiceMethodFactory } from '../../factory.js'; +import { RESOURCE_SERVERS } from '../../auth/config.js'; + +import type { OpenAPI } from '../index.js'; +import type { + JSONFetchResponse, + ServiceMethod, + ServiceMethodDynamicSegments, +} from '../../types.js'; + +export const get = function ( + web_input_id: string, + options?, + sdkOptions?, +): Promise< + JSONFetchResponse< + OpenAPI.paths['/web_inputs/{web_input_id}']['get']['responses']['200']['content']['application/json'] + > +> { + return serviceRequest( + { + service: ID, + scope: SCOPES.WEB_INPUT_VIEW, + path: `/web_inputs/${web_input_id}`, + }, + options, + sdkOptions, + ); +} satisfies ServiceMethodDynamicSegments< + string, + { + query?: OpenAPI.paths['/web_inputs/{web_input_id}']['get']['parameters']['query']; + }, + JSONFetchResponse< + OpenAPI.paths['/web_inputs/{web_input_id}']['get']['responses']['200']['content']['application/json'] + > +>; + +/** + * @see https://flows.globus.org/redoc#tag/Web-Inputs/paths/~1web_inputs/get + */ +export const getAll = function ( + options?, + sdkOptions?, +): Promise< + JSONFetchResponse< + OpenAPI.paths['/web_inputs']['get']['responses']['200']['content']['application/json'] + > +> { + return serviceRequest( + { + service: ID, + scope: SCOPES.WEB_INPUT_VIEW, + path: `/web_inputs`, + }, + options, + sdkOptions, + ); +} satisfies ServiceMethod<{ + query?: OpenAPI.paths['/web_inputs']['get']['parameters']['query']; +}>; + +/** + * @see https://flows.globus.org/redoc#tag/Web-Inputs/paths/~1web_inputs~1%7Bweb_input_id%7D~1response/post + */ +export const respond = function ( + web_input_id: string, + options?, + sdkOptions?, +): Promise< + JSONFetchResponse< + OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['responses']['200']['content']['application/json'] + > +> { + return serviceRequest( + { + service: ID, + scope: SCOPES.WEB_INPUT_RESPOND, + path: `/web_inputs/${web_input_id}/response`, + method: HTTP_METHODS.POST, + }, + options, + sdkOptions, + ); +} satisfies ServiceMethodDynamicSegments< + string, + { + body: OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['requestBody']['content']['application/json']; + }, + JSONFetchResponse< + OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['responses']['200']['content']['application/json'] + > +>; + +/** + * @private + */ +export const next = { + get: createServiceMethodFactory({ + service: ID, + resource_server: RESOURCE_SERVERS.FLOWS, + path: `/web_inputs/{web_input_id}`, + }).generate< + { + request?: { + query?: OpenAPI.paths['/web_inputs/{web_input_id}']['get']['parameters']['query']; + }; + }, + JSONFetchResponse< + OpenAPI.paths['/web_inputs/{web_input_id}']['get']['responses']['200']['content']['application/json'] + > + >(), + getAll: createServiceMethodFactory({ + service: ID, + resource_server: RESOURCE_SERVERS.FLOWS, + path: `/web_inputs`, + }).generate< + { + request?: { + query?: OpenAPI.paths['/web_inputs']['get']['parameters']['query']; + }; + }, + JSONFetchResponse< + OpenAPI.paths['/web_inputs']['get']['responses']['200']['content']['application/json'] + > + >(), + respond: createServiceMethodFactory({ + service: ID, + resource_server: RESOURCE_SERVERS.FLOWS, + path: `/web_inputs/{web_input_id}/response`, + }).generate< + { + request?: { + query?: OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['parameters']['query']; + data?: OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['requestBody']['content']['application/json']; + }; + }, + JSONFetchResponse< + OpenAPI.paths['/web_inputs/{web_input_id}/response']['post']['responses']['200']['content']['application/json'] + > + >(), +};