Skip to content

Commit f7e0662

Browse files
committed
getting started with Vault
1 parent 9314bd0 commit f7e0662

3 files changed

Lines changed: 197 additions & 1 deletion

File tree

classes/Manifest/Manifest.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Vault } from "@hyperion-framework/vault"
2+
3+
const vault = new Vault()
4+
5+
class Manifest {
6+
7+
manifest = null
8+
uri = null
9+
10+
constructor(manifestOrUri) {
11+
12+
if (typeof manifestOrUri !== 'string' && typeof manifestOrUri !== 'object') {
13+
throw new Error('Invalid input: must be a manifest object or a URI string')
14+
}
15+
let id = manifestOrUri['@id'] ?? manifestOrUri.id ?? manifestOrUri
16+
17+
if (!id) {
18+
throw new Error('Invalid input: manifest object must have an @id or id property')
19+
}
20+
21+
try {
22+
new URL(id);
23+
this.uri = id;
24+
} catch (_) {
25+
throw new Error('Invalid input: must be a valid URI string');
26+
}
27+
28+
const requiredProperties = [
29+
['@type', 'type'],
30+
['@context', 'context'],
31+
['sequences', 'items']
32+
]
33+
34+
try {
35+
for (const [prop1, prop2] of requiredProperties) {
36+
if (!manifestOrUri[prop1] && !manifestOrUri[prop2]) {
37+
throw new Error(`Invalid input: manifest object must have either ${prop1} or ${prop2} property`)
38+
}
39+
}
40+
} catch (err) {
41+
console.warn(err, Object.keys(manifestOrUri))
42+
return
43+
}
44+
45+
this.manifest = manifestOrUri
46+
}
47+
48+
load = async () => vault.loadManifest(this.uri)
49+
}
50+
51+
export default Manifest

package-lock.json

Lines changed: 145 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"inviteMemberTests": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t inviteMemberTests "
3434
},
3535
"dependencies": {
36+
"@hyperion-framework/vault": "^2.0.0-alpha.0",
3637
"cookie-parser": "^1.4.7",
3738
"cors": "^2.8.5",
3839
"debug": "^4.4.0",

0 commit comments

Comments
 (0)