@emailens/cli 0.13.19 → 0.14.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.
package/dist/index.js CHANGED
@@ -3,44 +3,47 @@ import { createRequire as __cr } from "node:module";
3
3
  const require = __cr(import.meta.url);
4
4
  import {
5
5
  AI_FIX_SYSTEM_PROMPT,
6
- EMAIL_CLIENTS,
7
6
  EMAIL_DIRS,
8
7
  TARGETING_POLICY_ARG,
9
8
  analyzeEmail,
10
9
  auditEmail,
11
10
  compile,
12
- csstree_esm_exports,
13
11
  defineCommand,
14
- es_exports,
15
12
  estimateAiFixTokens,
16
13
  findEmailsDir,
17
14
  generateAiFix,
18
15
  generateCompatibilityScore,
19
- init_csstree_esm,
20
- init_es,
21
16
  lint_default,
22
17
  parseTargetingPolicy,
23
18
  positionsApply,
24
19
  readInput,
25
- require_boolbase,
26
- require_lib,
27
- require_mime_type,
28
20
  require_picocolors,
29
- require_undici,
30
- require_whatwg_encoding,
31
21
  resolveClients,
32
22
  resolveFormat,
33
23
  runMain,
34
24
  simulateDarkMode,
35
- toFramework,
25
+ toFramework
26
+ } from "./chunk-MCD4OEZU.js";
27
+ import {
28
+ EMAIL_CLIENTS,
29
+ csstree_esm_exports,
30
+ es_exports,
31
+ init_csstree_esm,
32
+ init_es,
33
+ require_boolbase,
34
+ require_lib,
35
+ require_mime_type,
36
+ require_undici,
37
+ require_whatwg_encoding,
36
38
  transformForAllClients
37
- } from "./chunk-J4YQYM4C.js";
38
- import "./chunk-UN26YQF6.js";
39
- import "./chunk-2AP7CT6R.js";
40
- import "./chunk-NXBRJX3V.js";
39
+ } from "./chunk-NGCLN4RF.js";
40
+ import "./chunk-LURVXP3P.js";
41
+ import "./chunk-YE65PQ5Z.js";
42
+ import "./chunk-5MSFYC7W.js";
41
43
  import {
42
44
  CompileError
43
- } from "./chunk-TQGPCAMW.js";
45
+ } from "./chunk-WAXESPJE.js";
46
+ import "./chunk-JKHKS7VL.js";
44
47
  import {
45
48
  __commonJS,
46
49
  __require,
@@ -43703,7 +43706,7 @@ Href: ${href}`
43703
43706
  // package.json
43704
43707
  var package_default = {
43705
43708
  name: "@emailens/cli",
43706
- version: "0.13.19",
43709
+ version: "0.14.2",
43707
43710
  description: "CLI tool for email compatibility analysis: lint, preview and export HTML, MJML, Maizzle and React Email rendering across 21 email clients.",
43708
43711
  type: "module",
43709
43712
  bin: {
@@ -43735,16 +43738,20 @@ var package_default = {
43735
43738
  },
43736
43739
  dependencies: {},
43737
43740
  peerDependencies: {
43738
- "playwright-core": "^1.62.1"
43741
+ "playwright-core": "^1.62.1",
43742
+ sharp: ">=0.33.0"
43739
43743
  },
43740
43744
  peerDependenciesMeta: {
43741
43745
  "playwright-core": {
43742
43746
  optional: true
43747
+ },
43748
+ sharp: {
43749
+ optional: true
43743
43750
  }
43744
43751
  },
43745
43752
  devDependencies: {
43746
43753
  "@anthropic-ai/sdk": "^0.52.0",
43747
- "@emailens/engine": "^0.18.22",
43754
+ "@emailens/engine": "^0.19.1",
43748
43755
  "@react-email/components": "1.0.12",
43749
43756
  "@types/bun": "^1.4.0",
43750
43757
  "@types/mjml": "^4.7.4",
@@ -46206,6 +46213,8 @@ async function waitForEmail(o, fetchImpl = fetch) {
46206
46213
  if (o.subject) q.set("subject", o.subject);
46207
46214
  if (o.sender) q.set("sender", o.sender);
46208
46215
  if (o.inbox) q.set("inboxId", o.inbox);
46216
+ if (o.testId) q.set("testId", o.testId);
46217
+ if (o.runId) q.set("runId", o.runId);
46209
46218
  let res;
46210
46219
  try {
46211
46220
  res = await fetchImpl(`${API_URL()}/api/sandbox/v1/messages/wait?${q}`, {
@@ -46218,17 +46227,76 @@ async function waitForEmail(o, fetchImpl = fetch) {
46218
46227
  const body = await res.json().catch(() => ({}));
46219
46228
  if (res.status === 401)
46220
46229
  return { code: 2, error: "Invalid or revoked API key (EMAILENS_API_KEY).", failures: [] };
46221
- if (!res.ok) return { code: 2, error: body.error ?? `Emailens answered ${res.status}.`, failures: [] };
46230
+ if (!res.ok) {
46231
+ if (body.ambiguous && o.testId && o.runId)
46232
+ return { code: 1, response: body, error: body.error, failures: [body.error ?? "More than one matching email arrived."] };
46233
+ return { code: 2, error: body.error ?? `Emailens answered ${res.status}.`, failures: [] };
46234
+ }
46222
46235
  const a = body.message?.analysis ?? {};
46223
46236
  const bad = (rows) => (rows ?? []).filter((r) => !r.ok).map((r) => r.text);
46224
- const failures = [
46237
+ const failures = o.testId && body.verdict ? body.verdict.reasons : [
46225
46238
  ...o.failOn === "all" || o.failOn === "check" ? bad(a.match?.rows) : [],
46226
46239
  ...o.failOn === "all" || o.failOn === "drift" ? bad(a.drift?.rows) : []
46227
46240
  ];
46228
- return { code: failures.length ? 1 : 0, response: body, failures };
46241
+ return { code: o.testId && body.verdict ? body.verdict.pass ? 0 : 1 : failures.length ? 1 : 0, response: body, failures };
46229
46242
  }
46230
- return { code: 2, error: `No matching email arrived within ${o.timeout}s.`, failures: [] };
46243
+ const error = `No matching email arrived within ${o.timeout}s.`;
46244
+ if (o.testId && o.runId) {
46245
+ try {
46246
+ await fetchImpl(`${API_URL()}/api/email-tests/${encodeURIComponent(o.testId)}/runs/${encodeURIComponent(o.runId)}`, {
46247
+ method: "PATCH",
46248
+ headers: { Authorization: `Bearer ${o.apiKey}`, "Content-Type": "application/json" },
46249
+ body: JSON.stringify({ status: "timed_out", reasons: [error] })
46250
+ });
46251
+ } catch {
46252
+ }
46253
+ }
46254
+ return { code: 2, error, failures: [] };
46231
46255
  }
46256
+ var begin = defineCommand({
46257
+ meta: { name: "begin", description: "Start a saved email test run before your app sends the staging email" },
46258
+ args: {
46259
+ testId: { type: "positional", required: true, description: "Saved email test ID" },
46260
+ "api-key": { type: "string", description: "API key (default: EMAILENS_API_KEY)" },
46261
+ json: { type: "boolean", description: "Output run metadata as JSON" }
46262
+ },
46263
+ async run({ args }) {
46264
+ const apiKey = args["api-key"] ?? process.env.EMAILENS_API_KEY;
46265
+ const testId = args.testId;
46266
+ if (!apiKey || !testId) {
46267
+ console.error(import_picocolors5.default.red(" Usage: emailens inbox begin <test-id> (set EMAILENS_API_KEY)."));
46268
+ process.exitCode = 2;
46269
+ return;
46270
+ }
46271
+ const metadata = {
46272
+ source: process.env.GITHUB_ACTIONS ? "github-action" : "cli",
46273
+ commitSha: process.env.GITHUB_SHA ?? process.env.GIT_COMMIT,
46274
+ branch: process.env.GITHUB_REF_NAME ?? process.env.GIT_BRANCH,
46275
+ environment: process.env.GITHUB_ENVIRONMENT ?? process.env.DEPLOY_ENVIRONMENT
46276
+ };
46277
+ let response;
46278
+ try {
46279
+ response = await fetch(`${API_URL()}/api/email-tests/${encodeURIComponent(testId)}/runs`, {
46280
+ method: "POST",
46281
+ headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
46282
+ body: JSON.stringify(metadata)
46283
+ });
46284
+ } catch (e) {
46285
+ console.error(import_picocolors5.default.red(` Could not reach Emailens: ${e.message}`));
46286
+ process.exitCode = 2;
46287
+ return;
46288
+ }
46289
+ const body = await response.json().catch(() => ({}));
46290
+ if (!response.ok || !body.run) {
46291
+ console.error(import_picocolors5.default.red(` ${body.error ?? `Emailens answered ${response.status}.`}`));
46292
+ process.exitCode = response.status === 401 ? 2 : 1;
46293
+ return;
46294
+ }
46295
+ const result = { testId, runId: body.run.id, startedAt: body.run.startedAt };
46296
+ if (args.json) console.log(JSON.stringify(result));
46297
+ else console.log(` Started email test run ${result.runId}`);
46298
+ }
46299
+ });
46232
46300
  var wait = defineCommand({
46233
46301
  meta: {
46234
46302
  name: "wait",
@@ -46249,6 +46317,8 @@ var wait = defineCommand({
46249
46317
  default: "all"
46250
46318
  },
46251
46319
  "api-key": { type: "string", description: "API key (default: EMAILENS_API_KEY)" },
46320
+ test: { type: "string", description: "Saved test ID; pair with --run-id" },
46321
+ "run-id": { type: "string", description: "Run ID returned by inbox begin" },
46252
46322
  json: { type: "boolean", description: "Output as JSON" }
46253
46323
  },
46254
46324
  async run({ args }) {
@@ -46258,6 +46328,10 @@ var wait = defineCommand({
46258
46328
  console.error(import_picocolors5.default.red(" Set EMAILENS_API_KEY (or pass --api-key). Keys are at app.emailens.dev/dashboard/api."));
46259
46329
  process.exit(2);
46260
46330
  }
46331
+ if (Boolean(args.test) !== Boolean(args["run-id"])) {
46332
+ console.error(import_picocolors5.default.red(" --test and --run-id must be provided together."));
46333
+ process.exit(2);
46334
+ }
46261
46335
  if (!["all", "check", "drift", "none"].includes(failOn)) {
46262
46336
  console.error(import_picocolors5.default.red(` --fail-on: all, check, drift or none, not ${failOn}.`));
46263
46337
  process.exit(2);
@@ -46276,7 +46350,9 @@ var wait = defineCommand({
46276
46350
  inbox: args.inbox,
46277
46351
  since,
46278
46352
  timeout: Math.min(600, Math.max(1, Number(args.timeout) || 60)),
46279
- failOn
46353
+ failOn,
46354
+ testId: args.test,
46355
+ runId: args["run-id"]
46280
46356
  });
46281
46357
  if (args.json) {
46282
46358
  console.log(
@@ -46331,7 +46407,7 @@ var inbox_default = defineCommand({
46331
46407
  name: "inbox",
46332
46408
  description: "Your Emailens test inbox, from CI"
46333
46409
  },
46334
- subCommands: { wait }
46410
+ subCommands: { begin, wait }
46335
46411
  });
46336
46412
 
46337
46413
  // src/commands/react-email.ts
@@ -46385,6 +46461,90 @@ Watching ${dir} for changes. Ctrl+C to stop.`))
46385
46461
  }
46386
46462
  });
46387
46463
 
46464
+ // src/commands/design.ts
46465
+ var import_picocolors7 = __toESM(require_picocolors(), 1);
46466
+ var MARK = { kept: import_picocolors7.default.green("\u2713"), changed: import_picocolors7.default.yellow("~"), broken: import_picocolors7.default.red("\u2717") };
46467
+ function designExitCode(results, strict = false) {
46468
+ const failing = results.some(
46469
+ (r) => r.verdict === "broken" || strict && r.verdict === "changed"
46470
+ );
46471
+ return failing ? 1 : 0;
46472
+ }
46473
+ var design_default = defineCommand({
46474
+ meta: {
46475
+ name: "design",
46476
+ description: "Check the email still looks like its design in each client's live preview (needs a browser)"
46477
+ },
46478
+ args: {
46479
+ input: {
46480
+ type: "positional",
46481
+ description: "HTML, JSX, MJML or Maizzle file path, or - for stdin",
46482
+ required: true
46483
+ },
46484
+ format: {
46485
+ type: "string",
46486
+ alias: "f",
46487
+ description: "Input format: html, jsx, mjml, maizzle"
46488
+ },
46489
+ clients: {
46490
+ type: "string",
46491
+ alias: "c",
46492
+ description: "Comma-separated client IDs (default: all)"
46493
+ },
46494
+ strict: {
46495
+ type: "boolean",
46496
+ description: "Fail on Needs work too, not only on Broken"
46497
+ },
46498
+ json: {
46499
+ type: "boolean",
46500
+ description: "Output as JSON"
46501
+ },
46502
+ quiet: {
46503
+ type: "boolean",
46504
+ alias: "q",
46505
+ description: "Suppress spinners and decorations"
46506
+ }
46507
+ },
46508
+ async run({ args }) {
46509
+ const spinner = args.quiet || args.json ? null : ora();
46510
+ try {
46511
+ if (args.format) resolveFormat(args.format);
46512
+ const source = await readInput(args.input);
46513
+ const format = resolveFormat(args.format, args.input, source);
46514
+ const html = await compile(source, format);
46515
+ const clientIds = resolveClients(args.clients);
46516
+ const { checkDesignAcross } = await import("./design-AAMRTVQO.js");
46517
+ spinner?.start(process.env.BROWSERLESS_URL ? "Connecting to Browserless..." : "Starting Chromium...");
46518
+ const results = await checkDesignAcross(html, clientIds, {
46519
+ framework: toFramework(format),
46520
+ onProgress: (done, total) => {
46521
+ if (spinner) spinner.text = `Checking the design (${done}/${total})...`;
46522
+ }
46523
+ });
46524
+ spinner?.stop();
46525
+ if (!results.length && !args.json) {
46526
+ console.log("No design to compare: the input is not a rendered email.");
46527
+ } else if (args.json) {
46528
+ console.log(JSON.stringify({ design: results }, null, 2));
46529
+ } else {
46530
+ for (const r of results) {
46531
+ console.log(`${MARK[r.verdict]} ${import_picocolors7.default.bold(r.name.padEnd(26))} ${r.label}`);
46532
+ if (r.verdict === "kept") continue;
46533
+ console.log(import_picocolors7.default.dim(` ${r.sentence}`));
46534
+ for (const reason of r.reasons) console.log(` - ${reason}`);
46535
+ if (r.more) console.log(import_picocolors7.default.dim(` and ${r.more} more`));
46536
+ }
46537
+ }
46538
+ const code = designExitCode(results, args.strict);
46539
+ if (code) process.exit(code);
46540
+ } catch (err) {
46541
+ spinner?.fail("Design check failed");
46542
+ console.error(err.message);
46543
+ process.exit(1);
46544
+ }
46545
+ }
46546
+ });
46547
+
46388
46548
  // src/index.ts
46389
46549
  var main2 = defineCommand({
46390
46550
  meta,
@@ -46397,7 +46557,8 @@ var main2 = defineCommand({
46397
46557
  audit: audit_default,
46398
46558
  lint: lint_default,
46399
46559
  inbox: inbox_default,
46400
- "react-email": react_email_default
46560
+ "react-email": react_email_default,
46561
+ design: design_default
46401
46562
  }
46402
46563
  });
46403
46564
  runMain(main2);
@@ -3,8 +3,9 @@ const require = __cr(import.meta.url);
3
3
  import {
4
4
  compileMaizzle,
5
5
  isMaizzle6
6
- } from "./chunk-NXBRJX3V.js";
7
- import "./chunk-TQGPCAMW.js";
6
+ } from "./chunk-5MSFYC7W.js";
7
+ import "./chunk-WAXESPJE.js";
8
+ import "./chunk-JKHKS7VL.js";
8
9
  import "./chunk-K6T7YHQE.js";
9
10
  export {
10
11
  compileMaizzle,
@@ -2,8 +2,9 @@ import { createRequire as __cr } from "node:module";
2
2
  const require = __cr(import.meta.url);
3
3
  import {
4
4
  compileMjml
5
- } from "./chunk-2AP7CT6R.js";
6
- import "./chunk-TQGPCAMW.js";
5
+ } from "./chunk-YE65PQ5Z.js";
6
+ import "./chunk-WAXESPJE.js";
7
+ import "./chunk-JKHKS7VL.js";
7
8
  import "./chunk-K6T7YHQE.js";
8
9
  export {
9
10
  compileMjml
@@ -2,8 +2,9 @@ import { createRequire as __cr } from "node:module";
2
2
  const require = __cr(import.meta.url);
3
3
  import {
4
4
  compileReactEmail
5
- } from "./chunk-UN26YQF6.js";
6
- import "./chunk-TQGPCAMW.js";
5
+ } from "./chunk-LURVXP3P.js";
6
+ import "./chunk-WAXESPJE.js";
7
+ import "./chunk-JKHKS7VL.js";
7
8
  import "./chunk-K6T7YHQE.js";
8
9
  export {
9
10
  compileReactEmail
package/dist/test.js CHANGED
@@ -5,11 +5,13 @@ import {
5
5
  auditEmail,
6
6
  flattenToLintIssues,
7
7
  loadProjectConfig
8
- } from "./chunk-J4YQYM4C.js";
9
- import "./chunk-UN26YQF6.js";
10
- import "./chunk-2AP7CT6R.js";
11
- import "./chunk-NXBRJX3V.js";
12
- import "./chunk-TQGPCAMW.js";
8
+ } from "./chunk-MCD4OEZU.js";
9
+ import "./chunk-NGCLN4RF.js";
10
+ import "./chunk-LURVXP3P.js";
11
+ import "./chunk-YE65PQ5Z.js";
12
+ import "./chunk-5MSFYC7W.js";
13
+ import "./chunk-WAXESPJE.js";
14
+ import "./chunk-JKHKS7VL.js";
13
15
  import "./chunk-K6T7YHQE.js";
14
16
 
15
17
  // src/test.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emailens/cli",
3
- "version": "0.13.19",
3
+ "version": "0.14.2",
4
4
  "description": "CLI tool for email compatibility analysis: lint, preview and export HTML, MJML, Maizzle and React Email rendering across 21 email clients.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,16 +32,20 @@
32
32
  },
33
33
  "dependencies": {},
34
34
  "peerDependencies": {
35
- "playwright-core": "^1.62.1"
35
+ "playwright-core": "^1.62.1",
36
+ "sharp": ">=0.33.0"
36
37
  },
37
38
  "peerDependenciesMeta": {
38
39
  "playwright-core": {
39
40
  "optional": true
41
+ },
42
+ "sharp": {
43
+ "optional": true
40
44
  }
41
45
  },
42
46
  "devDependencies": {
43
47
  "@anthropic-ai/sdk": "^0.52.0",
44
- "@emailens/engine": "^0.18.22",
48
+ "@emailens/engine": "^0.19.1",
45
49
  "@react-email/components": "1.0.12",
46
50
  "@types/bun": "^1.4.0",
47
51
  "@types/mjml": "^4.7.4",