-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmappersmith.js
123 lines (111 loc) · 3.89 KB
/
mappersmith.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* global VERSION */
import ClientBuilder from './client-builder'
import { assign } from './utils'
export const version = VERSION
export const configs = {
context: {},
middleware: [],
Promise: typeof Promise === 'function' ? Promise : null,
fetch: typeof fetch === 'function' ? fetch : null, // eslint-disable-line no-undef
/**
* The maximum amount of executions allowed before it is considered an infinite loop.
* In the response phase of middleware, it's possible to execute a function called "renew",
* which can be used to rerun the middleware stack. This feature is useful in some scenarios,
* for example, re-fetching an invalid access token.
* This configuration is used to detect infinite loops, don't increase this value too much
* @default 2
*/
maxMiddlewareStackExecutionAllowed: 2,
/**
* Gateway implementation, it defaults to "lib/gateway/xhr" for browsers and
* "lib/gateway/http" for node
*/
gateway: null,
gatewayConfigs: {
/**
* Setting this option will fake PUT, PATCH and DELETE requests with a HTTP POST. It will
* add "_method" and "X-HTTP-Method-Override" with the original requested method
* @default false
*/
emulateHTTP: false,
/**
* Setting this option will return HTTP status 408 (Request Timeout) when a request times
* out. When "false", HTTP status 400 (Bad Request) will be used instead.
* @default false
*/
enableHTTP408OnTimeouts: false,
XHR: {
/**
* Indicates whether or not cross-site Access-Control requests should be made using credentials
* such as cookies, authorization headers or TLS client certificates.
* Setting withCredentials has no effect on same-site requests
*
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
*
* @default false
*/
withCredentials: false,
/**
* For additional configurations to the XMLHttpRequest object.
* @param {XMLHttpRequest} xhr
* @default null
*/
configure: null
},
HTTP: {
/**
* Enable this option to evaluate timeout on entire request durations,
* including DNS resolution and socket connection.
*
* See original nodejs issue: https://github.com/nodejs/node/pull/8101
*
* @default false
*/
useSocketConnectionTimeout: false,
/**
* For additional configurations to the http/https module
* For http: https://nodejs.org/api/http.html#http_http_request_options_callback
* For https: https://nodejs.org/api/https.html#https_https_request_options_callback
*
* @param {object} options
* @default null
*/
configure: null,
onRequestWillStart: null,
onRequestSocketAssigned: null,
onSocketLookup: null,
onSocketConnect: null,
onSocketSecureConnect: null,
onResponseReadable: null,
onResponseEnd: null
},
Fetch: {
/**
* Indicates whether the user agent should send cookies from the other domain in the case of cross-origin
* requests. This is similar to XHR’s withCredentials flag, but with three available values (instead of two):
*
* "omit": Never send cookies.
* "same-origin": Only send cookies if the URL is on the same origin as the calling script.
* "include": Always send cookies, even for cross-origin calls.
*
* https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
*
* @default "omit"
*/
credentials: 'omit'
}
}
}
/**
* @param {Object} context
*/
export const setContext = (context) => {
configs.context = assign(configs.context, context)
}
/**
* @param {Object} manifest
*/
export default function forge (manifest) {
const GatewayClassFactory = () => configs.gateway
return new ClientBuilder(manifest, GatewayClassFactory, configs).build()
}