UNPKG

@smythos/sdk

Version:
117 lines (103 loc) 3.54 kB
//!!! DO NOT EDIT THIS FILE, IT IS AUTO-GENERATED !!!// import { Agent } from '../../Agent/Agent.class'; import { createSafeAccessor } from '../utils'; import { ComponentWrapper } from '../ComponentWrapper.class'; import { InputSettings, ComponentInput } from '../../types/SDKTypes'; export interface TAPICallSettings { name?: string; /** Method */ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'; /** URL */ url: string; /** Headers */ headers?: any; /** Content-Type */ contentType?: 'none' | 'application/json' | 'multipart/form-data' | 'binary' | 'application/x-www-form-urlencoded' | 'text/plain' | 'application/xml'; /** Body */ body?: any; /** Proxy */ proxy?: string; /** OAuth Service */ oauthService?: string; /** Scope */ scope?: string; /** Authorization URL */ authorizationURL?: string; /** Token URL */ tokenURL?: string; /** Client ID */ clientID?: string; /** Client Secret */ clientSecret?: string; /** OAuth2 Callback URL */ oauth2CallbackURL?: string; /** Callback URL */ callbackURL?: string; /** Request Token URL */ requestTokenURL?: string; /** Access Token URL */ accessTokenURL?: string; /** User Authorization URL */ userAuthorizationURL?: string; /** Consumer Key */ consumerKey?: string; /** Consumer Secret */ consumerSecret?: string; /** OAuth1 Callback URL */ oauth1CallbackURL?: string; /** Authenticate */ authenticate?: string; /** OAuth Connection ID */ oauth_con_id?: string; } export type TAPICallInputs = { [key: string]: InputSettings; }; export type TAPICallOutputs = { /** The headers of the API call response */ Headers: any; /** The response of the API call */ Response: any; [key: string]: any; }; /** * Use this component to make an API call */ export function APICall(settings?: TAPICallSettings, agent?: Agent) { //const { name, ...settingsWithoutName } = settings || {}; const dataObject: any = { name: /*settings?.name || */'APICall', settings: { //...settingsWithoutName ...settings } }; const component = new ComponentWrapper(dataObject, agent); if (agent) { (agent.structure.components as ComponentWrapper[]).push(component); agent.sync(); } const _out: TAPICallOutputs = createSafeAccessor({ Headers: createSafeAccessor({}, component, 'Headers', {"description":"The headers of the API call response","default":true}), Response: createSafeAccessor({}, component, 'Response', {"description":"The response of the API call","default":true}), }, component, ''); const _in: { [key: string]: ComponentInput } = { // No inputs defined }; dataObject.outputs = _out; dataObject.inputs = _in; component.inputs(_in); const wrapper = { /** Component outputs - access via .out.OutputName */ out: _out, /** * Create or Connect the component inputs * if the input does not exist, it will be created * @examples * - component.in({ Input: source.out.data }) * - component.in({ Input: { type: 'string', source:source.out.data } }) */ in: component.inputs.bind(component) as (inputs: TAPICallInputs) => void, }; return wrapper; }