@iblai/iblai-js 1.4.4 → 1.4.8

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.
@@ -113255,6 +113255,20 @@ const millisecondsInWeek = 604800000;
113255
113255
  */
113256
113256
  const millisecondsInDay = 86400000;
113257
113257
 
113258
+ /**
113259
+ * @constant
113260
+ * @name minutesInMonth
113261
+ * @summary Minutes in 1 month.
113262
+ */
113263
+ const minutesInMonth = 43200;
113264
+
113265
+ /**
113266
+ * @constant
113267
+ * @name minutesInDay
113268
+ * @summary Minutes in 1 day.
113269
+ */
113270
+ const minutesInDay = 1440;
113271
+
113258
113272
  /**
113259
113273
  * @constant
113260
113274
  * @name constructFromSymbol
@@ -113630,7 +113644,7 @@ function getTimezoneOffsetInMilliseconds(date) {
113630
113644
  function normalizeDates(context, ...dates) {
113631
113645
  const normalize = constructFrom.bind(
113632
113646
  null,
113633
- dates.find((date) => typeof date === "object"),
113647
+ context || dates.find((date) => typeof date === "object"),
113634
113648
  );
113635
113649
  return dates.map(normalize);
113636
113650
  }
@@ -113910,6 +113924,80 @@ function min$3(dates, options) {
113910
113924
  return constructFrom(context, result || NaN);
113911
113925
  }
113912
113926
 
113927
+ /**
113928
+ * @name compareAsc
113929
+ * @category Common Helpers
113930
+ * @summary Compare the two dates and return -1, 0 or 1.
113931
+ *
113932
+ * @description
113933
+ * Compare the two dates and return 1 if the first date is after the second,
113934
+ * -1 if the first date is before the second or 0 if dates are equal.
113935
+ *
113936
+ * @param dateLeft - The first date to compare
113937
+ * @param dateRight - The second date to compare
113938
+ *
113939
+ * @returns The result of the comparison
113940
+ *
113941
+ * @example
113942
+ * // Compare 11 February 1987 and 10 July 1989:
113943
+ * const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))
113944
+ * //=> -1
113945
+ *
113946
+ * @example
113947
+ * // Sort the array of dates:
113948
+ * const result = [
113949
+ * new Date(1995, 6, 2),
113950
+ * new Date(1987, 1, 11),
113951
+ * new Date(1989, 6, 10)
113952
+ * ].sort(compareAsc)
113953
+ * //=> [
113954
+ * // Wed Feb 11 1987 00:00:00,
113955
+ * // Mon Jul 10 1989 00:00:00,
113956
+ * // Sun Jul 02 1995 00:00:00
113957
+ * // ]
113958
+ */
113959
+ function compareAsc(dateLeft, dateRight) {
113960
+ const diff = +toDate(dateLeft) - +toDate(dateRight);
113961
+
113962
+ if (diff < 0) return -1;
113963
+ else if (diff > 0) return 1;
113964
+
113965
+ // Return 0 if diff is 0; return NaN if diff is NaN
113966
+ return diff;
113967
+ }
113968
+
113969
+ /**
113970
+ * @name constructNow
113971
+ * @category Generic Helpers
113972
+ * @summary Constructs a new current date using the passed value constructor.
113973
+ * @pure false
113974
+ *
113975
+ * @description
113976
+ * The function constructs a new current date using the constructor from
113977
+ * the reference date. It helps to build generic functions that accept date
113978
+ * extensions and use the current date.
113979
+ *
113980
+ * It defaults to `Date` if the passed reference date is a number or a string.
113981
+ *
113982
+ * @param date - The reference date to take constructor from
113983
+ *
113984
+ * @returns Current date initialized using the given date constructor
113985
+ *
113986
+ * @example
113987
+ * import { constructNow, isSameDay } from 'date-fns'
113988
+ *
113989
+ * function isToday<DateType extends Date>(
113990
+ * date: DateArg<DateType>,
113991
+ * ): boolean {
113992
+ * // If we were to use `new Date()` directly, the function would behave
113993
+ * // differently in different timezones and return false for the same date.
113994
+ * return isSameDay(date, constructNow(date));
113995
+ * }
113996
+ */
113997
+ function constructNow(date) {
113998
+ return constructFrom(date, Date.now());
113999
+ }
114000
+
113913
114001
  /**
113914
114002
  * The {@link isSameDay} function options.
113915
114003
  */
@@ -114066,6 +114154,73 @@ function differenceInCalendarMonths(laterDate, earlierDate, options) {
114066
114154
  return yearsDiff * 12 + monthsDiff;
114067
114155
  }
114068
114156
 
114157
+ function getRoundingMethod(method) {
114158
+ return (number) => {
114159
+ const round = method ? Math[method] : Math.trunc;
114160
+ const result = round(number);
114161
+ // Prevent negative zero
114162
+ return result === 0 ? 0 : result;
114163
+ };
114164
+ }
114165
+
114166
+ /**
114167
+ * @name differenceInMilliseconds
114168
+ * @category Millisecond Helpers
114169
+ * @summary Get the number of milliseconds between the given dates.
114170
+ *
114171
+ * @description
114172
+ * Get the number of milliseconds between the given dates.
114173
+ *
114174
+ * @param laterDate - The later date
114175
+ * @param earlierDate - The earlier date
114176
+ *
114177
+ * @returns The number of milliseconds
114178
+ *
114179
+ * @example
114180
+ * // How many milliseconds are between
114181
+ * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
114182
+ * const result = differenceInMilliseconds(
114183
+ * new Date(2014, 6, 2, 12, 30, 21, 700),
114184
+ * new Date(2014, 6, 2, 12, 30, 20, 600)
114185
+ * )
114186
+ * //=> 1100
114187
+ */
114188
+ function differenceInMilliseconds(laterDate, earlierDate) {
114189
+ return +toDate(laterDate) - +toDate(earlierDate);
114190
+ }
114191
+
114192
+ /**
114193
+ * The {@link endOfDay} function options.
114194
+ */
114195
+
114196
+ /**
114197
+ * @name endOfDay
114198
+ * @category Day Helpers
114199
+ * @summary Return the end of a day for the given date.
114200
+ *
114201
+ * @description
114202
+ * Return the end of a day for the given date.
114203
+ * The result will be in the local timezone.
114204
+ *
114205
+ * @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).
114206
+ * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
114207
+ *
114208
+ * @param date - The original date
114209
+ * @param options - An object with options
114210
+ *
114211
+ * @returns The end of a day
114212
+ *
114213
+ * @example
114214
+ * // The end of a day for 2 September 2014 11:55:00:
114215
+ * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
114216
+ * //=> Tue Sep 02 2014 23:59:59.999
114217
+ */
114218
+ function endOfDay(date, options) {
114219
+ const _date = toDate(date, options?.in);
114220
+ _date.setHours(23, 59, 59, 999);
114221
+ return _date;
114222
+ }
114223
+
114069
114224
  /**
114070
114225
  * The {@link endOfMonth} function options.
114071
114226
  */
@@ -114100,6 +114255,115 @@ function endOfMonth(date, options) {
114100
114255
  return _date;
114101
114256
  }
114102
114257
 
114258
+ /**
114259
+ * @name isLastDayOfMonth
114260
+ * @category Month Helpers
114261
+ * @summary Is the given date the last day of a month?
114262
+ *
114263
+ * @description
114264
+ * Is the given date the last day of a month?
114265
+ *
114266
+ * @param date - The date to check
114267
+ * @param options - An object with options
114268
+ *
114269
+ * @returns The date is the last day of a month
114270
+ *
114271
+ * @example
114272
+ * // Is 28 February 2014 the last day of a month?
114273
+ * const result = isLastDayOfMonth(new Date(2014, 1, 28))
114274
+ * //=> true
114275
+ */
114276
+ function isLastDayOfMonth(date, options) {
114277
+ const _date = toDate(date, options?.in);
114278
+ return +endOfDay(_date, options) === +endOfMonth(_date, options);
114279
+ }
114280
+
114281
+ /**
114282
+ * The {@link differenceInMonths} function options.
114283
+ */
114284
+
114285
+ /**
114286
+ * @name differenceInMonths
114287
+ * @category Month Helpers
114288
+ * @summary Get the number of full months between the given dates.
114289
+ *
114290
+ * @param laterDate - The later date
114291
+ * @param earlierDate - The earlier date
114292
+ * @param options - An object with options
114293
+ *
114294
+ * @returns The number of full months
114295
+ *
114296
+ * @example
114297
+ * // How many full months are between 31 January 2014 and 1 September 2014?
114298
+ * const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31))
114299
+ * //=> 7
114300
+ */
114301
+ function differenceInMonths(laterDate, earlierDate, options) {
114302
+ const [laterDate_, workingLaterDate, earlierDate_] = normalizeDates(
114303
+ options?.in,
114304
+ laterDate,
114305
+ laterDate,
114306
+ earlierDate,
114307
+ );
114308
+
114309
+ const sign = compareAsc(workingLaterDate, earlierDate_);
114310
+ const difference = Math.abs(
114311
+ differenceInCalendarMonths(workingLaterDate, earlierDate_),
114312
+ );
114313
+
114314
+ if (difference < 1) return 0;
114315
+
114316
+ if (workingLaterDate.getMonth() === 1 && workingLaterDate.getDate() > 27)
114317
+ workingLaterDate.setDate(30);
114318
+
114319
+ workingLaterDate.setMonth(workingLaterDate.getMonth() - sign * difference);
114320
+
114321
+ let isLastMonthNotFull = compareAsc(workingLaterDate, earlierDate_) === -sign;
114322
+
114323
+ if (
114324
+ isLastDayOfMonth(laterDate_) &&
114325
+ difference === 1 &&
114326
+ compareAsc(laterDate_, earlierDate_) === 1
114327
+ ) {
114328
+ isLastMonthNotFull = false;
114329
+ }
114330
+
114331
+ const result = sign * (difference - +isLastMonthNotFull);
114332
+ return result === 0 ? 0 : result;
114333
+ }
114334
+
114335
+ /**
114336
+ * The {@link differenceInSeconds} function options.
114337
+ */
114338
+
114339
+ /**
114340
+ * @name differenceInSeconds
114341
+ * @category Second Helpers
114342
+ * @summary Get the number of seconds between the given dates.
114343
+ *
114344
+ * @description
114345
+ * Get the number of seconds between the given dates.
114346
+ *
114347
+ * @param laterDate - The later date
114348
+ * @param earlierDate - The earlier date
114349
+ * @param options - An object with options.
114350
+ *
114351
+ * @returns The number of seconds
114352
+ *
114353
+ * @example
114354
+ * // How many seconds are between
114355
+ * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
114356
+ * const result = differenceInSeconds(
114357
+ * new Date(2014, 6, 2, 12, 30, 20, 0),
114358
+ * new Date(2014, 6, 2, 12, 30, 7, 999)
114359
+ * )
114360
+ * //=> 12
114361
+ */
114362
+ function differenceInSeconds(laterDate, earlierDate, options) {
114363
+ const diff = differenceInMilliseconds(laterDate, earlierDate) / 1000;
114364
+ return getRoundingMethod(options?.roundingMethod)(diff);
114365
+ }
114366
+
114103
114367
  function normalizeInterval(context, interval) {
114104
114368
  const [start, end] = normalizeDates(context, interval.start, interval.end);
114105
114369
  return { start, end };
@@ -114427,7 +114691,7 @@ const formatDistanceLocale = {
114427
114691
  },
114428
114692
  };
114429
114693
 
114430
- const formatDistance = (token, count, options) => {
114694
+ const formatDistance$1 = (token, count, options) => {
114431
114695
  let result;
114432
114696
 
114433
114697
  const tokenValue = formatDistanceLocale[token];
@@ -114977,7 +115241,7 @@ const match = {
114977
115241
  */
114978
115242
  const enUS = {
114979
115243
  code: "en-US",
114980
- formatDistance: formatDistance,
115244
+ formatDistance: formatDistance$1,
114981
115245
  formatLong: formatLong,
114982
115246
  formatRelative: formatRelative,
114983
115247
  localize: localize,
@@ -116592,6 +116856,283 @@ function cleanEscapedString(input) {
116592
116856
  return matched[1].replace(doubleQuoteRegExp, "'");
116593
116857
  }
116594
116858
 
116859
+ /**
116860
+ * The {@link formatDistance} function options.
116861
+ */
116862
+
116863
+ /**
116864
+ * @name formatDistance
116865
+ * @category Common Helpers
116866
+ * @summary Return the distance between the given dates in words.
116867
+ *
116868
+ * @description
116869
+ * Return the distance between the given dates in words.
116870
+ *
116871
+ * | Distance between dates | Result |
116872
+ * |-------------------------------------------------------------------|---------------------|
116873
+ * | 0 ... 30 secs | less than a minute |
116874
+ * | 30 secs ... 1 min 30 secs | 1 minute |
116875
+ * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes |
116876
+ * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |
116877
+ * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours |
116878
+ * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |
116879
+ * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days |
116880
+ * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |
116881
+ * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |
116882
+ * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months |
116883
+ * | 1 yr ... 1 yr 3 months | about 1 year |
116884
+ * | 1 yr 3 months ... 1 yr 9 month s | over 1 year |
116885
+ * | 1 yr 9 months ... 2 yrs | almost 2 years |
116886
+ * | N yrs ... N yrs 3 months | about N years |
116887
+ * | N yrs 3 months ... N yrs 9 months | over N years |
116888
+ * | N yrs 9 months ... N+1 yrs | almost N+1 years |
116889
+ *
116890
+ * With `options.includeSeconds == true`:
116891
+ * | Distance between dates | Result |
116892
+ * |------------------------|----------------------|
116893
+ * | 0 secs ... 5 secs | less than 5 seconds |
116894
+ * | 5 secs ... 10 secs | less than 10 seconds |
116895
+ * | 10 secs ... 20 secs | less than 20 seconds |
116896
+ * | 20 secs ... 40 secs | half a minute |
116897
+ * | 40 secs ... 60 secs | less than a minute |
116898
+ * | 60 secs ... 90 secs | 1 minute |
116899
+ *
116900
+ * @param laterDate - The date
116901
+ * @param earlierDate - The date to compare with
116902
+ * @param options - An object with options
116903
+ *
116904
+ * @returns The distance in words
116905
+ *
116906
+ * @throws `date` must not be Invalid Date
116907
+ * @throws `baseDate` must not be Invalid Date
116908
+ * @throws `options.locale` must contain `formatDistance` property
116909
+ *
116910
+ * @example
116911
+ * // What is the distance between 2 July 2014 and 1 January 2015?
116912
+ * const result = formatDistance(new Date(2014, 6, 2), new Date(2015, 0, 1))
116913
+ * //=> '6 months'
116914
+ *
116915
+ * @example
116916
+ * // What is the distance between 1 January 2015 00:00:15
116917
+ * // and 1 January 2015 00:00:00, including seconds?
116918
+ * const result = formatDistance(
116919
+ * new Date(2015, 0, 1, 0, 0, 15),
116920
+ * new Date(2015, 0, 1, 0, 0, 0),
116921
+ * { includeSeconds: true }
116922
+ * )
116923
+ * //=> 'less than 20 seconds'
116924
+ *
116925
+ * @example
116926
+ * // What is the distance from 1 January 2016
116927
+ * // to 1 January 2015, with a suffix?
116928
+ * const result = formatDistance(new Date(2015, 0, 1), new Date(2016, 0, 1), {
116929
+ * addSuffix: true
116930
+ * })
116931
+ * //=> 'about 1 year ago'
116932
+ *
116933
+ * @example
116934
+ * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto?
116935
+ * import { eoLocale } from 'date-fns/locale/eo'
116936
+ * const result = formatDistance(new Date(2016, 7, 1), new Date(2015, 0, 1), {
116937
+ * locale: eoLocale
116938
+ * })
116939
+ * //=> 'pli ol 1 jaro'
116940
+ */
116941
+ function formatDistance(laterDate, earlierDate, options) {
116942
+ const defaultOptions = getDefaultOptions();
116943
+ const locale = options?.locale ?? defaultOptions.locale ?? enUS;
116944
+ const minutesInAlmostTwoDays = 2520;
116945
+
116946
+ const comparison = compareAsc(laterDate, earlierDate);
116947
+
116948
+ if (isNaN(comparison)) throw new RangeError("Invalid time value");
116949
+
116950
+ const localizeOptions = Object.assign({}, options, {
116951
+ addSuffix: options?.addSuffix,
116952
+ comparison: comparison,
116953
+ });
116954
+
116955
+ const [laterDate_, earlierDate_] = normalizeDates(
116956
+ options?.in,
116957
+ ...(comparison > 0 ? [earlierDate, laterDate] : [laterDate, earlierDate]),
116958
+ );
116959
+
116960
+ const seconds = differenceInSeconds(earlierDate_, laterDate_);
116961
+ const offsetInSeconds =
116962
+ (getTimezoneOffsetInMilliseconds(earlierDate_) -
116963
+ getTimezoneOffsetInMilliseconds(laterDate_)) /
116964
+ 1000;
116965
+ const minutes = Math.round((seconds - offsetInSeconds) / 60);
116966
+ let months;
116967
+
116968
+ // 0 up to 2 mins
116969
+ if (minutes < 2) {
116970
+ if (options?.includeSeconds) {
116971
+ if (seconds < 5) {
116972
+ return locale.formatDistance("lessThanXSeconds", 5, localizeOptions);
116973
+ } else if (seconds < 10) {
116974
+ return locale.formatDistance("lessThanXSeconds", 10, localizeOptions);
116975
+ } else if (seconds < 20) {
116976
+ return locale.formatDistance("lessThanXSeconds", 20, localizeOptions);
116977
+ } else if (seconds < 40) {
116978
+ return locale.formatDistance("halfAMinute", 0, localizeOptions);
116979
+ } else if (seconds < 60) {
116980
+ return locale.formatDistance("lessThanXMinutes", 1, localizeOptions);
116981
+ } else {
116982
+ return locale.formatDistance("xMinutes", 1, localizeOptions);
116983
+ }
116984
+ } else {
116985
+ if (minutes === 0) {
116986
+ return locale.formatDistance("lessThanXMinutes", 1, localizeOptions);
116987
+ } else {
116988
+ return locale.formatDistance("xMinutes", minutes, localizeOptions);
116989
+ }
116990
+ }
116991
+
116992
+ // 2 mins up to 0.75 hrs
116993
+ } else if (minutes < 45) {
116994
+ return locale.formatDistance("xMinutes", minutes, localizeOptions);
116995
+
116996
+ // 0.75 hrs up to 1.5 hrs
116997
+ } else if (minutes < 90) {
116998
+ return locale.formatDistance("aboutXHours", 1, localizeOptions);
116999
+
117000
+ // 1.5 hrs up to 24 hrs
117001
+ } else if (minutes < minutesInDay) {
117002
+ const hours = Math.round(minutes / 60);
117003
+ return locale.formatDistance("aboutXHours", hours, localizeOptions);
117004
+
117005
+ // 1 day up to 1.75 days
117006
+ } else if (minutes < minutesInAlmostTwoDays) {
117007
+ return locale.formatDistance("xDays", 1, localizeOptions);
117008
+
117009
+ // 1.75 days up to 30 days
117010
+ } else if (minutes < minutesInMonth) {
117011
+ const days = Math.round(minutes / minutesInDay);
117012
+ return locale.formatDistance("xDays", days, localizeOptions);
117013
+
117014
+ // 1 month up to 2 months
117015
+ } else if (minutes < minutesInMonth * 2) {
117016
+ months = Math.round(minutes / minutesInMonth);
117017
+ return locale.formatDistance("aboutXMonths", months, localizeOptions);
117018
+ }
117019
+
117020
+ months = differenceInMonths(earlierDate_, laterDate_);
117021
+
117022
+ // 2 months up to 12 months
117023
+ if (months < 12) {
117024
+ const nearestMonth = Math.round(minutes / minutesInMonth);
117025
+ return locale.formatDistance("xMonths", nearestMonth, localizeOptions);
117026
+
117027
+ // 1 year up to max Date
117028
+ } else {
117029
+ const monthsSinceStartOfYear = months % 12;
117030
+ const years = Math.trunc(months / 12);
117031
+
117032
+ // N years up to 1 years 3 months
117033
+ if (monthsSinceStartOfYear < 3) {
117034
+ return locale.formatDistance("aboutXYears", years, localizeOptions);
117035
+
117036
+ // N years 3 months up to N years 9 months
117037
+ } else if (monthsSinceStartOfYear < 9) {
117038
+ return locale.formatDistance("overXYears", years, localizeOptions);
117039
+
117040
+ // N years 9 months up to N year 12 months
117041
+ } else {
117042
+ return locale.formatDistance("almostXYears", years + 1, localizeOptions);
117043
+ }
117044
+ }
117045
+ }
117046
+
117047
+ /**
117048
+ * The {@link formatDistanceToNow} function options.
117049
+ */
117050
+
117051
+ /**
117052
+ * @name formatDistanceToNow
117053
+ * @category Common Helpers
117054
+ * @summary Return the distance between the given date and now in words.
117055
+ * @pure false
117056
+ *
117057
+ * @description
117058
+ * Return the distance between the given date and now in words.
117059
+ *
117060
+ * | Distance to now | Result |
117061
+ * |-------------------------------------------------------------------|---------------------|
117062
+ * | 0 ... 30 secs | less than a minute |
117063
+ * | 30 secs ... 1 min 30 secs | 1 minute |
117064
+ * | 1 min 30 secs ... 44 mins 30 secs | [2..44] minutes |
117065
+ * | 44 mins ... 30 secs ... 89 mins 30 secs | about 1 hour |
117066
+ * | 89 mins 30 secs ... 23 hrs 59 mins 30 secs | about [2..24] hours |
117067
+ * | 23 hrs 59 mins 30 secs ... 41 hrs 59 mins 30 secs | 1 day |
117068
+ * | 41 hrs 59 mins 30 secs ... 29 days 23 hrs 59 mins 30 secs | [2..30] days |
117069
+ * | 29 days 23 hrs 59 mins 30 secs ... 44 days 23 hrs 59 mins 30 secs | about 1 month |
117070
+ * | 44 days 23 hrs 59 mins 30 secs ... 59 days 23 hrs 59 mins 30 secs | about 2 months |
117071
+ * | 59 days 23 hrs 59 mins 30 secs ... 1 yr | [2..12] months |
117072
+ * | 1 yr ... 1 yr 3 months | about 1 year |
117073
+ * | 1 yr 3 months ... 1 yr 9 month s | over 1 year |
117074
+ * | 1 yr 9 months ... 2 yrs | almost 2 years |
117075
+ * | N yrs ... N yrs 3 months | about N years |
117076
+ * | N yrs 3 months ... N yrs 9 months | over N years |
117077
+ * | N yrs 9 months ... N+1 yrs | almost N+1 years |
117078
+ *
117079
+ * With `options.includeSeconds == true`:
117080
+ * | Distance to now | Result |
117081
+ * |---------------------|----------------------|
117082
+ * | 0 secs ... 5 secs | less than 5 seconds |
117083
+ * | 5 secs ... 10 secs | less than 10 seconds |
117084
+ * | 10 secs ... 20 secs | less than 20 seconds |
117085
+ * | 20 secs ... 40 secs | half a minute |
117086
+ * | 40 secs ... 60 secs | less than a minute |
117087
+ * | 60 secs ... 90 secs | 1 minute |
117088
+ *
117089
+ * @param date - The given date
117090
+ * @param options - The object with options
117091
+ *
117092
+ * @returns The distance in words
117093
+ *
117094
+ * @throws `date` must not be Invalid Date
117095
+ * @throws `options.locale` must contain `formatDistance` property
117096
+ *
117097
+ * @example
117098
+ * // If today is 1 January 2015, what is the distance to 2 July 2014?
117099
+ * const result = formatDistanceToNow(
117100
+ * new Date(2014, 6, 2)
117101
+ * )
117102
+ * //=> '6 months'
117103
+ *
117104
+ * @example
117105
+ * // If now is 1 January 2015 00:00:00,
117106
+ * // what is the distance to 1 January 2015 00:00:15, including seconds?
117107
+ * const result = formatDistanceToNow(
117108
+ * new Date(2015, 0, 1, 0, 0, 15),
117109
+ * {includeSeconds: true}
117110
+ * )
117111
+ * //=> 'less than 20 seconds'
117112
+ *
117113
+ * @example
117114
+ * // If today is 1 January 2015,
117115
+ * // what is the distance to 1 January 2016, with a suffix?
117116
+ * const result = formatDistanceToNow(
117117
+ * new Date(2016, 0, 1),
117118
+ * {addSuffix: true}
117119
+ * )
117120
+ * //=> 'in about 1 year'
117121
+ *
117122
+ * @example
117123
+ * // If today is 1 January 2015,
117124
+ * // what is the distance to 1 August 2016 in Esperanto?
117125
+ * const eoLocale = require('date-fns/locale/eo')
117126
+ * const result = formatDistanceToNow(
117127
+ * new Date(2016, 7, 1),
117128
+ * {locale: eoLocale}
117129
+ * )
117130
+ * //=> 'pli ol 1 jaro'
117131
+ */
117132
+ function formatDistanceToNow(date, options) {
117133
+ return formatDistance(date, constructNow(date), options);
117134
+ }
117135
+
116595
117136
  /**
116596
117137
  * The {@link getDaysInMonth} function options.
116597
117138
  */
@@ -149893,7 +150434,7 @@ const defaultTabs = [
149893
150434
  },
149894
150435
  {
149895
150436
  label: 'Audit',
149896
- value: 'audit-log',
150437
+ value: 'audit',
149897
150438
  },
149898
150439
  /*{
149899
150440
  label: 'Monetization',
@@ -149923,8 +150464,8 @@ function AnalyticsLayout({ children, currentPath, basePath, onTabChange, tabs =
149923
150464
  return 'transcripts';
149924
150465
  if (path === `${basePath}/financial`)
149925
150466
  return 'financial';
149926
- if (path === `${basePath}/audit-log`)
149927
- return 'audit-log';
150467
+ if (path === `${basePath}/audit`)
150468
+ return 'audit';
149928
150469
  if (path === `${basePath}/monetization`)
149929
150470
  return 'monetization';
149930
150471
  if (path === `${basePath}/reports`)
@@ -187607,7 +188148,7 @@ const useAuditLog = ({ tenantKey, userId, mentorId, }) => {
187607
188148
  offset: (page - 1) * limit,
187608
188149
  ...(mentorId ? { mentor: mentorId } : {}),
187609
188150
  ...(actionFilter !== undefined ? { action: actionFilter } : {}),
187610
- ...(actorFilter ? { actor_username: actorFilter } : {}),
188151
+ ...(actorFilter ? { actor_email: actorFilter } : {}),
187611
188152
  ...((dateRange === null || dateRange === void 0 ? void 0 : dateRange.from) ? { from_date: formatDateToYYYYMMDD(dateRange.from) } : {}),
187612
188153
  ...((dateRange === null || dateRange === void 0 ? void 0 : dateRange.to) ? { to_date: formatDateToYYYYMMDD(dateRange.to) } : {}),
187613
188154
  };
@@ -187646,9 +188187,6 @@ const ACTION_FILTER_OPTIONS = [
187646
188187
  { label: 'Update', value: '1' },
187647
188188
  { label: 'Delete', value: '2' },
187648
188189
  ];
187649
- function formatTimestamp(timestamp) {
187650
- return format$1(new Date(timestamp), 'MMM dd, yyyy h:mm a');
187651
- }
187652
188190
  function summarizeChanges(entry) {
187653
188191
  const action = ACTION_LABELS[entry.action] || entry.action;
187654
188192
  const resourceType = entry.resource_type === 'mentorsettings' ? 'mentor settings' : entry.resource_type;
@@ -187678,9 +188216,7 @@ function AnalyticsAuditLogStats({ tenantKey, mentorId, userId, selectedMentorId,
187678
188216
  if (!(data === null || data === void 0 ? void 0 : data.results))
187679
188217
  return [];
187680
188218
  const unique = [
187681
- ...new Set(data.results
187682
- .map((e) => e.actor_username)
187683
- .filter((username) => !!username)),
188219
+ ...new Set(data.results.map((e) => e.actor_email).filter((email) => !!email)),
187684
188220
  ];
187685
188221
  return unique.sort();
187686
188222
  }, [data === null || data === void 0 ? void 0 : data.results]);
@@ -187688,7 +188224,7 @@ function AnalyticsAuditLogStats({ tenantKey, mentorId, userId, selectedMentorId,
187688
188224
  if (is403) {
187689
188225
  return (jsx(Card, { className: "bg-white rounded-lg border border-gray-100 shadow-sm", children: jsx(CardContent, { className: "p-8 text-center", children: jsx("p", { className: "text-gray-500", children: "You do not have permission to view audit logs." }) }) }));
187690
188226
  }
187691
- return (jsxs("div", { className: "space-y-6", children: [jsx("div", { className: "border rounded-lg p-4 bg-white", children: jsxs("div", { className: "flex flex-col lg:flex-row gap-3", children: [jsx("div", { className: "relative flex-1 min-w-[200px]", children: jsxs(Popover, { open: actorOpen, onOpenChange: setActorOpen, children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button$1, { variant: "outline", role: "combobox", "aria-expanded": actorOpen, "aria-label": "Search for User", className: "w-full justify-between font-normal bg-white h-9", children: [actorFilter || 'Search for User', jsx(ChevronsUpDown, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })] }) }), jsx(PopoverContent, { className: "w-full p-0", align: "start", children: jsxs(Command, { children: [jsx(CommandInput, { placeholder: "Search user..." }), jsxs(CommandList, { children: [jsx(CommandEmpty, { children: "No users found." }), jsxs(CommandGroup, { children: [jsxs(CommandItem, { value: "", onSelect: () => {
188227
+ return (jsxs("div", { className: "space-y-6", children: [jsx("div", { className: "border rounded-lg p-4 bg-white", children: jsxs("div", { className: "flex flex-col lg:flex-row gap-3", children: [jsx("div", { className: "relative flex-1 min-w-[200px]", children: jsxs(Popover, { modal: true, open: actorOpen, onOpenChange: setActorOpen, children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button$1, { variant: "outline", role: "combobox", "aria-expanded": actorOpen, "aria-label": "Search for User", className: "w-full justify-between font-normal bg-white h-9", children: [actorFilter || 'Search for User', jsx(ChevronsUpDown, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })] }) }), jsx(PopoverContent, { className: "w-full p-0", align: "start", children: jsxs(Command, { children: [jsx(CommandInput, { placeholder: "Search user..." }), jsxs(CommandList, { children: [jsx(CommandEmpty, { children: "No users found." }), jsxs(CommandGroup, { children: [jsxs(CommandItem, { value: "", onSelect: () => {
187692
188228
  setActorFilter('');
187693
188229
  setActorOpen(false);
187694
188230
  setPage(1);
@@ -187696,7 +188232,7 @@ function AnalyticsAuditLogStats({ tenantKey, mentorId, userId, selectedMentorId,
187696
188232
  setActorFilter(actor);
187697
188233
  setActorOpen(false);
187698
188234
  setPage(1);
187699
- }, children: [jsx(Check, { className: cn('mr-2 h-4 w-4', actorFilter === actor ? 'opacity-100' : 'opacity-0') }), jsx("span", { className: "font-medium text-gray-700", children: actor })] }, actor)))] })] })] }) })] }) }), jsxs(Popover, { children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button$1, { variant: "outline", className: "flex items-center gap-2 whitespace-nowrap font-normal bg-white w-full lg:w-auto h-9", children: [jsx(Calendar$1, { className: "h-4 w-4" }), (dateRange === null || dateRange === void 0 ? void 0 : dateRange.from) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.to)
188235
+ }, children: [jsx(Check, { className: cn('mr-2 h-4 w-4', actorFilter === actor ? 'opacity-100' : 'opacity-0') }), jsx("span", { className: "font-medium text-gray-700", children: actor })] }, actor)))] })] })] }) })] }) }), jsxs(Popover, { modal: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button$1, { variant: "outline", className: "flex items-center gap-2 whitespace-nowrap font-normal bg-white w-full lg:w-auto h-9", children: [jsx(Calendar$1, { className: "h-4 w-4" }), (dateRange === null || dateRange === void 0 ? void 0 : dateRange.from) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.to)
187700
188236
  ? `${format$1(dateRange.from, 'MMM dd')} - ${format$1(dateRange.to, 'MMM dd')}`
187701
188237
  : 'Pick a Date Range'] }) }), jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: jsx(Calendar, { mode: "range", selected: dateRange, onSelect: (range) => {
187702
188238
  setDateRange(range ? { from: range.from, to: range.to } : undefined);
@@ -187704,7 +188240,7 @@ function AnalyticsAuditLogStats({ tenantKey, mentorId, userId, selectedMentorId,
187704
188240
  }, numberOfMonths: 2 }) })] }), jsx("div", { className: "min-w-[160px]", children: jsxs(Select$1, { value: actionFilter !== undefined ? String(actionFilter) : 'all', onValueChange: (val) => {
187705
188241
  setActionFilter(val === 'all' ? undefined : Number(val));
187706
188242
  setPage(1);
187707
- }, children: [jsx(SelectTrigger, { className: "w-full font-normal bg-white h-9", children: jsx(SelectValue, { placeholder: "All Actions" }) }), jsx(SelectContent, { children: ACTION_FILTER_OPTIONS.map((opt) => (jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))) })] }) })] }) }), jsx("div", { className: "overflow-hidden rounded-md border bg-white", children: jsx("div", { className: "overflow-x-auto", children: jsx("div", { className: "inline-block min-w-full align-middle", children: isLoading ? (jsx("div", { className: "flex items-center justify-center w-full py-10", children: jsx("div", { className: "h-6 w-6 animate-spin rounded-full border-2 border-blue-600 border-t-transparent" }) })) : error && !is403 ? (jsx("div", { className: "py-8 text-center text-[#646464]", children: "An error occurred while loading audit logs." })) : !((_a = data === null || data === void 0 ? void 0 : data.results) === null || _a === void 0 ? void 0 : _a.length) ? (jsx("div", { className: "h-[120px]", children: jsx(EmptyStats, { title: "No audit log entries found for this tenant." }) })) : (jsxs(Table, { className: "min-w-full", children: [jsx(TableHeader, { children: jsxs(TableRow, { className: "bg-muted/50 border-b", children: [jsx(TableHead, { className: "p-3 text-left text-sm whitespace-nowrap text-[#646464]", children: "USER" }), jsx(TableHead, { className: "p-3 text-left text-sm whitespace-nowrap text-[#646464]", children: "ACTION" }), jsx(TableHead, { className: "p-3 text-left text-sm whitespace-nowrap text-[#646464]", children: "TIMESTAMP" })] }) }), jsx(TableBody, { children: data.results.map((entry) => (jsxs(TableRow, { className: "border-b last:border-0", children: [jsx(TableCell, { className: "p-3 font-medium whitespace-nowrap text-[#646464]", children: entry.actor_username }), jsx(TableCell, { className: "p-3 whitespace-nowrap text-[#646464]", children: summarizeChanges(entry) }), jsx(TableCell, { className: "p-3 whitespace-nowrap text-[#646464]", children: formatTimestamp(entry.timestamp) })] }, entry.id))) })] })) }) }) }), jsx(IblPagination, { currentPage: page, totalPages: totalPages, onPageChange: setPage, disabled: isLoading })] }));
188243
+ }, children: [jsx(SelectTrigger, { className: "w-full font-normal bg-white h-9", children: jsx(SelectValue, { placeholder: "All Actions" }) }), jsx(SelectContent, { children: ACTION_FILTER_OPTIONS.map((opt) => (jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))) })] }) })] }) }), jsx("div", { className: "overflow-hidden rounded-md border bg-white", children: jsx("div", { className: "overflow-x-auto", children: jsx("div", { className: "inline-block min-w-full align-middle", children: isLoading ? (jsx("div", { className: "flex items-center justify-center w-full py-10", children: jsx("div", { className: "h-6 w-6 animate-spin rounded-full border-2 border-blue-600 border-t-transparent" }) })) : error && !is403 ? (jsx("div", { className: "py-8 text-center text-[#646464]", children: "An error occurred while loading audit logs." })) : !((_a = data === null || data === void 0 ? void 0 : data.results) === null || _a === void 0 ? void 0 : _a.length) ? (jsx("div", { className: "h-[120px]", children: jsx(EmptyStats, { title: "No audit log entries found for this tenant." }) })) : (jsxs(Table, { className: "min-w-full", children: [jsx(TableHeader, { children: jsxs(TableRow, { className: "bg-muted/50 border-b", children: [jsx(TableHead, { className: "p-3 text-left text-sm whitespace-nowrap text-[#646464]", children: "USER" }), jsx(TableHead, { className: "p-3 text-left text-sm whitespace-nowrap text-[#646464]", children: "ACTION" }), jsx(TableHead, { className: "p-3 text-left text-sm whitespace-nowrap text-[#646464]", children: "TIME" })] }) }), jsx(TableBody, { children: data.results.map((entry) => (jsxs(TableRow, { className: "border-b last:border-0", children: [jsx(TableCell, { className: "p-3 font-medium whitespace-nowrap text-[#646464]", children: entry.actor_email }), jsx(TableCell, { className: "min-w-[250px] p-3 text-[#646464]", children: summarizeChanges(entry) }), jsx(TableCell, { className: "p-3 whitespace-nowrap text-[#646464]", children: formatDistanceToNow(new Date(entry.timestamp), { addSuffix: true }) })] }, entry.id))) })] })) }) }) }), jsx(IblPagination, { currentPage: page, totalPages: totalPages, onPageChange: setPage, disabled: isLoading })] }));
187708
188244
  }
187709
188245
 
187710
188246
  const SkeletonMultiplier = ({ Skeleton, multiplier }) => {