commune-ai 0.3.0 → 0.3.1

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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AttachmentRecord, AttachmentUrl, AttachmentUploadResponse, CreateDomainPayload, DomainEntry, InboxEntry, MessageListParams, SendMessagePayload, UnifiedMessage, SearchFilter, SearchOptions, SearchResult, IndexConversationPayload, ThreadListParams, ThreadListResponse } from './types.js';
1
+ import type { AttachmentRecord, AttachmentUrl, AttachmentUploadResponse, CreateDomainPayload, DomainEntry, InboxEntry, MessageListParams, SendMessagePayload, UnifiedMessage, SearchFilter, SearchOptions, SearchResult, IndexConversationPayload, ThreadListParams, ThreadListResponse, SearchThreadsParams, SearchThreadResult, ThreadMetadataEntry, DeliveryMetricsParams, DeliveryEventEntry, DeliveryEventsParams, DeliverySuppressionsParams, SuppressionEntry } from './types.js';
2
2
  export type ClientOptions = {
3
3
  baseUrl?: string;
4
4
  apiKey: string;
@@ -6,12 +6,13 @@ export type ClientOptions = {
6
6
  fetcher?: typeof fetch;
7
7
  };
8
8
  export declare class CommuneClient {
9
- private searchClient;
10
9
  private baseUrl;
11
10
  private apiKey;
12
11
  private headers?;
13
12
  private fetcher;
13
+ private deprecationWarnings;
14
14
  constructor(options: ClientOptions);
15
+ private warnDeprecated;
15
16
  private request;
16
17
  domains: {
17
18
  list: () => Promise<DomainEntry[]>;
@@ -93,6 +94,9 @@ export declare class CommuneClient {
93
94
  order?: "asc" | "desc";
94
95
  }) => Promise<UnifiedMessage[]>;
95
96
  };
97
+ search: {
98
+ threads: (params: SearchThreadsParams) => Promise<SearchThreadResult[]>;
99
+ };
96
100
  conversations: {
97
101
  search: (query: string, filter: SearchFilter, options?: SearchOptions) => Promise<SearchResult[]>;
98
102
  index: (organizationId: string, conversation: IndexConversationPayload) => Promise<{
@@ -108,6 +112,16 @@ export declare class CommuneClient {
108
112
  limit?: number;
109
113
  order?: "asc" | "desc";
110
114
  }) => Promise<UnifiedMessage[]>;
115
+ metadata: (threadId: string) => Promise<ThreadMetadataEntry>;
116
+ setStatus: (threadId: string, status: "open" | "needs_reply" | "waiting" | "closed") => Promise<ThreadMetadataEntry>;
117
+ addTags: (threadId: string, tags: string[]) => Promise<ThreadMetadataEntry>;
118
+ removeTags: (threadId: string, tags: string[]) => Promise<ThreadMetadataEntry>;
119
+ assign: (threadId: string, assignedTo?: string | null) => Promise<ThreadMetadataEntry>;
120
+ };
121
+ delivery: {
122
+ metrics: (params?: DeliveryMetricsParams) => Promise<Record<string, unknown>>;
123
+ events: (params?: DeliveryEventsParams) => Promise<DeliveryEventEntry[]>;
124
+ suppressions: (params?: DeliverySuppressionsParams) => Promise<SuppressionEntry[]>;
111
125
  };
112
126
  attachments: {
113
127
  upload: (content: string, filename: string, mimeType: string) => Promise<AttachmentUploadResponse>;
package/dist/client.js CHANGED
@@ -1,4 +1,3 @@
1
- import { SearchClient } from './client/search.js';
2
1
  const DEFAULT_BASE_URL = 'https://api.commune.email';
3
2
  const buildQuery = (params) => {
4
3
  const query = new URLSearchParams();
@@ -13,6 +12,7 @@ const buildQuery = (params) => {
13
12
  };
14
13
  export class CommuneClient {
15
14
  constructor(options) {
15
+ this.deprecationWarnings = new Set();
16
16
  this.domains = {
17
17
  list: async () => {
18
18
  const response = await this.request(`/v1/domains`);
@@ -136,18 +136,29 @@ export class CommuneClient {
136
136
  })}`);
137
137
  },
138
138
  };
139
+ this.search = {
140
+ threads: async (params) => {
141
+ return this.request(`/v1/search/threads${buildQuery({
142
+ q: params.query,
143
+ inbox_id: params.inboxId,
144
+ domain_id: params.domainId,
145
+ limit: params.limit,
146
+ })}`);
147
+ },
148
+ };
139
149
  this.conversations = {
140
150
  search: async (query, filter, options) => {
141
- return this.request('/v1/search', {
142
- method: 'POST',
143
- json: {
144
- query,
145
- filter,
146
- options,
147
- },
151
+ this.warnDeprecated('conversations.search', '[commune-ai] `conversations.search` is deprecated. Use `search.threads({ query, inboxId, domainId, limit })`.');
152
+ const inboxId = filter.inboxIds && filter.inboxIds.length > 0 ? filter.inboxIds[0] : undefined;
153
+ return this.search.threads({
154
+ query,
155
+ inboxId,
156
+ domainId: filter.domainId,
157
+ limit: options?.limit,
148
158
  });
149
159
  },
150
160
  index: async (organizationId, conversation) => {
161
+ this.warnDeprecated('conversations.index', '[commune-ai] `conversations.index` is deprecated and will be removed. Indexing is handled automatically.');
151
162
  return this.request('/v1/search/index', {
152
163
  method: 'POST',
153
164
  json: {
@@ -157,6 +168,7 @@ export class CommuneClient {
157
168
  });
158
169
  },
159
170
  indexBatch: async (organizationId, conversations) => {
171
+ this.warnDeprecated('conversations.indexBatch', '[commune-ai] `conversations.indexBatch` is deprecated and will be removed. Indexing is handled automatically.');
160
172
  return this.request('/v1/search/index/batch', {
161
173
  method: 'POST',
162
174
  json: {
@@ -193,6 +205,58 @@ export class CommuneClient {
193
205
  order: params?.order,
194
206
  })}`);
195
207
  },
208
+ metadata: async (threadId) => {
209
+ return this.request(`/v1/threads/${encodeURIComponent(threadId)}/metadata`);
210
+ },
211
+ setStatus: async (threadId, status) => {
212
+ return this.request(`/v1/threads/${encodeURIComponent(threadId)}/status`, {
213
+ method: 'PUT',
214
+ json: { status },
215
+ });
216
+ },
217
+ addTags: async (threadId, tags) => {
218
+ return this.request(`/v1/threads/${encodeURIComponent(threadId)}/tags`, {
219
+ method: 'POST',
220
+ json: { tags },
221
+ });
222
+ },
223
+ removeTags: async (threadId, tags) => {
224
+ return this.request(`/v1/threads/${encodeURIComponent(threadId)}/tags`, {
225
+ method: 'DELETE',
226
+ json: { tags },
227
+ });
228
+ },
229
+ assign: async (threadId, assignedTo) => {
230
+ return this.request(`/v1/threads/${encodeURIComponent(threadId)}/assign`, {
231
+ method: 'PUT',
232
+ json: { assigned_to: assignedTo ?? null },
233
+ });
234
+ },
235
+ };
236
+ this.delivery = {
237
+ metrics: async (params = {}) => {
238
+ return this.request(`/v1/delivery/metrics${buildQuery({
239
+ inbox_id: params.inboxId,
240
+ domain_id: params.domainId,
241
+ period: params.period,
242
+ })}`);
243
+ },
244
+ events: async (params = {}) => {
245
+ return this.request(`/v1/delivery/events${buildQuery({
246
+ message_id: params.messageId,
247
+ inbox_id: params.inboxId,
248
+ domain_id: params.domainId,
249
+ event_type: params.eventType,
250
+ limit: params.limit,
251
+ })}`);
252
+ },
253
+ suppressions: async (params = {}) => {
254
+ return this.request(`/v1/delivery/suppressions${buildQuery({
255
+ inbox_id: params.inboxId,
256
+ domain_id: params.domainId,
257
+ limit: params.limit,
258
+ })}`);
259
+ },
196
260
  };
197
261
  this.attachments = {
198
262
  upload: async (content, filename, mimeType) => {
@@ -213,7 +277,12 @@ export class CommuneClient {
213
277
  this.apiKey = options.apiKey;
214
278
  this.headers = options.headers;
215
279
  this.fetcher = options.fetcher || fetch;
216
- this.searchClient = new SearchClient(this.baseUrl, { Authorization: `Bearer ${this.apiKey}` });
280
+ }
281
+ warnDeprecated(key, message) {
282
+ if (this.deprecationWarnings.has(key))
283
+ return;
284
+ this.deprecationWarnings.add(key);
285
+ console.warn(message);
217
286
  }
218
287
  async request(path, options = {}) {
219
288
  const { json, headers, ...rest } = options;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CommuneClient } from './client.js';
2
- export type { ApiError, ApiResponse, AttachmentRecord, Channel, ConversationListParams, CreateDomainPayload, CreateInboxPayload, Direction, DomainEntry, DomainWebhook, InboxEntry, InboxWebhook, InboundEmailWebhookPayload, MessageListParams, MessageMetadata, Participant, ParticipantRole, SendMessagePayload, SvixHeaders, Thread, ThreadListParams, ThreadListResponse, UnifiedMessage, } from './types.js';
2
+ export type { ApiError, ApiResponse, AttachmentRecord, Channel, ConversationListParams, CreateDomainPayload, CreateInboxPayload, Direction, DomainEntry, DomainWebhook, InboxEntry, InboxWebhook, InboundEmailWebhookPayload, MessageListParams, MessageMetadata, Participant, ParticipantRole, SendMessagePayload, SearchThreadResult, SearchThreadsParams, ThreadMetadataEntry, SvixHeaders, SuppressionEntry, Thread, DeliveryEventEntry, DeliveryEventsParams, DeliveryMetricsParams, DeliverySuppressionsParams, ThreadListParams, ThreadListResponse, UnifiedMessage, } from './types.js';
3
3
  export { verifyResendWebhook, verifyCommuneWebhook, computeCommuneSignature } from './webhooks.js';
4
4
  export type { CommuneWebhookHeaders } from './webhooks.js';
5
5
  export { createWebhookHandler } from './listener.js';
package/dist/types.d.ts CHANGED
@@ -305,3 +305,65 @@ export interface ThreadListParams {
305
305
  cursor?: string;
306
306
  order?: 'asc' | 'desc';
307
307
  }
308
+ export interface SearchThreadsParams {
309
+ query: string;
310
+ inboxId?: string;
311
+ domainId?: string;
312
+ limit?: number;
313
+ }
314
+ export interface SearchThreadResult {
315
+ thread_id: string;
316
+ subject?: string | null;
317
+ score?: number;
318
+ inbox_id?: string | null;
319
+ domain_id?: string | null;
320
+ participants?: string[];
321
+ direction?: Direction | null;
322
+ }
323
+ export interface ThreadMetadataEntry {
324
+ thread_id: string;
325
+ orgId?: string;
326
+ tags: string[];
327
+ status: 'open' | 'needs_reply' | 'waiting' | 'closed';
328
+ assigned_to?: string | null;
329
+ updated_at?: string;
330
+ }
331
+ export interface DeliveryMetricsParams {
332
+ inboxId?: string;
333
+ domainId?: string;
334
+ period?: string;
335
+ }
336
+ export interface DeliveryEventEntry {
337
+ _id?: string;
338
+ message_id: string;
339
+ event_type: string;
340
+ event_data: Record<string, unknown>;
341
+ processed_at?: string;
342
+ inbox_id?: string;
343
+ domain_id?: string;
344
+ }
345
+ export interface DeliveryEventsParams {
346
+ messageId?: string;
347
+ inboxId?: string;
348
+ domainId?: string;
349
+ eventType?: string;
350
+ limit?: number;
351
+ }
352
+ export interface SuppressionEntry {
353
+ _id?: string;
354
+ email: string;
355
+ reason: string;
356
+ type: string;
357
+ source: 'inbox' | 'domain' | 'global';
358
+ inbox_id?: string;
359
+ domain_id?: string;
360
+ created_at?: string;
361
+ expires_at?: string;
362
+ message_id?: string;
363
+ metadata?: Record<string, unknown>;
364
+ }
365
+ export interface DeliverySuppressionsParams {
366
+ inboxId?: string;
367
+ domainId?: string;
368
+ limit?: number;
369
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commune-ai",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Email infrastructure for agents — set up an inbox and send your first email in 30 seconds. Programmatic inboxes (~1 line), consistent threads, custom domains, attachments, and structured data.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",