Skip to content

Commit fdee9c4

Browse files
committed
feat: maxe policies container if it does not exist yet
1 parent 61d1ff7 commit fdee9c4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

demo/flow.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ async function main() {
9999
const purpose = 'age-verification'
100100
const policy = demoPolicy(terms.views.age, terms.agents.vendor, { startDate, endDate, purpose })
101101

102+
// create container if it does not exist yet
103+
await initContainer(policyContainer)
102104
const policyCreationResponse = await fetch(policyContainer, {
103105
method: 'POST',
104106
headers: { 'content-type': 'text/turtle' },
@@ -146,3 +148,17 @@ function log(msg: string, obj?: any) {
146148
console.log(obj);
147149
}
148150
}
151+
152+
// creates the container if it does not exist yet (only when access is there)
153+
async function initContainer(policyContainer: string): Promise<void> {
154+
const res = await fetch(policyContainer)
155+
if (res.status === 404) {
156+
const res = await fetch(policyContainer, {
157+
method: 'PUT'
158+
})
159+
if (res.status !== 201) {
160+
log('Creating container at ' + policyContainer + ' not successful'); throw 0;
161+
}
162+
}
163+
}
164+

0 commit comments

Comments
 (0)