@nivinjoseph/n-sec 5.0.3 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const tslib_1 = require("tslib");
5
+ // import { given } from "@nivinjoseph/n-defensive";
6
+ const n_util_1 = require("@nivinjoseph/n-util");
7
+ const symmetric_encryption_1 = require("./crypto/symmetric-encryption");
8
+ var SupportedCommands;
9
+ (function (SupportedCommands) {
10
+ SupportedCommands["generateSymmetricKey"] = "generate-symmetric-key";
11
+ })(SupportedCommands || (SupportedCommands = {}));
12
+ const supportedCommandsString = JSON.stringify(n_util_1.TypeHelper.enumTypeToTuples(SupportedCommands).map(t => t[1]));
13
+ function executeCommand(command) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ // given(command, "command").ensureHasValue().ensureIsString();
16
+ switch (command) {
17
+ case SupportedCommands.generateSymmetricKey:
18
+ {
19
+ const key = yield symmetric_encryption_1.SymmetricEncryption.generateKey();
20
+ console.log("SYMMETRIC KEY => ", key);
21
+ break;
22
+ }
23
+ default:
24
+ console.error(`Unknown command '${command}'. Supported commands are ${supportedCommandsString}.`);
25
+ }
26
+ });
27
+ }
28
+ const args = process.argv.slice(2);
29
+ if (args.length !== 1) {
30
+ console.error(`Please enter a single command. Supported commands are ${supportedCommandsString}.`);
31
+ process.exit(1); //an error occurred
32
+ }
33
+ const command = args[0];
34
+ executeCommand(command)
35
+ .then(() => process.exit(0))
36
+ .catch(e => {
37
+ console.error("Error occurred");
38
+ console.error(e);
39
+ process.exit(1);
40
+ });
41
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/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C;IAChC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivinjoseph/n-sec",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "Security library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -17,6 +17,7 @@
17
17
  "test-ci": "mocha --timeout 5000 --reporter spec --ui tdd --require ts-node/register './test/**/*.test.js'",
18
18
  "publish-package": "npm run ts-build-dist && git add . && git commit -m 'preparing to publish new version' && npm version patch && git push && npm publish --access=public"
19
19
  },
20
+ "bin": "./dist/bin.js",
20
21
  "repository": {
21
22
  "type": "git",
22
23
  "url": "git+https://github.com/nivinjoseph/n-sec.git"
@@ -44,6 +45,7 @@
44
45
  "dependencies": {
45
46
  "@nivinjoseph/n-defensive": "^1.0.41",
46
47
  "@nivinjoseph/n-exception": "^1.0.26",
47
- "@nivinjoseph/n-ext": "^1.1.36"
48
+ "@nivinjoseph/n-ext": "^1.1.36",
49
+ "@nivinjoseph/n-util": "^1.0.81"
48
50
  }
49
51
  }
package/src/bin.ts ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ // import { given } from "@nivinjoseph/n-defensive";
4
+ import { TypeHelper } from "@nivinjoseph/n-util";
5
+ import { SymmetricEncryption } from "./crypto/symmetric-encryption";
6
+
7
+ enum SupportedCommands
8
+ {
9
+ generateSymmetricKey = "generate-symmetric-key"
10
+ }
11
+
12
+ const supportedCommandsString = JSON.stringify(TypeHelper.enumTypeToTuples(SupportedCommands).map(t => t[1]));
13
+
14
+ async function executeCommand(command: SupportedCommands): Promise<void>
15
+ {
16
+ // given(command, "command").ensureHasValue().ensureIsString();
17
+
18
+ switch (command)
19
+ {
20
+ case SupportedCommands.generateSymmetricKey:
21
+ {
22
+ const key = await SymmetricEncryption.generateKey();
23
+ console.log("SYMMETRIC KEY => ", key);
24
+ break;
25
+ }
26
+ default:
27
+ console.error(`Unknown command '${command}'. Supported commands are ${supportedCommandsString}.`);
28
+ }
29
+ }
30
+
31
+ const args = process.argv.slice(2);
32
+
33
+ if (args.length !== 1)
34
+ {
35
+ console.error(`Please enter a single command. Supported commands are ${supportedCommandsString}.`);
36
+ process.exit(1); //an error occurred
37
+ }
38
+
39
+ const command = args[0] as SupportedCommands;
40
+
41
+ executeCommand(command)
42
+ .then(() => process.exit(0))
43
+ .catch(e =>
44
+ {
45
+ console.error("Error occurred");
46
+ console.error(e);
47
+ process.exit(1);
48
+ });
49
+