@getstrata/bootstrap 0.1.0
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/README.md +29 -0
- package/dist/bootstrap/applicationRegistry.d.ts +16 -0
- package/dist/bootstrap/config.d.ts +20 -0
- package/dist/bootstrap/contracts.d.ts +63 -0
- package/dist/bootstrap/httpKernel.d.ts +26 -0
- package/dist/bootstrap/prefixRouteMap.d.ts +2 -0
- package/dist/bootstrap/public-api.d.ts +10 -0
- package/dist/bootstrap/web/forms.d.ts +10 -0
- package/dist/bootstrap/web/index.d.ts +7 -0
- package/dist/bootstrap/web/server.d.ts +7 -0
- package/dist/bootstrap/web/session.d.ts +23 -0
- package/dist/bootstrap/web/slug.d.ts +1 -0
- package/dist/config/app.d.ts +10 -0
- package/dist/config/contentSecurityPolicy.d.ts +5 -0
- package/dist/config/cors.d.ts +9 -0
- package/dist/config/database.d.ts +10 -0
- package/dist/config/features.d.ts +18 -0
- package/dist/config/frontend.d.ts +6 -0
- package/dist/config/rateLimit.d.ts +9 -0
- package/dist/core/auth/accessControl.d.ts +8 -0
- package/dist/core/auth/authContext.d.ts +12 -0
- package/dist/core/auth/guard.d.ts +36 -0
- package/dist/core/auth/membershipContext.d.ts +16 -0
- package/dist/core/auth/membershipContextMiddleware.d.ts +3 -0
- package/dist/core/auth/membershipMiddleware.d.ts +2 -0
- package/dist/core/auth/oauth/oidcProvider.d.ts +18 -0
- package/dist/core/auth/oauth/providers.d.ts +22 -0
- package/dist/core/auth/oauth/samlProvider.d.ts +9 -0
- package/dist/core/auth/oauth/types.d.ts +11 -0
- package/dist/core/auth/password.d.ts +3 -0
- package/dist/core/auth/policy.d.ts +15 -0
- package/dist/core/auth/tokenHash.d.ts +3 -0
- package/dist/core/crypto/fieldEncryption.d.ts +13 -0
- package/dist/core/crypto/mfaSecret.d.ts +3 -0
- package/dist/core/database/baseRepository.d.ts +44 -0
- package/dist/core/database/connection.d.ts +7 -0
- package/dist/core/database/connectionContext.d.ts +7 -0
- package/dist/core/database/errors.d.ts +12 -0
- package/dist/core/database/index.d.ts +11 -0
- package/dist/core/database/query.d.ts +51 -0
- package/dist/core/database/relationships.d.ts +26 -0
- package/dist/core/database/table.d.ts +13 -0
- package/dist/core/database/transaction.d.ts +3 -0
- package/dist/core/database/types.d.ts +29 -0
- package/dist/core/errors/http.d.ts +33 -0
- package/dist/core/events/eventBus.d.ts +10 -0
- package/dist/core/events/index.d.ts +4 -0
- package/dist/core/http/authMiddleware.d.ts +5 -0
- package/dist/core/http/authorizeMiddleware.d.ts +5 -0
- package/dist/core/http/bodySizeLimitMiddleware.d.ts +4 -0
- package/dist/core/http/contentNegotiation.d.ts +2 -0
- package/dist/core/http/corsMiddleware.d.ts +3 -0
- package/dist/core/http/csrfMiddleware.d.ts +3 -0
- package/dist/core/http/csrfToken.d.ts +14 -0
- package/dist/core/http/flashMiddleware.d.ts +3 -0
- package/dist/core/http/flashSession.d.ts +12 -0
- package/dist/core/http/loginThrottleMiddleware.d.ts +11 -0
- package/dist/core/http/memoryThrottleMiddleware.d.ts +9 -0
- package/dist/core/http/metricsMiddleware.d.ts +4 -0
- package/dist/core/http/middleware.d.ts +8 -0
- package/dist/core/http/requestMetaContext.d.ts +16 -0
- package/dist/core/http/requireAbilityMiddleware.d.ts +4 -0
- package/dist/core/http/requireAuthMiddleware.d.ts +4 -0
- package/dist/core/http/requireGlobalAdminMiddleware.d.ts +3 -0
- package/dist/core/http/requireWebAuthMiddleware.d.ts +4 -0
- package/dist/core/http/routeMiddleware.d.ts +3 -0
- package/dist/core/http/securityHeadersMiddleware.d.ts +3 -0
- package/dist/core/http/throttleMiddleware.d.ts +11 -0
- package/dist/core/logging/logger.d.ts +17 -0
- package/dist/core/logging/requestLoggingMiddleware.d.ts +3 -0
- package/dist/core/metrics/prometheus.d.ts +26 -0
- package/dist/core/pagination/index.d.ts +17 -0
- package/dist/core/queue/index.d.ts +19 -0
- package/dist/core/security/publicReads.d.ts +3 -0
- package/dist/core/security/securityEvents.d.ts +6 -0
- package/dist/core/security/tokenExpiry.d.ts +2 -0
- package/dist/core/security/totp.d.ts +3 -0
- package/dist/core/tenant/databaseTenantContext.d.ts +2 -0
- package/dist/core/tenant/resolveTenant.d.ts +3 -0
- package/dist/core/tenant/tenantContext.d.ts +14 -0
- package/dist/core/tenant/tenantDatabaseScope.d.ts +7 -0
- package/dist/core/tenant/tenantMiddleware.d.ts +6 -0
- package/dist/core/tracing/otel.d.ts +26 -0
- package/dist/core/tracing/traceContext.d.ts +10 -0
- package/dist/core/tracing/tracingMiddleware.d.ts +3 -0
- package/dist/db/connection/createConnection.d.ts +6 -0
- package/dist/db/connection/index.d.ts +11 -0
- package/dist/domain/abilities.d.ts +5 -0
- package/dist/domain/auth.d.ts +4 -0
- package/dist/index.js +1751 -0
- package/dist/modules/organization/memberRepository.d.ts +14 -0
- package/dist/modules/organization/memberTypes.d.ts +9 -0
- package/dist/modules/user/apiTokenRepository.d.ts +8 -0
- package/dist/modules/user/apiTokenTable.d.ts +3 -0
- package/dist/modules/user/authService.d.ts +23 -0
- package/dist/modules/user/notificationRepository.d.ts +6 -0
- package/dist/modules/user/notificationService.d.ts +25 -0
- package/dist/modules/user/notificationTable.d.ts +3 -0
- package/dist/modules/user/notificationTypes.d.ts +12 -0
- package/dist/modules/user/oauthIdentityRepository.d.ts +9 -0
- package/dist/modules/user/provider.d.ts +11 -0
- package/dist/modules/user/repository.d.ts +12 -0
- package/dist/modules/user/table.d.ts +3 -0
- package/dist/modules/user/tokenService.d.ts +29 -0
- package/dist/modules/user/types.d.ts +46 -0
- package/dist/types/services.d.ts +16 -0
- package/package.json +38 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OrganizationMemberRecord, OrganizationMemberRole } from "./memberTypes";
|
|
2
|
+
declare class OrganizationMemberRepository {
|
|
3
|
+
constructor();
|
|
4
|
+
findMembership(userId: number, organizationId: number): Promise<OrganizationMemberRecord | null>;
|
|
5
|
+
listForUser(userId: number): Promise<OrganizationMemberRecord[]>;
|
|
6
|
+
listForOrganization(organizationId: number): Promise<OrganizationMemberRecord[]>;
|
|
7
|
+
addMember(input: {
|
|
8
|
+
organizationId: number;
|
|
9
|
+
userId: number;
|
|
10
|
+
role?: OrganizationMemberRole;
|
|
11
|
+
}): Promise<OrganizationMemberRecord>;
|
|
12
|
+
removeMember(organizationId: number, userId: number): Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
export default OrganizationMemberRepository;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type OrganizationMemberRole = "owner" | "admin" | "member";
|
|
2
|
+
type OrganizationMemberRecord = {
|
|
3
|
+
id: number;
|
|
4
|
+
organization_id: number;
|
|
5
|
+
user_id: number;
|
|
6
|
+
role: OrganizationMemberRole;
|
|
7
|
+
created_at: Date;
|
|
8
|
+
};
|
|
9
|
+
export type { OrganizationMemberRecord, OrganizationMemberRole };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseRepository } from "../../core/database";
|
|
2
|
+
import type { ApiTokenRecord } from "./types";
|
|
3
|
+
declare class ApiTokenRepository extends BaseRepository<ApiTokenRecord, "id"> {
|
|
4
|
+
constructor();
|
|
5
|
+
findByTokenHash(tokenHash: string): Promise<ApiTokenRecord | null>;
|
|
6
|
+
touchLastUsedAt(id: number): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export default ApiTokenRepository;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OAuthProvider } from "../../core/auth/oauth/types";
|
|
2
|
+
import type OAuthIdentityRepository from "./oauthIdentityRepository";
|
|
3
|
+
import type UserRepository from "./repository";
|
|
4
|
+
import type TokenService from "./tokenService";
|
|
5
|
+
import type { CreatedApiToken } from "./types";
|
|
6
|
+
interface LoginOptions {
|
|
7
|
+
mfaCode?: string;
|
|
8
|
+
}
|
|
9
|
+
declare class AuthService {
|
|
10
|
+
private readonly users;
|
|
11
|
+
private readonly tokens;
|
|
12
|
+
private readonly oauthIdentities;
|
|
13
|
+
private readonly oauthProviders;
|
|
14
|
+
constructor(users: UserRepository, tokens: TokenService, oauthIdentities: OAuthIdentityRepository);
|
|
15
|
+
registerOAuthProvider(provider: OAuthProvider): void;
|
|
16
|
+
getOAuthProvider(name: string): OAuthProvider | undefined;
|
|
17
|
+
loginWithPassword(email: string, password: string, options?: LoginOptions): Promise<CreatedApiToken>;
|
|
18
|
+
loginWithOAuth(providerName: string, code: string): Promise<CreatedApiToken>;
|
|
19
|
+
buildOAuthAuthorizationUrl(providerName: string, state: string): string;
|
|
20
|
+
private findOrCreateOAuthUser;
|
|
21
|
+
}
|
|
22
|
+
export default AuthService;
|
|
23
|
+
export type { LoginOptions };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BaseRepository } from "../../core/database";
|
|
2
|
+
import type { NotificationRecord } from "./notificationTypes";
|
|
3
|
+
declare class NotificationRepository extends BaseRepository<NotificationRecord, "id"> {
|
|
4
|
+
constructor();
|
|
5
|
+
}
|
|
6
|
+
export default NotificationRepository;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PaginatedResult } from "../../core/pagination";
|
|
2
|
+
import type NotificationRepository from "./notificationRepository";
|
|
3
|
+
import type { NotificationRecord } from "./notificationTypes";
|
|
4
|
+
interface CreateNotificationInput {
|
|
5
|
+
userId: number;
|
|
6
|
+
tenantId: number;
|
|
7
|
+
type: string;
|
|
8
|
+
title: string;
|
|
9
|
+
body: string;
|
|
10
|
+
data?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
declare class NotificationService {
|
|
13
|
+
private readonly repository;
|
|
14
|
+
constructor(repository: NotificationRepository);
|
|
15
|
+
listForUser(userId: number, options: {
|
|
16
|
+
page: number;
|
|
17
|
+
perPage: number;
|
|
18
|
+
unreadOnly?: boolean;
|
|
19
|
+
}): Promise<PaginatedResult<NotificationRecord>>;
|
|
20
|
+
markRead(userId: number, notificationId: number): Promise<NotificationRecord>;
|
|
21
|
+
markAllRead(userId: number): Promise<number>;
|
|
22
|
+
create(input: CreateNotificationInput): Promise<NotificationRecord>;
|
|
23
|
+
}
|
|
24
|
+
export default NotificationService;
|
|
25
|
+
export type { CreateNotificationInput };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseRepository } from "../../core/database";
|
|
2
|
+
import type { OAuthIdentityRecord } from "./types";
|
|
3
|
+
declare const oauthIdentityTable: import("../../core/database").TableDefinition<OAuthIdentityRecord, "id">;
|
|
4
|
+
declare class OAuthIdentityRepository extends BaseRepository<OAuthIdentityRecord, "id"> {
|
|
5
|
+
constructor();
|
|
6
|
+
findByProviderUser(provider: string, providerUserId: string): Promise<OAuthIdentityRecord | null>;
|
|
7
|
+
}
|
|
8
|
+
export default OAuthIdentityRepository;
|
|
9
|
+
export { oauthIdentityTable };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ServiceProvider } from "../../bootstrap/contracts";
|
|
2
|
+
declare const userRepositoryToken = "user.repository";
|
|
3
|
+
declare const apiTokenRepositoryToken = "user.apiTokenRepository";
|
|
4
|
+
declare const tokenServiceToken = "core.tokenService";
|
|
5
|
+
declare const authServiceToken = "user.authService";
|
|
6
|
+
declare const oauthIdentityRepositoryToken = "user.oauthIdentityRepository";
|
|
7
|
+
declare const notificationRepositoryToken = "user.notificationRepository";
|
|
8
|
+
declare const notificationServiceToken = "user.notificationService";
|
|
9
|
+
declare const userProvider: ServiceProvider;
|
|
10
|
+
export default userProvider;
|
|
11
|
+
export { apiTokenRepositoryToken, authServiceToken, notificationRepositoryToken, notificationServiceToken, oauthIdentityRepositoryToken, tokenServiceToken, userRepositoryToken, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseRepository } from "../../core/database";
|
|
2
|
+
import type { UserRecord } from "./types";
|
|
3
|
+
declare class UserRepository extends BaseRepository<UserRecord, "id"> {
|
|
4
|
+
constructor();
|
|
5
|
+
private decode;
|
|
6
|
+
findById(id: number): Promise<UserRecord | null>;
|
|
7
|
+
findAll(options?: Parameters<BaseRepository<UserRecord, "id">["findAll"]>[0]): Promise<UserRecord[]>;
|
|
8
|
+
create(values: Partial<UserRecord>): Promise<UserRecord>;
|
|
9
|
+
updateByIdOrThrow(id: number, values: Partial<UserRecord>, errorFactory?: (missingId: number) => Error): Promise<UserRecord>;
|
|
10
|
+
findByEmail(email: string): Promise<UserRecord | null>;
|
|
11
|
+
}
|
|
12
|
+
export default UserRepository;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AuthUser } from "../../core/auth/authContext";
|
|
2
|
+
import type ApiTokenRepository from "./apiTokenRepository";
|
|
3
|
+
import type UserRepository from "./repository";
|
|
4
|
+
import type { ApiTokenRecord, ApiTokenResource, CreatedApiToken, UserRecord } from "./types";
|
|
5
|
+
interface CreateTokenInput {
|
|
6
|
+
name: string;
|
|
7
|
+
abilities?: string[];
|
|
8
|
+
expiresAt?: Date | null;
|
|
9
|
+
expiresInDays?: number;
|
|
10
|
+
}
|
|
11
|
+
declare function toApiTokenResource(record: ApiTokenRecord): ApiTokenResource;
|
|
12
|
+
declare function generatePlainTextToken(): string;
|
|
13
|
+
declare function resolveExpiresAt(input: CreateTokenInput): Date | null;
|
|
14
|
+
declare function normalizeAbilities(value: unknown): string[];
|
|
15
|
+
declare class TokenService {
|
|
16
|
+
private readonly users;
|
|
17
|
+
private readonly tokens;
|
|
18
|
+
constructor(users: UserRepository, tokens: ApiTokenRepository);
|
|
19
|
+
resolveUserFromToken(token: string): Promise<AuthUser | null>;
|
|
20
|
+
createToken(userId: number, input: CreateTokenInput): Promise<CreatedApiToken>;
|
|
21
|
+
listTokensForUser(userId: number): Promise<ApiTokenResource[]>;
|
|
22
|
+
revokeToken(userId: number, tokenId: number): Promise<void>;
|
|
23
|
+
tokenCan(user: AuthUser | null, ability: string): boolean;
|
|
24
|
+
requireAbility(user: AuthUser | null, ability: string): void;
|
|
25
|
+
findByIdOrThrow(id: number): Promise<UserRecord>;
|
|
26
|
+
deleteUserAccount(userId: number): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export default TokenService;
|
|
29
|
+
export { generatePlainTextToken, normalizeAbilities, resolveExpiresAt, toApiTokenResource };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { UserRole } from "../../domain/auth";
|
|
2
|
+
interface UserRecord {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
email: string;
|
|
6
|
+
email_lookup?: string | null;
|
|
7
|
+
role: UserRole;
|
|
8
|
+
tenant_id: number;
|
|
9
|
+
password_hash?: string | null;
|
|
10
|
+
email_verified_at?: Date | null;
|
|
11
|
+
mfa_secret?: string | null;
|
|
12
|
+
mfa_enabled?: boolean;
|
|
13
|
+
created_at: Date;
|
|
14
|
+
updated_at: Date;
|
|
15
|
+
}
|
|
16
|
+
interface OAuthIdentityRecord {
|
|
17
|
+
id: number;
|
|
18
|
+
user_id: number;
|
|
19
|
+
provider: string;
|
|
20
|
+
provider_user_id: string;
|
|
21
|
+
email: string | null;
|
|
22
|
+
created_at: Date;
|
|
23
|
+
}
|
|
24
|
+
interface ApiTokenRecord {
|
|
25
|
+
id: number;
|
|
26
|
+
user_id: number;
|
|
27
|
+
name: string;
|
|
28
|
+
token_hash: string;
|
|
29
|
+
abilities: string[];
|
|
30
|
+
last_used_at: Date | null;
|
|
31
|
+
expires_at: Date | null;
|
|
32
|
+
created_at: Date;
|
|
33
|
+
}
|
|
34
|
+
interface ApiTokenResource {
|
|
35
|
+
id: number;
|
|
36
|
+
name: string;
|
|
37
|
+
abilities: string[];
|
|
38
|
+
last_used_at: string | null;
|
|
39
|
+
expires_at: string | null;
|
|
40
|
+
created_at: string;
|
|
41
|
+
}
|
|
42
|
+
interface CreatedApiToken {
|
|
43
|
+
token: ApiTokenResource;
|
|
44
|
+
plainTextToken: string;
|
|
45
|
+
}
|
|
46
|
+
export type { ApiTokenRecord, ApiTokenResource, CreatedApiToken, OAuthIdentityRecord, UserRecord };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface CacheLike {
|
|
2
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
3
|
+
remember<T>(key: string, callback: () => Promise<T>, ttlMs?: number): Promise<T>;
|
|
4
|
+
forget(key: string): Promise<boolean>;
|
|
5
|
+
flush(): Promise<void>;
|
|
6
|
+
tags(...names: string[]): {
|
|
7
|
+
remember<T>(key: string, callback: () => Promise<T>, ttlMs?: number): Promise<T>;
|
|
8
|
+
flush(): Promise<number>;
|
|
9
|
+
};
|
|
10
|
+
getOrSet<T>(key: string, loader: () => Promise<T>, ttlMs?: number): Promise<T>;
|
|
11
|
+
invalidate(key: string): Promise<boolean>;
|
|
12
|
+
invalidateByPrefix(prefix: string): Promise<number>;
|
|
13
|
+
clear(): Promise<void>;
|
|
14
|
+
size(): Promise<number>;
|
|
15
|
+
}
|
|
16
|
+
export type { CacheLike };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getstrata/bootstrap",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Strata application bootstrap — HttpKernel, DI, web session helpers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/EyK-26/strata.git",
|
|
10
|
+
"directory": "packages/strata-bootstrap"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/bootstrap/public-api.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/bootstrap/public-api.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "bun run build:bundle && bun run build:types",
|
|
27
|
+
"build:bundle": "bun build index.ts --outdir dist --target bun --external bun --external eta --external @getstrata/core",
|
|
28
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
29
|
+
"prepublishOnly": "bun run build"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@getstrata/core": "^0.3.0",
|
|
36
|
+
"typescript": "^5.9.0"
|
|
37
|
+
}
|
|
38
|
+
}
|