@passflow/core 0.31.0 → 0.32.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/index.d.cts CHANGED
@@ -4853,6 +4853,109 @@ export declare class UserService {
4853
4853
  * the diagnostics.
4854
4854
  */
4855
4855
  export declare const requiredAcrLevel: (raw: string | undefined | null) => number | undefined;
4856
+ /** One captured header. Lower-cased name, value verbatim. */
4857
+ type SnapshotHeader = readonly [name: string, value: string];
4858
+ /**
4859
+ * The frozen description of one request.
4860
+ *
4861
+ * Immutable by construction: `Object.freeze` on the snapshot and on its header
4862
+ * list, and the body already captured by value where the shape is mutable. It
4863
+ * carries no live reference to anything the caller can still change.
4864
+ */
4865
+ type RequestSnapshot = {
4866
+ /** Exactly what the caller passed, for diagnostics only. NEVER for a decision. */
4867
+ readonly raw: string;
4868
+ /**
4869
+ * The absolute, platform-normalised URL the request will actually be sent to,
4870
+ * or `raw` when it could not be resolved at all (a malformed URL).
4871
+ *
4872
+ * This is the value every decision and the replay use.
4873
+ */
4874
+ readonly href: string;
4875
+ /**
4876
+ * The URL to actually DISPATCH a replay to.
4877
+ *
4878
+ * Identical to `href` wherever a real base existed — a browser, or any host
4879
+ * that resolved the URL absolutely — which is the case every decision cares
4880
+ * about. It falls back to `raw` only when resolution used the reserved
4881
+ * sentinel base, i.e. a relative URL on a host with no document: the
4882
+ * sentinel's origin is a reserved name that resolves to nothing, so sending
4883
+ * `href` there would send the request into a hole. The transport's own base
4884
+ * (axios' `baseURL`, the runtime's fetch base) then resolves the captured
4885
+ * string, exactly as it did for the original send.
4886
+ *
4887
+ * It is still a captured STRING, never the caller's object, so the TOCTOU
4888
+ * this module exists to close stays closed on that path too.
4889
+ */
4890
+ readonly dispatchUrl: string;
4891
+ /** The resolved origin, or `undefined` when the URL could not be resolved. */
4892
+ readonly origin?: string;
4893
+ /** The resolved pathname, or the raw path when the URL could not be resolved. */
4894
+ readonly pathname: string;
4895
+ /** False when the URL could not be parsed even against the base. */
4896
+ readonly resolved: boolean;
4897
+ /**
4898
+ * True when the resolved origin is the base's own — the page's origin on a
4899
+ * browser, the sentinel's off it, which means "genuinely relative".
4900
+ *
4901
+ * This is what a same-origin path-prefix pattern (`backend: '/api'`) tests,
4902
+ * and it is the one bit that makes `'/\\evil.example/x'` fail where `'/api/x'`
4903
+ * passes.
4904
+ */
4905
+ readonly relativeToBase: boolean;
4906
+ /** Upper-cased, with the same precedence the transport itself applies. */
4907
+ readonly method: string;
4908
+ /** The effective header set, captured once. Frozen. */
4909
+ readonly headers: readonly SnapshotHeader[];
4910
+ /** How the body can be re-sent, which is what decides replayability. */
4911
+ readonly bodyKind: BodyKind;
4912
+ /**
4913
+ * The already-captured body. `undefined` means "the caller passed no body
4914
+ * key", which is distinct from an explicit `null`.
4915
+ */
4916
+ readonly body?: unknown;
4917
+ };
4918
+ /** Our own `fetch` shape. Declared here rather than imported so no DOM lib is required. */
4919
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
4920
+ /** How a body can be re-sent, which is the only thing that decides replayability. */
4921
+ type BodyKind =
4922
+ /** No body at all. Re-issue the same input. */
4923
+ 'none' |
4924
+ /** A value the caller still holds and `fetch` re-reads: string, Blob, buffer, FormData, params. */
4925
+ 'reusable' |
4926
+ /** A `Request` with a body, cloned before the first send. */
4927
+ 'request-clone' |
4928
+ /** Consumed by the first send and unrecoverable: a `ReadableStream`, or a failed clone. */
4929
+ 'one-shot';
4930
+ /** What the policy predicate is told about a request. */
4931
+ type UpgradeReplayInfo = {
4932
+ url: string;
4933
+ method: string;
4934
+ bodyKind: BodyKind;
4935
+ };
4936
+ /**
4937
+ * Replay policy.
4938
+ *
4939
+ * The object form is §13.5's: size and streaming limits. The three string and
4940
+ * function forms are §5.1's escape hatch, kept because `'idempotent-only'`
4941
+ * expresses a constraint the object form cannot — a backend whose challenge may
4942
+ * arrive after a side effect.
4943
+ */
4944
+ type ReplayPolicy = {
4945
+ /** Refuse to buffer a `Request` body larger than this many bytes, when the size is known. */
4946
+ maxBodyBytes?: number;
4947
+ /** A stream is never replayable; the field exists so the intent is written down. */
4948
+ allowStreamingBody?: false;
4949
+ } | 'always' | 'idempotent-only' | ((info: UpgradeReplayInfo) => boolean);
4950
+ /** What `withAuth`, `attachAuth` and `createClient` accept. */
4951
+ type WithAuthOptions = {
4952
+ /**
4953
+ * Origins besides the page's own that receive the access token, for example
4954
+ * `['https://api.example.com']`. Each entry is reduced to its origin; anything that is not a URL
4955
+ * throws when the wrapper or interceptor is built.
4956
+ */
4957
+ origins?: readonly string[];
4958
+ };
4856
4959
  /** What the UI is shown when an upgrade is required. */
4857
4960
  type UpgradePromptRequest = {
4858
4961
  /** What the server demanded — the MERGED requirement, when several challenges joined. */
@@ -5230,100 +5333,6 @@ export declare class UpgradeController {
5230
5333
  /** Runs one full proof for a single factor. */
5231
5334
  private proveAndCommit;
5232
5335
  }
5233
- /** One captured header. Lower-cased name, value verbatim. */
5234
- type SnapshotHeader = readonly [name: string, value: string];
5235
- /**
5236
- * The frozen description of one request.
5237
- *
5238
- * Immutable by construction: `Object.freeze` on the snapshot and on its header
5239
- * list, and the body already captured by value where the shape is mutable. It
5240
- * carries no live reference to anything the caller can still change.
5241
- */
5242
- type RequestSnapshot = {
5243
- /** Exactly what the caller passed, for diagnostics only. NEVER for a decision. */
5244
- readonly raw: string;
5245
- /**
5246
- * The absolute, platform-normalised URL the request will actually be sent to,
5247
- * or `raw` when it could not be resolved at all (a malformed URL).
5248
- *
5249
- * This is the value every decision and the replay use.
5250
- */
5251
- readonly href: string;
5252
- /**
5253
- * The URL to actually DISPATCH a replay to.
5254
- *
5255
- * Identical to `href` wherever a real base existed — a browser, or any host
5256
- * that resolved the URL absolutely — which is the case every decision cares
5257
- * about. It falls back to `raw` only when resolution used the reserved
5258
- * sentinel base, i.e. a relative URL on a host with no document: the
5259
- * sentinel's origin is a reserved name that resolves to nothing, so sending
5260
- * `href` there would send the request into a hole. The transport's own base
5261
- * (axios' `baseURL`, the runtime's fetch base) then resolves the captured
5262
- * string, exactly as it did for the original send.
5263
- *
5264
- * It is still a captured STRING, never the caller's object, so the TOCTOU
5265
- * this module exists to close stays closed on that path too.
5266
- */
5267
- readonly dispatchUrl: string;
5268
- /** The resolved origin, or `undefined` when the URL could not be resolved. */
5269
- readonly origin?: string;
5270
- /** The resolved pathname, or the raw path when the URL could not be resolved. */
5271
- readonly pathname: string;
5272
- /** False when the URL could not be parsed even against the base. */
5273
- readonly resolved: boolean;
5274
- /**
5275
- * True when the resolved origin is the base's own — the page's origin on a
5276
- * browser, the sentinel's off it, which means "genuinely relative".
5277
- *
5278
- * This is what a same-origin path-prefix pattern (`backend: '/api'`) tests,
5279
- * and it is the one bit that makes `'/\\evil.example/x'` fail where `'/api/x'`
5280
- * passes.
5281
- */
5282
- readonly relativeToBase: boolean;
5283
- /** Upper-cased, with the same precedence the transport itself applies. */
5284
- readonly method: string;
5285
- /** The effective header set, captured once. Frozen. */
5286
- readonly headers: readonly SnapshotHeader[];
5287
- /** How the body can be re-sent, which is what decides replayability. */
5288
- readonly bodyKind: BodyKind;
5289
- /**
5290
- * The already-captured body. `undefined` means "the caller passed no body
5291
- * key", which is distinct from an explicit `null`.
5292
- */
5293
- readonly body?: unknown;
5294
- };
5295
- /** Our own `fetch` shape. Declared here rather than imported so no DOM lib is required. */
5296
- type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
5297
- /** How a body can be re-sent, which is the only thing that decides replayability. */
5298
- type BodyKind =
5299
- /** No body at all. Re-issue the same input. */
5300
- 'none' |
5301
- /** A value the caller still holds and `fetch` re-reads: string, Blob, buffer, FormData, params. */
5302
- 'reusable' |
5303
- /** A `Request` with a body, cloned before the first send. */
5304
- 'request-clone' |
5305
- /** Consumed by the first send and unrecoverable: a `ReadableStream`, or a failed clone. */
5306
- 'one-shot';
5307
- /** What the policy predicate is told about a request. */
5308
- type UpgradeReplayInfo = {
5309
- url: string;
5310
- method: string;
5311
- bodyKind: BodyKind;
5312
- };
5313
- /**
5314
- * Replay policy.
5315
- *
5316
- * The object form is §13.5's: size and streaming limits. The three string and
5317
- * function forms are §5.1's escape hatch, kept because `'idempotent-only'`
5318
- * expresses a constraint the object form cannot — a backend whose challenge may
5319
- * arrive after a side effect.
5320
- */
5321
- type ReplayPolicy = {
5322
- /** Refuse to buffer a `Request` body larger than this many bytes, when the size is known. */
5323
- maxBodyBytes?: number;
5324
- /** A stream is never replayable; the field exists so the intent is written down. */
5325
- allowStreamingBody?: false;
5326
- } | 'always' | 'idempotent-only' | ((info: UpgradeReplayInfo) => boolean);
5327
5336
  /** "You were challenged and you declined" — as opposed to "you were not authorised". */
5328
5337
  export declare const isUpgradeCancelled: (response: object) => boolean;
5329
5338
  export declare const isUpgradeExhausted: (response: object) => boolean;
@@ -5345,6 +5354,11 @@ type ResponseInterceptorHost = {
5345
5354
  use(onFulfilled?: (value: any) => any, onRejected?: (error: any) => any): number;
5346
5355
  eject(id: number): void;
5347
5356
  };
5357
+ /** Where the access token is added. A client without one gets step-up handling only. */
5358
+ request?: {
5359
+ use(onFulfilled?: (value: any) => any, onRejected?: (error: any) => any): number;
5360
+ eject(id: number): void;
5361
+ };
5348
5362
  };
5349
5363
  };
5350
5364
  /**
@@ -5641,10 +5655,17 @@ type UpgradeFacade = {
5641
5655
  * prompt, because they share one controller.
5642
5656
  */
5643
5657
  elevate(challenge: UpgradeChallenge, waiter?: Waiter): Promise<UpgradeElevation>;
5644
- /** Wraps a fetch and returns the wrapper. Touches no global. */
5645
- withAuth(next?: FetchLike): FetchLike;
5658
+ /**
5659
+ * Wraps a fetch and returns the wrapper. Touches no global. Adds the access token to requests for
5660
+ * the page's own origin and `options.origins` that carry no `Authorization` header.
5661
+ */
5662
+ withAuth(next?: FetchLike, options?: WithAuthOptions): FetchLike;
5646
5663
  /** Attaches to an axios instance the developer owns, MUTATING it. Returns `detach()`. */
5647
- attachAuth(instance: ResponseInterceptorHost): () => void;
5664
+ /**
5665
+ * Attaches step-up handling to an axios instance and, under the same rule as `withAuth`, a
5666
+ * request interceptor that adds the access token. Returns a disposer that removes both.
5667
+ */
5668
+ attachAuth(instance: ResponseInterceptorHost, options?: WithAuthOptions): () => void;
5648
5669
  };
5649
5670
  /**
5650
5671
  * Orders the factors to offer for a challenge. Index 0 is the suggested
@@ -5750,7 +5771,12 @@ export declare class Passflow {
5750
5771
  */
5751
5772
  setAppId(appId: string): void;
5752
5773
  /**
5753
- * Wraps a `fetch`, returning a new function with step-up handling attached.
5774
+ * Wraps a `fetch`, returning a new function that adds the access token and handles step-up.
5775
+ *
5776
+ * A request for the page's own origin or one in `options.origins` (compared exactly: scheme, host
5777
+ * and port) that has no `Authorization` header gets `Bearer <access token>`, refreshed first when
5778
+ * it has expired. Any other origin, a request with its own header, and a request with no
5779
+ * signed-in user go out as given.
5754
5780
  *
5755
5781
  * Installs nothing and touches no global — this is the SSR- and
5756
5782
  * React-Native-safe surface. Two verbs exist because the semantics genuinely
@@ -5763,18 +5789,23 @@ export declare class Passflow {
5763
5789
  *
5764
5790
  * @example
5765
5791
  * ```typescript
5766
- * const authedFetch = passflow.withAuth(fetch);
5792
+ * const authedFetch = passflow.withAuth(fetch, { origins: ['https://api.example.com'] });
5767
5793
  * const res = await authedFetch('https://api.example.com/transfer', { method: 'POST' });
5768
5794
  * if (!res.ok && isUpgradeCancelled(res)) {
5769
5795
  * // the user declined the step-up — not an authorization failure
5770
5796
  * }
5771
5797
  * ```
5772
5798
  */
5773
- withAuth(next?: FetchLike): FetchLike;
5799
+ withAuth(next?: FetchLike, options?: WithAuthOptions): FetchLike;
5774
5800
  /**
5775
5801
  * Attaches step-up handling to an axios instance the caller already owns,
5776
5802
  * **mutating** it, and returns a `detach()` disposer.
5777
5803
  *
5804
+ * It also adds a request interceptor with `withAuth`'s rule: a request for the
5805
+ * page's own origin or one in `options.origins` (exact scheme, host and port,
5806
+ * `baseURL` joined as axios does) that has no `Authorization` header gets
5807
+ * `Bearer <access token>`. The disposer removes both interceptors.
5808
+ *
5778
5809
  * The parameter is typed structurally — duck-typed on
5779
5810
  * `interceptors.response.use` — so this package's axios version is not a
5780
5811
  * constraint on the caller's. It returns the disposer rather than the
@@ -5784,13 +5815,14 @@ export declare class Passflow {
5784
5815
  * @example
5785
5816
  * ```typescript
5786
5817
  * const api = axios.create({ baseURL: 'https://api.example.com' });
5787
- * const detach = passflow.attachAuth(api);
5818
+ * const detach = passflow.attachAuth(api, { origins: ['https://api.example.com'] });
5788
5819
  * ```
5789
5820
  */
5790
- attachAuth(instance: ResponseInterceptorHost): () => void;
5821
+ attachAuth(instance: ResponseInterceptorHost, options?: WithAuthOptions): () => void;
5791
5822
  /**
5792
- * Builds a ready axios instance with step-up handling already wired, for a
5793
- * caller with no HTTP client of their own.
5823
+ * Builds a ready axios instance with step-up handling and the access token
5824
+ * (as `attachAuth`, with `options.origins`) already wired, for a caller with no
5825
+ * HTTP client of their own.
5794
5826
  *
5795
5827
  * Pure passthrough of axios' own create options, so `baseURL`, `headers`,
5796
5828
  * `timeout` and `adapter` stay the caller's. A `baseURL` is NOT read as a
@@ -5799,10 +5831,10 @@ export declare class Passflow {
5799
5831
  *
5800
5832
  * @example
5801
5833
  * ```typescript
5802
- * const api = passflow.createClient({ baseURL: 'https://api.example.com' });
5834
+ * const api = passflow.createClient({ baseURL: 'https://api.example.com' }, { origins: ['https://api.example.com'] });
5803
5835
  * ```
5804
5836
  */
5805
- createClient(config?: CreateClientConfig): AxiosInstance;
5837
+ createClient(config?: CreateClientConfig, options?: WithAuthOptions): AxiosInstance;
5806
5838
  /**
5807
5839
  * The assurance bar the session currently holds, read from the `acr` claim of
5808
5840
  * the stored access token.
@@ -7193,4 +7225,4 @@ export declare function isValidPhoneNumber(phone: string): boolean;
7193
7225
  * @returns true if valid username format, false otherwise
7194
7226
  */
7195
7227
  export declare function isValidUsername(username: string): boolean;
7196
- export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport };
7228
+ export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport, WithAuthOptions };
package/dist/index.d.ts CHANGED
@@ -4853,6 +4853,109 @@ export declare class UserService {
4853
4853
  * the diagnostics.
4854
4854
  */
4855
4855
  export declare const requiredAcrLevel: (raw: string | undefined | null) => number | undefined;
4856
+ /** One captured header. Lower-cased name, value verbatim. */
4857
+ type SnapshotHeader = readonly [name: string, value: string];
4858
+ /**
4859
+ * The frozen description of one request.
4860
+ *
4861
+ * Immutable by construction: `Object.freeze` on the snapshot and on its header
4862
+ * list, and the body already captured by value where the shape is mutable. It
4863
+ * carries no live reference to anything the caller can still change.
4864
+ */
4865
+ type RequestSnapshot = {
4866
+ /** Exactly what the caller passed, for diagnostics only. NEVER for a decision. */
4867
+ readonly raw: string;
4868
+ /**
4869
+ * The absolute, platform-normalised URL the request will actually be sent to,
4870
+ * or `raw` when it could not be resolved at all (a malformed URL).
4871
+ *
4872
+ * This is the value every decision and the replay use.
4873
+ */
4874
+ readonly href: string;
4875
+ /**
4876
+ * The URL to actually DISPATCH a replay to.
4877
+ *
4878
+ * Identical to `href` wherever a real base existed — a browser, or any host
4879
+ * that resolved the URL absolutely — which is the case every decision cares
4880
+ * about. It falls back to `raw` only when resolution used the reserved
4881
+ * sentinel base, i.e. a relative URL on a host with no document: the
4882
+ * sentinel's origin is a reserved name that resolves to nothing, so sending
4883
+ * `href` there would send the request into a hole. The transport's own base
4884
+ * (axios' `baseURL`, the runtime's fetch base) then resolves the captured
4885
+ * string, exactly as it did for the original send.
4886
+ *
4887
+ * It is still a captured STRING, never the caller's object, so the TOCTOU
4888
+ * this module exists to close stays closed on that path too.
4889
+ */
4890
+ readonly dispatchUrl: string;
4891
+ /** The resolved origin, or `undefined` when the URL could not be resolved. */
4892
+ readonly origin?: string;
4893
+ /** The resolved pathname, or the raw path when the URL could not be resolved. */
4894
+ readonly pathname: string;
4895
+ /** False when the URL could not be parsed even against the base. */
4896
+ readonly resolved: boolean;
4897
+ /**
4898
+ * True when the resolved origin is the base's own — the page's origin on a
4899
+ * browser, the sentinel's off it, which means "genuinely relative".
4900
+ *
4901
+ * This is what a same-origin path-prefix pattern (`backend: '/api'`) tests,
4902
+ * and it is the one bit that makes `'/\\evil.example/x'` fail where `'/api/x'`
4903
+ * passes.
4904
+ */
4905
+ readonly relativeToBase: boolean;
4906
+ /** Upper-cased, with the same precedence the transport itself applies. */
4907
+ readonly method: string;
4908
+ /** The effective header set, captured once. Frozen. */
4909
+ readonly headers: readonly SnapshotHeader[];
4910
+ /** How the body can be re-sent, which is what decides replayability. */
4911
+ readonly bodyKind: BodyKind;
4912
+ /**
4913
+ * The already-captured body. `undefined` means "the caller passed no body
4914
+ * key", which is distinct from an explicit `null`.
4915
+ */
4916
+ readonly body?: unknown;
4917
+ };
4918
+ /** Our own `fetch` shape. Declared here rather than imported so no DOM lib is required. */
4919
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
4920
+ /** How a body can be re-sent, which is the only thing that decides replayability. */
4921
+ type BodyKind =
4922
+ /** No body at all. Re-issue the same input. */
4923
+ 'none' |
4924
+ /** A value the caller still holds and `fetch` re-reads: string, Blob, buffer, FormData, params. */
4925
+ 'reusable' |
4926
+ /** A `Request` with a body, cloned before the first send. */
4927
+ 'request-clone' |
4928
+ /** Consumed by the first send and unrecoverable: a `ReadableStream`, or a failed clone. */
4929
+ 'one-shot';
4930
+ /** What the policy predicate is told about a request. */
4931
+ type UpgradeReplayInfo = {
4932
+ url: string;
4933
+ method: string;
4934
+ bodyKind: BodyKind;
4935
+ };
4936
+ /**
4937
+ * Replay policy.
4938
+ *
4939
+ * The object form is §13.5's: size and streaming limits. The three string and
4940
+ * function forms are §5.1's escape hatch, kept because `'idempotent-only'`
4941
+ * expresses a constraint the object form cannot — a backend whose challenge may
4942
+ * arrive after a side effect.
4943
+ */
4944
+ type ReplayPolicy = {
4945
+ /** Refuse to buffer a `Request` body larger than this many bytes, when the size is known. */
4946
+ maxBodyBytes?: number;
4947
+ /** A stream is never replayable; the field exists so the intent is written down. */
4948
+ allowStreamingBody?: false;
4949
+ } | 'always' | 'idempotent-only' | ((info: UpgradeReplayInfo) => boolean);
4950
+ /** What `withAuth`, `attachAuth` and `createClient` accept. */
4951
+ type WithAuthOptions = {
4952
+ /**
4953
+ * Origins besides the page's own that receive the access token, for example
4954
+ * `['https://api.example.com']`. Each entry is reduced to its origin; anything that is not a URL
4955
+ * throws when the wrapper or interceptor is built.
4956
+ */
4957
+ origins?: readonly string[];
4958
+ };
4856
4959
  /** What the UI is shown when an upgrade is required. */
4857
4960
  type UpgradePromptRequest = {
4858
4961
  /** What the server demanded — the MERGED requirement, when several challenges joined. */
@@ -5230,100 +5333,6 @@ export declare class UpgradeController {
5230
5333
  /** Runs one full proof for a single factor. */
5231
5334
  private proveAndCommit;
5232
5335
  }
5233
- /** One captured header. Lower-cased name, value verbatim. */
5234
- type SnapshotHeader = readonly [name: string, value: string];
5235
- /**
5236
- * The frozen description of one request.
5237
- *
5238
- * Immutable by construction: `Object.freeze` on the snapshot and on its header
5239
- * list, and the body already captured by value where the shape is mutable. It
5240
- * carries no live reference to anything the caller can still change.
5241
- */
5242
- type RequestSnapshot = {
5243
- /** Exactly what the caller passed, for diagnostics only. NEVER for a decision. */
5244
- readonly raw: string;
5245
- /**
5246
- * The absolute, platform-normalised URL the request will actually be sent to,
5247
- * or `raw` when it could not be resolved at all (a malformed URL).
5248
- *
5249
- * This is the value every decision and the replay use.
5250
- */
5251
- readonly href: string;
5252
- /**
5253
- * The URL to actually DISPATCH a replay to.
5254
- *
5255
- * Identical to `href` wherever a real base existed — a browser, or any host
5256
- * that resolved the URL absolutely — which is the case every decision cares
5257
- * about. It falls back to `raw` only when resolution used the reserved
5258
- * sentinel base, i.e. a relative URL on a host with no document: the
5259
- * sentinel's origin is a reserved name that resolves to nothing, so sending
5260
- * `href` there would send the request into a hole. The transport's own base
5261
- * (axios' `baseURL`, the runtime's fetch base) then resolves the captured
5262
- * string, exactly as it did for the original send.
5263
- *
5264
- * It is still a captured STRING, never the caller's object, so the TOCTOU
5265
- * this module exists to close stays closed on that path too.
5266
- */
5267
- readonly dispatchUrl: string;
5268
- /** The resolved origin, or `undefined` when the URL could not be resolved. */
5269
- readonly origin?: string;
5270
- /** The resolved pathname, or the raw path when the URL could not be resolved. */
5271
- readonly pathname: string;
5272
- /** False when the URL could not be parsed even against the base. */
5273
- readonly resolved: boolean;
5274
- /**
5275
- * True when the resolved origin is the base's own — the page's origin on a
5276
- * browser, the sentinel's off it, which means "genuinely relative".
5277
- *
5278
- * This is what a same-origin path-prefix pattern (`backend: '/api'`) tests,
5279
- * and it is the one bit that makes `'/\\evil.example/x'` fail where `'/api/x'`
5280
- * passes.
5281
- */
5282
- readonly relativeToBase: boolean;
5283
- /** Upper-cased, with the same precedence the transport itself applies. */
5284
- readonly method: string;
5285
- /** The effective header set, captured once. Frozen. */
5286
- readonly headers: readonly SnapshotHeader[];
5287
- /** How the body can be re-sent, which is what decides replayability. */
5288
- readonly bodyKind: BodyKind;
5289
- /**
5290
- * The already-captured body. `undefined` means "the caller passed no body
5291
- * key", which is distinct from an explicit `null`.
5292
- */
5293
- readonly body?: unknown;
5294
- };
5295
- /** Our own `fetch` shape. Declared here rather than imported so no DOM lib is required. */
5296
- type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
5297
- /** How a body can be re-sent, which is the only thing that decides replayability. */
5298
- type BodyKind =
5299
- /** No body at all. Re-issue the same input. */
5300
- 'none' |
5301
- /** A value the caller still holds and `fetch` re-reads: string, Blob, buffer, FormData, params. */
5302
- 'reusable' |
5303
- /** A `Request` with a body, cloned before the first send. */
5304
- 'request-clone' |
5305
- /** Consumed by the first send and unrecoverable: a `ReadableStream`, or a failed clone. */
5306
- 'one-shot';
5307
- /** What the policy predicate is told about a request. */
5308
- type UpgradeReplayInfo = {
5309
- url: string;
5310
- method: string;
5311
- bodyKind: BodyKind;
5312
- };
5313
- /**
5314
- * Replay policy.
5315
- *
5316
- * The object form is §13.5's: size and streaming limits. The three string and
5317
- * function forms are §5.1's escape hatch, kept because `'idempotent-only'`
5318
- * expresses a constraint the object form cannot — a backend whose challenge may
5319
- * arrive after a side effect.
5320
- */
5321
- type ReplayPolicy = {
5322
- /** Refuse to buffer a `Request` body larger than this many bytes, when the size is known. */
5323
- maxBodyBytes?: number;
5324
- /** A stream is never replayable; the field exists so the intent is written down. */
5325
- allowStreamingBody?: false;
5326
- } | 'always' | 'idempotent-only' | ((info: UpgradeReplayInfo) => boolean);
5327
5336
  /** "You were challenged and you declined" — as opposed to "you were not authorised". */
5328
5337
  export declare const isUpgradeCancelled: (response: object) => boolean;
5329
5338
  export declare const isUpgradeExhausted: (response: object) => boolean;
@@ -5345,6 +5354,11 @@ type ResponseInterceptorHost = {
5345
5354
  use(onFulfilled?: (value: any) => any, onRejected?: (error: any) => any): number;
5346
5355
  eject(id: number): void;
5347
5356
  };
5357
+ /** Where the access token is added. A client without one gets step-up handling only. */
5358
+ request?: {
5359
+ use(onFulfilled?: (value: any) => any, onRejected?: (error: any) => any): number;
5360
+ eject(id: number): void;
5361
+ };
5348
5362
  };
5349
5363
  };
5350
5364
  /**
@@ -5641,10 +5655,17 @@ type UpgradeFacade = {
5641
5655
  * prompt, because they share one controller.
5642
5656
  */
5643
5657
  elevate(challenge: UpgradeChallenge, waiter?: Waiter): Promise<UpgradeElevation>;
5644
- /** Wraps a fetch and returns the wrapper. Touches no global. */
5645
- withAuth(next?: FetchLike): FetchLike;
5658
+ /**
5659
+ * Wraps a fetch and returns the wrapper. Touches no global. Adds the access token to requests for
5660
+ * the page's own origin and `options.origins` that carry no `Authorization` header.
5661
+ */
5662
+ withAuth(next?: FetchLike, options?: WithAuthOptions): FetchLike;
5646
5663
  /** Attaches to an axios instance the developer owns, MUTATING it. Returns `detach()`. */
5647
- attachAuth(instance: ResponseInterceptorHost): () => void;
5664
+ /**
5665
+ * Attaches step-up handling to an axios instance and, under the same rule as `withAuth`, a
5666
+ * request interceptor that adds the access token. Returns a disposer that removes both.
5667
+ */
5668
+ attachAuth(instance: ResponseInterceptorHost, options?: WithAuthOptions): () => void;
5648
5669
  };
5649
5670
  /**
5650
5671
  * Orders the factors to offer for a challenge. Index 0 is the suggested
@@ -5750,7 +5771,12 @@ export declare class Passflow {
5750
5771
  */
5751
5772
  setAppId(appId: string): void;
5752
5773
  /**
5753
- * Wraps a `fetch`, returning a new function with step-up handling attached.
5774
+ * Wraps a `fetch`, returning a new function that adds the access token and handles step-up.
5775
+ *
5776
+ * A request for the page's own origin or one in `options.origins` (compared exactly: scheme, host
5777
+ * and port) that has no `Authorization` header gets `Bearer <access token>`, refreshed first when
5778
+ * it has expired. Any other origin, a request with its own header, and a request with no
5779
+ * signed-in user go out as given.
5754
5780
  *
5755
5781
  * Installs nothing and touches no global — this is the SSR- and
5756
5782
  * React-Native-safe surface. Two verbs exist because the semantics genuinely
@@ -5763,18 +5789,23 @@ export declare class Passflow {
5763
5789
  *
5764
5790
  * @example
5765
5791
  * ```typescript
5766
- * const authedFetch = passflow.withAuth(fetch);
5792
+ * const authedFetch = passflow.withAuth(fetch, { origins: ['https://api.example.com'] });
5767
5793
  * const res = await authedFetch('https://api.example.com/transfer', { method: 'POST' });
5768
5794
  * if (!res.ok && isUpgradeCancelled(res)) {
5769
5795
  * // the user declined the step-up — not an authorization failure
5770
5796
  * }
5771
5797
  * ```
5772
5798
  */
5773
- withAuth(next?: FetchLike): FetchLike;
5799
+ withAuth(next?: FetchLike, options?: WithAuthOptions): FetchLike;
5774
5800
  /**
5775
5801
  * Attaches step-up handling to an axios instance the caller already owns,
5776
5802
  * **mutating** it, and returns a `detach()` disposer.
5777
5803
  *
5804
+ * It also adds a request interceptor with `withAuth`'s rule: a request for the
5805
+ * page's own origin or one in `options.origins` (exact scheme, host and port,
5806
+ * `baseURL` joined as axios does) that has no `Authorization` header gets
5807
+ * `Bearer <access token>`. The disposer removes both interceptors.
5808
+ *
5778
5809
  * The parameter is typed structurally — duck-typed on
5779
5810
  * `interceptors.response.use` — so this package's axios version is not a
5780
5811
  * constraint on the caller's. It returns the disposer rather than the
@@ -5784,13 +5815,14 @@ export declare class Passflow {
5784
5815
  * @example
5785
5816
  * ```typescript
5786
5817
  * const api = axios.create({ baseURL: 'https://api.example.com' });
5787
- * const detach = passflow.attachAuth(api);
5818
+ * const detach = passflow.attachAuth(api, { origins: ['https://api.example.com'] });
5788
5819
  * ```
5789
5820
  */
5790
- attachAuth(instance: ResponseInterceptorHost): () => void;
5821
+ attachAuth(instance: ResponseInterceptorHost, options?: WithAuthOptions): () => void;
5791
5822
  /**
5792
- * Builds a ready axios instance with step-up handling already wired, for a
5793
- * caller with no HTTP client of their own.
5823
+ * Builds a ready axios instance with step-up handling and the access token
5824
+ * (as `attachAuth`, with `options.origins`) already wired, for a caller with no
5825
+ * HTTP client of their own.
5794
5826
  *
5795
5827
  * Pure passthrough of axios' own create options, so `baseURL`, `headers`,
5796
5828
  * `timeout` and `adapter` stay the caller's. A `baseURL` is NOT read as a
@@ -5799,10 +5831,10 @@ export declare class Passflow {
5799
5831
  *
5800
5832
  * @example
5801
5833
  * ```typescript
5802
- * const api = passflow.createClient({ baseURL: 'https://api.example.com' });
5834
+ * const api = passflow.createClient({ baseURL: 'https://api.example.com' }, { origins: ['https://api.example.com'] });
5803
5835
  * ```
5804
5836
  */
5805
- createClient(config?: CreateClientConfig): AxiosInstance;
5837
+ createClient(config?: CreateClientConfig, options?: WithAuthOptions): AxiosInstance;
5806
5838
  /**
5807
5839
  * The assurance bar the session currently holds, read from the `acr` claim of
5808
5840
  * the stored access token.
@@ -7193,4 +7225,4 @@ export declare function isValidPhoneNumber(phone: string): boolean;
7193
7225
  * @returns true if valid username format, false otherwise
7194
7226
  */
7195
7227
  export declare function isValidUsername(username: string): boolean;
7196
- export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport };
7228
+ export type { AssuranceBar, AuthCallbackResult, BodyKind, ChallengeChannel, CreateClientConfig, CurrentUrlInfo, ErrorPayload, EventOrigin, FetchLike, FetchMiddleware, GroupMembership, InvitationToken, M2MClientConfig, M2MErrorCode, M2MErrorResponse, M2MRateLimitInfo, M2MTokenCache, M2MTokenClaims, M2MTokenRequestInfo, M2MTokenRequestOptions, M2MTokenResponse, OidcErrorCode, OpenAuthUrlOptions, OperationErrorPayload, PassflowEmailVerificationOperation, PassflowEventPayload, PassflowOperation, PassflowRefreshErrorOptions, PassflowSubscriber, PasskeySupport, PlatformAdapter, PlatformStorage, RawUserMembership, RefreshChannel, RefreshClock, RefreshCoordination, RefreshCoordinator, RefreshErrorInfo, RefreshFailureKind, RefreshLockManager, RefreshLockOptions, RefreshTrigger, RegisterOptions, ReplayPolicy, RequestSnapshot, ResponseInterceptorHost, RetryStrategy, SessionExpiredReason, SnapshotHeader, Tenant, TenantMembership, Token, UpgradeAssertContext, UpgradeAssertion, UpgradeChallenge, UpgradeCommitInterruptedReason, UpgradeControllerOptions, UpgradeDiagnostic, UpgradeDiagnosticReason, UpgradeDiagnosticSink, UpgradeElevation, UpgradeEnableOptions, UpgradeEndpoint, UpgradeErrorKind, UpgradeFacade, UpgradeFactor, UpgradeFactorInput, UpgradeFactorType, UpgradeFlightState, UpgradeFlightSummary, UpgradeOptions, UpgradePrepared, UpgradePromptHandler, UpgradePromptRequest, UpgradePromptResult, UpgradeProof, UpgradeReplayInfo, UpgradeResult, UpgradeSessionPin, UpgradeTransport, UpgradeTransportErrorInit, UpgradeWaiterSummary, UserMembership, Waiter, WaiterEntry, WaiterOutcome, WaiterReport, WithAuthOptions };