1 | const path = require('path');
|
2 | const { SDK } = require('@axway/api-builder-sdk');
|
3 | const action = require('./action');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const noBodyResponseSchema = {
|
9 | type: 'object',
|
10 | properties: {
|
11 | headers: {
|
12 | additionalProperties: {
|
13 | type: 'string'
|
14 | }
|
15 | },
|
16 | status: {
|
17 | type: 'integer'
|
18 | }
|
19 | }
|
20 | };
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | const responseSchema = {
|
26 | ...noBodyResponseSchema,
|
27 | properties: {
|
28 | ...noBodyResponseSchema.properties,
|
29 | body: {}
|
30 | }
|
31 | };
|
32 |
|
33 | function getNodes(config) {
|
34 | const nodes = new SDK({ pluginConfig: config });
|
35 |
|
36 |
|
37 | nodes.addCommonRestOutputs = function (schema = responseSchema) {
|
38 | this
|
39 | .output('2xx', {
|
40 | name: '2XX',
|
41 | context: '$.response',
|
42 | schema
|
43 | })
|
44 | .output('3xx', {
|
45 | name: '3XX',
|
46 | context: '$.response',
|
47 | schema
|
48 | })
|
49 | .output('4xx', {
|
50 | name: '4XX',
|
51 | context: '$.response',
|
52 | schema
|
53 | })
|
54 | .output('5xx', {
|
55 | name: '5XX',
|
56 | context: '$.response',
|
57 | schema
|
58 | })
|
59 | .output('error', {
|
60 | name: 'Error',
|
61 | context: '$.error'
|
62 | });
|
63 | return this;
|
64 | };
|
65 |
|
66 |
|
67 | nodes.addURLParameter = function () {
|
68 | this
|
69 | .parameter('url', {
|
70 | title: 'URL',
|
71 | type: 'string',
|
72 | description: 'The target URL.',
|
73 | format: 'uri'
|
74 | });
|
75 | return this;
|
76 | };
|
77 |
|
78 |
|
79 | nodes.addHeadersParameter = function () {
|
80 | this
|
81 | .parameter('headers', {
|
82 | title: 'Headers',
|
83 | description: 'The HTTP headers to set.',
|
84 | type: 'object',
|
85 | additionalProperties: {
|
86 | type: 'string'
|
87 | }
|
88 | }, { required: false });
|
89 | return this;
|
90 | };
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | nodes.addAdvancedHTTPParameters = function () {
|
96 | this
|
97 | .group('Advanced HTTP Options')
|
98 | .parameter('insecure', {
|
99 | title: 'Insecure',
|
100 | description: 'Do not require the SSL certificates to be valid.',
|
101 | type: 'boolean',
|
102 | default: false
|
103 | }, { required: false })
|
104 | .parameter('followRedirect', {
|
105 | title: 'Follow redirect',
|
106 | description: 'Follow HTTP 3xx responses as redirects.',
|
107 | type: 'boolean',
|
108 | default: true
|
109 | }, { required: false })
|
110 | .parameter('maxRedirects', {
|
111 | title: 'Maximum redirects',
|
112 | description: 'Maximum number of redirects before aborting.',
|
113 | type: 'integer',
|
114 | default: 10,
|
115 | minimum: 1
|
116 | }, { required: false });
|
117 | return this;
|
118 | };
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | nodes.addResponseBodyParameters = function () {
|
124 | this
|
125 | .parameter('encoding', {
|
126 | title: 'Response encoding',
|
127 | description: 'The response body encoding. If you expect binary data use \'binary\' as the encoding.',
|
128 | type: 'string'
|
129 | }, { required: false });
|
130 | return this;
|
131 | };
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | nodes.add('rest', {
|
137 | name: 'REST',
|
138 | icon: path.join(__dirname, 'icon.svg'),
|
139 | description: 'The REST node contains methods for making REST requests to HTTP endpoints.',
|
140 | category: 'connector'
|
141 | });
|
142 |
|
143 |
|
144 | nodes.method('get', {
|
145 | name: 'GET',
|
146 | description: 'Use GET APIs to retrieve resources only and not to modify them in any way.'
|
147 | })
|
148 | .addURLParameter()
|
149 | .addHeadersParameter()
|
150 | .addAdvancedHTTPParameters()
|
151 | .addResponseBodyParameters()
|
152 | .addCommonRestOutputs()
|
153 | .action(action.get);
|
154 |
|
155 |
|
156 | nodes.method('head', {
|
157 | name: 'HEAD',
|
158 | description: 'Use HEAD APIs to request the headers that are returned if the specified resource would be requested with a GET API.'
|
159 | })
|
160 | .addURLParameter()
|
161 | .addHeadersParameter()
|
162 | .addAdvancedHTTPParameters()
|
163 | .addCommonRestOutputs(noBodyResponseSchema)
|
164 | .action(action.head);
|
165 |
|
166 |
|
167 | nodes.method('put', {
|
168 | name: 'PUT',
|
169 | description: 'Use PUT APIs primarily to update existing resources, if resource does not exist then API may decide to create a new resource or not.'
|
170 | })
|
171 | .addURLParameter()
|
172 | .parameter('body', {
|
173 | title: 'Body',
|
174 | description: 'The content to send.'
|
175 | })
|
176 | .addHeadersParameter()
|
177 | .addAdvancedHTTPParameters()
|
178 | .addResponseBodyParameters()
|
179 | .addCommonRestOutputs()
|
180 | .action(action.put);
|
181 |
|
182 |
|
183 | nodes.method('post', {
|
184 | name: 'POST',
|
185 | description: 'Use POST APIs to create new resources.'
|
186 | })
|
187 | .addURLParameter()
|
188 | .parameter('body', {
|
189 | title: 'Body',
|
190 | description: 'The content to send.'
|
191 | })
|
192 | .addHeadersParameter()
|
193 | .addAdvancedHTTPParameters()
|
194 | .addResponseBodyParameters()
|
195 | .addCommonRestOutputs()
|
196 | .action(action.post);
|
197 |
|
198 |
|
199 | nodes.method('patch', {
|
200 | name: 'PATCH',
|
201 | description: 'Use PATCH APIs to make partial updates on a resource.'
|
202 | })
|
203 | .addURLParameter()
|
204 | .parameter('body', {
|
205 | title: 'Body',
|
206 | description: 'The content to send.'
|
207 | })
|
208 | .addHeadersParameter()
|
209 | .addAdvancedHTTPParameters()
|
210 | .addResponseBodyParameters()
|
211 | .addCommonRestOutputs()
|
212 | .action(action.patch);
|
213 |
|
214 |
|
215 | nodes.method('delete', {
|
216 | name: 'DELETE',
|
217 | description: 'Use DELETE APIs to delete resources.'
|
218 | })
|
219 | .addURLParameter()
|
220 | .addHeadersParameter()
|
221 | .addAdvancedHTTPParameters()
|
222 | .addResponseBodyParameters()
|
223 | .addCommonRestOutputs()
|
224 | .action(action.delete);
|
225 |
|
226 |
|
227 | nodes.method('options', {
|
228 | name: 'OPTIONS',
|
229 | description: 'Use OPTIONS APIs to determine the options and requirements associated with a resource.'
|
230 | })
|
231 | .addURLParameter()
|
232 | .addHeadersParameter()
|
233 | .addAdvancedHTTPParameters()
|
234 | .addResponseBodyParameters()
|
235 | .addCommonRestOutputs()
|
236 | .action(action.options);
|
237 |
|
238 | return nodes;
|
239 | }
|
240 |
|
241 | module.exports = getNodes;
|