groundmail-cli 0.48.0 → 0.50.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/README.md +1 -1
- package/dist/cli.js +408 -285
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -658,8 +658,8 @@ function parseSendCommandOptions(args, env) {
|
|
|
658
658
|
};
|
|
659
659
|
}
|
|
660
660
|
function createDefaultSendDeps(apiKey, baseUrl) {
|
|
661
|
-
let
|
|
662
|
-
const getClient = () =>
|
|
661
|
+
let client3 = null;
|
|
662
|
+
const getClient = () => client3 ?? (client3 = import("groundmail").then(({ Groundmail }) => new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0)));
|
|
663
663
|
return {
|
|
664
664
|
sendEmail: async (params) => (await getClient()).emails.send(params),
|
|
665
665
|
getEmail: async (id) => (await getClient()).emails.get(id),
|
|
@@ -733,10 +733,10 @@ async function runBatchCommandWithClient(args, env = process.env) {
|
|
|
733
733
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
734
734
|
}
|
|
735
735
|
const { Groundmail } = await import("groundmail");
|
|
736
|
-
const
|
|
736
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
737
737
|
return runBatchCommand(args, {
|
|
738
738
|
env,
|
|
739
|
-
sendBatch: (emails) =>
|
|
739
|
+
sendBatch: (emails) => client3.emails.batch(emails)
|
|
740
740
|
});
|
|
741
741
|
}
|
|
742
742
|
function parseBatchPayload(source) {
|
|
@@ -789,10 +789,10 @@ async function runCancelCommandWithClient(args, env = process.env) {
|
|
|
789
789
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
790
790
|
}
|
|
791
791
|
const { Groundmail } = await import("groundmail");
|
|
792
|
-
const
|
|
792
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
793
793
|
return runCancelCommand(args, {
|
|
794
794
|
env,
|
|
795
|
-
cancelEmail: (id) =>
|
|
795
|
+
cancelEmail: (id) => client3.emails.cancel(id)
|
|
796
796
|
});
|
|
797
797
|
}
|
|
798
798
|
|
|
@@ -832,10 +832,10 @@ async function runResendCommandWithClient(args, env = process.env) {
|
|
|
832
832
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
833
833
|
}
|
|
834
834
|
const { Groundmail } = await import("groundmail");
|
|
835
|
-
const
|
|
835
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
836
836
|
return runResendCommand(args, {
|
|
837
837
|
env,
|
|
838
|
-
resendEmail: (id) =>
|
|
838
|
+
resendEmail: (id) => client3.emails.resend(id)
|
|
839
839
|
});
|
|
840
840
|
}
|
|
841
841
|
|
|
@@ -909,10 +909,10 @@ async function runGetCommandWithClient(args, env = process.env) {
|
|
|
909
909
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
910
910
|
}
|
|
911
911
|
const { Groundmail } = await import("groundmail");
|
|
912
|
-
const
|
|
912
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
913
913
|
const result = await runGetCommand(args, {
|
|
914
914
|
env,
|
|
915
|
-
getEmail: (id) =>
|
|
915
|
+
getEmail: (id) => client3.emails.get(id),
|
|
916
916
|
resolveMx: lookupMx
|
|
917
917
|
});
|
|
918
918
|
return { exitCode: result.exitCode };
|
|
@@ -954,10 +954,10 @@ async function runInsightsCommandWithClient(args, env = process.env) {
|
|
|
954
954
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
955
955
|
}
|
|
956
956
|
const { Groundmail } = await import("groundmail");
|
|
957
|
-
const
|
|
957
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
958
958
|
return runInsightsCommand(args, {
|
|
959
959
|
env,
|
|
960
|
-
getInsights: (window) =>
|
|
960
|
+
getInsights: (window) => client3.emails.insights(window)
|
|
961
961
|
});
|
|
962
962
|
}
|
|
963
963
|
|
|
@@ -1012,10 +1012,10 @@ async function runListCommandWithClient(args, env = process.env) {
|
|
|
1012
1012
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
1013
1013
|
}
|
|
1014
1014
|
const { Groundmail } = await import("groundmail");
|
|
1015
|
-
const
|
|
1015
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
1016
1016
|
return runListCommand(args, {
|
|
1017
1017
|
env,
|
|
1018
|
-
listEmails: (params) =>
|
|
1018
|
+
listEmails: (params) => client3.emails.list(params)
|
|
1019
1019
|
});
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
@@ -1062,8 +1062,8 @@ async function runSendEventCommand(args, env = process.env) {
|
|
|
1062
1062
|
}
|
|
1063
1063
|
}
|
|
1064
1064
|
try {
|
|
1065
|
-
const
|
|
1066
|
-
const result = await
|
|
1065
|
+
const client3 = await createClient(apiKey, baseUrl);
|
|
1066
|
+
const result = await client3.events.trigger({
|
|
1067
1067
|
name,
|
|
1068
1068
|
email,
|
|
1069
1069
|
user_id: userId,
|
|
@@ -1149,8 +1149,8 @@ async function runListCommand2(args, env = process.env) {
|
|
|
1149
1149
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
1150
1150
|
}
|
|
1151
1151
|
try {
|
|
1152
|
-
const
|
|
1153
|
-
const result = await
|
|
1152
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1153
|
+
const result = await client3.automations.list();
|
|
1154
1154
|
console.log(JSON.stringify(result));
|
|
1155
1155
|
return { exitCode: 0 };
|
|
1156
1156
|
} catch (error) {
|
|
@@ -1168,8 +1168,8 @@ async function runGetCommand2(args, env = process.env) {
|
|
|
1168
1168
|
const id = readFlag9(args, "--id");
|
|
1169
1169
|
if (!id) return { exitCode: 1, error: "Required flag: --id" };
|
|
1170
1170
|
try {
|
|
1171
|
-
const
|
|
1172
|
-
const result = await
|
|
1171
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1172
|
+
const result = await client3.automations.get(id);
|
|
1173
1173
|
console.log(JSON.stringify(result));
|
|
1174
1174
|
return { exitCode: 0 };
|
|
1175
1175
|
} catch (error) {
|
|
@@ -1197,8 +1197,8 @@ async function runCreateCommand(args, env = process.env) {
|
|
|
1197
1197
|
return { exitCode: 1, error: "Required: --steps or steps in --file" };
|
|
1198
1198
|
}
|
|
1199
1199
|
try {
|
|
1200
|
-
const
|
|
1201
|
-
const result = await
|
|
1200
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1201
|
+
const result = await client3.automations.create({
|
|
1202
1202
|
name,
|
|
1203
1203
|
trigger,
|
|
1204
1204
|
steps,
|
|
@@ -1230,8 +1230,8 @@ async function runUpdateCommand(args, env = process.env) {
|
|
|
1230
1230
|
};
|
|
1231
1231
|
}
|
|
1232
1232
|
try {
|
|
1233
|
-
const
|
|
1234
|
-
const result = await
|
|
1233
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1234
|
+
const result = await client3.automations.update(id, {
|
|
1235
1235
|
...name ? { name } : {},
|
|
1236
1236
|
...trigger ? { trigger } : {},
|
|
1237
1237
|
...steps ? { steps } : {},
|
|
@@ -1254,8 +1254,8 @@ async function runActivateCommand(args, env = process.env) {
|
|
|
1254
1254
|
const id = readFlag9(args, "--id");
|
|
1255
1255
|
if (!id) return { exitCode: 1, error: "Required flag: --id" };
|
|
1256
1256
|
try {
|
|
1257
|
-
const
|
|
1258
|
-
const result = await
|
|
1257
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1258
|
+
const result = await client3.automations.activate(id);
|
|
1259
1259
|
console.log(JSON.stringify(result));
|
|
1260
1260
|
return { exitCode: 0 };
|
|
1261
1261
|
} catch (error) {
|
|
@@ -1271,8 +1271,8 @@ async function runPauseCommand(args, env = process.env) {
|
|
|
1271
1271
|
const id = readFlag9(args, "--id");
|
|
1272
1272
|
if (!id) return { exitCode: 1, error: "Required flag: --id" };
|
|
1273
1273
|
try {
|
|
1274
|
-
const
|
|
1275
|
-
const result = await
|
|
1274
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1275
|
+
const result = await client3.automations.pause(id);
|
|
1276
1276
|
console.log(JSON.stringify(result));
|
|
1277
1277
|
return { exitCode: 0 };
|
|
1278
1278
|
} catch (error) {
|
|
@@ -1288,8 +1288,8 @@ async function runDeleteCommand(args, env = process.env) {
|
|
|
1288
1288
|
const id = readFlag9(args, "--id");
|
|
1289
1289
|
if (!id) return { exitCode: 1, error: "Required flag: --id" };
|
|
1290
1290
|
try {
|
|
1291
|
-
const
|
|
1292
|
-
const result = await
|
|
1291
|
+
const client3 = await createAutomationsClient(apiKey, options.baseUrl);
|
|
1292
|
+
const result = await client3.automations.remove(id);
|
|
1293
1293
|
console.log(JSON.stringify(result));
|
|
1294
1294
|
return { exitCode: 0 };
|
|
1295
1295
|
} catch (error) {
|
|
@@ -1357,9 +1357,9 @@ async function runAddCommand(args, env = process.env) {
|
|
|
1357
1357
|
};
|
|
1358
1358
|
}
|
|
1359
1359
|
try {
|
|
1360
|
-
const
|
|
1360
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1361
1361
|
const inbound = readFlag10(args, "--inbound");
|
|
1362
|
-
const result = await
|
|
1362
|
+
const result = await client3.domains.create({
|
|
1363
1363
|
name,
|
|
1364
1364
|
...inbound === "true" || inbound === "1" ? { inbound_enabled: true } : {},
|
|
1365
1365
|
...options.tenant ? { tenant: options.tenant } : {}
|
|
@@ -1418,10 +1418,10 @@ async function runApplyCommand(args, env = process.env) {
|
|
|
1418
1418
|
};
|
|
1419
1419
|
}
|
|
1420
1420
|
try {
|
|
1421
|
-
const
|
|
1421
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1422
1422
|
const dnsProvider = provider;
|
|
1423
1423
|
const useStored = !hasLocalCredentials(dnsProvider, env);
|
|
1424
|
-
const result = useStored ? await
|
|
1424
|
+
const result = useStored ? await client3.domains.apply(idOrName, { provider: dnsProvider }) : await client3.domains.applyDns({
|
|
1425
1425
|
idOrName,
|
|
1426
1426
|
provider: dnsProvider,
|
|
1427
1427
|
cloudflareApiToken: env.CLOUDFLARE_API_TOKEN || env.CLOUDFLARE_API_KEY,
|
|
@@ -1460,8 +1460,8 @@ async function runDeleteCommand2(args, env = process.env) {
|
|
|
1460
1460
|
const idOrName = options.id || options.name || readFirstPositional2(args);
|
|
1461
1461
|
if (!idOrName) return { exitCode: 1, error: "Missing domain. Usage: groundmail domains delete example.com" };
|
|
1462
1462
|
try {
|
|
1463
|
-
const
|
|
1464
|
-
console.log(JSON.stringify(await
|
|
1463
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1464
|
+
console.log(JSON.stringify(await client3.domains.delete(idOrName)));
|
|
1465
1465
|
return { exitCode: 0 };
|
|
1466
1466
|
} catch (error) {
|
|
1467
1467
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -1488,8 +1488,8 @@ async function runGetCommand3(args, env = process.env) {
|
|
|
1488
1488
|
const idOrName = options.id || options.name || readFirstPositional3(args);
|
|
1489
1489
|
if (!idOrName) return { exitCode: 1, error: "Missing domain. Usage: groundmail domains get example.com" };
|
|
1490
1490
|
try {
|
|
1491
|
-
const
|
|
1492
|
-
console.log(JSON.stringify(await
|
|
1491
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1492
|
+
console.log(JSON.stringify(await client3.domains.get(idOrName)));
|
|
1493
1493
|
return { exitCode: 0 };
|
|
1494
1494
|
} catch (error) {
|
|
1495
1495
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -1515,8 +1515,8 @@ async function runListCommand3(args, env = process.env) {
|
|
|
1515
1515
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
1516
1516
|
}
|
|
1517
1517
|
try {
|
|
1518
|
-
const
|
|
1519
|
-
const result = await
|
|
1518
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1519
|
+
const result = await client3.domains.list(options.tenant ? { tenant: options.tenant } : {});
|
|
1520
1520
|
console.log(JSON.stringify(result));
|
|
1521
1521
|
return { exitCode: 0 };
|
|
1522
1522
|
} catch (error) {
|
|
@@ -1621,8 +1621,8 @@ async function runUpdateCommand2(args, env = process.env) {
|
|
|
1621
1621
|
error: "No updates provided. Pass --inbound true|false, --tls-mode opportunistic|enforced, --open-tracking true|false, --click-tracking true|false, --inbound-spam-threshold <1-100|default>, --inbound-spam-action flag|drop, --inbound-forward-url <https://\u2026|none>, or --inbound-forward-secret <secret|none>."
|
|
1622
1622
|
};
|
|
1623
1623
|
}
|
|
1624
|
-
const
|
|
1625
|
-
console.log(JSON.stringify(await
|
|
1624
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1625
|
+
console.log(JSON.stringify(await client3.domains.update(idOrName, payload)));
|
|
1626
1626
|
return { exitCode: 0 };
|
|
1627
1627
|
} catch (error) {
|
|
1628
1628
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -1644,8 +1644,8 @@ async function runVerifyCommand(args, env = process.env) {
|
|
|
1644
1644
|
};
|
|
1645
1645
|
}
|
|
1646
1646
|
try {
|
|
1647
|
-
const
|
|
1648
|
-
const result = await
|
|
1647
|
+
const client3 = await createDomainsClient(apiKey, options.baseUrl);
|
|
1648
|
+
const result = await client3.domains.verify(idOrName);
|
|
1649
1649
|
console.log(JSON.stringify(result));
|
|
1650
1650
|
if (result.verified) {
|
|
1651
1651
|
console.error(`Domain ${result.domain.name} verified.`);
|
|
@@ -1701,8 +1701,8 @@ async function runGetCommand4(args, env = process.env) {
|
|
|
1701
1701
|
return { exitCode: 1, error: "Missing id. Usage: groundmail received-emails get inb_..." };
|
|
1702
1702
|
}
|
|
1703
1703
|
try {
|
|
1704
|
-
const
|
|
1705
|
-
console.log(JSON.stringify(await
|
|
1704
|
+
const client3 = await createReceivedEmailsClient(apiKey, options.baseUrl);
|
|
1705
|
+
console.log(JSON.stringify(await client3.receivedEmails.get(id)));
|
|
1706
1706
|
return { exitCode: 0 };
|
|
1707
1707
|
} catch (error) {
|
|
1708
1708
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -1717,10 +1717,10 @@ async function runListCommand4(args, env = process.env) {
|
|
|
1717
1717
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
1718
1718
|
}
|
|
1719
1719
|
try {
|
|
1720
|
-
const
|
|
1720
|
+
const client3 = await createReceivedEmailsClient(apiKey, options.baseUrl);
|
|
1721
1721
|
console.log(
|
|
1722
1722
|
JSON.stringify(
|
|
1723
|
-
await
|
|
1723
|
+
await client3.receivedEmails.list({
|
|
1724
1724
|
limit: readFlag11(args, "--limit") ? Number(readFlag11(args, "--limit")) : void 0,
|
|
1725
1725
|
cursor: readFlag11(args, "--cursor"),
|
|
1726
1726
|
domain: readFlag11(args, "--domain"),
|
|
@@ -1875,10 +1875,10 @@ async function runCreateCommand2(args, env = process.env) {
|
|
|
1875
1875
|
return { exitCode: 1, error: "Required flag: --url" };
|
|
1876
1876
|
}
|
|
1877
1877
|
try {
|
|
1878
|
-
const
|
|
1878
|
+
const client3 = await createWebhooksClient(apiKey, options.baseUrl);
|
|
1879
1879
|
const tenants = parseTenantsList(readFlag13(args, "--tenants"));
|
|
1880
1880
|
const mailboxes = parseTenantsList(readFlag13(args, "--mailboxes"));
|
|
1881
|
-
const result = await
|
|
1881
|
+
const result = await client3.webhooks.create({
|
|
1882
1882
|
url,
|
|
1883
1883
|
...tenants?.length ? { tenants } : {},
|
|
1884
1884
|
...mailboxes?.length ? { mailboxes } : {}
|
|
@@ -1899,8 +1899,8 @@ async function runGetCommand5(args, env = process.env) {
|
|
|
1899
1899
|
const id = readFlag14(args, "--id") || readFirstPositional6(args);
|
|
1900
1900
|
if (!id) return { exitCode: 1, error: "Missing webhook id. Pass --id wh_\u2026" };
|
|
1901
1901
|
try {
|
|
1902
|
-
const
|
|
1903
|
-
console.log(JSON.stringify(await
|
|
1902
|
+
const client3 = await createWebhooksClient(apiKey, options.baseUrl);
|
|
1903
|
+
console.log(JSON.stringify(await client3.webhooks.get(id)));
|
|
1904
1904
|
return { exitCode: 0 };
|
|
1905
1905
|
} catch (error) {
|
|
1906
1906
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -1934,8 +1934,8 @@ async function runDeleteCommand3(args, env = process.env) {
|
|
|
1934
1934
|
return { exitCode: 1, error: "Required flag: --id" };
|
|
1935
1935
|
}
|
|
1936
1936
|
try {
|
|
1937
|
-
const
|
|
1938
|
-
const result = await
|
|
1937
|
+
const client3 = await createWebhooksClient(apiKey, options.baseUrl);
|
|
1938
|
+
const result = await client3.webhooks.delete(id);
|
|
1939
1939
|
console.log(JSON.stringify(result));
|
|
1940
1940
|
return { exitCode: 0 };
|
|
1941
1941
|
} catch (error) {
|
|
@@ -1951,8 +1951,8 @@ async function runListCommand5(args, env = process.env) {
|
|
|
1951
1951
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
1952
1952
|
}
|
|
1953
1953
|
try {
|
|
1954
|
-
const
|
|
1955
|
-
const result = await
|
|
1954
|
+
const client3 = await createWebhooksClient(apiKey, options.baseUrl);
|
|
1955
|
+
const result = await client3.webhooks.list();
|
|
1956
1956
|
console.log(JSON.stringify(result));
|
|
1957
1957
|
return { exitCode: 0 };
|
|
1958
1958
|
} catch (error) {
|
|
@@ -1985,8 +1985,8 @@ async function runUpdateCommand3(args, env = process.env) {
|
|
|
1985
1985
|
...mailboxes !== void 0 ? { mailboxes } : {}
|
|
1986
1986
|
};
|
|
1987
1987
|
try {
|
|
1988
|
-
const
|
|
1989
|
-
console.log(JSON.stringify(await
|
|
1988
|
+
const client3 = await createWebhooksClient(apiKey, options.baseUrl);
|
|
1989
|
+
console.log(JSON.stringify(await client3.webhooks.update(id, payload)));
|
|
1990
1990
|
return { exitCode: 0 };
|
|
1991
1991
|
} catch (error) {
|
|
1992
1992
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -2085,11 +2085,11 @@ async function runListKeysCommandWithClient(args, env = process.env) {
|
|
|
2085
2085
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
2086
2086
|
}
|
|
2087
2087
|
const { Groundmail } = await import("groundmail");
|
|
2088
|
-
const
|
|
2088
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
2089
2089
|
try {
|
|
2090
2090
|
const limitRaw = readFlag16(args, "--limit");
|
|
2091
2091
|
const cursor = readFlag16(args, "--cursor");
|
|
2092
|
-
const result = await
|
|
2092
|
+
const result = await client3.apiKeys.list({
|
|
2093
2093
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
2094
2094
|
...cursor ? { cursor } : {}
|
|
2095
2095
|
});
|
|
@@ -2103,7 +2103,7 @@ async function runListKeysCommandWithClient(args, env = process.env) {
|
|
|
2103
2103
|
}
|
|
2104
2104
|
|
|
2105
2105
|
// package.json
|
|
2106
|
-
var version = "0.
|
|
2106
|
+
var version = "0.50.0";
|
|
2107
2107
|
|
|
2108
2108
|
// src/help.ts
|
|
2109
2109
|
var USAGE_LINES = [
|
|
@@ -2187,6 +2187,13 @@ var USAGE_LINES = [
|
|
|
2187
2187
|
" groundmail suppressions remove --id <id> | --email user@example.com [--tenant <tenant>]",
|
|
2188
2188
|
" groundmail suppressions list --type category_opt_out [--category product|newsletter] [--tenant <tenant> | --include-tenants] one-click category unsubscribes",
|
|
2189
2189
|
" groundmail suppressions remove --type category_opt_out --email user@example.com [--category newsletter] [--tenant <tenant>] re-subscribe to a category",
|
|
2190
|
+
" groundmail routes list <domain> email routing: what happens to mail for each address",
|
|
2191
|
+
" groundmail routes add <domain> --address support --action url --url https://\u2026 [--secret \u2026] send an address to your app (raw message)",
|
|
2192
|
+
" groundmail routes add <domain> --address billing --action forward --forward-to you@example.com forward an address (it confirms first)",
|
|
2193
|
+
" groundmail routes add <domain> --address noreply --action drop|keep drop mail, or keep it in Inbound",
|
|
2194
|
+
" groundmail routes update <domain> <route-id> [--action \u2026] [--url \u2026] [--forward-to \u2026]",
|
|
2195
|
+
" groundmail routes remove <domain> <route-id>",
|
|
2196
|
+
" groundmail routes test <domain> [--address support] send a real test email through routing",
|
|
2190
2197
|
" groundmail templates list [--status draft|published]",
|
|
2191
2198
|
" groundmail templates starters",
|
|
2192
2199
|
" groundmail templates from-starter password-reset",
|
|
@@ -2226,6 +2233,7 @@ var USAGE_LINES = [
|
|
|
2226
2233
|
" groundmail migrate mailgun [--dry-run] [--only \u2026] [--region eu] import from Mailgun (Beta)",
|
|
2227
2234
|
" groundmail migrate resend [--dry-run] [--only \u2026] import from Resend (Beta; a Full access key)",
|
|
2228
2235
|
" groundmail migrate ses --region us-east-1 [--dry-run] [--only \u2026] import one Amazon SES region (Beta)",
|
|
2236
|
+
" groundmail migrate azure --subscription <id> [--dry-run] [--only \u2026] import from Azure Communication Services (Beta; connect Azure first)",
|
|
2229
2237
|
" groundmail migrate list your recent imports",
|
|
2230
2238
|
" groundmail migrate report <id> [--csv] an import report (JSON, or CSV to stdout)",
|
|
2231
2239
|
" groundmail integrations twilio status",
|
|
@@ -2439,15 +2447,15 @@ function parseArgs(argv, spec) {
|
|
|
2439
2447
|
const booleanFlags = new Set(spec.booleans ?? []);
|
|
2440
2448
|
const values = {};
|
|
2441
2449
|
const booleans = {};
|
|
2442
|
-
const
|
|
2450
|
+
const positionals4 = [];
|
|
2443
2451
|
for (let i = 0; i < argv.length; i++) {
|
|
2444
2452
|
const arg = argv[i];
|
|
2445
2453
|
if (arg === "--") {
|
|
2446
|
-
|
|
2454
|
+
positionals4.push(...argv.slice(i + 1));
|
|
2447
2455
|
break;
|
|
2448
2456
|
}
|
|
2449
2457
|
if (!arg.startsWith("--") || arg === "-") {
|
|
2450
|
-
|
|
2458
|
+
positionals4.push(arg);
|
|
2451
2459
|
continue;
|
|
2452
2460
|
}
|
|
2453
2461
|
const eq = arg.indexOf("=");
|
|
@@ -2473,7 +2481,7 @@ function parseArgs(argv, spec) {
|
|
|
2473
2481
|
const known = [...valueFlags, ...booleanFlags].sort().join(", ");
|
|
2474
2482
|
return { ok: false, error: `Unknown flag ${name}.${known ? ` This command takes: ${known}.` : ""}` };
|
|
2475
2483
|
}
|
|
2476
|
-
return { ok: true, args: { values, booleans, positionals:
|
|
2484
|
+
return { ok: true, args: { values, booleans, positionals: positionals4 } };
|
|
2477
2485
|
}
|
|
2478
2486
|
function wantsJson(args, stdout = process.stdout) {
|
|
2479
2487
|
if (args.booleans["--json"] !== void 0) return args.booleans["--json"];
|
|
@@ -3292,9 +3300,9 @@ async function runDeleteKeyCommandWithClient(args, env = process.env) {
|
|
|
3292
3300
|
return { exitCode: 1, error: "Required: --id <api-key-id>" };
|
|
3293
3301
|
}
|
|
3294
3302
|
const { Groundmail } = await import("groundmail");
|
|
3295
|
-
const
|
|
3303
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
3296
3304
|
try {
|
|
3297
|
-
const result = await
|
|
3305
|
+
const result = await client3.apiKeys.remove(id);
|
|
3298
3306
|
console.log(JSON.stringify(result));
|
|
3299
3307
|
return { exitCode: 0 };
|
|
3300
3308
|
} catch (error) {
|
|
@@ -3332,7 +3340,7 @@ async function runListCommand6(args, env = process.env) {
|
|
|
3332
3340
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3333
3341
|
}
|
|
3334
3342
|
try {
|
|
3335
|
-
const
|
|
3343
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
3336
3344
|
const limitRaw = readFlag19(args, "--limit");
|
|
3337
3345
|
const cursor = readFlag19(args, "--cursor");
|
|
3338
3346
|
const email = readFlag19(args, "--email");
|
|
@@ -3346,7 +3354,7 @@ async function runListCommand6(args, env = process.env) {
|
|
|
3346
3354
|
if (category && category !== "product" && category !== "newsletter") {
|
|
3347
3355
|
return { exitCode: 1, error: "--category must be product or newsletter" };
|
|
3348
3356
|
}
|
|
3349
|
-
const optOuts = await
|
|
3357
|
+
const optOuts = await client3.suppressions.listCategoryOptOuts({
|
|
3350
3358
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
3351
3359
|
...cursor ? { cursor } : {},
|
|
3352
3360
|
...email ? { email } : {},
|
|
@@ -3357,7 +3365,7 @@ async function runListCommand6(args, env = process.env) {
|
|
|
3357
3365
|
console.log(JSON.stringify(optOuts));
|
|
3358
3366
|
return { exitCode: 0 };
|
|
3359
3367
|
}
|
|
3360
|
-
const result = await
|
|
3368
|
+
const result = await client3.suppressions.list({
|
|
3361
3369
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
3362
3370
|
...cursor ? { cursor } : {},
|
|
3363
3371
|
...email ? { email } : {},
|
|
@@ -3383,9 +3391,9 @@ async function runAddCommand2(args, env = process.env) {
|
|
|
3383
3391
|
return { exitCode: 1, error: "Missing email. Pass --email user@example.com" };
|
|
3384
3392
|
}
|
|
3385
3393
|
try {
|
|
3386
|
-
const
|
|
3394
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
3387
3395
|
const reason = readFlag19(args, "--reason");
|
|
3388
|
-
const result = await
|
|
3396
|
+
const result = await client3.suppressions.create({
|
|
3389
3397
|
email,
|
|
3390
3398
|
...reason ? { reason } : {},
|
|
3391
3399
|
...tenant ? { tenant } : {}
|
|
@@ -3420,16 +3428,16 @@ async function runRemoveCommand(args, env = process.env) {
|
|
|
3420
3428
|
return { exitCode: 1, error: "Missing id or email. Pass --id <uuid> or --email user@example.com" };
|
|
3421
3429
|
}
|
|
3422
3430
|
try {
|
|
3423
|
-
const
|
|
3431
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
3424
3432
|
if (type === "category_opt_out") {
|
|
3425
|
-
const optOut = await
|
|
3433
|
+
const optOut = await client3.suppressions.removeCategoryOptOut(idOrEmail, {
|
|
3426
3434
|
...category ? { category } : {},
|
|
3427
3435
|
...tenant ? { tenant } : {}
|
|
3428
3436
|
});
|
|
3429
3437
|
console.log(JSON.stringify(optOut));
|
|
3430
3438
|
return { exitCode: 0 };
|
|
3431
3439
|
}
|
|
3432
|
-
const result = tenant ? await
|
|
3440
|
+
const result = tenant ? await client3.suppressions.remove(idOrEmail, { tenant }) : await client3.suppressions.remove(idOrEmail);
|
|
3433
3441
|
console.log(JSON.stringify(result));
|
|
3434
3442
|
return { exitCode: 0 };
|
|
3435
3443
|
} catch (error) {
|
|
@@ -3437,16 +3445,104 @@ async function runRemoveCommand(args, env = process.env) {
|
|
|
3437
3445
|
}
|
|
3438
3446
|
}
|
|
3439
3447
|
|
|
3440
|
-
// src/commands/
|
|
3448
|
+
// src/commands/routes/routes.ts
|
|
3441
3449
|
function readFlag20(args, flag) {
|
|
3450
|
+
const index = args.indexOf(flag);
|
|
3451
|
+
return index === -1 ? void 0 : args[index + 1];
|
|
3452
|
+
}
|
|
3453
|
+
var VALUE_FLAGS2 = ["--api-key", "--base-url", "--address", "--action", "--url", "--secret", "--forward-to", "--skip-spam", "--id"];
|
|
3454
|
+
function positionals2(args) {
|
|
3455
|
+
const out = [];
|
|
3456
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
3457
|
+
if (args[i].startsWith("--")) {
|
|
3458
|
+
if (VALUE_FLAGS2.includes(args[i])) i += 1;
|
|
3459
|
+
continue;
|
|
3460
|
+
}
|
|
3461
|
+
out.push(args[i]);
|
|
3462
|
+
}
|
|
3463
|
+
return out;
|
|
3464
|
+
}
|
|
3465
|
+
async function client(args, env) {
|
|
3466
|
+
const apiKey = readFlag20(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
3467
|
+
if (!apiKey) return null;
|
|
3468
|
+
const baseUrl = readFlag20(args, "--base-url");
|
|
3469
|
+
const { Groundmail } = await import("groundmail");
|
|
3470
|
+
return new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
3471
|
+
}
|
|
3472
|
+
var ACTIONS = ["url", "forward", "keep", "drop"];
|
|
3473
|
+
function routeParams(args) {
|
|
3474
|
+
const params = {};
|
|
3475
|
+
const action = readFlag20(args, "--action");
|
|
3476
|
+
if (action !== void 0) {
|
|
3477
|
+
if (!ACTIONS.includes(action)) return { ok: false, error: "--action must be url, forward, keep or drop" };
|
|
3478
|
+
params.action = action;
|
|
3479
|
+
}
|
|
3480
|
+
const url = readFlag20(args, "--url");
|
|
3481
|
+
if (url !== void 0) params.url = url;
|
|
3482
|
+
const secret = readFlag20(args, "--secret");
|
|
3483
|
+
if (secret !== void 0) params.secret = secret === "none" ? null : secret;
|
|
3484
|
+
const forwardTo = readFlag20(args, "--forward-to");
|
|
3485
|
+
if (forwardTo !== void 0) params.forwardTo = forwardTo;
|
|
3486
|
+
const skipSpam = readFlag20(args, "--skip-spam");
|
|
3487
|
+
if (skipSpam !== void 0) {
|
|
3488
|
+
if (skipSpam !== "true" && skipSpam !== "false") return { ok: false, error: "--skip-spam must be true or false" };
|
|
3489
|
+
params.skipSpam = skipSpam === "true";
|
|
3490
|
+
}
|
|
3491
|
+
return { ok: true, params };
|
|
3492
|
+
}
|
|
3493
|
+
async function runRoutesCommand(subcommand, args, env = process.env) {
|
|
3494
|
+
const gm = await client(args, env);
|
|
3495
|
+
if (!gm) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3496
|
+
const [domain, routeId] = positionals2(args);
|
|
3497
|
+
if (!domain) return { exitCode: 1, error: "Missing domain. Usage: groundmail routes <list|add|update|remove|test> <domain> \u2026" };
|
|
3498
|
+
try {
|
|
3499
|
+
if (subcommand === "list") {
|
|
3500
|
+
console.log(JSON.stringify(await gm.routes.list(domain)));
|
|
3501
|
+
return { exitCode: 0 };
|
|
3502
|
+
}
|
|
3503
|
+
if (subcommand === "add" || subcommand === "create") {
|
|
3504
|
+
const address = readFlag20(args, "--address");
|
|
3505
|
+
if (!address) return { exitCode: 1, error: "Missing --address (a local part such as support, or *)" };
|
|
3506
|
+
const parsed = routeParams(args);
|
|
3507
|
+
if (!parsed.ok) return { exitCode: 1, error: parsed.error };
|
|
3508
|
+
if (!parsed.params.action) return { exitCode: 1, error: "Missing --action url|forward|keep|drop" };
|
|
3509
|
+
console.log(JSON.stringify(await gm.routes.create(domain, { address, ...parsed.params })));
|
|
3510
|
+
return { exitCode: 0 };
|
|
3511
|
+
}
|
|
3512
|
+
if (subcommand === "update") {
|
|
3513
|
+
const id = readFlag20(args, "--id") ?? routeId;
|
|
3514
|
+
if (!id) return { exitCode: 1, error: "Missing route id" };
|
|
3515
|
+
const parsed = routeParams(args);
|
|
3516
|
+
if (!parsed.ok) return { exitCode: 1, error: parsed.error };
|
|
3517
|
+
console.log(JSON.stringify(await gm.routes.update(domain, id, parsed.params)));
|
|
3518
|
+
return { exitCode: 0 };
|
|
3519
|
+
}
|
|
3520
|
+
if (subcommand === "remove" || subcommand === "delete") {
|
|
3521
|
+
const id = readFlag20(args, "--id") ?? routeId;
|
|
3522
|
+
if (!id) return { exitCode: 1, error: "Missing route id" };
|
|
3523
|
+
console.log(JSON.stringify(await gm.routes.remove(domain, id)));
|
|
3524
|
+
return { exitCode: 0 };
|
|
3525
|
+
}
|
|
3526
|
+
if (subcommand === "test") {
|
|
3527
|
+
console.log(JSON.stringify(await gm.routes.test(domain, readFlag20(args, "--address"))));
|
|
3528
|
+
return { exitCode: 0 };
|
|
3529
|
+
}
|
|
3530
|
+
return { exitCode: 1, error: "Usage: groundmail routes <list|add|update|remove|test> <domain> \u2026" };
|
|
3531
|
+
} catch (error) {
|
|
3532
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3536
|
+
// src/commands/templates/shared.ts
|
|
3537
|
+
function readFlag21(args, flag) {
|
|
3442
3538
|
const index = args.indexOf(flag);
|
|
3443
3539
|
if (index === -1) return void 0;
|
|
3444
3540
|
return args[index + 1];
|
|
3445
3541
|
}
|
|
3446
3542
|
function parseTemplatesCommonArgs(args) {
|
|
3447
3543
|
return {
|
|
3448
|
-
apiKey:
|
|
3449
|
-
baseUrl:
|
|
3544
|
+
apiKey: readFlag21(args, "--api-key"),
|
|
3545
|
+
baseUrl: readFlag21(args, "--base-url")
|
|
3450
3546
|
};
|
|
3451
3547
|
}
|
|
3452
3548
|
function resolveApiKey8(options, env) {
|
|
@@ -3463,11 +3559,11 @@ async function runDeleteCommand4(args, env = process.env) {
|
|
|
3463
3559
|
const options = parseTemplatesCommonArgs(args);
|
|
3464
3560
|
const apiKey = resolveApiKey8(options, env);
|
|
3465
3561
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3466
|
-
const idOrAlias =
|
|
3562
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional8(args);
|
|
3467
3563
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3468
3564
|
try {
|
|
3469
|
-
const
|
|
3470
|
-
console.log(JSON.stringify(await
|
|
3565
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3566
|
+
console.log(JSON.stringify(await client3.templates.remove(idOrAlias)));
|
|
3471
3567
|
return { exitCode: 0 };
|
|
3472
3568
|
} catch (error) {
|
|
3473
3569
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3491,12 +3587,12 @@ async function runDuplicateCommand(args, env = process.env) {
|
|
|
3491
3587
|
const options = parseTemplatesCommonArgs(args);
|
|
3492
3588
|
const apiKey = resolveApiKey8(options, env);
|
|
3493
3589
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3494
|
-
const idOrAlias =
|
|
3590
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional9(args);
|
|
3495
3591
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3496
|
-
const name =
|
|
3592
|
+
const name = readFlag21(args, "--name");
|
|
3497
3593
|
try {
|
|
3498
|
-
const
|
|
3499
|
-
console.log(JSON.stringify(await
|
|
3594
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3595
|
+
console.log(JSON.stringify(await client3.templates.duplicate(idOrAlias, name ? { name } : {})));
|
|
3500
3596
|
return { exitCode: 0 };
|
|
3501
3597
|
} catch (error) {
|
|
3502
3598
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3520,11 +3616,11 @@ async function runGetCommand6(args, env = process.env) {
|
|
|
3520
3616
|
const options = parseTemplatesCommonArgs(args);
|
|
3521
3617
|
const apiKey = resolveApiKey8(options, env);
|
|
3522
3618
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3523
|
-
const idOrAlias =
|
|
3619
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional10(args);
|
|
3524
3620
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3525
3621
|
try {
|
|
3526
|
-
const
|
|
3527
|
-
console.log(JSON.stringify(await
|
|
3622
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3623
|
+
console.log(JSON.stringify(await client3.templates.get(idOrAlias)));
|
|
3528
3624
|
return { exitCode: 0 };
|
|
3529
3625
|
} catch (error) {
|
|
3530
3626
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3550,11 +3646,11 @@ async function runListCommand7(args, env = process.env) {
|
|
|
3550
3646
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3551
3647
|
}
|
|
3552
3648
|
try {
|
|
3553
|
-
const
|
|
3554
|
-
const limitRaw =
|
|
3555
|
-
const cursor =
|
|
3556
|
-
const status =
|
|
3557
|
-
const result = await
|
|
3649
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3650
|
+
const limitRaw = readFlag21(args, "--limit");
|
|
3651
|
+
const cursor = readFlag21(args, "--cursor");
|
|
3652
|
+
const status = readFlag21(args, "--status");
|
|
3653
|
+
const result = await client3.templates.list({
|
|
3558
3654
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
3559
3655
|
...cursor ? { cursor } : {},
|
|
3560
3656
|
...status ? { status } : {}
|
|
@@ -3572,11 +3668,11 @@ async function runPublishCommand(args, env = process.env) {
|
|
|
3572
3668
|
const options = parseTemplatesCommonArgs(args);
|
|
3573
3669
|
const apiKey = resolveApiKey8(options, env);
|
|
3574
3670
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3575
|
-
const idOrAlias =
|
|
3671
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional11(args);
|
|
3576
3672
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3577
3673
|
try {
|
|
3578
|
-
const
|
|
3579
|
-
console.log(JSON.stringify(await
|
|
3674
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3675
|
+
console.log(JSON.stringify(await client3.templates.publish(idOrAlias)));
|
|
3580
3676
|
return { exitCode: 0 };
|
|
3581
3677
|
} catch (error) {
|
|
3582
3678
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3684,7 +3780,7 @@ async function loadTemplateSource(filePath, options = {}, deps = {}) {
|
|
|
3684
3780
|
}
|
|
3685
3781
|
|
|
3686
3782
|
// src/commands/templates/push.ts
|
|
3687
|
-
var
|
|
3783
|
+
var VALUE_FLAGS3 = /* @__PURE__ */ new Set([
|
|
3688
3784
|
"--alias",
|
|
3689
3785
|
"--subject",
|
|
3690
3786
|
"--name",
|
|
@@ -3698,7 +3794,7 @@ function readPositional(args) {
|
|
|
3698
3794
|
for (let index = 0; index < args.length; index += 1) {
|
|
3699
3795
|
const arg = args[index];
|
|
3700
3796
|
if (arg.startsWith("--")) {
|
|
3701
|
-
if (
|
|
3797
|
+
if (VALUE_FLAGS3.has(arg)) index += 1;
|
|
3702
3798
|
continue;
|
|
3703
3799
|
}
|
|
3704
3800
|
return arg;
|
|
@@ -3715,19 +3811,19 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3715
3811
|
if (!apiKey) {
|
|
3716
3812
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3717
3813
|
}
|
|
3718
|
-
const file =
|
|
3814
|
+
const file = readFlag21(args, "--file") ?? readPositional(args);
|
|
3719
3815
|
if (!file) {
|
|
3720
3816
|
return { exitCode: 1, error: "Missing template file. Usage: templates push <file> --alias <alias>" };
|
|
3721
3817
|
}
|
|
3722
|
-
const alias =
|
|
3818
|
+
const alias = readFlag21(args, "--alias");
|
|
3723
3819
|
if (!alias) {
|
|
3724
3820
|
return { exitCode: 1, error: "Missing --alias. The alias identifies which template to update." };
|
|
3725
3821
|
}
|
|
3726
|
-
const subject =
|
|
3727
|
-
const name =
|
|
3728
|
-
const preheader =
|
|
3729
|
-
const textFile =
|
|
3730
|
-
const propsRaw =
|
|
3822
|
+
const subject = readFlag21(args, "--subject");
|
|
3823
|
+
const name = readFlag21(args, "--name");
|
|
3824
|
+
const preheader = readFlag21(args, "--preheader");
|
|
3825
|
+
const textFile = readFlag21(args, "--text");
|
|
3826
|
+
const propsRaw = readFlag21(args, "--props");
|
|
3731
3827
|
const shouldPublish = args.includes("--publish");
|
|
3732
3828
|
let props = {};
|
|
3733
3829
|
if (propsRaw) {
|
|
@@ -3751,10 +3847,10 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3751
3847
|
return { exitCode: 1, error: `${file} produced no content to push.` };
|
|
3752
3848
|
}
|
|
3753
3849
|
const createClient2 = deps.createClient ?? createTemplatesClient;
|
|
3754
|
-
const
|
|
3850
|
+
const client3 = await createClient2(apiKey, options.baseUrl);
|
|
3755
3851
|
let existed = true;
|
|
3756
3852
|
try {
|
|
3757
|
-
await
|
|
3853
|
+
await client3.templates.get(alias);
|
|
3758
3854
|
} catch (error) {
|
|
3759
3855
|
if (statusOf(error) !== 404) throw error;
|
|
3760
3856
|
existed = false;
|
|
@@ -3769,7 +3865,7 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3769
3865
|
};
|
|
3770
3866
|
let result;
|
|
3771
3867
|
if (existed) {
|
|
3772
|
-
result = await
|
|
3868
|
+
result = await client3.templates.update(alias, body);
|
|
3773
3869
|
} else {
|
|
3774
3870
|
if (!subject) {
|
|
3775
3871
|
return {
|
|
@@ -3777,7 +3873,7 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3777
3873
|
error: `Template "${alias}" does not exist yet. Pass --subject to create it.`
|
|
3778
3874
|
};
|
|
3779
3875
|
}
|
|
3780
|
-
result = await
|
|
3876
|
+
result = await client3.templates.create({
|
|
3781
3877
|
name: name || alias,
|
|
3782
3878
|
subject,
|
|
3783
3879
|
alias,
|
|
@@ -3785,7 +3881,7 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3785
3881
|
});
|
|
3786
3882
|
}
|
|
3787
3883
|
if (shouldPublish) {
|
|
3788
|
-
result = await
|
|
3884
|
+
result = await client3.templates.publish(alias);
|
|
3789
3885
|
}
|
|
3790
3886
|
console.log(JSON.stringify({ ...result, pushed: { file, alias, created: !existed } }));
|
|
3791
3887
|
return { exitCode: 0 };
|
|
@@ -3801,14 +3897,14 @@ async function runCreateCommand3(args, env = process.env) {
|
|
|
3801
3897
|
if (!apiKey) {
|
|
3802
3898
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3803
3899
|
}
|
|
3804
|
-
const name =
|
|
3805
|
-
const subject =
|
|
3806
|
-
const html =
|
|
3807
|
-
const text =
|
|
3808
|
-
const alias =
|
|
3809
|
-
const category =
|
|
3810
|
-
const folder =
|
|
3811
|
-
const sender =
|
|
3900
|
+
const name = readFlag21(args, "--name");
|
|
3901
|
+
const subject = readFlag21(args, "--subject");
|
|
3902
|
+
const html = readFlag21(args, "--html");
|
|
3903
|
+
const text = readFlag21(args, "--text");
|
|
3904
|
+
const alias = readFlag21(args, "--alias");
|
|
3905
|
+
const category = readFlag21(args, "--category");
|
|
3906
|
+
const folder = readFlag21(args, "--folder");
|
|
3907
|
+
const sender = readFlag21(args, "--sender");
|
|
3812
3908
|
const unsubscribeEnabled = args.includes("--unsubscribe-enabled");
|
|
3813
3909
|
if (!name) {
|
|
3814
3910
|
return { exitCode: 1, error: 'Missing name. Pass --name "Welcome"' };
|
|
@@ -3820,8 +3916,8 @@ async function runCreateCommand3(args, env = process.env) {
|
|
|
3820
3916
|
return { exitCode: 1, error: 'Missing body. Pass --html "<p>Hi</p>" or --text "Hi"' };
|
|
3821
3917
|
}
|
|
3822
3918
|
try {
|
|
3823
|
-
const
|
|
3824
|
-
const result = await
|
|
3919
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3920
|
+
const result = await client3.templates.create({
|
|
3825
3921
|
name,
|
|
3826
3922
|
subject,
|
|
3827
3923
|
...html ? { html } : {},
|
|
@@ -3860,19 +3956,19 @@ async function runUpdateCommand4(args, env = process.env) {
|
|
|
3860
3956
|
if (!apiKey) {
|
|
3861
3957
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3862
3958
|
}
|
|
3863
|
-
const idOrAlias =
|
|
3959
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional12(args);
|
|
3864
3960
|
if (!idOrAlias) {
|
|
3865
3961
|
return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3866
3962
|
}
|
|
3867
|
-
const name =
|
|
3868
|
-
const subject =
|
|
3869
|
-
const html =
|
|
3870
|
-
const text =
|
|
3871
|
-
const alias =
|
|
3963
|
+
const name = readFlag21(args, "--name");
|
|
3964
|
+
const subject = readFlag21(args, "--subject");
|
|
3965
|
+
const html = readFlag21(args, "--html");
|
|
3966
|
+
const text = readFlag21(args, "--text");
|
|
3967
|
+
const alias = readFlag21(args, "--set-alias");
|
|
3872
3968
|
const variables = readFlags3(args, "--variable");
|
|
3873
|
-
const category =
|
|
3874
|
-
const folder =
|
|
3875
|
-
const sender =
|
|
3969
|
+
const category = readFlag21(args, "--category");
|
|
3970
|
+
const folder = readFlag21(args, "--folder");
|
|
3971
|
+
const sender = readFlag21(args, "--sender");
|
|
3876
3972
|
const unsubscribeEnabled = args.includes("--unsubscribe-enabled");
|
|
3877
3973
|
const unsubscribeDisabled = args.includes("--no-unsubscribe-enabled");
|
|
3878
3974
|
if (!name && !subject && !html && !text && !alias && variables.length === 0 && !category && folder === void 0 && sender === void 0 && !unsubscribeEnabled && !unsubscribeDisabled) {
|
|
@@ -3882,8 +3978,8 @@ async function runUpdateCommand4(args, env = process.env) {
|
|
|
3882
3978
|
};
|
|
3883
3979
|
}
|
|
3884
3980
|
try {
|
|
3885
|
-
const
|
|
3886
|
-
const result = await
|
|
3981
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3982
|
+
const result = await client3.templates.update(idOrAlias, {
|
|
3887
3983
|
...name ? { name } : {},
|
|
3888
3984
|
...subject ? { subject } : {},
|
|
3889
3985
|
...html ? { html } : {},
|
|
@@ -3940,7 +4036,7 @@ async function runFromStarterCommand(args, env = process.env) {
|
|
|
3940
4036
|
if (!apiKey) {
|
|
3941
4037
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3942
4038
|
}
|
|
3943
|
-
const alias =
|
|
4039
|
+
const alias = readFlag21(args, "--alias") || readFirstPositional13(args);
|
|
3944
4040
|
if (!alias) {
|
|
3945
4041
|
return {
|
|
3946
4042
|
exitCode: 1,
|
|
@@ -3948,8 +4044,8 @@ async function runFromStarterCommand(args, env = process.env) {
|
|
|
3948
4044
|
};
|
|
3949
4045
|
}
|
|
3950
4046
|
try {
|
|
3951
|
-
const
|
|
3952
|
-
console.log(JSON.stringify(await
|
|
4047
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4048
|
+
console.log(JSON.stringify(await client3.templates.fromStarter(alias)));
|
|
3953
4049
|
return { exitCode: 0 };
|
|
3954
4050
|
} catch (error) {
|
|
3955
4051
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3962,8 +4058,8 @@ async function runListStartersCommand(args, env = process.env) {
|
|
|
3962
4058
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3963
4059
|
}
|
|
3964
4060
|
try {
|
|
3965
|
-
const
|
|
3966
|
-
console.log(JSON.stringify(await
|
|
4061
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4062
|
+
console.log(JSON.stringify(await client3.templates.listStarters()));
|
|
3967
4063
|
return { exitCode: 0 };
|
|
3968
4064
|
} catch (error) {
|
|
3969
4065
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3989,13 +4085,13 @@ async function runVersionsCommand(args, env = process.env) {
|
|
|
3989
4085
|
if (!apiKey) {
|
|
3990
4086
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3991
4087
|
}
|
|
3992
|
-
const idOrAlias =
|
|
4088
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional14(args);
|
|
3993
4089
|
if (!idOrAlias) {
|
|
3994
4090
|
return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3995
4091
|
}
|
|
3996
4092
|
try {
|
|
3997
|
-
const
|
|
3998
|
-
console.log(JSON.stringify(await
|
|
4093
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4094
|
+
console.log(JSON.stringify(await client3.templates.listVersions(idOrAlias)));
|
|
3999
4095
|
return { exitCode: 0 };
|
|
4000
4096
|
} catch (error) {
|
|
4001
4097
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -4007,8 +4103,8 @@ async function runRestoreCommand(args, env = process.env) {
|
|
|
4007
4103
|
if (!apiKey) {
|
|
4008
4104
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4009
4105
|
}
|
|
4010
|
-
const idOrAlias =
|
|
4011
|
-
const versionRaw =
|
|
4106
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional14(args);
|
|
4107
|
+
const versionRaw = readFlag21(args, "--version");
|
|
4012
4108
|
const version2 = versionRaw ? Number.parseInt(versionRaw, 10) : NaN;
|
|
4013
4109
|
if (!idOrAlias || !Number.isFinite(version2) || version2 < 1) {
|
|
4014
4110
|
return {
|
|
@@ -4017,8 +4113,8 @@ async function runRestoreCommand(args, env = process.env) {
|
|
|
4017
4113
|
};
|
|
4018
4114
|
}
|
|
4019
4115
|
try {
|
|
4020
|
-
const
|
|
4021
|
-
console.log(JSON.stringify(await
|
|
4116
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4117
|
+
console.log(JSON.stringify(await client3.templates.restoreVersion(idOrAlias, version2)));
|
|
4022
4118
|
return { exitCode: 0 };
|
|
4023
4119
|
} catch (error) {
|
|
4024
4120
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -4030,10 +4126,10 @@ async function runTestSendCommand(args, env = process.env) {
|
|
|
4030
4126
|
if (!apiKey) {
|
|
4031
4127
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4032
4128
|
}
|
|
4033
|
-
const idOrAlias =
|
|
4034
|
-
const from =
|
|
4035
|
-
const sender =
|
|
4036
|
-
const to =
|
|
4129
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional14(args);
|
|
4130
|
+
const from = readFlag21(args, "--from");
|
|
4131
|
+
const sender = readFlag21(args, "--sender");
|
|
4132
|
+
const to = readFlag21(args, "--to");
|
|
4037
4133
|
if (!idOrAlias || !to) {
|
|
4038
4134
|
return {
|
|
4039
4135
|
exitCode: 1,
|
|
@@ -4041,10 +4137,10 @@ async function runTestSendCommand(args, env = process.env) {
|
|
|
4041
4137
|
};
|
|
4042
4138
|
}
|
|
4043
4139
|
try {
|
|
4044
|
-
const
|
|
4140
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4045
4141
|
console.log(
|
|
4046
4142
|
JSON.stringify(
|
|
4047
|
-
await
|
|
4143
|
+
await client3.templates.testSend(idOrAlias, { to, ...from ? { from } : {}, ...sender ? { sender } : {} })
|
|
4048
4144
|
)
|
|
4049
4145
|
);
|
|
4050
4146
|
return { exitCode: 0 };
|
|
@@ -4054,15 +4150,15 @@ async function runTestSendCommand(args, env = process.env) {
|
|
|
4054
4150
|
}
|
|
4055
4151
|
|
|
4056
4152
|
// src/commands/integrations/shared.ts
|
|
4057
|
-
function
|
|
4153
|
+
function readFlag22(args, flag) {
|
|
4058
4154
|
const index = args.indexOf(flag);
|
|
4059
4155
|
if (index === -1) return void 0;
|
|
4060
4156
|
return args[index + 1];
|
|
4061
4157
|
}
|
|
4062
4158
|
function parseIntegrationsCommonArgs(args) {
|
|
4063
4159
|
return {
|
|
4064
|
-
apiKey:
|
|
4065
|
-
baseUrl:
|
|
4160
|
+
apiKey: readFlag22(args, "--api-key"),
|
|
4161
|
+
baseUrl: readFlag22(args, "--base-url")
|
|
4066
4162
|
};
|
|
4067
4163
|
}
|
|
4068
4164
|
function resolveApiKey9(options, env) {
|
|
@@ -4081,8 +4177,8 @@ async function runTwilioStatusCommand(args, env = process.env) {
|
|
|
4081
4177
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4082
4178
|
}
|
|
4083
4179
|
try {
|
|
4084
|
-
const
|
|
4085
|
-
const result = await
|
|
4180
|
+
const client3 = await createIntegrationsClient(apiKey, options.baseUrl);
|
|
4181
|
+
const result = await client3.integrations.getTwilio();
|
|
4086
4182
|
console.log(JSON.stringify(result));
|
|
4087
4183
|
return { exitCode: 0 };
|
|
4088
4184
|
} catch (error) {
|
|
@@ -4095,10 +4191,10 @@ async function runTwilioConnectCommand(args, env = process.env) {
|
|
|
4095
4191
|
if (!apiKey) {
|
|
4096
4192
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4097
4193
|
}
|
|
4098
|
-
const accountSid =
|
|
4099
|
-
const authToken =
|
|
4100
|
-
const defaultFrom =
|
|
4101
|
-
const messagingServiceSid =
|
|
4194
|
+
const accountSid = readFlag22(args, "--account-sid") || env.TWILIO_ACCOUNT_SID || env.TWILIO_SID || "";
|
|
4195
|
+
const authToken = readFlag22(args, "--auth-token") || env.TWILIO_AUTH_TOKEN || env.TWILIO_TOKEN || "";
|
|
4196
|
+
const defaultFrom = readFlag22(args, "--from") || readFlag22(args, "--default-from") || env.TWILIO_DEFAULT_FROM || "";
|
|
4197
|
+
const messagingServiceSid = readFlag22(args, "--messaging-service-sid") || readFlag22(args, "--messaging-sid") || env.TWILIO_MESSAGING_SERVICE_SID || "";
|
|
4102
4198
|
if (!accountSid.trim() || !authToken.trim()) {
|
|
4103
4199
|
return {
|
|
4104
4200
|
exitCode: 1,
|
|
@@ -4112,8 +4208,8 @@ async function runTwilioConnectCommand(args, env = process.env) {
|
|
|
4112
4208
|
};
|
|
4113
4209
|
}
|
|
4114
4210
|
try {
|
|
4115
|
-
const
|
|
4116
|
-
const result = await
|
|
4211
|
+
const client3 = await createIntegrationsClient(apiKey, options.baseUrl);
|
|
4212
|
+
const result = await client3.integrations.connectTwilio({
|
|
4117
4213
|
accountSid: accountSid.trim(),
|
|
4118
4214
|
authToken: authToken.trim(),
|
|
4119
4215
|
...defaultFrom.trim() ? { defaultFrom: defaultFrom.trim() } : {},
|
|
@@ -4132,8 +4228,8 @@ async function runTwilioDisconnectCommand(args, env = process.env) {
|
|
|
4132
4228
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4133
4229
|
}
|
|
4134
4230
|
try {
|
|
4135
|
-
const
|
|
4136
|
-
const result = await
|
|
4231
|
+
const client3 = await createIntegrationsClient(apiKey, options.baseUrl);
|
|
4232
|
+
const result = await client3.integrations.disconnectTwilio();
|
|
4137
4233
|
console.log(JSON.stringify(result));
|
|
4138
4234
|
return { exitCode: 0 };
|
|
4139
4235
|
} catch (error) {
|
|
@@ -4147,8 +4243,8 @@ async function withClient(args, env, run) {
|
|
|
4147
4243
|
const apiKey = resolveApiKey5(options, env);
|
|
4148
4244
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY };
|
|
4149
4245
|
try {
|
|
4150
|
-
const
|
|
4151
|
-
console.log(JSON.stringify(await run(
|
|
4246
|
+
const client3 = await createTenantsClient(apiKey, options.baseUrl);
|
|
4247
|
+
console.log(JSON.stringify(await run(client3)));
|
|
4152
4248
|
return { exitCode: 0 };
|
|
4153
4249
|
} catch (error) {
|
|
4154
4250
|
return failure(error);
|
|
@@ -4167,7 +4263,7 @@ async function runListCommand8(args, env = process.env) {
|
|
|
4167
4263
|
return withClient(
|
|
4168
4264
|
args,
|
|
4169
4265
|
env,
|
|
4170
|
-
(
|
|
4266
|
+
(client3) => client3.tenants.list({
|
|
4171
4267
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
4172
4268
|
...cursor ? { cursor } : {},
|
|
4173
4269
|
...status ? { status } : {}
|
|
@@ -4181,12 +4277,12 @@ async function runCreateCommand4(args, env = process.env) {
|
|
|
4181
4277
|
}
|
|
4182
4278
|
const settings = parseTenantSettings(args);
|
|
4183
4279
|
if ("error" in settings) return { exitCode: 1, error: settings.error };
|
|
4184
|
-
return withClient(args, env, (
|
|
4280
|
+
return withClient(args, env, (client3) => client3.tenants.create({ external_id: externalId, ...settings.value }));
|
|
4185
4281
|
}
|
|
4186
4282
|
async function runGetCommand7(args, env = process.env) {
|
|
4187
4283
|
const tenant = tenantRef(args);
|
|
4188
4284
|
if (!tenant) return missingTenant("groundmail tenants get <tenant>");
|
|
4189
|
-
return withClient(args, env, (
|
|
4285
|
+
return withClient(args, env, (client3) => client3.tenants.get(tenant));
|
|
4190
4286
|
}
|
|
4191
4287
|
async function runUpdateCommand5(args, env = process.env) {
|
|
4192
4288
|
const tenant = tenantRef(args);
|
|
@@ -4199,18 +4295,18 @@ async function runUpdateCommand5(args, env = process.env) {
|
|
|
4199
4295
|
error: "Nothing to update. Pass --name, --default-from-domain, --stream-policy, --daily-limit or --metadata (or use tenants pause / resume)."
|
|
4200
4296
|
};
|
|
4201
4297
|
}
|
|
4202
|
-
return withClient(args, env, (
|
|
4298
|
+
return withClient(args, env, (client3) => client3.tenants.update(tenant, settings.value));
|
|
4203
4299
|
}
|
|
4204
4300
|
async function runPauseCommand2(args, env = process.env) {
|
|
4205
4301
|
const tenant = tenantRef(args);
|
|
4206
4302
|
if (!tenant) return missingTenant("groundmail tenants pause <tenant> [--reason \u2026]");
|
|
4207
4303
|
const reason = readFlag12(args, "--reason");
|
|
4208
|
-
return withClient(args, env, (
|
|
4304
|
+
return withClient(args, env, (client3) => client3.tenants.pause(tenant, reason));
|
|
4209
4305
|
}
|
|
4210
4306
|
async function runResumeCommand(args, env = process.env) {
|
|
4211
4307
|
const tenant = tenantRef(args);
|
|
4212
4308
|
if (!tenant) return missingTenant("groundmail tenants resume <tenant>");
|
|
4213
|
-
return withClient(args, env, (
|
|
4309
|
+
return withClient(args, env, (client3) => client3.tenants.resume(tenant));
|
|
4214
4310
|
}
|
|
4215
4311
|
async function runDeleteCommand5(args, env = process.env) {
|
|
4216
4312
|
const tenant = tenantRef(args);
|
|
@@ -4221,7 +4317,7 @@ async function runDeleteCommand5(args, env = process.env) {
|
|
|
4221
4317
|
error: `This deletes tenant ${tenant} and its suppression list; its domains go back to the account and keys limited to it stop working. Run again with --yes to confirm.`
|
|
4222
4318
|
};
|
|
4223
4319
|
}
|
|
4224
|
-
return withClient(args, env, (
|
|
4320
|
+
return withClient(args, env, (client3) => client3.tenants.delete(tenant));
|
|
4225
4321
|
}
|
|
4226
4322
|
async function runStatsCommand(args, env = process.env) {
|
|
4227
4323
|
const tenant = tenantRef(args);
|
|
@@ -4231,7 +4327,7 @@ async function runStatsCommand(args, env = process.env) {
|
|
|
4231
4327
|
if (days !== void 0 && (!Number.isInteger(days) || days < 1 || days > 90)) {
|
|
4232
4328
|
return { exitCode: 1, error: "--days must be a whole number from 1 to 90" };
|
|
4233
4329
|
}
|
|
4234
|
-
return withClient(args, env, (
|
|
4330
|
+
return withClient(args, env, (client3) => client3.tenants.stats(tenant, days !== void 0 ? { days } : {}));
|
|
4235
4331
|
}
|
|
4236
4332
|
async function runDomainsCommand(args, env = process.env) {
|
|
4237
4333
|
const [action, ...rest] = args;
|
|
@@ -4240,19 +4336,19 @@ async function runDomainsCommand(args, env = process.env) {
|
|
|
4240
4336
|
const domain = readFlag12(rest, "--domain") || pos.shift();
|
|
4241
4337
|
if (action === "list") {
|
|
4242
4338
|
if (!tenant) return missingTenant("groundmail tenants domains list <tenant>");
|
|
4243
|
-
return withClient(rest, env, (
|
|
4339
|
+
return withClient(rest, env, (client3) => client3.tenants.domains.list(tenant));
|
|
4244
4340
|
}
|
|
4245
4341
|
if (action === "add" || action === "assign") {
|
|
4246
4342
|
if (!tenant || !domain) {
|
|
4247
4343
|
return { exitCode: 1, error: "Usage: groundmail tenants domains add <tenant> <domain>" };
|
|
4248
4344
|
}
|
|
4249
|
-
return withClient(rest, env, (
|
|
4345
|
+
return withClient(rest, env, (client3) => client3.tenants.domains.assign(tenant, domain));
|
|
4250
4346
|
}
|
|
4251
4347
|
if (action === "remove" || action === "unassign" || action === "delete") {
|
|
4252
4348
|
if (!tenant || !domain) {
|
|
4253
4349
|
return { exitCode: 1, error: "Usage: groundmail tenants domains remove <tenant> <domain>" };
|
|
4254
4350
|
}
|
|
4255
|
-
return withClient(rest, env, (
|
|
4351
|
+
return withClient(rest, env, (client3) => client3.tenants.domains.unassign(tenant, domain));
|
|
4256
4352
|
}
|
|
4257
4353
|
return {
|
|
4258
4354
|
exitCode: 1,
|
|
@@ -4262,7 +4358,7 @@ async function runDomainsCommand(args, env = process.env) {
|
|
|
4262
4358
|
|
|
4263
4359
|
// src/commands/senders/shared.ts
|
|
4264
4360
|
var SENDER_VALUE_FLAGS = ["--api-key", "--base-url", "--id", "--name", "--address", "--reply-to", "--handle"];
|
|
4265
|
-
function
|
|
4361
|
+
function readFlag23(args, flag) {
|
|
4266
4362
|
const index = args.indexOf(flag);
|
|
4267
4363
|
if (index === -1) return void 0;
|
|
4268
4364
|
return args[index + 1];
|
|
@@ -4270,7 +4366,7 @@ function readFlag22(args, flag) {
|
|
|
4270
4366
|
function hasFlag2(args, flag) {
|
|
4271
4367
|
return args.includes(flag);
|
|
4272
4368
|
}
|
|
4273
|
-
function
|
|
4369
|
+
function positionals3(args, valueFlags = SENDER_VALUE_FLAGS) {
|
|
4274
4370
|
const out = [];
|
|
4275
4371
|
for (let i = 0; i < args.length; i += 1) {
|
|
4276
4372
|
const arg = args[i];
|
|
@@ -4284,8 +4380,8 @@ function positionals2(args, valueFlags = SENDER_VALUE_FLAGS) {
|
|
|
4284
4380
|
}
|
|
4285
4381
|
function parseSendersCommonArgs(args) {
|
|
4286
4382
|
return {
|
|
4287
|
-
apiKey:
|
|
4288
|
-
baseUrl:
|
|
4383
|
+
apiKey: readFlag23(args, "--api-key"),
|
|
4384
|
+
baseUrl: readFlag23(args, "--base-url")
|
|
4289
4385
|
};
|
|
4290
4386
|
}
|
|
4291
4387
|
function resolveApiKey10(options, env) {
|
|
@@ -4303,13 +4399,13 @@ function failure2(error) {
|
|
|
4303
4399
|
${hint}` : message };
|
|
4304
4400
|
}
|
|
4305
4401
|
function senderRef(args) {
|
|
4306
|
-
return
|
|
4402
|
+
return readFlag23(args, "--id") || positionals3(args)[0];
|
|
4307
4403
|
}
|
|
4308
4404
|
function parseSenderFields(args) {
|
|
4309
|
-
const name =
|
|
4310
|
-
const address =
|
|
4311
|
-
const replyTo =
|
|
4312
|
-
const handle =
|
|
4405
|
+
const name = readFlag23(args, "--name");
|
|
4406
|
+
const address = readFlag23(args, "--address");
|
|
4407
|
+
const replyTo = readFlag23(args, "--reply-to");
|
|
4408
|
+
const handle = readFlag23(args, "--handle");
|
|
4313
4409
|
const makeDefault = hasFlag2(args, "--default");
|
|
4314
4410
|
const notDefault = hasFlag2(args, "--no-default");
|
|
4315
4411
|
if (makeDefault && notDefault) return { error: "Pass --default or --no-default, not both" };
|
|
@@ -4330,8 +4426,8 @@ async function withClient2(args, env, run) {
|
|
|
4330
4426
|
const apiKey = resolveApiKey10(options, env);
|
|
4331
4427
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY2 };
|
|
4332
4428
|
try {
|
|
4333
|
-
const
|
|
4334
|
-
console.log(JSON.stringify(await run(
|
|
4429
|
+
const client3 = await createSendersClient(apiKey, options.baseUrl);
|
|
4430
|
+
console.log(JSON.stringify(await run(client3)));
|
|
4335
4431
|
return { exitCode: 0 };
|
|
4336
4432
|
} catch (error) {
|
|
4337
4433
|
return failure2(error);
|
|
@@ -4341,7 +4437,7 @@ function missingSender(usage) {
|
|
|
4341
4437
|
return { exitCode: 1, error: `Missing sender (id or handle). Usage: ${usage}` };
|
|
4342
4438
|
}
|
|
4343
4439
|
async function runListCommand9(args, env = process.env) {
|
|
4344
|
-
return withClient2(args, env, (
|
|
4440
|
+
return withClient2(args, env, (client3) => client3.senders.list());
|
|
4345
4441
|
}
|
|
4346
4442
|
async function runCreateCommand5(args, env = process.env) {
|
|
4347
4443
|
const fields = parseSenderFields(args);
|
|
@@ -4353,12 +4449,12 @@ async function runCreateCommand5(args, env = process.env) {
|
|
|
4353
4449
|
error: 'Required: --name and --address. Usage: groundmail senders create --name "Acme Billing" --address billing@mail.acme.com [--reply-to \u2026] [--handle billing] [--default]'
|
|
4354
4450
|
};
|
|
4355
4451
|
}
|
|
4356
|
-
return withClient2(args, env, (
|
|
4452
|
+
return withClient2(args, env, (client3) => client3.senders.create({ ...fields.value, name, address }));
|
|
4357
4453
|
}
|
|
4358
4454
|
async function runGetCommand8(args, env = process.env) {
|
|
4359
4455
|
const sender = senderRef(args);
|
|
4360
4456
|
if (!sender) return missingSender("groundmail senders get <id|handle>");
|
|
4361
|
-
return withClient2(args, env, (
|
|
4457
|
+
return withClient2(args, env, (client3) => client3.senders.get(sender));
|
|
4362
4458
|
}
|
|
4363
4459
|
async function runUpdateCommand6(args, env = process.env) {
|
|
4364
4460
|
const sender = senderRef(args);
|
|
@@ -4371,7 +4467,7 @@ async function runUpdateCommand6(args, env = process.env) {
|
|
|
4371
4467
|
error: "Nothing to update. Pass --name, --address, --reply-to, --handle, --default or --no-default."
|
|
4372
4468
|
};
|
|
4373
4469
|
}
|
|
4374
|
-
return withClient2(args, env, (
|
|
4470
|
+
return withClient2(args, env, (client3) => client3.senders.update(sender, fields.value));
|
|
4375
4471
|
}
|
|
4376
4472
|
async function runDeleteCommand6(args, env = process.env) {
|
|
4377
4473
|
const sender = senderRef(args);
|
|
@@ -4382,7 +4478,7 @@ async function runDeleteCommand6(args, env = process.env) {
|
|
|
4382
4478
|
error: `This deletes sender ${sender}. Sends that name it will fail. Run again with --yes to confirm.`
|
|
4383
4479
|
};
|
|
4384
4480
|
}
|
|
4385
|
-
return withClient2(args, env, (
|
|
4481
|
+
return withClient2(args, env, (client3) => client3.senders.remove(sender));
|
|
4386
4482
|
}
|
|
4387
4483
|
|
|
4388
4484
|
// src/commands/brand/commands.ts
|
|
@@ -4406,26 +4502,26 @@ async function withClient3(args, env, run) {
|
|
|
4406
4502
|
const apiKey = resolveApiKey10(options, env);
|
|
4407
4503
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY2 };
|
|
4408
4504
|
try {
|
|
4409
|
-
const
|
|
4410
|
-
console.log(JSON.stringify(await run(
|
|
4505
|
+
const client3 = await createBrandClient(apiKey, options.baseUrl);
|
|
4506
|
+
console.log(JSON.stringify(await run(client3)));
|
|
4411
4507
|
return { exitCode: 0 };
|
|
4412
4508
|
} catch (error) {
|
|
4413
4509
|
return failure2(error);
|
|
4414
4510
|
}
|
|
4415
4511
|
}
|
|
4416
4512
|
async function runGetCommand9(args, env = process.env) {
|
|
4417
|
-
return withClient3(args, env, (
|
|
4513
|
+
return withClient3(args, env, (client3) => client3.brand.get());
|
|
4418
4514
|
}
|
|
4419
4515
|
function clearable(value) {
|
|
4420
4516
|
if (value === void 0) return void 0;
|
|
4421
4517
|
return value === "none" || value === "" ? null : value;
|
|
4422
4518
|
}
|
|
4423
4519
|
async function runSetCommand(args, env = process.env) {
|
|
4424
|
-
const logoUrl = clearable(
|
|
4425
|
-
const logoAlign =
|
|
4426
|
-
const logoWidth =
|
|
4427
|
-
const color =
|
|
4428
|
-
const settingsFile =
|
|
4520
|
+
const logoUrl = clearable(readFlag23(args, "--logo-url"));
|
|
4521
|
+
const logoAlign = readFlag23(args, "--logo-align");
|
|
4522
|
+
const logoWidth = readFlag23(args, "--logo-width");
|
|
4523
|
+
const color = readFlag23(args, "--color");
|
|
4524
|
+
const settingsFile = readFlag23(args, "--settings-file");
|
|
4429
4525
|
if (logoAlign !== void 0 && logoAlign !== "left" && logoAlign !== "center") {
|
|
4430
4526
|
return { exitCode: 1, error: "--logo-align must be left or center" };
|
|
4431
4527
|
}
|
|
@@ -4446,9 +4542,9 @@ async function runSetCommand(args, env = process.env) {
|
|
|
4446
4542
|
if (logoUrl !== void 0) {
|
|
4447
4543
|
params.logo = logoUrl === null ? null : { url: logoUrl, align: logoAlign ?? "left", ...logoWidth ? { width: Number(logoWidth) } : {} };
|
|
4448
4544
|
}
|
|
4449
|
-
const company = clearable(
|
|
4450
|
-
const address = clearable(
|
|
4451
|
-
const website = clearable(
|
|
4545
|
+
const company = clearable(readFlag23(args, "--company"));
|
|
4546
|
+
const address = clearable(readFlag23(args, "--address"));
|
|
4547
|
+
const website = clearable(readFlag23(args, "--website"));
|
|
4452
4548
|
if (company !== void 0) params.company_name = company;
|
|
4453
4549
|
if (address !== void 0) params.address = address;
|
|
4454
4550
|
if (website !== void 0) params.website = website;
|
|
@@ -4459,9 +4555,9 @@ async function runSetCommand(args, env = process.env) {
|
|
|
4459
4555
|
error: "Nothing to set. Usage: groundmail brand set [--logo-url \u2026] [--color #2f6feb] [--company \u2026] [--address \u2026] [--website \u2026] [--settings-file brand.json]"
|
|
4460
4556
|
};
|
|
4461
4557
|
}
|
|
4462
|
-
return withClient3(args, env, async (
|
|
4558
|
+
return withClient3(args, env, async (client3) => {
|
|
4463
4559
|
if (color) {
|
|
4464
|
-
const base = params.settings ?? (await
|
|
4560
|
+
const base = params.settings ?? (await client3.brand.get()).brand.settings ?? {};
|
|
4465
4561
|
const theme = base.theme ?? {};
|
|
4466
4562
|
params.accent_color = color;
|
|
4467
4563
|
params.settings = {
|
|
@@ -4470,25 +4566,25 @@ async function runSetCommand(args, env = process.env) {
|
|
|
4470
4566
|
theme: { ...theme, buttonBackground: color, buttonTextColor: readableText(color) }
|
|
4471
4567
|
};
|
|
4472
4568
|
}
|
|
4473
|
-
return
|
|
4569
|
+
return client3.brand.update(params);
|
|
4474
4570
|
});
|
|
4475
4571
|
}
|
|
4476
4572
|
|
|
4477
4573
|
// src/commands/batches/commands.ts
|
|
4478
|
-
var
|
|
4574
|
+
var VALUE_FLAGS4 = ["--api-key", "--base-url", "--id"];
|
|
4479
4575
|
var MISSING_KEY3 = "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key.";
|
|
4480
|
-
function
|
|
4576
|
+
function readFlag24(args, flag) {
|
|
4481
4577
|
const index = args.indexOf(flag);
|
|
4482
4578
|
if (index === -1) return void 0;
|
|
4483
4579
|
return args[index + 1];
|
|
4484
4580
|
}
|
|
4485
4581
|
function batchRef(args) {
|
|
4486
|
-
const id =
|
|
4582
|
+
const id = readFlag24(args, "--id");
|
|
4487
4583
|
if (id) return id;
|
|
4488
4584
|
for (let i = 0; i < args.length; i += 1) {
|
|
4489
4585
|
const arg = args[i];
|
|
4490
4586
|
if (arg.startsWith("--")) {
|
|
4491
|
-
if (
|
|
4587
|
+
if (VALUE_FLAGS4.includes(arg)) i += 1;
|
|
4492
4588
|
continue;
|
|
4493
4589
|
}
|
|
4494
4590
|
return arg;
|
|
@@ -4502,21 +4598,21 @@ async function createBatchesClient(apiKey, baseUrl) {
|
|
|
4502
4598
|
async function withBatch(args, env, usage, run) {
|
|
4503
4599
|
const batchId = batchRef(args);
|
|
4504
4600
|
if (!batchId) return { exitCode: 1, error: `Missing batch id (batch_\u2026). Usage: ${usage}` };
|
|
4505
|
-
const apiKey =
|
|
4601
|
+
const apiKey = readFlag24(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
4506
4602
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY3 };
|
|
4507
4603
|
try {
|
|
4508
|
-
const
|
|
4509
|
-
console.log(JSON.stringify(await run(
|
|
4604
|
+
const client3 = await createBatchesClient(apiKey, readFlag24(args, "--base-url"));
|
|
4605
|
+
console.log(JSON.stringify(await run(client3, batchId)));
|
|
4510
4606
|
return { exitCode: 0 };
|
|
4511
4607
|
} catch (error) {
|
|
4512
4608
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
4513
4609
|
}
|
|
4514
4610
|
}
|
|
4515
4611
|
async function runGetCommand10(args, env = process.env) {
|
|
4516
|
-
return withBatch(args, env, "groundmail batches get <batch_id>", (
|
|
4612
|
+
return withBatch(args, env, "groundmail batches get <batch_id>", (client3, id) => client3.batches.get(id));
|
|
4517
4613
|
}
|
|
4518
4614
|
async function runCancelCommand2(args, env = process.env) {
|
|
4519
|
-
return withBatch(args, env, "groundmail batches cancel <batch_id>", (
|
|
4615
|
+
return withBatch(args, env, "groundmail batches cancel <batch_id>", (client3, id) => client3.batches.cancel(id));
|
|
4520
4616
|
}
|
|
4521
4617
|
|
|
4522
4618
|
// src/commands/auth.ts
|
|
@@ -4656,7 +4752,7 @@ async function switchWorkspace(argv, deps) {
|
|
|
4656
4752
|
}
|
|
4657
4753
|
|
|
4658
4754
|
// src/commands/migrate.ts
|
|
4659
|
-
var PROVIDERS2 = ["sendgrid", "postmark", "mailgun", "resend", "ses"];
|
|
4755
|
+
var PROVIDERS2 = ["sendgrid", "postmark", "mailgun", "resend", "ses", "azure"];
|
|
4660
4756
|
var RESOURCES = ["domains", "webhooks", "templates", "suppressions"];
|
|
4661
4757
|
var KEY_ENV = {
|
|
4662
4758
|
sendgrid: "SENDGRID_API_KEY",
|
|
@@ -4669,7 +4765,8 @@ var LABELS = {
|
|
|
4669
4765
|
postmark: "Postmark",
|
|
4670
4766
|
mailgun: "Mailgun",
|
|
4671
4767
|
resend: "Resend",
|
|
4672
|
-
ses: "Amazon SES"
|
|
4768
|
+
ses: "Amazon SES",
|
|
4769
|
+
azure: "Azure Communication Services"
|
|
4673
4770
|
};
|
|
4674
4771
|
var AWS_REGION = /^[a-z]{2}(?:-gov)?-[a-z]+-\d{1,2}$/;
|
|
4675
4772
|
function sesParams(args, env) {
|
|
@@ -4682,7 +4779,7 @@ function sesParams(args, env) {
|
|
|
4682
4779
|
"Use a key with the read-only import policy (https://docs.groundmail.dev/migrations#amazon-ses-iam-policy). It is used for this import only and never stored."
|
|
4683
4780
|
].join("\n");
|
|
4684
4781
|
}
|
|
4685
|
-
const region =
|
|
4782
|
+
const region = readFlag25(args, "--region") || env.AWS_REGION || env.AWS_DEFAULT_REGION;
|
|
4686
4783
|
if (!region) return "Set the SES region with --region (for example --region us-east-1) or AWS_REGION. One region per import.";
|
|
4687
4784
|
if (!AWS_REGION.test(region)) return `--region must be an AWS region such as us-east-1, not ${region}`;
|
|
4688
4785
|
return {
|
|
@@ -4693,8 +4790,23 @@ function sesParams(args, env) {
|
|
|
4693
4790
|
aws_region: region
|
|
4694
4791
|
};
|
|
4695
4792
|
}
|
|
4696
|
-
var
|
|
4697
|
-
function
|
|
4793
|
+
var GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4794
|
+
function azureParams(args, env) {
|
|
4795
|
+
const subscription = readFlag25(args, "--subscription") || env.AZURE_SUBSCRIPTION_ID;
|
|
4796
|
+
if (!subscription) {
|
|
4797
|
+
return [
|
|
4798
|
+
"Missing the Azure subscription. Pass --subscription <id> or set AZURE_SUBSCRIPTION_ID (find it with: az account show --query id -o tsv).",
|
|
4799
|
+
"Before the first import, connect your Microsoft Entra tenant in the dashboard (API keys \u2192 New credential \u2192 Azure managed identity \u2192 Connect Azure)",
|
|
4800
|
+
"and give the Groundmail app the Reader role on the resource group that holds your Email Communication Service."
|
|
4801
|
+
].join(" ");
|
|
4802
|
+
}
|
|
4803
|
+
if (!GUID.test(subscription)) return `--subscription must be an Azure subscription ID (a GUID), not ${subscription}`;
|
|
4804
|
+
const tenant = readFlag25(args, "--tenant") || env.AZURE_TENANT_ID;
|
|
4805
|
+
if (tenant && !GUID.test(tenant)) return `--tenant must be a Microsoft Entra tenant ID (a GUID), not ${tenant}`;
|
|
4806
|
+
return { provider: "azure", azure_subscription_id: subscription, ...tenant ? { azure_tenant_id: tenant } : {} };
|
|
4807
|
+
}
|
|
4808
|
+
var VALUE_FLAGS5 = /* @__PURE__ */ new Set(["--api-key", "--base-url", "--subscription", "--tenant"]);
|
|
4809
|
+
function readFlag25(args, flag) {
|
|
4698
4810
|
const index = args.indexOf(flag);
|
|
4699
4811
|
if (index === -1) return void 0;
|
|
4700
4812
|
return args[index + 1];
|
|
@@ -4715,7 +4827,9 @@ function formatMigrationSummary(m) {
|
|
|
4715
4827
|
m.provider === "ses" ? " Webhooks reported, not imported (SES has no webhooks; see the notes)" : ` Webhooks ${n(m.webhooks.totals.imported)} of ${n(m.webhooks.totals.found)} (created disabled)`
|
|
4716
4828
|
);
|
|
4717
4829
|
}
|
|
4718
|
-
if (m.templates) {
|
|
4830
|
+
if (m.templates && m.provider === "azure") {
|
|
4831
|
+
lines.push(" Templates none (Azure Communication Services has no stored templates)");
|
|
4832
|
+
} else if (m.templates) {
|
|
4719
4833
|
const t = m.templates.totals;
|
|
4720
4834
|
lines.push(` Templates ${n(t.imported)} ready, ${n(t.needs_attention)} to review, of ${n(t.found)}`);
|
|
4721
4835
|
}
|
|
@@ -4768,15 +4882,15 @@ function formatMigrationSummary(m) {
|
|
|
4768
4882
|
if (!m.dry_run && !m.has_more) lines.push("", `Report: groundmail migrate report ${m.id} --csv > import-report.csv`);
|
|
4769
4883
|
return lines.join("\n");
|
|
4770
4884
|
}
|
|
4771
|
-
async function
|
|
4772
|
-
const apiKey =
|
|
4885
|
+
async function client2(args, env) {
|
|
4886
|
+
const apiKey = readFlag25(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
4773
4887
|
if (!apiKey) return null;
|
|
4774
4888
|
const { Groundmail } = await import("groundmail");
|
|
4775
|
-
const baseUrl =
|
|
4889
|
+
const baseUrl = readFlag25(args, "--base-url");
|
|
4776
4890
|
return new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
4777
4891
|
}
|
|
4778
4892
|
async function runStoredCommand(sub, args, env) {
|
|
4779
|
-
const gm = await
|
|
4893
|
+
const gm = await client2(args, env);
|
|
4780
4894
|
if (!gm) return { exitCode: 1, error: "Not signed in. Run `groundmail login`, or set GROUNDMAIL_API_KEY." };
|
|
4781
4895
|
try {
|
|
4782
4896
|
if (sub === "list") {
|
|
@@ -4786,7 +4900,7 @@ async function runStoredCommand(sub, args, env) {
|
|
|
4786
4900
|
if (!data.length) console.error("No imports yet. Previews are not stored.");
|
|
4787
4901
|
return { exitCode: 0 };
|
|
4788
4902
|
}
|
|
4789
|
-
const id = args.find((arg, i) => !arg.startsWith("--") && !
|
|
4903
|
+
const id = args.find((arg, i) => !arg.startsWith("--") && !VALUE_FLAGS5.has(args[i - 1] ?? ""));
|
|
4790
4904
|
if (!id) return { exitCode: 1, error: "Usage: groundmail migrate report <import id> [--csv]" };
|
|
4791
4905
|
if (args.includes("--csv")) {
|
|
4792
4906
|
process.stdout.write(await gm.migrations.reportCsv(id));
|
|
@@ -4805,11 +4919,11 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4805
4919
|
if (!provider || !PROVIDERS2.includes(provider)) {
|
|
4806
4920
|
return {
|
|
4807
4921
|
exitCode: 1,
|
|
4808
|
-
error: "Usage: groundmail migrate <sendgrid|postmark|mailgun|resend|ses> [--dry-run] [--only templates,suppressions], groundmail migrate list, or groundmail migrate report <id> [--csv]"
|
|
4922
|
+
error: "Usage: groundmail migrate <sendgrid|postmark|mailgun|resend|ses|azure> [--dry-run] [--only templates,suppressions], groundmail migrate list, or groundmail migrate report <id> [--csv]"
|
|
4809
4923
|
};
|
|
4810
4924
|
}
|
|
4811
4925
|
const id = provider;
|
|
4812
|
-
const apiKey =
|
|
4926
|
+
const apiKey = readFlag25(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
4813
4927
|
if (!apiKey) {
|
|
4814
4928
|
return { exitCode: 1, error: "Not signed in. Run `groundmail login`, or set GROUNDMAIL_API_KEY." };
|
|
4815
4929
|
}
|
|
@@ -4818,8 +4932,12 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4818
4932
|
const ses = sesParams(args, env);
|
|
4819
4933
|
if (typeof ses === "string") return { exitCode: 1, error: ses };
|
|
4820
4934
|
params = ses;
|
|
4935
|
+
} else if (id === "azure") {
|
|
4936
|
+
const azure = azureParams(args, env);
|
|
4937
|
+
if (typeof azure === "string") return { exitCode: 1, error: azure };
|
|
4938
|
+
params = azure;
|
|
4821
4939
|
} else {
|
|
4822
|
-
const providerKey =
|
|
4940
|
+
const providerKey = readFlag25(args, "--key") || env[KEY_ENV[id]];
|
|
4823
4941
|
if (!providerKey) {
|
|
4824
4942
|
const resend = id === "resend" ? " Use a key with Full access (Resend \u2192 API Keys); a Sending access key cannot read your account." : "";
|
|
4825
4943
|
return {
|
|
@@ -4829,15 +4947,15 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4829
4947
|
}
|
|
4830
4948
|
params = { provider: id, api_key: providerKey };
|
|
4831
4949
|
if (id === "postmark") {
|
|
4832
|
-
const accountToken =
|
|
4950
|
+
const accountToken = readFlag25(args, "--account-token") || env.POSTMARK_ACCOUNT_TOKEN;
|
|
4833
4951
|
if (accountToken) params.account_api_key = accountToken;
|
|
4834
4952
|
} else if (id === "sendgrid" || id === "mailgun") {
|
|
4835
|
-
const region =
|
|
4953
|
+
const region = readFlag25(args, "--region");
|
|
4836
4954
|
if (region === "us" || region === "eu") params.region = region;
|
|
4837
4955
|
else if (region) return { exitCode: 1, error: "--region must be us or eu" };
|
|
4838
4956
|
}
|
|
4839
4957
|
}
|
|
4840
|
-
const only =
|
|
4958
|
+
const only = readFlag25(args, "--only");
|
|
4841
4959
|
if (only) {
|
|
4842
4960
|
const list = only.split(",").map((s) => s.trim()).filter(Boolean);
|
|
4843
4961
|
const bad = list.filter((r) => !RESOURCES.includes(r));
|
|
@@ -4849,10 +4967,10 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4849
4967
|
if (args.includes("--dry-run")) params.dry_run = true;
|
|
4850
4968
|
try {
|
|
4851
4969
|
const { Groundmail } = await import("groundmail");
|
|
4852
|
-
const baseUrl =
|
|
4853
|
-
const
|
|
4970
|
+
const baseUrl = readFlag25(args, "--base-url");
|
|
4971
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
4854
4972
|
console.error(`${params.dry_run ? "Previewing" : "Importing"} from ${LABELS[id]}${params.provider === "ses" ? ` (${params.aws_region})` : ""} (Beta)\u2026`);
|
|
4855
|
-
const report = await
|
|
4973
|
+
const report = await client3.migrations.run(params, {
|
|
4856
4974
|
onProgress: (m) => {
|
|
4857
4975
|
if (m.has_more) {
|
|
4858
4976
|
const s = m.suppressions?.totals;
|
|
@@ -4888,8 +5006,8 @@ async function withClient4(args, env, run) {
|
|
|
4888
5006
|
const apiKey = resolveApiKey7(options, env);
|
|
4889
5007
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY4 };
|
|
4890
5008
|
try {
|
|
4891
|
-
const
|
|
4892
|
-
const output = await run(
|
|
5009
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
5010
|
+
const output = await run(client3);
|
|
4893
5011
|
if (output !== void 0) console.log(JSON.stringify(output));
|
|
4894
5012
|
return { exitCode: 0 };
|
|
4895
5013
|
} catch (error) {
|
|
@@ -4898,7 +5016,7 @@ async function withClient4(args, env, run) {
|
|
|
4898
5016
|
}
|
|
4899
5017
|
async function runSites(action, rest, env) {
|
|
4900
5018
|
if (!action || action === "list" || action.startsWith("--")) {
|
|
4901
|
-
return withClient4(action ? [action, ...rest] : rest, env, (
|
|
5019
|
+
return withClient4(action ? [action, ...rest] : rest, env, (client3) => client3.burrowguard.sites.list());
|
|
4902
5020
|
}
|
|
4903
5021
|
if (action === "create") {
|
|
4904
5022
|
const name = readFlag19(rest, "--name");
|
|
@@ -4909,7 +5027,7 @@ ${USAGE}` };
|
|
|
4909
5027
|
return withClient4(
|
|
4910
5028
|
rest,
|
|
4911
5029
|
env,
|
|
4912
|
-
(
|
|
5030
|
+
(client3) => client3.burrowguard.sites.create({
|
|
4913
5031
|
name,
|
|
4914
5032
|
...hostnames.length > 0 ? { allowed_hostnames: hostnames } : {},
|
|
4915
5033
|
...emailOnly ? { email_checks_only: true } : {},
|
|
@@ -4926,7 +5044,7 @@ ${USAGE}` };
|
|
|
4926
5044
|
const on = rest.includes("--watch-only");
|
|
4927
5045
|
if (on === rest.includes("--no-watch-only")) return { exitCode: 1, error: `Pass --watch-only or --no-watch-only.
|
|
4928
5046
|
${USAGE}` };
|
|
4929
|
-
return withClient4(rest, env, (
|
|
5047
|
+
return withClient4(rest, env, (client3) => client3.burrowguard.sites.update(id, { watch_only: on }));
|
|
4930
5048
|
}
|
|
4931
5049
|
if (action === "delete" || action === "roll-secret") {
|
|
4932
5050
|
const id = rest[0] && !rest[0].startsWith("--") ? rest[0] : void 0;
|
|
@@ -4936,12 +5054,12 @@ ${USAGE}` };
|
|
|
4936
5054
|
const effect = action === "delete" ? "deletes the site and its checks" : "stops the current secret working at once";
|
|
4937
5055
|
return { exitCode: 1, error: `This ${effect}. Pass --yes to go ahead.` };
|
|
4938
5056
|
}
|
|
4939
|
-
return withClient4(rest, env, async (
|
|
5057
|
+
return withClient4(rest, env, async (client3) => {
|
|
4940
5058
|
if (action === "delete") {
|
|
4941
|
-
await
|
|
5059
|
+
await client3.burrowguard.sites.remove(id);
|
|
4942
5060
|
return { deleted: true, id };
|
|
4943
5061
|
}
|
|
4944
|
-
return
|
|
5062
|
+
return client3.burrowguard.sites.rollSecret(id);
|
|
4945
5063
|
});
|
|
4946
5064
|
}
|
|
4947
5065
|
return { exitCode: 1, error: `Unknown command: burrowguard sites ${action}
|
|
@@ -4960,7 +5078,7 @@ function runChecks(args, env) {
|
|
|
4960
5078
|
return withClient4(
|
|
4961
5079
|
args,
|
|
4962
5080
|
env,
|
|
4963
|
-
(
|
|
5081
|
+
(client3) => client3.burrowguard.checks.list({
|
|
4964
5082
|
...readFlag19(args, "--site") ? { site: readFlag19(args, "--site") } : {},
|
|
4965
5083
|
...result ? { result } : {},
|
|
4966
5084
|
...range ? { range } : {},
|
|
@@ -4988,8 +5106,8 @@ async function runValidateCommand(args, env = process.env) {
|
|
|
4988
5106
|
return { exitCode: 1, error: "Missing email. Usage: groundmail validate user@example.com" };
|
|
4989
5107
|
}
|
|
4990
5108
|
try {
|
|
4991
|
-
const
|
|
4992
|
-
const result = await
|
|
5109
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
5110
|
+
const result = await client3.validate(email);
|
|
4993
5111
|
console.log(JSON.stringify(result));
|
|
4994
5112
|
return { exitCode: result.verdict === "invalid" ? 2 : 0 };
|
|
4995
5113
|
} catch (error) {
|
|
@@ -4999,17 +5117,17 @@ async function runValidateCommand(args, env = process.env) {
|
|
|
4999
5117
|
|
|
5000
5118
|
// src/commands/dmarc/dmarc.ts
|
|
5001
5119
|
var DMARC_APPLY_PROVIDERS = ["cloudflare", "vercel", "godaddy", "netlify", "digitalocean", "dnsimple"];
|
|
5002
|
-
function
|
|
5120
|
+
function readFlag26(args, flag) {
|
|
5003
5121
|
const index = args.indexOf(flag);
|
|
5004
5122
|
if (index === -1) return void 0;
|
|
5005
5123
|
return args[index + 1];
|
|
5006
5124
|
}
|
|
5007
|
-
var
|
|
5125
|
+
var VALUE_FLAGS6 = ["--api-key", "--base-url", "--domain", "--apply"];
|
|
5008
5126
|
function readFirstPositional15(args) {
|
|
5009
5127
|
for (let i = 0; i < args.length; i += 1) {
|
|
5010
5128
|
const arg = args[i];
|
|
5011
5129
|
if (arg.startsWith("--")) {
|
|
5012
|
-
if (
|
|
5130
|
+
if (VALUE_FLAGS6.includes(arg)) i += 1;
|
|
5013
5131
|
continue;
|
|
5014
5132
|
}
|
|
5015
5133
|
return arg;
|
|
@@ -5056,27 +5174,27 @@ function formatDmarcStatus(dmarc) {
|
|
|
5056
5174
|
return lines.join("\n");
|
|
5057
5175
|
}
|
|
5058
5176
|
async function runDmarcCommand(subcommand, args, env = process.env) {
|
|
5059
|
-
const apiKey =
|
|
5177
|
+
const apiKey = readFlag26(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
5060
5178
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Run groundmail login, set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
5061
|
-
const domain =
|
|
5179
|
+
const domain = readFlag26(args, "--domain") || readFirstPositional15(args);
|
|
5062
5180
|
if (!subcommand || !["status", "enable", "disable", "digest"].includes(subcommand)) {
|
|
5063
5181
|
return { exitCode: 1, error: "Usage: groundmail dmarc status|enable|disable|digest <domain>" };
|
|
5064
5182
|
}
|
|
5065
5183
|
if (!domain) return { exitCode: 1, error: `Missing domain. Usage: groundmail dmarc ${subcommand} example.com` };
|
|
5066
5184
|
const json = args.includes("--json");
|
|
5067
5185
|
try {
|
|
5068
|
-
const
|
|
5186
|
+
const client3 = await createDmarcClient(apiKey, readFlag26(args, "--base-url"));
|
|
5069
5187
|
if (subcommand === "status") {
|
|
5070
|
-
const result2 = await
|
|
5188
|
+
const result2 = await client3.dmarc.get(domain);
|
|
5071
5189
|
console.log(json ? JSON.stringify(result2) : formatDmarcStatus(result2.dmarc));
|
|
5072
5190
|
return { exitCode: 0 };
|
|
5073
5191
|
}
|
|
5074
5192
|
if (subcommand === "enable") {
|
|
5075
|
-
const apply =
|
|
5193
|
+
const apply = readFlag26(args, "--apply");
|
|
5076
5194
|
if (apply && !DMARC_APPLY_PROVIDERS.includes(apply)) {
|
|
5077
5195
|
return { exitCode: 1, error: `--apply must be one of: ${DMARC_APPLY_PROVIDERS.join(", ")}` };
|
|
5078
5196
|
}
|
|
5079
|
-
const result2 = await
|
|
5197
|
+
const result2 = await client3.dmarc.enable(domain, apply ? { apply } : {});
|
|
5080
5198
|
if (json) console.log(JSON.stringify(result2));
|
|
5081
5199
|
else {
|
|
5082
5200
|
console.log(formatDmarcStatus(result2.dmarc));
|
|
@@ -5087,13 +5205,13 @@ Updated the DMARC record with ${result2.applied.provider}.`);
|
|
|
5087
5205
|
return { exitCode: 0 };
|
|
5088
5206
|
}
|
|
5089
5207
|
if (subcommand === "disable") {
|
|
5090
|
-
const result2 = await
|
|
5208
|
+
const result2 = await client3.dmarc.disable(domain);
|
|
5091
5209
|
console.log(json ? JSON.stringify(result2) : `DMARC monitoring for ${domain} is off. Remove the report address from your DMARC record's rua= tag too.`);
|
|
5092
5210
|
return { exitCode: 0 };
|
|
5093
5211
|
}
|
|
5094
5212
|
const value = args.includes("--off") ? false : args.includes("--on") ? true : void 0;
|
|
5095
5213
|
if (value === void 0) return { exitCode: 1, error: "Usage: groundmail dmarc digest example.com --on|--off" };
|
|
5096
|
-
const result = await
|
|
5214
|
+
const result = await client3.dmarc.update(domain, { digest_enabled: value });
|
|
5097
5215
|
console.log(json ? JSON.stringify(result) : `Weekly DMARC digest for ${domain} is ${value ? "on" : "off"}.`);
|
|
5098
5216
|
return { exitCode: 0 };
|
|
5099
5217
|
} catch (error) {
|
|
@@ -5102,7 +5220,7 @@ Updated the DMARC record with ${result2.applied.provider}.`);
|
|
|
5102
5220
|
}
|
|
5103
5221
|
|
|
5104
5222
|
// src/commands/test-inbox/test-inbox.ts
|
|
5105
|
-
function
|
|
5223
|
+
function readFlag27(args, flag) {
|
|
5106
5224
|
const index = args.indexOf(flag);
|
|
5107
5225
|
if (index === -1) return void 0;
|
|
5108
5226
|
return args[index + 1];
|
|
@@ -5130,20 +5248,20 @@ function formatTestEmail(email) {
|
|
|
5130
5248
|
var USAGE2 = "Usage: groundmail test-inbox address [--prefix signup] | wait --to <address> [--timeout 30] [--since <iso>] [--json] | list [--to <address>] [--json]";
|
|
5131
5249
|
async function runTestInboxCommand(subcommand, args, env = process.env) {
|
|
5132
5250
|
if (!subcommand || !["address", "wait", "list"].includes(subcommand)) return { exitCode: 1, error: USAGE2 };
|
|
5133
|
-
const apiKey =
|
|
5251
|
+
const apiKey = readFlag27(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
5134
5252
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Run groundmail login, set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
5135
5253
|
const json = args.includes("--json");
|
|
5136
5254
|
try {
|
|
5137
|
-
const
|
|
5255
|
+
const client3 = await createTestInboxClient(apiKey, readFlag27(args, "--base-url"));
|
|
5138
5256
|
if (subcommand === "address") {
|
|
5139
|
-
console.log(await
|
|
5257
|
+
console.log(await client3.testInbox.address({ prefix: readFlag27(args, "--prefix") }));
|
|
5140
5258
|
return { exitCode: 0 };
|
|
5141
5259
|
}
|
|
5142
5260
|
if (subcommand === "list") {
|
|
5143
|
-
const result = await
|
|
5144
|
-
to:
|
|
5145
|
-
since:
|
|
5146
|
-
limit:
|
|
5261
|
+
const result = await client3.testInbox.list({
|
|
5262
|
+
to: readFlag27(args, "--to"),
|
|
5263
|
+
since: readFlag27(args, "--since"),
|
|
5264
|
+
limit: readFlag27(args, "--limit") ? Number(readFlag27(args, "--limit")) : void 0
|
|
5147
5265
|
});
|
|
5148
5266
|
if (json) console.log(JSON.stringify(result));
|
|
5149
5267
|
else if (!result.emails.length) console.log("No test emails yet.");
|
|
@@ -5154,13 +5272,13 @@ async function runTestInboxCommand(subcommand, args, env = process.env) {
|
|
|
5154
5272
|
}
|
|
5155
5273
|
return { exitCode: 0 };
|
|
5156
5274
|
}
|
|
5157
|
-
const to =
|
|
5275
|
+
const to = readFlag27(args, "--to");
|
|
5158
5276
|
if (!to) return { exitCode: 1, error: "Missing --to. Usage: groundmail test-inbox wait --to signup-k3m9x2pq@acme.test.groundmail.dev" };
|
|
5159
|
-
const timeoutRaw =
|
|
5277
|
+
const timeoutRaw = readFlag27(args, "--timeout");
|
|
5160
5278
|
const seconds = timeoutRaw === void 0 ? 30 : Number(timeoutRaw);
|
|
5161
5279
|
if (!Number.isFinite(seconds) || seconds < 0) return { exitCode: 1, error: "--timeout must be a number of seconds" };
|
|
5162
5280
|
try {
|
|
5163
|
-
const email = await
|
|
5281
|
+
const email = await client3.testInbox.waitFor({ to, timeout: seconds * 1e3, since: readFlag27(args, "--since") });
|
|
5164
5282
|
console.log(json ? JSON.stringify({ email }) : formatTestEmail(email));
|
|
5165
5283
|
return { exitCode: 0 };
|
|
5166
5284
|
} catch (error) {
|
|
@@ -5176,7 +5294,7 @@ async function runTestInboxCommand(subcommand, args, env = process.env) {
|
|
|
5176
5294
|
}
|
|
5177
5295
|
|
|
5178
5296
|
// src/commands/mailboxes/mailboxes.ts
|
|
5179
|
-
var
|
|
5297
|
+
var VALUE_FLAGS7 = [
|
|
5180
5298
|
"--send-as",
|
|
5181
5299
|
"--allowed-senders",
|
|
5182
5300
|
"--blocked-senders",
|
|
@@ -5375,7 +5493,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5375
5493
|
if (!subcommand || !["create", "owner", "verify", "list", "get", "update", "delete", "forward", "threads", "read", "wait", "send", "reply"].includes(subcommand)) {
|
|
5376
5494
|
return { exitCode: 1, error: USAGE3 };
|
|
5377
5495
|
}
|
|
5378
|
-
const parsed = parseArgs(argv, { values:
|
|
5496
|
+
const parsed = parseArgs(argv, { values: VALUE_FLAGS7, booleans: BOOLEAN_FLAGS });
|
|
5379
5497
|
if (!parsed.ok) return { exitCode: 1, error: parsed.error };
|
|
5380
5498
|
const { args } = parsed;
|
|
5381
5499
|
if (subcommand === "create" && args.booleans["--instant"] === true) return createInstant(args);
|
|
@@ -5391,30 +5509,30 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5391
5509
|
}
|
|
5392
5510
|
const ref = mailbox;
|
|
5393
5511
|
try {
|
|
5394
|
-
const
|
|
5512
|
+
const client3 = await createMailboxesClient(apiKey, v["--base-url"]);
|
|
5395
5513
|
if (subcommand === "owner") {
|
|
5396
5514
|
if (!v["--owner-email"]) return { exitCode: 1, error: "Missing --owner-email." };
|
|
5397
|
-
const owner = await
|
|
5515
|
+
const owner = await client3.mailboxes.setOwner(ref, v["--owner-email"]);
|
|
5398
5516
|
print(owner, () => `Code sent to ${owner.owner_email}. Ask them for it, then run: groundmail mailboxes verify ${ref} --code <code>`);
|
|
5399
5517
|
return { exitCode: 0 };
|
|
5400
5518
|
}
|
|
5401
5519
|
if (subcommand === "verify") {
|
|
5402
5520
|
if (!v["--code"]) return { exitCode: 1, error: "Missing --code." };
|
|
5403
|
-
const verified = await
|
|
5521
|
+
const verified = await client3.mailboxes.verifyOwner(ref, v["--code"]);
|
|
5404
5522
|
print(verified, () => "Verified. This mailbox now has a normal account, with the same key.");
|
|
5405
5523
|
return { exitCode: 0 };
|
|
5406
5524
|
}
|
|
5407
5525
|
if (subcommand === "create") {
|
|
5408
5526
|
const params = createParams(args);
|
|
5409
5527
|
if ("error" in params) return { exitCode: 1, error: params.error };
|
|
5410
|
-
const created = await
|
|
5528
|
+
const created = await client3.mailboxes.create(params);
|
|
5411
5529
|
print({ mailbox: created }, () => formatMailbox(created));
|
|
5412
5530
|
return { exitCode: 0 };
|
|
5413
5531
|
}
|
|
5414
5532
|
if (subcommand === "list") {
|
|
5415
5533
|
const page = paging(args);
|
|
5416
5534
|
if ("error" in page) return { exitCode: 1, error: page.error };
|
|
5417
|
-
const result = await
|
|
5535
|
+
const result = await client3.mailboxes.list({ ...page, ...v["--tenant"] ? { tenant: v["--tenant"] } : {} });
|
|
5418
5536
|
print(
|
|
5419
5537
|
result,
|
|
5420
5538
|
() => result.data.length ? result.data.map((item) => `${item.id} ${item.address} ${item.status}`).join("\n") : "No mailboxes yet."
|
|
@@ -5422,7 +5540,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5422
5540
|
return { exitCode: 0 };
|
|
5423
5541
|
}
|
|
5424
5542
|
if (subcommand === "get") {
|
|
5425
|
-
const found = await
|
|
5543
|
+
const found = await client3.mailboxes.get(ref);
|
|
5426
5544
|
print({ mailbox: found }, () => formatMailbox(found));
|
|
5427
5545
|
return { exitCode: 0 };
|
|
5428
5546
|
}
|
|
@@ -5433,7 +5551,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5433
5551
|
if (sendAs === void 0 && !allowed && !blocked) {
|
|
5434
5552
|
return { exitCode: 1, error: "Nothing to change. Usage: groundmail mailboxes update <mailbox> [--send-as support@example.com] [--allowed-senders you@example.com,example.com] [--blocked-senders spam.example]. Use none to clear one." };
|
|
5435
5553
|
}
|
|
5436
|
-
const updated = await
|
|
5554
|
+
const updated = await client3.mailboxes.update(ref, {
|
|
5437
5555
|
...sendAs !== void 0 ? { send_as: sendAs === "none" ? null : sendAs } : {},
|
|
5438
5556
|
...allowed ? { allowed_senders: allowed } : {},
|
|
5439
5557
|
...blocked ? { blocked_senders: blocked } : {}
|
|
@@ -5445,7 +5563,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5445
5563
|
if (!on("--yes")) {
|
|
5446
5564
|
return { exitCode: 1, error: "This deletes the mailbox and all its mail. Add --yes to confirm." };
|
|
5447
5565
|
}
|
|
5448
|
-
const result = await
|
|
5566
|
+
const result = await client3.mailboxes.delete(ref);
|
|
5449
5567
|
print(result, () => `Deleted ${result.id}`);
|
|
5450
5568
|
return { exitCode: 0 };
|
|
5451
5569
|
}
|
|
@@ -5458,14 +5576,14 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5458
5576
|
error: "This moves the address for good: it can't send again, and its mail is dropped after 30 days. Add --yes to confirm."
|
|
5459
5577
|
};
|
|
5460
5578
|
}
|
|
5461
|
-
const moved = await
|
|
5579
|
+
const moved = await client3.mailboxes.forward(ref, { to });
|
|
5462
5580
|
print({ mailbox: moved }, () => formatMailbox(moved));
|
|
5463
5581
|
return { exitCode: 0 };
|
|
5464
5582
|
}
|
|
5465
5583
|
if (subcommand === "threads") {
|
|
5466
5584
|
const page = paging(args);
|
|
5467
5585
|
if ("error" in page) return { exitCode: 1, error: page.error };
|
|
5468
|
-
const result = await
|
|
5586
|
+
const result = await client3.mailboxes.threads.list(ref, {
|
|
5469
5587
|
...page,
|
|
5470
5588
|
...v["--label"] ? { label: v["--label"] } : {},
|
|
5471
5589
|
...v["--participant"] ? { participant: v["--participant"] } : {},
|
|
@@ -5479,18 +5597,18 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5479
5597
|
}
|
|
5480
5598
|
if (subcommand === "read") {
|
|
5481
5599
|
if (target?.startsWith("thd_")) {
|
|
5482
|
-
const thread = await
|
|
5600
|
+
const thread = await client3.mailboxes.threads.get(ref, target, on("--include-held") ? { include_held: true } : {});
|
|
5483
5601
|
print({ thread }, () => formatThread(thread));
|
|
5484
5602
|
return { exitCode: 0 };
|
|
5485
5603
|
}
|
|
5486
5604
|
if (target) {
|
|
5487
|
-
const message = await
|
|
5605
|
+
const message = await client3.mailboxes.messages.get(ref, target);
|
|
5488
5606
|
print({ message }, () => formatMessage(message));
|
|
5489
5607
|
return { exitCode: 0 };
|
|
5490
5608
|
}
|
|
5491
5609
|
const page = paging(args);
|
|
5492
5610
|
if ("error" in page) return { exitCode: 1, error: page.error };
|
|
5493
|
-
const result = await
|
|
5611
|
+
const result = await client3.mailboxes.messages.list(ref, {
|
|
5494
5612
|
...page,
|
|
5495
5613
|
...v["--search"] ? { q: v["--search"] } : {},
|
|
5496
5614
|
...v["--from"] ? { from: v["--from"] } : {},
|
|
@@ -5510,7 +5628,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5510
5628
|
const body = bodyFlags(args);
|
|
5511
5629
|
if (!body) return { exitCode: 1, error: "Pass --text or --html." };
|
|
5512
5630
|
const cc = addresses(v["--cc"]);
|
|
5513
|
-
const result = await
|
|
5631
|
+
const result = await client3.mailboxes.messages.send(ref, { to, ...cc.length ? { cc } : {}, subject: v["--subject"], ...body });
|
|
5514
5632
|
print(result, () => formatSent(result));
|
|
5515
5633
|
return { exitCode: 0 };
|
|
5516
5634
|
}
|
|
@@ -5518,7 +5636,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5518
5636
|
if (!target) return { exitCode: 1, error: "Missing message id. Usage: groundmail mailboxes reply <mailbox> mbm_\u2026 --text \u2026" };
|
|
5519
5637
|
const body = bodyFlags(args);
|
|
5520
5638
|
if (!body) return { exitCode: 1, error: "Pass --text or --html." };
|
|
5521
|
-
const result = await
|
|
5639
|
+
const result = await client3.mailboxes.messages.reply(ref, target, { ...body, ...on("--reply-all") ? { reply_all: true } : {} });
|
|
5522
5640
|
print(result, () => formatSent(result));
|
|
5523
5641
|
return { exitCode: 0 };
|
|
5524
5642
|
}
|
|
@@ -5526,7 +5644,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5526
5644
|
const seconds = timeoutRaw === void 0 ? 30 : Number(timeoutRaw);
|
|
5527
5645
|
if (!Number.isFinite(seconds) || seconds < 0) return { exitCode: 1, error: "--timeout must be a number of seconds" };
|
|
5528
5646
|
try {
|
|
5529
|
-
const message = await
|
|
5647
|
+
const message = await client3.mailboxes.wait(ref, {
|
|
5530
5648
|
timeout: seconds * 1e3,
|
|
5531
5649
|
...v["--from"] ? { from: v["--from"] } : {},
|
|
5532
5650
|
...v["--thread"] ? { thread: v["--thread"] } : {},
|
|
@@ -6030,6 +6148,11 @@ async function main() {
|
|
|
6030
6148
|
process.exit(result.exitCode);
|
|
6031
6149
|
}
|
|
6032
6150
|
}
|
|
6151
|
+
if (command === "routes") {
|
|
6152
|
+
const result = await runRoutesCommand(subcommand, rest);
|
|
6153
|
+
if (result.error) console.error(result.error);
|
|
6154
|
+
process.exit(result.exitCode);
|
|
6155
|
+
}
|
|
6033
6156
|
if (command === "templates") {
|
|
6034
6157
|
if (subcommand === "list") {
|
|
6035
6158
|
const result = await runListCommand7(rest);
|