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,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateIntegration = void 0;
|
|
7
|
+
const zod_types_1 = require("../../zod-types");
|
|
8
|
+
const create_mock_integration_context_1 = require("./create-mock-integration-context");
|
|
9
|
+
const zod_1 = __importDefault(require("zod"));
|
|
10
|
+
const validateIntegration = (integration, config) => {
|
|
11
|
+
const result = {
|
|
12
|
+
isValid: true,
|
|
13
|
+
errors: [],
|
|
14
|
+
warnings: []
|
|
15
|
+
};
|
|
16
|
+
// Check required functions
|
|
17
|
+
checkStartupFunction(integration, result);
|
|
18
|
+
checkDoLookupFunction(integration, result);
|
|
19
|
+
checkOnMessageFunction(integration, result);
|
|
20
|
+
// Check function signatures
|
|
21
|
+
validateFunctionSignatures(integration, result);
|
|
22
|
+
// Check exported integration object structure (e.g. if it's wrapped in an 'integration' property)
|
|
23
|
+
checkIntegrationObject(integration, result);
|
|
24
|
+
if (config) {
|
|
25
|
+
const configResult = zod_types_1.IntegrationConfigSchema.safeParse(config);
|
|
26
|
+
if (!configResult.success) {
|
|
27
|
+
result.errors.push(`Invalid config.json: ${JSON.stringify(zod_1.default.treeifyError(configResult.error), null, 2)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
result.isValid = result.errors.length === 0;
|
|
31
|
+
if (!result.isValid) {
|
|
32
|
+
throw new Error(`Integration validation failed:\n${result.errors.map((e) => `• ${e}`).join('\n')}`);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
exports.validateIntegration = validateIntegration;
|
|
37
|
+
function checkStartupFunction(integration, result) {
|
|
38
|
+
if (typeof integration.startup !== 'function') {
|
|
39
|
+
result.errors.push('Missing required startup function');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if (integration.startup.length !== 1) {
|
|
43
|
+
result.warnings.push(`startup function should accept exactly 1 parameter (logger), found ${integration.startup.length}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function checkDoLookupFunction(integration, result) {
|
|
48
|
+
if (typeof integration.doLookup !== 'function') {
|
|
49
|
+
result.errors.push('Missing required doLookup function');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (integration.doLookup.length !== 3) {
|
|
53
|
+
result.warnings.push(`doLookup function should accept exactly 3 parameters (entities, options, context), found ${integration.doLookup.length}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function checkOnMessageFunction(integration, result) {
|
|
58
|
+
if (integration.onMessage !== undefined) {
|
|
59
|
+
if (typeof integration.onMessage !== 'function') {
|
|
60
|
+
result.errors.push('onMessage must be a function if present');
|
|
61
|
+
}
|
|
62
|
+
else if (integration.onMessage.length !== 3) {
|
|
63
|
+
result.warnings.push(`onMessage function should accept exactly 3 parameters (payload, options, context), found ${integration.onMessage.length}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function validateFunctionSignatures(integration, result) {
|
|
68
|
+
const mockLogger = {
|
|
69
|
+
info: () => { },
|
|
70
|
+
debug: () => { },
|
|
71
|
+
warn: () => { },
|
|
72
|
+
error: () => { },
|
|
73
|
+
trace: () => { },
|
|
74
|
+
fatal: () => { }
|
|
75
|
+
};
|
|
76
|
+
const mockContext = (0, create_mock_integration_context_1.createMockIntegrationContext)();
|
|
77
|
+
// Test startup return type
|
|
78
|
+
if (typeof integration.startup === 'function') {
|
|
79
|
+
try {
|
|
80
|
+
const startupResult = integration.startup(mockLogger);
|
|
81
|
+
if (!startupResult || typeof startupResult.then !== 'function') {
|
|
82
|
+
result.errors.push('startup function must return a Promise');
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// Prevent unhandled rejection if startup throws asynchronously
|
|
86
|
+
startupResult.catch(() => { });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
result.warnings.push(`startup function threw error during validation: ${error}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Test doLookup return type
|
|
94
|
+
if (typeof integration.doLookup === 'function') {
|
|
95
|
+
try {
|
|
96
|
+
const doLookupResult = integration.doLookup([], { validatePayload: false }, mockContext);
|
|
97
|
+
const isValidReturn = Array.isArray(doLookupResult) ||
|
|
98
|
+
doLookupResult === null ||
|
|
99
|
+
doLookupResult === undefined ||
|
|
100
|
+
(doLookupResult &&
|
|
101
|
+
typeof doLookupResult === 'object' &&
|
|
102
|
+
'name' in doLookupResult &&
|
|
103
|
+
doLookupResult.name === 'IntegrationError') ||
|
|
104
|
+
// Check for promise
|
|
105
|
+
(doLookupResult &&
|
|
106
|
+
typeof doLookupResult.then === 'function');
|
|
107
|
+
if (!isValidReturn) {
|
|
108
|
+
// It might be a promise that resolves to the valid return types, so checking if it's a promise is important.
|
|
109
|
+
// The original code checked constructor name IntegrationError.
|
|
110
|
+
// Let's refine this. doLookup MUST return a Promise.
|
|
111
|
+
if (doLookupResult &&
|
|
112
|
+
typeof doLookupResult.then === 'function') {
|
|
113
|
+
// It's a promise, which is good.
|
|
114
|
+
doLookupResult.catch(() => { });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
result.warnings.push(`doLookup should return a Promise, returned: ${typeof doLookupResult}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (doLookupResult &&
|
|
121
|
+
typeof doLookupResult.then === 'function') {
|
|
122
|
+
doLookupResult.catch(() => { });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
result.warnings.push(`doLookup function threw error during validation: ${error}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Test onMessage return type
|
|
130
|
+
if (typeof integration.onMessage === 'function') {
|
|
131
|
+
try {
|
|
132
|
+
const onMessageResult = integration.onMessage({}, { validatePayload: false }, mockContext);
|
|
133
|
+
if (!onMessageResult || typeof onMessageResult.then !== 'function') {
|
|
134
|
+
result.errors.push('onMessage function must return a Promise');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Prevent unhandled rejection if onMessage throws asynchronously
|
|
138
|
+
onMessageResult.catch(() => { });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
result.warnings.push(`onMessage function threw error during validation: ${error}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function checkIntegrationObject(integration, result) {
|
|
147
|
+
// Check if someone accidentally exported { integration: { ... } } instead of { ... }
|
|
148
|
+
if ('integration' in integration) {
|
|
149
|
+
const integrationObj = integration.integration;
|
|
150
|
+
if (integrationObj &&
|
|
151
|
+
typeof integrationObj === 'object' &&
|
|
152
|
+
'startup' in integrationObj &&
|
|
153
|
+
typeof integrationObj.startup === 'function' &&
|
|
154
|
+
'doLookup' in integrationObj &&
|
|
155
|
+
typeof integrationObj.doLookup === 'function') {
|
|
156
|
+
result.warnings.push('Detected potential incorrect export structure. The integration seems to be nested under an "integration" property. Ensure you are exporting the integration object directly (e.g. export = { ... }).');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./test-factory/create-integration-tests"), exports);
|
|
18
|
+
__exportStar(require("./enhanced-utils/create-entity"), exports);
|
|
19
|
+
__exportStar(require("./enhanced-utils/create-mock-integration-context"), exports);
|
|
20
|
+
__exportStar(require("./enhanced-utils/mock-request"), exports);
|
|
21
|
+
__exportStar(require("./enhanced-utils/validate-integration"), exports);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createIntegrationTests = void 0;
|
|
37
|
+
const validate_integration_1 = require("../enhanced-utils/validate-integration");
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const test_do_lookup_1 = require("./test-do-lookup");
|
|
41
|
+
const test_on_message_1 = require("./test-on-message");
|
|
42
|
+
const createIntegrationTests = (integration) => {
|
|
43
|
+
const configPath = path.join(process.cwd(), 'config', 'config.json');
|
|
44
|
+
const config = fs.existsSync(configPath)
|
|
45
|
+
? JSON.parse(fs.readFileSync(configPath, 'utf-8'))
|
|
46
|
+
: undefined;
|
|
47
|
+
(0, validate_integration_1.validateIntegration)(integration, config);
|
|
48
|
+
return {
|
|
49
|
+
testDoLookup: test_do_lookup_1.testDoLookup.bind(null, integration),
|
|
50
|
+
testOnMessage: test_on_message_1.testOnMessage.bind(null, integration)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.createIntegrationTests = createIntegrationTests;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testDoLookup = void 0;
|
|
4
|
+
const zod_types_1 = require("../../zod-types");
|
|
5
|
+
const create_mock_integration_context_1 = require("../enhanced-utils/create-mock-integration-context");
|
|
6
|
+
const testDoLookup = (integration, description, { entities, options, expected }) => {
|
|
7
|
+
test(description, async () => {
|
|
8
|
+
const mockLogger = {
|
|
9
|
+
info: jest.fn(),
|
|
10
|
+
debug: jest.fn(),
|
|
11
|
+
trace: jest.fn(),
|
|
12
|
+
warn: jest.fn(),
|
|
13
|
+
error: jest.fn(),
|
|
14
|
+
fatal: jest.fn()
|
|
15
|
+
};
|
|
16
|
+
await integration.startup(mockLogger);
|
|
17
|
+
const context = (0, create_mock_integration_context_1.createMockIntegrationContext)();
|
|
18
|
+
const result = await integration.doLookup(entities, options, context);
|
|
19
|
+
const validationResult = zod_types_1.DoLookupResultSchema.safeParse(result);
|
|
20
|
+
expect(validationResult.success).toBe(true);
|
|
21
|
+
expect(result).toEqual(expected);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.testDoLookup = testDoLookup;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testOnMessage = void 0;
|
|
4
|
+
const create_mock_integration_context_1 = require("../enhanced-utils/create-mock-integration-context");
|
|
5
|
+
const testOnMessage = (integration, description, { command, args, expected, options = {} }) => {
|
|
6
|
+
test(description, async () => {
|
|
7
|
+
const mockLogger = {
|
|
8
|
+
info: jest.fn(),
|
|
9
|
+
debug: jest.fn(),
|
|
10
|
+
trace: jest.fn(),
|
|
11
|
+
warn: jest.fn(),
|
|
12
|
+
error: jest.fn(),
|
|
13
|
+
fatal: jest.fn()
|
|
14
|
+
};
|
|
15
|
+
await integration.startup(mockLogger);
|
|
16
|
+
const context = (0, create_mock_integration_context_1.createMockIntegrationContext)();
|
|
17
|
+
if (typeof integration.onMessage !== 'function') {
|
|
18
|
+
throw new Error('Integration does not have an onMessage method.');
|
|
19
|
+
}
|
|
20
|
+
const result = await integration.onMessage({ command, ...args }, options, context);
|
|
21
|
+
expect(result).toEqual(expected);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.testOnMessage = testOnMessage;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntegrationError = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
Object.defineProperty(exports, "IntegrationError", { enumerable: true, get: function () { return errors_1.IntegrationError; } });
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntegrationConfigSchema = exports.DoLookupResultSchema = exports.ResultSchema = exports.EntitySchema = exports.EntityTypeSchema = exports.StandardEntityTypeSchema = exports.ChannelSchema = exports.ValidateOptionsUserOptionsSchema = exports.ValidateOptionsUserOptionSchema = exports.DoLookupUserOptionsSchema = exports.PossibleUserOptionValueSchema = exports.DropdownUserOptionValueSchema = exports.ValidationErrorSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.ValidationErrorSchema = zod_1.z.object({
|
|
6
|
+
key: zod_1.z.string(),
|
|
7
|
+
message: zod_1.z.string()
|
|
8
|
+
});
|
|
9
|
+
exports.DropdownUserOptionValueSchema = zod_1.z.object({
|
|
10
|
+
display: zod_1.z.string(),
|
|
11
|
+
value: zod_1.z.string()
|
|
12
|
+
});
|
|
13
|
+
exports.PossibleUserOptionValueSchema = zod_1.z.union([
|
|
14
|
+
zod_1.z.undefined(),
|
|
15
|
+
zod_1.z.string(),
|
|
16
|
+
zod_1.z.number(),
|
|
17
|
+
zod_1.z.boolean(),
|
|
18
|
+
exports.DropdownUserOptionValueSchema,
|
|
19
|
+
zod_1.z.array(exports.DropdownUserOptionValueSchema)
|
|
20
|
+
]);
|
|
21
|
+
exports.DoLookupUserOptionsSchema = zod_1.z.record(zod_1.z.string(), exports.PossibleUserOptionValueSchema);
|
|
22
|
+
exports.ValidateOptionsUserOptionSchema = zod_1.z.object({
|
|
23
|
+
integration_id: zod_1.z.string().optional(),
|
|
24
|
+
key: zod_1.z.string(),
|
|
25
|
+
value: exports.PossibleUserOptionValueSchema,
|
|
26
|
+
user_can_edit: zod_1.z.boolean().optional(),
|
|
27
|
+
admin_only: zod_1.z.boolean().optional()
|
|
28
|
+
});
|
|
29
|
+
exports.ValidateOptionsUserOptionsSchema = zod_1.z.record(zod_1.z.string(), exports.ValidateOptionsUserOptionSchema);
|
|
30
|
+
exports.ChannelSchema = zod_1.z.object({
|
|
31
|
+
channel_name: zod_1.z.string(),
|
|
32
|
+
id: zod_1.z.number()
|
|
33
|
+
});
|
|
34
|
+
exports.StandardEntityTypeSchema = zod_1.z.union([
|
|
35
|
+
zod_1.z.literal('IP'),
|
|
36
|
+
zod_1.z.literal('IPv4'),
|
|
37
|
+
zod_1.z.literal('IPv4CIDR'),
|
|
38
|
+
zod_1.z.literal('IPv6'),
|
|
39
|
+
zod_1.z.literal('MAC'),
|
|
40
|
+
zod_1.z.literal('MD5'),
|
|
41
|
+
zod_1.z.literal('SHA1'),
|
|
42
|
+
zod_1.z.literal('SHA256'),
|
|
43
|
+
zod_1.z.literal('cve'),
|
|
44
|
+
zod_1.z.literal('domain'),
|
|
45
|
+
zod_1.z.literal('email'),
|
|
46
|
+
zod_1.z.literal('hash'),
|
|
47
|
+
zod_1.z.literal('string'),
|
|
48
|
+
zod_1.z.literal('url')
|
|
49
|
+
]);
|
|
50
|
+
exports.EntityTypeSchema = zod_1.z.union([
|
|
51
|
+
exports.StandardEntityTypeSchema,
|
|
52
|
+
zod_1.z.literal('*'),
|
|
53
|
+
zod_1.z.literal('custom'),
|
|
54
|
+
zod_1.z.custom((val) => /^custom\..+$/.test(val))
|
|
55
|
+
]);
|
|
56
|
+
exports.EntitySchema = zod_1.z.object({
|
|
57
|
+
value: zod_1.z.string(),
|
|
58
|
+
types: zod_1.z.array(exports.EntityTypeSchema),
|
|
59
|
+
type: exports.EntityTypeSchema,
|
|
60
|
+
requestContext: zod_1.z.object({
|
|
61
|
+
requestType: zod_1.z.literal('onDemand'),
|
|
62
|
+
isUserInitiated: zod_1.z.boolean()
|
|
63
|
+
}),
|
|
64
|
+
longitude: zod_1.z.number(),
|
|
65
|
+
latitude: zod_1.z.number(),
|
|
66
|
+
isURL: zod_1.z.boolean(),
|
|
67
|
+
isSHA512: zod_1.z.boolean(),
|
|
68
|
+
isSHA256: zod_1.z.boolean(),
|
|
69
|
+
isSHA1: zod_1.z.boolean(),
|
|
70
|
+
isPrivateIP: zod_1.z.boolean(),
|
|
71
|
+
isMD5: zod_1.z.boolean(),
|
|
72
|
+
isIPv6: zod_1.z.boolean(),
|
|
73
|
+
isIPv4: zod_1.z.boolean(),
|
|
74
|
+
isIP: zod_1.z.boolean(),
|
|
75
|
+
isHex: zod_1.z.boolean(),
|
|
76
|
+
isHash: zod_1.z.boolean(),
|
|
77
|
+
isHTMLTag: zod_1.z.boolean(),
|
|
78
|
+
isEmail: zod_1.z.boolean(),
|
|
79
|
+
isDomain: zod_1.z.boolean(),
|
|
80
|
+
hashType: zod_1.z.union([
|
|
81
|
+
zod_1.z.literal('md5'),
|
|
82
|
+
zod_1.z.literal('sha1'),
|
|
83
|
+
zod_1.z.literal('sha256'),
|
|
84
|
+
zod_1.z.literal('sha512'),
|
|
85
|
+
zod_1.z.literal('')
|
|
86
|
+
]),
|
|
87
|
+
displayValue: zod_1.z.string(),
|
|
88
|
+
channels: zod_1.z.array(exports.ChannelSchema),
|
|
89
|
+
IPType: zod_1.z.union([zod_1.z.literal('IPv4'), zod_1.z.literal('IPv6'), zod_1.z.literal('')])
|
|
90
|
+
});
|
|
91
|
+
exports.ResultSchema = zod_1.z.object({
|
|
92
|
+
entity: exports.EntitySchema,
|
|
93
|
+
displayValue: zod_1.z.string().optional(),
|
|
94
|
+
data: zod_1.z.object({
|
|
95
|
+
summary: zod_1.z.array(zod_1.z.string()),
|
|
96
|
+
details: zod_1.z.unknown()
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
exports.DoLookupResultSchema = zod_1.z.array(exports.ResultSchema);
|
|
100
|
+
const SelectOptionItemSchema = zod_1.z.object({
|
|
101
|
+
value: zod_1.z.string(),
|
|
102
|
+
display: zod_1.z.string()
|
|
103
|
+
});
|
|
104
|
+
// Schema for the 'options' array items (User Configuration)
|
|
105
|
+
const OptionSchema = zod_1.z.discriminatedUnion('type', [
|
|
106
|
+
zod_1.z.object({
|
|
107
|
+
type: zod_1.z.enum(['text', 'password']),
|
|
108
|
+
key: zod_1.z.string(),
|
|
109
|
+
name: zod_1.z.string(),
|
|
110
|
+
description: zod_1.z.string().optional(),
|
|
111
|
+
default: zod_1.z.string().nullable(),
|
|
112
|
+
userCanEdit: zod_1.z.boolean().optional(),
|
|
113
|
+
adminOnly: zod_1.z.boolean().optional()
|
|
114
|
+
}),
|
|
115
|
+
zod_1.z.object({
|
|
116
|
+
type: zod_1.z.literal('boolean'),
|
|
117
|
+
key: zod_1.z.string(),
|
|
118
|
+
name: zod_1.z.string(),
|
|
119
|
+
description: zod_1.z.string().optional(),
|
|
120
|
+
default: zod_1.z.boolean().nullable(),
|
|
121
|
+
userCanEdit: zod_1.z.boolean().optional(),
|
|
122
|
+
adminOnly: zod_1.z.boolean().optional()
|
|
123
|
+
}),
|
|
124
|
+
zod_1.z.object({
|
|
125
|
+
type: zod_1.z.literal('number'),
|
|
126
|
+
key: zod_1.z.string(),
|
|
127
|
+
name: zod_1.z.string(),
|
|
128
|
+
description: zod_1.z.string().optional(),
|
|
129
|
+
default: zod_1.z.number().nullable(),
|
|
130
|
+
userCanEdit: zod_1.z.boolean().optional(),
|
|
131
|
+
adminOnly: zod_1.z.boolean().optional()
|
|
132
|
+
}),
|
|
133
|
+
zod_1.z.object({
|
|
134
|
+
type: zod_1.z.literal('select'),
|
|
135
|
+
key: zod_1.z.string(),
|
|
136
|
+
name: zod_1.z.string(),
|
|
137
|
+
description: zod_1.z.string().optional(),
|
|
138
|
+
// Default can be a single object or an array of objects depending on 'multiple'
|
|
139
|
+
default: zod_1.z
|
|
140
|
+
.union([
|
|
141
|
+
SelectOptionItemSchema,
|
|
142
|
+
zod_1.z.array(SelectOptionItemSchema),
|
|
143
|
+
zod_1.z.string() // Occasionally a simple string value is used for default
|
|
144
|
+
])
|
|
145
|
+
.nullable(),
|
|
146
|
+
options: zod_1.z.array(SelectOptionItemSchema),
|
|
147
|
+
multiple: zod_1.z.boolean().optional(),
|
|
148
|
+
userCanEdit: zod_1.z.boolean(),
|
|
149
|
+
adminOnly: zod_1.z.boolean()
|
|
150
|
+
})
|
|
151
|
+
]);
|
|
152
|
+
// Schema for custom data types defined within the config
|
|
153
|
+
const CustomTypeSchema = zod_1.z.object({
|
|
154
|
+
type: zod_1.z.literal('custom').optional(), // Sometimes present in dataTypes
|
|
155
|
+
name: zod_1.z.string().optional(),
|
|
156
|
+
description: zod_1.z.string().optional(),
|
|
157
|
+
key: zod_1.z.string(),
|
|
158
|
+
regex: zod_1.z.string(),
|
|
159
|
+
editable: zod_1.z.boolean().optional(),
|
|
160
|
+
enabled: zod_1.z.boolean().optional()
|
|
161
|
+
});
|
|
162
|
+
// Component definition for block/summary
|
|
163
|
+
const ComponentPathSchema = zod_1.z.object({
|
|
164
|
+
file: zod_1.z.string()
|
|
165
|
+
});
|
|
166
|
+
const ViewComponentSchema = zod_1.z.object({
|
|
167
|
+
component: ComponentPathSchema,
|
|
168
|
+
template: ComponentPathSchema
|
|
169
|
+
});
|
|
170
|
+
exports.IntegrationConfigSchema = zod_1.z.object({
|
|
171
|
+
polarityIntegrationUuid: zod_1.z.uuid(),
|
|
172
|
+
name: zod_1.z.string(),
|
|
173
|
+
acronym: zod_1.z.string().max(10),
|
|
174
|
+
description: zod_1.z.string().optional(),
|
|
175
|
+
defaultColor: zod_1.z.string().optional(),
|
|
176
|
+
// Entity and Data types
|
|
177
|
+
entityTypes: zod_1.z.array(zod_1.z.string()).optional(),
|
|
178
|
+
dataTypes: zod_1.z.array(zod_1.z.union([zod_1.z.string(), CustomTypeSchema])).optional(),
|
|
179
|
+
customTypes: zod_1.z.array(CustomTypeSchema).optional(),
|
|
180
|
+
supportsAdditionalCustomTypes: zod_1.z.boolean().optional(),
|
|
181
|
+
// UI/View Configuration
|
|
182
|
+
styles: zod_1.z.array(zod_1.z.string()).optional(),
|
|
183
|
+
block: ViewComponentSchema,
|
|
184
|
+
summary: ViewComponentSchema.optional(),
|
|
185
|
+
// Behavior Configuration
|
|
186
|
+
onDemandOnly: zod_1.z.boolean().optional(),
|
|
187
|
+
copyOnDemand: zod_1.z.boolean().optional(),
|
|
188
|
+
// Logging and Networking
|
|
189
|
+
logging: zod_1.z
|
|
190
|
+
.object({
|
|
191
|
+
level: zod_1.z.enum(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
|
|
192
|
+
})
|
|
193
|
+
.optional(),
|
|
194
|
+
request: zod_1.z
|
|
195
|
+
.object({
|
|
196
|
+
cert: zod_1.z.string().optional(),
|
|
197
|
+
key: zod_1.z.string().optional(),
|
|
198
|
+
passphrase: zod_1.z.string().optional(),
|
|
199
|
+
ca: zod_1.z.string().optional(),
|
|
200
|
+
proxy: zod_1.z.string().optional(),
|
|
201
|
+
rejectUnauthorized: zod_1.z.boolean().optional()
|
|
202
|
+
})
|
|
203
|
+
.optional(),
|
|
204
|
+
// User Options
|
|
205
|
+
options: zod_1.z.array(OptionSchema).optional()
|
|
206
|
+
});
|