@serenity-js/rest 3.10.3 → 3.11.0

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/index.d.ts +0 -1
  3. package/lib/index.d.ts.map +1 -1
  4. package/lib/index.js +0 -1
  5. package/lib/index.js.map +1 -1
  6. package/lib/screenplay/abilities/AxiosRequestConfigDefaults.d.ts +14 -0
  7. package/lib/screenplay/abilities/AxiosRequestConfigDefaults.d.ts.map +1 -0
  8. package/lib/screenplay/abilities/AxiosRequestConfigDefaults.js +3 -0
  9. package/lib/screenplay/abilities/AxiosRequestConfigDefaults.js.map +1 -0
  10. package/lib/screenplay/abilities/CallAnApi.d.ts +297 -38
  11. package/lib/screenplay/abilities/CallAnApi.d.ts.map +1 -1
  12. package/lib/screenplay/abilities/CallAnApi.js +353 -44
  13. package/lib/screenplay/abilities/CallAnApi.js.map +1 -1
  14. package/lib/screenplay/abilities/index.d.ts +1 -0
  15. package/lib/screenplay/abilities/index.d.ts.map +1 -1
  16. package/lib/screenplay/abilities/index.js +1 -0
  17. package/lib/screenplay/abilities/index.js.map +1 -1
  18. package/lib/screenplay/abilities/proxy/ProxyAgent.d.ts +55 -0
  19. package/lib/screenplay/abilities/proxy/ProxyAgent.d.ts.map +1 -0
  20. package/lib/screenplay/abilities/proxy/ProxyAgent.js +107 -0
  21. package/lib/screenplay/abilities/proxy/ProxyAgent.js.map +1 -0
  22. package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.d.ts +12 -0
  23. package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.d.ts.map +1 -0
  24. package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.js +35 -0
  25. package/lib/screenplay/abilities/proxy/axiosProxyOverridesFor.js.map +1 -0
  26. package/lib/screenplay/abilities/proxy/createUrl.d.ts +10 -0
  27. package/lib/screenplay/abilities/proxy/createUrl.d.ts.map +1 -0
  28. package/lib/screenplay/abilities/proxy/createUrl.js +30 -0
  29. package/lib/screenplay/abilities/proxy/createUrl.js.map +1 -0
  30. package/lib/screenplay/abilities/proxy/index.d.ts +2 -0
  31. package/lib/screenplay/abilities/proxy/index.d.ts.map +1 -0
  32. package/lib/screenplay/abilities/proxy/index.js +18 -0
  33. package/lib/screenplay/abilities/proxy/index.js.map +1 -0
  34. package/lib/screenplay/index.d.ts +1 -0
  35. package/lib/screenplay/index.d.ts.map +1 -1
  36. package/lib/screenplay/index.js +1 -0
  37. package/lib/screenplay/index.js.map +1 -1
  38. package/lib/screenplay/interactions/Send.d.ts +3 -3
  39. package/lib/screenplay/interactions/Send.js +3 -3
  40. package/lib/{models → screenplay/models}/DeleteRequest.d.ts +1 -1
  41. package/lib/screenplay/models/DeleteRequest.d.ts.map +1 -0
  42. package/lib/{models → screenplay/models}/DeleteRequest.js +1 -1
  43. package/lib/screenplay/models/DeleteRequest.js.map +1 -0
  44. package/lib/{models → screenplay/models}/GetRequest.d.ts +1 -1
  45. package/lib/screenplay/models/GetRequest.d.ts.map +1 -0
  46. package/lib/{models → screenplay/models}/GetRequest.js +1 -1
  47. package/lib/screenplay/models/GetRequest.js.map +1 -0
  48. package/lib/screenplay/models/HTTPRequest.d.ts.map +1 -0
  49. package/lib/screenplay/models/HTTPRequest.js.map +1 -0
  50. package/lib/{models → screenplay/models}/HeadRequest.d.ts +1 -1
  51. package/lib/screenplay/models/HeadRequest.d.ts.map +1 -0
  52. package/lib/{models → screenplay/models}/HeadRequest.js +1 -1
  53. package/lib/screenplay/models/HeadRequest.js.map +1 -0
  54. package/lib/{models → screenplay/models}/OptionsRequest.d.ts +1 -1
  55. package/lib/screenplay/models/OptionsRequest.d.ts.map +1 -0
  56. package/lib/{models → screenplay/models}/OptionsRequest.js +1 -1
  57. package/lib/screenplay/models/OptionsRequest.js.map +1 -0
  58. package/lib/{models → screenplay/models}/PatchRequest.d.ts +1 -1
  59. package/lib/screenplay/models/PatchRequest.d.ts.map +1 -0
  60. package/lib/{models → screenplay/models}/PatchRequest.js +1 -1
  61. package/lib/screenplay/models/PatchRequest.js.map +1 -0
  62. package/lib/{models → screenplay/models}/PostRequest.d.ts +1 -1
  63. package/lib/screenplay/models/PostRequest.d.ts.map +1 -0
  64. package/lib/{models → screenplay/models}/PostRequest.js +1 -1
  65. package/lib/screenplay/models/PostRequest.js.map +1 -0
  66. package/lib/{models → screenplay/models}/PutRequest.d.ts +2 -2
  67. package/lib/screenplay/models/PutRequest.d.ts.map +1 -0
  68. package/lib/{models → screenplay/models}/PutRequest.js +2 -2
  69. package/lib/screenplay/models/PutRequest.js.map +1 -0
  70. package/lib/screenplay/models/index.d.ts.map +1 -0
  71. package/lib/screenplay/models/index.js.map +1 -0
  72. package/lib/screenplay/questions/LastResponse.d.ts +2 -2
  73. package/lib/screenplay/questions/LastResponse.js +2 -2
  74. package/package.json +11 -6
  75. package/src/index.ts +0 -1
  76. package/src/screenplay/abilities/AxiosRequestConfigDefaults.ts +15 -0
  77. package/src/screenplay/abilities/CallAnApi.ts +355 -48
  78. package/src/screenplay/abilities/index.ts +1 -0
  79. package/src/screenplay/abilities/proxy/ProxyAgent.ts +129 -0
  80. package/src/screenplay/abilities/proxy/axiosProxyOverridesFor.ts +39 -0
  81. package/src/screenplay/abilities/proxy/createUrl.ts +39 -0
  82. package/src/screenplay/abilities/proxy/index.ts +1 -0
  83. package/src/screenplay/index.ts +1 -0
  84. package/src/screenplay/interactions/Send.ts +3 -3
  85. package/src/{models → screenplay/models}/DeleteRequest.ts +1 -1
  86. package/src/{models → screenplay/models}/GetRequest.ts +1 -1
  87. package/src/{models → screenplay/models}/HeadRequest.ts +1 -1
  88. package/src/{models → screenplay/models}/OptionsRequest.ts +1 -1
  89. package/src/{models → screenplay/models}/PatchRequest.ts +1 -1
  90. package/src/{models → screenplay/models}/PostRequest.ts +1 -1
  91. package/src/{models → screenplay/models}/PutRequest.ts +2 -2
  92. package/src/screenplay/questions/LastResponse.ts +2 -2
  93. package/lib/models/DeleteRequest.d.ts.map +0 -1
  94. package/lib/models/DeleteRequest.js.map +0 -1
  95. package/lib/models/GetRequest.d.ts.map +0 -1
  96. package/lib/models/GetRequest.js.map +0 -1
  97. package/lib/models/HTTPRequest.d.ts.map +0 -1
  98. package/lib/models/HTTPRequest.js.map +0 -1
  99. package/lib/models/HeadRequest.d.ts.map +0 -1
  100. package/lib/models/HeadRequest.js.map +0 -1
  101. package/lib/models/OptionsRequest.d.ts.map +0 -1
  102. package/lib/models/OptionsRequest.js.map +0 -1
  103. package/lib/models/PatchRequest.d.ts.map +0 -1
  104. package/lib/models/PatchRequest.js.map +0 -1
  105. package/lib/models/PostRequest.d.ts.map +0 -1
  106. package/lib/models/PostRequest.js.map +0 -1
  107. package/lib/models/PutRequest.d.ts.map +0 -1
  108. package/lib/models/PutRequest.js.map +0 -1
  109. package/lib/models/index.d.ts.map +0 -1
  110. package/lib/models/index.js.map +0 -1
  111. /package/lib/{models → screenplay/models}/HTTPRequest.d.ts +0 -0
  112. /package/lib/{models → screenplay/models}/HTTPRequest.js +0 -0
  113. /package/lib/{models → screenplay/models}/index.d.ts +0 -0
  114. /package/lib/{models → screenplay/models}/index.js +0 -0
  115. /package/src/{models → screenplay/models}/HTTPRequest.ts +0 -0
  116. /package/src/{models → screenplay/models}/index.ts +0 -0
@@ -1,17 +1,46 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.CallAnApi = void 0;
7
27
  const core_1 = require("@serenity-js/core");
8
- const axios_1 = __importDefault(require("axios"));
28
+ const axios_1 = __importStar(require("axios"));
29
+ const proxy_1 = require("./proxy");
9
30
  /**
10
- * An {@apilink Ability} that enables the {@apilink Actor} to call an HTTP API.
31
+ * An {@apilink Ability} that wraps [axios client](https://axios-http.com/docs/api_intro) and enables
32
+ * the {@apilink Actor} to {@apilink Send} {@apilink HTTPRequest|HTTP requests} to HTTP APIs.
33
+ *
34
+ * `CallAnApi` uses [`proxy-from-env`](https://www.npmjs.com/package/proxy-from-env) and an approach
35
+ * described in ["Node.js Axios behind corporate proxies"](https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d)
36
+ * to automatically detect proxy server configuration based
37
+ * on your [environment variables](https://www.npmjs.com/package/proxy-from-env#environment-variables).
38
+ * You can override this configuration if needed.
11
39
  *
12
- * If you need to connect via a proxy, check out ["Using Axios behind corporate proxies"](https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d).
40
+ * ## Configuring the ability to call an API
13
41
  *
14
- * ## Using the default Axios HTTP client
42
+ * The easiest way to configure the ability to `CallAnApi` is to provide the `baseURL` of your HTTP API,
43
+ * and rely on Serenity/JS to offer other sensible defaults:
15
44
  *
16
45
  * ```ts
17
46
  * import { actorCalled } from '@serenity-js/core'
@@ -23,30 +52,180 @@ const axios_1 = __importDefault(require("axios"));
23
52
  * CallAnApi.at('https://api.example.org/')
24
53
  * )
25
54
  * .attemptsTo(
55
+ * Send.a(GetRequest.to('/v1/users/2')), // GET https://api.example.org/v1/users/2
56
+ * Ensure.that(LastResponse.status(), equals(200)),
57
+ * )
58
+ * ```
59
+ *
60
+ * ### Resolving relative URLs
61
+ *
62
+ * Serenity/JS resolves request URLs using Node.js [WHATWG URL API](https://nodejs.org/api/url.html#new-urlinput-base).
63
+ * This means that the request URL is determined using the resource path resolved in the context of base URL, i.e. `new URL(resourcePath, [baseURL])`.
64
+ *
65
+ * Consider the following example:
66
+ *
67
+ * ```ts
68
+ * import { actorCalled } from '@serenity-js/core'
69
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
70
+ * import { Ensure, equals } from '@serenity-js/assertions'
71
+ *
72
+ * await actorCalled('Apisitt')
73
+ * .whoCan(
74
+ * CallAnApi.at(baseURL)
75
+ * )
76
+ * .attemptsTo(
77
+ * Send.a(GetRequest.to(resourcePath)),
78
+ * Ensure.that(LastResponse.status(), equals(200)),
79
+ * )
80
+ * ```
81
+ *
82
+ * In the above example:
83
+ * - when `resourcePath` is defined as a full URL, it overrides the base URL
84
+ * - when `resourcePath` starts with a forward slash `/`, it replaces any path defined in the base URL
85
+ * - when `resourcePath` is not a full URL and doesn't start with a forward slash, it gets appended to the base URL
86
+ *
87
+ * | baseURL | resourcePath | result |
88
+ * | ----------------------------- | -------------------------- | ------------------------------------ |
89
+ * | `https://api.example.org/` | `/v1/users/2` | `https://api.example.org/v1/users/2` |
90
+ * | `https://example.org/api/v1/` | `users/2` | `https://example.org/api/v1/users/2` |
91
+ * | `https://example.org/api/v1/` | `/secure/oauth` | `https://example.org/secure/oauth` |
92
+ * | `https://v1.example.org/api/` | `https://v2.example.org/` | `https://v2.example.org/` |
93
+ *
94
+ * ### Using Axios configuration object
95
+ *
96
+ * When you need more control over how your Axios instance is configured, provide
97
+ * an [Axios configuration object](https://axios-http.com/docs/req_config). For example:
98
+ *
99
+ * ```ts
100
+ * import { actorCalled } from '@serenity-js/core'
101
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
102
+ * import { Ensure, equals } from '@serenity-js/assertions'
103
+ *
104
+ * await actorCalled('Apisitt')
105
+ * .whoCan(
106
+ * CallAnApi.using({
107
+ * baseURL: 'https://api.example.org/',
108
+ * timeout: 30_000,
109
+ * // ... other configuration options
110
+ * })
111
+ * )
112
+ * .attemptsTo(
113
+ * Send.a(GetRequest.to('/users/2')),
114
+ * Ensure.that(LastResponse.status(), equals(200)),
115
+ * )
116
+ * ```
117
+ *
118
+ * ### Working with proxy servers
119
+ *
120
+ * `CallAnApi` uses [`proxy-from-env`](https://www.npmjs.com/package/proxy-from-env) to automatically
121
+ * detect proxy server configuration based on your [environment variables](https://www.npmjs.com/package/proxy-from-env#environment-variables).
122
+ *
123
+ * This default behaviour can be overridden by providing explicit proxy configuration:
124
+ *
125
+ * ```ts
126
+ * import { actorCalled } from '@serenity-js/core'
127
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
128
+ * import { Ensure, equals } from '@serenity-js/assertions'
129
+ *
130
+ * await actorCalled('Apisitt')
131
+ * .whoCan(
132
+ * CallAnApi.using({
133
+ * baseURL: 'https://api.example.org/',
134
+ * proxy: {
135
+ * protocol: 'http',
136
+ * host: 'proxy.example.org',
137
+ * port: 9000,
138
+ * auth: { // `auth` is optional
139
+ * username: 'proxy-username',
140
+ * password: 'proxy-password',
141
+ * }
142
+ * }
143
+ * // ... other configuration options
144
+ * })
145
+ * )
146
+ * .attemptsTo(
147
+ * Send.a(GetRequest.to('/users/2')),
148
+ * Ensure.that(LastResponse.status(), equals(200)),
149
+ * )
150
+ * ```
151
+ *
152
+ * Please note that Serenity/JS uses [proxy-agents](https://github.com/TooTallNate/proxy-agents)
153
+ * and the approach described in ["Node.js Axios behind corporate proxies"](https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d)
154
+ * to work around [limited proxy support capabilities](https://github.com/axios/axios/issues?q=is%3Aissue+is%3Aopen+proxy) in Axios itself.
155
+ *
156
+ * ### Using Axios instance with proxy support
157
+ *
158
+ * To have full control over the Axios instance used by the ability to `CallAnApi`, you can create it yourself
159
+ * and inject it into the ability.
160
+ * This approach allows you to still benefit from automated proxy detection in configuration, while taking advantage
161
+ * of the many [Axios plugins](https://www.npmjs.com/search?q=axios).
162
+ *
163
+ * ```ts
164
+ * import { actorCalled } from '@serenity-js/core'
165
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
166
+ * import { Ensure, equals } from '@serenity-js/assertions'
167
+ *
168
+ * import axios from 'axios'
169
+ * import axiosRetry from 'axios-retry'
170
+ *
171
+ * const instance = axios.create({ baseURL 'https://api.example.org/' })
172
+ * axiosRetry(axios, { retries: 3 })
173
+ *
174
+ * await actorCalled('Apisitt')
175
+ * .whoCan(
176
+ * CallAnApi.using(instance)
177
+ * )
178
+ * .attemptsTo(
26
179
  * Send.a(GetRequest.to('/users/2')),
27
180
  * Ensure.that(LastResponse.status(), equals(200)),
28
181
  * )
29
182
  * ```
30
183
  *
31
- * ## Using Axios client with custom configuration
184
+ * ### Using raw Axios instance
185
+ *
186
+ * If you don't want Serenity/JS to enhance your Axios instance with proxy support, instantiate the ability to
187
+ * `CallAnApi` using its constructor directly.
188
+ * Note, however, that by using this approach you're taking the responsibility for all the aspects of configuring Axios.
32
189
  *
33
190
  * ```ts
34
191
  * import { actorCalled } from '@serenity-js/core'
35
192
  * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
36
193
  * import { Ensure, equals } from '@serenity-js/assertions'
37
194
  *
38
- * import * as axios from 'axios'
195
+ * import axios from 'axios'
196
+ * import axiosRetry from 'axios-retry'
197
+ *
198
+ * const instance = axios.create({ baseURL 'https://api.example.org/' })
199
+ * axiosRetry(axios, { retries: 3 })
200
+ *
201
+ * await actorCalled('Apisitt')
202
+ * .whoCan(
203
+ * new CallAnApi(instance) // using the constructor ensures your axios instance is not modified in any way.
204
+ * )
205
+ * .attemptsTo(
206
+ * // ...
207
+ * )
208
+ * ```
209
+ *
210
+ * ### Serenity/JS defaults
211
+ *
212
+ * When using {@apilink CallAnApi.at} or {@apilink CallAnApi.using} with a configuration object, Serenity/JS
213
+ * merges your [Axios request configuration](https://axios-http.com/docs/req_config) with the following defaults:
214
+ * - `timeout`: 10 seconds
39
215
  *
40
- * const axiosInstance = axios.create({
41
- * timeout: 5 * 1000,
42
- * headers: {
43
- * 'X-Custom-Api-Key': 'secret-key',
44
- * },
45
- * });
216
+ *
217
+ * You can override them by specifying the given property in your configuration object, for example:
218
+ * ```ts
219
+ * import { actorCalled } from '@serenity-js/core'
220
+ * import { CallAnApi, GetRequest, LastResponse, Send } from '@serenity-js/rest'
221
+ * import { Ensure, equals } from '@serenity-js/assertions'
46
222
  *
47
223
  * await actorCalled('Apisitt')
48
224
  * .whoCan(
49
- * CallAnApi.using(axiosInstance),
225
+ * CallAnApi.using({
226
+ * baseURL: 'https://api.example.org/',
227
+ * timeout: 30_000
228
+ * })
50
229
  * )
51
230
  * .attemptsTo(
52
231
  * Send.a(GetRequest.to('/users/2')),
@@ -54,48 +233,162 @@ const axios_1 = __importDefault(require("axios"));
54
233
  * )
55
234
  * ```
56
235
  *
236
+ * ## Interacting with multiple APIs
237
+ *
238
+ * Some test scenarios might require you to interact with multiple HTTP APIs. With Serenity/JS you can do this
239
+ * using either API-specific actors, or by specifying full URLs when performing the requests.
240
+ *
241
+ * The following examples will assume that the test scenarios needs to interact with the following APIs:
242
+ * - `https://testdata.example.org/api/v1/`
243
+ * - `https://shop.example.org/api/v1/`
244
+ *
245
+ * Let's also assume that the `testdata` API allows the automation to manage the test data used by the `shop` API.
246
+ *
247
+ * ### Using API-specific actors
248
+ *
249
+ * To create API-specific actors, configure your [test runner](/handbook/test-runners/) with a {@apilink Cast}
250
+ * that gives your actors appropriate abilities based, for example, on their name:
251
+ *
252
+ * ```ts
253
+ * import { beforeEach } from 'mocha'
254
+ * import { Actor, Cast, engage } from '@serenity-js/core'
255
+ * import { CallAnApi } from '@serenity-js/rest'
256
+ *
257
+ * export class MyActors implements Cast {
258
+ * prepare(actor: Actor): Actor {
259
+ * switch(actor.name) {
260
+ * case 'Ted':
261
+ * return actor.whoCan(CallAnApi.at('https://testdata.example.org/api/v1/'))
262
+ * case 'Shelly':
263
+ * return actor.whoCan(CallAnApi.at('https://shop.example.org/api/v1/'))
264
+ * default:
265
+ * return actor;
266
+ * }
267
+ * }
268
+ * }
269
+ *
270
+ * beforeEach(() => engage(new MyActors()))
271
+ * ```
272
+ *
273
+ * Next, retrieve the appropriate actor in your test scenario using {@apilink actorCalled}, for example:
274
+ *
275
+ * ```ts
276
+ * import { describe, it, beforeEach } from 'mocha'
277
+ * import { actorCalled, engage } from '@serenity-js/core
278
+ * import { Send, GetRequest, PostRequest, LastResponse } from '@serenity-js/rest'
279
+ * import { Ensure, equals } from '@serenity-js/assertions'
280
+ *
281
+ * describe('Multi-actor API testing', () => {
282
+ * beforeEach(() => engage(new MyActors()))
283
+ *
284
+ * it('allows each actor to interact with their API', async () => {
285
+ *
286
+ * await actorCalled('Ted').attemptsTo(
287
+ * Send.a(PostRequest.to('products').with({ name: 'Apples', price: '£2.50' })),
288
+ * Ensure.that(LastResponse.status(), equals(201)),
289
+ * )
290
+ *
291
+ * await actorCalled('Shelly').attemptsTo(
292
+ * Send.a(GetRequest.to('?product=Apples')),
293
+ * Ensure.that(LastResponse.status(), equals(200)),
294
+ * Ensure.that(LastResponse.body(), equals([
295
+ * { name: 'Apples', price: '£2.50' }
296
+ * ])),
297
+ * )
298
+ * })
299
+ * })
300
+ * ```
301
+ *
302
+ * ### Using full URLs
303
+ *
304
+ * If you prefer to have a single actor interacting with multiple APIs, you can specify the full URL for every request:
305
+ *
306
+ * ```ts
307
+ * import { describe, it, beforeEach } from 'mocha'
308
+ * import { actorCalled, Cast, engage } from '@serenity-js/core
309
+ * import { CallAnApi, Send, GetRequest, PostRequest, LastResponse } from '@serenity-js/rest'
310
+ * import { Ensure, equals } from '@serenity-js/assertions'
311
+ *
312
+ * describe('Multi-actor API testing', () => {
313
+ * beforeEach(() => engage(
314
+ * Cast.where(actor => actor.whoCan(CallAnApi.using({})))
315
+ * ))
316
+ *
317
+ * it('allows each actor to interact with their API', async () => {
318
+ *
319
+ * await actorCalled('Alice').attemptsTo(
320
+ * Send.a(PostRequest.to('https://testdata.example.org/api/v1/products')
321
+ * .with({ name: 'Apples', price: '£2.50' })),
322
+ * Ensure.that(LastResponse.status(), equals(201)),
323
+ *
324
+ * Send.a(GetRequest.to('https://shop.example.org/api/v1/?product=Apples')),
325
+ * Ensure.that(LastResponse.status(), equals(200)),
326
+ * Ensure.that(LastResponse.body(), equals([
327
+ * { name: 'Apples', price: '£2.50' }
328
+ * ])),
329
+ * )
330
+ * })
331
+ * })
332
+ * ```
333
+ *
57
334
  * ## Learn more
58
- * - https://github.com/axios/axios
59
- * - https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
335
+ * - [Axios: Configuring requests](https://axios-http.com/docs/req_config)
336
+ * - [MDN: HTTP methods documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
60
337
  *
61
338
  * @group Abilities
62
339
  */
63
340
  class CallAnApi extends core_1.Ability {
64
341
  /**
65
- * Produces an {@apilink Ability|ability} to call a REST api at a specified baseUrl
66
- *
67
- * Default timeout is set to 2s.
342
+ * Produces an {@apilink Ability|ability} to call a REST API at a specified `baseURL`;
68
343
  *
69
- * Default request headers:
70
- * - `Accept`: `application/json,application/xml`
344
+ * This is the same as invoking `CallAnApi.using({ baseURL: 'https://example.org' })`
71
345
  *
72
346
  * @param baseURL
73
347
  */
74
348
  static at(baseURL) {
75
- return new CallAnApi(axios_1.default.create({
76
- baseURL,
77
- timeout: 2000,
78
- headers: { Accept: 'application/json,application/xml' },
79
- }));
349
+ return CallAnApi.using({
350
+ baseURL: baseURL instanceof URL
351
+ ? baseURL.toString()
352
+ : baseURL
353
+ });
80
354
  }
81
355
  /**
82
- * Produces an {@apilink Ability|ability} to call a REST API using a given axios instance.
356
+ * Produces an {@apilink Ability|ability} to call an HTTP API using the given Axios instance,
357
+ * or an Axios request configuration object.
83
358
  *
84
- * Useful when you need to customise Axios to
85
- * [make it aware of proxies](https://janmolak.com/node-js-axios-behind-corporate-proxies-8b17a6f31f9d),
86
- * for example.
359
+ * When you provide an [Axios configuration object](https://axios-http.com/docs/req_config),
360
+ * it gets shallow-merged with the following defaults:
361
+ * - request timeout of 10 seconds
362
+ * - automatic proxy support based on
363
+ * your [environment variables](https://www.npmjs.com/package/proxy-from-env#environment-variables)
87
364
  *
88
- * #### Learn more
89
- * - [AxiosInstance](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L235-L238)
365
+ * When you provide an Axios instance, it's enhanced with proxy support and no other modifications are made.
90
366
  *
91
- * @param axiosInstance
367
+ * If you don't want Serenity/JS to augment or modify your Axios instance in any way,
368
+ * please use the {@apilink CallAnApi.constructor} directly.
369
+ *
370
+ * @param axiosInstanceOrConfig
92
371
  */
93
- static using(axiosInstance) {
94
- return new CallAnApi(axiosInstance);
372
+ static using(axiosInstanceOrConfig) {
373
+ const axiosInstanceGiven = isAxiosInstance(axiosInstanceOrConfig);
374
+ const axiosInstance = axiosInstanceGiven
375
+ ? axiosInstanceOrConfig
376
+ : axios_1.default.create({
377
+ ...CallAnApi.defaults,
378
+ ...omit(axiosInstanceOrConfig, 'proxy'),
379
+ });
380
+ const proxyConfig = axiosInstanceGiven
381
+ ? axiosInstanceOrConfig.defaults.proxy
382
+ : axiosInstanceOrConfig.proxy;
383
+ const proxyOverrides = (0, proxy_1.axiosProxyOverridesFor)({
384
+ ...axiosInstance.defaults,
385
+ proxy: proxyConfig || undefined,
386
+ });
387
+ return new CallAnApi(withOverrides(axiosInstance, proxyOverrides));
95
388
  }
96
389
  /**
97
390
  * #### Learn more
98
- * - [AxiosInstance](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L235-L238)
391
+ * - [AxiosInstance](https://axios-http.com/docs/instance)
99
392
  *
100
393
  * @param axiosInstance
101
394
  * A pre-configured instance of the Axios HTTP client
@@ -110,7 +403,7 @@ class CallAnApi extends core_1.Ability {
110
403
  * has been instantiated and given to the {@apilink Actor}.
111
404
  *
112
405
  * #### Learn more
113
- * - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
406
+ * - [AxiosRequestConfig](https://axios-http.com/docs/req_config)
114
407
  *
115
408
  * @param fn
116
409
  */
@@ -122,8 +415,8 @@ class CallAnApi extends core_1.Ability {
122
415
  * Response will be cached and available via {@apilink mapLastResponse}
123
416
  *
124
417
  * #### Learn more
125
- * - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
126
- * - [AxiosResponse](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L133-L140)
418
+ * - [AxiosRequestConfig](https://axios-http.com/docs/req_config)
419
+ * - [AxiosResponse](https://axios-http.com/docs/res_schema)
127
420
  *
128
421
  * @param config
129
422
  * Axios request configuration, which can be used to override the defaults
@@ -160,9 +453,8 @@ class CallAnApi extends core_1.Ability {
160
453
  * Resolves the final URL, based on the {@apilink AxiosRequestConfig} provided
161
454
  * and any defaults that the {@apilink AxiosInstance} has been configured with.
162
455
  *
163
- * #### Learn more
164
- * - [AxiosRequestConfig](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L75-L113)
165
- * - [AxiosInstance](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L235-L238)
456
+ * Note that unlike Axios, this method uses the Node.js [WHATWG URL API](https://nodejs.org/api/url.html#new-urlinput-base)
457
+ * to ensure URLs are correctly resolved.
166
458
  *
167
459
  * @param config
168
460
  */
@@ -177,7 +469,7 @@ class CallAnApi extends core_1.Ability {
177
469
  * Useful when you need to extract a portion of the {@apilink AxiosResponse} object.
178
470
  *
179
471
  * #### Learn more
180
- * - [AxiosResponse](https://github.com/axios/axios/blob/v0.27.2/index.d.ts#L133-L140)
472
+ * - [AxiosResponse](https://axios-http.com/docs/res_schema)
181
473
  *
182
474
  * @param mappingFunction
183
475
  */
@@ -189,4 +481,21 @@ class CallAnApi extends core_1.Ability {
189
481
  }
190
482
  }
191
483
  exports.CallAnApi = CallAnApi;
484
+ CallAnApi.defaults = {
485
+ timeout: core_1.Duration.ofSeconds(10).inMilliseconds(),
486
+ };
487
+ function isAxiosInstance(axiosInstanceOrConfig) {
488
+ return axiosInstanceOrConfig
489
+ && (axiosInstanceOrConfig instanceof axios_1.Axios || axiosInstanceOrConfig.defaults);
490
+ }
491
+ function withOverrides(axiosInstance, overrides) {
492
+ for (const [key, override] of Object.entries(overrides)) {
493
+ axiosInstance.defaults[key] = override;
494
+ }
495
+ return axiosInstance;
496
+ }
497
+ function omit(record, key) {
498
+ const { [key]: omitted_, ...rest } = record;
499
+ return rest;
500
+ }
192
501
  //# sourceMappingURL=CallAnApi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CallAnApi.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/CallAnApi.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAkG;AAElG,kDAA0B;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAa,SAAU,SAAQ,cAAO;IAKlC;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,CAAC,OAAe;QACrB,OAAO,IAAI,SAAS,CAAC,eAAK,CAAC,MAAM,CAAC;YAC9B,OAAO;YACP,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,EAAE,MAAM,EAAE,kCAAkC,EAAE;SAC1D,CAAC,CAAC,CAAC;IACR,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CAAC,aAA4B;QACrC,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,YAA6B,aAA4B;QACrD,KAAK,EAAE,CAAC;QADiB,kB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;;OAQG;IACH,eAAe,CAAI,eAA+C;QAC9D,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACpB,MAAM,IAAI,iBAAU,CAAC,sEAAsE,CAAC,CAAC;SAChG;QAED,OAAO,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC;;AApKL,8BAqKC;AAjK2B,kBAAQ,GAA6B;IACzD,OAAO,EAAE,eAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,cAAc,EAAE;CACnD,CAAC;AAiKN,SAAS,eAAe,CAAC,qBAA0B;IAC/C,OAAO,qBAAqB;WACrB,CAAC,qBAAqB,YAAY,aAAK,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,aAAa,CAAa,aAA4B,EAAE,SAAmC;IAChG,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QACrD,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;KAC1C;IAED,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,SAAS,IAAI,CAAsC,MAAS,EAAE,GAAM;IAChE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAC5C,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -1,2 +1,3 @@
1
+ export * from './AxiosRequestConfigDefaults';
1
2
  export * from './CallAnApi';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,aAAa,CAAC"}
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AxiosRequestConfigDefaults"), exports);
17
18
  __exportStar(require("./CallAnApi"), exports);
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/abilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C;AAC7C,8CAA4B"}
@@ -0,0 +1,55 @@
1
+ /// <reference types="node" />
2
+ import type { AgentConnectOpts } from 'agent-base';
3
+ import { Agent } from 'agent-base';
4
+ import * as http from 'http';
5
+ import { type HttpProxyAgentOptions } from 'http-proxy-agent';
6
+ import { type HttpsProxyAgentOptions } from 'https-proxy-agent';
7
+ type GetProxyForUrlCallback = (url: string) => string;
8
+ export type ProxyAgentOptions = HttpProxyAgentOptions<''> & HttpsProxyAgentOptions<''> & {
9
+ /**
10
+ * Default `http.Agent` instance to use when no proxy is
11
+ * configured for a request. Defaults to a new `http.Agent()`
12
+ * instance with the proxy agent options passed in.
13
+ */
14
+ httpAgent?: http.Agent;
15
+ /**
16
+ * Default `http.Agent` instance to use when no proxy is
17
+ * configured for a request. Defaults to a new `https.Agent()`
18
+ * instance with the proxy agent options passed in.
19
+ */
20
+ httpsAgent?: http.Agent;
21
+ /**
22
+ * A callback for dynamic provision of proxy for url.
23
+ * Defaults to standard proxy environment variables,
24
+ * see https://www.npmjs.com/package/proxy-from-env for details
25
+ */
26
+ getProxyForUrl?: GetProxyForUrlCallback;
27
+ };
28
+ /**
29
+ * A simplified version of the original
30
+ * [`ProxyAgent`](https://github.com/TooTallNate/proxy-agents/blob/5923589c2e5206504772c250ac4f20fc31122d3b/packages/proxy-agent/src/index.ts)
31
+ * with fewer dependencies.
32
+ *
33
+ * Delegates requests to the appropriate `Agent` subclass based on the "proxy"
34
+ * environment variables, or the provided `agentOptions.getProxyForUrl` callback.
35
+ *
36
+ * Uses an LRU cache to prevent unnecessary creation of proxy `http.Agent` instances.
37
+ */
38
+ export declare class ProxyAgent extends Agent {
39
+ private readonly agentOptions;
40
+ private static proxyAgents;
41
+ /**
42
+ * Cache for `Agent` instances.
43
+ */
44
+ private readonly cache;
45
+ private readonly httpAgent;
46
+ private readonly httpsAgent;
47
+ private readonly getProxyForUrl;
48
+ constructor(agentOptions: ProxyAgentOptions);
49
+ connect(request: http.ClientRequest, options: AgentConnectOpts): Promise<http.Agent>;
50
+ private createAgent;
51
+ private isValidProtocol;
52
+ destroy(): void;
53
+ }
54
+ export {};
55
+ //# sourceMappingURL=ProxyAgent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProxyAgent.d.ts","sourceRoot":"","sources":["../../../../src/screenplay/abilities/proxy/ProxyAgent.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAmB,KAAK,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAYjF,KAAK,sBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GACzB,qBAAqB,CAAC,EAAE,CAAC,GACzB,sBAAsB,CAAC,EAAE,CAAC,GAAG;IACzB;;;;OAIG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;IACvB;;;;OAI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