Skip to content

Commit

Permalink
validate playground inputs via validate scopes (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniscruff authored Dec 15, 2024
1 parent d7f61a4 commit d0b4e7c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docs/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Try out scopes and rules in scopie to determine if the actor would be allowed to
<textarea class="md-typeset" id="action-scopes-input" rows="5" cols="42" wrap="off">
blog/create
</textarea>
<div id="action-scopes-error"></div>
<div id="action-scopes-error">Valid</div>

## Actor Rules

<textarea class="md-typeset" id="actor-rules-input" rows="5" cols="42" wrap="off">
allow/blog/create|update
allow/accounts/read
</textarea>
<div id="actor-rules-error"></div>
<div id="actor-rules-error">Valid</div>

## Result
<div id="is-allowed">Is Allowed</div>
Expand Down
17 changes: 5 additions & 12 deletions docs/static/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
window.addEventListener("load", async function() {
console.log("scopie playground initializing")

window.scopie = await import("/static/scopie.browser.min.js");
window.scopie = await import("/static/scopie.browser.min.v0.3.0.js");

window.actionScopesInput = document.getElementById("action-scopes-input");
window.actionScopesError = document.getElementById("action-scopes-error");
Expand All @@ -15,7 +15,7 @@ window.addEventListener("load", async function() {

window.updateAllowedState = function() {
try {
window.isAllowedDisplay.textContent = scopie.isAllowed(
window.isAllowedDisplay.textContent = window.scopie.isAllowed(
window.actionScopesInput.value.trim().split('\n'),
window.actorRulesInput.value.trim().split('\n'),
) ? "Is Allowed" : "Is Not Allowed"
Expand All @@ -24,25 +24,18 @@ window.addEventListener("load", async function() {
}
}

/*
window.actionScopesInput.addEventListener("keyup", function() {
console.log(window.actionScopesInput.value.trim().split('\n'))
const e = scopie.validateScope(window.actionScopesInput.value.trim().split('\n'))
console.log('e', e)
const e = window.scopie.validateScopes(window.actionScopesInput.value.trim().split('\n'))
window.actionValid = e === undefined;
window.actionScopesError.textContent = window.actionValid ? "Valid" : e.toString()
window.updateAllowedState();
});
window.actorRulesInput.addEventListener("keyup", function() {
console.log(window.actorRulesInput.value.trim().split('\n'))
console.log('e', e)
const e = scopie.validateScope(window.actorRulesInput.value.trim().split('\n'))
const e = window.scopie.validateScopes(window.actorRulesInput.value.trim().split('\n'))
window.actorValid = e === undefined;
window.actorRulesError.textContent = window.actorValid ? "Valid" : e.toString();
window.updateAllowedState();
});
*/

window.actionScopesInput.addEventListener("keyup", window.updateAllowedState)
window.actorRulesInput.addEventListener("keyup", window.updateAllowedState)
window.updateAllowedState()
})
2 changes: 0 additions & 2 deletions docs/static/scopie.browser.min.js

This file was deleted.

7 changes: 0 additions & 7 deletions docs/static/scopie.browser.min.js.map

This file was deleted.

Loading

0 comments on commit d0b4e7c

Please sign in to comment.