Skip to content

Commit

Permalink
feat: maxe policies container if it does not exist yet
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslabbinck committed Mar 15, 2024
1 parent 61d1ff7 commit fdee9c4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions demo/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ async function main() {
const purpose = 'age-verification'
const policy = demoPolicy(terms.views.age, terms.agents.vendor, { startDate, endDate, purpose })

// create container if it does not exist yet
await initContainer(policyContainer)
const policyCreationResponse = await fetch(policyContainer, {
method: 'POST',
headers: { 'content-type': 'text/turtle' },
Expand Down Expand Up @@ -146,3 +148,17 @@ function log(msg: string, obj?: any) {
console.log(obj);
}
}

// creates the container if it does not exist yet (only when access is there)
async function initContainer(policyContainer: string): Promise<void> {
const res = await fetch(policyContainer)
if (res.status === 404) {
const res = await fetch(policyContainer, {
method: 'PUT'
})
if (res.status !== 201) {
log('Creating container at ' + policyContainer + ' not successful'); throw 0;
}
}
}

0 comments on commit fdee9c4

Please sign in to comment.