@tstdl/base 0.93.152 → 0.93.153

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.
@@ -57,7 +57,7 @@ export declare class AuthenticationServiceOptions {
57
57
  /**
58
58
  * How long a refresh token is valid in milliseconds. Implies session time to live.
59
59
  *
60
- * @default 5 days
60
+ * @default 1 hour
61
61
  */
62
62
  refreshTokenTimeToLive?: number;
63
63
  /**
@@ -28,7 +28,7 @@ import { createJwtTokenString } from '../../utils/jwt.js';
28
28
  import { isUuid } from '../../utils/patterns.js';
29
29
  import { getRandomBytes, getRandomString } from '../../utils/random.js';
30
30
  import { isBinaryData, isDefined, isString, isUndefined } from '../../utils/type-guards.js';
31
- import { millisecondsPerDay, millisecondsPerMinute } from '../../utils/units.js';
31
+ import { millisecondsPerDay, millisecondsPerHour, millisecondsPerMinute } from '../../utils/units.js';
32
32
  import { AuthenticationCredentials, AuthenticationSession, Subject, User } from '../models/index.js';
33
33
  import { AuthenticationAncillaryService, GetTokenPayloadContextAction } from './authentication-ancillary.service.js';
34
34
  import { AuthenticationSecretRequirementsValidator } from './authentication-secret-requirements.validator.js';
@@ -55,7 +55,7 @@ export class AuthenticationServiceOptions {
55
55
  /**
56
56
  * How long a refresh token is valid in milliseconds. Implies session time to live.
57
57
  *
58
- * @default 5 days
58
+ * @default 1 hour
59
59
  */
60
60
  refreshTokenTimeToLive;
61
61
  /**
@@ -126,7 +126,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
126
126
  };
127
127
  tokenVersion = this.#options.version ?? 1;
128
128
  tokenTimeToLive = this.#options.tokenTimeToLive ?? (5 * millisecondsPerMinute);
129
- refreshTokenTimeToLive = this.#options.refreshTokenTimeToLive ?? (5 * millisecondsPerDay);
129
+ refreshTokenTimeToLive = this.#options.refreshTokenTimeToLive ?? (1 * millisecondsPerHour);
130
130
  rememberRefreshTokenTimeToLive = this.#options.rememberRefreshTokenTimeToLive ?? (30 * millisecondsPerDay);
131
131
  secretResetTokenTimeToLive = this.#options.secretResetTokenTimeToLive ?? (10 * millisecondsPerMinute);
132
132
  derivedTokenSigningSecret;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.152",
3
+ "version": "0.93.153",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,4 +1,6 @@
1
- type ErrorData = Pick<Error, 'name' | 'message' | 'stack'>;
1
+ type ErrorData = Pick<Error, 'name' | 'message' | 'stack'> & {
2
+ cause?: ErrorData;
3
+ };
2
4
  export declare function serializeError(error: Error): ErrorData;
3
5
  export declare function deserializeError(data: ErrorData): Error;
4
6
  export {};
@@ -1,9 +1,19 @@
1
+ import { formatError } from '../../errors/format.js';
2
+ import { isDefined, isError, isString } from '../../utils/type-guards.js';
1
3
  export function serializeError(error) {
2
- return { name: error.name, message: error.message, stack: error.stack };
4
+ const cause = isError(error.cause)
5
+ ? serializeError(error.cause)
6
+ : isString(error.cause)
7
+ ? { name: 'Error', message: error.cause, stack: undefined }
8
+ : isDefined(error.cause)
9
+ ? { name: 'Error', message: formatError(error.cause), stack: undefined }
10
+ : undefined;
11
+ return { name: error.name, message: error.message, stack: error.stack, cause };
3
12
  }
4
13
  export function deserializeError(data) {
5
14
  const error = new Error(data.message);
6
15
  error.name = data.name;
7
16
  error.stack = data.stack;
17
+ error.cause = isDefined(data.cause) ? deserializeError(data.cause) : undefined;
8
18
  return error;
9
19
  }
@@ -2,4 +2,5 @@ export * from './enqueue-batch.js';
2
2
  export * from './provider.js';
3
3
  export * from './task-context.js';
4
4
  export * from './task-queue.js';
5
+ export * from './task.error.js';
5
6
  export * from './types.js';
@@ -2,4 +2,5 @@ export * from './enqueue-batch.js';
2
2
  export * from './provider.js';
3
3
  export * from './task-context.js';
4
4
  export * from './task-queue.js';
5
+ export * from './task.error.js';
5
6
  export * from './types.js';
@@ -103,7 +103,7 @@ export declare class PostgresTaskQueue<Definitions extends TaskDefinitionMap = T
103
103
  results?: TasksResults<Tasks>;
104
104
  transaction?: Transaction;
105
105
  }): Promise<void>;
106
- fail(task: Task<Definitions>, error: unknown, options?: {
106
+ fail(task: Task<Definitions>, caughtError: unknown, options?: {
107
107
  fatal?: boolean;
108
108
  transaction?: Transaction;
109
109
  }): Promise<void>;
@@ -74,6 +74,7 @@ import { cancelableTimeout } from '../../utils/timing.js';
74
74
  import { isArray, isDefined, isNotNull, isNull, isNumber, isString, isUndefined } from '../../utils/type-guards.js';
75
75
  import { millisecondsPerMinute, millisecondsPerSecond } from '../../utils/units.js';
76
76
  import { defaultQueueConfig, queueableOrWaitableStatuses, queueableStatuses, TaskDependencyType, TaskQueue, TaskStatus, terminalStatuses } from '../task-queue.js';
77
+ import { ensureTaskError } from '../task.error.js';
77
78
  import { PostgresTaskQueueModuleConfig } from './module.js';
78
79
  import { taskArchive as taskArchiveTable, taskDependency as taskDependencyTable, taskDependencyType, taskStatus, task as taskTable } from './schemas.js';
79
80
  import { PostgresTask, PostgresTaskArchive } from './task.model.js';
@@ -849,7 +850,8 @@ let PostgresTaskQueue = class PostgresTaskQueue extends TaskQueue {
849
850
  }
850
851
  });
851
852
  }
852
- async fail(task, error, options) {
853
+ async fail(task, caughtError, options) {
854
+ const error = ensureTaskError(caughtError);
853
855
  const isRetryable = (options?.fatal != true) && (task.tries < this.maxTries);
854
856
  const nextStatus = isRetryable ? TaskStatus.Retrying : TaskStatus.Dead;
855
857
  const delay = isRetryable
@@ -883,7 +885,7 @@ let PostgresTaskQueue = class PostgresTaskQueue extends TaskQueue {
883
885
  }
884
886
  await this.#repository.useTransaction(options?.transaction, async (tx) => {
885
887
  const rows = tasks.map((task, index) => {
886
- const error = errors[index];
888
+ const error = ensureTaskError(errors[index]);
887
889
  const isRetryable = (task.tries < this.maxTries);
888
890
  const nextStatus = isRetryable ? TaskStatus.Retrying : TaskStatus.Dead;
889
891
  const delay = isRetryable
@@ -0,0 +1,7 @@
1
+ import { CustomError, type CustomErrorOptions } from '../errors/custom.error.js';
2
+ import type { TypedOmit } from '../types/types.js';
3
+ export declare class TaskError extends CustomError {
4
+ static readonly errorName = "TaskError";
5
+ constructor(message: string, options?: TypedOmit<CustomErrorOptions, 'message' | 'cause'>);
6
+ }
7
+ export declare function ensureTaskError(error: unknown): Error;
@@ -0,0 +1,18 @@
1
+ import { CustomError } from '../errors/custom.error.js';
2
+ import { formatError } from '../errors/format.js';
3
+ import { isString } from '../utils/type-guards.js';
4
+ export class TaskError extends CustomError {
5
+ static errorName = 'TaskError';
6
+ constructor(message, options) {
7
+ super({ message, ...options });
8
+ }
9
+ }
10
+ export function ensureTaskError(error) {
11
+ if (error instanceof Error) {
12
+ return error;
13
+ }
14
+ if (isString(error)) {
15
+ return new TaskError(error, undefined);
16
+ }
17
+ return new TaskError(`A task error occurred: ${formatError(error)}`);
18
+ }