@poly-x/core 0.1.0-alpha.6 → 0.1.0-alpha.8

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 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
@@ -775,6 +782,11 @@ function parsePasswordOutcome(status, body) {
775
782
  if (status === 403) return { type: "no_access" };
776
783
  return { type: "invalid_credentials" };
777
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
+ }
778
790
  //#endregion
779
791
  //#region src/auth/normalize.ts
780
792
  const FALLBACK_TTL_MS = 5 * 6e4;
@@ -934,6 +946,39 @@ var AuthClient = class {
934
946
  });
935
947
  if (response.status !== 200) throw this.toError(response);
936
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
+ }
937
982
  async exchangeCode(params) {
938
983
  const response = await this.transport.request({
939
984
  method: "POST",
@@ -1032,6 +1077,7 @@ exports.normalizeRefresh = normalizeRefresh;
1032
1077
  exports.parseAuthorizeOutcome = parseAuthorizeOutcome;
1033
1078
  exports.parsePasswordOutcome = parsePasswordOutcome;
1034
1079
  exports.parsePolyXKey = parsePolyXKey;
1080
+ exports.parseResetOutcome = parseResetOutcome;
1035
1081
  exports.randomState = randomState;
1036
1082
  exports.redactSensitive = redactSensitive;
1037
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
@@ -452,6 +459,14 @@ type PasswordAuthOutcome = {
452
459
  type: "no_access";
453
460
  };
454
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;
455
470
  //#endregion
456
471
  //#region src/auth/normalize.d.ts
457
472
  declare function decodeJwtExp(token: string): number | null;
@@ -557,6 +572,23 @@ declare class AuthClient {
557
572
  * the proof the caller knows the temporary password.
558
573
  */
559
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>;
560
592
  exchangeCode(params: ExchangeCodeParams): Promise<StoredSession>;
561
593
  /** The `RefreshTokens` function the SessionEngine (F003) injects. */
562
594
  createRefresher(): RefreshTokens;
@@ -575,4 +607,4 @@ declare class AuthClient {
575
607
  declare const PACKAGE_NAME = "@poly-x/core";
576
608
  declare const version = "0.0.0";
577
609
  //#endregion
578
- 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
@@ -452,6 +459,14 @@ type PasswordAuthOutcome = {
452
459
  type: "no_access";
453
460
  };
454
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;
455
470
  //#endregion
456
471
  //#region src/auth/normalize.d.ts
457
472
  declare function decodeJwtExp(token: string): number | null;
@@ -557,6 +572,23 @@ declare class AuthClient {
557
572
  * the proof the caller knows the temporary password.
558
573
  */
559
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>;
560
592
  exchangeCode(params: ExchangeCodeParams): Promise<StoredSession>;
561
593
  /** The `RefreshTokens` function the SessionEngine (F003) injects. */
562
594
  createRefresher(): RefreshTokens;
@@ -575,4 +607,4 @@ declare class AuthClient {
575
607
  declare const PACKAGE_NAME = "@poly-x/core";
576
608
  declare const version = "0.0.0";
577
609
  //#endregion
578
- 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
@@ -774,6 +781,11 @@ function parsePasswordOutcome(status, body) {
774
781
  if (status === 403) return { type: "no_access" };
775
782
  return { type: "invalid_credentials" };
776
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
+ }
777
789
  //#endregion
778
790
  //#region src/auth/normalize.ts
779
791
  const FALLBACK_TTL_MS = 5 * 6e4;
@@ -933,6 +945,39 @@ var AuthClient = class {
933
945
  });
934
946
  if (response.status !== 200) throw this.toError(response);
935
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
+ }
936
981
  async exchangeCode(params) {
937
982
  const response = await this.transport.request({
938
983
  method: "POST",
@@ -997,4 +1042,4 @@ var AuthClient = class {
997
1042
  const PACKAGE_NAME = "@poly-x/core";
998
1043
  const version = "0.0.0";
999
1044
  //#endregion
1000
- 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poly-x/core",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "Framework-agnostic core of the PolyX SDK",
5
5
  "license": "MIT",
6
6
  "type": "module",