polarity-integration-utils 2.0.8 → 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.
Files changed (139) hide show
  1. package/dist/dts/context/cache.d.ts +149 -0
  2. package/dist/dts/context/cache.d.ts.map +1 -0
  3. package/dist/dts/context/index.d.ts +3 -0
  4. package/dist/dts/context/index.d.ts.map +1 -0
  5. package/dist/dts/context/integration-context.d.ts +16 -0
  6. package/dist/dts/context/integration-context.d.ts.map +1 -0
  7. package/dist/dts/index.d.ts +4 -1
  8. package/dist/dts/index.d.ts.map +1 -1
  9. package/dist/dts/index.docs.d.ts +1 -0
  10. package/dist/dts/index.docs.d.ts.map +1 -1
  11. package/dist/dts/lib/context/cache.d.ts +149 -0
  12. package/dist/dts/lib/context/cache.d.ts.map +1 -0
  13. package/dist/dts/lib/context/index.d.ts +3 -0
  14. package/dist/dts/lib/context/index.d.ts.map +1 -0
  15. package/dist/dts/lib/context/integration-context.d.ts +16 -0
  16. package/dist/dts/lib/context/integration-context.d.ts.map +1 -0
  17. package/dist/dts/lib/errors/api-request-error.d.ts +10 -0
  18. package/dist/dts/lib/errors/api-request-error.d.ts.map +1 -0
  19. package/dist/dts/lib/errors/auth-request-error.d.ts +10 -0
  20. package/dist/dts/lib/errors/auth-request-error.d.ts.map +1 -0
  21. package/dist/dts/lib/errors/index.d.ts +8 -0
  22. package/dist/dts/lib/errors/index.d.ts.map +1 -0
  23. package/dist/dts/lib/errors/integration-error.d.ts +189 -0
  24. package/dist/dts/lib/errors/integration-error.d.ts.map +1 -0
  25. package/dist/dts/lib/errors/library-usage-error.d.ts +12 -0
  26. package/dist/dts/lib/errors/library-usage-error.d.ts.map +1 -0
  27. package/dist/dts/lib/errors/network-error.d.ts +11 -0
  28. package/dist/dts/lib/errors/network-error.d.ts.map +1 -0
  29. package/dist/dts/lib/errors/parse-error-to-readable-json.d.ts +7 -0
  30. package/dist/dts/lib/errors/parse-error-to-readable-json.d.ts.map +1 -0
  31. package/dist/dts/lib/errors/retry-request-error.d.ts +11 -0
  32. package/dist/dts/lib/errors/retry-request-error.d.ts.map +1 -0
  33. package/dist/dts/lib/index.d.ts +8 -0
  34. package/dist/dts/lib/index.d.ts.map +1 -0
  35. package/dist/dts/lib/index.docs.d.ts +10 -0
  36. package/dist/dts/lib/index.docs.d.ts.map +1 -0
  37. package/dist/dts/lib/internal/helpers/parallel-limit.d.ts +9 -0
  38. package/dist/dts/lib/internal/helpers/parallel-limit.d.ts.map +1 -0
  39. package/dist/dts/lib/internal/helpers/sanitize-object.d.ts +11 -0
  40. package/dist/dts/lib/internal/helpers/sanitize-object.d.ts.map +1 -0
  41. package/dist/dts/lib/logging/index.d.ts +2 -0
  42. package/dist/dts/lib/logging/index.d.ts.map +1 -0
  43. package/dist/dts/lib/logging/logger.d.ts +49 -0
  44. package/dist/dts/lib/logging/logger.d.ts.map +1 -0
  45. package/dist/dts/lib/requests/index.d.ts +3 -0
  46. package/dist/dts/lib/requests/index.d.ts.map +1 -0
  47. package/dist/dts/lib/requests/polarity-request.d.ts +411 -0
  48. package/dist/dts/lib/requests/polarity-request.d.ts.map +1 -0
  49. package/dist/dts/lib/requests/sanitize-request-options.d.ts +20 -0
  50. package/dist/dts/lib/requests/sanitize-request-options.d.ts.map +1 -0
  51. package/dist/dts/lib/testing/enhanced-utils/create-entity.d.ts +3 -0
  52. package/dist/dts/lib/testing/enhanced-utils/create-entity.d.ts.map +1 -0
  53. package/dist/dts/lib/testing/enhanced-utils/create-mock-integration-context.d.ts +3 -0
  54. package/dist/dts/lib/testing/enhanced-utils/create-mock-integration-context.d.ts.map +1 -0
  55. package/dist/dts/lib/testing/enhanced-utils/mock-request.d.ts +14 -0
  56. package/dist/dts/lib/testing/enhanced-utils/mock-request.d.ts.map +1 -0
  57. package/dist/dts/lib/testing/enhanced-utils/validate-integration.d.ts +8 -0
  58. package/dist/dts/lib/testing/enhanced-utils/validate-integration.d.ts.map +1 -0
  59. package/dist/dts/lib/testing/index.d.ts +6 -0
  60. package/dist/dts/lib/testing/index.d.ts.map +1 -0
  61. package/dist/dts/lib/testing/test-factory/create-integration-tests.d.ts +6 -0
  62. package/dist/dts/lib/testing/test-factory/create-integration-tests.d.ts.map +1 -0
  63. package/dist/dts/lib/testing/test-factory/test-do-lookup.d.ts +7 -0
  64. package/dist/dts/lib/testing/test-factory/test-do-lookup.d.ts.map +1 -0
  65. package/dist/dts/lib/testing/test-factory/test-on-message.d.ts +8 -0
  66. package/dist/dts/lib/testing/test-factory/test-on-message.d.ts.map +1 -0
  67. package/dist/dts/lib/types.d.ts +101 -0
  68. package/dist/dts/lib/types.d.ts.map +1 -0
  69. package/dist/dts/lib/zod-types.d.ts +278 -0
  70. package/dist/dts/lib/zod-types.d.ts.map +1 -0
  71. package/dist/dts/testing/enhanced-utils/create-entity.d.ts +3 -0
  72. package/dist/dts/testing/enhanced-utils/create-entity.d.ts.map +1 -0
  73. package/dist/dts/testing/enhanced-utils/create-mock-integration-context.d.ts +3 -0
  74. package/dist/dts/testing/enhanced-utils/create-mock-integration-context.d.ts.map +1 -0
  75. package/dist/dts/testing/enhanced-utils/mock-request.d.ts +14 -0
  76. package/dist/dts/testing/enhanced-utils/mock-request.d.ts.map +1 -0
  77. package/dist/dts/testing/enhanced-utils/validate-integration.d.ts +8 -0
  78. package/dist/dts/testing/enhanced-utils/validate-integration.d.ts.map +1 -0
  79. package/dist/dts/testing/index.d.ts +6 -0
  80. package/dist/dts/testing/index.d.ts.map +1 -0
  81. package/dist/dts/testing/test-factory/create-integration-tests.d.ts +6 -0
  82. package/dist/dts/testing/test-factory/create-integration-tests.d.ts.map +1 -0
  83. package/dist/dts/testing/test-factory/test-do-lookup.d.ts +7 -0
  84. package/dist/dts/testing/test-factory/test-do-lookup.d.ts.map +1 -0
  85. package/dist/dts/testing/test-factory/test-on-message.d.ts +8 -0
  86. package/dist/dts/testing/test-factory/test-on-message.d.ts.map +1 -0
  87. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  88. package/dist/dts/types.d.ts +50 -53
  89. package/dist/dts/types.d.ts.map +1 -1
  90. package/dist/dts/zod-types.d.ts +278 -0
  91. package/dist/dts/zod-types.d.ts.map +1 -0
  92. package/dist/es/lib/context/index.js +18 -0
  93. package/dist/es/lib/context/integration-context.js +2 -0
  94. package/dist/es/{errors → lib/errors}/network-error.js +1 -1
  95. package/dist/es/{index.docs.js → lib/index.docs.js} +1 -0
  96. package/dist/es/{index.js → lib/index.js} +9 -1
  97. package/dist/es/lib/testing/enhanced-utils/create-entity.js +37 -0
  98. package/dist/es/lib/testing/enhanced-utils/create-mock-integration-context.js +36 -0
  99. package/dist/es/lib/testing/enhanced-utils/mock-request.js +22 -0
  100. package/dist/es/lib/testing/enhanced-utils/validate-integration.js +159 -0
  101. package/dist/es/lib/testing/index.js +21 -0
  102. package/dist/es/lib/testing/test-factory/create-integration-tests.js +53 -0
  103. package/dist/es/lib/testing/test-factory/test-do-lookup.js +24 -0
  104. package/dist/es/lib/testing/test-factory/test-on-message.js +24 -0
  105. package/dist/es/lib/types.js +5 -0
  106. package/dist/es/lib/zod-types.js +206 -0
  107. package/dist/lib/context/cache.js +2 -0
  108. package/dist/lib/context/index.js +18 -0
  109. package/dist/lib/context/integration-context.js +2 -0
  110. package/dist/lib/errors/network-error.js +1 -1
  111. package/dist/lib/index.docs.js +1 -0
  112. package/dist/lib/index.js +9 -1
  113. package/dist/lib/testing/enhanced-utils/create-entity.js +37 -0
  114. package/dist/lib/testing/enhanced-utils/create-mock-integration-context.js +36 -0
  115. package/dist/lib/testing/enhanced-utils/mock-request.js +22 -0
  116. package/dist/lib/testing/enhanced-utils/validate-integration.js +159 -0
  117. package/dist/lib/testing/index.js +21 -0
  118. package/dist/lib/testing/test-factory/create-integration-tests.js +53 -0
  119. package/dist/lib/testing/test-factory/test-do-lookup.js +24 -0
  120. package/dist/lib/testing/test-factory/test-on-message.js +24 -0
  121. package/dist/lib/types.js +3 -0
  122. package/dist/lib/zod-types.js +206 -0
  123. package/dist/polarity-integration-utils.d.ts +461 -54
  124. package/package.json +30 -9
  125. /package/dist/es/{types.js → lib/context/cache.js} +0 -0
  126. /package/dist/es/{errors → lib/errors}/api-request-error.js +0 -0
  127. /package/dist/es/{errors → lib/errors}/auth-request-error.js +0 -0
  128. /package/dist/es/{errors → lib/errors}/index.js +0 -0
  129. /package/dist/es/{errors → lib/errors}/integration-error.js +0 -0
  130. /package/dist/es/{errors → lib/errors}/library-usage-error.js +0 -0
  131. /package/dist/es/{errors → lib/errors}/parse-error-to-readable-json.js +0 -0
  132. /package/dist/es/{errors → lib/errors}/retry-request-error.js +0 -0
  133. /package/dist/es/{internal → lib/internal}/helpers/parallel-limit.js +0 -0
  134. /package/dist/es/{internal → lib/internal}/helpers/sanitize-object.js +0 -0
  135. /package/dist/es/{logging → lib/logging}/index.js +0 -0
  136. /package/dist/es/{logging → lib/logging}/logger.js +0 -0
  137. /package/dist/es/{requests → lib/requests}/index.js +0 -0
  138. /package/dist/es/{requests → lib/requests}/polarity-request.js +0 -0
  139. /package/dist/es/{requests → lib/requests}/sanitize-request-options.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
+ });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
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("./cache"), exports);
18
+ __exportStar(require("./integration-context"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -65,7 +65,7 @@ class NetworkError extends integration_error_1.IntegrationError {
65
65
  'SSL errors are typically caused by an untrusted SSL certificate in the HTTPS request chain (e.g., ' +
66
66
  'an internal server that is being queried directly, or a web proxy for external requests). You can temporarily ' +
67
67
  'ignore SSL validation errors by enabling the integration setting "Allow Insecure TLS/SSL Connections". In most ' +
68
- 'cases, you will need to add your organization\'s Certificate Authority to the Polarity Server to resolve the ' +
68
+ "cases, you will need to add your organization's Certificate Authority to the Polarity Server to resolve the " +
69
69
  'issue permanently.';
70
70
  }
71
71
  else if (code && code === 'ENOTFOUND') {
@@ -22,3 +22,4 @@ __exportStar(require("./errors"), exports);
22
22
  __exportStar(require("./requests"), exports);
23
23
  __exportStar(require("./logging"), exports);
24
24
  __exportStar(require("./types"), exports);
25
+ __exportStar(require("./context"), exports);
package/dist/lib/index.js CHANGED
@@ -32,11 +32,19 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.logging = exports.requests = exports.errors = void 0;
39
+ exports.types = exports.context = exports.logging = exports.requests = exports.errors = void 0;
37
40
  const errors = __importStar(require("./errors"));
38
41
  exports.errors = errors;
39
42
  const requests = __importStar(require("./requests"));
40
43
  exports.requests = requests;
41
44
  const logging = __importStar(require("./logging"));
42
45
  exports.logging = logging;
46
+ const context = __importStar(require("./context"));
47
+ exports.context = context;
48
+ const types = __importStar(require("./types"));
49
+ exports.types = types;
50
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createEntity = void 0;
4
+ const createEntity = (type, value) => {
5
+ const isDomain = /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/.test(value);
6
+ const isIPv4 = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(value);
7
+ return {
8
+ value,
9
+ displayValue: value,
10
+ type,
11
+ types: [type],
12
+ isDomain,
13
+ isIPv4,
14
+ isIP: isIPv4,
15
+ isEmail: false,
16
+ isHash: false,
17
+ isHex: false,
18
+ isHTMLTag: false,
19
+ isIPv6: false,
20
+ isMD5: false,
21
+ isPrivateIP: false,
22
+ isSHA1: false,
23
+ isSHA256: false,
24
+ isSHA512: false,
25
+ isURL: false,
26
+ latitude: 0,
27
+ longitude: 0,
28
+ hashType: '',
29
+ IPType: isIPv4 ? 'IPv4' : '',
30
+ channels: [],
31
+ requestContext: {
32
+ requestType: 'onDemand',
33
+ isUserInitiated: true
34
+ }
35
+ };
36
+ };
37
+ exports.createEntity = createEntity;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMockIntegrationContext = void 0;
4
+ const createMockIntegrationContext = () => {
5
+ const cache = {
6
+ global: {
7
+ get: jest.fn(),
8
+ set: jest.fn(),
9
+ delete: jest.fn()
10
+ },
11
+ integration: {
12
+ get: jest.fn(),
13
+ set: jest.fn(),
14
+ delete: jest.fn()
15
+ },
16
+ user: {
17
+ get: jest.fn(),
18
+ set: jest.fn(),
19
+ delete: jest.fn()
20
+ }
21
+ };
22
+ return {
23
+ cache,
24
+ integrationId: 'test-integration',
25
+ userId: 'test-user',
26
+ logger: {
27
+ info: jest.fn(),
28
+ debug: jest.fn(),
29
+ trace: jest.fn(),
30
+ warn: jest.fn(),
31
+ error: jest.fn(),
32
+ fatal: jest.fn()
33
+ }
34
+ };
35
+ };
36
+ exports.createMockIntegrationContext = createMockIntegrationContext;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockRequest = void 0;
4
+ const polarity_request_1 = require("../../requests/polarity-request");
5
+ jest.mock('../../requests/polarity-request');
6
+ const mockRequest = () => {
7
+ const mockRequest = {
8
+ get: jest.fn(),
9
+ post: jest.fn(),
10
+ put: jest.fn(),
11
+ delete: jest.fn(),
12
+ patch: jest.fn(),
13
+ head: jest.fn(),
14
+ options: jest.fn()
15
+ };
16
+ polarity_request_1.PolarityRequest.mockImplementation(() => mockRequest);
17
+ return {
18
+ PolarityRequestMock: polarity_request_1.PolarityRequest,
19
+ mockRequest
20
+ };
21
+ };
22
+ exports.mockRequest = mockRequest;