@orvello/sdk 0.6.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
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  // src/contract-hash.ts
4
- var CONTRACT_SHA256 = "0a5b04b49734a49f2b1295c1308ba7fed5ed8050b27a50ba73c29c98114b48d7";
4
+ var CONTRACT_SHA256 = "bab3c1b429c28f8ac8aea5f9325c1205c6a29e2481efc868ad47a74d6587cc3d";
5
5
 
6
6
  // src/diagnose.ts
7
- var SDK_VERSION = "0.6.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");
@@ -417,6 +417,7 @@ var ROUTE_INDEX = {
417
417
  "invoices_payment_instructions_external": ["GET", "/invoices/external/:invoiceId/payment-instructions", "b", "unified_bearer", 1, ["invoices:read"]],
418
418
  "invoices_payment_reconciliation": ["GET", "/invoices/:invoiceId/payment-reconciliation", "b", "frontend_permission_http", 1],
419
419
  "invoices_pending_external": ["GET", "/invoices/external/pending", "b", "unified_bearer", 2, ["invoices:read"]],
420
+ "invoices_preview_external": ["POST", "/invoices/external/preview", "b", "unified_bearer", 4, ["invoices:read"]],
420
421
  "invoices_repair_pdf": ["POST", "/invoices/:invoiceId/repair-pdf", "b", "frontend_bearer_http", 1],
421
422
  "invoices_search": ["GET", "/invoices", "b", "frontend_bearer_http", 2],
422
423
  "invoices_search_external": ["GET", "/invoices/external", "b", "unified_bearer", 2, ["invoices:read"]],
@@ -736,7 +737,7 @@ function buildPath(operationId, params) {
736
737
  }
737
738
 
738
739
  // src/capabilities.ts
739
- var SDK_VERSION2 = "0.6.0" ;
740
+ var SDK_VERSION2 = "0.7.1" ;
740
741
  var CLIENT_MANAGEMENT_OPS = [
741
742
  "oauth2_external_clients_list",
742
743
  "oauth2_external_clients_get",
@@ -1036,7 +1037,8 @@ var OrvelloClient = class _OrvelloClient {
1036
1037
  }
1037
1038
  this.managementApiKey = config.managementApiKey ?? this.envManagementApiKey();
1038
1039
  this.extraHeaders = config.headers;
1039
- 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;
1040
1042
  this.timeoutMs = config.timeoutMs ?? 15e3;
1041
1043
  this.maxRetries = config.maxRetries ?? 3;
1042
1044
  this.retryBaseDelayMs = config.retryBaseDelayMs ?? 500;
@@ -1074,6 +1076,41 @@ var OrvelloClient = class _OrvelloClient {
1074
1076
  const val = typeof this.baseUrl === "function" ? await this.baseUrl() : this.baseUrl;
1075
1077
  return val.replace(/\/+$/, "");
1076
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
+ }
1077
1114
  static async resolveValue(provider) {
1078
1115
  if (provider === void 0) return void 0;
1079
1116
  return typeof provider === "function" ? await provider() : provider;
@@ -1549,6 +1586,11 @@ var OrvelloClient = class _OrvelloClient {
1549
1586
  method: "GET",
1550
1587
  ...options
1551
1588
  }),
1589
+ preview: (body, options) => this.request("/invoices/external/preview", {
1590
+ ...options,
1591
+ method: "POST",
1592
+ body: JSON.stringify(body)
1593
+ }),
1552
1594
  create: async (body, options) => {
1553
1595
  if (body.idempotencyKey !== void 0 && options?.idempotencyKey !== void 0 && body.idempotencyKey !== options.idempotencyKey) {
1554
1596
  throw new Error("Invoice body and request options contain different idempotency keys");