sandbox 3.0.0-beta.16 → 3.0.0-beta.20

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.
@@ -15,7 +15,7 @@ import childProcess, { execFile } from "node:child_process";
15
15
  import fs, { constants, writeFile } from "node:fs/promises";
16
16
  import fs$1, { createWriteStream } from "node:fs";
17
17
  import * as Auth from "@vercel/sandbox/dist/auth/index.js";
18
- import { OAuth, getAuth, pollForToken, updateAuthConfig } from "@vercel/sandbox/dist/auth/index.js";
18
+ import { OAuth, getAuth, inferScope, pollForToken, updateAuthConfig } from "@vercel/sandbox/dist/auth/index.js";
19
19
  import { EOL } from "os";
20
20
  import { z } from "zod/v4";
21
21
  import { z as z$1 } from "zod";
@@ -3156,7 +3156,7 @@ var import_cjs$25 = /* @__PURE__ */ __toESM(require_cjs());
3156
3156
  const timeout = import_cjs$25.option({
3157
3157
  long: "timeout",
3158
3158
  type: Duration,
3159
- description: "The maximum duration a sandbox can run for. Example: 5m, 1h",
3159
+ description: "The maximum duration a sandbox can run for. Example: 5m, 30m",
3160
3160
  defaultValue: () => "5 minutes",
3161
3161
  defaultValueIsSerializable: true
3162
3162
  });
@@ -3242,7 +3242,7 @@ const formatDistanceLocale = {
3242
3242
  other: "almost {{count}} years"
3243
3243
  }
3244
3244
  };
3245
- const formatDistance$1 = (token$1, count, options) => {
3245
+ const formatDistance = (token$1, count, options) => {
3246
3246
  let result;
3247
3247
  const tokenValue = formatDistanceLocale[token$1];
3248
3248
  if (typeof tokenValue === "string") result = tokenValue;
@@ -3764,7 +3764,7 @@ const match = {
3764
3764
  */
3765
3765
  const enUS = {
3766
3766
  code: "en-US",
3767
- formatDistance: formatDistance$1,
3767
+ formatDistance,
3768
3768
  formatLong,
3769
3769
  formatRelative,
3770
3770
  localize,
@@ -3782,6 +3782,15 @@ function getDefaultOptions() {
3782
3782
  return defaultOptions;
3783
3783
  }
3784
3784
 
3785
+ //#endregion
3786
+ //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/_lib/getRoundingMethod.js
3787
+ function getRoundingMethod(method) {
3788
+ return (number) => {
3789
+ const result = (method ? Math[method] : Math.trunc)(number);
3790
+ return result === 0 ? 0 : result;
3791
+ };
3792
+ }
3793
+
3785
3794
  //#endregion
3786
3795
  //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/constants.js
3787
3796
  /**
@@ -3815,6 +3824,18 @@ const daysInYear = 365.2425;
3815
3824
  const maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
3816
3825
  /**
3817
3826
  * @constant
3827
+ * @name millisecondsInMinute
3828
+ * @summary Milliseconds in 1 minute
3829
+ */
3830
+ const millisecondsInMinute = 6e4;
3831
+ /**
3832
+ * @constant
3833
+ * @name minutesInYear
3834
+ * @summary Minutes in 1 year.
3835
+ */
3836
+ const minutesInYear = 525600;
3837
+ /**
3838
+ * @constant
3818
3839
  * @name minutesInMonth
3819
3840
  * @summary Minutes in 1 month.
3820
3841
  */
@@ -4031,277 +4052,31 @@ function compareAsc(dateLeft, dateRight) {
4031
4052
  }
4032
4053
 
4033
4054
  //#endregion
4034
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/differenceInCalendarMonths.js
4035
- /**
4036
- * The {@link differenceInCalendarMonths} function options.
4037
- */
4038
- /**
4039
- * @name differenceInCalendarMonths
4040
- * @category Month Helpers
4041
- * @summary Get the number of calendar months between the given dates.
4042
- *
4043
- * @description
4044
- * Get the number of calendar months between the given dates.
4045
- *
4046
- * @param laterDate - The later date
4047
- * @param earlierDate - The earlier date
4048
- * @param options - An object with options
4049
- *
4050
- * @returns The number of calendar months
4051
- *
4052
- * @example
4053
- * // How many calendar months are between 31 January 2014 and 1 September 2014?
4054
- * const result = differenceInCalendarMonths(
4055
- * new Date(2014, 8, 1),
4056
- * new Date(2014, 0, 31)
4057
- * )
4058
- * //=> 8
4059
- */
4060
- function differenceInCalendarMonths(laterDate, earlierDate, options) {
4061
- const [laterDate_, earlierDate_] = normalizeDates(options?.in, laterDate, earlierDate);
4062
- const yearsDiff = laterDate_.getFullYear() - earlierDate_.getFullYear();
4063
- const monthsDiff = laterDate_.getMonth() - earlierDate_.getMonth();
4064
- return yearsDiff * 12 + monthsDiff;
4065
- }
4066
-
4067
- //#endregion
4068
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfDay.js
4069
- /**
4070
- * The {@link endOfDay} function options.
4071
- */
4072
- /**
4073
- * @name endOfDay
4074
- * @category Day Helpers
4075
- * @summary Return the end of a day for the given date.
4076
- *
4077
- * @description
4078
- * Return the end of a day for the given date.
4079
- * The result will be in the local timezone.
4080
- *
4081
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
4082
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
4083
- *
4084
- * @param date - The original date
4085
- * @param options - An object with options
4086
- *
4087
- * @returns The end of a day
4088
- *
4089
- * @example
4090
- * // The end of a day for 2 September 2014 11:55:00:
4091
- * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
4092
- * //=> Tue Sep 02 2014 23:59:59.999
4093
- */
4094
- function endOfDay(date, options) {
4095
- const _date = toDate(date, options?.in);
4096
- _date.setHours(23, 59, 59, 999);
4097
- return _date;
4098
- }
4099
-
4100
- //#endregion
4101
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/endOfMonth.js
4102
- /**
4103
- * The {@link endOfMonth} function options.
4104
- */
4105
- /**
4106
- * @name endOfMonth
4107
- * @category Month Helpers
4108
- * @summary Return the end of a month for the given date.
4109
- *
4110
- * @description
4111
- * Return the end of a month for the given date.
4112
- * The result will be in the local timezone.
4113
- *
4114
- * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
4115
- * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
4116
- *
4117
- * @param date - The original date
4118
- * @param options - An object with options
4119
- *
4120
- * @returns The end of a month
4121
- *
4122
- * @example
4123
- * // The end of a month for 2 September 2014 11:55:00:
4124
- * const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0))
4125
- * //=> Tue Sep 30 2014 23:59:59.999
4126
- */
4127
- function endOfMonth(date, options) {
4128
- const _date = toDate(date, options?.in);
4129
- const month = _date.getMonth();
4130
- _date.setFullYear(_date.getFullYear(), month + 1, 0);
4131
- _date.setHours(23, 59, 59, 999);
4132
- return _date;
4133
- }
4134
-
4135
- //#endregion
4136
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/isLastDayOfMonth.js
4137
- /**
4138
- * @name isLastDayOfMonth
4139
- * @category Month Helpers
4140
- * @summary Is the given date the last day of a month?
4141
- *
4142
- * @description
4143
- * Is the given date the last day of a month?
4144
- *
4145
- * @param date - The date to check
4146
- * @param options - An object with options
4147
- *
4148
- * @returns The date is the last day of a month
4149
- *
4150
- * @example
4151
- * // Is 28 February 2014 the last day of a month?
4152
- * const result = isLastDayOfMonth(new Date(2014, 1, 28))
4153
- * //=> true
4154
- */
4155
- function isLastDayOfMonth(date, options) {
4156
- const _date = toDate(date, options?.in);
4157
- return +endOfDay(_date, options) === +endOfMonth(_date, options);
4158
- }
4159
-
4160
- //#endregion
4161
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/differenceInMonths.js
4162
- /**
4163
- * The {@link differenceInMonths} function options.
4164
- */
4165
- /**
4166
- * @name differenceInMonths
4167
- * @category Month Helpers
4168
- * @summary Get the number of full months between the given dates.
4169
- *
4170
- * @param laterDate - The later date
4171
- * @param earlierDate - The earlier date
4172
- * @param options - An object with options
4173
- *
4174
- * @returns The number of full months
4175
- *
4176
- * @example
4177
- * // How many full months are between 31 January 2014 and 1 September 2014?
4178
- * const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
4179
- * //=> 7
4180
- */
4181
- function differenceInMonths(laterDate, earlierDate, options) {
4182
- const [laterDate_, workingLaterDate, earlierDate_] = normalizeDates(options?.in, laterDate, laterDate, earlierDate);
4183
- const sign = compareAsc(workingLaterDate, earlierDate_);
4184
- const difference = Math.abs(differenceInCalendarMonths(workingLaterDate, earlierDate_));
4185
- if (difference < 1) return 0;
4186
- if (workingLaterDate.getMonth() === 1 && workingLaterDate.getDate() > 27) workingLaterDate.setDate(30);
4187
- workingLaterDate.setMonth(workingLaterDate.getMonth() - sign * difference);
4188
- let isLastMonthNotFull = compareAsc(workingLaterDate, earlierDate_) === -sign;
4189
- if (isLastDayOfMonth(laterDate_) && difference === 1 && compareAsc(laterDate_, earlierDate_) === 1) isLastMonthNotFull = false;
4190
- const result = sign * (difference - +isLastMonthNotFull);
4191
- return result === 0 ? 0 : result;
4192
- }
4193
-
4194
- //#endregion
4195
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/_lib/getRoundingMethod.js
4196
- function getRoundingMethod(method) {
4197
- return (number) => {
4198
- const result = (method ? Math[method] : Math.trunc)(number);
4199
- return result === 0 ? 0 : result;
4200
- };
4201
- }
4202
-
4203
- //#endregion
4204
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/differenceInMilliseconds.js
4205
- /**
4206
- * @name differenceInMilliseconds
4207
- * @category Millisecond Helpers
4208
- * @summary Get the number of milliseconds between the given dates.
4209
- *
4210
- * @description
4211
- * Get the number of milliseconds between the given dates.
4212
- *
4213
- * @param laterDate - The later date
4214
- * @param earlierDate - The earlier date
4215
- *
4216
- * @returns The number of milliseconds
4217
- *
4218
- * @example
4219
- * // How many milliseconds are between
4220
- * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
4221
- * const result = differenceInMilliseconds(
4222
- * new Date(2014, 6, 2, 12, 30, 21, 700),
4223
- * new Date(2014, 6, 2, 12, 30, 20, 600)
4224
- * )
4225
- * //=> 1100
4226
- */
4227
- function differenceInMilliseconds(laterDate, earlierDate) {
4228
- return +toDate(laterDate) - +toDate(earlierDate);
4229
- }
4230
-
4231
- //#endregion
4232
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/differenceInSeconds.js
4233
- /**
4234
- * The {@link differenceInSeconds} function options.
4235
- */
4055
+ //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/formatDistanceStrict.js
4236
4056
  /**
4237
- * @name differenceInSeconds
4238
- * @category Second Helpers
4239
- * @summary Get the number of seconds between the given dates.
4240
- *
4241
- * @description
4242
- * Get the number of seconds between the given dates.
4243
- *
4244
- * @param laterDate - The later date
4245
- * @param earlierDate - The earlier date
4246
- * @param options - An object with options.
4247
- *
4248
- * @returns The number of seconds
4249
- *
4250
- * @example
4251
- * // How many seconds are between
4252
- * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
4253
- * const result = differenceInSeconds(
4254
- * new Date(2014, 6, 2, 12, 30, 20, 0),
4255
- * new Date(2014, 6, 2, 12, 30, 7, 999)
4256
- * )
4257
- * //=> 12
4057
+ * The {@link formatDistanceStrict} function options.
4258
4058
  */
4259
- function differenceInSeconds(laterDate, earlierDate, options) {
4260
- const diff = differenceInMilliseconds(laterDate, earlierDate) / 1e3;
4261
- return getRoundingMethod(options?.roundingMethod)(diff);
4262
- }
4263
-
4264
- //#endregion
4265
- //#region ../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/formatDistance.js
4266
4059
  /**
4267
- * The {@link formatDistance} function options.
4060
+ * The unit used to format the distance in {@link formatDistanceStrict}.
4268
4061
  */
4269
4062
  /**
4270
- * @name formatDistance
4063
+ * @name formatDistanceStrict
4271
4064
  * @category Common Helpers
4272
4065
  * @summary Return the distance between the given dates in words.
4273
4066
  *
4274
4067
  * @description
4275
- * Return the distance between the given dates in words.
4068
+ * Return the distance between the given dates in words, using strict units.
4069
+ * This is like `formatDistance`, but does not use helpers like 'almost', 'over',
4070
+ * 'less than' and the like.
4276
4071
  *
4277
- * | Distance between dates | Result |
4278
- * |-------------------------------------------------------------------|---------------------|
4279
- * | 0 ... 30 secs | less than a minute |
4280
- * | 30 secs ... 1 min 30 secs | 1 minute |
4281
- * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes |
4282
- * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |
4283
- * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours |
4284
- * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |
4285
- * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days |
4286
- * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |
4287
- * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |
4288
- * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months |
4289
- * | 1 yr ... 1 yr 3 months | about 1 year |
4290
- * | 1 yr 3 months ... 1 yr 9 month s | over 1 year |
4291
- * | 1 yr 9 months ... 2 yrs | almost 2 years |
4292
- * | N yrs ... N yrs 3 months | about N years |
4293
- * | N yrs 3 months ... N yrs 9 months | over N years |
4294
- * | N yrs 9 months ... N+1 yrs | almost N+1 years |
4295
- *
4296
- * With `options.includeSeconds == true`:
4297
- * | Distance between dates | Result |
4298
- * |------------------------|----------------------|
4299
- * | 0 secs ... 5 secs | less than 5 seconds |
4300
- * | 5 secs ... 10 secs | less than 10 seconds |
4301
- * | 10 secs ... 20 secs | less than 20 seconds |
4302
- * | 20 secs ... 40 secs | half a minute |
4303
- * | 40 secs ... 60 secs | less than a minute |
4304
- * | 60 secs ... 90 secs | 1 minute |
4072
+ * | Distance between dates | Result |
4073
+ * |------------------------|---------------------|
4074
+ * | 0 ... 59 secs | [0..59] seconds |
4075
+ * | 1 ... 59 mins | [1..59] minutes |
4076
+ * | 1 ... 23 hrs | [1..23] hours |
4077
+ * | 1 ... 29 days | [1..29] days |
4078
+ * | 1 ... 11 months | [1..11] months |
4079
+ * | 1 ... N years | [1..N] years |
4305
4080
  *
4306
4081
  * @param laterDate - The date
4307
4082
  * @param earlierDate - The date to compare with
@@ -4311,43 +4086,59 @@ function differenceInSeconds(laterDate, earlierDate, options) {
4311
4086
  *
4312
4087
  * @throws `date` must not be Invalid Date
4313
4088
  * @throws `baseDate` must not be Invalid Date
4089
+ * @throws `options.unit` must be 'second', 'minute', 'hour', 'day', 'month' or 'year'
4314
4090
  * @throws `options.locale` must contain `formatDistance` property
4315
4091
  *
4316
4092
  * @example
4317
4093
  * // What is the distance between 2 July 2014 and 1 January 2015?
4318
- * const result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1))
4094
+ * const result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2))
4319
4095
  * //=> '6 months'
4320
4096
  *
4321
4097
  * @example
4322
4098
  * // What is the distance between 1 January 2015 00:00:15
4323
- * // and 1 January 2015 00:00:00, including seconds?
4324
- * const result = formatDistance(
4099
+ * // and 1 January 2015 00:00:00?
4100
+ * const result = formatDistanceStrict(
4325
4101
  * new Date(2015, 0, 1, 0, 0, 15),
4326
- * new Date(2015, 0, 1, 0, 0, 0),
4327
- * { includeSeconds: true }
4102
+ * new Date(2015, 0, 1, 0, 0, 0)
4328
4103
  * )
4329
- * //=> 'less than 20 seconds'
4104
+ * //=> '15 seconds'
4330
4105
  *
4331
4106
  * @example
4332
4107
  * // What is the distance from 1 January 2016
4333
4108
  * // to 1 January 2015, with a suffix?
4334
- * const result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), {
4109
+ * const result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), {
4335
4110
  * addSuffix: true
4336
4111
  * })
4337
- * //=> 'about 1 year ago'
4112
+ * //=> '1 year ago'
4113
+ *
4114
+ * @example
4115
+ * // What is the distance from 1 January 2016
4116
+ * // to 1 January 2015, in minutes?
4117
+ * const result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), {
4118
+ * unit: 'minute'
4119
+ * })
4120
+ * //=> '525600 minutes'
4121
+ *
4122
+ * @example
4123
+ * // What is the distance from 1 January 2015
4124
+ * // to 28 January 2015, in months, rounded up?
4125
+ * const result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), {
4126
+ * unit: 'month',
4127
+ * roundingMethod: 'ceil'
4128
+ * })
4129
+ * //=> '1 month'
4338
4130
  *
4339
4131
  * @example
4340
4132
  * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto?
4341
4133
  * import { eoLocale } from 'date-fns/locale/eo'
4342
- * const result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), {
4134
+ * const result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), {
4343
4135
  * locale: eoLocale
4344
4136
  * })
4345
- * //=> 'pli ol 1 jaro'
4137
+ * //=> '1 jaro'
4346
4138
  */
4347
- function formatDistance(laterDate, earlierDate, options) {
4139
+ function formatDistanceStrict(laterDate, earlierDate, options) {
4348
4140
  const defaultOptions$1 = getDefaultOptions();
4349
4141
  const locale = options?.locale ?? defaultOptions$1.locale ?? enUS;
4350
- const minutesInAlmostTwoDays = 2520;
4351
4142
  const comparison = compareAsc(laterDate, earlierDate);
4352
4143
  if (isNaN(comparison)) throw new RangeError("Invalid time value");
4353
4144
  const localizeOptions = Object.assign({}, options, {
@@ -4355,41 +4146,37 @@ function formatDistance(laterDate, earlierDate, options) {
4355
4146
  comparison
4356
4147
  });
4357
4148
  const [laterDate_, earlierDate_] = normalizeDates(options?.in, ...comparison > 0 ? [earlierDate, laterDate] : [laterDate, earlierDate]);
4358
- const seconds = differenceInSeconds(earlierDate_, laterDate_);
4359
- const offsetInSeconds = (getTimezoneOffsetInMilliseconds(earlierDate_) - getTimezoneOffsetInMilliseconds(laterDate_)) / 1e3;
4360
- const minutes = Math.round((seconds - offsetInSeconds) / 60);
4361
- let months;
4362
- if (minutes < 2) if (options?.includeSeconds) if (seconds < 5) return locale.formatDistance("lessThanXSeconds", 5, localizeOptions);
4363
- else if (seconds < 10) return locale.formatDistance("lessThanXSeconds", 10, localizeOptions);
4364
- else if (seconds < 20) return locale.formatDistance("lessThanXSeconds", 20, localizeOptions);
4365
- else if (seconds < 40) return locale.formatDistance("halfAMinute", 0, localizeOptions);
4366
- else if (seconds < 60) return locale.formatDistance("lessThanXMinutes", 1, localizeOptions);
4367
- else return locale.formatDistance("xMinutes", 1, localizeOptions);
4368
- else if (minutes === 0) return locale.formatDistance("lessThanXMinutes", 1, localizeOptions);
4369
- else return locale.formatDistance("xMinutes", minutes, localizeOptions);
4370
- else if (minutes < 45) return locale.formatDistance("xMinutes", minutes, localizeOptions);
4371
- else if (minutes < 90) return locale.formatDistance("aboutXHours", 1, localizeOptions);
4372
- else if (minutes < minutesInDay) {
4373
- const hours = Math.round(minutes / 60);
4374
- return locale.formatDistance("aboutXHours", hours, localizeOptions);
4375
- } else if (minutes < minutesInAlmostTwoDays) return locale.formatDistance("xDays", 1, localizeOptions);
4376
- else if (minutes < minutesInMonth) {
4377
- const days = Math.round(minutes / minutesInDay);
4149
+ const roundingMethod = getRoundingMethod(options?.roundingMethod ?? "round");
4150
+ const milliseconds = earlierDate_.getTime() - laterDate_.getTime();
4151
+ const minutes = milliseconds / millisecondsInMinute;
4152
+ const dstNormalizedMinutes = (milliseconds - (getTimezoneOffsetInMilliseconds(earlierDate_) - getTimezoneOffsetInMilliseconds(laterDate_))) / millisecondsInMinute;
4153
+ const defaultUnit = options?.unit;
4154
+ let unit;
4155
+ if (!defaultUnit) if (minutes < 1) unit = "second";
4156
+ else if (minutes < 60) unit = "minute";
4157
+ else if (minutes < minutesInDay) unit = "hour";
4158
+ else if (dstNormalizedMinutes < minutesInMonth) unit = "day";
4159
+ else if (dstNormalizedMinutes < minutesInYear) unit = "month";
4160
+ else unit = "year";
4161
+ else unit = defaultUnit;
4162
+ if (unit === "second") {
4163
+ const seconds = roundingMethod(milliseconds / 1e3);
4164
+ return locale.formatDistance("xSeconds", seconds, localizeOptions);
4165
+ } else if (unit === "minute") {
4166
+ const roundedMinutes = roundingMethod(minutes);
4167
+ return locale.formatDistance("xMinutes", roundedMinutes, localizeOptions);
4168
+ } else if (unit === "hour") {
4169
+ const hours = roundingMethod(minutes / 60);
4170
+ return locale.formatDistance("xHours", hours, localizeOptions);
4171
+ } else if (unit === "day") {
4172
+ const days = roundingMethod(dstNormalizedMinutes / minutesInDay);
4378
4173
  return locale.formatDistance("xDays", days, localizeOptions);
4379
- } else if (minutes < minutesInMonth * 2) {
4380
- months = Math.round(minutes / minutesInMonth);
4381
- return locale.formatDistance("aboutXMonths", months, localizeOptions);
4382
- }
4383
- months = differenceInMonths(earlierDate_, laterDate_);
4384
- if (months < 12) {
4385
- const nearestMonth = Math.round(minutes / minutesInMonth);
4386
- return locale.formatDistance("xMonths", nearestMonth, localizeOptions);
4174
+ } else if (unit === "month") {
4175
+ const months = roundingMethod(dstNormalizedMinutes / minutesInMonth);
4176
+ return months === 12 && defaultUnit !== "month" ? locale.formatDistance("xYears", 1, localizeOptions) : locale.formatDistance("xMonths", months, localizeOptions);
4387
4177
  } else {
4388
- const monthsSinceStartOfYear = months % 12;
4389
- const years = Math.trunc(months / 12);
4390
- if (monthsSinceStartOfYear < 3) return locale.formatDistance("aboutXYears", years, localizeOptions);
4391
- else if (monthsSinceStartOfYear < 9) return locale.formatDistance("overXYears", years, localizeOptions);
4392
- else return locale.formatDistance("almostXYears", years + 1, localizeOptions);
4178
+ const years = roundingMethod(dstNormalizedMinutes / minutesInYear);
4179
+ return locale.formatDistance("xYears", years, localizeOptions);
4393
4180
  }
4394
4181
  }
4395
4182
 
@@ -4421,7 +4208,7 @@ function formatBytes(bytes) {
4421
4208
  }
4422
4209
  function timeAgo(date) {
4423
4210
  if (date === void 0) return "-";
4424
- return formatDistance(date, /* @__PURE__ */ new Date(), { addSuffix: true }).replace("about ", "").replace("less than ", "");
4211
+ return formatDistanceStrict(date, /* @__PURE__ */ new Date(), { addSuffix: true });
4425
4212
  }
4426
4213
  function table(opts) {
4427
4214
  const titles = Object.keys(opts.columns);
@@ -4447,6 +4234,19 @@ function formatRunDuration(d$1) {
4447
4234
  if (d$1 < 1e3) return `${d$1}ms`;
4448
4235
  return `${d$1 / 1e3}s`;
4449
4236
  }
4237
+ function formatNextCursorHint(cursor) {
4238
+ const args$4 = process.argv.slice(2);
4239
+ const filtered = [];
4240
+ for (let i = 0; i < args$4.length; i++) {
4241
+ if (args$4[i] === "--cursor") {
4242
+ i++;
4243
+ continue;
4244
+ }
4245
+ if (args$4[i].startsWith("--cursor=")) continue;
4246
+ filtered.push(args$4[i]);
4247
+ }
4248
+ return `\nMore results: sandbox ${filtered.join(" ")} --cursor ${cursor}`;
4249
+ }
4450
4250
 
4451
4251
  //#endregion
4452
4252
  //#region ../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
@@ -6890,7 +6690,7 @@ function createAbortController(reason) {
6890
6690
  signal: controller.signal,
6891
6691
  ignoreInterruptions: ignoreAbortErrors(controller.signal)
6892
6692
  };
6893
- }, (c) => c.abort(reason));
6693
+ }, (c$1) => c$1.abort(reason));
6894
6694
  }
6895
6695
 
6896
6696
  //#endregion
@@ -7019,7 +6819,15 @@ const login = import_cjs$23.command({
7019
6819
  if (error) {
7020
6820
  spinner.fail(`${source_default.red("error:")} ${error.message}`);
7021
6821
  process.exitCode = 1;
7022
- } else spinner.succeed(`${source_default.cyan("Congratulations!")} You are now signed in.`);
6822
+ } else {
6823
+ spinner.succeed(`${source_default.cyan("Congratulations!")} You are now signed in.`);
6824
+ const auth = getAuth();
6825
+ if (auth?.token) try {
6826
+ const { teamId, teamSlug, projectId, projectSlug } = await inferScope({ token: auth.token });
6827
+ process.stderr.write(source_default.dim(" │ ") + "team: " + source_default.cyan(teamSlug ?? teamId) + "\n");
6828
+ process.stderr.write(source_default.dim(" ╰ ") + "project: " + source_default.cyan(projectSlug ?? projectId) + "\n");
6829
+ } catch {}
6830
+ }
7023
6831
  } catch (_) {
7024
6832
  _usingCtx$1.e = _;
7025
6833
  } finally {
@@ -7254,7 +7062,7 @@ function readProjectConfiguration(cwd) {
7254
7062
  //#endregion
7255
7063
  //#region src/util/infer-scope.ts
7256
7064
  const debug$3 = createDebugger("sandbox:scope");
7257
- async function inferScope({ token: token$1, team: team$1 }) {
7065
+ async function inferScope$1({ token: token$1, team: team$1 }) {
7258
7066
  const jwt = z.jwt().safeParse(token$1);
7259
7067
  if (jwt.success) {
7260
7068
  debug$3("trying to infer scope from OIDC JWT");
@@ -7302,15 +7110,15 @@ async function inferFromJwt(jwt) {
7302
7110
  };
7303
7111
  }
7304
7112
  async function inferFromToken(token$1, requestedTeam) {
7305
- const { teamId, projectId } = await Auth.inferScope({
7113
+ const { teamId, teamSlug, projectId, projectSlug } = await Auth.inferScope({
7306
7114
  token: token$1,
7307
7115
  teamId: requestedTeam
7308
7116
  });
7309
7117
  return {
7310
7118
  owner: teamId,
7311
7119
  project: projectId,
7312
- ownerSlug: teamId,
7313
- projectSlug: projectId
7120
+ ownerSlug: teamSlug ?? teamId,
7121
+ projectSlug: projectSlug ?? projectId
7314
7122
  };
7315
7123
  }
7316
7124
 
@@ -7381,7 +7189,7 @@ const scope = {
7381
7189
  let projectSlug;
7382
7190
  let teamSlug;
7383
7191
  if (typeof projectId.value === "undefined" || typeof teamId.value === "undefined") try {
7384
- const scope$1 = await inferScope({
7192
+ const scope$1 = await inferScope$1({
7385
7193
  token: t.value,
7386
7194
  team: teamId.value
7387
7195
  });
@@ -7427,7 +7235,7 @@ const scope = {
7427
7235
 
7428
7236
  //#endregion
7429
7237
  //#region package.json
7430
- var version = "3.0.0-beta.16";
7238
+ var version = "3.0.0-beta.20";
7431
7239
 
7432
7240
  //#endregion
7433
7241
  //#region src/error.ts
@@ -12000,9 +11808,19 @@ const list = import_cjs$12.command({
12000
11808
  description: "Filter sandboxes by tag. Format: \"key=value\"",
12001
11809
  type: ObjectFromKeyValue
12002
11810
  }),
11811
+ limit: import_cjs$12.option({
11812
+ long: "limit",
11813
+ description: "Maximum number of sandboxes per page (default 50).",
11814
+ type: import_cjs$12.optional(import_cjs$12.number)
11815
+ }),
11816
+ cursor: import_cjs$12.option({
11817
+ long: "cursor",
11818
+ description: "Pagination cursor from a previous 'More results' hint.",
11819
+ type: import_cjs$12.optional(import_cjs$12.string)
11820
+ }),
12003
11821
  scope
12004
11822
  },
12005
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, namePrefix, sortBy, sortOrder, tags }) {
11823
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, namePrefix, sortBy, sortOrder, tags, limit, cursor }) {
12006
11824
  if (namePrefix) {
12007
11825
  if (sortBy && sortBy !== "name") {
12008
11826
  console.error(source_default.red("Error: --sort-by must be 'name' when using --name-prefix"));
@@ -12010,28 +11828,28 @@ const list = import_cjs$12.command({
12010
11828
  }
12011
11829
  sortBy = "name";
12012
11830
  }
12013
- const sandboxes = await (async () => {
11831
+ const { sandboxes, pagination } = await (async () => {
12014
11832
  try {
12015
11833
  var _usingCtx$1 = _usingCtx();
12016
11834
  const _spinner$1 = _usingCtx$1.u(acquireRelease(() => ora("Fetching sandboxes...").start(), (s$1) => s$1.stop()));
12017
- let { sandboxes: sandboxes$1 } = await sandboxClient.list({
11835
+ return sandboxClient.list({
12018
11836
  token: token$1,
12019
11837
  teamId: team$1,
12020
11838
  projectId: project$1,
12021
- limit: 50,
11839
+ limit: limit ?? 50,
11840
+ ...cursor && { cursor },
12022
11841
  ...namePrefix && { namePrefix },
12023
11842
  ...sortBy && { sortBy },
12024
11843
  ...sortOrder && { sortOrder },
12025
11844
  ...Object.keys(tags).length > 0 && { tags }
12026
11845
  });
12027
- if (!all) sandboxes$1 = sandboxes$1.filter((x) => x.status === "running");
12028
- return sandboxes$1;
12029
11846
  } catch (_) {
12030
11847
  _usingCtx$1.e = _;
12031
11848
  } finally {
12032
11849
  _usingCtx$1.d();
12033
11850
  }
12034
11851
  })();
11852
+ const displayedSandboxes = all ? sandboxes : sandboxes.filter((x) => x.status === "running");
12035
11853
  const memoryFormatter = new Intl.NumberFormat(void 0, {
12036
11854
  style: "unit",
12037
11855
  unit: "megabyte"
@@ -12055,9 +11873,10 @@ const list = import_cjs$12.command({
12055
11873
  columns["NETWORK (OUT/IN)"] = { value: (s$1) => s$1.totalEgressBytes || s$1.totalIngressBytes ? `${formatBytes(s$1.totalEgressBytes ?? 0)} / ${formatBytes(s$1.totalIngressBytes ?? 0)}` : "- / -" };
12056
11874
  }
12057
11875
  console.log(table({
12058
- rows: sandboxes,
11876
+ rows: displayedSandboxes,
12059
11877
  columns
12060
11878
  }));
11879
+ if (pagination.next !== null) console.log(formatNextCursorHint(pagination.next));
12061
11880
  }
12062
11881
  });
12063
11882
  const SandboxStatusColor = {
@@ -12089,6 +11908,106 @@ const connect = import_cjs$11.command({
12089
11908
  }
12090
11909
  });
12091
11910
 
11911
+ //#endregion
11912
+ //#region src/commands/stop.ts
11913
+ var import_cjs$10 = /* @__PURE__ */ __toESM(require_cjs());
11914
+ init_source();
11915
+ function c(label, value) {
11916
+ return {
11917
+ label,
11918
+ value
11919
+ };
11920
+ }
11921
+ /** Visible width of a cell (label + value, no ANSI). */
11922
+ function cellWidth(cell) {
11923
+ return cell ? cell.label.length + cell.value.length : 0;
11924
+ }
11925
+ /** Print rows as a tree with column-aligned label: value pairs. */
11926
+ function printTree(rows) {
11927
+ const widths = [];
11928
+ for (const row of rows) for (let i = 0; i < row.length; i++) widths[i] = Math.max(widths[i] ?? 0, cellWidth(row[i]));
11929
+ for (let r = 0; r < rows.length; r++) {
11930
+ const prefix$1 = r === rows.length - 1 ? source_default.dim(" ╰ ") : source_default.dim(" │ ");
11931
+ const line = rows[r].map((cell, i) => {
11932
+ if (!cell) return " ".repeat(widths[i]);
11933
+ const pad = widths[i] - cell.label.length - cell.value.length;
11934
+ return cell.label + source_default.cyan(cell.value) + " ".repeat(Math.max(0, pad));
11935
+ }).join(" ").trimEnd();
11936
+ process.stderr.write(prefix$1 + line + "\n");
11937
+ }
11938
+ }
11939
+ function printStopResult(name, sandbox, sessionSnapshot) {
11940
+ process.stderr.write(source_default.green("✔") + " Sandbox stopped.\n");
11941
+ const snapshot$1 = sessionSnapshot.snapshot;
11942
+ printTree([
11943
+ [
11944
+ c("sandbox: ", name),
11945
+ sandbox.totalActiveCpuDurationMs != null ? c("active cpu: ", formatRunDuration(sandbox.totalActiveCpuDurationMs)) : null,
11946
+ sandbox.memory != null ? c("mem: ", `${sandbox.memory} MB`) : null,
11947
+ sandbox.totalDurationMs != null ? c("duration: ", formatRunDuration(sandbox.totalDurationMs)) : null,
11948
+ sandbox.totalIngressBytes != null ? c("ingress: ", formatBytes(sandbox.totalIngressBytes)) : null,
11949
+ sandbox.totalEgressBytes != null ? c("egress: ", formatBytes(sandbox.totalEgressBytes)) : null
11950
+ ],
11951
+ [
11952
+ c("session: ", sessionSnapshot.id),
11953
+ sessionSnapshot.activeCpuDurationMs != null ? c("active cpu: ", formatRunDuration(sessionSnapshot.activeCpuDurationMs)) : null,
11954
+ c("mem: ", `${sessionSnapshot.memory} MB`),
11955
+ sessionSnapshot.duration != null ? c("duration: ", formatRunDuration(sessionSnapshot.duration)) : null,
11956
+ sessionSnapshot.networkTransfer ? c("ingress: ", formatBytes(sessionSnapshot.networkTransfer.ingress)) : null,
11957
+ sessionSnapshot.networkTransfer ? c("egress: ", formatBytes(sessionSnapshot.networkTransfer.egress)) : null
11958
+ ],
11959
+ ...snapshot$1 ? [[
11960
+ c("snapshot: ", snapshot$1.id),
11961
+ c("size: ", formatBytes(snapshot$1.sizeBytes)),
11962
+ c("expires: ", snapshot$1.expiresAt ? timeAgo(snapshot$1.expiresAt) : "never")
11963
+ ]] : []
11964
+ ]);
11965
+ }
11966
+ const stop = import_cjs$10.command({
11967
+ name: "stop",
11968
+ description: "Stop the current session of one or more sandboxes",
11969
+ args: {
11970
+ sandboxName: import_cjs$10.positional({
11971
+ type: sandboxName,
11972
+ description: "A sandbox name to stop"
11973
+ }),
11974
+ sandboxNames: import_cjs$10.restPositionals({
11975
+ type: sandboxName,
11976
+ description: "More sandboxes to stop"
11977
+ }),
11978
+ scope
11979
+ },
11980
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, sandboxName: sandboxName$1, sandboxNames }) {
11981
+ const names = Array.from(new Set([sandboxName$1, ...sandboxNames]));
11982
+ const spinner = ora({
11983
+ text: names.length === 1 ? `Stopping ${names[0]}` : `Stopping ${names.length} sandboxes`,
11984
+ stream: process.stderr
11985
+ }).start();
11986
+ const results = await Promise.allSettled(names.map(async (name) => {
11987
+ const sandbox = await sandboxClient.get({
11988
+ token: token$1,
11989
+ teamId: team$1,
11990
+ projectId: project$1,
11991
+ name
11992
+ });
11993
+ return {
11994
+ name,
11995
+ sandbox,
11996
+ sessionSnapshot: await sandbox.stop()
11997
+ };
11998
+ }));
11999
+ spinner.stop();
12000
+ for (const result of results) if (result.status === "fulfilled") {
12001
+ const { name, sandbox, sessionSnapshot } = result.value;
12002
+ printStopResult(name, sandbox, sessionSnapshot);
12003
+ } else {
12004
+ const error = result.reason;
12005
+ process.stderr.write(source_default.red("✖") + ` ${error.message ?? error}\n`);
12006
+ process.exitCode = 1;
12007
+ }
12008
+ }
12009
+ });
12010
+
12092
12011
  //#endregion
12093
12012
  //#region ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js
12094
12013
  var require_eventemitter3 = /* @__PURE__ */ __commonJS$1({ "../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js": ((exports, module) => {
@@ -14372,45 +14291,6 @@ var Listr = class {
14372
14291
  }
14373
14292
  };
14374
14293
 
14375
- //#endregion
14376
- //#region src/commands/stop.ts
14377
- var import_cjs$10 = /* @__PURE__ */ __toESM(require_cjs());
14378
- const stop = import_cjs$10.command({
14379
- name: "stop",
14380
- description: "Stop the current session of one or more sandboxes",
14381
- args: {
14382
- sandboxName: import_cjs$10.positional({
14383
- type: sandboxName,
14384
- description: "A sandbox name to stop"
14385
- }),
14386
- sandboxNames: import_cjs$10.restPositionals({
14387
- type: sandboxName,
14388
- description: "More sandboxes to stop"
14389
- }),
14390
- scope
14391
- },
14392
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, sandboxName: sandboxName$1, sandboxNames }) {
14393
- const tasks = Array.from(new Set([sandboxName$1, ...sandboxNames]), (sandboxName$2) => {
14394
- return {
14395
- title: `Stopping active session from ${sandboxName$2}`,
14396
- async task() {
14397
- await (await sandboxClient.get({
14398
- token: token$1,
14399
- teamId: team$1,
14400
- projectId: project$1,
14401
- name: sandboxName$2
14402
- })).stop();
14403
- }
14404
- };
14405
- });
14406
- try {
14407
- await new Listr(tasks, { concurrent: true }).run();
14408
- } catch {
14409
- process.exitCode = 1;
14410
- }
14411
- }
14412
- });
14413
-
14414
14294
  //#endregion
14415
14295
  //#region src/commands/remove.ts
14416
14296
  var import_cjs$9 = /* @__PURE__ */ __toESM(require_cjs());
@@ -14625,22 +14505,32 @@ const list$2 = import_cjs$4.command({
14625
14505
  long: "sort-order",
14626
14506
  description: "Sort order. Options: asc, desc (default)",
14627
14507
  type: import_cjs$4.optional(import_cjs$4.oneOf(["asc", "desc"]))
14508
+ }),
14509
+ limit: import_cjs$4.option({
14510
+ long: "limit",
14511
+ description: "Maximum number of snapshots per page (default 50).",
14512
+ type: import_cjs$4.optional(import_cjs$4.number)
14513
+ }),
14514
+ cursor: import_cjs$4.option({
14515
+ long: "cursor",
14516
+ description: "Pagination cursor from a previous 'More results' hint.",
14517
+ type: import_cjs$4.optional(import_cjs$4.string)
14628
14518
  })
14629
14519
  },
14630
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, name, sortOrder }) {
14631
- const snapshots$1 = await (async () => {
14520
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, name, sortOrder, limit, cursor }) {
14521
+ const { snapshots: snapshots$1, pagination } = await (async () => {
14632
14522
  try {
14633
14523
  var _usingCtx$1 = _usingCtx();
14634
14524
  const _spinner$1 = _usingCtx$1.u(acquireRelease(() => ora("Fetching snapshots...").start(), (s$1) => s$1.stop()));
14635
- const { snapshots: snapshots$2 } = await snapshotClient.list({
14525
+ return snapshotClient.list({
14636
14526
  token: token$1,
14637
14527
  teamId: team$1,
14638
14528
  projectId: project$1,
14639
14529
  name,
14640
- limit: 50,
14530
+ limit: limit ?? 50,
14531
+ ...cursor && { cursor },
14641
14532
  ...sortOrder && { sortOrder }
14642
14533
  });
14643
- return snapshots$2;
14644
14534
  } catch (_) {
14645
14535
  _usingCtx$1.e = _;
14646
14536
  } finally {
@@ -14661,6 +14551,7 @@ const list$2 = import_cjs$4.command({
14661
14551
  ["SOURCE SESSION"]: { value: (s$1) => s$1.sourceSessionId }
14662
14552
  }
14663
14553
  }));
14554
+ if (pagination.next !== null) console.log(formatNextCursorHint(pagination.next));
14664
14555
  }
14665
14556
  });
14666
14557
  const get = import_cjs$4.command({
@@ -14783,27 +14674,41 @@ const list$1 = import_cjs$2.command({
14783
14674
  description: "Sort order. Options: asc, desc (default)",
14784
14675
  type: import_cjs$2.optional(import_cjs$2.oneOf(["asc", "desc"]))
14785
14676
  }),
14677
+ limit: import_cjs$2.option({
14678
+ long: "limit",
14679
+ description: "Maximum number of sessions per page (default 50).",
14680
+ type: import_cjs$2.optional(import_cjs$2.number)
14681
+ }),
14682
+ cursor: import_cjs$2.option({
14683
+ long: "cursor",
14684
+ description: "Pagination cursor from a previous 'More results' hint.",
14685
+ type: import_cjs$2.optional(import_cjs$2.string)
14686
+ }),
14786
14687
  scope
14787
14688
  },
14788
- async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, sandbox: name, sortOrder }) {
14689
+ async handler({ scope: { token: token$1, team: team$1, project: project$1 }, all, sandbox: name, sortOrder, limit, cursor }) {
14789
14690
  const sandbox = await sandboxClient.get({
14790
14691
  name,
14791
14692
  projectId: project$1,
14792
14693
  teamId: team$1,
14793
14694
  token: token$1
14794
14695
  });
14795
- let { sessions: sessions$1 } = await (async () => {
14696
+ const { sessions: sessions$1, pagination } = await (async () => {
14796
14697
  try {
14797
14698
  var _usingCtx$1 = _usingCtx();
14798
14699
  const _spinner$1 = _usingCtx$1.u(acquireRelease(() => ora("Fetching sessions...").start(), (s$1) => s$1.stop()));
14799
- return sandbox.listSessions({ ...sortOrder && { sortOrder } });
14700
+ return sandbox.listSessions({
14701
+ limit: limit ?? 50,
14702
+ ...cursor && { cursor },
14703
+ ...sortOrder && { sortOrder }
14704
+ });
14800
14705
  } catch (_) {
14801
14706
  _usingCtx$1.e = _;
14802
14707
  } finally {
14803
14708
  _usingCtx$1.d();
14804
14709
  }
14805
14710
  })();
14806
- if (!all) sessions$1 = sessions$1.filter((x) => x.status === "running");
14711
+ const displayedSessions = all ? sessions$1 : sessions$1.filter((x) => x.status === "running");
14807
14712
  const memoryFormatter = new Intl.NumberFormat(void 0, {
14808
14713
  style: "unit",
14809
14714
  unit: "megabyte"
@@ -14827,9 +14732,10 @@ const list$1 = import_cjs$2.command({
14827
14732
  columns["NETWORK (OUT/IN)"] = { value: (s$1) => s$1.networkTransfer?.egress || s$1.networkTransfer?.ingress ? `${formatBytes(s$1.networkTransfer?.egress ?? 0)} / ${formatBytes(s$1.networkTransfer?.ingress ?? 0)}` : "- / -" };
14828
14733
  }
14829
14734
  console.log(table({
14830
- rows: sessions$1,
14735
+ rows: displayedSessions,
14831
14736
  columns
14832
14737
  }));
14738
+ if (pagination.next !== null) console.log(formatNextCursorHint(pagination.next));
14833
14739
  }
14834
14740
  });
14835
14741
  const sessions = (0, import_cjs$3.subcommands)({
@@ -15234,4 +15140,4 @@ const app = (opts) => (0, import_cjs.subcommands)({
15234
15140
 
15235
15141
  //#endregion
15236
15142
  export { source_exports as a, init_source as i, StyledError as n, require_cjs as r, app as t };
15237
- //# sourceMappingURL=app-CvPilMmO.mjs.map
15143
+ //# sourceMappingURL=app-DfdLC3Kn.mjs.map