@bsb/base 9.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 (182) hide show
  1. package/LICENSE +665 -0
  2. package/LICENSE.commercial +32 -0
  3. package/README.md +263 -0
  4. package/bsb-plugin.json +62 -0
  5. package/lib/base/BSBConfig.d.ts +130 -0
  6. package/lib/base/BSBConfig.js +95 -0
  7. package/lib/base/BSBConfig.js.map +1 -0
  8. package/lib/base/BSBEvents.d.ts +207 -0
  9. package/lib/base/BSBEvents.js +101 -0
  10. package/lib/base/BSBEvents.js.map +1 -0
  11. package/lib/base/BSBObservable.d.ts +178 -0
  12. package/lib/base/BSBObservable.js +91 -0
  13. package/lib/base/BSBObservable.js.map +1 -0
  14. package/lib/base/BSBService.d.ts +277 -0
  15. package/lib/base/BSBService.js +366 -0
  16. package/lib/base/BSBService.js.map +1 -0
  17. package/lib/base/BSBServiceClient.d.ts +135 -0
  18. package/lib/base/BSBServiceClient.js +130 -0
  19. package/lib/base/BSBServiceClient.js.map +1 -0
  20. package/lib/base/EventValidator.d.ts +137 -0
  21. package/lib/base/EventValidator.js +210 -0
  22. package/lib/base/EventValidator.js.map +1 -0
  23. package/lib/base/ObservableBackend.d.ts +281 -0
  24. package/lib/base/ObservableBackend.js +515 -0
  25. package/lib/base/ObservableBackend.js.map +1 -0
  26. package/lib/base/PluginConfig.d.ts +196 -0
  27. package/lib/base/PluginConfig.js +96 -0
  28. package/lib/base/PluginConfig.js.map +1 -0
  29. package/lib/base/PluginEvents.d.ts +140 -0
  30. package/lib/base/PluginEvents.js +268 -0
  31. package/lib/base/PluginEvents.js.map +1 -0
  32. package/lib/base/PluginObservable.d.ts +196 -0
  33. package/lib/base/PluginObservable.js +250 -0
  34. package/lib/base/PluginObservable.js.map +1 -0
  35. package/lib/base/ResourceContext.d.ts +70 -0
  36. package/lib/base/ResourceContext.js +54 -0
  37. package/lib/base/ResourceContext.js.map +1 -0
  38. package/lib/base/base.d.ts +264 -0
  39. package/lib/base/base.js +182 -0
  40. package/lib/base/base.js.map +1 -0
  41. package/lib/base/errorMessages.d.ts +56 -0
  42. package/lib/base/errorMessages.js +70 -0
  43. package/lib/base/errorMessages.js.map +1 -0
  44. package/lib/base/factory.d.ts +58 -0
  45. package/lib/base/factory.js +167 -0
  46. package/lib/base/factory.js.map +1 -0
  47. package/lib/base/functions.d.ts +117 -0
  48. package/lib/base/functions.js +152 -0
  49. package/lib/base/functions.js.map +1 -0
  50. package/lib/base/index.d.ts +44 -0
  51. package/lib/base/index.js +64 -0
  52. package/lib/base/index.js.map +1 -0
  53. package/lib/base/logFormatter.d.ts +50 -0
  54. package/lib/base/logFormatter.js +105 -0
  55. package/lib/base/logFormatter.js.map +1 -0
  56. package/lib/base/tools.d.ts +316 -0
  57. package/lib/base/tools.js +666 -0
  58. package/lib/base/tools.js.map +1 -0
  59. package/lib/cli.d.ts +28 -0
  60. package/lib/cli.js +254 -0
  61. package/lib/cli.js.map +1 -0
  62. package/lib/dev.d.ts +27 -0
  63. package/lib/dev.js +200 -0
  64. package/lib/dev.js.map +1 -0
  65. package/lib/index.d.ts +32 -0
  66. package/lib/index.js +49 -0
  67. package/lib/index.js.map +1 -0
  68. package/lib/interfaces/events.d.ts +67 -0
  69. package/lib/interfaces/events.js +44 -0
  70. package/lib/interfaces/events.js.map +1 -0
  71. package/lib/interfaces/index.d.ts +38 -0
  72. package/lib/interfaces/index.js +59 -0
  73. package/lib/interfaces/index.js.map +1 -0
  74. package/lib/interfaces/logging.d.ts +106 -0
  75. package/lib/interfaces/logging.js +39 -0
  76. package/lib/interfaces/logging.js.map +1 -0
  77. package/lib/interfaces/metrics.d.ts +365 -0
  78. package/lib/interfaces/metrics.js +46 -0
  79. package/lib/interfaces/metrics.js.map +1 -0
  80. package/lib/interfaces/observable-types.d.ts +63 -0
  81. package/lib/interfaces/observable-types.js +49 -0
  82. package/lib/interfaces/observable-types.js.map +1 -0
  83. package/lib/interfaces/observable.d.ts +297 -0
  84. package/lib/interfaces/observable.js +29 -0
  85. package/lib/interfaces/observable.js.map +1 -0
  86. package/lib/interfaces/options.d.ts +164 -0
  87. package/lib/interfaces/options.js +56 -0
  88. package/lib/interfaces/options.js.map +1 -0
  89. package/lib/interfaces/plugins.d.ts +143 -0
  90. package/lib/interfaces/plugins.js +45 -0
  91. package/lib/interfaces/plugins.js.map +1 -0
  92. package/lib/interfaces/result.d.ts +129 -0
  93. package/lib/interfaces/result.js +162 -0
  94. package/lib/interfaces/result.js.map +1 -0
  95. package/lib/interfaces/schema-events.d.ts +378 -0
  96. package/lib/interfaces/schema-events.js +247 -0
  97. package/lib/interfaces/schema-events.js.map +1 -0
  98. package/lib/interfaces/schema-types.d.ts +407 -0
  99. package/lib/interfaces/schema-types.js +581 -0
  100. package/lib/interfaces/schema-types.js.map +1 -0
  101. package/lib/interfaces/service.d.ts +48 -0
  102. package/lib/interfaces/service.js +29 -0
  103. package/lib/interfaces/service.js.map +1 -0
  104. package/lib/interfaces/tools.d.ts +65 -0
  105. package/lib/interfaces/tools.js +50 -0
  106. package/lib/interfaces/tools.js.map +1 -0
  107. package/lib/plugins/config-default/index.d.ts +59 -0
  108. package/lib/plugins/config-default/index.js +197 -0
  109. package/lib/plugins/config-default/index.js.map +1 -0
  110. package/lib/plugins/config-default/interfaces.d.ts +92 -0
  111. package/lib/plugins/config-default/interfaces.js +36 -0
  112. package/lib/plugins/config-default/interfaces.js.map +1 -0
  113. package/lib/plugins/events-default/events/broadcast.d.ts +36 -0
  114. package/lib/plugins/events-default/events/broadcast.js +85 -0
  115. package/lib/plugins/events-default/events/broadcast.js.map +1 -0
  116. package/lib/plugins/events-default/events/emit.d.ts +38 -0
  117. package/lib/plugins/events-default/events/emit.js +104 -0
  118. package/lib/plugins/events-default/events/emit.js.map +1 -0
  119. package/lib/plugins/events-default/events/emitAndReturn.d.ts +36 -0
  120. package/lib/plugins/events-default/events/emitAndReturn.js +100 -0
  121. package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -0
  122. package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +38 -0
  123. package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +134 -0
  124. package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -0
  125. package/lib/plugins/events-default/events/index.d.ts +30 -0
  126. package/lib/plugins/events-default/events/index.js +38 -0
  127. package/lib/plugins/events-default/events/index.js.map +1 -0
  128. package/lib/plugins/events-default/index.d.ts +57 -0
  129. package/lib/plugins/events-default/index.js +86 -0
  130. package/lib/plugins/events-default/index.js.map +1 -0
  131. package/lib/plugins/observable-default/index.d.ts +43 -0
  132. package/lib/plugins/observable-default/index.js +151 -0
  133. package/lib/plugins/observable-default/index.js.map +1 -0
  134. package/lib/schemas/config-default.json +34 -0
  135. package/lib/schemas/config-default.plugin.json +36 -0
  136. package/lib/schemas/events-default.json +18 -0
  137. package/lib/schemas/events-default.plugin.json +17 -0
  138. package/lib/schemas/observable-default.json +33 -0
  139. package/lib/schemas/observable-default.plugin.json +24 -0
  140. package/lib/scripts/bsb-client-cli.d.ts +21 -0
  141. package/lib/scripts/bsb-client-cli.js +701 -0
  142. package/lib/scripts/bsb-client-cli.js.map +1 -0
  143. package/lib/scripts/bsb-plugin-cli.d.ts +15 -0
  144. package/lib/scripts/bsb-plugin-cli.js +547 -0
  145. package/lib/scripts/bsb-plugin-cli.js.map +1 -0
  146. package/lib/scripts/export-schemas.d.ts +17 -0
  147. package/lib/scripts/export-schemas.js +205 -0
  148. package/lib/scripts/export-schemas.js.map +1 -0
  149. package/lib/scripts/extract-schemas-from-source.d.ts +23 -0
  150. package/lib/scripts/extract-schemas-from-source.js +604 -0
  151. package/lib/scripts/extract-schemas-from-source.js.map +1 -0
  152. package/lib/scripts/generate-client-types.d.ts +22 -0
  153. package/lib/scripts/generate-client-types.js +537 -0
  154. package/lib/scripts/generate-client-types.js.map +1 -0
  155. package/lib/scripts/generate-plugin-json.d.ts +17 -0
  156. package/lib/scripts/generate-plugin-json.js +219 -0
  157. package/lib/scripts/generate-plugin-json.js.map +1 -0
  158. package/lib/serviceBase/config.d.ts +83 -0
  159. package/lib/serviceBase/config.js +236 -0
  160. package/lib/serviceBase/config.js.map +1 -0
  161. package/lib/serviceBase/events.d.ts +91 -0
  162. package/lib/serviceBase/events.js +519 -0
  163. package/lib/serviceBase/events.js.map +1 -0
  164. package/lib/serviceBase/index.d.ts +33 -0
  165. package/lib/serviceBase/index.js +50 -0
  166. package/lib/serviceBase/index.js.map +1 -0
  167. package/lib/serviceBase/observable.d.ts +249 -0
  168. package/lib/serviceBase/observable.js +551 -0
  169. package/lib/serviceBase/observable.js.map +1 -0
  170. package/lib/serviceBase/plugins.d.ts +48 -0
  171. package/lib/serviceBase/plugins.js +184 -0
  172. package/lib/serviceBase/plugins.js.map +1 -0
  173. package/lib/serviceBase/serviceBase.d.ts +228 -0
  174. package/lib/serviceBase/serviceBase.js +420 -0
  175. package/lib/serviceBase/serviceBase.js.map +1 -0
  176. package/lib/serviceBase/services.d.ts +63 -0
  177. package/lib/serviceBase/services.js +346 -0
  178. package/lib/serviceBase/services.js.map +1 -0
  179. package/lib/tests.d.ts +27 -0
  180. package/lib/tests.js +44 -0
  181. package/lib/tests.js.map +1 -0
  182. package/package.json +91 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export interface MergeObjectsKey {
5
+ refPropName: string;
6
+ refPropKey: string;
7
+ }
8
+ /**
9
+ * @hidden
10
+ */
11
+ export interface SimpleStatu<T = any> {
12
+ status: boolean;
13
+ value?: T;
14
+ }
15
+ /**
16
+ * @hidden
17
+ */
18
+ export type DynamicallyReferencedType = Record<string, Function>;
19
+ /**
20
+ * @hidden
21
+ */
22
+ export type DynamicallyReferencedMethodBase = DynamicallyReferencedType;
23
+ /**
24
+ * @hidden
25
+ */
26
+ export type DynamicallyReferencedMethodType<T> = T & DynamicallyReferencedMethodBase;
27
+ /**
28
+ * @hidden
29
+ */
30
+ export type ParamsFromString<T extends string> = T extends `${infer Pre}{${infer Param}}${infer Post}` ? // A param exists in the string, so return it as a union type that
31
+ Param | ParamsFromString<`${Pre}${Post}`> : never;
32
+ /**
33
+ * @hidden
34
+ */
35
+ export type DynamicallyReferencedMethod<Interface extends DynamicallyReferencedType, Method extends string, ArgsReference extends boolean = true> = ArgsReference extends true ? Interface[Method] extends (...a: infer Arguments) => infer Return ? [
36
+ method: Method,
37
+ ...a: Arguments
38
+ ] : [
39
+ method: Method,
40
+ noMatchingMethod: never
41
+ ] : Interface[Method] extends (...a: infer Arguments) => infer Return ? Return : never;
42
+ /**
43
+ * @hidden
44
+ */
45
+ export declare enum CleanStringStrength {
46
+ soft = "soft",
47
+ hard = "hard",
48
+ exhard = "exhard",
49
+ url = "url",
50
+ ip = "ip",
51
+ email = "email",
52
+ custom = "custom"
53
+ }
54
+ /**
55
+ * @hidden
56
+ */
57
+ export declare function generateAppIdHash(appId: string): string;
58
+ /**
59
+ * @hidden
60
+ */
61
+ export declare function generateTimeBasedId(byteLength: number, appId: string): string;
62
+ /**
63
+ * @hidden
64
+ */
65
+ export declare const DEBUG_MODE: boolean;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ // THIS FILE IS SUBJECT TO COPYRIGHT FROM THE SOURCE - https://github.com/BetterCorp/Node-Tools.git
3
+ // @bettercorp/tools
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.DEBUG_MODE = exports.CleanStringStrength = void 0;
6
+ exports.generateAppIdHash = generateAppIdHash;
7
+ exports.generateTimeBasedId = generateTimeBasedId;
8
+ const node_crypto_1 = require("node:crypto");
9
+ /**
10
+ * @hidden
11
+ */
12
+ var CleanStringStrength;
13
+ (function (CleanStringStrength) {
14
+ CleanStringStrength["soft"] = "soft";
15
+ CleanStringStrength["hard"] = "hard";
16
+ CleanStringStrength["exhard"] = "exhard";
17
+ CleanStringStrength["url"] = "url";
18
+ CleanStringStrength["ip"] = "ip";
19
+ CleanStringStrength["email"] = "email";
20
+ CleanStringStrength["custom"] = "custom";
21
+ })(CleanStringStrength || (exports.CleanStringStrength = CleanStringStrength = {}));
22
+ /**
23
+ * @hidden
24
+ */
25
+ function generateAppIdHash(appId) {
26
+ const hash = (0, node_crypto_1.createHash)('sha256').update(appId).digest('hex');
27
+ return hash.slice(0, 2); // Take the first 2 characters of the hash
28
+ }
29
+ /**
30
+ * @hidden
31
+ */
32
+ function generateTimeBasedId(byteLength, appId) {
33
+ // Get current timestamp in milliseconds
34
+ const timestamp = BigInt(Date.now());
35
+ // Convert timestamp to hexadecimal and pad to 10 characters (40 bits)
36
+ const timeHex = timestamp.toString(16).padStart(10, '0');
37
+ // Generate 2-character hash from appId
38
+ const appIdHash = generateAppIdHash(appId);
39
+ // Calculate how many bytes we need to fill with random data
40
+ const randomBytesLength = byteLength - 6; // 5 bytes for timestamp, 1 byte for appId hash
41
+ // Generate random bytes
42
+ const randomHex = (0, node_crypto_1.randomBytes)(randomBytesLength).toString('hex');
43
+ // Combine timestamp, appId hash, and random data
44
+ return timeHex + appIdHash + randomHex;
45
+ }
46
+ /**
47
+ * @hidden
48
+ */
49
+ exports.DEBUG_MODE = process.env.NODE_ENV !== "production";
50
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/interfaces/tools.ts"],"names":[],"mappings":";AAAA,oGAAoG;AACpG,oBAAoB;;;AAoFpB,8CAGC;AAKD,kDAaC;AAvGD,6CAAoD;AAkEpD;;GAEG;AACH,IAAY,mBAQX;AARD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,oCAAa,CAAA;IACb,wCAAiB,CAAA;IACjB,kCAAW,CAAA;IACX,gCAAS,CAAA;IACT,sCAAe,CAAA;IACf,wCAAiB,CAAA;AACnB,CAAC,EARW,mBAAmB,mCAAnB,mBAAmB,QAQ9B;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,0CAA0C;AACrE,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,UAAkB,EAAE,KAAa;IACnE,wCAAwC;IACxC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACrC,sEAAsE;IACtE,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACzD,uCAAuC;IACvC,MAAM,SAAS,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC3C,4DAA4D;IAC5D,MAAM,iBAAiB,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC,+CAA+C;IACzF,wBAAwB;IACxB,MAAM,SAAS,GAAG,IAAA,yBAAW,EAAC,iBAAiB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjE,iDAAiD;IACjD,OAAO,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AACzC,CAAC;AAED;;GAEG;AACU,QAAA,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * BSB (Better-Service-Base) is an event-bus based microservice framework.
3
+ * Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published
7
+ * by the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * Alternatively, you may obtain a commercial license for this program.
11
+ * The commercial license allows you to use the Program in a closed-source manner,
12
+ * including the right to create derivative works that are not subject to the terms
13
+ * of the AGPL.
14
+ *
15
+ * To obtain a commercial license, please contact the copyright holders at
16
+ * https://www.bettercorp.dev. The terms and conditions of the commercial license
17
+ * will be provided upon request.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU Affero General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU Affero General Public License
25
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
26
+ */
27
+ import { EventsConfig, ObservableConfig, PluginDefinition, PluginType, Observable } from "../../index";
28
+ import { BSBConfig, BSBConfigConstructor } from "../../base/BSBConfig";
29
+ import { z } from "zod";
30
+ export declare const Config: import("../../index").BSBPluginConfigClass<z.ZodObject<{
31
+ BSB_PROFILE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
32
+ BSB_CONFIG_FILE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
33
+ }, z.core.$strip>>;
34
+ export declare class Plugin extends BSBConfig<InstanceType<typeof Config>> {
35
+ static Config: import("../../index").BSBPluginConfigClass<z.ZodObject<{
36
+ BSB_PROFILE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
37
+ BSB_CONFIG_FILE: z.ZodDefault<z.ZodOptional<z.ZodString>>;
38
+ }, z.core.$strip>>;
39
+ getServicePluginDefinition(obs: Observable, pluginName: string): Promise<{
40
+ name: string;
41
+ enabled: boolean;
42
+ }>;
43
+ getObservablePlugins(): Promise<Record<string, ObservableConfig>>;
44
+ getEventsPlugins(): Promise<Record<string, EventsConfig>>;
45
+ getServicePlugins(): Promise<Record<string, PluginDefinition>>;
46
+ getPluginConfig(obs: Observable, pluginType: PluginType, plugin: string): Promise<object | null>;
47
+ dispose(): void;
48
+ private _appConfig;
49
+ private _secConfigFilePath;
50
+ private _deploymentProfile;
51
+ constructor(config: BSBConfigConstructor<InstanceType<typeof Config>>);
52
+ init(obs: Observable): void;
53
+ getPlugins(): Promise<{
54
+ npmPackage: string | undefined | null;
55
+ plugin: string;
56
+ name: string;
57
+ enabled: boolean;
58
+ }[]>;
59
+ }
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * BSB (Better-Service-Base) is an event-bus based microservice framework.
4
+ * Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published
8
+ * by the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * Alternatively, you may obtain a commercial license for this program.
12
+ * The commercial license allows you to use the Program in a closed-source manner,
13
+ * including the right to create derivative works that are not subject to the terms
14
+ * of the AGPL.
15
+ *
16
+ * To obtain a commercial license, please contact the copyright holders at
17
+ * https://www.bettercorp.dev. The terms and conditions of the commercial license
18
+ * will be provided upon request.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU Affero General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU Affero General Public License
26
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Plugin = exports.Config = void 0;
30
+ const path = require("node:path");
31
+ const fs = require("node:fs");
32
+ const yaml_1 = require("yaml");
33
+ const index_1 = require("../../index");
34
+ const BSBConfig_1 = require("../../base/BSBConfig");
35
+ const PluginConfig_1 = require("../../base/PluginConfig");
36
+ const zod_1 = require("zod");
37
+ const ConfigSchema = zod_1.z.object({
38
+ BSB_PROFILE: zod_1.z.string().optional().default("default"),
39
+ BSB_CONFIG_FILE: zod_1.z.string().optional().default("./sec-config.yaml"),
40
+ });
41
+ exports.Config = (0, PluginConfig_1.createConfigSchema)({
42
+ name: "config-default",
43
+ description: "Default configuration plugin for profile and plugin resolution",
44
+ version: "1.0.0",
45
+ image: "../docs/public/assets/images/bsb-logo.png",
46
+ tags: ["core", "config", "default"],
47
+ documentation: ["./docs/core-plugins/config-default.md"],
48
+ }, ConfigSchema);
49
+ class Plugin extends BSBConfig_1.BSBConfig {
50
+ static Config = exports.Config;
51
+ async getServicePluginDefinition(obs, pluginName) {
52
+ const keydPlugins = Object.keys(this._appConfig[this._deploymentProfile].services ?? {});
53
+ const keydWithMap = keydPlugins.map((x) => {
54
+ return {
55
+ mappedName: x,
56
+ ...this._appConfig[this._deploymentProfile].services[x],
57
+ };
58
+ });
59
+ let plugin = keydWithMap.find((x) => {
60
+ return x.plugin === pluginName && x.enabled === true;
61
+ });
62
+ if (plugin !== undefined) {
63
+ return {
64
+ name: plugin.mappedName,
65
+ enabled: plugin.enabled,
66
+ };
67
+ }
68
+ plugin = keydWithMap.find((x) => {
69
+ return x.plugin === pluginName;
70
+ });
71
+ if (plugin !== undefined) {
72
+ return {
73
+ name: plugin.mappedName,
74
+ enabled: plugin.enabled,
75
+ };
76
+ }
77
+ throw new index_1.BSBError(obs.trace, "Cannot find the plugin {plugin} in the config", {
78
+ plugin: pluginName,
79
+ });
80
+ }
81
+ async getObservablePlugins() {
82
+ const plugins = Object.keys(this._appConfig[this._deploymentProfile].observable ?? {})
83
+ .filter((x) => {
84
+ return (this._appConfig[this._deploymentProfile].observable[x].enabled === true);
85
+ });
86
+ return plugins.reduce((acc, x) => {
87
+ acc[x] = {
88
+ version: this._appConfig[this._deploymentProfile].observable[x].version,
89
+ plugin: this._appConfig[this._deploymentProfile].observable[x].plugin,
90
+ package: this._appConfig[this._deploymentProfile].observable[x].package,
91
+ enabled: this._appConfig[this._deploymentProfile].observable[x].enabled,
92
+ filter: this._appConfig[this._deploymentProfile].observable[x].filter,
93
+ };
94
+ return acc;
95
+ }, {});
96
+ }
97
+ async getEventsPlugins() {
98
+ const plugins = Object.keys(this._appConfig[this._deploymentProfile].events ?? {})
99
+ .filter((x) => {
100
+ return (this._appConfig[this._deploymentProfile].events[x].enabled === true);
101
+ });
102
+ return plugins.reduce((acc, x) => {
103
+ acc[x] = {
104
+ //name: this._appConfig[this._deploymentProfile].events[x].name,
105
+ version: this._appConfig[this._deploymentProfile].events[x].version,
106
+ plugin: this._appConfig[this._deploymentProfile].events[x].plugin,
107
+ package: this._appConfig[this._deploymentProfile].events[x].package,
108
+ enabled: this._appConfig[this._deploymentProfile].events[x].enabled,
109
+ filter: this._appConfig[this._deploymentProfile].events[x].filter,
110
+ };
111
+ return acc;
112
+ }, {});
113
+ }
114
+ async getServicePlugins() {
115
+ const plugins = Object.keys(this._appConfig[this._deploymentProfile].services ?? {})
116
+ .filter((x) => {
117
+ return (this._appConfig[this._deploymentProfile].services[x].enabled === true);
118
+ });
119
+ return plugins.reduce((acc, x) => {
120
+ acc[x] = {
121
+ //name: this._appConfig[this._deploymentProfile].services[x].name,
122
+ version: this._appConfig[this._deploymentProfile].services[x].version,
123
+ plugin: this._appConfig[this._deploymentProfile].services[x].plugin,
124
+ package: this._appConfig[this._deploymentProfile].services[x].package,
125
+ enabled: this._appConfig[this._deploymentProfile].services[x].enabled,
126
+ };
127
+ return acc;
128
+ }, {});
129
+ }
130
+ async getPluginConfig(obs, pluginType, plugin) {
131
+ if (pluginType === index_1.PluginTypes.config) {
132
+ return null;
133
+ }
134
+ let configKey = "services";
135
+ if (pluginType === index_1.PluginTypes.events) {
136
+ configKey = "events";
137
+ }
138
+ if (pluginType === index_1.PluginTypes.observable) {
139
+ configKey = "observable";
140
+ }
141
+ return (this._appConfig[this._deploymentProfile][configKey][plugin].config ?? null);
142
+ }
143
+ dispose() {
144
+ this._appConfig = undefined;
145
+ }
146
+ _appConfig;
147
+ _secConfigFilePath;
148
+ _deploymentProfile = "default";
149
+ constructor(config) {
150
+ super(config);
151
+ this._secConfigFilePath = path.join(this.cwd, this.config.BSB_CONFIG_FILE);
152
+ }
153
+ init(obs) {
154
+ this._deploymentProfile = this.config.BSB_PROFILE;
155
+ this._secConfigFilePath = this.config.BSB_CONFIG_FILE;
156
+ this._appConfig = {
157
+ default: {
158
+ observable: {},
159
+ events: {},
160
+ services: {},
161
+ },
162
+ };
163
+ if (fs.existsSync(this._secConfigFilePath)) {
164
+ this._appConfig =
165
+ (0, yaml_1.parse)(fs.readFileSync(this._secConfigFilePath, "utf8")
166
+ .toString()) ??
167
+ this._appConfig;
168
+ }
169
+ else {
170
+ throw new index_1.BSBError(obs.trace, "Cannot find config file at {filepath}", {
171
+ filepath: this._secConfigFilePath,
172
+ });
173
+ }
174
+ if (index_1.Tools.isNullOrUndefined(this._appConfig[this._deploymentProfile])) {
175
+ throw new index_1.BSBError(obs.trace, "unknown deployment profile ({deploymentProfile}), please create it first.", {
176
+ deploymentProfile: this._deploymentProfile,
177
+ });
178
+ }
179
+ obs.log.debug("Config ready, using profile: {profile}", {
180
+ profile: this._deploymentProfile,
181
+ });
182
+ }
183
+ async getPlugins() {
184
+ return Object.keys(this._appConfig[this._deploymentProfile].services)
185
+ .map((x) => {
186
+ return {
187
+ npmPackage: this._appConfig[this._deploymentProfile].services[x].package,
188
+ plugin: this._appConfig[this._deploymentProfile].services[x].plugin,
189
+ name: x,
190
+ enabled: this._appConfig[this._deploymentProfile].services[x].enabled ===
191
+ true,
192
+ };
193
+ });
194
+ }
195
+ }
196
+ exports.Plugin = Plugin;
197
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/config-default/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,kCAAkC;AAClC,8BAA8B;AAC9B,+BAA6B;AAC7B,uCAQqB;AACrB,oDAAuE;AACvE,0DAA6D;AAC7D,6BAAwB;AAGxB,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;IACrD,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ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 /**
2
+ * BSB (Better-Service-Base) is an event-bus based microservice framework.
3
+ * Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published
7
+ * by the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * Alternatively, you may obtain a commercial license for this program.
11
+ * The commercial license allows you to use the Program in a closed-source manner,
12
+ * including the right to create derivative works that are not subject to the terms
13
+ * of the AGPL.
14
+ *
15
+ * To obtain a commercial license, please contact the copyright holders at
16
+ * https://www.bettercorp.dev. The terms and conditions of the commercial license
17
+ * will be provided upon request.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU Affero General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU Affero General Public License
25
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
26
+ */
27
+ import { ObservableConfig, EventsConfig, PluginDefinition as ServiceConfig } from "../../index";
28
+ export interface DeploymentProfile {
29
+ /**
30
+ * @name NPM Package name
31
+ * @description The NPM package that holds the plugin
32
+ * @example @bettercorp/service-base-plugin-web-server
33
+ * @example @bettercorp/service-base-plugin-graphql
34
+ */
35
+ package: string;
36
+ /**
37
+ * @name NPM Package version
38
+ * @description The NPM package version that holds the plugin
39
+ * @example 1.0.0
40
+ * @example 1.0.1
41
+ */
42
+ /**
43
+ * @name Plugin name
44
+ * @description The name of the plugin
45
+ * @example service-fastify
46
+ * @example service-graphql
47
+ * @example logging-graylog
48
+ */
49
+ plugin: string;
50
+ /**
51
+ * @name Plugin enabled
52
+ * @description If the plugin is enabled or not
53
+ * @example true
54
+ * @example false
55
+ */
56
+ enabled: boolean;
57
+ }
58
+ /**
59
+ * @name Plugin name
60
+ * @description The name of the plugin
61
+ * @example service-fastify
62
+ */
63
+ export type PluginName = string;
64
+ /**
65
+ * @name Deployment profile name
66
+ * @description The name of the deployment profile
67
+ * @example default
68
+ * @example server1
69
+ * @example frontend
70
+ * @example backend
71
+ */
72
+ export type DeploymentProfileName = string;
73
+ export interface DeploymentProfiles<T> extends Record<string, T> {
74
+ /**
75
+ * @name Default deployment profile
76
+ * @description The default deployment profile
77
+ */
78
+ default: T;
79
+ }
80
+ export interface ExtendedConfig {
81
+ config: any | undefined;
82
+ }
83
+ export interface ConfigProfile {
84
+ observable: Record<PluginName, ObservableConfig & ExtendedConfig>;
85
+ events: Record<PluginName, EventsConfig & ExtendedConfig>;
86
+ services: Record<PluginName, ServiceConfig & ExtendedConfig>;
87
+ }
88
+ export interface DefaultProfile {
89
+ default: ConfigProfile;
90
+ }
91
+ export interface ConfigDefinition extends Record<string, ConfigProfile>, DefaultProfile {
92
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * BSB (Better-Service-Base) is an event-bus based microservice framework.
4
+ * Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published
8
+ * by the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * Alternatively, you may obtain a commercial license for this program.
12
+ * The commercial license allows you to use the Program in a closed-source manner,
13
+ * including the right to create derivative works that are not subject to the terms
14
+ * of the AGPL.
15
+ *
16
+ * To obtain a commercial license, please contact the copyright holders at
17
+ * https://www.bettercorp.dev. The terms and conditions of the commercial license
18
+ * will be provided upon request.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU Affero General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU Affero General Public License
26
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ // export interface PluginConfig<INCLCONF extends boolean> {
30
+ // package?: string | null;
31
+ // plugin: string;
32
+ // name: string;
33
+ // enabled: boolean;
34
+ // config: INCLCONF extends true ? any : never;
35
+ // }
36
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/plugins/config-default/interfaces.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AA+EH,4DAA4D;AAC5D,6BAA6B;AAC7B,oBAAoB;AACpB,kBAAkB;AAClB,sBAAsB;AACtB,iDAAiD;AACjD,IAAI"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * BSB (Better-Service-Base) is an event-bus based microservice framework.
3
+ * Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published
7
+ * by the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * Alternatively, you may obtain a commercial license for this program.
11
+ * The commercial license allows you to use the Program in a closed-source manner,
12
+ * including the right to create derivative works that are not subject to the terms
13
+ * of the AGPL.
14
+ *
15
+ * To obtain a commercial license, please contact the copyright holders at
16
+ * https://www.bettercorp.dev. The terms and conditions of the commercial license
17
+ * will be provided upon request.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU Affero General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU Affero General Public License
25
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
26
+ */
27
+ import { EventEmitter } from "node:events";
28
+ import { Observable, IPluginLogging } from "../../../index";
29
+ export declare class broadcast extends EventEmitter {
30
+ constructor(_log: IPluginLogging);
31
+ dispose(): void;
32
+ onBroadcast(obs: Observable, pluginName: string, event: string, listener: {
33
+ (obs: Observable, args: Array<any>): Promise<void>;
34
+ }): Promise<void>;
35
+ emitBroadcast(obs: Observable, pluginName: string, event: string, args: Array<any>): Promise<void>;
36
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * BSB (Better-Service-Base) is an event-bus based microservice framework.
4
+ * Copyright (C) 2016 - 2025 BetterCorp (PTY) Ltd
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published
8
+ * by the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * Alternatively, you may obtain a commercial license for this program.
12
+ * The commercial license allows you to use the Program in a closed-source manner,
13
+ * including the right to create derivative works that are not subject to the terms
14
+ * of the AGPL.
15
+ *
16
+ * To obtain a commercial license, please contact the copyright holders at
17
+ * https://www.bettercorp.dev. The terms and conditions of the commercial license
18
+ * will be provided upon request.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU Affero General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU Affero General Public License
26
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.broadcast = void 0;
30
+ const node_events_1 = require("node:events");
31
+ class broadcast extends node_events_1.EventEmitter {
32
+ constructor(_log) {
33
+ super();
34
+ }
35
+ dispose() {
36
+ this.removeAllListeners();
37
+ }
38
+ async onBroadcast(obs, pluginName, event, listener) {
39
+ obs.log.debug("onBroadcast: listening to {pluginName}-{event}", {
40
+ pluginName,
41
+ event,
42
+ });
43
+ this.on(`${pluginName}-${event}`, async (eobs, args) => {
44
+ // Create child observable for receiving the broadcast
45
+ const receiveObs = eobs.startSpan("onBroadcast:receive", {
46
+ pluginName,
47
+ event,
48
+ });
49
+ try {
50
+ await listener(receiveObs, args);
51
+ }
52
+ catch (error) {
53
+ const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
54
+ receiveObs.error(errorObj);
55
+ throw error;
56
+ }
57
+ finally {
58
+ receiveObs.end();
59
+ }
60
+ });
61
+ }
62
+ async emitBroadcast(obs, pluginName, event, args) {
63
+ // Create child observable for sending the broadcast
64
+ const sendObs = obs.startSpan("emitBroadcast:send", {
65
+ pluginName,
66
+ event,
67
+ });
68
+ try {
69
+ sendObs.log.debug("emitBroadcast: emitting {pluginName}-{event}", {
70
+ pluginName, event,
71
+ });
72
+ this.emit(`${pluginName}-${event}`, sendObs, args);
73
+ }
74
+ catch (error) {
75
+ const errorObj = error instanceof Error ? error : new Error(error?.message || String(error));
76
+ sendObs.error(errorObj);
77
+ throw error;
78
+ }
79
+ finally {
80
+ sendObs.end();
81
+ }
82
+ }
83
+ }
84
+ exports.broadcast = broadcast;
85
+ //# sourceMappingURL=broadcast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../../../../src/plugins/events-default/events/broadcast.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,6CAA2C;AAG3C,MAAa,SAAU,SAAQ,0BAAY;IACzC,YAAY,IAAoB;QAC9B,KAAK,EAAE,CAAC;IACV,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,GAAe,EACf,UAAkB,EAClB,KAAa,EACb,QAAgE;QAEhE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,gDAAgD,EAAE;YAC9D,UAAU;YACV,KAAK;SACN,CAAC,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,GAAI,UAAW,IAAK,KAAM,EAAE,EAAE,KAAK,EAAE,IAAgB,EAAE,IAAW,EAAE,EAAE;YAC5E,sDAAsD;YACtD,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,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