@getstrata/core 2.2.47 → 2.2.48
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/CHANGELOG.md +7 -0
- package/dist/core/auth/membershipService.d.ts +3 -23
- package/dist/core/auth/membershipServiceImplementation.d.ts +22 -0
- package/dist/core/auth/resolveMembershipService.d.ts +1 -1
- package/dist/core/contracts/container.d.ts +2 -0
- package/dist/core/database/baseRepository.d.ts +3 -20
- package/dist/core/database/boundConnection.d.ts +1 -1
- package/dist/core/database/bunSql.d.ts +1 -1
- package/dist/core/database/connection.d.ts +1 -1
- package/dist/core/database/connectionContracts.d.ts +21 -0
- package/dist/core/database/defaultConnection.d.ts +1 -1
- package/dist/core/database/index.d.ts +1 -1
- package/dist/core/database/isolatedReadOnlyObservation.d.ts +1 -1
- package/dist/core/database/mysqlConnection.d.ts +1 -1
- package/dist/core/database/queryProxy.d.ts +1 -1
- package/dist/core/database/repositoryConnection.d.ts +1 -1
- package/dist/core/database/sqliteConnection.d.ts +1 -1
- package/dist/core/database/transaction.d.ts +1 -1
- package/dist/entries/auth/basicAuthGuard.js +14 -2
- package/dist/entries/auth/jwtGuard.js +14 -2
- package/dist/entries/auth/membershipService.js +13 -14
- package/dist/entries/auth/scimAuthMiddleware.js +3 -0
- package/dist/entries/auth/sessionGuard.js +14 -2
- package/dist/entries/config/envSchema.js +2 -1
- package/dist/entries/contracts/container.js +14 -2
- package/dist/entries/contracts/serviceTokens.js +14 -2
- package/dist/framework/public-api.d.ts +1 -1
- package/dist/index.js +77 -63
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @getstrata/core changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.48
|
|
4
|
+
|
|
5
|
+
- Validate complete integer environment values instead of accepting partial numeric strings; retain documented defaults, signs and minimum checks.
|
|
6
|
+
- Add the protected `BaseRepository.cloneWithConnection()` construction hook for custom repositories with native private state. Keep the default legacy rebinding behavior and avoid rerunning application constructors implicitly; concrete subclasses own their construction override.
|
|
7
|
+
- Separate database connection capability contracts and membership lookup internals while retaining existing exports, constructors and service identity.
|
|
8
|
+
- Report synchronous dependency-resolution cycles with their service path and clean resolution state after failure, preserving singleton and transient behavior.
|
|
9
|
+
|
|
3
10
|
## 2.2.47
|
|
4
11
|
|
|
5
12
|
- Align the package version with the starter/CLI correction batch; no core runtime behavior changes.
|
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare class MembershipService {
|
|
5
|
-
private readonly members;
|
|
6
|
-
constructor(members?: MembershipRepositoryLike);
|
|
7
|
-
listOrganizationIdsForUser(userId: number): Promise<number[]>;
|
|
8
|
-
getOrgRole(userId: number, organizationId: number): Promise<OrganizationMemberRole | null>;
|
|
9
|
-
requireOrgAccess(organizationId: number, minimumRole?: OrganizationMemberRole, user?: AuthUser | null): Promise<OrganizationMemberRole>;
|
|
10
|
-
filterAccessibleOrganizationIds(organizationIds: number[], user?: AuthUser | null): Promise<number[]>;
|
|
11
|
-
addOwnerOnOrganizationCreate(organizationId: number, userId: number): Promise<void>;
|
|
12
|
-
listMembersForOrganization(organizationId: number): Promise<import("../contracts/membership").MembershipRecord[]>;
|
|
13
|
-
addMember(input: {
|
|
14
|
-
organizationId: number;
|
|
15
|
-
userId: number;
|
|
16
|
-
role?: OrganizationMemberRole;
|
|
17
|
-
}): Promise<import("../contracts/membership").MembershipRecord>;
|
|
18
|
-
removeMember(organizationId: number, userId: number): Promise<unknown>;
|
|
19
|
-
updateMemberRole(organizationId: number, userId: number, role: OrganizationMemberRole): Promise<import("../contracts/membership").MembershipRecord>;
|
|
20
|
-
}
|
|
21
|
-
export type { MembershipRepositoryLike };
|
|
22
|
-
export default MembershipService;
|
|
23
|
-
export { resolveMembershipService } from "./resolveMembershipService.ts";
|
|
1
|
+
export type { MembershipRepositoryLike } from "./membershipServiceImplementation";
|
|
2
|
+
export { default } from "./membershipServiceImplementation";
|
|
3
|
+
export { resolveMembershipService } from "./resolveMembershipService";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MembershipLookup, OrganizationMemberRole } from "../contracts/membership";
|
|
2
|
+
import { type AuthUser } from "./authContext";
|
|
3
|
+
type MembershipRepositoryLike = MembershipLookup;
|
|
4
|
+
declare class MembershipService {
|
|
5
|
+
private readonly members;
|
|
6
|
+
constructor(members?: MembershipRepositoryLike);
|
|
7
|
+
listOrganizationIdsForUser(userId: number): Promise<number[]>;
|
|
8
|
+
getOrgRole(userId: number, organizationId: number): Promise<OrganizationMemberRole | null>;
|
|
9
|
+
requireOrgAccess(organizationId: number, minimumRole?: OrganizationMemberRole, user?: AuthUser | null): Promise<OrganizationMemberRole>;
|
|
10
|
+
filterAccessibleOrganizationIds(organizationIds: number[], user?: AuthUser | null): Promise<number[]>;
|
|
11
|
+
addOwnerOnOrganizationCreate(organizationId: number, userId: number): Promise<void>;
|
|
12
|
+
listMembersForOrganization(organizationId: number): Promise<import("../contracts/membership").MembershipRecord[]>;
|
|
13
|
+
addMember(input: {
|
|
14
|
+
organizationId: number;
|
|
15
|
+
userId: number;
|
|
16
|
+
role?: OrganizationMemberRole;
|
|
17
|
+
}): Promise<import("../contracts/membership").MembershipRecord>;
|
|
18
|
+
removeMember(organizationId: number, userId: number): Promise<unknown>;
|
|
19
|
+
updateMemberRole(organizationId: number, userId: number, role: OrganizationMemberRole): Promise<import("../contracts/membership").MembershipRecord>;
|
|
20
|
+
}
|
|
21
|
+
export type { MembershipRepositoryLike };
|
|
22
|
+
export default MembershipService;
|
|
@@ -18,6 +18,7 @@ declare class ServiceContainer implements ServiceContainerLike {
|
|
|
18
18
|
private readonly services;
|
|
19
19
|
private readonly singletonFactories;
|
|
20
20
|
private readonly bindings;
|
|
21
|
+
private readonly resolutionPath;
|
|
21
22
|
set<T>(key: ServiceToken<T>, value: NoInfer<T>): T;
|
|
22
23
|
set<T>(key: LegacyServiceKey, value: T): T;
|
|
23
24
|
singleton<T>(key: ServiceToken<T>, factory: ServiceFactory<NoInfer<T>>): void;
|
|
@@ -26,6 +27,7 @@ declare class ServiceContainer implements ServiceContainerLike {
|
|
|
26
27
|
bind<T>(key: LegacyServiceKey, factory: ServiceFactory<T>): void;
|
|
27
28
|
get<T>(key: ServiceToken<T>): T;
|
|
28
29
|
get<T>(key: LegacyServiceKey): T;
|
|
30
|
+
private resolveFactory;
|
|
29
31
|
resolve<T>(key: ServiceToken<T>): T;
|
|
30
32
|
resolve<T>(key: LegacyServiceKey): T;
|
|
31
33
|
make<T>(key: ServiceToken<T>): T;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { KeysetCursor, KeysetOptions } from "../pagination/index.ts";
|
|
2
2
|
import { type CursorPaginatedResult, type PaginatedResult } from "../pagination/index.ts";
|
|
3
|
+
import type { DatabaseConnection, SqlDatabaseConnection } from "./connectionContracts";
|
|
3
4
|
import { type BelongsToManyRelation, type BelongsToRelation, type HasManyRelation, type HasManyThroughRelation, type MorphManyRelation, type MorphOneRelation, type MorphToRelation } from "./relationships.ts";
|
|
4
5
|
import { RepositoryQuery } from "./repositoryQuery.ts";
|
|
5
6
|
import type { TableDefinition } from "./table.ts";
|
|
@@ -8,26 +9,6 @@ import type { WhereNode } from "./whereBuilder.ts";
|
|
|
8
9
|
type ExtendedQueryOptions<TEntity extends object> = QueryOptions<TEntity> & {
|
|
9
10
|
whereNodes?: WhereNode<TEntity>[];
|
|
10
11
|
};
|
|
11
|
-
interface DatabaseConnection {
|
|
12
|
-
unsafe<T>(query: string, params?: readonly unknown[]): Promise<T[]>;
|
|
13
|
-
begin?<T>(callback: (transaction: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
14
|
-
/** Optional native cancellable pool checkout; absence must not be silently emulated. */
|
|
15
|
-
reserve?(options: {
|
|
16
|
-
signal?: AbortSignal;
|
|
17
|
-
}): Promise<DatabaseConnection & {
|
|
18
|
-
release(): void | Promise<void>;
|
|
19
|
-
}>;
|
|
20
|
-
/** Optional independent, interruptible read-only observation; no business transaction or pool slot. */
|
|
21
|
-
observeReadOnly?<T>(operation: (connection: DatabaseConnection) => Promise<T>, options: {
|
|
22
|
-
signal: AbortSignal;
|
|
23
|
-
timeoutMs: number;
|
|
24
|
-
}): Promise<T>;
|
|
25
|
-
/** SQLite closes synchronously; pooled drivers return a promise. */
|
|
26
|
-
close?(): void | Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
interface SqlDatabaseConnection extends DatabaseConnection {
|
|
29
|
-
(strings: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;
|
|
30
|
-
}
|
|
31
12
|
type ErrorFactory<TValue> = (value: TValue) => Error;
|
|
32
13
|
declare class BaseRepository<TEntity extends object, PrimaryKey extends keyof TEntity & string> {
|
|
33
14
|
protected readonly table: TableDefinition<TEntity, PrimaryKey>;
|
|
@@ -75,6 +56,8 @@ declare class BaseRepository<TEntity extends object, PrimaryKey extends keyof TE
|
|
|
75
56
|
restoreById(id: TEntity[PrimaryKey]): Promise<TEntity | null>;
|
|
76
57
|
private primaryKeySeekDirection;
|
|
77
58
|
withConnection(connection: DatabaseConnection): this;
|
|
59
|
+
/** Override when constructor initialization or native private fields must be preserved. */
|
|
60
|
+
protected cloneWithConnection(connection: DatabaseConnection): this;
|
|
78
61
|
getConnection(): DatabaseConnection;
|
|
79
62
|
getTable(): TableDefinition<TEntity, PrimaryKey>;
|
|
80
63
|
query(where?: QueryWhere<TEntity>): RepositoryQuery<TEntity, PrimaryKey>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DatabaseConnection } from "./
|
|
1
|
+
import type { DatabaseConnection } from "./connectionContracts";
|
|
2
2
|
declare function bindDatabaseConnection(connection: DatabaseConnection): void;
|
|
3
3
|
declare function getBoundDatabaseConnection(): DatabaseConnection | null;
|
|
4
4
|
declare function resetBoundDatabaseConnection(): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface DatabaseConnection {
|
|
2
|
+
unsafe<T>(query: string, params?: readonly unknown[]): Promise<T[]>;
|
|
3
|
+
begin?<T>(callback: (transaction: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
4
|
+
/** Optional native cancellable pool checkout; absence must not be silently emulated. */
|
|
5
|
+
reserve?(options: {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}): Promise<DatabaseConnection & {
|
|
8
|
+
release(): void | Promise<void>;
|
|
9
|
+
}>;
|
|
10
|
+
/** Optional independent, interruptible read-only observation; no business transaction or pool slot. */
|
|
11
|
+
observeReadOnly?<T>(operation: (connection: DatabaseConnection) => Promise<T>, options: {
|
|
12
|
+
signal: AbortSignal;
|
|
13
|
+
timeoutMs: number;
|
|
14
|
+
}): Promise<T>;
|
|
15
|
+
/** SQLite closes synchronously; pooled drivers return a promise. */
|
|
16
|
+
close?(): void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
interface SqlDatabaseConnection extends DatabaseConnection {
|
|
19
|
+
(strings: TemplateStringsArray, ...values: unknown[]): Promise<unknown[]>;
|
|
20
|
+
}
|
|
21
|
+
export type { DatabaseConnection, SqlDatabaseConnection };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SqlDatabaseConnection } from "./
|
|
1
|
+
import type { SqlDatabaseConnection } from "./connectionContracts";
|
|
2
2
|
declare function registerDefaultDatabasePool(connection: SqlDatabaseConnection): void;
|
|
3
3
|
declare function getDefaultDatabasePool(): SqlDatabaseConnection;
|
|
4
4
|
declare function getDefaultDatabaseQuery(): SqlDatabaseConnection;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export type { DatabaseConnection } from "./baseRepository.ts";
|
|
2
1
|
export { default as BaseRepository } from "./baseRepository.ts";
|
|
3
2
|
export { createDatabaseConnection } from "./connection.ts";
|
|
4
3
|
export type { ActiveDatabaseHandle } from "./connectionContext.ts";
|
|
5
4
|
export { getActiveDatabaseConnection, hasActiveDatabaseConnection, runWithDatabaseConnection, } from "./connectionContext.ts";
|
|
5
|
+
export type { DatabaseConnection } from "./connectionContracts.ts";
|
|
6
6
|
export type { SqlDialect } from "./dialect.ts";
|
|
7
7
|
export { currentSqlDialect, dialectFor, resetSqlDialect, runWithSqlDialect, useSqlDialect, } from "./dialect.ts";
|
|
8
8
|
export { mapDatabaseError, withDatabaseErrorHandling } from "./errors.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DatabaseConnection } from "./baseRepository.ts";
|
|
2
1
|
import { type ActiveDatabaseHandle } from "./connectionContext.ts";
|
|
2
|
+
import type { DatabaseConnection } from "./connectionContracts.ts";
|
|
3
3
|
import { type ReadOnlyObservationOptions } from "./isolatedReadOnlyObservation.ts";
|
|
4
4
|
type MysqlExecutable = {
|
|
5
5
|
execute: (sql: string, params?: unknown[]) => Promise<[unknown, unknown]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SqlDatabaseConnection } from "./
|
|
1
|
+
import type { SqlDatabaseConnection } from "./connectionContracts";
|
|
2
2
|
declare function resolveRepositoryConnection(): SqlDatabaseConnection;
|
|
3
3
|
declare const repositoryConnection: SqlDatabaseConnection;
|
|
4
4
|
export { repositoryConnection, resolveRepositoryConnection };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DatabaseConnection } from "./baseRepository.ts";
|
|
2
1
|
import { type ActiveDatabaseHandle } from "./connectionContext.ts";
|
|
2
|
+
import type { DatabaseConnection } from "./connectionContracts.ts";
|
|
3
3
|
import { type ReadOnlyObservationOptions } from "./isolatedReadOnlyObservation.ts";
|
|
4
4
|
type SqliteConnection = ActiveDatabaseHandle & {
|
|
5
5
|
begin<T>(callback: (transaction: ActiveDatabaseHandle) => Promise<T>): Promise<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterCommit } from "../events/deferredModelEvents.ts";
|
|
2
2
|
import { type TransactionAcquisitionMetrics } from "./acquisitionMetrics.ts";
|
|
3
|
-
import type { DatabaseConnection } from "./
|
|
3
|
+
import type { DatabaseConnection } from "./connectionContracts.ts";
|
|
4
4
|
import { hasActiveTransaction, requestTransactionRollback } from "./transactionControl.ts";
|
|
5
5
|
/** Recognizes the callback handle without admitting an unrelated pool. */
|
|
6
6
|
declare function isActiveTransactionConnection(connection: DatabaseConnection): boolean;
|
|
@@ -924,6 +924,7 @@ class ServiceContainer {
|
|
|
924
924
|
services = new Map;
|
|
925
925
|
singletonFactories = new Map;
|
|
926
926
|
bindings = new Map;
|
|
927
|
+
resolutionPath = [];
|
|
927
928
|
set(key, value) {
|
|
928
929
|
this.singletonFactories.delete(key);
|
|
929
930
|
this.bindings.delete(key);
|
|
@@ -946,16 +947,27 @@ class ServiceContainer {
|
|
|
946
947
|
}
|
|
947
948
|
const singletonFactory = this.singletonFactories.get(key);
|
|
948
949
|
if (singletonFactory) {
|
|
949
|
-
const value = singletonFactory
|
|
950
|
+
const value = this.resolveFactory(key, singletonFactory);
|
|
950
951
|
this.services.set(key, value);
|
|
951
952
|
return value;
|
|
952
953
|
}
|
|
953
954
|
const binding = this.bindings.get(key);
|
|
954
955
|
if (binding) {
|
|
955
|
-
return binding
|
|
956
|
+
return this.resolveFactory(key, binding);
|
|
956
957
|
}
|
|
957
958
|
throw new Error(`Service "${key}" is not registered.`);
|
|
958
959
|
}
|
|
960
|
+
resolveFactory(key, factory) {
|
|
961
|
+
if (this.resolutionPath.includes(key)) {
|
|
962
|
+
throw new Error(`Circular service dependency: ${[...this.resolutionPath, key].join(" -> ")}.`);
|
|
963
|
+
}
|
|
964
|
+
this.resolutionPath.push(key);
|
|
965
|
+
try {
|
|
966
|
+
return factory(this);
|
|
967
|
+
} finally {
|
|
968
|
+
this.resolutionPath.pop();
|
|
969
|
+
}
|
|
970
|
+
}
|
|
959
971
|
resolve(key) {
|
|
960
972
|
return this.get(key);
|
|
961
973
|
}
|
|
@@ -10,6 +10,7 @@ class ServiceContainer {
|
|
|
10
10
|
services = new Map;
|
|
11
11
|
singletonFactories = new Map;
|
|
12
12
|
bindings = new Map;
|
|
13
|
+
resolutionPath = [];
|
|
13
14
|
set(key, value) {
|
|
14
15
|
this.singletonFactories.delete(key);
|
|
15
16
|
this.bindings.delete(key);
|
|
@@ -32,16 +33,27 @@ class ServiceContainer {
|
|
|
32
33
|
}
|
|
33
34
|
const singletonFactory = this.singletonFactories.get(key);
|
|
34
35
|
if (singletonFactory) {
|
|
35
|
-
const value = singletonFactory
|
|
36
|
+
const value = this.resolveFactory(key, singletonFactory);
|
|
36
37
|
this.services.set(key, value);
|
|
37
38
|
return value;
|
|
38
39
|
}
|
|
39
40
|
const binding = this.bindings.get(key);
|
|
40
41
|
if (binding) {
|
|
41
|
-
return binding
|
|
42
|
+
return this.resolveFactory(key, binding);
|
|
42
43
|
}
|
|
43
44
|
throw new Error(`Service "${key}" is not registered.`);
|
|
44
45
|
}
|
|
46
|
+
resolveFactory(key, factory) {
|
|
47
|
+
if (this.resolutionPath.includes(key)) {
|
|
48
|
+
throw new Error(`Circular service dependency: ${[...this.resolutionPath, key].join(" -> ")}.`);
|
|
49
|
+
}
|
|
50
|
+
this.resolutionPath.push(key);
|
|
51
|
+
try {
|
|
52
|
+
return factory(this);
|
|
53
|
+
} finally {
|
|
54
|
+
this.resolutionPath.pop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
45
57
|
resolve(key) {
|
|
46
58
|
return this.get(key);
|
|
47
59
|
}
|
|
@@ -26,7 +26,7 @@ function createAsyncContextStore(key) {
|
|
|
26
26
|
}
|
|
27
27
|
var init_asyncContextStore = () => {};
|
|
28
28
|
|
|
29
|
-
// ../../src/core/auth/
|
|
29
|
+
// ../../src/core/auth/membershipServiceImplementation.ts
|
|
30
30
|
import { resolveMembershipLookup } from "@getstrata/core/auth/membershipContext";
|
|
31
31
|
import { ForbiddenError as ForbiddenError2 } from "@getstrata/core/errors/http";
|
|
32
32
|
|
|
@@ -71,17 +71,7 @@ function resolveUserId(user) {
|
|
|
71
71
|
return userId;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// ../../src/core/auth/
|
|
75
|
-
import { resolveApplicationDependencies } from "@getstrata/core/runtime/applicationRegistry";
|
|
76
|
-
function resolveMembershipService() {
|
|
77
|
-
const dependencies = resolveApplicationDependencies();
|
|
78
|
-
if (dependencies.container.has("core.membership")) {
|
|
79
|
-
return dependencies.container.resolve("core.membership");
|
|
80
|
-
}
|
|
81
|
-
return new membershipService_default;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// ../../src/core/auth/membershipService.ts
|
|
74
|
+
// ../../src/core/auth/membershipServiceImplementation.ts
|
|
85
75
|
class MembershipService {
|
|
86
76
|
members;
|
|
87
77
|
constructor(members = resolveMembershipLookup()) {
|
|
@@ -138,8 +128,17 @@ class MembershipService {
|
|
|
138
128
|
return this.members.updateMemberRole(organizationId, userId, role);
|
|
139
129
|
}
|
|
140
130
|
}
|
|
141
|
-
var
|
|
131
|
+
var membershipServiceImplementation_default = MembershipService;
|
|
132
|
+
// ../../src/core/auth/resolveMembershipService.ts
|
|
133
|
+
import { resolveApplicationDependencies } from "@getstrata/core/runtime/applicationRegistry";
|
|
134
|
+
function resolveMembershipService() {
|
|
135
|
+
const dependencies = resolveApplicationDependencies();
|
|
136
|
+
if (dependencies.container.has("core.membership")) {
|
|
137
|
+
return dependencies.container.resolve("core.membership");
|
|
138
|
+
}
|
|
139
|
+
return new membershipServiceImplementation_default;
|
|
140
|
+
}
|
|
142
141
|
export {
|
|
143
|
-
|
|
142
|
+
membershipServiceImplementation_default as default,
|
|
144
143
|
resolveMembershipService
|
|
145
144
|
};
|
|
@@ -2990,6 +2990,9 @@ class BaseRepository {
|
|
|
2990
2990
|
return order.direction;
|
|
2991
2991
|
}
|
|
2992
2992
|
withConnection(connection) {
|
|
2993
|
+
return this.cloneWithConnection(connection);
|
|
2994
|
+
}
|
|
2995
|
+
cloneWithConnection(connection) {
|
|
2993
2996
|
const clone = Object.create(Object.getPrototypeOf(this));
|
|
2994
2997
|
Object.assign(clone, this);
|
|
2995
2998
|
clone.connection = connection;
|
|
@@ -10,6 +10,7 @@ class ServiceContainer {
|
|
|
10
10
|
services = new Map;
|
|
11
11
|
singletonFactories = new Map;
|
|
12
12
|
bindings = new Map;
|
|
13
|
+
resolutionPath = [];
|
|
13
14
|
set(key, value) {
|
|
14
15
|
this.singletonFactories.delete(key);
|
|
15
16
|
this.bindings.delete(key);
|
|
@@ -32,16 +33,27 @@ class ServiceContainer {
|
|
|
32
33
|
}
|
|
33
34
|
const singletonFactory = this.singletonFactories.get(key);
|
|
34
35
|
if (singletonFactory) {
|
|
35
|
-
const value = singletonFactory
|
|
36
|
+
const value = this.resolveFactory(key, singletonFactory);
|
|
36
37
|
this.services.set(key, value);
|
|
37
38
|
return value;
|
|
38
39
|
}
|
|
39
40
|
const binding = this.bindings.get(key);
|
|
40
41
|
if (binding) {
|
|
41
|
-
return binding
|
|
42
|
+
return this.resolveFactory(key, binding);
|
|
42
43
|
}
|
|
43
44
|
throw new Error(`Service "${key}" is not registered.`);
|
|
44
45
|
}
|
|
46
|
+
resolveFactory(key, factory) {
|
|
47
|
+
if (this.resolutionPath.includes(key)) {
|
|
48
|
+
throw new Error(`Circular service dependency: ${[...this.resolutionPath, key].join(" -> ")}.`);
|
|
49
|
+
}
|
|
50
|
+
this.resolutionPath.push(key);
|
|
51
|
+
try {
|
|
52
|
+
return factory(this);
|
|
53
|
+
} finally {
|
|
54
|
+
this.resolutionPath.pop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
45
57
|
resolve(key) {
|
|
46
58
|
return this.get(key);
|
|
47
59
|
}
|
|
@@ -15,9 +15,10 @@ function validateEnv(schema, env = process.env) {
|
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
17
|
if (rule.integer) {
|
|
18
|
+
const completeInteger = /^[+-]?\d+$/.test(value.trim());
|
|
18
19
|
const parsed = Number.parseInt(value, 10);
|
|
19
20
|
const minimum = rule.minimum ?? Number.NEGATIVE_INFINITY;
|
|
20
|
-
if (!Number.isInteger(parsed) || parsed < minimum) {
|
|
21
|
+
if (!completeInteger || !Number.isInteger(parsed) || parsed < minimum) {
|
|
21
22
|
const comparison = minimum === Number.NEGATIVE_INFINITY ? "an integer" : `an integer >= ${minimum}`;
|
|
22
23
|
throw new Error(`Environment variable "${name}" must be ${comparison}.`);
|
|
23
24
|
}
|
|
@@ -10,6 +10,7 @@ class ServiceContainer {
|
|
|
10
10
|
services = new Map;
|
|
11
11
|
singletonFactories = new Map;
|
|
12
12
|
bindings = new Map;
|
|
13
|
+
resolutionPath = [];
|
|
13
14
|
set(key, value) {
|
|
14
15
|
this.singletonFactories.delete(key);
|
|
15
16
|
this.bindings.delete(key);
|
|
@@ -32,16 +33,27 @@ class ServiceContainer {
|
|
|
32
33
|
}
|
|
33
34
|
const singletonFactory = this.singletonFactories.get(key);
|
|
34
35
|
if (singletonFactory) {
|
|
35
|
-
const value = singletonFactory
|
|
36
|
+
const value = this.resolveFactory(key, singletonFactory);
|
|
36
37
|
this.services.set(key, value);
|
|
37
38
|
return value;
|
|
38
39
|
}
|
|
39
40
|
const binding = this.bindings.get(key);
|
|
40
41
|
if (binding) {
|
|
41
|
-
return binding
|
|
42
|
+
return this.resolveFactory(key, binding);
|
|
42
43
|
}
|
|
43
44
|
throw new Error(`Service "${key}" is not registered.`);
|
|
44
45
|
}
|
|
46
|
+
resolveFactory(key, factory) {
|
|
47
|
+
if (this.resolutionPath.includes(key)) {
|
|
48
|
+
throw new Error(`Circular service dependency: ${[...this.resolutionPath, key].join(" -> ")}.`);
|
|
49
|
+
}
|
|
50
|
+
this.resolutionPath.push(key);
|
|
51
|
+
try {
|
|
52
|
+
return factory(this);
|
|
53
|
+
} finally {
|
|
54
|
+
this.resolutionPath.pop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
45
57
|
resolve(key) {
|
|
46
58
|
return this.get(key);
|
|
47
59
|
}
|
|
@@ -10,6 +10,7 @@ class ServiceContainer {
|
|
|
10
10
|
services = new Map;
|
|
11
11
|
singletonFactories = new Map;
|
|
12
12
|
bindings = new Map;
|
|
13
|
+
resolutionPath = [];
|
|
13
14
|
set(key, value) {
|
|
14
15
|
this.singletonFactories.delete(key);
|
|
15
16
|
this.bindings.delete(key);
|
|
@@ -32,16 +33,27 @@ class ServiceContainer {
|
|
|
32
33
|
}
|
|
33
34
|
const singletonFactory = this.singletonFactories.get(key);
|
|
34
35
|
if (singletonFactory) {
|
|
35
|
-
const value = singletonFactory
|
|
36
|
+
const value = this.resolveFactory(key, singletonFactory);
|
|
36
37
|
this.services.set(key, value);
|
|
37
38
|
return value;
|
|
38
39
|
}
|
|
39
40
|
const binding = this.bindings.get(key);
|
|
40
41
|
if (binding) {
|
|
41
|
-
return binding
|
|
42
|
+
return this.resolveFactory(key, binding);
|
|
42
43
|
}
|
|
43
44
|
throw new Error(`Service "${key}" is not registered.`);
|
|
44
45
|
}
|
|
46
|
+
resolveFactory(key, factory) {
|
|
47
|
+
if (this.resolutionPath.includes(key)) {
|
|
48
|
+
throw new Error(`Circular service dependency: ${[...this.resolutionPath, key].join(" -> ")}.`);
|
|
49
|
+
}
|
|
50
|
+
this.resolutionPath.push(key);
|
|
51
|
+
try {
|
|
52
|
+
return factory(this);
|
|
53
|
+
} finally {
|
|
54
|
+
this.resolutionPath.pop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
45
57
|
resolve(key) {
|
|
46
58
|
return this.get(key);
|
|
47
59
|
}
|
|
@@ -36,12 +36,12 @@ export type { FieldEncryptionRotationBatch, FieldEncryptionRotationOptions, } fr
|
|
|
36
36
|
export { createFieldEncryptionRotationMigration, runFieldEncryptionRotationBatch, } from "../core/crypto/fieldEncryptionRotation";
|
|
37
37
|
export type { TransactionAcquisitionMetrics, TransactionAcquisitionSnapshot, } from "../core/database/acquisitionMetrics.ts";
|
|
38
38
|
export { createTransactionAcquisitionMetrics, renderTransactionAcquisitionMetrics, } from "../core/database/acquisitionMetrics.ts";
|
|
39
|
-
export type { DatabaseConnection } from "../core/database/baseRepository.ts";
|
|
40
39
|
export { default as BaseRepository } from "../core/database/baseRepository.ts";
|
|
41
40
|
export { bindDatabaseConnection, getBoundDatabaseConnection, resetBoundDatabaseConnection, } from "../core/database/bindConnection.ts";
|
|
42
41
|
export { bindBunSql, createBunSqlPool } from "../core/database/bunSql.ts";
|
|
43
42
|
export { createDatabaseConnection } from "../core/database/connection.ts";
|
|
44
43
|
export { getActiveDatabaseConnection, hasActiveDatabaseConnection, runWithDatabaseConnection, } from "../core/database/connectionContext.ts";
|
|
44
|
+
export type { DatabaseConnection } from "../core/database/connectionContracts.ts";
|
|
45
45
|
export { getDefaultDatabasePool, getDefaultDatabaseQuery, isDefaultDatabaseConnection, registerDefaultDatabasePool, resetDefaultDatabasePoolForTests, } from "../core/database/defaultConnection.ts";
|
|
46
46
|
export type { SqlDialect } from "../core/database/dialect.ts";
|
|
47
47
|
export { currentSqlDialect, dialectFor, resetSqlDialect, runWithSqlDialect, sqlTimestamp, useSqlDialect, } from "../core/database/dialect.ts";
|
package/dist/index.js
CHANGED
|
@@ -1235,6 +1235,7 @@ class ServiceContainer {
|
|
|
1235
1235
|
services = new Map;
|
|
1236
1236
|
singletonFactories = new Map;
|
|
1237
1237
|
bindings = new Map;
|
|
1238
|
+
resolutionPath = [];
|
|
1238
1239
|
set(key, value) {
|
|
1239
1240
|
this.singletonFactories.delete(key);
|
|
1240
1241
|
this.bindings.delete(key);
|
|
@@ -1257,16 +1258,27 @@ class ServiceContainer {
|
|
|
1257
1258
|
}
|
|
1258
1259
|
const singletonFactory = this.singletonFactories.get(key);
|
|
1259
1260
|
if (singletonFactory) {
|
|
1260
|
-
const value = singletonFactory
|
|
1261
|
+
const value = this.resolveFactory(key, singletonFactory);
|
|
1261
1262
|
this.services.set(key, value);
|
|
1262
1263
|
return value;
|
|
1263
1264
|
}
|
|
1264
1265
|
const binding = this.bindings.get(key);
|
|
1265
1266
|
if (binding) {
|
|
1266
|
-
return binding
|
|
1267
|
+
return this.resolveFactory(key, binding);
|
|
1267
1268
|
}
|
|
1268
1269
|
throw new Error(`Service "${key}" is not registered.`);
|
|
1269
1270
|
}
|
|
1271
|
+
resolveFactory(key, factory) {
|
|
1272
|
+
if (this.resolutionPath.includes(key)) {
|
|
1273
|
+
throw new Error(`Circular service dependency: ${[...this.resolutionPath, key].join(" -> ")}.`);
|
|
1274
|
+
}
|
|
1275
|
+
this.resolutionPath.push(key);
|
|
1276
|
+
try {
|
|
1277
|
+
return factory(this);
|
|
1278
|
+
} finally {
|
|
1279
|
+
this.resolutionPath.pop();
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1270
1282
|
resolve(key) {
|
|
1271
1283
|
return this.get(key);
|
|
1272
1284
|
}
|
|
@@ -2504,6 +2516,64 @@ function assertOrganizationReadable(organizationId) {
|
|
|
2504
2516
|
throw new NotFoundError(`Organization ${organizationId} not found.`);
|
|
2505
2517
|
}
|
|
2506
2518
|
}
|
|
2519
|
+
// ../../src/core/auth/membershipServiceImplementation.ts
|
|
2520
|
+
class MembershipService {
|
|
2521
|
+
members;
|
|
2522
|
+
constructor(members = resolveMembershipLookup()) {
|
|
2523
|
+
this.members = members;
|
|
2524
|
+
}
|
|
2525
|
+
async listOrganizationIdsForUser(userId) {
|
|
2526
|
+
const memberships = await this.members.listForUser(userId);
|
|
2527
|
+
return memberships.map((membership) => membership.organization_id);
|
|
2528
|
+
}
|
|
2529
|
+
async getOrgRole(userId, organizationId) {
|
|
2530
|
+
const membership = await this.members.findMembership(userId, organizationId);
|
|
2531
|
+
return membership?.role ?? null;
|
|
2532
|
+
}
|
|
2533
|
+
async requireOrgAccess(organizationId, minimumRole = "member", user = currentAuthUser()) {
|
|
2534
|
+
if (!user) {
|
|
2535
|
+
throw new ForbiddenError("Authentication required.");
|
|
2536
|
+
}
|
|
2537
|
+
if (isGlobalAdmin(user)) {
|
|
2538
|
+
return "owner";
|
|
2539
|
+
}
|
|
2540
|
+
const role = await this.getOrgRole(resolveUserId(user), organizationId);
|
|
2541
|
+
if (!role || !hasMinimumOrgRole(role, minimumRole)) {
|
|
2542
|
+
throw new ForbiddenError("Organization membership required.");
|
|
2543
|
+
}
|
|
2544
|
+
return role;
|
|
2545
|
+
}
|
|
2546
|
+
async filterAccessibleOrganizationIds(organizationIds, user = currentAuthUser()) {
|
|
2547
|
+
if (!user) {
|
|
2548
|
+
return [];
|
|
2549
|
+
}
|
|
2550
|
+
if (isGlobalAdmin(user)) {
|
|
2551
|
+
return organizationIds;
|
|
2552
|
+
}
|
|
2553
|
+
const allowed = new Set(await this.listOrganizationIdsForUser(resolveUserId(user)));
|
|
2554
|
+
return organizationIds.filter((organizationId) => allowed.has(organizationId));
|
|
2555
|
+
}
|
|
2556
|
+
async addOwnerOnOrganizationCreate(organizationId, userId) {
|
|
2557
|
+
await this.members.addMember({
|
|
2558
|
+
organizationId,
|
|
2559
|
+
userId,
|
|
2560
|
+
role: "owner"
|
|
2561
|
+
});
|
|
2562
|
+
}
|
|
2563
|
+
listMembersForOrganization(organizationId) {
|
|
2564
|
+
return this.members.listForOrganization(organizationId);
|
|
2565
|
+
}
|
|
2566
|
+
addMember(input) {
|
|
2567
|
+
return this.members.addMember(input);
|
|
2568
|
+
}
|
|
2569
|
+
removeMember(organizationId, userId) {
|
|
2570
|
+
return this.members.removeMember(organizationId, userId);
|
|
2571
|
+
}
|
|
2572
|
+
updateMemberRole(organizationId, userId, role) {
|
|
2573
|
+
return this.members.updateMemberRole(organizationId, userId, role);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
var membershipServiceImplementation_default = MembershipService;
|
|
2507
2577
|
// ../../src/core/contracts/di.ts
|
|
2508
2578
|
function getRequiredDependency(dependencies, key) {
|
|
2509
2579
|
const dependency = dependencies[key];
|
|
@@ -2611,67 +2681,8 @@ function resolveMembershipService() {
|
|
|
2611
2681
|
if (dependencies.container.has("core.membership")) {
|
|
2612
2682
|
return dependencies.container.resolve("core.membership");
|
|
2613
2683
|
}
|
|
2614
|
-
return new
|
|
2684
|
+
return new membershipServiceImplementation_default;
|
|
2615
2685
|
}
|
|
2616
|
-
|
|
2617
|
-
// ../../src/core/auth/membershipService.ts
|
|
2618
|
-
class MembershipService {
|
|
2619
|
-
members;
|
|
2620
|
-
constructor(members = resolveMembershipLookup()) {
|
|
2621
|
-
this.members = members;
|
|
2622
|
-
}
|
|
2623
|
-
async listOrganizationIdsForUser(userId) {
|
|
2624
|
-
const memberships = await this.members.listForUser(userId);
|
|
2625
|
-
return memberships.map((membership) => membership.organization_id);
|
|
2626
|
-
}
|
|
2627
|
-
async getOrgRole(userId, organizationId) {
|
|
2628
|
-
const membership = await this.members.findMembership(userId, organizationId);
|
|
2629
|
-
return membership?.role ?? null;
|
|
2630
|
-
}
|
|
2631
|
-
async requireOrgAccess(organizationId, minimumRole = "member", user = currentAuthUser()) {
|
|
2632
|
-
if (!user) {
|
|
2633
|
-
throw new ForbiddenError("Authentication required.");
|
|
2634
|
-
}
|
|
2635
|
-
if (isGlobalAdmin(user)) {
|
|
2636
|
-
return "owner";
|
|
2637
|
-
}
|
|
2638
|
-
const role = await this.getOrgRole(resolveUserId(user), organizationId);
|
|
2639
|
-
if (!role || !hasMinimumOrgRole(role, minimumRole)) {
|
|
2640
|
-
throw new ForbiddenError("Organization membership required.");
|
|
2641
|
-
}
|
|
2642
|
-
return role;
|
|
2643
|
-
}
|
|
2644
|
-
async filterAccessibleOrganizationIds(organizationIds, user = currentAuthUser()) {
|
|
2645
|
-
if (!user) {
|
|
2646
|
-
return [];
|
|
2647
|
-
}
|
|
2648
|
-
if (isGlobalAdmin(user)) {
|
|
2649
|
-
return organizationIds;
|
|
2650
|
-
}
|
|
2651
|
-
const allowed = new Set(await this.listOrganizationIdsForUser(resolveUserId(user)));
|
|
2652
|
-
return organizationIds.filter((organizationId) => allowed.has(organizationId));
|
|
2653
|
-
}
|
|
2654
|
-
async addOwnerOnOrganizationCreate(organizationId, userId) {
|
|
2655
|
-
await this.members.addMember({
|
|
2656
|
-
organizationId,
|
|
2657
|
-
userId,
|
|
2658
|
-
role: "owner"
|
|
2659
|
-
});
|
|
2660
|
-
}
|
|
2661
|
-
listMembersForOrganization(organizationId) {
|
|
2662
|
-
return this.members.listForOrganization(organizationId);
|
|
2663
|
-
}
|
|
2664
|
-
addMember(input) {
|
|
2665
|
-
return this.members.addMember(input);
|
|
2666
|
-
}
|
|
2667
|
-
removeMember(organizationId, userId) {
|
|
2668
|
-
return this.members.removeMember(organizationId, userId);
|
|
2669
|
-
}
|
|
2670
|
-
updateMemberRole(organizationId, userId, role) {
|
|
2671
|
-
return this.members.updateMemberRole(organizationId, userId, role);
|
|
2672
|
-
}
|
|
2673
|
-
}
|
|
2674
|
-
var membershipService_default = MembershipService;
|
|
2675
2686
|
// ../../src/core/auth/oauth/oidcProvider.ts
|
|
2676
2687
|
import { createHash as createHash2, randomBytes as randomBytes3 } from "crypto";
|
|
2677
2688
|
|
|
@@ -5700,6 +5711,9 @@ class BaseRepository {
|
|
|
5700
5711
|
return order.direction;
|
|
5701
5712
|
}
|
|
5702
5713
|
withConnection(connection) {
|
|
5714
|
+
return this.cloneWithConnection(connection);
|
|
5715
|
+
}
|
|
5716
|
+
cloneWithConnection(connection) {
|
|
5703
5717
|
const clone = Object.create(Object.getPrototypeOf(this));
|
|
5704
5718
|
Object.assign(clone, this);
|
|
5705
5719
|
clone.connection = connection;
|
|
@@ -17175,7 +17189,7 @@ export {
|
|
|
17175
17189
|
LogMailDriver,
|
|
17176
17190
|
MAX_PER_PAGE,
|
|
17177
17191
|
Mailer,
|
|
17178
|
-
|
|
17192
|
+
membershipServiceImplementation_default as MembershipService,
|
|
17179
17193
|
Model,
|
|
17180
17194
|
ModelQuery,
|
|
17181
17195
|
MorphManyRelationQuery,
|