akeyless-client-commons 1.1.39 → 1.1.40

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.
@@ -236,7 +236,11 @@ interface TimeOptions {
236
236
  defaultReturnedValue?: string;
237
237
  }
238
238
  declare function timestamp_to_string(firebaseTimestamp: Timestamp | Date | string | firebase_timestamp, options?: TimeOptions): string;
239
- declare function timestamp_to_millis(firebaseTimestamp: Timestamp): number;
239
+ declare function timestamp_to_millis(firebaseTimestamp: Timestamp | Date | string | firebase_timestamp, options?: {
240
+ fromFormat?: string;
241
+ tz?: string;
242
+ defaultReturnedValue?: number;
243
+ }): number;
240
244
  declare function sort_by_timestamp(a: Timestamp, b: Timestamp, reverse?: boolean): number;
241
245
 
242
246
  declare const baseDomain: string;
@@ -236,7 +236,11 @@ interface TimeOptions {
236
236
  defaultReturnedValue?: string;
237
237
  }
238
238
  declare function timestamp_to_string(firebaseTimestamp: Timestamp | Date | string | firebase_timestamp, options?: TimeOptions): string;
239
- declare function timestamp_to_millis(firebaseTimestamp: Timestamp): number;
239
+ declare function timestamp_to_millis(firebaseTimestamp: Timestamp | Date | string | firebase_timestamp, options?: {
240
+ fromFormat?: string;
241
+ tz?: string;
242
+ defaultReturnedValue?: number;
243
+ }): number;
240
244
  declare function sort_by_timestamp(a: Timestamp, b: Timestamp, reverse?: boolean): number;
241
245
 
242
246
  declare const baseDomain: string;
@@ -2367,12 +2367,32 @@ function timestamp_to_string(firebaseTimestamp, options) {
2367
2367
  }
2368
2368
  return import_moment_timezone.default.utc(date).format(format);
2369
2369
  }
2370
- function timestamp_to_millis(firebaseTimestamp) {
2370
+ function timestamp_to_millis(firebaseTimestamp, options) {
2371
+ var _options_fromFormat;
2372
+ var fromFormat = (_options_fromFormat = options === null || options === void 0 ? void 0 : options.fromFormat) !== null && _options_fromFormat !== void 0 ? _options_fromFormat : "DD/MM/YYYY HH:mm:ss";
2373
+ var _options_defaultReturnedValue;
2374
+ var defaultReturnedValue = (_options_defaultReturnedValue = options === null || options === void 0 ? void 0 : options.defaultReturnedValue) !== null && _options_defaultReturnedValue !== void 0 ? _options_defaultReturnedValue : 0;
2375
+ var tz = options === null || options === void 0 ? void 0 : options.tz;
2371
2376
  if (!firebaseTimestamp) {
2372
- return 0;
2377
+ return defaultReturnedValue;
2378
+ }
2379
+ if (_instanceof(firebaseTimestamp, import_firestore2.Timestamp)) {
2380
+ return firebaseTimestamp.toMillis();
2381
+ } else if (_instanceof(firebaseTimestamp, Date)) {
2382
+ var ms = firebaseTimestamp.getTime();
2383
+ return isNaN(ms) ? defaultReturnedValue : ms;
2384
+ } else if (typeof firebaseTimestamp === "string") {
2385
+ var m = tz ? import_moment_timezone.default.tz(firebaseTimestamp, fromFormat, tz) : import_moment_timezone.default.utc(firebaseTimestamp, fromFormat);
2386
+ return m.isValid() ? m.valueOf() : defaultReturnedValue;
2387
+ } else if (firebaseTimestamp._seconds) {
2388
+ var seconds = firebaseTimestamp._seconds;
2389
+ var _firebaseTimestamp__nanoseconds;
2390
+ var nanos = (_firebaseTimestamp__nanoseconds = firebaseTimestamp._nanoseconds) !== null && _firebaseTimestamp__nanoseconds !== void 0 ? _firebaseTimestamp__nanoseconds : 0;
2391
+ return seconds * 1e3 + Math.floor(nanos / 1e6);
2392
+ } else {
2393
+ console.error("Invalid timestamp format: ", firebaseTimestamp);
2394
+ return defaultReturnedValue;
2373
2395
  }
2374
- var timestamp = new import_firestore2.Timestamp(firebaseTimestamp === null || firebaseTimestamp === void 0 ? void 0 : firebaseTimestamp.seconds, firebaseTimestamp === null || firebaseTimestamp === void 0 ? void 0 : firebaseTimestamp.nanoseconds);
2375
- return timestamp.toMillis();
2376
2396
  }
2377
2397
  function sort_by_timestamp(a, b) {
2378
2398
  var reverse = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
@@ -1988,12 +1988,32 @@ function timestamp_to_string(firebaseTimestamp, options) {
1988
1988
  }
1989
1989
  return moment2.utc(date).format(format);
1990
1990
  }
1991
- function timestamp_to_millis(firebaseTimestamp) {
1991
+ function timestamp_to_millis(firebaseTimestamp, options) {
1992
+ var _options_fromFormat;
1993
+ var fromFormat = (_options_fromFormat = options === null || options === void 0 ? void 0 : options.fromFormat) !== null && _options_fromFormat !== void 0 ? _options_fromFormat : "DD/MM/YYYY HH:mm:ss";
1994
+ var _options_defaultReturnedValue;
1995
+ var defaultReturnedValue = (_options_defaultReturnedValue = options === null || options === void 0 ? void 0 : options.defaultReturnedValue) !== null && _options_defaultReturnedValue !== void 0 ? _options_defaultReturnedValue : 0;
1996
+ var tz = options === null || options === void 0 ? void 0 : options.tz;
1992
1997
  if (!firebaseTimestamp) {
1993
- return 0;
1998
+ return defaultReturnedValue;
1999
+ }
2000
+ if (_instanceof(firebaseTimestamp, Timestamp2)) {
2001
+ return firebaseTimestamp.toMillis();
2002
+ } else if (_instanceof(firebaseTimestamp, Date)) {
2003
+ var ms = firebaseTimestamp.getTime();
2004
+ return isNaN(ms) ? defaultReturnedValue : ms;
2005
+ } else if (typeof firebaseTimestamp === "string") {
2006
+ var m = tz ? moment2.tz(firebaseTimestamp, fromFormat, tz) : moment2.utc(firebaseTimestamp, fromFormat);
2007
+ return m.isValid() ? m.valueOf() : defaultReturnedValue;
2008
+ } else if (firebaseTimestamp._seconds) {
2009
+ var seconds = firebaseTimestamp._seconds;
2010
+ var _firebaseTimestamp__nanoseconds;
2011
+ var nanos = (_firebaseTimestamp__nanoseconds = firebaseTimestamp._nanoseconds) !== null && _firebaseTimestamp__nanoseconds !== void 0 ? _firebaseTimestamp__nanoseconds : 0;
2012
+ return seconds * 1e3 + Math.floor(nanos / 1e6);
2013
+ } else {
2014
+ console.error("Invalid timestamp format: ", firebaseTimestamp);
2015
+ return defaultReturnedValue;
1994
2016
  }
1995
- var timestamp = new Timestamp2(firebaseTimestamp === null || firebaseTimestamp === void 0 ? void 0 : firebaseTimestamp.seconds, firebaseTimestamp === null || firebaseTimestamp === void 0 ? void 0 : firebaseTimestamp.nanoseconds);
1996
- return timestamp.toMillis();
1997
2017
  }
1998
2018
  function sort_by_timestamp(a, b) {
1999
2019
  var reverse = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-client-commons",
3
- "version": "1.1.39",
3
+ "version": "1.1.40",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",