@anticeil/sdk 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +170 -73
- package/dist/index.d.ts +170 -73
- package/dist/index.js +190 -117
- package/dist/index.mjs +190 -117
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -34,17 +34,14 @@ var AnticeilClient = class {
|
|
|
34
34
|
this.config = {
|
|
35
35
|
token: config.token || "",
|
|
36
36
|
apiKey: config.apiKey || "",
|
|
37
|
-
baseUrl: config.baseUrl || "https://app.anticeil.com",
|
|
38
|
-
socketUrl: config.socketUrl || "https://app.anticeil.com",
|
|
37
|
+
baseUrl: (config.baseUrl || "https://app.anticeil.com").replace(/\/+$/, ""),
|
|
38
|
+
socketUrl: (config.socketUrl || config.baseUrl || "https://app.anticeil.com").replace(/\/+$/, ""),
|
|
39
39
|
autoConnect: config.autoConnect ?? false
|
|
40
40
|
};
|
|
41
41
|
if (this.config.autoConnect) {
|
|
42
42
|
this.connect();
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Connect to the Anticeil WebSocket real-time gateway
|
|
47
|
-
*/
|
|
48
45
|
connect() {
|
|
49
46
|
if (this.socket?.connected) return;
|
|
50
47
|
this.socket = (0, import_socket.io)(this.config.socketUrl, {
|
|
@@ -83,18 +80,12 @@ var AnticeilClient = class {
|
|
|
83
80
|
this.emitInternal("presence", data);
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Disconnect from the WebSocket real-time gateway
|
|
88
|
-
*/
|
|
89
83
|
disconnect() {
|
|
90
84
|
if (this.socket) {
|
|
91
85
|
this.socket.disconnect();
|
|
92
86
|
this.socket = null;
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Register an event listener (e.g. 'message', 'typing', 'connect', 'disconnect')
|
|
97
|
-
*/
|
|
98
89
|
on(event, handler) {
|
|
99
90
|
if (!this.eventHandlers.has(event)) {
|
|
100
91
|
this.eventHandlers.set(event, /* @__PURE__ */ new Set());
|
|
@@ -102,9 +93,6 @@ var AnticeilClient = class {
|
|
|
102
93
|
this.eventHandlers.get(event).add(handler);
|
|
103
94
|
return this;
|
|
104
95
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Remove an event listener
|
|
107
|
-
*/
|
|
108
96
|
off(event, handler) {
|
|
109
97
|
this.eventHandlers.get(event)?.delete(handler);
|
|
110
98
|
return this;
|
|
@@ -118,32 +106,81 @@ var AnticeilClient = class {
|
|
|
118
106
|
}
|
|
119
107
|
});
|
|
120
108
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Internal REST fetch helper
|
|
123
|
-
*/
|
|
124
109
|
async request(endpoint, options = {}) {
|
|
125
|
-
const
|
|
110
|
+
const path = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
111
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
126
112
|
const headers = new Headers(options.headers);
|
|
127
113
|
if (this.config.token) {
|
|
128
114
|
headers.set("Authorization", `Bearer ${this.config.token}`);
|
|
129
115
|
} else if (this.config.apiKey) {
|
|
116
|
+
headers.set("Authorization", `Bearer ${this.config.apiKey}`);
|
|
130
117
|
headers.set("X-Anticeil-Api-Key", this.config.apiKey);
|
|
131
118
|
}
|
|
132
|
-
headers.
|
|
119
|
+
if (!headers.has("Content-Type")) {
|
|
120
|
+
headers.set("Content-Type", "application/json");
|
|
121
|
+
}
|
|
133
122
|
const res = await fetch(url, { ...options, headers });
|
|
134
123
|
if (!res.ok) {
|
|
135
124
|
const errorText = await res.text().catch(() => res.statusText);
|
|
136
|
-
throw new Error(`Anticeil API Error [${res.status}]: ${errorText}`);
|
|
125
|
+
throw new Error(`Anticeil API Error [${res.status}] ${path}: ${errorText}`);
|
|
126
|
+
}
|
|
127
|
+
const text = await res.text();
|
|
128
|
+
if (!text) return {};
|
|
129
|
+
try {
|
|
130
|
+
return JSON.parse(text);
|
|
131
|
+
} catch {
|
|
132
|
+
return text;
|
|
137
133
|
}
|
|
138
|
-
return res.json();
|
|
139
134
|
}
|
|
140
135
|
// ==========================================
|
|
141
|
-
//
|
|
136
|
+
// 1. COLONIES API
|
|
137
|
+
// ==========================================
|
|
138
|
+
colonies = {
|
|
139
|
+
list: async () => this.request("/api/colonies"),
|
|
140
|
+
get: async (colonyId) => this.request(`/api/colonies/${colonyId}`),
|
|
141
|
+
create: async (data) => this.request("/api/v1/community/hubs", {
|
|
142
|
+
method: "POST",
|
|
143
|
+
body: JSON.stringify(data)
|
|
144
|
+
}),
|
|
145
|
+
update: async (colonyId, updates) => this.request(`/api/colonies/${colonyId}`, {
|
|
146
|
+
method: "PATCH",
|
|
147
|
+
body: JSON.stringify(updates)
|
|
148
|
+
}),
|
|
149
|
+
delete: async (colonyId) => this.request(`/api/v1/community/hubs/${colonyId}`, {
|
|
150
|
+
method: "DELETE"
|
|
151
|
+
}),
|
|
152
|
+
setPrivacy: async (colonyId, joinMethod, options = {}) => this.request(`/api/colonies/${colonyId}/access`, {
|
|
153
|
+
method: "PUT",
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
joinMethod,
|
|
156
|
+
visibility: joinMethod === "discoverable" ? "public" : "private",
|
|
157
|
+
...options
|
|
158
|
+
})
|
|
159
|
+
}),
|
|
160
|
+
getInsights: async (colonyId) => this.request(`/api/v1/colonies/${colonyId}/insights`)
|
|
161
|
+
};
|
|
162
|
+
// ==========================================
|
|
163
|
+
// 2. CHANNELS API
|
|
164
|
+
// ==========================================
|
|
165
|
+
channels = {
|
|
166
|
+
get: async (channelId) => this.request(`/api/channels/${channelId}`),
|
|
167
|
+
list: async (colonyId) => this.request(`/api/colonies/${colonyId}/channels`),
|
|
168
|
+
create: async (colonyId, data) => this.request(`/api/colonies/${colonyId}/channels`, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
body: JSON.stringify(data)
|
|
171
|
+
}),
|
|
172
|
+
update: async (channelId, updates) => this.request(`/api/v1/community/channels/${channelId}`, {
|
|
173
|
+
method: "PUT",
|
|
174
|
+
body: JSON.stringify(updates)
|
|
175
|
+
}),
|
|
176
|
+
delete: async (channelId) => this.request(`/api/v1/community/channels/${channelId}`, {
|
|
177
|
+
method: "DELETE"
|
|
178
|
+
})
|
|
179
|
+
};
|
|
180
|
+
// ==========================================
|
|
181
|
+
// 3. MESSAGES & REACTIONS API
|
|
142
182
|
// ==========================================
|
|
143
183
|
messages = {
|
|
144
|
-
/**
|
|
145
|
-
* Send a text message to a channel
|
|
146
|
-
*/
|
|
147
184
|
send: async (channelId, options) => {
|
|
148
185
|
const payload = typeof options === "string" ? { content: options } : options;
|
|
149
186
|
if (this.socket?.connected) {
|
|
@@ -154,112 +191,118 @@ var AnticeilClient = class {
|
|
|
154
191
|
body: JSON.stringify(payload)
|
|
155
192
|
});
|
|
156
193
|
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
170
|
-
}
|
|
194
|
+
list: async (channelId, limit = 50) => this.request(`/api/channels/${channelId}/messages?limit=${limit}`),
|
|
195
|
+
delete: async (channelId, messageId) => this.request(`/api/channels/${channelId}/messages/${messageId}`, {
|
|
196
|
+
method: "DELETE"
|
|
197
|
+
}),
|
|
198
|
+
toggleReaction: async (messageId, emoji) => this.request(`/api/v1/community/messages/${messageId}/reactions`, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
body: JSON.stringify({ emoji })
|
|
201
|
+
}),
|
|
202
|
+
togglePin: async (messageId, channelId) => this.request(`/api/v1/community/messages/${messageId}/pin`, {
|
|
203
|
+
method: "POST",
|
|
204
|
+
body: JSON.stringify({ channelId })
|
|
205
|
+
})
|
|
171
206
|
};
|
|
172
207
|
// ==========================================
|
|
173
|
-
//
|
|
208
|
+
// 4. THREADS API
|
|
174
209
|
// ==========================================
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
},
|
|
182
|
-
/**
|
|
183
|
-
* List all channels within a colony
|
|
184
|
-
*/
|
|
185
|
-
list: async (colonyId) => {
|
|
186
|
-
return this.request(`/api/colonies/${colonyId}/channels`);
|
|
187
|
-
},
|
|
188
|
-
/**
|
|
189
|
-
* Create a new channel
|
|
190
|
-
*/
|
|
191
|
-
create: async (colonyId, data) => {
|
|
192
|
-
return this.request(`/api/colonies/${colonyId}/channels`, {
|
|
193
|
-
method: "POST",
|
|
194
|
-
body: JSON.stringify(data)
|
|
195
|
-
});
|
|
196
|
-
}
|
|
210
|
+
threads = {
|
|
211
|
+
list: async (channelId) => this.request(`/api/v1/community/channels/${channelId}/threads`),
|
|
212
|
+
create: async (channelId, data) => this.request(`/api/v1/community/channels/${channelId}/threads`, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
body: JSON.stringify(data)
|
|
215
|
+
})
|
|
197
216
|
};
|
|
198
217
|
// ==========================================
|
|
199
|
-
//
|
|
218
|
+
// 5. FRIENDS & MESSAGE REQUESTS API
|
|
200
219
|
// ==========================================
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
friends = {
|
|
221
|
+
list: async () => this.request("/api/v1/community/friends"),
|
|
222
|
+
sendRequest: async (target) => this.request("/api/v1/community/friends/request", {
|
|
223
|
+
method: "POST",
|
|
224
|
+
body: JSON.stringify({ username: target, target })
|
|
225
|
+
}),
|
|
226
|
+
listMessageRequests: async () => this.request("/api/v1/community/message-requests"),
|
|
227
|
+
respondMessageRequest: async (requestId, action) => this.request(`/api/v1/community/message-requests/${requestId}/${action}`, {
|
|
228
|
+
method: "POST",
|
|
229
|
+
body: JSON.stringify({})
|
|
230
|
+
})
|
|
231
|
+
};
|
|
232
|
+
// ==========================================
|
|
233
|
+
// 6. MEMBERS, ROLES & MODERATION API
|
|
234
|
+
// ==========================================
|
|
235
|
+
members = {
|
|
236
|
+
list: async (colonyId) => this.request(
|
|
237
|
+
colonyId ? `/api/v1/community/members?colonyId=${encodeURIComponent(colonyId)}` : "/api/v1/community/members"
|
|
238
|
+
),
|
|
239
|
+
listRoles: async (colonyId) => this.request(`/api/v1/community/hubs/${colonyId}/roles`),
|
|
240
|
+
updateRole: async (colonyId, userId, roleId) => this.request(`/api/v1/community/hubs/${colonyId}/members/${userId}/role`, {
|
|
241
|
+
method: "PUT",
|
|
242
|
+
body: JSON.stringify({ roleId })
|
|
243
|
+
}),
|
|
244
|
+
ban: async (colonyId, userId, reason) => this.request(`/api/v1/colonies/${colonyId}/bans`, {
|
|
245
|
+
method: "POST",
|
|
246
|
+
body: JSON.stringify({ userId, reason })
|
|
247
|
+
}),
|
|
248
|
+
unban: async (colonyId, userId) => this.request(`/api/v1/colonies/${colonyId}/bans/${userId}`, {
|
|
249
|
+
method: "DELETE"
|
|
250
|
+
}),
|
|
251
|
+
getAuditLogs: async (colonyId) => this.request(`/api/v1/colonies/${colonyId}/audit-logs`)
|
|
252
|
+
};
|
|
253
|
+
// ==========================================
|
|
254
|
+
// 7. TASKS / KANBAN ASSIGNMENTS API
|
|
255
|
+
// ==========================================
|
|
256
|
+
tasks = {
|
|
257
|
+
list: async (filters) => {
|
|
258
|
+
const params = new URLSearchParams();
|
|
259
|
+
if (filters?.colonyId) params.set("colonyId", filters.colonyId);
|
|
260
|
+
if (filters?.channelId) params.set("channelId", filters.channelId);
|
|
261
|
+
const qs = params.toString();
|
|
262
|
+
return this.request(`/api/v1/community/assignments${qs ? `?${qs}` : ""}`);
|
|
222
263
|
},
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
}
|
|
264
|
+
create: async (data) => this.request("/api/v1/community/assignments", {
|
|
265
|
+
method: "POST",
|
|
266
|
+
body: JSON.stringify({ columnId: "todo", priority: "medium", ...data })
|
|
267
|
+
}),
|
|
268
|
+
update: async (taskId, updates) => this.request(`/api/v1/community/assignments/${taskId}`, {
|
|
269
|
+
method: "PUT",
|
|
270
|
+
body: JSON.stringify(updates)
|
|
271
|
+
}),
|
|
272
|
+
delete: async (taskId) => this.request(`/api/v1/community/assignments/${taskId}`, {
|
|
273
|
+
method: "DELETE"
|
|
274
|
+
})
|
|
236
275
|
};
|
|
237
276
|
// ==========================================
|
|
238
|
-
//
|
|
277
|
+
// 8. CALENDAR & COLONY EVENTS API
|
|
239
278
|
// ==========================================
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
279
|
+
events = {
|
|
280
|
+
list: async (colonyId) => this.request(
|
|
281
|
+
colonyId ? `/api/v1/community/calendar/events?colonyId=${encodeURIComponent(colonyId)}` : "/api/v1/community/calendar/events"
|
|
282
|
+
),
|
|
283
|
+
create: async (data) => this.request("/api/v1/community/calendar/events", {
|
|
284
|
+
method: "POST",
|
|
285
|
+
body: JSON.stringify(data)
|
|
286
|
+
}),
|
|
287
|
+
update: async (eventId, updates) => this.request(`/api/v1/community/calendar/events/${eventId}`, {
|
|
288
|
+
method: "PUT",
|
|
289
|
+
body: JSON.stringify(updates)
|
|
290
|
+
}),
|
|
291
|
+
delete: async (eventId) => this.request(`/api/v1/community/calendar/events/${eventId}`, {
|
|
292
|
+
method: "DELETE"
|
|
293
|
+
})
|
|
255
294
|
};
|
|
256
295
|
// ==========================================
|
|
257
|
-
// ACTIVITIES API
|
|
296
|
+
// 9. APPS, ACTIVITIES & QUESTS API
|
|
258
297
|
// ==========================================
|
|
298
|
+
apps = {
|
|
299
|
+
list: async () => this.request("/api/v1/community/activities/catalog"),
|
|
300
|
+
install: async (colonyId, appId) => this.request(`/api/v1/colonies/${colonyId}/apps/${appId}/install`, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
body: JSON.stringify({})
|
|
303
|
+
})
|
|
304
|
+
};
|
|
259
305
|
activities = {
|
|
260
|
-
/**
|
|
261
|
-
* Launch a voice activity (YouTube Watch Together, Chess, Whiteboard)
|
|
262
|
-
*/
|
|
263
306
|
launch: async (options) => {
|
|
264
307
|
if (this.socket?.connected) {
|
|
265
308
|
this.socket.emit("launch_activity", options);
|
|
@@ -273,6 +316,36 @@ var AnticeilClient = class {
|
|
|
273
316
|
);
|
|
274
317
|
}
|
|
275
318
|
};
|
|
319
|
+
quests = {
|
|
320
|
+
list: async () => this.request("/api/v1/community/quests"),
|
|
321
|
+
create: async (data) => this.request("/api/v1/community/quests", {
|
|
322
|
+
method: "POST",
|
|
323
|
+
body: JSON.stringify(data)
|
|
324
|
+
}),
|
|
325
|
+
update: async (questId, updates) => this.request(`/api/v1/community/quests/${questId}`, {
|
|
326
|
+
method: "PUT",
|
|
327
|
+
body: JSON.stringify(updates)
|
|
328
|
+
}),
|
|
329
|
+
delete: async (questId) => this.request(`/api/v1/community/quests/${questId}`, {
|
|
330
|
+
method: "DELETE"
|
|
331
|
+
})
|
|
332
|
+
};
|
|
333
|
+
// ==========================================
|
|
334
|
+
// 10. WEBHOOKS API
|
|
335
|
+
// ==========================================
|
|
336
|
+
webhooks = {
|
|
337
|
+
send: async (webhookUrl, payload) => {
|
|
338
|
+
const res = await fetch(webhookUrl, {
|
|
339
|
+
method: "POST",
|
|
340
|
+
headers: { "Content-Type": "application/json" },
|
|
341
|
+
body: JSON.stringify(payload)
|
|
342
|
+
});
|
|
343
|
+
if (!res.ok) {
|
|
344
|
+
throw new Error(`Webhook Error [${res.status}]: ${await res.text()}`);
|
|
345
|
+
}
|
|
346
|
+
return { success: true };
|
|
347
|
+
}
|
|
348
|
+
};
|
|
276
349
|
};
|
|
277
350
|
// Annotate the CommonJS export names for ESM import in node:
|
|
278
351
|
0 && (module.exports = {
|