carlyemail 0.5.0 → 0.6.2

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.
Files changed (4) hide show
  1. package/carlyemail.js +81 -14
  2. package/package.json +3 -3
  3. package/sdk.d.ts +65 -0
  4. package/sdk.js +34 -0
package/carlyemail.js CHANGED
@@ -18,7 +18,7 @@ import { join } from "node:path";
18
18
  import { fileURLToPath } from "node:url";
19
19
  import { randomBytes } from "node:crypto";
20
20
 
21
- export const VERSION = "0.5.0";
21
+ export const VERSION = "0.6.2";
22
22
 
23
23
  const DEFAULT_API = "https://api.carlyemail.com";
24
24
  const CONFIG_DIR = join(homedir(), ".carlyemail");
@@ -229,6 +229,28 @@ function suggestUsername() {
229
229
  return `agent-${randomBytes(2).toString("hex")}`;
230
230
  }
231
231
 
232
+ /**
233
+ * Ask the server to email a sign-in code and remember which address it went to,
234
+ * so a later `verify` knows to exchange the code for a key rather than confirm
235
+ * a sign-up. `known` distinguishes "you told me this account exists" (signup
236
+ * got `account_exists`) from the server's deliberately non-committal answer.
237
+ */
238
+ async function startSignin(ctx, human_email, { known = false } = {}) {
239
+ await request(ctx.config, "POST", "/v0/agent/sign-in", {
240
+ auth: false,
241
+ body: { human_email },
242
+ });
243
+ saveConfig({ ...ctx.config, pending_signin: human_email }, ctx.configFile, ctx.configDir);
244
+ ctx.print(
245
+ arrow(
246
+ known
247
+ ? `a sign-in code is on its way to ${human_email} (good for 30 minutes), then:`
248
+ : `if ${human_email} has an account, a code is on its way (good for 30 minutes), then:`
249
+ )
250
+ );
251
+ ctx.print(` carlyemail verify <code>`);
252
+ }
253
+
232
254
  define(
233
255
  "signup",
234
256
  "Create an account and an inbox",
@@ -258,19 +280,33 @@ define(
258
280
  const display_name =
259
281
  typeof ctx.flags["display-name"] === "string" ? ctx.flags["display-name"] : undefined;
260
282
 
261
- const out = await request(ctx.config, "POST", "/v0/agent/sign-up", {
262
- auth: false,
263
- body: { human_email, username, source: "cli", display_name },
264
- });
283
+ let out;
284
+ try {
285
+ out = await request(ctx.config, "POST", "/v0/agent/sign-up", {
286
+ auth: false,
287
+ body: { human_email, username, source: "cli", display_name },
288
+ });
289
+ } catch (error) {
290
+ // An existing account is not a dead end. Fall through to the sign-in
291
+ // flow the same way the console does, without being asked — the person
292
+ // typed their address wanting a working key, not an error about which
293
+ // command would have produced one.
294
+ if (error instanceof ApiError && error.code === "account_exists") {
295
+ ctx.print(`${human_email} already has an account — signing in instead.`);
296
+ await startSignin(ctx, human_email, { known: true });
297
+ return;
298
+ }
299
+ throw error;
300
+ }
265
301
 
266
302
  // Saved before anything else is printed: the key is returned exactly once
267
303
  // and is unrecoverable afterwards, so losing it to a later crash would
268
304
  // cost the account.
269
- const saved = saveConfig(
270
- { ...ctx.config, api_key: out.api_key, organization_id: out.organization_id },
271
- ctx.configFile,
272
- ctx.configDir
273
- );
305
+ const config = { ...ctx.config, api_key: out.api_key, organization_id: out.organization_id };
306
+ // A sign-in abandoned before its code arrived must not re-route the
307
+ // `verify` that belongs to this fresh sign-up.
308
+ delete config.pending_signin;
309
+ const saved = saveConfig(config, ctx.configFile, ctx.configDir);
274
310
 
275
311
  ctx.print(ok(bold(out.inbox_id)));
276
312
  ctx.print(ok(`key saved to ${saved}`));
@@ -278,7 +314,22 @@ define(
278
314
  ctx.print(arrow(`check ${human_email} for a 6-digit code, then:`));
279
315
  ctx.print(` carlyemail verify <code>`);
280
316
  ctx.print("");
281
- ctx.print(dim("Until it is confirmed the account can read its own mail but not send."));
317
+ ctx.print(dim(`Until the code is confirmed the account can only email ${human_email}.`));
318
+ }
319
+ );
320
+
321
+ define(
322
+ "signin",
323
+ "Sign in to an existing account with an emailed code",
324
+ "carlyemail signin you@example.com",
325
+ async (ctx) => {
326
+ let human_email = ctx.positional[0] || ctx.flags["human-email"];
327
+ if (typeof human_email !== "string" || !human_email) {
328
+ const answer = await ctx.ask("The account's owner email: ");
329
+ if (answer) human_email = answer;
330
+ }
331
+ if (!human_email) throw new UsageError("carlyemail signin you@example.com");
332
+ await startSignin(ctx, human_email);
282
333
  }
283
334
  );
284
335
 
@@ -286,8 +337,24 @@ define("verify", "Confirm the owner email with the code", "carlyemail verify 123
286
337
  const code = ctx.positional[0] || ctx.flags.code;
287
338
  if (!code) throw new UsageError("the 6-digit code is required: carlyemail verify 123456");
288
339
 
340
+ // A pending sign-in and a sign-up confirmation are the same step to the
341
+ // person typing the code, but different calls: one trades the code for a new
342
+ // key, the other upgrades the key sign-up already saved. The config
343
+ // remembers which one is open.
344
+ if (ctx.config.pending_signin) {
345
+ const out = await request(ctx.config, "POST", "/v0/agent/sign-in/verify", {
346
+ auth: false,
347
+ body: { human_email: ctx.config.pending_signin, otp_code: String(code) },
348
+ });
349
+ const config = { ...ctx.config, api_key: out.api_key, organization_id: out.organization_id };
350
+ delete config.pending_signin;
351
+ const saved = saveConfig(config, ctx.configFile, ctx.configDir);
352
+ ctx.print(ok(`signed in — key saved to ${saved}`));
353
+ return;
354
+ }
355
+
289
356
  await request(ctx.config, "POST", "/v0/agent/verify", { body: { otp_code: String(code) } });
290
- ctx.print(ok("verified — this account can send now"));
357
+ ctx.print(ok("verified — this account can send anywhere now"));
291
358
  });
292
359
 
293
360
  define("whoami", "Show the key's identity and scope", "carlyemail whoami", async (ctx) => {
@@ -726,9 +793,9 @@ define("plan", "Show the current plan and its limits", "carlyemail plan", async
726
793
  ctx.print(` ${dim("email")} ${cap(billing.monthly_emails)} a month`);
727
794
  });
728
795
 
729
- define("upgrade", "Get a checkout link for a paid plan", "carlyemail upgrade developer", async (ctx) => {
796
+ define("upgrade", "Get a checkout link for a paid plan", "carlyemail upgrade startup", async (ctx) => {
730
797
  const plan = ctx.positional[0] || ctx.flags.plan;
731
- if (!plan) throw new UsageError("which plan? carlyemail upgrade developer|startup");
798
+ if (!plan) throw new UsageError("which plan? carlyemail upgrade startup|business");
732
799
  const out = await request(ctx.config, "POST", "/v0/billing/checkout", { body: { plan } });
733
800
  emit(ctx, out, () => {
734
801
  ctx.print(arrow("open this to upgrade:"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carlyemail",
3
- "version": "0.5.0",
3
+ "version": "0.6.2",
4
4
  "description": "Real email inboxes your agent can send, receive and reply from. SDK and CLI.",
5
5
  "keywords": [
6
6
  "email",
@@ -11,7 +11,7 @@
11
11
  "mcp",
12
12
  "cli"
13
13
  ],
14
- "homepage": "https://carlyemail.com",
14
+ "homepage": "https://docs.carlyemail.com",
15
15
  "bugs": "https://docs.carlyemail.com/support",
16
16
  "repository": {
17
17
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "author": "SWH Labs LLC",
23
23
  "type": "module",
24
24
  "bin": {
25
- "carlyemail": "./carlyemail.js"
25
+ "carlyemail": "carlyemail.js"
26
26
  },
27
27
  "types": "./sdk.d.ts",
28
28
  "exports": {
package/sdk.d.ts CHANGED
@@ -16,6 +16,8 @@ export interface AgentSigninVerifyRequest {
16
16
  export interface AgentSigninVerifyResponse {
17
17
  organization_id: string;
18
18
  api_key: string;
19
+ inbox_domain?: string | null;
20
+ inboxes_on_signup_domain?: Array<string>;
19
21
  }
20
22
 
21
23
  export interface AgentSignupRequest {
@@ -39,6 +41,8 @@ export interface AgentVerifyRequest {
39
41
  export interface AgentVerifyResponse {
40
42
  organization_id: string;
41
43
  verified: boolean;
44
+ inbox_domain?: string | null;
45
+ inboxes_on_signup_domain?: Array<string>;
42
46
  }
43
47
 
44
48
  export interface ApiKeyOut {
@@ -50,6 +54,7 @@ export interface ApiKeyOut {
50
54
  used_at?: string | null;
51
55
  permissions?: Record<string, boolean> | null;
52
56
  created_at: string;
57
+ expires_at?: string | null;
53
58
  }
54
59
 
55
60
  export interface AttachmentOut {
@@ -97,6 +102,7 @@ export interface BatchUpdateMessagesResponse {
97
102
  export interface CreateApiKeyRequest {
98
103
  name?: string | null;
99
104
  permissions?: Record<string, boolean> | null;
105
+ expires_at?: string | null;
100
106
  }
101
107
 
102
108
  export interface CreateApiKeyResponse {
@@ -108,6 +114,7 @@ export interface CreateApiKeyResponse {
108
114
  inbox_id?: string | null;
109
115
  permissions?: Record<string, boolean> | null;
110
116
  created_at: string;
117
+ expires_at?: string | null;
111
118
  }
112
119
 
113
120
  export interface CreateDomainRequest {
@@ -204,6 +211,26 @@ export interface DraftOut {
204
211
  created_at: string;
205
212
  }
206
213
 
214
+ export interface EventOut {
215
+ event_id: string;
216
+ event_type: string;
217
+ organization_id: string;
218
+ pod_id?: string | null;
219
+ inbox_id?: string | null;
220
+ message_id?: string | null;
221
+ thread_id?: string | null;
222
+ payload?: Record<string, unknown>;
223
+ created_at: string;
224
+ }
225
+
226
+ export interface FeedbackRequest {
227
+ message: string;
228
+ }
229
+
230
+ export interface FeedbackResponse {
231
+ received: boolean;
232
+ }
233
+
207
234
  export interface ForwardMessageRequest {
208
235
  to?: Array<string> | string | null;
209
236
  cc?: Array<string> | string | null;
@@ -286,6 +313,13 @@ export interface ListEntryOut {
286
313
  created_at: string;
287
314
  }
288
315
 
316
+ export interface ListEventsResponse {
317
+ count: number;
318
+ limit?: number | null;
319
+ next_page_token?: string | null;
320
+ events: Array<EventOut>;
321
+ }
322
+
289
323
  export interface ListInboxEventsResponse {
290
324
  count: number;
291
325
  limit?: number | null;
@@ -328,6 +362,11 @@ export interface ListThreadsResponse {
328
362
  threads: Array<ThreadItem>;
329
363
  }
330
364
 
365
+ export interface ListWebhookAttemptsResponse {
366
+ count: number;
367
+ attempts: Array<WebhookAttemptOut>;
368
+ }
369
+
331
370
  export interface ListWebhooksResponse {
332
371
  count: number;
333
372
  limit?: number | null;
@@ -378,6 +417,7 @@ export interface MessageOut {
378
417
  in_reply_to?: string | null;
379
418
  references?: Array<string>;
380
419
  headers?: Record<string, unknown>;
420
+ authentication?: Record<string, string>;
381
421
  }
382
422
 
383
423
  export interface OrganizationOut {
@@ -587,6 +627,19 @@ export interface VerificationRecord {
587
627
  priority?: number | null;
588
628
  }
589
629
 
630
+ export interface WebhookAttemptOut {
631
+ attempt_id: string;
632
+ webhook_id: string;
633
+ event_id: string;
634
+ event_type: string;
635
+ url: string;
636
+ status_code?: number | null;
637
+ ok: boolean;
638
+ detail?: string | null;
639
+ duration_ms: number;
640
+ created_at: string;
641
+ }
642
+
590
643
  export interface WebhookHeadersResponse {
591
644
  header_names: Array<string>;
592
645
  }
@@ -635,6 +688,10 @@ export declare class Billing {
635
688
  current(): Promise<Record<string, unknown>>;
636
689
  }
637
690
 
691
+ export declare class Feedback {
692
+ send(body: FeedbackRequest): Promise<FeedbackResponse>;
693
+ }
694
+
638
695
  export declare class Inboxes {
639
696
  list(query?: { limit?: number | null; pageToken?: string | null; ascending?: boolean }): Promise<ListInboxesResponse>;
640
697
  create(body: CreateInboxRequest): Promise<InboxOut>;
@@ -717,6 +774,10 @@ export declare class ApiKeys {
717
774
  deleteInbox(inboxId: string, apiKeyId: string): Promise<void>;
718
775
  }
719
776
 
777
+ export declare class Events {
778
+ list(query?: { eventTypes?: Array<string> | null; inboxId?: string | null; start?: string | null; end?: string | null; limit?: number | null; pageToken?: string | null }): Promise<ListEventsResponse>;
779
+ }
780
+
720
781
  export declare class Metrics {
721
782
  orgEvents(query?: { eventTypes?: Array<string> | null; start?: string | null; end?: string | null; period?: number | null; limit?: number | null; descending?: boolean }): Promise<Record<string, unknown>>;
722
783
  orgUsage(query?: { usageTypes?: Array<string> | null; start?: string | null; end?: string | null; period?: number | null; limit?: number | null; descending?: boolean }): Promise<Record<string, unknown>>;
@@ -779,6 +840,8 @@ export declare class InboxEvents {
779
840
  export declare class Webhooks {
780
841
  list(query?: { limit?: number | null; pageToken?: string | null; ascending?: boolean }): Promise<ListWebhooksResponse>;
781
842
  create(body: CreateWebhookRequest): Promise<WebhookOut>;
843
+ listAllAttempts(query?: { limit?: number }): Promise<ListWebhookAttemptsResponse>;
844
+ listAttempts(webhookId: string, query?: { limit?: number }): Promise<ListWebhookAttemptsResponse>;
782
845
  get(webhookId: string): Promise<WebhookOut>;
783
846
  update(webhookId: string, body: UpdateWebhookRequest): Promise<WebhookOut>;
784
847
  delete(webhookId: string): Promise<void>;
@@ -798,6 +861,7 @@ export declare class CarlyEmail {
798
861
  agent: Agent;
799
862
  auth: Auth;
800
863
  billing: Billing;
864
+ feedback: Feedback;
801
865
  inboxes: Inboxes;
802
866
  messages: Messages;
803
867
  threads: Threads;
@@ -805,6 +869,7 @@ export declare class CarlyEmail {
805
869
  lists: Lists;
806
870
  domains: Domains;
807
871
  apiKeys: ApiKeys;
872
+ events: Events;
808
873
  metrics: Metrics;
809
874
  pods: Pods;
810
875
  organizations: Organizations;
package/sdk.js CHANGED
@@ -126,6 +126,17 @@ class Billing {
126
126
  }
127
127
  }
128
128
 
129
+ class Feedback {
130
+ constructor(transport) {
131
+ this.$ = transport;
132
+ }
133
+
134
+ /** Send Feedback */
135
+ send(body) {
136
+ return this.$.request("POST", `/v0/feedback`, { body });
137
+ }
138
+ }
139
+
129
140
  class Inboxes {
130
141
  constructor(transport) {
131
142
  this.$ = transport;
@@ -473,6 +484,17 @@ class ApiKeys {
473
484
  }
474
485
  }
475
486
 
487
+ class Events {
488
+ constructor(transport) {
489
+ this.$ = transport;
490
+ }
491
+
492
+ /** List Events */
493
+ list(query = {}) {
494
+ return this.$.request("GET", `/v0/events`, { query: { "event_types": query.eventTypes, "inbox_id": query.inboxId, "start": query.start, "end": query.end, "limit": query.limit, "page_token": query.pageToken } });
495
+ }
496
+ }
497
+
476
498
  class Metrics {
477
499
  constructor(transport) {
478
500
  this.$ = transport;
@@ -747,6 +769,16 @@ class Webhooks {
747
769
  return this.$.request("POST", `/v0/webhooks`, { body });
748
770
  }
749
771
 
772
+ /** List All Attempts */
773
+ listAllAttempts(query = {}) {
774
+ return this.$.request("GET", `/v0/webhooks/attempts`, { query: { "limit": query.limit } });
775
+ }
776
+
777
+ /** List Attempts */
778
+ listAttempts(webhookId, query = {}) {
779
+ return this.$.request("GET", `/v0/webhooks/${encode(webhookId)}/attempts`, { query: { "limit": query.limit } });
780
+ }
781
+
750
782
  /** Get Webhook */
751
783
  get(webhookId) {
752
784
  return this.$.request("GET", `/v0/webhooks/${encode(webhookId)}`);
@@ -814,6 +846,7 @@ export class CarlyEmail {
814
846
  this.agent = new Agent(transport);
815
847
  this.auth = new Auth(transport);
816
848
  this.billing = new Billing(transport);
849
+ this.feedback = new Feedback(transport);
817
850
  this.inboxes = new Inboxes(transport);
818
851
  this.messages = new Messages(transport);
819
852
  this.threads = new Threads(transport);
@@ -821,6 +854,7 @@ export class CarlyEmail {
821
854
  this.lists = new Lists(transport);
822
855
  this.domains = new Domains(transport);
823
856
  this.apiKeys = new ApiKeys(transport);
857
+ this.events = new Events(transport);
824
858
  this.metrics = new Metrics(transport);
825
859
  this.pods = new Pods(transport);
826
860
  this.organizations = new Organizations(transport);