@jupiterone/integration-sdk-cli 8.3.1 → 8.4.2

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 (68) hide show
  1. package/dist/src/commands/collect.d.ts +2 -0
  2. package/dist/src/commands/collect.js +50 -5
  3. package/dist/src/commands/collect.js.map +1 -1
  4. package/dist/src/commands/diff.js +3 -3
  5. package/dist/src/commands/diff.js.map +1 -1
  6. package/dist/src/commands/document.js +2 -2
  7. package/dist/src/commands/document.js.map +1 -1
  8. package/dist/src/commands/neo4j.js +7 -5
  9. package/dist/src/commands/neo4j.js.map +1 -1
  10. package/dist/src/commands/run.js +13 -13
  11. package/dist/src/commands/run.js.map +1 -1
  12. package/dist/src/commands/sync.js +7 -7
  13. package/dist/src/commands/sync.js.map +1 -1
  14. package/dist/src/commands/validate-question-file.js +4 -4
  15. package/dist/src/commands/validate-question-file.js.map +1 -1
  16. package/dist/src/commands/visualize-types.js +4 -4
  17. package/dist/src/commands/visualize-types.js.map +1 -1
  18. package/dist/src/commands/visualize.js +2 -2
  19. package/dist/src/commands/visualize.js.map +1 -1
  20. package/dist/src/config.js +3 -2
  21. package/dist/src/config.js.map +1 -1
  22. package/dist/src/index.js +10 -10
  23. package/dist/src/index.js.map +1 -1
  24. package/dist/src/log.js +1 -0
  25. package/dist/src/log.js.map +1 -1
  26. package/dist/src/neo4j/neo4jGraphStore.js +15 -14
  27. package/dist/src/neo4j/neo4jGraphStore.js.map +1 -1
  28. package/dist/src/neo4j/uploadToNeo4j.js +2 -2
  29. package/dist/src/neo4j/uploadToNeo4j.js.map +1 -1
  30. package/dist/src/neo4j/wipeNeo4j.js.map +1 -1
  31. package/dist/src/services/queryLanguage.js +1 -1
  32. package/dist/src/services/queryLanguage.js.map +1 -1
  33. package/dist/src/utils/generateVisHTML.js +1 -1
  34. package/dist/src/utils/generateVisHTML.js.map +1 -1
  35. package/dist/src/utils/getSortedJupiterOneTypes.js +2 -2
  36. package/dist/src/utils/getSortedJupiterOneTypes.js.map +1 -1
  37. package/dist/src/visualization/createMappedRelationshipNodesAndEdges.js +9 -9
  38. package/dist/src/visualization/createMappedRelationshipNodesAndEdges.js.map +1 -1
  39. package/dist/src/visualization/generateVisualization.js +6 -6
  40. package/dist/src/visualization/generateVisualization.js.map +1 -1
  41. package/dist/src/visualization/retrieveIntegrationData.js +1 -1
  42. package/dist/src/visualization/retrieveIntegrationData.js.map +1 -1
  43. package/dist/src/visualization/utils.d.ts +1 -1
  44. package/dist/src/visualization/utils.js +2 -2
  45. package/dist/src/visualization/utils.js.map +1 -1
  46. package/dist/tsconfig.dist.tsbuildinfo +1 -10704
  47. package/package.json +6 -4
  48. package/src/__tests__/cli.test.ts +78 -0
  49. package/src/commands/collect.ts +66 -2
  50. package/src/commands/document.ts +10 -9
  51. package/src/commands/neo4j.ts +16 -10
  52. package/src/commands/visualize-types.ts +7 -9
  53. package/src/config.ts +2 -1
  54. package/src/log.ts +1 -0
  55. package/src/neo4j/README.md +15 -18
  56. package/src/neo4j/__tests__/neo4jGraphStore.test.ts +55 -53
  57. package/src/neo4j/__tests__/neo4jUtilities.test.ts +27 -9
  58. package/src/neo4j/index.ts +1 -1
  59. package/src/neo4j/neo4jGraphStore.ts +39 -25
  60. package/src/neo4j/uploadToNeo4j.ts +5 -2
  61. package/src/neo4j/wipeNeo4j.ts +15 -11
  62. package/src/visualization/__tests__/createMappedRelationshipNodesAndEdges.test.ts +35 -49
  63. package/src/visualization/generateVisualization.ts +7 -12
  64. package/src/visualization/retrieveIntegrationData.ts +3 -5
  65. package/src/visualization/types/IntegrationData.ts +5 -1
  66. package/src/visualization/utils.ts +7 -4
  67. package/tsconfig.dist.json +1 -3
  68. package/tsconfig.json +1 -3
@@ -7,8 +7,8 @@ export interface Neo4jGraphObjectStoreParams {
7
7
  uri: string;
8
8
  username: string;
9
9
  password: string;
10
- integrationInstanceID: string,
11
- session?: neo4j.Session
10
+ integrationInstanceID: string;
11
+ session?: neo4j.Session;
12
12
  }
13
13
 
14
14
  export class Neo4jGraphStore {
@@ -19,10 +19,9 @@ export class Neo4jGraphStore {
19
19
  private integrationInstanceID: string;
20
20
 
21
21
  constructor(params: Neo4jGraphObjectStoreParams) {
22
- if(params.session) {
22
+ if (params.session) {
23
23
  this.persistedSession = params.session;
24
- }
25
- else {
24
+ } else {
26
25
  this.neo4jDriver = neo4j.driver(
27
26
  params.uri,
28
27
  neo4j.auth.basic(params.username, params.password),
@@ -31,12 +30,14 @@ export class Neo4jGraphStore {
31
30
  this.integrationInstanceID = params.integrationInstanceID;
32
31
  }
33
32
 
34
- private async runCypherCommand(cypherCommand: string, cypherParameters?: any): Promise<neo4j.Result> {
35
- if(this.persistedSession) {
33
+ private async runCypherCommand(
34
+ cypherCommand: string,
35
+ cypherParameters?: any,
36
+ ): Promise<neo4j.Result> {
37
+ if (this.persistedSession) {
36
38
  const result = await this.persistedSession.run(cypherCommand);
37
39
  return result;
38
- }
39
- else {
40
+ } else {
40
41
  const session = this.neo4jDriver.session({
41
42
  database: this.databaseName,
42
43
  defaultAccessMode: neo4j.session.WRITE,
@@ -65,9 +66,9 @@ export class Neo4jGraphStore {
65
66
  SET ${nodeAlias} += $propertyParameters
66
67
  SET ${nodeAlias}:${entity._type};`;
67
68
  await this.runCypherCommand(buildCommand, {
68
- propertyParameters: propertyParameters,
69
- finalKeyValue: finalKeyValue,
70
- integrationInstanceID: this.integrationInstanceID
69
+ propertyParameters: propertyParameters,
70
+ finalKeyValue: finalKeyValue,
71
+ integrationInstanceID: this.integrationInstanceID,
71
72
  });
72
73
  }
73
74
  }
@@ -84,43 +85,56 @@ export class Neo4jGraphStore {
84
85
  if (relationship._fromEntityKey) {
85
86
  startEntityKey = sanitizeValue(relationship._fromEntityKey.toString());
86
87
  }
87
- if(relationship._toEntityKey) {
88
+ if (relationship._toEntityKey) {
88
89
  endEntityKey = sanitizeValue(relationship._toEntityKey.toString());
89
90
  }
90
91
 
91
- if(relationship._mapping) { //Mapped Relationship
92
- if(relationship._mapping['skipTargetCreation'] === false) {
92
+ if (relationship._mapping) {
93
+ //Mapped Relationship
94
+ if (relationship._mapping['skipTargetCreation'] === false) {
93
95
  //Create target entity first
94
96
  const tempEntity: Entity = {
95
97
  _class: relationship._mapping['targetEntity']._class,
96
98
  //TODO, I think this key is wrong, but not sure what else to use
97
- _key: sanitizeValue(relationship._key.replace(relationship._mapping['sourceEntityKey'], '')),
99
+ _key: sanitizeValue(
100
+ relationship._key.replace(
101
+ relationship._mapping['sourceEntityKey'],
102
+ '',
103
+ ),
104
+ ),
98
105
  _type: relationship._mapping['targetEntity']._type,
99
- }
106
+ };
100
107
  await this.addEntities([tempEntity]);
101
108
  }
102
- startEntityKey = sanitizeValue(relationship._mapping['sourceEntityKey']);
109
+ startEntityKey = sanitizeValue(
110
+ relationship._mapping['sourceEntityKey'],
111
+ );
103
112
  // TODO, see above. This key might also be an issue for the same reason
104
- endEntityKey = sanitizeValue(relationship._key.replace(relationship._mapping['sourceEntityKey'], ''));
113
+ endEntityKey = sanitizeValue(
114
+ relationship._key.replace(
115
+ relationship._mapping['sourceEntityKey'],
116
+ '',
117
+ ),
118
+ );
105
119
  }
106
120
 
107
121
  const buildCommand = `
108
122
  MERGE (start {_key: $startEntityKey, _integrationInstanceID: $integrationInstanceID})
109
123
  MERGE (end {_key: $endEntityKey, _integrationInstanceID: $integrationInstanceID})
110
- MERGE (start)-[${relationshipAlias}:${relationship._type}]->(end)
124
+ MERGE (start)-[${relationshipAlias}:${relationship._class}]->(end)
111
125
  SET ${relationshipAlias} += $propertyParameters;`;
112
126
  await this.runCypherCommand(buildCommand, {
113
- propertyParameters: propertyParameters,
114
- startEntityKey: startEntityKey,
127
+ propertyParameters: propertyParameters,
128
+ startEntityKey: startEntityKey,
115
129
  endEntityKey: endEntityKey,
116
- integrationInstanceID: this.integrationInstanceID
130
+ integrationInstanceID: this.integrationInstanceID,
117
131
  });
118
132
  }
119
133
  }
120
134
 
121
135
  // TODO, if we get to very large databases we could reach a size where
122
- // one or both both of the below wipe commands can't be easily executed
123
- // in memory. At that time, we should consider requiring/using the APOC
136
+ // one or both both of the below wipe commands can't be easily executed
137
+ // in memory. At that time, we should consider requiring/using the APOC
124
138
  // library so we can use apoc.periodic.iterate. Leaving out for now,
125
139
  // since that would further complicate the Neo4j database setup.
126
140
  async wipeInstanceIdData() {
@@ -1,5 +1,8 @@
1
1
  import { Neo4jGraphStore } from './neo4jGraphStore';
2
- import { iterateParsedGraphFiles, isDirectoryPresent } from '@jupiterone/integration-sdk-runtime';
2
+ import {
3
+ iterateParsedGraphFiles,
4
+ isDirectoryPresent,
5
+ } from '@jupiterone/integration-sdk-runtime';
3
6
  import { FlushedGraphObjectData } from '@jupiterone/integration-sdk-runtime/src/storage/types';
4
7
 
5
8
  type UploadToNeo4jParams = {
@@ -44,4 +47,4 @@ export async function uploadToNeo4j({
44
47
  } finally {
45
48
  await store.close();
46
49
  }
47
- }
50
+ }
@@ -5,15 +5,17 @@ type WipeNeo4jParams = {
5
5
  neo4jUri?: string;
6
6
  neo4jUser?: string;
7
7
  neo4jPassword?: string;
8
- }
8
+ };
9
9
  export async function wipeNeo4jByID({
10
10
  integrationInstanceID,
11
11
  neo4jUri = process.env.NEO4J_URI,
12
- neo4jUser = process.env. NEO4J_USER,
13
- neo4jPassword = process.env. NEO4J_PASSWORD,
12
+ neo4jUser = process.env.NEO4J_USER,
13
+ neo4jPassword = process.env.NEO4J_PASSWORD,
14
14
  }: WipeNeo4jParams) {
15
- if(!neo4jUri || !neo4jUser || !neo4jPassword) {
16
- throw new Error('ERROR: must provide login information in function call or include NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD files in your .env file!');
15
+ if (!neo4jUri || !neo4jUser || !neo4jPassword) {
16
+ throw new Error(
17
+ 'ERROR: must provide login information in function call or include NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD files in your .env file!',
18
+ );
17
19
  }
18
20
 
19
21
  const store = new Neo4jGraphStore({
@@ -33,15 +35,17 @@ type WipeAllNeo4jParams = {
33
35
  neo4jUri?: string;
34
36
  neo4jUser?: string;
35
37
  neo4jPassword?: string;
36
- }
38
+ };
37
39
 
38
40
  export async function wipeAllNeo4j({
39
41
  neo4jUri = process.env.NEO4J_URI,
40
- neo4jUser = process.env. NEO4J_USER,
41
- neo4jPassword = process.env. NEO4J_PASSWORD,
42
+ neo4jUser = process.env.NEO4J_USER,
43
+ neo4jPassword = process.env.NEO4J_PASSWORD,
42
44
  }: WipeAllNeo4jParams) {
43
- if(!neo4jUri || !neo4jUser || !neo4jPassword) {
44
- throw new Error('ERROR: must provide login information in function call or include NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD files in your .env file!');
45
+ if (!neo4jUri || !neo4jUser || !neo4jPassword) {
46
+ throw new Error(
47
+ 'ERROR: must provide login information in function call or include NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD files in your .env file!',
48
+ );
45
49
  }
46
50
 
47
51
  const store = new Neo4jGraphStore({
@@ -55,4 +59,4 @@ export async function wipeAllNeo4j({
55
59
  } finally {
56
60
  await store.close();
57
61
  }
58
- }
62
+ }
@@ -42,13 +42,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
42
42
  },
43
43
  ];
44
44
 
45
- const {
46
- mappedRelationshipEdges,
47
- mappedRelationshipNodes,
48
- } = createMappedRelationshipNodesAndEdges({
49
- mappedRelationships,
50
- explicitEntities,
51
- });
45
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
46
+ createMappedRelationshipNodesAndEdges({
47
+ mappedRelationships,
48
+ explicitEntities,
49
+ });
52
50
 
53
51
  expect(mappedRelationshipEdges).toEqual([
54
52
  {
@@ -71,13 +69,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
71
69
  },
72
70
  ];
73
71
 
74
- const {
75
- mappedRelationshipEdges,
76
- mappedRelationshipNodes,
77
- } = createMappedRelationshipNodesAndEdges({
78
- mappedRelationships,
79
- explicitEntities,
80
- });
72
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
73
+ createMappedRelationshipNodesAndEdges({
74
+ mappedRelationships,
75
+ explicitEntities,
76
+ });
81
77
 
82
78
  expect(mappedRelationshipEdges).toEqual([
83
79
  {
@@ -110,13 +106,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
110
106
  },
111
107
  ];
112
108
 
113
- const {
114
- mappedRelationshipEdges,
115
- mappedRelationshipNodes,
116
- } = createMappedRelationshipNodesAndEdges({
117
- mappedRelationships,
118
- explicitEntities,
119
- });
109
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
110
+ createMappedRelationshipNodesAndEdges({
111
+ mappedRelationships,
112
+ explicitEntities,
113
+ });
120
114
 
121
115
  expect(mappedRelationshipEdges).toEqual([
122
116
  {
@@ -184,13 +178,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
184
178
  },
185
179
  ];
186
180
 
187
- const {
188
- mappedRelationshipEdges,
189
- mappedRelationshipNodes,
190
- } = createMappedRelationshipNodesAndEdges({
191
- mappedRelationships,
192
- explicitEntities,
193
- });
181
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
182
+ createMappedRelationshipNodesAndEdges({
183
+ mappedRelationships,
184
+ explicitEntities,
185
+ });
194
186
 
195
187
  expect(mappedRelationshipEdges).toEqual([
196
188
  {
@@ -264,13 +256,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
264
256
  },
265
257
  ];
266
258
 
267
- const {
268
- mappedRelationshipEdges,
269
- mappedRelationshipNodes,
270
- } = createMappedRelationshipNodesAndEdges({
271
- mappedRelationships,
272
- explicitEntities,
273
- });
259
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
260
+ createMappedRelationshipNodesAndEdges({
261
+ mappedRelationships,
262
+ explicitEntities,
263
+ });
274
264
 
275
265
  expect(mappedRelationshipEdges).toEqual([
276
266
  {
@@ -328,13 +318,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
328
318
  },
329
319
  ];
330
320
 
331
- const {
332
- mappedRelationshipEdges,
333
- mappedRelationshipNodes,
334
- } = createMappedRelationshipNodesAndEdges({
335
- mappedRelationships,
336
- explicitEntities,
337
- });
321
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
322
+ createMappedRelationshipNodesAndEdges({
323
+ mappedRelationships,
324
+ explicitEntities,
325
+ });
338
326
 
339
327
  expect(mappedRelationshipEdges).toEqual([
340
328
  {
@@ -389,13 +377,11 @@ describe('#createMappedRelationshipNodesAndEdges', () => {
389
377
  },
390
378
  ];
391
379
 
392
- const {
393
- mappedRelationshipEdges,
394
- mappedRelationshipNodes,
395
- } = createMappedRelationshipNodesAndEdges({
396
- mappedRelationships,
397
- explicitEntities,
398
- });
380
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
381
+ createMappedRelationshipNodesAndEdges({
382
+ mappedRelationships,
383
+ explicitEntities,
384
+ });
399
385
 
400
386
  expect(mappedRelationshipEdges).toEqual([
401
387
  {
@@ -28,11 +28,8 @@ export async function generateVisualization(
28
28
  log.warn(`Unable to find any files under path: ${graphDataPath}`);
29
29
  }
30
30
 
31
- const {
32
- entities,
33
- relationships,
34
- mappedRelationships,
35
- } = await retrieveIntegrationData(entitiesAndRelationshipPaths);
31
+ const { entities, relationships, mappedRelationships } =
32
+ await retrieveIntegrationData(entitiesAndRelationshipPaths);
36
33
 
37
34
  const nodeDataSets = entities.map((entity) => ({
38
35
  id: getNodeIdFromEntity(entity, []),
@@ -47,13 +44,11 @@ export async function generateVisualization(
47
44
  }),
48
45
  );
49
46
 
50
- const {
51
- mappedRelationshipEdges,
52
- mappedRelationshipNodes,
53
- } = createMappedRelationshipNodesAndEdges({
54
- mappedRelationships,
55
- explicitEntities: entities,
56
- });
47
+ const { mappedRelationshipEdges, mappedRelationshipNodes } =
48
+ createMappedRelationshipNodesAndEdges({
49
+ mappedRelationships,
50
+ explicitEntities: entities,
51
+ });
57
52
 
58
53
  await writeFileToPath({
59
54
  path: visualizationOutputPath,
@@ -18,11 +18,9 @@ export async function retrieveIntegrationData(
18
18
  const mappedRelationships: MappedRelationship[] = [];
19
19
 
20
20
  const entitiesAndRelationships = await Promise.all(
21
- entitiesAndRelationshipPaths.map(
22
- async (path): Promise<any> => {
23
- return await readJsonFromPath<any>(path);
24
- },
25
- ),
21
+ entitiesAndRelationshipPaths.map(async (path): Promise<any> => {
22
+ return await readJsonFromPath<any>(path);
23
+ }),
26
24
  );
27
25
 
28
26
  for (const item of entitiesAndRelationships) {
@@ -1,4 +1,8 @@
1
- import { Entity, ExplicitRelationship, MappedRelationship } from '@jupiterone/integration-sdk-core';
1
+ import {
2
+ Entity,
3
+ ExplicitRelationship,
4
+ MappedRelationship,
5
+ } from '@jupiterone/integration-sdk-core';
2
6
 
3
7
  export interface IntegrationData {
4
8
  entities: Entity[];
@@ -1,18 +1,21 @@
1
1
  import { v4 as uuid } from 'uuid';
2
- import { Entity } from "@jupiterone/integration-sdk-core";
2
+ import { Entity } from '@jupiterone/integration-sdk-core';
3
3
 
4
4
  export type NodeEntity = Partial<Entity> & { nodeId: string };
5
5
 
6
6
  /**
7
7
  * The nodeId should map back to _key, which ought to be globally unique.
8
8
  * Entities set their node ID once, and return if available.
9
- *
9
+ *
10
10
  * If nodeId is not set, first check that the _key isn't already a nodeId for another entity.
11
11
  * Duplicates will break vis.js, so we will set nodeId to a UUID (this makes isNodeDuplicate(nodeEntity) === true)
12
- *
12
+ *
13
13
  * If node is not a duplicate, return either the entity _key, or, if unavailable, return a new UUID.
14
14
  */
15
- export function getNodeIdFromEntity(entity: Partial<NodeEntity>, existingEntities: NodeEntity[]): string {
15
+ export function getNodeIdFromEntity(
16
+ entity: Partial<NodeEntity>,
17
+ existingEntities: NodeEntity[],
18
+ ): string {
16
19
  if (entity.nodeId !== undefined) {
17
20
  return entity.nodeId;
18
21
  }
@@ -3,9 +3,7 @@
3
3
  "compilerOptions": {
4
4
  "sourceMap": true
5
5
  },
6
- "include": [
7
- "src"
8
- ],
6
+ "include": ["src"],
9
7
  "exclude": [
10
8
  "**/dist/*",
11
9
  "**/*.test.ts",
package/tsconfig.json CHANGED
@@ -3,9 +3,7 @@
3
3
  "compilerOptions": {
4
4
  "outDir": "dist"
5
5
  },
6
- "exclude": [
7
- "**/dist/*"
8
- ],
6
+ "exclude": ["**/dist/*"],
9
7
  "references": [
10
8
  { "path": "../integration-sdk-core" },
11
9
  { "path": "../integration-sdk-runtime" },