@aneuhold/be-ts-lib 1.0.78 → 2.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.
- package/LICENSE +21 -0
- package/README.md +44 -1
- package/lib/index.d.ts +4 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -51
- package/lib/index.js.map +1 -0
- package/lib/index.ts +11 -0
- package/lib/services/ConfigService/ConfigDefinition.d.ts.map +1 -1
- package/lib/services/ConfigService/ConfigDefinition.js +2 -2
- package/lib/services/ConfigService/ConfigDefinition.js.map +1 -0
- package/lib/services/ConfigService/ConfigDefinition.ts +10 -0
- package/lib/services/ConfigService/ConfigService.d.ts +25 -4
- package/lib/services/ConfigService/ConfigService.d.ts.map +1 -1
- package/lib/services/ConfigService/ConfigService.js +33 -17
- package/lib/services/ConfigService/ConfigService.js.map +1 -0
- package/lib/services/ConfigService/ConfigService.spec.ts +17 -0
- package/lib/services/ConfigService/ConfigService.ts +88 -0
- package/lib/services/GitHubService.d.ts +10 -0
- package/lib/services/GitHubService.d.ts.map +1 -1
- package/lib/services/GitHubService.js +17 -9
- package/lib/services/GitHubService.js.map +1 -0
- package/lib/services/GitHubService.ts +63 -0
- package/lib/services/TranslationService/TranslationService.d.ts +7 -1
- package/lib/services/TranslationService/TranslationService.d.ts.map +1 -1
- package/lib/services/TranslationService/TranslationService.js +17 -17
- package/lib/services/TranslationService/TranslationService.js.map +1 -0
- package/lib/services/TranslationService/TranslationService.spec.ts +18 -0
- package/lib/services/TranslationService/TranslationService.ts +40 -0
- package/package.json +37 -28
- package/lib/services/CLIService.d.ts +0 -69
- package/lib/services/CLIService.d.ts.map +0 -1
- package/lib/services/CLIService.js +0 -193
- package/lib/services/ConfigService/ConfigService.spec.d.ts +0 -2
- package/lib/services/ConfigService/ConfigService.spec.d.ts.map +0 -1
- package/lib/services/ConfigService/ConfigService.spec.js +0 -20
- package/lib/services/TranslationService/TranslationService.spec.d.ts +0 -2
- package/lib/services/TranslationService/TranslationService.spec.d.ts.map +0 -1
- package/lib/services/TranslationService/TranslationService.spec.js +0 -39
- package/lib/services/applications/ChromeService.d.ts +0 -20
- package/lib/services/applications/ChromeService.d.ts.map +0 -1
- package/lib/services/applications/ChromeService.js +0 -60
- package/lib/services/applications/DockerService.d.ts +0 -21
- package/lib/services/applications/DockerService.d.ts.map +0 -1
- package/lib/services/applications/DockerService.js +0 -86
- package/lib/services/applications/ITermService.d.ts +0 -8
- package/lib/services/applications/ITermService.d.ts.map +0 -1
- package/lib/services/applications/ITermService.js +0 -45
- package/lib/services/applications/OSFileSystemService.d.ts +0 -19
- package/lib/services/applications/OSFileSystemService.d.ts.map +0 -1
- package/lib/services/applications/OSFileSystemService.js +0 -90
- package/lib/utils/CurrentEnv.d.ts +0 -63
- package/lib/utils/CurrentEnv.d.ts.map +0 -1
- package/lib/utils/CurrentEnv.js +0 -137
- package/lib/utils/OsaScriptBuilder.d.ts +0 -45
- package/lib/utils/OsaScriptBuilder.d.ts.map +0 -1
- package/lib/utils/OsaScriptBuilder.js +0 -53
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [Anton G Neuhold Jr]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# Personal Backend TypeScript Library
|
|
2
2
|
|
|
3
|
-
](https://jsr.io/@aneuhold/be-ts-lib)
|
|
4
|
+
[](https://www.npmjs.com/package/@aneuhold/be-ts-lib)
|
|
4
5
|
|
|
5
6
|
This is a library meant to contain any common code between backend TypeScript projects.
|
|
7
|
+
|
|
8
|
+
## 📦 Installation
|
|
9
|
+
|
|
10
|
+
To add to a repo, follow the instructions below for your environment:
|
|
11
|
+
|
|
12
|
+
### For Node using NPM
|
|
13
|
+
|
|
14
|
+
Run `yarn add @aneuhold/be-ts-lib`
|
|
15
|
+
|
|
16
|
+
### For Node using JSR
|
|
17
|
+
|
|
18
|
+
The below instructions still allow for things like Renovate to work, and normal commands with yarn such as `yarn up`.
|
|
19
|
+
|
|
20
|
+
1. Add the required JSR configuration to a `.yarnrc.yml` file if not there already:
|
|
21
|
+
```yml
|
|
22
|
+
npmScopes:
|
|
23
|
+
jsr:
|
|
24
|
+
npmRegistryServer: 'https://npm.jsr.io'
|
|
25
|
+
```
|
|
26
|
+
1. Add the package with `yarn add @jsr/aneuhold__be-ts-lib`
|
|
27
|
+
|
|
28
|
+
### For Deno
|
|
29
|
+
|
|
30
|
+
Run `deno add jsr:@aneuhold/be-ts-lib`
|
|
31
|
+
|
|
32
|
+
## 🟢 Usage
|
|
33
|
+
|
|
34
|
+
Pull in one of the services and use it like so:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { ConfigService } from '@aneuhold/be-ts-lib';
|
|
38
|
+
// If using Node with JSR
|
|
39
|
+
// import { ConfigService } from '@jsr/aneuhold__be-ts-lib';
|
|
40
|
+
|
|
41
|
+
export default async function getConfig() {
|
|
42
|
+
await ConfigService.useConfig('local');
|
|
43
|
+
const config = ConfigService.config;
|
|
44
|
+
console.log(config);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
[See full documentation on usage at JSR!](https://jsr.io/@aneuhold/be-ts-lib/doc)
|
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import OSFileSystemService from './services/applications/OSFileSystemService';
|
|
6
|
-
import CurrentEnv, { OperatingSystemType, ShellType, TerminalType } from './utils/CurrentEnv';
|
|
7
|
-
import ITermService from './services/applications/ITermService';
|
|
8
|
-
import ConfigService from './services/ConfigService/ConfigService';
|
|
9
|
-
import Config from './services/ConfigService/ConfigDefinition';
|
|
10
|
-
import TranslationService, { TranslationSource } from './services/TranslationService/TranslationService';
|
|
11
|
-
export { CLIService, CurrentEnv, ChromeService, DockerService, OSFileSystemService, sleep, OperatingSystemType, ShellType, TerminalType, ITermService, ConfigService, TranslationService, TranslationSource };
|
|
1
|
+
import Config from './services/ConfigService/ConfigDefinition.js';
|
|
2
|
+
import ConfigService from './services/ConfigService/ConfigService.js';
|
|
3
|
+
import TranslationService, { TranslationSource } from './services/TranslationService/TranslationService.js';
|
|
4
|
+
export { ConfigService, TranslationService, TranslationSource };
|
|
12
5
|
export type { Config };
|
|
13
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,8CAA8C,CAAC;AAClE,OAAO,aAAa,MAAM,2CAA2C,CAAC;AACtE,OAAO,kBAAkB,EAAE,EACzB,iBAAiB,EAClB,MAAM,qDAAqD,CAAC;AAG7D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;AAGhE,YAAY,EAAE,MAAM,EAAE,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,51 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.TranslationSource = 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
|
-
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
31
|
-
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return core_ts_lib_1.sleep; } });
|
|
32
|
-
const CLIService_1 = __importDefault(require("./services/CLIService"));
|
|
33
|
-
exports.CLIService = CLIService_1.default;
|
|
34
|
-
const ChromeService_1 = __importDefault(require("./services/applications/ChromeService"));
|
|
35
|
-
exports.ChromeService = ChromeService_1.default;
|
|
36
|
-
const DockerService_1 = __importDefault(require("./services/applications/DockerService"));
|
|
37
|
-
exports.DockerService = DockerService_1.default;
|
|
38
|
-
const OSFileSystemService_1 = __importDefault(require("./services/applications/OSFileSystemService"));
|
|
39
|
-
exports.OSFileSystemService = OSFileSystemService_1.default;
|
|
40
|
-
const CurrentEnv_1 = __importStar(require("./utils/CurrentEnv"));
|
|
41
|
-
exports.CurrentEnv = CurrentEnv_1.default;
|
|
42
|
-
Object.defineProperty(exports, "OperatingSystemType", { enumerable: true, get: function () { return CurrentEnv_1.OperatingSystemType; } });
|
|
43
|
-
Object.defineProperty(exports, "ShellType", { enumerable: true, get: function () { return CurrentEnv_1.ShellType; } });
|
|
44
|
-
Object.defineProperty(exports, "TerminalType", { enumerable: true, get: function () { return CurrentEnv_1.TerminalType; } });
|
|
45
|
-
const ITermService_1 = __importDefault(require("./services/applications/ITermService"));
|
|
46
|
-
exports.ITermService = ITermService_1.default;
|
|
47
|
-
const ConfigService_1 = __importDefault(require("./services/ConfigService/ConfigService"));
|
|
48
|
-
exports.ConfigService = ConfigService_1.default;
|
|
49
|
-
const TranslationService_1 = __importStar(require("./services/TranslationService/TranslationService"));
|
|
50
|
-
exports.TranslationService = TranslationService_1.default;
|
|
51
|
-
Object.defineProperty(exports, "TranslationSource", { enumerable: true, get: function () { return TranslationService_1.TranslationSource; } });
|
|
1
|
+
import ConfigService from './services/ConfigService/ConfigService.js';
|
|
2
|
+
import TranslationService, { TranslationSource } from './services/TranslationService/TranslationService.js';
|
|
3
|
+
// Export all the functions and classes from this library
|
|
4
|
+
export { ConfigService, TranslationService, TranslationSource };
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,2CAA2C,CAAC;AACtE,OAAO,kBAAkB,EAAE,EACzB,iBAAiB,EAClB,MAAM,qDAAqD,CAAC;AAE7D,yDAAyD;AACzD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from './services/ConfigService/ConfigDefinition.js';
|
|
2
|
+
import ConfigService from './services/ConfigService/ConfigService.js';
|
|
3
|
+
import TranslationService, {
|
|
4
|
+
TranslationSource
|
|
5
|
+
} from './services/TranslationService/TranslationService.js';
|
|
6
|
+
|
|
7
|
+
// Export all the functions and classes from this library
|
|
8
|
+
export { ConfigService, TranslationService, TranslationSource };
|
|
9
|
+
|
|
10
|
+
// Export TypeScript types where needed
|
|
11
|
+
export type { Config };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigDefinition.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"ConfigDefinition.d.ts","sourceRoot":"./src/","sources":["services/ConfigService/ConfigDefinition.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,MAAM;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=ConfigDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigDefinition.js","sourceRoot":"./src/","sources":["services/ConfigService/ConfigDefinition.ts"],"names":[],"mappings":""}
|
|
@@ -1,28 +1,49 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
import Config from './ConfigDefinition';
|
|
2
|
+
import Config from './ConfigDefinition.js';
|
|
3
3
|
export type ConfigEnv = 'local' | 'dev' | 'prod';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Service for managing configuration settings.
|
|
6
|
+
*
|
|
7
|
+
* The {@link ConfigService} class provides methods to load and access configuration
|
|
8
|
+
* settings from a GitHub repository. It ensures that the configuration is loaded
|
|
9
|
+
* and available for the current environment.
|
|
10
|
+
*
|
|
11
|
+
* This requires that a `.env` file exists in the
|
|
7
12
|
* root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
|
|
8
13
|
*/
|
|
9
14
|
export default class ConfigService {
|
|
15
|
+
/**
|
|
16
|
+
* The current environment configuration.
|
|
17
|
+
*/
|
|
10
18
|
static env: ConfigEnv | null;
|
|
11
19
|
private static configObject;
|
|
12
20
|
/**
|
|
13
21
|
* Returns the configuration object that has been loaded in for the current
|
|
14
22
|
* environment.
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} If the {@link ConfigService} has not been initialized.
|
|
25
|
+
* @returns The configuration object for the current environment.
|
|
15
26
|
*/
|
|
16
27
|
static get config(): Config;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the {@link ConfigService} has been initialized.
|
|
30
|
+
*
|
|
31
|
+
* @returns True if the {@link ConfigService} has been initialized, false otherwise.
|
|
32
|
+
*/
|
|
17
33
|
static get isInitialized(): boolean;
|
|
18
34
|
/**
|
|
19
|
-
* Loads configuration from the GitHub repository into the ConfigService.
|
|
35
|
+
* Loads configuration from the GitHub repository into the {@link ConfigService}.
|
|
36
|
+
*
|
|
37
|
+
* @param env - The environment for which to load the configuration.
|
|
38
|
+
* @throws {Error} If the configuration fails to load.
|
|
20
39
|
*/
|
|
21
40
|
static useConfig(env: ConfigEnv): Promise<void>;
|
|
22
41
|
/**
|
|
23
42
|
* Inserts the provided configuration into the local environment.
|
|
24
43
|
*
|
|
25
44
|
* This may not actually need to happen.
|
|
45
|
+
*
|
|
46
|
+
* @param config - The configuration object to insert into the environment.
|
|
26
47
|
*/
|
|
27
48
|
private static insertPropertiesIntoEnv;
|
|
28
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"ConfigService.d.ts","sourceRoot":"./src/","sources":["services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,CAAC;AAGvB,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAQ;IAEpC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAuB;IAElD;;;;;;OAMG;IACH,MAAM,KAAK,MAAM,IAAI,MAAM,CAO1B;IAED;;;;OAIG;IACH,MAAM,KAAK,aAAa,IAAI,OAAO,CAElC;IAED;;;;;OAKG;WACU,SAAS,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAcrD;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;CASvC"}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
require("dotenv/config");
|
|
7
|
-
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
8
|
-
const jsonc_parser_1 = require("jsonc-parser");
|
|
9
|
-
const GitHubService_1 = __importDefault(require("../GitHubService"));
|
|
1
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import GitHubService from '../GitHubService.js';
|
|
10
5
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* Service for managing configuration settings.
|
|
7
|
+
*
|
|
8
|
+
* The {@link ConfigService} class provides methods to load and access configuration
|
|
9
|
+
* settings from a GitHub repository. It ensures that the configuration is loaded
|
|
10
|
+
* and available for the current environment.
|
|
11
|
+
*
|
|
12
|
+
* This requires that a `.env` file exists in the
|
|
13
13
|
* root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
|
|
14
14
|
*/
|
|
15
|
-
class ConfigService {
|
|
15
|
+
export default class ConfigService {
|
|
16
|
+
/**
|
|
17
|
+
* The current environment configuration.
|
|
18
|
+
*/
|
|
16
19
|
static env = null;
|
|
17
20
|
static configObject = null;
|
|
18
21
|
/**
|
|
19
22
|
* Returns the configuration object that has been loaded in for the current
|
|
20
23
|
* environment.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If the {@link ConfigService} has not been initialized.
|
|
26
|
+
* @returns The configuration object for the current environment.
|
|
21
27
|
*/
|
|
22
28
|
static get config() {
|
|
23
29
|
if (!ConfigService.configObject) {
|
|
@@ -25,20 +31,28 @@ class ConfigService {
|
|
|
25
31
|
}
|
|
26
32
|
return ConfigService.configObject;
|
|
27
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if the {@link ConfigService} has been initialized.
|
|
36
|
+
*
|
|
37
|
+
* @returns True if the {@link ConfigService} has been initialized, false otherwise.
|
|
38
|
+
*/
|
|
28
39
|
static get isInitialized() {
|
|
29
40
|
return !!ConfigService.configObject;
|
|
30
41
|
}
|
|
31
42
|
/**
|
|
32
|
-
* Loads configuration from the GitHub repository into the ConfigService.
|
|
43
|
+
* Loads configuration from the GitHub repository into the {@link ConfigService}.
|
|
44
|
+
*
|
|
45
|
+
* @param env - The environment for which to load the configuration.
|
|
46
|
+
* @throws {Error} If the configuration fails to load.
|
|
33
47
|
*/
|
|
34
48
|
static async useConfig(env) {
|
|
35
49
|
ConfigService.env = env;
|
|
36
50
|
try {
|
|
37
|
-
const jsonString = await
|
|
38
|
-
ConfigService.configObject =
|
|
51
|
+
const jsonString = await GitHubService.getContentFromRepo('config', `${env}.jsonc`);
|
|
52
|
+
ConfigService.configObject = parse(jsonString);
|
|
39
53
|
}
|
|
40
54
|
catch (error) {
|
|
41
|
-
|
|
55
|
+
Logger.error(`Failed to load ${env}.json, error: ${error}`);
|
|
42
56
|
throw error;
|
|
43
57
|
}
|
|
44
58
|
}
|
|
@@ -46,6 +60,8 @@ class ConfigService {
|
|
|
46
60
|
* Inserts the provided configuration into the local environment.
|
|
47
61
|
*
|
|
48
62
|
* This may not actually need to happen.
|
|
63
|
+
*
|
|
64
|
+
* @param config - The configuration object to insert into the environment.
|
|
49
65
|
*/
|
|
50
66
|
static insertPropertiesIntoEnv(config) {
|
|
51
67
|
Object.entries(config).forEach(([key, value]) => {
|
|
@@ -58,4 +74,4 @@ class ConfigService {
|
|
|
58
74
|
});
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
|
-
|
|
77
|
+
//# sourceMappingURL=ConfigService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigService.js","sourceRoot":"./src/","sources":["services/ConfigService/ConfigService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAKhD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;OAEG;IACH,MAAM,CAAC,GAAG,GAAqB,IAAI,CAAC;IAE5B,MAAM,CAAC,YAAY,GAAkB,IAAI,CAAC;IAElD;;;;;;OAMG;IACH,MAAM,KAAK,MAAM;QACf,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;QACJ,CAAC;QACD,OAAO,aAAa,CAAC,YAAY,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,MAAM,KAAK,aAAa;QACtB,OAAO,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,GAAc;QACnC,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,kBAAkB,CACvD,QAAQ,EACR,GAAG,GAAG,QAAQ,CACf,CAAC;YACF,aAAa,CAAC,YAAY,GAAG,KAAK,CAAC,UAAU,CAAW,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,kBAAkB,GAAG,iBAAiB,KAAe,EAAE,CAAC,CAAC;YACtE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACK,MAAM,CAAC,uBAAuB,CAAC,MAAc;QACnD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,aAAa,CAAC,uBAAuB,CAAC,KAAe,CAAC,CAAC;YACzD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAe,CAAC;YACrC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import ConfigService from './ConfigService.js';
|
|
3
|
+
|
|
4
|
+
describe('ConfigService', () => {
|
|
5
|
+
describe('useConfig', () => {
|
|
6
|
+
/**
|
|
7
|
+
* Depends upon a GitHub token being available in the local environment.
|
|
8
|
+
* This will be a local `.env` file with the CONFIG_GITHUB_TOKEN variable
|
|
9
|
+
* set.
|
|
10
|
+
*/
|
|
11
|
+
it('should load configuration from GitHub', async () => {
|
|
12
|
+
const env = 'local';
|
|
13
|
+
await ConfigService.useConfig(env);
|
|
14
|
+
expect(ConfigService.config.someKey).toEqual('SOME_VALUE');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import GitHubService from '../GitHubService.js';
|
|
5
|
+
import Config from './ConfigDefinition.js';
|
|
6
|
+
|
|
7
|
+
export type ConfigEnv = 'local' | 'dev' | 'prod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Service for managing configuration settings.
|
|
11
|
+
*
|
|
12
|
+
* The {@link ConfigService} class provides methods to load and access configuration
|
|
13
|
+
* settings from a GitHub repository. It ensures that the configuration is loaded
|
|
14
|
+
* and available for the current environment.
|
|
15
|
+
*
|
|
16
|
+
* This requires that a `.env` file exists in the
|
|
17
|
+
* root of the project / machine with a `CONFIG_GITHUB_TOKEN` variable set.
|
|
18
|
+
*/
|
|
19
|
+
export default class ConfigService {
|
|
20
|
+
/**
|
|
21
|
+
* The current environment configuration.
|
|
22
|
+
*/
|
|
23
|
+
static env: ConfigEnv | null = null;
|
|
24
|
+
|
|
25
|
+
private static configObject: Config | null = null;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns the configuration object that has been loaded in for the current
|
|
29
|
+
* environment.
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} If the {@link ConfigService} has not been initialized.
|
|
32
|
+
* @returns The configuration object for the current environment.
|
|
33
|
+
*/
|
|
34
|
+
static get config(): Config {
|
|
35
|
+
if (!ConfigService.configObject) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'ConfigService has not been initialized yet. Use ConfigService.useConfig() to initialize it.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return ConfigService.configObject;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the {@link ConfigService} has been initialized.
|
|
45
|
+
*
|
|
46
|
+
* @returns True if the {@link ConfigService} has been initialized, false otherwise.
|
|
47
|
+
*/
|
|
48
|
+
static get isInitialized(): boolean {
|
|
49
|
+
return !!ConfigService.configObject;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Loads configuration from the GitHub repository into the {@link ConfigService}.
|
|
54
|
+
*
|
|
55
|
+
* @param env - The environment for which to load the configuration.
|
|
56
|
+
* @throws {Error} If the configuration fails to load.
|
|
57
|
+
*/
|
|
58
|
+
static async useConfig(env: ConfigEnv): Promise<void> {
|
|
59
|
+
ConfigService.env = env;
|
|
60
|
+
try {
|
|
61
|
+
const jsonString = await GitHubService.getContentFromRepo(
|
|
62
|
+
'config',
|
|
63
|
+
`${env}.jsonc`
|
|
64
|
+
);
|
|
65
|
+
ConfigService.configObject = parse(jsonString) as Config;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
Logger.error(`Failed to load ${env}.json, error: ${error as string}`);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Inserts the provided configuration into the local environment.
|
|
74
|
+
*
|
|
75
|
+
* This may not actually need to happen.
|
|
76
|
+
*
|
|
77
|
+
* @param config - The configuration object to insert into the environment.
|
|
78
|
+
*/
|
|
79
|
+
private static insertPropertiesIntoEnv(config: object) {
|
|
80
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
81
|
+
if (typeof value === 'object') {
|
|
82
|
+
ConfigService.insertPropertiesIntoEnv(value as object);
|
|
83
|
+
} else {
|
|
84
|
+
process.env[key] = value as string;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -5,10 +5,20 @@ export type ConfigEnv = 'local' | 'dev' | 'prod';
|
|
|
5
5
|
*/
|
|
6
6
|
export default class GitHubService {
|
|
7
7
|
private static gitHub;
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the content of a file from a specified GitHub repository.
|
|
10
|
+
*
|
|
11
|
+
* @param repoName - The name of the repository.
|
|
12
|
+
* @param filePath - The path to the file within the repository.
|
|
13
|
+
* @returns The content of the file as a string.
|
|
14
|
+
* @throws Will throw an error if the content cannot be retrieved.
|
|
15
|
+
*/
|
|
8
16
|
static getContentFromRepo(repoName: string, filePath: string): Promise<string>;
|
|
9
17
|
/**
|
|
10
18
|
* Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
|
|
11
19
|
* local environment or .env file.
|
|
20
|
+
*
|
|
21
|
+
* @returns A new GitHub client.
|
|
12
22
|
*/
|
|
13
23
|
private static getGitHubClient;
|
|
14
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitHubService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"GitHubService.d.ts","sourceRoot":"./src/","sources":["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;IAE7C;;;;;;;OAOG;WACU,kBAAkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC;IAsBlB;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAW/B"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require("dotenv/config");
|
|
5
|
-
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
1
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import { Octokit } from 'octokit';
|
|
6
4
|
/**
|
|
7
5
|
* A class which can be used to interact with GitHub.
|
|
8
6
|
*/
|
|
9
|
-
class GitHubService {
|
|
7
|
+
export default class GitHubService {
|
|
10
8
|
static gitHub = null;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the content of a file from a specified GitHub repository.
|
|
11
|
+
*
|
|
12
|
+
* @param repoName - The name of the repository.
|
|
13
|
+
* @param filePath - The path to the file within the repository.
|
|
14
|
+
* @returns The content of the file as a string.
|
|
15
|
+
* @throws Will throw an error if the content cannot be retrieved.
|
|
16
|
+
*/
|
|
11
17
|
static async getContentFromRepo(repoName, filePath) {
|
|
12
18
|
if (!GitHubService.gitHub) {
|
|
13
19
|
GitHubService.gitHub = GitHubService.getGitHubClient();
|
|
@@ -24,22 +30,24 @@ class GitHubService {
|
|
|
24
30
|
return result.data;
|
|
25
31
|
}
|
|
26
32
|
catch (error) {
|
|
27
|
-
|
|
33
|
+
Logger.error(`Failed to load ${filePath} from ${repoName}, error: ${error}`);
|
|
28
34
|
throw error;
|
|
29
35
|
}
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
|
|
33
39
|
* local environment or .env file.
|
|
40
|
+
*
|
|
41
|
+
* @returns A new GitHub client.
|
|
34
42
|
*/
|
|
35
43
|
static getGitHubClient() {
|
|
36
44
|
const authToken = process.env.CONFIG_GITHUB_TOKEN;
|
|
37
45
|
if (!authToken) {
|
|
38
46
|
throw new Error('No CONFIG_GITHUB_TOKEN key found in environment variables.');
|
|
39
47
|
}
|
|
40
|
-
return new
|
|
48
|
+
return new Octokit({
|
|
41
49
|
auth: authToken
|
|
42
50
|
});
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
|
-
|
|
53
|
+
//# sourceMappingURL=GitHubService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GitHubService.js","sourceRoot":"./src/","sources":["services/GitHubService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIlC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IACxB,MAAM,CAAC,MAAM,GAAmB,IAAI,CAAC;IAE7C;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAC7B,QAAgB,EAChB,QAAgB;QAEhB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YAC1B,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,eAAe,EAAE,CAAC;QACzD,CAAC;QACD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;gBAC9D,SAAS,EAAE;oBACT,MAAM,EAAE,KAAK;iBACd;gBACD,KAAK,EAAE,UAAU;gBACjB,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,IAAyB,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CACV,kBAAkB,QAAQ,SAAS,QAAQ,YAAY,KAAe,EAAE,CACzE,CAAC;YACF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,eAAe;QAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QAClD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,OAAO,CAAC;YACjB,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import { Octokit } from 'octokit';
|
|
4
|
+
|
|
5
|
+
export type ConfigEnv = 'local' | 'dev' | 'prod';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A class which can be used to interact with GitHub.
|
|
9
|
+
*/
|
|
10
|
+
export default class GitHubService {
|
|
11
|
+
private static gitHub: Octokit | null = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the content of a file from a specified GitHub repository.
|
|
15
|
+
*
|
|
16
|
+
* @param repoName - The name of the repository.
|
|
17
|
+
* @param filePath - The path to the file within the repository.
|
|
18
|
+
* @returns The content of the file as a string.
|
|
19
|
+
* @throws Will throw an error if the content cannot be retrieved.
|
|
20
|
+
*/
|
|
21
|
+
static async getContentFromRepo(
|
|
22
|
+
repoName: string,
|
|
23
|
+
filePath: string
|
|
24
|
+
): Promise<string> {
|
|
25
|
+
if (!GitHubService.gitHub) {
|
|
26
|
+
GitHubService.gitHub = GitHubService.getGitHubClient();
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const result = await GitHubService.gitHub.rest.repos.getContent({
|
|
30
|
+
mediaType: {
|
|
31
|
+
format: 'raw'
|
|
32
|
+
},
|
|
33
|
+
owner: 'aneuhold',
|
|
34
|
+
repo: repoName,
|
|
35
|
+
path: filePath
|
|
36
|
+
});
|
|
37
|
+
return result.data as unknown as string;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
Logger.error(
|
|
40
|
+
`Failed to load ${filePath} from ${repoName}, error: ${error as string}`
|
|
41
|
+
);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new GitHub client using `CONFIG_GITHUB_TOKEN` from the
|
|
48
|
+
* local environment or .env file.
|
|
49
|
+
*
|
|
50
|
+
* @returns A new GitHub client.
|
|
51
|
+
*/
|
|
52
|
+
private static getGitHubClient(): Octokit {
|
|
53
|
+
const authToken = process.env.CONFIG_GITHUB_TOKEN;
|
|
54
|
+
if (!authToken) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'No CONFIG_GITHUB_TOKEN key found in environment variables.'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return new Octokit({
|
|
60
|
+
auth: authToken
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
1
|
import { Translations } from '@aneuhold/core-ts-api-lib';
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
/**
|
|
4
|
+
* An enum which defines the sources of translations which can be loaded.
|
|
5
|
+
*/
|
|
3
6
|
export declare enum TranslationSource {
|
|
4
7
|
dashboard = "dashboard"
|
|
5
8
|
}
|
|
@@ -11,6 +14,9 @@ export declare enum TranslationSource {
|
|
|
11
14
|
export default class TranslationService {
|
|
12
15
|
/**
|
|
13
16
|
* Gets translations for the provided source.
|
|
17
|
+
*
|
|
18
|
+
* @param source - The source of the translations.
|
|
19
|
+
* @returns The translations for the provided source.
|
|
14
20
|
*/
|
|
15
21
|
static getTranslations(source: TranslationSource): Promise<Translations>;
|
|
16
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TranslationService.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"TranslationService.d.ts","sourceRoot":"./src/","sources":["services/TranslationService/TranslationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,eAAe,CAAC;AAIvB;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,SAAS,cAAc;CACxB;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACrC;;;;;OAKG;WACU,eAAe,CAC1B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,YAAY,CAAC;CAYzB"}
|