@nodestackapp/server 2.5.0 → 2.6.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 (221) hide show
  1. package/README.md +40 -28
  2. package/dist/NodeStack.d.ts +1 -1
  3. package/dist/NodeStack.d.ts.map +1 -1
  4. package/dist/NodeStack.js +73 -12
  5. package/dist/NodeStack.js.map +1 -1
  6. package/dist/admin/AdminUIBundler.d.ts.map +1 -1
  7. package/dist/admin/AdminUIBundler.js +1 -0
  8. package/dist/admin/AdminUIBundler.js.map +1 -1
  9. package/dist/admin/ui/css/main.css +34 -0
  10. package/dist/admin/ui/css/webhooks.css +8 -0
  11. package/dist/admin/ui/index.html +19150 -17212
  12. package/dist/admin/ui/js/api-keys.js +1381 -0
  13. package/dist/admin/ui/js/app.js +667 -641
  14. package/dist/admin/ui/js/apps.js +496 -489
  15. package/dist/admin/ui/js/collections.js +486 -484
  16. package/dist/admin/ui/js/command-palette.js +683 -673
  17. package/dist/admin/ui/js/flows-designer.js +1125 -1076
  18. package/dist/admin/ui/js/flows.js +908 -890
  19. package/dist/admin/ui/js/functions-tester.js +1 -1
  20. package/dist/admin/ui/js/functions-workbench.js +1144 -1101
  21. package/dist/admin/ui/js/functions.js +980 -979
  22. package/dist/admin/ui/js/rules.js +1080 -775
  23. package/dist/admin/ui/js/schema.js +346 -304
  24. package/dist/admin/ui/js/views.js +1 -1
  25. package/dist/apps/AppManager.d.ts +1 -1
  26. package/dist/apps/AppManager.d.ts.map +1 -1
  27. package/dist/apps/AppManager.js +4 -18
  28. package/dist/apps/AppManager.js.map +1 -1
  29. package/dist/apps/AppRegistry.d.ts +1 -0
  30. package/dist/apps/AppRegistry.d.ts.map +1 -1
  31. package/dist/apps/AppRegistry.js +78 -23
  32. package/dist/apps/AppRegistry.js.map +1 -1
  33. package/dist/apps/AppScope.d.ts +0 -1
  34. package/dist/apps/AppScope.d.ts.map +1 -1
  35. package/dist/apps/AppScope.js +5 -15
  36. package/dist/apps/AppScope.js.map +1 -1
  37. package/dist/auth/ApiKeyService.d.ts +62 -2
  38. package/dist/auth/ApiKeyService.d.ts.map +1 -1
  39. package/dist/auth/ApiKeyService.js +503 -8
  40. package/dist/auth/ApiKeyService.js.map +1 -1
  41. package/dist/auth/AuthService.d.ts +30 -1
  42. package/dist/auth/AuthService.d.ts.map +1 -1
  43. package/dist/auth/AuthService.js +468 -65
  44. package/dist/auth/AuthService.js.map +1 -1
  45. package/dist/auth/oauth/AppleProvider.d.ts +2 -0
  46. package/dist/auth/oauth/AppleProvider.d.ts.map +1 -1
  47. package/dist/auth/oauth/AppleProvider.js +40 -3
  48. package/dist/auth/oauth/AppleProvider.js.map +1 -1
  49. package/dist/auth/oauth/BaseOAuthProvider.d.ts +3 -2
  50. package/dist/auth/oauth/BaseOAuthProvider.d.ts.map +1 -1
  51. package/dist/auth/oauth/BaseOAuthProvider.js +29 -3
  52. package/dist/auth/oauth/BaseOAuthProvider.js.map +1 -1
  53. package/dist/auth/oauth/DiscordProvider.d.ts.map +1 -1
  54. package/dist/auth/oauth/DiscordProvider.js +4 -1
  55. package/dist/auth/oauth/DiscordProvider.js.map +1 -1
  56. package/dist/auth/oauth/GitHubProvider.d.ts.map +1 -1
  57. package/dist/auth/oauth/GitHubProvider.js +4 -1
  58. package/dist/auth/oauth/GitHubProvider.js.map +1 -1
  59. package/dist/auth/oauth/GoogleProvider.d.ts.map +1 -1
  60. package/dist/auth/oauth/GoogleProvider.js +4 -1
  61. package/dist/auth/oauth/GoogleProvider.js.map +1 -1
  62. package/dist/auth/oauth/MicrosoftProvider.d.ts.map +1 -1
  63. package/dist/auth/oauth/MicrosoftProvider.js +4 -1
  64. package/dist/auth/oauth/MicrosoftProvider.js.map +1 -1
  65. package/dist/auth/oauth/OAuthProviderRegistry.d.ts +6 -2
  66. package/dist/auth/oauth/OAuthProviderRegistry.d.ts.map +1 -1
  67. package/dist/auth/oauth/OAuthProviderRegistry.js +25 -10
  68. package/dist/auth/oauth/OAuthProviderRegistry.js.map +1 -1
  69. package/dist/auth/oauth/types.d.ts +4 -2
  70. package/dist/auth/oauth/types.d.ts.map +1 -1
  71. package/dist/cli/cli.d.ts.map +1 -1
  72. package/dist/cli/cli.js +228 -12
  73. package/dist/cli/cli.js.map +1 -1
  74. package/dist/core/config/ConfigService.d.ts.map +1 -1
  75. package/dist/core/config/ConfigService.js +5 -3
  76. package/dist/core/config/ConfigService.js.map +1 -1
  77. package/dist/core/config/EnvLoader.d.ts +14 -0
  78. package/dist/core/config/EnvLoader.d.ts.map +1 -1
  79. package/dist/core/config/EnvLoader.js +44 -0
  80. package/dist/core/config/EnvLoader.js.map +1 -1
  81. package/dist/core/container/Container.d.ts +14 -0
  82. package/dist/core/container/Container.d.ts.map +1 -1
  83. package/dist/core/container/Container.js +32 -0
  84. package/dist/core/container/Container.js.map +1 -1
  85. package/dist/core/errors/AppError.d.ts +7 -7
  86. package/dist/core/errors/AppError.d.ts.map +1 -1
  87. package/dist/core/errors/AppError.js +18 -14
  88. package/dist/core/errors/AppError.js.map +1 -1
  89. package/dist/core/events/EventBus.d.ts.map +1 -1
  90. package/dist/core/events/EventBus.js +36 -6
  91. package/dist/core/events/EventBus.js.map +1 -1
  92. package/dist/core/maintenance/MaintenanceGate.d.ts +47 -0
  93. package/dist/core/maintenance/MaintenanceGate.d.ts.map +1 -1
  94. package/dist/core/maintenance/MaintenanceGate.js +265 -7
  95. package/dist/core/maintenance/MaintenanceGate.js.map +1 -1
  96. package/dist/core/plugins/PluginManager.d.ts +20 -1
  97. package/dist/core/plugins/PluginManager.d.ts.map +1 -1
  98. package/dist/core/plugins/PluginManager.js +231 -146
  99. package/dist/core/plugins/PluginManager.js.map +1 -1
  100. package/dist/core/plugins/types.d.ts +48 -31
  101. package/dist/core/plugins/types.d.ts.map +1 -1
  102. package/dist/database/DatabaseService.d.ts +1 -0
  103. package/dist/database/DatabaseService.d.ts.map +1 -1
  104. package/dist/database/DatabaseService.js +24 -6
  105. package/dist/database/DatabaseService.js.map +1 -1
  106. package/dist/database/drivers/DriverRegistry.d.ts +1 -0
  107. package/dist/database/drivers/DriverRegistry.d.ts.map +1 -1
  108. package/dist/database/drivers/DriverRegistry.js +29 -0
  109. package/dist/database/drivers/DriverRegistry.js.map +1 -1
  110. package/dist/database/drivers/IDatabaseDriver.d.ts +1 -0
  111. package/dist/database/drivers/IDatabaseDriver.d.ts.map +1 -1
  112. package/dist/database/drivers/MssqlDriver.d.ts.map +1 -1
  113. package/dist/database/drivers/MssqlDriver.js +8 -2
  114. package/dist/database/drivers/MssqlDriver.js.map +1 -1
  115. package/dist/database/drivers/NodeSqliteDriver.d.ts.map +1 -1
  116. package/dist/database/drivers/NodeSqliteDriver.js +15 -1
  117. package/dist/database/drivers/NodeSqliteDriver.js.map +1 -1
  118. package/dist/database/migrations/SystemMigrations.d.ts.map +1 -1
  119. package/dist/database/migrations/SystemMigrations.js +62 -5
  120. package/dist/database/migrations/SystemMigrations.js.map +1 -1
  121. package/dist/flows/FlowEngine.js.map +1 -1
  122. package/dist/flows/FlowService.d.ts +7 -1
  123. package/dist/flows/FlowService.d.ts.map +1 -1
  124. package/dist/flows/FlowService.js +126 -12
  125. package/dist/flows/FlowService.js.map +1 -1
  126. package/dist/flows/FlowValidator.d.ts +1 -0
  127. package/dist/flows/FlowValidator.d.ts.map +1 -1
  128. package/dist/flows/FlowValidator.js +76 -1
  129. package/dist/flows/FlowValidator.js.map +1 -1
  130. package/dist/flows/types.d.ts +14 -2
  131. package/dist/flows/types.d.ts.map +1 -1
  132. package/dist/functions/FunctionService.d.ts +5 -1
  133. package/dist/functions/FunctionService.d.ts.map +1 -1
  134. package/dist/functions/FunctionService.js +84 -33
  135. package/dist/functions/FunctionService.js.map +1 -1
  136. package/dist/functions/runtime/QuickJsWasmRuntime.d.ts.map +1 -1
  137. package/dist/functions/runtime/QuickJsWasmRuntime.js +19 -10
  138. package/dist/functions/runtime/QuickJsWasmRuntime.js.map +1 -1
  139. package/dist/functions/types.d.ts +16 -2
  140. package/dist/functions/types.d.ts.map +1 -1
  141. package/dist/http/HttpServer.d.ts +3 -0
  142. package/dist/http/HttpServer.d.ts.map +1 -1
  143. package/dist/http/HttpServer.js +153 -6
  144. package/dist/http/HttpServer.js.map +1 -1
  145. package/dist/http/controllers/ApiKeyController.d.ts +1 -0
  146. package/dist/http/controllers/ApiKeyController.d.ts.map +1 -1
  147. package/dist/http/controllers/ApiKeyController.js +47 -1
  148. package/dist/http/controllers/ApiKeyController.js.map +1 -1
  149. package/dist/http/controllers/AuthController.d.ts +12 -0
  150. package/dist/http/controllers/AuthController.d.ts.map +1 -1
  151. package/dist/http/controllers/AuthController.js +40 -2
  152. package/dist/http/controllers/AuthController.js.map +1 -1
  153. package/dist/http/controllers/FlowController.d.ts.map +1 -1
  154. package/dist/http/controllers/FlowController.js +45 -4
  155. package/dist/http/controllers/FlowController.js.map +1 -1
  156. package/dist/http/controllers/FunctionController.d.ts.map +1 -1
  157. package/dist/http/controllers/FunctionController.js +16 -2
  158. package/dist/http/controllers/FunctionController.js.map +1 -1
  159. package/dist/http/controllers/HealthController.js +2 -2
  160. package/dist/http/middleware/AppResolutionMiddleware.d.ts +1 -1
  161. package/dist/http/middleware/AppResolutionMiddleware.d.ts.map +1 -1
  162. package/dist/http/middleware/AppResolutionMiddleware.js +2 -3
  163. package/dist/http/middleware/AppResolutionMiddleware.js.map +1 -1
  164. package/dist/http/middleware/AuthMiddleware.d.ts.map +1 -1
  165. package/dist/http/middleware/AuthMiddleware.js +6 -3
  166. package/dist/http/middleware/AuthMiddleware.js.map +1 -1
  167. package/dist/http/middleware/ChaosMiddleware.js +6 -6
  168. package/dist/http/middleware/ChaosMiddleware.js.map +1 -1
  169. package/dist/index.d.ts +2 -2
  170. package/dist/index.d.ts.map +1 -1
  171. package/dist/index.js +6 -2
  172. package/dist/index.js.map +1 -1
  173. package/dist/queue/QueueService.d.ts +9 -0
  174. package/dist/queue/QueueService.d.ts.map +1 -1
  175. package/dist/queue/QueueService.js +143 -60
  176. package/dist/queue/QueueService.js.map +1 -1
  177. package/dist/queue/drivers/SqliteQueueDriver.d.ts +3 -0
  178. package/dist/queue/drivers/SqliteQueueDriver.d.ts.map +1 -1
  179. package/dist/queue/drivers/SqliteQueueDriver.js +315 -255
  180. package/dist/queue/drivers/SqliteQueueDriver.js.map +1 -1
  181. package/dist/records/FtsService.d.ts +7 -3
  182. package/dist/records/FtsService.d.ts.map +1 -1
  183. package/dist/records/FtsService.js +69 -5
  184. package/dist/records/FtsService.js.map +1 -1
  185. package/dist/records/QueryFilterParser.d.ts.map +1 -1
  186. package/dist/records/QueryFilterParser.js +58 -20
  187. package/dist/records/QueryFilterParser.js.map +1 -1
  188. package/dist/records/RecordSanitizer.d.ts.map +1 -1
  189. package/dist/records/RecordSanitizer.js +32 -4
  190. package/dist/records/RecordSanitizer.js.map +1 -1
  191. package/dist/records/RecordService.d.ts +6 -0
  192. package/dist/records/RecordService.d.ts.map +1 -1
  193. package/dist/records/RecordService.js +95 -14
  194. package/dist/records/RecordService.js.map +1 -1
  195. package/dist/records/RecordValidator.d.ts +10 -0
  196. package/dist/records/RecordValidator.d.ts.map +1 -1
  197. package/dist/records/RecordValidator.js +110 -2
  198. package/dist/records/RecordValidator.js.map +1 -1
  199. package/dist/records/fts/IFtsDriver.d.ts +7 -6
  200. package/dist/records/fts/IFtsDriver.d.ts.map +1 -1
  201. package/dist/records/fts/MssqlFtsDriver.d.ts +5 -1
  202. package/dist/records/fts/MssqlFtsDriver.d.ts.map +1 -1
  203. package/dist/records/fts/MssqlFtsDriver.js +35 -3
  204. package/dist/records/fts/MssqlFtsDriver.js.map +1 -1
  205. package/dist/records/fts/PostgresFtsDriver.d.ts +9 -2
  206. package/dist/records/fts/PostgresFtsDriver.d.ts.map +1 -1
  207. package/dist/records/fts/PostgresFtsDriver.js +116 -11
  208. package/dist/records/fts/PostgresFtsDriver.js.map +1 -1
  209. package/dist/records/fts/SqliteFts5Driver.d.ts +7 -1
  210. package/dist/records/fts/SqliteFts5Driver.d.ts.map +1 -1
  211. package/dist/records/fts/SqliteFts5Driver.js +66 -6
  212. package/dist/records/fts/SqliteFts5Driver.js.map +1 -1
  213. package/dist/schema/OpenApiGenerator.d.ts.map +1 -1
  214. package/dist/schema/OpenApiGenerator.js +103 -3
  215. package/dist/schema/OpenApiGenerator.js.map +1 -1
  216. package/dist/schema/models/Field.d.ts +1 -0
  217. package/dist/schema/models/Field.d.ts.map +1 -1
  218. package/dist/templates/definitions/ecommerce.js +6 -6
  219. package/dist/templates/definitions/ecommerce.js.map +1 -1
  220. package/dist/webhooks/WebhookService.js +1 -1
  221. package/package.json +4 -3
@@ -1 +1 @@
1
- {"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../../src/core/plugins/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,YAAY,EAAE,cAAc,EAAsB,MAAM,SAAS,CAAC;AAE5F,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EACL,gBAAgB,EAChB,eAAe,EAEf,cAAc,EAId,kBAAkB,EAGlB,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAQ/C,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;C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AAO,CAAC,iBAAiB;IAezB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAyG5B;;;;OAIG;IACI,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA2FjF;IAED;;;;;;;OAOG;IACI,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,eAAe,GAAG,kBAAkB,CAgI7E;IAED;;;;;;;OAOG;IACU,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAyJ7H;IAED;;OAEG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAsBpC;CACF"}
@@ -3,7 +3,7 @@ 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
- exports.PluginManager = exports.OFFICIAL_PLUGINS = void 0;
6
+ exports.PluginManager = exports.ALLOWED_CORE_SERVICE_TOKENS = exports.OFFICIAL_PLUGINS = void 0;
7
7
  const find_my_way_1 = __importDefault(require("find-my-way"));
8
8
  const Tokens_1 = require("../container/Tokens");
9
9
  const AppError_1 = require("../errors/AppError");
@@ -74,6 +74,13 @@ exports.OFFICIAL_PLUGINS = [
74
74
  factory: () => (0, algolia_1.algoliaPlugin)(),
75
75
  },
76
76
  ];
77
+ const CORE_TOKENS_SET = new Set(Object.values(Tokens_1.TOKENS));
78
+ exports.ALLOWED_CORE_SERVICE_TOKENS = new Set([
79
+ Tokens_1.TOKENS.DatabaseService,
80
+ Tokens_1.TOKENS.SchemaService,
81
+ Tokens_1.TOKENS.RecordService,
82
+ Tokens_1.TOKENS.ConfigService,
83
+ ]);
77
84
  class PluginManager {
78
85
  app;
79
86
  container;
@@ -128,6 +135,12 @@ class PluginManager {
128
135
  }
129
136
  });
130
137
  }
138
+ }
139
+ /**
140
+ * Load any auto-enabled plugins on startup. Must be invoked after core service tokens
141
+ * are locked in the IoC container to enforce least privilege.
142
+ */
143
+ loadAutoEnabledPluginsOnStartup() {
131
144
  if (this.app.db.dialect.name === 'sqlite') {
132
145
  this.loadAutoEnabledPluginsSync();
133
146
  }
@@ -136,52 +149,157 @@ class PluginManager {
136
149
  }
137
150
  }
138
151
  /**
139
- * Install/use a plugin on the NodeStack instance
152
+ * Build a secure, restricted PluginContext API for plugin lifecycle execution.
153
+ * In accordance with the Principle of Least Privilege:
154
+ * - No raw DI Container access
155
+ * - No raw Fastify instance access (router.raw removed)
156
+ * - No internal core DI tokens leaked
157
+ * - No raw admin UI engine leaked
158
+ * - Safe application facade (records, db, schema, config, etc.) without host lifecycle (stop, start, maintenanceGate)
159
+ * - Safe EventBus without destructive clear()
160
+ * - Read-only getService() and custom plugin bindService() (core tokens sealed)
140
161
  */
141
- use(pluginOrFn, targetScope) {
142
- // 1. Normalize plugin
143
- let plugin;
144
- if (typeof pluginOrFn === 'function') {
145
- if (this.registeredFunctions.has(pluginOrFn)) {
146
- throw new Error('[PluginManager] This plugin function is already registered.');
147
- }
148
- const fnName = pluginOrFn.name || `plugin_${this.anonymousCounter++}`;
149
- plugin = {
150
- name: fnName,
151
- register: pluginOrFn,
152
- };
153
- }
154
- else {
155
- plugin = pluginOrFn;
156
- }
157
- if (!plugin || typeof plugin !== 'object' || !plugin.name) {
158
- throw new Error('[PluginManager] Invalid plugin provided: must have a valid name');
159
- }
160
- // 2. Check duplicate registration
161
- if (this.plugins.has(plugin.name)) {
162
- throw new Error(`[PluginManager] Plugin "${plugin.name}" is already registered. Duplicate plugin registrations are not permitted.`);
163
- }
164
- if (typeof pluginOrFn === 'function') {
165
- this.registeredFunctions.add(pluginOrFn);
166
- }
167
- // 3. Validate dependencies
168
- if (plugin.dependencies && plugin.dependencies.length > 0) {
169
- for (const dep of plugin.dependencies) {
170
- if (!this.plugins.has(dep)) {
171
- throw new Error(`[PluginManager] Plugin "${plugin.name}" requires dependent plugin "${dep}" which has not been registered.`);
162
+ createPluginContext(pluginName, targetScope) {
163
+ const isDefaultScope = !targetScope ||
164
+ targetScope === this.app.defaultApp ||
165
+ targetScope.app.slug === 'default' ||
166
+ targetScope.db === this.app.db;
167
+ const targetDb = targetScope ? targetScope.db : this.app.db;
168
+ const targetSchema = targetScope ? targetScope.schema : this.app.schema;
169
+ const targetRecords = targetScope ? targetScope.records : this.app.records;
170
+ const targetConfig = targetScope ? targetScope.config : this.app.config;
171
+ const targetEventBus = targetScope ? targetScope.eventBus : this.app.eventBus;
172
+ // 1. Safe PluginManagerFacade: Exposes ONLY own effective configuration (or justified alias), NOT container, app, use, disposeScope, or arbitrary plugin secrets
173
+ const allowedConfigPluginNames = new Set([pluginName]);
174
+ if (pluginName === 'chat-notifications')
175
+ allowedConfigPluginNames.add('webhooks');
176
+ if (pluginName === 'webhooks')
177
+ allowedConfigPluginNames.add('chat-notifications');
178
+ const pluginManagerFacade = {
179
+ getEffectiveConfig: (name, db) => {
180
+ const targetName = name || pluginName;
181
+ if (!allowedConfigPluginNames.has(targetName)) {
182
+ throw new Error(`[PluginManager] Unauthorized configuration access: Plugin "${pluginName}" is not permitted to access configuration for "${targetName}".`);
183
+ }
184
+ if (!isDefaultScope && db && db !== targetDb) {
185
+ throw new Error(`[PluginManager] Unauthorized database access: Scoped plugins cannot query configuration outside their assigned application scope.`);
172
186
  }
187
+ const effectiveDb = db || targetDb;
188
+ return this.getEffectiveConfig(targetName, effectiveDb);
189
+ },
190
+ };
191
+ // 2. Safe PluginAppFacade: Exposes ONLY domain data services, NOT container, server, stop(), or maintenanceGate
192
+ const appFacade = {
193
+ db: targetDb,
194
+ schema: targetSchema,
195
+ records: targetRecords,
196
+ config: targetConfig,
197
+ plugins: pluginManagerFacade,
198
+ };
199
+ // 2. Safe PluginEventBus: Exposes ONLY emit and on, NO destructive clear()
200
+ const safeEventBus = {
201
+ emit: (event, data) => targetEventBus.emit(event, data),
202
+ on: (event, handler) => targetEventBus.on(event, handler),
203
+ };
204
+ // 3. DI helpers: getService (restricted to safe capabilities and custom tokens) and bindService (custom tokens only, core tokens locked)
205
+ const getService = (token) => {
206
+ if (CORE_TOKENS_SET.has(token)) {
207
+ if (!exports.ALLOWED_CORE_SERVICE_TOKENS.has(token)) {
208
+ const tokenName = typeof token === 'symbol' ? (token.description || token.toString()) : String(token);
209
+ throw new Error(`[PluginManager] Access to restricted service token is not permitted: ${tokenName}`);
210
+ }
211
+ if (token === Tokens_1.TOKENS.DatabaseService)
212
+ return targetDb;
213
+ if (token === Tokens_1.TOKENS.SchemaService)
214
+ return targetSchema;
215
+ if (token === Tokens_1.TOKENS.RecordService)
216
+ return targetRecords;
217
+ if (token === Tokens_1.TOKENS.ConfigService)
218
+ return targetConfig;
219
+ }
220
+ return this.container.get(token);
221
+ };
222
+ const bindService = (token, instance) => {
223
+ if (this.container.isLocked(token)) {
224
+ const tokenName = typeof token === 'symbol' ? (token.description || token.toString()) : String(token);
225
+ throw new Error(`[PluginManager] Cannot override core service token: ${tokenName}`);
173
226
  }
227
+ this.container.bindInstance(token, instance);
228
+ };
229
+ if (!isDefaultScope && targetScope) {
230
+ const scopedContext = {
231
+ app: appFacade,
232
+ config: targetConfig,
233
+ db: targetDb,
234
+ schema: targetSchema,
235
+ records: targetRecords,
236
+ eventBus: safeEventBus,
237
+ auth: {
238
+ requireAdmin: () => this.app.authMiddleware.requireAdmin(),
239
+ requireAdminOrInitial: () => this.app.authMiddleware.requireAdminOrInitialSetup(),
240
+ requireAuth: () => this.app.authMiddleware.requireAuth(),
241
+ },
242
+ router: {
243
+ get: () => { },
244
+ post: () => { },
245
+ patch: () => { },
246
+ delete: () => { },
247
+ put: () => { },
248
+ },
249
+ registerRoute: () => { },
250
+ registerAdminNav: () => { },
251
+ registerSystemCollection: (dto) => targetSchema.registerSystemCollection(dto),
252
+ registerHook: (event, handler, collection) => {
253
+ const guardedHandler = async (...args) => {
254
+ if (!this.isPluginEnabledInDb(pluginName, targetScope.db)) {
255
+ return;
256
+ }
257
+ return handler(...args);
258
+ };
259
+ let unsubscribe;
260
+ switch (event) {
261
+ case 'beforeCreate':
262
+ unsubscribe = targetScope.eventBus.onRecordBeforeCreate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
263
+ break;
264
+ case 'afterCreate':
265
+ unsubscribe = targetScope.eventBus.onRecordAfterCreate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
266
+ break;
267
+ case 'beforeUpdate':
268
+ unsubscribe = targetScope.eventBus.onRecordBeforeUpdate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
269
+ break;
270
+ case 'afterUpdate':
271
+ unsubscribe = targetScope.eventBus.onRecordAfterUpdate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
272
+ break;
273
+ case 'beforeDelete':
274
+ unsubscribe = targetScope.eventBus.onRecordBeforeDelete(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
275
+ break;
276
+ case 'afterDelete':
277
+ unsubscribe = targetScope.eventBus.onRecordAfterDelete(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
278
+ break;
279
+ case 'beforeServe':
280
+ unsubscribe = targetScope.eventBus.onBeforeServe(guardedHandler);
281
+ break;
282
+ case 'afterServe':
283
+ unsubscribe = targetScope.eventBus.onAfterServe(guardedHandler);
284
+ break;
285
+ default:
286
+ unsubscribe = targetScope.eventBus.on(event, guardedHandler);
287
+ break;
288
+ }
289
+ this.addScopedHookUnsubscriber(targetScope.app.slug, pluginName, unsubscribe);
290
+ },
291
+ getService,
292
+ bindService: () => { },
293
+ };
294
+ return scopedContext;
174
295
  }
175
- // 4. Build Plugin Context
176
296
  const context = {
177
- app: this.app,
178
- container: this.container,
179
- tokens: Tokens_1.TOKENS,
297
+ app: appFacade,
180
298
  config: this.app.config,
181
299
  db: this.app.db,
182
300
  schema: this.app.schema,
183
- eventBus: this.app.eventBus,
184
- adminUi: this.app.adminUi,
301
+ records: this.app.records,
302
+ eventBus: safeEventBus,
185
303
  auth: {
186
304
  requireAdmin: () => this.app.authMiddleware.requireAdmin(),
187
305
  requireAdminOrInitial: () => this.app.authMiddleware.requireAdminOrInitialSetup(),
@@ -193,13 +311,12 @@ class PluginManager {
193
311
  patch: (path, handler, options) => context.registerRoute('PATCH', path, handler, options),
194
312
  delete: (path, handler, options) => context.registerRoute('DELETE', path, handler, options),
195
313
  put: (path, handler, options) => context.registerRoute('PUT', path, handler, options),
196
- raw: this.app.server.app,
197
314
  },
198
315
  registerRoute: (method, path, handler, options = {}) => {
199
316
  const fastify = this.app.server.app;
200
317
  const resolvedOptions = this.resolveRouteOptions(options);
201
318
  const routeHandler = async (req, reply) => {
202
- if (!this.plugins.has(plugin.name)) {
319
+ if (!this.plugins.has(pluginName)) {
203
320
  return reply.status(404).send({
204
321
  statusCode: 404,
205
322
  error: 'Not Found',
@@ -209,7 +326,7 @@ class PluginManager {
209
326
  return handler.call(this.app.server.app, req, reply);
210
327
  };
211
328
  const registerBoth = (p) => {
212
- this.registerDynamicRoute(method, p, routeHandler, resolvedOptions, plugin.name);
329
+ this.registerDynamicRoute(method, p, routeHandler, resolvedOptions, pluginName);
213
330
  const isBooted = this.isFastifyBooted(fastify);
214
331
  if (!isBooted) {
215
332
  try {
@@ -237,9 +354,8 @@ class PluginManager {
237
354
  }
238
355
  },
239
356
  registerHook: (event, handler, collection) => {
240
- // Guard handler with the plugin's active status
241
357
  const guardedHandler = async (...args) => {
242
- if (!this.plugins.has(plugin.name)) {
358
+ if (!this.plugins.has(pluginName)) {
243
359
  return;
244
360
  }
245
361
  return handler(...args);
@@ -274,10 +390,10 @@ class PluginManager {
274
390
  unsubscribe = this.app.eventBus.on(event, guardedHandler);
275
391
  break;
276
392
  }
277
- if (!this.pluginHookUnsubscribers.has(plugin.name)) {
278
- this.pluginHookUnsubscribers.set(plugin.name, []);
393
+ if (!this.pluginHookUnsubscribers.has(pluginName)) {
394
+ this.pluginHookUnsubscribers.set(pluginName, []);
279
395
  }
280
- this.pluginHookUnsubscribers.get(plugin.name).push(unsubscribe);
396
+ this.pluginHookUnsubscribers.get(pluginName).push(unsubscribe);
281
397
  },
282
398
  registerSystemCollection: (dto) => {
283
399
  return this.app.schema.registerSystemCollection(dto);
@@ -285,13 +401,50 @@ class PluginManager {
285
401
  registerAdminNav: (item) => {
286
402
  this.app.adminUi.registerNavItem(item);
287
403
  },
288
- getService: (token) => {
289
- return this.container.get(token);
290
- },
291
- bindService: (token, instance) => {
292
- this.container.bindInstance(token, instance);
293
- },
404
+ getService,
405
+ bindService,
294
406
  };
407
+ return context;
408
+ }
409
+ /**
410
+ * Install/use a plugin on the NodeStack instance
411
+ */
412
+ use(pluginOrFn, targetScope) {
413
+ // 1. Normalize plugin
414
+ let plugin;
415
+ if (typeof pluginOrFn === 'function') {
416
+ if (this.registeredFunctions.has(pluginOrFn)) {
417
+ throw new Error('[PluginManager] This plugin function is already registered.');
418
+ }
419
+ const fnName = pluginOrFn.name || `plugin_${this.anonymousCounter++}`;
420
+ plugin = {
421
+ name: fnName,
422
+ register: pluginOrFn,
423
+ };
424
+ }
425
+ else {
426
+ plugin = pluginOrFn;
427
+ }
428
+ if (!plugin || typeof plugin !== 'object' || !plugin.name) {
429
+ throw new Error('[PluginManager] Invalid plugin provided: must have a valid name');
430
+ }
431
+ // 2. Check duplicate registration
432
+ if (this.plugins.has(plugin.name)) {
433
+ throw new Error(`[PluginManager] Plugin "${plugin.name}" is already registered. Duplicate plugin registrations are not permitted.`);
434
+ }
435
+ if (typeof pluginOrFn === 'function') {
436
+ this.registeredFunctions.add(pluginOrFn);
437
+ }
438
+ // 3. Validate dependencies
439
+ if (plugin.dependencies && plugin.dependencies.length > 0) {
440
+ for (const dep of plugin.dependencies) {
441
+ if (!this.plugins.has(dep)) {
442
+ throw new Error(`[PluginManager] Plugin "${plugin.name}" requires dependent plugin "${dep}" which has not been registered.`);
443
+ }
444
+ }
445
+ }
446
+ // 4. Build Plugin Context
447
+ const context = this.createPluginContext(plugin.name);
295
448
  // 5. Execute Declarative Registrations
296
449
  const scopeToProvision = targetScope || this.app.defaultApp;
297
450
  if (scopeToProvision) {
@@ -312,7 +465,20 @@ class PluginManager {
312
465
  }
313
466
  }
314
467
  // 6. Execute Lifecycle Hooks
315
- if (typeof plugin.register === 'function') {
468
+ if (typeof plugin.onRegister === 'function') {
469
+ const regRes = plugin.onRegister(context);
470
+ if (regRes instanceof Promise) {
471
+ this.pendingInits.push(regRes.catch((err) => {
472
+ const record = this.plugins.get(plugin.name);
473
+ if (record) {
474
+ record.status = 'error';
475
+ record.error = err;
476
+ }
477
+ console.error(`[PluginManager] Error in onRegister hook for "${plugin.name}":`, err);
478
+ }));
479
+ }
480
+ }
481
+ if (typeof plugin.register === 'function' && plugin.register !== plugin.onRegister) {
316
482
  const regRes = plugin.register(context);
317
483
  if (regRes instanceof Promise) {
318
484
  this.pendingInits.push(regRes.catch((err) => {
@@ -986,104 +1152,23 @@ class PluginManager {
986
1152
  }
987
1153
  }
988
1154
  wireScopedPluginLifecycle(plugin, scope) {
989
- if (typeof plugin.register !== 'function')
1155
+ if (typeof plugin.register !== 'function' && typeof plugin.onRegister !== 'function')
990
1156
  return;
991
1157
  try {
992
1158
  const def = exports.OFFICIAL_PLUGINS.find((p) => p.name === plugin.name || p.id === plugin.name);
993
1159
  const scopedPlugin = def ? def.factory() : plugin;
994
- const scopedApp = new Proxy(this.app, {
995
- get(target, prop, receiver) {
996
- if (prop === 'db')
997
- return scope.db;
998
- if (prop === 'schema')
999
- return scope.schema;
1000
- if (prop === 'records')
1001
- return scope.records;
1002
- if (prop === 'eventBus')
1003
- return scope.eventBus;
1004
- if (prop === 'files')
1005
- return scope.files;
1006
- if (prop === 'fts')
1007
- return scope.fts;
1008
- if (prop === 'analytics')
1009
- return scope.analytics;
1010
- if (prop === 'auditLogs')
1011
- return scope.auditLogs;
1012
- if (prop === 'webhooks')
1013
- return scope.webhooks;
1014
- return Reflect.get(target, prop, receiver);
1015
- },
1016
- });
1017
- const scopedContext = {
1018
- app: scopedApp,
1019
- container: this.container,
1020
- tokens: Tokens_1.TOKENS,
1021
- config: scope.config,
1022
- db: scope.db,
1023
- schema: scope.schema,
1024
- eventBus: scope.eventBus,
1025
- adminUi: this.app.adminUi,
1026
- auth: {
1027
- requireAdmin: () => this.app.authMiddleware.requireAdmin(),
1028
- requireAdminOrInitial: () => this.app.authMiddleware.requireAdminOrInitialSetup(),
1029
- requireAuth: () => this.app.authMiddleware.requireAuth(),
1030
- },
1031
- router: {
1032
- get: () => { },
1033
- post: () => { },
1034
- patch: () => { },
1035
- delete: () => { },
1036
- put: () => { },
1037
- raw: this.app.server?.app,
1038
- },
1039
- registerRoute: () => { },
1040
- registerAdminNav: () => { },
1041
- registerSystemCollection: (dto) => scope.schema.registerSystemCollection(dto),
1042
- registerHook: (event, handler, collection) => {
1043
- const guardedHandler = async (...args) => {
1044
- if (!this.isPluginEnabledInDb(scopedPlugin.name, scope.db)) {
1045
- return;
1046
- }
1047
- return handler(...args);
1048
- };
1049
- let unsubscribe;
1050
- switch (event) {
1051
- case 'beforeCreate':
1052
- unsubscribe = scope.eventBus.onRecordBeforeCreate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
1053
- break;
1054
- case 'afterCreate':
1055
- unsubscribe = scope.eventBus.onRecordAfterCreate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
1056
- break;
1057
- case 'beforeUpdate':
1058
- unsubscribe = scope.eventBus.onRecordBeforeUpdate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
1059
- break;
1060
- case 'afterUpdate':
1061
- unsubscribe = scope.eventBus.onRecordAfterUpdate(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
1062
- break;
1063
- case 'beforeDelete':
1064
- unsubscribe = scope.eventBus.onRecordBeforeDelete(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
1065
- break;
1066
- case 'afterDelete':
1067
- unsubscribe = scope.eventBus.onRecordAfterDelete(collection ? collection : guardedHandler, collection ? guardedHandler : undefined);
1068
- break;
1069
- case 'beforeServe':
1070
- unsubscribe = scope.eventBus.onBeforeServe(guardedHandler);
1071
- break;
1072
- case 'afterServe':
1073
- unsubscribe = scope.eventBus.onAfterServe(guardedHandler);
1074
- break;
1075
- default:
1076
- unsubscribe = scope.eventBus.on(event, guardedHandler);
1077
- break;
1078
- }
1079
- this.addScopedHookUnsubscriber(scope.app.slug, scopedPlugin.name, unsubscribe);
1080
- },
1081
- getService: (token) => this.container.get(token),
1082
- bindService: () => { },
1083
- };
1160
+ const scopedContext = this.createPluginContext(scopedPlugin.name, scope);
1084
1161
  const key = this.getScopedHookKey(scope.app.slug, scopedPlugin.name);
1085
1162
  this.scopedPlugins.set(key, { plugin: scopedPlugin, context: scopedContext });
1086
- if (typeof scopedPlugin.register === 'function') {
1163
+ if (typeof scopedPlugin.onRegister === 'function') {
1164
+ const regRes = scopedPlugin.onRegister(scopedContext);
1165
+ if (regRes instanceof Promise) {
1166
+ this.pendingInits.push(regRes.catch((err) => {
1167
+ console.error(`[PluginManager] Scoped onRegister error for "${scopedPlugin.name}" in app "${scope.app.slug}":`, err);
1168
+ }));
1169
+ }
1170
+ }
1171
+ if (typeof scopedPlugin.register === 'function' && scopedPlugin.register !== scopedPlugin.onRegister) {
1087
1172
  const regRes = scopedPlugin.register(scopedContext);
1088
1173
  if (regRes instanceof Promise) {
1089
1174
  this.pendingInits.push(regRes.catch((err) => {