1
1
<!--
2
- Copyright 2019 Adobe. All rights reserved.
2
+ Copyright 2021 Adobe. All rights reserved.
3
3
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
you may not use this file except in compliance with the License. You may obtain a copy
5
5
of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -10,12 +10,20 @@ OF ANY KIND, either express or implied. See the License for the specific languag
10
10
governing permissions and limitations under the License.
11
11
-->
12
12
13
+ <!--
14
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15
+ DO NOT update README.md, it is generated.
16
+ Modify 'docs/readme_template.md', then run `npm run generate-docs`.
17
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18
+ -->
19
+
13
20
[ ![ Version] ( https://img.shields.io/npm/v/@adobe/aio-lib-core-networking.svg )] ( https://npmjs.org/package/@adobe/aio-lib-core-networking )
14
21
[ ![ Downloads/week] ( https://img.shields.io/npm/dw/@adobe/aio-lib-core-networking.svg )] ( https://npmjs.org/package/@adobe/aio-lib-core-networking )
15
22
[ ![ Node.js CI] ( https://github.com/adobe/aio-lib-core-networking/actions/workflows/node.js.yml/badge.svg )] ( https://github.com/adobe/aio-lib-core-networking/actions/workflows/node.js.yml )
16
23
[ ![ License] ( https://img.shields.io/badge/License-Apache%202.0-blue.svg )] ( https://opensource.org/licenses/Apache-2.0 )
17
24
[ ![ Codecov Coverage] ( https://img.shields.io/codecov/c/github/adobe/aio-lib-core-networking/master.svg?style=flat-square )] ( https://codecov.io/gh/adobe/aio-lib-core-networking/ )
18
25
26
+
19
27
# Adobe I/O Core Networking Lib
20
28
21
29
### Installing
@@ -28,15 +36,17 @@ $ npm install @adobe/aio-lib-core-networking
28
36
1 ) Initialize the SDK
29
37
30
38
``` javascript
31
- const fetchRetry = require (' @adobe/aio-lib-core-networking' )
32
-
39
+ const { HttpExponentialBackoff , createFetch } = require (' @adobe/aio-lib-core-networking' )
40
+ const fetchRetry = new HttpExponentialBackoff ()
41
+ const proxyFetch = createFetch ()
33
42
```
34
43
35
44
2 ) Call methods using the initialized SDK
36
45
37
46
``` javascript
38
47
39
- const fetchRetry = require (' @adobe/aio-lib-core-networking' )
48
+ const { HttpExponentialBackoff , createFetch } = require (' @adobe/aio-lib-core-networking' )
49
+ const fetchRetry = new HttpExponentialBackoff ()
40
50
async function sdkTest () {
41
51
42
52
return new Promise ((resolve , reject ) => {
@@ -54,44 +64,154 @@ async function sdkTest() {
54
64
})
55
65
}
56
66
57
- ```
58
-
59
- <a name =" module_@adobe/aio-lib-core-networking " ></a >
60
-
61
- ## @adobe/aio-lib-core-networking
62
-
63
- * [ @adobe/aio-lib-core-networking ] ( #module_@adobe/aio-lib-core-networking )
64
- * [ ~ HttpExponentialBackoff] ( #module_@adobe/aio-lib-core-networking..HttpExponentialBackoff )
65
- * [ .exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay)] ( #module_@adobe/aio-lib-core-networking..HttpExponentialBackoff+exponentialBackoff ) ⇒ <code >Promise.< ; Response> ; </code >
67
+ let proxyFetch
68
+ // this will get the proxy settings from the the HTTP_PROXY or HTTPS_PROXY environment variables, if set
69
+ proxyFetch = createFetch ()
66
70
67
- <a name =" module_@adobe/aio-lib-core-networking..HttpExponentialBackoff " ></a >
71
+ // this will use the passed in proxy settings. Embed basic auth in the url, if required
72
+ proxyFetch = createFetch ({ proxyUrl: ' http://my.proxy:8080' })
68
73
69
- ### Working of HttpExponentialBackoff
74
+ // if the proxy settings are not passed in, and not available in the HTTP_PROXY or HTTPS_PROXY environment variables, it falls back to a simple fetch
75
+ const simpleFetch = createFetch ()
76
+ ```
70
77
71
- ![ image not available ] ( docs/sequenceDiagram.jpeg?s=50 )
78
+ ## Classes
72
79
73
- ### @adobe/aio-lib-core-networking ~ HttpExponentialBackoff
80
+ <dl >
81
+ <dt ><a href =" #HttpExponentialBackoff " >HttpExponentialBackoff</a ></dt >
82
+ <dd ><p >This class provides methods to implement fetch with retries.
83
+ The retries use exponential backoff strategy
84
+ with defaults set to max of 3 retries and initial Delay as 100ms</p >
85
+ </dd >
86
+ <dt ><a href =" #ProxyFetch " >ProxyFetch</a ></dt >
87
+ <dd ><p >This provides a wrapper for fetch that facilitates proxy auth authorization.</p >
88
+ </dd >
89
+ </dl >
90
+
91
+ ## Functions
92
+
93
+ <dl >
94
+ <dt ><a href =" #createFetch " >createFetch([proxyAuthOptions])</a > ⇒ <code >function</code ></dt >
95
+ <dd ><p >Return the appropriate Fetch function depending on proxy settings.</p >
96
+ </dd >
97
+ </dl >
98
+
99
+ ## Typedefs
100
+
101
+ <dl >
102
+ <dt ><a href =" #RetryOptions " >RetryOptions</a > : <code >object</code ></dt >
103
+ <dd ><p >Fetch Retry Options</p >
104
+ </dd >
105
+ <dt ><a href =" #ProxyAuthOptions " >ProxyAuthOptions</a > : <code >object</code ></dt >
106
+ <dd ><p >Proxy Auth Options</p >
107
+ </dd >
108
+ </dl >
109
+
110
+ <a name =" HttpExponentialBackoff " ></a >
111
+
112
+ ## HttpExponentialBackoff
74
113
This class provides methods to implement fetch with retries.
75
114
The retries use exponential backoff strategy
76
115
with defaults set to max of 3 retries and initial Delay as 100ms
77
116
78
- ** Kind** : inner class of [ < code > @ adobe/aio-lib-core-networking </ code > ] ( #module_@adobe/aio-lib-core-networking )
79
- <a name =" module_@adobe/aio-lib-core-networking.. HttpExponentialBackoff+exponentialBackoff" ></a >
117
+ ** Kind** : global class
118
+ <a name =" HttpExponentialBackoff+exponentialBackoff " ></a >
80
119
81
- #### httpExponentialBackoff.exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay) ⇒ <code >Promise.< ; Response> ; </code >
120
+ ### httpExponentialBackoff.exponentialBackoff(url, requestOptions, [ retryOptions] , [ retryOn] , [ retryDelay] ) ⇒ <code >Promise.< ; Response> ; </code >
82
121
This function will retry connecting to a url end-point, with
83
122
exponential backoff. Returns a Promise.
84
123
85
- ** Kind** : instance method of [ <code >HttpExponentialBackoff</code >] ( #module_@adobe/aio-lib-core-networking.. HttpExponentialBackoff )
124
+ ** Kind** : instance method of [ <code >HttpExponentialBackoff</code >] ( #HttpExponentialBackoff )
86
125
** Returns** : <code >Promise.< ; Response> ; </code > - Promise object representing the http response
87
126
88
127
| Param | Type | Description |
89
128
| --- | --- | --- |
90
129
| url | <code >string</code > | endpoint url |
91
- | requestOptions | <code >object</code > | request options which includes the HTTP method, headers, timeout, etc. |
92
- | retryOptions | <code >object</code > | retry options with options being maxRetries and initialDelayInMillis |
93
- | retryOn | <code >function</code > \| <code >Array</code > | Optional Function or Array. If provided, will be used instead of the default |
94
- | retryDelay | <code >function</code > \| <code >number</code > | Optional Function or number. If provided, will be used instead of the default |
130
+ | requestOptions | <code >object</code > \| <code >Request</code > | request options |
131
+ | [ retryOptions] | [ <code >RetryOptions</code >] ( #RetryOptions ) | (optional) retry options |
132
+ | [ retryOn] | <code >function</code > \| <code >Array</code > | (optional) Function or Array. If provided, will be used instead of the default |
133
+ | [ retryDelay] | <code >function</code > \| <code >number</code > | (optional) Function or number. If provided, will be used instead of the default |
134
+
135
+ <a name =" ProxyFetch " ></a >
136
+
137
+ ## ProxyFetch
138
+ This provides a wrapper for fetch that facilitates proxy auth authorization.
139
+
140
+ ** Kind** : global class
141
+
142
+ * [ ProxyFetch] ( #ProxyFetch )
143
+ * [ new ProxyFetch(authOptions)] ( #new_ProxyFetch_new )
144
+ * [ .proxyAgent()] ( #ProxyFetch+proxyAgent ) ⇒ <code >http.Agent</code >
145
+ * [ .fetch(resource, options)] ( #ProxyFetch+fetch ) ⇒ <code >Promise.< ; Response> ; </code >
146
+
147
+ <a name =" new_ProxyFetch_new " ></a >
148
+
149
+ ### new ProxyFetch(authOptions)
150
+ Initialize this class with Proxy auth options
151
+
152
+
153
+ | Param | Type | Description |
154
+ | --- | --- | --- |
155
+ | authOptions | [ <code >ProxyAuthOptions</code >] ( #ProxyAuthOptions ) | the auth options to connect with |
156
+
157
+ <a name =" ProxyFetch+proxyAgent " ></a >
158
+
159
+ ### proxyFetch.proxyAgent() ⇒ <code >http.Agent</code >
160
+ Returns the http.Agent used for this proxy
161
+
162
+ ** Kind** : instance method of [ <code >ProxyFetch</code >] ( #ProxyFetch )
163
+ ** Returns** : <code >http.Agent</code > - a http.Agent for basic auth proxy
164
+ <a name =" ProxyFetch+fetch " ></a >
165
+
166
+ ### proxyFetch.fetch(resource, options) ⇒ <code >Promise.< ; Response> ; </code >
167
+ Fetch function, using the configured NTLM Auth options.
168
+
169
+ ** Kind** : instance method of [ <code >ProxyFetch</code >] ( #ProxyFetch )
170
+ ** Returns** : <code >Promise.< ; Response> ; </code > - Promise object representing the http response
171
+
172
+ | Param | Type | Description |
173
+ | --- | --- | --- |
174
+ | resource | <code >string</code > \| <code >Request</code > | the url or Request object to fetch from |
175
+ | options | <code >object</code > | the fetch options |
176
+
177
+ <a name =" createFetch " ></a >
178
+
179
+ ## createFetch([ proxyAuthOptions] ) ⇒ <code >function</code >
180
+ Return the appropriate Fetch function depending on proxy settings.
181
+
182
+ ** Kind** : global function
183
+ ** Returns** : <code >function</code > - the Fetch API function
184
+
185
+ | Param | Type | Description |
186
+ | --- | --- | --- |
187
+ | [ proxyAuthOptions] | [ <code >ProxyAuthOptions</code >] ( #ProxyAuthOptions ) | the proxy auth options |
188
+
189
+ <a name =" RetryOptions " ></a >
190
+
191
+ ## RetryOptions : <code >object</code >
192
+ Fetch Retry Options
193
+
194
+ ** Kind** : global typedef
195
+ ** Properties**
196
+
197
+ | Name | Type | Description |
198
+ | --- | --- | --- |
199
+ | maxRetries | <code >number</code > | the maximum number of retries to try (default:3) |
200
+ | initialDelayInMillis | <code >number</code > | the initial delay in milliseconds (default:100ms) |
201
+ | proxy | [ <code >ProxyAuthOptions</code >] ( #ProxyAuthOptions ) | the (optional) proxy auth options |
202
+
203
+ <a name =" ProxyAuthOptions " ></a >
204
+
205
+ ## ProxyAuthOptions : <code >object</code >
206
+ Proxy Auth Options
207
+
208
+ ** Kind** : global typedef
209
+ ** Properties**
210
+
211
+ | Name | Type | Description |
212
+ | --- | --- | --- |
213
+ | proxyUrl | <code >string</code > | the proxy's url |
214
+ | rejectUnauthorized | <code >boolean</code > | set to false to not reject unauthorized server certs |
95
215
96
216
### Debug Logs
97
217
0 commit comments