postman-runtime 7.28.3 → 7.29.1
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/CHANGELOG.yaml +30 -0
- package/README.md +3 -7
- package/dist/index.js +1 -1
- package/lib/authorizer/apikey.js +12 -11
- package/lib/authorizer/auth-interface.js +6 -6
- package/lib/authorizer/aws4.js +20 -20
- package/lib/authorizer/basic.js +12 -12
- package/lib/authorizer/bearer.js +12 -12
- package/lib/authorizer/digest.js +32 -31
- package/lib/authorizer/edgegrid.js +7 -7
- package/lib/authorizer/hawk.js +20 -20
- package/lib/authorizer/index.js +12 -8
- package/lib/authorizer/noauth.js +11 -11
- package/lib/authorizer/ntlm.js +43 -22
- package/lib/authorizer/oauth1.js +21 -21
- package/lib/authorizer/oauth2.js +12 -12
- package/lib/backpack/index.js +19 -19
- package/lib/requester/core-body-builder.js +16 -16
- package/lib/requester/core.js +25 -20
- package/lib/requester/dry-run.js +21 -21
- package/lib/requester/request-wrapper.js +6 -6
- package/lib/requester/requester-pool.js +1 -0
- package/lib/requester/requester.js +38 -43
- package/lib/runner/create-item-context.js +6 -6
- package/lib/runner/cursor.js +63 -63
- package/lib/runner/extensions/control.command.js +15 -14
- package/lib/runner/extensions/delay.command.js +12 -12
- package/lib/runner/extensions/event.command.js +33 -27
- package/lib/runner/extensions/http-request.command.js +20 -23
- package/lib/runner/extensions/item.command.js +6 -5
- package/lib/runner/extensions/request.command.js +12 -12
- package/lib/runner/extensions/waterfall.command.js +6 -6
- package/lib/runner/extract-runnable-items.js +25 -25
- package/lib/runner/index.js +20 -21
- package/lib/runner/instruction.js +14 -11
- package/lib/runner/replay-controller.js +6 -6
- package/lib/runner/request-helpers-postsend.js +5 -6
- package/lib/runner/request-helpers-presend.js +12 -16
- package/lib/runner/run.js +46 -41
- package/lib/runner/timings.js +7 -3
- package/lib/runner/util.js +10 -9
- package/lib/version.js +2 -2
- package/lib/visualizer/index.js +1 -1
- package/package.json +71 -75
package/lib/authorizer/index.js
CHANGED
|
@@ -24,7 +24,7 @@ AuthLoader = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Finds the Handler for an Auth type.
|
|
26
26
|
*
|
|
27
|
-
* @param name
|
|
27
|
+
* @param {String} name -
|
|
28
28
|
*
|
|
29
29
|
* @returns {AuthHandler}
|
|
30
30
|
*/
|
|
@@ -35,8 +35,8 @@ AuthLoader = {
|
|
|
35
35
|
/**
|
|
36
36
|
* Adds a Handler for use with given Auth type.
|
|
37
37
|
*
|
|
38
|
-
* @param Handler
|
|
39
|
-
* @param name
|
|
38
|
+
* @param {Object} Handler -
|
|
39
|
+
* @param {String} name -
|
|
40
40
|
*/
|
|
41
41
|
addHandler: function (Handler, name) {
|
|
42
42
|
if (!_.isFunction(Handler.init)) {
|
|
@@ -68,7 +68,7 @@ AuthLoader = {
|
|
|
68
68
|
/**
|
|
69
69
|
* Removes the Handler for the Auth type.
|
|
70
70
|
*
|
|
71
|
-
* @param name
|
|
71
|
+
* @param {String} name -
|
|
72
72
|
*/
|
|
73
73
|
removeHandler: function (name) {
|
|
74
74
|
AuthLoader.handlers[name] && (delete AuthLoader.handlers[name]);
|
|
@@ -96,8 +96,8 @@ _.forEach({
|
|
|
96
96
|
*
|
|
97
97
|
* @note This function does not take care of resolving variables.
|
|
98
98
|
*
|
|
99
|
-
* @param {Request} request
|
|
100
|
-
* @param done
|
|
99
|
+
* @param {Request} request -
|
|
100
|
+
* @param {Function} done -
|
|
101
101
|
*
|
|
102
102
|
* @returns {Request}
|
|
103
103
|
*/
|
|
@@ -120,8 +120,8 @@ authorizeRequest = function (request, done) {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
module.exports = {
|
|
123
|
-
AuthLoader
|
|
124
|
-
authorizeRequest
|
|
123
|
+
AuthLoader,
|
|
124
|
+
authorizeRequest
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
// Interface
|
|
@@ -202,6 +202,7 @@ module.exports = {
|
|
|
202
202
|
* - send the intermediate request
|
|
203
203
|
* - invoke the auth's [init]{@link AuthHandlerInterface#init} hook with the response of the intermediate request
|
|
204
204
|
* - invoke the auth's [pre]{@link AuthHandlerInterface#pre} hook
|
|
205
|
+
*
|
|
205
206
|
* @callback AuthHandlerInterface~authPreHookCallback
|
|
206
207
|
* @param {?Error} err
|
|
207
208
|
* @param {Boolean} success Defines whether the [pre]{@link AuthHandlerInterface#pre} hook was successful.
|
|
@@ -210,18 +211,21 @@ module.exports = {
|
|
|
210
211
|
|
|
211
212
|
/**
|
|
212
213
|
* This callback is called in the `init` hook of the auth handler
|
|
214
|
+
*
|
|
213
215
|
* @callback AuthHandlerInterface~authInitHookCallback
|
|
214
216
|
* @param {?Error} err
|
|
215
217
|
*/
|
|
216
218
|
|
|
217
219
|
/**
|
|
218
220
|
* This callback is called in the `sign` hook of the auth handler
|
|
221
|
+
*
|
|
219
222
|
* @callback AuthHandlerInterface~authSignHookCallback
|
|
220
223
|
* @param {?Error} err
|
|
221
224
|
*/
|
|
222
225
|
|
|
223
226
|
/**
|
|
224
227
|
* This callback is called in the `post` hook of the auth handler
|
|
228
|
+
*
|
|
225
229
|
* @callback AuthHandlerInterface~authPostHookCallback
|
|
226
230
|
* @param {?Error} err
|
|
227
231
|
* @param {Boolean} success Defines whether the request was successful or not. If not, it will be replayed.
|
package/lib/authorizer/noauth.js
CHANGED
|
@@ -19,9 +19,9 @@ module.exports = {
|
|
|
19
19
|
* Initializes an item (extracts parameters from intermediate requests if any, etc)
|
|
20
20
|
* before the actual authorization step.
|
|
21
21
|
*
|
|
22
|
-
* @param {AuthInterface} auth
|
|
23
|
-
* @param {Response} response
|
|
24
|
-
* @param {AuthHandlerInterface~authInitHookCallback} done
|
|
22
|
+
* @param {AuthInterface} auth -
|
|
23
|
+
* @param {Response} response -
|
|
24
|
+
* @param {AuthHandlerInterface~authInitHookCallback} done -
|
|
25
25
|
*/
|
|
26
26
|
init: function (auth, response, done) {
|
|
27
27
|
done(null);
|
|
@@ -31,8 +31,8 @@ module.exports = {
|
|
|
31
31
|
* Checks whether the given item has all the required parameters in its request.
|
|
32
32
|
* Sanitizes the auth parameters if needed.
|
|
33
33
|
*
|
|
34
|
-
* @param {AuthInterface} auth
|
|
35
|
-
* @param {AuthHandlerInterface~authPreHookCallback} done
|
|
34
|
+
* @param {AuthInterface} auth -
|
|
35
|
+
* @param {AuthHandlerInterface~authPreHookCallback} done -
|
|
36
36
|
*/
|
|
37
37
|
pre: function (auth, done) {
|
|
38
38
|
done(null, true);
|
|
@@ -41,9 +41,9 @@ module.exports = {
|
|
|
41
41
|
/**
|
|
42
42
|
* Verifies whether the request was successfully authorized after being sent.
|
|
43
43
|
*
|
|
44
|
-
* @param {AuthInterface} auth
|
|
45
|
-
* @param {Response} response
|
|
46
|
-
* @param {AuthHandlerInterface~authPostHookCallback} done
|
|
44
|
+
* @param {AuthInterface} auth -
|
|
45
|
+
* @param {Response} response -
|
|
46
|
+
* @param {AuthHandlerInterface~authPostHookCallback} done -
|
|
47
47
|
*/
|
|
48
48
|
post: function (auth, response, done) {
|
|
49
49
|
done(null, true);
|
|
@@ -52,9 +52,9 @@ module.exports = {
|
|
|
52
52
|
/**
|
|
53
53
|
* Signs a request.
|
|
54
54
|
*
|
|
55
|
-
* @param {AuthInterface} auth
|
|
56
|
-
* @param {Request} request
|
|
57
|
-
* @param {AuthHandlerInterface~authSignHookCallback} done
|
|
55
|
+
* @param {AuthInterface} auth -
|
|
56
|
+
* @param {Request} request -
|
|
57
|
+
* @param {AuthHandlerInterface~authSignHookCallback} done -
|
|
58
58
|
*/
|
|
59
59
|
sign: function (auth, request, done) {
|
|
60
60
|
return done();
|
package/lib/authorizer/ntlm.js
CHANGED
|
@@ -36,6 +36,7 @@ var ntlmUtil = require('httpntlm').ntlm,
|
|
|
36
36
|
* - Down-Level Logon name format `DOMAIN\USERNAME`
|
|
37
37
|
* - User Principal Name format `USERNAME@DOMAIN`
|
|
38
38
|
*
|
|
39
|
+
* @private
|
|
39
40
|
* @param {String} username - Username string to parse from
|
|
40
41
|
* @return {Object} - An object with `username` and `domain` fields, which are `strings`.
|
|
41
42
|
*/
|
|
@@ -56,7 +57,7 @@ function parseParametersFromUsername (username) {
|
|
|
56
57
|
// username should be either of the two formats, not both
|
|
57
58
|
if (dllParams.length > 1 && upnParams.length > 1) {
|
|
58
59
|
return {
|
|
59
|
-
username,
|
|
60
|
+
username: username,
|
|
60
61
|
domain: EMPTY
|
|
61
62
|
};
|
|
62
63
|
}
|
|
@@ -78,15 +79,36 @@ function parseParametersFromUsername (username) {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
return {
|
|
81
|
-
username,
|
|
82
|
+
username: username,
|
|
82
83
|
domain: EMPTY
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Check if `WWW-Authenticate` header has NTLM challenge.
|
|
89
|
+
*
|
|
90
|
+
* @private
|
|
91
|
+
* @param {*} headers - Postman headers instance
|
|
92
|
+
* @returns {Boolean}
|
|
93
|
+
*/
|
|
94
|
+
function hasNTLMChallenge (headers) {
|
|
95
|
+
// Case 1: multiple headers
|
|
96
|
+
// - WWW-Authenticate: NTLM
|
|
97
|
+
// - WWW-Authenticate: Negotiate
|
|
98
|
+
if (headers.has(WWW_AUTHENTICATE, NTLM) || headers.has(WWW_AUTHENTICATE, NEGOTIATE)) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Case 2: single header
|
|
103
|
+
// - WWW-Authenticate: Negotiate, NTLM
|
|
104
|
+
return String(headers.get(WWW_AUTHENTICATE)).includes(NTLM);
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
/**
|
|
87
108
|
* NTLM auth while authenticating requires negotiateMessage (type 1) and authenticateMessage (type 3) to be stored.
|
|
88
109
|
* Also it needs to know which stage is it in (INITIALIZED, T1_MSG_CREATED and T3_MSG_CREATED).
|
|
89
110
|
* After the first successful authentication, it just relies on the TCP connection, no other state is needed.
|
|
111
|
+
*
|
|
90
112
|
* @todo Currenty we don't close the connection. So there is no way to de-authenticate.
|
|
91
113
|
*
|
|
92
114
|
* @implements {AuthHandlerInterface}
|
|
@@ -112,9 +134,9 @@ module.exports = {
|
|
|
112
134
|
* Initializes an item (extracts parameters from intermediate requests if any, etc)
|
|
113
135
|
* before the actual authorization step.
|
|
114
136
|
*
|
|
115
|
-
* @param {AuthInterface} auth
|
|
116
|
-
* @param {Response} response
|
|
117
|
-
* @param {AuthHandlerInterface~authInitHookCallback} done
|
|
137
|
+
* @param {AuthInterface} auth -
|
|
138
|
+
* @param {Response} response -
|
|
139
|
+
* @param {AuthHandlerInterface~authInitHookCallback} done -
|
|
118
140
|
*/
|
|
119
141
|
init: function (auth, response, done) {
|
|
120
142
|
done(null);
|
|
@@ -124,8 +146,8 @@ module.exports = {
|
|
|
124
146
|
* Verifies whether the request has valid basic auth credentials (which is always).
|
|
125
147
|
* Sanitizes the auth parameters if needed.
|
|
126
148
|
*
|
|
127
|
-
* @param {AuthInterface} auth
|
|
128
|
-
* @param {AuthHandlerInterface~authPreHookCallback} done
|
|
149
|
+
* @param {AuthInterface} auth -
|
|
150
|
+
* @param {AuthHandlerInterface~authPreHookCallback} done -
|
|
129
151
|
*/
|
|
130
152
|
pre: function (auth, done) {
|
|
131
153
|
!auth.get(STATE) && auth.set(STATE, STATES.INITIALIZED);
|
|
@@ -136,9 +158,9 @@ module.exports = {
|
|
|
136
158
|
/**
|
|
137
159
|
* Verifies whether the basic auth succeeded.
|
|
138
160
|
*
|
|
139
|
-
* @param {AuthInterface} auth
|
|
140
|
-
* @param {Response} response
|
|
141
|
-
* @param {AuthHandlerInterface~authPostHookCallback} done
|
|
161
|
+
* @param {AuthInterface} auth -
|
|
162
|
+
* @param {Response} response -
|
|
163
|
+
* @param {AuthHandlerInterface~authPostHookCallback} done -
|
|
142
164
|
*/
|
|
143
165
|
post: function (auth, response, done) {
|
|
144
166
|
if (auth.get(DISABLE_RETRY_REQUEST)) {
|
|
@@ -170,15 +192,14 @@ module.exports = {
|
|
|
170
192
|
|
|
171
193
|
if (state === STATES.INITIALIZED) {
|
|
172
194
|
// Nothing to do if the server does not ask us for auth in the first place.
|
|
173
|
-
if (!(response.headers
|
|
174
|
-
response.headers.has(WWW_AUTHENTICATE, NEGOTIATE))) {
|
|
195
|
+
if (!hasNTLMChallenge(response.headers)) {
|
|
175
196
|
return done(null, true);
|
|
176
197
|
}
|
|
177
198
|
|
|
178
199
|
// Create a type 1 message to send to the server
|
|
179
200
|
negotiateMessage = ntlmUtil.createType1Message({
|
|
180
|
-
domain
|
|
181
|
-
workstation
|
|
201
|
+
domain,
|
|
202
|
+
workstation
|
|
182
203
|
});
|
|
183
204
|
|
|
184
205
|
// Add the type 1 message as the auth header
|
|
@@ -212,10 +233,10 @@ module.exports = {
|
|
|
212
233
|
}
|
|
213
234
|
|
|
214
235
|
authenticateMessage = ntlmUtil.createType3Message(challengeMessage, {
|
|
215
|
-
domain
|
|
216
|
-
workstation
|
|
217
|
-
username
|
|
218
|
-
password
|
|
236
|
+
domain,
|
|
237
|
+
workstation,
|
|
238
|
+
username,
|
|
239
|
+
password
|
|
219
240
|
});
|
|
220
241
|
|
|
221
242
|
// Now create the type 3 message, and add it to the request
|
|
@@ -237,14 +258,14 @@ module.exports = {
|
|
|
237
258
|
/**
|
|
238
259
|
* Signs a request.
|
|
239
260
|
*
|
|
240
|
-
* @param {AuthInterface} auth
|
|
241
|
-
* @param {Request} request
|
|
242
|
-
* @param {AuthHandlerInterface~authSignHookCallback} done
|
|
261
|
+
* @param {AuthInterface} auth -
|
|
262
|
+
* @param {Request} request -
|
|
263
|
+
* @param {AuthHandlerInterface~authSignHookCallback} done -
|
|
243
264
|
*/
|
|
244
265
|
sign: function (auth, request, done) {
|
|
245
266
|
var ntlmHeader = auth.get(NTLM_HEADER);
|
|
246
267
|
|
|
247
|
-
request.removeHeader(AUTHORIZATION, {ignoreCase: true});
|
|
268
|
+
request.removeHeader(AUTHORIZATION, { ignoreCase: true });
|
|
248
269
|
ntlmHeader && request.addHeader({
|
|
249
270
|
key: AUTHORIZATION,
|
|
250
271
|
value: ntlmHeader,
|
package/lib/authorizer/oauth1.js
CHANGED
|
@@ -244,9 +244,9 @@ module.exports = {
|
|
|
244
244
|
* Initializes an item (extracts parameters from intermediate requests if any, etc)
|
|
245
245
|
* before the actual authorization step.
|
|
246
246
|
*
|
|
247
|
-
* @param {AuthInterface} auth
|
|
248
|
-
* @param {Response} response
|
|
249
|
-
* @param {AuthHandlerInterface~authInitHookCallback} done
|
|
247
|
+
* @param {AuthInterface} auth -
|
|
248
|
+
* @param {Response} response -
|
|
249
|
+
* @param {AuthHandlerInterface~authInitHookCallback} done -
|
|
250
250
|
*/
|
|
251
251
|
init: function (auth, response, done) {
|
|
252
252
|
done(null);
|
|
@@ -256,8 +256,8 @@ module.exports = {
|
|
|
256
256
|
* Verifies whether the request has valid basic auth credentials (which is always).
|
|
257
257
|
* Sanitizes the auth parameters if needed.
|
|
258
258
|
*
|
|
259
|
-
* @param {AuthInterface} auth
|
|
260
|
-
* @param {AuthHandlerInterface~authPreHookCallback} done
|
|
259
|
+
* @param {AuthInterface} auth -
|
|
260
|
+
* @param {AuthHandlerInterface~authPreHookCallback} done -
|
|
261
261
|
*/
|
|
262
262
|
pre: function (auth, done) {
|
|
263
263
|
done(null, true);
|
|
@@ -266,9 +266,9 @@ module.exports = {
|
|
|
266
266
|
/**
|
|
267
267
|
* Verifies whether the basic auth succeeded.
|
|
268
268
|
*
|
|
269
|
-
* @param {AuthInterface} auth
|
|
270
|
-
* @param {Response} response
|
|
271
|
-
* @param {AuthHandlerInterface~authPostHookCallback} done
|
|
269
|
+
* @param {AuthInterface} auth -
|
|
270
|
+
* @param {Response} response -
|
|
271
|
+
* @param {AuthHandlerInterface~authPostHookCallback} done -
|
|
272
272
|
*/
|
|
273
273
|
post: function (auth, response, done) {
|
|
274
274
|
done(null, true);
|
|
@@ -300,12 +300,12 @@ module.exports = {
|
|
|
300
300
|
disableUrlEncoding = protocolProfileBehavior && protocolProfileBehavior.disableUrlEncoding;
|
|
301
301
|
|
|
302
302
|
signatureParams = [
|
|
303
|
-
{system: true, key: OAUTH1_PARAMS.oauthConsumerKey, value: params.consumerKey},
|
|
304
|
-
{system: true, key: OAUTH1_PARAMS.oauthToken, value: params.token},
|
|
305
|
-
{system: true, key: OAUTH1_PARAMS.oauthSignatureMethod, value: params.signatureMethod},
|
|
306
|
-
{system: true, key: OAUTH1_PARAMS.oauthTimestamp, value: params.timestamp},
|
|
307
|
-
{system: true, key: OAUTH1_PARAMS.oauthNonce, value: params.nonce},
|
|
308
|
-
{system: true, key: OAUTH1_PARAMS.oauthVersion, value: params.version}
|
|
303
|
+
{ system: true, key: OAUTH1_PARAMS.oauthConsumerKey, value: params.consumerKey },
|
|
304
|
+
{ system: true, key: OAUTH1_PARAMS.oauthToken, value: params.token },
|
|
305
|
+
{ system: true, key: OAUTH1_PARAMS.oauthSignatureMethod, value: params.signatureMethod },
|
|
306
|
+
{ system: true, key: OAUTH1_PARAMS.oauthTimestamp, value: params.timestamp },
|
|
307
|
+
{ system: true, key: OAUTH1_PARAMS.oauthNonce, value: params.nonce },
|
|
308
|
+
{ system: true, key: OAUTH1_PARAMS.oauthVersion, value: params.version }
|
|
309
309
|
];
|
|
310
310
|
|
|
311
311
|
// bodyHash, callback and verifier parameters are part of extensions of the original OAuth1 spec.
|
|
@@ -313,15 +313,15 @@ module.exports = {
|
|
|
313
313
|
// Otherwise it causes problem for servers that don't support the respective OAuth1 extensions.
|
|
314
314
|
// Issue: https://github.com/postmanlabs/postman-app-support/issues/8737
|
|
315
315
|
if (params.bodyHash) {
|
|
316
|
-
signatureParams.push({system: true, key: OAUTH1_PARAMS.oauthBodyHash, value: params.bodyHash});
|
|
316
|
+
signatureParams.push({ system: true, key: OAUTH1_PARAMS.oauthBodyHash, value: params.bodyHash });
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
if (params.callback) {
|
|
320
|
-
signatureParams.push({system: true, key: OAUTH1_PARAMS.oauthCallback, value: params.callback});
|
|
320
|
+
signatureParams.push({ system: true, key: OAUTH1_PARAMS.oauthCallback, value: params.callback });
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
if (params.verifier) {
|
|
324
|
-
signatureParams.push({system: true, key: OAUTH1_PARAMS.oauthVerifier, value: params.verifier});
|
|
324
|
+
signatureParams.push({ system: true, key: OAUTH1_PARAMS.oauthVerifier, value: params.verifier });
|
|
325
325
|
}
|
|
326
326
|
|
|
327
327
|
// filter empty signature parameters
|
|
@@ -364,7 +364,7 @@ module.exports = {
|
|
|
364
364
|
updateQueryParamEncoding(request, url);
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
signatureParams.push({system: true, key: OAUTH1_PARAMS.oauthSignature, value: signature});
|
|
367
|
+
signatureParams.push({ system: true, key: OAUTH1_PARAMS.oauthSignature, value: signature });
|
|
368
368
|
|
|
369
369
|
// Add signature params to the request. The OAuth specification says
|
|
370
370
|
// that we should add parameters in the following order of preference:
|
|
@@ -409,9 +409,9 @@ module.exports = {
|
|
|
409
409
|
/**
|
|
410
410
|
* Signs a request.
|
|
411
411
|
*
|
|
412
|
-
* @param {AuthInterface} auth
|
|
413
|
-
* @param {Request} request
|
|
414
|
-
* @param {AuthHandlerInterface~authSignHookCallback} done
|
|
412
|
+
* @param {AuthInterface} auth -
|
|
413
|
+
* @param {Request} request -
|
|
414
|
+
* @param {AuthHandlerInterface~authSignHookCallback} done -
|
|
415
415
|
*/
|
|
416
416
|
sign: function (auth, request, done) {
|
|
417
417
|
var self = this,
|
package/lib/authorizer/oauth2.js
CHANGED
|
@@ -42,9 +42,9 @@ module.exports = {
|
|
|
42
42
|
* Initializes an item (extracts parameters from intermediate requests if any, etc)
|
|
43
43
|
* before the actual authorization step.
|
|
44
44
|
*
|
|
45
|
-
* @param {AuthInterface} auth
|
|
46
|
-
* @param {Response} response
|
|
47
|
-
* @param {AuthHandlerInterface~authInitHookCallback} done
|
|
45
|
+
* @param {AuthInterface} auth -
|
|
46
|
+
* @param {Response} response -
|
|
47
|
+
* @param {AuthHandlerInterface~authInitHookCallback} done -
|
|
48
48
|
*/
|
|
49
49
|
init: function (auth, response, done) {
|
|
50
50
|
done(null);
|
|
@@ -54,8 +54,8 @@ module.exports = {
|
|
|
54
54
|
* Verifies whether the request has valid basic auth credentials (which is always).
|
|
55
55
|
* Sanitizes the auth parameters if needed.
|
|
56
56
|
*
|
|
57
|
-
* @param {AuthInterface} auth
|
|
58
|
-
* @param {AuthHandlerInterface~authPreHookCallback} done
|
|
57
|
+
* @param {AuthInterface} auth -
|
|
58
|
+
* @param {AuthHandlerInterface~authPreHookCallback} done -
|
|
59
59
|
*/
|
|
60
60
|
pre: function (auth, done) {
|
|
61
61
|
done(null, Boolean(auth.get('accessToken')));
|
|
@@ -64,9 +64,9 @@ module.exports = {
|
|
|
64
64
|
/**
|
|
65
65
|
* Verifies whether the basic auth succeeded.
|
|
66
66
|
*
|
|
67
|
-
* @param {AuthInterface} auth
|
|
68
|
-
* @param {Response} response
|
|
69
|
-
* @param {AuthHandlerInterface~authPostHookCallback} done
|
|
67
|
+
* @param {AuthInterface} auth -
|
|
68
|
+
* @param {Response} response -
|
|
69
|
+
* @param {AuthHandlerInterface~authPostHookCallback} done -
|
|
70
70
|
*/
|
|
71
71
|
post: function (auth, response, done) {
|
|
72
72
|
done(null, true);
|
|
@@ -75,9 +75,9 @@ module.exports = {
|
|
|
75
75
|
/**
|
|
76
76
|
* Signs a request.
|
|
77
77
|
*
|
|
78
|
-
* @param {AuthInterface} auth
|
|
79
|
-
* @param {Request} request
|
|
80
|
-
* @param {AuthHandlerInterface~authSignHookCallback} done
|
|
78
|
+
* @param {AuthInterface} auth -
|
|
79
|
+
* @param {Request} request -
|
|
80
|
+
* @param {AuthHandlerInterface~authSignHookCallback} done -
|
|
81
81
|
*/
|
|
82
82
|
sign: function (auth, request, done) {
|
|
83
83
|
var params = auth.get(OAUTH2_PARAMETERS),
|
|
@@ -110,7 +110,7 @@ module.exports = {
|
|
|
110
110
|
// clean conflicting headers and query params
|
|
111
111
|
// @todo: we should be able to get conflicting params from auth manifest
|
|
112
112
|
// and clear them before the sign step for any auth
|
|
113
|
-
request.removeHeader(AUTHORIZATION, {ignoreCase: true});
|
|
113
|
+
request.removeHeader(AUTHORIZATION, { ignoreCase: true });
|
|
114
114
|
request.removeQueryParams([ACCESS_TOKEN]);
|
|
115
115
|
|
|
116
116
|
if (params.addTokenTo === QUERY_PARAMS) {
|
package/lib/backpack/index.js
CHANGED
|
@@ -5,9 +5,9 @@ var _ = require('lodash'),
|
|
|
5
5
|
/**
|
|
6
6
|
* ensure the specified keys are functions in subject
|
|
7
7
|
*
|
|
8
|
-
* @param {Object} subject
|
|
9
|
-
* @param {Array} expectations
|
|
10
|
-
* @param {Array=} [defaults]
|
|
8
|
+
* @param {Object} subject -
|
|
9
|
+
* @param {Array} expectations -
|
|
10
|
+
* @param {Array=} [defaults] -
|
|
11
11
|
* @returns {Object}
|
|
12
12
|
*/
|
|
13
13
|
meetExpectations = function (subject, expectations, defaults) {
|
|
@@ -24,24 +24,24 @@ module.exports = backpack = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Ensures that the given argument is a callable.
|
|
26
26
|
*
|
|
27
|
-
* @param {*} arg
|
|
28
|
-
* @param {Object=} ctx
|
|
27
|
+
* @param {*} arg -
|
|
28
|
+
* @param {Object=} ctx -
|
|
29
29
|
* @returns {boolean|*}
|
|
30
30
|
*/
|
|
31
|
-
ensure
|
|
31
|
+
ensure (arg, ctx) {
|
|
32
32
|
return (typeof arg === 'function') && (ctx ? arg.bind(ctx) : arg) || undefined;
|
|
33
33
|
},
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* accept the callback parameter and convert it into a consistent object interface
|
|
37
37
|
*
|
|
38
|
-
* @param {Function|Object} cb
|
|
39
|
-
* @param {Array}
|
|
38
|
+
* @param {Function|Object} cb -
|
|
39
|
+
* @param {Array} expect -
|
|
40
40
|
* @returns {Object}
|
|
41
41
|
*
|
|
42
42
|
* @todo - write tests
|
|
43
43
|
*/
|
|
44
|
-
normalise
|
|
44
|
+
normalise (cb, expect) {
|
|
45
45
|
if (_.isFunction(cb) && cb.__normalised) {
|
|
46
46
|
return meetExpectations(cb, expect);
|
|
47
47
|
}
|
|
@@ -86,13 +86,13 @@ module.exports = backpack = {
|
|
|
86
86
|
* Convert a callback into a function that is called multiple times and the callback is actually called when a set
|
|
87
87
|
* of flags are set to true
|
|
88
88
|
*
|
|
89
|
-
* @param {Array} flags
|
|
90
|
-
* @param {Function} callback
|
|
91
|
-
* @param {Array} args
|
|
92
|
-
* @param {Number} ms
|
|
89
|
+
* @param {Array} flags -
|
|
90
|
+
* @param {Function} callback -
|
|
91
|
+
* @param {Array} args -
|
|
92
|
+
* @param {Number} ms -
|
|
93
93
|
* @returns {Function}
|
|
94
94
|
*/
|
|
95
|
-
multiback
|
|
95
|
+
multiback (flags, callback, args, ms) {
|
|
96
96
|
var status = {},
|
|
97
97
|
sealed;
|
|
98
98
|
|
|
@@ -116,7 +116,7 @@ module.exports = backpack = {
|
|
|
116
116
|
// if any flag is not defined, we exit. when all flags hold a value, we know that the end callback has to be
|
|
117
117
|
// executed.
|
|
118
118
|
for (var i = 0, ii = flags.length; i < ii; i++) {
|
|
119
|
-
if (!
|
|
119
|
+
if (!Object.hasOwnProperty.call(status, flags[i])) { return; }
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
sealed = true;
|
|
@@ -128,14 +128,14 @@ module.exports = backpack = {
|
|
|
128
128
|
/**
|
|
129
129
|
* Ensures that a callback is executed within a specific time.
|
|
130
130
|
*
|
|
131
|
-
* @param {Function} callback
|
|
132
|
-
* @param {Number=} [ms]
|
|
133
|
-
* @param {Object=} [scope]
|
|
131
|
+
* @param {Function} callback -
|
|
132
|
+
* @param {Number=} [ms] -
|
|
133
|
+
* @param {Object=} [scope] -
|
|
134
134
|
* @param {Function=} [when] - function executed right before callback is called with timeout. one can do cleanup
|
|
135
135
|
* stuff here
|
|
136
136
|
* @returns {Function}
|
|
137
137
|
*/
|
|
138
|
-
timeback
|
|
138
|
+
timeback (callback, ms, scope, when) {
|
|
139
139
|
ms = Number(ms);
|
|
140
140
|
|
|
141
141
|
// if np callback time is specified, just return the callback function and exit. this is because we do need to
|
|
@@ -32,11 +32,11 @@ var _ = require('lodash'),
|
|
|
32
32
|
* @type {Object}
|
|
33
33
|
*/
|
|
34
34
|
CONTENT_TYPE_LANGUAGE = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
html: 'text/html',
|
|
36
|
+
text: 'text/plain',
|
|
37
|
+
json: 'application/json',
|
|
38
|
+
javascript: 'application/javascript',
|
|
39
|
+
xml: 'application/xml'
|
|
40
40
|
},
|
|
41
41
|
|
|
42
42
|
STRING = 'string',
|
|
@@ -54,8 +54,8 @@ var _ = require('lodash'),
|
|
|
54
54
|
* @todo Add this helper in Collection SDK.
|
|
55
55
|
*
|
|
56
56
|
* @private
|
|
57
|
-
* @param {HeaderList} headers
|
|
58
|
-
* @param {String} name
|
|
57
|
+
* @param {HeaderList} headers -
|
|
58
|
+
* @param {String} name -
|
|
59
59
|
* @returns {Header|undefined}
|
|
60
60
|
*/
|
|
61
61
|
oneNormalizedHeader = function oneNormalizedHeader (headers, name) {
|
|
@@ -102,7 +102,7 @@ urlEncodedBodyReducer = function (form, param) {
|
|
|
102
102
|
value = param.value;
|
|
103
103
|
|
|
104
104
|
// add the parameter to the form while accounting for duplicate values
|
|
105
|
-
if (!
|
|
105
|
+
if (!Object.hasOwnProperty.call(form, key)) {
|
|
106
106
|
form[key] = value;
|
|
107
107
|
|
|
108
108
|
return form;
|
|
@@ -186,7 +186,7 @@ module.exports = {
|
|
|
186
186
|
* @param {Request} [request] - request object
|
|
187
187
|
* @returns {Object}
|
|
188
188
|
*/
|
|
189
|
-
raw
|
|
189
|
+
raw (content, request) {
|
|
190
190
|
var contentLanguage = _.get(request, 'body.options.raw.language', 'text');
|
|
191
191
|
|
|
192
192
|
// Add `Content-Type` header from body options if not set already
|
|
@@ -211,7 +211,7 @@ module.exports = {
|
|
|
211
211
|
* @param {Object} content - request body content
|
|
212
212
|
* @returns {Object}
|
|
213
213
|
*/
|
|
214
|
-
urlencoded
|
|
214
|
+
urlencoded (content) {
|
|
215
215
|
if (content && _.isFunction(content.all)) { content = content.all(); } // flatten the body content
|
|
216
216
|
|
|
217
217
|
return {
|
|
@@ -223,7 +223,7 @@ module.exports = {
|
|
|
223
223
|
* @param {Object} content - request body content
|
|
224
224
|
* @returns {Object}
|
|
225
225
|
*/
|
|
226
|
-
formdata
|
|
226
|
+
formdata (content) {
|
|
227
227
|
if (content && _.isFunction(content.all)) { content = content.all(); } // flatten the body content
|
|
228
228
|
|
|
229
229
|
return {
|
|
@@ -235,7 +235,7 @@ module.exports = {
|
|
|
235
235
|
* @param {Object} content - request body content
|
|
236
236
|
* @returns {Object}
|
|
237
237
|
*/
|
|
238
|
-
file
|
|
238
|
+
file (content) {
|
|
239
239
|
return {
|
|
240
240
|
body: content && content.content
|
|
241
241
|
};
|
|
@@ -246,7 +246,7 @@ module.exports = {
|
|
|
246
246
|
* @param {Request} [request] - Request object
|
|
247
247
|
* @returns {Object}
|
|
248
248
|
*/
|
|
249
|
-
graphql
|
|
249
|
+
graphql (content, request) {
|
|
250
250
|
var body;
|
|
251
251
|
|
|
252
252
|
// implicitly add `Content-Type` header if not set already
|
|
@@ -278,15 +278,15 @@ module.exports = {
|
|
|
278
278
|
// stringified content. This avoids parsing the variables.
|
|
279
279
|
body = [];
|
|
280
280
|
|
|
281
|
-
if (
|
|
281
|
+
if (Object.hasOwnProperty.call(content, 'query') && (typeof content.query === STRING)) {
|
|
282
282
|
body.push('"query":' + JSON.stringify(content.query));
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
if (
|
|
285
|
+
if (Object.hasOwnProperty.call(content, 'operationName') && (typeof content.operationName === STRING)) {
|
|
286
286
|
body.push('"operationName":' + JSON.stringify(content.operationName));
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
if (
|
|
289
|
+
if (Object.hasOwnProperty.call(content, 'variables') && (typeof content.variables === STRING) &&
|
|
290
290
|
// even though users are free to send even malformed json string, the case of empty string has to be
|
|
291
291
|
// specially disallowed since in most default cases if a text editor is used to accept this data, it will
|
|
292
292
|
// send a blank string for an empty text-editor state and that would be an error flow. That implies majority
|