@guren/server 2.1.1 → 2.3.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/dist/{DocsViewerServiceProvider-D7RGJPGM.js → DocsViewerServiceProvider-RUYDFBMW.js} +2 -2
- package/dist/McpServiceProvider-FRJ5O7LT.js +8 -0
- package/dist/auth/AuthManager.d.ts +30 -0
- package/dist/auth/AuthenticatableModel.d.ts +25 -0
- package/dist/auth/RequestAuthContext.d.ts +24 -0
- package/dist/auth/SessionGuard.d.ts +31 -0
- package/dist/auth/api-token.d.ts +299 -0
- package/dist/auth/email-verification.d.ts +203 -0
- package/dist/auth/index.d.ts +18 -110
- package/dist/auth/index.js +4 -1
- package/dist/auth/oauth/index.d.ts +239 -0
- package/dist/auth/password/DefaultHasher.d.ts +13 -0
- package/dist/auth/password/NodeHasher.d.ts +22 -0
- package/dist/auth/password/PasswordHasher.d.ts +5 -0
- package/dist/auth/password/ScryptHasher.d.ts +26 -0
- package/dist/auth/password-reset.d.ts +91 -0
- package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
- package/dist/auth/providers/UserProvider.d.ts +9 -0
- package/dist/auth/types.d.ts +102 -0
- package/dist/auth/utils.d.ts +39 -0
- package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
- package/dist/authorization/Policy.d.ts +77 -0
- package/dist/authorization/index.d.ts +5 -129
- package/dist/authorization/index.js +3 -1
- package/dist/authorization/middleware.d.ts +49 -0
- package/dist/authorization/types.d.ts +108 -0
- package/dist/broadcasting/BroadcastManager.d.ts +205 -0
- package/dist/broadcasting/channels/Channel.d.ts +28 -0
- package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
- package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
- package/dist/broadcasting/channels/index.d.ts +3 -0
- package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
- package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
- package/dist/broadcasting/drivers/index.d.ts +2 -0
- package/dist/broadcasting/index.d.ts +6 -233
- package/dist/broadcasting/index.js +1 -1
- package/dist/broadcasting/typed.d.ts +23 -0
- package/dist/broadcasting/types.d.ts +155 -0
- package/dist/cache/CacheManager.d.ts +87 -0
- package/dist/cache/TaggedCache.d.ts +62 -0
- package/dist/cache/index.d.ts +6 -233
- package/dist/cache/index.js +1 -1
- package/dist/cache/stores/FileStore.d.ts +64 -0
- package/dist/cache/stores/MemoryStore.d.ts +52 -0
- package/dist/cache/stores/RedisStore.d.ts +53 -0
- package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
- package/dist/chunk-3KV5X2FL.js +31 -0
- package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
- package/dist/{chunk-DSDX3ASM.js → chunk-5WL2FTC4.js} +67 -85
- package/dist/{chunk-5SZTEZ22.js → chunk-6IGN233M.js} +15 -8
- package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
- package/dist/{chunk-WIXGT4TN.js → chunk-A5JJ7XTH.js} +8 -2
- package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
- package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
- package/dist/{chunk-BZMZEFRG.js → chunk-LHR6OHI7.js} +11 -0
- package/dist/{chunk-JBG4AR24.js → chunk-Q2P6YLRR.js} +8 -2
- package/dist/{chunk-J6ETA476.js → chunk-TVV5YNEC.js} +101 -9
- package/dist/console/Command.d.ts +179 -0
- package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
- package/dist/console/Input.d.ts +140 -0
- package/dist/console/Output.d.ts +161 -0
- package/dist/console/index.d.ts +5 -0
- package/dist/console/types.d.ts +106 -0
- package/dist/container/Container.d.ts +148 -0
- package/dist/container/ServiceProvider.d.ts +103 -0
- package/dist/container/bindings.d.ts +55 -0
- package/dist/container/defineModule.d.ts +88 -0
- package/dist/container/definePlugin.d.ts +62 -0
- package/dist/container/index.d.ts +8 -0
- package/dist/container/types.d.ts +73 -0
- package/dist/database/Factory.d.ts +82 -0
- package/dist/database/Seeder.d.ts +35 -0
- package/dist/database/SeederRunner.d.ts +41 -0
- package/dist/database/index.d.ts +4 -0
- package/dist/database/types.d.ts +49 -0
- package/dist/discovery/AutoDiscovery.d.ts +113 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
- package/dist/docs-viewer/endpoint.d.ts +29 -0
- package/dist/encryption/Encrypter.d.ts +96 -0
- package/dist/encryption/Hash.d.ts +69 -0
- package/dist/encryption/MessageSigner.d.ts +21 -0
- package/dist/encryption/Random.d.ts +119 -0
- package/dist/encryption/app-key.d.ts +12 -0
- package/dist/encryption/index.d.ts +10 -222
- package/dist/encryption/signed-url.d.ts +9 -0
- package/dist/encryption/types.d.ts +103 -0
- package/dist/errors/ExceptionHandler.d.ts +118 -0
- package/dist/errors/HttpException.d.ts +106 -0
- package/dist/errors/debug-page.d.ts +22 -0
- package/dist/errors/error-page.d.ts +1 -0
- package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
- package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
- package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
- package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
- package/dist/errors/exceptions/ValidationException.d.ts +60 -0
- package/dist/errors/exceptions/index.d.ts +5 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/types.d.ts +43 -0
- package/dist/events/Event.d.ts +33 -0
- package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
- package/dist/events/Listener.d.ts +79 -0
- package/dist/events/builtin.d.ts +73 -0
- package/dist/events/index.d.ts +6 -155
- package/dist/events/types.d.ts +48 -0
- package/dist/facades/index.d.ts +31 -0
- package/dist/health/HealthCheck.d.ts +34 -0
- package/dist/health/HealthManager.d.ts +53 -0
- package/dist/health/checks/CacheCheck.d.ts +35 -0
- package/dist/health/checks/CustomCheck.d.ts +23 -0
- package/dist/health/checks/DatabaseCheck.d.ts +33 -0
- package/dist/health/checks/MemoryCheck.d.ts +32 -0
- package/dist/health/checks/RedisCheck.d.ts +27 -0
- package/dist/health/checks/StorageCheck.d.ts +35 -0
- package/dist/health/checks/index.d.ts +12 -0
- package/dist/health/index.d.ts +5 -185
- package/dist/health/types.d.ts +52 -0
- package/dist/hot-reload/hot-disposables.d.ts +96 -0
- package/dist/hot-reload/testing.d.ts +14 -0
- package/dist/http/Application.d.ts +199 -0
- package/dist/http/FormRequest.d.ts +73 -0
- package/dist/http/dev-assets.d.ts +62 -0
- package/dist/http/dev-banner.d.ts +7 -0
- package/dist/http/inertia-assets.d.ts +31 -0
- package/dist/http/middleware/auth.d.ts +13 -0
- package/dist/http/middleware/capabilities.d.ts +22 -0
- package/dist/http/middleware/cors.d.ts +40 -0
- package/dist/http/middleware/csp.d.ts +59 -0
- package/dist/http/middleware/csrf.d.ts +121 -0
- package/dist/http/middleware/detect-locale.d.ts +65 -0
- package/dist/http/middleware/force-https.d.ts +34 -0
- package/dist/http/middleware/host-authorization.d.ts +24 -0
- package/dist/http/middleware/index.d.ts +19 -0
- package/dist/http/middleware/loopback-guard.d.ts +51 -0
- package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
- package/dist/http/middleware/redirect-safety.d.ts +29 -0
- package/dist/http/middleware/request-id.d.ts +19 -0
- package/dist/http/middleware/request-logging.d.ts +16 -0
- package/dist/http/middleware/response-headers.d.ts +18 -0
- package/dist/http/middleware/security-headers.d.ts +49 -0
- package/dist/http/middleware/session.d.ts +93 -0
- package/dist/http/middleware/validation.d.ts +94 -0
- package/dist/http/public-assets.d.ts +15 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/resources/CursorPaginator.d.ts +106 -0
- package/dist/http/resources/Paginator.d.ts +130 -0
- package/dist/http/resources/Resource.d.ts +67 -0
- package/dist/http/resources/ResourceCollection.d.ts +60 -0
- package/dist/http/resources/index.d.ts +6 -0
- package/dist/http/resources/types.d.ts +91 -0
- package/dist/http/validation/Validator.d.ts +128 -0
- package/dist/http/validation/index.d.ts +3 -0
- package/dist/http/validation/rules.d.ts +196 -0
- package/dist/http/validation/types.d.ts +96 -0
- package/dist/http/vite-dev-server.d.ts +27 -0
- package/dist/i18n/I18nManager.d.ts +114 -0
- package/dist/i18n/Translator.d.ts +80 -0
- package/dist/i18n/index.d.ts +6 -101
- package/dist/i18n/index.js +5 -3
- package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
- package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
- package/dist/i18n/pluralization.d.ts +19 -0
- package/dist/i18n/types.d.ts +106 -0
- package/dist/index.d.ts +69 -2605
- package/dist/index.js +405 -180
- package/dist/lambda/index.d.ts +17 -37
- package/dist/logging/LogManager.d.ts +83 -0
- package/dist/logging/Logger.d.ts +76 -0
- package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
- package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
- package/dist/logging/channels/FileChannel.d.ts +15 -0
- package/dist/logging/index.d.ts +8 -50
- package/dist/logging/types.d.ts +96 -0
- package/dist/mail/Mail.d.ts +138 -0
- package/dist/mail/MailManager.d.ts +79 -0
- package/dist/mail/address.d.ts +8 -0
- package/dist/mail/index.d.ts +7 -316
- package/dist/mail/transports/LogTransport.d.ts +19 -0
- package/dist/mail/transports/MemoryTransport.d.ts +84 -0
- package/dist/mail/transports/ResendTransport.d.ts +32 -0
- package/dist/mail/transports/SmtpTransport.d.ts +40 -0
- package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
- package/dist/mcp/McpServiceProvider.d.ts +17 -0
- package/dist/mcp/create-mcp-server.d.ts +152 -0
- package/dist/mcp/endpoint.d.ts +47 -0
- package/dist/mcp/index.d.ts +3 -185
- package/dist/mcp/index.js +3 -3
- package/dist/mvc/Controller.d.ts +326 -0
- package/dist/mvc/Router.d.ts +239 -0
- package/dist/mvc/ViewEngine.d.ts +11 -0
- package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
- package/dist/mvc/inertia/shared.d.ts +90 -0
- package/dist/mvc/mount-route.d.ts +10 -0
- package/dist/notifications/Notification.d.ts +99 -0
- package/dist/notifications/NotificationManager.d.ts +150 -0
- package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
- package/dist/notifications/channels/MailChannel.d.ts +45 -0
- package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
- package/dist/notifications/channels/SlackChannel.d.ts +73 -0
- package/dist/notifications/channels/index.d.ts +4 -0
- package/dist/notifications/index.d.ts +6 -322
- package/dist/notifications/notifiable-type.d.ts +10 -0
- package/dist/notifications/registry.d.ts +39 -0
- package/dist/notifications/types.d.ts +162 -0
- package/dist/providers/AuthServiceProvider.d.ts +7 -0
- package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
- package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
- package/dist/providers/CacheServiceProvider.d.ts +7 -0
- package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
- package/dist/providers/ErrorServiceProvider.d.ts +9 -0
- package/dist/providers/EventServiceProvider.d.ts +7 -0
- package/dist/providers/HealthServiceProvider.d.ts +7 -0
- package/dist/providers/I18nServiceProvider.d.ts +27 -0
- package/dist/providers/InertiaServiceProvider.d.ts +20 -0
- package/dist/providers/LogServiceProvider.d.ts +7 -0
- package/dist/providers/MailServiceProvider.d.ts +7 -0
- package/dist/providers/NotificationServiceProvider.d.ts +8 -0
- package/dist/providers/OAuthServiceProvider.d.ts +7 -0
- package/dist/providers/QueueServiceProvider.d.ts +7 -0
- package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
- package/dist/providers/StorageServiceProvider.d.ts +7 -0
- package/dist/providers/index.d.ts +17 -0
- package/dist/queue/FailedJobReporter.d.ts +40 -0
- package/dist/queue/Job.d.ts +140 -0
- package/dist/queue/QueueManager.d.ts +79 -0
- package/dist/queue/Worker.d.ts +99 -0
- package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
- package/dist/queue/drivers/RedisDriver.d.ts +96 -0
- package/dist/queue/drivers/SqsDriver.d.ts +108 -0
- package/dist/queue/drivers/SyncDriver.d.ts +28 -0
- package/dist/queue/index.d.ts +9 -453
- package/dist/queue/types.d.ts +171 -0
- package/dist/redis/RedisApiTokenStore.d.ts +78 -0
- package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
- package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
- package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
- package/dist/redis/RedisRateLimitStore.d.ts +77 -0
- package/dist/redis/RedisSessionStore.d.ts +61 -0
- package/dist/redis/client.d.ts +41 -0
- package/dist/redis/index.d.ts +14 -356
- package/dist/redis/index.js +45 -9
- package/dist/redis/redis-values.d.ts +17 -0
- package/dist/redis/scan-keys.d.ts +6 -0
- package/dist/runtime/index.d.ts +8 -95
- package/dist/runtime/index.js +101 -68
- package/dist/scheduling/CronParser.d.ts +37 -0
- package/dist/scheduling/Schedule.d.ts +229 -0
- package/dist/scheduling/ScheduledTask.d.ts +47 -0
- package/dist/scheduling/Scheduler.d.ts +99 -0
- package/dist/scheduling/index.d.ts +5 -41
- package/dist/scheduling/types.d.ts +97 -0
- package/dist/storage/StorageManager.d.ts +65 -0
- package/dist/storage/drivers/LocalDriver.d.ts +55 -0
- package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
- package/dist/storage/drivers/S3Driver.d.ts +72 -0
- package/dist/storage/index.d.ts +5 -197
- package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
- package/dist/support/contained-path.d.ts +26 -0
- package/dist/support/error-polyfill.d.ts +9 -0
- package/dist/support/expiry.d.ts +47 -0
- package/dist/support/expiry.js +12 -0
- package/dist/support/import-map.d.ts +13 -0
- package/dist/support/redirect-target.d.ts +11 -0
- package/dist/support/stack-frames.d.ts +56 -0
- package/dist/support/trim-slashes.d.ts +11 -0
- package/dist/vite/index.d.ts +2 -35
- package/dist/vite/index.js +0 -3
- package/dist/vite/plugin.d.ts +34 -0
- package/package.json +7 -3
- package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
- package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
- package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
- package/dist/I18nManager-BiSoczfV.d.ts +0 -275
- package/dist/LogManager-7mxnkaPM.d.ts +0 -256
- package/dist/McpServiceProvider-7BB5FPF3.js +0 -8
- package/dist/Scheduler-pZiT8i57.d.ts +0 -471
- package/dist/api-token-D24VPr_E.d.ts +0 -663
- package/dist/app-key-CsBfRC_Q.d.ts +0 -214
- package/dist/email-verification-Dx426KLn.d.ts +0 -336
- package/dist/index-9_Jzj5jo.d.ts +0 -7
- package/dist/validation-yAL53e1S.d.ts +0 -2610
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isExpired,
|
|
3
|
+
isOptionalExpiryPast
|
|
4
|
+
} from "./chunk-3KV5X2FL.js";
|
|
1
5
|
import {
|
|
2
6
|
AuthenticationException
|
|
3
7
|
} from "./chunk-DAQKYKLH.js";
|
|
@@ -158,6 +162,12 @@ var SessionImpl = class {
|
|
|
158
162
|
shouldPersist() {
|
|
159
163
|
return this.dirty || this.isNew && this.hasContent();
|
|
160
164
|
}
|
|
165
|
+
willPersist() {
|
|
166
|
+
if (this.destroyed) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
return !this.isNew || this.shouldPersist();
|
|
170
|
+
}
|
|
161
171
|
hasContent() {
|
|
162
172
|
return Object.keys(this.data).length > 0 || this.hasFlash();
|
|
163
173
|
}
|
|
@@ -1253,7 +1263,7 @@ async function verifyApiToken(plainTextToken, store, options = {}) {
|
|
|
1253
1263
|
const token = await store.findByHashedToken(hashedToken);
|
|
1254
1264
|
if (!token) return null;
|
|
1255
1265
|
if (token.id !== parsed.id) return null;
|
|
1256
|
-
if (
|
|
1266
|
+
if (isOptionalExpiryPast(token.expiresAt)) {
|
|
1257
1267
|
return null;
|
|
1258
1268
|
}
|
|
1259
1269
|
if (!secureCompare(token.hashedToken, hashedToken)) {
|
|
@@ -1369,6 +1379,52 @@ function hostMatchesAllowlist(target, allowedHosts) {
|
|
|
1369
1379
|
}
|
|
1370
1380
|
|
|
1371
1381
|
// src/auth/oauth/index.ts
|
|
1382
|
+
var OAUTH_SESSION_BINDING_KEY = "guren:oauth.bindings";
|
|
1383
|
+
var MAX_PENDING_SESSION_BINDINGS = 5;
|
|
1384
|
+
var warnedAboutUnboundState = false;
|
|
1385
|
+
function warnOnceAboutUnboundState() {
|
|
1386
|
+
if (warnedAboutUnboundState) return;
|
|
1387
|
+
warnedAboutUnboundState = true;
|
|
1388
|
+
console.warn(
|
|
1389
|
+
"[guren] OAuth authorize() was called without `session` or `bindTo`, so `state` is not tied to the browser that started the flow. An attacker can then complete their own authorization in a victim's browser and log the victim into the attacker's account. Pass the current session (`this.auth.session()`) as `session` to both authorize() and handleCallback(), or manage a per-browser value yourself via `bindTo`. See: https://guren.dev/docs/guides/oauth"
|
|
1390
|
+
);
|
|
1391
|
+
}
|
|
1392
|
+
var warnedAboutDroppedBinding = false;
|
|
1393
|
+
function warnOnceAboutDroppedBinding() {
|
|
1394
|
+
if (warnedAboutDroppedBinding) return;
|
|
1395
|
+
warnedAboutDroppedBinding = true;
|
|
1396
|
+
console.warn(
|
|
1397
|
+
"[guren] An OAuth state was created with `bindTo` but came back from the state store without its binding, so the callback could not be tied to the browser that started the flow. The configured OAuthStateStore is dropping `OAuthStatePayload.binding` \u2014 for DatabaseOAuthStateStore this usually means the `oauth_states` table has no `binding` column. See: https://guren.dev/docs/guides/oauth"
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
function readPendingBindings(session) {
|
|
1401
|
+
const stored = session.get(OAUTH_SESSION_BINDING_KEY);
|
|
1402
|
+
if (!Array.isArray(stored)) return [];
|
|
1403
|
+
const now = Date.now();
|
|
1404
|
+
return stored.filter(
|
|
1405
|
+
(entry) => typeof entry === "object" && entry !== null && typeof entry.stateHash === "string" && typeof entry.binding === "string" && typeof entry.expiresAt === "number" && entry.expiresAt > now
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
function issueSessionBinding(session) {
|
|
1409
|
+
if (!session) return void 0;
|
|
1410
|
+
return generateToken(DEFAULT_STATE_LENGTH);
|
|
1411
|
+
}
|
|
1412
|
+
function rememberSessionBinding(session, stateHash, binding, expiresAt) {
|
|
1413
|
+
const pending = readPendingBindings(session);
|
|
1414
|
+
pending.push({ stateHash, binding, expiresAt: expiresAt.getTime() });
|
|
1415
|
+
session.set(
|
|
1416
|
+
OAUTH_SESSION_BINDING_KEY,
|
|
1417
|
+
pending.slice(Math.max(0, pending.length - MAX_PENDING_SESSION_BINDINGS))
|
|
1418
|
+
);
|
|
1419
|
+
}
|
|
1420
|
+
function consumeSessionBinding(session, stateHash) {
|
|
1421
|
+
if (!session) return void 0;
|
|
1422
|
+
const pending = readPendingBindings(session);
|
|
1423
|
+
if (pending.length === 0) return void 0;
|
|
1424
|
+
const match = pending.find((entry) => entry.stateHash === stateHash);
|
|
1425
|
+
session.set(OAUTH_SESSION_BINDING_KEY, pending.filter((entry) => entry.stateHash !== stateHash));
|
|
1426
|
+
return match?.binding;
|
|
1427
|
+
}
|
|
1372
1428
|
var DEFAULT_STATE_EXPIRES_IN = 10 * 60 * 1e3;
|
|
1373
1429
|
var DEFAULT_STATE_LENGTH = 24;
|
|
1374
1430
|
var DEFAULT_STATE_HASH_ALGORITHM = "sha256";
|
|
@@ -1392,7 +1448,7 @@ var MemoryOAuthStateStore = class {
|
|
|
1392
1448
|
sweepExpired() {
|
|
1393
1449
|
const now = Date.now();
|
|
1394
1450
|
for (const [hash, payload] of this.states) {
|
|
1395
|
-
if (payload.expiresAt
|
|
1451
|
+
if (isExpired(payload.expiresAt, now)) {
|
|
1396
1452
|
this.states.delete(hash);
|
|
1397
1453
|
}
|
|
1398
1454
|
}
|
|
@@ -1400,7 +1456,7 @@ var MemoryOAuthStateStore = class {
|
|
|
1400
1456
|
async find(stateHash) {
|
|
1401
1457
|
const payload = this.states.get(stateHash);
|
|
1402
1458
|
if (!payload) return null;
|
|
1403
|
-
if (payload.expiresAt
|
|
1459
|
+
if (isExpired(payload.expiresAt)) {
|
|
1404
1460
|
this.states.delete(stateHash);
|
|
1405
1461
|
return null;
|
|
1406
1462
|
}
|
|
@@ -1413,7 +1469,7 @@ var MemoryOAuthStateStore = class {
|
|
|
1413
1469
|
const payload = this.states.get(stateHash);
|
|
1414
1470
|
if (!payload) return null;
|
|
1415
1471
|
this.states.delete(stateHash);
|
|
1416
|
-
if (payload.expiresAt
|
|
1472
|
+
if (isExpired(payload.expiresAt)) return null;
|
|
1417
1473
|
return payload;
|
|
1418
1474
|
}
|
|
1419
1475
|
clear() {
|
|
@@ -1448,13 +1504,27 @@ var OAuthManager = class {
|
|
|
1448
1504
|
}
|
|
1449
1505
|
async authorize(providerName, options = {}) {
|
|
1450
1506
|
const provider = this.getProvider(providerName);
|
|
1507
|
+
const sessionBinding = options.bindTo ? void 0 : issueSessionBinding(options.session);
|
|
1508
|
+
const bindTo = options.bindTo ?? sessionBinding;
|
|
1509
|
+
if (!bindTo) {
|
|
1510
|
+
warnOnceAboutUnboundState();
|
|
1511
|
+
}
|
|
1451
1512
|
const { state, expiresAt } = await createOAuthState(
|
|
1452
1513
|
providerName,
|
|
1453
1514
|
this.stateStore,
|
|
1454
1515
|
this.stateConfig,
|
|
1455
1516
|
options.redirectTo,
|
|
1456
|
-
options.state
|
|
1517
|
+
options.state,
|
|
1518
|
+
bindTo
|
|
1457
1519
|
);
|
|
1520
|
+
if (sessionBinding && options.session) {
|
|
1521
|
+
rememberSessionBinding(
|
|
1522
|
+
options.session,
|
|
1523
|
+
hashToken(state, this.stateConfig.hashAlgorithm),
|
|
1524
|
+
sessionBinding,
|
|
1525
|
+
expiresAt
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1458
1528
|
const scope = options.scope ?? provider.scopes;
|
|
1459
1529
|
const url = buildOAuthAuthorizeUrl(provider, state, { scope, extraParams: options.extraParams });
|
|
1460
1530
|
return { url, state, expiresAt };
|
|
@@ -1471,7 +1541,16 @@ var OAuthManager = class {
|
|
|
1471
1541
|
*/
|
|
1472
1542
|
async handleCallback(providerName, payload) {
|
|
1473
1543
|
const provider = this.getProvider(providerName);
|
|
1474
|
-
const verified = await verifyOAuthState(
|
|
1544
|
+
const verified = await verifyOAuthState(
|
|
1545
|
+
payload.state,
|
|
1546
|
+
providerName,
|
|
1547
|
+
this.stateStore,
|
|
1548
|
+
this.stateConfig,
|
|
1549
|
+
payload.bindTo ?? consumeSessionBinding(
|
|
1550
|
+
payload.session,
|
|
1551
|
+
hashToken(payload.state, this.stateConfig.hashAlgorithm)
|
|
1552
|
+
)
|
|
1553
|
+
);
|
|
1475
1554
|
if (!verified) {
|
|
1476
1555
|
throw new AuthenticationException("Invalid or expired OAuth state.");
|
|
1477
1556
|
}
|
|
@@ -1483,7 +1562,7 @@ var OAuthManager = class {
|
|
|
1483
1562
|
function createOAuthManager(options = {}) {
|
|
1484
1563
|
return new OAuthManager(options);
|
|
1485
1564
|
}
|
|
1486
|
-
async function createOAuthState(provider, store, config = {}, redirectTo, fixedState) {
|
|
1565
|
+
async function createOAuthState(provider, store, config = {}, redirectTo, fixedState, bindTo) {
|
|
1487
1566
|
const state = fixedState ?? generateToken(config.stateLength ?? DEFAULT_STATE_LENGTH);
|
|
1488
1567
|
const hashAlgorithm = config.hashAlgorithm ?? DEFAULT_STATE_HASH_ALGORITHM;
|
|
1489
1568
|
const expiresAt = new Date(Date.now() + (config.expiresIn ?? DEFAULT_STATE_EXPIRES_IN));
|
|
@@ -1491,18 +1570,30 @@ async function createOAuthState(provider, store, config = {}, redirectTo, fixedS
|
|
|
1491
1570
|
await store.store(stateHash, {
|
|
1492
1571
|
provider,
|
|
1493
1572
|
redirectTo: sanitizeOAuthRedirect(redirectTo, config.allowedRedirectHosts),
|
|
1494
|
-
expiresAt
|
|
1573
|
+
expiresAt,
|
|
1574
|
+
// Only the hash is stored, so a leaked state store does not hand out
|
|
1575
|
+
// session ids.
|
|
1576
|
+
binding: bindTo ? hashToken(bindTo, hashAlgorithm) : void 0
|
|
1495
1577
|
});
|
|
1496
1578
|
return { state, expiresAt };
|
|
1497
1579
|
}
|
|
1498
|
-
async function verifyOAuthState(state, provider, store, config = {}) {
|
|
1580
|
+
async function verifyOAuthState(state, provider, store, config = {}, bindTo) {
|
|
1499
1581
|
const hashAlgorithm = config.hashAlgorithm ?? DEFAULT_STATE_HASH_ALGORITHM;
|
|
1500
1582
|
const stateHash = hashToken(state, hashAlgorithm);
|
|
1501
1583
|
const payload = typeof store.consume === "function" ? await store.consume(stateHash) : await findAndDeleteState(store, stateHash);
|
|
1502
1584
|
if (!payload) return null;
|
|
1503
1585
|
if (payload.provider !== provider) return null;
|
|
1586
|
+
if (!bindingMatches(payload.binding, bindTo, hashAlgorithm)) return null;
|
|
1504
1587
|
return { ...payload, redirectTo: sanitizeOAuthRedirect(payload.redirectTo, config.allowedRedirectHosts) };
|
|
1505
1588
|
}
|
|
1589
|
+
function bindingMatches(stored, presented, hashAlgorithm) {
|
|
1590
|
+
if (!stored) {
|
|
1591
|
+
if (presented) warnOnceAboutDroppedBinding();
|
|
1592
|
+
return true;
|
|
1593
|
+
}
|
|
1594
|
+
if (!presented) return false;
|
|
1595
|
+
return secureCompare(stored, hashToken(presented, hashAlgorithm));
|
|
1596
|
+
}
|
|
1506
1597
|
async function findAndDeleteState(store, stateHash) {
|
|
1507
1598
|
const payload = await store.find(stateHash);
|
|
1508
1599
|
if (!payload) return null;
|
|
@@ -1717,6 +1808,7 @@ export {
|
|
|
1717
1808
|
createBearerTokenMiddleware,
|
|
1718
1809
|
getApiToken,
|
|
1719
1810
|
getApiTokenOrFail,
|
|
1811
|
+
OAUTH_SESSION_BINDING_KEY,
|
|
1720
1812
|
MemoryOAuthStateStore,
|
|
1721
1813
|
OAuthManager,
|
|
1722
1814
|
createOAuthManager,
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { Container } from '../container/index.js';
|
|
2
|
+
import type { OutputInterface, CommandInstance } from './types.js';
|
|
3
|
+
import { Input } from './Input.js';
|
|
4
|
+
import * as readline from 'readline';
|
|
5
|
+
/**
|
|
6
|
+
* Base command class for console commands.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* export class CreateUserCommand extends Command {
|
|
11
|
+
* static signature = 'users:create {email} {--admin} {--role=user}'
|
|
12
|
+
* static description = 'Create a new user'
|
|
13
|
+
*
|
|
14
|
+
* async handle(): Promise<void> {
|
|
15
|
+
* const email = this.argument('email')
|
|
16
|
+
* const isAdmin = this.hasOption('admin')
|
|
17
|
+
* const role = this.option('role', 'user')
|
|
18
|
+
*
|
|
19
|
+
* const password = await this.secret('Enter password:')
|
|
20
|
+
* const confirm = await this.confirm(`Create user ${email}?`)
|
|
21
|
+
*
|
|
22
|
+
* if (!confirm) {
|
|
23
|
+
* this.warn('Cancelled')
|
|
24
|
+
* return
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* this.info(`Creating user: ${email}`)
|
|
28
|
+
* this.success('User created!')
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare abstract class Command implements CommandInstance {
|
|
34
|
+
/**
|
|
35
|
+
* The command signature.
|
|
36
|
+
* Format: 'command:name {arg} {--option}'
|
|
37
|
+
* Tokens may carry a description: 'command:name {arg : What it is}'
|
|
38
|
+
* See `parseSignature` for the full grammar.
|
|
39
|
+
*/
|
|
40
|
+
static signature: string;
|
|
41
|
+
/**
|
|
42
|
+
* The command description.
|
|
43
|
+
*/
|
|
44
|
+
static description: string;
|
|
45
|
+
/**
|
|
46
|
+
* The command input.
|
|
47
|
+
*/
|
|
48
|
+
protected input: Input;
|
|
49
|
+
/**
|
|
50
|
+
* The command output.
|
|
51
|
+
*/
|
|
52
|
+
protected output: OutputInterface;
|
|
53
|
+
/**
|
|
54
|
+
* The service container.
|
|
55
|
+
*/
|
|
56
|
+
protected container?: Container;
|
|
57
|
+
constructor(container?: Container);
|
|
58
|
+
/**
|
|
59
|
+
* Set the input for this command.
|
|
60
|
+
*/
|
|
61
|
+
setInput(argv: string[]): void;
|
|
62
|
+
/**
|
|
63
|
+
* Set the output for this command.
|
|
64
|
+
*/
|
|
65
|
+
setOutput(output: OutputInterface): void;
|
|
66
|
+
/**
|
|
67
|
+
* Execute the command.
|
|
68
|
+
*/
|
|
69
|
+
run(): Promise<number>;
|
|
70
|
+
/**
|
|
71
|
+
* Handle the command.
|
|
72
|
+
* Must be implemented by subclasses.
|
|
73
|
+
*/
|
|
74
|
+
abstract handle(): Promise<number | void>;
|
|
75
|
+
/**
|
|
76
|
+
* Get an argument value.
|
|
77
|
+
*/
|
|
78
|
+
argument<T = string>(name: string): T;
|
|
79
|
+
/**
|
|
80
|
+
* Get all arguments.
|
|
81
|
+
*/
|
|
82
|
+
arguments(): Record<string, string | string[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Get an option value with optional default.
|
|
85
|
+
*/
|
|
86
|
+
option<T = string>(name: string, defaultValue?: T): T;
|
|
87
|
+
/**
|
|
88
|
+
* Get all options.
|
|
89
|
+
*/
|
|
90
|
+
options(): Record<string, string | boolean | string[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Check if an option was provided.
|
|
93
|
+
*/
|
|
94
|
+
hasOption(name: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Output an info message.
|
|
97
|
+
*/
|
|
98
|
+
info(message: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Output an error message.
|
|
101
|
+
*/
|
|
102
|
+
error(message: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Output a warning message.
|
|
105
|
+
*/
|
|
106
|
+
warn(message: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Output a success message.
|
|
109
|
+
*/
|
|
110
|
+
success(message: string): void;
|
|
111
|
+
/**
|
|
112
|
+
* Output a plain line.
|
|
113
|
+
*/
|
|
114
|
+
line(message: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Output new lines.
|
|
117
|
+
*/
|
|
118
|
+
newLine(count?: number): void;
|
|
119
|
+
/**
|
|
120
|
+
* Output a table.
|
|
121
|
+
*/
|
|
122
|
+
table(headers: string[], rows: string[][]): void;
|
|
123
|
+
/**
|
|
124
|
+
* Ask a question and get user input.
|
|
125
|
+
*/
|
|
126
|
+
ask(question: string, defaultValue?: string): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Ask for confirmation.
|
|
129
|
+
*/
|
|
130
|
+
confirm(question: string, defaultValue?: boolean): Promise<boolean>;
|
|
131
|
+
/**
|
|
132
|
+
* Present choices to the user.
|
|
133
|
+
*/
|
|
134
|
+
choice<T extends string>(question: string, choices: T[], defaultValue?: T): Promise<T>;
|
|
135
|
+
/**
|
|
136
|
+
* Ask for secret input (password).
|
|
137
|
+
*/
|
|
138
|
+
secret(question: string): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Create a readline interface.
|
|
141
|
+
*/
|
|
142
|
+
protected createReadline(): readline.Interface;
|
|
143
|
+
/**
|
|
144
|
+
* Process items with progress output.
|
|
145
|
+
*/
|
|
146
|
+
withProgress<T>(items: T[], callback: (item: T, index: number) => Promise<void>): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Kernel reference for calling other commands.
|
|
149
|
+
*/
|
|
150
|
+
protected kernel?: {
|
|
151
|
+
handle(argv: string[]): Promise<number>;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Set the kernel reference.
|
|
155
|
+
*/
|
|
156
|
+
setKernel(kernel: {
|
|
157
|
+
handle(argv: string[]): Promise<number>;
|
|
158
|
+
}): void;
|
|
159
|
+
/**
|
|
160
|
+
* Call another command.
|
|
161
|
+
*/
|
|
162
|
+
call(command: string, args?: string[]): Promise<number>;
|
|
163
|
+
/**
|
|
164
|
+
* Resolve a service from the container.
|
|
165
|
+
*/
|
|
166
|
+
protected resolve<T>(key: string): T;
|
|
167
|
+
/**
|
|
168
|
+
* Get the command signature.
|
|
169
|
+
*/
|
|
170
|
+
getSignature(): string;
|
|
171
|
+
/**
|
|
172
|
+
* Get the command description.
|
|
173
|
+
*/
|
|
174
|
+
getDescription(): string;
|
|
175
|
+
/**
|
|
176
|
+
* Get the command name.
|
|
177
|
+
*/
|
|
178
|
+
getName(): string;
|
|
179
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { Container } from '../container/index.js';
|
|
2
|
+
import type { CommandClass, ConsoleKernelOptions, OutputInterface } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Console kernel for managing and executing commands.
|
|
5
5
|
*
|
|
@@ -14,7 +14,7 @@ import { C as CommandClass, a as Container, O as OutputInterface, b as ConsoleKe
|
|
|
14
14
|
* const exitCode = await kernel.handle(['users:create', 'john@example.com', '--admin'])
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
declare class ConsoleKernel {
|
|
17
|
+
export declare class ConsoleKernel {
|
|
18
18
|
/**
|
|
19
19
|
* Registered commands.
|
|
20
20
|
*/
|
|
@@ -96,6 +96,4 @@ declare class ConsoleKernel {
|
|
|
96
96
|
/**
|
|
97
97
|
* Create a console kernel.
|
|
98
98
|
*/
|
|
99
|
-
declare function createConsoleKernel(options?: ConsoleKernelOptions): ConsoleKernel;
|
|
100
|
-
|
|
101
|
-
export { ConsoleKernel as C, createConsoleKernel as c };
|
|
99
|
+
export declare function createConsoleKernel(options?: ConsoleKernelOptions): ConsoleKernel;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { ParsedSignature, ArgumentDefinition, OptionDefinition, InputInterface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a command signature into argument and option definitions.
|
|
4
|
+
*
|
|
5
|
+
* Signature format:
|
|
6
|
+
* - `command:name` - Command name
|
|
7
|
+
* - `{argument}` - Required argument
|
|
8
|
+
* - `{argument?}` - Optional argument
|
|
9
|
+
* - `{argument=default}` - Argument with default
|
|
10
|
+
* - `{argument*}` - Array argument (must be last)
|
|
11
|
+
* - `{--option}` - Boolean option (flag)
|
|
12
|
+
* - `{--option=}` - Option that requires a value
|
|
13
|
+
* - `{--option=default}` - Option with default value
|
|
14
|
+
* - `{-o|--option}` - Option with shortcut
|
|
15
|
+
* - `{--option=*}` - Array option
|
|
16
|
+
* - `{argument : Description}` - Argument with a description
|
|
17
|
+
* - `{--option= : Description}` - Option with a description
|
|
18
|
+
*
|
|
19
|
+
* A description is separated from the token by a colon with whitespace on at
|
|
20
|
+
* least one side, so it may contain spaces and colons freely. Requiring that
|
|
21
|
+
* whitespace keeps colons inside default values (`{--url=https://example.com}`)
|
|
22
|
+
* out of descriptions.
|
|
23
|
+
*
|
|
24
|
+
* A colon with no whitespace at all (`{argument:Description}`) is accepted for
|
|
25
|
+
* a single-word description, but only on a token carrying no other marker:
|
|
26
|
+
* `{argument?}`, `{argument*}` and `{--option=default}` must use the spaced
|
|
27
|
+
* form, since their markers are stripped before that fallback runs.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* parseSignature('users:create {name} {--admin} {--role=user}')
|
|
32
|
+
* // => {
|
|
33
|
+
* // name: 'users:create',
|
|
34
|
+
* // arguments: [{ name: 'name', required: true, array: false }],
|
|
35
|
+
* // options: [
|
|
36
|
+
* // { name: 'admin', requiresValue: false },
|
|
37
|
+
* // { name: 'role', requiresValue: true, defaultValue: 'user' }
|
|
38
|
+
* // ]
|
|
39
|
+
* // }
|
|
40
|
+
*
|
|
41
|
+
* parseSignature('users:create {name : The full name} {--admin : Grant admin rights}')
|
|
42
|
+
* // => arguments[0].description === 'The full name'
|
|
43
|
+
* // options[0].description === 'Grant admin rights'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseSignature(signature: string): ParsedSignature;
|
|
47
|
+
/**
|
|
48
|
+
* The label an argument is displayed with in help output.
|
|
49
|
+
*/
|
|
50
|
+
export declare function argumentLabel(arg: ArgumentDefinition): string;
|
|
51
|
+
/**
|
|
52
|
+
* The label an option is displayed with in help output, carrying whether it
|
|
53
|
+
* takes a value and whether it may be repeated.
|
|
54
|
+
*/
|
|
55
|
+
export declare function optionLabel(opt: OptionDefinition): string;
|
|
56
|
+
/**
|
|
57
|
+
* Build a usage line from a parsed signature.
|
|
58
|
+
*/
|
|
59
|
+
export declare function formatUsage(parsed: ParsedSignature): string;
|
|
60
|
+
/**
|
|
61
|
+
* Console input handler.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const input = new Input('users:create {name} {--admin}', ['John', '--admin'])
|
|
66
|
+
* input.argument('name') // => 'John'
|
|
67
|
+
* input.option('admin') // => true
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare class Input implements InputInterface {
|
|
71
|
+
/**
|
|
72
|
+
* Parsed signature.
|
|
73
|
+
*/
|
|
74
|
+
protected parsed: ParsedSignature;
|
|
75
|
+
/**
|
|
76
|
+
* Parsed argument values.
|
|
77
|
+
*/
|
|
78
|
+
protected argumentValues: Record<string, string | string[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Parsed option values.
|
|
81
|
+
*/
|
|
82
|
+
protected optionValues: Record<string, string | boolean | string[]>;
|
|
83
|
+
constructor(signature: string, argv?: string[]);
|
|
84
|
+
/**
|
|
85
|
+
* Parse command line arguments.
|
|
86
|
+
*/
|
|
87
|
+
protected parseArgv(argv: string[]): void;
|
|
88
|
+
/**
|
|
89
|
+
* Parse a long option.
|
|
90
|
+
*/
|
|
91
|
+
protected parseLongOption(option: string, argv: string[], index: number): void;
|
|
92
|
+
/**
|
|
93
|
+
* Parse a short option.
|
|
94
|
+
*/
|
|
95
|
+
protected parseShortOption(option: string, argv: string[], index: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Map positional arguments to definitions.
|
|
98
|
+
*/
|
|
99
|
+
protected mapArguments(args: string[]): void;
|
|
100
|
+
/**
|
|
101
|
+
* Find an option definition by name.
|
|
102
|
+
*/
|
|
103
|
+
protected findOption(name: string): OptionDefinition | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Find an option definition by shortcut.
|
|
106
|
+
*/
|
|
107
|
+
protected findOptionByShortcut(shortcut: string): OptionDefinition | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Check if an option requires a value.
|
|
110
|
+
*/
|
|
111
|
+
protected optionRequiresValue(name: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Get an argument value.
|
|
114
|
+
*/
|
|
115
|
+
argument<T = string>(name: string): T;
|
|
116
|
+
/**
|
|
117
|
+
* Get all argument values.
|
|
118
|
+
*/
|
|
119
|
+
arguments(): Record<string, string | string[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Get an option value.
|
|
122
|
+
*/
|
|
123
|
+
option<T = string | boolean>(name: string): T | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Get all option values.
|
|
126
|
+
*/
|
|
127
|
+
options(): Record<string, string | boolean | string[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Check if an option was provided.
|
|
130
|
+
*/
|
|
131
|
+
hasOption(name: string): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Get the parsed signature.
|
|
134
|
+
*/
|
|
135
|
+
getSignature(): ParsedSignature;
|
|
136
|
+
/**
|
|
137
|
+
* Get the command name.
|
|
138
|
+
*/
|
|
139
|
+
getCommandName(): string;
|
|
140
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import type { OutputInterface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* ANSI color codes.
|
|
4
|
+
*/
|
|
5
|
+
declare const COLORS: {
|
|
6
|
+
readonly reset: "\u001B[0m";
|
|
7
|
+
readonly bold: "\u001B[1m";
|
|
8
|
+
readonly dim: "\u001B[2m";
|
|
9
|
+
readonly black: "\u001B[30m";
|
|
10
|
+
readonly red: "\u001B[31m";
|
|
11
|
+
readonly green: "\u001B[32m";
|
|
12
|
+
readonly yellow: "\u001B[33m";
|
|
13
|
+
readonly blue: "\u001B[34m";
|
|
14
|
+
readonly magenta: "\u001B[35m";
|
|
15
|
+
readonly cyan: "\u001B[36m";
|
|
16
|
+
readonly white: "\u001B[37m";
|
|
17
|
+
readonly bgRed: "\u001B[41m";
|
|
18
|
+
readonly bgGreen: "\u001B[42m";
|
|
19
|
+
readonly bgYellow: "\u001B[43m";
|
|
20
|
+
readonly bgBlue: "\u001B[44m";
|
|
21
|
+
readonly bgMagenta: "\u001B[45m";
|
|
22
|
+
readonly bgCyan: "\u001B[46m";
|
|
23
|
+
readonly bgWhite: "\u001B[47m";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Console output handler.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const output = new Output()
|
|
31
|
+
* output.info('Processing...')
|
|
32
|
+
* output.success('Done!')
|
|
33
|
+
* output.table(['Name', 'Age'], [['John', '30'], ['Jane', '25']])
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class Output implements OutputInterface {
|
|
37
|
+
/**
|
|
38
|
+
* Whether to use colors.
|
|
39
|
+
*/
|
|
40
|
+
protected useColors: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Output stream.
|
|
43
|
+
*/
|
|
44
|
+
protected stdout: NodeJS.WriteStream;
|
|
45
|
+
/**
|
|
46
|
+
* Error stream.
|
|
47
|
+
*/
|
|
48
|
+
protected stderr: NodeJS.WriteStream;
|
|
49
|
+
constructor(options?: {
|
|
50
|
+
colors?: boolean;
|
|
51
|
+
stdout?: NodeJS.WriteStream;
|
|
52
|
+
stderr?: NodeJS.WriteStream;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Apply color to text.
|
|
56
|
+
*/
|
|
57
|
+
protected color(text: string, ...codes: string[]): string;
|
|
58
|
+
/**
|
|
59
|
+
* Output an info message.
|
|
60
|
+
*/
|
|
61
|
+
info(message: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Output an error message.
|
|
64
|
+
*/
|
|
65
|
+
error(message: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Output a warning message.
|
|
68
|
+
*/
|
|
69
|
+
warn(message: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Output a success message.
|
|
72
|
+
*/
|
|
73
|
+
success(message: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* Output a plain line.
|
|
76
|
+
*/
|
|
77
|
+
line(message: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Output new lines.
|
|
80
|
+
*/
|
|
81
|
+
newLine(count?: number): void;
|
|
82
|
+
/**
|
|
83
|
+
* Output a table.
|
|
84
|
+
*/
|
|
85
|
+
table(headers: string[], rows: string[][]): void;
|
|
86
|
+
/**
|
|
87
|
+
* Write raw text without newline.
|
|
88
|
+
*/
|
|
89
|
+
write(message: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Write a line to stdout.
|
|
92
|
+
*/
|
|
93
|
+
protected writeLine(message: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Write a line to stderr.
|
|
96
|
+
*/
|
|
97
|
+
protected writeErrorLine(message: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Output a comment.
|
|
100
|
+
*/
|
|
101
|
+
comment(message: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Output a question.
|
|
104
|
+
*/
|
|
105
|
+
question(message: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Output a bulleted list.
|
|
108
|
+
*/
|
|
109
|
+
listing(items: string[]): void;
|
|
110
|
+
/**
|
|
111
|
+
* Output text with specific color.
|
|
112
|
+
*/
|
|
113
|
+
colored(message: string, color: keyof typeof COLORS): void;
|
|
114
|
+
/**
|
|
115
|
+
* Create a progress bar string.
|
|
116
|
+
*/
|
|
117
|
+
progressBar(current: number, total: number, width?: number): string;
|
|
118
|
+
/**
|
|
119
|
+
* Clear the current line.
|
|
120
|
+
*/
|
|
121
|
+
clearLine(): void;
|
|
122
|
+
/**
|
|
123
|
+
* Check if colors are enabled.
|
|
124
|
+
*/
|
|
125
|
+
isColored(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Enable or disable colors.
|
|
128
|
+
*/
|
|
129
|
+
setColors(enabled: boolean): void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Output that collects messages instead of printing.
|
|
133
|
+
* Useful for testing.
|
|
134
|
+
*/
|
|
135
|
+
export declare class BufferedOutput extends Output {
|
|
136
|
+
/**
|
|
137
|
+
* Collected messages.
|
|
138
|
+
*/
|
|
139
|
+
protected buffer: string[];
|
|
140
|
+
constructor();
|
|
141
|
+
protected writeLine(message: string): void;
|
|
142
|
+
protected writeErrorLine(message: string): void;
|
|
143
|
+
write(message: string): void;
|
|
144
|
+
/**
|
|
145
|
+
* Get all output as array.
|
|
146
|
+
*/
|
|
147
|
+
getLines(): string[];
|
|
148
|
+
/**
|
|
149
|
+
* Get all output as string.
|
|
150
|
+
*/
|
|
151
|
+
getOutput(): string;
|
|
152
|
+
/**
|
|
153
|
+
* Clear the buffer.
|
|
154
|
+
*/
|
|
155
|
+
clear(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Check if buffer contains a string.
|
|
158
|
+
*/
|
|
159
|
+
contains(text: string): boolean;
|
|
160
|
+
}
|
|
161
|
+
export {};
|