-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap.js
161 lines (148 loc) · 4.5 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const { writeFile } = require("fs").promises;
const Ceramic = require("@ceramicnetwork/http-client").default;
const { createDefinition, publishSchema } = require("@ceramicstudio/idx-tools");
const { Ed25519Provider } = require("key-did-provider-ed25519");
const fromString = require("uint8arrays/from-string");
const CERAMIC_URL =
"https://ceramic-clay.3boxlabs.com" || "http://localhost:7007";
const ActivityStreamSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
title: "ActivityStreamObject",
description: "ActivityStream object",
type: "object",
properties: {
"@context": {
type: "string",
default: "https://www.w3.org/ns/activitystreams#Object",
},
type: {
type: "string",
enum: ["Object", "Link", "Activity", "Note", "Page", "Article"],
default: "Article",
title: "Type",
},
id: { type: "string" },
name: { type: "string", title: "Name" },
content: { type: "string", title: "Content" },
context: { type: "string" },
published: { type: "string" },
updated: { type: "string" },
partOf: { type: "string" },
mediaType: {
type: "string",
title: "Media type",
enum: ["text/markdown"],
default: "text/markdown",
},
},
required: ["type"],
};
const FeedSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
title: "Feed",
type: "object",
properties: {
feed: {
type: "array",
title: "items",
items: {
type: "string",
title: "FeedItem",
pattern: "^ceramic://.+(\\\\?version=.+)?",
maxLength: 150,
},
},
},
};
const FollowingSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
title: "Following",
type: "object",
properties: {
following: {
type: "array",
title: "dids",
dids: {
type: "string",
title: "DID",
pattern: "^ceramic://.+(\\\\?version=.+)?",
maxLength: 150,
},
},
},
};
async function run() {
// The seed must be provided as an environment variable
const seed = fromString(process.env.SEED, "base16");
// Connect to the local Ceramic node
//const ceramic = new Ceramic("https://gateway-clay.ceramic.network")
//const ceramic = new Ceramic("https://ceramic-clay.3boxlabs.com")
const ceramic = new Ceramic(CERAMIC_URL);
// Authenticate the Ceramic instance with the provider
await ceramic.setDIDProvider(new Ed25519Provider(seed));
// Publish the two schemas
// const [
// activityStreamSchema,
// feedSchema,
// followingSchema,
// ] = await Promise.all([
// publishSchema(ceramic, { content: ActivityStreamSchema }),
// publishSchema(ceramic, { content: FeedSchema }),
// publishSchema(ceramic, { content: FollowingSchema }),
// ]);
/*
// Create the definition using the created schema ID
const feedDefinition = await createDefinition(ceramic, {
name: "feed",
description: "Feed",
schema: feedSchema.commitId.toUrl(),
});
const followingDefinition = await createDefinition(ceramic, {
name: "following",
description: "Following",
schema: followingSchema.commitId.toUrl(),
});
*/
const schemas = await Promise.all(
[ActivityStreamSchema].map(async (content) => {
const schema = await publishSchema(ceramic, { content });
return {
key: content.title,
value: schema.commitId.toUrl(),
};
})
);
// Definitions
const definitions = await Promise.all(
[FeedSchema, FollowingSchema].map(async (content) => {
const schema = await publishSchema(ceramic, { content });
const def = await createDefinition(ceramic, {
name: content.title.toLowerCase(),
description: content.title,
schema: schema.commitId.toUrl(),
});
return {
key: content.title.toLowerCase(),
value: def.id.toString(),
};
})
);
// Write config to JSON file
const keyValue = (obj, { key, value }) => ({ ...obj, [key]: value });
const config = {
definitions: definitions.reduce(keyValue, {}),
schemas: schemas.reduce(keyValue, {}),
// definitions: {
// feed: feedDefinition.id.toString(),
// following: followingDefinition.id.toString(),
// },
// schemas: {
// ActivityStream: activityStreamSchema.commitId.toUrl(),
// ActivityCollection: feedSchema.commitId.toUrl(),
// },
};
await writeFile("./src/config.json", JSON.stringify(config));
console.log("Config written to src/config.json file:", config);
process.exit(0);
}
run().catch(console.error);