@aooth/auth-moost 0.1.34 → 0.1.36
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/index.d.mts +24 -9
- package/dist/index.mjs +31 -6
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -627,14 +627,19 @@ declare class WfTriggerProvider {
|
|
|
627
627
|
//#region src/rate-limit/mate.d.ts
|
|
628
628
|
/**
|
|
629
629
|
* Caller-identity strategy for a rate-limited route (RL.spec.md §5.3):
|
|
630
|
-
* - `'ip'` — client IP (the public-endpoint mode; honors `trustProxy`)
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
|
|
637
|
-
|
|
630
|
+
* - `'ip'` — client IP (the public-endpoint mode; honors `trustProxy`).
|
|
631
|
+
* Evaluated PRE-guard — floods rejected before credential work.
|
|
632
|
+
* - any other string — a NAMED SUBJECT, looked up in the per-event
|
|
633
|
+
* subjects slot (see `setRateLimitSubject`) and evaluated POST-guard so
|
|
634
|
+
* GUARD-priority writers have run. When the slot is empty, `'user'` and
|
|
635
|
+
* `'session'` (per login/device) derive from the auth context; anything
|
|
636
|
+
* unresolved falls back to the IP budget. `'auto'` is an alias of
|
|
637
|
+
* `'user'`. Apps supply their own kinds (`'tenant'`, `'apiKey'`, …) via
|
|
638
|
+
* `setRateLimitSubject`.
|
|
639
|
+
* - custom function — runs inside the event context PRE-guard; must be
|
|
640
|
+
* self-sufficient (it cannot read what GUARD-priority code sets).
|
|
641
|
+
*/
|
|
642
|
+
type RateLimitKeyStrategy = "ip" | "user" | "auto" | "session" | (string & {}) | (() => string | Promise<string>);
|
|
638
643
|
/** Trailing options object accepted by `@RateLimit(...rules, opts)`. */
|
|
639
644
|
interface RateLimitDecoratorOptions {
|
|
640
645
|
/** Overrides the interceptor-level default key strategy for this route. */
|
|
@@ -756,6 +761,16 @@ declare function RateLimit(...rulesAndOpts: [RateLimitRuleInput$1, ...Array<Rate
|
|
|
756
761
|
declare function RateLimited(opts?: RateLimitInterceptorOptions): ClassDecorator & MethodDecorator;
|
|
757
762
|
//#endregion
|
|
758
763
|
//#region src/rate-limit/composables.d.ts
|
|
764
|
+
/**
|
|
765
|
+
* Supply the rate-limit subject for a named key strategy — the seam for
|
|
766
|
+
* custom IAMs / tenant resolvers. Call from GUARD-priority (or earlier)
|
|
767
|
+
* code; the value is used VERBATIM as the counter subject (include your own
|
|
768
|
+
* prefix, e.g. `iam:<sub>`) and always wins over the built-in `user` /
|
|
769
|
+
* `session` derivations. Full contract: docs `/moost/rate-limit`.
|
|
770
|
+
*/
|
|
771
|
+
declare function setRateLimitSubject(kind: string, subject: string, ctx?: EventContext): void;
|
|
772
|
+
/** Read a named rate-limit subject set for this event (or `undefined`). */
|
|
773
|
+
declare function getRateLimitSubject(kind: string, ctx?: EventContext): string | undefined;
|
|
759
774
|
interface RateLimitBindings {
|
|
760
775
|
/**
|
|
761
776
|
* The decision the interceptor computed for this event, or `null` when the
|
|
@@ -4062,4 +4077,4 @@ interface AuditEmitter {
|
|
|
4062
4077
|
emit(event: AuditEvent): Promise<void> | void;
|
|
4063
4078
|
}
|
|
4064
4079
|
//#endregion
|
|
4065
|
-
export { ADD_MFA_WORKFLOW, AUTHZ_BINDING_COOKIE, AUTH_CODE_STORE_TOKEN, type AuditEmitter, type AuditEvent, type AuthBindings, type AuthContext, AuthController, type AuthDeliveryPayload, type AuthEmailEvent, type AuthEmailKind, type AuthEmailOutletDeps, AuthGuarded, type AuthLoginResponse, type AuthLogoutBody, type AuthOkResponse, type AuthOptions, type AuthRefreshBody, type AuthSmsEvent, type AuthSmsKind, type AuthWfCompletionState, type AuthWfConsentsState, type AuthWfCtx, type AuthWfMfaEnrollState, type AuthWfOAuthState, type AuthWfPasswordUiState, type AuthWfPincodeUiState, AuthWorkflow, type AuthWorkflowOpts, type AuthorizationServerMetadata, AuthorizeController, AuthorizeRuntime, type BuildAuthorizationServerMetadataOptions, type BuildMagicLinkUrl, type BuildProtectedResourceMetadataOptions, CHANGE_PASSWORD_WORKFLOW, CLIENT_REDIRECT_POLICY_TOKEN, type ConcurrencyLimitOptions, type ConnectedAccount, type ConsentDescriptor, type ConsentDescriptorLike, type ConsentEvent, ConsentStore, DEFAULT_AUTH_WORKFLOWS, DYNAMIC_CLIENT_STORE_TOKEN, DynamicClientRegistration, type DynamicClientRegistrationOptions, type EmailSender, type EnrichedSession, FEDERATED_IDENTITY_STORE_TOKEN, type IssueResult, type LoginRedirect, type MfaSummary, type MfaTransport, OAUTH_CSRF_COOKIE, OAuthController, OAuthRuntime, PENDING_AUTHORIZATION_STORE_TOKEN, type ProtectedResourceMetadata, Public, RESERVED_USER_KEYS, RateLimit, type RateLimitBindings, type RateLimitDecision, type RateLimitDecoratorOptions, type RateLimitInterceptorOptions, type RateLimitKeyStrategy, type RateLimitRule, type RateLimitRuleInput, type RateLimitStore, RateLimitStoreMemory, RateLimited, RateLimiter, type RateLimiterOptions, type ResolvedAuthCookieConfig, type ResolvedAuthOptions, type ResolvedAuthWorkflowOpts, type SessionEnricher, SessionEnricherProvider, type SessionInfo, SessionsController, type SmsSender, type SsoProvider, type TAuthMeta, type TRateLimitMeta, UserId, WfTrigger, type WfTriggerOpts, WfTriggerProvider, type WwwAuthenticateBearerChallengeOptions, authGuardInterceptor, authzBindingCookieAttrs, buildAuthorizationServerMetadata, buildInviteAlreadyAcceptedEnvelope, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, createAuthEmailOutlet, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, resolveOAuthRedirect, stripReservedUserKeys, useAuth, useRateLimit };
|
|
4080
|
+
export { ADD_MFA_WORKFLOW, AUTHZ_BINDING_COOKIE, AUTH_CODE_STORE_TOKEN, type AuditEmitter, type AuditEvent, type AuthBindings, type AuthContext, AuthController, type AuthDeliveryPayload, type AuthEmailEvent, type AuthEmailKind, type AuthEmailOutletDeps, AuthGuarded, type AuthLoginResponse, type AuthLogoutBody, type AuthOkResponse, type AuthOptions, type AuthRefreshBody, type AuthSmsEvent, type AuthSmsKind, type AuthWfCompletionState, type AuthWfConsentsState, type AuthWfCtx, type AuthWfMfaEnrollState, type AuthWfOAuthState, type AuthWfPasswordUiState, type AuthWfPincodeUiState, AuthWorkflow, type AuthWorkflowOpts, type AuthorizationServerMetadata, AuthorizeController, AuthorizeRuntime, type BuildAuthorizationServerMetadataOptions, type BuildMagicLinkUrl, type BuildProtectedResourceMetadataOptions, CHANGE_PASSWORD_WORKFLOW, CLIENT_REDIRECT_POLICY_TOKEN, type ConcurrencyLimitOptions, type ConnectedAccount, type ConsentDescriptor, type ConsentDescriptorLike, type ConsentEvent, ConsentStore, DEFAULT_AUTH_WORKFLOWS, DYNAMIC_CLIENT_STORE_TOKEN, DynamicClientRegistration, type DynamicClientRegistrationOptions, type EmailSender, type EnrichedSession, FEDERATED_IDENTITY_STORE_TOKEN, type IssueResult, type LoginRedirect, type MfaSummary, type MfaTransport, OAUTH_CSRF_COOKIE, OAuthController, OAuthRuntime, PENDING_AUTHORIZATION_STORE_TOKEN, type ProtectedResourceMetadata, Public, RESERVED_USER_KEYS, RateLimit, type RateLimitBindings, type RateLimitDecision, type RateLimitDecoratorOptions, type RateLimitInterceptorOptions, type RateLimitKeyStrategy, type RateLimitRule, type RateLimitRuleInput, type RateLimitStore, RateLimitStoreMemory, RateLimited, RateLimiter, type RateLimiterOptions, type ResolvedAuthCookieConfig, type ResolvedAuthOptions, type ResolvedAuthWorkflowOpts, type SessionEnricher, SessionEnricherProvider, type SessionInfo, SessionsController, type SmsSender, type SsoProvider, type TAuthMeta, type TRateLimitMeta, UserId, WfTrigger, type WfTriggerOpts, WfTriggerProvider, type WwwAuthenticateBearerChallengeOptions, authGuardInterceptor, authzBindingCookieAttrs, buildAuthorizationServerMetadata, buildInviteAlreadyAcceptedEnvelope, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, createAuthEmailOutlet, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, getRateLimitSubject, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, resolveOAuthRedirect, setRateLimitSubject, stripReservedUserKeys, useAuth, useRateLimit };
|
package/dist/index.mjs
CHANGED
|
@@ -6558,6 +6558,28 @@ SessionsController = __decorate([
|
|
|
6558
6558
|
*/
|
|
6559
6559
|
const rateLimitDecisionKey = key("aooth.rateLimit.decision");
|
|
6560
6560
|
/**
|
|
6561
|
+
* Internal: named rate-limit subjects for this event — subject kind
|
|
6562
|
+
* (`'user'`, `'tenant'`, …) → resolved caller identity, written via
|
|
6563
|
+
* {@link setRateLimitSubject} and read by the post-guard rate-limit phase.
|
|
6564
|
+
*/
|
|
6565
|
+
const rateLimitSubjectsKey = key("aooth.rateLimit.subjects");
|
|
6566
|
+
/**
|
|
6567
|
+
* Supply the rate-limit subject for a named key strategy — the seam for
|
|
6568
|
+
* custom IAMs / tenant resolvers. Call from GUARD-priority (or earlier)
|
|
6569
|
+
* code; the value is used VERBATIM as the counter subject (include your own
|
|
6570
|
+
* prefix, e.g. `iam:<sub>`) and always wins over the built-in `user` /
|
|
6571
|
+
* `session` derivations. Full contract: docs `/moost/rate-limit`.
|
|
6572
|
+
*/
|
|
6573
|
+
function setRateLimitSubject(kind, subject, ctx = current()) {
|
|
6574
|
+
const subjects = ctx.has(rateLimitSubjectsKey) ? ctx.get(rateLimitSubjectsKey) : {};
|
|
6575
|
+
subjects[kind] = subject;
|
|
6576
|
+
ctx.set(rateLimitSubjectsKey, subjects);
|
|
6577
|
+
}
|
|
6578
|
+
/** Read a named rate-limit subject set for this event (or `undefined`). */
|
|
6579
|
+
function getRateLimitSubject(kind, ctx = current()) {
|
|
6580
|
+
return ctx.has(rateLimitSubjectsKey) ? ctx.get(rateLimitSubjectsKey)[kind] : void 0;
|
|
6581
|
+
}
|
|
6582
|
+
/**
|
|
6561
6583
|
* Read the current event's rate-limit state. A plain function (not a cached
|
|
6562
6584
|
* wook) — it's a single slot read, and workflow child events inherit the
|
|
6563
6585
|
* HTTP parent's slot transparently.
|
|
@@ -6627,7 +6649,7 @@ function rateLimitInterceptors(opts) {
|
|
|
6627
6649
|
config = {
|
|
6628
6650
|
rules,
|
|
6629
6651
|
keyStrategy,
|
|
6630
|
-
|
|
6652
|
+
postGuardKeyed: typeof keyStrategy === "string" && keyStrategy !== "ip",
|
|
6631
6653
|
scope: metaOpts?.id ?? `${ctor.name}.${method}`,
|
|
6632
6654
|
...(metaOpts?.message ?? opts?.message) !== void 0 && { defaultMessage: metaOpts?.message ?? opts?.message },
|
|
6633
6655
|
policyHeader: rules.map((p) => `${p.limit};w=${Math.max(1, Math.round(p.window / 1e3))}`).join(", ")
|
|
@@ -6642,7 +6664,7 @@ function rateLimitInterceptors(opts) {
|
|
|
6642
6664
|
if (ctx.has(rateLimitDecisionKey)) return;
|
|
6643
6665
|
const config = resolveRouteConfig(useControllerContext(ctx));
|
|
6644
6666
|
if (!config) return;
|
|
6645
|
-
if (config.
|
|
6667
|
+
if (config.postGuardKeyed !== (phase === "post")) return;
|
|
6646
6668
|
const subject = await resolveSubject(config.keyStrategy, ipOpts, ctx);
|
|
6647
6669
|
const decision = await limiter.check(config.scope, subject, config.rules, { ...config.defaultMessage !== void 0 && { defaultMessage: config.defaultMessage } });
|
|
6648
6670
|
ctx.set(rateLimitDecisionKey, decision);
|
|
@@ -6662,9 +6684,12 @@ function rateLimitInterceptors(opts) {
|
|
|
6662
6684
|
}
|
|
6663
6685
|
async function resolveSubject(strategy, ipOpts, ctx) {
|
|
6664
6686
|
if (typeof strategy === "function") return await strategy();
|
|
6665
|
-
if (strategy
|
|
6666
|
-
const
|
|
6667
|
-
if (
|
|
6687
|
+
if (strategy !== "ip") {
|
|
6688
|
+
const subject = getRateLimitSubject(strategy, ctx);
|
|
6689
|
+
if (subject !== void 0) return subject;
|
|
6690
|
+
const auth = strategy === "user" || strategy === "session" ? useAuth(ctx).getAuthContext() : null;
|
|
6691
|
+
if (strategy === "user" && auth?.userId !== void 0) return `u:${auth.userId}`;
|
|
6692
|
+
if (strategy === "session" && auth?.sessionId !== void 0) return `s:${auth.sessionId}`;
|
|
6668
6693
|
}
|
|
6669
6694
|
return `ip:${useRequest(ctx).getIp(ipOpts)}`;
|
|
6670
6695
|
}
|
|
@@ -7367,4 +7392,4 @@ function createAuthEmailOutlet(deps) {
|
|
|
7367
7392
|
});
|
|
7368
7393
|
}
|
|
7369
7394
|
//#endregion
|
|
7370
|
-
export { ADD_MFA_WORKFLOW, AUTHZ_BINDING_COOKIE, AUTH_CODE_STORE_TOKEN, AuthController, AuthGuarded, AuthWorkflow, AuthorizeController, AuthorizeRuntime, CHANGE_PASSWORD_WORKFLOW, CLIENT_REDIRECT_POLICY_TOKEN, ConsentStore, DEFAULT_AUTH_WORKFLOWS, DYNAMIC_CLIENT_STORE_TOKEN, DynamicClientRegistration, FEDERATED_IDENTITY_STORE_TOKEN, OAUTH_CSRF_COOKIE, OAuthController, OAuthRuntime, PENDING_AUTHORIZATION_STORE_TOKEN, Public, RESERVED_USER_KEYS, RateLimit, RateLimitStoreMemory, RateLimited, RateLimiter, SessionEnricherProvider, SessionsController, UserId, WfTrigger, WfTriggerProvider, authGuardInterceptor, authzBindingCookieAttrs, buildAuthorizationServerMetadata, buildInviteAlreadyAcceptedEnvelope, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, createAuthEmailOutlet, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, resolveOAuthRedirect, stripReservedUserKeys, useAuth, useRateLimit };
|
|
7395
|
+
export { ADD_MFA_WORKFLOW, AUTHZ_BINDING_COOKIE, AUTH_CODE_STORE_TOKEN, AuthController, AuthGuarded, AuthWorkflow, AuthorizeController, AuthorizeRuntime, CHANGE_PASSWORD_WORKFLOW, CLIENT_REDIRECT_POLICY_TOKEN, ConsentStore, DEFAULT_AUTH_WORKFLOWS, DYNAMIC_CLIENT_STORE_TOKEN, DynamicClientRegistration, FEDERATED_IDENTITY_STORE_TOKEN, OAUTH_CSRF_COOKIE, OAuthController, OAuthRuntime, PENDING_AUTHORIZATION_STORE_TOKEN, Public, RESERVED_USER_KEYS, RateLimit, RateLimitStoreMemory, RateLimited, RateLimiter, SessionEnricherProvider, SessionsController, UserId, WfTrigger, WfTriggerProvider, authGuardInterceptor, authzBindingCookieAttrs, buildAuthorizationServerMetadata, buildInviteAlreadyAcceptedEnvelope, buildProtectedResourceMetadata, buildWwwAuthenticateBearerChallenge, canonicalizeIssuer, createAuthEmailOutlet, deriveWfStateSecret, generateMagicLinkToken, getAuthMate, getRateLimitMate, getRateLimitSubject, haversineKm, humanizeUserAgent, isSafeRelativeRedirect, oauthCsrfCookieAttrs, parseInviteRoles, rateLimitInterceptors, resolveOAuthRedirect, setRateLimitSubject, stripReservedUserKeys, useAuth, useRateLimit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aooth/auth-moost",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"description": "Moost auth integration for aoothjs — AuthGuard interceptor, useAuth composable, REST endpoints, workflows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aoothjs",
|
|
@@ -57,18 +57,18 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@atscript/moost-wf": "^0.1.
|
|
60
|
+
"@atscript/moost-wf": "^0.1.110",
|
|
61
61
|
"@wooksjs/http-body": "^0.7.19",
|
|
62
|
-
"@aooth/arbac-moost": "^0.1.
|
|
63
|
-
"@aooth/
|
|
64
|
-
"@aooth/
|
|
65
|
-
"@aooth/user": "0.1.
|
|
62
|
+
"@aooth/arbac-moost": "^0.1.36",
|
|
63
|
+
"@aooth/idp": "0.1.36",
|
|
64
|
+
"@aooth/auth": "0.1.36",
|
|
65
|
+
"@aooth/user": "0.1.36"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@atscript/core": "^0.1.78",
|
|
69
69
|
"@atscript/typescript": "^0.1.78",
|
|
70
|
-
"@atscript/ui": "^0.1.
|
|
71
|
-
"@atscript/ui-fns": "^0.1.
|
|
70
|
+
"@atscript/ui": "^0.1.110",
|
|
71
|
+
"@atscript/ui-fns": "^0.1.110",
|
|
72
72
|
"@moostjs/event-http": "^0.6.28",
|
|
73
73
|
"@moostjs/event-wf": "^0.6.28",
|
|
74
74
|
"moost": "^0.6.28",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"wooks": "^0.7.19"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@atscript/moost-wf": "^0.1.
|
|
79
|
+
"@atscript/moost-wf": "^0.1.110",
|
|
80
80
|
"@atscript/typescript": "^0.1.78",
|
|
81
81
|
"@moostjs/event-http": "^0.6.28",
|
|
82
82
|
"@moostjs/event-wf": "^0.6.28",
|