ofauth-shared-core 0.1.0-alpha.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.
Files changed (56) hide show
  1. package/README.md +20 -0
  2. package/dist/OfauthCore.d.ts +48 -0
  3. package/dist/OfauthCore.js +200 -0
  4. package/dist/contracts/AuthAuditContract.d.ts +25 -0
  5. package/dist/contracts/AuthAuditContract.js +16 -0
  6. package/dist/contracts/AuthErrorContract.d.ts +5 -0
  7. package/dist/contracts/AuthErrorContract.js +2 -0
  8. package/dist/contracts/AuthPolicyContract.d.ts +25 -0
  9. package/dist/contracts/AuthPolicyContract.js +2 -0
  10. package/dist/contracts/ContextContract.d.ts +27 -0
  11. package/dist/contracts/ContextContract.js +8 -0
  12. package/dist/contracts/IdentityContract.d.ts +36 -0
  13. package/dist/contracts/IdentityContract.js +2 -0
  14. package/dist/contracts/SessionContract.d.ts +25 -0
  15. package/dist/contracts/SessionContract.js +10 -0
  16. package/dist/data/applyPendingMigrations.d.ts +2 -0
  17. package/dist/data/applyPendingMigrations.js +30 -0
  18. package/dist/data/migrations.d.ts +2 -0
  19. package/dist/data/migrations.js +47 -0
  20. package/dist/data/schemas.d.ts +11 -0
  21. package/dist/data/schemas.js +109 -0
  22. package/dist/index.d.ts +20 -0
  23. package/dist/index.js +36 -0
  24. package/dist/runtime/ContractStage.d.ts +2 -0
  25. package/dist/runtime/ContractStage.js +4 -0
  26. package/dist/services/AuthAuditService.d.ts +7 -0
  27. package/dist/services/AuthAuditService.js +2 -0
  28. package/dist/services/AuthHostComposition.d.ts +40 -0
  29. package/dist/services/AuthHostComposition.js +100 -0
  30. package/dist/services/AuthPolicyService.d.ts +9 -0
  31. package/dist/services/AuthPolicyService.js +2 -0
  32. package/dist/services/ContextService.d.ts +6 -0
  33. package/dist/services/ContextService.js +2 -0
  34. package/dist/services/IdentityService.d.ts +15 -0
  35. package/dist/services/IdentityService.js +2 -0
  36. package/dist/services/SessionService.d.ts +7 -0
  37. package/dist/services/SessionService.js +2 -0
  38. package/dist/services/createContractOnlyOfauthServices.d.ts +13 -0
  39. package/dist/services/createContractOnlyOfauthServices.js +82 -0
  40. package/dist/services/createDbAdapterOfauthServices.d.ts +20 -0
  41. package/dist/services/createDbAdapterOfauthServices.js +22 -0
  42. package/dist/services/errors.d.ts +8 -0
  43. package/dist/services/errors.js +20 -0
  44. package/dist/services/impl/DbAdapterAuthAuditService.d.ts +14 -0
  45. package/dist/services/impl/DbAdapterAuthAuditService.js +107 -0
  46. package/dist/services/impl/DbAdapterAuthPolicyService.d.ts +17 -0
  47. package/dist/services/impl/DbAdapterAuthPolicyService.js +114 -0
  48. package/dist/services/impl/DbAdapterContextService.d.ts +13 -0
  49. package/dist/services/impl/DbAdapterContextService.js +79 -0
  50. package/dist/services/impl/DbAdapterIdentityService.d.ts +23 -0
  51. package/dist/services/impl/DbAdapterIdentityService.js +146 -0
  52. package/dist/services/impl/DbAdapterSessionService.d.ts +14 -0
  53. package/dist/services/impl/DbAdapterSessionService.js +63 -0
  54. package/dist/services/impl/runtimeSupport.d.ts +95 -0
  55. package/dist/services/impl/runtimeSupport.js +112 -0
  56. package/package.json +37 -0
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ofauthSchema = exports.OFAUTH_TABLES = void 0;
4
+ exports.getOfauthTableSchemas = getOfauthTableSchemas;
5
+ exports.OFAUTH_TABLES = {
6
+ identities: 'ofauth_identities',
7
+ assignments: 'ofauth_assignments',
8
+ sessions: 'ofauth_sessions',
9
+ policyProfiles: 'ofauth_policy_profiles',
10
+ policyStepups: 'ofauth_policy_stepups',
11
+ auditEvents: 'ofauth_audit_events',
12
+ };
13
+ const tableSchemas = [
14
+ {
15
+ name: exports.OFAUTH_TABLES.identities,
16
+ columns: [
17
+ { name: 'id', type: 'string' },
18
+ { name: 'principal', type: 'string', isIndexed: true },
19
+ { name: 'secretHash', type: 'string' },
20
+ { name: 'verifyMethod', type: 'string', enum: ['pin', 'password', 'custom'] },
21
+ { name: 'status', type: 'string', enum: ['active', 'disabled', 'locked'], isIndexed: true },
22
+ { name: 'failedAttempts', type: 'number' },
23
+ { name: 'lockoutUntil', type: 'string', isOptional: true },
24
+ { name: 'version', type: 'number' },
25
+ { name: 'lastModified', type: 'string' },
26
+ { name: 'deleted', type: 'boolean', isIndexed: true },
27
+ ],
28
+ },
29
+ {
30
+ name: exports.OFAUTH_TABLES.assignments,
31
+ columns: [
32
+ { name: 'id', type: 'string' },
33
+ { name: 'identityId', type: 'string', isIndexed: true },
34
+ { name: 'roleRef', type: 'string', isIndexed: true },
35
+ { name: 'tenantId', type: 'string', isOptional: true, isIndexed: true },
36
+ { name: 'branchId', type: 'string', isOptional: true, isIndexed: true },
37
+ { name: 'scopeAttributes', type: 'json', isOptional: true },
38
+ { name: 'version', type: 'number' },
39
+ { name: 'lastModified', type: 'string' },
40
+ { name: 'deleted', type: 'boolean', isIndexed: true },
41
+ ],
42
+ },
43
+ {
44
+ name: exports.OFAUTH_TABLES.sessions,
45
+ columns: [
46
+ { name: 'id', type: 'string' },
47
+ { name: 'identityId', type: 'string', isIndexed: true },
48
+ { name: 'activeAssignmentId', type: 'string', isOptional: true, isIndexed: true },
49
+ { name: 'assuranceLevel', type: 'string', enum: ['basic', 'elevated'], isIndexed: true },
50
+ { name: 'issuedAt', type: 'string' },
51
+ { name: 'expiresAt', type: 'string', isIndexed: true },
52
+ { name: 'revokedAt', type: 'string', isOptional: true },
53
+ { name: 'version', type: 'number' },
54
+ { name: 'lastModified', type: 'string' },
55
+ { name: 'deleted', type: 'boolean', isIndexed: true },
56
+ ],
57
+ },
58
+ {
59
+ name: exports.OFAUTH_TABLES.policyProfiles,
60
+ columns: [
61
+ { name: 'id', type: 'string' },
62
+ { name: 'profileId', type: 'string', isIndexed: true },
63
+ { name: 'defaultAssuranceLevel', type: 'string', enum: ['basic', 'elevated'] },
64
+ { name: 'lockoutPolicyRef', type: 'string' },
65
+ { name: 'version', type: 'number' },
66
+ { name: 'lastModified', type: 'string' },
67
+ { name: 'deleted', type: 'boolean', isIndexed: true },
68
+ ],
69
+ },
70
+ {
71
+ name: exports.OFAUTH_TABLES.policyStepups,
72
+ columns: [
73
+ { name: 'id', type: 'string' },
74
+ { name: 'actionRef', type: 'string', isIndexed: true },
75
+ { name: 'requiredAssuranceLevel', type: 'string', enum: ['basic', 'elevated'] },
76
+ { name: 'reauthWindowSeconds', type: 'number', isOptional: true },
77
+ { name: 'version', type: 'number' },
78
+ { name: 'lastModified', type: 'string' },
79
+ { name: 'deleted', type: 'boolean', isIndexed: true },
80
+ ],
81
+ },
82
+ {
83
+ name: exports.OFAUTH_TABLES.auditEvents,
84
+ columns: [
85
+ { name: 'id', type: 'string' },
86
+ { name: 'eventType', type: 'string', isIndexed: true },
87
+ { name: 'identityId', type: 'string', isOptional: true, isIndexed: true },
88
+ { name: 'sessionId', type: 'string', isOptional: true, isIndexed: true },
89
+ { name: 'tenantId', type: 'string', isOptional: true, isIndexed: true },
90
+ { name: 'branchId', type: 'string', isOptional: true, isIndexed: true },
91
+ { name: 'scopeAttributes', type: 'json', isOptional: true },
92
+ { name: 'result', type: 'string', enum: ['success', 'failed'], isIndexed: true },
93
+ { name: 'reasonCode', type: 'string', isOptional: true },
94
+ { name: 'timestamp', type: 'string', isIndexed: true },
95
+ { name: 'syncStatus', type: 'string', enum: ['pending', 'replayed'], isIndexed: true },
96
+ { name: 'replayedAt', type: 'string', isOptional: true, isIndexed: true },
97
+ { name: 'version', type: 'number' },
98
+ { name: 'lastModified', type: 'string' },
99
+ { name: 'deleted', type: 'boolean', isIndexed: true },
100
+ ],
101
+ },
102
+ ];
103
+ exports.ofauthSchema = {
104
+ version: 2,
105
+ tables: tableSchemas,
106
+ };
107
+ function getOfauthTableSchemas() {
108
+ return exports.ofauthSchema.tables;
109
+ }
@@ -0,0 +1,20 @@
1
+ export * from './contracts/ContextContract';
2
+ export * from './contracts/IdentityContract';
3
+ export * from './contracts/SessionContract';
4
+ export * from './contracts/AuthPolicyContract';
5
+ export * from './contracts/AuthAuditContract';
6
+ export * from './contracts/AuthErrorContract';
7
+ export * from './services/IdentityService';
8
+ export * from './services/SessionService';
9
+ export * from './services/ContextService';
10
+ export * from './services/AuthHostComposition';
11
+ export * from './services/AuthPolicyService';
12
+ export * from './services/AuthAuditService';
13
+ export * from './services/createContractOnlyOfauthServices';
14
+ export * from './services/createDbAdapterOfauthServices';
15
+ export * from './services/errors';
16
+ export * from './runtime/ContractStage';
17
+ export * from './OfauthCore';
18
+ export * from './data/schemas';
19
+ export * from './data/migrations';
20
+ export * from './data/applyPendingMigrations';
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./contracts/ContextContract"), exports);
18
+ __exportStar(require("./contracts/IdentityContract"), exports);
19
+ __exportStar(require("./contracts/SessionContract"), exports);
20
+ __exportStar(require("./contracts/AuthPolicyContract"), exports);
21
+ __exportStar(require("./contracts/AuthAuditContract"), exports);
22
+ __exportStar(require("./contracts/AuthErrorContract"), exports);
23
+ __exportStar(require("./services/IdentityService"), exports);
24
+ __exportStar(require("./services/SessionService"), exports);
25
+ __exportStar(require("./services/ContextService"), exports);
26
+ __exportStar(require("./services/AuthHostComposition"), exports);
27
+ __exportStar(require("./services/AuthPolicyService"), exports);
28
+ __exportStar(require("./services/AuthAuditService"), exports);
29
+ __exportStar(require("./services/createContractOnlyOfauthServices"), exports);
30
+ __exportStar(require("./services/createDbAdapterOfauthServices"), exports);
31
+ __exportStar(require("./services/errors"), exports);
32
+ __exportStar(require("./runtime/ContractStage"), exports);
33
+ __exportStar(require("./OfauthCore"), exports);
34
+ __exportStar(require("./data/schemas"), exports);
35
+ __exportStar(require("./data/migrations"), exports);
36
+ __exportStar(require("./data/applyPendingMigrations"), exports);
@@ -0,0 +1,2 @@
1
+ export type OfauthContractStage = 'phase1-contract-only' | 'phase2-runtime-logic';
2
+ export declare const OFAUTH_CONTRACT_STAGE: OfauthContractStage;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OFAUTH_CONTRACT_STAGE = void 0;
4
+ exports.OFAUTH_CONTRACT_STAGE = 'phase1-contract-only';
@@ -0,0 +1,7 @@
1
+ import type { AuthAuditEvent, AuthAuditQuery, AuthAuditReplayQuery } from '../contracts/AuthAuditContract';
2
+ export interface AuthAuditService {
3
+ appendEvent(event: AuthAuditEvent): Promise<void>;
4
+ queryEvents(query: AuthAuditQuery): Promise<AuthAuditEvent[]>;
5
+ listPendingReplay(query?: AuthAuditReplayQuery): Promise<AuthAuditEvent[]>;
6
+ markReplayed(eventIds: string[], replayedAt?: string): Promise<number>;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,40 @@
1
+ import type { AuthScopeRef, ContextAssignment } from '../contracts/ContextContract';
2
+ import { type AssuranceLevel } from '../contracts/SessionContract';
3
+ import type { OfauthDomainServices } from './createContractOnlyOfauthServices';
4
+ import type { LoginRequest } from './IdentityService';
5
+ export interface ResolvedAuthContext {
6
+ sessionId: string;
7
+ identityId: string;
8
+ principal: string;
9
+ assignments: ContextAssignment[];
10
+ activeContextAssignmentId?: string;
11
+ activeAssignment?: ContextAssignment;
12
+ scopeRef: AuthScopeRef;
13
+ roleRef?: string;
14
+ assuranceLevel: AssuranceLevel;
15
+ }
16
+ export interface ProtectedRoutePolicy {
17
+ minimumAssuranceLevel?: AssuranceLevel;
18
+ requiredRoleRefs?: string[];
19
+ requiredTenantId?: string;
20
+ requiredBranchId?: string;
21
+ requiredScopeAttributes?: Record<string, string>;
22
+ }
23
+ export interface ProtectedRouteGateResult {
24
+ allowed: boolean;
25
+ reasonCode?: 'NO_SESSION' | 'ASSURANCE_TOO_LOW' | 'ROLE_FORBIDDEN' | 'SCOPE_FORBIDDEN';
26
+ }
27
+ export declare function loginWithResolvedContext(services: Pick<OfauthDomainServices, 'identityService' | 'sessionService' | 'contextService'>, input: LoginRequest): Promise<ResolvedAuthContext>;
28
+ export declare function refreshResolvedContext(services: Pick<OfauthDomainServices, 'sessionService' | 'contextService'>, input: {
29
+ sessionId: string;
30
+ identityId: string;
31
+ principal: string;
32
+ }): Promise<ResolvedAuthContext | null>;
33
+ export declare function switchContextWithResolvedState(services: Pick<OfauthDomainServices, 'sessionService' | 'contextService'>, input: {
34
+ sessionId: string;
35
+ identityId: string;
36
+ principal: string;
37
+ targetAssignmentId: string;
38
+ reasonCode?: string;
39
+ }): Promise<ResolvedAuthContext>;
40
+ export declare function evaluateProtectedRouteGate(resolved: ResolvedAuthContext | null, policy?: ProtectedRoutePolicy): ProtectedRouteGateResult;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loginWithResolvedContext = loginWithResolvedContext;
4
+ exports.refreshResolvedContext = refreshResolvedContext;
5
+ exports.switchContextWithResolvedState = switchContextWithResolvedState;
6
+ exports.evaluateProtectedRouteGate = evaluateProtectedRouteGate;
7
+ const SessionContract_1 = require("../contracts/SessionContract");
8
+ function findAssignment(assignments, assignmentId) {
9
+ if (!assignmentId)
10
+ return undefined;
11
+ return assignments.find((row) => row.assignmentId === assignmentId);
12
+ }
13
+ function isScopeAllowed(scope, policy) {
14
+ if (policy.requiredTenantId && scope.tenantId !== policy.requiredTenantId)
15
+ return false;
16
+ if (policy.requiredBranchId && scope.branchId !== policy.requiredBranchId)
17
+ return false;
18
+ if (policy.requiredScopeAttributes) {
19
+ const attrs = scope.attributes ?? {};
20
+ for (const [key, value] of Object.entries(policy.requiredScopeAttributes)) {
21
+ if (attrs[key] !== value)
22
+ return false;
23
+ }
24
+ }
25
+ return true;
26
+ }
27
+ async function buildResolvedContext(services, input) {
28
+ const session = await services.sessionService.getActiveSession(input.sessionId);
29
+ if (!session)
30
+ return null;
31
+ const assignments = await services.contextService.listAssignments(input.identityId);
32
+ let activeContext = await services.contextService.getActiveContext(input.sessionId);
33
+ if (!activeContext && assignments[0]) {
34
+ const switched = await services.contextService.switchContext({
35
+ sessionId: input.sessionId,
36
+ targetAssignmentId: assignments[0].assignmentId,
37
+ ...(input.assignmentFallbackReason ? { reasonCode: input.assignmentFallbackReason } : {}),
38
+ });
39
+ activeContext = switched.activeContext;
40
+ }
41
+ const activeAssignment = findAssignment(assignments, activeContext?.assignmentId);
42
+ return {
43
+ sessionId: input.sessionId,
44
+ identityId: input.identityId,
45
+ principal: input.principal,
46
+ assignments,
47
+ activeContextAssignmentId: activeContext?.assignmentId,
48
+ activeAssignment,
49
+ scopeRef: activeContext?.scopeRef ?? activeAssignment?.scopeRef ?? session.activeScopeRef ?? {},
50
+ roleRef: activeAssignment?.roleRef,
51
+ assuranceLevel: session.assuranceLevel,
52
+ };
53
+ }
54
+ async function loginWithResolvedContext(services, input) {
55
+ const login = await services.identityService.login(input);
56
+ const resolved = await buildResolvedContext(services, {
57
+ sessionId: login.sessionId,
58
+ identityId: login.identity.identityId,
59
+ principal: login.identity.principal,
60
+ assignmentFallbackReason: 'AUTO_CONTEXT_AFTER_LOGIN',
61
+ });
62
+ if (!resolved) {
63
+ throw new Error('session is not active after login');
64
+ }
65
+ return resolved;
66
+ }
67
+ async function refreshResolvedContext(services, input) {
68
+ return buildResolvedContext(services, input);
69
+ }
70
+ async function switchContextWithResolvedState(services, input) {
71
+ await services.contextService.switchContext({
72
+ sessionId: input.sessionId,
73
+ targetAssignmentId: input.targetAssignmentId,
74
+ ...(input.reasonCode ? { reasonCode: input.reasonCode } : {}),
75
+ });
76
+ const resolved = await buildResolvedContext(services, input);
77
+ if (!resolved) {
78
+ throw new Error('session is not active while switching context');
79
+ }
80
+ return resolved;
81
+ }
82
+ function evaluateProtectedRouteGate(resolved, policy = {}) {
83
+ if (!resolved) {
84
+ return { allowed: false, reasonCode: 'NO_SESSION' };
85
+ }
86
+ const minimumAssurance = policy.minimumAssuranceLevel ?? 'basic';
87
+ if (!(0, SessionContract_1.isAssuranceLevelAtLeast)(resolved.assuranceLevel, minimumAssurance)) {
88
+ return { allowed: false, reasonCode: 'ASSURANCE_TOO_LOW' };
89
+ }
90
+ if (policy.requiredRoleRefs?.length) {
91
+ const hasRole = !!resolved.roleRef && policy.requiredRoleRefs.includes(resolved.roleRef);
92
+ if (!hasRole) {
93
+ return { allowed: false, reasonCode: 'ROLE_FORBIDDEN' };
94
+ }
95
+ }
96
+ if (!isScopeAllowed(resolved.scopeRef, policy)) {
97
+ return { allowed: false, reasonCode: 'SCOPE_FORBIDDEN' };
98
+ }
99
+ return { allowed: true };
100
+ }
@@ -0,0 +1,9 @@
1
+ import type { AuthPolicySnapshot, StepUpEvaluation, StepUpRequirement } from '../contracts/AuthPolicyContract';
2
+ import type { SessionRef } from '../contracts/SessionContract';
3
+ export interface AuthPolicyService {
4
+ getPolicySnapshot(): Promise<AuthPolicySnapshot>;
5
+ getStepUpRequirement(actionRef: string): Promise<StepUpRequirement | null>;
6
+ evaluateStepUp(sessionId: string, actionRef: string): Promise<StepUpEvaluation>;
7
+ enforceStepUp(sessionId: string, actionRef: string): Promise<void>;
8
+ markStepUpPassed(sessionId: string, actionRef: string): Promise<SessionRef>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import type { ActiveContext, ContextAssignment, ContextSwitchRequest, ContextSwitchResult } from '../contracts/ContextContract';
2
+ export interface ContextService {
3
+ listAssignments(identityId: string): Promise<ContextAssignment[]>;
4
+ getActiveContext(sessionId: string): Promise<ActiveContext | null>;
5
+ switchContext(input: ContextSwitchRequest): Promise<ContextSwitchResult>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import type { CredentialVerifyRequest, CredentialVerifyResult, IdentityRef } from '../contracts/IdentityContract';
2
+ export interface LoginRequest {
3
+ principal: string;
4
+ secret: string;
5
+ verifyMethod: 'pin' | 'password' | 'custom';
6
+ }
7
+ export interface LoginResult {
8
+ identity: IdentityRef;
9
+ sessionId: string;
10
+ }
11
+ export interface IdentityService {
12
+ verifyCredential(input: CredentialVerifyRequest): Promise<CredentialVerifyResult>;
13
+ login(input: LoginRequest): Promise<LoginResult>;
14
+ logout(sessionId: string): Promise<void>;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import type { CreateSessionRequest, RefreshSessionRequest, RevokeSessionRequest, SessionRef } from '../contracts/SessionContract';
2
+ export interface SessionService {
3
+ createSession(input: CreateSessionRequest): Promise<SessionRef>;
4
+ refreshSession(input: RefreshSessionRequest): Promise<SessionRef>;
5
+ revokeSession(input: RevokeSessionRequest): Promise<void>;
6
+ getActiveSession(sessionId: string): Promise<SessionRef | null>;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import type { AuthAuditService } from './AuthAuditService';
2
+ import type { AuthPolicyService } from './AuthPolicyService';
3
+ import type { ContextService } from './ContextService';
4
+ import type { IdentityService } from './IdentityService';
5
+ import type { SessionService } from './SessionService';
6
+ export interface OfauthDomainServices {
7
+ identityService: IdentityService;
8
+ sessionService: SessionService;
9
+ contextService: ContextService;
10
+ authPolicyService: AuthPolicyService;
11
+ authAuditService: AuthAuditService;
12
+ }
13
+ export declare function createContractOnlyOfauthServices(): OfauthDomainServices;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createContractOnlyOfauthServices = createContractOnlyOfauthServices;
4
+ function notImplemented(message) {
5
+ const error = {
6
+ code: 'AUTH_NOT_IMPLEMENTED',
7
+ message,
8
+ retryable: false,
9
+ };
10
+ throw error;
11
+ }
12
+ function createContractOnlyOfauthServices() {
13
+ return {
14
+ identityService: {
15
+ async verifyCredential() {
16
+ return notImplemented('identityService.verifyCredential not implemented yet');
17
+ },
18
+ async login() {
19
+ return notImplemented('identityService.login not implemented yet');
20
+ },
21
+ async logout() {
22
+ return notImplemented('identityService.logout not implemented yet');
23
+ },
24
+ },
25
+ sessionService: {
26
+ async createSession() {
27
+ return notImplemented('sessionService.createSession not implemented yet');
28
+ },
29
+ async refreshSession() {
30
+ return notImplemented('sessionService.refreshSession not implemented yet');
31
+ },
32
+ async revokeSession() {
33
+ return notImplemented('sessionService.revokeSession not implemented yet');
34
+ },
35
+ async getActiveSession() {
36
+ return notImplemented('sessionService.getActiveSession not implemented yet');
37
+ },
38
+ },
39
+ contextService: {
40
+ async listAssignments() {
41
+ return notImplemented('contextService.listAssignments not implemented yet');
42
+ },
43
+ async getActiveContext() {
44
+ return notImplemented('contextService.getActiveContext not implemented yet');
45
+ },
46
+ async switchContext() {
47
+ return notImplemented('contextService.switchContext not implemented yet');
48
+ },
49
+ },
50
+ authPolicyService: {
51
+ async getPolicySnapshot() {
52
+ return notImplemented('authPolicyService.getPolicySnapshot not implemented yet');
53
+ },
54
+ async getStepUpRequirement() {
55
+ return notImplemented('authPolicyService.getStepUpRequirement not implemented yet');
56
+ },
57
+ async evaluateStepUp() {
58
+ return notImplemented('authPolicyService.evaluateStepUp not implemented yet');
59
+ },
60
+ async enforceStepUp() {
61
+ return notImplemented('authPolicyService.enforceStepUp not implemented yet');
62
+ },
63
+ async markStepUpPassed() {
64
+ return notImplemented('authPolicyService.markStepUpPassed not implemented yet');
65
+ },
66
+ },
67
+ authAuditService: {
68
+ async appendEvent() {
69
+ return notImplemented('authAuditService.appendEvent not implemented yet');
70
+ },
71
+ async queryEvents() {
72
+ return notImplemented('authAuditService.queryEvents not implemented yet');
73
+ },
74
+ async listPendingReplay() {
75
+ return notImplemented('authAuditService.listPendingReplay not implemented yet');
76
+ },
77
+ async markReplayed() {
78
+ return notImplemented('authAuditService.markReplayed not implemented yet');
79
+ },
80
+ },
81
+ };
82
+ }
@@ -0,0 +1,20 @@
1
+ import type { ActivityRecord, DbAdapter, LoggerAdapter, PlatformAdapter } from 'ofcore';
2
+ import type { AuthAuditService } from './AuthAuditService';
3
+ import type { AuthPolicyService } from './AuthPolicyService';
4
+ import type { ContextService } from './ContextService';
5
+ import type { IdentityService } from './IdentityService';
6
+ import type { SessionService } from './SessionService';
7
+ import type { OfauthDomainServices } from './createContractOnlyOfauthServices';
8
+ export interface ServiceRuntimeOptions {
9
+ logger?: LoggerAdapter;
10
+ platformAdapter?: PlatformAdapter;
11
+ emitActivity?: (record: ActivityRecord) => Promise<void>;
12
+ }
13
+ export interface OfauthDbAdapterServices extends OfauthDomainServices {
14
+ identityService: IdentityService;
15
+ sessionService: SessionService;
16
+ contextService: ContextService;
17
+ authPolicyService: AuthPolicyService;
18
+ authAuditService: AuthAuditService;
19
+ }
20
+ export declare function createDbAdapterOfauthServices(db: DbAdapter, options?: ServiceRuntimeOptions): Promise<OfauthDbAdapterServices>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDbAdapterOfauthServices = createDbAdapterOfauthServices;
4
+ const DbAdapterAuthAuditService_1 = require("./impl/DbAdapterAuthAuditService");
5
+ const DbAdapterAuthPolicyService_1 = require("./impl/DbAdapterAuthPolicyService");
6
+ const DbAdapterContextService_1 = require("./impl/DbAdapterContextService");
7
+ const DbAdapterIdentityService_1 = require("./impl/DbAdapterIdentityService");
8
+ const DbAdapterSessionService_1 = require("./impl/DbAdapterSessionService");
9
+ async function createDbAdapterOfauthServices(db, options = {}) {
10
+ const authAuditService = new DbAdapterAuthAuditService_1.DbAdapterAuthAuditService(db, options);
11
+ const sessionService = new DbAdapterSessionService_1.DbAdapterSessionService(db, options);
12
+ const contextService = new DbAdapterContextService_1.DbAdapterContextService(db, authAuditService);
13
+ const authPolicyService = new DbAdapterAuthPolicyService_1.DbAdapterAuthPolicyService(db, authAuditService);
14
+ const identityService = new DbAdapterIdentityService_1.DbAdapterIdentityService(db, options, sessionService, contextService, authAuditService);
15
+ return {
16
+ identityService,
17
+ sessionService,
18
+ contextService,
19
+ authPolicyService,
20
+ authAuditService,
21
+ };
22
+ }
@@ -0,0 +1,8 @@
1
+ import type { AuthErrorCode } from '../contracts/AuthErrorContract';
2
+ export declare class OfauthDomainError extends Error {
3
+ readonly code: AuthErrorCode;
4
+ readonly retryable: boolean;
5
+ constructor(code: AuthErrorCode, message: string, retryable?: boolean);
6
+ }
7
+ export declare function unauthorized(code: AuthErrorCode, message: string): OfauthDomainError;
8
+ export declare function invalidState(message: string): OfauthDomainError;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OfauthDomainError = void 0;
4
+ exports.unauthorized = unauthorized;
5
+ exports.invalidState = invalidState;
6
+ class OfauthDomainError extends Error {
7
+ constructor(code, message, retryable = false) {
8
+ super(message);
9
+ this.code = code;
10
+ this.retryable = retryable;
11
+ this.name = 'OfauthDomainError';
12
+ }
13
+ }
14
+ exports.OfauthDomainError = OfauthDomainError;
15
+ function unauthorized(code, message) {
16
+ return new OfauthDomainError(code, message, false);
17
+ }
18
+ function invalidState(message) {
19
+ return new OfauthDomainError('AUTH_NOT_IMPLEMENTED', message, false);
20
+ }
@@ -0,0 +1,14 @@
1
+ import type { DbAdapter } from 'ofcore';
2
+ import type { AuthAuditEvent, AuthAuditQuery, AuthAuditReplayQuery } from '../../contracts/AuthAuditContract';
3
+ import type { AuthAuditService } from '../AuthAuditService';
4
+ import type { ServiceRuntimeOptions } from './runtimeSupport';
5
+ export declare class DbAdapterAuthAuditService implements AuthAuditService {
6
+ private readonly db;
7
+ private readonly options;
8
+ private readonly newId;
9
+ constructor(db: DbAdapter, options: ServiceRuntimeOptions);
10
+ appendEvent(event: AuthAuditEvent): Promise<void>;
11
+ queryEvents(query: AuthAuditQuery): Promise<AuthAuditEvent[]>;
12
+ listPendingReplay(query?: AuthAuditReplayQuery): Promise<AuthAuditEvent[]>;
13
+ markReplayed(eventIds: string[], replayedAt?: string): Promise<number>;
14
+ }