@aneuhold/be-ts-lib 1.0.3 → 1.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/README.md CHANGED
@@ -1,3 +1,5 @@
1
1
  # Personal Backend TypeScript Library
2
2
 
3
+ ![npm](https://img.shields.io/npm/v/%40aneuhold%2Fbe-ts-lib)
4
+
3
5
  This is a library meant to contain any common code between backend TypeScript projects.
package/lib/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './util
7
7
  import ITermService from './services/applications/ITermService';
8
8
  import ConfigService from './services/ConfigService/ConfigService';
9
9
  import Config from './services/ConfigService/ConfigDefinition';
10
- export { CLIService, CurrentEnv, ChromeService, DockerService, OSFileSystemService, sleep, OperatingSystemType, ShellType, TerminalType, ITermService, ConfigService };
11
- export type { Config };
10
+ import TranslationService, { TranslationProject } from './services/TranslationService/TranslationService';
11
+ export { CLIService, CurrentEnv, ChromeService, DockerService, OSFileSystemService, sleep, OperatingSystemType, ShellType, TerminalType, ITermService, ConfigService, TranslationService };
12
+ export type { Config, TranslationProject };
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,MAAM,MAAM,2CAA2C,CAAC;AAG/D,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACd,CAAC;AAGF,YAAY,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,mBAAmB,MAAM,6CAA6C,CAAC;AAC9E,OAAO,UAAU,EAAE,EACjB,mBAAmB,EACnB,SAAS,EACT,YAAY,EACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,MAAM,MAAM,2CAA2C,CAAC;AAC/D,OAAO,kBAAkB,EAAE,EACzB,kBAAkB,EACnB,MAAM,kDAAkD,CAAC;AAG1D,OAAO,EACL,UAAU,EACV,UAAU,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,KAAK,EACL,mBAAmB,EACnB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,kBAAkB,EACnB,CAAC;AAGF,YAAY,EAAE,MAAM,EAAE,kBAAkB,EAAE,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.ConfigService = exports.ITermService = exports.TerminalType = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.OSFileSystemService = exports.DockerService = exports.ChromeService = exports.CurrentEnv = exports.CLIService = void 0;
29
+ exports.TranslationService = exports.ConfigService = exports.ITermService = exports.TerminalType = exports.ShellType = exports.OperatingSystemType = exports.sleep = exports.OSFileSystemService = exports.DockerService = exports.ChromeService = exports.CurrentEnv = exports.CLIService = void 0;
30
30
  const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
31
31
  Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return core_ts_lib_1.sleep; } });
32
32
  const CLIService_1 = __importDefault(require("./services/CLIService"));
@@ -46,3 +46,5 @@ const ITermService_1 = __importDefault(require("./services/applications/ITermSer
46
46
  exports.ITermService = ITermService_1.default;
47
47
  const ConfigService_1 = __importDefault(require("./services/ConfigService/ConfigService"));
48
48
  exports.ConfigService = ConfigService_1.default;
49
+ const TranslationService_1 = __importDefault(require("./services/TranslationService/TranslationService"));
50
+ exports.TranslationService = TranslationService_1.default;
@@ -8,7 +8,6 @@ export type ConfigEnv = 'local' | 'dev' | 'prod';
8
8
  */
9
9
  export default class ConfigService {
10
10
  static env: ConfigEnv | null;
11
- private static gitHub;
12
11
  private static configObject;
13
12
  /**
14
13
  * Returns the configuration object that has been loaded in for the current
@@ -20,21 +19,11 @@ export default class ConfigService {
20
19
  * Loads configuration from the GitHub repository into the ConfigService.
21
20
  */
22
21
  static useConfig(env: ConfigEnv): Promise<void>;
23
- /**
24
- * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
25
- * local environment or .env file.
26
- */
27
- private static getGitHubClient;
28
22
  /**
29
23
  * Inserts the provided configuration into the local environment.
30
24
  *
31
25
  * This may not actually need to happen.
32
26
  */
33
27
  private static insertPropertiesIntoEnv;
34
- /**
35
- * Strips JSON comments from the provided JSON string. Only `//` comments
36
- * are supported at the moment.
37
- */
38
- private static stripJsonComments;
39
28
  }
40
29
  //# sourceMappingURL=ConfigService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["../../../src/services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,O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AAO,CAAC,MAAM,CAAC,uBAAuB;CASvC"}
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const octokit_1 = require("octokit");
4
6
  require("dotenv/config");
5
7
  const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
8
+ const GitHubService_1 = __importDefault(require("../GitHubService"));
6
9
  /**
7
10
  * A class which can be used to load configuration into the ConfigService
8
11
  * from a pre-defined location. This requries that a `.env` file exists in the
@@ -10,7 +13,6 @@ const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
10
13
  */
11
14
  class ConfigService {
12
15
  static env = null;
13
- static gitHub = null;
14
16
  static configObject = null;
15
17
  /**
16
18
  * Returns the configuration object that has been loaded in for the current
@@ -30,19 +32,9 @@ class ConfigService {
30
32
  */
31
33
  static async useConfig(env) {
32
34
  ConfigService.env = env;
33
- if (!ConfigService.gitHub) {
34
- ConfigService.gitHub = ConfigService.getGitHubClient();
35
- }
36
35
  try {
37
- const result = await ConfigService.gitHub.rest.repos.getContent({
38
- mediaType: {
39
- format: 'raw'
40
- },
41
- owner: 'aneuhold',
42
- repo: 'config',
43
- path: `${env}.jsonc`
44
- });
45
- const strippedJson = ConfigService.stripJsonComments(result.data);
36
+ const jsonString = await GitHubService_1.default.getContentFromRepo('config', `${env}.jsonc`);
37
+ const strippedJson = core_ts_lib_1.StringService.stripJsonComments(jsonString);
46
38
  ConfigService.configObject = JSON.parse(strippedJson);
47
39
  }
48
40
  catch (error) {
@@ -50,19 +42,6 @@ class ConfigService {
50
42
  throw error;
51
43
  }
52
44
  }
53
- /**
54
- * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
55
- * local environment or .env file.
56
- */
57
- static getGitHubClient() {
58
- const authToken = process.env.CONFIG_GITHUB_TOKEN;
59
- if (!authToken) {
60
- throw new Error('No CONFIG_GITHUB_TOKEN key found in environment variables.');
61
- }
62
- return new octokit_1.Octokit({
63
- auth: authToken
64
- });
65
- }
66
45
  /**
67
46
  * Inserts the provided configuration into the local environment.
68
47
  *
@@ -78,13 +57,5 @@ class ConfigService {
78
57
  }
79
58
  });
80
59
  }
81
- /**
82
- * Strips JSON comments from the provided JSON string. Only `//` comments
83
- * are supported at the moment.
84
- */
85
- static stripJsonComments = (jsonString) => {
86
- const commentRegex = /\/\/(.*)/g;
87
- return jsonString.replace(commentRegex, '');
88
- };
89
60
  }
90
61
  exports.default = ConfigService;
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const console_1 = require("console");
7
6
  const ConfigService_1 = __importDefault(require("./ConfigService"));
8
7
  describe('ConfigService', () => {
9
8
  describe('useConfig', () => {
@@ -15,7 +14,7 @@ describe('ConfigService', () => {
15
14
  it('should load configuration from GitHub', async () => {
16
15
  const env = 'local';
17
16
  await ConfigService_1.default.useConfig(env);
18
- (0, console_1.assert)(ConfigService_1.default.config.someKey === 'SOME_VALUE');
17
+ expect(ConfigService_1.default.config.someKey).toEqual('SOME_VALUE');
19
18
  });
20
19
  });
21
20
  });
@@ -0,0 +1,15 @@
1
+ import 'dotenv/config';
2
+ export type ConfigEnv = 'local' | 'dev' | 'prod';
3
+ /**
4
+ * A class which can be used to interact with GitHub.
5
+ */
6
+ export default class GitHubService {
7
+ private static gitHub;
8
+ static getContentFromRepo(repoName: string, filePath: string): Promise<string>;
9
+ /**
10
+ * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
11
+ * local environment or .env file.
12
+ */
13
+ private static getGitHubClient;
14
+ }
15
+ //# sourceMappingURL=GitHubService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHubService.d.ts","sourceRoot":"","sources":["../../src/services/GitHubService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAGvB,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwB;WAEhC,kBAAkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAW/B"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const octokit_1 = require("octokit");
4
+ require("dotenv/config");
5
+ const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
6
+ /**
7
+ * A class which can be used to interact with GitHub.
8
+ */
9
+ class GitHubService {
10
+ static gitHub = null;
11
+ static async getContentFromRepo(repoName, filePath) {
12
+ if (!GitHubService.gitHub) {
13
+ GitHubService.gitHub = GitHubService.getGitHubClient();
14
+ }
15
+ try {
16
+ const result = await GitHubService.gitHub.rest.repos.getContent({
17
+ mediaType: {
18
+ format: 'raw'
19
+ },
20
+ owner: 'aneuhold',
21
+ repo: repoName,
22
+ path: filePath
23
+ });
24
+ return result.data;
25
+ }
26
+ catch (error) {
27
+ core_ts_lib_1.Logger.error(`Failed to load ${filePath} from ${repoName}, error: ${error}`);
28
+ throw error;
29
+ }
30
+ }
31
+ /**
32
+ * Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
33
+ * local environment or .env file.
34
+ */
35
+ static getGitHubClient() {
36
+ const authToken = process.env.CONFIG_GITHUB_TOKEN;
37
+ if (!authToken) {
38
+ throw new Error('No CONFIG_GITHUB_TOKEN key found in environment variables.');
39
+ }
40
+ return new octokit_1.Octokit({
41
+ auth: authToken
42
+ });
43
+ }
44
+ }
45
+ exports.default = GitHubService;
@@ -0,0 +1,18 @@
1
+ import 'dotenv/config';
2
+ import { Translations } from '@aneuhold/core-ts-api-lib';
3
+ export declare const TranslationProject: {
4
+ readonly dashboard: "dashboard";
5
+ };
6
+ export type TranslationProject = (typeof TranslationProject)[keyof typeof TranslationProject];
7
+ /**
8
+ * A class which can be used to get translations for personal projects. It is
9
+ * expected that the translations will be loaded in fresh each time this class
10
+ * is called.
11
+ */
12
+ export default class TranslationService {
13
+ /**
14
+ * Gets translations for the provided project.
15
+ */
16
+ static getTranslations(project: TranslationProject): Promise<Translations>;
17
+ }
18
+ //# sourceMappingURL=TranslationService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranslationService.d.ts","sourceRoot":"","sources":["../../../src/services/TranslationService/TranslationService.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,eAAO,MAAM,kBAAkB;;CAErB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC;;OAEG;WACU,eAAe,CAAC,OAAO,EAAE,kBAAkB;CAazD"}
@@ -0,0 +1,34 @@
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.TranslationProject = void 0;
7
+ require("dotenv/config");
8
+ const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
9
+ const GitHubService_1 = __importDefault(require("../GitHubService"));
10
+ exports.TranslationProject = {
11
+ dashboard: 'dashboard'
12
+ };
13
+ /**
14
+ * A class which can be used to get translations for personal projects. It is
15
+ * expected that the translations will be loaded in fresh each time this class
16
+ * is called.
17
+ */
18
+ class TranslationService {
19
+ /**
20
+ * Gets translations for the provided project.
21
+ */
22
+ static async getTranslations(project) {
23
+ try {
24
+ const jsonString = await GitHubService_1.default.getContentFromRepo('translations', `${project}.jsonc`);
25
+ const strippedJson = core_ts_lib_1.StringService.stripJsonComments(jsonString);
26
+ return JSON.parse(strippedJson);
27
+ }
28
+ catch (error) {
29
+ core_ts_lib_1.Logger.error(`Failed to load ${project}.json, error: ${error}`);
30
+ throw error;
31
+ }
32
+ }
33
+ }
34
+ exports.default = TranslationService;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TranslationService.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TranslationService.spec.d.ts","sourceRoot":"","sources":["../../../src/services/TranslationService/TranslationService.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const TranslationService_1 = __importStar(require("./TranslationService"));
27
+ describe('TranslationService', () => {
28
+ describe('getTranslations', () => {
29
+ /**
30
+ * Depends upon a GitHub token being available in the local environment.
31
+ * This will be a local `.env` file with the CONFIG_GITHUB_TOKEN variable
32
+ * set.
33
+ */
34
+ it('should load translations from GitHub', async () => {
35
+ const translations = await TranslationService_1.default.getTranslations(TranslationService_1.TranslationProject.dashboard);
36
+ expect(translations['test-translation'].value).toEqual('something');
37
+ });
38
+ });
39
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/be-ts-lib",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A backend TypeScript library used for common functionality in personal backend projects.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -28,13 +28,15 @@
28
28
  "link:local": "cd lib && yarn link",
29
29
  "unlink:local": "cd lib && yarn unlink",
30
30
  "upgrade:all": "yarn upgrade --latest",
31
+ "upgrade:core": "yarn upgrade --latest --pattern @aneuhold",
31
32
  "test": "jest"
32
33
  },
33
34
  "dependencies": {
34
- "@aneuhold/core-ts-lib": "^1.1.5",
35
+ "@aneuhold/core-ts-api-lib": "^1.0.4",
36
+ "@aneuhold/core-ts-lib": "^1.1.8",
37
+ "dotenv": "^16.3.1",
35
38
  "node-fetch": "^2",
36
- "octokit": "^3.1.2",
37
- "dotenv": "^16.3.1"
39
+ "octokit": "^3.1.2"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@types/jest": "^29.5.8",