@btravstack/oauth-client 0.37.0 → 0.39.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.cjs CHANGED
@@ -70,18 +70,26 @@ const refusalOf = (cause) => cause instanceof openid_client.WWWAuthenticateChall
70
70
  description: cause.error_description
71
71
  } : void 0;
72
72
  const reasonOf = (audience, failure) => failure.tag === "Err" && failure.error._tag === "TokenRefused" ? `${audience}: refused (${failure.error.error})` : `${audience}: the issuer could not be asked`;
73
- const tokenFetches = (settings, observers, clock) => {
73
+ const tokenFetches = (settings, observers, clock, transport) => {
74
+ const fetch = transport === void 0 ? void 0 : (url, { body, ...options }) => transport(url, {
75
+ ...options,
76
+ ...body === void 0 ? {} : { body }
77
+ });
74
78
  let configuration;
75
79
  const cached = /* @__PURE__ */ new Map();
76
80
  const inFlight = /* @__PURE__ */ new Map();
77
81
  const failing = /* @__PURE__ */ new Map();
78
82
  const latestFetch = /* @__PURE__ */ new Map();
79
83
  const discover = () => {
80
- configuration ??= (0, unthrown.fromPromise)(Promise.resolve().then(() => (0, openid_client.discovery)(new URL(settings.issuer), settings.clientId, void 0, (0, openid_client.ClientSecretBasic)(settings.clientSecret), { execute: settings.insecure ? [openid_client.allowInsecureRequests] : [] })), (cause) => new TokenIssuerUnavailable({
84
+ configuration ??= (0, unthrown.fromPromise)(Promise.resolve().then(() => (0, openid_client.discovery)(new URL(settings.issuer), settings.clientId, void 0, (0, openid_client.ClientSecretBasic)(settings.clientSecret), {
85
+ execute: settings.insecure ? [openid_client.allowInsecureRequests] : [],
86
+ ...fetch === void 0 ? {} : { [openid_client.customFetch]: fetch }
87
+ })), (cause) => new TokenIssuerUnavailable({
81
88
  issuer: settings.issuer,
82
89
  cause
83
90
  })).map((config) => {
84
91
  if (settings.insecure) (0, openid_client.allowInsecureRequests)(config);
92
+ if (fetch !== void 0) config[openid_client.customFetch] = fetch;
85
93
  return config;
86
94
  }).tapFailure(() => {
87
95
  configuration = void 0;
@@ -224,7 +232,7 @@ const oauthClient = (options = {}) => {
224
232
  })) : (0, unthrown.OkAsync)(tokenFetches({
225
233
  ...bound,
226
234
  insecure
227
- }, observers, clock));
235
+ }, observers, clock, options.fetch));
228
236
  })
229
237
  });
230
238
  return (0, _btravstack_di.Module)("OAuthClient")({
package/dist/index.d.cts CHANGED
@@ -97,6 +97,8 @@ type OAuthClientOptions = {
97
97
  readonly allowInsecureIssuer?: boolean;
98
98
  /** What a token's lifetime is measured against (default: the kernel's `systemClock`). */
99
99
  readonly clock?: Clock | undefined;
100
+ /** Application-owned fetch boundary, used for both discovery and token requests. */
101
+ readonly fetch?: typeof fetch;
100
102
  };
101
103
  /**
102
104
  * `TokenSource` over an OAuth 2.0 authorization server: client credentials
package/dist/index.d.mts CHANGED
@@ -97,6 +97,8 @@ type OAuthClientOptions = {
97
97
  readonly allowInsecureIssuer?: boolean;
98
98
  /** What a token's lifetime is measured against (default: the kernel's `systemClock`). */
99
99
  readonly clock?: Clock | undefined;
100
+ /** Application-owned fetch boundary, used for both discovery and token requests. */
101
+ readonly fetch?: typeof fetch;
100
102
  };
101
103
  /**
102
104
  * `TokenSource` over an OAuth 2.0 authorization server: client credentials
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { Config, Env, cleartext, cleartextRefused } from "@btravstack/config";
3
3
  import { HealthCheckFailed, HealthChecks, Observers, noObserverMember, observed, systemClock } from "@btravstack/core";
4
4
  import { Module, Port, Provider } from "@btravstack/di";
5
- import { ClientSecretBasic, ResponseBodyError, WWWAuthenticateChallengeError, allowInsecureRequests, clientCredentialsGrant, discovery, genericGrantRequest } from "openid-client";
5
+ import { ClientSecretBasic, ResponseBodyError, WWWAuthenticateChallengeError, allowInsecureRequests, clientCredentialsGrant, customFetch, discovery, genericGrantRequest } from "openid-client";
6
6
  import { ErrAsync, OkAsync, TaggedError, fromPromise } from "unthrown";
7
7
  //#region src/token-source.ts
8
8
  /**
@@ -69,18 +69,26 @@ const refusalOf = (cause) => cause instanceof WWWAuthenticateChallengeError ? {
69
69
  description: cause.error_description
70
70
  } : void 0;
71
71
  const reasonOf = (audience, failure) => failure.tag === "Err" && failure.error._tag === "TokenRefused" ? `${audience}: refused (${failure.error.error})` : `${audience}: the issuer could not be asked`;
72
- const tokenFetches = (settings, observers, clock) => {
72
+ const tokenFetches = (settings, observers, clock, transport) => {
73
+ const fetch = transport === void 0 ? void 0 : (url, { body, ...options }) => transport(url, {
74
+ ...options,
75
+ ...body === void 0 ? {} : { body }
76
+ });
73
77
  let configuration;
74
78
  const cached = /* @__PURE__ */ new Map();
75
79
  const inFlight = /* @__PURE__ */ new Map();
76
80
  const failing = /* @__PURE__ */ new Map();
77
81
  const latestFetch = /* @__PURE__ */ new Map();
78
82
  const discover = () => {
79
- configuration ??= fromPromise(Promise.resolve().then(() => discovery(new URL(settings.issuer), settings.clientId, void 0, ClientSecretBasic(settings.clientSecret), { execute: settings.insecure ? [allowInsecureRequests] : [] })), (cause) => new TokenIssuerUnavailable({
83
+ configuration ??= fromPromise(Promise.resolve().then(() => discovery(new URL(settings.issuer), settings.clientId, void 0, ClientSecretBasic(settings.clientSecret), {
84
+ execute: settings.insecure ? [allowInsecureRequests] : [],
85
+ ...fetch === void 0 ? {} : { [customFetch]: fetch }
86
+ })), (cause) => new TokenIssuerUnavailable({
80
87
  issuer: settings.issuer,
81
88
  cause
82
89
  })).map((config) => {
83
90
  if (settings.insecure) allowInsecureRequests(config);
91
+ if (fetch !== void 0) config[customFetch] = fetch;
84
92
  return config;
85
93
  }).tapFailure(() => {
86
94
  configuration = void 0;
@@ -223,7 +231,7 @@ const oauthClient = (options = {}) => {
223
231
  })) : OkAsync(tokenFetches({
224
232
  ...bound,
225
233
  insecure
226
- }, observers, clock));
234
+ }, observers, clock, options.fetch));
227
235
  })
228
236
  });
229
237
  return Module("OAuthClient")({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btravstack/oauth-client",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "A TokenSource port for @btravstack/core: OAuth 2.0 client credentials and RFC 8693 token exchange, so a service calls another as itself or for a subject — cached per audience until shortly before expiry, one fetch shared by concurrent callers, and a static adapter for tests",
5
5
  "keywords": [
6
6
  "client-credentials",
@@ -43,11 +43,11 @@
43
43
  "./package.json": "./package.json"
44
44
  },
45
45
  "devDependencies": {
46
- "@btravstack/config": "0.37.0",
47
- "@btravstack/core": "0.37.0",
48
- "@btravstack/di": "0.37.0",
46
+ "@btravstack/config": "0.39.0",
47
+ "@btravstack/core": "0.39.0",
48
+ "@btravstack/di": "0.39.0",
49
49
  "@btravstack/internal-test-infra": "0.0.0",
50
- "@btravstack/testing": "0.37.0",
50
+ "@btravstack/testing": "0.39.0",
51
51
  "@btravstack/tsconfig": "0.4.0",
52
52
  "@types/node": "26.6.5",
53
53
  "@unthrown/vitest": "5.12.1",
@@ -59,9 +59,9 @@
59
59
  "vitest": "5.0.3"
60
60
  },
61
61
  "peerDependencies": {
62
- "@btravstack/config": "^0.37.0",
63
- "@btravstack/core": "^0.37.0",
64
- "@btravstack/di": "^0.37.0",
62
+ "@btravstack/config": "^0.39.0",
63
+ "@btravstack/core": "^0.39.0",
64
+ "@btravstack/di": "^0.39.0",
65
65
  "openid-client": "^6",
66
66
  "unthrown": "^5.0.0"
67
67
  },