@jupiterone/integration-sdk-cli 7.2.0 → 8.0.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.
Files changed (36) hide show
  1. package/dist/src/commands/index.d.ts +1 -0
  2. package/dist/src/commands/index.js +1 -0
  3. package/dist/src/commands/index.js.map +1 -1
  4. package/dist/src/commands/neo4j.d.ts +2 -0
  5. package/dist/src/commands/neo4j.js +70 -0
  6. package/dist/src/commands/neo4j.js.map +1 -0
  7. package/dist/src/index.js +2 -1
  8. package/dist/src/index.js.map +1 -1
  9. package/dist/src/neo4j/index.d.ts +2 -0
  10. package/dist/src/neo4j/index.js +15 -0
  11. package/dist/src/neo4j/index.js.map +1 -0
  12. package/dist/src/neo4j/neo4jGraphStore.d.ts +23 -0
  13. package/dist/src/neo4j/neo4jGraphStore.js +134 -0
  14. package/dist/src/neo4j/neo4jGraphStore.js.map +1 -0
  15. package/dist/src/neo4j/neo4jUtilities.d.ts +4 -0
  16. package/dist/src/neo4j/neo4jUtilities.js +46 -0
  17. package/dist/src/neo4j/neo4jUtilities.js.map +1 -0
  18. package/dist/src/neo4j/uploadToNeo4j.d.ts +9 -0
  19. package/dist/src/neo4j/uploadToNeo4j.js +33 -0
  20. package/dist/src/neo4j/uploadToNeo4j.js.map +1 -0
  21. package/dist/src/neo4j/wipeNeo4j.d.ts +14 -0
  22. package/dist/src/neo4j/wipeNeo4j.js +41 -0
  23. package/dist/src/neo4j/wipeNeo4j.js.map +1 -0
  24. package/dist/tsconfig.dist.tsbuildinfo +4128 -1259
  25. package/package.json +12 -10
  26. package/src/commands/index.ts +1 -0
  27. package/src/commands/neo4j.ts +63 -0
  28. package/src/index.ts +3 -1
  29. package/src/neo4j/README.md +42 -0
  30. package/src/neo4j/__tests__/neo4jGraphStore.test.ts +99 -0
  31. package/src/neo4j/__tests__/neo4jUtilities.test.ts +25 -0
  32. package/src/neo4j/index.ts +2 -0
  33. package/src/neo4j/neo4jGraphStore.ts +139 -0
  34. package/src/neo4j/neo4jUtilities.ts +43 -0
  35. package/src/neo4j/uploadToNeo4j.ts +47 -0
  36. package/src/neo4j/wipeNeo4j.ts +58 -0
@@ -6,3 +6,4 @@ export * from './run';
6
6
  export * from './document';
7
7
  export * from './visualize-types';
8
8
  export * from './validate-question-file';
9
+ export * from './neo4j';
@@ -18,4 +18,5 @@ __exportStar(require("./run"), exports);
18
18
  __exportStar(require("./document"), exports);
19
19
  __exportStar(require("./visualize-types"), exports);
20
20
  __exportStar(require("./validate-question-file"), exports);
21
+ __exportStar(require("./neo4j"), exports);
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,yCAAuB;AACvB,wCAAsB;AACtB,6CAA2B;AAC3B,oDAAkC;AAClC,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,yCAAuB;AACvB,8CAA4B;AAC5B,yCAAuB;AACvB,wCAAsB;AACtB,6CAA2B;AAC3B,oDAAkC;AAClC,2DAAyC;AACzC,0CAAwB"}
@@ -0,0 +1,2 @@
1
+ import * as commander from 'commander';
2
+ export declare function neo4j(): commander.Command;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.neo4j = void 0;
26
+ const commander = __importStar(require("commander"));
27
+ const path_1 = __importDefault(require("path"));
28
+ const dotenv_1 = __importDefault(require("dotenv"));
29
+ const dotenv_expand_1 = __importDefault(require("dotenv-expand"));
30
+ const log = __importStar(require("../log"));
31
+ const neo4j_1 = require("../neo4j");
32
+ function neo4j() {
33
+ dotenv_expand_1.default(dotenv_1.default.config());
34
+ const program = new commander.Command();
35
+ program.description(`Suite of neo4j commands. Options are currently 'neo4j push', 'neo4j wipe', and 'neo4j wipe-all'`);
36
+ const neo4jCommand = program.command('neo4j');
37
+ neo4jCommand
38
+ .command('push')
39
+ .description('upload collected entities and relationships to local Neo4j')
40
+ .option('-d, --data-dir <directory>', 'path to collected entities and relationships', path_1.default.resolve(process.cwd(), '.j1-integration'))
41
+ .option('-i, --integration-instance-id <id>', '_integrationInstanceId assigned to uploaded entities', 'defaultLocalInstanceID')
42
+ .action(async (options) => {
43
+ log.info(`Beginning data upload to local neo4j`);
44
+ // Point `fileSystem.ts` functions to expected location relative to
45
+ // integration project path.
46
+ const finalDir = path_1.default.resolve(process.cwd(), options.dataDir);
47
+ process.env.JUPITERONE_INTEGRATION_STORAGE_DIRECTORY = finalDir;
48
+ await neo4j_1.uploadToNeo4j({
49
+ pathToData: finalDir,
50
+ integrationInstanceID: options.integrationInstanceId
51
+ });
52
+ log.info(`Data uploaded to local neo4j`);
53
+ });
54
+ neo4jCommand
55
+ .command('wipe')
56
+ .description('wipe entities and relationships for a given integrationInstanceID in the Neo4j database')
57
+ .option('-i, --integration-instance-id <id>', '_integrationInstanceId assigned to uploaded entities', 'defaultLocalInstanceID')
58
+ .action(async (options) => {
59
+ await neo4j_1.wipeNeo4jByID({ integrationInstanceID: options.integrationInstanceId });
60
+ });
61
+ neo4jCommand
62
+ .command('wipe-all')
63
+ .description('wipe all entities and relationships in the Neo4j database')
64
+ .action(async (options) => {
65
+ await neo4j_1.wipeAllNeo4j({});
66
+ });
67
+ return neo4jCommand;
68
+ }
69
+ exports.neo4j = neo4j;
70
+ //# sourceMappingURL=neo4j.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neo4j.js","sourceRoot":"","sources":["../../../src/commands/neo4j.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,gDAAwB;AAExB,oDAA4B;AAC5B,kEAAyC;AAEzC,4CAA8B;AAC9B,oCAAsE;AAEtE,SAAgB,KAAK;IACnB,uBAAY,CAAC,gBAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAE9B,MAAM,OAAO,GAAG,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;IACxC,OAAO,CAAC,WAAW,CAAC,kGAAkG,CAAC,CAAC;IACxH,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,YAAY;SACT,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,4DAA4D,CAAC;SACzE,MAAM,CACL,4BAA4B,EAC5B,8CAA8C,EAC9C,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAC/C;SACA,MAAM,CACL,oCAAoC,EACpC,sDAAsD,EACtD,wBAAwB,CACzB;SACA,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,GAAG,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACjD,mEAAmE;QACnE,4BAA4B;QAC5B,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9D,OAAO,CAAC,GAAG,CAAC,wCAAwC,GAAG,QAAQ,CAAC;QAEhE,MAAM,qBAAa,CAAC;YAClB,UAAU,EAAE,QAAQ;YACpB,qBAAqB,EAAE,OAAO,CAAC,qBAAqB;SACrD,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,YAAY;SACX,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,yFAAyF,CAAC;SACtG,MAAM,CACL,oCAAoC,EACpC,sDAAsD,EACtD,wBAAwB,CACzB;SACA,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,qBAAa,CAAC,EAAC,qBAAqB,EAAE,OAAO,CAAC,qBAAqB,EAAC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IAEH,YAAY;SACX,OAAO,CAAC,UAAU,CAAC;SACnB,WAAW,CAAC,2DAA2D,CAAC;SACxE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,oBAAY,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACxB,CAAC;AArDD,sBAqDC"}
package/dist/src/index.js CHANGED
@@ -12,7 +12,8 @@ function createCli() {
12
12
  .addCommand(commands_1.run())
13
13
  .addCommand(commands_1.visualizeTypes())
14
14
  .addCommand(commands_1.document())
15
- .addCommand(commands_1.validateQuestionFile());
15
+ .addCommand(commands_1.validateQuestionFile())
16
+ .addCommand(commands_1.neo4j());
16
17
  }
17
18
  exports.createCli = createCli;
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAE1C,yCASoB;AAEpB,SAAgB,SAAS;IACvB,OAAO,yBAAa,EAAE;SACnB,UAAU,CAAC,kBAAO,EAAE,CAAC;SACrB,UAAU,CAAC,eAAI,EAAE,CAAC;SAClB,UAAU,CAAC,oBAAS,EAAE,CAAC;SACvB,UAAU,CAAC,eAAI,EAAE,CAAC;SAClB,UAAU,CAAC,cAAG,EAAE,CAAC;SACjB,UAAU,CAAC,yBAAc,EAAE,CAAC;SAC5B,UAAU,CAAC,mBAAQ,EAAE,CAAC;SACtB,UAAU,CAAC,+BAAoB,EAAE,CAAC,CAAC;AACxC,CAAC;AAVD,8BAUC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAE1C,yCAUoB;AAEpB,SAAgB,SAAS;IACvB,OAAO,yBAAa,EAAE;SACnB,UAAU,CAAC,kBAAO,EAAE,CAAC;SACrB,UAAU,CAAC,eAAI,EAAE,CAAC;SAClB,UAAU,CAAC,oBAAS,EAAE,CAAC;SACvB,UAAU,CAAC,eAAI,EAAE,CAAC;SAClB,UAAU,CAAC,cAAG,EAAE,CAAC;SACjB,UAAU,CAAC,yBAAc,EAAE,CAAC;SAC5B,UAAU,CAAC,mBAAQ,EAAE,CAAC;SACtB,UAAU,CAAC,+BAAoB,EAAE,CAAC;SAClC,UAAU,CAAC,gBAAK,EAAE,CAAC,CAAC;AACzB,CAAC;AAXD,8BAWC"}
@@ -0,0 +1,2 @@
1
+ export * from './uploadToNeo4j';
2
+ export * from './wipeNeo4j';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./uploadToNeo4j"), exports);
14
+ __exportStar(require("./wipeNeo4j"), exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/neo4j/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,8CAA4B"}
@@ -0,0 +1,23 @@
1
+ import { Entity, Relationship } from '@jupiterone/integration-sdk-core';
2
+ import * as neo4j from 'neo4j-driver';
3
+ export interface Neo4jGraphObjectStoreParams {
4
+ uri: string;
5
+ username: string;
6
+ password: string;
7
+ integrationInstanceID: string;
8
+ session?: neo4j.Session;
9
+ }
10
+ export declare class Neo4jGraphStore {
11
+ private neo4jDriver;
12
+ private persistedSession;
13
+ private databaseName;
14
+ private typeList;
15
+ private integrationInstanceID;
16
+ constructor(params: Neo4jGraphObjectStoreParams);
17
+ private runCypherCommand;
18
+ addEntities(newEntities: Entity[]): Promise<void>;
19
+ addRelationships(newRelationships: Relationship[]): Promise<void>;
20
+ wipeInstanceIdData(): Promise<void>;
21
+ wipeDatabase(): Promise<void>;
22
+ close(): Promise<void>;
23
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.Neo4jGraphStore = void 0;
23
+ const neo4jUtilities_1 = require("./neo4jUtilities");
24
+ const neo4j = __importStar(require("neo4j-driver"));
25
+ class Neo4jGraphStore {
26
+ constructor(params) {
27
+ this.databaseName = 'neo4j';
28
+ this.typeList = new Set();
29
+ if (params.session) {
30
+ this.persistedSession = params.session;
31
+ }
32
+ else {
33
+ this.neo4jDriver = neo4j.driver(params.uri, neo4j.auth.basic(params.username, params.password));
34
+ }
35
+ this.integrationInstanceID = params.integrationInstanceID;
36
+ }
37
+ async runCypherCommand(cypherCommand, cypherParameters) {
38
+ if (this.persistedSession) {
39
+ const result = await this.persistedSession.run(cypherCommand);
40
+ return result;
41
+ }
42
+ else {
43
+ const session = this.neo4jDriver.session({
44
+ database: this.databaseName,
45
+ defaultAccessMode: neo4j.session.WRITE,
46
+ });
47
+ const result = await session.run(cypherCommand, cypherParameters);
48
+ await session.close();
49
+ return result;
50
+ }
51
+ }
52
+ async addEntities(newEntities) {
53
+ const nodeAlias = 'entityNode';
54
+ for (const entity of newEntities) {
55
+ //Add index if not already in types. This will optimize future
56
+ //MATCH/MERGE calls.
57
+ if (!this.typeList.has(entity._type)) {
58
+ await this.runCypherCommand(`CREATE INDEX index_${entity._type} IF NOT EXISTS FOR (n:${entity._type}) ON (n._key, n._integrationInstanceID);`);
59
+ this.typeList.add(entity._type);
60
+ }
61
+ const propertyParameters = neo4jUtilities_1.buildPropertyParameters(entity);
62
+ const finalKeyValue = neo4jUtilities_1.sanitizeValue(entity._key.toString());
63
+ const buildCommand = `
64
+ MERGE (${nodeAlias} {_key: $finalKeyValue, _integrationInstanceID: $integrationInstanceID})
65
+ SET ${nodeAlias} += $propertyParameters
66
+ SET ${nodeAlias}:${entity._type};`;
67
+ await this.runCypherCommand(buildCommand, {
68
+ propertyParameters: propertyParameters,
69
+ finalKeyValue: finalKeyValue,
70
+ integrationInstanceID: this.integrationInstanceID
71
+ });
72
+ }
73
+ }
74
+ async addRelationships(newRelationships) {
75
+ for (const relationship of newRelationships) {
76
+ const relationshipAlias = 'relationship';
77
+ const propertyParameters = neo4jUtilities_1.buildPropertyParameters(relationship);
78
+ let startEntityKey = '';
79
+ let endEntityKey = '';
80
+ //Get start and end _keys. Will be overwritten if we're
81
+ //working with a mapped relationship.
82
+ if (relationship._fromEntityKey) {
83
+ startEntityKey = neo4jUtilities_1.sanitizeValue(relationship._fromEntityKey.toString());
84
+ }
85
+ if (relationship._toEntityKey) {
86
+ endEntityKey = neo4jUtilities_1.sanitizeValue(relationship._toEntityKey.toString());
87
+ }
88
+ if (relationship._mapping) { //Mapped Relationship
89
+ if (relationship._mapping['skipTargetCreation'] === false) {
90
+ //Create target entity first
91
+ const tempEntity = {
92
+ _class: relationship._mapping['targetEntity']._class,
93
+ //TODO, I think this key is wrong, but not sure what else to use
94
+ _key: neo4jUtilities_1.sanitizeValue(relationship._key.replace(relationship._mapping['sourceEntityKey'], '')),
95
+ _type: relationship._mapping['targetEntity']._type,
96
+ };
97
+ await this.addEntities([tempEntity]);
98
+ }
99
+ startEntityKey = neo4jUtilities_1.sanitizeValue(relationship._mapping['sourceEntityKey']);
100
+ // TODO, see above. This key might also be an issue for the same reason
101
+ endEntityKey = neo4jUtilities_1.sanitizeValue(relationship._key.replace(relationship._mapping['sourceEntityKey'], ''));
102
+ }
103
+ const buildCommand = `
104
+ MERGE (start {_key: $startEntityKey, _integrationInstanceID: $integrationInstanceID})
105
+ MERGE (end {_key: $endEntityKey, _integrationInstanceID: $integrationInstanceID})
106
+ MERGE (start)-[${relationshipAlias}:${relationship._type}]->(end)
107
+ SET ${relationshipAlias} += $propertyParameters;`;
108
+ await this.runCypherCommand(buildCommand, {
109
+ propertyParameters: propertyParameters,
110
+ startEntityKey: startEntityKey,
111
+ endEntityKey: endEntityKey,
112
+ integrationInstanceID: this.integrationInstanceID
113
+ });
114
+ }
115
+ }
116
+ // TODO, if we get to very large databases we could reach a size where
117
+ // one or both both of the below wipe commands can't be easily executed
118
+ // in memory. At that time, we should consider requiring/using the APOC
119
+ // library so we can use apoc.periodic.iterate. Leaving out for now,
120
+ // since that would further complicate the Neo4j database setup.
121
+ async wipeInstanceIdData() {
122
+ const wipeCypherCommand = `MATCH (n {_integrationInstanceID: '${this.integrationInstanceID}'}) DETACH DELETE n`;
123
+ await this.runCypherCommand(wipeCypherCommand);
124
+ }
125
+ async wipeDatabase() {
126
+ const wipeCypherCommand = `MATCH (n) DETACH DELETE n`;
127
+ await this.runCypherCommand(wipeCypherCommand);
128
+ }
129
+ async close() {
130
+ await this.neo4jDriver.close();
131
+ }
132
+ }
133
+ exports.Neo4jGraphStore = Neo4jGraphStore;
134
+ //# sourceMappingURL=neo4jGraphStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neo4jGraphStore.js","sourceRoot":"","sources":["../../../src/neo4j/neo4jGraphStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,qDAA0E;AAE1E,oDAAsC;AAUtC,MAAa,eAAe;IAO1B,YAAY,MAAmC;QAJvC,iBAAY,GAAG,OAAO,CAAC;QACvB,aAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;QAInC,IAAG,MAAM,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC;SACxC;aACI;YACH,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,MAAM,CAC7B,MAAM,CAAC,GAAG,EACV,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CACnD,CAAC;SACH;QACD,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC,qBAAqB,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,CAAC,CAAC,CAAC;iBACtC;gBACD,cAAc,GAAG,8BAAa,CAAC,YAAY,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;gBACzE,wEAAwE;gBACxE,YAAY,GAAG,8BAAa,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;aACvG;YAED,MAAM,YAAY,GAAG;;;uBAGJ,iBAAiB,IAAI,YAAY,CAAC,KAAK;YAClD,iBAAiB,0BAA0B,CAAC;YAClD,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE;gBACxC,kBAAkB,EAAE,kBAAkB;gBACtC,cAAc,EAAE,cAAc;gBAC9B,YAAY,EAAE,YAAY;gBAC1B,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;aAClD,CAAC,CAAC;SACJ;IACH,CAAC;IAED,sEAAsE;IACtE,wEAAwE;IACxE,yEAAyE;IACzE,qEAAqE;IACrE,gEAAgE;IAChE,KAAK,CAAC,kBAAkB;QACtB,MAAM,iBAAiB,GAAG,sCAAsC,IAAI,CAAC,qBAAqB,qBAAqB,CAAC;QAChH,MAAM,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,iBAAiB,GAAG,2BAA2B,CAAC;QACtD,MAAM,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CACF;AA7HD,0CA6HC"}
@@ -0,0 +1,4 @@
1
+ export declare function startsWithNumeric(str: string): boolean;
2
+ export declare function sanitizePropertyName(propertyName: string): string;
3
+ export declare function sanitizeValue(value: string): string;
4
+ export declare function buildPropertyParameters(propList: Object): {};
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPropertyParameters = exports.sanitizeValue = exports.sanitizePropertyName = exports.startsWithNumeric = void 0;
4
+ function startsWithNumeric(str) {
5
+ return /^\d/.test(str);
6
+ }
7
+ exports.startsWithNumeric = startsWithNumeric;
8
+ function sanitizePropertyName(propertyName) {
9
+ let sanitizedName = '';
10
+ if (startsWithNumeric(propertyName)) {
11
+ sanitizedName += 'n';
12
+ }
13
+ sanitizedName += propertyName;
14
+ sanitizedName = sanitizedName.replace(/[\s!@#$%^&*()\-=+\\|'";:/?.,><`~\t\n[\]{}]/g, "_");
15
+ return sanitizedName;
16
+ }
17
+ exports.sanitizePropertyName = sanitizePropertyName;
18
+ function sanitizeValue(value) {
19
+ return value.replace(/"/gi, '\\"');
20
+ }
21
+ exports.sanitizeValue = sanitizeValue;
22
+ function buildPropertyParameters(propList) {
23
+ const propertyParameters = {};
24
+ for (const key in propList) {
25
+ if (key === '_rawData') {
26
+ //stringify JSON in rawData so we can store it.
27
+ propertyParameters[key] = `"${JSON.stringify(propList[key])}"`;
28
+ }
29
+ else {
30
+ // Sanitize out characters that aren't allowed in property names
31
+ const propertyName = sanitizePropertyName(key);
32
+ //If we're dealing with a number or boolean, leave alone, otherwise
33
+ //wrap in single quotes to convert to a string and escape all
34
+ //other single quotes so they don't terminate strings prematurely.
35
+ if (typeof propList[key] == 'number' || typeof propList[key] == 'boolean') {
36
+ propertyParameters[propertyName] = propList[key];
37
+ }
38
+ else {
39
+ propertyParameters[propertyName] = sanitizeValue(propList[key].toString());
40
+ }
41
+ }
42
+ }
43
+ return propertyParameters;
44
+ }
45
+ exports.buildPropertyParameters = buildPropertyParameters;
46
+ //# sourceMappingURL=neo4jUtilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"neo4jUtilities.js","sourceRoot":"","sources":["../../../src/neo4j/neo4jUtilities.ts"],"names":[],"mappings":";;;AACA,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,OAAO,K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BAAkB,CAAC;AAC5B,CAAC;AAvBD,0DAuBC"}
@@ -0,0 +1,9 @@
1
+ declare type UploadToNeo4jParams = {
2
+ pathToData: string;
3
+ integrationInstanceID: string;
4
+ neo4jUri?: string;
5
+ neo4jUser?: string;
6
+ neo4jPassword?: string;
7
+ };
8
+ export declare function uploadToNeo4j({ pathToData, integrationInstanceID, neo4jUri, neo4jUser, neo4jPassword, }: UploadToNeo4jParams): Promise<void>;
9
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadToNeo4j = void 0;
4
+ const neo4jGraphStore_1 = require("./neo4jGraphStore");
5
+ const integration_sdk_runtime_1 = require("@jupiterone/integration-sdk-runtime");
6
+ async function uploadToNeo4j({ pathToData, integrationInstanceID, neo4jUri = process.env.NEO4J_URI, neo4jUser = process.env.NEO4J_USER, neo4jPassword = process.env.NEO4J_PASSWORD, }) {
7
+ if (!neo4jUri || !neo4jUser || !neo4jPassword) {
8
+ 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!');
9
+ }
10
+ if (!integration_sdk_runtime_1.isDirectoryPresent(pathToData)) {
11
+ throw new Error('ERROR: graph directory does not exist!');
12
+ }
13
+ const store = new neo4jGraphStore_1.Neo4jGraphStore({
14
+ uri: neo4jUri,
15
+ username: neo4jUser,
16
+ password: neo4jPassword,
17
+ integrationInstanceID: integrationInstanceID,
18
+ });
19
+ async function handleGraphObjectFile(parsedData) {
20
+ if (parsedData.entities)
21
+ await store.addEntities(parsedData.entities);
22
+ if (parsedData.relationships)
23
+ await store.addRelationships(parsedData.relationships);
24
+ }
25
+ try {
26
+ await integration_sdk_runtime_1.iterateParsedGraphFiles(handleGraphObjectFile, pathToData);
27
+ }
28
+ finally {
29
+ await store.close();
30
+ }
31
+ }
32
+ exports.uploadToNeo4j = uploadToNeo4j;
33
+ //# sourceMappingURL=uploadToNeo4j.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploadToNeo4j.js","sourceRoot":"","sources":["../../../src/neo4j/uploadToNeo4j.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,iFAAkG;AAW3F,KAAK,UAAU,aAAa,CAAC,EAClC,UAAU,EACV,qBAAqB,EACrB,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAChC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAClC,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,GACtB;IACpB,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,aAAa,EAAE;QAC7C,MAAM,IAAI,KAAK,CACb,sIAAsI,CACvI,CAAC;KACH;IACD,IAAI,CAAC,4CAAkB,CAAC,UAAU,CAAC,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IAED,MAAM,KAAK,GAAG,IAAI,iCAAe,CAAC;QAChC,GAAG,EAAE,QAAQ;QACb,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,aAAa;QACvB,qBAAqB,EAAE,qBAAqB;KAC7C,CAAC,CAAC;IAEH,KAAK,UAAU,qBAAqB,CAAC,UAAkC;QACrE,IAAI,UAAU,CAAC,QAAQ;YAAE,MAAM,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,UAAU,CAAC,aAAa;YAC1B,MAAM,KAAK,CAAC,gBAAgB,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI;QACF,MAAM,iDAAuB,CAAC,qBAAqB,EAAE,UAAU,CAAC,CAAC;KAClE;YAAS;QACR,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;KACrB;AACH,CAAC;AAlCD,sCAkCC"}
@@ -0,0 +1,14 @@
1
+ declare type WipeNeo4jParams = {
2
+ integrationInstanceID: string;
3
+ neo4jUri?: string;
4
+ neo4jUser?: string;
5
+ neo4jPassword?: string;
6
+ };
7
+ export declare function wipeNeo4jByID({ integrationInstanceID, neo4jUri, neo4jUser, neo4jPassword, }: WipeNeo4jParams): Promise<void>;
8
+ declare type WipeAllNeo4jParams = {
9
+ neo4jUri?: string;
10
+ neo4jUser?: string;
11
+ neo4jPassword?: string;
12
+ };
13
+ export declare function wipeAllNeo4j({ neo4jUri, neo4jUser, neo4jPassword, }: WipeAllNeo4jParams): Promise<void>;
14
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wipeAllNeo4j = exports.wipeNeo4jByID = void 0;
4
+ const neo4jGraphStore_1 = require("./neo4jGraphStore");
5
+ async function wipeNeo4jByID({ integrationInstanceID, neo4jUri = process.env.NEO4J_URI, neo4jUser = process.env.NEO4J_USER, neo4jPassword = process.env.NEO4J_PASSWORD, }) {
6
+ if (!neo4jUri || !neo4jUser || !neo4jPassword) {
7
+ 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!');
8
+ }
9
+ const store = new neo4jGraphStore_1.Neo4jGraphStore({
10
+ uri: neo4jUri,
11
+ username: neo4jUser,
12
+ password: neo4jPassword,
13
+ integrationInstanceID: integrationInstanceID,
14
+ });
15
+ try {
16
+ await store.wipeInstanceIdData();
17
+ }
18
+ finally {
19
+ await store.close();
20
+ }
21
+ }
22
+ exports.wipeNeo4jByID = wipeNeo4jByID;
23
+ async function wipeAllNeo4j({ neo4jUri = process.env.NEO4J_URI, neo4jUser = process.env.NEO4J_USER, neo4jPassword = process.env.NEO4J_PASSWORD, }) {
24
+ if (!neo4jUri || !neo4jUser || !neo4jPassword) {
25
+ 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!');
26
+ }
27
+ const store = new neo4jGraphStore_1.Neo4jGraphStore({
28
+ uri: neo4jUri,
29
+ username: neo4jUser,
30
+ password: neo4jPassword,
31
+ integrationInstanceID: '',
32
+ });
33
+ try {
34
+ await store.wipeDatabase();
35
+ }
36
+ finally {
37
+ await store.close();
38
+ }
39
+ }
40
+ exports.wipeAllNeo4j = wipeAllNeo4j;
41
+ //# sourceMappingURL=wipeNeo4j.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wipeNeo4j.js","sourceRoot":"","sources":["../../../src/neo4j/wipeNeo4j.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAQ7C,KAAK,UAAU,aAAa,CAAC,EAClC,qBAAqB,EACrB,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAChC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAE,UAAU,EACnC,aAAa,GAAG,OAAO,CAAC,GAAG,CAAE,cAAc,GAC3B;IAChB,IAAG,CAAC,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,aAAa,EAAE;QAC5C,MAAM,IAAI,KAAK,CAAC,sIAAsI,CAAC,CAAC;KACzJ;IAED,MAAM,KAAK,GAAG,IAAI,iCAAe,CAAC;QAChC,GAAG,EAAE,QAAQ;QACb,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,aAAa;QACvB,qBAAqB,EAAE,qBAAqB;KAC7C,CAAC,CAAC;IACH,IAAI;QACF,MAAM,KAAK,CAAC,kBAAkB,EAAE,CAAC;KAClC;YAAS;QACR,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;KACrB;AACH,CAAC;AArBD,sCAqBC;AAQM,KAAK,UAAU,YAAY,CAAC,EACjC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,EAChC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAE,UAAU,EACnC,aAAa,GAAG,OAAO,CAAC,GAAG,CAAE,cAAc,GACxB;IACnB,IAAG,CAAC,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,aAAa,EAAE;QAC5C,MAAM,IAAI,KAAK,CAAC,sIAAsI,CAAC,CAAC;K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