backend-manager 4.2.21 → 4.2.23

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/CHANGELOG.md CHANGED
@@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
15
15
  - `Security` in case of vulnerabilities.
16
16
 
17
17
  ---#
18
+ # [4.2.22] - 2024-12-19
19
+ ### Changed
20
+ - `Manager.install()` now automatically binds the fn with the proper `this` context (this may be breaking).
21
+
18
22
  # [4.1.0] - 2024-12-19
19
23
  ### Changed
20
24
  - Attach `schema` to `bm-properties` response header.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "4.2.21",
3
+ "version": "4.2.23",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -619,18 +619,39 @@ Manager.prototype.install = function (controller, options) {
619
619
  self.assistant.log(`Installing from ${options.dir}, prefix=${options.prefix}, isDirectory=${isDirectory}...`);
620
620
  }
621
621
 
622
+ // function _install(prefix, file) {
623
+ // if (!file.includes('.js')) {return}
624
+ // const name = file.replace('.js', '');
625
+ // const _prefix = prefix ? `${prefix}_${name}` : name;
626
+
627
+ // const fullPath = path.resolve(options.dir, file);
628
+
629
+ // if (options.log) {
630
+ // self.assistant.log(`Installing ${_prefix} from ${fullPath}...`);
631
+ // }
632
+
633
+ // controller[`${_prefix}`] = require(fullPath);
634
+ // }
635
+
622
636
  function _install(prefix, file) {
623
- if (!file.includes('.js')) {return}
637
+ if (!file.includes('.js')) return;
638
+
624
639
  const name = file.replace('.js', '');
625
640
  const _prefix = prefix ? `${prefix}_${name}` : name;
626
-
627
641
  const fullPath = path.resolve(options.dir, file);
628
642
 
629
643
  if (options.log) {
630
644
  self.assistant.log(`Installing ${_prefix} from ${fullPath}...`);
631
645
  }
632
646
 
633
- controller[`${_prefix}`] = require(fullPath);
647
+ const mod = require(fullPath);
648
+
649
+ // If module exports a function, bind it to controller
650
+ if (typeof mod === 'function') {
651
+ controller[_prefix] = mod.bind(controller);
652
+ } else {
653
+ controller[_prefix] = mod;
654
+ }
634
655
  }
635
656
 
636
657
  if (isDirectory) {
@@ -198,7 +198,10 @@ function OpenAI(assistant, key) {
198
198
  self.assistant = assistant;
199
199
  self.Manager = assistant.Manager;
200
200
  self.user = assistant.user;
201
- self.key = key || self.Manager.config?.openai?.key;
201
+ self.key = key
202
+ || self.Manager.config?.openai?.key
203
+ || self.Manager.config?.openai?.global
204
+ || self.Manager.config?.openai?.main
202
205
 
203
206
  self.tokens = {
204
207
  total: {