@vsaas/loopback 12.2.4 → 12.3.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.
@@ -253,6 +253,21 @@ var require_application = /* @__PURE__ */ require_runtime.__commonJSMin(((export
253
253
  */
254
254
  app.dataSources = app.datasources = {};
255
255
  /**
256
+ * Decide whether the caller of a remote invocation is authenticated.
257
+ *
258
+ * An ACL denial for an authenticated caller uses `aclErrorStatus`; an
259
+ * anonymous caller is always denied with 401. By default only a LoopBack
260
+ * access token authenticates. Applications that authenticate callers by other
261
+ * means (API keys, device tokens, server keys) override this method so their
262
+ * denials are reported as the configured status instead of 401.
263
+ *
264
+ * @param {Object} ctx The remoting context.
265
+ * @returns {boolean}
266
+ */
267
+ app.isRequestAuthenticated = function(ctx) {
268
+ return Boolean(ctx.req && ctx.req.accessToken);
269
+ };
270
+ /**
256
271
  * Enable app wide authentication.
257
272
  */
258
273
  app.enableAuth = function(options) {
@@ -291,7 +306,7 @@ var require_application = /* @__PURE__ */ require_runtime.__commonJSMin(((export
291
306
  const modelId = modelInstance && modelInstance.id || (req.params && req.params.id !== void 0 ? req.params.id : req.body && req.body.id !== void 0 ? req.body.id : req.query && req.query.id !== void 0 ? req.query.id : void 0);
292
307
  const modelName = Model.modelName;
293
308
  let errStatusCode = (Model.settings || {}).aclErrorStatus || app.get("aclErrorStatus") || 401;
294
- if (!req.accessToken) errStatusCode = 401;
309
+ if (!app.isRequestAuthenticated(ctx)) errStatusCode = 401;
295
310
  if (Model.checkAccess) utils.invokeWithCallback(Model.checkAccess, Model, [
296
311
  req.accessToken,
297
312
  modelId,
@@ -39,6 +39,34 @@ var require_model = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, mod
39
39
  }
40
40
  completeSyncRemoteHook(retval, next);
41
41
  }
42
+ function runListeners(listeners, ctx, next) {
43
+ const stack = [].concat(listeners || []);
44
+ let index = 0;
45
+ function run(err) {
46
+ if (err || index >= stack.length) {
47
+ next(err);
48
+ return;
49
+ }
50
+ const listener = stack[index++];
51
+ let completed = false;
52
+ const advance = function(advanceErr) {
53
+ if (completed) return;
54
+ completed = true;
55
+ run(advanceErr);
56
+ };
57
+ try {
58
+ const result = listener.call(null, ctx, advance);
59
+ if (result && typeof result.then === "function") result.then(function() {
60
+ advance();
61
+ }, function(promiseErr) {
62
+ advance(promiseErr);
63
+ });
64
+ } catch (err) {
65
+ advance(err);
66
+ }
67
+ }
68
+ run();
69
+ }
42
70
  module.exports = function(registry) {
43
71
  /**
44
72
  * The base class for **all models**.
@@ -999,10 +1027,10 @@ var require_model = /* @__PURE__ */ require_runtime.__commonJSMin(((exports, mod
999
1027
  const after = method.isStatic ? afterListeners : afterListeners["prototype"];
1000
1028
  const m = method.isStatic ? method.name : "prototype." + method.name;
1001
1029
  if (before && before[delegateTo.name]) self.beforeRemote(m, function(ctx, result, next) {
1002
- before[delegateTo.name]._listeners.call(null, ctx, next);
1030
+ runListeners(before[delegateTo.name]._listeners, ctx, next);
1003
1031
  });
1004
1032
  if (after && after[delegateTo.name]) self.afterRemote(m, function(ctx, result, next) {
1005
- after[delegateTo.name]._listeners.call(null, ctx, next);
1033
+ runListeners(after[delegateTo.name]._listeners, ctx, next);
1006
1034
  });
1007
1035
  }
1008
1036
  });
package/dist/package.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  var require_package = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.cjs").__commonJSMin(((exports, module) => {
3
3
  module.exports = {
4
4
  "name": "@vsaas/loopback",
5
- "version": "12.2.4",
5
+ "version": "12.3.0",
6
6
  "description": "Fork of LoopBack 3 framework for building APIs and microservices in Node.js",
7
7
  "keywords": [
8
8
  "StrongLoop",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vsaas/loopback",
3
- "version": "12.2.4",
3
+ "version": "12.3.0",
4
4
  "description": "Fork of LoopBack 3 framework for building APIs and microservices in Node.js",
5
5
  "keywords": [
6
6
  "StrongLoop",
@@ -104,9 +104,9 @@
104
104
  "nodemailer": "^9.0.5",
105
105
  "otplib": "13.4.1",
106
106
  "serve-favicon": "^2.5.1",
107
+ "@vsaas/loopback-datasource-juggler": "^13.0.1",
107
108
  "@vsaas/remoting": "^13.0.1",
108
- "@vsaas/loopback-connector-remote": "^12.0.2",
109
- "@vsaas/loopback-datasource-juggler": "^13.0.0"
109
+ "@vsaas/loopback-connector-remote": "^12.0.2"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@types/node": "25.5.0",
@@ -124,8 +124,8 @@
124
124
  "tsdown": "0.22.14",
125
125
  "typescript": "6.0.2",
126
126
  "vitest": "4.1.11",
127
- "@vsaas/error-handler": "^12.0.1",
128
- "@vsaas/loopback-boot": "^12.0.2"
127
+ "@vsaas/loopback-boot": "^12.0.2",
128
+ "@vsaas/error-handler": "^12.0.1"
129
129
  },
130
130
  "engines": {
131
131
  "node": ">=24"