@authup/access 1.0.0-beta.63 → 1.0.0-beta.65

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/dist/index.mjs CHANGED
@@ -199,13 +199,10 @@ function aggregatePermissionPolicyBindings(input) {
199
199
  return previous;
200
200
  }, {});
201
201
  const output = [];
202
- for (const key of Object.keys(grouped)) {
203
- const group = grouped[key];
204
- output.push({
205
- permission: group[0].permission,
206
- grants: group.map(buildGrant)
207
- });
208
- }
202
+ for (const group of Object.values(grouped)) output.push({
203
+ permission: group[0].permission,
204
+ grants: group.map(buildGrant)
205
+ });
209
206
  return output;
210
207
  }
211
208
  //#endregion
@@ -252,9 +249,8 @@ const NON_SEMANTIC_POLICY_KEYS = /* @__PURE__ */ new Set([
252
249
  */
253
250
  function normalizePolicyForEquality(policy) {
254
251
  const result = {};
255
- for (const key of Object.keys(policy)) {
252
+ for (const [key, value] of Object.entries(policy)) {
256
253
  if (NON_SEMANTIC_POLICY_KEYS.has(key)) continue;
257
- const value = policy[key];
258
254
  if (key === "children" && Array.isArray(value)) {
259
255
  result[key] = value.map((child) => normalizePolicyForEquality(child));
260
256
  continue;
@@ -847,7 +843,7 @@ var CompositePolicyEvaluator = class {
847
843
  }
848
844
  if (settled === null) {
849
845
  let condition = null;
850
- if (ctx.withConditions && pendingWithoutCondition === 0 && pendingConditions.length > 0 && decisionStrategy !== DecisionStrategy.CONSENSUS) {
846
+ if (pendingWithoutCondition === 0 && ctx.withConditions && pendingConditions.length > 0 && decisionStrategy !== DecisionStrategy.CONSENSUS) {
851
847
  if (pendingConditions.length === 1) {
852
848
  const [first] = pendingConditions;
853
849
  condition = first ?? null;
@@ -907,13 +903,14 @@ var DatePolicyEvaluator = class {
907
903
  async evaluate(value, ctx) {
908
904
  const policy = await this.validator.run(value);
909
905
  let now;
910
- if (ctx.data.has("date")) if (ctx.data.isValidated("date")) now = ctx.data.get("date");
911
- else {
912
- now = normalizeDate$1(toDate$1(ctx.data.get("date")));
913
- ctx.data.set("date", now);
914
- ctx.data.setValidated("date");
915
- }
916
- else now = normalizeDate$1(/* @__PURE__ */ new Date());
906
+ if (ctx.data.has("date")) {
907
+ if (ctx.data.isValidated("date")) now = ctx.data.get("date");
908
+ else {
909
+ now = normalizeDate$1(toDate$1(ctx.data.get("date")));
910
+ ctx.data.set("date", now);
911
+ ctx.data.setValidated("date");
912
+ }
913
+ } else now = normalizeDate$1(/* @__PURE__ */ new Date());
917
914
  if (policy.start) {
918
915
  const start = normalizeDate$1(toDate$1(policy.start));
919
916
  if (now < start) return { success: maybeInvertPolicyOutcome(false, policy.invert) };
@@ -1064,7 +1061,7 @@ var RealmMatchPolicyEvaluator = class {
1064
1061
  if (scope === "any") condition = nin(field, []);
1065
1062
  else {
1066
1063
  const terms = [];
1067
- if (scope !== "none" && realmId !== null) terms.push(eq(field, realmId));
1064
+ if (realmId !== null && scope !== "none") terms.push(eq(field, realmId));
1068
1065
  if (scope === "ownOrNull") terms.push(eq(field, null));
1069
1066
  if (terms.length === 0) condition = inArray(field, []);
1070
1067
  else if (terms.length === 1) condition = terms[0];
@@ -1118,9 +1115,10 @@ var RealmMatchPolicyEvaluator = class {
1118
1115
  })]
1119
1116
  };
1120
1117
  let keys;
1121
- if (policy.attributeName) if (Array.isArray(policy.attributeName)) keys = policy.attributeName;
1122
- else keys = [policy.attributeName];
1123
- else {
1118
+ if (policy.attributeName) {
1119
+ if (Array.isArray(policy.attributeName)) keys = policy.attributeName;
1120
+ else keys = [policy.attributeName];
1121
+ } else {
1124
1122
  keys = [
1125
1123
  "realm_id",
1126
1124
  "realm_name",
@@ -1149,8 +1147,7 @@ var RealmMatchPolicyEvaluator = class {
1149
1147
  evaluated = true;
1150
1148
  let outcome = false;
1151
1149
  const attributeValue = attributes[key];
1152
- if (attributeValue === null && policy.attributeNullMatchAll) outcome = true;
1153
- else if (attributeValue === identity.realmId || attributeValue === identity.realmName) outcome = true;
1150
+ if (attributeValue === null && policy.attributeNullMatchAll || attributeValue === identity.realmId || attributeValue === identity.realmName) outcome = true;
1154
1151
  if (outcome) {
1155
1152
  if (policy.decisionStrategy === DecisionStrategy.AFFIRMATIVE) return { success: maybeInvertPolicyOutcome(true, policy.invert) };
1156
1153
  count++;
@@ -1231,13 +1228,14 @@ var TimePolicyEvaluator = class {
1231
1228
  async evaluate(value, ctx) {
1232
1229
  const policy = await this.validator.run(value);
1233
1230
  let now;
1234
- if (ctx.data.has("time")) if (ctx.data.isValidated("time")) now = ctx.data.get("time");
1235
- else {
1236
- now = toDate(ctx.data.get("time"));
1237
- ctx.data.set("time", now);
1238
- ctx.data.setValidated("time");
1239
- }
1240
- else now = /* @__PURE__ */ new Date();
1231
+ if (ctx.data.has("time")) {
1232
+ if (ctx.data.isValidated("time")) now = ctx.data.get("time");
1233
+ else {
1234
+ now = toDate(ctx.data.get("time"));
1235
+ ctx.data.set("time", now);
1236
+ ctx.data.setValidated("time");
1237
+ }
1238
+ } else now = /* @__PURE__ */ new Date();
1241
1239
  if (policy.start) {
1242
1240
  const start = normalizeDate(toDate(policy.start, now), now);
1243
1241
  if (now < start) return { success: maybeInvertPolicyOutcome(false, policy.invert) };
@@ -1440,8 +1438,10 @@ var PermissionEvaluator = class {
1440
1438
  withConditions: true
1441
1439
  }));
1442
1440
  if (evaluationResult.success) return { verdict: "allow" };
1443
- if (evaluationResult.pending) if (evaluationResult.condition) conditions.push(evaluationResult.condition);
1444
- else post = true;
1441
+ if (evaluationResult.pending) {
1442
+ if (evaluationResult.condition) conditions.push(evaluationResult.condition);
1443
+ else post = true;
1444
+ }
1445
1445
  }
1446
1446
  if (post) return { verdict: "post" };
1447
1447
  if (conditions.length === 0) return { verdict: "deny" };