@tstdl/base 0.93.76 → 0.93.78
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/prompts/instructions-formatter.d.ts +68 -5
- package/ai/prompts/instructions-formatter.js +11 -3
- package/authentication/client/http-client.middleware.js +2 -2
- package/authentication/models/authentication-credentials.model.d.ts +2 -2
- package/authentication/models/authentication-credentials.model.js +5 -3
- package/authentication/models/authentication-session.model.d.ts +2 -2
- package/authentication/models/authentication-session.model.js +5 -3
- package/authentication/models/index.d.ts +4 -0
- package/authentication/models/index.js +4 -0
- package/authentication/models/service-account.model.d.ts +7 -0
- package/authentication/models/service-account.model.js +31 -0
- package/authentication/models/subject.model.d.ts +16 -0
- package/authentication/models/subject.model.js +59 -0
- package/authentication/models/system-account.model.d.ts +5 -0
- package/authentication/models/system-account.model.js +25 -0
- package/authentication/models/user.model.d.ts +15 -0
- package/authentication/models/user.model.js +47 -0
- package/authentication/server/drizzle/0001_condemned_pretty_boy.sql +70 -0
- package/authentication/server/drizzle/meta/0001_snapshot.json +651 -0
- package/authentication/server/drizzle/meta/_journal.json +7 -0
- package/authentication/server/index.d.ts +1 -0
- package/authentication/server/index.js +1 -0
- package/authentication/server/schemas.d.ts +16 -1
- package/authentication/server/schemas.js +7 -1
- package/authentication/server/subject.service.d.ts +6 -0
- package/authentication/server/subject.service.js +44 -0
- package/circuit-breaker/circuit-breaker.d.ts +32 -0
- package/circuit-breaker/circuit-breaker.js +9 -0
- package/circuit-breaker/index.d.ts +2 -0
- package/circuit-breaker/index.js +2 -0
- package/circuit-breaker/postgres/circuit-breaker.d.ts +7 -0
- package/circuit-breaker/postgres/circuit-breaker.js +78 -0
- package/circuit-breaker/postgres/drizzle/0000_hard_shocker.sql +9 -0
- package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +82 -0
- package/circuit-breaker/postgres/drizzle/meta/_journal.json +13 -0
- package/circuit-breaker/postgres/drizzle.config.d.ts +2 -0
- package/circuit-breaker/postgres/drizzle.config.js +11 -0
- package/circuit-breaker/postgres/index.d.ts +5 -0
- package/circuit-breaker/postgres/index.js +5 -0
- package/circuit-breaker/postgres/model.d.ts +9 -0
- package/circuit-breaker/postgres/model.js +40 -0
- package/circuit-breaker/postgres/module.d.ts +6 -0
- package/circuit-breaker/postgres/module.js +25 -0
- package/circuit-breaker/postgres/provider.d.ts +6 -0
- package/circuit-breaker/postgres/provider.js +21 -0
- package/circuit-breaker/postgres/schemas.d.ts +8 -0
- package/circuit-breaker/postgres/schemas.js +6 -0
- package/circuit-breaker/provider.d.ts +4 -0
- package/circuit-breaker/provider.js +2 -0
- package/circuit-breaker/tests/circuit-breaker.test.js +113 -0
- package/document-management/models/document.model.d.ts +0 -1
- package/document-management/models/document.model.js +0 -5
- package/document-management/server/api/document-management.api.js +1 -2
- package/document-management/server/drizzle/0002_round_warbird.sql +1 -0
- package/document-management/server/drizzle/meta/0002_snapshot.json +2722 -0
- package/document-management/server/drizzle/meta/_journal.json +7 -0
- package/document-management/server/services/document-collection.service.js +3 -3
- package/document-management/server/services/document-management-ancillary.service.d.ts +1 -1
- package/document-management/server/services/document-management.service.js +1 -1
- package/document-management/server/services/document-workflow.service.js +5 -5
- package/document-management/server/services/document.service.d.ts +0 -2
- package/document-management/server/services/document.service.js +1 -2
- package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
- package/examples/document-management/main.d.ts +1 -1
- package/examples/document-management/main.js +1 -1
- package/logger/transports/console.d.ts +1 -1
- package/logger/transports/console.js +4 -1
- package/message-bus/message-bus-base.js +1 -1
- package/package.json +8 -5
- package/queue/enqueue-batch.d.ts +11 -11
- package/queue/enqueue-batch.js +2 -3
- package/queue/index.d.ts +1 -0
- package/queue/index.js +1 -0
- package/queue/postgres/drizzle/0003_tricky_venom.sql +30 -0
- package/queue/postgres/drizzle/meta/0003_snapshot.json +288 -0
- package/queue/postgres/drizzle/meta/_journal.json +7 -0
- package/queue/postgres/drizzle.config.js +2 -2
- package/queue/postgres/index.d.ts +1 -1
- package/queue/postgres/index.js +1 -1
- package/queue/postgres/module.d.ts +1 -1
- package/queue/postgres/module.js +1 -1
- package/queue/postgres/queue.d.ts +52 -23
- package/queue/postgres/queue.js +582 -64
- package/queue/postgres/queue.provider.d.ts +1 -1
- package/queue/postgres/schemas.d.ts +13 -2
- package/queue/postgres/schemas.js +4 -2
- package/queue/postgres/task.model.d.ts +24 -0
- package/queue/postgres/task.model.js +115 -0
- package/queue/provider.d.ts +1 -1
- package/queue/queue.d.ts +158 -37
- package/queue/queue.js +97 -19
- package/queue/task-context.d.ts +38 -0
- package/queue/task-context.js +102 -0
- package/queue/tests/queue.test.d.ts +1 -0
- package/queue/tests/queue.test.js +623 -0
- package/test4.d.ts +1 -1
- package/test4.js +1 -1
- package/utils/format-error.d.ts +17 -20
- package/utils/format-error.js +105 -47
- package/queue/postgres/job.model.d.ts +0 -12
- package/queue/postgres/job.model.js +0 -53
- package/test6.js +0 -33
- /package/{test6.d.ts → circuit-breaker/tests/circuit-breaker.test.d.ts} +0 -0
|
@@ -1,25 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the visual formatting style for a list of instructions.
|
|
3
|
+
* - `sections`: Renders keys as Markdown headers (e.g., `# Header`).
|
|
4
|
+
* - `ordered`: Renders items as a numbered list (e.g., `1. Item`).
|
|
5
|
+
* - `unordered`: Renders items as a bulleted list (e.g., `- Item`).
|
|
6
|
+
*/
|
|
1
7
|
export type ListStyle = 'sections' | 'ordered' | 'unordered';
|
|
2
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The content of an instructions list, which can be either:
|
|
10
|
+
* - An array of strings (simple list items).
|
|
11
|
+
* - A nested `Instructions` object (key-value pairs or further lists).
|
|
12
|
+
*/
|
|
13
|
+
export type InstructionsListContent = string[] | Instructions;
|
|
14
|
+
/**
|
|
15
|
+
* A container representing a specific grouping of instructions with a defined style.
|
|
16
|
+
* This is usually created via factory functions like `sections()`, `orderedList()`, or `unorderedList()`.
|
|
17
|
+
*/
|
|
3
18
|
export type InstructionsList = {
|
|
19
|
+
/** The rendering style to apply to this group. */
|
|
4
20
|
style: ListStyle;
|
|
21
|
+
/** An optional high-level instruction or description associated with this group. */
|
|
5
22
|
instruction?: string;
|
|
23
|
+
/** The content of the list, either an array of strings or a nested key-value map. */
|
|
6
24
|
items: InstructionsListContent;
|
|
7
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* A recursive dictionary structure for defining structured instructions.
|
|
28
|
+
* Keys typically represent labels or headers, while values represent the content.
|
|
29
|
+
*/
|
|
8
30
|
export type Instructions = {
|
|
9
31
|
[key: string]: string | string[] | InstructionsList | Instructions;
|
|
10
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Creates a container where content is rendered as Markdown sections.
|
|
35
|
+
* Keys in the object map become headers (e.g., `# Key`), and nested items reset indentation.
|
|
36
|
+
*
|
|
37
|
+
* @param items - The content of the section.
|
|
38
|
+
*/
|
|
11
39
|
export declare function sections(items: InstructionsListContent): InstructionsList;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a container where content is rendered as Markdown sections with a preamble.
|
|
42
|
+
*
|
|
43
|
+
* @param instruction - A general instruction describing this section.
|
|
44
|
+
* @param items - The content of the section.
|
|
45
|
+
*/
|
|
12
46
|
export declare function sections(instruction: string, items: InstructionsListContent): InstructionsList;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a container rendered as a numbered list.
|
|
49
|
+
*
|
|
50
|
+
* @param items - The list items or map.
|
|
51
|
+
*/
|
|
13
52
|
export declare function orderedList(items: InstructionsListContent): InstructionsList;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a container rendered as a numbered list with a preamble.
|
|
55
|
+
*
|
|
56
|
+
* @param instruction - An instruction describing the list.
|
|
57
|
+
* @param items - The list items or map.
|
|
58
|
+
*/
|
|
14
59
|
export declare function orderedList(instruction: string, items: InstructionsListContent): InstructionsList;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a container rendered as a bulleted list.
|
|
62
|
+
*
|
|
63
|
+
* @param items - The list items or map.
|
|
64
|
+
*/
|
|
15
65
|
export declare function unorderedList(items: InstructionsListContent): InstructionsList;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a container rendered as a bulleted list with a preamble.
|
|
68
|
+
*
|
|
69
|
+
* @param instruction - An instruction describing the list.
|
|
70
|
+
* @param items - The list items or map.
|
|
71
|
+
*/
|
|
16
72
|
export declare function unorderedList(instruction: string, items: InstructionsListContent): InstructionsList;
|
|
17
73
|
/**
|
|
18
|
-
* Formats instructions into a string representation suitable for AI prompts.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
74
|
+
* Formats a structured instructions object into a string representation suitable for AI prompts (Markdown).
|
|
75
|
+
*
|
|
76
|
+
* It recursively handles:
|
|
77
|
+
* - `sections`: Creates headers (H1, H2...).
|
|
78
|
+
* - `ordered` / `unordered`: Creates indented lists.
|
|
79
|
+
* - `Instructions`: Objects are formatted as key-value pairs (e.g., `- **Key:** Value`).
|
|
80
|
+
*
|
|
81
|
+
* @param node - The root instructions object, array, or instructions list wrapper.
|
|
82
|
+
* @param options - Formatting options.
|
|
83
|
+
* @param options.initialDepth - The starting indentation level (default: 0).
|
|
84
|
+
* @returns A formatted string.
|
|
21
85
|
*/
|
|
22
86
|
export declare function formatInstructions(node: Instructions | InstructionsList | string[], options?: {
|
|
23
87
|
initialDepth?: number;
|
|
24
88
|
}): string;
|
|
25
|
-
export {};
|
|
@@ -146,9 +146,17 @@ function processNode(node, context) {
|
|
|
146
146
|
}).join(separator);
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
-
* Formats instructions into a string representation suitable for AI prompts.
|
|
150
|
-
*
|
|
151
|
-
*
|
|
149
|
+
* Formats a structured instructions object into a string representation suitable for AI prompts (Markdown).
|
|
150
|
+
*
|
|
151
|
+
* It recursively handles:
|
|
152
|
+
* - `sections`: Creates headers (H1, H2...).
|
|
153
|
+
* - `ordered` / `unordered`: Creates indented lists.
|
|
154
|
+
* - `Instructions`: Objects are formatted as key-value pairs (e.g., `- **Key:** Value`).
|
|
155
|
+
*
|
|
156
|
+
* @param node - The root instructions object, array, or instructions list wrapper.
|
|
157
|
+
* @param options - Formatting options.
|
|
158
|
+
* @param options.initialDepth - The starting indentation level (default: 0).
|
|
159
|
+
* @returns A formatted string.
|
|
152
160
|
*/
|
|
153
161
|
export function formatInstructions(node, options = {}) {
|
|
154
162
|
// Heuristic: If passing a raw object, assume it's a Root Section unless specified otherwise.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { firstValueFrom } from 'rxjs';
|
|
1
|
+
import { firstValueFrom, timeout } from 'rxjs';
|
|
2
2
|
import { cacheValueOrAsyncProvider } from '../../utils/value-or-provider.js';
|
|
3
3
|
import { dontWaitForValidToken } from '../authentication.api.js';
|
|
4
4
|
/**
|
|
@@ -13,7 +13,7 @@ export function waitForAuthenticationCredentialsMiddleware(authenticationService
|
|
|
13
13
|
if ((endpoint?.credentials == true) && (endpoint.data?.[dontWaitForValidToken] != true)) {
|
|
14
14
|
const authenticationService = await getAuthenticationService();
|
|
15
15
|
while (!authenticationService.hasValidToken) {
|
|
16
|
-
await firstValueFrom(authenticationService.validToken
|
|
16
|
+
await firstValueFrom(authenticationService.validToken$.pipe(timeout(30000)));
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
await next();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Entity } from '../../orm/index.js';
|
|
1
|
+
import { Entity, type Uuid } from '../../orm/index.js';
|
|
2
2
|
export declare class AuthenticationCredentials extends Entity {
|
|
3
|
-
subject:
|
|
3
|
+
subject: Uuid;
|
|
4
4
|
hashVersion: number;
|
|
5
5
|
/**
|
|
6
6
|
* The salt used to hash the secret.
|
|
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Entity, Table, Unique } from '../../orm/index.js';
|
|
11
|
-
import { Integer,
|
|
10
|
+
import { Entity, Reference, Table, Unique, UuidProperty } from '../../orm/index.js';
|
|
11
|
+
import { Integer, Uint8ArrayProperty } from '../../schema/index.js';
|
|
12
|
+
import { Subject } from './subject.model.js';
|
|
12
13
|
let AuthenticationCredentials = class AuthenticationCredentials extends Entity {
|
|
13
14
|
subject;
|
|
14
15
|
hashVersion;
|
|
@@ -22,8 +23,9 @@ let AuthenticationCredentials = class AuthenticationCredentials extends Entity {
|
|
|
22
23
|
hash;
|
|
23
24
|
};
|
|
24
25
|
__decorate([
|
|
25
|
-
|
|
26
|
+
Reference(() => Subject),
|
|
26
27
|
Unique(),
|
|
28
|
+
UuidProperty(),
|
|
27
29
|
__metadata("design:type", String)
|
|
28
30
|
], AuthenticationCredentials.prototype, "subject", void 0);
|
|
29
31
|
__decorate([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Timestamp } from '../../orm/index.js';
|
|
1
|
+
import type { Timestamp, Uuid } from '../../orm/index.js';
|
|
2
2
|
import { Entity } from '../../orm/index.js';
|
|
3
3
|
export declare class AuthenticationSession extends Entity {
|
|
4
|
-
subject:
|
|
4
|
+
subject: Uuid;
|
|
5
5
|
begin: Timestamp;
|
|
6
6
|
end: Timestamp;
|
|
7
7
|
refreshTokenHashVersion: number;
|
|
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { Entity, Table, TimestampProperty } from '../../orm/index.js';
|
|
11
|
-
import { Integer,
|
|
10
|
+
import { Entity, Reference, Table, TimestampProperty, UuidProperty } from '../../orm/index.js';
|
|
11
|
+
import { Integer, Uint8ArrayProperty } from '../../schema/index.js';
|
|
12
|
+
import { Subject } from './subject.model.js';
|
|
12
13
|
let AuthenticationSession = class AuthenticationSession extends Entity {
|
|
13
14
|
subject;
|
|
14
15
|
begin;
|
|
@@ -24,7 +25,8 @@ let AuthenticationSession = class AuthenticationSession extends Entity {
|
|
|
24
25
|
refreshTokenHash;
|
|
25
26
|
};
|
|
26
27
|
__decorate([
|
|
27
|
-
|
|
28
|
+
Reference(() => Subject),
|
|
29
|
+
UuidProperty(),
|
|
28
30
|
__metadata("design:type", String)
|
|
29
31
|
], AuthenticationSession.prototype, "subject", void 0);
|
|
30
32
|
__decorate([
|
|
@@ -2,5 +2,9 @@ export * from './authentication-credentials.model.js';
|
|
|
2
2
|
export * from './authentication-session.model.js';
|
|
3
3
|
export * from './init-secret-reset-data.model.js';
|
|
4
4
|
export * from './secret-check-result.model.js';
|
|
5
|
+
export * from './service-account.model.js';
|
|
6
|
+
export * from './subject.model.js';
|
|
7
|
+
export * from './system-account.model.js';
|
|
5
8
|
export * from './token-payload-base.model.js';
|
|
6
9
|
export * from './token.model.js';
|
|
10
|
+
export * from './user.model.js';
|
|
@@ -2,5 +2,9 @@ export * from './authentication-credentials.model.js';
|
|
|
2
2
|
export * from './authentication-session.model.js';
|
|
3
3
|
export * from './init-secret-reset-data.model.js';
|
|
4
4
|
export * from './secret-check-result.model.js';
|
|
5
|
+
export * from './service-account.model.js';
|
|
6
|
+
export * from './subject.model.js';
|
|
7
|
+
export * from './system-account.model.js';
|
|
5
8
|
export * from './token-payload-base.model.js';
|
|
6
9
|
export * from './token.model.js';
|
|
10
|
+
export * from './user.model.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
2
|
+
import { Subject } from './subject.model.js';
|
|
3
|
+
export declare class ServiceAccount extends TenantEntity {
|
|
4
|
+
description: string;
|
|
5
|
+
/** Who owns this service account? If null, it is a tenant-wide service account. */
|
|
6
|
+
parent: Subject | null;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
11
|
+
import { Table, TenantReference, UuidProperty } from '../../orm/index.js';
|
|
12
|
+
import { StringProperty } from '../../schema/index.js';
|
|
13
|
+
import { Subject } from './subject.model.js';
|
|
14
|
+
let ServiceAccount = class ServiceAccount extends TenantEntity {
|
|
15
|
+
description;
|
|
16
|
+
/** Who owns this service account? If null, it is a tenant-wide service account. */
|
|
17
|
+
parent;
|
|
18
|
+
};
|
|
19
|
+
__decorate([
|
|
20
|
+
StringProperty(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], ServiceAccount.prototype, "description", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
TenantReference(() => Subject),
|
|
25
|
+
UuidProperty({ nullable: true }),
|
|
26
|
+
__metadata("design:type", Object)
|
|
27
|
+
], ServiceAccount.prototype, "parent", void 0);
|
|
28
|
+
ServiceAccount = __decorate([
|
|
29
|
+
Table('service_account', { schema: 'authentication' })
|
|
30
|
+
], ServiceAccount);
|
|
31
|
+
export { ServiceAccount };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type EnumType } from '../../enumeration/enumeration.js';
|
|
2
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
3
|
+
import { type Uuid } from '../../orm/index.js';
|
|
4
|
+
export declare const SubjectType: {
|
|
5
|
+
readonly System: "system";
|
|
6
|
+
readonly User: "user";
|
|
7
|
+
readonly ServiceAccount: "service-account";
|
|
8
|
+
};
|
|
9
|
+
export type SubjectType = EnumType<typeof SubjectType>;
|
|
10
|
+
export declare class Subject extends TenantEntity {
|
|
11
|
+
type: SubjectType;
|
|
12
|
+
displayName: string;
|
|
13
|
+
systemAccountId: Uuid | null;
|
|
14
|
+
userId: Uuid | null;
|
|
15
|
+
serviceAccountId: Uuid | null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { defineEnum } from '../../enumeration/enumeration.js';
|
|
11
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
12
|
+
import { Check, exclusiveNotNull, Table, TenantReference, Unique, UuidProperty } from '../../orm/index.js';
|
|
13
|
+
import { Enumeration, StringProperty } from '../../schema/index.js';
|
|
14
|
+
import { ServiceAccount } from './service-account.model.js';
|
|
15
|
+
import { SystemAccount } from './system-account.model.js';
|
|
16
|
+
import { User } from './user.model.js';
|
|
17
|
+
export const SubjectType = defineEnum('SubjectType', {
|
|
18
|
+
System: 'system',
|
|
19
|
+
User: 'user',
|
|
20
|
+
ServiceAccount: 'service-account',
|
|
21
|
+
});
|
|
22
|
+
let Subject = class Subject extends TenantEntity {
|
|
23
|
+
type;
|
|
24
|
+
displayName;
|
|
25
|
+
systemAccountId;
|
|
26
|
+
userId;
|
|
27
|
+
serviceAccountId;
|
|
28
|
+
};
|
|
29
|
+
__decorate([
|
|
30
|
+
Enumeration(SubjectType),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], Subject.prototype, "type", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
StringProperty(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], Subject.prototype, "displayName", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
Unique(),
|
|
39
|
+
TenantReference(() => SystemAccount),
|
|
40
|
+
UuidProperty({ nullable: true }),
|
|
41
|
+
__metadata("design:type", Object)
|
|
42
|
+
], Subject.prototype, "systemAccountId", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
Unique(),
|
|
45
|
+
TenantReference(() => User),
|
|
46
|
+
UuidProperty({ nullable: true }),
|
|
47
|
+
__metadata("design:type", Object)
|
|
48
|
+
], Subject.prototype, "userId", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
Unique(),
|
|
51
|
+
TenantReference(() => ServiceAccount),
|
|
52
|
+
UuidProperty({ nullable: true }),
|
|
53
|
+
__metadata("design:type", Object)
|
|
54
|
+
], Subject.prototype, "serviceAccountId", void 0);
|
|
55
|
+
Subject = __decorate([
|
|
56
|
+
Table('subject', { schema: 'authentication' }),
|
|
57
|
+
Check('authentication_subject_reference_check', (table) => exclusiveNotNull(table.systemAccountId, table.userId, table.serviceAccountId))
|
|
58
|
+
], Subject);
|
|
59
|
+
export { Subject };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
11
|
+
import { Table, Unique } from '../../orm/index.js';
|
|
12
|
+
import { StringProperty } from '../../schema/index.js';
|
|
13
|
+
let SystemAccount = class SystemAccount extends TenantEntity {
|
|
14
|
+
/** Programmatic name: 'cleanup-task', 'ai-agent' */
|
|
15
|
+
identifier;
|
|
16
|
+
};
|
|
17
|
+
__decorate([
|
|
18
|
+
Unique(),
|
|
19
|
+
StringProperty(),
|
|
20
|
+
__metadata("design:type", String)
|
|
21
|
+
], SystemAccount.prototype, "identifier", void 0);
|
|
22
|
+
SystemAccount = __decorate([
|
|
23
|
+
Table('system_account', { schema: 'authentication' })
|
|
24
|
+
], SystemAccount);
|
|
25
|
+
export { SystemAccount };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type EnumType } from '../../enumeration/enumeration.js';
|
|
2
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
3
|
+
export declare const UserStatus: {
|
|
4
|
+
readonly Active: "active";
|
|
5
|
+
readonly Suspended: "suspended";
|
|
6
|
+
readonly PendingApproval: "pending-approval";
|
|
7
|
+
readonly Invited: "invited";
|
|
8
|
+
};
|
|
9
|
+
export type UserStatus = EnumType<typeof UserStatus>;
|
|
10
|
+
export declare class User extends TenantEntity {
|
|
11
|
+
status: UserStatus;
|
|
12
|
+
email: string;
|
|
13
|
+
firstName: string;
|
|
14
|
+
lastName: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { defineEnum } from '../../enumeration/enumeration.js';
|
|
11
|
+
import { TenantEntity } from '../../orm/entity.js';
|
|
12
|
+
import { Table, Unique } from '../../orm/index.js';
|
|
13
|
+
import { Enumeration, StringProperty } from '../../schema/index.js';
|
|
14
|
+
import { mailPattern } from '../../utils/patterns.js';
|
|
15
|
+
export const UserStatus = defineEnum('UserStatus', {
|
|
16
|
+
Active: 'active',
|
|
17
|
+
Suspended: 'suspended',
|
|
18
|
+
PendingApproval: 'pending-approval',
|
|
19
|
+
Invited: 'invited',
|
|
20
|
+
});
|
|
21
|
+
let User = class User extends TenantEntity {
|
|
22
|
+
status;
|
|
23
|
+
email;
|
|
24
|
+
firstName;
|
|
25
|
+
lastName;
|
|
26
|
+
};
|
|
27
|
+
__decorate([
|
|
28
|
+
Enumeration(UserStatus),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], User.prototype, "status", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
StringProperty({ pattern: mailPattern }),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], User.prototype, "email", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
StringProperty(),
|
|
37
|
+
__metadata("design:type", String)
|
|
38
|
+
], User.prototype, "firstName", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
StringProperty(),
|
|
41
|
+
__metadata("design:type", String)
|
|
42
|
+
], User.prototype, "lastName", void 0);
|
|
43
|
+
User = __decorate([
|
|
44
|
+
Table('user', { schema: 'authentication' }),
|
|
45
|
+
Unique(['tenantId', 'email'])
|
|
46
|
+
], User);
|
|
47
|
+
export { User };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
CREATE TYPE "authentication"."subject_type" AS ENUM('system', 'user', 'service-account');--> statement-breakpoint
|
|
2
|
+
CREATE TYPE "authentication"."user_status" AS ENUM('active', 'suspended', 'pending-approval', 'invited');--> statement-breakpoint
|
|
3
|
+
CREATE TABLE "authentication"."service_account" (
|
|
4
|
+
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
5
|
+
"tenant_id" uuid NOT NULL,
|
|
6
|
+
"description" text NOT NULL,
|
|
7
|
+
"parent" uuid,
|
|
8
|
+
"revision" integer NOT NULL,
|
|
9
|
+
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
10
|
+
"create_timestamp" timestamp with time zone NOT NULL,
|
|
11
|
+
"delete_timestamp" timestamp with time zone,
|
|
12
|
+
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
13
|
+
CONSTRAINT "service_account_tenant_id_id_pk" PRIMARY KEY("tenant_id","id")
|
|
14
|
+
);
|
|
15
|
+
--> statement-breakpoint
|
|
16
|
+
CREATE TABLE "authentication"."subject" (
|
|
17
|
+
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
18
|
+
"tenant_id" uuid NOT NULL,
|
|
19
|
+
"type" "authentication"."subject_type" NOT NULL,
|
|
20
|
+
"display_name" text NOT NULL,
|
|
21
|
+
"system_account_id" uuid,
|
|
22
|
+
"user_id" uuid,
|
|
23
|
+
"service_account_id" uuid,
|
|
24
|
+
"revision" integer NOT NULL,
|
|
25
|
+
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
26
|
+
"create_timestamp" timestamp with time zone NOT NULL,
|
|
27
|
+
"delete_timestamp" timestamp with time zone,
|
|
28
|
+
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
29
|
+
CONSTRAINT "subject_tenant_id_id_pk" PRIMARY KEY("tenant_id","id"),
|
|
30
|
+
CONSTRAINT "subject_system_account_id_unique" UNIQUE("system_account_id"),
|
|
31
|
+
CONSTRAINT "subject_user_id_unique" UNIQUE("user_id"),
|
|
32
|
+
CONSTRAINT "subject_service_account_id_unique" UNIQUE("service_account_id"),
|
|
33
|
+
CONSTRAINT "authentication_subject_reference_check" CHECK (num_nonnulls("authentication"."subject"."system_account_id", "authentication"."subject"."user_id", "authentication"."subject"."service_account_id") = 1)
|
|
34
|
+
);
|
|
35
|
+
--> statement-breakpoint
|
|
36
|
+
CREATE TABLE "authentication"."system_account" (
|
|
37
|
+
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
38
|
+
"tenant_id" uuid NOT NULL,
|
|
39
|
+
"identifier" text NOT NULL,
|
|
40
|
+
"revision" integer NOT NULL,
|
|
41
|
+
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
42
|
+
"create_timestamp" timestamp with time zone NOT NULL,
|
|
43
|
+
"delete_timestamp" timestamp with time zone,
|
|
44
|
+
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
45
|
+
CONSTRAINT "system_account_tenant_id_id_pk" PRIMARY KEY("tenant_id","id"),
|
|
46
|
+
CONSTRAINT "system_account_identifier_unique" UNIQUE("identifier")
|
|
47
|
+
);
|
|
48
|
+
--> statement-breakpoint
|
|
49
|
+
CREATE TABLE "authentication"."user" (
|
|
50
|
+
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
|
51
|
+
"tenant_id" uuid NOT NULL,
|
|
52
|
+
"status" "authentication"."user_status" NOT NULL,
|
|
53
|
+
"email" text NOT NULL,
|
|
54
|
+
"first_name" text NOT NULL,
|
|
55
|
+
"last_name" text NOT NULL,
|
|
56
|
+
"revision" integer NOT NULL,
|
|
57
|
+
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
58
|
+
"create_timestamp" timestamp with time zone NOT NULL,
|
|
59
|
+
"delete_timestamp" timestamp with time zone,
|
|
60
|
+
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
61
|
+
CONSTRAINT "user_tenant_id_id_pk" PRIMARY KEY("tenant_id","id"),
|
|
62
|
+
CONSTRAINT "user_tenant_id_email_unique" UNIQUE("tenant_id","email")
|
|
63
|
+
);
|
|
64
|
+
--> statement-breakpoint
|
|
65
|
+
ALTER TABLE "authentication"."credentials" ALTER COLUMN "subject" SET DATA TYPE uuid;--> statement-breakpoint
|
|
66
|
+
ALTER TABLE "authentication"."session" ALTER COLUMN "subject" SET DATA TYPE uuid;--> statement-breakpoint
|
|
67
|
+
ALTER TABLE "authentication"."service_account" ADD CONSTRAINT "service_account_id_fkey" FOREIGN KEY ("tenant_id","parent") REFERENCES "authentication"."subject"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
68
|
+
ALTER TABLE "authentication"."subject" ADD CONSTRAINT "subject_id_fkey" FOREIGN KEY ("tenant_id","service_account_id") REFERENCES "authentication"."service_account"("tenant_id","id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
69
|
+
ALTER TABLE "authentication"."credentials" ADD CONSTRAINT "credentials_subject_subject_id_fk" FOREIGN KEY ("subject") REFERENCES "authentication"."subject"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
|
70
|
+
ALTER TABLE "authentication"."session" ADD CONSTRAINT "session_subject_subject_id_fk" FOREIGN KEY ("subject") REFERENCES "authentication"."subject"("id") ON DELETE no action ON UPDATE no action;
|