@tstdl/base 0.93.86 → 0.93.89
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/ai/genkit/helpers.d.ts +3 -1
- package/ai/genkit/helpers.js +3 -3
- package/api/server/gateway.d.ts +3 -0
- package/api/server/gateway.js +15 -4
- package/api/server/middlewares/catch-error.middleware.js +2 -4
- package/api/server/middlewares/cors.middleware.js +2 -3
- package/api/server/middlewares/csrf.middleware.d.ts +41 -0
- package/api/server/middlewares/csrf.middleware.js +108 -0
- package/api/server/middlewares/index.d.ts +1 -0
- package/api/server/middlewares/index.js +1 -0
- package/api/server/module.d.ts +8 -2
- package/api/server/module.js +14 -8
- package/api/server/tests/csrf.middleware.test.js +91 -0
- package/audit/drizzle/{0000_bored_stick.sql → 0000_lumpy_thunderball.sql} +3 -3
- package/audit/drizzle/meta/0000_snapshot.json +4 -4
- package/audit/drizzle/meta/_journal.json +2 -9
- package/audit/module.d.ts +4 -1
- package/audit/module.js +3 -2
- package/audit/schemas.d.ts +1 -1
- package/audit/types.d.ts +1 -1
- package/audit/types.js +1 -1
- package/authentication/client/authentication.service.d.ts +14 -1
- package/authentication/client/authentication.service.js +82 -23
- package/authentication/client/http-client.middleware.d.ts +6 -0
- package/authentication/client/http-client.middleware.js +36 -0
- package/authentication/client/module.js +8 -2
- package/authentication/models/service-account.model.d.ts +2 -2
- package/authentication/models/service-account.model.js +10 -5
- package/authentication/models/subject.model.d.ts +19 -5
- package/authentication/models/subject.model.js +25 -29
- package/authentication/models/system-account.model.d.ts +3 -2
- package/authentication/models/system-account.model.js +11 -5
- package/authentication/models/user.model.d.ts +2 -11
- package/authentication/models/user.model.js +5 -16
- package/authentication/server/authentication-api-request-token.provider.d.ts +0 -2
- package/authentication/server/authentication-api-request-token.provider.js +3 -11
- package/authentication/server/authentication.api-controller.d.ts +1 -2
- package/authentication/server/authentication.api-controller.js +8 -9
- package/authentication/server/authentication.audit.d.ts +3 -2
- package/authentication/server/authentication.service.d.ts +27 -1
- package/authentication/server/authentication.service.js +67 -18
- package/authentication/server/drizzle/{0000_normal_paper_doll.sql → 0000_soft_tag.sql} +25 -32
- package/authentication/server/drizzle/meta/0000_snapshot.json +180 -205
- package/authentication/server/drizzle/meta/_journal.json +2 -2
- package/authentication/server/helper.js +9 -2
- package/authentication/server/module.d.ts +4 -1
- package/authentication/server/module.js +9 -5
- package/authentication/server/schemas.d.ts +2 -1
- package/authentication/server/schemas.js +2 -2
- package/authentication/server/subject.service.d.ts +14 -8
- package/authentication/server/subject.service.js +86 -84
- package/authentication/tests/authentication-ancillary.service.test.d.ts +1 -0
- package/authentication/tests/authentication-ancillary.service.test.js +13 -0
- package/authentication/tests/authentication-secret-requirements.validator.test.d.ts +1 -0
- package/authentication/tests/authentication-secret-requirements.validator.test.js +29 -0
- package/authentication/tests/authentication.api-controller.test.d.ts +1 -0
- package/authentication/tests/authentication.api-controller.test.js +88 -0
- package/authentication/tests/authentication.api-request-token.provider.test.d.ts +1 -0
- package/authentication/tests/authentication.api-request-token.provider.test.js +48 -0
- package/authentication/tests/authentication.client-middleware.test.d.ts +1 -0
- package/authentication/tests/authentication.client-middleware.test.js +23 -0
- package/authentication/tests/authentication.client-service.test.d.ts +1 -0
- package/authentication/tests/authentication.client-service.test.js +70 -0
- package/authentication/tests/authentication.service.test.d.ts +1 -0
- package/authentication/tests/authentication.service.test.js +186 -0
- package/authentication/tests/authentication.test-ancillary-service.d.ts +9 -0
- package/authentication/tests/authentication.test-ancillary-service.js +27 -0
- package/authentication/tests/helper.test.d.ts +1 -0
- package/authentication/tests/helper.test.js +107 -0
- package/authentication/tests/secret-requirements.error.test.d.ts +1 -0
- package/authentication/tests/secret-requirements.error.test.js +14 -0
- package/authentication/tests/subject.service.test.d.ts +1 -0
- package/authentication/tests/subject.service.test.js +140 -0
- package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +1 -1
- package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
- package/circuit-breaker/postgres/module.d.ts +7 -1
- package/circuit-breaker/postgres/module.js +8 -6
- package/circuit-breaker/tests/circuit-breaker.test.js +2 -22
- package/document-management/api/document-management.api.js +2 -6
- package/document-management/server/services/document-validation.service.js +6 -5
- package/document-management/server/services/document-workflow.service.js +5 -5
- package/document-management/service-models/document-folders.view-model.d.ts +5 -2
- package/document-management/service-models/document-folders.view-model.js +42 -9
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
- package/examples/document-management/main.js +4 -4
- package/http/client/adapters/undici.adapter.d.ts +7 -5
- package/http/client/adapters/undici.adapter.js +13 -10
- package/http/client/module.d.ts +3 -1
- package/http/client/module.js +8 -9
- package/http/server/http-server.d.ts +2 -0
- package/http/server/node/module.d.ts +6 -2
- package/http/server/node/module.js +6 -4
- package/http/server/node/node-http-server.d.ts +2 -0
- package/http/server/node/node-http-server.js +7 -0
- package/http/types.d.ts +1 -1
- package/key-value-store/postgres/module.d.ts +7 -1
- package/key-value-store/postgres/module.js +7 -3
- package/lock/postgres/lock.js +0 -1
- package/lock/postgres/module.d.ts +7 -1
- package/lock/postgres/module.js +9 -5
- package/logger/formatter.d.ts +2 -0
- package/logger/formatters/json.js +2 -2
- package/logger/formatters/pretty-print.js +8 -10
- package/logger/logger.d.ts +1 -1
- package/logger/logger.js +15 -12
- package/message-bus/local/module.d.ts +5 -2
- package/message-bus/local/module.js +5 -4
- package/module/module.d.ts +2 -1
- package/module/module.js +3 -0
- package/module/modules/web-server.module.d.ts +11 -6
- package/module/modules/web-server.module.js +15 -10
- package/orm/decorators.d.ts +24 -1
- package/orm/decorators.js +40 -4
- package/orm/index.d.ts +1 -1
- package/orm/index.js +1 -1
- package/orm/query/base.d.ts +17 -17
- package/orm/query/base.js +1 -1
- package/orm/repository.types.d.ts +46 -2
- package/orm/schemas/tsvector.js +1 -1
- package/orm/server/drizzle/schema-converter.d.ts +3 -1
- package/orm/server/drizzle/schema-converter.js +120 -14
- package/orm/server/index.d.ts +1 -0
- package/orm/server/index.js +1 -0
- package/orm/server/module.d.ts +4 -2
- package/orm/server/module.js +6 -5
- package/orm/server/query-converter.d.ts +6 -3
- package/orm/server/query-converter.js +33 -21
- package/orm/server/repository-config.d.ts +8 -0
- package/orm/server/repository-config.js +8 -0
- package/orm/server/repository.d.ts +117 -43
- package/orm/server/repository.js +758 -254
- package/orm/server/transaction.d.ts +4 -2
- package/orm/server/transaction.js +14 -5
- package/orm/server/transactional.d.ts +6 -2
- package/orm/server/transactional.js +39 -9
- package/orm/server/types.d.ts +2 -0
- package/orm/sqls/case-when.d.ts +25 -0
- package/orm/sqls/case-when.js +54 -0
- package/orm/sqls/index.d.ts +2 -0
- package/orm/sqls/index.js +2 -0
- package/orm/{sqls.d.ts → sqls/sqls.d.ts} +67 -19
- package/orm/{sqls.js → sqls/sqls.js} +116 -22
- package/orm/tests/data-types.test.d.ts +1 -0
- package/orm/tests/data-types.test.js +39 -0
- package/orm/tests/decorators.test.d.ts +1 -0
- package/orm/tests/decorators.test.js +77 -0
- package/orm/tests/encryption.test.d.ts +1 -0
- package/orm/tests/encryption.test.js +34 -0
- package/orm/tests/query-complex.test.d.ts +1 -0
- package/orm/tests/query-complex.test.js +203 -0
- package/orm/tests/query-converter-complex.test.d.ts +1 -0
- package/orm/tests/query-converter-complex.test.js +126 -0
- package/orm/tests/query-converter.test.d.ts +1 -0
- package/orm/tests/query-converter.test.js +123 -0
- package/orm/tests/repository-advanced.test.d.ts +1 -0
- package/orm/tests/repository-advanced.test.js +232 -0
- package/orm/tests/repository-attributes.test.d.ts +1 -0
- package/orm/tests/repository-attributes.test.js +99 -0
- package/orm/tests/repository-comprehensive.test.d.ts +1 -0
- package/orm/tests/repository-comprehensive.test.js +187 -0
- package/orm/tests/repository-coverage.test.d.ts +1 -0
- package/orm/tests/repository-coverage.test.js +303 -0
- package/orm/tests/repository-cti-complex.test.d.ts +1 -0
- package/orm/tests/repository-cti-complex.test.js +170 -0
- package/orm/tests/repository-cti-embedded.test.d.ts +1 -0
- package/orm/tests/repository-cti-embedded.test.js +188 -0
- package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
- package/orm/tests/repository-cti-extensive.test.js +308 -0
- package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
- package/orm/tests/repository-cti-mapping.test.js +121 -0
- package/orm/tests/repository-cti-search.test.d.ts +1 -0
- package/orm/tests/repository-cti-search.test.js +152 -0
- package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-cti-soft-delete.test.js +115 -0
- package/orm/tests/repository-cti-transactions.test.d.ts +1 -0
- package/orm/tests/repository-cti-transactions.test.js +126 -0
- package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
- package/orm/tests/repository-cti-upsert-many.test.js +127 -0
- package/orm/tests/repository-cti.test.d.ts +1 -0
- package/orm/tests/repository-cti.test.js +456 -0
- package/orm/tests/repository-edge-cases.test.d.ts +1 -0
- package/orm/tests/repository-edge-cases.test.js +216 -0
- package/orm/tests/repository-expiration.test.d.ts +1 -0
- package/orm/tests/repository-expiration.test.js +153 -0
- package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
- package/orm/tests/repository-extra-coverage.test.js +546 -0
- package/orm/tests/repository-mapping.test.d.ts +1 -0
- package/orm/tests/repository-mapping.test.js +71 -0
- package/orm/tests/repository-regression.test.d.ts +1 -0
- package/orm/tests/repository-regression.test.js +330 -0
- package/orm/tests/repository-search-coverage.test.d.ts +1 -0
- package/orm/tests/repository-search-coverage.test.js +129 -0
- package/orm/tests/repository-search.test.d.ts +1 -0
- package/orm/tests/repository-search.test.js +116 -0
- package/orm/tests/repository-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-soft-delete.test.js +143 -0
- package/orm/tests/repository-transactions-nested.test.d.ts +1 -0
- package/orm/tests/repository-transactions-nested.test.js +202 -0
- package/orm/tests/repository-types.test.d.ts +1 -0
- package/orm/tests/repository-types.test.js +218 -0
- package/orm/tests/schema-converter.test.d.ts +1 -0
- package/orm/tests/schema-converter.test.js +81 -0
- package/orm/tests/schema-generation.test.d.ts +1 -0
- package/orm/tests/schema-generation.test.js +127 -0
- package/orm/tests/sql-helpers.test.d.ts +1 -0
- package/orm/tests/sql-helpers.test.js +67 -0
- package/orm/tests/transaction-safety.test.d.ts +1 -0
- package/orm/tests/transaction-safety.test.js +81 -0
- package/orm/tests/transactional.test.d.ts +1 -0
- package/orm/tests/transactional.test.js +224 -0
- package/orm/tests/utils.test.d.ts +1 -0
- package/orm/tests/utils.test.js +70 -0
- package/orm/utils.d.ts +7 -0
- package/orm/utils.js +26 -6
- package/package.json +12 -7
- package/pool/pool.js +1 -1
- package/rate-limit/index.d.ts +2 -0
- package/rate-limit/index.js +2 -0
- package/rate-limit/postgres/drizzle/0000_watery_rage.sql +7 -0
- package/{queue → rate-limit}/postgres/drizzle/meta/0000_snapshot.json +14 -39
- package/rate-limit/postgres/drizzle/meta/_journal.json +13 -0
- package/{queue → rate-limit}/postgres/drizzle.config.js +1 -1
- package/rate-limit/postgres/index.d.ts +4 -0
- package/rate-limit/postgres/index.js +4 -0
- package/rate-limit/postgres/module.d.ts +12 -0
- package/rate-limit/postgres/module.js +28 -0
- package/rate-limit/postgres/postgres-rate-limiter.d.ts +9 -0
- package/rate-limit/postgres/postgres-rate-limiter.js +56 -0
- package/rate-limit/postgres/rate-limit.model.d.ts +8 -0
- package/rate-limit/postgres/rate-limit.model.js +35 -0
- package/rate-limit/postgres/rate-limiter.provider.d.ts +6 -0
- package/rate-limit/postgres/rate-limiter.provider.js +21 -0
- package/rate-limit/postgres/schemas.d.ts +3 -0
- package/rate-limit/postgres/schemas.js +4 -0
- package/rate-limit/provider.d.ts +9 -0
- package/rate-limit/provider.js +2 -0
- package/rate-limit/rate-limiter.d.ts +35 -0
- package/rate-limit/rate-limiter.js +3 -0
- package/rate-limit/tests/postgres-rate-limiter.test.d.ts +1 -0
- package/rate-limit/tests/postgres-rate-limiter.test.js +92 -0
- package/signals/implementation/configure.d.ts +3 -0
- package/signals/implementation/configure.js +3 -0
- package/sse/data-stream-source.d.ts +1 -1
- package/sse/data-stream-source.js +6 -6
- package/task-queue/enqueue-batch.d.ts +17 -0
- package/task-queue/enqueue-batch.js +24 -0
- package/{queue → task-queue}/index.d.ts +1 -1
- package/{queue → task-queue}/index.js +1 -1
- package/task-queue/postgres/drizzle/0000_thin_black_panther.sql +74 -0
- package/task-queue/postgres/drizzle/meta/0000_snapshot.json +592 -0
- package/task-queue/postgres/drizzle/meta/_journal.json +13 -0
- package/task-queue/postgres/drizzle.config.d.ts +2 -0
- package/task-queue/postgres/drizzle.config.js +11 -0
- package/task-queue/postgres/index.d.ts +4 -0
- package/task-queue/postgres/index.js +4 -0
- package/task-queue/postgres/module.d.ts +12 -0
- package/task-queue/postgres/module.js +28 -0
- package/task-queue/postgres/schemas.d.ts +16 -0
- package/task-queue/postgres/schemas.js +8 -0
- package/task-queue/postgres/task-queue.d.ts +83 -0
- package/task-queue/postgres/task-queue.js +1054 -0
- package/task-queue/postgres/task-queue.provider.d.ts +7 -0
- package/{queue/postgres/queue.provider.js → task-queue/postgres/task-queue.provider.js} +8 -8
- package/task-queue/postgres/task.model.d.ts +39 -0
- package/task-queue/postgres/task.model.js +178 -0
- package/{queue → task-queue}/provider.d.ts +3 -3
- package/task-queue/provider.js +2 -0
- package/{queue → task-queue}/task-context.d.ts +7 -7
- package/{queue → task-queue}/task-context.js +8 -8
- package/{queue/queue.d.ts → task-queue/task-queue.d.ts} +128 -59
- package/task-queue/task-queue.js +200 -0
- package/task-queue/tests/complex.test.d.ts +1 -0
- package/task-queue/tests/complex.test.js +299 -0
- package/task-queue/tests/dependencies.test.d.ts +1 -0
- package/task-queue/tests/dependencies.test.js +174 -0
- package/task-queue/tests/queue.test.d.ts +1 -0
- package/task-queue/tests/queue.test.js +334 -0
- package/task-queue/tests/worker.test.d.ts +1 -0
- package/task-queue/tests/worker.test.js +163 -0
- package/test1.js +1 -1
- package/test4.js +2 -2
- package/unit-test/index.d.ts +1 -0
- package/unit-test/index.js +1 -0
- package/unit-test/integration-setup.d.ts +55 -0
- package/unit-test/integration-setup.js +182 -0
- package/utils/patterns.d.ts +3 -0
- package/utils/patterns.js +6 -1
- package/audit/drizzle/0001_previous_network.sql +0 -2
- package/audit/drizzle/meta/0001_snapshot.json +0 -195
- package/queue/enqueue-batch.d.ts +0 -17
- package/queue/enqueue-batch.js +0 -18
- package/queue/postgres/drizzle/0000_zippy_moondragon.sql +0 -11
- package/queue/postgres/drizzle/0001_certain_wild_pack.sql +0 -2
- package/queue/postgres/drizzle/0002_dear_meggan.sql +0 -2
- package/queue/postgres/drizzle/0003_tricky_venom.sql +0 -30
- package/queue/postgres/drizzle/meta/0001_snapshot.json +0 -103
- package/queue/postgres/drizzle/meta/0002_snapshot.json +0 -90
- package/queue/postgres/drizzle/meta/0003_snapshot.json +0 -288
- package/queue/postgres/drizzle/meta/_journal.json +0 -34
- package/queue/postgres/index.d.ts +0 -4
- package/queue/postgres/index.js +0 -4
- package/queue/postgres/module.d.ts +0 -9
- package/queue/postgres/module.js +0 -29
- package/queue/postgres/queue.d.ts +0 -60
- package/queue/postgres/queue.js +0 -681
- package/queue/postgres/queue.provider.d.ts +0 -7
- package/queue/postgres/schemas.d.ts +0 -14
- package/queue/postgres/schemas.js +0 -6
- package/queue/postgres/task.model.d.ts +0 -24
- package/queue/postgres/task.model.js +0 -115
- package/queue/provider.js +0 -2
- package/queue/queue.js +0 -131
- package/queue/tests/queue.test.js +0 -623
- package/test3.d.ts +0 -1
- package/test3.js +0 -47
- /package/{queue/tests/queue.test.d.ts → api/server/tests/csrf.middleware.test.d.ts} +0 -0
- /package/circuit-breaker/postgres/drizzle/{0000_hard_shocker.sql → 0000_cooing_korath.sql} +0 -0
- /package/{queue → rate-limit}/postgres/drizzle.config.d.ts +0 -0
package/ai/genkit/helpers.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { GenerateOptions, z } from 'genkit';
|
|
2
|
+
import { type SchemaConversionOptions } from '../../schema/converters/zod-v3-converter.js';
|
|
2
3
|
import type { SchemaTestable } from '../../schema/index.js';
|
|
3
4
|
import type { TypedOmit } from '../../types/types.js';
|
|
4
5
|
export type TstdlGenkitGenerationOptions<T, O extends z.ZodTypeAny> = TypedOmit<GenerateOptions<z.ZodType<NoInfer<T>>, O>, 'output'> & {
|
|
5
6
|
output?: TypedOmit<NonNullable<GenerateOptions['output']>, 'schema'> & {
|
|
6
7
|
schema?: SchemaTestable<T>;
|
|
8
|
+
schemaOptions?: SchemaConversionOptions;
|
|
7
9
|
};
|
|
8
10
|
};
|
|
9
|
-
export declare function convertToGenkitSchema<T>(schema: SchemaTestable<T
|
|
11
|
+
export declare function convertToGenkitSchema<T>(schema: SchemaTestable<T>, options?: SchemaConversionOptions): z.ZodType<T>;
|
|
10
12
|
export declare function genkitGenerationOptions<T, O extends z.ZodTypeAny>(options: TstdlGenkitGenerationOptions<T, O>): GenerateOptions<z.ZodType<T>, z.ZodType<O>>;
|
package/ai/genkit/helpers.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { convertToZodV3Schema } from '../../schema/converters/zod-v3-converter.js';
|
|
2
2
|
import { isDefined } from '../../utils/type-guards.js';
|
|
3
|
-
export function convertToGenkitSchema(schema) {
|
|
4
|
-
return convertToZodV3Schema(schema); // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
3
|
+
export function convertToGenkitSchema(schema, options) {
|
|
4
|
+
return convertToZodV3Schema(schema, options); // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
5
5
|
}
|
|
6
6
|
export function genkitGenerationOptions(options) {
|
|
7
7
|
return {
|
|
8
8
|
...options,
|
|
9
9
|
output: {
|
|
10
10
|
...options.output,
|
|
11
|
-
schema: isDefined(options.output?.schema) ? convertToGenkitSchema(options.output.schema) : undefined,
|
|
11
|
+
schema: isDefined(options.output?.schema) ? convertToGenkitSchema(options.output.schema, options.output.schemaOptions) : undefined,
|
|
12
12
|
},
|
|
13
13
|
};
|
|
14
14
|
}
|
package/api/server/gateway.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { Type } from '../../types/index.js';
|
|
|
6
6
|
import { type AsyncMiddleware, type AsyncMiddlewareNext } from '../../utils/middleware.js';
|
|
7
7
|
import { type ApiController, type ApiDefinition, type ApiEndpointDefinition, type ApiEndpointMethod, type ApiEndpointServerImplementation } from '../types.js';
|
|
8
8
|
import type { CorsMiddlewareOptions } from './middlewares/cors.middleware.js';
|
|
9
|
+
import { type CsrfMiddlewareOptions } from './middlewares/index.js';
|
|
9
10
|
export type ApiGatewayMiddlewareContext = {
|
|
10
11
|
readonly api: ApiItem;
|
|
11
12
|
/** can be undefined if used before allowedMethods middleware */
|
|
@@ -28,6 +29,8 @@ export declare abstract class ApiGatewayOptions {
|
|
|
28
29
|
supressedErrors?: Type<Error>[];
|
|
29
30
|
/** Cors middleware options */
|
|
30
31
|
cors?: CorsMiddlewareOptions;
|
|
32
|
+
/** Csrf middleware options */
|
|
33
|
+
csrf?: CsrfMiddlewareOptions;
|
|
31
34
|
/**
|
|
32
35
|
* Maximum size of request body. Useful to prevent harmful requests.
|
|
33
36
|
* @default 10 MB
|
package/api/server/gateway.js
CHANGED
|
@@ -35,7 +35,7 @@ import { normalizedApiDefinitionEndpointsEntries } from '../types.js';
|
|
|
35
35
|
import { getFullApiEndpointResource } from '../utils.js';
|
|
36
36
|
import { ApiRequestTokenProvider } from './api-request-token.provider.js';
|
|
37
37
|
import { handleApiError } from './error-handler.js';
|
|
38
|
-
import { allowedMethodsMiddleware, contentTypeMiddleware, corsMiddleware, getCatchErrorMiddleware, responseTimeMiddleware } from './middlewares/index.js';
|
|
38
|
+
import { allowedMethodsMiddleware, contentTypeMiddleware, corsMiddleware, csrfMiddleware, getCatchErrorMiddleware, responseTimeMiddleware } from './middlewares/index.js';
|
|
39
39
|
import { API_MODULE_OPTIONS } from './tokens.js';
|
|
40
40
|
const defaultMaxBytes = 10 * mebibyte;
|
|
41
41
|
export class ApiGatewayOptions {
|
|
@@ -50,6 +50,8 @@ export class ApiGatewayOptions {
|
|
|
50
50
|
supressedErrors;
|
|
51
51
|
/** Cors middleware options */
|
|
52
52
|
cors;
|
|
53
|
+
/** Csrf middleware options */
|
|
54
|
+
csrf;
|
|
53
55
|
/**
|
|
54
56
|
* Maximum size of request body. Useful to prevent harmful requests.
|
|
55
57
|
* @default 10 MB
|
|
@@ -162,7 +164,16 @@ let ApiGateway = ApiGateway_1 = class ApiGateway {
|
|
|
162
164
|
throw new NotFoundError(`Resource ${resource.pathname} not available.`);
|
|
163
165
|
}
|
|
164
166
|
updateMiddleware() {
|
|
165
|
-
const middlewares = [
|
|
167
|
+
const middlewares = [
|
|
168
|
+
responseTimeMiddleware,
|
|
169
|
+
contentTypeMiddleware,
|
|
170
|
+
this.#catchErrorMiddleware,
|
|
171
|
+
corsMiddleware(this.#options.cors),
|
|
172
|
+
csrfMiddleware(this.#options.csrf),
|
|
173
|
+
allowedMethodsMiddleware,
|
|
174
|
+
...this.#middlewares,
|
|
175
|
+
async (context, next) => await this.endpointMiddleware(context, next)
|
|
176
|
+
];
|
|
166
177
|
this.#composedMiddleware = composeAsyncMiddleware(middlewares);
|
|
167
178
|
}
|
|
168
179
|
async endpointMiddleware(context, next) {
|
|
@@ -198,9 +209,9 @@ let ApiGateway = ApiGateway_1 = class ApiGateway {
|
|
|
198
209
|
return auditor.fork(context.api.resource)
|
|
199
210
|
.withCorrelation()
|
|
200
211
|
.with({
|
|
201
|
-
actorType: isNotNull(token) ? ActorType.
|
|
212
|
+
actorType: isNotNull(token) ? ActorType.Subject : ActorType.Anonymous,
|
|
202
213
|
actor: token?.payload.subject ?? NIL_UUID,
|
|
203
|
-
impersonatorType: isNotNullOrUndefined(token?.payload.impersonator) ? ActorType.
|
|
214
|
+
impersonatorType: isNotNullOrUndefined(token?.payload.impersonator) ? ActorType.Subject : null,
|
|
204
215
|
impersonator: token?.payload.impersonator ?? null,
|
|
205
216
|
network: {
|
|
206
217
|
path: context.request.url.pathname,
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { handleApiError } from '../error-handler.js';
|
|
2
2
|
export function getCatchErrorMiddleware(supressedErrors, logger) {
|
|
3
|
-
|
|
4
|
-
async function catchErrorMiddleware(context, next) {
|
|
3
|
+
return async function catchErrorMiddleware(context, next) {
|
|
5
4
|
try {
|
|
6
5
|
await next();
|
|
7
6
|
}
|
|
8
7
|
catch (error) {
|
|
9
8
|
handleApiError(error, context.response, supressedErrors, logger);
|
|
10
9
|
}
|
|
11
|
-
}
|
|
12
|
-
return catchErrorMiddleware;
|
|
10
|
+
};
|
|
13
11
|
}
|
|
@@ -2,7 +2,7 @@ import { resolveApiEndpointDataProvider } from '../../../api/types.js';
|
|
|
2
2
|
import { toArray } from '../../../utils/array/array.js';
|
|
3
3
|
import { isDefined } from '../../../utils/type-guards.js';
|
|
4
4
|
export function corsMiddleware(options = {}) {
|
|
5
|
-
async function corsMiddleware(context, next) {
|
|
5
|
+
return async function corsMiddleware(context, next) {
|
|
6
6
|
try {
|
|
7
7
|
await next();
|
|
8
8
|
}
|
|
@@ -49,6 +49,5 @@ export function corsMiddleware(options = {}) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
}
|
|
53
|
-
return corsMiddleware;
|
|
52
|
+
};
|
|
54
53
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ApiGatewayMiddleware } from '../gateway.js';
|
|
2
|
+
export interface CsrfMiddlewareOptions {
|
|
3
|
+
/**
|
|
4
|
+
* List of additional hostnames to trust (e.g. 'api.example.com').
|
|
5
|
+
*/
|
|
6
|
+
trustedHosts?: string[];
|
|
7
|
+
/**
|
|
8
|
+
* Whether to allow `Sec-Fetch-Site: same-site`.
|
|
9
|
+
* If false, only `same-origin` is accepted via Fetch Metadata.
|
|
10
|
+
* Disable this if you host untrusted content on subdomains.
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
allowFetchSiteSameSite?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to allow requests with `Sec-Fetch-Site: none`.
|
|
16
|
+
* Useful for user-initiated actions like clicking a link or bookmark opening an app.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
allowFetchSiteNone?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to trust the `X-Forwarded-Host` header.
|
|
22
|
+
* Enable this when running behind a reverse proxy (e.g., Nginx, AWS ALB).
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
trustProxy?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates a middleware for Stateless CSRF Protection using Fetch Metadata and Origin headers.
|
|
29
|
+
*
|
|
30
|
+
* This middleware verifies that mutating requests (POST, PUT, DELETE, PATCH) originate from a trusted source.
|
|
31
|
+
* It uses the following strategy:
|
|
32
|
+
* 1. Allows "safe" HTTP methods (GET, HEAD, OPTIONS, TRACE).
|
|
33
|
+
* 2. Validates the `Sec-Fetch-Site` header if present.
|
|
34
|
+
* 3. Falls back to validating the `Origin` header against the resolved Host.
|
|
35
|
+
* 4. Falls back to validating the `Referer` header against the resolved Host.
|
|
36
|
+
* 5. Allows requests that lack all standard headers (assumed non-browser clients).
|
|
37
|
+
*
|
|
38
|
+
* @param options CSRF middleware options.
|
|
39
|
+
* @returns An API middleware function.
|
|
40
|
+
*/
|
|
41
|
+
export declare function csrfMiddleware(options?: CsrfMiddlewareOptions): ApiGatewayMiddleware;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { ForbiddenError } from '../../../errors/forbidden.error.js';
|
|
2
|
+
import { isNotNullOrUndefined, isNull, isNullOrUndefined, isString } from '../../../utils/type-guards.js';
|
|
3
|
+
const safeMethods = new Set(['GET', 'HEAD', 'OPTIONS', 'TRACE']);
|
|
4
|
+
/**
|
|
5
|
+
* Creates a middleware for Stateless CSRF Protection using Fetch Metadata and Origin headers.
|
|
6
|
+
*
|
|
7
|
+
* This middleware verifies that mutating requests (POST, PUT, DELETE, PATCH) originate from a trusted source.
|
|
8
|
+
* It uses the following strategy:
|
|
9
|
+
* 1. Allows "safe" HTTP methods (GET, HEAD, OPTIONS, TRACE).
|
|
10
|
+
* 2. Validates the `Sec-Fetch-Site` header if present.
|
|
11
|
+
* 3. Falls back to validating the `Origin` header against the resolved Host.
|
|
12
|
+
* 4. Falls back to validating the `Referer` header against the resolved Host.
|
|
13
|
+
* 5. Allows requests that lack all standard headers (assumed non-browser clients).
|
|
14
|
+
*
|
|
15
|
+
* @param options CSRF middleware options.
|
|
16
|
+
* @returns An API middleware function.
|
|
17
|
+
*/
|
|
18
|
+
export function csrfMiddleware(options) {
|
|
19
|
+
const trustedHosts = new Set((options?.trustedHosts ?? [])
|
|
20
|
+
.map((h) => normalizeHost(h))
|
|
21
|
+
.filter(isNotNullOrUndefined));
|
|
22
|
+
const allowFetchSiteNone = options?.allowFetchSiteNone ?? false;
|
|
23
|
+
const allowFetchSiteSameSite = options?.allowFetchSiteSameSite ?? true;
|
|
24
|
+
const trustProxy = options?.trustProxy ?? false;
|
|
25
|
+
return async function csrfMiddleware(context, next) {
|
|
26
|
+
// 1. Skip safe methods
|
|
27
|
+
if (safeMethods.has(context.request.method)) {
|
|
28
|
+
return await next();
|
|
29
|
+
}
|
|
30
|
+
// 2. Set Vary headers to prevent cache poisoning on these crucial headers
|
|
31
|
+
context.response.headers.append('Vary', 'Sec-Fetch-Site, Origin, Referer');
|
|
32
|
+
const secFetchSite = context.request.headers.tryGet('Sec-Fetch-Site');
|
|
33
|
+
const origin = context.request.headers.tryGet('Origin');
|
|
34
|
+
const referer = context.request.headers.tryGet('Referer');
|
|
35
|
+
// Resolve current host
|
|
36
|
+
let rawHost = context.request.headers.tryGetSingle('Host');
|
|
37
|
+
if (trustProxy) {
|
|
38
|
+
const forwardedHost = context.request.headers.tryGetSingle('X-Forwarded-Host');
|
|
39
|
+
if (isString(forwardedHost)) {
|
|
40
|
+
// CAUTION: Ensure your proxy overwrites this header, or verify behavior
|
|
41
|
+
rawHost = forwardedHost.split(',')[0].trim();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const currentHost = normalizeHost(rawHost);
|
|
45
|
+
// 3. Primary Check: Fetch Metadata
|
|
46
|
+
if (isNotNullOrUndefined(secFetchSite)) {
|
|
47
|
+
if ((secFetchSite == 'same-origin')
|
|
48
|
+
|| (allowFetchSiteSameSite && (secFetchSite == 'same-site'))
|
|
49
|
+
|| (allowFetchSiteNone && (secFetchSite == 'none'))) {
|
|
50
|
+
return await next();
|
|
51
|
+
}
|
|
52
|
+
throw new ForbiddenError('Cross-site request blocked.');
|
|
53
|
+
}
|
|
54
|
+
// Helper to validate a URL against current host or trusted hosts
|
|
55
|
+
const isUrlTrusted = (url) => {
|
|
56
|
+
try {
|
|
57
|
+
const normalizedUrlHost = normalizeHost(url);
|
|
58
|
+
if (isNull(normalizedUrlHost)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// 1. Check Explicit Trust List (Safest)
|
|
62
|
+
if (trustedHosts.has(normalizedUrlHost)) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
// 2. Check Host Header (Fallback - Vulnerable to Host Injection)
|
|
66
|
+
if (currentHost && (normalizedUrlHost == currentHost)) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
// 4. Secondary Check: Origin Header
|
|
76
|
+
if (isNotNullOrUndefined(origin)) {
|
|
77
|
+
if (isUrlTrusted(origin)) {
|
|
78
|
+
return await next();
|
|
79
|
+
}
|
|
80
|
+
throw new ForbiddenError('Cross-site request blocked.');
|
|
81
|
+
}
|
|
82
|
+
// 5. Tertiary Check: Referer Header
|
|
83
|
+
if (isNotNullOrUndefined(referer)) {
|
|
84
|
+
if (isUrlTrusted(referer)) {
|
|
85
|
+
return await next();
|
|
86
|
+
}
|
|
87
|
+
throw new ForbiddenError('Cross-site request blocked.');
|
|
88
|
+
}
|
|
89
|
+
// 6. Final Fallback: Allow requests with NO headers (Non-browser clients)
|
|
90
|
+
// Note: This relies on the assumption that browsers will always send at least
|
|
91
|
+
// one of the headers checked above for mutating requests.
|
|
92
|
+
await next();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function normalizeHost(host) {
|
|
96
|
+
if (isNullOrUndefined(host) || (host == 'null')) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const url = host.startsWith('http://') || host.startsWith('https://')
|
|
101
|
+
? new URL(host)
|
|
102
|
+
: new URL(`http://${host}`);
|
|
103
|
+
return url.hostname;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
package/api/server/module.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injector } from '../../injector/injector.js';
|
|
1
2
|
import type { Type } from '../../types/index.js';
|
|
2
3
|
import { ApiRequestTokenProvider } from './api-request-token.provider.js';
|
|
3
4
|
import type { ApiGatewayOptions } from './gateway.js';
|
|
@@ -6,5 +7,10 @@ export type ApiModuleOptions = {
|
|
|
6
7
|
requestTokenProvider?: Type<ApiRequestTokenProvider>;
|
|
7
8
|
gatewayOptions?: ApiGatewayOptions;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* configure api server module
|
|
12
|
+
* @param options module configuration
|
|
13
|
+
*/
|
|
14
|
+
export declare function configureApiServer({ injector, ...options }?: Partial<ApiModuleOptions> & {
|
|
15
|
+
injector?: Injector;
|
|
16
|
+
}): void;
|
package/api/server/module.js
CHANGED
|
@@ -3,19 +3,25 @@ import { isDefined } from '../../utils/type-guards.js';
|
|
|
3
3
|
import { ensureApiController } from './api-controller.js';
|
|
4
4
|
import { ApiRequestTokenProvider } from './api-request-token.provider.js';
|
|
5
5
|
import { API_CONTROLLER, API_MODULE_OPTIONS } from './tokens.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* configure api server module
|
|
8
|
+
* @param options module configuration
|
|
9
|
+
*/
|
|
10
|
+
export function configureApiServer({ injector, ...options } = {}) {
|
|
11
|
+
const targetInjector = injector ?? Injector;
|
|
10
12
|
if (isDefined(options.controllers)) {
|
|
11
13
|
for (const controller of options.controllers) {
|
|
12
14
|
ensureApiController(controller);
|
|
13
|
-
|
|
15
|
+
targetInjector.register(API_CONTROLLER, { useToken: controller }, { multi: true });
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
if (isDefined(options.requestTokenProvider)) {
|
|
17
|
-
|
|
19
|
+
targetInjector.register(ApiRequestTokenProvider, { useToken: options.requestTokenProvider });
|
|
18
20
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const moduleOptions = {
|
|
22
|
+
controllers: options.controllers ?? [],
|
|
23
|
+
gatewayOptions: options.gatewayOptions,
|
|
24
|
+
requestTokenProvider: options.requestTokenProvider,
|
|
25
|
+
};
|
|
26
|
+
targetInjector.register(API_MODULE_OPTIONS, { useValue: moduleOptions });
|
|
21
27
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ForbiddenError } from '../../../errors/index.js';
|
|
2
|
+
import { HttpHeaders } from '../../../http/http-headers.js';
|
|
3
|
+
import { HttpServerResponse } from '../../../http/server/index.js';
|
|
4
|
+
import { toArray } from '../../../utils/array/array.js';
|
|
5
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { csrfMiddleware } from '../middlewares/csrf.middleware.js';
|
|
7
|
+
describe('csrfMiddleware', () => {
|
|
8
|
+
const middleware = csrfMiddleware();
|
|
9
|
+
it('should allow safe methods (GET, HEAD, OPTIONS, TRACE)', async () => {
|
|
10
|
+
const safeMethods = ['GET', 'HEAD', 'OPTIONS', 'TRACE'];
|
|
11
|
+
for (const method of safeMethods) {
|
|
12
|
+
const context = {
|
|
13
|
+
request: { method, headers: new HttpHeaders() },
|
|
14
|
+
response: new HttpServerResponse(),
|
|
15
|
+
};
|
|
16
|
+
const next = vi.fn();
|
|
17
|
+
await middleware(context, next);
|
|
18
|
+
expect(next).toHaveBeenCalled();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
it('should allow mutating methods (POST, PUT, DELETE, PATCH) without headers (non-browser client)', async () => {
|
|
22
|
+
const mutatingMethods = ['POST', 'PUT', 'DELETE', 'PATCH'];
|
|
23
|
+
for (const method of mutatingMethods) {
|
|
24
|
+
const context = {
|
|
25
|
+
request: { method, headers: new HttpHeaders() },
|
|
26
|
+
response: new HttpServerResponse(),
|
|
27
|
+
};
|
|
28
|
+
const next = vi.fn();
|
|
29
|
+
await middleware(context, next);
|
|
30
|
+
expect(next).toHaveBeenCalled();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
it('should allow same-origin requests via Sec-Fetch-Site', async () => {
|
|
34
|
+
const headers = new HttpHeaders();
|
|
35
|
+
headers.set('Sec-Fetch-Site', 'same-origin');
|
|
36
|
+
const context = {
|
|
37
|
+
request: { method: 'POST', headers },
|
|
38
|
+
response: new HttpServerResponse(),
|
|
39
|
+
};
|
|
40
|
+
const next = vi.fn();
|
|
41
|
+
await middleware(context, next);
|
|
42
|
+
expect(next).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
it('should allow user-initiated requests via Sec-Fetch-Site (none) when enabled', async () => {
|
|
45
|
+
const middlewareWithNone = csrfMiddleware({ allowFetchSiteNone: true });
|
|
46
|
+
const headers = new HttpHeaders();
|
|
47
|
+
headers.set('Sec-Fetch-Site', 'none');
|
|
48
|
+
const context = {
|
|
49
|
+
request: { method: 'POST', headers },
|
|
50
|
+
response: new HttpServerResponse(),
|
|
51
|
+
};
|
|
52
|
+
const next = vi.fn();
|
|
53
|
+
await middlewareWithNone(context, next);
|
|
54
|
+
expect(next).toHaveBeenCalled();
|
|
55
|
+
});
|
|
56
|
+
it('should reject cross-site requests via Sec-Fetch-Site', async () => {
|
|
57
|
+
const headers = new HttpHeaders();
|
|
58
|
+
headers.set('Sec-Fetch-Site', 'cross-site');
|
|
59
|
+
const context = {
|
|
60
|
+
request: { method: 'POST', headers },
|
|
61
|
+
response: new HttpServerResponse(),
|
|
62
|
+
};
|
|
63
|
+
const next = vi.fn();
|
|
64
|
+
await expect(middleware(context, next)).rejects.toThrow(ForbiddenError);
|
|
65
|
+
expect(next).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
it('should allow same-origin requests via Origin fallback', async () => {
|
|
68
|
+
const headers = new HttpHeaders();
|
|
69
|
+
headers.set('Origin', 'http://localhost:8080');
|
|
70
|
+
headers.set('Host', 'localhost:8080');
|
|
71
|
+
const context = {
|
|
72
|
+
request: { method: 'POST', headers },
|
|
73
|
+
response: new HttpServerResponse(),
|
|
74
|
+
};
|
|
75
|
+
const next = vi.fn();
|
|
76
|
+
await middleware(context, next);
|
|
77
|
+
expect(next).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
it('should include Vary: Sec-Fetch-Site, Origin for mutating methods', async () => {
|
|
80
|
+
const context = {
|
|
81
|
+
request: { method: 'POST', headers: new HttpHeaders() },
|
|
82
|
+
response: new HttpServerResponse(),
|
|
83
|
+
};
|
|
84
|
+
const next = vi.fn();
|
|
85
|
+
await middleware(context, next);
|
|
86
|
+
const vary = context.response.headers.tryGet('Vary');
|
|
87
|
+
const varyArray = toArray(vary).flatMap((v) => v.split(',').map((s) => s.trim()));
|
|
88
|
+
expect(varyArray).toContain('Sec-Fetch-Site');
|
|
89
|
+
expect(varyArray).toContain('Origin');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
CREATE TYPE "audit"."actor_type" AS ENUM('anonymous', 'system', 'api-key', '
|
|
1
|
+
CREATE TYPE "audit"."actor_type" AS ENUM('anonymous', 'system', 'api-key', 'subject');--> statement-breakpoint
|
|
2
2
|
CREATE TYPE "audit"."audit_outcome" AS ENUM('pending', 'success', 'cancelled', 'failure', 'denied');--> statement-breakpoint
|
|
3
3
|
CREATE TYPE "audit"."audit_severity" AS ENUM('info', 'warn', 'error', 'critical');--> statement-breakpoint
|
|
4
4
|
CREATE TABLE "audit"."event" (
|
|
@@ -11,12 +11,12 @@ CREATE TABLE "audit"."event" (
|
|
|
11
11
|
"outcome" "audit"."audit_outcome" NOT NULL,
|
|
12
12
|
"severity" "audit"."audit_severity" NOT NULL,
|
|
13
13
|
"actor_type" "audit"."actor_type" NOT NULL,
|
|
14
|
-
"actor" text
|
|
14
|
+
"actor" text,
|
|
15
15
|
"impersonator_type" "audit"."actor_type",
|
|
16
16
|
"impersonator" text,
|
|
17
17
|
"target_type" text NOT NULL,
|
|
18
18
|
"target_id" uuid NOT NULL,
|
|
19
|
-
"network_path" text
|
|
19
|
+
"network_path" text,
|
|
20
20
|
"network_ip_address" text,
|
|
21
21
|
"network_user_agent" text,
|
|
22
22
|
"network_session_id" uuid,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
2
|
+
"id": "e6910cc2-1674-462e-be27-f94e3372393f",
|
|
3
3
|
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
4
4
|
"version": "7",
|
|
5
5
|
"dialect": "postgresql",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"name": "actor",
|
|
71
71
|
"type": "text",
|
|
72
72
|
"primaryKey": false,
|
|
73
|
-
"notNull":
|
|
73
|
+
"notNull": false
|
|
74
74
|
},
|
|
75
75
|
"impersonator_type": {
|
|
76
76
|
"name": "impersonator_type",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"name": "network_path",
|
|
102
102
|
"type": "text",
|
|
103
103
|
"primaryKey": false,
|
|
104
|
-
"notNull":
|
|
104
|
+
"notNull": false
|
|
105
105
|
},
|
|
106
106
|
"network_ip_address": {
|
|
107
107
|
"name": "network_ip_address",
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
"anonymous",
|
|
158
158
|
"system",
|
|
159
159
|
"api-key",
|
|
160
|
-
"
|
|
160
|
+
"subject"
|
|
161
161
|
]
|
|
162
162
|
},
|
|
163
163
|
"audit.audit_outcome": {
|
|
@@ -5,15 +5,8 @@
|
|
|
5
5
|
{
|
|
6
6
|
"idx": 0,
|
|
7
7
|
"version": "7",
|
|
8
|
-
"when":
|
|
9
|
-
"tag": "
|
|
10
|
-
"breakpoints": true
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"idx": 1,
|
|
14
|
-
"version": "7",
|
|
15
|
-
"when": 1762968766536,
|
|
16
|
-
"tag": "0001_previous_network",
|
|
8
|
+
"when": 1768666123825,
|
|
9
|
+
"tag": "0000_lumpy_thunderball",
|
|
17
10
|
"breakpoints": true
|
|
18
11
|
}
|
|
19
12
|
]
|
package/audit/module.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Injector } from '../injector/index.js';
|
|
1
2
|
import { type DatabaseConfig } from '../orm/server/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Configuration for {@link configureAudit}.
|
|
@@ -13,7 +14,9 @@ export declare class AuditModuleConfig {
|
|
|
13
14
|
* Configures audit server services.
|
|
14
15
|
* @param config Configuration.
|
|
15
16
|
*/
|
|
16
|
-
export declare function configureAudit(config
|
|
17
|
+
export declare function configureAudit({ injector, ...config }?: AuditModuleConfig & {
|
|
18
|
+
injector?: Injector;
|
|
19
|
+
}): void;
|
|
17
20
|
/**
|
|
18
21
|
* Migrates the audit database schema to the latest version.
|
|
19
22
|
* It uses the database connection provided with {@link configureAudit},
|
package/audit/module.js
CHANGED
|
@@ -14,8 +14,9 @@ export class AuditModuleConfig {
|
|
|
14
14
|
* Configures audit server services.
|
|
15
15
|
* @param config Configuration.
|
|
16
16
|
*/
|
|
17
|
-
export function configureAudit(config) {
|
|
18
|
-
|
|
17
|
+
export function configureAudit({ injector, ...config } = {}) {
|
|
18
|
+
const targetInjector = injector ?? Injector;
|
|
19
|
+
targetInjector.register(AuditModuleConfig, { useValue: config });
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Migrates the audit database schema to the latest version.
|
package/audit/schemas.d.ts
CHANGED
|
@@ -17,6 +17,6 @@ export declare const actorType: import("../orm/enums.js").PgEnumFromEnumeration<
|
|
|
17
17
|
readonly Anonymous: "anonymous";
|
|
18
18
|
readonly System: "system";
|
|
19
19
|
readonly ApiKey: "api-key";
|
|
20
|
-
readonly
|
|
20
|
+
readonly Subject: "subject";
|
|
21
21
|
}>;
|
|
22
22
|
export declare const auditEvent: import("../orm/server/types.js").PgTableFromType<typeof AuditEvent, "audit">;
|
package/audit/types.d.ts
CHANGED
package/audit/types.js
CHANGED
|
@@ -27,6 +27,7 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
27
27
|
private readonly logger;
|
|
28
28
|
private readonly disposeToken;
|
|
29
29
|
private clockOffset;
|
|
30
|
+
private refreshLoopPromise;
|
|
30
31
|
/**
|
|
31
32
|
* Observable for authentication errors.
|
|
32
33
|
* Emits when a refresh fails.
|
|
@@ -34,6 +35,12 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
34
35
|
readonly error$: import("rxjs").Observable<Error>;
|
|
35
36
|
/** Current token */
|
|
36
37
|
readonly token: import("../../signals/api.js").WritableSignal<TokenPayload<AdditionalTokenPayload> | undefined>;
|
|
38
|
+
/** Current raw token */
|
|
39
|
+
readonly rawToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
40
|
+
/** Current raw refresh token */
|
|
41
|
+
readonly rawRefreshToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
42
|
+
/** Current raw impersonator refresh token */
|
|
43
|
+
readonly rawImpersonatorRefreshToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
37
44
|
/** Whether the user is logged in */
|
|
38
45
|
readonly isLoggedIn: import("../../signals/api.js").Signal<boolean>;
|
|
39
46
|
/** Current session id */
|
|
@@ -170,9 +177,15 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
170
177
|
* @returns The result of the check
|
|
171
178
|
*/
|
|
172
179
|
checkSecret(secret: string): Promise<SecretCheckResult>;
|
|
180
|
+
/**
|
|
181
|
+
* Update raw tokens.
|
|
182
|
+
* @param token Raw token
|
|
183
|
+
* @param refreshToken Raw refresh token
|
|
184
|
+
* @param impersonatorRefreshToken Raw impersonator refresh token
|
|
185
|
+
*/
|
|
186
|
+
updateRawTokens(token?: string, refreshToken?: string, impersonatorRefreshToken?: string): void;
|
|
173
187
|
private setNewToken;
|
|
174
188
|
private refreshLoop;
|
|
175
|
-
private refreshLoopIteration;
|
|
176
189
|
private handleRefreshError;
|
|
177
190
|
private estimatedServerTimestampSeconds;
|
|
178
191
|
private syncClock;
|