@aneuhold/core-ts-lib 1.0.10 → 1.0.12

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/lib/index.d.ts CHANGED
@@ -6,8 +6,9 @@ import DockerService from './services/applications/DockerService';
6
6
  import FileSystemService from './services/applications/FileSystemService';
7
7
  import ITermService from './services/applications/ITermService';
8
8
  import CLIService from './services/CLIService';
9
+ import ConfigService from './services/ConfigService/ConfigService';
9
10
  import StringService from './services/StringService';
10
11
  import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
11
12
  import Logger from './utils/Logger';
12
- export { CLIService, StringService, CurrentEnv, ChromeService, DockerService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, getFileNameExtension, ITermService };
13
+ export { CLIService, StringService, CurrentEnv, ChromeService, DockerService, FileSystemService, sleep, OperatingSystemType, ShellType, Logger, TerminalType, datesAreOnSameDay, getFileNameExtension, ITermService, ConfigService };
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAC1E,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,0BAA0B,CAAC;AACrD,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,MAAM,MAAM,gBAAgB,CAAC;AAGpC,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACb,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,MAAM,yBAAyB,CAAC;AAC5C,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAC1E,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,aAAa,MAAM,0BAA0B,CAAC;AACrD,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,MAAM,MAAM,gBAAgB,CAAC;AAGpC,OAAO,EACL,UAAU,EACV,aAAa,EACb,UAAU,EACV,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACd,CAAC"}
package/lib/index.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ITermService = exports.getFileNameExtension = exports.datesAreOnSameDay = exports.TerminalType = exports.Logger = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.FileSystemService = exports.DockerService = exports.ChromeService = exports.CurrentEnv = exports.StringService = exports.CLIService = void 0;
29
+ exports.ConfigService = exports.ITermService = exports.getFileNameExtension = exports.datesAreOnSameDay = exports.TerminalType = exports.Logger = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.FileSystemService = exports.DockerService = exports.ChromeService = exports.CurrentEnv = exports.StringService = exports.CLIService = void 0;
30
30
  const dateFunctions_1 = __importDefault(require("./helperFunctions/dateFunctions"));
31
31
  exports.datesAreOnSameDay = dateFunctions_1.default;
32
32
  const sleep_1 = __importDefault(require("./helperFunctions/sleep"));
@@ -43,6 +43,8 @@ const ITermService_1 = __importDefault(require("./services/applications/ITermSer
43
43
  exports.ITermService = ITermService_1.default;
44
44
  const CLIService_1 = __importDefault(require("./services/CLIService"));
45
45
  exports.CLIService = CLIService_1.default;
46
+ const ConfigService_1 = __importDefault(require("./services/ConfigService/ConfigService"));
47
+ exports.ConfigService = ConfigService_1.default;
46
48
  const StringService_1 = __importDefault(require("./services/StringService"));
47
49
  exports.StringService = StringService_1.default;
48
50
  const CurrentEnv_1 = __importStar(require("./utils/CurrentEnv"));
@@ -0,0 +1,25 @@
1
+ import 'dotenv/config';
2
+ export type ConfigEnv = 'local' | 'dev' | 'prod';
3
+ /**
4
+ * A class which can be used to load configuration into the local environment
5
+ * from a pre-defined location.
6
+ */
7
+ export default class ConfigService {
8
+ private static gitHub;
9
+ static useConfig(env: string): Promise<void>;
10
+ /**
11
+ * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
12
+ * local environment or .env file.
13
+ */
14
+ private static getGitHubClient;
15
+ /**
16
+ * Inserts the provided configuration into the local environment.
17
+ */
18
+ private static insertPropertiesIntoEnv;
19
+ /**
20
+ * Strips JSON comments from the provided JSON string. Only `//` comments
21
+ * are supported at the moment.
22
+ */
23
+ private static stripJsonComments;
24
+ }
25
+ //# sourceMappingURL=ConfigService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAGvB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwB;WAEhC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBlD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAUtC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAG9B;CACH"}
@@ -0,0 +1,72 @@
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
+ const octokit_1 = require("octokit");
7
+ require("dotenv/config");
8
+ const Logger_1 = __importDefault(require("../../utils/Logger"));
9
+ /**
10
+ * A class which can be used to load configuration into the local environment
11
+ * from a pre-defined location.
12
+ */
13
+ class ConfigService {
14
+ static gitHub = null;
15
+ static async useConfig(env) {
16
+ if (!ConfigService.gitHub) {
17
+ ConfigService.gitHub = ConfigService.getGitHubClient();
18
+ }
19
+ try {
20
+ const result = await ConfigService.gitHub.rest.repos.getContent({
21
+ mediaType: {
22
+ format: 'raw'
23
+ },
24
+ owner: 'aneuhold',
25
+ repo: 'config',
26
+ path: `${env}.jsonc`
27
+ });
28
+ const strippedJson = ConfigService.stripJsonComments(result.data);
29
+ const config = JSON.parse(strippedJson);
30
+ ConfigService.insertPropertiesIntoEnv(config);
31
+ }
32
+ catch (error) {
33
+ Logger_1.default.error(`Failed to load ${env}.json, error: ${error}`);
34
+ throw error;
35
+ }
36
+ }
37
+ /**
38
+ * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
39
+ * local environment or .env file.
40
+ */
41
+ static getGitHubClient() {
42
+ const authToken = process.env.CONFIG_GITHUB_TOKEN;
43
+ if (!authToken) {
44
+ throw new Error('No CONFIG_GITHUB_TOKEN key found in environment variables.');
45
+ }
46
+ return new octokit_1.Octokit({
47
+ auth: authToken
48
+ });
49
+ }
50
+ /**
51
+ * Inserts the provided configuration into the local environment.
52
+ */
53
+ static insertPropertiesIntoEnv(config) {
54
+ Object.entries(config).forEach(([key, value]) => {
55
+ if (typeof value === 'object') {
56
+ ConfigService.insertPropertiesIntoEnv(value);
57
+ }
58
+ else {
59
+ process.env[key] = value;
60
+ }
61
+ });
62
+ }
63
+ /**
64
+ * Strips JSON comments from the provided JSON string. Only `//` comments
65
+ * are supported at the moment.
66
+ */
67
+ static stripJsonComments = (jsonString) => {
68
+ const commentRegex = /\/\/(.*)/g;
69
+ return jsonString.replace(commentRegex, '');
70
+ };
71
+ }
72
+ exports.default = ConfigService;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Output from a Digital Ocean function must always be an object.
3
+ */
4
+ export type DOFunctionOutput<TOutput extends object> = {
5
+ /**
6
+ * The body is an object, which means it will automatically be serialized to
7
+ * JSON and the Content-Type header will be set to application/json.
8
+ */
9
+ body: TOutput;
10
+ };
11
+ /**
12
+ * A service to provide some utility common to multiple Digital Ocean functions.
13
+ */
14
+ export default class DOFunctionService {
15
+ }
16
+ //# sourceMappingURL=DOFunctionService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../src/services/DOFunctionService.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,MAAM,IAAI;IACrD;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;CAAG"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * A service to provide some utility common to multiple Digital Ocean functions.
5
+ */
6
+ class DOFunctionService {
7
+ }
8
+ exports.default = DOFunctionService;
@@ -0,0 +1,14 @@
1
+ export default class TestUtils {
2
+ private static consoleLoggers;
3
+ /**
4
+ * Suppresses the console output of all console loggers (error, log, info, etc.).
5
+ * Use `restoreConsole` when the test is finished to restore the console.
6
+ */
7
+ static suppressConsole(): void;
8
+ /**
9
+ * Restores the normal console output functionality of all console loggers
10
+ * (error, log, info, etc.).
11
+ */
12
+ static restoreConsole(): void;
13
+ }
14
+ //# sourceMappingURL=TestUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TestUtils.d.ts","sourceRoot":"","sources":["../../src/utils/TestUtils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,OAAO,CAAC,MAAM,CAAC,cAAc,CAK3B;IAEF;;;OAGG;WACW,eAAe;IAO7B;;;OAGG;WACW,cAAc;CAM7B"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class TestUtils {
4
+ static consoleLoggers = {
5
+ error: console.error,
6
+ log: console.log,
7
+ info: console.info,
8
+ warn: console.warn
9
+ };
10
+ /**
11
+ * Suppresses the console output of all console loggers (error, log, info, etc.).
12
+ * Use `restoreConsole` when the test is finished to restore the console.
13
+ */
14
+ static suppressConsole() {
15
+ console.error = jest.fn();
16
+ console.log = jest.fn();
17
+ console.info = jest.fn();
18
+ console.warn = jest.fn();
19
+ }
20
+ /**
21
+ * Restores the normal console output functionality of all console loggers
22
+ * (error, log, info, etc.).
23
+ */
24
+ static restoreConsole() {
25
+ console.error = TestUtils.consoleLoggers.error;
26
+ console.log = TestUtils.consoleLoggers.log;
27
+ console.info = TestUtils.consoleLoggers.info;
28
+ console.warn = TestUtils.consoleLoggers.warn;
29
+ }
30
+ }
31
+ exports.default = TestUtils;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/core-ts-lib",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "A core library for all of my TypeScript projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "pushpub": "npm run build && npm version patch && git push && npm publish --access public",
9
9
  "build": "tsc",
10
10
  "watch": "tsc -w",
11
- "upgrade:all": "yarn upgrade --latest"
11
+ "upgrade:all": "yarn upgrade --latest",
12
+ "test": "jest"
12
13
  },
13
14
  "type": "commonjs",
14
15
  "repository": {
@@ -28,8 +29,12 @@
28
29
  "files": [
29
30
  "lib/**/*"
30
31
  ],
31
- "dependencies": {},
32
+ "dependencies": {
33
+ "dotenv": "^16.3.1",
34
+ "octokit": "^3.1.2"
35
+ },
32
36
  "devDependencies": {
37
+ "@types/jest": "^29.5.8",
33
38
  "@types/node": "^18.15.0",
34
39
  "@typescript-eslint/eslint-plugin": "^5.54.1",
35
40
  "@typescript-eslint/parser": "^5.54.1",
@@ -38,7 +43,9 @@
38
43
  "eslint-config-prettier": "^8.3.0",
39
44
  "eslint-plugin-import": "^2.22.1",
40
45
  "eslint-plugin-prettier": "^4.0.0",
46
+ "jest": "^29.7.0",
41
47
  "prettier": "^2.4.1",
48
+ "ts-jest": "^29.1.1",
42
49
  "ts-node": "^10.2.1",
43
50
  "typescript": "^4.4.3"
44
51
  }