polarity-integration-utils 0.1.0 → 2.0.8

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 (118) hide show
  1. package/README.md +30 -2
  2. package/dist/dts/errors/api-request-error.d.ts +10 -0
  3. package/dist/dts/errors/api-request-error.d.ts.map +1 -0
  4. package/dist/dts/errors/auth-request-error.d.ts +10 -0
  5. package/dist/dts/errors/auth-request-error.d.ts.map +1 -0
  6. package/dist/dts/errors/index.d.ts +8 -0
  7. package/dist/dts/errors/index.d.ts.map +1 -0
  8. package/dist/dts/errors/integration-error.d.ts +189 -0
  9. package/dist/dts/errors/integration-error.d.ts.map +1 -0
  10. package/dist/dts/errors/library-usage-error.d.ts +12 -0
  11. package/dist/dts/errors/library-usage-error.d.ts.map +1 -0
  12. package/dist/dts/errors/network-error.d.ts +11 -0
  13. package/dist/dts/errors/network-error.d.ts.map +1 -0
  14. package/dist/dts/errors/parse-error-to-readable-json.d.ts +7 -0
  15. package/dist/dts/errors/parse-error-to-readable-json.d.ts.map +1 -0
  16. package/dist/dts/errors/retry-request-error.d.ts +11 -0
  17. package/dist/dts/errors/retry-request-error.d.ts.map +1 -0
  18. package/dist/dts/index.d.ts +5 -0
  19. package/dist/dts/index.d.ts.map +1 -0
  20. package/dist/dts/index.docs.d.ts +9 -0
  21. package/dist/dts/index.docs.d.ts.map +1 -0
  22. package/dist/dts/internal/helpers/parallel-limit.d.ts +9 -0
  23. package/dist/dts/internal/helpers/parallel-limit.d.ts.map +1 -0
  24. package/dist/dts/internal/helpers/sanitize-object.d.ts +11 -0
  25. package/dist/dts/internal/helpers/sanitize-object.d.ts.map +1 -0
  26. package/dist/dts/logging/index.d.ts +2 -0
  27. package/dist/dts/logging/index.d.ts.map +1 -0
  28. package/dist/dts/logging/logger.d.ts +49 -0
  29. package/dist/dts/logging/logger.d.ts.map +1 -0
  30. package/dist/dts/requests/index.d.ts +3 -0
  31. package/dist/dts/requests/index.d.ts.map +1 -0
  32. package/dist/dts/requests/polarity-request.d.ts +411 -0
  33. package/dist/dts/requests/polarity-request.d.ts.map +1 -0
  34. package/dist/dts/requests/sanitize-request-options.d.ts +20 -0
  35. package/dist/dts/requests/sanitize-request-options.d.ts.map +1 -0
  36. package/dist/dts/types.d.ts +104 -0
  37. package/dist/dts/types.d.ts.map +1 -0
  38. package/dist/es/errors/api-request-error.js +15 -0
  39. package/dist/es/errors/auth-request-error.js +15 -0
  40. package/dist/es/errors/index.js +20 -8
  41. package/dist/es/errors/integration-error.js +116 -0
  42. package/dist/es/errors/library-usage-error.js +17 -0
  43. package/dist/es/errors/network-error.js +88 -0
  44. package/dist/es/errors/parse-error-to-readable-json.js +9 -0
  45. package/dist/es/errors/retry-request-error.js +16 -0
  46. package/dist/es/index.docs.js +24 -0
  47. package/dist/es/index.js +40 -14
  48. package/dist/es/internal/helpers/parallel-limit.js +36 -0
  49. package/dist/es/internal/helpers/sanitize-object.js +37 -0
  50. package/dist/es/logging/index.js +15 -2
  51. package/dist/es/logging/logger.js +41 -5
  52. package/dist/es/requests/index.js +15 -8
  53. package/dist/es/requests/polarity-request.js +426 -0
  54. package/dist/es/requests/sanitize-request-options.js +50 -0
  55. package/dist/lib/errors/api-request-error.js +15 -0
  56. package/dist/lib/errors/auth-request-error.js +15 -0
  57. package/dist/lib/errors/index.js +20 -8
  58. package/dist/lib/errors/integration-error.js +116 -0
  59. package/dist/lib/errors/library-usage-error.js +17 -0
  60. package/dist/lib/errors/network-error.js +88 -0
  61. package/dist/lib/errors/parse-error-to-readable-json.js +9 -0
  62. package/dist/lib/errors/retry-request-error.js +16 -0
  63. package/dist/lib/index.docs.js +24 -0
  64. package/dist/lib/index.js +40 -14
  65. package/dist/lib/internal/helpers/parallel-limit.js +36 -0
  66. package/dist/lib/internal/helpers/sanitize-object.js +37 -0
  67. package/dist/lib/logging/index.js +15 -2
  68. package/dist/lib/logging/logger.js +41 -5
  69. package/dist/lib/requests/index.js +15 -8
  70. package/dist/lib/requests/polarity-request.js +426 -0
  71. package/dist/lib/requests/sanitize-request-options.js +50 -0
  72. package/dist/polarity-integration-utils.d.ts +852 -0
  73. package/dist/tsdoc-metadata.json +11 -0
  74. package/package.json +59 -10
  75. package/dist/es/errors/RequestError.js +0 -12
  76. package/dist/es/errors/parseErrorToReadableJson.js +0 -4
  77. package/dist/es/helpers/async/index.js +0 -9
  78. package/dist/es/helpers/async/parallelLimit.js +0 -33
  79. package/dist/es/helpers/encodings/decodeBase64.js +0 -4
  80. package/dist/es/helpers/encodings/encodeBase64.js +0 -4
  81. package/dist/es/helpers/encodings/index.js +0 -11
  82. package/dist/es/helpers/index.js +0 -10
  83. package/dist/es/helpers/json/and.js +0 -4
  84. package/dist/es/helpers/json/filterObjectsContainingString.js +0 -10
  85. package/dist/es/helpers/json/index.js +0 -17
  86. package/dist/es/helpers/json/mapOverObject.js +0 -24
  87. package/dist/es/helpers/json/or.js +0 -4
  88. package/dist/es/helpers/json/transpose2dArray.js +0 -8
  89. package/dist/es/helpers/time/index.js +0 -11
  90. package/dist/es/helpers/time/millisecondsToHoursMinutesAndSeconds.js +0 -18
  91. package/dist/es/helpers/time/sleep.js +0 -13
  92. package/dist/es/requests/createRequestWithDefaults.js +0 -166
  93. package/dist/es/requests/createRequestsInParallel.js +0 -40
  94. package/dist/es/user-options/index.js +0 -9
  95. package/dist/es/user-options/validateUrlOption.js +0 -77
  96. package/dist/lib/errors/RequestError.js +0 -12
  97. package/dist/lib/errors/parseErrorToReadableJson.js +0 -4
  98. package/dist/lib/helpers/async/index.js +0 -9
  99. package/dist/lib/helpers/async/parallelLimit.js +0 -33
  100. package/dist/lib/helpers/encodings/decodeBase64.js +0 -4
  101. package/dist/lib/helpers/encodings/encodeBase64.js +0 -4
  102. package/dist/lib/helpers/encodings/index.js +0 -11
  103. package/dist/lib/helpers/index.js +0 -10
  104. package/dist/lib/helpers/json/and.js +0 -4
  105. package/dist/lib/helpers/json/filterObjectsContainingString.js +0 -10
  106. package/dist/lib/helpers/json/index.js +0 -17
  107. package/dist/lib/helpers/json/mapOverObject.js +0 -24
  108. package/dist/lib/helpers/json/or.js +0 -4
  109. package/dist/lib/helpers/json/transpose2dArray.js +0 -8
  110. package/dist/lib/helpers/time/index.js +0 -11
  111. package/dist/lib/helpers/time/millisecondsToHoursMinutesAndSeconds.js +0 -18
  112. package/dist/lib/helpers/time/sleep.js +0 -13
  113. package/dist/lib/requests/createRequestWithDefaults.js +0 -166
  114. package/dist/lib/requests/createRequestsInParallel.js +0 -40
  115. package/dist/lib/user-options/index.js +0 -9
  116. package/dist/lib/user-options/validateUrlOption.js +0 -77
  117. /package/dist/es/{requests/requestTypes.js → types.js} +0 -0
  118. /package/dist/lib/{requests/requestTypes.js → types.js} +0 -0
@@ -0,0 +1,411 @@
1
+ import Bottleneck from 'bottleneck';
2
+ import { ApiRequestError, NetworkError, RetryRequestError } from '../errors';
3
+ import type { Entity, DoLookupUserOptions } from '../types';
4
+ /**
5
+ * @public
6
+ */
7
+ export type ConfigRequestProxyOptions = {
8
+ ca?: undefined | string;
9
+ cert?: undefined | string;
10
+ key?: undefined | string;
11
+ passphrase?: undefined | string;
12
+ rejectUnauthorized?: undefined | boolean;
13
+ proxy?: undefined | string;
14
+ json?: undefined | boolean;
15
+ };
16
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
17
+ /**
18
+ * @public
19
+ */
20
+ export type HttpRequestOptions = {
21
+ /**
22
+ * The URL to make the request to.
23
+ */
24
+ url?: string;
25
+ /**
26
+ * The HTTP method to use for the request.
27
+ *
28
+ * @defaultValue 'GET'
29
+ */
30
+ method?: HttpMethod;
31
+ /**
32
+ * If true, sets body to JSON representation of value and adds Content-type: application/json header.
33
+ * Additionally, parses the response body as JSON.
34
+ *
35
+ * @defaultValue true
36
+ */
37
+ json?: boolean;
38
+ /**
39
+ * An object containing the headers to include in the request.
40
+ * @example
41
+ * Here is an example of setting the "X-Api-Key" `headers` property:
42
+ * ```
43
+ * {
44
+ * headers: {
45
+ * 'X-Api-Key': '1234567890'
46
+ * }
47
+ * }
48
+ * ```
49
+ */
50
+ headers?: object;
51
+ /**
52
+ * An object containing querystring parameters to include in the request.
53
+ * @example
54
+ * Here is an example of setting the `qs` property:
55
+ * ```
56
+ * {
57
+ * qs: {
58
+ * search: 'foo'
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ qs?: object;
64
+ /**
65
+ * When passed an object or a querystring, this sets body to a querystring representation of value,
66
+ * and adds Content-type: application/x-www-form-urlencoded header.
67
+ */
68
+ form?: object;
69
+ /**
70
+ * The body of the request.
71
+ */
72
+ body?: object;
73
+ /**
74
+ * The authentication options to use for the request
75
+ */
76
+ auth?: {
77
+ username: string;
78
+ password: string;
79
+ sendImmediately?: boolean;
80
+ } | {
81
+ bearer: string;
82
+ sendImmediately?: boolean;
83
+ };
84
+ [key: string]: unknown;
85
+ } & ({
86
+ entity: Entity;
87
+ entities?: never;
88
+ requestId?: never;
89
+ } | {
90
+ entities: Entity[];
91
+ entity?: never;
92
+ requestId?: never;
93
+ } | {
94
+ requestId: string | unknown;
95
+ entity?: never;
96
+ entities?: never;
97
+ } | {
98
+ entity?: never;
99
+ entities?: never;
100
+ requestId?: never;
101
+ });
102
+ /**
103
+ * @public
104
+ */
105
+ export type RunInParallelOptions = {
106
+ /**
107
+ * Array of HttpRequestOptions that will be run in parallel as specified by
108
+ * the `maxConcurrentRequests` property.
109
+ */
110
+ allRequestOptions: HttpRequestOptions[];
111
+ /**
112
+ * Maximum number of requests to run in parallel
113
+ *
114
+ * @defaultValue 5
115
+ */
116
+ maxConcurrentRequests?: number;
117
+ /**
118
+ * If true, any errors thrown during the request will be returned in the response object on the `error` property
119
+ * of the returned `HttpRequestResponse` object. If false, any errors thrown will be thrown and should be handled by
120
+ *
121
+ *
122
+ * @defaultValue false
123
+ */
124
+ returnErrors?: boolean;
125
+ };
126
+ /**
127
+ * @public
128
+ */
129
+ export type HttpRequestResponse = {
130
+ /**
131
+ * The HTTP status code of the response.
132
+ */
133
+ statusCode: number;
134
+ request: {
135
+ uri: unknown;
136
+ method: string;
137
+ headers: unknown;
138
+ [key: string]: unknown;
139
+ };
140
+ /**
141
+ * The body of the response.
142
+ */
143
+ body: unknown;
144
+ /**
145
+ * The response headers
146
+ */
147
+ headers: unknown;
148
+ /**
149
+ * The error object if an error occurred during the request.
150
+ */
151
+ error?: ApiRequestError | NetworkError | RetryRequestError;
152
+ /**
153
+ * The entity that the request was made for. The `entity` property matches the
154
+ * `entity` property set on the {@link HttpRequestOptions} object associated with this HttpRequestResponse.
155
+ */
156
+ entity?: Entity;
157
+ /**
158
+ * An array of entities that the request was made for. The `entities` property
159
+ * matches the `entities` property set on the {@link HttpRequestOptions} object associated
160
+ * with this HttpRequestResponse.
161
+ */
162
+ entities?: Entity[];
163
+ /**
164
+ * A custom request id that can be used to identify the request. The `requestId` matches
165
+ * the `requestId` property set on the {@link HttpRequestOptions} object.
166
+ */
167
+ requestId?: string | unknown;
168
+ [key: string]: unknown;
169
+ };
170
+ /**
171
+ * @public
172
+ */
173
+ export type IsApiErrorResult = {
174
+ /**
175
+ * Indicates whether the response is an API error.
176
+ */
177
+ isApiError: boolean;
178
+ /**
179
+ * Optional message providing additional information about the API error. The
180
+ * returned `message` will be used as the `message` property on the {@link ApiRequestError} object
181
+ * thrown by the request.
182
+ */
183
+ message?: string;
184
+ };
185
+ /**
186
+ * @public
187
+ */
188
+ export type IsApiErrorFunction = (response: HttpRequestResponse, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => IsApiErrorResult;
189
+ /**
190
+ * Optional middleware method for modifying {@link HttpRequestOptions} before a request is made
191
+ * via the {@link PolarityRequest.run} method or {@link PolarityRequest.runInParallel} method.
192
+ * The returned `requestOptions` object will be used for the request. This method is passed
193
+ * a copy of the original `requestOptions` object so it can be modified without side effects.
194
+ *
195
+ * This method is typically used for adding authentication (e.g., auth headers, or basic auth) to every request. It can also
196
+ * be used to add headers that are required on every request or conditionally add headers based
197
+ * on the passed in `userOptions`.
198
+ *
199
+ * @public
200
+ */
201
+ export type PreprocessRequestOptions = (requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => Promise<HttpRequestOptions> | never | undefined;
202
+ /**
203
+ * Optional middleware method for modifying the {@link HttpRequestResponse} after a successful request.
204
+ * The passed in {@link HttpRequestResponse} object is not a copy but can be safely modified without
205
+ * side effects. The returned `HttpRequestResponse` object will be used for the response.
206
+ *
207
+ * @public
208
+ */
209
+ export type PostprocessRequestSuccess = (response: HttpRequestResponse, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => Promise<HttpRequestResponse> | never;
210
+ /**
211
+ * @public
212
+ */
213
+ export type PostprocessRequestFailure = (error: Error, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => Promise<unknown> | never;
214
+ /**
215
+ * @public
216
+ */
217
+ export interface PolarityRequestOptions {
218
+ defaults?: ConfigRequestProxyOptions;
219
+ isApiError?: IsApiErrorFunction;
220
+ roundedSuccessStatusCodes?: number[];
221
+ httpResponseErrorProperties?: string[];
222
+ httpResponseErrorMessageProperties?: string[];
223
+ requestOptionsToSanitize?: string[];
224
+ preprocessRequestOptions?: PreprocessRequestOptions;
225
+ postprocessRequestSuccess?: PostprocessRequestSuccess;
226
+ postprocessRequestFailure?: PostprocessRequestFailure;
227
+ throttlingOptions?: Bottleneck.ConstructorOptions;
228
+ }
229
+ /**
230
+ * A utility class for making HTTP requests
231
+ * @public
232
+ */
233
+ export declare class PolarityRequest {
234
+ private bottleneckLimiter;
235
+ /**
236
+ * Instance of a Bunyan logger
237
+ */
238
+ private logger;
239
+ private internalThrottlingOptions;
240
+ /**
241
+ * postman-request library request object with default values set. Used internally for
242
+ * making HTTP requests directly via the postman-request library
243
+ */
244
+ private readonly requestWithDefaults;
245
+ readonly roundedSuccessStatusCodes: number[];
246
+ /**
247
+ * One or more HTTP response properties specified using JSON dot notation. If the
248
+ * specified path exists within the `body` property of the HTTP Response, an
249
+ * ApiRequestError will be thrown.
250
+ *
251
+ * By default, this value is an empty array and response properties are not used to
252
+ * detect errors.
253
+ * @defaultValue []
254
+ */
255
+ readonly httpResponseErrorProperties: string[];
256
+ /**
257
+ * One or more HTTP response properties specified using JSON dot notation that
258
+ * point to an error message that should be displayed to the user in the event
259
+ * of an API error.
260
+ *
261
+ * The property should be a string value. If the property does not exist or is not
262
+ * a string value, a default error message will be used instead.
263
+ */
264
+ readonly httpResponseErrorMessageProperties: string[];
265
+ /**
266
+ * Optional method that can be implemented to determine if an API error
267
+ * was encountered after an HTTP request is made.
268
+ *
269
+ * If the `isApiError` method is implemented
270
+ * the property `roundedSuccessStatusCodes` and `httpResponseErrorProperties` are not
271
+ * used to determine API errors.
272
+ *
273
+ * @returns An object indicating whether an API error was encountered and an optional message.
274
+ */
275
+ readonly isApiError: IsApiErrorFunction;
276
+ /**
277
+ * An array of JSON dot notation paths to omit from the request options when logging.
278
+ *
279
+ * This property can be used to sanitize sensitive request properties that should not
280
+ * appear in logging.
281
+ *
282
+ * Note that the `requestOptions` object is automatically sanitized to remove properties that
283
+ * typically contain sensitive API key and passwords. For a list of properties that are
284
+ * automatically sanitized, see the {@link sanitizeRequestOptions} method.
285
+ */
286
+ readonly requestOptionsToSanitize: string[];
287
+ userOptions: DoLookupUserOptions;
288
+ /**
289
+ * Optional middleware method for modifying {@link HttpRequestOptions} before a request is made
290
+ * via the {@link PolarityRequest.run} method or {@link PolarityRequest.runInParallel} method.
291
+ * The returned `requestOptions` object will be used for the request. This method is passed
292
+ * a copy of the original `requestOptions` object so it can be modified without side effects.
293
+ *
294
+ * This method is typically used for adding authentication (e.g., auth headers, or basic auth) to every request.
295
+ * It can also be used to add headers that are required on every request or conditionally add headers based
296
+ * on the passed in `userOptions`.
297
+ *
298
+ * This method can be set as part of the {@link PolarityRequestOptions} when creating a new instance of the
299
+ * {@link PolarityRequest} class or can be set after the fact.
300
+ *
301
+ * @param requestOptions - A copy of the request options used for the request. This object can be modified
302
+ * without side effects.
303
+ * @param userOptions - The user options passed into the `doLookup` method.
304
+ * @returns The modified request options to use for the request.
305
+ */
306
+ preprocessRequestOptions: PreprocessRequestOptions;
307
+ /**
308
+ * Optional middleware method for modifying the {@link HttpRequestResponse} after a successful request.
309
+ * The passed in {@link HttpRequestResponse} object is not a copy but can be safely modified without
310
+ * side effects. The returned `HttpRequestResponse` object will be used for the response.
311
+ *
312
+ * @param response - The HTTP response from the request.
313
+ * @param requestOptions - The request options used for the request.
314
+ * @param userOptions - The user options passed into the `doLookup` method.
315
+ */
316
+ postprocessRequestSuccess: PostprocessRequestSuccess;
317
+ /**
318
+ * Method that can be implemented to post-process the HTTP response after a failed request.
319
+ * This method is typically used to inspect the error thrown and either alter the error
320
+ * object (e.g., to change the error message property to something more specific), to ignore
321
+ * the error (by not rethrowing it), or to take a specific action based on the error (e.g.,
322
+ * in the case of a RetryRequestError you may want to retry the request or return a special
323
+ * payload to the integration front end).
324
+ *
325
+ * @param error - The error thrown during the request.
326
+ * @param requestOptions - The request options used for the request.
327
+ * @param userOptions - The user options passed into the `doLookup` method.
328
+ */
329
+ postprocessRequestFailure: PostprocessRequestFailure;
330
+ get throttlingOptions(): Bottleneck.ConstructorOptions;
331
+ set throttlingOptions(throttlingOptions: Bottleneck.ConstructorOptions);
332
+ constructor(options?: PolarityRequestOptions);
333
+ private configFieldIsValid;
334
+ /**
335
+ * Makes a single HTTP request and returns the response or throws an error
336
+ *
337
+ * @param requestOptions - request options used to make the HTTP request
338
+ * @returns The HTTP response
339
+ */
340
+ run(requestOptions: HttpRequestOptions): Promise<HttpRequestResponse> | never;
341
+ /**
342
+ * Checks whether the HTTP response is an API error and throws an ApiRequestError if it is.
343
+ *
344
+ * @param httpResponse - The HTTP response from the Postman request.
345
+ * @param requestOptions - The options used for the request.
346
+ *
347
+ * @throws {@link ApiRequestError}
348
+ * Throws an error if the response indicates an API error.
349
+ */
350
+ private maybeThrowApiRequestError;
351
+ /**
352
+ * Returns true if the `httpStatusCode` is not one of the rounded HTTP status codes
353
+ * specified in the PolarityRequest `roundedSuccessStatusCodes` property.
354
+ *
355
+ * @param httpStatusCode - A numeric HTTP Status Code
356
+ * @returns true if the provided `httpStatusCode` is an error code
357
+ */
358
+ private isHttpStatusCodeError;
359
+ /**
360
+ * Returns true indicating that the API returned an error if the `httpBody` contains
361
+ * one of the paths specified by the PolarityRequest `httpResponseErrorProperties`
362
+ * property.
363
+ *
364
+ * @param httpBody - body property from the HttpRequestResponse
365
+ * @returns `true` if the httpBody property contains properties specified in `httpResponseErrorProperties`
366
+ */
367
+ private hasHttpResponseErrorProperty;
368
+ /**
369
+ * Returns an error message based on the `httpResponseErrorMessageProperties` first. If no
370
+ * message is found, it then uses the `httpResponseErrorProperties` to attempt to find
371
+ * a suitable error message. If no message is still found, the `defaultMessage` is returned.
372
+ *
373
+ * @param httpBody - JSON Object returned by an HTTP Request
374
+ * @param defaultMessage - A default error message to use if no specific error messages are found
375
+ * @returns An error message
376
+ */
377
+ private getErrorMessageFromHttpResponse;
378
+ /**
379
+ * Given a list of `properties` which are strings representing JSON dot notation, this
380
+ * method returns the first string property found at the given JSON path
381
+ * in the given `object`.
382
+ *
383
+ * @param object - An object to find properties in
384
+ * @param properties - a list of JSON dot notation properties to look for within `object`
385
+ * @returns A string value of the property found within the given object or undefined if no value is found
386
+ */
387
+ private maybeGetStringPropertyValue;
388
+ /**
389
+ * Runs multiple requests in parallel with a limit on the maximum number of concurrent requests.
390
+ *
391
+ * When running multiple request at once it is often useful to be able to tie a specific request
392
+ * back to the entity the request is for. To support this, the `HttpRequestOptions` object accepts
393
+ * an optional `entity` property which can be assigned to the Entity the request is being made for.
394
+ * The `HttpRequestResponse` object returned by this method will include the same `entity` property
395
+ * making it easy to match the response to the entity.
396
+ *
397
+ * Alternatively, for requests that are made for multiple entities at once (e.g., a query that can
398
+ * search multiple entities at a time), the `HttpRequestOptions` object also has an `entities`
399
+ * property which accept an array of entity objects. Similar to the `entity`, the
400
+ * `entities` property will be set on the `HttpRequestResponse` object.
401
+ *
402
+ * Finally, if you are looking to pass through a custom request id you can do that using the
403
+ * `requestId` property.
404
+ *
405
+ * @param options - An array of request options for running requests in parallel.
406
+ * @returns A promise that resolves to an array of responses. If the `returnErrors` property is set to `true`
407
+ * then the response objects will have their `error` property set to the thrown error.
408
+ */
409
+ runInParallel(options: RunInParallelOptions): Promise<HttpRequestResponse[]>;
410
+ }
411
+ //# sourceMappingURL=polarity-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polarity-request.d.ts","sourceRoot":"","sources":["../../../lib/requests/polarity-request.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,YAAY,CAAC;AAMpC,OAAO,EACL,eAAe,EACf,YAAY,EACZ,iBAAiB,EAElB,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG5D;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAChC,kBAAkB,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IACzC,KAAK,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAE1F;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;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M;IACjD,WAAW,EAAE,mBAAmB,CAAQ;IAE/C;;;;;;;;;;;;;;;;;OAiBG;IACI,wBAAwB,EAAE,wBAAwB,CAIR;IAEjD;;;;;;;;OAQG;IACI,yBAAyB,EAAE,yBAAyB,CAMf;IAE5C;;;;;;;;;;;OAWG;IACI,yBAAyB,EAAE,yBAAyB,CAQzD;IAEF,IAAW,iBAAiB,IAAI,UAAU,CAAC,kBAAkB,CAE5D;IAID,IAAW,iBAAiB,CAAC,iBAAiB,EAAE,UAAU,CAAC,kBAAkB,EAkB5E;gBAEW,OAAO,GAAE,sBAA2B;IAuEhD,OAAO,CAAC,kBAAkB,CACsB;IAEhD;;;;;OAKG;IACU,GAAG,CACd,cAAc,EAAE,kBAAkB,GACjC,OAAO,CAAC,mBAAmB,CAAC,GAAG,KAAK;IA2EvC;;;;;;;;OAQG;IACH,OAAO,CAAC,yBAAyB;IAkEjC;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;;;;;;OAOG;IACH,OAAO,CAAC,4BAA4B;IAIpC;;;;;;;;OAQG;IACH,OAAO,CAAC,+BAA+B;IAkBvC;;;;;;;;OAQG;IACH,OAAO,CAAC,2BAA2B;IAiBnC;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,aAAa,CACxB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,EAAE,CAAC;CA4ClC"}
@@ -0,0 +1,20 @@
1
+ import type { HttpRequestOptions } from './polarity-request';
2
+ /**
3
+ * Sanitizes the request options by removing sensitive information
4
+ * from the provided request options object.
5
+ *
6
+ * Default sanitized paths are:
7
+ *
8
+ * - auth.password
9
+ * - auth.bearer
10
+ * - body.password
11
+ * - form.client_secret
12
+ * - headers.authorization
13
+ * - headers.x-api-key
14
+ *
15
+ * @param requestOptions - request options to sanitize
16
+ * @param additionalPathsToSanitize - array of additional paths to sanitize in addition to the
17
+ * default paths.
18
+ */
19
+ export declare function sanitizeRequestOptions(requestOptions: HttpRequestOptions, additionalPathsToSanitize?: string[]): HttpRequestOptions;
20
+ //# sourceMappingURL=sanitize-request-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-request-options.d.ts","sourceRoot":"","sources":["../../../lib/requests/sanitize-request-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAU7D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,EAAE,kBAAkB,EAClC,yBAAyB,GAAE,MAAM,EAAO,GACvC,kBAAkB,CA0BpB"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export type ValidationError = {
5
+ key: string;
6
+ message: string;
7
+ };
8
+ /**
9
+ * User options object passed into the integration's `doLookup` method.
10
+ *
11
+ * @example
12
+ * Example of the user options object passed into `doLookup`
13
+ * ```js
14
+ * function doLookup(entities, options, cb){
15
+ * // options here is of type DoLookupUserOptions
16
+ * }
17
+ * ```
18
+ *
19
+ * @example
20
+ * As an example, if your integration has a user option with a `key` value of
21
+ * `apiKey` within its `config.json`, the user options object passed into the `doLookup` method would look like:
22
+ * ```json
23
+ * {
24
+ * "apiKey": "XXXXXXXXXX"
25
+ * }
26
+ * ```
27
+ * @public
28
+ */
29
+ export type DoLookupUserOptions = {
30
+ [key: string]: PossibleUserOptionValue;
31
+ };
32
+ /**
33
+ * @public
34
+ */
35
+ export type ValidateOptionsUserOptions = {
36
+ [key: string]: ValidateOptionsUserOption;
37
+ };
38
+ /**
39
+ * @public
40
+ */
41
+ export type ValidateOptionsUserOption = {
42
+ integration_id?: string;
43
+ key: string;
44
+ value: PossibleUserOptionValue;
45
+ user_can_edit?: boolean;
46
+ admin_only?: boolean;
47
+ };
48
+ /**
49
+ * @public
50
+ */
51
+ export type PossibleUserOptionValue = undefined | string | number | boolean | DropdownUserOptionValue | DropdownUserOptionValue[];
52
+ /**
53
+ * @public
54
+ */
55
+ export type DropdownUserOptionValue = {
56
+ display: string;
57
+ value: string;
58
+ };
59
+ /**
60
+ * Represents a Polarity Entity object which is passed to an integration's
61
+ * doLookup method.
62
+ *
63
+ * @public
64
+ */
65
+ export type Entity = {
66
+ value: string;
67
+ types: EntityType[];
68
+ type: EntityType;
69
+ requestContext: {
70
+ requestType: 'onDemand';
71
+ isUserInitiated: boolean;
72
+ };
73
+ longitude: number;
74
+ latitude: number;
75
+ isURL: boolean;
76
+ isSHA512: boolean;
77
+ isSHA256: boolean;
78
+ isSHA1: boolean;
79
+ isPrivateIP: boolean;
80
+ isMD5: boolean;
81
+ isIPv6: boolean;
82
+ isIPv4: boolean;
83
+ isIP: boolean;
84
+ isHex: boolean;
85
+ isHash: boolean;
86
+ isHTMLTag: boolean;
87
+ isEmail: boolean;
88
+ isDomain: boolean;
89
+ hashType: string;
90
+ displayValue: string;
91
+ channels: string[];
92
+ IPType: string;
93
+ };
94
+ /**
95
+ * Entity Types including custom types
96
+ * @public
97
+ */
98
+ export type EntityType = StandardEntityType | '*' | 'custom' | `custom.${string}`;
99
+ /**
100
+ * List of supported entity type values
101
+ * @public
102
+ */
103
+ export type StandardEntityType = 'IP' | 'IPv4' | 'IPv4CIDR' | 'IPv6' | 'MAC' | 'MD5' | 'SHA1' | 'SHA256' | 'cve' | 'domain' | 'email' | 'hash' | 'string' | 'url';
104
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,uBAAuB,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,C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CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,GAAG,GACH,QAAQ,GACR,UAAU,MAAM,EAAE,CAAC;AAEvB;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC1B,IAAI,GACJ,MAAM,GACN,UAAU,GACV,MAAM,GACN,KAAK,GACL,KAAK,GACL,MAAM,GACN,QAAQ,GACR,KAAK,GACL,QAAQ,GACR,OAAO,GACP,MAAM,GACN,QAAQ,GACR,KAAK,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiRequestError = void 0;
4
+ const integration_error_1 = require("./integration-error");
5
+ /**
6
+ * API error for REST requests
7
+ *
8
+ * @public
9
+ */
10
+ class ApiRequestError extends integration_error_1.IntegrationError {
11
+ constructor(message, properties = {}) {
12
+ super(message, properties);
13
+ }
14
+ }
15
+ exports.ApiRequestError = ApiRequestError;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthRequestError = void 0;
4
+ const integration_error_1 = require("./integration-error");
5
+ /**
6
+ * Thrown by generateAccessToken method if there is a failure to fetch a token
7
+ *
8
+ * @public
9
+ */
10
+ class AuthRequestError extends integration_error_1.IntegrationError {
11
+ constructor(message, properties = {}) {
12
+ super(message, properties);
13
+ }
14
+ }
15
+ exports.AuthRequestError = AuthRequestError;
@@ -1,11 +1,23 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const parseErrorToReadableJson_1 = __importDefault(require("./parseErrorToReadableJson"));
7
- const RequestError_1 = __importDefault(require("./RequestError"));
8
- exports.default = {
9
- parseErrorToReadableJson: parseErrorToReadableJson_1.default,
10
- RequestError: RequestError_1.default
11
- };
17
+ __exportStar(require("./parse-error-to-readable-json"), exports);
18
+ __exportStar(require("./integration-error"), exports);
19
+ __exportStar(require("./api-request-error"), exports);
20
+ __exportStar(require("./auth-request-error"), exports);
21
+ __exportStar(require("./network-error"), exports);
22
+ __exportStar(require("./retry-request-error"), exports);
23
+ __exportStar(require("./library-usage-error"), exports);