@dench.com/cli 3.11.52 → 3.11.53-staging.1009

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 (2) hide show
  1. package/email.ts +94 -16
  2. package/package.json +1 -1
package/email.ts CHANGED
@@ -411,7 +411,7 @@ ${EMAIL_INBOX_HELP}
411
411
  dench email identity forward --identity <identityId|email> --off [--json] # turn forwarding off
412
412
  dench email send --from founder@example.com --to "Ada <ada@x.com>,bob@y.com" --subject "Hi" (--html-file body.html | --text "...") [--cc ...] [--bcc ...] [--from-name "Ada"] [--reply-to support@x.com] [--reply-message-id <messageId|rfc-id>] [--json]
413
413
  dench email message status --message <messageId> [--json]
414
- dench email message list [--limit 25] [--json]
414
+ dench email message list [--limit 25] [--status sent] [--cursor <nextCursor>] [--json]
415
415
  dench email template create --name "Intro" --subject "Hi {{firstName}}" --html-file body.html [--text-file body.txt] [--json]
416
416
  dench email template preview --template <id> --data '{"firstName":"Ada"}' [--json]
417
417
  dench email campaign create --name "Q2 outreach" (--mailbox you@gmail.com | --identity <identityId|fromEmail>) --template <id> [--json]
@@ -829,6 +829,86 @@ async function runDraft(ctx: EmailCliContext) {
829
829
  out(ctx, result, JSON.stringify(result, null, 2));
830
830
  }
831
831
 
832
+ type MessageLogPage = {
833
+ messages: JsonRecord[];
834
+ truncated: boolean;
835
+ nextCursor?: string;
836
+ };
837
+
838
+ /**
839
+ * Text for one message-log page. An empty page is "nothing sent yet" only
840
+ * when the walk reached the end of the log from its start: a page the scan
841
+ * budget cut short (most newest rows unreadable to the caller, e.g. a
842
+ * teammate's private inbox) says so and gives the cursor (DEN-541).
843
+ */
844
+ export function formatMessageLogPage(
845
+ page: MessageLogPage,
846
+ options: { resumed: boolean; status?: string },
847
+ ): string {
848
+ const lines = page.messages.map(
849
+ (message) =>
850
+ `${message.messageId} ${message.status} from=${message.fromEmail} subject=${JSON.stringify(message.subject)} opens=${message.openCount} clicks=${message.clickCount}`,
851
+ );
852
+ if (lines.length === 0) {
853
+ if (page.truncated) {
854
+ lines.push("No messages you can read in this part of the log.");
855
+ } else {
856
+ return options.resumed
857
+ ? "No older messages."
858
+ : "No raw messages sent yet. Use `dench email send`.";
859
+ }
860
+ } else if (page.truncated) {
861
+ lines.push(
862
+ "Stopped early: the scan limit was reached before the page filled.",
863
+ );
864
+ }
865
+ if (page.nextCursor) {
866
+ lines.push(
867
+ `More may be older: dench email message list${options.status ? ` --status ${options.status}` : ""} --cursor ${page.nextCursor}`,
868
+ );
869
+ }
870
+ return lines.join("\n");
871
+ }
872
+
873
+ function isMissingPublicFunction(error: unknown) {
874
+ const message = error instanceof Error ? error.message : String(error);
875
+ return /Could not find public function/i.test(message);
876
+ }
877
+
878
+ /**
879
+ * One message-log page. `listMessagesPage` is newer than this CLI's oldest
880
+ * supported backend, so a backend that does not have it yet answers with
881
+ * the older bare-array `listMessages` (no cursor, no truncation signal).
882
+ */
883
+ async function readMessageLogPage(
884
+ ctx: EmailCliContext,
885
+ args: { limit?: number; status?: string; cursor?: string },
886
+ ): Promise<MessageLogPage> {
887
+ try {
888
+ return (await callQuery(
889
+ ctx,
890
+ "functions/emailCampaigns:listMessagesPage",
891
+ args,
892
+ )) as MessageLogPage;
893
+ } catch (error) {
894
+ if (!isMissingPublicFunction(error)) throw error;
895
+ }
896
+ if (args.cursor) {
897
+ throw new EmailCliError(
898
+ "This workspace's server does not support --cursor yet. Run `dench email message list` without it.",
899
+ );
900
+ }
901
+ const messages = (await callQuery(
902
+ ctx,
903
+ "functions/emailCampaigns:listMessages",
904
+ {
905
+ limit: args.limit,
906
+ status: args.status,
907
+ },
908
+ )) as JsonRecord[];
909
+ return { messages, truncated: false };
910
+ }
911
+
832
912
  async function runMessage(ctx: EmailCliContext) {
833
913
  const sub = ctx.args.shift();
834
914
  if (sub === "status") {
@@ -844,24 +924,22 @@ async function runMessage(ctx: EmailCliContext) {
844
924
  if (sub === "list") {
845
925
  const limitRaw = getFlag(ctx.args, "--limit");
846
926
  const status = getFlag(ctx.args, "--status");
847
- const payload = (await callQuery(
927
+ const cursor = getFlag(ctx.args, "--cursor");
928
+ const page = await readMessageLogPage(ctx, {
929
+ limit: limitRaw ? Number(limitRaw) : undefined,
930
+ status,
931
+ cursor,
932
+ });
933
+ out(
848
934
  ctx,
849
- "functions/emailCampaigns:listMessages",
850
935
  {
851
- limit: limitRaw ? Number(limitRaw) : undefined,
852
- status,
936
+ ok: true,
937
+ messages: page.messages,
938
+ truncated: page.truncated,
939
+ ...(page.nextCursor ? { nextCursor: page.nextCursor } : {}),
853
940
  },
854
- )) as JsonRecord[];
855
- const text =
856
- payload.length === 0
857
- ? "No raw messages sent yet. Use `dench email send`."
858
- : payload
859
- .map(
860
- (message) =>
861
- `${message.messageId} ${message.status} from=${message.fromEmail} subject=${JSON.stringify(message.subject)} opens=${message.openCount} clicks=${message.clickCount}`,
862
- )
863
- .join("\n");
864
- out(ctx, { ok: true, messages: payload }, text);
941
+ formatMessageLogPage(page, { resumed: Boolean(cursor), status }),
942
+ );
865
943
  return;
866
944
  }
867
945
  throw new EmailCliError("Usage: dench email message status|list");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dench.com/cli",
3
- "version": "3.11.52",
3
+ "version": "3.11.53-staging.1009",
4
4
  "description": "Dench agent workspace CLI.",
5
5
  "type": "module",
6
6
  "bin": {