polarity-integration-utils 4.1.1 → 4.2.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.
- package/dist/dts/cache/create-cache-key.d.ts +23 -0
- package/dist/dts/cache/create-cache-key.d.ts.map +1 -0
- package/dist/dts/cache/index.d.ts +2 -0
- package/dist/dts/cache/index.d.ts.map +1 -0
- package/dist/dts/errors/integration-error.d.ts +1 -0
- package/dist/dts/errors/integration-error.d.ts.map +1 -1
- package/dist/dts/errors/parse-error-to-readable-json.d.ts +2 -0
- package/dist/dts/errors/parse-error-to-readable-json.d.ts.map +1 -1
- package/dist/dts/index.d.ts +3 -1
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/index.docs.d.ts +1 -0
- package/dist/dts/index.docs.d.ts.map +1 -1
- package/dist/dts/logging/logger.d.ts +2 -0
- package/dist/dts/logging/logger.d.ts.map +1 -1
- package/dist/dts/requests/polarity-request.d.ts +1 -0
- package/dist/dts/requests/polarity-request.d.ts.map +1 -1
- package/dist/dts/requests/sanitize-request-options.d.ts +2 -0
- package/dist/dts/requests/sanitize-request-options.d.ts.map +1 -1
- package/dist/dts/testing/enhanced-utils/create-entity.d.ts +3 -0
- package/dist/dts/testing/enhanced-utils/create-entity.d.ts.map +1 -1
- package/dist/dts/testing/enhanced-utils/create-mock-integration-context.d.ts +4 -0
- package/dist/dts/testing/enhanced-utils/create-mock-integration-context.d.ts.map +1 -1
- package/dist/es/cache/create-cache-key.js +56 -0
- package/dist/es/cache/index.js +5 -0
- package/dist/es/{lib/errors → errors}/parse-error-to-readable-json.js +2 -0
- package/dist/es/{lib/index.docs.js → index.docs.js} +1 -0
- package/dist/es/{lib/index.js → index.js} +4 -1
- package/dist/es/{lib/logging → logging}/logger.js +2 -0
- package/dist/es/{lib/requests → requests}/polarity-request.js +1 -0
- package/dist/es/{lib/requests → requests}/sanitize-request-options.js +2 -0
- package/dist/es/{lib/testing → testing}/enhanced-utils/create-entity.js +3 -0
- package/dist/es/{lib/testing → testing}/enhanced-utils/create-mock-integration-context.js +3 -0
- package/dist/lib/cache/create-cache-key.js +56 -0
- package/dist/lib/cache/index.js +5 -0
- package/dist/lib/errors/parse-error-to-readable-json.js +2 -0
- package/dist/lib/index.docs.js +1 -0
- package/dist/lib/index.js +4 -1
- package/dist/lib/logging/logger.js +2 -0
- package/dist/lib/requests/polarity-request.js +1 -0
- package/dist/lib/requests/sanitize-request-options.js +2 -0
- package/dist/lib/testing/enhanced-utils/create-entity.js +3 -0
- package/dist/lib/testing/enhanced-utils/create-mock-integration-context.js +3 -0
- package/dist/polarity-integration-utils.d.ts +880 -842
- package/package.json +6 -1
- package/dist/dts/lib/errors/api-request-error.d.ts +0 -10
- package/dist/dts/lib/errors/api-request-error.d.ts.map +0 -1
- package/dist/dts/lib/errors/auth-request-error.d.ts +0 -10
- package/dist/dts/lib/errors/auth-request-error.d.ts.map +0 -1
- package/dist/dts/lib/errors/index.d.ts +0 -8
- package/dist/dts/lib/errors/index.d.ts.map +0 -1
- package/dist/dts/lib/errors/integration-error.d.ts +0 -189
- package/dist/dts/lib/errors/integration-error.d.ts.map +0 -1
- package/dist/dts/lib/errors/library-usage-error.d.ts +0 -12
- package/dist/dts/lib/errors/library-usage-error.d.ts.map +0 -1
- package/dist/dts/lib/errors/network-error.d.ts +0 -11
- package/dist/dts/lib/errors/network-error.d.ts.map +0 -1
- package/dist/dts/lib/errors/parse-error-to-readable-json.d.ts +0 -7
- package/dist/dts/lib/errors/parse-error-to-readable-json.d.ts.map +0 -1
- package/dist/dts/lib/errors/retry-request-error.d.ts +0 -11
- package/dist/dts/lib/errors/retry-request-error.d.ts.map +0 -1
- package/dist/dts/lib/index.d.ts +0 -9
- package/dist/dts/lib/index.d.ts.map +0 -1
- package/dist/dts/lib/index.docs.d.ts +0 -14
- package/dist/dts/lib/index.docs.d.ts.map +0 -1
- package/dist/dts/lib/internal/helpers/parallel-limit.d.ts +0 -9
- package/dist/dts/lib/internal/helpers/parallel-limit.d.ts.map +0 -1
- package/dist/dts/lib/internal/helpers/sanitize-object.d.ts +0 -11
- package/dist/dts/lib/internal/helpers/sanitize-object.d.ts.map +0 -1
- package/dist/dts/lib/logging/index.d.ts +0 -2
- package/dist/dts/lib/logging/index.d.ts.map +0 -1
- package/dist/dts/lib/logging/logger.d.ts +0 -38
- package/dist/dts/lib/logging/logger.d.ts.map +0 -1
- package/dist/dts/lib/requests/index.d.ts +0 -3
- package/dist/dts/lib/requests/index.d.ts.map +0 -1
- package/dist/dts/lib/requests/polarity-request.d.ts +0 -436
- package/dist/dts/lib/requests/polarity-request.d.ts.map +0 -1
- package/dist/dts/lib/requests/sanitize-request-options.d.ts +0 -20
- package/dist/dts/lib/requests/sanitize-request-options.d.ts.map +0 -1
- package/dist/dts/lib/testing/enhanced-utils/create-entity.d.ts +0 -19
- package/dist/dts/lib/testing/enhanced-utils/create-entity.d.ts.map +0 -1
- package/dist/dts/lib/testing/enhanced-utils/create-mock-integration-context.d.ts +0 -43
- package/dist/dts/lib/testing/enhanced-utils/create-mock-integration-context.d.ts.map +0 -1
- package/dist/dts/lib/testing/index.d.ts +0 -3
- package/dist/dts/lib/testing/index.d.ts.map +0 -1
- package/dist/dts/lib/types.d.ts +0 -105
- package/dist/dts/lib/types.d.ts.map +0 -1
- /package/dist/es/{lib/errors → errors}/api-request-error.js +0 -0
- /package/dist/es/{lib/errors → errors}/auth-request-error.js +0 -0
- /package/dist/es/{lib/errors → errors}/index.js +0 -0
- /package/dist/es/{lib/errors → errors}/integration-error.js +0 -0
- /package/dist/es/{lib/errors → errors}/library-usage-error.js +0 -0
- /package/dist/es/{lib/errors → errors}/network-error.js +0 -0
- /package/dist/es/{lib/errors → errors}/retry-request-error.js +0 -0
- /package/dist/es/{lib/internal → internal}/helpers/parallel-limit.js +0 -0
- /package/dist/es/{lib/internal → internal}/helpers/sanitize-object.js +0 -0
- /package/dist/es/{lib/logging → logging}/index.js +0 -0
- /package/dist/es/{lib/requests → requests}/index.js +0 -0
- /package/dist/es/{lib/testing → testing}/index.js +0 -0
- /package/dist/es/{lib/types.js → types.js} +0 -0
|
@@ -58,872 +58,910 @@ export declare type ConfigRequestProxyOptions = {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* Creates a
|
|
61
|
+
* Creates a cache-safe key by hashing the input values with SHA-256 and
|
|
62
|
+
* prepending a descriptive prefix.
|
|
62
63
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
64
|
+
* Use this to derive cache keys from dynamic or sensitive data (entity values,
|
|
65
|
+
* credentials, etc.) that may contain characters outside the allowed set.
|
|
65
66
|
*
|
|
66
|
-
* @param
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
67
|
+
* @param prefix - A short descriptive label using only letters, digits, dots,
|
|
68
|
+
* underscores, and hyphens (must match `/^[a-zA-Z0-9._-]+$/`).
|
|
69
|
+
* @param value - First value to hash (required).
|
|
70
|
+
* @param values - Additional values to hash (e.g., further credentials or identifiers).
|
|
71
|
+
* @returns A key in the form `prefix_<64-char hex hash>`.
|
|
69
72
|
*
|
|
70
|
-
* @
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export declare const createEntity: (type: EntityType, value: string) => Entity;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Creates a mock `IntegrationContext`
|
|
80
|
-
* with stubbed logger, cache, and polling methods.
|
|
81
|
-
*
|
|
82
|
-
* Pass your testing framework's mock function factory to enable spy capabilities
|
|
83
|
-
* (e.g., `toHaveBeenCalledWith()`). When omitted, plain no-op stubs are used.
|
|
84
|
-
*
|
|
85
|
-
* @param createMockFn - A factory that creates mock functions (e.g., `vi.fn` or `jest.fn`)
|
|
86
|
-
* @returns A fully populated `IntegrationContext` with stubbed methods
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* // Vitest
|
|
91
|
-
* const ctx = createMockIntegrationContext(vi.fn);
|
|
92
|
-
*
|
|
93
|
-
* // Jest
|
|
94
|
-
* const ctx = createMockIntegrationContext(jest.fn);
|
|
95
|
-
*
|
|
96
|
-
* // No framework — plain no-ops
|
|
97
|
-
* const ctx = createMockIntegrationContext();
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
export declare const createMockIntegrationContext: (createMockFn?: MockFnFactory) => IntegrationContext;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Custom entity type definition for config.json
|
|
104
|
-
* @public
|
|
105
|
-
*/
|
|
106
|
-
export declare interface CustomType {
|
|
107
|
-
type?: 'custom';
|
|
108
|
-
name?: string;
|
|
109
|
-
description?: string;
|
|
110
|
-
key: string;
|
|
111
|
-
regex: string;
|
|
112
|
-
editable?: boolean;
|
|
113
|
-
enabled?: boolean;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @public
|
|
118
|
-
*/
|
|
119
|
-
export declare type ErrorMeta = {
|
|
120
|
-
[otherMetadata: string]: unknown;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* return the logger object set via the {@link setLogger} method.
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* Example of using the integration's logging object:
|
|
128
|
-
* ```js
|
|
129
|
-
* const { getLogger } = require('polarity-integration-utils');
|
|
130
|
-
*
|
|
131
|
-
* const logger = getLogger();
|
|
132
|
-
* logger.trace('this is a trace message');
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* @public
|
|
136
|
-
* @returns the integration's logger object
|
|
137
|
-
*/
|
|
138
|
-
export declare const getLogger: () => Logger;
|
|
139
|
-
|
|
140
|
-
export declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* @public
|
|
144
|
-
*/
|
|
145
|
-
export declare type HttpRequestOptions = {
|
|
146
|
-
/**
|
|
147
|
-
* The URL to make the request to.
|
|
148
|
-
*/
|
|
149
|
-
url?: string;
|
|
150
|
-
/**
|
|
151
|
-
* The HTTP method to use for the request.
|
|
152
|
-
*
|
|
153
|
-
* @defaultValue 'GET'
|
|
154
|
-
*/
|
|
155
|
-
method?: HttpMethod;
|
|
156
|
-
/**
|
|
157
|
-
* If true, sets body to JSON representation of value and adds Content-type: application/json header.
|
|
158
|
-
* Additionally, parses the response body as JSON.
|
|
73
|
+
* @throws {@link LibraryUsageError}
|
|
74
|
+
* If `prefix` or `value` is not a string, if `prefix` is empty or contains
|
|
75
|
+
* invalid characters, if any additional value is not a string, or if the
|
|
76
|
+
* resulting key would exceed 250 characters.
|
|
159
77
|
*
|
|
160
|
-
*
|
|
161
|
-
|
|
162
|
-
json?: boolean;
|
|
163
|
-
/**
|
|
164
|
-
* An object containing the headers to include in the request.
|
|
165
|
-
* @example
|
|
166
|
-
* Here is an example of setting the "X-Api-Key" `headers` property:
|
|
167
|
-
* ```
|
|
168
|
-
* {
|
|
169
|
-
* headers: {
|
|
170
|
-
* 'X-Api-Key': '1234567890'
|
|
171
|
-
* }
|
|
172
|
-
* }
|
|
173
|
-
* ```
|
|
174
|
-
*/
|
|
175
|
-
headers?: object;
|
|
176
|
-
/**
|
|
177
|
-
* An object containing querystring parameters to include in the request.
|
|
178
|
-
* @example
|
|
179
|
-
* Here is an example of setting the `qs` property:
|
|
180
|
-
* ```
|
|
181
|
-
* {
|
|
182
|
-
* qs: {
|
|
183
|
-
* search: 'foo'
|
|
184
|
-
* }
|
|
185
|
-
* }
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
qs?: object;
|
|
189
|
-
/**
|
|
190
|
-
* When passed an object or a querystring, this sets body to a querystring representation of value,
|
|
191
|
-
* and adds Content-type: application/x-www-form-urlencoded header.
|
|
192
|
-
*/
|
|
193
|
-
form?: object;
|
|
194
|
-
/**
|
|
195
|
-
* The body of the request.
|
|
196
|
-
*/
|
|
197
|
-
body?: object;
|
|
198
|
-
/**
|
|
199
|
-
* The authentication options to use for the request
|
|
200
|
-
*/
|
|
201
|
-
auth?: {
|
|
202
|
-
username: string;
|
|
203
|
-
password: string;
|
|
204
|
-
sendImmediately?: boolean;
|
|
205
|
-
} | {
|
|
206
|
-
bearer: string;
|
|
207
|
-
sendImmediately?: boolean;
|
|
208
|
-
};
|
|
209
|
-
[key: string]: unknown;
|
|
210
|
-
} & ({
|
|
211
|
-
entity: Entity;
|
|
212
|
-
entities?: never;
|
|
213
|
-
requestId?: never;
|
|
214
|
-
} | {
|
|
215
|
-
entities: Entity[];
|
|
216
|
-
entity?: never;
|
|
217
|
-
requestId?: never;
|
|
218
|
-
} | {
|
|
219
|
-
requestId: string | unknown;
|
|
220
|
-
entity?: never;
|
|
221
|
-
entities?: never;
|
|
222
|
-
} | {
|
|
223
|
-
entity?: never;
|
|
224
|
-
entities?: never;
|
|
225
|
-
requestId?: never;
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* @public
|
|
230
|
-
*/
|
|
231
|
-
export declare type HttpRequestResponse = {
|
|
232
|
-
/**
|
|
233
|
-
* The HTTP status code of the response.
|
|
234
|
-
*/
|
|
235
|
-
statusCode: number;
|
|
236
|
-
request: {
|
|
237
|
-
uri: unknown;
|
|
238
|
-
method: string;
|
|
239
|
-
headers: unknown;
|
|
240
|
-
[key: string]: unknown;
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* The body of the response.
|
|
244
|
-
*/
|
|
245
|
-
body: unknown;
|
|
246
|
-
/**
|
|
247
|
-
* The response headers
|
|
248
|
-
*/
|
|
249
|
-
headers: unknown;
|
|
250
|
-
/**
|
|
251
|
-
* The error object if an error occurred during the request.
|
|
252
|
-
*/
|
|
253
|
-
error?: ApiRequestError | NetworkError | RetryRequestError;
|
|
254
|
-
/**
|
|
255
|
-
* The entity that the request was made for. The `entity` property matches the
|
|
256
|
-
* `entity` property set on the {@link HttpRequestOptions} object associated with this HttpRequestResponse.
|
|
257
|
-
*/
|
|
258
|
-
entity?: Entity;
|
|
259
|
-
/**
|
|
260
|
-
* An array of entities that the request was made for. The `entities` property
|
|
261
|
-
* matches the `entities` property set on the {@link HttpRequestOptions} object associated
|
|
262
|
-
* with this HttpRequestResponse.
|
|
263
|
-
*/
|
|
264
|
-
entities?: Entity[];
|
|
265
|
-
/**
|
|
266
|
-
* A custom request id that can be used to identify the request. The `requestId` matches
|
|
267
|
-
* the `requestId` property set on the {@link HttpRequestOptions} object.
|
|
268
|
-
*/
|
|
269
|
-
requestId?: string | unknown;
|
|
270
|
-
[key: string]: unknown;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Integration config.json type
|
|
275
|
-
* @public
|
|
276
|
-
*/
|
|
277
|
-
export declare interface IntegrationConfig {
|
|
278
|
-
polarityIntegrationUuid: string;
|
|
279
|
-
name: string;
|
|
280
|
-
acronym: string;
|
|
281
|
-
description?: string;
|
|
282
|
-
defaultColor?: string;
|
|
283
|
-
entityTypes?: string[];
|
|
284
|
-
dataTypes?: (string | CustomType)[];
|
|
285
|
-
customTypes?: CustomType[];
|
|
286
|
-
supportsAdditionalCustomTypes?: boolean;
|
|
287
|
-
styles?: string[];
|
|
288
|
-
block: ViewComponent;
|
|
289
|
-
summary?: ViewComponent;
|
|
290
|
-
onDemandOnly?: boolean;
|
|
291
|
-
copyOnDemand?: boolean;
|
|
292
|
-
logging?: {
|
|
293
|
-
level: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
294
|
-
};
|
|
295
|
-
request?: {
|
|
296
|
-
cert?: string;
|
|
297
|
-
key?: string;
|
|
298
|
-
passphrase?: string;
|
|
299
|
-
ca?: string;
|
|
300
|
-
proxy?: string;
|
|
301
|
-
rejectUnauthorized?: boolean;
|
|
302
|
-
};
|
|
303
|
-
options?: IntegrationOption[];
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* @public
|
|
308
|
-
*/
|
|
309
|
-
export declare class IntegrationError extends Error {
|
|
310
|
-
/**
|
|
311
|
-
* a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of
|
|
312
|
-
* the problem except for purposes of localization.
|
|
313
|
-
*/
|
|
314
|
-
readonly title: string;
|
|
315
|
-
/**
|
|
316
|
-
* a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be
|
|
317
|
-
* localized
|
|
318
|
-
*/
|
|
319
|
-
readonly detail: string;
|
|
320
|
-
/**
|
|
321
|
-
* a meta object containing non-standard meta-information about the error.
|
|
322
|
-
*/
|
|
323
|
-
readonly meta?: ErrorMeta;
|
|
324
|
-
/**
|
|
325
|
-
* The HTTP status code applicable to this error, expressed as a string value.
|
|
326
|
-
*/
|
|
327
|
-
readonly status?: string;
|
|
328
|
-
/**
|
|
329
|
-
* an application-specific error code, expressed as a string value.
|
|
330
|
-
*/
|
|
331
|
-
readonly code?: string;
|
|
332
|
-
/**
|
|
333
|
-
* The `cause` property is used to specify the `cause` of the error. Typically,
|
|
334
|
-
* this property is used to pass through a related Error instance but can be any value.
|
|
335
|
-
*/
|
|
336
|
-
readonly cause?: unknown;
|
|
337
|
-
/**
|
|
338
|
-
* Additional details related to the error that may help the user troubleshoot the issue. If set by the user
|
|
339
|
-
* via the Error constructor, the user provided value will override any automated help message set by the
|
|
340
|
-
* Error class.
|
|
341
|
-
*/
|
|
342
|
-
readonly help?: string;
|
|
343
|
-
/**
|
|
344
|
-
* Relevant for integration errors involving a network call, the `requestOptions` property
|
|
345
|
-
* details the request options that resulted in the specified error. The `requestOptions` property will automatically
|
|
346
|
-
* have sensitive authentication headers stripped.
|
|
347
|
-
*/
|
|
348
|
-
readonly requestOptions?: HttpRequestOptions;
|
|
349
|
-
/**
|
|
350
|
-
* Construct a new IntegrationError object.
|
|
351
|
-
* @param message - A string description of the error which is used as the `detail` property on the
|
|
352
|
-
* serialized error.
|
|
353
|
-
* @param properties - Optional properties for the error.
|
|
354
|
-
*/
|
|
355
|
-
constructor(message: string, properties?: IntegrationErrorProperties);
|
|
356
|
-
/**
|
|
357
|
-
* Serializes the error's properties into a POJO. The order of the
|
|
358
|
-
* properties is preserved when serialized.
|
|
359
|
-
* @returns JSON representation of the error
|
|
360
|
-
*/
|
|
361
|
-
toJSON(): SerializedIntegrationError;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* @public
|
|
366
|
-
*/
|
|
367
|
-
export declare interface IntegrationErrorProperties {
|
|
368
|
-
/**
|
|
369
|
-
* a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of
|
|
370
|
-
* the problem except for purposes of localization. If omitted, the title will default to the type
|
|
371
|
-
* of error (e.g., IntegrationError, or ApiRequestError)
|
|
372
|
-
*/
|
|
373
|
-
title?: string;
|
|
374
|
-
/**
|
|
375
|
-
* Additional details related to the error that may help the user troubleshoot the issue. If set by the user
|
|
376
|
-
* via the Error constructor, the user provided value will override any automated help message set by the
|
|
377
|
-
* Error class.
|
|
378
|
-
*/
|
|
379
|
-
help?: string;
|
|
380
|
-
/**
|
|
381
|
-
* The `cause` property is used to specify the `cause` of the error. Typically,
|
|
382
|
-
* this property is used to pass through a related Error instance but can be any value.
|
|
383
|
-
*/
|
|
384
|
-
cause?: unknown;
|
|
385
|
-
/**
|
|
386
|
-
* The HTTP status code applicable to this error, expressed as a string value.
|
|
387
|
-
*/
|
|
388
|
-
status?: string;
|
|
389
|
-
/**
|
|
390
|
-
* an application-specific error code, expressed as a string value.
|
|
391
|
-
*/
|
|
392
|
-
code?: string;
|
|
393
|
-
/**
|
|
394
|
-
* Relevant for integration errors involving a network call, the `requestOptions` property
|
|
395
|
-
* details the request options that resulted in the specified error. The `requestOptions` property will automatically
|
|
396
|
-
* have sensitive authentication headers stripped.
|
|
397
|
-
* By default, the following paths are sanitized:
|
|
398
|
-
*
|
|
399
|
-
* - auth.password
|
|
400
|
-
* - auth.bearer
|
|
401
|
-
* - body.password
|
|
402
|
-
* - form.client_secret
|
|
403
|
-
* - headers.authorization
|
|
404
|
-
* - headers.x-api-key
|
|
405
|
-
*
|
|
406
|
-
* Additional paths can be sanitized by using the `requestOptionsToSanitize` property.
|
|
407
|
-
*/
|
|
408
|
-
requestOptions?: HttpRequestOptions;
|
|
409
|
-
/**
|
|
410
|
-
* List of paths in JSON dot notation to sanitize in the requestOptions object
|
|
411
|
-
*/
|
|
412
|
-
requestOptionsToSanitize?: string[];
|
|
413
|
-
/**
|
|
414
|
-
* Any additional properties which will be appended to the Error's meta property
|
|
415
|
-
*/
|
|
416
|
-
meta?: MetaObject;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Integration option definition for config.json
|
|
421
|
-
* @public
|
|
422
|
-
*/
|
|
423
|
-
export declare type IntegrationOption = {
|
|
424
|
-
type: 'text' | 'password';
|
|
425
|
-
key: string;
|
|
426
|
-
name: string;
|
|
427
|
-
description?: string;
|
|
428
|
-
default: string | null;
|
|
429
|
-
userCanEdit?: boolean;
|
|
430
|
-
adminOnly?: boolean;
|
|
431
|
-
} | {
|
|
432
|
-
type: 'boolean';
|
|
433
|
-
key: string;
|
|
434
|
-
name: string;
|
|
435
|
-
description?: string;
|
|
436
|
-
default: boolean | null;
|
|
437
|
-
userCanEdit?: boolean;
|
|
438
|
-
adminOnly?: boolean;
|
|
439
|
-
} | {
|
|
440
|
-
type: 'number';
|
|
441
|
-
key: string;
|
|
442
|
-
name: string;
|
|
443
|
-
description?: string;
|
|
444
|
-
default: number | null;
|
|
445
|
-
userCanEdit?: boolean;
|
|
446
|
-
adminOnly?: boolean;
|
|
447
|
-
} | {
|
|
448
|
-
type: 'select';
|
|
449
|
-
key: string;
|
|
450
|
-
name: string;
|
|
451
|
-
description?: string;
|
|
452
|
-
default: SelectOptionItem | SelectOptionItem[] | string | null;
|
|
453
|
-
options: SelectOptionItem[];
|
|
454
|
-
multiple?: boolean;
|
|
455
|
-
userCanEdit: boolean;
|
|
456
|
-
adminOnly: boolean;
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
/**
|
|
460
|
-
* @public
|
|
461
|
-
*/
|
|
462
|
-
export declare type IsApiErrorFunction = (response: HttpRequestResponse, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => IsApiErrorResult;
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* @public
|
|
466
|
-
*/
|
|
467
|
-
export declare type IsApiErrorResult = {
|
|
468
|
-
/**
|
|
469
|
-
* Indicates whether the response is an API error.
|
|
470
|
-
*/
|
|
471
|
-
isApiError: boolean;
|
|
472
|
-
/**
|
|
473
|
-
* Optional message providing additional information about the API error. The
|
|
474
|
-
* returned `message` will be used as the `message` property on the {@link ApiRequestError} object
|
|
475
|
-
* thrown by the request.
|
|
78
|
+
* @group Utilities
|
|
79
|
+
* @public
|
|
476
80
|
*/
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
export declare
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
export declare const
|
|
81
|
+
export declare function createCacheKey(prefix: string, value: string, ...values: string[]): string;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Creates a mock `Entity` for use in tests.
|
|
85
|
+
*
|
|
86
|
+
* Automatically detects whether the value is a domain or IPv4 address and sets
|
|
87
|
+
* the corresponding boolean flags. All other flags default to `false`.
|
|
88
|
+
*
|
|
89
|
+
* @param type - An `EntityType` string (e.g., `'IPv4'`, `'domain'`, `'MD5'`)
|
|
90
|
+
* @param value - The entity value string
|
|
91
|
+
* @returns A fully populated `Entity` object
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const ip = createEntity('IPv4', '8.8.8.8');
|
|
96
|
+
* const domain = createEntity('domain', 'example.com');
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @group Testing
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export declare const createEntity: (type: EntityType, value: string) => Entity;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates a mock `IntegrationContext`
|
|
106
|
+
* with stubbed logger, cache, and polling methods.
|
|
107
|
+
*
|
|
108
|
+
* Pass your testing framework's mock function factory to enable spy capabilities
|
|
109
|
+
* (e.g., `toHaveBeenCalledWith()`). When omitted, plain no-op stubs are used.
|
|
110
|
+
*
|
|
111
|
+
* @param createMockFn - A factory that creates mock functions (e.g., `vi.fn` or `jest.fn`)
|
|
112
|
+
* @returns A fully populated `IntegrationContext` with stubbed methods
|
|
113
|
+
*
|
|
114
|
+
* @group Testing
|
|
115
|
+
* @public
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // Vitest
|
|
120
|
+
* const ctx = createMockIntegrationContext(vi.fn);
|
|
121
|
+
*
|
|
122
|
+
* // Jest
|
|
123
|
+
* const ctx = createMockIntegrationContext(jest.fn);
|
|
124
|
+
*
|
|
125
|
+
* // No framework — plain no-ops
|
|
126
|
+
* const ctx = createMockIntegrationContext();
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare const createMockIntegrationContext: (createMockFn?: MockFnFactory) => IntegrationContext;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Custom entity type definition for config.json
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export declare interface CustomType {
|
|
136
|
+
type?: 'custom';
|
|
137
|
+
name?: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
key: string;
|
|
140
|
+
regex: string;
|
|
141
|
+
editable?: boolean;
|
|
142
|
+
enabled?: boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
export declare type ErrorMeta = {
|
|
149
|
+
[otherMetadata: string]: unknown;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* return the logger object set via the {@link setLogger} method.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* Example of using the integration's logging object:
|
|
157
|
+
* ```js
|
|
158
|
+
* const { getLogger } = require('polarity-integration-utils');
|
|
159
|
+
*
|
|
160
|
+
* const logger = getLogger();
|
|
161
|
+
* logger.trace('this is a trace message');
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @group Logging
|
|
165
|
+
* @public
|
|
166
|
+
* @returns the integration's logger object
|
|
167
|
+
*/
|
|
168
|
+
export declare const getLogger: () => Logger;
|
|
169
|
+
|
|
170
|
+
export declare type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
export declare type HttpRequestOptions = {
|
|
176
|
+
/**
|
|
177
|
+
* The URL to make the request to.
|
|
178
|
+
*/
|
|
179
|
+
url?: string;
|
|
180
|
+
/**
|
|
181
|
+
* The HTTP method to use for the request.
|
|
182
|
+
*
|
|
183
|
+
* @defaultValue 'GET'
|
|
184
|
+
*/
|
|
185
|
+
method?: HttpMethod;
|
|
186
|
+
/**
|
|
187
|
+
* If true, sets body to JSON representation of value and adds Content-type: application/json header.
|
|
188
|
+
* Additionally, parses the response body as JSON.
|
|
189
|
+
*
|
|
190
|
+
* @defaultValue true
|
|
191
|
+
*/
|
|
192
|
+
json?: boolean;
|
|
193
|
+
/**
|
|
194
|
+
* An object containing the headers to include in the request.
|
|
195
|
+
* @example
|
|
196
|
+
* Here is an example of setting the "X-Api-Key" `headers` property:
|
|
197
|
+
* ```
|
|
198
|
+
* {
|
|
199
|
+
* headers: {
|
|
200
|
+
* 'X-Api-Key': '1234567890'
|
|
201
|
+
* }
|
|
202
|
+
* }
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
headers?: object;
|
|
206
|
+
/**
|
|
207
|
+
* An object containing querystring parameters to include in the request.
|
|
208
|
+
* @example
|
|
209
|
+
* Here is an example of setting the `qs` property:
|
|
210
|
+
* ```
|
|
211
|
+
* {
|
|
212
|
+
* qs: {
|
|
213
|
+
* search: 'foo'
|
|
214
|
+
* }
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
qs?: object;
|
|
219
|
+
/**
|
|
220
|
+
* When passed an object or a querystring, this sets body to a querystring representation of value,
|
|
221
|
+
* and adds Content-type: application/x-www-form-urlencoded header.
|
|
222
|
+
*/
|
|
223
|
+
form?: object;
|
|
224
|
+
/**
|
|
225
|
+
* The body of the request.
|
|
226
|
+
*/
|
|
227
|
+
body?: object;
|
|
228
|
+
/**
|
|
229
|
+
* The authentication options to use for the request
|
|
230
|
+
*/
|
|
231
|
+
auth?: {
|
|
232
|
+
username: string;
|
|
233
|
+
password: string;
|
|
234
|
+
sendImmediately?: boolean;
|
|
235
|
+
} | {
|
|
236
|
+
bearer: string;
|
|
237
|
+
sendImmediately?: boolean;
|
|
238
|
+
};
|
|
239
|
+
[key: string]: unknown;
|
|
240
|
+
} & ({
|
|
241
|
+
entity: Entity;
|
|
242
|
+
entities?: never;
|
|
243
|
+
requestId?: never;
|
|
244
|
+
} | {
|
|
245
|
+
entities: Entity[];
|
|
246
|
+
entity?: never;
|
|
247
|
+
requestId?: never;
|
|
248
|
+
} | {
|
|
249
|
+
requestId: string | unknown;
|
|
250
|
+
entity?: never;
|
|
251
|
+
entities?: never;
|
|
252
|
+
} | {
|
|
253
|
+
entity?: never;
|
|
254
|
+
entities?: never;
|
|
255
|
+
requestId?: never;
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @public
|
|
260
|
+
*/
|
|
261
|
+
export declare type HttpRequestResponse = {
|
|
262
|
+
/**
|
|
263
|
+
* The HTTP status code of the response.
|
|
264
|
+
*/
|
|
265
|
+
statusCode: number;
|
|
266
|
+
request: {
|
|
267
|
+
uri: unknown;
|
|
268
|
+
method: string;
|
|
269
|
+
headers: unknown;
|
|
270
|
+
[key: string]: unknown;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* The body of the response.
|
|
274
|
+
*/
|
|
275
|
+
body: unknown;
|
|
276
|
+
/**
|
|
277
|
+
* The response headers
|
|
278
|
+
*/
|
|
279
|
+
headers: unknown;
|
|
280
|
+
/**
|
|
281
|
+
* The error object if an error occurred during the request.
|
|
282
|
+
*/
|
|
283
|
+
error?: ApiRequestError | NetworkError | RetryRequestError;
|
|
284
|
+
/**
|
|
285
|
+
* The entity that the request was made for. The `entity` property matches the
|
|
286
|
+
* `entity` property set on the {@link HttpRequestOptions} object associated with this HttpRequestResponse.
|
|
287
|
+
*/
|
|
288
|
+
entity?: Entity;
|
|
289
|
+
/**
|
|
290
|
+
* An array of entities that the request was made for. The `entities` property
|
|
291
|
+
* matches the `entities` property set on the {@link HttpRequestOptions} object associated
|
|
292
|
+
* with this HttpRequestResponse.
|
|
293
|
+
*/
|
|
294
|
+
entities?: Entity[];
|
|
295
|
+
/**
|
|
296
|
+
* A custom request id that can be used to identify the request. The `requestId` matches
|
|
297
|
+
* the `requestId` property set on the {@link HttpRequestOptions} object.
|
|
298
|
+
*/
|
|
299
|
+
requestId?: string | unknown;
|
|
300
|
+
[key: string]: unknown;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Integration config.json type
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
export declare interface IntegrationConfig {
|
|
308
|
+
polarityIntegrationUuid: string;
|
|
309
|
+
name: string;
|
|
310
|
+
acronym: string;
|
|
311
|
+
description?: string;
|
|
312
|
+
defaultColor?: string;
|
|
313
|
+
entityTypes?: string[];
|
|
314
|
+
dataTypes?: (string | CustomType)[];
|
|
315
|
+
customTypes?: CustomType[];
|
|
316
|
+
supportsAdditionalCustomTypes?: boolean;
|
|
317
|
+
styles?: string[];
|
|
318
|
+
block: ViewComponent;
|
|
319
|
+
summary?: ViewComponent;
|
|
320
|
+
onDemandOnly?: boolean;
|
|
321
|
+
copyOnDemand?: boolean;
|
|
322
|
+
logging?: {
|
|
323
|
+
level: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
324
|
+
};
|
|
325
|
+
request?: {
|
|
326
|
+
cert?: string;
|
|
327
|
+
key?: string;
|
|
328
|
+
passphrase?: string;
|
|
329
|
+
ca?: string;
|
|
330
|
+
proxy?: string;
|
|
331
|
+
rejectUnauthorized?: boolean;
|
|
332
|
+
};
|
|
333
|
+
options?: IntegrationOption[];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
export declare class IntegrationError extends Error {
|
|
340
|
+
/**
|
|
341
|
+
* a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of
|
|
342
|
+
* the problem except for purposes of localization.
|
|
343
|
+
*/
|
|
344
|
+
readonly title: string;
|
|
345
|
+
/**
|
|
346
|
+
* a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be
|
|
347
|
+
* localized
|
|
348
|
+
*/
|
|
349
|
+
readonly detail: string;
|
|
350
|
+
/**
|
|
351
|
+
* a meta object containing non-standard meta-information about the error.
|
|
352
|
+
*/
|
|
353
|
+
readonly meta?: ErrorMeta;
|
|
354
|
+
/**
|
|
355
|
+
* The HTTP status code applicable to this error, expressed as a string value.
|
|
356
|
+
*/
|
|
357
|
+
readonly status?: string;
|
|
358
|
+
/**
|
|
359
|
+
* an application-specific error code, expressed as a string value.
|
|
360
|
+
*/
|
|
361
|
+
readonly code?: string;
|
|
362
|
+
/**
|
|
363
|
+
* The `cause` property is used to specify the `cause` of the error. Typically,
|
|
364
|
+
* this property is used to pass through a related Error instance but can be any value.
|
|
365
|
+
*/
|
|
366
|
+
readonly cause?: unknown;
|
|
367
|
+
/**
|
|
368
|
+
* Additional details related to the error that may help the user troubleshoot the issue. If set by the user
|
|
369
|
+
* via the Error constructor, the user provided value will override any automated help message set by the
|
|
370
|
+
* Error class.
|
|
371
|
+
*/
|
|
372
|
+
readonly help?: string;
|
|
373
|
+
/**
|
|
374
|
+
* Relevant for integration errors involving a network call, the `requestOptions` property
|
|
375
|
+
* details the request options that resulted in the specified error. The `requestOptions` property will automatically
|
|
376
|
+
* have sensitive authentication headers stripped.
|
|
377
|
+
*/
|
|
378
|
+
readonly requestOptions?: HttpRequestOptions;
|
|
379
|
+
/**
|
|
380
|
+
* Construct a new IntegrationError object.
|
|
381
|
+
* @param message - A string description of the error which is used as the `detail` property on the
|
|
382
|
+
* serialized error.
|
|
383
|
+
* @param properties - Optional properties for the error.
|
|
384
|
+
*/
|
|
385
|
+
constructor(message: string, properties?: IntegrationErrorProperties);
|
|
386
|
+
/**
|
|
387
|
+
* Serializes the error's properties into a POJO. The order of the
|
|
388
|
+
* properties is preserved when serialized.
|
|
389
|
+
* @returns JSON representation of the error
|
|
390
|
+
*/
|
|
391
|
+
toJSON(): SerializedIntegrationError;
|
|
392
|
+
}
|
|
565
393
|
|
|
566
|
-
/**
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
*
|
|
596
|
-
* The property should be a string value. If the property does not exist or is not
|
|
597
|
-
* a string value, a default error message will be used instead.
|
|
598
|
-
*/
|
|
599
|
-
readonly httpResponseErrorMessageProperties: string[];
|
|
600
|
-
/**
|
|
601
|
-
* Optional method that can be implemented to determine if an API error
|
|
602
|
-
* was encountered after an HTTP request is made.
|
|
603
|
-
*
|
|
604
|
-
* If the `isApiError` method is implemented
|
|
605
|
-
* the property `roundedSuccessStatusCodes` and `httpResponseErrorProperties` are not
|
|
606
|
-
* used to determine API errors.
|
|
607
|
-
*
|
|
608
|
-
* @returns An object indicating whether an API error was encountered and an optional message.
|
|
609
|
-
*/
|
|
610
|
-
readonly isApiError: IsApiErrorFunction;
|
|
611
|
-
/**
|
|
612
|
-
* An array of JSON dot notation paths to omit from the request options when logging.
|
|
613
|
-
*
|
|
614
|
-
* This property can be used to sanitize sensitive request properties that should not
|
|
615
|
-
* appear in logging.
|
|
616
|
-
*
|
|
617
|
-
* Note that the `requestOptions` object is automatically sanitized to remove properties that
|
|
618
|
-
* typically contain sensitive API key and passwords. For a list of properties that are
|
|
619
|
-
* automatically sanitized, see the {@link sanitizeRequestOptions} method.
|
|
620
|
-
*/
|
|
621
|
-
readonly requestOptionsToSanitize: string[];
|
|
622
|
-
userOptions: DoLookupUserOptions;
|
|
623
|
-
/**
|
|
624
|
-
* An optional rate limiter instance used to throttle HTTP requests.
|
|
625
|
-
* When set, all requests made via {@link PolarityRequest.run} are scheduled
|
|
626
|
-
* through this limiter. Typically provided by the Polarity server via the
|
|
627
|
-
* integration context.
|
|
628
|
-
*/
|
|
629
|
-
limiter: Limiter | null;
|
|
630
|
-
/**
|
|
631
|
-
* Lifecycle hooks for customizing request behavior. Hooks are configured via the
|
|
632
|
-
* {@link PolarityRequestOptions.hooks} property when creating a new instance of the
|
|
633
|
-
* {@link PolarityRequest} class.
|
|
634
|
-
*
|
|
635
|
-
* @see {@link PolarityRequestHooks} for hook type details.
|
|
636
|
-
*/
|
|
637
|
-
readonly hooks: Required<PolarityRequestHooks>;
|
|
638
|
-
constructor(options?: PolarityRequestOptions);
|
|
639
|
-
private configFieldIsValid;
|
|
640
|
-
/**
|
|
641
|
-
* Makes a single HTTP request and returns the response or throws an error
|
|
642
|
-
*
|
|
643
|
-
* @param requestOptions - request options used to make the HTTP request
|
|
644
|
-
* @returns The HTTP response
|
|
645
|
-
*/
|
|
646
|
-
run(requestOptions: HttpRequestOptions): Promise<HttpRequestResponse | undefined> | never;
|
|
647
|
-
/**
|
|
648
|
-
* Checks whether the HTTP response is an API error and returns an ApiRequestError if it is.
|
|
649
|
-
*
|
|
650
|
-
* @param httpResponse - The HTTP response from the Postman request.
|
|
651
|
-
* @param requestOptions - The options used for the request.
|
|
652
|
-
* @returns An ApiRequestError if the response indicates an API error, undefined otherwise.
|
|
653
|
-
*
|
|
654
|
-
* @throws {@link LibraryUsageError}
|
|
655
|
-
* Throws if the `isApiError` function returns an invalid result.
|
|
656
|
-
*/
|
|
657
|
-
private detectApiError;
|
|
394
|
+
/**
|
|
395
|
+
* @public
|
|
396
|
+
*/
|
|
397
|
+
export declare interface IntegrationErrorProperties {
|
|
398
|
+
/**
|
|
399
|
+
* a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of
|
|
400
|
+
* the problem except for purposes of localization. If omitted, the title will default to the type
|
|
401
|
+
* of error (e.g., IntegrationError, or ApiRequestError)
|
|
402
|
+
*/
|
|
403
|
+
title?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Additional details related to the error that may help the user troubleshoot the issue. If set by the user
|
|
406
|
+
* via the Error constructor, the user provided value will override any automated help message set by the
|
|
407
|
+
* Error class.
|
|
408
|
+
*/
|
|
409
|
+
help?: string;
|
|
410
|
+
/**
|
|
411
|
+
* The `cause` property is used to specify the `cause` of the error. Typically,
|
|
412
|
+
* this property is used to pass through a related Error instance but can be any value.
|
|
413
|
+
*/
|
|
414
|
+
cause?: unknown;
|
|
415
|
+
/**
|
|
416
|
+
* The HTTP status code applicable to this error, expressed as a string value.
|
|
417
|
+
*/
|
|
418
|
+
status?: string;
|
|
419
|
+
/**
|
|
420
|
+
* an application-specific error code, expressed as a string value.
|
|
421
|
+
*/
|
|
422
|
+
code?: string;
|
|
658
423
|
/**
|
|
659
|
-
*
|
|
660
|
-
*
|
|
424
|
+
* Relevant for integration errors involving a network call, the `requestOptions` property
|
|
425
|
+
* details the request options that resulted in the specified error. The `requestOptions` property will automatically
|
|
426
|
+
* have sensitive authentication headers stripped.
|
|
427
|
+
* By default, the following paths are sanitized:
|
|
661
428
|
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
429
|
+
* - auth.password
|
|
430
|
+
* - auth.bearer
|
|
431
|
+
* - body.password
|
|
432
|
+
* - form.client_secret
|
|
433
|
+
* - headers.authorization
|
|
434
|
+
* - headers.x-api-key
|
|
435
|
+
*
|
|
436
|
+
* Additional paths can be sanitized by using the `requestOptionsToSanitize` property.
|
|
437
|
+
*/
|
|
438
|
+
requestOptions?: HttpRequestOptions;
|
|
439
|
+
/**
|
|
440
|
+
* List of paths in JSON dot notation to sanitize in the requestOptions object
|
|
441
|
+
*/
|
|
442
|
+
requestOptionsToSanitize?: string[];
|
|
443
|
+
/**
|
|
444
|
+
* Any additional properties which will be appended to the Error's meta property
|
|
445
|
+
*/
|
|
446
|
+
meta?: MetaObject;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Integration option definition for config.json
|
|
451
|
+
* @public
|
|
452
|
+
*/
|
|
453
|
+
export declare type IntegrationOption = {
|
|
454
|
+
type: 'text' | 'password';
|
|
455
|
+
key: string;
|
|
456
|
+
name: string;
|
|
457
|
+
description?: string;
|
|
458
|
+
default: string | null;
|
|
459
|
+
userCanEdit?: boolean;
|
|
460
|
+
adminOnly?: boolean;
|
|
461
|
+
} | {
|
|
462
|
+
type: 'boolean';
|
|
463
|
+
key: string;
|
|
464
|
+
name: string;
|
|
465
|
+
description?: string;
|
|
466
|
+
default: boolean | null;
|
|
467
|
+
userCanEdit?: boolean;
|
|
468
|
+
adminOnly?: boolean;
|
|
469
|
+
} | {
|
|
470
|
+
type: 'number';
|
|
471
|
+
key: string;
|
|
472
|
+
name: string;
|
|
473
|
+
description?: string;
|
|
474
|
+
default: number | null;
|
|
475
|
+
userCanEdit?: boolean;
|
|
476
|
+
adminOnly?: boolean;
|
|
477
|
+
} | {
|
|
478
|
+
type: 'select';
|
|
479
|
+
key: string;
|
|
480
|
+
name: string;
|
|
481
|
+
description?: string;
|
|
482
|
+
default: SelectOptionItem | SelectOptionItem[] | string | null;
|
|
483
|
+
options: SelectOptionItem[];
|
|
484
|
+
multiple?: boolean;
|
|
485
|
+
userCanEdit: boolean;
|
|
486
|
+
adminOnly: boolean;
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* @public
|
|
491
|
+
*/
|
|
492
|
+
export declare type IsApiErrorFunction = (response: HttpRequestResponse, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => IsApiErrorResult;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* @public
|
|
496
|
+
*/
|
|
497
|
+
export declare type IsApiErrorResult = {
|
|
498
|
+
/**
|
|
499
|
+
* Indicates whether the response is an API error.
|
|
664
500
|
*/
|
|
665
|
-
|
|
501
|
+
isApiError: boolean;
|
|
666
502
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
503
|
+
* Optional message providing additional information about the API error. The
|
|
504
|
+
* returned `message` will be used as the `message` property on the {@link ApiRequestError} object
|
|
505
|
+
* thrown by the request.
|
|
506
|
+
*/
|
|
507
|
+
message?: string;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Thrown when the polarity-integration-utils library is used incorrectly. For example,
|
|
512
|
+
* if a method is called with incorrect or missing parameters, or a required initialization
|
|
513
|
+
* method is not called. This Error class should not be used directly by integrations.
|
|
514
|
+
*
|
|
515
|
+
* @public
|
|
516
|
+
*/
|
|
517
|
+
export declare class LibraryUsageError extends IntegrationError {
|
|
518
|
+
constructor(message: string, properties?: IntegrationErrorProperties);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Minimal interface for a rate limiter compatible with PolarityRequest.
|
|
523
|
+
* The Polarity server provides a Bottleneck instance that satisfies this interface.
|
|
524
|
+
*
|
|
525
|
+
* @public
|
|
526
|
+
*/
|
|
527
|
+
export declare interface Limiter {
|
|
528
|
+
schedule<T>(fn: (...args: unknown[]) => PromiseLike<T>, ...args: unknown[]): Promise<T>;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* @public
|
|
533
|
+
*/
|
|
534
|
+
export declare type MetaObject = {
|
|
535
|
+
[key: string]: unknown;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Factory function that creates mock functions. Pass `vi.fn` (Vitest)
|
|
540
|
+
* or `jest.fn` (Jest) to get spy capabilities. When omitted, plain
|
|
541
|
+
* no-op functions are used.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* // Vitest — enables toHaveBeenCalledWith() assertions
|
|
546
|
+
* const ctx = createMockIntegrationContext(vi.fn);
|
|
547
|
+
*
|
|
548
|
+
* // Jest
|
|
549
|
+
* const ctx = createMockIntegrationContext(jest.fn);
|
|
550
|
+
*
|
|
551
|
+
* // No framework — plain no-ops
|
|
552
|
+
* const ctx = createMockIntegrationContext();
|
|
553
|
+
* ```
|
|
554
|
+
* @public
|
|
555
|
+
*/
|
|
556
|
+
export declare type MockFnFactory = () => (...args: any[]) => any;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Generic network error for REST requests.
|
|
560
|
+
* https://betterstack.com/community/guides/scaling-nodejs/nodejs-errors/#4-econnrefused
|
|
561
|
+
*
|
|
562
|
+
* @public
|
|
563
|
+
*/
|
|
564
|
+
export declare class NetworkError extends IntegrationError {
|
|
565
|
+
constructor(message: string, properties?: IntegrationErrorProperties);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Hook that runs when an API error is detected (non-success status code or error
|
|
570
|
+
* properties found in the response body). Receives the full HTTP response so the
|
|
571
|
+
* hook can inspect status codes, headers, and body.
|
|
572
|
+
*
|
|
573
|
+
* If all registered hooks return without throwing, the error is suppressed and
|
|
574
|
+
* the HTTP response is returned to the caller. To propagate or replace the error,
|
|
575
|
+
* throw from within the hook.
|
|
576
|
+
*
|
|
577
|
+
* @public
|
|
578
|
+
*/
|
|
579
|
+
export declare type OnApiErrorHook = (error: ApiRequestError, response: HttpRequestResponse, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => Promise<void>;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Hook that runs when a network error or rate-limiting error occurs during a request.
|
|
583
|
+
*
|
|
584
|
+
* If all registered hooks return without throwing, the error is suppressed.
|
|
585
|
+
* To propagate or replace the error, throw from within the hook.
|
|
586
|
+
*
|
|
587
|
+
* @public
|
|
588
|
+
*/
|
|
589
|
+
export declare type OnNetworkErrorHook = (error: NetworkError | RetryRequestError, requestOptions: HttpRequestOptions, userOptions: DoLookupUserOptions) => Promise<void>;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* @deprecated Do not use in v2 integrations.
|
|
593
|
+
* @group Utilities
|
|
594
|
+
* @public
|
|
595
|
+
* @param error - Error instance to parse into a plain old javascript object
|
|
596
|
+
*/
|
|
597
|
+
export declare const parseErrorToReadableJson: (error: ResponseError) => any;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* A utility class for making HTTP requests
|
|
601
|
+
* @group Requests
|
|
602
|
+
* @public
|
|
603
|
+
*/
|
|
604
|
+
export declare class PolarityRequest {
|
|
605
|
+
/**
|
|
606
|
+
* Instance of a Bunyan logger
|
|
607
|
+
*/
|
|
608
|
+
private logger;
|
|
609
|
+
/**
|
|
610
|
+
* postman-request library request object with default values set. Used internally for
|
|
611
|
+
* making HTTP requests directly via the postman-request library
|
|
612
|
+
*/
|
|
613
|
+
private readonly requestWithDefaults;
|
|
614
|
+
readonly roundedSuccessStatusCodes: number[];
|
|
615
|
+
/**
|
|
616
|
+
* One or more HTTP response properties specified using JSON dot notation. If the
|
|
617
|
+
* specified path exists within the `body` property of the HTTP Response, an
|
|
618
|
+
* ApiRequestError will be thrown.
|
|
670
619
|
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
620
|
+
* By default, this value is an empty array and response properties are not used to
|
|
621
|
+
* detect errors.
|
|
622
|
+
* @defaultValue []
|
|
673
623
|
*/
|
|
674
|
-
|
|
624
|
+
readonly httpResponseErrorProperties: string[];
|
|
675
625
|
/**
|
|
676
|
-
*
|
|
677
|
-
* message
|
|
678
|
-
*
|
|
626
|
+
* One or more HTTP response properties specified using JSON dot notation that
|
|
627
|
+
* point to an error message that should be displayed to the user in the event
|
|
628
|
+
* of an API error.
|
|
679
629
|
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
* @returns An error message
|
|
630
|
+
* The property should be a string value. If the property does not exist or is not
|
|
631
|
+
* a string value, a default error message will be used instead.
|
|
683
632
|
*/
|
|
684
|
-
|
|
633
|
+
readonly httpResponseErrorMessageProperties: string[];
|
|
685
634
|
/**
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
635
|
+
* Optional method that can be implemented to determine if an API error
|
|
636
|
+
* was encountered after an HTTP request is made.
|
|
637
|
+
*
|
|
638
|
+
* If the `isApiError` method is implemented
|
|
639
|
+
* the property `roundedSuccessStatusCodes` and `httpResponseErrorProperties` are not
|
|
640
|
+
* used to determine API errors.
|
|
689
641
|
*
|
|
690
|
-
* @
|
|
691
|
-
* @param properties - a list of JSON dot notation properties to look for within `object`
|
|
692
|
-
* @returns A string value of the property found within the given object or undefined if no value is found
|
|
642
|
+
* @returns An object indicating whether an API error was encountered and an optional message.
|
|
693
643
|
*/
|
|
694
|
-
|
|
644
|
+
readonly isApiError: IsApiErrorFunction;
|
|
695
645
|
/**
|
|
696
|
-
*
|
|
646
|
+
* An array of JSON dot notation paths to omit from the request options when logging.
|
|
697
647
|
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* an optional `entity` property which can be assigned to the Entity the request is being made for.
|
|
701
|
-
* The `HttpRequestResponse` object returned by this method will include the same `entity` property
|
|
702
|
-
* making it easy to match the response to the entity.
|
|
648
|
+
* This property can be used to sanitize sensitive request properties that should not
|
|
649
|
+
* appear in logging.
|
|
703
650
|
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
|
|
651
|
+
* Note that the `requestOptions` object is automatically sanitized to remove properties that
|
|
652
|
+
* typically contain sensitive API key and passwords. For a list of properties that are
|
|
653
|
+
* automatically sanitized, see the {@link sanitizeRequestOptions} method.
|
|
654
|
+
*/
|
|
655
|
+
readonly requestOptionsToSanitize: string[];
|
|
656
|
+
userOptions: DoLookupUserOptions;
|
|
657
|
+
/**
|
|
658
|
+
* An optional rate limiter instance used to throttle HTTP requests.
|
|
659
|
+
* When set, all requests made via {@link PolarityRequest.run} are scheduled
|
|
660
|
+
* through this limiter. Typically provided by the Polarity server via the
|
|
661
|
+
* integration context.
|
|
662
|
+
*/
|
|
663
|
+
limiter: Limiter | null;
|
|
664
|
+
/**
|
|
665
|
+
* Lifecycle hooks for customizing request behavior. Hooks are configured via the
|
|
666
|
+
* {@link PolarityRequestOptions.hooks} property when creating a new instance of the
|
|
667
|
+
* {@link PolarityRequest} class.
|
|
708
668
|
*
|
|
709
|
-
*
|
|
710
|
-
|
|
669
|
+
* @see {@link PolarityRequestHooks} for hook type details.
|
|
670
|
+
*/
|
|
671
|
+
readonly hooks: Required<PolarityRequestHooks>;
|
|
672
|
+
constructor(options?: PolarityRequestOptions);
|
|
673
|
+
private configFieldIsValid;
|
|
674
|
+
/**
|
|
675
|
+
* Makes a single HTTP request and returns the response or throws an error
|
|
711
676
|
*
|
|
712
|
-
* @param
|
|
713
|
-
* @returns
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
677
|
+
* @param requestOptions - request options used to make the HTTP request
|
|
678
|
+
* @returns The HTTP response
|
|
679
|
+
*/
|
|
680
|
+
run(requestOptions: HttpRequestOptions): Promise<HttpRequestResponse | undefined> | never;
|
|
681
|
+
/**
|
|
682
|
+
* Checks whether the HTTP response is an API error and returns an ApiRequestError if it is.
|
|
683
|
+
*
|
|
684
|
+
* @param httpResponse - The HTTP response from the Postman request.
|
|
685
|
+
* @param requestOptions - The options used for the request.
|
|
686
|
+
* @returns An ApiRequestError if the response indicates an API error, undefined otherwise.
|
|
687
|
+
*
|
|
688
|
+
* @throws {@link LibraryUsageError}
|
|
689
|
+
* Throws if the `isApiError` function returns an invalid result.
|
|
690
|
+
*/
|
|
691
|
+
private detectApiError;
|
|
692
|
+
/**
|
|
693
|
+
* Returns true if the `httpStatusCode` is not one of the rounded HTTP status codes
|
|
694
|
+
* specified in the PolarityRequest `roundedSuccessStatusCodes` property.
|
|
695
|
+
*
|
|
696
|
+
* @param httpStatusCode - A numeric HTTP Status Code
|
|
697
|
+
* @returns true if the provided `httpStatusCode` is an error code
|
|
698
|
+
*/
|
|
699
|
+
private isHttpStatusCodeError;
|
|
700
|
+
/**
|
|
701
|
+
* Returns true indicating that the API returned an error if the `httpBody` contains
|
|
702
|
+
* one of the paths specified by the PolarityRequest `httpResponseErrorProperties`
|
|
703
|
+
* property.
|
|
704
|
+
*
|
|
705
|
+
* @param httpBody - body property from the HttpRequestResponse
|
|
706
|
+
* @returns `true` if the httpBody property contains properties specified in `httpResponseErrorProperties`
|
|
707
|
+
*/
|
|
708
|
+
private hasHttpResponseErrorProperty;
|
|
709
|
+
/**
|
|
710
|
+
* Returns an error message based on the `httpResponseErrorMessageProperties` first. If no
|
|
711
|
+
* message is found, it then uses the `httpResponseErrorProperties` to attempt to find
|
|
712
|
+
* a suitable error message. If no message is still found, the `defaultMessage` is returned.
|
|
713
|
+
*
|
|
714
|
+
* @param httpBody - JSON Object returned by an HTTP Request
|
|
715
|
+
* @param defaultMessage - A default error message to use if no specific error messages are found
|
|
716
|
+
* @returns An error message
|
|
717
|
+
*/
|
|
718
|
+
private getErrorMessageFromHttpResponse;
|
|
719
|
+
/**
|
|
720
|
+
* Given a list of `properties` which are strings representing JSON dot notation, this
|
|
721
|
+
* method returns the first string property found at the given JSON path
|
|
722
|
+
* in the given `object`.
|
|
723
|
+
*
|
|
724
|
+
* @param object - An object to find properties in
|
|
725
|
+
* @param properties - a list of JSON dot notation properties to look for within `object`
|
|
726
|
+
* @returns A string value of the property found within the given object or undefined if no value is found
|
|
727
|
+
*/
|
|
728
|
+
private maybeGetStringPropertyValue;
|
|
729
|
+
/**
|
|
730
|
+
* Runs multiple requests in parallel with a limit on the maximum number of concurrent requests.
|
|
731
|
+
*
|
|
732
|
+
* When running multiple request at once it is often useful to be able to tie a specific request
|
|
733
|
+
* back to the entity the request is for. To support this, the `HttpRequestOptions` object accepts
|
|
734
|
+
* an optional `entity` property which can be assigned to the Entity the request is being made for.
|
|
735
|
+
* The `HttpRequestResponse` object returned by this method will include the same `entity` property
|
|
736
|
+
* making it easy to match the response to the entity.
|
|
737
|
+
*
|
|
738
|
+
* Alternatively, for requests that are made for multiple entities at once (e.g., a query that can
|
|
739
|
+
* search multiple entities at a time), the `HttpRequestOptions` object also has an `entities`
|
|
740
|
+
* property which accept an array of entity objects. Similar to the `entity`, the
|
|
741
|
+
* `entities` property will be set on the `HttpRequestResponse` object.
|
|
742
|
+
*
|
|
743
|
+
* Finally, if you are looking to pass through a custom request id you can do that using the
|
|
744
|
+
* `requestId` property.
|
|
745
|
+
*
|
|
746
|
+
* @param options - An array of request options for running requests in parallel.
|
|
747
|
+
* @returns A promise that resolves to an array of responses in the same order as the input
|
|
748
|
+
* request options. If the `returnErrors` property is set to `true`, the response objects will
|
|
749
|
+
* have their `error` property set to the thrown error. If `onNetworkError` hooks are configured
|
|
750
|
+
* and suppress an error (return without throwing), the corresponding entry will be `undefined`.
|
|
751
|
+
*/
|
|
752
|
+
runInParallel(options: RunInParallelOptions): Promise<(HttpRequestResponse | undefined)[]>;
|
|
753
|
+
}
|
|
786
754
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
* - auth.password
|
|
819
|
-
* - auth.bearer
|
|
820
|
-
* - body.password
|
|
821
|
-
* - form.client_secret
|
|
822
|
-
* - headers.authorization
|
|
823
|
-
* - headers.x-api-key
|
|
824
|
-
*
|
|
825
|
-
* @param requestOptions - request options to sanitize
|
|
826
|
-
* @param additionalPathsToSanitize - array of additional paths to sanitize in addition to the
|
|
827
|
-
* default paths.
|
|
828
|
-
*/
|
|
829
|
-
export declare function sanitizeRequestOptions(requestOptions: HttpRequestOptions, additionalPathsToSanitize?: string[]): HttpRequestOptions;
|
|
755
|
+
/**
|
|
756
|
+
* Hooks for customizing the {@link PolarityRequest} lifecycle. All hook arrays
|
|
757
|
+
* execute in order. `beforeRequest` and `afterResponse` hooks chain their output,
|
|
758
|
+
* while error hooks run sequentially and can suppress errors by returning without
|
|
759
|
+
* throwing.
|
|
760
|
+
*
|
|
761
|
+
* @public
|
|
762
|
+
*/
|
|
763
|
+
export declare interface PolarityRequestHooks {
|
|
764
|
+
/**
|
|
765
|
+
* Hooks that run before each HTTP request. Each hook receives a copy of the request
|
|
766
|
+
* options and the return value is passed to the next hook (or used for the request).
|
|
767
|
+
*/
|
|
768
|
+
beforeRequest?: BeforeRequestHook[];
|
|
769
|
+
/**
|
|
770
|
+
* Hooks that run after a successful HTTP response. Each hook receives the response
|
|
771
|
+
* from the previous hook and the return value is passed to the next hook (or returned
|
|
772
|
+
* to the caller).
|
|
773
|
+
*/
|
|
774
|
+
afterResponse?: AfterResponseHook[];
|
|
775
|
+
/**
|
|
776
|
+
* Hooks that run when an API error is detected. Each hook receives the error and the
|
|
777
|
+
* full HTTP response. If all hooks return without throwing, the error is suppressed.
|
|
778
|
+
*/
|
|
779
|
+
onApiError?: OnApiErrorHook[];
|
|
780
|
+
/**
|
|
781
|
+
* Hooks that run when a network or rate-limiting error occurs. If all hooks return
|
|
782
|
+
* without throwing, the error is suppressed.
|
|
783
|
+
*/
|
|
784
|
+
onNetworkError?: OnNetworkErrorHook[];
|
|
785
|
+
}
|
|
830
786
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
787
|
+
/**
|
|
788
|
+
* @public
|
|
789
|
+
*/
|
|
790
|
+
export declare interface PolarityRequestOptions {
|
|
791
|
+
defaults?: ConfigRequestProxyOptions;
|
|
792
|
+
isApiError?: IsApiErrorFunction;
|
|
793
|
+
roundedSuccessStatusCodes?: number[];
|
|
794
|
+
httpResponseErrorProperties?: string[];
|
|
795
|
+
httpResponseErrorMessageProperties?: string[];
|
|
796
|
+
requestOptionsToSanitize?: string[];
|
|
797
|
+
hooks?: PolarityRequestHooks;
|
|
798
|
+
limiter?: Limiter;
|
|
799
|
+
}
|
|
839
800
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* The name data property of IntegrationError.prototype is shared by all Error instances.
|
|
852
|
-
* It represents the name for the type of error. For IntegrationError.prototype.name,
|
|
853
|
-
* the initial value is "IntegrationError".
|
|
854
|
-
*/
|
|
855
|
-
name: string;
|
|
856
|
-
/**
|
|
857
|
-
* a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be
|
|
858
|
-
* localized
|
|
859
|
-
*/
|
|
860
|
-
detail: string;
|
|
861
|
-
/**
|
|
862
|
-
* An optional HTTP status code applicable to this error, expressed as a string value.
|
|
863
|
-
*/
|
|
864
|
-
status?: string;
|
|
865
|
-
/**
|
|
866
|
-
* Additional details related to the error that may help the user troubleshoot the issue. If set by the user
|
|
867
|
-
* via the Error constructor, the user provided value will override any automated help message set by the
|
|
868
|
-
* Error class.
|
|
869
|
-
*/
|
|
870
|
-
help?: string;
|
|
871
|
-
/**
|
|
872
|
-
* An optional StackTrace of the error
|
|
873
|
-
*/
|
|
874
|
-
stack?: string;
|
|
875
|
-
/**
|
|
876
|
-
* An optional application-specific error code, expressed as a string value.
|
|
877
|
-
*/
|
|
878
|
-
code?: number | string;
|
|
879
|
-
/**
|
|
880
|
-
* The `cause` property is used to specify the `cause` of the error. Typically,
|
|
881
|
-
* this property is used to pass through a related Error instance but can be any value.
|
|
882
|
-
*/
|
|
883
|
-
cause?: unknown;
|
|
884
|
-
/**
|
|
885
|
-
* Relevant for integration errors involving a network call, the `requestOptions` property
|
|
886
|
-
* details the request options that resulted in the specified error. The `requestOptions` property will automatically
|
|
887
|
-
* have sensitive authentication headers stripped.
|
|
888
|
-
*/
|
|
889
|
-
requestOptions?: HttpRequestOptions;
|
|
890
|
-
/**
|
|
891
|
-
* an optional meta object containing non-standard meta-information about the error.
|
|
892
|
-
*/
|
|
893
|
-
meta?: ErrorMeta;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* Set the logger object used by the integration.
|
|
898
|
-
*
|
|
899
|
-
* @example
|
|
900
|
-
* Example of setting the logger within the integration's startup method:
|
|
901
|
-
* ```js
|
|
902
|
-
* const { setLogger } = require('polarity-integration-utils');
|
|
903
|
-
*
|
|
904
|
-
* function startup(logger){
|
|
905
|
-
* setLogger(logger);
|
|
906
|
-
* }
|
|
907
|
-
* ```
|
|
908
|
-
*
|
|
909
|
-
* You can now use {@link getLogger} to get the logger object anywhere within your integration codebase.
|
|
910
|
-
*
|
|
911
|
-
* @public
|
|
912
|
-
* @param logger - the integration logger object passed into the `startup` method
|
|
913
|
-
*/
|
|
914
|
-
export declare const setLogger: (logger: Logger) => void;
|
|
801
|
+
/**
|
|
802
|
+
* @deprecated Do not use in v2 integrations.
|
|
803
|
+
* @public
|
|
804
|
+
*/
|
|
805
|
+
export declare interface ResponseError {
|
|
806
|
+
name: string;
|
|
807
|
+
message: string;
|
|
808
|
+
stack?: string;
|
|
809
|
+
code?: number | string;
|
|
810
|
+
}
|
|
915
811
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
812
|
+
/**
|
|
813
|
+
* Thrown by authenticated request method for any HTTP status codes where we want to allow
|
|
814
|
+
* the user to retry their lookup.
|
|
815
|
+
*
|
|
816
|
+
* @public
|
|
817
|
+
*/
|
|
818
|
+
export declare class RetryRequestError extends IntegrationError {
|
|
819
|
+
constructor(message: string, properties?: IntegrationErrorProperties);
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* @public
|
|
824
|
+
*/
|
|
825
|
+
export declare type RunInParallelOptions = {
|
|
826
|
+
/**
|
|
827
|
+
* Array of HttpRequestOptions that will be run in parallel as specified by
|
|
828
|
+
* the `maxConcurrentRequests` property.
|
|
829
|
+
*/
|
|
830
|
+
allRequestOptions: HttpRequestOptions[];
|
|
831
|
+
/**
|
|
832
|
+
* Maximum number of requests to run in parallel
|
|
833
|
+
*
|
|
834
|
+
* @defaultValue 5
|
|
835
|
+
*/
|
|
836
|
+
maxConcurrentRequests?: number;
|
|
837
|
+
/**
|
|
838
|
+
* If true, any errors thrown during the request will be returned in the response object on the `error` property
|
|
839
|
+
* of the returned `HttpRequestResponse` object. If false, any errors thrown will be thrown and should be handled by
|
|
840
|
+
*
|
|
841
|
+
*
|
|
842
|
+
* @defaultValue false
|
|
843
|
+
*/
|
|
844
|
+
returnErrors?: boolean;
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Sanitizes the request options by removing sensitive information
|
|
849
|
+
* from the provided request options object.
|
|
850
|
+
*
|
|
851
|
+
* Default sanitized paths are:
|
|
852
|
+
*
|
|
853
|
+
* - auth.password
|
|
854
|
+
* - auth.bearer
|
|
855
|
+
* - body.password
|
|
856
|
+
* - form.client_secret
|
|
857
|
+
* - headers.authorization
|
|
858
|
+
* - headers.x-api-key
|
|
859
|
+
*
|
|
860
|
+
* @param requestOptions - request options to sanitize
|
|
861
|
+
* @param additionalPathsToSanitize - array of additional paths to sanitize in addition to the
|
|
862
|
+
* default paths.
|
|
863
|
+
* @group Requests
|
|
864
|
+
* @public
|
|
865
|
+
*/
|
|
866
|
+
export declare function sanitizeRequestOptions(requestOptions: HttpRequestOptions, additionalPathsToSanitize?: string[]): HttpRequestOptions;
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* A select option item with display label and value
|
|
870
|
+
* @public
|
|
871
|
+
*/
|
|
872
|
+
export declare interface SelectOptionItem {
|
|
873
|
+
value: string;
|
|
874
|
+
display: string;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* @public
|
|
879
|
+
*/
|
|
880
|
+
export declare interface SerializedIntegrationError {
|
|
881
|
+
/**
|
|
882
|
+
* a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of
|
|
883
|
+
* the problem except for purposes of localization. If omitted, the title will default to the type
|
|
884
|
+
* of error (e.g., IntegrationError, or ApiRequestError)
|
|
885
|
+
*/
|
|
886
|
+
title: string;
|
|
887
|
+
/**
|
|
888
|
+
* The name data property of IntegrationError.prototype is shared by all Error instances.
|
|
889
|
+
* It represents the name for the type of error. For IntegrationError.prototype.name,
|
|
890
|
+
* the initial value is "IntegrationError".
|
|
891
|
+
*/
|
|
892
|
+
name: string;
|
|
893
|
+
/**
|
|
894
|
+
* a human-readable explanation specific to this occurrence of the problem. Like title, this field’s value can be
|
|
895
|
+
* localized
|
|
896
|
+
*/
|
|
897
|
+
detail: string;
|
|
898
|
+
/**
|
|
899
|
+
* An optional HTTP status code applicable to this error, expressed as a string value.
|
|
900
|
+
*/
|
|
901
|
+
status?: string;
|
|
902
|
+
/**
|
|
903
|
+
* Additional details related to the error that may help the user troubleshoot the issue. If set by the user
|
|
904
|
+
* via the Error constructor, the user provided value will override any automated help message set by the
|
|
905
|
+
* Error class.
|
|
906
|
+
*/
|
|
907
|
+
help?: string;
|
|
908
|
+
/**
|
|
909
|
+
* An optional StackTrace of the error
|
|
910
|
+
*/
|
|
911
|
+
stack?: string;
|
|
912
|
+
/**
|
|
913
|
+
* An optional application-specific error code, expressed as a string value.
|
|
914
|
+
*/
|
|
915
|
+
code?: number | string;
|
|
916
|
+
/**
|
|
917
|
+
* The `cause` property is used to specify the `cause` of the error. Typically,
|
|
918
|
+
* this property is used to pass through a related Error instance but can be any value.
|
|
919
|
+
*/
|
|
920
|
+
cause?: unknown;
|
|
921
|
+
/**
|
|
922
|
+
* Relevant for integration errors involving a network call, the `requestOptions` property
|
|
923
|
+
* details the request options that resulted in the specified error. The `requestOptions` property will automatically
|
|
924
|
+
* have sensitive authentication headers stripped.
|
|
925
|
+
*/
|
|
926
|
+
requestOptions?: HttpRequestOptions;
|
|
927
|
+
/**
|
|
928
|
+
* an optional meta object containing non-standard meta-information about the error.
|
|
929
|
+
*/
|
|
930
|
+
meta?: ErrorMeta;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Set the logger object used by the integration.
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* Example of setting the logger within the integration's startup method:
|
|
938
|
+
* ```js
|
|
939
|
+
* const { setLogger } = require('polarity-integration-utils');
|
|
940
|
+
*
|
|
941
|
+
* function startup(logger){
|
|
942
|
+
* setLogger(logger);
|
|
943
|
+
* }
|
|
944
|
+
* ```
|
|
945
|
+
*
|
|
946
|
+
* You can now use {@link getLogger} to get the logger object anywhere within your integration codebase.
|
|
947
|
+
*
|
|
948
|
+
* @group Logging
|
|
949
|
+
* @public
|
|
950
|
+
* @param logger - the integration logger object passed into the `startup` method
|
|
951
|
+
*/
|
|
952
|
+
export declare const setLogger: (logger: Logger) => void;
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* View component reference in config.json
|
|
956
|
+
* @public
|
|
957
|
+
*/
|
|
958
|
+
export declare interface ViewComponent {
|
|
959
|
+
component: {
|
|
960
|
+
file: string;
|
|
961
|
+
};
|
|
962
|
+
template: {
|
|
963
|
+
file: string;
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
export { }
|