polarity-integration-utils 0.1.0 → 3.1.3
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/README.md +30 -2
- package/dist/dts/context/cache.d.ts +149 -0
- package/dist/dts/context/cache.d.ts.map +1 -0
- package/dist/dts/context/index.d.ts +3 -0
- package/dist/dts/context/index.d.ts.map +1 -0
- package/dist/dts/context/integration-context.d.ts +16 -0
- package/dist/dts/context/integration-context.d.ts.map +1 -0
- package/dist/dts/errors/api-request-error.d.ts +10 -0
- package/dist/dts/errors/api-request-error.d.ts.map +1 -0
- package/dist/dts/errors/auth-request-error.d.ts +10 -0
- package/dist/dts/errors/auth-request-error.d.ts.map +1 -0
- package/dist/dts/errors/index.d.ts +8 -0
- package/dist/dts/errors/index.d.ts.map +1 -0
- package/dist/dts/errors/integration-error.d.ts +189 -0
- package/dist/dts/errors/integration-error.d.ts.map +1 -0
- package/dist/dts/errors/library-usage-error.d.ts +12 -0
- package/dist/dts/errors/library-usage-error.d.ts.map +1 -0
- package/dist/dts/errors/network-error.d.ts +11 -0
- package/dist/dts/errors/network-error.d.ts.map +1 -0
- package/dist/dts/errors/parse-error-to-readable-json.d.ts +7 -0
- package/dist/dts/errors/parse-error-to-readable-json.d.ts.map +1 -0
- package/dist/dts/errors/retry-request-error.d.ts +11 -0
- package/dist/dts/errors/retry-request-error.d.ts.map +1 -0
- package/dist/dts/index.d.ts +8 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/index.docs.d.ts +10 -0
- package/dist/dts/index.docs.d.ts.map +1 -0
- package/dist/dts/internal/helpers/parallel-limit.d.ts +9 -0
- package/dist/dts/internal/helpers/parallel-limit.d.ts.map +1 -0
- package/dist/dts/internal/helpers/sanitize-object.d.ts +11 -0
- package/dist/dts/internal/helpers/sanitize-object.d.ts.map +1 -0
- package/dist/dts/lib/context/cache.d.ts +149 -0
- package/dist/dts/lib/context/cache.d.ts.map +1 -0
- package/dist/dts/lib/context/index.d.ts +3 -0
- package/dist/dts/lib/context/index.d.ts.map +1 -0
- package/dist/dts/lib/context/integration-context.d.ts +16 -0
- package/dist/dts/lib/context/integration-context.d.ts.map +1 -0
- package/dist/dts/lib/errors/api-request-error.d.ts +10 -0
- package/dist/dts/lib/errors/api-request-error.d.ts.map +1 -0
- package/dist/dts/lib/errors/auth-request-error.d.ts +10 -0
- package/dist/dts/lib/errors/auth-request-error.d.ts.map +1 -0
- package/dist/dts/lib/errors/index.d.ts +8 -0
- package/dist/dts/lib/errors/index.d.ts.map +1 -0
- package/dist/dts/lib/errors/integration-error.d.ts +189 -0
- package/dist/dts/lib/errors/integration-error.d.ts.map +1 -0
- package/dist/dts/lib/errors/library-usage-error.d.ts +12 -0
- package/dist/dts/lib/errors/library-usage-error.d.ts.map +1 -0
- package/dist/dts/lib/errors/network-error.d.ts +11 -0
- package/dist/dts/lib/errors/network-error.d.ts.map +1 -0
- package/dist/dts/lib/errors/parse-error-to-readable-json.d.ts +7 -0
- package/dist/dts/lib/errors/parse-error-to-readable-json.d.ts.map +1 -0
- package/dist/dts/lib/errors/retry-request-error.d.ts +11 -0
- package/dist/dts/lib/errors/retry-request-error.d.ts.map +1 -0
- package/dist/dts/lib/index.d.ts +8 -0
- package/dist/dts/lib/index.d.ts.map +1 -0
- package/dist/dts/lib/index.docs.d.ts +10 -0
- package/dist/dts/lib/index.docs.d.ts.map +1 -0
- package/dist/dts/lib/internal/helpers/parallel-limit.d.ts +9 -0
- package/dist/dts/lib/internal/helpers/parallel-limit.d.ts.map +1 -0
- package/dist/dts/lib/internal/helpers/sanitize-object.d.ts +11 -0
- package/dist/dts/lib/internal/helpers/sanitize-object.d.ts.map +1 -0
- package/dist/dts/lib/logging/index.d.ts +2 -0
- package/dist/dts/lib/logging/index.d.ts.map +1 -0
- package/dist/dts/lib/logging/logger.d.ts +49 -0
- package/dist/dts/lib/logging/logger.d.ts.map +1 -0
- package/dist/dts/lib/requests/index.d.ts +3 -0
- package/dist/dts/lib/requests/index.d.ts.map +1 -0
- package/dist/dts/lib/requests/polarity-request.d.ts +411 -0
- package/dist/dts/lib/requests/polarity-request.d.ts.map +1 -0
- package/dist/dts/lib/requests/sanitize-request-options.d.ts +20 -0
- package/dist/dts/lib/requests/sanitize-request-options.d.ts.map +1 -0
- package/dist/dts/lib/testing/enhanced-utils/create-entity.d.ts +3 -0
- package/dist/dts/lib/testing/enhanced-utils/create-entity.d.ts.map +1 -0
- package/dist/dts/lib/testing/enhanced-utils/create-mock-integration-context.d.ts +3 -0
- package/dist/dts/lib/testing/enhanced-utils/create-mock-integration-context.d.ts.map +1 -0
- package/dist/dts/lib/testing/enhanced-utils/mock-request.d.ts +14 -0
- package/dist/dts/lib/testing/enhanced-utils/mock-request.d.ts.map +1 -0
- package/dist/dts/lib/testing/enhanced-utils/validate-integration.d.ts +8 -0
- package/dist/dts/lib/testing/enhanced-utils/validate-integration.d.ts.map +1 -0
- package/dist/dts/lib/testing/index.d.ts +6 -0
- package/dist/dts/lib/testing/index.d.ts.map +1 -0
- package/dist/dts/lib/testing/test-factory/create-integration-tests.d.ts +6 -0
- package/dist/dts/lib/testing/test-factory/create-integration-tests.d.ts.map +1 -0
- package/dist/dts/lib/testing/test-factory/test-do-lookup.d.ts +7 -0
- package/dist/dts/lib/testing/test-factory/test-do-lookup.d.ts.map +1 -0
- package/dist/dts/lib/testing/test-factory/test-on-message.d.ts +8 -0
- package/dist/dts/lib/testing/test-factory/test-on-message.d.ts.map +1 -0
- package/dist/dts/lib/types.d.ts +101 -0
- package/dist/dts/lib/types.d.ts.map +1 -0
- package/dist/dts/lib/zod-types.d.ts +278 -0
- package/dist/dts/lib/zod-types.d.ts.map +1 -0
- package/dist/dts/logging/index.d.ts +2 -0
- package/dist/dts/logging/index.d.ts.map +1 -0
- package/dist/dts/logging/logger.d.ts +49 -0
- package/dist/dts/logging/logger.d.ts.map +1 -0
- package/dist/dts/requests/index.d.ts +3 -0
- package/dist/dts/requests/index.d.ts.map +1 -0
- package/dist/dts/requests/polarity-request.d.ts +411 -0
- package/dist/dts/requests/polarity-request.d.ts.map +1 -0
- package/dist/dts/requests/sanitize-request-options.d.ts +20 -0
- package/dist/dts/requests/sanitize-request-options.d.ts.map +1 -0
- package/dist/dts/testing/enhanced-utils/create-entity.d.ts +3 -0
- package/dist/dts/testing/enhanced-utils/create-entity.d.ts.map +1 -0
- package/dist/dts/testing/enhanced-utils/create-mock-integration-context.d.ts +3 -0
- package/dist/dts/testing/enhanced-utils/create-mock-integration-context.d.ts.map +1 -0
- package/dist/dts/testing/enhanced-utils/mock-request.d.ts +14 -0
- package/dist/dts/testing/enhanced-utils/mock-request.d.ts.map +1 -0
- package/dist/dts/testing/enhanced-utils/validate-integration.d.ts +8 -0
- package/dist/dts/testing/enhanced-utils/validate-integration.d.ts.map +1 -0
- package/dist/dts/testing/index.d.ts +6 -0
- package/dist/dts/testing/index.d.ts.map +1 -0
- package/dist/dts/testing/test-factory/create-integration-tests.d.ts +6 -0
- package/dist/dts/testing/test-factory/create-integration-tests.d.ts.map +1 -0
- package/dist/dts/testing/test-factory/test-do-lookup.d.ts +7 -0
- package/dist/dts/testing/test-factory/test-do-lookup.d.ts.map +1 -0
- package/dist/dts/testing/test-factory/test-on-message.d.ts +8 -0
- package/dist/dts/testing/test-factory/test-on-message.d.ts.map +1 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/types.d.ts +101 -0
- package/dist/dts/types.d.ts.map +1 -0
- package/dist/dts/zod-types.d.ts +278 -0
- package/dist/dts/zod-types.d.ts.map +1 -0
- package/dist/es/lib/context/index.js +18 -0
- package/dist/es/lib/errors/api-request-error.js +15 -0
- package/dist/es/lib/errors/auth-request-error.js +15 -0
- package/dist/es/lib/errors/index.js +23 -0
- package/dist/es/lib/errors/integration-error.js +116 -0
- package/dist/es/lib/errors/library-usage-error.js +17 -0
- package/dist/es/lib/errors/network-error.js +88 -0
- package/dist/es/lib/errors/parse-error-to-readable-json.js +9 -0
- package/dist/es/lib/errors/retry-request-error.js +16 -0
- package/dist/es/lib/index.docs.js +25 -0
- package/dist/es/lib/index.js +50 -0
- package/dist/es/lib/internal/helpers/parallel-limit.js +36 -0
- package/dist/es/lib/internal/helpers/sanitize-object.js +37 -0
- package/dist/es/lib/logging/index.js +17 -0
- package/dist/es/lib/logging/logger.js +53 -0
- package/dist/es/lib/requests/index.js +18 -0
- package/dist/es/lib/requests/polarity-request.js +426 -0
- package/dist/es/lib/requests/sanitize-request-options.js +50 -0
- package/dist/es/lib/testing/enhanced-utils/create-entity.js +37 -0
- package/dist/es/lib/testing/enhanced-utils/create-mock-integration-context.js +36 -0
- package/dist/es/lib/testing/enhanced-utils/mock-request.js +22 -0
- package/dist/es/lib/testing/enhanced-utils/validate-integration.js +159 -0
- package/dist/es/lib/testing/index.js +21 -0
- package/dist/es/lib/testing/test-factory/create-integration-tests.js +53 -0
- package/dist/es/lib/testing/test-factory/test-do-lookup.js +24 -0
- package/dist/es/lib/testing/test-factory/test-on-message.js +24 -0
- package/dist/es/lib/types.js +5 -0
- package/dist/es/lib/zod-types.js +206 -0
- package/dist/lib/context/cache.js +2 -0
- package/dist/lib/context/index.js +18 -0
- package/dist/lib/context/integration-context.js +2 -0
- package/dist/lib/errors/api-request-error.js +15 -0
- package/dist/lib/errors/auth-request-error.js +15 -0
- package/dist/lib/errors/index.js +20 -8
- package/dist/lib/errors/integration-error.js +116 -0
- package/dist/lib/errors/library-usage-error.js +17 -0
- package/dist/lib/errors/network-error.js +88 -0
- package/dist/lib/errors/parse-error-to-readable-json.js +9 -0
- package/dist/lib/errors/retry-request-error.js +16 -0
- package/dist/lib/index.docs.js +25 -0
- package/dist/lib/index.js +47 -13
- package/dist/lib/internal/helpers/parallel-limit.js +36 -0
- package/dist/lib/internal/helpers/sanitize-object.js +37 -0
- package/dist/lib/logging/index.js +15 -2
- package/dist/lib/logging/logger.js +41 -5
- package/dist/lib/requests/index.js +15 -8
- package/dist/lib/requests/polarity-request.js +426 -0
- package/dist/lib/requests/sanitize-request-options.js +50 -0
- package/dist/lib/testing/enhanced-utils/create-entity.js +37 -0
- package/dist/lib/testing/enhanced-utils/create-mock-integration-context.js +36 -0
- package/dist/lib/testing/enhanced-utils/mock-request.js +22 -0
- package/dist/lib/testing/enhanced-utils/validate-integration.js +159 -0
- package/dist/lib/testing/index.js +21 -0
- package/dist/lib/testing/test-factory/create-integration-tests.js +53 -0
- package/dist/lib/testing/test-factory/test-do-lookup.js +24 -0
- package/dist/lib/testing/test-factory/test-on-message.js +24 -0
- package/dist/lib/types.js +5 -0
- package/dist/lib/zod-types.js +206 -0
- package/dist/polarity-integration-utils.d.ts +1259 -0
- package/package.json +81 -11
- package/dist/es/errors/RequestError.js +0 -12
- package/dist/es/errors/index.js +0 -11
- package/dist/es/errors/parseErrorToReadableJson.js +0 -4
- package/dist/es/helpers/async/index.js +0 -9
- package/dist/es/helpers/async/parallelLimit.js +0 -33
- package/dist/es/helpers/encodings/decodeBase64.js +0 -4
- package/dist/es/helpers/encodings/encodeBase64.js +0 -4
- package/dist/es/helpers/encodings/index.js +0 -11
- package/dist/es/helpers/index.js +0 -10
- package/dist/es/helpers/json/and.js +0 -4
- package/dist/es/helpers/json/filterObjectsContainingString.js +0 -10
- package/dist/es/helpers/json/index.js +0 -17
- package/dist/es/helpers/json/mapOverObject.js +0 -24
- package/dist/es/helpers/json/or.js +0 -4
- package/dist/es/helpers/json/transpose2dArray.js +0 -8
- package/dist/es/helpers/time/index.js +0 -11
- package/dist/es/helpers/time/millisecondsToHoursMinutesAndSeconds.js +0 -18
- package/dist/es/helpers/time/sleep.js +0 -13
- package/dist/es/index.js +0 -16
- package/dist/es/logging/index.js +0 -4
- package/dist/es/logging/logger.js +0 -17
- package/dist/es/requests/createRequestWithDefaults.js +0 -166
- package/dist/es/requests/createRequestsInParallel.js +0 -40
- package/dist/es/requests/index.js +0 -11
- package/dist/es/user-options/index.js +0 -9
- package/dist/es/user-options/validateUrlOption.js +0 -77
- package/dist/lib/errors/RequestError.js +0 -12
- package/dist/lib/errors/parseErrorToReadableJson.js +0 -4
- package/dist/lib/helpers/async/index.js +0 -9
- package/dist/lib/helpers/async/parallelLimit.js +0 -33
- package/dist/lib/helpers/encodings/decodeBase64.js +0 -4
- package/dist/lib/helpers/encodings/encodeBase64.js +0 -4
- package/dist/lib/helpers/encodings/index.js +0 -11
- package/dist/lib/helpers/index.js +0 -10
- package/dist/lib/helpers/json/and.js +0 -4
- package/dist/lib/helpers/json/filterObjectsContainingString.js +0 -10
- package/dist/lib/helpers/json/index.js +0 -17
- package/dist/lib/helpers/json/mapOverObject.js +0 -24
- package/dist/lib/helpers/json/or.js +0 -4
- package/dist/lib/helpers/json/transpose2dArray.js +0 -8
- package/dist/lib/helpers/time/index.js +0 -11
- package/dist/lib/helpers/time/millisecondsToHoursMinutesAndSeconds.js +0 -18
- package/dist/lib/helpers/time/sleep.js +0 -13
- package/dist/lib/requests/createRequestWithDefaults.js +0 -166
- package/dist/lib/requests/createRequestsInParallel.js +0 -40
- package/dist/lib/user-options/index.js +0 -9
- package/dist/lib/user-options/validateUrlOption.js +0 -77
- /package/dist/es/{requests/requestTypes.js → lib/context/cache.js} +0 -0
- /package/dist/{lib/requests/requestTypes.js → es/lib/context/integration-context.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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AEW,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 @@
|
|
|
1
|
+
{"version":3,"file":"create-entity.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/enhanced-utils/create-entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,YAAY,GAAI,MAAM,UAAU,EAAE,OAAO,MAAM,KAAG,MAmC9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-mock-integration-context.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/enhanced-utils/create-mock-integration-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,eAAO,MAAM,4BAA4B,QAAO,kBAgC/C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PolarityRequest } from '../../requests/polarity-request';
|
|
2
|
+
export declare const mockRequest: () => {
|
|
3
|
+
PolarityRequestMock: jest.MockedClass<typeof PolarityRequest>;
|
|
4
|
+
mockRequest: {
|
|
5
|
+
get: jest.Mock<any, any, any>;
|
|
6
|
+
post: jest.Mock<any, any, any>;
|
|
7
|
+
put: jest.Mock<any, any, any>;
|
|
8
|
+
delete: jest.Mock<any, any, any>;
|
|
9
|
+
patch: jest.Mock<any, any, any>;
|
|
10
|
+
head: jest.Mock<any, any, any>;
|
|
11
|
+
options: jest.Mock<any, any, any>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=mock-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-request.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/enhanced-utils/mock-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAIlE,eAAO,MAAM,WAAW;yBAcoB,IAAI,CAAC,WAAW,CAAC,OAAO,eAAe,CAAC;;;;;;;;;;CAGnF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Integration, IntegrationConfig } from '../../types';
|
|
2
|
+
export interface ValidationResult {
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
errors: string[];
|
|
5
|
+
warnings: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const validateIntegration: (integration: Integration, config?: IntegrationConfig) => ValidationResult;
|
|
8
|
+
//# sourceMappingURL=validate-integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-integration.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/enhanced-utils/validate-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAsB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKjF,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,mBAAmB,GAC9B,aAAa,WAAW,EACxB,SAAS,iBAAiB,KACzB,gBAoCF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './test-factory/create-integration-tests';
|
|
2
|
+
export * from './enhanced-utils/create-entity';
|
|
3
|
+
export * from './enhanced-utils/create-mock-integration-context';
|
|
4
|
+
export * from './enhanced-utils/mock-request';
|
|
5
|
+
export * from './enhanced-utils/validate-integration';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kDAAkD,CAAC;AACjE,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-integration-tests.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/test-factory/create-integration-tests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO1C,eAAO,MAAM,sBAAsB,GAAI,aAAa,WAAW;;;CAY9D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DoLookupResult, DoLookupUserOptions, Entity, Integration } from '../../types';
|
|
2
|
+
export declare const testDoLookup: (integration: Integration, description: string, { entities, options, expected }: {
|
|
3
|
+
entities: Entity[];
|
|
4
|
+
options: DoLookupUserOptions;
|
|
5
|
+
expected: DoLookupResult;
|
|
6
|
+
}) => void;
|
|
7
|
+
//# sourceMappingURL=test-do-lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-do-lookup.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/test-factory/test-do-lookup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAIvF,eAAO,MAAM,YAAY,GACvB,aAAa,WAAW,EACxB,aAAa,MAAM,EACnB,iCAIG;IACD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,QAAQ,EAAE,cAAc,CAAC;CAC1B,SAkBF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DoLookupUserOptions, Integration } from '../../types';
|
|
2
|
+
export declare const testOnMessage: (integration: Integration, description: string, { command, args, expected, options }: {
|
|
3
|
+
command: string;
|
|
4
|
+
args: Record<string, unknown>;
|
|
5
|
+
expected: unknown;
|
|
6
|
+
options?: DoLookupUserOptions;
|
|
7
|
+
}) => void;
|
|
8
|
+
//# sourceMappingURL=test-on-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-on-message.d.ts","sourceRoot":"","sources":["../../../../../lib/testing/test-factory/test-on-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/D,eAAO,MAAM,aAAa,GACxB,aAAa,WAAW,EACxB,aAAa,MAAM,EACnB,sCAKG;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,mBAAmB,CAAC;CAC/B,SAmBF,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Logger as PolarityLogger } from './logging';
|
|
3
|
+
import { ValidationErrorSchema, DoLookupUserOptionsSchema, ValidateOptionsUserOptionsSchema, ValidateOptionsUserOptionSchema, PossibleUserOptionValueSchema, DropdownUserOptionValueSchema, EntitySchema, EntityTypeSchema, StandardEntityTypeSchema, ChannelSchema, ResultSchema, IntegrationConfigSchema } from './zod-types';
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type ValidationError = z.infer<typeof ValidationErrorSchema>;
|
|
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 = z.infer<typeof DoLookupUserOptionsSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export type ValidateOptionsUserOptions = z.infer<typeof ValidateOptionsUserOptionsSchema>;
|
|
34
|
+
/**
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export type ValidateOptionsUserOption = z.infer<typeof ValidateOptionsUserOptionSchema>;
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export type PossibleUserOptionValue = z.infer<typeof PossibleUserOptionValueSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export type DropdownUserOptionValue = z.infer<typeof DropdownUserOptionValueSchema>;
|
|
46
|
+
/**
|
|
47
|
+
* Represents a Polarity Entity object which is passed to an integration's
|
|
48
|
+
* doLookup method.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export type Entity = z.infer<typeof EntitySchema>;
|
|
53
|
+
/**
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
export type Channel = z.infer<typeof ChannelSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* Entity Types including custom types
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export type EntityType = z.infer<typeof EntityTypeSchema>;
|
|
62
|
+
/**
|
|
63
|
+
* List of supported entity type values
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export type StandardEntityType = z.infer<typeof StandardEntityTypeSchema>;
|
|
67
|
+
/**
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export type Result<TDetails = unknown> = Omit<z.infer<typeof ResultSchema>, 'data'> & {
|
|
71
|
+
data: {
|
|
72
|
+
summary: string[];
|
|
73
|
+
details: TDetails;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export type DoLookupResult<TDetails = unknown> = Result<TDetails>[];
|
|
80
|
+
/**
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export type IntegrationConfig = z.infer<typeof IntegrationConfigSchema>;
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
export { PolarityLogger };
|
|
88
|
+
/**
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
import { IntegrationContext } from './context';
|
|
92
|
+
import { IntegrationError } from './errors';
|
|
93
|
+
export { IntegrationContext, IntegrationError };
|
|
94
|
+
export interface Integration<TStartupResult = unknown, TDetails = unknown> {
|
|
95
|
+
startup: (logger: PolarityLogger) => Promise<TStartupResult>;
|
|
96
|
+
doLookup: (entities: Entity[], options: DoLookupUserOptions, context: IntegrationContext) => Promise<DoLookupResult<TDetails> | IntegrationError | null | void>;
|
|
97
|
+
onMessage?: (payload: unknown, options: DoLookupUserOptions, context: IntegrationContext) => Promise<unknown>;
|
|
98
|
+
onDetails?: (lookupObject: Result<TDetails>, options: DoLookupUserOptions, context: IntegrationContext) => Promise<unknown>;
|
|
99
|
+
validateOptions: (options: ValidateOptionsUserOptions, context: IntegrationContext) => IntegrationError[];
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,WAAW,CAA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