gigadrive 2.13.0 → 2.14.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/index.mjs CHANGED
@@ -9,7 +9,7 @@ import { Effect as Effect29, Layer, LogLevel, Logger } from "effect";
9
9
  // package.json
10
10
  var package_default = {
11
11
  name: "gigadrive",
12
- version: "2.13.0",
12
+ version: "2.14.0",
13
13
  repository: {
14
14
  type: "git",
15
15
  url: "https://github.com/Gigadrive/sdk.git",
@@ -3089,6 +3089,26 @@ var formatImageTable = (images) => formatTable([
3089
3089
  ["NAME", "STATUS", "SOURCE", "ID"],
3090
3090
  ...images.map((image) => [image.name, image.status, imageSource(image), image.id])
3091
3091
  ]);
3092
+ var formatWebhookTable = (webhooks) => formatTable([
3093
+ ["URL", "EVENTS", "STATUS", "ID"],
3094
+ ...webhooks.map((webhook) => [
3095
+ webhook.url,
3096
+ webhook.events.join(","),
3097
+ webhook.enabled ? "enabled" : "disabled",
3098
+ webhook.id
3099
+ ])
3100
+ ]);
3101
+ var formatDeliveryTable = (deliveries) => formatTable([
3102
+ ["CREATED", "EVENT", "STATUS", "ATTEMPTS", "RESPONSE", "MICROVM"],
3103
+ ...deliveries.map((delivery) => [
3104
+ delivery.createdAt,
3105
+ delivery.eventType,
3106
+ delivery.status,
3107
+ String(delivery.attempts),
3108
+ delivery.lastStatusCode === null ? delivery.lastError ?? "-" : String(delivery.lastStatusCode),
3109
+ delivery.microvmId
3110
+ ])
3111
+ ]);
3092
3112
  var formatBytes = (bytes) => {
3093
3113
  if (bytes < 1024) return `${bytes} B`;
3094
3114
  const units = ["KiB", "MiB", "GiB", "TiB"];
@@ -3935,6 +3955,121 @@ var imagesCommand = Command12.make("images", {}, () => Effect22.void).pipe(
3935
3955
  Command12.withDescription("Built-in and custom microVM images"),
3936
3956
  Command12.withSubcommands([imagesListCommand, imagesCreateCommand, imagesRemoveCommand])
3937
3957
  );
3958
+ var WEBHOOK_EVENTS = [
3959
+ "microvm.created",
3960
+ "microvm.running",
3961
+ "microvm.paused",
3962
+ "microvm.stopped",
3963
+ "microvm.failed"
3964
+ ];
3965
+ var webhookIdArg = Args5.text({ name: "webhook-id" }).pipe(Args5.withDescription("The webhook ID"));
3966
+ var webhooksListCommand = Command12.make(
3967
+ "ls",
3968
+ { app: appOption6, json: jsonOption2 },
3969
+ ({ app, json }) => Effect22.gen(function* () {
3970
+ const apiClient = yield* ApiClientService;
3971
+ const applicationId = yield* resolveApplicationId(app);
3972
+ const webhooks = yield* apiClient.request((client) => client.microvms.webhooks.list({ applicationId }));
3973
+ if (json) return yield* Console12.log(JSON.stringify(webhooks, null, 2));
3974
+ if (webhooks.length === 0)
3975
+ return yield* Console12.log('No webhooks yet. Add one with "gigadrive microvms webhooks add".');
3976
+ for (const line of formatWebhookTable(webhooks)) yield* Console12.log(line);
3977
+ }).pipe(reportErrors2("list webhooks"))
3978
+ ).pipe(Command12.withDescription("List the application's microVM webhooks"));
3979
+ var addWebhook = (flags) => Effect22.gen(function* () {
3980
+ const apiClient = yield* ApiClientService;
3981
+ const unknown = flags.events.find((event) => !WEBHOOK_EVENTS.includes(event));
3982
+ if (unknown !== void 0) {
3983
+ return yield* new InvalidMicroVmOptionsError({
3984
+ message: `${unknown} is not a microVM event. Use ${WEBHOOK_EVENTS.join(", ")}.`
3985
+ });
3986
+ }
3987
+ const events = flags.events.length > 0 ? [...new Set(flags.events)] : WEBHOOK_EVENTS;
3988
+ const applicationId = yield* resolveApplicationId(flags.app);
3989
+ const webhook = yield* apiClient.request(
3990
+ (client) => client.microvms.webhooks.create({
3991
+ url: flags.url,
3992
+ events,
3993
+ ...Option14.isSome(flags.description) ? { description: flags.description.value } : {},
3994
+ ...applicationId ? { applicationId } : {}
3995
+ })
3996
+ );
3997
+ if (flags.json) {
3998
+ yield* Console12.log(JSON.stringify(webhook, null, 2));
3999
+ } else {
4000
+ yield* Console12.log(`Added webhook ${webhook.id} for ${webhook.events.join(", ")}.`);
4001
+ yield* Console12.log(`Signing secret (shown only now): ${webhook.secret}`);
4002
+ }
4003
+ return webhook;
4004
+ });
4005
+ var webhooksAddCommand = Command12.make(
4006
+ "add",
4007
+ {
4008
+ url: Args5.text({ name: "url" }).pipe(Args5.withDescription("HTTPS URL on a public host")),
4009
+ events: Options7.text("event").pipe(
4010
+ Options7.withDescription(`Event to send (repeatable; default: all of ${WEBHOOK_EVENTS.join(", ")})`),
4011
+ Options7.repeated
4012
+ ),
4013
+ description: Options7.text("description").pipe(Options7.withDescription("A note for yourself"), Options7.optional),
4014
+ app: appOption6,
4015
+ json: jsonOption2
4016
+ },
4017
+ (flags) => addWebhook(flags).pipe(Effect22.asVoid, reportErrors2("add the webhook"))
4018
+ ).pipe(Command12.withDescription("Add an endpoint for microVM lifecycle events and print its signing secret"));
4019
+ var webhooksEnableCommand = (enabled) => Command12.make(
4020
+ enabled ? "enable" : "disable",
4021
+ { webhookId: webhookIdArg },
4022
+ ({ webhookId }) => Effect22.gen(function* () {
4023
+ const apiClient = yield* ApiClientService;
4024
+ const webhook = yield* apiClient.request((client) => client.microvms.webhooks.update(webhookId, { enabled }));
4025
+ yield* Console12.log(`${webhook.url} is ${webhook.enabled ? "enabled" : "disabled"}.`);
4026
+ }).pipe(reportErrors2(enabled ? "enable the webhook" : "disable the webhook"))
4027
+ ).pipe(
4028
+ Command12.withDescription(
4029
+ enabled ? "Send events to a webhook again" : "Stop sending events to a webhook; waiting retries are held"
4030
+ )
4031
+ );
4032
+ var webhooksSecretCommand = Command12.make(
4033
+ "rotate-secret",
4034
+ { webhookId: webhookIdArg },
4035
+ ({ webhookId }) => Effect22.gen(function* () {
4036
+ const apiClient = yield* ApiClientService;
4037
+ const webhook = yield* apiClient.request((client) => client.microvms.webhooks.rotateSecret(webhookId));
4038
+ yield* Console12.log(`New signing secret (shown only now): ${webhook.secret}`);
4039
+ }).pipe(reportErrors2("replace the signing secret"))
4040
+ ).pipe(Command12.withDescription("Replace the signing secret; the old one stops signing at once"));
4041
+ var webhooksDeliveriesCommand = Command12.make(
4042
+ "deliveries",
4043
+ { webhookId: webhookIdArg, json: jsonOption2 },
4044
+ ({ webhookId, json }) => Effect22.gen(function* () {
4045
+ const apiClient = yield* ApiClientService;
4046
+ const deliveries = yield* apiClient.request((client) => client.microvms.webhooks.listDeliveries(webhookId));
4047
+ if (json) return yield* Console12.log(JSON.stringify(deliveries, null, 2));
4048
+ if (deliveries.length === 0) return yield* Console12.log("Nothing has been sent yet.");
4049
+ for (const line of formatDeliveryTable(deliveries)) yield* Console12.log(line);
4050
+ }).pipe(reportErrors2("list the deliveries"))
4051
+ ).pipe(Command12.withDescription("Show a webhook's 50 most recent deliveries"));
4052
+ var webhooksRemoveCommand = Command12.make(
4053
+ "rm",
4054
+ { webhookId: webhookIdArg },
4055
+ ({ webhookId }) => Effect22.gen(function* () {
4056
+ const apiClient = yield* ApiClientService;
4057
+ yield* apiClient.request((client) => client.microvms.webhooks.delete(webhookId));
4058
+ yield* Console12.log(`Deleted webhook ${webhookId}.`);
4059
+ }).pipe(reportErrors2("delete the webhook"))
4060
+ ).pipe(Command12.withDescription("Delete a webhook"));
4061
+ var webhooksCommand = Command12.make("webhooks", {}, () => Effect22.void).pipe(
4062
+ Command12.withDescription("Signed HTTPS requests when a microVM is created, starts, pauses, stops or fails"),
4063
+ Command12.withSubcommands([
4064
+ webhooksListCommand,
4065
+ webhooksAddCommand,
4066
+ webhooksEnableCommand(true),
4067
+ webhooksEnableCommand(false),
4068
+ webhooksSecretCommand,
4069
+ webhooksDeliveriesCommand,
4070
+ webhooksRemoveCommand
4071
+ ])
4072
+ );
3938
4073
  var SUBCOMMANDS = [
3939
4074
  createCommand,
3940
4075
  listCommand2,
@@ -3947,7 +4082,8 @@ var SUBCOMMANDS = [
3947
4082
  removeCommand2,
3948
4083
  extendCommand,
3949
4084
  networkCommand,
3950
- imagesCommand
4085
+ imagesCommand,
4086
+ webhooksCommand
3951
4087
  ];
3952
4088
  var microvmsCommand = Command12.make("microvms", {}, () => Effect22.void).pipe(
3953
4089
  Command12.withDescription("Isolated Linux machines for running code: create, exec, shell, cp, stop"),