@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.
- package/authentication/server/authentication.service.d.ts +1 -1
- package/authentication/server/authentication.service.js +3 -3
- package/package.json +1 -1
- package/serializer/handlers/error.d.ts +3 -1
- package/serializer/handlers/error.js +11 -1
- package/task-queue/index.d.ts +1 -0
- package/task-queue/index.js +1 -0
- package/task-queue/postgres/task-queue.d.ts +1 -1
- package/task-queue/postgres/task-queue.js +4 -2
- package/task-queue/task.error.d.ts +7 -0
- package/task-queue/task.error.js +18 -0
|
@@ -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
|
|
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 ?? (
|
|
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,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
|
-
|
|
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
|
}
|
package/task-queue/index.d.ts
CHANGED
package/task-queue/index.js
CHANGED
|
@@ -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>,
|
|
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,
|
|
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
|
+
}
|