@poly-x/core 0.1.0-alpha.5 → 0.1.0-alpha.7
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.cjs +51 -3
- package/dist/index.d.cts +40 -1
- package/dist/index.d.mts +40 -1
- package/dist/index.mjs +51 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -715,7 +715,14 @@ const ENDPOINTS = {
|
|
|
715
715
|
* password, poly-auth answered `403 {userPasswordSet, userId}`, and this sets
|
|
716
716
|
* the real one. Only succeeds while the account is flagged `mustChangePassword`.
|
|
717
717
|
*/
|
|
718
|
-
setPassword: "/v1/auth/set-password"
|
|
718
|
+
setPassword: "/v1/auth/set-password",
|
|
719
|
+
/**
|
|
720
|
+
* Server-mediated self-service reset (poly-x v5 / F040). `forgotPassword` starts it
|
|
721
|
+
* — always a uniform 202, the token is emailed to the mailbox, never returned.
|
|
722
|
+
* `resetPassword` redeems that opaque token single-use and sets the new password.
|
|
723
|
+
*/
|
|
724
|
+
forgotPassword: "/v1/idp/forgot-password",
|
|
725
|
+
resetPassword: "/v1/idp/reset-password"
|
|
719
726
|
};
|
|
720
727
|
//#endregion
|
|
721
728
|
//#region src/auth/outcomes.ts
|
|
@@ -769,11 +776,17 @@ function parsePasswordOutcome(status, body) {
|
|
|
769
776
|
};
|
|
770
777
|
if (status === 403 && b.userPasswordSet === true && typeof b.userId === "string") return {
|
|
771
778
|
type: "password_change_required",
|
|
772
|
-
userId: b.userId
|
|
779
|
+
userId: b.userId,
|
|
780
|
+
ticket: typeof b.ticket === "string" ? b.ticket : void 0
|
|
773
781
|
};
|
|
774
782
|
if (status === 403) return { type: "no_access" };
|
|
775
783
|
return { type: "invalid_credentials" };
|
|
776
784
|
}
|
|
785
|
+
function parseResetOutcome(status, body) {
|
|
786
|
+
if (status === 200) return "ok";
|
|
787
|
+
if (asRecord$1(body).status === "weak_password") return "weak_password";
|
|
788
|
+
return "invalid_or_expired";
|
|
789
|
+
}
|
|
777
790
|
//#endregion
|
|
778
791
|
//#region src/auth/normalize.ts
|
|
779
792
|
const FALLBACK_TTL_MS = 5 * 6e4;
|
|
@@ -927,11 +940,45 @@ var AuthClient = class {
|
|
|
927
940
|
body: {
|
|
928
941
|
userId: params.userId,
|
|
929
942
|
newPassword: params.newPassword,
|
|
930
|
-
confirmPassword: params.confirmPassword
|
|
943
|
+
confirmPassword: params.confirmPassword,
|
|
944
|
+
...params.ticket ? { ticket: params.ticket } : {}
|
|
931
945
|
}
|
|
932
946
|
});
|
|
933
947
|
if (response.status !== 200) throw this.toError(response);
|
|
934
948
|
}
|
|
949
|
+
/**
|
|
950
|
+
* Start a server-mediated self-service reset (F040). POSTs the email + this app's
|
|
951
|
+
* publishable key; the backend resolves the account, mints a single-use token, and
|
|
952
|
+
* emails the link ITSELF — nothing comes back but a uniform 202. Resolves on success;
|
|
953
|
+
* a 4xx (e.g. a misconfigured key) surfaces as a typed error for the developer.
|
|
954
|
+
*/
|
|
955
|
+
async requestPasswordReset(params) {
|
|
956
|
+
const response = await this.transport.request({
|
|
957
|
+
method: "POST",
|
|
958
|
+
url: this.config.baseUrl + ENDPOINTS.forgotPassword,
|
|
959
|
+
body: {
|
|
960
|
+
email: params.email,
|
|
961
|
+
client_id: this.config.key.raw
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
if (response.status >= 400) throw this.toError(response);
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Redeem a reset token (the opaque value from the emailed link) single-use and set
|
|
968
|
+
* the new password. Returns a typed outcome the UI branches on; only a 5xx throws.
|
|
969
|
+
*/
|
|
970
|
+
async resetPassword(params) {
|
|
971
|
+
const response = await this.transport.request({
|
|
972
|
+
method: "POST",
|
|
973
|
+
url: this.config.baseUrl + ENDPOINTS.resetPassword,
|
|
974
|
+
body: {
|
|
975
|
+
token: params.token,
|
|
976
|
+
newPassword: params.newPassword
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
if (response.status >= 500) throw this.toError(response);
|
|
980
|
+
return parseResetOutcome(response.status, response.body);
|
|
981
|
+
}
|
|
935
982
|
async exchangeCode(params) {
|
|
936
983
|
const response = await this.transport.request({
|
|
937
984
|
method: "POST",
|
|
@@ -1030,6 +1077,7 @@ exports.normalizeRefresh = normalizeRefresh;
|
|
|
1030
1077
|
exports.parseAuthorizeOutcome = parseAuthorizeOutcome;
|
|
1031
1078
|
exports.parsePasswordOutcome = parsePasswordOutcome;
|
|
1032
1079
|
exports.parsePolyXKey = parsePolyXKey;
|
|
1080
|
+
exports.parseResetOutcome = parseResetOutcome;
|
|
1033
1081
|
exports.randomState = randomState;
|
|
1034
1082
|
exports.redactSensitive = redactSensitive;
|
|
1035
1083
|
exports.reduceSessionState = reduce;
|
package/dist/index.d.cts
CHANGED
|
@@ -398,6 +398,13 @@ declare const ENDPOINTS: {
|
|
|
398
398
|
* the real one. Only succeeds while the account is flagged `mustChangePassword`.
|
|
399
399
|
*/
|
|
400
400
|
readonly setPassword: "/v1/auth/set-password";
|
|
401
|
+
/**
|
|
402
|
+
* Server-mediated self-service reset (poly-x v5 / F040). `forgotPassword` starts it
|
|
403
|
+
* — always a uniform 202, the token is emailed to the mailbox, never returned.
|
|
404
|
+
* `resetPassword` redeems that opaque token single-use and sets the new password.
|
|
405
|
+
*/
|
|
406
|
+
readonly forgotPassword: "/v1/idp/forgot-password";
|
|
407
|
+
readonly resetPassword: "/v1/idp/reset-password";
|
|
401
408
|
};
|
|
402
409
|
//#endregion
|
|
403
410
|
//#region src/auth/outcomes.d.ts
|
|
@@ -447,10 +454,19 @@ type PasswordAuthOutcome = {
|
|
|
447
454
|
} | {
|
|
448
455
|
type: "password_change_required";
|
|
449
456
|
userId: string;
|
|
457
|
+
ticket?: string;
|
|
450
458
|
} | {
|
|
451
459
|
type: "no_access";
|
|
452
460
|
};
|
|
453
461
|
declare function parsePasswordOutcome(status: number, body: unknown): PasswordAuthOutcome;
|
|
462
|
+
/**
|
|
463
|
+
* The outcome of redeeming a reset token (`POST /idp/reset-password`, F040):
|
|
464
|
+
* `ok` on success, `weak_password` when it fails the platform floor, and a
|
|
465
|
+
* uniform `invalid_or_expired` for an unknown/used/expired token (the backend
|
|
466
|
+
* does not distinguish unknown from expired to the caller).
|
|
467
|
+
*/
|
|
468
|
+
type PasswordResetOutcome = "ok" | "weak_password" | "invalid_or_expired";
|
|
469
|
+
declare function parseResetOutcome(status: number, body: unknown): PasswordResetOutcome;
|
|
454
470
|
//#endregion
|
|
455
471
|
//#region src/auth/normalize.d.ts
|
|
456
472
|
declare function decodeJwtExp(token: string): number | null;
|
|
@@ -506,6 +522,12 @@ interface SetPasswordParams {
|
|
|
506
522
|
userId: string;
|
|
507
523
|
newPassword: string;
|
|
508
524
|
confirmPassword: string;
|
|
525
|
+
/**
|
|
526
|
+
* Single-use proof-of-possession ticket from the `password_change_required`
|
|
527
|
+
* outcome. When present the platform trusts the ticket over `userId`; when the
|
|
528
|
+
* backend enforces tickets, it's required. Omit against older backends.
|
|
529
|
+
*/
|
|
530
|
+
ticket?: string;
|
|
509
531
|
}
|
|
510
532
|
interface AuthorizeWithPasswordParams {
|
|
511
533
|
email: string;
|
|
@@ -550,6 +572,23 @@ declare class AuthClient {
|
|
|
550
572
|
* the proof the caller knows the temporary password.
|
|
551
573
|
*/
|
|
552
574
|
setPassword(params: SetPasswordParams): Promise<void>;
|
|
575
|
+
/**
|
|
576
|
+
* Start a server-mediated self-service reset (F040). POSTs the email + this app's
|
|
577
|
+
* publishable key; the backend resolves the account, mints a single-use token, and
|
|
578
|
+
* emails the link ITSELF — nothing comes back but a uniform 202. Resolves on success;
|
|
579
|
+
* a 4xx (e.g. a misconfigured key) surfaces as a typed error for the developer.
|
|
580
|
+
*/
|
|
581
|
+
requestPasswordReset(params: {
|
|
582
|
+
email: string;
|
|
583
|
+
}): Promise<void>;
|
|
584
|
+
/**
|
|
585
|
+
* Redeem a reset token (the opaque value from the emailed link) single-use and set
|
|
586
|
+
* the new password. Returns a typed outcome the UI branches on; only a 5xx throws.
|
|
587
|
+
*/
|
|
588
|
+
resetPassword(params: {
|
|
589
|
+
token: string;
|
|
590
|
+
newPassword: string;
|
|
591
|
+
}): Promise<PasswordResetOutcome>;
|
|
553
592
|
exchangeCode(params: ExchangeCodeParams): Promise<StoredSession>;
|
|
554
593
|
/** The `RefreshTokens` function the SessionEngine (F003) injects. */
|
|
555
594
|
createRefresher(): RefreshTokens;
|
|
@@ -568,4 +607,4 @@ declare class AuthClient {
|
|
|
568
607
|
declare const PACKAGE_NAME = "@poly-x/core";
|
|
569
608
|
declare const version = "0.0.0";
|
|
570
609
|
//#endregion
|
|
571
|
-
export { AuthClient, type AuthClientOptions, type AuthorizeOutcome, type AuthorizeWithPasswordParams, type BuildAuthorizeUrlParams, type Clock, DEFAULT_RETRY_POLICY, DEFAULT_TIMEOUT_MS, ENDPOINTS, type ExchangeCodeParams, FetchTransport, type FieldError, ForbiddenError, type HttpMethod, INITIAL_STATE as INITIAL_SESSION_STATE, InMemoryLock, InMemoryPkceStore, InMemorySessionChannel, InMemorySessionStore, type KeyEnv, type KeyKind, type Lock, type MockRoute, MockTransport, PACKAGE_NAME, type ParsedKey, type PasswordAuthOutcome, type PkceEntry, type PkcePair, type PkceStore, type PlatformResponseLike, PolyXConfigError, PolyXError, type PolyXErrorOptions, RateLimitedError, type RefreshTokens, type ResolveConfigInput, type ResolvedConfig, type RetryPolicy, type RuntimeContext, type Session, type SessionChannel, type SessionChannelEvent, type SessionClaims, SessionEngine, type SessionEngineOptions, type SessionEvent, SessionExpiredError, SessionRevokedError, type SessionState, type SessionStore, type SetPasswordParams, type SignedOutReason, type StoredSession, SystemClock, type TenantOption, type TimerHandle, type TokenSet, type Transport, type TransportRequest, type TransportResponse, UnauthenticatedError, UpstreamError, ValidationError, computeChallenge, createSessionEngine, decodeJwtExp, generatePkce, isTransientStatus, mapPlatformError, normalizeExchange, normalizeRefresh, parseAuthorizeOutcome, parsePasswordOutcome, parsePolyXKey, randomState, redactSensitive, reduce as reduceSessionState, resolveConfig, version };
|
|
610
|
+
export { AuthClient, type AuthClientOptions, type AuthorizeOutcome, type AuthorizeWithPasswordParams, type BuildAuthorizeUrlParams, type Clock, DEFAULT_RETRY_POLICY, DEFAULT_TIMEOUT_MS, ENDPOINTS, type ExchangeCodeParams, FetchTransport, type FieldError, ForbiddenError, type HttpMethod, INITIAL_STATE as INITIAL_SESSION_STATE, InMemoryLock, InMemoryPkceStore, InMemorySessionChannel, InMemorySessionStore, type KeyEnv, type KeyKind, type Lock, type MockRoute, MockTransport, PACKAGE_NAME, type ParsedKey, type PasswordAuthOutcome, type PasswordResetOutcome, type PkceEntry, type PkcePair, type PkceStore, type PlatformResponseLike, PolyXConfigError, PolyXError, type PolyXErrorOptions, RateLimitedError, type RefreshTokens, type ResolveConfigInput, type ResolvedConfig, type RetryPolicy, type RuntimeContext, type Session, type SessionChannel, type SessionChannelEvent, type SessionClaims, SessionEngine, type SessionEngineOptions, type SessionEvent, SessionExpiredError, SessionRevokedError, type SessionState, type SessionStore, type SetPasswordParams, type SignedOutReason, type StoredSession, SystemClock, type TenantOption, type TimerHandle, type TokenSet, type Transport, type TransportRequest, type TransportResponse, UnauthenticatedError, UpstreamError, ValidationError, computeChallenge, createSessionEngine, decodeJwtExp, generatePkce, isTransientStatus, mapPlatformError, normalizeExchange, normalizeRefresh, parseAuthorizeOutcome, parsePasswordOutcome, parsePolyXKey, parseResetOutcome, randomState, redactSensitive, reduce as reduceSessionState, resolveConfig, version };
|
package/dist/index.d.mts
CHANGED
|
@@ -398,6 +398,13 @@ declare const ENDPOINTS: {
|
|
|
398
398
|
* the real one. Only succeeds while the account is flagged `mustChangePassword`.
|
|
399
399
|
*/
|
|
400
400
|
readonly setPassword: "/v1/auth/set-password";
|
|
401
|
+
/**
|
|
402
|
+
* Server-mediated self-service reset (poly-x v5 / F040). `forgotPassword` starts it
|
|
403
|
+
* — always a uniform 202, the token is emailed to the mailbox, never returned.
|
|
404
|
+
* `resetPassword` redeems that opaque token single-use and sets the new password.
|
|
405
|
+
*/
|
|
406
|
+
readonly forgotPassword: "/v1/idp/forgot-password";
|
|
407
|
+
readonly resetPassword: "/v1/idp/reset-password";
|
|
401
408
|
};
|
|
402
409
|
//#endregion
|
|
403
410
|
//#region src/auth/outcomes.d.ts
|
|
@@ -447,10 +454,19 @@ type PasswordAuthOutcome = {
|
|
|
447
454
|
} | {
|
|
448
455
|
type: "password_change_required";
|
|
449
456
|
userId: string;
|
|
457
|
+
ticket?: string;
|
|
450
458
|
} | {
|
|
451
459
|
type: "no_access";
|
|
452
460
|
};
|
|
453
461
|
declare function parsePasswordOutcome(status: number, body: unknown): PasswordAuthOutcome;
|
|
462
|
+
/**
|
|
463
|
+
* The outcome of redeeming a reset token (`POST /idp/reset-password`, F040):
|
|
464
|
+
* `ok` on success, `weak_password` when it fails the platform floor, and a
|
|
465
|
+
* uniform `invalid_or_expired` for an unknown/used/expired token (the backend
|
|
466
|
+
* does not distinguish unknown from expired to the caller).
|
|
467
|
+
*/
|
|
468
|
+
type PasswordResetOutcome = "ok" | "weak_password" | "invalid_or_expired";
|
|
469
|
+
declare function parseResetOutcome(status: number, body: unknown): PasswordResetOutcome;
|
|
454
470
|
//#endregion
|
|
455
471
|
//#region src/auth/normalize.d.ts
|
|
456
472
|
declare function decodeJwtExp(token: string): number | null;
|
|
@@ -506,6 +522,12 @@ interface SetPasswordParams {
|
|
|
506
522
|
userId: string;
|
|
507
523
|
newPassword: string;
|
|
508
524
|
confirmPassword: string;
|
|
525
|
+
/**
|
|
526
|
+
* Single-use proof-of-possession ticket from the `password_change_required`
|
|
527
|
+
* outcome. When present the platform trusts the ticket over `userId`; when the
|
|
528
|
+
* backend enforces tickets, it's required. Omit against older backends.
|
|
529
|
+
*/
|
|
530
|
+
ticket?: string;
|
|
509
531
|
}
|
|
510
532
|
interface AuthorizeWithPasswordParams {
|
|
511
533
|
email: string;
|
|
@@ -550,6 +572,23 @@ declare class AuthClient {
|
|
|
550
572
|
* the proof the caller knows the temporary password.
|
|
551
573
|
*/
|
|
552
574
|
setPassword(params: SetPasswordParams): Promise<void>;
|
|
575
|
+
/**
|
|
576
|
+
* Start a server-mediated self-service reset (F040). POSTs the email + this app's
|
|
577
|
+
* publishable key; the backend resolves the account, mints a single-use token, and
|
|
578
|
+
* emails the link ITSELF — nothing comes back but a uniform 202. Resolves on success;
|
|
579
|
+
* a 4xx (e.g. a misconfigured key) surfaces as a typed error for the developer.
|
|
580
|
+
*/
|
|
581
|
+
requestPasswordReset(params: {
|
|
582
|
+
email: string;
|
|
583
|
+
}): Promise<void>;
|
|
584
|
+
/**
|
|
585
|
+
* Redeem a reset token (the opaque value from the emailed link) single-use and set
|
|
586
|
+
* the new password. Returns a typed outcome the UI branches on; only a 5xx throws.
|
|
587
|
+
*/
|
|
588
|
+
resetPassword(params: {
|
|
589
|
+
token: string;
|
|
590
|
+
newPassword: string;
|
|
591
|
+
}): Promise<PasswordResetOutcome>;
|
|
553
592
|
exchangeCode(params: ExchangeCodeParams): Promise<StoredSession>;
|
|
554
593
|
/** The `RefreshTokens` function the SessionEngine (F003) injects. */
|
|
555
594
|
createRefresher(): RefreshTokens;
|
|
@@ -568,4 +607,4 @@ declare class AuthClient {
|
|
|
568
607
|
declare const PACKAGE_NAME = "@poly-x/core";
|
|
569
608
|
declare const version = "0.0.0";
|
|
570
609
|
//#endregion
|
|
571
|
-
export { AuthClient, type AuthClientOptions, type AuthorizeOutcome, type AuthorizeWithPasswordParams, type BuildAuthorizeUrlParams, type Clock, DEFAULT_RETRY_POLICY, DEFAULT_TIMEOUT_MS, ENDPOINTS, type ExchangeCodeParams, FetchTransport, type FieldError, ForbiddenError, type HttpMethod, INITIAL_STATE as INITIAL_SESSION_STATE, InMemoryLock, InMemoryPkceStore, InMemorySessionChannel, InMemorySessionStore, type KeyEnv, type KeyKind, type Lock, type MockRoute, MockTransport, PACKAGE_NAME, type ParsedKey, type PasswordAuthOutcome, type PkceEntry, type PkcePair, type PkceStore, type PlatformResponseLike, PolyXConfigError, PolyXError, type PolyXErrorOptions, RateLimitedError, type RefreshTokens, type ResolveConfigInput, type ResolvedConfig, type RetryPolicy, type RuntimeContext, type Session, type SessionChannel, type SessionChannelEvent, type SessionClaims, SessionEngine, type SessionEngineOptions, type SessionEvent, SessionExpiredError, SessionRevokedError, type SessionState, type SessionStore, type SetPasswordParams, type SignedOutReason, type StoredSession, SystemClock, type TenantOption, type TimerHandle, type TokenSet, type Transport, type TransportRequest, type TransportResponse, UnauthenticatedError, UpstreamError, ValidationError, computeChallenge, createSessionEngine, decodeJwtExp, generatePkce, isTransientStatus, mapPlatformError, normalizeExchange, normalizeRefresh, parseAuthorizeOutcome, parsePasswordOutcome, parsePolyXKey, randomState, redactSensitive, reduce as reduceSessionState, resolveConfig, version };
|
|
610
|
+
export { AuthClient, type AuthClientOptions, type AuthorizeOutcome, type AuthorizeWithPasswordParams, type BuildAuthorizeUrlParams, type Clock, DEFAULT_RETRY_POLICY, DEFAULT_TIMEOUT_MS, ENDPOINTS, type ExchangeCodeParams, FetchTransport, type FieldError, ForbiddenError, type HttpMethod, INITIAL_STATE as INITIAL_SESSION_STATE, InMemoryLock, InMemoryPkceStore, InMemorySessionChannel, InMemorySessionStore, type KeyEnv, type KeyKind, type Lock, type MockRoute, MockTransport, PACKAGE_NAME, type ParsedKey, type PasswordAuthOutcome, type PasswordResetOutcome, type PkceEntry, type PkcePair, type PkceStore, type PlatformResponseLike, PolyXConfigError, PolyXError, type PolyXErrorOptions, RateLimitedError, type RefreshTokens, type ResolveConfigInput, type ResolvedConfig, type RetryPolicy, type RuntimeContext, type Session, type SessionChannel, type SessionChannelEvent, type SessionClaims, SessionEngine, type SessionEngineOptions, type SessionEvent, SessionExpiredError, SessionRevokedError, type SessionState, type SessionStore, type SetPasswordParams, type SignedOutReason, type StoredSession, SystemClock, type TenantOption, type TimerHandle, type TokenSet, type Transport, type TransportRequest, type TransportResponse, UnauthenticatedError, UpstreamError, ValidationError, computeChallenge, createSessionEngine, decodeJwtExp, generatePkce, isTransientStatus, mapPlatformError, normalizeExchange, normalizeRefresh, parseAuthorizeOutcome, parsePasswordOutcome, parsePolyXKey, parseResetOutcome, randomState, redactSensitive, reduce as reduceSessionState, resolveConfig, version };
|
package/dist/index.mjs
CHANGED
|
@@ -714,7 +714,14 @@ const ENDPOINTS = {
|
|
|
714
714
|
* password, poly-auth answered `403 {userPasswordSet, userId}`, and this sets
|
|
715
715
|
* the real one. Only succeeds while the account is flagged `mustChangePassword`.
|
|
716
716
|
*/
|
|
717
|
-
setPassword: "/v1/auth/set-password"
|
|
717
|
+
setPassword: "/v1/auth/set-password",
|
|
718
|
+
/**
|
|
719
|
+
* Server-mediated self-service reset (poly-x v5 / F040). `forgotPassword` starts it
|
|
720
|
+
* — always a uniform 202, the token is emailed to the mailbox, never returned.
|
|
721
|
+
* `resetPassword` redeems that opaque token single-use and sets the new password.
|
|
722
|
+
*/
|
|
723
|
+
forgotPassword: "/v1/idp/forgot-password",
|
|
724
|
+
resetPassword: "/v1/idp/reset-password"
|
|
718
725
|
};
|
|
719
726
|
//#endregion
|
|
720
727
|
//#region src/auth/outcomes.ts
|
|
@@ -768,11 +775,17 @@ function parsePasswordOutcome(status, body) {
|
|
|
768
775
|
};
|
|
769
776
|
if (status === 403 && b.userPasswordSet === true && typeof b.userId === "string") return {
|
|
770
777
|
type: "password_change_required",
|
|
771
|
-
userId: b.userId
|
|
778
|
+
userId: b.userId,
|
|
779
|
+
ticket: typeof b.ticket === "string" ? b.ticket : void 0
|
|
772
780
|
};
|
|
773
781
|
if (status === 403) return { type: "no_access" };
|
|
774
782
|
return { type: "invalid_credentials" };
|
|
775
783
|
}
|
|
784
|
+
function parseResetOutcome(status, body) {
|
|
785
|
+
if (status === 200) return "ok";
|
|
786
|
+
if (asRecord$1(body).status === "weak_password") return "weak_password";
|
|
787
|
+
return "invalid_or_expired";
|
|
788
|
+
}
|
|
776
789
|
//#endregion
|
|
777
790
|
//#region src/auth/normalize.ts
|
|
778
791
|
const FALLBACK_TTL_MS = 5 * 6e4;
|
|
@@ -926,11 +939,45 @@ var AuthClient = class {
|
|
|
926
939
|
body: {
|
|
927
940
|
userId: params.userId,
|
|
928
941
|
newPassword: params.newPassword,
|
|
929
|
-
confirmPassword: params.confirmPassword
|
|
942
|
+
confirmPassword: params.confirmPassword,
|
|
943
|
+
...params.ticket ? { ticket: params.ticket } : {}
|
|
930
944
|
}
|
|
931
945
|
});
|
|
932
946
|
if (response.status !== 200) throw this.toError(response);
|
|
933
947
|
}
|
|
948
|
+
/**
|
|
949
|
+
* Start a server-mediated self-service reset (F040). POSTs the email + this app's
|
|
950
|
+
* publishable key; the backend resolves the account, mints a single-use token, and
|
|
951
|
+
* emails the link ITSELF — nothing comes back but a uniform 202. Resolves on success;
|
|
952
|
+
* a 4xx (e.g. a misconfigured key) surfaces as a typed error for the developer.
|
|
953
|
+
*/
|
|
954
|
+
async requestPasswordReset(params) {
|
|
955
|
+
const response = await this.transport.request({
|
|
956
|
+
method: "POST",
|
|
957
|
+
url: this.config.baseUrl + ENDPOINTS.forgotPassword,
|
|
958
|
+
body: {
|
|
959
|
+
email: params.email,
|
|
960
|
+
client_id: this.config.key.raw
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
if (response.status >= 400) throw this.toError(response);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Redeem a reset token (the opaque value from the emailed link) single-use and set
|
|
967
|
+
* the new password. Returns a typed outcome the UI branches on; only a 5xx throws.
|
|
968
|
+
*/
|
|
969
|
+
async resetPassword(params) {
|
|
970
|
+
const response = await this.transport.request({
|
|
971
|
+
method: "POST",
|
|
972
|
+
url: this.config.baseUrl + ENDPOINTS.resetPassword,
|
|
973
|
+
body: {
|
|
974
|
+
token: params.token,
|
|
975
|
+
newPassword: params.newPassword
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
if (response.status >= 500) throw this.toError(response);
|
|
979
|
+
return parseResetOutcome(response.status, response.body);
|
|
980
|
+
}
|
|
934
981
|
async exchangeCode(params) {
|
|
935
982
|
const response = await this.transport.request({
|
|
936
983
|
method: "POST",
|
|
@@ -995,4 +1042,4 @@ var AuthClient = class {
|
|
|
995
1042
|
const PACKAGE_NAME = "@poly-x/core";
|
|
996
1043
|
const version = "0.0.0";
|
|
997
1044
|
//#endregion
|
|
998
|
-
export { AuthClient, DEFAULT_RETRY_POLICY, DEFAULT_TIMEOUT_MS, ENDPOINTS, FetchTransport, ForbiddenError, INITIAL_STATE as INITIAL_SESSION_STATE, InMemoryLock, InMemoryPkceStore, InMemorySessionChannel, InMemorySessionStore, MockTransport, PACKAGE_NAME, PolyXConfigError, PolyXError, RateLimitedError, SessionEngine, SessionExpiredError, SessionRevokedError, SystemClock, UnauthenticatedError, UpstreamError, ValidationError, computeChallenge, createSessionEngine, decodeJwtExp, generatePkce, isTransientStatus, mapPlatformError, normalizeExchange, normalizeRefresh, parseAuthorizeOutcome, parsePasswordOutcome, parsePolyXKey, randomState, redactSensitive, reduce as reduceSessionState, resolveConfig, version };
|
|
1045
|
+
export { AuthClient, DEFAULT_RETRY_POLICY, DEFAULT_TIMEOUT_MS, ENDPOINTS, FetchTransport, ForbiddenError, INITIAL_STATE as INITIAL_SESSION_STATE, InMemoryLock, InMemoryPkceStore, InMemorySessionChannel, InMemorySessionStore, MockTransport, PACKAGE_NAME, PolyXConfigError, PolyXError, RateLimitedError, SessionEngine, SessionExpiredError, SessionRevokedError, SystemClock, UnauthenticatedError, UpstreamError, ValidationError, computeChallenge, createSessionEngine, decodeJwtExp, generatePkce, isTransientStatus, mapPlatformError, normalizeExchange, normalizeRefresh, parseAuthorizeOutcome, parsePasswordOutcome, parsePolyXKey, parseResetOutcome, randomState, redactSensitive, reduce as reduceSessionState, resolveConfig, version };
|