feathers-ucan 0.1.42 → 0.1.44

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.
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.42";
1
+ export declare const VERSION = "0.1.44";
package/lib/index.cjs CHANGED
@@ -955,12 +955,14 @@ const checkUcan = (requiredCapabilities, options) => {
955
955
  } = options || {
956
956
  loginPass: [[['*'], ['nonExistentMethod']]]
957
957
  };
958
+ if (options != null && options.log) console.log('loginPass precheck', loginPass);
958
959
  if (loginPass != null && loginPass.length) {
959
960
  //object of scrubbed data object for pass that includes only limited access or full context.data object if no limits were present
960
961
  let scrubbedData = {};
961
962
  //scruData defaults to true - is only set to false
962
963
  let scrubData = true;
963
964
  const checkLoginPass = async lpass => {
965
+ if (options != null && options.log) console.log('checkLoginPass', lpass);
964
966
  let methodsOnly = [];
965
967
  const allMethods = lpass[1] === '*';
966
968
  let methodIdx = -1;
@@ -979,7 +981,7 @@ const checkUcan = (requiredCapabilities, options) => {
979
981
  /** function for comparing record login id with context login*/
980
982
  const checkLogin = (recordLoginPassId, loginIdPath = '_id') => {
981
983
  const loginCheckId = symbolUcan._get(context.params, `${configuration.entity}.${loginIdPath}`);
982
- if (options != null && options.log) console.log('checkLoginPass', loginCheckId, recordLoginPassId);
984
+ if (options != null && options.log) console.log('checkLogin', loginCheckId, recordLoginPassId);
983
985
  /**Make sure both are present to avoid pass on undefined*/
984
986
  if (loginCheckId && recordLoginPassId) {
985
987
  /** change login path result to array no matter what */
@@ -990,7 +992,11 @@ const checkUcan = (requiredCapabilities, options) => {
990
992
  const checkId = String(checkArr[i]);
991
993
  for (let rl = 0; rl < recordLoginPassId.length;) {
992
994
  const rlId = String(recordLoginPassId[rl]);
993
- if (rlId === checkId) loginOk = true;else rl++;
995
+ if (rlId === checkId) {
996
+ // Found a matching login id; mark success and break out of the inner loop
997
+ loginOk = true;
998
+ break;
999
+ } else rl++;
994
1000
  }
995
1001
  if (loginOk) return;
996
1002
  }
@@ -1003,6 +1009,7 @@ const checkUcan = (requiredCapabilities, options) => {
1003
1009
  context = setExists(context, existing);
1004
1010
  /**perform the check*/
1005
1011
  const idArr = Array.isArray(lpass[2]) ? lpass[2] : lpass[0] || [];
1012
+ if (options != null && options.log) console.log('loginPass: id paths to check', idArr);
1006
1013
  for (const passPath of idArr || []) {
1007
1014
  const spl = String(passPath).split('/');
1008
1015
  if (spl[0].includes('*')) {
@@ -1025,6 +1032,11 @@ const checkUcan = (requiredCapabilities, options) => {
1025
1032
  }
1026
1033
  } else checkLogin(symbolUcan._get(existing, spl[0]), spl[1] || '_id');
1027
1034
  }
1035
+ } else {
1036
+ if (options != null && options.log) console.log('loginPass: no existing record loaded; skipping checkLogin', {
1037
+ method: context.method,
1038
+ path: context.path
1039
+ });
1028
1040
  }
1029
1041
  if (loginOk) {
1030
1042
  v.ok = true;