groundmail-cli 0.48.0 → 0.49.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/dist/cli.js +381 -281
- 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.49.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",
|
|
@@ -2439,15 +2446,15 @@ function parseArgs(argv, spec) {
|
|
|
2439
2446
|
const booleanFlags = new Set(spec.booleans ?? []);
|
|
2440
2447
|
const values = {};
|
|
2441
2448
|
const booleans = {};
|
|
2442
|
-
const
|
|
2449
|
+
const positionals4 = [];
|
|
2443
2450
|
for (let i = 0; i < argv.length; i++) {
|
|
2444
2451
|
const arg = argv[i];
|
|
2445
2452
|
if (arg === "--") {
|
|
2446
|
-
|
|
2453
|
+
positionals4.push(...argv.slice(i + 1));
|
|
2447
2454
|
break;
|
|
2448
2455
|
}
|
|
2449
2456
|
if (!arg.startsWith("--") || arg === "-") {
|
|
2450
|
-
|
|
2457
|
+
positionals4.push(arg);
|
|
2451
2458
|
continue;
|
|
2452
2459
|
}
|
|
2453
2460
|
const eq = arg.indexOf("=");
|
|
@@ -2473,7 +2480,7 @@ function parseArgs(argv, spec) {
|
|
|
2473
2480
|
const known = [...valueFlags, ...booleanFlags].sort().join(", ");
|
|
2474
2481
|
return { ok: false, error: `Unknown flag ${name}.${known ? ` This command takes: ${known}.` : ""}` };
|
|
2475
2482
|
}
|
|
2476
|
-
return { ok: true, args: { values, booleans, positionals:
|
|
2483
|
+
return { ok: true, args: { values, booleans, positionals: positionals4 } };
|
|
2477
2484
|
}
|
|
2478
2485
|
function wantsJson(args, stdout = process.stdout) {
|
|
2479
2486
|
if (args.booleans["--json"] !== void 0) return args.booleans["--json"];
|
|
@@ -3292,9 +3299,9 @@ async function runDeleteKeyCommandWithClient(args, env = process.env) {
|
|
|
3292
3299
|
return { exitCode: 1, error: "Required: --id <api-key-id>" };
|
|
3293
3300
|
}
|
|
3294
3301
|
const { Groundmail } = await import("groundmail");
|
|
3295
|
-
const
|
|
3302
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
3296
3303
|
try {
|
|
3297
|
-
const result = await
|
|
3304
|
+
const result = await client3.apiKeys.remove(id);
|
|
3298
3305
|
console.log(JSON.stringify(result));
|
|
3299
3306
|
return { exitCode: 0 };
|
|
3300
3307
|
} catch (error) {
|
|
@@ -3332,7 +3339,7 @@ async function runListCommand6(args, env = process.env) {
|
|
|
3332
3339
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3333
3340
|
}
|
|
3334
3341
|
try {
|
|
3335
|
-
const
|
|
3342
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
3336
3343
|
const limitRaw = readFlag19(args, "--limit");
|
|
3337
3344
|
const cursor = readFlag19(args, "--cursor");
|
|
3338
3345
|
const email = readFlag19(args, "--email");
|
|
@@ -3346,7 +3353,7 @@ async function runListCommand6(args, env = process.env) {
|
|
|
3346
3353
|
if (category && category !== "product" && category !== "newsletter") {
|
|
3347
3354
|
return { exitCode: 1, error: "--category must be product or newsletter" };
|
|
3348
3355
|
}
|
|
3349
|
-
const optOuts = await
|
|
3356
|
+
const optOuts = await client3.suppressions.listCategoryOptOuts({
|
|
3350
3357
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
3351
3358
|
...cursor ? { cursor } : {},
|
|
3352
3359
|
...email ? { email } : {},
|
|
@@ -3357,7 +3364,7 @@ async function runListCommand6(args, env = process.env) {
|
|
|
3357
3364
|
console.log(JSON.stringify(optOuts));
|
|
3358
3365
|
return { exitCode: 0 };
|
|
3359
3366
|
}
|
|
3360
|
-
const result = await
|
|
3367
|
+
const result = await client3.suppressions.list({
|
|
3361
3368
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
3362
3369
|
...cursor ? { cursor } : {},
|
|
3363
3370
|
...email ? { email } : {},
|
|
@@ -3383,9 +3390,9 @@ async function runAddCommand2(args, env = process.env) {
|
|
|
3383
3390
|
return { exitCode: 1, error: "Missing email. Pass --email user@example.com" };
|
|
3384
3391
|
}
|
|
3385
3392
|
try {
|
|
3386
|
-
const
|
|
3393
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
3387
3394
|
const reason = readFlag19(args, "--reason");
|
|
3388
|
-
const result = await
|
|
3395
|
+
const result = await client3.suppressions.create({
|
|
3389
3396
|
email,
|
|
3390
3397
|
...reason ? { reason } : {},
|
|
3391
3398
|
...tenant ? { tenant } : {}
|
|
@@ -3420,16 +3427,16 @@ async function runRemoveCommand(args, env = process.env) {
|
|
|
3420
3427
|
return { exitCode: 1, error: "Missing id or email. Pass --id <uuid> or --email user@example.com" };
|
|
3421
3428
|
}
|
|
3422
3429
|
try {
|
|
3423
|
-
const
|
|
3430
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
3424
3431
|
if (type === "category_opt_out") {
|
|
3425
|
-
const optOut = await
|
|
3432
|
+
const optOut = await client3.suppressions.removeCategoryOptOut(idOrEmail, {
|
|
3426
3433
|
...category ? { category } : {},
|
|
3427
3434
|
...tenant ? { tenant } : {}
|
|
3428
3435
|
});
|
|
3429
3436
|
console.log(JSON.stringify(optOut));
|
|
3430
3437
|
return { exitCode: 0 };
|
|
3431
3438
|
}
|
|
3432
|
-
const result = tenant ? await
|
|
3439
|
+
const result = tenant ? await client3.suppressions.remove(idOrEmail, { tenant }) : await client3.suppressions.remove(idOrEmail);
|
|
3433
3440
|
console.log(JSON.stringify(result));
|
|
3434
3441
|
return { exitCode: 0 };
|
|
3435
3442
|
} catch (error) {
|
|
@@ -3437,16 +3444,104 @@ async function runRemoveCommand(args, env = process.env) {
|
|
|
3437
3444
|
}
|
|
3438
3445
|
}
|
|
3439
3446
|
|
|
3440
|
-
// src/commands/
|
|
3447
|
+
// src/commands/routes/routes.ts
|
|
3441
3448
|
function readFlag20(args, flag) {
|
|
3449
|
+
const index = args.indexOf(flag);
|
|
3450
|
+
return index === -1 ? void 0 : args[index + 1];
|
|
3451
|
+
}
|
|
3452
|
+
var VALUE_FLAGS2 = ["--api-key", "--base-url", "--address", "--action", "--url", "--secret", "--forward-to", "--skip-spam", "--id"];
|
|
3453
|
+
function positionals2(args) {
|
|
3454
|
+
const out = [];
|
|
3455
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
3456
|
+
if (args[i].startsWith("--")) {
|
|
3457
|
+
if (VALUE_FLAGS2.includes(args[i])) i += 1;
|
|
3458
|
+
continue;
|
|
3459
|
+
}
|
|
3460
|
+
out.push(args[i]);
|
|
3461
|
+
}
|
|
3462
|
+
return out;
|
|
3463
|
+
}
|
|
3464
|
+
async function client(args, env) {
|
|
3465
|
+
const apiKey = readFlag20(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
3466
|
+
if (!apiKey) return null;
|
|
3467
|
+
const baseUrl = readFlag20(args, "--base-url");
|
|
3468
|
+
const { Groundmail } = await import("groundmail");
|
|
3469
|
+
return new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
3470
|
+
}
|
|
3471
|
+
var ACTIONS = ["url", "forward", "keep", "drop"];
|
|
3472
|
+
function routeParams(args) {
|
|
3473
|
+
const params = {};
|
|
3474
|
+
const action = readFlag20(args, "--action");
|
|
3475
|
+
if (action !== void 0) {
|
|
3476
|
+
if (!ACTIONS.includes(action)) return { ok: false, error: "--action must be url, forward, keep or drop" };
|
|
3477
|
+
params.action = action;
|
|
3478
|
+
}
|
|
3479
|
+
const url = readFlag20(args, "--url");
|
|
3480
|
+
if (url !== void 0) params.url = url;
|
|
3481
|
+
const secret = readFlag20(args, "--secret");
|
|
3482
|
+
if (secret !== void 0) params.secret = secret === "none" ? null : secret;
|
|
3483
|
+
const forwardTo = readFlag20(args, "--forward-to");
|
|
3484
|
+
if (forwardTo !== void 0) params.forwardTo = forwardTo;
|
|
3485
|
+
const skipSpam = readFlag20(args, "--skip-spam");
|
|
3486
|
+
if (skipSpam !== void 0) {
|
|
3487
|
+
if (skipSpam !== "true" && skipSpam !== "false") return { ok: false, error: "--skip-spam must be true or false" };
|
|
3488
|
+
params.skipSpam = skipSpam === "true";
|
|
3489
|
+
}
|
|
3490
|
+
return { ok: true, params };
|
|
3491
|
+
}
|
|
3492
|
+
async function runRoutesCommand(subcommand, args, env = process.env) {
|
|
3493
|
+
const gm = await client(args, env);
|
|
3494
|
+
if (!gm) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3495
|
+
const [domain, routeId] = positionals2(args);
|
|
3496
|
+
if (!domain) return { exitCode: 1, error: "Missing domain. Usage: groundmail routes <list|add|update|remove|test> <domain> \u2026" };
|
|
3497
|
+
try {
|
|
3498
|
+
if (subcommand === "list") {
|
|
3499
|
+
console.log(JSON.stringify(await gm.routes.list(domain)));
|
|
3500
|
+
return { exitCode: 0 };
|
|
3501
|
+
}
|
|
3502
|
+
if (subcommand === "add" || subcommand === "create") {
|
|
3503
|
+
const address = readFlag20(args, "--address");
|
|
3504
|
+
if (!address) return { exitCode: 1, error: "Missing --address (a local part such as support, or *)" };
|
|
3505
|
+
const parsed = routeParams(args);
|
|
3506
|
+
if (!parsed.ok) return { exitCode: 1, error: parsed.error };
|
|
3507
|
+
if (!parsed.params.action) return { exitCode: 1, error: "Missing --action url|forward|keep|drop" };
|
|
3508
|
+
console.log(JSON.stringify(await gm.routes.create(domain, { address, ...parsed.params })));
|
|
3509
|
+
return { exitCode: 0 };
|
|
3510
|
+
}
|
|
3511
|
+
if (subcommand === "update") {
|
|
3512
|
+
const id = readFlag20(args, "--id") ?? routeId;
|
|
3513
|
+
if (!id) return { exitCode: 1, error: "Missing route id" };
|
|
3514
|
+
const parsed = routeParams(args);
|
|
3515
|
+
if (!parsed.ok) return { exitCode: 1, error: parsed.error };
|
|
3516
|
+
console.log(JSON.stringify(await gm.routes.update(domain, id, parsed.params)));
|
|
3517
|
+
return { exitCode: 0 };
|
|
3518
|
+
}
|
|
3519
|
+
if (subcommand === "remove" || subcommand === "delete") {
|
|
3520
|
+
const id = readFlag20(args, "--id") ?? routeId;
|
|
3521
|
+
if (!id) return { exitCode: 1, error: "Missing route id" };
|
|
3522
|
+
console.log(JSON.stringify(await gm.routes.remove(domain, id)));
|
|
3523
|
+
return { exitCode: 0 };
|
|
3524
|
+
}
|
|
3525
|
+
if (subcommand === "test") {
|
|
3526
|
+
console.log(JSON.stringify(await gm.routes.test(domain, readFlag20(args, "--address"))));
|
|
3527
|
+
return { exitCode: 0 };
|
|
3528
|
+
}
|
|
3529
|
+
return { exitCode: 1, error: "Usage: groundmail routes <list|add|update|remove|test> <domain> \u2026" };
|
|
3530
|
+
} catch (error) {
|
|
3531
|
+
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3535
|
+
// src/commands/templates/shared.ts
|
|
3536
|
+
function readFlag21(args, flag) {
|
|
3442
3537
|
const index = args.indexOf(flag);
|
|
3443
3538
|
if (index === -1) return void 0;
|
|
3444
3539
|
return args[index + 1];
|
|
3445
3540
|
}
|
|
3446
3541
|
function parseTemplatesCommonArgs(args) {
|
|
3447
3542
|
return {
|
|
3448
|
-
apiKey:
|
|
3449
|
-
baseUrl:
|
|
3543
|
+
apiKey: readFlag21(args, "--api-key"),
|
|
3544
|
+
baseUrl: readFlag21(args, "--base-url")
|
|
3450
3545
|
};
|
|
3451
3546
|
}
|
|
3452
3547
|
function resolveApiKey8(options, env) {
|
|
@@ -3463,11 +3558,11 @@ async function runDeleteCommand4(args, env = process.env) {
|
|
|
3463
3558
|
const options = parseTemplatesCommonArgs(args);
|
|
3464
3559
|
const apiKey = resolveApiKey8(options, env);
|
|
3465
3560
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3466
|
-
const idOrAlias =
|
|
3561
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional8(args);
|
|
3467
3562
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3468
3563
|
try {
|
|
3469
|
-
const
|
|
3470
|
-
console.log(JSON.stringify(await
|
|
3564
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3565
|
+
console.log(JSON.stringify(await client3.templates.remove(idOrAlias)));
|
|
3471
3566
|
return { exitCode: 0 };
|
|
3472
3567
|
} catch (error) {
|
|
3473
3568
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3491,12 +3586,12 @@ async function runDuplicateCommand(args, env = process.env) {
|
|
|
3491
3586
|
const options = parseTemplatesCommonArgs(args);
|
|
3492
3587
|
const apiKey = resolveApiKey8(options, env);
|
|
3493
3588
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3494
|
-
const idOrAlias =
|
|
3589
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional9(args);
|
|
3495
3590
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3496
|
-
const name =
|
|
3591
|
+
const name = readFlag21(args, "--name");
|
|
3497
3592
|
try {
|
|
3498
|
-
const
|
|
3499
|
-
console.log(JSON.stringify(await
|
|
3593
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3594
|
+
console.log(JSON.stringify(await client3.templates.duplicate(idOrAlias, name ? { name } : {})));
|
|
3500
3595
|
return { exitCode: 0 };
|
|
3501
3596
|
} catch (error) {
|
|
3502
3597
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3520,11 +3615,11 @@ async function runGetCommand6(args, env = process.env) {
|
|
|
3520
3615
|
const options = parseTemplatesCommonArgs(args);
|
|
3521
3616
|
const apiKey = resolveApiKey8(options, env);
|
|
3522
3617
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3523
|
-
const idOrAlias =
|
|
3618
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional10(args);
|
|
3524
3619
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3525
3620
|
try {
|
|
3526
|
-
const
|
|
3527
|
-
console.log(JSON.stringify(await
|
|
3621
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3622
|
+
console.log(JSON.stringify(await client3.templates.get(idOrAlias)));
|
|
3528
3623
|
return { exitCode: 0 };
|
|
3529
3624
|
} catch (error) {
|
|
3530
3625
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3550,11 +3645,11 @@ async function runListCommand7(args, env = process.env) {
|
|
|
3550
3645
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3551
3646
|
}
|
|
3552
3647
|
try {
|
|
3553
|
-
const
|
|
3554
|
-
const limitRaw =
|
|
3555
|
-
const cursor =
|
|
3556
|
-
const status =
|
|
3557
|
-
const result = await
|
|
3648
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3649
|
+
const limitRaw = readFlag21(args, "--limit");
|
|
3650
|
+
const cursor = readFlag21(args, "--cursor");
|
|
3651
|
+
const status = readFlag21(args, "--status");
|
|
3652
|
+
const result = await client3.templates.list({
|
|
3558
3653
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
3559
3654
|
...cursor ? { cursor } : {},
|
|
3560
3655
|
...status ? { status } : {}
|
|
@@ -3572,11 +3667,11 @@ async function runPublishCommand(args, env = process.env) {
|
|
|
3572
3667
|
const options = parseTemplatesCommonArgs(args);
|
|
3573
3668
|
const apiKey = resolveApiKey8(options, env);
|
|
3574
3669
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3575
|
-
const idOrAlias =
|
|
3670
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional11(args);
|
|
3576
3671
|
if (!idOrAlias) return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3577
3672
|
try {
|
|
3578
|
-
const
|
|
3579
|
-
console.log(JSON.stringify(await
|
|
3673
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3674
|
+
console.log(JSON.stringify(await client3.templates.publish(idOrAlias)));
|
|
3580
3675
|
return { exitCode: 0 };
|
|
3581
3676
|
} catch (error) {
|
|
3582
3677
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3684,7 +3779,7 @@ async function loadTemplateSource(filePath, options = {}, deps = {}) {
|
|
|
3684
3779
|
}
|
|
3685
3780
|
|
|
3686
3781
|
// src/commands/templates/push.ts
|
|
3687
|
-
var
|
|
3782
|
+
var VALUE_FLAGS3 = /* @__PURE__ */ new Set([
|
|
3688
3783
|
"--alias",
|
|
3689
3784
|
"--subject",
|
|
3690
3785
|
"--name",
|
|
@@ -3698,7 +3793,7 @@ function readPositional(args) {
|
|
|
3698
3793
|
for (let index = 0; index < args.length; index += 1) {
|
|
3699
3794
|
const arg = args[index];
|
|
3700
3795
|
if (arg.startsWith("--")) {
|
|
3701
|
-
if (
|
|
3796
|
+
if (VALUE_FLAGS3.has(arg)) index += 1;
|
|
3702
3797
|
continue;
|
|
3703
3798
|
}
|
|
3704
3799
|
return arg;
|
|
@@ -3715,19 +3810,19 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3715
3810
|
if (!apiKey) {
|
|
3716
3811
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3717
3812
|
}
|
|
3718
|
-
const file =
|
|
3813
|
+
const file = readFlag21(args, "--file") ?? readPositional(args);
|
|
3719
3814
|
if (!file) {
|
|
3720
3815
|
return { exitCode: 1, error: "Missing template file. Usage: templates push <file> --alias <alias>" };
|
|
3721
3816
|
}
|
|
3722
|
-
const alias =
|
|
3817
|
+
const alias = readFlag21(args, "--alias");
|
|
3723
3818
|
if (!alias) {
|
|
3724
3819
|
return { exitCode: 1, error: "Missing --alias. The alias identifies which template to update." };
|
|
3725
3820
|
}
|
|
3726
|
-
const subject =
|
|
3727
|
-
const name =
|
|
3728
|
-
const preheader =
|
|
3729
|
-
const textFile =
|
|
3730
|
-
const propsRaw =
|
|
3821
|
+
const subject = readFlag21(args, "--subject");
|
|
3822
|
+
const name = readFlag21(args, "--name");
|
|
3823
|
+
const preheader = readFlag21(args, "--preheader");
|
|
3824
|
+
const textFile = readFlag21(args, "--text");
|
|
3825
|
+
const propsRaw = readFlag21(args, "--props");
|
|
3731
3826
|
const shouldPublish = args.includes("--publish");
|
|
3732
3827
|
let props = {};
|
|
3733
3828
|
if (propsRaw) {
|
|
@@ -3751,10 +3846,10 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3751
3846
|
return { exitCode: 1, error: `${file} produced no content to push.` };
|
|
3752
3847
|
}
|
|
3753
3848
|
const createClient2 = deps.createClient ?? createTemplatesClient;
|
|
3754
|
-
const
|
|
3849
|
+
const client3 = await createClient2(apiKey, options.baseUrl);
|
|
3755
3850
|
let existed = true;
|
|
3756
3851
|
try {
|
|
3757
|
-
await
|
|
3852
|
+
await client3.templates.get(alias);
|
|
3758
3853
|
} catch (error) {
|
|
3759
3854
|
if (statusOf(error) !== 404) throw error;
|
|
3760
3855
|
existed = false;
|
|
@@ -3769,7 +3864,7 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3769
3864
|
};
|
|
3770
3865
|
let result;
|
|
3771
3866
|
if (existed) {
|
|
3772
|
-
result = await
|
|
3867
|
+
result = await client3.templates.update(alias, body);
|
|
3773
3868
|
} else {
|
|
3774
3869
|
if (!subject) {
|
|
3775
3870
|
return {
|
|
@@ -3777,7 +3872,7 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3777
3872
|
error: `Template "${alias}" does not exist yet. Pass --subject to create it.`
|
|
3778
3873
|
};
|
|
3779
3874
|
}
|
|
3780
|
-
result = await
|
|
3875
|
+
result = await client3.templates.create({
|
|
3781
3876
|
name: name || alias,
|
|
3782
3877
|
subject,
|
|
3783
3878
|
alias,
|
|
@@ -3785,7 +3880,7 @@ async function runPushCommand(args, env = process.env, deps = {}) {
|
|
|
3785
3880
|
});
|
|
3786
3881
|
}
|
|
3787
3882
|
if (shouldPublish) {
|
|
3788
|
-
result = await
|
|
3883
|
+
result = await client3.templates.publish(alias);
|
|
3789
3884
|
}
|
|
3790
3885
|
console.log(JSON.stringify({ ...result, pushed: { file, alias, created: !existed } }));
|
|
3791
3886
|
return { exitCode: 0 };
|
|
@@ -3801,14 +3896,14 @@ async function runCreateCommand3(args, env = process.env) {
|
|
|
3801
3896
|
if (!apiKey) {
|
|
3802
3897
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3803
3898
|
}
|
|
3804
|
-
const name =
|
|
3805
|
-
const subject =
|
|
3806
|
-
const html =
|
|
3807
|
-
const text =
|
|
3808
|
-
const alias =
|
|
3809
|
-
const category =
|
|
3810
|
-
const folder =
|
|
3811
|
-
const sender =
|
|
3899
|
+
const name = readFlag21(args, "--name");
|
|
3900
|
+
const subject = readFlag21(args, "--subject");
|
|
3901
|
+
const html = readFlag21(args, "--html");
|
|
3902
|
+
const text = readFlag21(args, "--text");
|
|
3903
|
+
const alias = readFlag21(args, "--alias");
|
|
3904
|
+
const category = readFlag21(args, "--category");
|
|
3905
|
+
const folder = readFlag21(args, "--folder");
|
|
3906
|
+
const sender = readFlag21(args, "--sender");
|
|
3812
3907
|
const unsubscribeEnabled = args.includes("--unsubscribe-enabled");
|
|
3813
3908
|
if (!name) {
|
|
3814
3909
|
return { exitCode: 1, error: 'Missing name. Pass --name "Welcome"' };
|
|
@@ -3820,8 +3915,8 @@ async function runCreateCommand3(args, env = process.env) {
|
|
|
3820
3915
|
return { exitCode: 1, error: 'Missing body. Pass --html "<p>Hi</p>" or --text "Hi"' };
|
|
3821
3916
|
}
|
|
3822
3917
|
try {
|
|
3823
|
-
const
|
|
3824
|
-
const result = await
|
|
3918
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3919
|
+
const result = await client3.templates.create({
|
|
3825
3920
|
name,
|
|
3826
3921
|
subject,
|
|
3827
3922
|
...html ? { html } : {},
|
|
@@ -3860,19 +3955,19 @@ async function runUpdateCommand4(args, env = process.env) {
|
|
|
3860
3955
|
if (!apiKey) {
|
|
3861
3956
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3862
3957
|
}
|
|
3863
|
-
const idOrAlias =
|
|
3958
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional12(args);
|
|
3864
3959
|
if (!idOrAlias) {
|
|
3865
3960
|
return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3866
3961
|
}
|
|
3867
|
-
const name =
|
|
3868
|
-
const subject =
|
|
3869
|
-
const html =
|
|
3870
|
-
const text =
|
|
3871
|
-
const alias =
|
|
3962
|
+
const name = readFlag21(args, "--name");
|
|
3963
|
+
const subject = readFlag21(args, "--subject");
|
|
3964
|
+
const html = readFlag21(args, "--html");
|
|
3965
|
+
const text = readFlag21(args, "--text");
|
|
3966
|
+
const alias = readFlag21(args, "--set-alias");
|
|
3872
3967
|
const variables = readFlags3(args, "--variable");
|
|
3873
|
-
const category =
|
|
3874
|
-
const folder =
|
|
3875
|
-
const sender =
|
|
3968
|
+
const category = readFlag21(args, "--category");
|
|
3969
|
+
const folder = readFlag21(args, "--folder");
|
|
3970
|
+
const sender = readFlag21(args, "--sender");
|
|
3876
3971
|
const unsubscribeEnabled = args.includes("--unsubscribe-enabled");
|
|
3877
3972
|
const unsubscribeDisabled = args.includes("--no-unsubscribe-enabled");
|
|
3878
3973
|
if (!name && !subject && !html && !text && !alias && variables.length === 0 && !category && folder === void 0 && sender === void 0 && !unsubscribeEnabled && !unsubscribeDisabled) {
|
|
@@ -3882,8 +3977,8 @@ async function runUpdateCommand4(args, env = process.env) {
|
|
|
3882
3977
|
};
|
|
3883
3978
|
}
|
|
3884
3979
|
try {
|
|
3885
|
-
const
|
|
3886
|
-
const result = await
|
|
3980
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
3981
|
+
const result = await client3.templates.update(idOrAlias, {
|
|
3887
3982
|
...name ? { name } : {},
|
|
3888
3983
|
...subject ? { subject } : {},
|
|
3889
3984
|
...html ? { html } : {},
|
|
@@ -3940,7 +4035,7 @@ async function runFromStarterCommand(args, env = process.env) {
|
|
|
3940
4035
|
if (!apiKey) {
|
|
3941
4036
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3942
4037
|
}
|
|
3943
|
-
const alias =
|
|
4038
|
+
const alias = readFlag21(args, "--alias") || readFirstPositional13(args);
|
|
3944
4039
|
if (!alias) {
|
|
3945
4040
|
return {
|
|
3946
4041
|
exitCode: 1,
|
|
@@ -3948,8 +4043,8 @@ async function runFromStarterCommand(args, env = process.env) {
|
|
|
3948
4043
|
};
|
|
3949
4044
|
}
|
|
3950
4045
|
try {
|
|
3951
|
-
const
|
|
3952
|
-
console.log(JSON.stringify(await
|
|
4046
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4047
|
+
console.log(JSON.stringify(await client3.templates.fromStarter(alias)));
|
|
3953
4048
|
return { exitCode: 0 };
|
|
3954
4049
|
} catch (error) {
|
|
3955
4050
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3962,8 +4057,8 @@ async function runListStartersCommand(args, env = process.env) {
|
|
|
3962
4057
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3963
4058
|
}
|
|
3964
4059
|
try {
|
|
3965
|
-
const
|
|
3966
|
-
console.log(JSON.stringify(await
|
|
4060
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4061
|
+
console.log(JSON.stringify(await client3.templates.listStarters()));
|
|
3967
4062
|
return { exitCode: 0 };
|
|
3968
4063
|
} catch (error) {
|
|
3969
4064
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -3989,13 +4084,13 @@ async function runVersionsCommand(args, env = process.env) {
|
|
|
3989
4084
|
if (!apiKey) {
|
|
3990
4085
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
3991
4086
|
}
|
|
3992
|
-
const idOrAlias =
|
|
4087
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional14(args);
|
|
3993
4088
|
if (!idOrAlias) {
|
|
3994
4089
|
return { exitCode: 1, error: "Missing template id or alias. Pass --id tpl_\u2026 or --alias welcome" };
|
|
3995
4090
|
}
|
|
3996
4091
|
try {
|
|
3997
|
-
const
|
|
3998
|
-
console.log(JSON.stringify(await
|
|
4092
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4093
|
+
console.log(JSON.stringify(await client3.templates.listVersions(idOrAlias)));
|
|
3999
4094
|
return { exitCode: 0 };
|
|
4000
4095
|
} catch (error) {
|
|
4001
4096
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -4007,8 +4102,8 @@ async function runRestoreCommand(args, env = process.env) {
|
|
|
4007
4102
|
if (!apiKey) {
|
|
4008
4103
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4009
4104
|
}
|
|
4010
|
-
const idOrAlias =
|
|
4011
|
-
const versionRaw =
|
|
4105
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional14(args);
|
|
4106
|
+
const versionRaw = readFlag21(args, "--version");
|
|
4012
4107
|
const version2 = versionRaw ? Number.parseInt(versionRaw, 10) : NaN;
|
|
4013
4108
|
if (!idOrAlias || !Number.isFinite(version2) || version2 < 1) {
|
|
4014
4109
|
return {
|
|
@@ -4017,8 +4112,8 @@ async function runRestoreCommand(args, env = process.env) {
|
|
|
4017
4112
|
};
|
|
4018
4113
|
}
|
|
4019
4114
|
try {
|
|
4020
|
-
const
|
|
4021
|
-
console.log(JSON.stringify(await
|
|
4115
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4116
|
+
console.log(JSON.stringify(await client3.templates.restoreVersion(idOrAlias, version2)));
|
|
4022
4117
|
return { exitCode: 0 };
|
|
4023
4118
|
} catch (error) {
|
|
4024
4119
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
@@ -4030,10 +4125,10 @@ async function runTestSendCommand(args, env = process.env) {
|
|
|
4030
4125
|
if (!apiKey) {
|
|
4031
4126
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4032
4127
|
}
|
|
4033
|
-
const idOrAlias =
|
|
4034
|
-
const from =
|
|
4035
|
-
const sender =
|
|
4036
|
-
const to =
|
|
4128
|
+
const idOrAlias = readFlag21(args, "--id") || readFlag21(args, "--alias") || readFirstPositional14(args);
|
|
4129
|
+
const from = readFlag21(args, "--from");
|
|
4130
|
+
const sender = readFlag21(args, "--sender");
|
|
4131
|
+
const to = readFlag21(args, "--to");
|
|
4037
4132
|
if (!idOrAlias || !to) {
|
|
4038
4133
|
return {
|
|
4039
4134
|
exitCode: 1,
|
|
@@ -4041,10 +4136,10 @@ async function runTestSendCommand(args, env = process.env) {
|
|
|
4041
4136
|
};
|
|
4042
4137
|
}
|
|
4043
4138
|
try {
|
|
4044
|
-
const
|
|
4139
|
+
const client3 = await createTemplatesClient(apiKey, options.baseUrl);
|
|
4045
4140
|
console.log(
|
|
4046
4141
|
JSON.stringify(
|
|
4047
|
-
await
|
|
4142
|
+
await client3.templates.testSend(idOrAlias, { to, ...from ? { from } : {}, ...sender ? { sender } : {} })
|
|
4048
4143
|
)
|
|
4049
4144
|
);
|
|
4050
4145
|
return { exitCode: 0 };
|
|
@@ -4054,15 +4149,15 @@ async function runTestSendCommand(args, env = process.env) {
|
|
|
4054
4149
|
}
|
|
4055
4150
|
|
|
4056
4151
|
// src/commands/integrations/shared.ts
|
|
4057
|
-
function
|
|
4152
|
+
function readFlag22(args, flag) {
|
|
4058
4153
|
const index = args.indexOf(flag);
|
|
4059
4154
|
if (index === -1) return void 0;
|
|
4060
4155
|
return args[index + 1];
|
|
4061
4156
|
}
|
|
4062
4157
|
function parseIntegrationsCommonArgs(args) {
|
|
4063
4158
|
return {
|
|
4064
|
-
apiKey:
|
|
4065
|
-
baseUrl:
|
|
4159
|
+
apiKey: readFlag22(args, "--api-key"),
|
|
4160
|
+
baseUrl: readFlag22(args, "--base-url")
|
|
4066
4161
|
};
|
|
4067
4162
|
}
|
|
4068
4163
|
function resolveApiKey9(options, env) {
|
|
@@ -4081,8 +4176,8 @@ async function runTwilioStatusCommand(args, env = process.env) {
|
|
|
4081
4176
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4082
4177
|
}
|
|
4083
4178
|
try {
|
|
4084
|
-
const
|
|
4085
|
-
const result = await
|
|
4179
|
+
const client3 = await createIntegrationsClient(apiKey, options.baseUrl);
|
|
4180
|
+
const result = await client3.integrations.getTwilio();
|
|
4086
4181
|
console.log(JSON.stringify(result));
|
|
4087
4182
|
return { exitCode: 0 };
|
|
4088
4183
|
} catch (error) {
|
|
@@ -4095,10 +4190,10 @@ async function runTwilioConnectCommand(args, env = process.env) {
|
|
|
4095
4190
|
if (!apiKey) {
|
|
4096
4191
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4097
4192
|
}
|
|
4098
|
-
const accountSid =
|
|
4099
|
-
const authToken =
|
|
4100
|
-
const defaultFrom =
|
|
4101
|
-
const messagingServiceSid =
|
|
4193
|
+
const accountSid = readFlag22(args, "--account-sid") || env.TWILIO_ACCOUNT_SID || env.TWILIO_SID || "";
|
|
4194
|
+
const authToken = readFlag22(args, "--auth-token") || env.TWILIO_AUTH_TOKEN || env.TWILIO_TOKEN || "";
|
|
4195
|
+
const defaultFrom = readFlag22(args, "--from") || readFlag22(args, "--default-from") || env.TWILIO_DEFAULT_FROM || "";
|
|
4196
|
+
const messagingServiceSid = readFlag22(args, "--messaging-service-sid") || readFlag22(args, "--messaging-sid") || env.TWILIO_MESSAGING_SERVICE_SID || "";
|
|
4102
4197
|
if (!accountSid.trim() || !authToken.trim()) {
|
|
4103
4198
|
return {
|
|
4104
4199
|
exitCode: 1,
|
|
@@ -4112,8 +4207,8 @@ async function runTwilioConnectCommand(args, env = process.env) {
|
|
|
4112
4207
|
};
|
|
4113
4208
|
}
|
|
4114
4209
|
try {
|
|
4115
|
-
const
|
|
4116
|
-
const result = await
|
|
4210
|
+
const client3 = await createIntegrationsClient(apiKey, options.baseUrl);
|
|
4211
|
+
const result = await client3.integrations.connectTwilio({
|
|
4117
4212
|
accountSid: accountSid.trim(),
|
|
4118
4213
|
authToken: authToken.trim(),
|
|
4119
4214
|
...defaultFrom.trim() ? { defaultFrom: defaultFrom.trim() } : {},
|
|
@@ -4132,8 +4227,8 @@ async function runTwilioDisconnectCommand(args, env = process.env) {
|
|
|
4132
4227
|
return { exitCode: 1, error: "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
4133
4228
|
}
|
|
4134
4229
|
try {
|
|
4135
|
-
const
|
|
4136
|
-
const result = await
|
|
4230
|
+
const client3 = await createIntegrationsClient(apiKey, options.baseUrl);
|
|
4231
|
+
const result = await client3.integrations.disconnectTwilio();
|
|
4137
4232
|
console.log(JSON.stringify(result));
|
|
4138
4233
|
return { exitCode: 0 };
|
|
4139
4234
|
} catch (error) {
|
|
@@ -4147,8 +4242,8 @@ async function withClient(args, env, run) {
|
|
|
4147
4242
|
const apiKey = resolveApiKey5(options, env);
|
|
4148
4243
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY };
|
|
4149
4244
|
try {
|
|
4150
|
-
const
|
|
4151
|
-
console.log(JSON.stringify(await run(
|
|
4245
|
+
const client3 = await createTenantsClient(apiKey, options.baseUrl);
|
|
4246
|
+
console.log(JSON.stringify(await run(client3)));
|
|
4152
4247
|
return { exitCode: 0 };
|
|
4153
4248
|
} catch (error) {
|
|
4154
4249
|
return failure(error);
|
|
@@ -4167,7 +4262,7 @@ async function runListCommand8(args, env = process.env) {
|
|
|
4167
4262
|
return withClient(
|
|
4168
4263
|
args,
|
|
4169
4264
|
env,
|
|
4170
|
-
(
|
|
4265
|
+
(client3) => client3.tenants.list({
|
|
4171
4266
|
...limitRaw ? { limit: Number(limitRaw) } : {},
|
|
4172
4267
|
...cursor ? { cursor } : {},
|
|
4173
4268
|
...status ? { status } : {}
|
|
@@ -4181,12 +4276,12 @@ async function runCreateCommand4(args, env = process.env) {
|
|
|
4181
4276
|
}
|
|
4182
4277
|
const settings = parseTenantSettings(args);
|
|
4183
4278
|
if ("error" in settings) return { exitCode: 1, error: settings.error };
|
|
4184
|
-
return withClient(args, env, (
|
|
4279
|
+
return withClient(args, env, (client3) => client3.tenants.create({ external_id: externalId, ...settings.value }));
|
|
4185
4280
|
}
|
|
4186
4281
|
async function runGetCommand7(args, env = process.env) {
|
|
4187
4282
|
const tenant = tenantRef(args);
|
|
4188
4283
|
if (!tenant) return missingTenant("groundmail tenants get <tenant>");
|
|
4189
|
-
return withClient(args, env, (
|
|
4284
|
+
return withClient(args, env, (client3) => client3.tenants.get(tenant));
|
|
4190
4285
|
}
|
|
4191
4286
|
async function runUpdateCommand5(args, env = process.env) {
|
|
4192
4287
|
const tenant = tenantRef(args);
|
|
@@ -4199,18 +4294,18 @@ async function runUpdateCommand5(args, env = process.env) {
|
|
|
4199
4294
|
error: "Nothing to update. Pass --name, --default-from-domain, --stream-policy, --daily-limit or --metadata (or use tenants pause / resume)."
|
|
4200
4295
|
};
|
|
4201
4296
|
}
|
|
4202
|
-
return withClient(args, env, (
|
|
4297
|
+
return withClient(args, env, (client3) => client3.tenants.update(tenant, settings.value));
|
|
4203
4298
|
}
|
|
4204
4299
|
async function runPauseCommand2(args, env = process.env) {
|
|
4205
4300
|
const tenant = tenantRef(args);
|
|
4206
4301
|
if (!tenant) return missingTenant("groundmail tenants pause <tenant> [--reason \u2026]");
|
|
4207
4302
|
const reason = readFlag12(args, "--reason");
|
|
4208
|
-
return withClient(args, env, (
|
|
4303
|
+
return withClient(args, env, (client3) => client3.tenants.pause(tenant, reason));
|
|
4209
4304
|
}
|
|
4210
4305
|
async function runResumeCommand(args, env = process.env) {
|
|
4211
4306
|
const tenant = tenantRef(args);
|
|
4212
4307
|
if (!tenant) return missingTenant("groundmail tenants resume <tenant>");
|
|
4213
|
-
return withClient(args, env, (
|
|
4308
|
+
return withClient(args, env, (client3) => client3.tenants.resume(tenant));
|
|
4214
4309
|
}
|
|
4215
4310
|
async function runDeleteCommand5(args, env = process.env) {
|
|
4216
4311
|
const tenant = tenantRef(args);
|
|
@@ -4221,7 +4316,7 @@ async function runDeleteCommand5(args, env = process.env) {
|
|
|
4221
4316
|
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
4317
|
};
|
|
4223
4318
|
}
|
|
4224
|
-
return withClient(args, env, (
|
|
4319
|
+
return withClient(args, env, (client3) => client3.tenants.delete(tenant));
|
|
4225
4320
|
}
|
|
4226
4321
|
async function runStatsCommand(args, env = process.env) {
|
|
4227
4322
|
const tenant = tenantRef(args);
|
|
@@ -4231,7 +4326,7 @@ async function runStatsCommand(args, env = process.env) {
|
|
|
4231
4326
|
if (days !== void 0 && (!Number.isInteger(days) || days < 1 || days > 90)) {
|
|
4232
4327
|
return { exitCode: 1, error: "--days must be a whole number from 1 to 90" };
|
|
4233
4328
|
}
|
|
4234
|
-
return withClient(args, env, (
|
|
4329
|
+
return withClient(args, env, (client3) => client3.tenants.stats(tenant, days !== void 0 ? { days } : {}));
|
|
4235
4330
|
}
|
|
4236
4331
|
async function runDomainsCommand(args, env = process.env) {
|
|
4237
4332
|
const [action, ...rest] = args;
|
|
@@ -4240,19 +4335,19 @@ async function runDomainsCommand(args, env = process.env) {
|
|
|
4240
4335
|
const domain = readFlag12(rest, "--domain") || pos.shift();
|
|
4241
4336
|
if (action === "list") {
|
|
4242
4337
|
if (!tenant) return missingTenant("groundmail tenants domains list <tenant>");
|
|
4243
|
-
return withClient(rest, env, (
|
|
4338
|
+
return withClient(rest, env, (client3) => client3.tenants.domains.list(tenant));
|
|
4244
4339
|
}
|
|
4245
4340
|
if (action === "add" || action === "assign") {
|
|
4246
4341
|
if (!tenant || !domain) {
|
|
4247
4342
|
return { exitCode: 1, error: "Usage: groundmail tenants domains add <tenant> <domain>" };
|
|
4248
4343
|
}
|
|
4249
|
-
return withClient(rest, env, (
|
|
4344
|
+
return withClient(rest, env, (client3) => client3.tenants.domains.assign(tenant, domain));
|
|
4250
4345
|
}
|
|
4251
4346
|
if (action === "remove" || action === "unassign" || action === "delete") {
|
|
4252
4347
|
if (!tenant || !domain) {
|
|
4253
4348
|
return { exitCode: 1, error: "Usage: groundmail tenants domains remove <tenant> <domain>" };
|
|
4254
4349
|
}
|
|
4255
|
-
return withClient(rest, env, (
|
|
4350
|
+
return withClient(rest, env, (client3) => client3.tenants.domains.unassign(tenant, domain));
|
|
4256
4351
|
}
|
|
4257
4352
|
return {
|
|
4258
4353
|
exitCode: 1,
|
|
@@ -4262,7 +4357,7 @@ async function runDomainsCommand(args, env = process.env) {
|
|
|
4262
4357
|
|
|
4263
4358
|
// src/commands/senders/shared.ts
|
|
4264
4359
|
var SENDER_VALUE_FLAGS = ["--api-key", "--base-url", "--id", "--name", "--address", "--reply-to", "--handle"];
|
|
4265
|
-
function
|
|
4360
|
+
function readFlag23(args, flag) {
|
|
4266
4361
|
const index = args.indexOf(flag);
|
|
4267
4362
|
if (index === -1) return void 0;
|
|
4268
4363
|
return args[index + 1];
|
|
@@ -4270,7 +4365,7 @@ function readFlag22(args, flag) {
|
|
|
4270
4365
|
function hasFlag2(args, flag) {
|
|
4271
4366
|
return args.includes(flag);
|
|
4272
4367
|
}
|
|
4273
|
-
function
|
|
4368
|
+
function positionals3(args, valueFlags = SENDER_VALUE_FLAGS) {
|
|
4274
4369
|
const out = [];
|
|
4275
4370
|
for (let i = 0; i < args.length; i += 1) {
|
|
4276
4371
|
const arg = args[i];
|
|
@@ -4284,8 +4379,8 @@ function positionals2(args, valueFlags = SENDER_VALUE_FLAGS) {
|
|
|
4284
4379
|
}
|
|
4285
4380
|
function parseSendersCommonArgs(args) {
|
|
4286
4381
|
return {
|
|
4287
|
-
apiKey:
|
|
4288
|
-
baseUrl:
|
|
4382
|
+
apiKey: readFlag23(args, "--api-key"),
|
|
4383
|
+
baseUrl: readFlag23(args, "--base-url")
|
|
4289
4384
|
};
|
|
4290
4385
|
}
|
|
4291
4386
|
function resolveApiKey10(options, env) {
|
|
@@ -4303,13 +4398,13 @@ function failure2(error) {
|
|
|
4303
4398
|
${hint}` : message };
|
|
4304
4399
|
}
|
|
4305
4400
|
function senderRef(args) {
|
|
4306
|
-
return
|
|
4401
|
+
return readFlag23(args, "--id") || positionals3(args)[0];
|
|
4307
4402
|
}
|
|
4308
4403
|
function parseSenderFields(args) {
|
|
4309
|
-
const name =
|
|
4310
|
-
const address =
|
|
4311
|
-
const replyTo =
|
|
4312
|
-
const handle =
|
|
4404
|
+
const name = readFlag23(args, "--name");
|
|
4405
|
+
const address = readFlag23(args, "--address");
|
|
4406
|
+
const replyTo = readFlag23(args, "--reply-to");
|
|
4407
|
+
const handle = readFlag23(args, "--handle");
|
|
4313
4408
|
const makeDefault = hasFlag2(args, "--default");
|
|
4314
4409
|
const notDefault = hasFlag2(args, "--no-default");
|
|
4315
4410
|
if (makeDefault && notDefault) return { error: "Pass --default or --no-default, not both" };
|
|
@@ -4330,8 +4425,8 @@ async function withClient2(args, env, run) {
|
|
|
4330
4425
|
const apiKey = resolveApiKey10(options, env);
|
|
4331
4426
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY2 };
|
|
4332
4427
|
try {
|
|
4333
|
-
const
|
|
4334
|
-
console.log(JSON.stringify(await run(
|
|
4428
|
+
const client3 = await createSendersClient(apiKey, options.baseUrl);
|
|
4429
|
+
console.log(JSON.stringify(await run(client3)));
|
|
4335
4430
|
return { exitCode: 0 };
|
|
4336
4431
|
} catch (error) {
|
|
4337
4432
|
return failure2(error);
|
|
@@ -4341,7 +4436,7 @@ function missingSender(usage) {
|
|
|
4341
4436
|
return { exitCode: 1, error: `Missing sender (id or handle). Usage: ${usage}` };
|
|
4342
4437
|
}
|
|
4343
4438
|
async function runListCommand9(args, env = process.env) {
|
|
4344
|
-
return withClient2(args, env, (
|
|
4439
|
+
return withClient2(args, env, (client3) => client3.senders.list());
|
|
4345
4440
|
}
|
|
4346
4441
|
async function runCreateCommand5(args, env = process.env) {
|
|
4347
4442
|
const fields = parseSenderFields(args);
|
|
@@ -4353,12 +4448,12 @@ async function runCreateCommand5(args, env = process.env) {
|
|
|
4353
4448
|
error: 'Required: --name and --address. Usage: groundmail senders create --name "Acme Billing" --address billing@mail.acme.com [--reply-to \u2026] [--handle billing] [--default]'
|
|
4354
4449
|
};
|
|
4355
4450
|
}
|
|
4356
|
-
return withClient2(args, env, (
|
|
4451
|
+
return withClient2(args, env, (client3) => client3.senders.create({ ...fields.value, name, address }));
|
|
4357
4452
|
}
|
|
4358
4453
|
async function runGetCommand8(args, env = process.env) {
|
|
4359
4454
|
const sender = senderRef(args);
|
|
4360
4455
|
if (!sender) return missingSender("groundmail senders get <id|handle>");
|
|
4361
|
-
return withClient2(args, env, (
|
|
4456
|
+
return withClient2(args, env, (client3) => client3.senders.get(sender));
|
|
4362
4457
|
}
|
|
4363
4458
|
async function runUpdateCommand6(args, env = process.env) {
|
|
4364
4459
|
const sender = senderRef(args);
|
|
@@ -4371,7 +4466,7 @@ async function runUpdateCommand6(args, env = process.env) {
|
|
|
4371
4466
|
error: "Nothing to update. Pass --name, --address, --reply-to, --handle, --default or --no-default."
|
|
4372
4467
|
};
|
|
4373
4468
|
}
|
|
4374
|
-
return withClient2(args, env, (
|
|
4469
|
+
return withClient2(args, env, (client3) => client3.senders.update(sender, fields.value));
|
|
4375
4470
|
}
|
|
4376
4471
|
async function runDeleteCommand6(args, env = process.env) {
|
|
4377
4472
|
const sender = senderRef(args);
|
|
@@ -4382,7 +4477,7 @@ async function runDeleteCommand6(args, env = process.env) {
|
|
|
4382
4477
|
error: `This deletes sender ${sender}. Sends that name it will fail. Run again with --yes to confirm.`
|
|
4383
4478
|
};
|
|
4384
4479
|
}
|
|
4385
|
-
return withClient2(args, env, (
|
|
4480
|
+
return withClient2(args, env, (client3) => client3.senders.remove(sender));
|
|
4386
4481
|
}
|
|
4387
4482
|
|
|
4388
4483
|
// src/commands/brand/commands.ts
|
|
@@ -4406,26 +4501,26 @@ async function withClient3(args, env, run) {
|
|
|
4406
4501
|
const apiKey = resolveApiKey10(options, env);
|
|
4407
4502
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY2 };
|
|
4408
4503
|
try {
|
|
4409
|
-
const
|
|
4410
|
-
console.log(JSON.stringify(await run(
|
|
4504
|
+
const client3 = await createBrandClient(apiKey, options.baseUrl);
|
|
4505
|
+
console.log(JSON.stringify(await run(client3)));
|
|
4411
4506
|
return { exitCode: 0 };
|
|
4412
4507
|
} catch (error) {
|
|
4413
4508
|
return failure2(error);
|
|
4414
4509
|
}
|
|
4415
4510
|
}
|
|
4416
4511
|
async function runGetCommand9(args, env = process.env) {
|
|
4417
|
-
return withClient3(args, env, (
|
|
4512
|
+
return withClient3(args, env, (client3) => client3.brand.get());
|
|
4418
4513
|
}
|
|
4419
4514
|
function clearable(value) {
|
|
4420
4515
|
if (value === void 0) return void 0;
|
|
4421
4516
|
return value === "none" || value === "" ? null : value;
|
|
4422
4517
|
}
|
|
4423
4518
|
async function runSetCommand(args, env = process.env) {
|
|
4424
|
-
const logoUrl = clearable(
|
|
4425
|
-
const logoAlign =
|
|
4426
|
-
const logoWidth =
|
|
4427
|
-
const color =
|
|
4428
|
-
const settingsFile =
|
|
4519
|
+
const logoUrl = clearable(readFlag23(args, "--logo-url"));
|
|
4520
|
+
const logoAlign = readFlag23(args, "--logo-align");
|
|
4521
|
+
const logoWidth = readFlag23(args, "--logo-width");
|
|
4522
|
+
const color = readFlag23(args, "--color");
|
|
4523
|
+
const settingsFile = readFlag23(args, "--settings-file");
|
|
4429
4524
|
if (logoAlign !== void 0 && logoAlign !== "left" && logoAlign !== "center") {
|
|
4430
4525
|
return { exitCode: 1, error: "--logo-align must be left or center" };
|
|
4431
4526
|
}
|
|
@@ -4446,9 +4541,9 @@ async function runSetCommand(args, env = process.env) {
|
|
|
4446
4541
|
if (logoUrl !== void 0) {
|
|
4447
4542
|
params.logo = logoUrl === null ? null : { url: logoUrl, align: logoAlign ?? "left", ...logoWidth ? { width: Number(logoWidth) } : {} };
|
|
4448
4543
|
}
|
|
4449
|
-
const company = clearable(
|
|
4450
|
-
const address = clearable(
|
|
4451
|
-
const website = clearable(
|
|
4544
|
+
const company = clearable(readFlag23(args, "--company"));
|
|
4545
|
+
const address = clearable(readFlag23(args, "--address"));
|
|
4546
|
+
const website = clearable(readFlag23(args, "--website"));
|
|
4452
4547
|
if (company !== void 0) params.company_name = company;
|
|
4453
4548
|
if (address !== void 0) params.address = address;
|
|
4454
4549
|
if (website !== void 0) params.website = website;
|
|
@@ -4459,9 +4554,9 @@ async function runSetCommand(args, env = process.env) {
|
|
|
4459
4554
|
error: "Nothing to set. Usage: groundmail brand set [--logo-url \u2026] [--color #2f6feb] [--company \u2026] [--address \u2026] [--website \u2026] [--settings-file brand.json]"
|
|
4460
4555
|
};
|
|
4461
4556
|
}
|
|
4462
|
-
return withClient3(args, env, async (
|
|
4557
|
+
return withClient3(args, env, async (client3) => {
|
|
4463
4558
|
if (color) {
|
|
4464
|
-
const base = params.settings ?? (await
|
|
4559
|
+
const base = params.settings ?? (await client3.brand.get()).brand.settings ?? {};
|
|
4465
4560
|
const theme = base.theme ?? {};
|
|
4466
4561
|
params.accent_color = color;
|
|
4467
4562
|
params.settings = {
|
|
@@ -4470,25 +4565,25 @@ async function runSetCommand(args, env = process.env) {
|
|
|
4470
4565
|
theme: { ...theme, buttonBackground: color, buttonTextColor: readableText(color) }
|
|
4471
4566
|
};
|
|
4472
4567
|
}
|
|
4473
|
-
return
|
|
4568
|
+
return client3.brand.update(params);
|
|
4474
4569
|
});
|
|
4475
4570
|
}
|
|
4476
4571
|
|
|
4477
4572
|
// src/commands/batches/commands.ts
|
|
4478
|
-
var
|
|
4573
|
+
var VALUE_FLAGS4 = ["--api-key", "--base-url", "--id"];
|
|
4479
4574
|
var MISSING_KEY3 = "Missing API key. Set GROUNDMAIL_API_KEY or pass --api-key.";
|
|
4480
|
-
function
|
|
4575
|
+
function readFlag24(args, flag) {
|
|
4481
4576
|
const index = args.indexOf(flag);
|
|
4482
4577
|
if (index === -1) return void 0;
|
|
4483
4578
|
return args[index + 1];
|
|
4484
4579
|
}
|
|
4485
4580
|
function batchRef(args) {
|
|
4486
|
-
const id =
|
|
4581
|
+
const id = readFlag24(args, "--id");
|
|
4487
4582
|
if (id) return id;
|
|
4488
4583
|
for (let i = 0; i < args.length; i += 1) {
|
|
4489
4584
|
const arg = args[i];
|
|
4490
4585
|
if (arg.startsWith("--")) {
|
|
4491
|
-
if (
|
|
4586
|
+
if (VALUE_FLAGS4.includes(arg)) i += 1;
|
|
4492
4587
|
continue;
|
|
4493
4588
|
}
|
|
4494
4589
|
return arg;
|
|
@@ -4502,21 +4597,21 @@ async function createBatchesClient(apiKey, baseUrl) {
|
|
|
4502
4597
|
async function withBatch(args, env, usage, run) {
|
|
4503
4598
|
const batchId = batchRef(args);
|
|
4504
4599
|
if (!batchId) return { exitCode: 1, error: `Missing batch id (batch_\u2026). Usage: ${usage}` };
|
|
4505
|
-
const apiKey =
|
|
4600
|
+
const apiKey = readFlag24(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
4506
4601
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY3 };
|
|
4507
4602
|
try {
|
|
4508
|
-
const
|
|
4509
|
-
console.log(JSON.stringify(await run(
|
|
4603
|
+
const client3 = await createBatchesClient(apiKey, readFlag24(args, "--base-url"));
|
|
4604
|
+
console.log(JSON.stringify(await run(client3, batchId)));
|
|
4510
4605
|
return { exitCode: 0 };
|
|
4511
4606
|
} catch (error) {
|
|
4512
4607
|
return { exitCode: 1, error: error instanceof Error ? error.message : String(error) };
|
|
4513
4608
|
}
|
|
4514
4609
|
}
|
|
4515
4610
|
async function runGetCommand10(args, env = process.env) {
|
|
4516
|
-
return withBatch(args, env, "groundmail batches get <batch_id>", (
|
|
4611
|
+
return withBatch(args, env, "groundmail batches get <batch_id>", (client3, id) => client3.batches.get(id));
|
|
4517
4612
|
}
|
|
4518
4613
|
async function runCancelCommand2(args, env = process.env) {
|
|
4519
|
-
return withBatch(args, env, "groundmail batches cancel <batch_id>", (
|
|
4614
|
+
return withBatch(args, env, "groundmail batches cancel <batch_id>", (client3, id) => client3.batches.cancel(id));
|
|
4520
4615
|
}
|
|
4521
4616
|
|
|
4522
4617
|
// src/commands/auth.ts
|
|
@@ -4682,7 +4777,7 @@ function sesParams(args, env) {
|
|
|
4682
4777
|
"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
4778
|
].join("\n");
|
|
4684
4779
|
}
|
|
4685
|
-
const region =
|
|
4780
|
+
const region = readFlag25(args, "--region") || env.AWS_REGION || env.AWS_DEFAULT_REGION;
|
|
4686
4781
|
if (!region) return "Set the SES region with --region (for example --region us-east-1) or AWS_REGION. One region per import.";
|
|
4687
4782
|
if (!AWS_REGION.test(region)) return `--region must be an AWS region such as us-east-1, not ${region}`;
|
|
4688
4783
|
return {
|
|
@@ -4693,8 +4788,8 @@ function sesParams(args, env) {
|
|
|
4693
4788
|
aws_region: region
|
|
4694
4789
|
};
|
|
4695
4790
|
}
|
|
4696
|
-
var
|
|
4697
|
-
function
|
|
4791
|
+
var VALUE_FLAGS5 = /* @__PURE__ */ new Set(["--api-key", "--base-url"]);
|
|
4792
|
+
function readFlag25(args, flag) {
|
|
4698
4793
|
const index = args.indexOf(flag);
|
|
4699
4794
|
if (index === -1) return void 0;
|
|
4700
4795
|
return args[index + 1];
|
|
@@ -4768,15 +4863,15 @@ function formatMigrationSummary(m) {
|
|
|
4768
4863
|
if (!m.dry_run && !m.has_more) lines.push("", `Report: groundmail migrate report ${m.id} --csv > import-report.csv`);
|
|
4769
4864
|
return lines.join("\n");
|
|
4770
4865
|
}
|
|
4771
|
-
async function
|
|
4772
|
-
const apiKey =
|
|
4866
|
+
async function client2(args, env) {
|
|
4867
|
+
const apiKey = readFlag25(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
4773
4868
|
if (!apiKey) return null;
|
|
4774
4869
|
const { Groundmail } = await import("groundmail");
|
|
4775
|
-
const baseUrl =
|
|
4870
|
+
const baseUrl = readFlag25(args, "--base-url");
|
|
4776
4871
|
return new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
4777
4872
|
}
|
|
4778
4873
|
async function runStoredCommand(sub, args, env) {
|
|
4779
|
-
const gm = await
|
|
4874
|
+
const gm = await client2(args, env);
|
|
4780
4875
|
if (!gm) return { exitCode: 1, error: "Not signed in. Run `groundmail login`, or set GROUNDMAIL_API_KEY." };
|
|
4781
4876
|
try {
|
|
4782
4877
|
if (sub === "list") {
|
|
@@ -4786,7 +4881,7 @@ async function runStoredCommand(sub, args, env) {
|
|
|
4786
4881
|
if (!data.length) console.error("No imports yet. Previews are not stored.");
|
|
4787
4882
|
return { exitCode: 0 };
|
|
4788
4883
|
}
|
|
4789
|
-
const id = args.find((arg, i) => !arg.startsWith("--") && !
|
|
4884
|
+
const id = args.find((arg, i) => !arg.startsWith("--") && !VALUE_FLAGS5.has(args[i - 1] ?? ""));
|
|
4790
4885
|
if (!id) return { exitCode: 1, error: "Usage: groundmail migrate report <import id> [--csv]" };
|
|
4791
4886
|
if (args.includes("--csv")) {
|
|
4792
4887
|
process.stdout.write(await gm.migrations.reportCsv(id));
|
|
@@ -4809,7 +4904,7 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4809
4904
|
};
|
|
4810
4905
|
}
|
|
4811
4906
|
const id = provider;
|
|
4812
|
-
const apiKey =
|
|
4907
|
+
const apiKey = readFlag25(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
4813
4908
|
if (!apiKey) {
|
|
4814
4909
|
return { exitCode: 1, error: "Not signed in. Run `groundmail login`, or set GROUNDMAIL_API_KEY." };
|
|
4815
4910
|
}
|
|
@@ -4819,7 +4914,7 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4819
4914
|
if (typeof ses === "string") return { exitCode: 1, error: ses };
|
|
4820
4915
|
params = ses;
|
|
4821
4916
|
} else {
|
|
4822
|
-
const providerKey =
|
|
4917
|
+
const providerKey = readFlag25(args, "--key") || env[KEY_ENV[id]];
|
|
4823
4918
|
if (!providerKey) {
|
|
4824
4919
|
const resend = id === "resend" ? " Use a key with Full access (Resend \u2192 API Keys); a Sending access key cannot read your account." : "";
|
|
4825
4920
|
return {
|
|
@@ -4829,15 +4924,15 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4829
4924
|
}
|
|
4830
4925
|
params = { provider: id, api_key: providerKey };
|
|
4831
4926
|
if (id === "postmark") {
|
|
4832
|
-
const accountToken =
|
|
4927
|
+
const accountToken = readFlag25(args, "--account-token") || env.POSTMARK_ACCOUNT_TOKEN;
|
|
4833
4928
|
if (accountToken) params.account_api_key = accountToken;
|
|
4834
4929
|
} else if (id === "sendgrid" || id === "mailgun") {
|
|
4835
|
-
const region =
|
|
4930
|
+
const region = readFlag25(args, "--region");
|
|
4836
4931
|
if (region === "us" || region === "eu") params.region = region;
|
|
4837
4932
|
else if (region) return { exitCode: 1, error: "--region must be us or eu" };
|
|
4838
4933
|
}
|
|
4839
4934
|
}
|
|
4840
|
-
const only =
|
|
4935
|
+
const only = readFlag25(args, "--only");
|
|
4841
4936
|
if (only) {
|
|
4842
4937
|
const list = only.split(",").map((s) => s.trim()).filter(Boolean);
|
|
4843
4938
|
const bad = list.filter((r) => !RESOURCES.includes(r));
|
|
@@ -4849,10 +4944,10 @@ async function runMigrateCommand(provider, args, env = process.env) {
|
|
|
4849
4944
|
if (args.includes("--dry-run")) params.dry_run = true;
|
|
4850
4945
|
try {
|
|
4851
4946
|
const { Groundmail } = await import("groundmail");
|
|
4852
|
-
const baseUrl =
|
|
4853
|
-
const
|
|
4947
|
+
const baseUrl = readFlag25(args, "--base-url");
|
|
4948
|
+
const client3 = new Groundmail(apiKey, baseUrl ? { baseUrl } : void 0);
|
|
4854
4949
|
console.error(`${params.dry_run ? "Previewing" : "Importing"} from ${LABELS[id]}${params.provider === "ses" ? ` (${params.aws_region})` : ""} (Beta)\u2026`);
|
|
4855
|
-
const report = await
|
|
4950
|
+
const report = await client3.migrations.run(params, {
|
|
4856
4951
|
onProgress: (m) => {
|
|
4857
4952
|
if (m.has_more) {
|
|
4858
4953
|
const s = m.suppressions?.totals;
|
|
@@ -4888,8 +4983,8 @@ async function withClient4(args, env, run) {
|
|
|
4888
4983
|
const apiKey = resolveApiKey7(options, env);
|
|
4889
4984
|
if (!apiKey) return { exitCode: 1, error: MISSING_KEY4 };
|
|
4890
4985
|
try {
|
|
4891
|
-
const
|
|
4892
|
-
const output = await run(
|
|
4986
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
4987
|
+
const output = await run(client3);
|
|
4893
4988
|
if (output !== void 0) console.log(JSON.stringify(output));
|
|
4894
4989
|
return { exitCode: 0 };
|
|
4895
4990
|
} catch (error) {
|
|
@@ -4898,7 +4993,7 @@ async function withClient4(args, env, run) {
|
|
|
4898
4993
|
}
|
|
4899
4994
|
async function runSites(action, rest, env) {
|
|
4900
4995
|
if (!action || action === "list" || action.startsWith("--")) {
|
|
4901
|
-
return withClient4(action ? [action, ...rest] : rest, env, (
|
|
4996
|
+
return withClient4(action ? [action, ...rest] : rest, env, (client3) => client3.burrowguard.sites.list());
|
|
4902
4997
|
}
|
|
4903
4998
|
if (action === "create") {
|
|
4904
4999
|
const name = readFlag19(rest, "--name");
|
|
@@ -4909,7 +5004,7 @@ ${USAGE}` };
|
|
|
4909
5004
|
return withClient4(
|
|
4910
5005
|
rest,
|
|
4911
5006
|
env,
|
|
4912
|
-
(
|
|
5007
|
+
(client3) => client3.burrowguard.sites.create({
|
|
4913
5008
|
name,
|
|
4914
5009
|
...hostnames.length > 0 ? { allowed_hostnames: hostnames } : {},
|
|
4915
5010
|
...emailOnly ? { email_checks_only: true } : {},
|
|
@@ -4926,7 +5021,7 @@ ${USAGE}` };
|
|
|
4926
5021
|
const on = rest.includes("--watch-only");
|
|
4927
5022
|
if (on === rest.includes("--no-watch-only")) return { exitCode: 1, error: `Pass --watch-only or --no-watch-only.
|
|
4928
5023
|
${USAGE}` };
|
|
4929
|
-
return withClient4(rest, env, (
|
|
5024
|
+
return withClient4(rest, env, (client3) => client3.burrowguard.sites.update(id, { watch_only: on }));
|
|
4930
5025
|
}
|
|
4931
5026
|
if (action === "delete" || action === "roll-secret") {
|
|
4932
5027
|
const id = rest[0] && !rest[0].startsWith("--") ? rest[0] : void 0;
|
|
@@ -4936,12 +5031,12 @@ ${USAGE}` };
|
|
|
4936
5031
|
const effect = action === "delete" ? "deletes the site and its checks" : "stops the current secret working at once";
|
|
4937
5032
|
return { exitCode: 1, error: `This ${effect}. Pass --yes to go ahead.` };
|
|
4938
5033
|
}
|
|
4939
|
-
return withClient4(rest, env, async (
|
|
5034
|
+
return withClient4(rest, env, async (client3) => {
|
|
4940
5035
|
if (action === "delete") {
|
|
4941
|
-
await
|
|
5036
|
+
await client3.burrowguard.sites.remove(id);
|
|
4942
5037
|
return { deleted: true, id };
|
|
4943
5038
|
}
|
|
4944
|
-
return
|
|
5039
|
+
return client3.burrowguard.sites.rollSecret(id);
|
|
4945
5040
|
});
|
|
4946
5041
|
}
|
|
4947
5042
|
return { exitCode: 1, error: `Unknown command: burrowguard sites ${action}
|
|
@@ -4960,7 +5055,7 @@ function runChecks(args, env) {
|
|
|
4960
5055
|
return withClient4(
|
|
4961
5056
|
args,
|
|
4962
5057
|
env,
|
|
4963
|
-
(
|
|
5058
|
+
(client3) => client3.burrowguard.checks.list({
|
|
4964
5059
|
...readFlag19(args, "--site") ? { site: readFlag19(args, "--site") } : {},
|
|
4965
5060
|
...result ? { result } : {},
|
|
4966
5061
|
...range ? { range } : {},
|
|
@@ -4988,8 +5083,8 @@ async function runValidateCommand(args, env = process.env) {
|
|
|
4988
5083
|
return { exitCode: 1, error: "Missing email. Usage: groundmail validate user@example.com" };
|
|
4989
5084
|
}
|
|
4990
5085
|
try {
|
|
4991
|
-
const
|
|
4992
|
-
const result = await
|
|
5086
|
+
const client3 = await createSuppressionsClient(apiKey, options.baseUrl);
|
|
5087
|
+
const result = await client3.validate(email);
|
|
4993
5088
|
console.log(JSON.stringify(result));
|
|
4994
5089
|
return { exitCode: result.verdict === "invalid" ? 2 : 0 };
|
|
4995
5090
|
} catch (error) {
|
|
@@ -4999,17 +5094,17 @@ async function runValidateCommand(args, env = process.env) {
|
|
|
4999
5094
|
|
|
5000
5095
|
// src/commands/dmarc/dmarc.ts
|
|
5001
5096
|
var DMARC_APPLY_PROVIDERS = ["cloudflare", "vercel", "godaddy", "netlify", "digitalocean", "dnsimple"];
|
|
5002
|
-
function
|
|
5097
|
+
function readFlag26(args, flag) {
|
|
5003
5098
|
const index = args.indexOf(flag);
|
|
5004
5099
|
if (index === -1) return void 0;
|
|
5005
5100
|
return args[index + 1];
|
|
5006
5101
|
}
|
|
5007
|
-
var
|
|
5102
|
+
var VALUE_FLAGS6 = ["--api-key", "--base-url", "--domain", "--apply"];
|
|
5008
5103
|
function readFirstPositional15(args) {
|
|
5009
5104
|
for (let i = 0; i < args.length; i += 1) {
|
|
5010
5105
|
const arg = args[i];
|
|
5011
5106
|
if (arg.startsWith("--")) {
|
|
5012
|
-
if (
|
|
5107
|
+
if (VALUE_FLAGS6.includes(arg)) i += 1;
|
|
5013
5108
|
continue;
|
|
5014
5109
|
}
|
|
5015
5110
|
return arg;
|
|
@@ -5056,27 +5151,27 @@ function formatDmarcStatus(dmarc) {
|
|
|
5056
5151
|
return lines.join("\n");
|
|
5057
5152
|
}
|
|
5058
5153
|
async function runDmarcCommand(subcommand, args, env = process.env) {
|
|
5059
|
-
const apiKey =
|
|
5154
|
+
const apiKey = readFlag26(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
5060
5155
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Run groundmail login, set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
5061
|
-
const domain =
|
|
5156
|
+
const domain = readFlag26(args, "--domain") || readFirstPositional15(args);
|
|
5062
5157
|
if (!subcommand || !["status", "enable", "disable", "digest"].includes(subcommand)) {
|
|
5063
5158
|
return { exitCode: 1, error: "Usage: groundmail dmarc status|enable|disable|digest <domain>" };
|
|
5064
5159
|
}
|
|
5065
5160
|
if (!domain) return { exitCode: 1, error: `Missing domain. Usage: groundmail dmarc ${subcommand} example.com` };
|
|
5066
5161
|
const json = args.includes("--json");
|
|
5067
5162
|
try {
|
|
5068
|
-
const
|
|
5163
|
+
const client3 = await createDmarcClient(apiKey, readFlag26(args, "--base-url"));
|
|
5069
5164
|
if (subcommand === "status") {
|
|
5070
|
-
const result2 = await
|
|
5165
|
+
const result2 = await client3.dmarc.get(domain);
|
|
5071
5166
|
console.log(json ? JSON.stringify(result2) : formatDmarcStatus(result2.dmarc));
|
|
5072
5167
|
return { exitCode: 0 };
|
|
5073
5168
|
}
|
|
5074
5169
|
if (subcommand === "enable") {
|
|
5075
|
-
const apply =
|
|
5170
|
+
const apply = readFlag26(args, "--apply");
|
|
5076
5171
|
if (apply && !DMARC_APPLY_PROVIDERS.includes(apply)) {
|
|
5077
5172
|
return { exitCode: 1, error: `--apply must be one of: ${DMARC_APPLY_PROVIDERS.join(", ")}` };
|
|
5078
5173
|
}
|
|
5079
|
-
const result2 = await
|
|
5174
|
+
const result2 = await client3.dmarc.enable(domain, apply ? { apply } : {});
|
|
5080
5175
|
if (json) console.log(JSON.stringify(result2));
|
|
5081
5176
|
else {
|
|
5082
5177
|
console.log(formatDmarcStatus(result2.dmarc));
|
|
@@ -5087,13 +5182,13 @@ Updated the DMARC record with ${result2.applied.provider}.`);
|
|
|
5087
5182
|
return { exitCode: 0 };
|
|
5088
5183
|
}
|
|
5089
5184
|
if (subcommand === "disable") {
|
|
5090
|
-
const result2 = await
|
|
5185
|
+
const result2 = await client3.dmarc.disable(domain);
|
|
5091
5186
|
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
5187
|
return { exitCode: 0 };
|
|
5093
5188
|
}
|
|
5094
5189
|
const value = args.includes("--off") ? false : args.includes("--on") ? true : void 0;
|
|
5095
5190
|
if (value === void 0) return { exitCode: 1, error: "Usage: groundmail dmarc digest example.com --on|--off" };
|
|
5096
|
-
const result = await
|
|
5191
|
+
const result = await client3.dmarc.update(domain, { digest_enabled: value });
|
|
5097
5192
|
console.log(json ? JSON.stringify(result) : `Weekly DMARC digest for ${domain} is ${value ? "on" : "off"}.`);
|
|
5098
5193
|
return { exitCode: 0 };
|
|
5099
5194
|
} catch (error) {
|
|
@@ -5102,7 +5197,7 @@ Updated the DMARC record with ${result2.applied.provider}.`);
|
|
|
5102
5197
|
}
|
|
5103
5198
|
|
|
5104
5199
|
// src/commands/test-inbox/test-inbox.ts
|
|
5105
|
-
function
|
|
5200
|
+
function readFlag27(args, flag) {
|
|
5106
5201
|
const index = args.indexOf(flag);
|
|
5107
5202
|
if (index === -1) return void 0;
|
|
5108
5203
|
return args[index + 1];
|
|
@@ -5130,20 +5225,20 @@ function formatTestEmail(email) {
|
|
|
5130
5225
|
var USAGE2 = "Usage: groundmail test-inbox address [--prefix signup] | wait --to <address> [--timeout 30] [--since <iso>] [--json] | list [--to <address>] [--json]";
|
|
5131
5226
|
async function runTestInboxCommand(subcommand, args, env = process.env) {
|
|
5132
5227
|
if (!subcommand || !["address", "wait", "list"].includes(subcommand)) return { exitCode: 1, error: USAGE2 };
|
|
5133
|
-
const apiKey =
|
|
5228
|
+
const apiKey = readFlag27(args, "--api-key") || env.GROUNDMAIL_API_KEY;
|
|
5134
5229
|
if (!apiKey) return { exitCode: 1, error: "Missing API key. Run groundmail login, set GROUNDMAIL_API_KEY or pass --api-key." };
|
|
5135
5230
|
const json = args.includes("--json");
|
|
5136
5231
|
try {
|
|
5137
|
-
const
|
|
5232
|
+
const client3 = await createTestInboxClient(apiKey, readFlag27(args, "--base-url"));
|
|
5138
5233
|
if (subcommand === "address") {
|
|
5139
|
-
console.log(await
|
|
5234
|
+
console.log(await client3.testInbox.address({ prefix: readFlag27(args, "--prefix") }));
|
|
5140
5235
|
return { exitCode: 0 };
|
|
5141
5236
|
}
|
|
5142
5237
|
if (subcommand === "list") {
|
|
5143
|
-
const result = await
|
|
5144
|
-
to:
|
|
5145
|
-
since:
|
|
5146
|
-
limit:
|
|
5238
|
+
const result = await client3.testInbox.list({
|
|
5239
|
+
to: readFlag27(args, "--to"),
|
|
5240
|
+
since: readFlag27(args, "--since"),
|
|
5241
|
+
limit: readFlag27(args, "--limit") ? Number(readFlag27(args, "--limit")) : void 0
|
|
5147
5242
|
});
|
|
5148
5243
|
if (json) console.log(JSON.stringify(result));
|
|
5149
5244
|
else if (!result.emails.length) console.log("No test emails yet.");
|
|
@@ -5154,13 +5249,13 @@ async function runTestInboxCommand(subcommand, args, env = process.env) {
|
|
|
5154
5249
|
}
|
|
5155
5250
|
return { exitCode: 0 };
|
|
5156
5251
|
}
|
|
5157
|
-
const to =
|
|
5252
|
+
const to = readFlag27(args, "--to");
|
|
5158
5253
|
if (!to) return { exitCode: 1, error: "Missing --to. Usage: groundmail test-inbox wait --to signup-k3m9x2pq@acme.test.groundmail.dev" };
|
|
5159
|
-
const timeoutRaw =
|
|
5254
|
+
const timeoutRaw = readFlag27(args, "--timeout");
|
|
5160
5255
|
const seconds = timeoutRaw === void 0 ? 30 : Number(timeoutRaw);
|
|
5161
5256
|
if (!Number.isFinite(seconds) || seconds < 0) return { exitCode: 1, error: "--timeout must be a number of seconds" };
|
|
5162
5257
|
try {
|
|
5163
|
-
const email = await
|
|
5258
|
+
const email = await client3.testInbox.waitFor({ to, timeout: seconds * 1e3, since: readFlag27(args, "--since") });
|
|
5164
5259
|
console.log(json ? JSON.stringify({ email }) : formatTestEmail(email));
|
|
5165
5260
|
return { exitCode: 0 };
|
|
5166
5261
|
} catch (error) {
|
|
@@ -5176,7 +5271,7 @@ async function runTestInboxCommand(subcommand, args, env = process.env) {
|
|
|
5176
5271
|
}
|
|
5177
5272
|
|
|
5178
5273
|
// src/commands/mailboxes/mailboxes.ts
|
|
5179
|
-
var
|
|
5274
|
+
var VALUE_FLAGS7 = [
|
|
5180
5275
|
"--send-as",
|
|
5181
5276
|
"--allowed-senders",
|
|
5182
5277
|
"--blocked-senders",
|
|
@@ -5375,7 +5470,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5375
5470
|
if (!subcommand || !["create", "owner", "verify", "list", "get", "update", "delete", "forward", "threads", "read", "wait", "send", "reply"].includes(subcommand)) {
|
|
5376
5471
|
return { exitCode: 1, error: USAGE3 };
|
|
5377
5472
|
}
|
|
5378
|
-
const parsed = parseArgs(argv, { values:
|
|
5473
|
+
const parsed = parseArgs(argv, { values: VALUE_FLAGS7, booleans: BOOLEAN_FLAGS });
|
|
5379
5474
|
if (!parsed.ok) return { exitCode: 1, error: parsed.error };
|
|
5380
5475
|
const { args } = parsed;
|
|
5381
5476
|
if (subcommand === "create" && args.booleans["--instant"] === true) return createInstant(args);
|
|
@@ -5391,30 +5486,30 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5391
5486
|
}
|
|
5392
5487
|
const ref = mailbox;
|
|
5393
5488
|
try {
|
|
5394
|
-
const
|
|
5489
|
+
const client3 = await createMailboxesClient(apiKey, v["--base-url"]);
|
|
5395
5490
|
if (subcommand === "owner") {
|
|
5396
5491
|
if (!v["--owner-email"]) return { exitCode: 1, error: "Missing --owner-email." };
|
|
5397
|
-
const owner = await
|
|
5492
|
+
const owner = await client3.mailboxes.setOwner(ref, v["--owner-email"]);
|
|
5398
5493
|
print(owner, () => `Code sent to ${owner.owner_email}. Ask them for it, then run: groundmail mailboxes verify ${ref} --code <code>`);
|
|
5399
5494
|
return { exitCode: 0 };
|
|
5400
5495
|
}
|
|
5401
5496
|
if (subcommand === "verify") {
|
|
5402
5497
|
if (!v["--code"]) return { exitCode: 1, error: "Missing --code." };
|
|
5403
|
-
const verified = await
|
|
5498
|
+
const verified = await client3.mailboxes.verifyOwner(ref, v["--code"]);
|
|
5404
5499
|
print(verified, () => "Verified. This mailbox now has a normal account, with the same key.");
|
|
5405
5500
|
return { exitCode: 0 };
|
|
5406
5501
|
}
|
|
5407
5502
|
if (subcommand === "create") {
|
|
5408
5503
|
const params = createParams(args);
|
|
5409
5504
|
if ("error" in params) return { exitCode: 1, error: params.error };
|
|
5410
|
-
const created = await
|
|
5505
|
+
const created = await client3.mailboxes.create(params);
|
|
5411
5506
|
print({ mailbox: created }, () => formatMailbox(created));
|
|
5412
5507
|
return { exitCode: 0 };
|
|
5413
5508
|
}
|
|
5414
5509
|
if (subcommand === "list") {
|
|
5415
5510
|
const page = paging(args);
|
|
5416
5511
|
if ("error" in page) return { exitCode: 1, error: page.error };
|
|
5417
|
-
const result = await
|
|
5512
|
+
const result = await client3.mailboxes.list({ ...page, ...v["--tenant"] ? { tenant: v["--tenant"] } : {} });
|
|
5418
5513
|
print(
|
|
5419
5514
|
result,
|
|
5420
5515
|
() => result.data.length ? result.data.map((item) => `${item.id} ${item.address} ${item.status}`).join("\n") : "No mailboxes yet."
|
|
@@ -5422,7 +5517,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5422
5517
|
return { exitCode: 0 };
|
|
5423
5518
|
}
|
|
5424
5519
|
if (subcommand === "get") {
|
|
5425
|
-
const found = await
|
|
5520
|
+
const found = await client3.mailboxes.get(ref);
|
|
5426
5521
|
print({ mailbox: found }, () => formatMailbox(found));
|
|
5427
5522
|
return { exitCode: 0 };
|
|
5428
5523
|
}
|
|
@@ -5433,7 +5528,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5433
5528
|
if (sendAs === void 0 && !allowed && !blocked) {
|
|
5434
5529
|
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
5530
|
}
|
|
5436
|
-
const updated = await
|
|
5531
|
+
const updated = await client3.mailboxes.update(ref, {
|
|
5437
5532
|
...sendAs !== void 0 ? { send_as: sendAs === "none" ? null : sendAs } : {},
|
|
5438
5533
|
...allowed ? { allowed_senders: allowed } : {},
|
|
5439
5534
|
...blocked ? { blocked_senders: blocked } : {}
|
|
@@ -5445,7 +5540,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5445
5540
|
if (!on("--yes")) {
|
|
5446
5541
|
return { exitCode: 1, error: "This deletes the mailbox and all its mail. Add --yes to confirm." };
|
|
5447
5542
|
}
|
|
5448
|
-
const result = await
|
|
5543
|
+
const result = await client3.mailboxes.delete(ref);
|
|
5449
5544
|
print(result, () => `Deleted ${result.id}`);
|
|
5450
5545
|
return { exitCode: 0 };
|
|
5451
5546
|
}
|
|
@@ -5458,14 +5553,14 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5458
5553
|
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
5554
|
};
|
|
5460
5555
|
}
|
|
5461
|
-
const moved = await
|
|
5556
|
+
const moved = await client3.mailboxes.forward(ref, { to });
|
|
5462
5557
|
print({ mailbox: moved }, () => formatMailbox(moved));
|
|
5463
5558
|
return { exitCode: 0 };
|
|
5464
5559
|
}
|
|
5465
5560
|
if (subcommand === "threads") {
|
|
5466
5561
|
const page = paging(args);
|
|
5467
5562
|
if ("error" in page) return { exitCode: 1, error: page.error };
|
|
5468
|
-
const result = await
|
|
5563
|
+
const result = await client3.mailboxes.threads.list(ref, {
|
|
5469
5564
|
...page,
|
|
5470
5565
|
...v["--label"] ? { label: v["--label"] } : {},
|
|
5471
5566
|
...v["--participant"] ? { participant: v["--participant"] } : {},
|
|
@@ -5479,18 +5574,18 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5479
5574
|
}
|
|
5480
5575
|
if (subcommand === "read") {
|
|
5481
5576
|
if (target?.startsWith("thd_")) {
|
|
5482
|
-
const thread = await
|
|
5577
|
+
const thread = await client3.mailboxes.threads.get(ref, target, on("--include-held") ? { include_held: true } : {});
|
|
5483
5578
|
print({ thread }, () => formatThread(thread));
|
|
5484
5579
|
return { exitCode: 0 };
|
|
5485
5580
|
}
|
|
5486
5581
|
if (target) {
|
|
5487
|
-
const message = await
|
|
5582
|
+
const message = await client3.mailboxes.messages.get(ref, target);
|
|
5488
5583
|
print({ message }, () => formatMessage(message));
|
|
5489
5584
|
return { exitCode: 0 };
|
|
5490
5585
|
}
|
|
5491
5586
|
const page = paging(args);
|
|
5492
5587
|
if ("error" in page) return { exitCode: 1, error: page.error };
|
|
5493
|
-
const result = await
|
|
5588
|
+
const result = await client3.mailboxes.messages.list(ref, {
|
|
5494
5589
|
...page,
|
|
5495
5590
|
...v["--search"] ? { q: v["--search"] } : {},
|
|
5496
5591
|
...v["--from"] ? { from: v["--from"] } : {},
|
|
@@ -5510,7 +5605,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5510
5605
|
const body = bodyFlags(args);
|
|
5511
5606
|
if (!body) return { exitCode: 1, error: "Pass --text or --html." };
|
|
5512
5607
|
const cc = addresses(v["--cc"]);
|
|
5513
|
-
const result = await
|
|
5608
|
+
const result = await client3.mailboxes.messages.send(ref, { to, ...cc.length ? { cc } : {}, subject: v["--subject"], ...body });
|
|
5514
5609
|
print(result, () => formatSent(result));
|
|
5515
5610
|
return { exitCode: 0 };
|
|
5516
5611
|
}
|
|
@@ -5518,7 +5613,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5518
5613
|
if (!target) return { exitCode: 1, error: "Missing message id. Usage: groundmail mailboxes reply <mailbox> mbm_\u2026 --text \u2026" };
|
|
5519
5614
|
const body = bodyFlags(args);
|
|
5520
5615
|
if (!body) return { exitCode: 1, error: "Pass --text or --html." };
|
|
5521
|
-
const result = await
|
|
5616
|
+
const result = await client3.mailboxes.messages.reply(ref, target, { ...body, ...on("--reply-all") ? { reply_all: true } : {} });
|
|
5522
5617
|
print(result, () => formatSent(result));
|
|
5523
5618
|
return { exitCode: 0 };
|
|
5524
5619
|
}
|
|
@@ -5526,7 +5621,7 @@ async function runMailboxesCommand(subcommand, argv, env = process.env) {
|
|
|
5526
5621
|
const seconds = timeoutRaw === void 0 ? 30 : Number(timeoutRaw);
|
|
5527
5622
|
if (!Number.isFinite(seconds) || seconds < 0) return { exitCode: 1, error: "--timeout must be a number of seconds" };
|
|
5528
5623
|
try {
|
|
5529
|
-
const message = await
|
|
5624
|
+
const message = await client3.mailboxes.wait(ref, {
|
|
5530
5625
|
timeout: seconds * 1e3,
|
|
5531
5626
|
...v["--from"] ? { from: v["--from"] } : {},
|
|
5532
5627
|
...v["--thread"] ? { thread: v["--thread"] } : {},
|
|
@@ -6030,6 +6125,11 @@ async function main() {
|
|
|
6030
6125
|
process.exit(result.exitCode);
|
|
6031
6126
|
}
|
|
6032
6127
|
}
|
|
6128
|
+
if (command === "routes") {
|
|
6129
|
+
const result = await runRoutesCommand(subcommand, rest);
|
|
6130
|
+
if (result.error) console.error(result.error);
|
|
6131
|
+
process.exit(result.exitCode);
|
|
6132
|
+
}
|
|
6033
6133
|
if (command === "templates") {
|
|
6034
6134
|
if (subcommand === "list") {
|
|
6035
6135
|
const result = await runListCommand7(rest);
|