@solidxai/core 0.1.18-beta.0 → 0.1.19-beta.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/CHANGELOG.md +1353 -0
- package/CLAUDE.md +26 -0
- package/dist/commands/seed.command.d.ts +2 -0
- package/dist/commands/seed.command.d.ts.map +1 -1
- package/dist/commands/seed.command.js +10 -2
- package/dist/commands/seed.command.js.map +1 -1
- package/dist/constants/error-messages.d.ts +2 -0
- package/dist/constants/error-messages.d.ts.map +1 -1
- package/dist/constants/error-messages.js +2 -0
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/decorators/login-extension-provider.decorator.d.ts +3 -0
- package/dist/decorators/login-extension-provider.decorator.d.ts.map +1 -0
- package/dist/decorators/login-extension-provider.decorator.js +8 -0
- package/dist/decorators/login-extension-provider.decorator.js.map +1 -0
- package/dist/helpers/bootstrap.helper.d.ts +1 -0
- package/dist/helpers/bootstrap.helper.d.ts.map +1 -1
- package/dist/helpers/bootstrap.helper.js +7 -6
- package/dist/helpers/bootstrap.helper.js.map +1 -1
- package/dist/helpers/solid-core-error-codes-provider.service.d.ts.map +1 -1
- package/dist/helpers/solid-core-error-codes-provider.service.js +18 -0
- package/dist/helpers/solid-core-error-codes-provider.service.js.map +1 -1
- package/dist/helpers/solid-registry.d.ts +5 -1
- package/dist/helpers/solid-registry.d.ts.map +1 -1
- package/dist/helpers/solid-registry.js +16 -0
- package/dist/helpers/solid-registry.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +24 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js +6 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +1 -0
- package/dist/services/authentication.service.d.ts +11 -1
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +70 -4
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/dashboard-providers/mq-dashboard-recent-failures-provider.service.d.ts +21 -1
- package/dist/services/dashboard-providers/mq-dashboard-recent-failures-provider.service.d.ts.map +1 -1
- package/dist/services/dashboard-providers/mq-dashboard-recent-failures-provider.service.js +10 -10
- package/dist/services/dashboard-providers/mq-dashboard-recent-failures-provider.service.js.map +1 -1
- package/dist/services/solid-introspect.service.d.ts +1 -0
- package/dist/services/solid-introspect.service.d.ts.map +1 -1
- package/dist/services/solid-introspect.service.js +11 -0
- package/dist/services/solid-introspect.service.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/seed.command.ts +7 -2
- package/src/constants/error-messages.ts +2 -0
- package/src/decorators/login-extension-provider.decorator.ts +6 -0
- package/src/helpers/bootstrap.helper.ts +31 -8
- package/src/helpers/solid-core-error-codes-provider.service.ts +21 -0
- package/src/helpers/solid-registry.ts +19 -1
- package/src/index.ts +1 -0
- package/src/interfaces.ts +93 -0
- package/src/seeders/seed-data/solid-core-metadata.json +1 -0
- package/src/services/authentication.service.ts +135 -3
- package/src/services/dashboard-providers/mq-dashboard-recent-failures-provider.service.ts +31 -13
- package/src/services/solid-introspect.service.ts +13 -0
|
@@ -8000,6 +8000,7 @@
|
|
|
8000
8000
|
"ViewMetadataController.findOne",
|
|
8001
8001
|
"ActionMetadataController.findMany",
|
|
8002
8002
|
"ActionMetadataController.findOne",
|
|
8003
|
+
"UserViewMetadataController.create",
|
|
8003
8004
|
"UserViewMetadataController.upsert",
|
|
8004
8005
|
"UserViewMetadataController.findMany",
|
|
8005
8006
|
"UserViewMetadataController.findOne",
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
InternalServerErrorException,
|
|
9
9
|
Logger,
|
|
10
10
|
NotFoundException,
|
|
11
|
+
ServiceUnavailableException,
|
|
11
12
|
UnauthorizedException,
|
|
12
13
|
} from "@nestjs/common";
|
|
13
14
|
import { EventEmitter2 } from "@nestjs/event-emitter";
|
|
@@ -38,8 +39,15 @@ import { SignInDto } from "../dtos/sign-in.dto";
|
|
|
38
39
|
import { SignUpDto } from "../dtos/sign-up.dto";
|
|
39
40
|
import { SignupIntent } from "../enums/signup-intent.enum";
|
|
40
41
|
import { User } from "../entities/user.entity";
|
|
41
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
EventDetails,
|
|
44
|
+
EventType,
|
|
45
|
+
ILoginExtensionContext,
|
|
46
|
+
ILoginExtensionProvider,
|
|
47
|
+
LoginExtensionChannel,
|
|
48
|
+
} from "../interfaces";
|
|
42
49
|
import { ActiveUserData } from "../interfaces/active-user-data.interface";
|
|
50
|
+
import { SolidRegistry } from "../helpers/solid-registry";
|
|
43
51
|
import { ActiveSessionStorageService } from "./active-session-storage.service";
|
|
44
52
|
import { AccessTokenDenylistService } from "./access-token-denylist.service";
|
|
45
53
|
import { HashingService } from "./hashing.service";
|
|
@@ -121,6 +129,19 @@ const SIGNUP_POLICY: Record<
|
|
|
121
129
|
},
|
|
122
130
|
};
|
|
123
131
|
|
|
132
|
+
/** Deadline for a single login extension provider, unless it overrides it. */
|
|
133
|
+
const DEFAULT_LOGIN_EXTENSION_TIMEOUT_MS = 5000;
|
|
134
|
+
|
|
135
|
+
/** A registered login extension provider denied this attempt. */
|
|
136
|
+
export class LoginExtensionDeniedException extends UnauthorizedException {}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A login extension provider malfunctioned or timed out while its failure
|
|
140
|
+
* policy was fail-closed. 503, not 401: the credential was fine, the
|
|
141
|
+
* dependency was not, and the client should retry.
|
|
142
|
+
*/
|
|
143
|
+
export class LoginExtensionUnavailableException extends ServiceUnavailableException {}
|
|
144
|
+
|
|
124
145
|
@Injectable()
|
|
125
146
|
export class AuthenticationService {
|
|
126
147
|
private readonly logger = new Logger(AuthenticationService.name);
|
|
@@ -146,6 +167,7 @@ export class AuthenticationService {
|
|
|
146
167
|
private readonly userActivityHistoryService: UserActivityHistoryService,
|
|
147
168
|
private readonly ssoCodeStorage: SsoCodeStorageService,
|
|
148
169
|
private readonly metadataValidationService: MetadataValidationService,
|
|
170
|
+
private readonly solidRegistry: SolidRegistry,
|
|
149
171
|
|
|
150
172
|
@InjectDataSource()
|
|
151
173
|
private readonly dataSource: DataSource,
|
|
@@ -207,6 +229,103 @@ export class AuthenticationService {
|
|
|
207
229
|
});
|
|
208
230
|
}
|
|
209
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Runs the registered login extension chain for a user whose primary
|
|
234
|
+
* credential has already been proven.
|
|
235
|
+
*
|
|
236
|
+
* Every call site invokes this after that path's credential check has
|
|
237
|
+
* passed and before any token is minted, so the chain can only convert a
|
|
238
|
+
* successful login into a failure - never the other way round.
|
|
239
|
+
*/
|
|
240
|
+
async runLoginExtensions(
|
|
241
|
+
user: User,
|
|
242
|
+
ctxt: Omit<ILoginExtensionContext, "attemptId" | "startedAt">,
|
|
243
|
+
): Promise<void> {
|
|
244
|
+
const wrappers = this.solidRegistry.getLoginExtensionProviders();
|
|
245
|
+
|
|
246
|
+
// Guardrail: with no provider registered this is the entire cost of the
|
|
247
|
+
// feature - one array read. No log line, nothing observable in any login
|
|
248
|
+
// path. Do not "simplify" this early return away: it is what makes
|
|
249
|
+
// absence structurally different from a provider that errors.
|
|
250
|
+
if (wrappers.length === 0) return;
|
|
251
|
+
|
|
252
|
+
const context: ILoginExtensionContext = {
|
|
253
|
+
attemptId: randomUUID(),
|
|
254
|
+
startedAt: new Date(),
|
|
255
|
+
...ctxt,
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const providers = wrappers
|
|
259
|
+
.map((w) => w.instance as ILoginExtensionProvider)
|
|
260
|
+
.filter(Boolean)
|
|
261
|
+
.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
262
|
+
|
|
263
|
+
for (const provider of providers) {
|
|
264
|
+
const providerName =
|
|
265
|
+
provider.name?.() ?? provider.constructor?.name ?? "unknown";
|
|
266
|
+
try {
|
|
267
|
+
const result = await this.withLoginExtensionTimeout(
|
|
268
|
+
provider.verifyLogin(user, context),
|
|
269
|
+
provider.timeoutMs ?? DEFAULT_LOGIN_EXTENSION_TIMEOUT_MS,
|
|
270
|
+
providerName,
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
if (result?.allow === false) {
|
|
274
|
+
this.logger.warn(
|
|
275
|
+
`Login denied by ${providerName} for user ${user.id} ` +
|
|
276
|
+
`[attempt=${context.attemptId} channel=${context.channel}]: ` +
|
|
277
|
+
`${result.reason ?? "no reason given"}`,
|
|
278
|
+
);
|
|
279
|
+
throw new LoginExtensionDeniedException(
|
|
280
|
+
result.message ?? ERROR_MESSAGES.LOGIN_DENIED_BY_EXTENSION,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
} catch (e: any) {
|
|
284
|
+
// Our own denial is a decision, not a malfunction, and is never
|
|
285
|
+
// fail-opened.
|
|
286
|
+
if (e instanceof LoginExtensionDeniedException) throw e;
|
|
287
|
+
|
|
288
|
+
const policy = provider.failurePolicy ?? "fail-closed";
|
|
289
|
+
this.logger.error(
|
|
290
|
+
`Login extension ${providerName} failed ` +
|
|
291
|
+
`[attempt=${context.attemptId} policy=${policy}]: ${e?.message}`,
|
|
292
|
+
e?.stack,
|
|
293
|
+
);
|
|
294
|
+
if (policy === "fail-open") continue;
|
|
295
|
+
throw new LoginExtensionUnavailableException(
|
|
296
|
+
ERROR_MESSAGES.LOGIN_EXTENSION_UNAVAILABLE,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* A provider that ignores its own timeouts must not be able to hang login,
|
|
304
|
+
* so the deadline is enforced here rather than trusted to the provider.
|
|
305
|
+
*/
|
|
306
|
+
private withLoginExtensionTimeout<T>(
|
|
307
|
+
work: Promise<T>,
|
|
308
|
+
ms: number,
|
|
309
|
+
providerName: string,
|
|
310
|
+
): Promise<T> {
|
|
311
|
+
if (!(ms > 0)) return work;
|
|
312
|
+
let timer: NodeJS.Timeout;
|
|
313
|
+
return Promise.race([
|
|
314
|
+
work.finally(() => clearTimeout(timer)),
|
|
315
|
+
new Promise<never>((_, reject) => {
|
|
316
|
+
timer = setTimeout(
|
|
317
|
+
() =>
|
|
318
|
+
reject(
|
|
319
|
+
new Error(
|
|
320
|
+
`Login extension ${providerName} timed out after ${ms}ms`,
|
|
321
|
+
),
|
|
322
|
+
),
|
|
323
|
+
ms,
|
|
324
|
+
);
|
|
325
|
+
}),
|
|
326
|
+
]);
|
|
327
|
+
}
|
|
328
|
+
|
|
210
329
|
private async validateUserForPasswordLogin(
|
|
211
330
|
user: User,
|
|
212
331
|
password: string,
|
|
@@ -1237,10 +1356,14 @@ export class AuthenticationService {
|
|
|
1237
1356
|
if (!user) {
|
|
1238
1357
|
throw new UnauthorizedException(ERROR_MESSAGES.INVALID_CREDENTIALS);
|
|
1239
1358
|
}
|
|
1240
|
-
await this.validateUserForPasswordLogin(user, signInDto.password);
|
|
1359
|
+
await this. validateUserForPasswordLogin(user, signInDto.password);
|
|
1241
1360
|
await this.rehashPasswordIfRequired(user, signInDto.password);
|
|
1242
1361
|
await this.resetFailedAttempts(user);
|
|
1243
1362
|
|
|
1363
|
+
await this.runLoginExtensions(user, {
|
|
1364
|
+
channel: LoginExtensionChannel.PASSWORD,
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1244
1367
|
const tokens = await this.generateTokens(user);
|
|
1245
1368
|
|
|
1246
1369
|
await this.userActivityHistoryService.logEvent("login", user);
|
|
@@ -1550,6 +1673,9 @@ export class AuthenticationService {
|
|
|
1550
1673
|
if (otp !== dummyOtp) {
|
|
1551
1674
|
throw new UnauthorizedException(ERROR_MESSAGES.INVALID_OTP);
|
|
1552
1675
|
}
|
|
1676
|
+
await this.runLoginExtensions(user, {
|
|
1677
|
+
channel: LoginExtensionChannel.OTP,
|
|
1678
|
+
});
|
|
1553
1679
|
return this.buildLoginTokenResponse(user);
|
|
1554
1680
|
}
|
|
1555
1681
|
|
|
@@ -1561,8 +1687,14 @@ export class AuthenticationService {
|
|
|
1561
1687
|
}
|
|
1562
1688
|
|
|
1563
1689
|
await this.clearLoginOtp(user, type);
|
|
1564
|
-
|
|
1690
|
+
// Reset before the chain runs, matching signIn: failedLoginAttempts counts
|
|
1691
|
+
// attempts against the *credential*, and the OTP was correct. A denial from
|
|
1692
|
+
// an external system is not a wrong OTP and must not leave the counter up.
|
|
1565
1693
|
await this.resetFailedAttempts(user);
|
|
1694
|
+
await this.runLoginExtensions(user, {
|
|
1695
|
+
channel: LoginExtensionChannel.OTP,
|
|
1696
|
+
});
|
|
1697
|
+
await this.userActivityHistoryService.logEvent("login", user);
|
|
1566
1698
|
return this.buildLoginTokenResponse(user);
|
|
1567
1699
|
}
|
|
1568
1700
|
|
|
@@ -4,6 +4,24 @@ import { MqMessageRepository } from "src/repository/mq-message.repository";
|
|
|
4
4
|
import { IDashboardWidgetDataProvider, IDashboardWidgetDataProviderContext, IDashboardWidgetDataResponseEnvelope } from "src/interfaces";
|
|
5
5
|
import { applyMqDashboardFilters } from "src/services/dashboard-providers/mq-dashboard-provider-utils";
|
|
6
6
|
|
|
7
|
+
type RecentFailureRecord = {
|
|
8
|
+
id: any;
|
|
9
|
+
messageId: any;
|
|
10
|
+
queueName: any;
|
|
11
|
+
stage: any;
|
|
12
|
+
retryCount: any;
|
|
13
|
+
elapsedMillis: any;
|
|
14
|
+
startedAt: any;
|
|
15
|
+
finishedAt: any;
|
|
16
|
+
error: any;
|
|
17
|
+
createdAt: any;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type TableColumn = {
|
|
21
|
+
field: keyof RecentFailureRecord;
|
|
22
|
+
header: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
7
25
|
@DashboardWidgetDataProvider()
|
|
8
26
|
@Injectable()
|
|
9
27
|
export class MqDashboardRecentFailuresProvider implements IDashboardWidgetDataProvider {
|
|
@@ -22,7 +40,7 @@ export class MqDashboardRecentFailuresProvider implements IDashboardWidgetDataPr
|
|
|
22
40
|
async getData(
|
|
23
41
|
widgetDefinition: Record<string, any>,
|
|
24
42
|
ctxt: IDashboardWidgetDataProviderContext,
|
|
25
|
-
): Promise<IDashboardWidgetDataResponseEnvelope<
|
|
43
|
+
): Promise<IDashboardWidgetDataResponseEnvelope<{ columns: TableColumn[]; records: RecentFailureRecord[] }>> {
|
|
26
44
|
const limit = Math.min(Math.max(Number(ctxt?.providerContext?.limit ?? 25), 1), 200);
|
|
27
45
|
const errorMaxLength = Math.max(Number(ctxt?.providerContext?.errorMaxLength ?? 160), 0);
|
|
28
46
|
|
|
@@ -47,20 +65,20 @@ export class MqDashboardRecentFailuresProvider implements IDashboardWidgetDataPr
|
|
|
47
65
|
.take(limit)
|
|
48
66
|
.getRawMany<Record<string, any>>();
|
|
49
67
|
|
|
50
|
-
const columns = [
|
|
51
|
-
"id",
|
|
52
|
-
"messageId",
|
|
53
|
-
"queueName",
|
|
54
|
-
"stage",
|
|
55
|
-
"retryCount",
|
|
56
|
-
"elapsedMillis",
|
|
57
|
-
"startedAt",
|
|
58
|
-
"finishedAt",
|
|
59
|
-
"error",
|
|
60
|
-
"createdAt",
|
|
68
|
+
const columns: TableColumn[] = [
|
|
69
|
+
{ field: "id", header: "ID" },
|
|
70
|
+
{ field: "messageId", header: "Message ID" },
|
|
71
|
+
{ field: "queueName", header: "Queue Name" },
|
|
72
|
+
{ field: "stage", header: "Stage" },
|
|
73
|
+
{ field: "retryCount", header: "Retry Count" },
|
|
74
|
+
{ field: "elapsedMillis", header: "Elapsed Millis" },
|
|
75
|
+
{ field: "startedAt", header: "Started At" },
|
|
76
|
+
{ field: "finishedAt", header: "Finished At" },
|
|
77
|
+
{ field: "error", header: "Error" },
|
|
78
|
+
{ field: "createdAt", header: "Created At" },
|
|
61
79
|
];
|
|
62
80
|
|
|
63
|
-
const records = rows.map((row) => ({
|
|
81
|
+
const records: RecentFailureRecord[] = rows.map((row) => ({
|
|
64
82
|
id: row.id ?? null,
|
|
65
83
|
messageId: row.messageId ?? row.messageid ?? null,
|
|
66
84
|
queueName: row.queueName ?? row.queuename ?? null,
|
|
@@ -13,6 +13,7 @@ import { IS_SECURITY_RULE_CONFIG_PROVIDER } from 'src/decorators/security-rule-c
|
|
|
13
13
|
import { IS_SELECTION_PROVIDER } from 'src/decorators/selection-provider.decorator';
|
|
14
14
|
import { IS_DASHBOARD_WIDGET_DATA_PROVIDER } from 'src/decorators/dashboard-widget-data-provider.decorator';
|
|
15
15
|
import { IS_EXTENSION_USER_CREATION_PROVIDER } from 'src/decorators/extension-user-creation-provider.decorator';
|
|
16
|
+
import { IS_LOGIN_EXTENSION_PROVIDER } from 'src/decorators/login-extension-provider.decorator';
|
|
16
17
|
import { IS_SOLID_DATABASE_MODULE } from 'src/decorators/solid-database-module.decorator';
|
|
17
18
|
import { IS_WA_PROVIDER } from 'src/decorators/whatsapp-provider.decorator';
|
|
18
19
|
import { IS_WORKFLOW_FIELD_DATA_PROVIDER } from 'src/decorators/workflow-field-data-provider.decorator';
|
|
@@ -64,6 +65,12 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
|
|
|
64
65
|
this.solidRegistry.registerErrorCodeProvider(errorCodeProvider);
|
|
65
66
|
});
|
|
66
67
|
|
|
68
|
+
// Register all ILoginExtensionProvider implementations
|
|
69
|
+
const loginExtensionProviders = this.discoveryService.getProviders().filter((provider) => this.isLoginExtensionProvider(provider));
|
|
70
|
+
loginExtensionProviders.forEach((loginExtensionProvider) => {
|
|
71
|
+
this.solidRegistry.registerLoginExtensionProvider(loginExtensionProvider);
|
|
72
|
+
});
|
|
73
|
+
|
|
67
74
|
// Register all ISelectionProvider implementations
|
|
68
75
|
const selectionProviders = this.discoveryService.getProviders().filter((provider) => this.isSelectionProvider(provider));
|
|
69
76
|
selectionProviders.forEach((selectionProvider) => {
|
|
@@ -314,6 +321,12 @@ export class SolidIntrospectService implements OnApplicationBootstrap {
|
|
|
314
321
|
return !!this.reflector.get<boolean>(IS_EXTENSION_USER_CREATION_PROVIDER, instance.constructor);
|
|
315
322
|
}
|
|
316
323
|
|
|
324
|
+
private isLoginExtensionProvider(provider: InstanceWrapper): boolean {
|
|
325
|
+
const { instance } = provider;
|
|
326
|
+
if (!instance) return false;
|
|
327
|
+
return !!this.reflector.get<boolean>(IS_LOGIN_EXTENSION_PROVIDER, instance.constructor);
|
|
328
|
+
}
|
|
329
|
+
|
|
317
330
|
private isSettingsProvider(provider: InstanceWrapper) {
|
|
318
331
|
const { instance } = provider;
|
|
319
332
|
if (!instance) return false;
|