@orvello/sdk 0.7.0 → 0.7.1

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
@@ -4,7 +4,7 @@
4
4
  var CONTRACT_SHA256 = "bab3c1b429c28f8ac8aea5f9325c1205c6a29e2481efc868ad47a74d6587cc3d";
5
5
 
6
6
  // src/diagnose.ts
7
- var SDK_VERSION = "0.7.0" ;
7
+ var SDK_VERSION = "0.7.1" ;
8
8
  function normalizeBaseUrl(raw) {
9
9
  const trimmed = raw.trim();
10
10
  if (!trimmed) throw new Error("Base URL cannot be empty");
@@ -737,7 +737,7 @@ function buildPath(operationId, params) {
737
737
  }
738
738
 
739
739
  // src/capabilities.ts
740
- var SDK_VERSION2 = "0.7.0" ;
740
+ var SDK_VERSION2 = "0.7.1" ;
741
741
  var CLIENT_MANAGEMENT_OPS = [
742
742
  "oauth2_external_clients_list",
743
743
  "oauth2_external_clients_get",
@@ -1037,7 +1037,8 @@ var OrvelloClient = class _OrvelloClient {
1037
1037
  }
1038
1038
  this.managementApiKey = config.managementApiKey ?? this.envManagementApiKey();
1039
1039
  this.extraHeaders = config.headers;
1040
- this.doFetch = config.fetch || globalThis.fetch;
1040
+ const rawFetch = config.fetch || globalThis.fetch;
1041
+ this.doFetch = typeof rawFetch === "function" ? ((input, init) => this.fetchWithServiceHeaders(rawFetch, input, init)) : rawFetch;
1041
1042
  this.timeoutMs = config.timeoutMs ?? 15e3;
1042
1043
  this.maxRetries = config.maxRetries ?? 3;
1043
1044
  this.retryBaseDelayMs = config.retryBaseDelayMs ?? 500;
@@ -1075,6 +1076,41 @@ var OrvelloClient = class _OrvelloClient {
1075
1076
  const val = typeof this.baseUrl === "function" ? await this.baseUrl() : this.baseUrl;
1076
1077
  return val.replace(/\/+$/, "");
1077
1078
  }
1079
+ /**
1080
+ * Haengt die konfigurierten Kopfzeilen an, wenn die Anfrage an den Dienst selbst geht
1081
+ * (Basis-Adresse oder eigener Token-Endpunkt). Schon gesetzte Kopfzeilen bleiben.
1082
+ */
1083
+ async fetchWithServiceHeaders(rawFetch, input, init) {
1084
+ const configured = await _OrvelloClient.resolveValue(this.extraHeaders);
1085
+ if (!configured || Object.keys(configured).length === 0) return rawFetch(input, init);
1086
+ const target = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
1087
+ if (!await this.isServiceOrigin(target)) return rawFetch(input, init);
1088
+ const headers = new Headers(init?.headers ?? (typeof input === "object" && "headers" in input ? input.headers : void 0));
1089
+ for (const [name, value] of Object.entries(configured)) {
1090
+ if (!headers.has(name)) headers.set(name, value);
1091
+ }
1092
+ return rawFetch(input, { ...init, headers });
1093
+ }
1094
+ async isServiceOrigin(target) {
1095
+ let origin;
1096
+ try {
1097
+ origin = new URL(target).origin;
1098
+ } catch {
1099
+ return false;
1100
+ }
1101
+ const own = [];
1102
+ try {
1103
+ own.push(new URL(await this.resolveBaseUrl()).origin);
1104
+ } catch {
1105
+ }
1106
+ if (typeof this.auth === "object" && "tokenUrl" in this.auth && this.auth.tokenUrl) {
1107
+ try {
1108
+ own.push(new URL(this.auth.tokenUrl).origin);
1109
+ } catch {
1110
+ }
1111
+ }
1112
+ return own.includes(origin);
1113
+ }
1078
1114
  static async resolveValue(provider) {
1079
1115
  if (provider === void 0) return void 0;
1080
1116
  return typeof provider === "function" ? await provider() : provider;