@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.mjs
CHANGED
|
@@ -8,17 +8,14 @@ var AnticeilClient = class {
|
|
|
8
8
|
this.config = {
|
|
9
9
|
token: config.token || "",
|
|
10
10
|
apiKey: config.apiKey || "",
|
|
11
|
-
baseUrl: config.baseUrl || "https://app.anticeil.com",
|
|
12
|
-
socketUrl: config.socketUrl || "https://app.anticeil.com",
|
|
11
|
+
baseUrl: (config.baseUrl || "https://app.anticeil.com").replace(/\/+$/, ""),
|
|
12
|
+
socketUrl: (config.socketUrl || config.baseUrl || "https://app.anticeil.com").replace(/\/+$/, ""),
|
|
13
13
|
autoConnect: config.autoConnect ?? false
|
|
14
14
|
};
|
|
15
15
|
if (this.config.autoConnect) {
|
|
16
16
|
this.connect();
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Connect to the Anticeil WebSocket real-time gateway
|
|
21
|
-
*/
|
|
22
19
|
connect() {
|
|
23
20
|
if (this.socket?.connected) return;
|
|
24
21
|
this.socket = io(this.config.socketUrl, {
|
|
@@ -57,18 +54,12 @@ var AnticeilClient = class {
|
|
|
57
54
|
this.emitInternal("presence", data);
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Disconnect from the WebSocket real-time gateway
|
|
62
|
-
*/
|
|
63
57
|
disconnect() {
|
|
64
58
|
if (this.socket) {
|
|
65
59
|
this.socket.disconnect();
|
|
66
60
|
this.socket = null;
|
|
67
61
|
}
|
|
68
62
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Register an event listener (e.g. 'message', 'typing', 'connect', 'disconnect')
|
|
71
|
-
*/
|
|
72
63
|
on(event, handler) {
|
|
73
64
|
if (!this.eventHandlers.has(event)) {
|
|
74
65
|
this.eventHandlers.set(event, /* @__PURE__ */ new Set());
|
|
@@ -76,9 +67,6 @@ var AnticeilClient = class {
|
|
|
76
67
|
this.eventHandlers.get(event).add(handler);
|
|
77
68
|
return this;
|
|
78
69
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Remove an event listener
|
|
81
|
-
*/
|
|
82
70
|
off(event, handler) {
|
|
83
71
|
this.eventHandlers.get(event)?.delete(handler);
|
|
84
72
|
return this;
|
|
@@ -92,32 +80,81 @@ var AnticeilClient = class {
|
|
|
92
80
|
}
|
|
93
81
|
});
|
|
94
82
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Internal REST fetch helper
|
|
97
|
-
*/
|
|
98
83
|
async request(endpoint, options = {}) {
|
|
99
|
-
const
|
|
84
|
+
const path = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
85
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
100
86
|
const headers = new Headers(options.headers);
|
|
101
87
|
if (this.config.token) {
|
|
102
88
|
headers.set("Authorization", `Bearer ${this.config.token}`);
|
|
103
89
|
} else if (this.config.apiKey) {
|
|
90
|
+
headers.set("Authorization", `Bearer ${this.config.apiKey}`);
|
|
104
91
|
headers.set("X-Anticeil-Api-Key", this.config.apiKey);
|
|
105
92
|
}
|
|
106
|
-
headers.
|
|
93
|
+
if (!headers.has("Content-Type")) {
|
|
94
|
+
headers.set("Content-Type", "application/json");
|
|
95
|
+
}
|
|
107
96
|
const res = await fetch(url, { ...options, headers });
|
|
108
97
|
if (!res.ok) {
|
|
109
98
|
const errorText = await res.text().catch(() => res.statusText);
|
|
110
|
-
throw new Error(`Anticeil API Error [${res.status}]: ${errorText}`);
|
|
99
|
+
throw new Error(`Anticeil API Error [${res.status}] ${path}: ${errorText}`);
|
|
100
|
+
}
|
|
101
|
+
const text = await res.text();
|
|
102
|
+
if (!text) return {};
|
|
103
|
+
try {
|
|
104
|
+
return JSON.parse(text);
|
|
105
|
+
} catch {
|
|
106
|
+
return text;
|
|
111
107
|
}
|
|
112
|
-
return res.json();
|
|
113
108
|
}
|
|
114
109
|
// ==========================================
|
|
115
|
-
//
|
|
110
|
+
// 1. COLONIES API
|
|
111
|
+
// ==========================================
|
|
112
|
+
colonies = {
|
|
113
|
+
list: async () => this.request("/api/colonies"),
|
|
114
|
+
get: async (colonyId) => this.request(`/api/colonies/${colonyId}`),
|
|
115
|
+
create: async (data) => this.request("/api/v1/community/hubs", {
|
|
116
|
+
method: "POST",
|
|
117
|
+
body: JSON.stringify(data)
|
|
118
|
+
}),
|
|
119
|
+
update: async (colonyId, updates) => this.request(`/api/colonies/${colonyId}`, {
|
|
120
|
+
method: "PATCH",
|
|
121
|
+
body: JSON.stringify(updates)
|
|
122
|
+
}),
|
|
123
|
+
delete: async (colonyId) => this.request(`/api/v1/community/hubs/${colonyId}`, {
|
|
124
|
+
method: "DELETE"
|
|
125
|
+
}),
|
|
126
|
+
setPrivacy: async (colonyId, joinMethod, options = {}) => this.request(`/api/colonies/${colonyId}/access`, {
|
|
127
|
+
method: "PUT",
|
|
128
|
+
body: JSON.stringify({
|
|
129
|
+
joinMethod,
|
|
130
|
+
visibility: joinMethod === "discoverable" ? "public" : "private",
|
|
131
|
+
...options
|
|
132
|
+
})
|
|
133
|
+
}),
|
|
134
|
+
getInsights: async (colonyId) => this.request(`/api/v1/colonies/${colonyId}/insights`)
|
|
135
|
+
};
|
|
136
|
+
// ==========================================
|
|
137
|
+
// 2. CHANNELS API
|
|
138
|
+
// ==========================================
|
|
139
|
+
channels = {
|
|
140
|
+
get: async (channelId) => this.request(`/api/channels/${channelId}`),
|
|
141
|
+
list: async (colonyId) => this.request(`/api/colonies/${colonyId}/channels`),
|
|
142
|
+
create: async (colonyId, data) => this.request(`/api/colonies/${colonyId}/channels`, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
body: JSON.stringify(data)
|
|
145
|
+
}),
|
|
146
|
+
update: async (channelId, updates) => this.request(`/api/v1/community/channels/${channelId}`, {
|
|
147
|
+
method: "PUT",
|
|
148
|
+
body: JSON.stringify(updates)
|
|
149
|
+
}),
|
|
150
|
+
delete: async (channelId) => this.request(`/api/v1/community/channels/${channelId}`, {
|
|
151
|
+
method: "DELETE"
|
|
152
|
+
})
|
|
153
|
+
};
|
|
154
|
+
// ==========================================
|
|
155
|
+
// 3. MESSAGES & REACTIONS API
|
|
116
156
|
// ==========================================
|
|
117
157
|
messages = {
|
|
118
|
-
/**
|
|
119
|
-
* Send a text message to a channel
|
|
120
|
-
*/
|
|
121
158
|
send: async (channelId, options) => {
|
|
122
159
|
const payload = typeof options === "string" ? { content: options } : options;
|
|
123
160
|
if (this.socket?.connected) {
|
|
@@ -128,112 +165,118 @@ var AnticeilClient = class {
|
|
|
128
165
|
body: JSON.stringify(payload)
|
|
129
166
|
});
|
|
130
167
|
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
}
|
|
168
|
+
list: async (channelId, limit = 50) => this.request(`/api/channels/${channelId}/messages?limit=${limit}`),
|
|
169
|
+
delete: async (channelId, messageId) => this.request(`/api/channels/${channelId}/messages/${messageId}`, {
|
|
170
|
+
method: "DELETE"
|
|
171
|
+
}),
|
|
172
|
+
toggleReaction: async (messageId, emoji) => this.request(`/api/v1/community/messages/${messageId}/reactions`, {
|
|
173
|
+
method: "POST",
|
|
174
|
+
body: JSON.stringify({ emoji })
|
|
175
|
+
}),
|
|
176
|
+
togglePin: async (messageId, channelId) => this.request(`/api/v1/community/messages/${messageId}/pin`, {
|
|
177
|
+
method: "POST",
|
|
178
|
+
body: JSON.stringify({ channelId })
|
|
179
|
+
})
|
|
145
180
|
};
|
|
146
181
|
// ==========================================
|
|
147
|
-
//
|
|
182
|
+
// 4. THREADS API
|
|
148
183
|
// ==========================================
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
},
|
|
156
|
-
/**
|
|
157
|
-
* List all channels within a colony
|
|
158
|
-
*/
|
|
159
|
-
list: async (colonyId) => {
|
|
160
|
-
return this.request(`/api/colonies/${colonyId}/channels`);
|
|
161
|
-
},
|
|
162
|
-
/**
|
|
163
|
-
* Create a new channel
|
|
164
|
-
*/
|
|
165
|
-
create: async (colonyId, data) => {
|
|
166
|
-
return this.request(`/api/colonies/${colonyId}/channels`, {
|
|
167
|
-
method: "POST",
|
|
168
|
-
body: JSON.stringify(data)
|
|
169
|
-
});
|
|
170
|
-
}
|
|
184
|
+
threads = {
|
|
185
|
+
list: async (channelId) => this.request(`/api/v1/community/channels/${channelId}/threads`),
|
|
186
|
+
create: async (channelId, data) => this.request(`/api/v1/community/channels/${channelId}/threads`, {
|
|
187
|
+
method: "POST",
|
|
188
|
+
body: JSON.stringify(data)
|
|
189
|
+
})
|
|
171
190
|
};
|
|
172
191
|
// ==========================================
|
|
173
|
-
//
|
|
192
|
+
// 5. FRIENDS & MESSAGE REQUESTS API
|
|
174
193
|
// ==========================================
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
friends = {
|
|
195
|
+
list: async () => this.request("/api/v1/community/friends"),
|
|
196
|
+
sendRequest: async (target) => this.request("/api/v1/community/friends/request", {
|
|
197
|
+
method: "POST",
|
|
198
|
+
body: JSON.stringify({ username: target, target })
|
|
199
|
+
}),
|
|
200
|
+
listMessageRequests: async () => this.request("/api/v1/community/message-requests"),
|
|
201
|
+
respondMessageRequest: async (requestId, action) => this.request(`/api/v1/community/message-requests/${requestId}/${action}`, {
|
|
202
|
+
method: "POST",
|
|
203
|
+
body: JSON.stringify({})
|
|
204
|
+
})
|
|
205
|
+
};
|
|
206
|
+
// ==========================================
|
|
207
|
+
// 6. MEMBERS, ROLES & MODERATION API
|
|
208
|
+
// ==========================================
|
|
209
|
+
members = {
|
|
210
|
+
list: async (colonyId) => this.request(
|
|
211
|
+
colonyId ? `/api/v1/community/members?colonyId=${encodeURIComponent(colonyId)}` : "/api/v1/community/members"
|
|
212
|
+
),
|
|
213
|
+
listRoles: async (colonyId) => this.request(`/api/v1/community/hubs/${colonyId}/roles`),
|
|
214
|
+
updateRole: async (colonyId, userId, roleId) => this.request(`/api/v1/community/hubs/${colonyId}/members/${userId}/role`, {
|
|
215
|
+
method: "PUT",
|
|
216
|
+
body: JSON.stringify({ roleId })
|
|
217
|
+
}),
|
|
218
|
+
ban: async (colonyId, userId, reason) => this.request(`/api/v1/colonies/${colonyId}/bans`, {
|
|
219
|
+
method: "POST",
|
|
220
|
+
body: JSON.stringify({ userId, reason })
|
|
221
|
+
}),
|
|
222
|
+
unban: async (colonyId, userId) => this.request(`/api/v1/colonies/${colonyId}/bans/${userId}`, {
|
|
223
|
+
method: "DELETE"
|
|
224
|
+
}),
|
|
225
|
+
getAuditLogs: async (colonyId) => this.request(`/api/v1/colonies/${colonyId}/audit-logs`)
|
|
226
|
+
};
|
|
227
|
+
// ==========================================
|
|
228
|
+
// 7. TASKS / KANBAN ASSIGNMENTS API
|
|
229
|
+
// ==========================================
|
|
230
|
+
tasks = {
|
|
231
|
+
list: async (filters) => {
|
|
232
|
+
const params = new URLSearchParams();
|
|
233
|
+
if (filters?.colonyId) params.set("colonyId", filters.colonyId);
|
|
234
|
+
if (filters?.channelId) params.set("channelId", filters.channelId);
|
|
235
|
+
const qs = params.toString();
|
|
236
|
+
return this.request(`/api/v1/community/assignments${qs ? `?${qs}` : ""}`);
|
|
196
237
|
},
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
});
|
|
209
|
-
}
|
|
238
|
+
create: async (data) => this.request("/api/v1/community/assignments", {
|
|
239
|
+
method: "POST",
|
|
240
|
+
body: JSON.stringify({ columnId: "todo", priority: "medium", ...data })
|
|
241
|
+
}),
|
|
242
|
+
update: async (taskId, updates) => this.request(`/api/v1/community/assignments/${taskId}`, {
|
|
243
|
+
method: "PUT",
|
|
244
|
+
body: JSON.stringify(updates)
|
|
245
|
+
}),
|
|
246
|
+
delete: async (taskId) => this.request(`/api/v1/community/assignments/${taskId}`, {
|
|
247
|
+
method: "DELETE"
|
|
248
|
+
})
|
|
210
249
|
};
|
|
211
250
|
// ==========================================
|
|
212
|
-
//
|
|
251
|
+
// 8. CALENDAR & COLONY EVENTS API
|
|
213
252
|
// ==========================================
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
253
|
+
events = {
|
|
254
|
+
list: async (colonyId) => this.request(
|
|
255
|
+
colonyId ? `/api/v1/community/calendar/events?colonyId=${encodeURIComponent(colonyId)}` : "/api/v1/community/calendar/events"
|
|
256
|
+
),
|
|
257
|
+
create: async (data) => this.request("/api/v1/community/calendar/events", {
|
|
258
|
+
method: "POST",
|
|
259
|
+
body: JSON.stringify(data)
|
|
260
|
+
}),
|
|
261
|
+
update: async (eventId, updates) => this.request(`/api/v1/community/calendar/events/${eventId}`, {
|
|
262
|
+
method: "PUT",
|
|
263
|
+
body: JSON.stringify(updates)
|
|
264
|
+
}),
|
|
265
|
+
delete: async (eventId) => this.request(`/api/v1/community/calendar/events/${eventId}`, {
|
|
266
|
+
method: "DELETE"
|
|
267
|
+
})
|
|
229
268
|
};
|
|
230
269
|
// ==========================================
|
|
231
|
-
// ACTIVITIES API
|
|
270
|
+
// 9. APPS, ACTIVITIES & QUESTS API
|
|
232
271
|
// ==========================================
|
|
272
|
+
apps = {
|
|
273
|
+
list: async () => this.request("/api/v1/community/activities/catalog"),
|
|
274
|
+
install: async (colonyId, appId) => this.request(`/api/v1/colonies/${colonyId}/apps/${appId}/install`, {
|
|
275
|
+
method: "POST",
|
|
276
|
+
body: JSON.stringify({})
|
|
277
|
+
})
|
|
278
|
+
};
|
|
233
279
|
activities = {
|
|
234
|
-
/**
|
|
235
|
-
* Launch a voice activity (YouTube Watch Together, Chess, Whiteboard)
|
|
236
|
-
*/
|
|
237
280
|
launch: async (options) => {
|
|
238
281
|
if (this.socket?.connected) {
|
|
239
282
|
this.socket.emit("launch_activity", options);
|
|
@@ -247,6 +290,36 @@ var AnticeilClient = class {
|
|
|
247
290
|
);
|
|
248
291
|
}
|
|
249
292
|
};
|
|
293
|
+
quests = {
|
|
294
|
+
list: async () => this.request("/api/v1/community/quests"),
|
|
295
|
+
create: async (data) => this.request("/api/v1/community/quests", {
|
|
296
|
+
method: "POST",
|
|
297
|
+
body: JSON.stringify(data)
|
|
298
|
+
}),
|
|
299
|
+
update: async (questId, updates) => this.request(`/api/v1/community/quests/${questId}`, {
|
|
300
|
+
method: "PUT",
|
|
301
|
+
body: JSON.stringify(updates)
|
|
302
|
+
}),
|
|
303
|
+
delete: async (questId) => this.request(`/api/v1/community/quests/${questId}`, {
|
|
304
|
+
method: "DELETE"
|
|
305
|
+
})
|
|
306
|
+
};
|
|
307
|
+
// ==========================================
|
|
308
|
+
// 10. WEBHOOKS API
|
|
309
|
+
// ==========================================
|
|
310
|
+
webhooks = {
|
|
311
|
+
send: async (webhookUrl, payload) => {
|
|
312
|
+
const res = await fetch(webhookUrl, {
|
|
313
|
+
method: "POST",
|
|
314
|
+
headers: { "Content-Type": "application/json" },
|
|
315
|
+
body: JSON.stringify(payload)
|
|
316
|
+
});
|
|
317
|
+
if (!res.ok) {
|
|
318
|
+
throw new Error(`Webhook Error [${res.status}]: ${await res.text()}`);
|
|
319
|
+
}
|
|
320
|
+
return { success: true };
|
|
321
|
+
}
|
|
322
|
+
};
|
|
250
323
|
};
|
|
251
324
|
export {
|
|
252
325
|
AnticeilClient
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anticeil/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Official TypeScript & JavaScript SDK for Anticeil Chat, Voice, Activities, and Bot Platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
+
"test": "node --test test/sdk.test.mjs",
|
|
19
20
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
20
21
|
"prepublishOnly": "npm run build"
|
|
21
22
|
},
|